@ludecker/aaac 1.1.6 → 1.2.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.
Files changed (79) hide show
  1. package/package.json +9 -9
  2. package/src/cli.mjs +0 -0
  3. package/src/run-engine/debug-run.mjs +0 -0
  4. package/src/run-engine/log-dump.mjs +0 -0
  5. package/src/run-engine/log-trace.mjs +0 -0
  6. package/templates/cursor/aaac/enforcement.json +84 -3
  7. package/templates/cursor/aaac/graph.project.yaml +28 -0
  8. package/templates/cursor/aaac/lifecycle/lifecycle.json +14 -0
  9. package/templates/cursor/aaac/lifecycle/phases.json +7 -1
  10. package/templates/cursor/aaac/ontology.json +1 -0
  11. package/templates/cursor/aaac/project.config.json +36 -0
  12. package/templates/cursor/aaac/scripts/remediation/auto-check-swarm-synthesis.mjs +75 -0
  13. package/templates/cursor/aaac/scripts/remediation/auto-dispatch-queue-from-health.mjs +78 -0
  14. package/templates/cursor/aaac/scripts/remediation/bootstrap-autonomous.mjs +113 -0
  15. package/templates/cursor/aaac/scripts/remediation/capture-verify-baseline.mjs +66 -0
  16. package/templates/cursor/aaac/scripts/remediation/capture-wave-snapshot.mjs +79 -0
  17. package/templates/cursor/aaac/scripts/remediation/check-swarm-raw.template.json +26 -0
  18. package/templates/cursor/aaac/scripts/remediation/classify-fallow-issues.mjs +77 -0
  19. package/templates/cursor/aaac/scripts/remediation/classify-verify-failure.mjs +176 -0
  20. package/templates/cursor/aaac/scripts/remediation/compute-satisfaction.mjs +344 -0
  21. package/templates/cursor/aaac/scripts/remediation/debt-sweep-gate.mjs +202 -0
  22. package/templates/cursor/aaac/scripts/remediation/dispatch-rules.json +44 -0
  23. package/templates/cursor/aaac/scripts/remediation/fallow-fp-rules.json +87 -0
  24. package/templates/cursor/aaac/scripts/remediation/fallow-scan.mjs +219 -0
  25. package/templates/cursor/aaac/scripts/remediation/handle-yield.mjs +240 -0
  26. package/templates/cursor/aaac/scripts/remediation/init-campaign.mjs +211 -0
  27. package/templates/cursor/aaac/scripts/remediation/lib/autonomous-mode.mjs +63 -0
  28. package/templates/cursor/aaac/scripts/remediation/lib/campaign-focus.mjs +87 -0
  29. package/templates/cursor/aaac/scripts/remediation/lib/fallow-classifier.mjs +190 -0
  30. package/templates/cursor/aaac/scripts/remediation/lib/fallow-health-targets.mjs +56 -0
  31. package/templates/cursor/aaac/scripts/remediation/lib/fallow-metrics.mjs +119 -0
  32. package/templates/cursor/aaac/scripts/remediation/lib/invoke-cursor-agent.mjs +51 -0
  33. package/templates/cursor/aaac/scripts/remediation/lib/reconcile-run-manifest.mjs +41 -0
  34. package/templates/cursor/aaac/scripts/remediation/lib/regression-analysis.mjs +55 -0
  35. package/templates/cursor/aaac/scripts/remediation/lib/remediation-config.mjs +69 -0
  36. package/templates/cursor/aaac/scripts/remediation/lib/remediation-progress.mjs +58 -0
  37. package/templates/cursor/aaac/scripts/remediation/lib/remediation-watch-loop.mjs +168 -0
  38. package/templates/cursor/aaac/scripts/remediation/lib/runner-exec.mjs +156 -0
  39. package/templates/cursor/aaac/scripts/remediation/lib/runner-state.mjs +145 -0
  40. package/templates/cursor/aaac/scripts/remediation/lib/verify-metrics.mjs +205 -0
  41. package/templates/cursor/aaac/scripts/remediation/merge-check-swarm.mjs +257 -0
  42. package/templates/cursor/aaac/scripts/remediation/plan-waves-from-queue.mjs +85 -0
  43. package/templates/cursor/aaac/scripts/remediation/prepare-check-context.mjs +148 -0
  44. package/templates/cursor/aaac/scripts/remediation/record-fallow-fp.mjs +107 -0
  45. package/templates/cursor/aaac/scripts/remediation/record-iteration-step.mjs +56 -0
  46. package/templates/cursor/aaac/scripts/remediation/remediation-cli.mjs +157 -0
  47. package/templates/cursor/aaac/scripts/remediation/remediation-cursor-watch.sh +10 -0
  48. package/templates/cursor/aaac/scripts/remediation/remediation-runner-daemon.sh +13 -0
  49. package/templates/cursor/aaac/scripts/remediation/remediation-runner.mjs +748 -0
  50. package/templates/cursor/aaac/scripts/remediation/remediation-yield-watcher.mjs +40 -0
  51. package/templates/cursor/aaac/scripts/remediation/remediator-gate.mjs +405 -0
  52. package/templates/cursor/aaac/scripts/remediation/repair-fallow-start-baseline.mjs +118 -0
  53. package/templates/cursor/aaac/scripts/remediation/runner-health-check.mjs +164 -0
  54. package/templates/cursor/aaac/scripts/remediation/satisfaction-loop-gate.mjs +286 -0
  55. package/templates/cursor/aaac/scripts/remediation/validate-campaign-complete.mjs +191 -0
  56. package/templates/cursor/aaac/scripts/remediation/verify-remediation-iteration.mjs +112 -0
  57. package/templates/cursor/aaac/scripts/run-engine/debug-run.mjs +0 -0
  58. package/templates/cursor/aaac/scripts/run-engine/log-dump.mjs +0 -0
  59. package/templates/cursor/aaac/scripts/run-engine/log-trace.mjs +0 -0
  60. package/templates/cursor/agents/remediation-check-app-inventory.md +32 -0
  61. package/templates/cursor/agents/remediation-check-app-ssot.md +24 -0
  62. package/templates/cursor/agents/remediation-check-app-trace.md +29 -0
  63. package/templates/cursor/agents/remediation-check-architecture-boundaries.md +21 -0
  64. package/templates/cursor/agents/remediation-check-architecture-decomposition.md +25 -0
  65. package/templates/cursor/agents/remediation-check-architecture-deps.md +23 -0
  66. package/templates/cursor/agents/remediation-check-risk.md +37 -0
  67. package/templates/cursor/agents/remediation-e2e-gate.md +30 -0
  68. package/templates/cursor/agents/remediation-remediator.md +69 -0
  69. package/templates/cursor/commands/remediate-app.md +212 -0
  70. package/templates/cursor/hooks/aaac-before-submit.sh +0 -0
  71. package/templates/cursor/hooks/aaac-pre-tool.sh +0 -0
  72. package/templates/cursor/hooks/aaac-stop.sh +0 -0
  73. package/templates/cursor/hooks/aaac-subagent-start.sh +0 -0
  74. package/templates/cursor/skills/shared/remediation/SKILL.md +51 -0
  75. package/templates/cursor/skills/shared/remediation/babysit/SKILL.md +223 -0
  76. package/templates/cursor/skills/shared/remediation/check-swarm/SKILL.md +114 -0
  77. package/templates/cursor/skills/shared/remediation/orchestrator/SKILL.md +275 -0
  78. package/templates/cursor/skills/shared/remediation/orchestrator/contract.yaml +116 -0
  79. package/templates/docs/agentic_architecture.md +1 -0
