@andares/pi-toolkits 0.14.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.
- package/CHANGELOG.md +13 -0
- package/README.md +87 -21
- package/README.zh-CN.md +52 -17
- package/package.json +8 -2
- package/src/features/ask/index.test.ts +15 -0
- package/src/features/ask/index.ts +17 -0
- package/src/features/init/audit.test.ts +19 -2
- package/src/features/init/audit.ts +117 -15
- package/src/features/init/index.test.ts +123 -1
- package/src/features/init/index.ts +156 -46
- package/src/features/init/parity.test.ts +176 -0
- package/src/features/init/parity.ts +229 -0
- package/src/features/init/plan.ts +25 -3
- package/src/features/init/refresh.test.ts +88 -1
- package/src/features/init/refresh.ts +43 -64
- package/src/features/init/spec.ts +11 -0
- package/src/features/init/templates/memory-readme.md +9 -2
- package/src/features/init/test-helpers.ts +1 -0
- package/src/features/init/workflow.ts +159 -0
- package/src/features/plan/index.test.ts +51 -0
- package/src/features/plan/index.ts +24 -4
- package/src/features/quit-guard/constants.ts +18 -5
- package/src/features/quit-guard/index.ts +75 -29
- package/src/features/quit-guard/killer.test.ts +77 -0
- package/src/features/quit-guard/killer.ts +215 -0
- package/src/features/review/index.ts +14 -0
- package/src/features/review/review.test.ts +34 -2
- package/src/features/uat/index.test.ts +15 -0
- package/src/features/uat/index.ts +10 -7
- package/src/features/uat/record-tool.ts +3 -2
- package/src/features/uat/state.ts +13 -5
- package/src/lib/phases.ts +37 -0
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,18 @@ renames that heading to the version being published and refuses an empty section
|
|
|
11
11
|
|
|
12
12
|
<!-- Notes for the next release go here; `pnpm release` renames this heading. -->
|
|
13
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
|
+
|
|
14
26
|
## 0.14.0 — 2026-11-13
|
|
15
27
|
|
|
16
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.
|
|
@@ -41,3 +53,4 @@ renames that heading to the version being published and refuses an empty section
|
|
|
41
53
|
|
|
42
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.
|
|
43
55
|
|
|
56
|
+
|
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
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.
|
|
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
|
|
|
@@ -77,10 +77,10 @@ After installing, verify in any pi session:
|
|
|
77
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 |
|
|
78
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" |
|
|
79
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 |
|
|
80
|
-
| ✅ **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 |
|
|
81
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 |
|
|
82
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 |
|
|
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,
|
|
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 |
|
|
84
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
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 |
|
|
86
86
|
|
|
@@ -92,6 +92,8 @@ After installing, verify in any pi session:
|
|
|
92
92
|
|
|
93
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.
|
|
94
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
|
+
|
|
95
97
|
**While active**:
|
|
96
98
|
|
|
97
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
|
|
@@ -279,6 +281,7 @@ After a development task is done, type the `/ask-review` command to summon **a d
|
|
|
279
281
|
|
|
280
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)
|
|
281
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
|
|
282
285
|
- A grey `review` status in the footer means a review model is configured
|
|
283
286
|
|
|
284
287
|
---
|
|
@@ -304,7 +307,10 @@ After a development task is done, type the `/ask-review` command to summon **a d
|
|
|
304
307
|
/ask-plan off # leave the phase (the draft stays where it is)
|
|
305
308
|
```
|
|
306
309
|
|
|
307
|
-
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.
|
|
308
314
|
|
|
309
315
|
---
|
|
310
316
|
|
|
@@ -321,6 +327,11 @@ change record per finished round plus a one-sentence, user-facing description of
|
|
|
321
327
|
(`record_change`); the UAT side clusters many records into a few acceptance items — one
|
|
322
328
|
behaviour may need ten records, and one record may touch several behaviours.
|
|
323
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
|
+
|
|
324
335
|
```text
|
|
325
336
|
record_change (implementation) → /ask-uat (cluster) → browser (tick) → ledger
|
|
326
337
|
```
|
|
@@ -375,7 +386,7 @@ pi's `/compact` and auto-compact summarize the context **with the current sessio
|
|
|
375
386
|
| auto-compact threshold reached | summarized by the compaction model |
|
|
376
387
|
| context overflow recovery | summarized by the compaction model, retry behavior unchanged |
|
|
377
388
|
|
|
378
|
-
**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.
|
|
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):
|
|
379
390
|
|
|
380
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
|
|
381
392
|
- **Split behavior** — the `keepRecentTokens` retention policy, and `firstKeptEntryId` / `tokensBefore` passed back unchanged
|
|
@@ -456,7 +467,7 @@ An **identical command line** declared by both sources runs once: a duplicate is
|
|
|
456
467
|
|
|
457
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.
|
|
458
469
|
|
|
459
|
-
> **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.
|
|
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).
|
|
460
471
|
|
|
461
472
|
---
|
|
462
473
|
|
|
@@ -482,14 +493,33 @@ repository root stays readable: `AGENTS.md`, `specs/`, `design/`, `docs/`,
|
|
|
482
493
|
|
|
483
494
|
| Command | What it does |
|
|
484
495
|
| --- | --- |
|
|
485
|
-
| `/ask-init` | detect →
|
|
486
|
-
| `/ask-init plan [--deep]` | print the plan and write nothing (`--dry-run` is the same) |
|
|
487
|
-
| `/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/`) |
|
|
488
499
|
| `/ask-init roots` | sync the directories added with `pi-add-dir` into the framework state |
|
|
489
|
-
| `/ask-init refresh` | refresh
|
|
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 |
|
|
490
501
|
| `/ask-init --yes` | skip the confirmation panel |
|
|
491
502
|
| `/ask-init --lang zh\|en` | rendering language for framework-generated files (per run; default: detected from the project's own docs) |
|
|
492
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
|
+
|
|
493
523
|
**What the mechanical half guarantees**:
|
|
494
524
|
|
|
495
525
|
1. **Snapshot first** — every path the run may write (including every file whose
|
|
@@ -520,13 +550,15 @@ unit spec verbatim. The default pass is conservative: install, fix mechanical
|
|
|
520
550
|
drift (tombstones, duplicated sections, appendix order), and record an over-budget
|
|
521
551
|
`AGENTS.md` as debt instead of rewriting prose; `--deep` opts into structural edits.
|
|
522
552
|
|
|
523
|
-
**Audit codes** (stable, so reports compare across runs):
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
`W-
|
|
527
|
-
appendix, `W-COV-01` open coverage rows, `W-
|
|
528
|
-
`W-ROOT-02` zero-byte root
|
|
529
|
-
`I-
|
|
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.
|
|
530
562
|
|
|
531
563
|
**Multi-repository workspaces**: memory lives in the main repository only.
|
|
532
564
|
`pi-add-dir` injects each added root's `AGENTS.md` verbatim into every request, so a
|
|
@@ -570,6 +602,29 @@ Ctrl+Z suspend/resume both re-enter the TUI, and a live session must never be ki
|
|
|
570
602
|
trigger is deliberately limited to TUI mode: RPC/JSON/print stdout is machine-readable and is
|
|
571
603
|
never given terminal escape sequences.
|
|
572
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
|
+
|
|
573
628
|
### Commands
|
|
574
629
|
|
|
575
630
|
| Command | Effect |
|
|
@@ -604,7 +659,8 @@ arguments are redacted with the same rules as the approval log, so `pi --api-key
|
|
|
604
659
|
leave the key on disk.
|
|
605
660
|
|
|
606
661
|
`PI_QUIT_GUARD_DEBUG=<file>` appends one line per `arm` / `disarm` / `fire` (plus one per
|
|
607
|
-
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.
|
|
608
664
|
|
|
609
665
|
### Boundaries
|
|
610
666
|
|
|
@@ -614,8 +670,11 @@ extension registration); once the TUI is gone it is the only channel left.
|
|
|
614
670
|
(not observed; `drainInput` is bounded at 1 s) is out of scope.
|
|
615
671
|
- When it fires, the remaining extension cleanup is skipped **by design** — that cleanup is what
|
|
616
672
|
was hanging. Session entries are appended to the session JSONL as they happen, so the
|
|
617
|
-
transcript is intact up to the last written entry. The process exits 0; if
|
|
618
|
-
itself
|
|
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.
|
|
619
678
|
- This is a workaround for a host gap. If pi ever bounds `session_shutdown`, the guard becomes
|
|
620
679
|
a no-op safety net and can be removed.
|
|
621
680
|
|
|
@@ -683,14 +742,21 @@ src/
|
|
|
683
742
|
│ # tests
|
|
684
743
|
├── favorites/ # model favorites: selector + cycle patches,
|
|
685
744
|
│ # persisted store, tests
|
|
745
|
+
├── init/ # agent memory framework: detect/plan/apply/audit,
|
|
746
|
+
│ # template parity + refresh, workflow markers,
|
|
747
|
+
│ # templates, tests
|
|
686
748
|
├── permission/ # session-scoped boundary permission: modes, panel,
|
|
687
749
|
│ # bash units, policy, session grants, prompt,
|
|
688
750
|
│ # audit payload, tests
|
|
751
|
+
├── plan/ # browser-reviewed planning: phases, block diff,
|
|
752
|
+
│ # review server, UI, tests
|
|
689
753
|
├── quit-guard/ # quit watchdog: TUI teardown + quit-event triggers,
|
|
690
754
|
│ # settings store, hang report, tests
|
|
691
|
-
├── review/ # third-party review:
|
|
755
|
+
├── review/ # third-party review: command trigger,
|
|
692
756
|
│ # review model config store, prompt, tests
|
|
693
757
|
├── stash/ # prompt stash: hotkey state machine + tests
|
|
758
|
+
├── uat/ # acceptance ledger: records/ledger, page server,
|
|
759
|
+
│ # record_change + uat_item, UI, tests
|
|
694
760
|
└── whats-new/ # release notes after an upgrade: CHANGELOG parser,
|
|
695
761
|
# last-seen store, startup notice, tests
|
|
696
762
|
```
|
package/README.zh-CN.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
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.
|
|
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
|
|
|
@@ -77,10 +77,10 @@ pi -e ./src/index.ts
|
|
|
77
77
|
| 📥 **stash** 提示词暂存 | `ctrl+alt+y` | 一段提示词的暂存槽,按键交换 / 连按两次暂存并清空输入框 |
|
|
78
78
|
| 🔎 **review** 第三方代码评审 | `/ask-review` | 召唤配置的评审模型,对刚完成的任务做查+修,重点检查「本轮需求实现 / 是否有遗漏 / 是否有错误」 |
|
|
79
79
|
| 🧭 **plan** 浏览器内计划评审 | `/ask-plan` | 先调研、写 plan、在浏览器里逐段评审并逐块批注,批准之后才动代码 |
|
|
80
|
-
| ✅ **uat** 验收台账 | `/ask-uat` |
|
|
80
|
+
| ✅ **uat** 验收台账 | `/ask-uat` | `/ask-init` 之后:把待归类的实施记录聚成用户视角的验收项,在页面里勾选(只追加、无提交),看清哪些已交付但还没验过 |
|
|
81
81
|
| 🗜️ **compact** 独立压缩模型 | `/compact-model` | 给 `/compact` 与 auto-compact 配一个便宜快模型做总结,主模型专注对话;未配置零开销、任何异常回落 pi 默认 |
|
|
82
82
|
| 🚀 **autostart** 会话启动自动化 | `.pi/autostart.toml` | 项目内声明启动时自动执行的斜杠命令(首批用例:`/add-dir` 多仓库挂载);未信任不执行、未注册命令跳过不发给模型 |
|
|
83
|
-
| 🧠 **init** agent 记忆框架 | `/ask-init` | 安装或接管一套固定的记忆结构(`AGENTS.md` + `specs/` + `.agents/memory` + `.agents/implementations`)
|
|
83
|
+
| 🧠 **init** agent 记忆框架 | `/ask-init` | 安装或接管一套固定的记忆结构(`AGENTS.md` + `specs/` + `.agents/memory` + `.agents/implementations`),带快照与覆盖表迁移旧文档,之后可随时审计/刷新漂移、预算与重复事实 |
|
|
84
84
|
| 🧯 **quit-guard** 退出看门狗 | `/quit-guard` | 交互式退出卡死时,无论发生在 TUI 收尾之后、还是信号触发路径的收尾之前,超时后写诊断报告并强制退出,把命令行提示符还给你;TUI 重启与 Ctrl+Z 恢复都会解除看守 |
|
|
85
85
|
| 🆕 **whats-new** 升级后的版本变更提示 | 自动 | 升级后的首次 `pi` 启动展示「从你上次运行的版本到现在改了什么」,只展示一次;不注册斜杠命令,不占用宿主的全局命令命名空间 |
|
|
86
86
|
|
|
@@ -92,6 +92,8 @@ pi -e ./src/index.ts
|
|
|
92
92
|
|
|
93
93
|
用 `/ask` 进入(再按一次退出)。适合只想要「问问题、读代码」的场景:模型不能改项目,但不会被剥夺思考的落点。
|
|
94
94
|
|
|
95
|
+
ask 是独立的(不需要 `/ask-init`)。计划评审或 UAT 页面开着时先退出它们——ask 不会叠在另一个相位上启动,因为那个相位的 `before_agent_start` 会把写工具重新加回来。
|
|
96
|
+
|
|
95
97
|
**进入后**:
|
|
96
98
|
|
|
97
99
|
- **项目文件写入仍然机制上不可能** —— `write` / `edit` / `powershell` 从活跃工具集中移除,pi 对未激活工具的调用直接拒绝("Tool not found");闸门还会二次拦截,防止有东西把它们重新打开
|
|
@@ -279,6 +281,7 @@ run = ["/ask-perm allow allow allow ask"]
|
|
|
279
281
|
|
|
280
282
|
- **未配置 / 配置的模型已不可用**(如在 pi 的 models.json 里删掉了该模型)→ 提示后照常弹出列表(此时无默认项)
|
|
281
283
|
- 任务仍在进行中(agent 未空闲)时触发 → 提示等待,不执行;同一时间只允许一个评审
|
|
284
|
+
- 计划期 → 拒绝(评审中的计划不能被改);ask 模式会自动退出,因为查+修需要完整工具集
|
|
282
285
|
- footer 出现灰色 `review` 状态 = 已配置评审模型
|
|
283
286
|
|
|
284
287
|
---
|
|
@@ -304,7 +307,9 @@ run = ["/ask-perm allow allow allow ask"]
|
|
|
304
307
|
/ask-plan off # 退出计划期(草稿留在原处)
|
|
305
308
|
```
|
|
306
309
|
|
|
307
|
-
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`——两个相位不会叠着跑。
|
|
308
313
|
|
|
309
314
|
---
|
|
310
315
|
|
|
@@ -320,6 +325,10 @@ spec 落在 `specs/<slug>.md`,与 `/ask-init` 的计划同一个位置。
|
|
|
320
325
|
附一句「用户视角能做什么」;UAT 侧把多条记录聚成少数验收项——一条行为可能要十条记录,
|
|
321
326
|
一条记录也可能碰到多个行为。
|
|
322
327
|
|
|
328
|
+
**需要框架。** 项目缺少框架状态、`AGENTS.md`、记忆合同或 `.agents/implementations/` 时,
|
|
329
|
+
`/ask-uat` 直接拒绝;先跑 `/ask-init`。此时 `record_change` 也不可用。判定按特征而非字节:
|
|
330
|
+
你对这些文件的小改不会挡住页面。
|
|
331
|
+
|
|
323
332
|
```text
|
|
324
333
|
record_change(实施)→ /ask-uat(聚类)→ 浏览器(勾选)→ 台账
|
|
325
334
|
```
|
|
@@ -370,7 +379,7 @@ pi 的 `/compact` 与 auto-compact 默认**用当前会话模型**做上下文
|
|
|
370
379
|
| auto-compact 阈值触发 | 压缩模型总结 |
|
|
371
380
|
| context overflow 恢复 | 压缩模型总结,重试行为不变 |
|
|
372
381
|
|
|
373
|
-
**接管后与 pi 内建行为完全一致的部分**(逐字同步 pi 内建实现,复制自 0.87.1、在 1.2.0 → 1.5.
|
|
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 回填进摘要请求):
|
|
374
383
|
|
|
375
384
|
- **摘要格式** —— Goal / Progress / Key Decisions 结构化 checkpoint;已有摘要时用迭代更新版 prompt,信息延续不丢
|
|
376
385
|
- **切分行为** —— 保留最近 `keepRecentTokens` 的策略、`firstKeptEntryId` / `tokensBefore` 原样回传,不动
|
|
@@ -451,7 +460,7 @@ run = [
|
|
|
451
460
|
|
|
452
461
|
**关键约束:只支持扩展命令**。`/add-dir`(pi-add-dir)、`/cd`(pi-cd)等 `registerCommand` 注册的命令可以;内置命令(`/compact`、`/reload`、`/resume`…)在 TUI 层分发,扩展层触发不了;skill 命令(`/skill:name`)是展开机制而非执行机制。依赖的目标扩展(如 pi-add-dir)需要先安装。
|
|
453
462
|
|
|
454
|
-
> **实现说明**:执行用 `sendUserMessage(cmd, { expandPromptTemplates: true })` —— 该选项把 `/cmd args` 路由到命令分发而不是模型 prompt 路径(包装层默认 `false`;`_tryExecuteExtensionCommand` 在 1.2.0–1.5.
|
|
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)。
|
|
455
464
|
|
|
456
465
|
---
|
|
457
466
|
|
|
@@ -475,13 +484,28 @@ run = [
|
|
|
475
484
|
|
|
476
485
|
| 命令 | 作用 |
|
|
477
486
|
| --- | --- |
|
|
478
|
-
| `/ask-init` |
|
|
479
|
-
| `/ask-init plan [--deep]` |
|
|
480
|
-
| `/ask-init check` |
|
|
487
|
+
| `/ask-init` | 首次:检测 → 出计划 → 确认 → 移动/脚手架/快照 → 派发;已安装:先刷新框架文字,再审计(不派模型) |
|
|
488
|
+
| `/ask-init plan [--deep]` | 只打印计划,不写任何盘(`--dry-run` 同义),含框架对等检查段 |
|
|
489
|
+
| `/ask-init check` | 审计已装的框架,含框架文字与模板的对等检查(只读;只在 `.agents/framework/reports/` 留下运行期报告) |
|
|
481
490
|
| `/ask-init roots` | 把 `pi-add-dir` 添加的目录同步进框架状态 |
|
|
482
|
-
| `/ask-init refresh` |
|
|
491
|
+
| `/ask-init refresh [--adopt]` | 单独执行刷新(`/ask-init` 也会跑):框架拥有文件 + `AGENTS.md` 里的工作流块;手工改过的文件一概不动。`--adopt` 在你核对过之后,把没有锚的旧文件认作框架拥有并接管 |
|
|
483
492
|
| `/ask-init --yes` | 跳过确认面板 |
|
|
484
|
-
| `/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 就会正常更新它。
|
|
485
509
|
|
|
486
510
|
**机械那一半保证什么**:
|
|
487
511
|
|
|
@@ -504,11 +528,15 @@ run = [
|
|
|
504
528
|
装框架、修机械漂移(墓碑、重复章节、附录顺序),超预算的 `AGENTS.md` 只登记成债务;
|
|
505
529
|
`--deep` 才允许结构性改写。
|
|
506
530
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
`
|
|
510
|
-
`
|
|
511
|
-
`W-SCAFFOLD-01` 未填的 `TODO(ask-init)`
|
|
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` 尚未安装框架。
|
|
512
540
|
|
|
513
541
|
**多仓库工作区**:记忆只住主仓。`pi-add-dir` 会把每个 added root 的 `AGENTS.md`
|
|
514
542
|
全文注入每次请求,所以根里的入口只能是 **scope card**(≤30 行:这里放什么、它的命令、
|
|
@@ -610,14 +638,21 @@ src/
|
|
|
610
638
|
│ # /compact-model、配置存储、prompt、测试
|
|
611
639
|
├── favorites/ # 模型收藏:选择器与循环 patch、
|
|
612
640
|
│ # 持久化存储、测试
|
|
641
|
+
├── init/ # agent 记忆框架:检测/计划/应用/审计、
|
|
642
|
+
│ # 模板对等检查 + refresh、工作流 marker、
|
|
643
|
+
│ # 模板、测试
|
|
613
644
|
├── permission/ # 会话级边界权限:模式、面板、bash 拆解、
|
|
614
645
|
│ # 策略、会话授权、确认对话框、
|
|
615
646
|
│ # 审计 payload、测试
|
|
647
|
+
├── plan/ # 浏览器内计划评审:相位、块级 diff、
|
|
648
|
+
│ # 评审服务器、UI、测试
|
|
616
649
|
├── quit-guard/ # 退出看门狗:TUI 收尾 + quit 事件双触发、
|
|
617
650
|
│ # 配置存储、诊断报告、测试
|
|
618
|
-
├── review/ #
|
|
651
|
+
├── review/ # 第三方评审:指令触发、
|
|
619
652
|
│ # 评审模型配置存储、提示词、测试
|
|
620
653
|
├── stash/ # 提示词暂存:热键状态机 + 测试
|
|
654
|
+
├── uat/ # 验收台账:记录/台账、页面服务器、
|
|
655
|
+
│ # record_change + uat_item、UI、测试
|
|
621
656
|
└── whats-new/ # 升级后的版本变更提示:CHANGELOG 解析、
|
|
622
657
|
# 已见版本存储、启动提示、测试
|
|
623
658
|
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andares/pi-toolkits",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Integrated toolkit extension for pi — ask mode (read-only Q&A), browser-reviewed planning, an acceptance ledger with a browser page, session-scoped permission checks, model favorites, prompt stash, third-party code review, session autostart, a dedicated compaction model, an agent memory framework (/ask-init), and release notes on the first start after an upgrade",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Integrated toolkit extension for pi — ask mode (read-only Q&A), browser-reviewed planning, an acceptance ledger with a browser page, session-scoped permission checks, model favorites, prompt stash, third-party code review, session autostart, a dedicated compaction model, an agent memory framework (/ask-init), a quit watchdog, and release notes on the first start after an upgrade",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -36,10 +36,16 @@
|
|
|
36
36
|
"memory-framework",
|
|
37
37
|
"scaffold",
|
|
38
38
|
"init",
|
|
39
|
+
"ask-init",
|
|
40
|
+
"plan",
|
|
41
|
+
"ask-plan",
|
|
39
42
|
"uat",
|
|
43
|
+
"ask-uat",
|
|
40
44
|
"acceptance",
|
|
41
45
|
"acceptance-testing",
|
|
42
46
|
"change-record",
|
|
47
|
+
"quit-guard",
|
|
48
|
+
"watchdog",
|
|
43
49
|
"whats-new",
|
|
44
50
|
"release-notes",
|
|
45
51
|
"changelog"
|
|
@@ -95,6 +95,9 @@ function makeHarness(options: { scratchBaseDir?: string } = {}) {
|
|
|
95
95
|
notes,
|
|
96
96
|
activeTools: () => activeTools,
|
|
97
97
|
registeredTool: () => registeredTool,
|
|
98
|
+
setActiveTools: (names: string[]) => {
|
|
99
|
+
activeTools = [...names];
|
|
100
|
+
},
|
|
98
101
|
setSessionId: (id: string) => {
|
|
99
102
|
sessionId = id;
|
|
100
103
|
},
|
|
@@ -120,6 +123,18 @@ beforeEach(() => {
|
|
|
120
123
|
});
|
|
121
124
|
|
|
122
125
|
describe("ask gate", () => {
|
|
126
|
+
it("refuses to enter while a plan or UAT phase is active", async () => {
|
|
127
|
+
const h = makeHarness({ scratchBaseDir: tempBase() });
|
|
128
|
+
h.setActiveTools(["read", "write", "edit", "bash", "plan_submit"]);
|
|
129
|
+
await h.toggle();
|
|
130
|
+
expect(h.notes.some((note) => /ask-plan/.test(note.message))).toBe(true);
|
|
131
|
+
expect(h.activeTools()).not.toContain(ASK_SCRATCH_TOOL);
|
|
132
|
+
|
|
133
|
+
h.setActiveTools(["read", "write", "edit", "bash", "uat_item"]);
|
|
134
|
+
await h.toggle();
|
|
135
|
+
expect(h.notes.some((note) => /ask-uat/.test(note.message))).toBe(true);
|
|
136
|
+
expect(h.activeTools()).not.toContain(ASK_SCRATCH_TOOL);
|
|
137
|
+
});
|
|
123
138
|
it("has no opinion while ask mode is off", async () => {
|
|
124
139
|
const h = makeHarness({ scratchBaseDir: tempBase() });
|
|
125
140
|
expect(await h.evaluate("write", { path: "x" })).toBeUndefined();
|
|
@@ -33,6 +33,7 @@ import type {
|
|
|
33
33
|
} from "@earendil-works/pi-coding-agent";
|
|
34
34
|
import type { GateHub } from "../../lib/gates.js";
|
|
35
35
|
import { setAskControl } from "../../lib/ask-control.js";
|
|
36
|
+
import { activePhases, describePhases } from "../../lib/phases.js";
|
|
36
37
|
// The jailed-tool registry lives here too: ask marks `scratchpad` while the mode
|
|
37
38
|
// is active so the boundary gate (`permission`) knows it has no path to judge.
|
|
38
39
|
import {
|
|
@@ -192,6 +193,22 @@ export function registerAsk(
|
|
|
192
193
|
pi.registerCommand("ask", {
|
|
193
194
|
description: "Toggle ask mode (consult mode: no project writes, scratch notes allowed)",
|
|
194
195
|
handler: async (_args, ctx) => {
|
|
196
|
+
if (!enabled) {
|
|
197
|
+
if (ctx.isIdle?.() === false) {
|
|
198
|
+
ctx.ui.notify("Ask mode: the agent is still running — wait for it to finish.", "warning");
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
// A phase already owns a write surface; entering a read-only mode on top
|
|
202
|
+
// would be a promise the other phase's before_agent_start can break.
|
|
203
|
+
const phases = activePhases(pi).filter((phase) => phase !== "ask");
|
|
204
|
+
if (phases.length > 0) {
|
|
205
|
+
ctx.ui.notify(
|
|
206
|
+
`Ask mode cannot start while ${describePhases(phases)} is active — leave it first.`,
|
|
207
|
+
"warning",
|
|
208
|
+
);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
195
212
|
toggle(ctx);
|
|
196
213
|
},
|
|
197
214
|
});
|
|
@@ -4,6 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
import { audit, countFindings, latestCoverageReport, renderFindings } from "./audit.js";
|
|
5
5
|
import { detect } from "./detect.js";
|
|
6
6
|
import { AUDIT_CODES, REPORTS_DIR } from "./spec.js";
|
|
7
|
+
import { workflowBlockText } from "./parity.js";
|
|
7
8
|
import { gitProject, installedProject, project, remove } from "./test-helpers.js";
|
|
8
9
|
|
|
9
10
|
function codes(root: string): string[] {
|
|
@@ -26,8 +27,11 @@ const CLEAN: Record<string, string> = {
|
|
|
26
27
|
"| `.agents/memory/FUTURE.md` | deferred |",
|
|
27
28
|
"| `.agents/memory/ARCHITECTURE.md` | decisions |",
|
|
28
29
|
"",
|
|
30
|
+
workflowBlockText(),
|
|
29
31
|
].join("\n"),
|
|
30
32
|
"specs/PLAN.md": "# Plan\n\n## Route\n\n- next\n",
|
|
33
|
+
".agents/README.md": "# `.agents/` — agent-facing material\n",
|
|
34
|
+
".agents/framework/.gitignore": "reports/\n",
|
|
31
35
|
".agents/memory/README.md": "# Agent memory framework v1\n",
|
|
32
36
|
".agents/memory/FINISHED.md":
|
|
33
37
|
"# Finished\n\n## Summary\n\n- init — `.agents/implementations/2026-01-01_init.md`\n",
|
|
@@ -58,8 +62,21 @@ describe("audit", () => {
|
|
|
58
62
|
}
|
|
59
63
|
});
|
|
60
64
|
|
|
61
|
-
it("reports bare legacy references", () => {
|
|
65
|
+
it("reports bare legacy references as a warning when there is nothing to move", () => {
|
|
62
66
|
const root = project({ ...CLEAN, "src/a.ts": "// see memory/DESIGN.md\n" });
|
|
67
|
+
try {
|
|
68
|
+
expect(codes(root)).toContain(AUDIT_CODES.pathBareRefStale);
|
|
69
|
+
} finally {
|
|
70
|
+
remove(root);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("keeps bare references an error while a legacy directory still exists", () => {
|
|
75
|
+
const root = project({
|
|
76
|
+
...CLEAN,
|
|
77
|
+
"memory/PLAN.md": "# old plan\n",
|
|
78
|
+
"src/a.ts": "// see memory/DESIGN.md\n",
|
|
79
|
+
});
|
|
63
80
|
try {
|
|
64
81
|
expect(codes(root)).toContain(AUDIT_CODES.pathBareRef);
|
|
65
82
|
} finally {
|
|
@@ -225,7 +242,7 @@ describe("audit", () => {
|
|
|
225
242
|
expect(findings.map((item) => item.code)).toContain(AUDIT_CODES.scaffoldLeftover);
|
|
226
243
|
const text = renderFindings(findings, { root, frameworkVersion: 1 });
|
|
227
244
|
expect(text).toMatch(/errors/);
|
|
228
|
-
expect(text).toContain(AUDIT_CODES.
|
|
245
|
+
expect(text).toContain(AUDIT_CODES.pathBareRefStale);
|
|
229
246
|
} finally {
|
|
230
247
|
remove(root);
|
|
231
248
|
}
|