Repository navigation
Description
Relates to #33. Same family as #396 (Cursor), different harness.
Goal and scope
Let users select Pi — the open-source @earendil-works/pi-coding-agent harness — as an Agent runtime in OpenDirector, use their own Pi account, models, and thinking levels, and create or edit project content through the shared business commands.
User flow and rules
- Detect the
piexecutable (PATH first, then common install locations) and give installation, authentication, and version guidance when unavailable, without affecting other runtimes. - Offer Pi's native models and thinking levels per conversation. Like the other external harnesses, do not read OpenDirector-saved model credentials for this runtime.
- Keep running each turn in
agent-runs/<turn-id>/work/. Pi's working directory is that directory, and business operations go through the inherited PATHopendirectorCLI and the per-turn gateway. - Stream replies, thinking, tool activity, usage, and errors into the conversation. Persist the native session identity so a conversation resumes with incremental input, including after restart.
- Load discovered skills (project
.opendirector/skills/, workspace, built-inpackages/agent/skills/) from the per-turn snapshot and expose the business CLI as other harnesses do. - Stop terminates the process group and keeps the partial reply. Already accepted generation jobs retain their own cancellation semantics.
- Keep native tool permissions; business rules still come from the shared commands and gateway validation, and unattended turns never auto-approve prompts.
- Provide English and Chinese setup, status, and error messages. Keep
pias a stable value in project data.
Feasibility and integration
Pi is a Node.js (>=22.19) harness published as @earendil-works/pi-coding-agent. Inspected surfaces: pi --mode json JSONL events (message_update deltas, authoritative message_end, toolcall_start/toolcall_end, turn_end, agent_end, agent_settled), pi --mode rpc bidirectional JSONL for a long-lived process, and the TypeScript SDK (createAgentSession) for in-process use. Sessions are persisted JSONL and addressable with --session, --session-id, --session-dir, --no-session; model and reasoning select with --model provider/id:thinking and --thinking, catalog discovery with --list-models, tool selection with --tools/--exclude-tools.
Prefer a stdio subprocess adapter next to deepseek.py and jiuwenswarm.py over an in-process SDK dependency, so runtime installation stays user-managed. Reuse the existing seams: RUNTIMES/RuntimeSpec with installation(), runtime_readiness(), and runtime_catalog() in packages/core/src/opendirector/agent/runtime.py; the RuntimeId literal in agent/context.py; the model catalog branch in agent/catalog.py; gateway and CLI injection; skill snapshot copying; and the <turn-id>.<runtime>.jsonl trace in agent-runs/.
Frontend: runtime option and logo (src/canvas/AgentPicker.tsx, src/canvas/HarnessLogo.tsx, src/canvas/agentPreferences.ts, src/contracts/generated.ts) plus both message catalogs. Documents: the runtime table in docs/architecture/agent-runtime.md and the harness inventory in docs/development/agent-collaboration.md. Real Pi tool execution, session recovery, image input, and cancellation still need validation before support is claimed.
Acceptance criteria
- Select Pi and an available model, then complete a streamed conversation with text, thinking, and tool activity. Missing CLI, missing auth, and unsupported versions produce actionable messages.
- Ask Pi to create a text node through the OpenDirector CLI. Verify stored content, object revision, and command receipt.
- Edit the node in the UI, then ask Pi to read and update it in the same conversation. Verify the latest user change is preserved.
- Restart the application and resume the conversation; verify context retention, a stable execution directory, and isolation between projects and conversations.
- Stop a running turn: no orphan processes, no duplicated reply, no automatic resubmission of accepted work.
- Confirm discovered skills load from the per-turn snapshot and that business writes still obey revisions, locks, and receipts.
- Check English and Chinese runtime name, status, and failure flows. Include the inspected
pi --version, reproducible steps, actual project results, and UI screenshots in the implementation PR.
Activity
Zhangbo-cn commentedon Nov 23, 2026
Design decisions settled for implementation
Following a design review of the proposal above against the current code and the
pi1.6.0 documentation, these points are now fixed. They refine the original body rather than replace it.Process and session model
pi --mode json. Matches the existing OpenCode / Codex / Claude Code / JiuwenSwarm adapters, soterminate(group=True), stderr tail capture, trace writing, and cancellation semantics are reused unchanged.--mode rpcis only needed for mid-turn steering and multiplexing, which is out of scope for the first version.agent-runs/<turn-id>/work/as the working directory and pass--session-id, following the existingreuse_workspacepath.pionly reuses a session inside the same directory, so a changed directory would force a fork. When the directory is gone, fall back to replaying the full message history instead of failing.--session-dir <project>/agent-runs/pi-sessions. This keeps session files next to the existingagent-runs/<turn-id>.<runtime>.jsonltraces, ties their lifetime to the project, and avoids polluting the user's globalpisession list.Project trust
pigates.agents/skillsand.pi/*behind project trust, and print, JSON, and RPC modes cannot show a trust prompt. With the defaultdefaultProjectTrust: "ask", protected resources are silently skipped. The per-turn skill snapshot therefore requires an explicit--approveon the command line; without it the snapshot written byprepare_skillswould be ignored with no error. Skills stay enabled (supportsSkills=True), loaded from the.agents/skillssnapshot, with the selected skill names named in the first prompt rather than relying on/skill:commands.Configuration inheritance
The runtime uses the user's own
~/.pi/agentconfiguration, credentials, extensions, and MCP servers, consistent with how Codex and Claude Code are integrated. No isolated agent directory and no copying of credentials into a runner directory.--no-mcpis deliberately not applied, since silently removing the user's own capabilities contradicts the "use your own harness" contract. The actual argv is recorded in the turn trace so behavior differences between machines remain diagnosable, and the assistant panel and documentation state that this runtime uses the localpiconfiguration and extensions.Model catalog and thinking levels
pi --list-modelsprints a fixed-width table (provider, model, context, max-out, thinking, images) and has no JSON output. The adapter parses the provider and model columns plus thethinkingandimagesbooleans, exposesprovider/idchoices, and only offers the thinking levels the selected model supports. Requests are sent as--model provider/idplus--thinking <level>;autoomits--thinking.catalogUnreadable.needs_configuration.Readiness
Three stages behind the existing status cache, each failure mapping to an existing status key:
installation('pi')finds the executable, otherwisenot_installed.pi --versionsucceeds, otherwiseunknown.pi --list-modelsyields models, otherwiseneeds_configurationorcatalogUnreadableas above.pi auth check --jsonreportsready, otherwiseneeds_login.pi auth checkreturnsready/not_ready/invalidwith exit codes 0 / 1 / 2 and a--jsonform, which is more reliable than parsing human-readable output. Probe failures must not block the picker.System prompt injection
piaccepts--append-system-promptwith either inline text or a file path. The adapter writes the sharedSYSTEMtext plus a short pi-specific appendix to a0600temporary file outside the turn'swork/directory, so the model does not read or publish it as project content. The appendix fixes three rules: observe media through the sharedopendirectorcommands, never modify project storage directly through shell commands, and always pass--operation-idfor business writes.Media observation is a prerequisite
The model input content blocks supported by
piare text and images (image/png,image/jpeg, base64 with a mime type); there is no audio or video modality. This is a property of the underlying model protocols, not apidefect: Codex, Claude Code, and OpenCode are equally limited and all depend on frame extraction or transcription.OpenDirector already has the needed capability in the backend (
media/probe.pyusingffprobe,media/processing.pyusingffmpegfor single-frame extraction, slicing, concatenation, thumbnails), but theopendirectorCLI exposes no media observation command. Agents can therefore only shell out toffmpegwith hand-written arguments, which is unreproducible and unverifiable, or describe media they never actually inspected.A separate prerequisite issue will add shared media observation commands (asset probe facts, and frame extraction returning written image paths) that reuse the existing media functions. The
piadapter then only needs the commands plus its ownreadtool, with the same semantics as every other runtime. The media commands land first and are reviewed separately; thepiruntime can already handle text and canvas work before they exist.Event finalization
message_updatecarries deltas,message_endcarries the authoritative message, andpimay continue running afteragent_endbecause of retries or context compaction. Deltas drive live display only;message_endreplaces the segment authoritatively, tool activity is deduplicated by id, and the turn ends onagent_settled. "No duplicated reply text and no duplicated tool activity after an automatic retry" is an explicit acceptance item, since this is the easiest part of the integration to get wrong.Delivery boundary
piis not vendored and the default runtime staysDefault; the entry appears only when a localpiis detected.pi, labelPi,group='harness',modelSource='cli',modelOverride=True, contracts regenerated throughscripts/generate_contracts.py.src/assets/harness-logos/pi.svgis added, since the icon set in use has no pi mark.zh-CNanden-US, andnpm run check:i18nmust pass.cli_discoverygainspicandidates including the Windowspi.exe/pi.cmdforms. Windows is in scope, but the platform is only documented as supported once a real Windows machine passes the acceptance run, including process-group termination; otherwise it is documented as unverified.piscript that emits JSONL events, following the existing fake-harness test pattern, plus an optional real-pigate that skips when no credentials are present. CI must not depend on provider keys.tests/test_pi_runtime.pyand cover table parsing, argv assembly, event mapping and finalization, stop behavior, session reuse and fallback, readiness branches, and trace writing. Existing harness tests are untouched.docs/architecture/agent-runtime.md, shared media observation indocs/development/agent-collaboration.md, and the acceptance entry point indocs/development/validation.md.A separate
[validate] harness: pi default-availability acceptanceissue will track the acceptance run.[bugfix] storage: keep child paths inside the project directory