@te-river/opencode-team-mode 1.7.2 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/README.md +1008 -849
  2. package/README.zh-CN.md +905 -756
  3. package/dist/host/v2-browser-gate.d.ts +4 -1
  4. package/dist/host/v2-browser-gate.d.ts.map +1 -1
  5. package/dist/host/v2-browser-gate.js +1 -1
  6. package/dist/host/v2-browser-gate.js.map +1 -1
  7. package/dist/host/v2-capabilities.js +1 -1
  8. package/dist/host/v2-capabilities.js.map +1 -1
  9. package/dist/host/v2-events.d.ts +8 -2
  10. package/dist/host/v2-events.d.ts.map +1 -1
  11. package/dist/host/v2-events.js +16 -2
  12. package/dist/host/v2-events.js.map +1 -1
  13. package/dist/host/v2-guard.d.ts +3 -45
  14. package/dist/host/v2-guard.d.ts.map +1 -1
  15. package/dist/host/v2-guard.js +10 -73
  16. package/dist/host/v2-guard.js.map +1 -1
  17. package/dist/host/v2-offload.d.ts +12 -2
  18. package/dist/host/v2-offload.d.ts.map +1 -1
  19. package/dist/host/v2-offload.js +9 -9
  20. package/dist/host/v2-offload.js.map +1 -1
  21. package/dist/host/v2-probe-chain.d.ts +5 -1
  22. package/dist/host/v2-probe-chain.d.ts.map +1 -1
  23. package/dist/host/v2-probe-chain.js +4 -6
  24. package/dist/host/v2-probe-chain.js.map +1 -1
  25. package/dist/host/v2-probe.d.ts.map +1 -1
  26. package/dist/host/v2-probe.js +2 -1
  27. package/dist/host/v2-probe.js.map +1 -1
  28. package/dist/host/v2-prune.d.ts +5 -1
  29. package/dist/host/v2-prune.d.ts.map +1 -1
  30. package/dist/host/v2-prune.js +8 -14
  31. package/dist/host/v2-prune.js.map +1 -1
  32. package/dist/host/v2-retry.d.ts +10 -3
  33. package/dist/host/v2-retry.d.ts.map +1 -1
  34. package/dist/host/v2-retry.js +14 -16
  35. package/dist/host/v2-retry.js.map +1 -1
  36. package/dist/host/v2-session.d.ts +6 -2
  37. package/dist/host/v2-session.d.ts.map +1 -1
  38. package/dist/host/v2-session.js +7 -13
  39. package/dist/host/v2-session.js.map +1 -1
  40. package/dist/host/v2.d.ts +0 -5
  41. package/dist/host/v2.d.ts.map +1 -1
  42. package/dist/host/v2.js +32 -73
  43. package/dist/host/v2.js.map +1 -1
  44. package/dist/prompts/lead.d.ts +1 -1
  45. package/dist/prompts/lead.d.ts.map +1 -1
  46. package/dist/prompts/lead.js +47 -19
  47. package/dist/prompts/lead.js.map +1 -1
  48. package/dist/prompts/shared.d.ts +1 -1
  49. package/dist/prompts/shared.d.ts.map +1 -1
  50. package/dist/prompts/shared.js +16 -0
  51. package/dist/prompts/shared.js.map +1 -1
  52. package/dist/prompts/specialists.d.ts +1 -1
  53. package/dist/prompts/specialists.d.ts.map +1 -1
  54. package/dist/prompts/specialists.js +1 -1
  55. package/dist/tm/args-schema.d.ts +1 -1
  56. package/dist/tm/args-schema.js +6 -6
  57. package/dist/tm/args-schema.js.map +1 -1
  58. package/dist/tm/board.js +2 -2
  59. package/dist/tm/board.js.map +1 -1
  60. package/dist/tm/config-files.d.ts +41 -17
  61. package/dist/tm/config-files.d.ts.map +1 -1
  62. package/dist/tm/config-files.js +68 -73
  63. package/dist/tm/config-files.js.map +1 -1
  64. package/dist/tm/config-layers.d.ts +65 -33
  65. package/dist/tm/config-layers.d.ts.map +1 -1
  66. package/dist/tm/config-layers.js +164 -81
  67. package/dist/tm/config-layers.js.map +1 -1
  68. package/dist/tm/config-template.d.ts +32 -0
  69. package/dist/tm/config-template.d.ts.map +1 -0
  70. package/dist/tm/config-template.js +74 -0
  71. package/dist/tm/config-template.js.map +1 -0
  72. package/dist/tm/config.d.ts +113 -140
  73. package/dist/tm/config.d.ts.map +1 -1
  74. package/dist/tm/config.js +100 -200
  75. package/dist/tm/config.js.map +1 -1
  76. package/dist/tm/dispatch.d.ts +0 -9
  77. package/dist/tm/dispatch.d.ts.map +1 -1
  78. package/dist/tm/dispatch.js +14 -16
  79. package/dist/tm/dispatch.js.map +1 -1
  80. package/dist/tm/index.d.ts +12 -12
  81. package/dist/tm/index.d.ts.map +1 -1
  82. package/dist/tm/index.js +48 -26
  83. package/dist/tm/index.js.map +1 -1
  84. package/dist/tm/ledger.d.ts +7 -3
  85. package/dist/tm/ledger.d.ts.map +1 -1
  86. package/dist/tm/ledger.js +5 -4
  87. package/dist/tm/ledger.js.map +1 -1
  88. package/dist/tm/memory.js +3 -3
  89. package/dist/tm/pipelines.js +1 -1
  90. package/dist/tm/search.js +6 -6
  91. package/dist/tm/search.js.map +1 -1
  92. package/dist/tm/stats.js +2 -2
  93. package/dist/tm/stats.js.map +1 -1
  94. package/dist/tm/tools.js +2 -2
  95. package/dist/tm/webfetch.d.ts +5 -2
  96. package/dist/tm/webfetch.d.ts.map +1 -1
  97. package/dist/tm/webfetch.js +24 -18
  98. package/dist/tm/webfetch.js.map +1 -1
  99. package/docs/installation-v2.md +59 -38
  100. package/docs/installation.md +4 -4
  101. package/package.json +1 -1
  102. package/scripts/gen-v2-config.mjs +8 -7
  103. package/dist/approval-gate.d.ts +0 -205
  104. package/dist/approval-gate.d.ts.map +0 -1
  105. package/dist/approval-gate.js +0 -627
  106. package/dist/approval-gate.js.map +0 -1
  107. package/dist/host/v1.d.ts +0 -14
  108. package/dist/host/v1.d.ts.map +0 -1
  109. package/dist/host/v1.js +0 -340
  110. package/dist/host/v1.js.map +0 -1
  111. package/dist/host/v2-client.d.ts +0 -53
  112. package/dist/host/v2-client.d.ts.map +0 -1
  113. package/dist/host/v2-client.js +0 -193
  114. package/dist/host/v2-client.js.map +0 -1
  115. package/dist/host/v2-transcript.d.ts +0 -73
  116. package/dist/host/v2-transcript.d.ts.map +0 -1
  117. package/dist/host/v2-transcript.js +0 -151
  118. package/dist/host/v2-transcript.js.map +0 -1
  119. package/dist/host-hooks.d.ts +0 -126
  120. package/dist/host-hooks.d.ts.map +0 -1
  121. package/dist/host-hooks.js +0 -284
  122. package/dist/host-hooks.js.map +0 -1
  123. package/dist/tm/bash-timeout.d.ts +0 -72
  124. package/dist/tm/bash-timeout.d.ts.map +0 -1
  125. package/dist/tm/bash-timeout.js +0 -100
  126. package/dist/tm/bash-timeout.js.map +0 -1
  127. package/dist/tm/browser.d.ts +0 -642
  128. package/dist/tm/browser.d.ts.map +0 -1
  129. package/dist/tm/browser.js +0 -2836
  130. package/dist/tm/browser.js.map +0 -1
  131. package/dist/tm/ptc/budgets.d.ts +0 -59
  132. package/dist/tm/ptc/budgets.d.ts.map +0 -1
  133. package/dist/tm/ptc/budgets.js +0 -138
  134. package/dist/tm/ptc/budgets.js.map +0 -1
  135. package/dist/tm/ptc/contract.d.ts +0 -171
  136. package/dist/tm/ptc/contract.d.ts.map +0 -1
  137. package/dist/tm/ptc/contract.js +0 -85
  138. package/dist/tm/ptc/contract.js.map +0 -1
  139. package/dist/tm/ptc/driver.d.ts +0 -40
  140. package/dist/tm/ptc/driver.d.ts.map +0 -1
  141. package/dist/tm/ptc/driver.js +0 -213
  142. package/dist/tm/ptc/driver.js.map +0 -1
  143. package/dist/tm/ptc/engines.d.ts +0 -43
  144. package/dist/tm/ptc/engines.d.ts.map +0 -1
  145. package/dist/tm/ptc/engines.js +0 -454
  146. package/dist/tm/ptc/engines.js.map +0 -1
  147. package/dist/tm/ptc/gate.d.ts +0 -28
  148. package/dist/tm/ptc/gate.d.ts.map +0 -1
  149. package/dist/tm/ptc/gate.js +0 -130
  150. package/dist/tm/ptc/gate.js.map +0 -1
  151. package/dist/tm/ptc/index.d.ts +0 -19
  152. package/dist/tm/ptc/index.d.ts.map +0 -1
  153. package/dist/tm/ptc/index.js +0 -15
  154. package/dist/tm/ptc/index.js.map +0 -1
  155. package/dist/tm/ptc/pscan.d.ts +0 -30
  156. package/dist/tm/ptc/pscan.d.ts.map +0 -1
  157. package/dist/tm/ptc/pscan.js +0 -341
  158. package/dist/tm/ptc/pscan.js.map +0 -1
  159. package/dist/tm/ptc/summary.d.ts +0 -17
  160. package/dist/tm/ptc/summary.d.ts.map +0 -1
  161. package/dist/tm/ptc/summary.js +0 -134
  162. package/dist/tm/ptc/summary.js.map +0 -1
  163. package/dist/tm/ptc/tool.d.ts +0 -66
  164. package/dist/tm/ptc/tool.d.ts.map +0 -1
  165. package/dist/tm/ptc/tool.js +0 -231
  166. package/dist/tm/ptc/tool.js.map +0 -1
  167. package/dist/tm/ptc.d.ts +0 -298
  168. package/dist/tm/ptc.d.ts.map +0 -1
  169. package/dist/tm/ptc.js +0 -865
  170. package/dist/tm/ptc.js.map +0 -1
  171. package/dist/tm/pty.d.ts +0 -70
  172. package/dist/tm/pty.d.ts.map +0 -1
  173. package/dist/tm/pty.js +0 -245
  174. package/dist/tm/pty.js.map +0 -1
  175. package/dist/tool-coerce.d.ts +0 -24
  176. package/dist/tool-coerce.d.ts.map +0 -1
  177. package/dist/tool-coerce.js +0 -63
  178. package/dist/tool-coerce.js.map +0 -1
