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.
Files changed (255) hide show
  1. package/LICENSE +189 -0
  2. package/README.en.md +1066 -0
  3. package/README.ja.md +1214 -0
  4. package/README.ko.md +1216 -0
  5. package/README.md +309 -0
  6. package/completions/rivet.bash +118 -0
  7. package/completions/rivet.fish +110 -0
  8. package/completions/rivet.ps1 +230 -0
  9. package/completions/rivet.zsh +187 -0
  10. package/dist/account-OAEKORZE.js +47 -0
  11. package/dist/account-login-V6FOLHJR.js +65 -0
  12. package/dist/account-status-KHNPPAFL.js +23 -0
  13. package/dist/agent/worker-process/child.js +407 -0
  14. package/dist/browser-cli-FLNY5ZHI.js +19 -0
  15. package/dist/browser-readiness-LWVGSBD5.js +12 -0
  16. package/dist/build-backends-5KXKR2S4.js +13 -0
  17. package/dist/build-options-66Y4ZE7C.js +9 -0
  18. package/dist/bundled-skills/brainstorming/SKILL.md +139 -0
  19. package/dist/bundled-skills/visual-acceptance/SKILL.md +64 -0
  20. package/dist/chain-7MAMFXZ3.js +10 -0
  21. package/dist/checkpoint-MND4DUIX.js +33 -0
  22. package/dist/chunk-2E6CK2RC.js +392 -0
  23. package/dist/chunk-2EBWGAXD.js +51 -0
  24. package/dist/chunk-2HDP7RMR.js +119 -0
  25. package/dist/chunk-2HKD2UFM.js +1000 -0
  26. package/dist/chunk-2VYRLULP.js +51 -0
  27. package/dist/chunk-2XN7PM4N.js +125 -0
  28. package/dist/chunk-35H7GVNR.js +66 -0
  29. package/dist/chunk-3C3R7JXY.js +77 -0
  30. package/dist/chunk-3VGD2FXB.js +118 -0
  31. package/dist/chunk-424AP7FM.js +534 -0
  32. package/dist/chunk-4J5TZGOE.js +3707 -0
  33. package/dist/chunk-4QJ3Y5JM.js +898 -0
  34. package/dist/chunk-4U2ET7ZY.js +1326 -0
  35. package/dist/chunk-4XPFLICE.js +876 -0
  36. package/dist/chunk-5B2OCU5P.js +31707 -0
  37. package/dist/chunk-5GGOGLSN.js +73 -0
  38. package/dist/chunk-5JRZPLI6.js +251 -0
  39. package/dist/chunk-5TQ3JYBU.js +397 -0
  40. package/dist/chunk-66JPZSGX.js +55 -0
  41. package/dist/chunk-6HSVXHCZ.js +764 -0
  42. package/dist/chunk-6S5FPUS7.js +21 -0
  43. package/dist/chunk-722LQO64.js +131 -0
  44. package/dist/chunk-73NJ7IT7.js +354 -0
  45. package/dist/chunk-7FW3I7WC.js +95 -0
  46. package/dist/chunk-7KUCBNLB.js +173 -0
  47. package/dist/chunk-7RDOV3DF.js +201 -0
  48. package/dist/chunk-A5MNH4ER.js +79 -0
  49. package/dist/chunk-ADIVZ2D5.js +15 -0
  50. package/dist/chunk-AE3P3F6W.js +366 -0
  51. package/dist/chunk-AERM3VGP.js +280 -0
  52. package/dist/chunk-AEWHC4WM.js +246 -0
  53. package/dist/chunk-AOVQ7VIF.js +169 -0
  54. package/dist/chunk-AOYHP3WI.js +12411 -0
  55. package/dist/chunk-B3YEBABJ.js +7160 -0
  56. package/dist/chunk-BCQXEZPJ.js +154 -0
  57. package/dist/chunk-BKTQAYO2.js +418 -0
  58. package/dist/chunk-BSECIPAQ.js +80 -0
  59. package/dist/chunk-BUIMGNDD.js +52 -0
  60. package/dist/chunk-BXHV3GSB.js +10320 -0
  61. package/dist/chunk-C6ZVZCPP.js +139 -0
  62. package/dist/chunk-CEZNQVWM.js +82 -0
  63. package/dist/chunk-CGFZGR7G.js +1492 -0
  64. package/dist/chunk-CGOADM2X.js +337 -0
  65. package/dist/chunk-CI4R6P2B.js +24 -0
  66. package/dist/chunk-D2TCGRSX.js +73 -0
  67. package/dist/chunk-D4PTYFOG.js +154 -0
  68. package/dist/chunk-D54ZWG4T.js +717 -0
  69. package/dist/chunk-DEBI37QB.js +145 -0
  70. package/dist/chunk-DWROHPXP.js +1051 -0
  71. package/dist/chunk-DZ6UOJ5D.js +92 -0
  72. package/dist/chunk-EBJTVRQN.js +81 -0
  73. package/dist/chunk-EGEI2RQA.js +1167 -0
  74. package/dist/chunk-EHHUASO5.js +1305 -0
  75. package/dist/chunk-EPKTIOED.js +41 -0
  76. package/dist/chunk-ER5JW2QZ.js +5681 -0
  77. package/dist/chunk-ETHFACAB.js +315 -0
  78. package/dist/chunk-EXUE5W2F.js +112 -0
  79. package/dist/chunk-EXXICUIW.js +73 -0
  80. package/dist/chunk-FFQSZJOO.js +169 -0
  81. package/dist/chunk-FHFKPGDO.js +85 -0
  82. package/dist/chunk-FW3QKMFX.js +158 -0
  83. package/dist/chunk-GD4ZNZ7W.js +30 -0
  84. package/dist/chunk-GHVMWF2I.js +581 -0
  85. package/dist/chunk-GMKAXSYQ.js +297 -0
  86. package/dist/chunk-HBVF6BWO.js +325 -0
  87. package/dist/chunk-HV4YGVMS.js +379 -0
  88. package/dist/chunk-ILBCKAV6.js +89 -0
  89. package/dist/chunk-J4U4AW46.js +440 -0
  90. package/dist/chunk-J6ESSM47.js +1791 -0
  91. package/dist/chunk-JBZHIC6T.js +2309 -0
  92. package/dist/chunk-JCFWOULR.js +245 -0
  93. package/dist/chunk-JRF5L6OD.js +131 -0
  94. package/dist/chunk-JSS75KCG.js +2014 -0
  95. package/dist/chunk-JSXWIWWJ.js +225 -0
  96. package/dist/chunk-JYV7I2QH.js +98 -0
  97. package/dist/chunk-KIOXTQQL.js +1596 -0
  98. package/dist/chunk-KWVTXT5B.js +89 -0
  99. package/dist/chunk-KX22RD6R.js +33 -0
  100. package/dist/chunk-LA6IPTGH.js +709 -0
  101. package/dist/chunk-LH5VCGLB.js +1796 -0
  102. package/dist/chunk-LQQ6XJ2Y.js +269 -0
  103. package/dist/chunk-MJQ55WZZ.js +65 -0
  104. package/dist/chunk-ML3UKMH3.js +40 -0
  105. package/dist/chunk-MOZPLHSU.js +5526 -0
  106. package/dist/chunk-NGEWJ4DF.js +89 -0
  107. package/dist/chunk-NH6VIOAR.js +211 -0
  108. package/dist/chunk-O5VZQKCB.js +26106 -0
  109. package/dist/chunk-OHSV42QB.js +748 -0
  110. package/dist/chunk-OO3TAHO5.js +4070 -0
  111. package/dist/chunk-OTNHSAGN.js +38282 -0
  112. package/dist/chunk-OUWAC7AQ.js +442 -0
  113. package/dist/chunk-OXMIV4WE.js +270 -0
  114. package/dist/chunk-P5KJURUR.js +229 -0
  115. package/dist/chunk-P6GJOVO6.js +307 -0
  116. package/dist/chunk-QARAGUXX.js +23 -0
  117. package/dist/chunk-R43HJCDX.js +2711 -0
  118. package/dist/chunk-RAXBAWRN.js +210 -0
  119. package/dist/chunk-RK3JHWPT.js +39 -0
  120. package/dist/chunk-RWA23GMM.js +24 -0
  121. package/dist/chunk-S4K4L6IM.js +179 -0
  122. package/dist/chunk-SAXK6LVF.js +124 -0
  123. package/dist/chunk-SEPGEJNK.js +1607 -0
  124. package/dist/chunk-SUJERP5I.js +285 -0
  125. package/dist/chunk-T3ED6BY2.js +913 -0
  126. package/dist/chunk-THKDVSEC.js +90 -0
  127. package/dist/chunk-TI4GSEL5.js +52 -0
  128. package/dist/chunk-TPI73L57.js +164 -0
  129. package/dist/chunk-TVHW77C7.js +338 -0
  130. package/dist/chunk-TWNHOSDT.js +1073 -0
  131. package/dist/chunk-UFMN76QD.js +347 -0
  132. package/dist/chunk-UHGLFRZE.js +205 -0
  133. package/dist/chunk-UTZYPKBF.js +15231 -0
  134. package/dist/chunk-UXNLELW6.js +25 -0
  135. package/dist/chunk-UXXS53EA.js +166 -0
  136. package/dist/chunk-V5DHFGI7.js +171 -0
  137. package/dist/chunk-V5YIPMHV.js +2353 -0
  138. package/dist/chunk-WMUWEO2C.js +754 -0
  139. package/dist/chunk-WOE3D7JM.js +945 -0
  140. package/dist/chunk-X2IK5LVR.js +2592 -0
  141. package/dist/chunk-XU2YXCDL.js +459 -0
  142. package/dist/chunk-YJG5HIX5.js +203 -0
  143. package/dist/chunk-Z3QE7TZM.js +72 -0
  144. package/dist/chunk-Z5Z3JHJY.js +64 -0
  145. package/dist/chunk-ZDIFBJFT.js +168 -0
  146. package/dist/chunk-ZGGCEXDC.js +176 -0
  147. package/dist/chunk-ZMZCZNKU.js +263 -0
  148. package/dist/chunk-ZNC5T65N.js +17 -0
  149. package/dist/chunk-ZO3I3A7O.js +308 -0
  150. package/dist/chunk-ZQKXBUB7.js +217 -0
  151. package/dist/chunk-ZTRINFM2.js +78 -0
  152. package/dist/chunk-ZU7JZCVP.js +193 -0
  153. package/dist/chunk-ZZAWNALS.js +350 -0
  154. package/dist/cli/entry.js +54 -0
  155. package/dist/connector-L5QQTR6Y.js +26 -0
  156. package/dist/context-62DC6EC3.js +31 -0
  157. package/dist/council-convene-NJWPNBDU.js +46 -0
  158. package/dist/create-agent-config-ODSQWNVC.js +55 -0
  159. package/dist/default-registry-2PU3BTAU.js +68 -0
  160. package/dist/deliver-task-KONV4C4M.js +57 -0
  161. package/dist/delivery-gate-v2-F2YVMVGK.js +27 -0
  162. package/dist/domain-knowledge-store-DDZ3F4J7.js +11 -0
  163. package/dist/fetch-core-ZPPYDSZH.js +14 -0
  164. package/dist/galaxy-K72BBDQN.js +91 -0
  165. package/dist/goal-criteria-SCALAU2D.js +141 -0
  166. package/dist/goal-persist-XWY2GDQX.js +19 -0
  167. package/dist/goal-tracker-FXMJ2GVK.js +11 -0
  168. package/dist/headless-LSB6I7PT.js +162 -0
  169. package/dist/headless-coordinator-VDPDMVUT.js +90 -0
  170. package/dist/inject-U55SMB6A.js +39 -0
  171. package/dist/login-flow-CD4ZGXOC.js +59 -0
  172. package/dist/logs-cli-SQVYFMMN.js +283 -0
  173. package/dist/loop-ULZYBDA3.js +76 -0
  174. package/dist/main.js +4064 -0
  175. package/dist/manager-ROZBCWPA.js +171 -0
  176. package/dist/manager-Z7XFFUOM.js +10670 -0
  177. package/dist/meridian-indexer-ZIW363L7.js +21 -0
  178. package/dist/native-resolver-PN34UIVV.js +13 -0
  179. package/dist/node_modules/better-sqlite3/lib/database.js +90 -0
  180. package/dist/node_modules/better-sqlite3/lib/index.js +3 -0
  181. package/dist/node_modules/better-sqlite3/lib/methods/aggregate.js +43 -0
  182. package/dist/node_modules/better-sqlite3/lib/methods/backup.js +67 -0
  183. package/dist/node_modules/better-sqlite3/lib/methods/function.js +31 -0
  184. package/dist/node_modules/better-sqlite3/lib/methods/inspect.js +7 -0
  185. package/dist/node_modules/better-sqlite3/lib/methods/pragma.js +12 -0
  186. package/dist/node_modules/better-sqlite3/lib/methods/serialize.js +16 -0
  187. package/dist/node_modules/better-sqlite3/lib/methods/table.js +189 -0
  188. package/dist/node_modules/better-sqlite3/lib/methods/transaction.js +78 -0
  189. package/dist/node_modules/better-sqlite3/lib/methods/wrappers.js +54 -0
  190. package/dist/node_modules/better-sqlite3/lib/sqlite-error.js +20 -0
  191. package/dist/node_modules/better-sqlite3/lib/util.js +12 -0
  192. package/dist/node_modules/better-sqlite3/package.json +59 -0
  193. package/dist/ownership-ledger-E3WIEKPL.js +9 -0
  194. package/dist/package.json +3 -0
  195. package/dist/path-grants-XRRXHXG7.js +40 -0
  196. package/dist/paths-LVV5IMQN.js +49 -0
  197. package/dist/plan-fact-anchors-LMVQZCW5.js +13 -0
  198. package/dist/plan-store-ODLTTPFB.js +17 -0
  199. package/dist/plan-templates-5FPFBOL6.js +109 -0
  200. package/dist/plugin-loader-ZZKX7ZE6.js +22 -0
  201. package/dist/prefix-budget-62OV5HQC.js +13 -0
  202. package/dist/project-trust-5WS5MOMU.js +31 -0
  203. package/dist/provider-cli-ALDQXIT7.js +37 -0
  204. package/dist/providers-XQYTAVPK.js +11 -0
  205. package/dist/proxy-resolver-V2Y6534D.js +15 -0
  206. package/dist/recovery-cli-KPGY6FY3.js +106 -0
  207. package/dist/review-discipline-MNSYCST5.js +55 -0
  208. package/dist/review-router-BVQZW3MX.js +18 -0
  209. package/dist/seed-capsules/seed-capsule-attack-methodology.md +62 -0
  210. package/dist/seed-capsules/seed-capsule-changgeng.md +31 -0
  211. package/dist/seed-capsules/seed-capsule-design-aesthetics.md +38 -0
  212. package/dist/seed-capsules/seed-capsule-diagnostic-ladder.md +54 -0
  213. package/dist/seed-capsules/seed-capsule-fu.md +39 -0
  214. package/dist/seed-capsules/seed-capsule-huagai.md +73 -0
  215. package/dist/seed-capsules/seed-capsule-kaiyang.md +65 -0
  216. package/dist/seed-capsules/seed-capsule-knowledge-work.md +40 -0
  217. package/dist/seed-capsules/seed-capsule-tanlang.md +47 -0
  218. package/dist/seed-capsules/seed-capsule-tianfu.md +23 -0
  219. package/dist/seed-capsules/seed-capsule-tianliang.md +63 -0
  220. package/dist/seed-capsules/seed-capsule-tianquan.md +32 -0
  221. package/dist/seed-capsules/seed-capsule-tianxuan-ccr.md +22 -0
  222. package/dist/seed-capsules/seed-capsule-tianxuan.md +64 -0
  223. package/dist/seed-capsules/seed-capsule-yaoguang.md +87 -0
  224. package/dist/serve-X2R2UTLF.js +170 -0
  225. package/dist/serve-agent-KHSU6RVV.js +965 -0
  226. package/dist/session-persist-HUUC772H.js +37 -0
  227. package/dist/session-registry-6XUD5C4Y.js +15 -0
  228. package/dist/skill-loader-CK3RMO47.js +48 -0
  229. package/dist/skills/cli-harness-sop.md +207 -0
  230. package/dist/spawn-git-4HFU65AH.js +29 -0
  231. package/dist/sse-EYUTBWUK.js +512 -0
  232. package/dist/starflow-NOFBMPFU.js +30 -0
  233. package/dist/streamableHttp-V67CNJMO.js +447 -0
  234. package/dist/task-contract-6XHBNJQK.js +32 -0
  235. package/dist/task-ledger-3K4TJIER.js +9 -0
  236. package/dist/team-orchestrate-S6NHZP7X.js +64 -0
  237. package/dist/title-extract-QX4XGCYN.js +50 -0
  238. package/dist/todo-QDXGRZZP.js +31 -0
  239. package/dist/todo-store-V3TTO5AH.js +12 -0
  240. package/dist/tool-preset-LU5BYEDZ.js +23 -0
  241. package/dist/tool-tiers-GD742YBN.js +23 -0
  242. package/dist/turndown.es-OI55K6C3.js +17373 -0
  243. package/dist/verification-attribution-EKG4CNUV.js +13 -0
  244. package/dist/volatile-git-MBTST7RA.js +15 -0
  245. package/dist/wave-checkpoint-XLIIHXQA.js +30 -0
  246. package/dist/web-cli-DUG4I35O.js +233 -0
  247. package/dist/web-search-3IK542AA.js +34 -0
  248. package/dist/workers/cpu-worker.js +45 -0
  249. package/dist/workflow-runner-HX7UBAYG.js +297 -0
  250. package/dist/worktree-baseline-O5NCU6M2.js +9 -0
  251. package/package.json +122 -0
  252. package/scripts/check-mobile-env.mjs +76 -0
  253. package/scripts/fetch-native-sqlite.js +392 -0
  254. package/scripts/prune-installed-wasms.js +45 -0
  255. package/scripts/tree-sitter-wasm-keep.js +40 -0
