@andares/pi-toolkits 0.13.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +123 -25
  3. package/README.zh-CN.md +75 -21
  4. package/package.json +14 -4
  5. package/src/features/ask/index.test.ts +15 -0
  6. package/src/features/ask/index.ts +17 -0
  7. package/src/features/init/audit.test.ts +19 -2
  8. package/src/features/init/audit.ts +117 -15
  9. package/src/features/init/index.test.ts +123 -1
  10. package/src/features/init/index.ts +156 -46
  11. package/src/features/init/parity.test.ts +176 -0
  12. package/src/features/init/parity.ts +229 -0
  13. package/src/features/init/plan.ts +25 -3
  14. package/src/features/init/refresh.test.ts +88 -1
  15. package/src/features/init/refresh.ts +43 -64
  16. package/src/features/init/spec.ts +11 -0
  17. package/src/features/init/templates/memory-readme.md +9 -2
  18. package/src/features/init/test-helpers.ts +1 -0
  19. package/src/features/init/workflow.ts +159 -0
  20. package/src/features/permission/policy.test.ts +10 -0
  21. package/src/features/permission/units.test.ts +157 -0
  22. package/src/features/permission/units.ts +317 -15
  23. package/src/features/plan/index.test.ts +51 -0
  24. package/src/features/plan/index.ts +24 -4
  25. package/src/features/quit-guard/constants.ts +18 -5
  26. package/src/features/quit-guard/index.ts +75 -29
  27. package/src/features/quit-guard/killer.test.ts +77 -0
  28. package/src/features/quit-guard/killer.ts +215 -0
  29. package/src/features/review/index.ts +14 -0
  30. package/src/features/review/review.test.ts +34 -2
  31. package/src/features/uat/index.test.ts +15 -0
  32. package/src/features/uat/index.ts +10 -7
  33. package/src/features/uat/record-tool.ts +3 -2
  34. package/src/features/uat/state.ts +13 -5
  35. package/src/features/whats-new/changelog.ts +104 -0
  36. package/src/features/whats-new/constants.ts +35 -0
  37. package/src/features/whats-new/index.ts +146 -0
  38. package/src/features/whats-new/notice.ts +68 -0
  39. package/src/features/whats-new/paths.ts +29 -0
  40. package/src/features/whats-new/store.ts +114 -0
  41. package/src/features/whats-new/version.ts +43 -0
  42. package/src/features/whats-new/whats-new.test.ts +460 -0
  43. package/src/index.ts +3 -0
  44. package/src/lib/phases.ts +37 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,56 @@
