peaks-loop 3.0.2 → 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.
Files changed (37) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README-en.md +1 -1
  3. package/README.md +1 -1
  4. package/dist/src/cli/commands/core/session-command.js +6 -0
  5. package/dist/src/cli/commands/job-commands.d.ts +3 -0
  6. package/dist/src/cli/commands/job-commands.js +236 -0
  7. package/dist/src/cli/commands/session-auto-compact-hook-command.d.ts +37 -0
  8. package/dist/src/cli/commands/session-auto-compact-hook-command.js +127 -0
  9. package/dist/src/cli/program.js +6 -0
  10. package/dist/src/services/context/auto-compact-dispatcher.js +60 -10
  11. package/dist/src/services/context/main-session-monitor.d.ts +12 -0
  12. package/dist/src/services/context/main-session-monitor.js +12 -0
  13. package/dist/src/services/hooks/auto-compact-hook-install.d.ts +104 -0
  14. package/dist/src/services/hooks/auto-compact-hook-install.js +157 -0
  15. package/dist/src/services/ide/adapters/claude-code-adapter.js +21 -9
  16. package/dist/src/services/job/job-event-emitter.d.ts +30 -0
  17. package/dist/src/services/job/job-event-emitter.js +5 -0
  18. package/dist/src/services/job/job-orchestrator.d.ts +50 -0
  19. package/dist/src/services/job/job-orchestrator.js +104 -0
  20. package/dist/src/services/job/job-resource-snapshot.d.ts +7 -0
  21. package/dist/src/services/job/job-resource-snapshot.js +47 -0
  22. package/dist/src/services/job/job-rotation.d.ts +17 -0
  23. package/dist/src/services/job/job-rotation.js +30 -0
  24. package/dist/src/services/job/job-state-store.d.ts +24 -0
  25. package/dist/src/services/job/job-state-store.js +60 -0
  26. package/dist/src/services/job/job-types.d.ts +444 -0
  27. package/dist/src/services/job/job-types.js +87 -0
  28. package/dist/src/services/job/subagent-job-wrapper.d.ts +35 -0
  29. package/dist/src/services/job/subagent-job-wrapper.js +30 -0
  30. package/dist/src/shared/version.d.ts +1 -1
  31. package/dist/src/shared/version.js +1 -1
  32. package/package.json +1 -1
  33. package/skills/peaks-solo/SKILL.md +91 -77
  34. package/skills/peaks-solo/references/completion-handoff.md +9 -4
  35. package/skills/peaks-solo/references/job-loop.md +68 -0
  36. package/skills/peaks-solo/references/periodic-checkpoint.md +11 -1
  37. package/skills/peaks-solo/references/runbook.md +18 -2
@@ -5,21 +5,17 @@ description: Full-auto orchestration facade for the Peaks-Loop skill family. Use
5
5
 
6
6
  ## Single-scope-axis naming convention (2.7.1)
7
7
 
8
- > **Read once at the top of this file.**
9
-
10
8
  The `.peaks/` workspace has a **single scope axis** (session-id) plus a nested **sub-agent axis** under `.peaks/_sub_agents/<sessionId>/...`. Use `<sessionId>` (NEVER bare `<sid>`). The change-id axis is gone as of slice `2026-06-29-change-id-root-removal` — reviewable artifacts now live at `.peaks/_runtime/<sessionId>/<role>/...` (gitignored) with the change-id optionally embedded as a filename slug. CLI surface: session-id → `peaks session *`; sub-agent → `peaks sub-agent *`. OpenSpec's independent `openspec/changes/<change-id>/` vocabulary (L4) is preserved untouched.
11
9
 
12
10
  **2.7.1:** `recordBypass` / `isBypassLimitReached` had a legacy write path that bypassed `.peaks/_runtime/` (slice 2.7.1 fix in `request-commands.ts:410`). Now writes canonical `.peaks/_runtime/<sid>/`. `getChangeArtifactRoot` removed. Test `skills-skill-md-naming.test.ts` enforces (a) zero bare `<sid>`, (b) axis labels, (c) this callout.
13
11
 
