@phren/cli 0.3.10 → 0.3.12

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 (184) hide show
  1. package/dist/bridge/agent-hook-stores.d.ts +3 -0
  2. package/dist/bridge/agent-hook-stores.js +5 -0
  3. package/dist/bridge/agent-hooks.d.ts +159 -5
  4. package/dist/bridge/agent-hooks.js +663 -49
  5. package/dist/bridge/approval-summary.d.ts +16 -0
  6. package/dist/bridge/approval-summary.js +133 -0
  7. package/dist/bridge/authority-command.d.ts +20 -0
  8. package/dist/bridge/authority-command.js +120 -0
  9. package/dist/bridge/authority.d.ts +223 -0
  10. package/dist/bridge/authority.js +231 -0
  11. package/dist/bridge/claude-account-setup.d.ts +14 -0
  12. package/dist/bridge/claude-account-setup.js +69 -0
  13. package/dist/bridge/claude-accounts.d.ts +49 -0
  14. package/dist/bridge/claude-accounts.js +195 -0
  15. package/dist/bridge/code-routes.js +2 -2
  16. package/dist/bridge/codex-app-server.d.ts +144 -0
  17. package/dist/bridge/codex-app-server.js +319 -0
  18. package/dist/bridge/codex-auth-refresh.d.ts +33 -0
  19. package/dist/bridge/codex-auth-refresh.js +71 -0
  20. package/dist/bridge/codex-question-reply.d.ts +16 -0
  21. package/dist/bridge/codex-question-reply.js +57 -0
  22. package/dist/bridge/codex-review-mode.d.ts +10 -0
  23. package/dist/bridge/codex-review-mode.js +74 -0
  24. package/dist/bridge/codex-servers.d.ts +217 -0
  25. package/dist/bridge/codex-servers.js +636 -0
  26. package/dist/bridge/command.js +94 -4
  27. package/dist/bridge/computer-identity.d.ts +75 -0
  28. package/dist/bridge/computer-identity.js +166 -0
  29. package/dist/bridge/conductor-group.d.ts +91 -8
  30. package/dist/bridge/conductor-group.js +105 -9
  31. package/dist/bridge/conductor-role.d.ts +94 -0
  32. package/dist/bridge/conductor-role.js +176 -0
  33. package/dist/bridge/conductor-sets.d.ts +20 -0
  34. package/dist/bridge/conductor-sets.js +59 -0
  35. package/dist/bridge/dispatch-command.d.ts +3 -0
  36. package/dist/bridge/dispatch-command.js +75 -11
  37. package/dist/bridge/dispatch-returns.d.ts +123 -19
  38. package/dist/bridge/dispatch-returns.js +357 -50
  39. package/dist/bridge/dispatch.d.ts +103 -2
  40. package/dist/bridge/dispatch.js +272 -40
  41. package/dist/bridge/fanout-messages.js +2 -2
  42. package/dist/bridge/fanouts.d.ts +7 -1
  43. package/dist/bridge/fanouts.js +40 -5
  44. package/dist/bridge/folder-trust.d.ts +56 -0
  45. package/dist/bridge/folder-trust.js +195 -0
  46. package/dist/bridge/grants.d.ts +22 -1
  47. package/dist/bridge/grants.js +57 -9
  48. package/dist/bridge/hand-off.d.ts +21 -9
  49. package/dist/bridge/hand-off.js +58 -45
  50. package/dist/bridge/harness-status.d.ts +11 -0
  51. package/dist/bridge/harness-status.js +32 -0
  52. package/dist/bridge/harnesses.d.ts +39 -0
  53. package/dist/bridge/harnesses.js +65 -0
  54. package/dist/bridge/health.d.ts +2 -0
  55. package/dist/bridge/health.js +1 -1
  56. package/dist/bridge/herdr.d.ts +11 -2
  57. package/dist/bridge/herdr.js +98 -23
  58. package/dist/bridge/hook-fast.d.ts +4 -0
  59. package/dist/bridge/hook-fast.js +68 -0
  60. package/dist/bridge/install.d.ts +16 -1
  61. package/dist/bridge/install.js +88 -21
  62. package/dist/bridge/launch-brief.d.ts +96 -0
  63. package/dist/bridge/launch-brief.js +164 -0
  64. package/dist/bridge/model-switch.d.ts +3 -0
  65. package/dist/bridge/model-switch.js +17 -1
  66. package/dist/bridge/models.d.ts +8 -4
  67. package/dist/bridge/models.js +24 -8
  68. package/dist/bridge/mux-wire.d.ts +9 -0
  69. package/dist/bridge/mux-wire.js +19 -0
  70. package/dist/bridge/opencode-pane-server.d.ts +113 -0
  71. package/dist/bridge/opencode-pane-server.js +332 -0
  72. package/dist/bridge/opencode-panes.d.ts +111 -0
  73. package/dist/bridge/opencode-panes.js +295 -0
  74. package/dist/bridge/pane-accounts.d.ts +8 -0
  75. package/dist/bridge/pane-accounts.js +46 -0
  76. package/dist/bridge/prompt-startup.d.ts +5 -0
  77. package/dist/bridge/prompt-startup.js +24 -0
  78. package/dist/bridge/protocol.d.ts +5 -0
  79. package/dist/bridge/protocol.js +4 -0
  80. package/dist/bridge/push.d.ts +5 -4
  81. package/dist/bridge/push.js +6 -4
  82. package/dist/bridge/questions.d.ts +37 -2
  83. package/dist/bridge/questions.js +158 -15
  84. package/dist/bridge/resources.d.ts +125 -0
  85. package/dist/bridge/resources.js +314 -0
  86. package/dist/bridge/schedule-format.d.ts +2 -0
  87. package/dist/bridge/schedule-format.js +3 -0
  88. package/dist/bridge/schedule-launch.d.ts +2 -1
  89. package/dist/bridge/schedule-launch.js +23 -53
  90. package/dist/bridge/schedule-watch.d.ts +10 -1
  91. package/dist/bridge/schedule-watch.js +54 -2
  92. package/dist/bridge/server-launch.d.ts +22 -5
  93. package/dist/bridge/server-launch.js +225 -29
  94. package/dist/bridge/server-overview.d.ts +8 -2
  95. package/dist/bridge/server-overview.js +26 -5
  96. package/dist/bridge/server-pane-routes.d.ts +2 -0
  97. package/dist/bridge/server-pane-routes.js +145 -15
  98. package/dist/bridge/server-routes.d.ts +11 -1
  99. package/dist/bridge/server-routes.js +195 -36
  100. package/dist/bridge/server-stream.d.ts +2 -0
  101. package/dist/bridge/server-stream.js +22 -8
  102. package/dist/bridge/server.d.ts +6 -1
  103. package/dist/bridge/server.js +47 -12
  104. package/dist/bridge/session-activity.d.ts +81 -0
  105. package/dist/bridge/session-activity.js +117 -0
  106. package/dist/bridge/session-rename.d.ts +48 -0
  107. package/dist/bridge/session-rename.js +190 -0
  108. package/dist/bridge/session-servers.js +2 -2
  109. package/dist/bridge/settings-switch.d.ts +60 -0
  110. package/dist/bridge/settings-switch.js +287 -0
  111. package/dist/bridge/speech-voice.d.ts +55 -0
  112. package/dist/bridge/speech-voice.js +132 -0
  113. package/dist/bridge/speech.d.ts +70 -11
  114. package/dist/bridge/speech.js +169 -41
  115. package/dist/bridge/terminal-herdr.js +9 -3
  116. package/dist/bridge/terminal-tmux.d.ts +3 -3
  117. package/dist/bridge/terminal-tmux.js +24 -9
  118. package/dist/bridge/terminal.d.ts +27 -4
  119. package/dist/bridge/terminal.js +8 -1
  120. package/dist/bridge/transcript-claude.js +62 -12
  121. package/dist/bridge/transcript-codex.d.ts +0 -2
  122. package/dist/bridge/transcript-codex.js +29 -4
  123. package/dist/bridge/transcript-preview.d.ts +1 -0
  124. package/dist/bridge/transcript-preview.js +24 -4
  125. package/dist/bridge/transcripts.d.ts +15 -2
  126. package/dist/bridge/transcripts.js +47 -16
  127. package/dist/bridge/turn-records.d.ts +85 -0
  128. package/dist/bridge/turn-records.js +143 -0
  129. package/dist/bridge/uploads.d.ts +3 -0
  130. package/dist/bridge/uploads.js +14 -0
  131. package/dist/bridge/usage.d.ts +73 -28
  132. package/dist/bridge/usage.js +313 -340
  133. package/dist/bridge-hook.mjs +24624 -18450
  134. package/dist/cli/claude-unmanaged.d.ts +12 -0
  135. package/dist/cli/claude-unmanaged.js +105 -0
  136. package/dist/cli/schedules.js +2 -1
  137. package/dist/cli/session-start.js +10 -1
  138. package/dist/cli/session-stop.js +9 -1
  139. package/dist/cli-registry.d.ts +2 -0
  140. package/dist/cli-registry.js +37 -5
  141. package/dist/computers/command.d.ts +6 -0
  142. package/dist/computers/command.js +152 -0
  143. package/dist/computers/mcp.d.ts +1 -0
  144. package/dist/computers/mcp.js +97 -0
  145. package/dist/computers/read.d.ts +85 -0
  146. package/dist/computers/read.js +177 -0
  147. package/dist/data/task-receipts.d.ts +19 -0
  148. package/dist/data/task-receipts.js +68 -0
  149. package/dist/data/tasks.js +4 -1
  150. package/dist/entrypoint.js +10 -0
  151. package/dist/fanout/adapters/claude.js +15 -2
  152. package/dist/fanout/adapters/types.d.ts +6 -0
  153. package/dist/fanout/launcher.d.ts +5 -1
  154. package/dist/fanout/launcher.js +34 -3
  155. package/dist/fanout/picker.js +3 -2
  156. package/dist/fanout/usage.js +1 -1
  157. package/dist/generated/memory-ui-graph.browser.js +63 -63
  158. package/dist/graph-core/model.js +24 -3
  159. package/dist/graph-core/types.d.ts +4 -1
  160. package/dist/graph-core/types.js +1 -0
  161. package/dist/init/init-preset.js +7 -3
  162. package/dist/init/init-uninstall.js +2 -11
  163. package/dist/init/teardown.d.ts +3 -0
  164. package/dist/init/teardown.js +47 -0
  165. package/dist/link/context.js +21 -9
  166. package/dist/mcp/plugin-mode.js +1 -1
  167. package/dist/memory-ui-graph.runtime.js +63 -63
  168. package/dist/modules/code-package.d.ts +1 -0
  169. package/dist/modules/code-package.js +36 -7
  170. package/dist/modules/registry.js +14 -13
  171. package/dist/profile-store.d.ts +6 -0
  172. package/dist/profile-store.js +25 -1
  173. package/dist/shell/graph/glyphs.js +4 -0
  174. package/dist/shell/graph/graph-view.js +2 -0
  175. package/dist/status.js +7 -1
  176. package/dist/sync/task-claim.js +3 -2
  177. package/dist/task/lifecycle.js +25 -4
  178. package/dist/test-global-setup.js +5 -0
  179. package/dist/tools/dispatch.js +35 -2
  180. package/dist/tools/tasks.js +10 -1
  181. package/package.json +1 -1
  182. package/plugins/opencode/phren-transcript.js +87 -4
  183. package/starter/global/skills/conductor/SKILL.md +17 -2
  184. package/starter/global/skills/fanout/SKILL.md +3 -0
