Skip to content

[feat] agent: add pi coding agent runtime - #461

Open
Zhangbo-cn wants to merge 3 commits into
ThinkFlowLab:mainfrom
Zhangbo-cn:feat/438-pi-runtime
Open

Zhangbo-cn wants to merge 3 commits into
ThinkFlowLab:mainfrom
Zhangbo-cn:feat/438-pi-runtime

Conversation

@Zhangbo-cn

Copy link
Copy Markdown
Contributor

Summary

  • Adds pi (@earendil-works/pi-coding-agent) as an external harness next to OpenCode, Codex, Claude Code, JiuwenSwarm and DeepSeek: one pi --mode json --print process per turn, reusing the existing terminate, stderr, trace and cancel handling.
  • Uses the user's own ~/.pi providers, sign-in, extensions and MCP servers (modelSource: cli); OpenDirector credentials are not injected.
  • Display text comes from message_update deltas, but message_end is authoritative: a retried attempt does not end the turn, and only an error on the final agent_end assistant message fails it. pi exits 0 for model errors, so the exit code alone cannot decide the outcome.
  • --approve is passed because print/json modes otherwise skip the project skills and .pi settings silently; --tools read,bash,write,edit keeps project content changes on the opendirector CLI.
  • Continuation reuses the turn workspace via --session-id, with sessions kept in agent-runs/pi-sessions/native so global session history is untouched and a missing directory degrades to a full replay.
  • Readiness is --version → --list-models → pi auth check --json, keeping "catalog unreadable" and "no models configured" distinguishable.
  • Adds the picker entry, a local monochrome logo, and the bilingual setup hint; runtime identifiers are carried through the API contract, docs and tests.

Known limitation: pi's message protocol accepts text and images only, so video and audio observation still depends on the pending project media commands. The visual gate is unchanged for that reason.

Linked issue

  • Fixes #N or Refs #N is included, or no issue applies

Refs #438

Labels

  • Labels applied

Suggested: type:feature, area:agent, area:web (cannot apply from outside; please add on triage).

Test plan

  • Local:
    • python3 -m pytest tests/test_pi_runtime.py tests/test_runtime_readiness.py (34 passed) — fake CLI covers argv, session reuse, single-shot final text, --thinking, retried failure, settled model error with trace, model table parsing, seven readiness branches and a missing installation.
    • python3 -m pytest -m ready (207 passed) and the full suite on the same tree (2905 passed, 120 skipped).
    • npm test (957 passed), npx tsc --noEmit, npm run check:i18n (3317 keys, 0 problems), python3 scripts/generate_contracts.py (no diff).
    • Browser: tests/browser/provider_settings.mjs passes against the isolated fixture API, with Pi in the harness list; the picker row, 配置 Pi panel and pi auth login <provider> command were checked in both languages.
    • Real CLI: two API turns on runtime=pi returned complete; the second turn recalled content from the first under one session id, and the session file landed under agent-runs/pi-sessions/native/.
  • Left to CI: full suite, release visual gate, and macOS/Windows platform differences.

Evidence that it works

  • Media attached, or N/A because:

Pi row in the harness picker (zh-CN) and the setup panel are locally captured but not attached; say the word and I will add screenshots. Automation evidence is the passing provider_settings.mjs check plus the two-turn session recall above.

## summary

- Run pi as an external harness: one `pi --mode json --print` process per
  turn over its JSONL event stream, reusing the existing terminate,
  stderr, trace and cancel handling.
- Take text from `message_update` deltas for display and from `message_end`
  as the authoritative body. A failed attempt that pi retries does not end
  the turn; only an error on the last `agent_end` assistant message is
  reported, because pi exits 0 for model errors.
- Keep the user's `~/.pi` providers and settings. Pass `--approve`, since
  print/json modes skip the project skills and `.pi` settings silently
  otherwise, and `--tools read,bash,write,edit` so project content changes
  still go through the opendirector CLI.
- Reuse a turn's workspace with `--session-id` and keep sessions inside
  `agent-runs/pi-sessions/native`, so continuation does not touch global
  session history and a missing directory degrades to a full replay.
- Probe readiness by version, model table and `pi auth check --json`;
  unreadable catalog and zero models stay distinguishable.
- Add the picker entry, local monochrome logo, bilingual setup hint and
  runtime identifiers in the API contract, docs and tests.

Refs: ThinkFlowLab#438
@github-actions github-actions Bot added area:agent Agent runtime, assistant chat and tools area:harness Harness and skill integration (Default, OpenCode, Codex, Claude Code, Jiuwen, DSH) type:feat New capability or behaviour labels Nov 23, 2026
@github-actions
github-actions Bot requested review from FayeSpica and wuzhf9 November 23, 2026 04:26
dev added 2 commits November 23, 2026 14:43
## summary

- Reject a joined name that leaves its directory. `child()` only refused a
  symlink at the final segment, so a request-derived identifier could still
  reach a sibling path through `..`; the check stays lexical, so hot paths
  take no extra filesystem call.
- Keep `pi` out of the credential-free release visual gate. The gate derives
  its cases from `RUNTIMES`, so adding a harness asserted a pinned CLI that
  release CI installs without credentials of its own. The opt-in nightly
  case still covers pi.
- State that exclusion and its reason in the validation guide in both
  languages.

## validation

- `python -m pytest -m ready` (207 passed)
- `python -m pytest tests/test_creation_storage.py tests/test_agent_gateway.py
  tests/test_pi_runtime.py tests/test_agent_visual_gate.py` (117 passed,
  14 skipped)
- `python -m pytest tests/test_agent_visual_gate.py --collect-only` lists
  five harness cases

Refs: ThinkFlowLab#438
## summary

- Reject a name that changes under `basename` before the join, so a request
  cannot carry a separator or `..` into the path at all. The lexical
  containment check stays as a second gate for the joined result.

## validation

- `python -m pytest -m ready` (207 passed)
- `python -m pytest tests/test_creation_storage.py tests/test_agent_gateway.py
  tests/test_pi_runtime.py tests/test_execution_files.py
  tests/test_local_json.py` (149 passed, 15 skipped)
@FayeSpica

Copy link
Copy Markdown
Collaborator

@Zhangbo-cn ci is red, PTAL

This branch has not been deployed

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

Labels

area:agent Agent runtime, assistant chat and tools area:harness Harness and skill integration (Default, OpenCode, Codex, Claude Code, Jiuwen, DSH) type:feat New capability or behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants