@webpieces/pr-gate 0.4.837 → 0.4.838
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 +6 -4
- package/src/scripts/commands/cleanup-command.d.ts +2 -1
- package/src/scripts/commands/cleanup-command.js +13 -12
- package/src/scripts/commands/cleanup-command.js.map +1 -1
- package/src/scripts/commands/finish-upsert-pr-command.js +5 -3
- package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/human-post-pr-command.d.ts +2 -1
- package/src/scripts/commands/human-post-pr-command.js +3 -2
- package/src/scripts/commands/human-post-pr-command.js.map +1 -1
- package/src/scripts/commands/land-pr-command.d.ts +2 -1
- package/src/scripts/commands/land-pr-command.js +12 -9
- package/src/scripts/commands/land-pr-command.js.map +1 -1
- package/src/scripts/commands/reap-worktree-command.d.ts +2 -1
- package/src/scripts/commands/reap-worktree-command.js +4 -2
- package/src/scripts/commands/reap-worktree-command.js.map +1 -1
- package/src/scripts/commands/sync-main-command.js +2 -1
- package/src/scripts/commands/sync-main-command.js.map +1 -1
- package/src/scripts/commands/upsert-hotfix-pr-command.d.ts +2 -1
- package/src/scripts/commands/upsert-hotfix-pr-command.js +2 -1
- package/src/scripts/commands/upsert-hotfix-pr-command.js.map +1 -1
- package/src/scripts/commands/worktree-cleanup.d.ts +1 -1
- package/src/scripts/commands/worktree-cleanup.js +11 -11
- package/src/scripts/commands/worktree-cleanup.js.map +1 -1
- package/src/scripts/commands/write-review-command.js +13 -10
- package/src/scripts/commands/write-review-command.js.map +1 -1
- package/src/scripts/commands/write-review-fixes-command.js +3 -2
- package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
- package/src/scripts/pr-gate-cli-app.js +2 -1
- package/src/scripts/pr-gate-cli-app.js.map +1 -1
- package/src/scripts/workflow/build-affected.d.ts +2 -1
- package/src/scripts/workflow/build-affected.js +2 -1
- package/src/scripts/workflow/build-affected.js.map +1 -1
- package/src/scripts/workflow/cleanTmp.d.ts +2 -1
- package/src/scripts/workflow/cleanTmp.js +3 -2
- package/src/scripts/workflow/cleanTmp.js.map +1 -1
- package/src/scripts/workflow/diff-materializer.js +2 -1
- package/src/scripts/workflow/diff-materializer.js.map +1 -1
- package/src/scripts/workflow/gate-log-file.js +5 -4
- package/src/scripts/workflow/gate-log-file.js.map +1 -1
- package/src/scripts/workflow/generated-artifact-registry.js +2 -1
- package/src/scripts/workflow/generated-artifact-registry.js.map +1 -1
- package/src/scripts/workflow/hotfix-redirect.d.ts +1 -1
- package/src/scripts/workflow/hotfix-redirect.js +2 -1
- package/src/scripts/workflow/hotfix-redirect.js.map +1 -1
- package/src/scripts/workflow/landed-tree-resolver.d.ts +1 -1
- package/src/scripts/workflow/landed-tree-resolver.js +2 -2
- package/src/scripts/workflow/landed-tree-resolver.js.map +1 -1
- package/src/scripts/workflow/landed-worktree-reaper.d.ts +1 -1
- package/src/scripts/workflow/landed-worktree-reaper.js +2 -1
- package/src/scripts/workflow/landed-worktree-reaper.js.map +1 -1
- package/src/scripts/workflow/merge-end.d.ts +1 -1
- package/src/scripts/workflow/merge-end.js +6 -5
- package/src/scripts/workflow/merge-end.js.map +1 -1
- package/src/scripts/workflow/merge-info-index.d.ts +1 -1
- package/src/scripts/workflow/merge-info-index.js +5 -4
- package/src/scripts/workflow/merge-info-index.js.map +1 -1
- package/src/scripts/workflow/merge-start.d.ts +1 -1
- package/src/scripts/workflow/merge-start.js +11 -9
- package/src/scripts/workflow/merge-start.js.map +1 -1
- package/src/scripts/workflow/merge-state.d.ts +1 -1
- package/src/scripts/workflow/merge-state.js +3 -2
- package/src/scripts/workflow/merge-state.js.map +1 -1
- package/src/scripts/workflow/provenance-enforcer.js +5 -4
- package/src/scripts/workflow/provenance-enforcer.js.map +1 -1
- package/src/scripts/workflow/push-dev-state.d.ts +1 -1
- package/src/scripts/workflow/push-dev-state.js +4 -2
- package/src/scripts/workflow/push-dev-state.js.map +1 -1
- package/src/scripts/workflow/review-round-state.d.ts +2 -1
- package/src/scripts/workflow/review-round-state.js +22 -20
- package/src/scripts/workflow/review-round-state.js.map +1 -1
- package/src/scripts/workflow/review-stage-receipt.js +2 -1
- package/src/scripts/workflow/review-stage-receipt.js.map +1 -1
- package/src/scripts/workflow/reviewer-briefing-builder.js +2 -1
- package/src/scripts/workflow/reviewer-briefing-builder.js.map +1 -1
- package/src/scripts/workflow/reviewer-identity.d.ts +1 -1
- package/src/scripts/workflow/reviewer-identity.js +8 -7
- package/src/scripts/workflow/reviewer-identity.js.map +1 -1
- package/src/scripts/workflow/reviewer-verdict-gate.js +2 -1
- package/src/scripts/workflow/reviewer-verdict-gate.js.map +1 -1
- package/src/scripts/workflow/run-update.d.ts +1 -1
- package/src/scripts/workflow/run-update.js +4 -4
- package/src/scripts/workflow/run-update.js.map +1 -1
- package/src/scripts/workflow/verdict-provenance.d.ts +2 -1
- package/src/scripts/workflow/verdict-provenance.js +10 -7
- package/src/scripts/workflow/verdict-provenance.js.map +1 -1
|
@@ -5,6 +5,8 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const fs = tslib_1.__importStar(require("fs"));
|
|
6
6
|
const path = tslib_1.__importStar(require("path"));
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
9
|
+
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
8
10
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
9
11
|
const inversify_1 = require("inversify");
|
|
10
12
|
const verdict_provenance_1 = require("./verdict-provenance");
|
|
@@ -198,7 +200,7 @@ let ReviewRoundStateService = class ReviewRoundStateService {
|
|
|
198
200
|
return new ReviewRoundPlan(exports.ROUND_ACTION_REVIEW, 1, maxRounds, fullBasis);
|
|
199
201
|
if (!snap.complete) {
|
|
200
202
|
if (snap.headSha !== fullBasis.headSha) {
|
|
201
|
-
throw new
|
|
203
|
+
throw new tooling_common_1.InformAiError(`Reviewer round ${snap.round} of ${maxRounds} is still active at `
|
|
202
204
|
+ `${snap.headSha.slice(0, 8)}. Finish that fixed roster before changing the reviewed HEAD.`);
|
|
203
205
|
}
|
|
204
206
|
return new ReviewRoundPlan(exports.ROUND_ACTION_RESUME, snap.round, maxRounds, fullBasis);
|
|
@@ -232,23 +234,23 @@ let ReviewRoundStateService = class ReviewRoundStateService {
|
|
|
232
234
|
writeRemediation(repoRoot, summaryPath, receipt, json) {
|
|
233
235
|
const snap = this.snapshot(summaryPath, receipt);
|
|
234
236
|
if (!snap.complete) {
|
|
235
|
-
throw new
|
|
237
|
+
throw new tooling_common_1.InformAiError('wp-write-review-fixes: the active reviewer round is not complete yet.');
|
|
236
238
|
}
|
|
237
239
|
const blocking = this.blockingIds(summaryPath, snap);
|
|
238
240
|
if (blocking.length === 0) {
|
|
239
|
-
throw new
|
|
241
|
+
throw new tooling_common_1.InformAiError(`wp-write-review-fixes: round ${snap.round} has no red or orange verdict to fix.`);
|
|
240
242
|
}
|
|
241
243
|
const out = this.fixesPath(summaryPath, snap.round);
|
|
242
244
|
const holding = this.validFixes(repoRoot, summaryPath, snap);
|
|
243
245
|
if (holding !== null) {
|
|
244
|
-
throw new
|
|
246
|
+
throw new tooling_common_1.InformAiError(`wp-write-review-fixes: the fixes for round ${snap.round} are already recorded in ${out}, and `
|
|
245
247
|
+ `that record still holds (its fixed commit ${holding.toHead.slice(0, 8)} is in HEAD's history), so it is not `
|
|
246
248
|
+ 'overwritten. Nothing more to record: re-run pnpm wp-review-upsert-pr, or pnpm wp-finish-upsert-pr after the last round.');
|
|
247
249
|
}
|
|
248
250
|
this.assertClean(repoRoot);
|
|
249
251
|
const currentHead = this.git(repoRoot, ['rev-parse', 'HEAD']);
|
|
250
252
|
if (currentHead === snap.headSha || this.git(repoRoot, ['diff', '--name-only', snap.headSha, currentHead]) === '') {
|
|
251
|
-
throw new
|
|
253
|
+
throw new tooling_common_1.InformAiError('wp-write-review-fixes: remediation must contain a committed, non-empty delta after the reviewed HEAD.');
|
|
252
254
|
}
|
|
253
255
|
const raw = this.parseObject(json, 'wp-write-review-fixes: input must be one JSON object.');
|
|
254
256
|
const agent = this.requiredText(raw, 'agent');
|
|
@@ -258,7 +260,7 @@ let ReviewRoundStateService = class ReviewRoundStateService {
|
|
|
258
260
|
const unknown = ids.filter((id) => !blocking.includes(id));
|
|
259
261
|
const missing = blocking.filter((id) => !ids.includes(id));
|
|
260
262
|
if (unknown.length > 0 || missing.length > 0) {
|
|
261
|
-
throw new
|
|
263
|
+
throw new tooling_common_1.InformAiError(`wp-write-review-fixes: responses must cover exactly the red/orange checklist(s) of round ${snap.round}. `
|
|
262
264
|
+ `Unknown: ${unknown.join(', ') || '(none)'}. Missing: ${missing.join(', ') || '(none)'}.`);
|
|
263
265
|
}
|
|
264
266
|
this.supersede(out);
|
|
@@ -374,7 +376,7 @@ let ReviewRoundStateService = class ReviewRoundStateService {
|
|
|
374
376
|
responses(value) {
|
|
375
377
|
const responses = this.responsesOrEmpty(value);
|
|
376
378
|
if (responses.length === 0)
|
|
377
|
-
throw new
|
|
379
|
+
throw new tooling_common_1.InformAiError('wp-write-review-fixes: "responses" must be a non-empty array.');
|
|
378
380
|
return responses;
|
|
379
381
|
}
|
|
380
382
|
responsesOrEmpty(value) {
|
|
@@ -397,7 +399,7 @@ let ReviewRoundStateService = class ReviewRoundStateService {
|
|
|
397
399
|
requiredText(raw, key) {
|
|
398
400
|
const value = this.text(raw[key]);
|
|
399
401
|
if (value === '')
|
|
400
|
-
throw new
|
|
402
|
+
throw new tooling_common_1.InformAiError(`wp-write-review-fixes: "${key}" must be a non-empty string.`);
|
|
401
403
|
return value;
|
|
402
404
|
}
|
|
403
405
|
text(value) {
|
|
@@ -413,10 +415,10 @@ let ReviewRoundStateService = class ReviewRoundStateService {
|
|
|
413
415
|
// webpieces-disable no-any-unknown -- the language types caught JavaScript values as unknown
|
|
414
416
|
}
|
|
415
417
|
catch (err) {
|
|
416
|
-
const error = (0,
|
|
418
|
+
const error = (0, to_error_1.toError)(err);
|
|
417
419
|
void error;
|
|
418
420
|
}
|
|
419
|
-
throw new
|
|
421
|
+
throw new tooling_common_1.InformAiError(message);
|
|
420
422
|
}
|
|
421
423
|
readObject(file) {
|
|
422
424
|
if (!fs.existsSync(file))
|
|
@@ -427,20 +429,20 @@ let ReviewRoundStateService = class ReviewRoundStateService {
|
|
|
427
429
|
const value = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
428
430
|
if (typeof value === 'object' && value !== null && !Array.isArray(value))
|
|
429
431
|
return value;
|
|
430
|
-
throw new
|
|
432
|
+
throw new tooling_common_1.InformAiError(`Review state file must contain one JSON object: ${file}`);
|
|
431
433
|
// webpieces-disable no-any-unknown -- the language types caught JavaScript values as unknown
|
|
432
434
|
}
|
|
433
435
|
catch (err) {
|
|
434
|
-
const error = (0,
|
|
435
|
-
if (error instanceof
|
|
436
|
+
const error = (0, to_error_1.toError)(err);
|
|
437
|
+
if (error instanceof tooling_common_1.InformAiError)
|
|
436
438
|
throw error;
|
|
437
|
-
throw new
|
|
439
|
+
throw new tooling_common_1.InformAiError(`Could not read review state file ${file}: ${error.message}`, { cause: error });
|
|
438
440
|
}
|
|
439
441
|
}
|
|
440
442
|
assertClean(repoRoot) {
|
|
441
443
|
const status = this.git(repoRoot, ['status', '--porcelain', '--untracked-files=all']);
|
|
442
444
|
if (status !== '')
|
|
443
|
-
throw new
|
|
445
|
+
throw new tooling_common_1.InformAiError('wp-write-review-fixes: commit every remediation and leave no staged, unstaged, or untracked files first.');
|
|
444
446
|
}
|
|
445
447
|
/**
|
|
446
448
|
* `git merge-base --is-ancestor`: exit 0 = yes, 1 = no. A `sha` git does not know (exit 128 with
|
|
@@ -456,8 +458,8 @@ let ReviewRoundStateService = class ReviewRoundStateService {
|
|
|
456
458
|
const detail = (result.stderr ?? '').trim() || result.error?.message || `exit ${result.status ?? 'unknown'}`;
|
|
457
459
|
const message = `Review-round Git command failed: git merge-base --is-ancestor ${sha} HEAD\n${detail}`;
|
|
458
460
|
if (result.error !== undefined)
|
|
459
|
-
throw new
|
|
460
|
-
throw new
|
|
461
|
+
throw new tooling_common_1.InformAiError(message, { cause: result.error });
|
|
462
|
+
throw new tooling_common_1.InformAiError(message);
|
|
461
463
|
}
|
|
462
464
|
git(repoRoot, args) {
|
|
463
465
|
const result = (0, child_process_1.spawnSync)('git', args, { cwd: repoRoot, encoding: 'utf8' });
|
|
@@ -467,8 +469,8 @@ let ReviewRoundStateService = class ReviewRoundStateService {
|
|
|
467
469
|
const detail = (result.stderr ?? '').trim() || result.error?.message || `exit ${result.status ?? 'unknown'}`;
|
|
468
470
|
const message = `Review-round Git command failed: ${command}\n${detail}`;
|
|
469
471
|
if (result.error !== undefined)
|
|
470
|
-
throw new
|
|
471
|
-
throw new
|
|
472
|
+
throw new tooling_common_1.InformAiError(message, { cause: result.error });
|
|
473
|
+
throw new tooling_common_1.InformAiError(message);
|
|
472
474
|
}
|
|
473
475
|
};
|
|
474
476
|
exports.ReviewRoundStateService = ReviewRoundStateService;
|
|
@@ -476,6 +478,6 @@ exports.ReviewRoundStateService = ReviewRoundStateService = tslib_1.__decorate([
|
|
|
476
478
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
477
479
|
tslib_1.__metadata("design:paramtypes", [rules_config_1.ReviewJsonService,
|
|
478
480
|
verdict_provenance_1.VerdictProvenanceService,
|
|
479
|
-
|
|
481
|
+
tooling_common_1.AtomicFile])
|
|
480
482
|
], ReviewRoundStateService);
|
|
481
483
|
//# sourceMappingURL=review-round-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"review-round-state.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/review-round-state.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,iDAA0C;AAC1C,0DAEiC;AACjC,yCAA2D;AAE3D,6DAAgE;AAChE,6CAAyC;AAM5B,QAAA,mBAAmB,GAAG,QAAQ,CAAC;AAC/B,QAAA,mB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,EAAE,CAAC;QACzE,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS;YAAE,MAAM,IAAI,4BAAa,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QAC1F,MAAM,IAAI,4BAAa,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;CACJ,CAAA;AA7WY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGJ,gCAAiB;QACjB,6CAAwB;QACxB,yBAAU;GAJlC,uBAAuB,CA6WnC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { spawnSync } from 'child_process';\nimport {\n AtomicFile, ChecklistResult, InformAiError, ReviewJsonService, VERDICT_ORANGE, VERDICT_RED, toError,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ReviewStageReceipt } from './review-stage-receipt';\nimport { VerdictProvenanceService } from './verdict-provenance';\nimport { DiffBasis } from './diff-basis';\n\ntype JsonPrimitive = string | number | boolean | null;\ntype JsonValue = JsonPrimitive | JsonValue[] | JsonObject;\ninterface JsonObject { [key: string]: JsonValue }\n\nexport const ROUND_ACTION_REVIEW = 'review';\nexport const ROUND_ACTION_RESUME = 'resume';\nexport const ROUND_ACTION_FIX = 'fix';\nexport const ROUND_ACTION_RECORD = 'record';\nexport const ROUND_ACTION_FINISH = 'finish';\n\n/** Every round-numbered file of a branch's review lives beside summary.json under this prefix (issue #1053). */\nconst ROUND_FILE = /^review-round(\\d+)-(.+)\\.json$/;\nconst FIXES_ID = 'fixes';\nconst PROVENANCE_SUFFIX = '.provenance';\n\nexport class ReviewRoundPlan {\n action: string;\n round: number;\n maxRounds: number;\n basis: DiffBasis;\n changedFiles: string[];\n redChecklistIds: string[];\n /** The final round's ORANGE checklists — must-fix, never re-reviewed (issue #1053). */\n orangeChecklistIds: string[];\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n action: string, round: number, maxRounds: number, basis: DiffBasis, changedFiles: string[] = [],\n redChecklistIds: string[] = [], orangeChecklistIds: string[] = [],\n ) {\n this.action = action;\n this.round = round;\n this.maxRounds = maxRounds;\n this.basis = basis;\n this.changedFiles = changedFiles;\n this.redChecklistIds = redChecklistIds;\n this.orangeChecklistIds = orangeChecklistIds;\n }\n}\n\n/**\n * Where a branch's review stands, DERIVED from the round-numbered files on disk plus the stage-② receipt\n * (issue #1053). There is no separate round counter: `round` is the highest round any file or briefing\n * names. Data-only.\n */\nexport class RoundSnapshot {\n round: number; // 0 = no round has started\n roster: string[]; // the REQUIRED checklists briefed in `round`, plus the optional ones that submitted in it\n headSha: string; // the commit `round` was briefed on\n complete: boolean; // every REQUIRED checklist briefed in `round` has a verdict in it (issue #1062)\n\n constructor(round: number, roster: string[], headSha: string, complete: boolean) {\n this.round = round;\n this.roster = roster;\n this.headSha = headSha;\n this.complete = complete;\n }\n}\n\nexport class RemediationResponse {\n checklistId: string;\n resolution: string;\n files: string[];\n\n constructor(checklistId: string, resolution: string, files: string[]) {\n this.checklistId = checklistId;\n this.resolution = resolution;\n this.files = files;\n }\n}\n\n/** The author's recorded fixes for one completed round: `review-round<N>-fixes.json`. Data-only. */\nexport class ReviewRemediation {\n agent: string;\n model: string;\n fromHead: string;\n toHead: string;\n responses: RemediationResponse[];\n writtenAt: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(agent: string, model: string, fromHead: string, toHead: string, responses: RemediationResponse[]) {\n this.agent = agent;\n this.model = model;\n this.fromHead = fromHead;\n this.toHead = toHead;\n this.responses = responses;\n this.writtenAt = new Date().toISOString();\n }\n}\n\n/**\n * The reviewer rounds of one branch, read from their round-numbered files (issue #1053).\n *\n * `commands.pr-gate.maxReviewerRounds` is a HARD CEILING, not a quota: 1 round means 1 round. Three rules\n * follow from it, and everything here exists to hold them:\n *\n * 1. Every verdict is `review-round<N>-<id>.json` (+ `.provenance.json`), every author fix record is\n * `review-round<N>-fixes.json`, and nothing is ever overwritten. The live verdict of a checklist is its\n * highest round; the round the branch is on is the highest round any file names.\n * 2. A new round starts ONLY when the previous round has a RED and rounds remain, and it re-briefs only\n * those reds. A green or yellow stands whatever changes afterwards — staleness never re-reviews.\n * 3. The final round has no red. Its blocking color is ORANGE: the author fixes it best effort, records the\n * fix, and ships with the finding and its claimed fix stamped on the dashboard.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewRoundStateService {\n constructor(\n private readonly reviewJson: ReviewJsonService,\n private readonly provenance: VerdictProvenanceService,\n private readonly atomicFile: AtomicFile,\n ) {}\n\n /** The author's recorded fixes for one round: `review-round<N>-fixes.json`, beside summary.json. */\n fixesPath(summaryPath: string, round: number): string {\n return path.join(path.dirname(summaryPath), `review-round${round}-${FIXES_ID}.json`);\n }\n\n /** The highest round any round-numbered file names, or 0. */\n highestRound(summaryPath: string): number {\n let highest = 0;\n for (const name of this.roundFiles(summaryPath)) {\n const match = ROUND_FILE.exec(name);\n if (match !== null) highest = Math.max(highest, Number(match[1]));\n }\n return highest;\n }\n\n /** Every checklist that has a verdict in ANY round on this branch. */\n verdictChecklistIds(summaryPath: string): string[] {\n const ids = new Set<string>();\n for (const name of this.roundFiles(summaryPath)) {\n const id = this.verdictIdOf(name);\n if (id !== '') ids.add(id);\n }\n return [...ids].sort();\n }\n\n /** Where the branch's review stands — see {@link RoundSnapshot}. */\n snapshot(summaryPath: string, receipt: ReviewStageReceipt | null): RoundSnapshot {\n const briefed = receipt !== null && receipt.reviewersBriefed.length > 0 ? receipt.round : 0;\n const round = Math.max(this.highestRound(summaryPath), briefed);\n if (round < 1) return new RoundSnapshot(0, [], '', false);\n if (receipt !== null && receipt.round === round) {\n // Only a REQUIRED checklist holds the round open (issue #1062). An optional one counts only if it\n // actually ran — a red from it still opens the next round — and one nobody chose to run is not\n // waited on, so an all-optional briefing nobody ran is complete with an empty roster.\n const optional = new Set<string>(receipt.optionalBriefed);\n const required = receipt.reviewersBriefed.filter((id: string): boolean => !optional.has(id));\n const roster = receipt.reviewersBriefed.filter((id: string): boolean =>\n !optional.has(id) || this.hasVerdict(summaryPath, id, round));\n return new RoundSnapshot(round, roster, receipt.headSha, this.everyVerdictIn(summaryPath, required, round));\n }\n // The receipt names an older round (or is gone): the files are the record, so the roster is exactly\n // the checklists that have a verdict in this round, and the reviewed HEAD is what their provenance says.\n const roster = this.roundFiles(summaryPath)\n .filter((name: string): boolean => name.startsWith(`review-round${round}-`))\n .map((name: string): string => this.verdictIdOf(name))\n .filter((id: string): boolean => id !== '')\n .sort();\n const headSha = roster.length === 0 ? '' : this.provenance.read(summaryPath, roster[0], round)?.headSha ?? '';\n return new RoundSnapshot(round, roster, headSha, roster.length > 0);\n }\n\n /**\n * TRUE once a review round has started on this branch. From then on the checklist set is FROZEN (issue\n * #1053): finish judges only the checklists that were briefed, never ones a later commit newly triggers.\n */\n roundStarted(summaryPath: string, receipt: ReviewStageReceipt | null): boolean {\n return this.snapshot(summaryPath, receipt).round >= 1;\n }\n\n /**\n * The frozen checklist set: every checklist briefed in any round — see {@link roundStarted}. It keeps an\n * optional checklist that was offered but never run, so its dashboard row reads \"optional, not run\"\n * rather than \"not briefed\"; it never holds a round open (see {@link snapshot}).\n */\n briefedChecklistIds(summaryPath: string, receipt: ReviewStageReceipt | null): string[] {\n const ids = new Set<string>(this.verdictChecklistIds(summaryPath));\n if (receipt !== null && receipt.round >= 1) for (const id of receipt.reviewersBriefed) ids.add(id);\n return [...ids].sort();\n }\n\n /** Does `checklistId` already have a verdict in `round`? A round's verdict is never overwritten. */\n hasVerdict(summaryPath: string, checklistId: string, round: number): boolean {\n return fs.existsSync(this.reviewJson.checklistResultPath(summaryPath, checklistId, round));\n }\n\n /** The roster checklists whose verdict in the snapshot's round is `status`. */\n checklistIdsWithStatus(summaryPath: string, snap: RoundSnapshot, status: string): string[] {\n if (!snap.complete) return [];\n return snap.roster.filter((id: string): boolean => {\n const raw = this.readObject(this.reviewJson.checklistResultPath(summaryPath, id, snap.round));\n return raw !== null && raw['status'] === status;\n });\n }\n\n /** What stage ② does next. See the class comment for the three rules it holds. */\n plan(repoRoot: string, summaryPath: string, receipt: ReviewStageReceipt | null, maxRounds: number, fullBasis: DiffBasis): ReviewRoundPlan {\n const snap = this.snapshot(summaryPath, receipt);\n if (snap.round < 1) return new ReviewRoundPlan(ROUND_ACTION_REVIEW, 1, maxRounds, fullBasis);\n if (!snap.complete) {\n if (snap.headSha !== fullBasis.headSha) {\n throw new InformAiError(`Reviewer round ${snap.round} of ${maxRounds} is still active at `\n + `${snap.headSha.slice(0, 8)}. Finish that fixed roster before changing the reviewed HEAD.`);\n }\n return new ReviewRoundPlan(ROUND_ACTION_RESUME, snap.round, maxRounds, fullBasis);\n }\n const reds = this.checklistIdsWithStatus(summaryPath, snap, VERDICT_RED);\n const oranges = this.checklistIdsWithStatus(summaryPath, snap, VERDICT_ORANGE);\n // No red, or no round left: nothing is ever re-reviewed. Oranges are the author's to fix and record.\n if (reds.length === 0 || snap.round >= maxRounds) {\n return new ReviewRoundPlan(ROUND_ACTION_FINISH, snap.round, maxRounds, fullBasis, [], reds, oranges);\n }\n if (snap.headSha === fullBasis.headSha) {\n return new ReviewRoundPlan(ROUND_ACTION_FIX, snap.round, maxRounds, fullBasis, [], reds, oranges);\n }\n if (this.validFixes(repoRoot, summaryPath, snap) === null) {\n return new ReviewRoundPlan(ROUND_ACTION_RECORD, snap.round, maxRounds, fullBasis, [], reds, oranges);\n }\n const basis = new DiffBasis(\n snap.headSha, fullBasis.headSha, false, [],\n `git diff ${snap.headSha} ${fullBasis.headSha}`,\n `git diff ${snap.headSha} ${fullBasis.headSha} -- <file>`, fullBasis.hashMainHead);\n const changed = this.git(repoRoot, ['diff', '--name-only', snap.headSha, fullBasis.headSha])\n .split('\\n').filter((f: string): boolean => f.trim() !== '');\n return new ReviewRoundPlan(ROUND_ACTION_REVIEW, snap.round + 1, maxRounds, basis, changed, reds, oranges);\n }\n\n /**\n * Record the author's fixes for the latest completed round — one response per RED (a round that is not\n * the last) or ORANGE (the final round) — as `review-round<N>-fixes.json`.\n *\n * A record that still HOLDS is never overwritten. One that no longer holds — its `toHead` left HEAD's\n * history, which every `wp-start-upsert-pr` squash-update does — is kept beside it as\n * `review-round<N>-fixes.json.superseded-<k>` and a fresh record is written, so re-recording is always\n * the way past a stale record and nothing is ever lost.\n */\n writeRemediation(repoRoot: string, summaryPath: string, receipt: ReviewStageReceipt, json: string): string {\n const snap = this.snapshot(summaryPath, receipt);\n if (!snap.complete) {\n throw new InformAiError('wp-write-review-fixes: the active reviewer round is not complete yet.');\n }\n const blocking = this.blockingIds(summaryPath, snap);\n if (blocking.length === 0) {\n throw new InformAiError(`wp-write-review-fixes: round ${snap.round} has no red or orange verdict to fix.`);\n }\n const out = this.fixesPath(summaryPath, snap.round);\n const holding = this.validFixes(repoRoot, summaryPath, snap);\n if (holding !== null) {\n throw new InformAiError(`wp-write-review-fixes: the fixes for round ${snap.round} are already recorded in ${out}, and `\n + `that record still holds (its fixed commit ${holding.toHead.slice(0, 8)} is in HEAD's history), so it is not `\n + 'overwritten. Nothing more to record: re-run pnpm wp-review-upsert-pr, or pnpm wp-finish-upsert-pr after the last round.');\n }\n this.assertClean(repoRoot);\n const currentHead = this.git(repoRoot, ['rev-parse', 'HEAD']);\n if (currentHead === snap.headSha || this.git(repoRoot, ['diff', '--name-only', snap.headSha, currentHead]) === '') {\n throw new InformAiError('wp-write-review-fixes: remediation must contain a committed, non-empty delta after the reviewed HEAD.');\n }\n const raw = this.parseObject(json, 'wp-write-review-fixes: input must be one JSON object.');\n const agent = this.requiredText(raw, 'agent');\n const model = this.requiredText(raw, 'model');\n const responses = this.responses(raw['responses']);\n const ids = responses.map((r: RemediationResponse): string => r.checklistId);\n const unknown = ids.filter((id: string): boolean => !blocking.includes(id));\n const missing = blocking.filter((id: string): boolean => !ids.includes(id));\n if (unknown.length > 0 || missing.length > 0) {\n throw new InformAiError(`wp-write-review-fixes: responses must cover exactly the red/orange checklist(s) of round ${snap.round}. `\n + `Unknown: ${unknown.join(', ') || '(none)'}. Missing: ${missing.join(', ') || '(none)'}.`);\n }\n this.supersede(out);\n this.atomicFile.writeJsonAtomic(out, new ReviewRemediation(agent, model, snap.headSha, currentHead, responses));\n return out;\n }\n\n /**\n * Keep a record that no longer holds beside the new one, as `<file>.superseded-<k>` — a name no round\n * scan reads, so it is history and never a live record.\n */\n private supersede(file: string): void {\n if (!fs.existsSync(file)) return;\n let k = 1;\n while (fs.existsSync(`${file}.superseded-${k}`)) k++;\n fs.renameSync(file, `${file}.superseded-${k}`);\n }\n\n /**\n * The round's recorded fixes, or null when there are none that still hold: written from the reviewed\n * HEAD, to a later commit that is still in HEAD's history, covering exactly the round's red/orange set.\n */\n validFixes(repoRoot: string, summaryPath: string, snap: RoundSnapshot): ReviewRemediation | null {\n const record = this.readFixes(repoRoot, summaryPath, snap.round);\n if (record === null || record.fromHead !== snap.headSha) return null;\n const blocking = this.blockingIds(summaryPath, snap);\n const ids = record.responses.map((r: RemediationResponse): string => r.checklistId);\n if (blocking.some((id: string): boolean => !ids.includes(id)) || ids.some((id: string): boolean => !blocking.includes(id))) return null;\n return record;\n }\n\n /**\n * checklist id → the dashboard stamp for every ORANGE whose fix the author recorded (issue #1053):\n * \"orange at <fromHead>, author-fixed in <toHead>, not re-reviewed: <resolution>\". An orange with no\n * valid record is absent, and so still blocks.\n */\n orangeFixes(repoRoot: string, summaryPath: string, results: readonly ChecklistResult[]): Record<string, string> {\n const out: Record<string, string> = {};\n for (const result of results) {\n if (result.status !== VERDICT_ORANGE || result.problem !== '') continue;\n const record = this.readFixes(repoRoot, summaryPath, result.round);\n const response = record?.responses.find((r: RemediationResponse): boolean => r.checklistId === result.id);\n if (record === null || response === undefined) continue;\n out[result.id] = `orange at ${record.fromHead.slice(0, 8)}, author-fixed in ${record.toHead.slice(0, 8)}, `\n + `not re-reviewed: ${response.resolution}`;\n }\n return out;\n }\n\n auditTrail(summaryPath: string, checklistId: string, maxRounds: number): string {\n const lines: string[] = [];\n const highest = this.highestRound(summaryPath);\n for (let round = 1; round <= highest; round++) {\n const verdict = this.readObject(this.reviewJson.checklistResultPath(summaryPath, checklistId, round));\n if (verdict !== null) {\n lines.push(`#### Reviewer round ${round} of ${maxRounds}`);\n lines.push(`Reviewed SHA: ${this.provenance.read(summaryPath, checklistId, round)?.headSha || '(unknown)'}`);\n lines.push(`Status: ${this.text(verdict['status']).toUpperCase()}`);\n lines.push('', this.text(verdict['output']), '');\n }\n const remediation = this.readObject(this.fixesPath(summaryPath, round));\n if (remediation !== null && Array.isArray(remediation['responses'])) {\n const response = (remediation['responses'] as JsonValue[]).find((entry: JsonValue): boolean =>\n typeof entry === 'object' && entry !== null && !Array.isArray(entry)\n && (entry as JsonObject)['checklistId'] === checklistId);\n if (typeof response === 'object' && response !== null && !Array.isArray(response)) {\n const raw = response as JsonObject;\n lines.push(`#### Author fix after round ${round}`);\n lines.push(`Range: ${this.text(remediation['fromHead'])}..${this.text(remediation['toHead'])}`);\n lines.push('', this.text(raw['resolution']), '');\n }\n }\n }\n return lines.join('\\n').trim();\n }\n\n private blockingIds(summaryPath: string, snap: RoundSnapshot): string[] {\n return [\n ...this.checklistIdsWithStatus(summaryPath, snap, VERDICT_RED),\n ...this.checklistIdsWithStatus(summaryPath, snap, VERDICT_ORANGE),\n ];\n }\n\n /** A round's fix record, provided its `toHead` is still in HEAD's history; else null. */\n private readFixes(repoRoot: string, summaryPath: string, round: number): ReviewRemediation | null {\n const raw = this.readObject(this.fixesPath(summaryPath, round));\n if (raw === null) return null;\n const responses = this.responsesOrEmpty(raw['responses']);\n const fromHead = this.text(raw['fromHead']);\n const toHead = this.text(raw['toHead']);\n if (this.text(raw['agent']) === '' || this.text(raw['model']) === '' || responses.length === 0\n || fromHead === '' || toHead === '' || fromHead === toHead || !this.isAncestorOfHead(repoRoot, toHead)) return null;\n return new ReviewRemediation(this.text(raw['agent']), this.text(raw['model']), fromHead, toHead, responses);\n }\n\n private everyVerdictIn(summaryPath: string, roster: readonly string[], round: number): boolean {\n return roster.every((id: string): boolean => this.hasVerdict(summaryPath, id, round));\n }\n\n /** `review-round<N>-<id>.json` → `<id>`; '' for the fixes record, a provenance file, or anything else. */\n private verdictIdOf(name: string): string {\n const match = ROUND_FILE.exec(name);\n if (match === null) return '';\n const id = match[2];\n return id === FIXES_ID || id.endsWith(PROVENANCE_SUFFIX) ? '' : id;\n }\n\n private roundFiles(summaryPath: string): string[] {\n const dir = path.dirname(summaryPath);\n if (!fs.existsSync(dir)) return [];\n return fs.readdirSync(dir).filter((name: string): boolean => ROUND_FILE.test(name));\n }\n\n private responses(value: JsonValue | undefined): RemediationResponse[] {\n const responses = this.responsesOrEmpty(value);\n if (responses.length === 0) throw new InformAiError('wp-write-review-fixes: \"responses\" must be a non-empty array.');\n return responses;\n }\n\n private responsesOrEmpty(value: JsonValue | undefined): RemediationResponse[] {\n if (!Array.isArray(value)) return [];\n const out: RemediationResponse[] = [];\n for (const entry of value) {\n if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) return [];\n const raw = entry as JsonObject;\n const id = this.text(raw['checklistId']);\n const resolution = this.text(raw['resolution']);\n const files = Array.isArray(raw['files']) ? raw['files'].filter((f: JsonValue): f is string => typeof f === 'string' && f.trim() !== '') : [];\n if (id === '' || resolution === '' || files.length === 0) return [];\n out.push(new RemediationResponse(id, resolution, files));\n }\n return out;\n }\n\n private requiredText(raw: JsonObject, key: string): string {\n const value = this.text(raw[key]);\n if (value === '') throw new InformAiError(`wp-write-review-fixes: \"${key}\" must be a non-empty string.`);\n return value;\n }\n\n private text(value: JsonValue | undefined): string {\n return typeof value === 'string' ? value.trim() : '';\n }\n\n private parseObject(json: string, message: string): JsonObject {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: malformed author JSON becomes an actionable refusal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const value = JSON.parse(json) as JsonValue;\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) return value;\n // webpieces-disable no-any-unknown -- the language types caught JavaScript values as unknown\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n throw new InformAiError(message);\n }\n\n private readObject(file: string): JsonObject | null {\n if (!fs.existsSync(file)) return null;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: unreadable durable state becomes an actionable refusal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const value = JSON.parse(fs.readFileSync(file, 'utf8')) as JsonValue;\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) return value;\n throw new InformAiError(`Review state file must contain one JSON object: ${file}`);\n // webpieces-disable no-any-unknown -- the language types caught JavaScript values as unknown\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof InformAiError) throw error;\n throw new InformAiError(`Could not read review state file ${file}: ${error.message}`, { cause: error });\n }\n }\n\n private assertClean(repoRoot: string): void {\n const status = this.git(repoRoot, ['status', '--porcelain', '--untracked-files=all']);\n if (status !== '') throw new InformAiError('wp-write-review-fixes: commit every remediation and leave no staged, unstaged, or untracked files first.');\n }\n\n /**\n * `git merge-base --is-ancestor`: exit 0 = yes, 1 = no. A `sha` git does not know (exit 128 with\n * \"Not a valid commit name\") is also no — the commit is gone from this clone, so it is not in HEAD's\n * history. Anything else is a real failure and refuses.\n */\n private isAncestorOfHead(repoRoot: string, sha: string): boolean {\n const result = spawnSync('git', ['merge-base', '--is-ancestor', sha, 'HEAD'], { cwd: repoRoot, encoding: 'utf8' });\n if (result.status === 0) return true;\n if (result.status === 1 || /not a valid (commit|object) name/i.test(result.stderr ?? '')) return false;\n const detail = (result.stderr ?? '').trim() || result.error?.message || `exit ${result.status ?? 'unknown'}`;\n const message = `Review-round Git command failed: git merge-base --is-ancestor ${sha} HEAD\\n${detail}`;\n if (result.error !== undefined) throw new InformAiError(message, { cause: result.error });\n throw new InformAiError(message);\n }\n\n private git(repoRoot: string, args: string[]): string {\n const result = spawnSync('git', args, { cwd: repoRoot, encoding: 'utf8' });\n if (result.status === 0) return (result.stdout ?? '').trim();\n const command = `git ${args.join(' ')}`;\n const detail = (result.stderr ?? '').trim() || result.error?.message || `exit ${result.status ?? 'unknown'}`;\n const message = `Review-round Git command failed: ${command}\\n${detail}`;\n if (result.error !== undefined) throw new InformAiError(message, { cause: result.error });\n throw new InformAiError(message);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"review-round-state.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/review-round-state.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,iDAA0C;AAC1C,8DAAsE;AACtE,iEAA6D;AAC7D,0DAA0G;AAC1G,yCAA2D;AAE3D,6DAAgE;AAChE,6CAAyC;AAM5B,QAAA,mBAAmB,GAAG,QAAQ,CAAC;AAC/B,QAAA,mBAAmB,GAAG,QAAQ,CAAC;AAC/B,QAAA,gBAAgB,GAAG,KAAK,CAAC;AACzB,QAAA,mBAAmB,GAAG,QAAQ,CAAC;AAC/B,QAAA,mBAAmB,GAAG,QAAQ,CAAC;AAE5C,gHAAgH;AAChH,MAAM,UAAU,GAAG,gCAAgC,CAAC;AACpD,MAAM,QAAQ,GAAG,OAAO,CAAC;AACzB,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAExC,MAAa,eAAe;IACxB,MAAM,CAAS;IACf,KAAK,CAAS;IACd,SAAS,CAAS;IAClB,KAAK,CAAY;IACjB,YAAY,CAAW;IACvB,eAAe,CAAW;IAC1B,uFAAuF;IACvF,kBAAkB,CAAW;IAE7B,yDAAyD;IACzD,YACI,MAAc,EAAE,KAAa,EAAE,SAAiB,EAAE,KAAgB,EAAE,eAAyB,EAAE,EAC/F,kBAA4B,EAAE,EAAE,qBAA+B,EAAE;QAEjE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI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AAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QAC3E,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC7D,MAAM,OAAO,GAAG,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACxC,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,IAAI,QAAQ,MAAM,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;QAC7G,MAAM,OAAO,GAAG,oCAAoC,OAAO,KAAK,MAAM,EAAE,CAAC;QACzE,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS;YAAE,MAAM,IAAI,8BAAa,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QAC1F,MAAM,IAAI,8BAAa,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;CACJ,CAAA;AA7WY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGJ,gCAAiB;QACjB,6CAAwB;QACxB,2BAAU;GAJlC,uBAAuB,CA6WnC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { spawnSync } from 'child_process';\nimport { AtomicFile, InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { ChecklistResult, ReviewJsonService, VERDICT_ORANGE, VERDICT_RED } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ReviewStageReceipt } from './review-stage-receipt';\nimport { VerdictProvenanceService } from './verdict-provenance';\nimport { DiffBasis } from './diff-basis';\n\ntype JsonPrimitive = string | number | boolean | null;\ntype JsonValue = JsonPrimitive | JsonValue[] | JsonObject;\ninterface JsonObject { [key: string]: JsonValue }\n\nexport const ROUND_ACTION_REVIEW = 'review';\nexport const ROUND_ACTION_RESUME = 'resume';\nexport const ROUND_ACTION_FIX = 'fix';\nexport const ROUND_ACTION_RECORD = 'record';\nexport const ROUND_ACTION_FINISH = 'finish';\n\n/** Every round-numbered file of a branch's review lives beside summary.json under this prefix (issue #1053). */\nconst ROUND_FILE = /^review-round(\\d+)-(.+)\\.json$/;\nconst FIXES_ID = 'fixes';\nconst PROVENANCE_SUFFIX = '.provenance';\n\nexport class ReviewRoundPlan {\n action: string;\n round: number;\n maxRounds: number;\n basis: DiffBasis;\n changedFiles: string[];\n redChecklistIds: string[];\n /** The final round's ORANGE checklists — must-fix, never re-reviewed (issue #1053). */\n orangeChecklistIds: string[];\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n action: string, round: number, maxRounds: number, basis: DiffBasis, changedFiles: string[] = [],\n redChecklistIds: string[] = [], orangeChecklistIds: string[] = [],\n ) {\n this.action = action;\n this.round = round;\n this.maxRounds = maxRounds;\n this.basis = basis;\n this.changedFiles = changedFiles;\n this.redChecklistIds = redChecklistIds;\n this.orangeChecklistIds = orangeChecklistIds;\n }\n}\n\n/**\n * Where a branch's review stands, DERIVED from the round-numbered files on disk plus the stage-② receipt\n * (issue #1053). There is no separate round counter: `round` is the highest round any file or briefing\n * names. Data-only.\n */\nexport class RoundSnapshot {\n round: number; // 0 = no round has started\n roster: string[]; // the REQUIRED checklists briefed in `round`, plus the optional ones that submitted in it\n headSha: string; // the commit `round` was briefed on\n complete: boolean; // every REQUIRED checklist briefed in `round` has a verdict in it (issue #1062)\n\n constructor(round: number, roster: string[], headSha: string, complete: boolean) {\n this.round = round;\n this.roster = roster;\n this.headSha = headSha;\n this.complete = complete;\n }\n}\n\nexport class RemediationResponse {\n checklistId: string;\n resolution: string;\n files: string[];\n\n constructor(checklistId: string, resolution: string, files: string[]) {\n this.checklistId = checklistId;\n this.resolution = resolution;\n this.files = files;\n }\n}\n\n/** The author's recorded fixes for one completed round: `review-round<N>-fixes.json`. Data-only. */\nexport class ReviewRemediation {\n agent: string;\n model: string;\n fromHead: string;\n toHead: string;\n responses: RemediationResponse[];\n writtenAt: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(agent: string, model: string, fromHead: string, toHead: string, responses: RemediationResponse[]) {\n this.agent = agent;\n this.model = model;\n this.fromHead = fromHead;\n this.toHead = toHead;\n this.responses = responses;\n this.writtenAt = new Date().toISOString();\n }\n}\n\n/**\n * The reviewer rounds of one branch, read from their round-numbered files (issue #1053).\n *\n * `commands.pr-gate.maxReviewerRounds` is a HARD CEILING, not a quota: 1 round means 1 round. Three rules\n * follow from it, and everything here exists to hold them:\n *\n * 1. Every verdict is `review-round<N>-<id>.json` (+ `.provenance.json`), every author fix record is\n * `review-round<N>-fixes.json`, and nothing is ever overwritten. The live verdict of a checklist is its\n * highest round; the round the branch is on is the highest round any file names.\n * 2. A new round starts ONLY when the previous round has a RED and rounds remain, and it re-briefs only\n * those reds. A green or yellow stands whatever changes afterwards — staleness never re-reviews.\n * 3. The final round has no red. Its blocking color is ORANGE: the author fixes it best effort, records the\n * fix, and ships with the finding and its claimed fix stamped on the dashboard.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewRoundStateService {\n constructor(\n private readonly reviewJson: ReviewJsonService,\n private readonly provenance: VerdictProvenanceService,\n private readonly atomicFile: AtomicFile,\n ) {}\n\n /** The author's recorded fixes for one round: `review-round<N>-fixes.json`, beside summary.json. */\n fixesPath(summaryPath: string, round: number): string {\n return path.join(path.dirname(summaryPath), `review-round${round}-${FIXES_ID}.json`);\n }\n\n /** The highest round any round-numbered file names, or 0. */\n highestRound(summaryPath: string): number {\n let highest = 0;\n for (const name of this.roundFiles(summaryPath)) {\n const match = ROUND_FILE.exec(name);\n if (match !== null) highest = Math.max(highest, Number(match[1]));\n }\n return highest;\n }\n\n /** Every checklist that has a verdict in ANY round on this branch. */\n verdictChecklistIds(summaryPath: string): string[] {\n const ids = new Set<string>();\n for (const name of this.roundFiles(summaryPath)) {\n const id = this.verdictIdOf(name);\n if (id !== '') ids.add(id);\n }\n return [...ids].sort();\n }\n\n /** Where the branch's review stands — see {@link RoundSnapshot}. */\n snapshot(summaryPath: string, receipt: ReviewStageReceipt | null): RoundSnapshot {\n const briefed = receipt !== null && receipt.reviewersBriefed.length > 0 ? receipt.round : 0;\n const round = Math.max(this.highestRound(summaryPath), briefed);\n if (round < 1) return new RoundSnapshot(0, [], '', false);\n if (receipt !== null && receipt.round === round) {\n // Only a REQUIRED checklist holds the round open (issue #1062). An optional one counts only if it\n // actually ran — a red from it still opens the next round — and one nobody chose to run is not\n // waited on, so an all-optional briefing nobody ran is complete with an empty roster.\n const optional = new Set<string>(receipt.optionalBriefed);\n const required = receipt.reviewersBriefed.filter((id: string): boolean => !optional.has(id));\n const roster = receipt.reviewersBriefed.filter((id: string): boolean =>\n !optional.has(id) || this.hasVerdict(summaryPath, id, round));\n return new RoundSnapshot(round, roster, receipt.headSha, this.everyVerdictIn(summaryPath, required, round));\n }\n // The receipt names an older round (or is gone): the files are the record, so the roster is exactly\n // the checklists that have a verdict in this round, and the reviewed HEAD is what their provenance says.\n const roster = this.roundFiles(summaryPath)\n .filter((name: string): boolean => name.startsWith(`review-round${round}-`))\n .map((name: string): string => this.verdictIdOf(name))\n .filter((id: string): boolean => id !== '')\n .sort();\n const headSha = roster.length === 0 ? '' : this.provenance.read(summaryPath, roster[0], round)?.headSha ?? '';\n return new RoundSnapshot(round, roster, headSha, roster.length > 0);\n }\n\n /**\n * TRUE once a review round has started on this branch. From then on the checklist set is FROZEN (issue\n * #1053): finish judges only the checklists that were briefed, never ones a later commit newly triggers.\n */\n roundStarted(summaryPath: string, receipt: ReviewStageReceipt | null): boolean {\n return this.snapshot(summaryPath, receipt).round >= 1;\n }\n\n /**\n * The frozen checklist set: every checklist briefed in any round — see {@link roundStarted}. It keeps an\n * optional checklist that was offered but never run, so its dashboard row reads \"optional, not run\"\n * rather than \"not briefed\"; it never holds a round open (see {@link snapshot}).\n */\n briefedChecklistIds(summaryPath: string, receipt: ReviewStageReceipt | null): string[] {\n const ids = new Set<string>(this.verdictChecklistIds(summaryPath));\n if (receipt !== null && receipt.round >= 1) for (const id of receipt.reviewersBriefed) ids.add(id);\n return [...ids].sort();\n }\n\n /** Does `checklistId` already have a verdict in `round`? A round's verdict is never overwritten. */\n hasVerdict(summaryPath: string, checklistId: string, round: number): boolean {\n return fs.existsSync(this.reviewJson.checklistResultPath(summaryPath, checklistId, round));\n }\n\n /** The roster checklists whose verdict in the snapshot's round is `status`. */\n checklistIdsWithStatus(summaryPath: string, snap: RoundSnapshot, status: string): string[] {\n if (!snap.complete) return [];\n return snap.roster.filter((id: string): boolean => {\n const raw = this.readObject(this.reviewJson.checklistResultPath(summaryPath, id, snap.round));\n return raw !== null && raw['status'] === status;\n });\n }\n\n /** What stage ② does next. See the class comment for the three rules it holds. */\n plan(repoRoot: string, summaryPath: string, receipt: ReviewStageReceipt | null, maxRounds: number, fullBasis: DiffBasis): ReviewRoundPlan {\n const snap = this.snapshot(summaryPath, receipt);\n if (snap.round < 1) return new ReviewRoundPlan(ROUND_ACTION_REVIEW, 1, maxRounds, fullBasis);\n if (!snap.complete) {\n if (snap.headSha !== fullBasis.headSha) {\n throw new InformAiError(`Reviewer round ${snap.round} of ${maxRounds} is still active at `\n + `${snap.headSha.slice(0, 8)}. Finish that fixed roster before changing the reviewed HEAD.`);\n }\n return new ReviewRoundPlan(ROUND_ACTION_RESUME, snap.round, maxRounds, fullBasis);\n }\n const reds = this.checklistIdsWithStatus(summaryPath, snap, VERDICT_RED);\n const oranges = this.checklistIdsWithStatus(summaryPath, snap, VERDICT_ORANGE);\n // No red, or no round left: nothing is ever re-reviewed. Oranges are the author's to fix and record.\n if (reds.length === 0 || snap.round >= maxRounds) {\n return new ReviewRoundPlan(ROUND_ACTION_FINISH, snap.round, maxRounds, fullBasis, [], reds, oranges);\n }\n if (snap.headSha === fullBasis.headSha) {\n return new ReviewRoundPlan(ROUND_ACTION_FIX, snap.round, maxRounds, fullBasis, [], reds, oranges);\n }\n if (this.validFixes(repoRoot, summaryPath, snap) === null) {\n return new ReviewRoundPlan(ROUND_ACTION_RECORD, snap.round, maxRounds, fullBasis, [], reds, oranges);\n }\n const basis = new DiffBasis(\n snap.headSha, fullBasis.headSha, false, [],\n `git diff ${snap.headSha} ${fullBasis.headSha}`,\n `git diff ${snap.headSha} ${fullBasis.headSha} -- <file>`, fullBasis.hashMainHead);\n const changed = this.git(repoRoot, ['diff', '--name-only', snap.headSha, fullBasis.headSha])\n .split('\\n').filter((f: string): boolean => f.trim() !== '');\n return new ReviewRoundPlan(ROUND_ACTION_REVIEW, snap.round + 1, maxRounds, basis, changed, reds, oranges);\n }\n\n /**\n * Record the author's fixes for the latest completed round — one response per RED (a round that is not\n * the last) or ORANGE (the final round) — as `review-round<N>-fixes.json`.\n *\n * A record that still HOLDS is never overwritten. One that no longer holds — its `toHead` left HEAD's\n * history, which every `wp-start-upsert-pr` squash-update does — is kept beside it as\n * `review-round<N>-fixes.json.superseded-<k>` and a fresh record is written, so re-recording is always\n * the way past a stale record and nothing is ever lost.\n */\n writeRemediation(repoRoot: string, summaryPath: string, receipt: ReviewStageReceipt, json: string): string {\n const snap = this.snapshot(summaryPath, receipt);\n if (!snap.complete) {\n throw new InformAiError('wp-write-review-fixes: the active reviewer round is not complete yet.');\n }\n const blocking = this.blockingIds(summaryPath, snap);\n if (blocking.length === 0) {\n throw new InformAiError(`wp-write-review-fixes: round ${snap.round} has no red or orange verdict to fix.`);\n }\n const out = this.fixesPath(summaryPath, snap.round);\n const holding = this.validFixes(repoRoot, summaryPath, snap);\n if (holding !== null) {\n throw new InformAiError(`wp-write-review-fixes: the fixes for round ${snap.round} are already recorded in ${out}, and `\n + `that record still holds (its fixed commit ${holding.toHead.slice(0, 8)} is in HEAD's history), so it is not `\n + 'overwritten. Nothing more to record: re-run pnpm wp-review-upsert-pr, or pnpm wp-finish-upsert-pr after the last round.');\n }\n this.assertClean(repoRoot);\n const currentHead = this.git(repoRoot, ['rev-parse', 'HEAD']);\n if (currentHead === snap.headSha || this.git(repoRoot, ['diff', '--name-only', snap.headSha, currentHead]) === '') {\n throw new InformAiError('wp-write-review-fixes: remediation must contain a committed, non-empty delta after the reviewed HEAD.');\n }\n const raw = this.parseObject(json, 'wp-write-review-fixes: input must be one JSON object.');\n const agent = this.requiredText(raw, 'agent');\n const model = this.requiredText(raw, 'model');\n const responses = this.responses(raw['responses']);\n const ids = responses.map((r: RemediationResponse): string => r.checklistId);\n const unknown = ids.filter((id: string): boolean => !blocking.includes(id));\n const missing = blocking.filter((id: string): boolean => !ids.includes(id));\n if (unknown.length > 0 || missing.length > 0) {\n throw new InformAiError(`wp-write-review-fixes: responses must cover exactly the red/orange checklist(s) of round ${snap.round}. `\n + `Unknown: ${unknown.join(', ') || '(none)'}. Missing: ${missing.join(', ') || '(none)'}.`);\n }\n this.supersede(out);\n this.atomicFile.writeJsonAtomic(out, new ReviewRemediation(agent, model, snap.headSha, currentHead, responses));\n return out;\n }\n\n /**\n * Keep a record that no longer holds beside the new one, as `<file>.superseded-<k>` — a name no round\n * scan reads, so it is history and never a live record.\n */\n private supersede(file: string): void {\n if (!fs.existsSync(file)) return;\n let k = 1;\n while (fs.existsSync(`${file}.superseded-${k}`)) k++;\n fs.renameSync(file, `${file}.superseded-${k}`);\n }\n\n /**\n * The round's recorded fixes, or null when there are none that still hold: written from the reviewed\n * HEAD, to a later commit that is still in HEAD's history, covering exactly the round's red/orange set.\n */\n validFixes(repoRoot: string, summaryPath: string, snap: RoundSnapshot): ReviewRemediation | null {\n const record = this.readFixes(repoRoot, summaryPath, snap.round);\n if (record === null || record.fromHead !== snap.headSha) return null;\n const blocking = this.blockingIds(summaryPath, snap);\n const ids = record.responses.map((r: RemediationResponse): string => r.checklistId);\n if (blocking.some((id: string): boolean => !ids.includes(id)) || ids.some((id: string): boolean => !blocking.includes(id))) return null;\n return record;\n }\n\n /**\n * checklist id → the dashboard stamp for every ORANGE whose fix the author recorded (issue #1053):\n * \"orange at <fromHead>, author-fixed in <toHead>, not re-reviewed: <resolution>\". An orange with no\n * valid record is absent, and so still blocks.\n */\n orangeFixes(repoRoot: string, summaryPath: string, results: readonly ChecklistResult[]): Record<string, string> {\n const out: Record<string, string> = {};\n for (const result of results) {\n if (result.status !== VERDICT_ORANGE || result.problem !== '') continue;\n const record = this.readFixes(repoRoot, summaryPath, result.round);\n const response = record?.responses.find((r: RemediationResponse): boolean => r.checklistId === result.id);\n if (record === null || response === undefined) continue;\n out[result.id] = `orange at ${record.fromHead.slice(0, 8)}, author-fixed in ${record.toHead.slice(0, 8)}, `\n + `not re-reviewed: ${response.resolution}`;\n }\n return out;\n }\n\n auditTrail(summaryPath: string, checklistId: string, maxRounds: number): string {\n const lines: string[] = [];\n const highest = this.highestRound(summaryPath);\n for (let round = 1; round <= highest; round++) {\n const verdict = this.readObject(this.reviewJson.checklistResultPath(summaryPath, checklistId, round));\n if (verdict !== null) {\n lines.push(`#### Reviewer round ${round} of ${maxRounds}`);\n lines.push(`Reviewed SHA: ${this.provenance.read(summaryPath, checklistId, round)?.headSha || '(unknown)'}`);\n lines.push(`Status: ${this.text(verdict['status']).toUpperCase()}`);\n lines.push('', this.text(verdict['output']), '');\n }\n const remediation = this.readObject(this.fixesPath(summaryPath, round));\n if (remediation !== null && Array.isArray(remediation['responses'])) {\n const response = (remediation['responses'] as JsonValue[]).find((entry: JsonValue): boolean =>\n typeof entry === 'object' && entry !== null && !Array.isArray(entry)\n && (entry as JsonObject)['checklistId'] === checklistId);\n if (typeof response === 'object' && response !== null && !Array.isArray(response)) {\n const raw = response as JsonObject;\n lines.push(`#### Author fix after round ${round}`);\n lines.push(`Range: ${this.text(remediation['fromHead'])}..${this.text(remediation['toHead'])}`);\n lines.push('', this.text(raw['resolution']), '');\n }\n }\n }\n return lines.join('\\n').trim();\n }\n\n private blockingIds(summaryPath: string, snap: RoundSnapshot): string[] {\n return [\n ...this.checklistIdsWithStatus(summaryPath, snap, VERDICT_RED),\n ...this.checklistIdsWithStatus(summaryPath, snap, VERDICT_ORANGE),\n ];\n }\n\n /** A round's fix record, provided its `toHead` is still in HEAD's history; else null. */\n private readFixes(repoRoot: string, summaryPath: string, round: number): ReviewRemediation | null {\n const raw = this.readObject(this.fixesPath(summaryPath, round));\n if (raw === null) return null;\n const responses = this.responsesOrEmpty(raw['responses']);\n const fromHead = this.text(raw['fromHead']);\n const toHead = this.text(raw['toHead']);\n if (this.text(raw['agent']) === '' || this.text(raw['model']) === '' || responses.length === 0\n || fromHead === '' || toHead === '' || fromHead === toHead || !this.isAncestorOfHead(repoRoot, toHead)) return null;\n return new ReviewRemediation(this.text(raw['agent']), this.text(raw['model']), fromHead, toHead, responses);\n }\n\n private everyVerdictIn(summaryPath: string, roster: readonly string[], round: number): boolean {\n return roster.every((id: string): boolean => this.hasVerdict(summaryPath, id, round));\n }\n\n /** `review-round<N>-<id>.json` → `<id>`; '' for the fixes record, a provenance file, or anything else. */\n private verdictIdOf(name: string): string {\n const match = ROUND_FILE.exec(name);\n if (match === null) return '';\n const id = match[2];\n return id === FIXES_ID || id.endsWith(PROVENANCE_SUFFIX) ? '' : id;\n }\n\n private roundFiles(summaryPath: string): string[] {\n const dir = path.dirname(summaryPath);\n if (!fs.existsSync(dir)) return [];\n return fs.readdirSync(dir).filter((name: string): boolean => ROUND_FILE.test(name));\n }\n\n private responses(value: JsonValue | undefined): RemediationResponse[] {\n const responses = this.responsesOrEmpty(value);\n if (responses.length === 0) throw new InformAiError('wp-write-review-fixes: \"responses\" must be a non-empty array.');\n return responses;\n }\n\n private responsesOrEmpty(value: JsonValue | undefined): RemediationResponse[] {\n if (!Array.isArray(value)) return [];\n const out: RemediationResponse[] = [];\n for (const entry of value) {\n if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) return [];\n const raw = entry as JsonObject;\n const id = this.text(raw['checklistId']);\n const resolution = this.text(raw['resolution']);\n const files = Array.isArray(raw['files']) ? raw['files'].filter((f: JsonValue): f is string => typeof f === 'string' && f.trim() !== '') : [];\n if (id === '' || resolution === '' || files.length === 0) return [];\n out.push(new RemediationResponse(id, resolution, files));\n }\n return out;\n }\n\n private requiredText(raw: JsonObject, key: string): string {\n const value = this.text(raw[key]);\n if (value === '') throw new InformAiError(`wp-write-review-fixes: \"${key}\" must be a non-empty string.`);\n return value;\n }\n\n private text(value: JsonValue | undefined): string {\n return typeof value === 'string' ? value.trim() : '';\n }\n\n private parseObject(json: string, message: string): JsonObject {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: malformed author JSON becomes an actionable refusal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const value = JSON.parse(json) as JsonValue;\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) return value;\n // webpieces-disable no-any-unknown -- the language types caught JavaScript values as unknown\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n throw new InformAiError(message);\n }\n\n private readObject(file: string): JsonObject | null {\n if (!fs.existsSync(file)) return null;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: unreadable durable state becomes an actionable refusal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const value = JSON.parse(fs.readFileSync(file, 'utf8')) as JsonValue;\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) return value;\n throw new InformAiError(`Review state file must contain one JSON object: ${file}`);\n // webpieces-disable no-any-unknown -- the language types caught JavaScript values as unknown\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof InformAiError) throw error;\n throw new InformAiError(`Could not read review state file ${file}: ${error.message}`, { cause: error });\n }\n }\n\n private assertClean(repoRoot: string): void {\n const status = this.git(repoRoot, ['status', '--porcelain', '--untracked-files=all']);\n if (status !== '') throw new InformAiError('wp-write-review-fixes: commit every remediation and leave no staged, unstaged, or untracked files first.');\n }\n\n /**\n * `git merge-base --is-ancestor`: exit 0 = yes, 1 = no. A `sha` git does not know (exit 128 with\n * \"Not a valid commit name\") is also no — the commit is gone from this clone, so it is not in HEAD's\n * history. Anything else is a real failure and refuses.\n */\n private isAncestorOfHead(repoRoot: string, sha: string): boolean {\n const result = spawnSync('git', ['merge-base', '--is-ancestor', sha, 'HEAD'], { cwd: repoRoot, encoding: 'utf8' });\n if (result.status === 0) return true;\n if (result.status === 1 || /not a valid (commit|object) name/i.test(result.stderr ?? '')) return false;\n const detail = (result.stderr ?? '').trim() || result.error?.message || `exit ${result.status ?? 'unknown'}`;\n const message = `Review-round Git command failed: git merge-base --is-ancestor ${sha} HEAD\\n${detail}`;\n if (result.error !== undefined) throw new InformAiError(message, { cause: result.error });\n throw new InformAiError(message);\n }\n\n private git(repoRoot: string, args: string[]): string {\n const result = spawnSync('git', args, { cwd: repoRoot, encoding: 'utf8' });\n if (result.status === 0) return (result.stdout ?? '').trim();\n const command = `git ${args.join(' ')}`;\n const detail = (result.stderr ?? '').trim() || result.error?.message || `exit ${result.status ?? 'unknown'}`;\n const message = `Review-round Git command failed: ${command}\\n${detail}`;\n if (result.error !== undefined) throw new InformAiError(message, { cause: result.error });\n throw new InformAiError(message);\n }\n}\n"]}
|
|
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const fs = tslib_1.__importStar(require("fs"));
|
|
6
6
|
const path = tslib_1.__importStar(require("path"));
|
|
7
7
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
8
|
+
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
8
9
|
const inversify_1 = require("inversify");
|
|
9
10
|
exports.RECEIPT_FILE = 'review-stage.json';
|
|
10
11
|
/**
|
|
@@ -101,7 +102,7 @@ let ReviewStageReceiptService = class ReviewStageReceiptService {
|
|
|
101
102
|
return receipt;
|
|
102
103
|
}
|
|
103
104
|
catch (err) {
|
|
104
|
-
const error = (0,
|
|
105
|
+
const error = (0, to_error_1.toError)(err);
|
|
105
106
|
void error; // unreadable ⇒ treated as absent, which re-runs stage ② (the safe direction)
|
|
106
107
|
return null;
|
|
107
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"review-stage-receipt.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/review-stage-receipt.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAqE;AACrE,yCAA2D;AAE9C,QAAA,YAAY,GAAG,mBAAmB,CAAC;AAEhD;;GAEG;AACH,MAAa,kBAAkB;IAC3B,OAAO,CAAS,CAAU,gEAAgE;IAC1F,cAAc,CAAU,CAAE,oEAAoE;IAC9F,YAAY,CAAS;IACrB,aAAa,CAAS,CAAI,4DAA4D;IACtF,gBAAgB,CAAW;IAC3B;;;;;OAKG;IACH,eAAe,CAAW;IAC1B;;;;OAIG;IACH,WAAW,CAAyB;IACpC;;;;;OAKG;IACH,KAAK,CAAS;IACd,8FAA8F;IAC9F,iBAAiB,CAAS;IAE1B,yDAAyD;IACzD,YAAY,OAAO,GAAG,EAAE,EAAE,cAAc,GAAG,KAAK,EAAE,YAAY,GAAG,EAAE,EAAE,aAAa,GAAG,EAAE,EAAE,mBAA6B,EAAE;QACpH,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC;IAC/B,CAAC;CACJ;AAzCD,gDAyCC;AAED;;;;;;;;;;;;;;GAcG;AAEI,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IACL;IAA7B,YAA6B,iBAAoC;QAApC,s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AAC;YAC3B,KAAK,KAAK,CAAC,CAAC,6EAA6E;YACzF,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAED,uFAAuF;IAC/E,SAAS,CAAC,KAAc;QAC5B,MAAM,GAAG,GAA2B,EAAE,CAAC;QACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,GAAG,CAAC;QACpF,4FAA4F;QAC5F,MAAM,GAAG,GAAG,KAAgC,CAAC;QAC7C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACjC,MAAM,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YACnB,IAAI,OAAO,CAAC,KAAK,QAAQ;gBAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;CACJ,CAAA;AAxDY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEW,gCAAiB;GADxD,yBAAyB,CAwDrC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { ReviewJsonService, toError } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nexport const RECEIPT_FILE = 'review-stage.json';\n\n/**\n * Proof that stage ② (`wp-review-upsert-pr`) actually ran, and on WHICH commit. Data-only (per CLAUDE.md).\n */\nexport class ReviewStageReceipt {\n headSha: string; // the sha the merge was validated and the build was run against\n mergeValidated: boolean; // a 3-point merge was finalized here, or there was none to finalize\n buildCommand: string;\n buildPassedAt: string; // ISO; '' when the gate was skipped (mode OFF / no command)\n reviewersBriefed: string[];\n /**\n * The OPTIONAL subset of `reviewersBriefed` (issue #1062). Every briefed checklist may submit a verdict,\n * but only the REQUIRED ones hold a round open: an optional checklist joins the round's roster only when\n * it actually submitted in that round, so one the human chose not to run never deadlocks the round.\n * Assigned after construction; a receipt written without the field reads as [].\n */\n optionalBriefed: string[];\n /**\n * checklist id → the hash of its in-scope diff at `headSha` (ChecklistScopeHasher). `wp-write-review`\n * stamps a verdict's provenance with the hash its reviewer was BRIEFED on, and the next stage ② carries\n * a green/yellow forward only while that hash is unchanged (issue #863). Assigned after construction.\n */\n scopeHashes: Record<string, string>;\n /**\n * The round stage ② BRIEFED `reviewersBriefed` for, and so the N every verdict submitted against this\n * receipt is written as (`review-round<N>-<id>.json`). Zero means no reviewer round has started. The\n * round the branch is on is DERIVED from the round-numbered files (issue #1053); this only says which\n * round the latest briefing opened.\n */\n round: number;\n /** Repository-owned cap copied from config, so `wp-write-review` refuses a round above it. */\n maxReviewerRounds: number;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(headSha = '', mergeValidated = false, buildCommand = '', buildPassedAt = '', reviewersBriefed: string[] = []) {\n this.headSha = headSha;\n this.mergeValidated = mergeValidated;\n this.buildCommand = buildCommand;\n this.buildPassedAt = buildPassedAt;\n this.reviewersBriefed = reviewersBriefed;\n this.optionalBriefed = [];\n this.scopeHashes = {};\n this.round = 0;\n this.maxReviewerRounds = 0;\n }\n}\n\n/**\n * Reads/writes the stage-② receipt.\n *\n * WHY a receipt rather than relying on the artifacts that already exist: `wp-finish-upsert-pr` already\n * refuses when a reviewer has no verdict and when summary.json is absent, so a repo WITH checklists is\n * mostly interlocked already. A repo with NO checklists is not — summary.json is the only thing standing\n * between it and a PR, and the AI writes summary.json itself. Nothing stopped it from writing that file and\n * going straight to finish, skipping the merge validation and the build entirely.\n *\n * The receipt also pays for itself in the other direction: because it records the sha the build passed on,\n * finish can SKIP its own build when HEAD has not moved, so adding a gate in the middle did not cost a\n * second full `nx affected` run.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewStageReceiptService {\n constructor(private readonly reviewJsonService: ReviewJsonService) {}\n\n receiptPath(repoRoot: string, featureName: string): string {\n return path.join(this.reviewJsonService.prDirFor(repoRoot, featureName), RECEIPT_FILE);\n }\n\n write(repoRoot: string, featureName: string, receipt: ReviewStageReceipt): string {\n const p = this.receiptPath(repoRoot, featureName);\n fs.mkdirSync(path.dirname(p), { recursive: true });\n fs.writeFileSync(p, JSON.stringify(receipt, null, 2) + '\\n');\n return p;\n }\n\n /** The receipt, or null when stage ② never ran (or left something unreadable behind). */\n read(repoRoot: string, featureName: string): ReviewStageReceipt | null {\n const p = this.receiptPath(repoRoot, featureName);\n if (!fs.existsSync(p)) return null;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable receipt is treated as absent, which re-runs stage ②\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- opaque parsed JSON, narrowed field-by-field below\n const raw = JSON.parse(fs.readFileSync(p, 'utf8')) as Record<string, unknown>;\n const receipt = new ReviewStageReceipt(\n typeof raw['headSha'] === 'string' ? (raw['headSha'] as string) : '',\n raw['mergeValidated'] === true,\n typeof raw['buildCommand'] === 'string' ? (raw['buildCommand'] as string) : '',\n typeof raw['buildPassedAt'] === 'string' ? (raw['buildPassedAt'] as string) : '',\n Array.isArray(raw['reviewersBriefed']) ? (raw['reviewersBriefed'] as string[]) : [],\n );\n receipt.optionalBriefed = Array.isArray(raw['optionalBriefed'])\n ? (raw['optionalBriefed'] as string[]).filter((id: string): boolean => typeof id === 'string') : [];\n receipt.scopeHashes = this.stringMap(raw['scopeHashes']);\n receipt.round = typeof raw['round'] === 'number' && Number.isInteger(raw['round']) ? raw['round'] as number : 0;\n receipt.maxReviewerRounds = typeof raw['maxReviewerRounds'] === 'number' && Number.isInteger(raw['maxReviewerRounds'])\n ? raw['maxReviewerRounds'] as number : 0;\n return receipt;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // unreadable ⇒ treated as absent, which re-runs stage ② (the safe direction)\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON value, narrowed to string→string\n private stringMap(value: unknown): Record<string, string> {\n const out: Record<string, string> = {};\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return out;\n // webpieces-disable no-any-unknown -- entries of an opaque JSON object, each narrowed below\n const obj = value as Record<string, unknown>;\n for (const key of Object.keys(obj)) {\n const v = obj[key];\n if (typeof v === 'string') out[key] = v;\n }\n return out;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"review-stage-receipt.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/review-stage-receipt.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,0DAA4D;AAC5D,iEAA6D;AAC7D,yCAA2D;AAE9C,QAAA,YAAY,GAAG,mBAAmB,CAAC;AAEhD;;GAEG;AACH,MAAa,kBAAkB;IAC3B,OAAO,CAAS,CAAU,gEAAgE;IAC1F,cAAc,CAAU,CAAE,oEAAoE;IAC9F,YAAY,CAAS;IACrB,aAAa,CAAS,CAAI,4DAA4D;IACtF,gBAAgB,CAAW;IAC3B;;;;;OAKG;IACH,eAAe,CAAW;IAC1B;;;;OAIG;IACH,WAAW,CAAyB;IACpC;;;;;OAKG;IACH,KAAK,CAAS;IACd,8FAA8F;IAC9F,iBAAiB,CAAS;IAE1B,yDAAyD;IACzD,YAAY,OAAO,GAAG,EAAE,EAAE,cAAc,GAAG,KAAK,EAAE,YAAY,GAAG,EAAE,EAAE,aAAa,GAAG,EAAE,EAAE,mBAA6B,EAAE;QACpH,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,W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C,SAAS,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;gBAClH,CAAC,CAAC,GAAG,CAAC,mBAAmB,CAAW,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7C,OAAO,OAAO,CAAC;QACnB,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC,CAAC,6EAA6E;YACzF,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAED,uFAAuF;IAC/E,SAAS,CAAC,KAAc;QAC5B,MAAM,GAAG,GAA2B,EAAE,CAAC;QACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,GAAG,CAAC;QACpF,4FAA4F;QAC5F,MAAM,GAAG,GAAG,KAAgC,CAAC;QAC7C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACjC,MAAM,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YACnB,IAAI,OAAO,CAAC,KAAK,QAAQ;gBAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;CACJ,CAAA;AAxDY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEW,gCAAiB;GADxD,yBAAyB,CAwDrC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { ReviewJsonService } from '@webpieces/rules-config';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nexport const RECEIPT_FILE = 'review-stage.json';\n\n/**\n * Proof that stage ② (`wp-review-upsert-pr`) actually ran, and on WHICH commit. Data-only (per CLAUDE.md).\n */\nexport class ReviewStageReceipt {\n headSha: string; // the sha the merge was validated and the build was run against\n mergeValidated: boolean; // a 3-point merge was finalized here, or there was none to finalize\n buildCommand: string;\n buildPassedAt: string; // ISO; '' when the gate was skipped (mode OFF / no command)\n reviewersBriefed: string[];\n /**\n * The OPTIONAL subset of `reviewersBriefed` (issue #1062). Every briefed checklist may submit a verdict,\n * but only the REQUIRED ones hold a round open: an optional checklist joins the round's roster only when\n * it actually submitted in that round, so one the human chose not to run never deadlocks the round.\n * Assigned after construction; a receipt written without the field reads as [].\n */\n optionalBriefed: string[];\n /**\n * checklist id → the hash of its in-scope diff at `headSha` (ChecklistScopeHasher). `wp-write-review`\n * stamps a verdict's provenance with the hash its reviewer was BRIEFED on, and the next stage ② carries\n * a green/yellow forward only while that hash is unchanged (issue #863). Assigned after construction.\n */\n scopeHashes: Record<string, string>;\n /**\n * The round stage ② BRIEFED `reviewersBriefed` for, and so the N every verdict submitted against this\n * receipt is written as (`review-round<N>-<id>.json`). Zero means no reviewer round has started. The\n * round the branch is on is DERIVED from the round-numbered files (issue #1053); this only says which\n * round the latest briefing opened.\n */\n round: number;\n /** Repository-owned cap copied from config, so `wp-write-review` refuses a round above it. */\n maxReviewerRounds: number;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(headSha = '', mergeValidated = false, buildCommand = '', buildPassedAt = '', reviewersBriefed: string[] = []) {\n this.headSha = headSha;\n this.mergeValidated = mergeValidated;\n this.buildCommand = buildCommand;\n this.buildPassedAt = buildPassedAt;\n this.reviewersBriefed = reviewersBriefed;\n this.optionalBriefed = [];\n this.scopeHashes = {};\n this.round = 0;\n this.maxReviewerRounds = 0;\n }\n}\n\n/**\n * Reads/writes the stage-② receipt.\n *\n * WHY a receipt rather than relying on the artifacts that already exist: `wp-finish-upsert-pr` already\n * refuses when a reviewer has no verdict and when summary.json is absent, so a repo WITH checklists is\n * mostly interlocked already. A repo with NO checklists is not — summary.json is the only thing standing\n * between it and a PR, and the AI writes summary.json itself. Nothing stopped it from writing that file and\n * going straight to finish, skipping the merge validation and the build entirely.\n *\n * The receipt also pays for itself in the other direction: because it records the sha the build passed on,\n * finish can SKIP its own build when HEAD has not moved, so adding a gate in the middle did not cost a\n * second full `nx affected` run.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewStageReceiptService {\n constructor(private readonly reviewJsonService: ReviewJsonService) {}\n\n receiptPath(repoRoot: string, featureName: string): string {\n return path.join(this.reviewJsonService.prDirFor(repoRoot, featureName), RECEIPT_FILE);\n }\n\n write(repoRoot: string, featureName: string, receipt: ReviewStageReceipt): string {\n const p = this.receiptPath(repoRoot, featureName);\n fs.mkdirSync(path.dirname(p), { recursive: true });\n fs.writeFileSync(p, JSON.stringify(receipt, null, 2) + '\\n');\n return p;\n }\n\n /** The receipt, or null when stage ② never ran (or left something unreadable behind). */\n read(repoRoot: string, featureName: string): ReviewStageReceipt | null {\n const p = this.receiptPath(repoRoot, featureName);\n if (!fs.existsSync(p)) return null;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable receipt is treated as absent, which re-runs stage ②\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- opaque parsed JSON, narrowed field-by-field below\n const raw = JSON.parse(fs.readFileSync(p, 'utf8')) as Record<string, unknown>;\n const receipt = new ReviewStageReceipt(\n typeof raw['headSha'] === 'string' ? (raw['headSha'] as string) : '',\n raw['mergeValidated'] === true,\n typeof raw['buildCommand'] === 'string' ? (raw['buildCommand'] as string) : '',\n typeof raw['buildPassedAt'] === 'string' ? (raw['buildPassedAt'] as string) : '',\n Array.isArray(raw['reviewersBriefed']) ? (raw['reviewersBriefed'] as string[]) : [],\n );\n receipt.optionalBriefed = Array.isArray(raw['optionalBriefed'])\n ? (raw['optionalBriefed'] as string[]).filter((id: string): boolean => typeof id === 'string') : [];\n receipt.scopeHashes = this.stringMap(raw['scopeHashes']);\n receipt.round = typeof raw['round'] === 'number' && Number.isInteger(raw['round']) ? raw['round'] as number : 0;\n receipt.maxReviewerRounds = typeof raw['maxReviewerRounds'] === 'number' && Number.isInteger(raw['maxReviewerRounds'])\n ? raw['maxReviewerRounds'] as number : 0;\n return receipt;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // unreadable ⇒ treated as absent, which re-runs stage ② (the safe direction)\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON value, narrowed to string→string\n private stringMap(value: unknown): Record<string, string> {\n const out: Record<string, string> = {};\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return out;\n // webpieces-disable no-any-unknown -- entries of an opaque JSON object, each narrowed below\n const obj = value as Record<string, unknown>;\n for (const key of Object.keys(obj)) {\n const v = obj[key];\n if (typeof v === 'string') out[key] = v;\n }\n return out;\n }\n}\n"]}
|
|
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const fs = tslib_1.__importStar(require("fs"));
|
|
6
6
|
const path = tslib_1.__importStar(require("path"));
|
|
7
7
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
8
|
+
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
8
9
|
const inversify_1 = require("inversify");
|
|
9
10
|
/**
|
|
10
11
|
* Turns a {@link ChecklistScan} plus the materialized {@link DiffManifest} into one {@link ReviewerBriefing}
|
|
@@ -130,7 +131,7 @@ let ReviewerBriefingBuilder = class ReviewerBriefingBuilder {
|
|
|
130
131
|
return new rules_config_1.ContextEntry(desc === '' ? pkg : `${pkg} — ${desc}`, dir);
|
|
131
132
|
}
|
|
132
133
|
catch (err) {
|
|
133
|
-
const error = (0,
|
|
134
|
+
const error = (0, to_error_1.toError)(err);
|
|
134
135
|
void error; // an unresolvable package is REPORTED below, never fatal
|
|
135
136
|
return new rules_config_1.ContextEntry(pkg, '', '(not installed — configured in pr-gate.reviewContextPackages)');
|
|
136
137
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reviewer-briefing-builder.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/reviewer-briefing-builder.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,0DAEiC;AACjC,yCAA2D;AAI3D;;;;;;GAMG;AAEI,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IACH;IAA7B,YAA6B,iBAAoC;QAApC,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAG,CAAC;IAErE,uGAAuG;IACvG,yDAAyD;IACzD,KAAK,CACD,QAAgB,EAAE,IAAmB,EAAE,UAAwC,EAAE,QAAsB,EACvG,OAAe,EAAE,MAAoB;QAErC,oGAAoG;QACpG,kEAAkE;QAClE,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACrD,MAAM,WAAW,GAAG,IAAI,GAAG,EAA6B,CAAC;QACzD,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,OAAO;YAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAC7D,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,GAAsB,EAAoB,EAAE,CAC/D,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC/E,CAAC;IAED,yDAAyD;IACjD,GAAG,CACP,QAAgB,EAAE,GAAsB,EAAE,IAAmB,EAC7D,WAA2C,EAAE,OAAe,EAAE,MAAsB,EAAE,QAAsB;QAE5G,MAAM,CAAC,GAAG,IAAI,+BAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;QACzE,CAAC,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,EAA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A,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEW,gCAAiB;GADxD,uBAAuB,CAiInC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport {\n BriefedFile, ContextEntry, PrGateConfig, RequiredChecklist, ReviewerBriefing, ReviewJsonService, toError,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { DiffManifest, DiffManifestEntry } from './diff-materializer';\nimport { ChecklistScan } from './checklist-scanner';\n\n/**\n * Turns a {@link ChecklistScan} plus the materialized {@link DiffManifest} into one {@link ReviewerBriefing}\n * per reviewer — resolving every path to an absolute one, because a reviewer that has to resolve a path\n * ends up searching, and searching is the cost this whole feature exists to remove.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewerBriefingBuilder {\n constructor(private readonly reviewJsonService: ReviewJsonService) {}\n\n /** One briefing per checklist in `checklists` — the OWED ones; a carried verdict is not re-briefed. */\n // eslint-disable-next-line @typescript-eslint/max-params\n build(\n repoRoot: string, scan: ChecklistScan, checklists: readonly RequiredChecklist[], manifest: DiffManifest,\n diffDir: string, config: PrGateConfig,\n ): ReviewerBriefing[] {\n // Resolved ONCE for the whole run, not per reviewer: `require.resolve` hits the filesystem, and the\n // answer cannot differ between two reviewers in the same process.\n const shared = this.contextEntries(repoRoot, config);\n const entryByFile = new Map<string, DiffManifestEntry>();\n for (const e of manifest.entries) entryByFile.set(e.file, e);\n return checklists.map((req: RequiredChecklist): ReviewerBriefing =>\n this.one(repoRoot, req, scan, entryByFile, diffDir, shared, manifest));\n }\n\n // eslint-disable-next-line @typescript-eslint/max-params\n private one(\n repoRoot: string, req: RequiredChecklist, scan: ChecklistScan,\n entryByFile: Map<string, DiffManifestEntry>, diffDir: string, shared: ContextEntry[], manifest: DiffManifest,\n ): ReviewerBriefing {\n const b = new ReviewerBriefing(req.reviewer.agentName, req.id, repoRoot);\n b.docPath = req.doc.trim() === '' ? '' : path.resolve(repoRoot, req.doc);\n b.diffDir = diffDir;\n b.allDiffPath = diffDir === '' ? '' : path.join(diffDir, 'ALL.diff');\n b.manifestPath = diffDir === '' ? '' : path.join(diffDir, 'manifest.json');\n b.myFiles = req.matchedFiles.map((f: string): BriefedFile => this.briefedFile(repoRoot, f, entryByFile));\n b.matchedPatterns = req.matchedPatterns;\n b.required = req.required;\n b.sourceDirs = this.sourceDirsFor(repoRoot, req.matchedFiles);\n b.contextEntries = shared;\n b.fileDiffCommand = scan.context.fileDiffCommand;\n b.dirty = scan.basis.dirty;\n b.ownAgentFileInDiff = this.ownAgentFileIn(manifest, req.reviewer.agentName);\n this.copyManifestFacts(b, manifest);\n return b;\n }\n\n /**\n * One row of the reviewer's table. The SOURCE path comes over with the diff path because the two need\n * identical affordance: when the diff was an absolute path and the source was a parent directory, four of\n * four reviewers read the diff and none opened a source file.\n */\n private briefedFile(repoRoot: string, file: string, entryByFile: Map<string, DiffManifestEntry>): BriefedFile {\n const e = entryByFile.get(file);\n if (e === undefined) return new BriefedFile(file, '', path.resolve(repoRoot, file));\n return new BriefedFile(file, e.diffAbs, e.fileAbs, e.status, e.bytes, e.truncated);\n }\n\n /**\n * Manifest headline facts, copied onto the briefing so the instructions can state them INLINE. A reviewer\n * that never opens the manifest still has to learn whether anything was truncated or excluded — that is\n * precisely the thing it could not otherwise know it was missing.\n */\n private copyManifestFacts(b: ReviewerBriefing, manifest: DiffManifest): void {\n b.changedFileCount = manifest.entries.length;\n b.truncatedCount = manifest.entries.filter((e: DiffManifestEntry): boolean => e.truncated).length;\n b.excludedCount = manifest.excluded.length;\n b.allDiffLines = manifest.allDiffLines;\n b.allDiffBytes = manifest.allDiffBytes;\n b.hashForkPoint = manifest.hashForkPoint;\n b.hashFeatureHead = manifest.hashFeatureHead;\n b.hashMainHead = manifest.hashMainHead;\n }\n\n /**\n * The reviewer agent's own `.claude/agents/<agentName>.md`, when THIS diff changes it. Detected here rather than\n * left to the reviewer to notice: on the measured run two reviewers reviewed their own definition and\n * neither mentioned it, and every PR that edits the review gate reproduces that.\n */\n private ownAgentFileIn(manifest: DiffManifest, agentName: string): string {\n const suffix = path.join('.claude', 'agents', `${agentName}.md`);\n const hit = manifest.entries.find((e: DiffManifestEntry): boolean => e.file.split('/').join(path.sep).endsWith(suffix));\n return hit === undefined ? '' : (hit.fileAbs === '' ? hit.file : hit.fileAbs);\n }\n\n /**\n * Deduped absolute parent dirs of the matched files. Dirs rather than files because the point is to say\n * \"the neighbourhood is here\" — a reviewer already has the file list; what it lacks is where to look for\n * the code AROUND the change.\n */\n private sourceDirsFor(repoRoot: string, files: readonly string[]): string[] {\n const dirs = new Set<string>();\n for (const f of files) dirs.add(path.resolve(repoRoot, path.dirname(f)));\n return [...dirs].sort();\n }\n\n /**\n * The pre-resolved context list, from two config keys with deliberately different jobs:\n *\n * `reviewContextPackages` — installed packages, resolved to their real on-disk dir. This is what deletes\n * the repeated `node_modules/@webpieces` greps: the tooling knows where a package resolved to, and the\n * reviewer does not.\n * `reviewContext` — the repo-specific escape hatch (`{label, path}`) for what tooling cannot possibly\n * guess, e.g. \"queue names live in terraform/services/\".\n *\n * Neither ever drops an entry: an unresolvable package or a missing path is LISTED, with the reason. A\n * silently shorter list is indistinguishable from a complete one.\n */\n private contextEntries(repoRoot: string, config: PrGateConfig): ContextEntry[] {\n const entries: ContextEntry[] = [];\n for (const pkg of config.reviewContextPackages) entries.push(this.resolvePackage(repoRoot, pkg));\n for (const item of config.reviewContext) {\n const abs = path.resolve(repoRoot, item.path);\n entries.push(fs.existsSync(abs)\n ? new ContextEntry(item.label, abs)\n : new ContextEntry(item.label, '', `(configured as \"${item.path}\" but missing)`));\n }\n return entries;\n }\n\n private resolvePackage(repoRoot: string, pkg: string): ContextEntry {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unresolvable package is REPORTED as such, never fatal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const manifestPath = require.resolve(`${pkg}/package.json`, { paths: [repoRoot] });\n const dir = path.dirname(manifestPath);\n // webpieces-disable no-any-unknown -- opaque package.json, only `description` is read\n const meta = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as Record<string, unknown>;\n const desc = typeof meta['description'] === 'string' ? (meta['description'] as string) : '';\n return new ContextEntry(desc === '' ? pkg : `${pkg} — ${desc}`, dir);\n } catch (err: unknown) {\n const error = toError(err);\n void error; // an unresolvable package is REPORTED below, never fatal\n return new ContextEntry(pkg, '', '(not installed — configured in pr-gate.reviewContextPackages)');\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"reviewer-briefing-builder.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/reviewer-briefing-builder.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,0DAA0I;AAC1I,iEAA6D;AAC7D,yCAA2D;AAI3D;;;;;;GAMG;AAEI,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IACH;IAA7B,YAA6B,iBAAoC;QAApC,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAG,CAAC;IAErE,uGAAuG;IACvG,yDAAyD;IACzD,KAAK,CACD,QAAgB,EAAE,IAAmB,EAAE,UAAwC,EAAE,QAAsB,EACvG,OAAe,EAAE,MAAoB;QAErC,oGAAoG;QACpG,kEAAkE;QAClE,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACrD,MAAM,WAAW,GAAG,IAAI,GAAG,EAA6B,CAAC;QACzD,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,OAAO;YAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAC7D,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,GAAsB,EAAoB,EAAE,CAC/D,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,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,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC;QACzE,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC,CAAC,yDAAyD;YACrE,OAAO,IAAI,2BAAY,CAAC,GAAG,EAAE,EAAE,EAAE,+DAA+D,CAAC,CAAC;QACtG,CAAC;IACL,CAAC;CACJ,CAAA;AAjIY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEW,gCAAiB;GADxD,uBAAuB,CAiInC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { BriefedFile, ContextEntry, PrGateConfig, RequiredChecklist, ReviewerBriefing, ReviewJsonService } from '@webpieces/rules-config';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { DiffManifest, DiffManifestEntry } from './diff-materializer';\nimport { ChecklistScan } from './checklist-scanner';\n\n/**\n * Turns a {@link ChecklistScan} plus the materialized {@link DiffManifest} into one {@link ReviewerBriefing}\n * per reviewer — resolving every path to an absolute one, because a reviewer that has to resolve a path\n * ends up searching, and searching is the cost this whole feature exists to remove.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewerBriefingBuilder {\n constructor(private readonly reviewJsonService: ReviewJsonService) {}\n\n /** One briefing per checklist in `checklists` — the OWED ones; a carried verdict is not re-briefed. */\n // eslint-disable-next-line @typescript-eslint/max-params\n build(\n repoRoot: string, scan: ChecklistScan, checklists: readonly RequiredChecklist[], manifest: DiffManifest,\n diffDir: string, config: PrGateConfig,\n ): ReviewerBriefing[] {\n // Resolved ONCE for the whole run, not per reviewer: `require.resolve` hits the filesystem, and the\n // answer cannot differ between two reviewers in the same process.\n const shared = this.contextEntries(repoRoot, config);\n const entryByFile = new Map<string, DiffManifestEntry>();\n for (const e of manifest.entries) entryByFile.set(e.file, e);\n return checklists.map((req: RequiredChecklist): ReviewerBriefing =>\n this.one(repoRoot, req, scan, entryByFile, diffDir, shared, manifest));\n }\n\n // eslint-disable-next-line @typescript-eslint/max-params\n private one(\n repoRoot: string, req: RequiredChecklist, scan: ChecklistScan,\n entryByFile: Map<string, DiffManifestEntry>, diffDir: string, shared: ContextEntry[], manifest: DiffManifest,\n ): ReviewerBriefing {\n const b = new ReviewerBriefing(req.reviewer.agentName, req.id, repoRoot);\n b.docPath = req.doc.trim() === '' ? '' : path.resolve(repoRoot, req.doc);\n b.diffDir = diffDir;\n b.allDiffPath = diffDir === '' ? '' : path.join(diffDir, 'ALL.diff');\n b.manifestPath = diffDir === '' ? '' : path.join(diffDir, 'manifest.json');\n b.myFiles = req.matchedFiles.map((f: string): BriefedFile => this.briefedFile(repoRoot, f, entryByFile));\n b.matchedPatterns = req.matchedPatterns;\n b.required = req.required;\n b.sourceDirs = this.sourceDirsFor(repoRoot, req.matchedFiles);\n b.contextEntries = shared;\n b.fileDiffCommand = scan.context.fileDiffCommand;\n b.dirty = scan.basis.dirty;\n b.ownAgentFileInDiff = this.ownAgentFileIn(manifest, req.reviewer.agentName);\n this.copyManifestFacts(b, manifest);\n return b;\n }\n\n /**\n * One row of the reviewer's table. The SOURCE path comes over with the diff path because the two need\n * identical affordance: when the diff was an absolute path and the source was a parent directory, four of\n * four reviewers read the diff and none opened a source file.\n */\n private briefedFile(repoRoot: string, file: string, entryByFile: Map<string, DiffManifestEntry>): BriefedFile {\n const e = entryByFile.get(file);\n if (e === undefined) return new BriefedFile(file, '', path.resolve(repoRoot, file));\n return new BriefedFile(file, e.diffAbs, e.fileAbs, e.status, e.bytes, e.truncated);\n }\n\n /**\n * Manifest headline facts, copied onto the briefing so the instructions can state them INLINE. A reviewer\n * that never opens the manifest still has to learn whether anything was truncated or excluded — that is\n * precisely the thing it could not otherwise know it was missing.\n */\n private copyManifestFacts(b: ReviewerBriefing, manifest: DiffManifest): void {\n b.changedFileCount = manifest.entries.length;\n b.truncatedCount = manifest.entries.filter((e: DiffManifestEntry): boolean => e.truncated).length;\n b.excludedCount = manifest.excluded.length;\n b.allDiffLines = manifest.allDiffLines;\n b.allDiffBytes = manifest.allDiffBytes;\n b.hashForkPoint = manifest.hashForkPoint;\n b.hashFeatureHead = manifest.hashFeatureHead;\n b.hashMainHead = manifest.hashMainHead;\n }\n\n /**\n * The reviewer agent's own `.claude/agents/<agentName>.md`, when THIS diff changes it. Detected here rather than\n * left to the reviewer to notice: on the measured run two reviewers reviewed their own definition and\n * neither mentioned it, and every PR that edits the review gate reproduces that.\n */\n private ownAgentFileIn(manifest: DiffManifest, agentName: string): string {\n const suffix = path.join('.claude', 'agents', `${agentName}.md`);\n const hit = manifest.entries.find((e: DiffManifestEntry): boolean => e.file.split('/').join(path.sep).endsWith(suffix));\n return hit === undefined ? '' : (hit.fileAbs === '' ? hit.file : hit.fileAbs);\n }\n\n /**\n * Deduped absolute parent dirs of the matched files. Dirs rather than files because the point is to say\n * \"the neighbourhood is here\" — a reviewer already has the file list; what it lacks is where to look for\n * the code AROUND the change.\n */\n private sourceDirsFor(repoRoot: string, files: readonly string[]): string[] {\n const dirs = new Set<string>();\n for (const f of files) dirs.add(path.resolve(repoRoot, path.dirname(f)));\n return [...dirs].sort();\n }\n\n /**\n * The pre-resolved context list, from two config keys with deliberately different jobs:\n *\n * `reviewContextPackages` — installed packages, resolved to their real on-disk dir. This is what deletes\n * the repeated `node_modules/@webpieces` greps: the tooling knows where a package resolved to, and the\n * reviewer does not.\n * `reviewContext` — the repo-specific escape hatch (`{label, path}`) for what tooling cannot possibly\n * guess, e.g. \"queue names live in terraform/services/\".\n *\n * Neither ever drops an entry: an unresolvable package or a missing path is LISTED, with the reason. A\n * silently shorter list is indistinguishable from a complete one.\n */\n private contextEntries(repoRoot: string, config: PrGateConfig): ContextEntry[] {\n const entries: ContextEntry[] = [];\n for (const pkg of config.reviewContextPackages) entries.push(this.resolvePackage(repoRoot, pkg));\n for (const item of config.reviewContext) {\n const abs = path.resolve(repoRoot, item.path);\n entries.push(fs.existsSync(abs)\n ? new ContextEntry(item.label, abs)\n : new ContextEntry(item.label, '', `(configured as \"${item.path}\" but missing)`));\n }\n return entries;\n }\n\n private resolvePackage(repoRoot: string, pkg: string): ContextEntry {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unresolvable package is REPORTED as such, never fatal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const manifestPath = require.resolve(`${pkg}/package.json`, { paths: [repoRoot] });\n const dir = path.dirname(manifestPath);\n // webpieces-disable no-any-unknown -- opaque package.json, only `description` is read\n const meta = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as Record<string, unknown>;\n const desc = typeof meta['description'] === 'string' ? (meta['description'] as string) : '';\n return new ContextEntry(desc === '' ? pkg : `${pkg} — ${desc}`, dir);\n } catch (err: unknown) {\n const error = toError(err);\n void error; // an unresolvable package is REPORTED below, never fatal\n return new ContextEntry(pkg, '', '(not installed — configured in pr-gate.reviewContextPackages)');\n }\n }\n}\n"]}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReviewerIdentityResolver = exports.ReviewerIdentity = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
6
|
+
const repo_workflow_core_1 = require("@webpieces/repo-workflow-core");
|
|
6
7
|
const inversify_1 = require("inversify");
|
|
7
8
|
const verdict_provenance_1 = require("./verdict-provenance");
|
|
8
9
|
/**
|
|
@@ -58,33 +59,33 @@ let ReviewerIdentityResolver = class ReviewerIdentityResolver {
|
|
|
58
59
|
const stamp = this.stamps.take(cwd, checklistId);
|
|
59
60
|
if (stamp !== null) {
|
|
60
61
|
if (this.stamps.isCoordinator(stamp))
|
|
61
|
-
throw new
|
|
62
|
+
throw new tooling_common_1.InformAiError(this.coordinatorRefusal(checklistId, stamp.aiType));
|
|
62
63
|
return new ReviewerIdentity(stamp.aiType, stamp.sessionId, stamp.agentId, stamp.agentType);
|
|
63
64
|
}
|
|
64
65
|
const inHarness = HARNESS_ENV.filter((name) => (env[name] ?? '').trim() !== '');
|
|
65
66
|
if (inHarness.length > 0)
|
|
66
|
-
throw new
|
|
67
|
+
throw new tooling_common_1.InformAiError(this.unstampedRefusal(checklistId, inHarness));
|
|
67
68
|
return new ReviewerIdentity(verdict_provenance_1.HARNESS_TERMINAL, '', '', '');
|
|
68
69
|
}
|
|
69
70
|
coordinatorRefusal(checklistId, aiType) {
|
|
70
|
-
return `${
|
|
71
|
+
return `${repo_workflow_core_1.WRITE_REVIEW_BIN} REFUSED: the ${aiType} harness reports this call comes from the COORDINATING agent, not a\n`
|
|
71
72
|
+ `reviewer subagent. The coordinator may never submit a reviewer's verdict for "${checklistId}" — not by this\n`
|
|
72
73
|
+ 'bin, and not by writing the file (wp-finish-upsert-pr rejects a verdict this bin did not write).\n\n'
|
|
73
74
|
+ 'Spawn the reviewer subagent pnpm wp-review-upsert-pr names and hand it the instructions file; the\n'
|
|
74
75
|
+ 'reviewer submits its own verdict.';
|
|
75
76
|
}
|
|
76
77
|
unstampedRefusal(checklistId, harnessEnv) {
|
|
77
|
-
return `${
|
|
78
|
+
return `${repo_workflow_core_1.WRITE_REVIEW_BIN} REFUSED: this process runs under an AI harness (${harnessEnv.join(', ')} set), but the\n`
|
|
78
79
|
+ `webpieces PreToolUse hook left no identity stamp for checklist "${checklistId}", so nothing can say whether a\n`
|
|
79
80
|
+ 'reviewer subagent or the coordinator is calling.\n\n'
|
|
80
81
|
+ `Run it as a plain Bash command the hook can read, naming the checklist literally:\n`
|
|
81
|
-
+ ` pnpm ${
|
|
82
|
+
+ ` pnpm ${repo_workflow_core_1.WRITE_REVIEW_BIN} --checklist ${checklistId} <<'EOF' … EOF\n`
|
|
82
83
|
+ 'If it already was, the webpieces hooks are not installed in this harness: pnpm wp-install-ai-hooks.';
|
|
83
84
|
}
|
|
84
85
|
};
|
|
85
86
|
exports.ReviewerIdentityResolver = ReviewerIdentityResolver;
|
|
86
87
|
exports.ReviewerIdentityResolver = ReviewerIdentityResolver = tslib_1.__decorate([
|
|
87
88
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
88
|
-
tslib_1.__metadata("design:paramtypes", [
|
|
89
|
+
tslib_1.__metadata("design:paramtypes", [repo_workflow_core_1.ReviewIdentityStampService])
|
|
89
90
|
], ReviewerIdentityResolver);
|
|
90
91
|
//# sourceMappingURL=reviewer-identity.js.map
|