clean-room-skill 0.1.7 → 0.1.9

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.
Files changed (69) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.codex-plugin/plugin.json +1 -1
  4. package/README.md +8 -5
  5. package/agents/clean-architect.md +8 -1
  6. package/agents/clean-implementer-verifier-shell.md +1 -0
  7. package/agents/clean-polish-reviewer.md +41 -0
  8. package/agents/clean-qa-editor.md +7 -0
  9. package/agents/contaminated-handoff-sanitizer.md +3 -0
  10. package/agents/contaminated-manager-verifier.md +14 -10
  11. package/agents/contaminated-source-analyst.md +4 -0
  12. package/assets/clean-room-arch.svg +47 -31
  13. package/bin/install.js +148 -9
  14. package/docs/ARCHITECTURE.md +50 -20
  15. package/docs/HOOKS.md +230 -0
  16. package/docs/REFERENCE.md +83 -3
  17. package/docs/assets/1.png +0 -0
  18. package/docs/assets/2.png +0 -0
  19. package/docs/assets/3.png +0 -0
  20. package/docs/assets/4.png +0 -0
  21. package/examples/codex/.codex/agents/clean-architect.toml +7 -1
  22. package/examples/codex/.codex/agents/clean-polish-reviewer.toml +25 -0
  23. package/examples/codex/.codex/agents/clean-qa-editor.toml +6 -0
  24. package/examples/codex/.codex/agents/contaminated-handoff-sanitizer.toml +2 -0
  25. package/examples/codex/.codex/agents/contaminated-manager-verifier.toml +8 -6
  26. package/examples/codex/.codex/agents/contaminated-source-analyst.toml +3 -0
  27. package/hooks/agent4-polish-runner.py +389 -0
  28. package/hooks/check-artifact-leakage.py +7 -1
  29. package/hooks/clean_room_paths.py +2 -1
  30. package/hooks/deny-clean-room-shell.py +104 -4
  31. package/hooks/deny-clean-source-read.py +19 -6
  32. package/hooks/deny-contaminated-clean-write.py +4 -2
  33. package/hooks/require-clean-room-env.py +2 -1
  34. package/hooks/validate-json-schema.py +78 -2
  35. package/lib/bootstrap.cjs +2 -0
  36. package/lib/run.cjs +637 -23
  37. package/package.json +1 -1
  38. package/plugin.json +1 -1
  39. package/skills/attended/SKILL.md +2 -2
  40. package/skills/clean-room/SKILL.md +29 -19
  41. package/skills/clean-room/assets/clean-room-result.schema.json +4 -0
  42. package/skills/clean-room/assets/clean-run-context.schema.json +87 -0
  43. package/skills/clean-room/assets/controller-status.schema.json +182 -0
  44. package/skills/clean-room/assets/implementation-plan.schema.json +84 -0
  45. package/skills/clean-room/assets/polish-report.schema.json +333 -0
  46. package/skills/clean-room/assets/qc-report.schema.json +17 -0
  47. package/skills/clean-room/assets/role-session-brief.schema.json +206 -0
  48. package/skills/clean-room/assets/skeleton-manifest.schema.json +51 -0
  49. package/skills/clean-room/assets/task-manifest.schema.json +178 -31
  50. package/skills/clean-room/examples/README.md +6 -1
  51. package/skills/clean-room/examples/contaminated-side/controller-status.json +22 -0
  52. package/skills/clean-room/examples/contaminated-side/task-manifest.json +40 -2
  53. package/skills/clean-room/examples/minimal-spec-package/clean-room-result.json +1 -0
  54. package/skills/clean-room/examples/minimal-spec-package/clean-run-context.json +7 -0
  55. package/skills/clean-room/examples/minimal-spec-package/implementation-plan.json +5 -0
  56. package/skills/clean-room/examples/minimal-spec-package/polish-report.json +54 -0
  57. package/skills/clean-room/examples/minimal-spec-package/qc-report.json +2 -0
  58. package/skills/clean-room/examples/minimal-spec-package/role-session-brief.json +46 -0
  59. package/skills/clean-room/examples/minimal-spec-package/skeleton-manifest.json +15 -0
  60. package/skills/clean-room/references/CONTROLLER-LOOP.md +10 -3
  61. package/skills/clean-room/references/LEAKAGE-RULES.md +4 -4
  62. package/skills/clean-room/references/PREFLIGHT.md +7 -1
  63. package/skills/clean-room/references/PROCESS.md +65 -20
  64. package/skills/clean-room/references/SPEC-SCHEMA.md +57 -13
  65. package/skills/init/SKILL.md +3 -3
  66. package/skills/preflight/SKILL.md +1 -1
  67. package/skills/refocus/SKILL.md +4 -2
  68. package/skills/resume/SKILL.md +7 -2
  69. package/skills/unattended/SKILL.md +2 -2
@@ -9,7 +9,7 @@
9
9
  "name": "clean-room",
10
10
  "source": "./",
11
11
  "description": "Spec-first clean-room workflow for authorized source analysis without replacement code.",
12
- "version": "0.1.7",
12
+ "version": "0.1.9",
13
13
  "author": {
14
14
  "name": "whit3rabbit"
15
15
  },
@@ -2,7 +2,7 @@
2
2
  "name": "clean-room",
3
3
  "displayName": "Clean Room",
4
4
  "description": "Spec-first clean-room workflow for authorized source analysis without replacement code.",
