opencode-claude-code-acpbridge 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,7 +19,12 @@ export declare class ACPOrchestratorModel implements LanguageModelV3 {
19
19
  private agent;
20
20
  private connection;
21
21
  private connecting;
22
- private current;
22
+ /** Live conversations, keyed by OpenCode sessionID (or the conversation hash).
23
+ * ONE state per conversation: a single shared state made two open chats — or a
24
+ * subagent — tear each other's session down and replay the history every turn. */
25
+ private readonly sessions;
26
+ /** Same states indexed by ACP sessionId, to route agent-initiated callbacks. */
27
+ private readonly byAcpSession;
23
28
  private idSeq;
24
29
  private promptCaps;
25
30
  constructor(config: ACPModelConfig);
@@ -29,14 +34,43 @@ export declare class ACPOrchestratorModel implements LanguageModelV3 {
29
34
  }>;
30
35
  doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
31
36
  private onStart;
37
+ /** Enqueue if a stream is attached; otherwise BUFFER. The stream is closed between
38
+ * a tool-call and its continuation, and text/thought chunks keep arriving on the
39
+ * (independent) ACP stdio channel meanwhile — dropping them truncated answers and
40
+ * hid the reasoning block entirely. */
41
+ private emit;
42
+ private flushPending;
32
43
  private onPromptDone;
33
44
  private onPromptError;
34
45
  /** Fired by the MCP host when the agent calls an OpenCode tool. */
35
46
  private onToolCall;
47
+ /** Map approve/reject to one of the options the agent offered (by kind/optionId). */
48
+ private permOutcome;
49
+ /** Tool name the agent wants permission for. The ACP toolCall carries NO bare
50
+ * name — `title` is a human label like "Read /path", "Write /path", "Skill" — so
51
+ * we take the first token. This becomes the permission key, so per-tool rules
52
+ * (`permission: { Read: … }`) match. The full title travels separately as metadata. */
53
+ private permToolName;
54
+ /** Extract the markdown plan from an ExitPlanMode (`switch_mode`) tool call: it rides
55
+ * in `rawInput.plan`, with the tool-call text content as a fallback. */
56
+ private planText;
57
+ /** ACP requestPermission → OpenCode `ask`, via the claude_permission meta-tool.
58
+ * Deferred: returns a Promise the agent awaits until OpenCode's verdict comes
59
+ * back as the meta-tool's result (resolved in onStart's continuation branch). */
60
+ private onRequestPermission;
61
+ /** Emit a claude_permission tool-call to OpenCode (same deferred pattern as a
62
+ * real tool-call): OpenCode applies its `ask` permission and returns the
63
+ * verdict as the tool-result on the next doStream. */
64
+ private emitPermissionCall;
36
65
  /** Fired by the ACP client on session/update. */
37
66
  private onSessionUpdate;
38
67
  private closeBlocks;
39
68
  private endTurn;
69
+ /** Keep at most MAX_LIVE_SESSIONS conversations alive; tear down the oldest idle ones
70
+ * (never one with work in flight) so hosts and agent sessions don't pile up. */
71
+ private evictIdleSessions;
72
+ /** Resolve every outstanding bridged permission as denied so the agent unblocks. */
73
+ private drainPermissions;
40
74
  /** Provider config overlaid with per-call `providerOptions.acp` (per-agent mode/effort/…). */
41
75
  private effectiveCtrl;
42
76
  /** Apply runtime config (mode/effort) to a live ACP session via set_mode/set_config_option. */
@@ -44,23 +78,72 @@ export declare class ACPOrchestratorModel implements LanguageModelV3 {
44
78
  private ensureConnected;
45
79
  private connect;
46
80
  private onCancel;
81
+ /** If a cancel was ignored (deferred work in flight) but no continuation comes,
82
+ * force teardown so the agent doesn't stay blocked. Cleared by a continuation. */
83
+ private armCancelWatchdog;
84
+ private clearCancelWatchdog;
47
85
  cleanup(): void;
48
86
  private convertTools;
87
+ /** Nudges the agent can only get from the tool description. Under the default
88
+ * `systemPromptMode: "preset"` OpenCode's system prompt never reaches the agent,
89
+ * so the instruction that would normally push it toward `question` is missing —
90
+ * and its own `AskUserQuestion` is disabled by the ACP agent. Without this the
91
+ * agent silently assumes instead of asking. A tool description is NOT a system
92
+ * prompt, so this doesn't affect how Anthropic bills the session. */
93
+ private toolDescription;
49
94
  /** Text of the first user message — stable identifier for the conversation. */
50
95
  private firstUserText;
96
+ /** The conversation proper: system messages are excluded because they're forwarded
97
+ * separately (or not at all) and OpenCode rewrites them every turn — including them
98
+ * would make every history comparison look like a divergence. */
99
+ private history;
100
+ /** Cheap, stable per-message identity. Deliberately keyed on tool-call IDs rather
101
+ * than payloads: it must survive re-serialization but change if the turn changes. */
102
+ private msgKey;
103
+ /** How the incoming history relates to what the agent already knows.
104
+ * - append → normal turn (or another agent ran turns meanwhile): send the tail.
105
+ * - revert → the user rewound: the agent can't unremember, so it needs a new session.
106
+ * - diverged → compaction/rollback replaced the middle: same, a new session. */
107
+ private classifyHistory;
108
+ private blocksFor;
51
109
  private messageToBlocks;
110
+ /** A foreign tool-result is replayed only so the agent can follow the thread —
111
+ * the full payload isn't worth the tokens. */
112
+ private truncate;
52
113
  /** Map an AI SDK file part to an ACP ContentBlock, honoring the agent's promptCapabilities. */
53
114
  private fileToBlock;
54
115
  private toBase64;
55
- /** Full prompt flattened to ACP ContentBlocks (first turn of a conversation). */
56
- private convertMessages;
57
116
  /** OpenCode's system text → `_meta.systemPrompt` per mode. */
58
117
  private buildSystemPromptMeta;
59
118
  private systemText;
119
+ /** The FACTUAL part of OpenCode's system prompt: where we are, what the workspace is,
120
+ * what references exist. Under `preset` the system prompt itself never reaches the
121
+ * agent (forwarding it would get the session billed as extra usage), but this
122
+ * context is genuinely useful and carries no instructions, so it rides along as
123
+ * user content instead. Everything else — OpenCode's behavioural instructions,
124
+ * AGENTS.md (the agent loads it itself via projectMemory), MCP/skill catalogues —
125
+ * is deliberately left out. */
126
+ private extractContextBlock;
127
+ /** Send the context block once per session, then only what changed. Appending a
128
+ * small delta at the END of the conversation is cache-safe (the cached prefix is
129
+ * untouched); resending the whole block every turn would not be. */
130
+ private contextBlocks;
60
131
  /** Only the last user message (delta for a persistent session). */
61
132
  private lastUserBlocks;
133
+ /** Find the live conversation whose deferred tool-calls/permissions this prompt
134
+ * answers. Scoped per session, so two concurrent chats can't cross-resolve. */
62
135
  private detectContinuation;
136
+ /** A tool-result is an error/denial when its output type is error-* (OpenCode
137
+ * RejectedError) — used by the permission bridge to map approve vs reject. */
138
+ private isErrorOutput;
139
+ /** Approve a bridged permission ONLY on an explicit positive verdict (the
140
+ * claude_permission meta-tool returns "approved: …"). Errors, denials, and any
141
+ * ambiguous output fail CLOSED so an unclear verdict never runs the native tool. */
142
+ private isApprovedOutput;
63
143
  private outputToText;
144
+ /** OpenCode tool output → MCP CallToolResult. Structured content (images from a
145
+ * `read`, mixed blocks) is mapped through rather than flattened to a string, so
146
+ * the agent sees what OpenCode actually returned. */
64
147
  private toMcpResult;
65
148
  }
66
149
  //# sourceMappingURL=model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/provider/model.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EACV,eAAe,EACf,0BAA0B,EAC1B,yBAAyB,EACzB,6BAA6B,EAG9B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,yBAAyB,CAAC;AAMjC,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAiED,qBAAa,oBAAqB,YAAW,eAAe;IAa9C,OAAO,CAAC,QAAQ,CAAC,MAAM;IAZnC,QAAQ,CAAC,oBAAoB,EAAG,IAAI,CAAU;IAC9C,QAAQ,CAAC,QAAQ,SAAS;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAM;IAEtD,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,UAAU,CAAa;IAC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