Skip to content
pi-c Keel: what pic builds and what it hosts
Login

Keel: what pic builds and what it hosts

Status: complete 2026-11-23. Adopted 2026-11-21; context policy, RPC command registry and provider registration cut 2026-11-22; the model seam and the client seam cut 2026-11-23; the tool registry, which keel did not plan, cut 2026-11-24, and the stop policy, nor planned, the same day. Two allowance lines remain, each for a reason that holds (below), and six core stubs name two seams keel did not plan: prompt assembly and export.

The full study, with the sorting test, the hard cases and the first audit, is at https://artifacts.craftdesign.group/v/7AcFU37QOBvcGyD3TEMpp#8b97a2dfe17cd12d8d19f2b890bd60dc80e77ed6cfa7b22a13851a27c01d9630. The manifest and its checks are in tiers.

The principle

Core records and enforces; components decide. Core holds the mechanisms that make an agent durable, recoverable and observable. It holds no decision whose right answer depends on a model, a vendor's API or price list, or the current way of prompting. A decision is journaled before it takes effect, recovery reads the record and never asks the component again, and core runs with no components.

Tiers

main.c is the composition root and may name everything. The terminal interface (src/tui/) is a client.

The component ladder

Lowest rung that works: data, then a hook, then a protocol client, then a C interface, then the extension host.

The tier-line rule

A capability is not core by default. Every ticket or design note that adds one carries a line: Tier: ... Clock: ... Record: ... Default: .... A Tier: core line needs a design note in this directory with a status line. A new seam goes to the owner; a new component on an existing seam does not. Tiers move both ways, by a recorded decision.

The first seam: context policy

Status: landed 2026-11-22. Tier: core (src/policy.h). Clock: durability. Record: a pic_hook_run row per answer. Default: the built-in compaction component (src/compact.c).

Before each reply request core asks one question, PreRequest, through the hook host: the facts it owns go in (model, context window, cache lifetime, idle seconds, first request of the submission or not), and the answer is "compact before this request in MODE, for REASON" or nothing. Core journals the answer before it takes effect, asks the component for that mode's plan, and runs it: a summary's requests are journaled and retried as before; a trim commits in one transaction. The first answer for a turn stands, so recovery and retries never ask again. loop.c no longer includes compact.h and decides nothing about compaction: Pi's threshold, overflow recovery's switch, lapse detection, the floor and the holdout draw are all the component's. Durability has the invariants.

How settings are scoped

A setting belongs to the tier that decides with it.

What it implies for the MCP seam (not built)

An out-of-process component could answer the same question: JSON facts in, a reason and a JSON context out, asked outside any transaction, journaled before it takes effect. Three things stand in the way today. The in-process answerer gets the journal's handle, which it uses for Pi's token estimate; an external one would need the estimate among the facts. Planning is in-process C over the journal, so an external component can only name a mode a built-in can plan, unless the plan becomes data (the first kept entry and the text, or the prompts), which pic_compact_plan nearly is. And the question blocks every request, so an external answerer needs a deadline whose default is no answer, as command hooks have.

The check that core stands alone is now real: check 5 in tiers links the core files with the vendored libraries alone, and ci/tiers.stubs lists the bundled symbols core still takes, each a seam not yet cut.

The second seam: the RPC command registry

Status: landed 2026-11-22. Tier: core (src/rpc.h). Clock: pi. Record: none; a command that changes the journal records what it changes as before. Default: src/listings.c answers get_available_models (the catalog and the models file) and get_commands (templates and skills); src/rewind.c answers rewind.

A component declares its commands (name, help, flags, an answer function) and the composition root hands them to the RPC server, which dispatches by name and owns the response, so every command keeps Pi's shape. rpc.c no longer includes catalog.h, compact.h, prompts.h or skills.h. Compaction did not need a command: compact is core's mechanism (pic_compact_now), and what rpc.c read from compact.c, whether compaction is automatic for get_state and the token estimate for get_session_stats and compact's result, now comes through the context policy (automatic, tokens in src/policy.h). The allowance fell from 29 to 25 lines and the stubs from 29 to 20. Architecture says how a component registers a command.

The same registry is how the terminal interface could reach components later. Most of its allowance lines (src/tui/app.c including compact.h, models.h, prompts.h, skills.h, procs.h, hooks.h) say "needs an RPC command": each would become a registered command the client asks over Pi's protocol, as get_commands and get_available_models already are. That seam was cut later; see the fifth seam.

The third seam: provider registration

