fascicle 0.17.1 → 0.17.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.
@@ -1,4 +1,4 @@
1
- import { D as describe, O as is_step } from "./core-BOFcG3tp.js";
1
+ import { O as describe, k as is_step } from "./core-Dwir3pkb.js";
2
2
  import { createRequire } from "node:module";
3
3
  import { resolve } from "node:path";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -10,13 +10,15 @@ import { parseArgs } from "node:util";
10
10
  * fascicle-diagram <module> print the diagram of the module's `flow`
11
11
  * fascicle-diagram <module> --export <name> read another export instead
12
12
  *
13
- * Flags: --export <name> --width <n> --prefix <text> --replays --internals --help
13
+ * Flags: --export <name> --width <n> --prefix <text> --replays --internals --outline --help
14
14
  *
15
15
  * The export is a Step, or a function that builds one with no arguments,
16
16
  * which is where an app wires its flow to stub dependencies so that drawing
17
17
  * it needs no credentials. The diagram is `describe.diagram` of that Step, so
18
18
  * it is what the code builds today and can be compared with the header in
19
- * `flow.ts` at a glance.
19
+ * `flow.ts` at a glance. `--outline` prints the plain `describe` outline
20
+ * instead, with each node's kind, id, and config, which is the view to read
21
+ * when the diagram hides something.
20
22
  *
21
23
  * This file holds every decision the command makes and touches nothing of
22
24
  * the process: output and module loading arrive through `DiagramCliIo`.
@@ -38,8 +40,15 @@ Options:
38
40
  --prefix <text> start every line with text, for example ' * '
39
41
  --replays mark the steps a resumed run would pay for again
40
42
  --internals draw a named composite's internal steps, not only its parts
43
+ --outline print describe()'s plain outline, with ids and config,
44
+ instead of the diagram (no --width, --replays, or --internals)
41
45
  --help show this message
42
46
  `;
47
+ const DIAGRAM_ONLY = [
48
+ "width",
49
+ "replays",
50
+ "internals"
51
+ ];
43
52
  /**
44
53
  * Run the CLI over `argv` and resolve to its exit code: 0 once the diagram is
45
54
  * printed, 1 when the module cannot be loaded or holds no Step, and 2 for a
@@ -56,7 +65,7 @@ async function run_diagram_cli(argv, io) {
56
65
  io.err(`fascicle-diagram: ${parsed.message}\n\n${HELP}`);
57
66
  return 2;
58
67
  }
59
- const { module, export_name, options } = parsed.args;
68
+ const { module, export_name, outline, options } = parsed.args;
60
69
  const path = resolve(module);
61
70
  let exports;
62
71
  try {
@@ -82,13 +91,22 @@ async function run_diagram_cli(argv, io) {
82
91
  io.err(`fascicle-diagram: ${export_name} in ${module} is not a Step: export the flow itself, or a function that builds it with no arguments\n`);
83
92
  return 1;
84
93
  }
85
- io.out(`${describe.diagram(flow, options)}\n`);
94
+ const text = outline ? outline_of(flow, options.prefix) : describe.diagram(flow, options);
95
+ io.out(`${text}\n`);
86
96
  return 0;
87
97
  }
88
98
  /**
99
+ * Render `describe`'s plain outline of `flow`, starting every line with
100
+ * `prefix` the way the diagram does.
101
+ */
102
+ function outline_of(flow, prefix = "") {
103
+ return describe(flow).split("\n").map((line) => `${prefix}${line}`).join("\n");
104
+ }
105
+ /**
89
106
  * Parse argv into a run request, a help request, or a usage error. Unknown
90
107
  * flags and a missing module are usage errors, and so is a width that is not
91
- * a positive integer.
108
+ * a positive integer. `--outline` with an option that only the diagram reads
109
+ * is one too, since the outline would drop it without a word.
92
110
  */
93
111
  function parse(argv) {
94
112
  let parsed;
@@ -111,6 +129,14 @@ function parse(argv) {
111
129
  kind: "usage",
112
130
  message: `expected one <module>, got ${positionals.join(" ")}`
113
131
  };
132
+ const outline = values.outline === true;
133
+ if (outline) {
134
+ const dropped = DIAGRAM_ONLY.filter((flag) => values[flag] !== void 0);
135
+ if (dropped.length > 0) return {
136
+ kind: "usage",
137
+ message: `--outline can't take ${dropped.map((flag) => `--${flag}`).join(", ")}, which only the diagram reads`
138
+ };
139
+ }
114
140
  const options = {};
115
141
  if (values.width !== void 0) {
116
142
  const width = Number(values.width);
@@ -128,6 +154,7 @@ function parse(argv) {
128
154
  args: {
129
155
  module,
130
156
  export_name: values.export ?? "flow",
157
+ outline,
131
158
  options
132
159
  }
133
160
  };
@@ -146,6 +173,7 @@ function parse_flags(argv) {
146
173
  prefix: { type: "string" },
147
174
  replays: { type: "boolean" },
148
175
  internals: { type: "boolean" },
176
+ outline: { type: "boolean" },
149
177
  help: { type: "boolean" }
150
178
  }
151
179
  });
