From 0dba09cf98124a46714f5f5a6e8d841958ab2ac3 Mon Sep 17 00:00:00 2001 From: factory-ain3sh Date: Tue, 17 Nov 2026 19:32:03 +0000 Subject: [PATCH 1/5] fix(acp-registry): Factory Droid asks before acting unless the thread has Full access Droid's ACP session modes are its autonomy levels, and a new session can start at auto-high, which runs every action without asking. T3 never set them, so an Approval required thread still ran Droid at auto-high, and the composer's Autonomy Level choice could raise it further. Droid now follows the thread's runtime policy on every session configure: auto-high only under unrestricted Full access, normal (asks before each change, so T3's policy answers) otherwise. The mode is locked to the policy, so neither the Autonomy Level option nor the Plan-exit restore can override it. Local `droid` installs get the same flavor as the registry agent. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- apps/server/scripts/acp-mock-agent.ts | 55 +++++++---- .../Adapters/AcpAdapterV2.test.ts | 97 +++++++++++++++++++ .../src/server/adapter.ts | 10 +- .../src/server/droidAcp.ts | 28 +++++- 4 files changed, 163 insertions(+), 27 deletions(-) diff --git a/apps/server/scripts/acp-mock-agent.ts b/apps/server/scripts/acp-mock-agent.ts index a65f4d5473c71..b71a4760d58f9 100644 --- a/apps/server/scripts/acp-mock-agent.ts +++ b/apps/server/scripts/acp-mock-agent.ts @@ -23,6 +23,9 @@ const copilotModesProfile = process.env.T3_ACP_COPILOT_MODES === "1"; const copilotModeId = (name: string) => `https://agentclientprotocol.com/protocol/session-modes#${name}`; const modeOptionCategory = process.env.T3_ACP_MODE_OPTION_CATEGORY ?? "mode"; +// Factory Droid's modes are autonomy levels behind an `autonomy_level` option, starting at auto-high. +const droidModesProfile = process.env.T3_ACP_DROID_MODES === "1"; +const modeConfigId = droidModesProfile ? "autonomy_level" : "mode"; // Comma-separated command names the mock advertises, so `/compact` support is testable. const advertisedCommandNames = (process.env.T3_ACP_AVAILABLE_COMMANDS ?? "") .split(",") @@ -115,7 +118,9 @@ let currentModeId = antigravityProfile ? (process.env.T3_ACP_INITIAL_MODE ?? "default") : copilotModesProfile ? copilotModeId("agent") - : "ask"; + : droidModesProfile + ? "auto-high" + : "ask"; let currentModelId = antigravityProfile ? "gemini-test-low" : "default"; let parameterizedModelPicker = false; let currentReasoning = "medium"; @@ -303,7 +308,7 @@ function configOptions(): ReadonlyArray { ] : []), { - configId: "mode", + configId: modeConfigId, name: "Mode", category: modeOptionCategory, type: "select" as const, @@ -376,23 +381,31 @@ const availableModes: ReadonlyArray = antigravityProfile { id: copilotModeId("plan"), name: "Plan" }, { id: copilotModeId("autopilot"), name: "Autopilot" }, ] - : [ - { - id: "ask", - name: "Ask", - description: "Request permission before making any changes", - }, - { - id: "architect", - name: "Architect", - description: "Design and plan software systems without implementation", - }, - { - id: "code", - name: "Code", - description: "Write and modify code with full tool access", - }, - ]; + : droidModesProfile + ? [ + { id: "normal", name: "Auto (Off)" }, + { id: "spec", name: "Spec" }, + { id: "auto-low", name: "Auto (Low)" }, + { id: "auto-medium", name: "Auto (Medium)" }, + { id: "auto-high", name: "Auto (High)" }, + ] + : [ + { + id: "ask", + name: "Ask", + description: "Request permission before making any changes", + }, + { + id: "architect", + name: "Architect", + description: "Design and plan software systems without implementation", + }, + { + id: "code", + name: "Code", + description: "Write and modify code with full tool access", + }, + ]; function modeState(): AcpCompat.SessionModeState { return { @@ -827,7 +840,7 @@ const program = Effect.gen(function* () { yield* agent.handleSetSessionConfigOption((request) => Effect.gen(function* () { - if (failSetModeConfigOption && request.configId === "mode") { + if (failSetModeConfigOption && request.configId === modeConfigId) { return yield* AcpError.AcpRequestError.invalidParams( "Mock invalid params for session/set_config_option", { @@ -836,7 +849,7 @@ const program = Effect.gen(function* () { }, ); } - if (request.configId === "mode" && typeof request.value === "string") { + if (request.configId === modeConfigId && typeof request.value === "string") { currentModeId = request.value; } if (request.configId === "model" && typeof request.value === "string") { diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index 52123f19ef059..0a77d5c4ddab2 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -2249,6 +2249,103 @@ describe("AcpAdapterV2", () => { }).pipe(Effect.provide(layerTest)); }); + it.live("keeps Factory Droid's autonomy level on the thread's runtime mode", () => + Effect.gen(function* () { + const protocolEvents = yield* Queue.unbounded(); + const instanceId = ProviderInstanceId.make("droid-autonomy-test"); + const threadId = ThreadId.make("thread-droid-autonomy"); + const adapter = yield* makeAcpRegistryAdapterV2({ + instanceId, + selfInvocation: yield* resolveSelfInvocation(), + settings: DROID_SETTINGS, + environment: {}, + makeRuntime: makeMockRuntime({ + childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner, + mockAgentPath: yield* bundledMockAgentPath, + protocolEvents, + environment: { T3_ACP_DROID_MODES: "1" }, + }), + }).pipe( + Effect.provide( + Layer.mock(AcpRegistryCatalog)({ resolve: () => Effect.die("runtime is injected") }), + ), + ); + const policy = ( + runtimeMode: "approval-required" | "full-access", + interactionMode: "default" | "plan" = "default", + ) => + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + runtimeMode, + interactionMode, + cwd: process.cwd(), + }); + const modelSelection: ModelSelection = { + instanceId, + model: "default", + options: [{ id: "autonomy_level", value: "auto-high" }], + }; + const runtime = yield* adapter.openSession({ + threadId, + providerSessionId: ProviderSessionId.make("provider-session-droid-autonomy"), + modelSelection, + runtimePolicy: policy("approval-required"), + }); + const providerThread = yield* runtime.ensureThread({ + threadId, + modelSelection, + runtimePolicy: policy("approval-required"), + }); + const now = yield* DateTime.now; + const autonomyWritesForTurn = Effect.fnUntraced(function* ( + ordinal: number, + runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy, + ) { + yield* runtime.startTurn( + makeTurnInput({ + threadId, + providerThread, + instanceId, + runtimePolicy, + now, + ordinal, + messageText: `Request ${ordinal}.`, + modelSelection, + }), + ); + yield* runtime.events.pipe( + Stream.takeUntil((event) => event.type === "turn.terminal"), + Stream.runDrain, + ); + const writes: Array = []; + while (true) { + const event = yield* Queue.take(protocolEvents); + if (event.direction !== "outgoing") continue; + const method = rawProtocolMethod(event); + if (method === "session/prompt") return writes; + if ( + method === "session/set_config_option" && + rawProtocolRequestParam(event, "configId") === "autonomy_level" + ) { + writes.push(rawProtocolRequestParam(event, "value")); + } + } + }); + + assert.deepEqual( + yield* autonomyWritesForTurn(0, policy("approval-required")), + ["normal"], + "Droid starts at auto-high and the Autonomy Level choice must not outrank the policy", + ); + assert.deepEqual(yield* autonomyWritesForTurn(1, policy("full-access")), ["auto-high"]); + assert.deepEqual(yield* autonomyWritesForTurn(2, policy("full-access", "plan")), []); + assert.deepEqual( + yield* autonomyWritesForTurn(3, policy("approval-required")), + ["normal"], + "Leaving Plan must not restore the autonomy level an earlier policy set", + ); + }).pipe(Effect.provide(layerTest)), + ); + it.live.each(["failed", "recovered", "cancelled"] as const)( "projects Mistral retry notices and their %s outcome", (outcome) => diff --git a/packages/provider-acp-registry/src/server/adapter.ts b/packages/provider-acp-registry/src/server/adapter.ts index 105778db7e876..e74fd6efc81b0 100644 --- a/packages/provider-acp-registry/src/server/adapter.ts +++ b/packages/provider-acp-registry/src/server/adapter.ts @@ -9,7 +9,7 @@ import { extractDevinSubagentUpdate, devinAnswerablePermissionOptions, } from "./devinAcp.ts"; -import { extractDroidElicitationForm } from "./droidAcp.ts"; +import { droidAcpFlavor } from "./droidAcp.ts"; import { makeKimiPromptOutcomeWatch } from "./kimiAcp.ts"; import { extractOmpElicitationForm } from "./ompAcp.ts"; import { extractOpenCodeElicitationForm } from "./opencodeAcp.ts"; @@ -192,6 +192,10 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu const startupKey = options.settings.source === "local" ? `local:${options.instanceId}` : registryAgentId; const isDevin = registryAgentId === "devin"; + const isDroid = + registryAgentId === "factory-droid" || + (options.settings.source === "local" && + /^droid(\.exe|\.cmd)?$/i.test(options.settings.commandPath.split(/[\\/]/).pop() ?? "")); const isOmp = options.settings.source === "local" && /^omp(\.exe|\.cmd)?$/i.test(options.settings.commandPath.split(/[\\/]/).pop() ?? ""); @@ -248,8 +252,8 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu customModels: readCustomModelEntries(options.settings.customModels).map((entry) => entry.slug), compactViaAdvertisedCommand: true, promptFailure: (cause) => acpRegistryPromptFailure(registryAgentId, cause), - ...(registryAgentId === "factory-droid" - ? { extractElicitationForm: extractDroidElicitationForm } + ...(isDroid + ? droidAcpFlavor : isOmp ? { extractElicitationForm: extractOmpElicitationForm } : isOpenCode diff --git a/packages/provider-acp-registry/src/server/droidAcp.ts b/packages/provider-acp-registry/src/server/droidAcp.ts index d5ad446a8c740..378865e27e357 100644 --- a/packages/provider-acp-registry/src/server/droidAcp.ts +++ b/packages/provider-acp-registry/src/server/droidAcp.ts @@ -1,5 +1,6 @@ import { type OrchestrationV2UserInputQuestion, TrimmedNonEmptyString } from "@t3tools/contracts"; import type { AcpAdapterV2Flavor } from "@t3tools/provider-acp/server/adapter"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as Predicate from "effect/Predicate"; import * as Schema from "effect/Schema"; @@ -26,9 +27,9 @@ const isDroidCompanion = Schema.is(Schema.Struct({ type: Schema.Literal("string" // Droid pairs each choice with an optional *_other field. The client already // offers custom answers, so hide the companion and restore it in the response. -export const extractDroidElicitationForm: NonNullable< - AcpAdapterV2Flavor["extractElicitationForm"] -> = (request) => { +const extractDroidElicitationForm: NonNullable = ( + request, +) => { if (request.mode !== "form" || !isDroidForm(request.requestedSchema)) return undefined; const { properties, required } = request.requestedSchema; const questions: Array = []; @@ -82,3 +83,24 @@ export const extractDroidElicitationForm: NonNullable< }, }; }; + +// Droid's session modes are its autonomy levels, and a new session can start at +// `auto-high`, which runs every action without asking. `normal` asks before each +// change, so T3's runtime policy answers; only unrestricted full access skips asking. +function droidSessionModeForPolicy( + policy: ProviderAdapter.ProviderAdapterV2RuntimePolicy, +): "auto-high" | "normal" { + return policy.runtimeMode === "full-access" && + policy.approvalPolicy === undefined && + policy.sandboxPolicy === undefined + ? "auto-high" + : "normal"; +} + +export const droidAcpFlavor = { + extractElicitationForm: extractDroidElicitationForm, + // The composer's Autonomy Level choice would outrank the thread's runtime mode. + ownedModelOptionIds: ["autonomy_level"], + lockSessionModeToPolicy: true, + sessionModeForPolicy: droidSessionModeForPolicy, +} satisfies Partial; From 28c59e5ac4b980980a5d14794b1812d9ce8677fc Mon Sep 17 00:00:00 2001 From: factory-ain3sh Date: Tue, 17 Nov 2026 22:09:06 +0000 Subject: [PATCH 2/5] fix(acp-registry): Droid's policy level is one its session advertises T3 wrote `auto-high` or `normal` to every Droid session, and T3 refuses to send a value the session does not advertise. Two cases failed. An organization can cap Droid's autonomy below auto-high; Droid then advertises only the levels up to the cap, so every Full access turn failed to start. A session that advertises no levels failed to open, which turned four Registry elicitation tests red. The flavor now receives the session's advertised modes and returns the highest level the policy allows among them: auto-high, auto-medium, auto-low, then normal under unrestricted Full access, and normal otherwise. When the session advertises none of them, T3 writes nothing. The test gains a capped row and a row for a local `droid` command, and its composer choice now differs from the policy's level, so it fails when the flavor stops owning that option. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- apps/server/scripts/acp-mock-agent.ts | 22 +- .../Adapters/AcpAdapterV2.test.ts | 200 ++++++++++-------- .../src/server/droidAcp.ts | 18 +- packages/provider-acp/src/server/adapter.ts | 7 +- 4 files changed, 140 insertions(+), 107 deletions(-) diff --git a/apps/server/scripts/acp-mock-agent.ts b/apps/server/scripts/acp-mock-agent.ts index b71a4760d58f9..36631212836bf 100644 --- a/apps/server/scripts/acp-mock-agent.ts +++ b/apps/server/scripts/acp-mock-agent.ts @@ -23,8 +23,10 @@ const copilotModesProfile = process.env.T3_ACP_COPILOT_MODES === "1"; const copilotModeId = (name: string) => `https://agentclientprotocol.com/protocol/session-modes#${name}`; const modeOptionCategory = process.env.T3_ACP_MODE_OPTION_CATEGORY ?? "mode"; -// Factory Droid's modes are autonomy levels behind an `autonomy_level` option, starting at auto-high. +// Factory Droid's modes are autonomy levels behind an `autonomy_level` option. An organization can +// cap them: Droid then starts no higher than the cap and advertises no level above it. const droidModesProfile = process.env.T3_ACP_DROID_MODES === "1"; +const droidMaxAutonomy = process.env.T3_ACP_DROID_MAX_AUTONOMY ?? "auto-high"; const modeConfigId = droidModesProfile ? "autonomy_level" : "mode"; // Comma-separated command names the mock advertises, so `/compact` support is testable. const advertisedCommandNames = (process.env.T3_ACP_AVAILABLE_COMMANDS ?? "") @@ -119,7 +121,7 @@ let currentModeId = antigravityProfile : copilotModesProfile ? copilotModeId("agent") : droidModesProfile - ? "auto-high" + ? droidMaxAutonomy : "ask"; let currentModelId = antigravityProfile ? "gemini-test-low" : "default"; let parameterizedModelPicker = false; @@ -369,6 +371,14 @@ const antigravityModels = [ { modelId: "gemini-test-high", name: "Gemini Test High" }, ] satisfies ReadonlyArray; +const droidModes: ReadonlyArray = [ + { id: "normal", name: "Auto (Off)" }, + { id: "spec", name: "Spec" }, + { id: "auto-low", name: "Auto (Low)" }, + { id: "auto-medium", name: "Auto (Medium)" }, + { id: "auto-high", name: "Auto (High)" }, +]; + const availableModes: ReadonlyArray = antigravityProfile ? [ { id: "default", name: "Default" }, @@ -382,13 +392,7 @@ const availableModes: ReadonlyArray = antigravityProfile { id: copilotModeId("autopilot"), name: "Autopilot" }, ] : droidModesProfile - ? [ - { id: "normal", name: "Auto (Off)" }, - { id: "spec", name: "Spec" }, - { id: "auto-low", name: "Auto (Low)" }, - { id: "auto-medium", name: "Auto (Medium)" }, - { id: "auto-high", name: "Auto (High)" }, - ] + ? droidModes.slice(0, droidModes.findIndex((mode) => mode.id === droidMaxAutonomy) + 1) : [ { id: "ask", diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index 0a77d5c4ddab2..ecad2d7e7bb78 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -104,6 +104,10 @@ import { const DEFAULT_GROK_SETTINGS = Schema.decodeSync(GrokSettings)({}); const DROID_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ agentId: "factory-droid" }); +const LOCAL_DROID_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ + source: "local", + commandPath: "/usr/local/bin/droid", +}); const DEVIN_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ agentId: "devin" }); const OMP_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ source: "local", @@ -2249,101 +2253,115 @@ describe("AcpAdapterV2", () => { }).pipe(Effect.provide(layerTest)); }); - it.live("keeps Factory Droid's autonomy level on the thread's runtime mode", () => - Effect.gen(function* () { - const protocolEvents = yield* Queue.unbounded(); - const instanceId = ProviderInstanceId.make("droid-autonomy-test"); - const threadId = ThreadId.make("thread-droid-autonomy"); - const adapter = yield* makeAcpRegistryAdapterV2({ - instanceId, - selfInvocation: yield* resolveSelfInvocation(), - settings: DROID_SETTINGS, - environment: {}, - makeRuntime: makeMockRuntime({ - childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner, - mockAgentPath: yield* bundledMockAgentPath, - protocolEvents, - environment: { T3_ACP_DROID_MODES: "1" }, - }), - }).pipe( - Effect.provide( - Layer.mock(AcpRegistryCatalog)({ resolve: () => Effect.die("runtime is injected") }), - ), - ); - const policy = ( - runtimeMode: "approval-required" | "full-access", - interactionMode: "default" | "plan" = "default", - ) => - ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ - runtimeMode, - interactionMode, - cwd: process.cwd(), - }); - const modelSelection: ModelSelection = { - instanceId, - model: "default", - options: [{ id: "autonomy_level", value: "auto-high" }], - }; - const runtime = yield* adapter.openSession({ - threadId, - providerSessionId: ProviderSessionId.make("provider-session-droid-autonomy"), - modelSelection, - runtimePolicy: policy("approval-required"), - }); - const providerThread = yield* runtime.ensureThread({ - threadId, - modelSelection, - runtimePolicy: policy("approval-required"), - }); - const now = yield* DateTime.now; - const autonomyWritesForTurn = Effect.fnUntraced(function* ( - ordinal: number, - runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy, - ) { - yield* runtime.startTurn( - makeTurnInput({ - threadId, - providerThread, - instanceId, - runtimePolicy, - now, - ordinal, - messageText: `Request ${ordinal}.`, - modelSelection, + it.live.each([ + { agent: "the registry agent", settings: DROID_SETTINGS, maxAutonomy: "auto-high" }, + { + agent: "the registry agent under an organization cap", + settings: DROID_SETTINGS, + maxAutonomy: "auto-medium", + }, + { agent: "a local droid command", settings: LOCAL_DROID_SETTINGS, maxAutonomy: "auto-high" }, + ])( + "keeps Factory Droid's autonomy level on the thread's runtime mode for $agent", + ({ settings, maxAutonomy }) => + Effect.gen(function* () { + const protocolEvents = yield* Queue.unbounded(); + const instanceId = ProviderInstanceId.make("droid-autonomy-test"); + const threadId = ThreadId.make("thread-droid-autonomy"); + const adapter = yield* makeAcpRegistryAdapterV2({ + instanceId, + selfInvocation: yield* resolveSelfInvocation(), + settings, + environment: {}, + makeRuntime: makeMockRuntime({ + childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner, + mockAgentPath: yield* bundledMockAgentPath, + protocolEvents, + environment: { T3_ACP_DROID_MODES: "1", T3_ACP_DROID_MAX_AUTONOMY: maxAutonomy }, }), + }).pipe( + Effect.provide( + Layer.mock(AcpRegistryCatalog)({ resolve: () => Effect.die("runtime is injected") }), + ), ); - yield* runtime.events.pipe( - Stream.takeUntil((event) => event.type === "turn.terminal"), - Stream.runDrain, - ); - const writes: Array = []; - while (true) { - const event = yield* Queue.take(protocolEvents); - if (event.direction !== "outgoing") continue; - const method = rawProtocolMethod(event); - if (method === "session/prompt") return writes; - if ( - method === "session/set_config_option" && - rawProtocolRequestParam(event, "configId") === "autonomy_level" - ) { - writes.push(rawProtocolRequestParam(event, "value")); + const policy = ( + runtimeMode: "approval-required" | "full-access", + interactionMode: "default" | "plan" = "default", + ) => + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + runtimeMode, + interactionMode, + cwd: process.cwd(), + }); + const modelSelection: ModelSelection = { + instanceId, + model: "default", + options: [{ id: "autonomy_level", value: "auto-low" }], + }; + const runtime = yield* adapter.openSession({ + threadId, + providerSessionId: ProviderSessionId.make("provider-session-droid-autonomy"), + modelSelection, + runtimePolicy: policy("approval-required"), + }); + const providerThread = yield* runtime.ensureThread({ + threadId, + modelSelection, + runtimePolicy: policy("approval-required"), + }); + const now = yield* DateTime.now; + const autonomyWritesForTurn = Effect.fnUntraced(function* ( + ordinal: number, + runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy, + ) { + yield* runtime.startTurn( + makeTurnInput({ + threadId, + providerThread, + instanceId, + runtimePolicy, + now, + ordinal, + messageText: `Request ${ordinal}.`, + modelSelection, + }), + ); + yield* runtime.events.pipe( + Stream.takeUntil((event) => event.type === "turn.terminal"), + Stream.runDrain, + ); + const writes: Array = []; + while (true) { + const event = yield* Queue.take(protocolEvents); + if (event.direction !== "outgoing") continue; + const method = rawProtocolMethod(event); + if (method === "session/prompt") return writes; + if ( + method === "session/set_config_option" && + rawProtocolRequestParam(event, "configId") === "autonomy_level" + ) { + writes.push(rawProtocolRequestParam(event, "value")); + } } - } - }); + }); - assert.deepEqual( - yield* autonomyWritesForTurn(0, policy("approval-required")), - ["normal"], - "Droid starts at auto-high and the Autonomy Level choice must not outrank the policy", - ); - assert.deepEqual(yield* autonomyWritesForTurn(1, policy("full-access")), ["auto-high"]); - assert.deepEqual(yield* autonomyWritesForTurn(2, policy("full-access", "plan")), []); - assert.deepEqual( - yield* autonomyWritesForTurn(3, policy("approval-required")), - ["normal"], - "Leaving Plan must not restore the autonomy level an earlier policy set", - ); - }).pipe(Effect.provide(layerTest)), + assert.deepEqual( + yield* autonomyWritesForTurn(0, policy("approval-required")), + ["normal"], + "The policy's level is the only write: the composer's Autonomy Level choice is never sent", + ); + assert.deepEqual( + yield* autonomyWritesForTurn(1, policy("full-access")), + [maxAutonomy], + "Full access reaches the highest level the organization allows", + ); + assert.deepEqual(yield* autonomyWritesForTurn(2, policy("full-access", "plan")), []); + assert.deepEqual( + yield* autonomyWritesForTurn(3, policy("approval-required")), + ["normal"], + "Leaving Plan must not restore the autonomy level an earlier policy set", + ); + }).pipe(Effect.provide(layerTest)), ); it.live.each(["failed", "recovered", "cancelled"] as const)( diff --git a/packages/provider-acp-registry/src/server/droidAcp.ts b/packages/provider-acp-registry/src/server/droidAcp.ts index 378865e27e357..a6a0133877b31 100644 --- a/packages/provider-acp-registry/src/server/droidAcp.ts +++ b/packages/provider-acp-registry/src/server/droidAcp.ts @@ -84,22 +84,28 @@ const extractDroidElicitationForm: NonNullable, +): string | undefined { + const unrestricted = + policy.runtimeMode === "full-access" && policy.approvalPolicy === undefined && - policy.sandboxPolicy === undefined - ? "auto-high" - : "normal"; + policy.sandboxPolicy === undefined; + return (unrestricted ? DROID_LEVELS_HIGHEST_FIRST : ["normal"]).find((level) => + advertisedModeIds.includes(level), + ); } export const droidAcpFlavor = { extractElicitationForm: extractDroidElicitationForm, - // The composer's Autonomy Level choice would outrank the thread's runtime mode. + // The policy picks the level, so T3 never sends the composer's Autonomy Level choice. ownedModelOptionIds: ["autonomy_level"], lockSessionModeToPolicy: true, sessionModeForPolicy: droidSessionModeForPolicy, diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index 7abc540793aff..da77c40c2bd58 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -446,8 +446,10 @@ export interface AcpAdapterV2Flavor { */ readonly ownedModelOptionIds?: ReadonlyArray; readonly lockSessionModeToPolicy?: true; + /** `advertisedModeIds` are the modes the live session offers; an agent may reject any other. */ readonly sessionModeForPolicy?: ( policy: ProviderAdapter.ProviderAdapterV2RuntimePolicy, + advertisedModeIds: ReadonlyArray, ) => string | undefined; /** * Native select-option values to apply for a runtime policy (e.g. Kiro's @@ -7812,7 +7814,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( if (!advertisedValues.includes(selection.value)) continue; yield* runtime.setConfigOption(selection.id, selection.value); } - const policyMode = flavor.sessionModeForPolicy?.(runtimePolicy); + const policyMode = flavor.sessionModeForPolicy?.( + runtimePolicy, + (yield* runtime.getModeState)?.availableModes.map((mode) => mode.id) ?? [], + ); const modeLocked = flavor.lockSessionModeToPolicy && policyMode !== undefined; if (policyMode !== undefined) { yield* runtime.setMode(policyMode); From 0f98c521b7ba67eef4abc87fc8aee1066913e5d6 Mon Sep 17 00:00:00 2001 From: factory-ain3sh Date: Thu, 19 Nov 2026 20:19:36 +0000 Subject: [PATCH 3/5] fix(provider-acp): reconfigure when approval or sandbox policy changes A reused ACP session compared runtime mode but not the approval and sandbox policies a flavor can use to configure it. Compare those inputs with the last configured policy and keep equivalent values a no-op. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- .../Adapters/AcpAdapterV2.test.ts | 63 +++++++++++++++++++ packages/provider-acp/src/server/adapter.ts | 16 +++-- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index 245da746361b7..0c2ce4382f826 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -2451,6 +2451,69 @@ describe("AcpAdapterV2", () => { }).pipe(Effect.provide(layerTest)), ); + it.live("reconfigures a reused ACP session only when its policy changes", () => + Effect.gen(function* () { + const instanceId = ProviderInstanceId.make("acp-policy-changes"); + const threadId = ThreadId.make("thread-policy-changes"); + const modelSelection = { instanceId, model: "default" }; + let configurations = 0; + const adapter = yield* makeAcpAdapterV2({ + instanceId, + selfInvocation: yield* resolveSelfInvocation(), + flavor: { + driver: ACP_TEST_DRIVER, + capabilities: AcpProviderCapabilitiesV2, + onSessionConfigurationUpdate: () => Effect.sync(() => configurations++), + makeRuntime: makeMockRuntime({ + childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner, + mockAgentPath: yield* bundledMockAgentPath, + }), + }, + }); + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + runtimeMode: "approval-required", + interactionMode: "default", + cwd: process.cwd(), + }); + const runtime = yield* adapter.openSession({ + threadId, + providerSessionId: ProviderSessionId.make("session-policy-changes"), + modelSelection, + runtimePolicy, + }); + const providerThread = yield* runtime.ensureThread({ + threadId, + modelSelection, + runtimePolicy, + }); + const changes = []; + for (const [ordinal, restrictions] of [ + { approvalPolicy: "on-request" }, + { approvalPolicy: "on-request", sandboxPolicy: { type: "readOnly" } }, + { approvalPolicy: "on-request", sandboxPolicy: { type: "readOnly" } }, + ].entries()) { + const before = configurations; + yield* runtime.startTurn( + makeTurnInput({ + threadId, + providerThread, + instanceId, + modelSelection, + runtimePolicy: { ...runtimePolicy, ...restrictions }, + now: yield* DateTime.now, + ordinal, + }), + ); + yield* runtime.events.pipe( + Stream.takeUntil((event) => event.type === "turn.terminal"), + Stream.runDrain, + ); + changes.push(configurations - before); + } + assert.deepEqual(changes, [1, 1, 0], "approval changed, sandbox changed, unchanged"); + }).pipe(Effect.provide(layerTest)), + ); + it.live.each(["failed", "recovered", "cancelled"] as const)( "projects Mistral retry notices and their %s outcome", (outcome) => diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index 34f5b634c6c9b..4a8a4e8adfa0c 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -2251,9 +2251,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( }); const activeSelection = yield* Ref.make(null); const activeInteractionMode = yield* Ref.make(null); - const configuredRuntimeMode = yield* Ref.make< - ProviderAdapter.ProviderAdapterV2RuntimePolicy["runtimeMode"] | null - >(null); + const configuredRuntimePolicy = + yield* Ref.make(null); const promptInstructionStates = yield* Ref.make(new Map()); const promptRuntimeInstructions = yield* Ref.make(new Map()); // Unique markers keep delayed prompt completions from clearing later compactions. @@ -8269,7 +8268,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( } } yield* validateModelSelection(modelSelection); - yield* Ref.set(configuredRuntimeMode, runtimePolicy.runtimeMode); + yield* Ref.set(configuredRuntimePolicy, runtimePolicy); yield* ( flavor.onSessionConfigurationUpdate?.( yield* runtime.getConfigOptions, @@ -9169,11 +9168,18 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( } else { const configuredSelection = yield* Ref.get(activeSelection); const configuredInteractionMode = yield* Ref.get(activeInteractionMode); + const configuredPolicy = yield* Ref.get(configuredRuntimePolicy); if ( configuredSelection === null || !modelSelectionsEqual(configuredSelection, turnInput.modelSelection) || configuredInteractionMode !== turnInput.runtimePolicy.interactionMode || - (yield* Ref.get(configuredRuntimeMode)) !== turnInput.runtimePolicy.runtimeMode + configuredPolicy === null || + configuredPolicy.runtimeMode !== turnInput.runtimePolicy.runtimeMode || + !Equal.equals( + configuredPolicy.approvalPolicy, + turnInput.runtimePolicy.approvalPolicy, + ) || + !Equal.equals(configuredPolicy.sandboxPolicy, turnInput.runtimePolicy.sandboxPolicy) ) { const currentSessionSetup = yield* Ref.get(activeSessionSetup); if (currentSessionSetup === null) { From 7483cf5c53b1ac40a59ddad97c7453cd268b8778 Mon Sep 17 00:00:00 2001 From: factory-ain3sh Date: Sat, 21 Nov 2026 16:03:57 +0000 Subject: [PATCH 4/5] test(acp-registry): use main's local Droid settings in the autonomy case Main added a settings fixture for a local Droid command, so the autonomy case uses it and this branch's copy goes. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- .../src/orchestration-v2/Adapters/AcpAdapterV2.test.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index 03999ef590593..2c354b46d4f4d 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -105,10 +105,6 @@ import { const DEFAULT_GROK_SETTINGS = Schema.decodeSync(GrokSettings)({}); const DROID_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ agentId: "factory-droid" }); -const LOCAL_DROID_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ - source: "local", - commandPath: "/usr/local/bin/droid", -}); const DEVIN_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ agentId: "devin" }); const OMP_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ source: "local", @@ -2478,7 +2474,7 @@ describe("AcpAdapterV2", () => { settings: DROID_SETTINGS, maxAutonomy: "auto-medium", }, - { agent: "a local droid command", settings: LOCAL_DROID_SETTINGS, maxAutonomy: "auto-high" }, + { agent: "a local droid command", settings: DROID_LOCAL_SETTINGS, maxAutonomy: "auto-high" }, ])( "keeps Factory Droid's autonomy level on the thread's runtime mode for $agent", ({ settings, maxAutonomy }) => From ad663e9c5d9d0b6db0a7980371a2416e27692a41 Mon Sep 17 00:00:00 2001 From: factory-ain3sh Date: Tue, 24 Nov 2026 11:15:45 +0000 Subject: [PATCH 5/5] fix(acp-registry): Droid's saved autonomy level no longer overrides a Supervised thread Factory Droid starts an ACP session at the autonomy level saved in its own settings, and T3 never looked at the thread's permission mode when it configured a Droid session. A Droid saved at Auto (High) ran a Supervised thread without asking. When T3 applies a permission mode below Full access to a Droid session (a session's first configure, or a changed runtime mode) and the thread carries no level pick, lower an `auto-*` level to `normal`. A level picked in T3's menu is written as before, and on Full access nothing is imposed. `sessionModeForPolicy` gains a second argument, the session's mode state, passed only in that case. fx and Antigravity ignore it. On a thread that carries no level pick, a session approval does not survive a reload below Full access: T3 cannot tell the level Droid was granted from the one it saved, so Droid asks once more. The client keeps model options per model, so a thread whose model changed after the pick carries none either. This replaces the branch's earlier approach (a target level, an owned Autonomy Level option, a level ranking and a wider reuse guard), which overrode the level picked in T3's menu and raised Droid on Full access. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- apps/server/scripts/acp-mock-agent.ts | 50 +++- .../Adapters/AcpAdapterV2.test.ts | 257 ++++++++++-------- docs/user/providers-acp.md | 12 + .../src/server/adapter.ts | 7 +- .../src/server/droidAcp.ts | 45 +-- packages/provider-acp/src/server/adapter.ts | 30 +- 6 files changed, 223 insertions(+), 178 deletions(-) diff --git a/apps/server/scripts/acp-mock-agent.ts b/apps/server/scripts/acp-mock-agent.ts index 7cac9d6cc577e..e14b25b9aae14 100644 --- a/apps/server/scripts/acp-mock-agent.ts +++ b/apps/server/scripts/acp-mock-agent.ts @@ -23,11 +23,12 @@ const copilotModesProfile = process.env.T3_ACP_COPILOT_MODES === "1"; const copilotModeId = (name: string) => `https://agentclientprotocol.com/protocol/session-modes#${name}`; const modeOptionCategory = process.env.T3_ACP_MODE_OPTION_CATEGORY ?? "mode"; -// Factory Droid's modes are autonomy levels behind an `autonomy_level` option. An organization can -// cap them: Droid then starts no higher than the cap and advertises no level above it. +// Factory Droid's modes are autonomy levels behind an `autonomy_level` option. const droidModesProfile = process.env.T3_ACP_DROID_MODES === "1"; -const droidMaxAutonomy = process.env.T3_ACP_DROID_MAX_AUTONOMY ?? "auto-high"; const modeConfigId = droidModesProfile ? "autonomy_level" : "mode"; +// A prompt containing "Always allow this session ()" makes the mock Droid raise itself to +// that level, as approving a request for the session does. +const droidGrantPattern = /Always allow this session \(([\w-]+)\)/; // Comma-separated command names the mock advertises, so `/compact` support is testable. const advertisedCommandNames = (process.env.T3_ACP_AVAILABLE_COMMANDS ?? "") .split(",") @@ -128,7 +129,7 @@ let currentModeId = antigravityProfile : copilotModesProfile ? copilotModeId("agent") : droidModesProfile - ? droidMaxAutonomy + ? "auto-high" : "ask"; let currentModelId = antigravityProfile ? "gemini-test-low" : "default"; let parameterizedModelPicker = false; @@ -378,14 +379,6 @@ const antigravityModels = [ { modelId: "gemini-test-high", name: "Gemini Test High" }, ] satisfies ReadonlyArray; -const droidModes: ReadonlyArray = [ - { id: "normal", name: "Auto (Off)" }, - { id: "spec", name: "Spec" }, - { id: "auto-low", name: "Auto (Low)" }, - { id: "auto-medium", name: "Auto (Medium)" }, - { id: "auto-high", name: "Auto (High)" }, -]; - const availableModes: ReadonlyArray = antigravityProfile ? [ { id: "default", name: "Default" }, @@ -399,7 +392,12 @@ const availableModes: ReadonlyArray = antigravityProfile { id: copilotModeId("autopilot"), name: "Autopilot" }, ] : droidModesProfile - ? droidModes.slice(0, droidModes.findIndex((mode) => mode.id === droidMaxAutonomy) + 1) + ? [ + { id: "normal", name: "Auto (Off)" }, + { id: "auto-low", name: "Auto (Low)" }, + { id: "auto-medium", name: "Auto (Medium)" }, + { id: "auto-high", name: "Auto (High)" }, + ] : [ { id: "ask", @@ -893,7 +891,7 @@ const program = Effect.gen(function* () { yield* Deferred.await(delayedLoadReplied); yield* Effect.sleep(100); } - if (failSetModeConfigOption && request.configId === modeConfigId) { + if (failSetModeConfigOption && request.configId === "mode") { return yield* AcpError.AcpRequestError.invalidParams( "Mock invalid params for session/set_config_option", { @@ -903,7 +901,15 @@ const program = Effect.gen(function* () { ); } if (request.configId === modeConfigId && typeof request.value === "string") { + const changed = request.value !== currentModeId; currentModeId = request.value; + // Droid reports a changed level in a full config update before it answers. + if (droidModesProfile && changed) { + yield* agent.client.sessionUpdate({ + sessionId: request.sessionId, + update: { sessionUpdate: "config_option_update", configOptions: configOptions() }, + }); + } } if (request.configId === "model" && typeof request.value === "string") { currentModelId = request.value; @@ -1591,6 +1597,22 @@ const program = Effect.gen(function* () { }); } } + const grantedLevel = droidModesProfile + ? request.prompt + .map((block) => + block.type === "text" && typeof block.text === "string" + ? droidGrantPattern.exec(block.text)?.[1] + : undefined, + ) + .find((level) => level !== undefined) + : undefined; + if (grantedLevel !== undefined) { + currentModeId = grantedLevel; + yield* agent.client.sessionUpdate({ + sessionId: requestedSessionId, + update: { sessionUpdate: "config_option_update", configOptions: configOptions() }, + }); + } if (emitTrackedToolCallKindThenHang !== undefined) { yield* agent.client.sessionUpdate({ diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index 433f47765a26f..f5eab80e7f90d 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -760,6 +760,24 @@ function rawProtocolRequestParam( return typeof params === "object" && params !== null ? Reflect.get(params, key) : undefined; } +// The `autonomy_level` a decoded reply or session update reports in its config options. Raw +// incoming events are chunks, which can split a message. +function protocolAutonomyLevel(event: EffectAcpProtocol.AcpProtocolLogEvent): unknown { + if (event.stage !== "decoded" || !Array.isArray(event.payload)) return undefined; + const field = (value: unknown, key: string): unknown => + typeof value === "object" && value !== null ? Reflect.get(value, key) : undefined; + let level: unknown; + for (const message of event.payload) { + const options = + field(field(field(message, "exit"), "value"), "configOptions") ?? + field(field(field(message, "payload"), "update"), "configOptions"); + if (!Array.isArray(options)) continue; + const option = options.find((candidate) => field(candidate, "configId") === "autonomy_level"); + if (option !== undefined) level = field(option, "currentValue"); + } + return level; +} + function rawProtocolPromptTextBlocks( event: EffectAcpProtocol.AcpProtocolLogEvent, ): Array<{ type: "text"; text: string }> { @@ -2471,17 +2489,82 @@ describe("AcpAdapterV2", () => { }).pipe(Effect.provide(layerTest)); }); + // Each mock Droid session starts at auto-high. `writes` are T3's level writes before a turn's + // prompt; `level` is the last level Droid reported by then. it.live.each([ - { agent: "the registry agent", settings: DROID_SETTINGS, maxAutonomy: "auto-high" }, { - agent: "the registry agent under an organization cap", + agent: "the registry agent", settings: DROID_SETTINGS, - maxAutonomy: "auto-medium", + turns: [ + { runtimeMode: "approval-required", writes: ["normal"], level: "normal" }, + { + runtimeMode: "approval-required", + pick: "auto-high", + writes: ["auto-high"], + level: "auto-high", + }, + { runtimeMode: "full-access", writes: [], level: "auto-high" }, + { runtimeMode: "approval-required", writes: ["normal"], level: "normal" }, + ], }, - { agent: "a local droid command", settings: DROID_LOCAL_SETTINGS, maxAutonomy: "auto-high" }, - ])( - "keeps Factory Droid's autonomy level on the thread's runtime mode for $agent", - ({ settings, maxAutonomy }) => + { + agent: "a local droid command", + settings: DROID_LOCAL_SETTINGS, + turns: [ + { + runtimeMode: "auto-accept-edits", + otherOption: "example", + grant: "auto-low", + writes: ["normal"], + level: "normal", + }, + { + runtimeMode: "approval-required", + grant: "auto-medium", + writes: ["normal"], + level: "normal", + }, + { runtimeMode: "auto", grant: "auto-high", writes: ["normal"], level: "normal" }, + { runtimeMode: "auto", model: "composer-2", writes: [], level: "auto-high" }, + ], + }, + { + agent: "a session approval, a model change and new sessions", + settings: DROID_SETTINGS, + turns: [ + { + runtimeMode: "approval-required", + grant: "auto-low", + writes: ["normal"], + level: "normal", + }, + { runtimeMode: "approval-required", model: "composer-2", writes: [], level: "auto-low" }, + { + runtimeMode: "approval-required", + newSession: true, + pick: "auto-low", + writes: ["auto-low"], + level: "auto-low", + }, + { runtimeMode: "approval-required", newSession: true, writes: ["normal"], level: "normal" }, + ], + }, + { + agent: "a pick a managed limit drops", + settings: DROID_SETTINGS, + turns: [ + { + runtimeMode: "approval-required", + maxRuntimeMode: "approval-required", + pick: "auto-high", + writes: ["normal"], + level: "normal", + }, + ], + }, + ] as const)( + "lowers an unpicked Factory Droid level only while applying a permission mode below Full access, for $agent", + ({ settings, turns }) => Effect.gen(function* () { const protocolEvents = yield* Queue.unbounded(); const instanceId = ProviderInstanceId.make("droid-autonomy-test"); @@ -2495,65 +2578,74 @@ describe("AcpAdapterV2", () => { childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner, mockAgentPath: yield* bundledMockAgentPath, protocolEvents, - environment: { T3_ACP_DROID_MODES: "1", T3_ACP_DROID_MAX_AUTONOMY: maxAutonomy }, + environment: { T3_ACP_DROID_MODES: "1", T3_ACP_EMIT_EMPTY_DEFAULT_AGENT_OPTION: "1" }, }), }).pipe( Effect.provide( Layer.mock(AcpRegistryCatalog)({ resolve: () => Effect.die("runtime is injected") }), ), ); - const policy = ( - runtimeMode: "approval-required" | "full-access", - interactionMode: "default" | "plan" = "default", - ) => - ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ - runtimeMode, - interactionMode, + const turnInputs = turns.map((turn) => ({ + modelSelection: { + instanceId, + model: "model" in turn ? turn.model : "default", + options: [ + ...("pick" in turn ? [{ id: "autonomy_level", value: turn.pick }] : []), + ...("otherOption" in turn ? [{ id: "agent", value: turn.otherOption }] : []), + ], + }, + runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + runtimeMode: turn.runtimeMode, + interactionMode: "default", + ...("maxRuntimeMode" in turn ? { maxRuntimeMode: turn.maxRuntimeMode } : {}), cwd: process.cwd(), - }); - const modelSelection: ModelSelection = { - instanceId, - model: "default", - options: [{ id: "autonomy_level", value: "auto-low" }], - }; + }), + })); const runtime = yield* adapter.openSession({ threadId, providerSessionId: ProviderSessionId.make("provider-session-droid-autonomy"), - modelSelection, - runtimePolicy: policy("approval-required"), - }); - const providerThread = yield* runtime.ensureThread({ - threadId, - modelSelection, - runtimePolicy: policy("approval-required"), + ...turnInputs[0]!, }); + let providerThread = yield* runtime.ensureThread({ threadId, ...turnInputs[0]! }); const now = yield* DateTime.now; - const autonomyWritesForTurn = Effect.fnUntraced(function* ( - ordinal: number, - runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy, - ) { + const observed = []; + let level: unknown; + for (const [ordinal, turn] of turns.entries()) { + const input = turnInputs[ordinal]!; + if ("newSession" in turn) { + providerThread = yield* runtime.ensureThread({ + threadId, + ...input, + existingProviderThread: providerThread, + forceNewNativeThread: true, + }); + } yield* runtime.startTurn( makeTurnInput({ threadId, providerThread, instanceId, - runtimePolicy, now, ordinal, - messageText: `Request ${ordinal}.`, - modelSelection, + // The mock Droid raises itself to this level, as a session approval does. + messageText: + "grant" in turn + ? `Always allow this session (${turn.grant}).` + : `Request ${ordinal}.`, + ...input, }), ); - yield* runtime.events.pipe( - Stream.takeUntil((event) => event.type === "turn.terminal"), - Stream.runDrain, + const terminal = yield* runtime.events.pipe( + Stream.filter((event) => event.type === "turn.terminal"), + Stream.runHead, ); const writes: Array = []; while (true) { const event = yield* Queue.take(protocolEvents); + if (event.direction === "incoming") level = protocolAutonomyLevel(event) ?? level; if (event.direction !== "outgoing") continue; const method = rawProtocolMethod(event); - if (method === "session/prompt") return writes; + if (method === "session/prompt") break; if ( method === "session/set_config_option" && rawProtocolRequestParam(event, "configId") === "autonomy_level" @@ -2561,90 +2653,19 @@ describe("AcpAdapterV2", () => { writes.push(rawProtocolRequestParam(event, "value")); } } - }); - - assert.deepEqual( - yield* autonomyWritesForTurn(0, policy("approval-required")), - ["normal"], - "The policy's level is the only write: the composer's Autonomy Level choice is never sent", - ); - assert.deepEqual( - yield* autonomyWritesForTurn(1, policy("full-access")), - [maxAutonomy], - "Full access reaches the highest level the organization allows", - ); - assert.deepEqual(yield* autonomyWritesForTurn(2, policy("full-access", "plan")), []); + observed.push({ writes, level, status: Option.getOrThrow(terminal).status }); + } assert.deepEqual( - yield* autonomyWritesForTurn(3, policy("approval-required")), - ["normal"], - "Leaving Plan must not restore the autonomy level an earlier policy set", + observed, + turns.map((turn) => ({ + writes: [...turn.writes], + level: turn.level, + status: "completed" as const, + })), ); }).pipe(Effect.provide(layerTest)), ); - it.live("reconfigures a reused ACP session only when its policy changes", () => - Effect.gen(function* () { - const instanceId = ProviderInstanceId.make("acp-policy-changes"); - const threadId = ThreadId.make("thread-policy-changes"); - const modelSelection = { instanceId, model: "default" }; - let configurations = 0; - const adapter = yield* makeAcpAdapterV2({ - instanceId, - selfInvocation: yield* resolveSelfInvocation(), - flavor: { - driver: ACP_TEST_DRIVER, - capabilities: AcpProviderCapabilitiesV2, - onSessionConfigurationUpdate: () => Effect.sync(() => configurations++), - makeRuntime: makeMockRuntime({ - childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner, - mockAgentPath: yield* bundledMockAgentPath, - }), - }, - }); - const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ - runtimeMode: "approval-required", - interactionMode: "default", - cwd: process.cwd(), - }); - const runtime = yield* adapter.openSession({ - threadId, - providerSessionId: ProviderSessionId.make("session-policy-changes"), - modelSelection, - runtimePolicy, - }); - const providerThread = yield* runtime.ensureThread({ - threadId, - modelSelection, - runtimePolicy, - }); - const changes = []; - for (const [ordinal, restrictions] of [ - { approvalPolicy: "on-request" }, - { approvalPolicy: "on-request", sandboxPolicy: { type: "readOnly" } }, - { approvalPolicy: "on-request", sandboxPolicy: { type: "readOnly" } }, - ].entries()) { - const before = configurations; - yield* runtime.startTurn( - makeTurnInput({ - threadId, - providerThread, - instanceId, - modelSelection, - runtimePolicy: { ...runtimePolicy, ...restrictions }, - now: yield* DateTime.now, - ordinal, - }), - ); - yield* runtime.events.pipe( - Stream.takeUntil((event) => event.type === "turn.terminal"), - Stream.runDrain, - ); - changes.push(configurations - before); - } - assert.deepEqual(changes, [1, 1, 0], "approval changed, sandbox changed, unchanged"); - }).pipe(Effect.provide(layerTest)), - ); - it.live.each(["failed", "recovered", "cancelled"] as const)( "projects Mistral retry notices and their %s outcome", (outcome) => diff --git a/docs/user/providers-acp.md b/docs/user/providers-acp.md index 453c777e3c8c0..1133a425786a6 100644 --- a/docs/user/providers-acp.md +++ b/docs/user/providers-acp.md @@ -112,6 +112,18 @@ approval rules. They start in their own default mode, and their mode picker in t menu switches it. How far an agent is confined depends on that mode and the agent's own settings, so use its sandbox and permission controls when that matters. +A new Factory Droid session starts at the autonomy level saved in Droid's own settings. On a thread +below **Full access** whose current model has no level picked in the menu, T3 Code switches Droid +from Auto (Low), (Medium), or (High) to Auto (Off), where Droid offers it, when it starts or reloads +the session and when the thread's permission mode changes. A session approval that had raised +Droid's level no longer covers the edits or commands that depended on it, so Droid can ask again. +Its own command rules still apply. A level picked in the menu applies in every permission mode, so +Auto (High) lets Droid act without asking even on **Supervised**, unless a +[managed policy](./managed-policy.md#permission-modes) caps the permission mode. As with any model +option, T3 Code keeps the pick with the model it was made on, so a thread carries no level after +you change to a model you have not picked one for. If a session or a turn fails while switching to +Auto (Off), update Droid to 0.236.0 or later. + When a registry agent asks for approval, T3 Code answers by the thread's [permission mode](./permission-modes.md): **Supervised** shows the request in the conversation, **Auto-accept edits** approves edits and shows the rest, and **Auto** and **Full access** approve diff --git a/packages/provider-acp-registry/src/server/adapter.ts b/packages/provider-acp-registry/src/server/adapter.ts index a3101f65ddde0..be80802efb9ee 100644 --- a/packages/provider-acp-registry/src/server/adapter.ts +++ b/packages/provider-acp-registry/src/server/adapter.ts @@ -9,7 +9,7 @@ import { extractDevinSubagentUpdate, devinAnswerablePermissionOptions, } from "./devinAcp.ts"; -import { droidAcpFlavor } from "./droidAcp.ts"; +import { droidSessionModeForPolicy, extractDroidElicitationForm } from "./droidAcp.ts"; import { makeKimiPromptOutcomeWatch } from "./kimiAcp.ts"; import { extractOmpElicitationForm } from "./ompAcp.ts"; import { extractOpenCodeElicitationForm } from "./opencodeAcp.ts"; @@ -277,7 +277,10 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu promptFailure: (cause) => acpRegistryPromptFailure(isVibe ? "mistral-vibe" : registryAgentId, cause), ...(isDroid - ? droidAcpFlavor + ? { + extractElicitationForm: extractDroidElicitationForm, + sessionModeForPolicy: droidSessionModeForPolicy, + } : isOmp ? { extractElicitationForm: extractOmpElicitationForm } : isOpenCode diff --git a/packages/provider-acp-registry/src/server/droidAcp.ts b/packages/provider-acp-registry/src/server/droidAcp.ts index a6a0133877b31..45b412e6625ce 100644 --- a/packages/provider-acp-registry/src/server/droidAcp.ts +++ b/packages/provider-acp-registry/src/server/droidAcp.ts @@ -1,6 +1,5 @@ import { type OrchestrationV2UserInputQuestion, TrimmedNonEmptyString } from "@t3tools/contracts"; import type { AcpAdapterV2Flavor } from "@t3tools/provider-acp/server/adapter"; -import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as Predicate from "effect/Predicate"; import * as Schema from "effect/Schema"; @@ -27,9 +26,9 @@ const isDroidCompanion = Schema.is(Schema.Struct({ type: Schema.Literal("string" // Droid pairs each choice with an optional *_other field. The client already // offers custom answers, so hide the companion and restore it in the response. -const extractDroidElicitationForm: NonNullable = ( - request, -) => { +export const extractDroidElicitationForm: NonNullable< + AcpAdapterV2Flavor["extractElicitationForm"] +> = (request) => { if (request.mode !== "form" || !isDroidForm(request.requestedSchema)) return undefined; const { properties, required } = request.requestedSchema; const questions: Array = []; @@ -84,29 +83,15 @@ const extractDroidElicitationForm: NonNullable, -): string | undefined { - const unrestricted = - policy.runtimeMode === "full-access" && - policy.approvalPolicy === undefined && - policy.sandboxPolicy === undefined; - return (unrestricted ? DROID_LEVELS_HIGHEST_FIRST : ["normal"]).find((level) => - advertisedModeIds.includes(level), - ); -} - -export const droidAcpFlavor = { - extractElicitationForm: extractDroidElicitationForm, - // The policy picks the level, so T3 never sends the composer's Autonomy Level choice. - ownedModelOptionIds: ["autonomy_level"], - lockSessionModeToPolicy: true, - sessionModeForPolicy: droidSessionModeForPolicy, -} satisfies Partial; +// Droid's modes are its autonomy levels: `normal` is Auto (Off), and the `auto-*` levels can act +// without asking. +export const droidSessionModeForPolicy: NonNullable = ( + policy, + unpickedMode, +) => + policy.runtimeMode !== "full-access" && + unpickedMode !== undefined && + ["auto-low", "auto-medium", "auto-high"].includes(unpickedMode.currentModeId) && + unpickedMode.availableModes.some((mode) => mode.id === "normal") + ? "normal" + : undefined; diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index 2e4955fc42d8e..42ba58d13e5bf 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -483,10 +483,14 @@ export interface AcpAdapterV2Flavor { */ readonly ownedModelOptionIds?: ReadonlyArray; readonly lockSessionModeToPolicy?: true; - /** `advertisedModeIds` are the modes the live session offers; an agent may reject any other. */ + /** + * Mode to set on each configure, or none. `unpickedMode` is the session's mode state, given only + * while applying the permission mode (a session's first configure, or a changed runtime mode) + * to a thread that picks no mode. + */ readonly sessionModeForPolicy?: ( policy: ProviderAdapter.ProviderAdapterV2RuntimePolicy, - advertisedModeIds: ReadonlyArray, + unpickedMode: AcpSessionModeState | undefined, ) => string | undefined; /** * Native select-option values to apply for a runtime policy (e.g. Kiro's @@ -2303,6 +2307,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( rootForegroundWork = undefined; agentRequests.clear(); nativeChildren.clear(); + yield* Ref.set(configuredRuntimeMode, null); yield* Ref.set(activeSessionSetup, setup); }); const activeSelection = yield* Ref.make(null); @@ -2325,8 +2330,9 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( } return modes; }); - const configuredRuntimePolicy = - yield* Ref.make(null); + const configuredRuntimeMode = yield* Ref.make< + ProviderAdapter.ProviderAdapterV2RuntimePolicy["runtimeMode"] | null + >(null); const promptInstructionStates = yield* Ref.make(new Map()); const promptRuntimeInstructions = yield* Ref.make(new Map()); // Unique markers keep delayed prompt completions from clearing later compactions. @@ -8290,7 +8296,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( } const policyMode = flavor.sessionModeForPolicy?.( runtimePolicy, - (yield* runtime.getModeState)?.availableModes.map((mode) => mode.id) ?? [], + (yield* Ref.get(configuredRuntimeMode)) !== runtimePolicy.runtimeMode && + !optionSelections.some((selection) => isModeChoice(selection.id)) + ? yield* runtime.getModeState + : undefined, ); const modeLocked = flavor.lockSessionModeToPolicy && policyMode !== undefined; if (policyMode !== undefined) { @@ -8380,7 +8389,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( } yield* validateModelSelection(modelSelection); yield* Ref.set(configuredModes, yield* readModes); - yield* Ref.set(configuredRuntimePolicy, runtimePolicy); + yield* Ref.set(configuredRuntimeMode, runtimePolicy.runtimeMode); yield* ( flavor.onSessionConfigurationUpdate?.( yield* runtime.getConfigOptions, @@ -9372,18 +9381,11 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( } else { const configuredSelection = yield* Ref.get(activeSelection); const configuredInteractionMode = yield* Ref.get(activeInteractionMode); - const configuredPolicy = yield* Ref.get(configuredRuntimePolicy); if ( configuredSelection === null || !modelSelectionsEqual(configuredSelection, turnInput.modelSelection) || configuredInteractionMode !== turnInput.runtimePolicy.interactionMode || - configuredPolicy === null || - configuredPolicy.runtimeMode !== turnInput.runtimePolicy.runtimeMode || - !Equal.equals( - configuredPolicy.approvalPolicy, - turnInput.runtimePolicy.approvalPolicy, - ) || - !Equal.equals(configuredPolicy.sandboxPolicy, turnInput.runtimePolicy.sandboxPolicy) + (yield* Ref.get(configuredRuntimeMode)) !== turnInput.runtimePolicy.runtimeMode ) { const currentSessionSetup = yield* Ref.get(activeSessionSetup); if (currentSessionSetup === null) {