@chances-ai/wire 24.0.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.
- package/dist/rpc/acp/adapter.d.ts +32 -0
- package/dist/rpc/acp/adapter.d.ts.map +1 -0
- package/dist/rpc/acp/adapter.js +185 -0
- package/dist/rpc/acp/adapter.js.map +1 -0
- package/dist/rpc/acp/engine-driver.d.ts +128 -0
- package/dist/rpc/acp/engine-driver.d.ts.map +1 -0
- package/dist/rpc/acp/engine-driver.js +550 -0
- package/dist/rpc/acp/engine-driver.js.map +1 -0
- package/dist/rpc/acp/event-map.d.ts +22 -0
- package/dist/rpc/acp/event-map.d.ts.map +1 -0
- package/dist/rpc/acp/event-map.js +205 -0
- package/dist/rpc/acp/event-map.js.map +1 -0
- package/dist/rpc/acp/load-sdk.d.ts +3 -0
- package/dist/rpc/acp/load-sdk.d.ts.map +1 -0
- package/dist/rpc/acp/load-sdk.js +24 -0
- package/dist/rpc/acp/load-sdk.js.map +1 -0
- package/dist/rpc/acp/workspace-query.d.ts +41 -0
- package/dist/rpc/acp/workspace-query.d.ts.map +1 -0
- package/dist/rpc/acp/workspace-query.js +89 -0
- package/dist/rpc/acp/workspace-query.js.map +1 -0
- package/dist/rpc/driver.d.ts +42 -0
- package/dist/rpc/driver.d.ts.map +1 -0
- package/dist/rpc/driver.js +7 -0
- package/dist/rpc/driver.js.map +1 -0
- package/dist/rpc/event-map.d.ts +8 -0
- package/dist/rpc/event-map.d.ts.map +1 -0
- package/dist/rpc/event-map.js +91 -0
- package/dist/rpc/event-map.js.map +1 -0
- package/dist/rpc/index.d.ts +13 -0
- package/dist/rpc/index.d.ts.map +1 -0
- package/dist/rpc/index.js +18 -0
- package/dist/rpc/index.js.map +1 -0
- package/dist/rpc/lines.d.ts +2 -0
- package/dist/rpc/lines.d.ts.map +1 -0
- package/dist/rpc/lines.js +24 -0
- package/dist/rpc/lines.js.map +1 -0
- package/dist/rpc/protocol.d.ts +315 -0
- package/dist/rpc/protocol.d.ts.map +1 -0
- package/dist/rpc/protocol.js +70 -0
- package/dist/rpc/protocol.js.map +1 -0
- package/dist/rpc/rpc-server.d.ts +56 -0
- package/dist/rpc/rpc-server.d.ts.map +1 -0
- package/dist/rpc/rpc-server.js +305 -0
- package/dist/rpc/rpc-server.js.map +1 -0
- package/dist/rpc/stdout-guard.d.ts +5 -0
- package/dist/rpc/stdout-guard.d.ts.map +1 -0
- package/dist/rpc/stdout-guard.js +31 -0
- package/dist/rpc/stdout-guard.js.map +1 -0
- package/dist/rpc/writer.d.ts +34 -0
- package/dist/rpc/writer.d.ts.map +1 -0
- package/dist/rpc/writer.js +85 -0
- package/dist/rpc/writer.js.map +1 -0
- package/dist/serve/acp-session-host.d.ts +120 -0
- package/dist/serve/acp-session-host.d.ts.map +1 -0
- package/dist/serve/acp-session-host.js +276 -0
- package/dist/serve/acp-session-host.js.map +1 -0
- package/dist/serve/auth.d.ts +21 -0
- package/dist/serve/auth.d.ts.map +1 -0
- package/dist/serve/auth.js +58 -0
- package/dist/serve/auth.js.map +1 -0
- package/dist/serve/highlight.d.ts +25 -0
- package/dist/serve/highlight.d.ts.map +1 -0
- package/dist/serve/highlight.js +28 -0
- package/dist/serve/highlight.js.map +1 -0
- package/dist/serve/index.d.ts +14 -0
- package/dist/serve/index.d.ts.map +1 -0
- package/dist/serve/index.js +23 -0
- package/dist/serve/index.js.map +1 -0
- package/dist/serve/pairing.d.ts +25 -0
- package/dist/serve/pairing.d.ts.map +1 -0
- package/dist/serve/pairing.js +10 -0
- package/dist/serve/pairing.js.map +1 -0
- package/dist/serve/relay-frames.d.ts +29 -0
- package/dist/serve/relay-frames.d.ts.map +1 -0
- package/dist/serve/relay-frames.js +54 -0
- package/dist/serve/relay-frames.js.map +1 -0
- package/dist/serve/relay.d.ts +146 -0
- package/dist/serve/relay.d.ts.map +1 -0
- package/dist/serve/relay.js +475 -0
- package/dist/serve/relay.js.map +1 -0
- package/dist/serve/replay-hub.d.ts +102 -0
- package/dist/serve/replay-hub.d.ts.map +1 -0
- package/dist/serve/replay-hub.js +176 -0
- package/dist/serve/replay-hub.js.map +1 -0
- package/dist/serve/tls.d.ts +20 -0
- package/dist/serve/tls.d.ts.map +1 -0
- package/dist/serve/tls.js +64 -0
- package/dist/serve/tls.js.map +1 -0
- package/dist/serve/ws-transport.d.ts +64 -0
- package/dist/serve/ws-transport.d.ts.map +1 -0
- package/dist/serve/ws-transport.js +92 -0
- package/dist/serve/ws-transport.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (v20 M3 / docs/6.4a §3) `AcpEngineDriver` — the ACP twin of `RpcServer`. It
|
|
3
|
+
* projects the SAME `EngineHost` seam onto an ACP (Agent Client Protocol) wire:
|
|
4
|
+
* JSON-RPC 2.0 + session semantics. Structurally identical to `RpcServer`
|
|
5
|
+
* (`run(lines: AsyncIterable<string>)` over an injected `ByteSink`), so the M2
|
|
6
|
+
* `SessionHost`/`ReplayHub` fan-out + seq/replay carry over with a one-line
|
|
7
|
+
* swap — but it speaks ACP, not the bespoke `chances-rpc` frames.
|
|
8
|
+
*
|
|
9
|
+
* **Self-rolled framing, NOT the ACP SDK's connection runtime** (user decision
|
|
10
|
+
* D1, docs/6.4a §1): the SDK's `AgentSideConnection` is point-to-point (it owns
|
|
11
|
+
* the JSON-RPC id correlation for ONE socket), which collides with M2's fan-out
|
|
12
|
+
* (one session, many sockets, any may answer a permission). So we roll the
|
|
13
|
+
* JSON-RPC framing ourselves on top of the fan-out, using the SDK only for its
|
|
14
|
+
* **types** (`import type` → erased; the driver compiles with or without the
|
|
15
|
+
* optional peer, exactly like the stdio adapter; `smoke-compile-rpc` gates both).
|
|
16
|
+
*
|
|
17
|
+
* Correlation is by **id pass-through**, no mapping table:
|
|
18
|
+
* - `session/prompt` request id → remembered as the active turn; the terminal
|
|
19
|
+
* `session/prompt` RESPONSE echoes it with `{ stopReason, usage }` (the
|
|
20
|
+
* chances `result` frame folded into the ACP response; the immediate `prompt`
|
|
21
|
+
* ack chances-rpc sends has no ACP equivalent and is simply not emitted).
|
|
22
|
+
* - `session/request_permission` is an agent→client REQUEST whose id we mint
|
|
23
|
+
* (`perm_*`); ANY attached socket may answer it (fan-out — the relay routes
|
|
24
|
+
* the response back here), and we dedup by id. **Fail-closed**: a cancelled/
|
|
25
|
+
* unknown outcome, or an errored response, denies (matches goose + v16).
|
|
26
|
+
* - chances-only fidelity (compaction/subagent/error) rides a
|
|
27
|
+
* `_chances/unstable/event` notification carrying `_meta.chances` — a plain
|
|
28
|
+
* ACP client ignores the unknown method; ours reads it.
|
|
29
|
+
*
|
|
30
|
+
* Socket-free + timer-free at the seam: tests drive `run()` with a fake
|
|
31
|
+
* `EngineHost` + scripted ACP lines and assert the emitted ACP message sequence.
|
|
32
|
+
*/
|
|
33
|
+
import { CancellationTokenSource, createId } from "@chances-ai/runtime";
|
|
34
|
+
import { BoundedNdjsonWriter } from "../writer.js";
|
|
35
|
+
import { chancesEventMeta, mapEventToAcp } from "./event-map.js";
|
|
36
|
+
/** ACP protocol version we speak (SDK `PROTOCOL_VERSION` = 1). */
|
|
37
|
+
export const ACP_PROTOCOL_VERSION = 1;
|
|
38
|
+
/** The four standard ACP permission options; the selected `optionId` maps back
|
|
39
|
+
* to a chances `PermissionDecision`. */
|
|
40
|
+
const PERMISSION_OPTIONS = [
|
|
41
|
+
{ optionId: "allow_once", kind: "allow_once", name: "Allow once" },
|
|
42
|
+
{ optionId: "allow_always", kind: "allow_always", name: "Allow always" },
|
|
43
|
+
{ optionId: "reject_once", kind: "reject_once", name: "Reject" },
|
|
44
|
+
{ optionId: "reject_always", kind: "reject_always", name: "Reject always" },
|
|
45
|
+
];
|
|
46
|
+
/** Wire method names. Standard ACP + namespaced chances extensions
|
|
47
|
+
* (`_chances/unstable/*`, mirroring goose's `_goose/unstable/*`). */
|
|
48
|
+
const METHOD = {
|
|
49
|
+
initialize: "initialize",
|
|
50
|
+
newSession: "session/new",
|
|
51
|
+
loadSession: "session/load",
|
|
52
|
+
prompt: "session/prompt",
|
|
53
|
+
cancel: "session/cancel",
|
|
54
|
+
update: "session/update",
|
|
55
|
+
requestPermission: "session/request_permission",
|
|
56
|
+
ext: {
|
|
57
|
+
setModel: "_chances/unstable/set_model",
|
|
58
|
+
setApproval: "_chances/unstable/set_approval",
|
|
59
|
+
requestQuestion: "_chances/unstable/request_question",
|
|
60
|
+
getState: "_chances/unstable/get_state",
|
|
61
|
+
getModels: "_chances/unstable/get_models",
|
|
62
|
+
setOptions: "_chances/unstable/set_options",
|
|
63
|
+
ping: "_chances/unstable/ping",
|
|
64
|
+
},
|
|
65
|
+
event: "_chances/unstable/event",
|
|
66
|
+
};
|
|
67
|
+
/** JSON-RPC standard error codes we use. */
|
|
68
|
+
const ERR = { methodNotFound: -32601, invalidParams: -32602, serverError: -32000 };
|
|
69
|
+
/** Runtime guard: a question answer body must be `Record<string, string[]>`.
|
|
70
|
+
* Anything else (a string, a non-array value, a non-string array element) is
|
|
71
|
+
* malformed → the caller fail-closes to declined (codex v22 MUST). */
|
|
72
|
+
function isAnswerMap(v) {
|
|
73
|
+
if (typeof v !== "object" || v === null || Array.isArray(v))
|
|
74
|
+
return false;
|
|
75
|
+
return Object.values(v).every((a) => Array.isArray(a) && a.every((s) => typeof s === "string"));
|
|
76
|
+
}
|
|
77
|
+
const SHUTDOWN_TURN_DEADLINE_MS = 2000;
|
|
78
|
+
const MAX_RESOLVED_IDS = 1024;
|
|
79
|
+
export class AcpEngineDriver {
|
|
80
|
+
host;
|
|
81
|
+
writer;
|
|
82
|
+
agent;
|
|
83
|
+
autoApprove;
|
|
84
|
+
logSink;
|
|
85
|
+
toolChunks = true;
|
|
86
|
+
built = null;
|
|
87
|
+
unsub = null;
|
|
88
|
+
sessionId = "";
|
|
89
|
+
activeTurn = null;
|
|
90
|
+
/** Tracked so shutdown can await the terminal prompt response before closing. */
|
|
91
|
+
activePrompt = null;
|
|
92
|
+
/** Open asks (permission OR question): minted id → the resolver's `resolve` +
|
|
93
|
+
* the serialized request (kept so a fresh attach can re-send a still-open ask
|
|
94
|
+
* the ring evicted) + its `kind` (so a response/deny resolves the right shape). */
|
|
95
|
+
pending = new Map();
|
|
96
|
+
resolvedIds = [];
|
|
97
|
+
resolvedSet = new Set();
|
|
98
|
+
workspaceQueries;
|
|
99
|
+
shuttingDown = false;
|
|
100
|
+
constructor(opts) {
|
|
101
|
+
this.host = opts.host;
|
|
102
|
+
this.writer = new BoundedNdjsonWriter(opts.sink, { warn: opts.logSink });
|
|
103
|
+
this.agent = opts.agent;
|
|
104
|
+
this.autoApprove = opts.autoApprove ?? false;
|
|
105
|
+
this.logSink = opts.logSink ?? ((line) => process.stderr.write(line));
|
|
106
|
+
this.workspaceQueries = opts.workspaceQueries ?? false;
|
|
107
|
+
}
|
|
108
|
+
async run(lines) {
|
|
109
|
+
const built = this.host.build(this.makeResolver());
|
|
110
|
+
this.built = built;
|
|
111
|
+
this.sessionId = built.sessionId;
|
|
112
|
+
// Subscribe BEFORE reading input so no frame is missed. ACP is
|
|
113
|
+
// client-initiated (the client sends `initialize` first), so — unlike the
|
|
114
|
+
// bespoke wire's proactive `ready` — we emit nothing until asked; we just
|
|
115
|
+
// keep the bus → `session/update` projection live.
|
|
116
|
+
this.unsub = built.bus.onAny((e) => this.onEvent(e));
|
|
117
|
+
try {
|
|
118
|
+
for await (const line of lines) {
|
|
119
|
+
const trimmed = line.trim();
|
|
120
|
+
if (trimmed === "")
|
|
121
|
+
continue;
|
|
122
|
+
this.handleLine(trimmed);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
await this.shutdown();
|
|
127
|
+
}
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
/** Idempotent shutdown — same order as `RpcServer` (cancel turn → deny pending
|
|
131
|
+
* → await the in-flight prompt's terminal response → dispose → flush → close). */
|
|
132
|
+
async shutdown() {
|
|
133
|
+
if (this.shuttingDown)
|
|
134
|
+
return;
|
|
135
|
+
this.shuttingDown = true;
|
|
136
|
+
this.activeTurn?.cts.cancel();
|
|
137
|
+
this.denyAllPending();
|
|
138
|
+
if (this.activePrompt) {
|
|
139
|
+
await Promise.race([this.activePrompt, delay(SHUTDOWN_TURN_DEADLINE_MS)]);
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
await this.host.dispose();
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
/* dispose is best-effort; never block the flush */
|
|
146
|
+
}
|
|
147
|
+
await this.writer.flush();
|
|
148
|
+
this.unsub?.();
|
|
149
|
+
this.writer.close();
|
|
150
|
+
}
|
|
151
|
+
// -- accessors (the relay reads these for the per-attach reconnect snapshot,
|
|
152
|
+
// replacing the bespoke wire's byte-snoop — driver state is authoritative) -
|
|
153
|
+
/** Whether a turn is in flight, so a reconnecting client can lock its composer. */
|
|
154
|
+
get busy() {
|
|
155
|
+
return this.activeTurn !== null;
|
|
156
|
+
}
|
|
157
|
+
/** Ids of still-open `session/request_permission` asks at attach time. */
|
|
158
|
+
pendingPermissionIds() {
|
|
159
|
+
return [...this.pending.keys()];
|
|
160
|
+
}
|
|
161
|
+
/** Serialized lines of every still-open permission request, re-sent right
|
|
162
|
+
* after the welcome so a parked turn stays answerable even if the ring
|
|
163
|
+
* evicted the ask. The client de-dups by permission id. */
|
|
164
|
+
openPermissionFrames() {
|
|
165
|
+
return [...this.pending.values()].map((e) => JSON.stringify(e.request) + "\n");
|
|
166
|
+
}
|
|
167
|
+
// -- outbound: bus → ACP ----------------------------------------------------
|
|
168
|
+
onEvent(e) {
|
|
169
|
+
if (e.type === "log") {
|
|
170
|
+
this.logSink(`[${e.level}] ${e.message}\n`);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
// chances-only fidelity has no standard SessionUpdate → extension notification.
|
|
174
|
+
const chances = chancesEventMeta(e);
|
|
175
|
+
if (chances) {
|
|
176
|
+
this.enqueueNotification(METHOD.event, { sessionId: this.sessionId, _meta: { chances } });
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
for (const update of mapEventToAcp(e, { toolChunks: this.toolChunks })) {
|
|
180
|
+
this.enqueueNotification(METHOD.update, { sessionId: this.sessionId, update });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// -- inbound: ACP → engine --------------------------------------------------
|
|
184
|
+
handleLine(line) {
|
|
185
|
+
let msg;
|
|
186
|
+
try {
|
|
187
|
+
msg = JSON.parse(line);
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
return; // ignore non-JSON noise
|
|
191
|
+
}
|
|
192
|
+
if (typeof msg !== "object" || msg === null)
|
|
193
|
+
return;
|
|
194
|
+
if (typeof msg.method === "string") {
|
|
195
|
+
this.handleMethod(msg.method, msg.id, msg.params);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
// A JSON-RPC RESPONSE to one of OUR requests (request_permission OR, v22,
|
|
199
|
+
// request_question). Dispatch by the pending entry's kind.
|
|
200
|
+
if (msg.id !== undefined && ("result" in msg || "error" in msg)) {
|
|
201
|
+
const id = String(msg.id);
|
|
202
|
+
const kind = this.pending.get(id)?.kind;
|
|
203
|
+
if (kind === "question")
|
|
204
|
+
this.resolveQuestion(id, msg.result, "error" in msg);
|
|
205
|
+
else
|
|
206
|
+
this.resolvePermission(id, msg.result, "error" in msg);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
handleMethod(method, id, params) {
|
|
210
|
+
switch (method) {
|
|
211
|
+
case METHOD.initialize:
|
|
212
|
+
this.respond(id, this.initializeResult());
|
|
213
|
+
return;
|
|
214
|
+
case METHOD.newSession:
|
|
215
|
+
// Standard ACP `models` (SessionModelState) so a plain ACP client gets
|
|
216
|
+
// the model list from `session/new`, not only our `_meta.chances`
|
|
217
|
+
// (codex M3 SHOULD). `modes: null` = no agent modes.
|
|
218
|
+
this.respond(id, { sessionId: this.sessionId, modes: null, models: this.modelState() });
|
|
219
|
+
return;
|
|
220
|
+
case METHOD.loadSession:
|
|
221
|
+
// M3 stub: the relay's reconnect/replay (M2) already restores the GUI
|
|
222
|
+
// transcript, so we don't replay history here. Advertised honestly via
|
|
223
|
+
// `agentCapabilities.loadSession: false`.
|
|
224
|
+
this.respond(id, {});
|
|
225
|
+
return;
|
|
226
|
+
case METHOD.prompt: {
|
|
227
|
+
// Guard BEFORE assigning `activePrompt` (codex M3 MUST): a rejected prompt
|
|
228
|
+
// (unknown session / AGENT_BUSY) must NOT overwrite the live turn's
|
|
229
|
+
// `activePrompt`, or shutdown would stop awaiting the real terminal
|
|
230
|
+
// response. Long-running otherwise → fire-and-forget so the loop keeps
|
|
231
|
+
// reading cancel/permission responses mid-turn (tracked for shutdown).
|
|
232
|
+
if (id === undefined)
|
|
233
|
+
return;
|
|
234
|
+
if (!this.isOurSession(params)) {
|
|
235
|
+
this.error(id, ERR.invalidParams, "unknown session");
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (this.activeTurn) {
|
|
239
|
+
this.error(id, ERR.serverError, "a turn is already running");
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
this.activePrompt = this.handlePrompt(id, params).finally(() => {
|
|
243
|
+
this.activePrompt = null;
|
|
244
|
+
});
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
case METHOD.cancel:
|
|
248
|
+
if (!this.isOurSession(params))
|
|
249
|
+
return; // a bogus session can't cancel ours
|
|
250
|
+
// Deny pending FIRST so a turn parked in the resolver unwinds, then cancel.
|
|
251
|
+
this.denyAllPending();
|
|
252
|
+
this.activeTurn?.cts.cancel();
|
|
253
|
+
return; // notification — no response
|
|
254
|
+
case METHOD.ext.setModel:
|
|
255
|
+
this.handleSetModel(id, params);
|
|
256
|
+
return;
|
|
257
|
+
case METHOD.ext.setApproval:
|
|
258
|
+
this.handleSetApproval(id, params);
|
|
259
|
+
return;
|
|
260
|
+
case METHOD.ext.getState:
|
|
261
|
+
this.respond(id, {
|
|
262
|
+
model: this.built?.selection.get() ?? {},
|
|
263
|
+
approvalMode: this.built?.approval?.get() ?? "default",
|
|
264
|
+
busy: this.activeTurn !== null,
|
|
265
|
+
sessionId: this.sessionId,
|
|
266
|
+
toolChunks: this.toolChunks,
|
|
267
|
+
});
|
|
268
|
+
return;
|
|
269
|
+
case METHOD.ext.getModels:
|
|
270
|
+
this.respond(id, { models: this.host.listModels() });
|
|
271
|
+
return;
|
|
272
|
+
case METHOD.ext.setOptions:
|
|
273
|
+
if (params && typeof params === "object" && "toolChunks" in params) {
|
|
274
|
+
const tc = params.toolChunks;
|
|
275
|
+
if (typeof tc === "boolean")
|
|
276
|
+
this.toolChunks = tc;
|
|
277
|
+
}
|
|
278
|
+
this.respond(id, { toolChunks: this.toolChunks });
|
|
279
|
+
return;
|
|
280
|
+
case METHOD.ext.ping:
|
|
281
|
+
this.respond(id, { pong: true });
|
|
282
|
+
return;
|
|
283
|
+
default:
|
|
284
|
+
if (id !== undefined)
|
|
285
|
+
this.error(id, ERR.methodNotFound, `unknown method: ${method}`);
|
|
286
|
+
return; // unknown notification → ignore
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/** Runs one turn. The caller (`handleMethod`'s prompt case) has already
|
|
290
|
+
* validated the session + rejected an overlapping turn, so this always starts. */
|
|
291
|
+
async handlePrompt(id, params) {
|
|
292
|
+
const text = textFromPrompt(params);
|
|
293
|
+
const cts = new CancellationTokenSource();
|
|
294
|
+
this.activeTurn = { cts, promptId: id };
|
|
295
|
+
let result = { text: "", inputTokens: 0, outputTokens: 0, costUsd: 0 };
|
|
296
|
+
let stopReason = "end_turn";
|
|
297
|
+
try {
|
|
298
|
+
result = await this.built.runTurn(text, cts.token);
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
// A non-cancel engine error already emitted an `error` bus event (→ ext
|
|
302
|
+
// notification); cancellation is user-initiated. ACP has no generic error
|
|
303
|
+
// stop reason, so the turn still ends — details rode the error event.
|
|
304
|
+
stopReason = cts.token.isCancelled ? "cancelled" : "end_turn";
|
|
305
|
+
}
|
|
306
|
+
finally {
|
|
307
|
+
this.activeTurn = null;
|
|
308
|
+
}
|
|
309
|
+
this.respond(id, {
|
|
310
|
+
stopReason,
|
|
311
|
+
usage: {
|
|
312
|
+
inputTokens: result.inputTokens,
|
|
313
|
+
outputTokens: result.outputTokens,
|
|
314
|
+
totalTokens: result.inputTokens + result.outputTokens,
|
|
315
|
+
},
|
|
316
|
+
_meta: { chances: { costUsd: result.costUsd } },
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
/** True if `params.sessionId` addresses our singleton session. An ABSENT id is
|
|
320
|
+
* tolerated (first-party clients always send ours); a PRESENT but mismatched id
|
|
321
|
+
* is rejected so a plain ACP client can't drive/cancel a bogus session (codex
|
|
322
|
+
* M3 SHOULD). */
|
|
323
|
+
isOurSession(params) {
|
|
324
|
+
const sid = params?.sessionId;
|
|
325
|
+
return sid === undefined || sid === this.sessionId;
|
|
326
|
+
}
|
|
327
|
+
/** The standard ACP `SessionModelState` (modelId = `provider/model`). */
|
|
328
|
+
modelState() {
|
|
329
|
+
const id = (m) => `${m.provider}/${m.model}`;
|
|
330
|
+
const models = this.host.listModels();
|
|
331
|
+
const sel = this.built?.selection.get();
|
|
332
|
+
const current = sel?.provider && sel?.model ? id({ provider: sel.provider, model: sel.model }) : models[0] ? id(models[0]) : "";
|
|
333
|
+
return { availableModels: models.map((m) => ({ modelId: id(m), name: id(m) })), currentModelId: current };
|
|
334
|
+
}
|
|
335
|
+
handleSetModel(id, params) {
|
|
336
|
+
if (this.activeTurn) {
|
|
337
|
+
if (id !== undefined)
|
|
338
|
+
this.error(id, ERR.serverError, "cannot switch model while a turn is running");
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const p = (params ?? {});
|
|
342
|
+
this.built?.selection.set({ provider: p.provider, model: p.model });
|
|
343
|
+
this.respond(id, this.built?.selection.get() ?? {});
|
|
344
|
+
}
|
|
345
|
+
/** (v22) Set the session approval mode. UNLIKE set_model this is allowed
|
|
346
|
+
* mid-turn — the mode applies to the NEXT permission check, which is the whole
|
|
347
|
+
* point of cycling it while a turn streams (claude-code parity; mirrors the
|
|
348
|
+
* TUI Stage-1 fix). A switch to `yolo` carries its own consent (the GUI
|
|
349
|
+
* confirms client-side before sending), so we latch it. */
|
|
350
|
+
handleSetApproval(id, params) {
|
|
351
|
+
const approval = this.built?.approval;
|
|
352
|
+
if (!approval) {
|
|
353
|
+
if (id !== undefined)
|
|
354
|
+
this.error(id, ERR.serverError, "approval mode not supported by this host");
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const VALID = ["default", "auto-edit", "plan", "yolo"];
|
|
358
|
+
const mode = params?.mode;
|
|
359
|
+
if (!mode || !VALID.includes(mode)) {
|
|
360
|
+
if (id !== undefined)
|
|
361
|
+
this.error(id, ERR.invalidParams, `invalid approval mode: ${String(mode)}`);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (mode === "yolo")
|
|
365
|
+
approval.confirmYolo();
|
|
366
|
+
approval.set(mode);
|
|
367
|
+
this.respond(id, { approvalMode: approval.get() });
|
|
368
|
+
}
|
|
369
|
+
// -- permission round-trip --------------------------------------------------
|
|
370
|
+
makeResolver() {
|
|
371
|
+
return (req) => {
|
|
372
|
+
// (v22) A structured question (`ask_user_question`) is forwarded to the
|
|
373
|
+
// client as a `_chances/unstable/request_question` request and answered with
|
|
374
|
+
// `{answers, annotations, declined}`. autoApprove does NOT apply (a question
|
|
375
|
+
// is not an authorization); a non-chances ACP client never sends the method,
|
|
376
|
+
// so the ask stays parked until a chances client answers (or shutdown denies).
|
|
377
|
+
if (req.kind === "question") {
|
|
378
|
+
const id = createId("ask");
|
|
379
|
+
return new Promise((resolve) => {
|
|
380
|
+
const request = {
|
|
381
|
+
jsonrpc: "2.0",
|
|
382
|
+
id,
|
|
383
|
+
method: METHOD.ext.requestQuestion,
|
|
384
|
+
params: {
|
|
385
|
+
sessionId: this.sessionId,
|
|
386
|
+
questions: req.questions,
|
|
387
|
+
_meta: { chances: { tool: req.name, category: req.category } },
|
|
388
|
+
},
|
|
389
|
+
};
|
|
390
|
+
this.pending.set(id, { resolve, request, kind: "question" });
|
|
391
|
+
this.writer.enqueue(request);
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
if (this.autoApprove)
|
|
395
|
+
return Promise.resolve({ allow: true, remember: true });
|
|
396
|
+
const id = createId("perm");
|
|
397
|
+
return new Promise((resolve) => {
|
|
398
|
+
const request = {
|
|
399
|
+
jsonrpc: "2.0",
|
|
400
|
+
id,
|
|
401
|
+
method: METHOD.requestPermission,
|
|
402
|
+
params: {
|
|
403
|
+
sessionId: this.sessionId,
|
|
404
|
+
toolCall: {
|
|
405
|
+
toolCallId: req.callId ?? createId("tool"),
|
|
406
|
+
title: req.summary,
|
|
407
|
+
rawInput: (req.args ?? {}),
|
|
408
|
+
// Tool NAME + category an ACP-only client ignores; ours reads them
|
|
409
|
+
// for a clean permission-card header (the title carries the diff).
|
|
410
|
+
_meta: { chances: { tool: req.name, category: req.category } },
|
|
411
|
+
},
|
|
412
|
+
options: PERMISSION_OPTIONS,
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
this.pending.set(id, { resolve, request, kind: "authorization" });
|
|
416
|
+
this.writer.enqueue(request);
|
|
417
|
+
});
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
/** A client answered a `session/request_permission` request (JSON-RPC
|
|
421
|
+
* response). Fail-closed: an error response, a non-`selected` outcome, or an
|
|
422
|
+
* unknown `optionId` all deny. Dedups duplicate/foreign answers. */
|
|
423
|
+
resolvePermission(id, result, isError) {
|
|
424
|
+
if (this.resolvedSet.has(id))
|
|
425
|
+
return;
|
|
426
|
+
const entry = this.pending.get(id);
|
|
427
|
+
if (!entry)
|
|
428
|
+
return; // unknown id — ignore
|
|
429
|
+
this.pending.delete(id);
|
|
430
|
+
this.markResolved(id);
|
|
431
|
+
const { resolve } = entry;
|
|
432
|
+
if (isError) {
|
|
433
|
+
resolve({ allow: false });
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
const outcome = result?.outcome;
|
|
437
|
+
if (!outcome || outcome.outcome !== "selected") {
|
|
438
|
+
resolve({ allow: false }); // cancelled / malformed → deny
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
switch (outcome.optionId) {
|
|
442
|
+
case "allow_once":
|
|
443
|
+
resolve({ allow: true, remember: false });
|
|
444
|
+
return;
|
|
445
|
+
case "allow_always":
|
|
446
|
+
resolve({ allow: true, remember: true });
|
|
447
|
+
return;
|
|
448
|
+
default:
|
|
449
|
+
resolve({ allow: false }); // reject_once / reject_always / unknown
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
/** (v22) A client answered a `_chances/unstable/request_question` request.
|
|
454
|
+
* Fail-closed: an error response, a malformed body, or an explicit `declined`
|
|
455
|
+
* all resolve to a declined QuestionDecision (the ask tool turns that into a
|
|
456
|
+
* deterministic "declined" result). Dedups duplicate/foreign answers. */
|
|
457
|
+
resolveQuestion(id, result, isError) {
|
|
458
|
+
if (this.resolvedSet.has(id))
|
|
459
|
+
return;
|
|
460
|
+
const entry = this.pending.get(id);
|
|
461
|
+
if (!entry)
|
|
462
|
+
return;
|
|
463
|
+
this.pending.delete(id);
|
|
464
|
+
this.markResolved(id);
|
|
465
|
+
const { resolve } = entry;
|
|
466
|
+
if (isError || typeof result !== "object" || result === null) {
|
|
467
|
+
resolve({ kind: "question", answers: {}, declined: true });
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
const r = result;
|
|
471
|
+
// (codex v22 MUST) Fail-closed on a MALFORMED body, not just a missing one: an
|
|
472
|
+
// explicit `declined`, or anything that isn't a `Record<string,string[]>` of
|
|
473
|
+
// answers (e.g. `{answers:"x"}` / non-string-array values), declines.
|
|
474
|
+
const answers = r.declined !== true && isAnswerMap(r.answers) ? r.answers : {};
|
|
475
|
+
const declined = r.declined === true || !isAnswerMap(r.answers);
|
|
476
|
+
resolve({
|
|
477
|
+
kind: "question",
|
|
478
|
+
answers,
|
|
479
|
+
...(r.annotations ? { annotations: r.annotations } : {}),
|
|
480
|
+
declined,
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
denyAllPending() {
|
|
484
|
+
for (const [id, entry] of this.pending) {
|
|
485
|
+
this.markResolved(id);
|
|
486
|
+
// Deny in the SHAPE the asker expects (a question can't be auth-denied).
|
|
487
|
+
entry.resolve(entry.kind === "question" ? { kind: "question", answers: {}, declined: true } : { allow: false });
|
|
488
|
+
}
|
|
489
|
+
this.pending.clear();
|
|
490
|
+
}
|
|
491
|
+
markResolved(id) {
|
|
492
|
+
this.resolvedSet.add(id);
|
|
493
|
+
this.resolvedIds.push(id);
|
|
494
|
+
if (this.resolvedIds.length > MAX_RESOLVED_IDS) {
|
|
495
|
+
const evicted = this.resolvedIds.shift();
|
|
496
|
+
this.resolvedSet.delete(evicted);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
// -- ACP message helpers ----------------------------------------------------
|
|
500
|
+
initializeResult() {
|
|
501
|
+
return {
|
|
502
|
+
protocolVersion: ACP_PROTOCOL_VERSION,
|
|
503
|
+
agentInfo: { name: this.agent.name, version: this.agent.version },
|
|
504
|
+
agentCapabilities: { loadSession: false },
|
|
505
|
+
_meta: {
|
|
506
|
+
chances: {
|
|
507
|
+
capabilities: {
|
|
508
|
+
reconnect: true,
|
|
509
|
+
toolChunks: this.toolChunks,
|
|
510
|
+
modelSelection: true,
|
|
511
|
+
approvalSelection: this.built?.approval !== undefined,
|
|
512
|
+
models: this.host.listModels(),
|
|
513
|
+
fidelity: ["usage", "chunk", "compaction", "subagent", "reset"],
|
|
514
|
+
// (v23 M5) read-only workspace queries (file tree / read / git) for
|
|
515
|
+
// the GUI's 3-pane IDE — handled by the relay, not this driver.
|
|
516
|
+
workspaceQueries: this.workspaceQueries,
|
|
517
|
+
},
|
|
518
|
+
// (v22) Current approval mode, so a GUI badge reflects it on connect
|
|
519
|
+
// without a separate round-trip (set via `_chances/unstable/set_approval`).
|
|
520
|
+
approvalMode: this.built?.approval?.get() ?? "default",
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
enqueueNotification(method, params) {
|
|
526
|
+
this.writer.enqueue({ jsonrpc: "2.0", method, params });
|
|
527
|
+
}
|
|
528
|
+
respond(id, result) {
|
|
529
|
+
if (id === undefined)
|
|
530
|
+
return; // a notification has no id to respond to
|
|
531
|
+
this.writer.enqueue({ jsonrpc: "2.0", id, result });
|
|
532
|
+
}
|
|
533
|
+
error(id, code, message) {
|
|
534
|
+
this.writer.enqueue({ jsonrpc: "2.0", id, error: { code, message } });
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
/** Extract the user text from an ACP `PromptRequest.prompt` (ContentBlock[]). */
|
|
538
|
+
function textFromPrompt(params) {
|
|
539
|
+
const blocks = params?.prompt;
|
|
540
|
+
if (!Array.isArray(blocks))
|
|
541
|
+
return "";
|
|
542
|
+
return blocks
|
|
543
|
+
.map((b) => (b && typeof b === "object" && b.type === "text" ? String(b.text ?? "") : ""))
|
|
544
|
+
.filter((s) => s.length > 0)
|
|
545
|
+
.join("\n");
|
|
546
|
+
}
|
|
547
|
+
function delay(ms) {
|
|
548
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
549
|
+
}
|
|
550
|
+
//# sourceMappingURL=engine-driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-driver.js","sourceRoot":"","sources":["../../../src/rpc/acp/engine-driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAiB,MAAM,qBAAqB,CAAC;AAIvF,OAAO,EAAE,mBAAmB,EAAiB,MAAM,cAAc,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE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EAAE,CAAC;IACtC,OAAO,MAAM;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAuB,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAE,CAAwB,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SACxI,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;SAC3B,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AppEvent } from "@chances-ai/runtime";
|
|
2
|
+
import type { SessionUpdate } from "@agentclientprotocol/sdk";
|
|
3
|
+
export interface AcpMapOptions {
|
|
4
|
+
/** When false, `tool:chunk` (live PTY output) is suppressed (mirrors the
|
|
5
|
+
* bespoke-wire `EventMapOptions.toolChunks` opt-out). */
|
|
6
|
+
toolChunks: boolean;
|
|
7
|
+
/** Model context-window size in tokens, if the engine knows it — used as the
|
|
8
|
+
* `usage_update.size`. Absent ⇒ `size` falls back to `used` (an unknown
|
|
9
|
+
* window renders as "full" rather than zero). */
|
|
10
|
+
contextWindow?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function mapEventToAcp(e: AppEvent, opts: AcpMapOptions): SessionUpdate[];
|
|
13
|
+
/**
|
|
14
|
+
* chances-only fidelity (no standard ACP `SessionUpdate`) → the `_meta.chances`
|
|
15
|
+
* payload of a `_chances/unstable/event` extension notification, or `null` if `e`
|
|
16
|
+
* is not one of these. SHARED by the relay `AcpEngineDriver` + the stdio Zed
|
|
17
|
+
* adapter so both ACP transports carry compaction/subagent/error identically
|
|
18
|
+
* (codex M3 SHOULD — no per-transport drift). A plain ACP client ignores the
|
|
19
|
+
* unknown method; a chances-aware one reads `_meta.chances`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function chancesEventMeta(e: AppEvent): Record<string, unknown> | null;
|
|
22
|
+
//# sourceMappingURL=event-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-map.d.ts","sourceRoot":"","sources":["../../../src/rpc/acp/event-map.ts"],"names":[],"mappings":"AAqCA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,0BAA0B,CAAC;AAExE,MAAM,WAAW,aAAa;IAC5B;8DAC0D;IAC1D,UAAU,EAAE,OAAO,CAAC;IACpB;;sDAEkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAOD,wBAAgB,aAAa,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,aAAa,GAAG,aAAa,EAAE,CAuE/E;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAmC5E"}
|