14
- ## Hard ban (effective 2.8.3 — read every session, no exceptions)
15
-
16
- Never create `.peaks/_runtime/<YYYY-MM-DD-*>/` at the top level of `.peaks/`. The post-v2.19.0 single-scope-axis convention requires ALL reviewable artifact dirs to live under `.peaks/_runtime/<sessionId>/<role>/...` (gitignored) — never as siblings of `.peaks/_runtime/`. The `peaks workspace init` flow creates only `.peaks/_runtime/<sessionId>/session.json`; reviewable artifact files are placed under that same dir by the writer. The change-id is preserved as an optional filename slug inside `.peaks/_runtime/<sessionId>/<role>/requests/<rid>-<change-id>.md` but does NOT route filesystem writes. If you find yourself about to write a date-prefixed directory directly under `.peaks/`, STOP and reroute under `.peaks/_runtime/<sessionId>/`. The `.gitignore` rule `.peaks/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-*/` will block the write at commit time; the vitest guard at `tests/unit/workspace/top-level-change-id-guard.test.ts` (8 cases, including CLI help-text) will fail the suite if a regression sneaks through.
17
-
18
12
  ## Karpathy guidance (Slice 1/6 — karpathy prompt-injection-lift)
19
13
 
20
- > **Read once per Solo invocation; the 4 Karpathy guidelines are mandatory context for every sub-agent Solo dispatches.**
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
+
16
+ ## Hard ban (effective 2.8.3 — read every session, no exceptions)
21
17
 
22
- 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).
18
+ Never create `.peaks/_runtime/<YYYY-MM-DD-*>/` at the top level of `.peaks/`. The post-v2.19.0 single-scope-axis convention requires ALL reviewable artifact dirs to live under `.peaks/_runtime/<sessionId>/<role>/...` (gitignored) — never as siblings of `.peaks/_runtime/`. The `peaks workspace init` flow creates only `.peaks/_runtime/<sessionId>/session.json`; reviewable artifact files are placed under that same dir by the writer. The change-id is preserved as an optional filename slug inside `.peaks/_runtime/<sessionId>/<role>/requests/<rid>-<change-id>.md` but does NOT route filesystem writes. If you find yourself about to write a date-prefixed directory directly under `.peaks/`, STOP and reroute under `.peaks/_runtime/<sessionId>/`. The `.gitignore` rule `.peaks/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-*/` will block the write at commit time; the vitest guard at `tests/unit/workspace/top-level-change-id-guard.test.ts` (8 cases, including CLI help-text) will fail the suite if a regression sneaks through.
23
19
 
24
20
  # Peaks-Loop Solo
25
21
 
@@ -31,56 +27,25 @@ Peaks-Loop Solo is the orchestration facade for the Peaks-Loop short skill famil
31
27
 
32
28
  ## Skill-first architecture note (read once, internalise)
33
29
 
34
- This skill is the **primary surface**. The `peaks <cmd>` CLI is **auxiliary** — invoked by the skill prompt only when a primitive is the right tool (atomic side effect, machine-enforced gate, structured JSON for a downstream decision, or backstop the LLM cannot skip). Behaviour only an LLM in a skill prompt would use lives **here in the SKILL.md**, not as a new CLI command.
30
+ This skill is the **primary surface**. The `peaks <cmd>` CLI is **auxiliary** — invoked by the skill prompt only when a primitive is the right tool. Behaviour only an LLM in a skill prompt would use lives **here in the SKILL.md**.
35
31
 
36
32
  ## Code-Change Red Line (BLOCKING — read before ANY tool call)
37
33
 
