@stmcw1/dacw 1.1.0 → 1.1.2
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 +60 -133
- package/README_EN.md +58 -129
- package/SAFETY.md +5 -5
- package/SAFETY_EN.md +3 -3
- package/dist/index.js +25 -1
- package/dist/plugin.js +6 -6
- package/dist/state_manager.js +23 -17
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,72 +2,67 @@
|
|
|
2
2
|
<a href="https://stmcw1.github.io/DACW/dacw-workflow.html" target="_blank">
|
|
3
3
|
<img src="https://stmcw1.github.io/DACW/dacw.webp" alt="DACW 架构图" width="100%">
|
|
4
4
|
</a>
|
|
5
|
-
<p><i> 点击 or click</i></p>
|
|
6
5
|
</div>
|
|
7
6
|
|
|
8
7
|
<div align="center">
|
|
9
8
|
|
|
10
9
|
# DACW — 防御性智能体编程工作流
|
|
11
10
|
|
|
11
|
+
[](https://awesome-dsh-plugin.com)
|
|
12
|
+
[](https://www.dsh.so/artifact/dacw/?ref=badge)
|
|
13
|
+
[](https://www.npmjs.com/package/@stmcw1/dacw)
|
|
14
|
+
[](https://nodejs.org)
|
|
15
|
+
|
|
12
16
|
让 AI 写代码,让机器验代码,让人做最终裁决。
|
|
13
17
|
|
|
14
18
|
简体中文 | [English](README_EN.md) | [安全声明](SAFETY.md)
|
|
15
19
|
|
|
16
20
|
</div>
|
|
17
21
|
|
|
18
|
-
DACW
|
|
19
|
-
|
|
20
|
-
## 特性
|
|
21
|
-
|
|
22
|
-
- **三权分立**:写手只产出 JSON 变更集,运行机只执行白名单命令,审查者只输出裁决——没有任何一方能独立合入代码。
|
|
23
|
-
- **子代理零工具隔离**:写手/审查者运行在 persona-only preset 上,插件在 `agent/created` 阶段用 `ctx.tools.restrict({ allow: [] })` 剥除全部继承工具并校验可见工具为 0;隔离失败则拒绝创建子代理。
|
|
24
|
-
- **独立工作区(仅版本控制隔离,测试执行仍在宿主权限下)**:DACW 只在你指定的专用目录内读写与重置文件,不触碰主分支或其他目录;这属于版本控制层面的隔离,测试命令仍以宿主用户权限执行。
|
|
25
|
-
- **执行隔离默认关闭(host)**:`sandbox.mode` 默认 `"host"`——测试在宿主用户权限下运行写手产出的代码(无容器隔离)。可显式配置 `"auto"`:Docker 可用时容器化,不可用时交互询问是否降级(拒绝或无法确认则 fail-closed 停止)。
|
|
26
|
-
- **输出协议 v2**:写手只输出相对基线的变更,未提及文件逐字节保留,减少 token(未提及文件不重复输出),并避免"上轮通过的代码被改坏"。
|
|
27
|
-
- **确定性运行机**:命令白名单(npm / pnpm / yarn / npx / node / python / python3 / pytest / cargo / go)、环境变量白名单、超时强杀、输出截断。
|
|
28
|
-
- **结构化审查**:裁决必须为精确 JSON,解析失败按 REJECTED 处理;PASS 但含可疑字样 → 人工闸门。
|
|
29
|
-
- **可配置模型**:写手/审查者可分别继承父会话路由,或从 DSH 已配置模型目录中选择;启动日志与结果对象显示实际生效的模型。
|
|
30
|
-
- **工作区安全闸门**:仅接受空目录或本插件写入的合法 `.dacw-workspace` 标记;拒绝系统根、用户主目录、`DSH_HOME`/profile 目录;写入前做 realpath + 逐段符号链接校验。
|
|
31
|
-
- **审计记录**:状态文件包含任务、文件清单摘要、测试输出与审查文本,SHA-256 校验(防意外损坏/手滑改写;不防同账号本地用户重算,与审计日志边界一致)。
|
|
32
|
-
- **秘密管控**:写手输出凭据扫描(命中即拒绝该轮)、敏感文件不送模型审查、运行机输出密钥脱敏(`[REDACTED:<类别>]`)。
|
|
33
|
-
- **回滚(人工触发)**:任务开始前捕获回滚点(git HEAD 或工作区备份);`dacw_rollback` 需 `confirm: true` + 交互确认(无交互宿主用 `DACW_ROLLBACK_TOKEN`),git 工作区只给指令、非 git 从备份恢复。
|
|
34
|
-
|
|
35
|
-
> **信任边界**:测试在审查之前执行,审查是侦探性控制而非预防性控制;子代理工具隔离不是代码执行的安全边界。详见 [SAFETY.md](SAFETY.md)。
|
|
22
|
+
DACW 是 **DSH Host 插件**:写手子代理按增量协议产出代码 → 确定性运行机执行项目自带测试 → 独立审查者输出 JSON 裁决 → 停在人工闸门。所有失败与异常路径都收敛到 `NEED_HUMAN`,**绝不自动合入**。
|
|
36
23
|
|
|
37
24
|
## 工作流程
|
|
38
25
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
- 图示与完整边界见封面图 / [docs/dacw-workflow.html](docs/dacw-workflow.html) 与 [SAFETY.md](SAFETY.md)。
|
|
26
|
+
```
|
|
27
|
+
写手 → 协调器(校验/合并/落盘)→ 运行机(项目测试)→ 审查者(JSON 裁决)→ 人工闸门
|
|
28
|
+
```
|
|
43
29
|
|
|
44
|
-
|
|
30
|
+
- 每轮把工作区重置为「基线合并集」,未提及的文件逐字节保留。
|
|
31
|
+
- **测试先于审查执行**:审查是事后控制(侦探性),不是执行前安全屏障;人工闸门是最终兜底。
|
|
32
|
+
- 测试通过后重新枚举工作区与基线对账,任何无法解释的新增/删除/内容变更 → 直接转人工,不进入审查。
|
|
45
33
|
|
|
46
|
-
|
|
34
|
+
## 特性
|
|
47
35
|
|
|
48
|
-
|
|
36
|
+
- **三权分立**:写手只输出变更集,运行机只执行白名单命令,审查者只输出裁决,任何一方都无法独立合入;隔离失败即拒绝运行(fail-closed)。
|
|
37
|
+
- **子代理零工具**:写手/审查者运行在 persona-only preset,创建时剥除全部宿主工具并校验可见工具为 0。
|
|
38
|
+
- **独立工作区**:只在你指定的目录内读写与重置(版本控制层面隔离;测试仍以宿主权限执行),闸门拒绝系统根、用户主目录与 DSH profile 目录。
|
|
39
|
+
- **确定性运行机**:命令/环境变量白名单、超时强杀进程树、输出截断、密钥脱敏。
|
|
40
|
+
- **输出协议 v2**:写手只传变更、未提及文件保留;测试后对账保证「审查对象 === 最终交付物」。
|
|
41
|
+
- **秘密管控三层**:敏感文件不送模型审查,写手输出凭据扫描(命中即拒绝该轮),运行机输出脱敏(`[REDACTED:<类别>]`)。
|
|
42
|
+
- **可配置模型**:写手/审查者独立配置,支持继承父会话/显式 `provider/model`/本地模型。
|
|
43
|
+
- **回滚(人工触发)**:任务开始前捕获回滚点;`dacw_rollback` 需 `confirm: true` + 人工确认(无交互宿主需 `DACW_ROLLBACK_TOKEN`)。
|
|
49
44
|
|
|
50
|
-
>
|
|
45
|
+
> **信任边界**:DACW 会执行模型生成的代码。测试在审查之前运行,审查是侦探性控制;子代理工具隔离不是代码执行的安全边界。详见 [SAFETY.md](SAFETY.md)。
|
|
51
46
|
|
|
52
|
-
|
|
47
|
+
## 安装
|
|
53
48
|
|
|
54
|
-
|
|
49
|
+
**前置要求**:DSH ≥ 0.2.2-rc.1(实测版本),宿主需提供 `ctx.subagents`、`agentPresets`、`tools` 服务;依赖 DSH 官方 `dsh-persona`、`dsh-subagent-spawn-in-process`,不依赖第三方插件。
|
|
55
50
|
|
|
56
|
-
|
|
51
|
+
激活时探测宿主能力,缺失即报「宿主不兼容」并拒绝激活;sandbox 与子代理隔离必须可验证,无法确认的路径一律 fail-closed。构建需要 Node ≥ 24.9;被测试项目的依赖需人工预装。
|
|
57
52
|
|
|
58
53
|
```bash
|
|
59
54
|
node build.mjs # 构建 dist/(Node 内置类型擦除,无需 typescript)
|
|
60
|
-
node selftest.mjs #
|
|
55
|
+
node selftest.mjs # 135 项回归自测
|
|
61
56
|
npm pack --pack-destination ../dacw-pack # 生成安装产物
|
|
62
57
|
```
|
|
63
58
|
|
|
64
|
-
在 DSH 插件管理器中执行 `install_bundle`,target 填 tarball 的绝对路径并加 `file:` 前缀(例如 `file:/absolute/path/to/stmcw1-dacw-1.1.
|
|
59
|
+
在 DSH 插件管理器中执行 `install_bundle`,target 填 tarball 的绝对路径并加 `file:` 前缀(例如 `file:/absolute/path/to/stmcw1-dacw-1.1.1.tgz`)。安装后向 profile 插入 Host 行 `dacw`(bundle 包名 `@stmcw1/dacw`)。**不要用目录路径安装**——会绕过 `files` 白名单,把源码、测试与构建脚本一并装进 profile。
|
|
65
60
|
|
|
66
61
|
升级:改代码 → `node build.mjs` → `npm pack` → `remove_bundle` → `install_bundle` 同一 tarball → 重启 Harness。
|
|
67
62
|
|
|
68
63
|
## 使用
|
|
69
64
|
|
|
70
|
-
模型调用 `dacw_run
|
|
65
|
+
模型调用 `dacw_run`:
|
|
71
66
|
|
|
72
67
|
| 参数 | 必填 | 说明 |
|
|
73
68
|
|---|---|---|
|
|
@@ -75,30 +70,11 @@ npm pack --pack-destination ../dacw-pack # 生成安装产物
|
|
|
75
70
|
| `workspace` | 否 | 专用工作区;绝对路径或相对会话工作目录,省略则用配置值/会话工作目录 |
|
|
76
71
|
| `task_id` | 否 | 审计记录文件名后缀;省略自动生成 |
|
|
77
72
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
| 字段 | 说明 |
|
|
81
|
-
|---|---|
|
|
82
|
-
| `success` / `status` | 机器闸门结果;`status` 恒为 `NEED_HUMAN` |
|
|
83
|
-
| `message` | 人类可读结论 |
|
|
84
|
-
| `workspace` / `files` / `round` | 工作区、产出文件、终止轮次 |
|
|
85
|
-
| `models` | `{ writer, reviewer }`,实际生效的模型 |
|
|
86
|
-
| `logs` / `elapsed_ms` | 日志尾部与耗时 |
|
|
87
|
-
| `task_id` / `rollback_available` | 本次任务 ID(自动生成时也返回)与回滚是否可用 |
|
|
88
|
-
|
|
89
|
-
启动日志示例:
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
🧠 模型配置 | ✍️ 写手: deepseek-account/deepseek-flash(插件配置) | 🔍 审查者: 继承父会话路由(DSH 默认: deepseek-account/deepseek-flash)
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
工作流失败时工具抛出错误(附工作区、状态、轮次与日志尾部),不会把失败伪装成普通结果;所有路径都不提交、不合入。
|
|
73
|
+
返回 `success` / `status`(恒为 `NEED_HUMAN`)/ `message` / `workspace` / `files` / `round` / `models` / `logs` / `elapsed_ms` / `task_id` / `rollback_available`。失败时工具抛错并附工作区、状态、轮次与日志尾部,不把失败伪装成普通结果;所有路径都不提交、不合入。
|
|
96
74
|
|
|
97
75
|
### 在已有项目中使用
|
|
98
76
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
推荐姿势:在项目下新建空子目录作为 workspace,例如:
|
|
77
|
+
不要把项目根目录当 workspace。推荐在项目下建空子目录:
|
|
102
78
|
|
|
103
79
|
```
|
|
104
80
|
your-project/
|
|
@@ -107,69 +83,46 @@ your-project/
|
|
|
107
83
|
└── package.json
|
|
108
84
|
```
|
|
109
85
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
1. **依赖与工具链**:子目录内没有外层项目的 `node_modules`/依赖。测试命令需指向外层工具链,或预先在子目录内安装。纯 Python/Go 等项目同理。
|
|
113
|
-
2. **不要手写伪造 `.dacw-workspace` 标记来绕过空目录检查**。该标记由插件写入,用于标识「本目录允许重置」。手写伪造等于主动让重置逻辑接管该目录——比显式设置 `workspacePolicy: "allow"` 更隐蔽,因为闸门看起来放行了,但重置会直接动手。
|
|
114
|
-
|
|
115
|
-
### 回滚(dacw_rollback)
|
|
116
|
-
|
|
117
|
-
回滚是高影响操作:调用时**必须传 `confirm: true`**(boolean 字面量;缺省或非 `true` 直接拒绝,且不触碰工作区),工具随后请求人类交互确认(DSH `userQuestions`);
|
|
118
|
-
宿主无交互能力时,需在 DSH 宿主环境设置 `DACW_ROLLBACK_TOKEN=<任意非空字符串>`,
|
|
119
|
-
否则拒绝执行。
|
|
86
|
+
每轮只重置 `.dacw-work/` 内的非地基文件,项目其他文件不受影响。子目录不继承外层依赖,测试命令需指向外层工具链或预先安装;纯 Python/Go 项目同理。
|
|
120
87
|
|
|
121
|
-
|
|
88
|
+
> 不要手写伪造 `.dacw-workspace` 标记来绕过空目录检查:标记由插件写入,表示「本目录允许重置」,伪造等于主动让重置逻辑接管该目录。
|
|
122
89
|
|
|
123
|
-
|
|
124
|
-
|---|---|---|
|
|
125
|
-
| `task_id` | 是 | 要回滚的任务 ID(`dacw_run` 返回的 `task_id`) |
|
|
126
|
-
| `confirm` | 是 | 必须为 `true`;`false` / `"true"` / `1` 等非字面量 `true` 一律拒绝 |
|
|
127
|
-
| `workspace` | 否 | 与 `dacw_run` 相同的工作区解析(省略则用配置值/会话工作目录) |
|
|
128
|
-
| `reason` | 否 | 回滚原因,记录到审计,限 500 字符 |
|
|
129
|
-
|
|
130
|
-
- **git 工作区**:返回回滚指令(`git reset --hard <commit>`),不执行任何 git 命令,不修改文件。
|
|
131
|
-
- **非 git 工作区**:从备份恢复。执行前必须通过交互确认或 token 授权。
|
|
90
|
+
### 回滚
|
|
132
91
|
|
|
133
|
-
|
|
92
|
+
`dacw_rollback` 是高影响操作:必须传 `confirm: true`(字面量),随后请求人类交互确认;宿主无交互能力时需设置 `DACW_ROLLBACK_TOKEN`,否则拒绝执行。git 工作区返回回滚指令(DACW 不执行 git 命令);非 git 工作区从备份恢复。回滚后任务终止。
|
|
134
93
|
|
|
135
|
-
##
|
|
94
|
+
## 配置
|
|
136
95
|
|
|
137
|
-
|
|
96
|
+
### 测试执行位置(sandbox)
|
|
138
97
|
|
|
139
|
-
|
|
140
|
-
- 显式 `sandbox.mode: "docker"`:强制容器,Docker 不可用时拒绝运行(不询问、不降级)。
|
|
141
|
-
- 显式 `mode: "host"` 时启动会有一条红色警告(默认值不告警)。
|
|
142
|
-
|
|
143
|
-
> 交互确认文案(仅 `auto` 且 Docker 不可用时触发):未检测到可用的沙盒隔离环境(如 Docker 未安装或未启动)。是否关闭沙盒模式并继续?
|
|
98
|
+
**默认 `host`:执行隔离默认关闭,测试以宿主用户权限运行写手产出的代码。**
|
|
144
99
|
|
|
145
100
|
| 模式 | 行为 |
|
|
146
101
|
|---|---|
|
|
147
|
-
| `host`(默认) |
|
|
148
|
-
| `auto` | Docker 可用 → 一次性容器;不可用 →
|
|
102
|
+
| `host`(默认) | 宿主直执,无隔离;显式配置该值时启动有红色警告 |
|
|
103
|
+
| `auto` | Docker 可用 → 一次性容器;不可用 → 交互确认是否降级,拒绝或无法确认即 fail-closed |
|
|
149
104
|
| `docker` | 强制一次性容器;Docker 不可用 → 直接拒绝运行(不询问、不降级) |
|
|
150
105
|
|
|
106
|
+
docker 容器约束:无网络、只读根文件系统、非 root、`--cap-drop ALL`、`no-new-privileges`、内存/CPU/进程数上限、`--rm` 一次性;工作区先复制到一次性暂存目录再挂载。**docker 模式也不是完美隔离**(共享宿主内核,镜像需可信)。
|
|
107
|
+
|
|
151
108
|
```yaml
|
|
152
109
|
config:
|
|
153
110
|
sandbox:
|
|
154
111
|
mode: host # host(默认)| auto | docker
|
|
155
|
-
image: '' # 空 =
|
|
112
|
+
image: '' # 空 = 按测试命令自动选择镜像
|
|
156
113
|
memoryMb: 1024
|
|
157
|
-
cpus: 1
|
|
114
|
+
cpus: 1
|
|
158
115
|
pidsLimit: 256
|
|
159
116
|
tmpfsMb: 128
|
|
160
117
|
```
|
|
161
118
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
## 模型配置
|
|
165
|
-
|
|
166
|
-
`writerModel` / `reviewerModel` 支持四种取值:
|
|
119
|
+
### 写手 / 审查者模型
|
|
167
120
|
|
|
168
121
|
| 取值 | 行为 |
|
|
169
122
|
|---|---|
|
|
170
123
|
| `null` / `"inherit"` | 继承父会话路由(默认) |
|
|
171
|
-
| `"provider/model"` | 显式指定,并校验 provider
|
|
172
|
-
| `"model"` | 按模型名在 DSH
|
|
124
|
+
| `"provider/model"` | 显式指定,并校验 provider 已注册 |
|
|
125
|
+
| `"model"` | 按模型名在 DSH 已配置模型目录解析唯一 provider |
|
|
173
126
|
| `{ provider?, model, reasoningEffort? }` | 对象形式,`reasoningEffort` 透传给子代理 |
|
|
174
127
|
|
|
175
128
|
```yaml
|
|
@@ -178,56 +131,30 @@ config:
|
|
|
178
131
|
reviewerModel: { model: deepseek-flash, reasoningEffort: high }
|
|
179
132
|
```
|
|
180
133
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
### 可选接入:本地模型
|
|
184
|
-
|
|
185
|
-
如你有本地模型环境或合规要求,可通过 DSH 的 Custom model API(`@deepseek-ai/dsh-llm-pi-ai`)接入 Ollama / LM Studio / vLLM。DACW 侧只需将 `writerModel` / `reviewerModel` 设为 `provider/model` 形式:
|
|
186
|
-
|
|
187
|
-
```yaml
|
|
188
|
-
config:
|
|
189
|
-
writerModel: ollama/qwen2.5-coder
|
|
190
|
-
reviewerModel: lmstudio/local-model
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
DACW 不区分模型来源,防御机制一视同仁。注意:本地小模型能力弱于云端,DACW 会更频繁 fail-closed 转人工——这是预期行为,不是故障。如 DSH 的 `listModels` 返回空,请使用 `provider/model` 显式形式。
|
|
134
|
+
解析失败即 fail-closed,不会静默换用其他模型。本地模型可通过 DSH Custom model API(`@deepseek-ai/dsh-llm-pi-ai`)接入 Ollama / LM Studio / vLLM,配置成 `provider/model` 即可;本地小模型能力较弱,fail-closed 转人工会更频繁,属预期行为。
|
|
194
135
|
|
|
195
136
|
## 安全
|
|
196
137
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
-
|
|
200
|
-
-
|
|
201
|
-
-
|
|
202
|
-
- 敏感文件(`.env`、`*.pem`、`*.key`、`credentials*`、`secrets*`、`id_rsa*` 等)默认不送模型审查(内容不发给模型),但仍交付、保留在 `files` 清单中,message 会标注,需人工审阅。
|
|
203
|
-
- **秘密管控三层**:敏感文件不送模型审查、写手输出凭据扫描(命中即拒绝该轮)、运行机输出密钥脱敏(`[REDACTED:<类别>]`)。
|
|
204
|
-
- 请在专用或一次性环境、最小权限账号下使用,并始终保留人工终审。
|
|
205
|
-
|
|
206
|
-
完整边界、执行顺序与免责声明见 [SAFETY.md](SAFETY.md)。
|
|
138
|
+
- **默认 `host` 无隔离**:测试以宿主用户权限运行写手产出的任意代码(含 `package.json` 的 test/pretest 脚本),结果标注【安全降级】/红色警告;仅在专用或一次性环境、最小权限账号下使用。
|
|
139
|
+
- **审查完整性默认 fail-closed**:审查输入被截断、或锁文件仅送 SHA256 摘要时 `success` 恒为 false;`allowTruncatedReview: true` 可显式放行(**降低安全保证**,message/files/日志会标注)。
|
|
140
|
+
- **敏感文件不送模型审查**:按文件名识别(`.env`、`*.pem`、`*.key`、`credentials*`、`secrets*`、`id_rsa*` 等),内容不发给模型,但仍交付并保留在 `files` 清单中,需人工审阅。
|
|
141
|
+
- **审计边界**:状态文件与日志使用确定性 SHA-256 防意外损坏,不防同账号本地用户重算;需要强证据请导出并外部存证。
|
|
142
|
+
- **人工闸门是最终兜底**:PASS 但含可疑字样、审查不完整、测试后对账不一致等一律转人工。
|
|
207
143
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
| 路径 | 职责 |
|
|
211
|
-
|---|---|
|
|
212
|
-
| `plugin.ts` | DSH Host 半边:工具注册、子代理 preset、运行时工具隔离、模型解析、工作区闸门 |
|
|
213
|
-
| `index.ts` | 协调器:轮次、基线合并、运行机调度、裁决、人工闸门 |
|
|
214
|
-
| `sandbox.ts` | 沙箱策略层:host(默认)/auto/docker 决策、容器参数、Docker 探测、auto 降级确认请求 |
|
|
215
|
-
| `secrets.ts` | 秘密模式共享:写手输出扫描、运行机输出脱敏 |
|
|
216
|
-
| `runner.ts` | 运行机:命令解析、超时强杀、输出截断与密钥脱敏 |
|
|
217
|
-
| `state_manager.ts` | 状态:原子写、SHA-256 校验、串行队列 |
|
|
218
|
-
| `build.mjs` / `selftest.mjs` | 构建(TS → `dist/`)与回归自测 |
|
|
219
|
-
| `cordis.patch.yml` / `locale/` / `icon.png` | 插件清单与展示资源 |
|
|
144
|
+
完整边界、执行顺序与免责声明见 [SAFETY.md](SAFETY.md);已知限制见 [ROADMAP.md](ROADMAP.md)「4b」。
|
|
220
145
|
|
|
221
146
|
## 开发
|
|
222
147
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
148
|
+
```bash
|
|
149
|
+
node build.mjs # dist/ 用 Node 内置类型擦除生成,不依赖 typescript,不入库
|
|
150
|
+
node selftest.mjs # 提交前请执行 build + selftest
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
项目结构:`plugin.ts`(Host 半边)、`index.ts`(协调器)、`runner.ts`(运行机)、`sandbox.ts`(沙箱策略)、`secrets.ts`(秘密检测/脱敏)、`state_manager.ts`(状态)。图示见 [docs/dacw-workflow.html](docs/dacw-workflow.html)。完整配置默认值见 `plugin.ts` 的 `DEFAULT_PLUGIN_CONFIG` 与 `sandbox.ts` 的 `DEFAULT_SANDBOX_CONFIG`(`cordis.patch.yml` 可逐项覆盖)。实验性项目,接口与行为可能变化。
|
|
227
154
|
|
|
228
155
|
## 状态
|
|
229
156
|
|
|
230
|
-
|
|
157
|
+
实验性开发者预览(当前发布版本 `v1.1.1`,bundle `@stmcw1/dacw`):构建冒烟与 135 项回归自测通过;`v1.1.1` 修复回滚后地基文件残留(兼容 1.1.0 旧 state)。默认执行隔离关闭(`host`)。已知限制见 [ROADMAP.md](ROADMAP.md)「4b」。`2.0.0`(engine 重构)在计划中。
|
|
231
158
|
|
|
232
159
|
## 许可证
|
|
233
160
|
|
package/README_EN.md
CHANGED
|
@@ -2,72 +2,67 @@
|
|
|
2
2
|
<a href="https://stmcw1.github.io/DACW/dacw-workflow.html" target="_blank">
|
|
3
3
|
<img src="https://stmcw1.github.io/DACW/dacw.webp" alt="DACW workflow diagram" width="100%">
|
|
4
4
|
</a>
|
|
5
|
-
<p><i>Click to open the workflow diagram (中文)</i></p>
|
|
6
5
|
</div>
|
|
7
6
|
|
|
8
7
|
<div align="center">
|
|
9
8
|
|
|
10
9
|
# DACW — Defensive Agent Coding Workflow
|
|
11
10
|
|
|
11
|
+
[](https://awesome-dsh-plugin.com)
|
|
12
|
+
[](https://www.dsh.so/artifact/dacw/?ref=badge)
|
|
13
|
+
[](https://www.npmjs.com/package/@stmcw1/dacw)
|
|
14
|
+
[](https://nodejs.org)
|
|
15
|
+
|
|
12
16
|
Let AI write the code, let machines verify it, and let humans make the final call.
|
|
13
17
|
|
|
14
18
|
[简体中文](README.md) | English | [Safety](SAFETY_EN.md)
|
|
15
19
|
|
|
16
20
|
</div>
|
|
17
21
|
|
|
18
|
-
DACW is a **DSH Host plugin**: a writer subagent emits code
|
|
19
|
-
|
|
20
|
-
## Features
|
|
21
|
-
|
|
22
|
-
- **Separation of powers**: the writer only emits a JSON changeset, the runner only executes whitelisted commands, the reviewer only emits a verdict — no single party can merge code.
|
|
23
|
-
- **Zero-tool child isolation**: writer/reviewer run on persona-only presets; on `agent/created` the plugin uses `ctx.tools.restrict({ allow: [] })` to strip every inherited tool and verifies the child sees zero tools. If isolation fails, the child is never created.
|
|
24
|
-
- **Independent workspace (version-control isolation only; test execution still runs with host-user privileges)**: DACW reads, writes and resets files only inside the dedicated workspace directory, never touching the main branch or other directories; this is version-control-level isolation, and test commands still execute with host-user privileges.
|
|
25
|
-
- **Execution isolation off by default (host)**: `sandbox.mode` defaults to `"host"` — tests run writer-produced code with host-user privileges (no container isolation). Set `"auto"` explicitly to containerize when Docker is available and to get an interactive confirmation when it is not (keeping the sandbox or being unable to ask fails closed).
|
|
26
|
-
- **Output protocol v2**: the writer emits only deltas against the baseline, untouched files are preserved byte-for-byte, which reduces tokens (untouched files are not re-emitted) and prevents "the code that passed last round got broken" regressions.
|
|
27
|
-
- **Deterministic runner**: command whitelist (npm / pnpm / yarn / npx / node / python / python3 / pytest / cargo / go), environment whitelist, timeout tree-kill, output truncation.
|
|
28
|
-
- **Structured review**: the verdict must be exact JSON; unparseable output is treated as REJECTED; PASS containing suspicious wording goes to the human gate.
|
|
29
|
-
- **Configurable models**: writer/reviewer can each inherit the parent session route or select from the DSH configured-model directory; the startup log and the result object show the models actually in effect.
|
|
30
|
-
- **Workspace safety gate**: accepts only an empty directory or a valid `.dacw-workspace` marker written by this plugin; refuses filesystem roots, the user home directory, and `DSH_HOME`/profile directories; writes are checked with realpath plus per-segment symlink checks.
|
|
31
|
-
- **Audit record**: the state file records the task, file manifest summary, test output and review text, verified with SHA-256 (guards against accidental corruption/edits; not against a same-account local user recomputing it — same boundary as audit logs).
|
|
32
|
-
- **Secret controls**: writer-output credential scanning (a hit rejects that round), sensitive files excluded from model review, runner-output secret redaction (`[REDACTED:<category>]`).
|
|
33
|
-
- **Rollback (human-triggered)**: a rollback point is captured before the task starts (git HEAD or workspace backup); `dacw_rollback` requires `confirm: true` plus interactive confirmation (headless hosts use `DACW_ROLLBACK_TOKEN`); git workspaces get instructions only, non-git workspaces restore from the backup.
|
|
34
|
-
|
|
35
|
-
> **Trust boundary**: tests execute before any review, so review is a detective control, not a preventive one; child tool isolation is not a code-execution security boundary. See [SAFETY_EN.md](SAFETY_EN.md).
|
|
22
|
+
DACW is a **DSH Host plugin**: a writer subagent emits code under an incremental protocol → a deterministic runner executes the project's own tests → an independent reviewer returns a JSON verdict → the workflow stops at the human gate. Every failure and anomaly path converges to `NEED_HUMAN` — **nothing is ever merged automatically**.
|
|
36
23
|
|
|
37
24
|
## How it works
|
|
38
25
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
- Diagram and full boundaries: cover image / [docs/dacw-workflow.html](docs/dacw-workflow.html) and [SAFETY_EN.md](SAFETY_EN.md).
|
|
26
|
+
```
|
|
27
|
+
Writer → Orchestrator (validate / merge / write) → Runner (project tests) → Reviewer (JSON verdict) → Human gate
|
|
28
|
+
```
|
|
43
29
|
|
|
44
|
-
|
|
30
|
+
- Every round resets the workspace to the "baseline merged set"; untouched files are preserved byte-for-byte.
|
|
31
|
+
- **Tests execute before review**: review is a detective (post-hoc) control, not a pre-execution barrier; the human gate is the final backstop.
|
|
32
|
+
- After tests pass, the workspace is re-enumerated and reconciled against the baseline; any unexplained addition/deletion/content change → straight to the human gate, never into review.
|
|
45
33
|
|
|
46
|
-
|
|
34
|
+
## Features
|
|
47
35
|
|
|
48
|
-
|
|
36
|
+
- **Separation of powers**: the writer emits only a changeset, the runner executes only whitelisted commands, the reviewer only emits a verdict — no party can merge code on its own; if isolation fails, the run is refused (fail-closed).
|
|
37
|
+
- **Zero-tool child subagents**: writer/reviewer run on persona-only presets; on creation every inherited host tool is stripped and the child is verified to see zero tools.
|
|
38
|
+
- **Independent workspace**: reads, writes and resets only inside the directory you designate (version-control-level isolation; tests still run with host privileges); the gate refuses filesystem roots, the user home directory and DSH profile directories.
|
|
39
|
+
- **Deterministic runner**: command/environment whitelists, timeout tree-kill, output truncation, secret redaction.
|
|
40
|
+
- **Output protocol v2**: the writer emits only deltas and untouched files are preserved; post-test reconciliation guarantees "what was reviewed === what is delivered".
|
|
41
|
+
- **Secret controls, three layers**: sensitive files are not sent to model review, writer-output credentials are scanned (a hit rejects that round), runner output is redacted (`[REDACTED:<category>]`).
|
|
42
|
+
- **Configurable models**: writer/reviewer configured independently — inherit the parent session, explicit `provider/model`, or local models.
|
|
43
|
+
- **Rollback (human-triggered)**: a rollback point is captured before the task starts; `dacw_rollback` requires `confirm: true` plus human confirmation (headless hosts need `DACW_ROLLBACK_TOKEN`).
|
|
49
44
|
|
|
50
|
-
> **
|
|
45
|
+
> **Trust boundary**: DACW executes model-generated code. Tests run before review, so review is a detective control; child tool isolation is not a code-execution security boundary. See [SAFETY_EN.md](SAFETY_EN.md).
|
|
51
46
|
|
|
52
|
-
|
|
47
|
+
## Install
|
|
53
48
|
|
|
54
|
-
|
|
49
|
+
**Prerequisite**: DSH ≥ 0.2.2-rc.1 (current tested version); the host must provide the `ctx.subagents`, `agentPresets` and `tools` services. DACW depends on DSH's official `dsh-persona` and `dsh-subagent-spawn-in-process`; no third-party plugins are required.
|
|
55
50
|
|
|
56
|
-
|
|
51
|
+
Activation probes the required host capabilities and refuses to activate with a "host incompatible" error when any is missing; sandbox and child isolation must be verifiable — any unconfirmable path fails closed. Building requires Node ≥ 24.9; the tested project's dependencies must be installed manually.
|
|
57
52
|
|
|
58
53
|
```bash
|
|
59
54
|
node build.mjs # build dist/ (Node built-in type stripping, no typescript)
|
|
60
|
-
node selftest.mjs #
|
|
55
|
+
node selftest.mjs # 135 regression vectors
|
|
61
56
|
npm pack --pack-destination ../dacw-pack # produce the install artifact
|
|
62
57
|
```
|
|
63
58
|
|
|
64
|
-
In the DSH plugin manager run `install_bundle` with the tarball's absolute path prefixed by `file:` (
|
|
59
|
+
In the DSH plugin manager run `install_bundle` with the tarball's absolute path prefixed by `file:` (e.g. `file:/absolute/path/to/stmcw1-dacw-1.1.1.tgz`). Installation inserts Host row `dacw` (bundle package `@stmcw1/dacw`) into the profile. **Do not install with a directory path** — it bypasses the `files` whitelist and ships sources, tests and build scripts into the profile.
|
|
65
60
|
|
|
66
61
|
Upgrade: edit sources → `node build.mjs` → `npm pack` → `remove_bundle` → `install_bundle` the same tarball → restart the Harness.
|
|
67
62
|
|
|
68
63
|
## Usage
|
|
69
64
|
|
|
70
|
-
A model calls
|
|
65
|
+
A model calls `dacw_run`:
|
|
71
66
|
|
|
72
67
|
| Argument | Required | Description |
|
|
73
68
|
|---|---|---|
|
|
@@ -75,30 +70,11 @@ A model calls the `dacw_run` tool:
|
|
|
75
70
|
| `workspace` | no | Dedicated workspace; absolute or relative to the session working directory; omitted means the configured value / session working directory |
|
|
76
71
|
| `task_id` | no | Suffix for the audit record filename; auto-generated when omitted |
|
|
77
72
|
|
|
78
|
-
On
|
|
79
|
-
|
|
80
|
-
| Field | Description |
|
|
81
|
-
|---|---|
|
|
82
|
-
| `success` / `status` | Machine-gate result; `status` is always `NEED_HUMAN` |
|
|
83
|
-
| `message` | Human-readable conclusion |
|
|
84
|
-
| `workspace` / `files` / `round` | Workspace, produced files, terminating round |
|
|
85
|
-
| `models` | `{ writer, reviewer }`, the models actually in effect |
|
|
86
|
-
| `logs` / `elapsed_ms` | Log tail and elapsed time |
|
|
87
|
-
| `task_id` / `rollback_available` | The task ID (returned even when auto-generated) and whether rollback is available |
|
|
88
|
-
|
|
89
|
-
Example startup log line:
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
🧠 模型配置 | ✍️ 写手: deepseek-account/deepseek-flash(插件配置) | 🔍 审查者: 继承父会话路由(DSH 默认: deepseek-account/deepseek-flash)
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
On workflow failure the tool throws (including workspace, status, round and log tail) instead of returning a normal failure result; no path commits or merges anything.
|
|
73
|
+
Returns `success` / `status` (always `NEED_HUMAN`) / `message` / `workspace` / `files` / `round` / `models` / `logs` / `elapsed_ms` / `task_id` / `rollback_available`. On failure the tool throws with the workspace, status, round and log tail instead of disguising failure as a normal result; no path commits or merges anything.
|
|
96
74
|
|
|
97
75
|
### Using with an existing project
|
|
98
76
|
|
|
99
|
-
Do not use the project root as the workspace.
|
|
100
|
-
|
|
101
|
-
Recommended setup: create an empty subdirectory under the project as the workspace, e.g.:
|
|
77
|
+
Do not use the project root as the workspace. Recommended setup — create an empty subdirectory under the project:
|
|
102
78
|
|
|
103
79
|
```
|
|
104
80
|
your-project/
|
|
@@ -107,61 +83,40 @@ your-project/
|
|
|
107
83
|
└── package.json
|
|
108
84
|
```
|
|
109
85
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
1. **Dependencies and toolchain**: the subdirectory does not inherit the outer project's `node_modules`/dependencies. Point the test command at the outer toolchain, or install dependencies inside the subdirectory beforehand. Same for pure Python/Go projects.
|
|
113
|
-
2. **Do not hand-craft a `.dacw-workspace` marker to bypass the empty-directory check.** The marker is written by the plugin to signal "this directory may be reset." Hand-crafting it means you are voluntarily handing the directory to the reset logic — more deceptive than setting `workspacePolicy: "allow"`, because the gate appears to pass while reset acts directly.
|
|
114
|
-
|
|
115
|
-
### Rollback (dacw_rollback)
|
|
116
|
-
|
|
117
|
-
Rollback is a high-impact operation: calls **must pass `confirm: true`** (a boolean literal; omitted or any non-`true` value is rejected before touching the filesystem), and the tool then requests an interactive human confirmation (DSH `userQuestions`); when the host has no interaction capability, set `DACW_ROLLBACK_TOKEN=<any non-empty string>` in the DSH host environment — otherwise execution is refused.
|
|
86
|
+
Each round only resets non-foundation files inside `.dacw-work/`; the rest of the project is untouched. The subdirectory does not inherit the outer project's dependencies — point the test command at the outer toolchain or install dependencies inside the subdirectory beforehand; same for pure Python/Go projects.
|
|
118
87
|
|
|
119
|
-
|
|
88
|
+
> Do not hand-craft a `.dacw-workspace` marker to bypass the empty-directory check: the marker is written by the plugin to mean "this directory may be reset"; hand-crafting it voluntarily hands the directory to the reset logic.
|
|
120
89
|
|
|
121
|
-
|
|
122
|
-
|---|---|---|
|
|
123
|
-
| `task_id` | yes | Task ID returned by `dacw_run` |
|
|
124
|
-
| `confirm` | yes | Must be `true`; `false` / `"true"` / `1` and any non-literal-`true` value are rejected |
|
|
125
|
-
| `workspace` | no | Same workspace resolution as `dacw_run` (omitted means the configured value / session working directory) |
|
|
126
|
-
| `reason` | no | Rollback reason recorded in the audit, up to 500 characters |
|
|
127
|
-
|
|
128
|
-
- **git workspaces**: returns rollback instructions (`git reset --hard <commit>`); executes no git command and modifies no files.
|
|
129
|
-
- **Non-git workspaces**: restores from the backup. Interactive confirmation or token authorization is required before execution.
|
|
90
|
+
### Rollback
|
|
130
91
|
|
|
131
|
-
|
|
92
|
+
`dacw_rollback` is a high-impact operation: it **must be called with `confirm: true`** (a literal boolean), then requests interactive human confirmation; when the host has no interaction capability, set `DACW_ROLLBACK_TOKEN` or the call is refused. git workspaces get rollback instructions (DACW executes no git command); non-git workspaces are restored from the backup. The task terminates after rollback.
|
|
132
93
|
|
|
133
|
-
##
|
|
94
|
+
## Configuration
|
|
134
95
|
|
|
135
|
-
|
|
96
|
+
### Where tests execute (sandbox)
|
|
136
97
|
|
|
137
|
-
|
|
138
|
-
- Explicit `sandbox.mode: "docker"`: force a container; when Docker is unavailable the run is refused (no prompt, no downgrade).
|
|
139
|
-
- Explicit `mode: "host"` produces a red startup warning (the default value does not warn).
|
|
140
|
-
|
|
141
|
-
> Confirmation text (only for `auto` when Docker is unavailable): No usable sandboxed isolation environment was detected (e.g. Docker is not installed or not running). Disable sandbox mode and continue?
|
|
98
|
+
**Default `host`: execution isolation is off; tests run writer-produced code with host-user privileges.**
|
|
142
99
|
|
|
143
100
|
| Mode | Behavior |
|
|
144
101
|
|---|---|
|
|
145
|
-
| `host` (default) | Run on the host (no isolation)
|
|
146
|
-
| `auto` | Docker available → one-shot container; unavailable →
|
|
102
|
+
| `host` (default) | Run on the host (no isolation); a red warning is printed at startup when explicitly configured |
|
|
103
|
+
| `auto` | Docker available → one-shot container; unavailable → interactive confirmation whether to downgrade; keep/unavailable → fail-closed |
|
|
147
104
|
| `docker` | Force a one-shot container; Docker unavailable → run refused (no prompt, no downgrade) |
|
|
148
105
|
|
|
106
|
+
Container constraints in `docker` mode: no network, read-only root filesystem, non-root, `--cap-drop ALL`, `no-new-privileges`, memory/CPU/PID limits, `--rm` one-shot; the workspace is copied into a disposable staging directory and mounted. **Docker mode is not perfect isolation either** (shared host kernel, image must be trusted).
|
|
107
|
+
|
|
149
108
|
```yaml
|
|
150
109
|
config:
|
|
151
110
|
sandbox:
|
|
152
111
|
mode: host # host (default) | auto | docker
|
|
153
|
-
image: '' # empty = pick an
|
|
112
|
+
image: '' # empty = pick an image per test command
|
|
154
113
|
memoryMb: 1024
|
|
155
|
-
cpus: 1
|
|
114
|
+
cpus: 1
|
|
156
115
|
pidsLimit: 256
|
|
157
116
|
tmpfsMb: 128
|
|
158
117
|
```
|
|
159
118
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
## Model configuration
|
|
163
|
-
|
|
164
|
-
`writerModel` / `reviewerModel` accept four forms:
|
|
119
|
+
### Writer / reviewer models
|
|
165
120
|
|
|
166
121
|
| Value | Behavior |
|
|
167
122
|
|---|---|
|
|
@@ -176,56 +131,30 @@ config:
|
|
|
176
131
|
reviewerModel: { model: deepseek-flash, reasoningEffort: high }
|
|
177
132
|
```
|
|
178
133
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
### Optional: local models
|
|
182
|
-
|
|
183
|
-
If you have a local model environment or compliance requirements, connect Ollama / LM Studio / vLLM through DSH's Custom model API (`@deepseek-ai/dsh-llm-pi-ai`). On the DACW side you only need to set `writerModel` / `reviewerModel` in `provider/model` form:
|
|
184
|
-
|
|
185
|
-
```yaml
|
|
186
|
-
config:
|
|
187
|
-
writerModel: ollama/qwen2.5-coder
|
|
188
|
-
reviewerModel: lmstudio/local-model
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
DACW does not distinguish model sources — its defenses work the same way. Note: local small models are weaker than cloud models, so DACW will fail closed to the human gate more often — expected behavior, not a malfunction. If DSH's `listModels` returns empty, use the explicit `provider/model` form.
|
|
134
|
+
A resolution failure fails closed and never silently switches models. Local models can be connected through DSH's Custom model API (`@deepseek-ai/dsh-llm-pi-ai` — Ollama / LM Studio / vLLM) by configuring `provider/model`; local small models fail closed to the human gate more often — expected behavior.
|
|
192
135
|
|
|
193
136
|
## Safety
|
|
194
137
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
-
|
|
198
|
-
-
|
|
199
|
-
-
|
|
200
|
-
- Sensitive files (`.env`, `*.pem`, `*.key`, `credentials*`, `secrets*`, `id_rsa*` etc.) are not sent to model review by default (their content is not sent to the model), but they are still delivered and kept in the `files` manifest; the message lists them and they must be reviewed manually.
|
|
201
|
-
- **Secret controls, three layers**: sensitive files are not sent to model review, writer-output credentials are scanned (a hit rejects that round), and runner output is redacted (`[REDACTED:<category>]`).
|
|
202
|
-
- Run in a disposable or dedicated environment under a least-privilege account, and always keep the human gate.
|
|
203
|
-
|
|
204
|
-
See [SAFETY_EN.md](SAFETY_EN.md) for the full boundaries, execution order and disclaimer.
|
|
138
|
+
- **Default `host` has no isolation**: tests run arbitrary writer-produced code (including `package.json` test/pretest scripts) with host-user privileges, flagged as a **[security downgrade]** / red warning; use only in a disposable or dedicated environment under a least-privilege account.
|
|
139
|
+
- **Review completeness is fail-closed by default**: truncated review input or a lockfile sent only as a SHA256 digest makes `success` false; `allowTruncatedReview: true` explicitly lets it pass (**lowers the security guarantee**; message/files/logs are flagged).
|
|
140
|
+
- **Sensitive files are not sent to model review**: identified by filename (`.env`, `*.pem`, `*.key`, `credentials*`, `secrets*`, `id_rsa*`, etc.); their content is not sent to the model, but they are still delivered and kept in the `files` manifest and must be reviewed manually.
|
|
141
|
+
- **Audit boundary**: state files and logs use deterministic SHA-256 against accidental corruption, not against recomputation by a same-account local user; export and store evidence externally when strong evidence is required.
|
|
142
|
+
- **The human gate is the final backstop**: PASS containing suspicious wording, incomplete review, post-test reconciliation mismatch, etc. all route to the human gate.
|
|
205
143
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
| Path | Responsibility |
|
|
209
|
-
|---|---|
|
|
210
|
-
| `plugin.ts` | DSH Host half: tool registration, child presets, runtime tool isolation, model resolution, workspace gate |
|
|
211
|
-
| `index.ts` | Orchestrator: rounds, baseline merge, runner dispatch, verdict, human gate |
|
|
212
|
-
| `sandbox.ts` | Sandbox policy: host (default)/auto/docker decision, container args, Docker detection, auto-downgrade consent request |
|
|
213
|
-
| `secrets.ts` | Shared secret patterns: writer-output scanning and runner-output redaction |
|
|
214
|
-
| `runner.ts` | Runner: command resolution, timeout tree-kill, output truncation and secret redaction |
|
|
215
|
-
| `state_manager.ts` | State: atomic writes, SHA-256 verification, serial queue |
|
|
216
|
-
| `build.mjs` / `selftest.mjs` | Build (TS → `dist/`) and regression self-test |
|
|
217
|
-
| `cordis.patch.yml` / `locale/` / `icon.png` | Plugin manifest and display resources |
|
|
144
|
+
See [SAFETY_EN.md](SAFETY_EN.md) for the full boundaries, execution order and disclaimer; known limitations: [ROADMAP.md](ROADMAP.md) section "4b".
|
|
218
145
|
|
|
219
146
|
## Development
|
|
220
147
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
148
|
+
```bash
|
|
149
|
+
node build.mjs # dist/ is generated with Node built-in type stripping; no typescript, not committed
|
|
150
|
+
node selftest.mjs # run build + selftest before submitting changes
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Project layout: `plugin.ts` (Host half), `index.ts` (orchestrator), `runner.ts` (runner), `sandbox.ts` (sandbox policy), `secrets.ts` (secret detection/redaction), `state_manager.ts` (state). Diagram: [docs/dacw-workflow.html](docs/dacw-workflow.html). Config defaults live in `DEFAULT_PLUGIN_CONFIG` (`plugin.ts`) and `DEFAULT_SANDBOX_CONFIG` (`sandbox.ts`); `cordis.patch.yml` can override each field. Experimental project; interfaces and behavior may change.
|
|
225
154
|
|
|
226
155
|
## Status
|
|
227
156
|
|
|
228
|
-
Experimental developer preview (current
|
|
157
|
+
Experimental developer preview (current release `v1.1.1`, bundle `@stmcw1/dacw`): the build smoke check and 135 regression vectors pass; `v1.1.1` fixes leftover root-level foundation files after rollback (compatible with 1.1.0 state). Execution isolation is off by default (`host`). Known limitations: [ROADMAP.md](ROADMAP.md) section "4b". `2.0.0` (engine refactor) is planned.
|
|
229
158
|
|
|
230
159
|
## License
|
|
231
160
|
|
package/SAFETY.md
CHANGED
|
@@ -25,13 +25,13 @@ DACW 的执行顺序是「写手落盘 → 运行机测试 → 审查者审计
|
|
|
25
25
|
- 出现任何新增(+)、删除(-)、内容变更(~)→ 立即转人工(`success: false`),不进入审查阶段;
|
|
26
26
|
- 对账通过后,审查输入与结果 `files` 清单都只来自对账后的最终清单,且审查读取的是磁盘当前内容。
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
忽略只在**根目录**生效:根级 `.dacw-workspace` 是 DACW 自己的标记文件,无内容风险;根级 `.git` / `node_modules` 不做「无害忽略」,而是记录「存在性 + 顶层条目列表 + SHA256 摘要」指纹——测试期增删其顶层条目或创建/删除整个目录都会转人工;子目录里的同名条目(如 `nested/node_modules/payload.js`)**不忽略**,正常纳入对账与审查,否则测试可以在嵌套目录里投放文件绕过对账。除此之外的一切都必须能解释为"基线声明或测试前已存在",多一个文件也算差异。枚举失败的方向同样 fail-closed:遇到符号链接或非普通文件直接抛错转人工。
|
|
29
29
|
|
|
30
|
-
审查结束、返回 success
|
|
30
|
+
审查结束、返回 success 前再执行一次最终一致性断言:`postDigest`、`finalFiles`、审查循环实际遍历的键集三者必须一致,且再次枚举(文件 + 受保护目录指纹)必须与对账结果完全一致;任一不等(包括审查输入因字符上限被截断、审查期间工作区被改动)→ `success: false` 转人工,绝不放行 success:true。
|
|
31
31
|
|
|
32
|
-
**审查完整性同样 fail-closed
|
|
32
|
+
**审查完整性同样 fail-closed**:审查输入被字符上限截断(单文件或总输入)时,`reviewTruncated` 为真;锁文件只送 SHA256 摘要时,视为未送语义审查(`reviewPartial` 为真,完整性由测试前后 SHA256 对账保证)。默认配置下这两类路径一律禁止 PASS——`success` 恒为 false 并转人工,说明会列出未送审文件、单文件截断位置与总输入上限。唯一逃生门是显式配置 `allowTruncatedReview: true`:此时可放行 success:true,但 message 标注【安全降级】、files 标注未送审项、日志 warn——**这是降低安全保证的显式选择**,默认关闭。
|
|
33
33
|
|
|
34
|
-
**敏感文件默认不送模型审查**:按文件名识别的敏感文件(`.env` / `.env.*` / `*.pem` / `*.key` / `*.p12` / `*.pfx` / `id_rsa*` / `credentials*` / `secrets*` / `.npmrc` / `.netrc` 等)内容不进入审查输入(不发给模型),但文件仍正常交付并保留在 `files` 清单中;`message`
|
|
34
|
+
**敏感文件默认不送模型审查**:按文件名识别的敏感文件(`.env` / `.env.*` / `*.pem` / `*.key` / `*.p12` / `*.pfx` / `id_rsa*` / `credentials*` / `secrets*` / `.npmrc` / `.netrc` 等)内容不进入审查输入(不发给模型),但文件仍正常交付并保留在 `files` 清单中;`message` 会列出被排除文件,合入前必须人工审阅。一致性断言按 `iteratedKeys ∪ reviewExcluded === postDigest.keys()` 校验覆盖完整性。**零送审不放行**:若全部交付文件都被敏感排除(`iteratedKeys.length === 0`),工作流直接 `success:false`、转人工(message 明确「本次无任何文件送模型审查,全部需人工确认」)。被排除清单同时写入状态文件 `reviewExcluded` 字段供审计追溯。
|
|
35
35
|
|
|
36
36
|
差异直接转人工而不是打回重写,原因有三:测试期变更不是写手的产出,写手既看不到也无法解释它;这通常是测试侧注入/篡改或测试设计有问题的信号,需要人工判断现场;打回重写会让下一轮覆盖掉现场证据。
|
|
37
37
|
|
|
@@ -56,7 +56,7 @@ docker 模式的容器约束:`--network none`(无网络)、只读根文件
|
|
|
56
56
|
## 关键边界
|
|
57
57
|
|
|
58
58
|
- **独立工作区(仅版本控制隔离,测试执行仍在宿主权限下)**:DACW 只在指定工作区内读写与重置文件,不修改主分支或其他目录;这是版本控制层面的隔离,不是执行隔离。
|
|
59
|
-
-
|
|
59
|
+
- **执行隔离默认关闭**:测试在宿主用户权限下运行写手产出的代码;容器隔离为可选加强项(仅显式配置 `sandbox.mode: "auto"`/`"docker"` 时启用)。
|
|
60
60
|
- 插件运行在 DSH Host 进程内,通过 `node:fs` 直接读写工作区与状态文件,不经过 DSH 会话的文件沙箱;实际文件权限等于运行 Harness 的系统账号权限。
|
|
61
61
|
- 写手/审查者是真实的子代理会话(可在 profile 中查看);显式配置模型时,任务描述与工作区代码会发送给所选模型提供方。
|
|
62
62
|
- 工作区每轮被重置为非地基文件集,这是设计上的破坏性行为;`workspacePolicy: "allow"` 会跳过空目录/标记检查。
|
package/SAFETY_EN.md
CHANGED
|
@@ -25,11 +25,11 @@ DACW therefore reconciles between a passing test and the review stage:
|
|
|
25
25
|
- Any addition (+), deletion (-) or content change (~) → immediate human gate (`success: false`), the review stage is not entered;
|
|
26
26
|
- Once reconciliation passes, both the review input and the result `files` manifest come only from the reconciled final list, and review reads the current on-disk content.
|
|
27
27
|
|
|
28
|
-
The ignore rules apply **only at the workspace root
|
|
28
|
+
The ignore rules apply **only at the workspace root**. The root `.dacw-workspace` is DACW's own marker file and carries no content risk. The root `.git` / `node_modules` are not simply ignored as "harmless": DACW records a fingerprint of "existence + top-level entry list + SHA256 digest" — adding/removing a top-level entry, or creating/deleting the whole directory during the test, goes to the human gate. Same-named entries in subdirectories (e.g. `nested/node_modules/payload.js`) are **not** ignored and are reconciled and reviewed like any other file; otherwise a test could drop files into nested directories and bypass reconciliation entirely. Everything else must be explainable as "declared in the baseline or already present before the test" — one extra file is a difference. Enumeration failures fail closed the same way: a symlink or non-regular file aborts the reconciliation into the human gate.
|
|
29
29
|
|
|
30
|
-
Before returning success, a final consistency assertion
|
|
30
|
+
Before returning success, a final consistency assertion is enforced: `postDigest`, `finalFiles` and the key set actually iterated by the review loop must all agree, and a fresh enumeration (files plus protected-directory fingerprints) must exactly match the reconciled state; any mismatch (including truncated review input or workspace changes during review) → `success: false` to the human gate, never `success: true`.
|
|
31
31
|
|
|
32
|
-
**Review completeness is likewise fail-closed
|
|
32
|
+
**Review completeness is likewise fail-closed.** When review input is truncated by a character cap (single file or total input), `reviewTruncated` is set; when a lockfile is sent only as a SHA256 digest it counts as not semantically reviewed (`reviewPartial`, with integrity guaranteed by the pre/post-test digest reconciliation). Under the default configuration neither path may pass: `success` is always false and the run goes to the human gate, with a report listing unreviewed files, per-file truncation positions and the total input cap. The only escape hatch is explicitly setting `allowTruncatedReview: true`: truncated/digest-only reviews may then pass, but the message is flagged as a security downgrade, `files` marks the unreviewed items and the log warns — **an explicit choice that lowers the security guarantee**, off by default.
|
|
33
33
|
|
|
34
34
|
**Sensitive files are not sent to model review by default.** Files recognised by name (`.env` / `.env.*` / `*.pem` / `*.key` / `*.p12` / `*.pfx` / `id_rsa*` / `credentials*` / `secrets*` / `.npmrc` / `.netrc` etc.) never enter the review input (their content is not sent to the model), but they are still delivered and kept in the `files` manifest; the `message` lists the excluded files and they must be reviewed manually before merging. The F3 consistency assertion verifies coverage completeness as `iteratedKeys ∪ reviewExcluded === postDigest.keys()`. **Zero reviews never pass**: if every deliverable file is excluded by the sensitive rule (`iteratedKeys.length === 0`), the workflow returns `success:false` and goes to the human gate with the message "no file was sent to model review; all require manual confirmation". The excluded list is also persisted in the state file's `reviewExcluded` field for audit traceability.
|
|
35
35
|
|
package/dist/index.js
CHANGED
|
@@ -129,6 +129,21 @@ const CLEAN_PROTECTED_PATTERNS = [
|
|
|
129
129
|
function isFoundationName(name) {
|
|
130
130
|
return CLEAN_PROTECTED_PATTERNS.some((p)=>p.test(name));
|
|
131
131
|
}
|
|
132
|
+
export async function listRootFoundationFiles(workspaceDir) {
|
|
133
|
+
const resolved = path.resolve(workspaceDir);
|
|
134
|
+
const entries = await fs.readdir(resolved, {
|
|
135
|
+
withFileTypes: true
|
|
136
|
+
});
|
|
137
|
+
const names = [];
|
|
138
|
+
for (const entry of entries){
|
|
139
|
+
if (entry.name === '.git' || entry.name === 'node_modules' || entry.name === '.dacw-workspace') continue;
|
|
140
|
+
if (!entry.isFile()) continue;
|
|
141
|
+
if (!isFoundationName(entry.name)) continue;
|
|
142
|
+
names.push(entry.name);
|
|
143
|
+
}
|
|
144
|
+
names.sort();
|
|
145
|
+
return names;
|
|
146
|
+
}
|
|
132
147
|
function resolveInsideWorkspace(workspaceDir, relPath) {
|
|
133
148
|
const safeDir = path.resolve(workspaceDir);
|
|
134
149
|
const target = path.resolve(safeDir, relPath);
|
|
@@ -638,6 +653,7 @@ export async function captureRollbackPoint(workspaceDir, stateDir, rawTaskId) {
|
|
|
638
653
|
throw new Error(`检测到 .git 但无法读取 HEAD(仓库可能损坏):${e?.message ?? String(e)}`);
|
|
639
654
|
}
|
|
640
655
|
}
|
|
656
|
+
const foundationAtStart = await listRootFoundationFiles(resolvedWorkspace);
|
|
641
657
|
const backupKey = crypto.createHash('sha256').update(String(rawTaskId) + '\n' + resolvedWorkspace).digest('hex').slice(0, 8);
|
|
642
658
|
const backupDir = path.join(resolvedStateDir, 'backup', backupKey);
|
|
643
659
|
await fs.rm(backupDir, {
|
|
@@ -666,7 +682,8 @@ export async function captureRollbackPoint(workspaceDir, stateDir, rawTaskId) {
|
|
|
666
682
|
return {
|
|
667
683
|
mode: 'workspace',
|
|
668
684
|
ref: backupKey,
|
|
669
|
-
capturedAt
|
|
685
|
+
capturedAt,
|
|
686
|
+
foundationAtStart
|
|
670
687
|
};
|
|
671
688
|
}
|
|
672
689
|
export async function rollbackTask(stateDir, rawTaskId, workspaceDir, reason = '用户请求回滚', checksumFn, onBeforeExecute) {
|
|
@@ -745,6 +762,13 @@ export async function rollbackTask(stateDir, rawTaskId, workspaceDir, reason = '
|
|
|
745
762
|
}
|
|
746
763
|
try {
|
|
747
764
|
await safeCleanWorkspace(resolvedWorkspace);
|
|
765
|
+
if (Array.isArray(rollbackPoint.foundationAtStart)) {
|
|
766
|
+
const keptFoundation = new Set(rollbackPoint.foundationAtStart);
|
|
767
|
+
for (const name of (await listRootFoundationFiles(resolvedWorkspace))){
|
|
768
|
+
if (keptFoundation.has(name)) continue;
|
|
769
|
+
await fs.unlink(path.join(resolvedWorkspace, name));
|
|
770
|
+
}
|
|
771
|
+
}
|
|
748
772
|
await fs.cp(backupDir, resolvedWorkspace, {
|
|
749
773
|
recursive: true,
|
|
750
774
|
filter: (src)=>{
|
package/dist/plugin.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as os from 'os';
|
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import { apply as createEngine, isValidWorkspaceMarker, resolveEngineOptions, rollbackTask } from './index.js';
|
|
5
5
|
import { DEFAULT_SANDBOX_CONFIG, normalizeSandboxConfig, parseSandboxConsentAnswer } from './sandbox.js';
|
|
6
|
-
const PLUGIN_VERSION = '1.1.
|
|
6
|
+
const PLUGIN_VERSION = '1.1.2';
|
|
7
7
|
const WRITER_PRESET_ID = 'dacw-writer';
|
|
8
8
|
const REVIEWER_PRESET_ID = 'dacw-reviewer';
|
|
9
9
|
const WORKSPACE_MARKER = '.dacw-workspace';
|
|
@@ -169,7 +169,7 @@ function abortError() {
|
|
|
169
169
|
}
|
|
170
170
|
export function buildActivationSpec(input) {
|
|
171
171
|
const { config, role, text } = input;
|
|
172
|
-
const
|
|
172
|
+
const task = {
|
|
173
173
|
prompt: [
|
|
174
174
|
{
|
|
175
175
|
type: 'text',
|
|
@@ -178,10 +178,10 @@ export function buildActivationSpec(input) {
|
|
|
178
178
|
],
|
|
179
179
|
parent: input.parent
|
|
180
180
|
};
|
|
181
|
-
if (typeof input.cwd === 'string' && input.cwd)
|
|
182
|
-
if (typeof input.presetId === 'string' && input.presetId)
|
|
181
|
+
if (typeof input.cwd === 'string' && input.cwd) task.cwd = input.cwd;
|
|
182
|
+
if (typeof input.presetId === 'string' && input.presetId) task.agentPreset = input.presetId;
|
|
183
183
|
if (input.model) {
|
|
184
|
-
|
|
184
|
+
task.agentOptions = {
|
|
185
185
|
provider: input.model.provider,
|
|
186
186
|
model: input.model.model,
|
|
187
187
|
...input.model.reasoningEffort ? {
|
|
@@ -190,9 +190,9 @@ export function buildActivationSpec(input) {
|
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
192
|
return {
|
|
193
|
+
...task,
|
|
193
194
|
provider: config.subagentProvider,
|
|
194
195
|
label: `dacw-${role}`,
|
|
195
|
-
request,
|
|
196
196
|
signal: input.signal,
|
|
197
197
|
delivery: 'caller'
|
|
198
198
|
};
|
package/dist/state_manager.js
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import * as fs from 'fs/promises';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import * as crypto from 'crypto';
|
|
4
|
+
function serializeChecksumBody(state) {
|
|
5
|
+
const { taskId, round, status, taskPrompt, writtenFiles, testResult, reviewResult, reviewExcluded, secretScanHits, rollbackPoint, rollback, lastError } = state;
|
|
6
|
+
return JSON.stringify({
|
|
7
|
+
taskId,
|
|
8
|
+
round,
|
|
9
|
+
status,
|
|
10
|
+
taskPrompt,
|
|
11
|
+
writtenFiles,
|
|
12
|
+
testResult,
|
|
13
|
+
reviewResult,
|
|
14
|
+
reviewExcluded: reviewExcluded ?? null,
|
|
15
|
+
secretScanHits: secretScanHits ?? null,
|
|
16
|
+
rollbackPoint: rollbackPoint ?? null,
|
|
17
|
+
rollback: rollback ?? null,
|
|
18
|
+
lastError
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const DEFAULT_CHECKSUM_FN = (body)=>crypto.createHash('sha256').update(body).digest('hex');
|
|
4
22
|
export class StateManager {
|
|
5
23
|
stateDir;
|
|
6
24
|
stateFilePath;
|
|
@@ -13,27 +31,15 @@ export class StateManager {
|
|
|
13
31
|
const safeTaskId = rawTaskId.replace(/[^a-zA-Z0-9_\-]/g, '_');
|
|
14
32
|
const idHash = crypto.createHash('sha256').update(String(rawTaskId) + '\n' + String(workspaceDir)).digest('hex').slice(0, 8);
|
|
15
33
|
this.taskId = safeTaskId;
|
|
16
|
-
this.checksumFn = checksumFn ??
|
|
34
|
+
this.checksumFn = checksumFn ?? DEFAULT_CHECKSUM_FN;
|
|
17
35
|
this.stateDir = path.resolve(stateDir);
|
|
18
36
|
this.stateFilePath = path.join(this.stateDir, `state_${safeTaskId}_${idHash}.json`);
|
|
19
37
|
}
|
|
38
|
+
static computeChecksum(state) {
|
|
39
|
+
return DEFAULT_CHECKSUM_FN(serializeChecksumBody(state));
|
|
40
|
+
}
|
|
20
41
|
checksumOf(state) {
|
|
21
|
-
|
|
22
|
-
const body = JSON.stringify({
|
|
23
|
-
taskId,
|
|
24
|
-
round,
|
|
25
|
-
status,
|
|
26
|
-
taskPrompt,
|
|
27
|
-
writtenFiles,
|
|
28
|
-
testResult,
|
|
29
|
-
reviewResult,
|
|
30
|
-
reviewExcluded: reviewExcluded ?? null,
|
|
31
|
-
secretScanHits: secretScanHits ?? null,
|
|
32
|
-
rollbackPoint: rollbackPoint ?? null,
|
|
33
|
-
rollback: rollback ?? null,
|
|
34
|
-
lastError
|
|
35
|
-
});
|
|
36
|
-
return this.checksumFn(body);
|
|
42
|
+
return this.checksumFn(serializeChecksumBody(state));
|
|
37
43
|
}
|
|
38
44
|
async persist(state) {
|
|
39
45
|
await fs.mkdir(this.stateDir, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stmcw1/dacw",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Defensive Agent Coding Workflow (DACW) as a DSH Host plugin: an AI writer proposes code, a deterministic runner tests it, a separate reviewer audits it, and a human gate decides the merge.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dacw",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"LICENSE"
|
|
42
42
|
],
|
|
43
43
|
"engines": {
|
|
44
|
-
"node": ">=
|
|
44
|
+
"node": ">=24.9"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "node build.mjs",
|