peaks-loop 4.1.18 → 4.1.19

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 (168) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +126 -0
  3. package/README-en.md +6 -0
  4. package/README.md +5 -0
  5. package/contracts/test-style-contract.md +14 -5
  6. package/dist/cli/commands/audit-red-lines-runners.js +6 -1
  7. package/dist/cli/commands/best-practice-scan-collision.d.ts +42 -0
  8. package/dist/cli/commands/best-practice-scan-collision.js +115 -0
  9. package/dist/cli/commands/best-practice-scan-command.d.ts +5 -0
  10. package/dist/cli/commands/best-practice-scan-command.js +9 -18
  11. package/dist/cli/commands/best-practice-scan-helpers.d.ts +12 -6
  12. package/dist/cli/commands/best-practice-scan-helpers.js +37 -17
  13. package/dist/cli/commands/code-auto-compact-command.js +26 -18
  14. package/dist/cli/commands/core/skill-generated-config-notice.d.ts +5 -0
  15. package/dist/cli/commands/core/skill-generated-config-notice.js +42 -8
  16. package/dist/cli/commands/core/skill-presence-commands.js +42 -74
  17. package/dist/cli/commands/core/skill-presence-set-command.d.ts +11 -0
  18. package/dist/cli/commands/core/skill-presence-set-command.js +175 -0
  19. package/dist/cli/commands/core/standards-init-command.js +44 -8
  20. package/dist/cli/commands/core/standards-migrate-command.js +5 -4
  21. package/dist/cli/commands/dispatch-dag-runners.d.ts +1 -0
  22. package/dist/cli/commands/dispatch-dag-runners.js +11 -1
  23. package/dist/cli/commands/dispatch-detached-branch.js +19 -1
  24. package/dist/cli/commands/mut-commands-helpers.d.ts +72 -5
  25. package/dist/cli/commands/mut-commands-helpers.js +197 -4
  26. package/dist/cli/commands/mut-commands.d.ts +9 -1
  27. package/dist/cli/commands/mut-commands.js +82 -154
  28. package/dist/cli/commands/preferences-commands.js +27 -2
  29. package/dist/cli/commands/scan-scope-helpers.js +2 -2
  30. package/dist/services/24h-mode/auto-engage.d.ts +11 -3
  31. package/dist/services/24h-mode/auto-engage.js +14 -6
  32. package/dist/services/artifacts/artifact-templates.js +10 -0
  33. package/dist/services/artifacts/backcompat-acceptance.d.ts +8 -1
  34. package/dist/services/artifacts/backcompat-acceptance.js +8 -7
  35. package/dist/services/artifacts/rd-transition-gates.d.ts +32 -5
  36. package/dist/services/artifacts/rd-transition-gates.js +96 -19
  37. package/dist/services/artifacts/request-artifact-service.js +6 -6
  38. package/dist/services/audit/enforcers/lint-output-style.js +14 -2
  39. package/dist/services/audit/enforcers/root-scratch-artifacts.d.ts +46 -0
  40. package/dist/services/audit/enforcers/root-scratch-artifacts.js +97 -0
  41. package/dist/services/audit/static-service.js +4 -4
  42. package/dist/services/code/auto-compact-history.d.ts +6 -1
  43. package/dist/services/code/auto-compact-history.js +6 -1
  44. package/dist/services/code/auto-compact-modes.d.ts +60 -14
  45. package/dist/services/code/auto-compact-modes.js +75 -20
  46. package/dist/services/code/auto-compact-profile.d.ts +23 -0
  47. package/dist/services/code/auto-compact-profile.js +51 -0
  48. package/dist/services/compact-history/compact-history-service.d.ts +6 -1
  49. package/dist/services/compact-history/compact-history-service.js +5 -1
  50. package/dist/services/context/auto-compact-types.d.ts +7 -5
  51. package/dist/services/doctor/doctor-service/checks/l3-runtime-root-census.d.ts +37 -0
  52. package/dist/services/doctor/doctor-service/checks/l3-runtime-root-census.js +100 -0
  53. package/dist/services/doctor/doctor-service/checks/skill-reference-parity.d.ts +11 -3
  54. package/dist/services/doctor/doctor-service/checks/skill-reference-parity.js +48 -29
  55. package/dist/services/doctor/doctor-service/plugin-registry.js +2 -0
  56. package/dist/services/hooks/hook-payload-cwd.d.ts +11 -4
  57. package/dist/services/hooks/hook-payload-cwd.js +11 -4
  58. package/dist/services/hooks/presence-marker-detector.d.ts +3 -0
  59. package/dist/services/hooks/presence-marker-detector.js +21 -19
  60. package/dist/services/ide/adapters/claude-code-adapter.js +6 -8
  61. package/dist/services/ide/adapters/codex-adapter.js +23 -7
  62. package/dist/services/ide/adapters/cursor-adapter.js +23 -7
  63. package/dist/services/mode/mode-status-service.d.ts +26 -27
  64. package/dist/services/mode/mode-status-service.js +36 -60
  65. package/dist/services/preferences/preferences-types.d.ts +30 -0
  66. package/dist/services/preferences/preferences-types.js +13 -0
  67. package/dist/services/scan/acceptance-coverage-service.d.ts +14 -11
  68. package/dist/services/scan/acceptance-coverage-service.js +157 -52
  69. package/dist/services/scan/rid-change-claims.d.ts +15 -0
  70. package/dist/services/scan/rid-change-claims.js +116 -0
  71. package/dist/services/skills/presence-caller-id.d.ts +51 -0
  72. package/dist/services/skills/presence-caller-id.js +43 -0
  73. package/dist/services/skills/presence-gate.d.ts +65 -0
  74. package/dist/services/skills/presence-gate.js +113 -0
  75. package/dist/services/skills/presence-lease-resolver.d.ts +63 -0
  76. package/dist/services/skills/presence-lease-resolver.js +114 -0
  77. package/dist/services/skills/presence-lease-selection.d.ts +91 -0
  78. package/dist/services/skills/presence-lease-selection.js +135 -0
  79. package/dist/services/skills/presence-lease-service.d.ts +3 -11
  80. package/dist/services/skills/presence-lease-service.js +34 -87
  81. package/dist/services/skills/presence-lease-store.d.ts +33 -0
  82. package/dist/services/skills/presence-lease-store.js +94 -0
  83. package/dist/services/skills/presence-lease-types.d.ts +31 -0
  84. package/dist/services/skills/presence-lease-types.js +27 -0
  85. package/dist/services/skills/presence-role.d.ts +35 -0
  86. package/dist/services/skills/presence-role.js +72 -0
  87. package/dist/services/skills/skill-presence-service.d.ts +39 -9
  88. package/dist/services/skills/skill-presence-service.js +143 -174
  89. package/dist/services/skills/skill-presence-write.d.ts +60 -0
  90. package/dist/services/skills/skill-presence-write.js +74 -0
  91. package/dist/services/skills/skill-statusline-service.js +7 -7
  92. package/dist/services/standards/ide-aware-standards-service.d.ts +35 -23
  93. package/dist/services/standards/ide-aware-standards-service.js +45 -20
  94. package/dist/services/standards/migrate-claude-rules-service.d.ts +6 -0
  95. package/dist/services/standards/migrate-claude-rules-service.js +18 -0
  96. package/dist/services/standards/migrate-service.d.ts +1 -1
  97. package/dist/services/standards/migrate-service.js +27 -7
  98. package/dist/services/standards/project-scripts.d.ts +25 -0
  99. package/dist/services/standards/project-scripts.js +116 -0
  100. package/dist/services/standards/project-standards-service.d.ts +23 -15
  101. package/dist/services/standards/project-standards-service.js +176 -243
  102. package/dist/services/standards/standards-constitution.d.ts +89 -0
  103. package/dist/services/standards/standards-constitution.js +199 -0
  104. package/dist/services/standards/standards-files.d.ts +37 -0
  105. package/dist/services/standards/standards-files.js +138 -0
  106. package/dist/services/standards/standards-pointer.d.ts +73 -0
  107. package/dist/services/standards/standards-pointer.js +98 -0
  108. package/dist/services/standards/standards-render-agents.d.ts +34 -0
  109. package/dist/services/standards/standards-render-agents.js +149 -0
  110. package/dist/services/standards/standards-render-common.d.ts +38 -1
  111. package/dist/services/standards/standards-render-common.js +44 -7
  112. package/dist/services/standards/standards-render.d.ts +1 -3
  113. package/dist/services/standards/standards-render.js +6 -87
  114. package/dist/services/workflow/workflow-graph-ensure.d.ts +77 -0
  115. package/dist/services/workflow/workflow-graph-ensure.js +97 -0
  116. package/dist/services/workflow/workflow-presence-lifecycle.js +21 -6
  117. package/dist/services/workspace/generated-artifacts-content.d.ts +46 -0
  118. package/dist/services/workspace/generated-artifacts-content.js +167 -0
  119. package/dist/services/workspace/generated-artifacts-stamp.d.ts +36 -13
  120. package/dist/services/workspace/generated-artifacts-stamp.js +37 -15
  121. package/dist/services/workspace/runtime-layout.d.ts +64 -0
  122. package/dist/services/workspace/runtime-layout.js +62 -0
  123. package/output-styles/peaks-skill-swarm.md +18 -2
  124. package/package.json +8 -9
  125. package/schemas/doctor-report.schema.json +1 -1
  126. package/skills/bee/peaks-perf-audit/SKILL.md +3 -1
  127. package/skills/bee/peaks-prd/SKILL.md +5 -3
  128. package/skills/bee/peaks-qa/SKILL.md +4 -2
  129. package/skills/bee/peaks-qa/references/qa-skill-presence.md +1 -1
  130. package/skills/bee/peaks-qa/references/qa-standards-preflight.md +3 -1
  131. package/skills/bee/peaks-qa/references/qa-sub-agent-dispatch.md +2 -2
  132. package/skills/bee/peaks-rd/SKILL.md +4 -2
  133. package/skills/bee/peaks-rd/references/artifact-and-standards-output.md +1 -1
  134. package/skills/bee/peaks-rd/references/rd-runbook.md +11 -2
  135. package/skills/bee/peaks-rd/references/rd-standards-preflight.md +3 -1
  136. package/skills/bee/peaks-rd/references/rd-sub-agent-dispatch.md +4 -4
  137. package/skills/bee/peaks-rd/references/rd-transition-gates.md +49 -5
  138. package/skills/bee/peaks-rd/references/skill-presence-and-title.md +1 -1
  139. package/skills/bee/peaks-reviewer/SKILL.md +3 -1
  140. package/skills/bee/peaks-sc/SKILL.md +4 -2
  141. package/skills/bee/peaks-security-audit/SKILL.md +3 -1
  142. package/skills/bee/peaks-txt/SKILL.md +5 -3
  143. package/skills/bee/peaks-ui/SKILL.md +6 -4
  144. package/skills/peaks-audit/SKILL.md +3 -1
  145. package/skills/peaks-code/SKILL.md +3 -1
  146. package/skills/peaks-code/references/a2a-artifact-mapping.md +3 -3
  147. package/skills/peaks-code/references/completion-handoff.md +1 -1
  148. package/skills/peaks-code/references/local-artifact-workspace.md +10 -11
  149. package/skills/peaks-code/references/micro-cycle.md +2 -2
  150. package/skills/peaks-code/references/mode-selection-with-stale-presence.md +3 -3
  151. package/skills/peaks-code/references/runbook.md +4 -4
  152. package/skills/peaks-code/references/skill-presence-and-title.md +4 -2
  153. package/skills/peaks-code/references/standards-preflight.md +7 -6
  154. package/skills/peaks-code/references/sub-agent-dispatch.md +1 -1
  155. package/skills/peaks-code/references/swarm-dispatch-contract.md +5 -5
  156. package/skills/peaks-code/references/workflow-gates-and-types.md +37 -11
  157. package/skills/peaks-content/SKILL.md +3 -1
  158. package/skills/peaks-doctor/SKILL.md +3 -1
  159. package/skills/peaks-final-review/SKILL.md +3 -1
  160. package/skills/peaks-ide/SKILL.md +3 -1
  161. package/skills/peaks-issue-fix-orchestrator/SKILL.md +5 -3
  162. package/skills/peaks-race-code/SKILL.md +3 -1
  163. package/skills/peaks-resume/SKILL.md +3 -1
  164. package/skills/peaks-slice-decompose/SKILL.md +3 -1
  165. package/skills/peaks-solo/SKILL.md +3 -1
  166. package/skills/peaks-sop/SKILL.md +4 -2
  167. package/skills/peaks-status/SKILL.md +3 -1
  168. package/skills/peaks-test/SKILL.md +3 -1
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The PUBLIC auto-compact profile resolution.
3
+ *
4
+ * The profile used to be derived from the 24h long-run state machine, which
5
+ * made the compaction cadence a private property of one mode. It is now a
6
+ * public choice, resolved in ONE order:
7
+ *
8
+ * 1. an explicit `--mode` on this invocation (highest; one call, one override)
9
+ * 2. the project setting `autoCompactProfile` (public, persistent, any mode)
10
+ * 3. the default `'standard'`
11
+ *
12
+ * The 24h mode does NOT participate: a project that wants to compact earlier
13
+ * says so with the project setting. Where the profile is STORED or REPORTED it
14
+ * is always the canonical profile name — never the legacy alias.
15
+ */
16
+ import { loadPreferences } from '../preferences/preferences-service.js';
17
+ import { normalizeAutoCompactMode } from './auto-compact-modes.js';
18
+ /**
19
+ * The profile the project pinned, or `null` when it pinned nothing: no key in
20
+ * the file, an unknown value, or the default `'standard'`. A file this build
21
+ * CANNOT READ answers `null` too, leaving the compaction path unbroken.
22
+ */
23
+ export function readAutoCompactProfilePreference(projectRoot) {
24
+ const read = readStoredProfile(projectRoot);
25
+ if (!read.ok)
26
+ return null;
27
+ const normalized = typeof read.value === 'string' ? normalizeAutoCompactMode(read.value) : null;
28
+ return normalized === null || normalized === 'standard' ? null : normalized;
29
+ }
30
+ /** Read the stored preference, naming the failure instead of hiding it. */
31
+ function readStoredProfile(projectRoot) {
32
+ try {
33
+ return { ok: true, value: loadPreferences(projectRoot).autoCompactProfile };
34
+ }
35
+ catch {
36
+ return { ok: false, reason: 'unreadable' };
37
+ }
38
+ }
39
+ /**
40
+ * Resolve the profile in force for one invocation — THE resolution order lives
41
+ * here, in one place, so it cannot drift between the CLI and the services.
42
+ */
43
+ export function resolveAutoCompactProfile(input) {
44
+ if (input.cliMode !== undefined && input.cliMode !== null) {
45
+ return { profile: input.cliMode, source: 'cli' };
46
+ }
47
+ const preference = readAutoCompactProfilePreference(input.projectRoot);
48
+ if (preference !== null)
49
+ return { profile: preference, source: 'preference' };
50
+ return { profile: 'standard', source: 'default' };
51
+ }
@@ -2,7 +2,12 @@ export interface CompactHistoryEvent {
2
2
  readonly schemaVersion: 1;
3
3
  readonly ts: string;
4
4
  readonly target: 'main' | 'sub-agent' | 'worker';
5
- readonly mode: 'standard' | 'partial' | 'aggressive';
5
+ /**
6
+ * The profile the run used. `eager` is the canonical name of the
7
+ * earlier-firing profile; `partial` is its legacy alias and is still
8
+ * accepted so an old row keeps parsing; `aggressive` predates both.
9
+ */
10
+ readonly mode: 'standard' | 'partial' | 'aggressive' | 'eager';
6
11
  readonly ide: string;
7
12
  readonly pathway: string;
8
13
  readonly beforeRatio: number;
@@ -11,6 +11,7 @@
11
11
  // read.
12
12
  import { existsSync, readFileSync } from 'node:fs';
13
13
  import { join } from 'node:path';
14
+ import { normalizeAutoCompactMode } from '../code/auto-compact-modes.js';
14
15
  /**
15
16
  * Pair each dispatched compact with the measurement that followed it. Pure;
16
17
  * tolerates a file written by an earlier release (no `windowTokens`, no
@@ -79,7 +80,10 @@ export function readCompactHistory(input) {
79
80
  parseErrors.push({ line: idx + 1, raw: line });
80
81
  return;
81
82
  }
82
- events.push(parsed);
83
+ // A row written before the rename carries the legacy alias `partial`.
84
+ // It reads back as `eager`, so an old row and a new row describe the
85
+ // SAME profile and can be compared.
86
+ events.push({ ...parsed, mode: normalizeAutoCompactMode(parsed.mode) ?? parsed.mode });
83
87
  }
84
88
  catch {
85
89
  parseErrors.push({ line: idx + 1, raw: line });
@@ -130,11 +130,13 @@ export type AutoCompactResult = {
130
130
  */
131
131
  readonly target?: 'main' | 'sub-agent';
132
132
  /**
133
- * was used. Defaults to `'standard'` (0.85/0.95). `'partial'`
134
- * (0.70/0.85) is selected when 24h mode is active or the
135
- * caller passes `--mode partial`.
133
+ * The profile the run used. Defaults to `'standard'` (pre-compact
134
+ * 0.85 / red-line 0.95). `'eager'` (0.70/0.85) fires earlier; it is
135
+ * selected by the project setting `autoCompactProfile` or by an
136
+ * explicit `--mode eager`. The legacy alias `'partial'` means
137
+ * `'eager'`.
136
138
  */
137
- readonly mode?: 'standard' | 'partial';
139
+ readonly mode?: 'standard' | 'partial' | 'eager';
138
140
  /**
139
141
  * True when the ratio had crossed the red line and peaks-loop asked
140
142
  * the harness to compact.
@@ -193,7 +195,7 @@ export interface ContextPercentProbe {
193
195
  readonly ratio: number;
194
196
  /**
195
197
  * Adapter-driven source tag. Fixed values:
196
- * - `user-overridden` (v2.14.0 rid-002: explicit `--prompt-size
198
+ * - `user-overridden` (since v2.14.0: an explicit `--prompt-size
197
199
  * <bytes>` from the CLI / hook wrapper —
198
200
  * takes priority P0 over EVERY other source.
199
201
  * Mac escape hatch.)
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Check: the runtime root holds only what the registry knows
3
+ * (`L3:l3-runtime-root-census`).
4
+ *
5
+ * WHY A NEW CHECK, AND NOT AN EXTENSION OF `L3:l3-orphan-sessions`.
6
+ *
7
+ * The orphan check answers ONE question: "is this DIRECTORY a valid session
8
+ * id?". It reads directories only, so a stray FILE at the root was invisible
9
+ * to it — 204 of them had accumulated on 2026-10-24 with no product check
10
+ * able to name them. Widening that check to cover files would have made its
11
+ * id lie: an id that says "orphan sessions" must not start reporting stray
12
+ * files.
13
+ *
14
+ * This check answers a different question: "does the runtime root contain
15
+ * anything the registry does not know?". Its id names the ROOT rather than
16
+ * one failure mode, so it covers both an orphan session dir and a stray file
17
+ * — which is exactly what the registry has to be right about.
18
+ *
19
+ * IT READS THE REAL TREE. The drift guard (`tests/unit/workspace/
20
+ * runtime-layout-drift-guard.test.ts`) walks `src/**` and proved the CODE
21
+ * does not write an unregistered child; it never looked at the working tree.
22
+ * This check is the counterpart: it looks at the working tree.
23
+ *
24
+ * FAIL-CLOSED. A runtime root that cannot be read is NOT a clean root. The
25
+ * census reports "could not determine" and this check reports `ok: false`; it
26
+ * is rendered with `severity: 'warning'`, so an unreadable root is visible in
27
+ * the JSON envelope without turning `peaks doctor` red on a project that
28
+ * simply has no peaks workspace yet.
29
+ */
30
+ import type { DoctorCheckPlugin } from '../types.js';
31
+ /**
32
+ * The check id. The `L3:` prefix keeps it in the family that runs last, and
33
+ * the name covers the whole root — an orphan session dir and a stray file are
34
+ * the same finding here: something the registry does not know.
35
+ */
36
+ export declare const RUNTIME_ROOT_CENSUS_CHECK_ID = "L3:l3-runtime-root-census";
37
+ export declare const check: DoctorCheckPlugin;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Check: the runtime root holds only what the registry knows
3
+ * (`L3:l3-runtime-root-census`).
4
+ *
5
+ * WHY A NEW CHECK, AND NOT AN EXTENSION OF `L3:l3-orphan-sessions`.
6
+ *
7
+ * The orphan check answers ONE question: "is this DIRECTORY a valid session
8
+ * id?". It reads directories only, so a stray FILE at the root was invisible
9
+ * to it — 204 of them had accumulated on 2026-10-24 with no product check
10
+ * able to name them. Widening that check to cover files would have made its
11
+ * id lie: an id that says "orphan sessions" must not start reporting stray
12
+ * files.
13
+ *
14
+ * This check answers a different question: "does the runtime root contain
15
+ * anything the registry does not know?". Its id names the ROOT rather than
16
+ * one failure mode, so it covers both an orphan session dir and a stray file
17
+ * — which is exactly what the registry has to be right about.
18
+ *
19
+ * IT READS THE REAL TREE. The drift guard (`tests/unit/workspace/
20
+ * runtime-layout-drift-guard.test.ts`) walks `src/**` and proved the CODE
21
+ * does not write an unregistered child; it never looked at the working tree.
22
+ * This check is the counterpart: it looks at the working tree.
23
+ *
24
+ * FAIL-CLOSED. A runtime root that cannot be read is NOT a clean root. The
25
+ * census reports "could not determine" and this check reports `ok: false`; it
26
+ * is rendered with `severity: 'warning'`, so an unreadable root is visible in
27
+ * the JSON envelope without turning `peaks doctor` red on a project that
28
+ * simply has no peaks workspace yet.
29
+ */
30
+ import { readdirSync } from 'node:fs';
31
+ import { join } from 'node:path';
32
+ import { getErrorMessage } from 'peaks-loop-shared/result';
33
+ import { censusRuntimeRoot } from '../../../workspace/runtime-layout.js';
34
+ /**
35
+ * The check id. The `L3:` prefix keeps it in the family that runs last, and
36
+ * the name covers the whole root — an orphan session dir and a stray file are
37
+ * the same finding here: something the registry does not know.
38
+ */
39
+ export const RUNTIME_ROOT_CENSUS_CHECK_ID = 'L3:l3-runtime-root-census';
40
+ /** How many offenders the message inlines before eliding the rest. */
41
+ const MAX_NAMES_IN_MESSAGE = 5;
42
+ /**
43
+ * Read the runtime root.
44
+ *
45
+ * A read that fails (missing directory, permission denied) is reported as
46
+ * `unreadable`, NEVER as an empty list: an empty list would read as "clean",
47
+ * which is the one answer an unreadable tree is not entitled to give.
48
+ */
49
+ function readRuntimeRoot(runtimeDir) {
50
+ try {
51
+ const entries = readdirSync(runtimeDir, { withFileTypes: true });
52
+ const mapped = entries.map((entry) => ({
53
+ name: entry.name,
54
+ kind: entry.isDirectory() ? 'dir' : 'file'
55
+ }));
56
+ return { status: 'read', entries: mapped };
57
+ }
58
+ catch (error) {
59
+ return { status: 'unreadable', reason: getErrorMessage(error) };
60
+ }
61
+ }
62
+ /** The offenders, each with its kind, elided past the cut. */
63
+ function describeViolations(violations) {
64
+ const shown = violations.slice(0, MAX_NAMES_IN_MESSAGE);
65
+ const elided = violations.length - shown.length;
66
+ const names = shown.map((violation) => `${violation.name} (${violation.kind})`).join(', ');
67
+ return elided > 0 ? `${names} (+${elided} more)` : names;
68
+ }
69
+ function render(census) {
70
+ if (census.status === 'clean') {
71
+ return {
72
+ id: RUNTIME_ROOT_CENSUS_CHECK_ID,
73
+ ok: true,
74
+ message: `Runtime root census: all ${census.entryCount} top-level entr(y/ies) under .peaks/_runtime/ are registered or session-shaped`
75
+ };
76
+ }
77
+ if (census.status === 'violations') {
78
+ return {
79
+ id: RUNTIME_ROOT_CENSUS_CHECK_ID,
80
+ ok: false,
81
+ severity: 'error',
82
+ message: `Runtime root census: ${census.violations.length} stray entr(y/ies) under .peaks/_runtime/ are not registered: ${describeViolations(census.violations)}. Register the legitimate ones in src/services/workspace/runtime-layout.ts; move the rest under the session dir.`
83
+ };
84
+ }
85
+ return {
86
+ id: RUNTIME_ROOT_CENSUS_CHECK_ID,
87
+ ok: false,
88
+ severity: 'warning',
89
+ message: `Runtime root census could not be determined — the runtime root could not be read (${census.reason}); the tree was NOT verified clean.`
90
+ };
91
+ }
92
+ function run({ resolvedL3Root, isValidSessionId }) {
93
+ const runtimeDir = join(resolvedL3Root, '.peaks/_runtime');
94
+ const read = readRuntimeRoot(runtimeDir);
95
+ return [render(censusRuntimeRoot({ read, isValidSessionId }))];
96
+ }
97
+ export const check = {
98
+ name: 'l3-runtime-root-census',
99
+ run
100
+ };
@@ -11,6 +11,12 @@
11
11
  * repairs, rewrites, or deletes. A mismatch is a warning — a skill missing one
12
12
  * reference still runs — and the message names the LLM-run repair.
13
13
  *
14
+ * IT ALWAYS EMITS A ROW. A check that stays silent when it finds nothing
15
+ * cannot be told apart from one that never ran, so this one says "clean" out
16
+ * loud: `skills:reference-parity:store` with `ok: true` when every tree is in
17
+ * parity, or when there was nothing to compare. The SAME id goes red when
18
+ * the store could not be compared at all (absent or unreadable).
19
+ *
14
20
  * The canonical store is the anchor: only skills present under
15
21
  * `<PEAKS_HOME or ~/.peaks>/skills` are compared, so a user-authored skill that
16
22
  * exists only in an IDE root is not reported as drift.
@@ -27,9 +33,11 @@ import type { DoctorCheck, DoctorCheckPlugin } from '../types.js';
27
33
  * directories to compare against it. Roots that do not exist are skipped, so
28
34
  * the wrapper may pass every adapter that declares `skillInstall`.
29
35
  *
30
- * Identical trees emit no check at all: the absence of a parity finding is the
31
- * pass, which keeps the doctor report exactly as long as its findings. A store
32
- * that exists but cannot be read is a warning, never silence.
36
+ * IT ALWAYS EMITS A ROW. The store-level row `skills:reference-parity:store`
37
+ * has FOUR outcomes: GREEN in parity (the comparison ran and every tree
38
+ * matched), GREEN with nothing to compare (no IDE skill root exists), RED
39
+ * when the store is absent, and RED when the store is not a readable
40
+ * directory. A diverging tree reports its own `<ide>:<skill>` row instead.
33
41
  */
34
42
  export declare function compareSkillReferenceParity(canonicalRoot: string, ideRoots: ReadonlyArray<{
35
43
  ide: string;
@@ -11,6 +11,12 @@
11
11
  * repairs, rewrites, or deletes. A mismatch is a warning — a skill missing one
12
12
  * reference still runs — and the message names the LLM-run repair.
13
13
  *
14
+ * IT ALWAYS EMITS A ROW. A check that stays silent when it finds nothing
15
+ * cannot be told apart from one that never ran, so this one says "clean" out
16
+ * loud: `skills:reference-parity:store` with `ok: true` when every tree is in
17
+ * parity, or when there was nothing to compare. The SAME id goes red when
18
+ * the store could not be compared at all (absent or unreadable).
19
+ *
14
20
  * The canonical store is the anchor: only skills present under
15
21
  * `<PEAKS_HOME or ~/.peaks>/skills` are compared, so a user-authored skill that
16
22
  * exists only in an IDE root is not reported as drift.
@@ -167,52 +173,65 @@ function toCheck(issue, canonicalRoot) {
167
173
  message: `${parts.join('; ')}. ${REPAIR_HINT}.`
168
174
  };
169
175
  }
176
+ /** The store-level RED row: one id and one severity for both failure arms. */
177
+ function storeWarningRow(message) {
178
+ return { id: 'skills:reference-parity:store', ok: false, severity: 'warning', message };
179
+ }
170
180
  /**
171
- * Pure comparator. `canonicalRoot` is the canonical skills store
172
- * (`<PEAKS_HOME or ~/.peaks>/skills`); `ideRoots` are the IDE-side skills
173
- * directories to compare against it. Roots that do not exist are skipped, so
174
- * the wrapper may pass every adapter that declares `skillInstall`.
175
- *
176
- * Identical trees emit no check at all: the absence of a parity finding is the
177
- * pass, which keeps the doctor report exactly as long as its findings. A store
178
- * that exists but cannot be read is a warning, never silence.
181
+ * The store-level RED row when the canonical store cannot be compared, or null
182
+ * when it can: both failure arms share one id and one `severity: 'warning'`.
179
183
  */
180
- export function compareSkillReferenceParity(canonicalRoot, ideRoots) {
184
+ function storeFailureRow(canonicalRoot) {
181
185
  if (!existsSync(canonicalRoot)) {
182
- return [
183
- {
184
- id: 'skills:reference-parity:store',
185
- ok: true,
186
- message: `Canonical skill store not found at ${canonicalRoot}; nothing to compare`
187
- }
188
- ];
186
+ return storeWarningRow(`Canonical skill store not found at ${canonicalRoot}; IDE skill roots were not compared`);
189
187
  }
190
188
  const problem = storeProblem(canonicalRoot);
191
- if (problem !== null) {
192
- return [
193
- {
194
- id: 'skills:reference-parity:store',
195
- ok: false,
196
- severity: 'warning',
197
- message: `Canonical skill store at ${canonicalRoot} ${problem}; IDE skill roots were not compared`
198
- }
199
- ];
200
- }
189
+ if (problem === null)
190
+ return null;
191
+ return storeWarningRow(`Canonical skill store at ${canonicalRoot} ${problem}; IDE skill roots were not compared`);
192
+ }
193
+ /** The divergence rows for every IDE skill root, or the GREEN store row. */
194
+ function compareIdeSkillTrees(canonicalRoot, ideRoots) {
201
195
  const canonicalSkills = new Map();
202
196
  for (const skill of listSkillNames(canonicalRoot)) {
203
197
  canonicalSkills.set(skill, listRelativeFiles(join(canonicalRoot, skill)));
204
198
  }
205
199
  const checks = [];
200
+ let compared = 0;
206
201
  for (const { ide, skillsDir } of ideRoots) {
207
202
  if (!existsSync(skillsDir))
208
203
  continue;
209
- for (const skill of [...canonicalSkills.keys()].sort()) {
210
- const issue = diffSkillTrees(ide, skill, canonicalSkills.get(skill) ?? new Set(), listRelativeFiles(join(skillsDir, skill)));
204
+ for (const [skill, files] of canonicalSkills) {
205
+ compared += 1;
206
+ const issue = diffSkillTrees(ide, skill, files, listRelativeFiles(join(skillsDir, skill)));
211
207
  if (issue !== null)
212
208
  checks.push(toCheck(issue, canonicalRoot));
213
209
  }
214
210
  }
215
- return checks;
211
+ if (checks.length > 0)
212
+ return checks;
213
+ const clean = compared === 0
214
+ ? `No skill tree to compare with the canonical store at ${canonicalRoot}; nothing to compare`
215
+ : `Every IDE skill tree is in parity with the canonical store at ${canonicalRoot} (${compared} skill trees compared)`;
216
+ return [{ id: 'skills:reference-parity:store', ok: true, message: clean }];
217
+ }
218
+ /**
219
+ * Pure comparator. `canonicalRoot` is the canonical skills store
220
+ * (`<PEAKS_HOME or ~/.peaks>/skills`); `ideRoots` are the IDE-side skills
221
+ * directories to compare against it. Roots that do not exist are skipped, so
222
+ * the wrapper may pass every adapter that declares `skillInstall`.
223
+ *
224
+ * IT ALWAYS EMITS A ROW. The store-level row `skills:reference-parity:store`
225
+ * has FOUR outcomes: GREEN in parity (the comparison ran and every tree
226
+ * matched), GREEN with nothing to compare (no IDE skill root exists), RED
227
+ * when the store is absent, and RED when the store is not a readable
228
+ * directory. A diverging tree reports its own `<ide>:<skill>` row instead.
229
+ */
230
+ export function compareSkillReferenceParity(canonicalRoot, ideRoots) {
231
+ const failure = storeFailureRow(canonicalRoot);
232
+ if (failure !== null)
233
+ return [failure];
234
+ return compareIdeSkillTrees(canonicalRoot, ideRoots);
216
235
  }
217
236
  function canonicalSkillsStore() {
218
237
  const home = process.env.PEAKS_HOME?.trim();
@@ -53,6 +53,7 @@ import { check as eccHooksSchemaDrift } from './checks/ecc-hooks-schema-drift.js
53
53
  import { check as checkIdSchema } from './checks/check-id-schema.js';
54
54
  import { check as backcompatAcceptance } from './checks/backcompat-acceptance.js';
55
55
  import { check as l3OrphanSessions } from './checks/l3-orphan-sessions.js';
56
+ import { check as l3RuntimeRootCensus } from './checks/l3-runtime-root-census.js';
56
57
  import { check as l3MemoryHealth } from './checks/l3-memory-health.js';
57
58
  /**
58
59
  * Ordered list of doctor check plugins. The order mirrors the legacy
@@ -85,5 +86,6 @@ export const PLUGINS = [
85
86
  backcompatAcceptance, // id "config:backcompat-acceptance"
86
87
  checkIdSchema, // id "doctor-self:check-id-pattern"
87
88
  l3OrphanSessions, // id "L3:l3-orphan-sessions"
89
+ l3RuntimeRootCensus, // id "L3:l3-runtime-root-census"
88
90
  l3MemoryHealth // id "L3:l3-memory-health"
89
91
  ];
@@ -30,10 +30,17 @@ export declare function readToolCallCwd(payload: Readonly<Record<string, unknown
30
30
  * The rule ASSUMES the tool call runs inside the named project, which is
31
31
  * where the gate is installed. When it does not, the payload `cwd` is
32
32
  * rejected and the path is read against the gate's own working directory
33
- * instead — a different tree — and the error is one-directional: a file that
34
- * lies outside every family can be denied. It is never the other way round,
35
- * and that is the trade the gate makes everywhere else: a wrongly allowed
36
- * edit is a hole, a wrongly refused one is an inconvenience.
33
+ * instead — a different tree.
34
+ *
35
+ * While the base the path is read against IS the call's own directory, the
36
+ * error stays one-directional: a file that lies outside every family can be
37
+ * denied, and never the other way round — a wrongly allowed edit is a hole,
38
+ * a wrongly refused one is an inconvenience. That direction is NOT a general
39
+ * property of the fallback: when the base is the gate's own working
40
+ * directory and the call runs somewhere else, the call's relative path is
41
+ * read against a tree that is not the call's, and a file that really is
42
+ * inside a hard-blocked family can be ALLOWED.
43
+ * Measured 2026-10-23; backlog §19.3.
37
44
  *
38
45
  * The fallback is the gate process's own working directory: that is where the
39
46
  * hook runs, and in the normal invocation it IS the tool call's directory.
@@ -88,10 +88,17 @@ function isInsideProject(root, dir) {
88
88
  * The rule ASSUMES the tool call runs inside the named project, which is
89
89
  * where the gate is installed. When it does not, the payload `cwd` is
90
90
  * rejected and the path is read against the gate's own working directory
91
- * instead — a different tree — and the error is one-directional: a file that
92
- * lies outside every family can be denied. It is never the other way round,
93
- * and that is the trade the gate makes everywhere else: a wrongly allowed
94
- * edit is a hole, a wrongly refused one is an inconvenience.
91
+ * instead — a different tree.
92
+ *
93
+ * While the base the path is read against IS the call's own directory, the
94
+ * error stays one-directional: a file that lies outside every family can be
95
+ * denied, and never the other way round — a wrongly allowed edit is a hole,
96
+ * a wrongly refused one is an inconvenience. That direction is NOT a general
97
+ * property of the fallback: when the base is the gate's own working
98
+ * directory and the call runs somewhere else, the call's relative path is
99
+ * read against a tree that is not the call's, and a file that really is
100
+ * inside a hard-blocked family can be ALLOWED.
101
+ * Measured 2026-10-23; backlog §19.3.
95
102
  *
96
103
  * The fallback is the gate process's own working directory: that is where the
97
104
  * hook runs, and in the normal invocation it IS the tool call's directory.
@@ -5,6 +5,9 @@ export type DetectPresenceMarkerInput = {
5
5
  export type DetectPresenceMarkerResult = {
6
6
  active: boolean;
7
7
  skill?: string;
8
+ /** The gate the active presence is parked on — the machine fact behind
9
+ * the status header's middle cell. Absent when the lease carries none. */
10
+ gate?: string;
8
11
  markerFound: boolean;
9
12
  warning?: string;
10
13
  };
@@ -1,5 +1,5 @@
1
- import { getSessionId } from '../session/session-manager.js';
2
- import { listPresenceLeases } from '../skills/presence-lease-service.js';
1
+ import { resolvePresenceLease } from '../skills/presence-lease-resolver.js';
2
+ import { readPresenceGate } from '../skills/presence-gate.js';
3
3
  /**
4
4
  *
5
5
  * Background: the consumer-facing CLAUDE.md template (rendered by
@@ -43,25 +43,23 @@ export const PRESENCE_MARKER_WARNING = [
43
43
  ];
44
44
  /**
45
45
  * Slice 4.0.11 statusline-sid-scoped-lease C: read the canonical
46
- * sid-scoped lease projection. Returns the in-flight lease with the
47
- * most recent `lastHeartbeat`, or null when no leases exist for the
48
- * bound session. Picked the most-recent-in-flight lease (mirrors the
49
- * statusline `callerId === null` back-compat path).
46
+ * sid-scoped lease projection.
47
+ *
48
+ * Slice 4.0.17 (presence cross-session): the read goes through
49
+ * the SAME resolver the `peaks skill presence` CLI uses — the lease that
50
+ * is eligible across EVERY session tree, not just the bound one. The
51
+ * two readers must not disagree: the CLI says "peaks-code is running"
52
+ * and the hook says "no presence" is not a state a user can act on.
53
+ *
54
+ * Returns the freshest eligible lease (freshest `lastHeartbeat` wins,
55
+ * with a total tie-break), or null when no tree holds one.
50
56
  */
51
57
  function readCanonicalLease(projectRoot) {
52
- const sessionId = getSessionId(projectRoot);
53
- if (sessionId === null)
54
- return null;
55
- const leases = listPresenceLeases(projectRoot, sessionId);
56
- const inFlight = leases.filter((l) => l.status === 'running' || l.status === 'preparing');
57
- if (inFlight.length === 0)
58
- return null;
59
- // Sort by lastHeartbeat desc, return the freshest.
60
- inFlight.sort((a, b) => b.lastHeartbeat.localeCompare(a.lastHeartbeat));
61
- const freshest = inFlight[0];
62
- if (freshest === undefined)
58
+ const selection = resolvePresenceLease(projectRoot);
59
+ if (selection === null)
63
60
  return null;
64
- return { skill: freshest.skill };
61
+ const gate = readPresenceGate(selection.lease.gate);
62
+ return { skill: selection.lease.skill, ...(gate !== undefined ? { gate } : {}) };
65
63
  }
66
64
  /**
67
65
  * Slice 4.0.11 statusline-sid-scoped-lease C: the deprecated
@@ -100,6 +98,7 @@ export function detectPresenceMarker(input) {
100
98
  if (presence === null) {
101
99
  return { active: false, markerFound: false };
102
100
  }
101
+ const gateField = presence.gate !== undefined ? { gate: presence.gate } : {};
103
102
  const brokenGraph = tryDetectBrokenGraph(project);
104
103
  const markerFound = messageHasMarker(message);
105
104
  if (markerFound) {
@@ -107,16 +106,18 @@ export function detectPresenceMarker(input) {
107
106
  return {
108
107
  active: true,
109
108
  skill: presence.skill,
109
+ ...gateField,
110
110
  markerFound: true,
111
111
  warning: `Peaks presence active but graph is broken (${brokenGraph}); run \`peaks workspace reconcile\` to repair.`
112
112
  };
113
113
  }
114
- return { active: true, skill: presence.skill, markerFound: true };
114
+ return { active: true, skill: presence.skill, ...gateField, markerFound: true };
115
115
  }
116
116
  if (brokenGraph !== null) {
117
117
  return {
118
118
  active: true,
119
119
  skill: presence.skill,
120
+ ...gateField,
120
121
  markerFound: false,
121
122
  warning: `Peaks presence active but graph is broken (${brokenGraph}); run \`peaks workspace reconcile\` to repair.`
122
123
  };
@@ -124,6 +125,7 @@ export function detectPresenceMarker(input) {
124
125
  return {
125
126
  active: true,
126
127
  skill: presence.skill,
128
+ ...gateField,
127
129
  markerFound: false,
128
130
  warning: PRESENCE_MARKER_WARNING[0]
129
131
  };
@@ -530,20 +530,18 @@ export const CLAUDE_CODE_ADAPTER = {
530
530
  resolveTranscriptPath: (outerSessionId) => resolveClaudeTranscriptPath(outerSessionId)
531
531
  },
532
532
  // Slice #011: standards profile. Claude Code reads its constitution at
533
- // CLAUDE.md + module-level rules under .claude/rules/**. The values mirror
534
- // the hardcoded paths in `src/services/standards/project-standards-service.ts`
535
- // (line 147 = '.claude', line 417/421 = 'CLAUDE.md' + '.claude/rules/...')
536
- // and the postinstall target in `scripts/install-skills.mjs` (line 427 =
537
- // '~/.claude/skills'). Filling the profile here makes the dispatch layer
538
- // route to the SAME paths, so byte-stability on `peaks standards init` for
539
- // Claude Code projects is preserved.
533
+ // CLAUDE.md and its module-level rules under .claude/rules/**. The
534
+ // `rootFile` value is what the standards writer branches on: a
535
+ // `CLAUDE.md` root means the writer emits the shared cross-tool body
536
+ // (AGENTS.md) AND a CLAUDE.md pointer that imports it, because Claude
537
+ // Code reads CLAUDE.md, not AGENTS.md, unless it is configured to.
540
538
  standardsProfile: {
541
539
  rootFile: 'CLAUDE.md',
542
540
  rulesDir: '.claude/rules',
543
541
  rulesFileGlob: '**/*.md',
544
542
  autoLoaded: true,
545
543
  format: 'markdown',
546
- migrationHint: 'Standards live at CLAUDE.md + .claude/rules/** for Claude Code.'
544
+ migrationHint: 'Standards live at AGENTS.md (body) + CLAUDE.md (pointer) for Claude Code.'
547
545
  },
548
546
  // Slice #011: skill install profile. The postinstall script symlinks
549
547
  // bundled skills to `~/.claude/skills` and writes output-styles to
@@ -102,12 +102,28 @@ export const CODEX_ADAPTER = {
102
102
  const err = new Error('PEAKS_CALLER_NOT_RESOLVED: Codex vendor signal reserved');
103
103
  err.code = 'PEAKS_CALLER_NOT_RESOLVED';
104
104
  throw err;
105
+ },
106
+ // Standards profile: Codex CLI reads `AGENTS.md` natively — it is one of
107
+ // the tools the AGENTS.md standard (OpenAI's AGENTS.md, now under the
108
+ // Linux Foundation's Agentic AI Foundation) is adopted by. So the shared
109
+ // cross-tool body IS Codex's project-instructions file, and no CLAUDE.md
110
+ // pointer is needed next to it.
111
+ //
112
+ // `rulesDir` stays `null`: where Codex looks for MODULE-level rules is
113
+ // still unverified (see slice #013+ for the real-install dogfood), so the
114
+ // profile claims only the root file.
115
+ standardsProfile: {
116
+ rootFile: 'AGENTS.md',
117
+ rulesDir: null,
118
+ rulesFileGlob: '**/*.md',
119
+ autoLoaded: true,
120
+ format: 'markdown',
121
+ migrationHint: 'Codex reads AGENTS.md directly; no CLAUDE.md pointer is written.'
105
122
  }
106
- // Standards: UNVERIFIED — see slice #013+ (Codex real-install dogfood for
107
- // the `standardsProfile` and `skillInstall` fields). Until then, `peaks
108
- // standards init` on a Codex-detected project falls back to the Claude
109
- // Code path (CLAUDE.md + .claude/rules/**) with a stderr warning, and the
110
- // postinstall script writes skills + output-styles to the legacy
111
- // `~/.claude/{skills,output-styles}` paths with a stderr warning. Users
112
- // who want Codex-specific paths must move the files manually.
123
+ // Standards: the ROOT file is verified above (AGENTS.md); the `rulesDir`
124
+ // and `skillInstall` fields remain UNVERIFIED pending slice #013+
125
+ // (Codex real-install dogfood). Until then the postinstall script writes
126
+ // skills + output-styles to the legacy `~/.claude/{skills,output-styles}`
127
+ // paths with a stderr warning. Users who want Codex-specific paths must
128
+ // move the files manually.
113
129
  };