Skip to content

[feat] harness: Add pi coding agent support #438

Open

Description

@Zhangbo-cn

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 pi executable (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 PATH opendirector CLI 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-in packages/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 pi as 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.

References

Activity

  1. added
    area:harnessHarness and skill integration (Default, OpenCode, Codex, Claude Code, Jiuwen, DSH)
    on Nov 22, 2026
  2. Zhangbo-cn commented on Nov 23, 2026

    @Zhangbo-cn
    ContributorAuthor

    Design decisions settled for implementation

    Following a design review of the proposal above against the current code and the pi 1.6.0 documentation, these points are now fixed. They refine the original body rather than replace it.

    Process and session model

    • One subprocess per turn, pi --mode json. Matches the existing OpenCode / Codex / Claude Code / JiuwenSwarm adapters, so terminate(group=True), stderr tail capture, trace writing, and cancellation semantics are reused unchanged. --mode rpc is only needed for mid-turn steering and multiplexing, which is out of scope for the first version.
    • Workspace reuse for continuation. Resume the previous turn's agent-runs/<turn-id>/work/ as the working directory and pass --session-id, following the existing reuse_workspace path. pi only 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.
    • Sessions live inside the project: --session-dir <project>/agent-runs/pi-sessions. This keeps session files next to the existing agent-runs/<turn-id>.<runtime>.jsonl traces, ties their lifetime to the project, and avoids polluting the user's global pi session list.
    • Stopping does not persist the session. A stopped or disconnected turn keeps its partial reply but does not save the native session id, so a session with dangling tool calls is never carried into the next turn.

    Project trust

    pi gates .agents/skills and .pi/* behind project trust, and print, JSON, and RPC modes cannot show a trust prompt. With the default defaultProjectTrust: "ask", protected resources are silently skipped. The per-turn skill snapshot therefore requires an explicit --approve on the command line; without it the snapshot written by prepare_skills would be ignored with no error. Skills stay enabled (supportsSkills=True), loaded from the .agents/skills snapshot, 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/agent configuration, 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-mcp is 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 local pi configuration and extensions.

    Model catalog and thinking levels

    pi --list-models prints 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 the thinking and images booleans, exposes provider/id choices, and only offers the thinking levels the selected model supports. Requests are sent as --model provider/id plus --thinking <level>; auto omits --thinking.

    • Non-zero exit or unparseable output: catalogUnreadable.
    • Successful parse with zero models: needs_configuration.

    Readiness

    Three stages behind the existing status cache, each failure mapping to an existing status key:

    1. installation('pi') finds the executable, otherwise not_installed.
    2. pi --version succeeds, otherwise unknown.
    3. pi --list-models yields models, otherwise needs_configuration or catalogUnreadable as above.
    4. pi auth check --json reports ready, otherwise needs_login.

    pi auth check returns ready / not_ready / invalid with exit codes 0 / 1 / 2 and a --json form, which is more reliable than parsing human-readable output. Probe failures must not block the picker.

    System prompt injection

    pi accepts --append-system-prompt with either inline text or a file path. The adapter writes the shared SYSTEM text plus a short pi-specific appendix to a 0600 temporary file outside the turn's work/ directory, so the model does not read or publish it as project content. The appendix fixes three rules: observe media through the shared opendirector commands, never modify project storage directly through shell commands, and always pass --operation-id for business writes.

    Media observation is a prerequisite

    The model input content blocks supported by pi are 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 a pi defect: 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.py using ffprobe, media/processing.py using ffmpeg for single-frame extraction, slicing, concatenation, thumbnails), but the opendirector CLI exposes no media observation command. Agents can therefore only shell out to ffmpeg with 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 pi adapter then only needs the commands plus its own read tool, with the same semantics as every other runtime. The media commands land first and are reviewed separately; the pi runtime can already handle text and canvas work before they exist.

    Event finalization

    message_update carries deltas, message_end carries the authoritative message, and pi may continue running after agent_end because of retries or context compaction. Deltas drive live display only; message_end replaces the segment authoritatively, tool activity is deduplicated by id, and the turn ends on agent_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

    • pi is not vendored and the default runtime stays Default; the entry appears only when a local pi is detected.
    • Runtime id pi, label Pi, group='harness', modelSource='cli', modelOverride=True, contracts regenerated through scripts/generate_contracts.py.
    • A local monochrome src/assets/harness-logos/pi.svg is added, since the icon set in use has no pi mark.
    • Installation guidance offers a terminal command per platform plus a link to the project site, reusing the existing status message keys. One new hint key is added in both zh-CN and en-US, and npm run check:i18n must pass.
    • cli_discovery gains pi candidates including the Windows pi.exe / pi.cmd forms. 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.
    • CI uses a fake pi script that emits JSONL events, following the existing fake-harness test pattern, plus an optional real-pi gate that skips when no credentials are present. CI must not depend on provider keys.
    • New tests live in tests/test_pi_runtime.py and 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.
    • Documentation updates ship with the code: the runtime table in docs/architecture/agent-runtime.md, shared media observation in docs/development/agent-collaboration.md, and the acceptance entry point in docs/development/validation.md.

    A separate [validate] harness: pi default-availability acceptance issue will track the acceptance run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:harnessHarness and skill integration (Default, OpenCode, Codex, Claude Code, Jiuwen, DSH)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions