peaks-loop 4.0.10 → 4.0.12

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 (35) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/config/eslint/.peaks-rules.cjs +123 -0
  3. package/dist/cli/commands/code-commands.js +2 -0
  4. package/dist/cli/commands/code-orchestrator-can-do.d.ts +17 -0
  5. package/dist/cli/commands/code-orchestrator-can-do.js +75 -0
  6. package/dist/cli/commands/workspace/reconcile-command.js +5 -2
  7. package/dist/reporters/bdd-reporter.d.ts +36 -0
  8. package/dist/reporters/bdd-reporter.js +159 -0
  9. package/dist/services/audit/enforcers/active-skill-resolver.js +4 -1
  10. package/dist/services/code/orchestrator-can-do.d.ts +114 -0
  11. package/dist/services/code/orchestrator-can-do.js +205 -0
  12. package/dist/services/doctor/doctor-service/checks/skill-presence.js +1 -1
  13. package/dist/services/doctor/doctor-service/checks/workspace-layout.d.ts +5 -2
  14. package/dist/services/doctor/doctor-service/checks/workspace-layout.js +70 -9
  15. package/dist/services/doctor/doctor-service/types.d.ts +9 -0
  16. package/dist/services/hooks/presence-marker-detector.d.ts +7 -5
  17. package/dist/services/hooks/presence-marker-detector.js +45 -85
  18. package/dist/services/migration/v2-10-to-v2-11-service.js +1 -3
  19. package/dist/services/qa/bdd-test-style-verifier.d.ts +88 -0
  20. package/dist/services/qa/bdd-test-style-verifier.js +268 -0
  21. package/dist/services/sc/sc-service.d.ts +11 -7
  22. package/dist/services/sc/sc-service.js +29 -26
  23. package/dist/services/session/binding-store.d.ts +6 -6
  24. package/dist/services/skills/hooks-settings-service.d.ts +1 -1
  25. package/dist/services/skills/hooks-settings-service.js +1 -1
  26. package/dist/services/skills/presence-lease-service.js +1 -0
  27. package/dist/services/skills/skill-presence-service.d.ts +0 -1
  28. package/dist/services/skills/skill-presence-service.js +112 -102
  29. package/dist/services/skills/skill-statusline-service.js +73 -39
  30. package/docs/test-style-contract.md +135 -0
  31. package/package.json +6 -4
  32. package/skills/bee/peaks-qa/references/qa-sub-agent-dispatch.md +17 -1
  33. package/skills/bee/peaks-rd/references/rd-sub-agent-dispatch.md +21 -1
  34. package/skills/peaks-code/SKILL.md +6 -0
  35. package/skills/peaks-code/references/session-overload-signal-index.md +60 -0
@@ -65,4 +65,20 @@ The dispatch CLI (`peaks sub-agent dispatch`) automatically prepends a Test Tool
65
65
 
66
66
  If the framework is not obvious from `package.json#scripts.test`, the sub-agent should run `peaks test --json` to introspect the resolved framework + argv before picking a runner.
67
67
 
68
- See the block constant at `src/services/dispatch/test-tool-detection.ts` for the verbatim text.
68
+ See the block constant at `src/services/dispatch/test-tool-detection.ts` for the verbatim text.
69
+
70
+ ## BDD Test Style Verification (effective rid-2026-08-05-bdd-test-style, v4.0.11+)
71
+
72
+ When you (peaks-qa) verify a slice, you MUST run the BDD test-style verifier on every new or modified `tests/unit/**/*.test.ts` file in the slice's git diff. Use:
73
+
74
+ ```bash
75
+ node -e "
76
+ const { verifyBddStyle } = await import('./src/services/qa/bdd-test-style-verifier.ts');
77
+ const { execSync } = require('node:child_process');
78
+ const files = execSync('git diff --name-only HEAD~1 -- tests/unit', { encoding: 'utf8' })
79
+ .split('\n').filter(f => f.endsWith('.test.ts'));
80
+ console.log(JSON.stringify(verifyBddStyle({ projectRoot: '.', testFiles: files })));
81
+ "
82
+ ```
83
+
84
+ If the verifier returns `ok: false`, your verdict MUST be `failed: bdd-style-violation` with the structured reason from the verifier (do NOT mark the slice as passing).
@@ -147,4 +147,24 @@ Touch only what you must. Clean up only your own mess. When editing existing cod
147
147
  Define success criteria. Loop until verified. "Add validation" → write tests for invalid inputs, then make them pass. "Fix the bug" → write a test that reproduces it, then make it pass. For multi-step tasks, state a brief plan with verify checkpoints. Strong success criteria let you loop independently. Weak criteria require constant clarification.
