diff --git a/apps/server/src/orchestration-v2/Adapters/FxAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/FxAdapterV2.test.ts index 24a380e7fd6c0..3c0f8a20c644c 100644 --- a/apps/server/src/orchestration-v2/Adapters/FxAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/FxAdapterV2.test.ts @@ -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; @@ -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", { diff --git a/apps/server/src/orchestration-v2/RuntimePolicy.ts b/apps/server/src/orchestration-v2/RuntimePolicy.ts index f0d0ae38577d1..ca7f70561046d 100644 --- a/apps/server/src/orchestration-v2/RuntimePolicy.ts +++ b/apps/server/src/orchestration-v2/RuntimePolicy.ts @@ -88,7 +88,7 @@ export const layer: Layer.Layer = Layer.succeed(RuntimePolicyV2 }), }); -function providerRuntimeMode( +export function providerRuntimeMode( runtimeMode: RuntimeMode, supportedRuntimeModes: ReadonlyArray | undefined, ): RuntimeMode { diff --git a/apps/server/src/orchestration-v2/testkit/FxReplayFixtures.integration.test.ts b/apps/server/src/orchestration-v2/testkit/FxReplayFixtures.integration.test.ts index 60adbeb3f2d38..c226c2ba0f350 100644 --- a/apps/server/src/orchestration-v2/testkit/FxReplayFixtures.integration.test.ts +++ b/apps/server/src/orchestration-v2/testkit/FxReplayFixtures.integration.test.ts @@ -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, + }), ); }); diff --git a/docs/user/permission-modes.md b/docs/user/permission-modes.md index 796e3f316122d..6a3fa01ab7e75 100644 --- a/docs/user/permission-modes.md +++ b/docs/user/permission-modes.md @@ -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 diff --git a/docs/user/providers-fx.md b/docs/user/providers-fx.md index 4b14caa48dae5..e500fac35b3ab 100644 --- a/docs/user/providers-fx.md +++ b/docs/user/providers-fx.md @@ -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. @@ -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. diff --git a/packages/provider-fx/src/server/acpSupport.test.ts b/packages/provider-fx/src/server/acpSupport.test.ts index f227eb0f36435..6295ef44425ed 100644 --- a/packages/provider-fx/src/server/acpSupport.test.ts +++ b/packages/provider-fx/src/server/acpSupport.test.ts @@ -11,6 +11,7 @@ import { ProviderAdapterV2RuntimePolicy } from "@t3tools/provider-core/server/Pr import { applyFxModelSelection, fxPermissionDisposition, + fxSessionModeForPolicy, fxToolCallWasCancelled, } from "./acpSupport.ts"; @@ -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", () => { diff --git a/packages/provider-fx/src/server/acpSupport.ts b/packages/provider-fx/src/server/acpSupport.ts index d7a109dfab871..569bfe4984f76 100644 --- a/packages/provider-fx/src/server/acpSupport.ts +++ b/packages/provider-fx/src/server/acpSupport.ts @@ -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; +/** 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. */ @@ -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); + } } /** @@ -147,8 +162,8 @@ export function fxPermissionDisposition( */ function fxModeId(requested: string, advertised: ReadonlyArray): string | undefined { const candidates = - requested === "ask" - ? ["ask"] + requested === "ask" || requested === FX_FULL_ACCESS_MODE_ID + ? [requested] : requested === "auto" || requested === "code" ? ["auto", "code"] : []; diff --git a/packages/provider-fx/src/server/status.test.ts b/packages/provider-fx/src/server/status.test.ts index 90313f2235625..f4bab296fdd29 100644 --- a/packages/provider-fx/src/server/status.test.ts +++ b/packages/provider-fx/src/server/status.test.ts @@ -44,7 +44,7 @@ function processHandle(stdout: string, code: number, answered: Effect.Effect = {}) => +const status = (auth: string, fields: Record = {}) => JSON.stringify({ kind: "status", model: "default", auth, auth_refreshable: false, ...fields }); const models = (ids: ReadonlyArray) => JSON.stringify({ kind: "models", count: ids.length, private_models_hidden: false, ids }); @@ -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({ diff --git a/packages/provider-fx/src/server/status.ts b/packages/provider-fx/src/server/status.ts index 2f6a78d07713c..49b4b172fcc04 100644 --- a/packages/provider-fx/src/server/status.ts +++ b/packages/provider-fx/src/server/status.ts @@ -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, @@ -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], }); @@ -115,10 +118,11 @@ const snapshot = ( probe: ProviderProbeResult, defaultModel?: string, backends: ReadonlyArray = [], + fullAccess = false, ): ServerProviderDraft => ({ ...buildServerProvider({ driver: FX_DRIVER_KIND, - presentation: FX_PRESENTATION, + presentation: fxPresentation(fullAccess), enabled: settings.enabled, checkedAt, models: fxModels(settings, defaultModel, backends), @@ -180,7 +184,8 @@ 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({ @@ -188,6 +193,7 @@ const FxStatus = Schema.fromJsonString( 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); @@ -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, ); }); diff --git a/packages/provider-fx/src/testing.ts b/packages/provider-fx/src/testing.ts index 8a3258b9ce5b8..6b962a2f5b6bc 100644 --- a/packages/provider-fx/src/testing.ts +++ b/packages/provider-fx/src/testing.ts @@ -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";