tianshu-harness 3.23.0
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/LICENSE +189 -0
- package/README.en.md +1066 -0
- package/README.ja.md +1214 -0
- package/README.ko.md +1216 -0
- package/README.md +309 -0
- package/completions/rivet.bash +118 -0
- package/completions/rivet.fish +110 -0
- package/completions/rivet.ps1 +230 -0
- package/completions/rivet.zsh +187 -0
- package/dist/account-OAEKORZE.js +47 -0
- package/dist/account-login-V6FOLHJR.js +65 -0
- package/dist/account-status-KHNPPAFL.js +23 -0
- package/dist/agent/worker-process/child.js +407 -0
- package/dist/browser-cli-FLNY5ZHI.js +19 -0
- package/dist/browser-readiness-LWVGSBD5.js +12 -0
- package/dist/build-backends-5KXKR2S4.js +13 -0
- package/dist/build-options-66Y4ZE7C.js +9 -0
- package/dist/bundled-skills/brainstorming/SKILL.md +139 -0
- package/dist/bundled-skills/visual-acceptance/SKILL.md +64 -0
- package/dist/chain-7MAMFXZ3.js +10 -0
- package/dist/checkpoint-MND4DUIX.js +33 -0
- package/dist/chunk-2E6CK2RC.js +392 -0
- package/dist/chunk-2EBWGAXD.js +51 -0
- package/dist/chunk-2HDP7RMR.js +119 -0
- package/dist/chunk-2HKD2UFM.js +1000 -0
- package/dist/chunk-2VYRLULP.js +51 -0
- package/dist/chunk-2XN7PM4N.js +125 -0
- package/dist/chunk-35H7GVNR.js +66 -0
- package/dist/chunk-3C3R7JXY.js +77 -0
- package/dist/chunk-3VGD2FXB.js +118 -0
- package/dist/chunk-424AP7FM.js +534 -0
- package/dist/chunk-4J5TZGOE.js +3707 -0
- package/dist/chunk-4QJ3Y5JM.js +898 -0
- package/dist/chunk-4U2ET7ZY.js +1326 -0
- package/dist/chunk-4XPFLICE.js +876 -0
- package/dist/chunk-5B2OCU5P.js +31707 -0
- package/dist/chunk-5GGOGLSN.js +73 -0
- package/dist/chunk-5JRZPLI6.js +251 -0
- package/dist/chunk-5TQ3JYBU.js +397 -0
- package/dist/chunk-66JPZSGX.js +55 -0
- package/dist/chunk-6HSVXHCZ.js +764 -0
- package/dist/chunk-6S5FPUS7.js +21 -0
- package/dist/chunk-722LQO64.js +131 -0
- package/dist/chunk-73NJ7IT7.js +354 -0
- package/dist/chunk-7FW3I7WC.js +95 -0
- package/dist/chunk-7KUCBNLB.js +173 -0
- package/dist/chunk-7RDOV3DF.js +201 -0
- package/dist/chunk-A5MNH4ER.js +79 -0
- package/dist/chunk-ADIVZ2D5.js +15 -0
- package/dist/chunk-AE3P3F6W.js +366 -0
- package/dist/chunk-AERM3VGP.js +280 -0
- package/dist/chunk-AEWHC4WM.js +246 -0
- package/dist/chunk-AOVQ7VIF.js +169 -0
- package/dist/chunk-AOYHP3WI.js +12411 -0
- package/dist/chunk-B3YEBABJ.js +7160 -0
- package/dist/chunk-BCQXEZPJ.js +154 -0
- package/dist/chunk-BKTQAYO2.js +418 -0
- package/dist/chunk-BSECIPAQ.js +80 -0
- package/dist/chunk-BUIMGNDD.js +52 -0
- package/dist/chunk-BXHV3GSB.js +10320 -0
- package/dist/chunk-C6ZVZCPP.js +139 -0
- package/dist/chunk-CEZNQVWM.js +82 -0
- package/dist/chunk-CGFZGR7G.js +1492 -0
- package/dist/chunk-CGOADM2X.js +337 -0
- package/dist/chunk-CI4R6P2B.js +24 -0
- package/dist/chunk-D2TCGRSX.js +73 -0
- package/dist/chunk-D4PTYFOG.js +154 -0
- package/dist/chunk-D54ZWG4T.js +717 -0
- package/dist/chunk-DEBI37QB.js +145 -0
- package/dist/chunk-DWROHPXP.js +1051 -0
- package/dist/chunk-DZ6UOJ5D.js +92 -0
- package/dist/chunk-EBJTVRQN.js +81 -0
- package/dist/chunk-EGEI2RQA.js +1167 -0
- package/dist/chunk-EHHUASO5.js +1305 -0
- package/dist/chunk-EPKTIOED.js +41 -0
- package/dist/chunk-ER5JW2QZ.js +5681 -0
- package/dist/chunk-ETHFACAB.js +315 -0
- package/dist/chunk-EXUE5W2F.js +112 -0
- package/dist/chunk-EXXICUIW.js +73 -0
- package/dist/chunk-FFQSZJOO.js +169 -0
- package/dist/chunk-FHFKPGDO.js +85 -0
- package/dist/chunk-FW3QKMFX.js +158 -0
- package/dist/chunk-GD4ZNZ7W.js +30 -0
- package/dist/chunk-GHVMWF2I.js +581 -0
- package/dist/chunk-GMKAXSYQ.js +297 -0
- package/dist/chunk-HBVF6BWO.js +325 -0
- package/dist/chunk-HV4YGVMS.js +379 -0
- package/dist/chunk-ILBCKAV6.js +89 -0
- package/dist/chunk-J4U4AW46.js +440 -0
- package/dist/chunk-J6ESSM47.js +1791 -0
- package/dist/chunk-JBZHIC6T.js +2309 -0
- package/dist/chunk-JCFWOULR.js +245 -0
- package/dist/chunk-JRF5L6OD.js +131 -0
- package/dist/chunk-JSS75KCG.js +2014 -0
- package/dist/chunk-JSXWIWWJ.js +225 -0
- package/dist/chunk-JYV7I2QH.js +98 -0
- package/dist/chunk-KIOXTQQL.js +1596 -0
- package/dist/chunk-KWVTXT5B.js +89 -0
- package/dist/chunk-KX22RD6R.js +33 -0
- package/dist/chunk-LA6IPTGH.js +709 -0
- package/dist/chunk-LH5VCGLB.js +1796 -0
- package/dist/chunk-LQQ6XJ2Y.js +269 -0
- package/dist/chunk-MJQ55WZZ.js +65 -0
- package/dist/chunk-ML3UKMH3.js +40 -0
- package/dist/chunk-MOZPLHSU.js +5526 -0
- package/dist/chunk-NGEWJ4DF.js +89 -0
- package/dist/chunk-NH6VIOAR.js +211 -0
- package/dist/chunk-O5VZQKCB.js +26106 -0
- package/dist/chunk-OHSV42QB.js +748 -0
- package/dist/chunk-OO3TAHO5.js +4070 -0
- package/dist/chunk-OTNHSAGN.js +38282 -0
- package/dist/chunk-OUWAC7AQ.js +442 -0
- package/dist/chunk-OXMIV4WE.js +270 -0
- package/dist/chunk-P5KJURUR.js +229 -0
- package/dist/chunk-P6GJOVO6.js +307 -0
- package/dist/chunk-QARAGUXX.js +23 -0
- package/dist/chunk-R43HJCDX.js +2711 -0
- package/dist/chunk-RAXBAWRN.js +210 -0
- package/dist/chunk-RK3JHWPT.js +39 -0
- package/dist/chunk-RWA23GMM.js +24 -0
- package/dist/chunk-S4K4L6IM.js +179 -0
- package/dist/chunk-SAXK6LVF.js +124 -0
- package/dist/chunk-SEPGEJNK.js +1607 -0
- package/dist/chunk-SUJERP5I.js +285 -0
- package/dist/chunk-T3ED6BY2.js +913 -0
- package/dist/chunk-THKDVSEC.js +90 -0
- package/dist/chunk-TI4GSEL5.js +52 -0
- package/dist/chunk-TPI73L57.js +164 -0
- package/dist/chunk-TVHW77C7.js +338 -0
- package/dist/chunk-TWNHOSDT.js +1073 -0
- package/dist/chunk-UFMN76QD.js +347 -0
- package/dist/chunk-UHGLFRZE.js +205 -0
- package/dist/chunk-UTZYPKBF.js +15231 -0
- package/dist/chunk-UXNLELW6.js +25 -0
- package/dist/chunk-UXXS53EA.js +166 -0
- package/dist/chunk-V5DHFGI7.js +171 -0
- package/dist/chunk-V5YIPMHV.js +2353 -0
- package/dist/chunk-WMUWEO2C.js +754 -0
- package/dist/chunk-WOE3D7JM.js +945 -0
- package/dist/chunk-X2IK5LVR.js +2592 -0
- package/dist/chunk-XU2YXCDL.js +459 -0
- package/dist/chunk-YJG5HIX5.js +203 -0
- package/dist/chunk-Z3QE7TZM.js +72 -0
- package/dist/chunk-Z5Z3JHJY.js +64 -0
- package/dist/chunk-ZDIFBJFT.js +168 -0
- package/dist/chunk-ZGGCEXDC.js +176 -0
- package/dist/chunk-ZMZCZNKU.js +263 -0
- package/dist/chunk-ZNC5T65N.js +17 -0
- package/dist/chunk-ZO3I3A7O.js +308 -0
- package/dist/chunk-ZQKXBUB7.js +217 -0
- package/dist/chunk-ZTRINFM2.js +78 -0
- package/dist/chunk-ZU7JZCVP.js +193 -0
- package/dist/chunk-ZZAWNALS.js +350 -0
- package/dist/cli/entry.js +54 -0
- package/dist/connector-L5QQTR6Y.js +26 -0
- package/dist/context-62DC6EC3.js +31 -0
- package/dist/council-convene-NJWPNBDU.js +46 -0
- package/dist/create-agent-config-ODSQWNVC.js +55 -0
- package/dist/default-registry-2PU3BTAU.js +68 -0
- package/dist/deliver-task-KONV4C4M.js +57 -0
- package/dist/delivery-gate-v2-F2YVMVGK.js +27 -0
- package/dist/domain-knowledge-store-DDZ3F4J7.js +11 -0
- package/dist/fetch-core-ZPPYDSZH.js +14 -0
- package/dist/galaxy-K72BBDQN.js +91 -0
- package/dist/goal-criteria-SCALAU2D.js +141 -0
- package/dist/goal-persist-XWY2GDQX.js +19 -0
- package/dist/goal-tracker-FXMJ2GVK.js +11 -0
- package/dist/headless-LSB6I7PT.js +162 -0
- package/dist/headless-coordinator-VDPDMVUT.js +90 -0
- package/dist/inject-U55SMB6A.js +39 -0
- package/dist/login-flow-CD4ZGXOC.js +59 -0
- package/dist/logs-cli-SQVYFMMN.js +283 -0
- package/dist/loop-ULZYBDA3.js +76 -0
- package/dist/main.js +4064 -0
- package/dist/manager-ROZBCWPA.js +171 -0
- package/dist/manager-Z7XFFUOM.js +10670 -0
- package/dist/meridian-indexer-ZIW363L7.js +21 -0
- package/dist/native-resolver-PN34UIVV.js +13 -0
- package/dist/node_modules/better-sqlite3/lib/database.js +90 -0
- package/dist/node_modules/better-sqlite3/lib/index.js +3 -0
- package/dist/node_modules/better-sqlite3/lib/methods/aggregate.js +43 -0
- package/dist/node_modules/better-sqlite3/lib/methods/backup.js +67 -0
- package/dist/node_modules/better-sqlite3/lib/methods/function.js +31 -0
- package/dist/node_modules/better-sqlite3/lib/methods/inspect.js +7 -0
- package/dist/node_modules/better-sqlite3/lib/methods/pragma.js +12 -0
- package/dist/node_modules/better-sqlite3/lib/methods/serialize.js +16 -0
- package/dist/node_modules/better-sqlite3/lib/methods/table.js +189 -0
- package/dist/node_modules/better-sqlite3/lib/methods/transaction.js +78 -0
- package/dist/node_modules/better-sqlite3/lib/methods/wrappers.js +54 -0
- package/dist/node_modules/better-sqlite3/lib/sqlite-error.js +20 -0
- package/dist/node_modules/better-sqlite3/lib/util.js +12 -0
- package/dist/node_modules/better-sqlite3/package.json +59 -0
- package/dist/ownership-ledger-E3WIEKPL.js +9 -0
- package/dist/package.json +3 -0
- package/dist/path-grants-XRRXHXG7.js +40 -0
- package/dist/paths-LVV5IMQN.js +49 -0
- package/dist/plan-fact-anchors-LMVQZCW5.js +13 -0
- package/dist/plan-store-ODLTTPFB.js +17 -0
- package/dist/plan-templates-5FPFBOL6.js +109 -0
- package/dist/plugin-loader-ZZKX7ZE6.js +22 -0
- package/dist/prefix-budget-62OV5HQC.js +13 -0
- package/dist/project-trust-5WS5MOMU.js +31 -0
- package/dist/provider-cli-ALDQXIT7.js +37 -0
- package/dist/providers-XQYTAVPK.js +11 -0
- package/dist/proxy-resolver-V2Y6534D.js +15 -0
- package/dist/recovery-cli-KPGY6FY3.js +106 -0
- package/dist/review-discipline-MNSYCST5.js +55 -0
- package/dist/review-router-BVQZW3MX.js +18 -0
- package/dist/seed-capsules/seed-capsule-attack-methodology.md +62 -0
- package/dist/seed-capsules/seed-capsule-changgeng.md +31 -0
- package/dist/seed-capsules/seed-capsule-design-aesthetics.md +38 -0
- package/dist/seed-capsules/seed-capsule-diagnostic-ladder.md +54 -0
- package/dist/seed-capsules/seed-capsule-fu.md +39 -0
- package/dist/seed-capsules/seed-capsule-huagai.md +73 -0
- package/dist/seed-capsules/seed-capsule-kaiyang.md +65 -0
- package/dist/seed-capsules/seed-capsule-knowledge-work.md +40 -0
- package/dist/seed-capsules/seed-capsule-tanlang.md +47 -0
- package/dist/seed-capsules/seed-capsule-tianfu.md +23 -0
- package/dist/seed-capsules/seed-capsule-tianliang.md +63 -0
- package/dist/seed-capsules/seed-capsule-tianquan.md +32 -0
- package/dist/seed-capsules/seed-capsule-tianxuan-ccr.md +22 -0
- package/dist/seed-capsules/seed-capsule-tianxuan.md +64 -0
- package/dist/seed-capsules/seed-capsule-yaoguang.md +87 -0
- package/dist/serve-X2R2UTLF.js +170 -0
- package/dist/serve-agent-KHSU6RVV.js +965 -0
- package/dist/session-persist-HUUC772H.js +37 -0
- package/dist/session-registry-6XUD5C4Y.js +15 -0
- package/dist/skill-loader-CK3RMO47.js +48 -0
- package/dist/skills/cli-harness-sop.md +207 -0
- package/dist/spawn-git-4HFU65AH.js +29 -0
- package/dist/sse-EYUTBWUK.js +512 -0
- package/dist/starflow-NOFBMPFU.js +30 -0
- package/dist/streamableHttp-V67CNJMO.js +447 -0
- package/dist/task-contract-6XHBNJQK.js +32 -0
- package/dist/task-ledger-3K4TJIER.js +9 -0
- package/dist/team-orchestrate-S6NHZP7X.js +64 -0
- package/dist/title-extract-QX4XGCYN.js +50 -0
- package/dist/todo-QDXGRZZP.js +31 -0
- package/dist/todo-store-V3TTO5AH.js +12 -0
- package/dist/tool-preset-LU5BYEDZ.js +23 -0
- package/dist/tool-tiers-GD742YBN.js +23 -0
- package/dist/turndown.es-OI55K6C3.js +17373 -0
- package/dist/verification-attribution-EKG4CNUV.js +13 -0
- package/dist/volatile-git-MBTST7RA.js +15 -0
- package/dist/wave-checkpoint-XLIIHXQA.js +30 -0
- package/dist/web-cli-DUG4I35O.js +233 -0
- package/dist/web-search-3IK542AA.js +34 -0
- package/dist/workers/cpu-worker.js +45 -0
- package/dist/workflow-runner-HX7UBAYG.js +297 -0
- package/dist/worktree-baseline-O5NCU6M2.js +9 -0
- package/package.json +122 -0
- package/scripts/check-mobile-env.mjs +76 -0
- package/scripts/fetch-native-sqlite.js +392 -0
- package/scripts/prune-installed-wasms.js +45 -0
- package/scripts/tree-sitter-wasm-keep.js +40 -0
|
@@ -0,0 +1,965 @@
|
|
|
1
|
+
#!/usr/bin/env -S node --expose-gc --max-old-space-size=4096
|
|
2
|
+
import { createRequire as __rivetCreateRequire } from 'node:module'; const require = __rivetCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
buildDelegateSummary,
|
|
5
|
+
forgetSkillLoadErrors,
|
|
6
|
+
isModelSpecUsable,
|
|
7
|
+
partitionPluginTools,
|
|
8
|
+
pluginToolsSnapshot,
|
|
9
|
+
recordSkillLoadErrors,
|
|
10
|
+
resolveModelSpecWithReload,
|
|
11
|
+
resolveServeContext,
|
|
12
|
+
restoreHistoryMessages,
|
|
13
|
+
unconfiguredSpecMessage
|
|
14
|
+
} from "./chunk-UTZYPKBF.js";
|
|
15
|
+
import "./chunk-NGEWJ4DF.js";
|
|
16
|
+
import "./chunk-MJQ55WZZ.js";
|
|
17
|
+
import "./chunk-2EBWGAXD.js";
|
|
18
|
+
import "./chunk-ZZAWNALS.js";
|
|
19
|
+
import "./chunk-FHFKPGDO.js";
|
|
20
|
+
import "./chunk-LQQ6XJ2Y.js";
|
|
21
|
+
import {
|
|
22
|
+
buildCockpitSnapshot
|
|
23
|
+
} from "./chunk-FFQSZJOO.js";
|
|
24
|
+
import {
|
|
25
|
+
computeUsageCost,
|
|
26
|
+
findModelPricing
|
|
27
|
+
} from "./chunk-5B2OCU5P.js";
|
|
28
|
+
import "./chunk-ML3UKMH3.js";
|
|
29
|
+
import "./chunk-AEWHC4WM.js";
|
|
30
|
+
import "./chunk-OUWAC7AQ.js";
|
|
31
|
+
import "./chunk-66JPZSGX.js";
|
|
32
|
+
import {
|
|
33
|
+
FileHistory,
|
|
34
|
+
captureGitBaseline,
|
|
35
|
+
createAgentRuntime,
|
|
36
|
+
createFindReferencesTool,
|
|
37
|
+
createGotoDefinitionTool,
|
|
38
|
+
createInteractiveToolRegistry,
|
|
39
|
+
createMemoryTool,
|
|
40
|
+
createMultiLspManager,
|
|
41
|
+
loadProjectRules,
|
|
42
|
+
memoryBackfillEnabled,
|
|
43
|
+
resetLegacyMemoryIfNeeded,
|
|
44
|
+
runMemoryBackfill
|
|
45
|
+
} from "./chunk-AOYHP3WI.js";
|
|
46
|
+
import {
|
|
47
|
+
DEFAULT_COUNCIL_SEATS,
|
|
48
|
+
buildCouncilSessionEvent,
|
|
49
|
+
compileCouncilPlan,
|
|
50
|
+
persistCouncilRoutingShadow,
|
|
51
|
+
recordCouncilSession,
|
|
52
|
+
renderCouncilPlan,
|
|
53
|
+
runCouncil,
|
|
54
|
+
runCouncilDebate,
|
|
55
|
+
summarizeCouncilPlan
|
|
56
|
+
} from "./chunk-4U2ET7ZY.js";
|
|
57
|
+
import "./chunk-JBZHIC6T.js";
|
|
58
|
+
import {
|
|
59
|
+
attachObligations,
|
|
60
|
+
extractObligations
|
|
61
|
+
} from "./chunk-KWVTXT5B.js";
|
|
62
|
+
import {
|
|
63
|
+
createTaskLedger
|
|
64
|
+
} from "./chunk-2XN7PM4N.js";
|
|
65
|
+
import {
|
|
66
|
+
createOwnershipLedger
|
|
67
|
+
} from "./chunk-SAXK6LVF.js";
|
|
68
|
+
import {
|
|
69
|
+
createWorktreeBaseline
|
|
70
|
+
} from "./chunk-D2TCGRSX.js";
|
|
71
|
+
import "./chunk-73NJ7IT7.js";
|
|
72
|
+
import {
|
|
73
|
+
DomainKnowledgeStore
|
|
74
|
+
} from "./chunk-5TQ3JYBU.js";
|
|
75
|
+
import "./chunk-KX22RD6R.js";
|
|
76
|
+
import "./chunk-BXHV3GSB.js";
|
|
77
|
+
import "./chunk-FW3QKMFX.js";
|
|
78
|
+
import "./chunk-WOE3D7JM.js";
|
|
79
|
+
import "./chunk-B3YEBABJ.js";
|
|
80
|
+
import "./chunk-UXXS53EA.js";
|
|
81
|
+
import "./chunk-DWROHPXP.js";
|
|
82
|
+
import "./chunk-ZDIFBJFT.js";
|
|
83
|
+
import "./chunk-D54ZWG4T.js";
|
|
84
|
+
import {
|
|
85
|
+
sealPlan
|
|
86
|
+
} from "./chunk-R43HJCDX.js";
|
|
87
|
+
import "./chunk-D4PTYFOG.js";
|
|
88
|
+
import {
|
|
89
|
+
createDelegationActivityMapper
|
|
90
|
+
} from "./chunk-AERM3VGP.js";
|
|
91
|
+
import "./chunk-RK3JHWPT.js";
|
|
92
|
+
import "./chunk-NH6VIOAR.js";
|
|
93
|
+
import "./chunk-S4K4L6IM.js";
|
|
94
|
+
import "./chunk-3VGD2FXB.js";
|
|
95
|
+
import "./chunk-UXNLELW6.js";
|
|
96
|
+
import {
|
|
97
|
+
deserializeUnifiedPlan,
|
|
98
|
+
serializeUnifiedPlan
|
|
99
|
+
} from "./chunk-TVHW77C7.js";
|
|
100
|
+
import {
|
|
101
|
+
SessionContext
|
|
102
|
+
} from "./chunk-424AP7FM.js";
|
|
103
|
+
import "./chunk-JCFWOULR.js";
|
|
104
|
+
import "./chunk-2HKD2UFM.js";
|
|
105
|
+
import "./chunk-5JRZPLI6.js";
|
|
106
|
+
import "./chunk-JRF5L6OD.js";
|
|
107
|
+
import "./chunk-EBJTVRQN.js";
|
|
108
|
+
import "./chunk-J4U4AW46.js";
|
|
109
|
+
import "./chunk-2HDP7RMR.js";
|
|
110
|
+
import {
|
|
111
|
+
anchorsFromMessages,
|
|
112
|
+
runGateCompletion
|
|
113
|
+
} from "./chunk-OTNHSAGN.js";
|
|
114
|
+
import "./chunk-DZ6UOJ5D.js";
|
|
115
|
+
import "./chunk-T3ED6BY2.js";
|
|
116
|
+
import "./chunk-RAXBAWRN.js";
|
|
117
|
+
import {
|
|
118
|
+
scheduleMeridianBackfill
|
|
119
|
+
} from "./chunk-4J5TZGOE.js";
|
|
120
|
+
import "./chunk-BUIMGNDD.js";
|
|
121
|
+
import "./chunk-ZU7JZCVP.js";
|
|
122
|
+
import "./chunk-JSS75KCG.js";
|
|
123
|
+
import "./chunk-EHHUASO5.js";
|
|
124
|
+
import "./chunk-LA6IPTGH.js";
|
|
125
|
+
import "./chunk-HBVF6BWO.js";
|
|
126
|
+
import "./chunk-UHGLFRZE.js";
|
|
127
|
+
import "./chunk-4QJ3Y5JM.js";
|
|
128
|
+
import "./chunk-CGOADM2X.js";
|
|
129
|
+
import "./chunk-ZGGCEXDC.js";
|
|
130
|
+
import "./chunk-ZMZCZNKU.js";
|
|
131
|
+
import "./chunk-Z3QE7TZM.js";
|
|
132
|
+
import "./chunk-GHVMWF2I.js";
|
|
133
|
+
import {
|
|
134
|
+
MeridianIndexer
|
|
135
|
+
} from "./chunk-J6ESSM47.js";
|
|
136
|
+
import "./chunk-3C3R7JXY.js";
|
|
137
|
+
import {
|
|
138
|
+
restoreGoalTracker
|
|
139
|
+
} from "./chunk-TI4GSEL5.js";
|
|
140
|
+
import "./chunk-OXMIV4WE.js";
|
|
141
|
+
import "./chunk-4XPFLICE.js";
|
|
142
|
+
import "./chunk-V5YIPMHV.js";
|
|
143
|
+
import "./chunk-ILBCKAV6.js";
|
|
144
|
+
import "./chunk-X2IK5LVR.js";
|
|
145
|
+
import "./chunk-CEZNQVWM.js";
|
|
146
|
+
import "./chunk-O5VZQKCB.js";
|
|
147
|
+
import "./chunk-SEPGEJNK.js";
|
|
148
|
+
import "./chunk-7RDOV3DF.js";
|
|
149
|
+
import "./chunk-6HSVXHCZ.js";
|
|
150
|
+
import "./chunk-RWA23GMM.js";
|
|
151
|
+
import {
|
|
152
|
+
loadProjectSkills
|
|
153
|
+
} from "./chunk-OHSV42QB.js";
|
|
154
|
+
import "./chunk-ADIVZ2D5.js";
|
|
155
|
+
import "./chunk-7FW3I7WC.js";
|
|
156
|
+
import "./chunk-GD4ZNZ7W.js";
|
|
157
|
+
import "./chunk-ZQKXBUB7.js";
|
|
158
|
+
import "./chunk-Z5Z3JHJY.js";
|
|
159
|
+
import "./chunk-KIOXTQQL.js";
|
|
160
|
+
import "./chunk-35H7GVNR.js";
|
|
161
|
+
import "./chunk-AE3P3F6W.js";
|
|
162
|
+
import "./chunk-JSXWIWWJ.js";
|
|
163
|
+
import "./chunk-BSECIPAQ.js";
|
|
164
|
+
import "./chunk-2E6CK2RC.js";
|
|
165
|
+
import "./chunk-ZO3I3A7O.js";
|
|
166
|
+
import "./chunk-P6GJOVO6.js";
|
|
167
|
+
import "./chunk-TPI73L57.js";
|
|
168
|
+
import "./chunk-HV4YGVMS.js";
|
|
169
|
+
import "./chunk-722LQO64.js";
|
|
170
|
+
import "./chunk-GMKAXSYQ.js";
|
|
171
|
+
import "./chunk-EPKTIOED.js";
|
|
172
|
+
import "./chunk-2VYRLULP.js";
|
|
173
|
+
import {
|
|
174
|
+
applyConfiguredPathGrants,
|
|
175
|
+
applyDefaultDependencyReadGrants,
|
|
176
|
+
applyRivetRuntimeReadGrants,
|
|
177
|
+
loadPersistedGrants
|
|
178
|
+
} from "./chunk-SUJERP5I.js";
|
|
179
|
+
import "./chunk-CI4R6P2B.js";
|
|
180
|
+
import "./chunk-XU2YXCDL.js";
|
|
181
|
+
import "./chunk-ETHFACAB.js";
|
|
182
|
+
import "./chunk-THKDVSEC.js";
|
|
183
|
+
import "./chunk-UFMN76QD.js";
|
|
184
|
+
import "./chunk-EXUE5W2F.js";
|
|
185
|
+
import {
|
|
186
|
+
SessionPersist,
|
|
187
|
+
getSessionDir
|
|
188
|
+
} from "./chunk-LH5VCGLB.js";
|
|
189
|
+
import "./chunk-6S5FPUS7.js";
|
|
190
|
+
import "./chunk-EXXICUIW.js";
|
|
191
|
+
import "./chunk-QARAGUXX.js";
|
|
192
|
+
import {
|
|
193
|
+
TodoStore
|
|
194
|
+
} from "./chunk-DEBI37QB.js";
|
|
195
|
+
import "./chunk-YJG5HIX5.js";
|
|
196
|
+
import {
|
|
197
|
+
findProjectConfig,
|
|
198
|
+
proRegistry
|
|
199
|
+
} from "./chunk-ER5JW2QZ.js";
|
|
200
|
+
import "./chunk-CGFZGR7G.js";
|
|
201
|
+
import "./chunk-P5KJURUR.js";
|
|
202
|
+
import "./chunk-WMUWEO2C.js";
|
|
203
|
+
import "./chunk-BKTQAYO2.js";
|
|
204
|
+
import "./chunk-OO3TAHO5.js";
|
|
205
|
+
import "./chunk-EGEI2RQA.js";
|
|
206
|
+
import "./chunk-ZTRINFM2.js";
|
|
207
|
+
import "./chunk-ZNC5T65N.js";
|
|
208
|
+
import {
|
|
209
|
+
isProjectTrusted,
|
|
210
|
+
notifyUntrustedOnce
|
|
211
|
+
} from "./chunk-7KUCBNLB.js";
|
|
212
|
+
import "./chunk-A5MNH4ER.js";
|
|
213
|
+
import "./chunk-BCQXEZPJ.js";
|
|
214
|
+
import {
|
|
215
|
+
init_esm_shims
|
|
216
|
+
} from "./chunk-5GGOGLSN.js";
|
|
217
|
+
|
|
218
|
+
// src/server/serve-agent.ts
|
|
219
|
+
init_esm_shims();
|
|
220
|
+
import { join, dirname } from "path";
|
|
221
|
+
import { randomUUID } from "crypto";
|
|
222
|
+
import { readFileSync } from "fs";
|
|
223
|
+
var sparkReviewProfiles = {
|
|
224
|
+
reviewer: { provider: "deepseek-spark", model: "deepseek-v4-flash" },
|
|
225
|
+
verifier: { provider: "deepseek-spark", model: "deepseek-v4-flash" },
|
|
226
|
+
adversarial_verifier: { provider: "deepseek-spark", model: "deepseek-v4-flash" }
|
|
227
|
+
};
|
|
228
|
+
function getOrCreateDomainStore(shared, cwd) {
|
|
229
|
+
const existing = shared.domainStores.get(cwd);
|
|
230
|
+
if (existing) return existing;
|
|
231
|
+
const store = new DomainKnowledgeStore(join(cwd, ".rivet", "knowledge"));
|
|
232
|
+
shared.domainStores.set(cwd, store);
|
|
233
|
+
return store;
|
|
234
|
+
}
|
|
235
|
+
function getOrCreateMeridianIndexer(shared, cwd) {
|
|
236
|
+
const existing = shared.meridianIndexers.get(cwd);
|
|
237
|
+
if (existing) return existing;
|
|
238
|
+
const indexer = new MeridianIndexer(cwd);
|
|
239
|
+
try {
|
|
240
|
+
resetLegacyMemoryIfNeeded(cwd, {
|
|
241
|
+
clearMistakeEntries: () => indexer.getDb().clearMistakeEntries()
|
|
242
|
+
});
|
|
243
|
+
} catch {
|
|
244
|
+
}
|
|
245
|
+
shared.meridianIndexers.set(cwd, indexer);
|
|
246
|
+
setImmediate(() => {
|
|
247
|
+
scheduleMeridianBackfill(indexer, cwd, { reason: "startup" });
|
|
248
|
+
});
|
|
249
|
+
return indexer;
|
|
250
|
+
}
|
|
251
|
+
function getOrCreateLspEntry(shared, cwd) {
|
|
252
|
+
const existing = shared.lspManagers.get(cwd);
|
|
253
|
+
if (existing) return existing;
|
|
254
|
+
const manager = createMultiLspManager(cwd);
|
|
255
|
+
const ready = manager.initialize().then(() => manager.isReady()).catch(() => false);
|
|
256
|
+
const entry = { manager, ready };
|
|
257
|
+
shared.lspManagers.set(cwd, entry);
|
|
258
|
+
return entry;
|
|
259
|
+
}
|
|
260
|
+
function attachLspTools(entry, toolRegistry, refs, updateTools) {
|
|
261
|
+
return entry.ready.then((ok) => {
|
|
262
|
+
if (!ok) return;
|
|
263
|
+
toolRegistry.register(createGotoDefinitionTool(entry.manager));
|
|
264
|
+
toolRegistry.register(createFindReferencesTool(entry.manager));
|
|
265
|
+
refs.lspManager = entry.manager;
|
|
266
|
+
updateTools();
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
function disposeSharedCwdResources(shared) {
|
|
270
|
+
for (const indexer of shared.meridianIndexers.values()) {
|
|
271
|
+
try {
|
|
272
|
+
indexer.close();
|
|
273
|
+
} catch {
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
shared.meridianIndexers.clear();
|
|
277
|
+
for (const entry of shared.lspManagers.values()) {
|
|
278
|
+
try {
|
|
279
|
+
entry.manager.dispose();
|
|
280
|
+
} catch {
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
shared.lspManagers.clear();
|
|
284
|
+
}
|
|
285
|
+
var sessionStoresById = /* @__PURE__ */ new Map();
|
|
286
|
+
function resolveGoalHandles(sessionId, config) {
|
|
287
|
+
const entry = sessionStoresById.get(sessionId);
|
|
288
|
+
if (!entry) return void 0;
|
|
289
|
+
return {
|
|
290
|
+
goalTrackerRef: entry.stores.refs.goalTrackerRef,
|
|
291
|
+
sessionDir: getSessionDir(entry.cwd),
|
|
292
|
+
...config?.workers?.profiles?.cheap ? { cheapProfile: config.workers.profiles.cheap } : {},
|
|
293
|
+
...config?.provider?.providers ? { allProviders: config.provider.providers } : {}
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function forgetSessionStores(sessionId) {
|
|
297
|
+
sessionStoresById.delete(sessionId);
|
|
298
|
+
forgetSkillLoadErrors(sessionId);
|
|
299
|
+
}
|
|
300
|
+
function resolveReviewGateRef(sessionId) {
|
|
301
|
+
return sessionStoresById.get(sessionId)?.stores.refs.reviewGateRef;
|
|
302
|
+
}
|
|
303
|
+
function resolveReviewGate(ctx) {
|
|
304
|
+
const isSpark = ctx.provider.name === "deepseek-spark";
|
|
305
|
+
const flag = isSpark ? ctx.config.agent.review.skipAutoSpark : ctx.config.agent.review.skipAuto;
|
|
306
|
+
return flag ? "off" : "auto";
|
|
307
|
+
}
|
|
308
|
+
function buildSessionStores(ctx, cwd, sessionId, registry, shared) {
|
|
309
|
+
const persist = new SessionPersist(sessionId, cwd);
|
|
310
|
+
const claimStore = persist.createClaimStore();
|
|
311
|
+
persist.injectDurableClaims(claimStore, cwd);
|
|
312
|
+
for (const rule of loadProjectRules(cwd)) claimStore.propose(rule);
|
|
313
|
+
loadPersistedGrants(cwd);
|
|
314
|
+
applyConfiguredPathGrants(ctx.config.agent.permissions);
|
|
315
|
+
applyDefaultDependencyReadGrants();
|
|
316
|
+
applyRivetRuntimeReadGrants();
|
|
317
|
+
const skillLoad = loadProjectSkills(cwd, { importFromClaude: ctx.config.skills?.importFromClaude });
|
|
318
|
+
recordSkillLoadErrors(sessionId, skillLoad.errors);
|
|
319
|
+
const fileHistory = new FileHistory(persist.getBackupDir(), sessionId);
|
|
320
|
+
const session = new SessionContext();
|
|
321
|
+
const historyRestore = restoreHistoryMessages(persist, session, cwd);
|
|
322
|
+
const refs = {
|
|
323
|
+
coordinator: null,
|
|
324
|
+
fileHistory,
|
|
325
|
+
claimStore,
|
|
326
|
+
sessionId,
|
|
327
|
+
sessionRegistry: registry ?? null,
|
|
328
|
+
taskLedger: null,
|
|
329
|
+
ownershipLedger: null,
|
|
330
|
+
verificationSnapshotManager: null,
|
|
331
|
+
deliveryGate: null,
|
|
332
|
+
// Wave G: per-cwd 共享 Meridian——repo_graph/related_tests 惰性读 refs,
|
|
333
|
+
// 但在 createInteractiveToolRegistry 之前设值(代码清晰)。legacy /prompt
|
|
334
|
+
// 路径(无 shared)保持 null。
|
|
335
|
+
meridianIndexer: shared ? getOrCreateMeridianIndexer(shared, cwd) : null,
|
|
336
|
+
// 对称性回写:sidecar 无功能性消费者(服务器级 MCP 走 SharedRuntime),
|
|
337
|
+
// 但避免 refs 硬编码 null 造成读到假状态。
|
|
338
|
+
mcpManager: shared?.mcpManager ?? null,
|
|
339
|
+
// Wave G: LSP 是异步 init——assembleAgentLoop 在 entry.ready 后回写。
|
|
340
|
+
lspManager: null,
|
|
341
|
+
banditState: null,
|
|
342
|
+
promptEngine: null,
|
|
343
|
+
// Wave F: 通过 SharedRuntime → RuntimeSessionManager.sameCwdRunningCount
|
|
344
|
+
// 注入真实计数;shared 缺失或 manager 未就绪退化为 0(保持 TUI 兼容行为)。
|
|
345
|
+
getSameCwdRunningSessions: shared ? () => shared.sameCwdRunningCount?.(cwd, sessionId) ?? 0 : void 0,
|
|
346
|
+
goalTrackerRef: { current: null },
|
|
347
|
+
// 域知识库引用:buildAgentLoop 解析 store(SharedRuntime.domainStores 优先)
|
|
348
|
+
// 后回写——galaxy 路由学习经此存取。
|
|
349
|
+
domainKnowledgeStoreRef: { current: null },
|
|
350
|
+
obligationTrackerRef: { current: null },
|
|
351
|
+
// 会话级审查门开关:初始值取 review.skipAuto / skipAutoSpark 配置快照。
|
|
352
|
+
// spark provider 默认开(skipAutoSpark=false),标准 deepseek 默认关(skipAuto=true)。
|
|
353
|
+
// 用户可在桌面端 Settings 中独立控制两路。RIVET_REVIEW_DISCIPLINE=0 仍全局关闭。
|
|
354
|
+
reviewGateRef: { current: resolveReviewGate(ctx) },
|
|
355
|
+
// 插件 hooks/commands:sidecar 暂不加载插件(TUI bootstrap 专属装配链),
|
|
356
|
+
// 保持空数组与 RuntimeRefs 契约对齐——消费方按空集处理,不影响会话。
|
|
357
|
+
pluginHooks: [],
|
|
358
|
+
pluginCommands: [],
|
|
359
|
+
// 多会话隔离:每会话独立内存态 TodoStore,杜绝并发会话清单串台(提示词注入污染)。
|
|
360
|
+
// 不做磁盘持久化(按决策),展示与跨重启恢复靠事件日志重放。
|
|
361
|
+
todoStore: new TodoStore()
|
|
362
|
+
};
|
|
363
|
+
const sessionDir = getSessionDir(cwd);
|
|
364
|
+
try {
|
|
365
|
+
const restored = restoreGoalTracker(sessionDir, sessionId, { maxJudgeRuns: ctx.config.agent?.goal?.judge?.maxRuns });
|
|
366
|
+
if (restored) refs.goalTrackerRef.current = restored;
|
|
367
|
+
} catch {
|
|
368
|
+
}
|
|
369
|
+
const { registry: toolRegistry } = createInteractiveToolRegistry(refs, ctx.config, cwd);
|
|
370
|
+
const pluginSnap = pluginToolsSnapshot();
|
|
371
|
+
if (pluginSnap) {
|
|
372
|
+
const { accepted, blocked } = partitionPluginTools(pluginSnap.tools, new Set(toolRegistry.getAllNames()));
|
|
373
|
+
if (blocked.length > 0) {
|
|
374
|
+
console.warn(`[plugins] \u4EE5\u4E0B\u63D2\u4EF6\u5DE5\u5177\u4E0E\u5DF2\u88C5\u914D\u5DE5\u5177\u540C\u540D\uFF0C\u5DF2\u8DF3\u8FC7\uFF1A${blocked.join(", ")}`);
|
|
375
|
+
}
|
|
376
|
+
for (const tool of accepted) toolRegistry.register(tool);
|
|
377
|
+
for (const name of pluginSnap.suppressTools) toolRegistry.remove(name);
|
|
378
|
+
refs.pluginHooks = pluginSnap.hooks;
|
|
379
|
+
refs.pluginCommands = pluginSnap.commands;
|
|
380
|
+
}
|
|
381
|
+
if (ctx.provider.name === "deepseek-spark") {
|
|
382
|
+
const sparkConfig = ctx.config.agent.review;
|
|
383
|
+
for (const [profileName, entry] of Object.entries(sparkReviewProfiles)) {
|
|
384
|
+
if (!sparkConfig.profiles[profileName]) {
|
|
385
|
+
sparkConfig.profiles[profileName] = entry;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
const deepRecallAgentRef = {};
|
|
390
|
+
toolRegistry.register(createMemoryTool(claimStore, {
|
|
391
|
+
sessionId,
|
|
392
|
+
getTurn: () => session.getTurnCount(),
|
|
393
|
+
cwd,
|
|
394
|
+
deepRecallComplete: async (prompt, timeoutMs) => {
|
|
395
|
+
const client = deepRecallAgentRef.current?.config.compactClient ?? deepRecallAgentRef.current?.config.primaryClient ?? deepRecallAgentRef.current?.config.client;
|
|
396
|
+
if (!client) throw new Error("deep recall: no client");
|
|
397
|
+
return runGateCompletion(client, () => {
|
|
398
|
+
}, prompt, timeoutMs);
|
|
399
|
+
},
|
|
400
|
+
sessionDir,
|
|
401
|
+
excludeSessionId: sessionId
|
|
402
|
+
}));
|
|
403
|
+
const taskLedger = refs.taskLedger ?? createTaskLedger({ taskId: sessionId });
|
|
404
|
+
const ownershipLedger = refs.ownershipLedger ?? createOwnershipLedger({
|
|
405
|
+
baseline: createWorktreeBaseline(captureGitBaseline(cwd)),
|
|
406
|
+
taskLedger
|
|
407
|
+
});
|
|
408
|
+
const mcpMgr = shared?.mcpManager;
|
|
409
|
+
if (mcpMgr) {
|
|
410
|
+
const mcpTools = mcpMgr.getAllTools();
|
|
411
|
+
for (const tool of mcpTools) {
|
|
412
|
+
toolRegistry.register(tool);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return { persist, claimStore, fileHistory, toolRegistry, session, taskLedger, ownershipLedger, refs, historyRestore, deepRecallAgentRef };
|
|
416
|
+
}
|
|
417
|
+
function resolveSessionBaseConfig(ctx, reload) {
|
|
418
|
+
return reload ? reload().config : ctx.config;
|
|
419
|
+
}
|
|
420
|
+
function mergeProjectAgentConfig(startupConfig, cwd) {
|
|
421
|
+
try {
|
|
422
|
+
const projectPath = findProjectConfig(cwd);
|
|
423
|
+
if (!projectPath) return startupConfig;
|
|
424
|
+
if (!isProjectTrusted(dirname(projectPath))) {
|
|
425
|
+
notifyUntrustedOnce("config", dirname(projectPath));
|
|
426
|
+
return startupConfig;
|
|
427
|
+
}
|
|
428
|
+
const raw = JSON.parse(readFileSync(projectPath, "utf-8"));
|
|
429
|
+
const agent = raw?.agent;
|
|
430
|
+
if (!agent || typeof agent !== "object" || Array.isArray(agent)) return startupConfig;
|
|
431
|
+
const projectAgent = agent;
|
|
432
|
+
const projectTG = projectAgent.toolGating;
|
|
433
|
+
const projectToolGating = projectTG && typeof projectTG === "object" && !Array.isArray(projectTG) ? projectTG : void 0;
|
|
434
|
+
return {
|
|
435
|
+
...startupConfig,
|
|
436
|
+
agent: {
|
|
437
|
+
...startupConfig.agent,
|
|
438
|
+
...projectAgent,
|
|
439
|
+
...projectToolGating ? {
|
|
440
|
+
toolGating: {
|
|
441
|
+
...startupConfig.agent?.toolGating,
|
|
442
|
+
...projectToolGating
|
|
443
|
+
}
|
|
444
|
+
} : {}
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
} catch {
|
|
448
|
+
return startupConfig;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function assembleAgentLoop(ctx, cwd, sessionId, stores, spec, approvalMode, registry, shared, allowedTools, reload) {
|
|
452
|
+
const domainKnowledgeStore = shared ? getOrCreateDomainStore(shared, cwd) : new DomainKnowledgeStore(join(cwd, ".rivet", "knowledge"));
|
|
453
|
+
if (stores.refs.domainKnowledgeStoreRef) stores.refs.domainKnowledgeStoreRef.current = domainKnowledgeStore;
|
|
454
|
+
if (registry) stores.refs.sessionRegistry = registry;
|
|
455
|
+
const mergedConfig = mergeProjectAgentConfig(resolveSessionBaseConfig(ctx, reload), cwd);
|
|
456
|
+
const { agent } = createAgentRuntime({
|
|
457
|
+
provider: spec.provider,
|
|
458
|
+
apiKey: spec.apiKey,
|
|
459
|
+
auth: spec.auth,
|
|
460
|
+
config: mergedConfig,
|
|
461
|
+
sessionId,
|
|
462
|
+
cwd,
|
|
463
|
+
toolRegistry: stores.toolRegistry,
|
|
464
|
+
persist: stores.persist,
|
|
465
|
+
claimStore: stores.claimStore,
|
|
466
|
+
fileHistory: stores.fileHistory,
|
|
467
|
+
refs: stores.refs,
|
|
468
|
+
domainKnowledgeStore,
|
|
469
|
+
modelId: spec.model.id,
|
|
470
|
+
session: stores.session,
|
|
471
|
+
// Wave J: 跨 session 复用 ProviderHealthTracker,让 switchModel 不丢
|
|
472
|
+
// provider 健康累积;coordinator 冷层路由有正确依据。
|
|
473
|
+
sharedProviderHealth: shared?.providerHealth,
|
|
474
|
+
// I4: user hook results → desktop event stream via the session manager.
|
|
475
|
+
emitHookResult: (results, meta) => shared?.sessions?.emitHookResult(sessionId, results, meta),
|
|
476
|
+
// Per-session 工具白名单(蒸馏回放等自动化场景)。
|
|
477
|
+
allowedTools
|
|
478
|
+
});
|
|
479
|
+
stores.deepRecallAgentRef.current = agent;
|
|
480
|
+
if (memoryBackfillEnabled()) {
|
|
481
|
+
const backfillTimer = setTimeout(() => {
|
|
482
|
+
const client = agent.config.compactClient ?? agent.config.primaryClient ?? agent.config.client;
|
|
483
|
+
if (!client) return;
|
|
484
|
+
void runMemoryBackfill({
|
|
485
|
+
cwd,
|
|
486
|
+
sessionDir: getSessionDir(cwd),
|
|
487
|
+
currentSessionId: sessionId,
|
|
488
|
+
complete: (prompt, timeoutMs) => runGateCompletion(client, () => {
|
|
489
|
+
}, prompt, timeoutMs)
|
|
490
|
+
}).catch(() => {
|
|
491
|
+
});
|
|
492
|
+
}, 3e4);
|
|
493
|
+
backfillTimer.unref?.();
|
|
494
|
+
}
|
|
495
|
+
if (approvalMode) {
|
|
496
|
+
agent.setApprovalMode(approvalMode);
|
|
497
|
+
if (approvalMode === "dangerously-skip-permissions") {
|
|
498
|
+
agent.config.maxTurns = 0;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
stores.refs.getImpactedTests = () => [...agent.getEvidenceState().impactedTests];
|
|
502
|
+
if (shared) {
|
|
503
|
+
void attachLspTools(
|
|
504
|
+
getOrCreateLspEntry(shared, cwd),
|
|
505
|
+
stores.toolRegistry,
|
|
506
|
+
stores.refs,
|
|
507
|
+
() => agent.updateTools()
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
shared?.sessions?.setCoordinatorRef(sessionId, () => stores.refs.coordinator ?? void 0);
|
|
511
|
+
const priorMessages = stores.session.getMessages();
|
|
512
|
+
if (priorMessages.length > 0) {
|
|
513
|
+
const anchorExtractor = proRegistry.getAnchorExtractor(spec.provider.name);
|
|
514
|
+
if (anchorExtractor) {
|
|
515
|
+
const anchors = anchorsFromMessages(priorMessages, anchorExtractor, spec.model.id, agent.config.wireContext);
|
|
516
|
+
if (anchors.length > 0) agent.config.promptEngine.appendExcludedPathAnchors(anchors);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
const goalExtractor = proRegistry.getGoalExtractor(spec.provider.name);
|
|
520
|
+
if (goalExtractor) {
|
|
521
|
+
const frozen = stores.persist.loadMetadata()?.goalAnchor;
|
|
522
|
+
let goalFromHistory = null;
|
|
523
|
+
if (frozen) {
|
|
524
|
+
agent.config.promptEngine.setGoalAnchor(frozen);
|
|
525
|
+
} else if (priorMessages.length > 0) {
|
|
526
|
+
goalFromHistory = goalExtractor(priorMessages);
|
|
527
|
+
if (goalFromHistory) {
|
|
528
|
+
agent.config.promptEngine.setGoalAnchor(goalFromHistory);
|
|
529
|
+
try {
|
|
530
|
+
stores.persist.updateMetadata({ goalAnchor: goalFromHistory });
|
|
531
|
+
} catch {
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
const baseline = frozen ?? goalFromHistory;
|
|
536
|
+
stores.session.setGoalTracking(
|
|
537
|
+
(msgs) => goalExtractor(msgs),
|
|
538
|
+
(next) => {
|
|
539
|
+
agent.config.promptEngine.setGoalAnchor(next);
|
|
540
|
+
if (next !== null) {
|
|
541
|
+
try {
|
|
542
|
+
stores.persist.updateMetadata({ goalAnchor: next });
|
|
543
|
+
} catch {
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
baseline
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
return agent;
|
|
551
|
+
}
|
|
552
|
+
function specOfContext(ctx) {
|
|
553
|
+
return {
|
|
554
|
+
provider: ctx.provider,
|
|
555
|
+
apiKey: ctx.apiKey,
|
|
556
|
+
auth: ctx.auth,
|
|
557
|
+
model: { id: ctx.model.id, maxTokens: ctx.model.maxTokens, contextWindow: ctx.model.contextWindow, reasoningEffort: ctx.model.reasoningEffort, capabilities: ctx.model.capabilities }
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
function resolveInitialSpec(ctx, reload) {
|
|
561
|
+
if (reload) {
|
|
562
|
+
try {
|
|
563
|
+
const fresh = reload();
|
|
564
|
+
if (fresh.configured) return specOfContext(fresh);
|
|
565
|
+
} catch {
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (ctx.configured) return specOfContext(ctx);
|
|
569
|
+
return specOfContext(resolveServeContext());
|
|
570
|
+
}
|
|
571
|
+
function buildAgentLoop(ctx, cwd, sessionId = randomUUID(), registry, approvalMode, shared, reload) {
|
|
572
|
+
const stores = buildSessionStores(ctx, cwd, sessionId, registry, shared);
|
|
573
|
+
const spec = resolveInitialSpec(ctx, reload);
|
|
574
|
+
const agent = assembleAgentLoop(ctx, cwd, sessionId, stores, spec, approvalMode, registry, shared, void 0, reload);
|
|
575
|
+
return { agent, sessionId };
|
|
576
|
+
}
|
|
577
|
+
function buildManagedAgent(ctx, cwd, sessionId, registry, approvalMode, shared, reload, preferredModelId, allowedTools) {
|
|
578
|
+
const stores = buildSessionStores(ctx, cwd, sessionId, registry, shared);
|
|
579
|
+
sessionStoresById.set(sessionId, { stores, cwd });
|
|
580
|
+
let spec = (preferredModelId ? reload ? resolveModelSpecWithReload(ctx, preferredModelId, reload) : resolveModelSpecWithReload(ctx, preferredModelId) : null) ?? resolveInitialSpec(ctx, reload);
|
|
581
|
+
let agent = assembleAgentLoop(ctx, cwd, sessionId, stores, spec, approvalMode, registry, shared, allowedTools, reload);
|
|
582
|
+
const rebuildOnSpec = (next) => {
|
|
583
|
+
const oldCoordinator = stores.refs.coordinator;
|
|
584
|
+
const oldAgent = agent;
|
|
585
|
+
void oldAgent.cancelIdleCompaction();
|
|
586
|
+
spec = next;
|
|
587
|
+
const liveApprovalMode = oldAgent.config.approvalMode;
|
|
588
|
+
agent = assembleAgentLoop(ctx, cwd, sessionId, stores, spec, liveApprovalMode, registry, shared, allowedTools, reload);
|
|
589
|
+
if (oldCoordinator && oldCoordinator !== stores.refs.coordinator) {
|
|
590
|
+
try {
|
|
591
|
+
oldCoordinator.shutdown();
|
|
592
|
+
} catch {
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return oldAgent;
|
|
596
|
+
};
|
|
597
|
+
return {
|
|
598
|
+
run: (prompt, callbacks, images) => {
|
|
599
|
+
if (!isModelSpecUsable(spec)) {
|
|
600
|
+
const healed = reload ? resolveModelSpecWithReload(ctx, spec.model.id, reload) : null;
|
|
601
|
+
if (healed && isModelSpecUsable(healed)) {
|
|
602
|
+
rebuildOnSpec(healed);
|
|
603
|
+
} else {
|
|
604
|
+
return Promise.reject(new Error(unconfiguredSpecMessage(spec)));
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
return agent.run(prompt, callbacks, images);
|
|
608
|
+
},
|
|
609
|
+
abort: () => agent.abort(),
|
|
610
|
+
setApprovalMode: (mode) => {
|
|
611
|
+
agent.setApprovalMode(mode);
|
|
612
|
+
agent.config.maxTurns = mode === "dangerously-skip-permissions" ? 0 : 200;
|
|
613
|
+
},
|
|
614
|
+
enterPlanMode: () => agent.enterPlanMode(),
|
|
615
|
+
exitPlanMode: () => agent.exitPlanMode(),
|
|
616
|
+
setActivePlan: (plan) => agent.setActivePlan(plan),
|
|
617
|
+
listArtifacts: () => agent.artifactStore?.list() ?? [],
|
|
618
|
+
readArtifact: (artifactId) => agent.artifactStore?.readRaw(artifactId) ?? Promise.resolve(null),
|
|
619
|
+
getMessages: () => agent.session.getMessages(),
|
|
620
|
+
getHistoryRestore: () => stores.historyRestore,
|
|
621
|
+
replaceMessages: (msgs) => {
|
|
622
|
+
agent.session.replaceMessages(msgs);
|
|
623
|
+
agent.config.promptEngine.resetAppendixBaseline();
|
|
624
|
+
},
|
|
625
|
+
rewindToMessages: (msgs) => {
|
|
626
|
+
agent.session.rewindToMessages(msgs);
|
|
627
|
+
agent.config.promptEngine.resetAppendixBaseline();
|
|
628
|
+
},
|
|
629
|
+
getFileHistory: () => agent.getFileHistory(),
|
|
630
|
+
// PlusMenu — star domain (delegate to the live agent).
|
|
631
|
+
setSessionDomain: (domain) => agent.setSessionDomain(domain),
|
|
632
|
+
resetSessionDomain: () => agent.resetSessionDomain(),
|
|
633
|
+
restoreAutoResolvedDomain: (domain) => agent.restoreAutoResolvedDomain(domain),
|
|
634
|
+
getSessionDomain: () => agent.getSessionDomain(),
|
|
635
|
+
// PlusMenu — skills (per-session discovery filter on the live agent).
|
|
636
|
+
setDisabledSkills: (names) => agent.setDisabledSkills(names),
|
|
637
|
+
// PlusMenu — model hot-switch (rebuild on the same SessionContext).
|
|
638
|
+
// Wave C-followup P0: createAgentRuntime 在 refs 上原地装新 coordinator/
|
|
639
|
+
// providerHealth/runtimeFactory,但旧 coordinator 的 stallSweep 定时器与
|
|
640
|
+
// 在途 worker AbortController 仍持有句柄。sidecar 长驻进程 + 频繁
|
|
641
|
+
// switchModel 会累积泄漏。先 capture old,装新后调 shutdown 释放。
|
|
642
|
+
// Wave J: 透传 shared 让 switchModel 后仍复用 providerHealth/domainStore,
|
|
643
|
+
// 健康数据不丢、knowledge 不重 load。
|
|
644
|
+
switchModel: (modelId) => {
|
|
645
|
+
const next = resolveModelSpecWithReload(ctx, modelId);
|
|
646
|
+
if (!next) return null;
|
|
647
|
+
const oldAgent = rebuildOnSpec(next);
|
|
648
|
+
let fromModel;
|
|
649
|
+
try {
|
|
650
|
+
fromModel = oldAgent.config.promptEngine.getModel();
|
|
651
|
+
} catch {
|
|
652
|
+
}
|
|
653
|
+
const modelRef = spec.keyId ? `${spec.provider.name}:${spec.keyId}:${spec.model.id}` : `${spec.provider.name}:${spec.model.id}`;
|
|
654
|
+
try {
|
|
655
|
+
stores.persist.updateMetadata({ model: spec.model.id, provider: spec.provider.name });
|
|
656
|
+
stores.persist.appendModelSwitch({ from: fromModel, to: spec.model.id, provider: spec.provider.name });
|
|
657
|
+
} catch {
|
|
658
|
+
}
|
|
659
|
+
return modelRef;
|
|
660
|
+
},
|
|
661
|
+
// Context usage display (desktop header progress bar) — real occupancy
|
|
662
|
+
// (last API prompt_tokens + tail estimate), provider-agnostic.
|
|
663
|
+
getEstimatedTokens: () => agent.session.getRealOccupancy(),
|
|
664
|
+
getContextWindow: () => spec.model.contextWindow,
|
|
665
|
+
getReasoningEffort: () => agent.getReasoningEffort(),
|
|
666
|
+
// 识图桥真实状态(供桌面端准确显示,而非只看 config 有没有 visionModel 键)。
|
|
667
|
+
// 依赖当前会话模型,故取活 agent 的 config 而非静态 config。
|
|
668
|
+
getVisionBridge: () => agent.config.visionBridge,
|
|
669
|
+
// Cockpit snapshot for the desktop cockpit panel. Assembles the full
|
|
670
|
+
// runtime state (safety/verify/context/model/advisory) via the pure
|
|
671
|
+
// buildCockpitSnapshot function — same source the TUI uses (main.ts:706).
|
|
672
|
+
// try/catch: the agent may be mid-rebuild (switchModel) — degrade to null
|
|
673
|
+
// instead of 500'ing the cockpit poll.
|
|
674
|
+
getCockpitSnapshot: () => {
|
|
675
|
+
try {
|
|
676
|
+
const usage = agent.session.getTotalUsage();
|
|
677
|
+
const pricing = findModelPricing(ctx.config.provider?.providers, spec.provider.name, spec.model.id);
|
|
678
|
+
const cost = computeUsageCost(usage, pricing).total;
|
|
679
|
+
return buildCockpitSnapshot({
|
|
680
|
+
agent,
|
|
681
|
+
session: agent.session,
|
|
682
|
+
model: spec.model.id,
|
|
683
|
+
cacheHitRate: agent.session.getRecentTurnHitRate(3) ?? agent.session.getCacheHitRate(),
|
|
684
|
+
cost,
|
|
685
|
+
mcpManager: shared?.mcpManager ?? null,
|
|
686
|
+
reasoningEffort: agent.getReasoningEffort()
|
|
687
|
+
// claimCounts / advisoryStatusNotices omitted — safe degradation
|
|
688
|
+
// (claimCounts defaults to zero counts, statusNotices to []).
|
|
689
|
+
});
|
|
690
|
+
} catch {
|
|
691
|
+
return null;
|
|
692
|
+
}
|
|
693
|
+
},
|
|
694
|
+
// Wave L: 进程退出释放本 session 的 coordinator timer + in-flight worker
|
|
695
|
+
// 句柄。abort() 仅中止当前 turn;shutdown() 是终结性操作。
|
|
696
|
+
shutdown: async () => {
|
|
697
|
+
try {
|
|
698
|
+
agent.stopConfigWatcher();
|
|
699
|
+
} catch {
|
|
700
|
+
}
|
|
701
|
+
try {
|
|
702
|
+
void agent.cancelIdleCompaction();
|
|
703
|
+
} catch {
|
|
704
|
+
}
|
|
705
|
+
try {
|
|
706
|
+
await agent.drainPostSession(5e3);
|
|
707
|
+
} catch {
|
|
708
|
+
}
|
|
709
|
+
try {
|
|
710
|
+
await stores.claimStore.flushWrites(2e3);
|
|
711
|
+
} catch {
|
|
712
|
+
}
|
|
713
|
+
const coordinator = stores.refs.coordinator;
|
|
714
|
+
let settled = !coordinator;
|
|
715
|
+
try {
|
|
716
|
+
if (coordinator?.shutdownAndWait) settled = await coordinator.shutdownAndWait();
|
|
717
|
+
else if (coordinator) {
|
|
718
|
+
coordinator.shutdown();
|
|
719
|
+
settled = false;
|
|
720
|
+
}
|
|
721
|
+
} catch {
|
|
722
|
+
settled = false;
|
|
723
|
+
}
|
|
724
|
+
shared?.sessions?.clearCoordinatorRef(sessionId);
|
|
725
|
+
return settled;
|
|
726
|
+
},
|
|
727
|
+
// I1: 桌面端议事会入口,直接评审 artifact 中的 council-plan-json。
|
|
728
|
+
conveneCouncil: (input) => conveneCouncilOnCoordinator(agent, stores.refs.coordinator, stores.refs, input),
|
|
729
|
+
// 用户主动派后台子代理:独立 AbortSignal,跑在隔离子会话,不碰主历史。
|
|
730
|
+
delegateWorker: (input, opts) => delegateWorkerOnCoordinator(stores.refs.coordinator, input, opts),
|
|
731
|
+
// P0-2: plan_task 成功后 onToolResult 通过此方法读取 TodoStore 发 todo_state SSE
|
|
732
|
+
getTodos: () => stores.refs.todoStore.read(),
|
|
733
|
+
// Hot-inject MCP tools discovered after this agent was built (mid-session
|
|
734
|
+
// connector enable). register is Map.set-idempotent; updateTools refreshes
|
|
735
|
+
// the prompt tool list the same way attachLspTools does for LSP tools.
|
|
736
|
+
registerExternalTools: (tools) => {
|
|
737
|
+
for (const tool of tools) {
|
|
738
|
+
stores.toolRegistry.register(tool);
|
|
739
|
+
}
|
|
740
|
+
agent.updateTools();
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
var CouncilError = class extends Error {
|
|
745
|
+
constructor(message, statusCode) {
|
|
746
|
+
super(message);
|
|
747
|
+
this.statusCode = statusCode;
|
|
748
|
+
this.name = "CouncilError";
|
|
749
|
+
}
|
|
750
|
+
statusCode;
|
|
751
|
+
};
|
|
752
|
+
async function conveneCouncilOnCoordinator(agent, coordinator, refs, input) {
|
|
753
|
+
if (agent.isRunning()) {
|
|
754
|
+
throw new CouncilError("Session is already running a turn", 409);
|
|
755
|
+
}
|
|
756
|
+
if (!coordinator) {
|
|
757
|
+
throw new Error("DelegationCoordinator not initialized");
|
|
758
|
+
}
|
|
759
|
+
const raw = await agent.artifactStore?.readRaw(input.artifactId);
|
|
760
|
+
if (!raw) {
|
|
761
|
+
throw new CouncilError("Artifact not found", 404);
|
|
762
|
+
}
|
|
763
|
+
const planJson = extractCouncilPlanJson(raw);
|
|
764
|
+
if (!planJson) {
|
|
765
|
+
throw new CouncilError("Artifact does not contain a valid council-plan-json block", 400);
|
|
766
|
+
}
|
|
767
|
+
const draftItems = planJson.tasks.map((t) => ({
|
|
768
|
+
id: t.id,
|
|
769
|
+
title: t.title,
|
|
770
|
+
detail: t.objective,
|
|
771
|
+
files: t.files
|
|
772
|
+
}));
|
|
773
|
+
const seats = input.seats && input.seats.length > 0 ? input.seats.map((s) => ({ authority: s.authority, ...s.charter ? { charter: s.charter } : {} })) : [...DEFAULT_COUNCIL_SEATS];
|
|
774
|
+
const abortController = new AbortController();
|
|
775
|
+
const councilInput = {
|
|
776
|
+
draft: { objective: input.objective ?? planJson.objective, items: draftItems },
|
|
777
|
+
seats,
|
|
778
|
+
abortSignal: abortController.signal,
|
|
779
|
+
...typeof input.rounds === "number" ? { maxRounds: input.rounds } : {}
|
|
780
|
+
};
|
|
781
|
+
const now = Date.now();
|
|
782
|
+
const deps = {
|
|
783
|
+
delegateBatch: async (requests, policy, signal, onProgress) => {
|
|
784
|
+
const delegationReqs = requests.map((r) => ({
|
|
785
|
+
parentTurnId: r.parentTurnId,
|
|
786
|
+
objective: r.objective,
|
|
787
|
+
kind: r.kind,
|
|
788
|
+
profile: r.profile,
|
|
789
|
+
scope: r.scope,
|
|
790
|
+
// 席位路由字段透传:曾在此处丢弃,桌面路由的异构席/瑶光门失效。
|
|
791
|
+
authority: r.authority,
|
|
792
|
+
...r.modelOverride ? { modelOverride: r.modelOverride } : {},
|
|
793
|
+
...r.tierFloor ? { tierFloor: r.tierFloor } : {}
|
|
794
|
+
}));
|
|
795
|
+
const run = await coordinator.delegateBatch(
|
|
796
|
+
delegationReqs,
|
|
797
|
+
policy,
|
|
798
|
+
signal,
|
|
799
|
+
onProgress
|
|
800
|
+
);
|
|
801
|
+
return { results: run.results, workerModels: run.workerModels };
|
|
802
|
+
},
|
|
803
|
+
now: () => now,
|
|
804
|
+
sessionId: refs.sessionId ?? "unknown",
|
|
805
|
+
recordRoutingShadow: (event) => persistCouncilRoutingShadow(refs.meridianIndexer?.getDb(), event)
|
|
806
|
+
};
|
|
807
|
+
const runner = councilInput.maxRounds && councilInput.maxRounds >= 2 ? runCouncilDebate : runCouncil;
|
|
808
|
+
const plan = await runner(councilInput, deps);
|
|
809
|
+
const planMarkdown = renderCouncilPlan(plan);
|
|
810
|
+
const compiled = plan.aggregate.mergedItems.length > 0 ? compileCouncilPlan(plan) : void 0;
|
|
811
|
+
const sealed = compiled?.ok && compiled.plan ? sealPlan(attachObligations(compiled.plan, extractObligations(plan))) : void 0;
|
|
812
|
+
const outputRaw = sealed ? [planMarkdown, "", "```council-plan-json", serializeUnifiedPlan(sealed), "```"].join("\n") : compiled && !compiled.ok ? [planMarkdown, "", "## \u26D4 \u8BAE\u4E8B\u4F1A\u5426\u51B3\uFF08blocking challenge \u672A\u5316\u89E3\uFF09", ...compiled.vetoes.map((v) => `- ${v.description}: ${v.left}`)].join("\n") : planMarkdown;
|
|
813
|
+
const savedArtifactId = await agent.artifactStore?.save({
|
|
814
|
+
tool: "council_convene",
|
|
815
|
+
target: `council:${plan.meta.objectiveHash}`,
|
|
816
|
+
rawContent: outputRaw,
|
|
817
|
+
summary: summarizeCouncilPlan(plan),
|
|
818
|
+
sections: []
|
|
819
|
+
});
|
|
820
|
+
try {
|
|
821
|
+
recordCouncilSession(refs.meridianIndexer?.getDb(), buildCouncilSessionEvent({
|
|
822
|
+
sessionId: refs.sessionId ?? "unknown",
|
|
823
|
+
plan,
|
|
824
|
+
timestamp: Date.now()
|
|
825
|
+
}));
|
|
826
|
+
} catch {
|
|
827
|
+
}
|
|
828
|
+
if (!savedArtifactId) {
|
|
829
|
+
throw new Error("Failed to save council plan artifact");
|
|
830
|
+
}
|
|
831
|
+
const councilPanel = {
|
|
832
|
+
schemaVersion: 1,
|
|
833
|
+
objective: plan.objective,
|
|
834
|
+
seats: plan.contributions.map((c) => ({
|
|
835
|
+
authority: c.authority,
|
|
836
|
+
status: "passed",
|
|
837
|
+
round: c.round ?? 1,
|
|
838
|
+
modelUsed: c.modelUsed
|
|
839
|
+
})),
|
|
840
|
+
verdict: {
|
|
841
|
+
accepted: plan.aggregate.decisions.filter((d) => d.verdict === "accepted").length,
|
|
842
|
+
rejected: plan.aggregate.decisions.filter((d) => d.verdict === "rejected").length,
|
|
843
|
+
deferred: plan.aggregate.decisions.filter((d) => d.verdict === "deferred").length,
|
|
844
|
+
conflicts: plan.aggregate.conflicts.length
|
|
845
|
+
},
|
|
846
|
+
sealVersion: sealed?.seal?.version,
|
|
847
|
+
pillarsMode: false,
|
|
848
|
+
failedSeats: plan.meta.failedSeats,
|
|
849
|
+
qliphothCount: plan.meta.qliphoth?.length
|
|
850
|
+
};
|
|
851
|
+
return { planMarkdown, artifactId: savedArtifactId, councilPanel };
|
|
852
|
+
}
|
|
853
|
+
function extractCouncilPlanJson(raw) {
|
|
854
|
+
const match = raw.match(/```council-plan-json\n([\s\S]*?)\n```/);
|
|
855
|
+
if (!match) return null;
|
|
856
|
+
return deserializeUnifiedPlan(match[1]);
|
|
857
|
+
}
|
|
858
|
+
function kindForProfile(profile) {
|
|
859
|
+
switch (profile) {
|
|
860
|
+
case "patcher":
|
|
861
|
+
return "patch_proposal";
|
|
862
|
+
case "reviewer":
|
|
863
|
+
return "review";
|
|
864
|
+
case "verifier":
|
|
865
|
+
case "adversarial_verifier":
|
|
866
|
+
return "verify";
|
|
867
|
+
case "planner":
|
|
868
|
+
case "perspective_planner":
|
|
869
|
+
return "plan";
|
|
870
|
+
case "doc_scout":
|
|
871
|
+
return "doc_research";
|
|
872
|
+
default:
|
|
873
|
+
return "code_search";
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
async function delegateWorkerOnCoordinator(coordinator, input, opts) {
|
|
877
|
+
if (!coordinator) throw new Error("DelegationCoordinator not initialized");
|
|
878
|
+
const profile = input.profile && input.profile.trim() ? input.profile.trim() : "code_scout";
|
|
879
|
+
const activityMapper = createDelegationActivityMapper(opts.workerId, (a) => {
|
|
880
|
+
opts.onActivity({
|
|
881
|
+
workOrderId: opts.workerId,
|
|
882
|
+
parentToolId: a.parentToolId,
|
|
883
|
+
...a.dispatchId ? { dispatchId: a.dispatchId } : {},
|
|
884
|
+
...a.attemptId ? { attemptId: a.attemptId } : {},
|
|
885
|
+
...a.parentAttemptId ? { parentAttemptId: a.parentAttemptId } : {},
|
|
886
|
+
profile: a.profile ?? profile,
|
|
887
|
+
authority: a.authority,
|
|
888
|
+
status: a.status,
|
|
889
|
+
progressLine: a.progressLine,
|
|
890
|
+
toolUseCount: a.toolUseCount,
|
|
891
|
+
tokenCount: a.tokenCount,
|
|
892
|
+
eventKind: a.eventKind,
|
|
893
|
+
eventDetail: a.eventDetail,
|
|
894
|
+
contract: a.contract
|
|
895
|
+
});
|
|
896
|
+
});
|
|
897
|
+
const request = {
|
|
898
|
+
// Use the manager-owned workerId as the stable node key (parentTurnId derives
|
|
899
|
+
// the work order id), so every activity update merges into the same panel node.
|
|
900
|
+
parentTurnId: opts.workerId,
|
|
901
|
+
objective: input.objective,
|
|
902
|
+
kind: kindForProfile(profile),
|
|
903
|
+
profile,
|
|
904
|
+
scope: input.files && input.files.length ? { files: input.files } : {},
|
|
905
|
+
delegationDepth: 0,
|
|
906
|
+
// Reuse the shared mapper so user-dispatched workers get the same live
|
|
907
|
+
// counters (toolUseCount/tokenCount) and eventKind/eventDetail passthrough
|
|
908
|
+
// as agent-initiated delegations.
|
|
909
|
+
onActivity: activityMapper
|
|
910
|
+
};
|
|
911
|
+
if (input.authority) request.authority = input.authority;
|
|
912
|
+
if (input.resume) request.resumeWorkOrderId = input.resume;
|
|
913
|
+
try {
|
|
914
|
+
const run = await coordinator.delegate(request, opts.signal);
|
|
915
|
+
const result = run.results[0];
|
|
916
|
+
if (result) {
|
|
917
|
+
const identity = result;
|
|
918
|
+
const terminal = {
|
|
919
|
+
workOrderId: result.workOrderId,
|
|
920
|
+
parentToolId: opts.workerId,
|
|
921
|
+
...identity.dispatchId ? { dispatchId: identity.dispatchId } : {},
|
|
922
|
+
...identity.attemptId ? { attemptId: identity.attemptId } : {},
|
|
923
|
+
...identity.parentAttemptId ? { parentAttemptId: identity.parentAttemptId } : {},
|
|
924
|
+
profile,
|
|
925
|
+
status: result.status === "passed" ? "completed" : result.status,
|
|
926
|
+
progressLine: result.summary ? result.summary.slice(0, 120) : void 0,
|
|
927
|
+
failureReason: result.failureReason,
|
|
928
|
+
summary: buildDelegateSummary(input, run),
|
|
929
|
+
changedFiles: result.changedFiles.length > 0 ? result.changedFiles : void 0,
|
|
930
|
+
artifactId: result.diffArtifactId,
|
|
931
|
+
model: run.selectedModel ?? result.model,
|
|
932
|
+
provider: result.provider,
|
|
933
|
+
usage: result.usage,
|
|
934
|
+
// 终态证据摘要(与 delegate_task 的 emitTerminal 对齐)。
|
|
935
|
+
findingsCount: result.findings.length > 0 ? result.findings.length : void 0,
|
|
936
|
+
topFinding: result.findings[0]?.claim,
|
|
937
|
+
verificationBrief: result.verification ? { status: result.verification.status, passed: result.verification.passed, failed: result.verification.failed } : void 0,
|
|
938
|
+
evidenceStatus: result.evidenceStatus
|
|
939
|
+
};
|
|
940
|
+
activityMapper.finish(terminal);
|
|
941
|
+
} else {
|
|
942
|
+
activityMapper.finish({
|
|
943
|
+
workOrderId: opts.workerId,
|
|
944
|
+
parentToolId: opts.workerId,
|
|
945
|
+
profile,
|
|
946
|
+
status: run.status === "skipped" ? "blocked" : "completed",
|
|
947
|
+
summary: buildDelegateSummary(input, run)
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
} finally {
|
|
951
|
+
activityMapper.dispose();
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
export {
|
|
955
|
+
attachLspTools,
|
|
956
|
+
buildAgentLoop,
|
|
957
|
+
buildManagedAgent,
|
|
958
|
+
disposeSharedCwdResources,
|
|
959
|
+
forgetSessionStores,
|
|
960
|
+
getOrCreateMeridianIndexer,
|
|
961
|
+
mergeProjectAgentConfig,
|
|
962
|
+
resolveGoalHandles,
|
|
963
|
+
resolveReviewGateRef,
|
|
964
|
+
resolveSessionBaseConfig
|
|
965
|
+
};
|