@@ -6,15 +6,19 @@ import { fanoutWorktrees } from "./fanouts.js";
6
6
  import { gitWorktrees, resolveWorktree } from "./git-worktrees.js";
7
7
  import { gitCommit, gitPullRequest, gitPush } from "./git-publish.js";
8
8
  import { findPane, paneAgentName, paneChatState, paneIdentity, snapshot, startingPane, trustedDirectory, validateStartingTarget, validateTarget } from "./herdr.js";
9
- import { terminalProvider } from "./terminal.js";
9
+ import { agentNotReady, terminalProvider } from "./terminal.js";
10
+ import { AppServerRpcError } from "./codex-app-server.js";
11
+ import { CodexServerUnavailable, codexServers } from "./codex-servers.js";
10
12
  import { refuseWorkingSlash } from "./model-switch.js";
11
13
  import { sessionWebServers } from "./session-servers.js";
12
14
  import { repositoryDiff } from "./projects.js";
13
15
  import { BridgeError, MAX_FRAME, object, objects, startingTargetSchema, targetSchema } from "./protocol.js";
14
- import { childAgent, childAgentTree, conversationNamedPaths, transcriptPath } from "./transcripts.js";
16
+ import { childAgent, childAgentTree, conversationNamedPaths, targetTranscriptPath } from "./transcripts.js";
15
17
  import { sideQuestionText } from "./side-questions.js";
