@andares/pi-toolkits 1.2.4 → 1.3.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 CHANGED
@@ -11,6 +11,19 @@ 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.3.0 — 2026-12-02
15
+
16
+ - **permission** — `/ask-perm` asks far less for read-only shell work: a `curl` operand is treated as a URL (it was every `${H[@]}`-style array expansion), a literal `PI=/opt/pi; grep x "$PI/docs"` is resolved, `if`/`then`/`fi` and `{ … }` are structure instead of commands named `if`, `grep -o PATTERN` and `find … -o …` are no longer "output files", and `rm -f /tmp/snap*.txt` no longer counts as deleting a temp root. A copy (`cp`/`ln`/`scp`) now reads its source and writes only its destination, and a remote `host:path` is not a local path at all.
17
+ - **permission** — an unresolved output file is now fail-closed: `curl -o "$X"` and `sort -o "$X"` ask instead of being judged as a write to the working directory.
18
+ - **ask-uat** — the acceptance page is rebuilt in the bright-green visual language of the spec page: a progress head, a two-line queue notice, item cards with expandable test plans, a side rail with the current batch and retired records, and the evidence drawer. It also stops counting the directory README and `_`-prefixed drafts as change records.
19
+ - **ask-uat** — the queue now separates records that carry a behaviour sentence from old files that have none: a normal `/ask-uat` clusters only the former, and `/ask-uat legacy` includes the rest. Records whose `record_change` hint starts with `none:` leave the queue on their own, and `uat_item` can retire records by id without inventing an item for them.
20
+ - **ask-uat** — attaching an older record to an accepted item no longer reopens it; only a record newer than the tick does. Records retired either way are listed on the page, so a smaller queue never looks like lost work.
21
+
22
+ ## 1.2.5 — 2026-11-30
23
+
24
+ - **ask-spec** — `/ask-spec` without arguments now arms the phase instead of starting it from an empty topic: the next message you send (multi-line, pasted, whole paragraphs) becomes the spec brief, and its first line names the draft file. Running the bare command again, or `/ask-spec off`, cancels before anything starts.
25
+ - **host compatibility** — the supported pi range moves to `pi >= 1.0.0`, verified 1.0.0 through 1.7.0 (window 1.4–1.7 plus the 1.3/1.2/1.1/1.0 probes, every published version, full gate). Nothing in this plugin needed a code change for 1.7.0; the keys and the mirrored compaction files are unchanged.
26
+
14
27
  ## 1.2.4 — 2026-11-28
15
28
 
16
29
  - **ask-review / ask-spec** — the retired command spellings `/third-review` and `/ask-plan` are no longer registered; use `/ask-review` and `/ask-spec`. An autostart entry still spelled the old way is skipped with a warning instead of being sent to the model as chat.
@@ -100,3 +113,5 @@ renames that heading to the version being published and refuses an empty section
100
113
  - permission — a capped rolling JSONL approval log records each ask, its parsed units and your answer; `pnpm approval-report` turns it into rule candidates.
101
114
 
102
115
 
