clearai-dsh 0.5.5 → 0.5.6

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
@@ -2,6 +2,31 @@
2
2
 
3
3
  All notable changes to this project are recorded here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
4
 
5
+ ## [0.5.6] — 2026-10-19
6
+
7
+ **适配 DSH 0.2.1:独立评估者在新宿主上重新派得出去,且仍然只读(issue #38);交给评估者的材料有了体积闸门(issue #36),复跑副本能被认出是副本(issue #35);另补上递归删除闸门的几处绕过。**
8
+
9
+ DSH 0.2.1-alpha.2 把 `subagents.start(provider, request)` 换成了 `startActivation(spec)`,而 `engines.dsh` 拦不住新宿主:装得上、跑得起,直到第一次派评估者才以 `audit_dispatch_failed` 失败,结案与 L3+ 交付都过不去。桌面版 0.2.1-rc.2 正是这一代。
10
+
11
+ ### Fixed
12
+
13
+ - **评估者在 0.2.1 上派得出去**(issue #38,报告者 devil233-ui):内核按方法是否存在选入口——有 `start` 走旧路径(逐次请求给 persona / toolFilter),只有 `startActivation` 时以 `agentPreset: 'clearai-evaluator'`、`delivery: 'caller'` 派遣;回包统一成 `{ id, result, dispose }`,账本、目录对账与落定照旧。两个入口都不在时,挂载那一刻就警告,派遣时 fail-closed 并点名原因。
14
+ - **新宿主上评估者仍然只读**:0.2.1 的 `startActivation` 会**静默丢掉**请求里的 `persona` / `toolFilter`。照旧塞进请求而不选预设,评估者会加入主会话的 ClearAI 组合,拿到写工具与主人格(issue 里的临时补丁正是这样)。所以新增随包的评估者预设 `clearai-evaluator`:只读文件面(`tool-fs` 关掉 `write` / `edit`)、搜索、shell 与后台任务;再由 `clearai-evaluator-face` 把宿主全局层继承下来的工具(`write` / `edit` / `subagent` / `web_*` / goal 工具……)从工具清单里遮掉,并在执行处用 guard 拦住白名单外的调用。评估者的工具面与旧入口 `toolFilter` 给的是同一张表。
15
+ - **递归删除闸门的绕过**:pwsh 与 bash 两条规则从前只查命令里**第一段**删除(`Remove-Item a; Remove-Item -Recurse C:\`、`rm a; rm -rf ~` 都能过);pwsh 一条还把 `-Force` 当成递归,认不出 `C:/`、`$env:SystemRoot` 与 `{ … }` 里的命令。现在逐段查,认 pwsh 别名(`ri / rm / rd / del / erase`)与 `-recurse` 的缩写;提权规则不区分大小写。
16
+ - `.gitattributes` 开头的 BOM 让 git 把第一行注释读成无效属性(`is not a valid attribute name`)。
17
+
18
+ ### Added
19
+
20
+ - **评估材料体积闸门**(issue #36,报告者 GameKingdomNatives):L3+ 交付随交付带给评估者的未解释项(`anomalies`)有了上限——每次至多 4 条、每条至多 400 字,可用预设配置 `auditMaterialLimits: { anomalies, anomalyChars }` 调整,写错在装配期就抛错。超限**拒绝而不截断**(从前单条超过 400 字是静默截断),在落账之前拒,被拒的这一批不留记录,也不算连拦;拒因写明超了多少、怎么压(同源合并,读数与推导写进产物文件)。只量 `anomalies`:observations 的 note 与 `basis` 并不进评估者的任务书(`basis` 只用于 L2 自判),限它们减不了评估者的负担。
21
+ - **复跑副本做了记号**(issue #35,报告者 GameKingdomNatives):副本根目录写一份 `.clearai-rerun.json`(原工作区与副本路径、用途),原工作区不写;任务书告诉评估者这是一次性副本,并提醒复跑可能写进被检程序按项目名定位的全局用户数据目录、有改道约定先改道、没有就在裁决里写明可能写到了哪里。项目可在工作区根声明 `.clearai-rerun-env`(每行 `KEY=VALUE`,`{copy}` 换成副本路径),变量随记号写下并列进任务书,评估者复跑前先设上。内核**不**关闭被检项目的采集:评估者要核的数字可能正是采集出来的。
22
+
23
+ ### Tests
24
+
25
+ - 模拟宿主可扮演两代子代理入口;`test/run.sh` 把整套内核用例在 `startActivation` 上再跑一遍(两遍各 700/0)。新增评估者工具面插件、两代入口都不在、删除规则绕过与误伤、评估材料闸门(超限拒绝不落账、刚好在限内放行、上限可调、配置写错抛错、L2 不受限)、复跑记号与项目声明变量的用例。
26
+ - `verify-clean-install` 多一项:名册里 `clearai-evaluator` 在场且没有 broken。DSH 0.2.1-rc.2 与 0.2.0-rc.2 上干净安装均 23/0。
27
+ - 桌面版 DSH 0.2.1-rc.2 上的真实评估(`tools/native-headless/audit-wait-probe.mjs`):评估者派出、裁决回到内核、目标 `achieved`;评估者子会话的工具面为 `read, read_image, glob, grep, bash, job_output, job_list, job_kill, structured_output`,主会话不受影响。
28
+ - `tools/native-headless` 增加两个显式开关:`CLEARAI_NATIVE_RUNTIME`(在预注册的 0.2.0-rc.2 之外的宿主上跑兼容性检查,并记入安装记录)与 `CLEARAI_NATIVE_PASS_ENV`(按名转发模型密钥这类环境变量;缺省仍是白名单)。
29
+
5
30
  ## [0.5.5] — 2026-10-14
6
31
 
7
32
  **Windows 上的硬边界、证据落盘与自检全部补齐;另按社区 issue #33 / #34 做了能做的那部分加固。**
package/README.md CHANGED
@@ -22,8 +22,8 @@ ClearAI is an **ontology discovery and exploration platform**, built on two core
22
22
 
23
23
  ```bash
24
24
  # Install (npm package, prebuilt — no build step, no allowBuilds prompt)
25
- dsh plugin --profile web add clearai-dsh@0.5.5
26
- # or in the app: Plugins → Add plugin → clearai-dsh@0.5.5
25
+ dsh plugin --profile web add clearai-dsh@0.5.6
26
+ # or in the app: Plugins → Add plugin → clearai-dsh@0.5.6
27
27
  ```
28
28
 
29
29
  Restart `dsh web`, then pick **ClearAI** in the preset picker at the top of a new session. That is the whole setup. [Full install notes ↓](#install-and-use)
@@ -86,12 +86,12 @@ ClearAI does **not** claim recursive self-improvement. It provides the epistemic
86
86
 
87
87
  **Recommended — install it in the app, with the version pinned:**
88
88
 
89
- In the sidebar open **Plugins → Add plugin**, enter `clearai-dsh@0.5.5`, and install. That is DSH's own plugin manager: it hands what you type to pnpm, checks that the package declares a bundle and is compatible with this host, and applies it live. (The Settings page **插件列表 / Plugins** is the read-only inventory — installing happens on the sidebar's Plugins page.)
89
+ In the sidebar open **Plugins → Add plugin**, enter `clearai-dsh@0.5.6`, and install. That is DSH's own plugin manager: it hands what you type to pnpm, checks that the package declares a bundle and is compatible with this host, and applies it live. (The Settings page **插件列表 / Plugins** is the read-only inventory — installing happens on the sidebar's Plugins page.)
90
90
 
91
91
  **Or from a terminal — the same install:**
92
92
 
93
93
  ```bash
94
- dsh plugin --profile web add clearai-dsh@0.5.5
94
+ dsh plugin --profile web add clearai-dsh@0.5.6
95
95
  ```
96
96
 
97
97
  This installs the prebuilt package from the npm registry. Nothing is compiled on your machine, so there is no `allowBuilds` grant to approve — the plugin is ready the moment the command returns.
package/README.zh-CN.md CHANGED
@@ -22,8 +22,8 @@ ClearAI 是一个**本体发现与探索平台**,核心由两个概念支撑
22
22
 
23
23
  ```bash
24
24
  # 安装(npm 包,预构建——无需构建步骤,不会触发 allowBuilds 授权)
25
- dsh plugin --profile web add clearai-dsh@0.5.5
26
- # 或在应用里:侧栏「插件」→ 添加插件 → clearai-dsh@0.5.5
25
+ dsh plugin --profile web add clearai-dsh@0.5.6
26
+ # 或在应用里:侧栏「插件」→ 添加插件 → clearai-dsh@0.5.6
27
27
  ```
28
28
 
29
29
  重启 `dsh web`,在新建会话顶部的模式选择器里选 **ClearAI** 即可。这就是全部步骤。[完整安装说明 ↓](#安装与使用)
@@ -86,12 +86,12 @@ ClearAI **不**声称递归自我改进。它提供的是自我改进系统所
86
86
 
87
87
  **推荐——在应用里装,并把版本钉住:**
88
88
 
89
- 侧栏打开**「插件」→ 添加插件**,填 `clearai-dsh@0.5.5`,安装。这就是 DSH 自己的插件管理器:它把你填的东西交给 pnpm,校验这个包声明了组合包、与当前宿主兼容,然后当场生效。(设置里的**插件列表**是**只读清单**;安装入口在侧栏那个「插件」页。)
89
+ 侧栏打开**「插件」→ 添加插件**,填 `clearai-dsh@0.5.6`,安装。这就是 DSH 自己的插件管理器:它把你填的东西交给 pnpm,校验这个包声明了组合包、与当前宿主兼容,然后当场生效。(设置里的**插件列表**是**只读清单**;安装入口在侧栏那个「插件」页。)
90
90
 
91
91
  **或者开终端——同一次安装:**
92
92
 
93
93
  ```bash
94
- dsh plugin --profile web add clearai-dsh@0.5.5
94
+ dsh plugin --profile web add clearai-dsh@0.5.6
95
95
  ```
96
96
 
97
97
  从 npm registry 装预构建产物。本机不跑任何编译,因此不需要批准 `allowBuilds` 授权——命令返回时插件就已经可用。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clearai-dsh",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "ClearAI: an ontology-first DSH agent preset — evidence-checked research that grows into a domain ontology.",
5
5
  "type": "module",
6
6
  "private": false,
@@ -328,3 +328,89 @@
328
328
  # 产不出一条 clearai 变更。「不挂」当年防的是「自己派一个来判自己」——评估者的派遣
329
329
  # 在内核里(auditProvider),与模型面的 subagent 是两层;后者派出去的只是干活的,
330
330
  # 它的结论要进账本,只能回到主线过观测准入。
331
+
332
+ - id: preset-clearai-evaluator
333
+ name: '@deepseek-ai/dsh-agent-preset'
334
+ config:
335
+ id: clearai-evaluator
336
+ name: ClearAI 评估者 · Evaluator
337
+ description: |-
338
+ 由 ClearAI 内核派出的只读独立评估者,不用于直接对话。Read-only evaluator dispatched by ClearAI; not for direct chat.
339
+ order: 90
340
+ plugins:
341
+ # The `clearai-evaluator` agent preset:ClearAI 内核派出的**独立评估者**用的组合。
342
+ #
343
+ # 为什么要有这一份(issue #38):宿主 ≥0.2.1-alpha.2 的 `subagents.startActivation` 不再接受
344
+ # 逐次请求的 persona / toolFilter —— 本地子会话的人格与工具面**只由所选预设决定**。
345
+ # 不选预设,评估者就加入父会话的 ClearAI 组合:拿到写工具和 ClearAI 自己的工具,读到主人格。
346
+ # 所以评估者改用这一份组合:身份、只读的文件面由「挂了哪些行」决定;
347
+ # 宿主全局层继承下来的工具由下面的 clearai-evaluator-face 遮掉并在执行处拦住。
348
+ #
349
+ # 旧宿主(仍有 `subagents.start`)上内核走逐次请求的 toolFilter,这一份预设不被用到。
350
+ #
351
+ # 名册没有「隐藏」开关,这一份会出现在预设选择器里;名字和介绍都写明它不用于直接对话。
352
+ # 由 tools/build-package.mjs 装配成 `presets/clearai/clearai.patch.yml` 里的第二条声明行。
353
+
354
+ # ── 身份 ────────────────────────────────────────────────────────────────────
355
+
356
+ # 评估纪律在任务书里(内核 `evaluatorPrompt` 的第一段,跟着人说话的语言走);这里只说身份。
357
+ # 同主预设一样,不写 `{{…}}` 模板变量(issue #34)。
358
+ - id: persona
359
+ name: '@deepseek-ai/dsh-persona'
360
+ config:
361
+ prefix: '你是 ClearAI 派出的独立评估者:只核对,不做方案,不改原工作区。怎么判见任务书。You are the independent evaluator dispatched by ClearAI: verify only, do not redo the work, do not modify the original workspace. The brief says how to judge.'
362
+
363
+ # ── 只读文件面 ──────────────────────────────────────────────────────────────
364
+
365
+ # 只开读:`write` / `edit` 关掉,工具注册表里就没有它们(不是挂上再拦)。
366
+ # `read_image` 照旧随 `attachments` 在场与否(看图也是读)。
367
+ - id: tool-fs
368
+ name: '@deepseek-ai/dsh-tool-fs'
369
+ config:
370
+ write: false
371
+ edit: false
372
+
373
+ - id: tool-fs-search
374
+ name: '@deepseek-ai/dsh-tool-fs-search'
375
+ config:
376
+ sampleOverCapGlobResults: false
377
+
378
+ # ── 复跑 ────────────────────────────────────────────────────────────────────
379
+
380
+ # 复跑在工作区副本里进行(内核 `rerunCopy`,不含 `clear/`);任务书写明原工作区只读,
381
+ # 评估期间产物被改动过,内核按 `evaluator_touched_outputs` 不认这份裁决。
382
+ - id: tool-bash
383
+ name: '@deepseek-ai/dsh-tool-bash'
384
+ disabled: !!js process.platform === 'win32'
385
+
386
+ - id: tool-pwsh
387
+ name: '@deepseek-ai/dsh-tool-pwsh'
388
+ disabled: !!js process.platform !== 'win32'
389
+
390
+ # 命令转后台 job 时,评估者要能收取 / 取消自己的任务。
391
+ - id: tool-jobs
392
+ name: '@deepseek-ai/dsh-tool-jobs'
393
+
394
+ # ── 工具面 ──────────────────────────────────────────────────────────────────
395
+
396
+ # 只换预设不够:宿主 profile 在全局层注册的工具(write / edit / subagent / web_* / goal……)
397
+ # 每个 agent 都继承得到:不遮这一层,评估者照样拿得到 write 与 edit。
398
+ # 这一行把继承来的全局工具按白名单遮掉,并在执行处再拦一道。白名单与旧入口的 toolFilter 同一张。
399
+ - id: clearai-evaluator-face
400
+ name: 'clearai-dsh/presets/clearai/plugins/clearai-evaluator-face.js'
401
+ config:
402
+ allow:
403
+ - read
404
+ - read_image
405
+ - glob
406
+ - grep
407
+ - bash
408
+ - pwsh
409
+ - job_output
410
+ - job_list
411
+ - job_kill
412
+
413
+ # ── 刻意不挂的行 ────────────────────────────────────────────────────────────
414
+ #
415
+ # · ClearAI 内核:评估者不立题、不推进、不结案;它的裁决经结构化回包回到父会话的内核。
416
+ # · 子代理 / workflow / ralph / ask-user / web:判的人不再派人,也不找人问。
@@ -0,0 +1,76 @@
1
+ # The `clearai-evaluator` agent preset:ClearAI 内核派出的**独立评估者**用的组合。
2
+ #
3
+ # 为什么要有这一份(issue #38):宿主 ≥0.2.1-alpha.2 的 `subagents.startActivation` 不再接受
4
+ # 逐次请求的 persona / toolFilter —— 本地子会话的人格与工具面**只由所选预设决定**。
5
+ # 不选预设,评估者就加入父会话的 ClearAI 组合:拿到写工具和 ClearAI 自己的工具,读到主人格。
6
+ # 所以评估者改用这一份组合:身份、只读的文件面由「挂了哪些行」决定;
7
+ # 宿主全局层继承下来的工具由下面的 clearai-evaluator-face 遮掉并在执行处拦住。
8
+ #
9
+ # 旧宿主(仍有 `subagents.start`)上内核走逐次请求的 toolFilter,这一份预设不被用到。
10
+ #
11
+ # 名册没有「隐藏」开关,这一份会出现在预设选择器里;名字和介绍都写明它不用于直接对话。
12
+ # 由 tools/build-package.mjs 装配成 `presets/clearai/clearai.patch.yml` 里的第二条声明行。
13
+
14
+ # ── 身份 ────────────────────────────────────────────────────────────────────
15
+
16
+ # 评估纪律在任务书里(内核 `evaluatorPrompt` 的第一段,跟着人说话的语言走);这里只说身份。
17
+ # 同主预设一样,不写 `{{…}}` 模板变量(issue #34)。
18
+ - id: persona
19
+ name: '@deepseek-ai/dsh-persona'
20
+ config:
21
+ prefix: '你是 ClearAI 派出的独立评估者:只核对,不做方案,不改原工作区。怎么判见任务书。You are the independent evaluator dispatched by ClearAI: verify only, do not redo the work, do not modify the original workspace. The brief says how to judge.'
22
+
23
+ # ── 只读文件面 ──────────────────────────────────────────────────────────────
24
+
25
+ # 只开读:`write` / `edit` 关掉,工具注册表里就没有它们(不是挂上再拦)。
26
+ # `read_image` 照旧随 `attachments` 在场与否(看图也是读)。
27
+ - id: tool-fs
28
+ name: '@deepseek-ai/dsh-tool-fs'
29
+ config:
30
+ write: false
31
+ edit: false
32
+
33
+ - id: tool-fs-search
34
+ name: '@deepseek-ai/dsh-tool-fs-search'
35
+ config:
36
+ sampleOverCapGlobResults: false
37
+
38
+ # ── 复跑 ────────────────────────────────────────────────────────────────────
39
+
40
+ # 复跑在工作区副本里进行(内核 `rerunCopy`,不含 `clear/`);任务书写明原工作区只读,
41
+ # 评估期间产物被改动过,内核按 `evaluator_touched_outputs` 不认这份裁决。
42
+ - id: tool-bash
43
+ name: '@deepseek-ai/dsh-tool-bash'
44
+ disabled: !!js process.platform === 'win32'
45
+
46
+ - id: tool-pwsh
47
+ name: '@deepseek-ai/dsh-tool-pwsh'
48
+ disabled: !!js process.platform !== 'win32'
49
+
50
+ # 命令转后台 job 时,评估者要能收取 / 取消自己的任务。
51
+ - id: tool-jobs
52
+ name: '@deepseek-ai/dsh-tool-jobs'
53
+
54
+ # ── 工具面 ──────────────────────────────────────────────────────────────────
55
+
56
+ # 只换预设不够:宿主 profile 在全局层注册的工具(write / edit / subagent / web_* / goal……)
57
+ # 每个 agent 都继承得到:不遮这一层,评估者照样拿得到 write 与 edit。
58
+ # 这一行把继承来的全局工具按白名单遮掉,并在执行处再拦一道。白名单与旧入口的 toolFilter 同一张。
59
+ - id: clearai-evaluator-face
60
+ name: 'clearai-dsh/presets/clearai/plugins/clearai-evaluator-face.js'
61
+ config:
62
+ allow:
63
+ - read
64
+ - read_image
65
+ - glob
66
+ - grep
67
+ - bash
68
+ - pwsh
69
+ - job_output
70
+ - job_list
71
+ - job_kill
72
+
73
+ # ── 刻意不挂的行 ────────────────────────────────────────────────────────────
74
+ #
75
+ # · ClearAI 内核:评估者不立题、不推进、不结案;它的裁决经结构化回包回到父会话的内核。
76
+ # · 子代理 / workflow / ralph / ask-user / web:判的人不再派人,也不找人问。
@@ -0,0 +1,60 @@
1
+ /**
2
+ * clearai-evaluator-face —— 独立评估者的**工具面**(只挂在 `clearai-evaluator` 预设里)。
3
+ *
4
+ * 为什么要它(issue #38,宿主 ≥0.2.1-alpha.2):`startActivation` 不再接受逐次请求的
5
+ * toolFilter,评估者预设又只能决定「自己挂了哪些行」。可宿主 profile 在**全局层**注册的工具
6
+ * (`write` / `edit` / `subagent` / `workflow` / `web_*` / goal 工具……)每个 agent 都继承得到 ——
7
+ * 只换预设,评估者照样拿得到写工具。旧入口的 toolFilter 遮的正是这一层。
8
+ *
9
+ * 两道,缺一不可:
10
+ * · **可见面**:`tools.restrict({ deny })` 把白名单外的全局工具从评估者的工具清单里拿掉,
11
+ * 模型看不见就不会去试。restriction 遮的是 agent 继承来的面(全局 + 祖先层),
12
+ * 预设层对评估者是祖先,所以这里只能 deny 具体名字,不能 allow —— allow 会连本预设挂的 read 一起遮掉。
13
+ * · **硬边界**:`tools.guard` 拒绝白名单外的一切执行。guard 单调(别的 guard 放行不了它拒的),
14
+ * 也兜住挂载之后才注册进来的全局工具 —— deny 名单只认得挂载那一刻的名字。
15
+ *
16
+ * 白名单与旧入口的 toolFilter 同一张:read / read_image / glob / grep + 复跑用的 shell 与后台任务;
17
+ * `structured_output` 是宿主挂在评估者自己层上的回包通道,不在继承面里,但执行要经过 guard,所以列上。
18
+ */
19
+
20
+ export const name = 'clearai-evaluator-face'
21
+ export const inject = ['tools']
22
+
23
+ const PRESET_ID = 'clearai-evaluator'
24
+ /** `run_code` 是 PTC 模式的呈现通道(里面的每次调用仍按原名过 guard),不是一件能力。 */
25
+ const ALWAYS = ['structured_output', 'run_code']
26
+
27
+ export function apply(ctx, config = {}) {
28
+ const allow = new Set([...(Array.isArray(config.allow) ? config.allow : []), ...ALWAYS])
29
+ if (allow.size === ALWAYS.length) throw new Error('clearai-evaluator-face: config.allow must list the evaluator tools')
30
+ const tools = ctx.tools
31
+
32
+ /**
33
+ * 只管评估者自己。restriction / guard 注册在预设作用域里,本来就只覆盖加入这个预设的 agent;
34
+ * 若宿主把这一层当成全局(作用域判断变了),再按 agent 实际加入的预设核一遍,绝不误伤主会话。
35
+ */
36
+ let scoped = true
37
+ const presets = () => {
38
+ try { return ctx.get('agentPresets') } catch { return undefined }
39
+ }
40
+ const isEvaluator = (agent) => {
41
+ if (scoped) return true
42
+ const composed = agent?.ctx === undefined ? undefined : presets()?.composedPreset?.(agent.ctx)
43
+ return composed === PRESET_ID
44
+ }
45
+
46
+ try {
47
+ const inherited = [...(tools.view?.(undefined)?.restrictableNames ?? [])]
48
+ const deny = inherited.filter((toolName) => !allow.has(toolName) && toolName !== 'run_code')
49
+ if (deny.length > 0) tools.restrict({ deny })
50
+ } catch (error) {
51
+ const message = String(error?.message ?? error)
52
+ if (/scoped context/.test(message)) scoped = false
53
+ ctx.logger?.warn?.(`clearai-evaluator-face: could not hide inherited tools (${message.slice(0, 160)}); the execution guard still applies`)
54
+ }
55
+
56
+ tools.guard((exec) => {
57
+ if (allow.has(exec?.name) || !isEvaluator(exec?.agent)) return undefined
58
+ return `The ClearAI evaluator is read-only: "${exec?.name}" is outside its tool face (${[...allow].join(', ')}). Verify with the allowed tools and report the limitation in the verdict.`
59
+ })
60
+ }
@@ -90,6 +90,12 @@ const canonicalVerdict = (value) => {
90
90
  }
91
91
  /** 自判等级上限:L0–L2 可自判,L3 以上拒绝。 */
92
92
  const SELF_JUDGE_MAX_INDEX = 2
93
+ /**
94
+ * 一次 L3+ 交付随交付带给评估者的未解释项上限(issue #36)。
95
+ * 评估者的任务书里,这次交付由做的人决定的那一份就是 `anomalies`(observations 的 note 与 basis 不进任务书);
96
+ * 0.5.4 起评估者不再被硬取消,材料体积是剩下的那道刹车。超限**拒绝而不截断**:截断会让做的人以为都送到了。
97
+ */
98
+ const AUDIT_MATERIAL_LIMITS = { anomalies: 4, anomalyChars: 400 }
93
99
  /**
94
100
  * **给模型选的只有三档**:L2 自判、L3 独立评估、L4 人放行。L0 / L1 / L2 的细分从没改变过谁来判
95
101
  * (模型一律自标 L1/L2),所以合并成「自判」:旧账照旧读(界面一律说「自判」),新写的 L0 / L1 当 L2 收。
@@ -224,6 +230,8 @@ export const CONFIG_KEYS = [
224
230
  'auditTimeoutMs',
225
231
  'auditHardTimeoutMs',
226
232
  'auditToolFilter',
233
+ 'auditPreset',
234
+ 'auditMaterialLimits',
227
235
  'auditRerun',
228
236
  'runtimeCard',
229
237
  'contributions',
@@ -329,6 +337,14 @@ export function apply(ctx, config = {}) {
329
337
  if (config.blockedThreshold !== undefined && (!Number.isInteger(config.blockedThreshold) || config.blockedThreshold < 1)) {
330
338
  throw new Error('invalid_config:clearai-kernel:blockedThreshold')
331
339
  }
340
+ if (config.auditMaterialLimits !== undefined) {
341
+ const limits = config.auditMaterialLimits
342
+ if (limits === null || typeof limits !== 'object' || Array.isArray(limits)) throw new Error('invalid_config:clearai-kernel:auditMaterialLimits')
343
+ for (const [key, value] of Object.entries(limits)) {
344
+ if (!(key in AUDIT_MATERIAL_LIMITS)) throw new Error(`invalid_config:clearai-kernel:auditMaterialLimits.${key}`)
345
+ if (!Number.isInteger(value) || value < 1) throw new Error(`invalid_config:clearai-kernel:auditMaterialLimits.${key}`)
346
+ }
347
+ }
332
348
  const CFG = {
333
349
  // Native experimental variants; published ClearAI keeps both enabled.
334
350
  applicabilityFeedback: config.applicabilityFeedback !== false,
@@ -372,12 +388,30 @@ export function apply(ctx, config = {}) {
372
388
  // (见 resolveToolFace):`read_image` 只在挂了 `attachments` 的部署里存在,名单里写了它、
373
389
  // 部署里没有,`tools.restrict` 会**直接抛**(未知工具名)→ 评估整条路 fail-closed。
374
390
  auditToolFilter: config.auditToolFilter ?? ['read', 'glob', 'grep', 'read_image'],
391
+ /**
392
+ * 宿主 ≥0.2.1-alpha.2 的评估者组合:`startActivation` 的请求里**没有** persona / toolFilter
393
+ * (传了也被静默丢掉),子会话的人格与工具面只由所选预设决定。这一份预设随包声明
394
+ * (`preset/evaluator.cordis.yml`):文件只读、搜索、shell 与后台任务,不挂写工具也不挂 ClearAI 工具。
395
+ */
396
+ auditPreset: config.auditPreset ?? 'clearai-evaluator',
397
+ /** 一次 L3+ 交付随交付带给评估者的未解释项:条数与每条长度的上限(issue #36,见 `auditMaterialProblem`)。 */
398
+ auditMaterialLimits: { ...AUDIT_MATERIAL_LIMITS, ...(config.auditMaterialLimits ?? {}) },
375
399
  auditRerun: config.auditRerun === true,
376
400
  runtimeCard: config.runtimeCard !== false,
377
401
  /** 贡献表。缺省 = 全开;要裁剪就从这里裁,而不是去改装配代码。 */
378
402
  contributions: config.contributions ?? {},
379
403
  }
380
404
  if (config.auditHardTimeoutMs !== undefined) ctx.logger?.warn?.('clearai: auditHardTimeoutMs is deprecated and ignored; auditTimeoutMs is diagnostic only. Cancellation and run budgets belong to the host.')
405
+ /**
406
+ * 启动自检(issue #38):子代理入口两代都不认识,就在挂载时说出来,
407
+ * 而不是等用户跑完长任务、在结案那一步才拿到 `audit_dispatch_failed`。
408
+ * 服务暂时不在不报(它在宿主平面,可能晚到);派遣时还会再判一次并 fail-closed。
409
+ */
410
+ {
411
+ let probe
412
+ try { probe = ctx.get('subagents') } catch { probe = undefined }
413
+ if (probe !== undefined && subagentApi(probe) === null) ctx.logger?.warn?.('clearai: the host subagents service exposes neither start() nor startActivation(); independent evaluation will fail closed on this host version')
414
+ }
381
415
 
382
416
  /** 贡献表:先校验(装配期炸),后登记(见文件末尾的装配段)。 */
383
417
  const CONTRIB = resolveContributions(CFG.contributions)
@@ -1013,6 +1047,28 @@ export function apply(ctx, config = {}) {
1013
1047
  ]
1014
1048
  }
1015
1049
 
1050
+ /**
1051
+ * 任务书里「这是副本」的那几句(issue #35):记号文件在哪、项目声明的复跑变量、全局用户数据目录的提醒。
1052
+ * 不叫评估者关掉被检项目的采集 —— 它要核的数字可能正是采集出来的。
1053
+ */
1054
+ function rerunNotice(rerunDir) {
1055
+ if (rerunDir === null) return { zh: [], en: [] }
1056
+ const environment = Object.entries(rerunEnvironments.get(rerunDir) ?? {})
1057
+ const assignments = environment.map(([key, value]) => `${key}=${value}`).join(' ')
1058
+ return {
1059
+ zh: [
1060
+ `副本根目录有 \`.clearai-rerun.json\`:这里是一次性副本,不是原作者的工作区。`,
1061
+ ...(environment.length === 0 ? [] : [`项目声明了复跑用的环境变量,复跑前先设上(例如命令前加 \`${assignments}\`):${environment.map(([key]) => key).join('、')}。`]),
1062
+ '复跑可能写进被检程序的**全局用户数据目录**(很多引擎按项目名定位它,不随目录改变),从而混进原作者的取证集。若项目有改道约定(上面的变量、或项目文档写的开关),先按约定改道再跑;没有约定时,在裁决里写明复跑可能写到了哪里。不要擅自关闭项目的采集:你要核的数字可能正是它产出的。',
1063
+ ],
1064
+ en: [
1065
+ `The copy root contains \`.clearai-rerun.json\`: this is a disposable copy, not the author's workspace.`,
1066
+ ...(environment.length === 0 ? [] : [`The project declares environment variables for re-runs; set them first (for example prefix the command with \`${assignments}\`): ${environment.map(([key]) => key).join(', ')}.`]),
1067
+ 'A re-run may write into the program\'s **global user-data directory** (many engines locate it by project name, not by folder), mixing your outputs into the author\'s evidence. If the project has a redirect convention (the variables above, or a switch its docs describe), apply it before running; if it has none, say in the verdict where the re-run may have written. Do not switch off the project\'s data collection: the numbers you check may come from it.',
1068
+ ],
1069
+ }
1070
+ }
1071
+
1016
1072
  function evaluatorPrompt(state, step, gate, sessionId, rerunDir = null) {
1017
1073
  const goal = state.goal
1018
1074
  const tested = testedBy(step)
@@ -1067,6 +1123,7 @@ export function apply(ctx, config = {}) {
1067
1123
  rerunDir === null
1068
1124
  ? '你不得修改任何文件,不得执行写入命令,不得重做方案。'
1069
1125
  : `原工作区只读:不要在里面写文件或运行命令。要核对数字就复跑:工作区副本在 ${rerunDir}(不含 clear/),cd 进去运行产物自带的脚本,对照它打印的结果。命令转为后台 job 时,用 job_output({job_id,wait:true,timeout_ms:600000}) 等待并收取同一任务的结果;不要用 sleep 轮询、重跑相同命令或读取宿主私有日志找结果。不再需要的任务用 job_kill 取消。复跑的读数是硬信号;不要重做方案。`,
1126
+ ...rerunNotice(rerunDir).zh,
1070
1127
  ],
1071
1128
  [
1072
1129
  `Working directory: ${sessionCwdLabel(sessionId)}`,
@@ -1076,6 +1133,7 @@ export function apply(ctx, config = {}) {
1076
1133
  rerunDir === null
1077
1134
  ? 'You may not modify any file, run write commands or redo the work.'
1078
1135
  : `The original workspace is read-only: do not write files or run commands in it. To check numbers, re-run: a copy of the workspace is at ${rerunDir} (without clear/); cd into it and run the scripts the outputs came from, and compare what they print. When a command becomes a background job, collect that same job with job_output({job_id,wait:true,timeout_ms:600000}); do not sleep-poll, repeat the command, or search private host logs for its output. Cancel unnecessary jobs with job_kill. Re-run readings are hard signals; do not redo the work.`,
1136
+ ...rerunNotice(rerunDir).en,
1079
1137
  ],
1080
1138
  ),
1081
1139
  ].join('\n')
