fascicle 0.17.7 → 0.18.0

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 (67) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +25 -2
  3. package/dist/AGENTS.md +23 -11
  4. package/dist/acp.d.ts +3 -17
  5. package/dist/acp.js +25 -44
  6. package/dist/acp.js.map +1 -1
  7. package/dist/{adapters-CDUzZlby.js → adapters-CpKpDk7r.js} +9 -17
  8. package/dist/{adapters-CDUzZlby.js.map → adapters-CpKpDk7r.js.map} +1 -1
  9. package/dist/adapters.d.ts +1 -13
  10. package/dist/adapters.js +1 -1
  11. package/dist/agents.d.ts +3 -5
  12. package/dist/agents.js +2 -3
  13. package/dist/{console-CdB4pcFO.js → console-B1ozi_ii.js} +2 -3
  14. package/dist/{console-CdB4pcFO.js.map → console-B1ozi_ii.js.map} +1 -1
  15. package/dist/{core-Bfzt55Fl.js → core-BH7sWpEG.js} +34 -66
  16. package/dist/{core-Bfzt55Fl.js.map → core-BH7sWpEG.js.map} +1 -1
  17. package/dist/diagram_bin.d.ts +0 -2
  18. package/dist/diagram_bin.js +3 -5
  19. package/dist/diagram_bin.js.map +1 -1
  20. package/dist/{engine-B5iQ3if9.js → engine-fOjYHcv6.js} +302 -98
  21. package/dist/engine-fOjYHcv6.js.map +1 -0
  22. package/dist/index.d.ts +4 -98
  23. package/dist/index.js +27 -47
  24. package/dist/index.js.map +1 -1
  25. package/dist/{invoke-DnmWf8gE.js → invoke-7iu8db6V.js} +19 -12
  26. package/dist/{invoke-DnmWf8gE.js.map → invoke-7iu8db6V.js.map} +1 -1
  27. package/dist/{json_schema_to_standard-C4F4lXHE.js → json_schema_to_standard-BstoXjM8.js} +3 -4
  28. package/dist/{json_schema_to_standard-C4F4lXHE.js.map → json_schema_to_standard-BstoXjM8.js.map} +1 -1
  29. package/dist/{leading_system-CHSYz0h9.js → leading_system-BeQUSAim.js} +6 -10
  30. package/dist/{leading_system-CHSYz0h9.js.map → leading_system-BeQUSAim.js.map} +1 -1
  31. package/dist/{mcp-8mKK7eDY.js → mcp-CHJ88HiG.js} +9 -14
  32. package/dist/{mcp-8mKK7eDY.js.map → mcp-CHJ88HiG.js.map} +1 -1
  33. package/dist/mcp.d.ts +3 -11
  34. package/dist/mcp.js +2 -2
  35. package/dist/otel.d.ts +1 -5
  36. package/dist/otel.js +3 -6
  37. package/dist/otel.js.map +1 -1
  38. package/dist/{records-1HU7mWXf.js → records-Btlmvunj.js} +2 -3
  39. package/dist/{records-1HU7mWXf.js.map → records-Btlmvunj.js.map} +1 -1
  40. package/dist/{search-DjhdMsJ8.js → search-BZagxXtd.js} +7 -11
  41. package/dist/{search-DjhdMsJ8.js.map → search-BZagxXtd.js.map} +1 -1
  42. package/dist/search_worker.js +2 -3
  43. package/dist/stdio.d.ts +2 -6
  44. package/dist/stdio.js +5 -7
  45. package/dist/stdio.js.map +1 -1
  46. package/dist/testing.d.ts +2 -18
  47. package/dist/testing.js +12 -21
  48. package/dist/testing.js.map +1 -1
  49. package/dist/{trajectory-DeURWIhj.js → trajectory-CkCFZWNR.js} +2 -3
  50. package/dist/{trajectory-DeURWIhj.js.map → trajectory-CkCFZWNR.js.map} +1 -1
  51. package/dist/{trajectory-BKGNxi7u.d.ts → trajectory-Dt0-A7kb.d.ts} +1 -3
  52. package/dist/{types-CPqLZOEr.d.ts → types-BUXt_zgJ.d.ts} +1 -3
  53. package/dist/{types-BK0UW28o.d.ts → types-CvghbZ0x.d.ts} +1 -5
  54. package/dist/{types-xYjCEd6i.d.ts → types-Dk9tLpUq.d.ts} +42 -9
  55. package/dist/ui.d.ts +1 -3
  56. package/dist/ui.js +1 -2
  57. package/dist/viewer-app/assets/index-D8Tb3drm.js +4 -0
  58. package/dist/viewer-app/index.html +1 -1
  59. package/dist/viewer.d.ts +1 -11
  60. package/dist/viewer.js +8 -14
  61. package/dist/viewer.js.map +1 -1
  62. package/dist/web.d.ts +83 -0
  63. package/dist/web.js +2888 -0
  64. package/dist/web.js.map +1 -0
  65. package/package.json +34 -28
  66. package/dist/engine-B5iQ3if9.js.map +0 -1
  67. package/dist/viewer-app/assets/index-YrQFld-l.js +0 -4
@@ -2,7 +2,7 @@ import { createHash, randomUUID } from "node:crypto";
2
2
  import { link, mkdir, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
3
3
  import { dirname, join } from "node:path";
4
4
  import { appendFileSync, mkdirSync } from "node:fs";
5
- //#region src/adapters/trajectory_recorder.ts
5
+ // src/adapters/trajectory_recorder.ts
6
6
  /**
7
7
  * Shared span/record core for trajectory loggers.
8
8
  *
@@ -55,8 +55,7 @@ function trajectory_recorder(emit) {
55
55
  end_span
56
56
  };
57
57
  }
58
- //#endregion
59
- //#region src/adapters/line_logger.ts
58
+ // src/adapters/line_logger.ts
60
59
  /**
61
60
  * Create a `TrajectoryLogger` that writes one JSON object per line via
62
61
  * `write_line`.
@@ -64,8 +63,7 @@ function trajectory_recorder(emit) {
64
63
  function line_logger(write_line) {
65
64
  return trajectory_recorder(write_line);
66
65
  }
67
- //#endregion
68
- //#region src/adapters/filesystem_logger.ts
66
+ // src/adapters/filesystem_logger.ts
69
67
  /**
70
68
  * Filesystem JSONL trajectory logger.
71
69
  *
@@ -107,8 +105,7 @@ function report_to_stderr(output_path, err) {
107
105
  const reason = err instanceof Error ? err.message : String(err);
108
106
  process.stderr.write(`filesystem_logger: dropped an event it could not write to ${output_path} (${reason}). Check that the path is a writable file and that every emitted value is JSON-serializable.\n`);
109
107
  }
110
- //#endregion
111
- //#region src/adapters/http_logger.ts
108
+ // src/adapters/http_logger.ts
112
109
  /**
113
110
  * Default `HttpLoggerFetch`, backed by the global `fetch`.
114
111
  */
@@ -146,8 +143,7 @@ function http_logger(config) {
146
143
  };
147
144
  return trajectory_recorder(post);
148
145
  }
149
- //#endregion
150
- //#region src/adapters/noop_logger.ts
146
+ // src/adapters/noop_logger.ts
151
147
  /**
152
148
  * No-op trajectory logger.
153
149
  *
@@ -166,8 +162,7 @@ function noop_logger() {
166
162
  end_span: () => {}
167
163
  };
168
164
  }
169
- //#endregion
170
- //#region src/adapters/stderr_logger.ts
165
+ // src/adapters/stderr_logger.ts
171
166
  /**
172
167
  * Create a `TrajectoryLogger` that writes one JSON object per line to
173
168
  * stderr, or to `options.stream` when supplied.
@@ -180,8 +175,7 @@ function stderr_logger(options = {}) {
180
175
  } catch {}
181
176
  });
182
177
  }
183
- //#endregion
184
- //#region src/adapters/tee_logger.ts
178
+ // src/adapters/tee_logger.ts
185
179
  /**
186
180
  * Create a `TrajectoryLogger` that fans every call out to `loggers`.
187
181
  */
@@ -221,8 +215,7 @@ function tee_logger(...loggers) {
221
215
  }
222
216
  };
223
217
  }
224
- //#endregion
225
- //#region src/adapters/filesystem_store.ts
218
+ // src/adapters/filesystem_store.ts
226
219
  /**
227
220
  * Filesystem-backed checkpoint store.
228
221
  *
@@ -463,7 +456,6 @@ function store_at(root_dir) {
463
456
  function filesystem_store(config) {
464
457
  return store_at(config.root_dir);
465
458
  }
466
- //#endregion
467
459
  export { http_logger as a, noop_logger as i, tee_logger as n, filesystem_logger as o, stderr_logger as r, filesystem_store as t };
468
460
 
469
- //# sourceMappingURL=adapters-CDUzZlby.js.map
461
+ //# sourceMappingURL=adapters-CpKpDk7r.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapters-CDUzZlby.js","names":[],"sources":["../src/adapters/trajectory_recorder.ts","../src/adapters/line_logger.ts","../src/adapters/filesystem_logger.ts","../src/adapters/http_logger.ts","../src/adapters/noop_logger.ts","../src/adapters/stderr_logger.ts","../src/adapters/tee_logger.ts","../src/adapters/filesystem_store.ts"],"sourcesContent":["/**\n * Shared span/record core for trajectory loggers.\n *\n * Every Fascicle trajectory logger emits the same wire format (one JSON object\n * per event) and differs only in where each event goes: `line_logger` writes a\n * line, `http_logger` POSTs NDJSON. This module holds the span bookkeeping they\n * share, parameterized by a single `emit` sink.\n *\n * `start_span` and `end_span` each emit one event; `record` emits the event as\n * written. When the caller supplies `parent_span_id` in the span meta (the\n * runner threads the true structural parent through `RunContext`), that value is\n * used verbatim, so span trees are correct even for concurrent children under\n * `parallel`/`map`. Only when no parent is supplied does the recorder fall back\n * to an in-memory stack of still-open spans, which is best-effort under\n * concurrency.\n */\n\nimport { randomUUID } from 'node:crypto'\nimport type { TrajectoryLogger } from '#core'\n\n/**\n * Build a `TrajectoryLogger` whose events are handed, one at a time, to `emit`.\n */\nexport function trajectory_recorder(\n emit: (event: Record<string, unknown>) => void,\n): TrajectoryLogger {\n const stack: string[] = []\n\n const start_span: TrajectoryLogger['start_span'] = (name, meta) => {\n const span_id = `${name}:${randomUUID().slice(0, 8)}`\n const event: Record<string, unknown> = { kind: 'span_start', span_id, name, ...meta }\n // Prefer the caller-threaded structural parent; fall back to the open-span\n // stack only when none was supplied (best-effort under concurrency).\n if (event['parent_span_id'] === undefined && stack.length > 0) {\n event['parent_span_id'] = stack[stack.length - 1]\n }\n emit(event)\n stack.push(span_id)\n return span_id\n }\n\n const end_span: TrajectoryLogger['end_span'] = (id, meta) => {\n emit({ kind: 'span_end', span_id: id, ...meta })\n const idx = stack.lastIndexOf(id)\n if (idx !== -1) stack.splice(idx, 1)\n }\n\n const record: TrajectoryLogger['record'] = (event) => {\n emit({ ...event })\n }\n\n return { record, start_span, end_span }\n}\n","/**\n * Line-oriented trajectory logger core.\n *\n * `filesystem_logger` and `stderr_logger` emit the same wire format (one JSON\n * object per line) and differ only in where the line goes. Both build on this:\n * `line_logger` adapts the shared span/record core (`trajectory_recorder`) to a\n * `write_line` sink, so the span bookkeeping and `parent_span_id` handling that\n * keep span trees correct under `parallel`/`map` live in exactly one place.\n */\n\nimport type { TrajectoryLogger } from '#core'\nimport { trajectory_recorder } from './trajectory_recorder.js'\n\n/**\n * Create a `TrajectoryLogger` that writes one JSON object per line via\n * `write_line`.\n */\nexport function line_logger(write_line: (event: Record<string, unknown>) => void): TrajectoryLogger {\n return trajectory_recorder(write_line)\n}\n","/**\n * Filesystem JSONL trajectory logger.\n *\n * Appends one JSON object per line to a configured output file. Span\n * bookkeeping (including the `parent_span_id` handling that keeps span trees\n * correct for concurrent children under `parallel`/`map`) lives in\n * `line_logger`. Two concurrent `run(...)` calls that pass distinct logger\n * instances (constructed with distinct `output_path`s) share nothing.\n *\n * Failure policy: an event that can't be serialized or appended is dropped\n * and reported, through the optional `on_error` callback or else as one line\n * on stderr. Never throws into the flow, the same as every adapter logger.\n *\n * Paths are accepted at construction; the logger never reads `process.env`.\n */\n\nimport { appendFileSync, mkdirSync } from 'node:fs'\nimport { dirname } from 'node:path'\nimport type { TrajectoryLogger } from '#core'\nimport { line_logger } from './line_logger.js'\n\nexport type FilesystemLoggerConfig = {\n readonly output_path: string\n /**\n * Called with the error when an event can't be serialized or appended.\n * Omitted, each failure writes one `filesystem_logger:` line to stderr.\n * Either way the event is dropped and the flow carries on.\n */\n readonly on_error?: (err: unknown) => void\n}\n\n/**\n * Create a `TrajectoryLogger` that appends one JSON object per line to\n * `output_path`, creating the parent directory if needed.\n */\nexport function filesystem_logger(config: FilesystemLoggerConfig): TrajectoryLogger {\n const { output_path } = config\n const report = config.on_error ?? ((err: unknown) => report_to_stderr(output_path, err))\n mkdirSync(dirname(output_path), { recursive: true })\n\n return line_logger((event) => {\n try {\n appendFileSync(output_path, `${JSON.stringify(event)}\\n`)\n } catch (err: unknown) {\n try {\n report(err)\n } catch {\n // A reporter that throws is dropped too: the flow always wins.\n }\n }\n })\n}\n\n/**\n * The default reporter: one stderr line that names the file and the reason\n * an event was dropped.\n */\nfunction report_to_stderr(output_path: string, err: unknown): void {\n const reason = err instanceof Error ? err.message : String(err)\n process.stderr.write(\n `filesystem_logger: dropped an event it could not write to ${output_path} (${reason}). Check that the path is a writable file and that every emitted value is JSON-serializable.\\n`,\n )\n}\n","/**\n * HTTP push trajectory logger.\n *\n * Conforms to `TrajectoryLogger`. POSTs each event as a single line of\n * newline-delimited JSON to a configured URL. Pairs naturally with the\n * Fascicle viewer's `/api/ingest` endpoint, but is a generic adapter: the\n * receiver can be anything that accepts NDJSON over HTTP.\n *\n * Failure policy: drop on transport error and invoke the optional `on_error`\n * callback. Never throws, never blocks the user's flow on a dev tool being\n * up. The flow always wins; the viewer is best-effort.\n *\n * Span bookkeeping (including the `parent_span_id` handling that mirrors\n * `filesystem_logger` so the wire format is identical) lives in the shared\n * `trajectory_recorder`; this adapter only supplies the emit sink.\n */\n\nimport type { TrajectoryLogger } from '#core'\nimport { trajectory_recorder } from './trajectory_recorder.js'\n\nexport type HttpLoggerFetch = (\n url: string,\n init: { method: 'POST'; headers: Record<string, string>; body: string },\n) => Promise<{ ok: boolean; status: number }>\n\nexport type HttpLoggerConfig = {\n readonly url: string\n readonly fetch?: HttpLoggerFetch\n readonly on_error?: (err: unknown) => void\n}\n\n/**\n * Default `HttpLoggerFetch`, backed by the global `fetch`.\n */\nconst default_fetch: HttpLoggerFetch = async (url, init) => {\n const res = await fetch(url, init)\n return { ok: res.ok, status: res.status }\n}\n\n/**\n * Create a `TrajectoryLogger` that POSTs each event as NDJSON to\n * `config.url`.\n *\n * Never throws: a transport failure, an event JSON can't serialize, and a\n * custom `fetch` that throws are each dropped and reported through the\n * optional `on_error` callback, so a dev viewer being unreachable never\n * blocks the flow.\n */\nexport function http_logger(config: HttpLoggerConfig): TrajectoryLogger {\n const { url, on_error } = config\n const send = config.fetch ?? default_fetch\n\n const post = (event: Record<string, unknown>): void => {\n // The executor serializes the event as it is now, and a throw there or\n // in `send` rejects into the catch below rather than into the flow.\n void new Promise<string>((resolve) => {\n resolve(`${JSON.stringify(event)}\\n`)\n })\n .then(async (body) =>\n send(url, {\n method: 'POST',\n headers: { 'content-type': 'application/x-ndjson' },\n body,\n }),\n )\n .then((res) => {\n if (!res.ok && on_error) on_error(new Error(`http_logger: POST ${url} -> ${res.status}`))\n })\n .catch((err: unknown) => {\n if (on_error) on_error(err)\n })\n }\n\n return trajectory_recorder(post)\n}\n","/**\n * No-op trajectory logger.\n *\n * Satisfies `TrajectoryLogger` from `core` without emitting any\n * output. A caller passes it where a logger is required and nothing should be\n * recorded, such as a test that does not care about trajectory output.\n * `run(...)` keeps its own private no-op for a run given no logger.\n */\n\nimport { randomUUID } from 'node:crypto'\nimport type { TrajectoryLogger } from '#core'\n\n/**\n * Create a `TrajectoryLogger` whose methods do nothing.\n */\nexport function noop_logger(): TrajectoryLogger {\n return {\n record: () => {},\n start_span: (name) => `${name}:${randomUUID().slice(0, 8)}`,\n end_span: () => {},\n }\n}\n","/**\n * Stderr JSONL trajectory logger.\n *\n * Writes one JSON object per line to stderr (or an injected stream), leaving\n * stdout untouched. This is the blessed console logger for agents that run as\n * somebody's child process: under the stdio agent contract, stdout carries the\n * result envelope and belongs to the parent, so trajectory must go elsewhere.\n * The wire format is identical to `filesystem_logger`, so captured stderr is a\n * valid trajectory JSONL file (`2>events.jsonl`) the viewer parses unchanged.\n *\n * Writes never throw: a broken pipe or closed stream drops the event rather\n * than failing the flow.\n */\n\nimport type { TrajectoryLogger } from '#core'\nimport { line_logger } from './line_logger.js'\n\nexport type StderrLoggerOptions = {\n readonly stream?: { write(chunk: string): unknown }\n}\n\n/**\n * Create a `TrajectoryLogger` that writes one JSON object per line to\n * stderr, or to `options.stream` when supplied.\n */\nexport function stderr_logger(options: StderrLoggerOptions = {}): TrajectoryLogger {\n const stream = options.stream ?? process.stderr\n return line_logger((event) => {\n try {\n stream.write(`${JSON.stringify(event)}\\n`)\n } catch {\n // Never throw from a logger; the flow always wins.\n }\n })\n}\n","/**\n * tee_logger: fan one TrajectoryLogger contract out to many sinks.\n *\n * Each sink receives every record/start_span/end_span call. Sinks are called\n * in registration order and exceptions in one sink do not prevent the others\n * from receiving the event.\n *\n * The id from the first sink whose `start_span` returns is canonical and goes\n * back to the caller, or `<name>:tee` when every sink throws. The tee\n * remembers each sink's own id by its position, so that\n * `end_span(canonical_id, ...)` translates back to the right id for each sink,\n * and a sink that threw on `start_span` gets the canonical id. Within any one\n * sink the wire format stays internally consistent; only the across-sink ids\n * may differ.\n */\n\nimport type { TrajectoryLogger } from '#core'\n\n/**\n * Create a `TrajectoryLogger` that fans every call out to `loggers`.\n */\nexport function tee_logger(...loggers: ReadonlyArray<TrajectoryLogger>): TrajectoryLogger {\n if (loggers.length === 0) {\n throw new Error(\n 'tee_logger needs at least one logger: pass the sinks to fan out to, as in `tee_logger(stderr_logger(), http_logger(config))`',\n )\n }\n\n const id_map = new Map<string, ReadonlyArray<string | undefined>>()\n\n const safe_each = (fn: (l: TrajectoryLogger, idx: number) => void): void => {\n for (let i = 0; i < loggers.length; i += 1) {\n const l = loggers[i]\n if (l === undefined) continue\n try {\n fn(l, i)\n } catch {\n // best-effort fan-out: a misbehaving sink must not derail the others\n }\n }\n }\n\n return {\n record: (event) => {\n safe_each((l) => l.record(event))\n },\n start_span: (name, meta) => {\n const ids: Array<string | undefined> = loggers.map(() => undefined)\n safe_each((l, idx) => {\n ids[idx] = l.start_span(name, meta)\n })\n const canonical = ids.find((sink_id) => sink_id !== undefined) ?? `${name}:tee`\n if (loggers.length > 1) id_map.set(canonical, ids)\n return canonical\n },\n end_span: (id, meta) => {\n const ids = id_map.get(id)\n if (ids === undefined) {\n safe_each((l) => l.end_span(id, meta))\n return\n }\n id_map.delete(id)\n safe_each((l, idx) => l.end_span(ids[idx] ?? id, meta))\n },\n }\n}\n","/**\n * Filesystem-backed checkpoint store.\n *\n * Satisfies `CheckpointStore` from `core`, every optional capability\n * included. Each key is stored as\n * a JSON file under the configured root directory. Writes are all-or-nothing:\n * values are written to a temporary sibling file and then atomically renamed\n * into place, so an interrupted write never leaves a partially written file\n * at the target key. On `get`, a missing file, a partial temp file that was\n * never atomically renamed, or a JSON parse failure each read as a cache\n * miss (returning `null`) rather than an error. Any other failure to read\n * (a permission error, a failing disk) surfaces, because reading it as a miss\n * could start a durable run over, or hand a live claim to a second owner.\n *\n * A scope is a directory beside the values (`<prefix>.scope/`), which makes\n * `clear` one recursive delete. A claim is a directory of numbered\n * generations (`<key>.claim/<n>.json`), and the newest one is the claim. A\n * claimer takes a free or expired key by creating the next generation with\n * `link`, which makes the file appear whole and refuses a target that\n * already exists, so two claimers can't both create it. Taking an expired\n * claim never overwrites a live one, which a rename into place couldn't\n * promise, and a claimer that finds a newer generation than its own has lost.\n * All of this leans on `link` and `rename` being atomic and on a directory\n * listing being current, which a local filesystem gives and a network\n * filesystem may not.\n *\n * Paths are accepted at construction; the store never reads `process.env`.\n */\n\nimport { createHash, randomUUID } from 'node:crypto'\nimport { link, mkdir, readdir, readFile, rename, rm, writeFile } from 'node:fs/promises'\nimport { join } from 'node:path'\n\nexport type FilesystemStoreConfig = {\n readonly root_dir: string\n}\n\n/**\n * What `filesystem_store` returns: a `CheckpointStore` with every optional\n * capability, which is what `durable` needs from its store.\n */\nexport type FilesystemStore = {\n readonly get: (key: string) => Promise<unknown>\n readonly set: (key: string, value: unknown) => Promise<void>\n readonly delete: (key: string) => Promise<void>\n readonly scope: (prefix: string) => FilesystemScopedStore\n readonly claim: (key: string, owner: string, ttl_ms: number) => Promise<boolean>\n readonly release: (key: string, owner: string) => Promise<void>\n}\n\n/**\n * A scope of a `filesystem_store`, which can also `clear`.\n */\nexport type FilesystemScopedStore = FilesystemStore & {\n readonly clear: () => Promise<void>\n}\n\ntype ClaimRecord = {\n readonly owner: string\n readonly expires_at: number\n}\n\n/**\n * Turn a key or a scope prefix into a filesystem-safe name.\n *\n * Slugs it down to `[a-zA-Z0-9._-]` and appends a short hash of the whole\n * string, so two strings that slug alike still land on distinct names.\n */\nfunction safe_name(key: string): string {\n const hash = createHash('sha256').update(key).digest('hex').slice(0, 12)\n const slug = key.replace(/[^a-zA-Z0-9._-]/g, '_').slice(0, 64)\n return `${slug}.${hash}`\n}\n\n/**\n * Read the `code` a Node filesystem error carries, if it has one.\n */\nfunction error_code(err: unknown): unknown {\n return err instanceof Error ? Reflect.get(err, 'code') : undefined\n}\n\n/**\n * Serialize a value for disk. A value JSON has no text for (`undefined`, a\n * bare function) is written as `null`, which reads back as a miss.\n */\nfunction to_json(value: unknown): string {\n const text: string | undefined = JSON.stringify(value)\n return text ?? 'null'\n}\n\n/**\n * Write `value` to `path` through a temporary sibling and a rename, so a\n * reader sees the old file or the new one and never a torn one.\n */\nasync function write_atomic(path: string, value: unknown): Promise<void> {\n // Stryker disable next-line MethodExpression: the temporary name only has to be unique, which the whole UUID is as well.\n const tmp = `${path}.${randomUUID().slice(0, 8)}.tmp`\n await writeFile(tmp, to_json(value))\n await rename(tmp, path)\n}\n\n/**\n * Create `path` holding `value` unless something is already there.\n *\n * The JSON goes to a temporary file first and is hard-linked into place, so\n * the file appears whole, and `link` refuses an existing target, so exactly\n * one of several racing creators sees true.\n */\nasync function create_exclusive(path: string, value: unknown): Promise<boolean> {\n // Stryker disable next-line MethodExpression: the temporary name only has to be unique, which the whole UUID is as well.\n const tmp = `${path}.${randomUUID().slice(0, 8)}.tmp`\n await writeFile(tmp, to_json(value))\n try {\n await link(tmp, path)\n return true\n } catch (err) {\n if (error_code(err) === 'EEXIST') return false\n throw err\n } finally {\n await rm(tmp)\n }\n}\n\n/**\n * The path of one generation in a claim directory.\n */\nfunction generation_path(dir: string, generation: number): string {\n return join(dir, `${generation}.json`)\n}\n\n/**\n * The newest generation in a claim directory, or 0 when it holds none or\n * doesn't exist yet.\n */\nasync function latest_generation(dir: string): Promise<number> {\n return Math.max(0, ...(await generations(dir)))\n}\n\n/**\n * Every generation number present in a claim directory.\n */\nasync function generations(dir: string): Promise<number[]> {\n let names: string[]\n try {\n names = await readdir(dir)\n } catch (err) {\n if (error_code(err) === 'ENOENT') return []\n throw err\n }\n return names.flatMap((name) => {\n const match = /^(\\d+)\\.json$/.exec(name)\n return match === null ? [] : [Number(match[1])]\n })\n}\n\n/**\n * Read and parse the JSON at `path`, or `null` when the file is missing or\n * doesn't parse. Any other failure surfaces.\n */\nasync function read_json(path: string): Promise<unknown> {\n let raw: string\n try {\n // Stryker disable next-line StringLiteral: without an encoding readFile hands back a Buffer, which JSON.parse turns into the same text before parsing.\n raw = await readFile(path, 'utf8')\n } catch (err) {\n if (error_code(err) === 'ENOENT') return null\n throw err\n }\n try {\n return JSON.parse(raw) as unknown\n } catch {\n return null\n }\n}\n\n/**\n * Read the claim one generation holds, or null when the file is gone or\n * doesn't hold a claim.\n */\nasync function read_claim(path: string): Promise<ClaimRecord | null> {\n const parsed = await read_json(path)\n return is_claim_record(parsed) ? parsed : null\n}\n\n/**\n * True for the `{ owner, expires_at }` shape a generation file holds.\n */\nfunction is_claim_record(value: unknown): value is ClaimRecord {\n // Stryker disable next-line BooleanLiteral: a value that isn't an object reads as free either way, since null fails the null check and a primitive has no expiry to keep it live.\n if (typeof value !== 'object' || value === null) return false\n return (\n typeof Reflect.get(value, 'owner') === 'string' &&\n typeof Reflect.get(value, 'expires_at') === 'number'\n )\n}\n\n/**\n * Delete every generation older than `keep`. A claimer only reads the newest\n * generation, so the older ones are history and nothing waits on them.\n */\nasync function prune(dir: string, keep: number): Promise<void> {\n const stale = (await generations(dir)).filter((generation) => generation < keep)\n await Promise.all(stale.map((generation) => rm(generation_path(dir, generation), { force: true })))\n}\n\n/**\n * Take or renew the claim in `dir` for `owner`.\n *\n * A live claim held by `owner` is renewed in place. Anything else that isn't\n * a live claim is taken by creating the next generation, and the claimer\n * still loses if a newer generation shows up before it confirms. Only a live\n * claim is ever renewed in place, so an expired one changes hands through\n * `create_exclusive` alone and two claimers can't both win it. A renewal that\n * lands at the very instant its claim expires can still race a takeover, and\n * it loses whenever the takeover's generation appears before it confirms.\n */\nasync function claim_in(dir: string, owner: string, ttl_ms: number): Promise<boolean> {\n await mkdir(dir, { recursive: true })\n const generation = await latest_generation(dir)\n const current = await read_claim(generation_path(dir, generation))\n const now = Date.now()\n const claim: ClaimRecord = { owner, expires_at: now + ttl_ms }\n if (current !== null && current.expires_at > now) {\n if (current.owner !== owner) return false\n await write_atomic(generation_path(dir, generation), claim)\n return (await latest_generation(dir)) === generation\n }\n const next = generation + 1\n if (!(await create_exclusive(generation_path(dir, next), claim))) return false\n if ((await latest_generation(dir)) !== next) return false\n await prune(dir, next)\n return true\n}\n\n/**\n * Release the claim in `dir` when `owner` holds it.\n *\n * The newest generation is rewritten as expired rather than deleted, so\n * generation numbers only ever grow and a slow claimer can't recreate one\n * that was already taken. A directory that vanished meanwhile (its scope was\n * cleared) has nothing left to release.\n */\nasync function release_in(dir: string, owner: string): Promise<void> {\n const generation = await latest_generation(dir)\n const path = generation_path(dir, generation)\n const current = await read_claim(path)\n if (current?.owner !== owner) return\n try {\n await write_atomic(path, { owner, expires_at: 0 })\n } catch (err) {\n if (error_code(err) !== 'ENOENT') throw err\n }\n}\n\n/**\n * Build the store rooted at `root_dir`, scopes and claims included.\n */\nfunction store_at(root_dir: string): FilesystemStore {\n const value_path = (key: string): string => join(root_dir, `${safe_name(key)}.json`)\n const claim_dir = (key: string): string => join(root_dir, `${safe_name(key)}.claim`)\n\n const get = (key: string): Promise<unknown> => read_json(value_path(key))\n\n const set = async (key: string, value: unknown): Promise<void> => {\n await mkdir(root_dir, { recursive: true })\n await write_atomic(value_path(key), value)\n }\n\n const delete_key = async (key: string): Promise<void> => {\n await rm(value_path(key), { force: true })\n }\n\n const scope = (prefix: string): FilesystemScopedStore => {\n const dir = join(root_dir, `${safe_name(prefix)}.scope`)\n return {\n ...store_at(dir),\n clear: () => rm(dir, { recursive: true, force: true }),\n }\n }\n\n return {\n get,\n set,\n delete: delete_key,\n scope,\n claim: (key, owner, ttl_ms) => claim_in(claim_dir(key), owner, ttl_ms),\n release: (key, owner) => release_in(claim_dir(key), owner),\n }\n}\n\n/**\n * Create a `CheckpointStore` backed by JSON files under `config.root_dir`.\n */\nexport function filesystem_store(config: FilesystemStoreConfig): FilesystemStore {\n return store_at(config.root_dir)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBACd,MACkB;CAClB,MAAM,QAAkB,CAAC;CAEzB,MAAM,cAA8C,MAAM,SAAS;EACjE,MAAM,UAAU,GAAG,KAAK,GAAG,WAAW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kBAAkB,GAAG,CACF;CAE5C,KAAI,MADkB,WAAW,IAAI,EAAA,EACxB,UAAU,OAAO;CAC9B,IAAI;EACF,MAAM,aAAa,MAAM;GAAE;GAAO,YAAY;EAAE,CAAC;CACnD,SAAS,KAAK;EACZ,IAAI,WAAW,GAAG,MAAM,UAAU,MAAM;CAC1C;AACF;;;;AAKA,SAAS,SAAS,UAAmC;CACnD,MAAM,cAAc,QAAwB,KAAK,UAAU,GAAG,UAAU,GAAG,EAAE,MAAM;CACnF,MAAM,aAAa,QAAwB,KAAK,UAAU,GAAG,UAAU,GAAG,EAAE,OAAO;CAEnF,MAAM,OAAO,QAAkC,UAAU,WAAW,GAAG,CAAC;CAExE,MAAM,MAAM,OAAO,KAAa,UAAkC;EAChE,MAAM,MAAM,UAAU,EAAE,WAAW,KAAK,CAAC;EACzC,MAAM,aAAa,WAAW,GAAG,GAAG,KAAK;CAC3C;CAEA,MAAM,aAAa,OAAO,QAA+B;EACvD,MAAM,GAAG,WAAW,GAAG,GAAG,EAAE,OAAO,KAAK,CAAC;CAC3C;CAEA,MAAM,SAAS,WAA0C;EACvD,MAAM,MAAM,KAAK,UAAU,GAAG,UAAU,MAAM,EAAE,OAAO;EACvD,OAAO;GACL,GAAG,SAAS,GAAG;GACf,aAAa,GAAG,KAAK;IAAE,WAAW;IAAM,OAAO;GAAK,CAAC;EACvD;CACF;CAEA,OAAO;EACL;EACA;EACA,QAAQ;EACR;EACA,QAAQ,KAAK,OAAO,WAAW,SAAS,UAAU,GAAG,GAAG,OAAO,MAAM;EACrE,UAAU,KAAK,UAAU,WAAW,UAAU,GAAG,GAAG,KAAK;CAC3D;AACF;;;;AAKA,SAAgB,iBAAiB,QAAgD;CAC/E,OAAO,SAAS,OAAO,QAAQ;AACjC"}
1
+ {"version":3,"file":"adapters-CpKpDk7r.js","names":[],"sources":["../src/adapters/trajectory_recorder.ts","../src/adapters/line_logger.ts","../src/adapters/filesystem_logger.ts","../src/adapters/http_logger.ts","../src/adapters/noop_logger.ts","../src/adapters/stderr_logger.ts","../src/adapters/tee_logger.ts","../src/adapters/filesystem_store.ts"],"sourcesContent":["/**\n * Shared span/record core for trajectory loggers.\n *\n * Every Fascicle trajectory logger emits the same wire format (one JSON object\n * per event) and differs only in where each event goes: `line_logger` writes a\n * line, `http_logger` POSTs NDJSON. This module holds the span bookkeeping they\n * share, parameterized by a single `emit` sink.\n *\n * `start_span` and `end_span` each emit one event; `record` emits the event as\n * written. When the caller supplies `parent_span_id` in the span meta (the\n * runner threads the true structural parent through `RunContext`), that value is\n * used verbatim, so span trees are correct even for concurrent children under\n * `parallel`/`map`. Only when no parent is supplied does the recorder fall back\n * to an in-memory stack of still-open spans, which is best-effort under\n * concurrency.\n */\n\nimport { randomUUID } from 'node:crypto'\nimport type { TrajectoryLogger } from '#core'\n\n/**\n * Build a `TrajectoryLogger` whose events are handed, one at a time, to `emit`.\n */\nexport function trajectory_recorder(\n emit: (event: Record<string, unknown>) => void,\n): TrajectoryLogger {\n const stack: string[] = []\n\n const start_span: TrajectoryLogger['start_span'] = (name, meta) => {\n const span_id = `${name}:${randomUUID().slice(0, 8)}`\n const event: Record<string, unknown> = { kind: 'span_start', span_id, name, ...meta }\n // Prefer the caller-threaded structural parent; fall back to the open-span\n // stack only when none was supplied (best-effort under concurrency).\n if (event['parent_span_id'] === undefined && stack.length > 0) {\n event['parent_span_id'] = stack[stack.length - 1]\n }\n emit(event)\n stack.push(span_id)\n return span_id\n }\n\n const end_span: TrajectoryLogger['end_span'] = (id, meta) => {\n emit({ kind: 'span_end', span_id: id, ...meta })\n const idx = stack.lastIndexOf(id)\n if (idx !== -1) stack.splice(idx, 1)\n }\n\n const record: TrajectoryLogger['record'] = (event) => {\n emit({ ...event })\n }\n\n return { record, start_span, end_span }\n}\n","/**\n * Line-oriented trajectory logger core.\n *\n * `filesystem_logger` and `stderr_logger` emit the same wire format (one JSON\n * object per line) and differ only in where the line goes. Both build on this:\n * `line_logger` adapts the shared span/record core (`trajectory_recorder`) to a\n * `write_line` sink, so the span bookkeeping and `parent_span_id` handling that\n * keep span trees correct under `parallel`/`map` live in exactly one place.\n */\n\nimport type { TrajectoryLogger } from '#core'\nimport { trajectory_recorder } from './trajectory_recorder.js'\n\n/**\n * Create a `TrajectoryLogger` that writes one JSON object per line via\n * `write_line`.\n */\nexport function line_logger(write_line: (event: Record<string, unknown>) => void): TrajectoryLogger {\n return trajectory_recorder(write_line)\n}\n","/**\n * Filesystem JSONL trajectory logger.\n *\n * Appends one JSON object per line to a configured output file. Span\n * bookkeeping (including the `parent_span_id` handling that keeps span trees\n * correct for concurrent children under `parallel`/`map`) lives in\n * `line_logger`. Two concurrent `run(...)` calls that pass distinct logger\n * instances (constructed with distinct `output_path`s) share nothing.\n *\n * Failure policy: an event that can't be serialized or appended is dropped\n * and reported, through the optional `on_error` callback or else as one line\n * on stderr. Never throws into the flow, the same as every adapter logger.\n *\n * Paths are accepted at construction; the logger never reads `process.env`.\n */\n\nimport { appendFileSync, mkdirSync } from 'node:fs'\nimport { dirname } from 'node:path'\nimport type { TrajectoryLogger } from '#core'\nimport { line_logger } from './line_logger.js'\n\nexport type FilesystemLoggerConfig = {\n readonly output_path: string\n /**\n * Called with the error when an event can't be serialized or appended.\n * Omitted, each failure writes one `filesystem_logger:` line to stderr.\n * Either way the event is dropped and the flow carries on.\n */\n readonly on_error?: (err: unknown) => void\n}\n\n/**\n * Create a `TrajectoryLogger` that appends one JSON object per line to\n * `output_path`, creating the parent directory if needed.\n */\nexport function filesystem_logger(config: FilesystemLoggerConfig): TrajectoryLogger {\n const { output_path } = config\n const report = config.on_error ?? ((err: unknown) => report_to_stderr(output_path, err))\n mkdirSync(dirname(output_path), { recursive: true })\n\n return line_logger((event) => {\n try {\n appendFileSync(output_path, `${JSON.stringify(event)}\\n`)\n } catch (err: unknown) {\n try {\n report(err)\n } catch {\n // A reporter that throws is dropped too: the flow always wins.\n }\n }\n })\n}\n\n/**\n * The default reporter: one stderr line that names the file and the reason\n * an event was dropped.\n */\nfunction report_to_stderr(output_path: string, err: unknown): void {\n const reason = err instanceof Error ? err.message : String(err)\n process.stderr.write(\n `filesystem_logger: dropped an event it could not write to ${output_path} (${reason}). Check that the path is a writable file and that every emitted value is JSON-serializable.\\n`,\n )\n}\n","/**\n * HTTP push trajectory logger.\n *\n * Conforms to `TrajectoryLogger`. POSTs each event as a single line of\n * newline-delimited JSON to a configured URL. Pairs naturally with the\n * Fascicle viewer's `/api/ingest` endpoint, but is a generic adapter: the\n * receiver can be anything that accepts NDJSON over HTTP.\n *\n * Failure policy: drop on transport error and invoke the optional `on_error`\n * callback. Never throws, never blocks the user's flow on a dev tool being\n * up. The flow always wins; the viewer is best-effort.\n *\n * Span bookkeeping (including the `parent_span_id` handling that mirrors\n * `filesystem_logger` so the wire format is identical) lives in the shared\n * `trajectory_recorder`; this adapter only supplies the emit sink.\n */\n\nimport type { TrajectoryLogger } from '#core'\nimport { trajectory_recorder } from './trajectory_recorder.js'\n\nexport type HttpLoggerFetch = (\n url: string,\n init: { method: 'POST'; headers: Record<string, string>; body: string },\n) => Promise<{ ok: boolean; status: number }>\n\nexport type HttpLoggerConfig = {\n readonly url: string\n readonly fetch?: HttpLoggerFetch\n readonly on_error?: (err: unknown) => void\n}\n\n/**\n * Default `HttpLoggerFetch`, backed by the global `fetch`.\n */\nconst default_fetch: HttpLoggerFetch = async (url, init) => {\n const res = await fetch(url, init)\n return { ok: res.ok, status: res.status }\n}\n\n/**\n * Create a `TrajectoryLogger` that POSTs each event as NDJSON to\n * `config.url`.\n *\n * Never throws: a transport failure, an event JSON can't serialize, and a\n * custom `fetch` that throws are each dropped and reported through the\n * optional `on_error` callback, so a dev viewer being unreachable never\n * blocks the flow.\n */\nexport function http_logger(config: HttpLoggerConfig): TrajectoryLogger {\n const { url, on_error } = config\n const send = config.fetch ?? default_fetch\n\n const post = (event: Record<string, unknown>): void => {\n // The executor serializes the event as it is now, and a throw there or\n // in `send` rejects into the catch below rather than into the flow.\n void new Promise<string>((resolve) => {\n resolve(`${JSON.stringify(event)}\\n`)\n })\n .then(async (body) =>\n send(url, {\n method: 'POST',\n headers: { 'content-type': 'application/x-ndjson' },\n body,\n }),\n )\n .then((res) => {\n if (!res.ok && on_error) on_error(new Error(`http_logger: POST ${url} -> ${res.status}`))\n })\n .catch((err: unknown) => {\n if (on_error) on_error(err)\n })\n }\n\n return trajectory_recorder(post)\n}\n","/**\n * No-op trajectory logger.\n *\n * Satisfies `TrajectoryLogger` from `core` without emitting any\n * output. A caller passes it where a logger is required and nothing should be\n * recorded, such as a test that does not care about trajectory output.\n * `run(...)` keeps its own private no-op for a run given no logger.\n */\n\nimport { randomUUID } from 'node:crypto'\nimport type { TrajectoryLogger } from '#core'\n\n/**\n * Create a `TrajectoryLogger` whose methods do nothing.\n */\nexport function noop_logger(): TrajectoryLogger {\n return {\n record: () => {},\n start_span: (name) => `${name}:${randomUUID().slice(0, 8)}`,\n end_span: () => {},\n }\n}\n","/**\n * Stderr JSONL trajectory logger.\n *\n * Writes one JSON object per line to stderr (or an injected stream), leaving\n * stdout untouched. This is the blessed console logger for agents that run as\n * somebody's child process: under the stdio agent contract, stdout carries the\n * result envelope and belongs to the parent, so trajectory must go elsewhere.\n * The wire format is identical to `filesystem_logger`, so captured stderr is a\n * valid trajectory JSONL file (`2>events.jsonl`) the viewer parses unchanged.\n *\n * Writes never throw: a broken pipe or closed stream drops the event rather\n * than failing the flow.\n */\n\nimport type { TrajectoryLogger } from '#core'\nimport { line_logger } from './line_logger.js'\n\nexport type StderrLoggerOptions = {\n readonly stream?: { write(chunk: string): unknown }\n}\n\n/**\n * Create a `TrajectoryLogger` that writes one JSON object per line to\n * stderr, or to `options.stream` when supplied.\n */\nexport function stderr_logger(options: StderrLoggerOptions = {}): TrajectoryLogger {\n const stream = options.stream ?? process.stderr\n return line_logger((event) => {\n try {\n stream.write(`${JSON.stringify(event)}\\n`)\n } catch {\n // Never throw from a logger; the flow always wins.\n }\n })\n}\n","/**\n * tee_logger: fan one TrajectoryLogger contract out to many sinks.\n *\n * Each sink receives every record/start_span/end_span call. Sinks are called\n * in registration order and exceptions in one sink do not prevent the others\n * from receiving the event.\n *\n * The id from the first sink whose `start_span` returns is canonical and goes\n * back to the caller, or `<name>:tee` when every sink throws. The tee\n * remembers each sink's own id by its position, so that\n * `end_span(canonical_id, ...)` translates back to the right id for each sink,\n * and a sink that threw on `start_span` gets the canonical id. Within any one\n * sink the wire format stays internally consistent; only the across-sink ids\n * may differ.\n */\n\nimport type { TrajectoryLogger } from '#core'\n\n/**\n * Create a `TrajectoryLogger` that fans every call out to `loggers`.\n */\nexport function tee_logger(...loggers: ReadonlyArray<TrajectoryLogger>): TrajectoryLogger {\n if (loggers.length === 0) {\n throw new Error(\n 'tee_logger needs at least one logger: pass the sinks to fan out to, as in `tee_logger(stderr_logger(), http_logger(config))`',\n )\n }\n\n const id_map = new Map<string, ReadonlyArray<string | undefined>>()\n\n const safe_each = (fn: (l: TrajectoryLogger, idx: number) => void): void => {\n for (let i = 0; i < loggers.length; i += 1) {\n const l = loggers[i]\n if (l === undefined) continue\n try {\n fn(l, i)\n } catch {\n // best-effort fan-out: a misbehaving sink must not derail the others\n }\n }\n }\n\n return {\n record: (event) => {\n safe_each((l) => l.record(event))\n },\n start_span: (name, meta) => {\n const ids: Array<string | undefined> = loggers.map(() => undefined)\n safe_each((l, idx) => {\n ids[idx] = l.start_span(name, meta)\n })\n const canonical = ids.find((sink_id) => sink_id !== undefined) ?? `${name}:tee`\n if (loggers.length > 1) id_map.set(canonical, ids)\n return canonical\n },\n end_span: (id, meta) => {\n const ids = id_map.get(id)\n if (ids === undefined) {\n safe_each((l) => l.end_span(id, meta))\n return\n }\n id_map.delete(id)\n safe_each((l, idx) => l.end_span(ids[idx] ?? id, meta))\n },\n }\n}\n","/**\n * Filesystem-backed checkpoint store.\n *\n * Satisfies `CheckpointStore` from `core`, every optional capability\n * included. Each key is stored as\n * a JSON file under the configured root directory. Writes are all-or-nothing:\n * values are written to a temporary sibling file and then atomically renamed\n * into place, so an interrupted write never leaves a partially written file\n * at the target key. On `get`, a missing file, a partial temp file that was\n * never atomically renamed, or a JSON parse failure each read as a cache\n * miss (returning `null`) rather than an error. Any other failure to read\n * (a permission error, a failing disk) surfaces, because reading it as a miss\n * could start a durable run over, or hand a live claim to a second owner.\n *\n * A scope is a directory beside the values (`<prefix>.scope/`), which makes\n * `clear` one recursive delete. A claim is a directory of numbered\n * generations (`<key>.claim/<n>.json`), and the newest one is the claim. A\n * claimer takes a free or expired key by creating the next generation with\n * `link`, which makes the file appear whole and refuses a target that\n * already exists, so two claimers can't both create it. Taking an expired\n * claim never overwrites a live one, which a rename into place couldn't\n * promise, and a claimer that finds a newer generation than its own has lost.\n * All of this leans on `link` and `rename` being atomic and on a directory\n * listing being current, which a local filesystem gives and a network\n * filesystem may not.\n *\n * Paths are accepted at construction; the store never reads `process.env`.\n */\n\nimport { createHash, randomUUID } from 'node:crypto'\nimport { link, mkdir, readdir, readFile, rename, rm, writeFile } from 'node:fs/promises'\nimport { join } from 'node:path'\n\nexport type FilesystemStoreConfig = {\n readonly root_dir: string\n}\n\n/**\n * What `filesystem_store` returns: a `CheckpointStore` with every optional\n * capability, which is what `durable` needs from its store.\n */\nexport type FilesystemStore = {\n readonly get: (key: string) => Promise<unknown>\n readonly set: (key: string, value: unknown) => Promise<void>\n readonly delete: (key: string) => Promise<void>\n readonly scope: (prefix: string) => FilesystemScopedStore\n readonly claim: (key: string, owner: string, ttl_ms: number) => Promise<boolean>\n readonly release: (key: string, owner: string) => Promise<void>\n}\n\n/**\n * A scope of a `filesystem_store`, which can also `clear`.\n */\nexport type FilesystemScopedStore = FilesystemStore & {\n readonly clear: () => Promise<void>\n}\n\ntype ClaimRecord = {\n readonly owner: string\n readonly expires_at: number\n}\n\n/**\n * Turn a key or a scope prefix into a filesystem-safe name.\n *\n * Slugs it down to `[a-zA-Z0-9._-]` and appends a short hash of the whole\n * string, so two strings that slug alike still land on distinct names.\n */\nfunction safe_name(key: string): string {\n const hash = createHash('sha256').update(key).digest('hex').slice(0, 12)\n const slug = key.replace(/[^a-zA-Z0-9._-]/g, '_').slice(0, 64)\n return `${slug}.${hash}`\n}\n\n/**\n * Read the `code` a Node filesystem error carries, if it has one.\n */\nfunction error_code(err: unknown): unknown {\n return err instanceof Error ? Reflect.get(err, 'code') : undefined\n}\n\n/**\n * Serialize a value for disk. A value JSON has no text for (`undefined`, a\n * bare function) is written as `null`, which reads back as a miss.\n */\nfunction to_json(value: unknown): string {\n const text: string | undefined = JSON.stringify(value)\n return text ?? 'null'\n}\n\n/**\n * Write `value` to `path` through a temporary sibling and a rename, so a\n * reader sees the old file or the new one and never a torn one.\n */\nasync function write_atomic(path: string, value: unknown): Promise<void> {\n // Stryker disable next-line MethodExpression: the temporary name only has to be unique, which the whole UUID is as well.\n const tmp = `${path}.${randomUUID().slice(0, 8)}.tmp`\n await writeFile(tmp, to_json(value))\n await rename(tmp, path)\n}\n\n/**\n * Create `path` holding `value` unless something is already there.\n *\n * The JSON goes to a temporary file first and is hard-linked into place, so\n * the file appears whole, and `link` refuses an existing target, so exactly\n * one of several racing creators sees true.\n */\nasync function create_exclusive(path: string, value: unknown): Promise<boolean> {\n // Stryker disable next-line MethodExpression: the temporary name only has to be unique, which the whole UUID is as well.\n const tmp = `${path}.${randomUUID().slice(0, 8)}.tmp`\n await writeFile(tmp, to_json(value))\n try {\n await link(tmp, path)\n return true\n } catch (err) {\n if (error_code(err) === 'EEXIST') return false\n throw err\n } finally {\n await rm(tmp)\n }\n}\n\n/**\n * The path of one generation in a claim directory.\n */\nfunction generation_path(dir: string, generation: number): string {\n return join(dir, `${generation}.json`)\n}\n\n/**\n * The newest generation in a claim directory, or 0 when it holds none or\n * doesn't exist yet.\n */\nasync function latest_generation(dir: string): Promise<number> {\n return Math.max(0, ...(await generations(dir)))\n}\n\n/**\n * Every generation number present in a claim directory.\n */\nasync function generations(dir: string): Promise<number[]> {\n let names: string[]\n try {\n names = await readdir(dir)\n } catch (err) {\n if (error_code(err) === 'ENOENT') return []\n throw err\n }\n return names.flatMap((name) => {\n const match = /^(\\d+)\\.json$/.exec(name)\n return match === null ? [] : [Number(match[1])]\n })\n}\n\n/**\n * Read and parse the JSON at `path`, or `null` when the file is missing or\n * doesn't parse. Any other failure surfaces.\n */\nasync function read_json(path: string): Promise<unknown> {\n let raw: string\n try {\n // Stryker disable next-line StringLiteral: without an encoding readFile hands back a Buffer, which JSON.parse turns into the same text before parsing.\n raw = await readFile(path, 'utf8')\n } catch (err) {\n if (error_code(err) === 'ENOENT') return null\n throw err\n }\n try {\n return JSON.parse(raw) as unknown\n } catch {\n return null\n }\n}\n\n/**\n * Read the claim one generation holds, or null when the file is gone or\n * doesn't hold a claim.\n */\nasync function read_claim(path: string): Promise<ClaimRecord | null> {\n const parsed = await read_json(path)\n return is_claim_record(parsed) ? parsed : null\n}\n\n/**\n * True for the `{ owner, expires_at }` shape a generation file holds.\n */\nfunction is_claim_record(value: unknown): value is ClaimRecord {\n // Stryker disable next-line BooleanLiteral: a value that isn't an object reads as free either way, since null fails the null check and a primitive has no expiry to keep it live.\n if (typeof value !== 'object' || value === null) return false\n return (\n typeof Reflect.get(value, 'owner') === 'string' &&\n typeof Reflect.get(value, 'expires_at') === 'number'\n )\n}\n\n/**\n * Delete every generation older than `keep`. A claimer only reads the newest\n * generation, so the older ones are history and nothing waits on them.\n */\nasync function prune(dir: string, keep: number): Promise<void> {\n const stale = (await generations(dir)).filter((generation) => generation < keep)\n await Promise.all(stale.map((generation) => rm(generation_path(dir, generation), { force: true })))\n}\n\n/**\n * Take or renew the claim in `dir` for `owner`.\n *\n * A live claim held by `owner` is renewed in place. Anything else that isn't\n * a live claim is taken by creating the next generation, and the claimer\n * still loses if a newer generation shows up before it confirms. Only a live\n * claim is ever renewed in place, so an expired one changes hands through\n * `create_exclusive` alone and two claimers can't both win it. A renewal that\n * lands at the very instant its claim expires can still race a takeover, and\n * it loses whenever the takeover's generation appears before it confirms.\n */\nasync function claim_in(dir: string, owner: string, ttl_ms: number): Promise<boolean> {\n await mkdir(dir, { recursive: true })\n const generation = await latest_generation(dir)\n const current = await read_claim(generation_path(dir, generation))\n const now = Date.now()\n const claim: ClaimRecord = { owner, expires_at: now + ttl_ms }\n if (current !== null && current.expires_at > now) {\n if (current.owner !== owner) return false\n await write_atomic(generation_path(dir, generation), claim)\n return (await latest_generation(dir)) === generation\n }\n const next = generation + 1\n if (!(await create_exclusive(generation_path(dir, next), claim))) return false\n if ((await latest_generation(dir)) !== next) return false\n await prune(dir, next)\n return true\n}\n\n/**\n * Release the claim in `dir` when `owner` holds it.\n *\n * The newest generation is rewritten as expired rather than deleted, so\n * generation numbers only ever grow and a slow claimer can't recreate one\n * that was already taken. A directory that vanished meanwhile (its scope was\n * cleared) has nothing left to release.\n */\nasync function release_in(dir: string, owner: string): Promise<void> {\n const generation = await latest_generation(dir)\n const path = generation_path(dir, generation)\n const current = await read_claim(path)\n if (current?.owner !== owner) return\n try {\n await write_atomic(path, { owner, expires_at: 0 })\n } catch (err) {\n if (error_code(err) !== 'ENOENT') throw err\n }\n}\n\n/**\n * Build the store rooted at `root_dir`, scopes and claims included.\n */\nfunction store_at(root_dir: string): FilesystemStore {\n const value_path = (key: string): string => join(root_dir, `${safe_name(key)}.json`)\n const claim_dir = (key: string): string => join(root_dir, `${safe_name(key)}.claim`)\n\n const get = (key: string): Promise<unknown> => read_json(value_path(key))\n\n const set = async (key: string, value: unknown): Promise<void> => {\n await mkdir(root_dir, { recursive: true })\n await write_atomic(value_path(key), value)\n }\n\n const delete_key = async (key: string): Promise<void> => {\n await rm(value_path(key), { force: true })\n }\n\n const scope = (prefix: string): FilesystemScopedStore => {\n const dir = join(root_dir, `${safe_name(prefix)}.scope`)\n return {\n ...store_at(dir),\n clear: () => rm(dir, { recursive: true, force: true }),\n }\n }\n\n return {\n get,\n set,\n delete: delete_key,\n scope,\n claim: (key, owner, ttl_ms) => claim_in(claim_dir(key), owner, ttl_ms),\n release: (key, owner) => release_in(claim_dir(key), owner),\n }\n}\n\n/**\n * Create a `CheckpointStore` backed by JSON files under `config.root_dir`.\n */\nexport function filesystem_store(config: FilesystemStoreConfig): FilesystemStore {\n return store_at(config.root_dir)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBACd,MACkB;CAClB,MAAM,QAAkB,CAAC;CAEzB,MAAM,cAA8C,MAAM,SAAS;EACjE,MAAM,UAAU,GAAG,KAAK,GAAG,WAAW,CAAC,CAAC,MAAM,GAAG,CAAC;EAClD,MAAM,QAAiC;GAAE,MAAM;GAAc;GAAS;GAAM,GAAG;EAAK;EAGpF,IAAI,MAAM,sBAAsB,KAAA,KAAa,MAAM,SAAS,GAC1D,MAAM,oBAAoB,MAAM,MAAM,SAAS;EAEjD,KAAK,KAAK;EACV,MAAM,KAAK,OAAO;EAClB,OAAO;CACT;CAEA,MAAM,YAA0C,IAAI,SAAS;EAC3D,KAAK;GAAE,MAAM;GAAY,SAAS;GAAI,GAAG;EAAK,CAAC;EAC/C,MAAM,MAAM,MAAM,YAAY,EAAE;EAChC,IAAI,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;CACrC;CAEA,MAAM,UAAsC,UAAU;EACpD,KAAK,EAAE,GAAG,MAAM,CAAC;CACnB;CAEA,OAAO;EAAE;EAAQ;EAAY;CAAS;AACxC;;;;;;ACnCA,SAAgB,YAAY,YAAwE;CAClG,OAAO,oBAAoB,UAAU;AACvC;;;;;;;;;;;;;;;;;;;;;ACgBA,SAAgB,kBAAkB,QAAkD;CAClF,MAAM,EAAE,gBAAgB;CACxB,MAAM,SAAS,OAAO,cAAc,QAAiB,iBAAiB,aAAa,GAAG;CACtF,UAAU,QAAQ,WAAW,GAAG,EAAE,WAAW,KAAK,CAAC;CAEnD,OAAO,aAAa,UAAU;EAC5B,IAAI;GACF,eAAe,aAAa,GAAG,KAAK,UAAU,KAAK,EAAE,GAAG;EAC1D,SAAS,KAAc;GACrB,IAAI;IACF,OAAO,GAAG;GACZ,QAAQ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rE,UAAU,KAAK,UAAU,WAAW,UAAU,GAAG,GAAG,KAAK;CAC3D;AACF;;;;AAKA,SAAgB,iBAAiB,QAAgD;CAC/E,OAAO,SAAS,OAAO,QAAQ;AACjC"}
@@ -1,5 +1,4 @@
1
- import { h as TrajectoryLogger } from "./types-CPqLZOEr.js";
2
- //#region src/adapters/filesystem_logger.d.ts
1
+ import { h as TrajectoryLogger } from "./types-BUXt_zgJ.js";
3
2
  type FilesystemLoggerConfig = {
4
3
  readonly output_path: string;
5
4
  /**
@@ -14,8 +13,6 @@ type FilesystemLoggerConfig = {
14
13
  * `output_path`, creating the parent directory if needed.
15
14
  */
16
15
  export declare function filesystem_logger(config: FilesystemLoggerConfig): TrajectoryLogger;
17
- //#endregion
18
- //#region src/adapters/http_logger.d.ts
19
16
  type HttpLoggerFetch = (url: string, init: {
20
17
  method: 'POST';
21
18
  headers: Record<string, string>;
@@ -39,14 +36,10 @@ type HttpLoggerConfig = {
39
36
  * blocks the flow.
40
37
  */
41
38
  export declare function http_logger(config: HttpLoggerConfig): TrajectoryLogger;
42
- //#endregion
43
- //#region src/adapters/noop_logger.d.ts
44
39
  /**
45
40
  * Create a `TrajectoryLogger` whose methods do nothing.
46
41
  */
47
42
  export declare function noop_logger(): TrajectoryLogger;
48
- //#endregion
49
- //#region src/adapters/stderr_logger.d.ts
50
43
  type StderrLoggerOptions = {
51
44
  readonly stream?: {
52
45
  write(chunk: string): unknown;
@@ -57,14 +50,10 @@ type StderrLoggerOptions = {
57
50
  * stderr, or to `options.stream` when supplied.
58
51
  */
59
52
  export declare function stderr_logger(options?: StderrLoggerOptions): TrajectoryLogger;
60
- //#endregion
61
- //#region src/adapters/tee_logger.d.ts
62
53
  /**
63
54
  * Create a `TrajectoryLogger` that fans every call out to `loggers`.
64
55
  */
65
56
  export declare function tee_logger(...loggers: ReadonlyArray<TrajectoryLogger>): TrajectoryLogger;
66
- //#endregion
67
- //#region src/adapters/filesystem_store.d.ts
68
57
  /**
69
58
  * Filesystem-backed checkpoint store.
70
59
  *
@@ -118,6 +107,5 @@ type FilesystemScopedStore = FilesystemStore & {
118
107
  * Create a `CheckpointStore` backed by JSON files under `config.root_dir`.
119
108
  */
120
109
  export declare function filesystem_store(config: FilesystemStoreConfig): FilesystemStore;
121
- //#endregion
122
110
  export type { FilesystemLoggerConfig, FilesystemScopedStore, FilesystemStore, FilesystemStoreConfig, HttpLoggerConfig, HttpLoggerFetch, StderrLoggerOptions };
123
111
  //# sourceMappingURL=adapters.d.ts.map
package/dist/adapters.js CHANGED
@@ -1 +1 @@
1
- export { o as filesystem_logger, t as filesystem_store, a as http_logger, i as noop_logger, r as stderr_logger, n as tee_logger } from "./adapters-CDUzZlby.js";
1
+ export { o as filesystem_logger, t as filesystem_store, a as http_logger, i as noop_logger, r as stderr_logger, n as tee_logger } from "./adapters-CpKpDk7r.js";
package/dist/agents.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { c as Step } from "./types-CPqLZOEr.js";
2
- import { r as ToolSchema } from "./types-BK0UW28o.js";
3
- import { l as EffortLevel, u as Engine } from "./types-xYjCEd6i.js";
4
- //#region src/agents/define_agent.d.ts
1
+ import { c as Step } from "./types-BUXt_zgJ.js";
2
+ import { l as EffortLevel, u as Engine } from "./types-Dk9tLpUq.js";
3
+ import { r as ToolSchema } from "./types-CvghbZ0x.js";
5
4
  type AgentBuiltPrompt = string | {
6
5
  readonly user: string;
7
6
  readonly system?: string;
@@ -56,6 +55,5 @@ type DefineAgentConfig<i, o> = {
56
55
  * records an `agent.call` event with the resolved model and usage.
57
56
  */
58
57
  export declare function define_agent<i, o>(config: DefineAgentConfig<i, o>): Step<i, o>;
59
- //#endregion
60
58
  export type { AgentBuiltPrompt, DefineAgentConfig };
61
59
  //# sourceMappingURL=agents.d.ts.map
package/dist/agents.js CHANGED
@@ -1,7 +1,7 @@
1
- import { _ as step, j as aborted_error, v as assert_valid_step_id } from "./core-Bfzt55Fl.js";
1
+ import { _ as step, j as aborted_error, v as assert_valid_step_id } from "./core-BH7sWpEG.js";
2
2
  import { readFileSync } from "node:fs";
3
3
  import { fileURLToPath } from "node:url";
4
- //#region src/agents/define_agent.ts
4
+ // src/agents/define_agent.ts
5
5
  /**
6
6
  * define_agent: markdown-driven loader for simple agents.
7
7
  *
@@ -247,7 +247,6 @@ function define_agent(config) {
247
247
  ...frontmatter.description === void 0 ? {} : { description: frontmatter.description }
248
248
  });
249
249
  }
250
- //#endregion
251
250
  export { define_agent };
252
251
 
253
252
  //# sourceMappingURL=agents.js.map
@@ -1,5 +1,5 @@
1
1
  import { Console } from "node:console";
2
- //#region src/process/console.ts
2
+ // src/process/console.ts
3
3
  /**
4
4
  * console: keep a process's console off its stdout.
5
5
  *
@@ -31,7 +31,6 @@ function route_console_to_stderr(target, stderr) {
31
31
  }
32
32
  });
33
33
  }
34
- //#endregion
35
34
  export { route_console_to_stderr as t };
36
35
 
37
- //# sourceMappingURL=console-CdB4pcFO.js.map
36
+ //# sourceMappingURL=console-B1ozi_ii.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"console-CdB4pcFO.js","names":[],"sources":["../src/process/console.ts"],"sourcesContent":["/**\n * console: keep a process's console off its stdout.\n *\n * A process whose stdout carries something a parent reads (the ACP protocol\n * under `serve_acp`, the one result document under `run_stdio`) breaks when a\n * flow or a dependency logs, because `console.log` writes to stdout by\n * default. Routing the console's stdout methods to stderr keeps that stream\n * to its one job.\n */\n\nimport { Console } from 'node:console'\nimport type { InspectOptions } from 'node:util'\n\n/**\n * Route `target`'s stdout methods (`log`, `info`, `debug`, `dirxml`, and\n * `dir`) to stderr for as long as `target` lives.\n *\n * Four of them call `target.error`, which already writes to stderr. `dir`\n * writes to its console's own stream rather than through `log`, so it comes\n * from a console bound to `stderr`, which honors options such as `depth`.\n * A write that goes straight to `process.stdout` still lands there.\n */\nexport function route_console_to_stderr(target: typeof console, stderr: NodeJS.WritableStream): void {\n const stderr_console = new Console(stderr)\n const to_stderr = target.error.bind(target)\n Object.assign(target, {\n log: to_stderr,\n info: to_stderr,\n debug: to_stderr,\n dirxml: to_stderr,\n dir: (item: unknown, options?: InspectOptions) => {\n stderr_console.dir(item, options)\n },\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,wBAAwB,QAAwB,QAAqC;CACnG,MAAM,iBAAiB,IAAI,QAAQ,MAAM;CACzC,MAAM,YAAY,OAAO,MAAM,KAAK,MAAM;CAC1C,OAAO,OAAO,QAAQ;EACpB,KAAK;EACL,MAAM;EACN,OAAO;EACP,QAAQ;EACR,MAAM,MAAe,YAA6B;GAChD,eAAe,IAAI,MAAM,OAAO;EAClC;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"console-B1ozi_ii.js","names":[],"sources":["../src/process/console.ts"],"sourcesContent":["/**\n * console: keep a process's console off its stdout.\n *\n * A process whose stdout carries something a parent reads (the ACP protocol\n * under `serve_acp`, the one result document under `run_stdio`) breaks when a\n * flow or a dependency logs, because `console.log` writes to stdout by\n * default. Routing the console's stdout methods to stderr keeps that stream\n * to its one job.\n */\n\nimport { Console } from 'node:console'\nimport type { InspectOptions } from 'node:util'\n\n/**\n * Route `target`'s stdout methods (`log`, `info`, `debug`, `dirxml`, and\n * `dir`) to stderr for as long as `target` lives.\n *\n * Four of them call `target.error`, which already writes to stderr. `dir`\n * writes to its console's own stream rather than through `log`, so it comes\n * from a console bound to `stderr`, which honors options such as `depth`.\n * A write that goes straight to `process.stdout` still lands there.\n */\nexport function route_console_to_stderr(target: typeof console, stderr: NodeJS.WritableStream): void {\n const stderr_console = new Console(stderr)\n const to_stderr = target.error.bind(target)\n Object.assign(target, {\n log: to_stderr,\n info: to_stderr,\n debug: to_stderr,\n dirxml: to_stderr,\n dir: (item: unknown, options?: InspectOptions) => {\n stderr_console.dir(item, options)\n },\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,wBAAwB,QAAwB,QAAqC;CACnG,MAAM,iBAAiB,IAAI,QAAQ,MAAM;CACzC,MAAM,YAAY,OAAO,MAAM,KAAK,MAAM;CAC1C,OAAO,OAAO,QAAQ;EACpB,KAAK;EACL,MAAM;EACN,OAAO;EACP,QAAQ;EACR,MAAM,MAAe,YAA6B;GAChD,eAAe,IAAI,MAAM,OAAO;EAClC;CACF,CAAC;AACH"}