fascicle 0.15.0 → 0.16.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/README.md +8 -8
  3. package/dist/acp.d.ts +9 -2
  4. package/dist/acp.js +1538 -1472
  5. package/dist/acp.js.map +1 -1
  6. package/dist/{adapters-DNnzeLxr.js → adapters-CDUzZlby.js} +35 -13
  7. package/dist/adapters-CDUzZlby.js.map +1 -0
  8. package/dist/adapters.d.ts +8 -1
  9. package/dist/adapters.js +1 -1
  10. package/dist/agents.d.ts +1 -1
  11. package/dist/agents.js +15 -8
  12. package/dist/agents.js.map +1 -1
  13. package/dist/bin/fascicle-viewer.js +4 -1
  14. package/dist/console-CdB4pcFO.js +37 -0
  15. package/dist/console-CdB4pcFO.js.map +1 -0
  16. package/dist/{core-CDrz0NM1.js → core-CErsxGF6.js} +246 -147
  17. package/dist/core-CErsxGF6.js.map +1 -0
  18. package/dist/diagram_bin.js +2 -2
  19. package/dist/diagram_bin.js.map +1 -1
  20. package/dist/{engine-ha9xmgwE.js → engine-CR8q2IqV.js} +173 -67
  21. package/dist/engine-CR8q2IqV.js.map +1 -0
  22. package/dist/index.d.ts +529 -73
  23. package/dist/index.js +440 -137
  24. package/dist/index.js.map +1 -1
  25. package/dist/{invoke-px31fffH.js → invoke-COaeZ-vy.js} +6 -5
  26. package/dist/invoke-COaeZ-vy.js.map +1 -0
  27. package/dist/{json_schema_to_standard-BTWD0J6p.js → json_schema_to_standard-C4F4lXHE.js} +9 -12
  28. package/dist/json_schema_to_standard-C4F4lXHE.js.map +1 -0
  29. package/dist/{leading_system-DfJLqpGi.js → leading_system-PoHzNHuV.js} +28 -8
  30. package/dist/leading_system-PoHzNHuV.js.map +1 -0
  31. package/dist/mcp.d.ts +3 -2
  32. package/dist/mcp.js +8 -4
  33. package/dist/mcp.js.map +1 -1
  34. package/dist/otel.js +10 -10
  35. package/dist/otel.js.map +1 -1
  36. package/dist/{search-CA_OqFeW.js → search-CpCJYMUm.js} +53 -6
  37. package/dist/search-CpCJYMUm.js.map +1 -0
  38. package/dist/search_worker.js +1 -1
  39. package/dist/stdio.js +7 -3
  40. package/dist/stdio.js.map +1 -1
  41. package/dist/testing.d.ts +1 -1
  42. package/dist/testing.js +3 -3
  43. package/dist/testing.js.map +1 -1
  44. package/dist/{trajectory-Bm-mOtqw.d.ts → trajectory-BKGNxi7u.d.ts} +10 -9
  45. package/dist/{trajectory-BI-mrVFT.js → trajectory-DeURWIhj.js} +6 -5
  46. package/dist/trajectory-DeURWIhj.js.map +1 -0
  47. package/dist/{types-De-TVQxS.d.ts → types-Sw0oHW-_.d.ts} +6 -7
  48. package/dist/ui.d.ts +2 -1
  49. package/dist/ui.js +8 -1
  50. package/dist/ui.js.map +1 -1
  51. package/dist/viewer-app/assets/index-BYF5Dp7d.js +2 -0
  52. package/dist/viewer-app/index.html +2 -1
  53. package/dist/viewer.d.ts +26 -12
  54. package/dist/viewer.js +282 -63
  55. package/dist/viewer.js.map +1 -1
  56. package/package.json +5 -5
  57. package/dist/adapters-DNnzeLxr.js.map +0 -1
  58. package/dist/core-CDrz0NM1.js.map +0 -1
  59. package/dist/engine-ha9xmgwE.js.map +0 -1
  60. package/dist/invoke-px31fffH.js.map +0 -1
  61. package/dist/json_schema_to_standard-BTWD0J6p.js.map +0 -1
  62. package/dist/leading_system-DfJLqpGi.js.map +0 -1
  63. package/dist/search-CA_OqFeW.js.map +0 -1
  64. package/dist/trajectory-BI-mrVFT.js.map +0 -1
  65. package/dist/viewer-app/assets/index-Fnh5HKSU.js +0 -2
@@ -1,4 +1,4 @@
1
- import { D as describe, O as is_step } from "./core-CDrz0NM1.js";
1
+ import { D as describe, O as is_step } from "./core-CErsxGF6.js";
2
2
  import { createRequire } from "node:module";
