@dogfood-lab/dogfood-swarm 1.2.1

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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +136 -0
  3. package/cli.js +1095 -0
  4. package/commands/collect.js +529 -0
  5. package/commands/dispatch.js +262 -0
  6. package/commands/history.js +118 -0
  7. package/commands/init.js +104 -0
  8. package/commands/persist.js +137 -0
  9. package/commands/receipt.js +352 -0
  10. package/commands/redrive.js +578 -0
  11. package/commands/resume.js +242 -0
  12. package/commands/revalidate.js +445 -0
  13. package/commands/rewind.js +486 -0
  14. package/commands/status.js +506 -0
  15. package/commands/verify-approved.js +181 -0
  16. package/commands/verify-fixed.js +152 -0
  17. package/commands/verify-recurring.js +188 -0
  18. package/commands/verify-unverified.js +138 -0
  19. package/commands/verify.js +144 -0
  20. package/db/connection.js +141 -0
  21. package/db/schema.js +340 -0
  22. package/lib/advance.js +435 -0
  23. package/lib/domains.js +359 -0
  24. package/lib/error-render.js +69 -0
  25. package/lib/errors.js +114 -0
  26. package/lib/findings-digest.js +284 -0
  27. package/lib/findings-filter.js +52 -0
  28. package/lib/findings-render.js +502 -0
  29. package/lib/fingerprint.js +262 -0
  30. package/lib/git-touched-files.js +117 -0
  31. package/lib/log-stage.js +142 -0
  32. package/lib/output-schema.js +220 -0
  33. package/lib/persist/dogfood-bridge.js +104 -0
  34. package/lib/persist/export.js +175 -0
  35. package/lib/persist/repoknowledge-bridge.js +117 -0
  36. package/lib/state-machine.js +278 -0
  37. package/lib/templates.js +498 -0
  38. package/lib/validate-agent-output.js +121 -0
  39. package/lib/verify/adapters/node.js +96 -0
  40. package/lib/verify/adapters/python.js +96 -0
  41. package/lib/verify/adapters/rust.js +91 -0
  42. package/lib/verify/registry.js +102 -0
  43. package/lib/verify/runner.js +125 -0
  44. package/lib/verify-classifier-v2.js +541 -0
  45. package/lib/verify-fixed.js +359 -0
  46. package/lib/wave-state-machine.js +266 -0
  47. package/lib/worktree.js +244 -0
  48. package/package.json +65 -0
  49. package/persist-results.js +250 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mcp-tool-shop
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,136 @@
1
+ <p align="center">
2
+ <a href="https://github.com/dogfood-lab/testing-os">
3
+ <img src="https://raw.githubusercontent.com/dogfood-lab/testing-os/main/assets/logo.png" alt="testing-os" width="280">
4
+ </a>
5
+ </p>
6
+
7
+ # @dogfood-lab/dogfood-swarm
8
+
9
+ > 10-phase parallel-agent protocol runner for testing-os. SQLite-backed control plane, durable receipts, domain-aware orchestration. Three R's recovery contract: `revalidate` / `rewind` / `redrive`.
10
+
11
+ Part of the [`testing-os`](https://github.com/dogfood-lab/testing-os) monorepo — the operating system for testing in the AI era.
12
+
13
+ The `swarm` CLI runs parallel-agent audits against a codebase. Each wave dispatches multiple agents under exclusive file ownership, collects their outputs through the verifier, and persists durable receipts to a SQLite control plane. The wave-level and agent-level state machines surface every status transition as an auditable event; the recovery verbs (`revalidate`, `rewind`, `redrive`) handle wave failures lawfully without raw SQL surgery.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm install -g @dogfood-lab/dogfood-swarm
19
+ ```
20
+
21
+ Binary: `swarm`. Requires Node ≥ 20.
22
+
23
+ ## Quick start
24
+
25
+ ```bash
26
+ # Initialize a swarm run
27
+ swarm dispatch <run-id> <wave-number>
28
+
29
+ # (Agents execute externally — e.g., parallel Claude sessions — and write
30
+ # their outputs to swarms/<run-id>/wave-N/<domain>/output.json)
31
+
32
+ # Collect outputs through the verifier
33
+ swarm collect <run-id>
34
+
35
+ # Inspect current wave + agent state
36
+ swarm status <run-id>
37
+
38
+ # Inspect wave transition history (full audit chain)
39
+ swarm history <wave-id>
40
+
41
+ # Generate per-wave receipt artifact
42
+ swarm receipt <run-id>
43
+
44
+ # Advance to the next phase once gates pass
45
+ swarm advance <run-id>
46
+ ```
47
+
48
+ ## Recovery — the Three R's
49
+
50
+ | Verb | When to use | Behavior |
51
+ |---|---|---|
52
+ | `swarm revalidate` | Agents wrote `invalid_output` — schema mismatch, validator rejection | Repairs in place; transitions agent_runs out of BLOCKED status via override (with operator `--reason`); wave-level rollback if all 4 agents repaired |
53
+ | `swarm rewind` | Wave needs full restart from a save-point; tree state needs reset | Restores tree via `git reset --hard <tag>`; lawfully aborts orphaned in-flight runs to terminal `aborted_for_rewind`; preserves audit chain (append-only) |
54
+ | `swarm redrive` | Some agents failed, others completed; want to resume the failing tail without re-running completed work | Same `wave_id`, completed receipts preserved byte-identical, only failed/pending agents made re-dispatchable |
55
+
56
+ All three recovery verbs share the same operator-safety contract:
57
+
58
+ - **Dry-run by default** — `--apply` required to mutate
59
+ - **`--reason "<text>"` required, non-empty** — recorded in `wave_state_events` / `agent_state_events` with a verb-specific prefix (`revalidate:` / `rewind:` / `redrive:`)
60
+ - **Zero raw SQL on `agent_runs.status` or `waves.status`** — every state mutation routes through `transitionAgent` / `transitionWave`; static-scan guard test (Pattern #10) blocks regressions
61
+
62
+ Example session:
63
+
64
+ ```bash
65
+ # Failed wave needs schema-mismatch repair
66
+ swarm revalidate <run-id> --reason "wave-2 schema mismatch corrected" --apply
67
+
68
+ # Wedged wave — restart from save-point tag
69
+ swarm rewind <save-point-tag> --reason "rolling back wedged amend wave" --apply
70
+
71
+ # Transient infra failure — resume only the failed agents
72
+ swarm redrive <wave-id> --reason "GitHub API outage retry" --apply
73
+
74
+ # Audit the full transition chain for any wave
75
+ swarm history <wave-id>
76
+ ```
77
+
78
+ ## State machines
79
+
80
+ Two parallel state machines:
81
+
82
+ - **Agent runs** (`lib/state-machine.js`): `pending → dispatched → complete | failed | invalid_output | ownership_violation | aborted_for_rewind`
83
+ - **Waves** (`lib/wave-state-machine.js`): `dispatched → collected → verified → advanced | failed | aborted_for_rewind`
84
+
85
+ Discipline:
86
+
87
+ - **Terminal statuses** (`complete`, `advanced`, `aborted_for_rewind`) cannot be transitioned out of — not even with `override=true`.
88
+ - **BLOCKED statuses** (`failed`, `invalid_output`, `ownership_violation`) require explicit `override=true` + non-empty `reason` to transition out.
89
+ - Every transition lands in `wave_state_events` / `agent_state_events` **atomically** with the underlying status mutation, inside the same SQLite transaction.
90
+
91
+ ## Control plane
92
+
93
+ SQLite-backed. Each swarm run gets `swarms/<run-id>/control-plane.db`:
94
+
95
+ | Table | Purpose |
96
+ |---|---|
97
+ | `waves` | Wave records (status, phase, wave_number, run_id, snapshot, serial_verify_required) |
98
+ | `agent_runs` | Per-agent dispatch records (status, domain, output_path, verification_skipped) |
99
+ | `wave_state_events` | Append-only wave-status audit log (from_status, to_status, reason, created_at) |
100
+ | `agent_state_events` | Append-only agent-status audit log (mirror shape of wave_state_events) |
101
+ | `findings` | Findings derived from agent outputs |
102
+ | `domain_events` | Domain-map mutation audit log (unfreeze / edit / freeze) |
103
+
104
+ Read via `swarm status`, `swarm history`, `swarm receipt`. Never via raw SQL in scripts — the state-machine helpers are the supported interface and the audit chain depends on going through them.
105
+
106
+ ## 10-phase protocol
107
+
108
+ | Phase | Purpose |
109
+ |---|---|
110
+ | 1–4 (Health Pass) | Audit → Review → Amend → Repeat. Three stages: A (bug/security fix), B (proactive health), C (humanization), D (visual/presentation truth). Closes at 0 CRIT / 0 HIGH. |
111
+ | 5–8 (Feature Pass) | Feature audit → user review → execution → repeat. Production-readiness focus. |
112
+ | 9 | Final test pass — comprehensive validation across the whole system. |
113
+ | 10 | Full Treatment — shipcheck, README finalize + translations, landing page, handbook, repo-knowledge DB entry, deploy + verify. |
114
+
115
+ Each wave produces a manifest (`swarms/<run-id>/manifest.json`) and per-wave receipts (`swarms/<run-id>/wave-N/receipt.md`) for durable audit. A swarm is **not complete** until Phase 10 finishes.
116
+
117
+ ## Domain ownership
118
+
119
+ Agents in a wave have exclusive file ownership scoped to their domain (typical domains: backend, bridge, tests, ci-tooling, frontend, docs). The frozen domain map at dispatch time is the canonical authority; the agent prompt is derived from the frozen state so dispatch + agent + verifier all consume the same shape.
120
+
121
+ Cross-domain mutation surfaces at collect time as status `ownership_violation` (BLOCKED). Recovery options:
122
+
123
+ - `swarm domains --unfreeze --reason "..." → --edit <domain> --globs "..." → --freeze` — to legitimately extend a domain's scope (recorded in `domain_events`)
124
+ - `swarm revalidate` — if the agent's `files_changed` self-report turns out to match the original frozen scope after coordinator review
125
+
126
+ ## Save-point discipline
127
+
128
+ The repo's git tags + commits ARE the save points. Commits on `main` are the durable mechanism for "I can roll back to here." `swarm rewind` accepts any git tag matching `swarm-save-*` by default (`--force-arbitrary-ref` opts into any ref). Rewind is dry-run safe; verified by an explicit HEAD-guard test that confirms the actual repo's HEAD is unchanged after the rewind test suite runs (cordoned-test discipline).
129
+
130
+ ## Docs
131
+
132
+ 📖 Full handbook: **<https://dogfood-lab.github.io/testing-os/handbook/>**
133
+
134
+ ## License
135
+
136
+ MIT © 2026 mcp-tool-shop