@yemi33/minions 0.1.1883 → 0.1.1885

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.
@@ -0,0 +1,215 @@
1
+ # Completion Reports
2
+
3
+ Every Minions agent ends its dispatch by writing a JSON completion report. The report is the engine's primary, machine-readable signal that the work item is finished and is the source of truth for status, retry decisions, dashboard surfaces, and downstream automation. Fenced ` ```completion ` blocks in stdout are still parsed as a compatibility fallback, but the JSON file always wins when both exist.
4
+
5
+ This document is the canonical schema. Playbooks should cross-link here instead of restating the field list.
6
+
7
+ ## Where the report is written
8
+
9
+ The engine injects the absolute path two ways before spawning each agent:
10
+
11
+ - `MINIONS_COMPLETION_REPORT` environment variable
12
+ - The same path appears in the rendered playbook prompt
13
+
14
+ Path shape (resolved by `shared.dispatchCompletionReportPath()` in `engine/shared.js`):
15
+
16
+ ```
17
+ <MINIONS_DIR>/engine/completions/<dispatch-id>.json
18
+ ```
19
+
20
+ The agent must write the JSON to that exact path before exiting. Any character outside `[a-zA-Z0-9._-]` in the dispatch id is replaced with `-` by the engine when computing the path.
21
+
22
+ ## Top-level schema
23
+
24
+ ```json
25
+ {
26
+ "status": "success",
27
+ "summary": "what changed and how it was validated",
28
+ "verdict": null,
29
+ "pr": "PR id/url or N/A",
30
+ "failure_class": "N/A",
31
+ "retryable": false,
32
+ "needs_rerun": false,
33
+ "noop": false,
34
+ "artifacts": [
35
+ {"type": "pr", "path": "https://github.com/owner/repo/pull/123", "title": "PR-123"}
36
+ ]
37
+ }
38
+ ```
39
+
40
+ ### Required fields
41
+
42
+ | Field | Type | Notes |
43
+ |---|---|---|
44
+ | `status` | string | One of `success`, `partial`, `failed`. Aliases `done` / `complete` are accepted on read for `success`. The engine refuses to mark a work item done without a status. |
45
+ | `summary` | string | Short prose describing what changed and how it was validated. Truncated to 500 chars in dashboard surfaces (`engine/queries.js`). Do not summarize validation as "tests passed" — name the commands that ran. |
46
+ | `verdict` | string \| null | Required for review tasks: `approved` or `changes-requested`. `null` for non-review tasks. Aliases: `approve`, `request_changes`, `changes_requested`. |
47
+ | `pr` | string | PR URL, `PR-<number>`, or `N/A`. The engine uses this to attach the PR to the work item; missing-PR detection treats anything other than a recognizable URL/PR id as missing unless `noop: true` is set. |
48
+ | `failure_class` | string | One of the `failure_class` enum values below, or `N/A`. Drives retry policy in `engine/dispatch.js` and recovery routing in `engine/recovery.js`. |
49
+ | `retryable` | boolean | `true` if the engine should auto-retry the dispatch on failure. Overrides the default per-class retry policy when present. |
50
+ | `needs_rerun` | boolean | `true` if the same work needs to be re-dispatched (vs. retried). Used by build-fix and review-fix loops. |
51
+ | `artifacts` | array | Durable artifacts the agent created or updated; surfaces in the dashboard work-item detail modal. See [Artifacts](#artifacts). |
52
+
53
+ ### Optional fields
54
+
55
+ | Field | Type | Notes |
56
+ |---|---|---|
57
+ | `noop` | boolean | Canonical no-op signal. See [No-op semantics](#no-op-semantics). |
58
+ | `noopReason` | string | Human-readable rationale shown when `noop: true`. Falls back to `summary` if absent. |
59
+ | `files_changed` | string \| array | Comma-separated list (or array) of key files changed. |
60
+ | `tests` | string | `pass`, `fail`, `skipped`, `N/A`, or a free-form note like `skipped — relying on PR pipeline`. |
61
+ | `pending` | string | Any remaining work, or `none`. |
62
+
63
+ ## `failure_class` enum
64
+
65
+ Defined in `engine/shared.js` as `FAILURE_CLASS`. Use the canonical hyphenated string.
66
+
67
+ | Value | When to use | Default escalation |
68
+ |---|---|---|
69
+ | `config-error` | CLI not found, exit code 78, malformed config | Never retry |
70
+ | `permission-blocked` | Trust gate, permission denied, auth failure | Never retry |
71
+ | `merge-conflict` | Git merge conflict in worktree or dependency | Retry same agent |
72
+ | `build-failure` | Compilation, lint, or test failure introduced by the agent | Retry same agent |
73
+ | `timeout` | Hard runtime timeout or stale-orphan timeout | Retry with fresh session |
74
+ | `empty-output` | Agent produced no meaningful output | Flag for human review |
75
+ | `spawn-error` | Process failed to start or crashed immediately | Retry with fresh session |
76
+ | `network-error` | API rate limit, DNS, connectivity | Default retry logic |
77
+ | `out-of-context` | Context window exhausted | Flag for human review |
78
+ | `max-turns` | Claude CLI `error_max_turns` — work in progress | Retry same agent |
79
+ | `unknown` | Unclassified failure | Default retry logic |
80
+
81
+ Use `"N/A"` when `status` is `success` or `partial` without a failure.
82
+
83
+ ## No-op semantics
84
+
85
+ A no-op completion declares that the agent correctly **declined** to do the work — the change was already shipped on master, the dispatch premise was wrong, the flagged review comment was an author-note, etc.
86
+
87
+ To signal a no-op:
88
+
89
+ ```json
90
+ {
91
+ "status": "success",
92
+ "summary": "PR #2372 Linux CI fix already shipped by parallel agent — nothing to do",
93
+ "pr": "N/A",
94
+ "noop": true,
95
+ "noopReason": "Fix already on master at commit abc1234"
96
+ }
97
+ ```
98
+
99
+ Engine behavior when `noop: true` (`engine/lifecycle.js` `parseCompletionNoop` + `runPostCompletionHooks`):
100
+
101
+ - The work item is marked `done` with the rationale stored as `_noopReason` (visible in the dashboard).
102
+ - The PR-attachment contract is **skipped**, so an empty `pr` field will not be flagged as a silent failure or auto-retried.
103
+ - Any non-success `status` combined with `noop: true` is treated as a contradiction and falls through to the normal contract.
104
+
105
+ Without `noop: true`, an empty PR field will be flagged as a missing-PR-attachment failure and auto-retried up to `ENGINE_DEFAULTS.maxRetries` times.
106
+
107
+ ## `retryable` and `needs_rerun`
108
+
109
+ Both default to `false`. Together they let the agent override the engine's default retry policy:
110
+
111
+ - `retryable: true` — engine should treat the failure as transient and re-dispatch (subject to `maxRetries` and the per-class escalation policy).
112
+ - `retryable: false` — engine should not auto-retry; the failure is terminal for this dispatch.
113
+ - `needs_rerun: true` — even on `status: success`, the same work item should be re-dispatched (used by review-fix and build-fix loops where one pass cannot complete the work).
114
+
115
+ When the agent sets either field, it overrides the per-`failure_class` default in `isRetryableFailureReason()` (`engine/dispatch.js`).
116
+
117
+ ## Artifacts
118
+
119
+ `artifacts` is an array of objects with this shape:
120
+
121
+ ```json
122
+ {"type": "pr", "path": "https://github.com/owner/repo/pull/123", "title": "PR-123: Stale HEAD guard"}
123
+ ```
124
+
125
+ | Field | Type | Notes |
126
+ |---|---|---|
127
+ | `type` | string | One of `note`, `plan`, `prd`, `pr`, `file`. |
128
+ | `path` | string | Relative repo path, absolute path, or URL. |
129
+ | `title` | string | Short label used in the dashboard list. |
130
+
131
+ The dashboard caps the rendered list at 20 artifacts per report (`engine/queries.js`). Include every durable artifact you created or updated — PRs, plan/PRD files, key source files, inbox notes — so the work-item detail modal can show them.
132
+
133
+ ## Validation and source-of-truth precedence
134
+
135
+ The engine reads completion signals in this order (`engine/lifecycle.js`):
136
+
137
+ 1. The JSON report at `MINIONS_COMPLETION_REPORT` — primary.
138
+ 2. A fenced ` ```completion ` block in the agent's stdout — fallback only.
139
+ 3. Process exit code and stdout heuristics — last-resort recovery.
140
+
141
+ If the JSON report exists and is well-formed, the engine ignores the fenced block. If the JSON is missing or malformed (logged as a warning), the engine falls back to the fenced block, then to stdout parsing.
142
+
143
+ ## Examples
144
+
145
+ ### Successful implement
146
+
147
+ ```json
148
+ {
149
+ "status": "success",
150
+ "summary": "Added stale-HEAD guard to push step in spawn-agent.js; verified with new unit test test/unit/spawn-agent.test.js (4632 passed, 0 failed)",
151
+ "verdict": null,
152
+ "pr": "https://github.com/yemi33/minions/pull/2360",
153
+ "failure_class": "N/A",
154
+ "retryable": false,
155
+ "needs_rerun": false,
156
+ "artifacts": [
157
+ {"type": "pr", "path": "https://github.com/yemi33/minions/pull/2360", "title": "PR-2360"},
158
+ {"type": "file", "path": "engine/spawn-agent.js", "title": "Stale-HEAD guard"},
159
+ {"type": "file", "path": "test/unit/spawn-agent.test.js", "title": "New unit test"}
160
+ ]
161
+ }
162
+ ```
163
+
164
+ ### Successful review
165
+
166
+ ```json
167
+ {
168
+ "status": "success",
169
+ "summary": "Verified completeRun sweep is inside mutateJsonFileLocked callback and pre-existing terminal stages are preserved.",
170
+ "verdict": "approved",
171
+ "pr": "https://github.com/yemi33/minions/pull/2313",
172
+ "failure_class": "N/A",
173
+ "retryable": false,
174
+ "needs_rerun": false,
175
+ "artifacts": [
176
+ {"type": "pr", "path": "https://github.com/yemi33/minions/pull/2313", "title": "PR-2313"}
177
+ ]
178
+ }
179
+ ```
180
+
181
+ ### Failed build
182
+
183
+ ```json
184
+ {
185
+ "status": "failed",
186
+ "summary": "test/unit.test.js — c-c-multi-tab.test.js:409 fails on stale _joinCcPromptParts 4-arg signature; needs master rebase.",
187
+ "verdict": null,
188
+ "pr": "N/A",
189
+ "failure_class": "build-failure",
190
+ "retryable": true,
191
+ "needs_rerun": false,
192
+ "artifacts": []
193
+ }
194
+ ```
195
+
196
+ ### No-op
197
+
198
+ ```json
199
+ {
200
+ "status": "success",
201
+ "summary": "Fix already shipped on master at commit eb2e7230 by parallel agent.",
202
+ "pr": "N/A",
203
+ "noop": true,
204
+ "noopReason": "Linux CI fix already on master before this dispatch started"
205
+ }
206
+ ```
207
+
208
+ ## Related
209
+
210
+ - `engine/shared.js` — `FAILURE_CLASS`, `COMPLETION_FIELDS`, `dispatchCompletionReportPath()`
211
+ - `engine/lifecycle.js` — `parseCompletionReportFile()`, `parseCompletionNoop()`, `enforcePrAttachmentContract()`
212
+ - `engine/dispatch.js` — `isRetryableFailureReason()`, `writeFailedAgentReport()`
213
+ - `engine/recovery.js` — per-`failure_class` recovery recipes
214
+ - `docs/rfc-completion-json.md` — original RFC describing the protocol's design
215
+ - `playbooks/shared-rules.md` — the per-task "Completion Reports" instruction every playbook inherits
@@ -1,5 +1,7 @@
1
1
  # Engine Restart & Agent Survival
2
2
 
3
+ > Last verified: 2026-05-12 against `engine.js` (`engineRestartGraceUntil`, line 161) and `engine/shared.js` `ENGINE_DEFAULTS` (`restartGracePeriod: 1200000`, `heartbeatTimeout: 300000`, `agentTimeout: 18000000`).
4
+
3
5
  ## The Problem
4
6
 
5
7
  When the engine restarts, it loses its in-memory process handles (`activeProcesses` Map). Claude CLI agents spawned before the restart may still be running as OS processes, but the engine can't monitor their process state, detect exit codes, or manage their lifecycle. Stale-orphan detection keeps these dispatch records from staying active forever after the restart grace period expires.
@@ -0,0 +1,173 @@
1
+ # Knowledge Base Sweep
2
+
3
+ How the `knowledge/` directory stays curated, deduplicated, and small enough to keep injecting into agent prompts.
4
+
5
+ ## What the Sweep Does
6
+
7
+ The KB sweep is a 3-pass cycle implemented in [`engine/kb-sweep.js`](../engine/kb-sweep.js) that prunes duplicate, stale, and oversized entries from `knowledge/`. It runs asynchronously, archives (rather than deletes) what it removes, and writes a `_swept` frontmatter flag so the expensive rewrite pass is idempotent.
8
+
9
+ ```
10
+ Entries in knowledge/<category>/*.md
11
+ → Pass 1: Hash dedup (cheap, no LLM)
12
+ → Pass 2: LLM batch sweep (Haiku, batches of 30)
13
+ → Pass 3: Per-entry rewrite (Haiku, concurrency 5)
14
+ → Prune _swept/ archive (>30 days)
15
+ → Invalidate KB cache, write engine/kb-swept.json
16
+ ```
17
+
18
+ ## The 3-Pass Cycle
19
+
20
+ ### Pass 1 — Hash Dedup
21
+
22
+ Cheap, deterministic. No LLM call.
23
+
24
+ For every entry, compute `sha256(normalize(content).slice(0,500) + ':' + content.length)` (source: [`engine/kb-sweep.js:29`](../engine/kb-sweep.js#L29)). Group by hash. When two or more entries collide, keep the most recent (by `date:` frontmatter, then mtime) and archive the rest into `knowledge/_swept/` with a `<!-- swept: ... | reason: hash-duplicate of ... -->` header (source: [`engine/kb-sweep.js:84-105`](../engine/kb-sweep.js#L84)).
25
+
26
+ This catches near-identical re-postings across batches that the LLM pass might miss because they land in different batches.
27
+
28
+ ### Pass 2 — LLM Batch Sweep
29
+
30
+ The remaining survivors are sent to Claude Haiku in batches of `LLM_BATCH_SIZE = 30` (source: [`engine/kb-sweep.js:25`](../engine/kb-sweep.js#L25)). Each batch prompt asks for three lists in JSON:
31
+
32
+ | Field | What the LLM looks for |
33
+ |-------|------------------------|
34
+ | `duplicates` | Entries with substantially the same content. Returned as `{keep, remove[], reason}`. |
35
+ | `reclassify` | Entries in the wrong category. Returned as `{index, from, to, reason}`. |
36
+ | `remove` | Stale or empty entries (boilerplate, "no changes needed", bail-out notes). Returned as `{index, reason}`. |
37
+
38
+ Each action archives the file via the same `_archiveKbFile()` helper used by Pass 1; reclassification rewrites the `category:` frontmatter line and moves the file into the new category directory (source: [`engine/kb-sweep.js:243-279`](../engine/kb-sweep.js#L243)).
39
+
40
+ Reclassification targets are validated against `shared.KB_CATEGORIES` (`architecture`, `conventions`, `project-notes`, `build-reports`, `reviews` — source: [`engine/shared.js:1012`](../engine/shared.js#L1012)); unknown categories are silently dropped.
41
+
42
+ If a batch returns invalid JSON or the runtime is unavailable, that batch is skipped with a warning and the rest of the sweep continues (source: [`engine/kb-sweep.js:139-151`](../engine/kb-sweep.js#L139)).
43
+
44
+ ### Pass 3 — Per-Entry Rewrite
45
+
46
+ Survivors of Passes 1 and 2 that are still on disk get rewritten one entry at a time, with up to `NORMALIZE_CONCURRENCY = 5` parallel workers (source: [`engine/kb-sweep.js:26`](../engine/kb-sweep.js#L26)). Each entry is sent to Haiku with a fixed template prompt that:
47
+
48
+ - Caps output at ~800 words.
49
+ - Forces the structure `## Summary` → `## Key Findings` → `## Action Items` (omit if none) → `## References` (omit if none).
50
+ - Preserves all `file:line` references and code snippets.
51
+ - Drops boilerplate (full dates, agent IDs in the body, narrative scaffolding).
52
+
53
+ After a successful rewrite, the entry's frontmatter gains a `_swept: <ISO timestamp>` key (source: [`engine/kb-sweep.js:229`](../engine/kb-sweep.js#L229)).
54
+
55
+ ## The `_swept` Frontmatter Flag
56
+
57
+ `_swept` makes Pass 3 idempotent across runs. Semantics:
58
+
59
+ - **Set** to `new Date().toISOString()` whenever the rewrite pass successfully rewrites the body (source: [`engine/kb-sweep.js:229`](../engine/kb-sweep.js#L229)).
60
+ - **Skipped** by Pass 3 on subsequent sweeps as long as the file's `mtimeMs` is `<= sweptAt + 1000` ms (1 s grace for FS timestamp jitter — source: [`engine/kb-sweep.js:196-202`](../engine/kb-sweep.js#L196)).
61
+ - **Re-processed** if the file is edited after the sweep flag was set (mtime exceeds the grace window).
62
+
63
+ Hash dedup (Pass 1) and the LLM sweep (Pass 2) ignore `_swept` — those passes act on metadata and similarity, not on whether the entry was previously rewritten.
64
+
65
+ The flag key is exported as `SWEPT_FLAG_KEY` for tests (source: [`engine/kb-sweep.js:27,429`](../engine/kb-sweep.js#L27)).
66
+
67
+ ## 30-Day Archive Retention
68
+
69
+ Archived entries land in `knowledge/_swept/` with their original filename (deduped via `shared.uniquePath()` if it collides). They're not deleted immediately — `_pruneOldSwept()` runs at the end of every sweep and removes any file whose `mtimeMs` is older than `SWEPT_RETENTION_MS = 30 * 24 * 60 * 60 * 1000` (30 days — source: [`engine/kb-sweep.js:23,69-81`](../engine/kb-sweep.js#L23)).
70
+
71
+ This gives humans a recovery window: if a sweep archives something useful, you have ~30 days to copy it back out of `_swept/` before it's permanently pruned.
72
+
73
+ ## Manual Trigger
74
+
75
+ The dashboard exposes two endpoints:
76
+
77
+ | Method | Path | Purpose |
78
+ |--------|------|---------|
79
+ | `POST` | `/api/knowledge/sweep` | Start a sweep in the background. Returns `202 { ok: true, started: true }` (source: [`dashboard.js:7351`](../dashboard.js#L7351), [`dashboard.js:4285`](../dashboard.js#L4285)). |
80
+ | `GET` | `/api/knowledge/sweep/status` | Poll `{ inFlight, startedAt, lastResult, lastCompletedAt }` (source: [`dashboard.js:7352`](../dashboard.js#L7352), [`dashboard.js:4335`](../dashboard.js#L4335)). |
81
+
82
+ POST body is optional. Pass `{ "pinnedKeys": ["knowledge/conventions/foo.md", ...] }` to add request-level pins on top of `pinned.md`. Pinned entries are excluded from every pass (source: [`engine/kb-sweep.js:345-356`](../engine/kb-sweep.js#L345)).
83
+
84
+ ```bash
85
+ # Trigger a sweep
86
+ curl -X POST http://localhost:7331/api/knowledge/sweep \
87
+ -H 'Content-Type: application/json' \
88
+ -d '{}'
89
+
90
+ # Poll status
91
+ curl http://localhost:7331/api/knowledge/sweep/status
92
+ ```
93
+
94
+ ### Concurrency Guard
95
+
96
+ Only one sweep runs at a time. The POST handler refuses to start a second sweep with `{ ok: true, alreadyRunning: true, startedAt }` while one is in flight (source: [`dashboard.js:4306-4311`](../dashboard.js#L4306)).
97
+
98
+ The guard auto-releases when the sweep has been running longer than `staleGuardMs(entryCount)` — `max(30 min, 1 s × entryCount)` — which protects against a dashboard process that died mid-sweep leaving the flag stuck (source: [`engine/kb-sweep.js:413-417`](../engine/kb-sweep.js#L413), [`dashboard.js:4286-4305`](../dashboard.js#L4286)).
99
+
100
+ ### Persistent State
101
+
102
+ Sweep state is mirrored to `engine/kb-sweep-state.json` so the dashboard can recover the in-flight indicator across restarts:
103
+
104
+ ```jsonc
105
+ // While running
106
+ { "status": "in-flight", "startedAt": 1715472000000, "startedAtIso": "2026-05-12T..." }
107
+
108
+ // On success
109
+ { "status": "completed", "startedAt": ..., "completedAt": ..., "durationMs": ..., "summary": "...", "lastResult": { ... } }
110
+
111
+ // On failure
112
+ { "status": "failed", "startedAt": ..., "completedAt": ..., "error": "..." }
113
+ ```
114
+
115
+ Memory still wins when present; the disk file is a fallback (source: [`engine/kb-sweep.js:298-320`](../engine/kb-sweep.js#L298), [`dashboard.js:4296-4354`](../dashboard.js#L4296)). A separate `engine/kb-swept.json` is written after each successful sweep with the human-readable summary line shown by the dashboard's "swept N days ago" badge (source: [`engine/kb-sweep.js:407`](../engine/kb-sweep.js#L407)).
116
+
117
+ ## Dashboard UI
118
+
119
+ The KB page surfaces sweep state in two places:
120
+
121
+ 1. **Trigger button** (`kbSweep()` in [`dashboard/js/render-kb.js:166`](../dashboard/js/render-kb.js#L166)) posts to `/api/knowledge/sweep` with the user's pinned keys and shows an immediate "queued" toast. If the response says `alreadyRunning`, the toast switches to "already running (Xm elapsed) — let it finish first".
122
+ 2. **`#kb-swept-time` indicator** renders `swept N days ago · now sweeping (Xm)` (source: [`dashboard/js/render-kb.js:72-82`](../dashboard/js/render-kb.js#L72)). The `sweepInFlight` and `sweepStartedAt` fields come from `GET /api/knowledge` (source: [`dashboard.js:4262-4267`](../dashboard.js#L4262)).
123
+
124
+ ### Polling
125
+
126
+ The KB page is refreshed by the dashboard's main refresh loop **every third tick (~12 s)** in [`dashboard/js/refresh.js:121`](../dashboard/js/refresh.js#L121). There is no separate sweep-status polling timer and no auto-stop — the in-flight badge keeps refreshing for as long as the user has the dashboard open and the sweep is running. Sweeps can take many minutes for a large KB; the persistent `engine/kb-sweep-state.json` flag plus the indefinite refresh loop are what let the indicator survive dashboard restarts and arbitrarily long sweeps.
127
+
128
+ ## Result Summary
129
+
130
+ `runKbSweep()` returns (and persists in `engine/kb-swept.json`):
131
+
132
+ ```js
133
+ {
134
+ ok: true,
135
+ entriesBefore, entriesAfter,
136
+ bytesBefore, bytesAfter,
137
+ hashDuplicatesArchived, // Pass 1
138
+ llmDuplicatesArchived, // Pass 2 (within-batch dupes)
139
+ staleRemoved, // Pass 2 (LLM-flagged removals)
140
+ reclassified, // Pass 2 (category moves)
141
+ rewritten, // Pass 3
142
+ rewriteBytesBefore, rewriteBytesAfter,
143
+ sweptArchivePruned, // Files purged from _swept/ (>30 days)
144
+ durationMs,
145
+ summary: '<n> hash-dup, <n> llm-dup, <n> stale, <n> reclassified, <n> rewritten (<bytes> saved)',
146
+ }
147
+ ```
148
+
149
+ After a non-dry-run sweep, `queries.invalidateKnowledgeBaseCache()` is called so the next `/api/knowledge` read sees the new state (source: [`engine/kb-sweep.js:408`](../engine/kb-sweep.js#L408)).
150
+
151
+ ## What NOT to Do
152
+
153
+ > **Never write to `knowledge/` directly.** The sweep is the only writer. Every other code path — agents, dashboard handlers, scripts — should write findings to `notes/inbox/<agent>-<id>-<date>.md` and let the consolidation engine classify them into `knowledge/<category>/`.
154
+
155
+ Why this matters:
156
+
157
+ - Direct writes bypass the hash-dedup, classification, and `_swept` rewrite passes, so future sweeps see a "fresh" entry and may immediately rewrite or archive it.
158
+ - Editing an entry resets its `mtime`, which makes the `_swept` flag stale (re-rewrite on next sweep) and silently changes the entry the next consolidation pass diffs against.
159
+ - Manual edits collide with the LLM rewrite pass — your edit can be replaced wholesale by the next sweep.
160
+ - Per the team-wide rule injected into every dispatched playbook: **"Never delete, move, or overwrite files in `knowledge/`."**
161
+
162
+ If you spot an incorrect KB entry, write a note to `notes/inbox/` describing the issue. The next sweep will reclassify, merge, or remove it; humans can also pin entries (via `pinned.md` or the dashboard) to keep them out of the sweep entirely.
163
+
164
+ The archive directory `knowledge/_swept/` is also off-limits to manual edits — touching it interferes with the 30-day retention timestamp.
165
+
166
+ ## Related Files
167
+
168
+ - [`engine/kb-sweep.js`](../engine/kb-sweep.js) — implementation
169
+ - [`engine/queries.js`](../engine/queries.js) — `getKnowledgeBaseEntries()`, `invalidateKnowledgeBaseCache()`
170
+ - [`dashboard.js`](../dashboard.js) — `handleKnowledgeSweep`, `handleKnowledgeSweepStatus`, `handleKnowledgeList`
171
+ - [`dashboard/js/render-kb.js`](../dashboard/js/render-kb.js) — UI trigger and indicator
172
+ - [`dashboard/js/refresh.js`](../dashboard/js/refresh.js) — refresh cadence (every 3rd tick)
173
+ - [`engine/shared.js`](../engine/shared.js) — `KB_CATEGORIES`, `getPinnedItems()`, `uniquePath()`
@@ -0,0 +1,246 @@
1
+ # Minions Onboarding — Your First 30 Minutes
2
+
3
+ A fast, hands-on walkthrough for new contributors. Follow the eight steps below in order. Each step is independent enough that you can stop, take a break, and resume without losing state.
4
+
5
+ > **Prerequisites:** Node.js 18+, Git, and a working Claude Code CLI (`npm install -g @anthropic-ai/claude-code`) authenticated against your Anthropic API key or Claude Max subscription. See the top-level [README.md](../README.md#prerequisites) for the full list.
6
+
7
+ > **Screenshots:** This walkthrough is intentionally text-only on the first pass. If you want annotated dashboard screenshots, run the [`capture-demos`](../README.md#dashboard) skill after Step 5; it drives Playwright over the running dashboard and writes images you can drop alongside each section.
8
+
9
+ ---
10
+
11
+ ## Step 1 — Clone the repo
12
+
13
+ You only need to clone if you intend to modify Minions itself. End users normally `npm install -g @yemi33/minions` instead, but a checkout is the right starting point for contributors.
14
+
15
+ ```bash
16
+ git clone https://github.com/yemi33/minions.git ~/minions-dev
17
+ cd ~/minions-dev
18
+ npm install # installs dev tooling (Playwright); engine itself has zero deps
19
+ ```
20
+
21
+ You should now have:
22
+
23
+ - `engine.js` — the orchestrator entry point
24
+ - `dashboard.js` — the HTTP/UI server (binds `:7331`)
25
+ - `minions.js` — the CLI shim that maps `minions <cmd>` to the right script
26
+ - `playbooks/`, `agents/`, `prompts/`, `docs/` — content the engine renders into agent prompts
27
+ - `test/` — `unit.test.js`, the integration suite, and Playwright specs
28
+
29
+ If you cloned to somewhere other than `~/.minions`, the CLI will still work — `minions init` writes runtime state under `~/.minions/` regardless of where the source lives. The `node` scripts under your checkout will use the checkout as the runtime root when invoked directly (e.g. `node ./engine.js start`).
30
+
31
+ ---
32
+
33
+ ## Step 2 — Run `minions doctor`
34
+
35
+ `minions doctor` runs the same preflight checks the engine runs at startup. It is safe to run any time and never mutates state.
36
+
37
+ ```bash
38
+ minions doctor
39
+ ```
40
+
41
+ A healthy Mac/Linux run looks roughly like:
42
+
43
+ ```
44
+ Runtime:
45
+
46
+ ✓ node: v20.11.1 (>= 18 required)
47
+ ✓ git: git version 2.45.0
48
+ ✓ claude CLI: 1.0.x found on PATH
49
+
50
+ Authentication:
51
+
52
+ ✓ ANTHROPIC_API_KEY: set
53
+ ✓ gh auth: logged in as <you>
54
+
55
+ Filesystem:
56
+
57
+ ✓ ~/.minions writable
58
+ ✓ engine/ writable
59
+
60
+ All checks passed.
61
+ ```
62
+
63
+ What to look for:
64
+
65
+ - `✓` (green) means OK. `!` is a warning the engine can usually work around. `✗` (critical) will block dispatch — fix it before continuing.
66
+ - The most common failure is `claude CLI: not found` — re-install with `npm install -g @anthropic-ai/claude-code` and re-run.
67
+ - On Windows, runtime resolution prefers native `claude.exe` over the POSIX bash shim; if you see runtime-resolution warnings, `gh auth status` and `where.exe claude` are good first stops.
68
+
69
+ If `doctor` reports any `✗`, stop and resolve it. The remaining steps assume a clean preflight.
70
+
71
+ ---
72
+
73
+ ## Step 3 — Bootstrap state with `minions init`
74
+
75
+ `minions init` scaffolds `~/.minions/` with a default config, five agent charters, default playbooks, an empty knowledge base, and the engine state files.
76
+
77
+ ```bash
78
+ minions init
79
+ ```
80
+
81
+ After init you will have (under `~/.minions/`):
82
+
83
+ - `config.json` — projects, agents, schedules
84
+ - `agents/<name>/charter.md` — the personality + boundaries for each of the five default agents (`ripley`, `dallas`, `lambert`, `rebecca`, `ralph`)
85
+ - `engine/dispatch.json`, `engine/control.json`, `engine/metrics.json` — empty queues, ready for first dispatch
86
+ - `pinned.md`, `notes.md` — empty team-memory surfaces
87
+ - `playbooks/`, `prompts/`, `routing.md` — agent prompt scaffolding
88
+
89
+ `init` is safe to re-run; existing customizations to `config.json`, charters, notes, knowledge, and routing are preserved. To force overwrites after a major version bump, use `minions init --force`.
90
+
91
+ ---
92
+
93
+ ## Step 4 — Link your first project with `minions add`
94
+
95
+ A "project" tells Minions which repo to discover work for and where to spawn worktrees. The CLI auto-detects host (GitHub/ADO), org, repo name, and main branch from the directory's git remote.
96
+
97
+ ```bash
98
+ minions add ~/code/your-repo
99
+ ```
100
+
101
+ You will be prompted to confirm or override the auto-detected fields, plus a one-line description. The description is **important** — agents read it during routing to decide whether a work item belongs to your repo. Keep it specific (e.g. "Internal billing API and webhook ingestion service") rather than generic ("Backend code").
102
+
103
+ After `minions add` returns, `~/.minions/config.json` has a new `projects[]` entry, and `~/.minions/projects/<name>/` holds the per-project `work-items.json` + `pull-requests.json` trackers.
104
+
105
+ To link several at once interactively, run `minions scan` (default: scans `~` to depth 3 for git repos and lets you multi-select).
106
+
107
+ ---
108
+
109
+ ## Step 5 — Start engine + dashboard with `minions restart`
110
+
111
+ `minions restart` starts (or restarts) both the engine daemon and the dashboard server. Use `restart` rather than `start` whenever you have edited engine code or playbooks — it ensures the daemon picks up your changes.
112
+
113
+ ```bash
114
+ minions restart
115
+ ```
116
+
117
+ You should see logs like `Engine started (pid=…)` and `Dashboard listening on http://localhost:7331`. Open the dashboard:
118
+
119
+ ```bash
120
+ minions dash # opens http://localhost:7331 in your default browser
121
+ ```
122
+
123
+ A quick tour of the panels you will use most often during onboarding:
124
+
125
+ | Panel | What it shows | When to use it |
126
+ |---|---|---|
127
+ | **Projects bar** (top) | All linked projects with descriptions | Confirm Step 4 worked |
128
+ | **Minions Members** | Five agent cards with status, current task, last result | Watch dispatches happen in real time |
129
+ | **Live Output** (per agent) | Streaming `live-output.log` | Tail an agent while it runs — refreshes every 3 s |
130
+ | **Command Center** (CC button, top-right) | Conversational chat with Claude over your full Minions state | Ask questions, queue work, draft plans |
131
+ | **Work Items** | Paginated table of all work, filterable by project/status | Inspect / retry / archive |
132
+ | **Plans & PRD** | Plan markdown drafts and approved PRDs | Approve, discuss-and-revise, or reject plans |
133
+ | **Pull Requests** | Cached PR status (build, review, merge) | Track the PRs your agents create |
134
+ | **Engine** | Dispatch queue, engine log, LLM call performance | Diagnose timing / token issues |
135
+
136
+ The engine ticks every 60 seconds. If the dashboard says "Engine: stopped", run `minions restart` again — the dashboard auto-restarts a dead engine on its next health check, but a manual restart is faster.
137
+
138
+ ---
139
+
140
+ ## Step 6 — Your first dispatch via the Command Center
141
+
142
+ The fastest way to give Minions a task is the Command Center (CC).
143
+
144
+ 1. Click the **CC** button in the top-right of the dashboard.
145
+ 2. In the slide-out chat, type a one-line description, e.g.:
146
+ ```
147
+ Add a brief comment to README.md explaining what minions doctor does
148
+ ```
149
+ 3. CC will propose an action (usually `POST /api/work-items` or `POST /api/plan`). Confirm.
150
+
151
+ Within one tick (≤60 s), the engine will:
152
+
153
+ 1. Pick an idle agent that matches the work type (per `routing.md`).
154
+ 2. Create a git worktree for that agent under `<your-repo>/.worktrees/<work-item-id>/`.
155
+ 3. Render the appropriate playbook (`playbooks/implement.md` for an implement task) with your project context, charter, pinned notes, and recent team notes.
156
+ 4. Spawn `engine/spawn-agent.js`, which invokes the Claude CLI with the rendered prompt.
157
+
158
+ Watch the **Minions Members** card for that agent flip to "working", and click into the **Live Output** tab to tail the streaming agent log.
159
+
160
+ You can do the same thing from the CLI: `minions work "Add a brief comment to README.md…"`.
161
+
162
+ ---
163
+
164
+ ## Step 7 — Your first plan via `/plan`
165
+
166
+ For multi-step work, use a plan instead of a one-shot work item. In the Command Center, type:
167
+
168
+ ```
169
+ /plan Audit our README and propose three concrete improvements with examples
170
+ ```
171
+
172
+ CC will queue a `plan` work item. The plan agent writes a markdown draft to `~/.minions/plans/<project>-<date>.md`, then chains automatically to a `plan-to-prd` agent that produces a structured PRD JSON in `~/.minions/prd/`. The PRD lands with `status: "awaiting-approval"`.
173
+
174
+ Open **Plans & PRD** in the dashboard. You will see the new plan with three buttons:
175
+
176
+ - **Approve** — materializes one work item per PRD entry, with `depends_on` honored.
177
+ - **Discuss & Revise** — opens a doc-chat modal where you can iterate on the plan with Claude.
178
+ - **Reject** — closes the plan with a reason.
179
+
180
+ After approving, agents start picking up the materialized work items on the next tick. When all PRD items complete, the engine auto-dispatches a `verify` task that builds + tests the changes and writes a manual testing guide. Archiving (after verify) is a manual dashboard action — see [docs/plan-lifecycle.md](plan-lifecycle.md) for the full pipeline.
181
+
182
+ ---
183
+
184
+ ## Step 8 — Your first PR review
185
+
186
+ When an `implement` agent finishes a work item, it pushes a branch and opens a PR. The engine polls PR status every `prPollStatusEvery` ticks (≈12 minutes by default) and dispatches a `review` agent automatically.
187
+
188
+ To watch the cycle end-to-end on your first task:
189
+
190
+ 1. Open **Pull Requests** in the dashboard. Find the PR your agent just opened.
191
+ 2. Wait for the next status poll (or run `minions dispatch` to wake the daemon immediately). The PR's `reviewStatus` will flip from `pending` to `waiting`, then a review agent will spawn.
192
+ 3. Click the agent card to watch the live review. The reviewer reads the diff, runs targeted checks, then posts a comment that starts with `VERDICT: APPROVE` or `VERDICT: REQUEST_CHANGES`.
193
+ 4. If the verdict is `REQUEST_CHANGES`, the engine queues a `fix` task for the original author with a feedback note. The cycle repeats until approved or capped by the eval-loop config.
194
+
195
+ You can also trigger reviews manually by commenting on the PR — see [docs/pr-review-fix-loop.md](pr-review-fix-loop.md).
196
+
197
+ > **Note on self-approval:** Minions agents share a single GitHub identity, so `gh pr review --approve` is blocked by GitHub's self-approval rule. Reviewers post a `VERDICT:` **comment** instead, and the engine treats that comment as authoritative.
198
+
199
+ ---
200
+
201
+ ## Debugging — Where to look when something goes wrong
202
+
203
+ When an agent gets stuck, hangs, or produces unexpected output, these files are your first stops. They live under `~/.minions/` (or wherever your runtime root is).
204
+
205
+ | File | What it tells you |
206
+ |---|---|
207
+ | `agents/<id>/live-output.log` | Real-time streaming output from the agent's Claude CLI session — same content the dashboard's Live Output tab shows. Tail this with `tail -f ~/.minions/agents/<id>/live-output.log`. |
208
+ | `agents/<id>/last-prompt.txt` | The most recent rendered prompt the agent received (playbook + system prompt + injected context). Inspect this to see exactly what the agent was asked to do, including pinned notes, team notes, charter, and dispatch context. If your install does not surface this file yet, the live equivalents are `engine/tmp/prompt-<dispatch-id>.md` (while the agent is running) and `engine/contexts/<dispatch-id>.md` (when the prompt was sidecarred because it exceeded `maxDispatchPromptBytes`). |
209
+ | `agents/<id>/output.log` | The agent's final output after completion (post-mortem read; `live-output.log` is the during-run read). |
210
+ | `agents/<id>/history.md` | Last 20 tasks for that agent with timestamps, results, projects, and branches. Useful when a single agent is misbehaving over multiple tasks. |
211
+ | `engine/log.json` | Audit trail of engine actions (last 2500 entries, rotated to 2000). Filter with `jq` for a specific agent or work item. |
212
+ | `engine/dispatch.json` | Pending / active / completed dispatch queue. If an agent appears idle on the dashboard but the queue says `active`, the engine likely lost process tracking — try `minions restart`. |
213
+ | `engine/metrics.json` | Per-agent token usage, runtime, error counts. Useful for spotting agents that are silently retrying. |
214
+ | `notes/inbox/` | Raw findings agents drop after each task. Look here for the latest learnings before the consolidator merges them into `notes.md`. |
215
+ | `pinned.md` and `notes.md` | Team memory that gets injected into every agent prompt. If an agent keeps making the same mistake, pin a correction here. |
216
+
217
+ Other quick debugging knobs:
218
+
219
+ - `minions status` — text snapshot of agents, projects, dispatch queue, and quality metrics.
220
+ - `minions queue` — focused view of the dispatch queue (pending, active, completed).
221
+ - `minions kill` — kills all active agents and resets their dispatches to `pending`. Use when an agent is wedged.
222
+ - `minions cleanup` — manually run the temp-file / worktree / zombie sweep that normally runs every 10 ticks.
223
+
224
+ For deeper dives: [docs/engine-restart.md](engine-restart.md), [docs/auto-discovery.md](auto-discovery.md), and [docs/self-improvement.md](self-improvement.md).
225
+
226
+ ---
227
+
228
+ ## What's next
229
+
230
+ You have:
231
+
232
+ - Linked a project, started the engine, opened the dashboard.
233
+ - Dispatched a one-shot task via Command Center.
234
+ - Authored a plan, approved it, and watched the PRD materialize into work items.
235
+ - Watched an agent open and review a PR.
236
+ - Located the files you need to debug a stuck agent.
237
+
238
+ From here, sensible next reads are:
239
+
240
+ - [README.md](../README.md) — the full feature catalog and CLI reference.
241
+ - [CLAUDE.md](../CLAUDE.md) — engineering conventions, tick cycle, locking rules. Read this before editing engine code.
242
+ - [docs/plan-lifecycle.md](plan-lifecycle.md) — plan → PRD → implement → verify → archive in detail.
243
+ - [docs/command-center.md](command-center.md) — full CC capabilities, including doc-chat and plan steering.
244
+ - [docs/pr-review-fix-loop.md](pr-review-fix-loop.md) — how the review/fix cycle is bounded and steered.
245
+
246
+ Welcome to the team.