peaks-loop 3.0.3 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ The `.peaks/` workspace has a **single scope axis** (session-id) plus a nested *
11
11
 
12
12
  ## Karpathy guidance (Slice 1/6 — karpathy prompt-injection-lift)
13
13
 
14
- Every sub-agent dispatch (`peaks-prd`, `peaks-rd`, `peaks-qa`, `peaks-ui`, `peaks-sc`, `peaks-txt`) MUST receive the 4 Karpathy guidelines. Append the verbatim block from `peaks-rd/references/rd-sub-agent-dispatch.md` §"Karpathy-guidelines context" to the dispatch prompt; never silently drop it. Canonical skill id: `andrej-karpathy-skills:karpathy-guidelines`. Summary: **#1 Think Before Coding** (surface assumptions, name tradeoffs), **#2 Simplicity First** (min code, no speculative features, 800-line file cap), **#3 Surgical Changes** (touch only what the request requires), **#4 Goal-Driven Execution** (verifiable ACs, plan + verify checkpoints).
14
+ Every sub-agent dispatch (`peaks-prd`, `peaks-rd`, `peaks-qa`, `peaks-ui`, `peaks-sc`, `peaks-txt`) MUST receive the 4 Karpathy guidelines. Append the verbatim block from `peaks-rd/references/rd-sub-agent-dispatch.md` §"Karpathy-guidelines context" to the dispatch prompt. Canonical skill id: `andrej-karpathy-skills:karpathy-guidelines`. Summary: **#1 Think Before Coding**, **#2 Simplicity First** (min code, no speculative features, 800-line cap), **#3 Surgical Changes**, **#4 Goal-Driven Execution** (verifiable ACs, plan + verify checkpoints).
15
15
 
16
16
  ## Hard ban (effective 2.8.3 — read every session, no exceptions)
17
17
 
@@ -31,7 +31,7 @@ This skill is the **primary surface**. The `peaks <cmd>` CLI is **auxiliary**
31
31
 
32
32
  ## Code-Change Red Line (BLOCKING — read before ANY tool call)
33
33
 
34
- **Peaks-Loop Solo is an orchestrator, NOT an implementer. You MUST NOT write, edit, or modify any application source code directly.** Every code change goes through `peaks-solo → RD → QA → verdict`. `full-auto`/`swarm` use `peaks sub-agent dispatch <role>`; `assisted`/`strict`/inline-fallback executes inline. Both follow `peaks-rd` + `peaks-qa` contracts. **If you catch yourself about to write code, STOP.** Hand off to RD. Before declaring workflow complete, run `peaks workflow verify-pipeline --rid <rid> --project <repo> --json`.
34
+ **Peaks-Loop Solo is an orchestrator, NOT an implementer. You MUST NOT write, edit, or modify any application source code directly.** Every code change goes through `peaks-solo → RD → QA → verdict`. `full-auto`/`swarm` use `peaks sub-agent dispatch <role>`; `assisted`/`strict`/inline-fallback executes inline. **If you catch yourself about to write code, STOP.** Hand off to RD. Before declaring workflow complete, run `peaks workflow verify-pipeline --rid <rid> --project <repo> --json`.
35
35
 
36
36
  ## Peaks-Loop Startup sequence (MANDATORY — execute in order)
37
37
 
@@ -41,11 +41,11 @@ This skill is the **primary surface**. The `peaks <cmd>` CLI is **auxiliary**
41
41
 
42
42
  ### Peaks-Loop Step 0.75: Resume from checkpoint (BLOCKING on same-day re-invocation)
43
43
 
