clearai-dsh 0.5.5 → 0.5.7
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 +39 -0
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/lib/client.js +141 -51
- package/package.json +1 -1
- package/presets/clearai/clearai.patch.yml +86 -0
- package/presets/clearai/evaluator.cordis.yml +76 -0
- package/presets/clearai/plugins/clearai-evaluator-face.js +60 -0
- package/presets/clearai/plugins/clearai-kernel.js +208 -17
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,45 @@
|
|
|
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.7] — 2026-10-24
|
|
6
|
+
|
|
7
|
+
**暗色模式下本体图的缩放控件看得清了;会话在跑时图上的关系文字不再闪。**
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- **暗色下的缩放/适配控件看不清**:React Flow 的 Controls 默认走它自己的浅色主题——按钮底色 `#fefefe`,而按钮颜色是 `inherit`;暗色宿主把文字色设成近白,图标于是成了白底上的白图标(对比度 1.04:1),整块控件在暗色画布上还是一块刺眼的白框。现在把控件用到的那几个库变量(`--xy-controls-button-*`)接到宿主主题令牌上,深浅色都跟着宿主走,不写死色值。
|
|
12
|
+
- **会话运行时本体图「字会闪」**:中栏会跟着会话更新高频重渲染,而图带每次渲染都新造 nodes / edges;React Flow 按对象身份判断节点是否变化,于是每次都重新 adopt(`measured` 归零)、边被卸载重挂,边标签(要等 `useEffect` 里的 `getBBox` 才量出尺寸)先画成 hidden 再变 visible——看起来就是关系文字在闪。现在用 `useMemo` 把「同一份投影 + 同一个选中态」钉成同一组 nodes / edges,并按签名缓存节点对象(选中一个点只换那一个);父级重渲染不再动图的数据模型。
|
|
13
|
+
|
|
14
|
+
### Tests
|
|
15
|
+
|
|
16
|
+
- 客户端套件新增:父级重渲染时 nodes / edges 对象身份不变;选中一个点只换它自己;缩放控件接到宿主主题令牌。
|
|
17
|
+
- 另做了修前 / 修后对照:同一份投影重渲染 90 次,修前边被卸载重挂 2047 次、控件对比度 1.04:1;修后 0 次、15:1,且没有 hidden 的边标签。
|
|
18
|
+
|
|
19
|
+
## [0.5.6] — 2026-10-19
|
|
20
|
+
|
|
21
|
+
**适配 DSH 0.2.1:独立评估者在新宿主上重新派得出去,且仍然只读(issue #38);交给评估者的材料有了体积闸门(issue #36),复跑副本能被认出是副本(issue #35);另补上递归删除闸门的几处绕过。**
|
|
22
|
+
|
|
23
|
+
DSH 0.2.1-alpha.2 把 `subagents.start(provider, request)` 换成了 `startActivation(spec)`,而 `engines.dsh` 拦不住新宿主:装得上、跑得起,直到第一次派评估者才以 `audit_dispatch_failed` 失败,结案与 L3+ 交付都过不去。桌面版 0.2.1-rc.2 正是这一代。
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **评估者在 0.2.1 上派得出去**(issue #38,报告者 devil233-ui):内核按方法是否存在选入口——有 `start` 走旧路径(逐次请求给 persona / toolFilter),只有 `startActivation` 时以 `agentPreset: 'clearai-evaluator'`、`delivery: 'caller'` 派遣;回包统一成 `{ id, result, dispose }`,账本、目录对账与落定照旧。两个入口都不在时,挂载那一刻就警告,派遣时 fail-closed 并点名原因。
|
|
28
|
+
- **新宿主上评估者仍然只读**: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` 给的是同一张表。
|
|
29
|
+
- **递归删除闸门的绕过**: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` 的缩写;提权规则不区分大小写。
|
|
30
|
+
- `.gitattributes` 开头的 BOM 让 git 把第一行注释读成无效属性(`is not a valid attribute name`)。
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- **评估材料体积闸门**(issue #36,报告者 GameKingdomNatives):L3+ 交付随交付带给评估者的未解释项(`anomalies`)有了上限——每次至多 4 条、每条至多 400 字,可用预设配置 `auditMaterialLimits: { anomalies, anomalyChars }` 调整,写错在装配期就抛错。超限**拒绝而不截断**(从前单条超过 400 字是静默截断),在落账之前拒,被拒的这一批不留记录,也不算连拦;拒因写明超了多少、怎么压(同源合并,读数与推导写进产物文件)。只量 `anomalies`:observations 的 note 与 `basis` 并不进评估者的任务书(`basis` 只用于 L2 自判),限它们减不了评估者的负担。
|
|
35
|
+
- **复跑副本做了记号**(issue #35,报告者 GameKingdomNatives):副本根目录写一份 `.clearai-rerun.json`(原工作区与副本路径、用途),原工作区不写;任务书告诉评估者这是一次性副本,并提醒复跑可能写进被检程序按项目名定位的全局用户数据目录、有改道约定先改道、没有就在裁决里写明可能写到了哪里。项目可在工作区根声明 `.clearai-rerun-env`(每行 `KEY=VALUE`,`{copy}` 换成副本路径),变量随记号写下并列进任务书,评估者复跑前先设上。内核**不**关闭被检项目的采集:评估者要核的数字可能正是采集出来的。
|
|
36
|
+
|
|
37
|
+
### Tests
|
|
38
|
+
|
|
39
|
+
- 模拟宿主可扮演两代子代理入口;`test/run.sh` 把整套内核用例在 `startActivation` 上再跑一遍(两遍各 700/0)。新增评估者工具面插件、两代入口都不在、删除规则绕过与误伤、评估材料闸门(超限拒绝不落账、刚好在限内放行、上限可调、配置写错抛错、L2 不受限)、复跑记号与项目声明变量的用例。
|
|
40
|
+
- `verify-clean-install` 多一项:名册里 `clearai-evaluator` 在场且没有 broken。DSH 0.2.1-rc.2 与 0.2.0-rc.2 上干净安装均 23/0。
|
|
41
|
+
- 桌面版 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`,主会话不受影响。
|
|
42
|
+
- `tools/native-headless` 增加两个显式开关:`CLEARAI_NATIVE_RUNTIME`(在预注册的 0.2.0-rc.2 之外的宿主上跑兼容性检查,并记入安装记录)与 `CLEARAI_NATIVE_PASS_ENV`(按名转发模型密钥这类环境变量;缺省仍是白名单)。
|
|
43
|
+
|
|
5
44
|
## [0.5.5] — 2026-10-14
|
|
6
45
|
|
|
7
46
|
**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.
|
|
26
|
-
# or in the app: Plugins → Add plugin → clearai-dsh@0.5.
|
|
25
|
+
dsh plugin --profile web add clearai-dsh@0.5.7
|
|
26
|
+
# or in the app: Plugins → Add plugin → clearai-dsh@0.5.7
|
|
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.
|
|
89
|
+
In the sidebar open **Plugins → Add plugin**, enter `clearai-dsh@0.5.7`, 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.
|
|
94
|
+
dsh plugin --profile web add clearai-dsh@0.5.7
|
|
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.
|
|
26
|
-
# 或在应用里:侧栏「插件」→ 添加插件 → clearai-dsh@0.5.
|
|
25
|
+
dsh plugin --profile web add clearai-dsh@0.5.7
|
|
26
|
+
# 或在应用里:侧栏「插件」→ 添加插件 → clearai-dsh@0.5.7
|
|
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.
|
|
89
|
+
侧栏打开**「插件」→ 添加插件**,填 `clearai-dsh@0.5.7`,安装。这就是 DSH 自己的插件管理器:它把你填的东西交给 pnpm,校验这个包声明了组合包、与当前宿主兼容,然后当场生效。(设置里的**插件列表**是**只读清单**;安装入口在侧栏那个「插件」页。)
|
|
90
90
|
|
|
91
91
|
**或者开终端——同一次安装:**
|
|
92
92
|
|
|
93
93
|
```bash
|
|
94
|
-
dsh plugin --profile web add clearai-dsh@0.5.
|
|
94
|
+
dsh plugin --profile web add clearai-dsh@0.5.7
|
|
95
95
|
```
|
|
96
96
|
|
|
97
97
|
从 npm registry 装预构建产物。本机不跑任何编译,因此不需要批准 `allowBuilds` 授权——命令返回时插件就已经可用。
|
package/lib/client.js
CHANGED
|
@@ -313,6 +313,15 @@ window.__ModuleLoader__.load({
|
|
|
313
313
|
.clearai-graph[data-full="1"] .clearai-graph-body{flex:1 1 auto}
|
|
314
314
|
.clearai-graph-body[data-side="1"]{flex-direction:row}
|
|
315
315
|
.clearai-graph-canvas{height:340px;border:.5px solid var(--dsw-alias-border-l2);border-radius:10px;overflow:hidden;background:var(--dsw-alias-bg-base)}
|
|
316
|
+
/**
|
|
317
|
+
* **缩放/适配控件跟着宿主主题走**(暗色下原来白底白图标,对比度 1.04:1)。
|
|
318
|
+
*
|
|
319
|
+
* React Flow 的 Controls 默认是它自己的浅色主题:按钮底色 #fefefe,而按钮颜色是 inherit ——
|
|
320
|
+
* 暗色宿主把文字色设成近白,图标就继承成近白,于是白底上的白图标看不见。
|
|
321
|
+
* 这里不传 colorMode(那会把整张图切到库自带的暗色板,和宿主令牌未必同色),
|
|
322
|
+
* 只把控件用到的那几个库变量接到宿主令牌上:深浅色都跟着宿主走,不写死色值。
|
|
323
|
+
*/
|
|
324
|
+
.clearai-graph-canvas .react-flow{--xy-controls-button-background-color:var(--dsw-alias-bg-layer-1);--xy-controls-button-background-color-hover:var(--dsw-alias-interactive-bg-hover);--xy-controls-button-color:var(--dsw-alias-label-primary);--xy-controls-button-color-hover:var(--dsw-alias-label-primary);--xy-controls-button-border-color:var(--dsw-alias-border-l2)}
|
|
316
325
|
.clearai-graph[data-full="1"] .clearai-graph-canvas{height:auto;flex:1 1 auto;min-width:0}
|
|
317
326
|
/**
|
|
318
327
|
* 全屏是自画的覆盖层(fixed / inset:0 / z-index:40),画布与右下角抽屉都长在它里面。
|
|
@@ -2469,16 +2478,24 @@ window.__ModuleLoader__.load({
|
|
|
2469
2478
|
* · **点击语义**:点节点 / 边 = 打开小卡;「只看相关」是卡上的显式动作。
|
|
2470
2479
|
* · **全屏**:position: fixed 的真 overlay,打开时自动适配。
|
|
2471
2480
|
*/
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2481
|
+
/** 空投影:常量,免得每次渲染造一个新对象。 */
|
|
2482
|
+
const EMPTY_GRAPH = { nodes: [], edges: [], bounds: { width: 0, height: 0 } }
|
|
2483
|
+
|
|
2484
|
+
/**
|
|
2485
|
+
* 投影 → React Flow 的 nodes / edges(纯计算;GraphBand 用 useMemo 把它钉住)。
|
|
2486
|
+
*
|
|
2487
|
+
* 为什么必须稳定:会话在跑时中栏会跟着高频重渲染。每次重渲染都新造 node/edge 对象的话,
|
|
2488
|
+
* React Flow 会把它们当成新节点重新 adopt:`measured` 归零 → 边被卸载重挂 →
|
|
2489
|
+
* 边标签(要等 useEffect 里的 getBBox 才量出尺寸)先 hidden 再 visible,肉眼就是「字在闪」。
|
|
2490
|
+
* 同一份投影 + 同一个选中态 = 同一组对象;选中一个点也只换那一个节点对象(按签名缓存)。
|
|
2491
|
+
*/
|
|
2492
|
+
function graphViewOf({ lexicon, layer, toggled, dragged, selectedId, entityKnowledge, nodeCache, setToggled }) {
|
|
2493
|
+
const graph = lexicon?.graph ?? EMPTY_GRAPH
|
|
2476
2494
|
const conflicts = Array.isArray(lexicon?.conflicts) ? lexicon.conflicts : []
|
|
2477
2495
|
const conflicted = new Set(conflicts.flatMap((item) => item.sides.map((side) => side.fact)).filter((id) => typeof id === 'string'))
|
|
2478
2496
|
const layerNodes = graph.nodes.filter((node) => node.layer === layer)
|
|
2479
2497
|
const layerEdges = graph.edges.filter((edge) => edge.layer === layer && typeof edge.from === 'string' && typeof edge.to === 'string')
|
|
2480
2498
|
const nodeById = new Map(layerNodes.map((node) => [node.id, node]))
|
|
2481
|
-
const problems = Array.isArray(lexicon?.problems) ? lexicon.problems : []
|
|
2482
2499
|
|
|
2483
2500
|
/**
|
|
2484
2501
|
* **目录嵌套就是子图**:概念的父是 `node.parent`(is_a),实体的父是 `node.container`(组成)。
|
|
@@ -2501,10 +2518,6 @@ window.__ModuleLoader__.load({
|
|
|
2501
2518
|
}
|
|
2502
2519
|
return depth
|
|
2503
2520
|
}
|
|
2504
|
-
const [toggled, setToggled] = React.useState({})
|
|
2505
|
-
React.useEffect(() => {
|
|
2506
|
-
setToggled({})
|
|
2507
|
-
}, [layer])
|
|
2508
2521
|
const crowded = layerNodes.length > 40
|
|
2509
2522
|
const isCollapsed = (id) => (childCount.get(id) ?? 0) > 0 && (toggled[id] ?? (crowded && depthOfNode(id) >= 1))
|
|
2510
2523
|
/** 往上找第一个没被收起的祖先挡住的点:自己可见就是自己。 */
|
|
@@ -2541,7 +2554,14 @@ window.__ModuleLoader__.load({
|
|
|
2541
2554
|
}
|
|
2542
2555
|
return out
|
|
2543
2556
|
})()
|
|
2544
|
-
|
|
2557
|
+
/**
|
|
2558
|
+
* 收起/展开用**函数式更新**读当下的 `toggled`:节点对象会被缓存复用,
|
|
2559
|
+
* 闭包里存旧状态的话,复用节点的折叠按钮会按上一帧的状态去翻。
|
|
2560
|
+
*/
|
|
2561
|
+
const toggle = (id) => setToggled((current) => {
|
|
2562
|
+
const collapsed = (childCount.get(id) ?? 0) > 0 && (current[id] ?? (crowded && depthOfNode(id) >= 1))
|
|
2563
|
+
return { ...current, [id]: !collapsed }
|
|
2564
|
+
})
|
|
2545
2565
|
const countOf = (name) => graph.nodes.filter((node) => node.layer === name).length
|
|
2546
2566
|
const entityNames = new Map(graph.nodes.filter((node) => node.kind === 'instance' && typeof node.ref === 'string' && node.ref !== '' && node.label !== node.ref).map((node) => [String(node.ref), String(node.label)]))
|
|
2547
2567
|
|
|
@@ -2550,28 +2570,6 @@ window.__ModuleLoader__.load({
|
|
|
2550
2570
|
const value = String(text ?? '')
|
|
2551
2571
|
return value.length <= limit ? value : `${value.slice(0, limit - 1)}…`
|
|
2552
2572
|
}
|
|
2553
|
-
|
|
2554
|
-
/**
|
|
2555
|
-
* **节点位置是受控的,所以必须自己接住拖动**:不给 `onNodesChange`,
|
|
2556
|
-
* React Flow 内部的拖动没有地方落地,节点根本拖不动。位置是界面状态,换层或图变了就清掉。
|
|
2557
|
-
*/
|
|
2558
|
-
const [dragged, setDragged] = React.useState({})
|
|
2559
|
-
const graphKey = `${layer}|${layerNodes.length}|${layerEdges.length}`
|
|
2560
|
-
React.useEffect(() => {
|
|
2561
|
-
setDragged({})
|
|
2562
|
-
}, [graphKey])
|
|
2563
|
-
const onNodesChange = React.useCallback((changes) => {
|
|
2564
|
-
setDragged((current) => {
|
|
2565
|
-
let next = current
|
|
2566
|
-
for (const change of changes) {
|
|
2567
|
-
if (change?.type !== 'position' || change.position === undefined) continue
|
|
2568
|
-
if (next === current) next = { ...current }
|
|
2569
|
-
next[change.id] = change.position
|
|
2570
|
-
}
|
|
2571
|
-
return next
|
|
2572
|
-
})
|
|
2573
|
-
}, [])
|
|
2574
|
-
|
|
2575
2573
|
/** 一个点的状态:矛盾 > 废止 > 待核验(只登记、没有写进长期知识的事实)> 平常。 */
|
|
2576
2574
|
const nodeState = (node) => {
|
|
2577
2575
|
if (Array.isArray(node.facts) && node.facts.some((id) => conflicted.has(id))) return 'conflict'
|
|
@@ -2579,12 +2577,7 @@ window.__ModuleLoader__.load({
|
|
|
2579
2577
|
if (node.kind !== 'concept' && node.kind !== 'value_type' && node.source === 'asserted' && (node.facts ?? []).length === 0) return 'pending'
|
|
2580
2578
|
return 'on'
|
|
2581
2579
|
}
|
|
2582
|
-
const selectedId = picked?.kind === 'node' ? picked.node.id : (focus ?? null)
|
|
2583
2580
|
|
|
2584
|
-
/**
|
|
2585
|
-
* 投影节点 → React Flow 节点。坐标 = 力导向松弛过的投影坐标(起点确定 ⇒ 同一份账本同一张图)。
|
|
2586
|
-
* 尺寸显式给:只写在 style 里的话,React Flow 要等测量完成才知道它多大。
|
|
2587
|
-
*/
|
|
2588
2581
|
/**
|
|
2589
2582
|
* 小图(十来个点)不跑力导向:几个点、几条边时它常常把点排成一条线。
|
|
2590
2583
|
* 改成一圈:连得最多的那个点居中(它是这张图的主语),其余按投影顺序绕一圈——确定、好读。
|
|
@@ -2609,43 +2602,84 @@ window.__ModuleLoader__.load({
|
|
|
2609
2602
|
})
|
|
2610
2603
|
return out
|
|
2611
2604
|
})()
|
|
2612
|
-
const
|
|
2613
|
-
|
|
2614
|
-
|
|
2605
|
+
const basePosition = (node) => dragged[node.id] ?? ring?.get(node.id) ?? { x: node.x ?? 0, y: node.y ?? 0 }
|
|
2606
|
+
/**
|
|
2607
|
+
* 坐标 = 力导向松弛过的投影坐标(起点确定 ⇒ 同一份账本同一张图)。
|
|
2608
|
+
* 力导向会把它收到的节点整个换成新对象,所以**先算坐标、后建节点对象**;
|
|
2609
|
+
* 反过来的话缓存下来的节点身份会在布局那一步丢掉。
|
|
2610
|
+
*/
|
|
2611
|
+
const positions = small
|
|
2612
|
+
? new Map(allNodes.map((node) => [node.id, basePosition(node)]))
|
|
2613
|
+
: (() => {
|
|
2614
|
+
const laidOut = forceLayout(
|
|
2615
|
+
allNodes.map((node) => ({ id: node.id, position: basePosition(node) })),
|
|
2616
|
+
allEdges.map((edge) => ({ source: edge.from, target: edge.to })),
|
|
2617
|
+
)
|
|
2618
|
+
const out = new Map(allNodes.map((node) => [node.id, basePosition(node)]))
|
|
2619
|
+
for (const node of laidOut) {
|
|
2620
|
+
const x = node?.position?.x
|
|
2621
|
+
const y = node?.position?.y
|
|
2622
|
+
if (Number.isFinite(x) && Number.isFinite(y)) out.set(node.id, { x, y })
|
|
2623
|
+
}
|
|
2624
|
+
return out
|
|
2625
|
+
})()
|
|
2626
|
+
|
|
2627
|
+
/**
|
|
2628
|
+
* 投影节点 → React Flow 节点。坐标 = 上面算好的位置。
|
|
2629
|
+
* 尺寸显式给:只写在 style 里的话,React Flow 要等测量完成才知道它多大。
|
|
2630
|
+
* 对象身份按**签名**守:内容没变就复用上一次那个对象,内容真变了才重建。
|
|
2631
|
+
*/
|
|
2632
|
+
const cache = nodeCache.current ?? new Map()
|
|
2633
|
+
const rfNodes = allNodes.map((node) => {
|
|
2634
|
+
const position = positions.get(node.id) ?? { x: 0, y: 0 }
|
|
2635
|
+
const state = nodeState(node)
|
|
2636
|
+
const selected = node.id === selectedId
|
|
2637
|
+
const labelText = trimLabel(node.kind === 'value_type' ? (FORM_WORD[node.ref] ?? node.label ?? node.ref) : (node.label ?? node.ref ?? node.id), 16)
|
|
2638
|
+
const counts = node.layer === 'entity' ? entityKnowledge?.[node.id]?.counts : undefined
|
|
2639
|
+
const children = childCount.get(node.id) ?? 0
|
|
2640
|
+
const collapsed = children > 0 ? isCollapsed(node.id) : false
|
|
2641
|
+
const foldText = children > 0 ? (collapsed ? `+${hiddenUnder.get(node.id) ?? 0}` : '−') : ''
|
|
2642
|
+
const signature = [node.id, node.kind, node.ref ?? '', position.x, position.y, selected ? 1 : 0, state, labelText, foldText, counts === undefined ? '' : JSON.stringify(counts)].join('\u0001')
|
|
2643
|
+
const cached = cache.get(node.id)
|
|
2644
|
+
if (cached !== undefined && cached.signature === signature) return cached.node
|
|
2645
|
+
const rfNode = {
|
|
2615
2646
|
id: node.id,
|
|
2616
2647
|
type: 'default',
|
|
2617
|
-
position
|
|
2648
|
+
position,
|
|
2618
2649
|
initialWidth: 120,
|
|
2619
2650
|
initialHeight: 26,
|
|
2620
|
-
selected
|
|
2651
|
+
selected,
|
|
2621
2652
|
data: {
|
|
2622
2653
|
label: h(
|
|
2623
2654
|
'span',
|
|
2624
|
-
{ className: 'clearai-star', 'data-kind': node.kind, 'data-state':
|
|
2655
|
+
{ className: 'clearai-star', 'data-kind': node.kind, 'data-state': state, 'data-sel': selected ? '1' : '0' },
|
|
2625
2656
|
h('i', null),
|
|
2626
|
-
h('span', null,
|
|
2627
|
-
node.layer === 'entity' ? h(CountMarks, { counts
|
|
2628
|
-
|
|
2657
|
+
h('span', null, labelText),
|
|
2658
|
+
node.layer === 'entity' ? h(CountMarks, { counts }) : null,
|
|
2659
|
+
children > 0
|
|
2629
2660
|
? h(
|
|
2630
2661
|
'b',
|
|
2631
2662
|
{
|
|
2632
2663
|
className: 'clearai-fold',
|
|
2633
|
-
title:
|
|
2664
|
+
title: collapsed ? t('展开下一层') : t('收起下一层'),
|
|
2634
2665
|
onClick: (event) => {
|
|
2635
2666
|
event.stopPropagation()
|
|
2636
2667
|
toggle(node.id)
|
|
2637
2668
|
},
|
|
2638
2669
|
},
|
|
2639
|
-
|
|
2670
|
+
foldText,
|
|
2640
2671
|
)
|
|
2641
2672
|
: null,
|
|
2642
2673
|
),
|
|
2643
2674
|
},
|
|
2644
2675
|
className: 'clearai-star-node',
|
|
2645
2676
|
style: { background: 'transparent', border: 0, padding: 0, width: 'auto', boxShadow: 'none' },
|
|
2646
|
-
}
|
|
2647
|
-
|
|
2648
|
-
|
|
2677
|
+
}
|
|
2678
|
+
cache.set(node.id, { signature, node: rfNode })
|
|
2679
|
+
return rfNode
|
|
2680
|
+
})
|
|
2681
|
+
/** 塌掉/移除的分支不在图上了:缓存里只留当前层还认识的点。 */
|
|
2682
|
+
for (const id of [...cache.keys()]) if (!nodeById.has(id)) cache.delete(id)
|
|
2649
2683
|
|
|
2650
2684
|
/** 投影边 → React Flow 边:实线已验证、虚线待核验、淡线上下位、告警色是矛盾。 */
|
|
2651
2685
|
const edgeTone = (edge) => {
|
|
@@ -2667,6 +2701,62 @@ window.__ModuleLoader__.load({
|
|
|
2667
2701
|
style: edgeTone(edge),
|
|
2668
2702
|
}))
|
|
2669
2703
|
|
|
2704
|
+
return {
|
|
2705
|
+
rfNodes,
|
|
2706
|
+
rfEdges,
|
|
2707
|
+
allNodes,
|
|
2708
|
+
allEdges,
|
|
2709
|
+
nodeById,
|
|
2710
|
+
entityNames,
|
|
2711
|
+
countOf,
|
|
2712
|
+
conflicts,
|
|
2713
|
+
graphKey: `${layer}|${layerNodes.length}|${layerEdges.length}`,
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
const GraphBand = ({ lexicon, data, send, layer, onLayer, fullscreen, onToggleFullscreen, onFilter, sessionId, unlanded, focus }) => {
|
|
2718
|
+
const [picked, setPicked] = React.useState(null)
|
|
2719
|
+
const [asked, setAsked] = React.useState({})
|
|
2720
|
+
const [toggled, setToggled] = React.useState({})
|
|
2721
|
+
const [dragged, setDragged] = React.useState({})
|
|
2722
|
+
/** 节点对象缓存:见 graphViewOf。父级重渲染一个都不换,选中只换选中那个。 */
|
|
2723
|
+
const nodeCache = React.useRef(new Map())
|
|
2724
|
+
const selectedId = picked?.kind === 'node' ? picked.node.id : (focus ?? null)
|
|
2725
|
+
React.useEffect(() => {
|
|
2726
|
+
setToggled({})
|
|
2727
|
+
}, [layer])
|
|
2728
|
+
|
|
2729
|
+
/**
|
|
2730
|
+
* **同一份投影只产出一组 nodes/edges**。会话在跑时中栏会被高频重渲染;
|
|
2731
|
+
* 每次重造对象会让 React Flow 重新 adopt、边被卸载重挂,边标签因此闪。
|
|
2732
|
+
*/
|
|
2733
|
+
const view = React.useMemo(
|
|
2734
|
+
() => graphViewOf({ lexicon, layer, toggled, dragged, selectedId, entityKnowledge: data?.entityKnowledge, nodeCache, setToggled }),
|
|
2735
|
+
[lexicon, layer, toggled, dragged, selectedId, data?.entityKnowledge],
|
|
2736
|
+
)
|
|
2737
|
+
const { rfNodes, rfEdges, allNodes, allEdges, nodeById, entityNames, countOf, conflicts, graphKey } = view
|
|
2738
|
+
/** 读时的跨文件检查只标不拦:有问题的那一份不进图,这里说清是哪个文件、哪里不对。 */
|
|
2739
|
+
const problems = Array.isArray(lexicon?.problems) ? lexicon.problems : []
|
|
2740
|
+
|
|
2741
|
+
/**
|
|
2742
|
+
* **节点位置是受控的,所以必须自己接住拖动**:不给 `onNodesChange`,
|
|
2743
|
+
* React Flow 内部的拖动没有地方落地,节点根本拖不动。位置是界面状态,换层或图变了就清掉。
|
|
2744
|
+
*/
|
|
2745
|
+
React.useEffect(() => {
|
|
2746
|
+
setDragged({})
|
|
2747
|
+
}, [graphKey])
|
|
2748
|
+
const onNodesChange = React.useCallback((changes) => {
|
|
2749
|
+
setDragged((current) => {
|
|
2750
|
+
let next = current
|
|
2751
|
+
for (const change of changes) {
|
|
2752
|
+
if (change?.type !== 'position' || change.position === undefined) continue
|
|
2753
|
+
if (next === current) next = { ...current }
|
|
2754
|
+
next[change.id] = change.position
|
|
2755
|
+
}
|
|
2756
|
+
return next
|
|
2757
|
+
})
|
|
2758
|
+
}, [])
|
|
2759
|
+
|
|
2670
2760
|
const onNodeClick = (_event, node) => {
|
|
2671
2761
|
const original = nodeById.get(node.id)
|
|
2672
2762
|
if (original !== undefined) setPicked({ kind: 'node', node: original })
|
package/package.json
CHANGED
|
@@ -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
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
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
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
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
|
|
5057
|
+
[['提权(pwsh)', 'privilege escalation (pwsh)'], (command) => /(^|[;&|]\s*)(sudo|gsudo)\s/i.test(command)],
|
|
4867
5058
|
]
|
|
4868
5059
|
|
|
4869
5060
|
/**
|