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

Keel: what pic builds and what it hosts

Status: adopted 2026-11-21; first seam (context policy) cut 2026-11-22; RPC command registry cut 2026-11-22

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 is not cut here.