@@ -1335,6 +1393,9 @@ export function apply(ctx, config = {}) {
1335
1393
  async function dispatchSubRun(options) {
1336
1394
  const subagents = ctx.get('subagents')
1337
1395
  if (subagents === undefined) return { ok: false, reason: tr('subagents 服务不可用', 'the subagents service is unavailable'), failures: [] }
1396
+ const api = subagentApi(subagents)
1397
+ if (api === null) return { ok: false, reason: tr('宿主的 subagents 服务既没有 start 也没有 startActivation:这个宿主版本不受支持', 'the host subagents service has neither start nor startActivation; this host version is unsupported'), failures: [] }
1398
+ if (api === 'activation') return dispatchActivation(subagents, options)
1338
1399
  const base = { label: options.label, parent: options.parent, signal: options.signal, prompt: text(options.prompt) }
1339
1400
  const persona = options.persona
1340
1401
  const schema = options.outputSchema ? nativeAuditSchema(options.outputSchema) : undefined
@@ -1358,6 +1419,80 @@ export function apply(ctx, config = {}) {
1358
1419
  return { ok: false, reason: failures.join(' | '), failures }
1359
1420
  }
1360
1421
 
1422
+ /**
1423
+ * 一次 L3+ 交付随交付带给评估者的未解释项,超限就说清怎么压(issue #36)。
1424
+ * 只量 `anomalies`:这是这次交付里由做的人决定、又会进评估者任务书的那一份。
1425
+ * 拒的是这一次调用的形状,不是这份发现 —— 合并同类、把细节写进产物文件,换一种写法再交。
1426
+ */
1427
+ function auditMaterialProblem(anomalies) {
1428
+ const items = (Array.isArray(anomalies) ? anomalies : []).filter((item) => String(item?.what ?? '').trim() !== '')
1429
+ const { anomalies: maxItems, anomalyChars } = CFG.auditMaterialLimits
1430
+ const long = items.map((item, index) => ({ index, length: String(item.what).trim().length })).filter((item) => item.length > anomalyChars)
1431
+ if (items.length <= maxItems && long.length === 0) return null
1432
+ const parts = []
1433
+ if (items.length > maxItems) parts.push(tr(`这次带了 ${items.length} 条未解释项,上限 ${maxItems} 条`, `this delivery carries ${items.length} unexplained items; the limit is ${maxItems}`))
1434
+ if (long.length > 0) parts.push(tr(`第 ${long.map((item) => item.index + 1).join('、')} 条超过 ${anomalyChars} 字(${long.map((item) => item.length).join('、')} 字)`, `item(s) ${long.map((item) => item.index + 1).join(', ')} exceed ${anomalyChars} characters (${long.map((item) => item.length).join(', ')})`))
1435
+ return tr(
1436
+ `交给独立评估者的材料太重:${parts.join(';')}。评估者要逐条核对、还要复跑,材料越重越容易跑不完。没有截断、没有落账,请压一压再交:同一来源的合并成一条;每条只写「预测为何、实际为何」一句,读数与推导写进产物文件(放进这一步的 artifacts),由评估者去读。上限可在预设配置 auditMaterialLimits 里调。`,
1437
+ `The material for the independent evaluator is too heavy: ${parts.join('; ')}. The evaluator checks each item and may re-run the work, so heavy material makes it more likely to not finish. Nothing was truncated or recorded; trim it and deliver again: merge items with the same source; give each one sentence (what was expected, what was seen) and put readings and derivations in an output file listed in this step's artifacts for the evaluator to read. The limits can be changed with auditMaterialLimits in the preset config.`,
1438
+ )
1439
+ }
1440
+
1441
+ /**
1442
+ * 宿主的子代理入口是哪一代(issue #38)。
1443
+ *
1444
+ * DSH 0.2.1-alpha.2 把 `subagents.start(provider, request)` 换成了 `startActivation(spec)`,
1445
+ * 而 `engines.dsh` 拦不住新宿主:装得上、跑得起,直到第一次派评估者才炸。
1446
+ * 按**方法在不在**判,不按版本号判 —— 方法在场就是能力本身,版本号只是它的间接证据。
1447
+ * 两个都在时走旧入口:那一代的 persona / toolFilter 是逐次请求给的,不依赖随包预设。
1448
+ */
1449
+ function subagentApi(subagents) {
1450
+ if (typeof subagents?.start === 'function') return 'start'
1451
+ if (typeof subagents?.startActivation === 'function') return 'activation'
1452
+ return null
1453
+ }
1454
+
1455
+ /**
1456
+ * 新一代入口(宿主 ≥0.2.1-alpha.2)。
1457
+ *
1458
+ * 这一代的 `startActivation` 请求里**没有** `persona` / `toolFilter`:本地子会话的组合只取
1459
+ * `request.agentPreset`(宿主 `startLocal` 里是 `composition: { agentPreset }`),多传的字段被静默丢掉。
1460
+ * 若照旧把两项塞进请求、不选预设,评估者会加入父会话的 ClearAI 组合 —— 拿到写工具与 ClearAI 自己的工具,
1461
+ * 读到主人格的提示词,「独立、只读」就只剩一句话。所以评估者的工具面改由随包的评估者预设
1462
+ * (`CFG.auditPreset`)决定:平台按挂了哪些行给工具,不是靠我们事后拦。
1463
+ *
1464
+ * 评估纪律照旧写在任务书里(`evaluatorPrompt` 第一段就是它),预设的人格只说身份。
1465
+ * `delivery: 'caller'`:裁决只回到内核,不往父会话的模型面投递;子会话仍进父会话的目录,
1466
+ * 所以 `sweepEndedAudits` 的 `listChildren` 照样看得见它。
1467
+ *
1468
+ * 这一代 `signal` 只管「发布之前」;发布之后的取消归 `dispose`。与 0.5.4 起的语义一致:
1469
+ * 调用方中途放弃只是不再等,评估者不因此被掐断。
1470
+ */
1471
+ async function dispatchActivation(subagents, options) {
1472
+ const schema = options.outputSchema ? nativeAuditSchema(options.outputSchema) : undefined
1473
+ const capability = `preset:${CFG.auditPreset}${schema === undefined ? '' : '+outputSchema'}`
1474
+ try {
1475
+ const activation = await subagents.startActivation({
1476
+ provider: CFG.auditProvider,
1477
+ label: options.label,
1478
+ delivery: 'caller',
1479
+ signal: options.signal ?? new AbortController().signal,
1480
+ request: {
1481
+ prompt: text(options.prompt),
1482
+ parent: options.parent,
1483
+ agentPreset: CFG.auditPreset,
1484
+ ...(schema === undefined ? {} : { outputSchema: schema }),
1485
+ },
1486
+ })
1487
+ /** 回包归一成旧形状:这一代的身份叫 `childId`,下游(账本、目录对账、落定)只认 `id`。 */
1488
+ const run = { id: String(activation.childId), result: activation.result, dispose: () => activation.dispose() }
1489
+ return { ok: true, run, capability, native: false, degraded: null }
1490
+ } catch (error) {
1491
+ const failure = `${capability}:${String(error?.message ?? error).slice(0, 160)}`
1492
+ return { ok: false, reason: failure, failures: [failure] }
1493
+ }
1494
+ }
1495
+
1361
1496
  /**
1362
1497
  * **从评估者自己的会话日志里读回结论**(结论若只挂在父进程内存的 promise 上,父进程一断就永久丢)。
1363
1498
  *
@@ -1729,6 +1864,8 @@ export function apply(ctx, config = {}) {
1729
1864
  const skip = new Set([join(cwd, 'clear'), join(cwd, '.git'), join(cwd, 'node_modules')])
1730
1865
  try {
1731
1866
  cpSync(cwd, target, { recursive: true, filter: (source) => !skip.has(source) })
1867
+ // 记号写不进不影响复跑本身:任务书照样说明这是副本。
1868
+ try { markRerunCopy(cwd, target) } catch (error) { ctx.logger?.warn?.(`clearai kernel: 复跑副本记号没写成 ${String(error?.message ?? error).slice(0, 160)}`) }
1732
1869
  return target
1733
1870
  } catch (error) {
1734
1871
  ctx.logger?.warn?.(`clearai kernel: 复跑副本没建成 ${String(error?.message ?? error).slice(0, 160)}`)
@@ -1737,8 +1874,43 @@ export function apply(ctx, config = {}) {
1737
1874
  }
1738
1875
  }
1739
1876
 
1877
+ /** 副本 → 项目声明的复跑环境变量(任务书要列给评估者)。副本删掉时一起丢。 */
1878
+ const rerunEnvironments = new Map()
1879
+
1880
+ /**
1881
+ * **给副本做记号**(issue #35)。
1882
+ *
1883
+ * 副本只隔开了工作区:很多桌面引擎的用户数据目录按**项目名**定位(Godot 的 `user://`
1884
+ * = `%APPDATA%\Godot\app_userdata\<项目名>`),不随目录改变,于是评估者在副本里复跑,
1885
+ * 写的仍是原作者的全局目录,原作者的取证集里混进另一份代码态的产物。
1886
+ *
1887
+ * 内核替不了被检项目做决定(采集可能正是评估者要核的东西,所以**不关**),能做的是让「这是副本」可被看见:
1888
+ * · 副本根放一份 `.clearai-rerun.json`(原工作区不写):被检项目可以据此把输出改道到副本内;
1889
+ * · 项目若在工作区根声明了 `.clearai-rerun-env`(每行 `KEY=VALUE`,`{copy}` 换成副本路径),
1890
+ * 变量随标记写下,并由任务书列给评估者 —— 宿主不提供替子会话设环境变量的接口,只能告诉它复跑前先设。
1891
+ */
1892
+ function markRerunCopy(cwd, target) {
1893
+ const environment = {}
1894
+ try {
1895
+ const declared = readFileSync(join(cwd, '.clearai-rerun-env'), 'utf8')
1896
+ for (const line of declared.split(/\r?\n/)) {
1897
+ const match = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/.exec(line)
1898
+ if (match === null || line.trimStart().startsWith('#')) continue
1899
+ environment[match[1]] = match[2].replaceAll('{copy}', target)
1900
+ }
1901
+ } catch {
1902
+ /* 没有声明就没有变量:标记照写 */
1903
+ }
1904
+ writeTextFile(
1905
+ join(target, '.clearai-rerun.json'),
1906
+ `${JSON.stringify({ clearai_rerun_copy: true, purpose: 'independent evaluator re-run', original_workspace: cwd, copy: target, environment, note: 'This directory is a disposable copy. Write outputs inside it; do not write the original author\'s global user-data directories.' }, null, 2)}\n`,
1907
+ )
1908
+ if (Object.keys(environment).length > 0) rerunEnvironments.set(target, environment)
1909
+ }
1910
+
1740
1911
  function dropRerunCopy(dir) {
1741
1912
  if (dir === null) return
1913
+ rerunEnvironments.delete(dir)
1742
1914
  try {
1743
1915
  rmSync(dir, { recursive: true, force: true })
1744
1916
  } catch {
@@ -4286,6 +4458,11 @@ export function apply(ctx, config = {}) {
4286
4458
  if (grounding) return grounding
4287
4459
  const level = step.tests?.level ?? null
4288
4460
  const levelIndex = levelIndexOf(level)
4461
+ // ⓪ 交给评估者的材料先过体积闸门:在落账之前拒,被拒的这一批不留半截记录。
4462
+ if (levelIndex > SELF_JUDGE_MAX_INDEX) {
4463
+ const heavy = auditMaterialProblem(args.anomalies)
4464
+ if (heavy !== null) return fail('audit_material_too_large', heavy)
4465
+ }
4289
4466
 
4290
4467
  // ① 登记观测(只追加)
4291
4468
  const accepted = []
@@ -4815,14 +4992,15 @@ export function apply(ctx, config = {}) {
4815
4992
  [
4816
4993
  ['递归删除系统路径', 'recursive delete of a system path'],
4817
4994
  (command) => {
4818
- const match = /(^|[;&|]\s*)rm\s+([^;&|]*)/i.exec(command)
4819
- if (match === null) return false
4820
- const segment = match[2]
4821
- if (!(/(^|\s)-[A-Za-z]*r/i.test(segment) || segment.includes('--recursive'))) return false
4822
- for (const token of segment.split(/\s+/)) {
4823
- if (token === '' || token.startsWith('-')) continue
4824
- const bare = token.replace(/^["']|["']$/g, '')
4825
- if (bare === '/' || bare === '~' || bare.startsWith('~/') || /^\/[^/]+$/.test(bare)) return true
4995
+ // 每个 `rm` 段都查:只看第一段时,`rm a; rm -rf ~` 会从第二段漏过去。
4996
+ for (const match of command.matchAll(/(^|[;&|]\s*)rm\s+([^;&|]*)/gi)) {
4997
+ const segment = match[2]
4998
+ if (!(/(^|\s)-[A-Za-z]*r/i.test(segment) || segment.includes('--recursive'))) continue
4999
+ for (const token of segment.split(/\s+/)) {
5000
+ if (token === '' || token.startsWith('-')) continue
5001
+ const bare = token.replace(/^["']|["']$/g, '')
5002
+ if (bare === '/' || bare === '~' || bare.startsWith('~/') || /^\/[^/]+$/.test(bare)) return true
5003
+ }
4826
5004
  }
4827
5005
  return false
4828
5006
  },
@@ -4848,14 +5026,27 @@ export function apply(ctx, config = {}) {
4848
5026
  [
4849
5027
  ['递归删除系统路径(pwsh)', 'recursive delete of a system path (pwsh)'],
4850
5028
  (command) => {
4851
- const match = /(^|[;&|]\s*)remove-item\s+([^;&|]*)/i.exec(command)
4852
- if (match === null) return false
4853
- const segment = match[2]
4854
- if (!(/(^|\s)-[a-z]*r/i.test(segment) || segment.includes('--recurse'))) return false
4855
- for (const token of segment.split(/\s+/)) {
4856
- if (token === '' || token.startsWith('-')) continue
4857
- const bare = token.replace(/^["']|["']$/g, '').replace(/^env:/i, '').toLowerCase()
4858
- if (bare === '/' || bare === '~' || bare.startsWith('~/') || bare === '%systemroot%' || bare.startsWith('%systemroot%\\') || bare.startsWith('%systemroot%/') || /^\/[^/]+$/.test(bare) || /^[a-z]:\\?$/.test(bare) || /^[a-z]:\\windows\\?$/.test(bare)) return true
5029
+ /**
5030
+ * 每一段都查,不只第一段:`Remove-Item a.txt; Remove-Item -Recurse C:\` 的危险在第二段。
5031
+ * 段边界除了 `; & |` 还有 `{ } ( )` 与换行(`% { Remove-Item -Recurse C:\ }`)。
5032
+ * 动词认 pwsh 的内置别名(`ri / rm / rmdir / rd / del / erase`)。
5033
+ */
5034
+ const verbs = /(?:^|[;&|{}()\n]\s*)(?:remove-item|ri|rm|rmdir|rd|del|erase)\s+([^;&|{}()\n]*)/gi
5035
+ for (const match of command.matchAll(verbs)) {
5036
+ const tokens = match[1].split(/\s+/).filter((token) => token !== '')
5037
+ /**
5038
+ * 递归开关:pwsh 参数可以缩写成 `-recurse` 的任意前缀(`-r` / `-rec` / `-Recurse:$true`),
5039
+ * bash 式短开关簇(`-rf` / `-fr`)也算。`-Force` 不是递归 —— 从前「破折号后任意处有 r」把它也算进去了。
5040
+ */
5041
+ const recursive = tokens.some((token) => /^-(r|re|rec|recu|recur|recurs|recurse)(:\$?true)?$/i.test(token) || /^-[fdiv]*r[fdiv]*$/i.test(token) || token.toLowerCase() === '--recursive')
5042
+ if (!recursive) continue
5043
+ for (const token of tokens) {
5044
+ if (token.startsWith('-')) continue
5045
+ const bare = token.replace(/^["']|["']$/g, '').toLowerCase().replaceAll('\\', '/').replace(/\/+$/, '')
5046
+ if (bare === '' || bare === '~' || bare.startsWith('~/') || bare === '$home' || bare.startsWith('$home/') || /^\/[^/]+$/.test(bare)) return true
5047
+ if (/^[a-z]:$/.test(bare) || /^[a-z]:\/(windows|users|program files|program files \(x86\))$/.test(bare)) return true
5048
+ if (/^(\$env:|env:)(systemroot|windir|systemdrive|userprofile|homedrive|programfiles)$/.test(bare) || /^%(systemroot|windir|systemdrive|userprofile)%$/.test(bare)) return true
5049
+ }
4859
5050
  }
4860
5051
  return false
4861
5052
  },
@@ -4863,7 +5054,7 @@ export function apply(ctx, config = {}) {
4863
5054
  [['远程脚本直灌 shell(pwsh)', 'remote script piped into a shell (pwsh)'], (command) => /(iwr|invoke-webrequest|invoke-restmethod|curl|wget)\b[^;&|]*\|\s*(iex|invoke-expression)\b/i.test(command)],
4864
5055
  [['动态执行下载内容(pwsh)', 'dynamic execution of downloaded content (pwsh)'], (command) => /(iex|invoke-expression)\b[^;&|]*((iwr|invoke-webrequest|invoke-restmethod|curl|wget)\b|https?:\/\/)/i.test(command)],
4865
5056
  [['卷格式化(pwsh)', 'volume formatting (pwsh)'], (command) => /(^|[;&|]\s*)format-volume\b|(^|[;&|]\s*)format\s+[a-z]:/i.test(command)],
4866
- [['提权(pwsh)', 'privilege escalation (pwsh)'], (command) => /(^|[;&|]\s*)(sudo|gsudo)\s/.test(command)],
5057
+ [['提权(pwsh)', 'privilege escalation (pwsh)'], (command) => /(^|[;&|]\s*)(sudo|gsudo)\s/i.test(command)],
4867
5058
  ]
4868
5059
 
4869
5060
  /**