@@ -1,454 +0,0 @@
1
- /**
2
- * tm_ptc_run — the three engines behind the frozen `PtcEngine` seam.
3
- * Split out of the former monolithic ptc.ts; behavior unchanged.
4
- *
5
- * M1 legacy: InlineSequentialEngine (test-only — runs on the MAIN thread,
6
- * no sandbox, no timeout; a post-await busy loop blocks the host event loop
7
- * irrecoverably).
8
- * M2 primary: WorkerEngine (worker_threads + MessagePort RPC, env:{},
9
- * resourceLimits, hard `terminate()` wall-clock kill; bootstrap as a
10
- * build-time string; the program body runs inside a node:vm sandbox —
11
- * whitelist { tm, console, setTimeout, clearTimeout }, no node globals —
12
- * with the run's timeoutMs as the in-engine script timeout).
13
- * M2 fallback: InlineVmEngine (node:vm runInContext — the script timeout
14
- * kills PRE-await synchronous busy-loops; a POST-await busy loop blocks the
15
- * host event loop irrecoverably, documented — prefer worker/auto).
16
- *
17
- * C1 fix batch: BOTH vm engines now build their `tm` facade IN-CONTEXT via
18
- * `vm.compileFunction` (parsingContext) and compile the context with
19
- * `codeGeneration:{strings:false,wasm:false}`, so an injected facade's
20
- * `.constructor` is the sandbox Function
21
- * and `tm.read.constructor("return process")()` / `eval` / `new Function` THROW
22
- * instead of escaping into the worker/plugin realm. A started worker that
23
- * then crashes is reported as a program fault (never auto-replayed on the
24
- * more-privileged inline realm) — see engines WorkerEngine error/exit handling.
25
- */
26
- import * as vm from "node:vm";
27
- import { PtcProgramError, PtcStopSignal } from "./contract.js";
28
- const vmSandbox = vm;
29
- /** Build the `tm` facade the program body sees (one method per bridge tool). */
30
- function makeFacade(bridge) {
31
- const one = (tool) => (args) => bridge.call(tool, args && typeof args === "object" ? args : {});
32
- return {
33
- read: one("tm_read"),
34
- grep: one("tm_grep"),
35
- bash: one("tm_bash"),
36
- fetch: one("tm_fetch"),
37
- // T6 web bridges — always present so the program SHAPE is uniform; the
38
- // bridge itself rejects the call with a clear error when the web bridge
39
- // is off (TM_PTC_WEB_BRIDGE) or the caller's role denies the tool.
40
- search: one("tm_search"),
41
- webfetch: one("tm_webfetch"),
42
- };
43
- }
44
- /**
45
- * C1 (sandbox-escape) containment — the reason a facade is built with
46
- * `vm.compileFunction` (parsingContext) instead of being injected as a host/worker-realm closure.
47
- *
48
- * A function injected into a `vm` context still belongs to the realm that
49
- * CREATED it, so `tm.read.constructor` used to be the WORKER (or, worse, the
50
- * plugin ESM) realm's `Function` — `tm.read.constructor("return process")()`
51
- * escaped the sandbox outright. Compiling the facade INSIDE the context via
52
- * `compileFunction`-with-parsingContext makes every injected function a SANDBOX-realm function whose
53
- * `.constructor` is the sandbox `Function`; combined with
54
- * `codeGeneration:{strings:false}` on the context that call throws
55
- * ("Code generation from strings disallowed for this context"), and even
56
- * without the throw the sandbox `Function` can only compile into the sandbox
57
- * realm, where `process` / `require` do not exist.
58
- *
59
- * The two host callbacks the sandbox needs (`postCall` in the worker,
60
- * `callBridge` inline) are passed as WRAPPER PARAMETERS, so they live in the
61
- * closure — unreachable from the program (`Function.prototype.toString`
62
- * shows only source, never the closed-over values). And every RPC result is
63
- * JSON round-tripped IN the sandbox (`JSON.parse(JSON.stringify(raw))`) so a
64
- * host/worker-realm object (whose `.constructor` would be a host Object →
65
- * host Function) NEVER crosses into the program: rejected reasons are plain
66
- * strings too. Dynamic `import("node:fs")` is unavailable in a `vm` context
67
- * that supplies no `importModuleDynamically` callback, so it throws by default.
68
- */
69
- /** The vm-wrap body (worker engine): builds { tm, console, setTimeout,
70
- * clearTimeout } entirely in the sandbox realm from four host callbacks. */
71
- const TM_SANDBOX_SRC = [
72
- '"use strict";',
73
- "function mk(tool) {",
74
- " return function(args) {",
75
- " return new Promise(function(resolve, reject) {",
76
- // resolve normalizes the host/worker-realm result into a sandbox object.
77
- " postCall(tool, args, function(raw) { resolve(JSON.parse(JSON.stringify(raw))); }, reject);",
78
- " });",
79
- " };",
80
- "}",
81
- 'var tm = { read: mk("tm_read"), grep: mk("tm_grep"), bash: mk("tm_bash"), fetch: mk("tm_fetch"), search: mk("tm_search"), webfetch: mk("tm_webfetch") };',
82
- "var console = { log: function() { return callLog(); }, error: function() { return callLog(); }, warn: function() { return callLog(); }, info: function() { return callLog(); }, debug: function() { return callLog(); }, trace: function() { return callLog(); } };",
83
- // setTimeout/clearTimeout return a SANDBOX id and keep the worker timer
84
- // handle in a closure so no worker object ever surfaces to the program.
85
- "var __timers = {}; var __tid = 0;",
86
- "var setTimeout = function(fn, ms) {",
87
- " var id = ++__tid;",
88
- " __timers[id] = callTimeout(function() { delete __timers[id]; try { fn(); } catch (e) { void e; } }, ms);",
89
- " return id;",
90
- "};",
91
- "var clearTimeout = function(id) { var h = __timers[id]; if (h) { delete __timers[id]; callClearTimeout(h); } };",
92
- "return { tm: tm, console: console, setTimeout: setTimeout, clearTimeout: clearTimeout };",
93
- ].join("\n");
94
- /** The vm-wrap body (inline-vm engine): builds { tm } in the sandbox realm
95
- * from one host `callBridge` callback (rejects hand back a string, never a
96
- * host Error, so the program cannot climb `err.constructor`). */
97
- const TM_INLINE_SRC = [
98
- '"use strict";',
99
- "function mk(tool) {",
100
- " return function(args) {",
101
- " return new Promise(function(resolve, reject) {",
102
- " callBridge(tool, args, function(raw) { resolve(JSON.parse(JSON.stringify(raw))); }, function(msg) { reject(String(msg)); });",
103
- " });",
104
- " };",
105
- "}",
106
- 'return { read: mk("tm_read"), grep: mk("tm_grep"), bash: mk("tm_bash"), fetch: mk("tm_fetch"), search: mk("tm_search"), webfetch: mk("tm_webfetch") };',
107
- ].join("\n");
108
- export class InlineSequentialEngine {
109
- name = "inline";
110
- async run(program, bridge, signal) {
111
- // M1 legacy engine, kept test-only: the program runs as a trusted async
112
- // function body on the MAIN thread — no sandbox, no timeout, and a
113
- // post-await busy loop blocks the host event loop irrecoverably (same
114
- // residual as InlineVmEngine). Production runs WorkerEngine (auto
115
- // default) or InlineVmEngine.
116
- const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
117
- const tm = makeFacade(bridge);
118
- let abortHandler;
119
- const abortP = new Promise((_, rej) => {
120
- // The driver only aborts on wall-clock timeout (budget stops flow through
121
- // the gate as PtcStopSignal).
122
- abortHandler = () => rej(new PtcStopSignal("timeout"));
123
- if (signal.aborted)
124
- abortHandler();
125
- else
126
- signal.addEventListener("abort", abortHandler, { once: true });
127
- });
128
- try {
129
- const fn = new AsyncFunction("tm", `"use strict";\n${program}`);
130
- return await Promise.race([fn(tm), abortP]);
131
- }
132
- finally {
133
- if (abortHandler)
134
- signal.removeEventListener("abort", abortHandler);
135
- }
136
- }
137
- }
138
- // ---------- worker engine (MessagePort RPC over worker_threads) --------------
139
- export class WorkerEngine {
140
- name = "worker";
141
- async run(program, bridge, signal, opts) {
142
- const { Worker } = await import("node:worker_threads");
143
- // Build the worker bootstrap source as a regular string (ts-safe).
144
- // The worker receives {program, startDeadlineMs, timeoutMs} via its
145
- // first message, creates the tm facade, runs the program, and sends RPC
146
- // call requests back to the driver which executes them through the
147
- // gate bridge.
148
- //
149
- // T2 (C1 security): the program body runs inside a node:vm context —
150
- // a fresh realm with NO node globals. The C1 FIX closes the residual
151
- // host-function leak the earlier comments conceded: the `tm` facade and
152
- // the whitelisted intrinsics (console/setTimeout/clearTimeout) are now
153
- // COMPILED INSIDE the context via `vm.compileFunction` + `parsingContext` (see TM_SANDBOX_SRC), so a
154
- // facade function's `.constructor` is the sandbox Function, and the
155
- // context carries `codeGeneration:{strings:false,wasm:false}` so
156
- // `tm.read.constructor("return process")()` / `eval` / `new Function`
157
- // all THROW instead of escaping into the worker realm. RPC results are
158
- // JSON round-tripped in the sandbox and rejection reasons are strings,
159
- // so no worker-realm object crosses the boundary. (node:vm is still a
160
- // containment layer, not a hard boundary — staticPscan stays the first
161
- // gate and terminate() the wall-clock kill — but the trivial
162
- // `.constructor` escape that used to make the sandbox porous is gone.)
163
- // The bootstrap itself keeps worker powers (it needs require for
164
- // node:vm/worker_threads) — ONLY the program loses them.
165
- const src = [
166
- '"use strict";',
167
- 'const { parentPort } = require("node:worker_threads");',
168
- 'const vm = require("node:vm");',
169
- "parentPort.on(" + JSON.stringify("message") + ", async function onMsg(msg) {",
170
- " if (msg && msg.t === " + JSON.stringify("run") + ") {",
171
- " const program = msg.program;",
172
- " const callMap = new Map();",
173
- " let nextId = 0;",
174
- // The ONLY worker capability the sandbox reaches — passed to the wrapped
175
- // facade as a closure parameter, so it is invisible to the program. A
176
- // postMessage clone failure rejects with a STRING (never a worker Error).
177
- " var postCall = function(tool, args, resolve, reject) {",
178
- " const id = nextId++;",
179
- " callMap.set(id, { resolve: resolve, reject: reject });",
180
- " try { parentPort.postMessage({ t: " + JSON.stringify("call") + ", id: id, tool: tool, args: args }); }",
181
- " catch (e) { callMap.delete(id); reject(String(e && e.message ? e.message : e)); }",
182
- " };",
183
- " var callLog = function() {};",
184
- " var callTimeout = function(fn, ms) { return setTimeout(fn, ms); };",
185
- " var callClearTimeout = function(h) { return clearTimeout(h); };",
186
- // inner listener: RPC replies resolve pending program calls; abort
187
- // rejects are STRINGS (the parent normally hard-terminates on a stop).
188
- ' parentPort.on("message", function(inner) {',
189
- ' if (inner && inner.t === "result" && callMap.has(inner.id)) {',
190
- " callMap.get(inner.id).resolve(inner.r);",
191
- " callMap.delete(inner.id);",
192
- ' } else if (inner && inner.t === "abort") {',
193
- " for (const e of callMap.values()) e.reject(String(" + JSON.stringify("ptc-stop:") + ") + String(inner.reason));",
194
- " callMap.clear();",
195
- " }",
196
- " });",
197
- // C1: null-prototype context + codeGeneration OFF, facade built in-realm.
198
- " var sandbox = Object.create(null);",
199
- " vm.createContext(sandbox, { codeGeneration: { strings: false, wasm: false } });",
200
- " var inject = vm.compileFunction(" + JSON.stringify(TM_SANDBOX_SRC) + ", [" +
201
- JSON.stringify("postCall") + ", " + JSON.stringify("callLog") + ", " +
202
- JSON.stringify("callTimeout") + ", " + JSON.stringify("callClearTimeout") + "], " +
203
- "{ parsingContext: sandbox });",
204
- " var built = inject(postCall, callLog, callTimeout, callClearTimeout);",
205
- " sandbox.tm = built.tm;",
206
- " sandbox.console = built.console;",
207
- " sandbox.setTimeout = built.setTimeout;",
208
- " sandbox.clearTimeout = built.clearTimeout;",
209
- " var vmTimeout = typeof msg.timeoutMs === " + JSON.stringify("number") + " && msg.timeoutMs > 0 ? msg.timeoutMs : 30000;",
210
- " try {",
211
- // async-IIFE wrapper (same shape as InlineVmEngine): `return` stays
212
- // legal in the body, strict mode applies, and the completion value
213
- // IS the program's promise. The vm timeout kills PRE-await sync
214
- // busy-loops in-engine (post-await loops die via the driver-side
215
- // abort → terminate()).
216
- " var result = await vm.runInContext(" +
217
- JSON.stringify('(async () => {\n"use strict";\n') +
218
- " + program + " +
219
- JSON.stringify("\n})()") +
220
- ", sandbox, { timeout: vmTimeout });",
221
- ' parentPort.postMessage({ t: "done", result: result });',
222
- " } catch (err) {",
223
- // T5: tag the fault kind — a program throw becomes kind:"program"
224
- // so the parent constructs PtcProgramError (status "program-error",
225
- // no auto-degrade). vm-realm Errors are not instanceof the worker
226
- // realm's Error — read message/stack structurally.
227
- ' parentPort.postMessage({ t: "error", kind: "program", message: (err && err.message) ? String(err.message) : String(err), stack: (err && err.stack) ? String(err.stack) : undefined });',
228
- " }",
229
- " }",
230
- "});",
231
- ].join("\n");
232
- return new Promise((resolve, reject) => {
233
- let settled = false;
234
- // C1: did the worker thread actually START? A crash AFTER the thread
235
- // came online is a RUNTIME fault (a started program) and must never be
236
- // replayed on the inline/ESM realm; only a failure to START at all
237
- // (pre-online) is an engine-init fault the driver may degrade from.
238
- let online = false;
239
- const w = new Worker(src, {
240
- eval: true,
241
- env: {},
242
- resourceLimits: { maxOldGenerationSizeMb: 128, maxYoungGenerationSizeMb: 16 },
243
- });
244
- function settle(fn) {
245
- if (settled)
246
- return;
247
- settled = true;
248
- fn();
249
- }
250
- w.on("message", (msg) => {
251
- if (!msg || settled)
252
- return;
253
- if (msg.t === "done") {
254
- settle(() => {
255
- w.terminate();
256
- resolve(msg.result);
257
- });
258
- }
259
- else if (msg.t === "error") {
260
- settle(() => {
261
- w.terminate();
262
- const message = typeof msg.message === "string" ? msg.message : "worker error";
263
- // A vm script-timeout text means the program blew its
264
- // in-engine time budget — surface it as the run TIMEOUT so the
265
- // status stays "timeout" whichever watchdog fired first.
266
- if (msg.kind === "program" && /^Script execution timed out/i.test(message)) {
267
- reject(new PtcStopSignal("timeout"));
268
- return;
269
- }
270
- // T5: a tagged program fault → PtcProgramError (the driver maps
271
- // it to "program-error" and never auto-degrades). An untagged
272
- // error stays a generic engine fault.
273
- if (msg.kind === "program") {
274
- reject(new PtcProgramError(message, typeof msg.stack === "string" ? msg.stack : undefined));
275
- return;
276
- }
277
- const err = new Error(message);
278
- if (typeof msg.stack === "string")
279
- err.stack = msg.stack;
280
- reject(err);
281
- });
282
- }
283
- else if (msg.t === "call") {
284
- // Driver executes the bridge call through the gate and replies.
285
- const req = msg;
286
- bridge
287
- .call(req.tool, req.args)
288
- .then((r) => {
289
- if (!settled) {
290
- w.postMessage({ t: "result", id: req.id, r });
291
- }
292
- })
293
- .catch((err) => {
294
- // T5 (stop-signal swallow): the gate throws PtcStopSignal on
295
- // budget/time stops — it must TERMINATE the run with the stop
296
- // status instead of being swallowed into a generic per-call
297
- // error (zombie mode: the program kept running past the stop
298
- // on "bridge call failed" replies).
299
- if (err instanceof PtcStopSignal) {
300
- settle(() => {
301
- w.terminate().then(() => reject(err));
302
- });
303
- return;
304
- }
305
- if (!settled) {
306
- w.postMessage({
307
- t: "result",
308
- id: req.id,
309
- r: { ok: false, error: { tool: req.tool, phase: "execute", message: "bridge call failed" } },
310
- });
311
- }
312
- });
313
- }
314
- });
315
- w.on("online", () => {
316
- online = true;
317
- });
318
- w.on("error", (err) => {
319
- const msg = err instanceof Error ? err.message : String(err);
320
- settle(() => {
321
- if (online) {
322
- // The worker thread had started and then threw at the bootstrap
323
- // level — a runtime crash of a started program. Tag it as a
324
- // PROGRAM fault so the driver maps to "program-error" and NEVER
325
- // replays the (already-running) program on a more-privileged
326
- // realm. Do NOT terminate-and-resolve; the run simply fails.
327
- reject(new PtcProgramError(msg, err instanceof Error ? err.stack : undefined));
328
- }
329
- else {
330
- // The worker never came online: an engine-init fault. This is
331
- // the ONLY case the auto worker→inline degrade may act on.
332
- reject(err instanceof Error ? err : new Error(msg));
333
- }
334
- });
335
- });
336
- // C1: an unexpected exit while the run is still open. Post-online this
337
- // is a crash (e.g. a bootstrap-level process.exit) → program-error, no
338
- // replay; pre-online it is an init failure → engine-error (degradable).
339
- w.on("exit", (code) => {
340
- if (code === 0 || settled)
341
- return;
342
- settle(() => {
343
- if (online)
344
- reject(new PtcProgramError(`worker crashed (exit ${code})`));
345
- else
346
- reject(new Error(`worker failed to start (exit ${code})`));
347
- });
348
- });
349
- // Wire signal abort → terminate the worker.
350
- const onAbort = () => {
351
- settle(() => {
352
- w.terminate().then(() => reject(new PtcStopSignal("timeout")));
353
- });
354
- };
355
- if (signal.aborted)
356
- onAbort();
357
- else
358
- signal.addEventListener("abort", onAbort, { once: true });
359
- // Send the run request — timeoutMs feeds the in-engine vm script
360
- // timeout (complementary to the driver-side abort→terminate).
361
- w.postMessage({
362
- t: "run",
363
- program,
364
- startDeadlineMs: opts?.startDeadlineMs ?? 0,
365
- timeoutMs: opts?.timeoutMs,
366
- });
367
- });
368
- }
369
- }
370
- // ---------- inline-vm fallback engine (node:vm with script timeout) ----------
371
- export class InlineVmEngine {
372
- name = "inline";
373
- /** Script execution timeout in ms (kills pre-await synchronous
374
- * busy-loops). Injectable so tests can pin the kill fast. */
375
- compileTimeoutMs;
376
- constructor(compileTimeoutMs = 30_000) {
377
- this.compileTimeoutMs = compileTimeoutMs;
378
- }
379
- async run(program, bridge, signal) {
380
- // C1: build the facade INSIDE the sandbox (vm.compileFunction + parsingContext) and compile the
381
- // context with codeGeneration OFF. This engine runs in the PLUGIN ESM
382
- // realm (historically the WORST leak: an escaped `Function` could then
383
- // `import("node:fs" | "node:child_process")` → arbitrary file read incl.
384
- // .env, bypassing R6/P2). Wrapping the injected functions into the
385
- // sandbox realm is what closes it: `tm.read.constructor` is the sandbox
386
- // Function, codeGeneration:{strings:false} blocks compiling any new
387
- // string, and dynamic `import(...)` has no callback in a vm context so it
388
- // throws. The plugin-realm `bridge` is passed as a WRAPPER PARAMETER
389
- // (closure, unreachable from the program); RPC results are JSON
390
- // round-tripped into the sandbox and rejection reasons are plain strings,
391
- // so no host-realm object (with a host `.constructor`) ever crosses in.
392
- const callBridge = (tool, args, resolve, reject) => {
393
- let p;
394
- try {
395
- p = bridge.call(tool, args && typeof args === "object" ? args : {});
396
- }
397
- catch (e) {
398
- reject(e instanceof Error ? e.message : String(e));
399
- return;
400
- }
401
- Promise.resolve(p).then((r) => resolve(r), (e) => reject(e instanceof Error ? e.message : String(e)));
402
- };
403
- const sandbox = Object.create(null);
404
- vmSandbox.createContext(sandbox, { codeGeneration: { strings: false, wasm: false } });
405
- // TM_INLINE_SRC returns the { read, grep, bash, fetch, search, webfetch }
406
- // facade directly (this context carries only `tm`, no console/timers).
407
- const inject = vmSandbox.compileFunction(TM_INLINE_SRC, ["callBridge"], {
408
- parsingContext: sandbox,
409
- });
410
- sandbox.tm = inject(callBridge);
411
- let abortHandler;
412
- const abortP = new Promise((_, rej) => {
413
- abortHandler = () => rej(new PtcStopSignal("timeout"));
414
- if (signal.aborted)
415
- abortHandler();
416
- else
417
- signal.addEventListener("abort", abortHandler, { once: true });
418
- });
419
- try {
420
- // The async-IIFE is the program wrapper: `return` stays legal in the
421
- // body, the `tm` facade rides the context globals, and the script's
422
- // completion value IS the program's promise. The timeout kills
423
- // pre-await synchronous busy-loops (see the module doc).
424
- let promise;
425
- try {
426
- promise = vmSandbox.runInContext(`(async () => {\n"use strict";\n${program}\n})()`, sandbox, { timeout: this.compileTimeoutMs });
427
- }
428
- catch (err) {
429
- // a SYNCHRONOUS vm throw (script timeout) is an engine-side kill —
430
- // generic Error → engine-error semantics (pinned by §9j).
431
- throw err;
432
- }
433
- try {
434
- return await Promise.race([promise, abortP]);
435
- }
436
- catch (err) {
437
- if (err instanceof PtcStopSignal)
438
- throw err;
439
- // T5: the program body REJECTED — tag it so the driver maps to
440
- // status "program-error" instead of auto-degrading. A vm-realm
441
- // Error is not instanceof the host Error — read message/stack
442
- // structurally.
443
- const message = err?.message;
444
- const stack = err?.stack;
445
- throw new PtcProgramError(typeof message === "string" && message ? message : String(err ?? "program error"), typeof stack === "string" ? stack : undefined);
446
- }
447
- }
448
- finally {
449
- if (abortHandler)
450
- signal.removeEventListener("abort", abortHandler);
451
- }
452
- }
453
- }
454
- //# sourceMappingURL=engines.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"engines.js","sourceRoot":"","sources":["../../../src/tm/ptc/engines.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAE7B,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AA4B9D,MAAM,SAAS,GAAG,EAA6B,CAAA;AAE/C,gFAAgF;AAChF,SAAS,UAAU,CACjB,MAAiB;IAEjB,MAAM,GAAG,GACP,CAAC,IAAY,EAAE,EAAE,CACjB,CAAC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O,EAAE,YAAY,CAAC,CAAA;QACrE,CAAC;IACH,CAAC;CACF"}
@@ -1,28 +0,0 @@
1
- /**
2
- * tm_ptc_run — the StepGate. All budget/retry/step-id/trajectory logic lives
3
- * ONLY here (outside the engines), per design §3 ("决策进代码"). Split out
4
- * of the former monolithic ptc.ts; behavior unchanged.
5
- */
6
- import type { RunStore } from "../store.js";
7
- import type { PtcBridge, PtcStepRecord } from "./contract.js";
8
- import type { PtcBudgets } from "./budgets.js";
9
- export interface GateState {
10
- calls: number;
11
- errors: number;
12
- retries: number;
13
- steps: PtcStepRecord[];
14
- stopReason?: "timeout" | "error-budget" | "call-budget";
15
- }
16
- /**
17
- * Wrap a raw bridge with the StepGate. Every call: enforce time/call budget
18
- * (throw a stop that unwinds the program), assign a composite step id
19
- * `parent.kNN`, retry ≤1 on idempotent phases, record + persist errors, and
20
- * trip the error budget.
21
- */
22
- export declare function createGateBridge(raw: PtcBridge, parent: string, budgets: PtcBudgets, state: GateState, opts: {
23
- now: () => number;
24
- deadlineAt: number;
25
- store?: RunStore;
26
- trajectoryParent?: string;
27
- }): PtcBridge;
28
- //# sourceMappingURL=gate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../../src/tm/ptc/gate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,EAAc,SAAS,EAAiB,aAAa,EAAE,MAAM,eAAe,CAAA;AAExF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE9C,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,aAAa,EAAE,CAAA;IACtB,UAAU,CAAC,EAAE,SAAS,GAAG,cAAc,GAAG,aAAa,CAAA;CACxD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,SAAS,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE;IAAE,GAAG,EAAE,MAAM,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,QAAQ,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3F,SAAS,CAkGX"}
@@ -1,130 +0,0 @@
1
- /**
2
- * tm_ptc_run — the StepGate. All budget/retry/step-id/trajectory logic lives
3
- * ONLY here (outside the engines), per design §3 ("决策进代码"). Split out
4
- * of the former monolithic ptc.ts; behavior unchanged.
5
- */
6
- import { estimateTokens, shorten } from "../config.js";
7
- import { buildRef } from "../refs.js";
8
- import { PtcStopSignal, RETRYABLE_PHASES, shortRefCode } from "./contract.js";
9
- /**
10
- * Wrap a raw bridge with the StepGate. Every call: enforce time/call budget
11
- * (throw a stop that unwinds the program), assign a composite step id
12
- * `parent.kNN`, retry ≤1 on idempotent phases, record + persist errors, and
13
- * trip the error budget.
14
- */
15
- export function createGateBridge(raw, parent, budgets, state, opts) {
16
- const { now, deadlineAt, store } = opts;
17
- const ptcTag = opts.trajectoryParent ?? parent;
18
- let seq = 0;
19
- const traj = (e) => store?.appendTrajectory(e);
20
- return {
21
- async call(tool, args) {
22
- if (state.stopReason)
23
- throw new PtcStopSignal(state.stopReason);
24
- // time budget checked BEFORE the call so a run cannot start a call it
25
- // has no time left for.
26
- if (now() >= deadlineAt) {
27
- state.stopReason = "timeout";
28
- throw new PtcStopSignal("timeout");
29
- }
30
- // call budget: only `maxCalls` bridged calls may be dispatched.
31
- if (state.calls >= budgets.maxCalls) {
32
- state.stopReason = "call-budget";
33
- throw new PtcStopSignal("call-budget");
34
- }
35
- state.calls++;
36
- seq++;
37
- const composite = `${parent}.k${String(seq).padStart(2, "0")}`;
38
- traj({ tool, step_id: composite, event: "call", ptc: ptcTag });
39
- const t0 = now();
40
- let res = await raw.call(tool, args);
41
- let retried = false;
42
- // ≤1 retry on idempotent phases — but never PAST the deadline: a
43
- // retryable failure at the wire must not buy extra wall-clock time.
44
- // The retry still rides the same budget unit (one call = one unit).
45
- if (!res.ok && RETRYABLE_PHASES.includes(res.error.phase) && now() < deadlineAt) {
46
- retried = true;
47
- state.retries++;
48
- res = await raw.call(tool, args);
49
- }
50
- const ms = now() - t0;
51
- if (res.ok) {
52
- const { tokens, dest, ref } = describeOk(res.data);
53
- state.steps.push({ n: seq, tool, ok: true, ms, tokens, dest, ref });
54
- traj({
55
- tool,
56
- step_id: composite,
57
- event: "result",
58
- offloaded: Boolean(ref),
59
- tokens,
60
- ptc: ptcTag,
61
- ...(ref ? { ref } : {}),
62
- });
63
- return res;
64
- }
65
- // error path — full text persists to steps/sXXXX.kNN/ (design §4.1)
66
- state.errors++;
67
- const err = res.error;
68
- let errorRef;
69
- if (store) {
70
- try {
71
- store.writeResult(composite, {
72
- tool,
73
- content: JSON.stringify({ error: err }, null, 2),
74
- tokens: estimateTokens(JSON.stringify(err)),
75
- contentType: "json",
76
- preview: shorten(err.message, 120),
77
- expireAt: Date.now() + 24 * 60 * 60 * 1000,
78
- });
79
- errorRef = buildRef(store.runId, composite);
80
- }
81
- catch {
82
- /* error persistence is best-effort; never mask the original error */
83
- }
84
- }
85
- state.steps.push({
86
- n: seq,
87
- tool,
88
- ok: false,
89
- ms,
90
- tokens: 0,
91
- dest: "err",
92
- phase: err.phase,
93
- line: err.line,
94
- retry: retried,
95
- message: err.message,
96
- errorRef,
97
- });
98
- traj({
99
- tool,
100
- step_id: composite,
101
- event: "error",
102
- phase: err.phase,
103
- ...(typeof err.line === "number" ? { line: err.line } : {}),
104
- retry: retried,
105
- ptc: ptcTag,
106
- ...(errorRef ? { ref: errorRef } : {}),
107
- });
108
- if (state.errors >= budgets.maxErrors) {
109
- state.stopReason = "error-budget";
110
- throw new PtcStopSignal("error-budget");
111
- }
112
- return res;
113
- },
114
- };
115
- }
116
- /** Describe an ok bridge result for the success table (inline vs handle). */
117
- function describeOk(data) {
118
- if (data && typeof data === "object" && data.offloaded === true) {
119
- const o = data;
120
- const ref = typeof o.ref === "string" ? o.ref : null;
121
- return {
122
- tokens: typeof o.tokens === "number" ? o.tokens : 0,
123
- dest: ref ? `ref:${shortRefCode(ref)}` : "ref",
124
- ref,
125
- };
126
- }
127
- const text = typeof data === "string" ? data : JSON.stringify(data ?? "");
128
- return { tokens: estimateTokens(text), dest: "inline", ref: null };
129
- }
130
- //# sourceMappingURL=gate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gate.js","sourceRoot":"","sources":["../../../src/tm/ptc/gate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGrC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAW7E;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAc,EACd,MAAc,EACd,OAAmB,EACnB,KAAgB,EAChB,IAA4F;IAE5F,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,IAAI,CAAA;IACvC,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,IAAI,MAAM,CAAA;IAC9C,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,MAAM,IAAI,GAAG,CAAC,CAA0B,EAAE,EAAE,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAA;IACvE,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI;YACnB,IAAI,KAAK,CAAC,UAAU;gBAAE,MAAM,IAAI,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;YAC/D,sEAAsE;YACtE,wBAAwB;YACxB,IAAI,GAAG,EA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