Repository navigation
[feat] agent: add pi coding agent runtime - #461
Zhangbo-cn wants to merge 6 commits into
Conversation
|
@Zhangbo-cn ci is red, PTAL |
ee488e0 to
e8935dd
Compare
|
@FayeSpica CI is green now — thanks for the nudge. Two things were red. CodeQL: 3
Also opened #487 — the media observation commands ( All checks pass at |
| const RUNTIME_NAMES: Record<string, string> = { | ||
| default: "OpenCode", opencode: "OpenCode", codex: "Codex", claude: "Claude Code", | ||
| jiuwenswarm: "JiuwenSwarm", deepseek: "DeepSeek Harness", | ||
| jiuwenswarm: "JiuwenSwarm", deepseek: "DeepSeek Harness", pi: "Pi", |
There was a problem hiding this comment.
In manual testing, the Trace page didn’t recognize many of Pi’s message_* events or group its tool_execution_* events into tool calls. Please normalize both so messages render with the correct roles and each tool call appears once with its name, status, and expandable result.
e8935dd to
864c44d
Compare
|
Fixed both, in Roles. Tool calls. I kept pi's retry semantics instead of guessing at them: an attempt that ends with Validation:
Boundary worth stating: the Trace page has no browser test, so what I verified is the normalized rows from a real pi stream plus the unit fixtures, not a screenshot of the page. If a screen recording of the Trace page for a |
|
@Zhangbo-cn seems need resolve conflicts |
- 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
## 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)
`child()` reduced the requested name to a base name and compared the joined path with the directory through `Path.parents`. That comparison is not a containment check CodeQL recognizes for `py/path-injection`: `os.path.abspath` only moves the value to the "normalized, unchecked" state, so every sink that inherited the result stayed tainted. The PR run reported three such sinks — `FileResponse` and `is_file` in the trace route, and `is_symlink` in `child()` itself. Check the normalized string against the directory prefix, and build the returned `Path` only inside that branch, so every path handed to callers has passed the check. Verified by rerunning the scan locally (CodeQL 2.27.5, python-code-scanning suite) on the same source: before, three `py/path-injection` results at agent.py:333, agent.py:335 and local_projects.py:23; after, none. The new `tests/test_local_json.py` case covers traversal, separators and links.
## summary
- Normalize pi's JSON mode stream before the page renders it. `message_end`
becomes one row per message with its own role: user text, assistant text and
assistant thinking. Lifecycle records (`session`, `agent_start`,
`turn_start`, `message_start`, `message_update`, `turn_end`,
`agent_settled`, queue and settings events) stay out of the list, and the
system prompt and tool results are not echoed as conversation rows.
- Collapse `tool_execution_start`/`_update`/`_end` into one row per
`toolCallId`, carrying the tool name, `in_progress`/`completed`/`failed`,
the arguments and the result text, so a call is no longer three separate
raw rows. An `_end` without a matching `_start` still shows, and a late
update does not overwrite a settled result.
- Keep pi's retry semantics: an attempt that ends with `stopReason: 'error'`
contributes no text, and only the settled `agent_end` message reports the
turn's error — the same rule `agent/pi.py` applies.
- Streaming deltas are not drawn as their own rows because they repeat the
finished message; a text row appears when its message ends, as the Claude
and Codex normalizers already do.
## validation
- `node --test tests/piTrace.test.ts` (4 passed)
- `node --test tests/*.test.ts` (974 passed), `npx tsc --noEmit` (no error)
- `scripts/check-i18n.mjs` (3342 keys, 0 problems),
`scripts/check-browser-manifest.mjs` (92 entries)
- Real stream: `pi --mode json --print --tools read` on a scratch directory,
22 records; the normalizer returns the user message and one `read ·
completed` row carrying `{"path": ...}` and the file text, and drops the
system message and the 22 lifecycle records.
Refs: ThinkFlowLab#438
## summary
- `main` moved `RuntimeId` out of `agent/context.py` into
`domain/agent_runtime.py`. This branch still added `pi` to the old literal,
so resolving the conflict kept main's line — a module the branch never saw —
and the new literal has no `pi`.
- `apps/api/.../agent.py` validates `Turn.runtime` and `Draft.runtime` against
that type, so a pi turn was rejected with a 422 while every local test kept
passing: `test_pi_runtime` builds a `RunContext`, a dataclass with no
validation, and never crosses the request models.
- Declare `pi` in the shared literal, and guard the seam: every name in
`RUNTIMES` must be declared and must construct `Turn` and `Draft`.
## validation
- `python -m pytest tests/test_pi_runtime.py` (20 passed)
- same file with the literal reverted (1 failed: `AssertionError: {'pi'}`)
- `python -m pytest tests/test_creation_api.py tests/test_creation_contracts.py
tests/test_runtime_catalog.py tests/test_prompt_optimization.py
tests/test_assistant_conversations.py tests/test_capability_contract.py`
(295 passed)
- `python -m pytest tests/test_pi_runtime.py tests/test_native_runtime.py
tests/test_runtime_readiness.py tests/test_agent_visual_gate.py`
(62 passed, 21 skipped)
- `npx tsc --noEmit` (no errors), `node --test tests/piTrace.test.ts` (4 pass)
- `node scripts/check-i18n.mjs` (3376 keys, 0 problems, baseline 169)
- `python3 scripts/generate_contracts.py --check` (contracts verified)
864c44d to
2c5f256
Compare
|
Conflicts resolved: rebased onto Where it conflicted. One file, one hunk — Why it was more than a text conflict. Nothing local caught it. Fix in Scope note. The three Ran: |
Summary
pi(@earendil-works/pi-coding-agent) as an external harness next to OpenCode, Codex, Claude Code, JiuwenSwarm and DeepSeek: onepi --mode json --printprocess per turn, reusing the existing terminate, stderr, trace and cancel handling.~/.piproviders, sign-in, extensions and MCP servers (modelSource: cli); OpenDirector credentials are not injected.message_updatedeltas, butmessage_endis authoritative: a retried attempt does not end the turn, and only an error on the finalagent_endassistant message fails it. pi exits 0 for model errors, so the exit code alone cannot decide the outcome.--approveis passed because print/json modes otherwise skip the project skills and.pisettings silently;--tools read,bash,write,editkeeps project content changes on theopendirectorCLI.--session-id, with sessions kept inagent-runs/pi-sessions/nativeso global session history is untouched and a missing directory degrades to a full replay.--version→--list-models→pi auth check --json, keeping "catalog unreadable" and "no models configured" distinguishable.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 #NorRefs #Nis included, or no issue appliesRefs #438Labels
Suggested:
type:feature,area:agent,area:web(cannot apply from outside; please add on triage).Test plan
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).tests/browser/provider_settings.mjspasses against the isolated fixture API, with Pi in the harness list; the picker row,配置 Pipanel andpi auth login <provider>command were checked in both languages.runtime=pireturnedcomplete; the second turn recalled content from the first under one session id, and the session file landed underagent-runs/pi-sessions/native/.Evidence that it works
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.mjscheck plus the two-turn session recall above.