@stmcw1/dacw 1.0.1 → 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/SAFETY_EN.md CHANGED
@@ -4,26 +4,79 @@
4
4
 
5
5
  ## Experimental status
6
6
 
7
- DACW is an experimental developer-preview plugin. It has not undergone a security audit and must not be used in production. It executes model-generated code and commands (npm / pytest / cargo / go etc.) and grants them access to workspace files, environment variables and local processes; wrong model output, defects, misconfiguration or malicious input may damage the host, leak data, or cause other unintended effects.
7
+ DACW is an experimental developer-preview plugin. It has not undergone a security audit and must not be used in production. It executes model-generated code and commands (npm / pytest / cargo / go etc.); wrong model output, defects, misconfiguration or malicious input may damage the host, leak data, or cause other unintended effects.
8
8
 
9
- ## Sandbox limitations
9
+ ## Execution order and the limits of review (important)
10
10
 
11
- DACW is **not a container-grade sandbox**: child processes run with the same user and privileges as the host and can access the network. Command whitelists, environment isolation, HMAC signing, structured verdicts and the human gate reduce risk but do not constitute isolation. Do not treat DACW as the sole security control for untrusted workloads.
11
+ DACW runs: writer writes files → runner executes tests → reviewer audits → human gate.
12
+
13
+ - **Tests execute before any review.** By the time the reviewer (model or human) sees the code, it has already run once. Review is a *detective* control (it detects problems that already happened), **not a preventive control** (it does not stop execution).
14
+ - **Child tool isolation is not a code-execution security boundary.** It only constrains whether the writer/reviewer subagents can call host tools; it does not constrain the test subprocesses spawned by the runner.
15
+ - The writer can modify the `scripts` field of `package.json` directly (`test` / `pretest` / `posttest` etc.), and the test command executes arbitrary commands from it; the test code itself is also produced by the writer. Therefore **"the reviewer looked at it first" must not be treated as a security guarantee for code execution**.
16
+
17
+ ## Post-test reconciliation (review target === final deliverable)
18
+
19
+ The test command runs writer-produced code, and that code can rewrite the workspace during the test: create files, delete files, tamper with already-generated content (for example `fs.writeFileSync('unreviewed.js', ...)` in a test script, or appending code to a deliverable file). If review only looks at "the baseline manifest the writer declared", those test-time changes bypass review and enter the final deliverable.
20
+
21
+ DACW therefore reconciles between a passing test and the review stage:
22
+
23
+ - Before the test it takes a SHA256 snapshot of the workspace: the expected state = writer baseline ∪ foundation files that already existed before the test (package.json etc.); the baseline portion must match what was written byte-for-byte, otherwise the run goes straight to the human gate;
24
+ - After the test passes it re-enumerates the workspace recursively, hashes every file and compares against the snapshot;
25
+ - Any addition (+), deletion (-) or content change (~) → immediate human gate (`success: false`), the review stage is not entered;
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
+
28
+ The ignore rules apply **only at the workspace root** (F1). 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" (F2) — 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
+
30
+ Before returning success, a final consistency assertion (F3) 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
+
32
+ **Review completeness is likewise fail-closed (G).** 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
+
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
+
36
+ Differences go straight to the human gate instead of back to the writer for three reasons: test-time changes are not the writer's output, so the writer cannot see or explain them; they usually signal test-side injection/tampering or a broken test design and need human adjudication of the actual state; and sending them back would let the next round overwrite the evidence.
37
+
38
+ ## Sandbox (where tests execute)
39
+
40
+ Execution isolation is off by default: tests run writer-produced code with host-user privileges. Setting `sandbox.mode: "auto"` explicitly containerizes when Docker is available; when it is not, a human confirmation ("disable sandbox?") is shown — keeping the sandbox or being unable to ask fails closed (never a silent downgrade).
41
+
42
+ `config.sandbox` decides where tests run:
43
+
44
+ | Mode | Behavior | Isolation |
45
+ |---|---|---|
46
+ | `host` (default) | Run on the host: writer-produced code runs with the full privileges of the host user (execution isolation off by default; red startup warning) | **None** |
47
+ | `auto` (optional) | Docker available → one-shot container; unavailable → human confirmation; keep/unavailable → **tests are refused** (fail-closed) | Container-grade (see below) |
48
+ | `docker` (optional) | Force a one-shot container; Docker unavailable → **run refused** (no prompt, no downgrade) | Container-grade (see below) |
49
+
50
+ Container constraints in docker mode: `--network none` (no network), read-only root filesystem (only a /tmp tmpfs is writable), non-root user (uid/gid 1000), `--cap-drop ALL`, `no-new-privileges`, memory / CPU / PID limits, `--rm` one-shot; the workspace is first copied into a disposable staging directory and that copy is mounted — **the host workspace itself never enters the container**.
51
+
52
+ **docker mode is not perfect isolation either**: containers share the host kernel, the image must be trusted (use only official or reviewed images), and the Docker Desktop file-sharing layer has its own attack surface; pre-pull the image before first use or the pull time may trip the test timeout.
53
+
54
+ With the default host mode (or when the user confirms disabling the sandbox under `auto`), arbitrary writer-produced code (including `package.json` test/pretest scripts) runs with the full privileges of the host user; the result message is flagged as a security downgrade / states where tests executed, and the log carries a red warning. In host mode the command whitelist, environment whitelist, state-file checksum, review and human gate reduce risk but **do not constitute isolation**; do not treat DACW as the sole security control for untrusted workloads.
12
55
 
