dsh-swarm-console 0.1.3 → 0.1.4
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 +103 -88
- package/docs/V1-ACCEPTANCE.md +54 -48
- package/lib/core/verify.js +135 -135
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,88 +1,103 @@
|
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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
|
+
> 已在 DSH 0.2.2-rc.5 上实测:profile 依赖解析为 `^0.1.3`,安装后 `verify_*` 工具与三条斜杠命令均可用。
|
|
37
|
+
|
|
38
|
+
### 从本地目录安装(已验证)
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
plugin_manager install_bundle <本包目录的绝对路径>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
> 注意:以 `link` 方式安装时,卸载该插件会清空被链接目录的内容——请只链接已提交(或已备份)的目录。
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## 快速开始
|
|
48
|
+
|
|
49
|
+
```text
|
|
50
|
+
verify_contract 冻结一个契约(objective / constraints / criteria)
|
|
51
|
+
verify_run 跑证据校验,得到 GREEN / YELLOW / RED
|
|
52
|
+
/gate-status 查看某个契约最近一次判定
|
|
53
|
+
/gate-approve 放行(仅 GREEN 允许,用户手动输入)
|
|
54
|
+
/gate-retry 重算并刷新判定
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
示例:
|
|
58
|
+
|
|
59
|
+
```text
|
|
60
|
+
> verify_contract {"objective":"给 README 加安装节","criteria":[{"id":"c1","text":"安装节存在","checkIds":["k1"]}]}
|
|
61
|
+
contract 5bc483324d46 已冻结
|
|
62
|
+
|
|
63
|
+
> verify_run {"contractId":"5bc483324d46","checks":[{"id":"k1","type":"file.exists","ok":true}]}
|
|
64
|
+
门禁 GREEN:全部 1 条验收条件均有通过证据
|
|
65
|
+
|
|
66
|
+
> /gate-approve 5bc483324d46
|
|
67
|
+
契约 5bc483324d46 已由用户放行(approved)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 能力与限制
|
|
71
|
+
|
|
72
|
+
已实现:
|
|
73
|
+
|
|
74
|
+
- 契约冻结与内容哈希(`contract.id`)
|
|
75
|
+
- 证据分级与三态门禁(`GREEN` / `YELLOW` / `RED`)
|
|
76
|
+
- `RED` 必带可执行复现命令;缺证据不判通过
|
|
77
|
+
- 用户专属放行:`/gate-approve` `/gate-retry` `/gate-status`
|
|
78
|
+
- 外部 agent 适配层(OpenAI 兼容端点,作为原生 subagent run 使用)
|
|
79
|
+
|
|
80
|
+
尚未实现(不承诺):
|
|
81
|
+
|
|
82
|
+
- 可视化画布
|
|
83
|
+
- 多阶段评审状态机
|
|
84
|
+
- 动作卡片:代码保留为可选增强,需目标 profile 挂载 `action-cards` 服务
|
|
85
|
+
- 证据持久化:v1 存在进程内,DSH 重启即丢
|
|
86
|
+
|
|
87
|
+
## 开发与门禁
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npm run gate # probe / selftest / plugin:test / smoke / pack / wiring / dryrun 七段
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
验收记录见 [`docs/V1-ACCEPTANCE.md`](https://github.com/whyissodifficult/dsh-agent-swarm-console/blob/main/plugin/docs/V1-ACCEPTANCE.md):包含斜杠命令链路的日志证据(`command/run`、`command/done`)与三条硬规则的反证。
|
|
94
|
+
|
|
95
|
+
## 链接
|
|
96
|
+
|
|
97
|
+
- 仓库:https://github.com/whyissodifficult/dsh-agent-swarm-console
|
|
98
|
+
- 插件详情:见 [`docs/DETAIL.md`](https://github.com/whyissodifficult/dsh-agent-swarm-console/blob/main/plugin/docs/DETAIL.md)
|
|
99
|
+
- 验收记录:[`docs/V1-ACCEPTANCE.md`](https://github.com/whyissodifficult/dsh-agent-swarm-console/blob/main/plugin/docs/V1-ACCEPTANCE.md)
|
|
100
|
+
|
|
101
|
+
## 许可
|
|
102
|
+
|
|
103
|
+
[MIT](https://github.com/whyissodifficult/dsh-agent-swarm-console/blob/main/LICENSE)
|
package/docs/V1-ACCEPTANCE.md
CHANGED
|
@@ -1,48 +1,54 @@
|
|
|
1
|
-
# v1 验收记录
|
|
2
|
-
|
|
3
|
-
## 1. 验收范围
|
|
4
|
-
|
|
5
|
-
- 版本:0.1.0,基准提交 `58dc124`
|
|
6
|
-
- 覆盖:阶段 3A(可安装 Host 插件骨架)、阶段 4(verify v1 三态门禁)、阶段 5(发布配置)
|
|
7
|
-
- 本文事实以 `58dc124` 为准;放行入口为斜杠命令,门禁卡为可选增强(当前 profile 未挂载 action-cards)
|
|
8
|
-
|
|
9
|
-
## 2. 机器证据(会话日志 session.v4.jsonl.zstd,3186 事件)
|
|
10
|
-
|
|
11
|
-
评审侧逐帧解出的五条 command 事件:
|
|
12
|
-
|
|
13
|
-
| seq | 事件对 | 命令 | 结果 |
|
|
14
|
-
|---|---|---|---|
|
|
15
|
-
| 3150 / 3151 | command/run → command/done | `gate-status` | success:GREEN,尚未放行 |
|
|
16
|
-
| 3152 / 3153 | command/run → command/done | `gate-approve` | success:已由用户放行(approved) |
|
|
17
|
-
| 3154 / 3155 | command/run → command/done | `gate-status` | success:已由 user 放行 @ 时间戳 |
|
|
18
|
-
| 3156 / 3157 | command/run → command/done | `gate-approve` | error:非 GREEN 不可放行,请先 /gate-retry |
|
|
19
|
-
| 3158 / 3159 | command/run → command/done | `gate-retry` | success:重算 YELLOW,需补证据 |
|
|
20
|
-
|
|
21
|
-
**全日志模型侧 gate 类工具调用 0 次** —— H3(放行只能由用户触发)由结构保证:斜杠命令由用户在交互界面输入,模型中不存在对应工具。
|
|
22
|
-
|
|
23
|
-
## 3. 三条硬规则与反证
|
|
24
|
-
|
|
25
|
-
| 规则 | 内容 | 反证(已实测) |
|
|
26
|
-
|---|---|---|
|
|
27
|
-
| H1 | 证据先于验收:没有 evidence 的 criterion 不算通过 | 某 criterion 的 `checkIds` 为空 → 判定必为 YELLOW,不判 GREEN |
|
|
28
|
-
| H2 | RED 必须给可执行的最小复现命令 | 失败 check 未提供 `cmd` → `makeEvidence` 抛错;gate 兜底给 `echo "check X 未提供 cmd" && exit 1`,经 `sh -c` 执行退出非 0 |
|
|
29
|
-
| H3 | 放行只能由用户触发 | agent 身份调 `act(approve)` → refused 并留拒绝事件;实机全日志模型侧 gate 工具调用 0 次 |
|
|
30
|
-
|
|
31
|
-
## 4.
|
|
32
|
-
|
|
33
|
-
- **
|
|
34
|
-
- **npm
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
1
|
+
# v1 验收记录
|
|
2
|
+
|
|
3
|
+
## 1. 验收范围
|
|
4
|
+
|
|
5
|
+
- 版本:0.1.0,基准提交 `58dc124`
|
|
6
|
+
- 覆盖:阶段 3A(可安装 Host 插件骨架)、阶段 4(verify v1 三态门禁)、阶段 5(发布配置)
|
|
7
|
+
- 本文事实以 `58dc124` 为准;放行入口为斜杠命令,门禁卡为可选增强(当前 profile 未挂载 action-cards)
|
|
8
|
+
|
|
9
|
+
## 2. 机器证据(会话日志 session.v4.jsonl.zstd,3186 事件)
|
|
10
|
+
|
|
11
|
+
评审侧逐帧解出的五条 command 事件:
|
|
12
|
+
|
|
13
|
+
| seq | 事件对 | 命令 | 结果 |
|
|
14
|
+
|---|---|---|---|
|
|
15
|
+
| 3150 / 3151 | command/run → command/done | `gate-status` | success:GREEN,尚未放行 |
|
|
16
|
+
| 3152 / 3153 | command/run → command/done | `gate-approve` | success:已由用户放行(approved) |
|
|
17
|
+
| 3154 / 3155 | command/run → command/done | `gate-status` | success:已由 user 放行 @ 时间戳 |
|
|
18
|
+
| 3156 / 3157 | command/run → command/done | `gate-approve` | error:非 GREEN 不可放行,请先 /gate-retry |
|
|
19
|
+
| 3158 / 3159 | command/run → command/done | `gate-retry` | success:重算 YELLOW,需补证据 |
|
|
20
|
+
|
|
21
|
+
**全日志模型侧 gate 类工具调用 0 次** —— H3(放行只能由用户触发)由结构保证:斜杠命令由用户在交互界面输入,模型中不存在对应工具。
|
|
22
|
+
|
|
23
|
+
## 3. 三条硬规则与反证
|
|
24
|
+
|
|
25
|
+
| 规则 | 内容 | 反证(已实测) |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| H1 | 证据先于验收:没有 evidence 的 criterion 不算通过 | 某 criterion 的 `checkIds` 为空 → 判定必为 YELLOW,不判 GREEN |
|
|
28
|
+
| H2 | RED 必须给可执行的最小复现命令 | 失败 check 未提供 `cmd` → `makeEvidence` 抛错;gate 兜底给 `echo "check X 未提供 cmd" && exit 1`,经 `sh -c` 执行退出非 0 |
|
|
29
|
+
| H3 | 放行只能由用户触发 | agent 身份调 `act(approve)` → refused 并留拒绝事件;实机全日志模型侧 gate 工具调用 0 次 |
|
|
30
|
+
|
|
31
|
+
## 4. 发布与安装验证(2026-11-22 补充)
|
|
32
|
+
|
|
33
|
+
- **npm**:`dsh-swarm-console@0.1.3` 已发布,`latest` 指向 0.1.3;tarball 逐文件核对通过(16 文件,含 README / LICENSE / icon.svg / docs)
|
|
34
|
+
- **npm 直装已验证**:在 DSH 0.2.2-rc.5 的「插件 → 添加插件」输入包名安装成功,profile 依赖解析为 `^0.1.3`,
|
|
35
|
+
安装后 `verify_contract` / `verify_run` / `verify_status` 与三条斜杠命令均可用
|
|
36
|
+
- **Plugins 列表截图**:已由用户补(图标、名称、版本、启用开关齐全)
|
|
37
|
+
- **市场/意向表**:已提交(用户侧)
|
|
38
|
+
|
|
39
|
+
仍待补:
|
|
40
|
+
- 真实第三方用户的使用记录(加分项,非阻塞)
|
|
41
|
+
|
|
42
|
+
## 5. 复现命令
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm run gate # 七段门禁一键验证
|
|
46
|
+
node --test plugin/test/*.test.mjs # core / verify / gate-skill / commands 单测
|
|
47
|
+
|
|
48
|
+
# 手动在 DSH 会话里输入(把 <id> 换成 verify_contract 返回的 contractId)
|
|
49
|
+
/gate-status <id>
|
|
50
|
+
/gate-retry <id>
|
|
51
|
+
/gate-approve <id>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
每次命令执行会在会话日志留下 `command/run` 与 `command/done` 事件,可作为放行/重试的机器证据。
|
package/lib/core/verify.js
CHANGED
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* D5/D6 · verify v1 的宿主无关核心。
|
|
3
|
-
* 三工具的纯逻辑 + 卡片 act 的调用者判定,便于不装 DSH 就能单测。
|
|
4
|
-
* 状态用进程内 Map(v1,不做持久化;D8 明确不做多阶段状态机)。
|
|
5
|
-
*/
|
|
6
|
-
import { freezeContract } from './contract.js'
|
|
7
|
-
import { makeEvidence, evidenceHash } from './evidence.js'
|
|
8
|
-
import { decide } from './gate.js'
|
|
9
|
-
|
|
10
|
-
const contracts = new Map()
|
|
11
|
-
const runs = new Map()
|
|
12
|
-
|
|
13
|
-
/** verify_contract:冻结契约,返回 id。 */
|
|
14
|
-
export function verifyContract(input, store = contracts) {
|
|
15
|
-
const c = freezeContract(input)
|
|
16
|
-
store.set(c.id, { contract: c, frozenAt: c.frozenAt })
|
|
17
|
-
return { contractId: c.id }
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* verify_run:跑策略 → 三态判定。
|
|
22
|
-
* H1 证据先于验收:evidence 缺失时不判 GREEN(gate 的 R1 已保证)。
|
|
23
|
-
* policy runner 由调用方注入(composePolicy),这里只做编排与落盘。
|
|
24
|
-
*/
|
|
25
|
-
export function verifyRun({ contractId, evidenceInput, runPolicy }, store = contracts, runStore = runs) {
|
|
26
|
-
const entry = store.get(contractId)
|
|
27
|
-
if (!entry) return { decision: 'RED', reasons: [`未知 contractId ${contractId}`], evidenceHash: '' }
|
|
28
|
-
|
|
29
|
-
// H1:既没有证据输入、也没有策略来产出证据 → 直接判 YELLOW,不伪造证据
|
|
30
|
-
if (!evidenceInput && typeof runPolicy !== 'function') {
|
|
31
|
-
const d = decide(entry.contract, { checks: [], artifacts: [] })
|
|
32
|
-
const ev = makeEvidence({ contractId })
|
|
33
|
-
const hash = evidenceHash(ev)
|
|
34
|
-
runStore.set(contractId, { decision: d.decision, at: new Date().toISOString(), evidenceHash: hash, missing: d.missing, reproCmd: d.reproCmd })
|
|
35
|
-
return {
|
|
36
|
-
decision: d.decision, reasons: d.reasons, evidenceHash: hash,
|
|
37
|
-
missing: d.missing,
|
|
38
|
-
...(d.reproCmd ? { reproCmd: d.reproCmd } : {}),
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const evidence = typeof runPolicy === 'function'
|
|
43
|
-
? runPolicy(entry.contract, evidenceInput)
|
|
44
|
-
: makeEvidence({ contractId, ...evidenceInput })
|
|
45
|
-
|
|
46
|
-
const d = decide(entry.contract, evidence)
|
|
47
|
-
const hash = evidenceHash(evidence)
|
|
48
|
-
runStore.set(contractId, { decision: d.decision, at: new Date().toISOString(), evidenceHash: hash, missing: d.missing, reproCmd: d.reproCmd })
|
|
49
|
-
return {
|
|
50
|
-
decision: d.decision,
|
|
51
|
-
reasons: d.reasons,
|
|
52
|
-
evidenceHash: hash,
|
|
53
|
-
missing: d.missing,
|
|
54
|
-
...(d.reproCmd ? { reproCmd: d.reproCmd } : {}),
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** verify_status:最近一次 decision 与时间。 */
|
|
59
|
-
export function verifyStatus({ contractId }, runStore = runs) {
|
|
60
|
-
const r = runStore.get(contractId)
|
|
61
|
-
// 未知契约返回 known:false,不落进 GREEN/YELLOW/RED 三态(评审必改3)
|
|
62
|
-
if (!r) return { known: false }
|
|
63
|
-
return {
|
|
64
|
-
known: true,
|
|
65
|
-
decision: r.decision,
|
|
66
|
-
at: r.at,
|
|
67
|
-
...(r.reproCmd ? { reproCmd: r.reproCmd } : {}),
|
|
68
|
-
...(Array.isArray(r.missing) && r.missing.length > 0 ? { missing: r.missing } : {}),
|
|
69
|
-
...(r.approved === true ? { approved: true, approvedAt: r.approvedAt } : {}),
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* H3 · act() 的调用者守卫。
|
|
75
|
-
* 非用户(subagent / 代码发起 / 无 session)→ refused + 记拒绝事件。
|
|
76
|
-
* @returns {{status:'refused',reason}|null} null 表示允许继续
|
|
77
|
-
*/
|
|
78
|
-
export function guardCaller(agent, record) {
|
|
79
|
-
const origin = agent?.session?.header?.origin
|
|
80
|
-
const fromAgent = origin === 'subagent' || agent?.fromAgent === true || agent?.origin === 'subagent'
|
|
81
|
-
const live = agent && typeof agent === 'object' && !agent.disposed
|
|
82
|
-
if (!live || fromAgent) {
|
|
83
|
-
const reason = !live ? 'not-live-root' : 'agent-initiated-not-user'
|
|
84
|
-
if (typeof record === 'function') {
|
|
85
|
-
record(agent, { callId: agent?.callId ?? 'unknown', action: 'dsh-swarm-console/gate', phase: 'refused', data: { reason } })
|
|
86
|
-
}
|
|
87
|
-
return { status: 'refused', reason }
|
|
88
|
-
}
|
|
89
|
-
return null
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** 供测试隔离用的空 store。 */
|
|
93
|
-
export function newStores() {
|
|
94
|
-
return { contracts: new Map(), runs: new Map() }
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// ── v1 放行入口:斜杠命令核心(宿主无关)─────────────────────────────
|
|
98
|
-
// 命令只能由用户触发(斜杠命令不走模型工具),H3 由结构保证,不靠 act 守卫。
|
|
99
|
-
// 状态与 verify 同源:契约在 contracts,最近决定在 runs,approved 也写回 runs。
|
|
100
|
-
|
|
101
|
-
/** /gate-approve:非 GREEN 拒绝;GREEN 记 approved 返回成功。 */
|
|
102
|
-
export function gateApprove({ contractId }, store = contracts, runStore = runs) {
|
|
103
|
-
if (!store.has(contractId)) return { kind: 'error', text: `未知契约 ${contractId}` }
|
|
104
|
-
const r = runStore.get(contractId)
|
|
105
|
-
if (!r) return { kind: 'error', text: '尚无门禁决定,请先执行 verify_run' }
|
|
106
|
-
if (r.decision !== 'GREEN') {
|
|
107
|
-
return { kind: 'error', text: `非 GREEN 不可放行,请先 /gate-retry ${contractId}` }
|
|
108
|
-
}
|
|
109
|
-
runStore.set(contractId, { ...r, approved: true, approvedAt: new Date().toISOString(), by: 'user' })
|
|
110
|
-
return { kind: 'success', text: `契约 ${contractId} 已由用户放行(approved)` }
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** /gate-retry:空证据重算 → YELLOW,刷新决定时间戳,提示补证据。 */
|
|
114
|
-
export function gateRetry({ contractId }, store = contracts, runStore = runs) {
|
|
115
|
-
if (!store.has(contractId)) return { kind: 'error', text: `未知契约 ${contractId}` }
|
|
116
|
-
const r = verifyRun({ contractId, evidenceInput: undefined }, store, runStore)
|
|
117
|
-
return {
|
|
118
|
-
kind: 'success',
|
|
119
|
-
text: `契约 ${contractId} 已重算:${r.decision} @ ${verifyStatus({ contractId }, runStore).at}。需重新执行 verify_run 补证据后才可能转 GREEN。`,
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** /gate-status:最近决定 + 时间 + 是否 approved;未知契约 error。 */
|
|
124
|
-
export function gateStatus({ contractId }, store = contracts, runStore = runs) {
|
|
125
|
-
if (!store.has(contractId)) return { kind: 'error', text: `未知契约 ${contractId}` }
|
|
126
|
-
const r = runStore.get(contractId)
|
|
127
|
-
if (!r) return { kind: 'success', text: `契约 ${contractId} 尚无门禁决定` }
|
|
128
|
-
const approved = r.approved === true
|
|
129
|
-
const head = `契约 ${contractId}:最近决定 ${r.decision} @ ${r.at}${approved ? `;已由 ${r.by ?? 'user'} 放行 @ ${r.approvedAt}` : ';尚未放行'}`
|
|
130
|
-
// H2 可见性:RED 必须把复现命令亮给用户,YELLOW 必须把缺失证据亮出来
|
|
131
|
-
const extra = []
|
|
132
|
-
if (r.reproCmd) extra.push(`复现:${r.reproCmd}`)
|
|
133
|
-
if (Array.isArray(r.missing) && r.missing.length > 0) extra.push(`缺失证据:${r.missing.join(';')}`)
|
|
134
|
-
return { kind: 'success', text: [head, ...extra].join('\n') }
|
|
135
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* D5/D6 · verify v1 的宿主无关核心。
|
|
3
|
+
* 三工具的纯逻辑 + 卡片 act 的调用者判定,便于不装 DSH 就能单测。
|
|
4
|
+
* 状态用进程内 Map(v1,不做持久化;D8 明确不做多阶段状态机)。
|
|
5
|
+
*/
|
|
6
|
+
import { freezeContract } from './contract.js'
|
|
7
|
+
import { makeEvidence, evidenceHash } from './evidence.js'
|
|
8
|
+
import { decide } from './gate.js'
|
|
9
|
+
|
|
10
|
+
const contracts = new Map()
|
|
11
|
+
const runs = new Map()
|
|
12
|
+
|
|
13
|
+
/** verify_contract:冻结契约,返回 id。 */
|
|
14
|
+
export function verifyContract(input, store = contracts) {
|
|
15
|
+
const c = freezeContract(input)
|
|
16
|
+
store.set(c.id, { contract: c, frozenAt: c.frozenAt })
|
|
17
|
+
return { contractId: c.id }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* verify_run:跑策略 → 三态判定。
|
|
22
|
+
* H1 证据先于验收:evidence 缺失时不判 GREEN(gate 的 R1 已保证)。
|
|
23
|
+
* policy runner 由调用方注入(composePolicy),这里只做编排与落盘。
|
|
24
|
+
*/
|
|
25
|
+
export function verifyRun({ contractId, evidenceInput, runPolicy }, store = contracts, runStore = runs) {
|
|
26
|
+
const entry = store.get(contractId)
|
|
27
|
+
if (!entry) return { decision: 'RED', reasons: [`未知 contractId ${contractId}`], evidenceHash: '' }
|
|
28
|
+
|
|
29
|
+
// H1:既没有证据输入、也没有策略来产出证据 → 直接判 YELLOW,不伪造证据
|
|
30
|
+
if (!evidenceInput && typeof runPolicy !== 'function') {
|
|
31
|
+
const d = decide(entry.contract, { checks: [], artifacts: [] })
|
|
32
|
+
const ev = makeEvidence({ contractId })
|
|
33
|
+
const hash = evidenceHash(ev)
|
|
34
|
+
runStore.set(contractId, { decision: d.decision, at: new Date().toISOString(), evidenceHash: hash, missing: d.missing, reproCmd: d.reproCmd })
|
|
35
|
+
return {
|
|
36
|
+
decision: d.decision, reasons: d.reasons, evidenceHash: hash,
|
|
37
|
+
missing: d.missing,
|
|
38
|
+
...(d.reproCmd ? { reproCmd: d.reproCmd } : {}),
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const evidence = typeof runPolicy === 'function'
|
|
43
|
+
? runPolicy(entry.contract, evidenceInput)
|
|
44
|
+
: makeEvidence({ contractId, ...evidenceInput })
|
|
45
|
+
|
|
46
|
+
const d = decide(entry.contract, evidence)
|
|
47
|
+
const hash = evidenceHash(evidence)
|
|
48
|
+
runStore.set(contractId, { decision: d.decision, at: new Date().toISOString(), evidenceHash: hash, missing: d.missing, reproCmd: d.reproCmd })
|
|
49
|
+
return {
|
|
50
|
+
decision: d.decision,
|
|
51
|
+
reasons: d.reasons,
|
|
52
|
+
evidenceHash: hash,
|
|
53
|
+
missing: d.missing,
|
|
54
|
+
...(d.reproCmd ? { reproCmd: d.reproCmd } : {}),
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** verify_status:最近一次 decision 与时间。 */
|
|
59
|
+
export function verifyStatus({ contractId }, runStore = runs) {
|
|
60
|
+
const r = runStore.get(contractId)
|
|
61
|
+
// 未知契约返回 known:false,不落进 GREEN/YELLOW/RED 三态(评审必改3)
|
|
62
|
+
if (!r) return { known: false }
|
|
63
|
+
return {
|
|
64
|
+
known: true,
|
|
65
|
+
decision: r.decision,
|
|
66
|
+
at: r.at,
|
|
67
|
+
...(r.reproCmd ? { reproCmd: r.reproCmd } : {}),
|
|
68
|
+
...(Array.isArray(r.missing) && r.missing.length > 0 ? { missing: r.missing } : {}),
|
|
69
|
+
...(r.approved === true ? { approved: true, approvedAt: r.approvedAt } : {}),
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* H3 · act() 的调用者守卫。
|
|
75
|
+
* 非用户(subagent / 代码发起 / 无 session)→ refused + 记拒绝事件。
|
|
76
|
+
* @returns {{status:'refused',reason}|null} null 表示允许继续
|
|
77
|
+
*/
|
|
78
|
+
export function guardCaller(agent, record) {
|
|
79
|
+
const origin = agent?.session?.header?.origin
|
|
80
|
+
const fromAgent = origin === 'subagent' || agent?.fromAgent === true || agent?.origin === 'subagent'
|
|
81
|
+
const live = agent && typeof agent === 'object' && !agent.disposed
|
|
82
|
+
if (!live || fromAgent) {
|
|
83
|
+
const reason = !live ? 'not-live-root' : 'agent-initiated-not-user'
|
|
84
|
+
if (typeof record === 'function') {
|
|
85
|
+
record(agent, { callId: agent?.callId ?? 'unknown', action: 'dsh-swarm-console/gate', phase: 'refused', data: { reason } })
|
|
86
|
+
}
|
|
87
|
+
return { status: 'refused', reason }
|
|
88
|
+
}
|
|
89
|
+
return null
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** 供测试隔离用的空 store。 */
|
|
93
|
+
export function newStores() {
|
|
94
|
+
return { contracts: new Map(), runs: new Map() }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ── v1 放行入口:斜杠命令核心(宿主无关)─────────────────────────────
|
|
98
|
+
// 命令只能由用户触发(斜杠命令不走模型工具),H3 由结构保证,不靠 act 守卫。
|
|
99
|
+
// 状态与 verify 同源:契约在 contracts,最近决定在 runs,approved 也写回 runs。
|
|
100
|
+
|
|
101
|
+
/** /gate-approve:非 GREEN 拒绝;GREEN 记 approved 返回成功。 */
|
|
102
|
+
export function gateApprove({ contractId }, store = contracts, runStore = runs) {
|
|
103
|
+
if (!store.has(contractId)) return { kind: 'error', text: `未知契约 ${contractId}` }
|
|
104
|
+
const r = runStore.get(contractId)
|
|
105
|
+
if (!r) return { kind: 'error', text: '尚无门禁决定,请先执行 verify_run' }
|
|
106
|
+
if (r.decision !== 'GREEN') {
|
|
107
|
+
return { kind: 'error', text: `非 GREEN 不可放行,请先 /gate-retry ${contractId}` }
|
|
108
|
+
}
|
|
109
|
+
runStore.set(contractId, { ...r, approved: true, approvedAt: new Date().toISOString(), by: 'user' })
|
|
110
|
+
return { kind: 'success', text: `契约 ${contractId} 已由用户放行(approved)` }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** /gate-retry:空证据重算 → YELLOW,刷新决定时间戳,提示补证据。 */
|
|
114
|
+
export function gateRetry({ contractId }, store = contracts, runStore = runs) {
|
|
115
|
+
if (!store.has(contractId)) return { kind: 'error', text: `未知契约 ${contractId}` }
|
|
116
|
+
const r = verifyRun({ contractId, evidenceInput: undefined }, store, runStore)
|
|
117
|
+
return {
|
|
118
|
+
kind: 'success',
|
|
119
|
+
text: `契约 ${contractId} 已重算:${r.decision} @ ${verifyStatus({ contractId }, runStore).at}。需重新执行 verify_run 补证据后才可能转 GREEN。`,
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** /gate-status:最近决定 + 时间 + 是否 approved;未知契约 error。 */
|
|
124
|
+
export function gateStatus({ contractId }, store = contracts, runStore = runs) {
|
|
125
|
+
if (!store.has(contractId)) return { kind: 'error', text: `未知契约 ${contractId}` }
|
|
126
|
+
const r = runStore.get(contractId)
|
|
127
|
+
if (!r) return { kind: 'success', text: `契约 ${contractId} 尚无门禁决定` }
|
|
128
|
+
const approved = r.approved === true
|
|
129
|
+
const head = `契约 ${contractId}:最近决定 ${r.decision} @ ${r.at}${approved ? `;已由 ${r.by ?? 'user'} 放行 @ ${r.approvedAt}` : ';尚未放行'}`
|
|
130
|
+
// H2 可见性:RED 必须把复现命令亮给用户,YELLOW 必须把缺失证据亮出来
|
|
131
|
+
const extra = []
|
|
132
|
+
if (r.reproCmd) extra.push(`复现:${r.reproCmd}`)
|
|
133
|
+
if (Array.isArray(r.missing) && r.missing.length > 0) extra.push(`缺失证据:${r.missing.join(';')}`)
|
|
134
|
+
return { kind: 'success', text: [head, ...extra].join('\n') }
|
|
135
|
+
}
|
package/locale/en.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "meta": { "title": "Swarm Console", "description": "Run one external agent from DSH, with a machine-checkable delivery gate; canvas in progress.", "detail": "docs/DETAIL.md" } }
|
|
1
|
+
{ "meta": { "title": "Swarm Console", "description": "Run one external agent from DSH, with a machine-checkable delivery gate; canvas in progress.", "detail": "docs/DETAIL.md" } }
|
package/locale/zh.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "meta": { "title": "Swarm Console 集群控制台", "description": "在 DSH 里跑一个外部 agent,并用可机器验证的门禁确认交付;画布开发中。", "detail": "docs/DETAIL.md" } }
|
|
1
|
+
{ "meta": { "title": "Swarm Console 集群控制台", "description": "在 DSH 里跑一个外部 agent,并用可机器验证的门禁确认交付;画布开发中。", "detail": "docs/DETAIL.md" } }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-swarm-console",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Run one external agent from DSH, with a visible gate (v0.1 路 闂ㄧ鍙敤锛岀敾甯冨紑鍙戜腑).",
|
|
6
6
|
"keywords": ["deepseek-harness", "dsh-plugin", "agent", "swarm", "verification", "gate"],
|