@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,75 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Persistence for ACP "always allow" grants.
8
+ *
9
+ * A grant is a decision the operator made about a command, so it must outlive
10
+ * the child that asked: the idle reaper kills an ACP agent after ten minutes and
11
+ * the next prompt adopts (or spawns) another one. Keeping the set in memory made
12
+ * the operator approve the same `bash` line again after every reclaim.
13
+ *
14
+ * Deliberately its own table rather than `session_ui_state`: that blob belongs
15
+ * to the client and the session route REPLACES it wholesale, so a server-side
16
+ * write there would be erased by the next layout save.
17
+ */
18
+
19
+ import { getDb } from '@/server/db.server';
20
+ import type { DbClient } from '@/server/lib/db/client';
21
+
22
+ const GRANTS_SQL = `
23
+ CREATE TABLE IF NOT EXISTS acp_permission_grants (
24
+ session_id TEXT NOT NULL,
25
+ grant_key TEXT NOT NULL,
26
+ created_at INTEGER NOT NULL,
27
+ PRIMARY KEY (session_id, grant_key)
28
+ );
29
+ `;
30
+
31
+ /** Create the table on boot; the session routes touch it lazily. */
32
+ export async function ensureAcpGrantSchema(db: DbClient): Promise<void> {
33
+ await db.exec(GRANTS_SQL);
34
+ }
35
+
36
+ /** Every key this session has already approved with "always". */
37
+ export async function loadAcpGrants(sessionId: string): Promise<string[]> {
38
+ try {
39
+ const db = await getDb();
40
+ const rows = await db.all<{ grant_key: string }>(
41
+ 'SELECT grant_key FROM acp_permission_grants WHERE session_id = ?',
42
+ [sessionId],
43
+ );
44
+ return rows.map((row) => row.grant_key);
45
+ } catch {
46
+ // no-excuse-ok: catch — an unreadable grants table is not a reason to fail
47
+ // the spawn; the operator is asked again, which is the safe direction.
48
+ return [];
49
+ }
50
+ }
51
+
52
+ /** Remember one "always allow" decision. Best effort: the current turn already
53
+ * holds the in-memory grant, so a failed write only costs a repeat question. */
54
+ export async function saveAcpGrant(sessionId: string, grantKey: string): Promise<void> {
55
+ try {
56
+ const db = await getDb();
57
+ await db.run(
58
+ `INSERT INTO acp_permission_grants (session_id, grant_key, created_at) VALUES (?, ?, ?)
59
+ ON CONFLICT(session_id, grant_key) DO NOTHING`,
60
+ [sessionId, grantKey, Date.now()],
61
+ );
62
+ } catch {
63
+ // no-excuse-ok: catch — see above.
64
+ }
65
+ }
66
+
67
+ /** Drop a deleted chat's grants with the rest of its rows. */
68
+ export async function forgetAcpGrants(sessionId: string): Promise<void> {
69
+ try {
70
+ const db = await getDb();
71
+ await db.run('DELETE FROM acp_permission_grants WHERE session_id = ?', [sessionId]);
72
+ } catch {
73
+ // no-excuse-ok: catch — the delete path reports its own failures.
74
+ }
75
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * "Always allow" is the operator's standing decision about one CALL, keyed by
8
+ * what the dialog showed — not by a tool-call id that differs on every
9
+ * invocation. A grant that outlived a process is the point; a grant that leaked
10
+ * across kinds (a write covering an exec) would be a security hole.
11
+ */
12
+
13
+ import { describe, expect, test } from 'bun:test';
14
+ import { permissionGrantKey, PermissionGrants } from '@/server/lib/harness/acp/grants';
15
+ import { ensureAcpGrantSchema, loadAcpGrants, saveAcpGrant } from '@/server/lib/harness/acp/grants.server';
16
+ import { getDb } from '@/server/db.server';
17
+ import { isolateDb, releaseDb } from '@/test-support/isolated-db';
18
+
19
+ describe('permissionGrantKey', () => {
20
+ test('keys on the command the dialog shows', () => {
21
+ expect(permissionGrantKey({ kind: 'execute', rawInput: { command: 'rm -rf build' } })).toBe('execute\u0000rm -rf build');
22
+ });
23
+
24
+ test('keeps kinds apart so a write grant never covers an exec', () => {
25
+ const write = permissionGrantKey({ kind: 'edit', rawInput: { path: '/a.ts' } });
26
+ const read = permissionGrantKey({ kind: 'read', rawInput: { path: '/a.ts' } });
27
+ expect(write).not.toBe(read);
28
+ });
29
+
30
+ test('a call with nothing identifying earns no key', () => {
31
+ expect(permissionGrantKey({ kind: 'execute', title: ' ' })).toBeNull();
32
+ expect(permissionGrantKey(undefined)).toBeNull();
33
+ });
34
+ });
35
+
36
+ describe('PermissionGrants', () => {
37
+ test('hydrated keys answer without a dialog', () => {
38
+ const grants = new PermissionGrants();
39
+ grants.hydrate(['execute\u0000make']);
40
+ expect(grants.has('execute\u0000make')).toBe(true);
41
+ expect(grants.has(null)).toBe(false);
42
+ });
43
+
44
+ test('adding a key twice reports the first as the new grant', () => {
45
+ const grants = new PermissionGrants();
46
+ expect(grants.add('k')).toBe(true);
47
+ expect(grants.add('k')).toBe(false);
48
+ expect(grants.snapshot()).toEqual(['k']);
49
+ });
50
+ });
51
+
52
+ describe('grant persistence', () => {
53
+ test('a saved grant is read back for the same session, and only that one', async () => {
54
+ await isolateDb();
55
+ try {
56
+ await ensureAcpGrantSchema(await getDb());
57
+ await saveAcpGrant('chat-1', 'execute\u0000make test');
58
+ await saveAcpGrant('chat-1', 'execute\u0000make test');
59
+ expect(await loadAcpGrants('chat-1')).toEqual(['execute\u0000make test']);
60
+ expect(await loadAcpGrants('chat-2')).toEqual([]);
61
+ } finally {
62
+ await releaseDb();
63
+ }
64
+ });
65
+ });
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The "always allow" grants of one ACP session.
8
+ *
9
+ * ACP offers `allow_always` beside `allow_once` on a permission request, and
10
+ * ignoring it made every repeated tool call ask again — the agent's own answer
11
+ * to "can I run this script" was thrown away and the operator re-approved the
12
+ * same command for the whole turn.
13
+ *
14
+ * A grant is keyed by what the approval DIALOG showed, not by the tool call id
15
+ * (which is different on every invocation): the tool's kind plus the command or
16
+ * path the agent reported. `reject_always` is deliberately NOT remembered —
17
+ * surfacing every attempt again is the safer mistake, and a refusal the operator
18
+ * has to repeat is never a security hole.
19
+ *
20
+ * The set is per SESSION and hydrated from the database at spawn, so a reload or
21
+ * a reclaimed child does not resurrect the questions.
22
+ */
23
+
24
+ /** A grant is a key plus the option kind it was granted with. */
25
+ export interface PermissionGrant {
26
+ key: string;
27
+ kind: 'allow_always';
28
+ }
29
+
30
+ /** The identity a dialog showed: stable across invocations of the same call. */
31
+ export function permissionGrantKey(toolCall: Record<string, unknown> | undefined): string | null {
32
+ if (!toolCall) return null;
33
+ const kind = typeof toolCall.kind === 'string' ? toolCall.kind : 'other';
34
+ const rawInput = toolCall.rawInput && typeof toolCall.rawInput === 'object'
35
+ ? toolCall.rawInput as Record<string, unknown>
36
+ : {};
37
+ // The field the dialog renders for a write/edit, plus the fields an exec
38
+ // carries. A title is a last resort: some agents send a constant title, and a
39
+ // grant keyed on nothing must not exist.
40
+ const subject = [
41
+ rawInput.command,
42
+ rawInput.path,
43
+ rawInput.filePath,
44
+ rawInput.file,
45
+ rawInput.target,
46
+ ].find((value): value is string => typeof value === 'string' && value.trim().length > 0);
47
+ const title = typeof toolCall.title === 'string' ? toolCall.title.trim() : '';
48
+ const identity = subject ?? title;
49
+ if (!identity) return null;
50
+ return `${kind}\u0000${identity}`;
51
+ }
52
+
53
+ /** The grants one session has earned, in memory. */
54
+ export class PermissionGrants {
55
+ readonly #keys = new Set<string>();
56
+
57
+ /** Adopt the rows read from the database at spawn. */
58
+ hydrate(keys: readonly string[]): void {
59
+ for (const key of keys) this.#keys.add(key);
60
+ }
61
+
62
+ has(key: string | null): boolean {
63
+ return key !== null && this.#keys.has(key);
64
+ }
65
+
66
+ add(key: string | null): boolean {
67
+ if (key === null || this.#keys.has(key)) return false;
68
+ this.#keys.add(key);
69
+ return true;
70
+ }
71
+
72
+ clear(): void {
73
+ this.#keys.clear();
74
+ }
75
+
76
+ snapshot(): string[] {
77
+ return [...this.#keys];
78
+ }
79
+ }
@@ -63,4 +63,13 @@ describe('allowOption', () => {
63
63
  expect(allowOption([{ optionId: 'deny', kind: 'reject_once' }])).toBeNull();
64
64
  expect(allowOption([])).toBeNull();
65
65
  });
66
+
67
+ test('a GRANTED call asks for the standing option first', () => {
68
+ expect(
69
+ allowOption([
70
+ { optionId: 'once', kind: 'allow_once' },
71
+ { optionId: 'always', kind: 'allow_always' },
72
+ ], 'always'),
73
+ ).toBe('always');
74
+ });
66
75
  });
@@ -19,6 +19,7 @@
19
19
 
20
20
  import type { AcpId } from '@/server/lib/harness/acp/protocol';
21
21
  import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
22
+ import { PermissionGrants } from '@/server/lib/harness/acp/grants';
22
23
 
23
24
  export interface PermissionOption {
24
25
  optionId: string;
@@ -35,18 +36,40 @@ export interface PendingPermission {
35
36
  options: PermissionOption[];
36
37
  }
37
38
 
38
- /** What `extension_ui_request` carries for one pending approval. */
39
+ /** What `extension_ui_request` carries for one pending approval.
40
+ *
41
+ * `options`/`optionIds` are parallel arrays: the client draws the labels and
42
+ * answers with the id, so "Always allow" is a decision it can actually make.
43
+ * The labels alone cannot name an option — two may read alike, and omp frames
44
+ * that have no ids (every non-ACP producer) stay a yes/no confirm. */
39
45
  export interface PermissionDialog {
40
46
  type: 'extension_ui_request';
41
47
  id: string;
42
48
  method: 'confirm';
43
49
  title: string;
44
50
  message: string;
45
- options: { id: string; label: string }[];
51
+ options: string[];
52
+ optionIds: string[];
53
+ }
54
+
55
+ /** One dialog, from the request it parks. Shared by `add` and the replay so a
56
+ * reattaching client sees exactly what the live one did. */
57
+ function dialogFor(entry: PendingPermission): PermissionDialog {
58
+ return {
59
+ type: 'extension_ui_request',
60
+ id: entry.requestId,
61
+ method: 'confirm',
62
+ title: typeof entry.toolCall?.title === 'string' ? entry.toolCall.title : 'Approve this action',
63
+ message: describePermission(entry.toolCall),
64
+ options: entry.options.map((option) => option.name ?? option.optionId),
65
+ optionIds: entry.options.map((option) => option.optionId),
66
+ };
46
67
  }
47
68
 
48
69
  export class PendingPermissions {
49
70
  private readonly entries: PendingPermission[] = [];
71
+ /** Standing "always allow" decisions, keyed by the call the dialog showed. */
72
+ readonly grants = new PermissionGrants();
50
73
 
51
74
  /** Register one agent request and describe the dialog the client must draw. */
52
75
  add(id: AcpId, sessionId: string, params: Record<string, unknown>): PermissionDialog {
@@ -61,48 +84,36 @@ export class PendingPermissions {
61
84
  options: Array.isArray(params.options) ? (params.options as PermissionOption[]) : [],
62
85
  };
63
86
  this.entries.push(entry);
64
- return {
65
- type: 'extension_ui_request',
66
- id: entry.requestId,
67
- method: 'confirm',
68
- title: typeof toolCall?.title === 'string' ? toolCall.title : 'Approve this action',
69
- message: describePermission(toolCall),
70
- options: entry.options.map((option) => ({ id: option.optionId, label: option.name ?? option.optionId })),
71
- };
87
+ return dialogFor(entry);
72
88
  }
73
89
 
74
90
  /** Every dialog still waiting — a reattaching client replays these. */
75
91
  pendingDialogs(): PermissionDialog[] {
76
- return this.entries.map((entry) => ({
77
- type: 'extension_ui_request',
78
- id: entry.requestId,
79
- method: 'confirm',
80
- title: typeof entry.toolCall?.title === 'string' ? entry.toolCall.title : 'Approve this action',
81
- message: describePermission(entry.toolCall),
82
- options: entry.options.map((option) => ({ id: option.optionId, label: option.name ?? option.optionId })),
83
- }));
92
+ return this.entries.map(dialogFor);
84
93
  }
85
94
 
86
- /** The entry a dialog id names, without removing it. */
95
+ /** The entry a dialog id names, removing it so one request is answered once. */
87
96
  take(dialogId: string): PendingPermission | undefined {
88
97
  const index = this.entries.findIndex((entry) => entry.requestId === dialogId);
89
98
  if (index === -1) return undefined;
90
99
  return this.entries.splice(index, 1)[0];
91
100
  }
92
101
 
93
- /** Answer one dialog through `answer`, or cancel it when it is unknown. */
94
- resolve(dialogId: string, answer: (dialogId: string, confirmed: boolean) => unknown, confirmed = false): unknown {
95
- if (!this.entries.some((entry) => entry.requestId === dialogId)) {
96
- return answer(dialogId, false);
97
- }
98
- return answer(dialogId, confirmed);
99
- }
100
-
101
- /** The option a decision maps to, preferring the exact once-only kind. */
102
+ /** The option a decision maps to, IN THAT DIRECTION ONLY.
103
+ *
104
+ * The previous fallback (`options[0]` for confirm, the last option for deny)
105
+ * guessed from POSITION, and an agent whose list ran `[reject_once, …]` made
106
+ * Confirm reject while a dismissed dialog ("Esc") selected an `allow_*` that
107
+ * happened to be last. Undefined is the honest answer when the agent offered
108
+ * no option pointing the way the operator chose; the caller answers
109
+ * `cancelled`. */
102
110
  optionFor(entry: PendingPermission, confirmed: boolean): PermissionOption | undefined {
103
- return confirmed
104
- ? entry.options.find((option) => option.kind === 'allow_once') ?? entry.options[0]
105
- : entry.options.find((option) => option.kind === 'reject_once') ?? entry.options[entry.options.length - 1];
111
+ const kinds = confirmed ? ['allow_once', 'allow_always'] : ['reject_once', 'reject_always'];
112
+ for (const kind of kinds) {
113
+ const found = entry.options.find((option) => option.kind === kind);
114
+ if (found) return found;
115
+ }
116
+ return undefined;
106
117
  }
107
118
 
108
119
  clear(): void {
@@ -153,9 +164,18 @@ export function autoApproval(mode: ApprovalMode, toolCall: Record<string, unknow
153
164
  }
154
165
 
155
166
  /** The `allow_*` option id an auto-approval selects, or null when the agent
156
- * offered none — a request with no allow option still has to reach the user. */
157
- export function allowOption(options: readonly PermissionOption[]): string | null {
158
- const option = options.find((entry) => entry.kind === 'allow_once')
159
- ?? options.find((entry) => typeof entry.kind === 'string' && entry.kind.startsWith('allow_'));
160
- return option?.optionId ?? null;
167
+ * offered none — a request with no allow option still has to reach the user.
168
+ * `prefer: 'always'` is used for a GRANTED call, where the standing decision
169
+ * is exactly "always" and no dialog will follow. */
170
+ export function allowOption(
171
+ options: readonly PermissionOption[],
172
+ prefer: 'once' | 'always' = 'once',
173
+ ): string | null {
174
+ const kinds = prefer === 'always' ? ['allow_always', 'allow_once'] : ['allow_once', 'allow_always'];
175
+ for (const kind of kinds) {
176
+ const found = options.find((entry) => entry.kind === kind);
177
+ if (found) return found.optionId;
178
+ }
179
+ const any = options.find((entry) => typeof entry.kind === 'string' && entry.kind.startsWith('allow_'));
180
+ return any?.optionId ?? null;
161
181
  }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * `@path` mentions as ACP `resource_link` blocks.
8
+ *
9
+ * Only omp expands a mention into file contents. For every other agent the
10
+ * mention is a path with no bytes behind it, so the client sends the link the
11
+ * agent can resolve through the `fs/*` surface it was promised. The refusals
12
+ * matter as much: an escaped or missing path must not become a link the agent
13
+ * then fails to read.
14
+ */
15
+
16
+ import { afterEach, describe, expect, test } from 'bun:test';
17
+ import { mkdtemp, rm } from 'node:fs/promises';
18
+ import { tmpdir } from 'node:os';
19
+ import { join } from 'node:path';
20
+ import { promptFileLinks } from '@/server/lib/harness/acp/prompt-files';
21
+ import { promptBlocks } from '@/server/lib/harness/acp/prompt';
22
+
23
+ const scratch: string[] = [];
24
+
25
+ async function workspace(): Promise<string> {
26
+ const cwd = await mkdtemp(join(tmpdir(), 'kabmo-acp-links-'));
27
+ scratch.push(cwd);
28
+ return cwd;
29
+ }
30
+
31
+ afterEach(async () => {
32
+ await Promise.all(scratch.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
33
+ });
34
+
35
+ describe('promptFileLinks', () => {
36
+ test('a bare mention of an existing file becomes a link', async () => {
37
+ const cwd = await workspace();
38
+ await Bun.write(join(cwd, 'app.ts'), 'x');
39
+ expect(await promptFileLinks(cwd, 'look at @app.ts please')).toEqual([
40
+ { uri: `file://${join(cwd, 'app.ts')}`, name: 'app.ts' },
41
+ ]);
42
+ });
43
+
44
+ test('a quoted mention with spaces works, and duplicates collapse', async () => {
45
+ const cwd = await workspace();
46
+ await Bun.write(join(cwd, 'my file.md'), 'x');
47
+ expect(await promptFileLinks(cwd, '@"my file.md" and @"my file.md"')).toEqual([
48
+ { uri: `file://${join(cwd, 'my file.md')}`, name: 'my file.md' },
49
+ ]);
50
+ });
51
+
52
+ test('an escaped path is never a link', async () => {
53
+ const cwd = await workspace();
54
+ expect(await promptFileLinks(cwd, '@../../etc/hosts')).toEqual([]);
55
+ });
56
+
57
+ test('a missing file and an agent mention are dropped', async () => {
58
+ const cwd = await workspace();
59
+ expect(await promptFileLinks(cwd, '@missing.ts and @claude')).toEqual([]);
60
+ });
61
+
62
+ test('a file link precedes the text block', async () => {
63
+ const blocks = promptBlocks('read it', undefined, [{ uri: 'file:///x/a.ts', name: 'a.ts' }]);
64
+ expect(blocks).toEqual([
65
+ { type: 'resource_link', uri: 'file:///x/a.ts', name: 'a.ts' },
66
+ { type: 'text', text: 'read it' },
67
+ ]);
68
+ });
69
+ });
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The files a prompt mentions, as ACP `resource_link` blocks.
8
+ *
9
+ * `@path` is omp's own mention syntax and omp expands it into file contents. No
10
+ * other ACP agent does: they receive the raw text, so "look at @src/app.ts"
11
+ * reaches the model as a path with no bytes behind it. ACP's answer is a
12
+ * `resource_link` block — a URI the agent resolves through the `fs/*` surface
13
+ * this client already serves — and that is what this module builds.
14
+ *
15
+ * Only paths that exist and stay inside the session's workspace become links. A
16
+ * `@claude`/`@agent` mention resolves to nothing and is dropped, and so is an
17
+ * escaped path, because a link the agent cannot read is worse than a mention the
18
+ * agent ignores.
19
+ */
20
+
21
+ import path from 'node:path';
22
+
23
+ export interface PromptFileLink {
24
+ uri: string;
25
+ name: string;
26
+ }
27
+
28
+ /** `@path`, `@"path with spaces"`, `@'path'` — the three forms the composer writes. */
29
+ const MENTION_RE = /(^|[\s([{])@(?:"([^"]+)"|'([^']+)'|(\S+))/g;
30
+
31
+ /** Trailing prose punctuation that is never part of a path. */
32
+ const TRAILING_PUNCT_RE = /[.,;:!?)\]}]+$/;
33
+
34
+ /** Does `target` stay inside `root`? Pure string math; the link is only SENT,
35
+ * so a symlink that escapes costs nothing here — `fs/read_text_file` refuses
36
+ * it on the way back. */
37
+ function inside(root: string, target: string): boolean {
38
+ const relative = path.relative(root, target);
39
+ return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
40
+ }
41
+
42
+ /** Every mention that names a readable file inside the session workspace. */
43
+ export async function promptFileLinks(cwd: string, text: string): Promise<PromptFileLink[]> {
44
+ const root = path.resolve(cwd);
45
+ const seen = new Set<string>();
46
+ const links: PromptFileLink[] = [];
47
+ for (const match of text.matchAll(MENTION_RE)) {
48
+ const raw = (match[2] ?? match[3] ?? match[4] ?? '').replace(TRAILING_PUNCT_RE, '');
49
+ if (!raw || raw.includes('://')) continue;
50
+ const absolute = path.resolve(root, raw);
51
+ if (seen.has(absolute) || !inside(root, absolute)) continue;
52
+ seen.add(absolute);
53
+ const file = Bun.file(absolute);
54
+ if (!(await file.exists())) continue;
55
+ links.push({ uri: `file://${absolute}`, name: path.basename(absolute) });
56
+ }
57
+ return links;
58
+ }
@@ -16,7 +16,8 @@
16
16
  * approve.
17
17
  */
18
18
 
19
- import { acpOptionValues, type AcpConfigOption, type AcpSessionModeState } from '@/server/lib/harness/acp/protocol';
19
+ import { acpOptionValues, type AcpConfigOption, type AcpSessionModeState, type AcpSessionModels } from '@/server/lib/harness/acp/protocol';
20
+ import type { PromptFileLink } from '@/server/lib/harness/acp/prompt-files';
20
21
 
21
22
  /** The selector in a `configOptions` list for one ACP category. */
22
23
  export function configOption(options: AcpConfigOption[], category: string): AcpConfigOption | undefined {
@@ -66,8 +67,50 @@ function parseModelPair(value: string): { provider: string; modelId: string } |
66
67
  return null;
67
68
  }
68
69
 
70
+ /**
71
+ * The model an agent publishes as a `models` block, when it publishes no
72
+ * `model` config option.
73
+ *
74
+ * Measured on grok 1.0.77: `session/new` answers `models: {currentModelId,
75
+ * availableModels}` and no selector, so a client that reads only
76
+ * `configOptions` showed an empty picker and refused every `set_model`.
77
+ * `currentModelId` is the agent's own id, with no `provider/` prefix, so the
78
+ * harness stands in for the provider — the same fallback a bare selector value
79
+ * gets.
80
+ */
81
+ export function modelFromList(
82
+ models: AcpSessionModels | undefined,
83
+ fallbackProvider: string,
84
+ ): { provider: string; modelId: string } | null {
85
+ const current = models?.currentModelId;
86
+ if (typeof current !== 'string' || current.length === 0) return null;
87
+ return modelFromOption({ id: 'model', currentValue: current }, fallbackProvider);
88
+ }
89
+
90
+ /** The selector list a `models` block stands in for, in `configOptions` form, so
91
+ * every consumer (picker, `get_state`, `set_model`) reads ONE shape. */
92
+ export function modelsAsSelector(models: AcpSessionModels | undefined): AcpConfigOption | null {
93
+ const available = models?.availableModels;
94
+ if (!Array.isArray(available) || available.length === 0) return null;
95
+ return {
96
+ id: 'model',
97
+ name: 'Model',
98
+ category: 'model',
99
+ type: 'select',
100
+ ...(typeof models?.currentModelId === 'string' ? { currentValue: models.currentModelId } : {}),
101
+ options: available.flatMap((model) => {
102
+ if (!model || typeof model.modelId !== 'string' || !model.modelId) return [];
103
+ return [{
104
+ value: model.modelId,
105
+ ...(typeof model.name === 'string' && model.name ? { name: model.name } : {}),
106
+ ...(typeof model.description === 'string' && model.description ? { description: model.description } : {}),
107
+ }];
108
+ }),
109
+ } satisfies AcpConfigOption;
110
+ }
111
+
69
112
  /** A prompt in ACP content-block form. */
70
- export function promptBlocks(message: string, images: unknown): unknown[] {
113
+ export function promptBlocks(message: string, images: unknown, files: readonly PromptFileLink[] = []): unknown[] {
71
114
  const blocks: unknown[] = [];
72
115
  if (Array.isArray(images)) {
73
116
  for (const image of images) {
@@ -77,19 +120,15 @@ export function promptBlocks(message: string, images: unknown): unknown[] {
77
120
  blocks.push({ type: 'image', data: image.data, mimeType });
78
121
  }
79
122
  }
123
+ // The file links precede the text: an agent that reads them does so while it
124
+ // reads the prompt, and the text is the last block (a trailing link is what
125
+ // some adapters truncate).
126
+ for (const file of files) blocks.push({ type: 'resource_link', uri: file.uri, name: file.name });
80
127
  blocks.push({ type: 'text', text: message });
81
128
  return blocks;
82
129
  }
83
130
 
84
- /** What the approval dialog says, from the tool call the agent reported. */
85
- export function permissionText(toolCall: Record<string, unknown> | undefined): string {
86
- const rawInput = toolCall?.rawInput;
87
- if (rawInput && typeof rawInput === 'object' && 'command' in rawInput && typeof rawInput.command === 'string') {
88
- return `$ ${rawInput.command}`;
89
- }
90
- const title = toolCall?.title;
91
- return typeof title === 'string' ? title : 'This action needs your approval';
92
- }
131
+
93
132
 
94
133
  /** What a session may write into the agent's config selectors. */
95
134
  export interface ConfigSelections {
@@ -206,6 +206,16 @@ export interface AcpSessionNewResult {
206
206
  modes?: AcpSessionModeState;
207
207
  /** v2 setup responses may advertise the initial slash commands. */
208
208
  availableCommands?: AcpAgentCommand[];
209
+ /** The model list some agents publish INSTEAD of a `model` config option
210
+ * (measured on grok: `currentModelId` + `availableModels`). Read by the
211
+ * picker, and written back with `session/set_model`. */
212
+ models?: AcpSessionModels;
213
+ }
214
+
215
+ /** `session/new|load|resume`'s model list, for an agent that publishes one. */
216
+ export interface AcpSessionModels {
217
+ currentModelId?: string;
218
+ availableModels?: { modelId: string; name?: string; description?: string }[];
209
219
  }
210
220
 
211
221
  /** `session/new|load|resume`'s legacy mode state, and `session/set_mode`. */
@@ -224,7 +234,16 @@ export interface AcpInitializeResult {
224
234
  sessionCapabilities?: Record<string, unknown>;
225
235
  _meta?: Record<string, unknown>;
226
236
  };
227
- authMethods?: { id: string; name: string; description?: string; type?: string }[];
237
+ authMethods?: {
238
+ id: string;
239
+ name: string;
240
+ description?: string;
241
+ type?: string;
242
+ /** A `terminal` method's own arguments: the sign-in command to print. */
243
+ args?: string[];
244
+ /** Environment the sign-in command needs, as name/value pairs. */
245
+ env?: Record<string, string>;
246
+ }[];
228
247
  _meta?: Record<string, unknown>;
229
248
  }
230
249
 
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The approvals one ACP session is holding, as the `HarnessSession` contract
8
+ * exposes them.
9
+ *
10
+ * A `session/request_permission` blocks the agent's turn, so the queue IS state
11
+ * the client must be able to read after a reload and answer by id. Split from
12
+ * `session.ts` because none of it is session lifecycle: it is a read and two
13
+ * writes over `PendingPermissions`.
14
+ */
15
+
16
+ import { settlePermissionDialog } from '@/server/lib/harness/acp/session-config';
17
+ import type { PendingPermissions } from '@/server/lib/harness/acp/permissions';
18
+
19
+ /** The process slice answering a dialog needs. */
20
+ export interface AcpPermissionResponder {
21
+ respond(id: string | number, result: unknown): void;
22
+ }
23
+
24
+ /** Dialogs a reattaching client has to draw again. */
25
+ export function acpPendingDialogs(permissions: PendingPermissions): Record<string, unknown>[] {
26
+ // Widened for the shared `HarnessSession` contract, which predates the dialog
27
+ // shape; every field the client reads is present.
28
+ return permissions.pendingDialogs() as unknown as Record<string, unknown>[];
29
+ }
30
+
31
+ /** Answer one parked request with the option the operator clicked (or a yes/no
32
+ * decision when the frame carried no list). Returns the key it just granted,
33
+ * so the caller can persist a standing "always allow". */
34
+ export function answerAcpDialog(
35
+ permissions: PendingPermissions,
36
+ responder: AcpPermissionResponder,
37
+ dialogId: string,
38
+ confirmed: boolean,
39
+ optionId?: string,
40
+ ): string | null {
41
+ return settlePermissionDialog(permissions, responder, dialogId, {
42
+ confirmed,
43
+ ...(optionId ? { optionId } : {}),
44
+ });
45
+ }