dsh-swarm-console 0.3.0 → 0.3.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 +117 -109
- package/lib/core/checks.js +89 -89
- package/lib/core/evidence.js +1 -1
- package/lib/core/gate.js +85 -81
- package/package.json +47 -47
package/README.md
CHANGED
|
@@ -1,109 +1,117 @@
|
|
|
1
|
-
# Swarm Console(`dsh-swarm-console`)
|
|
2
|
-
|
|
3
|
-
> 让 agent 说「完成」之前,先过一道可机器验证的交付门禁。
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/dsh-swarm-console)
|
|
6
|
-
[](https://github.com/whyissodifficult/dsh-agent-swarm-console/blob/main/LICENSE)
|
|
7
|
-
[](https://nodejs.org/)
|
|
8
|
-
|
|
9
|
-
DeepSeek Harness(DSH)插件:把「任务契约 → 证据校验 → 三态门禁 → 用户放行」做成一条可核查的链路。
|
|
10
|
-
|
|
11
|
-
## 它解决什么
|
|
12
|
-
|
|
13
|
-
Agent 说「完成了」,可能只是日志刷屏、产出为零。这个插件让「完成」必须在证据上成立:
|
|
14
|
-
|
|
15
|
-
- **冻结契约**:目标 / 约束 / 验收条件写死并哈希成 `contractId`,改一个字就换 id;
|
|
16
|
-
- **证据先于验收**:每条验收条件必须绑定检查项,缺证据最多判 `YELLOW`;
|
|
17
|
-
- **三态判定**:`GREEN` / `YELLOW` / `RED`,`RED` 一定带可复制执行的复现命令;
|
|
18
|
-
- **放行只归用户**:由斜杠命令触发,模型中不存在对应工具,无法代批。
|
|
19
|
-
|
|
20
|
-
## 安装
|
|
21
|
-
|
|
22
|
-
### 从 npm 安装(已验证)
|
|
23
|
-
|
|
24
|
-
DSH 的 **插件 → 添加插件** 里输入包名,安装源选 `npm 官方源`:
|
|
25
|
-
|
|
26
|
-
```text
|
|
27
|
-
dsh-swarm-console
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
或命令行:
|
|
31
|
-
|
|
32
|
-
```text
|
|
33
|
-
plugin_manager install_bundle dsh-swarm-console
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
##
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
1
|
+
# Swarm Console(`dsh-swarm-console`)
|
|
2
|
+
|
|
3
|
+
> 让 agent 说「完成」之前,先过一道可机器验证的交付门禁。
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/dsh-swarm-console)
|
|
6
|
+
[](https://github.com/whyissodifficult/dsh-agent-swarm-console/blob/main/LICENSE)
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
|
|
9
|
+
DeepSeek Harness(DSH)插件:把「任务契约 → 证据校验 → 三态门禁 → 用户放行」做成一条可核查的链路。
|
|
10
|
+
|
|
11
|
+
## 它解决什么
|
|
12
|
+
|
|
13
|
+
Agent 说「完成了」,可能只是日志刷屏、产出为零。这个插件让「完成」必须在证据上成立:
|
|
14
|
+
|
|
15
|
+
- **冻结契约**:目标 / 约束 / 验收条件写死并哈希成 `contractId`,改一个字就换 id;
|
|
16
|
+
- **证据先于验收**:每条验收条件必须绑定检查项,缺证据最多判 `YELLOW`;
|
|
17
|
+
- **三态判定**:`GREEN` / `YELLOW` / `RED`,`RED` 一定带可复制执行的复现命令;
|
|
18
|
+
- **放行只归用户**:由斜杠命令触发,模型中不存在对应工具,无法代批。
|
|
19
|
+
|
|
20
|
+
## 安装
|
|
21
|
+
|
|
22
|
+
### 从 npm 安装(已验证)
|
|
23
|
+
|
|
24
|
+
DSH 的 **插件 → 添加插件** 里输入包名,安装源选 `npm 官方源`:
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
dsh-swarm-console
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
或命令行:
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
plugin_manager install_bundle dsh-swarm-console
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
> 升级到新的次版本(0.2.x → 0.3.x)必须显式指定版本:`install_bundle dsh-swarm-console@0.3.1`,
|
|
37
|
+
> 因为 `^0.2.x` 的 semver 上限不含 0.3.0。
|
|
38
|
+
|
|
39
|
+
> 已在 DSH 0.2.2-rc.5 上实测:profile 依赖解析为 `^0.2.2`,安装后 `verify_*` 工具与三条斜杠命令均可用。
|
|
40
|
+
|
|
41
|
+
### 从本地目录安装(已验证)
|
|
42
|
+
|
|
43
|
+
```text
|
|
44
|
+
plugin_manager install_bundle <本包目录的绝对路径>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
> 注意:以 `link` 方式安装时,卸载该插件会清空被链接目录的内容——请只链接已提交(或已备份)的目录。
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## 快速开始
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
verify_contract 冻结契约(objective / workspaceRoot / criteria / constraints,testCmd 可选)
|
|
54
|
+
verify_run 跑证据校验:checks 是「检查请求」,由插件实际执行
|
|
55
|
+
/gate-status 不带参数列出本会话所有契约;带参数看单条(支持 id 前缀,如 7e28)
|
|
56
|
+
/gate-approve 放行:/gate-approve <id|前缀> <证据hash>(仅 GREEN + hash 一致时允许)
|
|
57
|
+
/gate-retry 重算并刷新判定(旧放行标 stale)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
示例:
|
|
61
|
+
|
|
62
|
+
```text
|
|
63
|
+
> verify_contract {"objective":"给 README 加安装节","workspaceRoot":"D:/my-project",
|
|
64
|
+
"criteria":[{"id":"c1","text":"安装节存在","checkIds":["k1"]}]}
|
|
65
|
+
contract 7e280e5c4f7e 已冻结
|
|
66
|
+
|
|
67
|
+
> verify_run {"contractId":"7e280e5c4f7e","checks":[{"id":"k1","type":"file.exists","path":"README.md"}]}
|
|
68
|
+
门禁 GREEN:全部 1 条验收条件均有通过证据
|
|
69
|
+
|
|
70
|
+
> /gate-status 7e28
|
|
71
|
+
契约 7e280e5c4f7e:最近决定 GREEN @ …;尚未放行
|
|
72
|
+
证据:380cdbc5b3ed
|
|
73
|
+
|
|
74
|
+
> /gate-approve 7e28 380cdbc5b3ed
|
|
75
|
+
契约 7e280e5c4f7e 已由用户放行(approved)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## 能力与限制
|
|
79
|
+
|
|
80
|
+
已实现:
|
|
81
|
+
|
|
82
|
+
- 契约冻结与内容哈希(`contract.id`)
|
|
83
|
+
- 证据由插件执行:`verify_run` 的 `checks` 是**检查请求**而非结论——`file.exists` 由插件 `existsSync` 判定,`exec` 由插件实际执行;模型自报的 `ok` 一律忽略
|
|
84
|
+
- 证据分级与三态门禁(`GREEN` / `YELLOW` / `RED`);空契约直接 `RED`
|
|
85
|
+
- `RED` 必带可执行复现命令;缺证据不判通过
|
|
86
|
+
- 用户专属放行:`/gate-approve` `/gate-retry` `/gate-status`;重跑后旧放行标记 `stale`
|
|
87
|
+
- 外部 agent 适配层(OpenAI 兼容端点,作为原生 subagent run 使用)
|
|
88
|
+
|
|
89
|
+
⚠️ 两条必须知道的行为:
|
|
90
|
+
|
|
91
|
+
- **`exec` 检查以当前用户权限执行命令**,等同于你自己在终端敲那条命令。请只把可信命令写进契约,不要接受来源不明的检查请求。
|
|
92
|
+
- **执行期间阻塞宿主**:v0.2 采用同步执行,单条检查最长 120 秒,期间宿主事件循环被占用,界面可能短暂无响应。异步执行排进 0.3。
|
|
93
|
+
|
|
94
|
+
尚未实现(不承诺):
|
|
95
|
+
|
|
96
|
+
- 可视化画布
|
|
97
|
+
- 多阶段评审状态机
|
|
98
|
+
- 动作卡片:代码保留为可选增强,需目标 profile 挂载 `action-cards` 服务
|
|
99
|
+
- 证据持久化:v1 存在进程内,DSH 重启即丢
|
|
100
|
+
|
|
101
|
+
## 开发与门禁
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
npm run gate # probe / selftest / plugin:test / smoke / pack / wiring / dryrun / encoding 八段
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
验收记录见 [`docs/V1-ACCEPTANCE.md`](https://github.com/whyissodifficult/dsh-agent-swarm-console/blob/main/plugin/docs/V1-ACCEPTANCE.md):包含斜杠命令链路的日志证据(`command/run`、`command/done`)与三条硬规则的反证。
|
|
108
|
+
|
|
109
|
+
## 链接
|
|
110
|
+
|
|
111
|
+
- 仓库:https://github.com/whyissodifficult/dsh-agent-swarm-console
|
|
112
|
+
- 插件详情:见 [`docs/DETAIL.md`](https://github.com/whyissodifficult/dsh-agent-swarm-console/blob/main/plugin/docs/DETAIL.md)
|
|
113
|
+
- 验收记录:[`docs/V1-ACCEPTANCE.md`](https://github.com/whyissodifficult/dsh-agent-swarm-console/blob/main/plugin/docs/V1-ACCEPTANCE.md)
|
|
114
|
+
|
|
115
|
+
## 许可
|
|
116
|
+
|
|
117
|
+
[MIT](https://github.com/whyissodifficult/dsh-agent-swarm-console/blob/main/LICENSE)
|
package/lib/core/checks.js
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* P0-2 · 检查请求执行器(0.3.0:契约结构破坏性变更)。
|
|
3
|
-
*
|
|
4
|
-
* 变化:
|
|
5
|
-
* - 一切路径以 contract.workspaceRoot 为根;file.exists 只接受相对路径
|
|
6
|
-
* - exec 的 cwd 固定为 workspaceRoot(结论不由宿主 cwd 决定)
|
|
7
|
-
* - exec 命令必须与 contract.testCmd 完全相等(白名单),否则该检查判 RED
|
|
8
|
-
* - 非法请求不再 throw:返回 {ok:false, detail:'检查请求非法:…'},由 gate 判 RED
|
|
9
|
-
*
|
|
10
|
-
* 模型传入的 ok 一律忽略,并记一条 warning。
|
|
11
|
-
*/
|
|
12
|
-
import { existsSync as fsExistsSync } from 'node:fs'
|
|
13
|
-
import { spawnSync as cpSpawnSync } from 'node:child_process'
|
|
14
|
-
import { isAbsolute, resolve } from 'node:path'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param {Array} requests 检查请求
|
|
18
|
-
* @param {{workspaceRoot:string, testCmd?:string, existsSync?:Function, exec?:Function}} deps
|
|
19
|
-
* @returns {{checks:Array, warnings:string[]}}
|
|
20
|
-
*/
|
|
21
|
-
export function runChecks(requests, deps = {}) {
|
|
22
|
-
const workspaceRoot = deps.workspaceRoot
|
|
23
|
-
const existsSync = deps.existsSync ?? fsExistsSync
|
|
24
|
-
const exec = deps.exec ?? ((cmd, opts) => cpSpawnSync(cmd, {
|
|
25
|
-
shell: true,
|
|
26
|
-
cwd: opts?.cwd,
|
|
27
|
-
timeout: 120000,
|
|
28
|
-
encoding: 'utf8',
|
|
29
|
-
maxBuffer: 8 * 1024 * 1024,
|
|
30
|
-
}))
|
|
31
|
-
|
|
32
|
-
const warnings = []
|
|
33
|
-
// 顶层非法(不是数组)也不抛:整体记为一条失败检查,交 gate 判 RED
|
|
34
|
-
if (!Array.isArray(requests)) {
|
|
35
|
-
return {
|
|
36
|
-
checks: [{ id: '__checks__', type: 'invalid', ok: false, detail: '检查请求非法:checks 必须是数组' }],
|
|
37
|
-
warnings,
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const checks = requests.map((req, i) => {
|
|
42
|
-
const fallbackId = req && typeof req === 'object' && typeof req.id === 'string' ? req.id : `checks[${i}]`
|
|
43
|
-
const invalid = (reason) => ({ id: fallbackId, type: String(req?.type ?? 'invalid'), ok: false, detail: `检查请求非法:${reason}` })
|
|
44
|
-
|
|
45
|
-
if (!req || typeof req !== 'object') return invalid('必须是对象')
|
|
46
|
-
const { id, type } = req
|
|
47
|
-
if (typeof id !== 'string' || id === '') return invalid('id 必填')
|
|
48
|
-
if (typeof type !== 'string' || type === '') return invalid('type 必填')
|
|
49
|
-
|
|
50
|
-
// 模型自报 ok 一律忽略,记 warning
|
|
51
|
-
if (req.ok !== undefined) {
|
|
52
|
-
warnings.push(`check ${id} 自报 ok=${req.ok} 已忽略,改由插件实际执行判定`)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (type === 'file.exists') {
|
|
56
|
-
if (typeof req.path !== 'string' || req.path === '') return invalid('file.exists 必带 path')
|
|
57
|
-
// P0-2:路径必须是相对 workspaceRoot 的相对路径,绝对路径直接判 RED
|
|
58
|
-
if (isAbsolute(req.path)) {
|
|
59
|
-
return { id, type, ok: false, path: req.path, detail: '检查路径必须是相对 workspaceRoot 的相对路径' }
|
|
60
|
-
}
|
|
61
|
-
if (typeof workspaceRoot !== 'string' || workspaceRoot === '') {
|
|
62
|
-
return invalid('缺少 workspaceRoot,无法解析相对路径')
|
|
63
|
-
}
|
|
64
|
-
const absPath = resolve(workspaceRoot, req.path)
|
|
65
|
-
const ok = existsSync(absPath) === true
|
|
66
|
-
return { id, type, ok, path: req.path, absPath, detail: ok ? `文件存在:${req.path}` : `文件不存在:${req.path}` }
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (type === 'exec') {
|
|
70
|
-
if (typeof req.cmd !== 'string' || req.cmd === '') return invalid('exec 必带 cmd')
|
|
71
|
-
// P0-4:命令白名单——必须与契约 testCmd 完全相等
|
|
72
|
-
if (typeof deps.testCmd !== 'string' || deps.testCmd === '' || req.cmd !== deps.testCmd) {
|
|
73
|
-
return { id, type, ok: false, cmd: req.cmd, detail: 'exec 命令未在契约中声明为 testCmd,已拒绝' }
|
|
74
|
-
}
|
|
75
|
-
const r = exec(req.cmd, { cwd: workspaceRoot })
|
|
76
|
-
const ok = r.error === undefined && r.status === 0
|
|
77
|
-
const out = { id, type, ok, cmd: req.cmd, exitCode: r.status }
|
|
78
|
-
if (!ok) {
|
|
79
|
-
const msg = r.error?.message ?? r.stderr ?? r.stdout ?? `exit ${r.status}`
|
|
80
|
-
out.detail = String(msg).slice(0, 300)
|
|
81
|
-
}
|
|
82
|
-
return out
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return invalid(`未知检查类型 ${type}`)
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
return { checks, warnings }
|
|
89
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* P0-2 · 检查请求执行器(0.3.0:契约结构破坏性变更)。
|
|
3
|
+
*
|
|
4
|
+
* 变化:
|
|
5
|
+
* - 一切路径以 contract.workspaceRoot 为根;file.exists 只接受相对路径
|
|
6
|
+
* - exec 的 cwd 固定为 workspaceRoot(结论不由宿主 cwd 决定)
|
|
7
|
+
* - exec 命令必须与 contract.testCmd 完全相等(白名单),否则该检查判 RED
|
|
8
|
+
* - 非法请求不再 throw:返回 {ok:false, detail:'检查请求非法:…'},由 gate 判 RED
|
|
9
|
+
*
|
|
10
|
+
* 模型传入的 ok 一律忽略,并记一条 warning。
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync as fsExistsSync } from 'node:fs'
|
|
13
|
+
import { spawnSync as cpSpawnSync } from 'node:child_process'
|
|
14
|
+
import { isAbsolute, resolve } from 'node:path'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {Array} requests 检查请求
|
|
18
|
+
* @param {{workspaceRoot:string, testCmd?:string, existsSync?:Function, exec?:Function}} deps
|
|
19
|
+
* @returns {{checks:Array, warnings:string[]}}
|
|
20
|
+
*/
|
|
21
|
+
export function runChecks(requests, deps = {}) {
|
|
22
|
+
const workspaceRoot = deps.workspaceRoot
|
|
23
|
+
const existsSync = deps.existsSync ?? fsExistsSync
|
|
24
|
+
const exec = deps.exec ?? ((cmd, opts) => cpSpawnSync(cmd, {
|
|
25
|
+
shell: true,
|
|
26
|
+
cwd: opts?.cwd,
|
|
27
|
+
timeout: 120000,
|
|
28
|
+
encoding: 'utf8',
|
|
29
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
30
|
+
}))
|
|
31
|
+
|
|
32
|
+
const warnings = []
|
|
33
|
+
// 顶层非法(不是数组)也不抛:整体记为一条失败检查,交 gate 判 RED
|
|
34
|
+
if (!Array.isArray(requests)) {
|
|
35
|
+
return {
|
|
36
|
+
checks: [{ id: '__checks__', type: 'invalid', ok: false, detail: '检查请求非法:checks 必须是数组' }],
|
|
37
|
+
warnings,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const checks = requests.map((req, i) => {
|
|
42
|
+
const fallbackId = req && typeof req === 'object' && typeof req.id === 'string' ? req.id : `checks[${i}]`
|
|
43
|
+
const invalid = (reason) => ({ id: fallbackId, type: String(req?.type ?? 'invalid'), ok: false, detail: `检查请求非法:${reason}` })
|
|
44
|
+
|
|
45
|
+
if (!req || typeof req !== 'object') return invalid('必须是对象')
|
|
46
|
+
const { id, type } = req
|
|
47
|
+
if (typeof id !== 'string' || id === '') return invalid('id 必填')
|
|
48
|
+
if (typeof type !== 'string' || type === '') return invalid('type 必填')
|
|
49
|
+
|
|
50
|
+
// 模型自报 ok 一律忽略,记 warning
|
|
51
|
+
if (req.ok !== undefined) {
|
|
52
|
+
warnings.push(`check ${id} 自报 ok=${req.ok} 已忽略,改由插件实际执行判定`)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (type === 'file.exists') {
|
|
56
|
+
if (typeof req.path !== 'string' || req.path === '') return invalid('file.exists 必带 path')
|
|
57
|
+
// P0-2:路径必须是相对 workspaceRoot 的相对路径,绝对路径直接判 RED
|
|
58
|
+
if (isAbsolute(req.path)) {
|
|
59
|
+
return { id, type, ok: false, path: req.path, detail: '检查路径必须是相对 workspaceRoot 的相对路径' }
|
|
60
|
+
}
|
|
61
|
+
if (typeof workspaceRoot !== 'string' || workspaceRoot === '') {
|
|
62
|
+
return invalid('缺少 workspaceRoot,无法解析相对路径')
|
|
63
|
+
}
|
|
64
|
+
const absPath = resolve(workspaceRoot, req.path)
|
|
65
|
+
const ok = existsSync(absPath) === true
|
|
66
|
+
return { id, type, ok, path: req.path, absPath, detail: ok ? `文件存在:${req.path}` : `文件不存在:${req.path}` }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (type === 'exec') {
|
|
70
|
+
if (typeof req.cmd !== 'string' || req.cmd === '') return invalid('exec 必带 cmd')
|
|
71
|
+
// P0-4:命令白名单——必须与契约 testCmd 完全相等
|
|
72
|
+
if (typeof deps.testCmd !== 'string' || deps.testCmd === '' || req.cmd !== deps.testCmd) {
|
|
73
|
+
return { id, type, ok: false, cmd: req.cmd, rejected: true, detail: 'exec 命令未在契约中声明为 testCmd,已拒绝' }
|
|
74
|
+
}
|
|
75
|
+
const r = exec(req.cmd, { cwd: workspaceRoot })
|
|
76
|
+
const ok = r.error === undefined && r.status === 0
|
|
77
|
+
const out = { id, type, ok, cmd: req.cmd, exitCode: r.status }
|
|
78
|
+
if (!ok) {
|
|
79
|
+
const msg = r.error?.message ?? r.stderr ?? r.stdout ?? `exit ${r.status}`
|
|
80
|
+
out.detail = String(msg).slice(0, 300)
|
|
81
|
+
}
|
|
82
|
+
return out
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return invalid(`未知检查类型 ${type}`)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
return { checks, warnings }
|
|
89
|
+
}
|
package/lib/core/evidence.js
CHANGED
|
@@ -93,7 +93,7 @@ function normalizeChecks(value) {
|
|
|
93
93
|
const out = { id: c.id, type: c.type, ok: c.ok }
|
|
94
94
|
// path 必须保留:file.exists 失败时 gate 要用它生成 `test -f <path>` 复现命令
|
|
95
95
|
// absPath 必须保留:file.exists 的复现命令要用绝对路径,否则换个 cwd 就指向别的文件
|
|
96
|
-
for (const k of ['detail', 'exitCode', 'cmd', 'path', 'absPath']) if (c[k] !== undefined) out[k] = c[k]
|
|
96
|
+
for (const k of ['detail', 'exitCode', 'cmd', 'path', 'absPath', 'rejected']) if (c[k] !== undefined) out[k] = c[k]
|
|
97
97
|
return out
|
|
98
98
|
})
|
|
99
99
|
}
|
package/lib/core/gate.js
CHANGED
|
@@ -1,81 +1,85 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* D3 · 三态门禁纯函数。
|
|
3
|
-
* decide(contract, evidence) → { decision, reasons, missing, reproCmd? }
|
|
4
|
-
*
|
|
5
|
-
* R1 任一 criterion 的 checkIds 为空,或没有对应 evidence.checks → 最高 YELLOW
|
|
6
|
-
* R2 任一 check.ok === false → RED,reasons 必须包含 reproCmd(可复制执行)
|
|
7
|
-
* R3 全部 criteria 有证据且通过 → GREEN
|
|
8
|
-
*
|
|
9
|
-
* 优先级:RED > YELLOW > GREEN。纯函数,零副作用、零依赖。
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @param {object} contract TaskContract
|
|
14
|
-
* @param {object} evidence Evidence
|
|
15
|
-
*/
|
|
16
|
-
export function decide(contract, evidence) {
|
|
17
|
-
const reasons = []
|
|
18
|
-
const missing = []
|
|
19
|
-
|
|
20
|
-
if (!contract || !Array.isArray(contract.criteria) || contract.criteria.length === 0) {
|
|
21
|
-
return { decision: 'RED', reasons: ['契约没有任何验收条件,不可判通过'], missing: [] }
|
|
22
|
-
}
|
|
23
|
-
const checks = Array.isArray(evidence?.checks) ? evidence.checks : []
|
|
24
|
-
const byId = new Map(checks.map((c) => [c.id, c]))
|
|
25
|
-
|
|
26
|
-
// R2 先行:任一 check 失败即 RED,并给出最小复现命令
|
|
27
|
-
const failed = checks.filter((c) => c.ok === false)
|
|
28
|
-
if (failed.length > 0) {
|
|
29
|
-
const reproCmd = failed.map((c) => reproFor(c)).filter(Boolean).join(' && ')
|
|
30
|
-
for (const c of failed) {
|
|
31
|
-
reasons.push(`check "${c.id}" 失败:${c.detail || c.type}${c.cmd ? `(${c.cmd})` : ''}`)
|
|
32
|
-
}
|
|
33
|
-
if (!reproCmd) reasons.push('未提供可复现命令(reproCmd 为空)')
|
|
34
|
-
return { decision: 'RED', reasons, missing, reproCmd: reproCmd || undefined }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// R1:逐条 criterion 查证据覆盖
|
|
38
|
-
for (const criterion of contract.criteria) {
|
|
39
|
-
const ids = Array.isArray(criterion.checkIds) ? criterion.checkIds : []
|
|
40
|
-
if (ids.length === 0) {
|
|
41
|
-
missing.push(`${criterion.id}: 未绑定 checkIds`)
|
|
42
|
-
continue
|
|
43
|
-
}
|
|
44
|
-
const hit = ids.filter((id) => byId.has(id))
|
|
45
|
-
if (hit.length === 0) {
|
|
46
|
-
missing.push(`${criterion.id}: 没有对应 evidence.checks(需要 ${ids.join(', ')})`)
|
|
47
|
-
} else if (hit.length < ids.length) {
|
|
48
|
-
const absent = ids.filter((id) => !byId.has(id))
|
|
49
|
-
missing.push(`${criterion.id}: 缺少检查 ${absent.join(', ')}`)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (missing.length > 0) {
|
|
54
|
-
reasons.push(`${missing.length} 条验收条件缺少证据,不能判为通过`)
|
|
55
|
-
return { decision: 'YELLOW', reasons, missing }
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// R3:全部覆盖且全通过
|
|
59
|
-
reasons.push(`全部 ${contract.criteria.length} 条验收条件均有通过证据`)
|
|
60
|
-
return { decision: 'GREEN', reasons, missing }
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** 从失败 check 构造可复制执行的最小复现命令(按检查类型给对应命令)。 */
|
|
64
|
-
function reproFor(check) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
1
|
+
/**
|
|
2
|
+
* D3 · 三态门禁纯函数。
|
|
3
|
+
* decide(contract, evidence) → { decision, reasons, missing, reproCmd? }
|
|
4
|
+
*
|
|
5
|
+
* R1 任一 criterion 的 checkIds 为空,或没有对应 evidence.checks → 最高 YELLOW
|
|
6
|
+
* R2 任一 check.ok === false → RED,reasons 必须包含 reproCmd(可复制执行)
|
|
7
|
+
* R3 全部 criteria 有证据且通过 → GREEN
|
|
8
|
+
*
|
|
9
|
+
* 优先级:RED > YELLOW > GREEN。纯函数,零副作用、零依赖。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {object} contract TaskContract
|
|
14
|
+
* @param {object} evidence Evidence
|
|
15
|
+
*/
|
|
16
|
+
export function decide(contract, evidence) {
|
|
17
|
+
const reasons = []
|
|
18
|
+
const missing = []
|
|
19
|
+
|
|
20
|
+
if (!contract || !Array.isArray(contract.criteria) || contract.criteria.length === 0) {
|
|
21
|
+
return { decision: 'RED', reasons: ['契约没有任何验收条件,不可判通过'], missing: [] }
|
|
22
|
+
}
|
|
23
|
+
const checks = Array.isArray(evidence?.checks) ? evidence.checks : []
|
|
24
|
+
const byId = new Map(checks.map((c) => [c.id, c]))
|
|
25
|
+
|
|
26
|
+
// R2 先行:任一 check 失败即 RED,并给出最小复现命令
|
|
27
|
+
const failed = checks.filter((c) => c.ok === false)
|
|
28
|
+
if (failed.length > 0) {
|
|
29
|
+
const reproCmd = failed.map((c) => reproFor(c)).filter(Boolean).join(' && ')
|
|
30
|
+
for (const c of failed) {
|
|
31
|
+
reasons.push(`check "${c.id}" 失败:${c.detail || c.type}${c.cmd ? `(${c.cmd})` : ''}`)
|
|
32
|
+
}
|
|
33
|
+
if (!reproCmd) reasons.push('未提供可复现命令(reproCmd 为空)')
|
|
34
|
+
return { decision: 'RED', reasons, missing, reproCmd: reproCmd || undefined }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// R1:逐条 criterion 查证据覆盖
|
|
38
|
+
for (const criterion of contract.criteria) {
|
|
39
|
+
const ids = Array.isArray(criterion.checkIds) ? criterion.checkIds : []
|
|
40
|
+
if (ids.length === 0) {
|
|
41
|
+
missing.push(`${criterion.id}: 未绑定 checkIds`)
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
const hit = ids.filter((id) => byId.has(id))
|
|
45
|
+
if (hit.length === 0) {
|
|
46
|
+
missing.push(`${criterion.id}: 没有对应 evidence.checks(需要 ${ids.join(', ')})`)
|
|
47
|
+
} else if (hit.length < ids.length) {
|
|
48
|
+
const absent = ids.filter((id) => !byId.has(id))
|
|
49
|
+
missing.push(`${criterion.id}: 缺少检查 ${absent.join(', ')}`)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (missing.length > 0) {
|
|
54
|
+
reasons.push(`${missing.length} 条验收条件缺少证据,不能判为通过`)
|
|
55
|
+
return { decision: 'YELLOW', reasons, missing }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// R3:全部覆盖且全通过
|
|
59
|
+
reasons.push(`全部 ${contract.criteria.length} 条验收条件均有通过证据`)
|
|
60
|
+
return { decision: 'GREEN', reasons, missing }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 从失败 check 构造可复制执行的最小复现命令(按检查类型给对应命令)。 */
|
|
64
|
+
function reproFor(check) {
|
|
65
|
+
// 被白名单拒绝的命令本身不能当复现(它可能退出 0),给可执行提示
|
|
66
|
+
if (check.rejected === true) {
|
|
67
|
+
return `echo "exec 命令未在契约 testCmd 中声明,已拒绝执行" && exit 1`
|
|
68
|
+
}
|
|
69
|
+
if (typeof check.cmd === 'string' && check.cmd.trim() !== '') return check.cmd
|
|
70
|
+
// P1-3 · file.exists:用 node -e 判断,跨平台(不依赖 sh / test -f);
|
|
71
|
+
// 有 absPath 时写绝对路径,保证命令在任何 cwd 下都指向同一文件。
|
|
72
|
+
if (check.type === 'file.exists') {
|
|
73
|
+
const target = typeof check.absPath === 'string' && check.absPath !== '' ? check.absPath : check.path
|
|
74
|
+
if (typeof target === 'string' && target !== '') {
|
|
75
|
+
return `node -e "process.exit(require('node:fs').existsSync(process.argv[1])?0:1)" ${dq(target)}`
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// 其余情况兜底:给一条可直接执行且退出非 0 的真命令,不是装饰性注释
|
|
79
|
+
return `echo "check ${check.id} 无可执行复现命令(该检查类型未提供路径/命令)" && exit 1`
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 双引号包裹(cmd 与 sh 都可解析),内部双引号转义 */
|
|
83
|
+
function dq(value) {
|
|
84
|
+
return '"' + String(value).replace(/"/g, '\\"') + '"'
|
|
85
|
+
}
|
package/package.json
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-swarm-console",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "Run one external agent from DSH, with a visible gate (v0.1 · 门禁可用,画布开发中).",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"deepseek-harness",
|
|
8
|
-
"dsh-plugin",
|
|
9
|
-
"agent",
|
|
10
|
-
"swarm",
|
|
11
|
-
"verification",
|
|
12
|
-
"gate"
|
|
13
|
-
],
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/whyissodifficult/dsh-agent-swarm-console.git",
|
|
17
|
-
"directory": "plugin"
|
|
18
|
-
},
|
|
19
|
-
"license": "MIT",
|
|
20
|
-
"author": "郑志阳 (Walk in the white)",
|
|
21
|
-
"homepage": "https://github.com/whyissodifficult/dsh-agent-swarm-console",
|
|
22
|
-
"bugs": {
|
|
23
|
-
"url": "https://github.com/whyissodifficult/dsh-agent-swarm-console/issues"
|
|
24
|
-
},
|
|
25
|
-
"engines": {
|
|
26
|
-
"node": ">=20.3"
|
|
27
|
-
},
|
|
28
|
-
"exports": {
|
|
29
|
-
".": "./index.js",
|
|
30
|
-
"./locale/*.json": "./locale/*.json",
|
|
31
|
-
"./icon": "./icon.svg"
|
|
32
|
-
},
|
|
33
|
-
"files": [
|
|
34
|
-
"index.js",
|
|
35
|
-
"lib",
|
|
36
|
-
"policies",
|
|
37
|
-
"cordis.patch.yml",
|
|
38
|
-
"locale",
|
|
39
|
-
"docs",
|
|
40
|
-
"icon.svg"
|
|
41
|
-
],
|
|
42
|
-
"dsh": {
|
|
43
|
-
"bundle": {
|
|
44
|
-
"patch": "./cordis.patch.yml"
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-swarm-console",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Run one external agent from DSH, with a visible gate (v0.1 · 门禁可用,画布开发中).",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"deepseek-harness",
|
|
8
|
+
"dsh-plugin",
|
|
9
|
+
"agent",
|
|
10
|
+
"swarm",
|
|
11
|
+
"verification",
|
|
12
|
+
"gate"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/whyissodifficult/dsh-agent-swarm-console.git",
|
|
17
|
+
"directory": "plugin"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "郑志阳 (Walk in the white)",
|
|
21
|
+
"homepage": "https://github.com/whyissodifficult/dsh-agent-swarm-console",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/whyissodifficult/dsh-agent-swarm-console/issues"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=20.3"
|
|
27
|
+
},
|
|
28
|
+
"exports": {
|
|
29
|
+
".": "./index.js",
|
|
30
|
+
"./locale/*.json": "./locale/*.json",
|
|
31
|
+
"./icon": "./icon.svg"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"index.js",
|
|
35
|
+
"lib",
|
|
36
|
+
"policies",
|
|
37
|
+
"cordis.patch.yml",
|
|
38
|
+
"locale",
|
|
39
|
+
"docs",
|
|
40
|
+
"icon.svg"
|
|
41
|
+
],
|
|
42
|
+
"dsh": {
|
|
43
|
+
"bundle": {
|
|
44
|
+
"patch": "./cordis.patch.yml"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|