@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
|
@@ -5,6 +5,7 @@ import { MarkdownRenderer } from '@/client/components/common/MarkdownRenderer';
|
|
|
5
5
|
import { tryParseJson } from '@/shared/lib/code/syntax-highlight';
|
|
6
6
|
import { JsonCodeBlock } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/JsonCodeBlock';
|
|
7
7
|
import { formatCompactTokens, formatCost } from '@/shared/lib/format/number';
|
|
8
|
+
import { acpDelegationRow } from '@/client/components/workspace/chat-timeline/tool-renderers/panels/task-rows';
|
|
8
9
|
|
|
9
10
|
interface TaskRow {
|
|
10
11
|
id?: unknown;
|
|
@@ -77,9 +78,18 @@ export function TaskResult({ tool }: { tool: ToolCallData }) {
|
|
|
77
78
|
const inputContext = typeof inputObj?.context === 'string' ? inputObj.context.trim() : '';
|
|
78
79
|
const inputTasks = Array.isArray(inputObj?.tasks) ? (inputObj.tasks as InputTask[]) : [];
|
|
79
80
|
|
|
81
|
+
// An ACP agent sends ONE child in its own spelling (grok's `description`/
|
|
82
|
+
// `subagent_type`, cursor's `_toolName`), never omp's `tasks[]`. Without this
|
|
83
|
+
// a delegation card from those agents rendered as an empty card.
|
|
84
|
+
const acpRow = useMemo(
|
|
85
|
+
() => acpDelegationRow(inputObj, typeof tool.intent === 'string' ? tool.intent : undefined),
|
|
86
|
+
[inputObj, tool.intent],
|
|
87
|
+
);
|
|
88
|
+
|
|
80
89
|
const rows: TaskRow[] = useMemo(() => {
|
|
81
90
|
if (results.length > 0) return results;
|
|
82
91
|
if (progress.length > 0) return progress;
|
|
92
|
+
if (acpRow) return [{ ...acpRow, id: tool.id, status: tool.status === 'success' ? 'done' : 'running' }];
|
|
83
93
|
if (inputTasks.length > 0) {
|
|
84
94
|
return inputTasks.map((t, idx) => ({
|
|
85
95
|
id: `task-sub-${idx}`,
|
|
@@ -90,9 +100,13 @@ export function TaskResult({ tool }: { tool: ToolCallData }) {
|
|
|
90
100
|
}));
|
|
91
101
|
}
|
|
92
102
|
return [];
|
|
93
|
-
}, [results, progress, inputTasks, tool.status]);
|
|
103
|
+
}, [results, progress, acpRow, inputTasks, tool.id, tool.status]);
|
|
94
104
|
|
|
95
|
-
|
|
105
|
+
// The ACP child's brief is its task, and it is shown as the specification
|
|
106
|
+
// block below; `acpRow` already contributed the row above it.
|
|
107
|
+
const specTasks: Array<{ name?: string; agent?: string; task?: string; assignment?: string }> =
|
|
108
|
+
inputTasks.length > 0 ? inputTasks : acpRow?.task ? [acpRow] : [];
|
|
109
|
+
if (rows.length === 0 && !tool.output && !inputContext && specTasks.length === 0) return null;
|
|
96
110
|
|
|
97
111
|
const totalTokens = rows.reduce((sum, r) => sum + (typeof r.tokens === 'number' ? r.tokens : 0), 0);
|
|
98
112
|
const totalCost = rows.reduce((sum, r) => sum + (typeof r.cost === 'number' ? r.cost : 0), 0);
|
|
@@ -174,7 +188,7 @@ export function TaskResult({ tool }: { tool: ToolCallData }) {
|
|
|
174
188
|
)}
|
|
175
189
|
|
|
176
190
|
{/* 3. Task Specifications (Target, Change, Acceptance) */}
|
|
177
|
-
{
|
|
191
|
+
{specTasks.length > 0 && (
|
|
178
192
|
<div className="overflow-hidden rounded-lg border border-ink/8 bg-paper">
|
|
179
193
|
<button
|
|
180
194
|
type="button"
|
|
@@ -192,7 +206,7 @@ export function TaskResult({ tool }: { tool: ToolCallData }) {
|
|
|
192
206
|
</button>
|
|
193
207
|
{tasksExpanded && (
|
|
194
208
|
<div className="divide-y divide-ink/8 border-t border-ink/8 bg-canvas/30">
|
|
195
|
-
{
|
|
209
|
+
{specTasks.map((t, idx) => (
|
|
196
210
|
<div key={idx} className="p-3 space-y-1.5 text-[11.5px] text-ink/80 select-text">
|
|
197
211
|
<div className="flex items-center gap-2">
|
|
198
212
|
<span className="font-semibold text-ink text-[12px]">{t.name || `Task #${idx + 1}`}</span>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The rows a `task` card draws, from either producer's shape.
|
|
8
|
+
*
|
|
9
|
+
* omp sends `input.tasks[]` — one entry per delegated worker, with `name` and
|
|
10
|
+
* `agent`. ACP adapters send ONE child in a different spelling: grok's
|
|
11
|
+
* `{description, prompt, subagent_type}` and cursor's `{_toolName:"task"}` with
|
|
12
|
+
* the words only in the title. The panel judged `rows.length === 0 && !output &&
|
|
13
|
+
* !context` and returned null, so a delegation from an ACP agent rendered as an
|
|
14
|
+
* EMPTY card — the call existed in the transcript and showed nothing.
|
|
15
|
+
*
|
|
16
|
+
* One normalizer keeps both shapes drawing the same card, and a missing
|
|
17
|
+
* `subagent_type` is reported as absent rather than invented as `scout`.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export interface TaskRowShape {
|
|
21
|
+
name: string;
|
|
22
|
+
agent?: string;
|
|
23
|
+
task?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The delegated child a non-omp adapter named, or null when the call carries
|
|
27
|
+
* no child at all (an omp `task` with an empty list is not a delegation). */
|
|
28
|
+
export function acpDelegationRow(
|
|
29
|
+
input: Record<string, unknown> | undefined,
|
|
30
|
+
intent: string | undefined,
|
|
31
|
+
): TaskRowShape | null {
|
|
32
|
+
if (!input) return null;
|
|
33
|
+
const description = typeof input.description === 'string' ? input.description.trim() : '';
|
|
34
|
+
const prompt = typeof input.prompt === 'string' ? input.prompt.trim() : '';
|
|
35
|
+
const subagent = typeof input.subagent_type === 'string' ? input.subagent_type.trim() : '';
|
|
36
|
+
const wrapped = input._toolName === 'task';
|
|
37
|
+
const task = description || prompt;
|
|
38
|
+
if (!task && !wrapped && !subagent) return null;
|
|
39
|
+
const label = task || intent?.trim() || 'Subagent';
|
|
40
|
+
return {
|
|
41
|
+
// The clamped first line is the card's row label; the full text is the
|
|
42
|
+
// brief, which is what the operator needs to approve the delegation.
|
|
43
|
+
name: label.split('\n')[0].slice(0, 80),
|
|
44
|
+
...(subagent ? { agent: subagent } : {}),
|
|
45
|
+
...(task ? { task } : {}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
2
2
|
import type { RefObject } from 'preact/compat';
|
|
3
3
|
import type { AgentImage, ChatMessageData, OmpAgentCallbacks, OmpAgentHandle, OmpAgentState, PromptDispatchResult } from '@/shared/types';
|
|
4
|
-
import type { ExtensionUiDialogRequest } from '@/shared/types/omp/agent';
|
|
4
|
+
import type { ExtensionDialogResponse, ExtensionUiDialogRequest } from '@/shared/types/omp/agent';
|
|
5
5
|
import { type ToolResultRecord, useOmpAgentStream } from '@/client/hooks/chat/omp/stream';
|
|
6
6
|
import { useOmpPromptSender } from '@/client/hooks/chat/omp/prompt-send';
|
|
7
7
|
import { stopAgentSession } from '@/shared/lib/chat/omp/abort';
|
|
@@ -263,11 +263,7 @@ export function useOmpAgent(
|
|
|
263
263
|
/** Jawab dialog ask/approval (extension_ui_response) — melepas blocking tool call. */
|
|
264
264
|
const respondToExtensionUi = useCallback(async (
|
|
265
265
|
request: ExtensionUiDialogRequest,
|
|
266
|
-
response:
|
|
267
|
-
| { value: string }
|
|
268
|
-
| { confirmed: boolean }
|
|
269
|
-
| { cancelled: true }
|
|
270
|
-
| { answers: { id: string; selectedOptions: string[]; customInput?: string }[] },
|
|
266
|
+
response: ExtensionDialogResponse,
|
|
271
267
|
): Promise<void> => {
|
|
272
268
|
const sid = sessionIdRef.current;
|
|
273
269
|
if (!sid) return;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A write the AGENT performed through this client (`fs/write_text_file`).
|
|
8
|
+
*
|
|
9
|
+
* It runs no tool of its own, so there is no `tool_execution_start`/end pair to
|
|
10
|
+
* journal: the write event carries both sides, and that is the whole record. The
|
|
11
|
+
* journal's start-frame snapshot never ran either, which is why the before side
|
|
12
|
+
* must travel with the event — reading the file after the write would report no
|
|
13
|
+
* change at all.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
17
|
+
import type { PendingCall } from '@/server/lib/changes/capture-types';
|
|
18
|
+
|
|
19
|
+
/** The pending call a client-side write journals as. */
|
|
20
|
+
export function clientWriteCall(event: AgentEvent, run: { runId: string | null; runAt: number }): PendingCall {
|
|
21
|
+
const target = typeof event.path === 'string' ? event.path : '';
|
|
22
|
+
return {
|
|
23
|
+
toolCallId: typeof event.toolCallId === 'string' ? event.toolCallId : `fs-${Bun.randomUUIDv7()}`,
|
|
24
|
+
...(run.runId !== null ? { runId: run.runId, runAt: run.runAt } : {}),
|
|
25
|
+
tool: typeof event.toolName === 'string' && event.toolName ? event.toolName : 'write',
|
|
26
|
+
agent: 'Main',
|
|
27
|
+
startedAt: Date.now(),
|
|
28
|
+
args: { path: target },
|
|
29
|
+
before: new Map(),
|
|
30
|
+
ready: Promise.resolve(),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Both sides of the write, as the journal records them. */
|
|
35
|
+
export function clientWriteSides(event: AgentEvent): { before: string | null; after: string | null } {
|
|
36
|
+
return {
|
|
37
|
+
before: typeof event.before === 'string' ? event.before : null,
|
|
38
|
+
after: typeof event.after === 'string' ? event.after : null,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Whether the event names a path at all. */
|
|
43
|
+
export function clientWriteTarget(event: AgentEvent): string {
|
|
44
|
+
return typeof event.path === 'string' ? event.path : '';
|
|
45
|
+
}
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* already on disk is left alone rather than journaled as a no-op.
|
|
26
26
|
*
|
|
27
27
|
* The trace is read BEFORE the first `await` in `#end`: `EventFanout` strips it
|
|
28
|
-
* from the frame
|
|
28
|
+
* from the frame right after the raw listeners return.
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
31
|
import { isRecord } from '@/shared/lib/util/guards';
|
|
@@ -51,6 +51,7 @@ import { isBuildPath, isExcludedTempPath, isInside } from '@/server/lib/changes/
|
|
|
51
51
|
import { captureTargets } from '@/server/lib/changes/capture-targets';
|
|
52
52
|
import { reconstructEdit, resolveRacedWrite } from '@/server/lib/changes/capture-write.server';
|
|
53
53
|
import { MAX_BLOB_BYTES } from '@/server/lib/changes/blobs.server';
|
|
54
|
+
import { clientWriteCall, clientWriteSides, clientWriteTarget } from '@/server/lib/changes/capture-client-write.server';
|
|
54
55
|
|
|
55
56
|
export class ChangeCapture {
|
|
56
57
|
readonly #pending = new Map<string, PendingCall>();
|
|
@@ -88,9 +89,24 @@ export class ChangeCapture {
|
|
|
88
89
|
case 'subagent_event':
|
|
89
90
|
this.#subagent(event);
|
|
90
91
|
break;
|
|
92
|
+
case 'fs_write':
|
|
93
|
+
// An ACP agent that writes through the CLIENT (`fs/write_text_file`)
|
|
94
|
+
// runs no tool of its own, so there is no start/end pair to journal. The
|
|
95
|
+
// write carries both sides, which is the whole record.
|
|
96
|
+
this.#track(this.#clientWrite(event));
|
|
97
|
+
break;
|
|
91
98
|
}
|
|
92
99
|
}
|
|
93
100
|
|
|
101
|
+
/** Journal one write the AGENT performed through this client. */
|
|
102
|
+
async #clientWrite(event: AgentEvent): Promise<void> {
|
|
103
|
+
const target = clientWriteTarget(event);
|
|
104
|
+
if (!target) return;
|
|
105
|
+
const call = clientWriteCall(event, { runId: this.#runId, runAt: this.#runAt });
|
|
106
|
+
const { before, after } = clientWriteSides(event);
|
|
107
|
+
await this.#writeChange(call, target, before, after, 'tool');
|
|
108
|
+
}
|
|
109
|
+
|
|
94
110
|
/** Await every in-flight capture and the journal's own append chain. */
|
|
95
111
|
async flush(): Promise<void> {
|
|
96
112
|
await Promise.all([...this.#tasks]);
|
|
@@ -194,8 +210,7 @@ export class ChangeCapture {
|
|
|
194
210
|
if (!pending) return;
|
|
195
211
|
this.#pending.delete(toolCallId);
|
|
196
212
|
// Read the trace BEFORE the first await: `EventFanout` strips it from the
|
|
197
|
-
// frame
|
|
198
|
-
// resumes later.
|
|
213
|
+
// frame right after the raw listeners return, and this resumes later.
|
|
199
214
|
const trace = extractTrace(event);
|
|
200
215
|
await pending.ready;
|
|
201
216
|
const isShell = pending.tool === 'bash' || typeof pending.args.command === 'string';
|
|
@@ -206,8 +221,8 @@ export class ChangeCapture {
|
|
|
206
221
|
async #endFileTool(pending: PendingCall): Promise<void> {
|
|
207
222
|
const targets = captureTargets(pending, this.deps.cwd);
|
|
208
223
|
if (targets.length === 0) {
|
|
209
|
-
// A read-only tool
|
|
210
|
-
//
|
|
224
|
+
// A read-only tool has no adapter and no mutation; only a tool whose NAME
|
|
225
|
+
// promises a write is worth a note.
|
|
211
226
|
if (MUTATING_TOOL.test(pending.tool)) {
|
|
212
227
|
await this.deps.journal.recordNote({
|
|
213
228
|
at: Date.now(),
|
|
@@ -28,6 +28,7 @@ import { ensurePromptHistorySchema } from '@/server/lib/chat/schema.server';
|
|
|
28
28
|
import { ensureSessionMcpSchema } from '@/server/lib/mcp/schema.server';
|
|
29
29
|
import { ensureNotificationSchema } from '@/server/lib/notifications/schema.server';
|
|
30
30
|
import { ensureConnectSchema } from '@/server/lib/connect/devices.server';
|
|
31
|
+
import { ensureAcpGrantSchema } from '@/server/lib/harness/acp/grants.server';
|
|
31
32
|
import { migrateWorkspaceFolderColumns } from '@/shared/lib/workspace/schema-migrations';
|
|
32
33
|
import { migrateSessionStreamStateColumns } from '@/shared/lib/omp/session/schema-migrations';
|
|
33
34
|
|
|
@@ -170,6 +171,8 @@ export async function initSchema(db: DbClient): Promise<void> {
|
|
|
170
171
|
// Paired devices and their token hashes: the Connect page's list, and the
|
|
171
172
|
// credential the auth gate verifies on every request from a phone.
|
|
172
173
|
await ensureConnectSchema(db);
|
|
174
|
+
// An ACP "always allow" decision survives the child it was made to.
|
|
175
|
+
await ensureAcpGrantSchema(db);
|
|
173
176
|
await db.exec(`
|
|
174
177
|
CREATE TABLE IF NOT EXISTS files (
|
|
175
178
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The `authenticate` step and the sentence a refused handshake shows.
|
|
8
|
+
*
|
|
9
|
+
* The failure this pins: an agent that advertises `cached_token` was asked for a
|
|
10
|
+
* session it refused with `-32000 Authentication required`, and the operator got
|
|
11
|
+
* that sentence with no command to run. Both halves matter — calling the method
|
|
12
|
+
* when one is usable, and naming the agent's own sign-in line when none is.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
import { authMethodsOf, describeSignIn, headlessAuthMethod, isAuthRequiredError } from '@/server/lib/harness/acp/auth';
|
|
17
|
+
|
|
18
|
+
describe('headlessAuthMethod', () => {
|
|
19
|
+
test('prefers the machine credential', () => {
|
|
20
|
+
expect(headlessAuthMethod([{ id: 'cursor_login', type: 'terminal' }, { id: 'cached_token' }], {})).toBe('cached_token');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('adopts an env-keyed method only when that variable is set', () => {
|
|
24
|
+
const methods = [{ id: 'xai.api_key' }];
|
|
25
|
+
expect(headlessAuthMethod(methods, {})).toBeNull();
|
|
26
|
+
expect(headlessAuthMethod(methods, { XAI_API_KEY: 'k' })).toBe('xai.api_key');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('a terminal-only agent yields no call at all', () => {
|
|
30
|
+
expect(headlessAuthMethod([{ id: 'cursor_login', type: 'terminal' }], {})).toBeNull();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('describeSignIn', () => {
|
|
35
|
+
test('prints the launch line plus the terminal method args and env', () => {
|
|
36
|
+
expect(
|
|
37
|
+
describeSignIn(
|
|
38
|
+
[{ id: 'login', type: 'terminal', args: ['--login'], env: { GROK_HOME: '/tmp/g' } }],
|
|
39
|
+
'grok agent stdio',
|
|
40
|
+
),
|
|
41
|
+
).toBe('To sign in, run this in a terminal on this machine, then try again: GROK_HOME=/tmp/g grok agent stdio --login');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('names the offered methods when none is a terminal command', () => {
|
|
45
|
+
expect(describeSignIn([{ id: 'a', name: 'Sign in A' }, { id: 'b', name: 'Sign in B' }], 'x acp')).toContain(
|
|
46
|
+
'Sign in A, Sign in B',
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('nothing to say when the agent offered nothing', () => {
|
|
51
|
+
expect(describeSignIn([], 'x acp')).toBeNull();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('isAuthRequiredError', () => {
|
|
56
|
+
test('recognises the spec code and the agent’s own wording', () => {
|
|
57
|
+
expect(isAuthRequiredError(Object.assign(new Error('nope'), { code: -32000 }))).toBe(true);
|
|
58
|
+
expect(isAuthRequiredError(new Error('Authentication required: run grok login'))).toBe(true);
|
|
59
|
+
expect(isAuthRequiredError(new Error('session not found'))).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('authMethodsOf', () => {
|
|
64
|
+
test('drops entries without an id', () => {
|
|
65
|
+
expect(authMethodsOf({ protocolVersion: 1, authMethods: [{ id: 'a', name: 'A' }, { name: 'B' } as never] })).toEqual([
|
|
66
|
+
{ id: 'a', name: 'A' },
|
|
67
|
+
]);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The `authenticate` step of an ACP handshake.
|
|
8
|
+
*
|
|
9
|
+
* `initialize` lists the ways in; a client that never calls `authenticate` makes
|
|
10
|
+
* every agent that requires a login refuse `session/new` with `-32000`, which
|
|
11
|
+
* surfaces to the operator as a raw spawn failure naming nothing actionable.
|
|
12
|
+
* Only a HEADLESS method is attempted — a `terminal` method wants a TTY Kabmo
|
|
13
|
+
* does not host, and asking for one parks the spawn instead of explaining it.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { AcpInitializeResult } from '@/server/lib/harness/acp/protocol';
|
|
17
|
+
|
|
18
|
+
export interface AcpAuthMethod {
|
|
19
|
+
id: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
type?: string;
|
|
23
|
+
args?: string[];
|
|
24
|
+
env?: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The method a client may call without a terminal, or null. */
|
|
28
|
+
export function headlessAuthMethod(
|
|
29
|
+
methods: readonly AcpAuthMethod[],
|
|
30
|
+
env: Record<string, string | undefined>,
|
|
31
|
+
): string | null {
|
|
32
|
+
// `cached_token` means "the credential this machine already stores", which is
|
|
33
|
+
// exactly what a headless client can rely on. A method whose id names an env
|
|
34
|
+
// var (`xai.api_key` ← `XAI_API_KEY`) is adopted only when that var is set.
|
|
35
|
+
if (methods.some((method) => method.id === 'cached_token')) return 'cached_token';
|
|
36
|
+
for (const method of methods) {
|
|
37
|
+
const fromEnv = method.id.toUpperCase().replace(/[.-]/g, '_');
|
|
38
|
+
const present = env[fromEnv] ?? env[method.id];
|
|
39
|
+
if (present) return method.id;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Every `authMethods` entry, narrowed from the raw initialize answer. */
|
|
45
|
+
export function authMethodsOf(init: AcpInitializeResult): AcpAuthMethod[] {
|
|
46
|
+
const raw = init.authMethods;
|
|
47
|
+
if (!Array.isArray(raw)) return [];
|
|
48
|
+
return raw.flatMap((entry) => (entry && typeof entry === 'object' && typeof entry.id === 'string' ? [entry] : []));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The sentence a failed spawn shows when the agent wants a login. */
|
|
52
|
+
export function describeSignIn(methods: readonly AcpAuthMethod[], command: string): string | null {
|
|
53
|
+
const terminal = methods.find((method) => method.type === 'terminal');
|
|
54
|
+
if (terminal) {
|
|
55
|
+
const parts = [...command.split(' ').filter(Boolean), ...(terminal.args ?? [])];
|
|
56
|
+
const env = Object.entries(terminal.env ?? {}).map(([name, value]) => `${name}=${value}`);
|
|
57
|
+
const line = [...env, parts.join(' ')].join(' ');
|
|
58
|
+
return `To sign in, run this in a terminal on this machine, then try again: ${line}`;
|
|
59
|
+
}
|
|
60
|
+
const names = methods.map((method) => method.name?.trim() || method.id).filter(Boolean);
|
|
61
|
+
if (names.length === 0) return null;
|
|
62
|
+
return `The agent offers these ways to sign in: ${names.slice(0, 4).join(', ')}${names.length > 4 ? ` and ${names.length - 4} more` : ''}. Sign in with the agent's own command on this machine, then try again.`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Whether a thrown error is the agent asking for a login. */
|
|
66
|
+
export function isAuthRequiredError(error: unknown): boolean {
|
|
67
|
+
const code = (error as { code?: unknown } | null)?.code;
|
|
68
|
+
if (code === -32000) return true;
|
|
69
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
70
|
+
return /authentication required|not authenticated|sign in/i.test(message);
|
|
71
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A held replay's WORK is a notice too.
|
|
8
|
+
*
|
|
9
|
+
* Measured on agy 1.5.3 against a real 155 s run: the replay carried
|
|
10
|
+
* `read_file` and a failed `run_command` after the holding sentence and NO new
|
|
11
|
+
* assistant text, so a probe that waited for prose delivered nothing until its
|
|
12
|
+
* ceiling. These cases pin the collection and the dedupe.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
import { collectReplayFrame, newToolNotice, type ReplaySegment } from '@/server/lib/harness/acp/background-replay';
|
|
17
|
+
import { AcpBackgroundProbe } from '@/server/lib/harness/acp/background-work';
|
|
18
|
+
|
|
19
|
+
const seg = (): ReplaySegment => ({ text: '', sawUser: false, tools: [] });
|
|
20
|
+
|
|
21
|
+
describe('replay collection', () => {
|
|
22
|
+
test('a tool_call and its update are ONE row, latest status kept', () => {
|
|
23
|
+
const s = seg();
|
|
24
|
+
collectReplayFrame(s, { sessionUpdate: 'tool_call', toolCallId: 't1', name: 'read_file', status: 'pending' });
|
|
25
|
+
collectReplayFrame(s, { sessionUpdate: 'tool_call_update', toolCallId: 't1', status: 'completed' });
|
|
26
|
+
expect(s.tools).toEqual([{ id: 't1', name: 'read_file', status: 'completed' }]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('a user chunk starts a new segment', () => {
|
|
30
|
+
const s = seg();
|
|
31
|
+
collectReplayFrame(s, { sessionUpdate: 'agent_message_chunk', content: { type: 'text', text: 'old' } });
|
|
32
|
+
collectReplayFrame(s, { sessionUpdate: 'user_message_chunk', content: { type: 'text', text: 'q' } });
|
|
33
|
+
expect(s.text).toBe('');
|
|
34
|
+
expect(s.sawUser).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('the notice marks status and is reported once per call', () => {
|
|
38
|
+
const s = seg();
|
|
39
|
+
s.tools.push({ id: 'a', name: 'read_file', status: 'completed' }, { id: 'b', name: 'run_command', status: 'failed' });
|
|
40
|
+
const reported = new Set<string>();
|
|
41
|
+
expect(newToolNotice(s, reported)).toBe('The subagent continued working:\n✓ read_file\n✗ run_command');
|
|
42
|
+
expect(newToolNotice(s, reported)).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('a long list is summarized', () => {
|
|
46
|
+
const s = seg();
|
|
47
|
+
for (let i = 0; i < 7; i += 1) s.tools.push({ id: `t${i}`, name: 'run_command', status: 'completed' });
|
|
48
|
+
expect(newToolNotice(s, new Set())).toContain('… and 2 more');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('the probe against a textless replay', () => {
|
|
53
|
+
test('a replay that only ran tools still reaches the operator', async () => {
|
|
54
|
+
// A deterministic queue, not wall-clock sleeps: the probe's schedule is
|
|
55
|
+
// injected, so each tick runs exactly one callback.
|
|
56
|
+
const scheduled: Array<() => void> = [];
|
|
57
|
+
const emitted: string[] = [];
|
|
58
|
+
const run = async (ticks: number): Promise<void> => {
|
|
59
|
+
for (let i = 0; i < ticks; i += 1) {
|
|
60
|
+
const next = scheduled.shift();
|
|
61
|
+
next?.();
|
|
62
|
+
for (let hop = 0; hop < 8; hop += 1) await Promise.resolve();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
let probe!: AcpBackgroundProbe;
|
|
66
|
+
probe = new AcpBackgroundProbe({
|
|
67
|
+
load: async () => {
|
|
68
|
+
probe.consume('session/update', { update: { sessionUpdate: 'user_message_chunk', content: { type: 'text', text: 'buat banner' } } });
|
|
69
|
+
probe.consume('session/update', { update: { sessionUpdate: 'agent_message_chunk', content: { type: 'text', text: 'Siap, langsung saya buatkan.' } } });
|
|
70
|
+
probe.consume('session/update', { update: { sessionUpdate: 'tool_call', toolCallId: 'r1', name: 'read_file', status: 'completed' } });
|
|
71
|
+
probe.consume('session/update', { update: { sessionUpdate: 'tool_call', toolCallId: 'c1', name: 'run_command', status: 'failed' } });
|
|
72
|
+
return {};
|
|
73
|
+
},
|
|
74
|
+
resetIdle: () => {},
|
|
75
|
+
emit: (text) => emitted.push(text),
|
|
76
|
+
firstDelayMs: 1,
|
|
77
|
+
maxDelayMs: 2,
|
|
78
|
+
now: () => 0,
|
|
79
|
+
schedule: (fn) => {
|
|
80
|
+
scheduled.push(fn);
|
|
81
|
+
return scheduled.length;
|
|
82
|
+
},
|
|
83
|
+
cancel: () => {},
|
|
84
|
+
});
|
|
85
|
+
probe.start('Siap, langsung saya buatkan.');
|
|
86
|
+
await run(1);
|
|
87
|
+
expect(emitted).toHaveLength(1);
|
|
88
|
+
expect(emitted[0]).toContain('✓ read_file');
|
|
89
|
+
expect(emitted[0]).toContain('✗ run_command');
|
|
90
|
+
// Each new tool call re-arms the probe, so a repeated replay is silent.
|
|
91
|
+
await run(3);
|
|
92
|
+
expect(emitted).toHaveLength(1);
|
|
93
|
+
probe.stop();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('the absolute ceiling', () => {
|
|
98
|
+
test('new work re-arms the quiet window but never past the lifetime', async () => {
|
|
99
|
+
const scheduled: Array<() => void> = [];
|
|
100
|
+
const emitted: string[] = [];
|
|
101
|
+
let clock = 0;
|
|
102
|
+
let tool = 0;
|
|
103
|
+
let probe!: AcpBackgroundProbe;
|
|
104
|
+
const run = async (): Promise<void> => {
|
|
105
|
+
for (let i = 0; i < 12; i += 1) {
|
|
106
|
+
const next = scheduled.shift();
|
|
107
|
+
if (!next) return;
|
|
108
|
+
next();
|
|
109
|
+
for (let hop = 0; hop < 8; hop += 1) await Promise.resolve();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
probe = new AcpBackgroundProbe({
|
|
113
|
+
load: async () => {
|
|
114
|
+
tool += 1;
|
|
115
|
+
probe.consume('session/update', { update: { sessionUpdate: 'user_message_chunk', content: { type: 'text', text: 'q' } } });
|
|
116
|
+
probe.consume('session/update', { update: { sessionUpdate: 'tool_call', toolCallId: `t${tool}`, name: 'run_command', status: 'pending' } });
|
|
117
|
+
return {};
|
|
118
|
+
},
|
|
119
|
+
resetIdle: () => {},
|
|
120
|
+
emit: (text) => emitted.push(text),
|
|
121
|
+
timeoutMs: 1_000,
|
|
122
|
+
firstDelayMs: 1,
|
|
123
|
+
maxDelayMs: 1,
|
|
124
|
+
// Each probe advances the clock by 20 minutes: past the hour after three.
|
|
125
|
+
now: () => clock,
|
|
126
|
+
schedule: (fn) => {
|
|
127
|
+
clock += 20 * 60_000;
|
|
128
|
+
scheduled.push(fn);
|
|
129
|
+
return scheduled.length;
|
|
130
|
+
},
|
|
131
|
+
cancel: () => {},
|
|
132
|
+
});
|
|
133
|
+
probe.start('');
|
|
134
|
+
await run();
|
|
135
|
+
expect(emitted.length).toBeGreaterThanOrEqual(2);
|
|
136
|
+
// The ceiling stops it; nothing is scheduled after it.
|
|
137
|
+
expect(scheduled).toHaveLength(0);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What one `session/load` replay added, and the notice that says it.
|
|
8
|
+
*
|
|
9
|
+
* A replay repeats the WHOLE conversation, so the probe's job is to find the
|
|
10
|
+
* part past the answer the operator already has. Two kinds of evidence matter,
|
|
11
|
+
* and the second was missing until a real chat proved it was needed:
|
|
12
|
+
*
|
|
13
|
+
* - **prose** — an `agent_message_chunk` past the baseline. Already handled.
|
|
14
|
+
* - **work** — a `tool_call` past the baseline. Measured on agy 1.5.3 against a
|
|
15
|
+
* finished 155 s run: the held replay carried `read_file` and a failed
|
|
16
|
+
* `run_command` AFTER the holding sentence and no new assistant text at all,
|
|
17
|
+
* so a probe that waited for prose delivered nothing before its ceiling.
|
|
18
|
+
*
|
|
19
|
+
* Both are reported once per call id, so a probe that runs every few seconds
|
|
20
|
+
* does not repeat the same notice.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { acpContentText } from '@/server/lib/harness/acp/mapper';
|
|
24
|
+
|
|
25
|
+
/** One tool call a replay added past the baseline. */
|
|
26
|
+
export interface ReplayTool {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
status: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Replay chunks collected since the last `user_message_chunk`. */
|
|
33
|
+
export interface ReplaySegment {
|
|
34
|
+
text: string;
|
|
35
|
+
sawUser: boolean;
|
|
36
|
+
tools: ReplayTool[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** How many tool rows one notice lists before it summarizes. */
|
|
40
|
+
const MAX_LISTED = 5;
|
|
41
|
+
|
|
42
|
+
/** The notice for tool calls this probe has not reported yet, or null. */
|
|
43
|
+
export function newToolNotice(segment: ReplaySegment, reported: Set<string>): string | null {
|
|
44
|
+
const fresh = segment.tools.filter((tool) => !reported.has(tool.id));
|
|
45
|
+
if (fresh.length === 0) return null;
|
|
46
|
+
for (const tool of fresh) reported.add(tool.id);
|
|
47
|
+
const lines = fresh.map((tool) => {
|
|
48
|
+
const mark = tool.status === 'completed' ? '✓' : tool.status === 'failed' ? '✗' : '·';
|
|
49
|
+
return `${mark} ${tool.name}`;
|
|
50
|
+
});
|
|
51
|
+
const shown = lines.slice(0, MAX_LISTED);
|
|
52
|
+
const more = lines.length - shown.length;
|
|
53
|
+
return ['The subagent continued working:', ...shown, ...(more > 0 ? [`… and ${more} more`] : [])].join('\n');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Apply one `session/update` payload to the open segment. */
|
|
57
|
+
export function collectReplayFrame(segment: ReplaySegment, update: unknown): void {
|
|
58
|
+
if (!update || typeof update !== 'object') return;
|
|
59
|
+
const record = update as Record<string, unknown>;
|
|
60
|
+
const kind = typeof record.sessionUpdate === 'string' ? record.sessionUpdate : '';
|
|
61
|
+
if (kind === 'user_message_chunk') {
|
|
62
|
+
// A new user turn starts a new assistant segment; everything before it is
|
|
63
|
+
// history this probe does not need.
|
|
64
|
+
segment.text = '';
|
|
65
|
+
segment.sawUser = true;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (kind === 'agent_message_chunk') {
|
|
69
|
+
segment.text += acpContentText(record.content);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (kind !== 'tool_call' && kind !== 'tool_call_update') return;
|
|
73
|
+
const id = typeof record.toolCallId === 'string' ? record.toolCallId : '';
|
|
74
|
+
if (!id) return;
|
|
75
|
+
const name = typeof record.name === 'string' && record.name
|
|
76
|
+
? record.name
|
|
77
|
+
: typeof record.title === 'string' && record.title ? record.title : 'tool';
|
|
78
|
+
const status = typeof record.status === 'string' ? record.status : 'pending';
|
|
79
|
+
const existing = segment.tools.find((tool) => tool.id === id);
|
|
80
|
+
// A `tool_call_update` patches the call: keep its first name and take the
|
|
81
|
+
// latest status, so one call is one row.
|
|
82
|
+
if (existing) {
|
|
83
|
+
existing.status = status;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
segment.tools.push({ id, name, status });
|
|
87
|
+
}
|