1
+ # Changelog
2
+
3
+ Notable, user-visible changes to `@andares/pi-toolkits`. After an upgrade, the
4
+ first interactive `pi` start shows the sections between the version you last ran
5
+ and the one just installed, once. This file keeps the full history.
6
+
7
+ Before releasing, add top-level `- ` bullets under `## Unreleased`. `pnpm release`
8
+ renames that heading to the version being published and refuses an empty section
9
+ (`--skip-changelog` bypasses the gate).
10
+ ## Unreleased
11
+
12
+ <!-- Notes for the next release go here; `pnpm release` renames this heading. -->
13
+
14
+ ## 1.0.0 — 2026-11-15
15
+
16
+ - **quit-guard** — a forced exit can no longer be defeated by a deadlock inside `process.exit` itself: after the report is written, a same-loop SIGKILL timer and then an independent worker thread guarantee the process ends (real hang observed 2026-11-13, process stuck 18 min with the pty already deleted).
17
+ - **quit-guard** — a new arm-time watchdog thread covers shutdown deadlocks that kill the main event loop *before* the fire deadline: the main loop beats a 1 Hz heartbeat, and a worker that sees it stop restores the terminal, writes a `quit-hang-*-thread.json` report and SIGKILLs; healthy quits, TUI restarts and Ctrl+Z resume are unaffected.
18
+ - **ask-init** — re-running it now compares the project's framework text with the installed version, repairs missing or stale framework-owned files when safe, and says explicitly when nothing needs changing; hand-edited files stay untouched.
19
+ - **ask-init** — the workflow marker matcher no longer mistakes inline examples or fenced snippets for the managed block; ambiguous marker pairs are reported and left untouched.
20
+ - **ask-init** — `refresh --adopt` takes ownership of framework files written by an older tool without a template anchor, after you review them; a normal refresh still leaves them alone.
21
+ - **ask** — phase guards: ask refuses to start on top of a plan review or the UAT page, a review exits ask mode and refuses while a plan is under review, and `/ask-init` refuses mutating runs while another phase owns the tree.
22
+ - **init** — the audit now distinguishes a stale framework file from a hand edit, reports a missing workflow block, and treats bare legacy paths as a warning once the legacy directories are gone.
23
+
24
+ <!-- Notes for the next release go here; `pnpm release` renames this heading. -->
25
+
26
+ ## 0.14.0 — 2026-11-13
27
+
28
+ - **whats-new** — the first interactive `pi` start after an upgrade shows what changed since the version you last ran, once, without registering a slash command.
29
+ - **permission** — fewer false-positive prompts for quoted grep patterns, literal shell loops, `env`, `curl` data flags and read-only container inspection; multi-line commands are now split correctly.
30
+
31
+ ## 0.13.0 — 2026-11-12
32
+
33
+ - `/ask-plan` — plan first, review in the browser, then implement: research the task, write a spec, annotate it paragraph by paragraph in a local page, and only get permission to code after approval.
34
+ - `/ask-uat` and the `record_change` tool — change records are clustered into user-facing acceptance items and ticked off on a local page, so "shipped but not verified" is visible instead of implied.
35
+ - `/ask-init refresh` — refresh the framework-owned files of an already-adopted project in place (idempotent, safe).
36
+ - Releases are published by GitHub Actions with npm trusted publishing and carry a provenance attestation.
37
+
38
+ ## 0.12.3 — 2026-11-10
39
+
40
+ - quit-guard also arms on a quit event, so a signal-triggered shutdown that hangs before the TUI teardown is still forced out — with the terminal restored first.
41
+ - The watchdog deadline defaults to 8 s (was 10 s); `/quit-guard <ms>` still overrides it.
42
+
43
+ ## 0.12.0 — 2026-11-06
44
+
45
+ - `/quit-guard` — force-exit a hung interactive shutdown and give the shell prompt back; a JSON hang report is written first when the deadline passes.
46
+ - Every runtime-facing string is in English.
47
+
48
+ ## 0.11.0 — 2026-10-26
49
+
50
+ - `/ask-init` — install or adopt the agent memory framework (`AGENTS.md`, `specs/`, `.agents/`) with a snapshot, a coverage table, and a later drift audit.
51
+
52
+ ## 0.10.0 — 2026-10-24
53
+
54
+ - permission — a capped rolling JSONL approval log records each ask, its parsed units and your answer; `pnpm approval-report` turns it into rule candidates.
55
+
56
+
package/README.md CHANGED
@@ -13,9 +13,9 @@
13
13
  [![pi >= 0.99](https://img.shields.io/badge/pi-%3E%3D0.99.0-blueviolet)](https://github.com/earendil-works/pi)
14
14
  [![GitHub](https://img.shields.io/badge/github-andares%2Fpi--toolkits-181717?logo=github)](https://github.com/andares/pi-toolkits)
15
15
 
16
- In a nutshell: eleven ready-to-use capabilities — **read-only consult mode** `ask`, **session-scoped boundary permission** `ask-perm`, **model favorites** `favorites`, **prompt stash** `stash`, **third-party code review** `ask-review`, **dedicated compaction model** `compact-model`, **session startup automation** `autostart`, an **agent memory framework** `ask-init`, a **plan review in the browser** `ask-plan`, an **acceptance ledger with a browser page** `ask-uat`, and a **quit watchdog** `quit-guard` — with more to come.
16
+ In a nutshell: twelve ready-to-use capabilities — **read-only consult mode** `ask`, **session-scoped boundary permission** `ask-perm`, **model favorites** `favorites`, **prompt stash** `stash`, **third-party code review** `ask-review`, **dedicated compaction model** `compact-model`, **session startup automation** `autostart`, an **agent memory framework** `ask-init`, a **plan review in the browser** `ask-plan`, an **acceptance ledger with a browser page** `ask-uat`, a **quit watchdog** `quit-guard`, and **release notes on the first start after an upgrade** `whats-new` — with more to come.
17
17
 
18
- **Requirements**: pi `>=0.99.0`. Every published pi release from 0.99.0 through 1.5.1 has been verified with the full gate (install → `tsc --noEmit` → full test suite → keybinding audit → hash compare of the host files this package patches), each in a sandbox with the whole `@earendil-works/*` family pinned to the version under test. Newer releases are verified as they ship and the floor moves only when the measurement says so; `pnpm check:compat` reproduces the result. Note: pi ≥ 0.99 hosts require host-provided packages to be declared in `peerDependencies` with a `"*"` range — `@earendil-works/pi-tui` and `typebox` (the `scratchpad` tool builds a TypeBox schema) are declared that way; an installed copy in `dependencies` would make pi warn.
18
+ **Requirements**: pi `>=0.99.0`. Every published pi release from 0.99.0 through 1.5.2 has been verified with the full gate (install → `tsc --noEmit` → full test suite → keybinding audit → hash compare of the host files this package patches), each in a sandbox with the whole `@earendil-works/*` family pinned to the version under test. Newer releases are verified as they ship and the floor moves only when the measurement says so; `pnpm check:compat` reproduces the result. Note: pi ≥ 0.99 hosts require host-provided packages to be declared in `peerDependencies` with a `"*"` range — `@earendil-works/pi-tui` and `typebox` (the `scratchpad` tool builds a TypeBox schema) are declared that way; an installed copy in `dependencies` would make pi warn.
19
19
 
20
20
  ---
21
21
 
@@ -58,6 +58,7 @@ After installing, verify in any pi session:
58
58
  - [🚀 autostart — session startup automation](#autostart)
59
59
  - [🧠 init — agent memory framework](#init)
60
60
  - [🧯 quit-guard — quit watchdog](#quit-guard)
61
+ - [🆕 whats-new — release notes after an upgrade](#whats-new)
61
62
  - [Development](#development)
62
63
  - [Contributing](#contributing)
63
64
  - [License](#license)
@@ -76,11 +77,12 @@ After installing, verify in any pi session:
76
77
  | 📥 **stash** prompt stash | `ctrl+alt+y` | a stash slot for one prompt: press to swap, press twice to stash and clear the input box |
77
78
  | 🔎 **review** third-party code review | `/ask-review` | summon the configured review model to check + fix the task just finished, focusing on "is this round's requirement implemented / is anything missing / is anything wrong" |
78
79
  | 🧭 **plan** browser-reviewed planning | `/ask-plan` | research first, write a spec, review it in your browser paragraph by paragraph, annotate block by block, then implement only after approval |
79
- | ✅ **uat** acceptance ledger | `/ask-uat` | cluster pending change records into user-facing acceptance items, tick them off on a page (append-only ledger, no submit), and see what shipped without being verified |
80
+ | ✅ **uat** acceptance ledger | `/ask-uat` | after `/ask-init`: cluster pending change records into user-facing acceptance items, tick them off on a page (append-only ledger, no submit), and see what shipped without being verified |
80
81
  | 🗜️ **compact** dedicated compaction model | `/compact-model` | give `/compact` and auto-compact a cheap fast model to summarize with, leaving the main model free to focus on the conversation; zero overhead when unconfigured, falls back to pi's default on any failure |
81
82
  | 🚀 **autostart** session startup automation | `.pi/autostart.toml` | declare slash commands to run automatically at session start, per project (first use case: mounting multi-repo directories with `/add-dir`); never runs in untrusted directories, unregistered commands are skipped instead of being sent to the model |
82
- | 🧠 **init** agent memory framework | `/ask-init` | install or adopt a fixed memory layout (`AGENTS.md` + `specs/` + `.agents/memory` + `.agents/implementations`), migrate an existing one with a snapshot and a coverage table, and audit it later for drift, budgets and duplicated facts |
83
+ | 🧠 **init** agent memory framework | `/ask-init` | install or adopt a fixed memory layout (`AGENTS.md` + `specs/` + `.agents/memory` + `.agents/implementations`), migrate an existing one with a snapshot and a coverage table, then audit/refresh it for drift, budgets and duplicated facts |
83
84
  | 🧯 **quit-guard** quit watchdog | `/quit-guard` | force-exit when an interactive shutdown hangs, whether after the TUI teardown or before it on a signal-triggered quit; write a hang report and give the shell prompt back; TUI restarts and Ctrl+Z resume disarm it |
85
+ | 🆕 **whats-new** release notes after an upgrade | automatic | the first `pi` start after an upgrade shows what changed since the version you last ran, once; no slash command or other global namespace is claimed |
84
86
 
85
87
  ---
86
88
 
@@ -90,6 +92,8 @@ After installing, verify in any pi session:
90
92
 
91
93
  Enter with `/ask` (press it again to exit). Meant for the case where you only want to "ask questions and read code": the model may not change the project, but it is not starved of a place to think.
92
94
 
95
+ Ask is standalone (no `/ask-init` needed). If a plan review or the UAT page is active, leave it first — ask refuses to start on top of another phase rather than promise a read-only surface another feature will re-open.
96
+
93
97
  **While active**:
94
98
 
95
99
  - **Project writes stay mechanically impossible** — `write` / `edit` / `powershell` are removed from the active tool set, so pi rejects calls to inactive tools outright ("Tool not found"); the gate blocks them again as defence in depth
@@ -136,8 +140,11 @@ Repeating the argument form with the modes already in force is a **no-op**: no s
136
140
  - **bash** is decomposed into simple commands — `&&`, `||`, `;`, pipes, `$(…)`, backticks, `bash -c`, `eval`, the common indirection wrappers (`sudo`, `env`, `xargs`, `find -exec`, …), heredocs — and judged per command. `cd` folds into the commands after it; the strictest result wins, so `cd /tmp && rm x` cannot ride on the first segment.
137
141
  - **path-bearing tools** (`read` / `write` / `edit` / `grep` / `find` / `ls`) are judged by their own path; every other tool is judged by the working directory.
138
142
  - **unresolvable input** — a non-literal `cd` or `git -C`, an unknown shell variable in a path, an unterminated heredoc or substitution — is asked about regardless of mode (fail closed), never guessed.
143
+ - **literal for-loops** — `for f in a b; do grep x "$f"; done` is expanded with the literal words, because that is what bash does. Ordinary assignments are not persisted across commands without control-flow analysis; an unresolved loop, a value from `$(…)`, or a reassigned/mutated loop variable stays fail-closed. Newlines separate commands (`ls⏎rm x` is two commands, not one), and a backslash-newline is a line continuation.
144
+ - **patterns are not paths** — the first positional operand of `grep`/`rg`/`ag` is the pattern (`grep -n '</div>\s*$' file` asks nothing), and `$` at the end of a quoted string is literal, not a variable.
139
145
  - **`git -C <dir>`** is resolved like a local `cd`: relative path arguments (and the repository) are judged against `<dir>`, not the working directory.
140
- - **device sinks and data arguments** — `/dev/null`, `/dev/stdout` and `/dev/stderr` are never boundary targets, whether written as a redirect (`cmd > /dev/null`) or an operand (`curl -o /dev/null`); the arguments of `echo` / `printf` are data, not paths.
146
+ - **device sinks and data arguments** — `/dev/null`, `/dev/stdout` and `/dev/stderr` are never boundary targets, whether written as a redirect (`cmd > /dev/null`) or an operand (`curl -o /dev/null`); the arguments of `echo` / `printf` are data, not paths, as are declared data flags such as `curl -w` / `-H` / `-d`. Unresolved input and output redirects both stay fail-closed.
147
+ - **container inspection** — `docker`/`podman` subcommands that only inspect (`ps`, `logs`, `inspect`, `images`, `compose ps/logs/config`, …) are reads; `exec`, `run`, `rm`, `build` and everything unlisted stay writes.
141
148
 
142
149
  **Answers**: `a` allow once · `s` allow this directory for the session · `d` deny · `f` deny this directory for the session. Session grants are kept in memory as `(read|write, directory)`, matched by containment, and cleared when the mode is turned off or the session ends. A session grant outranks the destructive table — once you have allowed an operation for the session, repeating it does not ask again. A command the parser cannot resolve is granted by its exact text instead, so repeating the same opaque command does not ask again.
143
150
 
@@ -274,6 +281,7 @@ After a development task is done, type the `/ask-review` command to summon **a d
274
281
 
275
282
  - **Unconfigured / the configured model is no longer available** (e.g. it was deleted from pi's models.json) → a notice is shown and the list opens as usual (with no default entry in that case)
276
283
  - Triggered while a task is still in progress (the agent is not idle) → you are told to wait and nothing runs; only one review may be active at a time
284
+ - Planning phase → refused (a plan under review must not be edited); ask mode is exited automatically because check + fix needs the full tool set
277
285
  - A grey `review` status in the footer means a review model is configured
278
286
 
279
287
  ---
@@ -299,7 +307,10 @@ After a development task is done, type the `/ask-review` command to summon **a d
299
307
  /ask-plan off # leave the phase (the draft stays where it is)
300
308
  ```
301
309
 
302
- The spec lands in `specs/<slug>.md` — the same place `/ask-init` puts plans.
310
+ The spec lands in `specs/<slug>.md` — the same place `/ask-init` puts plans. Without an
311
+ agent framework the plan still works, but `record_change` and `/ask-uat` stay unavailable
312
+ until `/ask-init`; the command says so when planning starts. Leave an open UAT page first:
313
+ the two phases do not run on top of each other.
303
314
 
304
315
  ---
305
316
 
@@ -316,6 +327,11 @@ change record per finished round plus a one-sentence, user-facing description of
316
327
  (`record_change`); the UAT side clusters many records into a few acceptance items — one
317
328
  behaviour may need ten records, and one record may touch several behaviours.
318
329
 
330
+ **Requires the framework.** `/ask-uat` refuses unless the project has the framework state,
331
+ `AGENTS.md`, the memory contract and `.agents/implementations/`; run `/ask-init` first.
332
+ `record_change` is inactive in that state too. The check is feature-based, not byte-based:
333
+ your own edits to those files do not block the page.
334
+
319
335
  ```text
320
336
  record_change (implementation) → /ask-uat (cluster) → browser (tick) → ledger
321
337
  ```
@@ -370,7 +386,7 @@ pi's `/compact` and auto-compact summarize the context **with the current sessio
370
386
  | auto-compact threshold reached | summarized by the compaction model |
371
387
  | context overflow recovery | summarized by the compaction model, retry behavior unchanged |
372
388
 
373
- **Parts that are identical to pi's built-in behavior after takeover** (the built-in implementation is mirrored verbatim — copied from 0.87.1, byte-identical across 1.2.0 → 1.5.1 apart from the two 1.4.0 fixes adopted here: summaries request the model's output limit instead of a fixed fraction of `reserveTokens`, and `/compact <instructions>` also reaches the split-turn prefix, plus the 1.5.0 `cost.totalFromProvider` merge rule in the usage accounting — and only the executing model changes; the conversation serializer itself is imported from the host, so it follows whatever the running host does, e.g. 1.2.0 stops feeding assistant thinking back into the summarization request):
389
+ **Parts that are identical to pi's built-in behavior after takeover** (the built-in implementation is mirrored verbatim — copied from 0.87.1, byte-identical across 1.2.0 → 1.5.2 apart from the two 1.4.0 fixes adopted here: summaries request the model's output limit instead of a fixed fraction of `reserveTokens`, and `/compact <instructions>` also reaches the split-turn prefix, plus the 1.5.0 `cost.totalFromProvider` merge rule in the usage accounting — and only the executing model changes; the conversation serializer itself is imported from the host, so it follows whatever the running host does, e.g. 1.2.0 stops feeding assistant thinking back into the summarization request):
374
390
 
375
391
  - **Summary format** — the structured Goal / Progress / Key Decisions checkpoint; when a summary already exists, the iterative-update prompt is used so information carries over instead of being lost
376
392
  - **Split behavior** — the `keepRecentTokens` retention policy, and `firstKeptEntryId` / `tokensBefore` passed back unchanged
@@ -451,7 +467,7 @@ An **identical command line** declared by both sources runs once: a duplicate is
451
467
 
452
468
  **Key constraint: extension commands only**. Commands registered via `registerCommand` such as `/add-dir` (pi-add-dir) and `/cd` (pi-cd) work; built-in commands (`/compact`, `/reload`, `/resume`, …) are dispatched in the TUI layer and cannot be triggered from the extension layer; skill commands (`/skill:name`) are an expansion mechanism rather than an execution mechanism. The target extension you depend on (e.g. pi-add-dir) must be installed first.
453
469
 
454
- > **Implementation notes**: execution uses `sendUserMessage(cmd, { expandPromptTemplates: true })` — that option routes `/cmd args` into command dispatch instead of the model prompt path (the wrapper defaults to `false`; `_tryExecuteExtensionCommand` is byte-identical across 1.2.0–1.5.1, and although 1.5.1 moved the rest of `sendUserMessage` into `_preparePrompt`, the extension-command branch is still its first early exit — see the host-compatibility discipline in AGENTS.md). Pre-validation uses `pi.getCommands()` (accepting only `source: "extension"`). Depends on `smol-toml` (zero-dependency, ~10KB, TOML 1.0).
470
+ > **Implementation notes**: execution uses `sendUserMessage(cmd, { expandPromptTemplates: true })` — that option routes `/cmd args` into command dispatch instead of the model prompt path (the wrapper defaults to `false`; `_tryExecuteExtensionCommand` is byte-identical across 1.2.0–1.5.2, and although 1.5.1 moved the rest of `sendUserMessage` into `_preparePrompt`, the extension-command branch is still its first early exit — see the host-compatibility discipline in AGENTS.md). Pre-validation uses `pi.getCommands()` (accepting only `source: "extension"`). Depends on `smol-toml` (zero-dependency, ~10KB, TOML 1.0).
455
471
 
456
472
  ---
457
473
 
@@ -477,14 +493,33 @@ repository root stays readable: `AGENTS.md`, `specs/`, `design/`, `docs/`,
477
493
 
478
494
  | Command | What it does |
479
495
  | --- | --- |
480
- | `/ask-init` | detect → show the plan → (confirm) → move/scaffold/snapshot → dispatch the prose work to the model |
481
- | `/ask-init plan [--deep]` | print the plan and write nothing (`--dry-run` is the same) |
482
- | `/ask-init check` | audit the installed framework (read-only; writes only a runtime report under `.agents/framework/reports/`) |
496
+ | `/ask-init` | first run: detect → plan → confirm → move/scaffold/snapshot → dispatch; installed framework: refresh framework-owned text, then audit (no model turn) |
497
+ | `/ask-init plan [--deep]` | print the plan and write nothing (`--dry-run` is the same), including the framework-parity section |
498
+ | `/ask-init check` | audit the installed framework, including framework-vs-template parity (read-only; writes only a runtime report under `.agents/framework/reports/`) |
483
499
  | `/ask-init roots` | sync the directories added with `pi-add-dir` into the framework state |
484
- | `/ask-init refresh` | refresh framework-owned files (contract, signpost, acceptance contract) and the workflow block in `AGENTS.md`; files you edited by hand are left untouched |
500
+ | `/ask-init refresh [--adopt]` | the refresh step on its own (also run by `/ask-init`): framework-owned files + the `AGENTS.md` workflow block; hand-edited files are left untouched. `--adopt` takes ownership of a legacy file that has no anchor, after you reviewed it |
485
501
  | `/ask-init --yes` | skip the confirmation panel |
486
502
  | `/ask-init --lang zh\|en` | rendering language for framework-generated files (per run; default: detected from the project's own docs) |
487
503
 
504
+ **Re-running is safe.** On an installed framework `/ask-init` first compares the
505
+ project's framework text with the version you are running: missing or behind
506
+ framework-owned files are refreshed, hand-edited files are left untouched, and
507
+ then the audit runs. If nothing drifted it says so and leaves framework files unchanged — no model
508
+ turn; the audit still writes its runtime report. After a package upgrade run `/ask-init` (or `/ask-init refresh`) and
509
+ `/reload` when the workflow block changed.
510
+
511
+ **What “installed” means for the ask loop**: `.agents/framework/state.toml`,
512
+ `AGENTS.md`, `.agents/memory/README.md` and `.agents/implementations/` exist. The
513
+ content is yours — small edits do not stop `/ask-uat` or `record_change`. Commands
514
+ that need the framework refuse with the missing list instead of guessing.
515
+ Mutating runs (including `refresh` and `roots`) refuse while `/ask`, a plan review
516
+ or the UAT page is active; `check` and `plan` stay available.
517
+
518
+ A project written by an older tool has no template anchor. `/ask-init` reports those
519
+ files as `I-FW-01` and leaves them alone because it cannot tell an old template from
520
+ your edit. Review one, then run `/ask-init refresh --adopt` to take ownership of the
521
+ current bytes; the next refresh updates them normally.
522
+
488
523
  **What the mechanical half guarantees**:
489
524
 
490
525
  1. **Snapshot first** — every path the run may write (including every file whose
@@ -515,13 +550,15 @@ unit spec verbatim. The default pass is conservative: install, fix mechanical
515
550
  drift (tombstones, duplicated sections, appendix order), and record an over-budget
516
551
  `AGENTS.md` as debt instead of rewriting prose; `--deep` opts into structural edits.
517
552
 
518
- **Audit codes** (stable, so reports compare across runs): `E-PATH-01` bare legacy
519
- paths, `E-STATE-01` memory gitignored, `W-STATE-01` memory not yet committed, `E-INDEX-01` index ↔ file
520
- mismatch, `E-LINK-01` broken internal links, `W-BUDGET-01` `AGENTS.md` over budget,
521
- `W-DUP-01` the same section in two files, `W-ORDER-01` sections appended after the
522
- appendix, `W-COV-01` open coverage rows, `W-TODO-01` retired `todos/` still present,
523
- `W-ROOT-02` zero-byte root files, `W-SCAFFOLD-01` unfilled `TODO(ask-init)` markers,
524
- `I-INSTALL-01` framework not installed yet.
553
+ **Audit codes** (stable, so reports compare across runs):
554
+
555
+ - **paths** — `E-PATH-01` bare legacy paths while a legacy directory still exists (a move would break them); `W-PATH-01` the same references once the legacy directories are gone.
556
+ - **structure and state** — `E-STATE-01` memory gitignored, `W-STATE-01` memory not yet committed, `E-STATE-02` state version mismatch, `E-INDEX-01` index ↔ file mismatch, `E-LINK-01` broken internal links, `E-CONTRACT-01` missing memory contract.
557
+ - **memory hygiene** — `W-BUDGET-01/02` `AGENTS.md` / memory file over budget, `W-DUP-01` the same section in two files, `W-ORDER-01` sections appended after the appendix, `W-COV-01` open coverage rows, `W-META-01` `FUTURE.md` entry without a trigger, `W-EVID-01` `FINISHED.md` entry without evidence, `W-PLAN-01` spec/spec-plan drift, `W-OVERRIDE-01` `AGENTS.override.md` shadowing the entry, `W-SCAFFOLD-01` unfilled `TODO(ask-init)` markers.
558
+ - **roots and retired dirs** — `W-ROOT-01` agent-only directory at the root, `W-ROOT-02` zero-byte root file, `W-ROOT-03` missing registered root, `W-ROOT-04` scope card too large, `W-TODO-01` retired `todos/` still present.
559
+ - **framework files** — `W-FW-01` managed file edited by hand, `W-FW-02` managed file missing or behind the installed template, `W-FW-03` workflow block missing/behind/malformed or hand-written without markers, `W-FW-04` required framework file missing, `I-FW-01` no template anchor (cannot tell a hand edit from older bytes; review and `refresh --adopt` if it is the framework’s own text).
560
+ - **acceptance** — `E-UAT-01` unparseable ledger line, `W-UAT-01` item points at a missing record, `W-UAT-02` candidate waiting too long, `W-UAT-03` item open too long, `W-REC-01` non-canonical change record, `I-UAT-01` acceptance ledger not installed.
561
+ - **info** — `I-AGENTS-01` `.agents/skills` present, `I-INSTALL-01` framework not installed yet.
525
562
 
526
563
  **Multi-repository workspaces**: memory lives in the main repository only.
527
564
  `pi-add-dir` injects each added root's `AGENTS.md` verbatim into every request, so a
@@ -565,6 +602,29 @@ Ctrl+Z suspend/resume both re-enter the TUI, and a live session must never be ki
565
602
  trigger is deliberately limited to TUI mode: RPC/JSON/print stdout is machine-readable and is
566
603
  never given terminal escape sequences.
567
604
 
605
+ **Two hangs, two layers.** The fire path above lives on the main event loop — which is exactly
606
+ what can also die: on 2026-11-13 the guard fired, wrote its report, printed "forcing exit" and
607
+ called `process.exit(0)` … and the process hung for 18 minutes in `futex_wait` with the pty
608
+ already deleted (the user had closed the terminal window to escape). Host code on the exit path
609
+ (`process.on("exit")` listeners, bundled graceful-fs patches, stdio flush) can deadlock
610
+ synchronously, and a `setTimeout` fallback cannot fire inside a dead loop. Therefore:
611
+
612
+ - **arm-time watchdog thread** — arming also starts a `worker_threads` worker that does not
613
+ live on the main loop. The main loop beats a 1 Hz heartbeat into shared memory; after the
614
+ deadline (plus a head start for the main-loop fire timer, which handles the common hangs with
615
+ full context: raw-mode probe, full report, terminal restore) the worker samples the heartbeat
616
+ twice. Still beating → the event loop is alive → it steps aside (the fire timer owns the
617
+ outcome, including its stray-marker protection). Stopped → the main loop can never fire → the
618
+ worker restores the terminal, writes a minimal `-thread.json` report and SIGKILLs. This also
619
+ covers the blind spot where the main thread deadlocks *before* the fire deadline — e.g.
620
+ synchronously inside `process.exit` right after a fast dispose — because the worker never
621
+ needed the main loop in the first place. Every disarm (TUI restart, Ctrl+Z resume, `/reload`)
622
+ cancels the worker, so a returning TUI is never killed.
623
+ - **fire-time hard kill** — after the report is on disk and "forcing exit" printed, fire()
624
+ starts a second worker that unconditionally SIGKILLs 500 ms later; `process.exit(0)` and a
625
+ same-loop `setTimeout` SIGKILL run before it, so the worker only matters when the main thread
626
+ is blocked inside the exit path (the exact 2026-11-13 shape).
627
+
568
628
  ### Commands
569
629
 
570
630
  | Command | Effect |
@@ -599,7 +659,8 @@ arguments are redacted with the same rules as the approval log, so `pi --api-key
599
659
  leave the key on disk.
600
660
 
601
661
  `PI_QUIT_GUARD_DEBUG=<file>` appends one line per `arm` / `disarm` / `fire` (plus one per
602
- extension registration); once the TUI is gone it is the only channel left.
662
+ extension registration); once the TUI is gone it is the only channel left. A thread-watchdog
663
+ kill appends `thread-kill heartbeat-stopped …` there.
603
664
 
604
665
  ### Boundaries
605
666
 
@@ -609,13 +670,41 @@ extension registration); once the TUI is gone it is the only channel left.
609
670
  (not observed; `drainInput` is bounded at 1 s) is out of scope.
610
671
  - When it fires, the remaining extension cleanup is skipped **by design** — that cleanup is what
611
672
  was hanging. Session entries are appended to the session JSONL as they happen, so the
612
- transcript is intact up to the last written entry. The process exits 0; if `process.exit()`
613
- itself is turned into a no-op by an `exit` listener, a 500 ms fallback sends `SIGKILL`.
673
+ transcript is intact up to the last written entry. The process exits 0; if the exit path
674
+ itself deadlocks (observed for real: host `exit` listeners, stdio flush), the layered
675
+ fallbacks — same-loop `setTimeout` SIGKILL, then the watchdog/hard-kill worker threads — end
676
+ the process anyway. A worker cannot be constructed only under resource exhaustion; the guard
677
+ then degrades to the behavior it had before the thread layers existed.
614
678
  - This is a workaround for a host gap. If pi ever bounds `session_shutdown`, the guard becomes
615
679
  a no-op safety net and can be removed.
616
680
 
617
681
  ---
618
682
 
683
+ ## 🆕 whats-new — release notes after an upgrade
684
+
685
+ <a name="whats-new"></a>
686
+
687
+ **What this does.** The first interactive `pi` start after an upgrade prints the notes for every
688
+ version between the one you last ran and the one you just installed — once. Later starts are
689
+ silent: the version is recorded in `<agent-dir>/pi-toolkits-whats-new.json`, so the notice never
690
+ comes back for that version. A fresh install is silent too (there is no previous version to
691
+ report from), and a downgrade is not an upgrade.
692
+
693
+ The notes are the bundled `CHANGELOG.md`: `pnpm release` renames its `## Unreleased` section to
694
+ the version being published (`--skip-changelog` bypasses that gate), so the notes always describe
695
+ the version that actually shipped. The startup notice is a session entry — it survives theme
696
+ changes and invalidations, and it stays out of the model context, so it costs no tokens. It is
697
+ capped at four versions and six notes per version; the file keeps everything. There is no slash
698
+ command: this is a plugin, and an automatic notice should not occupy the host's command namespace.
699
+
700
+ **Boundaries** — interactive TUI only: print/JSON/RPC sessions have no transcript to append to,
701
+ so they leave the notice for the first interactive start instead of consuming it. Notes appear
702
+ only when the version *increases*; reinstalling or downgrading records nothing new. If
703
+ `CHANGELOG.md` has no section for the running version, the notice still reports the version
704
+ change with an explicit "no release notes bundled" line rather than inventing content.
705
+
706
+ ---
707
+
619
708
  ## 🛠️ Development
620
709
 
621
710
  <a name="development"></a>
@@ -653,14 +742,23 @@ src/
653
742
  │ # tests
654
743
  ├── favorites/ # model favorites: selector + cycle patches,
655
744
  │ # persisted store, tests
745
+ ├── init/ # agent memory framework: detect/plan/apply/audit,
746
+ │ # template parity + refresh, workflow markers,
747
+ │ # templates, tests
656
748
  ├── permission/ # session-scoped boundary permission: modes, panel,
657
749
  │ # bash units, policy, session grants, prompt,
658
750
  │ # audit payload, tests
751
+ ├── plan/ # browser-reviewed planning: phases, block diff,
752
+ │ # review server, UI, tests
659
753
  ├── quit-guard/ # quit watchdog: TUI teardown + quit-event triggers,
660
754
  │ # settings store, hang report, tests
661
- ├── review/ # third-party review: input/command triggers,
755
+ ├── review/ # third-party review: command trigger,
662
756
  │ # review model config store, prompt, tests
663
- └── stash/ # prompt stash: hotkey state machine + tests
757
+ ├── stash/ # prompt stash: hotkey state machine + tests
758
+ ├── uat/ # acceptance ledger: records/ledger, page server,
759
+ │ # record_change + uat_item, UI, tests
760
+ └── whats-new/ # release notes after an upgrade: CHANGELOG parser,
761
+ # last-seen store, startup notice, tests
664
762
  ```
665
763
 
666
764
  **Adding a feature**: create `src/features/<name>/` exporting `registerXxx(pi)` and call it from `src/index.ts`. Existing modules stay untouched. Each feature ships its own `*.test.ts` (vitest) — keep them deterministic (inject clocks/state, no real agent-dir writes).
@@ -677,7 +775,7 @@ pnpm release:github # create/verify the GitHub Release for the c
677
775
  pnpm release:github --audit # list npm versions vs GitHub Releases vs remote tags
678
776
  ```
679
777
 
680
- Releasing is a **tag push**. `pnpm release` runs the gates (`typecheck`, `test`, UI checks), bumps the version, commits, tags `vX.Y.Z`, pushes the branch and the tag — then waits for the GitHub Actions `publish` workflow. That workflow publishes with **npm trusted publishing (OIDC)**: no npm token, no interactive 2FA, and a provenance attestation on every version. The script only reports success once the version is on npm with `dist.attestations` non-empty.
778
+ Releasing is a **tag push**. `pnpm release` runs the gates (`typecheck`, `test`, UI checks), promotes the `## Unreleased` section of `CHANGELOG.md` to the new version (an empty section aborts the release — `--skip-changelog` opts out), bumps the version, commits, tags `vX.Y.Z`, pushes the branch and the tag — then waits for the GitHub Actions `publish` workflow. That workflow publishes with **npm trusted publishing (OIDC)**: no npm token, no interactive 2FA, and a provenance attestation on every version. The script only reports success once the version is on npm with `dist.attestations` non-empty.
681
779
 
682
780
  `--prepare-only` is the "prepare everything, decide later" switch: it stops after commit+tag and prints the exact push command. `--no-wait` returns right after the push; `--local` is the emergency path that publishes from this machine with the old token. A failed workflow is retried on the same tag (`gh workflow run publish.yml -f tag=vX.Y.Z`); an already-published version is skipped, so the rerun is idempotent.
683
781
 
package/README.zh-CN.md CHANGED
@@ -13,9 +13,9 @@
13
13
  [![pi >= 0.99](https://img.shields.io/badge/pi-%3E%3D0.99.0-blueviolet)](https://github.com/earendil-works/pi)
14
14
  [![GitHub](https://img.shields.io/badge/github-andares%2Fpi--toolkits-181717?logo=github)](https://github.com/andares/pi-toolkits)
15
15
 
16
- 一句话介绍:目前包含十一个开箱即用的功能——**只读咨询模式** `ask`、**会话级边界权限** `ask-perm`、**模型收藏** `favorites`、**提示词暂存** `stash`、**第三方代码评审** `ask-review`、**独立压缩模型** `compact-model`、**会话启动自动化** `autostart`、**agent 记忆框架** `ask-init`、**浏览器内计划评审** `ask-plan`、**验收台账与浏览器页面** `ask-uat`、**退出看门狗** `quit-guard`,后续持续追加。
16
+ 一句话介绍:目前包含十二个开箱即用的功能——**只读咨询模式** `ask`、**会话级边界权限** `ask-perm`、**模型收藏** `favorites`、**提示词暂存** `stash`、**第三方代码评审** `ask-review`、**独立压缩模型** `compact-model`、**会话启动自动化** `autostart`、**agent 记忆框架** `ask-init`、**浏览器内计划评审** `ask-plan`、**验收台账与浏览器页面** `ask-uat`、**退出看门狗** `quit-guard`、**升级后首次启动的版本变更提示** `whats-new`,后续持续追加。
17
17
 
18
- **版本要求**:pi `>=0.99.0`。0.99.0 到 1.5.1 的每一个已发布版本都用完整门禁实测过(install → `tsc --noEmit` → 全量测试 → 键位审计 → 对 patch 目标宿主文件做哈希比对),每个版本都在沙箱中把整个 `@earendil-works/*` 家族钉在同一版本。更新的版本随发布逐个验证,下限只在实测结果允许时移动;`pnpm check:compat` 可复现该结论。注:pi ≥ 0.99 的宿主要求「宿主提供的包」一律声明为 peerDependencies `"*"` —— `@earendil-works/pi-tui` 与 `typebox`(ask 的 `scratchpad` 用它构造参数 schema)都按此声明;若放进 `dependencies`,pi 会告警。
18
+ **版本要求**:pi `>=0.99.0`。0.99.0 到 1.5.2 的每一个已发布版本都用完整门禁实测过(install → `tsc --noEmit` → 全量测试 → 键位审计 → 对 patch 目标宿主文件做哈希比对),每个版本都在沙箱中把整个 `@earendil-works/*` 家族钉在同一版本。更新的版本随发布逐个验证,下限只在实测结果允许时移动;`pnpm check:compat` 可复现该结论。注:pi ≥ 0.99 的宿主要求「宿主提供的包」一律声明为 peerDependencies `"*"` —— `@earendil-works/pi-tui` 与 `typebox`(ask 的 `scratchpad` 用它构造参数 schema)都按此声明;若放进 `dependencies`,pi 会告警。
19
19
 
20
20
  ---
21
21
 
@@ -58,6 +58,7 @@ pi -e ./src/index.ts
58
58
  - [🚀 autostart — 会话启动自动化](#autostart)
59
59
  - [🧠 init — agent 记忆框架](#init)
60
60
  - [🧯 quit-guard — 退出看门狗](#quit-guard)
61
+ - [🆕 whats-new — 升级后的版本变更提示](#whats-new)
61
62
  - [开发](#development)
62
63
  - [贡献](#contributing)
63
64
  - [许可](#license)
@@ -76,11 +77,12 @@ pi -e ./src/index.ts
76
77
  | 📥 **stash** 提示词暂存 | `ctrl+alt+y` | 一段提示词的暂存槽,按键交换 / 连按两次暂存并清空输入框 |
77
78
  | 🔎 **review** 第三方代码评审 | `/ask-review` | 召唤配置的评审模型,对刚完成的任务做查+修,重点检查「本轮需求实现 / 是否有遗漏 / 是否有错误」 |
78
79
  | 🧭 **plan** 浏览器内计划评审 | `/ask-plan` | 先调研、写 plan、在浏览器里逐段评审并逐块批注,批准之后才动代码 |
79
- | ✅ **uat** 验收台账 | `/ask-uat` | 把待归类的实施记录聚成用户视角的验收项,在页面里勾选(只追加、无提交),看清哪些已交付但还没验过 |
80
+ | ✅ **uat** 验收台账 | `/ask-uat` | `/ask-init` 之后:把待归类的实施记录聚成用户视角的验收项,在页面里勾选(只追加、无提交),看清哪些已交付但还没验过 |
80
81
  | 🗜️ **compact** 独立压缩模型 | `/compact-model` | 给 `/compact` 与 auto-compact 配一个便宜快模型做总结,主模型专注对话;未配置零开销、任何异常回落 pi 默认 |
81
82
  | 🚀 **autostart** 会话启动自动化 | `.pi/autostart.toml` | 项目内声明启动时自动执行的斜杠命令(首批用例:`/add-dir` 多仓库挂载);未信任不执行、未注册命令跳过不发给模型 |
82
- | 🧠 **init** agent 记忆框架 | `/ask-init` | 安装或接管一套固定的记忆结构(`AGENTS.md` + `specs/` + `.agents/memory` + `.agents/implementations`),带快照与覆盖表迁移旧文档,之后可随时审计漂移、预算与重复事实 |
83
+ | 🧠 **init** agent 记忆框架 | `/ask-init` | 安装或接管一套固定的记忆结构(`AGENTS.md` + `specs/` + `.agents/memory` + `.agents/implementations`),带快照与覆盖表迁移旧文档,之后可随时审计/刷新漂移、预算与重复事实 |
83
84
  | 🧯 **quit-guard** 退出看门狗 | `/quit-guard` | 交互式退出卡死时,无论发生在 TUI 收尾之后、还是信号触发路径的收尾之前,超时后写诊断报告并强制退出,把命令行提示符还给你;TUI 重启与 Ctrl+Z 恢复都会解除看守 |
85
+ | 🆕 **whats-new** 升级后的版本变更提示 | 自动 | 升级后的首次 `pi` 启动展示「从你上次运行的版本到现在改了什么」,只展示一次;不注册斜杠命令,不占用宿主的全局命令命名空间 |
84
86
 
85
87
  ---
86
88
 
@@ -90,6 +92,8 @@ pi -e ./src/index.ts
90
92
 
91
93
  用 `/ask` 进入(再按一次退出)。适合只想要「问问题、读代码」的场景:模型不能改项目,但不会被剥夺思考的落点。
92
94
 
95
+ ask 是独立的(不需要 `/ask-init`)。计划评审或 UAT 页面开着时先退出它们——ask 不会叠在另一个相位上启动,因为那个相位的 `before_agent_start` 会把写工具重新加回来。
96
+
93
97
  **进入后**:
94
98
 
95
99
  - **项目文件写入仍然机制上不可能** —— `write` / `edit` / `powershell` 从活跃工具集中移除,pi 对未激活工具的调用直接拒绝("Tool not found");闸门还会二次拦截,防止有东西把它们重新打开
@@ -136,8 +140,11 @@ pi -e ./src/index.ts
136
140
  - **bash** 先拆成简单命令 —— `&&`、`||`、`;`、管道、`$(…)`、反引号、`bash -c`、`eval`、常见间接包装(`sudo`、`env`、`xargs`、`find -exec`…)、heredoc —— 再逐条判定;`cd` 向前折叠,取最严格的结果,所以 `cd /tmp && rm x` 不会靠第一段蒙混过关
137
141
  - **带路径的工具**(`read` / `write` / `edit` / `grep` / `find` / `ls`)按自己的路径判定;其它工具按工作目录判定
138
142
  - **无法解析的输入** —— 非字面量 `cd` 或 `git -C`、路径里的未知 shell 变量、未闭合的 heredoc/命令替换 —— 一律询问,不看模式(fail closed),绝不猜测
143
+ - **字面量 for 循环** —— `for f in a b; do grep x "$f"; done` 按字面量展开(这正是 bash 的行为);普通赋值不跨命令持久化(缺少控制流分析时不能安全替换),值来自 `$(…)`、循环列表不可知、循环变量被重赋值/修改时仍按 fail-closed 处理。换行是命令分隔符(`ls⏎rm x` 是两条命令,不是一条),反斜杠+换行是续行
144
+ - **模式不是路径** —— `grep`/`rg`/`ag` 的第一个位置参数是模式(`grep -n '</div>\s*$' file` 不会询问);引号内的结尾 `$` 是字面字符,不是变量
139
145
  - **`git -C <dir>`** 按局部 `cd` 处理:相对路径参数(和仓库本身)按 `<dir>` 判定,而不是工作目录
140
- - **设备 sink 与数据参数** —— `/dev/null`、`/dev/stdout`、`/dev/stderr` 无论是重定向(`cmd > /dev/null`)还是普通操作数(`curl -o /dev/null`),都不算边界目标;`echo` / `printf` 的参数是数据,不按路径处理
146
+ - **设备 sink 与数据参数** —— `/dev/null`、`/dev/stdout`、`/dev/stderr` 无论是重定向(`cmd > /dev/null`)还是普通操作数(`curl -o /dev/null`),都不算边界目标;`echo` / `printf` 的参数是数据,`curl -w` / `-H` / `-d` 这类已声明的 data flag 同理。未解析的输入与输出重定向都保持 fail closed
147
+ - **容器只读子命令** —— `docker`/`podman` 的只读子命令(`ps`、`logs`、`inspect`、`images`、`compose ps/logs/config` 等)算读;`exec`、`run`、`rm`、`build` 以及未列出的子命令算写
141
148
 
142
149
  **回答**:`a` 本次允许 · `s` 本会话允许该目录 · `d` 拒绝 · `f` 本会话拒绝该目录。会话授权在内存中按 `(读|写, 目录)` 保存、按包含关系匹配,关闭模式或会话结束时清空;**会话授权优先于破坏性表**——你按了 `s` 之后,重复同一操作不会再弹;解析不了完整路径的命令则按**完整命令文本**授权,重复同一条命令不会再问。
143
150
 
@@ -274,6 +281,7 @@ run = ["/ask-perm allow allow allow ask"]
274
281
 
275
282
  - **未配置 / 配置的模型已不可用**(如在 pi 的 models.json 里删掉了该模型)→ 提示后照常弹出列表(此时无默认项)
276
283
  - 任务仍在进行中(agent 未空闲)时触发 → 提示等待,不执行;同一时间只允许一个评审
284
+ - 计划期 → 拒绝(评审中的计划不能被改);ask 模式会自动退出,因为查+修需要完整工具集
277
285
  - footer 出现灰色 `review` 状态 = 已配置评审模型
278
286
 
279
287
  ---
@@ -299,7 +307,9 @@ run = ["/ask-perm allow allow allow ask"]
299
307
  /ask-plan off # 退出计划期(草稿留在原处)
300
308
  ```
301
309
 
302
- spec 落在 `specs/<slug>.md`,与 `/ask-init` 的计划同一个位置。
310
+ spec 落在 `specs/<slug>.md`,与 `/ask-init` 的计划同一个位置。没有 agent 框架时计划仍能用,
311
+ 但 `record_change` 与 `/ask-uat` 要等 `/ask-init` 之后才可用;进入计划期时会提示。
312
+ UAT 页面开着时先 `/ask-uat off`——两个相位不会叠着跑。
303
313
 
304
314
  ---
305
315
 
@@ -315,6 +325,10 @@ spec 落在 `specs/<slug>.md`,与 `/ask-init` 的计划同一个位置。
315
325
  附一句「用户视角能做什么」;UAT 侧把多条记录聚成少数验收项——一条行为可能要十条记录,
316
326
  一条记录也可能碰到多个行为。
317
327
 
328
+ **需要框架。** 项目缺少框架状态、`AGENTS.md`、记忆合同或 `.agents/implementations/` 时,
329
+ `/ask-uat` 直接拒绝;先跑 `/ask-init`。此时 `record_change` 也不可用。判定按特征而非字节:
330
+ 你对这些文件的小改不会挡住页面。
331
+
318
332
  ```text
319
333
  record_change(实施)→ /ask-uat(聚类)→ 浏览器(勾选)→ 台账
320
334
  ```
@@ -365,7 +379,7 @@ pi 的 `/compact` 与 auto-compact 默认**用当前会话模型**做上下文
365
379
  | auto-compact 阈值触发 | 压缩模型总结 |
366
380
  | context overflow 恢复 | 压缩模型总结,重试行为不变 |
367
381
 
368
- **接管后与 pi 内建行为完全一致的部分**(逐字同步 pi 内建实现,复制自 0.87.1、在 1.2.0 → 1.5.1 内字节级不变 —— 除了此处采纳的两项 1.4.0 修正:摘要请求使用模型自身的输出上限而非 `reserveTokens` 的固定比例,以及 `/compact <instructions>` 也会进入 split-turn 前缀,外加 1.5.0 的 `cost.totalFromProvider` 合并规则(用量统计);只换执行模型;对话序列化函数(`serializeConversation`)是直接从宿主导入的,因此跟随宿主行为 —— 例如 1.2.0 起不再把 assistant thinking 回填进摘要请求):
382
+ **接管后与 pi 内建行为完全一致的部分**(逐字同步 pi 内建实现,复制自 0.87.1、在 1.2.0 → 1.5.2 内字节级不变 —— 除了此处采纳的两项 1.4.0 修正:摘要请求使用模型自身的输出上限而非 `reserveTokens` 的固定比例,以及 `/compact <instructions>` 也会进入 split-turn 前缀,外加 1.5.0 的 `cost.totalFromProvider` 合并规则(用量统计);只换执行模型;对话序列化函数(`serializeConversation`)是直接从宿主导入的,因此跟随宿主行为 —— 例如 1.2.0 起不再把 assistant thinking 回填进摘要请求):
369
383
 
370
384
  - **摘要格式** —— Goal / Progress / Key Decisions 结构化 checkpoint;已有摘要时用迭代更新版 prompt,信息延续不丢
371
385
  - **切分行为** —— 保留最近 `keepRecentTokens` 的策略、`firstKeptEntryId` / `tokensBefore` 原样回传,不动
@@ -446,7 +460,7 @@ run = [
446
460
 
447
461
  **关键约束:只支持扩展命令**。`/add-dir`(pi-add-dir)、`/cd`(pi-cd)等 `registerCommand` 注册的命令可以;内置命令(`/compact`、`/reload`、`/resume`…)在 TUI 层分发,扩展层触发不了;skill 命令(`/skill:name`)是展开机制而非执行机制。依赖的目标扩展(如 pi-add-dir)需要先安装。
448
462
 
449
- > **实现说明**:执行用 `sendUserMessage(cmd, { expandPromptTemplates: true })` —— 该选项把 `/cmd args` 路由到命令分发而不是模型 prompt 路径(包装层默认 `false`;`_tryExecuteExtensionCommand` 在 1.2.0–1.5.1 全区间字节级一致,1.5.1 虽把 `sendUserMessage` 其余部分重构进 `_preparePrompt`,扩展命令分支仍是它最前面的早退路径,见 AGENTS.md 宿主兼容纪律)。预校验用 `pi.getCommands()`(只认 `source: "extension"`)。依赖 `smol-toml`(零依赖、~10KB、TOML 1.0)。
463
+ > **实现说明**:执行用 `sendUserMessage(cmd, { expandPromptTemplates: true })` —— 该选项把 `/cmd args` 路由到命令分发而不是模型 prompt 路径(包装层默认 `false`;`_tryExecuteExtensionCommand` 在 1.2.0–1.5.2 全区间字节级一致,1.5.1 虽把 `sendUserMessage` 其余部分重构进 `_preparePrompt`,扩展命令分支仍是它最前面的早退路径,见 AGENTS.md 宿主兼容纪律)。预校验用 `pi.getCommands()`(只认 `source: "extension"`)。依赖 `smol-toml`(零依赖、~10KB、TOML 1.0)。
450
464
 
451
465
  ---
452
466
 
@@ -470,13 +484,28 @@ run = [
470
484
 
471
485
  | 命令 | 作用 |
472
486
  | --- | --- |
473
- | `/ask-init` | 检测 → 出计划 → 确认 → 移动/脚手架/快照 → 把正文工作派发给模型 |
474
- | `/ask-init plan [--deep]` | 只打印计划,不写任何盘(`--dry-run` 同义) |
475
- | `/ask-init check` | 审计已装的框架(只读;只在 `.agents/framework/reports/` 留下运行期报告) |
487
+ | `/ask-init` | 首次:检测 → 出计划 → 确认 → 移动/脚手架/快照 → 派发;已安装:先刷新框架文字,再审计(不派模型) |
488
+ | `/ask-init plan [--deep]` | 只打印计划,不写任何盘(`--dry-run` 同义),含框架对等检查段 |
489
+ | `/ask-init check` | 审计已装的框架,含框架文字与模板的对等检查(只读;只在 `.agents/framework/reports/` 留下运行期报告) |
476
490
  | `/ask-init roots` | 把 `pi-add-dir` 添加的目录同步进框架状态 |
477
- | `/ask-init refresh` | 刷新框架拥有的文件(合同、门牌、验收合同)与 `AGENTS.md` 里的工作流块;手工改过的文件一概不动 |
491
+ | `/ask-init refresh [--adopt]` | 单独执行刷新(`/ask-init` 也会跑):框架拥有文件 + `AGENTS.md` 里的工作流块;手工改过的文件一概不动。`--adopt` 在你核对过之后,把没有锚的旧文件认作框架拥有并接管 |
478
492
  | `/ask-init --yes` | 跳过确认面板 |
479
- | `/ask-init --lang zh\|en` | 框架生成文件的渲染语言(单次生效;默认按项目自身文档判定) |
493
+ | `/ask-init --lang zh\|en` | 框架生成文件的渲染语言(单次生效;默认按项目自身文档判定) |
494
+
495
+ **重复运行是安全的。** 已安装框架时,`/ask-init` 先对比项目里的框架文字与当前版本:
496
+ 缺失或落后的框架拥有文件会刷新,手工改过的保持原状,然后跑审计。没有任何漂移时
497
+ 会明确说「已是最新」,不修改框架文件——也不会派模型回合(审计仍写运行期报告)。升级包之后运行 `/ask-init`
498
+ (或 `/ask-init refresh`),工作流块变了再 `/reload`。
499
+
500
+ **ask 循环说的「已安装」**:`.agents/framework/state.toml`、`AGENTS.md`、
501
+ `.agents/memory/README.md`、`.agents/implementations/` 存在。内容是用户的——小改
502
+ 不会让 `/ask-uat` 或 `record_change` 拒绝;需要框架的命令会把缺失项列出来。
503
+ mutating 运行(含 `refresh`、`roots`)在 `/ask`、计划评审或 UAT 页面开着时拒绝;
504
+ `check` 与 `plan` 仍可用。
505
+
506
+ 旧工具写的项目没有模板锚。`/ask-init` 把这些文件报成 `I-FW-01` 并保持原状——它分不清
507
+ 旧模板和你的手改。核对一份之后运行 `/ask-init refresh --adopt` 接管当前字节;之后的
508
+ refresh 就会正常更新它。
480
509
 
481
510
  **机械那一半保证什么**:
482
511
 
@@ -499,11 +528,15 @@ run = [
499
528
  装框架、修机械漂移(墓碑、重复章节、附录顺序),超预算的 `AGENTS.md` 只登记成债务;
500
529
  `--deep` 才允许结构性改写。
501
530
 
502
- **审计码**(稳定,可跨次对比):`E-PATH-01` 裸旧路径、`E-STATE-01` 记忆被 gitignore、`W-STATE-01` 记忆尚未提交、`E-INDEX-01` 索引与实际文件不一致、`E-LINK-01` 内部链接失效、
503
- `W-BUDGET-01` `AGENTS.md` 超预算、`W-DUP-01` 同一章节出现在两个文件、
504
- `W-ORDER-01` 附录之后又追加章节、`W-COV-01` 覆盖表仍有 OPEN、
505
- `W-TODO-01` 仍存在退役的 `todos/`、`W-ROOT-02` 根下零字节文件、
506
- `W-SCAFFOLD-01` 未填的 `TODO(ask-init)` 标记、`I-INSTALL-01` 尚未安装框架。
531
+ **审计码**(稳定,可跨次对比):
532
+
533
+ - **路径** —— `E-PATH-01` 旧目录仍存在时的裸旧路径(移动会断);`W-PATH-01` 旧目录已不存在时的同类引用。
534
+ - **结构与状态** —— `E-STATE-01` 记忆被 gitignore、`W-STATE-01` 记忆尚未提交、`E-STATE-02` 状态版本不符、`E-INDEX-01` 索引与实际文件不一致、`E-LINK-01` 内部链接失效、`E-CONTRACT-01` 缺记忆合同。
535
+ - **记忆卫生** —— `W-BUDGET-01/02` `AGENTS.md` / 记忆文件超预算、`W-DUP-01` 同一章节出现在两个文件、`W-ORDER-01` 附录之后又追加章节、`W-COV-01` 覆盖表仍有 OPEN、`W-META-01` `FUTURE.md` 条目缺触发条件、`W-EVID-01` `FINISHED.md` 条目缺证据、`W-PLAN-01` spec / 计划漂移、`W-OVERRIDE-01` `AGENTS.override.md` 顶替入口、`W-SCAFFOLD-01` 未填的 `TODO(ask-init)` 标记。
536
+ - **根与退役目录** —— `W-ROOT-01` 根下 agent-only 目录、`W-ROOT-02` 根下零字节文件、`W-ROOT-03` 登记的 root 缺失、`W-ROOT-04` scope card 过大、`W-TODO-01` 仍存在退役的 `todos/`。
537
+ - **框架文件** —— `W-FW-01` 受管文件被手工改过、`W-FW-02` 受管文件缺失或落后于当前模板、`W-FW-03` 工作流块缺失/落后/marker 不一致/手写无 marker、`W-FW-04` 必需框架文件缺失、`I-FW-01` 无模板锚(无法区分手工编辑与旧模板;核对是框架原文后跑 `refresh --adopt`)。
538
+ - **验收** —— `E-UAT-01` 台账行不可解析、`W-UAT-01` 项指向不存在的记录、`W-UAT-02` 候选等待过久、`W-UAT-03` 项超 30 天未勾、`W-REC-01` 近期记录首行/文件名不合规、`I-UAT-01` 验收台账未安装。
539
+ - **信息** —— `I-AGENTS-01` `.agents/skills` 存在、`I-INSTALL-01` 尚未安装框架。
507
540
 
508
541
  **多仓库工作区**:记忆只住主仓。`pi-add-dir` 会把每个 added root 的 `AGENTS.md`
509
542
  全文注入每次请求,所以根里的入口只能是 **scope card**(≤30 行:这里放什么、它的命令、
@@ -557,6 +590,18 @@ run = [
557
590
 
558
591
  ---
559
592
 
593
+ ## 🆕 whats-new — 升级后的版本变更提示
594
+
595
+ <a name="whats-new"></a>
596
+
597
+ **做什么。** 升级后第一次进入交互式 `pi` 时,展示「你上次运行的版本 → 刚装上的版本」之间每个版本的变更要点,**只展示一次**。版本号记在 `<agent-dir>/pi-toolkits-whats-new.json`,同一版本之后再怎么进入都不会再弹;全新安装也不弹(没有「上一个版本」可对比),降级不算升级。
598
+
599
+ 变更内容来自随包发布的 `CHANGELOG.md`:`pnpm release` 会把 `## Unreleased` 改名成即将发布的版本号(`--skip-changelog` 可跳过这道闸),所以提示里的内容永远对得上真正发出去的那一版。启动提示是一个会话条目 —— 主题切换/invalidate 不会冲掉它,也不进模型上下文(不花 token)。启动提示最多展示 4 个版本、每个版本 6 条;全文始终在 `CHANGELOG.md` 里。不提供斜杠命令:插件只负责自动提示,不占宿主的全局命令命名空间。
600
+
601
+ **边界** —— 只覆盖交互式 TUI:print/JSON/RPC 模式没有可追加的 transcript,会把这次提示留给下一次交互式启动,而不是白白消耗掉。只有版本**升高**时才会提示;重装或降级什么都不记。若 `CHANGELOG.md` 没有当前版本的段落,提示仍会报告版本变化,并明确写「没有内置变更记录」,不会编造内容。
602
+
603
+ ---
604
+
560
605
  ## 🛠️ 开发
561
606
 
562
607
  <a name="development"></a>
@@ -593,14 +638,23 @@ src/
593
638
  │ # /compact-model、配置存储、prompt、测试
594
639
  ├── favorites/ # 模型收藏:选择器与循环 patch、
595
640
  │ # 持久化存储、测试
641
+ ├── init/ # agent 记忆框架:检测/计划/应用/审计、
642
+ │ # 模板对等检查 + refresh、工作流 marker、
643
+ │ # 模板、测试
596
644
  ├── permission/ # 会话级边界权限:模式、面板、bash 拆解、
597
645
  │ # 策略、会话授权、确认对话框、
598
646
  │ # 审计 payload、测试
647
+ ├── plan/ # 浏览器内计划评审:相位、块级 diff、
648
+ │ # 评审服务器、UI、测试
599
649
  ├── quit-guard/ # 退出看门狗:TUI 收尾 + quit 事件双触发、
600
650
  │ # 配置存储、诊断报告、测试
601
- ├── review/ # 第三方评审:输入/指令触发、
651
+ ├── review/ # 第三方评审:指令触发、
602
652
  │ # 评审模型配置存储、提示词、测试
603
- └── stash/ # 提示词暂存:热键状态机 + 测试
653
+ ├── stash/ # 提示词暂存:热键状态机 + 测试
654
+ ├── uat/ # 验收台账:记录/台账、页面服务器、
655
+ │ # record_change + uat_item、UI、测试
656
+ └── whats-new/ # 升级后的版本变更提示:CHANGELOG 解析、
657
+ # 已见版本存储、启动提示、测试
604
658
  ```
605
659
 
606
660
  **新增功能**:新建 `src/features/<name>/`,导出 `registerXxx(pi)`,在 `src/index.ts` 中调用;已有模块保持不变。每个功能自带 `*.test.ts`(vitest)——保持确定性(时钟/状态可注入,不写真实 agent-dir)。
@@ -617,7 +671,7 @@ pnpm release:github # 为当前版本创建/校验 GitHub Releas
617
671
  pnpm release:github --audit # 列出 npm 版本 vs GitHub Release vs 远端 tag
618
672
  ```
619
673
 
620
- **发版 = 推 tag。** `pnpm release` 跑完门禁(`typecheck`、`test`、UI 检查)、改版本、commit、打 `vX.Y.Z` tag、推分支和 tag,然后等 GitHub Actions 的 `publish` 工作流。该工作流用 **npm trusted publishing(OIDC)** 发布:不需要 npm token、不需要交互式 2FA,每个版本自动附 provenance。脚本只在 npm 上真的出现该版本、且 `dist.attestations` 非空时才报成功。
674
+ **发版 = 推 tag。** `pnpm release` 跑完门禁(`typecheck`、`test`、UI 检查)、把 `CHANGELOG.md` 的 `## Unreleased` 提升为即将发布的版本号(段落为空则中止,`--skip-changelog` 可跳过)、改版本、commit、打 `vX.Y.Z` tag、推分支和 tag,然后等 GitHub Actions 的 `publish` 工作流。该工作流用 **npm trusted publishing(OIDC)** 发布:不需要 npm token、不需要交互式 2FA,每个版本自动附 provenance。脚本只在 npm 上真的出现该版本、且 `dist.attestations` 非空时才报成功。
621
675
 
622
676
  `--prepare-only` 是「都准备好、发不发最后再说」的开关:停在 commit+tag 后,打印确切的推送命令。`--no-wait` 推完就返回;`--local` 是应急路径(本机用旧 token 发布)。工作流失败后重跑同一个 tag 即可(`gh workflow run publish.yml -f tag=vX.Y.Z`):已发布的版本会跳过,所以重跑是幂等的。
623
677