@@ -0,0 +1,51 @@
1
+ ---
2
+ name: shared-remediation
3
+ description: Remediation campaign loop — scan, check, fix waves, regression gates, debt sweep, satisfaction.
4
+ disable-model-invocation: true
5
+ ---
6
+
7
+ # Used by `/remediate-app`. See [orchestrator/SKILL.md](./orchestrator/SKILL.md).
8
+
9
+ **Autonomous campaigns:** [babysit/SKILL.md](./babysit/SKILL.md) is **auto-required** when `campaign.config.autonomous` (see `artifacts/autonomous_bootstrap.json`).
10
+
11
+ ## Agentic OS loop
12
+
13
+ ```text
14
+ Planner (check_swarm mirrors check-app + check-architecture → plan_waves)
15
+
16
+ Executor (fix wave)
17
+
18
+ Validator — regression gate (remediator-gate --mode wave)
19
+
20
+ Remediator (fix-module / fix-bug) ← exit 3 = CONTINUE, not stop
21
+
22
+ Validator retry (attempt++)
23
+
24
+ Promote wave (no new regression) → next wave
25
+
26
+ Debt sweep — strict gate (debt-sweep-gate)
27
+
28
+ Remediator loop until all layers green
29
+
30
+ Satisfaction gate → report (validate-campaign-complete first)
31
+ ```
32
+
33
+ ## Two-tier validation
34
+
35
+ | Tier | Script | Pass when |
36
+ |------|--------|-----------|
37
+ | Regression | `remediator-gate --mode wave` | Errors did not **increase** vs pre-wave snapshot |
38
+ | Strict | `debt-sweep-gate` | All layers pass; `total_errors === 0` |
39
+
40
+ ## Loop invariant
41
+
42
+ Every iteration must persist:
43
+
44
+ 1. Verify baseline (campaign start)
45
+ 2. Fallow scan snapshot
46
+ 3. Pre-wave snapshots + wave verify reports
47
+ 4. Debt sweep state + verify-debt.json
48
+ 5. Full logs in `verify-logs/*.log`
49
+ 6. Satisfaction score
50
+
51
+ **Exit 3 never ends the campaign.** Pre-existing debt never blocks cleanup waves.
@@ -0,0 +1,223 @@
1
+ ---
2
+ name: remediate-app-babysit
3
+ description: >-
4
+ Babysit an active /remediate-app campaign using the shell runner. Handles
5
+ runner yields (check_swarm, execute waves, remediator handoffs, report),
6
+ runs health checks, and loops until satisfaction or max iterations. Use when
7
+ asked to continue remediation autonomously, babysit the campaign, or resume
8
+ run_*/campaign_* remediation.
9
+ disable-model-invocation: true
10
+ ---
11
+
12
+ # Remediation babysit (safety layer)
13
+
14
+ **Auto-invoked** when `campaign.config.autonomous === true` (set by `init-campaign.mjs`). The user does not need a separate “babysit” prompt.
15
+
16
+ Pairs with the **shell runner** (foundation). The runner drives scriptable phases; this skill handles **yields** and **safety**.
17
+
18
+ | Layer | Script / skill | Role |
19
+ |-------|----------------|------|
20
+ | Foundation | `remediation-runner.mjs` | State machine, gates, satisfaction loop |
21
+ | Daemon | `remediation-runner-daemon.sh` | Delegates to continuous yield watcher |
22
+ | Watcher | `remediation-yield-watcher.mjs` | Continuous loop until satisfaction goal |
23
+
24
+ ## When to use
25
+
26
+ - Campaign `status: running` but chat stopped mid-iteration
27
+ - `runner-yield.json` exists (runner exit **3**)
28
+ - User asks to **continue**, **babysit**, or **run autonomously** to satisfaction threshold
29
+ - After `/remediate-app` with `max_iterations` > 5 or `satisfaction_threshold=100`
30
+
31
+ ## When NOT to use
32
+
33
+ - Campaign `status: complete` and satisfaction gate says `complete`
34
+ - No `runner-state.json` — run `remediation-runner.mjs --tick` once to init, or start via `/remediate-app`
35
+ - User explicitly wants a single manual iteration only
36
+
37
+ ## Hard rules
38
+
39
+ 1. **Exit 3 ≠ stop** — runner yield, remediator gate, satisfaction gate continue = keep going
40
+ 2. **Never report** while `satisfaction-loop-gate` says `continue_loop`
41
+ 3. **Run health check** before each babysit cycle
42
+ 4. **Ack every yield** with `--ack-yield <type>` after agent work — runner will not advance otherwise
43
+ 5. **check_swarm** — exactly **7** readonly Task agents (see [check-swarm/SKILL.md](../check-swarm/SKILL.md))
44
+ 6. **Test-only waves** — use `test_execute` phase for test file dedupes, or mark wave `degraded` in `execute_waves.json`
45
+
46
+
47
+
48
+ ## Cursor CLI watch (preferred for monitoring)
49
+
50
+ Readable live progress in the **Cursor integrated terminal** (not a background shell task):
51
+
52
+ ```bash
53
+ node .cursor/aaac/scripts/remediation/remediation-cli.mjs watch \
54
+ --run-id <run_id> --campaign-id <campaign_id>
55
+ ```
56
+
57
+ Each cycle prints a line like:
58
+ `[remediate] iter 8 | execute/wave_fix wave 1 | score 45/100 | health 88.7 → yield execute_wave`
59
+
60
+ Snapshot SSOT: `.cursor/aaac/state/campaigns/<campaign_id>/progress.json`
61
+
62
+ One-shot status:
63
+ ```bash
64
+ node .cursor/aaac/scripts/remediation/remediation-cli.mjs status --campaign-id <id> --run-id <run_id>
65
+ ```
66
+
67
+ Via Cursor agent CLI (agent session supervises the watch command):
68
+ ```bash
69
+ node .cursor/aaac/scripts/remediation/remediation-cli.mjs cursor --run-id <run_id> --campaign-id <id>
70
+ # or: .cursor/aaac/scripts/remediation/remediation-cursor-watch.sh <run_id> <campaign_id>
71
+ ```
72
+
73
+ ## Continuous yield watcher (headless / CI)
74
+
75
+ Runs until `satisfaction_threshold` is met (extends `max_iterations` if needed):
76
+
77
+ ```bash
78
+ node .cursor/aaac/scripts/remediation/remediation-yield-watcher.mjs \
79
+ --run-id <run_id> --campaign-id <campaign_id>
80
+ # Monitor: ^AGENT_REMEDIATION_WATCHER
81
+ ```
82
+
83
+ Each cycle: health-check → runner `--until-yield` → `handle-yield.mjs` (scriptable + Cursor agent for code waves) → `--ack-yield` → repeat.
84
+
85
+ Background via daemon:
86
+
87
+ ```bash
88
+ .cursor/aaac/scripts/remediation/remediation-runner-daemon.sh <run_id> <campaign_id>
89
+ ```
90
+
91
+ Focus is parsed from campaign intent (`focus: Health Functions >60 LOC`, protected paths, wave intents).
92
+
93
+ ## Autonomous loop (mandatory pattern)
94
+
95
+ ```text
96
+ 1. health-check
97
+ 2. runner --until-yield (or daemon script)
98
+ 3. if exit 0 → validate + report → done
99
+ 4. if exit 3 → read runner-yield.json → do agent work → --ack-yield <type> → goto 1
100
+ 5. if exit 1 → journal + user handoff (blocked)
101
+ ```
102
+
103
+ ### Commands
104
+
105
+ ```bash
106
+ # Status
107
+ node .cursor/aaac/scripts/remediation/remediation-runner.mjs \
108
+ --run-id <run_id> --campaign-id <campaign_id> --status
109
+
110
+ # Health (stall / regression)
111
+ node .cursor/aaac/scripts/remediation/runner-health-check.mjs \
112
+ --campaign-id <campaign_id>
113
+
114
+ # Automated burst (stops at yield)
115
+ node .cursor/aaac/scripts/remediation/remediation-runner.mjs \
116
+ --run-id <run_id> --campaign-id <campaign_id> --until-yield
117
+
118
+ # Background daemon with sentinel (optional)
119
+ .cursor/aaac/scripts/remediation/remediation-runner-daemon.sh \
120
+ <run_id> <campaign_id>
121
+ # Monitor: ^AGENT_REMEDIATION_RUNNER
122
+ ```
123
+
124
+ ## Yield handlers
125
+
126
+ | `yield.type` | Agent work | Ack |
127
+ |--------------|------------|-----|
128
+ | `check_swarm` | 7 parallel Task agents → `iterations/{n}/check-swarm-raw.json` | `--ack-yield check_swarm` |
129
+ | `dispatch_queue` | Write `dispatch-queue.yaml` from merge synthesis | `--ack-yield dispatch_queue` |
130
+ | `execute_wave` | Inline `fix-module` / `fix-app` per wave intent; update `execute_waves.json` | `--ack-yield execute_wave` |
131
+ | `remediator` | Run handoff from `remediator-handoff-attempt-*.json` inline | `--ack-yield remediator` |
132
+ | `report` | Write `artifacts/report.md`, complete Run | `--ack-yield report` |
133
+
134
+ After each ack:
135
+
136
+ ```bash
137
+ node .cursor/aaac/scripts/remediation/remediation-runner.mjs \
138
+ --run-id <run_id> --campaign-id <campaign_id> --ack-yield <type>
139
+ ```
140
+
141
+ Then immediately `--until-yield` again.
142
+
143
+ ### check_swarm yield (7 agents)
144
+
145
+ Read `iterations/{n}/check-context.json`. Launch in **one message**:
146
+
147
+ - remediation-check-app-inventory
148
+ - remediation-check-app-ssot
149
+ - remediation-check-app-trace
150
+ - remediation-check-architecture-boundaries
151
+ - remediation-check-architecture-deps
152
+ - remediation-check-architecture-decomposition
153
+ - remediation-check-risk
154
+
155
+ Merge parent writes `check-swarm-raw.json`, then:
156
+
157
+ ```bash
158
+ node .cursor/aaac/scripts/remediation/merge-check-swarm.mjs \
159
+ --campaign-id <id> --iteration <n> --run-id <run_id>
160
+ ```
161
+
162
+ Parent writes `dispatch-queue.yaml` + `artifacts/check_synthesis.md`, then `--ack-yield check_swarm`.
163
+
164
+ ### execute_wave yield
165
+
166
+ 1. Read `artifacts/plan_waves.yaml` wave `wave_index`
167
+ 2. Respect `artifacts/protected_paths.yaml`
168
+ 3. Apply fix inline (no nested AAAC Run)
169
+ 4. Record wave in `artifacts/execute_waves.json` (`completed` | `degraded` | `deferred`)
170
+ 5. `--ack-yield execute_wave` → runner runs regression gate
171
+
172
+ ### remediator yield
173
+
174
+ 1. Read `yield.handoff` or latest `remediator-handoff-attempt-*.json`
175
+ 2. Fix inline per [remediation-remediator.md](../../../../agents/remediation-remediator.md)
176
+ 3. `--ack-yield remediator` → runner retries gate with `attempt + 1`
177
+
178
+ ## Safety checks (`runner-health-check.mjs`)
179
+
180
+ | Code | Meaning | Action |
181
+ |------|---------|--------|
182
+ | `stall_ticks` | Score/clones flat too long | Change wave plan or fix stuck yield |
183
+ | `yield_timeout` | Agent yield stale | Complete ack or escalate |
184
+ | `dupes_regression` | Clone groups grew >5% vs baseline | Stop deletes; re-run check_swarm |
185
+ | `health_regression` | Health dropped >2 pts | Roll back last wave |
186
+ | `flat_satisfaction` | 3 iterations same score | Prioritize dupes/health waves |
187
+
188
+ Exit **1** from health check → investigate before continuing automated runner.
189
+
190
+ ## Resume paused campaign (chat died at iteration N)
191
+
192
+ ```bash
193
+ # 1. Find run + campaign from campaign.json
194
+ cat .cursor/aaac/state/campaigns/<campaign_id>/campaign.json
195
+
196
+ # 2. Init runner state from manifest (if missing)
197
+ node .cursor/aaac/scripts/remediation/remediation-runner.mjs \
198
+ --run-id <run_id> --campaign-id <campaign_id> --status
199
+
200
+ # 3. If phase=scan and iter 3 has stale artifacts from older run, re-scan:
201
+ node .cursor/aaac/scripts/remediation/fallow-scan.mjs \
202
+ --campaign-id <id> --iteration <n>
203
+
204
+ # 4. Babysit loop
205
+ ```
206
+
207
+ ## Completion
208
+
209
+ Only when runner exits **0**:
210
+
211
+ ```bash
212
+ node .cursor/aaac/scripts/remediation/validate-campaign-complete.mjs \
213
+ --campaign-id <id> --iteration <n> \
214
+ --require-debt-sweep --require-satisfaction-loop
215
+ ```
216
+
217
+ Write report if `yield.type=report` not yet acked.
218
+
219
+ ## Related
220
+
221
+ - [orchestrator/SKILL.md](../orchestrator/SKILL.md) — phase contracts
222
+ - [check-swarm/SKILL.md](../check-swarm/SKILL.md) — 7-agent mirror
223
+ - `/remediate-app` command — manual + runner bootstrap
@@ -0,0 +1,114 @@
1
+ ---
2
+ name: remediate-check-swarm
3
+ description: >-
4
+ Remediation check_swarm — mirrors /check-app and /check-architecture before
5
+ Fallow-driven fix waves. Readonly. Prevents false-positive deletions.
6
+ disable-model-invocation: true
7
+ ---
8
+
9
+ # Remediation check_swarm
10
+
11
+ **Readonly.** Runs after `fallow-scan.mjs` + `classify-fallow-issues.mjs`. **No code edits** in this phase.
12
+
13
+ Mirrors two AAAC check commands with Fallow-scoped intent:
14
+
15
+ | Mirror | Question | Object skills (graph) |
16
+ |--------|----------|------------------------|
17
+ | `/check-app` | Which Fallow dead-code/dupes hits are **live app surface** (workers, barrels, lazy routes, payment providers)? | `architecture`, `integration` |
18
+ | `/check-architecture` | Which proposed deletions/dedup extractions would **break boundaries, SSOT, or runtime graphs**? | `architecture`, `documentation` |
19
+
20
+ ## Preflight (parent — mandatory)
21
+
22
+ ```bash
23
+ node .cursor/aaac/scripts/remediation/prepare-check-context.mjs \
24
+ --campaign-id <id> --iteration <n> [--run-id <run_id>]
25
+ ```
26
+
27
+ Read `iterations/{n}/check-context.json` — SSOT input for every agent.
28
+
29
+ ## Swarm (mandatory — **7 parallel Task agents**, one message)
30
+
31
+ Each agent: `subagent_type: explore`, `readonly: true`. Prompt **must** include policy from [_task-prompt-policy.md](../../_task-prompt-policy.md), `check-context.json` path, and agent spec path.
32
+
33
+ ### Wave A — check-app mirror (3 agents)
34
+
35
+ | # | Agent spec | Base agent | Focus |
36
+ |---|------------|------------|-------|
37
+ | 1 | [remediation-check-app-inventory.md](../../../../agents/remediation-check-app-inventory.md) | discovery-inventory | Entry points, workers, dynamic imports, overlay barrels vs Fallow `unused_files` |
38
+ | 2 | [remediation-check-app-ssot.md](../../../../agents/remediation-check-app-ssot.md) | discovery-ssot | Ownership: who consumes each `review`/`true_positive` symbol; runtime vs static |
39
+ | 3 | [remediation-check-app-trace.md](../../../../agents/remediation-check-app-trace.md) | check-capability-trace | `fallow dead-code --trace-file` / `--trace` for top `review` items in context |
40
+
41
+ ### Wave B — check-architecture mirror (3 agents)
42
+
43
+ | # | Agent spec | Base agent | Focus |
44
+ |---|------------|------------|-------|
45
+ | 4 | [remediation-check-architecture-boundaries.md](../../../../agents/remediation-check-architecture-boundaries.md) | boundary-review | Layer violations, cross-module coupling on delete candidates |
46
+ | 5 | [remediation-check-architecture-deps.md](../../../../agents/remediation-check-architecture-deps.md) | dependency-analysis | Import cycles, fan-in, blast radius of file/export removal |
47
+ | 6 | [remediation-check-architecture-decomposition.md](../../../../agents/remediation-check-architecture-decomposition.md) | system-decomposition | Dupes families (operations/, workers/ mirrors); safe extract vs delete |
48
+
49
+ ### Wave C — remediation guard (1 agent)
50
+
51
+ | # | Agent spec | Focus |
52
+ |---|------------|-------|
53
+ | 7 | [remediation-check-risk.md](../../../../agents/remediation-check-risk.md) | Confirm FP traps; **must** output `false_positives[]` for `merge-check-swarm.mjs` |
54
+
55
+ **Dispatch planner** is parent synthesis (not a Task agent) after merge.
56
+
57
+ ## Agent return shape (mandatory JSON block in final message)
58
+
59
+ ```json
60
+ {
61
+ "agent_id": "remediation-check-app-inventory",
62
+ "command_mirror": "check-app",
63
+ "answer": "yes | no | partial",
64
+ "confidence": "high | medium | low",
65
+ "false_positives": [
66
+ { "path": "src/hooks/useCryptoPriceWorker.ts", "export_name": null, "reason": "worker_hook_runtime", "evidence": "path:line" }
67
+ ],
68
+ "protected_paths": ["src/overlays/renderers/line/index.ts"],
69
+ "do_not_delete": [{ "path": "...", "reason": "..." }],
70
+ "safe_to_fix": [{ "path": "...", "category": "unused_export", "evidence": "path:line" }],
71
+ "findings": ["bullet"],
72
+ "gaps": ["what was not confirmed"]
73
+ }
74
+ ```
75
+
76
+ ## Post-swarm merge (parent — mandatory)
77
+
78
+ 1. Collect all 7 JSON blocks into `iterations/{n}/check-swarm-raw.json`
79
+ 2. Run merge:
80
+
81
+ ```bash
82
+ node .cursor/aaac/scripts/remediation/merge-check-swarm.mjs \
83
+ --campaign-id <id> --iteration <n> [--run-id <run_id>]
84
+ ```
85
+
86
+ 3. Re-read `iterations/{n}/fallow-classification.json` (merge re-runs classifier)
87
+
88
+ ## Parent artifacts (run + campaign)
89
+
90
+ | Artifact | Mirrors |
91
+ |----------|---------|
92
+ | `artifacts/check_app_validate.yaml` | `/check-app` validate phase |
93
+ | `artifacts/check_architecture_fitness.yaml` | `/check-architecture` fitness phase |
94
+ | `artifacts/check_synthesis.md` | Combined Answer + How + guardrails |
95
+ | `artifacts/dispatch-queue.yaml` | Ranked waves — **must** include `protected_paths` |
96
+ | `artifacts/protected_paths.yaml` | Paths/regions waves must not delete |
97
+ | `iterations/{n}/check-swarm-merge.json` | Merged FP registry + actionable list |
98
+
99
+ ## Dispatch guardrails (mandatory in every wave intent)
100
+
101
+ Every wave in `dispatch-queue.yaml` **must**:
102
+
103
+ 1. Copy `protected_paths` from merge output verbatim into `exclude:` block
104
+ 2. Never target paths classified `false_positive` in `fallow-false-positives.json`
105
+ 3. Prefer `fix-module` export trim over file delete when classification is `review`
106
+ 4. Run `fallow dead-code --trace-file` before any `remove-module` / file delete wave
107
+
108
+ ## Anti-patterns (forbidden)
109
+
110
+ - Skipping check-app or check-architecture mirrors (all 7 agents required)
111
+ - Deleting files from Fallow `unused_files` without trace-file evidence
112
+ - Bulk `fallow fix --yes` without swarm FP review
113
+ - Planning waves from raw Fallow totals (use `actionable_total` + merge output)
114
+ - Ignoring dupes **main/worker mirror** families — extract shared, do not delete one side
@@ -0,0 +1,275 @@
1
+ ---
2
+ name: remediate-app-orchestrator
3
+ description: >-
4
+ Orchestrates /remediate-app — Fallow scan, check swarm, ranked fix waves,
5
+ regression wave gates, mandatory debt sweep, satisfaction loop.
6
+ disable-model-invocation: true
7
+ ---
8
+
9
+ # remediate-app orchestrator
10
+
11
+ Campaign loop for whole-repo health remediation. Model after [platform-release/orchestrator](../../platform-release/orchestrator/SKILL.md) wave blocking.
12
+
13
+ Fallow scan suite: **dead-code** + **dupes** + **health** (all three run every iteration via `fallow-scan.mjs`).
14
+
15
+ Contract: [contract.yaml](./contract.yaml)
16
+
17
+ ## Hard invariants (never violate)
18
+
19
+ | Rule | Meaning |
20
+ |------|---------|
21
+ | **Exit 3 ≠ stop** | `remediator-gate` / `debt-sweep-gate` exit **3** means **remediate and retry**. Never set `campaign.status=blocked`, never skip remaining waves, never advance to `report`. |
22
+ | **Wave = regression** | Pre-existing typecheck/vitest debt does **not** block wave promotion. Only **new** regressions vs pre-wave snapshot trigger wave remediator. |
23
+ | **Debt sweep = strict** | After all waves, `debt_sweep` must reach **zero errors** on all layers before `satisfaction_gate` or `report`. |
24
+ | **All waves run** | Every wave in `plan_waves.yaml` must execute (status `completed`, `degraded`, or `deferred`) — never skip waves 2–3 because wave 1 handed off. |
25
+ | **Validate before report** | Run `validate-campaign-complete.mjs --require-debt-sweep --require-satisfaction-loop`; exit 1 → do not complete Run. |
26
+ | **Satisfaction exit 3 ≠ report** | `satisfaction-loop-gate` exit **3** → `--advance` to next iteration, return to `scan`. |
27
+ | **Immutable Fallow start** | `fallow-start-baseline.json` (dead-code), `fallow-start-dupes-baseline.json`, `fallow-start-health-baseline.json` written once; dupes/health auto-backfill if missing |
28
+
29
+ ## Parse
30
+
31
+ | Slot | Rule |
32
+ |------|------|
33
+ | Domain | Optional — `frontend`, `backend`, or omit for `whole-repo` |
34
+ | Intent | `max_iterations`, `max_waves_per_iteration`, `max_remediator_attempts_per_wave`, `max_remediator_attempts_per_debt_round`, `max_debt_sweep_rounds`, `satisfaction_threshold`, `resume campaign_*`, `autonomous` / `manual` |
35
+
36
+ **Autonomous mode (baked in):** `init-campaign.mjs` sets `config.autonomous` when any of:
37
+
38
+ - intent contains `autonomous`
39
+ - `satisfaction_threshold >= 100`
40
+ - `max_iterations >= 10`
41
+
42
+ Override off with `manual` in intent.
43
+
44
+ When `config.autonomous === true`, **do not walk phases manually**. Read [babysit/SKILL.md](../babysit/SKILL.md) and follow `artifacts/autonomous_bootstrap.json` → `next_action` until runner exit **0**.
45
+
46
+ **Preflight:** When `remediation.verify.playwright.enabled`, ensure dev server is reachable at `project.config.json` → `remediation.verify.dev_server.url` before debt sweep / Playwright gates.
47
+
48
+ ## Scripts (mandatory)
49
+
50
+ | Step | Command |
51
+ |------|---------|
52
+ | Init campaign | `node .cursor/aaac/scripts/remediation/init-campaign.mjs --run-id <run_id> --scope whole-repo --intent "<intent>"` |
53
+ | Verify baseline | `node .cursor/aaac/scripts/remediation/capture-verify-baseline.mjs --campaign-id <id> --run-id <run_id>` |
54
+ | Fallow scan | `node .cursor/aaac/scripts/remediation/fallow-scan.mjs --campaign-id <id> --iteration <n> [--save-baseline]` — runs dead-code, dupes, health |
55
+ | Classify Fallow | `node .cursor/aaac/scripts/remediation/classify-fallow-issues.mjs --campaign-id <id> --iteration <n>` (auto after scan) |
56
+ | Prepare check context | `node .cursor/aaac/scripts/remediation/prepare-check-context.mjs --campaign-id <id> --iteration <n> --run-id <run_id>` |
57
+ | Merge check swarm | `node .cursor/aaac/scripts/remediation/merge-check-swarm.mjs --campaign-id <id> --iteration <n> --run-id <run_id>` |
58
+ | Record false positive | `node .cursor/aaac/scripts/remediation/record-fallow-fp.mjs --campaign-id <id> --path <file> --classification false_positive` |
59
+ | Pre-wave snapshot | `node .cursor/aaac/scripts/remediation/capture-wave-snapshot.mjs --campaign-id <id> --iteration <n> --wave-index <w>` |
60
+ | Wave gate | `node .cursor/aaac/scripts/remediation/remediator-gate.mjs --campaign-id <id> --iteration <n> --mode wave --wave-index <w> --run-id <run_id> --attempt 1` |
61
+ | Debt sweep | `node .cursor/aaac/scripts/remediation/debt-sweep-gate.mjs --campaign-id <id> --iteration <n> --run-id <run_id> --round 1 --attempt 1` |
62
+ | Validate complete | `node .cursor/aaac/scripts/remediation/validate-campaign-complete.mjs --campaign-id <id> --iteration <n> --require-debt-sweep` |
63
+ | Satisfaction | `node .cursor/aaac/scripts/remediation/compute-satisfaction.mjs --campaign-id <id> --iteration <n>` |
64
+ | Satisfaction loop gate | `node .cursor/aaac/scripts/remediation/satisfaction-loop-gate.mjs --campaign-id <id> --iteration <n> --run-id <run_id> [--advance]` |
65
+ | Repair Fallow start | `node .cursor/aaac/scripts/remediation/repair-fallow-start-baseline.mjs --campaign-id <id> --total <n>` |
66
+ | Journal step | `node .cursor/aaac/scripts/remediation/record-iteration-step.mjs --campaign-id <id> --step <name> --detail "..." --status pass\|fail` |
67
+
68
+ ## Phases
69
+
70
+ ### 1. campaign_init
71
+
72
+ 1. Run `init-campaign.mjs`
73
+ 2. If `config.autonomous` → read `artifacts/autonomous_bootstrap.json` and **[babysit/SKILL.md](../babysit/SKILL.md)**; enter runner loop (skip manual phase walk below)
74
+ 3. Run `capture-verify-baseline.mjs` (records pre-campaign error counts) — runner also does this on first tick if resuming
75
+ 4. Write `artifacts/campaign.json` and `artifacts/verify_baseline.json`
76
+
77
+ **Autonomous first action after init:**
78
+
79
+ ```bash
80
+ node .cursor/aaac/scripts/remediation/runner-health-check.mjs --campaign-id <id>
81
+ node .cursor/aaac/scripts/remediation/remediation-runner.mjs \
82
+ --run-id <run_id> --campaign-id <id> --until-yield
83
+ ```
84
+
85
+ Then babysit loop until exit **0**. Never end turn on exit **3**.
86
+
87
+ ### 2. scan
88
+
89
+ 1. Set iteration `n = campaign.iteration`
90
+ 2. Run `fallow-scan.mjs --save-baseline` **only** when:
91
+ - New campaign (`fallow-start-baseline.json` missing), or
92
+ - Starting a **new** iteration (`n > 0` or first scan after `--advance`)
93
+ 3. On **resume** of same iteration: run `fallow-scan.mjs` **without** `--save-baseline`
94
+
95
+ Readonly. No code edits.
96
+
97
+ ### 3. check_swarm (parallel — **7 Task agents**, one message)
98
+
99
+ **Skill:** [check-swarm/SKILL.md](../check-swarm/SKILL.md) — mirrors `/check-app` + `/check-architecture`.
100
+
101
+ **Preflight:**
102
+
103
+ ```bash
104
+ node .cursor/aaac/scripts/remediation/prepare-check-context.mjs \
105
+ --campaign-id <id> --iteration <n> --run-id <run_id>
106
+ ```
107
+
108
+ | Wave | Agent spec | Mirrors |
109
+ |------|------------|---------|
110
+ | A1 | remediation-check-app-inventory | `/check-app` inventory |
111
+ | A2 | remediation-check-app-ssot | `/check-app` SSOT |
112
+ | A3 | remediation-check-app-trace | `/check-app` trace (+ `fallow --trace-file`) |
113
+ | B1 | remediation-check-architecture-boundaries | `/check-architecture` boundaries |
114
+ | B2 | remediation-check-architecture-deps | `/check-architecture` dependencies |
115
+ | B3 | remediation-check-architecture-decomposition | `/check-architecture` dupes families |
116
+ | C1 | remediation-check-risk | FP registry guard |
117
+
118
+ **Post-merge (mandatory):**
119
+
120
+ ```bash
121
+ # Parent writes iterations/{n}/check-swarm-raw.json from agent JSON blocks first
122
+ node .cursor/aaac/scripts/remediation/merge-check-swarm.mjs \
123
+ --campaign-id <id> --iteration <n> --run-id <run_id>
124
+ ```
125
+
126
+ **Parent synthesis:** `artifacts/check_synthesis.md`, `artifacts/dispatch-queue.yaml` (include `protected_paths` from merge)
127
+
128
+ Outputs: `check_app_validate.yaml`, `check_architecture_fitness.yaml`, `protected_paths.yaml`, `check_swarm_merge.json`, updates `fallow-false-positives.json`
129
+
130
+ **Fallow SSOT:** Dead-code raw counts are not remediation truth. After scan, `classify-fallow-issues.mjs` splits dead-code into `true_positive`, `review`, and `false_positive`. Satisfaction uses **actionable** dead-code, **clone_groups** (dupes), and **health_score** (health). Swarm-confirmed false positives go to `record-fallow-fp.mjs` → `fallow-false-positives.json`.
131
+
132
+ ### 4. plan_waves
133
+
134
+ 1. Validate dispatch queue entries
135
+ 2. Truncate to `max_waves_per_iteration`
136
+ 3. Write `artifacts/plan_waves.yaml`
137
+
138
+ Readonly.
139
+
140
+ ### 5. execute (sequential waves only)
141
+
142
+ For **each** wave in `plan_waves.yaml`:
143
+
144
+ 1. `capture-wave-snapshot.mjs --wave-index <w>` (pre-wave metrics)
145
+ 2. Apply fix per wave `command` + `intent` (inline fix-* orchestrator — no nested Run)
146
+ 3. **Remediator sub-loop (mandatory):**
147
+
148
+ ```text
149
+ attempt ← 1
150
+ loop:
151
+ remediator-gate --mode wave --wave-index <w> --attempt <attempt>
152
+ if action in (promote, promote_wave, defer_to_debt_sweep) → break # continue to NEXT wave
153
+ if action=remediate (exit 3):
154
+ run remediation-remediator handoff inline
155
+ attempt ← attempt + 1
156
+ goto loop # NEVER stop campaign here
157
+ if action=infrastructure → fix infra, retry
158
+ ```
159
+
160
+ 4. Record wave status `completed` | `degraded` | `deferred` in `artifacts/execute_waves.json`
161
+ 5. **Always proceed to next wave** — never abort execute phase on exit 3
162
+
163
+ ### 6. debt_sweep (mandatory strict gate)
164
+
165
+ Clears **all** remaining errors (old + new). Runs after every iteration's execute phase.
166
+
167
+ ```text
168
+ round ← 1
169
+ attempt ← 1
170
+ loop:
171
+ debt-sweep-gate --round <round> --attempt <attempt>
172
+ if action=debt_sweep_complete → break
173
+ if action=remediate (exit 3):
174
+ run remediation-remediator handoff inline
175
+ attempt ← attempt + 1
176
+ goto loop
177
+ if action=debt_sweep_next_round → round++, attempt←1, goto loop
178
+ if action=debt_sweep_blocked → campaign blocked (only after max_debt_sweep_rounds)
179
+ ```
180
+
181
+ Full logs: `iterations/{n}/verify-logs/debt-*.log`
182
+ Artifacts: `artifacts/debt_sweep.json`, `verify-debt.json`
183
+
184
+ ### 7. satisfaction_gate
185
+
186
+ ```bash
187
+ node .cursor/aaac/scripts/remediation/compute-satisfaction.mjs --campaign-id <id> --iteration <n>
188
+
189
+ node .cursor/aaac/scripts/remediation/satisfaction-loop-gate.mjs \
190
+ --campaign-id <id> --iteration <n> --run-id <run_id> --advance
191
+ ```
192
+
193
+ | Gate exit | Action |
194
+ |-----------|--------|
195
+ | `0` + `action: complete` | Threshold met → `report` |
196
+ | `0` + `action: partial_complete` | Max iterations → `report` (partial) |
197
+ | `3` + `action: continue_loop` | **Return to `scan`** for `next_iteration` — **never report** |
198
+ | `1` | Debt/verify prerequisites missing — fix first |
199
+
200
+ **Fallow start baseline** is immutable (`fallow-start-baseline.json`). Never rescored from resume scans.
201
+
202
+ ### 8. report
203
+
204
+ **Before writing report:**
205
+
206
+ ```bash
207
+ node .cursor/aaac/scripts/remediation/validate-campaign-complete.mjs \
208
+ --campaign-id <id> --iteration <n> --require-debt-sweep --require-satisfaction-loop
209
+ ```
210
+
211
+ If violations → do not complete Run. `satisfaction_loop_blocks_report` means iteration 1+ was required.
212
+
213
+ ## Autonomous platform
214
+
215
+ For multi-iteration campaigns, use the shell runner + babysit skill instead of relying on chat stop-hook loops.
216
+
217
+ | Component | Role |
218
+ |-----------|------|
219
+ | `remediation-runner.mjs` | Drives scriptable phases; **yields** (exit 3) for agent work |
220
+ | `remediation-runner-daemon.sh` | Background automated bursts; emits `AGENT_REMEDIATION_RUNNER` |
221
+ | `runner-health-check.mjs` | Stall, regression, yield-timeout detection |
222
+ | [babysit/SKILL.md](../babysit/SKILL.md) | Handles yields, acks, safety |
223
+
224
+ ```bash
225
+ node .cursor/aaac/scripts/remediation/remediation-runner.mjs \
226
+ --run-id <run_id> --campaign-id <id> --until-yield
227
+ # exit 3 → babysit → --ack-yield <type> → repeat
228
+ ```
229
+
230
+ Runner state: `campaigns/{id}/runner-state.json`, yields: `runner-yield.json`.
231
+
232
+ ## Two-tier validation
233
+
234
+ | Tier | When | Pass condition |
235
+ |------|------|----------------|
236
+ | **Regression** | After each cleanup wave | Error counts did **not increase** vs pre-wave snapshot |
237
+ | **Strict** | `debt_sweep` phase | typecheck, vitest, go test, build, Playwright all pass; `total_errors === 0` |
238
+
239
+ ## Anti-patterns (forbidden)
240
+
241
+ - Treating remediator exit **3** as campaign stop
242
+ - Setting `campaign.status=blocked` on wave handoff
243
+ - Skipping waves because verify failed on pre-existing debt
244
+ - Completing Run while `debt_sweep` pending or remediator loop `running`
245
+ - Writing report when `satisfaction-loop-gate` exits **3**
246
+ - Re-scanning with `--save-baseline` on resume (overwrites immutable start baseline)
247
+ - Using stderr tails only — read `verify-logs/*.log` for full evidence
248
+ - Bulk `fallow fix --yes` without trace-file
249
+
250
+ ## Persistence paths
251
+
252
+ ```
253
+ .cursor/aaac/state/campaigns/{campaign_id}/
254
+ campaign.json
255
+ fallow-start-baseline.json
256
+ fallow-start-dupes-baseline.json
257
+ fallow-start-health-baseline.json
258
+ journal.md
259
+ iterations/{n}/
260
+ fallow-scan.json
261
+ fallow-dupes.json
262
+ fallow-health.json
263
+ fallow-scan-bundle.json
264
+ fallow-scan-bundle.json
265
+ fallow-classification.json
266
+ check-context.json
267
+ check-swarm-raw.json
268
+ check-swarm-merge.json
269
+ protected-paths.json
270
+ verify-wave.json
271
+ verify-debt.json
272
+ verify-logs/
273
+ debt-sweep-state.json
274
+ remediator-loop-wave-{w}.json
275
+ ```