Skip to content

Pi: install the CLI in the agent image with a disposable runtime and safe credential handling #3831

Done

Description

@integry

Ship Pi 1.6.1 in the unified agent image and give it an entrypoint that runs it the way ProPR runs every agent: as root-started containers that drop to node, with disposable runtime state and the host credential store mounted as a source.

Acceptance:

  • Dockerfile.agent has a pi-cli stage installing @earendil-works/pi-coding-agent@${PI_CLI_VERSION} (default 1.6.1), copied into the final image with pi on PATH. The build verifies pi --version and that pi --help lists --mode, --print, --model, --thinking, --tools, --no-builtin-tools, --session-dir, --no-approve. Node in the image (22.23.x) satisfies Pi's >=22.19.0.
  • scripts/build-images.sh has PI_CLI_VERSION, matching the Dockerfile ARG; both bundle-content hash lists include the new files; AGENT_DEFAULT_VERSIONS gets pi: '1.6.1'; CLI version management resolves Pi versions from npm (@earendil-works/pi-coding-agent).
  • New scripts/pi-entrypoint.sh, dispatched from scripts/agent-entrypoint.sh. It creates a disposable agent dir (e.g. /tmp/propr-pi-home/agent, exported as PI_CODING_AGENT_DIR) and copies auth.json, settings.json, models.json and AGENTS.md/SYSTEM.md/APPEND_SYSTEM.md from the mounted host dir (source env, e.g. PROPR_PI_SOURCE_DIR). It never copies host sessions/, extensions/ or mcp.json; ProPR generates mcp.json itself. It sets PI_SKIP_VERSION_CHECK=1 and PI_TELEMETRY=0, and puts sessions under the runtime home.
  • Everything the entrypoint runs before the task (version probe, any pi auth/pi call) runs as node (su-exec node env HOME=/home/node …), never as root.
  • After the run, OAuth refreshes are written back to the host auth.json: per provider entry, and only if the host entry still equals what was seeded (compare-and-swap), so a host login or logout during the run wins. API-key entries are never rewritten. The write is atomic, via a temp file created owner-only (os.open(..., O_CREAT|O_EXCL, 0o600)), keeping the original file mode. Nothing is written when no OAuth entry changed. Implement it as a small Python helper like scripts/opencode-credentials.py (seed/sync) with unit tests.
  • Agent env vars (e.g. OPENROUTER_API_KEY, ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY) are forwarded as for other agents.
  • The egress allowlist covers what Pi needs for the configured providers; Pi's own update and telemetry endpoints stay off.
  • Smoke tests (scripts/smoke-test-images.sh): pi --version through the entrypoint; the entrypoint started as root (--user 0:0) with a mounted source dir leaves nothing under the runtime dir that node doesn't own.

Implementation

Model the entrypoint on scripts/opencode-entrypoint.sh and scripts/vibe-entrypoint.sh, the credential helper on scripts/opencode-credentials.py (seed snapshot of the imported auth.json, sync with per-entry compare-and-swap), and the root-ownership smoke check on the OpenCode one in scripts/smoke-test-images.sh. Update third-party notices generation for the new npm package. Keep the CLI-version change flow (packages/core/src/agents/version/*) consistent with the other npm-installed agents.

Notes

Verified with Pi 1.6.1:

  • pi -p --mode json emits strict JSONL on stdout; diagnostics go to stderr.
  • The prompt can come from stdin or as an @/path/to/file argument.
  • PI_CODING_AGENT_DIR relocates ~/.pi/agent, and Pi creates auth.json and models-store.json there on first run.
  • pi auth subcommands: login <provider> [--api-key] [--no-browser], logout, check [--provider] [--json] [--no-refresh], print-api-key, print-bearer-token.
  • Lesson from the OpenCode 2 upgrade: a version probe run as root created a root-owned log file that broke every run. Probe as node, and smoke-test as root.

Activity

  1. propr-dev commented on Nov 27, 2026

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-5-5
    • Branch: 3831/claude-opus-5-5-pi-install-the-cli-in-the-20261127-1443-62s
    • Base Branch: 3831-epic-pi-coding-jml
    • Worktree: issue-3831-20261127-1443-claude-opus-5-5-62s

    🔍 Track Task Execution

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions