fascicle 0.11.1 → 0.12.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.
- package/CHANGELOG.md +102 -0
- package/README.md +40 -31
- package/dist/adapters.d.ts +1 -1
- package/dist/agents.d.ts +11 -2
- package/dist/agents.js +63 -20
- package/dist/agents.js.map +1 -1
- package/dist/bin/fascicle-viewer.js +2 -2
- package/dist/{core-DgH4mDbK.js → core-DDRhHu5P.js} +458 -38
- package/dist/core-DDRhHu5P.js.map +1 -0
- package/dist/engine-b4ZH8esY.js +7317 -0
- package/dist/engine-b4ZH8esY.js.map +1 -0
- package/dist/index.d.ts +388 -224
- package/dist/index.js +331 -7795
- package/dist/index.js.map +1 -1
- package/dist/{invoke-BjrbCBSV.js → invoke-CyKNhvBw.js} +3 -3
- package/dist/{invoke-BjrbCBSV.js.map → invoke-CyKNhvBw.js.map} +1 -1
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +1 -1
- package/dist/otel.d.ts +1 -1
- package/dist/static/viewer.html +2 -1
- package/dist/stdio.d.ts +1 -1
- package/dist/stdio.js +1 -1
- package/dist/testing.d.ts +90 -0
- package/dist/testing.js +255 -0
- package/dist/testing.js.map +1 -0
- package/dist/trajectory-cSLNlHzh.d.ts +114 -0
- package/dist/{types-BDSbSUAO.d.ts → types-BqUY6nRX.d.ts} +25 -4
- package/dist/{types-B3HIsBBD.d.ts → types-CXBB4aIM.d.ts} +8 -4
- package/dist/ui.d.ts +2 -2
- package/dist/viewer.d.ts +117 -0
- package/dist/viewer.js +658 -0
- package/dist/viewer.js.map +1 -0
- package/package.json +27 -9
- package/dist/core-DgH4mDbK.js.map +0 -1
- package/dist/leading_system-CpkjHoCQ.js +0 -307
- package/dist/leading_system-CpkjHoCQ.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,107 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v0.12.1 — 2026-08-18
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **The `gate` composite: paid work survives an approval pause.** `gate(inner, { id, store?, format?, name? })` runs `inner`, checkpoints its result under `gate:<id>`, then suspends with that result as the payload, so the approver sees what they are approving. Resuming passes the inner result through unchanged, and a fresh run after a process restart with the same store replays from the checkpoint instead of paying for the model call again. Built from public primitives only, so it renders as one composite node in `describe`; reach for raw `checkpoint` plus `suspend` when the decision must shape the output.
|
|
8
|
+
|
|
9
|
+
- **`chain` states its input type once.** `chain('question').input<Request>()` replaces `chain<Request, 'question'>('question')`; the refinement is available only on a freshly opened chain, before the first binding.
|
|
10
|
+
|
|
11
|
+
- **Arm-first chain bindings.** `.step(name, arm, select)` takes a composed `Step` and a selector from the record to the arm's input: the chain dispatches the arm and records it as the binding's describe child in one statement, so the run tree and the described tree cannot drift apart. The `fn` plus `{ arm }` form remains for bodies that invoke an arm conditionally, in a loop, or more than once.
|
|
12
|
+
|
|
13
|
+
- **Scripted and sequenced test doubles.** `make_script_engine(responses, options?)` plays a strict call-order queue whose entries are plain content values or `{ content?, tool_calls?, finish_reason?, usage?, throw? }`, so a converging loop, a tool-call path, or a provider error can be scripted without hand-rolling an engine; a `make_stub_engine` response's `content` may now be a function of the call and its per-route index. `text_of(opts)` reads the user-visible prompt out of a captured `GenerateOptions` whatever its shape, and `engine_from_generate(generate)`, the shell both factories are built on, is now exported for custom doubles. `docs/testing.md` is the new guide.
|
|
14
|
+
|
|
15
|
+
- **Caller-shaped generation knobs everywhere they were missing.** `temperature`, `max_tokens`, `top_p`, `turn_timeout_ms`, and `prepare_step` ride on `ModelCallConfig` (and so on `model_step`); the three sampling knobs also work as `EngineDefaults`, with the per-call value winning. `define_agent` accepts `provider`, `effort`, `temperature`, `max_tokens`, and `top_p` through both markdown frontmatter and code config, code winning over frontmatter and frontmatter over the engine default. Previously the only route to a temperature was frontmatter or dropping to `engine.generate` inside a step body.
|
|
16
|
+
|
|
17
|
+
- **Terminal and checkpoint trajectory events.** Every run now ends with `run_end` carrying `status: 'done' | 'failed' | 'aborted' | 'suspended'`, so a consumer no longer infers a failed run from silence, and a failing span records `error_name`, `error_kind`, and `error_path` alongside the message. Checkpoint lookups emit `checkpoint` with `status: 'hit' | 'miss' | 'read_error'`; a store that throws still degrades to a miss, but visibly. Guards: `is_run_end_event`, `is_checkpoint_event`.
|
|
18
|
+
|
|
19
|
+
- **`run.until_suspended` outcomes carry their `payload`.** A driver loop can render what is awaiting approval without threading a side channel out of the `on` callback.
|
|
20
|
+
|
|
21
|
+
- **A bare predicate as a `loop` guard.** `guard: (state) => boolean`, or a promise of one, no longer needs wrapping in a step that returns `{ stop, state }`.
|
|
22
|
+
|
|
23
|
+
- **Every type a public signature names.** The composer configs (`SequenceOptions`, `ParallelOptions`, `BranchConfig`, `MapConfig`, `PipeOptions`, `RetryConfig`, `FallbackOptions`, `TimeoutOptions`, `CheckpointConfig`, `SuspendConfig`, `ScopeOptions`, `StashOptions`, `UseOptions`, `GateConfig`), the run vocabulary (`RunOptions`, `StreamingRunHandle`, `StepFn`, `CleanupFn`), the schema vocabulary (`ToolSchema`, `AnySchema`, `SchemaIssue`), `ClaudeCliErrorReason`, and the extractors `StepInput<s>` / `StepOutput<s>` are exported now, and `is_step` joins `is_step_kind` at runtime. Writing the wrapper factories the blueprint teaches no longer requires `Parameters<typeof run>[2]`.
|
|
24
|
+
|
|
25
|
+
- **A typed error path.** Every fascicle error class declares `path`, and `error_path(err)` reads it off any thrown value, including a foreign error the runner tagged on its way out. The documented diagnostic previously required a cast.
|
|
26
|
+
|
|
27
|
+
- **CommonJS consumers can `require()` the package.** Each export entry gained a `default` condition pointing at the same ESM file, so Node's native `require(esm)` resolves it on the supported Node 24 floor. No CJS build, no second artifact.
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- **Provider resolution no longer falls back to `anthropic`.** With several providers configured and neither a per-call `provider` nor `defaults.provider`, `generate` throws the new `provider_required_error` naming what is configured, instead of quietly sending the call to Anthropic. Per-call choice, engine default, and sole-provider inference are unchanged. **Breaking**, and deliberately so for a provider-agnostic library: a multi-provider engine that leaned on the implicit default now has to say which one it meant.
|
|
32
|
+
|
|
33
|
+
- **A misspelled provider name is reported at construction.** A provider key matching no built-in and no custom adapter throws `engine_config_error` with `unknown provider '<name>'; built-in providers are: ...`, rather than claiming it is not configured on the engine that just declared it. The call-time `provider_not_configured_error` keeps its own meaning.
|
|
34
|
+
|
|
35
|
+
- **`chain`'s input type parameter defaults to `never`.** An unannotated `chain()` used to produce a spine that accepted anything at `run`; the omission now fails at the `run` call site. **Breaking** for chains that leaned on the inferred `unknown`: state the type with `chain<Input>()` or `chain('name').input<Input>()`. Every call site in this repo already annotated, so the sweep changed none of them.
|
|
36
|
+
|
|
37
|
+
- **The viewer moved to the `fascicle/viewer` subpath.** `start_viewer`, `run_viewer_cli`, `StartViewerOptions`, and `ViewerHandle` are no longer re-exported from the package root. **Breaking**, one import line. The subpath also publishes `create_broadcaster`, `start_server`, and `start_tail`, which existed in the barrel but could not be reached from the published surface. The `fascicle-viewer` bin is unaffected.
|
|
38
|
+
|
|
39
|
+
- **`sequence` type checking.** Runtime-built homogeneous arrays infer as `Step<T, T>` through a new overload instead of degrading to `Step<unknown, unknown>` (which let `run(seq, wrong_type)` compile), a sound spread inside a literal tuple no longer false-positives, and a joint mismatch resolves to a branded `SequenceJointMismatch<At, Expected, Got>`, so the first line of the error names the position and the two types instead of two lines about optional properties.
|
|
40
|
+
|
|
41
|
+
- **Anonymous step ids are `step_<n>`** (previously `anon_<n>`), and a `model_call` without an explicit `id` mixes in an instance counter, so two identical leaves are distinguishable in `describe` and the trajectory.
|
|
42
|
+
|
|
43
|
+
- **`describe` shows the model call's knobs.** Temperature, token cap, `top_p`, and turn timeout appear by value when set, with `has_prepare_step` alongside the existing flags.
|
|
44
|
+
|
|
45
|
+
### Fixed
|
|
46
|
+
|
|
47
|
+
- **`fallback` no longer discards the primary error.** When the backup also fails, the primary error rides along as the backup error's `cause`, so the interesting failure, why the fallback happened at all, survives to the catch site.
|
|
48
|
+
|
|
49
|
+
- **`retry` rejects a non-finite `max_attempts` at construction.** A `NaN`, easy to produce from arithmetic on a missing config field, previously ran zero attempts and rejected with a literal `undefined`: no message, no stack.
|
|
50
|
+
|
|
51
|
+
- **`model_call` names a missing engine.** Constructing without one threw `Cannot read properties of undefined (reading 'generate')` at dispatch; it now throws a `TypeError` at construction saying which option is missing and where an `Engine` comes from.
|
|
52
|
+
|
|
53
|
+
- **The stub engine reports what failed a schema.** It surfaces the validation issues and throws the real `schema_validation_error`, so a test can exercise the same handling production takes; it previously computed the issues, dropped them, and threw a bare `Error`.
|
|
54
|
+
|
|
55
|
+
- **Docs no longer teach a model id that 404s.** Every family shorthand (`sonnet`, `opus`, `haiku`) on an API transport became a concrete id, since the engine sends `model` verbatim and only `claude_cli` resolves bare tokens; the README tour and the first-run examples were the worst of it. Several recipes moved to local Ollama and other open models. A compile-only snippet gate cannot catch a wrong id, which is how these survived.
|
|
56
|
+
|
|
57
|
+
- **The cookbook's multi-provider fallback recipe routes to two providers.** Neither `model_step` set `provider`, so both calls, including the one asking for `gpt-4o`, resolved to the same adapter.
|
|
58
|
+
|
|
59
|
+
- **`docs/composition.md` is the composition guide again.** It was an old module README, still titled `# core`, ending in a stray closing tag that rendered on GitHub, with a public-surface table missing a dozen exports.
|
|
60
|
+
|
|
61
|
+
- **The stale concurrency caveat is gone.** Six documents warned that bundled span stacks attribute concurrent children to the wrong parent; the loggers have used the runner-threaded `parent_span_id` for a while, and the roadmap already claimed the fixed behavior. The synchronous-write caveat on `filesystem_logger` is real and stays.
|
|
62
|
+
|
|
63
|
+
- **Standard Schema is documented as such.** The reference printed `schema?: z.ZodType<t>` and said "a zod schema" in four places, while the contract is any Standard Schema; an ArkType or Valibot user reading it would conclude the headline feature did not exist.
|
|
64
|
+
|
|
65
|
+
- **A viewer regression test that never ran.** Its path to the built bundle carried an extra `..` from the old workspace layout, so it resolved above the repository root and skipped silently.
|
|
66
|
+
|
|
67
|
+
### Internal
|
|
68
|
+
|
|
69
|
+
- `markdownlint` and `cspell` no longer ignore `docs/**`. That gap is how the stray tag and the stale claims survived every release; the twelve lint errors and forty-eight spelling flags it surfaced are fixed.
|
|
70
|
+
- The build's bundle invariants walk the root entry's static closure instead of grepping `dist/index.js`, so hoisting the engine into a shared chunk, which the testing subpath's value import now causes, no longer quietly stops the lazy `ai` seam from being checked. `fascicle/ui` is out of scope by design, since it imports `ai` on purpose.
|
|
71
|
+
- Getting-started gained a run scaffold (`"type": "module"`, Node 24, `tsx`), the keyless stub-engine path is advertised where a newcomer will see it, and the examples index marks which examples need a key.
|
|
72
|
+
|
|
73
|
+
## v0.12.0 — 2026-08-18
|
|
74
|
+
|
|
75
|
+
### Added
|
|
76
|
+
|
|
77
|
+
- **`chain`: named steps over a growing typed record.** `chain(input_name?)` builds a `Step` from `.step(name, fn)` bindings that each merge one named value into the record, `.stage(name, project?)` markers that conclude a phase (with `project`, narrowing the record), and a final `.output(fn)` projection. A step body receives the record plus the run context, so a binding can `ctx.call` a composed arm directly; passing that arm as step-level `{ arm }` metadata records it as a describe-only child, so `describe` still renders the full tree under the binding.
|
|
78
|
+
|
|
79
|
+
- **`model_step`: the default model boundary.** Takes the same config as `model_call` and returns a `Step` whose output is the content alone: a `string`, or the schema-validated value when `schema` is set. Implemented as `model_call` with `project` preset to the content, so the leaf is a single node in `describe` and the trajectory; reach for `model_call` when the caller needs the `GenerateResult` envelope (usage, cost, tool calls, finish reason).
|
|
80
|
+
|
|
81
|
+
- **`run.until_suspended`: suspension as a typed outcome.** Where plain `run` signals a `suspend` gate by throwing `suspended_error`, `run.until_suspended(flow, input, options?)` resolves `{ kind: 'suspended', id, resume }`; calling `resume(data)` re-runs the flow with the decision and resolves to the next outcome. Completion is `{ kind: 'done', output }`; real errors still throw. This supersedes the try/catch dance around `suspended_error`, which remains for plain `run`.
|
|
82
|
+
|
|
83
|
+
- **A `project` option on the six envelope composites and on `model_call`.** `adversarial`, `ensemble`, `ensemble_step`, `tournament`, `consensus`, and `improve` can now map their result envelope into the step's output at the source (`project: (r) => r.candidate`), so downstream steps see the value instead of the wrapper; `model_call` takes the same option over its `GenerateResult` (`project: (r) => ({ text: r.content, cost: r.cost })`), which is also how `model_step` is now built. In every case the projection runs inside the step, so `describe` and the trajectory gain no wrapper node; omitted, the envelope stays the output, as before.
|
|
84
|
+
|
|
85
|
+
- **The `fascicle/testing` subpath.** `make_stub_engine(canned, options?)` routes canned responses by system-prompt prefix, validates each one through the call's schema, and throws on an unmatched system; `make_capture_engine(options?)` records every call's `GenerateOptions` into a live `calls` array and answers with a canned result. Types: `StubEngineOptions`, `StubResponse`, `CaptureEngine`, `CaptureEngineOptions`.
|
|
86
|
+
|
|
87
|
+
- **Compile-time joint checking for literal `sequence` tuples.** Each child of a literal tuple must accept its predecessor's output, and a mismatch errors on the offending element. Arrays built at runtime still degrade to unknown boundaries; annotate the outer `Step<In, Out>` to keep the flow's boundary checked.
|
|
88
|
+
|
|
89
|
+
- **Docs for the layering.** `docs/leaf-arm-spine.md` names the leaf / arm / spine shape and the decision rules at each layer, `docs/advanced-composition.md` covers the demoted tier (`scope`/`stash`/`use`, plain `ensemble`, `tournament`, `improve`/`learn`), and `examples/newsroom.ts` is the vocabulary tour that uses every primary primitive once.
|
|
90
|
+
|
|
91
|
+
- **A one-file style pair in the examples.** `examples/release_notes.ts` and `examples/release_notes_direct.ts` build the same release-notes flow two ways — composed through `chain` and arms, and written straight through as one function — so the cost and the benefit of composing are readable side by side rather than asserted. `docs/blueprint.md` is rebuilt around `chain` and points at the pair.
|
|
92
|
+
|
|
93
|
+
### Changed
|
|
94
|
+
|
|
95
|
+
- **The `Step` type is sound.** `run` is a function property rather than a method, so a step's input is checked contravariantly, and `AnyStep` (`Step<never, unknown>`) is added as the erased supertype for code that handles steps generically. **Breaking** for consumers that relied on method bivariance: an assignment that only type-checked under that looser method-parameter rule now errors, which is the point of the change.
|
|
96
|
+
|
|
97
|
+
- **The examples fleet migrated to the `chain` / `model_step` / arm idioms.** The single-file demos and the reference apps now read as leaves, arms, and one spine per flow, matching the layering `docs/leaf-arm-spine.md` names.
|
|
98
|
+
|
|
99
|
+
- **The prose surface moved onto the `chain` / `model_step` idiom.** `README.md`, `docs/getting-started.md`, `docs/concepts.md`, `docs/api-reference.md`, `docs/cookbook.md`, `docs/composition.md`, `docs/writing-a-harness.md`, and the site pages now teach leaf / arm / spine first and present `pipe`, `sequence`, and `model_call` as the lower tier those primitives sit on. `docs/concepts.md` and `docs/api-reference.md` also state the sound `Step` shape and `AnyStep`.
|
|
100
|
+
|
|
101
|
+
### Internal
|
|
102
|
+
|
|
103
|
+
- Re-baselined the duplication report after the stub-engine paydown, and added the `.firecrawl` web-research scratch directory to `.gitignore`.
|
|
104
|
+
|
|
3
105
|
## v0.11.1 — 2026-08-13
|
|
4
106
|
|
|
5
107
|
### Fixed
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
|
-
Compose agents out of LLM calls, tool calls, and plain functions. Everything is a `Step<i, o>`. Wire steps together with
|
|
5
|
+
Compose agents out of LLM calls, tool calls, and plain functions. Everything is a `Step<i, o>`. Wire steps together with 22 primitives (`sequence`, `parallel`, `chain`, `branch`, `retry`, `loop`, `ensemble_step`, `checkpoint`, …) and run them as plain values. One `generate` surface fronts eight provider adapters: Anthropic, OpenAI, Google, OpenRouter, AWS Bedrock, Ollama, LM Studio, and a `claude_cli` subprocess that drives the Claude Code CLI.
|
|
6
6
|
|
|
7
7
|
No framework lifecycle. No ambient state. No decorators. Adapters are passed in per run.
|
|
8
8
|
|
|
@@ -14,6 +14,8 @@ pnpm add fascicle
|
|
|
14
14
|
|
|
15
15
|
fascicle is ESM-only and requires Node >= 24. `ai`, `zod`, and every provider SDK are optional peers — install only the ones you use. `pnpm add fascicle` alone builds and runs a flow against `transport: 'native'` or `claude_cli`, with no AI SDK package and no schema library installed at all; schemas accept any [Standard Schema](https://standardschema.dev) — zod, ArkType, Valibot, whichever you already use. See [docs/providers.md](./docs/providers.md).
|
|
16
16
|
|
|
17
|
+
No API key on hand? Several runnable examples need zero keys: [examples/hello.ts](./examples/hello.ts), [examples/suspend_resume.ts](./examples/suspend_resume.ts), and [examples/viewer_demo.ts](./examples/viewer_demo.ts) use no engine at all, and [examples/newsroom.ts](./examples/newsroom.ts) runs the full vocabulary against the bundled stub engine from `fascicle/testing`.
|
|
18
|
+
|
|
17
19
|
## A 60-second tour
|
|
18
20
|
|
|
19
21
|
<!-- snippet: check -->
|
|
@@ -32,18 +34,17 @@ Add a model call:
|
|
|
32
34
|
|
|
33
35
|
<!-- snippet: check -->
|
|
34
36
|
```typescript
|
|
35
|
-
import { create_engine,
|
|
37
|
+
import { create_engine, model_step, run, sequence, step } from 'fascicle';
|
|
36
38
|
|
|
37
39
|
const engine = create_engine({
|
|
38
|
-
providers: {
|
|
40
|
+
providers: {
|
|
41
|
+
anthropic: { api_key: process.env.ANTHROPIC_API_KEY!, transport: 'native' },
|
|
42
|
+
},
|
|
39
43
|
});
|
|
40
44
|
|
|
41
45
|
const flow = sequence([
|
|
42
46
|
step('brief', (topic: string) => `Write a 2-sentence brief on: ${topic}`),
|
|
43
|
-
|
|
44
|
-
model_call({ engine, model: 'sonnet', system: 'No preamble.' }),
|
|
45
|
-
(r) => r.content,
|
|
46
|
-
),
|
|
47
|
+
model_step({ engine, model: 'claude-sonnet-4-6', system: 'No preamble.' }),
|
|
47
48
|
]);
|
|
48
49
|
|
|
49
50
|
try {
|
|
@@ -53,11 +54,13 @@ try {
|
|
|
53
54
|
}
|
|
54
55
|
```
|
|
55
56
|
|
|
56
|
-
`
|
|
57
|
+
`transport: 'native'` keeps the zero-peer promise above: raw HTTP against the Messages API, nothing to install beyond `fascicle`. Drop it to use the default `ai_sdk` transport, which needs `pnpm add ai @ai-sdk/anthropic`.
|
|
58
|
+
|
|
59
|
+
`model_step` returns the model's answer (a `string`, or the schema-validated value when `schema` is set), keeping flows at the `step, step, model_step, step` cadence. Underneath sits `model_call`, the only sanctioned bridge between composition and the engine: same config, but it returns the full `GenerateResult` envelope (usage, cost, tool calls, finish reason), with an optional `project` to map a slice of it at the source. Both thread `ctx.abort`, `ctx.trajectory`, and streaming chunks for you.
|
|
57
60
|
|
|
58
61
|
## What's in the box
|
|
59
62
|
|
|
60
|
-
**Composition primitives
|
|
63
|
+
**Composition primitives.** Every composer takes `Step<i, o>` and returns `Step<i, o>`. Anything that fits a step fits any composition of steps. The everyday surface is small; most flows are built entirely from these nine:
|
|
61
64
|
|
|
62
65
|
| Primitive | Shape |
|
|
63
66
|
| --- | --- |
|
|
@@ -68,22 +71,12 @@ try {
|
|
|
68
71
|
| `map` | run a step per array element, optional concurrency cap |
|
|
69
72
|
| `pipe` | post-process an inner step's output with a plain function |
|
|
70
73
|
| `retry` | re-run on failure with exponential backoff |
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
| `ensemble_step` | pick-best where the scorer is itself a `Step` (a model judge with its own span) |
|
|
78
|
-
| `tournament` | single-elimination bracket |
|
|
79
|
-
| `consensus` | run N concurrently, accept when an `agree` predicate holds |
|
|
80
|
-
| `checkpoint` | memoize an inner step by key in a `CheckpointStore` |
|
|
81
|
-
| `suspend` | pause for external input; resume later with `resume_data` |
|
|
82
|
-
| `scope` / `stash` / `use` | named state across non-adjacent steps |
|
|
83
|
-
| `improve` | bounded online propose → score → accept/reject self-improvement loop |
|
|
84
|
-
| `learn` | offline reflection over recorded trajectories |
|
|
85
|
-
|
|
86
|
-
Plus `run`, `run.stream`, and `describe`.
|
|
74
|
+
| `model_step` | the model's answer as a step (`model_call` projected to its content) |
|
|
75
|
+
| `chain` | named steps over a typed record: `.step` binds, `.stage` concludes a phase, `.output` projects |
|
|
76
|
+
|
|
77
|
+
The remaining primitives are specialized composers with the same contract, so they drop into any flow when the task calls for them: control flow (`loop`, `fallback`, `timeout`, `compose`), multi-model orchestration (`adversarial`, `ensemble_step`, `consensus`), and durability (`checkpoint`, `suspend`). Behind those sits an advanced tier — the pick-best variants `ensemble` and `tournament`, the raw named-state primitives `scope` / `stash` / `use` underlying `chain`, and the self-improvement pair `improve` / `learn` — covered in [docs/advanced-composition.md](./docs/advanced-composition.md), each entry paired with the primary primitive to try first. One-liners for all of them live in [docs/composition.md](./docs/composition.md), full shapes in [docs/api-reference.md](./docs/api-reference.md), and [docs/leaf-arm-spine.md](./docs/leaf-arm-spine.md) is the decision guide for which layer each belongs to.
|
|
78
|
+
|
|
79
|
+
Plus `run`, `run.stream`, and `describe`. And inside any step body, `ctx.call(step, input)` runs another Step with spans, abort, and error paths intact: the direct-style counterpart to composing, for control flow too dynamic to declare.
|
|
87
80
|
|
|
88
81
|
**AI engine.** `create_engine(config)` returns one `generate` surface across eight providers. Two axes: `model` is an opaque id sent to the provider verbatim (`claude-opus-4-8`, `gpt-4o`, `us.anthropic.claude-sonnet-4-20250514-v1:0`), and `provider` names the transport (`anthropic`, `bedrock`, `openrouter`, `claude_cli`, …) — swap `provider` to move a call between transports. Reasoning effort (`'none'` through `'max'`) is translated per provider. Cost estimation uses a pricing table with per-engine overrides.
|
|
89
82
|
|
|
@@ -100,9 +93,19 @@ await run(flow, input, {
|
|
|
100
93
|
});
|
|
101
94
|
```
|
|
102
95
|
|
|
103
|
-
`filesystem_logger` writes synchronously
|
|
96
|
+
`filesystem_logger` writes synchronously (each event blocks the event loop briefly), which is fine for dev tools and short-lived runs; see [docs/concepts.md](./docs/concepts.md#adapter-limits) before wiring it into a long-running server. Span parentage is threaded through the runner, so span trees stay correct under `parallel`/`map` concurrency. The `TrajectoryLogger` and `CheckpointStore` contracts (exported from `fascicle`) are tiny — roll your own to push events to Honeycomb, S3, etc.
|
|
97
|
+
|
|
98
|
+
`run.stream(flow, input)` returns `{ events, result }` for incremental observation, and `run.until_suspended(flow, input)` drives human-in-the-loop flows: a `suspend` gate resolves to a typed outcome with a `resume` closure instead of throwing.
|
|
104
99
|
|
|
105
|
-
|
|
100
|
+
**Stub engines for tests.** The `fascicle/testing` subpath ships the two doubles an app needs — `make_stub_engine` routes canned responses by the system prompt's stable first line and validates them through the call's own schema, `make_capture_engine` records every `GenerateOptions` for assertions — so tests run the real flow through the real `run()` with zero network and no mocking framework:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import { make_stub_engine } from 'fascicle/testing';
|
|
104
|
+
|
|
105
|
+
const engine = make_stub_engine([
|
|
106
|
+
{ prefix: 'myapp/reviewer', content: { findings: [], summary: 'clean' } },
|
|
107
|
+
]);
|
|
108
|
+
```
|
|
106
109
|
|
|
107
110
|
**Markdown-defined agents.** When an agent is just a prompt plus an output schema, `define_agent` (the `fascicle/agents` subpath) folds a markdown file — frontmatter `name` / `model` / `temperature`, body as the prompt — and a zod schema into a `Step<i, o>`:
|
|
108
111
|
|
|
@@ -180,7 +183,7 @@ Or embed it programmatically:
|
|
|
180
183
|
|
|
181
184
|
<!-- snippet: check -->
|
|
182
185
|
```typescript
|
|
183
|
-
import { start_viewer } from 'fascicle';
|
|
186
|
+
import { start_viewer } from 'fascicle/viewer';
|
|
184
187
|
|
|
185
188
|
const handle = await start_viewer({ port: 4242 });
|
|
186
189
|
// later
|
|
@@ -200,19 +203,25 @@ The canonical worked example is [examples/pr-improve/](./examples/pr-improve/),
|
|
|
200
203
|
- [docs/blueprint.md](./docs/blueprint.md) — **the agent blueprint**: the standard app architecture (start here when building an app)
|
|
201
204
|
- [docs/getting-started.md](./docs/getting-started.md) — install and run your first flow
|
|
202
205
|
- [docs/concepts.md](./docs/concepts.md) — step-as-value, trajectories, cancellation
|
|
203
|
-
- [docs/composition.md](./docs/composition.md) — full composition surface: the
|
|
206
|
+
- [docs/composition.md](./docs/composition.md) — full composition surface: the 22 primitives, run/stream, checkpointing
|
|
207
|
+
- [docs/leaf-arm-spine.md](./docs/leaf-arm-spine.md) — the three-layer shape of a fascicle flow and how to choose the right primitive at each layer
|
|
208
|
+
- [docs/advanced-composition.md](./docs/advanced-composition.md) — the primitives to reach for last (`scope`/`stash`/`use`, `ensemble`, `tournament`, `improve`/`learn`) and when they earn their keep
|
|
204
209
|
- [docs/api-reference.md](./docs/api-reference.md) — the public surface at a glance
|
|
205
210
|
- [docs/configuration.md](./docs/configuration.md) — engine config, defaults, pricing, retries
|
|
206
211
|
- [docs/providers.md](./docs/providers.md) — per-provider adapter notes
|
|
207
212
|
- [docs/cli.md](./docs/cli.md) — the `claude_cli` subprocess adapter
|
|
208
213
|
- [docs/cookbook.md](./docs/cookbook.md) — retries, fan-out, judges, HITL, tool loops
|
|
214
|
+
- [docs/deliberation-as-composition.md](./docs/deliberation-as-composition.md) — how ensembles, tournaments, consensus, and adversarial loops decompose into the primitives
|
|
215
|
+
- [docs/testing.md](./docs/testing.md) — testing flows with stub, script, and capture engines
|
|
216
|
+
- [docs/regression-testing-model-behavior.md](./docs/regression-testing-model-behavior.md) — regression-testing model behavior with mutation-tested judges and a committed score baseline
|
|
209
217
|
- [docs/human-in-the-loop.md](./docs/human-in-the-loop.md) — suspend/resume approval over HTTP and streaming to a `useChat` UI via `fascicle/ui`
|
|
210
218
|
- [docs/writing-a-harness.md](./docs/writing-a-harness.md) — building a runner around fascicle
|
|
211
219
|
- [docs/embedding-under-a-harness.md](./docs/embedding-under-a-harness.md) — running a fascicle agent as somebody's child process
|
|
212
220
|
- [docs/troubleshooting.md](./docs/troubleshooting.md) — first-run errors and what they mean
|
|
213
221
|
- [docs/comparison.md](./docs/comparison.md) — how fascicle compares to LangChain, Mastra, and others
|
|
214
222
|
- [docs/adoption-decision.md](./docs/adoption-decision.md) weighs whether to adopt fascicle: the honest case, the risks, and when to reach for something else
|
|
215
|
-
- [
|
|
223
|
+
- [docs/roadmap.md](./docs/roadmap.md) — what has shipped, what is being considered, and what fascicle deliberately will not do
|
|
224
|
+
- [examples/](./examples/) — runnable reference flows; start with [examples/newsroom.ts](./examples/newsroom.ts), the vocabulary tour
|
|
216
225
|
- [docs/viewer.md](./docs/viewer.md) — viewer details and transport options
|
|
217
226
|
|
|
218
227
|
## Contributing
|
|
@@ -221,7 +230,7 @@ Fascicle is early and not accepting outside pull requests yet. Bug reports and f
|
|
|
221
230
|
|
|
222
231
|
## Development
|
|
223
232
|
|
|
224
|
-
This repo is a **single package**. The code is organized as deep modules under `src/`
|
|
233
|
+
This repo is a **single package**. The code is organized as deep modules under `src/` (`core`, `engine`, `composites`, `agents`, `adapters`, `mcp`, `stdio`, `ui`, `otel`, `policy`, `schema`, `testing`, `viewer`), each reachable only through its barrel via the `#<module>` import alias. The umbrella surface at the `src/` root is what publishes to npm as `fascicle`. Architectural boundaries (e.g. core cannot import adapters; engine imports core type-only; no `process.env` outside the audited exceptions) are enforced by the ast-grep rules in `rules/` and a directory-level boundary DAG in `fallow.toml`. The 7 apps under `examples/*/` are separate workspace members that consume the library via `fascicle: workspace:*`.
|
|
225
234
|
|
|
226
235
|
```bash
|
|
227
236
|
pnpm install
|
package/dist/adapters.d.ts
CHANGED
package/dist/agents.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as Step } from "./types-BqUY6nRX.js";
|
|
2
2
|
import { r as ToolSchema } from "./types-BCtKsxrX.js";
|
|
3
|
-
import { a as Engine } from "./types-
|
|
3
|
+
import { a as Engine, i as EffortLevel } from "./types-CXBB4aIM.js";
|
|
4
4
|
|
|
5
5
|
//#region src/agents/define_agent.d.ts
|
|
6
6
|
type AgentBuiltPrompt = string | {
|
|
@@ -19,6 +19,15 @@ type DefineAgentConfig<i, o> = {
|
|
|
19
19
|
* the engine default applies.
|
|
20
20
|
*/
|
|
21
21
|
readonly model?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Transport for the model. Same precedence as `model`: code wins over
|
|
24
|
+
* frontmatter `provider`, and the engine default is the last resort.
|
|
25
|
+
*/
|
|
26
|
+
readonly provider?: string; /** Reasoning effort for the call. Wins over frontmatter `effort`. */
|
|
27
|
+
readonly effort?: EffortLevel; /** Sampling temperature. Wins over frontmatter `temperature`. */
|
|
28
|
+
readonly temperature?: number; /** Output token cap. Wins over frontmatter `max_tokens`. */
|
|
29
|
+
readonly max_tokens?: number; /** Nucleus sampling cutoff. Wins over frontmatter `top_p`. */
|
|
30
|
+
readonly top_p?: number;
|
|
22
31
|
/**
|
|
23
32
|
* Forwarded to `engine.generate`: how many times the engine may re-prompt
|
|
24
33
|
* the model to repair schema-invalid output before failing the call.
|
package/dist/agents.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { M as step, P as aborted_error } from "./core-DDRhHu5P.js";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
//#region src/agents/define_agent.ts
|
|
@@ -10,15 +10,17 @@ import { fileURLToPath } from "node:url";
|
|
|
10
10
|
* folds those into a `Step<i, o>`:
|
|
11
11
|
*
|
|
12
12
|
* - The markdown file is read once at factory time. Its YAML-style frontmatter
|
|
13
|
-
* (`name`, `description`, `model`, `
|
|
14
|
-
*
|
|
13
|
+
* (`name`, `description`, `model`, `provider`, `effort`, `temperature`,
|
|
14
|
+
* `max_tokens`, `top_p`) is parsed into the agent's step name and engine
|
|
15
|
+
* call defaults; the body is the system prompt.
|
|
15
16
|
* - Without `build_prompt`, the body (after `{{key}}` substitution against
|
|
16
17
|
* top-level string fields of the input) is the user prompt and no system is
|
|
17
18
|
* sent; the markdown carries the full instruction.
|
|
18
19
|
* - With `build_prompt`, the body is the system prompt and `build_prompt(input)`
|
|
19
20
|
* produces the user message (string, or `{ user, system? }` to override).
|
|
20
|
-
* - `config.model`
|
|
21
|
-
*
|
|
21
|
+
* - `config.model`, `config.provider`, `config.effort`, `config.temperature`,
|
|
22
|
+
* `config.max_tokens`, `config.top_p`, and `config.schema_repair_attempts`
|
|
23
|
+
* shape the call from code. Code wins over frontmatter (frontmatter stays
|
|
22
24
|
* the role default when the app threads nothing; the engine default is the
|
|
23
25
|
* last resort), so a resolved role-to-model table and env overrides actually
|
|
24
26
|
* reach the call.
|
|
@@ -30,8 +32,9 @@ import { fileURLToPath } from "node:url";
|
|
|
30
32
|
* in; wrap with `retry()` from core if you need it.
|
|
31
33
|
*
|
|
32
34
|
* Frontmatter parser is intentionally tiny (no gray-matter): bare `key: value`
|
|
33
|
-
* lines, optional `'`/`"` quotes, `temperature` coerced
|
|
34
|
-
*
|
|
35
|
+
* lines, optional `'`/`"` quotes, `temperature`/`max_tokens`/`top_p` coerced
|
|
36
|
+
* to number, `effort` validated against the engine's levels. Anything richer
|
|
37
|
+
* should go through `build_prompt`.
|
|
35
38
|
*/
|
|
36
39
|
const FRONTMATTER_OPEN = /^---\s*\r?\n/;
|
|
37
40
|
const FRONTMATTER_CLOSE = /^---\s*$/m;
|
|
@@ -66,18 +69,35 @@ function split_frontmatter(content) {
|
|
|
66
69
|
};
|
|
67
70
|
}
|
|
68
71
|
/**
|
|
69
|
-
* Coerce a
|
|
70
|
-
* `raw` is the pre-unquote text, so the error message echoes what the
|
|
72
|
+
* Coerce a numeric frontmatter value to a finite number, throwing on anything
|
|
73
|
+
* else. `raw` is the pre-unquote text, so the error message echoes what the
|
|
74
|
+
* file held.
|
|
71
75
|
*/
|
|
72
|
-
function
|
|
76
|
+
function parse_number(key, value, raw) {
|
|
73
77
|
const n = Number(value);
|
|
74
|
-
if (!Number.isFinite(n)) throw new Error(`define_agent:
|
|
78
|
+
if (!Number.isFinite(n)) throw new Error(`define_agent: ${key} must be a number, got: ${raw}`);
|
|
75
79
|
return n;
|
|
76
80
|
}
|
|
81
|
+
const EFFORT_LEVELS = {
|
|
82
|
+
none: true,
|
|
83
|
+
low: true,
|
|
84
|
+
medium: true,
|
|
85
|
+
high: true,
|
|
86
|
+
xhigh: true,
|
|
87
|
+
max: true
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Validate an `effort` value against the engine's `EffortLevel` union,
|
|
91
|
+
* throwing at factory time so a typo'd level never reaches a live call.
|
|
92
|
+
*/
|
|
93
|
+
function parse_effort(value, raw) {
|
|
94
|
+
if (!Object.hasOwn(EFFORT_LEVELS, value)) throw new Error(`define_agent: effort must be one of ${Object.keys(EFFORT_LEVELS).join(", ")}, got: ${raw}`);
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
77
97
|
/**
|
|
78
98
|
* Parse one `key: value` frontmatter line into `out`. Blank and `#` comment
|
|
79
99
|
* lines are skipped; a line without a colon throws; unrecognized keys are
|
|
80
|
-
* ignored so only `
|
|
100
|
+
* ignored so only the `Frontmatter` fields reach the agent.
|
|
81
101
|
*/
|
|
82
102
|
function assign_frontmatter_field(out, raw) {
|
|
83
103
|
const line = raw.trim();
|
|
@@ -87,19 +107,24 @@ function assign_frontmatter_field(out, raw) {
|
|
|
87
107
|
const key = line.slice(0, colon_idx).trim();
|
|
88
108
|
const value_raw = line.slice(colon_idx + 1).trim();
|
|
89
109
|
const value = unquote(value_raw);
|
|
90
|
-
if (key === "name" || key === "description" || key === "model") {
|
|
110
|
+
if (key === "name" || key === "description" || key === "model" || key === "provider") {
|
|
91
111
|
out[key] = value;
|
|
92
112
|
return;
|
|
93
113
|
}
|
|
94
|
-
if (key === "temperature"
|
|
114
|
+
if (key === "temperature" || key === "max_tokens" || key === "top_p") {
|
|
115
|
+
out[key] = parse_number(key, value, value_raw);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (key === "effort") out.effort = parse_effort(value, value_raw);
|
|
95
119
|
}
|
|
96
120
|
/**
|
|
97
121
|
* Split a markdown file into frontmatter fields and prompt body.
|
|
98
122
|
*
|
|
99
123
|
* Parses only the flat `key: value` subset of YAML that agent files need:
|
|
100
|
-
* recognized keys are `name`, `description`, `model`,
|
|
101
|
-
* (
|
|
102
|
-
*
|
|
124
|
+
* recognized keys are `name`, `description`, `model`, `provider`, `effort`
|
|
125
|
+
* (validated against the engine's levels), and `temperature`/`max_tokens`/
|
|
126
|
+
* `top_p` (coerced to numbers); unrecognized keys are ignored. A file without
|
|
127
|
+
* an opening `---` is all body. Malformed frontmatter throws rather than
|
|
103
128
|
* silently producing a wrong prompt.
|
|
104
129
|
*/
|
|
105
130
|
function parse_frontmatter(content) {
|
|
@@ -141,6 +166,26 @@ function substitute(template, input) {
|
|
|
141
166
|
});
|
|
142
167
|
}
|
|
143
168
|
/**
|
|
169
|
+
* Fold the caller-shaped generation knobs onto `opts` with code config
|
|
170
|
+
* winning over frontmatter (the precedence `model` has always used; the
|
|
171
|
+
* engine default stays the last resort). Unset knobs leave their key off the
|
|
172
|
+
* options object entirely rather than present-as-undefined.
|
|
173
|
+
*/
|
|
174
|
+
function apply_call_knobs(opts, config, frontmatter) {
|
|
175
|
+
const model = config.model ?? frontmatter.model;
|
|
176
|
+
if (model !== void 0) opts.model = model;
|
|
177
|
+
const provider = config.provider ?? frontmatter.provider;
|
|
178
|
+
if (provider !== void 0) opts.provider = provider;
|
|
179
|
+
const effort = config.effort ?? frontmatter.effort;
|
|
180
|
+
if (effort !== void 0) opts.effort = effort;
|
|
181
|
+
const temperature = config.temperature ?? frontmatter.temperature;
|
|
182
|
+
if (temperature !== void 0) opts.temperature = temperature;
|
|
183
|
+
const max_tokens = config.max_tokens ?? frontmatter.max_tokens;
|
|
184
|
+
if (max_tokens !== void 0) opts.max_tokens = max_tokens;
|
|
185
|
+
const top_p = config.top_p ?? frontmatter.top_p;
|
|
186
|
+
if (top_p !== void 0) opts.top_p = top_p;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
144
189
|
* Load a markdown-defined agent as a `Step<i, o>`.
|
|
145
190
|
*
|
|
146
191
|
* Reads and parses the file once at factory time; each run resolves the
|
|
@@ -175,9 +220,7 @@ function define_agent(config) {
|
|
|
175
220
|
trajectory: ctx.trajectory
|
|
176
221
|
};
|
|
177
222
|
if (system_prompt !== void 0 && system_prompt !== "") opts.system = system_prompt;
|
|
178
|
-
|
|
179
|
-
if (model !== void 0) opts.model = model;
|
|
180
|
-
if (frontmatter.temperature !== void 0) opts.temperature = frontmatter.temperature;
|
|
223
|
+
apply_call_knobs(opts, config, frontmatter);
|
|
181
224
|
if (config.schema_repair_attempts !== void 0) opts.schema_repair_attempts = config.schema_repair_attempts;
|
|
182
225
|
const result = await config.engine.generate(opts);
|
|
183
226
|
const resolved_model = `${result.model_resolved.provider}:${result.model_resolved.model_id}`;
|
package/dist/agents.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.js","names":[],"sources":["../src/agents/define_agent.ts"],"sourcesContent":["/**\n * define_agent: markdown-driven loader for simple agents.\n *\n * Most \"agents\" in practice are a system prompt and an output schema with a\n * thin wrapper. `define_agent({ md_path, schema, engine, build_prompt? })`\n * folds those into a `Step<i, o>`:\n *\n * - The markdown file is read once at factory time. Its YAML-style frontmatter\n * (`name`, `description`, `model`, `temperature`) is parsed into the agent's\n * step name and engine call defaults; the body is the system prompt.\n * - Without `build_prompt`, the body (after `{{key}}` substitution against\n * top-level string fields of the input) is the user prompt and no system is\n * sent; the markdown carries the full instruction.\n * - With `build_prompt`, the body is the system prompt and `build_prompt(input)`\n * produces the user message (string, or `{ user, system? }` to override).\n * - `config.model` and `config.schema_repair_attempts` shape the call from\n * code. An explicit `model` wins over frontmatter `model` (frontmatter stays\n * the role default when the app threads nothing; the engine default is the\n * last resort), so a resolved role-to-model table and env overrides actually\n * reach the call.\n *\n * The factory keeps no engine state. Each call delegates to `engine.generate`\n * with the resolved prompts, the schema, and `ctx.abort` / `ctx.trajectory`\n * threaded through. An `agent.call` trajectory event carries the agent name,\n * resolved model id, and engine-reported usage. No retry or fallback is baked\n * in; wrap with `retry()` from core if you need it.\n *\n * Frontmatter parser is intentionally tiny (no gray-matter): bare `key: value`\n * lines, optional `'`/`\"` quotes, `temperature` coerced to number. Anything\n * richer should go through `build_prompt`.\n */\n\nimport { readFileSync } from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport { aborted_error, step } from '#core'\nimport type { RunContext, Step } from '#core'\nimport type { Engine, GenerateOptions } from '#engine'\nimport type { ToolSchema } from '#schema'\n\nexport type AgentBuiltPrompt =\n | string\n | { readonly user: string; readonly system?: string }\n\nexport type DefineAgentConfig<i, o> = {\n readonly md_path: string | URL\n readonly schema: ToolSchema<o>\n readonly engine: Engine\n readonly name?: string\n readonly build_prompt?: (input: i) => AgentBuiltPrompt\n /**\n * Model for this agent's calls, typically threaded from the app's resolved\n * role-to-model table. Wins over frontmatter `model`; when both are absent\n * the engine default applies.\n */\n readonly model?: string\n /**\n * Forwarded to `engine.generate`: how many times the engine may re-prompt\n * the model to repair schema-invalid output before failing the call.\n */\n readonly schema_repair_attempts?: number\n}\n\ntype Frontmatter = {\n readonly name?: string\n readonly description?: string\n readonly model?: string\n readonly temperature?: number\n}\n\ntype ParsedPrompt = {\n readonly frontmatter: Frontmatter\n readonly body: string\n}\n\nconst FRONTMATTER_OPEN = /^---\\s*\\r?\\n/\nconst FRONTMATTER_CLOSE = /^---\\s*$/m\nconst PLACEHOLDER_RE = /\\{\\{(\\w+)\\}\\}/g\n\n/**\n * Strip one matching pair of surrounding single or double quotes.\n */\nfunction unquote(raw: string): string {\n if (raw.length >= 2) {\n const first = raw[0]\n const last = raw[raw.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\")) {\n return raw.slice(1, -1)\n }\n }\n return raw\n}\n\ntype MutableFrontmatter = { -readonly [K in keyof Frontmatter]: Frontmatter[K] }\n\n/**\n * Locate the frontmatter block and split it from the body.\n *\n * Returns `null` when there is no opening `---` (the file is all body).\n * A block opened but never closed throws rather than silently producing a\n * wrong prompt.\n */\nfunction split_frontmatter(\n content: string,\n): { readonly yaml_block: string; readonly body: string } | null {\n const open_match = content.match(FRONTMATTER_OPEN)\n if (!open_match) return null\n const after_open = content.slice(open_match[0].length)\n const close_match = FRONTMATTER_CLOSE.exec(after_open)\n if (close_match?.index === undefined) {\n throw new Error('define_agent: malformed frontmatter (missing closing `---`)')\n }\n const yaml_block = after_open.slice(0, close_match.index)\n const body = after_open.slice(close_match.index + close_match[0].length).replace(/^\\r?\\n/, '')\n return { yaml_block, body }\n}\n\n/**\n * Coerce a `temperature` value to a finite number, throwing on anything else.\n * `raw` is the pre-unquote text, so the error message echoes what the file held.\n */\nfunction parse_temperature(value: string, raw: string): number {\n const n = Number(value)\n if (!Number.isFinite(n)) {\n throw new Error(`define_agent: temperature must be a number, got: ${raw}`)\n }\n return n\n}\n\n/**\n * Parse one `key: value` frontmatter line into `out`. Blank and `#` comment\n * lines are skipped; a line without a colon throws; unrecognized keys are\n * ignored so only `name`/`description`/`model`/`temperature` reach the agent.\n */\nfunction assign_frontmatter_field(out: MutableFrontmatter, raw: string): void {\n const line = raw.trim()\n if (line === '' || line.startsWith('#')) return\n const colon_idx = line.indexOf(':')\n if (colon_idx === -1) {\n throw new Error(`define_agent: malformed frontmatter line: ${raw}`)\n }\n const key = line.slice(0, colon_idx).trim()\n const value_raw = line.slice(colon_idx + 1).trim()\n const value = unquote(value_raw)\n if (key === 'name' || key === 'description' || key === 'model') {\n out[key] = value\n return\n }\n if (key === 'temperature') {\n out.temperature = parse_temperature(value, value_raw)\n }\n}\n\n/**\n * Split a markdown file into frontmatter fields and prompt body.\n *\n * Parses only the flat `key: value` subset of YAML that agent files need:\n * recognized keys are `name`, `description`, `model`, and `temperature`\n * (coerced to a number); unrecognized keys are ignored. A file without an\n * opening `---` is all body. Malformed frontmatter throws rather than\n * silently producing a wrong prompt.\n */\nfunction parse_frontmatter(content: string): ParsedPrompt {\n const split = split_frontmatter(content)\n if (split === null) return { frontmatter: {}, body: content }\n const out: MutableFrontmatter = {}\n for (const raw of split.yaml_block.split(/\\r?\\n/)) {\n assign_frontmatter_field(out, raw)\n }\n return { frontmatter: out, body: split.body }\n}\n\n/**\n * Read the markdown file from a filesystem path, `URL`, or `file://` string.\n *\n * Accepting all three lets callers pass `new URL('./x.md', import.meta.url)`\n * or its string form without caring about the difference.\n */\nfunction read_md_sync(path: string | URL): string {\n if (path instanceof URL) {\n return readFileSync(fileURLToPath(path), 'utf8')\n }\n if (path.startsWith('file://')) {\n return readFileSync(fileURLToPath(path), 'utf8')\n }\n return readFileSync(path, 'utf8')\n}\n\n/**\n * Replace `{{key}}` placeholders with top-level string fields of the input.\n *\n * Non-string values and unknown keys leave the placeholder untouched, so a\n * typo'd placeholder is visible in the sent prompt instead of vanishing.\n */\nfunction substitute(template: string, input: unknown): string {\n if (input === null || typeof input !== 'object') return template\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n const obj = input as Record<string, unknown>\n return template.replace(PLACEHOLDER_RE, (match, key: string) => {\n const v = obj[key]\n return typeof v === 'string' ? v : match\n })\n}\n\n/**\n * Load a markdown-defined agent as a `Step<i, o>`.\n *\n * Reads and parses the file once at factory time; each run resolves the\n * user/system prompts (via `build_prompt` or `{{key}}` substitution), calls\n * `engine.generate` with the schema and threaded abort/trajectory, and\n * records an `agent.call` event with the resolved model and usage.\n */\nexport function define_agent<i, o>(config: DefineAgentConfig<i, o>): Step<i, o> {\n const text = read_md_sync(config.md_path)\n const { frontmatter, body } = parse_frontmatter(text)\n\n const display_name = config.name ?? frontmatter.name ?? 'agent'\n\n return step<i, o>(display_name, async (input, ctx: RunContext): Promise<o> => {\n if (ctx.abort.aborted) {\n throw new aborted_error('aborted before agent call')\n }\n \n let user_prompt: string\n let system_prompt: string | undefined\n if (config.build_prompt) {\n const built = config.build_prompt(input)\n if (typeof built === 'string') {\n user_prompt = built\n system_prompt = body\n } else {\n user_prompt = built.user\n system_prompt = built.system ?? body\n }\n } else {\n user_prompt = substitute(body, input)\n system_prompt = undefined\n }\n \n const opts: GenerateOptions<o> = {\n prompt: user_prompt,\n schema: config.schema,\n abort: ctx.abort,\n trajectory: ctx.trajectory,\n }\n if (system_prompt !== undefined && system_prompt !== '') {\n opts.system = system_prompt\n }\n const model = config.model ?? frontmatter.model\n if (model !== undefined) opts.model = model\n if (frontmatter.temperature !== undefined) opts.temperature = frontmatter.temperature\n if (config.schema_repair_attempts !== undefined) {\n opts.schema_repair_attempts = config.schema_repair_attempts\n }\n \n const result = await config.engine.generate<o>(opts)\n \n const resolved_model = `${result.model_resolved.provider}:${result.model_resolved.model_id}`\n ctx.trajectory.record({\n kind: 'agent.call',\n name: display_name,\n model: resolved_model,\n usage: result.usage,\n })\n \n return result.content\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,iBAAiB;;;;AAKvB,SAAS,QAAQ,KAAqB;CACpC,IAAI,IAAI,UAAU,GAAG;EACnB,MAAM,QAAQ,IAAI;EAClB,MAAM,OAAO,IAAI,IAAI,SAAS;EAC9B,IAAK,UAAU,QAAO,SAAS,QAAS,UAAU,OAAO,SAAS,KAChE,OAAO,IAAI,MAAM,GAAG,EAAE;CAE1B;CACA,OAAO;AACT;;;;;;;;AAWA,SAAS,kBACP,SAC+D;CAC/D,MAAM,aAAa,QAAQ,MAAM,gBAAgB;CACjD,IAAI,CAAC,YAAY,OAAO;CACxB,MAAM,aAAa,QAAQ,MAAM,WAAW,EAAE,CAAC,MAAM;CACrD,MAAM,cAAc,kBAAkB,KAAK,UAAU;CACrD,IAAI,aAAa,UAAU,KAAA,GACzB,MAAM,IAAI,MAAM,6DAA6D;CAI/E,OAAO;EAAE,YAFU,WAAW,MAAM,GAAG,YAAY,KAEjC;EAAG,MADR,WAAW,MAAM,YAAY,QAAQ,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC,QAAQ,UAAU,EACnE;CAAE;AAC5B;;;;;AAMA,SAAS,kBAAkB,OAAe,KAAqB;CAC7D,MAAM,IAAI,OAAO,KAAK;CACtB,IAAI,CAAC,OAAO,SAAS,CAAC,GACpB,MAAM,IAAI,MAAM,oDAAoD,KAAK;CAE3E,OAAO;AACT;;;;;;AAOA,SAAS,yBAAyB,KAAyB,KAAmB;CAC5E,MAAM,OAAO,IAAI,KAAK;CAC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E,aAAa,SAAS,kBADjB,aAAa,OAAO,OACkB,CAAC;CAEpD,MAAM,eAAe,OAAO,QAAQ,YAAY,QAAQ;CAExD,OAAO,KAAW,cAAc,OAAO,OAAO,QAAgC;EAC5E,IAAI,IAAI,MAAM,SACZ,MAAM,IAAI,cAAc,2BAA2B;EAGrD,IAAI;EACJ,IAAI;EACJ,IAAI,OAAO,cAAc;GACvB,MAAM,QAAQ,OAAO,aAAa,KAAK;GACvC,IAAI,OAAO,UAAU,UAAU;IAC7B,cAAc;IACd,gBAAgB;GAClB,OAAO;IACL,cAAc,MAAM;IACpB,gBAAgB,MAAM,UAAU;GAClC;EACF,OAAO;GACL,cAAc,WAAW,MAAM,KAAK;GACpC,gBAAgB,KAAA;EAClB;EAEA,MAAM,OAA2B;GAC/B,QAAQ;GACR,QAAQ,OAAO;GACf,OAAO,IAAI;GACX,YAAY,IAAI;EAClB;EACA,IAAI,kBAAkB,KAAA,KAAa,kBAAkB,IACnD,KAAK,SAAS;EAEhB,MAAM,QAAQ,OAAO,SAAS,YAAY;EAC1C,IAAI,UAAU,KAAA,GAAW,KAAK,QAAQ;EACtC,IAAI,YAAY,gBAAgB,KAAA,GAAW,KAAK,cAAc,YAAY;EAC1E,IAAI,OAAO,2BAA2B,KAAA,GACpC,KAAK,yBAAyB,OAAO;EAGvC,MAAM,SAAS,MAAM,OAAO,OAAO,SAAY,IAAI;EAEnD,MAAM,iBAAiB,GAAG,OAAO,eAAe,SAAS,GAAG,OAAO,eAAe;EAClF,IAAI,WAAW,OAAO;GACpB,MAAM;GACN,MAAM;GACN,OAAO;GACP,OAAO,OAAO;EAChB,CAAC;EAED,OAAO,OAAO;CAChB,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"agents.js","names":[],"sources":["../src/agents/define_agent.ts"],"sourcesContent":["/**\n * define_agent: markdown-driven loader for simple agents.\n *\n * Most \"agents\" in practice are a system prompt and an output schema with a\n * thin wrapper. `define_agent({ md_path, schema, engine, build_prompt? })`\n * folds those into a `Step<i, o>`:\n *\n * - The markdown file is read once at factory time. Its YAML-style frontmatter\n * (`name`, `description`, `model`, `provider`, `effort`, `temperature`,\n * `max_tokens`, `top_p`) is parsed into the agent's step name and engine\n * call defaults; the body is the system prompt.\n * - Without `build_prompt`, the body (after `{{key}}` substitution against\n * top-level string fields of the input) is the user prompt and no system is\n * sent; the markdown carries the full instruction.\n * - With `build_prompt`, the body is the system prompt and `build_prompt(input)`\n * produces the user message (string, or `{ user, system? }` to override).\n * - `config.model`, `config.provider`, `config.effort`, `config.temperature`,\n * `config.max_tokens`, `config.top_p`, and `config.schema_repair_attempts`\n * shape the call from code. Code wins over frontmatter (frontmatter stays\n * the role default when the app threads nothing; the engine default is the\n * last resort), so a resolved role-to-model table and env overrides actually\n * reach the call.\n *\n * The factory keeps no engine state. Each call delegates to `engine.generate`\n * with the resolved prompts, the schema, and `ctx.abort` / `ctx.trajectory`\n * threaded through. An `agent.call` trajectory event carries the agent name,\n * resolved model id, and engine-reported usage. No retry or fallback is baked\n * in; wrap with `retry()` from core if you need it.\n *\n * Frontmatter parser is intentionally tiny (no gray-matter): bare `key: value`\n * lines, optional `'`/`\"` quotes, `temperature`/`max_tokens`/`top_p` coerced\n * to number, `effort` validated against the engine's levels. Anything richer\n * should go through `build_prompt`.\n */\n\nimport { readFileSync } from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport { aborted_error, step } from '#core'\nimport type { RunContext, Step } from '#core'\nimport type { EffortLevel, Engine, GenerateOptions } from '#engine'\nimport type { ToolSchema } from '#schema'\n\nexport type AgentBuiltPrompt =\n | string\n | { readonly user: string; readonly system?: string }\n\nexport type DefineAgentConfig<i, o> = {\n readonly md_path: string | URL\n readonly schema: ToolSchema<o>\n readonly engine: Engine\n readonly name?: string\n readonly build_prompt?: (input: i) => AgentBuiltPrompt\n /**\n * Model for this agent's calls, typically threaded from the app's resolved\n * role-to-model table. Wins over frontmatter `model`; when both are absent\n * the engine default applies.\n */\n readonly model?: string\n /**\n * Transport for the model. Same precedence as `model`: code wins over\n * frontmatter `provider`, and the engine default is the last resort.\n */\n readonly provider?: string\n /** Reasoning effort for the call. Wins over frontmatter `effort`. */\n readonly effort?: EffortLevel\n /** Sampling temperature. Wins over frontmatter `temperature`. */\n readonly temperature?: number\n /** Output token cap. Wins over frontmatter `max_tokens`. */\n readonly max_tokens?: number\n /** Nucleus sampling cutoff. Wins over frontmatter `top_p`. */\n readonly top_p?: number\n /**\n * Forwarded to `engine.generate`: how many times the engine may re-prompt\n * the model to repair schema-invalid output before failing the call.\n */\n readonly schema_repair_attempts?: number\n}\n\ntype Frontmatter = {\n readonly name?: string\n readonly description?: string\n readonly model?: string\n readonly provider?: string\n readonly effort?: EffortLevel\n readonly temperature?: number\n readonly max_tokens?: number\n readonly top_p?: number\n}\n\ntype ParsedPrompt = {\n readonly frontmatter: Frontmatter\n readonly body: string\n}\n\nconst FRONTMATTER_OPEN = /^---\\s*\\r?\\n/\nconst FRONTMATTER_CLOSE = /^---\\s*$/m\nconst PLACEHOLDER_RE = /\\{\\{(\\w+)\\}\\}/g\n\n/**\n * Strip one matching pair of surrounding single or double quotes.\n */\nfunction unquote(raw: string): string {\n if (raw.length >= 2) {\n const first = raw[0]\n const last = raw[raw.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\")) {\n return raw.slice(1, -1)\n }\n }\n return raw\n}\n\ntype MutableFrontmatter = { -readonly [K in keyof Frontmatter]: Frontmatter[K] }\n\n/**\n * Locate the frontmatter block and split it from the body.\n *\n * Returns `null` when there is no opening `---` (the file is all body).\n * A block opened but never closed throws rather than silently producing a\n * wrong prompt.\n */\nfunction split_frontmatter(\n content: string,\n): { readonly yaml_block: string; readonly body: string } | null {\n const open_match = content.match(FRONTMATTER_OPEN)\n if (!open_match) return null\n const after_open = content.slice(open_match[0].length)\n const close_match = FRONTMATTER_CLOSE.exec(after_open)\n if (close_match?.index === undefined) {\n throw new Error('define_agent: malformed frontmatter (missing closing `---`)')\n }\n const yaml_block = after_open.slice(0, close_match.index)\n const body = after_open.slice(close_match.index + close_match[0].length).replace(/^\\r?\\n/, '')\n return { yaml_block, body }\n}\n\n/**\n * Coerce a numeric frontmatter value to a finite number, throwing on anything\n * else. `raw` is the pre-unquote text, so the error message echoes what the\n * file held.\n */\nfunction parse_number(key: string, value: string, raw: string): number {\n const n = Number(value)\n if (!Number.isFinite(n)) {\n throw new Error(`define_agent: ${key} must be a number, got: ${raw}`)\n }\n return n\n}\n\n// A Record keyed by EffortLevel so tsc flags this table whenever the engine's\n// union gains or loses a member; the runtime lookup then validates frontmatter.\nconst EFFORT_LEVELS: Readonly<Record<EffortLevel, true>> = {\n none: true,\n low: true,\n medium: true,\n high: true,\n xhigh: true,\n max: true,\n}\n\n/**\n * Validate an `effort` value against the engine's `EffortLevel` union,\n * throwing at factory time so a typo'd level never reaches a live call.\n */\nfunction parse_effort(value: string, raw: string): EffortLevel {\n if (!Object.hasOwn(EFFORT_LEVELS, value)) {\n throw new Error(\n `define_agent: effort must be one of ${Object.keys(EFFORT_LEVELS).join(', ')}, got: ${raw}`,\n )\n }\n // The hasOwn check above proves membership in the union.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return value as EffortLevel\n}\n\n/**\n * Parse one `key: value` frontmatter line into `out`. Blank and `#` comment\n * lines are skipped; a line without a colon throws; unrecognized keys are\n * ignored so only the `Frontmatter` fields reach the agent.\n */\nfunction assign_frontmatter_field(out: MutableFrontmatter, raw: string): void {\n const line = raw.trim()\n if (line === '' || line.startsWith('#')) return\n const colon_idx = line.indexOf(':')\n if (colon_idx === -1) {\n throw new Error(`define_agent: malformed frontmatter line: ${raw}`)\n }\n const key = line.slice(0, colon_idx).trim()\n const value_raw = line.slice(colon_idx + 1).trim()\n const value = unquote(value_raw)\n if (key === 'name' || key === 'description' || key === 'model' || key === 'provider') {\n out[key] = value\n return\n }\n if (key === 'temperature' || key === 'max_tokens' || key === 'top_p') {\n out[key] = parse_number(key, value, value_raw)\n return\n }\n if (key === 'effort') {\n out.effort = parse_effort(value, value_raw)\n }\n}\n\n/**\n * Split a markdown file into frontmatter fields and prompt body.\n *\n * Parses only the flat `key: value` subset of YAML that agent files need:\n * recognized keys are `name`, `description`, `model`, `provider`, `effort`\n * (validated against the engine's levels), and `temperature`/`max_tokens`/\n * `top_p` (coerced to numbers); unrecognized keys are ignored. A file without\n * an opening `---` is all body. Malformed frontmatter throws rather than\n * silently producing a wrong prompt.\n */\nfunction parse_frontmatter(content: string): ParsedPrompt {\n const split = split_frontmatter(content)\n if (split === null) return { frontmatter: {}, body: content }\n const out: MutableFrontmatter = {}\n for (const raw of split.yaml_block.split(/\\r?\\n/)) {\n assign_frontmatter_field(out, raw)\n }\n return { frontmatter: out, body: split.body }\n}\n\n/**\n * Read the markdown file from a filesystem path, `URL`, or `file://` string.\n *\n * Accepting all three lets callers pass `new URL('./x.md', import.meta.url)`\n * or its string form without caring about the difference.\n */\nfunction read_md_sync(path: string | URL): string {\n if (path instanceof URL) {\n return readFileSync(fileURLToPath(path), 'utf8')\n }\n if (path.startsWith('file://')) {\n return readFileSync(fileURLToPath(path), 'utf8')\n }\n return readFileSync(path, 'utf8')\n}\n\n/**\n * Replace `{{key}}` placeholders with top-level string fields of the input.\n *\n * Non-string values and unknown keys leave the placeholder untouched, so a\n * typo'd placeholder is visible in the sent prompt instead of vanishing.\n */\nfunction substitute(template: string, input: unknown): string {\n if (input === null || typeof input !== 'object') return template\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n const obj = input as Record<string, unknown>\n return template.replace(PLACEHOLDER_RE, (match, key: string) => {\n const v = obj[key]\n return typeof v === 'string' ? v : match\n })\n}\n\n/**\n * Fold the caller-shaped generation knobs onto `opts` with code config\n * winning over frontmatter (the precedence `model` has always used; the\n * engine default stays the last resort). Unset knobs leave their key off the\n * options object entirely rather than present-as-undefined.\n */\nfunction apply_call_knobs<i, o>(\n opts: GenerateOptions<o>,\n config: DefineAgentConfig<i, o>,\n frontmatter: Frontmatter,\n): void {\n const model = config.model ?? frontmatter.model\n if (model !== undefined) opts.model = model\n const provider = config.provider ?? frontmatter.provider\n if (provider !== undefined) opts.provider = provider\n const effort = config.effort ?? frontmatter.effort\n if (effort !== undefined) opts.effort = effort\n const temperature = config.temperature ?? frontmatter.temperature\n if (temperature !== undefined) opts.temperature = temperature\n const max_tokens = config.max_tokens ?? frontmatter.max_tokens\n if (max_tokens !== undefined) opts.max_tokens = max_tokens\n const top_p = config.top_p ?? frontmatter.top_p\n if (top_p !== undefined) opts.top_p = top_p\n}\n\n/**\n * Load a markdown-defined agent as a `Step<i, o>`.\n *\n * Reads and parses the file once at factory time; each run resolves the\n * user/system prompts (via `build_prompt` or `{{key}}` substitution), calls\n * `engine.generate` with the schema and threaded abort/trajectory, and\n * records an `agent.call` event with the resolved model and usage.\n */\nexport function define_agent<i, o>(config: DefineAgentConfig<i, o>): Step<i, o> {\n const text = read_md_sync(config.md_path)\n const { frontmatter, body } = parse_frontmatter(text)\n\n const display_name = config.name ?? frontmatter.name ?? 'agent'\n\n return step<i, o>(display_name, async (input, ctx: RunContext): Promise<o> => {\n if (ctx.abort.aborted) {\n throw new aborted_error('aborted before agent call')\n }\n \n let user_prompt: string\n let system_prompt: string | undefined\n if (config.build_prompt) {\n const built = config.build_prompt(input)\n if (typeof built === 'string') {\n user_prompt = built\n system_prompt = body\n } else {\n user_prompt = built.user\n system_prompt = built.system ?? body\n }\n } else {\n user_prompt = substitute(body, input)\n system_prompt = undefined\n }\n \n const opts: GenerateOptions<o> = {\n prompt: user_prompt,\n schema: config.schema,\n abort: ctx.abort,\n trajectory: ctx.trajectory,\n }\n if (system_prompt !== undefined && system_prompt !== '') {\n opts.system = system_prompt\n }\n apply_call_knobs(opts, config, frontmatter)\n if (config.schema_repair_attempts !== undefined) {\n opts.schema_repair_attempts = config.schema_repair_attempts\n }\n \n const result = await config.engine.generate<o>(opts)\n \n const resolved_model = `${result.model_resolved.provider}:${result.model_resolved.model_id}`\n ctx.trajectory.record({\n kind: 'agent.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AAgB,KAAA;EAClB;EAEA,MAAM,OAA2B;GAC/B,QAAQ;GACR,QAAQ,OAAO;GACf,OAAO,IAAI;GACX,YAAY,IAAI;EAClB;EACA,IAAI,kBAAkB,KAAA,KAAa,kBAAkB,IACnD,KAAK,SAAS;EAEhB,iBAAiB,MAAM,QAAQ,WAAW;EAC1C,IAAI,OAAO,2BAA2B,KAAA,GACpC,KAAK,yBAAyB,OAAO;EAGvC,MAAM,SAAS,MAAM,OAAO,OAAO,SAAY,IAAI;EAEnD,MAAM,iBAAiB,GAAG,OAAO,eAAe,SAAS,GAAG,OAAO,eAAe;EAClF,IAAI,WAAW,OAAO;GACpB,MAAM;GACN,MAAM;GACN,OAAO;GACP,OAAO,OAAO;EAChB,CAAC;EAED,OAAO,OAAO;CAChB,CAAC;AACH"}
|
|
@@ -4,6 +4,6 @@ import { dirname, resolve } from 'node:path';
|
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
|
|
6
6
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
const
|
|
8
|
-
const mod = await import(pathToFileURL(
|
|
7
|
+
const dist_viewer = resolve(here, '..', 'viewer.js');
|
|
8
|
+
const mod = await import(pathToFileURL(dist_viewer).href);
|
|
9
9
|
await mod.run_viewer_cli(process.argv.slice(2));
|