@kabmo-labs/kabmo 0.43.0 → 0.43.1

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 (163) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +609 -600
  3. package/dist/client/static/js/{CsvGrid-3fr85032.js → CsvGrid-g67pk2zy.js} +1 -1
  4. package/dist/client/static/js/{DocxView-pqbp2fpd.js → DocxView-pyh6p2kb.js} +1 -1
  5. package/dist/client/static/js/{DrawioView-m0vecq1m.js → DrawioView-g48r6y2m.js} +1 -1
  6. package/dist/client/static/js/{ImageView-rbejbjwg.js → ImageView-rnzf5tve.js} +1 -1
  7. package/dist/client/static/js/{LayoutWrapper-mxfsqh57.js → LayoutWrapper-rekrgth6.js} +1 -1
  8. package/dist/client/static/js/{Modal-vnwg4xn3.js → Modal-edw446r8.js} +1 -1
  9. package/dist/client/static/js/{PdfView-wmg0vk2p.js → PdfView-6z3cgj37.js} +1 -1
  10. package/dist/client/static/js/{SessionsView-90z2t4qe.js → SessionsView-e84tjbcr.js} +1 -1
  11. package/dist/client/static/js/{SheetView-rg5gkcd7.js → SheetView-64076z1j.js} +1 -1
  12. package/dist/client/static/js/{SvgPreview-wpb7b0ez.js → SvgPreview-dmpgavgd.js} +1 -1
  13. package/dist/client/static/js/{abnfDiagram-O67JEVCF-4pxqt66j.js → abnfDiagram-O67JEVCF-nfz5z1vw.js} +1 -1
  14. package/dist/client/static/js/{architectureDiagram-NJMV4G6O-kwt1va5y.js → architectureDiagram-NJMV4G6O-jra2jyzw.js} +1 -1
  15. package/dist/client/static/js/{blockDiagram-BEXU5L5S-hbj5v7n7.js → blockDiagram-BEXU5L5S-3szktxam.js} +1 -1
  16. package/dist/client/static/js/{c4Diagram-YGBWAQC7-epfzh8dw.js → c4Diagram-YGBWAQC7-xe9vbppt.js} +1 -1
  17. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-kbks4qgz.js → classDiagram-v2-NBCMYWYE-egzhj1xn.js} +1 -1
  18. package/dist/client/static/js/{cose-bilkent-JH36ORCC-dvdmckrf.js → cose-bilkent-JH36ORCC-dfrk1wnr.js} +1 -1
  19. package/dist/client/static/js/{cynefinDiagram-VND7K2PF-r084stj5.js → cynefinDiagram-VND7K2PF-xefpcmpg.js} +1 -1
  20. package/dist/client/static/js/{dagre-6A5THRUB-64qc51n1.js → dagre-6A5THRUB-vtzjnrt9.js} +1 -1
  21. package/dist/client/static/js/{diagram-22UHCM2B-70qtb1rm.js → diagram-22UHCM2B-4vvn790v.js} +1 -1
  22. package/dist/client/static/js/{diagram-3UASUU5V-dgkvnsme.js → diagram-3UASUU5V-tmht3bew.js} +1 -1
  23. package/dist/client/static/js/{diagram-ATOU4E4O-rnpsp26v.js → diagram-ATOU4E4O-p5wa5ztx.js} +1 -1
  24. package/dist/client/static/js/{diagram-CDSNMT55-26hthh60.js → diagram-CDSNMT55-8myesjfc.js} +1 -1
  25. package/dist/client/static/js/{diagram-MLGK6HIB-nc1s85r5.js → diagram-MLGK6HIB-9t3x2d5f.js} +1 -1
  26. package/dist/client/static/js/{diagram-MPIPVDR6-e4dckqhv.js → diagram-MPIPVDR6-8ahgnmhy.js} +1 -1
  27. package/dist/client/static/js/{dockerfile-rxtyyhr1.js → dockerfile-x8aa0543.js} +1 -1
  28. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-3w9h8qk7.js → ebnfDiagram-ZINNZB2B-5semw111.js} +1 -1
  29. package/dist/client/static/js/{elk-276RUBZZ-httpkyb1.js → elk-276RUBZZ-jmhs58ww.js} +1 -1
  30. package/dist/client/static/js/{erDiagram-OPXOYQCR-3qhvf7se.js → erDiagram-OPXOYQCR-31wvbpdr.js} +1 -1
  31. package/dist/client/static/js/flowDiagram-KWPJA3E3-36ygrbvm.js +1 -0
  32. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-t53m50e5.js → ganttDiagram-FUAMR5RP-c2dycjrf.js} +1 -1
  33. package/dist/client/static/js/{gitGraphDiagram-X574FWY7-b5wn9eht.js → gitGraphDiagram-X574FWY7-y4k4pdd8.js} +1 -1
  34. package/dist/client/static/js/{index-kc3c2gzb.js → index-0q2qfcjn.js} +1 -1
  35. package/dist/client/static/js/{index-7zc1z9z9.js → index-2b46dzw8.js} +1 -1
  36. package/dist/client/static/js/{index-dg3b0mfk.js → index-2cbnjc32.js} +1 -1
  37. package/dist/client/static/js/{index-q1gwgmxt.js → index-3588r3wg.js} +1 -1
  38. package/dist/client/static/js/{index-8y51kgan.js → index-48gh56ka.js} +1 -1
  39. package/dist/client/static/js/{index-2q23dwrs.js → index-48pb18zj.js} +1 -1
  40. package/dist/client/static/js/{index-ksph3kpr.js → index-4rv388z7.js} +1 -1
  41. package/dist/client/static/js/{index-qzw4jnnv.js → index-52xmdeh2.js} +1 -1
  42. package/dist/client/static/js/{index-kccp6tgd.js → index-6fpd55cq.js} +1 -1
  43. package/dist/client/static/js/{index-d8r84zjd.js → index-8kqepehd.js} +2 -2
  44. package/dist/client/static/js/{index-fgyenbv8.js → index-aar68x31.js} +1 -1
  45. package/dist/client/static/js/{index-r11bbnek.js → index-cgzw43bc.js} +2 -2
  46. package/dist/client/static/js/{index-g3a9j9hf.js → index-cje5gg45.js} +1 -1
  47. package/dist/client/static/js/{index-rv4qs3wm.js → index-cjhvtzdd.js} +1 -1
  48. package/dist/client/static/js/{index-wmv3crye.js → index-dkwhs38j.js} +1 -1
  49. package/dist/client/static/js/{index-vmgzhp41.js → index-efra065v.js} +1 -1
  50. package/dist/client/static/js/{index-zqthmaxq.js → index-f77c3ag0.js} +147 -146
  51. package/dist/client/static/js/{index-7z9tz4ze.js → index-f7djda1g.js} +1 -1
  52. package/dist/client/static/js/{index-egd0vfey.js → index-fbcg8y95.js} +1 -1
  53. package/dist/client/static/js/{index-1dwdgp27.js → index-g3shdymf.js} +1 -1
  54. package/dist/client/static/js/{index-axszsg7a.js → index-h5n1btqy.js} +1 -1
  55. package/dist/client/static/js/{index-tzbzehqd.js → index-kc5znr75.js} +2 -2
  56. package/dist/client/static/js/{index-tnv3dryk.js → index-m1n4v0z7.js} +1 -1
  57. package/dist/client/static/js/{index-g4rsmakg.js → index-m94f4ngb.js} +1 -1
  58. package/dist/client/static/js/{index-4banz7gr.js → index-nt7nhchn.js} +1 -1
  59. package/dist/client/static/js/{index-f4fqvct6.js → index-pt8440xh.js} +1 -1
  60. package/dist/client/static/js/{index-jvs2fvqz.js → index-rn8w29pv.js} +1 -1
  61. package/dist/client/static/js/{index-kmzd0adv.js → index-s00j9042.js} +1 -1
  62. package/dist/client/static/js/{index-dkqgmacr.js → index-s7rfbydk.js} +1 -1
  63. package/dist/client/static/js/{index-j60gtvw8.js → index-sg6sz3g8.js} +1 -1
  64. package/dist/client/static/js/{index-k9ws464d.js → index-vyw4tbn8.js} +1 -1
  65. package/dist/client/static/js/{index-enb6chty.js → index-w5rw8f7w.js} +1 -1
  66. package/dist/client/static/js/{index-gwqb7m8g.js → index-x6v37h3j.js} +1 -1
  67. package/dist/client/static/js/{infoDiagram-VRGFBTTK-qv7438m3.js → infoDiagram-VRGFBTTK-z3pqx7w8.js} +1 -1
  68. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-p1w6zg5y.js → ishikawaDiagram-OU5B5YK6-f5v6z8yr.js} +1 -1
  69. package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-ywk6xqxr.js → journeyDiagram-ZHPQQLJL-js1yxatk.js} +1 -1
  70. package/dist/client/static/js/{kanban-definition-PNTS6WVX-gtrmhggc.js → kanban-definition-PNTS6WVX-m0a6069c.js} +1 -1
  71. package/dist/client/static/js/{mermaid.core-5s24b4hh.js → mermaid.core-6xvbnm63.js} +2 -2
  72. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-3wx7abqn.js → mindmap-definition-NLK3R4M7-a9f9yzc0.js} +1 -1
  73. package/dist/client/static/js/one-dark-pro-hteqzfb0.js +1 -0
  74. package/dist/client/static/js/one-light-dapnh0rs.js +1 -0
  75. package/dist/client/static/js/{pegDiagram-GJSIUBJH-yvyqnjya.js → pegDiagram-GJSIUBJH-4v4pf1h1.js} +1 -1
  76. package/dist/client/static/js/{pieDiagram-5QR66LMP-26x6pj38.js → pieDiagram-5QR66LMP-a54yrmfm.js} +1 -1
  77. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-qhe8h0j9.js → quadrantDiagram-O4NWA36T-1twhvnp2.js} +1 -1
  78. package/dist/client/static/js/{railroadDiagram-XR7U4H2S-dwy3k2jx.js → railroadDiagram-XR7U4H2S-83tqfdcy.js} +1 -1
  79. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-hcmgfesg.js → requirementDiagram-PLB6GJNP-73e3pzw6.js} +1 -1
  80. package/dist/client/static/js/{rust-bmb4ee5w.js → rust-jds4e4r7.js} +1 -1
  81. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-s6d3k4zs.js → sankeyDiagram-IPEJSGJF-1bzwj6sb.js} +1 -1
  82. package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-0fcmzgdy.js → sequenceDiagram-PO4LG4MO-yh3h988k.js} +1 -1
  83. package/dist/client/static/js/{sizeCapture-INFHLROL-t8fcm7rq.js → sizeCapture-INFHLROL-1n121yp6.js} +1 -1
  84. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-jr80hfeg.js → stateDiagram-v2-GCMORJYK-0tdrzn06.js} +1 -1
  85. package/dist/client/static/js/{swimlanes-2SLR337P-x1ay6w39.js → swimlanes-2SLR337P-77n1ttdw.js} +1 -1
  86. package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-xj123xrp.js → swimlanesDiagram-TC7HE7FX-akjqm31r.js} +1 -1
  87. package/dist/client/static/js/{timeline-definition-EJHVYXUP-qz0g6msb.js → timeline-definition-EJHVYXUP-b6r0k3e8.js} +1 -1
  88. package/dist/client/static/js/{usecaseDiagram-POWQR4AR-sxzrv8ht.js → usecaseDiagram-POWQR4AR-efq58m3m.js} +1 -1
  89. package/dist/client/static/js/{vennDiagram-UO4OBE2U-qsqgnjcv.js → vennDiagram-UO4OBE2U-ad4gvd5r.js} +1 -1
  90. package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-rvwxn458.js → wardleyDiagram-VNRHLVJA-v89tys2p.js} +1 -1
  91. package/dist/client/static/js/{xychartDiagram-PMCCYNJV-nb4w7rcg.js → xychartDiagram-PMCCYNJV-xtgzmknw.js} +1 -1
  92. package/package.json +1 -1
  93. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +21 -9
  94. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/TaskResult.tsx +18 -4
  95. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/task-rows.ts +47 -0
  96. package/src/client/hooks/chat/omp/index.ts +2 -6
  97. package/src/server/lib/changes/capture-client-write.server.ts +45 -0
  98. package/src/server/lib/changes/capture.server.ts +20 -5
  99. package/src/server/lib/db/schema.ts +3 -0
  100. package/src/server/lib/harness/acp/auth.test.ts +69 -0
  101. package/src/server/lib/harness/acp/auth.ts +71 -0
  102. package/src/server/lib/harness/acp/background-replay.test.ts +139 -0
  103. package/src/server/lib/harness/acp/background-replay.ts +87 -0
  104. package/src/server/lib/harness/acp/background-work.ts +50 -33
  105. package/src/server/lib/harness/acp/calls.test.ts +68 -0
  106. package/src/server/lib/harness/acp/calls.ts +13 -0
  107. package/src/server/lib/harness/acp/client-capabilities.ts +5 -2
  108. package/src/server/lib/harness/acp/client-fs.test.ts +13 -0
  109. package/src/server/lib/harness/acp/client-fs.ts +16 -2
  110. package/src/server/lib/harness/acp/client.ts +22 -23
  111. package/src/server/lib/harness/acp/commands.test.ts +19 -0
  112. package/src/server/lib/harness/acp/commands.ts +26 -8
  113. package/src/server/lib/harness/acp/frames.ts +16 -1
  114. package/src/server/lib/harness/acp/grants.server.ts +75 -0
  115. package/src/server/lib/harness/acp/grants.test.ts +65 -0
  116. package/src/server/lib/harness/acp/grants.ts +79 -0
  117. package/src/server/lib/harness/acp/permissions.test.ts +9 -0
  118. package/src/server/lib/harness/acp/permissions.ts +56 -36
  119. package/src/server/lib/harness/acp/prompt-files.test.ts +69 -0
  120. package/src/server/lib/harness/acp/prompt-files.ts +58 -0
  121. package/src/server/lib/harness/acp/prompt.ts +50 -11
  122. package/src/server/lib/harness/acp/protocol.ts +20 -1
  123. package/src/server/lib/harness/acp/session-approvals.ts +45 -0
  124. package/src/server/lib/harness/acp/session-config-view.ts +81 -0
  125. package/src/server/lib/harness/acp/session-config.ts +48 -9
  126. package/src/server/lib/harness/acp/session-handshake.test.ts +71 -2
  127. package/src/server/lib/harness/acp/session-handshake.ts +128 -53
  128. package/src/server/lib/harness/acp/session-intake.test.ts +93 -0
  129. package/src/server/lib/harness/acp/session-intake.ts +75 -0
  130. package/src/server/lib/harness/acp/session-lifecycle.ts +50 -0
  131. package/src/server/lib/harness/acp/session-lost.test.ts +44 -0
  132. package/src/server/lib/harness/acp/session-lost.ts +34 -0
  133. package/src/server/lib/harness/acp/session-notify.ts +47 -0
  134. package/src/server/lib/harness/acp/session-observers.test.ts +4 -4
  135. package/src/server/lib/harness/acp/session-permissions.test.ts +64 -0
  136. package/src/server/lib/harness/acp/session-permissions.ts +9 -4
  137. package/src/server/lib/harness/acp/session-requests.ts +6 -0
  138. package/src/server/lib/harness/acp/session-roots.server.ts +47 -0
  139. package/src/server/lib/harness/acp/session-roots.test.ts +31 -0
  140. package/src/server/lib/harness/acp/session-start.ts +7 -0
  141. package/src/server/lib/harness/acp/session-turns.ts +11 -0
  142. package/src/server/lib/harness/acp/session-wiring.ts +100 -0
  143. package/src/server/lib/harness/acp/session.test-util.ts +34 -2
  144. package/src/server/lib/harness/acp/session.test.ts +10 -10
  145. package/src/server/lib/harness/acp/session.ts +146 -144
  146. package/src/server/lib/harness/acp/tool-calls.ts +27 -15
  147. package/src/server/lib/harness/acp/tool-identity.test.ts +136 -0
  148. package/src/server/lib/harness/acp/tool-identity.ts +121 -0
  149. package/src/server/lib/harness/acp/turn-cancel.test.ts +79 -0
  150. package/src/server/lib/harness/acp/turn-cancel.ts +61 -0
  151. package/src/server/lib/harness/acp/turn-dispatch.test.ts +103 -0
  152. package/src/server/lib/harness/acp/turn-dispatch.ts +61 -0
  153. package/src/server/lib/harness/acp/turn-queue.ts +43 -0
  154. package/src/server/lib/harness/acp/turn-verdict.ts +102 -0
  155. package/src/server/lib/harness/acp/turn.ts +86 -88
  156. package/src/server/lib/harness/acp/v2.test.ts +9 -0
  157. package/src/server/lib/harness/acp/v2.ts +13 -0
  158. package/src/server/lib/harness/acp/verbs.ts +35 -4
  159. package/src/server/lib/omp/session/delete.server.ts +3 -0
  160. package/src/shared/types/omp/agent.ts +14 -5
  161. package/dist/client/static/js/flowDiagram-KWPJA3E3-1jat076e.js +0 -1
  162. package/dist/client/static/js/one-dark-pro-3vya9z02.js +0 -1
  163. package/dist/client/static/js/one-light-1yrwn9my.js +0 -1
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The inputs an ACP chat holds while a turn is running.
8
+ *
9
+ * ACP has no mid-turn channel of its own: `_session/steering` is omp's
10
+ * extension, and every other agent refuses it. Without a queue here, a
11
+ * follow-up sent while the agent was working had nowhere to go — it was either
12
+ * dropped or answered with a refusal the operator could not act on.
13
+ *
14
+ * One input is dispatched as each turn closes, in arrival order, and the queue is
15
+ * drained by `AcpTurns` itself so a queued input can never outlive the turn it
16
+ * was written against.
17
+ */
18
+
19
+ export interface QueuedInput {
20
+ message: string;
21
+ images: unknown;
22
+ }
23
+
24
+ export class TurnQueue {
25
+ readonly #items: QueuedInput[] = [];
26
+
27
+ push(input: QueuedInput): void {
28
+ this.#items.push(input);
29
+ }
30
+
31
+ /** Take the oldest input, or undefined when none is waiting. */
32
+ shift(): QueuedInput | undefined {
33
+ return this.#items.shift();
34
+ }
35
+
36
+ get size(): number {
37
+ return this.#items.length;
38
+ }
39
+
40
+ clear(): void {
41
+ this.#items.length = 0;
42
+ }
43
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The two verdicts a CLOSED assistant message supplies when a turn ends, split
8
+ * out of `turn.ts` so that file stays inside the size ceiling.
9
+ *
10
+ * Both are about what the agent actually sent, not about the envelope's
11
+ * `stopReason`: an agent records the provider's failure on the message, and a
12
+ * message whose blocks render nothing is the same operator-visible failure as no
13
+ * message at all.
14
+ */
15
+
16
+ import { deriveTurnError } from '@/shared/lib/omp/session/turn-error';
17
+
18
+ /**
19
+ * The reason the CLOSED message names, when it named one.
20
+ *
21
+ * The same rule as omp's: an agent records `stopReason` / `errorMessage` flat on
22
+ * the assistant message, and reading only the envelope's stop reason threw the
23
+ * provider's own words away — a coordinator was told "the agent ended the turn
24
+ * with an error" over a transcript that said which.
25
+ */
26
+ export function closedFailure(message: unknown): string | null {
27
+ if (!message || typeof message !== 'object' || Array.isArray(message)) return null;
28
+ const error = deriveTurnError(message as Record<string, unknown>);
29
+ return error?.message?.trim() || null;
30
+ }
31
+
32
+ /** Does the closed message carry anything the timeline draws? A whitespace-only
33
+ * chunk (or one that carried only an empty text block) opens a message row
34
+ * that renders nothing, which is the same operator-visible failure as no frame
35
+ * at all. Thinking and tool calls are content: they render as their own
36
+ * blocks. */
37
+ export function hasRenderableAnswer(message: unknown): boolean {
38
+ if (!message || typeof message !== 'object' || !('content' in message)) return false;
39
+ const content = message.content;
40
+ if (!Array.isArray(content)) return false;
41
+ return content.some((block) => {
42
+ if (!block || typeof block !== 'object') return false;
43
+ if ('text' in block && typeof block.text === 'string') return block.text.trim().length > 0;
44
+ if ('thinking' in block && typeof block.thinking === 'string') return block.thinking.trim().length > 0;
45
+ return 'type' in block && block.type === 'toolCall';
46
+ });
47
+ }
48
+
49
+ /** What one finished turn reports as its outcome. */
50
+ export interface TurnVerdict {
51
+ failed: boolean;
52
+ cancelled: boolean;
53
+ reason: string | null;
54
+ }
55
+
56
+ /** The verdict for a closed turn.
57
+ *
58
+ * A prompt that ends with no message and no tool call is a SILENT failure on
59
+ * most agents (measured on pi-acp: it answers `session/prompt` with `{}` and
60
+ * sends no frames when its provider call fails). Whitespace-only chunks are the
61
+ * same failure with a frame attached. Slash commands are exempt — an extension
62
+ * command is answered locally and correctly produces nothing — and a user's Stop
63
+ * is not a failure either.
64
+ *
65
+ * `stopReason: 'error'` is a failure even when the agent DID send a partial
66
+ * message: a v1 agent answers `{stopReason:'error'}` with whatever it streamed,
67
+ * and reading only "did it answer" told a coordinator its failed worker had
68
+ * finished. v2 cannot infer failure from an idle without a stop reason, so the
69
+ * silent-turn rule is gated to `completion === 'response'`. */
70
+ export function turnVerdict(args: {
71
+ closed: unknown;
72
+ abandoned: number;
73
+ result: { stopReason?: string } | undefined;
74
+ reported: boolean;
75
+ stranded: boolean;
76
+ /** The prompt text, to exempt slash commands. */
77
+ promptText: string;
78
+ completion: 'response' | 'state';
79
+ strandedReason: string;
80
+ /** A reason the caller already knows and reported. */
81
+ failure?: string;
82
+ }): TurnVerdict {
83
+ const answered = hasRenderableAnswer(args.closed) || args.abandoned > 0;
84
+ const cancelled = args.result?.stopReason === 'cancelled';
85
+ const slash = args.promptText.trimStart().startsWith('/');
86
+ const failed = !cancelled && !slash
87
+ && (args.stranded || args.reported || args.result?.stopReason === 'error' || (args.completion === 'response' && !answered));
88
+ const reason = failed
89
+ ? (args.failure ?? (args.stranded
90
+ ? args.strandedReason
91
+ : closedFailure(args.closed) ?? (args.result?.stopReason === 'error'
92
+ ? 'The agent ended the turn with an error'
93
+ : 'The agent ended the turn without sending an answer')))
94
+ : null;
95
+ return { failed, cancelled, reason };
96
+ }
97
+
98
+ /** A slash command is answered locally and correctly produces nothing, so the
99
+ * silent-turn verdict never applies to one. */
100
+ export function reasonSuppressed(promptText: string): boolean {
101
+ return promptText.trimStart().startsWith('/');
102
+ }
@@ -6,9 +6,7 @@
6
6
  /**
7
7
  * The life of an ACP turn: one prompt, its frames, and how it ends.
8
8
  *
9
- * Split out of `AcpSession` because the rules here are the ones that took a bug
10
- * each to learn, and a session that also owns spawning, config selectors and
11
- * client requests buried them:
9
+ * Three rules, each a bug that had to be learned:
12
10
  *
13
11
  * - **a prompt is CHAINED, never raced.** ACP has no queue: a second
14
12
  * `session/prompt` while one is open CANCELS the first (measured, twice).
@@ -22,7 +20,10 @@ import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
22
20
  import { AcpRequestError } from '@/server/lib/harness/acp/calls';
23
21
  import { turnEndFrame } from '@/server/lib/harness/acp/frames';
24
22
  import { TurnSilence } from '@/server/lib/harness/acp/turn-silence';
25
- import { deriveTurnError } from '@/shared/lib/omp/session/turn-error';
23
+ import { CancelSettle } from '@/server/lib/harness/acp/turn-cancel';
24
+ import { TurnQueue } from '@/server/lib/harness/acp/turn-queue';
25
+ import { promptWithBusyRetry, SESSION_BUSY_WAIT_MS } from '@/server/lib/harness/acp/turn-dispatch';
26
+ import { reasonSuppressed, turnVerdict } from '@/server/lib/harness/acp/turn-verdict';
26
27
 
27
28
  const STRANDED_REASON = 'The agent stopped reporting progress; the turn was closed after a long silence.';
28
29
 
@@ -83,9 +84,16 @@ export class AcpTurns {
83
84
  private awaitingCancellation = false;
84
85
  /** The silence ceiling for the open turn — see `turn-silence.ts`. */
85
86
  readonly #silence: TurnSilence;
87
+ /** Settles the prompt after a cancel the agent never answered. */
88
+ readonly #cancelSettle: CancelSettle;
89
+ /** Inputs held for an agent with no mid-turn channel. */
90
+ readonly #queue = new TurnQueue();
91
+ readonly #busyWaitMs: number;
86
92
 
87
- constructor(private readonly seams: AcpTurnSeams, options: { silenceMs?: number } = {}) {
93
+ constructor(private readonly seams: AcpTurnSeams, options: { silenceMs?: number; busyWaitMs?: number } = {}) {
88
94
  this.#silence = new TurnSilence(() => this.strand(), options.silenceMs);
95
+ this.#cancelSettle = new CancelSettle(() => this.seams.abandonPrompt());
96
+ this.#busyWaitMs = options.busyWaitMs ?? SESSION_BUSY_WAIT_MS;
89
97
  }
90
98
 
91
99
  /** Any frame from the agent defers the silence ceiling. */
@@ -111,6 +119,9 @@ export class AcpTurns {
111
119
  }
112
120
  this.seq += 1;
113
121
  const turnId = this.seq;
122
+ // A new prompt IS the decision that a cancelled turn is over: free the chain
123
+ // now rather than waiting out the grace window.
124
+ this.#cancelSettle.flush();
114
125
  this.promptText = message;
115
126
  this.awaitingCancellation = false;
116
127
  this.isPromptRunning = true;
@@ -122,9 +133,18 @@ export class AcpTurns {
122
133
  const request = (this.request ?? Promise.resolve())
123
134
  .catch(() => undefined)
124
135
  .then(() => {
136
+ // Stop pressed while this turn queued behind the previous prompt: the
137
+ // flags were cleared, so the prompt must never reach the agent.
138
+ if (!this.isPromptRunning || !this.isStreaming) return undefined;
125
139
  this.open = turnId;
126
140
  this.seams.resetMapper();
127
- return this.seams.prompt(message, images);
141
+ // `-32003 session_busy` is the agent still finishing its previous turn,
142
+ // not a failure: wait for it instead of reporting an error the operator
143
+ // can only work around by waiting.
144
+ return promptWithBusyRetry(() => this.seams.prompt(message, images), {
145
+ waitMs: this.#busyWaitMs,
146
+ isActive: () => this.open === turnId && this.isPromptRunning,
147
+ });
128
148
  });
129
149
  this.request = request;
130
150
  void request
@@ -158,30 +178,60 @@ export class AcpTurns {
158
178
  return { agentInvoked: true };
159
179
  }
160
180
 
161
- /**
162
- * Stop the turn AND close it here.
181
+ /** Stop the turn AND close it here.
163
182
  *
164
- * Nothing guarantees the agent answers the cancel, and a session whose agent
165
- * never does stayed `isStreaming` forever: the spinner cleared, and the NEXT
166
- * prompt was refused with "Agent is already processing". The agent's own
167
- * prompt request is settled locally for the same reason — it is what the next
168
- * turn is chained behind.
169
- */
183
+ * Nothing guarantees the agent answers the cancel, and a session whose agent
184
+ * never does stays `isStreaming` forever — the NEXT prompt is refused as
185
+ * "already processing". The outstanding prompt is settled after a grace
186
+ * window for the same reason: it is what the next turn is chained behind. */
170
187
  cancel(): void {
171
188
  this.awaitingCancellation = true;
189
+ this.#cancelSettle.disarm();
172
190
  if (this.open === null) {
173
- // Nothing dispatched yet, but a turn may be queued behind the previous
174
- // request: clear its flags too, or Stop leaves the session permanently
175
- // "processing".
191
+ // The prompt is still queued behind the previous request (or was never
192
+ // dispatched): clear the flags or Stop leaves the session permanently
193
+ // "processing", and tell the agent anyway — a cancel with nothing to stop
194
+ // is a no-op, while a prompt that slips out afterwards is what hangs the
195
+ // NEXT send.
196
+ if (this.isPromptRunning || this.isStreaming) {
197
+ this.abandonOnStop();
198
+ this.finish({ stopReason: 'cancelled' });
199
+ }
176
200
  this.isPromptRunning = false;
177
201
  this.isStreaming = false;
202
+ this.#silence.stop();
178
203
  return;
179
204
  }
180
205
  this.open = null;
181
206
  this.#silence.stop();
182
207
  this.seams.cancelAgent();
183
- this.seams.abandonPrompt();
184
208
  this.finish({ stopReason: 'cancelled' });
209
+ // A held input is the operator's NEXT intent and must not wait out the
210
+ // grace window; otherwise let the agent end its own turn first.
211
+ if (this.#queue.size > 0) this.seams.abandonPrompt();
212
+ else this.#cancelSettle.arm();
213
+ }
214
+
215
+ /** Hold an input until the running turn ends. */
216
+ queue(message: string, images: unknown): void {
217
+ this.#queue.push({ message, images });
218
+ }
219
+
220
+ /** Take the next held input; the SESSION dispatches it, so counters and the
221
+ * run marker stay on its own path. */
222
+ takeQueued(): { message: string; images: unknown } | undefined {
223
+ return this.#queue.shift();
224
+ }
225
+
226
+ /** The grace window is still open: a Stop that has not been answered yet. */
227
+ pendingCancel(): boolean {
228
+ return this.#cancelSettle.pending();
229
+ }
230
+
231
+ /** The prompt that a Stop must free, dispatched or still queued. */
232
+ private abandonOnStop(): void {
233
+ this.seams.cancelAgent();
234
+ this.seams.abandonPrompt();
185
235
  }
186
236
 
187
237
  /** Is a turn accepting the agent's frames right now? */
@@ -189,23 +239,18 @@ export class AcpTurns {
189
239
  return this.open !== null;
190
240
  }
191
241
 
192
- /**
193
- * v2's turn boundary: an idle `state_update` ends foreground work.
242
+ /** v2's turn boundary: an idle `state_update` ends foreground work.
194
243
  *
195
- * `running`/`requires_action` do not open a turn: a prompt that is still being
196
- * inserted is already open, and agent-initiated work without a prompt is not
197
- * represented as a Kabmo turn yet. Repeats are idempotent because `settle`
198
- * matches the turn id.
199
- */
244
+ * `running`/`requires_action` do not open a turn when a prompt is still being
245
+ * inserted; agent-initiated work with no prompt does. Repeats are idempotent
246
+ * because `settle` matches the turn id. */
200
247
  onStateUpdate(update: Record<string, unknown>): void {
201
248
  if (this.completion !== 'state') return;
202
249
  const state = typeof update.state === 'string' ? update.state : '';
203
250
  if (state !== 'idle') {
204
- // The cancelled run may still report running/requires_action before its
205
- // idle; those are not a new foreground interval.
251
+ // A cancelled run's running/requires_action is not a new interval;
252
+ // foreground work with no prompt (a goal) does open one.
206
253
  if (this.awaitingCancellation) return;
207
- // v2 allows foreground work with no prompt (a goal, a follow-up on a
208
- // background task). Open a turn so its frames are accepted and rendered.
209
254
  if (this.open === null && !this.isPromptRunning && !this.isStreaming) this.beginAgentTurn();
210
255
  return;
211
256
  }
@@ -270,34 +315,18 @@ export class AcpTurns {
270
315
  for (const toolCallId of abandoned) {
271
316
  this.seams.emit({ type: 'tool_execution_end', toolCallId, isError: true, result: { output: 'Cancelled' } });
272
317
  }
273
- // A prompt that ends with no message and no tool call is a SILENT failure on
274
- // most agents (measured on pi-acp: it answers `session/prompt` with `{}` and
275
- // sends no frames at all when its provider call fails). Reporting it beats
276
- // leaving an empty bubble that reads as "the agent had nothing to say".
277
- // Whitespace-only chunks are the same failure with a frame attached: the
278
- // row renders no text, so the operator still sees nothing. Slash commands
279
- // are exempt: an extension command is answered locally and correctly
280
- // produces nothing, and a user's Stop is not a failure either.
281
- const answered = hasRenderableAnswer(closed) || abandoned.length > 0;
282
- const cancelled = result?.stopReason === 'cancelled';
283
- const slash = this.promptText.trimStart().startsWith('/');
284
- // v2 says clients cannot infer failure from an idle without a stop reason;
285
- // the "silent answer is a failure" rule is a v1 agent behaviour (pi-acp).
286
- // `stopReason: 'error'` is a failure even when the agent DID send a partial
287
- // message: a v1 agent answers `{stopReason: 'error'}` with whatever it had
288
- // streamed, and reading only "did it answer" reported that turn as
289
- // completed — so a delegated worker whose provider failed mid-answer told
290
- // its coordinator it had finished.
291
- const failed = !cancelled && !slash
292
- && (stranded || reported || result?.stopReason === 'error' || (this.completion === 'response' && !answered));
293
- const reason = failed
294
- ? failure ?? (stranded
295
- ? STRANDED_REASON
296
- : closedFailure(closed) ?? (result?.stopReason === 'error'
297
- ? 'The agent ended the turn with an error'
298
- : 'The agent ended the turn without sending an answer'))
299
- : null;
300
- if (failed && !reported && !slash) {
318
+ const { failed, cancelled, reason } = turnVerdict({
319
+ closed,
320
+ abandoned: abandoned.length,
321
+ result,
322
+ reported,
323
+ stranded,
324
+ promptText: this.promptText,
325
+ completion: this.completion,
326
+ strandedReason: STRANDED_REASON,
327
+ ...(failure ? { failure } : {}),
328
+ });
329
+ if (failed && !reported && !reasonSuppressed(this.promptText)) {
301
330
  this.seams.emit({
302
331
  type: 'prompt_error',
303
332
  errorMessage: reason ?? 'The agent ended the turn without sending an answer',
@@ -316,34 +345,3 @@ export class AcpTurns {
316
345
  });
317
346
  }
318
347
  }
319
-
320
- /**
321
- * The reason the CLOSED message names, when it named one.
322
- *
323
- * The same rule as omp's: an agent records `stopReason` / `errorMessage` flat on
324
- * the assistant message, and reading only the envelope's stop reason threw the
325
- * provider's own words away — a coordinator was told "the agent ended the turn
326
- * with an error" over a transcript that said which.
327
- */
328
- function closedFailure(message: unknown): string | null {
329
- if (!message || typeof message !== 'object' || Array.isArray(message)) return null;
330
- const error = deriveTurnError(message as Record<string, unknown>);
331
- return error?.message?.trim() || null;
332
- }
333
-
334
- /** Does the closed message carry anything the timeline draws? A whitespace-only
335
- * chunk (or one that carried only an empty text block) opens a message row
336
- * that renders nothing, which is the same operator-visible failure as no frame
337
- * at all. Thinking and tool calls are content: they render as their own
338
- * blocks. */
339
- function hasRenderableAnswer(message: unknown): boolean {
340
- if (!message || typeof message !== 'object' || !('content' in message)) return false;
341
- const content = message.content;
342
- if (!Array.isArray(content)) return false;
343
- return content.some((block) => {
344
- if (!block || typeof block !== 'object') return false;
345
- if ('text' in block && typeof block.text === 'string') return block.text.trim().length > 0;
346
- if ('thinking' in block && typeof block.thinking === 'string') return block.thinking.trim().length > 0;
347
- return 'type' in block && block.type === 'toolCall';
348
- });
349
- }
@@ -68,6 +68,15 @@ describe('normalizeInitializeResult', () => {
68
68
  const v1 = { protocolVersion: 1, agentCapabilities: { loadSession: true } };
69
69
  expect(normalizeInitializeResult(v1)).toBe(v1 as never);
70
70
  });
71
+
72
+ test('a peer that reports 2 but answers in v1 shape is spoken to as v1', () => {
73
+ const init = normalizeInitializeResult({
74
+ protocolVersion: 2,
75
+ agentCapabilities: { loadSession: true, promptCapabilities: { image: true } },
76
+ });
77
+ expect(init.protocolVersion).toBe(1);
78
+ expect(init.agentCapabilities?.loadSession).toBe(true);
79
+ });
71
80
  });
72
81
 
73
82
  describe('normalizeConfigOptions', () => {
@@ -51,6 +51,15 @@ function advertised(value: unknown): boolean {
51
51
  export function normalizeInitializeResult(raw: Record<string, unknown>): AcpInitializeResult {
52
52
  const version = typeof raw.protocolVersion === 'number' ? raw.protocolVersion : 1;
53
53
  if (version !== 2) return raw as unknown as AcpInitializeResult;
54
+ // A peer that REPORTS 2 but answers with v1's keys (`agentCapabilities`, and
55
+ // no `capabilities`) is speaking v1. Reading it as v2 finds no capabilities
56
+ // at all and, worse, sets the turn machine's completion mode to `state` — so
57
+ // the `session/prompt` answer that ends every v1 turn is ignored and the run
58
+ // hangs until the silence ceiling. bb's heuristic is the same: the shape, not
59
+ // the number, decides which generation a result is written in.
60
+ if (asRecord(raw.agentCapabilities) !== undefined && asRecord(raw.capabilities) === undefined) {
61
+ return { ...raw, protocolVersion: 1 } as AcpInitializeResult;
62
+ }
54
63
 
55
64
  const capabilities = asRecord(raw.capabilities) ?? {};
56
65
  const session = asRecord(capabilities.session);
@@ -112,6 +121,10 @@ export function normalizeAuthMethods(value: unknown): AcpInitializeResult['authM
112
121
  name: asString(method?.name) ?? id,
113
122
  ...(asString(method?.description) ? { description: asString(method?.description) } : {}),
114
123
  ...(asString(method?.type) ? { type: asString(method?.type) } : {}),
124
+ ...(Array.isArray(method?.args)
125
+ ? { args: method.args.filter((arg): arg is string => typeof arg === 'string') }
126
+ : {}),
127
+ ...(asRecord(method?.env) ? { env: asRecord(method?.env) as Record<string, string> } : {}),
115
128
  }];
116
129
  });
117
130
  }
@@ -28,14 +28,20 @@ export type AcpNotify = (method: string, params: unknown) => void;
28
28
  /** The negotiated major, so a verb can shape its params and normalize its answer. */
29
29
  export type AcpDialect = 1 | 2;
30
30
 
31
+ /** The extra roots one setup request carries, when the agent advertised them. */
32
+ export interface SessionDirs {
33
+ additionalDirectories?: string[];
34
+ }
35
+
31
36
  export async function newSession(
32
37
  invoke: AcpInvoke,
33
38
  cwd: string,
34
39
  timeoutMs = 120_000,
35
40
  dialect: AcpDialect = 1,
36
41
  mcpServers: AcpMcpServerWire[] = [],
42
+ dirs: SessionDirs = {},
37
43
  ): Promise<AcpSessionNewResult> {
38
- const result = await invoke<Record<string, unknown>>('session/new', { cwd, mcpServers }, timeoutMs);
44
+ const result = await invoke<Record<string, unknown>>('session/new', { cwd, mcpServers, ...dirs }, timeoutMs);
39
45
  return dialect === 2 ? normalizeSessionResult(result) : (result as unknown as AcpSessionNewResult);
40
46
  }
41
47
 
@@ -45,8 +51,9 @@ export async function loadSession(
45
51
  cwd: string,
46
52
  timeoutMs = 120_000,
47
53
  mcpServers: AcpMcpServerWire[] = [],
54
+ dirs: SessionDirs = {},
48
55
  ): Promise<unknown> {
49
- return invoke('session/load', { sessionId, cwd, mcpServers }, timeoutMs);
56
+ return invoke('session/load', { sessionId, cwd, mcpServers, ...dirs }, timeoutMs);
50
57
  }
51
58
 
52
59
  export async function resumeSession(
@@ -60,10 +67,11 @@ export async function resumeSession(
60
67
  * `session/update` frames before the reply. v1 peers replay through
61
68
  * `session/load` instead. */
62
69
  replayFrom?: { type: 'start' },
70
+ dirs: SessionDirs = {},
63
71
  ): Promise<unknown> {
64
72
  const result = await invoke<Record<string, unknown>>(
65
73
  'session/resume',
66
- { sessionId, cwd, mcpServers, ...(dialect === 2 && replayFrom ? { replayFrom } : {}) },
74
+ { sessionId, cwd, mcpServers, ...(dialect === 2 && replayFrom ? { replayFrom } : {}), ...dirs },
67
75
  timeoutMs,
68
76
  );
69
77
  return dialect === 2 ? normalizeSessionResult(result) : result;
@@ -77,10 +85,11 @@ export async function forkSession(
77
85
  target?: Record<string, unknown>,
78
86
  meta?: Record<string, unknown>,
79
87
  mcpServers: AcpMcpServerWire[] = [],
88
+ dirs: SessionDirs = {},
80
89
  ): Promise<AcpSessionNewResult> {
81
90
  return invoke<AcpSessionNewResult>(
82
91
  'session/fork',
83
- { sessionId, cwd, mcpServers, ...(target ? { target } : {}), ...(meta ? { _meta: meta } : {}) },
92
+ { sessionId, cwd, mcpServers, ...dirs, ...(target ? { target } : {}), ...(meta ? { _meta: meta } : {}) },
84
93
  timeoutMs,
85
94
  );
86
95
  }
@@ -187,6 +196,28 @@ export async function setMode(
187
196
  return invoke('session/set_mode', { sessionId, modeId }, timeoutMs);
188
197
  }
189
198
 
199
+ /** Sign this client in with one of the agent's advertised `authMethods`.
200
+ * `_meta.headless` tells the agent no interactive terminal is attached, so a
201
+ * method that needs one refuses instead of parking the spawn. */
202
+ export async function authenticate(
203
+ invoke: AcpInvoke,
204
+ methodId: string,
205
+ timeoutMs = 120_000,
206
+ ): Promise<unknown> {
207
+ return invoke('authenticate', { methodId, _meta: { headless: true } }, timeoutMs);
208
+ }
209
+
210
+ /** `session/set_model`: select a model on an agent that publishes a `models`
211
+ * block instead of a `model` config option (measured on grok). */
212
+ export async function setModel(
213
+ invoke: AcpInvoke,
214
+ sessionId: string,
215
+ modelId: string,
216
+ timeoutMs = 30_000,
217
+ ): Promise<unknown> {
218
+ return invoke('session/set_model', { sessionId, modelId }, timeoutMs);
219
+ }
220
+
190
221
  /** Remove one session from the agent's own history (`sessionCapabilities.delete`). */
191
222
  export async function deleteSession(invoke: AcpInvoke, sessionId: string, timeoutMs = 30_000): Promise<unknown> {
192
223
  return invoke('session/delete', { sessionId }, timeoutMs);
@@ -88,6 +88,9 @@ const SESSION_ROW_DELETES: readonly (readonly [string, string])[] = [
88
88
  // The per-session MCP overrides and the agent-dir overlay they build. The
89
89
  // row is keyed to the id; the directory is removed below.
90
90
  ['session_mcp_state', 'session_id'],
91
+ // An ACP chat's standing "always allow" decisions. A deleted chat that kept
92
+ // them would re-approve the same commands if its id were ever reused.
93
+ ['acp_permission_grants', 'session_id'],
91
94
  ];
92
95
 
93
96
  async function purgeKabmoRows(db: DbClient, sessionId: string): Promise<number> {
@@ -223,11 +223,7 @@ export interface OmpAgentHandle extends OmpAgentState {
223
223
  * `answers` is the grouped ask's reply: one entry per question, in order. */
224
224
  respondToExtensionUi: (
225
225
  request: ExtensionUiDialogRequest,
226
- response:
227
- | { value: string }
228
- | { confirmed: boolean }
229
- | { cancelled: true }
230
- | { answers: { id: string; selectedOptions: string[]; customInput?: string }[] },
226
+ response: ExtensionDialogResponse,
231
227
  ) => Promise<void>;
232
228
  disconnect: () => void;
233
229
  }
@@ -253,6 +249,9 @@ export interface ExtensionUiDialogRequest {
253
249
  method: ExtensionUiDialogMethod;
254
250
  title: string;
255
251
  options?: string[];
252
+ /** Ids parallel to `options`, when the producer has them (ACP permission
253
+ * requests). The dialog answers with the id, never the label. */
254
+ optionIds?: string[];
256
255
  optionDetails?: { description?: string }[];
257
256
  message?: string;
258
257
  placeholder?: string;
@@ -287,3 +286,13 @@ export type IncomingExtensionUiRequest =
287
286
  | { type: 'extension_ui_request'; id: string; method: 'cancel'; targetId: string }
288
287
  | { type: 'extension_ui_request'; id: string; method: 'notify'; message: string; notifyType?: 'info' | 'warning' | 'error' }
289
288
  | { type: 'extension_ui_request'; id: string; method: 'open_url'; url: string; launchUrl?: string; instructions?: string };
289
+
290
+ /** One answer to an extension dialog. `optionId` names the producer's own
291
+ * choice (ACP approvals); `value`/`confirmed`/`answers` are omp's shapes. */
292
+ export type ExtensionDialogResponse =
293
+ | { value: string }
294
+ | { confirmed: boolean }
295
+ | { optionId: string }
296
+ | { cancelled: true }
297
+ /** One `ask` answer per question, in question order (grouped ask mode). */
298
+ | { answers: { id: string; selectedOptions: string[]; customInput?: string }[] };
@@ -1 +0,0 @@
1
- import"./index-r11bbnek.js";import"./index-rv4qs3wm.js";import{Bh}from"./index-f4fqvct6.js";export{Bh as diagram};
@@ -1 +0,0 @@
1
- import{tA}from"./index-zqthmaxq.js";export{tA as default};
@@ -1 +0,0 @@
1
- import{eA}from"./index-zqthmaxq.js";export{eA as default};