@tangle-network/sdk-cli-runner 0.3.1 → 0.3.3
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 -11
- package/dist/index.mjs +14 -20
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -185,8 +185,7 @@ interface CliProcess {
|
|
|
185
185
|
interface StreamParserConfig<T> {
|
|
186
186
|
/**
|
|
187
187
|
* Parse mode. See the interface docstring for the contract per mode.
|
|
188
|
-
* Defaults to "json"
|
|
189
|
-
* JSONL-only API.
|
|
188
|
+
* Defaults to "json".
|
|
190
189
|
*/
|
|
191
190
|
parseAs?: "json" | "lines" | "raw";
|
|
192
191
|
/**
|
|
@@ -344,6 +343,16 @@ declare function launchDifferences(spare: Pick<HeldSpareFields<unknown>, "args"
|
|
|
344
343
|
env: Readonly<Record<string, string | undefined>>;
|
|
345
344
|
}, comparable?: (key: string, value: string | undefined) => string | undefined): string[];
|
|
346
345
|
//#endregion
|
|
346
|
+
//#region src/owned-process-tree.d.ts
|
|
347
|
+
type ProcessIdentity = {
|
|
348
|
+
pid: number;
|
|
349
|
+
parent: number;
|
|
350
|
+
group: number;
|
|
351
|
+
start: string;
|
|
352
|
+
state: string;
|
|
353
|
+
};
|
|
354
|
+
declare function readProcessIdentity(pid: number): ProcessIdentity | undefined;
|
|
355
|
+
//#endregion
|
|
347
356
|
//#region src/raw-capture.d.ts
|
|
348
357
|
/** Hard encoded-byte bound across canonical JSON spool files, including live writers.
|
|
349
358
|
* Temporary trim copies and filesystem allocation are separate from this budget.
|
|
@@ -447,7 +456,7 @@ interface RpcBridgeLogger {
|
|
|
447
456
|
warn: (msg: string, meta?: Record<string, unknown>) => void;
|
|
448
457
|
error: (msg: string, meta?: Record<string, unknown>) => void;
|
|
449
458
|
}
|
|
450
|
-
interface RpcBridgeConfig {
|
|
459
|
+
interface RpcBridgeConfig extends Pick<CliSpawnConfig, "inheritEnv"> {
|
|
451
460
|
command: string;
|
|
452
461
|
args: string[];
|
|
453
462
|
cwd: string;
|
|
@@ -543,13 +552,7 @@ declare class RpcRequestTimeoutError extends Error {
|
|
|
543
552
|
}
|
|
544
553
|
//#endregion
|
|
545
554
|
//#region src/rpc-stdio-process.d.ts
|
|
546
|
-
/**
|
|
547
|
-
* Spawn an RpcBridge over a long-running stdio child process.
|
|
548
|
-
*
|
|
549
|
-
* The bridge is usable immediately after this call — outbound writes
|
|
550
|
-
* before the child has booted are buffered by Node's stdin pipe. Inbound
|
|
551
|
-
* dispatch starts as soon as the child writes its first line.
|
|
552
|
-
*/
|
|
555
|
+
/** Spawn one stdio RPC child; early writes buffer until it boots. */
|
|
553
556
|
declare function spawnRpcBridge(config: RpcBridgeConfig): RpcBridge;
|
|
554
557
|
//#endregion
|
|
555
558
|
//#region src/shell-quote.d.ts
|
|
@@ -580,5 +583,5 @@ declare function mergeSpawnEnv(base: NodeJS.ProcessEnv, overrides: Record<string
|
|
|
580
583
|
*/
|
|
581
584
|
declare function createStreamParser<T>(config: StreamParserConfig<T>): StreamParser<T>;
|
|
582
585
|
//#endregion
|
|
583
|
-
export { BridgeClosedError, type CliExecOptions, type CliExecResult, type CliExitResult, type CliLaunch, type CliLaunchSpec, type CliLauncher, type CliProcess, type CliSpawnConfig, type CliStdinValue, HELD_SPARE_IDLE_MS, type HeldSpare, type HeldSpareRegistry, InvalidAttachmentError, JsonRpcError, RAW_CAPTURE_ROOT, RAW_CAPTURE_TOTAL_CAP_BYTES, type RawCaptureProcess, type RpcBridge, type RpcBridgeConfig, type RpcCloseReason, type RpcNotificationHandler, type RpcRequestHandler, type RpcRequestOptions, RpcRequestTimeoutError, type StreamParserConfig, allowRetainedRawCapture, argAfter, createDeferredParser, createHeldSpareRegistry, createStreamParser, execCli, launchCliProcess, launchDifferences, mergeSpawnEnv, openRawCapture, removeRawCapture, resolveRawCapturePath, shellQuote, spawnCliProcess, spawnRpcBridge, summarizeRawCapture, trimRawCapture, withRawCaptureAttempt };
|
|
586
|
+
export { BridgeClosedError, type CliExecOptions, type CliExecResult, type CliExitResult, type CliLaunch, type CliLaunchSpec, type CliLauncher, type CliProcess, type CliSpawnConfig, type CliStdinValue, HELD_SPARE_IDLE_MS, type HeldSpare, type HeldSpareRegistry, InvalidAttachmentError, JsonRpcError, RAW_CAPTURE_ROOT, RAW_CAPTURE_TOTAL_CAP_BYTES, type RawCaptureProcess, type RpcBridge, type RpcBridgeConfig, type RpcCloseReason, type RpcNotificationHandler, type RpcRequestHandler, type RpcRequestOptions, RpcRequestTimeoutError, type StreamParserConfig, allowRetainedRawCapture, argAfter, createDeferredParser, createHeldSpareRegistry, createStreamParser, execCli, launchCliProcess, launchDifferences, mergeSpawnEnv, openRawCapture, readProcessIdentity, removeRawCapture, resolveRawCapturePath, shellQuote, spawnCliProcess, spawnRpcBridge, summarizeRawCapture, trimRawCapture, withRawCaptureAttempt };
|
|
584
587
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -770,7 +770,7 @@ var ProcessCapture = class {
|
|
|
770
770
|
};
|
|
771
771
|
//#endregion
|
|
772
772
|
//#region src/owned-process-tree.ts
|
|
773
|
-
function
|
|
773
|
+
function readProcessIdentity(pid) {
|
|
774
774
|
try {
|
|
775
775
|
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
776
776
|
const fields = stat.slice(stat.lastIndexOf(")") + 2).trim().split(/\s+/);
|
|
@@ -794,7 +794,7 @@ var OwnedProcessTree = class {
|
|
|
794
794
|
groups = /* @__PURE__ */ new Map();
|
|
795
795
|
root;
|
|
796
796
|
constructor(rootPid) {
|
|
797
|
-
const root =
|
|
797
|
+
const root = readProcessIdentity(rootPid);
|
|
798
798
|
this.root = root;
|
|
799
799
|
if (root) {
|
|
800
800
|
this.processes.set(rootPid, root);
|
|
@@ -809,7 +809,7 @@ var OwnedProcessTree = class {
|
|
|
809
809
|
const key = `${expected.pid}:${expected.start}`;
|
|
810
810
|
if (seen.has(key)) continue;
|
|
811
811
|
seen.add(key);
|
|
812
|
-
const current =
|
|
812
|
+
const current = readProcessIdentity(expected.pid);
|
|
813
813
|
if (!current || current.start !== expected.start || current.state === "Z" || current.state === "X") {
|
|
814
814
|
if (this.processes.get(expected.pid)?.start === expected.start) this.processes.delete(expected.pid);
|
|
815
815
|
continue;
|
|
@@ -826,7 +826,7 @@ var OwnedProcessTree = class {
|
|
|
826
826
|
for (const value of children.trim().split(/\s+/).filter(Boolean)) {
|
|
827
827
|
const pid = Number(value);
|
|
828
828
|
if (!Number.isSafeInteger(pid) || pid <= 0) throw new Error("Invalid child process identity");
|
|
829
|
-
const child =
|
|
829
|
+
const child = readProcessIdentity(pid);
|
|
830
830
|
if (!child || child.parent !== current.pid) continue;
|
|
831
831
|
this.processes.set(pid, child);
|
|
832
832
|
queue.push(child);
|
|
@@ -837,7 +837,7 @@ var OwnedProcessTree = class {
|
|
|
837
837
|
}
|
|
838
838
|
live() {
|
|
839
839
|
return [...this.processes.values()].flatMap((expected) => {
|
|
840
|
-
const current =
|
|
840
|
+
const current = readProcessIdentity(expected.pid);
|
|
841
841
|
return current && current.start === expected.start && current.state !== "Z" && current.state !== "X" ? [current] : [];
|
|
842
842
|
});
|
|
843
843
|
}
|
|
@@ -854,14 +854,14 @@ var OwnedProcessTree = class {
|
|
|
854
854
|
}
|
|
855
855
|
for (const entry of readdirSync("/proc")) {
|
|
856
856
|
if (!/^[1-9][0-9]*$/.test(entry)) continue;
|
|
857
|
-
const member =
|
|
857
|
+
const member = readProcessIdentity(Number(entry));
|
|
858
858
|
if (member && member.group === root.group && member.state !== "Z" && member.state !== "X") this.processes.set(member.pid, member);
|
|
859
859
|
}
|
|
860
860
|
return this.live().length > 0;
|
|
861
861
|
}
|
|
862
862
|
ownsRootGroup() {
|
|
863
863
|
if (!this.root || this.root.group !== this.root.pid) return false;
|
|
864
|
-
const current =
|
|
864
|
+
const current = readProcessIdentity(this.root.pid);
|
|
865
865
|
return !current || current.start === this.root.start;
|
|
866
866
|
}
|
|
867
867
|
signal(signal) {
|
|
@@ -875,7 +875,7 @@ var OwnedProcessTree = class {
|
|
|
875
875
|
}
|
|
876
876
|
for (const member of this.live()) {
|
|
877
877
|
const groupStart = this.groups.get(member.group);
|
|
878
|
-
const leader = groupStart === void 0 ? void 0 :
|
|
878
|
+
const leader = groupStart === void 0 ? void 0 : readProcessIdentity(member.group);
|
|
879
879
|
const target = groupStart !== void 0 && (!leader || leader.start === groupStart) ? -member.group : member.pid;
|
|
880
880
|
if (target < 0 && signaledGroups.has(target)) continue;
|
|
881
881
|
try {
|
|
@@ -2133,17 +2133,10 @@ const noopLogger = {
|
|
|
2133
2133
|
warn: () => {},
|
|
2134
2134
|
error: () => {}
|
|
2135
2135
|
};
|
|
2136
|
-
/**
|
|
2137
|
-
* Spawn an RpcBridge over a long-running stdio child process.
|
|
2138
|
-
*
|
|
2139
|
-
* The bridge is usable immediately after this call — outbound writes
|
|
2140
|
-
* before the child has booted are buffered by Node's stdin pipe. Inbound
|
|
2141
|
-
* dispatch starts as soon as the child writes its first line.
|
|
2142
|
-
*/
|
|
2136
|
+
/** Spawn one stdio RPC child; early writes buffer until it boots. */
|
|
2143
2137
|
function spawnRpcBridge(config) {
|
|
2144
2138
|
const { maxPendingRequests = DEFAULT_MAX_PENDING, maxStderrBytes = DEFAULT_MAX_STDERR_BYTES, defaultRequestTimeoutMs = DEFAULT_REQUEST_TIMEOUT_MS, defaultCloseGraceMs = DEFAULT_CLOSE_GRACE_MS, hardCloseDeadlineMs = DEFAULT_HARD_CLOSE_DEADLINE_MS, logger = noopLogger, rawCapturePath, rawCapturePerTurn = false, detached = false, stdinCloseGraceMs = 0 } = config;
|
|
2145
|
-
const processEnv =
|
|
2146
|
-
applyChildToolPath(processEnv);
|
|
2139
|
+
const processEnv = buildChildEnv(config);
|
|
2147
2140
|
const capture = new RpcByteCapture(rawCapturePath, rawCapturePerTurn, (killSignal) => owner.kill(killSignal), () => owner.captureTree(), () => lifecycle.childError?.message ?? null);
|
|
2148
2141
|
let child;
|
|
2149
2142
|
let isolatedLaunch;
|
|
@@ -2210,13 +2203,14 @@ function spawnRpcBridge(config) {
|
|
|
2210
2203
|
}
|
|
2211
2204
|
/** Start the bridge's child: through the runner for an isolated identity. */
|
|
2212
2205
|
function spawnBridgeChild(config, processEnv) {
|
|
2213
|
-
const { command, args, cwd,
|
|
2206
|
+
const { command, args, cwd, uid, gid, isolatedIdentity } = config;
|
|
2214
2207
|
if (isolatedIdentity) {
|
|
2215
2208
|
const isolatedLaunch = spawnCliProcess({
|
|
2216
2209
|
command,
|
|
2217
2210
|
args,
|
|
2218
2211
|
cwd,
|
|
2219
|
-
env,
|
|
2212
|
+
env: processEnv,
|
|
2213
|
+
inheritEnv: false,
|
|
2220
2214
|
isolatedIdentity,
|
|
2221
2215
|
spawnOptions: {
|
|
2222
2216
|
uid: uid ?? isolatedIdentity.uid,
|
|
@@ -2280,6 +2274,6 @@ function shellQuote(value) {
|
|
|
2280
2274
|
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
2281
2275
|
}
|
|
2282
2276
|
//#endregion
|
|
2283
|
-
export { BridgeClosedError, HELD_SPARE_IDLE_MS, InvalidAttachmentError, JsonRpcError, RAW_CAPTURE_ROOT, RAW_CAPTURE_TOTAL_CAP_BYTES, RpcRequestTimeoutError, allowRetainedRawCapture, argAfter, createDeferredParser, createHeldSpareRegistry, createStreamParser, execCli, launchCliProcess, launchDifferences, mergeSpawnEnv, openRawCapture, removeRawCapture, resolveRawCapturePath, shellQuote, spawnCliProcess, spawnRpcBridge, summarizeRawCapture, trimRawCapture, withRawCaptureAttempt };
|
|
2277
|
+
export { BridgeClosedError, HELD_SPARE_IDLE_MS, InvalidAttachmentError, JsonRpcError, RAW_CAPTURE_ROOT, RAW_CAPTURE_TOTAL_CAP_BYTES, RpcRequestTimeoutError, allowRetainedRawCapture, argAfter, createDeferredParser, createHeldSpareRegistry, createStreamParser, execCli, launchCliProcess, launchDifferences, mergeSpawnEnv, openRawCapture, readProcessIdentity, removeRawCapture, resolveRawCapturePath, shellQuote, spawnCliProcess, spawnRpcBridge, summarizeRawCapture, trimRawCapture, withRawCaptureAttempt };
|
|
2284
2278
|
|
|
2285
2279
|
//# sourceMappingURL=index.mjs.map
|
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.3",
|
|
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-
|
|
29
|
+
"sourceSha": "ec76ad8dd9f21b388654829015d2e4ee40c364a6",
|
|
30
|
+
"mergedAt": "2026-11-01T21:24:07-08:00"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsdown",
|