@andares/pi-toolkits 1.2.1 → 1.2.2
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 +8 -0
- package/README.md +2 -113
- package/README.zh-CN.md +2 -48
- package/package.json +2 -4
- package/src/index.ts +0 -3
- package/src/lib/approval-log.ts +3 -3
- package/src/features/quit-guard/constants.ts +0 -98
- package/src/features/quit-guard/guard.ts +0 -235
- package/src/features/quit-guard/index.ts +0 -368
- package/src/features/quit-guard/killer.test.ts +0 -77
- package/src/features/quit-guard/killer.ts +0 -215
- package/src/features/quit-guard/quit-guard.test.ts +0 -853
- package/src/features/quit-guard/report.ts +0 -212
- package/src/features/quit-guard/store.ts +0 -144
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,13 @@ 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.2.2 — 2026-11-26
|
|
15
|
+
|
|
16
|
+
<!-- Notes for the next release go here; `pnpm release` renames this heading. -->
|
|
17
|
+
|
|
18
|
+
- **release** — `pnpm release` now treats a green `publish` workflow run as the release's success criterion and stops there: no more polling npm for the version and its attestation, just a summary with the tag, the run URL, the Release URL and a package-page link. Every child process it spawns has a deadline (ssh included), so the wait can no longer sit silently on a dead connection.
|
|
19
|
+
- **quit-guard** — removed: `/quit-guard`, its settings file and the hang reports are gone. Force-exiting a hung shutdown never fixed the hang and hid the real cause, so pi is left to hang instead.
|
|
20
|
+
|
|
14
21
|
## 1.2.1 — 2026-11-26
|
|
15
22
|
|
|
16
23
|
- **spec/talk** — both pages have a confirmed **Close** action that stops the review server without sending a decision or a reply, including a closed-state fallback when the server is already gone.
|
|
@@ -99,3 +106,4 @@ renames that heading to the version being published and refuses an empty section
|
|
|
99
106
|
|
|
100
107
|
|
|
101
108
|
|
|
109
|
+
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
[](https://github.com/earendil-works/pi)
|
|
14
14
|
[](https://github.com/andares/pi-toolkits)
|
|
15
15
|
|
|
16
|
-
In a nutshell:
|
|
16
|
+
In a nutshell: thirteen 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 **spec review in the browser** `ask-spec`, **reply notes in the browser** `ask-talk`, an **acceptance ledger with a browser page** `ask-uat`, a **session backlog for parallel work** `keep`, and **release notes on the first start after an upgrade** `whats-new` — with more to come.
|
|
17
17
|
|
|
18
18
|
**Requirements**: pi `>=0.99.0`. Every published pi release from 0.99.0 through 1.6.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.
|
|
19
19
|
|
|
@@ -57,7 +57,6 @@ After installing, verify in any pi session:
|
|
|
57
57
|
- [🗜️ compact — dedicated compaction model](#compact)
|
|
58
58
|
- [🚀 autostart — session startup automation](#autostart)
|
|
59
59
|
- [🧠 init — agent memory framework](#init)
|
|
60
|
-
- [🧯 quit-guard — quit watchdog](#quit-guard)
|
|
61
60
|
- [🧷 keep — session backlog](#keep)
|
|
62
61
|
- [🆕 whats-new — release notes after an upgrade](#whats-new)
|
|
63
62
|
- [Development](#development)
|
|
@@ -83,7 +82,6 @@ After installing, verify in any pi session:
|
|
|
83
82
|
| 🗜️ **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 |
|
|
84
83
|
| 🚀 **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 |
|
|
85
84
|
| 🧠 **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 |
|
|
86
|
-
| 🧯 **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 |
|
|
87
85
|
| 🧷 **keep** session backlog | `/keep-quit` · `/keep-load` · `/keep-drop` | mark a session unfinished as you quit, reopen the backlog next time (loaded rows dimmed but still selectable), drop what you finished; an append-only ledger, no lock and no host session listing |
|
|
88
86
|
| 🆕 **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 |
|
|
89
87
|
|
|
@@ -604,113 +602,6 @@ package never directs the model which language to write or reply in.
|
|
|
604
602
|
> framework version lives in `.agents/framework/state.toml`; a project whose state
|
|
605
603
|
> version is newer than the installed tool is never migrated.
|
|
606
604
|
|
|
607
|
-
## 🧯 quit-guard — quit watchdog
|
|
608
|
-
|
|
609
|
-
<a name="quit-guard"></a>
|
|
610
|
-
|
|
611
|
-
**The problem.** pi's interactive `/quit` stops the TUI and then awaits every extension's
|
|
612
|
-
`session_shutdown` handler, one after another, **with no timeout**
|
|
613
|
-
(`runtimeHost.dispose()` → `emitSessionShutdownEvent()`; upstream
|
|
614
|
-
[issue #9997](https://github.com/earendil-works/pi/issues/9997), still unbounded in 1.5.1 and on
|
|
615
|
-
`main` — 1.5.1 added `await session.abort()` before the handler loop and a credential-write
|
|
616
|
-
settle after it, i.e. more awaits in the same untimed chain). One handler that never settles leaves pi alive at 0% CPU *after* the terminal has
|
|
617
|
-
already been restored and the final frame reprinted: the screen looks like a frozen "exit
|
|
618
|
-
screen", and the shell prompt never comes back. Ctrl+C and SIGTERM did not end the hung process
|
|
619
|
-
in our measurements (SIGKILL did); once that phase starts, the host has no way out of it.
|
|
620
|
-
Measured with a 20-extension setup (2026-11-05): a healthy quit spends 0.1–3 s in that phase,
|
|
621
|
-
`pi -ne` 0.12 s — and one of three quits with the same setup never finished at all.
|
|
622
|
-
|
|
623
|
-
**What this does.** The guard watches the terminal instead of the event stream, so it still
|
|
624
|
-
works when the handler that hangs was loaded *before* this package (in that case our own
|
|
625
|
-
`session_shutdown` would never run). It arms on the TUI's teardown sequence
|
|
626
|
-
(`\x1b[?2004l` / `\x1b[?1049l`) — and, for the signal-triggered path (`kill -TERM`, a closed
|
|
627
|
-
window), on `session_shutdown` with reason `quit`, because that path runs every extension
|
|
628
|
-
handler *before* the TUI writes its teardown sequence: a stuck handler there would never produce
|
|
629
|
-
a marker. If the process is still alive `timeoutMs` later, it writes a hang report, restores the
|
|
630
|
-
terminal if the TUI never did (alternate screen, bracketed paste, cursor) and forces the exit.
|
|
631
|
-
A TUI that comes back disarms it — an interactive mode switch (`/settings` → TUI mode) and
|
|
632
|
-
Ctrl+Z suspend/resume both re-enter the TUI, and a live session must never be killed. The event
|
|
633
|
-
trigger is deliberately limited to TUI mode: RPC/JSON/print stdout is machine-readable and is
|
|
634
|
-
never given terminal escape sequences.
|
|
635
|
-
|
|
636
|
-
**Two hangs, two layers.** The fire path above lives on the main event loop — which is exactly
|
|
637
|
-
what can also die: on 2026-11-13 the guard fired, wrote its report, printed "forcing exit" and
|
|
638
|
-
called `process.exit(0)` … and the process hung for 18 minutes in `futex_wait` with the pty
|
|
639
|
-
already deleted (the user had closed the terminal window to escape). Host code on the exit path
|
|
640
|
-
(`process.on("exit")` listeners, bundled graceful-fs patches, stdio flush) can deadlock
|
|
641
|
-
synchronously, and a `setTimeout` fallback cannot fire inside a dead loop. Therefore:
|
|
642
|
-
|
|
643
|
-
- **arm-time watchdog thread** — arming also starts a `worker_threads` worker that does not
|
|
644
|
-
live on the main loop. The main loop beats a 1 Hz heartbeat into shared memory; after the
|
|
645
|
-
deadline (plus a head start for the main-loop fire timer, which handles the common hangs with
|
|
646
|
-
full context: raw-mode probe, full report, terminal restore) the worker samples the heartbeat
|
|
647
|
-
twice. Still beating → the event loop is alive → it steps aside (the fire timer owns the
|
|
648
|
-
outcome, including its stray-marker protection). Stopped → the main loop can never fire → the
|
|
649
|
-
worker restores the terminal, writes a minimal `-thread.json` report and SIGKILLs. This also
|
|
650
|
-
covers the blind spot where the main thread deadlocks *before* the fire deadline — e.g.
|
|
651
|
-
synchronously inside `process.exit` right after a fast dispose — because the worker never
|
|
652
|
-
needed the main loop in the first place. Every disarm (TUI restart, Ctrl+Z resume, `/reload`)
|
|
653
|
-
cancels the worker, so a returning TUI is never killed.
|
|
654
|
-
- **fire-time hard kill** — after the report is on disk and "forcing exit" printed, fire()
|
|
655
|
-
starts a second worker that unconditionally SIGKILLs 500 ms later; `process.exit(0)` and a
|
|
656
|
-
same-loop `setTimeout` SIGKILL run before it, so the worker only matters when the main thread
|
|
657
|
-
is blocked inside the exit path (the exact 2026-11-13 shape).
|
|
658
|
-
|
|
659
|
-
### Commands
|
|
660
|
-
|
|
661
|
-
| Command | Effect |
|
|
662
|
-
| --- | --- |
|
|
663
|
-
| `/quit-guard` | status: on/off, timeout, report on/off, newest hang report |
|
|
664
|
-
| `/quit-guard on` / `/quit-guard off` | enable/disable, persisted |
|
|
665
|
-
| `/quit-guard <ms>` | set the deadline (clamped to 2000–60000 ms), persisted |
|
|
666
|
-
|
|
667
|
-
**Configuration** — the guard is **on by default** (8 s after the teardown write, hang report
|
|
668
|
-
on), so an install is protected without any setup. It persists to
|
|
669
|
-
`<agent-dir>/pi-toolkits-quit-guard.json`, written by the commands; every field is optional:
|
|
670
|
-
|
|
671
|
-
```json
|
|
672
|
-
{
|
|
673
|
-
"enabled": true,
|
|
674
|
-
"timeoutMs": 8000,
|
|
675
|
-
"report": true
|
|
676
|
-
}
|
|
677
|
-
```
|
|
678
|
-
|
|
679
|
-
`timeoutMs` counts **from the teardown write**, not from the moment you press Enter, so the time
|
|
680
|
-
the TUI spends stopping is not charged against a slow-but-finishing shutdown. Keep it above your
|
|
681
|
-
slowest healthy quit: the default is **8 s**, and the slowest healthy quit measured above was 5 s
|
|
682
|
-
end to end (of which ~2 s came after the teardown), leaving ~3 s of margin.
|
|
683
|
-
|
|
684
|
-
**Hang reports** — `<agent-dir>/quit-guard/quit-hang-<timestamp>-<pid>.json` records the
|
|
685
|
-
arm/fire timing, the teardown marker, and the process state at the deadline (`activeHandles`,
|
|
686
|
-
`activeRequests`, and the host's libuv handle table). An empty `libuv` table next to a live
|
|
687
|
-
process is the signature of a promise nobody will ever resolve, as opposed to a blocked socket
|
|
688
|
-
or a lingering child process. The file is owner-only (0600 in an 0700 directory) and process
|
|
689
|
-
arguments are redacted with the same rules as the approval log, so `pi --api-key …` does not
|
|
690
|
-
leave the key on disk.
|
|
691
|
-
|
|
692
|
-
`PI_QUIT_GUARD_DEBUG=<file>` appends one line per `arm` / `disarm` / `fire` (plus one per
|
|
693
|
-
extension registration); once the TUI is gone it is the only channel left. A thread-watchdog
|
|
694
|
-
kill appends `thread-kill heartbeat-stopped …` there.
|
|
695
|
-
|
|
696
|
-
### Boundaries
|
|
697
|
-
|
|
698
|
-
- Interactive TUI only. Print (`-p`), JSON, and RPC sessions never write the teardown
|
|
699
|
-
sequences, so the guard stays inert there.
|
|
700
|
-
- The deadline covers the **post-teardown** phase. A shutdown that hangs before the TUI stops
|
|
701
|
-
(not observed; `drainInput` is bounded at 1 s) is out of scope.
|
|
702
|
-
- When it fires, the remaining extension cleanup is skipped **by design** — that cleanup is what
|
|
703
|
-
was hanging. Session entries are appended to the session JSONL as they happen, so the
|
|
704
|
-
transcript is intact up to the last written entry. The process exits 0; if the exit path
|
|
705
|
-
itself deadlocks (observed for real: host `exit` listeners, stdio flush), the layered
|
|
706
|
-
fallbacks — same-loop `setTimeout` SIGKILL, then the watchdog/hard-kill worker threads — end
|
|
707
|
-
the process anyway. A worker cannot be constructed only under resource exhaustion; the guard
|
|
708
|
-
then degrades to the behavior it had before the thread layers existed.
|
|
709
|
-
- This is a workaround for a host gap. If pi ever bounds `session_shutdown`, the guard becomes
|
|
710
|
-
a no-op safety net and can be removed.
|
|
711
|
-
|
|
712
|
-
---
|
|
713
|
-
|
|
714
605
|
## 🧷 keep — session backlog for parallel work
|
|
715
606
|
|
|
716
607
|
<a name="keep"></a>
|
|
@@ -818,8 +709,6 @@ src/
|
|
|
818
709
|
│ # audit payload, tests
|
|
819
710
|
├── spec/ # browser-reviewed specs: phases, block diff,
|
|
820
711
|
│ # review server, UI, tests
|
|
821
|
-
├── quit-guard/ # quit watchdog: TUI teardown + quit-event triggers,
|
|
822
|
-
│ # settings store, hang report, tests
|
|
823
712
|
├── review/ # third-party review: command trigger,
|
|
824
713
|
│ # review model config store, prompt, tests
|
|
825
714
|
├── stash/ # prompt stash: hotkey state machine + tests
|
|
@@ -843,7 +732,7 @@ pnpm release:github # create/verify the GitHub Release for the c
|
|
|
843
732
|
pnpm release:github --audit # list npm versions vs GitHub Releases vs remote tags
|
|
844
733
|
```
|
|
845
734
|
|
|
846
|
-
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.
|
|
735
|
+
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. **A green workflow run is the release's success criterion** — the script does not poll npm afterwards; the package page is the place to check propagation and provenance.
|
|
847
736
|
|
|
848
737
|
`--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.
|
|
849
738
|
|
package/README.zh-CN.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
[](https://github.com/earendil-works/pi)
|
|
14
14
|
[](https://github.com/andares/pi-toolkits)
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
一句话介绍:目前包含十三个开箱即用的功能——**只读咨询模式** `ask`、**会话级边界权限** `ask-perm`、**模型收藏** `favorites`、**提示词暂存** `stash`、**第三方代码评审** `ask-review`、**独立压缩模型** `compact-model`、**会话启动自动化** `autostart`、**agent 记忆框架** `ask-init`、**浏览器内规格评审** `ask-spec`、**回复批注** `ask-talk`、**验收台账与浏览器页面** `ask-uat`、**并行任务的会话暂存** `keep`、**升级后首次启动的版本变更提示** `whats-new`,后续持续追加。
|
|
17
17
|
|
|
18
18
|
**版本要求**:pi `>=0.99.0`。0.99.0 到 1.6.1 的每一个已发布版本都用完整门禁实测过(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
|
|
|
@@ -57,7 +57,6 @@ pi -e ./src/index.ts
|
|
|
57
57
|
- [🗜️ compact — 独立压缩模型](#compact)
|
|
58
58
|
- [🚀 autostart — 会话启动自动化](#autostart)
|
|
59
59
|
- [🧠 init — agent 记忆框架](#init)
|
|
60
|
-
- [🧯 quit-guard — 退出看门狗](#quit-guard)
|
|
61
60
|
- [🧷 keep — 会话暂存](#keep)
|
|
62
61
|
- [🆕 whats-new — 升级后的版本变更提示](#whats-new)
|
|
63
62
|
- [开发](#development)
|
|
@@ -83,7 +82,6 @@ pi -e ./src/index.ts
|
|
|
83
82
|
| 🗜️ **compact** 独立压缩模型 | `/compact-model` | 给 `/compact` 与 auto-compact 配一个便宜快模型做总结,主模型专注对话;未配置零开销、任何异常回落 pi 默认 |
|
|
84
83
|
| 🚀 **autostart** 会话启动自动化 | `.pi/autostart.toml` | 项目内声明启动时自动执行的斜杠命令(首批用例:`/add-dir` 多仓库挂载);未信任不执行、未注册命令跳过不发给模型 |
|
|
85
84
|
| 🧠 **init** agent 记忆框架 | `/ask-init` | 安装或接管一套固定的记忆结构(`AGENTS.md` + `specs/` + `.agents/memory` + `.agents/implementations`),带快照与覆盖表迁移旧文档,之后可随时审计/刷新漂移、预算与重复事实 |
|
|
86
|
-
| 🧯 **quit-guard** 退出看门狗 | `/quit-guard` | 交互式退出卡死时,无论发生在 TUI 收尾之后、还是信号触发路径的收尾之前,超时后写诊断报告并强制退出,把命令行提示符还给你;TUI 重启与 Ctrl+Z 恢复都会解除看守 |
|
|
87
85
|
| 🧷 **keep** 会话暂存 | `/keep-quit` · `/keep-load` · `/keep-drop` | 退出时一条命令把当前会话标记为未完成,下次进来直接看这个待办列表(已载入的置灰但仍可选);做完的用 `/keep-drop` 或列表里的 `ctrl+r` 移出。只追加账本,没有锁,也不读宿主的会话列表 |
|
|
88
86
|
| 🆕 **whats-new** 升级后的版本变更提示 | 自动 | 升级后的首次 `pi` 启动展示「从你上次运行的版本到现在改了什么」,只展示一次;不注册斜杠命令,不占用宿主的全局命令命名空间 |
|
|
89
87
|
|
|
@@ -579,48 +577,6 @@ refresh 就会正常更新它。
|
|
|
579
577
|
> **跑完记得 `/reload`**,让新的 `AGENTS.md` 进入提示词。框架版本记在
|
|
580
578
|
> `.agents/framework/state.toml`;若项目的状态版本比当前工具新,则拒绝迁移。
|
|
581
579
|
|
|
582
|
-
## 🧯 quit-guard — 退出看门狗
|
|
583
|
-
|
|
584
|
-
<a name="quit-guard"></a>
|
|
585
|
-
|
|
586
|
-
**要解决的问题**。pi 的 `/quit` 先停 TUI,然后**逐个 await** 每个扩展的 `session_shutdown` 处理器,且**没有任何超时**(`runtimeHost.dispose()` → `emitSessionShutdownEvent()`;上游
|
|
587
|
-
[issue #9997](https://github.com/earendil-works/pi/issues/9997),1.5.1 与 `main` 至今未修,1.5.1 还在处理器循环前加了 `await session.abort()`、之后加了凭据写盘等待——同一条没有超时的链上又多了两个 await)。只要有一个处理器永不 settle,pi 就会在终端已还原、最后一帧已重绘之后,以 0% CPU 永远挂着:画面看起来像「停在退出界面」,提示符再也不回来;实测 Ctrl+C 与 SIGTERM 都无法结束这个进程(只有 SIGKILL 有效)——进了这段收尾,宿主自己也没有出口。20 个扩展的环境实测(2026-11-05):健康退出在这段收尾上花 0.1–3 秒,`pi -ne` 0.12 秒;同一环境三次 `/quit` 就有一次**永远不结束**。
|
|
588
|
-
|
|
589
|
-
**这个功能做什么**。看守盯的是**终端写出的收尾序列**,而不是事件流——所以即使卡死的处理器比本包**先**加载(那样我们自己的 `session_shutdown` 根本不会运行),它照样能触发。它在 TUI 收尾序列(`\x1b[?2004l` / `\x1b[?1049l`)出现时开始计时;**信号触发的退出**(`kill -TERM`、关窗 SIGHUP)另有一只触发源:`session_shutdown` 且 reason 为 `quit`——那条路是**先跑完所有扩展处理器再停 TUI**,处理器挂住时收尾序列永远写不出来,只靠序列就会漏掉。若 `timeoutMs` 之后进程还活着,它写一份诊断报告;若 TUI 从没恢复过终端,它先做恢复(退备用屏、关括号粘贴、显示光标)再强制退出。TUI **回来**时自动解除:`/settings` 里切换 TUI 显示模式、Ctrl+Z 挂起后 `fg` 恢复,都会让 TUI 重新进入,绝不能误杀活着的会话。事件触发源只限 TUI 模式:RPC/JSON/print 的 stdout 是机器可读协议,绝不会被写入终端转义序列。
|
|
590
|
-
|
|
591
|
-
### 命令
|
|
592
|
-
|
|
593
|
-
| 命令 | 作用 |
|
|
594
|
-
| --- | --- |
|
|
595
|
-
| `/quit-guard` | 查看状态:开关、超时、报告开关、最近一份诊断报告 |
|
|
596
|
-
| `/quit-guard on` / `/quit-guard off` | 开启/关闭,并持久化 |
|
|
597
|
-
| `/quit-guard <ms>` | 设置超时(钳制在 2000–60000 ms),并持久化 |
|
|
598
|
-
|
|
599
|
-
**配置** —— 看守**默认开启**(收尾序列写出后 8 秒、写诊断报告),装上就有保护,不用先配置。状态持久化在 `<agent-dir>/pi-toolkits-quit-guard.json`,由命令写入;所有字段都可省略:
|
|
600
|
-
|
|
601
|
-
```json
|
|
602
|
-
{
|
|
603
|
-
"enabled": true,
|
|
604
|
-
"timeoutMs": 8000,
|
|
605
|
-
"report": true
|
|
606
|
-
}
|
|
607
|
-
```
|
|
608
|
-
|
|
609
|
-
`timeoutMs` 从**收尾序列写出**那一刻开始算,不是从你按下 Enter 开始算——TUI 自己停下来的时间不计入,所以「慢但能完成」的收尾(记忆库 flush、MCP 关闭)不会被误杀。默认 **8 秒**;上例实测最慢的健康退出端到端 5 秒(其中约 2 秒发生在收尾之后),余量约 3 秒。
|
|
610
|
-
|
|
611
|
-
**诊断报告** —— `<agent-dir>/quit-guard/quit-hang-<时间戳>-<pid>.json`,记录开始计时/触发的时间、触发用的收尾序列,以及截止时进程的状态(`activeHandles`、`activeRequests`、宿主 libuv 句柄表)。**进程还活着但 `libuv` 表是空的**,就是「有个 Promise 永远不会 settle」的特征,区别于阻塞的 socket 或残留子进程。报告文件**仅本人可读**(0700 目录下的 0600 文件),进程参数按审批日志同一套规则脱敏,所以 `pi --api-key …` 不会把密钥留在盘上。
|
|
612
|
-
|
|
613
|
-
`PI_QUIT_GUARD_DEBUG=<文件>` 会把每次 `arm` / `disarm` / `fire`(以及每次扩展注册)追加一行;TUI 已经没了的时候,这是唯一还能观察的通道。
|
|
614
|
-
|
|
615
|
-
### 边界
|
|
616
|
-
|
|
617
|
-
- 只覆盖交互式 TUI。`-p`(print)、JSON、RPC 模式不会写这些收尾序列,看守在那里完全不生效。
|
|
618
|
-
- 计时覆盖的是**收尾之后**的阶段;在 TUI 停下之前就卡住的情况(未观察到;`drainInput` 上限 1 秒)不在范围内。
|
|
619
|
-
- 触发时**按设计跳过**剩余扩展清理——挂住的就是它。会话条目是随发生随写入 JSONL 的,所以最后一条已写入的记录不会丢。正常路径退出码 0;若 `process.exit()` 本身被 `exit` 监听器变成空操作,500 ms 后会补一记 `SIGKILL`。
|
|
620
|
-
- 这是对宿主缺口的权宜之计:哪天 pi 给 `session_shutdown` 加上限时,看守就退化成无害的保险,可以直接删掉。
|
|
621
|
-
|
|
622
|
-
---
|
|
623
|
-
|
|
624
580
|
## 🧷 keep — 并行任务的会话暂存
|
|
625
581
|
|
|
626
582
|
<a name="keep"></a>
|
|
@@ -708,8 +664,6 @@ src/
|
|
|
708
664
|
│ # 审计 payload、测试
|
|
709
665
|
├── spec/ # 浏览器内规格评审:相位、块级 diff、
|
|
710
666
|
│ # 评审服务器、UI、测试
|
|
711
|
-
├── quit-guard/ # 退出看门狗:TUI 收尾 + quit 事件双触发、
|
|
712
|
-
│ # 配置存储、诊断报告、测试
|
|
713
667
|
├── review/ # 第三方评审:指令触发、
|
|
714
668
|
│ # 评审模型配置存储、提示词、测试
|
|
715
669
|
├── stash/ # 提示词暂存:热键状态机 + 测试
|
|
@@ -733,7 +687,7 @@ pnpm release:github # 为当前版本创建/校验 GitHub Releas
|
|
|
733
687
|
pnpm release:github --audit # 列出 npm 版本 vs GitHub Release vs 远端 tag
|
|
734
688
|
```
|
|
735
689
|
|
|
736
|
-
**发版 = 推 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
|
|
690
|
+
**发版 = 推 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。**workflow run 绿了就是发版成功的判据** —— 脚本之后不再去查 npm;registry 的传播与 provenance 点开包页面自己看。
|
|
737
691
|
|
|
738
692
|
`--prepare-only` 是「都准备好、发不发最后再说」的开关:停在 commit+tag 后,打印确切的推送命令。`--no-wait` 推完就返回;`--local` 是应急路径(本机用旧 token 发布)。工作流失败后重跑同一个 tag 即可(`gh workflow run publish.yml -f tag=vX.Y.Z`):已发布的版本会跳过,所以重跑是幂等的。
|
|
739
693
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andares/pi-toolkits",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"description": "Integrated toolkit extension for pi — ask mode (read-only Q&A), browser-reviewed planning, reply notes in the browser (/ask-talk), 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 session backlog (/keep-quit, /keep-load, /keep-drop),
|
|
3
|
+
"version": "1.2.2",
|
|
4
|
+
"description": "Integrated toolkit extension for pi — ask mode (read-only Q&A), browser-reviewed planning, reply notes in the browser (/ask-talk), 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 session backlog (/keep-quit, /keep-load, /keep-drop), and release notes on the first start after an upgrade",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -47,8 +47,6 @@
|
|
|
47
47
|
"acceptance",
|
|
48
48
|
"acceptance-testing",
|
|
49
49
|
"change-record",
|
|
50
|
-
"quit-guard",
|
|
51
|
-
"watchdog",
|
|
52
50
|
"whats-new",
|
|
53
51
|
"release-notes",
|
|
54
52
|
"changelog",
|
package/src/index.ts
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
* - permission — session-scoped boundary permission checks (/ask-perm)
|
|
15
15
|
* - init — agent memory framework install / adoption (/ask-init)
|
|
16
16
|
* - uat — acceptance ledger and browser page (/ask-uat, record_change)
|
|
17
|
-
* - quit-guard — quit watchdog: force-exit when pi's shutdown hangs (/quit-guard)
|
|
18
17
|
* - keep — session backlog: keep-quit / keep-load / keep-drop
|
|
19
18
|
* - whats-new — automatic release notes on the first start after an upgrade
|
|
20
19
|
*
|
|
@@ -33,7 +32,6 @@ import { registerInit } from "./features/init/index.js";
|
|
|
33
32
|
import { registerKeep } from "./features/keep/index.js";
|
|
34
33
|
import { registerPermission } from "./features/permission/index.js";
|
|
35
34
|
import { registerSpec } from "./features/spec/index.js";
|
|
36
|
-
import { registerQuitGuard } from "./features/quit-guard/index.js";
|
|
37
35
|
import { registerReview } from "./features/review/index.js";
|
|
38
36
|
import { registerStash } from "./features/stash/index.js";
|
|
39
37
|
import { registerTalk } from "./features/talk/index.js";
|
|
@@ -58,7 +56,6 @@ export default function piToolkits(pi: ExtensionAPI): void {
|
|
|
58
56
|
registerFavorites(pi);
|
|
59
57
|
registerInit(pi);
|
|
60
58
|
registerKeep(pi);
|
|
61
|
-
registerQuitGuard(pi);
|
|
62
59
|
registerReview(pi);
|
|
63
60
|
registerStash(pi);
|
|
64
61
|
// Not a phase: no tools, no gates, no prompt banner. Registered after the
|
package/src/lib/approval-log.ts
CHANGED
|
@@ -264,9 +264,9 @@ const REDACTIONS: ReadonlyArray<readonly [RegExp, Replacer]> = [
|
|
|
264
264
|
/**
|
|
265
265
|
* Apply the credential patterns below to one string.
|
|
266
266
|
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
267
|
+
* The approval log owns the only copy of these rules; anything else that writes
|
|
268
|
+
* process arguments to disk (the retired quit-guard hang report was one) imports
|
|
269
|
+
* this instead of growing a second, drifting list.
|
|
270
270
|
*/
|
|
271
271
|
export function redactText(value: string): string {
|
|
272
272
|
let out = value;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* quit-guard feature — constants and the rationale behind them.
|
|
3
|
-
*
|
|
4
|
-
* WHY a terminal-sequence trigger instead of `session_shutdown`: pi runs
|
|
5
|
-
* extension shutdown handlers one after another without a timeout. If a
|
|
6
|
-
* handler loaded BEFORE ours never settles, our own `session_shutdown` never
|
|
7
|
-
* runs, so a watchdog armed from that event would miss exactly the hangs it
|
|
8
|
-
* is meant to catch. The teardown sequence below is written by the TUI
|
|
9
|
-
* before that phase starts, so it arms the guard regardless of extension
|
|
10
|
-
* load order (and even when the host's own writes are what hangs).
|
|
11
|
-
*
|
|
12
|
-
* Teardown markers (arm):
|
|
13
|
-
* - `\x1b[?2004l` — bracketed paste off, written by `ProcessTerminal.stop()`
|
|
14
|
-
* (both `regular` and `fullscreen` modes);
|
|
15
|
-
* - `\x1b[?1049l` — alternate-screen exit, written by the fullscreen
|
|
16
|
-
* renderer's `afterTerminalStop()`.
|
|
17
|
-
*
|
|
18
|
-
* Restart markers (disarm): a TUI that re-enters must never be killed by a
|
|
19
|
-
* timer meant for a process that is leaving:
|
|
20
|
-
* - `\x1b[?2004h` — bracketed paste on, `ProcessTerminal.start()`;
|
|
21
|
-
* - `\x1b[?1049h` — alternate-screen enter, fullscreen `beforeTerminalStart()`.
|
|
22
|
-
*
|
|
23
|
-
* These cover the two legitimate teardown-then-restart paths: an interactive
|
|
24
|
-
* TUI mode switch (`switchTuiMode()` stops the old renderer with
|
|
25
|
-
* `preserveScreen`, then starts the new one) and Ctrl+Z suspend/resume
|
|
26
|
-
* (`handleCtrlZ()` calls `ui.stop()`, then `ui.start()` on SIGCONT). The
|
|
27
|
-
* SIGCONT listener in index.ts disarms synchronously as well, so an expired
|
|
28
|
-
* timer cannot win a race against a resume.
|
|
29
|
-
*
|
|
30
|
-
* Scope: interactive TUI only. Print/JSON/RPC sessions never write these
|
|
31
|
-
* sequences, so the guard stays inert there (documented boundary).
|
|
32
|
-
*/
|
|
33
|
-
export const QUIT_GUARD_FILE = "pi-toolkits-quit-guard.json";
|
|
34
|
-
|
|
35
|
-
/** Directory holding the JSON reports written when the guard fires. */
|
|
36
|
-
export const QUIT_GUARD_REPORT_DIR = "quit-guard";
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Default watchdog deadline, measured from the terminal teardown write.
|
|
40
|
-
*
|
|
41
|
-
* Measured on a 20-extension setup (2026-11-05): a healthy `/quit` spends
|
|
42
|
-
* ~0.1–3 s between the teardown write and `process.exit(0)` (the whole
|
|
43
|
-
* `runtimeHost.dispose()` / extension-shutdown phase), 5 s worst case end to
|
|
44
|
-
* end, and 0.12 s with `pi -ne`. 8 s keeps ~3 s of margin over the slowest
|
|
45
|
-
* healthy quit observed (enough for a memory flush or an MCP server close)
|
|
46
|
-
* while returning the prompt sooner than the original 10 s when something
|
|
47
|
-
* never settles. Set by the operator (2026-11-10); it is a default, not a
|
|
48
|
-
* floor — `/quit-guard <ms>` still overrides it.
|
|
49
|
-
*/
|
|
50
|
-
export const DEFAULT_TIMEOUT_MS = 8_000;
|
|
51
|
-
|
|
52
|
-
/** Floor for `/quit-guard <ms>`: below this, a healthy slow quit would be cut. */
|
|
53
|
-
export const MIN_TIMEOUT_MS = 2_000;
|
|
54
|
-
|
|
55
|
-
/** Ceiling for `/quit-guard <ms>`: beyond this the user is better off with `kill -9`. */
|
|
56
|
-
export const MAX_TIMEOUT_MS = 60_000;
|
|
57
|
-
|
|
58
|
-
/** Sequences after which the interactive TUI has begun tearing down. */
|
|
59
|
-
export const TEARDOWN_MARKERS = ["\x1b[?2004l", "\x1b[?1049l"] as const;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Pseudo-marker for the second, event-driven trigger.
|
|
63
|
-
*
|
|
64
|
-
* `shutdown({ fromSignal: true })` runs every extension's `session_shutdown`
|
|
65
|
-
* handler BEFORE `ui.stop()` writes the teardown sequence (pi 1.5.1,
|
|
66
|
-
* interactive-mode.js). With a handler that never settles, the marker is never
|
|
67
|
-
* written and a sequence-only watchdog stays asleep: the process keeps the
|
|
68
|
-
* terminal, raw mode and the frozen frame forever. `session_shutdown` with
|
|
69
|
-
* reason `"quit"` is the only in-process signal available at that point, so it
|
|
70
|
-
* arms the guard too. Session replacements use `"new"`/`"resume"`/`"fork"`
|
|
71
|
-
* and `/reload` uses `"reload"` — those must never arm it.
|
|
72
|
-
*/
|
|
73
|
-
export const SHUTDOWN_EVENT_MARKER = "session_shutdown";
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Terminal restore written before every forced exit (writeSync(1, …), which
|
|
77
|
-
* bypasses our own stdout wrapper and cannot re-arm the guard).
|
|
78
|
-
*
|
|
79
|
-
* The shutdown-event path needs it because nothing restored the terminal:
|
|
80
|
-
* without it the prompt comes back on the alternate screen, with bracketed
|
|
81
|
-
* paste on and the cursor hidden. The marker path gets it too (since
|
|
82
|
-
* 2026-11-13): `ui.stop()` can also hang between its two sequences —
|
|
83
|
-
* `?2004l` written, `?1049l` never — and an already-restored terminal
|
|
84
|
-
* simply ignores the extra sequences. Idempotent, unlike a frozen screen.
|
|
85
|
-
*/
|
|
86
|
-
export const TERMINAL_RESTORE = "\x1b[?2004l\x1b[?1049l\x1b[?25h\x1b[0m\r\n";
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Grace period for the kill fallbacks that run AFTER the report is on disk
|
|
90
|
-
* and "forcing exit" has been printed: `process.exit(0)` first, then, in
|
|
91
|
-
* layers, a same-loop `setTimeout` SIGKILL and the independent-thread
|
|
92
|
-
* SIGKILL from killer.ts (see there for why the timer alone is not enough:
|
|
93
|
-
* the main thread can deadlock inside `process.exit`, where no timer runs).
|
|
94
|
-
*/
|
|
95
|
-
export const HARD_KILL_DELAY_MS = 500;
|
|
96
|
-
|
|
97
|
-
/** Sequences that mean a TUI is starting (mode switch or suspend/resume). */
|
|
98
|
-
export const RESTART_MARKERS = ["\x1b[?2004h", "\x1b[?1049h"] as const;
|