opencode-acp-client 0.0.0-stage → 0.1.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.
Files changed (55) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +220 -2
  3. package/README.zh.md +199 -0
  4. package/dist/acp/capabilities.d.ts +168 -0
  5. package/dist/acp/capabilities.js +240 -0
  6. package/dist/acp/capabilities.js.map +1 -0
  7. package/dist/acp/client.d.ts +241 -0
  8. package/dist/acp/client.js +767 -0
  9. package/dist/acp/client.js.map +1 -0
  10. package/dist/acp/types.d.ts +228 -0
  11. package/dist/acp/types.js +23 -0
  12. package/dist/acp/types.js.map +1 -0
  13. package/dist/acp-replay.d.ts +60 -0
  14. package/dist/acp-replay.js +188 -0
  15. package/dist/acp-replay.js.map +1 -0
  16. package/dist/contract.d.ts +435 -0
  17. package/dist/contract.js +126 -0
  18. package/dist/contract.js.map +1 -0
  19. package/dist/daemons.d.ts +39 -0
  20. package/dist/daemons.js +112 -0
  21. package/dist/daemons.js.map +1 -0
  22. package/dist/index.d.ts +268 -0
  23. package/dist/index.js +1882 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/opencode-bin.d.ts +73 -0
  26. package/dist/opencode-bin.js +109 -0
  27. package/dist/opencode-bin.js.map +1 -0
  28. package/dist/project.d.ts +81 -0
  29. package/dist/project.js +230 -0
  30. package/dist/project.js.map +1 -0
  31. package/dist/server.d.ts +743 -0
  32. package/dist/server.js +5029 -0
  33. package/dist/server.js.map +1 -0
  34. package/dist/session-map.d.ts +89 -0
  35. package/dist/session-map.js +305 -0
  36. package/dist/session-map.js.map +1 -0
  37. package/dist/sessions-command.d.ts +70 -0
  38. package/dist/sessions-command.js +188 -0
  39. package/dist/sessions-command.js.map +1 -0
  40. package/dist/sse.d.ts +40 -0
  41. package/dist/sse.js +147 -0
  42. package/dist/sse.js.map +1 -0
  43. package/dist/state.d.ts +161 -0
  44. package/dist/state.js +135 -0
  45. package/dist/state.js.map +1 -0
  46. package/dist/subagent-sessions.d.ts +71 -0
  47. package/dist/subagent-sessions.js +107 -0
  48. package/dist/subagent-sessions.js.map +1 -0
  49. package/dist/translate/events.d.ts +231 -0
  50. package/dist/translate/events.js +1244 -0
  51. package/dist/translate/events.js.map +1 -0
  52. package/dist/upgrade.d.ts +56 -0
  53. package/dist/upgrade.js +162 -0
  54. package/dist/upgrade.js.map +1 -0
  55. package/package.json +66 -4
