garage44.eu/jeroen/pinnacle

logclone: git clone https://garage44.eu/jeroen/pinnacle.git

.. /docs/agent-environment.md

raw

The agent as system software

A study, 2026-11-26, for the question: how should Pinnacle build the environment an agent works in, and the agent itself, so that it is part of the system rather than a program like Claude Code that happens to run on it? It works out the agent section of terminal-and-agent.md against what exists in the tree today, what the operating-system vendors shipped in 2025–2026, what the standalone agents are made of, and what a model on the device can do. The roadmap has the steps; this has the reasons.

The answer in one paragraph

A standalone agent is mostly a work-around. Every part of Claude Code that is not the model loop exists because the OS under it lacks something: permission rules on command text because a shell command is untyped bytes; a sandbox around bash because a process starts with every right its user has; hooks because there is no event the system raises; CLAUDE.md because programs do not say what they do; MCP servers as separate processes because apps have no way to be asked; a transcript file because the terminal keeps nothing; a 97 % "approve" rate because the dialog asks about a string, not an effect. Pinnacle has, or is building, the thing each of these stands in for: channels and handles with no ambient authority, confined apps, typed records instead of a byte stream, services that describe their verbs, a display server nothing can fake, a vault, and contacts with keys. So the agent environment is the environment Pinnacle is already building for people, and the agent is its second user. What is left to build for the agent is small and deterministic: a model service that owns the connection, a gatekeeper that turns the model's requests into messages it may send, a log, a budget, a mark on input the agent synthesises, and the taint rule. None of it needs the model, and none of it goes in the kernel.

What the standalone agents are made of

The harness around a model, as Claude Code (TypeScript, ~5 MB of its own code on a 95 MB Bun runtime), Codex CLI (Rust) and goose (Rust) build it, and what each part leans on:

PartTodayLeans onIn Pinnacle
Model clientHTTPS to one vendor, key in an environment variable or a fileTLS, env, keychainThe model service: the only program with the network, the key in the vault, every prompt logged
ContextSystem prompt + CLAUDE.md hierarchy + tool schemas + transcriptFilesystem walk, gitThe session document (records in the vault), the describe answers of the services the task may reach
ToolsBuilt-ins + MCP servers as child processes or HTTPSpawn, pipes, networkServices' verbs. A tool is a verb of a service the task holds a handle to; there is no second registry
Permissionsdeny → ask → allow on parsed command text; a model classifier in auto mode. The docs say the rules "aren't a security boundary"Nothing: string matchingHandles. What was not given does not exist in the prompt. The question to the person is about an effect class, not a string
SandboxBash only (bubblewrap + socat, Seatbelt); Read/Edit/Write, MCP servers, hooks run unconfined; ~/.ssh readableNamespaces, seccomp, LandlockThe process model: a task is a program with the handles it was given and no path to anything else. There is no unconfined part
Hooks34 events, shell scripts, exit code 2 blocksShellThe gatekeeper's policy and the audit log; no user scripts at first
MemoryCLAUDE.md, ~/.claude/projects/…/memory/FilesystemNotes in the vault, per app folder, readable by the person in Notes
SessionJSONL transcripts, swept after 30 days$HOMEThe terminal's session document; a record is what is kept, copied, shared
CompactionThe model summarises; a boundary markerThe APIStays with the model. Its summary is a record
SubagentsSame binary, own context, optional worktree, shared budgetSpawn, gitA task spawned by the gatekeeper with a subset of the handles and of the budget
UIA TUI in a PTY; editors over ACP (JSON-RPC: prompt, update, request_permission, the editor owns fs and terminal)PTY, escape codesThe terminal, Messages (the agent as a contact), the display server's act protocol. ACP's shape is right: the host owns the files and the terminal, the agent asks
RemoteOutbound polling to the vendor; the transcript on their serversTLS egressThe p2p layer: a stream to the agent on another of the person's devices, the contact's key as the host key

Two conclusions from this table. First, the parts worth moving into the system are identity and boundary, the tool registry, the host protocol and the audit log; every 2025–2026 incident below was one of those implemented as application code. Second, the loop, context assembly and compaction stay with the model: they need it, and a system that tried to own them would bind itself to one vendor's API, which changed shape twice in 2026 (MCP's July revision dropped sessions, the initialize handshake, sampling and roots). Pinnacle should not speak MCP to its own services; describe is smaller and ours. An MCP bridge for outside tools can come later, as a program.

The incidents, and which part failed

What the vendors converged on, 2025–2026