Status: landed 2026-11-22. Tier: core (src/provider_http.h). Clock: durability. Record: none new; a reply is journaled in both forms as before. Default: the four bundled adapters (src/provider_anthropic.c, provider_chat.c, provider_responses.c, provider_gemini.c), registered by the composition root.

An adapter declares its API, how to open a provider for a model (request building and stream decoding stay behind pic_provider), how long a long-retention cache lives, its tool-call id rule and the content shapes its requests name. Core looks the adapter up by the model's API, asks it for the cache lifetime, and the transform layer's pic_norm_id and pic_content dispatch to its rule and shapes. What stays core is mechanism: the shared POST and its retries, the key's attachment, the cacheRetention setting with short (300 seconds), none, and an hour for long where the adapter does not say, the default id rule, Pi's own shapes, and the image budget. The Messages API's conversion to the neutral form moved into its adapter; the scripted provider now replies in the neutral form itself, so core runs with no adapter at all, and the version-3 migration keeps a frozen copy of the conversion it was written against. The allowance fell from 25 to 14 lines and the stubs from 20 to

  1. Provider adapters says how to add one.

Refusal classification did not move: its rows are keyed by provider, not by wire API (OpenRouter and OpenAI share an API and differ in what a 402 means), and they already reach core through the credential seam (pic_cred_health_ops). The adapter keeps a probe slot, NULL for now, where the next landing puts free key checks (a provider's key or balance endpoint, else a models-list call). pic.h then still included models.h and loop.c priced replies from the registry; the fourth seam ended both.

The fourth seam: the model source

Status: landed 2026-11-23. Tier: core (src/model.h). Clock: pi. Record: none new; a reply's price is journaled with its usage as before. Default: src/models.c, registered by the composition root.

Core owns the model a request uses (pic_model) and Pi's thinking-level rules over it, and asks the registered source two questions: what a name means (provider, wire API, endpoint, key, limits, dialect switches, price) and what a reply costs. The built-in providers, the catalog, the models file, compat detection and the cost formula stay in the source; core names none of them. The wire API is now a name (Pi's, as models name it) rather than an enumeration, so adapters register under it and no core header names a vendor. With no source, nothing resolves and replies are journaled unpriced. pic.h and loop.c no longer include models.h: the allowance fell from 14 to 12 and the stubs from 16 to 9.

The fifth seam: the client asks commands

Status: landed 2026-11-23. Tier: core (src/rpc.h, src/rpc_core.c). Clock: pi. Record: none; a command that changes state records what it changes as before. Default: the terminal interface.

The terminal interface reaches components and the user's state only by asking commands: the composition root hands it ask (pic_tui_options), which answers Pi's RPC JSON in the interface's process with the same registry pic --mode rpc uses (pic_rpc_answer). Each answer lives with its owner: help and the changelog in help.c, templates, skills, providers, instruction files and a folder's files in listings.c, compaction settings in compact.c, settings, trust, the Ctrl+P scope, bug reports, phones, hooks and process records in core (rpc_core.c). The @file walk moved into ignore.c behind list_files. Check 8 in tiers links core and the client alone and finds nothing the client takes from a component. The allowance fell from 12 to 2.

What it enables (not built): every one of these is an RPC command, so another client (an editor plugin, a phone, a second terminal) can show the same help, settings, file completion, providers and templates the built-in interface does, and the interface could later run against a pic --mode rpc child instead of in process.

What remains, and why

The sixth seam: the tool registry

Status: landed 2026-11-24. Tier: core (src/toolreg.h, src/toolreg.c). Clock: durability. Record: none new; each call's replay safety is recorded with it as before, now from its tool's registration. Default: core's read, bash, edit and write; the composition root registers grep, find and ls (src/search.c) and send_message (src/peer.c).

A tool is a registration: its definition, replay safety, whether it runs alone, its tier and the function that runs it. The tool flags and the defaultTools setting choose among whatever is registered, so a component can add tools at startup or for a session; MCP, web fetch and UTCP will reach core this way. The stubs fell from 9 to 6. Architecture has the interface and its rules.

The seventh seam: the stop policy

Status: landed 2026-11-24 (loops, monitors and goals). Tier: core (src/policy.h). Clock: durability. Record: a pic_hook_run row per answer. Default: no policy; requests end as they do now; the composition root registers the goal component (src/goal.c).

When a request is about to end answered in a conversation with an active goal, core runs the goal's check command journaled as a hook run, asks the policy one question (done, continue or needs the person) with facts from the journal, journals the answer before acting on it, and acts in the transaction that makes the reply the answer. Core enforces the rounds and stalls that bound a goal; the component decides whether it is met. A judge model can answer on the same seam later.