@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
@@ -26,6 +26,7 @@ import { AcpTurns } from '@/server/lib/harness/acp/turn';
26
26
  import { SessionListeners } from '@/server/lib/harness/acp/session-listeners';
27
27
  import { RawNotificationSink } from '@/server/lib/harness/acp/raw-listeners';
28
28
  import { PendingPermissions } from '@/server/lib/harness/acp/permissions';
29
+ import { acpConfigView } from '@/server/lib/harness/acp/session-config-view';
29
30
  import { stampMessageModel } from '@/server/lib/harness/acp/session-config';
30
31
  import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
31
32
 
@@ -70,6 +71,16 @@ export interface BackgroundProbeStub {
70
71
  consume: (method: string, params: Record<string, unknown>) => boolean;
71
72
  }
72
73
 
74
+ /** Drain the microtask queue.
75
+ *
76
+ * `session/prompt` is chained: a settle resolves the stub, then the busy-retry
77
+ * wrapper, the turn's `settle`, `finish`, the end seams and the queue each take
78
+ * a hop. Four ticks stopped being enough the moment that wrapper existed; this
79
+ * is a fixed count of hops, not a wall-clock wait. */
80
+ export async function flushTicks(count = 24): Promise<void> {
81
+ for (let i = 0; i < count; i += 1) await Promise.resolve();
82
+ }
83
+
73
84
  /** One in-flight `session/prompt` the stub can settle. */