16
18
  import { saveUpload } from "./uploads.js";
17
19
  import { deliveryIdSchema, PromptOnce, promptScope } from "./prompt-once.js";
20
+ import { promptWithStartupRetry } from "./prompt-startup.js";
21
+ import { sendServedPrompt, servedPane } from "./opencode-panes.js";
18
22
  export /** A file from the phone: a plain name and base64 bytes, bounded. */ function uploadBody(data) {
19
23
  const name = z.string().regex(/^[A-Za-z0-9_][A-Za-z0-9_ .()-]{0,199}$/).refine(n => !n.includes("..")).parse(data.name);
20
24
  const encoded = z.string().max(11_184_812).regex(/^[A-Za-z0-9+/]*={0,2}$/).parse(data.data);
@@ -225,6 +229,23 @@ async function typeSecret(server, pane, text) {
225
229
  }
226
230
  }
227
231
  const promptOnce = new PromptOnce();
232
+ /** A prompt for an OpenCode pane the Hook started with its own server: sent
233
+ * over that API into the conversation the TUI shows (a new one, shown first,
234
+ * when it has none) and confirmed by the user turn appearing there. Undefined
235
+ * when the pane has no server entry, the text is a slash command (the TUI's
236
+ * own menus), or nothing reached OpenCode; the caller then types it. */
237
+ async function servedPrompt(target, session, text, typing) {
238
+ if (target.source !== "opencode" || text.trim().startsWith("/"))
239
+ return undefined;
240
+ const entry = servedPane(target.server, target.pane);
241
+ if (!entry)
242
+ return undefined;
243
+ typing();
244
+ const sent = await sendServedPrompt(entry, session, text);
245
+ if (!sent.sent)
246
+ return undefined;
247
+ return sent.delivered ? { ok: true, delivered: true } : { ok: true, deliveryUncertain: true };
248
+ }
228
249
  export async function paneRoute(ctx, url, data, response) {
229
250
  if (url.pathname !== "/v1/prompt")
230
251
  return paneRouteOnce(ctx, url, data, response, () => { });
@@ -234,7 +255,7 @@ export async function paneRoute(ctx, url, data, response) {
234
255
  return promptOnce.run(id, promptScope(object(data.target), String(data.text ?? "")), async (typing) => object(await paneRouteOnce(ctx, url, data, response, typing)));
235
256
  }
236
257
  async function paneRouteOnce(ctx, url, data, response, typing) {
237
- const { agentHooks, modelSwitcher, codexQuestions, sideQuestions } = ctx;
258
+ const { agentHooks, modelSwitcher, settingsSwitcher, codexQuestions, sideQuestions } = ctx;
238
259
  let result;
239
260
  if (url.pathname === "/v1/keys" && object(data.target).starting === true) {
240
261
  // A folder-trust or login prompt comes before the agent has a
@@ -261,10 +282,30 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
261
282
  else if (url.pathname === "/v1/prompt" && object(data.target).starting === true) {
262
283
  const target = startingTargetSchema.parse(data.target);
263
284
  const pane = await validateStartingTarget(target);
285
+ if (typeof pane.startingSession === "string") {
286
+ const resolved = { ...target, session: pane.startingSession };
287
+ modelSwitcher.assertAvailable(resolved);
288
+ settingsSwitcher.assertAvailable(resolved);
289
+ sideQuestions.assertAvailable(resolved);
290
+ }
264
291
  const text = z.string().min(1).max(32768).refine(t => !/[\x00-\x08\x0b-\x1f\x7f]/.test(t)).parse(data.text);
265
292
  refuseWorkingSlash(pane, text);
293
+ const served = await servedPrompt(target, undefined, text, typing);
294
+ if (served)
295
+ return served;
266
296
  typing();
267
- await terminalProvider().prompt(target.server, target.pane, text);
297
+ await promptWithStartupRetry(() => terminalProvider().prompt(target.server, target.pane, text), async () => {
298
+ const current = await validateStartingTarget(target);
299
+ if (current.terminal_id !== pane.terminal_id)
300
+ throw new BridgeError(409, "This agent pane changed. Reopen the chat.");
301
+ if (typeof current.startingSession === "string") {
302
+ const resolved = { ...target, session: current.startingSession };
303
+ modelSwitcher.assertAvailable(resolved);
304
+ settingsSwitcher.assertAvailable(resolved);
305
+ sideQuestions.assertAvailable(resolved);
306
+ }
307
+ refuseWorkingSlash(current, text);
308
+ });
268
309
  // A dispatched worker's brief is often long enough for Claude Code to
269
310
  // swallow the Enter; a slash command opens a menu an Enter would answer.
270
311
  const submitted = target.source !== "claude" || text.trim().startsWith("/")
@@ -287,9 +328,10 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
287
328
  const target = targetSchema.parse(data.target);
288
329
  // Uploads store bytes without answering or interrupting the agent.
289
330
  // They still require fresh identity, just like prompt mutations.
290
- const sendsInput = ["/v1/prompt", "/v1/keys", "/v1/secret", "/v1/model"].includes(url.pathname);
331
+ const sendsInput = ["/v1/prompt", "/v1/keys", "/v1/secret", "/v1/model", "/v1/settings"].includes(url.pathname);
291
332
  if (sendsInput) {
292
333
  modelSwitcher.assertAvailable(target);
334
+ settingsSwitcher.assertAvailable(target);
293
335
  sideQuestions.assertAvailable(target);
294
336
  }
295
337
  // A key press is how a prompt the agent draws in its terminal gets
@@ -298,6 +340,7 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
298
340
  const pane = await validateTarget(target, false, sendsInput || url.pathname === "/v1/upload");
299
341
  if (sendsInput) {
300
342
  modelSwitcher.assertAvailable(target);
343
+ settingsSwitcher.assertAvailable(target);
301
344
  sideQuestions.assertAvailable(target);
302
345
  }
303
346
  if (url.pathname === "/v1/prompt") {
@@ -305,9 +348,13 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
305
348
  // is pending there: an approval the Hook holds or saw, or a
306
349
  // status Herdr cannot read. Otherwise the answer keys are the way.
307
350
  const status = String(pane.agent_status);
308
- if (status === "unknown" || (["blocked", "waiting"].includes(status) && (agentHooks.approval(target) || agentHooks.terminalPrompt(target)))) {
351
+ if (status === "unknown" || (["blocked", "waiting"].includes(status) && (agentHooks.approval(target) || agentHooks.terminalPrompt(target) || agentHooks.servedQuestion(target)))) {
309
352
  throw new BridgeError(409, "This agent needs input in the terminal first.");
310
353
  }
354
+ const text = typeof data.text === "string" && data.text && data.text.length <= 32768 && !/[\x00-\x08\x0b-\x1f\x7f]/.test(data.text) ? data.text : undefined;
355
+ const served = text === undefined ? undefined : await servedPrompt(target, target.session, text, typing);
356
+ if (served)
357
+ return served;
311
358
  }
312
359
  if (url.pathname === "/v1/prompt") {
313
360
  const text = z.string().min(1).max(32768).refine(t => !/[\x00-\x08\x0b-\x1f\x7f]/.test(t)).parse(data.text);
@@ -317,6 +364,9 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
317
364
  // A working agent queues typed text and submits it when its turn
318
365
  // ends, which can be minutes away; waiting for that only delays
319
366
  // the phone. The record still guards the paste for ten minutes.
367
+ // Claude Code is the exception: it takes a message typed mid-turn at
368
+ // once and runs UserPromptSubmit about a third of a second later, so a
369
+ // busy Claude gets the idle wait and the phone a confirmed delivery.
320
370
  refuseWorkingSlash(pane, text, target.source);
321
371
  if (sideQuestionText(target.source, text) !== undefined) {
322
372
  // Claude's `/btw` runs beside the turn and never reaches the transcript:
@@ -326,11 +376,51 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
326
376
  }
327
377
  if (target.source === "codex" && /^\s*\/model\s+\S/i.test(text))
328
378
  throw new BridgeError(422, "Use the model picker to switch Codex models.");
329
- const busy = String(pane.agent_status) === "working";
330
- const expected = agentHooks.expectDelivery(target, text, busy ? 300 : 1_500);
331
- typing();
332
- await terminalProvider().prompt(target.server, target.pane, text);
333
- let outcome = await expected;
379
+ // A Codex pane on the Hook's own app-server takes the prompt as a turn on
380
+ // its thread, acknowledged with the turn id; nothing is typed. A slash
381
+ // command is the TUI's own and is still typed. An unreachable server
382
+ // sent nothing, so the pane is typed into instead; a request that may
383
+ // have reached it is reported uncertain and never retried.
384
+ const owned = text.trim().startsWith("/") ? undefined : codexServers.forTarget(target);
385
+ if (owned) {
386
+ typing();
387
+ try {
388
+ const { turnId } = await codexServers.prompt(owned, text);
389
+ return { ok: true, delivered: true, turnId };
390
+ }
391
+ catch (error) {
392
+ if (error instanceof AppServerRpcError)
393
+ throw new BridgeError(409, `Codex refused the message: ${error.message}`);
394
+ if (!(error instanceof CodexServerUnavailable))
395
+ return { ok: true, deliveryUncertain: true };
396
+ }
397
+ }
398
+ let busy = String(pane.agent_status) === "working";
399
+ let outcome = await promptWithStartupRetry(async () => {
400
+ const refused = new AbortController();
401
+ const expected = agentHooks.expectDelivery(target, text, busy && target.source !== "claude" ? 300 : 1_500, refused.signal);
402
+ typing();
403
+ try {
404
+ await terminalProvider().prompt(target.server, target.pane, text);
405
+ }
406
+ catch (error) {
407
+ if (agentNotReady(error))
408
+ refused.abort();
409
+ throw error;
410
+ }
411
+ return expected;
412
+ }, async () => {
413
+ // The same conversation can move to another terminal instance. A
414
+ // retry must retain both bindings and all input reservations.
415
+ const current = await validateTarget(target, true, true);
416
+ if (current.terminal_id !== pane.terminal_id)
417
+ throw new BridgeError(409, "This agent pane changed. Reopen the chat.");
418
+ modelSwitcher.assertAvailable(target);
419
+ settingsSwitcher.assertAvailable(target);
420
+ sideQuestions.assertAvailable(target);
421
+ refuseWorkingSlash(current, text, target.source);
422
+ busy = String(current.agent_status) === "working";
423
+ });
334
424
  // Only Claude confirms plain prompts through its hook, and a slash
335
425
  // command opens a menu that a second Enter would answer.
336
426
  if (outcome === "pending" && target.source === "claude" && !text.trim().startsWith("/")) {
@@ -346,8 +436,11 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
346
436
  // along so a Codex /permissions walk can find its confirmation.
347
437
  if (/^\/[a-z][a-z0-9_-]*$/i.test(text.trim()))
348
438
  agentHooks.menuOpened(target, text.trim());
439
+ const deliveryId = deliveryIdSchema.parse(data.deliveryId);
349
440
  if (outcome === "delivered") {
350
441
  result = { ok: true, delivered: true };
442
+ if (deliveryId)
443
+ agentHooks.trackDelivery(deliveryId, target, text, "delivered");
351
444
  }
352
445
  else if (outcome === "unsubmitted") {
353
446
  result = { ok: true, deliveryUncertain: true, unsubmitted: true };
@@ -355,22 +448,44 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
355
448
  else {
356
449
  // The agent has not submitted it yet (a busy agent queues typed
357
450
  // input). Recheck fresh identity and never retry; a late
358
- // submission to another conversation is still refused above.
451
+ // submission to another conversation is still refused above. A bare
452
+ // ok acknowledges transport only, even if this is still the same
453
+ // conversation. Callers needing a submitted turn require delivered.
359
454
  let confirmed = false;
360
455
  try {
361
456
  const current = findPane(await snapshot(target.server), target);
362
457
  confirmed = !!current && current.terminal_id === pane.terminal_id && await paneIdentity(target.server, current, true) === target.session;
363
458
  }
364
459
  catch { /* No reliable post-delivery identity. */ }
365
- result = { ok: true, ...(!confirmed ? { deliveryUncertain: true } : {}) };
460
+ // Still this conversation, in the same terminal: the agent holds the
461
+ // message (a busy turn queues it) and its hook has not submitted it
462
+ // yet. Queued, not delivered; `/v1/prompt/status` says when it lands.
463
+ if (confirmed && deliveryId)
464
+ agentHooks.trackDelivery(deliveryId, target, text, "queued");
465
+ result = { ok: true, ...(!confirmed ? { deliveryUncertain: true } : { queued: true }) };
366
466
  }
367
467
  }
468
+ else if (url.pathname === "/v1/prompt/status") {
469
+ // Asked by the phone's own delivery id, so no text is matched again.
470
+ const id = deliveryIdSchema.parse(data.deliveryId);
471
+ if (!id)
472
+ throw new BridgeError(400, "Name the message by its deliveryId.");
473
+ result = { ok: true, state: agentHooks.deliveryState(id, target) };
474
+ }
368
475
  else if (url.pathname === "/v1/side-question/dismiss") {
369
476
  result = sideQuestions.dismiss(target, z.string().uuid().parse(data.id));
370
477
  }
371
478
  else if (url.pathname === "/v1/model") {
372
479
  result = await modelSwitcher.switch(target, data);
373
480
  }
481
+ else if (url.pathname === "/v1/settings") {
482
+ result = await settingsSwitcher.switch(target, data);
483
+ }
484
+ else if (url.pathname === "/v1/keys" && await agentHooks.servedKeys(target, z.array(z.enum(ANSWER_KEYS)).min(1).max(4).parse(data.keys), String(pane.agent_status))) {
485
+ // A served OpenCode pane: Esc aborts its turn or declines its question,
486
+ // a digit answers its question, over its own API.
487
+ result = { ok: true };
488
+ }
374
489
  else if (url.pathname === "/v1/keys") {
375
490
  const keys = z.array(z.enum(ANSWER_KEYS)).min(1).max(4).parse(data.keys);
376
491
  const status = String(pane.agent_status), menu = agentHooks.menuOpen(target);
@@ -386,8 +501,15 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
386
501
  if (!cancelled && !holding && (keys.every(key => key === "Escape") ? !["working", "blocked", "waiting", "unknown"].includes(status)
387
502
  : !["blocked", "waiting", "unknown"].includes(status)))
388
503
  throw new BridgeError(409, keys.every(key => key === "Escape") ? "This agent is no longer working." : "This agent is not waiting for an answer.");
504
+ // Esc on a working Codex pane the Hook runs on its own app-server:
505
+ // decline the thread's parked requests, then interrupt the turn.
506
+ const owned = !cancelled && !holding && keys.every(key => key === "Escape") ? codexServers.forTarget(target) : undefined;
389
507
  if (cancelled) {
390
508
  result = { ok: true };
509
+ }
510
+ else if (owned && await codexServers.interrupt(owned).catch(() => false)) {
511
+ agentHooks.clearTerminalPrompt(target);
512
+ result = { ok: true, interrupted: true };
391
513
  // An older phone answers a released AskUserQuestion one question at
392
514
  // a time with its digits; the Hook walks that question in the pane
393
515
  // and submits the set after the last.
@@ -464,7 +586,7 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
464
586
  const allowed = paths.length ? await agentHooks.changes.recordedPaths(`${target.source}:${target.session}`) : [];
465
587
  if (paths.length) {
466
588
  try {
467
- allowed.push(...await conversationNamedPaths(await transcriptPath(target.source, target.session), target.source, cwd, abort.signal));
589
+ allowed.push(...await conversationNamedPaths(await targetTranscriptPath(target), target.source, cwd, abort.signal));
468
590
  }
469
591
  catch {
470
592
  abort.signal.throwIfAborted(); /* Missing transcripts grant no extra paths; recorded scope still works. */
@@ -507,11 +629,14 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
507
629
  else if (url.pathname === "/v1/approvals/answer") {
508
630
  const actionId = target.source === "opencode"
509
631
  ? z.string().regex(/^[A-Za-z0-9_]{1,200}$/).parse(data.actionId)
510
- : z.string().uuid().parse(data.actionId);
632
+ : z.union([z.string().uuid(), z.string().regex(/^dialog-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)]).parse(data.actionId);
511
633
  await agentHooks.answer(target, actionId, data.decision, data.updatedInput);
512
634
  result = { ok: true };
513
635
  }
514
636
  else if (url.pathname === "/v1/questions/answer") {
637
+ // Only a Codex answer can carry the phone's uploads (codex-questions).
638
+ if (target.source !== "codex" && Array.isArray(data.attachments) && data.attachments.length)
639
+ throw new BridgeError(400, "This question takes no attachments.");
515
640
  if (target.source === "claude") {
516
641
  // Claude's AskUserQuestion, answered in its terminal dialog: the
517
642
  // phone names the questions it shows, and the Hook answers only a
@@ -519,6 +644,11 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
519
644
  const { questions, answers } = claudeQuestionAnswer(data);
520
645
  await agentHooks.answerClaudeQuestions(target, questions, answers);
521
646
  }
647
+ else if (target.source === "opencode") {
648
+ // A served OpenCode pane's question, answered over its own API.
649
+ const { questions, answers } = claudeQuestionAnswer(data);
650
+ await agentHooks.answerServedQuestion(target, questions, answers);
651
+ }
522
652
  else
523
653
  await codexQuestions.answer(target, data);
524
654
  result = { ok: true };
@@ -12,8 +12,10 @@ import type { CodexQuestions } from "./questions.js";
12
12
  import type { TabActivityStore } from "./tab-activity.js";
13
13
  import type { ModelCatalog } from "./models.js";
14
14
  import type { ModelSwitcher } from "./model-switch.js";
15
+ import type { SettingsSwitcher } from "./settings-switch.js";
15
16
  import type { SideQuestions } from "./side-questions.js";
16
- import type { AccountUsageReader } from "./usage.js";
17
+ import { type AccountUsageReader } from "./usage.js";
18
+ import type { ResourceMonitor } from "./resources.js";
17
19
  import type { Scheduler } from "./schedules.js";
18
20
  import type { TranscriptStreams } from "./server-stream.js";
19
21
  /** The Hook's HTTP API over its Unix socket: module gating, the GET routes,
@@ -54,8 +56,10 @@ export interface RouteContext {
54
56
  contextUsage: WorkspaceContextUsage;
55
57
  modelCatalog: ModelCatalog;
56
58
  modelSwitcher: ModelSwitcher;
59
+ settingsSwitcher: SettingsSwitcher;
57
60
  sideQuestions: SideQuestions;
58
61
  accountUsage: AccountUsageReader;
62
+ resources: ResourceMonitor;
59
63
  codexQuestions: CodexQuestions;
60
64
  launches: LaunchLimiter;
61
65
  locatedDirectories: Set<string>;
@@ -74,6 +78,7 @@ export declare const capabilities: {
74
78
  terminal: string;
75
79
  shell: string;
76
80
  herdr: boolean;
81
+ sessionRename: boolean;
77
82
  diff: boolean;
78
83
  webServers: boolean;
79
84
  webPreview: string;
@@ -87,15 +92,20 @@ export declare const capabilities: {
87
92
  subagents: boolean;
88
93
  sideQuestions: boolean;
89
94
  dispatch: boolean;
95
+ conductorSets: boolean;
90
96
  approvalPush: string;
91
97
  simulators: boolean;
92
98
  code: boolean;
93
99
  overviewStream: boolean;
94
100
  speech: boolean;
95
101
  speechTimestamps: boolean;
102
+ speechVoices: boolean;
103
+ speechFormats: ("mp3_44100_192" | "pcm_24000" | "pcm_44100")[];
96
104
  transcribe: boolean;
97
105
  memoryStore: boolean;
98
106
  promptOnce: boolean;
107
+ promptStatus: boolean;
108
+ resources: boolean;
99
109
  };
100
110
  export declare function capabilitiesForModules(snapshot: ModuleSnapshot): Record<string, unknown>;
101
111
  export declare function requireRoute(snapshot: ModuleSnapshot, method: string, route: string): void;