@stmcw1/dacw 1.0.2 → 1.1.0
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 +128 -21
- package/README_EN.md +125 -20
- package/SAFETY.md +59 -6
- package/SAFETY_EN.md +59 -6
- package/cordis.patch.yml +12 -0
- package/dist/index.js +643 -14
- package/dist/plugin.js +444 -67
- package/dist/runner.js +159 -92
- package/dist/sandbox.js +297 -0
- package/dist/secrets.js +42 -0
- package/dist/state_manager.js +13 -11
- package/package.json +2 -5
package/README.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://stmcw1.github.io/DACW/dacw-workflow.html" target="_blank">
|
|
3
|
+
<img src="https://stmcw1.github.io/DACW/dacw.webp" alt="DACW 架构图" width="100%">
|
|
4
|
+
</a>
|
|
5
|
+
<p><i> 点击 or click</i></p>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
1
8
|
<div align="center">
|
|
2
9
|
|
|
3
10
|
# DACW — 防御性智能体编程工作流
|
|
@@ -14,38 +21,47 @@ DACW 是一个 **DSH Host 插件**:写手子代理按增量协议产出代码
|
|
|
14
21
|
|
|
15
22
|
- **三权分立**:写手只产出 JSON 变更集,运行机只执行白名单命令,审查者只输出裁决——没有任何一方能独立合入代码。
|
|
16
23
|
- **子代理零工具隔离**:写手/审查者运行在 persona-only preset 上,插件在 `agent/created` 阶段用 `ctx.tools.restrict({ allow: [] })` 剥除全部继承工具并校验可见工具为 0;隔离失败则拒绝创建子代理。
|
|
17
|
-
-
|
|
18
|
-
-
|
|
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)、环境变量白名单、超时强杀、输出截断。
|
|
19
28
|
- **结构化审查**:裁决必须为精确 JSON,解析失败按 REJECTED 处理;PASS 但含可疑字样 → 人工闸门。
|
|
20
29
|
- **可配置模型**:写手/审查者可分别继承父会话路由,或从 DSH 已配置模型目录中选择;启动日志与结果对象显示实际生效的模型。
|
|
21
30
|
- **工作区安全闸门**:仅接受空目录或本插件写入的合法 `.dacw-workspace` 标记;拒绝系统根、用户主目录、`DSH_HOME`/profile 目录;写入前做 realpath + 逐段符号链接校验。
|
|
22
|
-
- **审计记录**:状态文件包含任务、文件清单摘要、测试输出与审查文本,
|
|
31
|
+
- **审计记录**:状态文件包含任务、文件清单摘要、测试输出与审查文本,SHA-256 校验(防意外损坏/手滑改写;不防同账号本地用户重算,与审计日志边界一致)。
|
|
32
|
+
- **秘密管控**:写手输出凭据扫描(命中即拒绝该轮)、敏感文件不送模型审查、运行机输出密钥脱敏(`[REDACTED:<类别>]`)。
|
|
33
|
+
- **回滚(人工触发)**:任务开始前捕获回滚点(git HEAD 或工作区备份);`dacw_rollback` 需 `confirm: true` + 交互确认(无交互宿主用 `DACW_ROLLBACK_TOKEN`),git 工作区只给指令、非 git 从备份恢复。
|
|
34
|
+
|
|
35
|
+
> **信任边界**:测试在审查之前执行,审查是侦探性控制而非预防性控制;子代理工具隔离不是代码执行的安全边界。详见 [SAFETY.md](SAFETY.md)。
|
|
23
36
|
|
|
24
37
|
## 工作流程
|
|
25
38
|
|
|
26
|
-
|
|
27
|
-
写手(JSON 变更集) → 协调器(校验 / 合并 / 落盘) → 运行机(项目测试)
|
|
28
|
-
│ 失败 → 打回重写(最多 maxRounds 轮)
|
|
29
|
-
审查者(JSON 裁决) → 人工闸门 NEED_HUMAN
|
|
30
|
-
```
|
|
39
|
+
写手(增量 JSON 变更集)→ 协调器(校验 / 合并 / 落盘)→ 运行机(项目测试)→ 审查者(JSON 裁决)→ 人工闸门(`NEED_HUMAN`)。
|
|
31
40
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
3. 运行机按项目类型执行测试(每轮重新嗅探)。
|
|
35
|
-
4. 审查者审计全量文件 + 地基文件(锁文件送 SHA256 摘要)。
|
|
36
|
-
5. 通过后返回 `success: true`、`status: "NEED_HUMAN"`;其余路径同样收敛到人工闸门。
|
|
41
|
+
- **关键约束**:测试先于审查执行(审查是事后控制,不是执行前屏障);每轮把工作区重置为合并集,未提及文件逐字节保留。
|
|
42
|
+
- 图示与完整边界见封面图 / [docs/dacw-workflow.html](docs/dacw-workflow.html) 与 [SAFETY.md](SAFETY.md)。
|
|
37
43
|
|
|
38
44
|
## 安装
|
|
39
45
|
|
|
40
|
-
|
|
46
|
+
> **前置要求(版本+服务)**:**DSH ≥ 0.2.1-rc.5(当前实测版本)**。宿主需支持 `agentPresets` 与 `subagents` 服务(`ctx.subagents` / `agentPresets`,建议使用最新版 DSH)。
|
|
47
|
+
|
|
48
|
+
> **激活探测**:DACW 在激活时探测宿主能力(`ctx.tools.register`、按配置条件要求的 `ctx.tools.restrict`、`agentPresets.register`、`subagents.getProvider/startActivation`),缺失即报「宿主不兼容」并拒绝激活;`spawn` provider 注册仅告警(可能是加载顺序问题),在 `dacw_run` 调用时再次检查并拒绝。
|
|
49
|
+
|
|
50
|
+
> **sandbox fail-closed**:宿主版本过旧或 sandbox 模式(`docker` / `auto`)无法提供容器时拒绝执行测试,不会静默回退到宿主执行;子代理必须运行在零工具 preset 上且隔离必须可验证。
|
|
51
|
+
|
|
52
|
+
依赖说明:DACW 依赖 DSH 宿主提供的 `ctx.subagents`、`agentPresets`、`tools` 服务,以及 DSH 官方的 `dsh-persona`、`dsh-subagent-spawn-in-process`。不依赖第三方或社区插件。
|
|
53
|
+
|
|
54
|
+
状态校验默认确定性 SHA-256(防意外损坏,不防同账号本地用户重算);需要更强防篡改可注入自定义校验函数(编程调用方)。
|
|
55
|
+
|
|
56
|
+
构建需要 Node ≥ 22.13;测试默认在宿主直执(无隔离,需可用的 npm / pytest 等工具链),如需容器隔离请安装 Docker 并设置 `sandbox.mode: "docker"`/`"auto"`;被测试项目的依赖需人工预装。
|
|
41
57
|
|
|
42
58
|
```bash
|
|
43
59
|
node build.mjs # 构建 dist/(Node 内置类型擦除,无需 typescript)
|
|
44
|
-
node selftest.mjs #
|
|
60
|
+
node selftest.mjs # 131 项回归自测
|
|
45
61
|
npm pack --pack-destination ../dacw-pack # 生成安装产物
|
|
46
62
|
```
|
|
47
63
|
|
|
48
|
-
在 DSH 插件管理器中执行 `install_bundle`,target 填 tarball 的绝对路径并加 `file:` 前缀(例如 `file:/absolute/path/to/stmcw1-dacw-1.
|
|
64
|
+
在 DSH 插件管理器中执行 `install_bundle`,target 填 tarball 的绝对路径并加 `file:` 前缀(例如 `file:/absolute/path/to/stmcw1-dacw-1.1.0.tgz`)。安装后向 profile 插入 Host 行 `dacw`(bundle 包名 `@stmcw1/dacw`)。**不要用目录路径安装**——目录安装会绕过 `files` 白名单,把源码、测试与构建脚本一并装进 profile。
|
|
49
65
|
|
|
50
66
|
升级:改代码 → `node build.mjs` → `npm pack` → `remove_bundle` → `install_bundle` 同一 tarball → 重启 Harness。
|
|
51
67
|
|
|
@@ -68,6 +84,7 @@ npm pack --pack-destination ../dacw-pack # 生成安装产物
|
|
|
68
84
|
| `workspace` / `files` / `round` | 工作区、产出文件、终止轮次 |
|
|
69
85
|
| `models` | `{ writer, reviewer }`,实际生效的模型 |
|
|
70
86
|
| `logs` / `elapsed_ms` | 日志尾部与耗时 |
|
|
87
|
+
| `task_id` / `rollback_available` | 本次任务 ID(自动生成时也返回)与回滚是否可用 |
|
|
71
88
|
|
|
72
89
|
启动日志示例:
|
|
73
90
|
|
|
@@ -77,6 +94,73 @@ npm pack --pack-destination ../dacw-pack # 生成安装产物
|
|
|
77
94
|
|
|
78
95
|
工作流失败时工具抛出错误(附工作区、状态、轮次与日志尾部),不会把失败伪装成普通结果;所有路径都不提交、不合入。
|
|
79
96
|
|
|
97
|
+
### 在已有项目中使用
|
|
98
|
+
|
|
99
|
+
不要把项目根目录作为 workspace。默认情况下,工作区安全闸门要求工作区是空目录(或带本插件写入的合法 `.dacw-workspace` 标记),项目根目录会被拒绝。
|
|
100
|
+
|
|
101
|
+
推荐姿势:在项目下新建空子目录作为 workspace,例如:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
your-project/
|
|
105
|
+
├── .dacw-work/ ← workspace,加入 .gitignore
|
|
106
|
+
├── src/
|
|
107
|
+
└── package.json
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
DACW 每轮只重置 `.dacw-work/` 内的非地基文件,项目其他文件不受影响。注意两点:
|
|
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
|
+
否则拒绝执行。
|
|
120
|
+
|
|
121
|
+
调用参数(`dacw_rollback`):
|
|
122
|
+
|
|
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 授权。
|
|
132
|
+
|
|
133
|
+
回滚后任务终止,工作区内容恢复到回滚点。
|
|
134
|
+
|
|
135
|
+
## 沙箱配置
|
|
136
|
+
|
|
137
|
+
测试执行位置由 `config.sandbox` 决定(**默认 `host`:执行隔离默认关闭,测试在宿主用户权限下运行**)。
|
|
138
|
+
|
|
139
|
+
- 需要更强隔离时,可显式配置 `sandbox.mode: "auto"`:Docker 可用时在一次性容器内执行(无网络、只读根文件系统、非 root、cap-drop ALL、资源受限);Docker 不可用时通过 DSH 交互确认询问是否降级——选择保持或无法确认即 fail-closed 停止(不会静默降级)。
|
|
140
|
+
- 显式 `sandbox.mode: "docker"`:强制容器,Docker 不可用时拒绝运行(不询问、不降级)。
|
|
141
|
+
- 显式 `mode: "host"` 时启动会有一条红色警告(默认值不告警)。
|
|
142
|
+
|
|
143
|
+
> 交互确认文案(仅 `auto` 且 Docker 不可用时触发):未检测到可用的沙盒隔离环境(如 Docker 未安装或未启动)。是否关闭沙盒模式并继续?
|
|
144
|
+
|
|
145
|
+
| 模式 | 行为 |
|
|
146
|
+
|---|---|
|
|
147
|
+
| `host`(默认) | 宿主直执(无隔离):执行隔离默认关闭,测试在宿主用户权限下运行 |
|
|
148
|
+
| `auto` | Docker 可用 → 一次性容器;不可用 → 弹出确认,拒绝或无法确认则 fail-closed |
|
|
149
|
+
| `docker` | 强制一次性容器;Docker 不可用 → 直接拒绝运行(不询问、不降级) |
|
|
150
|
+
|
|
151
|
+
```yaml
|
|
152
|
+
config:
|
|
153
|
+
sandbox:
|
|
154
|
+
mode: host # host(默认)| auto | docker
|
|
155
|
+
image: '' # 空 = 按测试命令自动选择官方镜像;也可固定如 node:22-bookworm-slim
|
|
156
|
+
memoryMb: 1024
|
|
157
|
+
cpus: 1 # 允许小数
|
|
158
|
+
pidsLimit: 256
|
|
159
|
+
tmpfsMb: 128
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
docker 模式的容器约束:`--network none`(无网络)、只读根文件系统(仅 /tmp tmpfs 可写)、非 root(uid/gid 1000)、`--cap-drop ALL`、`no-new-privileges`、内存 / CPU / 进程数上限、`--rm` 一次性;工作区复制进一次性暂存目录后挂载,宿主工作区本身不进入容器。首次使用请先 `docker pull` 对应镜像(node 系默认 `node:22-bookworm-slim`,python 系 `python:3.12-slim`,cargo 系 `rust:1-slim`,go 系 `golang:1.23-bookworm`)。
|
|
163
|
+
|
|
80
164
|
## 模型配置
|
|
81
165
|
|
|
82
166
|
`writerModel` / `reviewerModel` 支持四种取值:
|
|
@@ -96,9 +180,30 @@ config:
|
|
|
96
180
|
|
|
97
181
|
解析发生在每次工具调用开始时,DSH 设置变更即时生效;解析失败即 fail-closed,不会静默换用其他模型。
|
|
98
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` 显式形式。
|
|
194
|
+
|
|
99
195
|
## 安全
|
|
100
196
|
|
|
101
|
-
DACW
|
|
197
|
+
DACW 会执行模型生成的代码与命令。**测试在审查之前执行**,审查(含人工终审)是侦探性控制,不是执行前的安全屏障;子代理工具隔离不是代码执行的安全边界。
|
|
198
|
+
|
|
199
|
+
- 默认 `sandbox.mode: "host"`:执行隔离默认关闭,测试在宿主用户权限下运行;可显式配置 `"auto"` 在 Docker 可用时容器化,不可用时交互询问是否降级(拒绝或无法确认则 fail-closed 停止,不会静默降级)。
|
|
200
|
+
- 用户显式确认降级(`auto` 下选择关闭沙盒)或配置 `sandbox.mode: "host"` 时,写手产出的任意代码(含 `package.json` 的 test/pretest 脚本)将以宿主用户全权限运行,结果标注【安全降级】/红色警告;docker 模式也不是完美隔离(共享宿主内核、镜像需可信)。
|
|
201
|
+
- 审查完整性默认 fail-closed:审查输入被字符上限截断、或锁文件只送 SHA256 摘要时,`success` 恒为 false 并转人工;`allowTruncatedReview: true` 可显式放行(**降低安全保证**,message/files/日志会标注)。
|
|
202
|
+
- 敏感文件(`.env`、`*.pem`、`*.key`、`credentials*`、`secrets*`、`id_rsa*` 等)默认不送模型审查(内容不发给模型),但仍交付、保留在 `files` 清单中,message 会标注,需人工审阅。
|
|
203
|
+
- **秘密管控三层**:敏感文件不送模型审查、写手输出凭据扫描(命中即拒绝该轮)、运行机输出密钥脱敏(`[REDACTED:<类别>]`)。
|
|
204
|
+
- 请在专用或一次性环境、最小权限账号下使用,并始终保留人工终审。
|
|
205
|
+
|
|
206
|
+
完整边界、执行顺序与免责声明见 [SAFETY.md](SAFETY.md)。
|
|
102
207
|
|
|
103
208
|
## 项目结构
|
|
104
209
|
|
|
@@ -106,8 +211,10 @@ DACW 会执行模型生成的代码与命令,**不是容器级沙箱**。请
|
|
|
106
211
|
|---|---|
|
|
107
212
|
| `plugin.ts` | DSH Host 半边:工具注册、子代理 preset、运行时工具隔离、模型解析、工作区闸门 |
|
|
108
213
|
| `index.ts` | 协调器:轮次、基线合并、运行机调度、裁决、人工闸门 |
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
214
|
+
| `sandbox.ts` | 沙箱策略层:host(默认)/auto/docker 决策、容器参数、Docker 探测、auto 降级确认请求 |
|
|
215
|
+
| `secrets.ts` | 秘密模式共享:写手输出扫描、运行机输出脱敏 |
|
|
216
|
+
| `runner.ts` | 运行机:命令解析、超时强杀、输出截断与密钥脱敏 |
|
|
217
|
+
| `state_manager.ts` | 状态:原子写、SHA-256 校验、串行队列 |
|
|
111
218
|
| `build.mjs` / `selftest.mjs` | 构建(TS → `dist/`)与回归自测 |
|
|
112
219
|
| `cordis.patch.yml` / `locale/` / `icon.png` | 插件清单与展示资源 |
|
|
113
220
|
|
|
@@ -115,12 +222,12 @@ DACW 会执行模型生成的代码与命令,**不是容器级沙箱**。请
|
|
|
115
222
|
|
|
116
223
|
- `dist/` 由 `build.mjs` 用 Node 内置类型擦除生成,不依赖 `typescript`,也不入库。
|
|
117
224
|
- 提交前请执行 `node build.mjs && node selftest.mjs`。
|
|
118
|
-
- 完整配置项与默认值见 `plugin.ts` 的 `DEFAULT_PLUGIN_CONFIG`(`cordis.patch.yml` 的 `config`
|
|
225
|
+
- 完整配置项与默认值见 `plugin.ts` 的 `DEFAULT_PLUGIN_CONFIG`(`cordis.patch.yml` 的 `config` 可逐项覆盖);沙箱默认值见 `sandbox.ts` 的 `DEFAULT_SANDBOX_CONFIG`。
|
|
119
226
|
- 实验性项目,接口与行为可能变化。
|
|
120
227
|
|
|
121
228
|
## 状态
|
|
122
229
|
|
|
123
|
-
实验性开发者预览(当前版本 `v1.0
|
|
230
|
+
实验性开发者预览(当前版本 `v1.1.0`,bundle `@stmcw1/dacw`):构建冒烟与 131 项回归自测通过。默认执行策略为宿主直执(`sandbox.mode: "host"`,无隔离);`auto`/`docker` 为显式可选(Docker 不可用时 fail-closed / 交互确认,见「沙箱配置」)。**宿主执行闭环验证状态:** v1.1.0 改动了默认执行策略、回滚授权、秘密管控、测试后对账与宿主能力探测,已在 DSH 0.2.2-rc.1 桌面宿主下完成闭环验证:插件激活、`dacw_run` 写手产出 → 测试 → 独立审查 → `NEED_HUMAN`、`dacw_rollback` 工作区恢复、秘密扫描命中拒绝、`userQuestions` 人工确认,五条链路均实测走通。已知限制见 ROADMAP「4b. 已知限制 / 建议优先」。欢迎 issue / PR。
|
|
124
231
|
|
|
125
232
|
## 许可证
|
|
126
233
|
|
package/README_EN.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://stmcw1.github.io/DACW/dacw-workflow.html" target="_blank">
|
|
3
|
+
<img src="https://stmcw1.github.io/DACW/dacw.webp" alt="DACW workflow diagram" width="100%">
|
|
4
|
+
</a>
|
|
5
|
+
<p><i>Click to open the workflow diagram (中文)</i></p>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
1
8
|
<div align="center">
|
|
2
9
|
|
|
3
10
|
# DACW — Defensive Agent Coding Workflow
|
|
@@ -14,38 +21,47 @@ DACW is a **DSH Host plugin**: a writer subagent emits code changes under an inc
|
|
|
14
21
|
|
|
15
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.
|
|
16
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.
|
|
17
|
-
- **
|
|
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.
|
|
18
27
|
- **Deterministic runner**: command whitelist (npm / pnpm / yarn / npx / node / python / python3 / pytest / cargo / go), environment whitelist, timeout tree-kill, output truncation.
|
|
19
28
|
- **Structured review**: the verdict must be exact JSON; unparseable output is treated as REJECTED; PASS containing suspicious wording goes to the human gate.
|
|
20
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.
|
|
21
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.
|
|
22
|
-
- **Audit record**: the state file records the task, file manifest summary, test output and review text,
|
|
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).
|
|
23
36
|
|
|
24
37
|
## How it works
|
|
25
38
|
|
|
26
|
-
|
|
27
|
-
Writer (JSON changeset) → Orchestrator (validate / merge / write) → Runner (project tests)
|
|
28
|
-
│ failure → rewrite (up to maxRounds)
|
|
29
|
-
Reviewer (JSON verdict) → human gate NEED_HUMAN
|
|
30
|
-
```
|
|
39
|
+
Writer (incremental JSON changeset) → Orchestrator (validate / merge / write) → Runner (project tests) → Reviewer (JSON verdict) → human gate (`NEED_HUMAN`).
|
|
31
40
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
3. The runner executes tests by project type (re-sniffed every round).
|
|
35
|
-
4. The reviewer audits the full file set plus foundation files (lockfiles as SHA256 digests).
|
|
36
|
-
5. On PASS the tool returns `success: true` and `status: "NEED_HUMAN"`; every other path also converges to the human gate.
|
|
41
|
+
- **Key constraints**: tests execute before review (review is a detective control, not a pre-execution barrier); every round resets the workspace to the merged set and untouched files are preserved byte-for-byte.
|
|
42
|
+
- Diagram and full boundaries: cover image / [docs/dacw-workflow.html](docs/dacw-workflow.html) and [SAFETY_EN.md](SAFETY_EN.md).
|
|
37
43
|
|
|
38
44
|
## Install
|
|
39
45
|
|
|
40
|
-
|
|
46
|
+
> **Prerequisite (version + services)**: **DSH ≥ 0.2.1-rc.5 (current tested version)**. The host must provide the `agentPresets` and `subagents` services (`ctx.subagents` / `agentPresets`; a recent DSH release is recommended).
|
|
47
|
+
|
|
48
|
+
> **Activation probe**: at activation DACW probes the required host capabilities (`ctx.tools.register`, `ctx.tools.restrict` when required by config, `agentPresets.register`, `subagents.getProvider/startActivation`) and refuses to activate with a "host incompatible" error when any is missing; an unregistered `spawn` provider only logs a warning (possibly a load-order issue) and is checked again — and refused — at `dacw_run` time.
|
|
49
|
+
|
|
50
|
+
> **Sandbox fail-closed**: on an older host, or when sandbox mode (`docker` / `auto`) cannot provide a container, tests are refused (fail-closed) — there is no silent fallback to host execution; subagents must run on zero-tool presets and isolation must be verifiable.
|
|
51
|
+
|
|
52
|
+
Dependencies: DACW relies on the DSH host services `ctx.subagents`, `agentPresets` and `tools`, plus DSH's official `dsh-persona` and `dsh-subagent-spawn-in-process`. No third-party or community plugins are required.
|
|
53
|
+
|
|
54
|
+
State verification uses deterministic SHA-256 by default (guards against accidental corruption; not against recomputation by a same-account local user); callers that need stronger tamper resistance can inject a custom checksum function (programmatic integration).
|
|
55
|
+
|
|
56
|
+
Build requires Node ≥ 22.13; tests run on the host by default (no isolation, requires a working npm / pytest toolchain) — for container isolation install Docker and set `sandbox.mode: "docker"`/`"auto"`; the tested project's dependencies must be installed manually.
|
|
41
57
|
|
|
42
58
|
```bash
|
|
43
59
|
node build.mjs # build dist/ (Node built-in type stripping, no typescript)
|
|
44
|
-
node selftest.mjs #
|
|
60
|
+
node selftest.mjs # 131 regression vectors
|
|
45
61
|
npm pack --pack-destination ../dacw-pack # produce the install artifact
|
|
46
62
|
```
|
|
47
63
|
|
|
48
|
-
In the DSH plugin manager run `install_bundle` with the tarball's absolute path prefixed by `file:` (for example `file:/absolute/path/to/stmcw1-dacw-1.
|
|
64
|
+
In the DSH plugin manager run `install_bundle` with the tarball's absolute path prefixed by `file:` (for example `file:/absolute/path/to/stmcw1-dacw-1.1.0.tgz`). Installation inserts Host row `dacw` (bundle package `@stmcw1/dacw`) into the profile. **Do not install with a directory path** — a directory install bypasses the `files` whitelist and ships sources, tests and build scripts into the profile.
|
|
49
65
|
|
|
50
66
|
Upgrade: edit sources → `node build.mjs` → `npm pack` → `remove_bundle` → `install_bundle` the same tarball → restart the Harness.
|
|
51
67
|
|
|
@@ -68,6 +84,7 @@ On success:
|
|
|
68
84
|
| `workspace` / `files` / `round` | Workspace, produced files, terminating round |
|
|
69
85
|
| `models` | `{ writer, reviewer }`, the models actually in effect |
|
|
70
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 |
|
|
71
88
|
|
|
72
89
|
Example startup log line:
|
|
73
90
|
|
|
@@ -77,6 +94,71 @@ Example startup log line:
|
|
|
77
94
|
|
|
78
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.
|
|
79
96
|
|
|
97
|
+
### Using with an existing project
|
|
98
|
+
|
|
99
|
+
Do not use the project root as the workspace. By default, the workspace safety gate requires the workspace to be an empty directory (or one carrying a valid `.dacw-workspace` marker written by this plugin); the project root will be rejected.
|
|
100
|
+
|
|
101
|
+
Recommended setup: create an empty subdirectory under the project as the workspace, e.g.:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
your-project/
|
|
105
|
+
├── .dacw-work/ ← workspace, add to .gitignore
|
|
106
|
+
├── src/
|
|
107
|
+
└── package.json
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
DACW only resets non-foundation files inside `.dacw-work/` each round; the rest of the project is untouched. Two caveats:
|
|
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.
|
|
118
|
+
|
|
119
|
+
Arguments (`dacw_rollback`):
|
|
120
|
+
|
|
121
|
+
| Argument | Required | Description |
|
|
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.
|
|
130
|
+
|
|
131
|
+
The task terminates after rollback and the workspace is restored to the rollback point.
|
|
132
|
+
|
|
133
|
+
## Sandbox configuration
|
|
134
|
+
|
|
135
|
+
`config.sandbox` decides where tests execute (**`host` by default — execution isolation off, tests run with host-user privileges**).
|
|
136
|
+
|
|
137
|
+
- For stronger isolation, explicitly set `sandbox.mode: "auto"`: Docker available → one-shot container (no network, read-only root filesystem, non-root, cap-drop ALL, resource-limited); Docker unavailable → interactive confirmation asking whether to downgrade — "keep sandbox" or no answer fails closed (never a silent downgrade).
|
|
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?
|
|
142
|
+
|
|
143
|
+
| Mode | Behavior |
|
|
144
|
+
|---|---|
|
|
145
|
+
| `host` (default) | Run on the host (no isolation): execution isolation is off, tests run with host-user privileges |
|
|
146
|
+
| `auto` | Docker available → one-shot container; unavailable → human confirmation; keep/unavailable → fail-closed |
|
|
147
|
+
| `docker` | Force a one-shot container; Docker unavailable → run refused (no prompt, no downgrade) |
|
|
148
|
+
|
|
149
|
+
```yaml
|
|
150
|
+
config:
|
|
151
|
+
sandbox:
|
|
152
|
+
mode: host # host (default) | auto | docker
|
|
153
|
+
image: '' # empty = pick an official image per test command; or pin e.g. node:22-bookworm-slim
|
|
154
|
+
memoryMb: 1024
|
|
155
|
+
cpus: 1 # fractions allowed
|
|
156
|
+
pidsLimit: 256
|
|
157
|
+
tmpfsMb: 128
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Container constraints in docker mode: `--network none` (no network), read-only root filesystem (only a /tmp tmpfs is writable), non-root (uid/gid 1000), `--cap-drop ALL`, `no-new-privileges`, memory / CPU / PID limits, `--rm` one-shot; the workspace is copied into a disposable staging directory and that copy is mounted — the host workspace itself never enters the container. Pre-pull the image on first use (node default `node:22-bookworm-slim`, python `python:3.12-slim`, cargo `rust:1-slim`, go `golang:1.23-bookworm`).
|
|
161
|
+
|
|
80
162
|
## Model configuration
|
|
81
163
|
|
|
82
164
|
`writerModel` / `reviewerModel` accept four forms:
|
|
@@ -96,9 +178,30 @@ config:
|
|
|
96
178
|
|
|
97
179
|
Resolution happens at the start of every tool call, so DSH settings changes apply immediately; a resolution failure fails closed and never silently switches models.
|
|
98
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.
|
|
192
|
+
|
|
99
193
|
## Safety
|
|
100
194
|
|
|
101
|
-
DACW executes model-generated code and commands
|
|
195
|
+
DACW executes model-generated code and commands. **Tests execute before any review**, so review (including the human gate) is a detective control, not a pre-execution security barrier; child tool isolation is not a code-execution security boundary.
|
|
196
|
+
|
|
197
|
+
- Default `sandbox.mode: "host"`: execution isolation is off, tests run with host-user privileges; setting `"auto"` containerizes when Docker is available and asks the human when it is not (keeping it or being unable to ask fails closed, never a silent downgrade).
|
|
198
|
+
- When the user explicitly confirms a downgrade (`auto` with the sandbox disabled) or sets `sandbox.mode: "host"`, arbitrary writer-produced code (including `package.json` test/pretest scripts) runs with the full privileges of the host user, flagged as a **[security downgrade]** / red warning; docker mode is not perfect isolation either (shared host kernel, image must be trusted).
|
|
199
|
+
- Review completeness is fail-closed by default: truncated review input or a lockfile sent only as a digest makes `success` false and routes to the human gate; `allowTruncatedReview: true` explicitly lets it pass (**lowers the security guarantee**; message/files/logs are flagged).
|
|
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.
|
|
102
205
|
|
|
103
206
|
## Project layout
|
|
104
207
|
|
|
@@ -106,8 +209,10 @@ DACW executes model-generated code and commands and is **not a container-grade s
|
|
|
106
209
|
|---|---|
|
|
107
210
|
| `plugin.ts` | DSH Host half: tool registration, child presets, runtime tool isolation, model resolution, workspace gate |
|
|
108
211
|
| `index.ts` | Orchestrator: rounds, baseline merge, runner dispatch, verdict, human gate |
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
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 |
|
|
111
216
|
| `build.mjs` / `selftest.mjs` | Build (TS → `dist/`) and regression self-test |
|
|
112
217
|
| `cordis.patch.yml` / `locale/` / `icon.png` | Plugin manifest and display resources |
|
|
113
218
|
|
|
@@ -115,12 +220,12 @@ DACW executes model-generated code and commands and is **not a container-grade s
|
|
|
115
220
|
|
|
116
221
|
- `dist/` is produced by `build.mjs` with Node built-in type stripping; it needs no `typescript` and is not committed.
|
|
117
222
|
- Run `node build.mjs && node selftest.mjs` before submitting changes.
|
|
118
|
-
- Every config field and its default lives in `DEFAULT_PLUGIN_CONFIG` in `plugin.ts` (each can be overridden in the `config` block of `cordis.patch.yml`).
|
|
223
|
+
- Every config field and its default lives in `DEFAULT_PLUGIN_CONFIG` in `plugin.ts` (each can be overridden in the `config` block of `cordis.patch.yml`); sandbox defaults live in `DEFAULT_SANDBOX_CONFIG` in `sandbox.ts`.
|
|
119
224
|
- Experimental project; interfaces and behavior may change.
|
|
120
225
|
|
|
121
226
|
## Status
|
|
122
227
|
|
|
123
|
-
Experimental developer preview (current version `v1.0
|
|
228
|
+
Experimental developer preview (current version `v1.1.0`, bundle `@stmcw1/dacw`): the build smoke check and 131 regression vectors pass. The default execution policy is host (no isolation); `auto`/`docker` are explicit opt-ins (fail-closed / interactive confirmation when Docker is unavailable — see "Sandbox configuration"). **Live host-execution loop status:** v1.1.0 changed the default execution policy, rollback authorization, secret controls, post-test reconciliation and host capability probe, and **has completed the closed-loop verification on the DSH `0.2.2-rc.1` desktop host** (2026-11-06): plugin activation, `dacw_run` writer output → test → independent review → `NEED_HUMAN`, `dacw_rollback` workspace restore, secret-scan hit rejection, and `userQuestions` human confirmation — all five paths measured in effect. Known limitations: see ROADMAP "4b. Known limitations / Prioritized suggestions". Issues and PRs are welcome.
|
|
124
229
|
|
|
125
230
|
## License
|
|
126
231
|
|
package/SAFETY.md
CHANGED
|
@@ -4,26 +4,79 @@
|
|
|
4
4
|
|
|
5
5
|
## 实验性状态
|
|
6
6
|
|
|
7
|
-
DACW 是实验性开发者预览插件,未经安全审计,不得用于生产环境。它会执行模型生成的代码与命令(npm / pytest / cargo / go
|
|
7
|
+
DACW 是实验性开发者预览插件,未经安全审计,不得用于生产环境。它会执行模型生成的代码与命令(npm / pytest / cargo / go 等);错误的模型输出、缺陷、配置错误或恶意输入可能损坏宿主、泄露数据或造成其他非预期影响。
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## 执行顺序与审查的局限(重要)
|
|
10
10
|
|
|
11
|
-
DACW
|
|
11
|
+
DACW 的执行顺序是「写手落盘 → 运行机测试 → 审查者审计 → 人工闸门」:
|
|
12
|
+
|
|
13
|
+
- **测试在所有审查之前执行**。审查者(无论是模型还是人工)看到的代码都已经被执行过一次;审查是侦探性控制(发现已发生的问题),**不是预防性控制**(阻止执行)。
|
|
14
|
+
- **子代理工具隔离不是代码执行的安全边界**。它只约束写手/审查者子代理能否调用宿主工具,不约束运行机执行的测试子进程。
|
|
15
|
+
- 写手可以直接修改 `package.json` 的 `scripts` 字段(`test`/`pretest`/`posttest` 等),测试命令会执行其中的任意命令;测试代码本身也由写手产出。因此**不能把"审查者先看过"当作代码执行的安全保证**。
|
|
16
|
+
|
|
17
|
+
## 测试后对账(审查对象 === 最终交付物)
|
|
18
|
+
|
|
19
|
+
测试命令执行的是写手产出的代码,它完全可以在测试期间改写工作区:新建文件、删除文件、篡改已生成文件的内容(例如在测试脚本里 `fs.writeFileSync('unreviewed.js', ...)`,或向交付文件追写代码)。如果审查只看"写手声明的基线清单",这些测试期变更就会绕过审查进入最终交付。
|
|
20
|
+
|
|
21
|
+
因此 DACW 在测试通过后、审查开始前强制对账:
|
|
22
|
+
|
|
23
|
+
- 测试前对工作区做一次 SHA256 快照:期望状态 = 写手基线 ∪ 测试前已存在的地基文件(package.json 等);基线部分必须与落盘内容逐字节一致,否则直接转人工;
|
|
24
|
+
- 测试通过后重新递归枚举工作区并计算 SHA256,与快照逐文件比对;
|
|
25
|
+
- 出现任何新增(+)、删除(-)、内容变更(~)→ 立即转人工(`success: false`),不进入审查阶段;
|
|
26
|
+
- 对账通过后,审查输入与结果 `files` 清单都只来自对账后的最终清单,且审查读取的是磁盘当前内容。
|
|
27
|
+
|
|
28
|
+
忽略只在**根目录**生效(F1):根级 `.dacw-workspace` 是 DACW 自己的标记文件,无内容风险;根级 `.git` / `node_modules` 不做「无害忽略」,而是记录「存在性 + 顶层条目列表 + SHA256 摘要」指纹(F2)——测试期增删其顶层条目或创建/删除整个目录都会转人工;子目录里的同名条目(如 `nested/node_modules/payload.js`)**不忽略**,正常纳入对账与审查,否则测试可以在嵌套目录里投放文件绕过对账。除此之外的一切都必须能解释为"基线声明或测试前已存在",多一个文件也算差异。枚举失败的方向同样 fail-closed:遇到符号链接或非普通文件直接抛错转人工。
|
|
29
|
+
|
|
30
|
+
审查结束、返回 success 前再执行一次最终一致性断言(F3):`postDigest`、`finalFiles`、审查循环实际遍历的键集三者必须一致,且再次枚举(文件 + 受保护目录指纹)必须与对账结果完全一致;任一不等(包括审查输入因字符上限被截断、审查期间工作区被改动)→ `success: false` 转人工,绝不放行 success:true。
|
|
31
|
+
|
|
32
|
+
**审查完整性同样 fail-closed(G 组)**:审查输入被字符上限截断(单文件或总输入)时,`reviewTruncated` 为真;锁文件只送 SHA256 摘要时,视为未送语义审查(`reviewPartial` 为真,完整性由测试前后 SHA256 对账保证)。默认配置下这两类路径一律禁止 PASS——`success` 恒为 false 并转人工,说明会列出未送审文件、单文件截断位置与总输入上限。唯一逃生门是显式配置 `allowTruncatedReview: true`:此时可放行 success:true,但 message 标注【安全降级】、files 标注未送审项、日志 warn——**这是降低安全保证的显式选择**,默认关闭。
|
|
33
|
+
|
|
34
|
+
**敏感文件默认不送模型审查**:按文件名识别的敏感文件(`.env` / `.env.*` / `*.pem` / `*.key` / `*.p12` / `*.pfx` / `id_rsa*` / `credentials*` / `secrets*` / `.npmrc` / `.netrc` 等)内容不进入审查输入(不发给模型),但文件仍正常交付并保留在 `files` 清单中;`message` 会列出被排除文件,合入前必须人工审阅。F3 一致性断言按 `iteratedKeys ∪ reviewExcluded === postDigest.keys()` 校验覆盖完整性。**零送审不放行**:若全部交付文件都被敏感排除(`iteratedKeys.length === 0`),工作流直接 `success:false`、转人工(message 明确「本次无任何文件送模型审查,全部需人工确认」)。被排除清单同时写入状态文件 `reviewExcluded` 字段供审计追溯。
|
|
35
|
+
|
|
36
|
+
差异直接转人工而不是打回重写,原因有三:测试期变更不是写手的产出,写手既看不到也无法解释它;这通常是测试侧注入/篡改或测试设计有问题的信号,需要人工判断现场;打回重写会让下一轮覆盖掉现场证据。
|
|
37
|
+
|
|
38
|
+
## 沙箱(测试执行位置)
|
|
39
|
+
|
|
40
|
+
执行隔离默认关闭:测试在宿主用户权限下运行写手产出的代码。可显式配置 `sandbox.mode: "auto"`:Docker 可用时在一次性容器内执行,不可用时弹出「是否关闭沙盒」的人类确认——选择保持或无法确认即 fail-closed 停止(不会静默降级)。
|
|
41
|
+
|
|
42
|
+
测试执行位置由 `config.sandbox` 决定:
|
|
43
|
+
|
|
44
|
+
| 模式 | 行为 | 隔离程度 |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| `host`(默认) | 宿主直执:写手产出的代码以宿主用户全权限运行(执行隔离默认关闭;启动有红色警告) | **无隔离** |
|
|
47
|
+
| `auto`(可选) | Docker 可用 → 一次性容器;不可用 → 弹出人工确认,保持/无法确认则 **拒绝执行测试**(fail-closed) | 容器级(见下) |
|
|
48
|
+
| `docker`(可选) | 强制一次性容器;Docker 不可用时**直接拒绝运行**(不询问、不降级) | 容器级(见下) |
|
|
49
|
+
|
|
50
|
+
docker 模式的容器约束:`--network none`(无网络)、只读根文件系统(仅 /tmp tmpfs 可写)、非 root 用户(uid/gid 1000)、`--cap-drop ALL`、`no-new-privileges`、内存 / CPU / 进程数上限、`--rm` 一次性;工作区先复制到一次性暂存目录再挂载进容器,**宿主工作区本身不进入容器**。
|
|
51
|
+
|
|
52
|
+
**docker 模式也不是完美隔离**:容器共享宿主内核,镜像必须可信(仅使用官方或经审查的镜像),Docker Desktop 的文件共享层有自身攻击面;首次使用前请预拉取镜像,否则可能因拉取耗时触发测试超时。
|
|
53
|
+
|
|
54
|
+
默认 host(或 `auto` 下用户确认关闭沙盒)时,写手产出的任意代码(包括 `package.json` 的 test/pretest 等脚本)都以宿主用户全权限运行;结果消息会标注【安全降级】/执行位置,日志有红色警告。host 模式下命令白名单、环境变量白名单、审查与人工闸门只能降低风险,**不构成隔离保证**;不要把 DACW 作为不可信工作负载唯一的安全控制措施。
|
|
12
55
|
|
|
13
56
|
## 关键边界
|
|
14
57
|
|
|
58
|
+
- **独立工作区(仅版本控制隔离,测试执行仍在宿主权限下)**:DACW 只在指定工作区内读写与重置文件,不修改主分支或其他目录;这是版本控制层面的隔离,不是执行隔离。
|
|
59
|
+
- **执行隔离默认关闭(第 9 条边界声明)**:测试在宿主用户权限下运行写手产出的代码;容器隔离为可选加强项(仅显式配置 `sandbox.mode: "auto"`/`"docker"` 时启用)。
|
|
15
60
|
- 插件运行在 DSH Host 进程内,通过 `node:fs` 直接读写工作区与状态文件,不经过 DSH 会话的文件沙箱;实际文件权限等于运行 Harness 的系统账号权限。
|
|
16
61
|
- 写手/审查者是真实的子代理会话(可在 profile 中查看);显式配置模型时,任务描述与工作区代码会发送给所选模型提供方。
|
|
17
62
|
- 工作区每轮被重置为非地基文件集,这是设计上的破坏性行为;`workspacePolicy: "allow"` 会跳过空目录/标记检查。
|
|
18
63
|
- 状态文件默认落在 `os.tmpdir()/dacw-state`,包含任务描述、测试输出与审查文本,不自动清理、不做崩溃恢复。
|
|
19
|
-
-
|
|
20
|
-
-
|
|
64
|
+
- **审计证据的局限:** 本地日志可被本地用户修改,不构成防篡改证据;状态文件(含 `secretScanHits`、`reviewExcluded`、`rollback` 等审计字段)使用确定性 SHA-256 校验,防意外损坏,不防同账号本地用户重算。需要对抗性证据时,应导出并外部存证。
|
|
65
|
+
- **并发限制:** 当前版本不支持多个任务并发操作同一工作区;`dacw_rollback` 应在任务终止后调用。同一工作区的任务在进程内串行执行(`workspaceLocks`),跨进程无文件锁保护。
|
|
66
|
+
- **回滚恢复范围:** 回滚恢复文件内容,不保证文件权限、时间戳、扩展属性(macOS xattr)与回滚点完全一致。需要精确恢复请使用 git(git 工作区 DACW 只提供指令,不执行)。
|
|
67
|
+
- **回滚授权:** git 工作区回滚只生成指令、不修改文件。非 git 工作区回滚有破坏性,执行前需交互确认(DSH `userQuestions`);宿主无交互能力时需设置 `DACW_ROLLBACK_TOKEN` 环境变量(非空即视为运维显式授权)。该机制防误触发,不构成对具备 shell 能力的主 Agent 的对抗性防线。
|
|
68
|
+
- **回滚交互失败:** 宿主提供 `userQuestions` 但调用失败(如 UI 断开、超时)时,DACW 拒绝回滚而非降级到 `DACW_ROLLBACK_TOKEN`——交互能力存在但不可用视为宿主状态异常,优先 fail-closed。仅当宿主完全未提供 `userQuestions` 时,才使用 `DACW_ROLLBACK_TOKEN` 授权路径。
|
|
69
|
+
- **进程中断:** 任务执行中被强杀(SIGKILL / 断电)时,状态文件因原子写不会损坏,但可能留下孤儿备份目录;下次同 `task_id` 运行时自动清理。
|
|
70
|
+
- 子代理工具隔离依赖宿主的 `ctx.tools.restrict` 与 `agent/created` 事件;隔离失败或 preset 注册失败时默认拒绝运行。**无法确认隔离同样是失败**:provider 未返回有效 childId、子代理上下文缺少 `tools.schemas` 等验证能力时,调用被终止且不记为成功。唯一逃生门是显式设置 `enforceChildToolIsolation=false`(接受子代理可能继承宿主工具的风险);`allowInheritedPresets` 仅在关闭隔离要求后才作为配套选项才有意义。
|
|
71
|
+
- 被测试项目的依赖需人工预装,`node_modules` 被视为可信基座;测试进程可以读写它们,host 模式下尤其如此。
|
|
21
72
|
- 审查者模型可能被工作区注入的指令劫持,格式合法的伪造 PASS 仍可能出现——**人工闸门是最终兜底**。
|
|
22
73
|
|
|
23
74
|
## 负责任地使用
|
|
24
75
|
|
|
25
76
|
- 仅安装来源可信、经过审查的 bundle;安装/升级会修改整个 DSH profile。
|
|
26
|
-
-
|
|
77
|
+
- 默认配置下测试以宿主用户权限执行:请只在专用或一次性环境、最小权限账号下运行,并确认你信任写手输出与工作区内容。
|
|
78
|
+
- 如需容器隔离,请安装 Docker 并设置 `sandbox.mode: "docker"`/`"auto"`(sandbox 分支);docker 模式同样不是完美隔离。
|
|
79
|
+
- 使用专用空工作区,并备份可访问的文件。
|
|
27
80
|
- 不要把敏感凭据或数据暴露给不可信的模型。
|
|
28
81
|
- 在 NEED_HUMAN 人工终审完成前,不要合入产出。
|
|
29
82
|
|