clikcode 1.0.4 → 1.0.5
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/README.md +25 -14
- package/dist/chunk-23TDEBGZ.js +71 -0
- package/dist/chunk-25T3GVS7.js +425 -0
- package/dist/chunk-2BBELGHY.js +11 -0
- package/dist/chunk-2EOL5PZL.js +208 -0
- package/dist/chunk-2GAB36IE.js +26 -0
- package/dist/chunk-2OLS7V66.js +2440 -0
- package/dist/chunk-2QFO2URB.js +179 -0
- package/dist/chunk-2QWPQRSU.js +254 -0
- package/dist/chunk-2YPAPAR3.js +184 -0
- package/dist/chunk-2ZAG5372.js +33 -0
- package/dist/chunk-32IKAIZC.js +12507 -0
- package/dist/chunk-34AZEGYW.js +95 -0
- package/dist/chunk-34JQYQCA.js +175 -0
- package/dist/chunk-34ZISPAO.js +67 -0
- package/dist/chunk-3AAAARE6.js +46 -0
- package/dist/chunk-3AJ6Q3OY.js +510 -0
- package/dist/chunk-3B2CHX7M.js +884 -0
- package/dist/chunk-3BUFORRX.js +59 -0
- package/dist/chunk-3QLHYYFK.js +30 -0
- package/dist/chunk-3RXBMYKZ.js +140 -0
- package/dist/chunk-3TFNIJWS.js +52 -0
- package/dist/chunk-3W3IPDFP.js +119 -0
- package/dist/chunk-3WMS7SEE.js +417 -0
- package/dist/chunk-435ZNSZ3.js +23 -0
- package/dist/chunk-4AQ5NINV.js +39 -0
- package/dist/chunk-4GVEJ5FK.js +168 -0
- package/dist/chunk-4GXAO3UY.js +262 -0
- package/dist/chunk-4L2ZZM4Q.js +332 -0
- package/dist/chunk-4LPDG57B.js +17 -0
- package/dist/chunk-4NN3XQQT.js +223 -0
- package/dist/chunk-4QZEZME7.js +54 -0
- package/dist/chunk-4R6CSC3S.js +38 -0
- package/dist/chunk-4RHXTL3W.js +514 -0
- package/dist/chunk-4SJMPTVQ.js +18 -0
- package/dist/chunk-4VY7G6TX.js +114 -0
- package/dist/chunk-5642PBF7.js +124 -0
- package/dist/chunk-5B6TVO4A.js +33 -0
- package/dist/chunk-5BJLDUPL.js +62 -0
- package/dist/chunk-5HMFFJWU.js +19 -0
- package/dist/chunk-5IKLK33T.js +69 -0
- package/dist/chunk-5NQ5FFMX.js +44 -0
- package/dist/chunk-5QNNW5L6.js +176 -0
- package/dist/chunk-5SM5UAWN.js +239 -0
- package/dist/chunk-5WYJTA6O.js +74 -0
- package/dist/chunk-5ZSR2Y5T.js +227 -0
- package/dist/chunk-5ZWUM5GH.js +39 -0
- package/dist/chunk-64E7D4HY.js +364 -0
- package/dist/chunk-6CK466BC.js +99 -0
- package/dist/chunk-6ES45HHO.js +138 -0
- package/dist/chunk-6HYEZFGL.js +277 -0
- package/dist/chunk-6Y7HLXGW.js +29 -0
- package/dist/chunk-6YKK4FYR.js +258 -0
- package/dist/chunk-74WNMLMS.js +117 -0
- package/dist/chunk-7AULZ7OD.js +55 -0
- package/dist/chunk-7DOKGSUN.js +101 -0
- package/dist/chunk-7IH5LTIZ.js +195 -0
- package/dist/chunk-7ISTS5NS.js +21 -0
- package/dist/chunk-7NMUTGOW.js +527 -0
- package/dist/chunk-7PNHUZEL.js +153 -0
- package/dist/chunk-7TSQLONI.js +88 -0
- package/dist/chunk-AE7TOLD5.js +30 -0
- package/dist/chunk-AEMHSXKA.js +130 -0
- package/dist/chunk-AKRYTS2D.js +211 -0
- package/dist/chunk-AMNSE36L.js +59 -0
- package/dist/chunk-AZVD74ZV.js +23 -0
- package/dist/chunk-B35DVOTK.js +1981 -0
- package/dist/chunk-B4HNJRAH.js +626 -0
- package/dist/chunk-B5WYPPHS.js +13 -0
- package/dist/chunk-BBOVDXQM.js +59 -0
- package/dist/chunk-BD3ECZLK.js +62 -0
- package/dist/chunk-BDGSOT74.js +4578 -0
- package/dist/chunk-BF5VEOPK.js +31 -0
- package/dist/chunk-BFFRW4XH.js +47 -0
- package/dist/chunk-BFPC6PEW.js +208 -0
- package/dist/chunk-BGEMY2JJ.js +376 -0
- package/dist/chunk-BISGNHKD.js +35 -0
- package/dist/chunk-BMRAEBRY.js +21 -0
- package/dist/chunk-BNTXAZXW.js +127 -0
- package/dist/chunk-BOQBXGSN.js +75 -0
- package/dist/chunk-BTJDSTQP.js +213 -0
- package/dist/chunk-BUOPJQP5.js +218 -0
- package/dist/chunk-BXFJS65Q.js +52 -0
- package/dist/chunk-BXPQFSX5.js +59 -0
- package/dist/chunk-C57LIWNY.js +1269 -0
- package/dist/chunk-C6YVCCWR.js +74 -0
- package/dist/chunk-CAADDF6M.js +167 -0
- package/dist/chunk-CBANJFBO.js +69 -0
- package/dist/chunk-CERF3RIB.js +597 -0
- package/dist/chunk-COAS5ETR.js +46 -0
- package/dist/chunk-CQ7J6UQ7.js +78 -0
- package/dist/chunk-CRUVYGO2.js +26 -0
- package/dist/chunk-CVFVFRGN.js +58 -0
- package/dist/chunk-D2UK66HM.js +37 -0
- package/dist/chunk-D2W7SA4R.js +18 -0
- package/dist/chunk-DA44ZENT.js +501 -0
- package/dist/chunk-DAJ76TOC.js +99 -0
- package/dist/chunk-DCZ6CIUM.js +147 -0
- package/dist/chunk-DF35KMXM.js +1314 -0
- package/dist/chunk-DGASQT26.js +151 -0
- package/dist/chunk-DJT57C5P.js +55 -0
- package/dist/chunk-DKDPZTD3.js +44 -0
- package/dist/chunk-DQYVQ2N7.js +77 -0
- package/dist/chunk-DRTP2RTY.js +266 -0
- package/dist/chunk-DW2BMUKY.js +61 -0
- package/dist/chunk-DW5T5ZVU.js +307 -0
- package/dist/chunk-DXKNDNFC.js +164 -0
- package/dist/chunk-DZEQ7UYR.js +291 -0
- package/dist/chunk-E4F4OUAC.js +463 -0
- package/dist/chunk-EE4B6A7W.js +69 -0
- package/dist/chunk-EISKIYWG.js +23 -0
- package/dist/chunk-EKAQK7UQ.js +235 -0
- package/dist/chunk-EOBTJV32.js +123 -0
- package/dist/chunk-ESF3DIZY.js +325 -0
- package/dist/chunk-EVOHOZ4U.js +45 -0
- package/dist/chunk-EXN4KHLB.js +110 -0
- package/dist/chunk-F252T6Y3.js +78 -0
- package/dist/chunk-F3DP4ZA2.js +40 -0
- package/dist/chunk-F6F47QAY.js +58 -0
- package/dist/chunk-FA3Y23ZW.js +57 -0
- package/dist/chunk-FBKXE4EJ.js +640 -0
- package/dist/chunk-FCGEB3H6.js +23 -0
- package/dist/chunk-FF7ZVYJF.js +3732 -0
- package/dist/chunk-FFGKN6L3.js +39 -0
- package/dist/chunk-FFGU4GCC.js +94 -0
- package/dist/chunk-FSFDAOVP.js +74 -0
- package/dist/chunk-FT5TX7OX.js +1573 -0
- package/dist/chunk-G3QP67Z7.js +232 -0
- package/dist/chunk-G5ORJKV2.js +179 -0
- package/dist/chunk-GFNC62PE.js +111 -0
- package/dist/chunk-GGK43Q3N.js +67 -0
- package/dist/chunk-GGYKY4GF.js +11537 -0
- package/dist/chunk-GGYNHGNJ.js +55 -0
- package/dist/chunk-GLY7RM3C.js +354 -0
- package/dist/chunk-GQBZU6EO.js +20 -0
- package/dist/chunk-GSXENUZL.js +9 -0
- package/dist/chunk-GTOAT5D3.js +40 -0
- package/dist/chunk-GWCMDPQU.js +1007 -0
- package/dist/chunk-GXYSMYHJ.js +152 -0
- package/dist/chunk-GYMAI5NY.js +14 -0
- package/dist/chunk-H2VZMKPE.js +30 -0
- package/dist/chunk-H4THUNBM.js +2091 -0
- package/dist/chunk-HGRVSNUZ.js +361 -0
- package/dist/chunk-HI4VY473.js +27 -0
- package/dist/chunk-HOJRSD3Q.js +447 -0
- package/dist/chunk-HRX25W35.js +82 -0
- package/dist/chunk-HSE4AQYV.js +55 -0
- package/dist/chunk-HU5SSUFX.js +383 -0
- package/dist/chunk-I3GDBJLH.js +196 -0
- package/dist/chunk-I75EDU75.js +684 -0
- package/dist/chunk-IBA7DMIO.js +20 -0
- package/dist/chunk-IC6N4NZA.js +231 -0
- package/dist/chunk-IF43HIGV.js +284 -0
- package/dist/chunk-IGZ6C2MC.js +439 -0
- package/dist/chunk-IMLTL2MY.js +192 -0
- package/dist/chunk-IMZL6SGR.js +33 -0
- package/dist/chunk-IS4USJPY.js +516 -0
- package/dist/chunk-ISFSPN2F.js +82 -0
- package/dist/chunk-IXE7GTFI.js +55 -0
- package/dist/chunk-IZ77QJQG.js +36 -0
- package/dist/chunk-J2PACWRQ.js +34 -0
- package/dist/chunk-J6EGFVQX.js +180 -0
- package/dist/chunk-JEKOD43D.js +22 -0
- package/dist/chunk-JGIWATSG.js +30 -0
- package/dist/chunk-JYBONKD4.js +43 -0
- package/dist/chunk-K2NLG2HK.js +454 -0
- package/dist/chunk-KCQ4TBLS.js +164 -0
- package/dist/chunk-KD5KIVMS.js +176 -0
- package/dist/chunk-KHW6TX6I.js +63 -0
- package/dist/chunk-KI5GZFCE.js +520 -0
- package/dist/chunk-KN34B7NO.js +105 -0
- package/dist/chunk-KYUHIFP3.js +136 -0
- package/dist/chunk-KZL5VS4B.js +300 -0
- package/dist/chunk-L3VW3QIH.js +48 -0
- package/dist/chunk-LA6MG4ET.js +2110 -0
- package/dist/chunk-LAVFOA3S.js +66 -0
- package/dist/chunk-LB4OA77N.js +13 -0
- package/dist/chunk-LBFRF2K4.js +196 -0
- package/dist/chunk-LM6EIA4B.js +93 -0
- package/dist/chunk-LPCNRGJ7.js +692 -0
- package/dist/chunk-LSLNL5T3.js +168 -0
- package/dist/chunk-LVRRWP4W.js +568 -0
- package/dist/chunk-LWCFBRHL.js +33 -0
- package/dist/chunk-LXFTMGZZ.js +166 -0
- package/dist/chunk-M33LVA4M.js +151 -0
- package/dist/chunk-M3FO5UMK.js +4944 -0
- package/dist/chunk-M5QNDBAY.js +66 -0
- package/dist/chunk-M6ND6KBE.js +1291 -0
- package/dist/chunk-M7H3WQTE.js +76 -0
- package/dist/chunk-MCBRVPA7.js +191 -0
- package/dist/chunk-MCSDWZET.js +91 -0
- package/dist/chunk-MDT5XDXL.js +289 -0
- package/dist/chunk-MJG3IQY4.js +91 -0
- package/dist/chunk-MOU3N2UL.js +44 -0
- package/dist/chunk-MP4KZOQC.js +3451 -0
- package/dist/chunk-MPAJ446F.js +66 -0
- package/dist/chunk-MVJZZ6AL.js +16 -0
- package/dist/chunk-MXS6S2PY.js +253 -0
- package/dist/chunk-N3SFDYM7.js +291 -0
- package/dist/chunk-NAOX3JUB.js +13 -0
- package/dist/chunk-NEKKIBCX.js +283 -0
- package/dist/chunk-NKDATMEM.js +133 -0
- package/dist/chunk-NR4FMC4K.js +395 -0
- package/dist/chunk-NSOHOJBR.js +221 -0
- package/dist/chunk-NTDB6QKF.js +29 -0
- package/dist/chunk-NWEYRBWK.js +25 -0
- package/dist/chunk-O2YSNYWD.js +23 -0
- package/dist/chunk-O3EW7LAY.js +54 -0
- package/dist/chunk-O7BNJIXU.js +366 -0
- package/dist/chunk-OARL2NXZ.js +116 -0
- package/dist/chunk-OHKZUEJW.js +351 -0
- package/dist/chunk-OKU45BXA.js +647 -0
- package/dist/chunk-OL4JBD3J.js +59 -0
- package/dist/chunk-OLUO5DDR.js +192 -0
- package/dist/chunk-OQ245JLA.js +196 -0
- package/dist/chunk-P72UZAQI.js +289 -0
- package/dist/chunk-PAL2ENB6.js +20 -0
- package/dist/chunk-PAXYQZH7.js +53 -0
- package/dist/chunk-PDPEM5VW.js +51 -0
- package/dist/chunk-PEWCDI2C.js +668 -0
- package/dist/chunk-PGZ54EDX.js +27 -0
- package/dist/chunk-PRWVLDZF.js +73 -0
- package/dist/chunk-PSQQ75VJ.js +52 -0
- package/dist/chunk-PUOVIFHW.js +118 -0
- package/dist/chunk-PWBF2X3V.js +107 -0
- package/dist/chunk-PWXII6HF.js +43 -0
- package/dist/chunk-Q35VLJRT.js +80 -0
- package/dist/chunk-QJP7EYGL.js +128 -0
- package/dist/chunk-QPQKX2MK.js +8836 -0
- package/dist/chunk-QQRLPY25.js +1053 -0
- package/dist/chunk-QUS4ER2W.js +407 -0
- package/dist/chunk-QYHI3YET.js +29 -0
- package/dist/chunk-QYRU2UQI.js +32 -0
- package/dist/chunk-R6XVVQGC.js +13 -0
- package/dist/chunk-R7QN6ONS.js +483 -0
- package/dist/chunk-RD23MPGC.js +221 -0
- package/dist/chunk-RDDWQBEM.js +185 -0
- package/dist/chunk-RDLLDYFO.js +104 -0
- package/dist/chunk-RE4TGORR.js +84 -0
- package/dist/chunk-RJLHVYQY.js +217 -0
- package/dist/chunk-RJLPTWHW.js +905 -0
- package/dist/chunk-RKUVLRZI.js +295 -0
- package/dist/chunk-ROGXPGYR.js +37 -0
- package/dist/chunk-RSZGEL5U.js +163 -0
- package/dist/chunk-RVUOIJXN.js +909 -0
- package/dist/chunk-RW7F4JRP.js +11 -0
- package/dist/chunk-S4UO3AO3.js +53 -0
- package/dist/chunk-S5JAAF6S.js +585 -0
- package/dist/chunk-SNU37TQI.js +56 -0
- package/dist/chunk-SQVUDO2O.js +31 -0
- package/dist/chunk-SYVHIYQT.js +66 -0
- package/dist/chunk-SZBQMTG2.js +85 -0
- package/dist/chunk-T5VCXA3J.js +25 -0
- package/dist/chunk-TK6NSP56.js +30 -0
- package/dist/chunk-TKWVMA6L.js +22 -0
- package/dist/chunk-TQDKJHWX.js +59 -0
- package/dist/chunk-TQDM7S5N.js +127 -0
- package/dist/chunk-TULAXS77.js +23 -0
- package/dist/chunk-TVT45XNH.js +4625 -0
- package/dist/chunk-TWCVV2JO.js +467 -0
- package/dist/chunk-U4DKAD6S.js +47 -0
- package/dist/chunk-UA5K2BTI.js +564 -0
- package/dist/chunk-UAMKCMOK.js +40 -0
- package/dist/chunk-UBMVADBF.js +51 -0
- package/dist/chunk-UFQ5A5PW.js +645 -0
- package/dist/chunk-UOD2SOLL.js +1301 -0
- package/dist/chunk-UTSB4LOW.js +156 -0
- package/dist/chunk-UVXNIUTN.js +412 -0
- package/dist/chunk-UXVPXYPE.js +90 -0
- package/dist/chunk-UYEEMIWR.js +374 -0
- package/dist/chunk-VBGM5ZBW.js +54 -0
- package/dist/chunk-VEWPCZPG.js +762 -0
- package/dist/chunk-VIRDLZ5E.js +108 -0
- package/dist/chunk-VMPO7WKN.js +52 -0
- package/dist/chunk-W2NVSDO5.js +5122 -0
- package/dist/chunk-W3YYPBEA.js +176 -0
- package/dist/chunk-W5AYOICN.js +280 -0
- package/dist/chunk-W5GZOIUF.js +27 -0
- package/dist/chunk-WHKNLZ3C.js +76 -0
- package/dist/chunk-WKBEPPQ5.js +1409 -0
- package/dist/chunk-WM3Z6QKQ.js +151 -0
- package/dist/chunk-WMI2TPMA.js +31 -0
- package/dist/chunk-WNX5VD7S.js +150 -0
- package/dist/chunk-WOVTYST3.js +60 -0
- package/dist/chunk-WPB5WEZJ.js +546 -0
- package/dist/chunk-WUO5EOAT.js +44 -0
- package/dist/chunk-WWLJMP6D.js +133 -0
- package/dist/chunk-WZMLH3XP.js +58 -0
- package/dist/chunk-WZYVLUVQ.js +79 -0
- package/dist/chunk-X2OCPVU5.js +135 -0
- package/dist/chunk-X3CL6DTR.js +95 -0
- package/dist/chunk-X6WF7JEV.js +354 -0
- package/dist/chunk-XAHGBPWT.js +44 -0
- package/dist/chunk-XCKQ5BM2.js +228 -0
- package/dist/chunk-XIBYREEY.js +106 -0
- package/dist/chunk-XKW5NDMR.js +378 -0
- package/dist/chunk-XRDALAO3.js +100 -0
- package/dist/chunk-XUP22EAS.js +41 -0
- package/dist/chunk-XWAC3MKW.js +243 -0
- package/dist/chunk-Y3R7JMXB.js +59 -0
- package/dist/chunk-Y54LTP4W.js +82 -0
- package/dist/chunk-Y7UECI4M.js +99 -0
- package/dist/chunk-YACGDFHC.js +47 -0
- package/dist/chunk-YHNIQPKY.js +71 -0
- package/dist/chunk-YMBR6HYP.js +111 -0
- package/dist/chunk-YMCH3L2S.js +26 -0
- package/dist/chunk-Z4ZU6T7V.js +99 -0
- package/dist/chunk-ZDPF67ZZ.js +173 -0
- package/dist/chunk-ZFC2Q67K.js +101 -0
- package/dist/chunk-ZGHNNSCT.js +114 -0
- package/dist/chunk-ZGX3ERAT.js +173 -0
- package/dist/chunk-ZI3YHEBY.js +37 -0
- package/dist/chunk-ZN7G6JLS.js +639 -0
- package/dist/chunk-ZNPFQMXT.js +47 -0
- package/dist/chunk-ZOU3LV4U.js +63 -0
- package/dist/chunk-ZT7B4H2V.js +117 -0
- package/dist/chunk-ZZCBDNZI.js +58 -0
- package/dist/cli.js +494 -112923
- package/dist/computer-tools.js +36642 -21259
- package/dist/harness-catalog.cjs +88 -43
- package/dist/index.js +1 -1
- package/dist/local-model-supervisor.cjs +555 -0
- package/package.json +3 -4
|
@@ -0,0 +1,884 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
ACTIVITY_PREVIEW_LINES,
|
|
5
|
+
COMMAND_HEAD_LINES,
|
|
6
|
+
COMMAND_TAIL_LINES,
|
|
7
|
+
DIFF_PREVIEW_FILES,
|
|
8
|
+
DIFF_PREVIEW_LINES,
|
|
9
|
+
markBefore,
|
|
10
|
+
mergeActivity,
|
|
11
|
+
sameCall,
|
|
12
|
+
stoppedCall,
|
|
13
|
+
withChildTool
|
|
14
|
+
} from "./chunk-XKW5NDMR.js";
|
|
15
|
+
import {
|
|
16
|
+
categoryOf,
|
|
17
|
+
formatToolRow,
|
|
18
|
+
isAgentToolName,
|
|
19
|
+
toolCategory,
|
|
20
|
+
toolLabel
|
|
21
|
+
} from "./chunk-W3YYPBEA.js";
|
|
22
|
+
import {
|
|
23
|
+
asRecord,
|
|
24
|
+
claudeShaped,
|
|
25
|
+
opencodeShaped
|
|
26
|
+
} from "./chunk-XIBYREEY.js";
|
|
27
|
+
import {
|
|
28
|
+
visibleSlice
|
|
29
|
+
} from "./chunk-G3QP67Z7.js";
|
|
30
|
+
|
|
31
|
+
// src/agent/line-diff.ts
|
|
32
|
+
function asFileDiffs(diff) {
|
|
33
|
+
if (Array.isArray(diff)) return diff.filter((file) => Boolean(file) && Array.isArray(file.lines));
|
|
34
|
+
const legacy = diff;
|
|
35
|
+
if (!legacy || !Array.isArray(legacy.removed) || !Array.isArray(legacy.added)) return void 0;
|
|
36
|
+
const lines = (side, kind) => side.map((text) => ({ kind, text: String(text) }));
|
|
37
|
+
return [{ lines: [...lines(legacy.removed, "removed"), ...lines(legacy.added, "added")], additions: legacy.added.length, removals: legacy.removed.length }];
|
|
38
|
+
}
|
|
39
|
+
var DIFF_CONTEXT = 2;
|
|
40
|
+
var FILE_DIFF_LINE_CAP = 80;
|
|
41
|
+
function boundFileDiff(file, cap) {
|
|
42
|
+
if (file.lines.length <= cap) return file;
|
|
43
|
+
return { ...file, lines: file.lines.slice(0, cap), omitted: (file.omitted ?? 0) + file.lines.length - cap };
|
|
44
|
+
}
|
|
45
|
+
function fileDiff(before, after, options = {}) {
|
|
46
|
+
const ops = diffLines(before, after);
|
|
47
|
+
const keep = ops.map(() => false);
|
|
48
|
+
ops.forEach((op, index) => {
|
|
49
|
+
if (op.kind === "same") return;
|
|
50
|
+
for (let k = Math.max(0, index - DIFF_CONTEXT); k <= Math.min(ops.length - 1, index + DIFF_CONTEXT); k++) keep[k] = true;
|
|
51
|
+
});
|
|
52
|
+
const lines = [];
|
|
53
|
+
let oldLine = 0;
|
|
54
|
+
let newLine = 0;
|
|
55
|
+
let skipped = false;
|
|
56
|
+
ops.forEach((op, index) => {
|
|
57
|
+
if (op.kind !== "added") oldLine += 1;
|
|
58
|
+
if (op.kind !== "removed") newLine += 1;
|
|
59
|
+
if (!keep[index]) {
|
|
60
|
+
skipped = true;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (skipped && lines.length) lines.push({ kind: "gap", text: "" });
|
|
64
|
+
skipped = false;
|
|
65
|
+
const line = op.kind === "removed" ? oldLine : newLine;
|
|
66
|
+
lines.push({ kind: op.kind, text: op.line, ...options.numbered ? { line } : {} });
|
|
67
|
+
});
|
|
68
|
+
return boundFileDiff({
|
|
69
|
+
...options.path ? { path: options.path } : {},
|
|
70
|
+
...options.change ? { change: options.change } : {},
|
|
71
|
+
lines,
|
|
72
|
+
additions: ops.filter((op) => op.kind === "added").length,
|
|
73
|
+
removals: ops.filter((op) => op.kind === "removed").length
|
|
74
|
+
}, options.cap ?? FILE_DIFF_LINE_CAP);
|
|
75
|
+
}
|
|
76
|
+
function unifiedFileDiffs(diff, options = {}) {
|
|
77
|
+
const cap = options.cap ?? FILE_DIFF_LINE_CAP;
|
|
78
|
+
const text = diff.replace(/\r?\n$/, "");
|
|
79
|
+
if (!/^@@ |^[-+]/m.test(text)) return [fileDiff("", text, { ...options, numbered: true, change: options.change ?? "add" })];
|
|
80
|
+
const files = [];
|
|
81
|
+
let current;
|
|
82
|
+
let oldLine = 0;
|
|
83
|
+
let newLine = 0;
|
|
84
|
+
const open = (path) => {
|
|
85
|
+
const file = { ...path ?? options.path ? { path: path ?? options.path } : {}, ...options.change ? { change: options.change } : {}, lines: [], additions: 0, removals: 0 };
|
|
86
|
+
files.push(file);
|
|
87
|
+
return file;
|
|
88
|
+
};
|
|
89
|
+
for (const line of text.split(/\r?\n/)) {
|
|
90
|
+
const git = /^diff --git a\/(.+?) b\/(.+)$/.exec(line);
|
|
91
|
+
if (git) {
|
|
92
|
+
current = open(git[2]);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (/^(?:index |--- |new file mode|deleted file mode|similarity index|rename (?:from|to) )/.test(line)) continue;
|
|
96
|
+
const target = /^\+\+\+ (?:b\/)?(.+)$/.exec(line);
|
|
97
|
+
if (target) {
|
|
98
|
+
if (current && !current.path && target[1] !== "/dev/null") current.path = target[1];
|
|
99
|
+
else if (!current) current = open(target[1] === "/dev/null" ? void 0 : target[1]);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const hunk = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(line);
|
|
103
|
+
if (hunk) {
|
|
104
|
+
current ??= open();
|
|
105
|
+
if (current.lines.length) current.lines.push({ kind: "gap", text: "" });
|
|
106
|
+
oldLine = Number(hunk[1]);
|
|
107
|
+
newLine = Number(hunk[2]);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (line.startsWith("\\")) continue;
|
|
111
|
+
current ??= open();
|
|
112
|
+
if (line.startsWith("-")) {
|
|
113
|
+
current.lines.push({ kind: "removed", text: line.slice(1), ...oldLine ? { line: oldLine } : {} });
|
|
114
|
+
current.removals += 1;
|
|
115
|
+
if (oldLine) oldLine += 1;
|
|
116
|
+
} else if (line.startsWith("+")) {
|
|
117
|
+
current.lines.push({ kind: "added", text: line.slice(1), ...newLine ? { line: newLine } : {} });
|
|
118
|
+
current.additions += 1;
|
|
119
|
+
if (newLine) newLine += 1;
|
|
120
|
+
} else {
|
|
121
|
+
current.lines.push({ kind: "same", text: line.startsWith(" ") ? line.slice(1) : line, ...newLine ? { line: newLine } : {} });
|
|
122
|
+
if (oldLine) oldLine += 1;
|
|
123
|
+
if (newLine) newLine += 1;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return files.map((file) => boundFileDiff(file, cap));
|
|
127
|
+
}
|
|
128
|
+
var LCS_CELL_CAP = 4e6;
|
|
129
|
+
function splitLines(text) {
|
|
130
|
+
if (!text) return [];
|
|
131
|
+
return text.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
132
|
+
}
|
|
133
|
+
function diffLines(before, after) {
|
|
134
|
+
const a = splitLines(before);
|
|
135
|
+
const b = splitLines(after);
|
|
136
|
+
let head = 0;
|
|
137
|
+
while (head < a.length && head < b.length && a[head] === b[head]) head++;
|
|
138
|
+
let tail = 0;
|
|
139
|
+
while (tail < a.length - head && tail < b.length - head && a[a.length - 1 - tail] === b[b.length - 1 - tail]) tail++;
|
|
140
|
+
const midA = a.slice(head, a.length - tail);
|
|
141
|
+
const midB = b.slice(head, b.length - tail);
|
|
142
|
+
const ops = a.slice(0, head).map((line) => ({ kind: "same", line }));
|
|
143
|
+
if (midA.length * midB.length > LCS_CELL_CAP) {
|
|
144
|
+
ops.push(...midA.map((line) => ({ kind: "removed", line })), ...midB.map((line) => ({ kind: "added", line })));
|
|
145
|
+
} else {
|
|
146
|
+
const n = midA.length;
|
|
147
|
+
const m = midB.length;
|
|
148
|
+
const width = m + 1;
|
|
149
|
+
const table = new Uint32Array((n + 1) * width);
|
|
150
|
+
for (let i2 = n - 1; i2 >= 0; i2--) {
|
|
151
|
+
for (let j2 = m - 1; j2 >= 0; j2--) {
|
|
152
|
+
table[i2 * width + j2] = midA[i2] === midB[j2] ? table[(i2 + 1) * width + j2 + 1] + 1 : Math.max(table[(i2 + 1) * width + j2], table[i2 * width + j2 + 1]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
let i = 0;
|
|
156
|
+
let j = 0;
|
|
157
|
+
while (i < n && j < m) {
|
|
158
|
+
if (midA[i] === midB[j]) {
|
|
159
|
+
ops.push({ kind: "same", line: midA[i] });
|
|
160
|
+
i++;
|
|
161
|
+
j++;
|
|
162
|
+
} else if (table[(i + 1) * width + j] >= table[i * width + j + 1]) ops.push({ kind: "removed", line: midA[i++] });
|
|
163
|
+
else ops.push({ kind: "added", line: midB[j++] });
|
|
164
|
+
}
|
|
165
|
+
while (i < n) ops.push({ kind: "removed", line: midA[i++] });
|
|
166
|
+
while (j < m) ops.push({ kind: "added", line: midB[j++] });
|
|
167
|
+
}
|
|
168
|
+
ops.push(...a.slice(a.length - tail).map((line) => ({ kind: "same", line })));
|
|
169
|
+
return ops;
|
|
170
|
+
}
|
|
171
|
+
function eventDiff(before, after, options = {}) {
|
|
172
|
+
const { priorUnknown, ...rest } = options;
|
|
173
|
+
const diff = fileDiff(before, after, { ...rest, ...before ? {} : { change: "add" } });
|
|
174
|
+
return [priorUnknown ? { ...diff, priorUnknown: true } : diff];
|
|
175
|
+
}
|
|
176
|
+
function unifiedEventDiff(diff, options = {}) {
|
|
177
|
+
return unifiedFileDiffs(diff, options);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/harness/protocol/activity-events.ts
|
|
181
|
+
var EVENT_OUTPUT_LINES = 60;
|
|
182
|
+
var HARNESS_NOTE = /(?:^|\r?\n)Shell cwd was reset to [^\r\n]+\s*$/;
|
|
183
|
+
function withoutHarnessNotes(text) {
|
|
184
|
+
return text.replace(HARNESS_NOTE, "");
|
|
185
|
+
}
|
|
186
|
+
function activityOutput(text, options = {}) {
|
|
187
|
+
const normalized = withoutHarnessNotes(text).replace(/\r?\n$/, "");
|
|
188
|
+
if (!normalized.trim()) return {};
|
|
189
|
+
const lines = normalized.split(/\r?\n/);
|
|
190
|
+
const kept = options.tail ? lines.slice(-EVENT_OUTPUT_LINES) : lines.slice(0, EVENT_OUTPUT_LINES);
|
|
191
|
+
const omitted = lines.length - kept.length;
|
|
192
|
+
return {
|
|
193
|
+
output: kept,
|
|
194
|
+
...omitted ? { outputOmitted: omitted } : {},
|
|
195
|
+
...options.tail ? { outputTail: true } : {},
|
|
196
|
+
...options.tail && omitted ? { outputHead: lines.slice(0, COMMAND_HEAD_LINES) } : {}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
var HUMAN_KEYS = ["error", "output", "stdout", "message", "text", "result", "response", "content"];
|
|
200
|
+
function jsonHumanSummary(value, depth = 0) {
|
|
201
|
+
if (Array.isArray(value)) return `${value.length} items`;
|
|
202
|
+
const record = asRecord(value);
|
|
203
|
+
if (!record) return void 0;
|
|
204
|
+
for (const key of HUMAN_KEYS) {
|
|
205
|
+
const field = record[key];
|
|
206
|
+
if (typeof field === "string" && field.trim()) return field;
|
|
207
|
+
if (Array.isArray(field)) {
|
|
208
|
+
const text = blockText(field);
|
|
209
|
+
if (text.trim()) return text;
|
|
210
|
+
} else if (depth < 2 && asRecord(field)) {
|
|
211
|
+
const nested = jsonHumanSummary(field, depth + 1);
|
|
212
|
+
if (nested && !/^\d+ items$/.test(nested)) return nested;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const lists = Object.entries(record).filter(([, field]) => Array.isArray(field));
|
|
216
|
+
if (lists.length === 1) {
|
|
217
|
+
const [key, list] = lists[0];
|
|
218
|
+
return `${list.length} ${HUMAN_KEYS.includes(key) ? "items" : key}`;
|
|
219
|
+
}
|
|
220
|
+
return void 0;
|
|
221
|
+
}
|
|
222
|
+
function cappedActivityOutput(text) {
|
|
223
|
+
const normalized = withoutHarnessNotes(text).trim();
|
|
224
|
+
if (!normalized) return {};
|
|
225
|
+
const records = normalized.split(/\r?\n/).filter(Boolean);
|
|
226
|
+
const parse = (candidate) => {
|
|
227
|
+
if (!/^(?:\{|\[)/.test(candidate.trim())) return void 0;
|
|
228
|
+
try {
|
|
229
|
+
return { value: JSON.parse(candidate) };
|
|
230
|
+
} catch {
|
|
231
|
+
return void 0;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
const whole = parse(normalized);
|
|
235
|
+
if (whole) {
|
|
236
|
+
const summary = jsonHumanSummary(whole.value);
|
|
237
|
+
return summary ? activityOutput(summary) : {};
|
|
238
|
+
}
|
|
239
|
+
if (records.length > 0 && records.every((record) => parse(record))) return {};
|
|
240
|
+
return activityOutput(normalized);
|
|
241
|
+
}
|
|
242
|
+
function commandOutcome(record) {
|
|
243
|
+
const exitCode = [record?.exitCode, record?.exit_code].find((value) => typeof value === "number" && Number.isFinite(value));
|
|
244
|
+
const durationMs = [record?.durationMs, record?.duration_ms].find((value) => typeof value === "number" && Number.isFinite(value) && value >= 0);
|
|
245
|
+
return { ...exitCode !== void 0 ? { exitCode } : {}, ...durationMs !== void 0 ? { durationMs } : {} };
|
|
246
|
+
}
|
|
247
|
+
function fileChangeActivity(changes) {
|
|
248
|
+
const list = Array.isArray(changes) ? changes.map((change) => asRecord(change)).filter((change) => Boolean(change)) : asRecord(changes) ? Object.entries(asRecord(changes)).map(([file, change]) => ({ path: file, ...asRecord(change) })) : [];
|
|
249
|
+
const paths = list.flatMap((change) => typeof change.path === "string" && change.path ? [change.path] : []);
|
|
250
|
+
const label = formatToolRow("edit", paths.length > 3 ? `${paths.slice(0, 3).join(", ")} +${paths.length - 3} more` : paths.join(", ") || "files", "edit");
|
|
251
|
+
const parts = list.flatMap((change) => {
|
|
252
|
+
const text = typeof change.diff === "string" ? change.diff : typeof change.unified_diff === "string" ? change.unified_diff : void 0;
|
|
253
|
+
if (text === void 0) return [];
|
|
254
|
+
const kind = String(asRecord(change.kind)?.type ?? change.kind ?? "");
|
|
255
|
+
const changeKind = ["add", "delete", "update", "move"].find((value) => value === kind);
|
|
256
|
+
return unifiedEventDiff(text, { ...typeof change.path === "string" ? { path: change.path } : {}, ...changeKind ? { change: changeKind } : {} });
|
|
257
|
+
});
|
|
258
|
+
return { label, category: "edit", ...parts.length ? { diff: parts } : {} };
|
|
259
|
+
}
|
|
260
|
+
function blockText(content) {
|
|
261
|
+
if (typeof content === "string") return content;
|
|
262
|
+
if (!Array.isArray(content)) return "";
|
|
263
|
+
return content.flatMap((part) => {
|
|
264
|
+
const record = asRecord(part);
|
|
265
|
+
return typeof record?.text === "string" ? [record.text] : [];
|
|
266
|
+
}).join("\n");
|
|
267
|
+
}
|
|
268
|
+
function thoughtLabel(text) {
|
|
269
|
+
const folded = text.replace(/\s+/g, " ").trim();
|
|
270
|
+
return folded.length > THOUGHT_LABEL_CHARS ? `\u2026${folded.slice(-(THOUGHT_LABEL_CHARS - 1))}` : folded;
|
|
271
|
+
}
|
|
272
|
+
var THOUGHT_LABEL_CHARS = 240;
|
|
273
|
+
var claudeThinkingId = (messageId) => `thinking:${messageId}`;
|
|
274
|
+
var first = (record, keys) => keys.map((key) => record[key]).find((value) => typeof value === "string");
|
|
275
|
+
function editDiffFromInput(input) {
|
|
276
|
+
if (!input) return void 0;
|
|
277
|
+
const path = first(input, ["file_path", "path", "filePath", "target_file", "filename", "abs_path"]);
|
|
278
|
+
const at = path ? { path } : {};
|
|
279
|
+
const replace = (record) => {
|
|
280
|
+
const before = first(record, ["old_string", "oldString", "old_str", "oldText", "old_text", "search"]);
|
|
281
|
+
const after = first(record, ["new_string", "newString", "new_str", "newText", "new_text", "replace"]);
|
|
282
|
+
return before !== void 0 && after !== void 0 ? eventDiff(before, after, at) : [];
|
|
283
|
+
};
|
|
284
|
+
const edits = Array.isArray(input.edits) ? input.edits.flatMap((edit) => asRecord(edit) ? replace(asRecord(edit)) : []) : [];
|
|
285
|
+
const diff = [...replace(input), ...edits];
|
|
286
|
+
if (diff.length) return diff;
|
|
287
|
+
const content = first(input, ["content", "file_text", "contents"]);
|
|
288
|
+
return content !== void 0 && path ? eventDiff("", content, { ...at, numbered: true, priorUnknown: true }) : void 0;
|
|
289
|
+
}
|
|
290
|
+
function toolFacts(name, input, command) {
|
|
291
|
+
const classified = categoryOf(name, input, command);
|
|
292
|
+
const diff = classified.category === "edit" ? editDiffFromInput(input) : void 0;
|
|
293
|
+
const agent = isAgentToolName(name) || typeof input?.subagent_type === "string" ? { agent: true } : {};
|
|
294
|
+
return { label: toolLabel(name, input, classified.category), ...classified, ...agent, ...diff?.length ? { diff } : {}, call: toolCall(name, input) };
|
|
295
|
+
}
|
|
296
|
+
var CALL_VALUE_CHARS = 2e3;
|
|
297
|
+
var CALL_INPUT_MAX_CHARS = 4096;
|
|
298
|
+
function clipValue(value, limit, depth = 0) {
|
|
299
|
+
if (typeof value === "string") return value.length > limit ? `${value.slice(0, limit - 1)}\u2026` : value;
|
|
300
|
+
if (value === null || typeof value !== "object") return value;
|
|
301
|
+
if (depth >= 3) return clipValue(JSON.stringify(value), limit);
|
|
302
|
+
if (Array.isArray(value)) return value.slice(0, 50).map((item) => clipValue(item, limit, depth + 1));
|
|
303
|
+
return Object.fromEntries(Object.entries(value).slice(0, 50).map(([key, item]) => [key, clipValue(item, limit, depth + 1)]));
|
|
304
|
+
}
|
|
305
|
+
function boundCallInput(input) {
|
|
306
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return void 0;
|
|
307
|
+
for (const limit of [CALL_VALUE_CHARS, 400, 80]) {
|
|
308
|
+
const clipped = clipValue(input, limit);
|
|
309
|
+
if (JSON.stringify(clipped).length <= CALL_INPUT_MAX_CHARS) return clipped;
|
|
310
|
+
}
|
|
311
|
+
return Object.fromEntries(Object.keys(input).slice(0, 50).map((key) => [key, "\u2026"]));
|
|
312
|
+
}
|
|
313
|
+
function toolCall(name, input) {
|
|
314
|
+
const bounded = boundCallInput(input);
|
|
315
|
+
return { name, ...bounded ? { input: bounded } : {} };
|
|
316
|
+
}
|
|
317
|
+
function claudeToolStart(tool, command) {
|
|
318
|
+
return { kind: "tool-start", ...toolFacts(String(tool.name ?? "tool"), asRecord(tool.input), command), ...typeof tool.id === "string" ? { id: tool.id } : {} };
|
|
319
|
+
}
|
|
320
|
+
function parseNativeActivityEventsFromValue(harness, parsed) {
|
|
321
|
+
const value = asRecord(parsed);
|
|
322
|
+
if (!value) return [];
|
|
323
|
+
if (claudeShaped(harness)) {
|
|
324
|
+
const claude = claudeShapedActivity(value, harness.command);
|
|
325
|
+
if (claude) return claude;
|
|
326
|
+
}
|
|
327
|
+
if (harness.parser === "goose") {
|
|
328
|
+
const goose = gooseActivity(value, harness.command);
|
|
329
|
+
if (goose) return goose;
|
|
330
|
+
}
|
|
331
|
+
const single = singleActivityEvent(harness, value);
|
|
332
|
+
return single ? [single] : [];
|
|
333
|
+
}
|
|
334
|
+
function claudeShapedActivity(value, command) {
|
|
335
|
+
const type = String(value.type ?? "");
|
|
336
|
+
const parent = typeof value.parent_tool_use_id === "string" && value.parent_tool_use_id ? { parentId: value.parent_tool_use_id } : {};
|
|
337
|
+
if (type === "system" || type === "result" || type === "rate_limit_event" || type === "stream_event") return [];
|
|
338
|
+
const message = asRecord(value.message);
|
|
339
|
+
const content = message?.content;
|
|
340
|
+
if (type === "assistant") {
|
|
341
|
+
if (!Array.isArray(content)) return [];
|
|
342
|
+
const thoughtId = typeof message?.id === "string" ? { id: claudeThinkingId(message.id) } : {};
|
|
343
|
+
return content.flatMap((part) => {
|
|
344
|
+
const block = asRecord(part);
|
|
345
|
+
if (block?.type === "tool_use" || block?.type === "server_tool_use") return [{ ...claudeToolStart(block, command), ...parent }];
|
|
346
|
+
if (block?.type === "thinking" && typeof block.thinking === "string" && block.thinking.trim()) {
|
|
347
|
+
return [{ kind: "thinking", label: thoughtLabel(block.thinking), ...thoughtId, ...parent }];
|
|
348
|
+
}
|
|
349
|
+
return [];
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
if (type === "user") {
|
|
353
|
+
if (!Array.isArray(content)) return [];
|
|
354
|
+
const results = content.filter((part) => asRecord(part)?.type === "tool_result");
|
|
355
|
+
const totals = results.length === 1 ? subAgentTotals(asRecord(value.tool_use_result ?? value.toolUseResult)) : {};
|
|
356
|
+
return results.flatMap((part) => {
|
|
357
|
+
const result = asRecord(part);
|
|
358
|
+
const output = cappedActivityOutput(blockText(result.content));
|
|
359
|
+
return [{
|
|
360
|
+
kind: result.is_error === true ? "tool-error" : "tool-done",
|
|
361
|
+
label: "tool",
|
|
362
|
+
...typeof result.tool_use_id === "string" ? { id: result.tool_use_id } : {},
|
|
363
|
+
...output,
|
|
364
|
+
...totals,
|
|
365
|
+
...parent
|
|
366
|
+
}];
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
return void 0;
|
|
370
|
+
}
|
|
371
|
+
function subAgentTotals(result) {
|
|
372
|
+
const count = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
373
|
+
const tools = count(result?.totalToolUseCount);
|
|
374
|
+
const tokens = count(result?.totalTokens);
|
|
375
|
+
const duration = count(result?.totalDurationMs);
|
|
376
|
+
return {
|
|
377
|
+
...tools !== void 0 ? { childTools: tools } : {},
|
|
378
|
+
...tokens ? { childTokens: tokens } : {},
|
|
379
|
+
...duration !== void 0 && (tools !== void 0 || tokens !== void 0) ? { durationMs: duration } : {}
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function gooseActivity(value, command) {
|
|
383
|
+
if (value.type !== "message") return void 0;
|
|
384
|
+
const content = asRecord(value.message)?.content;
|
|
385
|
+
if (!Array.isArray(content)) return [];
|
|
386
|
+
return content.flatMap((part, index) => {
|
|
387
|
+
const block = asRecord(part);
|
|
388
|
+
const identity = typeof block?.id === "string" ? { id: block.id } : {};
|
|
389
|
+
if (block?.type === "toolRequest") {
|
|
390
|
+
const call = asRecord(block.toolCall);
|
|
391
|
+
const detail = asRecord(call?.value) ?? call;
|
|
392
|
+
const name = String(detail?.name ?? "tool");
|
|
393
|
+
const args = asRecord(detail?.arguments);
|
|
394
|
+
const kind = call?.status === "error" ? "tool-error" : "tool-start";
|
|
395
|
+
return [{ kind, ...toolFacts(name, args, command), ...identity }];
|
|
396
|
+
}
|
|
397
|
+
if (block?.type === "toolResponse") {
|
|
398
|
+
const result = asRecord(block.toolResult);
|
|
399
|
+
const failed = result?.status === "error" || result?.isError === true || asRecord(result?.value)?.isError === true;
|
|
400
|
+
const payload = Array.isArray(result?.value) ? result.value : asRecord(result?.value)?.content;
|
|
401
|
+
const output = cappedActivityOutput(blockText(payload));
|
|
402
|
+
return [{ kind: failed ? "tool-error" : "tool-done", label: "tool", ...identity, ...output }];
|
|
403
|
+
}
|
|
404
|
+
if (block?.type === "thinking" && typeof block.thinking === "string" && block.thinking.trim()) {
|
|
405
|
+
const messageId = asRecord(value.message)?.id;
|
|
406
|
+
const thoughtKey = typeof messageId === "string" && messageId ? { id: `thinking:${messageId}:${index}` } : {};
|
|
407
|
+
return [{ kind: "thinking", label: visibleSlice(block.thinking.trim().replace(/\s+/g, " "), 140), ...thoughtKey }];
|
|
408
|
+
}
|
|
409
|
+
return [];
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
function cursorActivity(value) {
|
|
413
|
+
if (value.type === "thinking" && typeof value.text === "string" && value.text) return { kind: "thinking", label: value.text };
|
|
414
|
+
if (value.type !== "tool_call") return void 0;
|
|
415
|
+
const call = asRecord(value.tool_call);
|
|
416
|
+
const tagged = asRecord(call?.tool);
|
|
417
|
+
const [kind, body] = typeof tagged?.case === "string" ? [tagged.case, asRecord(tagged.value)] : Object.entries(call ?? {}).map(([key, entry]) => [key, asRecord(entry)])[0] ?? [];
|
|
418
|
+
if (!kind) return void 0;
|
|
419
|
+
const result = asRecord(body?.result);
|
|
420
|
+
const success = asRecord(result?.success);
|
|
421
|
+
const error = asRecord(result?.error) ?? asRecord(result?.failure);
|
|
422
|
+
const text = [success?.stdout, success?.stderr, success?.output, success?.content, error?.stderr, error?.message, error?.error].filter((part) => typeof part === "string" && part.length > 0).join("\n");
|
|
423
|
+
const exitCode = [success?.exitCode, error?.exitCode].find((code) => typeof code === "number");
|
|
424
|
+
const done = value.subtype === "completed";
|
|
425
|
+
return {
|
|
426
|
+
kind: done ? error || (exitCode ?? 0) !== 0 ? "tool-error" : "tool-done" : "tool-start",
|
|
427
|
+
...toolFacts(String(kind).replace(/ToolCall$/, ""), asRecord(body?.args), "cursor"),
|
|
428
|
+
...typeof value.call_id === "string" ? { id: value.call_id } : {},
|
|
429
|
+
...done && text ? activityOutput(text, { tail: true }) : {},
|
|
430
|
+
...done && exitCode !== void 0 ? { exitCode } : {}
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function singleActivityEvent(harness, value) {
|
|
434
|
+
const type = String(value.type ?? "");
|
|
435
|
+
if (harness.parser === "cursor-stream-json") return cursorActivity(value);
|
|
436
|
+
if (harness.parser === "antigravity" && value.event === "step_update") {
|
|
437
|
+
const step = value.step_update && typeof value.step_update === "object" ? value.step_update : void 0;
|
|
438
|
+
if (step?.step_type === "tool") {
|
|
439
|
+
const state = String(step.state ?? "");
|
|
440
|
+
const name = String(step.tool_name ?? "tool");
|
|
441
|
+
const parameters = asRecord(asRecord(step.tool_info)?.parameters);
|
|
442
|
+
const stepIndex = step.step_index;
|
|
443
|
+
return {
|
|
444
|
+
kind: /error|fail/i.test(state) ? "tool-error" : state === "DONE" ? "tool-done" : "tool-start",
|
|
445
|
+
...toolFacts(name, parameters, harness.command),
|
|
446
|
+
...typeof stepIndex === "number" ? { id: `step-${stepIndex}` } : {}
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
if (opencodeShaped(harness) && type === "reasoning") {
|
|
451
|
+
const part = asRecord(value.part);
|
|
452
|
+
const text = typeof part?.text === "string" ? part.text : "";
|
|
453
|
+
if (text.trim()) return { kind: "thinking", label: thoughtLabel(text), ...typeof part?.id === "string" ? { id: `thinking:${part.id}` } : {} };
|
|
454
|
+
return void 0;
|
|
455
|
+
}
|
|
456
|
+
if (opencodeShaped(harness) && type === "tool_use") {
|
|
457
|
+
const part = asRecord(value.part);
|
|
458
|
+
const state = asRecord(part?.state);
|
|
459
|
+
const name = String(part?.tool ?? "tool");
|
|
460
|
+
const status = String(state?.status ?? "");
|
|
461
|
+
const output = typeof state?.output === "string" ? cappedActivityOutput(state.output) : {};
|
|
462
|
+
return {
|
|
463
|
+
kind: /error|fail/i.test(status) ? "tool-error" : status === "completed" ? "tool-done" : "tool-start",
|
|
464
|
+
...toolFacts(name, asRecord(state?.input), harness.command),
|
|
465
|
+
...typeof part?.callID === "string" ? { id: part.callID } : typeof part?.id === "string" ? { id: part.id } : {},
|
|
466
|
+
...output
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
if (harness.eventDialect === "command-code") {
|
|
470
|
+
const inner = type === "event" ? asRecord(value.event) : value;
|
|
471
|
+
const innerType = String(inner?.type ?? "");
|
|
472
|
+
const kind = innerType === "tool_running" ? "tool-start" : innerType === "tool_completed" ? "tool-done" : /^tool_(?:errored|denied|hook_blocked)$/.test(innerType) ? "tool-error" : void 0;
|
|
473
|
+
if (inner && kind) {
|
|
474
|
+
const name = String(inner.toolName ?? "tool");
|
|
475
|
+
const description = typeof inner.description === "string" ? inner.description.trim().split(/\r?\n/, 1)[0] : "";
|
|
476
|
+
const rawOutput = innerType === "tool_completed" ? blockText(inner.result) : typeof inner.error === "string" ? inner.error : "";
|
|
477
|
+
const output = cappedActivityOutput(rawOutput);
|
|
478
|
+
const classified = categoryOf(name, void 0, harness.command);
|
|
479
|
+
return {
|
|
480
|
+
// Through the shared formatter, and on every kind -- this repeated
|
|
481
|
+
// the format inline and showed the description only while running,
|
|
482
|
+
// so the same tool changed shape the moment it finished.
|
|
483
|
+
kind,
|
|
484
|
+
label: formatToolRow(name, description, classified.category),
|
|
485
|
+
...classified,
|
|
486
|
+
...typeof inner.toolCallId === "string" ? { id: inner.toolCallId } : {},
|
|
487
|
+
...output
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
if (harness.parser === "pi-json") {
|
|
492
|
+
const piTool = (record, start) => {
|
|
493
|
+
const name = String(record.toolName ?? "tool");
|
|
494
|
+
const id = typeof record.toolCallId === "string" && record.toolCallId ? record.toolCallId : void 0;
|
|
495
|
+
const args = asRecord(record.args);
|
|
496
|
+
const facts = toolFacts(name, args, harness.command);
|
|
497
|
+
const label = !id ? formatToolRow(name, void 0, facts.category) : start || args ? facts.label : "tool";
|
|
498
|
+
return { kind: "tool-start", ...facts, label, ...id ? { id } : {} };
|
|
499
|
+
};
|
|
500
|
+
const reasoning = type === "message_update" ? asRecord(value.assistantMessageEvent) : void 0;
|
|
501
|
+
if (reasoning && /^thinking_(?:start|delta|end)$/.test(String(reasoning.type))) {
|
|
502
|
+
const content = asRecord(reasoning.partial)?.content;
|
|
503
|
+
const block = Array.isArray(content) && typeof reasoning.contentIndex === "number" ? asRecord(content[reasoning.contentIndex]) : void 0;
|
|
504
|
+
const text = typeof block?.thinking === "string" ? block.thinking : typeof reasoning.content === "string" ? reasoning.content : "";
|
|
505
|
+
return text.trim() ? { kind: "thinking", label: thoughtLabel(text) } : void 0;
|
|
506
|
+
}
|
|
507
|
+
if (type === "tool_execution_start") return piTool(value, true);
|
|
508
|
+
if (type === "tool_execution_end") {
|
|
509
|
+
const result = asRecord(value.result);
|
|
510
|
+
const said = blockText(result?.content) || (typeof value.error === "string" ? value.error : "") || (typeof result?.error === "string" ? result.error : "");
|
|
511
|
+
return { ...piTool(value, false), kind: value.isError === true || value.error ? "tool-error" : "tool-done", ...cappedActivityOutput(said) };
|
|
512
|
+
}
|
|
513
|
+
const event = type === "message_update" ? asRecord(value.assistantMessageEvent) : void 0;
|
|
514
|
+
if (event?.type === "toolcall_start") {
|
|
515
|
+
const content = asRecord(event.partial)?.content;
|
|
516
|
+
const call = Array.isArray(content) && typeof event.contentIndex === "number" ? asRecord(content[event.contentIndex]) : void 0;
|
|
517
|
+
return piTool(call ? { toolCallId: call.id, toolName: call.name, args: call.arguments } : { toolCallId: event.id, toolName: event.toolName ?? event.name, args: event.args ?? event.arguments }, true);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return void 0;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// src/harness/protocol/activity-normalize.ts
|
|
524
|
+
var OUTPUT_LINES = 60;
|
|
525
|
+
var OUTPUT_LINE_CHARS = 400;
|
|
526
|
+
var CANONICAL_LABEL = {
|
|
527
|
+
run: /^\$ /,
|
|
528
|
+
read: /^Read(?: |$)/,
|
|
529
|
+
edit: /^(?:Edit|Write|Delete)(?: |$)/,
|
|
530
|
+
search: /^(?:Glob|Grep|List|Search)(?: |$)/,
|
|
531
|
+
fetch: /^(?:Fetch|Web search)(?: |$)/
|
|
532
|
+
};
|
|
533
|
+
function categoryFromLabel(label) {
|
|
534
|
+
for (const category of Object.keys(CANONICAL_LABEL)) if (CANONICAL_LABEL[category].test(label)) return category;
|
|
535
|
+
const called = /^([A-Za-z_][\w-]*)\(/.exec(label);
|
|
536
|
+
return called ? toolCategory(called[1]) : void 0;
|
|
537
|
+
}
|
|
538
|
+
function categoryFor(event) {
|
|
539
|
+
if (event.category) return event.category;
|
|
540
|
+
if (event.agent) return void 0;
|
|
541
|
+
if (event.diff?.length) return "edit";
|
|
542
|
+
if (event.call) {
|
|
543
|
+
const named = toolCategory(event.call.name, event.call.input);
|
|
544
|
+
if (named) return named;
|
|
545
|
+
}
|
|
546
|
+
return categoryFromLabel(event.label);
|
|
547
|
+
}
|
|
548
|
+
function labelFor(event, category) {
|
|
549
|
+
const { label } = event;
|
|
550
|
+
if (!label || label === "tool") return label;
|
|
551
|
+
if (event.agent) {
|
|
552
|
+
const called2 = /^([A-Za-z_][\w-]*)\((.*)\)$/s.exec(label);
|
|
553
|
+
return called2 && isAgentToolName(called2[1]) ? formatToolRow("agent", called2[2]) : label;
|
|
554
|
+
}
|
|
555
|
+
if (!category || CANONICAL_LABEL[category].test(label)) return label;
|
|
556
|
+
const called = /^([A-Za-z_][\w-]*)\((.*)\)$/s.exec(label);
|
|
557
|
+
if (called) return formatToolRow(called[1], called[2], category);
|
|
558
|
+
const ticked = /^`([^`\n]+)`$/.exec(label);
|
|
559
|
+
if (ticked) return formatToolRow("shell", ticked[1], category);
|
|
560
|
+
if (event.call && event.id) {
|
|
561
|
+
const built = toolLabel(event.call.name, event.call.input, category);
|
|
562
|
+
if (built !== formatToolRow(event.call.name, void 0, category)) return built;
|
|
563
|
+
}
|
|
564
|
+
return label;
|
|
565
|
+
}
|
|
566
|
+
function boundedOutput(event, category) {
|
|
567
|
+
const lines = event.output;
|
|
568
|
+
if (!lines?.length) return void 0;
|
|
569
|
+
const clipped = lines.some((line) => line.length > OUTPUT_LINE_CHARS);
|
|
570
|
+
if (lines.length <= OUTPUT_LINES && !clipped) return void 0;
|
|
571
|
+
const clip2 = (line) => line.length > OUTPUT_LINE_CHARS ? `${line.slice(0, OUTPUT_LINE_CHARS - 1)}\u2026` : line;
|
|
572
|
+
const fromEnd = event.outputTail === true || category === "run" && !event.outputOmitted;
|
|
573
|
+
const kept = (fromEnd ? lines.slice(-OUTPUT_LINES) : lines.slice(0, OUTPUT_LINES)).map(clip2);
|
|
574
|
+
const dropped = lines.length - kept.length;
|
|
575
|
+
return {
|
|
576
|
+
output: kept,
|
|
577
|
+
...dropped || event.outputOmitted ? { outputOmitted: (event.outputOmitted ?? 0) + dropped } : {},
|
|
578
|
+
...fromEnd ? { outputTail: true } : {},
|
|
579
|
+
...fromEnd && dropped && !event.outputHead ? { outputHead: lines.slice(0, COMMAND_HEAD_LINES).map(clip2) } : {}
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
var finite = (value) => typeof value === "number" && Number.isFinite(value);
|
|
583
|
+
function normalizeActivityEvent(event) {
|
|
584
|
+
if (event.kind === "thinking") {
|
|
585
|
+
const label2 = thoughtLabel(event.label);
|
|
586
|
+
return label2 === event.label ? event : { ...event, label: label2 };
|
|
587
|
+
}
|
|
588
|
+
const agent = event.agent || event.call && (isAgentToolName(event.call.name) || typeof event.call.input?.subagent_type === "string") ? true : void 0;
|
|
589
|
+
const base = agent && !event.agent ? { ...event, agent } : event;
|
|
590
|
+
const category = categoryFor(base);
|
|
591
|
+
const label = labelFor(base, category);
|
|
592
|
+
const failedExit = base.kind === "tool-done" && !base.stopped && finite(base.exitCode) && base.exitCode !== 0;
|
|
593
|
+
const output = boundedOutput(base, category);
|
|
594
|
+
const next = {
|
|
595
|
+
...base,
|
|
596
|
+
...category && !base.category ? { category } : {},
|
|
597
|
+
...label !== base.label ? { label } : {},
|
|
598
|
+
...failedExit ? { kind: "tool-error" } : {},
|
|
599
|
+
...output
|
|
600
|
+
};
|
|
601
|
+
if (next.exitCode !== void 0 && !finite(next.exitCode)) delete next.exitCode;
|
|
602
|
+
if (next.durationMs !== void 0 && (!finite(next.durationMs) || next.durationMs < 0)) delete next.durationMs;
|
|
603
|
+
const same = next.category === event.category && next.label === event.label && next.kind === event.kind && next.agent === event.agent && next.output === event.output && next.exitCode === event.exitCode && next.durationMs === event.durationMs;
|
|
604
|
+
return same ? event : next;
|
|
605
|
+
}
|
|
606
|
+
var CODEX_AGENT_ROW = /^agent:(.+)$/;
|
|
607
|
+
function subAgentRef(event, harness, modes) {
|
|
608
|
+
if (event.kind === "thinking" || !event.agent || !event.id || event.parentId) return void 0;
|
|
609
|
+
const agentId = event.agentId ?? (harness === "codex" ? CODEX_AGENT_ROW.exec(event.id)?.[1] : void 0);
|
|
610
|
+
const status = event.kind === "tool-start" ? "running" : event.kind === "tool-done" ? "done" : event.stopped ? "stopped" : "error";
|
|
611
|
+
return {
|
|
612
|
+
id: event.id,
|
|
613
|
+
...agentId ? { agentId } : {},
|
|
614
|
+
label: event.label,
|
|
615
|
+
status,
|
|
616
|
+
harness,
|
|
617
|
+
read: modes?.read ?? "none",
|
|
618
|
+
steer: modes?.steer ?? "none"
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function subAgentSteerBlock(ref, vendor) {
|
|
622
|
+
if (ref.status !== "running") return "This sub-agent has finished: nothing to steer.";
|
|
623
|
+
if (ref.steer === "none") return `${vendor} gives ClikCode no way to message a running sub-agent: this view is read-only.`;
|
|
624
|
+
return void 0;
|
|
625
|
+
}
|
|
626
|
+
function subAgentRelayText(ref, text) {
|
|
627
|
+
const to = ref.agentId ? `${ref.label} (${ref.agentId})` : ref.label;
|
|
628
|
+
return `Send this to your sub-agent ${to}: ${text}`;
|
|
629
|
+
}
|
|
630
|
+
function subAgentSteerPlan(ref, vendor, mainRunning, text) {
|
|
631
|
+
const block = subAgentSteerBlock(ref, vendor);
|
|
632
|
+
if (block) return { refuse: block };
|
|
633
|
+
if (!mainRunning) return { refuse: "The main agent is not running, so there is nothing to carry the message to the sub-agent." };
|
|
634
|
+
if (ref.steer !== "relay") return { refuse: `ClikCode does not send to a ${vendor} sub-agent by ${ref.steer} yet.` };
|
|
635
|
+
return { steer: subAgentRelayText(ref, text) };
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// src/turn/turn-activities.ts
|
|
639
|
+
var MAX_LABEL_CHARS = 2e3;
|
|
640
|
+
var MAX_LINE_CHARS = 2e3;
|
|
641
|
+
var MAX_OUTPUT_LINES = 60;
|
|
642
|
+
var MAX_DIFF_LINES = 200;
|
|
643
|
+
var MAX_DIFF_FILES = 20;
|
|
644
|
+
var MAX_TURN_ACTIVITY_BYTES = 1024 * 1024;
|
|
645
|
+
var KINDS = /* @__PURE__ */ new Set(["tool-start", "tool-done", "tool-error"]);
|
|
646
|
+
var clip = (text, limit = MAX_LINE_CHARS) => text.length > limit ? `${text.slice(0, limit - 1)}\u2026` : text;
|
|
647
|
+
function boundDiff(files, perFile, withLines) {
|
|
648
|
+
return files.map((file, index) => {
|
|
649
|
+
const keep = index < withLines ? perFile : 0;
|
|
650
|
+
if (file.lines.length <= keep && file.lines.every((line) => line.text.length <= MAX_LINE_CHARS)) return file;
|
|
651
|
+
const lines = file.lines.slice(0, keep).map((line) => ({ ...line, text: clip(line.text) }));
|
|
652
|
+
return { ...file, lines, omitted: (file.omitted ?? 0) + file.lines.length - lines.length };
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
function boundOutput(event, limit) {
|
|
656
|
+
const output = event.output;
|
|
657
|
+
if (!output) return event;
|
|
658
|
+
const cleanHead = event.outputHead?.slice(0, COMMAND_HEAD_LINES).map((line) => clip(line));
|
|
659
|
+
if (output.length <= limit && output.every((line) => line.length <= MAX_LINE_CHARS)) {
|
|
660
|
+
return cleanHead && cleanHead.length !== event.outputHead.length ? { ...event, outputHead: cleanHead } : event;
|
|
661
|
+
}
|
|
662
|
+
const fromEnd = event.outputTail === true || event.category === "run" && !event.outputOmitted;
|
|
663
|
+
const kept = (fromEnd ? output.slice(-limit) : output.slice(0, limit)).map((line) => clip(line));
|
|
664
|
+
const dropped = output.length - kept.length;
|
|
665
|
+
return {
|
|
666
|
+
...event,
|
|
667
|
+
output: kept,
|
|
668
|
+
...dropped || event.outputOmitted ? { outputOmitted: (event.outputOmitted ?? 0) + dropped } : {},
|
|
669
|
+
...fromEnd && dropped ? {
|
|
670
|
+
outputTail: true,
|
|
671
|
+
outputHead: cleanHead ?? output.slice(0, COMMAND_HEAD_LINES).map((line) => clip(line))
|
|
672
|
+
} : cleanHead ? { outputHead: cleanHead } : {}
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
function boundEvent(event) {
|
|
676
|
+
const { diff: rawDiff, ...rest } = event;
|
|
677
|
+
const diff = asFileDiffs(rawDiff);
|
|
678
|
+
const bounded = boundOutput({ ...rest, label: clip(event.label, MAX_LABEL_CHARS) }, MAX_OUTPUT_LINES);
|
|
679
|
+
return diff?.length ? { ...bounded, diff: boundDiff(diff, MAX_DIFF_LINES, MAX_DIFF_FILES) } : bounded;
|
|
680
|
+
}
|
|
681
|
+
function shrink(activity, bare) {
|
|
682
|
+
const { diff: rawDiff, output: _output, outputHead: _head, outputOmitted: _omitted, outputTail: _tail, ...rest } = activity.event;
|
|
683
|
+
const diff = asFileDiffs(rawDiff);
|
|
684
|
+
if (bare) {
|
|
685
|
+
const lines = (activity.event.output?.length ?? 0) + (activity.event.outputOmitted ?? 0);
|
|
686
|
+
const { call, ...withoutCall } = rest;
|
|
687
|
+
return {
|
|
688
|
+
...activity,
|
|
689
|
+
event: {
|
|
690
|
+
...withoutCall,
|
|
691
|
+
...call ? { call: { name: call.name } } : {},
|
|
692
|
+
...lines ? { output: [], outputOmitted: lines } : {},
|
|
693
|
+
...diff?.length ? { diff: boundDiff(diff, 0, 0) } : {}
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
const budget = Math.max(ACTIVITY_PREVIEW_LINES, COMMAND_HEAD_LINES + COMMAND_TAIL_LINES);
|
|
698
|
+
const event = boundOutput(activity.event, budget);
|
|
699
|
+
return { ...activity, event: diff?.length ? { ...event, diff: boundDiff(diff, DIFF_PREVIEW_LINES, DIFF_PREVIEW_FILES) } : event };
|
|
700
|
+
}
|
|
701
|
+
function viewedActivity(activity, bare) {
|
|
702
|
+
const { call: _call, ...event } = shrink(activity, bare).event;
|
|
703
|
+
return { ...activity, event: { ...event, detailOmitted: true } };
|
|
704
|
+
}
|
|
705
|
+
var sizes = /* @__PURE__ */ new WeakMap();
|
|
706
|
+
function sizeOf(activity) {
|
|
707
|
+
let size = sizes.get(activity);
|
|
708
|
+
if (size === void 0) {
|
|
709
|
+
size = JSON.stringify(activity).length;
|
|
710
|
+
sizes.set(activity, size);
|
|
711
|
+
}
|
|
712
|
+
return size;
|
|
713
|
+
}
|
|
714
|
+
var MAX_CHILDREN_PER_PARENT = 40;
|
|
715
|
+
function boundTurnActivities(activities, limit = MAX_TURN_ACTIVITY_BYTES) {
|
|
716
|
+
let total = activities.reduce((sum, activity) => sum + sizeOf(activity) + 1, 1);
|
|
717
|
+
if (total <= limit) return activities;
|
|
718
|
+
const next = [...activities];
|
|
719
|
+
const isChild = (activity) => Boolean(activity.event.parentId);
|
|
720
|
+
const trim = (children, bare) => {
|
|
721
|
+
for (let index = 0; index < next.length - 1 && total > limit; index += 1) {
|
|
722
|
+
if (isChild(next[index]) !== children) continue;
|
|
723
|
+
const before = sizeOf(next[index]);
|
|
724
|
+
next[index] = shrink(next[index], bare);
|
|
725
|
+
total += sizeOf(next[index]) - before;
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
for (const children of [true, false]) {
|
|
729
|
+
for (const bare of [false, true]) trim(children, bare);
|
|
730
|
+
}
|
|
731
|
+
for (let index = 0; index < next.length - 1 && total > limit; ) {
|
|
732
|
+
if (isChild(next[index])) total -= sizeOf(next.splice(index, 1)[0]) + 1;
|
|
733
|
+
else index += 1;
|
|
734
|
+
}
|
|
735
|
+
while (total > limit && next.length > 1) total -= sizeOf(next.shift()) + 1;
|
|
736
|
+
return next;
|
|
737
|
+
}
|
|
738
|
+
function capChildren(activities, parentId) {
|
|
739
|
+
let count = 0;
|
|
740
|
+
for (const activity of activities) if (activity.event.parentId === parentId) count += 1;
|
|
741
|
+
if (count <= MAX_CHILDREN_PER_PARENT) return activities;
|
|
742
|
+
const next = [...activities];
|
|
743
|
+
let drop = count - MAX_CHILDREN_PER_PARENT;
|
|
744
|
+
for (const settledOnly of [true, false]) {
|
|
745
|
+
for (let index = 0; index < next.length && drop > 0; ) {
|
|
746
|
+
const event = next[index].event;
|
|
747
|
+
if (event.parentId === parentId && (!settledOnly || event.kind !== "tool-start")) {
|
|
748
|
+
next.splice(index, 1);
|
|
749
|
+
drop -= 1;
|
|
750
|
+
} else index += 1;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return next;
|
|
754
|
+
}
|
|
755
|
+
function recordTurnActivity(activities, event, responseOffset) {
|
|
756
|
+
if (event.kind === "thinking") return activities;
|
|
757
|
+
let current = activities;
|
|
758
|
+
if (event.parentId && event.kind === "tool-start") {
|
|
759
|
+
const index = current.findIndex((activity) => activity.event.id === event.parentId && !activity.event.parentId);
|
|
760
|
+
if (index >= 0) {
|
|
761
|
+
current = [...current];
|
|
762
|
+
current[index] = { ...current[index], event: withChildTool(current[index].event, event) };
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
const bounded = boundEvent(event);
|
|
766
|
+
for (let index = current.length - 1; index >= 0; index -= 1) {
|
|
767
|
+
const prior = current[index];
|
|
768
|
+
if (prior.event.parentId !== bounded.parentId || !sameCall(prior.event, bounded)) continue;
|
|
769
|
+
const next = [...current];
|
|
770
|
+
next[index] = { responseOffset: prior.responseOffset, event: boundEvent(mergeActivity(prior.event, bounded)) };
|
|
771
|
+
return boundTurnActivities(next);
|
|
772
|
+
}
|
|
773
|
+
const added = [...current, { event: bounded, responseOffset: Math.max(0, responseOffset) }];
|
|
774
|
+
return boundTurnActivities(bounded.parentId ? capChildren(added, bounded.parentId) : added);
|
|
775
|
+
}
|
|
776
|
+
function readTurnActivities(value, legacyOffset = 0) {
|
|
777
|
+
if (!Array.isArray(value)) return [];
|
|
778
|
+
let activities = [];
|
|
779
|
+
let legacy = false;
|
|
780
|
+
for (const item of value) {
|
|
781
|
+
if (typeof item === "string") {
|
|
782
|
+
const match = /^(started|completed|failed) ([\s\S]+)$/.exec(item.trim());
|
|
783
|
+
if (!match) continue;
|
|
784
|
+
legacy = true;
|
|
785
|
+
const kind = match[1] === "started" ? "tool-start" : match[1] === "failed" ? "tool-error" : "tool-done";
|
|
786
|
+
if (match[2] === "tool" && kind !== "tool-start") {
|
|
787
|
+
let open = activities.length - 1;
|
|
788
|
+
while (open >= 0 && activities[open].event.kind !== "tool-start") open -= 1;
|
|
789
|
+
if (open >= 0) activities[open] = { ...activities[open], event: { ...activities[open].event, kind } };
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
activities = recordTurnActivity(activities, normalizeActivityEvent({ kind, label: match[2] }), legacyOffset);
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
const record = item;
|
|
796
|
+
const event = record?.event;
|
|
797
|
+
if (!event || typeof event !== "object" || typeof event.label !== "string" || !KINDS.has(String(event.kind))) continue;
|
|
798
|
+
const offset = record.responseOffset;
|
|
799
|
+
const normalized = normalizeActivityEvent(event);
|
|
800
|
+
const sameEvent = normalized === event;
|
|
801
|
+
activities.push(typeof offset === "number" && Number.isFinite(offset) && offset >= 0 ? sameEvent ? record : { ...record, event: normalized } : { event: normalized, responseOffset: legacyOffset });
|
|
802
|
+
}
|
|
803
|
+
if (!legacy && activities.length === value.length && activities.every((activity, index) => activity === value[index])) return value;
|
|
804
|
+
return activities;
|
|
805
|
+
}
|
|
806
|
+
function runningTurnActivity(activities) {
|
|
807
|
+
let last;
|
|
808
|
+
for (let index = activities.length - 1; index >= 0; index -= 1) {
|
|
809
|
+
if (!activities[index].event.parentId) {
|
|
810
|
+
last = activities[index].event;
|
|
811
|
+
break;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
return last?.kind === "tool-start" ? last : void 0;
|
|
815
|
+
}
|
|
816
|
+
function activitiesBetween(activities, start, end, length, first2, startSeq, endSeq, textStart = start) {
|
|
817
|
+
return betweenSteers(activities, (activity) => activity.event.seq, start, end, length, first2, startSeq, endSeq).map((activity) => ({ ...activity, responseOffset: Math.min(length, Math.max(0, activity.responseOffset - textStart)) }));
|
|
818
|
+
}
|
|
819
|
+
function marksBetween(marks, start, end, length, first2, startSeq, endSeq, textStart = start) {
|
|
820
|
+
return betweenSteers(marks, (mark) => mark.seq, start, end, length, first2, startSeq, endSeq).map((mark) => ({ ...mark, responseOffset: Math.min(length, Math.max(0, mark.responseOffset - textStart)) }));
|
|
821
|
+
}
|
|
822
|
+
function betweenSteers(items, seqOf, start, end, _length, first2, startSeq, endSeq) {
|
|
823
|
+
return items.filter((item) => {
|
|
824
|
+
const place = { responseOffset: item.responseOffset, seq: seqOf(item) };
|
|
825
|
+
const afterStart = first2 ? item.responseOffset >= start : !markBefore(place, { responseOffset: start, seq: startSeq });
|
|
826
|
+
const beforeEnd = end === void 0 || markBefore(place, { responseOffset: end, seq: endSeq });
|
|
827
|
+
return afterStart && beforeEnd;
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
function stopOpenActivities(activities) {
|
|
831
|
+
if (!activities.some((activity) => activity.event.kind === "tool-start")) return activities;
|
|
832
|
+
return activities.map((activity) => activity.event.kind === "tool-start" ? { ...activity, event: stoppedCall(activity.event) } : activity);
|
|
833
|
+
}
|
|
834
|
+
var SUMMARY_MAX_CHARS = 1500;
|
|
835
|
+
function activityTextSummary(activities) {
|
|
836
|
+
const rows = activities.map(({ event }) => `${event.label}${event.stopped ? " (stopped)" : event.kind === "tool-error" ? " (failed)" : event.kind === "tool-start" ? " (not finished)" : ""}`);
|
|
837
|
+
const kept = [];
|
|
838
|
+
let room = SUMMARY_MAX_CHARS;
|
|
839
|
+
for (let index = rows.length - 1; index >= 0; index -= 1) {
|
|
840
|
+
const row = rows[index];
|
|
841
|
+
if (row.length + 2 > room) break;
|
|
842
|
+
kept.unshift(row);
|
|
843
|
+
room -= row.length + 2;
|
|
844
|
+
}
|
|
845
|
+
const earlier = rows.length - kept.length;
|
|
846
|
+
return `Tool calls: ${earlier ? `(${earlier} earlier) ` : ""}${kept.join("; ")}.`;
|
|
847
|
+
}
|
|
848
|
+
function textTranscript(messages) {
|
|
849
|
+
return messages.flatMap((message) => {
|
|
850
|
+
if (message.automatic) return [];
|
|
851
|
+
if (message.role !== "assistant" || message.content.trim()) return [{ role: message.role, content: message.content }];
|
|
852
|
+
const activities = readTurnActivities(message.activities);
|
|
853
|
+
return activities.length ? [{ role: "assistant", content: activityTextSummary(activities) }] : [];
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
export {
|
|
858
|
+
asFileDiffs,
|
|
859
|
+
fileDiff,
|
|
860
|
+
eventDiff,
|
|
861
|
+
activityOutput,
|
|
862
|
+
commandOutcome,
|
|
863
|
+
fileChangeActivity,
|
|
864
|
+
thoughtLabel,
|
|
865
|
+
claudeThinkingId,
|
|
866
|
+
editDiffFromInput,
|
|
867
|
+
toolFacts,
|
|
868
|
+
toolCall,
|
|
869
|
+
claudeToolStart,
|
|
870
|
+
parseNativeActivityEventsFromValue,
|
|
871
|
+
normalizeActivityEvent,
|
|
872
|
+
subAgentRef,
|
|
873
|
+
subAgentSteerBlock,
|
|
874
|
+
subAgentSteerPlan,
|
|
875
|
+
viewedActivity,
|
|
876
|
+
boundTurnActivities,
|
|
877
|
+
recordTurnActivity,
|
|
878
|
+
readTurnActivities,
|
|
879
|
+
runningTurnActivity,
|
|
880
|
+
activitiesBetween,
|
|
881
|
+
marksBetween,
|
|
882
|
+
stopOpenActivities,
|
|
883
|
+
textTranscript
|
|
884
|
+
};
|