Skip to content
pi-c Artifact [5fd27aab05]
Login

Artifact [5fd27aab05]

Artifact 5fd27aab0566bf6c90ba83de9294b3db45cd4eeb98f69d8bbf8a041bff6e5e3b:


Architecture

State

pic's state lives in SQLite: the journal per workspace (WORKSPACE/.pic/journal.sqlite, pic_* tables) and ~/.pic/pic.sqlite (picu_* tables) for settings, the model catalog, credentials, trust decisions, process records and the conversation lines that ctx archives. Several pic processes share a journal, one conversation each; durability says what is committed when and who may work a conversation.

The operating system seams

What touches the operating system sits behind two interfaces: pic_platform (clocks, entropy, the locks, input files, the SQLite VFS) and pic_executor (file operations and running commands). Host-only code stays behind them, which is what makes the targets in where pic can run reachable.

The terminal interface

The terminal interface is a module in the pic binary (src/tui/). It runs each request as a child pic --json process and knows the run only through Pi's JSON events, so a fault in the interface cannot touch a run.

Where the manual's facts are kept

The manual in the binary

src/manual.inc holds docs/manual and docs/reference as C strings, built by tools/manual-inc.sh; src/help.c serves them to pic help and the terminal's /help TOPIC. They cost about 65 KB of the binary. The text is a constant in the image, so it works with no filesystem.

The credential store

Each stored key is sealed with ChaCha20-Poly1305 (the provider's name bound as associated data), so no plaintext key reaches the database, its WAL, a backup or a log. The sealing key comes from a passphrase, stretched with PBKDF2-HMAC-SHA256 (600,000 iterations, a random salt; both kept in picu_credential_key with a verifier, so a wrong passphrase is refused cleanly). What it protects against is in credentials.

A subscription sign-in is a row of kind oauth: a JSON object (access, refresh, expires in ms, and whatever else its flow keeps, such as OpenAI's issued clientId), sealed whole like a key. Core (cred.c) knows only that shape; the flows are bundled files (oauth_*.c, over oauth.c) that the composition root registers through pic_cred_oauth_register, so core names no provider and links without them. A refresh, before expiry (within a minute) or after a 401 (once per request), runs under an exclusive lock on ~/.pic/credential.lock, not a database transaction, so no writer of pic.sqlite waits on the network. Inside the lock the row is read again: when another process already replaced the refused token, its token is used and the refresh token, which may rotate, is not spent twice. A picu_credential made before the oauth kind is rebuilt once with the wider CHECK.

The behavioural reference

reference/pi.lock.json pins the Pi revision used as the behavioural reference. Pi's source is not part of this repository. The decisions in force are in the implementation plan.