Apple (App Intents 2.0 and App Schemas, Siri AI on iOS 27), Google (Android 17's AppFunctions, "the on-device equivalent of MCP"), and Microsoft (Windows agent connectors, an MCP proxy, an Agent Workspace with its own account) agree on five things, and Pinnacle's design already has each:

  1. Structured actions, not pixels. Apps declare typed verbs the system indexes and calls in the background; screen automation survives only as Google's fallback and in Microsoft's separate desktop. Rabbit's R1, whose "large action model" was Playwright scripts, is the cautionary tale. Pinnacle: describe, and the act protocol on the UI tree only for what has no verb.
  2. The OS owns the connection and the identity. Windows proxies every MCP call; Android grants EXECUTE_APP_FUNCTIONS to the system assistant only; Apple's orchestrator decides what goes to Private Cloud Compute. Pinnacle: the model service.
  3. Risk-tiered confirmation. Apple derives a tier from an intent's schema (delete or send out = high, change shared content = medium), ties the high tier to an unlocked device, and lets an app make its policy stricter but never looser, enforced by the compiler. Pinnacle has no tiers yet; see below.
  4. Honest about injection. Apple's WWDC26 security session, Microsoft's documentation, OpenAI ("unlikely to ever be fully solved") and Anthropic all say in writing that indirect prompt injection is open and that model-side defences are a second layer. Containment is the baseline.
  5. Off by default, a visible indicator while acting, a stop at any time. Pinnacle: no host set means no agent; the status bar; the Process handle.

Four things are contested, and Pinnacle's design takes a side on each:

Where the agent lives

Three programs and one rule, as agreed in terminal-and-agent.md, with what the tree needs for each. The principle stands: assume the model is hijacked, and make that not matter. Everything it says is a request.

The model service

Owns one connection to the host the person chose, is the only program with the network, logs every prompt, and is off until Settings → Agent names a host. It offers one interface to everything above it: a conversation in, text and tool-call records out, whoever answers. The host is a setting: a provider's API over TLS first; the person's own machine found through the DHT, through NATs by hole punching (the midas hub's machines, for one); a model on the device behind the same interface one day.

What rt lacks for it: http_get is GET only, HTTP/1.0, no headers, no chunked encoding, no streaming (rt/src/lib.rs); a provider needs POST, an authorisation header, chunked replies and server-sent events. And there is no JSON reader anywhere in the tree; the person's rule means an own one, which describe will want too. The TLS client (tls::Client) is enough as it is.

The agent gatekeeper

A small deterministic program started per task with that task's handles and no network. It is the only thing that talks to the model service and the only thing that sends messages for the model: it turns a tool-call record into a message on a service's channel, checks it against the verbs the service described and the tier of the effect, writes every action to an append-only log in the vault, counts it against a budget, and asks the person through the display server where the tier says so. Model output never holds a handle; a handle the task was not given has no name in the prompt.

Why a program per task and not one daemon: a task's rights are its handles, and a process is the unit the kernel gives handles to. Two tasks cannot see each other's folders or channels because there is no call by which they could. A subagent is the same thing again with fewer handles and a share of the budget. Confined apps cannot spawn, so the gatekeeper is a system program, as the terminal is.

What the tree lacks: an append-only log (there is no audit facility; println! reaches the serial console and nothing else), a budget, and a way for a service to know a message came from an agent task rather than the person. The last needs no kernel change: the gatekeeper is the one connecting, so the service knows by the channel. But a verb a service runs for the agent should be the same code it runs for the person; an "agent flag" in the message would be two paths, and the Cartopolis simulator's rule holds here: an authorisation decision must not share a path with an ordinary request, and must not be a bit the requester sets.

The display server as the trusted path

It draws the agent's confirmation, as it draws the lock screen: no app or agent can see or fake it, and it says which app the agent is acting in. Input the agent synthesises carries a mark physical input does not, so an app can refuse it for what cannot be undone. InputEvent has no source field today (abi/src/lib.rs); one bit, set only by the display server, is the whole change. The act protocol on the UI tree is for what has no verb; a tree does not exist yet (apps push pixels), but every app's layout is already a pure function of its window's size (layout/), which is how xtask taps them. A tree is that function's result with names on it.

The taint rule

A task that read untrusted text, from the network, a message from a non-contact, or a file another program wrote, may send nothing out of the device without the person confirming. This is Meta's Rule of Two ("untrusted input, sensitive access, a way out: at most two without supervision") made mechanical, and Pinnacle can enforce it where Linux cannot because all IO is channels the gatekeeper handed out: it knows which handle leads to the network or to a contact and which carried untrusted bytes in. It is a label on the task, not on values (CaMeL labels values), which is coarser and always safe: a task that wants to send after reading asks once.

Verbs, tiers and the question to the person

Terminal step 3 gives every service a describe: its verbs and their parameters' types, so the terminal can complete, check and draw a form. The agent's tool schema is the same answer; nothing is written twice. Two things belong beside each verb from the start, because Apple showed they can be derived and enforced rather than left to the model:

The question the person then sees is "Messages: send to Anna what this task read from a web page?", with the task's log a tap away, rather than "Allow curl … | sh?" eighty times. That is the whole defence against fatigue that the evidence supports: fewer questions, each about an effect.

The plan as a program

The person asks a question in the terminal; the model answers with steps. In Claude Code each step is a tool call the model issues after seeing the last result, so the person can only approve one at a time or none. CaMeL's alternative, which the research behind it rates highest, is that the model writes the plan as a program in a restricted language, the interpreter runs it with capabilities on every value, and the quarantined reading of untrusted text can never choose an action.

Pinnacle is about to have that language: Frits (jeroen/frits), designed 2026-11-26 as the system's scripting language, with effects as capabilities in a function's type (fn f() / Net), unforgeable capability values, Secret<T> and untrusted-origin labels, processes preemptible by fuel, one canonical value encoding. A Frits script the model writes for a task is a plan the type checker reads before anything runs: a script whose type says it sends out after reading untrusted input is refused or shown to the person once, as one question, with the script. Fuel is the budget. The script's effects are the handles it needs, so the gatekeeper gives exactly those. This folds three of the agent's parts (tool checking, taint, budget) into one mechanism that is also how the person scripts the device, and it is why the terminal's command language stays small (pipelines, no loops): control belongs in programs, and Frits is the program.

Until Frits runs, the gatekeeper does the same checks per tool call; the records protocol does not change when the plan becomes a script, because a script's output is records too.

Undo

The design wants a pfs snapshot at a task's start so that undoing the task is one act. pfs never overwrites content or table blocks in place and journals every change (pfs/src/lib.rs), which is most of a snapshot, but it has no block reference counts, shared extents or generations, so two trees cannot share a block yet. Two ways in, in order:

  1. An inverse log first. For every verb with an inverse, the gatekeeper logs the inverse; for a file written under a size limit, the pre-image. Undo replays the log backwards. This covers what the agent does through services, costs nothing in pfs, and is what the records session shows the person as "what this task did".
  2. Reference-counted blocks in pfs later, when the Files app wants versions too: a snapshot is then a second root sharing every block, and a task's writes diverge from it. This is the Kairos shape, holding effects until released, done in the file system rather than a monitor.

The model

Three hosts behind one interface, in the order they become possible:

HostNeedsWhen
A provider's API over TLSPOST, headers, SSE, JSON in rt; the key in the vaultFirst
The person's own machine over the DHT (a midas node, a workstation)NAT hole punching or a relay; a service tag on p2p streams, which have none today (the p2p service treats every incoming stream as an exec request)After the p2p roadmap's hole punching
On the deviceA pure-Rust inference engine; see belowLater, and small

What a model on the device can do, as of late 2026: a 0.6–2 B model at 4-bit weights (0.5–1.5 GB) classifies intent, picks one tool from a handful, fills a form, summarises or rewrites a paragraph, and extracts JSON, reliably enough (single-turn tool choice ~85–95 % on the function-calling benchmarks for the best 3–4 B models); it fails at multi-step planning, nested calls and anything needing knowledge. Decode speed is memory bandwidth over weight bytes: ~5 tokens/s for a 0.8 GB model on a 4 GB RK3399, ~20–30 on a current phone. The KV cache is not small for a small model (~112 KiB a token for Qwen3-0.6B: 0.9 GB at 8 K context), so a 4 GB device budgets 1 GB of weights and half a GB of cache. The PinePhone Pro's Mali-T860 has no Vulkan at all (panvk dropped Midgard in 2022), so there the path is CPU only, and the Cortex-A72 lacks the sdot instruction the fast int8 kernels want. On a laptop or under QEMU with Venus, a WGSL compute path on wgpu is possible, and mobile Mali needs mobile-tuned shaders before it beats the CPU (llama.cpp's Vulkan path does 3.6 tokens/s against the CPU's 13 on an RK3588).

Pure-Rust engines exist but none is finished: candle's CPU backend is production code and portable (its wgpu backend is a fork and a pending PR); Burn's CubeCL compiles kernels to WGSL but Burn-LM is an alpha; Airframe (2026) is wgpu-only and young; ratchet and wonnx are dormant. The person's rule means an own engine anyway: GGUF in, Q4_K and Q8_0 kernels, NEON and AVX2 on the CPU, a WGSL path second, taking what those show. The useful first milestone is small: the model service maps one Qwen3-class 0.6 B file once (page-aligned tensors, one resident copy for every task), runs it on the CPU, and answers "which verb, with what arguments, or escalate" for a short prompt in under two seconds on an RK3399. That gives the terminal an offline command router and a privacy filter that redacts before anything leaves the device, and keeps the frontier model where it belongs: over the network, for the plan.

NPUs: only the RK3588's has an open, register-level interface (the rocket driver, mainline since Linux 6.18), and it does int8 convolutions at 200 MHz, no transformers. Watch; do not build.

Developing on the device

The agent people compare this to is a coding agent, and Pinnacle cannot be one for its own code: rustc is LLVM, which is C++, and the rule is no C anywhere. So there are two faces, and the design serves both:

What is given up, and what is not reinvented

Given up: a shell for development on the device; text as the universal interface (a tool from outside expects bytes and gets records); MCP servers as code (a service's describe is its schema, and a tool is a package the Store signed and the person installed, never a process the model started); per-action prompts as the safety story; and running every tool call the moment the model asks (a plan is checked first).

Not reinvented: the model's API, context compaction, the system prompt with the tool schemas, the models themselves. The model service speaks the provider's protocol and nothing above it knows which provider.

Order

The roadmap's steps 3–6, with what this study adds:

  1. What the tree needs first, each useful on its own: a kernel file handle (terminal step 3 wants it too); rt::net with POST, headers, chunked replies and server-sent events; an own JSON reader; an effect class and an inverse per verb in describe and the manifest, shown by the Store; one source bit in InputEvent; a service tag on p2p streams; an append-only log file format in the vault.
  2. describe in the services (terminal step 3), with effect classes.
  3. The model service and Settings → Agent: the host, the key in the vault, what was sent, the off switch.
  4. The gatekeeper in the terminal: a task per command line, handles from the person (a file picked is a file handle), the log with inverses, a budget, Stop; confirmations through the display server by effect class; undo from the log.
  5. The taint rule, as a label on the task's handles.
  6. The UI tree and the act protocol with the synthetic-input mark, from the layout functions, for apps without a verb; the status bar's indicator.
  7. Frits as the plan: the model writes a script, the checker reads its effects, the person confirms once.
  8. pfs snapshots by reference-counted blocks, when Files wants versions.
  9. A model on the device, CPU first, as the router and the filter.

As built (2026-11-26, session s855)

Steps 0 to 4 are built and in the self-check (handles, verbs, model, agent). Where the building found something the design did not say, or said otherwise:

Sources

Harness anatomy: Claude Code docs on permissions, sandboxing, hooks, memory and the agent loop (code.claude.com/docs); Anthropic, "Claude Code sandboxing" (2025-10-20); OpenAI, "Unlocking the Codex harness" (2026-02-04); Willison, "Codex sandbox investigation" (2025-11-09); agentclientprotocol.com; MCP changelogs 2025-11-25 and 2026-07-28. Incidents: Invariant Labs on the GitHub MCP server (2025-05-26); Socket and The Hacker News on Nx s1ngularity (2025-08-26); ReversingLabs on postmark-mcp (2025-09); CSA on Claude Code auto mode (2026-08). Vendors: Apple WWDC26 sessions 240, 343 and 347 ("Secure your app: mitigate risks to agentic features"); Android Developers Blog, "Android 17 is here" (2026-06-16) and AppFunctions 1.0 (2026-11-18); Windows Developer Blog, Build 2025 and Ignite 2025 posts; Microsoft Support, "Experimental agentic features". Research: Debenedetti et al., CaMeL (arXiv 2503.18813); Willison, "The lethal trifecta" (2025-06-16); Meta, "Agents Rule of Two" (2025-10-31); Kairos (arXiv 2610.18457); "Irreversibility budget" (arXiv 2609.00275); Odersky et al., "Tracking capabilities for safer agents" (arXiv 2603.00991); AIOS (arXiv 2403.16971). Models on the device: Google, Gemma 3n and Gemma 4 developer posts; Apple Foundation Models 3 (arXiv 2507.13575); BFCL studies arXiv 2608.22472 and 2610.35981; llama.cpp issues #9853 and #17783 (RK3399 sdot, Mali Vulkan); Mesa's panfrost docs; Linux rocket driver docs; candle PR #3379, FerrisMind/candle, tracel-ai/burn, Navegos/airframe.