claude-code-session-manager 0.139.0 → 0.140.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 (150) hide show
  1. package/README.md +20 -4
  2. package/dist/assets/AppSettings-CMFEM68R.js +2 -0
  3. package/dist/assets/History--JwsFnbn.js +2 -0
  4. package/dist/assets/{HomeClaudeConfig-CGD2Onjv.js → HomeClaudeConfig-ijEXs--3.js} +2 -2
  5. package/dist/assets/{Panel-Csyd9HbD.js → Panel-CALyU0pe.js} +1 -1
  6. package/dist/assets/{ProjectClaudeConfig-C-jlYpC_.js → ProjectClaudeConfig-sdlA-fUb.js} +1 -1
  7. package/dist/assets/Scheduler-YT3j8SUa.js +16 -0
  8. package/dist/assets/{SkillReferenceGraph-DcscPXAG.js → SkillReferenceGraph-CxAuwhNN.js} +1 -1
  9. package/dist/assets/{Skills-BpGRKOcY.js → Skills-DtRzghn5.js} +26 -26
  10. package/dist/assets/{TiptapBody-DSU3769X.js → TiptapBody-DApeu7x8.js} +1 -1
  11. package/dist/assets/{ViewTabs-C0PRZx4_.js → ViewTabs-B7qLXRAH.js} +1 -1
  12. package/dist/assets/{VoiceButton-D2rMurNg.js → VoiceButton-DtStfv1H.js} +1 -1
  13. package/dist/assets/{historyTotals-TcIQs2sh.js → historyTotals-ydfnwepc.js} +1 -1
  14. package/dist/assets/index-CtxruO1L.js +3121 -0
  15. package/dist/assets/{index-BCySPdtU.css → index-DKXdXfka.css} +1 -1
  16. package/dist/index.html +2 -2
  17. package/dist-web/app.css +1 -1
  18. package/dist-web/app.js +423 -426
  19. package/package.json +5 -2
  20. package/plugins/AGENTS.md +60 -0
  21. package/plugins/CLAUDE.md +1 -60
  22. package/plugins/session-manager-dev/skills/develop/SKILL.md +26 -19
  23. package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +5 -4
  24. package/plugins/session-manager-dev/skills/maintaining-md-network/audit.md +4 -2
  25. package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +16 -12
  26. package/plugins/session-manager-dev/skills/maintaining-md-network/migrate-to-agents-md.md +15 -0
  27. package/plugins/session-manager-dev/skills/maintaining-md-network/placement.md +50 -2
  28. package/plugins/session-manager-dev/skills/maintaining-md-network/plan.md +10 -10
  29. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +117 -112
  30. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdDuplicates.cjs +182 -0
  31. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdLinks.cjs +340 -0
  32. package/scripts/README.md +1 -0
  33. package/scripts/hooks/guard-tool-risk.cjs +91 -0
  34. package/scripts/hooks/lib/guard-tool-risk-policy.cjs +217 -0
  35. package/scripts/ops-sweep.cjs +53 -23
  36. package/scripts/scheduler-mcp-server.cjs +200 -18
  37. package/src/main/build-info.json +4 -4
  38. package/src/main/config.cjs +112 -8
  39. package/src/main/docEdit.cjs +6 -1
  40. package/src/main/files.cjs +7 -27
  41. package/src/main/health.cjs +48 -15
  42. package/src/main/historyAggregator.cjs +88 -5
  43. package/src/main/historyDashboard.cjs +69 -4
  44. package/src/main/index.cjs +56 -2
  45. package/src/main/ipcSchemas.cjs +112 -16
  46. package/src/main/lib/AGENTS.md +54 -0
  47. package/src/main/lib/CLAUDE.md +1 -54
  48. package/src/main/lib/agent-cli/adapters/codex.cjs +5 -2
  49. package/src/main/lib/agent-cli/agentCliIpc.cjs +18 -2
  50. package/src/main/lib/agent-cli/agentCliSessionStore.cjs +1 -0
  51. package/src/main/lib/agent-cli/agentCliTurn.cjs +20 -2
  52. package/src/main/lib/agent-cli/geminiContextDefaults.cjs +94 -0
  53. package/src/main/lib/claude/effectiveModelInfo.cjs +90 -20
  54. package/src/main/lib/claude/jobSandboxPolicy.cjs +202 -0
  55. package/src/main/lib/claude/personaToolScope.cjs +12 -6
  56. package/src/main/lib/claude/rateLimitDetect.cjs +13 -2
  57. package/src/main/lib/claude/runClaudeP.cjs +6 -1
  58. package/src/main/lib/claude/toolRiskIpc.cjs +177 -0
  59. package/src/main/lib/claude/toolRiskMarks.cjs +373 -0
  60. package/src/main/lib/demo-video-kit/seedKit.cjs +27 -6
  61. package/src/main/lib/ephemeralCwd.cjs +37 -2
  62. package/src/main/lib/epic/delegationReadiness.cjs +42 -9
  63. package/src/main/lib/epic/epicAdminRoutes.cjs +25 -5
  64. package/src/main/lib/epic/epicOutsideRead.cjs +118 -1
  65. package/src/main/lib/epic/epicOutsideState.cjs +2 -2
  66. package/src/main/lib/epic/epicSweepValidator.cjs +7 -2
  67. package/src/main/lib/epic/epicValidationHook.cjs +24 -4
  68. package/src/main/lib/epic/guardSpawnSettings.cjs +57 -1
  69. package/src/main/lib/externalContract.cjs +31 -5
  70. package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +55 -1
  71. package/src/main/lib/feedback-remote/crossProjectReply.cjs +106 -11
  72. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +47 -19
  73. package/src/main/lib/feedback-remote/needsYouStore.cjs +6 -2
  74. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +98 -1
  75. package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +5 -0
  76. package/src/main/lib/git/branchSweep.cjs +209 -4
  77. package/src/main/lib/git/gitWorktree.cjs +41 -5
  78. package/src/main/lib/guardShims.cjs +1 -1
  79. package/src/main/lib/historyRollup.cjs +26 -0
  80. package/src/main/lib/insideHome.cjs +27 -1
  81. package/src/main/lib/mcpToolCatalog.cjs +122 -12
  82. package/src/main/lib/mdDocCensus.cjs +59 -78
  83. package/src/main/lib/mdDocRefs.cjs +71 -93
  84. package/src/main/lib/mdNetworkScan.cjs +245 -250
  85. package/src/main/lib/mdReviewRecord.cjs +22 -9
  86. package/src/main/lib/memoryMdNetwork.cjs +5 -12
  87. package/src/main/lib/opsOwnership.cjs +18 -2
  88. package/src/main/lib/opsRetentionSettings.cjs +28 -4
  89. package/src/main/lib/persona-macro/macroJobDispatch.cjs +90 -20
  90. package/src/main/lib/persona-macro/macroJobIpc.cjs +144 -46
  91. package/src/main/lib/persona-macro/macroJobStatus.cjs +87 -9
  92. package/src/main/lib/persona-macro/macroLibrary.cjs +95 -5
  93. package/src/main/lib/persona-macro/personaImportHealth.cjs +78 -17
  94. package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +96 -0
  95. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
  96. package/src/main/lib/prd/depSlugResolve.cjs +104 -4
  97. package/src/main/lib/prd/prdAdminRoutes.cjs +35 -2
  98. package/src/main/lib/prd/prdCreate.cjs +351 -23
  99. package/src/main/lib/prd/prdDisposition.cjs +11 -2
  100. package/src/main/lib/prd/prdFrontmatter.cjs +96 -3
  101. package/src/main/lib/process/loginItem.cjs +171 -0
  102. package/src/main/lib/process/loginItemPlan.cjs +193 -0
  103. package/src/main/lib/project-pages/playerBridge.cjs +4 -0
  104. package/src/main/lib/project-pages/videoReview.cjs +268 -0
  105. package/src/main/lib/project-pages/videoReviewIpc.cjs +229 -0
  106. package/src/main/lib/scheduler/cpuSample.cjs +131 -4
  107. package/src/main/lib/scheduler/fixPlanSlug.cjs +4 -3
  108. package/src/main/lib/scheduler/loadGate.cjs +24 -6
  109. package/src/main/lib/scheduler/planRecordHarvest.cjs +108 -0
  110. package/src/main/lib/scheduler/planRecordRetention.cjs +144 -0
  111. package/src/main/lib/scheduler/queueStore.cjs +7 -0
  112. package/src/main/lib/scheduler/rcaReport.cjs +21 -1
  113. package/src/main/lib/scheduler/reaperHelpers.cjs +35 -5
  114. package/src/main/lib/scheduler/runLogRetention.cjs +104 -3
  115. package/src/main/lib/scheduler/scheduleJobSchema.cjs +3 -0
  116. package/src/main/lib/scheduler/schedulerBatch.cjs +25 -48
  117. package/src/main/lib/scheduler/schedulerPaths.cjs +3 -0
  118. package/src/main/lib/scheduler/sessionSlots.cjs +176 -21
  119. package/src/main/lib/scheduler/validationQuality.cjs +282 -0
  120. package/src/main/lib/scheduler/validatorVerdictSchema.cjs +254 -0
  121. package/src/main/lib/tasks/taskAdminRoutes.cjs +641 -0
  122. package/src/main/lib/tasks/taskIpc.cjs +80 -0
  123. package/src/main/lib/tasks/taskLedger.cjs +502 -0
  124. package/src/main/lib/tasks/taskRun.cjs +313 -0
  125. package/src/main/lib/tasks/taskSwitch.cjs +120 -0
  126. package/src/main/loginItemIpc.cjs +35 -0
  127. package/src/main/loopEfficiencyHandlers.cjs +10 -1
  128. package/src/main/projectPages.cjs +6 -15
  129. package/src/main/promptSessionEvents.cjs +9 -1
  130. package/src/main/queueOps.cjs +260 -3
  131. package/src/main/runVerify.cjs +53 -25
  132. package/src/main/scheduler/AGENTS.md +26 -0
  133. package/src/main/scheduler/CLAUDE.md +1 -26
  134. package/src/main/scheduler/budget.cjs +239 -9
  135. package/src/main/scheduler/cancelDependents.cjs +154 -0
  136. package/src/main/scheduler/prdParser.cjs +4 -1
  137. package/src/main/scheduler/starvation.cjs +20 -18
  138. package/src/main/scheduler.cjs +745 -64
  139. package/src/main/supervisor.cjs +5 -1
  140. package/src/main/templates/PRD_AUTHORING.md +6 -1
  141. package/src/main/validationQualityHandlers.cjs +199 -0
  142. package/src/main/webRemote.cjs +10 -2
  143. package/src/preload/api.d.ts +364 -21
  144. package/src/preload/apiSurface.json +89 -10
  145. package/src/preload/index.cjs +23 -2
  146. package/src/seed/agents/validator.md +19 -8
  147. package/dist/assets/AppSettings-CUfWY9vN.js +0 -2
  148. package/dist/assets/History-DDnqaLyw.js +0 -2
  149. package/dist/assets/Scheduler-NLs08fx7.js +0 -16
  150. package/dist/assets/index-C-d0DCre.js +0 -3124