44
- When a NEW conversation opens on a session whose `lastActivity` is from today AND `.peaks/_runtime/<sessionId>/checkpoints/` contains a `*.json`, surface via `peaks session info --active --json` + `peaks session resume --from <path> --project <repo>`. Prompt via `AskUserQuestion` (resume / fresh); if "resume", prepend the block. Honors "fresh" — on-disk checkpoint stays untouched. Step 0.75 is no-op on precondition fail. See `references/checkpoint-resume.md`.
44
+ When a NEW conversation opens on a session whose `lastActivity` is from today AND `.peaks/_runtime/<sessionId>/checkpoints/` has `*.json`, surface via `peaks session info --active --json` + `peaks session resume --from <path> --project <repo>`. Prompt via `AskUserQuestion` (resume / fresh); if "resume", prepend the block. Step 0.75 is no-op on precondition fail. See `references/checkpoint-resume.md`.
45
45
 
46
46
  ### Peaks-Loop Step N: Periodic checkpoint (auto-fire, no user action)
47
47
 
48
- Proactive context-overflow defense. CLI: `peaks session checkpoint [--reason <r>] [...flags]`. Fire `--reason periodic` every 20 tool calls (G1 hard-coded), `--reason artifact-written` per PRD/RD/QA/TXT write, `--reason context-fill` / `user-pause` / `user-close` as appropriate. 20-call cadence locked; see `references/periodic-checkpoint.md` (otherwise `tests/unit/solo/checkpoint-periodic-frequency.test.ts` fails).
48
+ Proactive context-overflow defense. CLI: `peaks session checkpoint [--reason <r>] [...flags]`. Fire `--reason periodic` every 20 tool calls (G1 hard-coded), `--reason artifact-written` per PRD/RD/QA/TXT write, `--reason context-fill` / `user-pause` / `user-close` as appropriate. See `references/periodic-checkpoint.md` (otherwise `tests/unit/solo/checkpoint-periodic-frequency.test.ts` fails).
49
49
 
50
50
  ### Peaks-Loop Step 0.5: OpenSpec first-run opt-in (conditional)
51
51
 
@@ -67,7 +67,7 @@ After autonomous work (RD, QA, security, perf), invoke peaks-final-review for 4-
67
67
 
68
68
  After every 4th tool call, probe via `peaks solo context-now --project <repo> --json`. Thresholds: 50% / **0.85 pre-compact / 0.95 red-line** (v2.13.0).
69
69
 
70
- **≥ 0.85**, LLM MUST fire `peaks solo auto-compact --execute --project <repo>` autonomously (zero-human-intervention). **≥ 0.95** red line: next Bash/Task tool call fires `peaks session auto-compact-hook` (PreToolUse), which in-band spawns `claude --compact` against the **current** runner.
70
+ **≥ 0.85**, LLM MUST fire `peaks solo auto-compact --execute --project <repo>` autonomously. **≥ 0.95** red line: next Bash/Task tool call fires `peaks session auto-compact-hook` (PreToolUse), which in-band spawns `claude --compact` against the current runner.
71
71
 
72
72
  **Karpathy §4 exception**: compact red line keeps runner alive → zero-intervention wins. LLM does NOT ask user to run `/compact`. Honor `--in-flight-batch` (D6.e).
73
73
 
@@ -87,19 +87,43 @@ Run `peaks workspace init` + `peaks skill presence:set peaks-solo` BEFORE any an
87
87
 
88
88
  After Step 0, run the resume-detection probe; surface via `AskUserQuestion` if a slice is in flight.
89
89
 
90
- **v2.11.0 D7 override:** if the user just `/compact`ed, run `peaks solo post-compact-detect --project <repo> --json` FIRST. If `shouldAutoResume: true`, skip the AskUserQuestion (D7.b — pre-compact approval carries forward). Log to `.peaks/_runtime/<sessionId>/txt/auto-decisions.md`. Applies to all 4 modes; cross-day / cross-machine resume NOT in scope (D7.g).
90
+ **v2.11.0 D7 override:** if the user just `/compact`ed, run `peaks solo post-compact-detect --project <repo> --json` FIRST. If `shouldAutoResume: true`, skip AskUserQuestion (D7.b). Log to `.peaks/_runtime/<sessionId>/txt/auto-decisions.md`. Cross-day / cross-machine resume NOT in scope (D7.g).
91
91
 
