@andares/pi-toolkits 1.2.5 → 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 +9 -0
- package/README.md +29 -14
- package/README.zh-CN.md +20 -10
- package/package.json +1 -1
- package/src/features/permission/policy.test.ts +11 -0
- package/src/features/permission/units.test.ts +168 -6
- package/src/features/permission/units.ts +441 -34
- package/src/features/uat/assets/index-CPTHXggT.js +1 -0
- package/src/features/uat/assets/index-D9S_sCVr.css +1 -0
- package/src/features/uat/assets/index.html +3 -3
- package/src/features/uat/index.test.ts +96 -3
- package/src/features/uat/index.ts +42 -12
- package/src/features/uat/item-tool.ts +36 -8
- package/src/features/uat/ledger.test.ts +170 -14
- package/src/features/uat/ledger.ts +127 -44
- package/src/features/uat/prompt.ts +41 -8
- package/src/features/uat/records.test.ts +14 -0
- package/src/features/uat/records.ts +13 -1
- package/src/features/uat/assets/index-D-W9zj0w.css +0 -1
- package/src/features/uat/assets/index-DCBQCsli.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,14 @@ 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
|
+
|
|
14
22
|
## 1.2.5 — 2026-11-30
|
|
15
23
|
|
|
16
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.
|
|
@@ -106,3 +114,4 @@ renames that heading to the version being published and refuses an empty section
|
|
|
106
114
|
|
|
107
115
|
|
|
108
116
|
|
|
117
|
+
|
package/README.md
CHANGED
|
@@ -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`
|
|
145
|
-
- **
|
|
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.
|
|
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
|
|
|
@@ -371,27 +373,40 @@ record_change (implementation) → /ask-uat (cluster) → browser (tick)
|
|
|
371
373
|
|
|
372
374
|
| Command | What it does |
|
|
373
375
|
| --- | --- |
|
|
374
|
-
| `/ask-uat` | cluster
|
|
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) |
|
|
375
378
|
| `/ask-uat open` | reopen the page without a model turn |
|
|
376
379
|
| `/ask-uat off` | stop the page server |
|
|
377
380
|
|
|
378
|
-
**The page**
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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.
|
|
383
388
|
|
|
384
389
|
**The rules that keep it honest**:
|
|
385
390
|
|
|
386
391
|
- **Append-only ledger, no submit.** `.agents/uat/ledger.jsonl` is an event stream (`candidate`,
|
|
387
392
|
`batch`, `item`, `link`, `check`, `uncheck`, `amend`, `merge`, `drop`), committed to git,
|
|
388
393
|
deduplicated by event id, and safe for two processes appending at once (no lock, no merge).
|
|
389
|
-
- **
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
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.
|
|
393
406
|
- **The directory is the fallback index.** A change record written by hand still shows up as
|
|
394
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.
|
|
395
410
|
- **Nothing else.** No editing, no ordering, no comments, no assignment. If clustering is wrong,
|
|
396
411
|
ask the agent in chat — it has `uat_item` (link / amend / merge / drop) while the page is open.
|
|
397
412
|
|
package/README.zh-CN.md
CHANGED
|
@@ -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
|
-
-
|
|
145
|
-
-
|
|
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`
|
|
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
|
|
|
@@ -368,20 +370,28 @@ record_change(实施)→ /ask-uat(聚类)→ 浏览器(勾选)→
|
|
|
368
370
|
|
|
369
371
|
| 命令 | 做什么 |
|
|
370
372
|
| --- | --- |
|
|
371
|
-
| `/ask-uat` |
|
|
373
|
+
| `/ask-uat` | 把有新行为句的待归类记录聚成验收项,然后打开页面 |
|
|
374
|
+
| `/ask-uat legacy` | 同上,并把没有行为句的旧记录也纳入一轮(聚类它们意味着逐个读文件) |
|
|
372
375
|
| `/ask-uat open` | 只重开页面,不走模型回合 |
|
|
373
376
|
| `/ask-uat off` | 关掉页面服务 |
|
|
374
377
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
+
**页面**顶部是验收进度(已验收 / 总数,以及还有多少记录未归类),下面按时间倒序列出未验收项:
|
|
379
|
+
每条 2–3 句摘要,可展开测试方案(步骤、边界、「这次不用测什么」),证据记录点一下就在底部抽屉里看原文。
|
|
380
|
+
勾选即写一条 `check` 事件——**没有提交**,关页不会丢决定。已验收项折叠在底部,展开可反选;
|
|
381
|
+
右侧栏显示本批次、队列命令、最近验收与已退休记录。
|
|
378
382
|
|
|
379
383
|
**它靠这几条站得住**:
|
|
380
384
|
|
|
381
385
|
- **只追加的台账,没有提交。** `.agents/uat/ledger.jsonl` 是事件流(`candidate`、`batch`、`item`、
|
|
382
386
|
`link`、`check`、`uncheck`、`amend`、`merge`、`drop`),进 git,按事件 id 去重,两个进程同时追加也不丢事件。
|
|
383
|
-
-
|
|
384
|
-
|
|
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 条记录。
|
|
385
395
|
- **台账只属于主仓。** 在 git worktree 里跑的会话,实施记录与事件都写主仓,验收历史不会被分裂。
|
|
386
396
|
- **目录本身就是兜底索引。** 手写的实施记录同样会出现在待验收列表;`record_change` 只是补上
|
|
387
397
|
行为句与测试提示,不是闸门。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andares/pi-toolkits",
|
|
3
|
-
"version": "1.
|
|
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",
|
|
@@ -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
|
-
|
|
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("
|
|
270
|
-
const units = summary('
|
|
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: "
|
|
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("
|
|
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
|
+
});
|