@mmmbuto/qwen-code-termux 0.16.1-termux → 0.18.0-termux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -109
- package/bundled/new-app/SKILL.md +22 -0
- package/bundled/qc-helper/SKILL.md +29 -24
- package/bundled/qc-helper/docs/_meta.ts +1 -0
- package/bundled/qc-helper/docs/configuration/_meta.ts +0 -3
- package/bundled/qc-helper/docs/configuration/settings.md +37 -31
- package/bundled/qc-helper/docs/configuration/themes.md +39 -0
- package/bundled/qc-helper/docs/features/_meta.ts +1 -3
- package/bundled/qc-helper/docs/features/approval-mode.md +35 -35
- package/bundled/qc-helper/docs/features/auto-mode.md +54 -9
- package/bundled/qc-helper/docs/features/channels/_meta.ts +1 -0
- package/bundled/qc-helper/docs/features/channels/feishu.md +170 -0
- package/bundled/qc-helper/docs/features/commands.md +115 -35
- package/bundled/qc-helper/docs/features/followup-suggestions.md +2 -2
- package/bundled/qc-helper/docs/features/headless.md +32 -0
- package/bundled/qc-helper/docs/features/markdown-rendering.md +21 -1
- package/bundled/qc-helper/docs/features/memory.md +22 -5
- package/bundled/qc-helper/docs/features/scheduled-tasks.md +1 -1
- package/bundled/qc-helper/docs/features/status-line.md +168 -32
- package/bundled/qc-helper/docs/features/sub-agents.md +60 -0
- package/bundled/qc-helper/docs/features/worktree.md +345 -0
- package/bundled/qc-helper/docs/overview.md +4 -4
- package/bundled/qc-helper/docs/quickstart.md +4 -4
- package/bundled/qc-helper/docs/qwen-serve-deploy-local.md +221 -0
- package/bundled/qc-helper/docs/qwen-serve.md +234 -24
- package/bundled/qc-helper/docs/reference/keyboard-shortcuts.md +16 -0
- package/bundled/qc-helper/docs/support/Uninstall.md +19 -1
- package/bundled/qc-helper/docs/support/troubleshooting.md +2 -1
- package/bundled/simplify/SKILL.md +123 -0
- package/chunks/agent-IDS4HMOX.js +56 -0
- package/chunks/agent-headless-5Q2EUSPS.js +50 -0
- package/chunks/{anthropicContentGenerator-SSGKR6DO.js → anthropicContentGenerator-2HBRNQ3B.js} +52 -9
- package/chunks/{askUserQuestion-PJWUUXKN.js → askUserQuestion-75TDJVK2.js} +45 -3
- package/chunks/{ca-UZ7BANMN.js → ca-BARBRL6N.js} +89 -5
- package/chunks/{chunk-GGNTZ2NH.js → chunk-2Y5SYSD3.js} +368 -597
- package/chunks/{chunk-2LA2TREA.js → chunk-3AA2DK35.js} +1448 -207
- package/chunks/{chunk-I2V5WXHJ.js → chunk-3AUHFMSK.js} +80 -38
- package/chunks/chunk-3DHXZ6EV.js +241 -0
- package/chunks/{chunk-PR4T27R7.js → chunk-3HTIVKZE.js} +42 -8
- package/chunks/chunk-3HX5LZ6R.js +1798 -0
- package/chunks/chunk-3PJXIDKI.js +2517 -0
- package/chunks/{chunk-MYAKAFEC.js → chunk-55ZMG67I.js} +7451 -3517
- package/chunks/{chunk-66CXYE4B.js → chunk-5IFG2VC4.js} +293 -242
- package/chunks/chunk-64WXLC72.js +98 -0
- package/chunks/{chunk-C6WMLUNB.js → chunk-72LDN5PP.js} +1 -1
- package/chunks/{chunk-F23NCRJ2.js → chunk-A7B4ISQP.js} +1 -1
- package/chunks/chunk-B7HXHOHU.js +393 -0
- package/chunks/{chunk-XEGHDASV.js → chunk-D3RHSPAS.js} +435 -540
- package/chunks/{chunk-XKS5KBFJ.js → chunk-EYENRK4D.js} +694 -384
- package/chunks/chunk-H6BD2ELD.js +36 -0
- package/chunks/{chunk-XP27SJMH.js → chunk-HR7SV7AY.js} +79 -48
- package/chunks/{chunk-D5NTAHYL.js → chunk-IDX6COTE.js} +7 -2
- package/chunks/{chunk-SHT4VJWU.js → chunk-IWKSG2AR.js} +2 -2
- package/chunks/chunk-J37FGIOA.js +1623 -0
- package/chunks/chunk-J5MDQKJL.js +2230 -0
- package/chunks/{chunk-USE2VQ5P.js → chunk-JTQAQBTV.js} +21 -0
- package/chunks/{chunk-NCTLV2NB.js → chunk-KQJMQJPI.js} +1 -1
- package/chunks/{chunk-5FBA5XC2.js → chunk-KRIHGKNA.js} +1 -1
- package/chunks/chunk-LD2XBG6Z.js +102 -0
- package/chunks/{chunk-MAY32HXD.js → chunk-M6VTDSVR.js} +3 -1
- package/chunks/chunk-MRO43B25.js +30 -0
- package/chunks/{chunk-N4WOREMD.js → chunk-NVFMZBX2.js} +43 -3
- package/chunks/chunk-OHEGWO4L.js +264 -0
- package/chunks/{chunk-K6O2NBMF.js → chunk-OQ7NJIY7.js} +4604 -6397
- package/chunks/chunk-QQDPRDVW.js +25 -0
- package/chunks/{chunk-KXZ4TJB4.js → chunk-SEGYWKIH.js} +1 -1
- package/chunks/chunk-SKBPNJEW.js +45 -0
- package/chunks/{chunk-4AOCVI6J.js → chunk-SNGELLWX.js} +52 -6
- package/chunks/{chunk-3OCRHZA3.js → chunk-TD4OPI4T.js} +56742 -44104
- package/chunks/{chunk-DQ4QTG7E.js → chunk-VV4F63BD.js} +11 -11
- package/chunks/chunk-XBY7E2FX.js +605 -0
- package/chunks/{chunk-JKMBWLFB.js → chunk-YILFYI5W.js} +48 -26
- package/chunks/chunk-YOGAOMYB.js +159 -0
- package/chunks/{chunk-QWSRH265.js → chunk-Z2Z3GUXZ.js} +777 -776
- package/chunks/{chunk-SDHRQFOS.js → chunk-ZTZ4DDQE.js} +2 -2
- package/chunks/computer-use-W2TYQNEE.js +825 -0
- package/chunks/contextCommand-6FGX3A7J.js +52 -0
- package/chunks/{cron-create-3ZBBN7WB.js → cron-create-APL5LU6I.js} +3 -3
- package/chunks/{cron-delete-NAGKKIIG.js → cron-delete-4SBJSCN4.js} +3 -3
- package/chunks/{cron-list-PAGRXNAI.js → cron-list-2AMGOMVO.js} +3 -3
- package/chunks/{de-V4IE2OOZ.js → de-YGKK2BC4.js} +89 -5
- package/chunks/{devtools-TWVXEJQB.js → devtools-FM6GJPYG.js} +2 -1
- package/chunks/{dist-4L54HRX2.js → dist-4LXD6L6X.js} +24 -5
- package/chunks/dist-H6ONXVLG.js +94146 -0
- package/chunks/{dist-XKWIWPWQ.js → dist-KAZ3SEBX.js} +1083 -3856
- package/chunks/{dist-BXDUQ2QY.js → dist-PK7DFCAW.js} +1 -1
- package/chunks/{edit-NVO3FOAK.js → edit-ZCEZC264.js} +30 -22
- package/chunks/{en-HGJ2SPLM.js → en-DHGYHIHX.js} +127 -6
- package/chunks/{enter-worktree-UEBG4WFC.js → enter-worktree-BBHCFCHG.js} +30 -20
- package/chunks/enterPlanMode-3M6KTD3B.js +158 -0
- package/chunks/{exit-worktree-UZ3MAQZN.js → exit-worktree-73YPIEQO.js} +27 -19
- package/chunks/exitPlanMode-TYZM6BAE.js +703 -0
- package/chunks/{fr-CJULI7ZX.js → fr-JXBKPJKQ.js} +89 -5
- package/chunks/{geminiContentGenerator-3UZFXGNT.js → geminiContentGenerator-7N2V3VW2.js} +8 -6
- package/chunks/{getMachineId-bsd-JXOSIJV2.js → getMachineId-bsd-4CASPIU4.js} +4 -4
- package/chunks/{getMachineId-darwin-TE4QRR42.js → getMachineId-darwin-HPQPEMZR.js} +4 -4
- package/chunks/{getMachineId-linux-S3OL52XK.js → getMachineId-linux-AUARKYHL.js} +3 -3
- package/chunks/{getMachineId-unsupported-DWUSBAPX.js → getMachineId-unsupported-S32ZDA2T.js} +3 -3
- package/chunks/{getMachineId-win-AAC5P3AP.js → getMachineId-win-4EFLHYIJ.js} +4 -4
- package/chunks/{glob-KNHSFFFG.js → glob-5XBCPQ2A.js} +27 -19
- package/chunks/{grep-LACWDZW4.js → grep-VIUU3A7X.js} +30 -19
- package/chunks/{ja-L7CHRQEW.js → ja-TGPZSP2B.js} +89 -5
- package/chunks/{keychain-token-storage-335UOLJ6.js → keychain-token-storage-6IU6ORQN.js} +3 -3
- package/chunks/{ls-AGXQOKSG.js → ls-JRGYIGLY.js} +4 -4
- package/chunks/{lsp-UDMUHNPA.js → lsp-SHMKFOAC.js} +3 -3
- package/chunks/{monitor-ETKWPJEH.js → monitor-6R4LIJL5.js} +40 -25
- package/chunks/{multipart-parser-3QWGTLK3.js → multipart-parser-AJ4WASWR.js} +2 -2
- package/chunks/{notebook-edit-QJJLPNYT.js → notebook-edit-5E7ULDVQ.js} +28 -20
- package/chunks/{openaiContentGenerator-CNNN424U.js → openaiContentGenerator-ZVHFKM3O.js} +17 -14
- package/chunks/{pt-M6JULLEQ.js → pt-TIBG6BIO.js} +89 -5
- package/chunks/{qwenContentGenerator-BOLCGK3R.js → qwenContentGenerator-B2VTVSPJ.js} +31 -23
- package/chunks/{qwenOAuth2-EEJGROP7.js → qwenOAuth2-2KCKWDCF.js} +6 -4
- package/chunks/read-file-GIT7BCDR.js +27 -0
- package/chunks/ripGrep-MWKFVYMS.js +48 -0
- package/chunks/{ru-QILM4HBC.js → ru-JBCHCK4L.js} +89 -5
- package/chunks/scheduler-5VOOYGBH.js +308 -0
- package/chunks/send-message-4QNWQJF4.js +244 -0
- package/chunks/{serve-OLSI7WSR.js → serve-MN6HZBWN.js} +14262 -7414
- package/chunks/shell-NQZQGFM2.js +56 -0
- package/chunks/{skill-D6YRHTTI.js → skill-WCFW4644.js} +145 -119
- package/chunks/{src-TMOD5X6F.js → src-7XL4G4DC.js} +88 -46
- package/chunks/{src-4QH4FZ6I.js → src-IHA6DTUV.js} +452 -62
- package/chunks/{syntheticOutput-5PVFDDJ4.js → syntheticOutput-YTYS2ZMQ.js} +4 -4
- package/chunks/task-create-MPORPYN6.js +19 -0
- package/chunks/task-list-R2YDYPZT.js +151 -0
- package/chunks/{task-stop-AJKPSR6R.js → task-stop-SYWJYBCM.js} +3 -3
- package/chunks/task-update-E4NSLKMQ.js +408 -0
- package/chunks/team-create-7R7KA5IP.js +314 -0
- package/chunks/team-delete-25OIWUPN.js +116 -0
- package/chunks/{todoWrite-VLAUG4CA.js → todoWrite-4YHMIF4X.js} +16 -5
- package/chunks/{tool-search-MZGHUUKD.js → tool-search-YBRVZCLI.js} +29 -11
- package/chunks/{tts-notification-K3X7X7MN.js → tts-notification-7SOEMQK4.js} +5 -4
- package/chunks/{web-fetch-OILB464A.js → web-fetch-MFIRHIHI.js} +5 -5
- package/chunks/workflow-5RIKVCIE.js +960 -0
- package/chunks/{write-file-BIQAA57V.js → write-file-DMQTJZOM.js} +32 -24
- package/chunks/{zh-PWL2NKY3.js → zh-7H5OQC4I.js} +135 -11
- package/chunks/{zh-TW-S3YGWICZ.js → zh-TW-P4IDHD3M.js} +128 -11
- package/cli.js +45402 -20570
- package/examples/agent/agents/diary.md +86 -0
- package/examples/agent/qwen-extension.json +5 -0
- package/examples/commands/commands/fs/grep-code.md +3 -0
- package/examples/commands/qwen-extension.json +5 -0
- package/examples/context/QWEN.md +8 -0
- package/examples/context/qwen-extension.json +5 -0
- package/examples/mcp-server/example.ts +60 -0
- package/examples/mcp-server/package.json +18 -0
- package/examples/mcp-server/qwen-extension.json +12 -0
- package/examples/mcp-server/tsconfig.json +13 -0
- package/examples/skills/qwen-extension.json +5 -0
- package/examples/skills/skills/synonyms/SKILL.md +48 -0
- package/examples/starter/QWEN.md +30 -0
- package/examples/starter/README.md +59 -0
- package/examples/starter/agents/diary.md +86 -0
- package/examples/starter/commands/writing/polish.md +13 -0
- package/examples/starter/example.ts +64 -0
- package/examples/starter/package.json +18 -0
- package/examples/starter/qwen-extension.json +12 -0
- package/examples/starter/skills/synonyms/SKILL.md +48 -0
- package/examples/starter/tsconfig.json +13 -0
- package/fzfWorker.js +1083 -0
- package/locales/ca.js +118 -5
- package/locales/de.js +117 -5
- package/locales/en.js +169 -7
- package/locales/fr.js +119 -5
- package/locales/ja.js +114 -5
- package/locales/pt.js +117 -5
- package/locales/ru.js +116 -5
- package/locales/zh-TW.js +161 -12
- package/locales/zh.js +169 -12
- package/package.json +4 -2
- package/scripts/postinstall.cjs +2 -1
- package/bundled/qc-helper/docs/features/checkpointing.md +0 -77
- package/chunks/agent-7ZN3CRHR.js +0 -48
- package/chunks/chunk-6PCB2DEF.js +0 -434
- package/chunks/chunk-EM6ETG2K.js +0 -60
- package/chunks/chunk-G7YTSRES.js +0 -150
- package/chunks/contextCommand-7IBASARL.js +0 -44
- package/chunks/exitPlanMode-PZAMWIRW.js +0 -227
- package/chunks/multipart-parser-IXGBIOIN.js +0 -384
- package/chunks/read-file-CCUEUFG2.js +0 -24
- package/chunks/ripGrep-TADOH2HK.js +0 -40
- package/chunks/send-message-YL44UZFC.js +0 -151
- package/chunks/shell-7KKKC5G7.js +0 -48
- package/chunks/src-IPWIHNMI.js +0 -1406
- package/chunks/undici-F6ZOXSS5.js +0 -8
|
@@ -0,0 +1,960 @@
|
|
|
1
|
+
// Force strict mode and setup for ESM
|
|
2
|
+
"use strict";
|
|
3
|
+
import "./chunk-SKBPNJEW.js";
|
|
4
|
+
import {
|
|
5
|
+
BaseDeclarativeTool,
|
|
6
|
+
BaseToolInvocation,
|
|
7
|
+
ToolDisplayNames,
|
|
8
|
+
ToolNames
|
|
9
|
+
} from "./chunk-D3RHSPAS.js";
|
|
10
|
+
import {
|
|
11
|
+
createChildAbortController
|
|
12
|
+
} from "./chunk-64WXLC72.js";
|
|
13
|
+
import {
|
|
14
|
+
createDebugLogger
|
|
15
|
+
} from "./chunk-HR7SV7AY.js";
|
|
16
|
+
import "./chunk-Z2Z3GUXZ.js";
|
|
17
|
+
import {
|
|
18
|
+
init_esbuild_shims
|
|
19
|
+
} from "./chunk-A4BMJM77.js";
|
|
20
|
+
import {
|
|
21
|
+
__name
|
|
22
|
+
} from "./chunk-J2S4EL5Y.js";
|
|
23
|
+
|
|
24
|
+
// packages/core/src/tools/workflow/workflow.ts
|
|
25
|
+
init_esbuild_shims();
|
|
26
|
+
|
|
27
|
+
// packages/core/src/agents/runtime/workflow-orchestrator.ts
|
|
28
|
+
init_esbuild_shims();
|
|
29
|
+
import { randomBytes } from "node:crypto";
|
|
30
|
+
import * as os from "node:os";
|
|
31
|
+
|
|
32
|
+
// packages/core/src/agents/runtime/workflow-sandbox.ts
|
|
33
|
+
init_esbuild_shims();
|
|
34
|
+
import * as vm from "node:vm";
|
|
35
|
+
function stripExportMeta(source) {
|
|
36
|
+
const re = /^\s*export\s+const\s+meta\s*=\s*\{/;
|
|
37
|
+
const match = re.exec(source);
|
|
38
|
+
if (!match) return source;
|
|
39
|
+
const exportIdx = match.index;
|
|
40
|
+
const startBrace = source.indexOf("{", exportIdx);
|
|
41
|
+
let depth = 1;
|
|
42
|
+
let i = startBrace + 1;
|
|
43
|
+
while (i < source.length && depth > 0) {
|
|
44
|
+
const ch = source[i];
|
|
45
|
+
const next = source[i + 1];
|
|
46
|
+
if (ch === "/" && next === "/") {
|
|
47
|
+
i += 2;
|
|
48
|
+
while (i < source.length && source[i] !== "\n") i++;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (ch === "/" && next === "*") {
|
|
52
|
+
i += 2;
|
|
53
|
+
while (i < source.length && !(source[i] === "*" && source[i + 1] === "/"))
|
|
54
|
+
i++;
|
|
55
|
+
i += 2;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (ch === "/" && isRegexContext(source, i)) {
|
|
59
|
+
i++;
|
|
60
|
+
let inClass = false;
|
|
61
|
+
while (i < source.length && (inClass || source[i] !== "/") && source[i] !== "\n") {
|
|
62
|
+
if (source[i] === "\\") i += 2;
|
|
63
|
+
else if (source[i] === "[") {
|
|
64
|
+
inClass = true;
|
|
65
|
+
i++;
|
|
66
|
+
} else if (source[i] === "]") {
|
|
67
|
+
inClass = false;
|
|
68
|
+
i++;
|
|
69
|
+
} else {
|
|
70
|
+
i++;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
i++;
|
|
74
|
+
while (i < source.length && /[gimsuy]/.test(source[i])) i++;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
78
|
+
const q = ch;
|
|
79
|
+
i++;
|
|
80
|
+
while (i < source.length && source[i] !== q) {
|
|
81
|
+
if (source[i] === "\\") i++;
|
|
82
|
+
i++;
|
|
83
|
+
}
|
|
84
|
+
i++;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (ch === "{") depth++;
|
|
88
|
+
else if (ch === "}") depth--;
|
|
89
|
+
i++;
|
|
90
|
+
}
|
|
91
|
+
if (depth !== 0) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
"stripExportMeta: unbalanced braces in export const meta declaration \u2014 the workflow script cannot be safely stripped. Check the meta block syntax."
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
while (i < source.length && /[\s;]/.test(source[i])) i++;
|
|
97
|
+
return source.slice(0, exportIdx) + source.slice(i);
|
|
98
|
+
}
|
|
99
|
+
__name(stripExportMeta, "stripExportMeta");
|
|
100
|
+
function isRegexContext(source, i) {
|
|
101
|
+
let j = i - 1;
|
|
102
|
+
while (j >= 0 && /\s/.test(source[j])) j--;
|
|
103
|
+
if (j < 0) return true;
|
|
104
|
+
const prev = source[j];
|
|
105
|
+
return /[{[(,;:=!&|?+\-*/%^~<>]/.test(prev);
|
|
106
|
+
}
|
|
107
|
+
__name(isRegexContext, "isRegexContext");
|
|
108
|
+
var debugLogger = createDebugLogger("WORKFLOW");
|
|
109
|
+
var MAX_LOG_LINES = 1e4;
|
|
110
|
+
var MAX_PHASE_ENTRIES = 1e4;
|
|
111
|
+
var ARGS_MAX_DEPTH = 64;
|
|
112
|
+
var DEFAULT_MAX_WALL_CLOCK_MS = 30 * 60 * 1e3;
|
|
113
|
+
function resolveMaxWallClockMs(opts) {
|
|
114
|
+
if (typeof opts.maxWallClockMs === "number" && opts.maxWallClockMs > 0) {
|
|
115
|
+
return opts.maxWallClockMs;
|
|
116
|
+
}
|
|
117
|
+
const envSec = Number(process.env["QWEN_CODE_MAX_WORKFLOW_SECONDS"]);
|
|
118
|
+
if (Number.isFinite(envSec) && envSec > 0) return envSec * 1e3;
|
|
119
|
+
return DEFAULT_MAX_WALL_CLOCK_MS;
|
|
120
|
+
}
|
|
121
|
+
__name(resolveMaxWallClockMs, "resolveMaxWallClockMs");
|
|
122
|
+
function validateArgs(val, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
|
|
123
|
+
if (depth > ARGS_MAX_DEPTH) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
`WorkflowSandbox: args exceeded max nesting depth of ${ARGS_MAX_DEPTH}`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
if (val === null) return;
|
|
129
|
+
const t = typeof val;
|
|
130
|
+
if (t === "function") {
|
|
131
|
+
throw new Error(
|
|
132
|
+
"WorkflowSandbox: args must be JSON-serializable (functions are not allowed)."
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
if (t === "bigint") {
|
|
136
|
+
throw new Error(
|
|
137
|
+
"WorkflowSandbox: args must be JSON-serializable (BigInt is not allowed \u2014 pass as string)."
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
if (t !== "object") return;
|
|
141
|
+
const obj = val;
|
|
142
|
+
if (seen.has(obj)) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
"WorkflowSandbox: args must be JSON-serializable (circular reference detected)."
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
seen.add(obj);
|
|
148
|
+
if (Array.isArray(val)) {
|
|
149
|
+
for (const item of val) validateArgs(item, depth + 1, seen);
|
|
150
|
+
} else {
|
|
151
|
+
for (const v of Object.values(val)) {
|
|
152
|
+
validateArgs(v, depth + 1, seen);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
__name(validateArgs, "validateArgs");
|
|
157
|
+
function createWorkflowSandbox(opts) {
|
|
158
|
+
const phases = [];
|
|
159
|
+
const logs = [];
|
|
160
|
+
const safeLog = /* @__PURE__ */ __name((msg) => {
|
|
161
|
+
if (logs.length < MAX_LOG_LINES) {
|
|
162
|
+
logs.push(String(msg));
|
|
163
|
+
} else if (logs.length === MAX_LOG_LINES) {
|
|
164
|
+
logs.push(`[workflow log truncated at ${MAX_LOG_LINES} lines]`);
|
|
165
|
+
}
|
|
166
|
+
}, "safeLog");
|
|
167
|
+
const safePhase = /* @__PURE__ */ __name((title) => {
|
|
168
|
+
if (phases.length < MAX_PHASE_ENTRIES) {
|
|
169
|
+
phases.push(String(title));
|
|
170
|
+
} else if (phases.length === MAX_PHASE_ENTRIES) {
|
|
171
|
+
phases.push(
|
|
172
|
+
`[workflow phases truncated at ${MAX_PHASE_ENTRIES} entries]`
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
}, "safePhase");
|
|
176
|
+
if (opts.args !== void 0) validateArgs(opts.args);
|
|
177
|
+
const argsJson = opts.args === void 0 ? null : JSON.stringify(opts.args);
|
|
178
|
+
const bridge = {
|
|
179
|
+
argsJson,
|
|
180
|
+
pushPhase: safePhase,
|
|
181
|
+
pushLog: safeLog,
|
|
182
|
+
lastPhase: /* @__PURE__ */ __name(() => phases[phases.length - 1], "lastPhase"),
|
|
183
|
+
hostAgent: opts.dispatch,
|
|
184
|
+
// PR #4947 R2 T7 (qwen-code-ci-bot): host-side log hook for reviveInRealm's
|
|
185
|
+
// catch path. Mirrors the rejection-logging in settleToNullArray so an
|
|
186
|
+
// operator running with debug logging can distinguish "thunk rejected"
|
|
187
|
+
// (settleToNullArray.warn) from "thunk resolved to a non-JSON-serializable
|
|
188
|
+
// value" (this warn). Receives only primitive strings/numbers — the bridge
|
|
189
|
+
// contract forbids host objects crossing back to the script.
|
|
190
|
+
logRevivalFailure: /* @__PURE__ */ __name((idx, reason) => {
|
|
191
|
+
debugLogger.warn(
|
|
192
|
+
`Workflow result revival failed at index ${idx}: ${reason}; slot set to null (non-JSON-serializable thunk return).`
|
|
193
|
+
);
|
|
194
|
+
}, "logRevivalFailure"),
|
|
195
|
+
// The truthy flags distinguish "injected" from "default stub" inside the
|
|
196
|
+
// init script without leaking the host function itself when not used.
|
|
197
|
+
hasParallel: !!opts.parallel,
|
|
198
|
+
hasPipeline: !!opts.pipeline,
|
|
199
|
+
hasBudget: !!opts.budget,
|
|
200
|
+
hostParallel: opts.parallel,
|
|
201
|
+
hostPipeline: opts.pipeline,
|
|
202
|
+
budgetTotal: opts.budget ? opts.budget.total : null,
|
|
203
|
+
hostBudgetSpent: opts.budget ? opts.budget.spent.bind(opts.budget) : null,
|
|
204
|
+
hostBudgetRemaining: opts.budget ? opts.budget.remaining.bind(opts.budget) : null
|
|
205
|
+
};
|
|
206
|
+
Object.setPrototypeOf(bridge, null);
|
|
207
|
+
const sandboxGlobals = Object.assign(
|
|
208
|
+
/* @__PURE__ */ Object.create(null),
|
|
209
|
+
{ __workflowBridge: bridge }
|
|
210
|
+
);
|
|
211
|
+
const ctx = vm.createContext(sandboxGlobals);
|
|
212
|
+
vm.runInContext(
|
|
213
|
+
`(() => {
|
|
214
|
+
const __b = globalThis.__workflowBridge;
|
|
215
|
+
delete globalThis.__workflowBridge;
|
|
216
|
+
|
|
217
|
+
// --- Math (vm-realm, random throws) ---
|
|
218
|
+
const realMath = Math;
|
|
219
|
+
const safeMath = Object.create(null);
|
|
220
|
+
for (const k of Object.getOwnPropertyNames(realMath)) {
|
|
221
|
+
if (k === 'random' || k === 'constructor') continue;
|
|
222
|
+
safeMath[k] = realMath[k];
|
|
223
|
+
}
|
|
224
|
+
safeMath.random = () => {
|
|
225
|
+
throw new Error(
|
|
226
|
+
'Math.random() is unavailable in workflow scripts (breaks resume). ' +
|
|
227
|
+
'For N independent samples, include the index in the agent label or prompt.'
|
|
228
|
+
);
|
|
229
|
+
};
|
|
230
|
+
globalThis.Math = safeMath;
|
|
231
|
+
|
|
232
|
+
// --- Date (vm-realm function that throws on any access) ---
|
|
233
|
+
const dateMsg = 'Date.now() / new Date() are unavailable in workflow ' +
|
|
234
|
+
'scripts (breaks resume). Stamp results after the workflow returns, ' +
|
|
235
|
+
'or pass timestamps via args.';
|
|
236
|
+
const safeDate = function Date() { throw new Error(dateMsg); };
|
|
237
|
+
safeDate.now = () => { throw new Error(dateMsg); };
|
|
238
|
+
safeDate.UTC = () => { throw new Error(dateMsg); };
|
|
239
|
+
safeDate.parse = () => { throw new Error(dateMsg); };
|
|
240
|
+
Object.setPrototypeOf(safeDate, null);
|
|
241
|
+
Object.defineProperty(safeDate, 'constructor', {
|
|
242
|
+
value: undefined, writable: false, configurable: false,
|
|
243
|
+
});
|
|
244
|
+
globalThis.Date = safeDate;
|
|
245
|
+
|
|
246
|
+
// --- args (parsed via vm-realm JSON \u2192 vm-realm objects/arrays) ---
|
|
247
|
+
// FIX-Round1-T2: vm-realm arrays keep their vm-realm Array.prototype,
|
|
248
|
+
// so for...of, .map, .forEach, spread, destructuring all work \u2014 and
|
|
249
|
+
// their inherited methods' constructors are vm-realm Function, which
|
|
250
|
+
// cannot reach host process.
|
|
251
|
+
globalThis.args = __b.argsJson === null ? undefined : JSON.parse(__b.argsJson);
|
|
252
|
+
|
|
253
|
+
// --- Wrap a host async function so it returns a vm-realm Promise ---
|
|
254
|
+
// FIX-Round1-T1/T8/T14: success and failure both cross the boundary
|
|
255
|
+
// as vm-realm values: resolve with the host's value (a primitive
|
|
256
|
+
// string for dispatch; vm-realm arrays for parallel/pipeline because
|
|
257
|
+
// those wrappers will produce vm-realm results); reject with a
|
|
258
|
+
// freshly-constructed vm-realm Error so e.constructor.constructor
|
|
259
|
+
// stays in the vm realm.
|
|
260
|
+
function vmAsync(hostFn) {
|
|
261
|
+
return function (...vmArgs) {
|
|
262
|
+
return new Promise(function (resolve, reject) {
|
|
263
|
+
try {
|
|
264
|
+
const hostPromise = hostFn.apply(null, vmArgs);
|
|
265
|
+
hostPromise.then(
|
|
266
|
+
function (value) { resolve(value); },
|
|
267
|
+
function (hostErr) {
|
|
268
|
+
const msg = (hostErr && hostErr.message != null)
|
|
269
|
+
? String(hostErr.message)
|
|
270
|
+
: String(hostErr);
|
|
271
|
+
reject(new Error(msg));
|
|
272
|
+
}
|
|
273
|
+
);
|
|
274
|
+
} catch (hostErr) {
|
|
275
|
+
const msg = (hostErr && hostErr.message != null)
|
|
276
|
+
? String(hostErr.message)
|
|
277
|
+
: String(hostErr);
|
|
278
|
+
reject(new Error(msg));
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// --- phase / log ---
|
|
285
|
+
globalThis.phase = function phase(title) {
|
|
286
|
+
__b.pushPhase(String(title));
|
|
287
|
+
};
|
|
288
|
+
globalThis.log = function log(msg) {
|
|
289
|
+
__b.pushLog(msg);
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// --- console (object with hardened methods, all in vm-realm) ---
|
|
293
|
+
const safeConsole = Object.create(null);
|
|
294
|
+
safeConsole.log = function () {
|
|
295
|
+
const parts = [];
|
|
296
|
+
for (let i = 0; i < arguments.length; i++) parts.push(String(arguments[i]));
|
|
297
|
+
__b.pushLog(parts.join(' '));
|
|
298
|
+
};
|
|
299
|
+
safeConsole.warn = safeConsole.log;
|
|
300
|
+
safeConsole.error = safeConsole.log;
|
|
301
|
+
globalThis.console = safeConsole;
|
|
302
|
+
|
|
303
|
+
// --- agent (with runtime allowlist + named throws, all vm-realm) ---
|
|
304
|
+
// FIX-Round1-T13: throw on any opts key not in the allowlist \u2014 catches
|
|
305
|
+
// typos like { scema: ... } that previously slipped through the
|
|
306
|
+
// [key:string]: unknown index signature.
|
|
307
|
+
const KNOWN_AGENT_OPTS = ['label', 'phase', 'schema', 'model', 'isolation', 'agentType'];
|
|
308
|
+
globalThis.agent = vmAsync(function (prompt, agentOpts) {
|
|
309
|
+
agentOpts = agentOpts || {};
|
|
310
|
+
const keys = Object.keys(agentOpts);
|
|
311
|
+
for (let i = 0; i < keys.length; i++) {
|
|
312
|
+
const k = keys[i];
|
|
313
|
+
if (KNOWN_AGENT_OPTS.indexOf(k) === -1) {
|
|
314
|
+
throw new Error(
|
|
315
|
+
"agent({" + k + "}): unknown option. " +
|
|
316
|
+
"Known options are: " + KNOWN_AGENT_OPTS.join(', ') + "."
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (agentOpts.schema !== undefined) {
|
|
321
|
+
throw new Error(
|
|
322
|
+
'agent({schema}) is not supported in P1. ' +
|
|
323
|
+
'Schema enforcement / StructuredOutput contract is scheduled for P3.'
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
if (agentOpts.isolation !== undefined) {
|
|
327
|
+
throw new Error(
|
|
328
|
+
"agent({isolation: '" + agentOpts.isolation + "'}) is not supported in P1. " +
|
|
329
|
+
'Worktree / remote isolation is scheduled for a later phase.'
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
if (agentOpts.model !== undefined) {
|
|
333
|
+
throw new Error(
|
|
334
|
+
'agent({model}) is not supported in P1. Model override is scheduled for a later phase.'
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
if (agentOpts.agentType !== undefined) {
|
|
338
|
+
throw new Error('agent({agentType}) is not supported in P1.');
|
|
339
|
+
}
|
|
340
|
+
if (typeof agentOpts.phase === 'string' && agentOpts.phase.length > 0) {
|
|
341
|
+
if (__b.lastPhase() !== agentOpts.phase) {
|
|
342
|
+
__b.pushPhase(agentOpts.phase);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return __b.hostAgent(prompt, agentOpts);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// --- parallel / pipeline ---
|
|
349
|
+
// SECURITY (PR #4732 P2): the host impl resolves with a HOST-realm array.
|
|
350
|
+
// vmAsync's resolve path is verbatim (it does NOT re-wrap resolved
|
|
351
|
+
// values), so handing that host array to the script would reopen the
|
|
352
|
+
// T1/T8/T14 escape: result.constructor.constructor('return process')()
|
|
353
|
+
// walks the host Array.prototype chain to the host Function constructor.
|
|
354
|
+
// We revive the array INSIDE the vm realm with JSON.parse(JSON.stringify)
|
|
355
|
+
// -- the same mechanism that makes the args global safe (see the args
|
|
356
|
+
// revival above) -- so the value the script sees has vm-realm prototypes
|
|
357
|
+
// whose constructors can't reach host process. Agent results are JSON
|
|
358
|
+
// strings (and null slots), so the round-trip is lossless for P2.
|
|
359
|
+
//
|
|
360
|
+
// EAD-1 (P2 self-review): revive PER-ELEMENT, not the whole array in one
|
|
361
|
+
// JSON.stringify. A single slot whose VALUE is non-serializable (a thunk
|
|
362
|
+
// that returns a BigInt or a circular object) must become null at its
|
|
363
|
+
// index -- it must NOT throw on the whole array and destroy every sibling
|
|
364
|
+
// result, which would defeat errors-as-data for return values. The outer
|
|
365
|
+
// [] is built in-realm here, so the result keeps vm-realm prototypes.
|
|
366
|
+
//
|
|
367
|
+
// SECURITY (PR #4947 R1 wenshao): reviveInRealm MUST remain inside this
|
|
368
|
+
// vm init runInContext block. JSON, Array, Object here are vm-realm
|
|
369
|
+
// globals; extracting this function to a host-side utility (e.g. a
|
|
370
|
+
// shared utils/jsonRevive.ts) would resolve those references against
|
|
371
|
+
// the HOST realm, silently reopening the T1/T8/T14 escape that the
|
|
372
|
+
// revival is designed to prevent. The textual identity to a host-side
|
|
373
|
+
// util is exactly the trap.
|
|
374
|
+
function reviveInRealm(hostArr) {
|
|
375
|
+
const out = [];
|
|
376
|
+
for (let i = 0; i < hostArr.length; i++) {
|
|
377
|
+
try {
|
|
378
|
+
out[i] = JSON.parse(JSON.stringify(hostArr[i]));
|
|
379
|
+
} catch (e) {
|
|
380
|
+
// Cross to host realm for debug logging. The bridge function
|
|
381
|
+
// accepts only primitive strings/numbers; the error message is
|
|
382
|
+
// coerced to a String here so no vm-realm Error object crosses.
|
|
383
|
+
__b.logRevivalFailure(i, String(e?.message ?? e));
|
|
384
|
+
out[i] = null;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return out;
|
|
388
|
+
}
|
|
389
|
+
if (__b.hasParallel) {
|
|
390
|
+
const callParallel = vmAsync(function (thunks) {
|
|
391
|
+
return __b.hostParallel(thunks);
|
|
392
|
+
});
|
|
393
|
+
globalThis.parallel = function parallel(thunks) {
|
|
394
|
+
return callParallel(thunks).then(reviveInRealm);
|
|
395
|
+
};
|
|
396
|
+
} else {
|
|
397
|
+
globalThis.parallel = function parallel() {
|
|
398
|
+
return new Promise(function (_, reject) {
|
|
399
|
+
reject(new Error(
|
|
400
|
+
'parallel() is unavailable: this sandbox was created without a ' +
|
|
401
|
+
'parallel implementation. The orchestrator injects one; a bare ' +
|
|
402
|
+
'sandbox has no concurrent-dispatch capability.'
|
|
403
|
+
));
|
|
404
|
+
});
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
if (__b.hasPipeline) {
|
|
408
|
+
const callPipeline = vmAsync(function (items) {
|
|
409
|
+
const stages = [];
|
|
410
|
+
for (let i = 1; i < arguments.length; i++) stages.push(arguments[i]);
|
|
411
|
+
return __b.hostPipeline.apply(null, [items].concat(stages));
|
|
412
|
+
});
|
|
413
|
+
globalThis.pipeline = function pipeline() {
|
|
414
|
+
return callPipeline.apply(null, arguments).then(reviveInRealm);
|
|
415
|
+
};
|
|
416
|
+
} else {
|
|
417
|
+
globalThis.pipeline = function pipeline() {
|
|
418
|
+
return new Promise(function (_, reject) {
|
|
419
|
+
reject(new Error(
|
|
420
|
+
'pipeline() is unavailable: this sandbox was created without a ' +
|
|
421
|
+
'pipeline implementation. The orchestrator injects one; a bare ' +
|
|
422
|
+
'sandbox has no staggered multi-stage capability.'
|
|
423
|
+
));
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
// workflow() always throws in P1.
|
|
428
|
+
globalThis.workflow = function workflow() {
|
|
429
|
+
return new Promise(function (_, reject) {
|
|
430
|
+
reject(new Error(
|
|
431
|
+
'workflow() (nested workflow invocation) is not supported in P1. ' +
|
|
432
|
+
'Scheduled for a later phase.'
|
|
433
|
+
));
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
// --- budget ---
|
|
438
|
+
const safeBudget = Object.create(null);
|
|
439
|
+
Object.defineProperty(safeBudget, 'total', {
|
|
440
|
+
value: __b.budgetTotal,
|
|
441
|
+
writable: false, configurable: false,
|
|
442
|
+
});
|
|
443
|
+
if (__b.hasBudget) {
|
|
444
|
+
Object.defineProperty(safeBudget, 'spent', {
|
|
445
|
+
value: function spent() { return __b.hostBudgetSpent(); },
|
|
446
|
+
writable: false, configurable: false,
|
|
447
|
+
});
|
|
448
|
+
Object.defineProperty(safeBudget, 'remaining', {
|
|
449
|
+
value: function remaining() { return __b.hostBudgetRemaining(); },
|
|
450
|
+
writable: false, configurable: false,
|
|
451
|
+
});
|
|
452
|
+
} else {
|
|
453
|
+
Object.defineProperty(safeBudget, 'spent', {
|
|
454
|
+
value: function spent() {
|
|
455
|
+
throw new Error(
|
|
456
|
+
'budget.spent() is not supported in P1. Token tracking is scheduled for P5.'
|
|
457
|
+
);
|
|
458
|
+
},
|
|
459
|
+
writable: false, configurable: false,
|
|
460
|
+
});
|
|
461
|
+
Object.defineProperty(safeBudget, 'remaining', {
|
|
462
|
+
value: function remaining() {
|
|
463
|
+
throw new Error(
|
|
464
|
+
'budget.remaining() is not supported in P1. Token tracking is scheduled for P5.'
|
|
465
|
+
);
|
|
466
|
+
},
|
|
467
|
+
writable: false, configurable: false,
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
globalThis.budget = safeBudget;
|
|
471
|
+
})();`,
|
|
472
|
+
ctx,
|
|
473
|
+
{ filename: "workflow-sandbox-init.js" }
|
|
474
|
+
);
|
|
475
|
+
const maxWallClockMs = resolveMaxWallClockMs(opts);
|
|
476
|
+
return {
|
|
477
|
+
async run(scriptSource) {
|
|
478
|
+
const stripped = stripExportMeta(scriptSource);
|
|
479
|
+
const wrapped = `(async () => {
|
|
480
|
+
${stripped}
|
|
481
|
+
})()`;
|
|
482
|
+
const script = new vm.Script(wrapped, {
|
|
483
|
+
filename: "workflow.js"
|
|
484
|
+
});
|
|
485
|
+
const runOpts = {
|
|
486
|
+
timeout: 3e4
|
|
487
|
+
};
|
|
488
|
+
const result = script.runInContext(ctx, runOpts);
|
|
489
|
+
let timer;
|
|
490
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
491
|
+
timer = setTimeout(() => {
|
|
492
|
+
opts.abortOnTimeout?.abort();
|
|
493
|
+
reject(
|
|
494
|
+
new Error(
|
|
495
|
+
`Workflow execution timed out after ${maxWallClockMs} ms wall clock. Override via SandboxOptions.maxWallClockMs or QWEN_CODE_MAX_WORKFLOW_SECONDS env var.`
|
|
496
|
+
)
|
|
497
|
+
);
|
|
498
|
+
}, maxWallClockMs);
|
|
499
|
+
timer.unref?.();
|
|
500
|
+
});
|
|
501
|
+
try {
|
|
502
|
+
return await Promise.race([result, timeoutPromise]);
|
|
503
|
+
} finally {
|
|
504
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
getPhases: /* @__PURE__ */ __name(() => [...phases], "getPhases"),
|
|
508
|
+
getLogs: /* @__PURE__ */ __name(() => [...logs], "getLogs")
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
__name(createWorkflowSandbox, "createWorkflowSandbox");
|
|
512
|
+
|
|
513
|
+
// packages/core/src/agents/runtime/workflow-prompts.ts
|
|
514
|
+
init_esbuild_shims();
|
|
515
|
+
var WORKFLOW_SUBAGENT_SYSTEM_PROMPT = 'You are a subagent spawned by a workflow orchestration script. Use the tools available to complete the task.\nCRITICAL: Your final text response is returned **verbatim** as a string to the calling script \u2014 it is your return value, not a message to a human.\n- Output the literal result (data, JSON, text). Do NOT output confirmations like "Done." or "Sent."\n- If asked for JSON, return ONLY the raw JSON \u2014 no code fences, no prose, no markdown.\n- Do NOT use SendUserMessage to deliver your answer. Put your answer in your final text response.\n- Be concise. The script will parse your output.';
|
|
516
|
+
|
|
517
|
+
// packages/core/src/utils/concurrencyLimiter.ts
|
|
518
|
+
init_esbuild_shims();
|
|
519
|
+
function abortError() {
|
|
520
|
+
return new DOMException("Concurrency limiter aborted.", "AbortError");
|
|
521
|
+
}
|
|
522
|
+
__name(abortError, "abortError");
|
|
523
|
+
function createConcurrencyLimiter(limit, signal) {
|
|
524
|
+
if (!Number.isInteger(limit) || limit < 1) {
|
|
525
|
+
throw new Error(
|
|
526
|
+
`Concurrency limit must be a positive integer, got ${String(limit)}.`
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
let active = 0;
|
|
530
|
+
const queue = [];
|
|
531
|
+
const pump = /* @__PURE__ */ __name(() => {
|
|
532
|
+
while (active < limit && queue.length > 0) {
|
|
533
|
+
const job = queue.shift();
|
|
534
|
+
if (signal?.aborted) {
|
|
535
|
+
job.reject(abortError());
|
|
536
|
+
continue;
|
|
537
|
+
}
|
|
538
|
+
active++;
|
|
539
|
+
Promise.resolve().then(job.thunk).then(job.resolve, job.reject).finally(() => {
|
|
540
|
+
active--;
|
|
541
|
+
pump();
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
}, "pump");
|
|
545
|
+
const run = /* @__PURE__ */ __name((thunk) => new Promise((resolve, reject) => {
|
|
546
|
+
if (signal?.aborted) {
|
|
547
|
+
reject(abortError());
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
queue.push({
|
|
551
|
+
thunk,
|
|
552
|
+
resolve,
|
|
553
|
+
reject
|
|
554
|
+
});
|
|
555
|
+
pump();
|
|
556
|
+
}), "run");
|
|
557
|
+
if (signal && !signal.aborted) {
|
|
558
|
+
signal.addEventListener(
|
|
559
|
+
"abort",
|
|
560
|
+
() => {
|
|
561
|
+
while (queue.length > 0) queue.shift().reject(abortError());
|
|
562
|
+
},
|
|
563
|
+
{ once: true }
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
return { run };
|
|
567
|
+
}
|
|
568
|
+
__name(createConcurrencyLimiter, "createConcurrencyLimiter");
|
|
569
|
+
|
|
570
|
+
// packages/core/src/agents/runtime/workflow-orchestrator.ts
|
|
571
|
+
var DEFAULT_MAX_AGENTS_PER_RUN = 1e3;
|
|
572
|
+
var MAX_WORKFLOW_AGENTS_ENV = "QWEN_CODE_MAX_WORKFLOW_AGENTS";
|
|
573
|
+
var HARD_MAX_AGENTS_PER_RUN_CEILING = 1e4;
|
|
574
|
+
function resolveMaxAgentsPerRun(env = process.env) {
|
|
575
|
+
const raw = env[MAX_WORKFLOW_AGENTS_ENV];
|
|
576
|
+
if (raw === void 0 || raw.trim() === "") {
|
|
577
|
+
return DEFAULT_MAX_AGENTS_PER_RUN;
|
|
578
|
+
}
|
|
579
|
+
const parsed = Number(raw);
|
|
580
|
+
if (!Number.isInteger(parsed) || parsed < 1) {
|
|
581
|
+
debugLogger.warn(
|
|
582
|
+
`Invalid ${MAX_WORKFLOW_AGENTS_ENV}=${JSON.stringify(raw)}, using default (${DEFAULT_MAX_AGENTS_PER_RUN})`
|
|
583
|
+
);
|
|
584
|
+
return DEFAULT_MAX_AGENTS_PER_RUN;
|
|
585
|
+
}
|
|
586
|
+
if (parsed > HARD_MAX_AGENTS_PER_RUN_CEILING) {
|
|
587
|
+
debugLogger.warn(
|
|
588
|
+
`${MAX_WORKFLOW_AGENTS_ENV}=${parsed} exceeds hard ceiling (${HARD_MAX_AGENTS_PER_RUN_CEILING}); clamping.`
|
|
589
|
+
);
|
|
590
|
+
return HARD_MAX_AGENTS_PER_RUN_CEILING;
|
|
591
|
+
}
|
|
592
|
+
return parsed;
|
|
593
|
+
}
|
|
594
|
+
__name(resolveMaxAgentsPerRun, "resolveMaxAgentsPerRun");
|
|
595
|
+
var MAX_WORKFLOW_CONCURRENCY_ENV = "QWEN_CODE_MAX_WORKFLOW_CONCURRENCY";
|
|
596
|
+
var HARD_MAX_CONCURRENCY_CEILING = 64;
|
|
597
|
+
function resolveConcurrencyLimit(env = process.env) {
|
|
598
|
+
const raw = env[MAX_WORKFLOW_CONCURRENCY_ENV];
|
|
599
|
+
if (raw !== void 0 && raw.trim() !== "") {
|
|
600
|
+
const parsed = Number(raw);
|
|
601
|
+
if (Number.isInteger(parsed) && parsed >= 1) {
|
|
602
|
+
if (parsed > HARD_MAX_CONCURRENCY_CEILING) {
|
|
603
|
+
debugLogger.warn(
|
|
604
|
+
`${MAX_WORKFLOW_CONCURRENCY_ENV}=${parsed} exceeds hard ceiling (${HARD_MAX_CONCURRENCY_CEILING}); clamping.`
|
|
605
|
+
);
|
|
606
|
+
return HARD_MAX_CONCURRENCY_CEILING;
|
|
607
|
+
}
|
|
608
|
+
return parsed;
|
|
609
|
+
}
|
|
610
|
+
debugLogger.warn(
|
|
611
|
+
`Invalid ${MAX_WORKFLOW_CONCURRENCY_ENV}=${JSON.stringify(raw)}, using cpu-derived default`
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
return Math.max(1, Math.min(16, os.cpus().length - 2));
|
|
615
|
+
}
|
|
616
|
+
__name(resolveConcurrencyLimit, "resolveConcurrencyLimit");
|
|
617
|
+
var WORKFLOW_SUBAGENT_MAX_TURNS = 50;
|
|
618
|
+
var WORKFLOW_SUBAGENT_MAX_TIME_MINUTES = 10;
|
|
619
|
+
var WORKFLOW_SUBAGENT_DISALLOWED_TOOLS = [
|
|
620
|
+
ToolNames.SEND_MESSAGE,
|
|
621
|
+
ToolNames.EXIT_PLAN_MODE
|
|
622
|
+
];
|
|
623
|
+
var WorkflowExecutionError = class extends Error {
|
|
624
|
+
constructor(message, phases, logs) {
|
|
625
|
+
super(message);
|
|
626
|
+
this.phases = phases;
|
|
627
|
+
this.logs = logs;
|
|
628
|
+
}
|
|
629
|
+
static {
|
|
630
|
+
__name(this, "WorkflowExecutionError");
|
|
631
|
+
}
|
|
632
|
+
name = "WorkflowExecutionError";
|
|
633
|
+
};
|
|
634
|
+
function generateRunId() {
|
|
635
|
+
return `wf_${randomBytes(8).toString("hex")}`;
|
|
636
|
+
}
|
|
637
|
+
__name(generateRunId, "generateRunId");
|
|
638
|
+
function createProductionDispatch(config, signal) {
|
|
639
|
+
return async (prompt, opts) => {
|
|
640
|
+
const { AgentHeadless, ContextState } = await import("./agent-headless-5Q2EUSPS.js");
|
|
641
|
+
const ctx = new ContextState();
|
|
642
|
+
ctx.set("task_prompt", prompt);
|
|
643
|
+
const subagent = await AgentHeadless.create(
|
|
644
|
+
opts.label ?? "workflow-agent",
|
|
645
|
+
config,
|
|
646
|
+
{
|
|
647
|
+
systemPrompt: WORKFLOW_SUBAGENT_SYSTEM_PROMPT,
|
|
648
|
+
initialMessages: []
|
|
649
|
+
},
|
|
650
|
+
{},
|
|
651
|
+
// T11 (PR #4732 R1): bound resource ceiling so a single agent() call
|
|
652
|
+
// cannot loop the model indefinitely. Without this, runConfig was {}
|
|
653
|
+
// and the loop guards never tripped — combined with the cancellation
|
|
654
|
+
// bug below, workflows were effectively unkillable.
|
|
655
|
+
{
|
|
656
|
+
max_turns: WORKFLOW_SUBAGENT_MAX_TURNS,
|
|
657
|
+
max_time_minutes: WORKFLOW_SUBAGENT_MAX_TIME_MINUTES
|
|
658
|
+
},
|
|
659
|
+
// T11 (PR #4732 R1): disallow SendMessage / ExitPlanMode to align with
|
|
660
|
+
// upstream Tg8 — closes the back-channel that would let a subagent
|
|
661
|
+
// deliver its answer via user message instead of the script's read.
|
|
662
|
+
{ tools: ["*"], disallowedTools: WORKFLOW_SUBAGENT_DISALLOWED_TOOLS }
|
|
663
|
+
);
|
|
664
|
+
await subagent.execute(ctx, signal);
|
|
665
|
+
const mode = subagent.getTerminateMode();
|
|
666
|
+
if (mode !== "GOAL" /* GOAL */) {
|
|
667
|
+
throw new Error(
|
|
668
|
+
`Workflow subagent did not complete (terminate mode: ${mode}).`
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
return subagent.getFinalText();
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
__name(createProductionDispatch, "createProductionDispatch");
|
|
675
|
+
var WorkflowOrchestrator = class {
|
|
676
|
+
constructor(dispatch) {
|
|
677
|
+
this.dispatch = dispatch;
|
|
678
|
+
}
|
|
679
|
+
static {
|
|
680
|
+
__name(this, "WorkflowOrchestrator");
|
|
681
|
+
}
|
|
682
|
+
async run(req) {
|
|
683
|
+
const runId = generateRunId();
|
|
684
|
+
const maxAgents = resolveMaxAgentsPerRun();
|
|
685
|
+
const signal = req.abortOnTimeout?.signal;
|
|
686
|
+
const limiter = createConcurrencyLimiter(resolveConcurrencyLimit(), signal);
|
|
687
|
+
let agentCount = 0;
|
|
688
|
+
const countedDispatch = /* @__PURE__ */ __name((prompt, opts) => {
|
|
689
|
+
agentCount += 1;
|
|
690
|
+
if (agentCount > maxAgents) {
|
|
691
|
+
return Promise.reject(
|
|
692
|
+
new Error(
|
|
693
|
+
`Workflow exceeded the maximum of ${maxAgents} agent() calls per run.`
|
|
694
|
+
)
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
return limiter.run(() => this.dispatch(prompt, opts));
|
|
698
|
+
}, "countedDispatch");
|
|
699
|
+
const parallelImpl = makeParallelImpl(signal);
|
|
700
|
+
const pipelineImpl = makePipelineImpl(signal);
|
|
701
|
+
const sandbox = createWorkflowSandbox({
|
|
702
|
+
args: req.args,
|
|
703
|
+
dispatch: countedDispatch,
|
|
704
|
+
parallel: parallelImpl,
|
|
705
|
+
pipeline: pipelineImpl,
|
|
706
|
+
abortOnTimeout: req.abortOnTimeout
|
|
707
|
+
});
|
|
708
|
+
try {
|
|
709
|
+
const result = await sandbox.run(req.script);
|
|
710
|
+
return {
|
|
711
|
+
runId,
|
|
712
|
+
result,
|
|
713
|
+
phases: sandbox.getPhases(),
|
|
714
|
+
logs: sandbox.getLogs()
|
|
715
|
+
};
|
|
716
|
+
} catch (err) {
|
|
717
|
+
throw new WorkflowExecutionError(
|
|
718
|
+
extractErrorMessage(err),
|
|
719
|
+
sandbox.getPhases(),
|
|
720
|
+
sandbox.getLogs()
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
async function settleToNullArray(thunks, signal) {
|
|
726
|
+
const settled = await Promise.allSettled(
|
|
727
|
+
thunks.map((t) => Promise.resolve().then(t))
|
|
728
|
+
);
|
|
729
|
+
if (signal?.aborted)
|
|
730
|
+
throw new DOMException("Workflow run aborted.", "AbortError");
|
|
731
|
+
return settled.map((r, i) => {
|
|
732
|
+
if (r.status === "fulfilled") return r.value;
|
|
733
|
+
debugLogger.warn(
|
|
734
|
+
`Workflow thunk at index ${i} rejected: ${String(r.reason?.message ?? r.reason)}`
|
|
735
|
+
);
|
|
736
|
+
return null;
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
__name(settleToNullArray, "settleToNullArray");
|
|
740
|
+
function makeParallelImpl(signal) {
|
|
741
|
+
return (thunks) => {
|
|
742
|
+
if (!Array.isArray(thunks)) {
|
|
743
|
+
return Promise.reject(
|
|
744
|
+
new Error(
|
|
745
|
+
"parallel() expects an array of thunks (functions returning promises)."
|
|
746
|
+
)
|
|
747
|
+
);
|
|
748
|
+
}
|
|
749
|
+
for (const t of thunks) {
|
|
750
|
+
if (typeof t !== "function") {
|
|
751
|
+
return Promise.reject(
|
|
752
|
+
new Error(
|
|
753
|
+
"parallel() expects an array of functions, not values \u2014 wrap each call: parallel([() => agent(...), () => agent(...)])."
|
|
754
|
+
)
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
return settleToNullArray(thunks, signal);
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
__name(makeParallelImpl, "makeParallelImpl");
|
|
762
|
+
function makePipelineImpl(signal) {
|
|
763
|
+
return (items, ...stages) => {
|
|
764
|
+
if (!Array.isArray(items)) {
|
|
765
|
+
return Promise.reject(
|
|
766
|
+
new Error(
|
|
767
|
+
"pipeline() expects an array of items as its first argument."
|
|
768
|
+
)
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
for (const s of stages) {
|
|
772
|
+
if (typeof s !== "function") {
|
|
773
|
+
return Promise.reject(
|
|
774
|
+
new Error(
|
|
775
|
+
"pipeline() stages must be functions: pipeline(items, item => ..., result => ...)."
|
|
776
|
+
)
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
const chains = items.map(
|
|
781
|
+
(item, idx) => () => runPipelineChain(item, idx, stages)
|
|
782
|
+
);
|
|
783
|
+
return settleToNullArray(chains, signal);
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
__name(makePipelineImpl, "makePipelineImpl");
|
|
787
|
+
async function runPipelineChain(item, idx, stages) {
|
|
788
|
+
let prev = item;
|
|
789
|
+
for (const stage of stages) {
|
|
790
|
+
if (prev === null) break;
|
|
791
|
+
prev = await stage(prev, item, idx);
|
|
792
|
+
}
|
|
793
|
+
return prev;
|
|
794
|
+
}
|
|
795
|
+
__name(runPipelineChain, "runPipelineChain");
|
|
796
|
+
function extractErrorMessage(err) {
|
|
797
|
+
if (err && typeof err === "object" && "message" in err) {
|
|
798
|
+
const m = err.message;
|
|
799
|
+
if (typeof m === "string") return m;
|
|
800
|
+
return String(m);
|
|
801
|
+
}
|
|
802
|
+
return String(err);
|
|
803
|
+
}
|
|
804
|
+
__name(extractErrorMessage, "extractErrorMessage");
|
|
805
|
+
|
|
806
|
+
// packages/core/src/tools/workflow/workflow.ts
|
|
807
|
+
var WORKFLOW_PARAM_SCHEMA = {
|
|
808
|
+
type: "object",
|
|
809
|
+
properties: {
|
|
810
|
+
script: {
|
|
811
|
+
type: "string",
|
|
812
|
+
description: "JavaScript source of the workflow. Wrapped as an async IIFE. May call the injected globals `phase(title)`, `log(msg)`, `agent(prompt, { label? })`, and read `args`. Concurrency: `parallel([() => agent(...), ...])` runs thunks through a shared per-run window (default `max(1, min(16, cpus-2))` agents in flight; override via `QWEN_CODE_MAX_WORKFLOW_CONCURRENCY`) and resolves to a position-aligned array \u2014 a thunk that throws, or resolves to a non-JSON-serializable value, becomes `null` at its index (errors-as-data); parallel() itself rejects only on invalid arguments or abort. `pipeline(items, ...stages)` runs each item through the stages (staggered, no inter-stage barrier); a stage that throws, returns `null`, or returns a non-JSON-serializable value drops that item to `null`. Pass THUNKS to parallel, not eager calls: `parallel([() => agent(...)])`, not `parallel([agent(...)])`. At most 1000 agent() calls per run (override via `QWEN_CODE_MAX_WORKFLOW_AGENTS`). `Date.now()` and `Math.random()` both throw \u2014 workflow scripts must be deterministic for resume. `export const meta = {...}` declarations are stripped before execution."
|
|
813
|
+
},
|
|
814
|
+
args: {
|
|
815
|
+
description: "Optional structured value bound to the `args` global. Pass actual JSON, not a stringified value."
|
|
816
|
+
}
|
|
817
|
+
},
|
|
818
|
+
required: ["script"]
|
|
819
|
+
};
|
|
820
|
+
var WorkflowToolInvocation = class extends BaseToolInvocation {
|
|
821
|
+
constructor(config, toolOptions, params) {
|
|
822
|
+
super(params);
|
|
823
|
+
this.config = config;
|
|
824
|
+
this.toolOptions = toolOptions;
|
|
825
|
+
}
|
|
826
|
+
static {
|
|
827
|
+
__name(this, "WorkflowToolInvocation");
|
|
828
|
+
}
|
|
829
|
+
getDescription() {
|
|
830
|
+
return `Run a workflow script (${this.params.script.length} chars)`;
|
|
831
|
+
}
|
|
832
|
+
toolLocations() {
|
|
833
|
+
return [];
|
|
834
|
+
}
|
|
835
|
+
getDefaultPermission() {
|
|
836
|
+
return Promise.resolve("ask");
|
|
837
|
+
}
|
|
838
|
+
async execute(signal, _updateOutput, _shellExecutionConfig) {
|
|
839
|
+
const dispatchController = createChildAbortController(signal);
|
|
840
|
+
const dispatch = this.toolOptions.dispatch ?? createProductionDispatch(this.config, dispatchController.signal);
|
|
841
|
+
const orchestrator = new WorkflowOrchestrator(dispatch);
|
|
842
|
+
try {
|
|
843
|
+
const outcome = await orchestrator.run({
|
|
844
|
+
script: this.params.script,
|
|
845
|
+
args: this.params.args,
|
|
846
|
+
abortOnTimeout: dispatchController
|
|
847
|
+
});
|
|
848
|
+
const llmText = safeStringifyResult(outcome.result);
|
|
849
|
+
const displayJson = safeStringifyDisplayPayload({
|
|
850
|
+
runId: outcome.runId,
|
|
851
|
+
phases: outcome.phases,
|
|
852
|
+
logs: outcome.logs,
|
|
853
|
+
result: outcome.result
|
|
854
|
+
});
|
|
855
|
+
return {
|
|
856
|
+
llmContent: [{ text: llmText }],
|
|
857
|
+
returnDisplay: "```json\n" + displayJson + "\n```"
|
|
858
|
+
};
|
|
859
|
+
} catch (err) {
|
|
860
|
+
const message = extractErrorMessage2(err);
|
|
861
|
+
const phases = err instanceof WorkflowExecutionError ? err.phases : void 0;
|
|
862
|
+
const logs = err instanceof WorkflowExecutionError ? err.logs : void 0;
|
|
863
|
+
const display = phases || logs ? `Workflow failed: ${message}
|
|
864
|
+
|
|
865
|
+
${safeStringifyDisplayPayload({
|
|
866
|
+
phases: phases ?? [],
|
|
867
|
+
logs: logs ?? []
|
|
868
|
+
})}` : `Workflow failed: ${message}`;
|
|
869
|
+
return {
|
|
870
|
+
llmContent: [{ text: `Workflow failed: ${message}` }],
|
|
871
|
+
returnDisplay: display,
|
|
872
|
+
// FIX-10 (REUSE-I1): use the standard ToolErrorType.EXECUTION_FAILED
|
|
873
|
+
// code so error routing / dashboards can classify workflow failures
|
|
874
|
+
// the same way as other execution-time tool errors.
|
|
875
|
+
error: { message, type: "execution_failed" /* EXECUTION_FAILED */ }
|
|
876
|
+
};
|
|
877
|
+
} finally {
|
|
878
|
+
dispatchController.abort();
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
function safeStringifyResult(result) {
|
|
883
|
+
if (result === void 0) return "(workflow returned no value)";
|
|
884
|
+
if (typeof result === "string") return result;
|
|
885
|
+
try {
|
|
886
|
+
return JSON.stringify(result, null, 2);
|
|
887
|
+
} catch {
|
|
888
|
+
return `(workflow returned a non-JSON-serializable value of type ${typeof result})`;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
__name(safeStringifyResult, "safeStringifyResult");
|
|
892
|
+
function safeStringifyDisplayPayload(payload) {
|
|
893
|
+
try {
|
|
894
|
+
return JSON.stringify(payload, null, 2);
|
|
895
|
+
} catch {
|
|
896
|
+
if (payload && typeof payload === "object") {
|
|
897
|
+
const sanitized = {};
|
|
898
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
899
|
+
try {
|
|
900
|
+
JSON.stringify(value);
|
|
901
|
+
sanitized[key] = value;
|
|
902
|
+
} catch {
|
|
903
|
+
sanitized[key] = `(non-JSON-serializable value of type ${typeof value})`;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
try {
|
|
907
|
+
return JSON.stringify(sanitized, null, 2);
|
|
908
|
+
} catch {
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return "(display payload not JSON-serializable)";
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
__name(safeStringifyDisplayPayload, "safeStringifyDisplayPayload");
|
|
915
|
+
function extractErrorMessage2(err) {
|
|
916
|
+
if (err && typeof err === "object" && "message" in err) {
|
|
917
|
+
const m = err.message;
|
|
918
|
+
if (typeof m === "string") return m;
|
|
919
|
+
return String(m);
|
|
920
|
+
}
|
|
921
|
+
return String(err);
|
|
922
|
+
}
|
|
923
|
+
__name(extractErrorMessage2, "extractErrorMessage");
|
|
924
|
+
var WorkflowTool = class extends BaseDeclarativeTool {
|
|
925
|
+
constructor(config, toolOptions = {}) {
|
|
926
|
+
super(
|
|
927
|
+
ToolNames.WORKFLOW,
|
|
928
|
+
ToolDisplayNames.WORKFLOW,
|
|
929
|
+
"Execute a workflow script that orchestrates subagents. Supports `phase`, `log`, sequential `agent`, and concurrent fan-out via `parallel(thunks)` / `pipeline(items, ...stages)` (default `max(1, min(16, cpus-2))` agents in flight per run, up to 1000 agents total; both env-overridable). No schema, no resume, no background execution yet. Scripts run in a node:vm sandbox without access to the filesystem or shell; all I/O happens through the spawned agents.",
|
|
930
|
+
"other" /* Other */,
|
|
931
|
+
WORKFLOW_PARAM_SCHEMA,
|
|
932
|
+
/* isOutputMarkdown */
|
|
933
|
+
true,
|
|
934
|
+
/* canUpdateOutput */
|
|
935
|
+
false
|
|
936
|
+
);
|
|
937
|
+
this.config = config;
|
|
938
|
+
this.toolOptions = toolOptions;
|
|
939
|
+
}
|
|
940
|
+
static {
|
|
941
|
+
__name(this, "WorkflowTool");
|
|
942
|
+
}
|
|
943
|
+
validateToolParamValues(params) {
|
|
944
|
+
if (typeof params.script !== "string" || params.script.length === 0) {
|
|
945
|
+
return "WorkflowTool: `script` parameter is required and must be a non-empty string.";
|
|
946
|
+
}
|
|
947
|
+
return null;
|
|
948
|
+
}
|
|
949
|
+
createInvocation(params) {
|
|
950
|
+
return new WorkflowToolInvocation(this.config, this.toolOptions, params);
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
export {
|
|
954
|
+
WorkflowTool
|
|
955
|
+
};
|
|
956
|
+
/**
|
|
957
|
+
* @license
|
|
958
|
+
* Copyright 2025 Qwen
|
|
959
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
960
|
+
*/
|