@te-river/opencode-team-mode 1.5.11 → 1.5.13
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 +154 -57
- package/README.zh-CN.md +126 -47
- package/dist/agents.d.ts +5 -1
- package/dist/agents.d.ts.map +1 -1
- package/dist/agents.js +37 -11
- package/dist/agents.js.map +1 -1
- package/dist/approval-gate.d.ts +54 -16
- package/dist/approval-gate.d.ts.map +1 -1
- package/dist/approval-gate.js +163 -42
- package/dist/approval-gate.js.map +1 -1
- package/dist/host-hooks.d.ts +115 -0
- package/dist/host-hooks.d.ts.map +1 -0
- package/dist/host-hooks.js +270 -0
- package/dist/host-hooks.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +68 -4
- package/dist/index.js.map +1 -1
- package/dist/prompts/lead.d.ts +1 -1
- package/dist/prompts/lead.d.ts.map +1 -1
- package/dist/prompts/lead.js +88 -6
- package/dist/prompts/lead.js.map +1 -1
- package/dist/prompts/shared.d.ts +1 -1
- package/dist/prompts/shared.d.ts.map +1 -1
- package/dist/prompts/shared.js +203 -119
- package/dist/prompts/shared.js.map +1 -1
- package/dist/prompts/specialists.d.ts +2 -2
- package/dist/prompts/specialists.d.ts.map +1 -1
- package/dist/prompts/specialists.js +73 -23
- package/dist/prompts/specialists.js.map +1 -1
- package/dist/tm/args-schema.d.ts +31 -1
- package/dist/tm/args-schema.d.ts.map +1 -1
- package/dist/tm/args-schema.js +155 -39
- package/dist/tm/args-schema.js.map +1 -1
- package/dist/tm/bash-timeout.d.ts +72 -0
- package/dist/tm/bash-timeout.d.ts.map +1 -0
- package/dist/tm/bash-timeout.js +100 -0
- package/dist/tm/bash-timeout.js.map +1 -0
- package/dist/tm/browser.d.ts +250 -20
- package/dist/tm/browser.d.ts.map +1 -1
- package/dist/tm/browser.js +1200 -143
- package/dist/tm/browser.js.map +1 -1
- package/dist/tm/config.d.ts +129 -0
- package/dist/tm/config.d.ts.map +1 -1
- package/dist/tm/config.js +117 -1
- package/dist/tm/config.js.map +1 -1
- package/dist/tm/dispatch.d.ts +95 -0
- package/dist/tm/dispatch.d.ts.map +1 -0
- package/dist/tm/dispatch.js +369 -0
- package/dist/tm/dispatch.js.map +1 -0
- package/dist/tm/index.d.ts +32 -7
- package/dist/tm/index.d.ts.map +1 -1
- package/dist/tm/index.js +74 -5
- package/dist/tm/index.js.map +1 -1
- package/dist/tm/memory.d.ts +88 -10
- package/dist/tm/memory.d.ts.map +1 -1
- package/dist/tm/memory.js +881 -99
- package/dist/tm/memory.js.map +1 -1
- package/dist/tm/pipelines.d.ts +26 -3
- package/dist/tm/pipelines.d.ts.map +1 -1
- package/dist/tm/pipelines.js +167 -11
- package/dist/tm/pipelines.js.map +1 -1
- package/dist/tm/ptc/budgets.d.ts +22 -1
- package/dist/tm/ptc/budgets.d.ts.map +1 -1
- package/dist/tm/ptc/budgets.js +87 -8
- package/dist/tm/ptc/budgets.js.map +1 -1
- package/dist/tm/ptc/contract.d.ts +49 -9
- package/dist/tm/ptc/contract.d.ts.map +1 -1
- package/dist/tm/ptc/contract.js +41 -3
- package/dist/tm/ptc/contract.js.map +1 -1
- package/dist/tm/ptc/driver.d.ts +5 -2
- package/dist/tm/ptc/driver.d.ts.map +1 -1
- package/dist/tm/ptc/driver.js +47 -15
- package/dist/tm/ptc/driver.js.map +1 -1
- package/dist/tm/ptc/engines.d.ts +15 -4
- package/dist/tm/ptc/engines.d.ts.map +1 -1
- package/dist/tm/ptc/engines.js +281 -28
- package/dist/tm/ptc/engines.js.map +1 -1
- package/dist/tm/ptc/index.d.ts +4 -4
- package/dist/tm/ptc/index.d.ts.map +1 -1
- package/dist/tm/ptc/index.js +2 -2
- package/dist/tm/ptc/index.js.map +1 -1
- package/dist/tm/ptc/pscan.d.ts +20 -1
- package/dist/tm/ptc/pscan.d.ts.map +1 -1
- package/dist/tm/ptc/pscan.js +328 -14
- package/dist/tm/ptc/pscan.js.map +1 -1
- package/dist/tm/ptc/summary.d.ts.map +1 -1
- package/dist/tm/ptc/summary.js +23 -1
- package/dist/tm/ptc/summary.js.map +1 -1
- package/dist/tm/ptc/tool.d.ts +34 -3
- package/dist/tm/ptc/tool.d.ts.map +1 -1
- package/dist/tm/ptc/tool.js +117 -20
- package/dist/tm/ptc/tool.js.map +1 -1
- package/dist/tm/pty.d.ts +70 -0
- package/dist/tm/pty.d.ts.map +1 -0
- package/dist/tm/pty.js +242 -0
- package/dist/tm/pty.js.map +1 -0
- package/dist/tm/search.d.ts +128 -15
- package/dist/tm/search.d.ts.map +1 -1
- package/dist/tm/search.js +556 -47
- package/dist/tm/search.js.map +1 -1
- package/dist/tm/shell-bridge.d.ts +14 -1
- package/dist/tm/shell-bridge.d.ts.map +1 -1
- package/dist/tm/shell-bridge.js +57 -10
- package/dist/tm/shell-bridge.js.map +1 -1
- package/dist/tm/webfetch.d.ts +29 -7
- package/dist/tm/webfetch.d.ts.map +1 -1
- package/dist/tm/webfetch.js +117 -15
- package/dist/tm/webfetch.js.map +1 -1
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/installation.md +216 -17
- package/package.json +5 -2
package/dist/tm/ptc/budgets.js
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
* behavior unchanged.
|
|
5
5
|
*/
|
|
6
6
|
import { tmError } from "../result.js";
|
|
7
|
+
/** caller-facing arg key → resolved PtcBudgets key. */
|
|
8
|
+
const BUDGET_FIELD_MAP = [
|
|
9
|
+
["max_calls", "maxCalls"],
|
|
10
|
+
["max_errors", "maxErrors"],
|
|
11
|
+
["timeout_ms", "timeoutMs"],
|
|
12
|
+
];
|
|
7
13
|
/**
|
|
8
14
|
* Clamp a caller-supplied budget against the resolved env ceiling. Absent ->
|
|
9
15
|
* the env ceiling; above the ceiling -> clamped DOWN (cannot loosen); below
|
|
@@ -20,13 +26,44 @@ function clampBudget(raw, ceiling, floor) {
|
|
|
20
26
|
return floor;
|
|
21
27
|
return i;
|
|
22
28
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Resolve budgets AND track provenance for the summary echo (fix batch T1):
|
|
31
|
+
* which fields the caller set, and which were clamped. `resolvePtcBudgets`
|
|
32
|
+
* (plain) stays deepEqual-stable for existing callers; the echo arrays are
|
|
33
|
+
* attached by `parsePtcArgs`, never by the plain resolver.
|
|
34
|
+
*/
|
|
35
|
+
export function resolvePtcBudgetsDetailed(cfg, budgets) {
|
|
36
|
+
const b = budgets && typeof budgets === "object" && !Array.isArray(budgets)
|
|
37
|
+
? budgets
|
|
38
|
+
: {};
|
|
39
|
+
const ceilings = {
|
|
40
|
+
maxCalls: cfg.ptcMaxCalls,
|
|
41
|
+
maxErrors: cfg.ptcMaxErrors,
|
|
42
|
+
timeoutMs: cfg.ptcTimeoutMs,
|
|
29
43
|
};
|
|
44
|
+
const floors = {
|
|
45
|
+
maxCalls: PTC_BUDGET_BOUNDS_FLOOR.maxCalls,
|
|
46
|
+
maxErrors: PTC_BUDGET_BOUNDS_FLOOR.maxErrors,
|
|
47
|
+
timeoutMs: PTC_BUDGET_BOUNDS_FLOOR.timeoutMs,
|
|
48
|
+
};
|
|
49
|
+
const setByUser = [];
|
|
50
|
+
const clamped = [];
|
|
51
|
+
const out = {};
|
|
52
|
+
for (const [raw, key] of BUDGET_FIELD_MAP) {
|
|
53
|
+
out[key] = clampBudget(b[raw], ceilings[key], floors[key]);
|
|
54
|
+
const n = b[raw];
|
|
55
|
+
const num = typeof n === "number" ? n : n == null ? NaN : Number(n);
|
|
56
|
+
if (!Number.isFinite(num))
|
|
57
|
+
continue;
|
|
58
|
+
setByUser.push(raw);
|
|
59
|
+
const i = Math.trunc(num);
|
|
60
|
+
if (i !== out[key])
|
|
61
|
+
clamped.push(raw);
|
|
62
|
+
}
|
|
63
|
+
return { budgets: out, setByUser, clamped };
|
|
64
|
+
}
|
|
65
|
+
export function resolvePtcBudgets(cfg, budgets) {
|
|
66
|
+
return resolvePtcBudgetsDetailed(cfg, budgets).budgets;
|
|
30
67
|
}
|
|
31
68
|
// floors mirror config.ts PTC_BUDGET_BOUNDS (kept here so this module stays
|
|
32
69
|
// self-contained for clamp tests without importing config internals).
|
|
@@ -36,7 +73,9 @@ export const PTC_LABEL_MAX = 80;
|
|
|
36
73
|
/**
|
|
37
74
|
* Validate + normalize tm_ptc_run args. `program` over the length cap is a
|
|
38
75
|
* hard args error (a program cannot be meaningfully truncated); `label` over
|
|
39
|
-
* 80 is truncated; `budgets` are
|
|
76
|
+
* 80 is truncated; `budgets` are validated LOUDLY (fix batch T1: a wrong
|
|
77
|
+
* shape used to silently fall back to the ceiling — the caller never learned
|
|
78
|
+
* their budgets were ignored) and clamped toward the env ceilings.
|
|
40
79
|
*/
|
|
41
80
|
export function parsePtcArgs(raw, cfg) {
|
|
42
81
|
const a = raw ?? {};
|
|
@@ -53,7 +92,47 @@ export function parsePtcArgs(raw, cfg) {
|
|
|
53
92
|
let label = typeof a.label === "string" && a.label.trim() ? a.label.trim() : "ptc-run";
|
|
54
93
|
if (label.length > PTC_LABEL_MAX)
|
|
55
94
|
label = label.slice(0, PTC_LABEL_MAX);
|
|
56
|
-
|
|
95
|
+
// budgets — loud validation (fix batch T1)
|
|
96
|
+
const rawBudgets = a.budgets;
|
|
97
|
+
if (rawBudgets !== undefined) {
|
|
98
|
+
if (typeof rawBudgets !== "object" || rawBudgets === null || Array.isArray(rawBudgets)) {
|
|
99
|
+
return {
|
|
100
|
+
ok: false,
|
|
101
|
+
error: tmError("tm_ptc_run", "args", "budgets 必须是 { max_calls?, max_errors?, timeout_ms? } 对象"),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// Wave B Minor② — reject unknown keys. A typo (max_call, missing the s)
|
|
105
|
+
// used to pass the type + per-field checks and then silently resolve to
|
|
106
|
+
// the ceiling default (T1's loud-validation goal violated: the caller
|
|
107
|
+
// never learned the budget was ignored). The zod schema layer adds
|
|
108
|
+
// .strict() too, but this is the runtime backstop that always fires.
|
|
109
|
+
const knownKeys = new Set(BUDGET_FIELD_MAP.map(([raw]) => raw));
|
|
110
|
+
const unknownKeys = Object.keys(rawBudgets).filter((k) => !knownKeys.has(k));
|
|
111
|
+
if (unknownKeys.length > 0) {
|
|
112
|
+
return {
|
|
113
|
+
ok: false,
|
|
114
|
+
error: tmError("tm_ptc_run", "args", `budgets 含未知键 [${unknownKeys.join(", ")}];合法键仅 max_calls / max_errors / timeout_ms(拼写必须完全一致,例如 max_call 漏 s 会被拒)`),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
for (const [field] of BUDGET_FIELD_MAP) {
|
|
118
|
+
const v = rawBudgets[field];
|
|
119
|
+
if (v === undefined || v === null)
|
|
120
|
+
continue;
|
|
121
|
+
if (typeof v !== "number" || !Number.isFinite(v) || v < 1) {
|
|
122
|
+
return {
|
|
123
|
+
ok: false,
|
|
124
|
+
error: tmError("tm_ptc_run", "args", `budgets.${field} 必须是不小于 1 的数字(当前值:${JSON.stringify(v)})`),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const resolution = resolvePtcBudgetsDetailed(cfg, rawBudgets);
|
|
130
|
+
// attach the echo provenance (setByUser / clamped) for the summary line
|
|
131
|
+
const budgets = {
|
|
132
|
+
...resolution.budgets,
|
|
133
|
+
...(resolution.setByUser.length ? { setByUser: resolution.setByUser } : {}),
|
|
134
|
+
...(resolution.clamped.length ? { clamped: resolution.clamped } : {}),
|
|
135
|
+
};
|
|
57
136
|
return { ok: true, args: { program, label, budgets } };
|
|
58
137
|
}
|
|
59
138
|
//# sourceMappingURL=budgets.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"budgets.js","sourceRoot":"","sources":["../../../src/tm/ptc/budgets.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,C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L,EAAE,EAAE,KAAK;oBACT,KAAK,EAAE,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,KAAK,qBAAqB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC;iBAChG,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,MAAM,UAAU,GAAG,yBAAyB,CAAC,GAAG,EAAE,UAA8B,CAAC,CAAA;IACjF,wEAAwE;IACxE,MAAM,OAAO,GAAe;QAC1B,GAAG,UAAU,CAAC,OAAO;QACrB,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3E,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtE,CAAA;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAA;AACxD,CAAC"}
|
|
@@ -11,12 +11,25 @@
|
|
|
11
11
|
* semantics apply to every bridged call verbatim. PTC is NOT a bypass layer.
|
|
12
12
|
*/
|
|
13
13
|
import type { TmPhase } from "../result.js";
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
import type { PtcBudgets } from "./budgets.js";
|
|
15
|
+
/** The six PTC run statuses (design §2; "program-error" added in the fix
|
|
16
|
+
* batch to separate PROGRAM faults — the body threw, engine healthy, no
|
|
17
|
+
* auto-degrade — from ENGINE faults). */
|
|
18
|
+
export declare const PTC_STATUS_VALUES: readonly ["ok", "stopped-error-budget", "stopped-call-budget", "timeout", "engine-error", "program-error"];
|
|
16
19
|
export type PtcStatus = (typeof PTC_STATUS_VALUES)[number];
|
|
17
|
-
export type BridgeTool = "tm_read" | "tm_grep" | "tm_bash" | "tm_fetch";
|
|
18
|
-
/**
|
|
20
|
+
export type BridgeTool = "tm_read" | "tm_grep" | "tm_bash" | "tm_fetch" | "tm_search" | "tm_webfetch";
|
|
21
|
+
/**
|
|
22
|
+
* Bridge allow set — read-only; tm_ptc_run itself is excluded (no nesting).
|
|
23
|
+
* T6 added the two WEB bridges (tm_search / tm_webfetch): they are gated a
|
|
24
|
+
* second time at the bridge layer (TM_PTC_WEB_BRIDGE=off → the bridge returns
|
|
25
|
+
* an args error) and a THIRD time by the host ruleset — a bridged call runs
|
|
26
|
+
* the real tm_search/tm_webfetch execute with the CALLER's per-execute ctx, so
|
|
27
|
+
* ctx.ask evaluates against that agent's grant and a non-web role is denied
|
|
28
|
+
* with a permission error (zero new mechanism).
|
|
29
|
+
*/
|
|
19
30
|
export declare const BRIDGE_ALLOW: readonly BridgeTool[];
|
|
31
|
+
/** The web bridge tools — the subset gated behind TM_PTC_WEB_BRIDGE + role. */
|
|
32
|
+
export declare const WEB_BRIDGE_TOOLS: readonly BridgeTool[];
|
|
20
33
|
/** Phases safe to retry once (idempotent read-only bridges; design §4.2). */
|
|
21
34
|
export declare const RETRYABLE_PHASES: readonly TmPhase[];
|
|
22
35
|
/** Error body the bridge surfaces (T1.4 shape: tool/phase/message/line?). */
|
|
@@ -43,6 +56,10 @@ export interface PtcRunRequest {
|
|
|
43
56
|
program: string;
|
|
44
57
|
/** monotonic token so a caller can correlate a call with its response. */
|
|
45
58
|
startDeadlineMs: number;
|
|
59
|
+
/** wall-clock budget in ms — the worker engine sets it as the in-engine
|
|
60
|
+
* vm script timeout (kills pre-await sync busy-loops in-engine,
|
|
61
|
+
* complementary to the driver-side abort→terminate). */
|
|
62
|
+
timeoutMs?: number;
|
|
46
63
|
}
|
|
47
64
|
/** Engine → driver: a single bridged call to execute under the gate. */
|
|
48
65
|
export interface PtcRpcRequest {
|
|
@@ -68,17 +85,26 @@ export type PtcEngineName = "worker" | "inline";
|
|
|
68
85
|
/**
|
|
69
86
|
* The engine seam — FROZEN. InlineSequentialEngine shipped in M1,
|
|
70
87
|
* WorkerEngine + InlineVmEngine in M2; a future engine implements this same
|
|
71
|
-
* shape and neither the driver nor the tool changes.
|
|
88
|
+
* shape and neither the driver nor the tool changes. (Fix batch: the
|
|
89
|
+
* OPTIONAL `opts` 4th param extends the seam source-compatibly — existing
|
|
90
|
+
* engines may ignore it; the worker engine turns `timeoutMs` into the
|
|
91
|
+
* in-engine vm script timeout.)
|
|
72
92
|
*/
|
|
73
93
|
export interface PtcEngine {
|
|
74
94
|
readonly name: PtcEngineName;
|
|
75
95
|
/**
|
|
76
96
|
* Run `program`, driving every bridge call through `bridge` (already
|
|
77
97
|
* gate-wrapped by the driver). Resolve with the program's return value;
|
|
78
|
-
* reject with a `PtcStopSignal` for a budget/time stop,
|
|
79
|
-
* for
|
|
98
|
+
* reject with a `PtcStopSignal` for a budget/time stop, a
|
|
99
|
+
* `PtcProgramError` for a program fault, or any other Error for an
|
|
100
|
+
* engine fault. `signal` lets the driver race a timeout.
|
|
80
101
|
*/
|
|
81
|
-
run(program: string, bridge: PtcBridge, signal: AbortSignal): Promise<unknown>;
|
|
102
|
+
run(program: string, bridge: PtcBridge, signal: AbortSignal, opts?: PtcEngineRunOpts): Promise<unknown>;
|
|
103
|
+
}
|
|
104
|
+
/** Per-run hints handed to the engine (optional, ignorable). */
|
|
105
|
+
export interface PtcEngineRunOpts {
|
|
106
|
+
startDeadlineMs?: number;
|
|
107
|
+
timeoutMs?: number;
|
|
82
108
|
}
|
|
83
109
|
/**
|
|
84
110
|
* The stop signal unwinding a program on a budget/time hit. Thrown by the
|
|
@@ -90,6 +116,16 @@ export declare class PtcStopSignal extends Error {
|
|
|
90
116
|
readonly reason: "timeout" | "error-budget" | "call-budget";
|
|
91
117
|
constructor(reason: "timeout" | "error-budget" | "call-budget");
|
|
92
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* A PROGRAM fault — the program body itself threw (the worker bootstrap
|
|
121
|
+
* posts kind:"program"; the inline-vm engine tags promise rejections).
|
|
122
|
+
* Distinct from an engine fault: the engine is healthy, so the driver maps
|
|
123
|
+
* it to status "program-error" and NEVER auto-degrades (re-running the same
|
|
124
|
+
* program would just throw again).
|
|
125
|
+
*/
|
|
126
|
+
export declare class PtcProgramError extends Error {
|
|
127
|
+
constructor(message: string, stack?: string);
|
|
128
|
+
}
|
|
93
129
|
/** Short display code for a ref: the `steps/<id>` step segment. Shared by
|
|
94
130
|
* the gate (success table) and the summary renderer (error refs). */
|
|
95
131
|
export declare function shortRefCode(ref: string): string;
|
|
@@ -124,8 +160,12 @@ export interface PtcRunOutcome {
|
|
|
124
160
|
degraded: boolean;
|
|
125
161
|
returnValue: unknown;
|
|
126
162
|
returned: boolean;
|
|
127
|
-
/** set when the program
|
|
163
|
+
/** set when the program or engine faulted (engine-error / program-error). */
|
|
128
164
|
engineError?: PtcErrorBody;
|
|
165
|
+
/** budgets echo (fix batch T1): the EFFECTIVE values + which fields were
|
|
166
|
+
* user-set / clamped — rendered as the summary's budgets line so the
|
|
167
|
+
* operator sees clamping, not just the final numbers. */
|
|
168
|
+
budgets?: PtcBudgets;
|
|
129
169
|
parentStepId: string;
|
|
130
170
|
}
|
|
131
171
|
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/tm/ptc/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/tm/ptc/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAI9C;;0CAE0C;AAC1C,eAAO,MAAM,iBAAiB,4GA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MAAM,WAAW,aAAa;IAC5B,CAAC,EAAE,MAAM,CAAA;IACT,IAAI,EAAE,UAAU,CAAA;IAChB,EAAE,EAAE,OAAO,CAAA;IACX,EAAE,EAAE,MAAM,CAAA;IACV,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAA;IACd,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAA;IACZ,wEAAwE;IACxE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,qBAAqB;IACrB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,SAAS,CAAA;IACjB,KAAK,EAAE,aAAa,EAAE,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,aAAa,CAAA;IACrB,QAAQ,EAAE,OAAO,CAAA;IACjB,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,YAAY,CAAA;IAC1B;;8DAE0D;IAC1D,OAAO,CAAC,EAAE,UAAU,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;CACrB"}
|
package/dist/tm/ptc/contract.js
CHANGED
|
@@ -12,17 +12,40 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { shorten } from "../config.js";
|
|
14
14
|
// ---------- statuses + bridge surface (design §2) ---------------------------
|
|
15
|
-
/** The
|
|
15
|
+
/** The six PTC run statuses (design §2; "program-error" added in the fix
|
|
16
|
+
* batch to separate PROGRAM faults — the body threw, engine healthy, no
|
|
17
|
+
* auto-degrade — from ENGINE faults). */
|
|
16
18
|
export const PTC_STATUS_VALUES = [
|
|
17
19
|
"ok",
|
|
18
20
|
"stopped-error-budget",
|
|
19
21
|
"stopped-call-budget",
|
|
20
22
|
"timeout",
|
|
21
23
|
"engine-error",
|
|
24
|
+
"program-error",
|
|
22
25
|
];
|
|
23
|
-
/**
|
|
24
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Bridge allow set — read-only; tm_ptc_run itself is excluded (no nesting).
|
|
28
|
+
* T6 added the two WEB bridges (tm_search / tm_webfetch): they are gated a
|
|
29
|
+
* second time at the bridge layer (TM_PTC_WEB_BRIDGE=off → the bridge returns
|
|
30
|
+
* an args error) and a THIRD time by the host ruleset — a bridged call runs
|
|
31
|
+
* the real tm_search/tm_webfetch execute with the CALLER's per-execute ctx, so
|
|
32
|
+
* ctx.ask evaluates against that agent's grant and a non-web role is denied
|
|
33
|
+
* with a permission error (zero new mechanism).
|
|
34
|
+
*/
|
|
35
|
+
export const BRIDGE_ALLOW = [
|
|
36
|
+
"tm_read",
|
|
37
|
+
"tm_grep",
|
|
38
|
+
"tm_bash",
|
|
39
|
+
"tm_fetch",
|
|
40
|
+
"tm_search",
|
|
41
|
+
"tm_webfetch",
|
|
42
|
+
];
|
|
43
|
+
/** The web bridge tools — the subset gated behind TM_PTC_WEB_BRIDGE + role. */
|
|
44
|
+
export const WEB_BRIDGE_TOOLS = ["tm_search", "tm_webfetch"];
|
|
25
45
|
/** Phases safe to retry once (idempotent read-only bridges; design §4.2). */
|
|
46
|
+
// T6: tm_search / tm_webfetch issue GETs — idempotent — so their transient
|
|
47
|
+
// failures (client/execute/store phases) inherit the SAME one-retry policy;
|
|
48
|
+
// a permission/args error is never retried (the role denial must stand).
|
|
26
49
|
export const RETRYABLE_PHASES = ["client", "execute", "store"];
|
|
27
50
|
/**
|
|
28
51
|
* The stop signal unwinding a program on a budget/time hit. Thrown by the
|
|
@@ -38,6 +61,21 @@ export class PtcStopSignal extends Error {
|
|
|
38
61
|
this.name = "PtcStopSignal";
|
|
39
62
|
}
|
|
40
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* A PROGRAM fault — the program body itself threw (the worker bootstrap
|
|
66
|
+
* posts kind:"program"; the inline-vm engine tags promise rejections).
|
|
67
|
+
* Distinct from an engine fault: the engine is healthy, so the driver maps
|
|
68
|
+
* it to status "program-error" and NEVER auto-degrades (re-running the same
|
|
69
|
+
* program would just throw again).
|
|
70
|
+
*/
|
|
71
|
+
export class PtcProgramError extends Error {
|
|
72
|
+
constructor(message, stack) {
|
|
73
|
+
super(message);
|
|
74
|
+
this.name = "PtcProgramError";
|
|
75
|
+
if (typeof stack === "string" && stack)
|
|
76
|
+
this.stack = stack;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
41
79
|
/** Short display code for a ref: the `steps/<id>` step segment. Shared by
|
|
42
80
|
* the gate (success table) and the summary renderer (error refs). */
|
|
43
81
|
export function shortRefCode(ref) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../../src/tm/ptc/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../../src/tm/ptc/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC,+EAA+E;AAE/E;;0CAE0C;AAC1C,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI;IACJ,sBAAsB;IACtB,qBAAqB;IACrB,SAAS;IACT,cAAc;IACd,eAAe;CACP,CAAA;AAWV;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAA0B;IACjD,SAAS;IACT,SAAS;IACT,SAAS;IACT,UAAU;IACV,WAAW;IACX,aAAa;CACd,CAAA;AAED,+EAA+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAA0B,CAAC,WAAW,EAAE,aAAa,CAAC,CAAA;AAEnF,6EAA6E;AAC7E,2EAA2E;AAC3E,4EAA4E;AAC5E,yEAAyE;AACzE,MAAM,CAAC,MAAM,gBAAgB,GAAuB,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;AA0FlF;;;;;GAKG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACjB;IAArB,YAAqB,MAAkD;QACrE,KAAK,CAAC,YAAY,MAAM,EAAE,CAAC,CAAA;QADR,WAAM,GAAN,MAAM,CAA4C;QAErE,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;IAC7B,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe,EAAE,KAAc;QACzC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;QAC7B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IAC5D,CAAC;CACF;AAED;sEACsE;AACtE,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,MAAM,CAAC,GAAG,0BAA0B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC9C,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AACpC,CAAC"}
|
package/dist/tm/ptc/driver.d.ts
CHANGED
|
@@ -18,8 +18,11 @@ export interface EngineSelection {
|
|
|
18
18
|
* - "worker": WorkerEngine only (throws on failure → engine-error status).
|
|
19
19
|
* - "inline": InlineVmEngine only (script timeout for pre-await busy-loops).
|
|
20
20
|
* - "auto" (default): worker-first — the REAL auto-degrade happens in
|
|
21
|
-
* runPtc, which re-runs the whole program on InlineVmEngine when a
|
|
22
|
-
* run returns engine-error
|
|
21
|
+
* runPtc, which re-runs the whole program on InlineVmEngine ONLY when a
|
|
22
|
+
* worker run returns engine-error having made ZERO bridged calls (the
|
|
23
|
+
* worker could not start). A worker that started and then crashed is
|
|
24
|
+
* reported program-error / engine-error-with-calls and is NEVER replayed
|
|
25
|
+
* on the inline realm (C1: never re-run a started program).
|
|
23
26
|
*/
|
|
24
27
|
export declare function selectEngine(mode: "auto" | "worker" | "inline", bridge: PtcBridge): EngineSelection;
|
|
25
28
|
export interface RunPtcOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../../src/tm/ptc/driver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAa,MAAM,eAAe,CAAA;AAMnF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAI9C,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,SAAS,CAAA;IACjB,+DAA+D;IAC/D,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED
|
|
1
|
+
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../../src/tm/ptc/driver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAa,MAAM,eAAe,CAAA;AAMnF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAI9C,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,SAAS,CAAA;IACjB,+DAA+D;IAC/D,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAG,eAAe,CAQnG;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,UAAU,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,GAAG,EAAE,QAAQ,CAAA;IACb,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,MAAM,EAAE,SAAS,CAAA;IACjB,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CACnB;AAED,wBAAsB,MAAM,CAAC,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAoKrE"}
|
package/dist/tm/ptc/driver.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* behavior unchanged.
|
|
6
6
|
*/
|
|
7
7
|
import * as crypto from "node:crypto";
|
|
8
|
-
import { PtcStopSignal } from "./contract.js";
|
|
8
|
+
import { PtcProgramError, PtcStopSignal } from "./contract.js";
|
|
9
9
|
import { createGateBridge } from "./gate.js";
|
|
10
10
|
import { InlineVmEngine, WorkerEngine } from "./engines.js";
|
|
11
11
|
import { staticPscan } from "./pscan.js";
|
|
@@ -14,8 +14,11 @@ import { staticPscan } from "./pscan.js";
|
|
|
14
14
|
* - "worker": WorkerEngine only (throws on failure → engine-error status).
|
|
15
15
|
* - "inline": InlineVmEngine only (script timeout for pre-await busy-loops).
|
|
16
16
|
* - "auto" (default): worker-first — the REAL auto-degrade happens in
|
|
17
|
-
* runPtc, which re-runs the whole program on InlineVmEngine when a
|
|
18
|
-
* run returns engine-error
|
|
17
|
+
* runPtc, which re-runs the whole program on InlineVmEngine ONLY when a
|
|
18
|
+
* worker run returns engine-error having made ZERO bridged calls (the
|
|
19
|
+
* worker could not start). A worker that started and then crashed is
|
|
20
|
+
* reported program-error / engine-error-with-calls and is NEVER replayed
|
|
21
|
+
* on the inline realm (C1: never re-run a started program).
|
|
19
22
|
*/
|
|
20
23
|
export function selectEngine(mode, bridge) {
|
|
21
24
|
void bridge;
|
|
@@ -64,14 +67,18 @@ export async function runPtc(o) {
|
|
|
64
67
|
phase: "args",
|
|
65
68
|
message: `程序包含禁止标识符(${pscan.tokens.join(", ")}),已拒绝执行。`,
|
|
66
69
|
},
|
|
70
|
+
budgets: o.budgets,
|
|
67
71
|
parentStepId: o.parentStepId,
|
|
68
72
|
};
|
|
69
73
|
}
|
|
70
|
-
// Auto-degrade: if the selected engine
|
|
71
|
-
// and we're in auto mode
|
|
72
|
-
|
|
74
|
+
// Auto-degrade: if the selected engine reports an ENGINE fault (not a
|
|
75
|
+
// budget stop, not a program fault), and we're in auto mode, retry with
|
|
76
|
+
// InlineVmEngine. A program fault is tagged PtcProgramError by the
|
|
77
|
+
// engines and mapped to "program-error" below — it never re-runs (the
|
|
78
|
+
// same program would just throw again).
|
|
79
|
+
const tryRun = async (eng, parentId = o.parentStepId) => {
|
|
73
80
|
const state = { calls: 0, errors: 0, retries: 0, steps: [] };
|
|
74
|
-
const gate = createGateBridge(o.bridge,
|
|
81
|
+
const gate = createGateBridge(o.bridge, parentId, o.budgets, state, {
|
|
75
82
|
now,
|
|
76
83
|
deadlineAt,
|
|
77
84
|
store: o.store,
|
|
@@ -79,7 +86,7 @@ export async function runPtc(o) {
|
|
|
79
86
|
// parent call event (design §6)
|
|
80
87
|
o.store?.appendTrajectory({
|
|
81
88
|
tool: "tm_ptc_run",
|
|
82
|
-
step_id:
|
|
89
|
+
step_id: parentId,
|
|
83
90
|
event: "call",
|
|
84
91
|
label: o.label,
|
|
85
92
|
program_sha256: crypto.createHash("sha256").update(o.program).digest("hex"),
|
|
@@ -93,7 +100,10 @@ export async function runPtc(o) {
|
|
|
93
100
|
let returned = false;
|
|
94
101
|
let engineError;
|
|
95
102
|
try {
|
|
96
|
-
returnValue = await eng.run(o.program, gate, ac.signal
|
|
103
|
+
returnValue = await eng.run(o.program, gate, ac.signal, {
|
|
104
|
+
startDeadlineMs: deadlineAt,
|
|
105
|
+
timeoutMs: o.budgets.timeoutMs,
|
|
106
|
+
});
|
|
97
107
|
returned = true;
|
|
98
108
|
status = state.stopReason ? mapStop(state.stopReason) : "ok";
|
|
99
109
|
}
|
|
@@ -101,6 +111,17 @@ export async function runPtc(o) {
|
|
|
101
111
|
if (err instanceof PtcStopSignal) {
|
|
102
112
|
status = mapStop(err.reason);
|
|
103
113
|
}
|
|
114
|
+
else if (err instanceof PtcProgramError) {
|
|
115
|
+
// T5: the PROGRAM threw — distinct status, NO auto-degrade re-run.
|
|
116
|
+
status = "program-error";
|
|
117
|
+
const line = extractLine(err);
|
|
118
|
+
engineError = {
|
|
119
|
+
tool: "tm_ptc_run",
|
|
120
|
+
phase: "execute",
|
|
121
|
+
message: err.message,
|
|
122
|
+
...(line != null ? { line } : {}),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
104
125
|
else {
|
|
105
126
|
status = "engine-error";
|
|
106
127
|
const line = extractLine(err);
|
|
@@ -130,11 +151,12 @@ export async function runPtc(o) {
|
|
|
130
151
|
returnValue,
|
|
131
152
|
returned,
|
|
132
153
|
...(engineError ? { engineError } : {}),
|
|
133
|
-
|
|
154
|
+
budgets: o.budgets,
|
|
155
|
+
parentStepId: parentId,
|
|
134
156
|
};
|
|
135
157
|
o.store?.appendTrajectory({
|
|
136
158
|
tool: "tm_ptc_run",
|
|
137
|
-
step_id:
|
|
159
|
+
step_id: parentId,
|
|
138
160
|
event: "finish",
|
|
139
161
|
status: outcome.status,
|
|
140
162
|
calls: outcome.calls,
|
|
@@ -144,15 +166,25 @@ export async function runPtc(o) {
|
|
|
144
166
|
});
|
|
145
167
|
return outcome;
|
|
146
168
|
};
|
|
147
|
-
// Auto mode: try worker first
|
|
148
|
-
|
|
169
|
+
// Auto mode: try worker first. C1 (never replay a started program): degrade
|
|
170
|
+
// to the inline-vm engine ONLY when the worker could not START at all — an
|
|
171
|
+
// ENGINE fault with ZERO bridged calls dispatched (the program never ran).
|
|
172
|
+
// A worker that started and THEN crashed surfaces as `program-error` (the
|
|
173
|
+
// engines tag any post-online crash a program fault) or as an `engine-error`
|
|
174
|
+
// with calls > 0; in BOTH such cases we return as-is and do NOT re-run the
|
|
175
|
+
// program on the more-privileged inline/ESM realm — re-running a program
|
|
176
|
+
// that already executed is exactly the sandbox-escape amplification the
|
|
177
|
+
// reviewer's PoC turned on. An INJECTED engine participates too (tests
|
|
178
|
+
// inject crashers); the fallback is always the real InlineVmEngine.
|
|
179
|
+
if (o.cfg.ptcEngine === "auto" && engine.name === "worker") {
|
|
149
180
|
const result = await tryRun(engine);
|
|
150
|
-
if (result.status === "engine-error") {
|
|
181
|
+
if (result.status === "engine-error" && result.calls === 0) {
|
|
151
182
|
// Degrade to inline-vm and re-run.
|
|
152
183
|
const inlineEngine = new InlineVmEngine();
|
|
153
|
-
const fallback = await tryRun(inlineEngine);
|
|
184
|
+
const fallback = await tryRun(inlineEngine, `${o.parentStepId}.r2`);
|
|
154
185
|
fallback.degraded = true;
|
|
155
186
|
fallback.engine = "inline";
|
|
187
|
+
fallback.parentStepId = o.parentStepId;
|
|
156
188
|
return fallback;
|
|
157
189
|
}
|
|
158
190
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../../../src/tm/ptc/driver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAIrC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../../../src/tm/ptc/driver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;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ary: WorkerEngine (worker_threads + MessagePort RPC, env:{},
|
|
9
9
|
* resourceLimits, hard `terminate()` wall-clock kill; bootstrap as a
|
|
10
|
-
* build-time string
|
|
11
|
-
*
|
|
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
|
|
12
14
|
* kills PRE-await synchronous busy-loops; a POST-await busy loop blocks the
|
|
13
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.
|
|
14
25
|
*/
|
|
15
|
-
import type { PtcBridge, PtcEngine, PtcEngineName } from "./contract.js";
|
|
26
|
+
import type { PtcBridge, PtcEngine, PtcEngineName, PtcEngineRunOpts } from "./contract.js";
|
|
16
27
|
export declare class InlineSequentialEngine implements PtcEngine {
|
|
17
28
|
readonly name: PtcEngineName;
|
|
18
29
|
run(program: string, bridge: PtcBridge, signal: AbortSignal): Promise<unknown>;
|
|
19
30
|
}
|
|
20
31
|
export declare class WorkerEngine implements PtcEngine {
|
|
21
32
|
readonly name: PtcEngineName;
|
|
22
|
-
run(program: string, bridge: PtcBridge, signal: AbortSignal): Promise<unknown>;
|
|
33
|
+
run(program: string, bridge: PtcBridge, signal: AbortSignal, opts?: PtcEngineRunOpts): Promise<unknown>;
|
|
23
34
|
}
|
|
24
35
|
export declare class InlineVmEngine implements PtcEngine {
|
|
25
36
|
readonly name: PtcEngineName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engines.d.ts","sourceRoot":"","sources":["../../../src/tm/ptc/engines.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"engines.d.ts","sourceRoot":"","sources":["../../../src/tm/ptc/engines.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAiC,MAAM,eAAe,CAAA;AAuHzH,qBAAa,sBAAuB,YAAW,SAAS;IACtD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAW;IACjC,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;CAyBrF;AAID,qBAAa,YAAa,YAAW,SAAS;IAC5C,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAW;IAEjC,GAAG,CACP,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,WAAW,EACnB,IAAI,CAAC,EAAE,gBAAgB,GACtB,OAAO,CAAC,OAAO,CAAC;CAkOpB;AAID,qBAAa,cAAe,YAAW,SAAS;IAC9C,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAW;IACvC;mEAC+D;IAC/D,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAQ;gBAC7B,gBAAgB,SAAS;IAI/B,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;CAoFrF"}
|