Skip to content
20 changes: 13 additions & 7 deletions apps/server/src/orchestration-v2/Adapters/FxAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const NAMED_MODEL = "anthropic/claude-sonnet-5.5";
const CUSTOM_MODEL = "openai/gpt-6.1-sol";
const CODEX_MODEL = "gpt-6.1-sol";
const FX_0_0_13_MODES = ["code", "ask"];
/** fx `main` after vercel-labs/fx#1189. */
/** fx 0.0.14+, after vercel-labs/fx#1189. */
const FX_MAIN_MODES = ["auto", "ask", "full-access"];

type Frame = Record<string, unknown>;
Expand Down Expand Up @@ -277,16 +277,22 @@ const openFxSession = Effect.fn("openFxSession")(function* (input: {
});

describe("FxAdapterV2", () => {
it.effect("runs Auto as fx's `code` mode on 0.0.13 and as `auto` where fx advertises it", () =>
it.effect("runs Auto as `code` on 0.0.13, and Auto and Full access as fx names them later", () =>
Effect.forEach(
[
{ scenario: "auto-0-0-13", modes: FX_0_0_13_MODES, written: "code" },
{ scenario: "auto-main", modes: FX_MAIN_MODES, written: "auto" },
],
({ scenario, modes, written }) =>
{ scenario: "auto-0-0-13", runtimeMode: "auto", modes: FX_0_0_13_MODES, written: "code" },
{ scenario: "auto-main", runtimeMode: "auto", modes: FX_MAIN_MODES, written: "auto" },
{
scenario: "full-access-main",
runtimeMode: "full-access",
modes: FX_MAIN_MODES,
written: "full-access",
},
] as const,
({ scenario, runtimeMode, modes, written }) =>
openFxSession({
scenario,
runtimeMode: "auto",
runtimeMode,
frames: [
...initialize,
outbound("session/new", {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/orchestration-v2/RuntimePolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const layer: Layer.Layer<RuntimePolicyV2> = Layer.succeed(RuntimePolicyV2
}),
});

function providerRuntimeMode(
export function providerRuntimeMode(
runtimeMode: RuntimeMode,
supportedRuntimeModes: ReadonlyArray<RuntimeMode> | undefined,
): RuntimeMode {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import { describe } from "@effect/vitest";
import { FX_SUPPORTED_RUNTIME_MODES } from "@t3tools/provider-fx/testing";

import { FxOrchestratorReplayHarness } from "../Adapters/FxAdapterV2.testkit.ts";
import { providerRuntimeMode } from "../RuntimePolicy.ts";
import { itRunsReplayFixtures, runReplayFixture } from "./ProviderReplayFixtures.ts";

describe("fx replay fixtures", () => {
// Recorded where fx's snapshot offers no Full access (0.0.13), so a thread
// set to it runs as RuntimePolicy resolves it there: Supervised.
itRunsReplayFixtures("fx", (input) =>
runReplayFixture({ ...input, harness: FxOrchestratorReplayHarness }),
runReplayFixture({
...input,
buildInput: () => {
const fixtureInput = input.buildInput();
return {
...fixtureInput,
runtimeMode: providerRuntimeMode(
fixtureInput.runtimeMode ?? "full-access",
FX_SUPPORTED_RUNTIME_MODES,
),
};
},
harness: FxOrchestratorReplayHarness,
}),
);
});
4 changes: 2 additions & 2 deletions docs/user/permission-modes.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ to you for approval. On fx, prompts it still sends also come to you.
Muse Code offers only **Supervised** and **Full access**. A Muse thread already set to another mode
runs in **Supervised**.

T3 Code offers no **Auto-accept edits** or **Full access** for fx. An fx thread already set to either runs in
**Supervised**.
T3 Code offers no **Auto-accept edits** for fx, and **Full access** only with fx 0.0.14 or later. An fx
thread set to a mode its fx lacks runs in **Supervised**.

Grok offers no **Auto-accept edits**. A Grok thread already set to it runs in **Supervised**. Grok
file-change approvals offer **Allow all edits this session**. Its command approvals have no
Expand Down
14 changes: 7 additions & 7 deletions docs/user/providers-fx.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ fx threads load the MCP servers from fx's profile config, `~/.fx/mcp.json`, on t

## Permission modes

fx offers two composer modes.
| Mode | Behavior |
| --------------- | ----------------------------------------------------------------------------------- |
| **Supervised** | fx asks before it changes files or runs commands. Read requests run without asking. |
| **Auto** | fx handles routine actions itself. Anything it still asks about reaches you. |
| **Full access** | fx runs every action without asking. Needs fx 0.0.14 or later. |

| Mode | Behavior |
| -------------- | ----------------------------------------------------------------------------------- |
| **Supervised** | fx asks before it changes files or runs commands. Read requests run without asking. |
| **Auto** | fx handles routine actions itself. Anything it still asks about reaches you. |
T3 Code offers **Full access** only when the server's fx reports it. After you upgrade fx, refresh the provider in **Settings → Providers** to see it. On an older fx, or before the provider check finishes, a thread set to **Full access** runs in **Supervised**.

T3 Code does not offer **Full access** or **Auto-accept edits** for fx. A thread already set to one of those runs in **Supervised**. Changing the permission mode restarts the connection and reloads the same fx session.
T3 Code does not offer **Auto-accept edits** for fx. A thread already set to it runs in **Supervised**. Changing the permission mode restarts the connection and reloads the same fx session.

On fx 0.0.14 and later, fx saves the mode T3 Code sets as its default permission mode. T3 Code sets it each time it opens an fx thread, so fx in the terminal then starts in that thread's mode.

Expand All @@ -64,7 +65,6 @@ fx doesn't pass on a sub-agent's permission requests, so a sub-agent that needs

## Not supported yet

- **Full access**.
- **Auto-accept edits**.
- Commit messages, pull request text, branch names, and thread titles. Pick another provider for those.

Expand Down
30 changes: 30 additions & 0 deletions packages/provider-fx/src/server/acpSupport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ProviderAdapterV2RuntimePolicy } from "@t3tools/provider-core/server/Pr
import {
applyFxModelSelection,
fxPermissionDisposition,
fxSessionModeForPolicy,
fxToolCallWasCancelled,
} from "./acpSupport.ts";

Expand Down Expand Up @@ -39,6 +40,35 @@ describe("fx permission prompts", () => {
"ask",
);
});

it("answers Full access prompts itself unless an explicit policy confines them", () => {
const fullAccess = {
runtimeMode: "full-access",
interactionMode: "default",
cwd: "/work",
} as const;
assert.equal(
fxPermissionDisposition(ProviderAdapterV2RuntimePolicy.make(fullAccess), editRequest),
"allow",
);
// Runs fx's `ask`, so the policy decides what fx asks about.
assert.equal(
fxPermissionDisposition(
ProviderAdapterV2RuntimePolicy.make({ ...fullAccess, approvalPolicy: "on-request" }),
editRequest,
),
"ask",
);
for (const confined of [
{ approvalPolicy: "on-request" },
{ sandboxPolicy: { type: "readOnly" } },
] as const) {
assert.equal(
fxSessionModeForPolicy(ProviderAdapterV2RuntimePolicy.make({ ...fullAccess, ...confined })),
"ask",
);
}
});
});

describe("fx model selection", () => {
Expand Down
45 changes: 30 additions & 15 deletions packages/provider-fx/src/server/acpSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ export const FX_EFFORT_OPTION_DESCRIPTOR: ProviderOptionDescriptor = {
})),
};

/** Every fx offers these; the provider snapshot adds Full access where `fx status` lists `full-access`. */
export const FX_SUPPORTED_RUNTIME_MODES = [
"approval-required",
"auto",
] as const satisfies ReadonlyArray<RuntimeMode>;
/** fx 0.0.14+; fx 0.0.13 has no such mode. */
export const FX_FULL_ACCESS_MODE_ID = "full-access";
/** fx 0.0.13 answers a cancelled prompt with `stopReason: cancelled`. */
export const FX_ACP_CANCEL_BEHAVIOR = "wait-for-prompt" as const;
/** fx inherits the user's `~/.fx/mcp.json` servers only when session setup asks for them. */
Expand Down Expand Up @@ -115,28 +118,40 @@ export function fxToolCallWasCancelled(payload: unknown): boolean {
}

/**
* Supervised runs fx's `ask` mode and Auto its automatic review. An explicit
* approval or sandbox policy must not launch automatic review, which would
* perform writes the policy meant to confine.
* Supervised runs fx's `ask` mode, Auto its automatic review and Full access
* its `full-access`. An explicit approval or sandbox policy runs `ask`, so it
* never launches a mode that performs writes the policy meant to confine.
*/
export function fxSessionModeForPolicy(
policy: ProviderAdapter.ProviderAdapterV2RuntimePolicy,
): "ask" | "auto" {
return policy.runtimeMode === "auto" &&
policy.approvalPolicy === undefined &&
policy.sandboxPolicy === undefined
? "auto"
: "ask";
): "ask" | "auto" | typeof FX_FULL_ACCESS_MODE_ID {
if (policy.approvalPolicy !== undefined || policy.sandboxPolicy !== undefined) return "ask";
switch (policy.runtimeMode) {
case "auto":
return "auto";
case "full-access":
return FX_FULL_ACCESS_MODE_ID;
default:
return "ask";
}
}

/** In automatic review fx asks only about what it refused itself, so every prompt reaches the user. */
/**
* In automatic review fx asks only about what it refused itself, so every
* prompt reaches the user. Full access answers by the shared ACP policy.
*/
export function fxPermissionDisposition(
policy: ProviderAdapter.ProviderAdapterV2RuntimePolicy,
request: EffectAcpSchema.RequestPermissionRequest,
): AcpPermissionDisposition {
return fxSessionModeForPolicy(policy) === "auto"
? "ask"
: acpPermissionDisposition({ ...policy, runtimeMode: "approval-required" }, request);
switch (fxSessionModeForPolicy(policy)) {
case "auto":
return "ask";
case FX_FULL_ACCESS_MODE_ID:
return acpPermissionDisposition(policy, request);
case "ask":
return acpPermissionDisposition({ ...policy, runtimeMode: "approval-required" }, request);
}
}

/**
Expand All @@ -147,8 +162,8 @@ export function fxPermissionDisposition(
*/
function fxModeId(requested: string, advertised: ReadonlyArray<string>): string | undefined {
const candidates =
requested === "ask"
? ["ask"]
requested === "ask" || requested === FX_FULL_ACCESS_MODE_ID
? [requested]
: requested === "auto" || requested === "code"
? ["auto", "code"]
: [];
Expand Down
28 changes: 27 additions & 1 deletion packages/provider-fx/src/server/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function processHandle(stdout: string, code: number, answered: Effect.Effect<voi

// `fx status --json` and `fx models --json` from fx 0.0.15, trimmed to the
// fields T3 reads plus a few it ignores.
const status = (auth: string, fields: Record<string, string> = {}) =>
const status = (auth: string, fields: Record<string, unknown> = {}) =>
JSON.stringify({ kind: "status", model: "default", auth, auth_refreshable: false, ...fields });
const models = (ids: ReadonlyArray<string>) =>
JSON.stringify({ kind: "models", count: ids.length, private_models_hidden: false, ids });
Expand Down Expand Up @@ -284,6 +284,32 @@ describe("checkFxProviderStatus", () => {
}),
);

it.effect("offers Full access only when `fx status` lists that mode", () =>
Effect.gen(function* () {
const backends = {
"gateway status --json": status("fx login"),
"gateway models --json": GATEWAY_MODELS,
"codex status --json": status("missing"),
"grok status --json": status("missing"),
};
// fx 0.0.13 lists no modes and has no full-access mode.
const withoutModes = yield* check({ ...backends, " status --json": status("fx login") });
assert.deepEqual(withoutModes.draft.supportedRuntimeModes, ["approval-required", "auto"]);
// fx 0.0.14+ lists the ACP session modes (src/core/output/output_contracts.zig).
const withModes = yield* check({
...backends,
" status --json": status("fx login", {
modes: [{ id: "auto" }, { id: "ask" }, { id: "full-access" }],
}),
});
assert.deepEqual(withModes.draft.supportedRuntimeModes, [
"approval-required",
"auto",
"full-access",
]);
}),
);

it.effect("reports a machine signed out of every backend", () =>
Effect.gen(function* () {
const signedOut = yield* check({
Expand Down
17 changes: 12 additions & 5 deletions packages/provider-fx/src/server/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
FX_DEFAULT_MODEL_SLUG,
FX_DRIVER_KIND,
FX_EFFORT_OPTION_DESCRIPTOR,
FX_FULL_ACCESS_MODE_ID,
FX_SUPPORTED_RUNTIME_MODES,
type FxModelChoice,
fxModelSlug,
Expand All @@ -38,11 +39,13 @@ import {
spawnAndCollect,
} from "@t3tools/provider-core/server/snapshotProbe";

const FX_PRESENTATION = {
const fxPresentation = (fullAccess: boolean) => ({
displayName: "fx",
showInteractionModeToggle: false,
supportedRuntimeModes: FX_SUPPORTED_RUNTIME_MODES,
} as const;
supportedRuntimeModes: fullAccess
? [...FX_SUPPORTED_RUNTIME_MODES, "full-access" as const]
: FX_SUPPORTED_RUNTIME_MODES,
});
const FX_MODEL_CAPABILITIES = createModelCapabilities({
optionDescriptors: [FX_EFFORT_OPTION_DESCRIPTOR],
});
Expand Down Expand Up @@ -115,10 +118,11 @@ const snapshot = (
probe: ProviderProbeResult,
defaultModel?: string,
backends: ReadonlyArray<FxBackendProbe> = [],
fullAccess = false,
): ServerProviderDraft => ({
...buildServerProvider({
driver: FX_DRIVER_KIND,
presentation: FX_PRESENTATION,
presentation: fxPresentation(fullAccess),
enabled: settings.enabled,
checkedAt,
models: fxModels(settings, defaultModel, backends),
Expand Down Expand Up @@ -180,14 +184,16 @@ const readFxCli = (
/**
* `fx status --json`: `auth` names the login method, `missing` when signed
* out. `model_source` names a backend other than the gateway, by its label
* for a built-in one and its id for a configured endpoint.
* for a built-in one and its id for a configured endpoint. fx 0.0.14+ also
* lists the ACP session `modes`; 0.0.13 omits them.
*/
const FxStatus = Schema.fromJsonString(
Schema.Struct({
auth: Schema.optional(Schema.String),
auth_help: Schema.optional(Schema.String),
model: Schema.optional(Schema.String),
model_source: Schema.optional(Schema.String),
modes: Schema.optional(Schema.Array(Schema.Struct({ id: Schema.String }))),
}),
);
const decodeFxStatus = Schema.decodeUnknownOption(FxStatus);
Expand Down Expand Up @@ -379,6 +385,7 @@ export const checkFxProviderStatus = Effect.fn("checkFxProviderStatus")(function
{ installed: true, version, auth, ...probe },
defaultModel,
backends,
status?.modes?.some((mode) => mode.id === FX_FULL_ACCESS_MODE_ID) ?? false,
);
});

Expand Down
6 changes: 5 additions & 1 deletion packages/provider-fx/src/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
* @module provider-fx/testing
*/
export { FX_DRIVER_KIND, makeFxAdapterV2 } from "./server/adapter.ts";
export { FX_ACP_CANCEL_BEHAVIOR, makeFxAcpRuntime } from "./server/acpSupport.ts";
export {
FX_ACP_CANCEL_BEHAVIOR,
FX_SUPPORTED_RUNTIME_MODES,
makeFxAcpRuntime,
} from "./server/acpSupport.ts";
Loading