@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.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +609 -600
- package/dist/client/static/js/{CsvGrid-3fr85032.js → CsvGrid-g67pk2zy.js} +1 -1
- package/dist/client/static/js/{DocxView-pqbp2fpd.js → DocxView-pyh6p2kb.js} +1 -1
- package/dist/client/static/js/{DrawioView-m0vecq1m.js → DrawioView-g48r6y2m.js} +1 -1
- package/dist/client/static/js/{ImageView-rbejbjwg.js → ImageView-rnzf5tve.js} +1 -1
- package/dist/client/static/js/{LayoutWrapper-mxfsqh57.js → LayoutWrapper-rekrgth6.js} +1 -1
- package/dist/client/static/js/{Modal-vnwg4xn3.js → Modal-edw446r8.js} +1 -1
- package/dist/client/static/js/{PdfView-wmg0vk2p.js → PdfView-6z3cgj37.js} +1 -1
- package/dist/client/static/js/{SessionsView-90z2t4qe.js → SessionsView-e84tjbcr.js} +1 -1
- package/dist/client/static/js/{SheetView-rg5gkcd7.js → SheetView-64076z1j.js} +1 -1
- package/dist/client/static/js/{SvgPreview-wpb7b0ez.js → SvgPreview-dmpgavgd.js} +1 -1
- package/dist/client/static/js/{abnfDiagram-O67JEVCF-4pxqt66j.js → abnfDiagram-O67JEVCF-nfz5z1vw.js} +1 -1
- package/dist/client/static/js/{architectureDiagram-NJMV4G6O-kwt1va5y.js → architectureDiagram-NJMV4G6O-jra2jyzw.js} +1 -1
- package/dist/client/static/js/{blockDiagram-BEXU5L5S-hbj5v7n7.js → blockDiagram-BEXU5L5S-3szktxam.js} +1 -1
- package/dist/client/static/js/{c4Diagram-YGBWAQC7-epfzh8dw.js → c4Diagram-YGBWAQC7-xe9vbppt.js} +1 -1
- package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-kbks4qgz.js → classDiagram-v2-NBCMYWYE-egzhj1xn.js} +1 -1
- package/dist/client/static/js/{cose-bilkent-JH36ORCC-dvdmckrf.js → cose-bilkent-JH36ORCC-dfrk1wnr.js} +1 -1
- package/dist/client/static/js/{cynefinDiagram-VND7K2PF-r084stj5.js → cynefinDiagram-VND7K2PF-xefpcmpg.js} +1 -1
- package/dist/client/static/js/{dagre-6A5THRUB-64qc51n1.js → dagre-6A5THRUB-vtzjnrt9.js} +1 -1
- package/dist/client/static/js/{diagram-22UHCM2B-70qtb1rm.js → diagram-22UHCM2B-4vvn790v.js} +1 -1
- package/dist/client/static/js/{diagram-3UASUU5V-dgkvnsme.js → diagram-3UASUU5V-tmht3bew.js} +1 -1
- package/dist/client/static/js/{diagram-ATOU4E4O-rnpsp26v.js → diagram-ATOU4E4O-p5wa5ztx.js} +1 -1
- package/dist/client/static/js/{diagram-CDSNMT55-26hthh60.js → diagram-CDSNMT55-8myesjfc.js} +1 -1
- package/dist/client/static/js/{diagram-MLGK6HIB-nc1s85r5.js → diagram-MLGK6HIB-9t3x2d5f.js} +1 -1
- package/dist/client/static/js/{diagram-MPIPVDR6-e4dckqhv.js → diagram-MPIPVDR6-8ahgnmhy.js} +1 -1
- package/dist/client/static/js/{dockerfile-rxtyyhr1.js → dockerfile-x8aa0543.js} +1 -1
- package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-3w9h8qk7.js → ebnfDiagram-ZINNZB2B-5semw111.js} +1 -1
- package/dist/client/static/js/{elk-276RUBZZ-httpkyb1.js → elk-276RUBZZ-jmhs58ww.js} +1 -1
- package/dist/client/static/js/{erDiagram-OPXOYQCR-3qhvf7se.js → erDiagram-OPXOYQCR-31wvbpdr.js} +1 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-36ygrbvm.js +1 -0
- package/dist/client/static/js/{ganttDiagram-FUAMR5RP-t53m50e5.js → ganttDiagram-FUAMR5RP-c2dycjrf.js} +1 -1
- package/dist/client/static/js/{gitGraphDiagram-X574FWY7-b5wn9eht.js → gitGraphDiagram-X574FWY7-y4k4pdd8.js} +1 -1
- package/dist/client/static/js/{index-kc3c2gzb.js → index-0q2qfcjn.js} +1 -1
- package/dist/client/static/js/{index-7zc1z9z9.js → index-2b46dzw8.js} +1 -1
- package/dist/client/static/js/{index-dg3b0mfk.js → index-2cbnjc32.js} +1 -1
- package/dist/client/static/js/{index-q1gwgmxt.js → index-3588r3wg.js} +1 -1
- package/dist/client/static/js/{index-8y51kgan.js → index-48gh56ka.js} +1 -1
- package/dist/client/static/js/{index-2q23dwrs.js → index-48pb18zj.js} +1 -1
- package/dist/client/static/js/{index-ksph3kpr.js → index-4rv388z7.js} +1 -1
- package/dist/client/static/js/{index-qzw4jnnv.js → index-52xmdeh2.js} +1 -1
- package/dist/client/static/js/{index-kccp6tgd.js → index-6fpd55cq.js} +1 -1
- package/dist/client/static/js/{index-d8r84zjd.js → index-8kqepehd.js} +2 -2
- package/dist/client/static/js/{index-fgyenbv8.js → index-aar68x31.js} +1 -1
- package/dist/client/static/js/{index-r11bbnek.js → index-cgzw43bc.js} +2 -2
- package/dist/client/static/js/{index-g3a9j9hf.js → index-cje5gg45.js} +1 -1
- package/dist/client/static/js/{index-rv4qs3wm.js → index-cjhvtzdd.js} +1 -1
- package/dist/client/static/js/{index-wmv3crye.js → index-dkwhs38j.js} +1 -1
- package/dist/client/static/js/{index-vmgzhp41.js → index-efra065v.js} +1 -1
- package/dist/client/static/js/{index-zqthmaxq.js → index-f77c3ag0.js} +147 -146
- package/dist/client/static/js/{index-7z9tz4ze.js → index-f7djda1g.js} +1 -1
- package/dist/client/static/js/{index-egd0vfey.js → index-fbcg8y95.js} +1 -1
- package/dist/client/static/js/{index-1dwdgp27.js → index-g3shdymf.js} +1 -1
- package/dist/client/static/js/{index-axszsg7a.js → index-h5n1btqy.js} +1 -1
- package/dist/client/static/js/{index-tzbzehqd.js → index-kc5znr75.js} +2 -2
- package/dist/client/static/js/{index-tnv3dryk.js → index-m1n4v0z7.js} +1 -1
- package/dist/client/static/js/{index-g4rsmakg.js → index-m94f4ngb.js} +1 -1
- package/dist/client/static/js/{index-4banz7gr.js → index-nt7nhchn.js} +1 -1
- package/dist/client/static/js/{index-f4fqvct6.js → index-pt8440xh.js} +1 -1
- package/dist/client/static/js/{index-jvs2fvqz.js → index-rn8w29pv.js} +1 -1
- package/dist/client/static/js/{index-kmzd0adv.js → index-s00j9042.js} +1 -1
- package/dist/client/static/js/{index-dkqgmacr.js → index-s7rfbydk.js} +1 -1
- package/dist/client/static/js/{index-j60gtvw8.js → index-sg6sz3g8.js} +1 -1
- package/dist/client/static/js/{index-k9ws464d.js → index-vyw4tbn8.js} +1 -1
- package/dist/client/static/js/{index-enb6chty.js → index-w5rw8f7w.js} +1 -1
- package/dist/client/static/js/{index-gwqb7m8g.js → index-x6v37h3j.js} +1 -1
- package/dist/client/static/js/{infoDiagram-VRGFBTTK-qv7438m3.js → infoDiagram-VRGFBTTK-z3pqx7w8.js} +1 -1
- package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-p1w6zg5y.js → ishikawaDiagram-OU5B5YK6-f5v6z8yr.js} +1 -1
- package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-ywk6xqxr.js → journeyDiagram-ZHPQQLJL-js1yxatk.js} +1 -1
- package/dist/client/static/js/{kanban-definition-PNTS6WVX-gtrmhggc.js → kanban-definition-PNTS6WVX-m0a6069c.js} +1 -1
- package/dist/client/static/js/{mermaid.core-5s24b4hh.js → mermaid.core-6xvbnm63.js} +2 -2
- package/dist/client/static/js/{mindmap-definition-NLK3R4M7-3wx7abqn.js → mindmap-definition-NLK3R4M7-a9f9yzc0.js} +1 -1
- package/dist/client/static/js/one-dark-pro-hteqzfb0.js +1 -0
- package/dist/client/static/js/one-light-dapnh0rs.js +1 -0
- package/dist/client/static/js/{pegDiagram-GJSIUBJH-yvyqnjya.js → pegDiagram-GJSIUBJH-4v4pf1h1.js} +1 -1
- package/dist/client/static/js/{pieDiagram-5QR66LMP-26x6pj38.js → pieDiagram-5QR66LMP-a54yrmfm.js} +1 -1
- package/dist/client/static/js/{quadrantDiagram-O4NWA36T-qhe8h0j9.js → quadrantDiagram-O4NWA36T-1twhvnp2.js} +1 -1
- package/dist/client/static/js/{railroadDiagram-XR7U4H2S-dwy3k2jx.js → railroadDiagram-XR7U4H2S-83tqfdcy.js} +1 -1
- package/dist/client/static/js/{requirementDiagram-PLB6GJNP-hcmgfesg.js → requirementDiagram-PLB6GJNP-73e3pzw6.js} +1 -1
- package/dist/client/static/js/{rust-bmb4ee5w.js → rust-jds4e4r7.js} +1 -1
- package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-s6d3k4zs.js → sankeyDiagram-IPEJSGJF-1bzwj6sb.js} +1 -1
- package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-0fcmzgdy.js → sequenceDiagram-PO4LG4MO-yh3h988k.js} +1 -1
- package/dist/client/static/js/{sizeCapture-INFHLROL-t8fcm7rq.js → sizeCapture-INFHLROL-1n121yp6.js} +1 -1
- package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-jr80hfeg.js → stateDiagram-v2-GCMORJYK-0tdrzn06.js} +1 -1
- package/dist/client/static/js/{swimlanes-2SLR337P-x1ay6w39.js → swimlanes-2SLR337P-77n1ttdw.js} +1 -1
- package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-xj123xrp.js → swimlanesDiagram-TC7HE7FX-akjqm31r.js} +1 -1
- package/dist/client/static/js/{timeline-definition-EJHVYXUP-qz0g6msb.js → timeline-definition-EJHVYXUP-b6r0k3e8.js} +1 -1
- package/dist/client/static/js/{usecaseDiagram-POWQR4AR-sxzrv8ht.js → usecaseDiagram-POWQR4AR-efq58m3m.js} +1 -1
- package/dist/client/static/js/{vennDiagram-UO4OBE2U-qsqgnjcv.js → vennDiagram-UO4OBE2U-ad4gvd5r.js} +1 -1
- package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-rvwxn458.js → wardleyDiagram-VNRHLVJA-v89tys2p.js} +1 -1
- package/dist/client/static/js/{xychartDiagram-PMCCYNJV-nb4w7rcg.js → xychartDiagram-PMCCYNJV-xtgzmknw.js} +1 -1
- package/package.json +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +21 -9
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/TaskResult.tsx +18 -4
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/task-rows.ts +47 -0
- package/src/client/hooks/chat/omp/index.ts +2 -6
- package/src/server/lib/changes/capture-client-write.server.ts +45 -0
- package/src/server/lib/changes/capture.server.ts +20 -5
- package/src/server/lib/db/schema.ts +3 -0
- package/src/server/lib/harness/acp/auth.test.ts +69 -0
- package/src/server/lib/harness/acp/auth.ts +71 -0
- package/src/server/lib/harness/acp/background-replay.test.ts +139 -0
- package/src/server/lib/harness/acp/background-replay.ts +87 -0
- package/src/server/lib/harness/acp/background-work.ts +50 -33
- package/src/server/lib/harness/acp/calls.test.ts +68 -0
- package/src/server/lib/harness/acp/calls.ts +13 -0
- package/src/server/lib/harness/acp/client-capabilities.ts +5 -2
- package/src/server/lib/harness/acp/client-fs.test.ts +13 -0
- package/src/server/lib/harness/acp/client-fs.ts +16 -2
- package/src/server/lib/harness/acp/client.ts +22 -23
- package/src/server/lib/harness/acp/commands.test.ts +19 -0
- package/src/server/lib/harness/acp/commands.ts +26 -8
- package/src/server/lib/harness/acp/frames.ts +16 -1
- package/src/server/lib/harness/acp/grants.server.ts +75 -0
- package/src/server/lib/harness/acp/grants.test.ts +65 -0
- package/src/server/lib/harness/acp/grants.ts +79 -0
- package/src/server/lib/harness/acp/permissions.test.ts +9 -0
- package/src/server/lib/harness/acp/permissions.ts +56 -36
- package/src/server/lib/harness/acp/prompt-files.test.ts +69 -0
- package/src/server/lib/harness/acp/prompt-files.ts +58 -0
- package/src/server/lib/harness/acp/prompt.ts +50 -11
- package/src/server/lib/harness/acp/protocol.ts +20 -1
- package/src/server/lib/harness/acp/session-approvals.ts +45 -0
- package/src/server/lib/harness/acp/session-config-view.ts +81 -0
- package/src/server/lib/harness/acp/session-config.ts +48 -9
- package/src/server/lib/harness/acp/session-handshake.test.ts +71 -2
- package/src/server/lib/harness/acp/session-handshake.ts +128 -53
- package/src/server/lib/harness/acp/session-intake.test.ts +93 -0
- package/src/server/lib/harness/acp/session-intake.ts +75 -0
- package/src/server/lib/harness/acp/session-lifecycle.ts +50 -0
- package/src/server/lib/harness/acp/session-lost.test.ts +44 -0
- package/src/server/lib/harness/acp/session-lost.ts +34 -0
- package/src/server/lib/harness/acp/session-notify.ts +47 -0
- package/src/server/lib/harness/acp/session-observers.test.ts +4 -4
- package/src/server/lib/harness/acp/session-permissions.test.ts +64 -0
- package/src/server/lib/harness/acp/session-permissions.ts +9 -4
- package/src/server/lib/harness/acp/session-requests.ts +6 -0
- package/src/server/lib/harness/acp/session-roots.server.ts +47 -0
- package/src/server/lib/harness/acp/session-roots.test.ts +31 -0
- package/src/server/lib/harness/acp/session-start.ts +7 -0
- package/src/server/lib/harness/acp/session-turns.ts +11 -0
- package/src/server/lib/harness/acp/session-wiring.ts +100 -0
- package/src/server/lib/harness/acp/session.test-util.ts +34 -2
- package/src/server/lib/harness/acp/session.test.ts +10 -10
- package/src/server/lib/harness/acp/session.ts +146 -144
- package/src/server/lib/harness/acp/tool-calls.ts +27 -15
- package/src/server/lib/harness/acp/tool-identity.test.ts +136 -0
- package/src/server/lib/harness/acp/tool-identity.ts +121 -0
- package/src/server/lib/harness/acp/turn-cancel.test.ts +79 -0
- package/src/server/lib/harness/acp/turn-cancel.ts +61 -0
- package/src/server/lib/harness/acp/turn-dispatch.test.ts +103 -0
- package/src/server/lib/harness/acp/turn-dispatch.ts +61 -0
- package/src/server/lib/harness/acp/turn-queue.ts +43 -0
- package/src/server/lib/harness/acp/turn-verdict.ts +102 -0
- package/src/server/lib/harness/acp/turn.ts +86 -88
- package/src/server/lib/harness/acp/v2.test.ts +9 -0
- package/src/server/lib/harness/acp/v2.ts +13 -0
- package/src/server/lib/harness/acp/verbs.ts +35 -4
- package/src/server/lib/omp/session/delete.server.ts +3 -0
- package/src/shared/types/omp/agent.ts +14 -5
- package/dist/client/static/js/flowDiagram-KWPJA3E3-1jat076e.js +0 -1
- package/dist/client/static/js/one-dark-pro-3vya9z02.js +0 -1
- package/dist/client/static/js/one-light-1yrwn9my.js +0 -1
|
@@ -20,25 +20,51 @@
|
|
|
20
20
|
* collected instead of folded (they repeat the whole chat), and the text past
|
|
21
21
|
* the answer the operator already has is emitted as the agent's continuation.
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
* **Text is not the only evidence.** Measured on agy 1.5.3 against a real chat
|
|
24
|
+
* (155 s of work): its replay carried `read_file` and a failed `run_command`
|
|
25
|
+
* AFTER the holding sentence and **no** new `agent_message_chunk` at all. A
|
|
26
|
+
* probe that waited for prose therefore sat on a finished run until the ten
|
|
27
|
+
* minute ceiling and the operator saw nothing. New TOOL calls are progress too,
|
|
28
|
+
* so they are surfaced as a notice — and each one that lands means the child is
|
|
29
|
+
* still working, which is what re-arms the ceiling.
|
|
30
|
+
*
|
|
31
|
+
* The probe backs off (2s → 30s) and gives up after ten minutes past the last
|
|
32
|
+
* evidence of work; it never substitutes a failure for an answer it did not see.
|
|
25
33
|
*/
|
|
26
34
|
|
|
27
|
-
import {
|
|
35
|
+
import { collectReplayFrame, newToolNotice, type ReplaySegment } from '@/server/lib/harness/acp/background-replay';
|
|
28
36
|
import { stampMessageModel } from '@/server/lib/harness/acp/session-config';
|
|
29
37
|
import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
|
|
30
38
|
import { extractTextFromContent } from '@/shared/lib/omp/session/mapper';
|
|
31
39
|
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
32
40
|
|
|
33
|
-
/** Tool names that hand work to a process the turn does not await.
|
|
41
|
+
/** Tool names that hand work to a process the turn does not await.
|
|
42
|
+
*
|
|
43
|
+
* `spawn_subagent` is grok's spelling and arrives only as `_meta["x.ai/tool"]`;
|
|
44
|
+
* `resolveToolIdentity` lifts it into the card's `name`, which is why this list
|
|
45
|
+
* still matches. Cursor's `task` is deliberately absent: its adapter runs the
|
|
46
|
+
* child inside the call and answers before `end_turn`, so there is nothing to
|
|
47
|
+
* probe for. */
|
|
34
48
|
const BACKGROUND_TOOLS: Record<string, true> = {
|
|
35
49
|
invoke_subagent: true,
|
|
36
50
|
spawn_subagent: true,
|
|
37
51
|
};
|
|
38
52
|
|
|
53
|
+
/** Whether a card names a call that outlives the turn. Reads the resolved
|
|
54
|
+
* `name`, so an adapter that hides it in `_meta` is detected too. */
|
|
55
|
+
export function isBackgroundToolName(name: string | undefined): boolean {
|
|
56
|
+
return typeof name === 'string' && BACKGROUND_TOOLS[name.toLowerCase()] === true;
|
|
57
|
+
}
|
|
58
|
+
|
|
39
59
|
export const BACKGROUND_FIRST_DELAY_MS = 2_000;
|
|
40
60
|
export const BACKGROUND_MAX_DELAY_MS = 30_000;
|
|
41
61
|
export const BACKGROUND_TIMEOUT_MS = 10 * 60_000;
|
|
62
|
+
/** The absolute ceiling, independent of how often new work re-arms the quiet
|
|
63
|
+
* window. A probe holds the session out of the idle reclaim (`resetIdle`), so
|
|
64
|
+
* an agent that reports a tool every minute must not keep it alive forever.
|
|
65
|
+
* One hour is the repo's own precedent for "silence means a wedged turn"
|
|
66
|
+
* (`turn-silence.ts`). */
|
|
67
|
+
export const BACKGROUND_MAX_LIFETIME_MS = 60 * 60_000;
|
|
42
68
|
export const BACKGROUND_LOAD_TIMEOUT_MS = 120_000;
|
|
43
69
|
|
|
44
70
|
/** Did this turn hand work to a background worker? Read from the closed
|
|
@@ -50,7 +76,7 @@ export function spawnsBackgroundWork(message: unknown): boolean {
|
|
|
50
76
|
return content.some((block) => {
|
|
51
77
|
if (!block || typeof block !== 'object') return false;
|
|
52
78
|
if (!('type' in block) || block.type !== 'toolCall') return false;
|
|
53
|
-
return 'name' in block && typeof block.name === 'string'
|
|
79
|
+
return 'name' in block && isBackgroundToolName(typeof block.name === 'string' ? block.name : undefined);
|
|
54
80
|
});
|
|
55
81
|
}
|
|
56
82
|
|
|
@@ -134,19 +160,6 @@ export interface AcpBackgroundProbeOptions {
|
|
|
134
160
|
cancel?: (handle: unknown) => void;
|
|
135
161
|
}
|
|
136
162
|
|
|
137
|
-
/** Replay chunks collected since the last `user_message_chunk`. */
|
|
138
|
-
interface ReplaySegment {
|
|
139
|
-
text: string;
|
|
140
|
-
sawUser: boolean;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* The load probe for one background turn.
|
|
145
|
-
*
|
|
146
|
-
* `consume` must be called for every notification while a probe is in flight:
|
|
147
|
-
* the replay repeats the whole transcript, and folding it into the live chat
|
|
148
|
-
* would duplicate history.
|
|
149
|
-
*/
|
|
150
163
|
export class AcpBackgroundProbe {
|
|
151
164
|
private readonly load: () => Promise<unknown>;
|
|
152
165
|
private readonly resetIdle: () => void;
|
|
@@ -164,12 +177,16 @@ export class AcpBackgroundProbe {
|
|
|
164
177
|
private pendingNotice: string | null = null;
|
|
165
178
|
private timer: unknown = null;
|
|
166
179
|
private deadline = 0;
|
|
180
|
+
/** When this probe began, for the absolute ceiling. */
|
|
181
|
+
private beganAt = 0;
|
|
167
182
|
private delay: number;
|
|
168
183
|
private stopped = true;
|
|
169
184
|
private inFlight = false;
|
|
170
185
|
/** Consecutive `session/load` failures; a lost agent is not retried forever. */
|
|
171
186
|
private failures = 0;
|
|
172
187
|
private queued: string | null = null;
|
|
188
|
+
/** Tool calls already reported for this probe, so a notice is not repeated. */
|
|
189
|
+
private reportedTools = new Set<string>();
|
|
173
190
|
|
|
174
191
|
constructor(options: AcpBackgroundProbeOptions) {
|
|
175
192
|
this.load = options.load;
|
|
@@ -188,6 +205,7 @@ export class AcpBackgroundProbe {
|
|
|
188
205
|
start(baseline: string): void {
|
|
189
206
|
this.baseline = baseline.trim();
|
|
190
207
|
this.pendingNotice = null;
|
|
208
|
+
this.reportedTools = new Set();
|
|
191
209
|
// A previous probe's load can still be running. Queue this turn instead of
|
|
192
210
|
// interleaving two replays; the queued baseline starts when that load ends.
|
|
193
211
|
if (this.inFlight) {
|
|
@@ -195,6 +213,7 @@ export class AcpBackgroundProbe {
|
|
|
195
213
|
return;
|
|
196
214
|
}
|
|
197
215
|
this.stopped = false;
|
|
216
|
+
this.beganAt = this.now();
|
|
198
217
|
this.deadline = this.now() + this.timeoutMs;
|
|
199
218
|
this.delay = this.firstDelayMs;
|
|
200
219
|
this.failures = 0;
|
|
@@ -218,20 +237,7 @@ export class AcpBackgroundProbe {
|
|
|
218
237
|
*/
|
|
219
238
|
consume(method: string, params: Record<string, unknown>): boolean {
|
|
220
239
|
if (!this.collecting || method !== 'session/update') return false;
|
|
221
|
-
|
|
222
|
-
if (!update || typeof update !== 'object') return true;
|
|
223
|
-
const record = update as Record<string, unknown>;
|
|
224
|
-
const kind = typeof record.sessionUpdate === 'string' ? record.sessionUpdate : '';
|
|
225
|
-
if (kind === 'user_message_chunk') {
|
|
226
|
-
// A new user turn starts a new assistant segment. Everything before it is
|
|
227
|
-
// history this probe does not need.
|
|
228
|
-
this.collecting.text = '';
|
|
229
|
-
this.collecting.sawUser = true;
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
if (kind === 'agent_message_chunk') {
|
|
233
|
-
this.collecting.text += acpContentText(record.content);
|
|
234
|
-
}
|
|
240
|
+
collectReplayFrame(this.collecting, params.update);
|
|
235
241
|
return true;
|
|
236
242
|
}
|
|
237
243
|
|
|
@@ -246,7 +252,7 @@ export class AcpBackgroundProbe {
|
|
|
246
252
|
private async probe(): Promise<void> {
|
|
247
253
|
if (this.stopped || this.inFlight) return;
|
|
248
254
|
this.inFlight = true;
|
|
249
|
-
this.collecting = { text: '', sawUser: false };
|
|
255
|
+
this.collecting = { text: '', sawUser: false, tools: [] };
|
|
250
256
|
this.resetIdle();
|
|
251
257
|
let failed = false;
|
|
252
258
|
try {
|
|
@@ -277,6 +283,7 @@ export class AcpBackgroundProbe {
|
|
|
277
283
|
}
|
|
278
284
|
} else {
|
|
279
285
|
this.failures = 0;
|
|
286
|
+
let toolNotice: string | null = null;
|
|
280
287
|
// A replay that never reached a user chunk cannot be placed in the
|
|
281
288
|
// conversation, so it is not a notice.
|
|
282
289
|
const notice = segment?.sawUser ? backgroundNotice(this.baseline, segment.text) : null;
|
|
@@ -293,6 +300,16 @@ export class AcpBackgroundProbe {
|
|
|
293
300
|
this.delay = this.firstDelayMs;
|
|
294
301
|
this.arm();
|
|
295
302
|
}
|
|
303
|
+
} else if (segment?.sawUser && (toolNotice = newToolNotice(segment, this.reportedTools)) !== null) {
|
|
304
|
+
// No new prose, but the child RAN something: deliver that and keep
|
|
305
|
+
// watching — each new tool call is evidence the run is alive, so the
|
|
306
|
+
// ceiling is re-armed instead of expiring under it.
|
|
307
|
+
this.emitNotice(toolNotice);
|
|
308
|
+
// New work re-arms the QUIET window, never the absolute ceiling.
|
|
309
|
+
this.deadline = this.now() + this.timeoutMs;
|
|
310
|
+
this.delay = Math.min(this.delay * 2, this.maxDelayMs);
|
|
311
|
+
if (this.now() - this.beganAt >= BACKGROUND_MAX_LIFETIME_MS) this.stopped = true;
|
|
312
|
+
else this.arm();
|
|
296
313
|
} else if (this.now() >= this.deadline) {
|
|
297
314
|
this.stopped = true;
|
|
298
315
|
} else {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A request the client gives up on must be withdrawn from the AGENT.
|
|
8
|
+
*
|
|
9
|
+
* The table's own timeout only freed the pending slot; the agent kept working on
|
|
10
|
+
* a request whose answer nobody would read, and its next prompt then arrived
|
|
11
|
+
* while it was still busy. ACP's `$/cancel_request` is the spec's words for
|
|
12
|
+
* "forget this", and the transport sends it on the request's own id.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test, vi } from 'bun:test';
|
|
16
|
+
import { PendingCalls } from '@/server/lib/harness/acp/calls';
|
|
17
|
+
|
|
18
|
+
describe('PendingCalls timeouts', () => {
|
|
19
|
+
test('the deadline notifies the agent and rejects the caller', async () => {
|
|
20
|
+
vi.useFakeTimers();
|
|
21
|
+
try {
|
|
22
|
+
const withdrawn: unknown[] = [];
|
|
23
|
+
const pending = new PendingCalls({
|
|
24
|
+
onTimeout: (id, method) => {
|
|
25
|
+
withdrawn.push([id, method]);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const call = pending.begin('k1', 'session/set_config_option', { sessionId: 's' }, 5);
|
|
29
|
+
vi.advanceTimersByTime(10);
|
|
30
|
+
await expect(call).rejects.toThrow('timed out after 5ms');
|
|
31
|
+
expect(withdrawn).toEqual([['k1', 'session/set_config_option']]);
|
|
32
|
+
} finally {
|
|
33
|
+
vi.useRealTimers();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('a settled request is never reported as timed out', async () => {
|
|
38
|
+
vi.useFakeTimers();
|
|
39
|
+
try {
|
|
40
|
+
const withdrawn: unknown[] = [];
|
|
41
|
+
const pending = new PendingCalls({
|
|
42
|
+
onTimeout: (id) => {
|
|
43
|
+
withdrawn.push(id);
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
const call = pending.begin('k2', 'session/set_mode', {}, 5);
|
|
47
|
+
expect(pending.settle({ jsonrpc: '2.0', id: 'k2', result: {} })).toBe(true);
|
|
48
|
+
await expect(call).resolves.toEqual({});
|
|
49
|
+
vi.advanceTimersByTime(50);
|
|
50
|
+
expect(withdrawn).toEqual([]);
|
|
51
|
+
} finally {
|
|
52
|
+
vi.useRealTimers();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('a prompt has no timer at all', async () => {
|
|
57
|
+
const withdrawn: unknown[] = [];
|
|
58
|
+
const pending = new PendingCalls({
|
|
59
|
+
onTimeout: (id) => {
|
|
60
|
+
withdrawn.push(id);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
const call = pending.begin('k3', 'session/prompt', { sessionId: 's' }, 0);
|
|
64
|
+
pending.abandonPrompt('s');
|
|
65
|
+
await expect(call).resolves.toEqual({ stopReason: 'cancelled' });
|
|
66
|
+
expect(withdrawn).toEqual([]);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -18,6 +18,13 @@
|
|
|
18
18
|
|
|
19
19
|
import type { AcpId, AcpResponse } from '@/server/lib/harness/acp/protocol';
|
|
20
20
|
|
|
21
|
+
/** What the table does when a request's own deadline expires. A timeout is the
|
|
22
|
+
* client's verdict, not the agent's: without telling it, the agent keeps
|
|
23
|
+
* working on a request nobody will read. */
|
|
24
|
+
export interface PendingCallsOptions {
|
|
25
|
+
onTimeout?: (id: AcpId, method: string, params: Record<string, unknown>) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
/** A JSON-RPC error answer, with the code the spec defines for it. */
|
|
22
29
|
export class AcpRequestError extends Error {
|
|
23
30
|
constructor(
|
|
@@ -43,6 +50,8 @@ export interface Pending {
|
|
|
43
50
|
export class PendingCalls {
|
|
44
51
|
private readonly map = new Map<AcpId, Pending>();
|
|
45
52
|
|
|
53
|
+
constructor(private readonly options: PendingCallsOptions = {}) {}
|
|
54
|
+
|
|
46
55
|
/** Track one call. `budgetMs` of 0 means "no timer" — a whole turn. */
|
|
47
56
|
begin<T>(id: AcpId, method: string, params: unknown, budgetMs: number): Promise<T> {
|
|
48
57
|
const { promise, resolve, reject } = Promise.withResolvers<T>();
|
|
@@ -56,6 +65,10 @@ export class PendingCalls {
|
|
|
56
65
|
entry.timer = setTimeout(() => {
|
|
57
66
|
if (this.map.get(id) !== entry) return;
|
|
58
67
|
this.map.delete(id);
|
|
68
|
+
// ACP's `$/cancel_request` is how a client withdraws a request it no
|
|
69
|
+
// longer wants. Keeping the pool consistent is not enough — the agent
|
|
70
|
+
// would run the abandoned request to completion.
|
|
71
|
+
this.options.onTimeout?.(id, method, entry.params);
|
|
59
72
|
reject(new Error(`ACP ${method} timed out after ${budgetMs}ms`));
|
|
60
73
|
}, budgetMs);
|
|
61
74
|
entry.timer.unref?.();
|
|
@@ -33,11 +33,14 @@
|
|
|
33
33
|
* - `auth.terminal` — Kabmo does not reproduce the agent's launch line in an
|
|
34
34
|
* interactive terminal for login.
|
|
35
35
|
* - `session.configOptions.boolean` — the selector UI is select-only.
|
|
36
|
-
*
|
|
36
|
+
*
|
|
37
|
+
* `session.compaction` IS advertised: the frame mapper turns a compaction into a
|
|
38
|
+
* notice, which is the surface the timeline already has, so an agent may report
|
|
39
|
+
* one instead of falling back to modelling it as conversation text.
|
|
37
40
|
*/
|
|
38
41
|
export const KABMO_CLIENT_CAPABILITIES = {
|
|
39
42
|
fs: { readTextFile: true, writeTextFile: true },
|
|
40
|
-
session: { notices: {} },
|
|
43
|
+
session: { notices: {}, compaction: {} },
|
|
41
44
|
} as const;
|
|
42
45
|
|
|
43
46
|
/** The latest protocol major this client sends; it also speaks v1. */
|
|
@@ -133,3 +133,16 @@ describe('fs/write_text_file', () => {
|
|
|
133
133
|
expect(answer).toMatchObject({ answered: false, code: ACP_ERROR.invalidParams });
|
|
134
134
|
});
|
|
135
135
|
});
|
|
136
|
+
|
|
137
|
+
describe('ACP fs/write_text_file reporting', () => {
|
|
138
|
+
test('the write carries both sides so the change journal can record it', async () => {
|
|
139
|
+
const base = await workspace();
|
|
140
|
+
const target = join(base.cwd, 'note.txt');
|
|
141
|
+
await Bun.write(target, 'old');
|
|
142
|
+
const events: Array<Record<string, unknown> & { type: string }> = [];
|
|
143
|
+
const host: AcpFsHost = { ...base, emit: (event) => events.push(event) };
|
|
144
|
+
const answer = await handleAcpFsRequest(host, 'fs/write_text_file', { sessionId: 's1', path: target, content: 'new' });
|
|
145
|
+
expect(answer).toEqual({ answered: true, result: {} });
|
|
146
|
+
expect(events).toEqual([{ type: 'fs_write', path: target, before: 'old', after: 'new' }]);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -32,6 +32,10 @@ import { ACP_ERROR } from '@/server/lib/harness/acp/protocol';
|
|
|
32
32
|
export interface AcpFsHost {
|
|
33
33
|
readonly cwd: string;
|
|
34
34
|
readonly sessionId: string;
|
|
35
|
+
/** Publish the write so the timeline's change journal records it. A write the
|
|
36
|
+
* AGENT performed through this client runs no tool of its own: without this
|
|
37
|
+
* frame its file change never reached the journal or the diff panel. */
|
|
38
|
+
emit?(event: Record<string, unknown> & { type: string }): void;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
/** Structurally the `answered: false` branch of the client-request answer. */
|
|
@@ -66,7 +70,7 @@ export async function handleAcpFsRequest(
|
|
|
66
70
|
return refuse(ACP_ERROR.invalidParams, `Path is outside this session's workspace: ${target}`);
|
|
67
71
|
}
|
|
68
72
|
|
|
69
|
-
return method === 'fs/read_text_file' ? read(target, params) : write(target, params);
|
|
73
|
+
return method === 'fs/read_text_file' ? read(target, params) : write(host, target, params);
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
async function read(target: string, params: Record<string, unknown>): Promise<AcpFsAnswer> {
|
|
@@ -94,15 +98,25 @@ async function read(target: string, params: Record<string, unknown>): Promise<Ac
|
|
|
94
98
|
return { answered: true, result: { content: lines.slice(start, end).join('\n') } };
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
async function write(target: string, params: Record<string, unknown>): Promise<AcpFsAnswer> {
|
|
101
|
+
async function write(host: AcpFsHost, target: string, params: Record<string, unknown>): Promise<AcpFsAnswer> {
|
|
98
102
|
const content = params.content;
|
|
99
103
|
if (typeof content !== 'string') {
|
|
100
104
|
return refuse(ACP_ERROR.invalidParams, 'content is required');
|
|
101
105
|
}
|
|
106
|
+
// The before side travels with the event: the journal's start-frame snapshot
|
|
107
|
+
// never ran, and reading the file again after this write would report no
|
|
108
|
+
// change at all.
|
|
109
|
+
const before = await Bun.file(target).text().catch(() => null);
|
|
102
110
|
try {
|
|
103
111
|
// `Bun.write` creates missing parent directories, which is the "MUST create
|
|
104
112
|
// the file if it doesn't exist" half of the method.
|
|
105
113
|
await Bun.write(target, content);
|
|
114
|
+
host.emit?.({
|
|
115
|
+
type: 'fs_write',
|
|
116
|
+
path: target,
|
|
117
|
+
...(before !== null ? { before } : {}),
|
|
118
|
+
after: content,
|
|
119
|
+
});
|
|
106
120
|
return { answered: true, result: {} };
|
|
107
121
|
} catch (error) {
|
|
108
122
|
return fileError(target, error);
|
|
@@ -73,7 +73,7 @@ const DEFAULT_REQUEST_TIMEOUT_MS = 60_000;
|
|
|
73
73
|
|
|
74
74
|
export class AcpProcess {
|
|
75
75
|
private readonly stdio: AgentStdio;
|
|
76
|
-
private readonly pending
|
|
76
|
+
private readonly pending: PendingCalls;
|
|
77
77
|
private readonly options: AcpClientOptions;
|
|
78
78
|
private nextId = 1;
|
|
79
79
|
private exited = false;
|
|
@@ -94,6 +94,11 @@ export class AcpProcess {
|
|
|
94
94
|
|
|
95
95
|
constructor(options: AcpClientOptions) {
|
|
96
96
|
this.options = options;
|
|
97
|
+
// A timed-out request is withdrawn from the AGENT too, not only from this
|
|
98
|
+
// table: `$/cancel_request` is the spec's way to say "stop working on it".
|
|
99
|
+
this.pending = new PendingCalls({
|
|
100
|
+
onTimeout: (id) => this.notify('$/cancel_request', { requestId: id }),
|
|
101
|
+
});
|
|
97
102
|
this.sinks = options;
|
|
98
103
|
this.stdio = new AgentStdio(
|
|
99
104
|
{
|
|
@@ -142,14 +147,8 @@ export class AcpProcess {
|
|
|
142
147
|
return this.init;
|
|
143
148
|
}
|
|
144
149
|
|
|
145
|
-
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* A prewarmed process is spawned before the session that will own it exists,
|
|
149
|
-
* so its notifications and agent→client requests have nowhere to go until the
|
|
150
|
-
* claim. Attaching here is what makes the warm child indistinguishable from a
|
|
151
|
-
* cold one for the rest of its life.
|
|
152
|
-
*/
|
|
150
|
+
/** Re-bind the frame sinks: a prewarmed process outlives the session that
|
|
151
|
+
* adopts it, so its handlers are attached at the claim. */
|
|
153
152
|
attachSinks(sinks: Pick<AcpClientOptions, 'onNotification' | 'onClientRequest' | 'onExit' | 'onStderr'>): void {
|
|
154
153
|
this.sinks = sinks;
|
|
155
154
|
}
|
|
@@ -159,8 +158,8 @@ export class AcpProcess {
|
|
|
159
158
|
}
|
|
160
159
|
|
|
161
160
|
// ── protocol verbs ───────────────────────────────────────────────────────
|
|
162
|
-
// Thin delegates to `verbs.ts`: the transport owns framing, the verbs own
|
|
163
|
-
// wire shape.
|
|
161
|
+
// Thin delegates to `verbs.ts`: the transport owns framing, the verbs own
|
|
162
|
+
// the wire shape.
|
|
164
163
|
|
|
165
164
|
newSession(cwd: string, timeoutMs?: number, mcpServers?: AcpMcpServerWire[]) {
|
|
166
165
|
return verbs.newSession(this.call, cwd, timeoutMs, this.protocolVersion, mcpServers);
|
|
@@ -225,6 +224,11 @@ export class AcpProcess {
|
|
|
225
224
|
return verbs.setMode(this.call, sessionId, modeId, timeoutMs);
|
|
226
225
|
}
|
|
227
226
|
|
|
227
|
+
/** Sign this client in with one of the agent's advertised auth methods. */
|
|
228
|
+
authenticate(methodId: string, timeoutMs?: number) {
|
|
229
|
+
return verbs.authenticate(this.call, methodId, timeoutMs);
|
|
230
|
+
}
|
|
231
|
+
|
|
228
232
|
deleteSession(sessionId: string, timeoutMs?: number) {
|
|
229
233
|
return verbs.deleteSession(this.call, sessionId, timeoutMs);
|
|
230
234
|
}
|
|
@@ -261,11 +265,9 @@ export class AcpProcess {
|
|
|
261
265
|
this.rejectAll(new Error('ACP agent disposed'));
|
|
262
266
|
}
|
|
263
267
|
|
|
264
|
-
/** Send a client→agent request and await its result.
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
* turn legitimately runs for minutes, and every other verb takes the default
|
|
268
|
-
* cap. A cap of 0 disables the timer entirely. */
|
|
268
|
+
/** Send a client→agent request and await its result. `timeoutMs` is the turn
|
|
269
|
+
* budget: a prompt passes 0 (a coding turn runs for minutes) and every other
|
|
270
|
+
* verb takes the default cap. */
|
|
269
271
|
private request<T>(method: string, params: unknown, timeoutMs = 0): Promise<T> {
|
|
270
272
|
if (this.exited) return Promise.reject(new Error('ACP agent has exited'));
|
|
271
273
|
const budget = timeoutMs > 0
|
|
@@ -286,9 +288,8 @@ export class AcpProcess {
|
|
|
286
288
|
private write(frame: AcpRequest | AcpNotification | AcpResponse): void {
|
|
287
289
|
if (this.exited) return;
|
|
288
290
|
const line = `${JSON.stringify(frame)}\n`;
|
|
289
|
-
// Serialized: two
|
|
290
|
-
//
|
|
291
|
-
// queue (which would wedge every later frame).
|
|
291
|
+
// Serialized: two interleaved frames would corrupt the stream, and a closed
|
|
292
|
+
// pipe is reported by `exited` rather than thrown into the queue.
|
|
292
293
|
this.writeQueue = this.writeQueue.then(async () => {
|
|
293
294
|
this.stdio.write(line);
|
|
294
295
|
await this.stdio.flush();
|
|
@@ -336,10 +337,8 @@ export class AcpProcess {
|
|
|
336
337
|
// approval dialog works this way, and sending a refusal here would answer
|
|
337
338
|
// the same request twice.
|
|
338
339
|
if (handled && 'deferred' in handled) return;
|
|
339
|
-
// A refusal is REQUIRED
|
|
340
|
-
//
|
|
341
|
-
// travels with it so the agent can distinguish "not implemented" from
|
|
342
|
-
// "that file is gone" and fall back accordingly.
|
|
340
|
+
// A refusal is REQUIRED: an unanswered agent→client call parks the turn.
|
|
341
|
+
// The code travels with it so the agent can fall back accordingly.
|
|
343
342
|
this.respondError(id, handled?.message ?? `Kabmo does not implement ${method}`, handled?.code);
|
|
344
343
|
} catch (error) {
|
|
345
344
|
this.respondError(id, error instanceof Error ? error.message : String(error));
|
|
@@ -61,6 +61,25 @@ function host(): AcpCommandHost & { writes: [string, string | boolean][]; access
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
describe('ACP dispatchCommand', () => {
|
|
64
|
+
test('a steer on an agent with no mid-turn channel is held for the next turn', async () => {
|
|
65
|
+
const stub = host();
|
|
66
|
+
const queued: [string, unknown][] = [];
|
|
67
|
+
stub.queueTurnInput = (message, images) => {
|
|
68
|
+
queued.push([message, images]);
|
|
69
|
+
};
|
|
70
|
+
expect(await dispatchCommand(stub, { type: 'steer', message: 'also do this' })).toEqual({ queued: true });
|
|
71
|
+
expect(queued).toEqual([['also do this', undefined]]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('a follow-up on an agent with no mid-turn channel is held too', async () => {
|
|
75
|
+
const stub = host();
|
|
76
|
+
const queued: string[] = [];
|
|
77
|
+
stub.queueTurnInput = (message) => {
|
|
78
|
+
queued.push(message);
|
|
79
|
+
};
|
|
80
|
+
expect(await dispatchCommand(stub, { type: 'follow_up', message: 'then that' })).toEqual({ queued: true });
|
|
81
|
+
expect(queued).toEqual(['then that']);
|
|
82
|
+
});
|
|
64
83
|
test('set_model / set_thinking_level / set_mode write the selector ids', async () => {
|
|
65
84
|
const stub = host();
|
|
66
85
|
await dispatchCommand(stub, { type: 'set_model', provider: 'p', modelId: 'n' });
|
|
@@ -46,19 +46,26 @@ export interface AcpCommandHost {
|
|
|
46
46
|
isAlive(): boolean;
|
|
47
47
|
destroyAndWait(): Promise<void>;
|
|
48
48
|
steer(blocks: unknown[], queue: 'steering' | 'followUp'): Promise<unknown>;
|
|
49
|
+
/** Hold an input until the running turn ends (an agent with no steering). */
|
|
50
|
+
queueTurnInput?: (message: string, images: unknown) => void;
|
|
51
|
+
/** The content blocks one prompt sends: text, images and `@path` links. */
|
|
52
|
+
blocksFor?: (message: string, images: unknown) => Promise<unknown[]>;
|
|
49
53
|
/** Record a mid-turn user message in the session's own transcript. */
|
|
50
54
|
recordUserTurn(message: string, images: unknown): void;
|
|
51
55
|
cancelTurn(): void;
|
|
52
56
|
/** Adopt the composer's approval tier. ACP decides approvals in-process. */
|
|
53
57
|
setAccessMode(mode: ApprovalMode): void;
|
|
54
58
|
setConfig(configId: string, value: string | boolean): Promise<unknown>;
|
|
55
|
-
resolvePermission(dialogId: string, confirmed: boolean): unknown;
|
|
59
|
+
resolvePermission(dialogId: string, confirmed: boolean, optionId?: string): unknown;
|
|
56
60
|
webState(): Record<string, unknown>;
|
|
57
61
|
/** The agent's own slash-command list, when it published one. */
|
|
58
62
|
agentCommands: { name: string; description?: string; inputHint?: string }[];
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
/**
|
|
65
|
+
/** A prompt's blocks when the host offers no richer builder: text and images. */
|
|
66
|
+
const defaultBlocks = async (message: string, images: unknown): Promise<unknown[]> => promptBlocks(message, images);
|
|
67
|
+
|
|
68
|
+
/** The command vocabulary the routes already use. */
|
|
62
69
|
export async function dispatchCommand(host: AcpCommandHost, command: Record<string, unknown>): Promise<unknown> {
|
|
63
70
|
if (!host.isAlive()) throw new Error('ACP session is not running');
|
|
64
71
|
const type = typeof command.type === 'string' ? command.type : '';
|
|
@@ -90,9 +97,14 @@ export interface AcpCommandHost {
|
|
|
90
97
|
|
|
91
98
|
case 'steer': {
|
|
92
99
|
const message = String(command.message ?? '');
|
|
93
|
-
const blocks =
|
|
100
|
+
const blocks = await (host.blocksFor ?? defaultBlocks)(message, command.images);
|
|
94
101
|
if (host.capabilities.steerMode !== 'steer') {
|
|
95
|
-
|
|
102
|
+
// No mid-turn channel: hold it for the turn's end instead of dropping
|
|
103
|
+
// the operator's message. ACP has no queue of its own — the second
|
|
104
|
+
// prompt WOULD cancel the first — so the wait belongs here.
|
|
105
|
+
host.queueTurnInput?.(message, command.images);
|
|
106
|
+
host.recordUserTurn(message, command.images);
|
|
107
|
+
return { queued: true };
|
|
96
108
|
}
|
|
97
109
|
const result = await host.steer(blocks, 'steering');
|
|
98
110
|
host.recordUserTurn(message, command.images);
|
|
@@ -101,8 +113,12 @@ export interface AcpCommandHost {
|
|
|
101
113
|
|
|
102
114
|
case 'follow_up': {
|
|
103
115
|
const message = String(command.message ?? '');
|
|
104
|
-
const blocks =
|
|
105
|
-
if (!host.capabilities.steerMode)
|
|
116
|
+
const blocks = await (host.blocksFor ?? defaultBlocks)(message, command.images);
|
|
117
|
+
if (!host.capabilities.steerMode) {
|
|
118
|
+
host.queueTurnInput?.(message, command.images);
|
|
119
|
+
host.recordUserTurn(message, command.images);
|
|
120
|
+
return { queued: true };
|
|
121
|
+
}
|
|
106
122
|
const result = await host.steer(blocks, 'followUp');
|
|
107
123
|
host.recordUserTurn(message, command.images);
|
|
108
124
|
return result;
|
|
@@ -173,10 +189,12 @@ export interface AcpCommandHost {
|
|
|
173
189
|
case 'extension_ui_response': {
|
|
174
190
|
// The approval dialog's answer, in the shape the shared gate sends. The
|
|
175
191
|
// session owns the picking (which option means "allow"), because it is
|
|
176
|
-
// also the side that rendered the options.
|
|
192
|
+
// also the side that rendered the options. `optionId` is the option the
|
|
193
|
+
// operator clicked; `confirmed` is the yes/no fallback.
|
|
177
194
|
const id = typeof command.id === 'string' ? command.id : '';
|
|
195
|
+
const optionId = typeof command.optionId === 'string' ? command.optionId : undefined;
|
|
178
196
|
const confirmed = command.confirmed === true || command.value === 'allow';
|
|
179
|
-
return host.resolvePermission(id, confirmed);
|
|
197
|
+
return host.resolvePermission(id, confirmed, optionId);
|
|
180
198
|
}
|
|
181
199
|
|
|
182
200
|
default:
|
|
@@ -119,9 +119,14 @@ export class AcpFrameMapper {
|
|
|
119
119
|
case 'state_update':
|
|
120
120
|
case 'terminal_update':
|
|
121
121
|
case 'terminal_output_chunk':
|
|
122
|
+
return [];
|
|
123
|
+
// Compaction has no card of its own, but it is a LIVE event the operator
|
|
124
|
+
// must see: a chat that silently spends a minute rewriting its context
|
|
125
|
+
// reads as a hang. `session.compaction` is advertised, so an agent may
|
|
126
|
+
// send these, and a notice is the surface that exists.
|
|
122
127
|
case 'compaction_update':
|
|
123
128
|
case 'compaction_summary_chunk':
|
|
124
|
-
return
|
|
129
|
+
return this.compaction(update);
|
|
125
130
|
case 'usage_update':
|
|
126
131
|
return this.usage(update);
|
|
127
132
|
case 'available_commands_update':
|
|
@@ -279,6 +284,16 @@ export class AcpFrameMapper {
|
|
|
279
284
|
return frames;
|
|
280
285
|
}
|
|
281
286
|
|
|
287
|
+
/** One compaction frame as a notice, or nothing once it is complete. */
|
|
288
|
+
private compaction(update: Record<string, unknown>): AgentEvent[] {
|
|
289
|
+
const failed = typeof update.error === 'string' && update.error.length > 0;
|
|
290
|
+
return [{
|
|
291
|
+
type: 'notice',
|
|
292
|
+
level: failed ? 'warning' : 'info',
|
|
293
|
+
message: failed ? `Compaction failed: ${update.error}` : 'Compacting the conversation…',
|
|
294
|
+
}];
|
|
295
|
+
}
|
|
296
|
+
|
|
282
297
|
private usage(update: Record<string, unknown>): AgentEvent[] {
|
|
283
298
|
const size = typeof update.size === 'number' ? update.size : undefined;
|
|
284
299
|
const used = typeof update.used === 'number' ? update.used : undefined;
|