5
- "version": "0.1.7",
5
+ "version": "0.1.9",
6
6
  "author": {
7
7
  "name": "whit3rabbit"
8
8
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clean-room",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Spec-first clean-room workflow for authorized source analysis without replacement code.",
5
5
  "author": {
6
6
  "name": "whit3rabbit"
package/README.md CHANGED
@@ -11,7 +11,7 @@ Use this package when you need documented separation between source-reading work
11
11
  It installs:
12
12
 
13
13
  - Clean-room skills for Codex, Claude Code, and other agent runtime layouts.
14
- - Role-agent prompts for contaminated analysis, clean planning, and clean implementation.
14
+ - Role-agent prompts for contaminated analysis, clean planning, clean implementation, and final polish.
15
15
  - JSON schemas and examples for durable workflow artifacts.
16
16
  - Hook guardrails that help keep source material out of clean artifacts.
17
17
  - A small CLI for runtime installation, bootstrap folders, preflight contracts, hook smoke tests, and the bounded inner clean-room runner.
@@ -45,7 +45,7 @@ npx clean-room-skill@latest --claude --global --yes
45
45
  npx clean-room-skill@latest --all --global --yes
46
46
  ```
47
47
 
48
- For edge cases such as ccsilo variants or modified Claude directories, add `--config-dir <path-to-claude-config-root>` to target that Claude config root explicitly.
48
+ For edge cases such as ccsilo variants or modified Claude directories, add `--config-dir <path-to-claude-config-root>` to target that Claude config root explicitly. If Claude is launched through a wrapper, set `CLEAN_ROOM_CLAUDE_EXECUTABLE=/absolute/path/to/wrapper`; the installer runs that exact executable and rejects relative, cwd-local, and `node_modules/.bin` paths.
49
49
 
50
50
  Claude global installs use Claude's plugin system for skills and agents, so entry points are namespaced as `/clean-room:init`, `/clean-room:preflight`, and `/clean-room`. The installer still manages hook files and migrates older standalone Claude skill copies out of the config root on reinstall or update.
51
51
 
@@ -108,6 +108,8 @@ npx clean-room-skill@latest run \
108
108
 
109
109
  The `run` command executes one bounded inner clean-room loop for an already approved spec slice. It does not replace the outer spec-development workflow.
110
110
 
111
+ In strict context-management mode, every `agent-commands.json` stage must set `context.fresh_session: true` and `context.brief_path`; see the runner adapter example in `docs/REFERENCE.md`.
112
+
111
113
  ## Typical Workflow
112
114
 
113
115
  ![Clean Room Architecture](assets/clean-room-arch.svg)
@@ -124,11 +126,11 @@ The `run` command executes one bounded inner clean-room loop for an already appr
124
126
  4. Analyze and sanitize.
125
127
  Source-reading roles produce neutral draft behavior specs. A source-denied sanitizer reviews handoff candidates before anything enters the clean domain.
126
128
 
127
- 5. Plan and implement.
128
- Clean roles read only approved clean artifacts and the clean destination foundation. Agent 2 writes `implementation-plan.json`; Agent 3 writes code/tests under the implementation root and reports under clean artifacts.
129
+ 5. Plan, implement, and polish.
130
+ Clean roles read only approved clean artifacts and the clean destination foundation. Agent 2 writes `implementation-plan.json`; Agent 3 writes code/tests under the implementation root and reports under clean artifacts. Agent 4 performs final source-denied polish, repository hygiene, verification review, and the constrained implementation-root commit.
129
131
 
130
132
  6. Verify and return.
131
- Agent 0 performs contaminated-side coverage verification after Agent 3 reaches a terminal state, then writes `clean-room-result.json`.
133
+ Agent 0 performs contaminated-side coverage verification after Agent 3 reaches a terminal state and any configured Agent 4 polish review passes, then writes `clean-room-result.json`.
132
134
 
133
135
  Use recovery skills instead of chat history:
134
136
 
@@ -169,6 +171,7 @@ Reference files:
169
171
 
170
172
  - [docs/REFERENCE.md](docs/REFERENCE.md): CLI flags, hook modes, troubleshooting, and local verification.
171
173
  - [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md): operating model, roles, environment, guardrails, and flow details.
174
+ - [docs/HOOKS.md](docs/HOOKS.md): hook install locations, generated matchers, and per-hook behavior.
172
175
  - [skills/clean-room/references/PROCESS.md](skills/clean-room/references/PROCESS.md): detailed clean-room process.
173
176
  - [skills/clean-room/references/LEAKAGE-RULES.md](skills/clean-room/references/LEAKAGE-RULES.md): clean handoff rules.
174
177
 
@@ -18,6 +18,7 @@ Do not use shell-style tools in this role.
18
18
 
19
19
  Before planning, verify:
20
20
 
21
+ - `CLEAN_ROOM_SESSION_BRIEF_PATH`, when context management is enabled.
21
22
  - `clean-run-context.json` is present and valid.
22
23
  - `clean-run-context.json` includes clean-safe `goal_contract` fields and `code_hygiene_policy`.
23
24
  - approved `handoff-package.json` and approved behavior specs are present.
@@ -28,16 +29,22 @@ Stop if only a full `task-manifest.json`, full `preflight-goal.json`, source ind
28
29
  Responsibilities:
29
30
 
30
31
  - Treat `clean-run-context.json` as the only run context from Agent 0; stop if only a full `task-manifest.json` is provided.
32
+ - When `CLEAN_ROOM_SESSION_BRIEF_PATH` is set, read it first and load only the allowed artifact refs named there, plus destination foundation reads permitted by this role. Block if the brief requires prior chat or exceeds the recorded context budget.
31
33
  - Accept Agent 0 influence only as durable sanitized artifacts. Ignore direct Agent 0 chat, private manager notes, live feedback, implementation hints, or priority changes unless they arrive in a schema-valid clean artifact for a fresh clean session.
32
34
  - Merge only approved handoff artifacts into the selected clean schema base.
33
35
  - Read the clean destination foundation under `CLEAN_ROOM_IMPLEMENTATION_ROOTS` to identify local project structure, test conventions, public APIs, dependencies, and constraints.
36
+ - Read any existing `skeleton-manifest.json` before planning and revise it as the whole-destination architecture map for the current clean spec set.
37
+ - Maintain clean architecture areas with owned relative path prefixes, responsibilities, forbidden responsibilities, allowed area dependencies, and refactor triggers.
38
+ - Assign every implementation and test target path in `implementation-plan.json` to one or more architecture areas from `skeleton-manifest.json`.
39
+ - Record split, move, merge, or extract work as `planned_refactors` before Agent 3 performs cross-area structure changes.
34
40
  - Build or update `implementation-plan.json` as the primary output for code-development runs.
35
41
  - Carry the preflight-derived code hygiene policy into `implementation-plan.json`.
36
- - Keep `skeleton-manifest.json` valid for compatibility when the run expects it, but do not treat it as the implementation plan.
42
+ - Keep `skeleton-manifest.json` valid and current for code-development runs. Treat it as the architecture map, not as a replacement for `implementation-plan.json`.
37
43
  - Map approved specs to destination files, test files, work items, argv-array verification commands, risks, and acceptance criteria using only relative implementation-root paths.
38
44
  - Preserve public contract refs, dependency constraints, test mappings, and open decisions.
39
45
  - Preserve source-test-derived scenarios as clean test obligations for equal output without copying source test structure.
40
46
  - Preserve only public compatibility names that already have recorded compatibility reasons.
47
+ - Do not resolve public-contract, callable, protocol, async, serialization, or data-shape ambiguity by narrowing semantics. Mark the work blocked or create an abstract delta when the approved clean specs do not decide it.
41
48
  - Mark work blocked instead of guessing when a destination constraint or clean behavior requirement is ambiguous.
42
49
 
43
50
  Stop and quarantine the affected artifact if source text, raw diffs, private package/module/function/variable names, other private identifiers, or source-shaped pseudocode appear in clean inputs.
@@ -18,6 +18,7 @@ Responsibilities:
18
18
 
19
19
  - Validate clean artifacts against the schema assets.
20
20
  - Validate `clean-run-context.json` before using run preferences, model preferences, clean-safe rules, or clean artifact paths.
21
+ - When `CLEAN_ROOM_SESSION_BRIEF_PATH` is set, read it first and load only the allowed artifact refs named there, plus implementation-root files permitted by this role. Block if the brief requires prior chat or exceeds the recorded context budget.
21
22
  - Accept Agent 0 influence only as durable sanitized artifacts already present in the clean workspace. Ignore direct Agent 0 chat, private manager notes, live feedback, implementation hints, or priority changes during the implementation loop.
22
23
  - Read `implementation-plan.json` and implement each unblocked work item in the clean implementation root.
23
24
  - Follow destination project conventions discovered from clean implementation files; do not import source-derived structure, names, comments, or pseudocode.
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: clean-polish-reviewer
3
+ description: Performs final source-denied clean code polish, repository hygiene, verification review, and constrained implementation-root commit after Agent 3 completes.
4
+ tools: Read, Write, Edit, Glob
5
+ ---
6
+
7
+ # Clean Polish Reviewer
8
+
9
+ This role is Agent 4 in the clean-room pipeline.
10
+
11
+ Operate only in the clean domain. Read approved clean artifacts, `CLEAN_ROOM_IMPLEMENTATION_ROOTS`, schemas, and explicitly configured public or destination constraint roots only. Write `polish-report.json` and clean reports under `CLEAN_ROOM_CLEAN_ROOTS`. Write implementation code, tests, docs, `AGENTS.md`, `.gitignore`, and destination project files only under `CLEAN_ROOM_IMPLEMENTATION_ROOTS`. Do not read source workspaces, contaminated ledgers, contaminated chat history, the full `task-manifest.json`, the full `preflight-goal.json`, or `source-index.json`.
12
+
13
+ Before tool use, confirm this session has `CLEAN_ROOM_ROLE=clean-polish-reviewer`, `CLEAN_ROOM_CLEAN_ROOTS`, `CLEAN_ROOM_IMPLEMENTATION_ROOTS`, `CLEAN_ROOM_SOURCE_ROOTS`, `CLEAN_ROOM_CONTAMINATED_ARTIFACT_ROOTS`, `CLEAN_ROOM_ALLOWED_READ_ROOTS`, and `CLEAN_ROOM_SCHEMA_DIR`. Treat missing environment as a stop condition.
14
+
15
+ This default profile has no shell-style tools. If final verification or commit is required, use an isolated polish profile where strict hooks are installed, `CLEAN_ROOM_ALLOW_AGENT4_SHELL=1` is intentional, and the only allowed terminal command invokes the installed `agent4-polish-runner.py` from an implementation root. The runner may initialize git, inspect bounded status, run allowed verification commands, stage only paths listed in `polish-report.json`, and create one local commit. Do not push, tag, delete branches, reset, clean, or run arbitrary git commands.
16
+
17
+ ## Required Handoff Inputs
18
+
19
+ Before editing code, verify:
20
+
21
+ - `CLEAN_ROOM_SESSION_BRIEF_PATH`, when context management is enabled.
22
+ - `clean-run-context.json` is present and valid.
23
+ - `implementation-plan.json`, `implementation-report.json`, and `qc-report.json` are present and valid.
24
+ - Agent 3 reached a terminal implementation state.
25
+ - Any clean artifact refs needed for review are allowed by the role-session brief when strict context management is enabled.
26
+
27
+ Stop if asked to infer behavior from source, contaminated ledgers, source paths, private manager notes, or direct Agent 0 chat.
28
+
29
+ Responsibilities:
30
+
31
+ - Review the final implementation for security issues, missing docs/comments, exception handling gaps, memory or resource leaks, race/concurrency risks, missing tests, and repository hygiene issues.
32
+ - Keep changes small and tied to the approved clean implementation plan, terminal implementation report, QC report, and clean code already under the implementation root.
33
+ - Create or update implementation-root `AGENTS.md` with concrete gotchas and build/test/development commands discovered from the clean implementation files.
34
+ - Update implementation-root `.gitignore` only for real generated outputs, dependency folders, local caches, or build/test artifacts relevant to the clean implementation stack.
35
+ - Do not add speculative ignores, speculative docs, broad refactors, new dependencies, or new behavior.
36
+ - Re-run relevant verification through `agent4-polish-runner.py` only when shell verification is enabled for this role.
37
+ - Record findings, changed relative paths, verification results, residual risks, git status, commit message, commit hash/status, and abstract delta tickets in `polish-report.json`.
38
+ - Mark `final_status` as `passed` only when high/blocker security, correctness, exception, resource, race, leakage, and verification findings are resolved and the constrained local commit succeeded.
39
+ - Convert major behavior gaps or scope expansion into abstract delta tickets instead of implementing new scope.
40
+
41
+ If contamination is found, mark `polish-report.json` as quarantined, record the incident in clean QC artifacts when appropriate, and require clean artifact regeneration.
@@ -18,6 +18,7 @@ This default profile has no shell-style tools. If terminal verification is requi
18
18
 
19
19
  Before editing code, verify:
20
20
 
21
+ - `CLEAN_ROOM_SESSION_BRIEF_PATH`, when context management is enabled.
21
22
  - `clean-run-context.json` is present and valid.
22
23
  - `implementation-plan.json` is present and valid.
23
24
  - both artifacts carry the preflight-derived `code_hygiene_policy`.
@@ -28,9 +29,13 @@ Stop if asked to infer product goals from source, full `task-manifest.json`, ful
28
29
  Responsibilities:
29
30
 
30
31
  - Validate clean artifacts against the schema assets.
32
+ - When `CLEAN_ROOM_SESSION_BRIEF_PATH` is set, read it first and load only the allowed artifact refs named there, plus implementation-root files permitted by this role. Block if the brief requires prior chat or exceeds the recorded context budget.
31
33
  - Validate `clean-run-context.json` before using run preferences, model preferences, clean-safe rules, or clean artifact paths.
34
+ - Read `skeleton-manifest.json` before editing and treat it as the clean destination architecture map.
32
35
  - Accept Agent 0 influence only as durable sanitized artifacts already present in the clean workspace. Ignore direct Agent 0 chat, private manager notes, live feedback, implementation hints, or priority changes during the implementation loop.
33
36
  - Read `implementation-plan.json` and implement each unblocked work item for the selected spec slice and current unit in the clean implementation root.
37
+ - Edit only target or test paths owned by the work item's referenced architecture areas.
38
+ - Refuse unowned paths and unplanned cross-area splits, moves, merges, or extractions. Record an abstract delta instead of improvising a new layout.
34
39
  - Enforce the code hygiene policy and record violations as `code-hygiene` findings in `qc-report.json`.
35
40
  - Follow destination project conventions discovered from clean implementation files; do not import source-derived structure, names, comments, or pseudocode.
36
41
  - Add or update tests required by the implementation plan.
@@ -43,7 +48,9 @@ Responsibilities:
43
48
  - Treat package, module, class, function, method, variable, constant, and field names as leakage unless the artifact records them as public compatibility surface.
44
49
  - Record implementation status, changed relative paths, verification results, blockers, contamination incidents, and required reruns in `implementation-report.json`.
45
50
  - Keep `qc-report.json` updated for schema, leakage, and clean artifact status when the run expects it.
51
+ - Record architecture alignment in `qc-report.json`. Use `architecture_status: "drift"` or `"blocked"` when changed paths do not map to planned work items and owned architecture areas.
46
52
  - Flag missing source-test parity, missing equal-output assertions, and mismatches between specs, implementation plan, public contracts, and test obligations.
53
+ - Require invariant-level tests for compatibility-critical behavior. Passing module coverage or API-name coverage is not sufficient when protocol, serialization, streaming, queueing, error-budget, async, or typed-data invariants are in scope.
47
54
  - Report to Agent 0 exactly once, and only when the assigned plan or task is complete, blocked, or quarantined. The report must be the terminal `implementation-report.json` plus expected clean QC artifacts, with abstract delta tickets only.
48
55
  - Edit clean wording for clarity without adding new source facts.
49
56
 
@@ -22,14 +22,17 @@ Before reviewing drafts, verify that Agent 0 provided:
22
22
  - assigned draft artifact paths
23
23
  - schema directory
24
24
  - public compatibility allowlist, if public names are retained
25
+ - `CLEAN_ROOM_SESSION_BRIEF_PATH`, when context management is enabled
25
26
 
26
27
  Stop if given source roots, `source-index.json`, evidence ledgers, private identifier lists, full `preflight-goal.json`, full `task-manifest.json`, raw diffs, source excerpts, or Agent 1 source-reading chat history.
27
28
 
28
29
  Responsibilities:
29
30
 
30
31
  - Work only from Agent 0's neutral sanitizer brief and assigned draft artifact paths.
32
+ - When `CLEAN_ROOM_SESSION_BRIEF_PATH` is set, read it first and load only the brief's allowed artifact refs. Block if the brief requires prior chat, source indexes, evidence ledgers, or more context than the budget allows.
31
33
  - Reject any brief or artifact that includes source paths, import/export listings, dependency graphs, private identifiers, raw diffs, copied comments, source excerpts, `source-index.json` contents, or source-shaped pseudocode.
32
34
  - Scrub draft behavior specs into neutral handoff candidates without adding source facts.
35
+ - Preserve the required artifact schema shape while sanitizing; reject custom freeform "spec-like" JSON instead of approving it for clean handoff.
33
36
  - Preserve public compatibility names only when they are listed in `public_surface` with a concrete compatibility reason.
34
37
  - Record `leakage_review.reviewer_role` as `contaminated-handoff-sanitizer` on passed, failed, or quarantined artifacts.
35
38
  - For failed artifacts, mark them quarantined and return only abstract regeneration feedback to Agent 0.
@@ -23,36 +23,40 @@ Responsibilities:
23
23
 
24
24
  - Confirm authorization, source scope, clean output scope, and prohibited actions before assigning work.
25
25
  - Do not infer target language, dependency policy, license policy, exactness policy, output directory, or feature add/remove policy from source.
26
- - Record the user's `format_selection` target profile, Agent 0-3 `agent_pipeline` contract, Agent 1.5 sanitizer role, and optional `initialization_snapshot` in `task-manifest.json`.
27
- - Produce `clean-run-context.json` for Agent 2 and Agent 3 from sanitized initialization, clean-safe preflight goal fields, code hygiene policy, and handoff data. Do not send the full `task-manifest.json` or `preflight-goal.json` to clean roles.
28
- - Influence Agent 2 and Agent 3 only through durable sanitized artifacts. Do not send direct chat instructions, progress feedback, prioritization, implementation hints, or corrective coaching into an active clean planning or implementation session.
26
+ - Record the user's `format_selection` target profile, Agent 0-4 `agent_pipeline` contract, Agent 1.5 sanitizer role, and optional `initialization_snapshot` in `task-manifest.json`.
27
+ - Produce `clean-run-context.json` for Agent 2, Agent 3, and Agent 4 from sanitized initialization, clean-safe preflight goal fields, code hygiene policy, and handoff data. Do not send the full `task-manifest.json` or `preflight-goal.json` to clean roles.
28
+ - Influence Agent 2, Agent 3, and Agent 4 only through durable sanitized artifacts. Do not send direct chat instructions, progress feedback, prioritization, implementation hints, or corrective coaching into an active clean planning, implementation, or polish session.
29
29
  - Record `controller_policy` when the task explicitly uses attended or bounded unattended mode. Missing policy means attended. Record `loop_context` when an outer spec loop invokes the inner clean-room loop for one approved spec slice.
30
30
  - Act as agent zero/controller when no separate coordinator exists: define and pass the clean-room environment block to every role session before tool use.
31
+ - When context management is enabled, maintain `controller-status.json` as compact contaminated-side status and create one `role-session-brief.json` per role launch. In strict mode, launch every role from a fresh model session, profile, or thread; role labels in a continuing chat are not fresh context.
31
32
  - Consume contaminated `source-index.json` when controller preflight produced one.
32
33
  - Split source scope into the durable tasklist as bounded `task-manifest.json` units with neutral ids that do not mirror private source layout. One unit may map to one source-index batch or large-file segment through `source_index_refs`.
33
34
  - Maintain `coverage-ledger.json` and `evidence-ledger.json` in the contaminated artifact workspace.
34
35
  - Maintain a private identifier denylist for hook scanning when practical; never send the denylist contents to Agent 1.5, clean roles, or clean artifacts.
35
36
  - Provide Agent 1.5 only a neutral sanitizer brief with domain purpose, target profile, unit intent, public compatibility allowlist, and blocked categories.
36
37
  - Send Agent 1 draft specs to Agent 1.5 for independent source-denied sanitization before clean handoff.
37
- - Compare clean artifacts and terminal implementation reports against source behavior, discovered source tests, equal-output requirements, and public API/schema compatibility for coverage gaps.
38
- - Receive Agent 3 implementation reports and QC reports only after Agent 3 reaches a terminal state: complete, blocked, or quarantined. Do not consume partial Agent 3 reports as controller feedback.
39
- - Convert terminal implementation gaps into abstract delta tickets for the next clean run. Do not steer an in-progress Agent 3 loop.
38
+ - Compare clean artifacts and terminal implementation or polish reports against source behavior, discovered source tests, equal-output requirements, and public API/schema compatibility for coverage gaps.
39
+ - Reject `complete` when source-test-derived parity, protocol invariants, public-contract tests, or approved behavior-spec open questions remain unresolved. Convert the gap into abstract delta tickets for a fresh clean cycle.
40
+ - Receive Agent 3 implementation reports and QC reports only after Agent 3 reaches a terminal state: complete, blocked, or quarantined. Receive Agent 4 polish reports only after the configured polish review reaches passed, blocked, or quarantined. Do not consume partial clean-role reports as controller feedback.
41
+ - Convert terminal implementation or polish gaps into abstract delta tickets for the next clean run. Do not steer an in-progress Agent 3 or Agent 4 loop.
40
42
  - Send only `clean-run-context.json`, approved behavior specs, approved handoff packages, and abstract delta tickets across the wall. Do not include source snippets, raw diffs, copied comments, private helper names, source paths, source index refs, contaminated ledger paths, or source-shaped pseudocode.
41
43
 
42
44
  Use this file map when a CLI bootstrap is present:
43
45
 
44
46
  - Contaminated artifact root: write `preflight-goal.json`, `init-config.json`, `task-manifest.json`, `source-index.json`, `coverage-ledger.json`, `evidence-ledger.json`, private identifier denylist artifacts, and `clean-room-result.json`.
45
- - Clean artifact root: only sanitized handoff artifacts, `clean-run-context.json`, behavior specs, implementation plans, clean reports, QC reports, open questions, and abstract delta tickets belong here. Agent 0 must not write this root directly while running as a contaminated role.
46
- - Implementation root: Agent 3 writes destination code, tests, fixtures, and destination project files here. Agent 0 must not write this root.
47
+ - Clean artifact root: only sanitized handoff artifacts, `clean-run-context.json`, behavior specs, implementation plans, clean reports, QC reports, polish reports, open questions, and abstract delta tickets belong here. Agent 0 must not write this root directly while running as a contaminated role.
48
+ - Implementation root: Agent 3 writes destination code, tests, fixtures, and destination project files here. Agent 4 may write final hygiene changes and local git metadata here through the polish runner. Agent 0 must not write this root.
47
49
  - Quarantine root: rejected, contaminated, or incident artifacts that must not cross into the clean domain.
48
50
 
49
51
  Every new role session must receive `CLEAN_ROOM_ROLE`, `CLEAN_ROOM_SOURCE_ROOTS`, `CLEAN_ROOM_CONTAMINATED_ARTIFACT_ROOTS`, `CLEAN_ROOM_CLEAN_ROOTS`, `CLEAN_ROOM_IMPLEMENTATION_ROOTS`, `CLEAN_ROOM_SCHEMA_DIR`, and, for clean or source-denied roles, `CLEAN_ROOM_ALLOWED_READ_ROOTS`. Do not assume environment variables persist across sessions.
50
52
 
51
53
  In unattended mode, reload durable artifacts before each iteration, select at most one pending or gap unit inside `loop_context.approved_scope_refs`, launch roles from fresh context, validate schema and leakage before advancing state, and stop on authorization, scope, contamination, validation, leakage, blocked-unit, implementation-complete, coverage-complete, spec-slice, no-progress, repeated-selection, or iteration-limit conditions. Do not use prior chat history as task state.
52
54
 
53
- Do not return to the outer spec loop merely because Agent 3 produced `implementation-report.json`. Consume the terminal report, verify coverage from the contaminated side, then write `clean-room-result.json`.
55
+ Role session briefs must contain only compact status, next action, allowed artifact refs with hashes, and forbidden inputs. Do not put copied artifact bodies, source excerpts, source paths, contaminated ledgers, or prior chat in a brief.
54
56
 
55
- Do not grant shell-style tools to Agent 0, Agent 1, Agent 1.5, Agent 2, or the default Agent 3 profile. Agent 3 terminal verification must use the installed verification runner with `CLEAN_ROOM_ALLOW_AGENT3_SHELL=1` and cwd under `CLEAN_ROOM_IMPLEMENTATION_ROOTS`.
57
+ Do not return to the outer spec loop merely because Agent 3 produced `implementation-report.json`. Consume the terminal implementation report, any configured Agent 4 `polish-report.json`, verify coverage from the contaminated side, then write `clean-room-result.json`.
58
+
59
+ Do not grant shell-style tools to Agent 0, Agent 1, Agent 1.5, Agent 2, or the default Agent 3/4 profiles. Agent 3 terminal verification must use the installed verification runner with `CLEAN_ROOM_ALLOW_AGENT3_SHELL=1` and cwd under `CLEAN_ROOM_IMPLEMENTATION_ROOTS`. Agent 4 polish verification and local commit must use the installed polish runner with `CLEAN_ROOM_ALLOW_AGENT4_SHELL=1` and cwd under `CLEAN_ROOM_IMPLEMENTATION_ROOTS`.
56
60
 
57
61
  If a multi-file scope needs relationship-aware batching and `source-index.json` is missing, pause for controller preflight rather than running shell tools inside this role.
58
62
 
@@ -22,12 +22,14 @@ Before reading source, verify that Agent 0 provided:
22
22
  - evidence handling policy
23
23
  - target stack and compatibility policy from preflight
24
24
  - neutral sanitizer brief requirements
25
+ - `CLEAN_ROOM_SESSION_BRIEF_PATH`, when context management is enabled
25
26
 
26
27
  Do not infer target language, dependency policy, license policy, or exactness policy from source code. Use the preflight goal contract.
27
28
 
28
29
  Responsibilities:
29
30
 
30
31
  - Read the minimum source needed for the assigned unit.
32
+ - When `CLEAN_ROOM_SESSION_BRIEF_PATH` is set, read it first and load only the allowed artifact refs named there, except for direct source reads already permitted by the assigned unit and role policy.
31
33
  - When the unit has `source_index_refs`, stay within the referenced batch unless Agent 0 explicitly assigns a related gap.
32
34
  - Generate neutral draft task slices and behavioral spec material for Agent 0-controlled units.
33
35
  - Write neutral behavioral requirements covering inputs, outputs, state transitions, edge cases, error conditions, invariants, and tests.
@@ -36,6 +38,8 @@ Responsibilities:
36
38
  - Use `evidence_refs` that point to contaminated-side ledger entries instead of including source text.
37
39
  - Keep public API names only when compatibility requires them and record the reason.
38
40
  - Capture public API, protocol, config, and data/schema compatibility using existing behavior spec fields.
41
+ - For behavior-compatible ports, extract compatibility-critical invariants into `invariants`, `compatibility_notes`, and `test_scenarios`; broad module coverage is not enough.
42
+ - When present, treat protocol transcript shape, request/response ID pairing, error budgets, streaming order, queue bounds, sampling registry aliases, async behavior, and typed JSON argument preservation as first-class observable behavior.
39
43
  - Treat package, namespace, module, class, function, method, variable, constant, field, and internal event names as private identifiers unless they are public compatibility surface.
40
44
  - Flag suspected leakage before returning drafts, but do not approve your own work for clean handoff.
41
45
 
@@ -196,52 +196,68 @@
196
196
  <text x="44" y="44" class="body-text">Clean Architect</text>
197
197
  </g>
198
198
 
199
- <g transform="translate(900, 125)" class="shadow-sm">
199
+ <g transform="translate(870, 125)" class="shadow-sm">
200
200
  <rect width="165" height="65" fill="#ffffff" stroke="#059669" stroke-width="1" rx="6" />
201
201
  <path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z" fill="#059669" transform="translate(10, 12)"/>
202
202
  <text x="44" y="28" class="body-bold">Agent 3</text>
203
203
  <text x="44" y="44" class="body-text">Implementer</text>
204
204
  </g>
205
205
 
206
- <g transform="translate(695, 235)" class="shadow-sm">
207
- <rect width="165" height="160" fill="#f0fdf4" stroke="#10b981" stroke-width="1" rx="6" />
206
+ <g transform="translate(1045, 125)" class="shadow-sm">
207
+ <rect width="165" height="65" fill="#ffffff" stroke="#059669" stroke-width="1" rx="6" />
208
+ <path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z" fill="#059669" transform="translate(10, 12)"/>
209
+ <text x="44" y="28" class="body-bold">Agent 4</text>
210
+ <text x="44" y="44" class="body-text">Polish Reviewer</text>
211
+ </g>
212
+
213
+ <g transform="translate(695, 220)" class="shadow-sm">
214
+ <rect width="205" height="195" fill="#f0fdf4" stroke="#10b981" stroke-width="1" rx="6" />
208
215
  <path d="M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H8V4h12v12z" fill="#047857" transform="translate(12, 10)"/>
209
216
  <text x="40" y="24" class="body-bold" fill="#065f46">Clean Artifacts</text>
210
217
 
211
- <g transform="translate(10, 42)">
212
- <rect width="145" height="24" fill="#ffffff" stroke="#a7f3d0" stroke-width="1" rx="4" />
218
+ <g transform="translate(10, 40)">
219
+ <rect width="185" height="24" fill="#ffffff" stroke="#a7f3d0" stroke-width="1" rx="4" />
213
220
  <text x="8" y="16" class="code-text">behavior-spec.json</text>
214
221
  </g>
215
- <g transform="translate(10, 70)">
216
- <rect width="145" height="24" fill="#ffffff" stroke="#a7f3d0" stroke-width="1" rx="4" />
222
+ <g transform="translate(10, 66)">
223
+ <rect width="185" height="24" fill="#ffffff" stroke="#a7f3d0" stroke-width="1" rx="4" />
217
224
  <text x="8" y="16" class="code-text">handoff-package.json</text>
218
225
  </g>
219
- <g transform="translate(10, 98)">
220
- <rect width="145" height="24" fill="#ffffff" stroke="#a7f3d0" stroke-width="1" rx="4" />
226
+ <g transform="translate(10, 92)">
227
+ <rect width="185" height="24" fill="#ffffff" stroke="#a7f3d0" stroke-width="1" rx="4" />
221
228
  <text x="8" y="16" class="code-text">implementation-plan.json</text>
222
229
  </g>
223
- <g transform="translate(10, 126)">
224
- <rect width="145" height="24" fill="#ffffff" stroke="#a7f3d0" stroke-width="1" rx="4" />
230
+ <g transform="translate(10, 118)">
231
+ <rect width="185" height="24" fill="#ffffff" stroke="#a7f3d0" stroke-width="1" rx="4" />
225
232
  <text x="8" y="16" class="code-text">implementation-report.json</text>
226
233
  </g>
234
+ <g transform="translate(10, 144)">
235
+ <rect width="185" height="24" fill="#ffffff" stroke="#a7f3d0" stroke-width="1" rx="4" />
236
+ <text x="8" y="16" class="code-text">qc-report.json</text>
237
+ </g>
238
+ <g transform="translate(10, 170)">
239
+ <rect width="185" height="24" fill="#ffffff" stroke="#a7f3d0" stroke-width="1" rx="4" />
240
+ <text x="8" y="16" class="code-text">polish-report.json</text>
241
+ </g>
227
242
  </g>
228
243
 
229
244
  <g transform="translate(1000, 255)" class="shadow">
230
245
  <rect width="200" height="130" fill="#f8fafc" stroke="#475569" stroke-width="1.5" rx="8" />
231
246
  <circle cx="100" cy="45" r="18" fill="#059669" />
232
247
  <path d="M94 45 l4 4 l8 -8" fill="none" stroke="#ffffff" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
233
- <text x="100" y="88" class="section-title" font-size="16" text-anchor="middle">Approved</text>
234
- <text x="100" y="108" class="section-title" font-size="16" text-anchor="middle">Clean Implementation</text>
248
+ <text x="100" y="82" class="section-title" font-size="16" text-anchor="middle">Approved</text>
249
+ <text x="100" y="102" class="section-title" font-size="16" text-anchor="middle">Polished Clean</text>
250
+ <text x="100" y="122" class="section-title" font-size="16" text-anchor="middle">Implementation</text>
235
251
  </g>
236
252
 
237
- <line x1="860" y1="157" x2="900" y2="157" stroke="#4b5563" stroke-width="1.5" marker-end="url(#arrow)" />
238
- <line x1="777" y1="235" x2="777" y2="190" stroke="#4b5563" stroke-width="1.5" marker-end="url(#arrow)" />
239
- <line x1="982" y1="190" x2="982" y2="310" stroke="#4b5563" stroke-width="1.5" />
240
- <line x1="982" y1="310" x2="1000" y2="310" stroke="#4b5563" stroke-width="1.5" marker-end="url(#arrow)" />
253
+ <line x1="860" y1="157" x2="870" y2="157" stroke="#4b5563" stroke-width="1.5" marker-end="url(#arrow)" />
254
+ <line x1="1035" y1="157" x2="1045" y2="157" stroke="#4b5563" stroke-width="1.5" marker-end="url(#arrow)" />
255
+ <line x1="777" y1="220" x2="777" y2="190" stroke="#4b5563" stroke-width="1.5" marker-end="url(#arrow)" />
256
+ <line x1="1128" y1="190" x2="1128" y2="255" stroke="#4b5563" stroke-width="1.5" marker-end="url(#arrow)" />
241
257
 
242
- <path d="M 695 390 L 170 390 L 170 370" fill="none" stroke="#374151" stroke-width="1.5" stroke-dasharray="4 4" marker-end="url(#arrow-dash)" />
243
- <rect x="382" y="378" width="196" height="22" fill="#ffffff" rx="4" />
244
- <text x="480" y="394" class="body-bold" text-anchor="middle" font-size="12">Terminal report + deltas only</text>
258
+ <path d="M 695 410 L 170 410 L 170 370" fill="none" stroke="#374151" stroke-width="1.5" stroke-dasharray="4 4" marker-end="url(#arrow-dash)" />
259
+ <rect x="382" y="398" width="196" height="22" fill="#ffffff" rx="4" />
260
+ <text x="480" y="414" class="body-bold" text-anchor="middle" font-size="12">Terminal report + deltas only</text>
245
261
 
246
262
 
247
263
  <line x1="0" y1="460" x2="1240" y2="460" stroke="#e5e7eb" stroke-width="2" />
@@ -303,9 +319,9 @@
303
319
  <rect width="136" height="100" fill="#ffffff" stroke="#2563eb" stroke-width="1" rx="6" />
304
320
  <circle cx="68" cy="-12" r="12" fill="#2563eb" />
305
321
  <text x="68" y="-7" class="step-num" text-anchor="middle">6</text>
306
- <text x="68" y="36" class="body-text" text-anchor="middle">6. Organize into</text>
307
- <text x="68" y="54" class="body-text" text-anchor="middle">selected clean</text>
308
- <text x="68" y="72" class="body-text" text-anchor="middle">schema</text>
322
+ <text x="68" y="28" class="body-text" text-anchor="middle">6. Plan and</text>
323
+ <text x="68" y="44" class="body-text" text-anchor="middle">implement</text>
324
+ <text x="68" y="60" class="body-text" text-anchor="middle">clean slice</text>
309
325
  </g>
310
326
  <line x1="916" y1="575" x2="932" y2="575" stroke="#2563eb" stroke-width="1.5" marker-end="url(#arrow-blue)" />
311
327
 
@@ -313,10 +329,10 @@
313
329
  <rect width="136" height="100" fill="#ffffff" stroke="#2563eb" stroke-width="1" rx="6" />
314
330
  <circle cx="68" cy="-12" r="12" fill="#2563eb" />
315
331
  <text x="68" y="-7" class="step-num" text-anchor="middle">7</text>
316
- <text x="68" y="28" class="body-text" text-anchor="middle">7. QA: schema,</text>
317
- <text x="68" y="44" class="body-text" text-anchor="middle">leakage,</text>
318
- <text x="68" y="60" class="body-text" text-anchor="middle">coverage,</text>
319
- <text x="68" y="76" class="body-text" text-anchor="middle">testability</text>
332
+ <text x="68" y="28" class="body-text" text-anchor="middle">7. Agent 4</text>
333
+ <text x="68" y="44" class="body-text" text-anchor="middle">polish review</text>
334
+ <text x="68" y="60" class="body-text" text-anchor="middle">and local</text>
335
+ <text x="68" y="76" class="body-text" text-anchor="middle">commit</text>
320
336
  </g>
321
337
  <line x1="1068" y1="575" x2="1084" y2="575" stroke="#2563eb" stroke-width="1.5" marker-end="url(#arrow-blue)" />
322
338
 
@@ -324,10 +340,10 @@
324
340
  <rect width="136" height="100" fill="#ffffff" stroke="#2563eb" stroke-width="1" rx="6" />
325
341
  <circle cx="68" cy="-12" r="12" fill="#2563eb" />
326
342
  <text x="68" y="-7" class="step-num" text-anchor="middle">8</text>
327
- <text x="68" y="28" class="body-text" text-anchor="middle">8. Publish</text>
328
- <text x="68" y="44" class="body-text" text-anchor="middle">approved clean-</text>
329
- <text x="68" y="60" class="body-text" text-anchor="middle">room package</text>
330
- <text x="68" y="76" class="body-text" text-anchor="middle">or return gaps</text>
343
+ <text x="68" y="28" class="body-text" text-anchor="middle">8. Agent 0</text>
344
+ <text x="68" y="44" class="body-text" text-anchor="middle">verifies</text>
345
+ <text x="68" y="60" class="body-text" text-anchor="middle">coverage or</text>
346
+ <text x="68" y="76" class="body-text" text-anchor="middle">returns gaps</text>
331
347
  </g>
332
348
 
333
349
  <g transform="translate(140, 650)">