13
56
  ## Key boundaries
14
57
 
58
+ - **Independent workspace (version-control isolation only; test execution still runs with host-user privileges)**: DACW reads, writes and resets files only inside the designated workspace, never modifying the main branch or other directories; this is version-control-level isolation, not execution isolation.
59
+ - **Execution isolation is off by default (boundary declaration #9)**: tests run writer-produced code with host-user privileges; container isolation is an optional hardening (enabled only when `sandbox.mode: "auto"`/`"docker"` is set explicitly).
15
60
  - The plugin runs inside the DSH Host process and reads/writes the workspace and state files through `node:fs`, outside the DSH session file sandbox; effective file permissions are those of the system account running the Harness.
16
61
  - Writer/reviewer are real subagent sessions (visible in the profile); with an explicitly configured model, the task description and workspace code are sent to the selected model provider.
17
62
  - The workspace is reset to the non-foundation file set every round — destructive by design; `workspacePolicy: "allow"` skips the empty-directory/marker check.
18
63
  - State files default to `os.tmpdir()/dacw-state` and contain the task description, test output and review text; they are never cleaned automatically and have no crash recovery.
19
- - Child tool isolation relies on the host's `ctx.tools.restrict` and the `agent/created` event; when isolation or preset registration fails the run is refused by default (it can be disabled explicitly with `enforceChildToolIsolation` / `allowInheritedPresets`, which gives up the corresponding guarantee).
20
- - The tested project's dependencies must be installed manually; `node_modules` is treated as a trusted base.
64
+ - **Limits of audit evidence:** local logs can be modified by a local user and are not tamper-proof evidence; state files (including audit fields such as `secretScanHits`, `reviewExcluded`, `rollback`) use deterministic SHA-256 verification, which guards against accidental corruption but not against recomputation by a same-account local user. When adversarial evidence is required, export it and store it externally.
65
+ - **Concurrency limits:** the current version does not support multiple tasks operating on the same workspace concurrently; call `dacw_rollback` after the task has terminated. Tasks on the same workspace are serialized in-process (`workspaceLocks`); there is no cross-process file lock.
66
+ - **Rollback recovery scope:** rollback restores file contents; it does not guarantee that file permissions, timestamps or extended attributes (macOS xattr) match the rollback point exactly. For exact recovery use git (in git workspaces DACW only provides instructions; it does not execute).
67
+ - **Rollback authorization:** in git workspaces rollback only produces instructions and modifies no files. In non-git workspaces rollback is destructive: execution requires interactive confirmation (DSH `userQuestions`); when the host has no interaction capability, set the `DACW_ROLLBACK_TOKEN` environment variable (any non-empty value counts as explicit operator authorization). This mechanism prevents accidental triggering; it is not an adversarial defense against a main Agent with shell access.
68
+ - **Rollback confirmation failure:** When the host provides `userQuestions` but the call fails (e.g., UI disconnected, timeout), DACW refuses the rollback instead of falling back to `DACW_ROLLBACK_TOKEN`—an interaction channel that exists but is unusable is treated as an abnormal host state, and fail-closed takes priority. The `DACW_ROLLBACK_TOKEN` authorization path is used only when the host does not provide `userQuestions` at all.
69
+ - **Process interruption:** if the process is force-killed (SIGKILL / power loss) mid-task, the state file is not corrupted thanks to atomic writes, but an orphan backup directory may remain; it is cleaned automatically the next time the same `task_id` runs.
70
+ - Child tool isolation relies on the host's `ctx.tools.restrict` and the `agent/created` event; when isolation or preset registration fails the run is refused by default. **Being unable to confirm isolation is itself a failure**: if the provider returns no valid childId, or the child context lacks validation capability such as `tools.schemas`, the call is aborted and never recorded as successful. The only escape hatch is explicitly setting `enforceChildToolIsolation=false` (accepting that children may inherit host tools); `allowInheritedPresets` is only meaningful as a companion option after the isolation requirement is turned off.
71
+ - The tested project's dependencies must be installed manually; `node_modules` is treated as a trusted base — test processes can read and write them, especially in host mode.
21
72
  - The reviewer model can be hijacked by instructions planted in the workspace, and a well-formed forged PASS can still appear — **the human gate is the final line of defense**.
22
73
 
23
74
  ## Responsible use
24
75
 
25
76
  - Install only bundles you have reviewed and trust; installing/upgrading modifies the whole DSH profile.
26
- - Run in a disposable or dedicated environment under a least-privilege account; use a dedicated empty workspace and back up files it can access.
77
+ - Under the default configuration tests run with host-user privileges: use a dedicated or disposable environment under a least-privilege account, and make sure you trust the writer output and workspace contents.
78
+ - For container isolation, install Docker and set `sandbox.mode: "docker"`/`"auto"` (sandbox branch); docker mode is not perfect isolation either.
79
+ - Use a dedicated empty workspace and back up files it can access.
27
80
  - Do not expose sensitive credentials or data to untrusted models.
28
81
  - Do not merge output before the NEED_HUMAN human review is complete.
29
82
 
package/cordis.patch.yml CHANGED
@@ -12,6 +12,18 @@
12
12
  workspacePolicy: guarded
13
13
  maxRounds: 3
14
14
  subagentProvider: spawn
15
+ # 测试执行策略(默认 host:执行隔离默认关闭,测试在宿主用户权限下运行)
16
+ # sandbox:
17
+ # mode: host # host(默认,执行隔离关闭)| auto(显式;Docker 可用则容器化,不可用则交互确认)| docker(强制容器,不可用拒绝运行)
18
+ # image: '' # 空 = 按测试命令自动选择官方镜像;也可固定如 node:22-bookworm-slim
19
+ # memoryMb: 1024
20
+ # cpus: 1
21
+ # pidsLimit: 256
22
+ # tmpfsMb: 128
23
+ # G3 逃生门(默认 false):允许截断/仅摘要的审查放行 success:true(降低安全保证,message/files/日志会标注)
24
+ # allowTruncatedReview: false
25
+ # 写手输出秘密扫描(默认 true):命中 PEM 私钥/AWS/GitHub/Slack/OpenAI 凭据模式时记录审计(不含原文)
26
+ # secretScanEnabled: true
15
27
  # 可选:写手/审查者模型(默认继承父会话路由)
16
28
  # writerModel: deepseek-account/deepseek-flash # 或 "deepseek-flash" 按 DSH 已配置模型目录解析 / "inherit"
17
29
  # reviewerModel: { model: deepseek-flash, reasoningEffort: high }