Skip to content

Commit d49cca0

Browse files
committed
Declare plan support for ACP agents and translate it via session modes
What was wrong: the plan action and edit-past-message gates were already capability-driven (composerActions "plan"; capabilities.fork), but ACP agents could not declare either: the ACP provider hardcoded composerActions to [] and typed AcpAgentDefinition.fork as none|tip, so every ACP agent was excluded by declaration shape rather than by capability. What was changed: AcpAgentDefinition gains supportsPlan (mirroring supportsManualCompaction), threaded through the customAgents setting and mapped to composerActions ["plan"] in the declaration; acp-omp declares it. The ACP bridge now reads the session modes agents advertise (session/new, session/load, session/fork results and current_mode_update notifications) and, when the agent advertises a plan mode, drives it with session/set_mode on plan turns, strips the /plan command mention from the prompt, and returns the session to its initial mode afterward; agents that report no modes keep byte-identical text passthrough. Session rewind stays undeclarable for ACP agents: ACP v1 session/fork is tip-only with no fork-point selector and reports no per-turn checkpoints, so no shipped or custom ACP agent can honestly declare checkpoint rewind today. What was verified: pnpm exec turbo run typecheck test lint --continue plus pnpm format:check. provider-bridge-acp typecheck is clean and all 317 tests pass, including the new ones: declaration mapping (composerActions ["plan"] only for agents declaring it), wire modes/current_mode_update parsing, and bridge plan-turn translation (set_mode "plan" precedes session/prompt with the mention stripped; a no-modes agent gets no set_mode and untouched text; the mode resets to the initial mode after the turn). The server suites that consume provider declarations pass solo (first-party-provider-plugins, plugin-install, plugin-update). Remaining failures are pre-existing on main f6868ad, each verified by stash-rerun on a clean tree: secret-storage concurrent-creators, server install-machine-script (macOS Abort trap: 6 on the spawned host-daemon), host-workspace workspace-diff/provisioning, and 183 files flagged by format:check from the pinned oxfmt 0.64.0 at head (formatter default drift); the new code matches the dominant committed style of the files it touches. AGENT GENERATED
1 parent f6868ad commit d49cca0

12 files changed

Lines changed: 378 additions & 10 deletions

File tree

‎docs/configuration.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,13 @@ entry is a path or `{"path": ..., "recursive": true, "ancestors": true}` for
408408
an agent that nests skills or reads them from every ancestor directory),
409409
`permissionCli` (permission-mode launch flags), `supportsManualCompaction`
410410
(only if the agent accepts an explicit compaction request — bb hides
411-
`/compact` otherwise), and `dialect` (the vendor side channels bb reads for
412-
the agent: `cursor`, `opencode`, `omp`, or `grok`).
411+
`/compact` otherwise), `supportsPlan` (only if the agent exposes a `plan`
412+
session mode over ACP — bb offers the composer's `/plan` action and switches
413+
the session into that mode for plan turns), and `dialect` (the vendor side
414+
channels bb reads for the agent: `cursor`, `opencode`, `omp`, or `grok`).
415+
Editing a past message (session rewind) stays unavailable for ACP agents:
416+
ACP `session/fork` can only fork a session's current end, never an earlier
417+
point, so no `fork` declaration is offered for these entries.
413418

414419
The change applies immediately: the plugin re-registers its providers when the
415420
setting changes, with no restart and no `config refresh`.