@@ -1 +1 @@
1
- {"version":3,"file":"diagram_bin.js","names":[],"sources":["../src/diagram_cli.ts","../src/diagram_bin.ts"],"sourcesContent":["/**\n * fascicle-diagram CLI.\n *\n * fascicle-diagram <module> print the diagram of the module's `flow`\n * fascicle-diagram <module> --export <name> read another export instead\n *\n * Flags: --export <name> --width <n> --prefix <text> --replays --internals --help\n *\n * The export is a Step, or a function that builds one with no arguments,\n * which is where an app wires its flow to stub dependencies so that drawing\n * it needs no credentials. The diagram is `describe.diagram` of that Step, so\n * it is what the code builds today and can be compared with the header in\n * `flow.ts` at a glance.\n *\n * This file holds every decision the command makes and touches nothing of\n * the process: output and module loading arrive through `DiagramCliIo`.\n * diagram_bin.ts binds that io to the real streams and to the project's\n * `tsx`, and is the entry that the package's bin shim runs.\n */\n\nimport { resolve } from 'node:path'\nimport { parseArgs } from 'node:util'\nimport { describe, is_step } from '#core'\nimport type { DiagramOptions } from '#core'\n\nexport type DiagramCliIo = {\n readonly out: (text: string) => void\n readonly err: (text: string) => void\n /** Import the module at an absolute path and return its exports. */\n readonly load: (path: string) => Promise<Readonly<Record<string, unknown>>>\n}\n\ntype CliArgs = {\n readonly module: string\n readonly export_name: string\n readonly options: DiagramOptions\n}\n\ntype Parsed =\n | { readonly kind: 'help' }\n | { readonly kind: 'usage'; readonly message: string }\n | { readonly kind: 'run'; readonly args: CliArgs }\n\nconst HELP = `\\\nfascicle-diagram prints a flow as an annotated box-drawing tree.\n\nUsage:\n fascicle-diagram <module> draw the module's \\`flow\\` export\n fascicle-diagram <module> --export <name> draw another export instead\n\nThe export is a Step, or a function that builds one with no arguments.\n\nOptions:\n --export <name> the export to draw (default flow)\n --width <n> wrap descriptions so no line runs wider than n\n --prefix <text> start every line with text, for example ' * '\n --replays mark the steps a resumed run would pay for again\n --internals draw a named composite's internal steps, not only its parts\n --help show this message\n`\n\n\n/**\n * Run the CLI over `argv` and resolve to its exit code: 0 once the diagram is\n * printed, 1 when the module cannot be loaded or holds no Step, and 2 for a\n * usage error. Output and loading go through `io`, so the caller owns the\n * process.\n */\nexport async function run_diagram_cli(argv: readonly string[], io: DiagramCliIo): Promise<number> {\n const parsed = parse(argv)\n if (parsed.kind === 'help') {\n io.out(HELP)\n return 0\n }\n if (parsed.kind === 'usage') {\n io.err(`fascicle-diagram: ${parsed.message}\\n\\n${HELP}`)\n return 2\n }\n const { module, export_name, options } = parsed.args\n const path = resolve(module)\n let exports: Readonly<Record<string, unknown>>\n try {\n exports = await io.load(path)\n } catch (err) {\n io.err(`fascicle-diagram: could not load ${module}: ${message_of(err)}\\n`)\n return 1\n }\n if (!Object.hasOwn(exports, export_name)) {\n const names = Object.keys(exports).join(', ') || 'nothing'\n io.err(\n `fascicle-diagram: ${module} has no export named ${export_name}: pass --export <name> (it exports ${names})\\n`,\n )\n return 1\n }\n let flow: unknown\n try {\n flow = await build(exports[export_name])\n } catch (err) {\n io.err(\n `fascicle-diagram: calling ${export_name}() in ${module} threw: ${message_of(err)}\\n` +\n 'Export a function that builds the flow with no arguments, wired to stub dependencies.\\n',\n )\n return 1\n }\n if (!is_step(flow)) {\n io.err(\n `fascicle-diagram: ${export_name} in ${module} is not a Step: export the flow itself, or a function that builds it with no arguments\\n`,\n )\n return 1\n }\n io.out(`${describe.diagram(flow, options)}\\n`)\n return 0\n}\n\n/**\n * Parse argv into a run request, a help request, or a usage error. Unknown\n * flags and a missing module are usage errors, and so is a width that is not\n * a positive integer.\n */\nfunction parse(argv: readonly string[]): Parsed {\n let parsed: ReturnType<typeof parse_flags>\n try {\n parsed = parse_flags(argv)\n } catch (err) {\n return { kind: 'usage', message: message_of(err) }\n }\n const { values, positionals } = parsed\n if (values.help === true) return { kind: 'help' }\n const [module, ...extra] = positionals\n if (module === undefined) return { kind: 'usage', message: 'a <module> to draw is required' }\n if (extra.length > 0) return { kind: 'usage', message: `expected one <module>, got ${positionals.join(' ')}` }\n const options: { width?: number; prefix?: string; replays?: boolean; internals?: boolean } = {}\n if (values.width !== undefined) {\n const width = Number(values.width)\n if (!Number.isInteger(width) || width <= 0) {\n return { kind: 'usage', message: `invalid --width '${values.width}': expected a positive integer` }\n }\n options.width = width\n }\n if (values.prefix !== undefined) options.prefix = values.prefix\n if (values.replays === true) options.replays = true\n if (values.internals === true) options.internals = true\n return { kind: 'run', args: { module, export_name: values.export ?? 'flow', options } }\n}\n\n/**\n * Read the CLI's flags with `node:util`'s strict parser, which throws on a\n * flag it does not know.\n */\nfunction parse_flags(argv: readonly string[]) {\n return parseArgs({\n args: [...argv],\n allowPositionals: true,\n options: {\n export: { type: 'string' },\n width: { type: 'string' },\n prefix: { type: 'string' },\n replays: { type: 'boolean' },\n internals: { type: 'boolean' },\n help: { type: 'boolean' },\n },\n })\n}\n\n/**\n * The Step an export stands for: the export itself, or what calling it with\n * no arguments returns (awaited, so an async builder works too).\n */\nasync function build(value: unknown): Promise<unknown> {\n return typeof value === 'function' ? await value() : value\n}\n\n/**\n * Render a thrown value as its message.\n */\nfunction message_of(err: unknown): string {\n return err instanceof Error ? err.message : String(err)\n}\n","/**\n * The process side of the fascicle-diagram bin: the real streams, and module\n * loading through the project's own `tsx`.\n *\n * Every decision the command makes lives in diagram_cli.ts, which is unit\n * tested through an injected io. This file only binds that io to the process,\n * so it is exercised by spawning it (__tests__/diagram_bin.test.ts) and kept\n * out of mutation testing, which cannot see a spawned child's coverage.\n *\n * A TypeScript module loads through `tsx` because Node's built-in type\n * stripping cannot follow the `./flow.js` specifiers that point at `.ts`\n * files under NodeNext resolution. Anything else, or a project without\n * `tsx`, goes through a plain `import()`.\n */\n\nimport { createRequire } from 'node:module'\nimport { resolve } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { run_diagram_cli } from './diagram_cli.js'\n\nconst TS_MODULE = /\\.[cm]?tsx?$/\n\n/**\n * Run the fascicle-diagram command over `argv` against the real process, and\n * leave its exit code on `process.exitCode`. A reader that closes the pipe\n * early (`| head`) ends the output quietly instead of crashing the command on\n * an unhandled EPIPE.\n */\nexport async function run_diagram_bin(argv: readonly string[]): Promise<void> {\n process.stdout.once('error', (err: NodeJS.ErrnoException) => {\n if (err.code !== 'EPIPE') throw err\n })\n process.exitCode = await run_diagram_cli(argv, {\n out: (text) => process.stdout.write(text),\n err: (text) => process.stderr.write(text),\n load: load_module,\n })\n}\n\n/**\n * Import the module at `path`. A TypeScript module goes through the `tsx`\n * that the project installs, looked up from the module's own directory and\n * then from the working directory. Everything else is a plain dynamic import.\n */\nasync function load_module(path: string): Promise<Readonly<Record<string, unknown>>> {\n const url = pathToFileURL(path).href\n if (!TS_MODULE.test(path)) return as_record(await import(url))\n const tsx = find_tsx([path, resolve('package.json')])\n if (tsx === undefined) return import_without_tsx(url)\n const api: unknown = await import(pathToFileURL(tsx).href)\n const ts_import = as_record(api)['tsImport']\n if (typeof ts_import !== 'function') return as_record(await import(url))\n return as_record(await ts_import(url, import.meta.url))\n}\n\n/**\n * Import a TypeScript module with Node's own type stripping, which handles\n * only erasable syntax and specifiers that name real files. A failure says\n * that tsx is the fix, since this path is taken only when none was found.\n */\nasync function import_without_tsx(url: string): Promise<Readonly<Record<string, unknown>>> {\n try {\n return as_record(await import(url))\n } catch (err) {\n const reason = err instanceof Error ? err.message : String(err)\n throw new Error(`${reason} (no tsx was found to load TypeScript: install it with pnpm add -D tsx)`, {\n cause: err,\n })\n }\n}\n\n/**\n * Resolve tsx's programmatic API from the first of `origins` that can see it,\n * or `undefined` when none can.\n */\nfunction find_tsx(origins: readonly string[]): string | undefined {\n for (const origin of origins) {\n try {\n return createRequire(origin).resolve('tsx/esm/api')\n } catch {\n // Not installed where this origin looks; try the next one.\n }\n }\n return undefined\n}\n\n/**\n * View a loaded module namespace as a record of its exports.\n */\nfunction as_record(value: unknown): Readonly<Record<string, unknown>> {\n return typeof value === 'object' && value !== null ? { ...value } : {}\n}\n\n// Auto-run only when this file is the entry script (`tsx src/diagram_bin.ts`),\n// never when the bundle that contains it is imported. The path comparison is\n// the same guard the viewer CLI uses.\nconst invoked_directly =\n process.argv[1] !== undefined && process.argv[1] === fileURLToPath(import.meta.url)\n\nif (invoked_directly) void run_diagram_bin(process.argv.slice(2))\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;AAyBb,eAAsB,gBAAgB,MAAyB,IAAmC;CAChG,MAAM,SAAS,MAAM,IAAI;CACzB,IAAI,OAAO,SAAS,QAAQ;EAC1B,GAAG,IAAI,IAAI;EACX,OAAO;CACT;CACA,IAAI,OAAO,SAAS,SAAS;EAC3B,GAAG,IAAI,qBAAqB,OAAO,QAAQ,MAAM,MAAM;EACvD,OAAO;CACT;CACA,MAAM,EAAE,QAAQ,aAAa,YAAY,OAAO;CAChD,MAAM,OAAO,QAAQ,MAAM;CAC3B,IAAI;CACJ,IAAI;EACF,UAAU,MAAM,GAAG,KAAK,IAAI;CAC9B,SAAS,KAAK;EACZ,GAAG,IAAI,oCAAoC,OAAO,IAAI,WAAW,GAAG,EAAE,GAAG;EACzE,OAAO;CACT;CACA,IAAI,CAAC,OAAO,OAAO,SAAS,WAAW,GAAG;EACxC,MAAM,QAAQ,OAAO,KAAK,OAAO,CAAC,CAAC,KAAK,IAAI,KAAK;EACjD,GAAG,IACD,qBAAqB,OAAO,uBAAuB,YAAY,qCAAqC,MAAM,IAC5G;EACA,OAAO;CACT;CACA,IAAI;CACJ,IAAI;EACF,OAAO,MAAM,MAAM,QAAQ,YAAY;CACzC,SAAS,KAAK;EACZ,GAAG,IACD,6BAA6B,YAAY,QAAQ,OAAO,UAAU,WAAW,GAAG,EAAE;CAEpF;EACA,OAAO;CACT;CACA,IAAI,CAAC,QAAQ,IAAI,GAAG;EAClB,GAAG,IACD,qBAAqB,YAAY,MAAM,OAAO,yFAChD;EACA,OAAO;CACT;CACA,GAAG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CAAC;CACH;AACF;;;;;AAMA,SAAS,SAAS,SAAgD;CAChE,KAAK,MAAM,UAAU,SACnB,IAAI;EACF,OAAO,cAAc,MAAM,CAAC,CAAC,QAAQ,aAAa;CACpD,QAAQ,CAER;AAGJ;;;;AAKA,SAAS,UAAU,OAAmD;CACpE,OAAO,OAAO,UAAU,YAAY,UAAU,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC;AACvE;AAQA,IAFE,QAAQ,KAAK,OAAO,KAAA,KAAa,QAAQ,KAAK,OAAO,cAAc,YAAY,GAAG,GAE9D,gBAAqB,QAAQ,KAAK,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"diagram_bin.js","names":[],"sources":["../src/diagram_cli.ts","../src/diagram_bin.ts"],"sourcesContent":["/**\n * fascicle-diagram CLI.\n *\n * fascicle-diagram <module> print the diagram of the module's `flow`\n * fascicle-diagram <module> --export <name> read another export instead\n *\n * Flags: --export <name> --width <n> --prefix <text> --replays --internals --outline --help\n *\n * The export is a Step, or a function that builds one with no arguments,\n * which is where an app wires its flow to stub dependencies so that drawing\n * it needs no credentials. The diagram is `describe.diagram` of that Step, so\n * it is what the code builds today and can be compared with the header in\n * `flow.ts` at a glance. `--outline` prints the plain `describe` outline\n * instead, with each node's kind, id, and config, which is the view to read\n * when the diagram hides something.\n *\n * This file holds every decision the command makes and touches nothing of\n * the process: output and module loading arrive through `DiagramCliIo`.\n * diagram_bin.ts binds that io to the real streams and to the project's\n * `tsx`, and is the entry that the package's bin shim runs.\n */\n\nimport { resolve } from 'node:path'\nimport { parseArgs } from 'node:util'\nimport { describe, is_step } from '#core'\nimport type { AnyStep, DiagramOptions } from '#core'\n\nexport type DiagramCliIo = {\n readonly out: (text: string) => void\n readonly err: (text: string) => void\n /** Import the module at an absolute path and return its exports. */\n readonly load: (path: string) => Promise<Readonly<Record<string, unknown>>>\n}\n\ntype CliArgs = {\n readonly module: string\n readonly export_name: string\n readonly outline: boolean\n readonly options: DiagramOptions\n}\n\ntype Parsed =\n | { readonly kind: 'help' }\n | { readonly kind: 'usage'; readonly message: string }\n | { readonly kind: 'run'; readonly args: CliArgs }\n\nconst HELP = `\\\nfascicle-diagram prints a flow as an annotated box-drawing tree.\n\nUsage:\n fascicle-diagram <module> draw the module's \\`flow\\` export\n fascicle-diagram <module> --export <name> draw another export instead\n\nThe export is a Step, or a function that builds one with no arguments.\n\nOptions:\n --export <name> the export to draw (default flow)\n --width <n> wrap descriptions so no line runs wider than n\n --prefix <text> start every line with text, for example ' * '\n --replays mark the steps a resumed run would pay for again\n --internals draw a named composite's internal steps, not only its parts\n --outline print describe()'s plain outline, with ids and config,\n instead of the diagram (no --width, --replays, or --internals)\n --help show this message\n`\n\n// The flags that only the diagram reads, which `--outline` refuses.\nconst DIAGRAM_ONLY = ['width', 'replays', 'internals'] as const\n\n/**\n * Run the CLI over `argv` and resolve to its exit code: 0 once the diagram is\n * printed, 1 when the module cannot be loaded or holds no Step, and 2 for a\n * usage error. Output and loading go through `io`, so the caller owns the\n * process.\n */\nexport async function run_diagram_cli(argv: readonly string[], io: DiagramCliIo): Promise<number> {\n const parsed = parse(argv)\n if (parsed.kind === 'help') {\n io.out(HELP)\n return 0\n }\n if (parsed.kind === 'usage') {\n io.err(`fascicle-diagram: ${parsed.message}\\n\\n${HELP}`)\n return 2\n }\n const { module, export_name, outline, options } = parsed.args\n const path = resolve(module)\n let exports: Readonly<Record<string, unknown>>\n try {\n exports = await io.load(path)\n } catch (err) {\n io.err(`fascicle-diagram: could not load ${module}: ${message_of(err)}\\n`)\n return 1\n }\n if (!Object.hasOwn(exports, export_name)) {\n const names = Object.keys(exports).join(', ') || 'nothing'\n io.err(\n `fascicle-diagram: ${module} has no export named ${export_name}: pass --export <name> (it exports ${names})\\n`,\n )\n return 1\n }\n let flow: unknown\n try {\n flow = await build(exports[export_name])\n } catch (err) {\n io.err(\n `fascicle-diagram: calling ${export_name}() in ${module} threw: ${message_of(err)}\\n` +\n 'Export a function that builds the flow with no arguments, wired to stub dependencies.\\n',\n )\n return 1\n }\n if (!is_step(flow)) {\n io.err(\n `fascicle-diagram: ${export_name} in ${module} is not a Step: export the flow itself, or a function that builds it with no arguments\\n`,\n )\n return 1\n }\n const text = outline ? outline_of(flow, options.prefix) : describe.diagram(flow, options)\n io.out(`${text}\\n`)\n return 0\n}\n\n/**\n * Render `describe`'s plain outline of `flow`, starting every line with\n * `prefix` the way the diagram does.\n */\nfunction outline_of(flow: AnyStep, prefix = ''): string {\n return describe(flow)\n .split('\\n')\n .map((line) => `${prefix}${line}`)\n .join('\\n')\n}\n\n/**\n * Parse argv into a run request, a help request, or a usage error. Unknown\n * flags and a missing module are usage errors, and so is a width that is not\n * a positive integer. `--outline` with an option that only the diagram reads\n * is one too, since the outline would drop it without a word.\n */\nfunction parse(argv: readonly string[]): Parsed {\n let parsed: ReturnType<typeof parse_flags>\n try {\n parsed = parse_flags(argv)\n } catch (err) {\n return { kind: 'usage', message: message_of(err) }\n }\n const { values, positionals } = parsed\n if (values.help === true) return { kind: 'help' }\n const [module, ...extra] = positionals\n if (module === undefined) return { kind: 'usage', message: 'a <module> to draw is required' }\n if (extra.length > 0) return { kind: 'usage', message: `expected one <module>, got ${positionals.join(' ')}` }\n const outline = values.outline === true\n if (outline) {\n const dropped = DIAGRAM_ONLY.filter((flag) => values[flag] !== undefined)\n if (dropped.length > 0) {\n const flags = dropped.map((flag) => `--${flag}`).join(', ')\n return { kind: 'usage', message: `--outline can't take ${flags}, which only the diagram reads` }\n }\n }\n const options: { width?: number; prefix?: string; replays?: boolean; internals?: boolean } = {}\n if (values.width !== undefined) {\n const width = Number(values.width)\n if (!Number.isInteger(width) || width <= 0) {\n return { kind: 'usage', message: `invalid --width '${values.width}': expected a positive integer` }\n }\n options.width = width\n }\n if (values.prefix !== undefined) options.prefix = values.prefix\n if (values.replays === true) options.replays = true\n if (values.internals === true) options.internals = true\n return { kind: 'run', args: { module, export_name: values.export ?? 'flow', outline, options } }\n}\n\n/**\n * Read the CLI's flags with `node:util`'s strict parser, which throws on a\n * flag it does not know.\n */\nfunction parse_flags(argv: readonly string[]) {\n return parseArgs({\n args: [...argv],\n allowPositionals: true,\n options: {\n export: { type: 'string' },\n width: { type: 'string' },\n prefix: { type: 'string' },\n replays: { type: 'boolean' },\n internals: { type: 'boolean' },\n outline: { type: 'boolean' },\n help: { type: 'boolean' },\n },\n })\n}\n\n/**\n * The Step an export stands for: the export itself, or what calling it with\n * no arguments returns (awaited, so an async builder works too).\n */\nasync function build(value: unknown): Promise<unknown> {\n return typeof value === 'function' ? await value() : value\n}\n\n/**\n * Render a thrown value as its message.\n */\nfunction message_of(err: unknown): string {\n return err instanceof Error ? err.message : String(err)\n}\n","/**\n * The process side of the fascicle-diagram bin: the real streams, and module\n * loading through the project's own `tsx`.\n *\n * Every decision the command makes lives in diagram_cli.ts, which is unit\n * tested through an injected io. This file only binds that io to the process,\n * so it is exercised by spawning it (__tests__/diagram_bin.test.ts) and kept\n * out of mutation testing, which cannot see a spawned child's coverage.\n *\n * A TypeScript module loads through `tsx` because Node's built-in type\n * stripping cannot follow the `./flow.js` specifiers that point at `.ts`\n * files under NodeNext resolution. Anything else, or a project without\n * `tsx`, goes through a plain `import()`.\n */\n\nimport { createRequire } from 'node:module'\nimport { resolve } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { run_diagram_cli } from './diagram_cli.js'\n\nconst TS_MODULE = /\\.[cm]?tsx?$/\n\n/**\n * Run the fascicle-diagram command over `argv` against the real process, and\n * leave its exit code on `process.exitCode`. A reader that closes the pipe\n * early (`| head`) ends the output quietly instead of crashing the command on\n * an unhandled EPIPE.\n */\nexport async function run_diagram_bin(argv: readonly string[]): Promise<void> {\n process.stdout.once('error', (err: NodeJS.ErrnoException) => {\n if (err.code !== 'EPIPE') throw err\n })\n process.exitCode = await run_diagram_cli(argv, {\n out: (text) => process.stdout.write(text),\n err: (text) => process.stderr.write(text),\n load: load_module,\n })\n}\n\n/**\n * Import the module at `path`. A TypeScript module goes through the `tsx`\n * that the project installs, looked up from the module's own directory and\n * then from the working directory. Everything else is a plain dynamic import.\n */\nasync function load_module(path: string): Promise<Readonly<Record<string, unknown>>> {\n const url = pathToFileURL(path).href\n if (!TS_MODULE.test(path)) return as_record(await import(url))\n const tsx = find_tsx([path, resolve('package.json')])\n if (tsx === undefined) return import_without_tsx(url)\n const api: unknown = await import(pathToFileURL(tsx).href)\n const ts_import = as_record(api)['tsImport']\n if (typeof ts_import !== 'function') return as_record(await import(url))\n return as_record(await ts_import(url, import.meta.url))\n}\n\n/**\n * Import a TypeScript module with Node's own type stripping, which handles\n * only erasable syntax and specifiers that name real files. A failure says\n * that tsx is the fix, since this path is taken only when none was found.\n */\nasync function import_without_tsx(url: string): Promise<Readonly<Record<string, unknown>>> {\n try {\n return as_record(await import(url))\n } catch (err) {\n const reason = err instanceof Error ? err.message : String(err)\n throw new Error(`${reason} (no tsx was found to load TypeScript: install it with pnpm add -D tsx)`, {\n cause: err,\n })\n }\n}\n\n/**\n * Resolve tsx's programmatic API from the first of `origins` that can see it,\n * or `undefined` when none can.\n */\nfunction find_tsx(origins: readonly string[]): string | undefined {\n for (const origin of origins) {\n try {\n return createRequire(origin).resolve('tsx/esm/api')\n } catch {\n // Not installed where this origin looks; try the next one.\n }\n }\n return undefined\n}\n\n/**\n * View a loaded module namespace as a record of its exports.\n */\nfunction as_record(value: unknown): Readonly<Record<string, unknown>> {\n return typeof value === 'object' && value !== null ? { ...value } : {}\n}\n\n// Auto-run only when this file is the entry script (`tsx src/diagram_bin.ts`),\n// never when the bundle that contains it is imported. The path comparison is\n// the same guard the viewer CLI uses.\nconst invoked_directly =\n process.argv[1] !== undefined && process.argv[1] === fileURLToPath(import.meta.url)\n\nif (invoked_directly) void run_diagram_bin(process.argv.slice(2))\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;AAqBb,MAAM,eAAe;CAAC;CAAS;CAAW;AAAW;;;;;;;AAQr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xD;;;;;;AAOA,eAAe,mBAAmB,KAAyD;CACzF,IAAI;EACF,OAAO,UAAU,MAAM,OAAO,IAAI;CACpC,SAAS,KAAK;EACZ,MAAM,SAAS,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;EAC9D,MAAM,IAAI,MAAM,GAAG,OAAO,0EAA0E,EAClG,OAAO,IACT,CAAC;CACH;AACF;;;;;AAMA,SAAS,SAAS,SAAgD;CAChE,KAAK,MAAM,UAAU,SACnB,IAAI;EACF,OAAO,cAAc,MAAM,CAAC,CAAC,QAAQ,aAAa;CACpD,QAAQ,CAER;AAGJ;;;;AAKA,SAAS,UAAU,OAAmD;CACpE,OAAO,OAAO,UAAU,YAAY,UAAU,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC;AACvE;AAQA,IAFE,QAAQ,KAAK,OAAO,KAAA,KAAa,QAAQ,KAAK,OAAO,cAAc,YAAY,GAAG,GAE9D,gBAAqB,QAAQ,KAAK,MAAM,CAAC,CAAC"}
@@ -1,6 +1,6 @@
1
- import { T as validate_schema, f as compute_backoff, k as aborted_error, p as wait_with_abort, w as format_schema_issues } from "./core-BOFcG3tp.js";
1
+ import { A as aborted_error, T as validate_schema, f as compute_backoff, p as wait_with_abort, w as format_schema_issues } from "./core-Dwir3pkb.js";
2
2
  import { n as is_record$1 } from "./records-1HU7mWXf.js";
3
- import { A as tool_approval_denied_error, C as provider_auth_error, D as provider_required_error, E as provider_not_configured_error, M as turn_timeout_error, O as rate_limit_error, S as on_chunk_error, T as provider_error, _ as claude_cli_error, b as incomplete_generation_error, c as parse_tool_call_arguments, d as default_normalize_usage, f as load_optional_peer, g as translate_effort_to_sdk_reasoning, h as resolve_transport, i as invoke_http_turn, j as tool_error, k as schema_validation_error, l as read_dialect_init, m as normalize_local_usage, n as consume_framed_stream, o as map_messages_by_role, p as missing_peer_error, r as create_line_splitter, s as network_failure, t as split_leading_system_run, u as split_assistant_parts, v as engine_config_error, w as provider_capability_error, x as model_required_error, y as engine_disposed_error } from "./leading_system-DmNxhvzL.js";
3
+ import { A as tool_approval_denied_error, C as provider_auth_error, D as provider_required_error, E as provider_not_configured_error, M as turn_timeout_error, O as rate_limit_error, S as on_chunk_error, T as provider_error, _ as claude_cli_error, b as incomplete_generation_error, c as parse_tool_call_arguments, d as default_normalize_usage, f as load_optional_peer, g as translate_effort_to_sdk_reasoning, h as resolve_transport, i as invoke_http_turn, j as tool_error, k as schema_validation_error, l as read_dialect_init, m as normalize_local_usage, n as consume_framed_stream, o as map_messages_by_role, p as missing_peer_error, r as create_line_splitter, s as network_failure, t as split_leading_system_run, u as split_assistant_parts, v as engine_config_error, w as provider_capability_error, x as model_required_error, y as engine_disposed_error } from "./leading_system-DJvuhESU.js";
4
4
  import { join } from "node:path";
5
5
  import { mkdtempSync, writeFileSync } from "node:fs";
6
6
  import { tmpdir } from "node:os";
@@ -465,36 +465,58 @@ function to_abort_error(reason) {
465
465
  return new aborted_error("aborted", { reason });
466
466
  }
467
467
  /**
468
- * Build the `rate_limit_error` thrown when 429 retries exhaust. Prefers the
469
- * failing attempt's own `Retry-After`, falling back to the most recent one a
470
- * prior attempt carried (`last_rate_limit_after`).
468
+ * Build the `rate_limit_error` for a 429 that this layer won't retry again.
469
+ * Prefers the failing attempt's own `Retry-After`, falling back to the most
470
+ * recent one a prior attempt carried (`last_rate_limit_after`), and carries
471
+ * the failure's own message, or `fallback` when it had none.
471
472
  */
472
- function build_rate_limit_error(retryable, attempt, last_rate_limit_after) {
473
+ function build_rate_limit_error(retryable, attempt, last_rate_limit_after, fallback) {
473
474
  const metadata = { attempts: attempt };
474
475
  if (retryable.retry_after_ms !== void 0) metadata.retry_after_ms = retryable.retry_after_ms;
475
476
  else if (last_rate_limit_after !== void 0) metadata.retry_after_ms = last_rate_limit_after;
476
477
  if (retryable.status !== void 0) metadata.status = retryable.status;
477
- return new rate_limit_error(retryable.message ?? `rate limited after ${attempt} attempts`, metadata);
478
+ return new rate_limit_error(retryable.message ?? fallback, metadata);
478
479
  }
479
480
  /**
480
- * Build the `provider_error` thrown when 5xx/network/timeout retries exhaust.
481
- * Timeout collapses onto the `network` cause; only 5xx carries status/body.
481
+ * Build the `provider_error` for a 5xx, network, or timeout failure that this
482
+ * layer won't retry again. Timeout collapses onto the `network` cause; only
483
+ * 5xx carries status/body. The failure's own message wins over `fallback`.
482
484
  */
483
- function build_provider_error(retryable, attempt) {
485
+ function build_provider_error(retryable, fallback) {
484
486
  const metadata = { cause_kind: retryable.kind === "provider_5xx" ? "provider_5xx" : "network" };
485
487
  if (retryable.kind === "provider_5xx") {
486
488
  if (retryable.status !== void 0) metadata.status = retryable.status;
487
489
  if (retryable.body !== void 0) metadata.body = retryable.body;
488
490
  }
489
- return new provider_error(retryable.message ?? `${retryable.kind} after ${attempt} attempts`, metadata);
491
+ return new provider_error(retryable.message ?? fallback, metadata);
490
492
  }
491
493
  /**
492
- * Map an exhausted retryable failure onto the error this layer rejects with:
493
- * `rate_limit_error` for 429s, `provider_error` for everything else.
494
+ * Map a classified failure that this layer won't retry again onto the error
495
+ * it rejects with: `rate_limit_error` for 429s, `provider_error` for
496
+ * everything else, after `attempt` failures in all. `fallback` is the message
497
+ * for a failure that carried none of its own.
494
498
  */
495
- function build_exhaustion_error(retryable, attempt, last_rate_limit_after) {
496
- if (retryable.kind === "rate_limit") return build_rate_limit_error(retryable, attempt, last_rate_limit_after);
497
- return build_provider_error(retryable, attempt);
499
+ function build_typed_error(retryable, attempt, last_rate_limit_after, fallback) {
500
+ if (retryable.kind === "rate_limit") return build_rate_limit_error(retryable, attempt, last_rate_limit_after, fallback);
501
+ return build_provider_error(retryable, fallback);
502
+ }
503
+ /**
504
+ * The error for a failure whose kind `retry_on` leaves out. One that's
505
+ * already an `Error`, such as `turn_timeout_error` or a native adapter's
506
+ * network failure, is rethrown as it is, so a caller that catches its class
507
+ * still gets it. A plain record that `classify_provider_error` built becomes
508
+ * the typed error that exhaustion would have thrown for its kind, so a
509
+ * caller never gets a value that prints as `[object Object]`.
510
+ */
511
+ function build_left_out_error(err, retryable, attempt, last_rate_limit_after) {
512
+ if (err instanceof Error) return err;
513
+ return build_typed_error(retryable, attempt, last_rate_limit_after, `${retryable.kind} not retried: retry_on leaves ${retryable.kind} out`);
514
+ }
515
+ /**
516
+ * The message for an exhausted failure that carried none of its own.
517
+ */
518
+ function exhaustion_message(retryable, attempt) {
519
+ return retryable.kind === "rate_limit" ? `rate limited after ${attempt} attempts` : `${retryable.kind} after ${attempt} attempts`;
498
520
  }
499
521
  /**
500
522
  * The server's `Retry-After`, in milliseconds, that a 429 or a 5xx carried,
@@ -552,6 +574,12 @@ function build_attempt_info(retryable, attempt, delay_ms) {
552
574
  * exhaustion, throws `rate_limit_error` (for 429s) or `provider_error` (for
553
575
  * 5xx/network/timeout).
554
576
  *
577
+ * A failure whose kind `retry_on` leaves out isn't retried. It's rethrown as
578
+ * it is when it's already an `Error`, and a plain record becomes the
579
+ * `rate_limit_error` or `provider_error` that exhaustion would throw for its
580
+ * kind, counting every failure so far in `attempts`, with the record's own
581
+ * message, or else one that says `retry_on` leaves its kind out.
582
+ *
555
583
  * `on_retry` fires once per retried failure, just before its backoff wait.
556
584
  * It does NOT fire for a first attempt that succeeds, a non-retryable
557
585
  * failure, or the final failure that exhausts the policy (those two throw
@@ -572,9 +600,10 @@ async function retry_with_policy(fn, policy = DEFAULT_RETRY, abort, on_retry) {
572
600
  return await fn(attempt);
573
601
  } catch (err) {
574
602
  const retryable = classify_retryable(err);
575
- if (retryable === void 0 || !is_retryable(retryable.kind, policy)) throw err;
603
+ if (retryable === void 0) throw err;
576
604
  attempt += 1;
577
- if (attempt >= policy.max_attempts) throw build_exhaustion_error(retryable, attempt, last_rate_limit_after);
605
+ if (!is_retryable(retryable.kind, policy)) throw build_left_out_error(err, retryable, attempt, last_rate_limit_after);
606
+ if (attempt >= policy.max_attempts) throw build_typed_error(retryable, attempt, last_rate_limit_after, exhaustion_message(retryable, attempt));
578
607
  const backoff = next_backoff(retryable, backoff_policy, attempt);
579
608
  last_rate_limit_after = carry_rate_limit_after(retryable, backoff, last_rate_limit_after);
580
609
  on_retry?.(build_attempt_info(retryable, attempt, backoff.delay));
@@ -7710,7 +7739,7 @@ async function build_ai_sdk_transport(cfg) {
7710
7739
  const provider_options = combined_provider_options !== void 0 && Object.keys(combined_provider_options).length > 0 ? combined_provider_options : void 0;
7711
7740
  let ai_sdk_invoke_mod;
7712
7741
  try {
7713
- ai_sdk_invoke_mod = await import("./invoke-BbJLQcLl.js");
7742
+ ai_sdk_invoke_mod = await import("./invoke-DF7YLovL.js");
7714
7743
  } catch (err) {
7715
7744
  throw missing_peer_error("ai", err);
7716
7745
  }
@@ -8347,4 +8376,4 @@ function create_engine(config) {
8347
8376
  //#endregion
8348
8377
  export { to_json_schema as n, create_engine as t };
8349
8378
 
8350
- //# sourceMappingURL=engine-Bde18P7H.js.map
8379
+ //# sourceMappingURL=engine-DPPqAVdZ.js.map