@webpieces/rules-config 0.4.469 → 0.4.471
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 +3 -1
- package/src/checklist-config.js +13 -2
- package/src/checklist-config.js.map +1 -1
- package/src/checklist-docs-validator.d.ts +9 -0
- package/src/checklist-docs-validator.js +45 -0
- package/src/checklist-docs-validator.js.map +1 -0
- package/src/gate-token.d.ts +24 -0
- package/src/gate-token.js +78 -0
- package/src/gate-token.js.map +1 -0
- package/src/index.d.ts +5 -2
- package/src/index.js +27 -4
- package/src/index.js.map +1 -1
- package/src/pr-gate-config.d.ts +14 -1
- package/src/pr-gate-config.js +18 -2
- package/src/pr-gate-config.js.map +1 -1
- package/src/review-json.d.ts +27 -2
- package/src/review-json.js +147 -31
- package/src/review-json.js.map +1 -1
- package/src/subagent-provenance.d.ts +39 -0
- package/src/subagent-provenance.js +173 -0
- package/src/subagent-provenance.js.map +1 -0
- package/src/validate-config.d.ts +1 -0
- package/src/validate-config.js +12 -0
- package/src/validate-config.js.map +1 -1
- package/templates/webpieces-pr-gate.yml +51 -0
package/src/review-json.d.ts
CHANGED
|
@@ -4,6 +4,13 @@ export declare class ChecklistAck {
|
|
|
4
4
|
notes: string[];
|
|
5
5
|
constructor(id: string, acknowledged: boolean, notes: string[]);
|
|
6
6
|
}
|
|
7
|
+
export declare class ChecklistResult {
|
|
8
|
+
id: string;
|
|
9
|
+
success: boolean;
|
|
10
|
+
output: string;
|
|
11
|
+
override: string;
|
|
12
|
+
constructor(id: string, success: boolean, output: string, override: string);
|
|
13
|
+
}
|
|
7
14
|
export declare class RequiredChecklist {
|
|
8
15
|
id: string;
|
|
9
16
|
title: string;
|
|
@@ -11,7 +18,8 @@ export declare class RequiredChecklist {
|
|
|
11
18
|
docs: string[];
|
|
12
19
|
blockMessage: string;
|
|
13
20
|
matchedFiles: string[];
|
|
14
|
-
|
|
21
|
+
subagent: string;
|
|
22
|
+
constructor(id: string, title: string, severity: string, docs: string[], blockMessage: string, matchedFiles: string[], subagent?: string);
|
|
15
23
|
}
|
|
16
24
|
export declare class ReviewJson {
|
|
17
25
|
title: string;
|
|
@@ -23,13 +31,26 @@ export declare class ReviewJson {
|
|
|
23
31
|
risks: string[];
|
|
24
32
|
filesToReview: string[];
|
|
25
33
|
checklists: ChecklistAck[];
|
|
26
|
-
|
|
34
|
+
results: ChecklistResult[];
|
|
35
|
+
constructor(title: string, riskScore: number, riskLevel: string, riskEmoji: string, summary: string, violations: string[], risks: string[], filesToReview: string[], checklists?: ChecklistAck[], results?: ChecklistResult[]);
|
|
36
|
+
}
|
|
37
|
+
export declare const CK_PASS = "pass";
|
|
38
|
+
export declare const CK_OVERRIDDEN = "overridden";
|
|
39
|
+
export declare const CK_FAIL = "fail";
|
|
40
|
+
export declare const CK_MISSING = "missing";
|
|
41
|
+
export declare const CK_ACKED = "acknowledged";
|
|
42
|
+
export declare class ChecklistVerdict {
|
|
43
|
+
id: string;
|
|
44
|
+
status: string;
|
|
45
|
+
detail: string;
|
|
46
|
+
constructor(id: string, status: string, detail: string);
|
|
27
47
|
}
|
|
28
48
|
/** Locates + loads/validates the AI-authored review.json. `@injectable(bindingScopeValues.Singleton)` so it's drawn in the design. */
|
|
29
49
|
export declare class ReviewJsonService {
|
|
30
50
|
prDirFor(repoRoot: string, featureName: string): string;
|
|
31
51
|
reviewJsonPath(repoRoot: string, featureName: string): string;
|
|
32
52
|
reviewJsonSchemaHint(filePath: string, required?: readonly RequiredChecklist[]): string;
|
|
53
|
+
checklistResultPath(reviewJsonFilePath: string, checklistId: string): string;
|
|
33
54
|
private requiredChecklistHint;
|
|
34
55
|
/**
|
|
35
56
|
* Load + validate the AI-authored review.json. Throws InformAiError (with the schema) when missing,
|
|
@@ -43,7 +64,11 @@ export declare class ReviewJsonService {
|
|
|
43
64
|
*/
|
|
44
65
|
loadReviewJson(filePath: string, required?: readonly RequiredChecklist[]): ReviewJson;
|
|
45
66
|
private parseChecklistAcks;
|
|
67
|
+
loadChecklistResults(reviewJsonFilePath: string, required: readonly RequiredChecklist[]): ChecklistResult[];
|
|
68
|
+
resolveVerdict(req: RequiredChecklist, acks: readonly ChecklistAck[], results: readonly ChecklistResult[]): ChecklistVerdict;
|
|
46
69
|
private requiredChecklistErrors;
|
|
70
|
+
private checklistFileName;
|
|
71
|
+
private parseChecklistResult;
|
|
47
72
|
private asStringArray;
|
|
48
73
|
private parseReviewJson;
|
|
49
74
|
}
|
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.ReviewJson = exports.RequiredChecklist = exports.ChecklistAck = void 0;
|
|
3
|
+
exports.ReviewJsonService = exports.ChecklistVerdict = exports.CK_ACKED = exports.CK_MISSING = exports.CK_FAIL = exports.CK_OVERRIDDEN = exports.CK_PASS = exports.ReviewJson = exports.RequiredChecklist = exports.ChecklistResult = exports.ChecklistAck = void 0;
|
|
4
4
|
exports.prDirFor = prDirFor;
|
|
5
5
|
exports.reviewJsonPath = reviewJsonPath;
|
|
6
6
|
exports.reviewJsonSchemaHint = reviewJsonSchemaHint;
|
|
@@ -26,6 +26,27 @@ class ChecklistAck {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
exports.ChecklistAck = ChecklistAck;
|
|
29
|
+
// The verdict a reviewer wrote into a PER-CHECKLIST file `.webpieces/pr-review/<branch>/review-<id>.json`,
|
|
30
|
+
// one per triggered checklist. Replaces the single shared `checklists[]` array so concurrent reviewer
|
|
31
|
+
// subagents never clobber one file. Unlike ChecklistAck's bare boolean, this records the OUTCOME:
|
|
32
|
+
// success:true → PASS
|
|
33
|
+
// success:false + override non-empty → OVERRIDDEN (pass; the free-text justification reaches the PR)
|
|
34
|
+
// success:false + no override → FAIL (refuse; `output` is printed verbatim)
|
|
35
|
+
// `override` is deliberately free text, not a boolean — it forces the bypass to be stated in words and
|
|
36
|
+
// surfaces it on the dashboard, where a human sees it. Data-only (per CLAUDE.md).
|
|
37
|
+
class ChecklistResult {
|
|
38
|
+
id;
|
|
39
|
+
success;
|
|
40
|
+
output; // what the reviewer found; printed verbatim when a BLOCK checklist fails
|
|
41
|
+
override; // '' = no override; non-empty = ship-anyway justification (renders 🟡 overridden)
|
|
42
|
+
constructor(id, success, output, override) {
|
|
43
|
+
this.id = id;
|
|
44
|
+
this.success = success;
|
|
45
|
+
this.output = output;
|
|
46
|
+
this.override = override;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.ChecklistResult = ChecklistResult;
|
|
29
50
|
// What the CALLER (the pr-gate command) computed from the diff: the checklists this branch triggered.
|
|
30
51
|
// Drives BOTH review.json validation (BLOCK must be acknowledged) AND the printed schema hint (so the
|
|
31
52
|
// AI is told, at the moment it writes review.json, exactly which docs to read). Data-only.
|
|
@@ -36,14 +57,16 @@ class RequiredChecklist {
|
|
|
36
57
|
docs;
|
|
37
58
|
blockMessage;
|
|
38
59
|
matchedFiles; // the changed files that triggered it (for the dashboard + hint)
|
|
60
|
+
subagent; // expected reviewer agentType ('' = no provenance requirement); enforced by finish
|
|
39
61
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
40
|
-
constructor(id, title, severity, docs, blockMessage, matchedFiles) {
|
|
62
|
+
constructor(id, title, severity, docs, blockMessage, matchedFiles, subagent = '') {
|
|
41
63
|
this.id = id;
|
|
42
64
|
this.title = title;
|
|
43
65
|
this.severity = severity;
|
|
44
66
|
this.docs = docs;
|
|
45
67
|
this.blockMessage = blockMessage;
|
|
46
68
|
this.matchedFiles = matchedFiles;
|
|
69
|
+
this.subagent = subagent;
|
|
47
70
|
}
|
|
48
71
|
}
|
|
49
72
|
exports.RequiredChecklist = RequiredChecklist;
|
|
@@ -58,9 +81,10 @@ class ReviewJson {
|
|
|
58
81
|
violations; // pattern/architecture violations; length = the Pattern Violations count
|
|
59
82
|
risks;
|
|
60
83
|
filesToReview;
|
|
61
|
-
checklists; //
|
|
84
|
+
checklists; // legacy inline acknowledgments (back-compat); [] when none written
|
|
85
|
+
results; // resolved per-checklist verdicts (from review-<id>.json); [] when none
|
|
62
86
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
63
|
-
constructor(title, riskScore, riskLevel, riskEmoji, summary, violations, risks, filesToReview, checklists = []) {
|
|
87
|
+
constructor(title, riskScore, riskLevel, riskEmoji, summary, violations, risks, filesToReview, checklists = [], results = []) {
|
|
64
88
|
this.title = title;
|
|
65
89
|
this.riskScore = riskScore;
|
|
66
90
|
this.riskLevel = riskLevel;
|
|
@@ -70,9 +94,27 @@ class ReviewJson {
|
|
|
70
94
|
this.risks = risks;
|
|
71
95
|
this.filesToReview = filesToReview;
|
|
72
96
|
this.checklists = checklists;
|
|
97
|
+
this.results = results;
|
|
73
98
|
}
|
|
74
99
|
}
|
|
75
100
|
exports.ReviewJson = ReviewJson;
|
|
101
|
+
// A checklist's resolved outcome, shared by review.json enforcement and the dashboard so both agree.
|
|
102
|
+
exports.CK_PASS = 'pass'; // review-<id>.json success:true
|
|
103
|
+
exports.CK_OVERRIDDEN = 'overridden'; // review-<id>.json success:false + non-empty override → 🟡
|
|
104
|
+
exports.CK_FAIL = 'fail'; // review-<id>.json success:false + no override → refuse
|
|
105
|
+
exports.CK_MISSING = 'missing'; // no verdict file and no inline ack → refuse (BLOCK)
|
|
106
|
+
exports.CK_ACKED = 'acknowledged'; // legacy inline checklists[] ack satisfied (back-compat)
|
|
107
|
+
class ChecklistVerdict {
|
|
108
|
+
id;
|
|
109
|
+
status; // one of CK_PASS | CK_OVERRIDDEN | CK_FAIL | CK_MISSING | CK_ACKED
|
|
110
|
+
detail; // reviewer output / override justification / ack notes (for the dashboard + errors)
|
|
111
|
+
constructor(id, status, detail) {
|
|
112
|
+
this.id = id;
|
|
113
|
+
this.status = status;
|
|
114
|
+
this.detail = detail;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.ChecklistVerdict = ChecklistVerdict;
|
|
76
118
|
const RISK_LEVELS = ['green', 'yellow', 'red'];
|
|
77
119
|
const EMOJI_FOR_LEVEL = { green: '🟢', yellow: '🟡', red: '🔴' };
|
|
78
120
|
/** Locates + loads/validates the AI-authored review.json. `@injectable(bindingScopeValues.Singleton)` so it's drawn in the design. */
|
|
@@ -91,9 +133,6 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
91
133
|
// in the JSON shape PLUS an instruction block naming the docs to read — diff-derived instructions
|
|
92
134
|
// injected at exactly the moment the AI writes review.json.
|
|
93
135
|
reviewJsonSchemaHint(filePath, required = []) {
|
|
94
|
-
const checklistLine = required.length > 0
|
|
95
|
-
? `,\n "checklists": [{ "id": "<id from the list below>", "acknowledged": true, "notes": ["what you checked"] }]\n`
|
|
96
|
-
: `\n`;
|
|
97
136
|
return (`Write your PR review to:\n ${filePath}\n\n` +
|
|
98
137
|
`with this exact JSON shape (riskEmoji optional — derived from riskLevel):\n\n` +
|
|
99
138
|
`{\n` +
|
|
@@ -103,26 +142,36 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
103
142
|
` "summary": "5–10 sentence review summary",\n` +
|
|
104
143
|
` "violations": ["pattern/architecture violations you found (empty array if none)"],\n` +
|
|
105
144
|
` "risks": ["notable risks (empty array if none)"],\n` +
|
|
106
|
-
` "filesToReview": ["paths a human should look at (empty array if none)"]` +
|
|
107
|
-
checklistLine +
|
|
145
|
+
` "filesToReview": ["paths a human should look at (empty array if none)"]\n` +
|
|
108
146
|
`}` +
|
|
109
|
-
this.requiredChecklistHint(required));
|
|
147
|
+
this.requiredChecklistHint(filePath, required));
|
|
148
|
+
}
|
|
149
|
+
// The per-checklist review file path that sits beside review.json: review-<id>.json.
|
|
150
|
+
checklistResultPath(reviewJsonFilePath, checklistId) {
|
|
151
|
+
return path.join(path.dirname(reviewJsonFilePath), `review-${checklistId}.json`);
|
|
110
152
|
}
|
|
111
|
-
// The diff-triggered instruction block, appended ONLY when the branch triggered a checklist. This
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
|
|
153
|
+
// The diff-triggered instruction block, appended ONLY when the branch triggered a checklist. This is
|
|
154
|
+
// the consumer's review process, re-injected: read doc Y because the diff touched X, then write ONE
|
|
155
|
+
// file per checklist — `review-<id>.json` — so concurrent reviewer subagents never clobber a shared
|
|
156
|
+
// file. A BLOCK checklist with success:false and no override refuses to open the PR.
|
|
157
|
+
requiredChecklistHint(reviewJsonFilePath, required) {
|
|
115
158
|
if (required.length === 0)
|
|
116
159
|
return '';
|
|
117
|
-
const lines = ['', '', 'This branch triggered company review checklist(s).
|
|
118
|
-
lines.push('
|
|
160
|
+
const lines = ['', '', 'This branch triggered company review checklist(s). For EACH one below: READ its docs, walk'];
|
|
161
|
+
lines.push('the items against your diff, then write a SEPARATE file `review-<id>.json` beside review.json');
|
|
162
|
+
lines.push('with this shape (override optional — a free-text ship-anyway justification):');
|
|
163
|
+
lines.push('');
|
|
164
|
+
lines.push(' { "success": true, "output": "what you checked / what you found", "override": "" }');
|
|
119
165
|
lines.push('');
|
|
120
166
|
for (const req of required) {
|
|
121
167
|
const gate = req.severity === checklist_config_1.CHECKLIST_BLOCK
|
|
122
|
-
? 'BLOCK —
|
|
123
|
-
: 'WARN —
|
|
168
|
+
? 'BLOCK — success:false with no "override" will NOT open the PR'
|
|
169
|
+
: 'WARN — recorded on the dashboard; never blocks';
|
|
124
170
|
lines.push(` • [${req.id}] ${req.title} (${gate})`);
|
|
171
|
+
lines.push(` write: ${this.checklistResultPath(reviewJsonFilePath, req.id)}`);
|
|
125
172
|
lines.push(` docs to read: ${req.docs.join(', ')}`);
|
|
173
|
+
if (req.subagent.trim() !== '')
|
|
174
|
+
lines.push(` must be reviewed by the "${req.subagent.trim()}" subagent (its independent run is verified from the harness).`);
|
|
126
175
|
if (req.blockMessage.trim() !== '')
|
|
127
176
|
lines.push(` ${req.blockMessage.trim()}`);
|
|
128
177
|
if (req.matchedFiles.length > 0)
|
|
@@ -146,7 +195,7 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
146
195
|
throw new inform_ai_error_1.InformAiError(`Required review.json not found.\n\n${this.reviewJsonSchemaHint(filePath, required)}\n\n` +
|
|
147
196
|
`Then re-run: pnpm wp-finish-upsert-pr`);
|
|
148
197
|
}
|
|
149
|
-
const raw = this.parseReviewJson(fs.readFileSync(filePath, 'utf8'), filePath);
|
|
198
|
+
const raw = this.parseReviewJson(fs.readFileSync(filePath, 'utf8'), filePath, required);
|
|
150
199
|
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
151
200
|
throw new inform_ai_error_1.InformAiError(`review.json must be a JSON object.\n\n${this.reviewJsonSchemaHint(filePath, required)}`);
|
|
152
201
|
}
|
|
@@ -164,7 +213,8 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
164
213
|
errors.push('"title" must be a non-empty, imperative PR title describing the change (no branch names).');
|
|
165
214
|
}
|
|
166
215
|
const acks = this.parseChecklistAcks(raw['checklists']);
|
|
167
|
-
|
|
216
|
+
const results = this.loadChecklistResults(filePath, required);
|
|
217
|
+
for (const err of this.requiredChecklistErrors(required, acks, results))
|
|
168
218
|
errors.push(err);
|
|
169
219
|
if (errors.length > 0) {
|
|
170
220
|
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` +
|
|
@@ -176,7 +226,7 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
176
226
|
? raw['riskEmoji']
|
|
177
227
|
: (EMOJI_FOR_LEVEL[level] ?? '🟡');
|
|
178
228
|
const summary = typeof raw['summary'] === 'string' ? raw['summary'] : '';
|
|
179
|
-
return new ReviewJson(title, riskScore, level, emoji, summary, this.asStringArray(raw['violations']), this.asStringArray(raw['risks']), this.asStringArray(raw['filesToReview']), acks);
|
|
229
|
+
return new ReviewJson(title, riskScore, level, emoji, summary, this.asStringArray(raw['violations']), this.asStringArray(raw['risks']), this.asStringArray(raw['filesToReview']), acks, results);
|
|
180
230
|
}
|
|
181
231
|
// Parse the AI-authored `checklists[]` into typed ChecklistAck[]. Tolerant of a missing/garbage
|
|
182
232
|
// field (→ []) and of non-object entries (skipped) — malformed acks simply fail to satisfy a BLOCK
|
|
@@ -198,23 +248,87 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
198
248
|
}
|
|
199
249
|
return acks;
|
|
200
250
|
}
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
|
|
251
|
+
// Read the per-checklist verdict files `review-<id>.json` that sit beside review.json — one per
|
|
252
|
+
// triggered checklist. Tolerant like parseChecklistAcks: a missing file is simply absent from the
|
|
253
|
+
// result (→ falls back to the inline ack / counts as unmet for a BLOCK), and a malformed one is
|
|
254
|
+
// skipped (an unknown/stale review-<id>.json never wedges the branch).
|
|
255
|
+
loadChecklistResults(reviewJsonFilePath, required) {
|
|
256
|
+
const results = [];
|
|
257
|
+
for (const req of required) {
|
|
258
|
+
const p = this.checklistResultPath(reviewJsonFilePath, req.id);
|
|
259
|
+
if (!fs.existsSync(p))
|
|
260
|
+
continue;
|
|
261
|
+
const parsed = this.parseChecklistResult(p, req.id);
|
|
262
|
+
if (parsed)
|
|
263
|
+
results.push(parsed);
|
|
264
|
+
}
|
|
265
|
+
return results;
|
|
266
|
+
}
|
|
267
|
+
// Resolve ONE checklist's verdict from its per-file result (preferred) or its legacy inline ack.
|
|
268
|
+
// Central so review.json enforcement AND the finish-command dashboard agree on the outcome.
|
|
269
|
+
resolveVerdict(req, acks, results) {
|
|
270
|
+
const result = results.find((r) => r.id === req.id);
|
|
271
|
+
if (result) {
|
|
272
|
+
if (result.success)
|
|
273
|
+
return new ChecklistVerdict(req.id, exports.CK_PASS, result.output);
|
|
274
|
+
if (result.override.trim() !== '')
|
|
275
|
+
return new ChecklistVerdict(req.id, exports.CK_OVERRIDDEN, result.override.trim());
|
|
276
|
+
return new ChecklistVerdict(req.id, exports.CK_FAIL, result.output);
|
|
277
|
+
}
|
|
278
|
+
const ack = acks.find((a) => a.id === req.id);
|
|
279
|
+
if (ack && ack.acknowledged)
|
|
280
|
+
return new ChecklistVerdict(req.id, exports.CK_ACKED, ack.notes.join('; '));
|
|
281
|
+
return new ChecklistVerdict(req.id, exports.CK_MISSING, '');
|
|
282
|
+
}
|
|
283
|
+
// BLOCK requirements whose verdict is FAIL (reviewed, found a problem, no override) or MISSING (no
|
|
284
|
+
// verdict written at all) → one error each. WARN never blocks. Uses the consumer's blockMessage /
|
|
285
|
+
// the reviewer's `output` verbatim so the consumer owns the wording and webpieces owns the mechanism.
|
|
286
|
+
requiredChecklistErrors(required, acks, results) {
|
|
204
287
|
const errors = [];
|
|
205
288
|
for (const req of required) {
|
|
206
289
|
if (req.severity !== checklist_config_1.CHECKLIST_BLOCK)
|
|
207
290
|
continue;
|
|
208
|
-
const
|
|
209
|
-
if (
|
|
291
|
+
const verdict = this.resolveVerdict(req, acks, results);
|
|
292
|
+
if (verdict.status === exports.CK_FAIL) {
|
|
293
|
+
const msg = req.blockMessage.trim() !== '' ? `${req.blockMessage.trim()} ` : '';
|
|
294
|
+
errors.push(`Checklist "${req.id}" (${req.title}) FAILED review. ${msg}` +
|
|
295
|
+
`The reviewer wrote:\n ${verdict.detail.split('\n').join('\n ')}\n` +
|
|
296
|
+
` Fix it, then re-run; or set a non-empty "override" in ${this.checklistFileName(req.id)} to ship anyway with a stated justification.`);
|
|
297
|
+
}
|
|
298
|
+
else if (verdict.status === exports.CK_MISSING) {
|
|
210
299
|
const docs = req.docs.length > 0 ? ` Read: ${req.docs.join(', ')}.` : '';
|
|
211
300
|
const msg = req.blockMessage.trim() !== '' ? `${req.blockMessage.trim()} ` : '';
|
|
212
|
-
errors.push(`Checklist "${req.id}" (${req.title}) is REQUIRED for this diff but
|
|
213
|
-
`
|
|
301
|
+
errors.push(`Checklist "${req.id}" (${req.title}) is REQUIRED for this diff but has no verdict. ${msg}` +
|
|
302
|
+
`Write ${this.checklistFileName(req.id)} with {"success":true,"output":"…"} once you have walked it.${docs}`);
|
|
214
303
|
}
|
|
215
304
|
}
|
|
216
305
|
return errors;
|
|
217
306
|
}
|
|
307
|
+
checklistFileName(checklistId) {
|
|
308
|
+
return `review-${checklistId}.json`;
|
|
309
|
+
}
|
|
310
|
+
// Parse one review-<id>.json into a ChecklistResult, or null when malformed. Tolerant: missing
|
|
311
|
+
// `success` counts as false (fail-closed), `output`/`override` default to ''.
|
|
312
|
+
// webpieces-disable no-any-unknown -- opaque parsed JSON, narrowed field-by-field
|
|
313
|
+
parseChecklistResult(filePath, id) {
|
|
314
|
+
// webpieces-disable no-unmanaged-exceptions -- chokepoint: a malformed per-checklist file is skipped, not fatal
|
|
315
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
316
|
+
try {
|
|
317
|
+
// webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed below
|
|
318
|
+
const raw = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
319
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
|
|
320
|
+
return null;
|
|
321
|
+
const success = raw['success'] === true;
|
|
322
|
+
const output = typeof raw['output'] === 'string' ? raw['output'] : '';
|
|
323
|
+
const override = typeof raw['override'] === 'string' ? raw['override'] : '';
|
|
324
|
+
return new ChecklistResult(id, success, output, override);
|
|
325
|
+
}
|
|
326
|
+
catch (err) {
|
|
327
|
+
const error = (0, to_error_1.toError)(err);
|
|
328
|
+
void error;
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
218
332
|
// webpieces-disable no-any-unknown -- opaque parsed JSON value, narrowed to string[] here
|
|
219
333
|
asStringArray(value) {
|
|
220
334
|
if (!Array.isArray(value))
|
|
@@ -222,9 +336,11 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
222
336
|
// webpieces-disable no-any-unknown -- element of an opaque JSON array, narrowed by the type guard
|
|
223
337
|
return value.filter((v) => typeof v === 'string');
|
|
224
338
|
}
|
|
225
|
-
// Parse opaque AI-authored JSON, converting a SyntaxError into a readable InformAiError.
|
|
339
|
+
// Parse opaque AI-authored JSON, converting a SyntaxError into a readable InformAiError. `required`
|
|
340
|
+
// is threaded through so a JSON syntax error still prints the checklist instructions the AI needs —
|
|
341
|
+
// exactly when it most needs them — rather than the bare schema.
|
|
226
342
|
// webpieces-disable no-any-unknown -- returns the opaque parsed object; loadReviewJson narrows each field
|
|
227
|
-
parseReviewJson(raw, filePath) {
|
|
343
|
+
parseReviewJson(raw, filePath, required) {
|
|
228
344
|
// webpieces-disable no-unmanaged-exceptions -- chokepoint: convert JSON.parse SyntaxError to an InformAiError for the AI
|
|
229
345
|
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
230
346
|
try {
|
|
@@ -233,7 +349,7 @@ let ReviewJsonService = class ReviewJsonService {
|
|
|
233
349
|
}
|
|
234
350
|
catch (err) {
|
|
235
351
|
const error = (0, to_error_1.toError)(err);
|
|
236
|
-
throw new inform_ai_error_1.InformAiError(`review.json is not valid JSON (${error.message}).\n\n${this.reviewJsonSchemaHint(filePath)}\n\n` +
|
|
352
|
+
throw new inform_ai_error_1.InformAiError(`review.json is not valid JSON (${error.message}).\n\n${this.reviewJsonSchemaHint(filePath, required)}\n\n` +
|
|
237
353
|
`Then re-run: pnpm wp-finish-upsert-pr`);
|
|
238
354
|
}
|
|
239
355
|
}
|
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":";;;AAwRA,4BAEC;AAGD,wCAEC;AAGD,oDAEC;AAGD,wCAEC;;AAzSD,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAC3D,2CAA+D;AAC/D,yDAAqD;AACrD,uDAAkD;AAClD,yCAAqC;AAErC,sGAAsG;AACtG,wGAAwG;AACxG,MAAa,YAAY;IACrB,EAAE,CAAS;IACX,YAAY,CAAU;IACtB,KAAK,CAA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E,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 { CHECKLIST_BLOCK } from './checklist-config';\nimport { InformAiError } from './inform-ai-error';\nimport { toError } from './to-error';\n\n// One entry the AI writes into review.json's `checklists[]`: \"I read the doc for <id> and walked it\".\n// acknowledged: true is the AI attesting it did the walk — a SURFACING/AUDIT signal, not authorization.\nexport class ChecklistAck {\n id: string;\n acknowledged: boolean;\n notes: string[]; // per-item findings the AI chose to record (optional; [] when none)\n\n constructor(id: string, acknowledged: boolean, notes: string[]) {\n this.id = id;\n this.acknowledged = acknowledged;\n this.notes = notes;\n }\n}\n\n// What the CALLER (the pr-gate command) computed from the diff: the checklists this branch triggered.\n// Drives BOTH review.json validation (BLOCK must be acknowledged) AND the printed schema hint (so the\n// AI is told, at the moment it writes review.json, exactly which docs to read). Data-only.\nexport class RequiredChecklist {\n id: string;\n title: string;\n severity: string; // 'BLOCK' | 'WARN'\n docs: string[];\n blockMessage: string;\n matchedFiles: string[]; // the changed files that triggered it (for the dashboard + hint)\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(id: string, title: string, severity: string, docs: string[], blockMessage: string, matchedFiles: string[]) {\n this.id = id;\n this.title = title;\n this.severity = severity;\n this.docs = docs;\n this.blockMessage = blockMessage;\n this.matchedFiles = matchedFiles;\n }\n}\n\n// The AI-authored review for a PR. The AI writes this file itself between `wp-start-upsert-pr` (which\n// prints the schema) and `wp-finish-upsert-pr` (which reads it). 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 checklists: ChecklistAck[]; // consumer-checklist acknowledgments; [] when no checklists were required\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 checklists: ChecklistAck[] = [],\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.checklists = checklists;\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 // Copy-paste schema both commands print (write it / fix it). `required` is the set of consumer\n // checklists the diff triggered; when it is empty the output is byte-identical to before this\n // feature existed (non-adopting repos see no change). When non-empty it grows a `checklists` line\n // in the JSON shape PLUS an instruction block naming the docs to read — diff-derived instructions\n // injected at exactly the moment the AI writes review.json.\n reviewJsonSchemaHint(filePath: string, required: readonly RequiredChecklist[] = []): string {\n const checklistLine = required.length > 0\n ? `,\\n \"checklists\": [{ \"id\": \"<id from the list below>\", \"acknowledged\": true, \"notes\": [\"what you checked\"] }]\\n`\n : `\\n`;\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 checklistLine +\n `}` +\n this.requiredChecklistHint(required)\n );\n }\n\n // The diff-triggered instruction block, appended ONLY when the branch triggered a checklist. This\n // is the consumer's review process, re-injected: read doc Y because the diff touched X. BLOCK\n // entries must be acknowledged in `checklists[]` or wp-finish-upsert-pr refuses to open the PR.\n private requiredChecklistHint(required: readonly RequiredChecklist[]): string {\n if (required.length === 0) return '';\n const lines: string[] = ['', '', 'This branch triggered company review checklist(s). BEFORE writing review.json, READ each'];\n lines.push('doc, walk its items against your diff, then add a `checklists[]` entry acknowledging it:');\n lines.push('');\n for (const req of required) {\n const gate = req.severity === CHECKLIST_BLOCK\n ? 'BLOCK — the PR will NOT open until you acknowledge it'\n : 'WARN — acknowledge if it applies (never blocks)';\n lines.push(` • [${req.id}] ${req.title} (${gate})`);\n lines.push(` docs to read: ${req.docs.join(', ')}`);\n if (req.blockMessage.trim() !== '') lines.push(` ${req.blockMessage.trim()}`);\n if (req.matchedFiles.length > 0) lines.push(` triggered by: ${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. Returns a fully-populated ReviewJson on success.\n *\n * `required` is the set of consumer checklists the diff triggered (empty for non-adopting repos, in\n * which case this behaves byte-identically to before the feature). Every BLOCK entry must appear in\n * review.json's `checklists[]` with `acknowledged: true`, or a validation error is raised alongside\n * the usual ones so the AI gets ONE message. WARN entries are never validated; unknown ids in\n * `checklists[]` are ignored (forward-compat).\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);\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 acks = this.parseChecklistAcks(raw['checklists']);\n for (const err of this.requiredChecklistErrors(required, acks)) 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 acks,\n );\n }\n\n // Parse the AI-authored `checklists[]` into typed ChecklistAck[]. Tolerant of a missing/garbage\n // field (→ []) and of non-object entries (skipped) — malformed acks simply fail to satisfy a BLOCK\n // requirement rather than crashing the load.\n // webpieces-disable no-any-unknown -- opaque parsed JSON value, narrowed here\n private parseChecklistAcks(value: unknown): ChecklistAck[] {\n if (!Array.isArray(value)) return [];\n const acks: ChecklistAck[] = [];\n for (const entry of value) {\n if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) continue;\n // webpieces-disable no-any-unknown -- one opaque ack entry, narrowed field-by-field\n const e = entry as Record<string, unknown>;\n const id = typeof e['id'] === 'string' ? (e['id'] as string) : '';\n if (id === '') continue;\n acks.push(new ChecklistAck(id, e['acknowledged'] === true, this.asStringArray(e['notes'])));\n }\n return acks;\n }\n\n // BLOCK requirements that are not acknowledged → one error each, using the consumer's blockMessage\n // verbatim so the consumer owns the wording and webpieces owns the mechanism.\n private requiredChecklistErrors(required: readonly RequiredChecklist[], acks: readonly ChecklistAck[]): string[] {\n const errors: string[] = [];\n for (const req of required) {\n if (req.severity !== CHECKLIST_BLOCK) continue;\n const ack = acks.find((a: ChecklistAck): boolean => a.id === req.id);\n if (!ack || !ack.acknowledged) {\n const docs = req.docs.length > 0 ? ` Read: ${req.docs.join(', ')}.` : '';\n const msg = req.blockMessage.trim() !== '' ? `${req.blockMessage.trim()} ` : '';\n errors.push(\n `Checklist \"${req.id}\" (${req.title}) is REQUIRED for this diff but not acknowledged. ${msg}` +\n `Add {\"id\":\"${req.id}\",\"acknowledged\":true,\"notes\":[...]} to \"checklists\" once you have walked it.${docs}`,\n );\n }\n }\n return errors;\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, 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,yDAAqD;AACrD,uDAAkD;AAClD,yCAAqC;AAErC,sGAAsG;AACtG,wGAAwG;AACxG,MAAa,YAAY;IACrB,EAAE,CAAS;IACX,YAAY,CAAU;IACtB,KAAK,CAAW,CAAC,oEAAoE;IAErF,YAAY,EAAU,EAAE,YAAqB,EAAE,KAAe;QAC1D,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAVD,oCAUC;AAED,2GAA2G;AAC3G,sGAAsG;AACtG,kGAAkG;AAClG,8CAA8C;AAC9C,uGAAuG;AACvG,qFAAqF;AACrF,uGAAuG;AACvG,kFAAkF;AAClF,MAAa,eAAe;IACxB,EAAE,CAAS;IACX,OAAO,CAAU;IACjB,MAAM,CAAS,CAAG,yEAAyE;IAC3F,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,sGAAsG;AACtG,sGAAsG;AACtG,2FAA2F;AAC3F,MAAa,iBAAiB;IAC1B,EAAE,CAAS;IACX,KAAK,CAAS;IACd,QAAQ,CAAS,CAAC,mBAAm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,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,iBAAiB,CAqQ7B;AAED,0FAA0F;AAC1F,MAAM,aAAa,GAAG,IAAI,iBAAiB,EAAE,CAAC;AAE9C,wIAAwI;AACxI,SAAgB,QAAQ,CAAC,QAAgB,EAAE,WAAmB;IAC1D,OAAO,aAAa,CAAC,QAAQ,CAAC,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,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 { CHECKLIST_BLOCK } from './checklist-config';\nimport { InformAiError } from './inform-ai-error';\nimport { toError } from './to-error';\n\n// One entry the AI writes into review.json's `checklists[]`: \"I read the doc for <id> and walked it\".\n// acknowledged: true is the AI attesting it did the walk — a SURFACING/AUDIT signal, not authorization.\nexport class ChecklistAck {\n id: string;\n acknowledged: boolean;\n notes: string[]; // per-item findings the AI chose to record (optional; [] when none)\n\n constructor(id: string, acknowledged: boolean, notes: string[]) {\n this.id = id;\n this.acknowledged = acknowledged;\n this.notes = notes;\n }\n}\n\n// The verdict a reviewer wrote into a PER-CHECKLIST file `.webpieces/pr-review/<branch>/review-<id>.json`,\n// one per triggered checklist. Replaces the single shared `checklists[]` array so concurrent reviewer\n// subagents never clobber one file. Unlike ChecklistAck's bare boolean, this 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 bypass to be stated in words and\n// 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 a BLOCK 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 CALLER (the pr-gate command) computed from the diff: the checklists this branch triggered.\n// Drives BOTH review.json validation (BLOCK must be acknowledged) AND the printed schema hint (so the\n// AI is told, at the moment it writes review.json, exactly which docs to read). Data-only.\nexport class RequiredChecklist {\n id: string;\n title: string;\n severity: string; // 'BLOCK' | 'WARN'\n docs: string[];\n blockMessage: string;\n matchedFiles: string[]; // the changed files that triggered it (for the dashboard + hint)\n subagent: string; // expected reviewer agentType ('' = no provenance requirement); enforced by finish\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(id: string, title: string, severity: string, docs: string[], blockMessage: string, matchedFiles: string[], subagent = '') {\n this.id = id;\n this.title = title;\n this.severity = severity;\n this.docs = docs;\n this.blockMessage = blockMessage;\n this.matchedFiles = matchedFiles;\n this.subagent = subagent;\n }\n}\n\n// The AI-authored review for a PR. The AI writes this file itself between `wp-start-upsert-pr` (which\n// prints the schema) and `wp-finish-upsert-pr` (which reads it). 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 checklists: ChecklistAck[]; // legacy inline acknowledgments (back-compat); [] when none written\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 checklists: ChecklistAck[] = [],\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.checklists = checklists;\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 verdict file and no inline ack → refuse (BLOCK)\nexport const CK_ACKED = 'acknowledged'; // legacy inline checklists[] ack satisfied (back-compat)\n\nexport class ChecklistVerdict {\n id: string;\n status: string; // one of CK_PASS | CK_OVERRIDDEN | CK_FAIL | CK_MISSING | CK_ACKED\n detail: string; // reviewer output / override justification / ack notes (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\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 // Copy-paste schema both commands print (write it / fix it). `required` is the set of consumer\n // checklists the diff triggered; when it is empty the output is byte-identical to before this\n // feature existed (non-adopting repos see no change). When non-empty it grows a `checklists` line\n // in the JSON shape PLUS an instruction block naming the docs to read — diff-derived instructions\n // injected at exactly the moment the AI writes review.json.\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 diff-triggered instruction block, appended ONLY when the branch triggered a checklist. This is\n // the consumer's review process, re-injected: read doc Y because the diff touched X, then write ONE\n // file per checklist — `review-<id>.json` — so concurrent reviewer subagents never clobber a shared\n // file. A BLOCK checklist with success:false and no override refuses to open the PR.\n private requiredChecklistHint(reviewJsonFilePath: string, required: readonly RequiredChecklist[]): string {\n if (required.length === 0) return '';\n const lines: string[] = ['', '', 'This branch triggered company review checklist(s). For EACH one below: READ its docs, walk'];\n lines.push('the items against your diff, then write a SEPARATE file `review-<id>.json` beside review.json');\n lines.push('with this shape (override optional — a free-text ship-anyway justification):');\n lines.push('');\n lines.push(' { \"success\": true, \"output\": \"what you checked / what you found\", \"override\": \"\" }');\n lines.push('');\n for (const req of required) {\n const gate = req.severity === CHECKLIST_BLOCK\n ? 'BLOCK — success:false with no \"override\" will NOT open the PR'\n : 'WARN — recorded on the dashboard; never blocks';\n lines.push(` • [${req.id}] ${req.title} (${gate})`);\n lines.push(` write: ${this.checklistResultPath(reviewJsonFilePath, req.id)}`);\n lines.push(` docs to read: ${req.docs.join(', ')}`);\n if (req.subagent.trim() !== '') lines.push(` must be reviewed by the \"${req.subagent.trim()}\" subagent (its independent run is verified from the harness).`);\n if (req.blockMessage.trim() !== '') lines.push(` ${req.blockMessage.trim()}`);\n if (req.matchedFiles.length > 0) lines.push(` triggered by: ${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. Returns a fully-populated ReviewJson on success.\n *\n * `required` is the set of consumer checklists the diff triggered (empty for non-adopting repos, in\n * which case this behaves byte-identically to before the feature). Every BLOCK entry must appear in\n * review.json's `checklists[]` with `acknowledged: true`, or a validation error is raised alongside\n * the usual ones so the AI gets ONE message. WARN entries are never validated; unknown ids in\n * `checklists[]` are ignored (forward-compat).\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 acks = this.parseChecklistAcks(raw['checklists']);\n const results = this.loadChecklistResults(filePath, required);\n for (const err of this.requiredChecklistErrors(required, acks, 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 acks,\n results,\n );\n }\n\n // Parse the AI-authored `checklists[]` into typed ChecklistAck[]. Tolerant of a missing/garbage\n // field (→ []) and of non-object entries (skipped) — malformed acks simply fail to satisfy a BLOCK\n // requirement rather than crashing the load.\n // webpieces-disable no-any-unknown -- opaque parsed JSON value, narrowed here\n private parseChecklistAcks(value: unknown): ChecklistAck[] {\n if (!Array.isArray(value)) return [];\n const acks: ChecklistAck[] = [];\n for (const entry of value) {\n if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) continue;\n // webpieces-disable no-any-unknown -- one opaque ack entry, narrowed field-by-field\n const e = entry as Record<string, unknown>;\n const id = typeof e['id'] === 'string' ? (e['id'] as string) : '';\n if (id === '') continue;\n acks.push(new ChecklistAck(id, e['acknowledged'] === true, this.asStringArray(e['notes'])));\n }\n return acks;\n }\n\n // Read the per-checklist verdict files `review-<id>.json` that sit beside review.json — one per\n // triggered checklist. Tolerant like parseChecklistAcks: a missing file is simply absent from the\n // result (→ falls back to the inline ack / counts as unmet for a BLOCK), and a malformed one is\n // skipped (an unknown/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 per-file result (preferred) or its legacy inline ack.\n // Central so review.json enforcement AND the finish-command dashboard agree on the outcome.\n resolveVerdict(req: RequiredChecklist, acks: readonly ChecklistAck[], results: readonly ChecklistResult[]): ChecklistVerdict {\n const result = results.find((r: ChecklistResult): boolean => r.id === req.id);\n if (result) {\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 const ack = acks.find((a: ChecklistAck): boolean => a.id === req.id);\n if (ack && ack.acknowledged) return new ChecklistVerdict(req.id, CK_ACKED, ack.notes.join('; '));\n return new ChecklistVerdict(req.id, CK_MISSING, '');\n }\n\n // BLOCK requirements whose verdict is FAIL (reviewed, found a problem, no override) or MISSING (no\n // verdict written at all) → one error each. WARN never blocks. Uses the consumer's blockMessage /\n // the reviewer's `output` verbatim so the consumer owns the wording and webpieces owns the mechanism.\n private requiredChecklistErrors(required: readonly RequiredChecklist[], acks: readonly ChecklistAck[], results: readonly ChecklistResult[]): string[] {\n const errors: string[] = [];\n for (const req of required) {\n if (req.severity !== CHECKLIST_BLOCK) continue;\n const verdict = this.resolveVerdict(req, acks, results);\n if (verdict.status === CK_FAIL) {\n const msg = req.blockMessage.trim() !== '' ? `${req.blockMessage.trim()} ` : '';\n errors.push(\n `Checklist \"${req.id}\" (${req.title}) FAILED review. ${msg}` +\n `The reviewer wrote:\\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 docs = req.docs.length > 0 ? ` Read: ${req.docs.join(', ')}.` : '';\n const msg = req.blockMessage.trim() !== '' ? `${req.blockMessage.trim()} ` : '';\n errors.push(\n `Checklist \"${req.id}\" (${req.title}) is REQUIRED for this diff but has no verdict. ${msg}` +\n `Write ${this.checklistFileName(req.id)} with {\"success\":true,\"output\":\"…\"} once you have walked it.${docs}`,\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 // exactly when it most needs them — rather than the bare schema.\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"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const PROVENANCE_OK = "ok";
|
|
2
|
+
export declare const PROVENANCE_MISSING = "missing";
|
|
3
|
+
export declare const PROVENANCE_SKIPPED = "skipped";
|
|
4
|
+
export declare class ProvenanceResult {
|
|
5
|
+
status: string;
|
|
6
|
+
detail: string;
|
|
7
|
+
constructor(status: string, detail: string);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Verifies — from the Claude Code harness's OWN artifacts, never from anything the model asserts — that
|
|
11
|
+
* a subagent of a given `agentType` actually ran during the current session on the current branch. Used
|
|
12
|
+
* to enforce a checklist's optional `subagent:` field: that an INDEPENDENT reviewer looked, rather than
|
|
13
|
+
* the coding agent self-certifying.
|
|
14
|
+
*
|
|
15
|
+
* The harness writes, beside each subagent transcript:
|
|
16
|
+
* ~/.claude/projects/<cwd-slug>/<sessionId>/subagents/agent-<id>.meta.json → { agentType, spawnDepth, … }
|
|
17
|
+
* ~/.claude/projects/<cwd-slug>/<sessionId>/subagents/agent-<id>.jsonl → record 0 { isSidechain, gitBranch, … }
|
|
18
|
+
* `agentType`/`spawnDepth`/`isSidechain` are written by Claude Code, not by the model. We locate the dir
|
|
19
|
+
* by the unique sessionId (globbing `projects/*/<sessionId>/subagents`), so the cwd-slug never has to be
|
|
20
|
+
* derived/guessed.
|
|
21
|
+
*
|
|
22
|
+
* IMPORTANT — this is NOT tamper-proof. A determined agent can `cat >` a fake agent-*.meta.json. This
|
|
23
|
+
* raises the bar from "trust the model's word" to "deliberate, auditable forgery outside the repo"; it
|
|
24
|
+
* is not cryptographic. Say so wherever `subagent:` is documented.
|
|
25
|
+
*
|
|
26
|
+
* `@injectable(bindingScopeValues.Singleton)` so it is drawn in the DI design and injected by type.
|
|
27
|
+
*/
|
|
28
|
+
export declare class SubagentProvenanceService {
|
|
29
|
+
verify(expectedAgentType: string, branch: string): ProvenanceResult;
|
|
30
|
+
private findSubagentsDir;
|
|
31
|
+
private metaFiles;
|
|
32
|
+
private agentIdOf;
|
|
33
|
+
private sidechainOnBranch;
|
|
34
|
+
private stripWp;
|
|
35
|
+
private readDir;
|
|
36
|
+
private firstNonEmptyLine;
|
|
37
|
+
private readJson;
|
|
38
|
+
private parseLine;
|
|
39
|
+
}
|