@tangle-network/sdk-cli-runner 0.3.13 → 0.3.15

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
@@ -163,13 +163,15 @@ interface CliProcess {
163
163
  /**
164
164
  * Configuration for stream parsing.
165
165
  *
166
- * Three modes cover every CLI output shape we've encountered:
166
+ * Choose the unit the native CLI emits:
167
167
  *
168
168
  * - **"json"** (default): newline-delimited JSON. Each line is parsed via
169
169
  * `JSON.parse`, then passed to `transform`. Used by claude-code, codex.
170
170
  * - **"lines"**: plaintext with one logical event per line. Each line is
171
171
  * passed to `transform` as a raw trimmed string with no JSON parsing.
172
172
  * Used by hermes quiet mode plaintext response lines.
173
+ * - **"chunks"**: each decoded UTF-8 stdout chunk reaches the consumer as it
174
+ * arrives, including incomplete lines and whitespace.
173
175
  * - **"raw"**: stdout chunks delivered verbatim with no per-line splitting.
174
176
  * `transform` is NOT called; instead the parser maintains a single
175
177
  * accumulating buffer that the consumer reads in `onComplete`. Used by
@@ -187,15 +189,16 @@ interface StreamParserConfig<T> {
187
189
  * Parse mode. See the interface docstring for the contract per mode.
188
190
  * Defaults to "json".
189
191
  */
190
- parseAs?: "json" | "lines" | "raw";
192
+ parseAs?: "json" | "lines" | "chunks" | "raw";
191
193
  /**
192
194
  * Transform a parsed event to the desired type (return null to skip).
193
195
  * In "json" mode the input is the JSON.parse result; in "lines" mode it
194
196
  * is the raw trimmed line string. **Ignored in "raw" mode** — the
195
- * consumer reads the full buffer via `onRawComplete`.
197
+ * consumer reads the full buffer via `onComplete`. In "chunks" mode
198
+ * the input is the decoded stdout chunk.
196
199
  */
197
200
  transform?: (raw: unknown) => T | null;
198
- /** Called for each parsed event ("json" and "lines" modes only). */
201
+ /** Called for each transformed event, except in "raw" mode. */
199
202
  onEvent: (event: T) => void;
200
203
  /** Called on parse errors (only fires in "json" mode) */
201
204
  onError?: (error: Error, rawLine: string) => void;
@@ -204,7 +207,7 @@ interface StreamParserConfig<T> {
204
207
  *
205
208
  * In "raw" mode, the full untouched stdout buffer is passed as the
206
209
  * argument so consumers can parse it however they want (single
207
- * `JSON.parse`, regex extraction, etc). In "json" and "lines" modes the
210
+ * `JSON.parse`, regex extraction, etc). In all other modes the
208
211
  * argument is undefined — events were already delivered via `onEvent`.
209
212
  */
210
213
  onComplete?: (rawBuffer?: string) => void;
@@ -608,10 +611,11 @@ declare function mergeSpawnEnv(base: NodeJS.ProcessEnv, overrides: Record<string
608
611
  //#endregion
609
612
  //#region src/stream-parser.d.ts
610
613
  /**
611
- * Creates a stdout stream parser. Three modes:
614
+ * Creates a stdout stream parser.
612
615
  *
613
616
  * - "json" (default): newline-delimited JSON, JSON.parse per line.
614
617
  * - "lines": plaintext, raw trimmed line per `transform` call.
618
+ * - "chunks": each decoded stdout chunk goes straight to the consumer.
615
619
  * - "raw": no per-line splitting — accumulate the entire stream into a
616
620
  * single buffer and deliver it via `onComplete(buffer)`.
617
621
  *
package/dist/index.mjs CHANGED
@@ -1170,10 +1170,11 @@ function stdoutFileFor(stdio, parsed) {
1170
1170
  //#endregion
1171
1171
  //#region src/stream-parser.ts
1172
1172
  /**
1173
- * Creates a stdout stream parser. Three modes:
1173
+ * Creates a stdout stream parser.
1174
1174
  *
1175
1175
  * - "json" (default): newline-delimited JSON, JSON.parse per line.
1176
1176
  * - "lines": plaintext, raw trimmed line per `transform` call.
1177
+ * - "chunks": each decoded stdout chunk goes straight to the consumer.
1177
1178
  * - "raw": no per-line splitting — accumulate the entire stream into a
1178
1179
  * single buffer and deliver it via `onComplete(buffer)`.
1179
1180
  *
@@ -1182,6 +1183,14 @@ function stdoutFileFor(stdio, parsed) {
1182
1183
  function createStreamParser(config) {
1183
1184
  let buffer = "";
1184
1185
  const { parseAs = "json", transform, onEvent, onError, onComplete } = config;
1186
+ function emit(value) {
1187
+ const event = transform ? transform(value) : value;
1188
+ if (event !== null) onEvent(event);
1189
+ }
1190
+ if (parseAs === "chunks") return {
1191
+ push: emit,
1192
+ end: () => onComplete?.()
1193
+ };
1185
1194
  if (parseAs === "raw") return {
1186
1195
  push(chunk) {
1187
1196
  buffer += chunk;
@@ -1195,14 +1204,11 @@ function createStreamParser(config) {
1195
1204
  const trimmed = line.trim();
1196
1205
  if (!trimmed) return;
1197
1206
  if (parseAs === "lines") {
1198
- const event = transform ? transform(trimmed) : trimmed;
1199
- if (event !== null) onEvent(event);
1207
+ emit(trimmed);
1200
1208
  return;
1201
1209
  }
1202
1210
  try {
1203
- const parsed = JSON.parse(trimmed);
1204
- const event = transform ? transform(parsed) : parsed;
1205
- if (event !== null) onEvent(event);
1211
+ emit(JSON.parse(trimmed));
1206
1212
  } catch (error) {
1207
1213
  onError?.(error instanceof Error ? error : new Error(String(error)), trimmed);
1208
1214
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/sdk-cli-runner",
3
- "version": "0.3.13",
3
+ "version": "0.3.15",
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": "14e91b253ce23c02d58a4af90dcfd9395e7c5a54",
30
- "mergedAt": "2026-11-18T16:09:13-08:00"
29
+ "sourceSha": "51b269bed8de37eb53a80b87424adfd869bb1de9",
30
+ "mergedAt": "2026-11-19T20:08:54-08:00"
31
31
  },
32
32
  "scripts": {
33
33
  "build": "tsdown",