Skip to content

Commit 60033a4

Browse files
authored
fix(tui): Linux follow-ups for the Rust agent runtime removal (plan r8, run on WSL2) (#9)
## Summary The macOS half of `docs/PLAN/PLAN-RUST-AGENT-RUNTIME-REMOVAL.md` is merged (#6 to #8). This is the Linux half, run in WSL2 (Ubuntu 24.04, kernel 5.10 **without Landlock**, bubblewrap 0.9.0): build the TUI, run its Rust suites, drive a real `zypi` under a pseudo-terminal, and look at what it leaves behind. That turned up six things, and this PR fixes them. The plan's section 10.10 has the full record (what was run, what was found, what is not verified). **What this PR is for in CI.** The numbers below were measured on WSL2, not on the runner. This PR's first TUI CI run is what confirms or corrects them: - `doctor_cmd::` is no longer skipped in `pi-pager` (12 tests). The skip existed because the voice probe hung on macOS CoreAudio; the probe is gone and the tests pass here without an audio device. If they do not hold on the runner, put the skip back (one line in `scripts/tui_baseline.toml`). - Two suites join the manifest: `pi-pager-render` (1,092 passed, 2 ignored) and `pi-pager-minimal` (79 passed). - `pi-pager` `reference_passed` 5552 -> 5577; `pi-pager-bin` 20 -> 21. - One known failure, `tmux_probe::tests::successful_near_deadline_exit_still_returns_captured_output`, is listed in `known_failures`. It spends 1.2 s of a 1.5 s budget in a shell script, so it fails when the machine stalls (twice on WSL2, both on the first run after linking, never in the 94 runs after). It is reported when it fails and does not block. **CI result.** The runs on `d84d98a` are green (TUI CI [run 38052332014](https://github.com/zy1233/pi-python/actions/runs/38052332014)): 10 suites, **8,634 passed / 0 failed / 22 ignored**, each suite equal to its `reference_passed`. That is the local 8,633 plus the one known failure, which passed on the runner, so `known_failures` stays as a safety net and was not needed this time. `doctor_cmd::` held on the runner without the skip. `cargo test` took 32 m 40 s, `Gates + cargo check` 8 m 21 s, Ruff 8 s, pytest on 3.11 / 3.12 / 3.13 about 2 minutes each; the release build baseline is skipped by design. ## The six findings | # | What was wrong | Fix | |---|---|---| | 1 | `zypi -p` runs the Python agent as a plain child on the user's terminal, so the agent never sees EOF when only zypi is killed (`kill -9`, `kill <pid>`, an IDE's stop button). The agent and a `sleep 300` it had started kept running. | zypi names itself in `PI_AGENT_PARENT_PID`; `pi_agent_cli` polls `os.getppid()` every 0.5 s in `-p` mode and stops as it does on SIGTERM (cancel the turn, reap every tool's process group). `-p` also stops on SIGTERM / SIGHUP now (exit status 128 + signal). | | 1b | With `--sandbox`, zypi re-executes itself under bubblewrap, and a plain bwrap only waits for its child. SIGKILL / SIGTERM / SIGHUP to bwrap alone left zypi, the agent and its tools running. | `bwrap --die-with-parent`, as its own commit. | | 2 | `SandboxManager::apply()` degrades on purpose (no Landlock, or applying fails): it logs, returns `Ok`, and the run goes on with none of the profile's limits. The user was never told. | The reason is kept; a warning is printed on stderr at start-up, and the welcome bar and status bar show `sandbox:<profile> (not enforced)` in the error colour. | | 3 | The agent's stderr went to `/dev/null` once the TUI was up, so a Python traceback went nowhere. | `<home>/logs/agent.stderr.log`: appended, one marker line per spawn, `0600`, rotated at 1 MiB at spawn, and a log that cannot be opened does not stop the agent. `-p` keeps the terminal. | | 4 | Two tests failed intermittently on WSL2. | Test-only: a 25 ms gap between two writes (the 100 Hz kernel clock makes ctime coarse), and `theme_cache::test_lock()` in a test that raced the terminal-native tests. | | 5 | The manifest skipped `doctor_cmd::` and had no `pi-pager-render` / `pi-pager-minimal`. | See the CI section above. | | 6 | The Linux-only checks (what is left running after each way of leaving zypi, the sandbox label, `-p` shutdown) had no repeatable form. | `scripts/tui_pty/` drives a built `zypi` under a pty (a `pyte` screen reads what it draws) and inspects the process tree. They need a built binary, so they are **not** part of pytest or CI. | ## Decision for you **`--die-with-parent` has a cost.** The sandboxed child is SIGKILLed when bwrap dies, so when only the outer bwrap gets SIGTERM or SIGHUP, zypi cannot restore the terminal (alternate screen, raw mode). Before the flag, the whole tree stayed up instead. I judged an unrestorable terminal better than a running agent nobody can see, but it is a trade, and the commit is only the flag and its test, so it is easy to revert. If you revert it, the CHANGELOG line and the plan's section 10.10 need the same edit. ## Not verified - **Landlock itself.** It needs kernel 5.13 or later and the WSL2 kernel is 5.10, so the "applied" side of the sandbox is covered by unit tests only (applying it would confine the test process for good). - **`-p` with a wrapper script as `PI_AGENT_COMMAND`.** The watch stays off when the process that started the agent is not the one named, so killing only zypi still leaves that agent behind. Windows has no counterpart for the watch. - Section 10.10 of the plan lists the rest. ## Review guide Nine commits. The first is not part of the Linux work: it was on local `main` and never pushed, so it rides along. If you squash-merge, it goes in under this PR's title; a rebase-merge keeps the nine as they are. | Commit | What | |---|---| | `eafc578` | Not mine: phase7 fix (project-trust for saved workflows, a bad meta description no longer breaks the session) | | `c13f7cc` | Finding 1: `-p` parent watch (Rust passes the pid; 15 pytest cases, POSIX only; 1 Rust test) | | `d14e6f8` | Finding 1b: `--die-with-parent` and the test that pins its position before `--` | | `2d499ad` | Finding 2: not-enforced notice (`pi-sandbox`, `pi-shell`, two render sites; 5 tests) | | `91b5f62` | Finding 3: agent stderr log (6 tests) | | `9489975` | Finding 4: two flaky tests, no production code | | `478aa8a` | Finding 5: manifest | | `15d2d85` | Finding 6: `scripts/tui_pty/` and `scripts/tests/test_tui_pty.py` | | `4cf989f` | Docs: plan 10.10 and r8, `docs/baselines/tui.md`, CHANGELOG, AGENTS files | ## Verification On WSL2, the whole manifest (`python scripts/tui_baseline.py test`): exit 0, 10 suites, 8,633 passed, 1 known failure, 22 ignored. pytest: 2,160 passed / 30 skipped on Linux (WSL), 2,156 passed / 34 skipped on Windows. `ruff check` and `ruff format --check` are clean. With a built `zypi` under a pty: `smoke.py` 23 checks (26 with `--sandbox workspace`), `exit_matrix.py` 12/12 (14/14 with the sandbox), `print_exit.py` 4/4 (the tool survived before the `-p` fix).
1 parent 4b5848f commit 60033a4

51 files changed

Lines changed: 3815 additions & 196 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ AgentMessage[] → transform_context() → convert_to_llm() → LangChain BaseMe
4646
6. **Usage accumulation** — per-field max, not sum (providers report cumulative snapshots or complementary splits).
4747
7. **Structured output** — `response_schema` via prompt injection + `response_format`; `with_structured_output` kills streaming.
4848
8. **Permission by declaration** — the CLI's `ask` mode asks about a tool call unless the tool's `annotations` (`ToolAnnotations`, MCP's hints) declare it harmless (`readOnlyHint`, or neither destructive nor open-world); no annotations means asked. A new tool that only reads should say so; `bash`/`edit`/`write`/`workflow` say nothing on purpose. See `packages/pi-agent-cli/AGENTS.md`.
49+
9. **Project trust** — what the project directory supplies (extensions, saved workflows, `.pi/SYSTEM.md`, project skills) is used only once the user vouched for the project. An extension that reads such files itself checks `pi.project_trusted is True` first; anything else means no. See `packages/pi-agent-cli/AGENTS.md`.
4950

5051
## Development
5152

52-
Python monorepo (`pi-agent-core`, `pi-agent-harness`, `pi-agent-cli`) + Rust TUI workspace `tui/` (vendored grok-build fork, binary `zypi`). Packages installed editable; tested via `pytest`. TUI: `cd tui && cargo check -p pi-pager-bin` (WSL; Cargo reads `CARGO_TARGET_DIR` from WSL env exclusively).
53+
Python monorepo (`pi-agent-core`, `pi-agent-harness`, `pi-agent-cli`) + Rust TUI workspace `tui/` (vendored grok-build fork, binary `zypi`). Packages installed editable; tested via `pytest`. TUI: `cd tui && cargo check -p pi-pager-bin` (WSL; Cargo reads `CARGO_TARGET_DIR` from WSL env exclusively). Rust tests run through `python scripts/tui_baseline.py test` (manifest `scripts/tui_baseline.toml`, numbers in `docs/baselines/tui.md`); it clears `PI_HOME` and friends, which a WSL login shell may export pointing at the real home — do not run test binaries or `zypi` without clearing them, and build on the Linux file system, not `/mnt/<drive>`. With a built `zypi`, `scripts/tui_pty/` drives it under a pseudo-terminal on Linux (smoke test, exit matrix, `-p` shutdown; README there).
5354

5455
### Virtual environments (uv)
5556

‎CHANGELOG.md‎

Lines changed: 41 additions & 47 deletions
Large diffs are not rendered by default.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ This repository is a monorepo containing:
7272
- Headless mode: `python -m pi_agent_cli -p "prompt"` for scripting and CI
7373
- `/new`, `/resume`, `/quit` session commands; `@` local directory listing
7474
- pi-aligned system prompt engine with tool contributions, `AGENTS.md` context files, `<available_skills>` format
75-
- Project trust: a project's own extensions (`<project>/.pi-python/extensions`, which run code when a session opens), `.pi/SYSTEM.md`, `.pi/APPEND_SYSTEM.md` and project-relative skills load only for trusted projects. An ACP client (the TUI) is asked once per directory; "Trust and remember" is saved in `~/.pi-python/agent/trust.json` with a fingerprint of those files, so a `git pull` that changes one of them asks again. Without being asked: list the project under `[extensions] trusted_projects` in `~/.pi-python/agent.toml`, set `default_project_trust` (`ask` by default, `never`, `always`), or run with `--trust-project-extensions` / `PI_TRUST_PROJECT_EXTENSIONS=1`. Headless `-p` runs never ask but honour an earlier answer. Installed extension packages, `AGENTS.md`, and absolute or `~` skills paths are unaffected
75+
- Project trust: a project's own extensions (`<project>/.pi-python/extensions`, which run code when a session opens), saved workflows (`<project>/.pi-python/workflows`, which become slash commands), `.pi/SYSTEM.md`, `.pi/APPEND_SYSTEM.md` and project-relative skills load only for trusted projects. An ACP client (the TUI) is asked once per directory; "Trust and remember" is saved in `~/.pi-python/agent/trust.json` with a fingerprint of those files, so a `git pull` that changes one of them asks again. Without being asked: list the project under `[extensions] trusted_projects` in `~/.pi-python/agent.toml`, set `default_project_trust` (`ask` by default, `never`, `always`), or run with `--trust-project-extensions` / `PI_TRUST_PROJECT_EXTENSIONS=1`. Headless `-p` runs never ask but honour an earlier answer. Installed extension packages, your own saved workflows in `~/.pi-python/workflows`, `AGENTS.md`, and absolute or `~` skills paths are unaffected
7676
- Extensions that fail to load (import error, bad entry point, `activate()` raising, invalid tool name) are skipped, and the agent says so at session start (ACP agent message; headless stderr) instead of just not having them. `PI_HOME` moves the whole home: config, `extensions/`, saved workflows and workflow journals
7777
- Git workspace context (`<git_status>`) is a session-start snapshot in the system prompt (kept stable for the provider prompt cache; the block tells the model to run `git status` for live state); `--no-git-context` or `[git] enabled = false` turns it off. The block (branch name and the paths of changed and untracked files) goes to the model provider with the rest of the system prompt, so turn it off if such names are sensitive
7878

‎docs/AUDIT/AUDIT-PHASE6-PHASE7-2026-09-30.md‎

Lines changed: 125 additions & 11 deletions
Large diffs are not rendered by default.

‎docs/PLAN/PLAN-RUST-AGENT-RUNTIME-REMOVAL.md‎

Lines changed: 136 additions & 9 deletions
Large diffs are not rendered by default.

‎docs/TUI-AND-CODE-AGENT.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,16 @@ command = "python -m pi_agent_cli"
119119

120120
[extensions]
121121
# Projects that may use their own <project>/.pi-python/extensions (arbitrary Python),
122-
# .pi/SYSTEM.md, .pi/APPEND_SYSTEM.md and project-relative skills, without being asked.
122+
# <project>/.pi-python/workflows, .pi/SYSTEM.md, .pi/APPEND_SYSTEM.md and project-relative
123+
# skills, without being asked.
123124
trusted_projects = ["~/work/my-repo"]
124125
# "ask" (the default), "never" (don't ask) or "always" (trust every project)
125126
default_project_trust = "ask"
126127
```
127128

128-
A project's own extensions, `.pi/SYSTEM.md`, `.pi/APPEND_SYSTEM.md` and project-relative skills (such as `.pi/skills`) are not used until the project is trusted. When you open a project that ships any of them, the agent tells you in the session which files they are and what each does, then asks "Allow loading this project's extensions and prompt files?" with two answers: **Don't trust** (the session goes on without them) and **Trust and remember**. The session's first prompt waits for your answer. "Trust and remember" is saved in `~/.pi-python/agent/trust.json` together with a fingerprint of those files, so you are asked again when one of them changes (after a `git pull`, say) and the agent says that they changed; refusing is never remembered. To take a trust back, delete the project's entry from that file. The TUI's YOLO mode does not answer this question for you: it has no "allow once" answer, so it always waits for you. The TUI does, however, pre-highlight the kind of answer you confirmed last time, so if that was an "always" answer, "Trust and remember" is the highlighted row: read the message above the question before pressing Enter.
129+
A project's own extensions, saved workflows (`.pi-python/workflows/*.py`, which become slash commands), `.pi/SYSTEM.md`, `.pi/APPEND_SYSTEM.md` and project-relative skills (such as `.pi/skills`) are not used until the project is trusted. When you open a project that ships any of them, the agent tells you in the session which files they are and what each does, then asks "Allow loading this project's …?" (naming what it ships, for example "extensions, saved workflows and prompt files") with two answers: **Don't trust** (the session goes on without them) and **Trust and remember**. The session's first prompt waits for your answer. "Trust and remember" is saved in `~/.pi-python/agent/trust.json` together with a fingerprint of those files, so you are asked again when one of them changes (after a `git pull`, say) and the agent says that they changed; refusing is never remembered. To take a trust back, delete the project's entry from that file. The TUI's YOLO mode does not answer this question for you: it has no "allow once" answer, so it always waits for you. The TUI does, however, pre-highlight the kind of answer you confirmed last time, so if that was an "always" answer, "Trust and remember" is the highlighted row: read the message above the question before pressing Enter.
129130

130-
The question is skipped, and the project's files used or left out, when the decision is already made: the project is under `trusted_projects` (subdirectories count), you start with `PI_TRUST_PROJECT_EXTENSIONS=1` / `--trust-project-extensions`, `default_project_trust` is `always` (trusted) or `never` (not), or you answered before and the files have not changed. A project whose files are too many, too large or unreadable to fingerprint is never asked about; list it under `trusted_projects`. When files are left out, the agent says so in the session. Headless `-p` runs never ask, but honour an answer given earlier. Extension packages installed with `pip`, `~/.pi-python/extensions`, `AGENTS.md`, and skills paths that are absolute or start with `~` always load. The TUI's own folder trust (`/hooks trust`) does not apply here.
131+
The question is skipped, and the project's files used or left out, when the decision is already made: the project is under `trusted_projects` (subdirectories count), you start with `PI_TRUST_PROJECT_EXTENSIONS=1` / `--trust-project-extensions`, `default_project_trust` is `always` (trusted) or `never` (not), or you answered before and the files have not changed. A project whose files are too many, too large or unreadable to fingerprint is never asked about; list it under `trusted_projects`. When files are left out, the agent says so in the session. Headless `-p` runs never ask, but honour an answer given earlier. Extension packages installed with `pip`, `~/.pi-python/extensions`, your own saved workflows in `~/.pi-python/workflows`, `AGENTS.md`, and skills paths that are absolute or start with `~` always load. The TUI's own folder trust (`/hooks trust`) does not apply here.
131132

132133
### `config.toml` — TUI-only config (optional)
133134

@@ -174,6 +175,10 @@ zypi
174175
# @ — browse local directory listing
175176
```
176177

178+
The TUI owns the screen, so what the agent writes to stderr (a Python traceback, a warning) is not shown there. It is appended to `~/.pi-python/logs/agent.stderr.log` (owner-only, one `--- agent started ... ---` line per run, moved to `agent.stderr.log.1` once it passes 1 MiB); look there when the agent dies or misbehaves. With `zypi -p` the agent's stderr is your terminal as usual.
179+
180+
`zypi --sandbox <profile>` confines zypi and the agent it starts with Landlock on Linux (kernel 5.13 or newer; Seatbelt on macOS). On a kernel without Landlock zypi still starts, but the profile's file and network limits do not apply: it warns on stderr and shows `sandbox:<profile> (not enforced)` in red at the top of the screen.
181+
177182
### ACP stdio mode (for editors)
178183

179184
The agent works with any ACP-compatible editor (Zed, Neovim, etc.):

0 commit comments

Comments
 (0)