@@ -0,0 +1,435 @@
1
+ /**
2
+ * The opencode v2 surface this bridge implements.
3
+ *
4
+ * Two reference points shaped this file:
5
+ * - `packages/tui/test/fixture/tui-client.ts` in the opencode repo: the
6
+ * minimal server their own TUI tests accept. Its route list is the floor.
7
+ * - the backend-oc's bridge: the same surface, proven against the real TUI.
8
+ *
9
+ * Everything here is therefore *observed*, not invented. Where a shape was
10
+ * inferred (part payloads), it is marked with `INFERRED` so the next person
11
+ * knows what to re-check against a new client build.
12
+ */
13
+ /** The event envelope every `/api/event` frame carries. */
14
+ export interface BridgeEvent<T extends string = string, D = unknown> {
15
+ /**
16
+ * The client's store reads this on some events (the shell ones) and hangs it on the
17
+ * message it inserts; leaving it off meant `metadata: undefined` there.
18
+ */
19
+ metadata?: Record<string, unknown>;
20
+ id: string;
21
+ type: T;
22
+ data: D;
23
+ /**
24
+ * The client stamps `time.created` from this on every row it builds, so an
25
+ * absent value leaves rows with `created: undefined`.
26
+ */
27
+ created: number;
28
+ /** opencode tags events with the location they belong to. */
29
+ location?: Location;
30
+ }
31
+ export interface Project {
32
+ id: string;
33
+ directory: string;
34
+ canonical: string;
35
+ }
36
+ export interface Location {
37
+ directory: string;
38
+ /** The client builds a LocationRef from this and dereferences it. */
39
+ workspaceID?: string;
40
+ project: Project;
41
+ }
42
+ /** Most `/api/*` reads wrap their payload in a location envelope. */
43
+ export interface Located<T> {
44
+ location: Location;
45
+ data: T;
46
+ }
47
+ export interface Session {
48
+ /**
49
+ * The ACP agent's own session id, once `session/new` (or a load/resume) has
50
+ * answered. The client-visible `id` stays ours: the published surface requires
51
+ * `^ses`, the agent id does not exist until the agent answers, and changing a
52
+ * primary id after the client has stored it would break its routing.
53
+ */
54
+ acpSessionId?: string;
55
+ id: string;
56
+ directory: string;
57
+ title?: string;
58
+ parentID?: string;
59
+ outcome?: 'succeeded' | 'failed' | 'interrupted';
60
+ time: {
61
+ created: number;
62
+ updated: number;
63
+ idle?: number;
64
+ viewed?: number;
65
+ archived?: number;
66
+ };
67
+ /**
68
+ * Required by the client's `SessionInfo`. It hydrates `session.info[id]`
69
+ * straight from this and later dereferences `session.location.directory`, so
70
+ * omitting it is what takes the TUI down with
71
+ * `undefined is not an object (evaluating 'O().location.directory')`.
72
+ */
73
+ location: LocationRef;
74
+ projectID: string;
75
+ /** MoneyUSD is just a number. */
76
+ cost: number;
77
+ tokens: TokenUsageInfo;
78
+ }
79
+ /**
80
+ * One shell command the client asked to run via `POST /api/shell`. The TUI polls
81
+ * `/api/shell/:id/output` for the transcript rather than streaming it.
82
+ */
83
+ export interface ShellRecord {
84
+ id: string;
85
+ command: string;
86
+ cwd: string;
87
+ shell: string;
88
+ file: string;
89
+ pid?: number;
90
+ exit?: number;
91
+ status: 'running' | 'exited' | 'timeout' | 'killed';
92
+ /** Required by the spec's `Shell.Info`; ACP gives us nothing to fill it with. */
93
+ metadata: Record<string, unknown>;
94
+ /**
95
+ * Deliberately absent from what we serve. The TUI's shell row fetches the text from
96
+ * `/api/shell/:id/output`, and a value on this object makes it skip that fetch while
97
+ * still rendering nothing; `ShellRun` keeps it internally.
98
+ */
99
+ output?: string;
100
+ time: {
101
+ started: number;
102
+ completed?: number;
103
+ };
104
+ /** Where it ran. The TUI opens its output dialog with this. */
105
+ location?: {
106
+ directory: string;
107
+ project?: {
108
+ id: string;
109
+ directory: string;
110
+ };
111
+ };
112
+ }
113
+ export interface LocationRef {
114
+ directory: string;
115
+ workspaceID?: string;
116
+ }
117
+ export interface TokenUsageInfo {
118
+ input: number;
119
+ output: number;
120
+ reasoning: number;
121
+ cache: {
122
+ read: number;
123
+ write: number;
124
+ };
125
+ }
126
+ /** INFERRED: mirrors the backend-oc's `streamPart` shape. */
127
+ export interface TextPart {
128
+ id: string;
129
+ sessionID: string;
130
+ messageID: string;
131
+ type: 'text';
132
+ text: string;
133
+ time: {
134
+ start: number;
135
+ end?: number;
136
+ };
137
+ }
138
+ export interface ReasoningPart {
139
+ id: string;
140
+ sessionID: string;
141
+ messageID: string;
142
+ type: 'reasoning';
143
+ text: string;
144
+ time: {
145
+ start: number;
146
+ end?: number;
147
+ };
148
+ }
149
+ export interface ToolPart {
150
+ id: string;
151
+ sessionID: string;
152
+ messageID: string;
153
+ type: 'tool';
154
+ callID: string;
155
+ tool: string;
156
+ state: {
157
+ status: 'pending' | 'running' | 'completed' | 'error';
158
+ input?: unknown;
159
+ output?: string;
160
+ title?: string;
161
+ /**
162
+ * ACP's `ToolKind` (`execute`, `edit`, `read`, `search`, …), from the tool call's first
163
+ * frame. The projection emits it because the client's own ACP adapter does: with
164
+ * `kind: "execute"` the row is a shell card even when the agent never sent a
165
+ * programmatic `name` (dsh sends a title only).
166
+ */
167
+ kind?: string;
168
+ /**
169
+ * Why the call failed, as the agent's own sentence ("[tool error: FS_STALE_VERSION]").
170
+ * Kept apart from `output`: `output` is what the tool *produced* (for a `write`
171
+ * that is the file's content), and the client paints `state.error.message` as the
172
+ * failure. Using `output` for both made a failed write render as a successful
173
+ * card whose "error" was the entire file.
174
+ */
175
+ error?: string;
176
+ /**
177
+ * Per-tool metadata that must survive a reload.
178
+ *
179
+ * The client stores this **inside `state`** (`ToolStateCompleted.metadata` in
180
+ * `packages/schema/src/session-message.ts`) and its shell row reads
181
+ * `props.metadata.shellID` to find the shell behind a `!command` card. Dropping it here
182
+ * meant a reloaded transcript showed the tool row without its shell, so the output could
183
+ * never be fetched again.
184
+ */
185
+ metadata?: Record<string, unknown>;
186
+ time: {
187
+ start: number;
188
+ end?: number;
189
+ };
190
+ };
191
+ }
192
+ export type Part = TextPart | ReasoningPart | ToolPart;
193
+ export interface Message {
194
+ id: string;
195
+ sessionID: string;
196
+ role: 'user' | 'assistant';
197
+ parentID?: string;
198
+ time: {
199
+ created: number;
200
+ completed?: number;
201
+ };
202
+ error?: {
203
+ name: string;
204
+ message: string;
205
+ };
206
+ /**
207
+ * A non-conversation notice shown in the transcript, modelled on the client's
208
+ * `Session.Message.System` (`type: "system"`), which the TUI renders as a
209
+ * `◈ Notice` row — the same surface the official client uses for
210
+ * "Instructions updated". The bridge uses it to say WHY a restored tab is
211
+ * empty: the session resumed, but the agent has no `session/load`, so the
212
+ * earlier conversation is not replayed. It is a notice, not a user or
213
+ * assistant turn, so it never counts as conversation content.
214
+ */
215
+ notice?: {
216
+ text: string;
217
+ description?: string;
218
+ };
219
+ /**
220
+ * A `!command` the bridge ran for this session.
221
+ *
222
+ * The client models a shell as its **own top-level message type**, not as an assistant tool
223
+ * part: `packages/schema/src/session-message.ts` declares `type: "shell"` with
224
+ * `{shellID, command, status, exit?, output?}`, and `SessionMessageView` matches
225
+ * `props.message.type === "shell"` to render it with the shell component. Storing a shell as
226
+ * a `tool` part therefore rendered it as a generic tool card after a reload — and, because a
227
+ * generic card has no shell context, it could not resolve `backgroundRunning` either.
228
+ */
229
+ shell?: {
230
+ shellID: string;
231
+ command: string;
232
+ cwd?: string;
233
+ status: 'running' | 'exited' | 'failed';
234
+ exit?: number;
235
+ output?: string;
236
+ };
237
+ }
238
+ /** `POST /api/session/:id/prompt` request body. */
239
+ export interface PromptBody {
240
+ /** The client-generated inbox id; also the id it echoes the user row under. */
241
+ id?: string;
242
+ messageID?: string;
243
+ /** `steer` (default) runs immediately; `queue` waits for the current turn. */
244
+ delivery?: 'steer' | 'queue';
245
+ model?: {
246
+ providerID?: string;
247
+ modelID?: string;
248
+ };
249
+ agent?: string;
250
+ parts?: Array<{
251
+ type: string;
252
+ text?: string;
253
+ [k: string]: unknown;
254
+ }>;
255
+ /** Older clients send a bare `text`. */
256
+ text?: string;
257
+ /**
258
+ * Attachments. Measured on v2.0.30: the real TUI's `@file` picker sends
259
+ * `{uri: "file:///abs/path", mime, name}` — a file URI, NOT base64 (the
260
+ * schema's `{data}` shape is what an API caller would send, and an earlier
261
+ * reading of the schema alone got this wrong: the image path looked dead
262
+ * until the wire was actually inspected). The bridge reads the file from
263
+ * the URI and forwards image attachments as ACP image blocks.
264
+ */
265
+ files?: Array<{
266
+ data?: string;
267
+ uri?: string;
268
+ mime?: string;
269
+ name?: string;
270
+ }>;
271
+ /**
272
+ * Skill mentions. The picker sends the chosen id; the bridge inlines the skill's
273
+ * content as the first text block of the ACP prompt, in the official toModelOutput
274
+ * envelope (`<skill_content>`), because that is what makes an agent actually execute
275
+ * the skill — a resource link is spec-legal but measured toothless. Agents have no ACP
276
+ * surface and stay logged only.
277
+ */
278
+ skills?: Array<{
279
+ id?: string;
280
+ name?: string;
281
+ }>;
282
+ agents?: Array<{
283
+ name?: string;
284
+ }>;
285
+ noReply?: boolean;
286
+ }
287
+ /**
288
+ * `Form.Info` — opencode's own shape for a form the user is asked to fill in.
289
+ *
290
+ * Observed from `packages/protocol/src/groups/form.ts` and
291
+ * `packages/schema/src/form.ts` in the opencode checkout, not invented: the id
292
+ * must start with `frm_`, `fields` must be non-empty, and `title` is required.
293
+ * The field union upstream is tagged by `type`; one interface with optional
294
+ * members serialises identically and is easier to build from a JSON Schema.
295
+ */
296
+ export interface FormFieldOption {
297
+ value: string;
298
+ label: string;
299
+ description?: string;
300
+ }
301
+ export interface FormField {
302
+ key: string;
303
+ type: 'string' | 'number' | 'integer' | 'boolean' | 'multiselect';
304
+ title?: string;
305
+ description?: string;
306
+ required?: boolean;
307
+ format?: string;
308
+ minLength?: number;
309
+ maxLength?: number;
310
+ pattern?: string;
311
+ placeholder?: string;
312
+ minimum?: number;
313
+ maximum?: number;
314
+ minItems?: number;
315
+ maxItems?: number;
316
+ default?: string | number | boolean | string[];
317
+ options?: FormFieldOption[];
318
+ }
319
+ export interface FormInfo {
320
+ id: string;
321
+ sessionID: string;
322
+ title: string;
323
+ fields: FormField[];
324
+ metadata?: Record<string, unknown>;
325
+ }
326
+ /** `Form.Answer` — one value per field, keyed by the field's `key`. */
327
+ export type FormAnswer = Record<string, string | number | boolean | string[]>;
328
+ /** The event names we emit. Proven against the real TUI via the backend-oc. */
329
+ export declare const EVENT: {
330
+ readonly serverConnected: "server.connected";
331
+ readonly sessionCreated: "session.created";
332
+ readonly sessionViewed: "session.viewed";
333
+ readonly sessionUpdated: "session.updated";
334
+ /**
335
+ * The event the TUI actually reads for a title change. Verified against the
336
+ * client's store (`packages/client/src/solid/data.ts`): it has a case for
337
+ * `session.renamed` and **none** for `session.updated`, so a title — whether it
338
+ * came from a rename or from the agent's `session_info_update` — only reaches
339
+ * the sidebar through this one. Payload: `{sessionID, title}`.
340
+ */
341
+ readonly sessionRenamed: "session.renamed";
342
+ /**
343
+ * The session's working directory changed (`/cd`). The client's store has a dedicated
344
+ * case for this one (data.ts `case "session.moved"`) that nothing else can reach: it
345
+ * rewrites the session's `location`/`projectID`/`subpath` — which is what the footer
346
+ * and the sidebar read — and inserts a `location-switched` row into the transcript
347
+ * ("↳ Moved to <dir>") purely from the event. Payload:
348
+ * `{sessionID, location: {directory}, projectID, subpath}`.
349
+ */
350
+ readonly sessionMoved: "session.moved";
351
+ /**
352
+ * The location's command palette changed. The client's store has a dedicated case
353
+ * (`command.updated`) that invalidates and re-syncs `GET /api/command` — which is
354
+ * exactly how the agent's ACP `available_commands_update` (dsh's slash commands, most
355
+ * of which run its skills) reaches the palette. Payload: `{}` + `location`.
356
+ */
357
+ readonly commandUpdated: "command.updated";
358
+ /**
359
+ * The location's model catalog changed. The client's store has a dedicated case that
360
+ * invalidates and re-syncs `GET /api/model`. Needed after a restored session's
361
+ * `session/load` applies the agent's config options: the client fetched the catalog
362
+ * *before* the adoption (at startup), saw only the placeholder, and nothing else would
363
+ * tell it to look again — leaving every model `(unavailable)` and the composer locked.
364
+ * Payload: `{}` + `location`.
365
+ */
366
+ readonly modelUpdated: "model.updated";
367
+ /**
368
+ * The session's selected model changed — including when the *agent* changed it
369
+ * (a rate-limit fallback, say). Payload `{sessionID, model: {providerID, modelID}, previous?}`;
370
+ * the store writes `model` into the session info, which is what the composer
371
+ * and the context meter read.
372
+ */
373
+ readonly modelSelected: "session.model.selected";
374
+ readonly sessionIdle: "session.idle";
375
+ readonly sessionStatus: "session.status";
376
+ readonly sessionError: "session.error";
377
+ readonly messageUpdated: "message.updated";
378
+ readonly messagePartUpdated: "message.part.updated";
379
+ readonly messagePartDelta: "message.part.delta";
380
+ readonly permissionAsked: "permission.asked";
381
+ readonly permissionReplied: "permission.replied";
382
+ /**
383
+ * Form lifecycle, as the TUI's data store reads it (`packages/schema/src/form.ts`
384
+ * declares them ephemeral). `form.created` is what makes the form UI appear;
385
+ * the reply and cancel events dismiss it.
386
+ */
387
+ readonly formCreated: "form.created";
388
+ readonly formReplied: "form.replied";
389
+ readonly formCancelled: "form.cancelled";
390
+ readonly sessionUsageUpdated: "session.usage.updated";
391
+ /**
392
+ * The session's `time.updated`. The client's spinner reads it through
393
+ * `time.now()` to render "Sending · Ns"; without a frame carrying it (and a
394
+ * `message.updated` with `completed`) the counter keeps running after the work
395
+ * stopped. Ephemeral, like `session.usage.updated`.
396
+ */
397
+ readonly sessionTimeUpdated: "session.time.updated";
398
+ readonly toolInputStarted: "session.tool.input.started";
399
+ readonly toolInputDelta: "session.tool.input.delta";
400
+ readonly toolInputEnded: "session.tool.input.ended";
401
+ readonly toolCalled: "session.tool.called";
402
+ readonly toolProgress: "session.tool.progress";
403
+ readonly toolSuccess: "session.tool.success";
404
+ readonly toolFailed: "session.tool.failed";
405
+ readonly inboxEnqueued: "session.inbox.enqueued";
406
+ readonly inboxDelivered: "session.inbox.delivered";
407
+ readonly inboxCancelled: "session.inbox.cancelled";
408
+ readonly inboxDeliveryChanged: "session.inbox.delivery.changed";
409
+ readonly shellStarted: "session.shell.started";
410
+ readonly shellEnded: "session.shell.ended";
411
+ /**
412
+ * The official lifecycle event that takes a finished shell out of the client's **live** shell
413
+ * table (`shell.exited` / `shell.deleted`, both ephemeral in `packages/schema/src/shell.ts`).
414
+ * The client's `data.shell` is what its shell row reads for
415
+ * `backgroundRunning = Boolean(id && data.shell.get(id))`, so without this an exited command
416
+ * kept a spinner on its card after the session was reopened. The `/api/shell` list itself
417
+ * keeps the record, so its output stays readable.
418
+ */
419
+ readonly shellExited: "shell.exited";
420
+ readonly stepStarted: "session.step.started";
421
+ readonly stepEnded: "session.step.ended";
422
+ readonly stepFailed: "session.step.failed";
423
+ readonly executionStarted: "session.execution.started";
424
+ readonly executionSucceeded: "session.execution.succeeded";
425
+ readonly executionInterrupted: "session.execution.interrupted";
426
+ readonly executionFailed: "session.execution.failed";
427
+ readonly textStarted: "session.text.started";
428
+ readonly textDelta: "session.text.delta";
429
+ readonly textEnded: "session.text.ended";
430
+ readonly reasoningStarted: "session.reasoning.started";
431
+ readonly reasoningDelta: "session.reasoning.delta";
432
+ readonly reasoningEnded: "session.reasoning.ended";
433
+ readonly turnWait: "turn.wait";
434
+ readonly turnIdle: "turn.idle";
435
+ };
@@ -0,0 +1,126 @@
1
+ /**
2
+ * The opencode v2 surface this bridge implements.
3
+ *
4
+ * Two reference points shaped this file:
5
+ * - `packages/tui/test/fixture/tui-client.ts` in the opencode repo: the
6
+ * minimal server their own TUI tests accept. Its route list is the floor.
7
+ * - the backend-oc's bridge: the same surface, proven against the real TUI.
8
+ *
9
+ * Everything here is therefore *observed*, not invented. Where a shape was
10
+ * inferred (part payloads), it is marked with `INFERRED` so the next person
11
+ * knows what to re-check against a new client build.
12
+ */
13
+ /** The event names we emit. Proven against the real TUI via the backend-oc. */
14
+ export const EVENT = {
15
+ serverConnected: 'server.connected',
16
+ sessionCreated: 'session.created',
17
+ sessionViewed: 'session.viewed',
18
+ sessionUpdated: 'session.updated',
19
+ /**
20
+ * The event the TUI actually reads for a title change. Verified against the
21
+ * client's store (`packages/client/src/solid/data.ts`): it has a case for
22
+ * `session.renamed` and **none** for `session.updated`, so a title — whether it
23
+ * came from a rename or from the agent's `session_info_update` — only reaches
24
+ * the sidebar through this one. Payload: `{sessionID, title}`.
25
+ */
26
+ sessionRenamed: 'session.renamed',
27
+ /**
28
+ * The session's working directory changed (`/cd`). The client's store has a dedicated
29
+ * case for this one (data.ts `case "session.moved"`) that nothing else can reach: it
30
+ * rewrites the session's `location`/`projectID`/`subpath` — which is what the footer
31
+ * and the sidebar read — and inserts a `location-switched` row into the transcript
32
+ * ("↳ Moved to <dir>") purely from the event. Payload:
33
+ * `{sessionID, location: {directory}, projectID, subpath}`.
34
+ */
35
+ sessionMoved: 'session.moved',
36
+ /**
37
+ * The location's command palette changed. The client's store has a dedicated case
38
+ * (`command.updated`) that invalidates and re-syncs `GET /api/command` — which is
39
+ * exactly how the agent's ACP `available_commands_update` (dsh's slash commands, most
40
+ * of which run its skills) reaches the palette. Payload: `{}` + `location`.
41
+ */
42
+ commandUpdated: 'command.updated',
43
+ /**
44
+ * The location's model catalog changed. The client's store has a dedicated case that
45
+ * invalidates and re-syncs `GET /api/model`. Needed after a restored session's
46
+ * `session/load` applies the agent's config options: the client fetched the catalog
47
+ * *before* the adoption (at startup), saw only the placeholder, and nothing else would
48
+ * tell it to look again — leaving every model `(unavailable)` and the composer locked.
49
+ * Payload: `{}` + `location`.
50
+ */
51
+ modelUpdated: 'model.updated',
52
+ /**
53
+ * The session's selected model changed — including when the *agent* changed it
54
+ * (a rate-limit fallback, say). Payload `{sessionID, model: {providerID, modelID}, previous?}`;
55
+ * the store writes `model` into the session info, which is what the composer
56
+ * and the context meter read.
57
+ */
58
+ modelSelected: 'session.model.selected',
59
+ sessionIdle: 'session.idle',
60
+ sessionStatus: 'session.status',
61
+ sessionError: 'session.error',
62
+ messageUpdated: 'message.updated',
63
+ messagePartUpdated: 'message.part.updated',
64
+ messagePartDelta: 'message.part.delta',
65
+ permissionAsked: 'permission.asked',
66
+ permissionReplied: 'permission.replied',
67
+ /**
68
+ * Form lifecycle, as the TUI's data store reads it (`packages/schema/src/form.ts`
69
+ * declares them ephemeral). `form.created` is what makes the form UI appear;
70
+ * the reply and cancel events dismiss it.
71
+ */
72
+ formCreated: 'form.created',
73
+ formReplied: 'form.replied',
74
+ formCancelled: 'form.cancelled',
75
+ sessionUsageUpdated: 'session.usage.updated',
76
+ /**
77
+ * The session's `time.updated`. The client's spinner reads it through
78
+ * `time.now()` to render "Sending · Ns"; without a frame carrying it (and a
79
+ * `message.updated` with `completed`) the counter keeps running after the work
80
+ * stopped. Ephemeral, like `session.usage.updated`.
81
+ */
82
+ sessionTimeUpdated: 'session.time.updated',
83
+ // opencode v2 speaks a different vocabulary than v1's message.part.*. The TUI
84
+ // only renders these, so both are emitted (v1 kept for the smoke harness).
85
+ toolInputStarted: 'session.tool.input.started',
86
+ toolInputDelta: 'session.tool.input.delta',
87
+ toolInputEnded: 'session.tool.input.ended',
88
+ toolCalled: 'session.tool.called',
89
+ toolProgress: 'session.tool.progress',
90
+ toolSuccess: 'session.tool.success',
91
+ toolFailed: 'session.tool.failed',
92
+ inboxEnqueued: 'session.inbox.enqueued',
93
+ inboxDelivered: 'session.inbox.delivered',
94
+ inboxCancelled: 'session.inbox.cancelled',
95
+ inboxDeliveryChanged: 'session.inbox.delivery.changed',
96
+ shellStarted: 'session.shell.started',
97
+ shellEnded: 'session.shell.ended',
98
+ /**
99
+ * The official lifecycle event that takes a finished shell out of the client's **live** shell
100
+ * table (`shell.exited` / `shell.deleted`, both ephemeral in `packages/schema/src/shell.ts`).
101
+ * The client's `data.shell` is what its shell row reads for
102
+ * `backgroundRunning = Boolean(id && data.shell.get(id))`, so without this an exited command
103
+ * kept a spinner on its card after the session was reopened. The `/api/shell` list itself
104
+ * keeps the record, so its output stays readable.
105
+ */
106
+ shellExited: 'shell.exited',
107
+ stepStarted: 'session.step.started',
108
+ stepEnded: 'session.step.ended',
109
+ stepFailed: 'session.step.failed',
110
+ executionStarted: 'session.execution.started',
111
+ executionSucceeded: 'session.execution.succeeded',
112
+ // The client's store maps this one to `outcome: "interrupted"`; it is not
113
+ // in the published OpenAPI (which models no execution events at all), so the
114
+ // client is the authority here.
115
+ executionInterrupted: 'session.execution.interrupted',
116
+ executionFailed: 'session.execution.failed',
117
+ textStarted: 'session.text.started',
118
+ textDelta: 'session.text.delta',
119
+ textEnded: 'session.text.ended',
120
+ reasoningStarted: 'session.reasoning.started',
121
+ reasoningDelta: 'session.reasoning.delta',
122
+ reasoningEnded: 'session.reasoning.ended',
123
+ turnWait: 'turn.wait',
124
+ turnIdle: 'turn.idle',
125
+ };
126
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA0RH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,eAAe,EAAE,kBAAkB;IACnC,cAAc,EAAE,iBAAiB;IACjC,aAAa,EAAE,gBAAgB;IAC/B,cAAc,EAAE,iBAAiB;IACjC;;;;;;OAMG;IACH,cAAc,EAAE,iBAAiB;IACjC;;;;;;;OAOG;IACH,YAAY,EAAE,eAAe;IAC7B;;;;;OAKG;IACH,cAAc,EAAE,iBAAiB;IACjC;;;;;;;OAOG;IACH,YAAY,EAAE,eAAe;IAC7B;;;;;OAKG;IACH,aAAa,EAAE,wBAAwB;IACvC,WAAW,EAAE,cAAc;IAC3B,aAAa,EAAE,gBAAgB;IAC/B,YAAY,EAAE,eAAe;IAC7B,cAAc,EAAE,iBAAiB;IACjC,kBAAkB,EAAE,sBAAsB;IAC1C,gBAAgB,EAAE,oBAAoB;IACtC,eAAe,EAAE,kBAAkB;IACnC,iBAAiB,EAAE,oBAAoB;IACvC;;;;OAIG;IACH,WAAW,EAAE,cAAc;IAC3B,WAAW,EAAE,cAAc;IAC3B,aAAa,EAAE,gBAAgB;IAC/B,mBAAmB,EAAE,uBAAuB;IAC5C;;;;;OAKG;IACH,kBAAkB,EAAE,sBAAsB;IAC1C,8EAA8E;IAC9E,2EAA2E;IAC3E,gBAAgB,EAAE,4BAA4B;IAC9C,cAAc,EAAE,0BAA0B;IAC1C,cAAc,EAAE,0BAA0B;IAC1C,UAAU,EAAE,qBAAqB;IACjC,YAAY,EAAE,uBAAuB;IACrC,WAAW,EAAE,sBAAsB;IACnC,UAAU,EAAE,qBAAqB;IACjC,aAAa,EAAE,wBAAwB;IACvC,cAAc,EAAE,yBAAyB;IACzC,cAAc,EAAE,yBAAyB;IACzC,oBAAoB,EAAE,gCAAgC;IACtD,YAAY,EAAE,uBAAuB;IACrC,UAAU,EAAE,qBAAqB;IACjC;;;;;;;OAOG;IACH,WAAW,EAAE,cAAc;IAC3B,WAAW,EAAE,sBAAsB;IACnC,SAAS,EAAE,oBAAoB;IAC/B,UAAU,EAAE,qBAAqB;IACjC,gBAAgB,EAAE,2BAA2B;IAC7C,kBAAkB,EAAE,6BAA6B;IACjD,0EAA0E;IAC1E,6EAA6E;IAC7E,gCAAgC;IAChC,oBAAoB,EAAE,+BAA+B;IACrD,eAAe,EAAE,0BAA0B;IAC3C,WAAW,EAAE,sBAAsB;IACnC,SAAS,EAAE,oBAAoB;IAC/B,SAAS,EAAE,oBAAoB;IAC/B,gBAAgB,EAAE,2BAA2B;IAC7C,cAAc,EAAE,yBAAyB;IACzC,cAAc,EAAE,yBAAyB;IACzC,QAAQ,EAAE,WAAW;IACrB,QAAQ,EAAE,WAAW;CACb,CAAC"}
@@ -0,0 +1,39 @@
1
+ export interface DaemonRecord {
2
+ pid: number;
3
+ /** Milliseconds since the epoch. */
4
+ startedAt: number;
5
+ directory: string;
6
+ /** The agent command as the user spelled it (e.g. `dsh`). */
7
+ agent: string;
8
+ agentArgs: string[];
9
+ /** The bridge URL the TUI was pointed at. */
10
+ url: string;
11
+ /** This package's version, for spotting entries from an older install. */
12
+ version: string;
13
+ }
14
+ export interface DaemonEntry {
15
+ record: DaemonRecord;
16
+ /** `kill(pid, 0)` said the process exists right now. */
17
+ alive: boolean;
18
+ file: string;
19
+ }
20
+ /**
21
+ * Where the records live. `OPENCODE_ACP_CLIENT_DAEMONS` overrides it — the test
22
+ * suite points it at a scratch directory, exactly like the session map.
23
+ */
24
+ export declare function daemonsDir(env?: NodeJS.ProcessEnv): string;
25
+ /** Whether a pid exists. Signal 0 does the permission check and nothing else. */
26
+ export declare function isAlive(pid: number): boolean;
27
+ /** Record this process. Best effort: a failure here must not stop the bridge. */
28
+ export declare function registerDaemon(record: Omit<DaemonRecord, 'pid' | 'startedAt'>, pid?: number): void;
29
+ /** Drop this process's record. Safe to call more than once. */
30
+ export declare function unregisterDaemon(pid?: number): void;
31
+ /**
32
+ * Every recorded bridge, newest first, each checked for liveness at call time.
33
+ *
34
+ * A malformed file is skipped rather than thrown: a half-written record must not
35
+ * make `ps` unusable exactly when the user is trying to clean up.
36
+ */
37
+ export declare function listDaemons(env?: NodeJS.ProcessEnv): DaemonEntry[];
38
+ /** Remove the records whose process is gone. Returns how many were dropped. */
39
+ export declare function pruneDaemons(env?: NodeJS.ProcessEnv): number;