fascicle 0.10.1 → 0.10.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/stdio.js CHANGED
@@ -1,8 +1,26 @@
1
- import { T as run } from "./core-DNH8ddMT.js";
1
+ import { k as run, p as validate_schema } from "./core-DkuJqLwd.js";
2
2
  import { r as stderr_logger } from "./adapters-CJnu1687.js";
3
3
  import { text } from "node:stream/consumers";
4
4
  //#region src/stdio/execute_stdio.ts
5
5
  /**
6
+ * The stdio agent contract, minus the process.
7
+ *
8
+ * `execute_stdio` is everything `run_stdio` does (read, parse, validate, run,
9
+ * validate, serialize, dispose), expressed over an injected `StdioIo` and
10
+ * returning a `StdioOutcome` instead of touching `process.*` or exiting. The
11
+ * split keeps the contract's branching unit-testable; the thin glue in
12
+ * `run_stdio.ts` owns the real streams and the exit.
13
+ *
14
+ * The governing invariant: code 0 if and only if stdout carries an
15
+ * authoritative result. That is why the engine is disposed before the output
16
+ * is written (a teardown failure on the success path yields code 1 and no
17
+ * stdout) and why every failure class short-circuits before `write_output`.
18
+ * Code 1 means the flow did not produce a result (including a forwarded
19
+ * SIGINT/SIGTERM aborting the run, or a failed delivery); code 2 means the
20
+ * contract itself was violated (unparseable stdin, schema mismatch in either
21
+ * direction, unserializable result).
22
+ */
23
+ /**
6
24
  * Runs the stdio agent contract over injected `io`: read input, run the
7
25
  * flow, dispose the engine, write output, and return the outcome as a
8
26
  * value.
@@ -63,17 +81,17 @@ async function produce_output(flow, options, io) {
63
81
  }
64
82
  let input;
65
83
  if (options.input_schema !== void 0) {
66
- const checked = options.input_schema.safeParse(parsed);
67
- if (!checked.success) return {
84
+ const checked = await validate_schema(options.input_schema, parsed);
85
+ if (!checked.ok) return {
68
86
  kind: "failed",
69
87
  code: 2,
70
88
  failure: {
71
89
  error: "input failed schema validation",
72
90
  stage: "validate_input",
73
- cause: to_json_safe(checked.error.issues)
91
+ cause: to_json_safe(checked.issues)
74
92
  }
75
93
  };
76
- input = checked.data;
94
+ input = checked.value;
77
95
  } else input = parsed;
78
96
  const trajectory = options.trajectory ?? stderr_logger({ stream: io.error_stream });
79
97
  let result;
@@ -91,17 +109,17 @@ async function produce_output(flow, options, io) {
91
109
  }
92
110
  let output = result;
93
111
  if (options.output_schema !== void 0) {
94
- const checked = options.output_schema.safeParse(result);
95
- if (!checked.success) return {
112
+ const checked = await validate_schema(options.output_schema, result);
113
+ if (!checked.ok) return {
96
114
  kind: "failed",
97
115
  code: 2,
98
116
  failure: {
99
117
  error: "flow result failed schema validation",
100
118
  stage: "validate_output",
101
- cause: to_json_safe(checked.error.issues)
119
+ cause: to_json_safe(checked.issues)
102
120
  }
103
121
  };
104
- output = checked.data;
122
+ output = checked.value;
105
123
  }
106
124
  let json;
107
125
  try {
@@ -153,9 +171,9 @@ function make_failure(stage, err) {
153
171
  /**
154
172
  * Reduces a thrown value to a JSON-safe cause for `StdioFailure`.
155
173
  *
156
- * An `Error` is reduced to its `name`, `message`, and Zod's `path` property
157
- * when present (`safeParse` issues carry one); anything else is passed
158
- * through `to_json_safe`.
174
+ * An `Error` is reduced to its `name`, `message`, and the `path` property the
175
+ * runner stamps on it as it bubbles up through nested steps; anything else is
176
+ * passed through `to_json_safe`.
159
177
  */
