@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
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
isKnownToolName,
|
|
32
32
|
toolTypeFor,
|
|
33
33
|
} from '@/server/lib/harness/acp/mapper';
|
|
34
|
+
import { delegationLabel, resolveToolIdentity } from '@/server/lib/harness/acp/tool-identity';
|
|
34
35
|
import type { AcpToolKind, AcpToolStatus } from '@/server/lib/harness/acp/protocol';
|
|
35
36
|
|
|
36
37
|
/** The message block a tool card renders from. */
|
|
@@ -41,6 +42,8 @@ export interface ToolCallBlock {
|
|
|
41
42
|
arguments?: Record<string, unknown>;
|
|
42
43
|
toolKind?: AcpToolKind;
|
|
43
44
|
toolType?: string;
|
|
45
|
+
/** The adapter's own kind, when it is not one of the spec's ten. */
|
|
46
|
+
rawKind?: string;
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
interface OpenTool {
|
|
@@ -82,23 +85,30 @@ export class AcpToolCalls {
|
|
|
82
85
|
open(update: Record<string, unknown>): AgentEvent[] {
|
|
83
86
|
const toolCallId = typeof update.toolCallId === 'string' ? update.toolCallId : '';
|
|
84
87
|
if (!toolCallId) return [];
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const kind = typeof update.kind === 'string' ? (update.kind as AcpToolKind) : undefined;
|
|
91
|
-
const status = typeof update.status === 'string' ? (update.status as AcpToolStatus) : 'pending';
|
|
92
|
-
// A specific kind is authoritative. `other`/absent is only an explicit type
|
|
93
|
-
// when the name is one the renderers know; otherwise the shared parser's
|
|
94
|
-
// own inference from the name is better informed than a forced `read`.
|
|
95
|
-
const toolType = kind !== undefined && kind !== 'other'
|
|
96
|
-
? toolTypeFor(kind, name)
|
|
97
|
-
: isKnownToolName(name) ? toolTypeFor(kind, name) : undefined;
|
|
88
|
+
// The identity is resolved, not read off the top level: grok names its tool
|
|
89
|
+
// in `_meta` and cursor names it in `rawInput._toolName`, and reading only
|
|
90
|
+
// `update.name` made a subagent a generic tool (or, with `kind` alone, a
|
|
91
|
+
// file read).
|
|
92
|
+
const identity = resolveToolIdentity(update);
|
|
98
93
|
const rawInput = update.rawInput;
|
|
99
94
|
const args = rawInput && typeof rawInput === 'object' && !Array.isArray(rawInput)
|
|
100
95
|
? Object.fromEntries(Object.entries(rawInput))
|
|
101
96
|
: undefined;
|
|
97
|
+
const title = typeof update.title === 'string' ? update.title : undefined;
|
|
98
|
+
const name = identity.name ?? title ?? 'tool';
|
|
99
|
+
// A delegation IS a subagent: it gets the `task` panel, not the read/edit
|
|
100
|
+
// one, and its label is the child's task so the card says what it is doing.
|
|
101
|
+
const delegation = delegationLabel(name, args, title);
|
|
102
|
+
const kind = identity.kind;
|
|
103
|
+
const status = typeof update.status === 'string' ? (update.status as AcpToolStatus) : 'pending';
|
|
104
|
+
// A specific kind is authoritative. `other`/absent is only an explicit type
|
|
105
|
+
// when the name is one the renderers know; otherwise the shared parser's
|
|
106
|
+
// own inference from the name is better informed than a forced `read`.
|
|
107
|
+
const toolType = delegation
|
|
108
|
+
? 'task'
|
|
109
|
+
: kind !== undefined && kind !== 'other'
|
|
110
|
+
? toolTypeFor(kind, name)
|
|
111
|
+
: isKnownToolName(name) ? toolTypeFor(kind, name) : undefined;
|
|
102
112
|
|
|
103
113
|
this.host.pushBlock({
|
|
104
114
|
type: 'toolCall',
|
|
@@ -106,6 +116,7 @@ export class AcpToolCalls {
|
|
|
106
116
|
name,
|
|
107
117
|
...(args ? { arguments: args } : {}),
|
|
108
118
|
...(kind ? { toolKind: kind } : {}),
|
|
119
|
+
...(identity.rawKind ? { rawKind: identity.rawKind } : {}),
|
|
109
120
|
...(toolType ? { toolType } : {}),
|
|
110
121
|
});
|
|
111
122
|
|
|
@@ -121,7 +132,8 @@ export class AcpToolCalls {
|
|
|
121
132
|
toolName: name,
|
|
122
133
|
...(toolType ? { toolType } : {}),
|
|
123
134
|
...(args ? { args } : {}),
|
|
124
|
-
|
|
135
|
+
// The child's task for a delegation; the adapter's title otherwise.
|
|
136
|
+
...(delegation ?? title ? { intent: delegation ?? title } : {}),
|
|
125
137
|
...(acpToolTarget(update.locations, rawInput) ? { target: acpToolTarget(update.locations, rawInput) } : {}),
|
|
126
138
|
},
|
|
127
139
|
];
|
|
@@ -133,7 +145,7 @@ export class AcpToolCalls {
|
|
|
133
145
|
id: toolCallId,
|
|
134
146
|
name,
|
|
135
147
|
kind,
|
|
136
|
-
title
|
|
148
|
+
title,
|
|
137
149
|
status,
|
|
138
150
|
rawOutput: update.rawOutput,
|
|
139
151
|
content: update.content,
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A delegation must be RECOGNISED, whichever spelling the adapter uses.
|
|
8
|
+
*
|
|
9
|
+
* Four gaps, each measured against a real agent or a recorded frame:
|
|
10
|
+
*
|
|
11
|
+
* - grok sends its tool name only in `_meta["x.ai/tool"]`; reading the top
|
|
12
|
+
* level left `spawn_subagent` unnamed, so the background probe never ran and
|
|
13
|
+
* the subagent's answer was never surfaced;
|
|
14
|
+
* - cursor names the tool in `rawInput._toolName` (`"task"`), so `kind:"other"`
|
|
15
|
+
* alone made a subagent render as a file read;
|
|
16
|
+
* - an adapter's own kind (`delegate`, `subagent`) was cast to the spec enum
|
|
17
|
+
* and mapped to `read` instead of staying generic;
|
|
18
|
+
* - the `task` card's body only knew omp's `input.tasks[]`, so an ACP
|
|
19
|
+
* delegation drew an EMPTY card.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { describe, expect, test } from 'bun:test';
|
|
23
|
+
import { delegationLabel, normalizeKind, resolveToolIdentity } from '@/server/lib/harness/acp/tool-identity';
|
|
24
|
+
import { acpDelegationRow } from '@/client/components/workspace/chat-timeline/tool-renderers/panels/task-rows';
|
|
25
|
+
|
|
26
|
+
describe('resolveToolIdentity', () => {
|
|
27
|
+
test('grok names its tool in _meta and keeps the spec kind', () => {
|
|
28
|
+
expect(
|
|
29
|
+
resolveToolIdentity({ title: 'spawn subagent', _meta: { 'x.ai/tool': { name: 'spawn_subagent', kind: 'read' } } }),
|
|
30
|
+
).toEqual({ name: 'spawn_subagent', kind: 'read' });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('cursor names its tool in rawInput._toolName', () => {
|
|
34
|
+
expect(resolveToolIdentity({ title: 'Task: Subagent task', kind: 'other', rawInput: { _toolName: 'task' } })).toEqual({
|
|
35
|
+
name: 'task',
|
|
36
|
+
kind: 'other',
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('an adapter kind outside the spec becomes other, and is kept', () => {
|
|
41
|
+
expect(normalizeKind('delegate')).toEqual({ kind: 'other', rawKind: 'delegate' });
|
|
42
|
+
expect(normalizeKind('execute')).toEqual({ kind: 'execute' });
|
|
43
|
+
expect(normalizeKind(undefined)).toEqual({});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('delegationLabel', () => {
|
|
48
|
+
test('grok: description wins, then prompt, then the title', () => {
|
|
49
|
+
expect(delegationLabel('spawn_subagent', { description: 'audit auth' }, 'spawn')).toBe('audit auth');
|
|
50
|
+
expect(delegationLabel('spawn_subagent', { prompt: 'trace the bug' }, 'spawn')).toBe('trace the bug');
|
|
51
|
+
expect(delegationLabel('spawn_subagent', {}, 'spawn')).toBe('spawn');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('cursor: the wrapped task is a delegation with the title as its label', () => {
|
|
55
|
+
expect(delegationLabel('task', { _toolName: 'task' }, 'Task: Subagent task')).toBe('Task: Subagent task');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('an ordinary tool is not a delegation', () => {
|
|
59
|
+
expect(delegationLabel('bash', { command: 'ls' }, 'ls')).toBeNull();
|
|
60
|
+
expect(delegationLabel('read', undefined, 'read a.ts')).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('acpDelegationRow', () => {
|
|
65
|
+
test('grok’s child becomes the row the card draws', () => {
|
|
66
|
+
expect(acpDelegationRow({ description: 'audit auth', subagent_type: 'explore' }, undefined)).toEqual({
|
|
67
|
+
name: 'audit auth',
|
|
68
|
+
agent: 'explore',
|
|
69
|
+
task: 'audit auth',
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('a missing subagent_type is absent, never invented', () => {
|
|
74
|
+
expect(acpDelegationRow({ prompt: 'trace it' }, undefined)).toEqual({ name: 'trace it', task: 'trace it' });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('cursor’s wrapped task falls back to the intent for its label', () => {
|
|
78
|
+
expect(acpDelegationRow({ _toolName: 'task' }, 'Task: Subagent task')).toEqual({ name: 'Task: Subagent task' });
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('a call with no child is not a delegation', () => {
|
|
82
|
+
expect(acpDelegationRow(undefined, 'ls')).toBeNull();
|
|
83
|
+
expect(acpDelegationRow({ path: 'a.ts' }, 'read')).toBeNull();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('the card the frames produce', () => {
|
|
88
|
+
test('grok and cursor both land on the task panel with the child named', async () => {
|
|
89
|
+
const { AcpFrameMapper } = await import('@/server/lib/harness/acp/frames');
|
|
90
|
+
const mapper = new AcpFrameMapper();
|
|
91
|
+
mapper.reset();
|
|
92
|
+
const grok = mapper.mapUpdate({
|
|
93
|
+
sessionUpdate: 'tool_call',
|
|
94
|
+
toolCallId: 'g1',
|
|
95
|
+
title: 'spawn subagent',
|
|
96
|
+
status: 'pending',
|
|
97
|
+
rawInput: { description: 'audit auth', subagent_type: 'explore' },
|
|
98
|
+
_meta: { 'x.ai/tool': { name: 'spawn_subagent', kind: 'other' } },
|
|
99
|
+
});
|
|
100
|
+
const start = grok.find((event) => event.type === 'tool_execution_start');
|
|
101
|
+
expect(start).toMatchObject({ toolName: 'spawn_subagent', toolType: 'task', intent: 'audit auth' });
|
|
102
|
+
const block = grok.find((event) => event.type === 'message_update')?.message as { content: unknown[] };
|
|
103
|
+
expect(block.content).toContainEqual(
|
|
104
|
+
expect.objectContaining({ type: 'toolCall', name: 'spawn_subagent', toolType: 'task' }),
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const cursor = mapper.mapUpdate({
|
|
108
|
+
sessionUpdate: 'tool_call',
|
|
109
|
+
toolCallId: 'c1',
|
|
110
|
+
title: 'Task: Subagent task',
|
|
111
|
+
kind: 'other',
|
|
112
|
+
status: 'pending',
|
|
113
|
+
rawInput: { _toolName: 'task' },
|
|
114
|
+
});
|
|
115
|
+
expect(cursor.find((event) => event.type === 'tool_execution_start')).toMatchObject({
|
|
116
|
+
toolName: 'task',
|
|
117
|
+
toolType: 'task',
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('an adapter kind outside the spec stays generic, not a file read', async () => {
|
|
122
|
+
const { AcpFrameMapper } = await import('@/server/lib/harness/acp/frames');
|
|
123
|
+
const mapper = new AcpFrameMapper();
|
|
124
|
+
mapper.reset();
|
|
125
|
+
const frames = mapper.mapUpdate({
|
|
126
|
+
sessionUpdate: 'tool_call',
|
|
127
|
+
toolCallId: 'x1',
|
|
128
|
+
name: 'VendorWidget',
|
|
129
|
+
title: 'VendorWidget — ls',
|
|
130
|
+
kind: 'delegate',
|
|
131
|
+
status: 'pending',
|
|
132
|
+
});
|
|
133
|
+
const start = frames.find((event) => event.type === 'tool_execution_start');
|
|
134
|
+
expect(start?.toolType).toBeUndefined();
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Who a tool call IS, when the top-level fields do not say.
|
|
8
|
+
*
|
|
9
|
+
* Two ACP agents put the identity somewhere else, and both were rendered as a
|
|
10
|
+
* generic or WRONG tool before this module existed:
|
|
11
|
+
*
|
|
12
|
+
* - **grok** sends `name` and `kind` only inside `_meta["x.ai/tool"]`. With the
|
|
13
|
+
* top-level fields absent, a `spawn_subagent` fell back to the title
|
|
14
|
+
* ("spawn subagent") and the probe for work that outlives the turn never
|
|
15
|
+
* matched it.
|
|
16
|
+
* - **cursor** sends the real tool in `rawInput._toolName` (`"task"`), with
|
|
17
|
+
* `kind:"other"` and a title of "Task: Subagent task". `kind` alone therefore
|
|
18
|
+
* made a subagent look like a file read.
|
|
19
|
+
*
|
|
20
|
+
* `kind` is the spec's ten-value enum, but adapters invent more (`delegate`,
|
|
21
|
+
* `subagent`). An unknown value becomes `other` with the original kept as
|
|
22
|
+
* `rawKind` — the same rule bb applies — instead of being cast and then mapped
|
|
23
|
+
* to `read`, which is how a delegation drew a file-read panel.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type { AcpToolKind } from '@/server/lib/harness/acp/protocol';
|
|
27
|
+
|
|
28
|
+
const KNOWN_KINDS: Readonly<Record<AcpToolKind, true>> = {
|
|
29
|
+
read: true,
|
|
30
|
+
edit: true,
|
|
31
|
+
delete: true,
|
|
32
|
+
move: true,
|
|
33
|
+
search: true,
|
|
34
|
+
execute: true,
|
|
35
|
+
think: true,
|
|
36
|
+
fetch: true,
|
|
37
|
+
switch_mode: true,
|
|
38
|
+
other: true,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export interface AcpToolIdentity {
|
|
42
|
+
name?: string;
|
|
43
|
+
kind?: AcpToolKind;
|
|
44
|
+
/** The adapter's own kind, when it is not one of the spec's ten. */
|
|
45
|
+
rawKind?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function record(value: unknown): Record<string, unknown> | undefined {
|
|
49
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
50
|
+
? Object.fromEntries(Object.entries(value))
|
|
51
|
+
: undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The `{name, kind}` a vendor `_meta` carries, when it carries one. */
|
|
55
|
+
function metaIdentity(update: Record<string, unknown>): AcpToolIdentity {
|
|
56
|
+
const meta = record(update._meta);
|
|
57
|
+
const vendor = meta ? record(meta['x.ai/tool']) : undefined;
|
|
58
|
+
if (!vendor) return {};
|
|
59
|
+
return {
|
|
60
|
+
...(typeof vendor.name === 'string' && vendor.name ? { name: vendor.name } : {}),
|
|
61
|
+
...(typeof vendor.kind === 'string' ? { rawKind: vendor.kind } : {}),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** A spec `kind`, or `other` with the adapter's own value kept. */
|
|
66
|
+
export function normalizeKind(kind: string | undefined): { kind?: AcpToolKind; rawKind?: string } {
|
|
67
|
+
if (!kind) return {};
|
|
68
|
+
if (kind in KNOWN_KINDS) return { kind: kind as AcpToolKind };
|
|
69
|
+
return { kind: 'other', rawKind: kind };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The identity of one tool call: the top-level fields, with the vendor `_meta`
|
|
74
|
+
* filling in what they omit and `rawInput._toolName` naming the tool a wrapped
|
|
75
|
+
* adapter hides.
|
|
76
|
+
*/
|
|
77
|
+
export function resolveToolIdentity(update: Record<string, unknown>): AcpToolIdentity {
|
|
78
|
+
const meta = metaIdentity(update);
|
|
79
|
+
const rawInput = record(update.rawInput);
|
|
80
|
+
const wrapped = typeof rawInput?._toolName === 'string' ? rawInput._toolName : undefined;
|
|
81
|
+
const name = typeof update.name === 'string' && update.name
|
|
82
|
+
? update.name
|
|
83
|
+
: meta.name ?? wrapped;
|
|
84
|
+
const declared = typeof update.kind === 'string' ? update.kind : meta.rawKind;
|
|
85
|
+
return {
|
|
86
|
+
...(name ? { name } : {}),
|
|
87
|
+
...normalizeKind(declared),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Names that hand work to a process the turn does not await. */
|
|
92
|
+
const DELEGATION_NAMES: Readonly<Record<string, true>> = {
|
|
93
|
+
spawn_subagent: true,
|
|
94
|
+
invoke_subagent: true,
|
|
95
|
+
spawn_agent: true,
|
|
96
|
+
delegate: true,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Whether this call DELEGATES, and the sentence the card shows for it.
|
|
101
|
+
*
|
|
102
|
+
* A delegation is not a file read and not a generic tool: it is a child agent,
|
|
103
|
+
* and Kabmo's `task` panel is what renders one. The label comes from the
|
|
104
|
+
* adapter's own words (`description`, then `prompt`, then the title) because a
|
|
105
|
+
* blank subagent card tells the operator nothing about what it is doing.
|
|
106
|
+
*/
|
|
107
|
+
export function delegationLabel(
|
|
108
|
+
name: string | undefined,
|
|
109
|
+
rawInput: Record<string, unknown> | undefined,
|
|
110
|
+
title: string | undefined,
|
|
111
|
+
): string | null {
|
|
112
|
+
const bare = (name ?? '').toLowerCase();
|
|
113
|
+
const delegates = DELEGATION_NAMES[bare] === true || rawInput?._toolName === 'task';
|
|
114
|
+
if (!delegates) return null;
|
|
115
|
+
const detail = typeof rawInput?.description === 'string' && rawInput.description
|
|
116
|
+
? rawInput.description
|
|
117
|
+
: typeof rawInput?.prompt === 'string' && rawInput.prompt
|
|
118
|
+
? rawInput.prompt
|
|
119
|
+
: undefined;
|
|
120
|
+
return detail ?? title ?? 'Subagent';
|
|
121
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The grace window after a local Stop.
|
|
8
|
+
*
|
|
9
|
+
* A new prompt (or a second Stop) must free the chain AT ONCE — waiting out the
|
|
10
|
+
* window is what made "Stop, then send" sit for seconds. Only an unanswered
|
|
11
|
+
* cancel with nothing else to do waits.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, expect, test, vi } from 'bun:test';
|
|
15
|
+
import { CancelSettle } from '@/server/lib/harness/acp/turn-cancel';
|
|
16
|
+
|
|
17
|
+
describe('CancelSettle', () => {
|
|
18
|
+
test('settles once the window closes', () => {
|
|
19
|
+
vi.useFakeTimers();
|
|
20
|
+
try {
|
|
21
|
+
let settled = 0;
|
|
22
|
+
const settle = new CancelSettle(() => {
|
|
23
|
+
settled += 1;
|
|
24
|
+
}, 4_000);
|
|
25
|
+
settle.arm();
|
|
26
|
+
expect(settle.pending()).toBe(true);
|
|
27
|
+
vi.advanceTimersByTime(3_999);
|
|
28
|
+
expect(settled).toBe(0);
|
|
29
|
+
vi.advanceTimersByTime(1);
|
|
30
|
+
expect(settled).toBe(1);
|
|
31
|
+
expect(settle.pending()).toBe(false);
|
|
32
|
+
} finally {
|
|
33
|
+
vi.useRealTimers();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('flush settles immediately for a prompt that needs the chain', () => {
|
|
38
|
+
vi.useFakeTimers();
|
|
39
|
+
try {
|
|
40
|
+
let settled = 0;
|
|
41
|
+
const settle = new CancelSettle(() => {
|
|
42
|
+
settled += 1;
|
|
43
|
+
}, 4_000);
|
|
44
|
+
settle.arm();
|
|
45
|
+
settle.flush();
|
|
46
|
+
expect(settled).toBe(1);
|
|
47
|
+
vi.advanceTimersByTime(10_000);
|
|
48
|
+
expect(settled).toBe(1);
|
|
49
|
+
} finally {
|
|
50
|
+
vi.useRealTimers();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('disarm drops the wait without settling', () => {
|
|
55
|
+
vi.useFakeTimers();
|
|
56
|
+
try {
|
|
57
|
+
let settled = 0;
|
|
58
|
+
const settle = new CancelSettle(() => {
|
|
59
|
+
settled += 1;
|
|
60
|
+
}, 4_000);
|
|
61
|
+
settle.arm();
|
|
62
|
+
settle.disarm();
|
|
63
|
+
vi.advanceTimersByTime(10_000);
|
|
64
|
+
expect(settled).toBe(0);
|
|
65
|
+
expect(settle.pending()).toBe(false);
|
|
66
|
+
} finally {
|
|
67
|
+
vi.useRealTimers();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('flush on an idle window is a no-op', () => {
|
|
72
|
+
let settled = 0;
|
|
73
|
+
const settle = new CancelSettle(() => {
|
|
74
|
+
settled += 1;
|
|
75
|
+
});
|
|
76
|
+
settle.flush();
|
|
77
|
+
expect(settled).toBe(0);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The grace window after a local Stop.
|
|
8
|
+
*
|
|
9
|
+
* `session/cancel` is a notification and the agent may never answer the prompt it
|
|
10
|
+
* was given, so the outstanding `session/prompt` request has to be settled
|
|
11
|
+
* locally or the NEXT turn — chained behind it — never goes out. Settling it at
|
|
12
|
+
* once is wrong for the opposite reason: an agent that is still finishing its
|
|
13
|
+
* cancel answers a prompt that no longer exists, and its own turn boundary is
|
|
14
|
+
* lost.
|
|
15
|
+
*
|
|
16
|
+
* This object owns the middle: it waits, then settles, and a new prompt (or a
|
|
17
|
+
* second Stop) cancels the wait. The visible turn is closed separately and
|
|
18
|
+
* immediately — only the CHAIN waits.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const CANCEL_SETTLE_MS = 4_000;
|
|
22
|
+
|
|
23
|
+
export class CancelSettle {
|
|
24
|
+
#timer: ReturnType<typeof setTimeout> | null = null;
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
private readonly settle: () => void,
|
|
28
|
+
private readonly ms: number = CANCEL_SETTLE_MS,
|
|
29
|
+
) {}
|
|
30
|
+
|
|
31
|
+
/** Hold the outstanding request open for the grace window. */
|
|
32
|
+
arm(): void {
|
|
33
|
+
this.disarm();
|
|
34
|
+
const timer = setTimeout(() => {
|
|
35
|
+
if (this.#timer !== timer) return;
|
|
36
|
+
this.#timer = null;
|
|
37
|
+
this.settle();
|
|
38
|
+
}, this.ms);
|
|
39
|
+
timer.unref?.();
|
|
40
|
+
this.#timer = timer;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Settle now — a new prompt is the decision that the old turn is over. */
|
|
44
|
+
flush(): void {
|
|
45
|
+
if (this.#timer === null) return;
|
|
46
|
+
this.disarm();
|
|
47
|
+
this.settle();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Is the grace window still open? */
|
|
51
|
+
pending(): boolean {
|
|
52
|
+
return this.#timer !== null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Drop the wait without settling (a Stop that queued its successor). */
|
|
56
|
+
disarm(): void {
|
|
57
|
+
if (this.#timer === null) return;
|
|
58
|
+
clearTimeout(this.#timer);
|
|
59
|
+
this.#timer = null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The `session_busy` retry and the held-input queue, which are one behaviour.
|
|
8
|
+
*
|
|
9
|
+
* ACP has no queue: a second `session/prompt` while one is open cancels the
|
|
10
|
+
* first. So a message sent mid-turn waits (either in `TurnQueue`, because the
|
|
11
|
+
* agent has no steering extension, or in the agent's own window after a cancel),
|
|
12
|
+
* and the dispatch that follows can still meet `-32003 session_busy` while the
|
|
13
|
+
* agent finishes the previous turn. Treating that as a failed turn is what made
|
|
14
|
+
* "Stop, then send again" answer an error the operator could only work around by
|
|
15
|
+
* waiting.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { describe, expect, test } from 'bun:test';
|
|
19
|
+
import { AcpRequestError } from '@/server/lib/harness/acp/calls';
|
|
20
|
+
import { isSessionBusy, promptWithBusyRetry } from '@/server/lib/harness/acp/turn-dispatch';
|
|
21
|
+
import { TurnQueue } from '@/server/lib/harness/acp/turn-queue';
|
|
22
|
+
|
|
23
|
+
const busy = () => new AcpRequestError('Session is busy', -32003, { reason: 'session_busy' });
|
|
24
|
+
|
|
25
|
+
describe('isSessionBusy', () => {
|
|
26
|
+
test('recognises the code with the documented reason', () => {
|
|
27
|
+
expect(isSessionBusy(busy())).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('recognises the wording when the reason is absent', () => {
|
|
31
|
+
expect(isSessionBusy(new AcpRequestError('session_busy', -32003))).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('another error is not a busy signal', () => {
|
|
35
|
+
expect(isSessionBusy(new AcpRequestError('boom', -32603))).toBe(false);
|
|
36
|
+
expect(isSessionBusy(new Error('session_busy'))).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('promptWithBusyRetry', () => {
|
|
41
|
+
test('retries a busy refusal and returns the eventual answer', async () => {
|
|
42
|
+
let calls = 0;
|
|
43
|
+
const result = await promptWithBusyRetry(async () => {
|
|
44
|
+
calls += 1;
|
|
45
|
+
if (calls < 3) throw busy();
|
|
46
|
+
return { stopReason: 'end_turn' };
|
|
47
|
+
}, { waitMs: 0, isActive: () => true });
|
|
48
|
+
expect(result).toEqual({ stopReason: 'end_turn' });
|
|
49
|
+
expect(calls).toBe(3);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('gives up after the retry budget', async () => {
|
|
53
|
+
let calls = 0;
|
|
54
|
+
await expect(
|
|
55
|
+
promptWithBusyRetry(async () => {
|
|
56
|
+
calls += 1;
|
|
57
|
+
throw busy();
|
|
58
|
+
}, { retries: 2, waitMs: 0, isActive: () => true }),
|
|
59
|
+
).rejects.toThrow('Session is busy');
|
|
60
|
+
expect(calls).toBe(3);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('a cancelled turn stops retrying at once', async () => {
|
|
64
|
+
let calls = 0;
|
|
65
|
+
await expect(
|
|
66
|
+
promptWithBusyRetry(async () => {
|
|
67
|
+
calls += 1;
|
|
68
|
+
throw busy();
|
|
69
|
+
}, { waitMs: 0, isActive: () => false }),
|
|
70
|
+
).rejects.toThrow('Session is busy');
|
|
71
|
+
expect(calls).toBe(1);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('a non-busy failure is never retried', async () => {
|
|
75
|
+
let calls = 0;
|
|
76
|
+
await expect(
|
|
77
|
+
promptWithBusyRetry(async () => {
|
|
78
|
+
calls += 1;
|
|
79
|
+
throw new AcpRequestError('provider down', -32603);
|
|
80
|
+
}, { waitMs: 0, isActive: () => true }),
|
|
81
|
+
).rejects.toThrow('provider down');
|
|
82
|
+
expect(calls).toBe(1);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('TurnQueue', () => {
|
|
87
|
+
test('holds inputs in arrival order and reports its size', () => {
|
|
88
|
+
const queue = new TurnQueue();
|
|
89
|
+
queue.push({ message: 'first', images: undefined });
|
|
90
|
+
queue.push({ message: 'second', images: undefined });
|
|
91
|
+
expect(queue.size).toBe(2);
|
|
92
|
+
expect(queue.shift()?.message).toBe('first');
|
|
93
|
+
expect(queue.shift()?.message).toBe('second');
|
|
94
|
+
expect(queue.shift()).toBeUndefined();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('clear drops everything a finished session will never dispatch', () => {
|
|
98
|
+
const queue = new TurnQueue();
|
|
99
|
+
queue.push({ message: 'x', images: undefined });
|
|
100
|
+
queue.clear();
|
|
101
|
+
expect(queue.size).toBe(0);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The retry an ACP agent's OWN "busy" refusal needs.
|
|
8
|
+
*
|
|
9
|
+
* `-32003 session_busy` is not a failed turn: the agent still considers the
|
|
10
|
+
* previous prompt open (omp answers it when a cancel has not settled yet, and an
|
|
11
|
+
* agent that just answered a steer can be busy for a moment). Treating it as an
|
|
12
|
+
* error is what made "Stop, then send again" fail with a message the operator
|
|
13
|
+
* could only work around by waiting. bb waits for the agent to go quiet and
|
|
14
|
+
* retries three times; this is that rule, with the wait injectable so a test
|
|
15
|
+
* does not spend seconds asleep.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { AcpRequestError } from '@/server/lib/harness/acp/calls';
|
|
19
|
+
|
|
20
|
+
export const SESSION_BUSY_CODE = -32003;
|
|
21
|
+
export const SESSION_BUSY_MAX_RETRIES = 3;
|
|
22
|
+
export const SESSION_BUSY_WAIT_MS = 2_000;
|
|
23
|
+
|
|
24
|
+
/** Whether the agent refused because it is still processing. */
|
|
25
|
+
export function isSessionBusy(error: unknown): boolean {
|
|
26
|
+
if (!(error instanceof AcpRequestError) || error.code !== SESSION_BUSY_CODE) return false;
|
|
27
|
+
const data = error.data;
|
|
28
|
+
if (data && typeof data === 'object' && 'reason' in data) {
|
|
29
|
+
return data.reason === 'session_busy';
|
|
30
|
+
}
|
|
31
|
+
return /session[ _]?busy/i.test(error.message);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface BusyRetryOptions {
|
|
35
|
+
/** Give up after this many retries (the first attempt is not a retry). */
|
|
36
|
+
retries?: number;
|
|
37
|
+
/** Quiet window between attempts. */
|
|
38
|
+
waitMs?: number;
|
|
39
|
+
/** Stop retrying once the turn was cancelled or the session died. */
|
|
40
|
+
isActive: () => boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Dispatch one prompt, retrying the agent's `session_busy` answer. */
|
|
44
|
+
export async function promptWithBusyRetry<T>(
|
|
45
|
+
dispatch: () => Promise<T>,
|
|
46
|
+
options: BusyRetryOptions,
|
|
47
|
+
): Promise<T> {
|
|
48
|
+
const retries = options.retries ?? SESSION_BUSY_MAX_RETRIES;
|
|
49
|
+
let attempt = 0;
|
|
50
|
+
for (;;) {
|
|
51
|
+
try {
|
|
52
|
+
return await dispatch();
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (!isSessionBusy(error) || attempt >= retries || !options.isActive()) throw error;
|
|
55
|
+
attempt += 1;
|
|
56
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
57
|
+
setTimeout(resolve, options.waitMs ?? SESSION_BUSY_WAIT_MS);
|
|
58
|
+
await promise;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|