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,13 @@
|
|
|
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
|
+
assessImpactedTestCoverage,
|
|
5
|
+
createVerificationAttribution,
|
|
6
|
+
getEffectiveVerifications
|
|
7
|
+
} from "./chunk-ZO3I3A7O.js";
|
|
8
|
+
import "./chunk-5GGOGLSN.js";
|
|
9
|
+
export {
|
|
10
|
+
assessImpactedTestCoverage,
|
|
11
|
+
createVerificationAttribution,
|
|
12
|
+
getEffectiveVerifications
|
|
13
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
createGitStatusCache,
|
|
5
|
+
formatGitStatus,
|
|
6
|
+
getGitInjectedContext,
|
|
7
|
+
gitStatusCache
|
|
8
|
+
} from "./chunk-EXUE5W2F.js";
|
|
9
|
+
import "./chunk-5GGOGLSN.js";
|
|
10
|
+
export {
|
|
11
|
+
createGitStatusCache,
|
|
12
|
+
formatGitStatus,
|
|
13
|
+
getGitInjectedContext,
|
|
14
|
+
gitStatusCache
|
|
15
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
buildResumeFromCheckpoint,
|
|
5
|
+
clearCheckpoint,
|
|
6
|
+
deriveTeamGroupId,
|
|
7
|
+
formatCheckpointList,
|
|
8
|
+
listCheckpoints,
|
|
9
|
+
loadCheckpoint,
|
|
10
|
+
saveCheckpoint
|
|
11
|
+
} from "./chunk-3VGD2FXB.js";
|
|
12
|
+
import "./chunk-UXNLELW6.js";
|
|
13
|
+
import "./chunk-TVHW77C7.js";
|
|
14
|
+
import "./chunk-4QJ3Y5JM.js";
|
|
15
|
+
import "./chunk-CGOADM2X.js";
|
|
16
|
+
import "./chunk-6HSVXHCZ.js";
|
|
17
|
+
import "./chunk-ADIVZ2D5.js";
|
|
18
|
+
import "./chunk-Z5Z3JHJY.js";
|
|
19
|
+
import "./chunk-WMUWEO2C.js";
|
|
20
|
+
import "./chunk-OO3TAHO5.js";
|
|
21
|
+
import "./chunk-5GGOGLSN.js";
|
|
22
|
+
export {
|
|
23
|
+
buildResumeFromCheckpoint,
|
|
24
|
+
clearCheckpoint,
|
|
25
|
+
deriveTeamGroupId,
|
|
26
|
+
formatCheckpointList,
|
|
27
|
+
listCheckpoints,
|
|
28
|
+
loadCheckpoint,
|
|
29
|
+
saveCheckpoint
|
|
30
|
+
};
|
|
@@ -0,0 +1,233 @@
|
|
|
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/cli/web-cli.ts
|
|
8
|
+
init_esm_shims();
|
|
9
|
+
var USAGE = [
|
|
10
|
+
"rivet web \u2014 web \u5DE5\u5177\u547D\u4EE4\u884C\u5165\u53E3\u4E0E\u8FDE\u901A\u6027\u81EA\u68C0",
|
|
11
|
+
"",
|
|
12
|
+
" rivet web search <query> [--count N] [--json] \u641C\u7D22\u5E76\u9010\u540E\u7AEF\u62A5\u544A\u7ED3\u679C",
|
|
13
|
+
" rivet web fetch <url> [--json] \u6293\u53D6 URL \u8F6C markdown",
|
|
14
|
+
" rivet web status [--json] \u6253\u5370 web \u914D\u7F6E\u751F\u6548\u72B6\u6001",
|
|
15
|
+
"",
|
|
16
|
+
"\u793A\u4F8B\uFF1A",
|
|
17
|
+
' rivet web search "GLM-5.2 \u53D1\u5E03"',
|
|
18
|
+
" rivet web fetch https://example.com",
|
|
19
|
+
" rivet web status"
|
|
20
|
+
].join("\n");
|
|
21
|
+
async function runWebCLI(args, ctx = {}) {
|
|
22
|
+
const write = ctx.write ?? ((s) => process.stdout.write(s));
|
|
23
|
+
const sub = args[0];
|
|
24
|
+
if (!sub || sub === "-h" || sub === "--help") {
|
|
25
|
+
write(USAGE + "\n");
|
|
26
|
+
return sub ? 0 : 1;
|
|
27
|
+
}
|
|
28
|
+
const { loadConfig } = await import("./manager-ROZBCWPA.js");
|
|
29
|
+
const config = loadConfig({ cwd: ctx.cwd ?? process.cwd() });
|
|
30
|
+
switch (sub) {
|
|
31
|
+
case "search":
|
|
32
|
+
return runSearch(args.slice(1), config, write);
|
|
33
|
+
case "fetch":
|
|
34
|
+
return runFetch(args.slice(1), config, write);
|
|
35
|
+
case "status":
|
|
36
|
+
return runStatus(args.slice(1), config, write);
|
|
37
|
+
default:
|
|
38
|
+
write(`\u672A\u77E5\u5B50\u547D\u4EE4: "${sub}"
|
|
39
|
+
|
|
40
|
+
${USAGE}
|
|
41
|
+
`);
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function runSearch(args, config, write) {
|
|
46
|
+
const json = args.includes("--json");
|
|
47
|
+
const countIdx = args.indexOf("--count");
|
|
48
|
+
const count = countIdx >= 0 && args[countIdx + 1] ? clampInt(args[countIdx + 1], 1, 20, 10) : 10;
|
|
49
|
+
const query = args.filter((a) => !a.startsWith("-") && a !== "--json").join(" ").trim();
|
|
50
|
+
if (!query) {
|
|
51
|
+
write("\u7528\u6CD5: rivet web search <query> [--count N] [--json]\n");
|
|
52
|
+
return 1;
|
|
53
|
+
}
|
|
54
|
+
const { buildSearchBackends } = await import("./build-backends-5KXKR2S4.js");
|
|
55
|
+
const { runBackendChain } = await import("./chain-7MAMFXZ3.js");
|
|
56
|
+
const { resolveProxyForUrl } = await import("./proxy-resolver-V2Y6534D.js");
|
|
57
|
+
const proxyOpts = {
|
|
58
|
+
...config.network.proxy ? { proxyUrl: config.network.proxy } : {},
|
|
59
|
+
...config.network.noProxy ? { noProxy: config.network.noProxy } : {}
|
|
60
|
+
};
|
|
61
|
+
const backends = buildSearchBackends(config, { proxy: proxyOpts });
|
|
62
|
+
const timeoutMs = config.search.timeoutMs;
|
|
63
|
+
const result = await runBackendChain(backends, query, count, timeoutMs);
|
|
64
|
+
if (json) {
|
|
65
|
+
write(JSON.stringify({
|
|
66
|
+
query,
|
|
67
|
+
count,
|
|
68
|
+
backend: result.backend,
|
|
69
|
+
results: result.results,
|
|
70
|
+
errors: result.errors,
|
|
71
|
+
proxy: resolveProxyForUrl("https://example.com", proxyOpts) ?? null
|
|
72
|
+
}, null, 2) + "\n");
|
|
73
|
+
return result.results.length > 0 ? 0 : 1;
|
|
74
|
+
}
|
|
75
|
+
const lines = [];
|
|
76
|
+
lines.push(`\u641C\u7D22\uFF1A\u300C${query}\u300D`);
|
|
77
|
+
const proxy = resolveProxyForUrl("https://example.com", proxyOpts);
|
|
78
|
+
lines.push(`\u4EE3\u7406\uFF1A${proxy ?? "\u76F4\u8FDE"}`);
|
|
79
|
+
lines.push("");
|
|
80
|
+
if (result.errors.length > 0) {
|
|
81
|
+
lines.push("\u540E\u7AEF\u94FE\u8DEF\uFF1A");
|
|
82
|
+
for (const e of result.errors) {
|
|
83
|
+
lines.push(` \u2717 ${e.backend}: ${e.message}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (result.backend) {
|
|
87
|
+
lines.push(` \u2713 ${result.backend} \u547D\u4E2D ${result.results.length} \u6761`);
|
|
88
|
+
}
|
|
89
|
+
lines.push("");
|
|
90
|
+
if (result.results.length === 0) {
|
|
91
|
+
lines.push("\u672A\u627E\u5230\u7ED3\u679C\uFF08\u6240\u6709\u540E\u7AEF\u5747\u65E0\u7ED3\u679C\u6216\u5931\u8D25\uFF09\u3002");
|
|
92
|
+
write(lines.join("\n") + "\n");
|
|
93
|
+
return 1;
|
|
94
|
+
}
|
|
95
|
+
for (let i = 0; i < result.results.length; i++) {
|
|
96
|
+
const r = result.results[i];
|
|
97
|
+
lines.push(`${i + 1}. ${r.title}`);
|
|
98
|
+
lines.push(` ${r.url}`);
|
|
99
|
+
if (r.snippet) lines.push(` ${r.snippet}`);
|
|
100
|
+
lines.push("");
|
|
101
|
+
}
|
|
102
|
+
write(lines.join("\n") + "\n");
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
async function runFetch(args, config, write) {
|
|
106
|
+
const json = args.includes("--json");
|
|
107
|
+
const url = args.find((a) => !a.startsWith("-") && a !== "--json");
|
|
108
|
+
if (!url) {
|
|
109
|
+
write("\u7528\u6CD5: rivet web fetch <url> [--json]\n");
|
|
110
|
+
return 1;
|
|
111
|
+
}
|
|
112
|
+
const { fetchMarkdown } = await import("./fetch-core-ZPPYDSZH.js");
|
|
113
|
+
const { buildFetchOptions } = await import("./build-options-66Y4ZE7C.js");
|
|
114
|
+
const opts = { ...buildFetchOptions(config), cwd: process.cwd() };
|
|
115
|
+
const outcome = await fetchMarkdown(url, {}, opts);
|
|
116
|
+
if (json) {
|
|
117
|
+
write(JSON.stringify(outcome, null, 2) + "\n");
|
|
118
|
+
return outcome.ok ? 0 : 1;
|
|
119
|
+
}
|
|
120
|
+
if (!outcome.ok) {
|
|
121
|
+
write(`\u6293\u53D6\u5931\u8D25\uFF1A${outcome.error}
|
|
122
|
+
`);
|
|
123
|
+
return 1;
|
|
124
|
+
}
|
|
125
|
+
const via = outcome.via ? ` ${outcome.via}` : "";
|
|
126
|
+
const cache = outcome.fromCache ? "\uFF08\u7F13\u5B58\uFF09" : "";
|
|
127
|
+
write(`URL\uFF1A${url}
|
|
128
|
+
\u72B6\u6001\uFF1A${outcome.status}${cache}${via}
|
|
129
|
+
\u957F\u5EA6\uFF1A${outcome.markdown.length}
|
|
130
|
+
|
|
131
|
+
`);
|
|
132
|
+
const MAX = 5e4;
|
|
133
|
+
const body = outcome.markdown.length > MAX ? outcome.markdown.slice(0, MAX) + `
|
|
134
|
+
|
|
135
|
+
\u2026\uFF08\u5DF2\u622A\u65AD\uFF0C\u5171 ${outcome.markdown.length} \u5B57\u7B26\uFF09` : outcome.markdown;
|
|
136
|
+
write(body + "\n");
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
async function runStatus(args, config, write) {
|
|
140
|
+
const json = args.includes("--json");
|
|
141
|
+
const { resolveProxyForUrl } = await import("./proxy-resolver-V2Y6534D.js");
|
|
142
|
+
const { buildSearchBackends } = await import("./build-backends-5KXKR2S4.js");
|
|
143
|
+
const proxyOpts = {
|
|
144
|
+
...config.network.proxy ? { proxyUrl: config.network.proxy } : {},
|
|
145
|
+
...config.network.noProxy ? { noProxy: config.network.noProxy } : {}
|
|
146
|
+
};
|
|
147
|
+
const proxy = resolveProxyForUrl("https://example.com", proxyOpts);
|
|
148
|
+
const proxySource = config.network.proxy ? "config (network.proxy)" : process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy ? "env (HTTPS_PROXY/HTTP_PROXY)" : proxy ? "system (OS)" : "direct\uFF08\u76F4\u8FDE\uFF09";
|
|
149
|
+
const backends = buildSearchBackends(config, { proxy: proxyOpts });
|
|
150
|
+
const backendStatus = backends.map((b) => ({
|
|
151
|
+
name: b.name,
|
|
152
|
+
available: b.isAvailable()
|
|
153
|
+
}));
|
|
154
|
+
const status = {
|
|
155
|
+
proxy: { url: proxy ?? null, source: proxySource },
|
|
156
|
+
noProxy: config.network.noProxy ?? null,
|
|
157
|
+
search: {
|
|
158
|
+
backends: config.search.backends,
|
|
159
|
+
timeoutMs: config.search.timeoutMs,
|
|
160
|
+
region: config.search.region ?? null,
|
|
161
|
+
backendStatus
|
|
162
|
+
},
|
|
163
|
+
fetch: {
|
|
164
|
+
jinaBaseUrl: config.fetch.jinaBaseUrl,
|
|
165
|
+
enablePlaywright: config.fetch.enablePlaywright,
|
|
166
|
+
userAgent: config.fetch.userAgent,
|
|
167
|
+
timeoutMs: config.fetch.timeoutMs
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
if (json) {
|
|
171
|
+
write(JSON.stringify(status, null, 2) + "\n");
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
const lines = [];
|
|
175
|
+
lines.push("\u2550\u2550\u2550 Web \u5DE5\u5177\u914D\u7F6E\u751F\u6548\u72B6\u6001 \u2550\u2550\u2550");
|
|
176
|
+
lines.push("");
|
|
177
|
+
lines.push("\u2500\u2500 \u4EE3\u7406 \u2500\u2500");
|
|
178
|
+
lines.push(` \u5730\u5740\uFF1A${proxy ?? "\uFF08\u76F4\u8FDE\uFF09"}`);
|
|
179
|
+
lines.push(` \u6765\u6E90\uFF1A${proxySource}`);
|
|
180
|
+
if (config.network.noProxy) lines.push(` NO_PROXY\uFF1A${config.network.noProxy}`);
|
|
181
|
+
lines.push("");
|
|
182
|
+
lines.push("\u2500\u2500 web_search \u540E\u7AEF\u94FE \u2500\u2500");
|
|
183
|
+
for (const b of backendStatus) {
|
|
184
|
+
const mark = b.available ? "\u2713" : "\u2717";
|
|
185
|
+
const note = b.available ? "\u53EF\u7528" : "\u4E0D\u53EF\u7528\uFF08\u7F3A API key \u6216\u672A\u914D\u7F6E\uFF09";
|
|
186
|
+
lines.push(` ${mark} ${b.name} \u2014 ${note}`);
|
|
187
|
+
}
|
|
188
|
+
lines.push(` \u8D85\u65F6\uFF1A${config.search.timeoutMs}ms`);
|
|
189
|
+
if (config.search.region) lines.push(` \u533A\u57DF\uFF1A${config.search.region}`);
|
|
190
|
+
lines.push("");
|
|
191
|
+
lines.push("\u2500\u2500 web_fetch \u2500\u2500");
|
|
192
|
+
lines.push(` Jina Reader\uFF1A${config.fetch.jinaBaseUrl}`);
|
|
193
|
+
lines.push(` Playwright \u6E32\u67D3\uFF1A${config.fetch.enablePlaywright ? "\u5F00" : "\u5173"}`);
|
|
194
|
+
lines.push(` User-Agent\uFF1A${config.fetch.userAgent}`);
|
|
195
|
+
lines.push(` \u8D85\u65F6\uFF1A${config.fetch.timeoutMs}ms`);
|
|
196
|
+
lines.push("");
|
|
197
|
+
lines.push("\u63D0\u793A\uFF1A\u7528 `rivet web search <query>` / `rivet web fetch <url>` \u5B9E\u6D4B\u8FDE\u901A\u6027\u3002");
|
|
198
|
+
write(lines.join("\n") + "\n");
|
|
199
|
+
return 0;
|
|
200
|
+
}
|
|
201
|
+
function clampInt(raw, min, max, fallback) {
|
|
202
|
+
const n = Number.parseInt(raw, 10);
|
|
203
|
+
if (!Number.isFinite(n)) return fallback;
|
|
204
|
+
return Math.min(Math.max(n, min), max);
|
|
205
|
+
}
|
|
206
|
+
function formatSearchResultText(query, result, proxy) {
|
|
207
|
+
const lines = [];
|
|
208
|
+
lines.push(`\u641C\u7D22\uFF1A\u300C${query}\u300D`);
|
|
209
|
+
lines.push(`\u4EE3\u7406\uFF1A${proxy ?? "\u76F4\u8FDE"}`);
|
|
210
|
+
lines.push("");
|
|
211
|
+
if (result.errors.length > 0) {
|
|
212
|
+
lines.push("\u540E\u7AEF\u94FE\u8DEF\uFF1A");
|
|
213
|
+
for (const e of result.errors) lines.push(` \u2717 ${e.backend}: ${e.message}`);
|
|
214
|
+
}
|
|
215
|
+
if (result.backend) lines.push(` \u2713 ${result.backend} \u547D\u4E2D ${result.results.length} \u6761`);
|
|
216
|
+
lines.push("");
|
|
217
|
+
if (result.results.length === 0) {
|
|
218
|
+
lines.push("\u672A\u627E\u5230\u7ED3\u679C\uFF08\u6240\u6709\u540E\u7AEF\u5747\u65E0\u7ED3\u679C\u6216\u5931\u8D25\uFF09\u3002");
|
|
219
|
+
return lines.join("\n");
|
|
220
|
+
}
|
|
221
|
+
for (let i = 0; i < result.results.length; i++) {
|
|
222
|
+
const r = result.results[i];
|
|
223
|
+
lines.push(`${i + 1}. ${r.title}`);
|
|
224
|
+
lines.push(` ${r.url}`);
|
|
225
|
+
if (r.snippet) lines.push(` ${r.snippet}`);
|
|
226
|
+
lines.push("");
|
|
227
|
+
}
|
|
228
|
+
return lines.join("\n");
|
|
229
|
+
}
|
|
230
|
+
export {
|
|
231
|
+
formatSearchResultText,
|
|
232
|
+
runWebCLI
|
|
233
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
WEB_SEARCH_TOOL,
|
|
5
|
+
createWebSearchTool
|
|
6
|
+
} from "./chunk-JRF5L6OD.js";
|
|
7
|
+
import {
|
|
8
|
+
runBackendChain
|
|
9
|
+
} from "./chunk-EBJTVRQN.js";
|
|
10
|
+
import {
|
|
11
|
+
BingBackend,
|
|
12
|
+
BraveBackend,
|
|
13
|
+
DuckDuckGoBackend,
|
|
14
|
+
TavilyBackend,
|
|
15
|
+
buildSearchBackends,
|
|
16
|
+
decodeHtmlEntities,
|
|
17
|
+
parseDuckDuckGoResults
|
|
18
|
+
} from "./chunk-J4U4AW46.js";
|
|
19
|
+
import "./chunk-2HDP7RMR.js";
|
|
20
|
+
import "./chunk-O5VZQKCB.js";
|
|
21
|
+
import "./chunk-BKTQAYO2.js";
|
|
22
|
+
import "./chunk-5GGOGLSN.js";
|
|
23
|
+
export {
|
|
24
|
+
BingBackend,
|
|
25
|
+
BraveBackend,
|
|
26
|
+
DuckDuckGoBackend,
|
|
27
|
+
TavilyBackend,
|
|
28
|
+
WEB_SEARCH_TOOL,
|
|
29
|
+
buildSearchBackends,
|
|
30
|
+
createWebSearchTool,
|
|
31
|
+
decodeHtmlEntities,
|
|
32
|
+
parseDuckDuckGoResults,
|
|
33
|
+
runBackendChain
|
|
34
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
astEditComputeRaw,
|
|
5
|
+
astScanRaw,
|
|
6
|
+
diffLinesRaw,
|
|
7
|
+
diffStructuredRaw,
|
|
8
|
+
diffUnifiedRaw,
|
|
9
|
+
esbuildTransformRaw,
|
|
10
|
+
parseEventsJsonlRaw,
|
|
11
|
+
parseEventsTailRaw
|
|
12
|
+
} from "../chunk-EGEI2RQA.js";
|
|
13
|
+
import {
|
|
14
|
+
init_esm_shims
|
|
15
|
+
} from "../chunk-5GGOGLSN.js";
|
|
16
|
+
|
|
17
|
+
// src/workers/cpu-worker.ts
|
|
18
|
+
init_esm_shims();
|
|
19
|
+
import { parentPort } from "worker_threads";
|
|
20
|
+
var tasks = {
|
|
21
|
+
diffUnifiedRaw,
|
|
22
|
+
diffStructuredRaw,
|
|
23
|
+
diffLinesRaw,
|
|
24
|
+
parseEventsJsonlRaw,
|
|
25
|
+
parseEventsTailRaw,
|
|
26
|
+
esbuildTransformRaw,
|
|
27
|
+
astScanRaw,
|
|
28
|
+
astEditComputeRaw
|
|
29
|
+
};
|
|
30
|
+
parentPort?.on("message", (msg) => {
|
|
31
|
+
const fn = tasks[msg.task];
|
|
32
|
+
if (!fn) {
|
|
33
|
+
parentPort?.postMessage({ id: msg.id, ok: false, error: `unknown task: ${msg.task}` });
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
Promise.resolve().then(() => fn(...msg.args)).then((result) => {
|
|
37
|
+
parentPort?.postMessage({ id: msg.id, ok: true, result });
|
|
38
|
+
}).catch((err) => {
|
|
39
|
+
parentPort?.postMessage({
|
|
40
|
+
id: msg.id,
|
|
41
|
+
ok: false,
|
|
42
|
+
error: err instanceof Error ? err.message : String(err)
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,297 @@
|
|
|
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_paths,
|
|
5
|
+
workflowsDir
|
|
6
|
+
} from "./chunk-BCQXEZPJ.js";
|
|
7
|
+
import {
|
|
8
|
+
init_esm_shims
|
|
9
|
+
} from "./chunk-5GGOGLSN.js";
|
|
10
|
+
|
|
11
|
+
// src/agent/workflow-runner.ts
|
|
12
|
+
init_esm_shims();
|
|
13
|
+
init_paths();
|
|
14
|
+
import { readFileSync, existsSync, readdirSync, mkdirSync, writeFileSync } from "fs";
|
|
15
|
+
import { join } from "path";
|
|
16
|
+
var WORKFLOWS_DIR = ".rivet/workflows";
|
|
17
|
+
var TRACES_DIR = ".rivet/traces";
|
|
18
|
+
function parseWorkflow(yaml) {
|
|
19
|
+
const lines = yaml.split("\n");
|
|
20
|
+
const def = { name: "", steps: [] };
|
|
21
|
+
let currentStep = null;
|
|
22
|
+
let inInputs = false;
|
|
23
|
+
for (const rawLine of lines) {
|
|
24
|
+
const line = rawLine.replace(/\r$/, "");
|
|
25
|
+
if (!line.trim() || line.trim().startsWith("#")) continue;
|
|
26
|
+
const nameMatch = line.match(/^name:\s*(.+)$/);
|
|
27
|
+
if (nameMatch) {
|
|
28
|
+
def.name = nameMatch[1].trim();
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const descMatch = line.match(/^description:\s*(.+)$/);
|
|
32
|
+
if (descMatch) {
|
|
33
|
+
def.description = descMatch[1].trim();
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (/^inputs:\s*$/.test(line)) {
|
|
37
|
+
inInputs = true;
|
|
38
|
+
def.inputs = {};
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (inInputs && /^[a-z]/.test(line.trim()) && !line.startsWith(" ")) {
|
|
42
|
+
inInputs = false;
|
|
43
|
+
}
|
|
44
|
+
if (inInputs) {
|
|
45
|
+
const m = line.trim().match(/^(\w+):\s*(.+)$/);
|
|
46
|
+
if (m) def.inputs[m[1]] = m[2].trim();
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (/^steps:\s*$/.test(line)) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const stepMatch = line.match(/^\s*- (?:id:\s*)?(\w+)/);
|
|
53
|
+
if (stepMatch) {
|
|
54
|
+
if (currentStep) def.steps.push(currentStep);
|
|
55
|
+
currentStep = { id: stepMatch[1], tool: "", input: {} };
|
|
56
|
+
const toolOnSameLine = line.match(/tool:\s*(\S+)/);
|
|
57
|
+
if (toolOnSameLine) currentStep.tool = toolOnSameLine[1].replace(/['"]/g, "");
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (currentStep && line.startsWith(" ")) {
|
|
61
|
+
const trimmed = line.trim();
|
|
62
|
+
const toolMatch = trimmed.match(/^tool:\s*(.+)$/);
|
|
63
|
+
if (toolMatch) {
|
|
64
|
+
currentStep.tool = toolMatch[1].trim().replace(/['"]/g, "");
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const dependsMatch = trimmed.match(/^depends_on:\s*\[(.*)\]$/);
|
|
68
|
+
if (dependsMatch) {
|
|
69
|
+
currentStep.depends_on = dependsMatch[1].split(",").map((s) => s.trim().replace(/['"]/g, "")).filter(Boolean);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const onFailureMatch = trimmed.match(/^on_failure:\s*(.+)$/);
|
|
73
|
+
if (onFailureMatch) {
|
|
74
|
+
currentStep.on_failure = onFailureMatch[1].trim().replace(/['"]/g, "");
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const conditionMatch = trimmed.match(/^condition:\s*(.+)$/);
|
|
78
|
+
if (conditionMatch) {
|
|
79
|
+
currentStep.condition = conditionMatch[1].trim();
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const inputMatch = trimmed.match(/^(\w+):\s*(.*)$/);
|
|
83
|
+
if (inputMatch) {
|
|
84
|
+
const key = inputMatch[1];
|
|
85
|
+
let val = inputMatch[2].trim().replace(/^["']|["']$/g, "");
|
|
86
|
+
if (val === "true") val = true;
|
|
87
|
+
else if (val === "false") val = false;
|
|
88
|
+
else if (/^\d+$/.test(val)) val = parseInt(val, 10);
|
|
89
|
+
if (!currentStep.input) currentStep.input = {};
|
|
90
|
+
currentStep.input[key] = val;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (currentStep) def.steps.push(currentStep);
|
|
95
|
+
if (!def.name) throw new Error("Workflow must have a name");
|
|
96
|
+
if (def.steps.length === 0) throw new Error("Workflow must have at least one step");
|
|
97
|
+
for (const s of def.steps) {
|
|
98
|
+
if (!s.tool) throw new Error(`Step "${s.id}" must have a tool`);
|
|
99
|
+
}
|
|
100
|
+
return def;
|
|
101
|
+
}
|
|
102
|
+
function resolveVars(value, ctx) {
|
|
103
|
+
if (typeof value === "string") {
|
|
104
|
+
return value.replace(/\$\{([^}]+)\}/g, (match, ref) => {
|
|
105
|
+
const parts = ref.split(".");
|
|
106
|
+
if (parts.length === 1) {
|
|
107
|
+
const val = ctx.inputs[parts[0]];
|
|
108
|
+
return val !== void 0 ? String(val) : match;
|
|
109
|
+
}
|
|
110
|
+
const [stepId, ...fieldParts] = parts;
|
|
111
|
+
const stepResult = ctx.stepResults[stepId];
|
|
112
|
+
if (!stepResult) return match;
|
|
113
|
+
const fieldVal = fieldParts.reduce((acc, k) => acc && typeof acc === "object" ? acc[k] : void 0, stepResult);
|
|
114
|
+
return fieldVal !== void 0 ? String(fieldVal) : match;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (Array.isArray(value)) return value.map((v) => resolveVars(v, ctx));
|
|
118
|
+
if (value && typeof value === "object") {
|
|
119
|
+
const result = {};
|
|
120
|
+
for (const [k, v] of Object.entries(value)) result[k] = resolveVars(v, ctx);
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
function topoSort(steps) {
|
|
126
|
+
const sorted = [];
|
|
127
|
+
const visited = /* @__PURE__ */ new Set();
|
|
128
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
129
|
+
function visit(step) {
|
|
130
|
+
if (visited.has(step.id)) return;
|
|
131
|
+
if (visiting.has(step.id)) throw new Error(`Circular dependency at step "${step.id}"`);
|
|
132
|
+
visiting.add(step.id);
|
|
133
|
+
for (const depId of step.depends_on ?? []) {
|
|
134
|
+
const dep = steps.find((s) => s.id === depId);
|
|
135
|
+
if (!dep) throw new Error(`Step "${step.id}" depends on unknown step "${depId}"`);
|
|
136
|
+
visit(dep);
|
|
137
|
+
}
|
|
138
|
+
visiting.delete(step.id);
|
|
139
|
+
visited.add(step.id);
|
|
140
|
+
sorted.push(step);
|
|
141
|
+
}
|
|
142
|
+
for (const s of steps) visit(s);
|
|
143
|
+
return sorted;
|
|
144
|
+
}
|
|
145
|
+
async function runWorkflow(def, inputs, cwd, executor, onProgress) {
|
|
146
|
+
const MAX_RETRIES = 3;
|
|
147
|
+
const traceId = `wf-${def.name}-${Date.now().toString(36)}`;
|
|
148
|
+
const trace = {
|
|
149
|
+
workflowName: def.name,
|
|
150
|
+
traceId,
|
|
151
|
+
startedAt: Date.now(),
|
|
152
|
+
inputs,
|
|
153
|
+
steps: [],
|
|
154
|
+
finalStatus: "pending"
|
|
155
|
+
};
|
|
156
|
+
const ctx = { inputs, stepResults: {}, cwd, onProgress };
|
|
157
|
+
const ordered = topoSort(def.steps);
|
|
158
|
+
let i = 0;
|
|
159
|
+
let retries = 0;
|
|
160
|
+
while (i < ordered.length) {
|
|
161
|
+
const step = ordered[i];
|
|
162
|
+
const stepTrace = {
|
|
163
|
+
stepId: step.id,
|
|
164
|
+
tool: step.tool,
|
|
165
|
+
status: "running",
|
|
166
|
+
startedAt: Date.now()
|
|
167
|
+
};
|
|
168
|
+
if (step.condition) {
|
|
169
|
+
const resolvedCondition = resolveVars(step.condition, ctx);
|
|
170
|
+
if (resolvedCondition === "false" || resolvedCondition === false) {
|
|
171
|
+
stepTrace.status = "skipped";
|
|
172
|
+
stepTrace.endedAt = Date.now();
|
|
173
|
+
trace.steps.push(stepTrace);
|
|
174
|
+
onProgress?.(step.id, "skipped");
|
|
175
|
+
i++;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
onProgress?.(step.id, "running");
|
|
180
|
+
const resolvedInput = resolveVars(step.input ?? {}, ctx);
|
|
181
|
+
try {
|
|
182
|
+
stepTrace.input = resolvedInput;
|
|
183
|
+
const result = await executor(step.tool, resolvedInput, ctx);
|
|
184
|
+
stepTrace.output = result.output?.slice(0, 2e3);
|
|
185
|
+
stepTrace.error = result.error;
|
|
186
|
+
stepTrace.status = result.error ? "failed" : "done";
|
|
187
|
+
stepTrace.endedAt = Date.now();
|
|
188
|
+
stepTrace.durationMs = stepTrace.endedAt - stepTrace.startedAt;
|
|
189
|
+
ctx.stepResults[step.id] = { output: result.output, ...result.error ? { error: result.error } : {} };
|
|
190
|
+
trace.steps.push(stepTrace);
|
|
191
|
+
onProgress?.(step.id, stepTrace.status);
|
|
192
|
+
if (result.error && step.on_failure && retries < MAX_RETRIES) {
|
|
193
|
+
const targetIdx = ordered.findIndex((s) => s.id === step.on_failure);
|
|
194
|
+
if (targetIdx >= 0) {
|
|
195
|
+
retries++;
|
|
196
|
+
i = targetIdx;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (result.error) {
|
|
201
|
+
trace.finalStatus = "failed";
|
|
202
|
+
trace.endedAt = Date.now();
|
|
203
|
+
trace.totalDurationMs = trace.endedAt - trace.startedAt;
|
|
204
|
+
return trace;
|
|
205
|
+
}
|
|
206
|
+
} catch (err) {
|
|
207
|
+
stepTrace.status = "failed";
|
|
208
|
+
stepTrace.error = err instanceof Error ? err.message : String(err);
|
|
209
|
+
stepTrace.endedAt = Date.now();
|
|
210
|
+
stepTrace.durationMs = stepTrace.endedAt - stepTrace.startedAt;
|
|
211
|
+
trace.steps.push(stepTrace);
|
|
212
|
+
onProgress?.(step.id, "failed");
|
|
213
|
+
trace.finalStatus = "failed";
|
|
214
|
+
trace.endedAt = Date.now();
|
|
215
|
+
trace.totalDurationMs = trace.endedAt - trace.startedAt;
|
|
216
|
+
return trace;
|
|
217
|
+
}
|
|
218
|
+
i++;
|
|
219
|
+
}
|
|
220
|
+
const lastByStep = /* @__PURE__ */ new Map();
|
|
221
|
+
for (const s of trace.steps) lastByStep.set(s.stepId, s);
|
|
222
|
+
trace.finalStatus = [...lastByStep.values()].every((s) => s.status === "done" || s.status === "skipped") ? "done" : "failed";
|
|
223
|
+
trace.endedAt = Date.now();
|
|
224
|
+
trace.totalDurationMs = trace.endedAt - trace.startedAt;
|
|
225
|
+
return trace;
|
|
226
|
+
}
|
|
227
|
+
function loadWorkflow(cwd, name) {
|
|
228
|
+
const paths = [
|
|
229
|
+
join(cwd, WORKFLOWS_DIR, `${name}.yaml`),
|
|
230
|
+
join(cwd, WORKFLOWS_DIR, `${name}.yml`),
|
|
231
|
+
join(workflowsDir(), `${name}.yaml`)
|
|
232
|
+
];
|
|
233
|
+
for (const p of paths) {
|
|
234
|
+
if (existsSync(p)) return parseWorkflow(readFileSync(p, "utf-8"));
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
function listWorkflows(cwd) {
|
|
239
|
+
const names = /* @__PURE__ */ new Set();
|
|
240
|
+
for (const dir of [join(cwd, WORKFLOWS_DIR), workflowsDir()]) {
|
|
241
|
+
if (existsSync(dir)) {
|
|
242
|
+
for (const f of readdirSync(dir)) {
|
|
243
|
+
if (f.endsWith(".yaml") || f.endsWith(".yml")) names.add(f.replace(/\.ya?ml$/, ""));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return [...names].sort();
|
|
248
|
+
}
|
|
249
|
+
function saveTrace(cwd, trace) {
|
|
250
|
+
const dir = join(cwd, TRACES_DIR);
|
|
251
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
252
|
+
writeFileSync(join(dir, `${trace.traceId}.json`), JSON.stringify(trace, null, 2), "utf-8");
|
|
253
|
+
}
|
|
254
|
+
function loadTrace(cwd, traceId) {
|
|
255
|
+
const p = join(cwd, TRACES_DIR, `${traceId}.json`);
|
|
256
|
+
if (!existsSync(p)) return null;
|
|
257
|
+
return JSON.parse(readFileSync(p, "utf-8"));
|
|
258
|
+
}
|
|
259
|
+
function listTraces(cwd, limit = 10) {
|
|
260
|
+
const dir = join(cwd, TRACES_DIR);
|
|
261
|
+
if (!existsSync(dir)) return [];
|
|
262
|
+
return readdirSync(dir).filter((f) => f.endsWith(".json")).map((f) => {
|
|
263
|
+
try {
|
|
264
|
+
return JSON.parse(readFileSync(join(dir, f), "utf-8"));
|
|
265
|
+
} catch {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
}).filter((t) => t !== null).sort((a, b) => b.startedAt - a.startedAt).slice(0, limit);
|
|
269
|
+
}
|
|
270
|
+
function formatTrace(trace) {
|
|
271
|
+
const lines = [
|
|
272
|
+
`Workflow: ${trace.workflowName} (${trace.traceId})`,
|
|
273
|
+
`Status: ${trace.finalStatus} Duration: ${trace.totalDurationMs ? `${(trace.totalDurationMs / 1e3).toFixed(1)}s` : "\u2014"}`,
|
|
274
|
+
`Started: ${new Date(trace.startedAt).toLocaleString()}`,
|
|
275
|
+
"",
|
|
276
|
+
"Steps:"
|
|
277
|
+
];
|
|
278
|
+
for (const s of trace.steps) {
|
|
279
|
+
const glyph = s.status === "done" ? "\u2713" : s.status === "failed" ? "\u2717" : s.status === "skipped" ? "\u2298" : s.status === "running" ? "\u25D0" : "\u25CC";
|
|
280
|
+
const dur = s.durationMs ? `${(s.durationMs / 1e3).toFixed(1)}s` : "\u2014";
|
|
281
|
+
lines.push(` ${glyph} ${s.stepId} (${s.tool}) ${dur}`);
|
|
282
|
+
if (s.error) lines.push(` error: ${s.error}`);
|
|
283
|
+
}
|
|
284
|
+
return lines.join("\n");
|
|
285
|
+
}
|
|
286
|
+
export {
|
|
287
|
+
formatTrace,
|
|
288
|
+
listTraces,
|
|
289
|
+
listWorkflows,
|
|
290
|
+
loadTrace,
|
|
291
|
+
loadWorkflow,
|
|
292
|
+
parseWorkflow,
|
|
293
|
+
resolveVars,
|
|
294
|
+
runWorkflow,
|
|
295
|
+
saveTrace,
|
|
296
|
+
topoSort
|
|
297
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
createWorktreeBaseline
|
|
5
|
+
} from "./chunk-D2TCGRSX.js";
|
|
6
|
+
import "./chunk-5GGOGLSN.js";
|
|
7
|
+
export {
|
|
8
|
+
createWorktreeBaseline
|
|
9
|
+
};
|