92
92
  → see `references/resume-detection.md` for the full detection algorithm + classification table.
93
93
 
94
94
  ### Peaks-Loop Step 0.55: 1.x → 2.0 detection (BLOCKING on first invocation per session, when the project is not on a 2.0 layout)
95
95
 
96
- Per the "one-key completion" tenet, peaks-loop 2.0 detects 1.x consumers and prompts upgrade. After Step 0.7 returns "fresh", run `peaks upgrade --detect-1x --project <root> --json`. If `isOneX: true`, surface `AskUserQuestion`. Persist to `.peaks/preferences.json` (`autoUpgradePrompt`: opt-in / skip-this-session / skip-forever).
96
+ Per the "one-key completion" tenet, peaks-loop 2.0 detects 1.x consumers and prompts upgrade. After Step 0.7 returns "fresh", run `peaks upgrade --detect-1x --project <root> --json`. If `isOneX: true`, surface `AskUserQuestion`. Persist to `.peaks/preferences.json`.
97
97
 
98
98
  → see `references/step-0-55-1x-detection.md` for the detection algorithm + AskUserQuestion options + persistence contract.
99
99
 
100
+ ### Peaks-Loop Step 0.8 — Job 启动
101
+
102
+ Trigger: user mentions N parallel targets, "全部完成"/"until all done", or disavows cost.
103
+
104
+ Action: parse slice list → choose strategy (≤2 single / ≥3 rotating) → `peaks job init --job-id <jid> --slice-list <...> --main-loop-strategy rotating --rotate-every 3` → Step 1.
105
+
106
+ ### Peaks-Loop Step 0.81 — per-slice 收尾
107
+
108
+ After commit: `peaks job checkpoint --slice-id <rid> --state done --commit-sha $(git rev-parse HEAD)` → `peaks job status` → loop (remaining>0 → Step 1; ==0 → Step 8/9/10/11; blocked → Step 0.85).
109
+
110
+ ### Peaks-Loop Step 0.85 — slice 阻塞处理
111
+
112
+ Trigger: `repair-status` atCap=true, context-now red-line ≥5min, or `subagent-cleanup` fails twice. Action: `peaks job block --slice-id <rid> --reason "<reason>"` then STOP with TXT handoff.
113
+
114
+ ### Peaks-Loop Step 0.86 — main session rotation
115
+
116
+ Active in rotating mode; fires every `rotateEvery` slices or on-demand. Sequence: cycle-summary → checkpoint rotate-marker → `peaks session rotate` → next turn resumes via `peaks session resume --job-id <jid>`.
117
+
118
+ ### Peaks-Loop Step 0.87 — sub-agent cleanup gate
119
+
120
+ After every `peaks sub-agent dispatch --batch-id <id>` inside a Job, BEFORE next slice checkpoint: `peaks job subagent-cleanup --job-id <jid> --batch-id <id> --force`. Non-zero → block.
121
+
122
+ → see `references/job-loop.md` for state machine, visibility table, rotation cadence, cleanup gate, cross-day recovery, 9 red lines.
123
+
100
124
  ### Peaks-Loop Step 1: Mode selection
101
125
 
102
- Use `AskUserQuestion` with `Full auto (Recommended)` as the first option when EITHER the user did not name a profile OR the recorded skill presence is stale (v2.15.0 slice 002 AC-2: run `peaks skill presence:check-stale --project <path> --json` first; `stale: true` ⇒ re-ask. `peaks solo should-pause --step step-1-mode-select` returns `reason: 'stale-presence'` in this case).
126
+ Use `AskUserQuestion` with `Full auto (Recommended)` first when user did not name a profile OR skill presence is stale (run `peaks skill presence:check-stale --project <path> --json` first; `stale: true` ⇒ re-ask).
103
127
 