38
- **Peaks-Loop Solo is an orchestrator, NOT an implementer. You MUST NOT write, edit, or modify any application source code directly.**
39
-
40
- Every code change — bugfix, feature, refactor, or config — MUST go through the full pipeline:
41
-
42
- ```
43
- peaks-solo (orchestrate only)
44
- → RD work ← ALL code changes happen HERE
45
- → Unit tests written + pass (Peaks-Loop Gate B2)
46
- → Karpathy standards enforced (file-size ≤800 lines, TypeScript rules)
47
- → Code review evidence (Peaks-Loop Gate B3)
48
- → Security review evidence (Peaks-Loop Gate B4)
49
- → QA work ← ALL validation happens HERE
50
- → Functional test execution (Peaks-Loop Gate A2)
51
- → Performance check (Peaks-Loop Gate A4)
52
- → Security test (Peaks-Loop Gate A3)
53
- → Browser E2E (when frontend; Peaks-Loop Gate D)
54
- → Verdict: pass | return-to-rd | blocked
55
- ```
56
-
57
- **Mechanism for "RD work" / "QA work" depends on the orchestration mode:** `full-auto`/`swarm` use `peaks sub-agent dispatch <role>` (IDE-agnostic dispatch primitive); `assisted`/`strict`/inline-fallback executes inline. In all modes, the work itself follows the same `peaks-rd` and `peaks-qa` contracts. **Never bypass the role contracts regardless of which path runs.**
58
-
59
- **Violations (BLOCKING — Solo must refuse to proceed):**
60
-
61
- 1. Writing implementation code directly instead of routing through the RD contract
62
- 2. Declaring work "done" without producing QA evidence after RD
63
- 3. Skipping unit tests ("it's a small change")
64
- 4. Skipping code review or security review
65
- 5. Skipping QA functional/performance/security validation
66
-
67
- **If you catch yourself about to write code in this skill, STOP. Hand off to the RD contract path immediately** (sub-agent Task in full-auto, inline execution in assisted/strict).
68
-
69
- **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`.
70
35
 
71
36
  ## Peaks-Loop Startup sequence (MANDATORY — execute in order)
72
37
 
73
38
  ### Peaks-Loop Slice 011 — workspace consolidate + session checkpoint/resume
74
39
 
75
- `peaks workspace consolidate` is the slice-011 umbrella primitive. `peaks session checkpoint` (proactive context-overflow defense) and `peaks session resume` (cross-session continuity) are surfaced in SKILL.md as Step 0.75 and Step N headings (slice 2.5.0, sub-fix A). See `references/cross-date-session-check.md` for the umbrella. IDE-agnostic.
40
+ `peaks workspace consolidate` is the slice-011 umbrella primitive. `peaks session checkpoint` (context-overflow defense) and `peaks session resume` surface as Step 0.75 + Step N. See `references/cross-date-session-check.md`.
76
41
 
77
42
  ### Peaks-Loop Step 0.75: Resume from checkpoint (BLOCKING on same-day re-invocation)
78
43
 
79
- When a NEW conversation opens on a session whose `lastActivity` is from today AND `.peaks/_runtime/<sessionId>/checkpoints/` contains at least one `*.json`, surface the most recent checkpoint. Run `peaks session info --active --json` to resolve the canonical session id, then `peaks session resume --from <path> --project <repo>` to emit a markdown "resume context" block. Prompt the user via IDE-native `AskUserQuestion` (resume / start fresh), and if "resume", prepend the emitted block to its own prompt. Honors the user choice on "fresh" — the on-disk checkpoint stays untouched. Step 0.75 is a no-op if any precondition fails (no sid, wrong day, no checkpoint). Full probe + decision tree: `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`.
80
45
 
81
46
  ### Peaks-Loop Step N: Periodic checkpoint (auto-fire, no user action)
82
47
 
83
- Proactive defense vs context overflow. CLI: `peaks session checkpoint [--reason <r>] [--session-id <sessionId>] [--project <p>] [--current-plan <text>] [--open-questions <list>] [--recent-decisions <list>] [--recent-artifact-paths <list>] [--git-status <text>] [--skills-active <list>] [--todo-state <list>] [--json]`. Fire `--reason periodic` every 20 tool calls (G1 hard-coded), `--reason artifact-written` per PRD/RD/QA/TXT write, `--reason context-fill` when full, `--reason user-pause` on save, `--reason user-close` before handoff. 20-call cadence locked here + `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).
84
49
 
85
50
  ### Peaks-Loop Step 0.5: OpenSpec first-run opt-in (conditional)
86
51
 
