@webpieces/rules-config 0.4.480 → 0.4.482
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.
- package/package.json +1 -1
- package/src/checklist-config.d.ts +32 -1
- package/src/checklist-config.js +86 -11
- package/src/checklist-config.js.map +1 -1
- package/src/checklist-instructions.d.ts +35 -0
- package/src/checklist-instructions.js +110 -0
- package/src/checklist-instructions.js.map +1 -0
- package/src/checklist-manifest.d.ts +26 -7
- package/src/checklist-manifest.js +88 -28
- package/src/checklist-manifest.js.map +1 -1
- package/src/index.d.ts +3 -2
- package/src/index.js +9 -3
- package/src/index.js.map +1 -1
- package/src/pr-gate-config.d.ts +3 -2
- package/src/pr-gate-config.js +30 -14
- package/src/pr-gate-config.js.map +1 -1
- package/src/pr-gate-section-validators.d.ts +22 -0
- package/src/pr-gate-section-validators.js +93 -0
- package/src/pr-gate-section-validators.js.map +1 -0
- package/src/review-json.d.ts +29 -4
- package/src/review-json.js +71 -38
- package/src/review-json.js.map +1 -1
- package/src/validate-config.d.ts +2 -1
- package/src/validate-config.js +24 -33
- package/src/validate-config.js.map +1 -1
- package/templates/webpieces.review-checklists.md +44 -5
package/src/review-json.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReviewJsonService = exports.PrContext = exports.ChecklistVerdict = exports.CK_MISSING = exports.CK_FAIL = exports.CK_OVERRIDDEN = exports.CK_PASS = exports.ReviewJson = exports.RequiredChecklist = exports.ChecklistResult = void 0;
|
|
3
|
+
exports.ReviewJsonService = exports.PrContext = exports.ChecklistVerdict = exports.CK_MISSING = exports.CK_FAIL = exports.CK_OVERRIDDEN = exports.CK_PASS = exports.ReviewJson = exports.ChecklistReviewContext = exports.RequiredChecklist = exports.ChecklistResult = void 0;
|
|
4
4
|
exports.prDirFor = prDirFor;
|
|
5
5
|
exports.reviewJsonPath = reviewJsonPath;
|
|
6
6
|
exports.reviewJsonSchemaHint = reviewJsonSchemaHint;
|
|
@@ -39,16 +39,37 @@ exports.ChecklistResult = ChecklistResult;
|
|
|
39
39
|
class RequiredChecklist {
|
|
40
40
|
id; // = subagent name; keys review-<id>.json
|
|
41
41
|
subagent; // reviewer agent that must run (agentType the harness stamps)
|
|
42
|
-
doc; // guidance doc the reviewer reads ('' → it reads the manifest doc)
|
|
42
|
+
doc; // REPO-RELATIVE guidance doc the reviewer reads ('' → it reads the manifest doc)
|
|
43
43
|
matchedFiles; // the changed files that matched it (for the dashboard + hint)
|
|
44
|
-
|
|
44
|
+
// Which of the checklist's OWN globs actually fired. Printed so a reviewer can judge how coarse the
|
|
45
|
+
// match was — a precise `db/migrations/**` hit means something different from a blanket `**` — and the
|
|
46
|
+
// template tells reviewers that matching IS deliberately coarse. [] = no patterns (matches every PR).
|
|
47
|
+
matchedPatterns;
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
49
|
+
constructor(id, subagent, doc, matchedFiles, matchedPatterns = []) {
|
|
45
50
|
this.id = id;
|
|
46
51
|
this.subagent = subagent;
|
|
47
52
|
this.doc = doc;
|
|
48
53
|
this.matchedFiles = matchedFiles;
|
|
54
|
+
this.matchedPatterns = matchedPatterns;
|
|
49
55
|
}
|
|
50
56
|
}
|
|
51
57
|
exports.RequiredChecklist = RequiredChecklist;
|
|
58
|
+
/**
|
|
59
|
+
* The per-PR facts every reviewer subagent needs GIVEN to it, alongside its own checklist: the exact base
|
|
60
|
+
* sha the gate diffs against and the file holding the complete changed-file set. Both used to live only in
|
|
61
|
+
* a doc the printed instruction told the AI to go read, one indirection away from the instruction to hand
|
|
62
|
+
* them over — so the printed block could not stand on its own. Data-only; empty = omit those lines.
|
|
63
|
+
*/
|
|
64
|
+
class ChecklistReviewContext {
|
|
65
|
+
baseSha; // the 3-point merge-base sha; `git diff <baseSha> HEAD -- <file>`
|
|
66
|
+
prContextPath; // path of pr-context.json — the AUTHORITATIVE full changed-file set
|
|
67
|
+
constructor(baseSha = '', prContextPath = '') {
|
|
68
|
+
this.baseSha = baseSha;
|
|
69
|
+
this.prContextPath = prContextPath;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.ChecklistReviewContext = ChecklistReviewContext;
|
|
52
73
|
// The AI-authored review for a PR. The AI writes review.json itself between `wp-start-upsert-pr` (which
|
|
53
74
|
// prints the schema) and `wp-finish-upsert-pr` (which reads it); reviewer subagents write the per-checklist
|
|
54
75
|
// review-<id>.json files. Data-only (per CLAUDE.md).
|
|
@@ -132,10 +153,34 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
132
153
|
fs.writeFileSync(p, JSON.stringify(context, null, 2) + '\n');
|
|
133
154
|
return p;
|
|
134
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* The review context for a feature, recovered from the pr-context.json wp-start-upsert-pr already wrote.
|
|
158
|
+
* Lets wp-finish-upsert-pr's "you still owe me review-<id>.json" message inline the SAME self-sufficient
|
|
159
|
+
* per-reviewer block start printed, instead of a checklist name and an indirection. Empty when the file
|
|
160
|
+
* is absent or unreadable — the block then just omits those lines.
|
|
161
|
+
*/
|
|
162
|
+
reviewContextFor(repoRoot, featureName) {
|
|
163
|
+
const p = this.prContextPath(repoRoot, featureName);
|
|
164
|
+
if (!fs.existsSync(p))
|
|
165
|
+
return new ChecklistReviewContext();
|
|
166
|
+
// webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable context file degrades to fewer printed lines, never a crash
|
|
167
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
168
|
+
try {
|
|
169
|
+
// webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed on the next line
|
|
170
|
+
const raw = JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
171
|
+
const base = typeof raw['base'] === 'string' ? raw['base'] : '';
|
|
172
|
+
return new ChecklistReviewContext(base, p);
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
const error = (0, to_error_1.toError)(err);
|
|
176
|
+
void error;
|
|
177
|
+
return new ChecklistReviewContext('', p);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
135
180
|
// Copy-paste schema both commands print. `required` is the set of checklists the diff MATCHED; empty
|
|
136
181
|
// ⇒ output identical to a repo with no checklists. Non-empty ⇒ appends per-checklist instructions
|
|
137
182
|
// naming the reviewer subagent + doc + the review-<id>.json to write.
|
|
138
|
-
reviewJsonSchemaHint(filePath
|
|
183
|
+
reviewJsonSchemaHint(filePath) {
|
|
139
184
|
return (`Write your PR review to:\n ${filePath}\n\n` +
|
|
140
185
|
`with this exact JSON shape (riskEmoji optional — derived from riskLevel):\n\n` +
|
|
141
186
|
`{\n` +
|
|
@@ -146,35 +191,12 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
146
191
|
` "violations": ["pattern/architecture violations you found (empty array if none)"],\n` +
|
|
147
192
|
` "risks": ["notable risks (empty array if none)"],\n` +
|
|
148
193
|
` "filesToReview": ["paths a human should look at (empty array if none)"]\n` +
|
|
149
|
-
`}`
|
|
150
|
-
this.requiredChecklistHint(filePath, required));
|
|
194
|
+
`}`);
|
|
151
195
|
}
|
|
152
196
|
// The per-checklist review file path that sits beside review.json: review-<id>.json.
|
|
153
197
|
checklistResultPath(reviewJsonFilePath, checklistId) {
|
|
154
198
|
return path.join(path.dirname(reviewJsonFilePath), `review-${checklistId}.json`);
|
|
155
199
|
}
|
|
156
|
-
// The matched-checklist instruction block, appended ONLY when the diff matched a checklist. Each matched
|
|
157
|
-
// checklist must be reviewed by its OWN subagent (a distinct one), which writes review-<id>.json.
|
|
158
|
-
requiredChecklistHint(reviewJsonFilePath, required) {
|
|
159
|
-
if (required.length === 0)
|
|
160
|
-
return '';
|
|
161
|
-
const lines = ['', '', 'This diff MATCHED company review checklist(s). Spawn EACH named subagent as a SEPARATE'];
|
|
162
|
-
lines.push('subagent (a different one per checklist — the coding agent may NOT self-certify). Each reads its');
|
|
163
|
-
lines.push('doc + the diff and writes its own review-<id>.json with this shape:');
|
|
164
|
-
lines.push('');
|
|
165
|
-
lines.push(' { "id": "<id>", "success": true, "output": "what you checked / found", "override": "" }');
|
|
166
|
-
lines.push(' (success:false with no non-empty "override" refuses the PR; a non-empty override ships it 🟡.)');
|
|
167
|
-
lines.push('');
|
|
168
|
-
for (const req of required) {
|
|
169
|
-
lines.push(` • [${req.id}] reviewer subagent: ${req.subagent}`);
|
|
170
|
-
lines.push(` write: ${this.checklistResultPath(reviewJsonFilePath, req.id)}`);
|
|
171
|
-
if (req.doc.trim() !== '')
|
|
172
|
-
lines.push(` doc to read: ${req.doc}`);
|
|
173
|
-
if (req.matchedFiles.length > 0)
|
|
174
|
-
lines.push(` matched: ${req.matchedFiles.slice(0, 5).join(', ')}`);
|
|
175
|
-
}
|
|
176
|
-
return lines.join('\n');
|
|
177
|
-
}
|
|
178
200
|
/**
|
|
179
201
|
* Load + validate the AI-authored review.json. Throws InformAiError (with the schema) when missing,
|
|
180
202
|
* unparseable, or structurally wrong. `required` is the set of checklists the diff matched: every one
|
|
@@ -184,12 +206,12 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
184
206
|
// webpieces-disable max-lines-new-methods -- one cohesive load+validate pass over the review fields
|
|
185
207
|
loadReviewJson(filePath, required = []) {
|
|
186
208
|
if (!fs.existsSync(filePath)) {
|
|
187
|
-
throw new inform_ai_error_1.InformAiError(`Required review.json not found.\n\n${this.reviewJsonSchemaHint(filePath
|
|
209
|
+
throw new inform_ai_error_1.InformAiError(`Required review.json not found.\n\n${this.reviewJsonSchemaHint(filePath)}\n\n` +
|
|
188
210
|
`Then re-run: pnpm wp-finish-upsert-pr`);
|
|
189
211
|
}
|
|
190
|
-
const raw = this.parseReviewJson(fs.readFileSync(filePath, 'utf8'), filePath
|
|
212
|
+
const raw = this.parseReviewJson(fs.readFileSync(filePath, 'utf8'), filePath);
|
|
191
213
|
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
192
|
-
throw new inform_ai_error_1.InformAiError(`review.json must be a JSON object.\n\n${this.reviewJsonSchemaHint(filePath
|
|
214
|
+
throw new inform_ai_error_1.InformAiError(`review.json must be a JSON object.\n\n${this.reviewJsonSchemaHint(filePath)}`);
|
|
193
215
|
}
|
|
194
216
|
const errors = [];
|
|
195
217
|
const riskScore = raw['riskScore'];
|
|
@@ -210,7 +232,7 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
210
232
|
if (errors.length > 0) {
|
|
211
233
|
throw new inform_ai_error_1.InformAiError(`review.json has ${errors.length} error(s) — fix ALL, then re-run pnpm wp-finish-upsert-pr:\n\n` +
|
|
212
234
|
errors.map((e) => ` • ${e}`).join('\n') +
|
|
213
|
-
`\n\n${this.reviewJsonSchemaHint(filePath
|
|
235
|
+
`\n\n${this.reviewJsonSchemaHint(filePath)}`);
|
|
214
236
|
}
|
|
215
237
|
const level = riskLevel;
|
|
216
238
|
const emoji = typeof raw['riskEmoji'] === 'string' && raw['riskEmoji'] !== ''
|
|
@@ -219,6 +241,18 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
219
241
|
const summary = typeof raw['summary'] === 'string' ? raw['summary'] : '';
|
|
220
242
|
return new ReviewJson(title, riskScore, level, emoji, summary, this.asStringArray(raw['violations']), this.asStringArray(raw['risks']), this.asStringArray(raw['filesToReview']), results);
|
|
221
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* The checklists that still OWE a verdict: no review-<id>.json at all, a malformed one, or one whose
|
|
246
|
+
* verdict is an un-overridden FAIL. This is the set every message lists — a checklist already PASSed or
|
|
247
|
+
* OVERRIDDEN on this branch is deliberately NOT re-listed, because re-instructing it invites a redundant
|
|
248
|
+
* second run and reads as though the earlier verdict did not count.
|
|
249
|
+
*/
|
|
250
|
+
pendingChecklists(required, results) {
|
|
251
|
+
return required.filter((req) => {
|
|
252
|
+
const status = this.resolveVerdict(req, results).status;
|
|
253
|
+
return status !== exports.CK_PASS && status !== exports.CK_OVERRIDDEN;
|
|
254
|
+
});
|
|
255
|
+
}
|
|
222
256
|
// Read the per-checklist verdict files `review-<id>.json` beside review.json — one per matched checklist.
|
|
223
257
|
// A missing file is simply absent from the result (→ counts as MISSING for that checklist); a malformed
|
|
224
258
|
// one is skipped (a stale review-<id>.json never wedges the branch).
|
|
@@ -297,10 +331,9 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
297
331
|
// webpieces-disable no-any-unknown -- element of an opaque JSON array, narrowed by the type guard
|
|
298
332
|
return value.filter((v) => typeof v === 'string');
|
|
299
333
|
}
|
|
300
|
-
// Parse opaque AI-authored JSON, converting a SyntaxError into a readable InformAiError.
|
|
301
|
-
// is threaded through so a JSON syntax error still prints the checklist instructions the AI needs.
|
|
334
|
+
// Parse opaque AI-authored JSON, converting a SyntaxError into a readable InformAiError.
|
|
302
335
|
// webpieces-disable no-any-unknown -- returns the opaque parsed object; loadReviewJson narrows each field
|
|
303
|
-
parseReviewJson(raw, filePath
|
|
336
|
+
parseReviewJson(raw, filePath) {
|
|
304
337
|
// webpieces-disable no-unmanaged-exceptions -- chokepoint: convert JSON.parse SyntaxError to an InformAiError for the AI
|
|
305
338
|
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
306
339
|
try {
|
|
@@ -309,7 +342,7 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
309
342
|
}
|
|
310
343
|
catch (err) {
|
|
311
344
|
const error = (0, to_error_1.toError)(err);
|
|
312
|
-
throw new inform_ai_error_1.InformAiError(`review.json is not valid JSON (${error.message}).\n\n${this.reviewJsonSchemaHint(filePath
|
|
345
|
+
throw new inform_ai_error_1.InformAiError(`review.json is not valid JSON (${error.message}).\n\n${this.reviewJsonSchemaHint(filePath)}\n\n` +
|
|
313
346
|
`Then re-run: pnpm wp-finish-upsert-pr`);
|
|
314
347
|
}
|
|
315
348
|
}
|
|
@@ -329,8 +362,8 @@ function reviewJsonPath(repoRoot, featureName) {
|
|
|
329
362
|
return reviewJsonSvc.reviewJsonPath(repoRoot, featureName);
|
|
330
363
|
}
|
|
331
364
|
// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it
|
|
332
|
-
function reviewJsonSchemaHint(filePath
|
|
333
|
-
return reviewJsonSvc.reviewJsonSchemaHint(filePath
|
|
365
|
+
function reviewJsonSchemaHint(filePath) {
|
|
366
|
+
return reviewJsonSvc.reviewJsonSchemaHint(filePath);
|
|
334
367
|
}
|
|
335
368
|
// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it
|
|
336
369
|
function loadReviewJson(filePath, required = []) {
|
package/src/review-json.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"review-json.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/review-json.ts"],"names":[],"mappings":";;;AA2WA,4BAEC;AAGD,wCAEC;AAGD,oDAEC;AAGD,wCAEC;;AA5XD,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAC3D,2CAA+D;AAC/D,uDAAkD;AAClD,yCAAqC;AAErC,wGAAwG;AACxG,sGAAsG;AACtG,gCAAgC;AAChC,8CAA8C;AAC9C,uGAAuG;AACvG,qFAAqF;AACrF,wGAAwG;AACxG,+FAA+F;AAC/F,MAAa,eAAe;IACxB,EAAE,CAAS;IACX,OAAO,CAAU;IACjB,MAAM,CAAS,CAAG,qEAAqE;IACvF,QAAQ,CAAS,CAAE,kFAAkF;IAErG,YAAY,EAAU,EAAE,OAAgB,EAAE,MAAc,EAAE,QAAgB;QACtE,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAZD,0CAYC;AAED,yGAAyG;AACzG,wGAAwG;AACxG,sCAAsC;AACtC,MAAa,iBAAiB;IAC1B,EAAE,CAAS,CAAa,yCAAyC;IACjE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WAAW,CAAC,CAAC;AACzD,CAAC;AAED,wIAAwI;AACxI,SAAgB,cAAc,CAAC,QAAgB,EAAE,WAAmB;IAChE,OAAO,aAAa,CAAC,cAAc,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AAC/D,CAAC;AAED,wIAAwI;AACxI,SAAgB,oBAAoB,CAAC,QAAgB,EAAE,WAAyC,EAAE;IAC9F,OAAO,aAAa,CAAC,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAClE,CAAC;AAED,wIAAwI;AACxI,SAAgB,cAAc,CAAC,QAAgB,EAAE,WAAyC,EAAE;IACxF,OAAO,aAAa,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { WEBPIECES_TMP_DIR, PR_REVIEW_DIR } from './constants';\nimport { InformAiError } from './inform-ai-error';\nimport { toError } from './to-error';\n\n// The verdict a reviewer SUBAGENT writes into `.webpieces/pr-review/<branch>/review-<id>.json`, one per\n// matched checklist. One file per checklist so N concurrent reviewer subagents never clobber a shared\n// file. It records the OUTCOME:\n// success:true → PASS\n// success:false + override non-empty → OVERRIDDEN (pass; the free-text justification reaches the PR)\n// success:false + no override → FAIL (refuse; `output` is printed verbatim)\n// `override` is deliberately free text, not a boolean — it forces the ship-anyway decision to be stated\n// in words and surfaces it on the dashboard, where a human sees it. Data-only (per CLAUDE.md).\nexport class ChecklistResult {\n id: string;\n success: boolean;\n output: string; // what the reviewer found; printed verbatim when the checklist fails\n override: string; // '' = no override; non-empty = ship-anyway justification (renders 🟡 overridden)\n\n constructor(id: string, success: boolean, output: string, override: string) {\n this.id = id;\n this.success = success;\n this.output = output;\n this.override = override;\n }\n}\n\n// What the pr-gate command computed from the diff: a checklist this branch MATCHED (its patterns hit the\n// diff, so its reviewer subagent must run). Drives review-<id>.json enforcement, provenance, the schema\n// hint, and the dashboard. Data-only.\nexport class RequiredChecklist {\n id: string; // = subagent name; keys review-<id>.json\n subagent: string; // reviewer agent that must run (agentType the harness stamps)\n doc: string; // guidance doc the reviewer reads ('' → it reads the manifest doc)\n matchedFiles: string[]; // the changed files that matched it (for the dashboard + hint)\n\n constructor(id: string, subagent: string, doc: string, matchedFiles: string[]) {\n this.id = id;\n this.subagent = subagent;\n this.doc = doc;\n this.matchedFiles = matchedFiles;\n }\n}\n\n// The AI-authored review for a PR. The AI writes review.json itself between `wp-start-upsert-pr` (which\n// prints the schema) and `wp-finish-upsert-pr` (which reads it); reviewer subagents write the per-checklist\n// review-<id>.json files. Data-only (per CLAUDE.md).\nexport class ReviewJson {\n title: string; // human PR title describing the change; used as the `gh pr` title (empty → caller falls back)\n riskScore: number; // 0–100, drives the risk bar\n riskLevel: string; // 'green' | 'yellow' | 'red'\n riskEmoji: string; // '🟢' | '🟡' | '🔴' — derived from riskLevel when omitted\n summary: string; // rendered in the dashboard Summary section\n violations: string[]; // pattern/architecture violations; length = the Pattern Violations count\n risks: string[];\n filesToReview: string[];\n results: ChecklistResult[]; // resolved per-checklist verdicts (from review-<id>.json); [] when none\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n title: string,\n riskScore: number,\n riskLevel: string,\n riskEmoji: string,\n summary: string,\n violations: string[],\n risks: string[],\n filesToReview: string[],\n results: ChecklistResult[] = [],\n ) {\n this.title = title;\n this.riskScore = riskScore;\n this.riskLevel = riskLevel;\n this.riskEmoji = riskEmoji;\n this.summary = summary;\n this.violations = violations;\n this.risks = risks;\n this.filesToReview = filesToReview;\n this.results = results;\n }\n}\n\n// A checklist's resolved outcome, shared by review.json enforcement and the dashboard so both agree.\nexport const CK_PASS = 'pass'; // review-<id>.json success:true\nexport const CK_OVERRIDDEN = 'overridden'; // review-<id>.json success:false + non-empty override → 🟡\nexport const CK_FAIL = 'fail'; // review-<id>.json success:false + no override → refuse\nexport const CK_MISSING = 'missing'; // no review-<id>.json written → refuse\n\nexport class ChecklistVerdict {\n id: string;\n status: string; // one of CK_PASS | CK_OVERRIDDEN | CK_FAIL | CK_MISSING\n detail: string; // reviewer output / override justification (for the dashboard + errors)\n\n constructor(id: string, status: string, detail: string) {\n this.id = id;\n this.status = status;\n this.detail = detail;\n }\n}\n\n// The PR's diff context, written by wp-start-upsert-pr into `.webpieces/pr-review/<branch>/pr-context.json`\n// so a reviewer subagent knows the exact 3-point base the gate used and the full changed-file set — then\n// reads any file's actual diff with `git diff <base> HEAD -- <file>`. This is what lets a checklist match\n// coarsely by path (in the manifest) while the subagent makes the fine, content-level judgment. Data-only.\nexport class PrContext {\n base: string; // the 3-point merge-base sha the gate diffs against\n head: string; // HEAD sha\n changedFiles: string[]; // every file changed base..head (NOT tsOnly — includes .sql/.gql/Dockerfile/…)\n\n constructor(base: string, head: string, changedFiles: string[]) {\n this.base = base;\n this.head = head;\n this.changedFiles = changedFiles;\n }\n}\n\nconst RISK_LEVELS = ['green', 'yellow', 'red'] as const;\nconst EMOJI_FOR_LEVEL: Record<string, string> = { green: '🟢', yellow: '🟡', red: '🔴' };\n\n/** Locates + loads/validates the AI-authored review.json. `@injectable(bindingScopeValues.Singleton)` so it's drawn in the design. */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewJsonService {\n // The per-feature PR working dir: `.webpieces/pr-review/<feature>`.\n prDirFor(repoRoot: string, featureName: string): string {\n return path.join(repoRoot, WEBPIECES_TMP_DIR, PR_REVIEW_DIR, featureName);\n }\n\n // Absolute path of the review.json for a feature — beside pr-body.md, keyed by branch name.\n reviewJsonPath(repoRoot: string, featureName: string): string {\n return path.join(this.prDirFor(repoRoot, featureName), 'review.json');\n }\n\n // Absolute path of the pr-context.json for a feature (the diff base/head + changed files).\n prContextPath(repoRoot: string, featureName: string): string {\n return path.join(this.prDirFor(repoRoot, featureName), 'pr-context.json');\n }\n\n // Persist the PR's diff context so reviewer subagents can read the changed-file set + the exact base\n // sha (then `git diff <base> HEAD -- <file>` for content). Returns the file path written.\n writePrContext(repoRoot: string, featureName: string, context: PrContext): string {\n const dir = this.prDirFor(repoRoot, featureName);\n fs.mkdirSync(dir, { recursive: true });\n const p = this.prContextPath(repoRoot, featureName);\n fs.writeFileSync(p, JSON.stringify(context, null, 2) + '\\n');\n return p;\n }\n\n // Copy-paste schema both commands print. `required` is the set of checklists the diff MATCHED; empty\n // ⇒ output identical to a repo with no checklists. Non-empty ⇒ appends per-checklist instructions\n // naming the reviewer subagent + doc + the review-<id>.json to write.\n reviewJsonSchemaHint(filePath: string, required: readonly RequiredChecklist[] = []): string {\n return (\n `Write your PR review to:\\n ${filePath}\\n\\n` +\n `with this exact JSON shape (riskEmoji optional — derived from riskLevel):\\n\\n` +\n `{\\n` +\n ` \"title\": \"concise PR title describing the change (imperative, no branch names)\",\\n` +\n ` \"riskScore\": 0, // integer 0–100 (higher = riskier)\\n` +\n ` \"riskLevel\": \"green | yellow | red\",\\n` +\n ` \"summary\": \"5–10 sentence review summary\",\\n` +\n ` \"violations\": [\"pattern/architecture violations you found (empty array if none)\"],\\n` +\n ` \"risks\": [\"notable risks (empty array if none)\"],\\n` +\n ` \"filesToReview\": [\"paths a human should look at (empty array if none)\"]\\n` +\n `}` +\n this.requiredChecklistHint(filePath, required)\n );\n }\n\n // The per-checklist review file path that sits beside review.json: review-<id>.json.\n checklistResultPath(reviewJsonFilePath: string, checklistId: string): string {\n return path.join(path.dirname(reviewJsonFilePath), `review-${checklistId}.json`);\n }\n\n // The matched-checklist instruction block, appended ONLY when the diff matched a checklist. Each matched\n // checklist must be reviewed by its OWN subagent (a distinct one), which writes review-<id>.json.\n private requiredChecklistHint(reviewJsonFilePath: string, required: readonly RequiredChecklist[]): string {\n if (required.length === 0) return '';\n const lines: string[] = ['', '', 'This diff MATCHED company review checklist(s). Spawn EACH named subagent as a SEPARATE'];\n lines.push('subagent (a different one per checklist — the coding agent may NOT self-certify). Each reads its');\n lines.push('doc + the diff and writes its own review-<id>.json with this shape:');\n lines.push('');\n lines.push(' { \"id\": \"<id>\", \"success\": true, \"output\": \"what you checked / found\", \"override\": \"\" }');\n lines.push(' (success:false with no non-empty \"override\" refuses the PR; a non-empty override ships it 🟡.)');\n lines.push('');\n for (const req of required) {\n lines.push(` • [${req.id}] reviewer subagent: ${req.subagent}`);\n lines.push(` write: ${this.checklistResultPath(reviewJsonFilePath, req.id)}`);\n if (req.doc.trim() !== '') lines.push(` doc to read: ${req.doc}`);\n if (req.matchedFiles.length > 0) lines.push(` matched: ${req.matchedFiles.slice(0, 5).join(', ')}`);\n }\n return lines.join('\\n');\n }\n\n /**\n * Load + validate the AI-authored review.json. Throws InformAiError (with the schema) when missing,\n * unparseable, or structurally wrong. `required` is the set of checklists the diff matched: every one\n * must have a well-formed, passing (or overridden) review-<id>.json or a validation error is raised\n * alongside the usual ones so the AI gets ONE message.\n */\n // webpieces-disable max-lines-new-methods -- one cohesive load+validate pass over the review fields\n loadReviewJson(filePath: string, required: readonly RequiredChecklist[] = []): ReviewJson {\n if (!fs.existsSync(filePath)) {\n throw new InformAiError(\n `Required review.json not found.\\n\\n${this.reviewJsonSchemaHint(filePath, required)}\\n\\n` +\n `Then re-run: pnpm wp-finish-upsert-pr`,\n );\n }\n\n const raw = this.parseReviewJson(fs.readFileSync(filePath, 'utf8'), filePath, required);\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {\n throw new InformAiError(`review.json must be a JSON object.\\n\\n${this.reviewJsonSchemaHint(filePath, required)}`);\n }\n\n const errors: string[] = [];\n\n const riskScore = raw['riskScore'];\n if (typeof riskScore !== 'number' || !Number.isFinite(riskScore) || riskScore < 0 || riskScore > 100) {\n errors.push(`\"riskScore\" must be a number 0–100, got ${JSON.stringify(riskScore)}.`);\n }\n\n const riskLevel = raw['riskLevel'];\n if (typeof riskLevel !== 'string' || !RISK_LEVELS.includes(riskLevel as typeof RISK_LEVELS[number])) {\n errors.push(`\"riskLevel\" must be one of: ${RISK_LEVELS.join(', ')}.`);\n }\n\n const title = typeof raw['title'] === 'string' ? (raw['title'] as string).trim() : '';\n if (title === '') {\n errors.push('\"title\" must be a non-empty, imperative PR title describing the change (no branch names).');\n }\n\n const results = this.loadChecklistResults(filePath, required);\n for (const err of this.requiredChecklistErrors(required, results)) errors.push(err);\n\n if (errors.length > 0) {\n throw new InformAiError(\n `review.json has ${errors.length} error(s) — fix ALL, then re-run pnpm wp-finish-upsert-pr:\\n\\n` +\n errors.map((e: string): string => ` • ${e}`).join('\\n') +\n `\\n\\n${this.reviewJsonSchemaHint(filePath, required)}`,\n );\n }\n\n const level = riskLevel as string;\n const emoji = typeof raw['riskEmoji'] === 'string' && raw['riskEmoji'] !== ''\n ? (raw['riskEmoji'] as string)\n : (EMOJI_FOR_LEVEL[level] ?? '🟡');\n const summary = typeof raw['summary'] === 'string' ? (raw['summary'] as string) : '';\n\n return new ReviewJson(\n title,\n riskScore as number,\n level,\n emoji,\n summary,\n this.asStringArray(raw['violations']),\n this.asStringArray(raw['risks']),\n this.asStringArray(raw['filesToReview']),\n results,\n );\n }\n\n // Read the per-checklist verdict files `review-<id>.json` beside review.json — one per matched checklist.\n // A missing file is simply absent from the result (→ counts as MISSING for that checklist); a malformed\n // one is skipped (a stale review-<id>.json never wedges the branch).\n loadChecklistResults(reviewJsonFilePath: string, required: readonly RequiredChecklist[]): ChecklistResult[] {\n const results: ChecklistResult[] = [];\n for (const req of required) {\n const p = this.checklistResultPath(reviewJsonFilePath, req.id);\n if (!fs.existsSync(p)) continue;\n const parsed = this.parseChecklistResult(p, req.id);\n if (parsed) results.push(parsed);\n }\n return results;\n }\n\n // Resolve ONE checklist's verdict from its review-<id>.json. Central so review.json enforcement AND the\n // finish-command dashboard agree on the outcome.\n resolveVerdict(req: RequiredChecklist, results: readonly ChecklistResult[]): ChecklistVerdict {\n const result = results.find((r: ChecklistResult): boolean => r.id === req.id);\n if (!result) return new ChecklistVerdict(req.id, CK_MISSING, '');\n if (result.success) return new ChecklistVerdict(req.id, CK_PASS, result.output);\n if (result.override.trim() !== '') return new ChecklistVerdict(req.id, CK_OVERRIDDEN, result.override.trim());\n return new ChecklistVerdict(req.id, CK_FAIL, result.output);\n }\n\n // Every matched checklist whose verdict is FAIL (reviewed, found a problem, no override) or MISSING (no\n // review-<id>.json written) → one error each, printing the reviewer's `output` verbatim.\n private requiredChecklistErrors(required: readonly RequiredChecklist[], results: readonly ChecklistResult[]): string[] {\n const errors: string[] = [];\n for (const req of required) {\n const verdict = this.resolveVerdict(req, results);\n if (verdict.status === CK_FAIL) {\n errors.push(\n `Checklist \"${req.id}\" FAILED review. The reviewer (${req.subagent}) wrote:\\n ` +\n `${verdict.detail.split('\\n').join('\\n ')}\\n` +\n ` Fix it, then re-run; or set a non-empty \"override\" in ${this.checklistFileName(req.id)} to ship anyway with a stated justification.`,\n );\n } else if (verdict.status === CK_MISSING) {\n const doc = req.doc.trim() !== '' ? ` Read: ${req.doc}.` : '';\n errors.push(\n `Checklist \"${req.id}\" MATCHED this diff but has no verdict. Spawn the \"${req.subagent}\" subagent to review it, ` +\n `then write ${this.checklistFileName(req.id)} with {\"id\":\"${req.id}\",\"success\":true,\"output\":\"…\"}.${doc}`,\n );\n }\n }\n return errors;\n }\n\n private checklistFileName(checklistId: string): string {\n return `review-${checklistId}.json`;\n }\n\n // Parse one review-<id>.json into a ChecklistResult, or null when malformed. Tolerant: missing\n // `success` counts as false (fail-closed), `output`/`override` default to ''.\n // webpieces-disable no-any-unknown -- opaque parsed JSON, narrowed field-by-field\n private parseChecklistResult(filePath: string, id: string): ChecklistResult | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: a malformed per-checklist file is skipped, not fatal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed below\n const raw = JSON.parse(fs.readFileSync(filePath, 'utf8')) as Record<string, unknown>;\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return null;\n const success = raw['success'] === true;\n const output = typeof raw['output'] === 'string' ? (raw['output'] as string) : '';\n const override = typeof raw['override'] === 'string' ? (raw['override'] as string) : '';\n return new ChecklistResult(id, success, output, override);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- opaque parsed JSON value, narrowed to string[] here\n private asStringArray(value: unknown): string[] {\n if (!Array.isArray(value)) return [];\n // webpieces-disable no-any-unknown -- element of an opaque JSON array, narrowed by the type guard\n return value.filter((v: unknown): v is string => typeof v === 'string');\n }\n\n // Parse opaque AI-authored JSON, converting a SyntaxError into a readable InformAiError. `required`\n // is threaded through so a JSON syntax error still prints the checklist instructions the AI needs.\n // webpieces-disable no-any-unknown -- returns the opaque parsed object; loadReviewJson narrows each field\n private parseReviewJson(raw: string, filePath: string, required: readonly RequiredChecklist[]): Record<string, unknown> {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: convert JSON.parse SyntaxError to an InformAiError for the AI\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed by the caller\n return JSON.parse(raw) as Record<string, unknown>;\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(\n `review.json is not valid JSON (${error.message}).\\n\\n${this.reviewJsonSchemaHint(filePath, required)}\\n\\n` +\n `Then re-run: pnpm wp-finish-upsert-pr`,\n );\n }\n }\n}\n\n// Temporary migration delegators to ReviewJsonService — removed once consumers inject it.\nconst reviewJsonSvc = new ReviewJsonService();\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function prDirFor(repoRoot: string, featureName: string): string {\n return reviewJsonSvc.prDirFor(repoRoot, featureName);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function reviewJsonPath(repoRoot: string, featureName: string): string {\n return reviewJsonSvc.reviewJsonPath(repoRoot, featureName);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function reviewJsonSchemaHint(filePath: string, required: readonly RequiredChecklist[] = []): string {\n return reviewJsonSvc.reviewJsonSchemaHint(filePath, required);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function loadReviewJson(filePath: string, required: readonly RequiredChecklist[] = []): ReviewJson {\n return reviewJsonSvc.loadReviewJson(filePath, required);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"review-json.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/review-json.ts"],"names":[],"mappings":";;;AA+YA,4BAEC;AAGD,wCAEC;AAGD,oDAEC;AAGD,wCAEC;;AAhaD,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAC3D,2CAA+D;AAC/D,uDAAkD;AAClD,yCAAqC;AAErC,wGAAwG;AACxG,sGAAsG;AACtG,gCAAgC;AAChC,8CAA8C;AAC9C,uGAAuG;AACvG,qFAAqF;AACrF,wGAAwG;AACxG,+FAA+F;AAC/F,MAAa,eAAe;IACxB,EAAE,CAAS;IACX,OAAO,CAAU;IACjB,MAAM,CAAS,CAAG,qEAAqE;IACvF,QAAQ,CAAS,CAAE,kFAAkF;IAErG,YAAY,EAAU,EAAE,OAAgB,EAAE,MAAc,EAAE,QAAgB;QACtE,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAZD,0CAYC;AAED,yGAAyG;AACzG,wGAAwG;AACxG,sCAAsC;AACtC,MAAa,iBAAiB;IAC1B,EAAE,CAAS,CAAa,yCAAyC;IACjE,QAAQ,CAAS,CAAO,8DAA8D;IACtF,GAAG,CAAS,CAAY,iFAAiF;IACzG,YAAY,CAAW,CAAC,+DAA+D;IACvF,oGAAoG;IACpG,uGAAuG;IACvG,sGAAsG;IACtG,eAAe,C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AC,QAAQ,EAAE,WAAW,CAAC,CAAC;AACzD,CAAC;AAED,wIAAwI;AACxI,SAAgB,cAAc,CAAC,QAAgB,EAAE,WAAmB;IAChE,OAAO,aAAa,CAAC,cAAc,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AAC/D,CAAC;AAED,wIAAwI;AACxI,SAAgB,oBAAoB,CAAC,QAAgB;IACjD,OAAO,aAAa,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;AACxD,CAAC;AAED,wIAAwI;AACxI,SAAgB,cAAc,CAAC,QAAgB,EAAE,WAAyC,EAAE;IACxF,OAAO,aAAa,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { WEBPIECES_TMP_DIR, PR_REVIEW_DIR } from './constants';\nimport { InformAiError } from './inform-ai-error';\nimport { toError } from './to-error';\n\n// The verdict a reviewer SUBAGENT writes into `.webpieces/pr-review/<branch>/review-<id>.json`, one per\n// matched checklist. One file per checklist so N concurrent reviewer subagents never clobber a shared\n// file. It records the OUTCOME:\n// success:true → PASS\n// success:false + override non-empty → OVERRIDDEN (pass; the free-text justification reaches the PR)\n// success:false + no override → FAIL (refuse; `output` is printed verbatim)\n// `override` is deliberately free text, not a boolean — it forces the ship-anyway decision to be stated\n// in words and surfaces it on the dashboard, where a human sees it. Data-only (per CLAUDE.md).\nexport class ChecklistResult {\n id: string;\n success: boolean;\n output: string; // what the reviewer found; printed verbatim when the checklist fails\n override: string; // '' = no override; non-empty = ship-anyway justification (renders 🟡 overridden)\n\n constructor(id: string, success: boolean, output: string, override: string) {\n this.id = id;\n this.success = success;\n this.output = output;\n this.override = override;\n }\n}\n\n// What the pr-gate command computed from the diff: a checklist this branch MATCHED (its patterns hit the\n// diff, so its reviewer subagent must run). Drives review-<id>.json enforcement, provenance, the schema\n// hint, and the dashboard. Data-only.\nexport class RequiredChecklist {\n id: string; // = subagent name; keys review-<id>.json\n subagent: string; // reviewer agent that must run (agentType the harness stamps)\n doc: string; // REPO-RELATIVE guidance doc the reviewer reads ('' → it reads the manifest doc)\n matchedFiles: string[]; // the changed files that matched it (for the dashboard + hint)\n // Which of the checklist's OWN globs actually fired. Printed so a reviewer can judge how coarse the\n // match was — a precise `db/migrations/**` hit means something different from a blanket `**` — and the\n // template tells reviewers that matching IS deliberately coarse. [] = no patterns (matches every PR).\n matchedPatterns: string[];\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(id: string, subagent: string, doc: string, matchedFiles: string[], matchedPatterns: string[] = []) {\n this.id = id;\n this.subagent = subagent;\n this.doc = doc;\n this.matchedFiles = matchedFiles;\n this.matchedPatterns = matchedPatterns;\n }\n}\n\n/**\n * The per-PR facts every reviewer subagent needs GIVEN to it, alongside its own checklist: the exact base\n * sha the gate diffs against and the file holding the complete changed-file set. Both used to live only in\n * a doc the printed instruction told the AI to go read, one indirection away from the instruction to hand\n * them over — so the printed block could not stand on its own. Data-only; empty = omit those lines.\n */\nexport class ChecklistReviewContext {\n baseSha: string; // the 3-point merge-base sha; `git diff <baseSha> HEAD -- <file>`\n prContextPath: string; // path of pr-context.json — the AUTHORITATIVE full changed-file set\n\n constructor(baseSha = '', prContextPath = '') {\n this.baseSha = baseSha;\n this.prContextPath = prContextPath;\n }\n}\n\n// The AI-authored review for a PR. The AI writes review.json itself between `wp-start-upsert-pr` (which\n// prints the schema) and `wp-finish-upsert-pr` (which reads it); reviewer subagents write the per-checklist\n// review-<id>.json files. Data-only (per CLAUDE.md).\nexport class ReviewJson {\n title: string; // human PR title describing the change; used as the `gh pr` title (empty → caller falls back)\n riskScore: number; // 0–100, drives the risk bar\n riskLevel: string; // 'green' | 'yellow' | 'red'\n riskEmoji: string; // '🟢' | '🟡' | '🔴' — derived from riskLevel when omitted\n summary: string; // rendered in the dashboard Summary section\n violations: string[]; // pattern/architecture violations; length = the Pattern Violations count\n risks: string[];\n filesToReview: string[];\n results: ChecklistResult[]; // resolved per-checklist verdicts (from review-<id>.json); [] when none\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n title: string,\n riskScore: number,\n riskLevel: string,\n riskEmoji: string,\n summary: string,\n violations: string[],\n risks: string[],\n filesToReview: string[],\n results: ChecklistResult[] = [],\n ) {\n this.title = title;\n this.riskScore = riskScore;\n this.riskLevel = riskLevel;\n this.riskEmoji = riskEmoji;\n this.summary = summary;\n this.violations = violations;\n this.risks = risks;\n this.filesToReview = filesToReview;\n this.results = results;\n }\n}\n\n// A checklist's resolved outcome, shared by review.json enforcement and the dashboard so both agree.\nexport const CK_PASS = 'pass'; // review-<id>.json success:true\nexport const CK_OVERRIDDEN = 'overridden'; // review-<id>.json success:false + non-empty override → 🟡\nexport const CK_FAIL = 'fail'; // review-<id>.json success:false + no override → refuse\nexport const CK_MISSING = 'missing'; // no review-<id>.json written → refuse\n\nexport class ChecklistVerdict {\n id: string;\n status: string; // one of CK_PASS | CK_OVERRIDDEN | CK_FAIL | CK_MISSING\n detail: string; // reviewer output / override justification (for the dashboard + errors)\n\n constructor(id: string, status: string, detail: string) {\n this.id = id;\n this.status = status;\n this.detail = detail;\n }\n}\n\n// The PR's diff context, written by wp-start-upsert-pr into `.webpieces/pr-review/<branch>/pr-context.json`\n// so a reviewer subagent knows the exact 3-point base the gate used and the full changed-file set — then\n// reads any file's actual diff with `git diff <base> HEAD -- <file>`. This is what lets a checklist match\n// coarsely by path (in the manifest) while the subagent makes the fine, content-level judgment. Data-only.\nexport class PrContext {\n base: string; // the 3-point merge-base sha the gate diffs against\n head: string; // HEAD sha\n changedFiles: string[]; // every file changed base..head (NOT tsOnly — includes .sql/.gql/Dockerfile/…)\n\n constructor(base: string, head: string, changedFiles: string[]) {\n this.base = base;\n this.head = head;\n this.changedFiles = changedFiles;\n }\n}\n\nconst RISK_LEVELS = ['green', 'yellow', 'red'] as const;\nconst EMOJI_FOR_LEVEL: Record<string, string> = { green: '🟢', yellow: '🟡', red: '🔴' };\n\n/** Locates + loads/validates the AI-authored review.json. `@injectable(bindingScopeValues.Singleton)` so it's drawn in the design. */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewJsonService {\n // The per-feature PR working dir: `.webpieces/pr-review/<feature>`.\n prDirFor(repoRoot: string, featureName: string): string {\n return path.join(repoRoot, WEBPIECES_TMP_DIR, PR_REVIEW_DIR, featureName);\n }\n\n // Absolute path of the review.json for a feature — beside pr-body.md, keyed by branch name.\n reviewJsonPath(repoRoot: string, featureName: string): string {\n return path.join(this.prDirFor(repoRoot, featureName), 'review.json');\n }\n\n // Absolute path of the pr-context.json for a feature (the diff base/head + changed files).\n prContextPath(repoRoot: string, featureName: string): string {\n return path.join(this.prDirFor(repoRoot, featureName), 'pr-context.json');\n }\n\n // Persist the PR's diff context so reviewer subagents can read the changed-file set + the exact base\n // sha (then `git diff <base> HEAD -- <file>` for content). Returns the file path written.\n writePrContext(repoRoot: string, featureName: string, context: PrContext): string {\n const dir = this.prDirFor(repoRoot, featureName);\n fs.mkdirSync(dir, { recursive: true });\n const p = this.prContextPath(repoRoot, featureName);\n fs.writeFileSync(p, JSON.stringify(context, null, 2) + '\\n');\n return p;\n }\n\n /**\n * The review context for a feature, recovered from the pr-context.json wp-start-upsert-pr already wrote.\n * Lets wp-finish-upsert-pr's \"you still owe me review-<id>.json\" message inline the SAME self-sufficient\n * per-reviewer block start printed, instead of a checklist name and an indirection. Empty when the file\n * is absent or unreadable — the block then just omits those lines.\n */\n reviewContextFor(repoRoot: string, featureName: string): ChecklistReviewContext {\n const p = this.prContextPath(repoRoot, featureName);\n if (!fs.existsSync(p)) return new ChecklistReviewContext();\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable context file degrades to fewer printed lines, never a crash\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed on the next line\n const raw = JSON.parse(fs.readFileSync(p, 'utf8')) as Record<string, unknown>;\n const base = typeof raw['base'] === 'string' ? (raw['base'] as string) : '';\n return new ChecklistReviewContext(base, p);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return new ChecklistReviewContext('', p);\n }\n }\n\n // Copy-paste schema both commands print. `required` is the set of checklists the diff MATCHED; empty\n // ⇒ output identical to a repo with no checklists. Non-empty ⇒ appends per-checklist instructions\n // naming the reviewer subagent + doc + the review-<id>.json to write.\n reviewJsonSchemaHint(filePath: string): string {\n return (\n `Write your PR review to:\\n ${filePath}\\n\\n` +\n `with this exact JSON shape (riskEmoji optional — derived from riskLevel):\\n\\n` +\n `{\\n` +\n ` \"title\": \"concise PR title describing the change (imperative, no branch names)\",\\n` +\n ` \"riskScore\": 0, // integer 0–100 (higher = riskier)\\n` +\n ` \"riskLevel\": \"green | yellow | red\",\\n` +\n ` \"summary\": \"5–10 sentence review summary\",\\n` +\n ` \"violations\": [\"pattern/architecture violations you found (empty array if none)\"],\\n` +\n ` \"risks\": [\"notable risks (empty array if none)\"],\\n` +\n ` \"filesToReview\": [\"paths a human should look at (empty array if none)\"]\\n` +\n `}`\n );\n }\n\n // The per-checklist review file path that sits beside review.json: review-<id>.json.\n checklistResultPath(reviewJsonFilePath: string, checklistId: string): string {\n return path.join(path.dirname(reviewJsonFilePath), `review-${checklistId}.json`);\n }\n\n /**\n * Load + validate the AI-authored review.json. Throws InformAiError (with the schema) when missing,\n * unparseable, or structurally wrong. `required` is the set of checklists the diff matched: every one\n * must have a well-formed, passing (or overridden) review-<id>.json or a validation error is raised\n * alongside the usual ones so the AI gets ONE message.\n */\n // webpieces-disable max-lines-new-methods -- one cohesive load+validate pass over the review fields\n loadReviewJson(filePath: string, required: readonly RequiredChecklist[] = []): ReviewJson {\n if (!fs.existsSync(filePath)) {\n throw new InformAiError(\n `Required review.json not found.\\n\\n${this.reviewJsonSchemaHint(filePath)}\\n\\n` +\n `Then re-run: pnpm wp-finish-upsert-pr`,\n );\n }\n\n const raw = this.parseReviewJson(fs.readFileSync(filePath, 'utf8'), filePath);\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {\n throw new InformAiError(`review.json must be a JSON object.\\n\\n${this.reviewJsonSchemaHint(filePath)}`);\n }\n\n const errors: string[] = [];\n\n const riskScore = raw['riskScore'];\n if (typeof riskScore !== 'number' || !Number.isFinite(riskScore) || riskScore < 0 || riskScore > 100) {\n errors.push(`\"riskScore\" must be a number 0–100, got ${JSON.stringify(riskScore)}.`);\n }\n\n const riskLevel = raw['riskLevel'];\n if (typeof riskLevel !== 'string' || !RISK_LEVELS.includes(riskLevel as typeof RISK_LEVELS[number])) {\n errors.push(`\"riskLevel\" must be one of: ${RISK_LEVELS.join(', ')}.`);\n }\n\n const title = typeof raw['title'] === 'string' ? (raw['title'] as string).trim() : '';\n if (title === '') {\n errors.push('\"title\" must be a non-empty, imperative PR title describing the change (no branch names).');\n }\n\n const results = this.loadChecklistResults(filePath, required);\n for (const err of this.requiredChecklistErrors(required, results)) errors.push(err);\n\n if (errors.length > 0) {\n throw new InformAiError(\n `review.json has ${errors.length} error(s) — fix ALL, then re-run pnpm wp-finish-upsert-pr:\\n\\n` +\n errors.map((e: string): string => ` • ${e}`).join('\\n') +\n `\\n\\n${this.reviewJsonSchemaHint(filePath)}`,\n );\n }\n\n const level = riskLevel as string;\n const emoji = typeof raw['riskEmoji'] === 'string' && raw['riskEmoji'] !== ''\n ? (raw['riskEmoji'] as string)\n : (EMOJI_FOR_LEVEL[level] ?? '🟡');\n const summary = typeof raw['summary'] === 'string' ? (raw['summary'] as string) : '';\n\n return new ReviewJson(\n title,\n riskScore as number,\n level,\n emoji,\n summary,\n this.asStringArray(raw['violations']),\n this.asStringArray(raw['risks']),\n this.asStringArray(raw['filesToReview']),\n results,\n );\n }\n\n /**\n * The checklists that still OWE a verdict: no review-<id>.json at all, a malformed one, or one whose\n * verdict is an un-overridden FAIL. This is the set every message lists — a checklist already PASSed or\n * OVERRIDDEN on this branch is deliberately NOT re-listed, because re-instructing it invites a redundant\n * second run and reads as though the earlier verdict did not count.\n */\n pendingChecklists(required: readonly RequiredChecklist[], results: readonly ChecklistResult[]): RequiredChecklist[] {\n return required.filter((req: RequiredChecklist): boolean => {\n const status = this.resolveVerdict(req, results).status;\n return status !== CK_PASS && status !== CK_OVERRIDDEN;\n });\n }\n\n // Read the per-checklist verdict files `review-<id>.json` beside review.json — one per matched checklist.\n // A missing file is simply absent from the result (→ counts as MISSING for that checklist); a malformed\n // one is skipped (a stale review-<id>.json never wedges the branch).\n loadChecklistResults(reviewJsonFilePath: string, required: readonly RequiredChecklist[]): ChecklistResult[] {\n const results: ChecklistResult[] = [];\n for (const req of required) {\n const p = this.checklistResultPath(reviewJsonFilePath, req.id);\n if (!fs.existsSync(p)) continue;\n const parsed = this.parseChecklistResult(p, req.id);\n if (parsed) results.push(parsed);\n }\n return results;\n }\n\n // Resolve ONE checklist's verdict from its review-<id>.json. Central so review.json enforcement AND the\n // finish-command dashboard agree on the outcome.\n resolveVerdict(req: RequiredChecklist, results: readonly ChecklistResult[]): ChecklistVerdict {\n const result = results.find((r: ChecklistResult): boolean => r.id === req.id);\n if (!result) return new ChecklistVerdict(req.id, CK_MISSING, '');\n if (result.success) return new ChecklistVerdict(req.id, CK_PASS, result.output);\n if (result.override.trim() !== '') return new ChecklistVerdict(req.id, CK_OVERRIDDEN, result.override.trim());\n return new ChecklistVerdict(req.id, CK_FAIL, result.output);\n }\n\n // Every matched checklist whose verdict is FAIL (reviewed, found a problem, no override) or MISSING (no\n // review-<id>.json written) → one error each, printing the reviewer's `output` verbatim.\n private requiredChecklistErrors(required: readonly RequiredChecklist[], results: readonly ChecklistResult[]): string[] {\n const errors: string[] = [];\n for (const req of required) {\n const verdict = this.resolveVerdict(req, results);\n if (verdict.status === CK_FAIL) {\n errors.push(\n `Checklist \"${req.id}\" FAILED review. The reviewer (${req.subagent}) wrote:\\n ` +\n `${verdict.detail.split('\\n').join('\\n ')}\\n` +\n ` Fix it, then re-run; or set a non-empty \"override\" in ${this.checklistFileName(req.id)} to ship anyway with a stated justification.`,\n );\n } else if (verdict.status === CK_MISSING) {\n const doc = req.doc.trim() !== '' ? ` Read: ${req.doc}.` : '';\n errors.push(\n `Checklist \"${req.id}\" MATCHED this diff but has no verdict. Spawn the \"${req.subagent}\" subagent to review it, ` +\n `then write ${this.checklistFileName(req.id)} with {\"id\":\"${req.id}\",\"success\":true,\"output\":\"…\"}.${doc}`,\n );\n }\n }\n return errors;\n }\n\n private checklistFileName(checklistId: string): string {\n return `review-${checklistId}.json`;\n }\n\n // Parse one review-<id>.json into a ChecklistResult, or null when malformed. Tolerant: missing\n // `success` counts as false (fail-closed), `output`/`override` default to ''.\n // webpieces-disable no-any-unknown -- opaque parsed JSON, narrowed field-by-field\n private parseChecklistResult(filePath: string, id: string): ChecklistResult | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: a malformed per-checklist file is skipped, not fatal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed below\n const raw = JSON.parse(fs.readFileSync(filePath, 'utf8')) as Record<string, unknown>;\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return null;\n const success = raw['success'] === true;\n const output = typeof raw['output'] === 'string' ? (raw['output'] as string) : '';\n const override = typeof raw['override'] === 'string' ? (raw['override'] as string) : '';\n return new ChecklistResult(id, success, output, override);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- opaque parsed JSON value, narrowed to string[] here\n private asStringArray(value: unknown): string[] {\n if (!Array.isArray(value)) return [];\n // webpieces-disable no-any-unknown -- element of an opaque JSON array, narrowed by the type guard\n return value.filter((v: unknown): v is string => typeof v === 'string');\n }\n\n // Parse opaque AI-authored JSON, converting a SyntaxError into a readable InformAiError.\n // webpieces-disable no-any-unknown -- returns the opaque parsed object; loadReviewJson narrows each field\n private parseReviewJson(raw: string, filePath: string): Record<string, unknown> {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: convert JSON.parse SyntaxError to an InformAiError for the AI\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed by the caller\n return JSON.parse(raw) as Record<string, unknown>;\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(\n `review.json is not valid JSON (${error.message}).\\n\\n${this.reviewJsonSchemaHint(filePath)}\\n\\n` +\n `Then re-run: pnpm wp-finish-upsert-pr`,\n );\n }\n }\n}\n\n// Temporary migration delegators to ReviewJsonService — removed once consumers inject it.\nconst reviewJsonSvc = new ReviewJsonService();\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function prDirFor(repoRoot: string, featureName: string): string {\n return reviewJsonSvc.prDirFor(repoRoot, featureName);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function reviewJsonPath(repoRoot: string, featureName: string): string {\n return reviewJsonSvc.reviewJsonPath(repoRoot, featureName);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function reviewJsonSchemaHint(filePath: string): string {\n return reviewJsonSvc.reviewJsonSchemaHint(filePath);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function loadReviewJson(filePath: string, required: readonly RequiredChecklist[] = []): ReviewJson {\n return reviewJsonSvc.loadReviewJson(filePath, required);\n}\n"]}
|
package/src/validate-config.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { validateChecklistsSection } from './pr-gate-section-validators';
|
|
2
|
+
export { validateChecklistsSection };
|
|
1
3
|
export declare function allRuleNames(): readonly string[];
|
|
2
4
|
export declare function validateWebpiecesConfig(rawRules: Record<string, Record<string, unknown>>, hasCustomRulesDir?: boolean): string[];
|
|
3
5
|
/**
|
|
@@ -8,7 +10,6 @@ export declare function validateWebpiecesConfig(rawRules: Record<string, Record<
|
|
|
8
10
|
* `repoRoot` (when known) lets the `checklists[].docs` existence check run.
|
|
9
11
|
*/
|
|
10
12
|
export declare function validatePrGateSection(section: unknown, repoRoot?: string): string[];
|
|
11
|
-
export declare function validateChecklistsSection(value: unknown, repoRoot?: string): string[];
|
|
12
13
|
/**
|
|
13
14
|
* Validate the REQUIRED top-level `excludePaths` block: two independent glob lists (`rules`,
|
|
14
15
|
* `guards`) that suppress hook enforcement per file path. Required so every client upgrading is
|
package/src/validate-config.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateChecklistsSection = void 0;
|
|
3
4
|
exports.allRuleNames = allRuleNames;
|
|
4
5
|
exports.validateWebpiecesConfig = validateWebpiecesConfig;
|
|
5
6
|
exports.validatePrGateSection = validatePrGateSection;
|
|
6
|
-
exports.validateChecklistsSection = validateChecklistsSection;
|
|
7
7
|
exports.validateExcludePaths = validateExcludePaths;
|
|
8
8
|
exports.validateMatchRulesSection = validateMatchRulesSection;
|
|
9
9
|
exports.validateSectionPlacement = validateSectionPlacement;
|
|
@@ -11,7 +11,8 @@ exports.validateCommandsSection = validateCommandsSection;
|
|
|
11
11
|
const sections_1 = require("./sections");
|
|
12
12
|
const rule_configs_1 = require("./rule-configs");
|
|
13
13
|
const main_sync_guard_configs_1 = require("./main-sync-guard-configs");
|
|
14
|
-
const
|
|
14
|
+
const pr_gate_section_validators_1 = require("./pr-gate-section-validators");
|
|
15
|
+
Object.defineProperty(exports, "validateChecklistsSection", { enumerable: true, get: function () { return pr_gate_section_validators_1.validateChecklistsSection; } });
|
|
15
16
|
const match_rules_config_1 = require("./match-rules-config");
|
|
16
17
|
const to_error_1 = require("./to-error");
|
|
17
18
|
const rule_configs_2 = require("./rule-configs");
|
|
@@ -223,9 +224,26 @@ function prGateExample() {
|
|
|
223
224
|
` "buildCommand": "<command CI runs to validate a PR, e.g. pnpm nx affected --target=ci --base=$(git merge-base origin/main HEAD)>",\n` +
|
|
224
225
|
` "gates": [\n` +
|
|
225
226
|
` { "name": "API Changed", "patterns": ["libraries/apis/**", "**/*Api.ts"], "warningColor": "yellow" }\n` +
|
|
227
|
+
` ],\n` +
|
|
228
|
+
` "checklists": [ // OPTIONAL — per-area review, one distinct reviewer subagent each\n` +
|
|
229
|
+
` { "subagent": "db-migration-reviewer", "doc": ".claude/review/db-migrations.md", "patterns": ["**/*.sql"] }\n` +
|
|
226
230
|
` ]\n` +
|
|
227
231
|
` }`);
|
|
228
232
|
}
|
|
233
|
+
// The `gates` array: dashboard-only warning flags. Extracted from validatePrGateSection to keep that
|
|
234
|
+
// method inside the length limit.
|
|
235
|
+
// webpieces-disable no-any-unknown -- `value` is the opaque consumer `gates` value until narrowed here
|
|
236
|
+
// webpieces-disable no-function-outside-class -- module-level config validator, matches the rest of this file
|
|
237
|
+
function validateGatesSection(value) {
|
|
238
|
+
if (!Array.isArray(value)) {
|
|
239
|
+
return [`[pr-gate] "gates" must be an array of { name, patterns, warningColor, disabled? }.`];
|
|
240
|
+
}
|
|
241
|
+
const errors = [];
|
|
242
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
243
|
+
errors.push(...validateGate(value[i], i));
|
|
244
|
+
}
|
|
245
|
+
return errors;
|
|
246
|
+
}
|
|
229
247
|
// webpieces-disable no-any-unknown -- one gate entry from opaque consumer JSON, validated field-by-field
|
|
230
248
|
function validateGate(gate, index) {
|
|
231
249
|
if (typeof gate !== 'object' || gate === null) {
|
|
@@ -291,21 +309,12 @@ function validatePrGateSection(section, repoRoot) {
|
|
|
291
309
|
errors.push(`[pr-gate] "mergeMode" = "${String(mm)}" is not valid. ${MERGE_MODE_HELP}`);
|
|
292
310
|
}
|
|
293
311
|
}
|
|
294
|
-
if ('gates' in s)
|
|
295
|
-
|
|
296
|
-
if (!Array.isArray(gates)) {
|
|
297
|
-
errors.push(`[pr-gate] "gates" must be an array of { name, patterns, warningColor, disabled? }.`);
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
for (let i = 0; i < gates.length; i += 1) {
|
|
301
|
-
errors.push(...validateGate(gates[i], i));
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
312
|
+
if ('gates' in s)
|
|
313
|
+
errors.push(...validateGatesSection(s['gates']));
|
|
305
314
|
// Optional extension point: company review checklists. The config only points at ONE manifest doc —
|
|
306
315
|
// { "doc": "..." } — and the checklist SET lives in that doc. Absent ⇒ no checklists.
|
|
307
316
|
if ('checklists' in s)
|
|
308
|
-
errors.push(...validateChecklistsSection(s['checklists'], repoRoot));
|
|
317
|
+
errors.push(...(0, pr_gate_section_validators_1.validateChecklistsSection)(s['checklists'], repoRoot));
|
|
309
318
|
// Optional server-token salt. Absent ⇒ no token minted, CI enforcement is a no-op. Present ⇒ must be
|
|
310
319
|
// a non-empty string (an empty salt would mint a token anyone can forge from a known-empty secret).
|
|
311
320
|
if ('gateSalt' in s) {
|
|
@@ -314,31 +323,13 @@ function validatePrGateSection(section, repoRoot) {
|
|
|
314
323
|
errors.push(`[pr-gate] "gateSalt" must be a non-empty string — it is the shared secret the gate token is HMAC'd with. Omit the key entirely to disable server-side token enforcement.`);
|
|
315
324
|
}
|
|
316
325
|
}
|
|
326
|
+
errors.push(...(0, pr_gate_section_validators_1.validateNoGateSaltRationale)(s));
|
|
317
327
|
// Optional: publish reviewer output as a PR comment (defaults true). Must be a boolean when present.
|
|
318
328
|
if ('checklistComments' in s && typeof s['checklistComments'] !== 'boolean') {
|
|
319
329
|
errors.push(`[pr-gate] "checklistComments" must be a boolean (defaults to true; set false to keep the PR body-only).`);
|
|
320
330
|
}
|
|
321
331
|
return errors;
|
|
322
332
|
}
|
|
323
|
-
// The `checklists` section of a pr-gate config: { "doc": "<path to the manifest doc>" }. The manifest
|
|
324
|
-
// itself (the list of { subagent, doc?, patterns? }) lives in that doc's <!-- webpieces:checklists -->
|
|
325
|
-
// block and is validated by ChecklistManifestService. Exported so the isolated validate-checklist-docs
|
|
326
|
-
// target reuses it. `repoRoot` (when known) lets the doc + manifest existence checks run.
|
|
327
|
-
// webpieces-disable no-any-unknown -- `value` is opaque consumer JSON until narrowed below
|
|
328
|
-
// webpieces-disable no-function-outside-class -- module-level config validator, matches the rest of this file
|
|
329
|
-
function validateChecklistsSection(value, repoRoot) {
|
|
330
|
-
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
331
|
-
return [`[pr-gate] "checklists" must be an object { "doc": "<path to the review manifest doc>" }.`];
|
|
332
|
-
}
|
|
333
|
-
// webpieces-disable no-any-unknown -- narrowing the opaque checklists section
|
|
334
|
-
const doc = value['doc'];
|
|
335
|
-
if (typeof doc !== 'string' || doc.trim() === '') {
|
|
336
|
-
return [`[pr-gate] "checklists.doc" must be a non-empty string — the repo-relative markdown doc carrying the <!-- webpieces:checklists [...] --> manifest.`];
|
|
337
|
-
}
|
|
338
|
-
if (repoRoot === undefined)
|
|
339
|
-
return [];
|
|
340
|
-
return new checklist_manifest_1.ChecklistManifestService().validate(repoRoot, doc);
|
|
341
|
-
}
|
|
342
333
|
function excludePathsExample() {
|
|
343
334
|
return '"excludePaths": {\n' +
|
|
344
335
|
' "rules": ["repositories/**"],\n' +
|