@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
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The config-selector view `setAcpConfig`/`setAcpMode` write through.
|
|
8
|
+
*
|
|
9
|
+
* `session-config.ts` owns the RULES (adopt the agent's answer, announce the new
|
|
10
|
+
* identity, route a synthesized selector to the verb that answers it), and it
|
|
11
|
+
* needs a mutable view of the session to apply them. Building that view here
|
|
12
|
+
* keeps `session.ts` from growing four near-identical delegates, and the getters
|
|
13
|
+
* matter: a snapshot would write the new model into a copy and leave the session
|
|
14
|
+
* naming the old one.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { AcpConfigOption, AcpSessionModeState, AcpSessionModels } from '@/server/lib/harness/acp/protocol';
|
|
18
|
+
import type { AcpConfigWriter } from '@/server/lib/harness/acp/session-config';
|
|
19
|
+
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
20
|
+
|
|
21
|
+
/** What the view reads and moves on the session. */
|
|
22
|
+
export interface AcpConfigState {
|
|
23
|
+
readonly harness: HarnessId;
|
|
24
|
+
readonly sessionId: string;
|
|
25
|
+
configOptions: AcpConfigOption[];
|
|
26
|
+
runModel: { provider: string; modelId: string } | null;
|
|
27
|
+
modes: AcpSessionModeState | null;
|
|
28
|
+
models: AcpSessionModels | null;
|
|
29
|
+
readonly isStreaming: boolean;
|
|
30
|
+
emit(event: Record<string, unknown> & { type: string }): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The process verbs the view calls. */
|
|
34
|
+
export interface AcpConfigProcess {
|
|
35
|
+
setConfigOption(sessionId: string, configId: string, value: string | boolean): Promise<unknown>;
|
|
36
|
+
setMode(sessionId: string, modeId: string): Promise<unknown>;
|
|
37
|
+
setModel(sessionId: string, modelId: string): Promise<unknown>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The `AcpConfigWriter` a session exposes, bound to ITS own fields. */
|
|
41
|
+
export function acpConfigView(state: AcpConfigState, proc: AcpConfigProcess): AcpConfigWriter {
|
|
42
|
+
return {
|
|
43
|
+
get harness() {
|
|
44
|
+
return state.harness;
|
|
45
|
+
},
|
|
46
|
+
get sessionId() {
|
|
47
|
+
return state.sessionId;
|
|
48
|
+
},
|
|
49
|
+
get configOptions() {
|
|
50
|
+
return state.configOptions;
|
|
51
|
+
},
|
|
52
|
+
set configOptions(options: AcpConfigOption[]) {
|
|
53
|
+
state.configOptions = options;
|
|
54
|
+
},
|
|
55
|
+
get runModel() {
|
|
56
|
+
return state.runModel;
|
|
57
|
+
},
|
|
58
|
+
set runModel(model: { provider: string; modelId: string } | null) {
|
|
59
|
+
state.runModel = model;
|
|
60
|
+
},
|
|
61
|
+
get modes() {
|
|
62
|
+
return state.modes;
|
|
63
|
+
},
|
|
64
|
+
set modes(modes: AcpSessionModeState | null) {
|
|
65
|
+
state.modes = modes;
|
|
66
|
+
},
|
|
67
|
+
get models() {
|
|
68
|
+
return state.models;
|
|
69
|
+
},
|
|
70
|
+
set models(models: AcpSessionModels | null) {
|
|
71
|
+
state.models = models;
|
|
72
|
+
},
|
|
73
|
+
get isStreaming() {
|
|
74
|
+
return state.isStreaming;
|
|
75
|
+
},
|
|
76
|
+
emit: (event) => state.emit(event),
|
|
77
|
+
writeConfigOption: (configId, value) => proc.setConfigOption(state.sessionId, configId, value),
|
|
78
|
+
writeMode: (modeId) => proc.setMode(state.sessionId, modeId),
|
|
79
|
+
writeModel: (modelId) => proc.setModel(state.sessionId, modelId),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
import { configOption, modelFromOption } from '@/server/lib/harness/acp/prompt';
|
|
33
|
-
import
|
|
33
|
+
import { permissionGrantKey } from '@/server/lib/harness/acp/grants';
|
|
34
|
+
import { saveAcpGrant } from '@/server/lib/harness/acp/grants.server';
|
|
35
|
+
import type { AcpConfigOption, AcpSessionModeState, AcpSessionModels } from '@/server/lib/harness/acp/protocol';
|
|
34
36
|
import type { PendingPermissions } from '@/server/lib/harness/acp/permissions';
|
|
35
37
|
import { markStreamModel } from '@/shared/lib/omp/session/stream-state.server';
|
|
36
38
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
@@ -132,26 +134,49 @@ export interface AcpResponder {
|
|
|
132
134
|
respond(id: string | number, result: unknown): void;
|
|
133
135
|
}
|
|
134
136
|
|
|
135
|
-
/** Answer one parked approval dialog.
|
|
137
|
+
/** Answer one parked approval dialog.
|
|
138
|
+
*
|
|
139
|
+
* `optionId` is the option the operator actually CLICKED (the dialog renders
|
|
140
|
+
* the agent's list); `confirmed` is the fallback for a yes/no frame. An id the
|
|
141
|
+
* dialog does not hold is ignored rather than guessed — it belongs to a frame
|
|
142
|
+
* that was withdrawn, and selecting a different option there would approve
|
|
143
|
+
* something the operator never saw.
|
|
144
|
+
*
|
|
145
|
+
* Returns the grant key when the chosen option was `allow_always`, so the
|
|
146
|
+
* caller can persist the standing decision. */
|
|
136
147
|
export function settlePermissionDialog(
|
|
137
148
|
permissions: PendingPermissions,
|
|
138
149
|
responder: AcpResponder,
|
|
139
150
|
dialogId: string,
|
|
140
|
-
confirmed: boolean,
|
|
141
|
-
):
|
|
151
|
+
choice: { confirmed: boolean; optionId?: string },
|
|
152
|
+
): string | null {
|
|
142
153
|
const entry = permissions.take(dialogId);
|
|
143
|
-
if (!entry) return;
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
154
|
+
if (!entry) return null;
|
|
155
|
+
const picked = (choice.optionId
|
|
156
|
+
? entry.options.find((option) => option.optionId === choice.optionId)
|
|
157
|
+
: undefined) ?? permissions.optionFor(entry, choice.confirmed);
|
|
158
|
+
if (!picked) {
|
|
159
|
+
responder.respond(entry.id, { outcome: { outcome: 'cancelled' } });
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
responder.respond(entry.id, { outcome: { outcome: 'selected', optionId: picked.optionId } });
|
|
163
|
+
if (picked.kind !== 'allow_always') return null;
|
|
164
|
+
const key = permissionGrantKey(entry.toolCall);
|
|
165
|
+
if (!permissions.grants.add(key)) return null;
|
|
166
|
+
if (key !== null) void saveAcpGrant(entry.sessionId, key).catch(() => {});
|
|
167
|
+
return key;
|
|
148
168
|
}
|
|
149
169
|
|
|
150
170
|
/** The process slice a config write drives; `AcpProcess` satisfies it. */
|
|
151
171
|
export interface AcpConfigWriter extends AcpConfigNotice {
|
|
152
172
|
modes: AcpSessionModeState | null;
|
|
173
|
+
/** The `models` block, for an agent with no `model` selector. */
|
|
174
|
+
models?: AcpSessionModels | null;
|
|
153
175
|
writeConfigOption(configId: string, value: string | boolean): Promise<unknown>;
|
|
154
176
|
writeMode(modeId: string): Promise<unknown>;
|
|
177
|
+
/** `session/set_model`: the only way to select a model on an agent that
|
|
178
|
+
* publishes a `models` block instead of a config option. */
|
|
179
|
+
writeModel?: (modelId: string) => Promise<unknown>;
|
|
155
180
|
}
|
|
156
181
|
|
|
157
182
|
/**
|
|
@@ -168,6 +193,20 @@ export async function setAcpConfig(
|
|
|
168
193
|
if (configId === 'mode' && typeof value === 'string' && !target.configOptions.some((option) => option.id === 'mode') && target.modes) {
|
|
169
194
|
return setAcpMode(target, value);
|
|
170
195
|
}
|
|
196
|
+
// The synthesized selector from a `models` block is answered by
|
|
197
|
+
// `session/set_model`: the agent never published a `model` config option, so a
|
|
198
|
+
// `set_config_option` would ask it for a selector it does not have.
|
|
199
|
+
const synthesized = configId === 'model'
|
|
200
|
+
&& typeof value === 'string'
|
|
201
|
+
&& target.models !== undefined
|
|
202
|
+
&& target.models !== null;
|
|
203
|
+
if (synthesized && target.writeModel) {
|
|
204
|
+
const result = await target.writeModel(value);
|
|
205
|
+
target.models = { ...target.models, currentModelId: value };
|
|
206
|
+
adoptConfigAnswer(target, result, { configId, value });
|
|
207
|
+
publishConfigChange(target, configId);
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
171
210
|
const result = await target.writeConfigOption(configId, value);
|
|
172
211
|
adoptConfigAnswer(target, result, { configId, value });
|
|
173
212
|
publishConfigChange(target, configId);
|
|
@@ -69,10 +69,79 @@ describe('handshakeAcpSession', () => {
|
|
|
69
69
|
expect(proc.calls).toEqual(['new']);
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
test('load restores
|
|
72
|
+
test('load restores the same session and continues on it', async () => {
|
|
73
73
|
const proc = processDouble();
|
|
74
|
-
|
|
74
|
+
const session = target();
|
|
75
|
+
await handshakeAcpSession(session, proc, { model: null, thinking: null, mode: null }, 'agent-1');
|
|
76
|
+
expect(proc.calls).toEqual(['load']);
|
|
77
|
+
expect(session.sessionId).toBe('agent-1');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('a load that answers a forked id continues on that id', async () => {
|
|
81
|
+
const proc = processDouble({
|
|
82
|
+
async loadSession() {
|
|
83
|
+
proc.calls.push('load');
|
|
84
|
+
return { sessionId: 'forked-1' };
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
const session = target();
|
|
88
|
+
await handshakeAcpSession(session, proc, { model: null, thinking: null, mode: null }, 'agent-1');
|
|
89
|
+
expect(proc.calls).toEqual(['load']);
|
|
90
|
+
expect(session.sessionId).toBe('forked-1');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('resume wins when the agent advertises both, and load is never called', async () => {
|
|
94
|
+
const proc = processDouble({
|
|
95
|
+
async initialize() {
|
|
96
|
+
return {
|
|
97
|
+
protocolVersion: 1,
|
|
98
|
+
agentCapabilities: { loadSession: true, sessionCapabilities: { resume: {} } },
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
async resumeSession(sessionId: string) {
|
|
102
|
+
proc.calls.push(`resume:${sessionId}`);
|
|
103
|
+
return {};
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
const session = target();
|
|
107
|
+
await handshakeAcpSession(session, proc, { model: null, thinking: null, mode: null }, 'agent-1');
|
|
108
|
+
expect(proc.calls).toEqual(['resume:agent-1']);
|
|
109
|
+
expect(session.sessionId).toBe('agent-1');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('a failed restore continues in a fresh session and says so', async () => {
|
|
113
|
+
const proc = processDouble({
|
|
114
|
+
async loadSession() {
|
|
115
|
+
proc.calls.push('load');
|
|
116
|
+
throw new Error('session not found');
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
const session = target();
|
|
120
|
+
const notices: unknown[] = [];
|
|
121
|
+
session.emit = (event) => {
|
|
122
|
+
notices.push(event);
|
|
123
|
+
};
|
|
124
|
+
await handshakeAcpSession(session, proc, { model: null, thinking: null, mode: null }, 'agent-1');
|
|
75
125
|
expect(proc.calls).toEqual(['load', 'new']);
|
|
126
|
+
expect(session.sessionId).toBe('new-id');
|
|
127
|
+
expect(notices).toContainEqual({
|
|
128
|
+
type: 'notice',
|
|
129
|
+
level: 'warning',
|
|
130
|
+
message: 'claude could not restore the previous session; continuing in a fresh session without in-agent history.',
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('an auth refusal during restore is never replaced by a silent new session', async () => {
|
|
135
|
+
const proc = processDouble({
|
|
136
|
+
async loadSession() {
|
|
137
|
+
proc.calls.push('load');
|
|
138
|
+
throw Object.assign(new Error('Authentication required'), { code: -32000 });
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
await expect(
|
|
142
|
+
handshakeAcpSession(target(), proc, { model: null, thinking: null, mode: null }, 'agent-1'),
|
|
143
|
+
).rejects.toThrow('Authentication required');
|
|
144
|
+
expect(proc.calls).toEqual(['load']);
|
|
76
145
|
});
|
|
77
146
|
|
|
78
147
|
test('an agent with no loadSession but sessionCapabilities.resume resumes in place', async () => {
|
|
@@ -25,8 +25,11 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { newSessionAfterActivation } from '@/server/lib/harness/acp/activation';
|
|
28
|
-
import { applyLaunchSelections, configOption, modelFromOption } from '@/server/lib/harness/acp/prompt';
|
|
28
|
+
import { applyLaunchSelections, configOption, modelFromOption, modelsAsSelector } from '@/server/lib/harness/acp/prompt';
|
|
29
29
|
import { toAcpV2McpServers } from '@/server/lib/harness/acp/v2';
|
|
30
|
+
import type { SessionDirs } from '@/server/lib/harness/acp/verbs';
|
|
31
|
+
import { authMethodsOf, describeSignIn, headlessAuthMethod, isAuthRequiredError } from '@/server/lib/harness/acp/auth';
|
|
32
|
+
import { additionalDirectoriesFor, sessionRoots } from '@/server/lib/harness/acp/session-roots.server';
|
|
30
33
|
import { capabilitiesFrom } from '@/server/lib/harness/launch';
|
|
31
34
|
import type {
|
|
32
35
|
AcpAgentCommand,
|
|
@@ -36,20 +39,42 @@ import type {
|
|
|
36
39
|
AcpMcpServerWire,
|
|
37
40
|
AcpProtocolVersion,
|
|
38
41
|
AcpSessionModeState,
|
|
42
|
+
AcpSessionModels,
|
|
39
43
|
AcpSessionNewResult,
|
|
40
44
|
} from '@/server/lib/harness/acp/protocol';
|
|
41
45
|
import type { HarnessCapabilities } from '@/server/lib/harness/capabilities';
|
|
46
|
+
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
42
47
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
43
48
|
|
|
44
49
|
/** The process slice a handshake drives; `AcpProcess` satisfies it as-is. */
|
|
45
50
|
export interface AcpHandshakeProcess {
|
|
46
51
|
initialize(params?: Record<string, unknown>, timeoutMs?: number): Promise<AcpInitializeResult>;
|
|
47
|
-
loadSession(
|
|
48
|
-
|
|
52
|
+
loadSession(
|
|
53
|
+
sessionId: string,
|
|
54
|
+
cwd: string,
|
|
55
|
+
timeoutMs?: number,
|
|
56
|
+
mcpServers?: AcpMcpServerWire[],
|
|
57
|
+
dirs?: SessionDirs,
|
|
58
|
+
): Promise<unknown>;
|
|
59
|
+
newSession(
|
|
60
|
+
cwd: string,
|
|
61
|
+
timeoutMs?: number,
|
|
62
|
+
mcpServers?: AcpMcpServerWire[],
|
|
63
|
+
dirs?: SessionDirs,
|
|
64
|
+
): Promise<AcpSessionNewResult>;
|
|
49
65
|
/** The negotiated major; absent on a test double, which is a v1 double. */
|
|
50
66
|
readonly protocolVersion?: AcpProtocolVersion;
|
|
51
67
|
/** `session/resume`; absent on a process double used by older tests. */
|
|
52
|
-
resumeSession?(
|
|
68
|
+
resumeSession?(
|
|
69
|
+
sessionId: string,
|
|
70
|
+
cwd: string,
|
|
71
|
+
timeoutMs?: number,
|
|
72
|
+
mcpServers?: AcpMcpServerWire[],
|
|
73
|
+
replayFrom?: unknown,
|
|
74
|
+
dirs?: SessionDirs,
|
|
75
|
+
): Promise<unknown>;
|
|
76
|
+
/** `authenticate`; absent on a process double, which needs no login. */
|
|
77
|
+
authenticate?(methodId: string, timeoutMs?: number): Promise<unknown>;
|
|
53
78
|
/** `session/fork`; absent on a process double used by older tests. */
|
|
54
79
|
forkSession?(
|
|
55
80
|
sessionId: string,
|
|
@@ -58,6 +83,7 @@ export interface AcpHandshakeProcess {
|
|
|
58
83
|
target?: Record<string, unknown>,
|
|
59
84
|
meta?: Record<string, unknown>,
|
|
60
85
|
mcpServers?: AcpMcpServerWire[],
|
|
86
|
+
dirs?: SessionDirs,
|
|
61
87
|
): Promise<AcpSessionNewResult>;
|
|
62
88
|
}
|
|
63
89
|
|
|
@@ -69,6 +95,8 @@ export interface AcpHandshakeTarget {
|
|
|
69
95
|
configOptions: AcpConfigOption[];
|
|
70
96
|
/** The older Session Modes API, when the agent publishes no `mode` selector. */
|
|
71
97
|
modes?: AcpSessionModeState | null;
|
|
98
|
+
/** The `models` block the agent published, when it published one. */
|
|
99
|
+
models?: AcpSessionModels | null;
|
|
72
100
|
runModel: { provider: string; modelId: string } | null;
|
|
73
101
|
capabilities: HarnessCapabilities;
|
|
74
102
|
setConfig(configId: string, value: string | boolean): Promise<unknown>;
|
|
@@ -83,6 +111,14 @@ export interface AcpHandshakeTarget {
|
|
|
83
111
|
/** Called as soon as `initialize` answers, before any session request, so a
|
|
84
112
|
* v2 resume snapshot can open a turn. */
|
|
85
113
|
onProtocol?(version: AcpProtocolVersion): void;
|
|
114
|
+
/** Push a notice when a restore had to start a fresh agent session; the
|
|
115
|
+
* operator must know the agent no longer holds the history. */
|
|
116
|
+
emit?(event: AgentEvent): void;
|
|
117
|
+
/** The environment the agent sees, read to decide whether an advertised
|
|
118
|
+
* `authMethods` entry can be satisfied headlessly. */
|
|
119
|
+
authEnv?: Record<string, string | undefined>;
|
|
120
|
+
/** The launch line, so a refused handshake can name the sign-in command. */
|
|
121
|
+
readonly command?: string[];
|
|
86
122
|
}
|
|
87
123
|
|
|
88
124
|
/** The picks the composer sent for a brand-new session. */
|
|
@@ -106,6 +142,15 @@ export async function handshakeAcpSession(
|
|
|
106
142
|
): Promise<void> {
|
|
107
143
|
const init = await proc.initialize(undefined, 60_000);
|
|
108
144
|
target.onProtocol?.(init.protocolVersion === 2 ? 2 : 1);
|
|
145
|
+
// ACP's `initialize` lists the ways in; a client that never calls
|
|
146
|
+
// `authenticate` makes every agent that requires a login refuse `session/new`
|
|
147
|
+
// with `-32000`, which surfaces as a raw spawn failure. Only a HEADLESS method
|
|
148
|
+
// is attempted — a terminal one wants a TTY Kabmo does not host.
|
|
149
|
+
const methods = authMethodsOf(init);
|
|
150
|
+
if (methods.length > 0 && proc.authenticate) {
|
|
151
|
+
const methodId = headlessAuthMethod(methods, target.authEnv ?? {});
|
|
152
|
+
if (methodId) await proc.authenticate(methodId, 120_000);
|
|
153
|
+
}
|
|
109
154
|
// stdio is the ACP baseline; `http`/`sse` are only real when the agent
|
|
110
155
|
// advertises them. Sending an unadvertised transport is at best ignored and
|
|
111
156
|
// at worst rejects the whole setup request, so the list is filtered here —
|
|
@@ -121,10 +166,19 @@ export async function handshakeAcpSession(
|
|
|
121
166
|
const mcpServers: AcpMcpServerWire[] = init.protocolVersion === 2
|
|
122
167
|
? toAcpV2McpServers(requestedMcp)
|
|
123
168
|
: requestedMcp;
|
|
169
|
+
// A chat whose cwd is a WORKTREE may work in the repository too, and the
|
|
170
|
+
// agent only knows that if the setup request names it. Gated on the agent's
|
|
171
|
+
// own capability, because `additionalDirectories` on a peer that does not
|
|
172
|
+
// advertise it is at best ignored and at worst rejects the request.
|
|
173
|
+
const dirs = additionalDirectoriesFor(
|
|
174
|
+
await sessionRoots(target.cwd),
|
|
175
|
+
target.cwd,
|
|
176
|
+
init.agentCapabilities?.sessionCapabilities?.additionalDirectories !== undefined,
|
|
177
|
+
);
|
|
124
178
|
/** opencode's plugin activation gate: the first `session/new`s refuse with
|
|
125
179
|
* `ServiceUnavailableError` until the agent's plugins finish booting. */
|
|
126
180
|
const newSession = (cwd: string, timeoutMs?: number) =>
|
|
127
|
-
newSessionAfterActivation(target.harness, cwd, (dir, ms) => proc.newSession(dir, ms, mcpServers), {
|
|
181
|
+
newSessionAfterActivation(target.harness, cwd, (dir, ms) => proc.newSession(dir, ms, mcpServers, dirs), {
|
|
128
182
|
...(timeoutMs !== undefined ? { perAttemptMs: timeoutMs } : {}),
|
|
129
183
|
});
|
|
130
184
|
let session: AcpSessionNewResult;
|
|
@@ -149,6 +203,7 @@ export async function handshakeAcpSession(
|
|
|
149
203
|
// one. An agent that does not read it ignores the key and forks whole.
|
|
150
204
|
forkMeta,
|
|
151
205
|
mcpServers,
|
|
206
|
+
dirs,
|
|
152
207
|
);
|
|
153
208
|
} else if (sessionIdToLoad) {
|
|
154
209
|
// ACP gates restoration on the AGENT's advertised capability: `loadSession`
|
|
@@ -157,48 +212,84 @@ export async function handshakeAcpSession(
|
|
|
157
212
|
// `session/load` anyway asked a non-supporting agent for a method it had not
|
|
158
213
|
// advertised and surfaced its `-32601` as a spawn failure.
|
|
159
214
|
const caps = init.agentCapabilities ?? {};
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
? await (proc.resumeSession
|
|
165
|
-
? proc.resumeSession(
|
|
166
|
-
sessionIdToLoad,
|
|
167
|
-
target.cwd,
|
|
168
|
-
120_000,
|
|
169
|
-
mcpServers,
|
|
170
|
-
replay ? { type: 'start' } : undefined,
|
|
171
|
-
)
|
|
172
|
-
: Promise.reject(new Error(`${target.harness} cannot resume a session`)))
|
|
173
|
-
: caps.loadSession === true
|
|
174
|
-
? await loadReplacement(proc, newSession, sessionIdToLoad, target.cwd, mcpServers)
|
|
175
|
-
: caps.sessionCapabilities?.resume != null
|
|
176
|
-
? await (proc.resumeSession
|
|
177
|
-
? proc.resumeSession(
|
|
178
|
-
sessionIdToLoad,
|
|
179
|
-
target.cwd,
|
|
180
|
-
120_000,
|
|
181
|
-
mcpServers,
|
|
182
|
-
replay ? { type: 'start' } : undefined,
|
|
183
|
-
)
|
|
184
|
-
: Promise.reject(new Error(`${target.harness} cannot resume a session`)))
|
|
185
|
-
: null;
|
|
186
|
-
if (restored === null) {
|
|
215
|
+
const replayFrom = replay ? { type: 'start' as const } : undefined;
|
|
216
|
+
const canResume = proc.protocolVersion === 2 || caps.sessionCapabilities?.resume != null;
|
|
217
|
+
const canLoad = proc.protocolVersion !== 2 && caps.loadSession === true;
|
|
218
|
+
if (!canResume && !canLoad) {
|
|
187
219
|
throw new Error(
|
|
188
220
|
`${target.harness} cannot restore this chat: it supports neither session/load nor session/resume`,
|
|
189
221
|
);
|
|
190
222
|
}
|
|
223
|
+
// `session/resume` wins whenever the agent speaks it: it restores the SAME
|
|
224
|
+
// session in place, while `session/load` replays and (on some adapters)
|
|
225
|
+
// answers a forked id. Resuming instead of loading what the agent can resume
|
|
226
|
+
// is what keeps the conversation's context, and the old order (load first)
|
|
227
|
+
// handed every agent that advertises both an empty follow-up session.
|
|
228
|
+
let restored: unknown;
|
|
229
|
+
try {
|
|
230
|
+
restored = canResume
|
|
231
|
+
? await (proc.resumeSession
|
|
232
|
+
// v2 removed `session/load`; `session/resume` is baseline there.
|
|
233
|
+
? proc.resumeSession(sessionIdToLoad, target.cwd, 120_000, mcpServers, replayFrom, dirs)
|
|
234
|
+
: Promise.reject(new Error(`${target.harness} cannot resume a session`)))
|
|
235
|
+
: await proc.loadSession(sessionIdToLoad, target.cwd, 120_000, mcpServers, dirs);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
// A restore that fails is not a reason to lose the chat: the agent may
|
|
238
|
+
// have dropped the session, but Kabmo's own transcript is on screen. A
|
|
239
|
+
// fresh session continues it, and the operator is told the history is not
|
|
240
|
+
// in the agent's context — silently doing so is the failure this branch
|
|
241
|
+
// exists to prevent. `fork` never reaches here, so nothing is substituted
|
|
242
|
+
// under a fork's name.
|
|
243
|
+
// A sign-in refusal is not a lost session: continuing in a fresh one would
|
|
244
|
+
// hide the one action the operator must take. The sentence names the
|
|
245
|
+
// agent's own command.
|
|
246
|
+
if (isAuthRequiredError(error)) {
|
|
247
|
+
const guidance = describeSignIn(authMethodsOf(init), (target.command ?? [target.harness]).join(' '));
|
|
248
|
+
throw guidance ? new Error(`${error instanceof Error ? error.message : String(error)}. ${guidance}`) : error;
|
|
249
|
+
}
|
|
250
|
+
target.emit?.({
|
|
251
|
+
type: 'notice',
|
|
252
|
+
level: 'warning',
|
|
253
|
+
message: `${target.harness} could not restore the previous session; continuing in a fresh session without in-agent history.`,
|
|
254
|
+
});
|
|
255
|
+
session = await newSession(target.cwd, 120_000);
|
|
256
|
+
return finishHandshake(target, init, session, wanted);
|
|
257
|
+
}
|
|
191
258
|
const state = restored && typeof restored === 'object'
|
|
192
259
|
? (restored as Partial<AcpSessionNewResult>)
|
|
193
260
|
: {};
|
|
194
|
-
//
|
|
195
|
-
//
|
|
196
|
-
|
|
261
|
+
// A load may answer a DIFFERENT (forked) id: that id IS the restored
|
|
262
|
+
// conversation, so it is the one to continue on. The registry re-points the
|
|
263
|
+
// chat at it; falling back to a fresh `session/new` here would throw the
|
|
264
|
+
// context away and leave the loaded session orphaned.
|
|
265
|
+
const restoredId = typeof state.sessionId === 'string' && state.sessionId
|
|
266
|
+
? state.sessionId
|
|
267
|
+
: sessionIdToLoad;
|
|
268
|
+
session = { ...state, sessionId: restoredId };
|
|
197
269
|
} else {
|
|
198
270
|
session = await newSession(target.cwd, 120_000);
|
|
199
271
|
}
|
|
200
|
-
target
|
|
272
|
+
return finishHandshake(target, init, session, wanted);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Adopt the setup answer and apply the launch picks, for every branch. */
|
|
276
|
+
async function finishHandshake(
|
|
277
|
+
target: AcpHandshakeTarget,
|
|
278
|
+
init: AcpInitializeResult,
|
|
279
|
+
session: AcpSessionNewResult,
|
|
280
|
+
wanted: AcpHandshakeSelections,
|
|
281
|
+
): Promise<void> {
|
|
282
|
+
target.sessionId = session.sessionId || target.sessionId || '';
|
|
201
283
|
target.configOptions = session.configOptions ?? [];
|
|
284
|
+
// An agent that publishes a `models` block instead of a `model` selector gets
|
|
285
|
+
// a synthesized selector, so the picker, `get_state` and `set_model` read one
|
|
286
|
+
// shape. A published selector always wins — it is what the agent will accept
|
|
287
|
+
// back on `session/set_config_option`.
|
|
288
|
+
const modelsSelector = configOption(target.configOptions, 'model')
|
|
289
|
+
? null
|
|
290
|
+
: modelsAsSelector(session.models);
|
|
291
|
+
if (modelsSelector) target.configOptions = [...target.configOptions, modelsSelector];
|
|
292
|
+
target.models = session.models ?? null;
|
|
202
293
|
target.modes = session.modes ?? null;
|
|
203
294
|
target.acceptsImages = init.agentCapabilities?.promptCapabilities?.image === true;
|
|
204
295
|
if (session.availableCommands) target.agentCommands = session.availableCommands;
|
|
@@ -207,20 +298,4 @@ export async function handshakeAcpSession(
|
|
|
207
298
|
await applyLaunchSelections(target, wanted);
|
|
208
299
|
}
|
|
209
300
|
|
|
210
|
-
|
|
211
|
-
* The v1 load path: replay the agent's history into the mapper, then continue on
|
|
212
|
-
* a fresh agent session.
|
|
213
|
-
*
|
|
214
|
-
* Deliberate: measured on omp, a load answers a FORKED id, and continuing on it
|
|
215
|
-
* would write a second sidebar row for one chat.
|
|
216
|
-
*/
|
|
217
|
-
async function loadReplacement(
|
|
218
|
-
proc: AcpHandshakeProcess,
|
|
219
|
-
create: (cwd: string, timeoutMs?: number) => Promise<AcpSessionNewResult>,
|
|
220
|
-
sessionId: string,
|
|
221
|
-
cwd: string,
|
|
222
|
-
mcpServers: AcpMcpServerWire[],
|
|
223
|
-
): Promise<unknown> {
|
|
224
|
-
await proc.loadSession(sessionId, cwd, 120_000, mcpServers);
|
|
225
|
-
return (await create(cwd).catch(() => null)) ?? { sessionId };
|
|
226
|
-
}
|
|
301
|
+
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What a prompt does before it reaches the wire.
|
|
8
|
+
*
|
|
9
|
+
* Two rules that a caller can see from outside: an image the agent never
|
|
10
|
+
* advertised is REFUSED with a sentence (rather than sent into a dispatcher that
|
|
11
|
+
* throws), and a mid-turn message on an agent with no steering extension is
|
|
12
|
+
* QUEUED for the next turn instead of being lost.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
import { startAcpPrompt, sendAcpMidTurn, type AcpPromptHost } from '@/server/lib/harness/acp/session-intake';
|
|
17
|
+
|
|
18
|
+
function host(overrides: Partial<AcpPromptHost> = {}): AcpPromptHost & {
|
|
19
|
+
events: string[];
|
|
20
|
+
queued: string[];
|
|
21
|
+
steered: unknown[][];
|
|
22
|
+
turns: number;
|
|
23
|
+
} {
|
|
24
|
+
const events: string[] = [];
|
|
25
|
+
const queued: string[] = [];
|
|
26
|
+
const steered: unknown[][] = [];
|
|
27
|
+
const state = {
|
|
28
|
+
cwd: '/tmp',
|
|
29
|
+
harness: 'claude',
|
|
30
|
+
acceptsImages: false,
|
|
31
|
+
promptCount: 0,
|
|
32
|
+
background: { stop: () => events.push('background-stop') },
|
|
33
|
+
usage: { beginTurn: () => events.push('usage-begin') },
|
|
34
|
+
beginTurn: () => {
|
|
35
|
+
state.turns += 1;
|
|
36
|
+
events.push('turn');
|
|
37
|
+
return { agentInvoked: true };
|
|
38
|
+
},
|
|
39
|
+
emit: (event: Record<string, unknown> & { type: string }) => events.push(event.type),
|
|
40
|
+
steer: async (blocks: unknown[]) => {
|
|
41
|
+
steered.push(blocks);
|
|
42
|
+
return { steered: true };
|
|
43
|
+
},
|
|
44
|
+
queueTurnInput: (_message: string) => {
|
|
45
|
+
queued.push(_message);
|
|
46
|
+
},
|
|
47
|
+
events,
|
|
48
|
+
queued,
|
|
49
|
+
steered,
|
|
50
|
+
turns: 0,
|
|
51
|
+
};
|
|
52
|
+
return Object.assign(state, overrides);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
describe('startAcpPrompt', () => {
|
|
56
|
+
test('opens the turn and records the user row', () => {
|
|
57
|
+
const h = host();
|
|
58
|
+
expect(startAcpPrompt(h, 'hello', undefined)).toEqual({ agentInvoked: true });
|
|
59
|
+
expect(h.turns).toBe(1);
|
|
60
|
+
expect(h.promptCount).toBe(1);
|
|
61
|
+
expect(h.events).toEqual(['background-stop', 'usage-begin', 'turn', 'user_turn']);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('an image the agent never advertised is refused before any turn opens', () => {
|
|
65
|
+
const h = host();
|
|
66
|
+
expect(() => startAcpPrompt(h, 'look', [{ data: 'x', mimeType: 'image/png' }])).toThrow(
|
|
67
|
+
'This harness does not accept image attachments (claude)',
|
|
68
|
+
);
|
|
69
|
+
expect(h.turns).toBe(0);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('an advertised image capability lets the turn run', () => {
|
|
73
|
+
const h = host({ acceptsImages: true });
|
|
74
|
+
expect(() => startAcpPrompt(h, 'look', [{ data: 'x', mimeType: 'image/png' }])).not.toThrow();
|
|
75
|
+
expect(h.turns).toBe(1);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('sendAcpMidTurn', () => {
|
|
80
|
+
test('an agent with a steering extension gets the call', async () => {
|
|
81
|
+
const h = host();
|
|
82
|
+
await sendAcpMidTurn(h, 'steering', 'go on', undefined, true);
|
|
83
|
+
expect(h.steered).toHaveLength(1);
|
|
84
|
+
expect(h.queued).toEqual([]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('an agent without one gets the message HELD, not refused', async () => {
|
|
88
|
+
const h = host();
|
|
89
|
+
expect(await sendAcpMidTurn(h, 'followUp', 'later', undefined, false)).toEqual({ queued: true });
|
|
90
|
+
expect(h.queued).toEqual(['later']);
|
|
91
|
+
expect(h.steered).toEqual([]);
|
|
92
|
+
});
|
|
93
|
+
});
|