116
+
117
+
package/README.md CHANGED
@@ -10,12 +10,12 @@
10
10
  [![Pi package gallery](https://img.shields.io/badge/pi.dev-package%20gallery-6f42c1)](https://pi.dev/packages/@andares/pi-toolkits)
11
11
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
12
12
  [![Package Manager](https://img.shields.io/badge/package%20manager-pnpm-orange?logo=pnpm)](https://pnpm.io)
13
- [![pi >= 0.99](https://img.shields.io/badge/pi-%3E%3D0.99.0-blueviolet)](https://github.com/earendil-works/pi)
13
+ [![pi >= 1.0](https://img.shields.io/badge/pi-%3E%3D1.0.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
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
- **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.
18
+ **Requirements**: pi `>=1.0.0`. Every published pi release from 1.0.0 through 1.7.0 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. There is no upper bound: 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
 
@@ -140,9 +140,11 @@ Repeating the argument form with the modes already in force is a **no-op**: no s
140
140
 
141
141
  - **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.
142
142
  - **path-bearing tools** (`read` / `write` / `edit` / `grep` / `find` / `ls`) are judged by their own path; every other tool is judged by the working directory.
143
- - **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.
144
- - **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.
145
- - **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.
143
+ - **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. Two shapes are *not* paths: a `curl` operand is a URL (`curl "$API/list"` asks nothing) and `host:path` on `scp`/`sftp`/`rsync` is a path on the other machine. A file flag is still a target, and an unresolved one is fail-closed (`curl -o "$X"`, `sort -o "$X"`).
144
+ - **literal assignments and for-loops** — `PI=/opt/pi; grep x "$PI/docs"` and `for f in a b; do grep x "$f"; done` are expanded with the literal values, because that is what bash does. An assignment is only substituted inside a plain sequential command: one behind `&&`/`||`, inside a pipeline, a subshell, a loop body, an `if`/`case` block, or a command that calls `read`/`eval`/`source`/`export`/`unset`/… keeps every `$VAR` fail-closed, as does a non-literal value (`$(…)`, globs with whitespace). Newlines separate commands (`ls⏎rm x` is two commands, not one), and a backslash-newline is a line continuation.
145
+ - **shell structure is not a command** — `if`/`then`/`fi`, `while`, `!`, `[[ ]]` and the grouping braces `{` `}` are stripped at segment edges, so a read-only `if [ -d "$d/x" ]; then echo "$d"; fi` inside a loop no longer parses as a write named `if`.
146
+ - **patterns and flags are not paths** — the first positional operand of `grep`/`rg`/`ag` is the pattern (`grep -n '</div>\s*$' file` asks nothing), `$` at the end of a quoted string is literal, and `-o` means "output file" only for the commands that define it that way: `find … -o -name x` and `grep -o PATTERN` are reads, `sort -o out.txt` and `docker compose config --output f` are writes.
147
+ - **globs and copies** — a glob resolves to its literal prefix (`/tmp/snap*.txt` → `/tmp/snap`), not to the containing directory, so an ordinary `rm -f /tmp/snap*.txt` is not "deleting a temp root" while `rm -rf /tmp/*` still is. A copy reads its sources and writes one destination (`cp`/`ln`/`install`/`rsync`/`scp`, `-t DIR` included); `mv` stays a write on both ends because it removes the source, as do `rsync --remove-source-files` and every operand of `install -d`.
146
148
  - **`git -C <dir>`** is resolved like a local `cd`: relative path arguments (and the repository) are judged against `<dir>`, not the working directory.
147
149
  - **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.
148
150
  - **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.
@@ -191,7 +193,7 @@ See the repository's `pnpm approval-report` for a read-only summary (answer mix,
191
193
  run = ["/ask-perm allow allow allow ask"]
192
194
  ```
193
195
 
194
- > **Implementation notes**: a new session resets the state on `session_start` (a repeated emission for the same session keeps it); the footer shows `perm i:A/A o:A/ask` while on (`A` allow, `a` ask, `D` deny). Subagent sessions start with their own state and do not inherit the parent's mode — when child sessions must be gated too, enable it through the project's autostart file. The approval log is appended by the gate bus (asks/blocks/session summaries) and by the permission gate (mode changes and session-grant allows); the writer is lazy, keeps no state across processes, and never participates in a decision. POSIX hosts (Linux / macOS / WSL) are the tested target; native Windows Git-Bash path spellings are approximated, not verified. bash decomposition uses `shell-quote`; unknown variables expand to a sentinel that makes the unit ask instead of silently becoming an empty path. Added directories are read from pi-add-dir's session entry (`add-dir:state`). Heuristic, not a sandbox: project-internal destructive commands are covered by the fixed table, not by a sandbox. One known blind spot: a *read* command's bare filename operand (`cat notes.txt`) is not collected as a target, so with `out read = ask` only absolute-path-shaped read operands are questioned — reads never write, so the four modes' write side is unaffected.
196
+ > **Implementation notes**: a new session resets the state on `session_start` (a repeated emission for the same session keeps it); the footer shows `perm i:A/A o:A/ask` while on (`A` allow, `a` ask, `D` deny). Subagent sessions start with their own state and do not inherit the parent's mode — when child sessions must be gated too, enable it through the project's autostart file. The approval log is appended by the gate bus (asks/blocks/session summaries) and by the permission gate (mode changes and session-grant allows); the writer is lazy, keeps no state across processes, and never participates in a decision. POSIX hosts (Linux / macOS / WSL) are the tested target; native Windows Git-Bash path spellings are approximated, not verified. bash decomposition uses `shell-quote`; unknown variables expand to a sentinel that makes the unit ask instead of silently becoming an empty path. Added directories are read from pi-add-dir's session entry (`add-dir:state`). Heuristic, not a sandbox: project-internal destructive commands are covered by the fixed table, not by a sandbox. Known blind spots, all on the **read** side (reads never write, so the four modes' write side is unaffected): a read command's bare filename operand (`cat notes.txt`) is not a target, so with `out read = ask` only absolute-path-shaped operands are questioned; a `curl` URL is never opened as a file, so only its `-o`/`-D`/`-c` flags are judged; and a remote `host:path` is somebody else's filesystem.
195
197
 
196
198
  ---
197
199
 
@@ -293,6 +295,8 @@ After a development task is done, type the `/ask-review` command to summon **a d
293
295
 
294
296
  `/ask-spec [topic]` opens a spec-review phase: the agent explores the code, asks what it cannot infer, and writes a spec — no code changes while the spec is under review. Then it calls `spec_submit`, the review opens in **your browser**, and you annotate it **paragraph by paragraph**: every blank-line-separated block can carry notes, and every note comes back to the agent as its next message. The pre-rename `/ask-plan` alias was removed.
295
297
 
298
+ - **A brief that does not fit on a command line.** Run `/ask-spec` with no arguments and the phase is only *armed*: nothing starts, nothing changes, and the next message you send — multi-line, pasted, whole paragraphs with lists and code — becomes the brief the review starts from. Its first line also names the default file (`specs/<slug>.md`). Typing the bare command again, or `/ask-spec off`, cancels before anything starts.
299
+
296
300
  - **Blocks are the unit of review.** Each paragraph is one block, with a badge telling you what changed since the previous round: `new`, `modified`, `moved`, `removed`. Unchanged blocks collapse, so a three-line edit does not look like a rewrite. Fenced code blocks stay whole.
297
301
  - **Two levels of notes.** On a block, or global. Nothing finer — no text ranges to re-anchor after an edit.
298
302
  - **The page keeps the review in view.** A two-column layout: the spec on the left; the revision stats and a clickable annotation index on the right. Global notes stay visible above the blocks even when the editor is closed.
@@ -307,13 +311,15 @@ After a development task is done, type the `/ask-review` command to summon **a d
307
311
  **Browser on WSL**: the review server binds `0.0.0.0` and the URL is printed with the WSL address, because Windows cannot reach a loopback-only server inside WSL. The opener prefers a Windows-side launcher (`wslview`, `cmd.exe /c start`, `powershell Start-Process`) and only falls back to `xdg-open` elsewhere — that is the difference between "opens your browser" and "opens a browser inside WSL that you cannot see".
308
312
 
309
313
  ```text
310
- /ask-spec build the export feature # start the review
311
- /ask-spec open # re-open the review page
312
- /ask-spec # while reviewing: leave the phase
314
+ /ask-spec build the export feature # start the review from a one-line topic
315
+ /ask-spec # idle: arm it — your next message becomes the brief
316
+ /ask-spec # reviewing: leave the phase
313
317
  /ask-spec off # leave the phase (the draft stays where it is)
318
+ /ask-spec open # re-open the review page
314
319
  ```
315
320
 
316
- The spec lands in `specs/<slug>.md` — the same place `/ask-init` keeps specs. Without an
321
+ The spec lands in `specs/<slug>.md` — the same place `/ask-init` keeps specs, with the slug
322
+ coming from the topic or from the first line of an armed brief. Without an
317
323
  agent framework the review still works, but `record_change` and `/ask-uat` stay unavailable
318
324
  until `/ask-init`; the command says so when the review starts. Leave an open UAT page first:
319
325
  the two phases do not run on top of each other.
@@ -367,27 +373,40 @@ record_change (implementation) → /ask-uat (cluster) → browser (tick)
367
373
 
368
374
  | Command | What it does |
369
375
  | --- | --- |
370
- | `/ask-uat` | cluster pending change records into acceptance items, then open the page |
376
+ | `/ask-uat` | cluster new change records into acceptance items, then open the page |
377
+ | `/ask-uat legacy` | same, but also cluster records that have no behaviour line (clustering those means reading them) |
371
378
  | `/ask-uat open` | reopen the page without a model turn |
372
379
  | `/ask-uat off` | stop the page server |
373
380
 
374
- **The page** lists open items newest-first. Each item carries a 2-3 sentence summary and an
375
- expandable test plan (steps, edge cases, what not to test). Ticking an item appends a `check`
376
- event immediately — there is no submit, and closing the page cannot lose a decision. Accepted
377
- items fold into a section you can expand to undo a tick; the evidence records are one click
378
- away in a drawer.
381
+ **The page** opens with a progress head (`verified / total` plus how many records are still
382
+ unclustered), then lists open items newest-first. Each item carries a 2-3 sentence summary and an
383
+ expandable test plan (steps, edge cases, what not to test) with the evidence records one click
384
+ away in a drawer. Ticking an item appends a `check` event immediately — there is no submit, and
385
+ closing the page cannot lose a decision. Accepted items fold into a section you can expand to
386
+ undo a tick; a side rail shows the current batch, the queue commands, what was accepted last and
387
+ which records were retired.
379
388
 
380
389
  **The rules that keep it honest**:
381
390
 
382
391
  - **Append-only ledger, no submit.** `.agents/uat/ledger.jsonl` is an event stream (`candidate`,
383
392
  `batch`, `item`, `link`, `check`, `uncheck`, `amend`, `merge`, `drop`), committed to git,
384
393
  deduplicated by event id, and safe for two processes appending at once (no lock, no merge).
385
- - **New evidence reopens an item.** If a change record lands after the tick, the item shows
386
- `reopened`: "accepted" means "accepted against the current evidence set".
387
- - **The ledger belongs to the main checkout.** A session running in a linked git worktree writes
388
- its records and events to the main checkout, so acceptance history never splits.
394
+ - **Newer evidence reopens an item.** An item counts as accepted only against the evidence it was
395
+ ticked with: attaching a record whose own timestamp is newer than the tick shows it as
396
+ `reopened`. Attaching an older record (backfilling history) leaves it accepted.
397
+ - **Retiring is a first-class exit.** `uat_item op="drop"` takes an item id, a list of record ids,
398
+ or both — the record-only form retires records without inventing an item for them. Records whose
399
+ `record_change` hint starts with `none:` never enter the queue at all (the filter is derived, the
400
+ ledger is not written). Both appear under "retired" on the page, so a shrinking queue never looks
401
+ like lost work.
402
+ - **The queue has two lanes.** Records written by `record_change` carry a behaviour sentence and a
403
+ normal `/ask-uat` run clusters them. Records that exist only as files (no behaviour line) stay
404
+ pending but out of the run, because clustering them means reading every file — `/ask-uat legacy`
405
+ includes them explicitly. One run clusters at most 12 items from 40 records either way.
389
406
  - **The directory is the fallback index.** A change record written by hand still shows up as
390
407
  pending; `record_change` adds the behaviour sentence and the test hint, but it is not a gate.
408
+ - **The ledger belongs to the main checkout.** A session running in a linked git worktree writes
409
+ its records and events to the main checkout, so acceptance history never splits.
391
410
  - **Nothing else.** No editing, no ordering, no comments, no assignment. If clustering is wrong,
392
411
  ask the agent in chat — it has `uat_item` (link / amend / merge / drop) while the page is open.
393
412
 
package/README.zh-CN.md CHANGED
@@ -10,12 +10,12 @@
10
10
  [![Pi package gallery](https://img.shields.io/badge/pi.dev-package%20gallery-6f42c1)](https://pi.dev/packages/@andares/pi-toolkits)
11
11
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
12
12
  [![Package Manager](https://img.shields.io/badge/package%20manager-pnpm-orange?logo=pnpm)](https://pnpm.io)
13
- [![pi >= 0.99](https://img.shields.io/badge/pi-%3E%3D0.99.0-blueviolet)](https://github.com/earendil-works/pi)
13
+ [![pi >= 1.0](https://img.shields.io/badge/pi-%3E%3D1.0.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
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
- **版本要求**: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 会告警。
18
+ **版本要求**:pi `>=1.0.0`。1.0.0 到 1.7.0 的每一个已发布版本都用完整门禁实测过(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
 
@@ -140,9 +140,11 @@ ask 是独立的(不需要 `/ask-init`)。规格评审或 UAT 页面开着
140
140
 
141
141
  - **bash** 先拆成简单命令 —— `&&`、`||`、`;`、管道、`$(…)`、反引号、`bash -c`、`eval`、常见间接包装(`sudo`、`env`、`xargs`、`find -exec`…)、heredoc —— 再逐条判定;`cd` 向前折叠,取最严格的结果,所以 `cd /tmp && rm x` 不会靠第一段蒙混过关
142
142
  - **带路径的工具**(`read` / `write` / `edit` / `grep` / `find` / `ls`)按自己的路径判定;其它工具按工作目录判定
143
- - **无法解析的输入** —— 非字面量 `cd` 或 `git -C`、路径里的未知 shell 变量、未闭合的 heredoc/命令替换 —— 一律询问,不看模式(fail closed),绝不猜测
144
- - **字面量 for 循环** —— `for f in a b; do grep x "$f"; done` 按字面量展开(这正是 bash 的行为);普通赋值不跨命令持久化(缺少控制流分析时不能安全替换),值来自 `$(…)`、循环列表不可知、循环变量被重赋值/修改时仍按 fail-closed 处理。换行是命令分隔符(`ls⏎rm x` 是两条命令,不是一条),反斜杠+换行是续行
145
- - **模式不是路径** —— `grep`/`rg`/`ag` 的第一个位置参数是模式(`grep -n '</div>\s*$' file` 不会询问);引号内的结尾 `$` 是字面字符,不是变量
143
+ - **无法解析的输入** —— 非字面量 `cd` 或 `git -C`、路径里的未知 shell 变量、未闭合的 heredoc/命令替换 —— 一律询问,不看模式(fail closed),绝不猜测。有两种形状**不是**路径:`curl` 的操作数是 URL(`curl "$API/list"` 不询问),`scp`/`sftp`/`rsync` 的 `host:path` 是对方机器上的路径。文件 flag 仍是目标,且解析不了时 fail closed(`curl -o "$X"`、`sort -o "$X"`)
144
+ - **字面量赋值与 for 循环** —— `PI=/opt/pi; grep x "$PI/docs"` 与 `for f in a b; do grep x "$f"; done` 都按字面量展开(这正是 bash 的行为)。赋值只在**纯顺序命令**里被替换:`&&`/`||` 之后、管道或子 shell 里、循环体内、`if`/`case` 块里、以及调用 `read`/`eval`/`source`/`export`/`unset`… 的命令,所有 `$VAR` 仍按 fail-closed 处理;值非字面量(`$(…)`、含空白的通配)同样不替换。换行是命令分隔符(`ls⏎rm x` 是两条命令,不是一条),反斜杠+换行是续行
145
+ - **shell 结构不是命令** —— `if`/`then`/`fi`、`while`、`!`、`[[ ]]` 与分组花括号 `{` `}` 在段首段尾被剥掉,循环里 `if [ -d "$d/x" ]; then echo "$d"; fi` 不会再被当成一条叫 `if` 的写命令
146
+ - **模式与 flag 不是路径** —— `grep`/`rg`/`ag` 的第一个位置参数是模式(`grep -n '</div>\s*$' file` 不会询问),引号内的结尾 `$` 是字面字符;`-o` 只在定义如此的命令里是输出文件:`find … -o -name x`、`grep -o PATTERN` 是读,`sort -o out.txt`、`docker compose config --output f` 是写
147
+ - **通配与拷贝** —— 通配解析到字面前缀(`/tmp/snap*.txt` → `/tmp/snap`)而不是所在目录,所以 `rm -f /tmp/snap*.txt` 不算「删除临时根」,而 `rm -rf /tmp/*` 仍然算。拷贝读源、只写一个目标(`cp`/`ln`/`install`/`rsync`/`scp`,含 `-t DIR`);`mv` 两端都算写,因为它会删掉源;`rsync --remove-source-files` 的源与 `install -d` 的每个操作数同样算写
146
148
  - **`git -C <dir>`** 按局部 `cd` 处理:相对路径参数(和仓库本身)按 `<dir>` 判定,而不是工作目录
147
149
  - **设备 sink 与数据参数** —— `/dev/null`、`/dev/stdout`、`/dev/stderr` 无论是重定向(`cmd > /dev/null`)还是普通操作数(`curl -o /dev/null`),都不算边界目标;`echo` / `printf` 的参数是数据,`curl -w` / `-H` / `-d` 这类已声明的 data flag 同理。未解析的输入与输出重定向都保持 fail closed
148
150
  - **容器只读子命令** —— `docker`/`podman` 的只读子命令(`ps`、`logs`、`inspect`、`images`、`compose ps/logs/config` 等)算读;`exec`、`run`、`rm`、`build` 以及未列出的子命令算写
@@ -191,7 +193,7 @@ jq -r 'select(.event=="ask") | .units[] | select(.opaque) | [.command,.note] | @
191
193
  run = ["/ask-perm allow allow allow ask"]
192
194
  ```
193
195
 
194
- > **实现说明**:新会话在 `session_start` 重置状态(同一会话的重复 emission 保持状态);开启时 footer 显示 `perm i:A/A o:A/ask`(`A` allow、`a` ask、`D` deny)。子代理会话有自己的状态、不继承父会话的模式;需要子会话也受控时,通过项目 autostart 再开启一次。审批日志由闸门总线(弹窗/拦截/会话摘要)与 permission 闸门(模式切换、会话授权放行)追加;写入器懒初始化、不跨进程保存状态,也从不参与判定。实测目标是 POSIX 宿主(Linux/macOS/WSL);原生 Windows Git-Bash 的路径拼写只做了近似,未验证。bash 拆解使用 `shell-quote`;未知变量会展开成哨兵而不是空字符串,使该命令转为询问而不是被悄悄当成空路径。add-dir 目录从 pi-add-dir 的会话条目 `add-dir:state` 读取。启发式,不是沙箱:项目内的破坏性操作由固定表兜底,而不是靠沙箱。已知盲区一处:**读命令的裸文件名参数**(`cat notes.txt`)不被收集为目标,所以把 `out read` 调成 `ask` 时只有绝对路径形状的读目标会被问——读本身不会写,四格模式的写侧不受影响。
196
+ > **实现说明**:新会话在 `session_start` 重置状态(同一会话的重复 emission 保持状态);开启时 footer 显示 `perm i:A/A o:A/ask`(`A` allow、`a` ask、`D` deny)。子代理会话有自己的状态、不继承父会话的模式;需要子会话也受控时,通过项目 autostart 再开启一次。审批日志由闸门总线(弹窗/拦截/会话摘要)与 permission 闸门(模式切换、会话授权放行)追加;写入器懒初始化、不跨进程保存状态,也从不参与判定。实测目标是 POSIX 宿主(Linux/macOS/WSL);原生 Windows Git-Bash 的路径拼写只做了近似,未验证。bash 拆解使用 `shell-quote`;未知变量会展开成哨兵而不是空字符串,使该命令转为询问而不是被悄悄当成空路径。add-dir 目录从 pi-add-dir 的会话条目 `add-dir:state` 读取。启发式,不是沙箱:项目内的破坏性操作由固定表兜底,而不是靠沙箱。已知盲区都在**读**侧(读不会写,四格模式的写侧不受影响):读命令的裸文件名参数(`cat notes.txt`)不被收集为目标,所以把 `out read` 调成 `ask` 时只有绝对路径形状的目标会被问;`curl` 的 URL 从不被当作本地文件打开,只判它的 `-o`/`-D`/`-c`;远端 `host:path` 是别人的文件系统。
195
197
 
196
198
  ---
197
199
 
@@ -293,6 +295,8 @@ run = ["/ask-perm allow allow allow ask"]
293
295
 
294
296
  `/ask-spec [主题]` 进入规格评审期:模型先调研、把代码里看不出来的问题问清楚,然后写一份 spec——评审期间不改代码。写完调用 `spec_submit`,评审页在**你的浏览器**里打开,你**逐段**批注:每个空行分隔的块都可以挂批注,批注会作为下一条消息回到模型。改名前的 `/ask-plan` 别名已移除。
295
297
 
298
+ - **一整段需求塞不进命令行。** 不带参数执行 `/ask-spec` 只是**武装**:什么都不启动、什么都不改,你发下的**下一条消息**——多行、粘贴、带列表和代码的整篇需求——才是这次评审的依据,默认文件名 `specs/<slug>.md` 也取自它的第一行。再执行一次裸命令或用 `/ask-spec off`,在任何东西开始前取消。
299
+
296
300
  - **块是评审单位。** 每个空行分隔的段落是一块,徽标告诉你相对上一版改了什么:`new`、`modified`、`moved`、`removed`。未变的块会折叠,三行小改不会看起来像整篇重写;围栏代码块保持完整。
297
301
  - **两级批注。** 段落级,或全局;没有更细的文本范围批注,改完不需要重新锚定。
298
302
  - **评审页一直看得见。** 双栏布局:左边是 spec,右边是本版统计和可点击的批注索引;全局批注即使编辑框关着也常显在正文上方。
@@ -307,13 +311,15 @@ run = ["/ask-perm allow allow allow ask"]
307
311
  **WSL 下的浏览器**:评审服务器绑 `0.0.0.0`,URL 用 WSL 的地址打印,因为 Windows 连不到 WSL 里只绑 loopback 的服务器。打开器优先用 Windows 侧启动器(`wslview`、`cmd.exe /c start`、`powershell Start-Process`),其它平台才回落到 `xdg-open`——这决定了是「打开你的浏览器」还是「在 WSL 里打开一个你看不见的浏览器」。
308
312
 
309
313
  ```text
310
- /ask-spec 做导出功能 # 进入规格评审
311
- /ask-spec open # 重新打开评审页
312
- /ask-spec # 评审中再次执行:退出评审期
314
+ /ask-spec 做导出功能 # 用一行主题进入规格评审
315
+ /ask-spec # 空闲时:武装——下一条消息作为需求
316
+ /ask-spec # 评审中:退出评审期
313
317
  /ask-spec off # 退出评审期(草稿留在原处)
318
+ /ask-spec open # 重新打开评审页
314
319
  ```
315
320
 
316
- spec 落在 `specs/<slug>.md`——与 `/ask-init` 放 spec 的地方相同。没有 agent 框架时评审仍可用,
321
+ spec 落在 `specs/<slug>.md`——与 `/ask-init` 放 spec 的地方相同,slug 取自主题或武装时那条
322
+ 需求的第一行。没有 agent 框架时评审仍可用,
317
323
  但 `record_change` 与 `/ask-uat` 不可用,直到 `/ask-init`;命令在评审开始时会说明。
318
324
  UAT 页面开着时先退出:两个相位不叠在一起跑。
319
325
 
@@ -364,20 +370,28 @@ record_change(实施)→ /ask-uat(聚类)→ 浏览器(勾选)→
364
370
 
365
371
  | 命令 | 做什么 |
366
372
  | --- | --- |
367
- | `/ask-uat` | 把待归类的实施记录聚成验收项,然后打开页面 |
373
+ | `/ask-uat` | 把有新行为句的待归类记录聚成验收项,然后打开页面 |
374
+ | `/ask-uat legacy` | 同上,并把没有行为句的旧记录也纳入一轮(聚类它们意味着逐个读文件) |
368
375
  | `/ask-uat open` | 只重开页面,不走模型回合 |
369
376
  | `/ask-uat off` | 关掉页面服务 |
370
377
 
371
- **页面**按时间倒序列出未验收项:每条 2–3 句摘要,可展开测试方案(步骤、边界、
372
- 「这次不用测什么」)。勾选即写一条 `check` 事件——**没有提交**,关页不会丢决定。
373
- 已验收项折叠在底部,展开可反选;证据记录点一下就能看原文。
378
+ **页面**顶部是验收进度(已验收 / 总数,以及还有多少记录未归类),下面按时间倒序列出未验收项:
379
+ 每条 2–3 句摘要,可展开测试方案(步骤、边界、「这次不用测什么」),证据记录点一下就在底部抽屉里看原文。
380
+ 勾选即写一条 `check` 事件——**没有提交**,关页不会丢决定。已验收项折叠在底部,展开可反选;
381
+ 右侧栏显示本批次、队列命令、最近验收与已退休记录。
374
382
 
375
383
  **它靠这几条站得住**:
376
384
 
377
385
  - **只追加的台账,没有提交。** `.agents/uat/ledger.jsonl` 是事件流(`candidate`、`batch`、`item`、
378
386
  `link`、`check`、`uncheck`、`amend`、`merge`、`drop`),进 git,按事件 id 去重,两个进程同时追加也不丢事件。
379
- - **新证据会重开验收项。** 勾选之后又有新记录落到同一项,页面标 `reopened`:
380
- 「已验收」的含义是「按当前证据集验过」。
387
+ - **更新的证据会重开验收项。** 「已验收」只对勾选当时的证据成立:挂上一条时间比勾选更新的记录,
388
+ 页面标 `reopened`;补挂更早的历史记录不会重开。
389
+ - **退休是一条正经出口。** `uat_item op="drop"` 可以给验收项 id、记录 id 列表,或两者都给——
390
+ 只给记录时直接退休,不必先建一个项。`record_change` 的 hint 以 `none:` 开头的记录根本不进队列
391
+ (过滤在派生层,不写台账)。两者都会在页面的「已退休」里列出来,队列变短不等于记录丢了。
392
+ - **队列分两条车道。** `record_change` 写的记录带行为句,普通 `/ask-uat` 就能聚类;只有文件、
393
+ 没有行为句的旧记录留在 pending 但不进这一轮,因为聚类它们要逐个读文件——
394
+ `/ask-uat legacy` 才显式纳入。两种情况下一轮都最多 12 个项、40 条记录。
381
395
  - **台账只属于主仓。** 在 git worktree 里跑的会话,实施记录与事件都写主仓,验收历史不会被分裂。
382
396
  - **目录本身就是兜底索引。** 手写的实施记录同样会出现在待验收列表;`record_change` 只是补上
383
397
  行为句与测试提示,不是闸门。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andares/pi-toolkits",
3
- "version": "1.2.4",
3
+ "version": "1.3.0",
4
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",
@@ -53,7 +53,7 @@
53
53
  "session-backlog"
54
54
  ],
55
55
  "peerDependencies": {
56
- "@earendil-works/pi-coding-agent": ">=0.99.0",
56
+ "@earendil-works/pi-coding-agent": ">=1.0.0",
57
57
  "@earendil-works/pi-tui": "*",
58
58
  "typebox": "*"
59
59
  },
@@ -63,9 +63,9 @@
63
63
  "smol-toml": "^1.9.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@earendil-works/pi-ai": "^1.6.0",
67
- "@earendil-works/pi-coding-agent": "^1.6.0",
68
- "@earendil-works/pi-tui": "^1.6.0",
66
+ "@earendil-works/pi-ai": "^1.7.0",
67
+ "@earendil-works/pi-coding-agent": "^1.7.0",
68
+ "@earendil-works/pi-tui": "^1.7.0",
69
69
  "@types/node": "^26.6.2",
70
70
  "typebox": "^1.3.27",
71
71
  "typescript": "^5.6.0",
@@ -48,7 +48,7 @@ export const RUNNABLE_REASONS: ReadonlySet<string> = new Set([
48
48
  * `-r` (`--resume`), `--session <path>` and `--fork <path>` all open an
49
49
  * existing session *before* the first runtime exists, and that runtime is
50
50
  * created without an explicit session_start event, so extensions see pi's
51
- * default reason — `startup` — not `resume` (verified on pi 1.2.0–1.6.0:
51
+ * default reason — `startup` — not `resume` (verified on pi 1.2.0–1.7.0:
52
52
  * `main.js` builds the initial session manager from those flags and calls
53
53
  * `createAgentSessionRuntime` with no `sessionStartEvent`;
54
54
  * `agent-session.js` defaults it to `{ reason: "startup" }`). `resume` is only
@@ -27,11 +27,11 @@
27
27
  * that flag is what routes "/cmd args" through _tryExecuteExtensionCommand
28
28
  * instead of the model prompt path. The wrapper defaults it to false in this
29
29
  * package. `_tryExecuteExtensionCommand` is byte-identical across every
30
- * published version of the supported window (1.3.0 → 1.6.0); `sendUserMessage`
30
+ * published version of the supported window (1.4.0 → 1.7.0); `sendUserMessage`
31
31
  * itself was refactored in 1.5.1 (the rest of the body moved into
32
32
  * `_preparePrompt`, #9154), but the extension-command branch is still the
33
33
  * first early exit of the wrapper, so `/cmd args` never reaches the model
34
- * prompt path (1.6.0 left `sendUserMessage` and `_preparePrompt`
34
+ * prompt path (1.6.0 → 1.7.0 left `sendUserMessage` and `_preparePrompt`
35
35
  * byte-identical). See AGENTS.md host-compat discipline for the version matrix.
36
36
  *
37
37
  * Only extension commands can run this way. Built-in commands (/compact,
@@ -135,7 +135,7 @@ async function completeSummary(
135
135
  * over).
136
136
  *
137
137
  * 1.4.0 changed two things this mirror covers, and we follow 1.4.0 for every
138
- * host in the supported window (1.2.0 → 1.5.1) because both are bug fixes
138
+ * host in the supported window (1.4.0 → 1.7.0) because both are bug fixes
139
139
  * rather than behavior we could sensibly keep per version:
140
140
  * - summaries no longer cap maxTokens at 0.8/0.5 × reserveTokens; the
141
141
  * request omits maxTokens so the provider uses the model's output limit
@@ -8,8 +8,8 @@
8
8
  * bindings — only the cycle semantics change (patch-cycle.ts), so no
9
9
  * keybinding conflicts arise.
10
10
  *
11
- * Verified against every published version of the supported range
12
- * (0.99.0 → 1.5.1) keybinding tables + pi-tui input dispatch on WSL2 +
11
+ * Keybinding tables audited against every published version in the supported
12
+ * range (1.0.0 → 1.7.0), with pi-tui input dispatch checked on WSL2 +
13
13
  * Windows Terminal; re-run `pnpm check:keybindings` after every host upgrade
14
14
  * before trusting this.
15
15
  */
@@ -15,9 +15,10 @@
15
15
  * model available" feedback); otherwise jump to it
16
16
  * - the apply logic mirrors pi's _cycleScopedModel/_cycleAvailableModel
17
17
  * (byte-identical across every published version in the supported window
18
- * 1.2.0 → 1.5.1 — `cycleModel` itself is untouched by 1.4.0's recovery and
19
- * tool-restore rewrites, by 1.5.0's auth-routing/loadout-ordering changes
20
- * and by 1.5.1's extraction of the index math into `getNextCycleIndex`
18
+ * 1.4.0 → 1.7.0 — `cycleModel` itself is untouched by 1.4.0's recovery and
19
+ * tool-restore rewrites, by 1.5.0's auth-routing/loadout-ordering changes,
20
+ * by the later 1.6.x changes and by 1.7.0, and by 1.5.1's extraction of
21
+ * the index math into `getNextCycleIndex`
21
22
  * (that refactor lives in `_cycleScopedModel`/`_cycleAvailableModel`, which
22
23
  * this patch replaces rather than calls; the semantics it encodes —
23
24
  * wrap-around, and "current model not in the list → forward first /
@@ -22,7 +22,7 @@
22
22
  * keeps loading and ctrl+p falls back to stock behavior. The prototype
23
23
  * shape touched here (handleInput/updateList/filterModels and the instance
24
24
  * fields below) is unchanged across the mandatory window
25
- * pi 1.3.0 → 1.6.0 (and exercised by the 0.99.0 → 1.2.0 backward probes).
25
+ * pi 1.4.0 → 1.7.0 (and exercised by the 1.0.0 → 1.3.0 backward probes).
26
26
  * updateList gained one layout change in 1.5.0 — the disambiguating model
27
27
  * name after the id — mirrored here; see distinctModelName below.
28
28
  * filterModels gained a second `preferredModel` argument in 1.5.1 (keep the
@@ -58,6 +58,17 @@ describe("four-mode policy", () => {
58
58
  expect(decision.reason).toContain("outside-project write");
59
59
  });
60
60
 
61
+ it("treats an rsync source as a write when rsync removes it", () => {
62
+ const ctx = makeContext(project());
63
+ expect(decide("rsync /outside/a /tmp/pi-perm-rsync", ctx).action).toBe("allow");
64
+ const decision = decide(
65
+ "rsync --remove-source-files /outside/a /tmp/pi-perm-rsync",
66
+ ctx,
67
+ );
68
+ expect(decision.action).toBe("ask");
69
+ expect(decision.target).toMatchObject({ path: "/outside/a", effect: "write" });
70
+ });
71
+
61
72
  it("honours ask for in-project writes", () => {
62
73
  const cwd = project();
63
74
  const ctx = makeContext(cwd, { ...DEFAULT_MODES, inWrite: "ask" });
@@ -156,7 +156,9 @@ describe("read/write classification", () => {
156
156
  describe("paths", () => {
157
157
  it("treats rm/mv/cp operands as targets even when bare", () => {
158
158
  expect(summary("rm notes.txt")[0]?.targets).toEqual(["write:/proj/notes.txt"]);
159
- expect(summary("cp a b")[0]?.targets).toEqual(["write:/proj/a", "write:/proj/b"]);
159
+ // A copy reads its source and writes its destination; `mv` removes both.
160
+ expect(summary("cp a b")[0]?.targets).toEqual(["read:/proj/a", "write:/proj/b"]);
161
+ expect(summary("mv a b")[0]?.targets).toEqual(["write:/proj/a", "write:/proj/b"]);
160
162
  });
161
163
 
162
164
  it("resolves git -C against the -C directory, not the base", () => {
@@ -266,14 +268,28 @@ describe("approval-log regressions", () => {
266
268
  expect(parseCommandUnits("f=2026-10-29.jsonl", CWD)).toEqual([]);
267
269
  });
268
270
 
269
- it("leaves ordinary assignments unresolved without control-flow analysis", () => {
270
- const units = summary('f=notes.md; grep -n x "src/$f"');
271
+ it("resolves a literal assignment for the commands that follow it", () => {
272
+ const units = summary('PI=/opt/pi; grep -n x "$PI/docs/a.md"');
271
273
  expect(units).toHaveLength(1);
272
- expect(units[0]).toMatchObject({ command: "grep", effect: "write", opaque: true });
273
- expect(units[0]?.targets).toEqual([]);
274
+ expect(units[0]).toMatchObject({ command: "grep", effect: "read", opaque: false });
275
+ expect(units[0]?.targets).toEqual(["read:/opt/pi/docs/a.md"]);
274
276
  });
275
277
 
276
- it("does not substitute a non-literal assignment", () => {
278
+ it("keeps a conditional assignment unresolved", () => {
279
+ // `&&` may skip the assignment, and the substitution would then answer for
280
+ // a path the command never touches.
281
+ for (const command of [
282
+ 'false && d=/safe; rm -rf "$d/x"',
283
+ 'if [ -d x ]; then d=/safe; fi; rm -rf "$d/x"',
284
+ 'd=/safe; d=$(mktemp); rm -rf "$d/x"',
285
+ 'f() { d=/safe; }; d=/etc; f; rm -rf "$d/x"',
286
+ ]) {
287
+ const rm = summary(command).filter((unit) => unit.command === "rm");
288
+ expect(rm[0]?.opaque).toBe(true);
289
+ }
290
+ });
291
+
292
+ it("keeps a non-literal assignment unresolved", () => {
277
293
  const units = summary('f=$(date); sed -n 1p "d/$f"');
278
294
  expect(units.find((unit) => unit.command === "sed")?.opaque).toBe(true);
279
295
  });
@@ -366,6 +382,16 @@ describe("approval-log regressions", () => {
366
382
  expect(unit).toMatchObject({ command: "rm", opaque: true });
367
383
  });
368
384
 
385
+ it("does not reuse an assignment after printf or arithmetic can change it", () => {
386
+ for (const command of [
387
+ 'D=/tmp; printf -v D /etc; rm "$D/x"',
388
+ 'D=/tmp; echo $((D=2)); rm "$D/x"',
389
+ ]) {
390
+ const unit = summary(command).find((entry) => entry.command === "rm");
391
+ expect(unit).toMatchObject({ command: "rm", opaque: true });
392
+ }
393
+ });
394
+
369
395
  it("keeps container output options as writes", () => {
370
396
  const unit = first("docker compose config --output /tmp/compose.yml");
371
397
  expect(unit.effect).toBe("write");
@@ -376,3 +402,139 @@ describe("approval-log regressions", () => {
376
402
  });
377
403
  });
378
404
  });
405
+
406
+ /**
407
+ * Regressions from the 2026-11-13 → 2026-12-02 approval log (46 asks, 12 of
408
+ * them `unresolved path argument`). Replaying every logged command against the
409
+ * parser took the still-asking count from 44 to 25; the cases below are the
410
+ * false-positive classes that log exposed. The 25 that still ask are counted
411
+ * in the record: SQL heredocs, shell-function calls, `node -e` / `python3 -c`,
412
+ * `docker exec` outside the project, broken quoting, process substitution.
413
+ */
414
+ describe("approval-log regressions (2026-11 → 12)", () => {
415
+ it("treats an unresolved curl operand as an unknown URL, not a path", () => {
416
+ for (const command of [
417
+ `curl -s --max-time 20 "\${H[@]}" http://zzd.local:26080/adminapi/project/list?page=1`,
418
+ 'API=http://zzd.local:26080/adminapi; curl -s "$API/project/list"',
419
+ ]) {
420
+ const unit = first(command);
421
+ expect(unit).toMatchObject({ command: "curl", effect: "read", opaque: false });
422
+ expect(unit.targets).toEqual([]);
423
+ }
424
+ });
425
+
426
+ it("fails closed on an unresolved curl output flag", () => {
427
+ // The old behaviour dropped the target silently, so the write was judged
428
+ // against the working directory instead of wherever `$X` points.
429
+ for (const command of [
430
+ 'curl -s -o "$X" http://example.com/x',
431
+ 'curl -s -o"$X/out" http://example.com/x',
432
+ 'curl -s --output="$X/out" http://example.com/x',
433
+ 'curl -s --output-dir "$X" -O http://example.com/x',
434
+ 'curl -s --output-dir="$X/out" -O http://example.com/x',
435
+ 'curl -s -D "$X" http://example.com/x',
436
+ 'curl --trace="$X/trace" http://example.com/x',
437
+ ]) {
438
+ expect(first(command)).toMatchObject({
439
+ command: "curl",
440
+ opaque: true,
441
+ note: "unresolved output target",
442
+ });
443
+ }
444
+ expect(summary("curl -s -o /tmp/a.json http://example.com/x")[0]?.targets).toEqual([
445
+ "write:/tmp/a.json",
446
+ ]);
447
+ expect(summary("curl --output=/tmp/b.json http://example.com/x")[0]?.targets).toEqual([
448
+ "write:/tmp/b.json",
449
+ ]);
450
+ expect(summary("curl --stderr /tmp/curl.err http://example.com/x")[0]?.targets).toEqual([
451
+ "write:/tmp/curl.err",
452
+ ]);
453
+ expect(summary("curl --output-dir - -O http://example.com/x")[0]?.targets).toEqual([
454
+ "write:/proj/-",
455
+ ]);
456
+ });
457
+
458
+ it("does not mistake curl's local file options for URL operands", () => {
459
+ for (const command of [
460
+ 'curl --upload-file "$X/file" http://example.com/x',
461
+ 'curl --cacert "$X/ca.pem" http://example.com/x',
462
+ 'curl --config="$X/curlrc"',
463
+ ]) {
464
+ expect(first(command)).toMatchObject({
465
+ command: "curl",
466
+ opaque: true,
467
+ note: "unresolved path argument",
468
+ });
469
+ }
470
+ expect(first("curl --cacert /tmp/ca.pem http://example.com/x").targets).toEqual([
471
+ { path: "/tmp/ca.pem", effect: "read", source: "operand" },
472
+ ]);
473
+ });
474
+
475
+ it("keeps `-o` a flag for the commands that define it that way", () => {
476
+ // Both used to become a write to the next word (and its glob directory).
477
+ const find = first("find . -maxdepth 2 -name '*.ptr' -o -name '*.pen'");
478
+ expect(find).toMatchObject({ command: "find", effect: "read" });
479
+ expect(find.targets.map((target) => target.effect)).toEqual(["read"]);
480
+ const grep = first(String.raw`grep -o "not clustered yet[^\"]*" assets/index.js`);
481
+ expect(grep).toMatchObject({ command: "grep", effect: "read" });
482
+ expect(grep.targets.map((target) => `${target.effect}:${target.path}`)).toEqual([
483
+ "read:/proj/assets/index.js",
484
+ ]);
485
+ });
486
+
487
+ it("treats shell keywords and grouping braces as structure", () => {
488
+ const loop = summary(
489
+ 'for d in /a /b; do if [ -d "$d/node_modules" ]; then echo "$d"; fi; done',
490
+ );
491
+ expect(loop.map((unit) => unit.command).sort()).toEqual(["[", "[", "echo", "echo"]);
492
+ expect(loop.every((unit) => unit.effect === "read")).toBe(true);
493
+ const block = summary('[ -n "$r" ] && { echo "== $d =="; echo "$r"; }');
494
+ expect(block.map((unit) => unit.command)).toEqual(["[", "echo", "echo"]);
495
+ expect(first("[[ -d /tmp/x ]] && echo ok")).toMatchObject({
496
+ command: "[[",
497
+ effect: "read",
498
+ });
499
+ });
500
+
501
+ it("resolves a glob to its literal prefix, not to the containing directory", () => {
502
+ // `/tmp/snap*.txt` used to resolve to `/tmp` and hit the destructive
503
+ // table as a "recursive delete of a temp root".
504
+ expect(summary("rm -f /tmp/snap*.txt")[0]?.targets).toEqual(["write:/tmp/snap"]);
505
+ expect(summary("rm -f *.log")[0]?.targets).toEqual(["write:/proj"]);
506
+ });
507
+
508
+ it("collects only the destination of a copy as a write", () => {
509
+ const ln = summary("ln -sfn /opt/tool/node_modules /tmp/smoke/node_modules");
510
+ expect(ln[0]?.targets).toEqual([
511
+ "read:/opt/tool/node_modules",
512
+ "write:/tmp/smoke/node_modules",
513
+ ]);
514
+ // The only local operand is the source; the destination is remote.
515
+ const scp = summary("scp -P 2158 -o BatchMode=yes /tmp/a.php andares@mix.zzdcn.com:/tmp/a.php");
516
+ expect(scp[0]?.targets).toEqual(["read:/tmp/a.php"]);
517
+ expect(summary("cp -t /tmp/out a b")[0]?.targets).toEqual([
518
+ "write:/tmp/out",
519
+ "read:/proj/a",
520
+ "read:/proj/b",
521
+ ]);
522
+ expect(summary("cp --target-directory=/outside /tmp/a")[0]?.targets).toEqual([
523
+ "write:/outside",
524
+ "read:/tmp/a",
525
+ ]);
526
+ expect(summary("cp -t/outside /tmp/a")[0]?.targets).toEqual([
527
+ "write:/outside",
528
+ "read:/tmp/a",
529
+ ]);
530
+ expect(summary("install -d /outside/a /tmp/out")[0]?.targets).toEqual([
531
+ "write:/outside/a",
532
+ "write:/tmp/out",
533
+ ]);
534
+ // rsync can be a move, not just a copy.
535
+ expect(summary("rsync --remove-source-files /outside/a /tmp/out")[0]?.targets).toEqual([
536
+ "write:/outside/a",
537
+ "write:/tmp/out",
538
+ ]);
539
+ });
540
+ });