@tangle-network/sdk-cli-runner 0.3.0 → 0.3.1

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 CHANGED
@@ -61,6 +61,13 @@ interface CliSpawnConfig {
61
61
  * may start a process meant to outlive it (a dev server a preview serves).
62
62
  */
63
63
  ownProcessGroup?: boolean;
64
+ /**
65
+ * What a child that rejects its stdin (closes the pipe early) gets. "stop"
66
+ * (default) stops it, because an adapter's turn cannot continue without its
67
+ * input. "report" lets it exit on its own and reports `stdinError`, for a
68
+ * caller that judges the exit itself.
69
+ */
70
+ stdinFailure?: "stop" | "report";
64
71
  }
65
72
  /** What a consumer-owned launch is asked to start, after env assembly. */
66
73
  interface CliLaunchSpec {
@@ -119,6 +126,8 @@ interface CliExitResult {
119
126
  spawnError?: string;
120
127
  /** The native child closed or rejected stdin before its input was delivered. */
121
128
  stdinError?: string;
129
+ /** The errno code of `stdinError` (EPIPE for a pipe the child closed). */
130
+ stdinErrorCode?: string;
122
131
  /** Raw evidence could not be written or flushed; the process is not a complete trace. */
123
132
  captureError?: string;
124
133
  /** The caller's abort signal fired before the process exited. */
@@ -229,6 +238,8 @@ interface CliExecResult<T> {
229
238
  interface CliExecOptions {
230
239
  /** Newest stdout and stderr bytes retained per stream. Default 64 MiB. */
231
240
  maxOutputBytes?: number;
241
+ /** Written to the child's stdin, which then closes. Omitted: stdin stays as the config leaves it. */
242
+ stdin?: string;
232
243
  }
233
244
  /**
234
245
  * One value the runner writes to a child process's standard input. A string
package/dist/index.mjs CHANGED
@@ -1118,7 +1118,7 @@ function attachCliProcess(config, parserConfig, run) {
1118
1118
  const { launch, killer, capture, detached } = run;
1119
1119
  const child = launch.child;
1120
1120
  const spawnedAt = Date.now();
1121
- const stdin = watchStdinFailure(child, killer);
1121
+ const stdin = watchStdinFailure(child, killer, config.stdinFailure);
1122
1122
  const group = config.ownProcessGroup && detached && process.platform !== "win32" && child.pid ? new CliProcessGroup(child.pid) : void 0;
1123
1123
  child.stdout?.on("data", (chunk) => capture.frame("stdout", chunk));
1124
1124
  child.stderr?.on("data", (chunk) => capture.frame("stderr", chunk));
@@ -1201,11 +1201,16 @@ function spawnChild(config, processEnv, detached) {
1201
1201
  ...isolated ? safeSpawnOptions : spawnOptions
1202
1202
  });
1203
1203
  }
1204
- function watchStdinFailure(child, killer) {
1205
- const failure = { error: void 0 };
1204
+ function watchStdinFailure(child, killer, mode = "stop") {
1205
+ const failure = {
1206
+ error: void 0,
1207
+ code: void 0
1208
+ };
1206
1209
  child.stdin?.on("error", (error) => {
1207
1210
  if (failure.error !== void 0) return;
1208
1211
  failure.error = error.message;
1212
+ failure.code = error.code;
1213
+ if (mode === "report") return;
1209
1214
  killer.kill("SIGTERM");
1210
1215
  if (!killer.escalating) killer.escalate(() => child.exitCode === null && child.signalCode === null);
1211
1216
  });
@@ -1280,6 +1285,7 @@ function createExitPromise(child, run) {
1280
1285
  timeoutReason: deadlines.timeoutReason,
1281
1286
  timeoutDiagnostic: deadlines.timeoutDiagnostic,
1282
1287
  stdinError: stdin.error,
1288
+ ...stdin.code === void 0 ? {} : { stdinErrorCode: stdin.code },
1283
1289
  captureError: capture.error,
1284
1290
  ...abort.aborted ? { aborted: true } : {},
1285
1291
  ...processGroupError === void 0 ? {} : { processGroupError },
@@ -1325,6 +1331,10 @@ async function execCli(config, parserConfig, options = {}) {
1325
1331
  } : void 0);
1326
1332
  cliProcess.process.stderr?.on("data", (chunk) => stderr.append(chunk));
1327
1333
  if (!parserConfig) cliProcess.process.stdout?.on("data", (chunk) => stdout.append(chunk));
1334
+ if (options.stdin !== void 0) {
1335
+ if (options.stdin) cliProcess.write(options.stdin);
1336
+ cliProcess.closeInput();
1337
+ }
1328
1338
  return {
1329
1339
  exit: await cliProcess.exitPromise,
1330
1340
  stderr: stderr.text(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/sdk-cli-runner",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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": "e962211a1ce5f2e11a99b60421e45fca5547ca2d",
30
- "mergedAt": "2026-10-27T03:53:58-06:00"
29
+ "sourceSha": "eac50ce23f7e07901fb8d90150c8032bbc40d2b0",
30
+ "mergedAt": "2026-10-28T12:36:25-06:00"
31
31
  },
32
32
  "scripts": {
33
33
  "build": "tsdown",