Repository navigation
Commit ec7d455
authored
feat(tui): zypi export reads the session through the agent (plan decision 6) (#18)
## Summary
`zypi export <id>` read the session files of the old Rust agent, so it failed for every session that the Python agent stored. It now asks the agent, as a resume does. This is plan decision 6, option (a).
```text
zypi export <id>
connect() # starts the Python agent
session/load(id, cwd)
collect session/update (isReplay)
done when: the answer came AND no replayed update came for 500 ms
before the answer: 60 s of silence is an error
AcpUpdateTracker -> ScrollbackState -> render_blocks_to_markdown # same path as /export
AgentProcessGuard drop: cancel + join # also when the command fails
```
```diff
pi-pager/src/
-├── export_cmd.rs # read the old Rust session store
+└── export_cmd/
+ ├── mod.rs # entry and rendering
+ ├── replay.rs # agent and collection of the replayed updates
+ └── tests.rs # 18 tests, paused tokio clock
```
The answer to `session/load` can come before the last replayed messages. So the answer alone does not end the collection: only the quiet period does, and only a replayed update restarts it. Permission requests get `Cancelled`, other requests from the agent get method-not-found. `isReplay` is read from the notification `_meta` and from the update `_meta` (the Python agent sets it on the update).
## Evidence
- **Before:** `resume_matrix.py` on `main` (plan section 10.12): 10 PASS / 3 GAP. Case 12, `zypi export <id>`, was GAP: `Session '<id>' not found.`, exit 1.
**After:** 11 PASS / 2 GAP / 0 FAIL on WSL2. Case 12 passes. Case 13 (unknown id) passes as before. The two GAP that remain are `--resume <title>` and `--session-id <id in use>`; this PR does not touch them. Cases 12 and 13 now also fail when a process is left behind.
- **Time** (debug build, WSL2; three runs each, the session file is not changed):
| Entries | File | `zypi export` | Agent alone (`session/load`) |
|---|---|---|---|
| 2,000 | 1.4 MB | 2.5 s | 0.24 s |
| 5,000 | 3.6 MB | 5.6-5.7 s | 0.53 s |
| 20,000 | 14.2 MB | 62.7-64.1 s | 2.5 s |
The agent is fast. The rest is `zypi` turning the messages into text, and that grows faster than the size. A release build was not measured.
- **Tests:** 18 unit tests in `export_cmd::tests`. 15 run on a paused tokio clock: they cover the order of the updates, the quiet period, the silence limit, requests from the agent, refusals, and an agent that exits or says nothing. 3 cover the rendering. 1 end-to-end test, `export_replays_a_stored_session_through_an_agent_of_its_own`, against the real Python agent; `python_agent_e2e` passes 11 of 11. 1 new test in `scripts/tests/test_tui_pty.py`.
- **Checks that ran locally** (on the code of the final commit; the last edits were documentation only): `tui_baseline.py check` exit 0 (warnings 0, residue words unchanged, dependency graph 980 = ceiling, `cargo check --workspace --tests` 0 errors). `ruff check` and `ruff format --check` pass. `pytest`: Windows 2,517 passed, 39 skipped, 31 deselected; WSL 2,540 passed, 16 skipped, 31 deselected.
- **CI** (on `e3f3458`: [TUI CI run](https://github.com/zy1233/pi-python/actions/runs/38344799030), [CI run](https://github.com/zy1233/pi-python/actions/runs/38344799403)): every job passes. `Ruff`. `pytest` 3.11, 3.12 and 3.13. `Gates + cargo check`: warnings 0, `leader` 245 of 245, `x.ai` 304 of 304, graph 980 of 980. `cargo test`: 8,684 passed, 0 failed, 22 ignored (`pi-pager`: 5,627 passed, 13 ignored). `Release build baseline` is manual and was skipped.
- **Not verified:** Windows and macOS (only WSL2 ran `zypi export`). Release-build time. A real model (the agent is a mock; export does not call the model).
- **Found, not fixed** (details in plan section 10.15, "continuation 6"): the Python agent loops forever on a session file with repeated entry ids; `scripts/session_list_bench.py` writes such a file above 4,096 entries; the pager reads `isReplay` only from the notification `_meta`, the agent sends it on the update (the resume path was not checked).
## Merge Danger
**Door:** two-way
The change reads session files and writes none. A revert restores the old behaviour, which fails for every session of the Python agent.
**Blast Radius:** export
`zypi export` now needs a working agent command, as a resume does; it did not before. A very large session takes about a minute on a debug build. Nothing else in the pager changes. The new `test-util` feature of `tokio` is a dev-dependency only.
Merged on the owner's order, into V0.5 (`v0.5.0`). The CHANGELOG entry moves from `[Unreleased]` to `[0.5.0]`, and the `zypi export` line leaves the known issues, in the commit that follows (it is part of #19, which merges after this PR). `tui/` changed, so the release size is measured again on the final tree (`release_baseline`, condition 2) and CI must pass on the tag commit (condition 1).1 parent 62b0a0c commit ec7d455
15 files changed
Lines changed: 825 additions & 52 deletions
File tree
- docs
- PLAN
- archive
- baselines
- scripts
- tests
- tui_pty
- tui/crates/codegen
- pi-pager-bin/src
- pi-pager
- docs/user-guide
- src
- acp
- export_cmd
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
| |||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
233 | 256 | | |
234 | 257 | | |
235 | 258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| 49 | + | |
| 50 | + | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
| |||
156 | 160 | | |
157 | 161 | | |
158 | 162 | | |
159 | | - | |
160 | | - | |
161 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
162 | 167 | | |
163 | 168 | | |
164 | 169 | | |
165 | 170 | | |
166 | 171 | | |
167 | 172 | | |
168 | | - | |
169 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
170 | 181 | | |
171 | 182 | | |
172 | 183 | | |
| |||
258 | 269 | | |
259 | 270 | | |
260 | 271 | | |
261 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
262 | 279 | | |
263 | 280 | | |
264 | 281 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
631 | 631 | | |
632 | 632 | | |
633 | 633 | | |
634 | | - | |
| 634 | + | |
635 | 635 | | |
636 | 636 | | |
637 | 637 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
| 174 | + | |
173 | 175 | | |
174 | 176 | | |
175 | 177 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
0 commit comments