phosphor
AGENTS.md17 starsChanged 36 days agoMITView on GitHub
Instructions for coding agents in this repository. CLAUDE.md only imports this file, so edit this one. Keep it short: detail belongs in the linked doc. Phosphor is an Electron desktop app that wraps the pi coding agent (@earendil-works/pi-coding-agent): one pi --mode rpc subprocess per live session, spoken to over JSONL on stdio. Phosphor never imports pi's code; the protocol is hand-mirrored in libs/shared/src/rpc.ts. The same client UI also runs as a PWA (apps/web) against the Host CLI (apps/host). Maps. README.md…
- Installs packages
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 35,117 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
The file
We split this AGENTS.md into the rules it gives an agent
7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 96
One home per helper: Search before writing one.
- Distinctive: line 111
Main stays green: If main is red, fix it in its own PR first.
- Distinctive: line 116
Read the linked doc before touching any of these.
- Very specific: line 147
Every interactive session shares one provider-blind context budget (sessionContextBudget, default 200k).
- Very specific: line 177
Never call window.prompt: Electron makes it throw.
- Very specific: line 192
No dated write-ups: git is the history and the commit message holds the reasoning.
- Very specific: line 198
Use isolated PHOSPHOR_TEST_USER_DATA for dev against a migrated machine.
≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
Instructions for coding agents in this repository. CLAUDE.md only imports this
file, so edit this one. Keep it short: detail belongs in the linked doc.
Phosphor is an Electron desktop app that wraps the pi coding agent
(@earendil-works/pi-coding-agent): one pi --mode rpc subprocess per live
session, spoken to over JSONL on stdio. Phosphor never imports pi's code; the
protocol is hand-mirrored in libs/shared/src/rpc.ts. The same client UI also
runs as a PWA (apps/web) against the Host CLI (apps/host).
Maps. README.md has the repo tree, the only copy.
docs/README.md indexes the docs. Everything in docs/ is present
tense: how Phosphor behaves now, one living contract per surface. Two
exceptions: known-issues.md holds defects that reproduce
today, and future-features.md holds directions that are
not built. A feature moves into its surface's living doc and leaves that file in
the same diff that builds it. remediation.md tracks the
engineering remediation and what is left of it.
Commands
npm run dev # Electron + Vite with HMR (needs pi on PATH)
npm run dev:web # the renderer in a browser, against the mock API
npm run typecheck # all-file audit + Desktop/tests, libraries, Host, Control, tooling, site
npm run lint # eslint + typed oxlint (suppression ratchets) + the dead-mock check
npm run format # prettier --write
npm test # vitest unit tests
npm run test:e2e # builds, then Playwright-Electron against the pi stub
npm run test:e2e:web # the PWA in Chromium and WebKit
npm run validate # all of the above, quiet: PASS/FAIL summary + a log file
npm run check:pr # before a PR: CI's checks + unit tests + the e2e specs you changedInstall with npm ci and npm ci --prefix apps/site. Testing
owns the commands, frozen-test rules, coverage evidence, size budgets and lint
ratchets. CI always runs typecheck, lint, prettier --check ., unit tests and
the size ratchet; on a PR it runs the e2e suites, Supabase and site only for the
apps the PR affects. Run npm run check:pr before opening or updating a PR: it
runs those checks and the e2e spec files you changed. Also run the Desktop e2e
specs for what you touched (IPC, session lifecycle or a visible UI flow) and web
e2e when touching libs/client-ui or libs/host-client.
SKIP_E2E=1 npm run validate stops before the slow part. E2E windows never
appear on your screen.
Architecture in six facts
- One runtime owns This Mac’s lanes per launch. Desktop main decides before
starting sessions: in-app, or the local service over
its owner socket. Packaged macOS and Linux builds default to the service (a
per-user launchd agent or systemd user unit): Desktop installs it in standby
while in-app, then moves lanes to it once, at a later launch. In service mode do not fall back to in-app data or start a
second runtime on disconnect. The sandboxed renderer is UI over typed IPC;
Electron bindings stay in main, reusable Node logic in
libs/*. - IPC is a typed contract. A new channel is an entry in its prefix's map under
libs/shared/src/ipc/, a handler inapps/desktop/electron/ipc/<prefix>-handlers.ts, and a case inlibs/client-ui/src/dev/mockPhosphor.tsif the browser harness uses it.apps/desktop/electron/ipc.tsis only the composition root; the session registry isapps/desktop/electron/registry.ts. - RPC to pi goes through
libs/client-ui/src/lib/rpc.ts(piCall/piCallOk), which unwraps the{success, data?, error?}envelope and surfaces failures on the session's chat. Lint rejects a rawwindow.phosphor.piCommand. libs/shared/src/rpc.tsmirrors pi's protocol with compile-time drift guards (_NoMissingResponseKeys/_NoExtraResponseKeys): a new RPC command updates the command union andRpcResponseDataMap, or it won't compile.- Sessions have independent owners, not a fleet orchestrator. An agent can
act on another lane or machine through the governed catalog,
not a second spawn path. Desktop and Host bind
libs/session-runtime/src/pi/; all callers share the owner's admission and path locks. There is no idle process reaper (known-issues.md S11). Routines run on their execution machine. The Host owns pi's environment, a loopback grant API when enrolled, and a private Unix socket in local mode. Control holds identity and machine metadata, not lane contents or private keys. - Stores (
libs/client-ui/src/stores/, zustand) project main-process state.files.tsandterminal.tsare keyedbyWorkspace[path]; their selectors return a shared frozen empty value, so never mutate it or inline a fresh{}. The current workspace isuseActiveWorkspace(), not a global.
Engineering rules
From the 2026 engineering review. The first three are enforced by CI; the rest are on the author and the reviewer.
- Size. Source files ≤ 400 lines, functions ≤ 80, test files ≤ 800.
tools/scripts/size-budget.mjsgives old offenders one-way ceilings and fails new ones. Split by responsibility, not to dodge the count. - No unhandled promises.
no-floating-promisesandno-misused-promisesare errors wherever a TS project owns the file. Await it, return it, or.catchit into a visible failure;voidonly when the callee handles its own errors.oxlint-suppressions.jsonrecords older violations and only shrinks, aseslint-suppressions.jsondoes for the other rules: never add to either to land a change. - No dead mocks.
npm run lintfails on avi.mockof a module the test never loads. Moving or renaming a module means retargeting its mocks. - One home per helper. Search before writing one. Path checks, process-tree
kills, print-mode runners and fake hosts were each copied two to four times and
drifted apart. Shared code lives in a
libs/*package, imported through its@phosphor/<lib>/…subpath (lint and boundary tests enforce this). - Pin behaviour before changing it. A refactor starts with a characterization test that passes on the old code; a fix starts with a regression test that fails on it, committed first (testing.md).
- Contracts change deliberately. IPC maps, the Host protocol, the control API and extension status keys have freeze tests. Change both ends in one diff.
- A screen that loads data must recover. Load only once what it needs is ready (for example, its lane is active), and load again when that changes. One failed load must not leave a permanent error; test the failing first attempt.
- Shared UI runs in two shells.
libs/client-uitalks only towindow.phosphor, which Electron's preload and the PWA's Host bridge both provide. No Electron or Node imports there. - Main stays green. If main is red, fix it in its own PR first. Never merge on a red or skipped check.
Sharp edges
Read the linked doc before touching any of these.
- In-app session files are edited only through
apps/desktop/electron/pi/session-mutation.ts, inside the path lock resume and deletion share; never callsession-writer.tsdirectly (pi-integration.md). - JSONL framing is strict LF through
JsonlDecoder, neverreadline, which splits on U+2028/U+2029 inside JSON strings. libs/session-runtime/src/pi/pi-paths.tsis the only source of pi's session layout and cwd mangling;apps/desktop/e2e/fixtures/pi-stub.cjscopies the mangling, so keep them in sync.pi -pwaits for stdin EOF: never run it throughexecFile/exec, spawn it throughprint-mode.ts(pi-integration.md).- A live session's title comes from the chat store's
meta.sessionName, because pi writes the file late and the scan lags (same doc, Sessions on disk). apps/desktop/electron/store.tsbuilds its electron-store lazily, so E2E can redirectuserDatafirst.- E2E env hooks (
PHOSPHOR_PI_STUB,PHOSPHOR_E2E_WORKSPACE,PHOSPHOR_TEST_USER_DATA,PHOSPHOR_LOCAL_DAEMON_SOCKET,PHOSPHOR_LOCAL_DAEMON_CONFIG,PHOSPHOR_E2E_OWNER_KEY,PHOSPHOR_MIGRATE,PHOSPHOR_E2E_SERVICE_FEATURES,PHOSPHOR_MIGRATION_CRASH_AT,PHOSPHOR_E2E_LOCKED_POLICY) stay gated on!app.isPackaged. Ungated, they are env-triggered code execution in a shipped app. bootstrapSessionlearns the session path asynchronously, so last-session persistence lives in two places instores/sessions.ts. Read its comments before simplifying.- Session-dir watchers follow sidebar group visibility. No unbounded watch paths.
- Old Claude Code transcripts hold marker blocks pi never emits. Read extensions.md before touching transcript rendering, tool UX or sub-agent UI.
- Claude is a separately versioned pi provider (
pi-claude-cli >= 0.10.0); pi owns its prompt, tools, compaction and thinking. No per-provider compaction toggles. Read cli-providers.md and provider-symmetry.md before changing either side. - Every interactive session shares one provider-blind context budget
(
sessionContextBudget, default 200k); in-run cap changes wait forturn_endoragent_settled(cli-providers.md). - Pi loads six bundled extensions plus the ops and Brain bundles when enabled.
worktree-paths.tsrefuses tool calls that escape a worktree; its four conditions are narrow on purpose.tool-name-guard.tsrewrites malformed tool names before pi persists them (extensions.md). - Status keys (
phosphor-*,claude-*) and widget payloads are unchecked wire contracts (extensions.md). Sub-agents are pi-subagents on both providers (chat.md). - Native modules compile on the release runner and inherit its glibc. Release
jobs pin runner images (never
*-latest) and the Linux floor is glibc 2.35, checked bytools/scripts/check-glibc-floor.mjs(desktop-build.md). - macOS updates by swapping its own bundle beside the installed
.app(updates.md). - MCP credentials belong to pi. Phosphor never holds a token or answers a dialog (mcp.md).
Conventions
- Tests live beside their subject as
*.test.tsuntil RL-03 moves them totest/folders; shared inputs go in sibling__fixtures__/. DOM suites opt in with// @vitest-environment jsdom. Prefer testing pure logic over components. See Testing. - Modals use
ModalOverlay(libs/client-ui/src/components/Modal.tsx), which owns depth-aware Escape. No window-level Escape listeners in modal content. - UI follows style-guide.md. Radii stay tight:
rounded-mdfor rows and cards,rounded-lgfor dialogs,rounded-composeronly for the composer.rounded-xland larger are a lint error. - Never call
window.prompt: Electron makes it throw. UsepromptText/presentTextfromlibs/client-ui/src/stores/prompt.ts(lint enforces it). - Choose behaviour by a
Platformcapability, never by screen width: inlibs/client-ui/srconlycomponents/,platform/andshell/readPlatform.formFactor(lint enforces it). A new Desktop/browser difference is a capability listed inplatform/Platform.test.ts(Web client). - Model-authored HTML renders only in a sandboxed iframe over
phosphor-artifact://(artifact-protocol.ts), neversrcdoc. The iframe never gainsallow-same-originand the policy never gains aconnect-src. phosphor-file://(fs/file-protocol.ts) serves only whatgrantPreviewgranted by token, never a path from the URL. New schemes join the singleprotocol.registerSchemesAsPrivilegedcall inmain.ts; a second call is dropped.- Aliases:
@/islibs/client-ui/src/,@phosphor/shared/islibs/shared/src/(@shared/is a legacy alias for it). - No dated write-ups: git is the history and the commit message holds the
reasoning. If a change makes a
docs/file wrong, that file is in the same diff. Fixing a known issue deletes its row in the same diff.
Running the app
Use isolated PHOSPHOR_TEST_USER_DATA for dev against a migrated machine. Dev does not take over service-owned data; see the launch gate.
npm run dev needs pi on PATH (npm i -g @earendil-works/pi-coding-agent,
Node ≥ 22.19); without it This Mac's home shows the pi setup (Hosts still work). apps/desktop/vite.config.ts
mirrors the renderer block of apps/desktop/electron.vite.config.ts; keep them in
sync. The /run and /e2e skills cover both flows. Never run a packaging build
in the main checkout (desktop-build.md).
Debugging a failing session
~/Library/Logs/Phosphor/phosphor.log (Linux: ~/.config/Phosphor/logs/) records
pi's spawn argv, stderr, unexpected exits, crashes and the inherited PATH. An
assistant message with empty content and totalTokens: 0 means the provider failed
before the model ran: read the provider's own transcript (for pi-claude-cli,
~/.claude/projects/<mangled-cwd>/<session-id>.jsonl, field result). If
cd /tmp && echo hi | pi -p fails too, it is not a Phosphor bug. The /debug skill
has the full procedure.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