104
128
  → see `references/mode-selection.md`, `references/fast-mode.md`, `references/mode-selection-with-stale-presence.md`.
105
129
 
@@ -153,7 +177,7 @@ When the project has no live backend (no swagger.json, no API server), Solo must
153
177
 
154
178
  ## Peaks-Loop Request type classification + Workflow order + Transition verification gates
155
179
 
156
- The contract for the 6-type classification table, the 11-step workflow order, and the 7 transition verification gates (A through G with their `ls` / `grep` shell snippets) lives in `references/workflow-gates-and-types.md`. The peaks-solo narrative in this SKILL.md references those gate numbers (Gate A through Gate G) — keep both files in lockstep when adding or renaming a gate. The reference file is the canonical contract; SKILL.md keeps the prose.
180
+ The contract for the 6-type classification table, the 11-step workflow order, and the 7 transition verification gates (A through G with their `ls` / `grep` shell snippets) lives in `references/workflow-gates-and-types.md`. The peaks-solo narrative references those gate numbers (Gate A through Gate G) — keep both files in lockstep when adding or renaming a gate.
157
181
 
158
182
  ## Peaks-Loop Default sub-agent fan-out (≥ 2 leaves/topological level → `--from-dag`)
159
183
 
@@ -212,7 +236,7 @@ After final validation, refresh project-local standards via `peaks standards ini
212
236
 
213
237
  ## Peaks-Loop Step 11: Memory sediment (BLOCKING on workflow complete)
214
238
 
215
- > **Hard rule.** Solo MUST NOT declare a workflow complete until Step 11 has produced ≥ 1 file in `.peaks/memory/` (the durable, LLM-authored memory store) OR the user has explicitly approved a no-sediment outcome via AskUserQuestion. This applies to **all modes** including `assisted` and `strict` — `assisted` previously skipped Step 10 because there was no `[CONFIRM]` gate; Step 11 fixes that.
239
+ > **Hard rule.** Solo MUST NOT declare a workflow complete until Step 11 has produced ≥ 1 file in `.peaks/memory/` (the durable, LLM-authored memory store) OR the user has explicitly approved a no-sediment outcome via AskUserQuestion. Applies to **all modes** including `assisted` and `strict` — `assisted` previously skipped Step 10 because there was no `[CONFIRM]` gate; Step 11 fixes that.
216
240
 
217
241
  ### Substeps (BLOCKING)
218
242
 
@@ -246,15 +270,15 @@ peaks memory extract --project <repo> --artifact .peaks/_runtime/<sessionId>/txt
246
270
 
247
271
  Default option = (a). Solo MUST NOT silently accept (b) without user pick.
248
272
 
249
- **Why this step exists:** audit 2026-07-03 confirmed 2 consecutive sessions produced zero `.peaks/memory/` files despite completing RD + QA + handoff artifacts. Root cause: `assisted` mode silently skipped runbook Step 10 (no STOP condition). Step 11 makes the BLOCKING semantics explicit. **Why `peaks memory extract` (not `peaks project memories:extract`):** the artifact-scoped extract is the canonical command next to its capsule; the batch-scoped sibling is for non-handoff flows (out of scope). For Step 11, **always** use `peaks memory extract --apply`.
273
+ **Why this step exists:** audit 2026-07-03 confirmed 2 consecutive sessions produced zero `.peaks/memory/` files despite completing RD + QA + handoff artifacts. `assisted` mode silently skipped runbook Step 10 (no STOP condition). Step 11 makes the BLOCKING semantics explicit. **Why `peaks memory extract` (not `peaks project memories:extract`):** artifact-scoped extract is canonical; the batch-scoped sibling is for non-handoff flows. Always use `peaks memory extract --apply`.
250
274
 
251
275
  ## Peaks-Loop External references and lifecycle
252
276
 
253
- 3rd-party integrations (codegraph, mattpocock/skills, shadcn/ui, MCPs, Context7) follow Discovery → Reference → Side effect through Peaks CLI only. Run `peaks capabilities` for capability discovery; treat external skills as reference material only. MCP servers (Playwright / Chrome DevTools / Figma) are user-installed — check the tool list for `mcp__<server>__*` entries. → `references/external-references.md` + `references/external-skill-invocation.md`.
277
+ 3rd-party integrations (codegraph, mattpocock/skills, shadcn/ui, MCPs, Context7) follow Discovery → Reference → Side effect through Peaks CLI only. Run `peaks capabilities` for capability discovery; treat external skills as reference material only. MCP servers (Playwright / Chrome DevTools / Figma) are user-installed — check the tool list for `mcp__<server>__*` entries. Do not execute upstream installer / run upstream commands / persist sensitive examples / install upstream resources directly — funnel side effects through the Peaks CLI surface. Peaks-Loop Solo gates and artifacts remain authoritative. → `references/external-references.md` + `references/external-skill-invocation.md`.
254
278
 
255
279
  ## Codegraph orchestration context
256
280
 
257
- `peaks codegraph affected` is an optional project-analysis enhancement (untrusted supporting evidence) used during role handoff. Solo must not treat codegraph output as approval for scope, design, or QA verdict. Never mutate agent settings / Claude settings / hooks from codegraph; do not commit `.codegraph/` artifacts. RD writes `.peaks/_runtime/<sessionId>/rd/codegraph-context.md`; QA / TXT consume the same envelope. → `references/codegraph-orchestration.md`.
281
+ `peaks codegraph affected` is an optional project-analysis enhancement (untrusted supporting evidence) used during role handoff. Solo must not treat codegraph output as approval for scope, design, or QA verdict. Never mutate agent settings / hooks from codegraph; do not commit `.codegraph/` artifacts. RD writes `.peaks/_runtime/<sessionId>/rd/codegraph-context.md`; QA / TXT consume the same envelope. → `references/codegraph-orchestration.md`.
258
282
 
259
283
  ## Sub-agent context governance (G7 + G7.7 + G8 + G9 — slice #010)
260
284
 
@@ -297,6 +321,7 @@ Index of every `references/` file. Read on demand.
297
321
  | `references/refactor-mode.md` | Refactor mode + red lines. |
298
322
  | `references/resume-detection.md` | Step 0.7 unfinished-work. |
299
323
  | `references/runbook.md` | End-to-end CLI sequence. |
324
+ | `references/job-loop.md` | Step 0.8 / 0.81 / 0.85 / 0.86 / 0.87 deep-dive. |
300
325
  | `references/skill-presence-and-title.md` | Step 2 + Step 2.5. |
301
326
  | `references/standards-preflight.md` | Standards preflight. |
302
327
  | `references/sub-agent-dispatch.md` | IDE-agnostic dispatch. |
@@ -0,0 +1,68 @@
1
+ # Peaks-Loop Solo — Job Loop Deep-Dive
2
+
3
+ > Read alongside `SKILL.md` Steps 0.8 / 0.81 / 0.85 / 0.86 / 0.87.
4
+
5
+ ## State machine
6
+
7
+ ```
8
+ init ─────────► pending ─► in-progress ─┐
9
+ │ │
10
+ ▼ ▼
11
+ blocked (one slice) done ──► (next slice)
12
+ │ ▲
13
+ ▼ │
14
+ (strict: STOP, │
15
+ best-effort: skipped) │
16
+ ```
17
+
18
+ ## Visibility
19
+
20
+ | Layer | Tool | Cost | User reads |
21
+ |---|---|---|---|
22
+ | LLM-runner transcript | (the chat) | free | always |
23
+ | `--watch` poll | peaks job status --watch | 1% CPU | when in a 2nd terminal pane |
24
+ | Statusline | peaks statusline install | ambient | in IDE bottom bar |
25
+
26
+ ## Rotation cadence
27
+
28
+ - `len(slices) ≤ 2` → single-mode (auto-compact passively).
29
+ - `len(slices) ≥ 3` → rotating-mode, K=3 default.
30
+ - LLM-initiated override (rotating→single) is **strongly discouraged**; if used, must record `mainLoopOverride` in state.json with `reason ≥ 10 chars` and predicted wall-time ≤ 30 min.
31
+
32
+ ## Cleanup gate
33
+
34
+ Every `peaks sub-agent dispatch` inside a Job scope MUST be matched by a `peaks job subagent-cleanup --force` BEFORE the next slice checkpoint. The wrapper (M5) refuses dispatch return-success without matching cleanup.
35
+
36
+ ## Cross-day recovery
37
+
38
+ `peaks session resume --job-id <jid>` reads:
39
+ 1. `job/<jid>/state.json` — current job state
40
+ 2. `session/cycle-<n>.md` — main-session cycle summary (rotating mode)
41
+ 3. `session/auto-decisions.md` — auto-compact history
42
+ 4. `session/checkpoints/*.json` — generic session checkpoints
43
+
44
+ The resume endpoint cross-checks all four before offering continuation; if any layer is stale, the user gets an AskUserQuestion (resume / restart / skip).
45
+
46
+ ## Visibility prose
47
+
48
+ The Job loop is foreground. Three visibility layers, all on by default:
49
+ 1. **LLM-runner transcript** — primary surface; user reads the chat to see active step.
50
+ 2. **`peaks job status --watch`** — terminal poll, ANSI bar, refresh every 3 s.
51
+ 3. **Statusline** — ambient `job: <jid> [done/total] currentSlice ETA m:s context main%. cycle`.
52
+
53
+ No detached workers, no `nohup`, no `disown`. Any attempt to spawn a background job → red line violation → block.
54
+
55
+ ## Red lines (9 hard rules)
56
+
57
+ The LLM-runner MUST NOT:
58
+ 1. Enter Step 11 / write final handoff while job has remaining slices.
59
+ 2. Re-ask the user about cost / length / context.
60
+ 3. Coalesce multiple slices into one rid.
61
+ 4. Modify a committed slice (`git commit --amend` on `done`).
62
+ 5. Fake completion (CLI verifies commit-sha exists in git log).
63
+ 6. Use detached / background / daemon-mode sub-agents inside a Job.
64
+ 7. Skip `peaks job subagent-cleanup` between dispatch and slice checkpoint.
65
+ 8. Skip or postpone a scheduled `peaks session rotate`.
66
+ 9. Suppress visibility — no silencing statusline / `--watch`.
67
+
68
+ Violations trigger a `peaks job block` event with the specific red-line number.
@@ -187,3 +187,18 @@ peaks skill doctor --json
187
187
  ```
188
188
 
189
189
  Repair loop details: see `## Mandatory RD QA repair loop` in SKILL.md for the full 5-step procedure and the 3-cycle cap. Append transition notes via `--reason` rather than rewriting artifacts during repair cycles.
190
+
191
+ ```bash
192
+
193
+ # Peaks-Loop Default runbook — Job path (excerpt; full flow in references/job-loop.md)
194
+
195
+ # After Step 7 (RD+QA commit) lands AND the user request was Job-shaped (Step 0.8 triggered):
196
+ peaks job checkpoint --slice-id <rid> --state done --commit-sha $(git rev-parse HEAD)
197
+ peaks job status --job-id <jid> --json
198
+ peaks job subagent-cleanup --job-id <jid> --batch-id <bid> --force # Step 0.87 gate
199
+ # Loop control:
200
+ # remaining > 0 → return to Step 1 (next slice)
201
+ # remaining == 0 → Step 8/9/10/11 (original tail)
202
+ # blocked (strict) → peaks job block + STOP
203
+ # Rotating-mode: every rotateEvery slices → Step 0.86 (peaks session rotate + resume)
204
+ ```