pi-verdict 0.12.0 → 0.12.1
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/README.md +14 -9
- package/README.zh-CN.md +70 -67
- package/extensions/jev-adapter.ts +16 -0
- package/extensions/pi-verdict.ts +77 -21
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/pi-verdict)
|
|
7
7
|
[](https://pi.dev)
|
|
8
8
|
|
|
9
|
-
**pi-verdict is a minimal permission gate for [pi](https://pi.dev)
|
|
9
|
+
**pi-verdict is a minimal permission gate for [pi](https://pi.dev), inspired by Claude Code's auto mode: every tool call gets checked before it runs — allow, deny, or ask you first.**
|
|
10
10
|
|
|
11
|
-
- Minimal —
|
|
11
|
+
- Minimal — a ~2k-line single-file core (plus a small bundled jev adapter)
|
|
12
12
|
- Built-in danger rules and your own allow/deny rules settle the clear cases first, at zero latency
|
|
13
13
|
- Everything else goes to a model classifier that sees the conversation context
|
|
14
14
|
- Any uncertainty or failure fails closed; nothing ever runs silently
|
|
@@ -39,10 +39,10 @@ Full statement in [docs/security-principles.md](docs/security-principles.md).
|
|
|
39
39
|
|
|
40
40
|
## Screenshots
|
|
41
41
|
|
|
42
|
-

|
|
42
|
+

|
|
43
43
|
|
|
44
|
-

|
|
45
|
-

|
|
44
|
+

|
|
45
|
+

|
|
46
46
|
|
|
47
47
|
## Quick start
|
|
48
48
|
|
|
@@ -58,6 +58,8 @@ pi --extension ./extensions/pi-verdict.ts
|
|
|
58
58
|
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
+
Requires pi ≥ 0.84. Works in interactive and non-interactive (`-p`/json/rpc) sessions; in non-interactive modes `ask` degrades to `deny`.
|
|
62
|
+
|
|
61
63
|
### Hosts
|
|
62
64
|
|
|
63
65
|
pi-verdict runs on both [pi](https://github.com/badlogic/pi-mono) and [oh-my-pi](https://github.com/can1357/oh-my-pi) (omp) — it self-anchors to whichever agent tree it is installed in, and follows the extension copy's own location on dual-install machines. On omp 18 the classifier's completion call falls back to the pi-ai compat API (still fail-closed). Details: [docs/configuration.md](docs/configuration.md#host-notes-pi-and-oh-my-pi).
|
|
@@ -94,6 +96,7 @@ pi-verdict runs on both [pi](https://github.com/badlogic/pi-mono) and [oh-my-pi]
|
|
|
94
96
|
"~/.profile",
|
|
95
97
|
"~/.gnupg",
|
|
96
98
|
"~/.mc",
|
|
99
|
+
"~/.kube",
|
|
97
100
|
"~/.zshrc",
|
|
98
101
|
"~/.bashrc"
|
|
99
102
|
],
|
|
@@ -122,7 +125,7 @@ pi-verdict runs on both [pi](https://github.com/badlogic/pi-mono) and [oh-my-pi]
|
|
|
122
125
|
- `classifierModel: "typesafe/jev-latest"` opts into the bundled **jev decisions adapter** — gray-zone verdicts via TypeSafe's jev (OpenRouter by default, or TypeSafe's official API directly with `PI_VERDICT_JEV_TRANSPORT=typesafe`); experimental, see [ADR-0003](docs/adr/0003-jev-decisions-adapter.md)
|
|
123
126
|
- `audit: true` records every **gray-zone adjudication** (the full transcript sent to the classifier, its raw response, the parsed verdict) as JSONL under `~/.pi/agent/verdicts/<sessionId>.jsonl` — one file per session, the 20 most recent kept. Interactive asks also record your answer (`userAnswer` ground truth, written after the confirm resolves), and protected-path asks are recorded too (#62); rule allow/deny stays unaudited. Local-only and full-fidelity (protected-path plaintext may appear — it never leaves your machine; [ADR-0002](docs/adr/0002-deny-paths-deterministic-ask.md) boundary note); the agent can neither read nor write the directory. `/automode` shows the audit state and path while on
|
|
124
127
|
- `notifyAllows: true` notifies on every **classifier allow** (reason + action line — e.g. jev's probability breakdown); default `false` keeps passes silent. Mechanical passes (your own allow rules, protected-path confirms) never notify; with both switches on the notification appears once
|
|
125
|
-
- `classifierMinConfidence` (optional, [ADR-0004](docs/adr/0004-classifier-fallback-cascade.md)) sets the **confidence floor**: a jev verdict below it is demoted — cascaded to `classifierFallbackModel` if set (`enforce`, the default = the second layer adjudicates
|
|
128
|
+
- `classifierMinConfidence` (optional, [ADR-0004](docs/adr/0004-classifier-fallback-cascade.md)) sets the **confidence floor**: a jev verdict below it is demoted — cascaded to `classifierFallbackModel` if set (`enforce`, the default = the second layer adjudicates; a demoted **deny or ask** can never be auto-relaxed to an allow; a fail-closed layer emitted no verdict, so its rescue stands; `shadow` = records its opinion only and you are asked — `/automode` hints the activation switch), otherwise asked of you directly. At/above the floor the first layer is autonomous. The floor applies to decisions models only — with an LLM classifier it is inert, and a one-time warning says so. A natural pairing: jev first + a haiku/flash-class fallback
|
|
126
129
|
|
|
127
130
|
No built-in allowlist — every "always allow" claim is yours ([why](docs/configuration.md#why-no-built-in-allowlist)). Full reference: [docs/configuration.md](docs/configuration.md).
|
|
128
131
|
|
|
@@ -148,9 +151,7 @@ jev's calibrated confidence is exactly what the confidence floor keys on — pai
|
|
|
148
151
|
The gate's own files — the config and the installed extension copy — are **user-editable only**: writes from inside the gate hard-deny (reads pass); your editor never passes through the gate, the sudoers/visudo precedent.
|
|
149
152
|
|
|
150
153
|
- **Not disableable by any config** — `builtinDenyFloor: false` and user `allow` rules cannot touch this layer
|
|
151
|
-
- **Tamper detection** as the backstop: watched files are snapshotted at `session_start` and re-verified before every verdict — a changed extension copy is auto-restored and the session goes fail-closed; a changed config gets one explicit keep/restore confirm ([ADR-0001](docs/adr/0001-self-protection-layer.md) for the differential-disposal rationale)
|
|
152
|
-
|
|
153
|
-
Requires pi ≥ 0.84. Works in interactive and non-interactive (`-p`/json/rpc) sessions; in non-interactive modes `ask` degrades to `deny`.
|
|
154
|
+
- **Tamper detection** as the backstop: watched files are snapshotted at `session_start` and re-verified before every verdict — a changed extension copy is auto-restored and the session goes fail-closed; a changed config gets one explicit keep/restore confirm when a UI is available (headless auto-restores, same as the extension copy; [ADR-0001](docs/adr/0001-self-protection-layer.md) for the differential-disposal rationale)
|
|
154
155
|
|
|
155
156
|
---
|
|
156
157
|
|
|
@@ -169,6 +170,10 @@ Honest framing: pi-automode and pi-verdict have **converged on the same architec
|
|
|
169
170
|
|
|
170
171
|
## Pipeline
|
|
171
172
|
|
|
173
|
+

|
|
174
|
+
|
|
175
|
+
*Diagram source & regeneration: [docs/diagrams/](docs/diagrams/README.md). Pipeline as of v0.12 — the ASCII version below is the text-faithful equivalent.*
|
|
176
|
+
|
|
172
177
|
```
|
|
173
178
|
tool_call
|
|
174
179
|
│
|
package/README.zh-CN.md
CHANGED
|
@@ -6,44 +6,43 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/pi-verdict)
|
|
7
7
|
[](https://pi.dev)
|
|
8
8
|
|
|
9
|
-
**pi-verdict 是 [pi](https://pi.dev)
|
|
9
|
+
**pi-verdict 是 [pi](https://pi.dev) 的极简权限门禁,灵感来自 Claude Code 的 auto mode:每次工具调用执行前先过检查——放行、拦截,或先问你。**
|
|
10
10
|
|
|
11
|
-
-
|
|
11
|
+
- 极简——核心单文件约 2k 行(另含一个小型 jev 适配器)
|
|
12
12
|
- 内置危险规则与你的 allow/deny 规则以零延迟先行裁决明确情形
|
|
13
13
|
- 其余交给携带会话上下文的模型分类器
|
|
14
|
-
- 任何不确定或失败一律 fail-closed
|
|
15
|
-
-
|
|
14
|
+
- 任何不确定或失败一律 fail-closed,绝不静默放行
|
|
15
|
+
- 自保护:门禁守护自身,防窥探与篡改
|
|
16
16
|
|
|
17
17
|
## 问题
|
|
18
18
|
|
|
19
19
|
pi 没有内置的逐次权限确认——每次工具调用都以 pi 进程自身的权限直接执行([pi 安全文档](https://pi.dev/docs/latest/security))。
|
|
20
20
|
|
|
21
|
-
pi-verdict
|
|
21
|
+
pi-verdict 补上这道缺失的门禁,由模型基于上下文和你的意图判定是否可以运行。
|
|
22
22
|
|
|
23
23
|
## 为什么是三态
|
|
24
24
|
|
|
25
|
-
**verdict
|
|
25
|
+
**verdict 是裁决,不是开关。** 本品类的分类器大多只输出二值 allow/block。三态有意义的地方在:`ask` 把真正含糊的动作转交人类确认(非交互会话中降级为 `deny`),「不确定」永远不会静默变成「放行」——目标是安全的自动化而非最大的自动化:审批疲劳与静默危险执行都是败因。
|
|
26
26
|
|
|
27
27
|
## 设计原则
|
|
28
28
|
|
|
29
|
-
- **Fail closed
|
|
29
|
+
- **Fail closed**——不确定产生摩擦,绝不产生许可。
|
|
30
30
|
- **确定性 floor 先于 AI**——硬 deny 永不被分类器或用户 allow 规则覆盖。
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
- **最小化可信输入**——transcript 不含工具结果(#22)
|
|
34
|
-
- **规范化身份**——词法 + realpath
|
|
31
|
+
- **语义优先于语法**——分类器判定的是动作**做什么可能会产生什么安全影响**,而不是命令有多长。
|
|
32
|
+
- **是判断,不是证明**——分类器的 `allow` 是有依据的判断;floor 的存在正因 allow 仅是判断。
|
|
33
|
+
- **最小化可信输入**——transcript 不含工具结果(#22),分类器零路径明文(ADR-0002)。
|
|
34
|
+
- **规范化身份**——词法 + realpath 双形匹配;「看起来在项目内」的路径不因此被信任(#20/#21)。
|
|
35
35
|
- **门禁守护自身**——任何配置都关不掉的自保护层(ADR-0001)。
|
|
36
|
-
-
|
|
37
|
-
|
|
38
|
-
完整表述见 [docs/security-principles.md](docs/security-principles.md):
|
|
36
|
+
- **是权限门禁,不是沙箱**——请在上面叠加 OS 级隔离;本门禁不替代它。
|
|
39
37
|
|
|
38
|
+
完整表述见 [docs/security-principles.md](docs/security-principles.md)。
|
|
40
39
|
|
|
41
40
|
## 截图
|
|
42
41
|
|
|
43
|
-

|
|
44
43
|
|
|
45
|
-

|
|
46
|
-

|
|
44
|
+

|
|
45
|
+

|
|
47
46
|
|
|
48
47
|
## 快速开始
|
|
49
48
|
|
|
@@ -59,32 +58,34 @@ pi --extension ./extensions/pi-verdict.ts
|
|
|
59
58
|
|
|
60
59
|
```
|
|
61
60
|
|
|
61
|
+
需要 pi ≥ 0.84。交互与非交互(`-p`/json/rpc)会话均支持;非交互模式下 `ask` 降级为 `deny`。
|
|
62
|
+
|
|
62
63
|
### 宿主
|
|
63
64
|
|
|
64
|
-
pi-verdict 同时支持 [pi](https://github.com/badlogic/pi-mono) 与 [oh-my-pi](https://github.com/can1357/oh-my-pi)(omp)
|
|
65
|
+
pi-verdict 同时支持 [pi](https://github.com/badlogic/pi-mono) 与 [oh-my-pi](https://github.com/can1357/oh-my-pi)(omp)——扩展按自身安装位置自锚定到所在宿主的目录树,双宿主并存的机器上跟随扩展副本自身的位置。omp 18 下分类器的模型调用回退到 pi-ai compat API(仍然 fail-closed)。细节见 [docs/configuration.md](docs/configuration.md#host-notes-pi-and-oh-my-pi)。
|
|
65
66
|
|
|
66
67
|
| | pi | omp |
|
|
67
68
|
|---|---|---|
|
|
68
69
|
| 安装 | `pi install npm:pi-verdict` | `omp plugin install npm:pi-verdict` |
|
|
69
|
-
| 扩展副本 | `~/.pi/agent/extensions/` | `~/.omp/plugins/node_modules/pi-verdict/`(omp 18.1
|
|
70
|
+
| 扩展副本 | `~/.pi/agent/extensions/` | `~/.omp/plugins/node_modules/pi-verdict/`(omp 18.1+;≤18.0 在 `agent/` 下) |
|
|
70
71
|
| 用户规则 | `~/.pi/agent/config/pi-verdict.json` | `~/.omp/agent/config/pi-verdict.json` |
|
|
71
72
|
| 凭据文件(S0 硬 deny) | `~/.pi/agent/auth.json` | `~/.omp/agent/auth.json` |
|
|
72
73
|
|
|
73
|
-
- `/automode` ——
|
|
74
|
+
- `/automode` —— 显示当前状态:开/关
|
|
74
75
|
- `/automode on`
|
|
75
76
|
- `/automode off`
|
|
76
|
-
- `ctrl+shift+a` —— 静默切换主开关(footer
|
|
77
|
+
- `ctrl+shift+a` —— 静默切换主开关(footer 始终显示为唯一反馈;键位可经 `toggleShortcut` 重绑或禁用)
|
|
77
78
|
- footer 恒显 `auto mode on`(绿色)/ `auto mode off`(黄色)
|
|
78
79
|
|
|
79
80
|
| 配置 | 默认 | 说明 |
|
|
80
81
|
|---|---|---|
|
|
81
|
-
| `--auto-mode` / `--no-auto-mode` | 开 |
|
|
82
|
+
| `--auto-mode` / `--no-auto-mode` | 开 | 主开关 |
|
|
82
83
|
| `--auto-mode-model provider/id` | 会话模型 | 分类器模型(默认"自省") |
|
|
83
84
|
| `--auto-mode-debug` | 关 | 全量裁决通知 |
|
|
84
85
|
| `PI_AUTO_MODE_MODEL` | — | 模型配置的环境变量形式 |
|
|
85
86
|
| `PI_AUTO_MODE_DEBUG=1` | 关 | 调试的环境变量形式(flag 优先) |
|
|
86
87
|
|
|
87
|
-
### 用户自定义规则(
|
|
88
|
+
### 用户自定义规则(`pi-verdict.json`)
|
|
88
89
|
|
|
89
90
|
```json
|
|
90
91
|
{
|
|
@@ -116,43 +117,41 @@ pi-verdict 同时支持 [pi](https://github.com/badlogic/pi-mono) 与 [oh-my-pi]
|
|
|
116
117
|
}
|
|
117
118
|
```
|
|
118
119
|
|
|
119
|
-
- `allow`/`deny` 为 JS
|
|
120
|
-
- `denyPaths`
|
|
121
|
-
- `ignoreTools` 列出规则未覆盖的工具(`todo`、`web_search`、MCP/自定义工具)
|
|
122
|
-
- `builtinDenyFloor: false` 整体关闭内置危险/路径拦截(
|
|
123
|
-
- `classifierModel`
|
|
124
|
-
- `classifierModel: "typesafe/jev-latest"` 启用随包的 **jev 决策适配器**——灰区裁决经 TypeSafe jev 完成(默认 OpenRouter
|
|
125
|
-
- `audit: true` 把每次**灰区裁决**(发给分类器的完整转录、其原始响应、解析出的裁决)以 JSONL 记录到 `~/.pi/agent/verdicts/<sessionId>.jsonl
|
|
126
|
-
- `notifyAllows: true` 对每次 **classifier 放行**发通知(reason + action 行——如 jev 的概率分解)
|
|
127
|
-
- `classifierMinConfidence`(
|
|
120
|
+
- `allow`/`deny` 为 JS 正则数组;**`deny` 优先于 `allow`**,两者都优先于分类器
|
|
121
|
+
- `denyPaths` 是你声明**受保护**的普通路径列表:触碰触发**终局 ask** 由你裁决(非交互降级 deny);分类器只被告知路径**存在**,路径明文永不出本机。`grep`/`find`/`ls` 按**整个搜索范围**比较:省略 `path`(pi 默认:当前目录)或传入位于声明路径之上的父目录,同样触发 ask。全新安装会预填一份**入门列表**(`~/.ssh/`、`~/.gnupg`、`~/.mc`、shell rc/profile 文件)
|
|
122
|
+
- `ignoreTools` 列出规则未覆盖的工具(`todo`、`web_search`、MCP/自定义工具):**直接放行、零模型调用**;列出已覆盖工具(`bash`/`read`/`write`/`edit`/`grep`/`find`/`ls`/`powershell`)的条目无效:它们仍受 deny floor 与你的 allow/deny 规则约束,自保护层也永远先行。全新安装会预填一份**入门列表**(`todo`、`ask_user_question`、`memory_write`、`memory_search`——来自项目 1265 条生产审计的观察)。注意:被豁免的工具失去分类器对 `denyPaths` 的存在性话术警戒(未覆盖工具本就不进路径提取器)
|
|
123
|
+
- `builtinDenyFloor: false` 整体关闭内置危险/路径拦截(风险自担;下方自保护层永远开启)
|
|
124
|
+
- `classifierModel` 指定分类器模型,如 `"zai/glm-5.3-flash:low"`(支持思考后缀;缺省 = 会话模型且显式关思考)
|
|
125
|
+
- `classifierModel: "typesafe/jev-latest"` 启用随包的 **jev 决策适配器**——灰区裁决经 TypeSafe jev 完成(默认 OpenRouter,或 `PI_VERDICT_JEV_TRANSPORT=typesafe` 直连官方 API);实验性质,详见 [ADR-0003](docs/adr/0003-jev-decisions-adapter.md)
|
|
126
|
+
- `audit: true` 把每次**灰区裁决**(发给分类器的完整转录、其原始响应、解析出的裁决)以 JSONL 记录到 `~/.pi/agent/verdicts/<sessionId>.jsonl`——按会话一分文件,保留最近 20 个。交互式 ask 还会记录你的应答(`userAnswer` ground truth,确认结束后落盘),protected-path ask 也入审计(#62);规则 allow/deny 仍不入。仅存本机且全保真(受保护路径明文可能出现——永不出本机;[ADR-0002](docs/adr/0002-deny-paths-deterministic-ask.md) 边界注);agent 对该目录读写双拒。开启时 `/automode` 会显示审计状态与路径
|
|
127
|
+
- `notifyAllows: true` 对每次 **classifier 放行**发通知(reason + action 行——如 jev 的概率分解);默认 `false` 保持放行静默。机械放行(你自己的 allow 规则、protected-path 确认)永不通知;两开关同开时通知只出现一次
|
|
128
|
+
- `classifierMinConfidence`(可选,[ADR-0004](docs/adr/0004-classifier-fallback-cascade.md))设定**置信地板**:低于它的 jev 裁决被降级——配置了 `classifierFallbackModel` 则级联(`enforce`,默认 = 第二层全权裁决;例外:降级的 **deny 与 ask** 永不被自动放宽为 allow;fail-closed 未产生裁决,其获救裁决照常生效;`shadow` = 只记录意见、由你裁决——`/automode` 会提示激活开关),否则直接问你。不低于地板时第一层自主。地板仅作用于 decisions 模型——LLM 分类器下不生效,会有一次中性警告提示。天然搭配:jev 在前 + haiku/flash 级回退
|
|
128
129
|
|
|
129
|
-
没有内置白名单——每一条「永远放行」声明都归你([为什么](docs/configuration.md#why-no-built-in-allowlist))
|
|
130
|
+
没有内置白名单——每一条「永远放行」声明都归你([为什么](docs/configuration.md#why-no-built-in-allowlist))。完整参考:[docs/configuration.md](docs/configuration.md)。
|
|
130
131
|
|
|
131
132
|
### Jev 决策后端(实验性——[ADR-0003](docs/adr/0003-jev-decisions-adapter.md))
|
|
132
133
|
|
|
133
|
-
1. 安装含适配器的版本(
|
|
134
|
-
2. 选一条 transport(两条走同一 decisions wire 契约)
|
|
135
|
-
- **OpenRouter(默认)
|
|
136
|
-
- **TypeSafe 直连(官方 v1 API)
|
|
137
|
-
3.
|
|
134
|
+
1. 安装含适配器的版本(v0.8 及以上):`pi install npm:pi-verdict`
|
|
135
|
+
2. 选一条 transport(两条走同一 decisions wire 契约):
|
|
136
|
+
- **OpenRouter(默认)**:pi 内执行 `/login openrouter`,或 shell 里 `export OPENROUTER_API_KEY=sk-or-v1...`
|
|
137
|
+
- **TypeSafe 直连(官方 v1 API)**:在 console.typesafe.ai 自助发 key,然后 `export TYPESAFE_API_KEY=apikey_...` 并 `export PI_VERDICT_JEV_TRANSPORT=typesafe`
|
|
138
|
+
3. 将分类器指向 jev(新会话生效)
|
|
138
139
|
- 持久:在 pi 之外编辑 `~/.pi/agent/config/pi-verdict.json` 并设置 `{ "classifierModel": "typesafe/jev-latest" }`
|
|
139
|
-
-
|
|
140
|
+
- 或者临时试用一次:`PI_AUTO_MODE_MODEL=typesafe/jev-latest pi`
|
|
140
141
|
|
|
141
|
-
|
|
142
|
-
- **Transport
|
|
143
|
-
-
|
|
144
|
-
-
|
|
142
|
+
**限制**:
|
|
143
|
+
- **Transport**:OpenRouter decisions(默认)或 TypeSafe 直连——TypeSafe 侧单次成本显示 $0(其 API 不返回 cost)
|
|
144
|
+
- **宿主**:仅支持 pi。omp 上该设置会警告并回退会话模型。也绝不能选作会话主模型(不生成文本,选中即警告)
|
|
145
|
+
- **逃生口**:`PI_VERDICT_JEV_URL` 可覆盖当前 transport 的端点(OpenRouter 侧为 alpha 接口)
|
|
145
146
|
|
|
146
|
-
jev 的校准 confidence 正是置信地板的判定依据——搭配第二层使用(`"classifierMinConfidence", "classifierFallbackModel"`)
|
|
147
|
+
jev 的校准 confidence 正是置信地板的判定依据——搭配第二层使用(`"classifierMinConfidence", "classifierFallbackModel"`),让低置信调用交由更深的模型复裁,而非就地生效([ADR-0004](docs/adr/0004-classifier-fallback-cascade.md))。
|
|
147
148
|
|
|
148
149
|
### 自保护(门禁守护自身——[ADR-0001](docs/adr/0001-self-protection-layer.md))
|
|
149
150
|
|
|
150
|
-
|
|
151
|
+
门禁自身的文件——配置与扩展安装副本——**仅用户可改**:门禁之内的写入一律硬 deny(读放行);你的编辑器修改不经门禁,同类先例是 sudoers 必须经 visudo。
|
|
151
152
|
|
|
152
153
|
- **不可经任何配置关闭**——`builtinDenyFloor: false` 与用户 `allow` 规则都动不了这一层
|
|
153
|
-
-
|
|
154
|
-
|
|
155
|
-
需要 pi ≥ 0.84。交互与非交互(`-p`/json/rpc)会话均支持;非交互模式下 `ask` 降级为 `deny`。
|
|
154
|
+
- **变更检测**作纵深兜底:受保护文件在 `session_start` 快照、每次裁决前复核——扩展副本被改 → 自动还原 + 本会话 fail-closed;配置被改 → 有 UI 时一次明确的双选确认(无 UI 时与扩展副本同样自动还原;差分处置的完整语义见 [ADR-0001](docs/adr/0001-self-protection-layer.md))
|
|
156
155
|
|
|
157
156
|
---
|
|
158
157
|
|
|
@@ -160,16 +159,20 @@ jev 的校准 confidence 正是置信地板的判定依据——搭配第二层
|
|
|
160
159
|
|
|
161
160
|
| | 三态裁决 | 分类器携带上下文 | fail 方向 | 运行时依赖 |
|
|
162
161
|
|---|---|---|---|---|
|
|
163
|
-
| **pi-verdict** | ✅ allow / ask / deny | ✅ 近期用户意图 + 工具调用 | **closed**(异常/超时/违约 → deny
|
|
164
|
-
| [@czottmann/pi-automode](https://github.com/czottmann/pi-automode) |
|
|
162
|
+
| **pi-verdict** | ✅ allow / ask / deny | ✅ 近期用户意图 + 工具调用 | **closed**(异常/超时/违约 → deny;非交互 ask → deny) | **0** |
|
|
163
|
+
| [@czottmann/pi-automode](https://github.com/czottmann/pi-automode) | 规则三态,分类器二态 | ✅ 预算内裁剪的 transcript | closed | 1 |
|
|
165
164
|
| [@zhushanwen/pi-permission](https://www.npmjs.com/package/@zhushanwen/pi-permission) | ✅(outcome) | ❌ 单轮无上下文 | closed(→ ask) | 4 |
|
|
166
165
|
| [@gotgenes/pi-permission-system](https://github.com/gotgenes/pi-packages) | ✅ 纯确定性 | —(无内置分类器) | closed | 3 |
|
|
167
166
|
|
|
168
|
-
|
|
167
|
+
完整全景:[`research/pi-permission-landscape.md`](research/pi-permission-landscape.md) · 与最近架构亲缘的收敛分析:[`research/pi-automode-convergence.md`](research/pi-automode-convergence.md)。
|
|
168
|
+
|
|
169
|
+
诚实地说:pi-automode 与 pi-verdict 在**架构上已收敛**(deny floor → 用户规则 → 分类器,fail-closed——见收敛分析)。这里仍然不同的是:分类器能说 `ask`(运行时人工介入,而非仅由规则预声明)、内置 floor 可以关(`builtinDenyFloor`——用户主权)、任何配置都关不掉的自保护层([ADR-0001](docs/adr/0001-self-protection-layer.md)——门禁完整性)、零依赖的[可通读单文件](extensions/pi-verdict.ts)(仍刻意单文件)、以及测量的习惯——本仓库每个设计决策都有随库研究背书。
|
|
170
|
+
|
|
171
|
+
## 判定管线
|
|
169
172
|
|
|
170
|
-
|
|
173
|
+

|
|
171
174
|
|
|
172
|
-
|
|
175
|
+
*图源与再生成:[docs/diagrams/](docs/diagrams/README.md)。管线基准:v0.12——下方 ASCII 为文本等价版。*
|
|
173
176
|
|
|
174
177
|
```
|
|
175
178
|
tool_call
|
|
@@ -199,36 +202,36 @@ tool_call
|
|
|
199
202
|
|
|
200
203
|
```
|
|
201
204
|
|
|
202
|
-
**fail-closed
|
|
205
|
+
**fail-closed**:分类器异常 / 超时(25s)/ 输出违反契约 → 拦截,绝不静默放行。
|
|
203
206
|
|
|
204
|
-
##
|
|
207
|
+
## 证据驱动,不靠直觉
|
|
205
208
|
|
|
206
|
-
|
|
209
|
+
这里的设计决策以测量定案,实验记录随仓库发布:
|
|
207
210
|
|
|
208
|
-
- [`research/cache-sim`](research/cache-sim/README.md) —— 回放 1.2k+
|
|
209
|
-
- [`research/thinking-param-blackhole.md`](research/thinking-param-blackhole.md) ——
|
|
211
|
+
- [`research/cache-sim`](research/cache-sim/README.md) —— 回放 1.2k+ 条真实分类器裁决,实测裁决缓存命中率(**3.2%** → 缓存暂缓;其后建成的运行时影子遥测实测 **3.3%**,后来一并移除,#73)
|
|
212
|
+
- [`research/thinking-param-blackhole.md`](research/thinking-param-blackhole.md) —— 思考模型烧尽分类器预算的三层取证,以及为什么修复是 `thinkingEnabled: false`
|
|
210
213
|
- [`research/rule-engine-sim`](research/rule-engine-sim/README.md) —— 用 746 条真实 bash 调用实测 tree-sitter 规则引擎移植(**灰区吸收 0 条**)并否决
|
|
211
214
|
- [`research/pi-permission-landscape.md`](research/pi-permission-landscape.md) —— 本 README 定位所对照的竞品全景
|
|
212
215
|
- [`research/rule-layer-security-audit.md`](research/rule-layer-security-audit.md) —— 规则层绕过测试(8/8 复现 → 0.2.0 架构性修复)
|
|
213
216
|
- [`research/pi-automode-convergence.md`](research/pi-automode-convergence.md) —— 与 pi-automode 何处真正收敛、何处仍然不同
|
|
214
|
-
- [`research/claude-code-classifier-prompts.md`](research/claude-code-classifier-prompts.md) —— Claude Code 分类器设计的结构化还原(基于自托管 Langfuse 观测)
|
|
217
|
+
- [`research/claude-code-classifier-prompts.md`](research/claude-code-classifier-prompts.md) —— Claude Code 分类器设计的结构化还原(基于自托管 Langfuse 观测),本扩展 transcript 契约的承袭来源
|
|
215
218
|
|
|
216
219
|
## 状态与限制
|
|
217
220
|
|
|
218
|
-
- 设计上无内置白名单(见[绕过测试](research/rule-layer-security-audit.md)与[
|
|
219
|
-
- 路径敏感度 floor
|
|
221
|
+
- 设计上无内置白名单(见[绕过测试](research/rule-layer-security-audit.md)与[用户自定义规则](#用户自定义规则pi-verdictjson));allow 配置为空时大多数命令进分类器 —— 延迟敏感可 `--auto-mode-model` 指向轻量模型
|
|
222
|
+
- 路径敏感度 floor 只作用于文件类工具:bash 命令串仅匹配危险正则——`cat ~/.ssh/id_rsa` 走分类器而非确定性 S0 拦截(文件工具拼写 `read ~/.ssh/id_rsa` 会拦截)
|
|
220
223
|
- Windows 下内置 floor 仅覆盖 bash 形态模式——PowerShell 原生危险命令(`Remove-Item -Recurse -Force`、`Invoke-Expression`、`Set-ExecutionPolicy` 等)依赖分类器兜底(fail-closed)
|
|
221
224
|
- AGENTS.md 未作为降权意图证据传入分类器(Claude Code 有此设计)
|
|
222
225
|
- 并行灰区调用串行裁决
|
|
223
|
-
-
|
|
224
|
-
- `denyPaths` 的 bash 提取是 token 级([ADR-0002](docs/adr/0002-deny-paths-deterministic-ask.md))
|
|
225
|
-
- `denyPaths` 的 bash token
|
|
226
|
-
- 自保护 bash
|
|
226
|
+
- 自省意味着会话模型自身裁决 —— 若延迟/成本敏感,用 `--auto-mode-model` 指向轻量模型(开放问题见 issue tracker)
|
|
227
|
+
- `denyPaths` 的 bash 提取是 token 级([ADR-0002](docs/adr/0002-deny-paths-deterministic-ask.md)):命令替换、base64 内嵌路径、外部脚本内容不产生命中信号——这些调用回落到分类器的存在性话术警戒。MCP 与自定义工具完全绕过提取器(其灰区裁决仍带话术)。路径归一化亦为基础档(ADR-0002):经符号链接目录写入尚不存在的目标不重建真实形、不产生命中——该间接路径同样由话术警戒覆盖(祖先重建档只适用于自保护层与路径敏感度 floor,不适用 denyPaths)。诚实表述,与自保护子串正则同例:确定性层可被混淆——这正是命中交由**你**裁决而非静默决定的原因
|
|
228
|
+
- `denyPaths` 的 bash token 不含空格:**声明路径本身含空格时**,bash 拼写无法被提取器识别——`cat "/path with space/x"` 被拆成两个 token 永不命中(文件类工具仍命中,其路径不经 token 化)。glob 覆盖基名末段(`denyPaths: ["/proj/personal"]` 时 `cat /proj/pers*`)同样漏过——基名自身从未字面出现。经 shell 发起的递归搜索在两种拼写下都漏过——不带路径参数(默认搜 cwd,如裸 `rg foo`)或带父目录参数(`rg foo <声明路径的父目录>`):无参命令根本不产生 token,带参时 bash token 只做单向比较;同一形状经 `grep`/`find`/`ls` 工具发起则由双向子树比较覆盖。三个洞与上述替换/base64 一样回落到分类器的存在性话术
|
|
229
|
+
- 自保护 bash 匹配是子串正则——可被混淆绕过;变更检测兜底覆盖会话内绕过,跨会话基线(启动时哈希比对与变更确认,含升级 UX)按 ADR-0001 为二期
|
|
227
230
|
- dev checkout(从仓库而非 `<agentDir>/extensions/` 运行扩展)不受自保护——下一个正常会话加载的安装副本只在其自身会话的门禁内受保护
|
|
228
231
|
|
|
229
|
-
**verdict 不是沙箱。** 它在 pi
|
|
232
|
+
**verdict 不是沙箱。** 它在 pi 进程内裁决工具调用;不能遏制恶意代码、不能防护被攻陷的进程、不守护手工 `!` shell 逃逸。需要隔离请用操作系统级沙箱。
|
|
230
233
|
|
|
231
|
-
|
|
234
|
+
命名:三态**裁决(verdict)**是核心概念。UX 保留 `/automode` —— 模式概念上溯 Claude Code 的 auto mode,本项目亦借鉴了其 transcript 设计。
|
|
232
235
|
|
|
233
236
|
## 开发
|
|
234
237
|
|
|
@@ -195,6 +195,22 @@ export function parseJevConfidence(reason: string): number | null {
|
|
|
195
195
|
return m ? Number(m[1]) : null;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
/** #81: protocol identity — `api === API_ID` names the decisions protocol, the
|
|
199
|
+
* capability axis the extension actually gates on (numeric confidence is a
|
|
200
|
+
* decisions-contract property, not a vendor trait). Structural type so callers
|
|
201
|
+
* can pass any model-shaped object. */
|
|
202
|
+
export function isDecisionsModel(model: { api?: string }): boolean {
|
|
203
|
+
return model.api === API_ID;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** #81: exact match for the one decisions spec pi-verdict registers
|
|
207
|
+
* ("typesafe/jev-latest"). The registry only ever holds that one slug, so prefix
|
|
208
|
+
* tolerance would only ever catch typos — and would mislead with the jev-specific
|
|
209
|
+
* wording keyed on this predicate. */
|
|
210
|
+
export function isJevSpec(spec: string): boolean {
|
|
211
|
+
return spec === `${PROVIDER_ID}/${MODEL_ID}`;
|
|
212
|
+
}
|
|
213
|
+
|
|
198
214
|
function mapUsage(u: unknown): AssistantMessage["usage"] {
|
|
199
215
|
const usage = (u ?? {}) as { input_tokens?: unknown; output_tokens?: unknown; cost?: unknown };
|
|
200
216
|
const input = Number(usage.input_tokens) || 0;
|
package/extensions/pi-verdict.ts
CHANGED
|
@@ -86,7 +86,7 @@ import * as os from "node:os";
|
|
|
86
86
|
import * as path from "node:path";
|
|
87
87
|
import { fileURLToPath } from "node:url";
|
|
88
88
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
89
|
-
import { parseJevConfidence } from "./jev-adapter";
|
|
89
|
+
import { isDecisionsModel, isJevSpec, parseJevConfidence } from "./jev-adapter";
|
|
90
90
|
|
|
91
91
|
// ============================================================================
|
|
92
92
|
// 规则层:bash
|
|
@@ -1097,8 +1097,8 @@ interface ClassifierOutcome {
|
|
|
1097
1097
|
verdict: "allow" | "ask" | "deny";
|
|
1098
1098
|
reason: string;
|
|
1099
1099
|
source: "model" | "fail-closed";
|
|
1100
|
-
/** #54 audit material: the transcript actually sent and the last attempt's raw output (attached on both model and fail-closed outcomes) */
|
|
1101
|
-
auditRaw?: { transcript: string; rawResponse: string; modelId: string; thinking: ThinkingLevel };
|
|
1100
|
+
/** #54 audit material: the transcript actually sent and the last attempt's raw output (attached on both model and fail-closed outcomes); thinking is null for decisions models (#81) */
|
|
1101
|
+
auditRaw?: { transcript: string; rawResponse: string; modelId: string; thinking: ThinkingLevel | null };
|
|
1102
1102
|
}
|
|
1103
1103
|
|
|
1104
1104
|
const CLASSIFIER_TIMEOUT_MS = 25_000; // 本网关 CC 分类器分布 p90=19.8s(15s 会误杀 ~15%),research/cache-sim 数据
|
|
@@ -1273,6 +1273,9 @@ async function classifyWithModel(
|
|
|
1273
1273
|
const transcript = buildTranscript(host, actionLine);
|
|
1274
1274
|
const userMessage = `<transcript>\n${transcript}\n</transcript>\nJudge the LAST action in the transcript above. Your entire response MUST begin with <verdict>.`;
|
|
1275
1275
|
const systemPrompt = denyPathsActive ? CLASSIFIER_SYSTEM + DENY_PATHS_HINT : CLASSIFIER_SYSTEM;
|
|
1276
|
+
// #81: decisions models parse-then-drop the thinking suffix — the audit records
|
|
1277
|
+
// null, never the configured-but-inert level (LLM classifiers keep theirs)
|
|
1278
|
+
const auditThinking = isDecisionsModel(model) ? null : thinking;
|
|
1276
1279
|
const attempts: Array<[number, number]> = [[1, CLASSIFIER_MAX_TOKENS], [2, CLASSIFIER_RETRY_MAX_TOKENS]];
|
|
1277
1280
|
const failures: string[] = [];
|
|
1278
1281
|
let rawResponse = ""; // #54: raw output of the last attempt ("" for exception attempts — diagnostics already live in failures)
|
|
@@ -1284,7 +1287,7 @@ async function classifyWithModel(
|
|
|
1284
1287
|
const diag = `stopReason=${r.stopReason}, model=${model.id}, errorMessage=${JSON.stringify(r.errorMessage ?? null)}, raw output=${JSON.stringify(r.text.slice(0, 200))}`;
|
|
1285
1288
|
if (r.stopReason !== "error" && r.stopReason !== "aborted") {
|
|
1286
1289
|
const parsed = parseVerdict(r.text);
|
|
1287
|
-
if (parsed) return { ...parsed, source: "model", auditRaw: { transcript, rawResponse, modelId: model.id, thinking } };
|
|
1290
|
+
if (parsed) return { ...parsed, source: "model", auditRaw: { transcript, rawResponse, modelId: model.id, thinking: auditThinking } };
|
|
1288
1291
|
failures.push(`attempt ${n} (${maxTokens}t) contract violation: ${diag}`);
|
|
1289
1292
|
} else {
|
|
1290
1293
|
failures.push(`attempt ${n} (${maxTokens}t) aborted/errored: ${diag}`);
|
|
@@ -1293,7 +1296,7 @@ async function classifyWithModel(
|
|
|
1293
1296
|
failures.push(`attempt ${n} (${maxTokens}t) exception: ${r.error}`);
|
|
1294
1297
|
}
|
|
1295
1298
|
}
|
|
1296
|
-
return { verdict: "deny", reason: `classifier failure (fail-closed): ${failures.join("; ")}`, source: "fail-closed", auditRaw: { transcript, rawResponse, modelId: model.id, thinking } };
|
|
1299
|
+
return { verdict: "deny", reason: `classifier failure (fail-closed): ${failures.join("; ")}`, source: "fail-closed", auditRaw: { transcript, rawResponse, modelId: model.id, thinking: auditThinking } };
|
|
1297
1300
|
}
|
|
1298
1301
|
|
|
1299
1302
|
// ============================================================================
|
|
@@ -1539,9 +1542,12 @@ export interface AdjudicateEnv {
|
|
|
1539
1542
|
|
|
1540
1543
|
/** #67: the confidence floor. Below it the first layer abstains and the call cascades —
|
|
1541
1544
|
* to the fallback if configured, else to the human (headless degrades to deny). Numeric
|
|
1542
|
-
* confidence
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
+
* confidence is a decisions-protocol contract property (#81): demotion requires the
|
|
1546
|
+
* protocol identity (isDecisionsModel) AND a parseable segment — an LLM whose free-text
|
|
1547
|
+
* reason happens to match the jev format no longer demotes. LLM first layers gate on
|
|
1548
|
+
* ask/fail-closed only. */
|
|
1549
|
+
function confidenceDemotion(outcome: ClassifierOutcome, rules: UserRules, model: NonNullable<ExtensionContext["model"]>): { confidence: number } | null {
|
|
1550
|
+
if (rules.classifierMinConfidence === null || outcome.source === "fail-closed" || !isDecisionsModel(model)) return null;
|
|
1545
1551
|
const conf = parseJevConfidence(outcome.reason);
|
|
1546
1552
|
if (conf !== null && conf < rules.classifierMinConfidence) return { confidence: conf };
|
|
1547
1553
|
return null;
|
|
@@ -1694,7 +1700,7 @@ export async function adjudicate(
|
|
|
1694
1700
|
|
|
1695
1701
|
// #67 cascade: a confidence-floor demotion, or a classifier fail-closed outcome
|
|
1696
1702
|
// (the first layer produced no verdict)
|
|
1697
|
-
const demotion = confidenceDemotion(outcome, state.userRules);
|
|
1703
|
+
const demotion = confidenceDemotion(outcome, state.userRules, resolved.model);
|
|
1698
1704
|
const cascade = demotion || outcome.source === "fail-closed"
|
|
1699
1705
|
? await runConfidenceCascade(state, env, demotion ? { verdict: outcome.verdict, reason: outcome.reason } : null, demotion ? { kind: "demotion", confidence: demotion.confidence } : { kind: "fail-closed" }, state.userRules.denyPaths.length > 0, actionLine)
|
|
1700
1706
|
: {};
|
|
@@ -1891,6 +1897,9 @@ export default function autoMode(pi: ExtensionAPI, deps: AutoModeDeps = {}) {
|
|
|
1891
1897
|
});
|
|
1892
1898
|
|
|
1893
1899
|
let warnedClassifierModel = false;
|
|
1900
|
+
let warnedFloorInert = false;
|
|
1901
|
+
/** #81: per-layer one-shot for the jev thinking-suffix warning */
|
|
1902
|
+
const jevSuffixWarned = { classifier: false, fallback: false };
|
|
1894
1903
|
/** 思考级别集(pi 原生 EXTENDED_THINKING_LEVELS;后缀语法对齐 pi --model provider/id:thinking) */
|
|
1895
1904
|
const THINKING_LEVELS = new Set(["off", "minimal", "low", "medium", "high", "xhigh", "max"]);
|
|
1896
1905
|
|
|
@@ -1907,6 +1916,42 @@ export default function autoMode(pi: ExtensionAPI, deps: AutoModeDeps = {}) {
|
|
|
1907
1916
|
return { specPart: raw, level: null };
|
|
1908
1917
|
}
|
|
1909
1918
|
|
|
1919
|
+
/** #81: jev-specialized unavailable wording — the two real causes, instead of the
|
|
1920
|
+
* generic "not found or no configured auth", which points nowhere for jev. */
|
|
1921
|
+
const JEV_UNAVAILABLE_HINT =
|
|
1922
|
+
"jev needs a pi host with registerProvider (omp is not supported) and a key: OPENROUTER_API_KEY / OpenRouter login (default transport), or TYPESAFE_API_KEY (PI_VERDICT_JEV_TRANSPORT=typesafe)";
|
|
1923
|
+
|
|
1924
|
+
/** #81: shared spec→model resolution for both classifier layers — registry
|
|
1925
|
+
* lookup + auth check, plus the jev thinking-suffix warning fired only on the
|
|
1926
|
+
* resolved path: decisions models parse-then-drop the suffix, so "ignored" is
|
|
1927
|
+
* factually true exactly here. On the session-model fallback (unresolvable
|
|
1928
|
+
* spec) the suffix stays effective for the LLM and must not be called ignored.
|
|
1929
|
+
* Returns null when the spec does not resolve; the layer's fallback semantics
|
|
1930
|
+
* stay with the caller. */
|
|
1931
|
+
function findSpecModel(ctx: ExtensionContext, specPart: string, level: string | null, layer: "classifier" | "fallback"): NonNullable<ExtensionContext["model"]> | null {
|
|
1932
|
+
const slash = specPart.indexOf("/");
|
|
1933
|
+
if (slash <= 0) return null;
|
|
1934
|
+
const model = ctx.modelRegistry.find(specPart.slice(0, slash), specPart.slice(slash + 1));
|
|
1935
|
+
if (!model || !ctx.modelRegistry.hasConfiguredAuth(model)) return null;
|
|
1936
|
+
if (level !== null && isJevSpec(specPart) && !jevSuffixWarned[layer]) {
|
|
1937
|
+
jevSuffixWarned[layer] = true;
|
|
1938
|
+
ctx.ui.notify(`pi-verdict: thinking suffix "${level}" has no effect on a decisions model (${specPart} has no reasoning to configure) — ignored`, "warning");
|
|
1939
|
+
}
|
|
1940
|
+
return model;
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
/** #81: floor-inert — the confidence floor binds to decisions models, so a
|
|
1944
|
+
* non-decisions classifier silently ignores it. Surfaces once per session at the
|
|
1945
|
+
* first resolution (explicit model and self-reflection fallback alike; a purely
|
|
1946
|
+
* rule-adjudicated session never sees it — lazy via getModel). Neutral wording:
|
|
1947
|
+
* the fact, never a judgment on the config (users may pre-set the floor for a
|
|
1948
|
+
* future jev switch). */
|
|
1949
|
+
function warnFloorInert(ctx: ExtensionContext, model: NonNullable<ExtensionContext["model"]>): void {
|
|
1950
|
+
if (warnedFloorInert || state.userRules.classifierMinConfidence === null || isDecisionsModel(model)) return;
|
|
1951
|
+
warnedFloorInert = true;
|
|
1952
|
+
ctx.ui.notify("pi-verdict: classifierMinConfidence has no effect on a non-decisions classifier (the floor applies to decisions models like typesafe/jev-latest)", "warning");
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1910
1955
|
/** 解析分类器模型与思考级别:CLI flag > 环境变量 > 配置文件(classifierModel) >
|
|
1911
1956
|
* 自省(会话模型)。不可用回退会话模型并警告一次;null = 连会话模型都没有 →
|
|
1912
1957
|
* fail-closed。经 AdjudicateEnv.getModel 惰性调用(仅灰区),回退警告不会出现在
|
|
@@ -1922,18 +1967,27 @@ export default function autoMode(pi: ExtensionAPI, deps: AutoModeDeps = {}) {
|
|
|
1922
1967
|
ctx.ui.notify(msg, "warning");
|
|
1923
1968
|
});
|
|
1924
1969
|
thinking = (level ?? "off") as ThinkingLevel;
|
|
1925
|
-
const
|
|
1926
|
-
if (
|
|
1927
|
-
|
|
1928
|
-
|
|
1970
|
+
const model = findSpecModel(ctx, specPart, level, "classifier");
|
|
1971
|
+
if (model) {
|
|
1972
|
+
warnFloorInert(ctx, model);
|
|
1973
|
+
return { model, thinking };
|
|
1929
1974
|
}
|
|
1930
1975
|
if (!warnedClassifierModel) {
|
|
1931
1976
|
warnedClassifierModel = true; // 每会话仅警告一次,避免逐调用刷屏
|
|
1932
|
-
ctx.ui.notify(
|
|
1977
|
+
ctx.ui.notify(
|
|
1978
|
+
isJevSpec(specPart)
|
|
1979
|
+
? `pi-verdict: classifier model "${raw}" unavailable — ${JEV_UNAVAILABLE_HINT}; falling back to session model (self-reflection)`
|
|
1980
|
+
: `pi-verdict: classifier model "${raw}" unavailable (not found or no configured auth), falling back to session model (self-reflection)`,
|
|
1981
|
+
"warning",
|
|
1982
|
+
);
|
|
1933
1983
|
}
|
|
1934
1984
|
}
|
|
1935
1985
|
// 自省:继承当前会话模型;显式指定的思考级别在回退时仍生效(原语义)
|
|
1936
|
-
|
|
1986
|
+
if (ctx.model) {
|
|
1987
|
+
warnFloorInert(ctx, ctx.model);
|
|
1988
|
+
return { model: ctx.model, thinking };
|
|
1989
|
+
}
|
|
1990
|
+
return null;
|
|
1937
1991
|
}
|
|
1938
1992
|
|
|
1939
1993
|
let warnedFallbackSuffix = false;
|
|
@@ -1952,14 +2006,16 @@ export default function autoMode(pi: ExtensionAPI, deps: AutoModeDeps = {}) {
|
|
|
1952
2006
|
ctx.ui.notify(msg, "warning");
|
|
1953
2007
|
});
|
|
1954
2008
|
const thinking = (level ?? "off") as ThinkingLevel;
|
|
1955
|
-
const
|
|
1956
|
-
if (
|
|
1957
|
-
const model = ctx.modelRegistry.find(specPart.slice(0, slash), specPart.slice(slash + 1));
|
|
1958
|
-
if (model && ctx.modelRegistry.hasConfiguredAuth(model)) return { model, thinking };
|
|
1959
|
-
}
|
|
2009
|
+
const model = findSpecModel(ctx, specPart, level, "fallback");
|
|
2010
|
+
if (model) return { model, thinking };
|
|
1960
2011
|
if (!warnedFallbackModel) {
|
|
1961
2012
|
warnedFallbackModel = true; // one warning per session
|
|
1962
|
-
ctx.ui.notify(
|
|
2013
|
+
ctx.ui.notify(
|
|
2014
|
+
isJevSpec(specPart)
|
|
2015
|
+
? `pi-verdict: fallback model "${raw}" unavailable — ${JEV_UNAVAILABLE_HINT} — classifierFallbackModel inactive this session`
|
|
2016
|
+
: `pi-verdict: fallback model "${raw}" unavailable (not found or no configured auth) — classifierFallbackModel inactive this session`,
|
|
2017
|
+
"warning",
|
|
2018
|
+
);
|
|
1963
2019
|
}
|
|
1964
2020
|
return null;
|
|
1965
2021
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-verdict",
|
|
3
|
-
"version": "0.12.
|
|
4
|
-
"description": "A minimal permission gate for Pi
|
|
3
|
+
"version": "0.12.1",
|
|
4
|
+
"description": "A minimal permission gate for Pi, inspired by Claude Code's auto mode",
|
|
5
5
|
"author": "Jesset (https://github.com/jesset)",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "extensions/pi-verdict.ts",
|