@@ -90,21 +55,21 @@ Run when `openspec/` is absent and `.peaks/.peaks-openspec-opt-in.json` is missi
90
55
 
91
56
  ### Peaks-Loop Step 0.6: Audit + Goal (NEW)
92
57
 
93
- After human expresses need, invoke peaks-audit to summarize + multi-dim audit + propose goal. Display audit + goal to human for one-shot approval. Store approved goal at `.peaks/_runtime/<sessionId>/audit-goal/<rid>.json`. **All subsequent autonomous work requires an approved goal.**
94
-
95
- > **v2.15.0+ 校准:** 业务 goal 与技术 goal 必须分离,user 不被推到技术决策位。详见 `.peaks/memory/peaks-loop-user-role-and-tech-decision.md`。
58
+ Invoke peaks-audit after need expressed; store approved goal at `.peaks/_runtime/<sessionId>/audit-goal/<rid>.json`. **All autonomous work requires approved goal.** (v2.15.0+ business vs tech goal separated; see `.peaks/memory/peaks-loop-user-role-and-tech-decision.md`.)
96
59
 
97
- → see `references/audit-goal-gate.md` for the full Step 0.6 contract.
60
+ → see `references/audit-goal-gate.md`.
98
61
 
99
62
  ### Peaks-Loop Step N+1: Final Review (NEW)
100
63
 
101
- After all autonomous LLM work (RD, QA, security, perf) completes, invoke peaks-final-review to prepare 4-dim evidence. Display evidence to human for judgment. If all 4 dims pass → final delivery. If any fail → loop back with feedback.
64
+ After autonomous work (RD, QA, security, perf), invoke peaks-final-review for 4-dim evidence. All 4 pass → final delivery; else loop back. See `references/final-review-gate.md`.
102
65
 
103
- → see `references/final-review-gate.md` for the full Step N+1 contract.
66
+ ### Peaks-Loop Step N+2: Main-session context monitor (D6 + slice 2026-07-02)
104
67
 
105
- ### Peaks-Loop Step N+2: Main-session context monitor (v2.11.0 D6)
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).
106
69
 
107
- After every 4th tool call (complement to Step N), probe via `peaks context check --prompt-size <bytes> --auto-trigger --json`. Thresholds: 50% soft warn / 75% user red line (return trigger path, do NOT auto-execute — Karpathy §4) / 90% emergency. Use `--in-flight-batch` to defer until batch converges (D6.e). Companion to Step N (soft signal); D6 is the hard signal.
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
+
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).
108
73
 
109
74
  ### Peaks-Loop Step 0: Anchor the workflow (MANDATORY FIRST ACTIONS — no bail-out)
110
75
 
@@ -122,19 +87,43 @@ Run `peaks workspace init` + `peaks skill presence:set peaks-solo` BEFORE any an
122
87
 
123
88
  After Step 0, run the resume-detection probe; surface via `AskUserQuestion` if a slice is in flight.
124
89
 
125
- **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).
126
91
 
127
92
  → see `references/resume-detection.md` for the full detection algorithm + classification table.
128
93
 
129
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)
130
95
 