3
3
  import { resolve } from "node:path";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -64,7 +64,7 @@ async function run_diagram_cli(argv, io) {
64
64
  io.err(`fascicle-diagram: could not load ${module}: ${message_of(err)}\n`);
65
65
  return 1;
66
66
  }
67
- if (!(export_name in exports)) {
67
+ if (!Object.hasOwn(exports, export_name)) {
68
68
  const names = Object.keys(exports).join(", ") || "nothing";
69
69
  io.err(`fascicle-diagram: ${module} has no export named ${export_name}: pass --export <name> (it exports ${names})\n`);
70
70
  return 1;
@@ -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 --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 --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 (!(export_name in exports)) {\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 } = {}\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 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 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;;;;;;;;;;;;;;;;;;;;;;AAwBb,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,EAAE,eAAe,UAAU;EAC7B,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;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AU,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 --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 --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 } = {}\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 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 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;;;;;;;;;;;;;;;;;;;;;;AAwBb,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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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 { h as wait_with_abort, k as aborted_error, m as compute_backoff, o as format_schema_issues, s as validate_schema } from "./core-CDrz0NM1.js";
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-CErsxGF6.js";
2
2
  import { n as is_record$1 } from "./records-1HU7mWXf.js";
3
- import { A as tool_error, C as provider_capability_error, D as rate_limit_error, E as provider_required_error, O as schema_validation_error, S as provider_auth_error, T as provider_not_configured_error, _ as engine_config_error, b as model_required_error, c as read_dialect_init, d as load_optional_peer, f as missing_peer_error, g as claude_cli_error, h as translate_effort_to_sdk_reasoning, i as invoke_http_turn, j as turn_timeout_error, k as tool_approval_denied_error, l as split_assistant_parts, m as resolve_transport, n as consume_framed_stream, o as map_messages_by_role, p as normalize_local_usage, r as create_line_splitter, s as parse_tool_call_arguments, t as split_leading_system_run, u as default_normalize_usage, v as engine_disposed_error, w as provider_error, x as on_chunk_error, y as incomplete_generation_error } from "./leading_system-DfJLqpGi.js";
3
+ import { A as tool_error, C as provider_capability_error, D as rate_limit_error, E as provider_required_error, O as schema_validation_error, S as provider_auth_error, T as provider_not_configured_error, _ as engine_config_error, b as model_required_error, c as read_dialect_init, d as load_optional_peer, f as missing_peer_error, g as claude_cli_error, h as translate_effort_to_sdk_reasoning, i as invoke_http_turn, j as turn_timeout_error, k as tool_approval_denied_error, l as split_assistant_parts, m as resolve_transport, n as consume_framed_stream, o as map_messages_by_role, p as normalize_local_usage, r as create_line_splitter, s as parse_tool_call_arguments, t as split_leading_system_run, u as default_normalize_usage, v as engine_disposed_error, w as provider_error, x as on_chunk_error, y as incomplete_generation_error } from "./leading_system-PoHzNHuV.js";
4
4
  import { join } from "node:path";
5
5
  import { mkdtempSync, writeFileSync } from "node:fs";
6
6
  import { tmpdir } from "node:os";
@@ -105,7 +105,7 @@ function close_nested(node) {
105
105
  const closed = { ...node };
106
106
  for (const key of SCHEMA_BAGS) {
107
107
  const bag = closed[key];
108
- if (is_node(bag)) closed[key] = close_bag(bag);
108
+ if (is_record$1(bag)) closed[key] = close_bag(bag);
109
109
  }
110
110
  for (const key of SCHEMA_SLOTS) if (key in closed) closed[key] = close_value(closed[key]);
111
111
  return closed;
@@ -119,7 +119,7 @@ function close_bag(bag) {
119
119
  /** Recurse into a schema or a list of them, leaving anything else alone. */
120
120
  function close_value(value) {
121
121
  if (Array.isArray(value)) return value.map(close_value);
122
- return is_node(value) ? close_objects(value) : value;
122
+ return is_record$1(value) ? close_objects(value) : value;
123
123
  }
124
124
  /** True for an object node listing its keys but not saying whether more are allowed. */
125
125
  function needs_closing(node) {
@@ -127,10 +127,6 @@ function needs_closing(node) {
127
127
  const type = node["type"];
128
128
  return type === "object" || Array.isArray(type) && type.includes("object");
129
129
  }
130
- /** A JSON Schema node, as opposed to a boolean schema, a list, or a scalar. */
131
- function is_node(value) {
132
- return typeof value === "object" && value !== null && !Array.isArray(value);
133
- }
134
130
  /**
135
131
  * Drop the top-level `$schema` and `$id` keys.
136
132
  *
@@ -147,6 +143,30 @@ const FREE_PROVIDERS = /* @__PURE__ */ new Set(["ollama", "lmstudio"]);
147
143
  const CACHE_READ_MULTIPLIER = .1;
148
144
  const CACHE_WRITE_MULTIPLIER = 1.25;
149
145
  const DEFAULT_PRICING = Object.freeze({
146
+ "anthropic:claude-fable-5-1": {
147
+ input_per_million: 10,
148
+ output_per_million: 50,
149
+ cached_input_per_million: .25,
150
+ cache_write_per_million: 12.5
151
+ },
152
+ "anthropic:claude-fable-5": {
153
+ input_per_million: 10,
154
+ output_per_million: 50,
155
+ cached_input_per_million: 1,
156
+ cache_write_per_million: 12.5
157
+ },
158
+ "anthropic:claude-opus-5-5": {
159
+ input_per_million: 4,
160
+ output_per_million: 20,
161
+ cached_input_per_million: .2,
162
+ cache_write_per_million: 5
163
+ },
164
+ "anthropic:claude-opus-5": {
165
+ input_per_million: 5,
166
+ output_per_million: 25,
167
+ cached_input_per_million: .5,
168
+ cache_write_per_million: 6.25
169
+ },
150
170
  "anthropic:claude-opus-4-8": {
151
171
  input_per_million: 5,
152
172
  output_per_million: 25,
@@ -165,18 +185,54 @@ const DEFAULT_PRICING = Object.freeze({
165
185
  cached_input_per_million: .5,
166
186
  cache_write_per_million: 6.25
167
187
  },
188
+ "anthropic:claude-sonnet-5-5": {
189
+ input_per_million: 2,
190
+ output_per_million: 10,
191
+ cached_input_per_million: .1,
192
+ cache_write_per_million: 2.5
193
+ },
194
+ "anthropic:claude-sonnet-5": {
195
+ input_per_million: 2,
196
+ output_per_million: 10,
197
+ cached_input_per_million: .2,
198
+ cache_write_per_million: 2.5
199
+ },
168
200
  "anthropic:claude-sonnet-4-6": {
169
201
  input_per_million: 3,
170
202
  output_per_million: 15,
171
203
  cached_input_per_million: .3,
172
204
  cache_write_per_million: 3.75
173
205
  },
206
+ "anthropic:claude-haiku-5-5": {
207
+ input_per_million: .1,
208
+ output_per_million: .5,
209
+ cached_input_per_million: .01,
210
+ cache_write_per_million: .125
211
+ },
174
212
  "anthropic:claude-haiku-4-5": {
175
213
  input_per_million: 1,
176
214
  output_per_million: 5,
177
215
  cached_input_per_million: .1,
178
216
  cache_write_per_million: 1.25
179
217
  },
218
+ "openai:gpt-6-astra": {
219
+ input_per_million: 10,
220
+ output_per_million: 50,
221
+ cached_input_per_million: 1,
222
+ cache_write_per_million: 12.5
223
+ },
224
+ "openai:gpt-6.1-sol": {
225
+ input_per_million: 2,
226
+ output_per_million: 10,
227
+ cached_input_per_million: .1,
228
+ cache_write_per_million: 2.5
229
+ },
230
+ "openai:gpt-6-luna": {
231
+ input_per_million: .1,
232
+ output_per_million: .5,
233
+ cached_input_per_million: .01,
234
+ cache_write_per_million: .125
235
+ },
180
236
  "openai:gpt-4o": {
181
237
  input_per_million: 2.5,
182
238
  output_per_million: 10,
@@ -187,13 +243,30 @@ const DEFAULT_PRICING = Object.freeze({
187
243
  output_per_million: .6,
188
244
  cached_input_per_million: .075
189
245
  },
246
+ "google:gemini-4-argon": {
247
+ input_per_million: 2,
248
+ output_per_million: 10,
249
+ cached_input_per_million: .1
250
+ },
251
+ "google:gemini-3.8-flash": {
252
+ input_per_million: .75,
253
+ output_per_million: 3.75,
254
+ cached_input_per_million: .075
255
+ },
256
+ "google:gemini-3.5-flash-lite": {
257
+ input_per_million: .3,
258
+ output_per_million: 2.5,
259
+ cached_input_per_million: .03
260
+ },
190
261
  "google:gemini-2.5-pro": {
191
262
  input_per_million: 1.25,
192
- output_per_million: 5
263
+ output_per_million: 10,
264
+ cached_input_per_million: .125
193
265
  },
194
266
  "google:gemini-2.5-flash": {
195
- input_per_million: .075,
196
- output_per_million: .3
267
+ input_per_million: .3,
268
+ output_per_million: 2.5,
269
+ cached_input_per_million: .03
197
270
  }
198
271
  });
199
272
  /**
@@ -208,7 +281,7 @@ function pricing_key(provider, model_id) {
208
281
  * Per-token rates produce long floating-point tails; 6 places keeps
209
282
  * sub-cent precision without leaking binary rounding noise into reports.
210
283
  */
211
- function round6$1(value) {
284
+ function round6(value) {
212
285
  return Math.round(value * 1e6) / 1e6;
213
286
  }
214
287
  /**
@@ -241,7 +314,7 @@ function apply_reasoning_cost(plain_output_usd_raw, reasoning, has_reasoning_rat
241
314
  if (reasoning > 0) {
242
315
  if (has_reasoning_rate) return {
243
316
  output_usd_raw: plain_output_usd_raw,
244
- surface_reasoning_usd: round6$1(reasoning_usd_raw)
317
+ surface_reasoning_usd: round6(reasoning_usd_raw)
245
318
  };
246
319
  return {
247
320
  output_usd_raw: plain_output_usd_raw + reasoning_usd_raw,
@@ -279,14 +352,14 @@ function compute_cost(usage, pricing, provider) {
279
352
  const reasoning_usd_raw = reasoning * reasoning_rate / 1e6;
280
353
  const { output_usd_raw, surface_reasoning_usd } = apply_reasoning_cost(Math.max(0, usage.output_tokens - reasoning) * pricing.output_per_million / 1e6, reasoning, pricing.reasoning_per_million !== void 0, reasoning_usd_raw);
281
354
  const breakdown = {
282
- total_usd: round6$1(input_usd_raw + cached_usd_raw + cache_write_usd_raw + (surface_reasoning_usd !== void 0 ? reasoning_usd_raw : 0) + output_usd_raw),
283
- input_usd: round6$1(input_usd_raw),
284
- output_usd: round6$1(output_usd_raw),
355
+ total_usd: round6(input_usd_raw + cached_usd_raw + cache_write_usd_raw + (surface_reasoning_usd !== void 0 ? reasoning_usd_raw : 0) + output_usd_raw),
356
+ input_usd: round6(input_usd_raw),
357
+ output_usd: round6(output_usd_raw),
285
358
  currency: "USD",
286
359
  is_estimate: true
287
360
  };
288
- if (cached > 0) breakdown.cached_input_usd = round6$1(cached_usd_raw);
289
- if (cache_write > 0) breakdown.cache_write_usd = round6$1(cache_write_usd_raw);
361
+ if (cached > 0) breakdown.cached_input_usd = round6(cached_usd_raw);
362
+ if (cache_write > 0) breakdown.cache_write_usd = round6(cache_write_usd_raw);
290
363
  if (surface_reasoning_usd !== void 0) breakdown.reasoning_usd = surface_reasoning_usd;
291
364
  return breakdown;
292
365
  }
@@ -614,7 +687,7 @@ function create_sse_decoder() {
614
687
  */
615
688
  /**
616
689
  * Effort level to the room native adds to its max_tokens default for
617
- * adaptive thinking. No transport sends these as a budget any more: native
690
+ * adaptive thinking. Neither transport sends these as a budget: native
618
691
  * sends `output_config.effort`, and the ai_sdk transport hands the level to
619
692
  * the SDK's `reasoning` option.
620
693
  */
@@ -1306,12 +1379,13 @@ const create_anthropic_ai_sdk_adapter = (init) => {
1306
1379
  * parallel code paths.
1307
1380
  */
1308
1381
  /**
1309
- * The flat field's wire enum is `low | medium | high` only, so `xhigh` and
1310
- * `max` clamp to `high`. The nested shape takes every level, so it skips this
1311
- * table. Non-reasoning models ignore either field server-side; the adapter
1312
- * does not model-sniff.
1382
+ * The levels a `clamp_effort` server takes on the flat field: `low | medium |
1383
+ * high` only, so `xhigh` and `max` clamp to `high`. OpenAI's own enum takes
1384
+ * every level, so the openai dialect skips this table, as the nested shape
1385
+ * does. Which levels a model honors is the server's call; the adapter does
1386
+ * not model-sniff.
1313
1387
  */
1314
- const OPENAI_COMPATIBLE_REASONING_EFFORT = {
1388
+ const CLAMPED_REASONING_EFFORT = {
1315
1389
  low: "low",
1316
1390
  medium: "medium",
1317
1391
  high: "high",
@@ -1434,7 +1508,7 @@ function to_chat_tools(tools) {
1434
1508
  function apply_effort(body, effort, dialect) {
1435
1509
  if (effort === "none") return;
1436
1510
  if (dialect.effort_shape === "nested") body["reasoning"] = { effort };
1437
- else body["reasoning_effort"] = OPENAI_COMPATIBLE_REASONING_EFFORT[effort];
1511
+ else body["reasoning_effort"] = dialect.clamp_effort === true ? CLAMPED_REASONING_EFFORT[effort] : effort;
1438
1512
  }
1439
1513
  /**
1440
1514
  * Build the Chat Completions request body for one turn: mapped messages and
@@ -1488,12 +1562,31 @@ function read_number(source, key) {
1488
1562
  return typeof value === "number" ? value : void 0;
1489
1563
  }
1490
1564
  /**
1565
+ * Copy the cache counts in a usage object's prompt_tokens_details onto
1566
+ * totals, `cached_tokens` as reads and `cache_write_tokens` as writes,
1567
+ * leaving off any count that isn't a number.
1568
+ */
1569
+ function read_prompt_details(raw, totals) {
1570
+ const details = Reflect.get(raw, "prompt_tokens_details");
1571
+ if (details === null || typeof details !== "object") return;
1572
+ const cached = read_number(details, "cached_tokens");
1573
+ if (cached !== void 0) totals.cached_input_tokens = cached;
1574
+ const cache_write = read_number(details, "cache_write_tokens");
1575
+ if (cache_write !== void 0) totals.cache_write_tokens = cache_write;
1576
+ }
1577
+ /**
1491
1578
  * Map the Chat Completions usage object to UsageTotals. prompt_tokens is
1492
1579
  * already INCLUSIVE of cached tokens on this API, unlike Anthropic's
1493
1580
  * exclusive accounting, so a straight copy is correct; compute_cost
1494
- * subtracts the cached portion back out. No cache-write concept exists on
1495
- * this wire. A missing usage object throws under a strict dialect (a hosted
1496
- * API omitting usage is a broken response) and zeroes under a tolerant one.
1581
+ * subtracts the cached portion back out. OpenRouter adds
1582
+ * `prompt_tokens_details.cache_write_tokens` for a model with explicit
1583
+ * caching, and prompt_tokens counts those too: a live request to
1584
+ * anthropic/claude-sonnet-5.5 through Google Vertex on 2026-10-19 reported
1585
+ * prompt_tokens 16,358 with 16,299 cache writes, then 16,358 with 16,299
1586
+ * cache reads on the same request repeated, and its charge matched pricing
1587
+ * that subtracts both from prompt_tokens. A missing usage object throws
1588
+ * under a strict dialect (a hosted API omitting usage is a broken response)
1589
+ * and zeroes under a tolerant one.
1497
1590
  */
1498
1591
  function map_chat_usage(raw, dialect) {
1499
1592
  if (raw === null || typeof raw !== "object") {
@@ -1507,11 +1600,7 @@ function map_chat_usage(raw, dialect) {
1507
1600
  input_tokens: read_number(raw, "prompt_tokens") ?? 0,
1508
1601
  output_tokens: read_number(raw, "completion_tokens") ?? 0
1509
1602
  };
1510
- const prompt_details = Reflect.get(raw, "prompt_tokens_details");
1511
- if (prompt_details !== null && typeof prompt_details === "object") {
1512
- const cached = read_number(prompt_details, "cached_tokens");
1513
- if (cached !== void 0) totals.cached_input_tokens = cached;
1514
- }
1603
+ read_prompt_details(raw, totals);
1515
1604
  const completion_details = Reflect.get(raw, "completion_tokens_details");
1516
1605
  if (completion_details !== null && typeof completion_details === "object") {
1517
1606
  const reasoning = read_number(completion_details, "reasoning_tokens");
@@ -1565,8 +1654,8 @@ function parse_tool_call(raw, provider) {
1565
1654
  }
1566
1655
  /**
1567
1656
  * The one response parser every path feeds: non-stream parses the payload
1568
- * directly, and the streaming aggregator (next step) rebuilds this same
1569
- * payload shape from deltas before calling it.
1657
+ * directly, and the streaming aggregator (create_chat_stream_aggregator)
1658
+ * rebuilds this same payload shape from deltas before calling it.
1570
1659
  */
1571
1660
  function parse_chat_completion(payload, dialect) {
1572
1661
  if (payload === null || typeof payload !== "object") throw new provider_error(`${dialect.name} native: response payload is not a JSON object`);
@@ -2240,10 +2329,12 @@ function create_ndjson_decoder() {
2240
2329
  * each call dispatches tool_call_start then tool_call_end with no input
2241
2330
  * deltas between. The `done: true` frame carries done_reason and the eval
2242
2331
  * counts and closes the turn (step_finish); frames after it are ignored. A
2243
- * stream that ends without one is truncated output, so complete() fails
2244
- * loud instead of returning a partial turn. complete() feeds the synthetic
2245
- * payload through parse_ollama_chat, which is what makes the streamed
2246
- * TurnResult equal the non-streamed one by construction.
2332
+ * frame whose top-level `error` is a string is the daemon failing mid-stream
2333
+ * and throws with its message. A stream that ends without a done frame is
2334
+ * truncated output, so complete() fails loud instead of returning a partial
2335
+ * turn. complete() feeds the synthetic payload through parse_ollama_chat,
2336
+ * which is what makes the streamed TurnResult equal the non-streamed one by
2337
+ * construction.
2247
2338
  */
2248
2339
  function create_ollama_stream_aggregator(step_index, dispatch) {
2249
2340
  let text = "";
@@ -2294,6 +2385,8 @@ function create_ollama_stream_aggregator(step_index, dispatch) {
2294
2385
  throw new provider_error("ollama native: stream frame is not valid JSON");
2295
2386
  }
2296
2387
  if (frame === null || typeof frame !== "object") return;
2388
+ const error = Reflect.get(frame, "error");
2389
+ if (typeof error === "string") throw new provider_error(`ollama native: the daemon reported an error mid-stream: ${error}`);
2297
2390
  const message = Reflect.get(frame, "message");
2298
2391
  if (message !== null && message !== void 0 && typeof message === "object") await on_message(message);
2299
2392
  if (Reflect.get(frame, "done") === true) {
@@ -2472,7 +2565,8 @@ const create_lmstudio_native_adapter = (init) => {
2472
2565
  token_limit_field: "max_tokens",
2473
2566
  stream_include_usage: true,
2474
2567
  tolerant_usage: true,
2475
- reports_cost: false
2568
+ reports_cost: false,
2569
+ clamp_effort: true
2476
2570
  });
2477
2571
  };
2478
2572
  /**
@@ -3082,6 +3176,7 @@ function create_spawn_runtime() {
3082
3176
  install_exit_handler_once();
3083
3177
  const spawn_cli = async (args) => {
3084
3178
  if (args.abort?.aborted === true) throw new aborted_error("aborted", { reason: args.abort.reason });
3179
+ const spawn_failure_reason = args.spawn_failure_reason ?? "binary_not_found";
3085
3180
  let child;
3086
3181
  try {
3087
3182
  const spawn_opts = {
@@ -3098,7 +3193,7 @@ function create_spawn_runtime() {
3098
3193
  child = spawn(args.cmd, [...args.argv], spawn_opts);
3099
3194
  } catch (err) {
3100
3195
  const message = err instanceof Error ? err.message : String(err);
3101
- throw new claude_cli_error("binary_not_found", `failed to spawn '${args.cmd}': ${message}`);
3196
+ throw new claude_cli_error(spawn_failure_reason, `failed to spawn '${args.cmd}': ${message}`);
3102
3197
  }
3103
3198
  live_children.add(child);
3104
3199
  let spawn_error;
@@ -3193,7 +3288,7 @@ function create_spawn_runtime() {
3193
3288
  const outcome = await close_promise;
3194
3289
  if (spawn_error !== void 0) {
3195
3290
  const message = spawn_error.message;
3196
- throw new claude_cli_error("binary_not_found", message);
3291
+ throw new claude_cli_error(spawn_failure_reason, message);
3197
3292
  }
3198
3293
  if (startup_error !== void 0) throw startup_error;
3199
3294
  if (stall_error !== void 0) throw stall_error;
@@ -3490,18 +3585,26 @@ function create_parser_state() {
3490
3585
  * `cache_read_input_tokens` maps to `cached_input_tokens` and
3491
3586
  * `cache_creation_input_tokens` maps to `cache_write_tokens`; both are
3492
3587
  * omitted when the CLI didn't report them.
3588
+ *
3589
+ * The CLI reports `input_tokens` exclusive of its cache reads and writes, as
3590
+ * the Messages API does, while `UsageTotals.input_tokens` is inclusive and
3591
+ * cost decomposition subtracts both back out to find the fresh input. So the
3592
+ * inclusive total is the sum of all three; a straight copy would leave fresh
3593
+ * input with too small a share of a reported cost.
3493
3594
  */
3494
3595
  function map_usage(raw) {
3495
3596
  if (raw === void 0) return {
3496
3597
  input_tokens: 0,
3497
3598
  output_tokens: 0
3498
3599
  };
3600
+ const cache_read = raw.cache_read_input_tokens;
3601
+ const cache_write = raw.cache_creation_input_tokens;
3499
3602
  const out = {
3500
- input_tokens: typeof raw.input_tokens === "number" ? raw.input_tokens : 0,
3501
- output_tokens: typeof raw.output_tokens === "number" ? raw.output_tokens : 0
3603
+ input_tokens: (raw.input_tokens ?? 0) + (cache_read ?? 0) + (cache_write ?? 0),
3604
+ output_tokens: raw.output_tokens ?? 0
3502
3605
  };
3503
- if (typeof raw.cache_read_input_tokens === "number") out.cached_input_tokens = raw.cache_read_input_tokens;
3504
- if (typeof raw.cache_creation_input_tokens === "number") out.cache_write_tokens = raw.cache_creation_input_tokens;
3606
+ if (cache_read !== void 0) out.cached_input_tokens = cache_read;
3607
+ if (cache_write !== void 0) out.cache_write_tokens = cache_write;
3505
3608
  return out;
3506
3609
  }
3507
3610
  /**
@@ -3926,7 +4029,7 @@ function normalize_turns(parsed) {
3926
4029
  * `duration_ms` is always 0: the CLI's stream-json events don't report
3927
4030
  * per-tool-call timing, so there's nothing to measure it against.
3928
4031
  */
3929
- function tool_call_record(step_index, call, results, now) {
4032
+ function tool_call_record(call, results, now) {
3930
4033
  const rec = {
3931
4034
  id: call.id,
3932
4035
  name: call.name,
@@ -3996,7 +4099,7 @@ function build_generate_result(input) {
3996
4099
  const steps = [];
3997
4100
  const tool_calls_accum = [];
3998
4101
  turns.forEach((turn, i) => {
3999
- const step_tool_calls = turn.tool_calls.map((call) => tool_call_record(turn.step_index, call, turn.tool_results, now));
4102
+ const step_tool_calls = turn.tool_calls.map((call) => tool_call_record(call, turn.tool_results, now));
4000
4103
  for (const tc of step_tool_calls) tool_calls_accum.push(tc);
4001
4104
  const record = {
4002
4105
  index: turn.step_index,
@@ -4022,7 +4125,7 @@ function build_generate_result(input) {
4022
4125
  ...parsed.duration_api_ms !== void 0 ? { duration_api_ms: parsed.duration_api_ms } : {}
4023
4126
  };
4024
4127
  const result = {
4025
- content: input.parsed_content ?? parsed.final_text,
4128
+ content: input.schema === void 0 ? parsed.final_text : input.parsed_content,
4026
4129
  tool_calls: tool_calls_accum,
4027
4130
  steps,
4028
4131
  usage: total_usage,
@@ -4476,6 +4579,7 @@ const SUPPORTED = /* @__PURE__ */ new Set([
4476
4579
  "reasoning"
4477
4580
  ]);
4478
4581
  const PROVIDER_NAME = "claude_cli";
4582
+ const BWRAP_EXEC_MISSING = /^bwrap: execvp (.+): No such file or directory$/m;
4479
4583
  const CLAUDE_CLI_EFFORT_VALUES = {
4480
4584
  low: "low",
4481
4585
  medium: "medium",
@@ -4558,13 +4662,20 @@ function compile_schema(schema) {
4558
4662
  * Turn a closed CLI subprocess's exit code, signal, and stderr into an
4559
4663
  * `Error`.
4560
4664
  *
4561
- * Checks stderr for an auth failure first, then for a missing sandbox
4562
- * binary, then falls back to a generic exit-code error. The stderr
4665
+ * Checks stderr for an auth failure first, then for a claude binary that
4666
+ * bwrap started but couldn't find inside its sandbox, then for a missing
4667
+ * sandbox binary, then falls back to a generic exit-code error. The stderr
4563
4668
  * snippet attached to each error is truncated to 512 bytes.
4669
+ *
4670
+ * The bwrap check has to come before the sandbox check: bwrap's own
4671
+ * "execvp <binary>: No such file or directory" names bwrap and says the file
4672
+ * is missing, so the sandbox check would blame bwrap for the claude binary.
4564
4673
  */
4565
4674
  function classify_close_error(code, signal, stderr) {
4566
4675
  const snippet = stderr.slice(0, 512);
4567
4676
  if (stderr_is_auth_failure(stderr)) return new provider_auth_error(PROVIDER_NAME, `claude CLI reported an auth failure: ${snippet}`, { refresh_command: "claude login" });
4677
+ const sandboxed_binary = BWRAP_EXEC_MISSING.exec(stderr)?.[1];
4678
+ if (sandboxed_binary !== void 0) return new claude_cli_error("binary_not_found", `bwrap ran but found no claude binary at '${sandboxed_binary}' inside its sandbox, which binds only /usr, /bin, /lib, /lib64, and additional_write_paths: ${snippet}`, { stderr_snippet: snippet });
4568
4679
  if (/bwrap|greywall|sandbox/i.test(stderr) && /not found|no such file|enoent/i.test(stderr)) return new claude_cli_error("sandbox_unavailable", `sandbox binary unavailable: ${snippet}`, { stderr_snippet: snippet });
4569
4680
  const status = typeof code === "number" ? code : void 0;
4570
4681
  const signal_part = signal !== null ? ` (signal ${signal})` : "";
@@ -4586,24 +4697,24 @@ function classify_close_error(code, signal, stderr) {
4586
4697
  async function run_cli(spawn_runtime, args) {
4587
4698
  const argv = build_cli_argv({
4588
4699
  model_id: args.model_id,
4589
- provider_config: {},
4700
+ provider_config: args.provider_config,
4590
4701
  call_opts: args.call_opts,
4591
4702
  merged_allowed_tools: args.merged_allowed_tools,
4592
4703
  merged_system: args.merged_system,
4593
4704
  ...args.compiled_schema !== void 0 ? { compiled_schema: args.compiled_schema } : {}
4594
4705
  });
4595
4706
  const full_argv = [...args.prefix_args, ...argv];
4596
- const spawn_args = {
4707
+ const session = await spawn_runtime.spawn_cli({
4597
4708
  cmd: args.spawn_cmd,
4598
4709
  argv: full_argv,
4599
4710
  env: args.env,
4600
4711
  stdin: args.stdin_text,
4601
4712
  startup_timeout_ms: args.startup_timeout_ms,
4602
- stall_timeout_ms: args.stall_timeout_ms
4603
- };
4604
- if (args.cwd !== void 0) spawn_args.cwd = args.cwd;
4605
- if (args.abort !== void 0) spawn_args.abort = args.abort;
4606
- const session = await spawn_runtime.spawn_cli(spawn_args);
4713
+ stall_timeout_ms: args.stall_timeout_ms,
4714
+ ...args.cwd !== void 0 ? { cwd: args.cwd } : {},
4715
+ ...args.abort !== void 0 ? { abort: args.abort } : {},
4716
+ ...args.provider_config.sandbox !== void 0 ? { spawn_failure_reason: "sandbox_unavailable" } : {}
4717
+ });
4607
4718
  const state = create_parser_state();
4608
4719
  const chunks = [];
4609
4720
  const consume = (async () => {
@@ -4897,6 +5008,7 @@ function create_claude_cli_adapter(init) {
4897
5008
  const spans = open_spans(trajectory, opts, resolved, tools_list.length > 0, dispatch_chunk !== void 0);
4898
5009
  const base_args = {
4899
5010
  model_id: resolved.model_id,
5011
+ provider_config: config,
4900
5012
  stdin_text: extract_prompt_text(opts.prompt),
4901
5013
  merged_system,
4902
5014
  merged_allowed_tools,
@@ -6078,7 +6190,7 @@ async function execute_approved_call(ctx, tool, input, raw_call) {
6078
6190
  err_message = serialize_error(err);
6079
6191
  }
6080
6192
  const duration_ms = Date.now() - started_at;
6081
- if (thrown !== void 0) {
6193
+ if (err_message !== void 0) {
6082
6194
  await record_execute_failure(ctx, tool, raw_call, input, {
6083
6195
  thrown,
6084
6196
  err_message,
@@ -6708,7 +6820,7 @@ async function build_ai_sdk_transport(cfg) {
6708
6820
  const provider_options = combined_provider_options !== void 0 && Object.keys(combined_provider_options).length > 0 ? combined_provider_options : void 0;
6709
6821
  let ai_sdk_invoke_mod;
6710
6822
  try {
6711
- ai_sdk_invoke_mod = await import("./invoke-px31fffH.js");
6823
+ ai_sdk_invoke_mod = await import("./invoke-COaeZ-vy.js");
6712
6824
  } catch (err) {
6713
6825
  throw missing_peer_error("ai", err);
6714
6826
  }
@@ -7016,12 +7128,6 @@ function call_timing(started_at) {
7016
7128
  };
7017
7129
  }
7018
7130
  /**
7019
- * Round `v` to 6 decimal places, the resolution used for the USD cost fields.
7020
- */
7021
- function round6(v) {
7022
- return Math.round(v * 1e6) / 1e6;
7023
- }
7024
- /**
7025
7131
  * Pick the call-level `provider_reported` from the step records: the payload of
7026
7132
  * the last step that reported one.
7027
7133
  *
@@ -7275,4 +7381,4 @@ function create_engine(config) {
7275
7381
  //#endregion
7276
7382
  export { create_engine as t };
7277
7383
 
7278
- //# sourceMappingURL=engine-ha9xmgwE.js.map
7384
+ //# sourceMappingURL=engine-CR8q2IqV.js.map