Flat config with two layers. Correctness (type-checked): the headline rules for this codebase are no-floating-promises / no-misused-promises (a lost promise in the agent loop is our primary bug class), switch-exhaustiveness-check (we switch over merge-extensible unions everywhere), no-unnecessary-condition, require-await, and no-explicit-any. Style (@stylistic): 2-space, no semicolons, single quotes, trailing commas, max-len 140 — the existing house style, now enforced instead of drifting between agents. vendor/ is excluded (vendored source keeps upstream style); tests relax the rules that fight test ergonomics (non-null assertions after expects, async mock signatures, non-Error throws). Code adjusted to pass: registry disposers wrap ctx.effect's promise-returning disposer behind a sync () => void (our public API), BlockAssembler gains an invariant-checking mustGet instead of non-null assertions, lastTurnNumber uses findLast, waterfall tails return Promise.resolve instead of async-without-await arrows, and the two deliberate suppressions (non-exhaustive derivation switch, unbound execute pass-through) carry justification comments. yarn lint / yarn lint:fix added.
echo-agent
Runnable demo: stdin chat with a scripted mock model and an echo tool.
What it shows
- A complete Cordis app loaded from
cordis.yml— the standard "stack of plugins" pattern mock-llm.ts— a mockLlmAdapterthat streams scripted responses and calls theechotool when the user types "echo "echo-tool.ts— a tool registered viactx.tools.register()that echoes text back uppercasedsession-jsonl.ts— a minimal persistence plugin: write-behind buffering ofsession/eventnotifications, drained to a JSONL file atsession/flushstdio-chat.ts— a minimal UI plugin: reads stdin lines andsend/steers the agent, renders stream deltas, tool calls, and tool results
Plugin files
| File | Role | Key patterns demonstrated |
|---|---|---|
mock-llm.ts |
LlmAdapter registration |
ctx.llm.registerAdapter(['mock-echo'], …), streaming chunks with proper block-start/block-end protocol |
echo-tool.ts |
Tool registration | ctx.tools.register(defineTool(…)) with typed execute args, tool execution returning ContentBlock[] |
session-jsonl.ts |
Persistence | session/event listener + session/flush drain, fiber-dispose cleanup |
stdio-chat.ts |
UI | agent/stream-chunk, session/event (tool/*), stdin→send/steer |
start.ts |
Bootstrap | Context + Loader + plugin-include wired to cordis.yml |
Run
yarn demo
# or:
node --expose-internals --import tsx examples/echo-agent/start.ts
Type a message and press Enter. "echo " triggers a tool call round-trip
(the mock model requests the echo tool, which echoes the text uppercased,
and the next model step acknowledges it).
The session is persisted to <session-id>.jsonl in the examples/echo-agent/
directory. Clean up with: rm -f examples/echo-agent/*.jsonl