@@ -0,0 +1,282 @@
1
+ /**
2
+ * validationQuality.cjs — pure calculator for the validator's quality numbers,
3
+ * per project, each with the PRD slugs behind it:
4
+ * - firstPass: share of judged work PRDs whose EARLIEST verdict is VERIFIED
5
+ * - refuted: share of judged work PRDs with ANY REFUTED verdict
6
+ * - fixWaves: fix-wave plans per original plan (a plan = a non-sweep
7
+ * validator row + its dependsOn; a fix wave = a plan holding a
8
+ * row with `fixes`)
9
+ * - escapes: a fix row naming a PRD whose newest verdict strictly before
10
+ * the fix row's creation was VERIFIED (the validator missed it)
11
+ * - week: the 7 days ending at nowMs — miss kinds counted over REFUTED
12
+ * verdicts and escapes, the top one, and one proposed standard
13
+ * check for a human to approve. A REFUTED verdict with no
14
+ * missKinds array (written before checked JSON verdicts) is
15
+ * unclassified: listed in week.unclassified, never ranked.
16
+ *
17
+ * No cost or usage numbers — those stay in loopEfficiency.cjs.
18
+ * Pure: no I/O, no Date.now(), no mutation of inputs.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ const path = require('path');
24
+ const { bareSlug } = require('../prd/depSlugResolve.cjs');
25
+ const { isSweepValidatorSlug } = require('../epic/epicSweepValidator.cjs');
26
+ const { MISS_KINDS } = require('./validatorVerdictSchema.cjs');
27
+ const { refutedReason } = require('../epic/epicOutsideState.cjs');
28
+
29
+ const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
30
+
31
+ /** One proposed standard check per miss kind, in MISS_KINDS order. */
32
+ const PROPOSED_CHECKS = Object.freeze({
33
+ 'not-landed': 'Before VERIFIED, confirm the PRD\'s commit is on the branch and its diff touches the files the criteria name.',
34
+ 'gate-red': 'Before VERIFIED, re-run every gate command yourself and cite its exit code and last lines as evidence.',
35
+ 'behavior-wrong': 'Before VERIFIED, exercise each criterion\'s behavior directly and cite the observed output next to the criterion text.',
36
+ 'not-checked-live': 'Before VERIFIED on a UI or data change, run it against real data or the live page and cite that output as evidence.',
37
+ 'missing-test': 'Before VERIFIED, name the test that checks each criterion and refute any criterion that has none.',
38
+ regression: 'Before VERIFIED, run the full test suite of every module the diff touches, not only the PRD\'s own test.',
39
+ 'spec-gap': 'Before VERIFIED, restate the PRD\'s goal and check it is met end to end, not only criterion by criterion.',
40
+ security: 'Before VERIFIED, review the diff for new input paths, shell calls, secrets and permission changes and cite what was checked.',
41
+ 'docs-drift': 'Before VERIFIED, grep the docs for every renamed or changed name in the diff and confirm they still match the code.',
42
+ other: 'Before VERIFIED, list what was checked for each criterion and how, so a later miss can be traced to a missing step.',
43
+ });
44
+
45
+ /** @param {unknown} t @returns {number} NaN when unparseable */
46
+ function toMs(t) {
47
+ if (typeof t === 'number') return Number.isFinite(t) ? t : NaN;
48
+ if (typeof t === 'string' && t) {
49
+ const n = Date.parse(t);
50
+ return Number.isFinite(n) ? n : NaN;
51
+ }
52
+ return NaN;
53
+ }
54
+
55
+ /** @param {any} r */
56
+ function rowCreatedMs(r) {
57
+ for (const k of ['createdAt', 'enqueuedAt', 'issuedAt']) {
58
+ const ms = toMs(r && r[k]);
59
+ if (Number.isFinite(ms)) return ms;
60
+ }
61
+ return NaN;
62
+ }
63
+
64
+ /** @param {unknown} k @returns {string} */
65
+ function normMissKind(k) {
66
+ return typeof k === 'string' && MISS_KINDS.includes(/** @type {any} */ (k)) ? k : 'other';
67
+ }
68
+
69
+ /** @param {number} num @param {number} den */
70
+ function pct(num, den) {
71
+ return den > 0 ? Math.round((num / den) * 1000) / 10 : null;
72
+ }
73
+
74
+ /** @param {Iterable<string>} xs */
75
+ function sortedUnique(xs) {
76
+ return [...new Set(xs)].sort();
77
+ }
78
+
79
+ /** @param {unknown} list @returns {string[]} */
80
+ function bareList(list) {
81
+ return Array.isArray(list) ? list.filter((s) => typeof s === 'string' && s).map(bareSlug) : [];
82
+ }
83
+
84
+ /** @param {any} r */
85
+ function isValidatorRow(r) {
86
+ return !!r && (r.agentType === 'validator' || bareSlug(r.slug).startsWith('validate-'));
87
+ }
88
+
89
+ /**
90
+ * @param {{ epics?: Array<{ cwd: string, epicId?: string, events?: any[] }>, rows?: any[], nowMs: number }} input
91
+ */
92
+ function computeValidationQuality({ epics, rows, nowMs }) {
93
+ /** @type {Map<string, { cwd: string, verdicts: Map<string, Array<{ at: number, verdict: 'verified'|'refuted', reason: string|null, missKinds: string[], legacy: boolean, validator: string|null }>>, rows: any[] }>} */
94
+ const byCwd = new Map();
95
+ const bucket = (/** @type {string} */ cwd) => {
96
+ let b = byCwd.get(cwd);
97
+ if (!b) {
98
+ b = { cwd, verdicts: new Map(), rows: [] };
99
+ byCwd.set(cwd, b);
100
+ }
101
+ return b;
102
+ };
103
+
104
+ for (const e of epics || []) {
105
+ if (!e || typeof e.cwd !== 'string') continue;
106
+ const b = bucket(e.cwd);
107
+ for (const ev of e.events || []) {
108
+ if (!ev || ev.kind !== 'response' || typeof ev.prdSlug !== 'string' || !ev.prdSlug) continue;
109
+ const verdict = String(ev.validation || '').toLowerCase();
110
+ if (verdict !== 'verified' && verdict !== 'refuted') continue;
111
+ const at = toMs(ev.at);
112
+ if (!Number.isFinite(at)) continue;
113
+ const key = bareSlug(ev.prdSlug);
114
+ let list = b.verdicts.get(key);
115
+ if (!list) b.verdicts.set(key, (list = []));
116
+ list.push({
117
+ at,
118
+ verdict,
119
+ reason: (typeof ev.reason === 'string' && ev.reason) || refutedReason(ev.text) || null,
120
+ missKinds: Array.isArray(ev.missKinds) ? ev.missKinds : [],
121
+ legacy: !Array.isArray(ev.missKinds),
122
+ validator: typeof ev.validator === 'string' && ev.validator ? ev.validator : null,
123
+ });
124
+ }
125
+ }
126
+ for (const r of rows || []) {
127
+ if (!r || typeof r.cwd !== 'string' || typeof r.slug !== 'string') continue;
128
+ bucket(r.cwd).rows.push(r);
129
+ }
130
+
131
+ const fromMs = nowMs - WEEK_MS;
132
+ const inWeek = (/** @type {number} */ t) => t > fromMs && t <= nowMs;
133
+
134
+ const projects = [];
135
+ for (const b of byCwd.values()) {
136
+ for (const list of b.verdicts.values()) list.sort((x, y) => x.at - y.at);
137
+
138
+ /** @type {Map<string, any>} */
139
+ const rowByBare = new Map();
140
+ for (const r of b.rows) if (!rowByBare.has(bareSlug(r.slug))) rowByBare.set(bareSlug(r.slug), r);
141
+ const isValidatorBare = (/** @type {string} */ s) =>
142
+ s.startsWith('validate-') || isValidatorRow(rowByBare.get(s));
143
+
144
+ // --- firstPass / refuted -------------------------------------------------
145
+ let judged = 0;
146
+ const firstPassPrds = [];
147
+ const refutedPrds = [];
148
+ for (const [slug, list] of b.verdicts) {
149
+ if (isValidatorBare(slug) || list.length === 0) continue;
150
+ judged += 1;
151
+ if (list[0].verdict === 'verified') firstPassPrds.push(slug);
152
+ if (list.some((x) => x.verdict === 'refuted')) refutedPrds.push(slug);
153
+ }
154
+
155
+ // --- plans and fix waves -------------------------------------------------
156
+ /** @type {Map<string, string[]>} plan (bare validator slug) -> member bare slugs */
157
+ const plans = new Map();
158
+ for (const r of b.rows) {
159
+ if (!isValidatorRow(r) || isSweepValidatorSlug(r.slug)) continue;
160
+ const key = bareSlug(r.slug);
161
+ const members = plans.get(key) || [];
162
+ plans.set(key, sortedUnique([...members, ...bareList(r.dependsOn)]));
163
+ }
164
+ const fixTargetsOf = (/** @type {string} */ plan) =>
165
+ (plans.get(plan) || []).flatMap((m) => bareList(rowByBare.get(m) && rowByBare.get(m).fixes));
166
+ const isFixWave = (/** @type {string} */ plan) => fixTargetsOf(plan).length > 0;
167
+
168
+ /** Original (non-fix-wave) plans a plan's fixes trace back to. */
169
+ const originsOf = (/** @type {string} */ plan, /** @type {Set<string>} */ seen) => {
170
+ if (seen.has(plan)) return [];
171
+ seen.add(plan);
172
+ if (!isFixWave(plan)) return [plan];
173
+ const out = [];
174
+ for (const target of fixTargetsOf(plan)) {
175
+ for (const [other, members] of plans) {
176
+ if (other !== plan && members.includes(target)) out.push(...originsOf(other, seen));
177
+ }
178
+ }
179
+ return out;
180
+ };
181
+
182
+ /** @type {Map<string, Set<string>>} */
183
+ const wavesByOrigin = new Map();
184
+ let fixWavePlans = 0;
185
+ for (const plan of plans.keys()) if (!isFixWave(plan)) wavesByOrigin.set(plan, new Set());
186
+ for (const plan of plans.keys()) {
187
+ if (!isFixWave(plan)) continue;
188
+ fixWavePlans += 1;
189
+ for (const origin of originsOf(plan, new Set())) {
190
+ const set = wavesByOrigin.get(origin);
191
+ if (set) set.add(plan);
192
+ }
193
+ }
194
+ const originalPlans = wavesByOrigin.size;
195
+ const fixWaves = {
196
+ perPlan: originalPlans > 0 ? Math.round((fixWavePlans / originalPlans) * 100) / 100 : null,
197
+ plans: [...wavesByOrigin.keys()].sort().map((plan) => ({ plan, fixWaves: sortedUnique(/** @type {Set<string>} */ (wavesByOrigin.get(plan))) })),
198
+ };
199
+
200
+ // --- escapes -------------------------------------------------------------
201
+ const escapes = [];
202
+ for (const r of b.rows) {
203
+ const targets = sortedUnique(bareList(r.fixes));
204
+ if (targets.length === 0) continue;
205
+ const created = rowCreatedMs(r);
206
+ if (!Number.isFinite(created)) continue;
207
+ for (const target of targets) {
208
+ const list = b.verdicts.get(target) || [];
209
+ let newest = null;
210
+ for (const x of list) if (x.at < created) newest = x;
211
+ if (!newest || newest.verdict !== 'verified') continue;
212
+ escapes.push({
213
+ fixPrd: bareSlug(r.slug),
214
+ escapedPrd: target,
215
+ verifiedBy: newest.validator,
216
+ missKind: normMissKind(r.missKind ?? (Array.isArray(r.missKinds) ? r.missKinds[0] : undefined)),
217
+ reason: typeof r.reason === 'string' && r.reason ? r.reason : null,
218
+ at: created,
219
+ });
220
+ }
221
+ }
222
+ escapes.sort((x, y) => x.at - y.at || (x.fixPrd < y.fixPrd ? -1 : x.fixPrd > y.fixPrd ? 1 : 0) || (x.escapedPrd < y.escapedPrd ? -1 : 1));
223
+
224
+ // --- week ----------------------------------------------------------------
225
+ /** @type {Record<string, number>} */
226
+ const missKinds = Object.fromEntries(MISS_KINDS.map((k) => [k, 0]));
227
+ /** @type {Map<string, { prds: string[], reasons: string[] }>} */
228
+ const detail = new Map(MISS_KINDS.map((k) => [k, { prds: [], reasons: [] }]));
229
+ const note = (/** @type {string} */ kind, /** @type {string} */ prd, /** @type {string|null} */ reason) => {
230
+ missKinds[kind] += 1;
231
+ const d = /** @type {{ prds: string[], reasons: string[] }} */ (detail.get(kind));
232
+ d.prds.push(prd);
233
+ if (reason && !d.reasons.includes(reason)) d.reasons.push(reason);
234
+ };
235
+ let unclassifiedCount = 0;
236
+ const unclassifiedPrds = [];
237
+ const unclassifiedReasons = [];
238
+ for (const [slug, list] of b.verdicts) {
239
+ for (const x of list) {
240
+ if (x.verdict !== 'refuted' || !inWeek(x.at)) continue;
241
+ if (x.legacy) {
242
+ unclassifiedCount += 1;
243
+ unclassifiedPrds.push(slug);
244
+ if (x.reason && !unclassifiedReasons.includes(x.reason)) unclassifiedReasons.push(x.reason);
245
+ continue;
246
+ }
247
+ const kinds = x.missKinds.length ? [...new Set(x.missKinds.map(normMissKind))] : ['other'];
248
+ for (const k of kinds) note(k, slug, x.reason);
249
+ }
250
+ }
251
+ for (const e of escapes) if (inWeek(e.at)) note(e.missKind, e.escapedPrd, e.reason);
252
+
253
+ let topMiss = null;
254
+ for (const k of MISS_KINDS) {
255
+ if (missKinds[k] > 0 && (!topMiss || missKinds[k] > topMiss.count)) {
256
+ const d = /** @type {{ prds: string[], reasons: string[] }} */ (detail.get(k));
257
+ topMiss = { missKind: k, count: missKinds[k], prds: sortedUnique(d.prds), reasons: d.reasons.slice(0, 5), proposal: PROPOSED_CHECKS[k] };
258
+ }
259
+ }
260
+
261
+ projects.push({
262
+ cwd: b.cwd,
263
+ project: path.basename(b.cwd),
264
+ firstPass: { pct: pct(firstPassPrds.length, judged), prds: sortedUnique(firstPassPrds) },
265
+ refuted: { pct: pct(refutedPrds.length, judged), prds: sortedUnique(refutedPrds) },
266
+ fixWaves,
267
+ escapes,
268
+ week: {
269
+ fromMs,
270
+ toMs: nowMs,
271
+ missKinds,
272
+ topMiss,
273
+ unclassified: { count: unclassifiedCount, prds: sortedUnique(unclassifiedPrds), reasons: unclassifiedReasons.slice(0, 5) },
274
+ },
275
+ });
276
+ }
277
+
278
+ projects.sort((a, b) => (a.project < b.project ? -1 : a.project > b.project ? 1 : a.cwd < b.cwd ? -1 : 1));
279
+ return { projects };
280
+ }
281
+
282
+ module.exports = { computeValidationQuality, PROPOSED_CHECKS };
@@ -0,0 +1,254 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * validatorVerdictSchema.cjs — the JSON Schema a plan-level validator run must
5
+ * return through `claude -p --json-schema`, the closed list of miss kinds used
6
+ * to group what it finds, and a checker that turns the CLI's
7
+ * `structured_output` into verdict rows (the parseValidationSentinels row
8
+ * shape plus `missKinds`).
9
+ *
10
+ * The CLI enforces the schema itself; parseValidatorVerdict is the defensive
11
+ * second check plus the rules a schema cannot express: a non-empty REFUTED
12
+ * reason, unique `prd` values, and at least one missKind on every REFUTED
13
+ * entry.
14
+ *
15
+ * Pure: no I/O, no dependencies, never throws, never mutates its input.
16
+ */
17
+
18
+ /** @typedef {'not-landed'|'gate-red'|'behavior-wrong'|'not-checked-live'|'missing-test'|'regression'|'spec-gap'|'security'|'docs-drift'|'other'} MissKind */
19
+ /** @typedef {'Critical'|'Important'|'Minor'} Severity */
20
+ /** @typedef {{ id: string, met: boolean, evidence: string, missKind?: MissKind }} Criterion */
21
+ /** @typedef {{ severity: Severity, text: string, file?: string, missKind?: MissKind }} Finding */
22
+ /** @typedef {{ prd: string, verdict: 'VERIFIED'|'REFUTED', reason: string, criteria: Criterion[], findings: Finding[] }} VerdictEntry */
23
+ /** @typedef {{ schedulerVerdict: 'PASS'|'FAIL', failReason?: string, verdicts: VerdictEntry[] }} ValidatorVerdict */
24
+ /** @typedef {{ slug: string, verdict: 'verified'|'refuted', reason: string, missKinds: MissKind[] }} VerdictRow */
25
+
26
+ /** One-line meaning per miss kind, in MISS_KINDS order. */
27
+ const MISS_KIND_MEANINGS = Object.freeze({
28
+ 'not-landed': 'nothing or the wrong thing was committed',
29
+ 'gate-red': 'a gate command fails',
30
+ 'behavior-wrong': 'runs but does not do what a criterion says',
31
+ 'not-checked-live': 'passes tests, wrong against real data or the real UI',
32
+ 'missing-test': 'a criterion or change has no test that checks it',
33
+ regression: 'breaks something that worked',
34
+ 'spec-gap': 'every criterion met but the goal is not',
35
+ security: 'introduces a security problem',
36
+ 'docs-drift': 'docs no longer match the code',
37
+ other: 'none of the above',
38
+ });
39
+
40
+ /** @type {ReadonlyArray<MissKind>} */
41
+ const MISS_KINDS = Object.freeze(/** @type {MissKind[]} */ (Object.keys(MISS_KIND_MEANINGS)));
42
+
43
+ /** @type {ReadonlyArray<Severity>} */
44
+ const SEVERITIES = Object.freeze(/** @type {Severity[]} */ (['Critical', 'Important', 'Minor']));
45
+
46
+ const MISS_KIND_DESCRIPTION =
47
+ 'Kind of miss: ' + MISS_KINDS.map((k) => `${k} = ${MISS_KIND_MEANINGS[k]}`).join('; ') + '.';
48
+
49
+ const VALIDATOR_VERDICT_SCHEMA = {
50
+ type: 'object',
51
+ description: 'Result of one validator run over a finished plan: one entry per judged PRD.',
52
+ additionalProperties: false,
53
+ required: ['schedulerVerdict', 'verdicts'],
54
+ properties: {
55
+ schedulerVerdict: {
56
+ type: 'string',
57
+ enum: ['PASS', 'FAIL'],
58
+ description: 'PASS when the validator run itself completed; FAIL when it could not judge the plan.',
59
+ },
60
+ failReason: { type: 'string', description: 'Why the run is FAIL.' },
61
+ verdicts: {
62
+ type: 'array',
63
+ items: {
64
+ type: 'object',
65
+ additionalProperties: false,
66
+ required: ['prd', 'verdict', 'reason', 'criteria', 'findings'],
67
+ properties: {
68
+ prd: { type: 'string', minLength: 1, description: 'Slug of the judged PRD, e.g. 3612-validator-verdict-schema.' },
69
+ verdict: { type: 'string', enum: ['VERIFIED', 'REFUTED'] },
70
+ reason: { type: 'string', description: 'One line; required (non-empty) when REFUTED.' },
71
+ criteria: {
72
+ type: 'array',
73
+ description: "One entry per item of the judged PRD's # Acceptance criteria list.",
74
+ items: {
75
+ type: 'object',
76
+ additionalProperties: false,
77
+ required: ['id', 'met', 'evidence'],
78
+ properties: {
79
+ id: {
80
+ type: 'string',
81
+ description: "The criterion's 1-based position in the judged PRD's # Acceptance criteria list, as a string ('1', '2', ...).",
82
+ },
83
+ met: { type: 'boolean' },
84
+ evidence: { type: 'string', description: 'What was checked and what it showed.' },
85
+ missKind: { type: 'string', enum: [...MISS_KINDS], description: MISS_KIND_DESCRIPTION + ' Set it on every unmet criterion.' },
86
+ },
87
+ },
88
+ },
89
+ findings: {
90
+ type: 'array',
91
+ items: {
92
+ type: 'object',
93
+ additionalProperties: false,
94
+ required: ['severity', 'text'],
95
+ properties: {
96
+ severity: { type: 'string', enum: [...SEVERITIES] },
97
+ text: { type: 'string' },
98
+ file: { type: 'string', description: 'Repo-relative path the finding is about.' },
99
+ missKind: { type: 'string', enum: [...MISS_KINDS], description: 'Kind of miss (same list as criteria[].missKind).' },
100
+ },
101
+ },
102
+ },
103
+ },
104
+ },
105
+ },
106
+ },
107
+ };
108
+
109
+ /** @param {unknown} v @returns {v is Record<string, unknown>} */
110
+ function isPlainObject(v) {
111
+ return typeof v === 'object' && v !== null && !Array.isArray(v);
112
+ }
113
+
114
+ /**
115
+ * @param {Record<string, unknown>} obj
116
+ * @param {string[]} required
117
+ * @param {string[]} allowed
118
+ * @param {string} where
119
+ * @returns {string|null}
120
+ */
121
+ function checkKeys(obj, required, allowed, where) {
122
+ for (const k of required) if (!(k in obj)) return `${where}: missing ${k}`;
123
+ for (const k of Object.keys(obj)) if (!allowed.includes(k)) return `${where}: unexpected key ${k}`;
124
+ return null;
125
+ }
126
+
127
+ /** @param {unknown} v @param {string} where @returns {string|null} */
128
+ function checkMissKind(v, where) {
129
+ if (v === undefined) return null;
130
+ return MISS_KINDS.includes(/** @type {MissKind} */ (v)) ? null : `${where}.missKind: not one of ${MISS_KINDS.join(', ')}`;
131
+ }
132
+
133
+ /** @param {unknown} c @param {string} where @returns {string|null} */
134
+ function checkCriterion(c, where) {
135
+ if (!isPlainObject(c)) return `${where}: not an object`;
136
+ const keyErr = checkKeys(c, ['id', 'met', 'evidence'], ['id', 'met', 'evidence', 'missKind'], where);
137
+ if (keyErr) return keyErr;
138
+ if (typeof c.id !== 'string') return `${where}.id: not a string`;
139
+ if (typeof c.met !== 'boolean') return `${where}.met: not a boolean`;
140
+ if (typeof c.evidence !== 'string') return `${where}.evidence: not a string`;
141
+ return checkMissKind(c.missKind, where);
142
+ }
143
+
144
+ /** @param {unknown} f @param {string} where @returns {string|null} */
145
+ function checkFinding(f, where) {
146
+ if (!isPlainObject(f)) return `${where}: not an object`;
147
+ const keyErr = checkKeys(f, ['severity', 'text'], ['severity', 'text', 'file', 'missKind'], where);
148
+ if (keyErr) return keyErr;
149
+ if (!SEVERITIES.includes(/** @type {Severity} */ (f.severity))) return `${where}.severity: not one of ${SEVERITIES.join(', ')}`;
150
+ if (typeof f.text !== 'string') return `${where}.text: not a string`;
151
+ if (f.file !== undefined && typeof f.file !== 'string') return `${where}.file: not a string`;
152
+ return checkMissKind(f.missKind, where);
153
+ }
154
+
155
+ /**
156
+ * Miss kinds of one entry: from its unmet criteria and all its findings,
157
+ * deduped and sorted.
158
+ * @param {VerdictEntry} entry
159
+ * @returns {MissKind[]}
160
+ */
161
+ function entryMissKinds(entry) {
162
+ /** @type {Set<MissKind>} */
163
+ const kinds = new Set();
164
+ for (const c of entry.criteria) if (!c.met && c.missKind) kinds.add(c.missKind);
165
+ for (const f of entry.findings) if (f.missKind) kinds.add(f.missKind);
166
+ return [...kinds].sort();
167
+ }
168
+
169
+ /** @param {unknown} e @param {string} where @returns {string|null} */
170
+ function checkEntry(e, where) {
171
+ if (!isPlainObject(e)) return `${where}: not an object`;
172
+ const keyErr = checkKeys(e, ['prd', 'verdict', 'reason', 'criteria', 'findings'], ['prd', 'verdict', 'reason', 'criteria', 'findings'], where);
173
+ if (keyErr) return keyErr;
174
+ if (typeof e.prd !== 'string' || e.prd.length < 1) return `${where}.prd: not a non-empty string`;
175
+ if (e.verdict !== 'VERIFIED' && e.verdict !== 'REFUTED') return `${where}.verdict: not VERIFIED or REFUTED`;
176
+ if (typeof e.reason !== 'string') return `${where}.reason: not a string`;
177
+ if (!Array.isArray(e.criteria)) return `${where}.criteria: not an array`;
178
+ if (!Array.isArray(e.findings)) return `${where}.findings: not an array`;
179
+ for (let i = 0; i < e.criteria.length; i++) {
180
+ const err = checkCriterion(e.criteria[i], `${where}.criteria[${i}]`);
181
+ if (err) return err;
182
+ }
183
+ for (let i = 0; i < e.findings.length; i++) {
184
+ const err = checkFinding(e.findings[i], `${where}.findings[${i}]`);
185
+ if (err) return err;
186
+ }
187
+ if (e.verdict === 'REFUTED') {
188
+ if (e.reason.trim() === '') return `${where} (${e.prd}): REFUTED with an empty reason`;
189
+ if (entryMissKinds(/** @type {VerdictEntry} */ (/** @type {unknown} */ (e))).length === 0) {
190
+ return `${where} (${e.prd}): REFUTED with no missKind on any unmet criterion or finding`;
191
+ }
192
+ }
193
+ return null;
194
+ }
195
+
196
+ /**
197
+ * parseValidatorVerdict(value) → { ok: true, value } | { ok: false, error }.
198
+ * Never throws.
199
+ * @param {unknown} value
200
+ * @returns {{ ok: true, value: ValidatorVerdict } | { ok: false, error: string }}
201
+ */
202
+ function parseValidatorVerdict(value) {
203
+ try {
204
+ if (!isPlainObject(value)) return { ok: false, error: 'verdict: not an object' };
205
+ const keyErr = checkKeys(value, ['schedulerVerdict', 'verdicts'], ['schedulerVerdict', 'failReason', 'verdicts'], 'verdict');
206
+ if (keyErr) return { ok: false, error: keyErr };
207
+ if (value.schedulerVerdict !== 'PASS' && value.schedulerVerdict !== 'FAIL') {
208
+ return { ok: false, error: 'schedulerVerdict: not PASS or FAIL' };
209
+ }
210
+ if (value.failReason !== undefined && typeof value.failReason !== 'string') {
211
+ return { ok: false, error: 'failReason: not a string' };
212
+ }
213
+ if (!Array.isArray(value.verdicts)) return { ok: false, error: 'verdicts: not an array' };
214
+ /** @type {Set<string>} */
215
+ const seen = new Set();
216
+ for (let i = 0; i < value.verdicts.length; i++) {
217
+ const where = `verdicts[${i}]`;
218
+ const err = checkEntry(value.verdicts[i], where);
219
+ if (err) return { ok: false, error: err };
220
+ const prd = /** @type {VerdictEntry} */ (value.verdicts[i]).prd;
221
+ if (seen.has(prd)) return { ok: false, error: `${where}.prd: duplicate ${prd}` };
222
+ seen.add(prd);
223
+ }
224
+ return { ok: true, value: /** @type {ValidatorVerdict} */ (/** @type {unknown} */ (value)) };
225
+ } catch (err) {
226
+ return { ok: false, error: `verdict: ${err instanceof Error ? err.message : String(err)}` };
227
+ }
228
+ }
229
+
230
+ /**
231
+ * verdictRowsFromStructured(value) → VerdictRow[] in input order; [] when the
232
+ * value does not pass parseValidatorVerdict.
233
+ * @param {unknown} value
234
+ * @returns {VerdictRow[]}
235
+ */
236
+ function verdictRowsFromStructured(value) {
237
+ const parsed = parseValidatorVerdict(value);
238
+ if (!parsed.ok) return [];
239
+ return parsed.value.verdicts.map((e) => ({
240
+ slug: e.prd,
241
+ verdict: e.verdict === 'VERIFIED' ? 'verified' : 'refuted',
242
+ reason: e.reason,
243
+ missKinds: entryMissKinds(e),
244
+ }));
245
+ }
246
+
247
+ module.exports = {
248
+ VALIDATOR_VERDICT_SCHEMA,
249
+ MISS_KINDS,
250
+ MISS_KIND_MEANINGS,
251
+ SEVERITIES,
252
+ parseValidatorVerdict,
253
+ verdictRowsFromStructured,
254
+ };