@herbertgao/pi-extensions 2026.11.13 → 2026.11.15
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/CHANGELOG.md +22 -0
- package/README.md +7 -7
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +3 -2
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +3 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/config.ts +5 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +9 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/index.ts +32 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/markdown-enhance.ts +26 -21
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/table-copy.ts +753 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/utils/fullscreen-detect.ts +11 -0
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +4 -4
- package/node_modules/@herbertgao/pi-inline-skill-commands/README.md +6 -2
- package/node_modules/@herbertgao/pi-inline-skill-commands/package.json +1 -1
- package/node_modules/@herbertgao/pi-inline-skill-commands/src/index.ts +41 -15
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +16 -0
- package/node_modules/@herbertgao/pi-subagents/README.md +54 -22
- package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +114 -35
- package/node_modules/@herbertgao/pi-subagents/package.json +9 -4
- package/node_modules/@herbertgao/pi-subagents/skills/workflow-authoring/SKILL.md +147 -0
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +48 -32
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +34 -13
- package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +88 -0
- package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +16 -6
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +114 -98
- package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +6 -2
- package/node_modules/@herbertgao/pi-subagents/src/mention.ts +5 -7
- package/node_modules/@herbertgao/pi-subagents/src/nested-tools.ts +18 -2
- package/node_modules/@herbertgao/pi-subagents/src/prompts.ts +25 -3
- package/node_modules/@herbertgao/pi-subagents/src/settings.ts +26 -0
- package/node_modules/@herbertgao/pi-subagents/src/structured-output.ts +13 -5
- package/node_modules/@herbertgao/pi-subagents/src/ui/fleet-list.ts +55 -8
- package/node_modules/@herbertgao/pi-subagents/src/ui/workflow-card-redraw.ts +86 -0
- package/node_modules/@herbertgao/pi-subagents/src/ui/workflow-card.ts +5 -5
- package/node_modules/@herbertgao/pi-subagents/src/ui/workflow-dialog.ts +478 -115
- package/node_modules/@herbertgao/pi-subagents/src/ui/workflow-menu.ts +77 -6
- package/node_modules/@herbertgao/pi-subagents/src/workflow/agent-detail.ts +148 -0
- package/node_modules/@herbertgao/pi-subagents/src/workflow/host.ts +88 -14
- package/node_modules/@herbertgao/pi-subagents/src/workflow/journal.ts +8 -0
- package/node_modules/@herbertgao/pi-subagents/src/workflow/json-schema.ts +507 -57
- package/node_modules/@herbertgao/pi-subagents/src/workflow/progress.ts +41 -11
- package/node_modules/@herbertgao/pi-subagents/src/workflow/runtime.ts +106 -34
- package/node_modules/@herbertgao/pi-subagents/src/workflow/task.ts +43 -5
- package/node_modules/@herbertgao/pi-subagents/src/workflow/tool-description.ts +93 -153
- package/node_modules/@herbertgao/pi-subagents/src/workflow/worker-source.ts +283 -71
- package/node_modules/@pi-plugins/fast-mode/dist/index.mjs +288 -177
- package/node_modules/@pi-plugins/fast-mode/dist/index.mjs.map +1 -1
- package/node_modules/@pi-plugins/fast-mode/package.json +7 -7
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +20 -0
- package/node_modules/pi-commandcode-provider/README.md +1 -1
- package/node_modules/pi-commandcode-provider/index.ts +2 -1
- package/node_modules/pi-commandcode-provider/package.json +1 -1
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +9 -2
- package/node_modules/pi-commandcode-provider/src/pricing.ts +5 -1
- package/node_modules/pi-commandcode-provider/src/responses-compat.ts +24 -1
- package/node_modules/pi-commandcode-provider/src/responses-stream.ts +99 -6
- package/node_modules/pi-lens/CHANGELOG-USER.md +6 -6
- package/node_modules/pi-lens/CHANGELOG.md +132 -0
- package/node_modules/pi-lens/README.md +2 -0
- package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +1 -0
- package/node_modules/pi-lens/dist/{chunk-LGH2HHZG.js → chunk-25CAONWT.js} +36 -25
- package/node_modules/pi-lens/dist/{chunk-ZQSSO7LO.js → chunk-2DWNYVUN.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-YCR6ZYTE.js → chunk-2RQREVGO.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-VWEBZ2JV.js → chunk-2XALJI2K.js} +40 -40
- package/node_modules/pi-lens/dist/{chunk-PQXUZYTQ.js → chunk-2YQ5LI7R.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-VSQT6IHZ.js → chunk-35UJUF27.js} +18 -4
- package/node_modules/pi-lens/dist/{chunk-OLWGYBYT.js → chunk-3IWMNN2S.js} +17 -17
- package/node_modules/pi-lens/dist/chunk-3UTDLQWO.js +88 -0
- package/node_modules/pi-lens/dist/chunk-3Z7Z3B7V.js +27 -0
- package/node_modules/pi-lens/dist/{chunk-UNP6Y4JV.js → chunk-4E4OCW3L.js} +16 -16
- package/node_modules/pi-lens/dist/{chunk-37IDWT6O.js → chunk-4GLSO2EM.js} +13 -11
- package/node_modules/pi-lens/dist/{chunk-QV3JPCMK.js → chunk-5HVDD7IA.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-ZRQMENT4.js → chunk-62PIU4TO.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-3TSMQZG6.js → chunk-6MDWNZ7E.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-WLD6BGON.js → chunk-6MWX2J5H.js} +4 -0
- package/node_modules/pi-lens/dist/{chunk-SCU62JLX.js → chunk-6MZLS6CK.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-B42AIWPJ.js → chunk-7BWPQZHE.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-I3NZVAMN.js → chunk-7JMEPY6P.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-7DPXUPRF.js → chunk-7ORBRDFY.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-6E5QLMWI.js → chunk-7WAQ3K26.js} +23 -23
- package/node_modules/pi-lens/dist/{chunk-2H5GHZKC.js → chunk-AB26NAHA.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-BBSDJTOV.js → chunk-AFSG6YUB.js} +13 -13
- package/node_modules/pi-lens/dist/{chunk-XDNWR7SG.js → chunk-ALTHJUZO.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-UN72ZAJ5.js → chunk-AOEVZXR6.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-HRLF35WL.js → chunk-ARTCVE6I.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-LQQNFCQJ.js → chunk-B2QO7GHY.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-I2FYOZNW.js → chunk-BJGWP4UX.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-G53LBDNU.js → chunk-BKJ6WZKP.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-P5MSLVUW.js → chunk-BQ72NQQM.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-K7O6AHSJ.js → chunk-BWGNVM33.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-ADYQRETD.js → chunk-BYIEU4E4.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-7ZVTFLCC.js → chunk-CDAJQBKJ.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-BKWFDWYM.js → chunk-D3UQWOCB.js} +16 -16
- package/node_modules/pi-lens/dist/{chunk-3PAS2ERX.js → chunk-DHFJS2I4.js} +8 -8
- package/node_modules/pi-lens/dist/{chunk-KNSOA43J.js → chunk-DKXIUGNA.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-LOEJFTF2.js → chunk-DLGJYQML.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-VGRGW4UL.js → chunk-DNJJVKJZ.js} +31 -31
- package/node_modules/pi-lens/dist/{chunk-5HBQL7DH.js → chunk-EBXCYEII.js} +3 -3
- package/node_modules/pi-lens/dist/chunk-EH6EHFW2.js +73 -0
- package/node_modules/pi-lens/dist/{chunk-W26QZ3OM.js → chunk-EKQDQPX6.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-TWEOJE3D.js → chunk-EXHSWN3P.js} +844 -377
- package/node_modules/pi-lens/dist/{chunk-4IZZEN63.js → chunk-F7BFIENK.js} +33 -33
- package/node_modules/pi-lens/dist/{chunk-ZI7YHV6I.js → chunk-FD4LJQ6Y.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-RIH3UBK4.js → chunk-GFCPPCNR.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-5JB4WENL.js → chunk-GIK6VUCY.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-PPQHMSPH.js → chunk-GNK2IHVG.js} +15 -15
- package/node_modules/pi-lens/dist/{chunk-CXQYK4YT.js → chunk-H6DNTQ4V.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-NGNBJIUO.js → chunk-HERQPNY6.js} +8 -8
- package/node_modules/pi-lens/dist/{chunk-INBK3HIT.js → chunk-HFIFEH46.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-J2ZB5MDS.js → chunk-HKRESBMC.js} +20 -20
- package/node_modules/pi-lens/dist/{chunk-AZG5UJYY.js → chunk-HMXWZUQW.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-XSC3BCN3.js → chunk-HOWHAKXO.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-7CLWC2UH.js → chunk-HUWW77QY.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-KZ732ZVW.js → chunk-IO6P3NBP.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-7WKVCZI4.js → chunk-J7VNGHLN.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-QE7BJQ6K.js → chunk-JGCBMCCS.js} +8 -8
- package/node_modules/pi-lens/dist/{chunk-PFJLYRO3.js → chunk-KIQSNH3F.js} +34 -34
- package/node_modules/pi-lens/dist/{chunk-JGUDT5KD.js → chunk-KSQJBGRO.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-RJ3APNIP.js → chunk-KXKM2DFP.js} +4 -4
- package/node_modules/pi-lens/dist/chunk-L3Q72QGQ.js +25 -0
- package/node_modules/pi-lens/dist/{chunk-6GLMMGCX.js → chunk-LDPY22FS.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-3PO4YYOX.js → chunk-M3QGXGY4.js} +3793 -3814
- package/node_modules/pi-lens/dist/{chunk-NNEQOC3U.js → chunk-MET776XM.js} +9 -7
- package/node_modules/pi-lens/dist/{chunk-X33QECRJ.js → chunk-MKQFSW2Q.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-7U36VQL6.js → chunk-MKW7ZUTT.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-PQF6YGYB.js → chunk-N2U644ZW.js} +4 -18
- package/node_modules/pi-lens/dist/{chunk-DI4AZZNY.js → chunk-NAACKIKT.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-O6LCSHHI.js → chunk-NHHS5T52.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-DCA2MXVQ.js → chunk-NIZKGBOU.js} +51 -27
- package/node_modules/pi-lens/dist/{chunk-PKWEBMCA.js → chunk-NNDZ7DOP.js} +194 -111
- package/node_modules/pi-lens/dist/{chunk-Q7J3JYJ2.js → chunk-NZ7NSKIW.js} +13 -13
- package/node_modules/pi-lens/dist/{chunk-S6MCMD27.js → chunk-OG3UCAHV.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-3QXFUP6T.js → chunk-OHTHVILU.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-NHA5K226.js → chunk-P7EV5ISR.js} +17 -2
- package/node_modules/pi-lens/dist/{chunk-L6BDRYUK.js → chunk-PVV27TOX.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-HIRBC72R.js → chunk-Q32RJDYC.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-QE5DJ7MX.js → chunk-Q4UQNTLB.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-SDYLT45T.js → chunk-QQGZY2BR.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-QMWKSYWB.js → chunk-S247BOH2.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-ARTYCUGF.js → chunk-S7KUDW73.js} +121 -18
- package/node_modules/pi-lens/dist/{chunk-6CFSDLHE.js → chunk-SJ2SR432.js} +17 -17
- package/node_modules/pi-lens/dist/{chunk-CQY2HEH7.js → chunk-SL4G67AP.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-LVLPA32Q.js → chunk-T2D2WWP6.js} +48 -11
- package/node_modules/pi-lens/dist/{chunk-HIJ4CHFF.js → chunk-T7KHGEJ5.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-74AMPWNC.js → chunk-TABDCX35.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-TFSBHRL2.js +25 -0
- package/node_modules/pi-lens/dist/{chunk-KNJH6WJQ.js → chunk-TQKWR5AZ.js} +7 -7
- package/node_modules/pi-lens/dist/chunk-TWAQFMLW.js +110 -0
- package/node_modules/pi-lens/dist/{chunk-TKOFTLGB.js → chunk-UARVPNAU.js} +33 -33
- package/node_modules/pi-lens/dist/chunk-UWBD3JMH.js +56 -0
- package/node_modules/pi-lens/dist/{chunk-K4Z7MK6T.js → chunk-VEF3GFOL.js} +15 -15
- package/node_modules/pi-lens/dist/{chunk-4DAHGU3V.js → chunk-W2JPGW7Q.js} +27 -25
- package/node_modules/pi-lens/dist/{chunk-CZJGAOKL.js → chunk-W2YHHNY3.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-R4L7KZ7R.js → chunk-WA6U2URH.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-OZQQ3AIR.js → chunk-WAK2AXQQ.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-DFKOA74L.js → chunk-WH6O4IFD.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-27JQHK7Y.js → chunk-WJ7GY5WJ.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-KXGTLAUW.js → chunk-WWZLT6AM.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-O2MHF7QM.js → chunk-XRLZ75YY.js} +38 -38
- package/node_modules/pi-lens/dist/chunk-XWWFESYZ.js +27 -0
- package/node_modules/pi-lens/dist/chunk-XZSXSM4K.js +27 -0
- package/node_modules/pi-lens/dist/{chunk-C5PLBTNR.js → chunk-Y2LIOCA7.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-AXAR5ZW2.js → chunk-YIEHUKX2.js} +84 -169
- package/node_modules/pi-lens/dist/{chunk-B2OXE4AH.js → chunk-YOMLAKU6.js} +182 -180
- package/node_modules/pi-lens/dist/{chunk-MOAVEPC4.js → chunk-YV7XVYSJ.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-ZULZS2I6.js → chunk-ZVQUYCBU.js} +996 -365
- package/node_modules/pi-lens/dist/index.js +4911 -2376
- package/node_modules/pi-lens/dist/mcp/analyze-cli.js +8 -8
- package/node_modules/pi-lens/dist/mcp/cli.js +40 -40
- package/node_modules/pi-lens/dist/mcp/server.js +321 -234
- package/node_modules/pi-lens/dist/mcp/worker.js +58 -58
- package/node_modules/pi-lens/dist/probes/installer.js +21 -21
- package/node_modules/pi-lens/docs/ci-bot-pr-checks.md +18 -9
- package/node_modules/pi-lens/docs/ci.md +7 -0
- package/node_modules/pi-lens/docs/defect-shapes.md +43 -28
- package/node_modules/pi-lens/docs/globalconfig.md +1 -0
- package/node_modules/pi-lens/docs/invariants/dispatch-runners.md +15 -0
- package/node_modules/pi-lens/docs/lsp-capability-matrix.md +3 -3
- package/node_modules/pi-lens/docs/lsp-idle-eviction.md +3 -2
- package/node_modules/pi-lens/docs/module-report-read-symbol.md +6 -2
- package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +3 -2
- package/node_modules/pi-lens/docs/pi-lens-orchestration.md +2 -1
- package/node_modules/pi-lens/docs/pi-lens-subagent.md +2 -1
- package/node_modules/pi-lens/docs/servercapabilities.md +1 -1
- package/node_modules/pi-lens/docs/settings.md +1 -0
- package/node_modules/pi-lens/docs/usage.md +1 -0
- package/node_modules/pi-lens/package.json +1 -1
- package/package.json +9 -7
- package/node_modules/pi-lens/dist/chunk-2H7NFZ4Q.js +0 -25
- package/node_modules/pi-lens/dist/chunk-5YJXF2IS.js +0 -56
- package/node_modules/pi-lens/dist/chunk-GCSDF5IE.js +0 -27
- package/node_modules/pi-lens/dist/chunk-H5API74E.js +0 -67
- package/node_modules/pi-lens/dist/chunk-HBX55MWO.js +0 -27
- package/node_modules/pi-lens/dist/chunk-JOIKBUQN.js +0 -88
- package/node_modules/pi-lens/dist/chunk-M2YMBT5G.js +0 -73
- package/node_modules/pi-lens/dist/chunk-MJRGPEQ5.js +0 -25
- package/node_modules/pi-lens/dist/chunk-TFKN5EIR.js +0 -27
|
@@ -31,40 +31,47 @@
|
|
|
31
31
|
* `EvalError`, so a captured host `Function` cannot compile anything. Treat this
|
|
32
32
|
* as a determinism boundary, not a security boundary against a hostile script.
|
|
33
33
|
*
|
|
34
|
-
* ## Why determinism is a
|
|
34
|
+
* ## Why determinism is a shim and not a stub
|
|
35
35
|
*
|
|
36
36
|
* Because `Date` and `Math` come *from the realm*, they cannot be neutered by
|
|
37
|
-
* injection — there is nothing to inject over. So the
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
37
|
+
* injection — there is nothing to inject over. So before the script runs, a
|
|
38
|
+
* shim runs inside the realm: it replaces
|
|
39
|
+
* `globalThis.Date` with a constructor whose zero-argument and call forms
|
|
40
|
+
* throw, points `Date.prototype.constructor` at it, makes `Date.now` and
|
|
41
|
+
* `Math.random` throw, and freezes the real constructor. A global rather than
|
|
42
|
+
* a lexical shadow, because a lexical `const Date` left `new globalThis.Date()`
|
|
43
|
+
* reading the real clock.
|
|
42
44
|
*
|
|
43
45
|
* Determinism is enforced because a workflow's journal is replayed by prefix on
|
|
44
46
|
* resume: a script that reads the clock produces a different prefix on the
|
|
45
47
|
* second run and the replay silently diverges.
|
|
46
48
|
*/
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
50
|
+
const NOW_ERROR =
|
|
51
|
+
"Date.now() / new Date() are unavailable in workflow scripts (breaks resume). Stamp results after the workflow returns, or pass timestamps via args."
|
|
52
|
+
const RANDOM_ERROR =
|
|
53
|
+
"Math.random() is unavailable in workflow scripts (breaks resume). For N independent samples, include the index in the agent label or prompt."
|
|
54
|
+
|
|
55
|
+
/** Runs once per vm context, before any script is compiled into it. Messages match what Claude Code scripts see, for compatibility. */
|
|
56
|
+
const DETERMINISM_SHIM = `(() => {
|
|
57
|
+
"use strict";
|
|
58
|
+
const NOW_ERROR = ${JSON.stringify(NOW_ERROR)};
|
|
59
|
+
const RANDOM_ERROR = ${JSON.stringify(RANDOM_ERROR)};
|
|
60
|
+
Math.random = function random() { throw new Error(RANDOM_ERROR); };
|
|
61
|
+
const RealDate = Date;
|
|
62
|
+
RealDate.now = function now() { throw new Error(NOW_ERROR); };
|
|
63
|
+
function WorkflowDate(...args) {
|
|
64
|
+
if (!new.target || args.length === 0) throw new Error(NOW_ERROR);
|
|
65
|
+
return Reflect.construct(RealDate, args, new.target);
|
|
66
|
+
}
|
|
67
|
+
WorkflowDate.now = RealDate.now;
|
|
68
|
+
WorkflowDate.parse = RealDate.parse;
|
|
69
|
+
WorkflowDate.UTC = RealDate.UTC;
|
|
70
|
+
WorkflowDate.prototype = RealDate.prototype;
|
|
71
|
+
RealDate.prototype.constructor = WorkflowDate;
|
|
72
|
+
Object.freeze(RealDate);
|
|
73
|
+
globalThis.Date = WorkflowDate;
|
|
74
|
+
})()`
|
|
68
75
|
|
|
69
76
|
export const WORKER_SOURCE = `"use strict";
|
|
70
77
|
|
|
@@ -73,7 +80,7 @@ const vm = require("node:vm");
|
|
|
73
80
|
|
|
74
81
|
const port = parentPort;
|
|
75
82
|
const ITEM_CAP = workerData.itemCap;
|
|
76
|
-
const
|
|
83
|
+
const DETERMINISM_SHIM = ${JSON.stringify(DETERMINISM_SHIM)};
|
|
77
84
|
|
|
78
85
|
/* ------------------------------------------------------------------ *
|
|
79
86
|
* RPC to the host
|
|
@@ -86,6 +93,13 @@ const PRELUDE = ${JSON.stringify(DETERMINISM_PRELUDE)};
|
|
|
86
93
|
let nextCallId = 1;
|
|
87
94
|
const pendingCalls = new Map();
|
|
88
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Label → why the most recent agent() call under it failed, for
|
|
98
|
+
* \`agentError(label)\`. Per worker, so a nested workflow shares it the way it
|
|
99
|
+
* shares resume labels; a success under the label clears it.
|
|
100
|
+
*/
|
|
101
|
+
const agentErrors = new Map();
|
|
102
|
+
|
|
89
103
|
/**
|
|
90
104
|
* Output tokens this run has spent, as last reported by the host.
|
|
91
105
|
*
|
|
@@ -114,6 +128,12 @@ port.on("message", function (message) {
|
|
|
114
128
|
if (!waiter) return;
|
|
115
129
|
pendingCalls.delete(message.callId);
|
|
116
130
|
if (message.ok) {
|
|
131
|
+
// Before resolving, so the script can read the reason as soon as agent()
|
|
132
|
+
// hands it the null.
|
|
133
|
+
if (typeof message.agentLabel === "string") {
|
|
134
|
+
if (message.value === null && typeof message.error === "string") agentErrors.set(message.agentLabel, message.error);
|
|
135
|
+
else agentErrors.delete(message.agentLabel);
|
|
136
|
+
}
|
|
117
137
|
waiter.resolve(message.value);
|
|
118
138
|
return;
|
|
119
139
|
}
|
|
@@ -157,12 +177,84 @@ function flushProgress() {
|
|
|
157
177
|
/* ------------------------------------------------------------------ *
|
|
158
178
|
* The JSON boundary
|
|
159
179
|
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
180
|
+
* Two directions, two policies. What the *script hands out* — its return
|
|
181
|
+
* value, a child's args and result — is copied for compatibility with Claude
|
|
182
|
+
* Code, so a script written there returns the same value here. What it hands
|
|
183
|
+
* *in* as configuration — \`opts.schema\` — is checked strictly, because a
|
|
184
|
+
* schema that changes shape in transit is a schema the journal key and the
|
|
185
|
+
* tool's parameters disagree about.
|
|
164
186
|
* ------------------------------------------------------------------ */
|
|
165
187
|
|
|
188
|
+
/**
|
|
189
|
+
* The VM-boundary copy Claude Code scripts expect: own enumerable keys only, so \`toJSON\` is
|
|
190
|
+
* never called and a Date, Map, Set or class instance arrives as \`{}\` plus its
|
|
191
|
+
* own fields. A function property is dropped and a function array slot becomes
|
|
192
|
+
* \`undefined\`; a \`__proto__\` key is skipped; a getter that throws loses its
|
|
193
|
+
* property. Shared references and cycles are preserved, which is what lets the
|
|
194
|
+
* stringify that follows reject a cycle instead of recursing forever.
|
|
195
|
+
*/
|
|
196
|
+
function toPlain(root) {
|
|
197
|
+
const seen = new Map();
|
|
198
|
+
function copy(value) {
|
|
199
|
+
if (typeof value === "function") return undefined;
|
|
200
|
+
if (value === null || typeof value !== "object") return value;
|
|
201
|
+
const hit = seen.get(value);
|
|
202
|
+
if (hit !== undefined) return hit;
|
|
203
|
+
if (Array.isArray(value)) {
|
|
204
|
+
const out = [];
|
|
205
|
+
seen.set(value, out);
|
|
206
|
+
const length = value.length;
|
|
207
|
+
for (let i = 0; i < length; i++) {
|
|
208
|
+
let item;
|
|
209
|
+
try {
|
|
210
|
+
item = value[i];
|
|
211
|
+
} catch {
|
|
212
|
+
item = undefined;
|
|
213
|
+
}
|
|
214
|
+
out[i] = copy(item);
|
|
215
|
+
}
|
|
216
|
+
return out;
|
|
217
|
+
}
|
|
218
|
+
const out = {};
|
|
219
|
+
seen.set(value, out);
|
|
220
|
+
let keys;
|
|
221
|
+
try {
|
|
222
|
+
keys = Object.keys(value);
|
|
223
|
+
} catch {
|
|
224
|
+
return out;
|
|
225
|
+
}
|
|
226
|
+
for (let i = 0; i < keys.length; i++) {
|
|
227
|
+
const key = keys[i];
|
|
228
|
+
if (key === "__proto__") continue;
|
|
229
|
+
let item;
|
|
230
|
+
try {
|
|
231
|
+
item = value[key];
|
|
232
|
+
} catch {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if (typeof item === "function") continue;
|
|
236
|
+
out[key] = copy(item);
|
|
237
|
+
}
|
|
238
|
+
return out;
|
|
239
|
+
}
|
|
240
|
+
return copy(root);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** The copy as JSON. Only a cycle or a BigInt can fail here. */
|
|
244
|
+
function toJson(value, what) {
|
|
245
|
+
try {
|
|
246
|
+
return JSON.stringify(toPlain(value));
|
|
247
|
+
} catch (error) {
|
|
248
|
+
throw new Error(what + " cannot be serialized: " + describe(error));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** The copy re-materialised in the script's realm, for a child's args and result. */
|
|
253
|
+
function toRealmCopy(value, what) {
|
|
254
|
+
const json = toJson(value, what);
|
|
255
|
+
return json === undefined ? undefined : realmParse(json);
|
|
256
|
+
}
|
|
257
|
+
|
|
166
258
|
let realmObjectPrototype = null;
|
|
167
259
|
/**
|
|
168
260
|
* The realm's own \`JSON.parse\`.
|
|
@@ -208,10 +300,7 @@ function assertBoundary(value, path, seen) {
|
|
|
208
300
|
if (!Number.isFinite(value)) throw boundaryError("a non-finite number", path);
|
|
209
301
|
return;
|
|
210
302
|
}
|
|
211
|
-
if (kind === "undefined")
|
|
212
|
-
if (path === "the workflow result") return;
|
|
213
|
-
throw boundaryError("undefined", path);
|
|
214
|
-
}
|
|
303
|
+
if (kind === "undefined") throw boundaryError("undefined", path);
|
|
215
304
|
if (kind === "bigint") throw boundaryError("a BigInt", path);
|
|
216
305
|
if (kind === "symbol") throw boundaryError("a symbol", path);
|
|
217
306
|
if (kind === "function") throw boundaryError("a function", path);
|
|
@@ -311,6 +400,44 @@ function optionalText(value, what) {
|
|
|
311
400
|
*/
|
|
312
401
|
const EFFORT_LEVELS = ["minimal", "low", "medium", "high", "xhigh", "max"];
|
|
313
402
|
|
|
403
|
+
/**
|
|
404
|
+
* \`opts.effort\`, read for compatibility with Claude Code: empty means unset, case does not
|
|
405
|
+
* matter, \`med\` means \`medium\`. An unknown level still throws here where
|
|
406
|
+
* Claude Code drops it to the default — the same typo guard unknown option
|
|
407
|
+
* keys get.
|
|
408
|
+
*/
|
|
409
|
+
function normalizeEffort(value) {
|
|
410
|
+
if (value === undefined || value === null || value === "") return undefined;
|
|
411
|
+
const lower = String(value).toLowerCase();
|
|
412
|
+
const level = lower === "med" ? "medium" : lower;
|
|
413
|
+
if (EFFORT_LEVELS.indexOf(level) === -1) {
|
|
414
|
+
throw new Error("agent() opts.effort must be one of: " + EFFORT_LEVELS.join(", ") + ".");
|
|
415
|
+
}
|
|
416
|
+
return level;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* \`opts.disallowedTools\`, validated for compatibility with Claude Code: a
|
|
421
|
+
* malformed list refuses the spawn rather than running it un-narrowed. Empty
|
|
422
|
+
* means unset; otherwise deduped and sorted, so the journal key does not
|
|
423
|
+
* depend on the order the script listed them in.
|
|
424
|
+
*/
|
|
425
|
+
function normalizeDisallowedTools(value) {
|
|
426
|
+
if (value === undefined) return undefined;
|
|
427
|
+
const malformed = function (entry) {
|
|
428
|
+
return typeof entry !== "string" || entry === "" || entry !== entry.trim();
|
|
429
|
+
};
|
|
430
|
+
if (!Array.isArray(value) || value.some(malformed)) {
|
|
431
|
+
throw new Error(
|
|
432
|
+
"agent() opts.disallowedTools must be an array of non-empty tool-name strings (e.g. ['Bash', 'Write']); got "
|
|
433
|
+
+ (Array.isArray(value) ? "an array with non-string, empty, or whitespace-padded entries" : typeof value)
|
|
434
|
+
+ ". Refusing the spawn rather than running it un-narrowed."
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
if (value.length === 0) return undefined;
|
|
438
|
+
return Array.from(new Set(value)).sort();
|
|
439
|
+
}
|
|
440
|
+
|
|
314
441
|
/**
|
|
315
442
|
* Every option \`agent()\` understands.
|
|
316
443
|
*
|
|
@@ -331,6 +458,7 @@ const AGENT_OPTIONS = [
|
|
|
331
458
|
"resume",
|
|
332
459
|
"effort",
|
|
333
460
|
"schema",
|
|
461
|
+
"disallowedTools",
|
|
334
462
|
];
|
|
335
463
|
|
|
336
464
|
/** Claude Code options this runtime does not have, and why. */
|
|
@@ -380,6 +508,12 @@ function makeScope(name, depth) {
|
|
|
380
508
|
scope.workflow = function (ref, args) {
|
|
381
509
|
return workflowIn(scope, ref, args);
|
|
382
510
|
};
|
|
511
|
+
scope.parallel = function (thunks) {
|
|
512
|
+
return parallelIn(scope, thunks);
|
|
513
|
+
};
|
|
514
|
+
scope.pipeline = function (items, ...stages) {
|
|
515
|
+
return pipelineIn(scope, items, stages);
|
|
516
|
+
};
|
|
383
517
|
scope.console = makeConsole(scope);
|
|
384
518
|
return scope;
|
|
385
519
|
}
|
|
@@ -430,6 +564,12 @@ function logIn(scope, message) {
|
|
|
430
564
|
emit({ type: "workflow_log", message: logPrefix(scope) + describe(message) });
|
|
431
565
|
}
|
|
432
566
|
|
|
567
|
+
/** A slot that dropped to null: a log line now, and a \`<failures>\` line in the notification. */
|
|
568
|
+
function reportFailure(scope, line) {
|
|
569
|
+
logIn(scope, line);
|
|
570
|
+
port.postMessage({ type: "failure", message: logPrefix(scope) + line });
|
|
571
|
+
}
|
|
572
|
+
|
|
433
573
|
function makeConsole(scope) {
|
|
434
574
|
const write = function () {
|
|
435
575
|
const parts = [];
|
|
@@ -466,7 +606,8 @@ async function agentIn(scope, prompt, opts) {
|
|
|
466
606
|
}
|
|
467
607
|
const gate = optionalText(options.gate, "agent() opts.gate");
|
|
468
608
|
const resume = optionalText(options.resume, "agent() opts.resume");
|
|
469
|
-
const effort =
|
|
609
|
+
const effort = normalizeEffort(options.effort);
|
|
610
|
+
const disallowedTools = normalizeDisallowedTools(options.disallowedTools);
|
|
470
611
|
const schema = options.schema;
|
|
471
612
|
if (schema !== undefined) {
|
|
472
613
|
if (typeof schema !== "object" || schema === null || Array.isArray(schema)) {
|
|
@@ -477,9 +618,6 @@ async function agentIn(scope, prompt, opts) {
|
|
|
477
618
|
// value gets.
|
|
478
619
|
checkBoundary(schema, "agent() opts.schema");
|
|
479
620
|
}
|
|
480
|
-
if (effort !== undefined && EFFORT_LEVELS.indexOf(effort) === -1) {
|
|
481
|
-
throw new Error("agent() opts.effort must be one of: " + EFFORT_LEVELS.join(", ") + ".");
|
|
482
|
-
}
|
|
483
621
|
|
|
484
622
|
// resume revives a child that already exists, so anything describing how to
|
|
485
623
|
// *start* one is not a thing this call gets to decide — the revived child
|
|
@@ -512,6 +650,11 @@ async function agentIn(scope, prompt, opts) {
|
|
|
512
650
|
+ "already had, whose tool set was fixed when it started — it has no StructuredOutput tool to answer through."
|
|
513
651
|
);
|
|
514
652
|
}
|
|
653
|
+
if (disallowedTools !== undefined) {
|
|
654
|
+
throw new Error(
|
|
655
|
+
"agent() opts.resume and opts.disallowedTools are mutually exclusive: a resumed agent keeps the tool set it was started with."
|
|
656
|
+
);
|
|
657
|
+
}
|
|
515
658
|
if (gate !== undefined) {
|
|
516
659
|
throw new Error("agent() opts.gate cannot be combined with opts.resume.");
|
|
517
660
|
}
|
|
@@ -535,12 +678,13 @@ async function agentIn(scope, prompt, opts) {
|
|
|
535
678
|
resume: resume,
|
|
536
679
|
effort: effort,
|
|
537
680
|
schema: schema,
|
|
681
|
+
disallowedTools: disallowedTools,
|
|
538
682
|
});
|
|
539
683
|
if (result === undefined || result === null) return null;
|
|
540
684
|
if (schema === undefined) return result;
|
|
541
685
|
// Parsed with the realm's own JSON.parse so the script gets an object whose
|
|
542
686
|
// prototype is its own — \`x instanceof Object\` and \`x.list instanceof Array\`
|
|
543
|
-
// both hold
|
|
687
|
+
// both hold.
|
|
544
688
|
try {
|
|
545
689
|
return realmParse(result);
|
|
546
690
|
} catch (error) {
|
|
@@ -552,9 +696,11 @@ async function agentIn(scope, prompt, opts) {
|
|
|
552
696
|
/**
|
|
553
697
|
* A barrier: every thunk starts now, and nothing past the await runs until all
|
|
554
698
|
* of them have settled. A thunk that throws resolves to null rather than
|
|
555
|
-
* failing its siblings — the script filters, it does not try/catch
|
|
699
|
+
* failing its siblings — the script filters, it does not try/catch — and
|
|
700
|
+
* leaves a \`parallel[i] failed: …\` log line, so the null
|
|
701
|
+
* is not silent. Per scope, so a nested child's line carries its prefix.
|
|
556
702
|
*/
|
|
557
|
-
async function
|
|
703
|
+
async function parallelIn(scope, thunks) {
|
|
558
704
|
const list = toList(thunks, "parallel(thunks)");
|
|
559
705
|
for (let i = 0; i < list.length; i++) {
|
|
560
706
|
if (typeof list[i] !== "function") {
|
|
@@ -562,11 +708,12 @@ async function parallel(thunks) {
|
|
|
562
708
|
}
|
|
563
709
|
}
|
|
564
710
|
const settled = await Promise.all(
|
|
565
|
-
list.map(async function (thunk) {
|
|
711
|
+
list.map(async function (thunk, index) {
|
|
566
712
|
try {
|
|
567
713
|
return await thunk();
|
|
568
714
|
} catch (error) {
|
|
569
715
|
if (isFatal(error)) throw error;
|
|
716
|
+
reportFailure(scope, "parallel[" + index + "] failed: " + describe(error));
|
|
570
717
|
return null;
|
|
571
718
|
}
|
|
572
719
|
})
|
|
@@ -580,10 +727,14 @@ async function parallel(thunks) {
|
|
|
580
727
|
* a barrier makes every stage wait on its slowest sibling, and with agents in
|
|
581
728
|
* the stages that latency is measured in minutes.
|
|
582
729
|
*
|
|
583
|
-
* A stage that throws drops that item to null
|
|
584
|
-
*
|
|
730
|
+
* A stage that throws drops that item to null, skips its remaining stages and
|
|
731
|
+
* logs \`pipeline[i] failed: …\`. A stage that *returns* null also ends the
|
|
732
|
+
* item's chain — the next stage would otherwise spend an
|
|
733
|
+
* agent on "verify null" — and so does a null item. An item that is a promise
|
|
734
|
+
* is awaited before stage one. Every stage sees (previousResult,
|
|
735
|
+
* originalItem, index).
|
|
585
736
|
*/
|
|
586
|
-
async function
|
|
737
|
+
async function pipelineIn(scope, items, stages) {
|
|
587
738
|
const list = toList(items, "pipeline(items, ...stages)");
|
|
588
739
|
for (let i = 0; i < stages.length; i++) {
|
|
589
740
|
if (typeof stages[i] !== "function") {
|
|
@@ -592,16 +743,17 @@ async function pipeline(items, ...stages) {
|
|
|
592
743
|
}
|
|
593
744
|
const settled = await Promise.all(
|
|
594
745
|
list.map(async function (item, index) {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
746
|
+
try {
|
|
747
|
+
let value = await item;
|
|
748
|
+
for (let s = 0; s < stages.length && value !== null; s++) {
|
|
598
749
|
value = await stages[s](value, item, index);
|
|
599
|
-
} catch (error) {
|
|
600
|
-
if (isFatal(error)) throw error;
|
|
601
|
-
return null;
|
|
602
750
|
}
|
|
751
|
+
return value;
|
|
752
|
+
} catch (error) {
|
|
753
|
+
if (isFatal(error)) throw error;
|
|
754
|
+
reportFailure(scope, "pipeline[" + index + "] failed: " + describe(error));
|
|
755
|
+
return null;
|
|
603
756
|
}
|
|
604
|
-
return value;
|
|
605
757
|
})
|
|
606
758
|
);
|
|
607
759
|
return toRealmArray(settled);
|
|
@@ -644,7 +796,9 @@ async function workflowIn(scope, nameOrRef, args) {
|
|
|
644
796
|
}
|
|
645
797
|
|
|
646
798
|
const label = ref.name !== undefined ? ref.name : ref.scriptPath;
|
|
647
|
-
|
|
799
|
+
// A copy, as Claude Code scripts expect: the child must not be able to
|
|
800
|
+
// mutate the parent's object through its \`args\`.
|
|
801
|
+
const childArgs = toRealmCopy(args, 'workflow("' + label + '") args');
|
|
648
802
|
|
|
649
803
|
if (nestedCount >= workerData.nestedCap) {
|
|
650
804
|
// Fatal, like the agent cap: a limit that silently drops work would be
|
|
@@ -678,10 +832,14 @@ async function workflowIn(scope, nameOrRef, args) {
|
|
|
678
832
|
let run;
|
|
679
833
|
try {
|
|
680
834
|
const compiled = new vm.Script(
|
|
681
|
-
//
|
|
682
|
-
//
|
|
683
|
-
//
|
|
684
|
-
|
|
835
|
+
// The body runs in an inner function, so its own declarations shadow
|
|
836
|
+
// these parameters instead of colliding with them — Claude Code hands a
|
|
837
|
+
// child the same names as globals, which a \`const pipeline\` may shadow.
|
|
838
|
+
// \`meta\` is not a parameter: the body opens with its own
|
|
839
|
+
// \`const meta = { ... }\` (extractMeta strips only the \`export\`).
|
|
840
|
+
"(async (agent, phase, log, workflow, console, args, parallel, pipeline) => {'use strict'; return (async () => {\\n"
|
|
841
|
+
+ loaded.body
|
|
842
|
+
+ "\\n})(); })",
|
|
685
843
|
{ filename: "workflow:" + loaded.name + ".js", lineOffset: -1 }
|
|
686
844
|
);
|
|
687
845
|
run = compiled.runInContext(realmContext);
|
|
@@ -689,9 +847,12 @@ async function workflowIn(scope, nameOrRef, args) {
|
|
|
689
847
|
throw new Error('workflow("' + label + '"): ' + describe(error));
|
|
690
848
|
}
|
|
691
849
|
|
|
692
|
-
const value = await run(
|
|
693
|
-
|
|
694
|
-
|
|
850
|
+
const value = await run(
|
|
851
|
+
child.agent, child.phase, child.log, child.workflow, child.console, childArgs, child.parallel, child.pipeline
|
|
852
|
+
);
|
|
853
|
+
// Refused as a script's own result is, rather than copied to undefined.
|
|
854
|
+
if (typeof value === "function") throw new Error('workflow("' + label + '") result cannot be a function');
|
|
855
|
+
return toRealmCopy(value, 'the result of workflow("' + label + '")');
|
|
695
856
|
}
|
|
696
857
|
|
|
697
858
|
/**
|
|
@@ -721,27 +882,77 @@ function makeBudget() {
|
|
|
721
882
|
};
|
|
722
883
|
}
|
|
723
884
|
|
|
885
|
+
/**
|
|
886
|
+
* The \`setTimeout\` / \`clearTimeout\` globals, for compatibility with Claude
|
|
887
|
+
* Code scripts: the delay coerced to a number, ids rather than handles, and a
|
|
888
|
+
* callback that throws — or, being async, rejects — swallowed rather than
|
|
889
|
+
* failing the run. Nothing clears them on
|
|
890
|
+
* settle or abort because nothing has to — the host terminates this worker
|
|
891
|
+
* either way.
|
|
892
|
+
*/
|
|
893
|
+
function makeTimers() {
|
|
894
|
+
const handles = new Map();
|
|
895
|
+
let nextId = 1;
|
|
896
|
+
return {
|
|
897
|
+
setTimeout: function (callback, ms) {
|
|
898
|
+
if (typeof callback !== "function") {
|
|
899
|
+
throw new TypeError("setTimeout(callback, ms) expects a function.");
|
|
900
|
+
}
|
|
901
|
+
const id = nextId++;
|
|
902
|
+
handles.set(
|
|
903
|
+
id,
|
|
904
|
+
setTimeout(function () {
|
|
905
|
+
handles.delete(id);
|
|
906
|
+
// A timer callback cannot fail the run. Through a promise, so an
|
|
907
|
+
// async callback's rejection is caught too rather than surfacing as
|
|
908
|
+
// an unhandled rejection that kills the worker.
|
|
909
|
+
Promise.resolve().then(callback).catch(function () {});
|
|
910
|
+
}, Number(ms) || 0)
|
|
911
|
+
);
|
|
912
|
+
return id;
|
|
913
|
+
},
|
|
914
|
+
clearTimeout: function (id) {
|
|
915
|
+
const handle = handles.get(id);
|
|
916
|
+
if (handle === undefined) return;
|
|
917
|
+
handles.delete(id);
|
|
918
|
+
clearTimeout(handle);
|
|
919
|
+
},
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
|
|
724
923
|
/* ------------------------------------------------------------------ *
|
|
725
924
|
* Run
|
|
726
925
|
* ------------------------------------------------------------------ */
|
|
727
926
|
|
|
728
927
|
async function main() {
|
|
729
928
|
rootScope = makeScope(undefined, 0);
|
|
929
|
+
const timers = makeTimers();
|
|
730
930
|
const sandbox = {
|
|
731
931
|
agent: rootScope.agent,
|
|
732
|
-
parallel: parallel,
|
|
733
|
-
pipeline: pipeline,
|
|
932
|
+
parallel: rootScope.parallel,
|
|
933
|
+
pipeline: rootScope.pipeline,
|
|
734
934
|
phase: rootScope.phase,
|
|
735
935
|
log: rootScope.log,
|
|
736
936
|
workflow: rootScope.workflow,
|
|
737
937
|
budget: makeBudget(),
|
|
738
938
|
console: rootScope.console,
|
|
939
|
+
setTimeout: timers.setTimeout,
|
|
940
|
+
clearTimeout: timers.clearTimeout,
|
|
739
941
|
};
|
|
942
|
+
// Read-only: a script that assigned over it would silently read its own
|
|
943
|
+
// stand-in instead of the host's answer.
|
|
944
|
+
Object.defineProperty(sandbox, "agentError", {
|
|
945
|
+
value: function agentError(label) {
|
|
946
|
+
return agentErrors.get(requireText(label, "agentError(label)"));
|
|
947
|
+
},
|
|
948
|
+
enumerable: true,
|
|
949
|
+
});
|
|
740
950
|
const context = vm.createContext(sandbox, {
|
|
741
951
|
name: "workflow",
|
|
742
952
|
codeGeneration: { strings: false, wasm: false },
|
|
743
953
|
});
|
|
744
954
|
|
|
955
|
+
vm.runInContext(DETERMINISM_SHIM, context);
|
|
745
956
|
realmObjectPrototype = vm.runInContext("Object.prototype", context);
|
|
746
957
|
realmNewArray = vm.runInContext("(function () { return []; })", context);
|
|
747
958
|
realmPush = vm.runInContext("(function (array, value) { array.push(value); })", context);
|
|
@@ -754,20 +965,21 @@ async function main() {
|
|
|
754
965
|
sandbox.meta = realmParse(workerData.metaJson);
|
|
755
966
|
sandbox.args = workerData.argsJson === undefined ? undefined : realmParse(workerData.argsJson);
|
|
756
967
|
|
|
757
|
-
const script = new vm.Script("(async () => {
|
|
968
|
+
const script = new vm.Script("(async () => {'use strict';\\n" + workerData.body + "\\n})()", {
|
|
758
969
|
filename: "workflow.js",
|
|
759
|
-
// The wrapper adds exactly one line above the
|
|
760
|
-
// error points at the line the author wrote.
|
|
970
|
+
// The wrapper, strict directive included, adds exactly one line above the
|
|
971
|
+
// body; undo it so a thrown error points at the line the author wrote.
|
|
972
|
+
// Strict: a Claude Code workflow script must not be relying on
|
|
973
|
+
// sloppy-mode leniency here.
|
|
761
974
|
lineOffset: -1,
|
|
762
975
|
});
|
|
763
976
|
|
|
764
977
|
const value = await script.runInContext(context);
|
|
765
|
-
|
|
978
|
+
// The one value refused outright; everything else is copied.
|
|
979
|
+
if (typeof value === "function") throw new Error("workflow result cannot be a function");
|
|
980
|
+
const resultJson = toJson(value, "the workflow result");
|
|
766
981
|
flushProgress();
|
|
767
|
-
port.postMessage({
|
|
768
|
-
type: "complete",
|
|
769
|
-
resultJson: value === undefined ? undefined : JSON.stringify(value),
|
|
770
|
-
});
|
|
982
|
+
port.postMessage({ type: "complete", resultJson: resultJson });
|
|
771
983
|
}
|
|
772
984
|
|
|
773
985
|
main().catch(function (error) {
|