160
178
  function safe_cause(err) {
161
179
  if (err instanceof Error) {
package/dist/stdio.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"stdio.js","names":[],"sources":["../src/stdio/execute_stdio.ts","../src/stdio/run_stdio.ts"],"sourcesContent":["/**\n * The stdio agent contract, minus the process.\n *\n * `execute_stdio` is everything `run_stdio` does (read, parse, validate, run,\n * validate, serialize, dispose), expressed over an injected `StdioIo` and\n * returning a `StdioOutcome` instead of touching `process.*` or exiting. The\n * split keeps the contract's branching unit-testable; the thin glue in\n * `run_stdio.ts` owns the real streams and the exit.\n *\n * The governing invariant: code 0 if and only if stdout carries an\n * authoritative result. That is why the engine is disposed before the output\n * is written (a teardown failure on the success path yields code 1 and no\n * stdout) and why every failure class short-circuits before `write_output`.\n * Code 1 means the flow did not produce a result (including a forwarded\n * SIGINT/SIGTERM aborting the run, or a failed delivery); code 2 means the\n * contract itself was violated (unparseable stdin, schema mismatch in either\n * direction, unserializable result).\n */\n\nimport type { z } from 'zod'\nimport { run } from '#core'\nimport type { Step, TrajectoryLogger } from '#core'\nimport { stderr_logger } from '#adapters'\n\nexport type RunStdioOptions<i, o> = {\n readonly input_schema?: z.ZodType<i>\n readonly output_schema?: z.ZodType<o>\n // Structural on purpose: anything with an async dispose qualifies, and the\n // stdio module never imports the engine layer.\n readonly engine?: { readonly dispose: () => Promise<void> }\n readonly trajectory?: TrajectoryLogger\n readonly abort?: AbortSignal\n}\n\nexport type StdioFailure = {\n readonly error: string\n readonly stage?:\n | 'read'\n | 'parse'\n | 'validate_input'\n | 'run'\n | 'validate_output'\n | 'serialize'\n | 'write'\n | 'dispose'\n readonly cause?: unknown\n}\n\nexport type StdioOutcome =\n | { readonly code: 0 }\n | { readonly code: 1 | 2; readonly failure: StdioFailure }\n\nexport type StdioIo = {\n readonly read_input: () => Promise<string>\n // Resolves once the bytes are flushed to the OS, so the caller may exit.\n readonly write_output: (text: string) => Promise<void>\n readonly error_stream: { write(chunk: string): unknown }\n}\n\n/**\n * Runs the stdio agent contract over injected `io`: read input, run the\n * flow, dispose the engine, write output, and return the outcome as a\n * value.\n *\n * Disposes the engine before writing output so a teardown failure on the\n * success path yields code 1 and no stdout, keeping \"code 0 means stdout\n * carries an authoritative result\" true even when disposal fails.\n */\nexport async function execute_stdio<i, o>(\n flow: Step<i, o>,\n options: RunStdioOptions<i, o>,\n io: StdioIo,\n): Promise<StdioOutcome> {\n const produced = await produce_output(flow, options, io)\n const dispose_failure = await dispose_engine(options.engine)\n if (produced.kind === 'failed') return { code: produced.code, failure: produced.failure }\n if (dispose_failure !== null) return { code: 1, failure: dispose_failure }\n try {\n await io.write_output(`${produced.json}\\n`)\n } catch (err) {\n return { code: 1, failure: make_failure('write', err) }\n }\n return { code: 0 }\n}\n\ntype ProduceResult =\n | { readonly kind: 'ok'; readonly json: string }\n | { readonly kind: 'failed'; readonly code: 1 | 2; readonly failure: StdioFailure }\n\n/**\n * Reads stdin, parses and validates it against the input schema, runs the\n * flow, then validates and serializes the result.\n *\n * Returns a tagged result instead of throwing so `execute_stdio` can dispose\n * the engine and choose the right exit code regardless of which stage\n * failed.\n */\nasync function produce_output<i, o>(\n flow: Step<i, o>,\n options: RunStdioOptions<i, o>,\n io: StdioIo,\n): Promise<ProduceResult> {\n let raw: string\n try {\n raw = await io.read_input()\n } catch (err) {\n return { kind: 'failed', code: 2, failure: make_failure('read', err) }\n }\n\n let parsed: unknown\n try {\n parsed = JSON.parse(raw)\n } catch (err) {\n return { kind: 'failed', code: 2, failure: make_failure('parse', err) }\n }\n\n let input: i\n if (options.input_schema !== undefined) {\n const checked = options.input_schema.safeParse(parsed)\n if (!checked.success) {\n return {\n kind: 'failed',\n code: 2,\n failure: {\n error: 'input failed schema validation',\n stage: 'validate_input',\n cause: to_json_safe(checked.error.issues),\n },\n }\n }\n input = checked.data\n } else {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n input = parsed as i\n }\n\n const trajectory = options.trajectory ?? stderr_logger({ stream: io.error_stream })\n\n let result: o\n try {\n result = await run(flow, input, {\n trajectory,\n ...(options.abort !== undefined ? { abort: options.abort } : {}),\n })\n } catch (err) {\n return { kind: 'failed', code: 1, failure: make_failure('run', err) }\n }\n\n let output: unknown = result\n if (options.output_schema !== undefined) {\n const checked = options.output_schema.safeParse(result)\n if (!checked.success) {\n return {\n kind: 'failed',\n code: 2,\n failure: {\n error: 'flow result failed schema validation',\n stage: 'validate_output',\n cause: to_json_safe(checked.error.issues),\n },\n }\n }\n output = checked.data\n }\n\n let json: string | undefined\n try {\n json = JSON.stringify(output)\n } catch (err) {\n return { kind: 'failed', code: 2, failure: make_failure('serialize', err) }\n }\n if (json === undefined) {\n return {\n kind: 'failed',\n code: 2,\n failure: { error: 'flow result is not JSON-serializable', stage: 'serialize' },\n }\n }\n return { kind: 'ok', json }\n}\n\n/**\n * Disposes the caller's engine when one was supplied, returning a\n * `StdioFailure` if disposal throws and `null` otherwise.\n */\nasync function dispose_engine(\n engine: RunStdioOptions<never, never>['engine'],\n): Promise<StdioFailure | null> {\n if (engine === undefined) return null\n try {\n await engine.dispose()\n return null\n } catch (err) {\n return make_failure('dispose', err)\n }\n}\n\n/**\n * Builds a `StdioFailure` for the given stage from a thrown value.\n */\nfunction make_failure(stage: NonNullable<StdioFailure['stage']>, err: unknown): StdioFailure {\n const cause = safe_cause(err)\n return {\n error: err instanceof Error ? err.message : String(err),\n stage,\n ...(cause !== undefined ? { cause } : {}),\n }\n}\n\n/**\n * Reduces a thrown value to a JSON-safe cause for `StdioFailure`.\n *\n * An `Error` is reduced to its `name`, `message`, and Zod's `path` property\n * when present (`safeParse` issues carry one); anything else is passed\n * through `to_json_safe`.\n */\nfunction safe_cause(err: unknown): unknown {\n if (err instanceof Error) {\n const path = Reflect.get(err, 'path')\n return {\n name: err.name,\n message: err.message,\n ...(Array.isArray(path) ? { path: to_json_safe(path) } : {}),\n }\n }\n return to_json_safe(err)\n}\n\n/**\n * Round-trips a value through `JSON.stringify`/`parse` so it is safe to\n * embed in a `StdioFailure` that the glue will serialize again.\n *\n * Never throws and never returns a value that would make that later\n * serialization throw or silently vanish: a circular reference or a BigInt\n * becomes `undefined` instead.\n */\nfunction to_json_safe(value: unknown): unknown {\n try {\n const json = JSON.stringify(value)\n if (json === undefined) return undefined\n return JSON.parse(json) as unknown\n } catch {\n return undefined\n }\n}\n","/**\n * Process glue for the stdio agent contract.\n *\n * Binds `execute_stdio` to the real process: stdin to EOF in, exactly one JSON\n * document on stdout out, trajectory on stderr, exit code as the verdict\n * (0 = result on stdout is authoritative, 1 = flow failure, 2 = contract\n * violation). On a non-zero exit the LAST stderr line is the `StdioFailure`\n * as a single JSON object, so parents that want machine-readable detail take\n * the tail line.\n *\n * Final writes await the write callback before `process.exit`: on pipes,\n * exiting with buffered data truncates it, and a large JSON result is exactly\n * the risk case. Signal handlers stay at the runner's default (installed): a\n * single-shot child must die when the parent forwards SIGINT.\n *\n * Excluded from mutation testing as process/IO glue (see stryker.config.mjs);\n * the spawn-based contract tests in `__tests__/e2e/` exercise it for real.\n */\n\nimport { text } from 'node:stream/consumers'\nimport type { Step } from '#core'\nimport { execute_stdio } from './execute_stdio.js'\nimport type { RunStdioOptions } from './execute_stdio.js'\n\n/**\n * Runs a flow as the stdio agent contract against the real process streams,\n * then exits with the outcome's code.\n *\n * On a non-zero outcome, writes the `StdioFailure` as the last line on\n * stderr so a parent process can take the tail line as machine-readable\n * detail.\n */\nexport async function run_stdio<i, o>(\n flow: Step<i, o>,\n options: RunStdioOptions<i, o> = {},\n): Promise<void> {\n const outcome = await execute_stdio(flow, options, {\n read_input: () => text(process.stdin),\n write_output: (chunk) => write_flushed(process.stdout, chunk),\n error_stream: process.stderr,\n })\n if (outcome.code !== 0) {\n try {\n await write_flushed(process.stderr, `${JSON.stringify(outcome.failure)}\\n`)\n } catch {\n // stderr is gone; the exit code still carries the verdict.\n }\n }\n process.exit(outcome.code)\n}\n\n/**\n * Writes a chunk to a stream and resolves only once it is flushed, so the\n * caller can safely exit the process afterward without truncating output.\n */\nfunction write_flushed(stream: NodeJS.WriteStream, chunk: string): Promise<void> {\n return new Promise((resolve, reject) => {\n stream.write(chunk, (err) => {\n if (err) reject(err)\n else resolve()\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;AAoEA,eAAsB,cACpB,MACA,SACA,IACuB;CACvB,MAAM,WAAW,MAAM,eAAe,MAAM,SAAS,EAAE;CACvD,MAAM,kBAAkB,MAAM,eAAe,QAAQ,MAAM;CAC3D,IAAI,SAAS,SAAS,UAAU,OAAO;EAAE,MAAM,SAAS;EAAM,SAAS,SAAS;CAAQ;CACxF,IAAI,oBAAoB,MAAM,OAAO;EAAE,MAAM;EAAG,SAAS;CAAgB;CACzE,IAAI;EACF,MAAM,GAAG,aA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACpNA,eAAsB,UACpB,MACA,UAAiC,CAAC,GACnB;CACf,MAAM,UAAU,MAAM,cAAc,MAAM,SAAS;EACjD,kBAAkB,KAAK,QAAQ,KAAK;EACpC,eAAe,UAAU,cAAc,QAAQ,QAAQ,KAAK;EAC5D,cAAc,QAAQ;CACxB,CAAC;CACD,IAAI,QAAQ,SAAS,GACnB,IAAI;EACF,MAAM,cAAc,QAAQ,QAAQ,GAAG,KAAK,UAAU,QAAQ,OAAO,EAAE,GAAG;CAC5E,QAAQ,CAER;CAEF,QAAQ,KAAK,QAAQ,IAAI;AAC3B;;;;;AAMA,SAAS,cAAc,QAA4B,OAA8B;CAC/E,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,OAAO,MAAM,QAAQ,QAAQ;GAC3B,IAAI,KAAK,OAAO,GAAG;QACd,QAAQ;EACf,CAAC;CACH,CAAC;AACH"}
1
+ {"version":3,"file":"stdio.js","names":[],"sources":["../src/stdio/execute_stdio.ts","../src/stdio/run_stdio.ts"],"sourcesContent":["/**\n * The stdio agent contract, minus the process.\n *\n * `execute_stdio` is everything `run_stdio` does (read, parse, validate, run,\n * validate, serialize, dispose), expressed over an injected `StdioIo` and\n * returning a `StdioOutcome` instead of touching `process.*` or exiting. The\n * split keeps the contract's branching unit-testable; the thin glue in\n * `run_stdio.ts` owns the real streams and the exit.\n *\n * The governing invariant: code 0 if and only if stdout carries an\n * authoritative result. That is why the engine is disposed before the output\n * is written (a teardown failure on the success path yields code 1 and no\n * stdout) and why every failure class short-circuits before `write_output`.\n * Code 1 means the flow did not produce a result (including a forwarded\n * SIGINT/SIGTERM aborting the run, or a failed delivery); code 2 means the\n * contract itself was violated (unparseable stdin, schema mismatch in either\n * direction, unserializable result).\n */\n\nimport { validate_schema, type AnySchema } from '#schema'\nimport { run } from '#core'\nimport type { Step, TrajectoryLogger } from '#core'\nimport { stderr_logger } from '#adapters'\n\nexport type RunStdioOptions<i, o> = {\n readonly input_schema?: AnySchema<i>\n readonly output_schema?: AnySchema<o>\n // Structural on purpose: anything with an async dispose qualifies, and the\n // stdio module never imports the engine layer.\n readonly engine?: { readonly dispose: () => Promise<void> }\n readonly trajectory?: TrajectoryLogger\n readonly abort?: AbortSignal\n}\n\nexport type StdioFailure = {\n readonly error: string\n readonly stage?:\n | 'read'\n | 'parse'\n | 'validate_input'\n | 'run'\n | 'validate_output'\n | 'serialize'\n | 'write'\n | 'dispose'\n readonly cause?: unknown\n}\n\nexport type StdioOutcome =\n | { readonly code: 0 }\n | { readonly code: 1 | 2; readonly failure: StdioFailure }\n\nexport type StdioIo = {\n readonly read_input: () => Promise<string>\n // Resolves once the bytes are flushed to the OS, so the caller may exit.\n readonly write_output: (text: string) => Promise<void>\n readonly error_stream: { write(chunk: string): unknown }\n}\n\n/**\n * Runs the stdio agent contract over injected `io`: read input, run the\n * flow, dispose the engine, write output, and return the outcome as a\n * value.\n *\n * Disposes the engine before writing output so a teardown failure on the\n * success path yields code 1 and no stdout, keeping \"code 0 means stdout\n * carries an authoritative result\" true even when disposal fails.\n */\nexport async function execute_stdio<i, o>(\n flow: Step<i, o>,\n options: RunStdioOptions<i, o>,\n io: StdioIo,\n): Promise<StdioOutcome> {\n const produced = await produce_output(flow, options, io)\n const dispose_failure = await dispose_engine(options.engine)\n if (produced.kind === 'failed') return { code: produced.code, failure: produced.failure }\n if (dispose_failure !== null) return { code: 1, failure: dispose_failure }\n try {\n await io.write_output(`${produced.json}\\n`)\n } catch (err) {\n return { code: 1, failure: make_failure('write', err) }\n }\n return { code: 0 }\n}\n\ntype ProduceResult =\n | { readonly kind: 'ok'; readonly json: string }\n | { readonly kind: 'failed'; readonly code: 1 | 2; readonly failure: StdioFailure }\n\n/**\n * Reads stdin, parses and validates it against the input schema, runs the\n * flow, then validates and serializes the result.\n *\n * Returns a tagged result instead of throwing so `execute_stdio` can dispose\n * the engine and choose the right exit code regardless of which stage\n * failed.\n */\nasync function produce_output<i, o>(\n flow: Step<i, o>,\n options: RunStdioOptions<i, o>,\n io: StdioIo,\n): Promise<ProduceResult> {\n let raw: string\n try {\n raw = await io.read_input()\n } catch (err) {\n return { kind: 'failed', code: 2, failure: make_failure('read', err) }\n }\n\n let parsed: unknown\n try {\n parsed = JSON.parse(raw)\n } catch (err) {\n return { kind: 'failed', code: 2, failure: make_failure('parse', err) }\n }\n\n let input: i\n if (options.input_schema !== undefined) {\n const checked = await validate_schema(options.input_schema, parsed)\n if (!checked.ok) {\n return {\n kind: 'failed',\n code: 2,\n failure: {\n error: 'input failed schema validation',\n stage: 'validate_input',\n cause: to_json_safe(checked.issues),\n },\n }\n }\n input = checked.value\n } else {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n input = parsed as i\n }\n\n const trajectory = options.trajectory ?? stderr_logger({ stream: io.error_stream })\n\n let result: o\n try {\n result = await run(flow, input, {\n trajectory,\n ...(options.abort !== undefined ? { abort: options.abort } : {}),\n })\n } catch (err) {\n return { kind: 'failed', code: 1, failure: make_failure('run', err) }\n }\n\n let output: unknown = result\n if (options.output_schema !== undefined) {\n const checked = await validate_schema(options.output_schema, result)\n if (!checked.ok) {\n return {\n kind: 'failed',\n code: 2,\n failure: {\n error: 'flow result failed schema validation',\n stage: 'validate_output',\n cause: to_json_safe(checked.issues),\n },\n }\n }\n output = checked.value\n }\n\n let json: string | undefined\n try {\n json = JSON.stringify(output)\n } catch (err) {\n return { kind: 'failed', code: 2, failure: make_failure('serialize', err) }\n }\n if (json === undefined) {\n return {\n kind: 'failed',\n code: 2,\n failure: { error: 'flow result is not JSON-serializable', stage: 'serialize' },\n }\n }\n return { kind: 'ok', json }\n}\n\n/**\n * Disposes the caller's engine when one was supplied, returning a\n * `StdioFailure` if disposal throws and `null` otherwise.\n */\nasync function dispose_engine(\n engine: RunStdioOptions<never, never>['engine'],\n): Promise<StdioFailure | null> {\n if (engine === undefined) return null\n try {\n await engine.dispose()\n return null\n } catch (err) {\n return make_failure('dispose', err)\n }\n}\n\n/**\n * Builds a `StdioFailure` for the given stage from a thrown value.\n */\nfunction make_failure(stage: NonNullable<StdioFailure['stage']>, err: unknown): StdioFailure {\n const cause = safe_cause(err)\n return {\n error: err instanceof Error ? err.message : String(err),\n stage,\n ...(cause !== undefined ? { cause } : {}),\n }\n}\n\n/**\n * Reduces a thrown value to a JSON-safe cause for `StdioFailure`.\n *\n * An `Error` is reduced to its `name`, `message`, and the `path` property the\n * runner stamps on it as it bubbles up through nested steps; anything else is\n * passed through `to_json_safe`.\n */\nfunction safe_cause(err: unknown): unknown {\n if (err instanceof Error) {\n const path = Reflect.get(err, 'path')\n return {\n name: err.name,\n message: err.message,\n ...(Array.isArray(path) ? { path: to_json_safe(path) } : {}),\n }\n }\n return to_json_safe(err)\n}\n\n/**\n * Round-trips a value through `JSON.stringify`/`parse` so it is safe to\n * embed in a `StdioFailure` that the glue will serialize again.\n *\n * Never throws and never returns a value that would make that later\n * serialization throw or silently vanish: a circular reference or a BigInt\n * becomes `undefined` instead.\n */\nfunction to_json_safe(value: unknown): unknown {\n try {\n const json = JSON.stringify(value)\n if (json === undefined) return undefined\n return JSON.parse(json) as unknown\n } catch {\n return undefined\n }\n}\n","/**\n * Process glue for the stdio agent contract.\n *\n * Binds `execute_stdio` to the real process: stdin to EOF in, exactly one JSON\n * document on stdout out, trajectory on stderr, exit code as the verdict\n * (0 = result on stdout is authoritative, 1 = flow failure, 2 = contract\n * violation). On a non-zero exit the LAST stderr line is the `StdioFailure`\n * as a single JSON object, so parents that want machine-readable detail take\n * the tail line.\n *\n * Final writes await the write callback before `process.exit`: on pipes,\n * exiting with buffered data truncates it, and a large JSON result is exactly\n * the risk case. Signal handlers stay at the runner's default (installed): a\n * single-shot child must die when the parent forwards SIGINT.\n *\n * Excluded from mutation testing as process/IO glue (see stryker.config.mjs);\n * the spawn-based contract tests in `__tests__/e2e/` exercise it for real.\n */\n\nimport { text } from 'node:stream/consumers'\nimport type { Step } from '#core'\nimport { execute_stdio } from './execute_stdio.js'\nimport type { RunStdioOptions } from './execute_stdio.js'\n\n/**\n * Runs a flow as the stdio agent contract against the real process streams,\n * then exits with the outcome's code.\n *\n * On a non-zero outcome, writes the `StdioFailure` as the last line on\n * stderr so a parent process can take the tail line as machine-readable\n * detail.\n */\nexport async function run_stdio<i, o>(\n flow: Step<i, o>,\n options: RunStdioOptions<i, o> = {},\n): Promise<void> {\n const outcome = await execute_stdio(flow, options, {\n read_input: () => text(process.stdin),\n write_output: (chunk) => write_flushed(process.stdout, chunk),\n error_stream: process.stderr,\n })\n if (outcome.code !== 0) {\n try {\n await write_flushed(process.stderr, `${JSON.stringify(outcome.failure)}\\n`)\n } catch {\n // stderr is gone; the exit code still carries the verdict.\n }\n }\n process.exit(outcome.code)\n}\n\n/**\n * Writes a chunk to a stream and resolves only once it is flushed, so the\n * caller can safely exit the process afterward without truncating output.\n */\nfunction write_flushed(stream: NodeJS.WriteStream, chunk: string): Promise<void> {\n return new Promise((resolve, reject) => {\n stream.write(chunk, (err) => {\n if (err) reject(err)\n else resolve()\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,eAAsB,cACpB,MACA,SACA,IACuB;CACvB,MAAM,WAAW,MAAM,eAAe,MAAM,SAAS,EAAE;CACvD,MAAM,kBAAkB,MAAM,eAAe,QAAQ,MAAM;CAC3D,IAAI,SAAS,SAAS,UAAU,OAAO;EAAE,MAAM,SAAS;EAAM,SAAS,SAAS;CAAQ;CACxF,IAAI,oBAAoB,MAAM,OAAO;EAAE,MAAM;EAAG,SAAS;CAAgB;CACzE,IAAI;EACF,MAAM,GAAG,aAAa,GAAG,SAAS,KAAK,GAAG;CAC5C,SAAS,KAAK;EACZ,OAAO;GAAE,MAAM;GAAG,SAAS,aAAa,SAAS,GAAG;EAAE;CACxD;CACA,OAAO,EAAE,MAAM,EAAE;AACnB;;;;;;;;;AAcA,eAAe,eACb,MACA,SACA,IACwB;CACxB,IAAI;CACJ,IAAI;EACF,MAAM,MAAM,GAAG,W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IAAI,QAAQ,SAAS,GACnB,IAAI;EACF,MAAM,cAAc,QAAQ,QAAQ,GAAG,KAAK,UAAU,QAAQ,OAAO,EAAE,GAAG;CAC5E,QAAQ,CAER;CAEF,QAAQ,KAAK,QAAQ,IAAI;AAC3B;;;;;AAMA,SAAS,cAAc,QAA4B,OAA8B;CAC/E,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,OAAO,MAAM,QAAQ,QAAQ;GAC3B,IAAI,KAAK,OAAO,GAAG;QACd,QAAQ;EACf,CAAC;CACH,CAAC;AACH"}
@@ -1,5 +1,5 @@
1
- import { J as TrajectoryLogger } from "./index-SkPG_Rew.js";
2
- import { z } from "zod";
1
+ import { s as TrajectoryLogger } from "./types-BDSbSUAO.js";
2
+ import { r as ToolSchema } from "./types-BCtKsxrX.js";
3
3
 
4
4
  //#region src/engine/providers/claude_cli/types.d.ts
5
5
  /**
@@ -237,7 +237,7 @@ type ToolExecContext = {
237
237
  type Tool<i = unknown, o = unknown> = {
238
238
  name: string;
239
239
  description: string;
240
- input_schema: z.ZodType<i>;
240
+ input_schema: ToolSchema<i>;
241
241
  execute: (input: i, ctx: ToolExecContext) => Promise<o> | o;
242
242
  needs_approval?: boolean | ((input: i) => boolean | Promise<boolean>);
243
243
  /**
@@ -341,7 +341,7 @@ type TurnRequest = {
341
341
  readonly stream: boolean;
342
342
  readonly model_id: string;
343
343
  readonly system?: string;
344
- readonly schema?: z.ZodType;
344
+ readonly schema?: ToolSchema;
345
345
  readonly effort: EffortLevel;
346
346
  readonly provider_options?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
347
347
  readonly temperature?: number;
@@ -380,7 +380,7 @@ type GenerateOptions<t = string> = {
380
380
  provider?: string;
381
381
  prompt: string | Message[];
382
382
  system?: string;
383
- schema?: z.ZodType<t>;
383
+ schema?: ToolSchema<t>;
384
384
  tools?: Tool[];
385
385
  effort?: EffortLevel;
386
386
  temperature?: number;
@@ -597,131 +597,5 @@ type Engine = {
597
597
  dispose: () => Promise<void>;
598
598
  };
599
599
  //#endregion
600
- //#region src/engine/create_engine.d.ts
601
- /**
602
- * Validate `config` and construct an `Engine`.
603
- *
604
- * Provider entries are validated synchronously via `build_provider_adapters`.
605
- * A `generate` call that names a provider absent from `config.providers`
606
- * still throws `provider_not_configured_error`, but only at call time.
607
- */
608
- declare function create_engine(config: EngineConfig): Engine;
609
- //#endregion
610
- //#region src/engine/errors.d.ts
611
- declare class rate_limit_error extends Error {
612
- readonly kind: "rate_limit_error";
613
- readonly retry_after_ms: number | undefined;
614
- readonly attempts: number;
615
- readonly status: number | undefined;
616
- constructor(message: string, metadata?: {
617
- retry_after_ms?: number;
618
- attempts?: number;
619
- status?: number;
620
- });
621
- }
622
- declare class provider_error extends Error {
623
- readonly kind: "provider_error";
624
- readonly status: number | undefined;
625
- readonly body: string | undefined;
626
- readonly cause_kind: 'provider_5xx' | 'network' | 'unknown' | undefined;
627
- constructor(message: string, metadata?: {
628
- status?: number;
629
- body?: string;
630
- cause_kind?: 'provider_5xx' | 'network' | 'unknown';
631
- });
632
- }
633
- declare class schema_validation_error extends Error {
634
- readonly kind: "schema_validation_error";
635
- readonly zod_error: unknown;
636
- readonly raw_text: string;
637
- constructor(message: string, zod_error: unknown, raw_text: string);
638
- }
639
- declare class tool_error extends Error {
640
- readonly kind: "tool_error";
641
- readonly tool_name: string;
642
- readonly tool_call_id: string;
643
- readonly cause: unknown;
644
- constructor(message: string, metadata: {
645
- tool_name: string;
646
- tool_call_id: string;
647
- cause: unknown;
648
- });
649
- }
650
- declare class tool_approval_denied_error extends Error {
651
- readonly kind: "tool_approval_denied_error";
652
- readonly tool_name: string;
653
- readonly step_index: number;
654
- readonly tool_call_id: string;
655
- constructor(message: string, metadata: {
656
- tool_name: string;
657
- step_index: number;
658
- tool_call_id: string;
659
- });
660
- }
661
- declare class model_required_error extends Error {
662
- readonly kind: "model_required_error";
663
- constructor(message?: string);
664
- }
665
- declare class provider_not_configured_error extends Error {
666
- readonly kind: "provider_not_configured_error";
667
- readonly provider: string;
668
- constructor(provider: string);
669
- }
670
- declare class engine_config_error extends Error {
671
- readonly kind: "engine_config_error";
672
- readonly provider: string | undefined;
673
- constructor(message: string, provider?: string);
674
- }
675
- declare class on_chunk_error extends Error {
676
- readonly kind: "on_chunk_error";
677
- readonly cause: unknown;
678
- constructor(message: string, cause: unknown);
679
- }
680
- declare class provider_capability_error extends Error {
681
- readonly kind: "provider_capability_error";
682
- readonly provider: string;
683
- readonly capability: string;
684
- constructor(provider: string, capability: string, detail?: string);
685
- }
686
- declare class engine_disposed_error extends Error {
687
- readonly kind: "engine_disposed_error";
688
- constructor(message?: string);
689
- }
690
- type ClaudeCliErrorReason = 'binary_not_found' | 'auth_missing' | 'auth_expired' | 'api_key_missing' | 'startup_timeout' | 'stall_timeout' | 'no_result_event' | 'result_error' | 'subprocess_exit' | 'sandbox_unavailable' | 'engine_disposed' | 'parse_error';
691
- declare class claude_cli_error extends Error {
692
- readonly kind: "claude_cli_error";
693
- readonly reason: ClaudeCliErrorReason;
694
- readonly status: number | undefined;
695
- readonly stderr_snippet: string | undefined;
696
- constructor(reason: ClaudeCliErrorReason, message: string, metadata?: {
697
- status?: number;
698
- stderr_snippet?: string;
699
- });
700
- }
701
- declare class provider_auth_error extends Error {
702
- readonly kind: "provider_auth_error";
703
- readonly provider: string;
704
- readonly refresh_command: string | undefined;
705
- constructor(provider: string, message: string, metadata?: {
706
- refresh_command?: string;
707
- });
708
- }
709
- /**
710
- * A generate call that set a schema finished for a reason other than 'stop'
711
- * (content_filter, length, max_steps, tool_calls), so no schema-validated
712
- * value exists and validation was never attempted. Carries the raw model text
713
- * and the last provider-reported payload, so a guardrail trace or other
714
- * block detail stays reachable from the catch. Distinct from
715
- * schema_validation_error, which covers a response that completed normally
716
- * and then failed validation after its repair attempts ran out.
717
- */
718
- declare class incomplete_generation_error extends Error {
719
- readonly kind: "incomplete_generation_error";
720
- readonly finish_reason: FinishReason;
721
- readonly raw_text: string;
722
- readonly provider_reported: Record<string, unknown> | undefined;
723
- constructor(finish_reason: FinishReason, raw_text: string, provider_reported?: Record<string, unknown>);
724
- }
725
- //#endregion
726
- export { ProviderCapability as $, Pricing as A, ToolApprovalHandler as B, FinishReason as C, PrepareStepContext as D, Message as E, RetryFailureKind as F, TurnResult as G, ToolCallRecord as H, RetryPolicy as I, AiSdkProviderAdapter as J, UsageTotals as K, StepRecord as L, ProviderConfigMap as M, ProviderInit as N, PrepareStepHook as O, ResolvedModel as P, ProviderAdapter as Q, StreamChunk as R, EngineDefaults as S, GenerateResult as T, ToolExecContext as U, ToolApprovalRequest as V, TurnRequest as W, ExternalAgentAdapter as X, EffortTranslation as Y, NativeProviderAdapter as Z, AssistantContentPart as _, model_required_error as a, Engine as b, provider_capability_error as c, rate_limit_error as d, ProviderFactory as et, schema_validation_error as f, AiSdkTelemetrySettings as g, create_engine as h, incomplete_generation_error as i, PricingTable as j, PrepareStepResult as k, provider_error as l, tool_error as m, engine_config_error as n, RawProviderUsage as nt, on_chunk_error as o, tool_approval_denied_error as p, UserContentPart as q, engine_disposed_error as r, default_normalize_usage as rt, provider_auth_error as s, claude_cli_error as t, ProviderTransport as tt, provider_not_configured_error as u, CostBreakdown as v, GenerateOptions as w, EngineConfig as x, EffortLevel as y, Tool as z };
727
- //# sourceMappingURL=index-BNgtkeUf.d.ts.map
600
+ export { TurnResult as A, ProviderTransport as B, StreamChunk as C, ToolCallRecord as D, ToolApprovalRequest as E, ExternalAgentAdapter as F, default_normalize_usage as H, NativeProviderAdapter as I, ProviderAdapter as L, UserContentPart as M, AiSdkProviderAdapter as N, ToolExecContext as O, EffortTranslation as P, ProviderCapability as R, StepRecord as S, ToolApprovalHandler as T, RawProviderUsage as V, ProviderConfigMap as _, Engine as a, RetryFailureKind as b, FinishReason as c, Message as d, PrepareStepContext as f, PricingTable as g, Pricing as h, EffortLevel as i, UsageTotals as j, TurnRequest as k, GenerateOptions as l, PrepareStepResult as m, AssistantContentPart as n, EngineConfig as o, PrepareStepHook as p, CostBreakdown as r, EngineDefaults as s, AiSdkTelemetrySettings as t, GenerateResult as u, ProviderInit as v, Tool as w, RetryPolicy as x, ResolvedModel as y, ProviderFactory as z };
601
+ //# sourceMappingURL=types-B3HIsBBD.d.ts.map
@@ -0,0 +1,149 @@
1
+ //#region node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts
2
+ /** The Standard Typed interface. This is a base type extended by other specs. */
3
+ interface StandardTypedV1<Input = unknown, Output = Input> {
4
+ /** The Standard properties. */
5
+ readonly "~standard": StandardTypedV1.Props<Input, Output>;
6
+ }
7
+ declare namespace StandardTypedV1 {
8
+ /** The Standard Typed properties interface. */
9
+ interface Props<Input = unknown, Output = Input> {
10
+ /** The version number of the standard. */
11
+ readonly version: 1;
12
+ /** The vendor name of the schema library. */
13
+ readonly vendor: string;
14
+ /** Inferred types associated with the schema. */
15
+ readonly types?: Types<Input, Output> | undefined;
16
+ }
17
+ /** The Standard Typed types interface. */
18
+ interface Types<Input = unknown, Output = Input> {
19
+ /** The input type of the schema. */
20
+ readonly input: Input;
21
+ /** The output type of the schema. */
22
+ readonly output: Output;
23
+ }
24
+ /** Infers the input type of a Standard Typed. */
25
+ type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
26
+ /** Infers the output type of a Standard Typed. */
27
+ type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
28
+ }
29
+ /** The Standard Schema interface. */
30
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
31
+ /** The Standard Schema properties. */
32
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
33
+ }
34
+ declare namespace StandardSchemaV1 {
35
+ /** The Standard Schema properties interface. */
36
+ interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
37
+ /** Validates unknown input values. */
38
+ readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
39
+ }
40
+ /** The result interface of the validate function. */
41
+ type Result<Output> = SuccessResult<Output> | FailureResult;
42
+ /** The result interface if validation succeeds. */
43
+ interface SuccessResult<Output> {
44
+ /** The typed output value. */
45
+ readonly value: Output;
46
+ /** A falsy value for `issues` indicates success. */
47
+ readonly issues?: undefined;
48
+ }
49
+ interface Options {
50
+ /** Explicit support for additional vendor-specific parameters, if needed. */
51
+ readonly libraryOptions?: Record<string, unknown> | undefined;
52
+ }
53
+ /** The result interface if validation fails. */
54
+ interface FailureResult {
55
+ /** The issues of failed validation. */
56
+ readonly issues: ReadonlyArray<Issue>;
57
+ }
58
+ /** The issue interface of the failure output. */
59
+ interface Issue {
60
+ /** The error message of the issue. */
61
+ readonly message: string;
62
+ /** The path of the issue, if any. */
63
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
64
+ }
65
+ /** The path segment interface of the issue. */
66
+ interface PathSegment {
67
+ /** The key representing a path segment. */
68
+ readonly key: PropertyKey;
69
+ }
70
+ /** The Standard types interface. */
71
+ interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
72
+ /** Infers the input type of a Standard. */
73
+ type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
74
+ /** Infers the output type of a Standard. */
75
+ type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
76
+ }
77
+ /** The Standard JSON Schema interface. */
78
+ interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
79
+ /** The Standard JSON Schema properties. */
80
+ readonly "~standard": StandardJSONSchemaV1.Props<Input, Output>;
81
+ }
82
+ declare namespace StandardJSONSchemaV1 {
83
+ /** The Standard JSON Schema properties interface. */
84
+ interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
85
+ /** Methods for generating the input/output JSON Schema. */
86
+ readonly jsonSchema: StandardJSONSchemaV1.Converter;
87
+ }
88
+ /** The Standard JSON Schema converter interface. */
89
+ interface Converter {
90
+ /** Converts the input type to JSON Schema. May throw if conversion is not supported. */
91
+ readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
92
+ /** Converts the output type to JSON Schema. May throw if conversion is not supported. */
93
+ readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
94
+ }
95
+ /**
96
+ * The target version of the generated JSON Schema.
97
+ *
98
+ * It is *strongly recommended* that implementers support `"draft-2020-12"` and `"draft-07"`, as they are both in wide use. All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.
99
+ *
100
+ * The `"openapi-3.0"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `"draft-04"`.
101
+ */
102
+ type Target = "draft-2020-12" | "draft-07" | "openapi-3.0" | ({} & string);
103
+ /** The options for the input/output methods. */
104
+ interface Options {
105
+ /** Specifies the target version of the generated JSON Schema. Support for all versions is on a best-effort basis. If a given version is not supported, the library should throw. */
106
+ readonly target: Target;
107
+ /** Explicit support for additional vendor-specific parameters, if needed. */
108
+ readonly libraryOptions?: Record<string, unknown> | undefined;
109
+ }
110
+ /** The Standard types interface. */
111
+ interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
112
+ /** Infers the input type of a Standard. */
113
+ type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
114
+ /** Infers the output type of a Standard. */
115
+ type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
116
+ }
117
+ //#endregion
118
+ //#region src/schema/types.d.ts
119
+ /**
120
+ * Any Standard Schema implementation, used where fascicle only ever validates.
121
+ *
122
+ * `t` is the validated output type, which is what callers care about; the input
123
+ * side stays `unknown` because fascicle validates values arriving from a model,
124
+ * a resume payload, or stdin, none of which are typed at the boundary.
125
+ */
126
+ type AnySchema<t = unknown> = StandardSchemaV1<unknown, t>;
127
+ /**
128
+ * A Standard Schema that can also emit JSON Schema.
129
+ *
130
+ * Required wherever a schema must reach a model as JSON Schema: tool
131
+ * definitions and structured output. This is a deliberate narrowing of
132
+ * `AnySchema` rather than an oversight, because a schema that cannot be
133
+ * expressed as JSON Schema cannot be sent to a provider at all.
134
+ */
135
+ type ToolSchema<t = unknown> = StandardSchemaV1<unknown, t> & StandardJSONSchemaV1;
136
+ /**
137
+ * One validation failure, flattened out of whichever shape the vendor used.
138
+ *
139
+ * The spec permits a path segment to be either a bare key or an object
140
+ * wrapping one; `validate_schema` normalizes both to the bare key so every
141
+ * consumer downstream reads one shape.
142
+ */
143
+ type SchemaIssue = {
144
+ readonly message: string;
145
+ readonly path?: ReadonlyArray<PropertyKey>;
146
+ };
147
+ //#endregion
148
+ export { SchemaIssue as n, ToolSchema as r, AnySchema as t };
149
+ //# sourceMappingURL=types-BCtKsxrX.d.ts.map
@@ -0,0 +1,63 @@
1
+ //#region src/core/types.d.ts
2
+ /**
3
+ * Shared type surface for the composition layer.
4
+ *
5
+ * These types are the public value contract between composers, the runner,
6
+ * and adapter packages (observability, stores,
7
+ * engine). Adapter packages import types from here; nothing in
8
+ * this file imports from any adapter.
9
+ *
10
+ * Type aliases and interfaces use PascalCase, per the naming convention.
11
+ * Value-level identifiers (field names, function parameter names) remain
12
+ * snake_case; those are the value contract, not the type contract.
13
+ */
14
+ type TrajectoryEvent = {
15
+ readonly kind: string;
16
+ readonly span_id?: string | undefined;
17
+ readonly ts?: number | undefined;
18
+ readonly [key: string]: unknown;
19
+ };
20
+ type TrajectoryLogger = {
21
+ readonly record: (event: TrajectoryEvent) => void;
22
+ readonly start_span: (name: string, meta?: Record<string, unknown>) => string;
23
+ readonly end_span: (id: string, meta?: Record<string, unknown>) => void;
24
+ };
25
+ type CheckpointStore = {
26
+ readonly get: (key: string) => Promise<unknown>;
27
+ readonly set: (key: string, value: unknown) => Promise<void>;
28
+ readonly delete: (key: string) => Promise<void>;
29
+ };
30
+ type CleanupFn = () => Promise<void> | void;
31
+ type RunContext = {
32
+ readonly run_id: string;
33
+ readonly trajectory: TrajectoryLogger;
34
+ readonly state: ReadonlyMap<string, unknown>;
35
+ readonly parent_span_id?: string | undefined;
36
+ readonly abort: AbortSignal;
37
+ readonly emit: (event: Record<string, unknown>) => void;
38
+ readonly on_cleanup: (fn: CleanupFn) => void;
39
+ readonly checkpoint_store?: CheckpointStore | undefined;
40
+ readonly resume_data?: Readonly<Record<string, unknown>> | undefined;
41
+ readonly streaming: boolean;
42
+ };
43
+ type StepFn<i, o> = (input: i, ctx: RunContext) => Promise<o> | o;
44
+ type StepMetadata = {
45
+ readonly display_name?: string;
46
+ readonly description?: string;
47
+ readonly port_labels?: Readonly<{
48
+ readonly in?: string;
49
+ readonly out?: string;
50
+ }>;
51
+ };
52
+ type Step<i, o> = {
53
+ readonly id: string;
54
+ readonly kind: string;
55
+ run(input: i, ctx: RunContext): Promise<o> | o;
56
+ readonly config?: Readonly<Record<string, unknown>>;
57
+ readonly children?: ReadonlyArray<Step<unknown, unknown>>;
58
+ readonly anonymous?: boolean;
59
+ readonly meta?: StepMetadata;
60
+ };
61
+ //#endregion
62
+ export { StepMetadata as a, StepFn as i, RunContext as n, TrajectoryEvent as o, Step as r, TrajectoryLogger as s, CheckpointStore as t };
63
+ //# sourceMappingURL=types-BDSbSUAO.d.ts.map