pi-agent-desktop
AGENTS.md954 starsChanged yesterdayMITView on GitHub
Typecheck: node_modules/.bin/tsc --noEmit · Lint: npm run lint Never run next build during dev: it pollutes .next/ and breaks npm run dev. - Building (or starting a fresh next dev) from inside the Pi desktop app's shell fails. The app exports NODE_ENV=production, __NEXT_PRIVATE_ORIGIN and __NEXT_PRIVATE_STANDALONE_CONFIG (its own serialized Next config, from which function values are gone). Next's CLI prefers that serialized config over next.config.ts, so next build dies with TypeError: generate is not a function and a fresh next dev…
- Reads credentials
- 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 33,398 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
8 rules. About 0 are common, 0 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 193
Read the doc for the area you touch before changing it.
- Very specific: line 227
Never assign agent.state.systemPrompt (a getter since pi 0.86).
- Very specific: line 230
Do not re-add the legacy auto_compaction_* event cases or a manual DeepSeek xhigh clamp.
- Very specific: line 235
Never give one iframe both allow-scripts and allow-same-origin.
- Very specific: line 237
No literal homedir() in session-scanner fs calls.
- Very specific: line 243
After an SDK bump run npm run desktop:prepare && npm run desktop:verify.
- Very specific: line 269
After a merge: node scripts/upstream-css-baseline.mjs update <upstream-ref> and npm run drift.
- Very specific: line 289
UI consistency is mandatory (user requirement): Every application menu, dropdown, option picker and autocomplete popup must use the shared …
≈ “Common” is an estimate: at least 1 in 5 of the 43,423 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
Pi Web - Development Notes
Quick Start
npm run dev # port 30141Typecheck: node_modules/.bin/tsc --noEmit · Lint: npm run lint
Never run next build during dev: it pollutes .next/ and breaks npm run dev.
Local environment traps
- Building (or starting a fresh
next dev) from inside the Pi desktop app's shell fails. The app exportsNODE_ENV=production,__NEXT_PRIVATE_ORIGINand__NEXT_PRIVATE_STANDALONE_CONFIG(its own serialized Next config, from which function values are gone). Next's CLI prefers that serialized config overnext.config.ts, sonext builddies withTypeError: generate is not a functionand a freshnext devwithMissing field turbopackMemoryEviction— while a dev server that was already running keeps working, which makes it look like a repo bug.scripts/prepare-desktop.mjsdeletes both__NEXT_PRIVATE_*vars for this exact reason; do the same (or run from a normal terminal) before anynext build/npm run test:e2e. - The
nodeonPATHmay not be the one the project runs on: the Pi app bundles its own runtime, while a dev server started from a terminal uses another install. Check withps -o command= -p $(lsof -nP -iTCP:30141 -sTCP:LISTEN -t). npm run test:e2erefuses to start while a dev server holds.next/dev/lock, andE2E_SERVER_MODE=start(the mode CI uses) needs a production build. Both can be satisfied without touching the dev state by building into the isolated desktop dir and pointing the harness at it:PI_WEB_DESKTOP_BUILD=1 node_modules/next/dist/bin/next build --webpackthenE2E_SERVER_MODE=start PI_WEB_DESKTOP_BUILD=1 node e2e/run.mjs(next.config.tsswapsdistDirto.next-desktop, which is gitignored).- A worktree's
node_modulescan lag the lockfile (created before an SDK bump), which fails tests that pin newer SDK behaviour.npm testrunsnpm run check:depsfirst and stops with the mismatched packages;npm cifixes it. - Windows test fixtures use
scripts/test-platform.mjs: directory links are junctions, unavailable file links skip only their own subtests, and POSIX mode checks remain active on POSIX hosts. Shell-command fixtures select native Git Bash inside the test process; trust fixtures must not inherit the user's ancestor skills. Await session shutdown before deleting MCP working directories. Real PTY integration runs in a child process; fake-clock tests use a controlled PTY. next devrewritesAGENTS.md: it appends a "This is NOT the Next.js you know" block to this file on every start. Preserve the project and user instructions here; review generated additions separately and never reset the entire file to discard development output.
Upgrading pi
pi's packages up to 1.2.0 depend on each other with ^ ranges (1.3.0 pins them exactly), and the published pi-web's dependencies resolve afresh on install (no lockfile ships). Install every @earendil-works/* package the tree holds, the SDK's own dependencies included (pi-codemode, pi-mcp, pi-telemetry, …), with npm install --save-exact, so npm reuses those exact versions for the SDK's ranges. lib/pi-packages.test.mjs fails on any pi package that is not pinned that way; pi-web 0.12.0 pinned four, and installs after pi 1.2.0 paired pi-coding-agent 1.1.0 with pi-codemode 1.2.0.
Architecture
- Browsing (read-only, no AgentSession):
GET /api/sessionslists~/.pi/agent/sessions/;GET /api/sessions/[id]reads the.jsonlthrough SDKSessionManagerhelpers andlib/session-reader.ts, or an open wrapper's in-memorySessionManager.GET /api/agent/runningsnapshots the running ids. - Sending:
POST /api/agent/[id]→startRpcSession()(lib/rpc-manager.ts) creates the AgentSession in-process (createAgentSessionFromServices());session.send(cmd)→session.prompt(). - Events:
GET /api/agent/[id]/eventsstreams SSEdata: {...}fromsession.onEvent(), fed bysession.subscribe(). - Product scope: a light web wrapper around pi, not an IDE or a platform of its own. Before adding a feature, check the out-of-scope list in CONTRIBUTING.md.
- Extension compatibility (principle): extensions written for the pi CLI must behave the same here. Fix display problems in the web client; never add pi-web-only options or fields to the extension API (
ctx.ui.*options,extension_ui_request). pi's TUI (node_modules/@earendil-works/pi-tui) is the reference for what an extension asking for something means.
File Map
app/api/
sessions/route.ts GET list all sessions
sessions/[id]/route.ts GET/PATCH/DELETE session
sessions/[id]/context/route.ts GET ?leafId= — context for a specific leaf
sessions/[id]/export/route.ts GET exported HTML for a session
agent/new/route.ts POST { cwd, message, toolNames?, provider?, modelId? }
agent/[id]/route.ts GET state | POST any command
agent/[id]/events/route.ts GET SSE stream
agent/running/route.ts GET currently-running session ids
agent/running/events/route.ts GET SSE stream of currently-running session ids
agent/tasks/route.ts GET live task snapshots (running step, waiting dialogs, last outcome) for the Tasks page
calendar/route.ts GET ?from=&to= (ms) prompts per session, scheduled runs and planned slots for the Tasks calendar
remote-access/route.ts GET/PUT Tailscale remote-access setting (PUT only from loopback)
network-proxy/route.ts GET/PUT the app's HTTP proxy setting (PUT only from this computer); test/route.ts POST a connection test
push/{config,subscribe,unsubscribe,test}/route.ts Web Push key, device subscriptions, test send
relay/route.ts GET/PUT encrypted relay status and config (PUT local-only)
relay/pairing/** POST pairing QR ticket, POST [id] approve/deny (local-only)
relay/devices/[id]/route.ts DELETE revoke a paired phone (local-only)
auth/all-providers/route.ts GET API-key provider list
auth/api-key/[provider]/route.ts GET/POST/DELETE provider API key status/storage
auth/login/[provider]/route.ts GET OAuth/device-code SSE | POST manual code
auth/logout/[provider]/route.ts POST OAuth logout
auth/providers/route.ts GET OAuth provider list
cwd/validate/route.ts POST validate/select a cwd
default-cwd/route.ts POST create ~/pi-cwd-YYYYMMDD
files/[...path]/route.ts GET file contents for viewer
home/route.ts GET user home directory
models/route.ts GET { models, modelList, defaultModel }
models/enabled/route.ts GET/PUT enabledModels switches for the Models panel
models/refresh/route.ts POST fetch provider catalogs from pi.dev on demand
models/nonchat/route.ts GET classifier + image models (with sign-in state) and the global Code mode choice
models-config/route.ts GET/PUT — read/write ~/.pi/agent/models.json
models-config/catalog/route.ts GET models.dev pricing presets
models-config/discover/route.ts POST fetch a configured provider's upstream model list
models-config/builtin-match/route.ts GET ?baseUrl=&modelId= built-in providers at that endpoint + pi's settings for the model
models-config/test/route.ts POST test a configured model/provider
plugins/route.ts GET/POST package plugin management
skills/route.ts GET/PATCH loaded skills and disable-model-invocation
skills/install/route.ts POST install skills through npx skills add
skills/search/route.ts GET/POST skills.sh search
scheduled-tasks/** GET/POST tasks, PATCH/DELETE [id], POST [id]/run, GET [id]/runs, POST run seen, POST preview, GET events (SSE)
worktrees/route.ts GET list / POST create / PUT switch branch / DELETE git worktrees
worktrees/fetch/route.ts POST git fetch --prune + fresh branch lists
desktop/read-images/route.ts POST read natively-picked images into attachment payloads
desktop/save/route.ts POST copy a file to, or write bytes at, a natively-picked path
artifacts/settings/route.ts GET/PUT the "artifacts in the side panel" prompt switch
session-title/settings/route.ts GET/PUT the "name sessions automatically" switch
artifacts/route.ts GET ?q= artifacts across all sessions (Artifacts page)
artifacts/item/route.ts GET ?session=&identifier= one artifact with every version
artifacts/file/route.ts GET ?path= one written/edited file's calls | ?session=&toolCallId= a write's content
lib/
agent-client.ts typed fetch helper for /api/agent commands
artifacts.ts `:::artifact` scanner, markdown encoding, version collection
artifact-store.ts client store shared by ChatWindow, message cards and the artifact panel
artifact-index.ts server index of artifacts in every session file (Artifacts page)
artifact-settings.ts / artifact-guide-extension.ts prompt switch file + `<artifacts>` prompt section
html-preview.ts inline HTML/SVG/React preview detection, sandbox, srcdoc bootstrap, React document
preview-runtime.ts loads public/preview-runtime/ (bundled React, Sucrase, Tailwind) for React previews
app-prefs.ts APP_PREF_KEYS + typed localStorage accessors (SSR/private-mode safe)
desktop-connection.ts useDesktopConnection() — local server health probe for the reconnect banner
desktop-native.ts native dialogs, open/reveal path, external links, save/import, window lifecycle
desktop-notify.ts native completion notifications (skipped while the window is focused)
draft-store.ts local draft persistence helpers
file-access.ts allowed file roots for /api/files and worktrees
file-paths.ts client/server path encoding helpers
enabled-models.ts pure minimal-edit engine for the `enabledModels` pattern list
enabled-models-runtime.ts SDK adapter: per-pattern resolution, provider kinds, settings IO
markdown.ts shared markdown helpers
npx.ts npx runner used by skill install
pi-types.ts local structural types for pi SDK objects
network-proxy.ts Settings › General › Network proxy: process.env + dispatcher rebuild; network-proxy-test.ts the connection test
rpc-manager.ts AgentSessionWrapper + registry + startRpcSession
scheduled-tasks/ scheduler, runner, cron, store, run index for scheduled tasks (see docs/agents/scheduled-tasks.md)
session-reader.ts SessionManager wrappers + path cache + buildSessionContext adapter
session-prompts.ts every user prompt with its time and reply, read on demand for the Tasks calendar (fingerprint cache)
tool-presets.ts PRESET_NONE/DEFAULT/FULL + getPresetFromTools()
types.ts shared TypeScript types
normalize.ts normalizeToolCalls() — field name mismatch between file format and our types
workspace-state.ts persisted session/cwd/file-tab restore for desktop cold starts
worktree.ts project/worktree resolution and git worktree operations
components/
AppShell.tsx layout + URL state + tab management
SessionSidebar.tsx session tree + FileExplorer
ChatWindow.tsx chat composition + completion sound wrapper
ChatInput.tsx input bar + model/thinking/tools/compact controls
MessageView.tsx renders one message (user/assistant/toolCall/toolResult)
BranchNavigator.tsx in-session branch switcher
MarkdownBody.tsx markdown renderer
HtmlPreviewBlock.tsx / HtmlPreviewErrorBar.tsx inline previews and their error strip
ArtifactCard.tsx / ArtifactPanel.tsx / ArtifactView.tsx / artifact-tabs.ts artifact card in messages, right-panel tab, shared viewer
artifacts/ Artifacts page (cross-session list, search, preview) and its sidebar row
ModelsConfig.tsx modal for editing models.json (opened from sidebar bottom)
EnabledModelsSection.tsx model switches inside ModelsConfig, backed by enabledModels
AgentsConfig.tsx built-in subagent toggle + agent profile editor
PluginsConfig.tsx modal for installed package plugins
SkillsConfig.tsx modal for loaded/search/installable skills
scheduled/ Scheduled page (list, detail, editor, run history) and its sidebar row
tasks/ Tasks page (waiting / running / recent across projects), its Calendar mode (TaskCalendar, calendar-helpers) and its sidebar row
RemoteAccessSection.tsx Settings › General › Remote access (Tailscale) and "Notify this device"
RelaySection.tsx Settings › General › Remote relay: relay config, pairing QR, approvals, paired phones
SettingsPanel.tsx settings dialog; its General tab hosts the app intro, Version & Updates and the desktop-only switches
AppUpdatesSection.tsx Version & Updates block at the top of General
desktop/DesktopAppSection.tsx window/tray prefs; renders nothing outside Tauri
FileExplorer.tsx file tree inside sidebar
FileIcons.tsx file icon helpers
FileViewer.tsx file content in a tab
TabBar.tsx tab bar (Chat + open file tabs)
hooks/
useAgentSession.ts messages, streaming, SSE, fork/navigate, reconciliation; built-in slash commands (/session, bare /mcp)
useAudio.ts completion sound + AudioContext unlock
useDragDrop.ts shared drag/drop state
useIsMobile.ts responsive breakpoint
useScheduledTasks.ts shared store + SSE for scheduled tasks
useKeyboardShortcuts.ts Esc stops the running agent unless a field or nearer handler took it; Ctrl+Alt+N
useResizablePanel.ts drag/keyboard panel size kept per key; persistClamp: false never saves a short window's clamp
useTheme.ts theme stateTopic Notes
Read the doc for the area you touch before changing it. Upstream docs (no prefix) come from pi-web; fork-* docs hold this fork's notes and win where the two disagree.
- sessions.md: AgentSession lifecycle and shutdown, fork vs in-session branching, the sidebar's on-disk Fork, session file rewrites, toolCall normalization, a run's message keys across the file read, SSE reconnect and tool events, a tool card's flat arguments as rows, transcript system / usage / context-edit entries, running-state polling, custom-message collapsing, streamed chunks re-rendering only the reply, streaming markdown block by block, hand-written anchors in rendered Markdown landing after the sanitizer's id prefix, Windows drive-letter Markdown links becoming
file:///before sanitizing, user messages' raw HTML shown as text, ```svg fences previewed only as an<img>, display math's Copy button, long thinking rendered in pieces, a finished turn's duration, history caches (tool-result images, subagent runs, session views) and deferred code highlighting with Prism languages loaded on demand, a patch shown in one column or two, the session sidebar (toolbar row and its brand, project groups, their order and display names, pins, archive, new-session project adoption, the files below the sessions or in a tab), the project/worktree bar above a fresh composer (the header: brand, then the bar) and what it carries across the remount, exported HTML, the extension status bar and itscommand:buttons, extension UI colors (pi's palette theme, the page's light/dark ANSI palette), cache and cost notices (showCacheMissNotices), the read-only Debug panel (connections, server state, sessions the server holds). Files:lib/rpc-manager.ts,lib/session-reader.ts,lib/session-fork*.ts,lib/session-delete.ts,lib/normalize.ts,lib/message-keys.ts,lib/session-tree.ts,lib/session-ui-state*.ts,lib/sidebar-prefs.ts,lib/sidebar-actions.ts,lib/session-links.ts,lib/favicon-badge.ts,lib/new-session-context.ts,hooks/useAgentSession.ts,hooks/useSessionUiState.ts,hooks/useSidebarMotion.ts,hooks/useGroupDrag.ts,hooks/useFilesPlacement.ts,hooks/useResizablePanel.ts,app/api/agent/**,app/api/sessions/**,components/SessionSidebar.tsx,components/PiWebTitle.tsx,components/SessionTree.tsx,components/SidebarMenu.tsx,components/SidebarToast.tsx,components/SidebarIcons.tsx,components/ProjectWorktreePicker.tsx,components/NewSessionContextBar.tsx,components/WorktreeCreateForm.tsx,handleNewSession,handleSelectSessionand the bar's handlers incomponents/AppShell.tsx,components/BranchNavigator.tsx,components/MessageView.tsx,lib/message-display.ts,lib/patch.ts,components/FileViewer.tsx,components/MarkdownBody.tsx,lib/markdown.ts,lib/markdown-blocks.ts,lib/streaming-message.ts,hooks/useStreamingSelector.ts,lib/turn-duration.ts,components/MermaidBlock.tsx,components/SvgBlock.tsx,lib/highlight-queue.ts,lib/prism-languages.ts,hooks/usePrismLanguages.ts,lib/session-view-cache.ts,components/CodemodeToolView.tsx,components/ExtensionStatusBar.tsx,components/ExtensionWidgets.tsx,lib/extension-ui-theme.ts,components/AnsiText.tsx,lib/transcript-notices*.ts,components/TranscriptNotices.tsx,app/api/cache-miss-notices/**,lib/tool-fields.ts,lib/debug-*.ts,lib/stream-client.ts,lib/page-stream-registry.ts,lib/page-debug.ts,lib/file-watch-registry.ts,components/DebugPanel.tsx,components/debug-panel-state.ts. - tools.md: tool presets and Chat only, exact system prompts, tool exposure, the codemode / tool-search / mcp built-ins, the read-only MCP policy, the Code mode and PowerShell
defaultToolsswitches. Files:lib/tool-presets.ts,lib/tool-preset-preference.ts,lib/chat-only.ts,lib/exact-system-prompt.ts,lib/builtin-extensions.ts,lib/mcp-read-only-policy.ts,lib/codemode-settings.ts,lib/powershell-settings.ts,lib/global-settings-file.ts,app/api/agent/new/route.ts,app/api/tools/settings/route.ts, tool selection inlib/rpc-manager.ts. - mcp-runtime.md: the per-session MCP host (when servers register and connect, reported states, trust read on every sync, idle release);
/mcpin the composer. Files:lib/mcp-host.ts,lib/mcp-transport.ts,lib/mcp-status.ts,lib/mcp-command.ts,lib/mcp-config-key.ts, MCP wiring inlib/rpc-manager.tsandlib/builtin-extensions.ts,/mcphandling inhooks/useAgentSession.ts. - mcp-settings.md: Settings › MCP reads without running anything, masking, the trust dialog's server list, row states, notices, Code mode choice, trust from Settings, Escape stacking, every
mcp.jsonwrite and undo. Files:app/api/mcp/route.ts,app/api/project-trust/route.ts,lib/mcp-config-read.ts,lib/mcp-config-file.ts,lib/mcp-override.ts,lib/mcp-undo.ts,lib/mcp-secrets.ts,lib/mcp-server-display.ts,lib/mcp-json-error.ts,lib/project-trust.ts,lib/regular-file.ts,lib/stacked-dialog.ts,lib/settings-navigation.ts,components/McpConfig.tsx,components/mcp-config-helpers.ts,components/ProjectTrustDialog.tsx,components/SettingsPanel.tsx. - mcp-test-sign-in.md: Settings › MCP Test (route checks, bounded connection,
!commandqueue, redaction, status store) and OAuth sign-in / sign-out. Files:app/api/mcp/test/**,app/api/mcp/sign-in/**,lib/mcp-test.ts,lib/mcp-entry-request.ts,lib/mcp-status.ts,lib/mcp-sign-in.ts,lib/mcp-sign-out.ts,components/McpSignIn.tsx,components/mcp-sign-in-helpers.ts,components/OAuthPastePanel.tsx. - mcp-add.md: Settings › MCP add (paste re-parsed on the server, host-variable confirmation, literal secrets kept global, fresh-folder trust, the add pane) and the paste importer's escaping and grammars. Files:
lib/mcp-add.ts,lib/mcp-import*.ts,lib/shell-words.ts, fresh-folder trust inlib/project-trust.ts,components/McpAddServer.tsx,components/mcp-add-helpers.ts, theaddaction ofapp/api/mcp/route.ts. - models.md: default model and reasoning level, providers registered at session_start, mid-run reasoning changes, remote provider catalogs,
enabledModelsscoping and minimal edits, provider auth listing and credentials. Files:app/api/models/**,app/api/models-config/**,app/api/auth/**,lib/default-preferences.ts,lib/model-scope.ts,lib/enabled-models*.ts,lib/model-catalog-refresh.ts,lib/deferred-provider-models.ts,lib/provider-listing*.ts,components/ModelsConfig.tsx,components/EnabledModelsSection.tsx,components/ModelSelector.tsx,components/SelectorRow.tsx. - files-and-access.md: worktrees and project grouping, the file access allow-list (the
/api/filessecurity boundary), file tree visibility, uploads and chat file drops, web password throttling. Files:app/api/files/**,app/api/cwd/**,app/api/worktrees/**,app/api/file-index/**,app/api/web-auth/**,proxy.ts,lib/path-security.ts,lib/file-access.ts,lib/linked-directory.ts,lib/session-file-references*.ts,lib/file-tree-visibility.ts,lib/file-upload-client.ts,lib/worktree.ts,lib/paths.ts,lib/auth-throttle.ts,components/ProjectWorktreePicker.tsx,components/NewSessionContextBar.tsx,components/FileExplorer.tsx,hooks/useDragDrop.ts. - settings-ui.md: Plugins and Skills routes, sidebar group switches, the shared
SettingsUiblocks every settings panel and add pane uses. Files:app/api/plugins/**,app/api/skills/**,components/SettingsUi.tsx,components/settings-ui-helpers.ts,components/SkillsConfig.tsx,components/PluginsConfig.tsx; also before adding a settings section or add pane. - subagents.md: the built-in subagent setting, profiles and their files, run status, completion notifications. Files:
lib/subagent*.ts,app/api/subagents/**,components/AgentsConfig.tsx. - scheduled-tasks.md: scheduled tasks (the Scheduled page): server-side scheduler and its lease, catch-up and overlap rules, read-only default, the run index that hides runs from the project tree, why shared state is on
globalThis. Files:lib/scheduled-tasks/**,app/api/scheduled-tasks/**,instrumentation-node.ts,hooks/useScheduledTasks.ts,components/scheduled/**, the Scheduled row incomponents/SessionSidebar.tsx, the page overlay incomponents/AppShell.tsx. - artifacts.md: inline HTML/SVG/React previews and
:::artifactblocks, output vs process files on the Artifacts page: what renders where, the sandbox rules and the desktopabout:srcdocallowance, the auto-run rule for scripted pages, the bundled React runtime (inlined, because sandboxed frames cannot reach localhost;npm run preview-runtimeregenerates it), the fix flow and the prompt switch, the cross-session Artifacts page. Files:lib/artifacts.ts,lib/artifact-store.ts,lib/artifact-index.ts,lib/file-output-role.ts,lib/artifact-file-roles.ts,lib/artifact-favorites.ts,components/artifacts/**,lib/html-preview.ts,lib/html-preview-stream.ts,lib/preview-theme-kit.ts,lib/artifact-settings.ts,lib/artifact-guide-extension.ts,hooks/useArtifactPublisher.ts,hooks/useHtmlPreviewFrame.ts,lib/preview-runtime.ts,scripts/build-preview-runtime.mjs,public/preview-runtime/,components/Artifact*.tsx,components/HtmlPreview*.tsx,components/artifact-tabs.ts,app/api/artifacts/**,is_inline_frame_documentinsrc-tauri/src/lib.rs. - remote-relay.md: the end-to-end encrypted relay (Noise IK over a dumb relay, phone shell + tunnel service worker, pairing, request mark). Files:
lib/relay/**,relay/(server, Docker),relay-shell/(npm run relay:shell),app/api/relay/**,components/RelaySection.tsx,e2e/relay.mjs; deploying: remote-relay-deploy.md. A request carrying the relay mark comes from a paired phone: it is never local (isLocalRequest), and local-only routes must askisLocalRequest(), never a loopback Host. - client-platform.md: mobile software keyboard and viewport height, completion sound. Files:
hooks/useViewportHeight.ts,hooks/useAudio.ts, the keyboard-open CSS.
Fork notes:
- fork-sessions.md: branch summaries, the not-yet-flushed new session, the SDK → wire → client event pipeline, the incremental session scanner,
useAgentSessionguards (request ids, load deadline, streaming seed, render-phase scroll save), compaction / retry / 0.86 events,isRunning()andisIdle, running-state propagation and reconciliation, session automation, the single-shot composer send,!commandoutput, stats, transcript system messages, extension command session actions. - fork-models.md: routed model, cost by model and cache warming, classifier and image models, the four thinking-level states, model defaults, remote provider catalogs (refresh only on request),
enabledModelsminimal edits andresync, auth and credential deletion. - fork-tools-subagents.md: new-session tool presets and Chat only, exact system prompts through
before_agent_start, built-in subagents (setting, disabled built-ins, profile files, notifications). - fork-files-security.md: security posture (web password, OAuth tokens, preview sandboxes), worktrees and branch switching, the file access allow-list, web password throttling.
- fork-desktop.md: the Tauri shell (desktop token, native menus in Rust, file context menu, window state, tauri plugin version pairing), workspace terminals and node-pty / quickjs staging, Windows overwrite installs, and the payload credential scan that keeps
.pi/mcp.jsonout of an installer. - fork-ui.md: who contains whom in the topbar / chat column / right panel, the settings dialog tabs, touch affordances, completion sound, plugins and skills.
- fork-chat-workspace.md: the non-project Chats section, the hidden
chat-workspacecwd andworkspaceKindidentity, project-workbench suppression, and the server-enforced chat policy (skills and MCP yes; no file, shell or other extension tools; no context files), text attachments, and continuing a chat in a project.
AgentSession lifecycle (lib/rpc-manager.ts)
- One
AgentSessionWrapperper session id, keyed inglobalThis.__piSessions globalThissurvives Next.js hot-reload; plain module-level Map does not- Idle timeout: 10 minutes. Concurrent
startRpcSession()calls share a single start Promise (globalThis.__piStartLocks)
Hard rules
Each one undid a real regression; the linked note has the reasoning.
AgentSessionWrapper.isRunning()ORs ininner.isIdle === false; dropping it evicts wrappers mid-retry. (fork-sessions)- Never assign
agent.state.systemPrompt(a getter since pi 0.86). Exact prompts go only throughlib/exact-system-prompt.ts; do not add a second path. (fork-tools-subagents) useAgentSession: keep the monotonic request ids,fetchWithRetryfor the session load,seedStreamingSnapshot(), the render-phase scroll save, and thesessionHookMountedRefre-assert beforemaintainEventsConnected(). (fork-sessions)- The composer sends exactly one
onSendper submit; a second raw send restores the text into the box. (fork-sessions) - Do not re-add the legacy
auto_compaction_*event cases or a manual DeepSeek xhigh clamp. (fork-sessions) enabledModels: never compare patterns as strings, never assumeprovider/*covers a provider, never rebuild the list fromgetAvailable(); every toggle is a minimal edit and onlyresyncrepairs entries. (fork-models)- Provider catalogs refresh over the network only when the user presses "Refresh catalog". (fork-models)
- Credential deletes go through
removeStoredCredentialIfType(), and both provider lists refresh after any auth change. (fork-models) - Built-in subagent profiles are switched off by name in
disabledBuiltIns, never copied out to a.md; keepSUBAGENT_NOTIFICATION_PREFIXin code. (fork-tools-subagents) - Never give one iframe both
allow-scriptsandallow-same-origin; keepSERVE_EXT_TO_MIMEingetServeMime. (fork-files-security) - Manual-code OAuth handshake tokens are
crypto.randomUUID(). The auth throttle stays global, and its reset window stays longer than the max delay. (fork-files-security) - No literal
homedir()in session-scanner fs calls; useuserHome(). (fork-sessions) - Native-dialog routes (
/api/desktop/*,?type=import) require the per-process desktop token; never a static token or User-Agent check.read-imagesderives its cap fromMAX_ATTACHED_IMAGES. (fork-desktop) - Open local paths with
explorer.exeon Windows, nevercmd.exe /C start. (fork-desktop) - Native popup menus are built in Rust (
show_popup_menu); do not go back to the JSMenuAPI. (fork-desktop) tauri-plugin-*crates and@tauri-apps/plugin-*packages stay on the same minor; fix drift inCargo.lock, never by pinning npm down. (fork-desktop)- Window state flags are
SIZE | POSITION | MAXIMIZED; neverVISIBLEorDECORATIONS. (fork-desktop) - After an SDK bump run
npm run desktop:prepare && npm run desktop:verify; never hard-code a nested staging destination; keep all three Windowsnode_modulesguards. (fork-desktop) - The staged payload must carry no
.pi/, noBearer ak_, no armoured private key and nosrc-tauri/targetleftover:outputFileTracingExcludesis inert on Windows, so the load-bearing defence is the pre-trace cleanup plus the throwing scan inscripts/prepare-desktop.mjs(scripts/packaged-payload.mjs). (fork-desktop) - Layout: the center column contains topbar and chat; the right-panel block is a full-height sibling inside the outer row; no
paddingLeft: sidebarResizer.widthon the topbar. Pinned byAppShell.right-panel-row.test.mjs. (fork-ui) SettingsPanelkeeps theonBusyChangeguard so a desktop update cannot be dismissed mid-install. (fork-ui)- Chats own a server-created folder under the chat root (a new chat is requested with the root, never a path built in the browser);
workspaceKind/chatFoldercome from the server, and chats stay out of project trust / worktrees / project files / terminals / the right panel. Server policy keeps a chat off the shell, with file tools confined to its folder,readalso opening skills and files the user named in their own message (read-only), MCP tools limited to those their server marks read-only, no extension tool the user has not allowed, and context-file-free, even for persisted sessions. Only the per-chat unlock (pi-web:chat-unlock, never on a network-exposed server) lifts that. Legacy chats (the old sharedchat-workspacecwd) keep their old policy. (fork-chat-workspace)
Two kinds of branching — don't confuse them
- Fork (Fork button on user message): creates a new independent
.jsonlfile (parentSessionheader field). In the sidebar it is a row of its own beside its source, marked with the fork glyph; only subagent runs and side chats nest under a row, folded by default (lib/sidebar-session-nodes.ts,lib/sidebar-subagent-expansion.ts, #237). - In-session branch (Continue button / BranchNavigator): calls
navigate_treewithin the same file. Multiple entries share the sameparentId. Switching between them calls/api/sessions/[id]/context?leafId=.
Upstream merge sentinels (not the same "fork" as session fork)
This repo is a fork of agegr/pi-web and periodically merges upstream. components/fork-extractions.test.mjs guards the failure mode that a clean merge can still be wrong: code this fork moved to another file reappears at its origin, or a fork change is silently reverted. Git does not track cross-file moves, so neither shows up in tsc, eslint, or the upstream suite.
When one of those assertions fails, the default is to restore the behaviour, not to delete the assertion. A failure saying a marker is "absent from the origin but also from the extraction targets — it looks deleted, not moved" means the feature is probably gone: that is exactly how the project-picker filter box was found missing after a restyle had left every project past the 7-row cap unreachable. Risk levels live in scripts/fork-ownership.json; the reasoning is in docs/ownership-boundaries.md.
The third direction is forbiddenMarkers on a FORK_FEATURES entry: a region the fork deleted that upstream still ships. A clean merge re-adds it silently, so the entry asserts those strings stay absent from the file (currently the new-session branding header in components/ChatWindow.tsx). A failure there means "put the removal back", never "drop the marker".
Upstream merge decisions (standing rules)
Full per-merge reasoning (segments E, F, G, with what was adopted and what was declined) is in merge-history.md. The rules that still bind a future merge:
- Upstream owns SDK adaptation. Exact system prompts go through
lib/exact-system-prompt.ts(before_agent_start); the session list comes fromlib/session-list-scanner.ts; MCP and Code mode run on ADR 0006'sbuiltin:*extensions (createMcpExtension()is never passed as a bare inline factory) andresolveActiveToolNames()replacedwithExtensionTools(). Do not re-add a second path for any of these. - Declined upstream UI stays declined: the sidebar explorer and resizable session/explorer panes (
data-resize-handle="sidebar-sections"),DirectoryPicker,SessionSearch,ChatMinimap,getSessionListIndiceswindowing, the second mobile toolbar group, the topbar models/skills/settings quick-buttons,ExtensionStatusBar(the fork'sExtensionStatusLinereplaces it). A merge that brings one back is re-introducing declined UI, not a test to satisfy. - Fork layers that must survive a merge:
userHome()routing instead of literalhomedir(), models-config literal-key redaction,resolveSessionReferencesin the send/queue paths, the monotonic request-id guards inuseAgentSession, the project-tree sidebar with the full-height layout, desktop i18n and Settings sections. lib/startup-preferences.tsstays deleted (new-session model picks are session-scoped);PUT /api/models/defaultis the only writer of global defaults.package-lock.jsonkeeps the tauri plugin versions pinned tosrc-tauri/Cargo.lock: restore HEAD's lock beforenpm install --package-lock-only, or the carets re-resolve andrelease-workflows.test.mjsfails.- After a merge:
node scripts/upstream-css-baseline.mjs update <upstream-ref>andnpm run drift.
Pi Session File Format
Location: ~/.pi/agent/sessions/<encoded-cwd>/<timestamp>_<uuid>.jsonl
{"type":"session","version":3,"id":"<uuid>","timestamp":"...","cwd":"/path","parentSession":"/abs/path/to/parent.jsonl"}
{"type":"model_change","id":"<8hex>","parentId":null,"provider":"zenmux","modelId":"claude-sonnet-4-6","timestamp":"..."}
{"type":"message","id":"<8hex>","parentId":"<8hex>","message":{"role":"user","content":"..."}}
{"type":"message","id":"<8hex>","parentId":"<8hex>","message":{"role":"assistant","content":[...],...}}
{"type":"message","id":"<8hex>","parentId":"<8hex>","message":{"role":"toolResult","toolCallId":"...","content":[...]}}
{"type":"compaction","id":"<8hex>","parentId":"<8hex>","summary":"...","firstKeptEntryId":"<8hex>","tokensBefore":N}
{"type":"session_info","id":"...","parentId":"...","name":"user-defined name"}SessionContext.entryIds[] parallels messages[]: each displayed message's .jsonl entry id, used for fork and navigate_tree.
Styling: fork CSS lives only in app/native-theme.css
UI consistency is mandatory (user requirement). Every application menu, dropdown,
option picker and autocomplete popup must use the shared .app-menu surface and menu
tokens in app/native-theme.css. Form choices use components/AppSelect.tsx; do not
introduce raw <select> controls or OS-native application option menus. Preserve the
same palette, nested radii, inset, row spacing, selected/disabled states and focus
treatment in both themes. Use the existing design as the reference, consult the
sources in docs/ui-menu-audit.md, and inspect actual rendered states at desktop and
narrow widths before claiming visual consistency. System file/directory dialogs are
separate OS tasks. Run node --test scripts/ui-menu-consistency.test.mjs after menu work;
changes to shared choices also run node e2e/option-controls.mjs.
app/globals.css and app/settings.css are pi-web's and stay byte-identical to upstream — scripts/upstream-css-baseline.test.mjs fails on any edit. Put every fork rule in app/native-theme.css (imported last in app/layout.tsx); overrides of upstream rules that other theme rules must beat go in its "fork base layer" at the top. After an upstream merge run node scripts/upstream-css-baseline.mjs update <upstream-ref> (the sync workflow does). Layout of the theme file and the design intent to restore after a merge: docs/native-theme.md.
CSS Variables (app/globals.css, re-tokened in app/native-theme.css)
--bg --bg-panel --bg-hover --bg-selected --border
--text --text-muted --text-dim
--accent --user-bg --tool-bg
--font-mono<!-- BEGIN:nextjs-agent-rules -->This is NOT the Next.js you know
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in node_modules/next/dist/docs/ (resolved from this file's directory; in monorepos the next package may not be visible from the repo root) before writing any code. Heed deprecation notices.
This block is written and re-added by next dev — verify at node_modules/next/dist/server/lib/generate-agent-files.js. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.
<!-- END:nextjs-agent-rules -->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.

