@tangle-network/sdk-cli-runner 0.3.18 → 0.3.20
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/dist/index.d.mts +14 -4
- package/dist/index.mjs +27 -7
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -159,6 +159,13 @@ interface CliProcess {
|
|
|
159
159
|
* no-op for any other process, or once the process has exited.
|
|
160
160
|
*/
|
|
161
161
|
beginRawCapture?(): void;
|
|
162
|
+
/**
|
|
163
|
+
* Bound a process spawned without `timeoutMs` (a held spare a turn adopted)
|
|
164
|
+
* to `budgetMs` from now. Past it the process ends as one spawned now with
|
|
165
|
+
* that `timeoutMs` would: SIGTERM then escalation, and an exit with
|
|
166
|
+
* `timedOut`, `timeoutReason: "fixed"` and the deadline's diagnostic.
|
|
167
|
+
*/
|
|
168
|
+
armDeadline?(budgetMs: number): void;
|
|
162
169
|
}
|
|
163
170
|
/**
|
|
164
171
|
* Configuration for stream parsing.
|
|
@@ -274,7 +281,7 @@ declare function execCli<T = unknown>(config: CliSpawnConfig, parserConfig?: Str
|
|
|
274
281
|
//#endregion
|
|
275
282
|
//#region src/held-spare.d.ts
|
|
276
283
|
/** The process handle a spare keeps and a turn takes over. */
|
|
277
|
-
type HeldSpareProcess = Pick<CliProcess, "pid" | "write" | "closeInput" | "kill" | "exitPromise" | "beginRawCapture"> & {
|
|
284
|
+
type HeldSpareProcess = Pick<CliProcess, "pid" | "write" | "closeInput" | "kill" | "exitPromise" | "beginRawCapture" | "armDeadline"> & {
|
|
278
285
|
stderr?: NodeJS.ReadableStream;
|
|
279
286
|
};
|
|
280
287
|
/**
|
|
@@ -320,14 +327,17 @@ interface HeldSpareRegistry<TEvent, TExtra extends object = object> {
|
|
|
320
327
|
* The turn takes the spare's process: the spare is claimed, its raw capture
|
|
321
328
|
* opens in the turn's attempt (what the process printed before is the
|
|
322
329
|
* turn's too), its output so far and from now on goes to the turn's parser,
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
330
|
+
* the turn's abort signal stops it, and the turn's `timeoutMs` bounds it
|
|
331
|
+
* from now, as it bounds a process the turn spawns. Returns the handle the
|
|
332
|
+
* turn drives. Throws for a spare that is stopped or already claimed, and
|
|
333
|
+
* stops the spare and throws when its capture cannot open or already failed
|
|
334
|
+
* while held, or when the turn has a deadline its process cannot take; the
|
|
326
335
|
* turn then starts its own process.
|
|
327
336
|
*/
|
|
328
337
|
adopt(spare: HeldSpare<TEvent, TExtra>, turn: {
|
|
329
338
|
parser: StreamParserConfig<TEvent>;
|
|
330
339
|
signal: AbortSignal;
|
|
340
|
+
timeoutMs?: number;
|
|
331
341
|
}): HeldSpareProcess;
|
|
332
342
|
/**
|
|
333
343
|
* End every spare no turn claimed, and wait for the processes to exit.
|
package/dist/index.mjs
CHANGED
|
@@ -143,26 +143,37 @@ var CliDeadlines = class {
|
|
|
143
143
|
timeoutReason;
|
|
144
144
|
timeoutDiagnostic;
|
|
145
145
|
fixedTimerId;
|
|
146
|
+
exited = false;
|
|
146
147
|
constructor(config, child, killer, spawnedAt) {
|
|
147
148
|
this.config = config;
|
|
148
149
|
this.child = child;
|
|
149
150
|
this.killer = killer;
|
|
150
151
|
this.spawnedAt = spawnedAt;
|
|
151
152
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Arm the fixed bound: the spawn's `timeoutMs`, counted from the spawn, or
|
|
155
|
+
* `budgetMs` counted from now, for a process a turn took over after it
|
|
156
|
+
* started (a held spare), as if that turn had spawned it now. A process has
|
|
157
|
+
* one fixed bound: arming a second throws. One that exited arms nothing.
|
|
158
|
+
*/
|
|
159
|
+
arm(budgetMs) {
|
|
160
|
+
const adopted = budgetMs !== void 0;
|
|
161
|
+
const timeoutMs = adopted ? budgetMs : this.config.timeoutMs;
|
|
162
|
+
if (this.exited || !(timeoutMs && timeoutMs > 0)) return;
|
|
163
|
+
if (this.fixedTimerId) throw new Error(`"${this.config.command}" already has a deadline`);
|
|
164
|
+
const from = adopted ? Date.now() : this.spawnedAt;
|
|
165
|
+
this.fixedTimerId = setTimeout(() => this.killOnTimeout(timeoutMs, from), timeoutMs);
|
|
156
166
|
}
|
|
157
167
|
clearAll() {
|
|
168
|
+
this.exited = true;
|
|
158
169
|
if (this.fixedTimerId) clearTimeout(this.fixedTimerId);
|
|
159
170
|
this.killer.clearEscalation();
|
|
160
171
|
}
|
|
161
|
-
killOnTimeout(budgetMs) {
|
|
172
|
+
killOnTimeout(budgetMs, from) {
|
|
162
173
|
if (this.timedOut) return;
|
|
163
174
|
this.timedOut = true;
|
|
164
175
|
this.timeoutReason = "fixed";
|
|
165
|
-
this.timeoutDiagnostic = `"${this.config.command}" ran past its deadline of ${budgetMs}ms; killed after ${Date.now() -
|
|
176
|
+
this.timeoutDiagnostic = `"${this.config.command}" ran past its deadline of ${budgetMs}ms; killed after ${Date.now() - from}ms`;
|
|
166
177
|
this.killer.kill("SIGTERM");
|
|
167
178
|
this.killer.escalate(() => this.child.exitCode === null);
|
|
168
179
|
}
|
|
@@ -1396,6 +1407,9 @@ function attachCliProcess(config, parserConfig, run) {
|
|
|
1396
1407
|
beginRawCapture() {
|
|
1397
1408
|
capture.begin();
|
|
1398
1409
|
},
|
|
1410
|
+
armDeadline(budgetMs) {
|
|
1411
|
+
deadlines.arm(budgetMs);
|
|
1412
|
+
},
|
|
1399
1413
|
exitPromise
|
|
1400
1414
|
};
|
|
1401
1415
|
}
|
|
@@ -1409,7 +1423,7 @@ function assertSpawnable(config) {
|
|
|
1409
1423
|
function assertRawCaptureStdio(config) {
|
|
1410
1424
|
if (!config.rawCapturePath || config.spawnOptions?.stdio === void 0) return;
|
|
1411
1425
|
const io = config.spawnOptions.stdio;
|
|
1412
|
-
if (!Array.isArray(io) ||
|
|
1426
|
+
if (!Array.isArray(io) || !["pipe", "ignore"].includes(String(io[0])) || io[1] !== "pipe" || io[2] !== "pipe") throw new Error("raw capture requires piped stdout and stderr, with pipe or ignored stdin");
|
|
1413
1427
|
}
|
|
1414
1428
|
function spawnChild(config, processEnv, detached, stdout) {
|
|
1415
1429
|
const { command, args, cwd, spawnOptions, isolatedIdentity } = config;
|
|
@@ -1760,6 +1774,11 @@ function createHeldSpareRegistry(options = {}) {
|
|
|
1760
1774
|
claim,
|
|
1761
1775
|
adopt: (spare, turn) => {
|
|
1762
1776
|
if (spare.state === "stopped" || spare.state === "claimed") throw new Error(`A ${spare.state} spare cannot be adopted`);
|
|
1777
|
+
const armDeadline = spare.process.armDeadline;
|
|
1778
|
+
if (turn.timeoutMs !== void 0 && !armDeadline) {
|
|
1779
|
+
stop(spare);
|
|
1780
|
+
throw new Error("The spare's process cannot take the turn's deadline");
|
|
1781
|
+
}
|
|
1763
1782
|
try {
|
|
1764
1783
|
spare.process.beginRawCapture?.();
|
|
1765
1784
|
} catch (error) {
|
|
@@ -1771,6 +1790,7 @@ function createHeldSpareRegistry(options = {}) {
|
|
|
1771
1790
|
const kill = () => spare.process.kill();
|
|
1772
1791
|
if (turn.signal.aborted) kill();
|
|
1773
1792
|
else turn.signal.addEventListener("abort", kill, { once: true });
|
|
1793
|
+
if (turn.timeoutMs !== void 0) armDeadline?.(turn.timeoutMs);
|
|
1774
1794
|
return {
|
|
1775
1795
|
...spare.process,
|
|
1776
1796
|
exitPromise: spare.process.exitPromise.finally(() => turn.signal.removeEventListener("abort", kill))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/sdk-cli-runner",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.20",
|
|
4
4
|
"description": "Generic CLI process spawning with stdin/stdout streaming and JSONL parsing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"registry": "https://registry.npmjs.org"
|
|
27
27
|
},
|
|
28
28
|
"tangleRelease": {
|
|
29
|
-
"sourceSha": "
|
|
30
|
-
"mergedAt": "2026-11-
|
|
29
|
+
"sourceSha": "7ea6db9ea259e8dd67074d20fd4e1378abc2c094",
|
|
30
|
+
"mergedAt": "2026-11-28T21:53:25-08:00"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsdown",
|