131
- 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`.
132
97
 
133
98
  → see `references/step-0-55-1x-detection.md` for the detection algorithm + AskUserQuestion options + persistence contract.
134
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
+
135
124
  ### Peaks-Loop Step 1: Mode selection
136
125
 
137
- 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).
138
127
 
139
128
  → see `references/mode-selection.md`, `references/fast-mode.md`, `references/mode-selection-with-stale-presence.md`.
140
129
 
@@ -170,19 +159,15 @@ Peaks-Loop Solo must NOT silently install hooks, create agents, enable MCP serve
170
159
 
171
160
  ## Peaks-Loop GStack integration
172
161
 
173
- Map gstack stages to Peaks-Loop role artifacts; preserve confirmation gates. Do not delegate orchestration to gstack commands. RD and QA use Playwright MCP for browser E2E.
174
-
175
- → see `references/gstack-integration.md` and `references/browser-workflow.md`.
162
+ Map gstack stages to Peaks-Loop role artifacts; preserve confirmation gates. → `references/gstack-integration.md` + `references/browser-workflow.md`.
176
163
 
177
164
  ## Peaks-Loop Local intermediate artifact workspace (MANDATORY)
178
165
 
179
- The workspace is created in Step 0 as a mandatory first action. All intermediate artifacts land under `.peaks/_runtime/<sessionId>/`. NEVER write Peaks-Loop intermediate artifacts to the project root directory.
166
+ Step 0 creates the workspace; all intermediate artifacts land under `.peaks/_runtime/<sessionId>/`. NEVER write Peaks-Loop intermediate artifacts to the project root directory.
180
167
 
181
168
  ## Peaks-Loop Pre-RD project scan checklist (MANDATORY)
182
169
 
183
- Before handing off to `peaks-rd`, scan the project and record findings to `.peaks/_runtime/<sessionId>/rd/project-scan.md`. The project-scan checklist (archetype detection, build-tool / component-library / CSS-framework / state-routing-data tables, legacy signals, artifact template) lives in the references file.
184
-
185
- → see `references/project-scan-checklist.md` for the checklist.
170
+ Before handing off to `peaks-rd`, scan the project and record findings to `.peaks/_runtime/<sessionId>/rd/project-scan.md`. → `references/project-scan-checklist.md`.
186
171
 
187
172
  ## Peaks-Loop Frontend-only development mode
188
173
 
@@ -192,7 +177,7 @@ When the project has no live backend (no swagger.json, no API server), Solo must
192
177
 
193
178
  ## Peaks-Loop Request type classification + Workflow order + Transition verification gates
194
179
 
195
- 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.
196
181
 
197
182
  ## Peaks-Loop Default sub-agent fan-out (≥ 2 leaves/topological level → `--from-dag`)
198
183
 
@@ -249,31 +234,59 @@ Five CLI commands harden the workflow against silent skips: `peaks request lint`
249
234
 
250
235
  After final validation, refresh project-local standards via `peaks standards init/update` (never hand-write). Use Peaks-Loop TXT for the compact handoff capsule: mode, validated decisions, artifact paths, standards deltas, open questions, next action. **Presence management is delegated to the last downstream skill** — peaks-solo does not call `peaks skill presence:clear` itself.
251
236
 
252
- ## Peaks-Loop External references and lifecycle
237
+ ## Peaks-Loop Step 11: Memory sediment (BLOCKING on workflow complete)
253
238
 
254
- 3rd-party integrations (codegraph, mattpocock/skills, shadcn/ui, MCPs, Context7) follow Discovery → Reference → Side effect through Peaks CLI only. Before naming external skills, run `peaks capabilities` for capability discovery; treat all external skills as reference material only. Peaks-Loop artifacts and ACs remain authoritative; do not execute upstream installers; MCP servers (Playwright / Chrome DevTools / Figma) are user-installed — check the tool list for `mcp__<server>__*` entries.
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.
255
240
 
256
- → see `references/external-references.md` and `references/external-skill-invocation.md`.
241
+ ### Substeps (BLOCKING)
257
242
 
258
- ## Codegraph orchestration context
243
+ **11a — Gate A (txt/ inventory):**
259
244
 
260
- `peaks codegraph affected` is an optional project-analysis enhancement; treat output as untrusted supporting evidence. Solo must not treat codegraph output as approval for scope, design, or QA verdict. Never mutate agent settings, Claude settings, or hooks from codegraph; do not commit `.codegraph/` artifacts. RD writes `.peaks/_runtime/<sessionId>/rd/codegraph-context.md`; QA / TXT consume the same envelope in the role handoff.
245
+ ```bash
246
+ find .peaks/_runtime/<sessionId>/txt/ -type f -name '*.md' | head
247
+ ```
261
248
 
262
- → see `references/codegraph-orchestration.md`.
249
+ If **0 files** → STOP. Dispatch `peaks-txt` first to write `handoff.md`, then return to 11c.
263
250
 
264
- ## Sub-agent context governance (G7 + G7.7 + G8 + G9 — slice #010)
251
+ **11b — Gate B (memory block embed scan, skill-side only):**
265
252
 
266
- Layer 3.5 context-governance push for sub-agent dispatch. Main LLM reducer sees metadata-only view (~200 chars/sub-agent); on-demand `Read` for full content. Threshold table: 50% soft warn, 75% `CONTEXT_NEAR_LIMIT`, 80% hard reject (CLI + hook double-guard). See `references/context-governance.md` for the full protocol.
253
+ ```bash
254
+ grep -c 'peaks-memory:start' .peaks/_runtime/<sessionId>/txt/handoff.md || true
255
+ ```
267
256
 
268
- ## Sub-agent cross-batch signal — G8.4 share / shared-read / await (slice 2026-06-23-audit-3rd)
257
+ If **0 AND this session surfaced a stable project fact** (decision / convention / approved refactor / hard rule), STOP and tell peaks-txt to embed at least one `<!-- peaks-memory:start -->` block first.
258
+
259
+ **11c — Canonical extract (the only CLI that writes `.peaks/memory/`):**
260
+
261
+ ```bash
262
+ peaks memory extract --project <repo> --artifact .peaks/_runtime/<sessionId>/txt/handoff.md --apply --json
263
+ ```
269
264
 
270
- Three CLI primitives let sibling sub-agents coordinate within a batch without peer-to-peer messaging. LLM-invoked from peaks-rd / peaks-qa / peaks-ui / peaks-txt skills.
265
+ `--apply` is REQUIRED. Without it the command only previews — no files land in `.peaks/memory/`.
271
266
 
272
- - **`peaks sub-agent share --batch <id> --key <role>.<event> --value <json> [--from <role>]`** — write to per-batch channel (≤ 1KB warn, ≥ 64KB reject). Last-write-wins.
273
- - **`peaks sub-agent shared-read --batch <id> [--since <iso>] [--key <glob>]`** — read sibling entries (glob `*`).
274
- - **`peaks sub-agent await --batch <id> [--timeout <ms>]`** — block until batch finishes (claude-code 1.2 MVP; other IDEs LLM-side await).
267
+ **11d — Gate C (zero-write outcome):** If `extractedCount === 0` after 11c, fire AskUserQuestion:
268
+
269
+ > "本次 solo 未沉淀任何 `.peaks/memory` 文件。可选: (a) 回去在 handoff.md 嵌入至少 1 个 `peaks-memory:start` block 后重试; (b) 显式接受 no-sediment 并记录为 lesson; (c) 取消完成。"
270
+
271
+ Default option = (a). Solo MUST NOT silently accept (b) without user pick.
272
+
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`.
274
+
275
+ ## Peaks-Loop External references and lifecycle
276
+
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`.
278
+
279
+ ## Codegraph orchestration context
280
+
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`.
282
+
283
+ ## Sub-agent context governance (G7 + G7.7 + G8 + G9 — slice #010)
284
+
285
+ Main LLM reducer sees metadata-only view (~200 chars/sub-agent); on-demand `Read` for full content. Threshold table: 50% soft warn, 75% `CONTEXT_NEAR_LIMIT`, 80% hard reject (CLI + hook double-guard). → `references/context-governance.md`.
286
+
287
+ ## Sub-agent cross-batch signal — G8.4 share / shared-read / await (slice 2026-06-23-audit-3rd)
275
288
 