148
148
  ```
149
149
 
150
- Sub-agents MUST NOT silently drop this block. The regression test `tests/unit/skills/karpathy-prompt-injection.test.ts` asserts this block is present. The canonical skill id for the full guidelines text is `andrej-karpathy-skills:karpathy-guidelines`.
150
+ Sub-agents MUST NOT silently drop this block. The regression test `tests/unit/skills/karpathy-prompt-injection.test.ts` asserts this block is present. The canonical skill id for the full guidelines text is `andrej-karpathy-skills:karpathy-guidelines`.
151
+
152
+ ## BDD Test Style Contract (effective rid-2026-08-05-bdd-test-style, v4.0.11+)
153
+
154
+ When you (the LLM sub-agent) write new or modified unit tests in `tests/unit/**`, every `it()` / `test()` block MUST follow the given-when-then contract:
155
+
156
+ 1. The first string-literal argument of `it()` / `test()` MUST describe business behavior in the form `when X, should Y` — must include either the word "when" (state / pre-condition) or "should" (observable outcome).
157
+ 2. The body callback (the second argument) MUST start with exactly 3 leading comments:
158
+ ```typescript
159
+ // given: <precondition — system / user state>
160
+ // when: <action — what is invoked>
161
+ // then: <expected outcome — what is asserted>
162
+ ```
163
+ 3. Legacy `// arrange:` / `// act:` / `// assert:` AAA markers MUST NOT appear in tests you write.
164
+
165
+ Run `node scripts/migrate-to-bdd.mjs --dry-run <file>` before writing new tests to inspect the contract, or use the Slice B verifier's rule directly:
166
+
167
+ - description: must contain `/(\bwhen\b|\bshould\b)/`
168
+ - first 3 body comments: must match `/^\s*\/\/\s*given\s*:/`, `/^\s*\/\/\s*when\s*:/`, `/^\s*\/\/\s*then\s*:/`
169
+
170
+ If your tests fail peaks-qa's `bdd-test-style-verifier` (see Slice B), the slice will be returned-to-rd. Fix the violations, do NOT bypass the check.
@@ -102,6 +102,10 @@ Full content extracted to **`references/startup-sequence.md`** (Steps 0 / 0.5-0.
102
102
 
103
103
  **Step 0.7 resume rule (read-FIRST):** on resume, `peaks code gate-step-08` reads `progress.json` first and surfaces `Next: slice #N of M (<currentSlice>)` so the orchestrator picks up at the right slice without re-reading the artifact tree.
104
104
 
105
+ ### Peaks-Loop Step 0.51 — `orchestrator-can-do` probe (slice 2026-08-05, lesson-encoded CLI)
106
+
107
+ > **Before deciding to push a slice to the next session**, run `peaks code orchestrator-can-do --slice-spec '<text>' --json`. The command evaluates 4 boundary questions (source code? sub-agent available? requires user decision? context sustainable?) and returns whether the slice can be done in the current session. Default to `canDoInSession=true` unless hard blockers are present; sub-agent dispatch (`peaks sub-agent dispatch rd`) is the canonical delegation path for source-code changes. This encodes the 2026-08-05 lesson — orchestrator MUST NOT Edit/Write `src/` directly, but MUST delegate via sub-agent dispatch. See `.peaks/memory/2026-08-05-peaks-code-orchestrator-capability-misjudgment.md`.
108
+
105
109
  ### Peaks-Loop Step N+2: Auto-compact at the warning line (v2.13.0 zero-pause contract)
106
110
 
107
111
  > **Zero-pause contract.** When context usage crosses the pre-compact threshold, peaks-loop **automatically fires `peaks compact auto --execute` — the LLM does NOT prompt the user to run `/compact` manually**. Stale prose that says "ask the user to compact" silently stalls the workflow. The v2.13.0 contract makes auto-compact a system responsibility, not a user action.
@@ -127,6 +131,8 @@ Full content extracted to **`references/startup-sequence.md`** (Steps 0 / 0.5-0.
127
131
 
128
132
  If the prose audit (`peaks audit red-lines`) flags any of the above, the slice is **blocked** until the prose is rewritten.
129
133
 
134
+ See also: references/session-overload-signal-index.md for the 7-signal lookup table the LLM consults before deciding to open a new session.
135
+
130
136
  ## CLI Drift Index (sediment 2026-07-09)
131
137
 
132
138
  > **Reading guide:** Verified against peaks-loop 4.0.0-beta.6. Each drift below is annotated inline at the relevant step with a `> CLI reality check`. On `error: unknown option ...`, **read the inline reality check first** before guessing.
@@ -0,0 +1,60 @@
1
+ # Session Overload Signal Index
2
+
3
+ > Single-source lookup for the LLM-side "should I open a new session?" decision.
4
+ > Slice 2026-08-05-session-overload-signal-index.
5
+
6
+ ## What this doc is
7
+
8
+ When the LLM senses context pressure, it must consult these 7 signals before
9
+ deciding to (a) auto-compact, (b) refuse the next slice, or (c) ask the user to
10
+ open a new session. The contract is: **LLM never re-asks the user about
11
+ cost/length/context** (red line #2 of `references/job-loop.md`). This index is
12
+ the lookup table the LLM must consult in lieu of intuition.
13
+
14
+ ## The 7 signals
15
+
16
+ | # | Signal source | Threshold | File / CLI | LLM action |
17
+ |---|---|---|---|---|
18
+ | 1 | prompt size (main session) | 50% / 75% / 80% / 90% | `src/services/context/threshold.ts`; probe via `peaks code context-now` | soft-warn at 50%; consider compact at 75%; MUST NOT auto-compact mid-batch (D6.e); Job mode ≥ 0.85 ⇒ MANDATORY `peaks compact auto --execute` |
19
+ | 2 | auto-compact zone | 0.85 pre-compact / 0.95 red-line | `src/services/code/auto-compact-orchestrator.ts`; `--enforce-job-mode` flag | Auto-fires `peaks compact auto --execute`; LLM MUST NOT prompt user to compact (zero-pause contract v2.13.0) |
20
+ | 3 | sub-agent dispatch prompt size | 50% / 75% / 80% | `src/services/context/context-guard.ts`; `peaks sub-agent-dispatch-guard` PreToolUse hook | soft-warn at 50%; CONTEXT_NEAR_LIMIT at 75%; hard-reject at 80% (CLI + hook double-guard) |
21
+ | 4 | statusline compact bar | visual | `src/services/compact-statusline/compact-statusline-service.ts` | ambient UI; surfaces queued/preparing/compacting/verifying/completed/failed/stalled |
22
+ | 5 | in-flight batch deferral | D6.e | `src/services/code/auto-compact-modes.ts` | defer compact until batch lands (NOT "new session") |
23
+ | 6 | compact stalled | 120s heartbeat timeout | `compact-lifecycle-store.ts` | ambient "stalled" detail in statusline |
24
+ | 7 | sub-agent heartbeat missing | per-role TTL | `peaks sub-agent heartbeat`; `peaks heartbeat-watch` | orchestrator-side warning, not LLM-driven "new session" |
25
+
26
+ ## Hard rules
27
+
28
+ - peaks-code SKILL.md red line #2 (see `references/job-loop.md`):
29
+ **Re-ask the user about cost / length / context is forbidden**.
30
+ The LLM MUST NOT prompt the user to open a new session based on overload
31
+ intuition alone; it MUST consult the 7 signals above and prefer auto-compact /
32
+ sub-agent dispatch guard / heartbeat-watch first.
33
+ - "Open a new session" is a **last resort** after auto-compact has been
34
+ attempted and the slice cannot fit. The user's role is to receive the
35
+ handoff capsule, not to micro-manage session lifecycle.
36
+
37
+ ## Decision flowchart
38
+
39
+ ```
40
+ LLM senses context pressure
41
+ ├─► Probe `peaks code context-now --json`
42
+ │ ├─ ratio < 0.50 → continue (no action)
43
+ │ ├─ 0.50 ≤ ratio < 0.75 → soft-warn; continue
44
+ │ ├─ 0.75 ≤ ratio < 0.85 → compact-zone candidate
45
+ │ │ ├─ Job mode → MUST auto-compact now
46
+ │ │ └─ non-Job → wait for next idle turn, then compact
47
+ │ ├─ 0.85 ≤ ratio < 0.95 → pre-compact zone; auto-compact MUST fire
48
+ │ └─ ratio ≥ 0.95 → red-line; synchronous gate (Karpathy §4)
49
+ ├─► Check statusline compact bar (signal #4)
50
+ │ ├─ queued / preparing / compacting / verifying → wait
51
+ │ ├─ failed → read failure reason, do NOT spawn new session
52
+ │ └─ stalled (>120s) → surface to user as a blocker, not a new-session ask
53
+ └─► Check sub-agent dispatch guard (signal #3)
54
+ ├─ 75% CONTEXT_NEAR_LIMIT → warn, continue with smaller prompt
55
+ └─ 80% PROMPT_TOO_LARGE → hard-reject; refactor the prompt
56
+
57
+ Only after ALL three checks above have been attempted without resolution:
58
+ emit the `peaks session split-handoff` capsule (NOT in this slice; follow-up)
59
+ and the user opens a new session in their own time.
60
+ ```