@@ -0,0 +1,90 @@
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
+ getResolvedEnv
5
+ } from "./chunk-UFMN76QD.js";
6
+ import {
7
+ init_esm_shims
8
+ } from "./chunk-5GGOGLSN.js";
9
+
10
+ // src/tools/spawn-git.ts
11
+ init_esm_shims();
12
+ import { spawn, spawnSync, execFile } from "child_process";
13
+ import { existsSync } from "fs";
14
+ import { join } from "path";
15
+ var UNSAFE_GIT_ENV = /* @__PURE__ */ new Set([
16
+ "GIT_DIR",
17
+ "GIT_WORK_TREE",
18
+ "GIT_INDEX_FILE",
19
+ "GIT_OBJECT_DIRECTORY",
20
+ "GIT_ALTERNATE_OBJECT_DIRECTORIES",
21
+ "GIT_COMMON_DIR",
22
+ "GIT_REPLACE_REF_BASE"
23
+ ]);
24
+ function sanitizeGitEnv(env) {
25
+ const copy = { ...env };
26
+ for (const name of Object.keys(copy)) {
27
+ if (UNSAFE_GIT_ENV.has(name.toUpperCase())) delete copy[name];
28
+ }
29
+ return copy;
30
+ }
31
+ function resolveGitCommand(env, deps) {
32
+ const effectiveEnv = { ...process.env, ...env };
33
+ const platform = deps?.platform ?? process.platform;
34
+ const exists = deps?.existsSync ?? existsSync;
35
+ const override = effectiveEnv["RIVET_GIT_PATH"];
36
+ if (override && exists(override)) return override;
37
+ if (platform === "win32") {
38
+ const candidates = [
39
+ "C:\\Program Files\\Git\\cmd\\git.exe",
40
+ "C:\\Program Files (x86)\\Git\\cmd\\git.exe"
41
+ ];
42
+ const localApp = effectiveEnv["LOCALAPPDATA"];
43
+ if (localApp) {
44
+ candidates.push(join(localApp, "Programs", "Git", "cmd", "git.exe"));
45
+ }
46
+ for (const c of candidates) {
47
+ if (exists(c)) return c;
48
+ }
49
+ }
50
+ return "git";
51
+ }
52
+ function gitEnv(cwd) {
53
+ return sanitizeGitEnv(getResolvedEnv(cwd));
54
+ }
55
+ function spawnGitSync(args, opts) {
56
+ const cwd = typeof opts?.cwd === "string" ? opts.cwd : void 0;
57
+ const command = resolveGitCommand(opts?.env);
58
+ const env = sanitizeGitEnv({ ...gitEnv(cwd), ...opts?.env });
59
+ return spawnSync(command, args, {
60
+ encoding: "utf-8",
61
+ ...opts,
62
+ env,
63
+ windowsHide: true
64
+ });
65
+ }
66
+ function spawnGit(args, opts) {
67
+ const cwd = typeof opts?.cwd === "string" ? opts.cwd : void 0;
68
+ const command = resolveGitCommand(opts?.env);
69
+ const env = sanitizeGitEnv({ ...gitEnv(cwd), ...opts?.env });
70
+ return spawn(command, args, { ...opts, env, windowsHide: true });
71
+ }
72
+ function execFileGit(args, opts, cb) {
73
+ const cwd = typeof opts?.cwd === "string" ? opts.cwd : void 0;
74
+ const command = resolveGitCommand(opts?.env);
75
+ const env = sanitizeGitEnv({ ...gitEnv(cwd), ...opts?.env });
76
+ const mergedOpts = { ...opts, encoding: "utf-8", env, windowsHide: true };
77
+ if (cb) {
78
+ return execFile(command, args, mergedOpts, cb);
79
+ }
80
+ return execFile(command, args, mergedOpts);
81
+ }
82
+
83
+ export {
84
+ sanitizeGitEnv,
85
+ resolveGitCommand,
86
+ gitEnv,
87
+ spawnGitSync,
88
+ spawnGit,
89
+ execFileGit
90
+ };
@@ -0,0 +1,52 @@
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
+ GoalTracker
5
+ } from "./chunk-OXMIV4WE.js";
6
+ import {
7
+ writeFileAtomicSync
8
+ } from "./chunk-A5MNH4ER.js";
9
+ import {
10
+ init_esm_shims
11
+ } from "./chunk-5GGOGLSN.js";
12
+
13
+ // src/agent/goal-persist.ts
14
+ init_esm_shims();
15
+ import { join } from "path";
16
+ import { readFileSync, existsSync, unlinkSync } from "fs";
17
+ function goalStatePath(sessionDir, sessionId) {
18
+ return join(sessionDir, `${sessionId}.goal.json`);
19
+ }
20
+ function saveGoalState(sessionDir, sessionId, tracker) {
21
+ const record = tracker.toRecord();
22
+ writeFileAtomicSync(goalStatePath(sessionDir, sessionId), JSON.stringify(record, null, 2) + "\n");
23
+ }
24
+ function loadGoalState(sessionDir, sessionId) {
25
+ const path = goalStatePath(sessionDir, sessionId);
26
+ if (!existsSync(path)) return null;
27
+ try {
28
+ return JSON.parse(readFileSync(path, "utf-8"));
29
+ } catch {
30
+ return null;
31
+ }
32
+ }
33
+ function deleteGoalState(sessionDir, sessionId) {
34
+ const path = goalStatePath(sessionDir, sessionId);
35
+ if (existsSync(path)) {
36
+ unlinkSync(path);
37
+ }
38
+ }
39
+ function restoreGoalTracker(sessionDir, sessionId, config) {
40
+ const record = loadGoalState(sessionDir, sessionId);
41
+ if (!record) return null;
42
+ if (record.status === "complete") return null;
43
+ return GoalTracker.fromRecord(record, config);
44
+ }
45
+
46
+ export {
47
+ goalStatePath,
48
+ saveGoalState,
49
+ loadGoalState,
50
+ deleteGoalState,
51
+ restoreGoalTracker
52
+ };
@@ -0,0 +1,164 @@
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
+ init_esm_shims
5
+ } from "./chunk-5GGOGLSN.js";
6
+
7
+ // src/compact/constants.ts
8
+ init_esm_shims();
9
+ var DEFAULT_POLICY_RATIOS = {
10
+ watch: 0.6,
11
+ compact: 0.78,
12
+ reactive: 0.88,
13
+ ceiling: 0.95
14
+ };
15
+ var STRATEGY_POLICY_RATIOS = {
16
+ // DeepSeek-style persistent exact-prefix cache: compaction is expensive because
17
+ // reshaping history can invalidate a valuable prefix. Delay non-emergency
18
+ // compaction while retaining the 95% hard ceiling.
19
+ "cache-preserving": { watch: 0.72, compact: 0.86, reactive: 0.92, ceiling: 0.95 },
20
+ // OpenAI/Gemini/Claude-like cache paths: some cache survives or TTL is short,
21
+ // so keep the existing ACF behaviour.
22
+ balanced: DEFAULT_POLICY_RATIOS,
23
+ // MiMO/local/no-cache providers: no prefix-cache loss, so compact earlier to
24
+ // keep the active context cleaner.
25
+ aggressive: { watch: 0.5, compact: 0.7, reactive: 0.84, ceiling: 0.95 }
26
+ };
27
+ function strategyForCacheType(cacheType, persistent) {
28
+ if (cacheType === "exact-prefix" && persistent) return "cache-preserving";
29
+ if (cacheType === "none") return "aggressive";
30
+ return "balanced";
31
+ }
32
+ function compactProviderStrategy(providerProfile) {
33
+ if (!providerProfile) return "balanced";
34
+ return strategyForCacheType(providerProfile.cacheType, providerProfile.persistent);
35
+ }
36
+ function compactPolicyRatios(providerProfile) {
37
+ const base = STRATEGY_POLICY_RATIOS[compactProviderStrategy(providerProfile)];
38
+ const o = providerProfile?.compaction?.ratios;
39
+ if (!o) return base;
40
+ return {
41
+ watch: o.watch ?? base.watch,
42
+ compact: o.compact ?? base.compact,
43
+ reactive: o.reactive ?? base.reactive,
44
+ ceiling: o.ceiling ?? base.ceiling
45
+ };
46
+ }
47
+ function compactThresholds(input) {
48
+ const contextWindow = typeof input === "number" ? input : input.contextWindow;
49
+ const ratios = typeof input === "number" ? { watch: 0.6, compact: 0.78, reactive: 0.8, ceiling: 0.95 } : compactPolicyRatios(input.providerProfile);
50
+ const isLargeWindow = contextWindow >= LARGE_CONTEXT_WINDOW_TOKENS;
51
+ const toolResultHardCap = isLargeWindow ? 2e5 : 1e5;
52
+ return {
53
+ autoThreshold: Math.floor(contextWindow * ratios.reactive),
54
+ // Pure ratio — the old Math.min(..., 500K) clamp dragged the 1M
55
+ // cache-preserving watch floor from 720K down to 500K, triggering the
56
+ // watch tier at 50% of the window instead of the intended 72%.
57
+ autoFloor: Math.floor(contextWindow * ratios.watch),
58
+ toolResultMaxTokens: Math.min(Math.floor(contextWindow * 0.3), toolResultHardCap)
59
+ };
60
+ }
61
+ var TASK_ANCHOR_MAX_ITEMS = 6;
62
+ var CACHE_ANCHOR_MESSAGES = 2;
63
+ var KEEP_RECENT_MESSAGES = 4;
64
+ var LARGE_CONTEXT_WINDOW_TOKENS = 5e5;
65
+ function summaryOutputBudgetChars(contextWindow, opts) {
66
+ const base = contextWindow >= 1e6 ? { full: 8e3, partial: 5e3 } : contextWindow >= LARGE_CONTEXT_WINDOW_TOKENS ? { full: 6e3, partial: 4e3 } : { full: 3e3, partial: 2e3 };
67
+ if (!opts?.generous) return base;
68
+ return { full: base.full * 2, partial: base.partial * 2 };
69
+ }
70
+ function adaptiveCompactPolicyRatios(providerProfile, recentHitRate) {
71
+ const base = compactPolicyRatios(providerProfile);
72
+ if (recentHitRate === null) return base;
73
+ if (recentHitRate >= 0.85) {
74
+ return {
75
+ watch: Math.min(base.watch + 0.05, 0.9),
76
+ compact: Math.min(base.compact + 0.03, 0.93),
77
+ reactive: Math.min(base.reactive + 0.02, 0.95),
78
+ ceiling: base.ceiling
79
+ };
80
+ }
81
+ if (recentHitRate < 0.3) {
82
+ return {
83
+ watch: Math.max(base.watch - 0.1, 0.4),
84
+ compact: Math.max(base.compact - 0.08, 0.6),
85
+ reactive: Math.max(base.reactive - 0.05, 0.75),
86
+ ceiling: base.ceiling
87
+ };
88
+ }
89
+ return base;
90
+ }
91
+ function precisionCeilingRatio(contextWindow, override) {
92
+ if (typeof override === "number" && Number.isFinite(override) && override > 0 && override < 1) {
93
+ return override;
94
+ }
95
+ if (contextWindow >= LARGE_CONTEXT_WINDOW_TOKENS) return 0.7;
96
+ if (contextWindow >= 2e5) return 0.55;
97
+ return 1;
98
+ }
99
+ var PRUNE_PROTECT_RECENT_MESSAGES = 8;
100
+ var PRUNE_MIN_CONTENT_CHARS = 1200;
101
+ function pruneThresholds(contextWindow) {
102
+ if (contextWindow >= 5e5) {
103
+ return { protectRecent: 60, minChars: 15e4 };
104
+ }
105
+ if (contextWindow >= 2e5) {
106
+ return { protectRecent: 30, minChars: 4e4 };
107
+ }
108
+ return { protectRecent: PRUNE_PROTECT_RECENT_MESSAGES, minChars: PRUNE_MIN_CONTENT_CHARS };
109
+ }
110
+ function staleRoundThresholds(contextWindow) {
111
+ if (contextWindow >= 5e5) {
112
+ return { recentToKeep: 30, previewChars: 15e4 };
113
+ }
114
+ if (contextWindow >= 2e5) {
115
+ return { recentToKeep: 12, previewChars: 4e4 };
116
+ }
117
+ return { recentToKeep: 4, previewChars: 1200 };
118
+ }
119
+ var PER_MESSAGE_TOOL_RESULT_BUDGET_CHARS = 12e4;
120
+ function perMessageToolResultBudget(contextWindow) {
121
+ if (!contextWindow || contextWindow <= 0) {
122
+ return PER_MESSAGE_TOOL_RESULT_BUDGET_CHARS;
123
+ }
124
+ const { minChars } = pruneThresholds(contextWindow);
125
+ const scaled = minChars * 2;
126
+ if (scaled < PER_MESSAGE_TOOL_RESULT_BUDGET_CHARS) {
127
+ return PER_MESSAGE_TOOL_RESULT_BUDGET_CHARS;
128
+ }
129
+ return Math.min(scaled, 3e5);
130
+ }
131
+ var INLINE_TOOL_RESULT_MAX_CHARS = 5e4;
132
+ function toolTypeBudgets(contextWindow) {
133
+ const w = contextWindow;
134
+ const grepPerCall = w >= 2e5 ? Math.min(Math.floor(w * 4e-3), 8e3) : 2e3;
135
+ const grepSummarize = w >= 2e5 ? Math.min(Math.floor(w * 8e-3), 16e3) : 4e3;
136
+ return {
137
+ grep: { perCall: grepPerCall, perTurnCumulative: grepSummarize * 2, summarizeAfter: grepSummarize },
138
+ search: { perCall: grepPerCall, perTurnCumulative: grepSummarize * 2, summarizeAfter: grepSummarize },
139
+ read_file: { perCall: Math.min(w * 0.1, 2e4), perTurnCumulative: Math.min(w * 0.25, 5e4), summarizeAfter: Math.min(w * 0.15, 3e4) },
140
+ bash: { perCall: 5e3, perTurnCumulative: 15e3, summarizeAfter: 8e3 },
141
+ default: { perCall: 5e3, perTurnCumulative: 2e4, summarizeAfter: 1e4 }
142
+ };
143
+ }
144
+ function getToolBudget(toolName, contextWindow) {
145
+ const budgets = toolTypeBudgets(contextWindow);
146
+ return budgets[toolName] ?? budgets["default"];
147
+ }
148
+
149
+ export {
150
+ compactProviderStrategy,
151
+ compactPolicyRatios,
152
+ compactThresholds,
153
+ TASK_ANCHOR_MAX_ITEMS,
154
+ CACHE_ANCHOR_MESSAGES,
155
+ KEEP_RECENT_MESSAGES,
156
+ summaryOutputBudgetChars,
157
+ adaptiveCompactPolicyRatios,
158
+ precisionCeilingRatio,
159
+ pruneThresholds,
160
+ staleRoundThresholds,
161
+ perMessageToolResultBudget,
162
+ INLINE_TOOL_RESULT_MAX_CHARS,
163
+ getToolBudget
164
+ };
@@ -0,0 +1,338 @@
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
+ dependencyEdgeSchema,
5
+ dependencyId
6
+ } from "./chunk-4QJ3Y5JM.js";
7
+ import {
8
+ init_esm_shims
9
+ } from "./chunk-5GGOGLSN.js";
10
+
11
+ // src/agent/unified-plan.ts
12
+ init_esm_shims();
13
+
14
+ // src/agent/task-graph.ts
15
+ init_esm_shims();
16
+ function validateTaskGraph(graph) {
17
+ const ids = new Set(graph.nodes.map((n) => n.id));
18
+ const dangling = [];
19
+ for (const node of graph.nodes) {
20
+ for (const dep of node.dependsOn) {
21
+ if (!ids.has(dep)) dangling.push({ taskId: node.id, missingDep: dep });
22
+ }
23
+ }
24
+ const cycles = [];
25
+ const visiting = /* @__PURE__ */ new Set();
26
+ const visited = /* @__PURE__ */ new Set();
27
+ const stack = [];
28
+ function dfs(id) {
29
+ if (visited.has(id)) return;
30
+ if (visiting.has(id)) {
31
+ const idx = stack.indexOf(id);
32
+ if (idx >= 0) cycles.push(stack.slice(idx).concat(id));
33
+ return;
34
+ }
35
+ visiting.add(id);
36
+ stack.push(id);
37
+ const node = graph.nodes.find((n) => n.id === id);
38
+ if (node) {
39
+ for (const dep of node.dependsOn) {
40
+ if (ids.has(dep)) dfs(dep);
41
+ }
42
+ }
43
+ stack.pop();
44
+ visiting.delete(id);
45
+ visited.add(id);
46
+ }
47
+ for (const node of graph.nodes) dfs(node.id);
48
+ return { valid: dangling.length === 0 && cycles.length === 0, dangling, cycles };
49
+ }
50
+ function topologicalOrder(graph) {
51
+ const nodeMap = new Map(graph.nodes.map((n) => [n.id, n]));
52
+ const visited = /* @__PURE__ */ new Set();
53
+ const result = [];
54
+ function visit(id) {
55
+ if (visited.has(id)) return;
56
+ visited.add(id);
57
+ const node = nodeMap.get(id);
58
+ if (node) {
59
+ for (const dep of node.dependsOn) {
60
+ if (nodeMap.has(dep)) visit(dep);
61
+ }
62
+ }
63
+ result.push(id);
64
+ }
65
+ for (const node of graph.nodes) visit(node.id);
66
+ return result;
67
+ }
68
+ function groupIntoWaves(graph) {
69
+ const order = topologicalOrder(graph);
70
+ const nodeMap = new Map(graph.nodes.map((n) => [n.id, n]));
71
+ const assigned = /* @__PURE__ */ new Map();
72
+ const waves = [];
73
+ for (const id of order) {
74
+ const node = nodeMap.get(id);
75
+ let wave = 0;
76
+ for (const dep of node.dependsOn) {
77
+ const depWave = assigned.get(dep);
78
+ if (depWave !== void 0 && depWave >= wave) wave = depWave + 1;
79
+ }
80
+ assigned.set(id, wave);
81
+ if (!waves[wave]) waves[wave] = [];
82
+ waves[wave].push(id);
83
+ }
84
+ return waves.filter(Boolean);
85
+ }
86
+ function renderTaskGraphSummary(graph) {
87
+ const waves = groupIntoWaves(graph);
88
+ const lines = [`Mission: ${graph.mission}`, `Tasks: ${graph.nodes.length}`, ""];
89
+ for (const [i, wave] of waves.entries()) {
90
+ lines.push(`Wave ${i + 1}:`);
91
+ for (const id of wave) {
92
+ const node = graph.nodes.find((n) => n.id === id);
93
+ const deps = node.dependsOn.length > 0 ? ` (deps: ${node.dependsOn.join(", ")})` : "";
94
+ lines.push(` ${node.id} [${node.profile}] ${node.title}${deps}`);
95
+ }
96
+ }
97
+ return lines.join("\n");
98
+ }
99
+
100
+ // src/agent/unified-plan.ts
101
+ function taskGraphToUnifiedPlan(graph, source = "plan_task") {
102
+ const tasks = graph.nodes.map((node) => ({
103
+ id: node.id,
104
+ title: node.title,
105
+ objective: node.objective,
106
+ profile: node.profile,
107
+ kind: node.kind,
108
+ files: node.files,
109
+ dependsOn: node.dependsOn.map(dependencyId),
110
+ riskTier: node.riskTier
111
+ }));
112
+ return {
113
+ version: 1,
114
+ objective: graph.mission,
115
+ tasks,
116
+ source,
117
+ createdAt: graph.createdAt
118
+ };
119
+ }
120
+ function unifiedPlanToTaskGraph(plan) {
121
+ return {
122
+ mission: plan.objective,
123
+ nodes: plan.tasks.map((node) => ({
124
+ id: node.id,
125
+ title: node.title,
126
+ objective: node.objective,
127
+ profile: node.profile,
128
+ kind: node.kind,
129
+ files: node.files,
130
+ dependsOn: node.dependsOn.map(dependencyId),
131
+ riskTier: node.riskTier
132
+ })),
133
+ createdAt: plan.createdAt
134
+ };
135
+ }
136
+ function unifiedPlanToTeamTasks(plan) {
137
+ return plan.tasks.map((node) => ({
138
+ id: node.id,
139
+ title: node.title,
140
+ objective: node.objective,
141
+ files: node.files,
142
+ profile: node.profile,
143
+ kind: node.kind,
144
+ verification: node.verification ?? [],
145
+ dependsOn: node.dependsOn,
146
+ riskTier: node.riskTier,
147
+ touchSet: node.touchSet ?? node.files,
148
+ groupId: node.groupId,
149
+ routeHint: node.routeHint
150
+ }));
151
+ }
152
+ function buildDependencyReachability(tasks) {
153
+ const direct = /* @__PURE__ */ new Map();
154
+ for (const t of tasks) direct.set(t.id, t.dependsOn.map(dependencyId));
155
+ const reach = /* @__PURE__ */ new Map();
156
+ for (const t of tasks) {
157
+ const acc = /* @__PURE__ */ new Set();
158
+ const stack = t.dependsOn.map(dependencyId);
159
+ while (stack.length > 0) {
160
+ const dep = stack.pop();
161
+ if (acc.has(dep)) continue;
162
+ acc.add(dep);
163
+ for (const d of direct.get(dep) ?? []) stack.push(d);
164
+ }
165
+ reach.set(t.id, acc);
166
+ }
167
+ return reach;
168
+ }
169
+ function detectOverlapWithoutOrder(tasks) {
170
+ const warnings = [];
171
+ const reach = buildDependencyReachability(tasks);
172
+ for (let i = 0; i < tasks.length; i++) {
173
+ for (let j = i + 1; j < tasks.length; j++) {
174
+ const a = tasks[i];
175
+ const b = tasks[j];
176
+ const aFiles = a.touchSet && a.touchSet.length > 0 ? a.touchSet : a.files;
177
+ const bFiles = b.touchSet && b.touchSet.length > 0 ? b.touchSet : b.files;
178
+ if (aFiles.length === 0 || bFiles.length === 0) continue;
179
+ const shared = aFiles.filter((f) => bFiles.includes(f));
180
+ if (shared.length === 0) continue;
181
+ const ordered = reach.get(a.id)?.has(b.id) === true || reach.get(b.id)?.has(a.id) === true;
182
+ if (!ordered) {
183
+ warnings.push(
184
+ `\u5206\u7247 ${a.id} \u4E0E ${b.id} \u90FD\u6539 ${shared.join(", ")} \u4F46\u672A\u6807 dependsOn \u2014\u2014 \u8865\u4E00\u6761\u4F9D\u8D56\u8BA9\u5199\u5165\u987A\u5E8F\u660E\u786E(\u5426\u5219\u4F1A\u88AB\u540C\u6587\u4EF6\u68C0\u6D4B\u81EA\u52A8\u4E32\u884C\u6392\u6CE2)\u3002`
185
+ );
186
+ }
187
+ }
188
+ }
189
+ return warnings;
190
+ }
191
+ function validateUnifiedPlan(plan) {
192
+ const errors = [];
193
+ const nodeErrors = [];
194
+ if (!plan.objective.trim()) {
195
+ errors.push("objective is empty");
196
+ }
197
+ if (plan.tasks.length === 0) {
198
+ errors.push("no tasks defined");
199
+ }
200
+ const ids = /* @__PURE__ */ new Set();
201
+ for (const node of plan.tasks) {
202
+ if (!node.id.trim()) {
203
+ nodeErrors.push({ nodeId: "(empty)", error: "node has empty id" });
204
+ continue;
205
+ }
206
+ if (ids.has(node.id)) {
207
+ nodeErrors.push({ nodeId: node.id, error: "duplicate node id" });
208
+ }
209
+ ids.add(node.id);
210
+ if (!node.objective.trim()) {
211
+ nodeErrors.push({ nodeId: node.id, error: "objective is empty" });
212
+ }
213
+ }
214
+ for (const node of plan.tasks) {
215
+ for (const dep of node.dependsOn) {
216
+ const depId = dependencyId(dep);
217
+ if (!ids.has(depId)) {
218
+ nodeErrors.push({ nodeId: node.id, error: `depends on unknown task: ${depId}` });
219
+ }
220
+ }
221
+ }
222
+ const graph = unifiedPlanToTaskGraph(plan);
223
+ const graphValidation = validateTaskGraph(graph);
224
+ if (!graphValidation.valid) {
225
+ for (const d of graphValidation.dangling) {
226
+ errors.push(`dangling dep: ${d.taskId} \u2192 ${d.missingDep}`);
227
+ }
228
+ for (const cycle of graphValidation.cycles) {
229
+ errors.push(`cycle: ${cycle.join(" \u2192 ")}`);
230
+ }
231
+ }
232
+ const warnings = graphValidation.cycles.length === 0 ? detectOverlapWithoutOrder(plan.tasks) : [];
233
+ return {
234
+ valid: errors.length === 0 && nodeErrors.length === 0,
235
+ errors,
236
+ nodeErrors,
237
+ warnings
238
+ };
239
+ }
240
+ function serializeUnifiedPlan(plan) {
241
+ return JSON.stringify(plan);
242
+ }
243
+ function deserializeUnifiedPlan(json) {
244
+ try {
245
+ const obj = JSON.parse(json);
246
+ if (!obj || typeof obj !== "object") return null;
247
+ const plan = obj;
248
+ if (plan.version !== 1) return null;
249
+ if (!Array.isArray(plan.tasks)) return null;
250
+ if (typeof plan.objective !== "string") return null;
251
+ for (const node of plan.tasks) {
252
+ if (typeof node.id !== "string" || !node.id.trim()) return null;
253
+ if (typeof node.objective !== "string") return null;
254
+ if (typeof node.profile !== "string") return null;
255
+ if (typeof node.kind !== "string") return null;
256
+ if (!Array.isArray(node.files)) return null;
257
+ if (!node.dependsOn.every((dep) => typeof dep === "string" || dependencyEdgeSchema.safeParse(dep).success)) return null;
258
+ }
259
+ return plan;
260
+ } catch {
261
+ return null;
262
+ }
263
+ }
264
+ function renderUnifiedPlanSummary(plan) {
265
+ const validated = validateUnifiedPlan(plan);
266
+ const lines = [
267
+ `Mission: ${plan.objective}`,
268
+ `Tasks: ${plan.tasks.length} | Source: ${plan.source}`,
269
+ `Valid: ${validated.valid ? "yes" : "no"}`
270
+ ];
271
+ if (!validated.valid) {
272
+ lines.push("");
273
+ lines.push("Validation errors:");
274
+ for (const err of validated.errors) {
275
+ lines.push(` - ${err}`);
276
+ }
277
+ for (const ne of validated.nodeErrors) {
278
+ lines.push(` - [${ne.nodeId}] ${ne.error}`);
279
+ }
280
+ }
281
+ if (validated.warnings.length > 0) {
282
+ lines.push("");
283
+ lines.push("Advisories (non-blocking):");
284
+ for (const w of validated.warnings) {
285
+ lines.push(` - ${w}`);
286
+ }
287
+ }
288
+ if (validated.valid) {
289
+ let getDepth2 = function(nodeId) {
290
+ if (depthMap.has(nodeId)) return depthMap.get(nodeId);
291
+ const node = plan.tasks.find((n) => n.id === nodeId);
292
+ if (!node || node.dependsOn.length === 0) {
293
+ depthMap.set(nodeId, 0);
294
+ return 0;
295
+ }
296
+ const max = Math.max(0, ...node.dependsOn.map((d) => getDepth2(dependencyId(d)) + 1));
297
+ depthMap.set(nodeId, max);
298
+ return max;
299
+ };
300
+ var getDepth = getDepth2;
301
+ lines.push("");
302
+ const depthMap = /* @__PURE__ */ new Map();
303
+ for (const node of plan.tasks) getDepth2(node.id);
304
+ const byDepth = /* @__PURE__ */ new Map();
305
+ for (const node of plan.tasks) {
306
+ const depth = depthMap.get(node.id) ?? 0;
307
+ const group = byDepth.get(depth) ?? [];
308
+ group.push(node);
309
+ byDepth.set(depth, group);
310
+ }
311
+ for (const [depth, nodes] of [...byDepth.entries()].sort(([a], [b]) => a - b)) {
312
+ const label = depth === 0 ? "Wave 1 (no deps)" : `Wave ${depth + 1}`;
313
+ lines.push(`${label}:`);
314
+ for (const node of nodes) {
315
+ const deps = node.dependsOn.length > 0 ? ` \u2190 ${node.dependsOn.map(dependencyId).join(", ")}` : "";
316
+ lines.push(` ${node.id} [${node.profile}] ${node.title}${deps}`);
317
+ }
318
+ }
319
+ }
320
+ if (plan.nonGoals?.length) {
321
+ lines.push("");
322
+ lines.push("Non-goals:");
323
+ for (const ng of plan.nonGoals) lines.push(` - ${ng}`);
324
+ }
325
+ return lines.join("\n");
326
+ }
327
+
328
+ export {
329
+ validateTaskGraph,
330
+ renderTaskGraphSummary,
331
+ taskGraphToUnifiedPlan,
332
+ unifiedPlanToTeamTasks,
333
+ detectOverlapWithoutOrder,
334
+ validateUnifiedPlan,
335
+ serializeUnifiedPlan,
336
+ deserializeUnifiedPlan,
337
+ renderUnifiedPlanSummary
338
+ };