276
- Channel file gitignored under `.peaks/_sub_agents/<sessionId>/shared/`.
289
+ Three CLI primitives let sibling sub-agents coordinate within a batch without peer-to-peer messaging: `peaks sub-agent share / shared-read / await` (last-write-wins channel ≤ 1KB warn / ≥ 64KB reject). Channel file gitignored under `.peaks/_sub_agents/<sessionId>/shared/`.
277
290
 
278
291
  ## References
279
292
 
@@ -308,6 +321,7 @@ Index of every `references/` file. Read on demand.
308
321
  | `references/refactor-mode.md` | Refactor mode + red lines. |
309
322
  | `references/resume-detection.md` | Step 0.7 unfinished-work. |
310
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. |
311
325
  | `references/skill-presence-and-title.md` | Step 2 + Step 2.5. |
312
326
  | `references/standards-preflight.md` | Standards preflight. |
313
327
  | `references/sub-agent-dispatch.md` | IDE-agnostic dispatch. |
@@ -12,7 +12,12 @@ peaks-solo does NOT itself call `peaks skill presence:clear --project <repo>` at
12
12
 
13
13
  The user can continue with follow-up requirements naturally — no need to re-invoke `/peaks-solo` to do so. The header continues to display whatever skill is active; the user can `/peaks-solo` again to re-anchor.