‎packages/provider-bridge-acp/src/bridge/bridge.test.ts‎

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { tmpdir } from "node:os";
1111
import { dirname, join, resolve } from "node:path";
1212
import { fileURLToPath } from "node:url";
1313
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
14-
import { createStandaloneBuiltinCompactCommandInput } from "@bb/domain";
14+
import {
15+
createBuiltinPlanCommandTextInput,
16+
createStandaloneBuiltinCompactCommandInput,
17+
} from "@bb/domain";
1518
import type { DynamicTool, ReasoningLevel } from "@bb/domain";
1619
import {
1720
PROVIDER_BRIDGE_PROTOCOL_VERSION,
@@ -145,6 +148,7 @@ function executionOptions(args: {
145148
envVars?: Record<string, string>;
146149
instructions?: string;
147150
model?: string;
151+
promptMode?: "plan";
148152
reasoningLevel?: ReasoningLevel;
149153
serviceTier?: "default" | "fast";
150154
providerOptions?: Record<string, unknown>;
@@ -167,6 +171,7 @@ function executionOptions(args: {
167171
...(args.envVars ? { envVars: args.envVars } : {}),
168172
...(args.instructions ? { instructions: args.instructions } : {}),
169173
...(args.model ? { model: args.model } : {}),
174+
...(args.promptMode ? { promptMode: args.promptMode } : {}),
170175
...(args.reasoningLevel ? { reasoningLevel: args.reasoningLevel } : {}),
171176
...(args.serviceTier ? { serviceTier: args.serviceTier } : {}),
172177
...(args.providerOptions ? { providerOptions: args.providerOptions } : {}),
@@ -494,6 +499,24 @@ function agentMessageTexts(): string[] {
494499
return order.map((id) => textsByItemId.get(id) ?? "");
495500
}
496501

502+
function promptTexts(request: LoggedAcpRequest | undefined): string[] {
503+
const prompt = request?.params?.["prompt"];
504+
if (!Array.isArray(prompt)) {
505+
return [];
506+
}
507+
return prompt.flatMap((block) => {
508+
if (
509+
typeof block === "object" &&
510+
block !== null &&
511+
"text" in block &&
512+
typeof block.text === "string"
513+
) {
514+
return [block.text];
515+
}
516+
return [];
517+
});
518+
}
519+
497520
function callDynamicToolBridge(args: {
498521
callId: string;
499522
host: string;
@@ -3318,4 +3341,94 @@ describe("acp bridge", () => {
33183341
message: expect.stringContaining("acpLaunchSpec"),
33193342
});
33203343
});
3344+
3345+
it("enters the agent's plan session mode and strips the plan command mention", async () => {
3346+
const requestLog = join(workspaceDir, "plan-mode-requests.jsonl");
3347+
const { providerThreadId } = await startThread({
3348+
envVars: {
3349+
FAKE_ACP_SESSION_MODES: "1",
3350+
FAKE_ACP_REQUEST_LOG: requestLog,
3351+
},
3352+
});
3353+
3354+
const id = sendTurnRequest("turn/start", providerThreadId, {
3355+
input: [createBuiltinPlanCommandTextInput("ship it")],
3356+
options: executionOptions({ promptMode: "plan" }),
3357+
});
3358+
await waitForResponse(id);
3359+
await waitForTurnCompleted();
3360+
3361+
const requests = loggedAcpRequests(requestLog);
3362+
const setModeIndex = requests.findIndex(
3363+
(request) => request.method === "session/set_mode",
3364+
);
3365+
const promptIndex = requests.findIndex(
3366+
(request) => request.method === "session/prompt",
3367+
);
3368+
expect(setModeIndex).toBeGreaterThanOrEqual(0);
3369+
expect(setModeIndex).toBeLessThan(promptIndex);
3370+
expect(requests[setModeIndex]?.params).toMatchObject({ modeId: "plan" });
3371+
expect(promptTexts(requests[promptIndex])).toEqual(["ship it"]);
3372+
});
3373+
3374+
it("leaves plan turns untouched for agents that report no session modes", async () => {
3375+
const requestLog = join(workspaceDir, "no-modes-requests.jsonl");
3376+
const { providerThreadId } = await startThread({
3377+
envVars: {
3378+
FAKE_ACP_REQUEST_LOG: requestLog,
3379+
},
3380+
});
3381+
3382+
const id = sendTurnRequest("turn/start", providerThreadId, {
3383+
input: [createBuiltinPlanCommandTextInput("ship it")],
3384+
options: executionOptions({ promptMode: "plan" }),
3385+
});
3386+
await waitForResponse(id);
3387+
await waitForTurnCompleted();
3388+
3389+
const requests = loggedAcpRequests(requestLog);
3390+
expect(
3391+
requests.filter((request) => request.method === "session/set_mode"),
3392+
).toEqual([]);
3393+
expect(
3394+
promptTexts(
3395+
requests.find((request) => request.method === "session/prompt"),
3396+
),
3397+
).toEqual(["/plan ship it"]);
3398+
});
3399+
3400+
it("returns the agent to its initial session mode after a plan turn", async () => {
3401+
const requestLog = join(workspaceDir, "plan-mode-reset-requests.jsonl");
3402+
const { providerThreadId } = await startThread({
3403+
envVars: {
3404+
FAKE_ACP_SESSION_MODES: "1",
3405+
FAKE_ACP_REQUEST_LOG: requestLog,
3406+
},
3407+
});
3408+
3409+
const planTurnId = sendTurnRequest("turn/start", providerThreadId, {
3410+
input: [createBuiltinPlanCommandTextInput("look around")],
3411+
options: executionOptions({ promptMode: "plan" }),
3412+
});
3413+
await waitForResponse(planTurnId);
3414+
await waitForTurnCompleted();
3415+
3416+
const normalTurnId = sendTurnRequest("turn/start", providerThreadId, {
3417+
input: [{ type: "text", text: "go ahead" }],
3418+
});
3419+
await waitForResponse(normalTurnId);
3420+
await waitForTurnCompleted();
3421+
3422+
expect(
3423+
loggedAcpRequests(requestLog)
3424+
.filter((request) => request.method === "session/set_mode")
3425+
.map((request) => request.params?.["modeId"]),
3426+
).toEqual(["plan", "default"]);
3427+
const promptRequests = loggedAcpRequests(requestLog).filter(
3428+
(request) => request.method === "session/prompt",
3429+
);
3430+
expect(promptTexts(promptRequests[promptRequests.length - 1])).toEqual([
3431+
"go ahead",
3432+
]);
3433+
});
33213434
});

‎packages/provider-bridge-acp/src/bridge/bridge.ts‎

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
isStandaloneBuiltinCompactCommand,
33
pendingInteractionResolutionSchema,
44
reasoningEffortsForLevels,
5+
removeCommandMentionsFromPromptInput,
56
} from "@bb/domain";
67
import type { AvailableModel, PromptInput, ReasoningLevel } from "@bb/domain";
78
import { acpLaunchSpecSchema, type AcpLaunchSpec } from "../launch-spec.js";
@@ -98,6 +99,9 @@ import {
9899
acpSessionForkResultSchema,
99100
acpSessionNewResultSchema,
100101
acpSessionNotificationParamsSchema,
102+
acpCurrentModeUpdateSchema,
103+
acpSetModeResultSchema,
104+
type AcpSessionModes,
101105
acpAgentMessageChunkUpdateSchema,
102106
extractAcpContentText,
103107
acpUsageUpdateSchema,
@@ -154,9 +158,16 @@ interface PendingAcpPermission {
154158
interface AcpPendingTurnInput {
155159
clientRequestId: string;
156160
input: PromptInput[];
161+
promptMode: "plan" | undefined;
157162
requestId: AcpBridgeRequestId | null;
158163
}
159164

165+
interface AcpSessionModeState {
166+
planModeId: string;
167+
resetModeId: string;
168+
currentModeId: string;
169+
}
170+
160171
interface AcpThreadSession {
161172
bbThreadId: string;
162173
providerThreadId: string;
@@ -166,6 +177,7 @@ interface AcpThreadSession {
166177
connection: AcpAgentConnection;
167178
supportsImageInput: boolean;
168179
supportsLoadSession: boolean;
180+
modeState: AcpSessionModeState | null;
169181
policy: AcpSessionPolicy;
170182
pendingInstructions: string | undefined;
171183
activePromptKind: "turn" | "compaction" | null;
@@ -1298,6 +1310,64 @@ function buildPromptContentBlocks(
12981310
return blocks;
12991311
}
13001312

1313+
const ACP_PLAN_MODE_ID = "plan";
1314+
1315+
function acpSessionModeState(
1316+
modes: AcpSessionModes | undefined,
1317+
): AcpSessionModeState | null {
1318+
if (modes === undefined) {
1319+
return null;
1320+
}
1321+
const planMode = modes.availableModes.find(
1322+
(mode) => mode.id === ACP_PLAN_MODE_ID,
1323+
);
1324+
if (planMode === undefined) {
1325+
return null;
1326+
}
1327+
return {
1328+
planModeId: planMode.id,
1329+
resetModeId: modes.currentModeId,
1330+
currentModeId: modes.currentModeId,
1331+
};
1332+
}
1333+
1334+
function planModeTurnInput(
1335+
session: AcpThreadSession,
1336+
pending: AcpPendingTurnInput,
1337+
): PromptInput[] {
1338+
if (pending.promptMode !== "plan" || session.modeState === null) {
1339+
return pending.input;
1340+
}
1341+
return removeCommandMentionsFromPromptInput(pending.input, {
1342+
trigger: "/",
1343+
name: ACP_PLAN_MODE_ID,
1344+
});
1345+
}
1346+
1347+
async function reconcilePlanMode(
1348+
session: AcpThreadSession,
1349+
pending: AcpPendingTurnInput,
1350+
): Promise<void> {
1351+
const modeState = session.modeState;
1352+
if (modeState === null) {
1353+
return;
1354+
}
1355+
const targetModeId =
1356+
pending.promptMode === "plan" ? modeState.planModeId : modeState.resetModeId;
1357+
if (modeState.currentModeId === targetModeId) {
1358+
return;
1359+
}
1360+
await session.connection.request({
1361+
method: "session/set_mode",
1362+
params: {
1363+
sessionId: session.providerThreadId,
1364+
modeId: targetModeId,
1365+
},
1366+
resultSchema: acpSetModeResultSchema,
1367+
});
1368+
modeState.currentModeId = targetModeId;
1369+
}
1370+
13011371
function findOptionIdByKinds(
13021372
options: AcpPermissionOption[],
13031373
kinds: AcpPermissionOption["kind"][],
@@ -1706,6 +1776,7 @@ async function startAgentSession(
17061776
connection,
17071777
supportsImageInput: false,
17081778
supportsLoadSession: false,
1779+
modeState: null,
17091780
policy: {
17101781
permissionMode: params.permissionMode,
17111782
workspaceWriteRoots: params.workspaceWriteRoots,
@@ -1776,6 +1847,7 @@ async function startAgentSession(
17761847
let sessionId: string | undefined;
17771848
let loadedConfigOptions: readonly AcpConfigOption[] | undefined;
17781849
let loadedModels: AcpSessionModels | undefined;
1850+
let loadedModes: AcpSessionModes | undefined;
17791851
if (request.kind === "fork") {
17801852
const forkedSession = await connection.request({
17811853
method: "session/fork",
@@ -1797,6 +1869,7 @@ async function startAgentSession(
17971869
sessionId = forkedSession.sessionId;
17981870
loadedConfigOptions = forkedSession.configOptions;
17991871
loadedModels = forkedSession.models;
1872+
loadedModes = forkedSession.modes;
18001873
} else if (request.kind === "resume" && supportsLoadSession) {
18011874
session.loading = true;
18021875
session.loadingSessionId = request.resumeProviderThreadId;
@@ -1813,6 +1886,7 @@ async function startAgentSession(
18131886
});
18141887
loadedConfigOptions = configState?.configOptions;
18151888
loadedModels = configState?.models;
1889+
loadedModes = configState?.modes;
18161890
sessionId = request.resumeProviderThreadId;
18171891
} catch {
18181892
sessionId = undefined;
@@ -1832,6 +1906,7 @@ async function startAgentSession(
18321906
resultSchema: acpSessionNewResultSchema,
18331907
});
18341908
sessionId = newSession.sessionId;
1909+
loadedModes = newSession.modes;
18351910
await selectAcpNativeModel({
18361911
connection,
18371912
sessionId,
@@ -1867,6 +1942,8 @@ async function startAgentSession(
18671942
}
18681943
}
18691944

1945+
session.modeState = acpSessionModeState(loadedModes);
1946+
18701947
if (session.stopping) {
18711948
throw new Error(
18721949
`ACP session for thread "${bbThreadId}" was released during construction`,
@@ -2050,11 +2127,15 @@ function runTurn(
20502127
session.cancelRequested = false;
20512128
try {
20522129
session.promptRequestPending = true;
2130+
await reconcilePlanMode(session, pending);
20532131
const promptResult = session.connection.request({
20542132
method: "session/prompt",
20552133
params: {
20562134
sessionId: session.providerThreadId,
2057-
prompt: buildPromptContentBlocks(session, pending.input),
2135+
prompt: buildPromptContentBlocks(
2136+
session,
2137+
planModeTurnInput(session, pending),
2138+
),
20582139
},
20592140
resultSchema: acpPromptResultSchema,
20602141
});
@@ -2242,6 +2323,14 @@ function handleAgentNotification(
22422323
if (parsed.data.sessionId !== session.providerThreadId) {
22432324
return;
22442325
}
2326+
if (session.modeState !== null) {
2327+
const modeUpdate = acpCurrentModeUpdateSchema.safeParse(
2328+
parsed.data.update,
2329+
);
2330+
if (modeUpdate.success) {
2331+
session.modeState.currentModeId = modeUpdate.data.currentModeId;
2332+
}
2333+
}
22452334
if (session.activePromptKind === "compaction") {
22462335
const chunk = acpAgentMessageChunkUpdateSchema.safeParse(
22472336
parsed.data.update,
@@ -2602,6 +2691,7 @@ async function handleRequest(
26022691
const pending: AcpPendingTurnInput = {
26032692
clientRequestId: params.clientRequestId,
26042693
input: params.input,
2694+
promptMode: params.options.promptMode,
26052695
requestId: request.id,
26062696
};
26072697
if (isStandaloneBuiltinCompactCommand(params.input)) {
@@ -2629,6 +2719,7 @@ async function handleRequest(
26292719
session.queuedInputs.push({
26302720
clientRequestId: params.clientRequestId,
26312721
input: params.input,
2722+
promptMode: params.options.promptMode,
26322723
requestId: null,
26332724
});
26342725
requestSteerCancel(session);

0 commit comments

Comments
 (0)