74
85
  interface PendingPrompt {
75
86
  promise: Promise<unknown>;
@@ -77,7 +88,7 @@ interface PendingPrompt {
77
88
  reject: (reason?: unknown) => void;
78
89
  }
79
90
 
80
- export function mountSession(): MountedSession {
91
+ export function mountSession(options: { busyWaitMs?: number } = {}): MountedSession {
81
92
  const events: AgentEvent[] = [];
82
93
  const dispatched = Promise.withResolvers<void>();
83
94
  const calls: PendingPrompt[] = [];
@@ -114,6 +125,8 @@ export function mountSession(): MountedSession {
114
125
  // A config write; the default reply omits the list, which is the shape a
115
126
  // harness that ignores the protocol's "complete list" rule returns.
116
127
  setConfigOption: async (_sessionId: string, _configId: string, _value: string | boolean) => ({}),
128
+ setMode: async (_sessionId: string, _modeId: string) => ({}),
129
+ setModel: async (_sessionId: string, _modelId: string) => ({}),
117
130
  deleteSession: async (sessionId: string) => {
118
131
  deletes.push(sessionId);
119
132
  return {};
@@ -135,7 +148,7 @@ export function mountSession(): MountedSession {
135
148
  .onTurnEnded(info);
136
149
  turnEndCount += 1;
137
150
  },
138
- });
151
+ }, options);
139
152
  const marks: string[] = [];
140
153
  const markFailures: Array<string | null> = [];
141
154
  const answers: { id: unknown; result: unknown }[] = [];
@@ -158,6 +171,25 @@ export function mountSession(): MountedSession {
158
171
  turns,
159
172
  mapper,
160
173
  permissions: new PendingPermissions(),
174
+ // The config view is a constructor field; a prototype mount has none, and
175
+ // `set_model` writes through it.
176
+ config: acpConfigView(
177
+ {
178
+ get harness() { return 'opencode'; },
179
+ get sessionId() { return 'acp-1'; },
180
+ get configOptions() { return session.configOptions; },
181
+ set configOptions(options) { session.configOptions = options; },
182
+ get runModel() { return session.runModel; },
183
+ set runModel(model) { session.runModel = model; },
184
+ get modes() { return session.modes; },
185
+ set modes(modes) { session.modes = modes; },
186
+ get models() { return session.models; },
187
+ set models(models) { session.models = models; },
188
+ get isStreaming() { return session.isStreaming; },
189
+ emit: (event) => session.emit(event),
190
+ },
191
+ proc,
192
+ ),
161
193
  accessMode: 'always-ask',
162
194
  capabilities: {},
163
195
  configOptions: [],
@@ -13,7 +13,7 @@
13
13
 
14
14
  import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
15
15
  import { isolateDb, releaseDb } from '@/test-support/isolated-db';
16
- import { mountSession, notify } from '@/server/lib/harness/acp/session.test-util';
16
+ import { flushTicks, mountSession, notify } from '@/server/lib/harness/acp/session.test-util';
17
17
  import { createSessionRelation } from '@/server/lib/sessions/relations.server';
18
18
  import { materializeNotice } from '@/server/lib/sessions/notify.server';
19
19
  import {
@@ -50,7 +50,7 @@ describe('ACP prompt dispatch', () => {
50
50
  expect(events.some((event) => event.type === 'agent_end')).toBe(false);
51
51
 
52
52
  turn.finish({ stopReason: 'end_turn' });
53
- for (let i = 0; i < 4; i += 1) await Promise.resolve();
53
+ await flushTicks();
54
54
 
55
55
  expect(events.find((event) => event.type === 'agent_end')).toMatchObject({
56
56
  type: 'agent_end',
@@ -64,7 +64,7 @@ describe('ACP prompt dispatch', () => {
64
64
  await session.send({ type: 'prompt', message: 'hello' });
65
65
  await turn.started;
66
66
  turn.fail(new Error('agent exploded'));
67
- for (let i = 0; i < 4; i += 1) await Promise.resolve();
67
+ await flushTicks();
68
68
  const errors = events.filter((event) => event.type === 'prompt_error');
69
69
  // The generic "no answer" verdict must not land on top of the agent's own
70
70
  // reason: it was emitted SECOND, so the client kept the useless one.
@@ -82,7 +82,7 @@ describe('ACP prompt dispatch', () => {
82
82
  expect(turnEnds()).toBe(0);
83
83
 
84
84
  turn.finish({ stopReason: 'end_turn' });
85
- for (let i = 0; i < 4; i += 1) await Promise.resolve();
85
+ await flushTicks();
86
86
  expect(turnEnds()).toBe(1);
87
87
  });
88
88
  });
@@ -108,7 +108,7 @@ describe('ACP cancel', () => {
108
108
  // The agent's own reply to the cancel arrives late; it must not close a turn
109
109
  // that is already closed.
110
110
  turn.finish({ stopReason: 'cancelled' });
111
- for (let i = 0; i < 4; i += 1) await Promise.resolve();
111
+ await flushTicks();
112
112
  expect(session.isRunning()).toBe(false);
113
113
  });
114
114
 
@@ -118,7 +118,7 @@ describe('ACP cancel', () => {
118
118
  await session.send({ type: 'prompt', message: 'long job' });
119
119
  session.cancelTurn();
120
120
  turn.finish({ stopReason: 'cancelled' });
121
- for (let i = 0; i < 4; i += 1) await Promise.resolve();
121
+ await flushTicks();
122
122
 
123
123
  const ends = events.filter((event) => event.type === 'agent_end');
124
124
  expect(ends).toHaveLength(1);
@@ -141,7 +141,7 @@ describe('ACP turn serialization', () => {
141
141
  // it — never went out and every later send was refused as "already
142
142
  // processing". Settling it locally is what frees the chain.
143
143
  await session.send({ type: 'prompt', message: 'second' });
144
- for (let i = 0; i < 8; i += 1) await Promise.resolve();
144
+ await flushTicks();
145
145
  expect(turn.calls()).toBe(2);
146
146
  expect(session.isRunning()).toBe(true);
147
147
  });
@@ -171,10 +171,10 @@ describe('ACP turn serialization', () => {
171
171
  await turn.started;
172
172
  session.cancelTurn();
173
173
  await session.send({ type: 'prompt', message: 'second' });
174
- for (let i = 0; i < 8; i += 1) await Promise.resolve();
174
+ await flushTicks();
175
175
 
176
176
  turn.finish({ stopReason: 'end_turn' });
177
- for (let i = 0; i < 8; i += 1) await Promise.resolve();
177
+ await flushTicks();
178
178
  expect(events.filter((event) => event.type === 'agent_end')).toHaveLength(2);
179
179
  expect(session.isRunning()).toBe(false);
180
180
  });
@@ -230,7 +230,7 @@ describe('ACP model identity', () => {
230
230
  });
231
231
 
232
232
  turn.finish({ stopReason: 'end_turn' });
233
- for (let i = 0; i < 8; i += 1) await Promise.resolve();
233
+ await flushTicks();
234
234
  expect(events.find((event) => event.type === 'message_end')?.message).toMatchObject({
235
235
  model: 'qwen3-8-27b:free',
236
236
  provider: 'kenari',
@@ -7,14 +7,11 @@
7
7
  * One live ACP session: the bridge between `AcpProcess` + `AcpFrameMapper` and
8
8
  * the `HarnessSession` contract every route already speaks.
9
9
  *
10
- * It owns the session's own state — the id, the config selectors, the resolved
11
- * model, the run flags the sidebar spinner and the queue delivery gate read, the
12
- * agent's commands and the approval queue a reloaded tab replays. The RULES live
13
- * beside it, one module per concern: `session-handshake.ts` (initialize/new/load
14
- * + the picks), `session-turns.ts` (the ACK contract and turn-end bookkeeping),
15
- * `session-config.ts` (config answers, parked dialogs), `session-permissions.ts`
16
- * (the tier that answers before a dialog exists), `session-facts.ts` (what an
17
- * agent publishes between turns) and `session-web-state.ts` (`get_state`).
10
+ * It owns the session's state — the id, the selectors, the model, the run flags,
11
+ * the commands and the approval queue. The RULES live beside it, one module per
12
+ * concern: `session-handshake.ts` (setup), `session-intake.ts` (what a prompt
13
+ * sends), `turn.ts` (the turn), `session-config.ts`, `session-permissions.ts`,
14
+ * `session-lifecycle.ts` and `session-web-state.ts`.
18
15
  *
19
16
  * `send()` takes the SAME command vocabulary the routes already send omp, so
20
17
  * `routes/agent/command.ts` needs no second dispatch table.
@@ -23,27 +20,36 @@
23
20
  import { AcpProcess } from '@/server/lib/harness/acp/client';
24
21
  import { openSessionProcess } from '@/server/lib/harness/acp/session-process';
25
22
  import { AcpTurns, type AcpTurnEndInfo } from '@/server/lib/harness/acp/turn';
23
+ import { acpBackgroundProbe, acpTurns, acpWiringFor } from '@/server/lib/harness/acp/session-wiring';
26
24
  import { AcpFrameMapper } from '@/server/lib/harness/acp/frames';
27
25
  import { AcpReplay } from '@/server/lib/harness/acp/replay';
28
26
  import { startAcpSession } from '@/server/lib/harness/acp/session-start';
29
- import type { AcpConfigOption, AcpId, AcpProtocolVersion, AcpSessionModeState } from '@/server/lib/harness/acp/protocol';
30
- import { promptBlocks } from '@/server/lib/harness/acp/prompt';
31
- import { setAcpConfig, setAcpMode, settlePermissionDialog, stampMessageModel } from '@/server/lib/harness/acp/session-config';
27
+ import type { AcpHandshakeSelections } from '@/server/lib/harness/acp/session-handshake';
28
+ import type {
29
+ AcpConfigOption,
30
+ AcpId,
31
+ AcpProtocolVersion,
32
+ AcpSessionModeState,
33
+ AcpSessionModels,
34
+ } from '@/server/lib/harness/acp/protocol';
35
+ import { promptContent, startAcpPrompt } from '@/server/lib/harness/acp/session-intake';
36
+ import { LOST_SESSION_NOTICE } from '@/server/lib/harness/acp/session-lost';
37
+ import { setAcpConfig, setAcpMode, type AcpConfigWriter } from '@/server/lib/harness/acp/session-config';
38
+ import { acpConfigView, type AcpConfigProcess } from '@/server/lib/harness/acp/session-config-view';
39
+ import * as verbs from '@/server/lib/harness/acp/verbs';
40
+ import { acpPendingDialogs, answerAcpDialog } from '@/server/lib/harness/acp/session-approvals';
32
41
  import { beginAcpTurn, endAcpTurn } from '@/server/lib/harness/acp/session-turns';
33
42
  import { capabilitiesFrom } from '@/server/lib/harness/launch';
34
43
  import { PendingPermissions } from '@/server/lib/harness/acp/permissions';
35
44
  import { cancelAllAcpPermissions } from '@/server/lib/harness/acp/session-permissions';
36
- import { handleSessionNotification } from '@/server/lib/harness/acp/session-notifications';
45
+ import { handleAcpNotification } from '@/server/lib/harness/acp/session-notify';
37
46
  import { RawNotificationSink, type RawNotificationListener } from '@/server/lib/harness/acp/raw-listeners';
38
47
  import { AcpUsageMeter, type AcpContextUsage } from '@/server/lib/harness/acp/session-usage';
39
- import { handleAcpClientRequest, handleAcpCancelRequest, type AcpClientRequestAnswer } from '@/server/lib/harness/acp/session-requests';
40
- import { reportAcpExit } from '@/server/lib/harness/acp/session-exit';
48
+ import { handleAcpClientRequest, type AcpClientRequestAnswer } from '@/server/lib/harness/acp/session-requests';
49
+ import { reportAcpExit, type AcpExitInfo } from '@/server/lib/harness/acp/session-exit';
50
+ import { acpExited, destroyAcp } from '@/server/lib/harness/acp/session-lifecycle';
41
51
  import { SessionListeners } from '@/server/lib/harness/acp/session-listeners';
42
- import {
43
- AcpBackgroundProbe,
44
- BACKGROUND_LOAD_TIMEOUT_MS,
45
- deliverBackgroundNotice,
46
- } from '@/server/lib/harness/acp/background-work';
52
+ import type { AcpBackgroundProbe } from '@/server/lib/harness/acp/background-work';
47
53
  import { acpWebState } from '@/server/lib/harness/acp/session-web-state';
48
54
  import { acpIdleReaper } from '@/server/lib/harness/acp/session-idle';
49
55
  import { DEFAULT_APPROVAL_MODE, isApprovalMode, type ApprovalMode } from '@/shared/lib/omp/config/access-mode';
@@ -57,13 +63,27 @@ import type { HarnessId } from '@/shared/lib/harness/catalog';
57
63
  import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
58
64
  import type { IdleReaper } from '@/server/lib/omp/rpc/idle-reaper';
59
65
 
66
+ /** The process verbs the config view calls, bound to the CURRENT session id. */
67
+ function configProcess(proc: AcpProcess): AcpConfigProcess {
68
+ return {
69
+ setConfigOption: (session, id, value) => proc.setConfigOption(session, id, value),
70
+ setMode: (session, modeId) => proc.setMode(session, modeId),
71
+ setModel: (session, modelId) => verbs.setModel(proc.call, session, modelId),
72
+ };
73
+ }
74
+
60
75
  export class AcpSession implements HarnessSession, AcpCommandHost {
61
76
  readonly harness: HarnessId;
62
77
  readonly cwd: string;
63
78
  readonly sessionFile = '';
79
+ /** The launch line, so a refused handshake can name the sign-in command. */
80
+ readonly command: string[];
81
+ /** The environment the agent sees, read to satisfy a headless auth method. */
82
+ readonly authEnv?: Record<string, string | undefined>;
64
83
  sessionId = '';
65
- /** The turn in flight — the only one whose frames are accepted. */
66
- private readonly turns: AcpTurns;
84
+ /** The turn in flight — the only one whose frames are accepted. Public so the
85
+ * notification router can note activity on it. */
86
+ readonly turns: AcpTurns;
67
87
  runModel: { provider: string; modelId: string } | null = null;
68
88
  /** The agent's own slash-command list; the composer's `/` pool reads it. */
69
89
  agentCommands: { name: string; description?: string; inputHint?: string }[] = [];
@@ -87,6 +107,9 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
87
107
  configOptions: AcpConfigOption[] = [];
88
108
  /** The older Session Modes API, adopted when the agent publishes one. */
89
109
  modes: AcpSessionModeState | null = null;
110
+ /** The `models` block the agent published, when it published one instead of
111
+ * a `model` selector (measured on grok). */
112
+ models: AcpSessionModels | null = null;
90
113
  /** Whether the agent advertised `promptCapabilities.image`. */
91
114
  acceptsImages = false;
92
115
  /** MCP servers every session request carries; empty when none are configured. */
@@ -98,65 +121,48 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
98
121
  readonly background: AcpBackgroundProbe;
99
122
  private readonly mapper = new AcpFrameMapper();
100
123
  private readonly events = new SessionListeners();
101
- /** Raw `session/update` sinks: the frame log the raw panel reads. */
102
- private readonly rawSink = new RawNotificationSink();
124
+ /** Raw `session/update` sinks: the frame log the raw panel reads. Public so
125
+ * `session-notify.ts` can feed it before the mapper folds a frame. */
126
+ readonly rawSink = new RawNotificationSink();
103
127
  readonly permissions = new PendingPermissions();
104
128
  private destroyHook: (() => void) | null = null;
105
- private destroyed = false;
129
+ destroyed = false;
106
130
  /** True only for a restore: replay frames are accepted and collected. */
107
131
  private readonly wantsReplay: boolean;
108
132
  readonly replay = new AcpReplay();
109
133
  /** Set when Kabmo ends the process, so a requested stop is not reported as a failure. */
110
- private closing = false;
134
+ closing = false;
111
135
 
112
136
  constructor(options: AcpSessionOptions, cwd: string) {
113
137
  this.harness = options.harness;
114
138
  this.cwd = cwd;
139
+ this.command = options.command;
140
+ if (options.env) this.authEnv = options.env;
115
141
  this.proc = openSessionProcess(options, cwd, {
116
142
  onNotification: (method, params) => this.onNotification(method, params),
117
143
  onClientRequest: (id, method, params) => this.onClientRequest(id, method, params),
118
144
  onExit: (info) => this.onExit(info),
119
145
  });
120
146
  this.idle = acpIdleReaper(this, options.idleDestroyMs);
121
- // ACP holds updates produced while idle until the next request, so a turn
122
- // that spawned a subagent is followed by a `session/load` probe. The replay
123
- // is swallowed by the probe; only the text past the answer already shown is
124
- // emitted, as the agent's continuation.
125
- this.background = new AcpBackgroundProbe({
126
- load: () => this.proc.loadSession(this.sessionId, this.cwd, BACKGROUND_LOAD_TIMEOUT_MS),
127
- resetIdle: () => this.idle.reset(),
128
- emit: (text) => deliverBackgroundNotice(this, text),
129
- });
130
- this.turns = new AcpTurns({
131
- emit: (event) => this.emit(event),
132
- prompt: (message, images) =>
133
- this.proc.prompt(this.sessionId, promptBlocks(message, images), 0) as Promise<{ stopReason?: string } | undefined>,
134
- cancelAgent: () => this.proc.cancel(this.sessionId),
135
- abandonPrompt: () => this.proc.abandonPrompt(this.sessionId),
136
- resetMapper: () => this.mapper.reset(),
137
- closeMessage: () => this.mapper.closeMessage().map((event) => stampMessageModel(event, this.runModel)),
138
- openCalls: () => this.mapper.openCalls(),
139
- // The follow-up queue is armed from the turn's END, exactly as the omp
140
- // wrapper arms it from its own terminal settle. Without this an ACP chat's
141
- // queued follow-up stayed in `queued_messages` forever: nothing on this
142
- // transport scheduled a delivery, and the client's nudge route only knew
143
- // omp's wrapper.
144
- onTurnEnd: (info) => this.onTurnEnded(info),
145
- });
147
+ // `sessionId`/`runModel` start empty and are read LIVE: the handshake sets
148
+ // them, and a closed message must carry the model it actually ran on.
149
+ const wiring = acpWiringFor(this, { proc: this.proc, mapper: this.mapper, idle: this.idle });
150
+ this.background = acpBackgroundProbe(wiring);
151
+ this.turns = acpTurns(wiring);
146
152
  this.mcpServers = options.mcpServers ?? [];
147
153
  this.wantsReplay = options.replay === true;
148
- this.requestedModel = options.model ?? null;
149
- this.requestedThinking = options.thinkingLevel ?? null;
150
- this.requestedMode = options.mode ?? null;
154
+ this.requested = { model: options.model ?? null, thinking: options.thinkingLevel ?? null, mode: options.mode ?? null };
151
155
  this.accessMode = isApprovalMode(options.accessMode) ? options.accessMode : DEFAULT_APPROVAL_MODE;
156
+ this.config = acpConfigView(this, configProcess(this.proc));
152
157
  }
153
158
 
154
- private readonly requestedModel: { provider: string; modelId: string } | null;
155
- private readonly requestedThinking: string | null;
156
- private readonly requestedMode: string | null;
159
+ /** The selector view the config rules write through. */
160
+ private readonly config: AcpConfigWriter;
161
+ /** The picks the spawn carried, applied after setup. */
162
+ private readonly requested: AcpHandshakeSelections;
157
163
  /** `initialize` + `session/new|load|resume`, then the requested selections. */
158
164
  async start(sessionIdToLoad?: string, forkFromSessionId?: string, forkMeta?: Record<string, unknown>): Promise<{ sessionId: string }> {
159
- return startAcpSession(this, this.proc, this.mapper, this.replay, this.wantsReplay, { model: this.requestedModel, thinking: this.requestedThinking, mode: this.requestedMode }, sessionIdToLoad, forkFromSessionId, forkMeta);
165
+ return startAcpSession(this, this.proc, this.mapper, this.replay, this.wantsReplay, this.requested, sessionIdToLoad, forkFromSessionId, forkMeta);
160
166
  }
161
167
 
162
168
  get protocol(): AcpProtocolVersion { return this.proc.protocolVersion === 2 ? 2 : 1; }
@@ -173,11 +179,29 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
173
179
  /** Subscribe to the raw `session/update` payloads, before the mapper folds them. */
174
180
  onRawNotification(listener: RawNotificationListener): () => void { return this.rawSink.add(listener); }
175
181
  emit(event: AgentEvent): void { this.replay.push(event); this.events.emit(event); }
182
+ /** Run the single destroy callback the registry installed. */
183
+ runDestroyHook(): void { this.destroyHook?.(); }
184
+
185
+ /** The teardown seams `session-lifecycle.ts` drives: methods, not class
186
+ * fields, because a test mounts the class on its prototype and a field
187
+ * initializer never runs there. */
188
+ disposeProcess(): Promise<void> {
189
+ return this.proc.dispose();
190
+ }
191
+
192
+ reportExit(info: AcpExitInfo): Promise<void> {
193
+ return reportAcpExit(this, info);
194
+ }
195
+
196
+ /** The dispatcher's command surface — see `commands.ts` for the rules. */
197
+ dispatch(command: Record<string, unknown>): Promise<unknown> {
198
+ // A command is the clearest sign the session is still wanted.
199
+ this.idle.reset();
200
+ return dispatchCommand(this, command);
201
+ }
176
202
 
177
203
  getPendingUiDialogs(): Record<string, unknown>[] {
178
- // Widened for the shared `HarnessSession` contract, which predates the
179
- // dialog shape; every field the client reads is present.
180
- return this.permissions.pendingDialogs() as unknown as Record<string, unknown>[];
204
+ return acpPendingDialogs(this.permissions);
181
205
  }
182
206
 
183
207
  resolvePendingUiDialog(id: string): void {
@@ -189,10 +213,8 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
189
213
  this.destroyHook = callback;
190
214
  }
191
215
 
192
- async send(command: Record<string, unknown>): Promise<unknown> {
193
- // A command is the clearest sign the session is still wanted.
194
- this.idle.reset();
195
- return dispatchCommand(this, command);
216
+ send(command: Record<string, unknown>): Promise<unknown> {
217
+ return this.dispatch(command);
196
218
  }
197
219
 
198
220
  /** Dispatcher seam: one steering send. */
@@ -200,22 +222,50 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
200
222
  return this.proc.steer(this.sessionId, blocks, queue);
201
223
  }
202
224
 
203
- /** Record a mid-turn user message; the ACP mapper drops live user frames. */
225
+ /** The blocks one prompt sends (text, images, `@path` links). */
226
+ blocksFor(message: string, images: unknown): Promise<unknown[]> {
227
+ return promptContent(this, message, images);
228
+ }
229
+
230
+ /** Dispatcher seam: hold an input the agent has no mid-turn channel for, so
231
+ * it is dispatched as the next turn instead of refused or lost. */
232
+ queueTurnInput(message: string, images: unknown): void {
233
+ this.turns.queue(message, images);
234
+ }
235
+
236
+ /** Record a mid-turn user message; the mapper drops live user frames. */
204
237
  recordUserTurn(message: string, images: unknown): void { this.emit({ type: 'user_turn', message, images }); }
205
- /**
206
- * The durable run marker (`session_stream_state`), the row the sidebar's
207
- * spinner and a reattaching tab's "still running" answer read. A field so a
208
- * unit test can stub it: the default writes the same row omp's dispatch writes.
209
- */
238
+
239
+ /** The durable run marker the sidebar's spinner and a reattaching tab read. A
240
+ * field so a unit test can stub it. */
210
241
  markStream: (status: 'stream' | 'finish' | 'abort', failure?: string | null) => void = (status, failure) => {
211
242
  if (!this.sessionId) return;
212
243
  void markStreamStatus(this.sessionId, status, status === 'stream' ? this.runModel : undefined, failure).catch(() => {});
213
244
  };
214
245
 
215
- /** Turn-end bookkeeping the panels read — see `endAcpTurn`. Returns the
216
- * child-outcome write, so a caller that must observe it can await it. */
246
+ /** Turn-end bookkeeping the panels read — see `endAcpTurn`, plus the held
247
+ * input that becomes the next turn. */
217
248
  onTurnEnded(info: AcpTurnEndInfo): Promise<void> {
218
- return endAcpTurn(this, info);
249
+ const reported = endAcpTurn(this, info);
250
+ // A held input is the NEXT turn: the queue lives in the turn machine, and a
251
+ // session that never drains it loses the message silently.
252
+ const next = this.turns.takeQueued();
253
+ if (next) {
254
+ try {
255
+ this.startTurn(next.message, next.images);
256
+ } catch {
257
+ // A turn that reopened first (a background interval) wins; the input is
258
+ // dropped rather than re-queued behind an indefinite run.
259
+ }
260
+ }
261
+ return reported;
262
+ }
263
+
264
+ /** Drop this session so the next command respawns it and resumes the agent's
265
+ * own history. Called when the agent reports the session is gone. */
266
+ dropLostSession(): void {
267
+ this.emit({ type: 'notice', level: 'warning', message: LOST_SESSION_NOTICE });
268
+ void this.destroyAndWait();
219
269
  }
220
270
 
221
271
  /** Dispatcher seam: stop the turn and answer every parked approval. */
@@ -231,71 +281,37 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
231
281
  this.accessMode = mode;
232
282
  }
233
283
 
234
- /** Dispatcher seam: write one config selector — see `session-config.ts`. */
284
+ /** Dispatcher seam: the selector writes this session accepts. */
235
285
  async setConfig(configId: string, value: string | boolean): Promise<unknown> {
236
- return setAcpConfig(this, configId, value);
286
+ return setAcpConfig(this.config, configId, value);
237
287
  }
238
288
 
239
289
  /** `session/set_mode`: the pre-config-options way to move a mode. */
240
290
  async setMode(modeId: string): Promise<unknown> {
241
- return setAcpMode(this, modeId);
291
+ return setAcpMode(this.config, modeId);
242
292
  }
243
293
 
244
- /** The process half of `setAcpConfig`/`setAcpMode`. */
245
- writeConfigOption(configId: string, value: string | boolean): Promise<unknown> {
246
- return this.proc.setConfigOption(this.sessionId, configId, value);
247
- }
248
-
249
- writeMode(modeId: string): Promise<unknown> {
250
- return this.proc.setMode(this.sessionId, modeId);
251
- }
252
-
253
- /** Dispatcher seam: answer a pending approval dialog. Every exit answers the
254
- * agent — a silent return would hang it (see `session-config.ts`). */
255
- resolvePermission(dialogId: string, confirmed: boolean): unknown {
256
- settlePermissionDialog(this.permissions, this.proc, dialogId, confirmed);
294
+ /** Answer a pending approval — every exit answers the agent, or it hangs. */
295
+ resolvePermission(dialogId: string, confirmed: boolean, optionId?: string): unknown {
296
+ answerAcpDialog(this.permissions, this.proc, dialogId, confirmed, optionId);
257
297
  return null;
258
298
  }
259
299
 
260
300
  webState(): Record<string, unknown> { return acpWebState(this); }
261
301
 
262
- /** Run one turn. The promise IS the turn: ACP resolves `session/prompt` when
263
- * the agent is done, so the reply is awaited for its whole duration. The ACK,
264
- * the refusal of a second prompt and the end bookkeeping are stated in
265
- * `session-turns.ts`.
266
- */
302
+ /** Run one turn — see `session-intake.ts` for the refusal and the ACK. */
267
303
  startTurn(message: string, images: unknown): unknown {
268
- // ACP's prompt capabilities are a MUST: an agent that did not advertise
269
- // `image` has to be told, not sent blocks its dispatcher rejects.
270
- if (!this.acceptsImages && Array.isArray(images) && images.length > 0) {
271
- throw new Error(`This harness does not accept image attachments (${this.harness})`);
272
- }
273
- // A new prompt is the next request, so the agent flushes any held update
274
- // itself; a probe would duplicate it.
275
- this.background.stop();
276
- this.promptCount += 1;
277
- this.usage.beginTurn();
278
- const ack = beginAcpTurn(this, this.turns, message, images);
279
- // Only a delivered turn is recorded: a refusal must not leave a user row.
280
- this.emit({ type: 'user_turn', message, images });
281
- return ack;
304
+ return startAcpPrompt(this, message, images);
305
+ }
306
+
307
+ /** The seam `startAcpPrompt` opens a turn through. */
308
+ beginTurn(message: string, images: unknown): unknown {
309
+ return beginAcpTurn(this, this.turns, message, images);
282
310
  }
283
311
 
312
+ /** One agent notification, routed — see `session-notify.ts`. */
284
313
  private onNotification(method: string, params: Record<string, unknown>): void {
285
- // A long turn emits no commands but plenty of `session/update` frames.
286
- this.idle.reset();
287
- // The same frames are the only evidence a turn is still alive: ACP has no
288
- // probe, so the silence ceiling is what bounds a wedged agent.
289
- this.turns.noteActivity();
290
- // `$/cancel_request` names an agent→client request the agent no longer
291
- // wants; the approval it parks is answered `cancelled`.
292
- if (handleAcpCancelRequest(this, method, params)) return;
293
- // A `session/load` replay repeats the whole chat; leave it to the probe.
294
- if (this.background.consume(method, params)) return;
295
- // The raw panel reads the original ACP payloads, so the frame log is fed
296
- // BEFORE the mapper folds them (and before the turn gate can drop one).
297
- if (method === 'session/update') this.rawSink.emit(method, params);
298
- handleSessionNotification(this, method, params);
314
+ handleAcpNotification(this, method, params);
299
315
  }
300
316
 
301
317
  absorbUsage(update: Record<string, unknown>): void { this.usage.absorb(update); }
@@ -303,32 +319,25 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
303
319
  acceptingFrames(): boolean { return this.replay.isActive || this.turns.acceptingFrames(); }
304
320
  mapUpdate(update: Record<string, unknown>): AgentEvent[] { return this.mapper.mapUpdate(update); }
305
321
  onStateUpdate(update: Record<string, unknown>): void { this.turns.onStateUpdate(update); this.replay.markIdle(update.state); }
306
- /** Answer an agent→client request with a result (cancellation uses it). */
307
322
  respond(id: AcpId, result: unknown): void { this.proc.respond(id, result); }
308
- /** Agent→client requests: every branch answers or refuses — an unanswered call parks the turn. */
323
+ /** Agent→client requests: every branch answers or refuses. */
309
324
  private onClientRequest(id: AcpId, method: string, params: Record<string, unknown>): Promise<AcpClientRequestAnswer> {
310
325
  this.idle.reset();
311
326
  return handleAcpClientRequest(this, id, method, params);
312
327
  }
313
328
 
314
- /** The agent's process is gone — see `reportAcpExit`; returns its notice write. */
315
- private onExit(info: { code: number | null; stderrTail: string }): Promise<void> {
316
- this.destroyed = true;
317
- this.background.stop();
318
- this.idle.stop();
319
- const reported = this.closing ? Promise.resolve() : reportAcpExit(this, info);
320
- this.destroyHook?.();
321
- return reported;
329
+ /** The agent's process is gone — see `session-lifecycle.ts`. */
330
+ private onExit(info: AcpExitInfo): Promise<void> {
331
+ return acpExited(this, info);
322
332
  }
323
333
 
324
334
  destroy(): void { void this.destroyAndWait(); }
325
335
 
326
336
  /** Remove this chat from the agent's own history, when it offers the method.
327
337
  *
328
- * `false` means the agent advertises no `session/delete` (or this session has
329
- * no agent id yet) — the caller then falls back to the local store. A failure
330
- * is THROWN: the delete route refuses and shows the agent's words, because a
331
- * swallowed error here is a row that returns on the next import. */
338
+ * `false` (no `session/delete`, or no agent id yet) makes the caller fall back
339
+ * to the local store; a failure is THROWN so the delete route can refuse
340
+ * instead of leaving a row that returns on the next import. */
332
341
  async deleteAgentSession(): Promise<boolean> {
333
342
  if (!this.sessionId || !this.capabilities.deleteSession) return false;
334
343
  await this.proc.deleteSession(this.sessionId, 10_000);
@@ -336,13 +345,6 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
336
345
  }
337
346
 
338
347
  async destroyAndWait(): Promise<void> {
339
- if (this.destroyed) return;
340
- this.destroyed = true;
341
- this.closing = true;
342
- this.background.stop();
343
- this.idle.stop();
344
- this.permissions.clear();
345
- await this.proc.dispose().catch(() => {});
346
- this.destroyHook?.();
348
+ await destroyAcp(this);
347
349
  }
348
350
  }