14
14
 
15
- Before ending, extract durable memories from this session:
16
- ```bash
17
- peaks project memories:extract --session-id <session-id> --project <repo> --json
18
- ```
15
+ Before ending, extract durable memories from this session.
16
+
17
+ > **Owned by runbook Step 10 (TXT handoff) + Step 11 (Memory sediment in SKILL.md).** Do not duplicate the CLI invocation here — the canonical command is:
18
+ >
19
+ > ```bash
20
+ > peaks memory extract --project <repo> --artifact .peaks/_runtime/<sessionId>/txt/handoff.md --apply --json
21
+ > ```
22
+ >
23
+ > `peaks project memories:extract` is a different (batch-scoped, no-artifact) CLI used in non-handoff flows. Step 11 in SKILL.md enforces the artifact-scoped path; follow that.
@@ -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.
@@ -68,4 +68,14 @@ checkpoint as often as it wants.
68
68
 
69
69
  ## Checkpoint IDE note
70
70
 
71
- This step is strictly IDE-agnostic. The LLM calls the peaks CLI; no IDE-specific tools or paths are involved.
71
+ This step is strictly IDE-agnostic. The LLM calls the peaks CLI; no IDE-specific tools or paths are involved.
72
+
73
+ ## Companion surface — auto-compact (zero-pause)
74
+
75
+ When the runner crosses the v2.13.0 auto-compact thresholds (0.85 pre-compact / 0.95 red-line), `peaks session checkpoint` is NOT enough on its own — the LLM must also fire `peaks solo auto-compact --execute` (or wait for the in-band PreToolUse hook at ratio ≥ 0.95 to compact the runner itself). See:
76
+
77
+ - `peaks solo auto-compact --execute` — orchestrator that writes the convergence plan + dispatches the compact pathway
78
+ - `peaks session auto-compact-hook` — the PreToolUse hook entrypoint fired by `.claude/settings.local.json` (slice 2026-07-02-auto-compact-zero-pause)
79
+ - `.peaks/memory/2026-06-27-auto-compact-design.md` — zero-human-intervention design rationale
80
+
81
+ The two surfaces compose: `peaks session checkpoint` persists the context state, `peaks solo auto-compact` collapses the runner's window. The LLM fires both in the 0.85–0.95 zone; the hook fires alone at ≥ 0.95.
@@ -154,10 +154,11 @@ peaks openspec validate <cid> --project <repo> --json
154
154
  peaks openspec archive <cid> --project <repo> --apply --json
155
155
  peaks workspace reconcile --project <repo> --apply --older-than 7
156
156
 
157
- # 10. Peaks-Loop TXT handoff — invoke peaks-txt which embeds memory markers and extracts
157
+ # 10. Peaks-Loop TXT handoff — invoke peaks-txt which embeds memory markers (BLOCKING)
158
158
  # peaks-txt writes the handoff capsule to .peaks/_runtime/<id>/txt/handoff.md. Inside the
159
159
  # capsule body, peaks-txt embeds <!-- peaks-memory:start --> blocks for every
160
- # stable project fact surfaced this session.
160
+ # stable project fact surfaced this session. Applies to ALL modes including
161
+ # `assisted` (audit 2026-07-03 found `assisted` previously skipped this step).
161
162
  #
162
163
  # 10a. Skill-side scan (do this BEFORE the AskUserQuestion below):
163
164
  # grep -n "peaks-memory:start" .peaks/_runtime/<id>/txt/handoff.md
@@ -186,3 +187,18 @@ peaks skill doctor --json
186
187
  ```
187
188
 
188
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
+ ```