@webpieces/pr-gate 0.4.834 → 0.4.836
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 +3 -3
- package/src/dashboard/author-identity.d.ts +1 -1
- package/src/dashboard/author-identity.js +4 -4
- package/src/dashboard/author-identity.js.map +1 -1
- package/src/scripts/commands/write-review-command.d.ts +2 -1
- package/src/scripts/commands/write-review-command.js +2 -5
- package/src/scripts/commands/write-review-command.js.map +1 -1
- package/src/scripts/commands/write-review-fixes-command.d.ts +2 -1
- package/src/scripts/commands/write-review-fixes-command.js +2 -5
- package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
- package/src/scripts/git-finishUpsertPr.js +7 -10
- package/src/scripts/git-finishUpsertPr.js.map +1 -1
- package/src/scripts/pr-gate-cli-app.d.ts +38 -0
- package/src/scripts/pr-gate-cli-app.js +255 -0
- package/src/scripts/pr-gate-cli-app.js.map +1 -0
- package/src/scripts/pr-gate-cli-invocation.d.ts +27 -0
- package/src/scripts/pr-gate-cli-invocation.js +71 -0
- package/src/scripts/pr-gate-cli-invocation.js.map +1 -0
- package/src/scripts/wp-await-checks.js +7 -21
- package/src/scripts/wp-await-checks.js.map +1 -1
- package/src/scripts/wp-await-reviews.js +7 -18
- package/src/scripts/wp-await-reviews.js.map +1 -1
- package/src/scripts/wp-build.js +7 -31
- package/src/scripts/wp-build.js.map +1 -1
- package/src/scripts/wp-check-pr.js +7 -10
- package/src/scripts/wp-check-pr.js.map +1 -1
- package/src/scripts/wp-cleanup.js +7 -18
- package/src/scripts/wp-cleanup.js.map +1 -1
- package/src/scripts/wp-finish-push-dev.js +7 -14
- package/src/scripts/wp-finish-push-dev.js.map +1 -1
- package/src/scripts/wp-finish-update.js +7 -10
- package/src/scripts/wp-finish-update.js.map +1 -1
- package/src/scripts/wp-human-post-pr.js +7 -9
- package/src/scripts/wp-human-post-pr.js.map +1 -1
- package/src/scripts/wp-land-pr.js +7 -21
- package/src/scripts/wp-land-pr.js.map +1 -1
- package/src/scripts/wp-push-dev.js +7 -38
- package/src/scripts/wp-push-dev.js.map +1 -1
- package/src/scripts/wp-review-upsert-pr.js +7 -10
- package/src/scripts/wp-review-upsert-pr.js.map +1 -1
- package/src/scripts/wp-start-update.js +7 -10
- package/src/scripts/wp-start-update.js.map +1 -1
- package/src/scripts/wp-start-upsert-pr.js +7 -10
- package/src/scripts/wp-start-upsert-pr.js.map +1 -1
- package/src/scripts/wp-sync-main.js +7 -10
- package/src/scripts/wp-sync-main.js.map +1 -1
- package/src/scripts/wp-upsert-hotfix-pr.js +7 -11
- package/src/scripts/wp-upsert-hotfix-pr.js.map +1 -1
- package/src/scripts/wp-write-review-fixes.js +7 -10
- package/src/scripts/wp-write-review-fixes.js.map +1 -1
- package/src/scripts/wp-write-review.js +7 -26
- package/src/scripts/wp-write-review.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/pr-gate",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.836",
|
|
4
4
|
"description": "Gated PR system: 3-point squash-merge, merge validation gate, and red/yellow/green PR dashboard. Standalone scripts, no Nx dependency required.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
19
|
-
"@webpieces/
|
|
20
|
-
"@webpieces/rules-config": "0.4.
|
|
19
|
+
"@webpieces/hook-runtime": "0.4.836",
|
|
20
|
+
"@webpieces/rules-config": "0.4.836",
|
|
21
21
|
"inversify": "7.10.4",
|
|
22
22
|
"reflect-metadata": "0.2.2"
|
|
23
23
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AI_TYPE_UNKNOWN, AiType } from '@webpieces/
|
|
1
|
+
import { AI_TYPE_UNKNOWN, AiType } from '@webpieces/hook-runtime';
|
|
2
2
|
/** The coding harness observed by the gate, plus the model the author reported in summary.json. */
|
|
3
3
|
export declare class AuthorIdentity {
|
|
4
4
|
harness: AiType | typeof AI_TYPE_UNKNOWN;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AuthorIdentityResolver = exports.AuthorIdentity = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
6
6
|
const inversify_1 = require("inversify");
|
|
7
7
|
/** The coding harness observed by the gate, plus the model the author reported in summary.json. */
|
|
8
8
|
class AuthorIdentity {
|
|
@@ -25,12 +25,12 @@ let AuthorIdentityResolver = class AuthorIdentityResolver {
|
|
|
25
25
|
resolve(selfReportedModel) {
|
|
26
26
|
const claude = this.present('CLAUDE_CODE_SESSION_ID');
|
|
27
27
|
const codex = this.present('CODEX_SESSION_ID') || this.present('CODEX_THREAD_ID');
|
|
28
|
-
let harness =
|
|
28
|
+
let harness = hook_runtime_1.AI_TYPE_UNKNOWN;
|
|
29
29
|
if (claude !== codex)
|
|
30
30
|
harness = claude ? 'claude-code' : 'codex';
|
|
31
31
|
// Keep this tied to ai-hook-rules' canonical vocabulary rather than growing a second spelling.
|
|
32
|
-
if (harness !==
|
|
33
|
-
harness =
|
|
32
|
+
if (harness !== hook_runtime_1.AI_TYPE_UNKNOWN && !hook_runtime_1.AI_TYPES.includes(harness))
|
|
33
|
+
harness = hook_runtime_1.AI_TYPE_UNKNOWN;
|
|
34
34
|
const model = selfReportedModel.trim() === '' ? 'unknown' : selfReportedModel.trim();
|
|
35
35
|
return new AuthorIdentity(harness, model);
|
|
36
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"author-identity.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/dashboard/author-identity.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"author-identity.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/dashboard/author-identity.ts"],"names":[],"mappings":";;;;AAAA,0DAA4E;AAC5E,yCAA2D;AAE3D,mGAAmG;AACnG,MAAa,cAAc;IACvB,OAAO,CAAkC;IACzC,KAAK,CAAS;IAEd,YAAY,OAAwC,EAAE,KAAa;QAC/D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AARD,wCAQC;AAED;;;;;;GAMG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAC/B,OAAO,CAAC,iBAAyB;QAC7B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC;QACtD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAClF,IAAI,OAAO,GAAoC,8BAAe,CAAC;QAC/D,IAAI,MAAM,KAAK,KAAK;YAAE,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC;QACjE,+FAA+F;QAC/F,IAAI,OAAO,KAAK,8BAAe,IAAI,CAAC,uBAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,OAAO,GAAG,8BAAe,CAAC;QAC1F,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;QACrF,OAAO,IAAI,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IAEO,OAAO,CAAC,IAAY;QACxB,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;IACnD,CAAC;CACJ,CAAA;AAfY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,sBAAsB,CAelC","sourcesContent":["import { AI_TYPES, AI_TYPE_UNKNOWN, AiType } from '@webpieces/hook-runtime';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/** The coding harness observed by the gate, plus the model the author reported in summary.json. */\nexport class AuthorIdentity {\n harness: AiType | typeof AI_TYPE_UNKNOWN;\n model: string;\n\n constructor(harness: AiType | typeof AI_TYPE_UNKNOWN, model: string) {\n this.harness = harness;\n this.model = model;\n }\n}\n\n/**\n * Resolves the authoring harness from session identifiers supplied by the harness itself.\n *\n * This deliberately does not trust summary.json's `agent` field: that file is AI-authored, while the\n * session variables are supplied by Claude Code / Codex before the model runs. Both-or-neither is\n * `unknown`; silently picking one in an ambiguous process would turn telemetry into a false claim.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class AuthorIdentityResolver {\n resolve(selfReportedModel: string): AuthorIdentity {\n const claude = this.present('CLAUDE_CODE_SESSION_ID');\n const codex = this.present('CODEX_SESSION_ID') || this.present('CODEX_THREAD_ID');\n let harness: AiType | typeof AI_TYPE_UNKNOWN = AI_TYPE_UNKNOWN;\n if (claude !== codex) harness = claude ? 'claude-code' : 'codex';\n // Keep this tied to ai-hook-rules' canonical vocabulary rather than growing a second spelling.\n if (harness !== AI_TYPE_UNKNOWN && !AI_TYPES.includes(harness)) harness = AI_TYPE_UNKNOWN;\n const model = selfReportedModel.trim() === '' ? 'unknown' : selfReportedModel.trim();\n return new AuthorIdentity(harness, model);\n }\n\n private present(name: string): boolean {\n return (process.env[name] ?? '').trim() !== '';\n }\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import { AiBranchName } from '../workflow/git-readAiBranchName';
|
|
|
3
3
|
import { ReviewStageReceiptService } from '../workflow/review-stage-receipt';
|
|
4
4
|
import { ReviewerIdentityResolver } from '../workflow/reviewer-identity';
|
|
5
5
|
import { VerdictProvenanceService } from '../workflow/verdict-provenance';
|
|
6
|
+
import type { PrGateCliStdin } from '../pr-gate-cli-invocation';
|
|
6
7
|
/** What `wp-write-review` was asked to do. Data-only. */
|
|
7
8
|
export declare class WriteReviewOptions {
|
|
8
9
|
checklistId: string;
|
|
@@ -84,5 +85,5 @@ export declare class WriteReviewCommand {
|
|
|
84
85
|
* so the command stays a function of its inputs.
|
|
85
86
|
*/
|
|
86
87
|
export declare class WriteReviewInput {
|
|
87
|
-
read(filePath: string): string;
|
|
88
|
+
read(filePath: string, stdin: PrGateCliStdin): string;
|
|
88
89
|
}
|
|
@@ -241,16 +241,13 @@ exports.WriteReviewCommand = WriteReviewCommand = tslib_1.__decorate([
|
|
|
241
241
|
* so the command stays a function of its inputs.
|
|
242
242
|
*/
|
|
243
243
|
let WriteReviewInput = class WriteReviewInput {
|
|
244
|
-
read(filePath) {
|
|
244
|
+
read(filePath, stdin) {
|
|
245
245
|
if (filePath.trim() !== '') {
|
|
246
246
|
if (!fs.existsSync(filePath))
|
|
247
247
|
throw new rules_config_1.InformAiError(`${rules_config_1.WRITE_REVIEW_BIN}: --file ${filePath} does not exist.`);
|
|
248
248
|
return fs.readFileSync(filePath, 'utf8');
|
|
249
249
|
}
|
|
250
|
-
|
|
251
|
-
throw new rules_config_1.InformAiError(`${rules_config_1.WRITE_REVIEW_BIN}: pass the verdict JSON on stdin (pnpm ${rules_config_1.WRITE_REVIEW_BIN} --checklist <id> <<'EOF' … EOF) or with --file <path>.`);
|
|
252
|
-
}
|
|
253
|
-
return fs.readFileSync(0, 'utf8');
|
|
250
|
+
return stdin.read();
|
|
254
251
|
}
|
|
255
252
|
};
|
|
256
253
|
exports.WriteReviewInput = WriteReviewInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-review-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/write-review-command.ts"],"names":[],"mappings":";;;;AAAA,+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AXY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,gBAAgB,CAW5B","sourcesContent":["import * as fs from 'fs';\nimport {\n InformAiError, RepoRootFinder, ReviewJsonService, VERDICT_ORANGE, VERDICT_RED, VERDICT_STATUSES, WRITE_REVIEW_BIN, checklistOverrideService,\n summaryJsonPath, toError,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { ReviewStageReceipt, ReviewStageReceiptService } from '../workflow/review-stage-receipt';\nimport { ReviewerIdentity, ReviewerIdentityResolver } from '../workflow/reviewer-identity';\nimport { SubmittedVerdict, VerdictProvenance, VerdictProvenanceService } from '../workflow/verdict-provenance';\n\n/** The only keys a verdict may carry. Anything else is somebody's second schema. */\nconst VERDICT_KEYS = ['id', 'status', 'agent', 'model', 'output'] as const;\n\n/** What `wp-write-review` was asked to do. Data-only. */\nexport class WriteReviewOptions {\n checklistId: string;\n // The verdict JSON itself — read from `--file` or stdin by the composition root, so this command is a\n // function of its inputs and a spec can drive it without a pipe.\n json: string;\n // Where the caller stands — the tree whose review dir and hook stamp are used. Passed in (the bin\n // passes process.cwd()) rather than read here, for the same reason `json` is.\n cwd: string;\n\n constructor(checklistId: string, json: string, cwd: string) {\n this.checklistId = checklistId;\n this.json = json;\n this.cwd = cwd;\n }\n}\n\n/** What `wp-write-review --check` was asked: may this checklist still be reviewed? Data-only. */\nexport class ReviewBudgetCheckOptions {\n checklistId: string;\n cwd: string;\n\n constructor(checklistId: string, cwd: string) {\n this.checklistId = checklistId;\n this.cwd = cwd;\n }\n}\n\n/**\n * `wp-write-review` — the ONE way any reviewer, Claude or Codex, submits a checklist verdict (issue #863).\n *\n * Before it existed a verdict was \"a file with the right shape at the right path\", and that is exactly what\n * a Codex coordinator produced on two merged PRs: the shared-tree guard blocked its reviewer's write, the\n * guard's own cure said to hand the edit to the coordinator, the coordinator wrote all five verdicts, and\n * `wp-finish-upsert-pr` accepted them. Now:\n * 1. the caller is identified by the harness (ReviewerIdentityResolver) and the COORDINATOR is refused;\n * 2. the checklist must be one stage ② briefed this round (its receipt), so a carried verdict cannot be\n * overwritten and a checklist that does not apply cannot be invented;\n * 3. the verdict is validated strictly — the five fields, nothing else;\n * 4. it is written as `review-round<N>-<id>.json` WITH `review-round<N>-<id>.provenance.json`: who, which\n * commit, which in-scope diff, and a hash of the verdict. `wp-finish-upsert-pr` rejects a verdict\n * without one, or one edited since;\n * 5. the round must be inside the budget (issues #1051, #1053): a round above `maxReviewerRounds` records\n * nothing, and a round's verdict is never overwritten, whoever spawned the reviewer. `--check` asks the\n * same question BEFORE a reviewer spends a review on it;\n * 6. the color must fit the round (issue #1053): the FINAL round has no red — its must-fix color is\n * orange, never re-reviewed — and orange is refused before the final round, where red still means\n * \"fix it and it will be reviewed again\".\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class WriteReviewCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly receipts: ReviewStageReceiptService,\n private readonly identity: ReviewerIdentityResolver,\n private readonly provenance: VerdictProvenanceService,\n private readonly reviewJsonService: ReviewJsonService,\n ) {}\n\n run(opts: WriteReviewOptions): Promise<void> {\n const id = opts.checklistId.trim();\n const cwd = opts.cwd;\n const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);\n const featureName = this.aiBranchName.getFeatureName();\n const receipt = this.briefedReceipt(repoRoot, featureName, id);\n // Identity BEFORE parsing: a coordinator is refused whatever it submitted, and the stamp it\n // consumes must not survive to lend itself to a later call.\n const who: ReviewerIdentity = this.identity.resolve(cwd, id);\n this.assertWithinBudget(summaryJsonPath(repoRoot, featureName), receipt, id);\n const verdict = this.parse(opts.json, id, receipt);\n const record = new VerdictProvenance(\n id, who.harness, who.sessionId, who.agentId, who.agentType, receipt.headSha, receipt.scopeHashes[id] ?? '');\n record.round = receipt.round;\n const written = this.provenance.write(summaryJsonPath(repoRoot, featureName), verdict, record);\n process.stdout.write(\n `✅ ${verdict.status.toUpperCase()} verdict for \"${id}\" submitted → ${written}\\n`\n + ` provenance: ${who.harness}${who.agentId === '' ? '' : ` agent ${who.agentId}`}, `\n + `briefed at ${receipt.headSha.slice(0, 8)}, global round ${receipt.round} of ${receipt.maxReviewerRounds}\\n`);\n return Promise.resolve();\n }\n\n /**\n * `wp-write-review --check`: the reviewer's FIRST step. Refuses exactly when {@link run} would refuse\n * on the budget, so a reviewer past the budget learns it before it reviews rather than after.\n */\n check(opts: ReviewBudgetCheckOptions): Promise<void> {\n const id = opts.checklistId.trim();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(opts.cwd);\n const featureName = this.aiBranchName.getFeatureName();\n const receipt = this.briefedReceipt(repoRoot, featureName, id);\n this.assertWithinBudget(summaryJsonPath(repoRoot, featureName), receipt, id);\n const final = this.isFinalRound(receipt)\n ? ` This is the FINAL round: there is no re-review, so you may NOT mark ${VERDICT_RED} — mark every must-fix finding ${VERDICT_ORANGE}.`\n : '';\n process.stdout.write(\n `✅ \"${id}\" may be reviewed: this is review round ${receipt.round} of at most ${receipt.maxReviewerRounds}.${final} `\n + `Review it, then submit with pnpm ${WRITE_REVIEW_BIN} --checklist ${id}.\\n`);\n return Promise.resolve();\n }\n\n /** The last round `maxReviewerRounds` allows — the one with no red (issue #1053). */\n private isFinalRound(receipt: ReviewStageReceipt): boolean {\n return receipt.round >= receipt.maxReviewerRounds;\n }\n\n /**\n * THE ROUND CAP, held by the reviewer's own submission path (issues #1051, #1053). The planner already\n * never briefs past the cap, but an author agent could still spawn a reviewer from an old instructions\n * file — the measured deadlock did exactly that. Two refusals make it mechanical: a round above\n * `maxReviewerRounds` records nothing, and a checklist that already has a verdict in this round (or a\n * later one) gets no second one — a round's verdict is never overwritten.\n */\n private assertWithinBudget(summaryPath: string, receipt: ReviewStageReceipt, id: string): void {\n const max = receipt.maxReviewerRounds;\n const latest = this.reviewJsonService.latestVerdictRound(summaryPath, id);\n if (receipt.round <= max && latest < receipt.round) return;\n const why = receipt.round > max\n ? `this briefing is for review round ${receipt.round}, above maxReviewerRounds (${max})`\n : `it already has a verdict for review round ${latest} (maxReviewerRounds is ${max}), and a round's verdict is never overwritten`;\n throw new InformAiError(\n `I am not allowed to review ${id}: ${why}.\\n`\n + `Do not review it and submit nothing for it; report this refusal, verbatim, to the agent that spawned you. `\n + `The verdict already recorded for it stands (${this.reviewJsonService.latestChecklistResultPath(summaryPath, id) || 'none'}), and `\n + 'the author records any fix with pnpm wp-write-review-fixes.');\n }\n\n /** The stage-② receipt, provided it briefed THIS checklist this round. */\n private briefedReceipt(repoRoot: string, featureName: string, id: string): ReviewStageReceipt {\n if (id === '') throw new InformAiError(`${WRITE_REVIEW_BIN} needs the checklist id: pnpm ${WRITE_REVIEW_BIN} --checklist <id>`);\n const receipt = this.receipts.read(repoRoot, featureName);\n if (receipt === null) {\n throw new InformAiError(`${WRITE_REVIEW_BIN}: pnpm wp-review-upsert-pr has not briefed any reviewer on this branch yet, `\n + 'so there is nothing to submit a verdict against.');\n }\n if (!receipt.reviewersBriefed.includes(id) || (receipt.scopeHashes[id] ?? '') === '') {\n const briefed = receipt.reviewersBriefed.length === 0 ? '(none)' : receipt.reviewersBriefed.join(', ');\n throw new InformAiError(`${WRITE_REVIEW_BIN}: checklist \"${id}\" was not briefed by the last pnpm wp-review-upsert-pr `\n + `(briefed this round: ${briefed}). Submit only for a checklist whose instructions file you were handed — `\n + 'a checklist absent here either carries its earlier verdict or does not apply to this diff.');\n }\n return receipt;\n }\n\n /**\n * Strict: an object with exactly the verdict's five fields, every one a string, and a status that fits\n * the round — red only BEFORE the final round, orange only ON it (issue #1053).\n */\n private parse(json: string, id: string, receipt: ReviewStageReceipt): SubmittedVerdict {\n const raw = this.parseObject(json);\n const problems: string[] = [];\n const extra = Object.keys(raw).filter((k: string): boolean => !(VERDICT_KEYS as readonly string[]).includes(k));\n if (extra.includes('override')) {\n problems.push(`\"override\" is not a verdict field — a ship-anyway decision is a HUMAN's, recorded by the coordinating agent in ${checklistOverrideService.overrideFileName(id)}`);\n }\n if (extra.length > 0) problems.push(`unknown field(s) ${extra.map((k: string): string => `\"${k}\"`).join(', ')} — a verdict has exactly: ${VERDICT_KEYS.join(', ')}`);\n if (raw['id'] !== undefined && this.text(raw, 'id') !== id) problems.push(`\"id\" is ${JSON.stringify(raw['id'])} but --checklist is \"${id}\"`);\n const status = this.text(raw, 'status').toLowerCase();\n // webpieces-disable no-any-unknown -- comparing against the readonly literal tuple of valid colors\n if (!(VERDICT_STATUSES as readonly string[]).includes(status)) problems.push(`\"status\" must be one of ${VERDICT_STATUSES.join(', ')}`);\n problems.push(...this.colorForRound(status, receipt));\n for (const key of ['agent', 'model', 'output']) {\n if (this.text(raw, key) === '') problems.push(`\"${key}\" must be a non-empty string${key === 'output' ? '' : ' (use \"unknown\" when unavailable)'}`);\n }\n if (problems.length > 0) {\n throw new InformAiError(`${WRITE_REVIEW_BIN}: the verdict for \"${id}\" was NOT submitted:\\n`\n + problems.map((p: string): string => ` • ${p}`).join('\\n'));\n }\n return new SubmittedVerdict(id, status, this.text(raw, 'agent'), this.text(raw, 'model'), raw['output'] as string);\n }\n\n /**\n * The round decides which blocking color exists. The FINAL round's red would mean \"fix it and it will be\n * reviewed again\", and there is no again — so it is refused and orange named. Orange before the final\n * round would waive a re-review that the budget still pays for — so it is refused and red named.\n */\n private colorForRound(status: string, receipt: ReviewStageReceipt): string[] {\n const round = `review round ${receipt.round} of ${receipt.maxReviewerRounds}`;\n if (status === VERDICT_RED && this.isFinalRound(receipt)) {\n return [`\"status\": \"${VERDICT_RED}\" is not allowed: ${round} is the FINAL round, and there is no re-review. `\n + `Mark anything that must be fixed \"${VERDICT_ORANGE}\", with a concrete, actionable fix in \"output\" — the author applies it `\n + 'best effort and ships without another review.'];\n }\n if (status === VERDICT_ORANGE && !this.isFinalRound(receipt)) {\n return [`\"status\": \"${VERDICT_ORANGE}\" is only for the FINAL review round, and ${round} is not it. `\n + `Use \"${VERDICT_RED}\" for a must-fix finding: the author's fix will be reviewed again next round.`];\n }\n return [];\n }\n\n // webpieces-disable no-any-unknown -- one field of the opaque submitted object, narrowed to a trimmed string\n private text(raw: Record<string, unknown>, key: string): string {\n const value = raw[key];\n return typeof value === 'string' ? value.trim() : '';\n }\n\n // webpieces-disable no-any-unknown -- the submitted JSON is opaque until parse() narrows every field\n private parseObject(json: string): Record<string, unknown> {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed\n let parsed: unknown = null;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: a JSON syntax error becomes the AI-facing refusal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n parsed = JSON.parse(json);\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(`${WRITE_REVIEW_BIN}: the verdict is not valid JSON.`, { cause: error });\n }\n if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n throw new InformAiError(`${WRITE_REVIEW_BIN}: the verdict must be ONE JSON object.`);\n }\n // webpieces-disable no-any-unknown -- narrowed to a plain object just above\n return parsed as Record<string, unknown>;\n }\n}\n\n/**\n * Reads the verdict JSON for the composition root: `--file <path>`, else stdin. Separate from the command\n * so the command stays a function of its inputs.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class WriteReviewInput {\n read(filePath: string): string {\n if (filePath.trim() !== '') {\n if (!fs.existsSync(filePath)) throw new InformAiError(`${WRITE_REVIEW_BIN}: --file ${filePath} does not exist.`);\n return fs.readFileSync(filePath, 'utf8');\n }\n if (process.stdin.isTTY === true) {\n throw new InformAiError(`${WRITE_REVIEW_BIN}: pass the verdict JSON on stdin (pnpm ${WRITE_REVIEW_BIN} --checklist <id> <<'EOF' … EOF) or with --file <path>.`);\n }\n return fs.readFileSync(0, 'utf8');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"write-review-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/write-review-command.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,0DAGiC;AACjC,yCAA2D;AAC3D,2EAAgE;AAChE,2EAAiG;AACjG,qEAA2F;AAC3F,uEAA+G;AAG/G,oFAAoF;AACpF,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC;AAE3E,yDAAyD;AACzD,MAAa,kBAAkB;IAC3B,WAAW,CAAS;IACpB,sGAAsG;IACtG,iEAAiE;IACjE,IAAI,CAAS;IACb,kGAAkG;IAClG,8EAA8E;IAC9E,GAAG,CAAS;IAEZ,YAAY,WAAmB,EAAE,IAAY,EAAE,GAAW;QACtD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;CACJ;AAdD,gDAcC;AAED,iGAAiG;AACjG,MAAa,wBAAwB;IACjC,WAAW,CAAS;IACpB,GAAG,CAAS;IAEZ,YAAY,WAAmB,EAAE,GAAW;QACxC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;CACJ;AARD,4DAQC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAGN;IACA;IACA;IACA;IACA;IACA;IAPrB,yDAAyD;IACzD,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,QAAmC,EACnC,QAAkC,EAClC,UAAoC,EACpC,iBAAoC;QALpC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAA2B;QACnC,aAAQ,G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AAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,gBAAgB,CAQ5B","sourcesContent":["import * as fs from 'fs';\nimport {\n InformAiError, RepoRootFinder, ReviewJsonService, VERDICT_ORANGE, VERDICT_RED, VERDICT_STATUSES, WRITE_REVIEW_BIN, checklistOverrideService,\n summaryJsonPath, toError,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { ReviewStageReceipt, ReviewStageReceiptService } from '../workflow/review-stage-receipt';\nimport { ReviewerIdentity, ReviewerIdentityResolver } from '../workflow/reviewer-identity';\nimport { SubmittedVerdict, VerdictProvenance, VerdictProvenanceService } from '../workflow/verdict-provenance';\nimport type { PrGateCliStdin } from '../pr-gate-cli-invocation';\n\n/** The only keys a verdict may carry. Anything else is somebody's second schema. */\nconst VERDICT_KEYS = ['id', 'status', 'agent', 'model', 'output'] as const;\n\n/** What `wp-write-review` was asked to do. Data-only. */\nexport class WriteReviewOptions {\n checklistId: string;\n // The verdict JSON itself — read from `--file` or stdin by the composition root, so this command is a\n // function of its inputs and a spec can drive it without a pipe.\n json: string;\n // Where the caller stands — the tree whose review dir and hook stamp are used. Passed in (the bin\n // passes process.cwd()) rather than read here, for the same reason `json` is.\n cwd: string;\n\n constructor(checklistId: string, json: string, cwd: string) {\n this.checklistId = checklistId;\n this.json = json;\n this.cwd = cwd;\n }\n}\n\n/** What `wp-write-review --check` was asked: may this checklist still be reviewed? Data-only. */\nexport class ReviewBudgetCheckOptions {\n checklistId: string;\n cwd: string;\n\n constructor(checklistId: string, cwd: string) {\n this.checklistId = checklistId;\n this.cwd = cwd;\n }\n}\n\n/**\n * `wp-write-review` — the ONE way any reviewer, Claude or Codex, submits a checklist verdict (issue #863).\n *\n * Before it existed a verdict was \"a file with the right shape at the right path\", and that is exactly what\n * a Codex coordinator produced on two merged PRs: the shared-tree guard blocked its reviewer's write, the\n * guard's own cure said to hand the edit to the coordinator, the coordinator wrote all five verdicts, and\n * `wp-finish-upsert-pr` accepted them. Now:\n * 1. the caller is identified by the harness (ReviewerIdentityResolver) and the COORDINATOR is refused;\n * 2. the checklist must be one stage ② briefed this round (its receipt), so a carried verdict cannot be\n * overwritten and a checklist that does not apply cannot be invented;\n * 3. the verdict is validated strictly — the five fields, nothing else;\n * 4. it is written as `review-round<N>-<id>.json` WITH `review-round<N>-<id>.provenance.json`: who, which\n * commit, which in-scope diff, and a hash of the verdict. `wp-finish-upsert-pr` rejects a verdict\n * without one, or one edited since;\n * 5. the round must be inside the budget (issues #1051, #1053): a round above `maxReviewerRounds` records\n * nothing, and a round's verdict is never overwritten, whoever spawned the reviewer. `--check` asks the\n * same question BEFORE a reviewer spends a review on it;\n * 6. the color must fit the round (issue #1053): the FINAL round has no red — its must-fix color is\n * orange, never re-reviewed — and orange is refused before the final round, where red still means\n * \"fix it and it will be reviewed again\".\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class WriteReviewCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly receipts: ReviewStageReceiptService,\n private readonly identity: ReviewerIdentityResolver,\n private readonly provenance: VerdictProvenanceService,\n private readonly reviewJsonService: ReviewJsonService,\n ) {}\n\n run(opts: WriteReviewOptions): Promise<void> {\n const id = opts.checklistId.trim();\n const cwd = opts.cwd;\n const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);\n const featureName = this.aiBranchName.getFeatureName();\n const receipt = this.briefedReceipt(repoRoot, featureName, id);\n // Identity BEFORE parsing: a coordinator is refused whatever it submitted, and the stamp it\n // consumes must not survive to lend itself to a later call.\n const who: ReviewerIdentity = this.identity.resolve(cwd, id);\n this.assertWithinBudget(summaryJsonPath(repoRoot, featureName), receipt, id);\n const verdict = this.parse(opts.json, id, receipt);\n const record = new VerdictProvenance(\n id, who.harness, who.sessionId, who.agentId, who.agentType, receipt.headSha, receipt.scopeHashes[id] ?? '');\n record.round = receipt.round;\n const written = this.provenance.write(summaryJsonPath(repoRoot, featureName), verdict, record);\n process.stdout.write(\n `✅ ${verdict.status.toUpperCase()} verdict for \"${id}\" submitted → ${written}\\n`\n + ` provenance: ${who.harness}${who.agentId === '' ? '' : ` agent ${who.agentId}`}, `\n + `briefed at ${receipt.headSha.slice(0, 8)}, global round ${receipt.round} of ${receipt.maxReviewerRounds}\\n`);\n return Promise.resolve();\n }\n\n /**\n * `wp-write-review --check`: the reviewer's FIRST step. Refuses exactly when {@link run} would refuse\n * on the budget, so a reviewer past the budget learns it before it reviews rather than after.\n */\n check(opts: ReviewBudgetCheckOptions): Promise<void> {\n const id = opts.checklistId.trim();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(opts.cwd);\n const featureName = this.aiBranchName.getFeatureName();\n const receipt = this.briefedReceipt(repoRoot, featureName, id);\n this.assertWithinBudget(summaryJsonPath(repoRoot, featureName), receipt, id);\n const final = this.isFinalRound(receipt)\n ? ` This is the FINAL round: there is no re-review, so you may NOT mark ${VERDICT_RED} — mark every must-fix finding ${VERDICT_ORANGE}.`\n : '';\n process.stdout.write(\n `✅ \"${id}\" may be reviewed: this is review round ${receipt.round} of at most ${receipt.maxReviewerRounds}.${final} `\n + `Review it, then submit with pnpm ${WRITE_REVIEW_BIN} --checklist ${id}.\\n`);\n return Promise.resolve();\n }\n\n /** The last round `maxReviewerRounds` allows — the one with no red (issue #1053). */\n private isFinalRound(receipt: ReviewStageReceipt): boolean {\n return receipt.round >= receipt.maxReviewerRounds;\n }\n\n /**\n * THE ROUND CAP, held by the reviewer's own submission path (issues #1051, #1053). The planner already\n * never briefs past the cap, but an author agent could still spawn a reviewer from an old instructions\n * file — the measured deadlock did exactly that. Two refusals make it mechanical: a round above\n * `maxReviewerRounds` records nothing, and a checklist that already has a verdict in this round (or a\n * later one) gets no second one — a round's verdict is never overwritten.\n */\n private assertWithinBudget(summaryPath: string, receipt: ReviewStageReceipt, id: string): void {\n const max = receipt.maxReviewerRounds;\n const latest = this.reviewJsonService.latestVerdictRound(summaryPath, id);\n if (receipt.round <= max && latest < receipt.round) return;\n const why = receipt.round > max\n ? `this briefing is for review round ${receipt.round}, above maxReviewerRounds (${max})`\n : `it already has a verdict for review round ${latest} (maxReviewerRounds is ${max}), and a round's verdict is never overwritten`;\n throw new InformAiError(\n `I am not allowed to review ${id}: ${why}.\\n`\n + `Do not review it and submit nothing for it; report this refusal, verbatim, to the agent that spawned you. `\n + `The verdict already recorded for it stands (${this.reviewJsonService.latestChecklistResultPath(summaryPath, id) || 'none'}), and `\n + 'the author records any fix with pnpm wp-write-review-fixes.');\n }\n\n /** The stage-② receipt, provided it briefed THIS checklist this round. */\n private briefedReceipt(repoRoot: string, featureName: string, id: string): ReviewStageReceipt {\n if (id === '') throw new InformAiError(`${WRITE_REVIEW_BIN} needs the checklist id: pnpm ${WRITE_REVIEW_BIN} --checklist <id>`);\n const receipt = this.receipts.read(repoRoot, featureName);\n if (receipt === null) {\n throw new InformAiError(`${WRITE_REVIEW_BIN}: pnpm wp-review-upsert-pr has not briefed any reviewer on this branch yet, `\n + 'so there is nothing to submit a verdict against.');\n }\n if (!receipt.reviewersBriefed.includes(id) || (receipt.scopeHashes[id] ?? '') === '') {\n const briefed = receipt.reviewersBriefed.length === 0 ? '(none)' : receipt.reviewersBriefed.join(', ');\n throw new InformAiError(`${WRITE_REVIEW_BIN}: checklist \"${id}\" was not briefed by the last pnpm wp-review-upsert-pr `\n + `(briefed this round: ${briefed}). Submit only for a checklist whose instructions file you were handed — `\n + 'a checklist absent here either carries its earlier verdict or does not apply to this diff.');\n }\n return receipt;\n }\n\n /**\n * Strict: an object with exactly the verdict's five fields, every one a string, and a status that fits\n * the round — red only BEFORE the final round, orange only ON it (issue #1053).\n */\n private parse(json: string, id: string, receipt: ReviewStageReceipt): SubmittedVerdict {\n const raw = this.parseObject(json);\n const problems: string[] = [];\n const extra = Object.keys(raw).filter((k: string): boolean => !(VERDICT_KEYS as readonly string[]).includes(k));\n if (extra.includes('override')) {\n problems.push(`\"override\" is not a verdict field — a ship-anyway decision is a HUMAN's, recorded by the coordinating agent in ${checklistOverrideService.overrideFileName(id)}`);\n }\n if (extra.length > 0) problems.push(`unknown field(s) ${extra.map((k: string): string => `\"${k}\"`).join(', ')} — a verdict has exactly: ${VERDICT_KEYS.join(', ')}`);\n if (raw['id'] !== undefined && this.text(raw, 'id') !== id) problems.push(`\"id\" is ${JSON.stringify(raw['id'])} but --checklist is \"${id}\"`);\n const status = this.text(raw, 'status').toLowerCase();\n // webpieces-disable no-any-unknown -- comparing against the readonly literal tuple of valid colors\n if (!(VERDICT_STATUSES as readonly string[]).includes(status)) problems.push(`\"status\" must be one of ${VERDICT_STATUSES.join(', ')}`);\n problems.push(...this.colorForRound(status, receipt));\n for (const key of ['agent', 'model', 'output']) {\n if (this.text(raw, key) === '') problems.push(`\"${key}\" must be a non-empty string${key === 'output' ? '' : ' (use \"unknown\" when unavailable)'}`);\n }\n if (problems.length > 0) {\n throw new InformAiError(`${WRITE_REVIEW_BIN}: the verdict for \"${id}\" was NOT submitted:\\n`\n + problems.map((p: string): string => ` • ${p}`).join('\\n'));\n }\n return new SubmittedVerdict(id, status, this.text(raw, 'agent'), this.text(raw, 'model'), raw['output'] as string);\n }\n\n /**\n * The round decides which blocking color exists. The FINAL round's red would mean \"fix it and it will be\n * reviewed again\", and there is no again — so it is refused and orange named. Orange before the final\n * round would waive a re-review that the budget still pays for — so it is refused and red named.\n */\n private colorForRound(status: string, receipt: ReviewStageReceipt): string[] {\n const round = `review round ${receipt.round} of ${receipt.maxReviewerRounds}`;\n if (status === VERDICT_RED && this.isFinalRound(receipt)) {\n return [`\"status\": \"${VERDICT_RED}\" is not allowed: ${round} is the FINAL round, and there is no re-review. `\n + `Mark anything that must be fixed \"${VERDICT_ORANGE}\", with a concrete, actionable fix in \"output\" — the author applies it `\n + 'best effort and ships without another review.'];\n }\n if (status === VERDICT_ORANGE && !this.isFinalRound(receipt)) {\n return [`\"status\": \"${VERDICT_ORANGE}\" is only for the FINAL review round, and ${round} is not it. `\n + `Use \"${VERDICT_RED}\" for a must-fix finding: the author's fix will be reviewed again next round.`];\n }\n return [];\n }\n\n // webpieces-disable no-any-unknown -- one field of the opaque submitted object, narrowed to a trimmed string\n private text(raw: Record<string, unknown>, key: string): string {\n const value = raw[key];\n return typeof value === 'string' ? value.trim() : '';\n }\n\n // webpieces-disable no-any-unknown -- the submitted JSON is opaque until parse() narrows every field\n private parseObject(json: string): Record<string, unknown> {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed\n let parsed: unknown = null;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: a JSON syntax error becomes the AI-facing refusal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n parsed = JSON.parse(json);\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(`${WRITE_REVIEW_BIN}: the verdict is not valid JSON.`, { cause: error });\n }\n if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n throw new InformAiError(`${WRITE_REVIEW_BIN}: the verdict must be ONE JSON object.`);\n }\n // webpieces-disable no-any-unknown -- narrowed to a plain object just above\n return parsed as Record<string, unknown>;\n }\n}\n\n/**\n * Reads the verdict JSON for the composition root: `--file <path>`, else stdin. Separate from the command\n * so the command stays a function of its inputs.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class WriteReviewInput {\n read(filePath: string, stdin: PrGateCliStdin): string {\n if (filePath.trim() !== '') {\n if (!fs.existsSync(filePath)) throw new InformAiError(`${WRITE_REVIEW_BIN}: --file ${filePath} does not exist.`);\n return fs.readFileSync(filePath, 'utf8');\n }\n return stdin.read();\n }\n}\n"]}
|
|
@@ -2,6 +2,7 @@ import { RepoRootFinder } from '@webpieces/rules-config';
|
|
|
2
2
|
import { AiBranchName } from '../workflow/git-readAiBranchName';
|
|
3
3
|
import { ReviewRoundStateService } from '../workflow/review-round-state';
|
|
4
4
|
import { ReviewStageReceiptService } from '../workflow/review-stage-receipt';
|
|
5
|
+
import type { PrGateCliStdin } from '../pr-gate-cli-invocation';
|
|
5
6
|
export declare class WriteReviewFixesOptions {
|
|
6
7
|
json: string;
|
|
7
8
|
cwd: string;
|
|
@@ -21,5 +22,5 @@ export declare class WriteReviewFixesCommand {
|
|
|
21
22
|
run(opts: WriteReviewFixesOptions): Promise<void>;
|
|
22
23
|
}
|
|
23
24
|
export declare class WriteReviewFixesInput {
|
|
24
|
-
read(filePath: string): string;
|
|
25
|
+
read(filePath: string, stdin: PrGateCliStdin): string;
|
|
25
26
|
}
|
|
@@ -53,16 +53,13 @@ exports.WriteReviewFixesCommand = WriteReviewFixesCommand = tslib_1.__decorate([
|
|
|
53
53
|
review_round_state_1.ReviewRoundStateService])
|
|
54
54
|
], WriteReviewFixesCommand);
|
|
55
55
|
let WriteReviewFixesInput = class WriteReviewFixesInput {
|
|
56
|
-
read(filePath) {
|
|
56
|
+
read(filePath, stdin) {
|
|
57
57
|
if (filePath.trim() !== '') {
|
|
58
58
|
if (!fs.existsSync(filePath))
|
|
59
59
|
throw new rules_config_1.InformAiError(`wp-write-review-fixes: --file ${filePath} does not exist.`);
|
|
60
60
|
return fs.readFileSync(filePath, 'utf8');
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
throw new rules_config_1.InformAiError('wp-write-review-fixes: pass JSON on stdin or with --file <path>.');
|
|
64
|
-
}
|
|
65
|
-
return fs.readFileSync(0, 'utf8');
|
|
62
|
+
return stdin.read();
|
|
66
63
|
}
|
|
67
64
|
};
|
|
68
65
|
exports.WriteReviewFixesInput = WriteReviewFixesInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-review-fixes-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/write-review-fixes-command.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,0DAAyF;AACzF,yCAA2D;AAC3D,2EAAgE;AAChE,uEAAyE;AACzE,2EAA6E;
|
|
1
|
+
{"version":3,"file":"write-review-fixes-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/write-review-fixes-command.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,0DAAyF;AACzF,yCAA2D;AAC3D,2EAAgE;AAChE,uEAAyE;AACzE,2EAA6E;AAG7E,MAAa,uBAAuB;IAChC,IAAI,CAAS;IACb,GAAG,CAAS;IAEZ,YAAY,IAAY,EAAE,GAAW;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;CACJ;AARD,0DAQC;AAED;;;;GAIG;AAEI,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAEX;IACA;IACA;IACA;IAJrB,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,QAAmC,EACnC,MAA+B;QAH/B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAA2B;QACnC,WAAM,GAAN,MAAM,CAAyB;IACjD,CAAC;IAEJ,GAAG,CAAC,IAA6B;QAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/D,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,CAAC;QACvD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC1D,IAAI,OAAO,KAAK,IAAI;YAAE,MAAM,IAAI,4BAAa,CAAC,sEAAsE,CAAC,CAAC;QACtH,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAA,8BAAe,EAAC,QAAQ,EAAE,WAAW,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACnH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,OAAO,IAAI,CAAC,CAAC;QAClE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACJ,CAAA;AAjBY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QAChB,gDAAyB;QAC3B,4CAAuB;GAL3C,uBAAuB,CAiBnC;AAGM,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAC9B,IAAI,CAAC,QAAgB,EAAE,KAAqB;QACxC,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACzB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;gBAAE,MAAM,IAAI,4BAAa,CAAC,iCAAiC,QAAQ,kBAAkB,CAAC,CAAC;YACnH,OAAO,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;CACJ,CAAA;AARY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,qBAAqB,CAQjC","sourcesContent":["import * as fs from 'fs';\nimport { RepoRootFinder, InformAiError, summaryJsonPath } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { ReviewRoundStateService } from '../workflow/review-round-state';\nimport { ReviewStageReceiptService } from '../workflow/review-stage-receipt';\nimport type { PrGateCliStdin } from '../pr-gate-cli-invocation';\n\nexport class WriteReviewFixesOptions {\n json: string;\n cwd: string;\n\n constructor(json: string, cwd: string) {\n this.json = json;\n this.cwd = cwd;\n }\n}\n\n/**\n * Coordinator-owned writer for the SHA-bound response to a completed reviewer round: one fix per RED (a round\n * that is not the last, re-reviewed next round) or per ORANGE (the final round, never re-reviewed — finish\n * stamps each on the dashboard with its resolution). Written as `review-round<N>-fixes.json`, once.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class WriteReviewFixesCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly receipts: ReviewStageReceiptService,\n private readonly rounds: ReviewRoundStateService,\n ) {}\n\n run(opts: WriteReviewFixesOptions): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(opts.cwd);\n const featureName = this.aiBranchName.getFeatureName();\n const receipt = this.receipts.read(repoRoot, featureName);\n if (receipt === null) throw new InformAiError('wp-write-review-fixes: no reviewer round has started on this branch.');\n const written = this.rounds.writeRemediation(repoRoot, summaryJsonPath(repoRoot, featureName), receipt, opts.json);\n process.stdout.write(`✅ SHA-bound fixes recorded → ${written}\\n`);\n return Promise.resolve();\n }\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class WriteReviewFixesInput {\n read(filePath: string, stdin: PrGateCliStdin): string {\n if (filePath.trim() !== '') {\n if (!fs.existsSync(filePath)) throw new InformAiError(`wp-write-review-fixes: --file ${filePath} does not exist.`);\n return fs.readFileSync(filePath, 'utf8');\n }\n return stdin.read();\n }\n}\n"]}
|
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
require("reflect-metadata");
|
|
5
|
-
const inversify_1 = require("inversify");
|
|
6
5
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
container.get(
|
|
14
|
-
await container.get(pr_gate_app_1.PrGateApp).finishUpsertPr();
|
|
15
|
-
});
|
|
6
|
+
const inversify_1 = require("inversify");
|
|
7
|
+
const pr_gate_cli_app_1 = require("./pr-gate-cli-app");
|
|
8
|
+
const pr_gate_cli_invocation_1 = require("./pr-gate-cli-invocation");
|
|
9
|
+
const container = new inversify_1.Container({ autobind: true });
|
|
10
|
+
(0, rules_config_1.runMain)(() => container
|
|
11
|
+
.get(pr_gate_cli_app_1.PrGateCliApp)
|
|
12
|
+
.run(container.get(pr_gate_cli_invocation_1.PrGateCliInvocationFactory).fromProcess('wp-finish-upsert-pr')));
|
|
16
13
|
//# sourceMappingURL=git-finishUpsertPr.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-finishUpsertPr.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-finishUpsertPr.ts"],"names":[],"mappings":";;;AACA,4BAA0B;AAC1B,yCAAsC;AACtC,
|
|
1
|
+
{"version":3,"file":"git-finishUpsertPr.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-finishUpsertPr.ts"],"names":[],"mappings":";;;AACA,4BAA0B;AAC1B,0DAAkD;AAClD,yCAAsC;AACtC,uDAAiD;AACjD,qEAAsE;AAEtE,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AACpD,IAAA,sBAAO,EACH,GAAkB,EAAE,CAChB,SAAS;KACJ,GAAG,CAAC,8BAAY,CAAC;KACjB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,mDAA0B,CAAC,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC,CAC7F,CAAC","sourcesContent":["#!/usr/bin/env node\nimport 'reflect-metadata';\nimport { runMain } from '@webpieces/rules-config';\nimport { Container } from 'inversify';\nimport { PrGateCliApp } from './pr-gate-cli-app';\nimport { PrGateCliInvocationFactory } from './pr-gate-cli-invocation';\n\nconst container = new Container({ autobind: true });\nrunMain(\n (): Promise<void> =>\n container\n .get(PrGateCliApp)\n .run(container.get(PrGateCliInvocationFactory).fromProcess('wp-finish-upsert-pr')),\n);\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CleanupUsage } from './commands/cleanup-options';
|
|
2
|
+
import { WriteReviewInput } from './commands/write-review-command';
|
|
3
|
+
import { WriteReviewFixesInput } from './commands/write-review-fixes-command';
|
|
4
|
+
import { PrGateApp } from './pr-gate-app';
|
|
5
|
+
import { PrGateCliInvocation } from './pr-gate-cli-invocation';
|
|
6
|
+
/** Stable application boundary for every published `wp-*` command. */
|
|
7
|
+
export declare class PrGateCliApp {
|
|
8
|
+
private readonly app;
|
|
9
|
+
private readonly cleanupUsage;
|
|
10
|
+
private readonly writeReviewInput;
|
|
11
|
+
private readonly writeReviewFixesInput;
|
|
12
|
+
constructor(app: PrGateApp, cleanupUsage: CleanupUsage, writeReviewInput: WriteReviewInput, writeReviewFixesInput: WriteReviewFixesInput);
|
|
13
|
+
run(invocation: PrGateCliInvocation): Promise<void>;
|
|
14
|
+
private dispatch;
|
|
15
|
+
private dispatchUpdateCommand;
|
|
16
|
+
private dispatchPrCommand;
|
|
17
|
+
private dispatchRepoCommand;
|
|
18
|
+
private dispatchReviewCommand;
|
|
19
|
+
private parse;
|
|
20
|
+
private noArgs;
|
|
21
|
+
private buildUsage;
|
|
22
|
+
private finishUpsertUsage;
|
|
23
|
+
private humanPostUsage;
|
|
24
|
+
private hotfixUsage;
|
|
25
|
+
private startUpsertUsage;
|
|
26
|
+
private startUpdateUsage;
|
|
27
|
+
private finishUpdateUsage;
|
|
28
|
+
private syncMainUsage;
|
|
29
|
+
private checkPrUsage;
|
|
30
|
+
private reviewUpsertUsage;
|
|
31
|
+
private awaitReviewsUsage;
|
|
32
|
+
private landUsage;
|
|
33
|
+
private pushDevUsage;
|
|
34
|
+
private finishPushDevUsage;
|
|
35
|
+
private awaitChecksUsage;
|
|
36
|
+
private writeReviewUsage;
|
|
37
|
+
private writeReviewFixesUsage;
|
|
38
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrGateCliApp = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path = tslib_1.__importStar(require("path"));
|
|
6
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
7
|
+
const inversify_1 = require("inversify");
|
|
8
|
+
const await_checks_command_1 = require("./commands/await-checks-command");
|
|
9
|
+
const build_command_1 = require("./commands/build-command");
|
|
10
|
+
const cleanup_options_1 = require("./commands/cleanup-options");
|
|
11
|
+
const finish_push_dev_command_1 = require("./commands/finish-push-dev-command");
|
|
12
|
+
const land_pr_command_1 = require("./commands/land-pr-command");
|
|
13
|
+
const push_dev_command_1 = require("./commands/push-dev-command");
|
|
14
|
+
const write_review_command_1 = require("./commands/write-review-command");
|
|
15
|
+
const write_review_fixes_command_1 = require("./commands/write-review-fixes-command");
|
|
16
|
+
const pr_gate_app_1 = require("./pr-gate-app");
|
|
17
|
+
const ABORT = '--abort';
|
|
18
|
+
const CHECK = '--check';
|
|
19
|
+
const CHECKLIST = '--checklist';
|
|
20
|
+
const FILE = '--file';
|
|
21
|
+
const FORCE = '--force';
|
|
22
|
+
const LIST = '--list';
|
|
23
|
+
const PR = '--pr';
|
|
24
|
+
const REBASE_RESOLUTION = '--rebase-resolution';
|
|
25
|
+
const REMOVE = '--remove';
|
|
26
|
+
const RESOLVE = '--resolve';
|
|
27
|
+
/** Stable application boundary for every published `wp-*` command. */
|
|
28
|
+
let PrGateCliApp = class PrGateCliApp {
|
|
29
|
+
app;
|
|
30
|
+
cleanupUsage;
|
|
31
|
+
writeReviewInput;
|
|
32
|
+
writeReviewFixesInput;
|
|
33
|
+
constructor(app, cleanupUsage, writeReviewInput, writeReviewFixesInput) {
|
|
34
|
+
this.app = app;
|
|
35
|
+
this.cleanupUsage = cleanupUsage;
|
|
36
|
+
this.writeReviewInput = writeReviewInput;
|
|
37
|
+
this.writeReviewFixesInput = writeReviewFixesInput;
|
|
38
|
+
}
|
|
39
|
+
async run(invocation) {
|
|
40
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
41
|
+
try {
|
|
42
|
+
await this.dispatch(path.basename(invocation.binName), invocation);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
const error = (0, rules_config_1.toError)(err);
|
|
46
|
+
if (err instanceof rules_config_1.CliExitError) {
|
|
47
|
+
if (err.message !== '') {
|
|
48
|
+
(err.exitCode === 0 ? invocation.stdout : invocation.stderr).write(err.message + '\n');
|
|
49
|
+
}
|
|
50
|
+
invocation.processExit.exit(err.exitCode);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const message = err instanceof rules_config_1.RuleFailError ? (0, rules_config_1.renderRuleFailForHuman)(err) : error.message;
|
|
54
|
+
invocation.stderr.write(message + '\n');
|
|
55
|
+
invocation.processExit.exit(1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async dispatch(binName, invocation) {
|
|
59
|
+
if (await this.dispatchUpdateCommand(binName, invocation))
|
|
60
|
+
return;
|
|
61
|
+
if (await this.dispatchPrCommand(binName, invocation))
|
|
62
|
+
return;
|
|
63
|
+
if (await this.dispatchRepoCommand(binName, invocation))
|
|
64
|
+
return;
|
|
65
|
+
if (await this.dispatchReviewCommand(binName, invocation))
|
|
66
|
+
return;
|
|
67
|
+
throw new rules_config_1.CliExitError(2, `Unknown PR-gate command: ${binName}`);
|
|
68
|
+
}
|
|
69
|
+
async dispatchUpdateCommand(binName, invocation) {
|
|
70
|
+
if (binName === 'wp-finish-upsert-pr') {
|
|
71
|
+
await this.noArgs(invocation, this.finishUpsertUsage(), () => this.app.finishUpsertPr());
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
if (binName === 'wp-start-upsert-pr') {
|
|
75
|
+
await this.noArgs(invocation, this.startUpsertUsage(), () => this.app.startUpsertPr());
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
if (binName === 'wp-start-update') {
|
|
79
|
+
await this.noArgs(invocation, this.startUpdateUsage(), () => this.app.startUpdate());
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
if (binName === 'wp-finish-update') {
|
|
83
|
+
await this.noArgs(invocation, this.finishUpdateUsage(), () => this.app.finishUpdate());
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (binName === 'wp-sync-main') {
|
|
87
|
+
await this.noArgs(invocation, this.syncMainUsage(), () => this.app.syncMain());
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
async dispatchPrCommand(binName, invocation) {
|
|
93
|
+
if (binName === 'wp-human-post-pr') {
|
|
94
|
+
await this.noArgs(invocation, this.humanPostUsage(), () => this.app.humanPostPr());
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if (binName === 'wp-upsert-hotfix-pr') {
|
|
98
|
+
await this.noArgs(invocation, this.hotfixUsage(), () => this.app.upsertHotfixPr());
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
if (binName === 'wp-check-pr') {
|
|
102
|
+
await this.noArgs(invocation, this.checkPrUsage(), () => this.app.checkPr());
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (binName === 'wp-review-upsert-pr') {
|
|
106
|
+
await this.noArgs(invocation, this.reviewUpsertUsage(), () => this.app.reviewUpsertPr());
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
if (binName === 'wp-await-reviews') {
|
|
110
|
+
await this.noArgs(invocation, this.awaitReviewsUsage(), () => this.app.awaitReviews());
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
async dispatchRepoCommand(binName, invocation) {
|
|
116
|
+
if (binName === 'wp-build') {
|
|
117
|
+
const args = this.parse(invocation, this.buildUsage());
|
|
118
|
+
await this.app.build(new build_command_1.BuildOptions(args.has(FORCE)));
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
if (binName === 'wp-cleanup') {
|
|
122
|
+
const args = this.parse(invocation, this.cleanupUsage.declare());
|
|
123
|
+
await this.app.cleanup(new cleanup_options_1.CleanupOptions(new cleanup_options_1.DeleteSelection(cleanup_options_1.FLAG_DELETE_BRANCHES, args.has(cleanup_options_1.FLAG_DELETE_BRANCHES), args.value(cleanup_options_1.FLAG_DELETE_BRANCHES)), new cleanup_options_1.DeleteSelection(cleanup_options_1.FLAG_DELETE_WORKTREES, args.has(cleanup_options_1.FLAG_DELETE_WORKTREES), args.value(cleanup_options_1.FLAG_DELETE_WORKTREES)), args.has(cleanup_options_1.FLAG_REPORT), args.has(cleanup_options_1.FLAG_INTERACTIVE), args.has(cleanup_options_1.FLAG_IGNORE_STALE_LOCKS)));
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
if (binName === 'wp-land-pr') {
|
|
127
|
+
const args = this.parse(invocation, this.landUsage());
|
|
128
|
+
await this.app.landPr(new land_pr_command_1.LandPrRequest(args.has(PR), args.value(PR)));
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
if (binName === 'wp-push-dev') {
|
|
132
|
+
const args = this.parse(invocation, this.pushDevUsage());
|
|
133
|
+
const opts = new push_dev_command_1.PushDevOptions();
|
|
134
|
+
opts.list = args.has(LIST);
|
|
135
|
+
opts.remove = args.has(REMOVE);
|
|
136
|
+
opts.force = args.has(FORCE);
|
|
137
|
+
opts.rebaseResolution = args.has(REBASE_RESOLUTION);
|
|
138
|
+
opts.resolve = args.has(RESOLVE);
|
|
139
|
+
opts.resolveTarget = args.value(RESOLVE);
|
|
140
|
+
await this.app.pushDev(opts);
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
if (binName === 'wp-finish-push-dev') {
|
|
144
|
+
const args = this.parse(invocation, this.finishPushDevUsage());
|
|
145
|
+
await this.app.finishPushDev(new finish_push_dev_command_1.FinishPushDevOptions(args.has(ABORT)));
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
if (binName === 'wp-await-checks') {
|
|
149
|
+
const args = this.parse(invocation, this.awaitChecksUsage());
|
|
150
|
+
await this.app.awaitChecks(new await_checks_command_1.AwaitChecksArgs().parse(args.value(PR)));
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
async dispatchReviewCommand(binName, invocation) {
|
|
156
|
+
if (binName === 'wp-write-review') {
|
|
157
|
+
const args = this.parse(invocation, this.writeReviewUsage());
|
|
158
|
+
if (args.has(CHECK)) {
|
|
159
|
+
await this.app.checkReviewBudget(new write_review_command_1.ReviewBudgetCheckOptions(args.value(CHECKLIST), invocation.cwd));
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
const json = this.writeReviewInput.read(args.value(FILE), invocation.stdin);
|
|
163
|
+
await this.app.writeReview(new write_review_command_1.WriteReviewOptions(args.value(CHECKLIST), json, invocation.cwd));
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
if (binName === 'wp-write-review-fixes') {
|
|
167
|
+
const args = this.parse(invocation, this.writeReviewFixesUsage());
|
|
168
|
+
const json = this.writeReviewFixesInput.read(args.value(FILE), invocation.stdin);
|
|
169
|
+
await this.app.writeReviewFixes(new write_review_fixes_command_1.WriteReviewFixesOptions(json, invocation.cwd));
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
parse(invocation, usage) {
|
|
175
|
+
return new rules_config_1.CliArgs().parseArgs(invocation.argv, usage);
|
|
176
|
+
}
|
|
177
|
+
async noArgs(invocation, usage, action) {
|
|
178
|
+
this.parse(invocation, usage);
|
|
179
|
+
await action();
|
|
180
|
+
}
|
|
181
|
+
buildUsage() {
|
|
182
|
+
return new rules_config_1.CliUsage('wp-build', 'Run this repo`s configured build (commands.pr-gate.buildCommand) — the same command the PR gate runs.', [
|
|
183
|
+
new rules_config_1.CliFlag(FORCE, 'Build even though this machine is already at its concurrent-build limit.'),
|
|
184
|
+
]);
|
|
185
|
+
}
|
|
186
|
+
finishUpsertUsage() {
|
|
187
|
+
return new rules_config_1.CliUsage('wp-finish-upsert-pr', 'Finalize the merge, run the authoritative build gate, render the dashboard, and create/update the PR.');
|
|
188
|
+
}
|
|
189
|
+
humanPostUsage() {
|
|
190
|
+
return new rules_config_1.CliUsage('wp-human-post-pr', 'Interactively attest that a human is posting the current clean, current-main feature branch.');
|
|
191
|
+
}
|
|
192
|
+
hotfixUsage() {
|
|
193
|
+
return new rules_config_1.CliUsage('wp-upsert-hotfix-pr', 'Publish the current /hotfix/ branch through the hotfix gate.');
|
|
194
|
+
}
|
|
195
|
+
startUpsertUsage() {
|
|
196
|
+
return new rules_config_1.CliUsage('wp-start-upsert-pr', 'Update from main and hand off the PR review stage.');
|
|
197
|
+
}
|
|
198
|
+
startUpdateUsage() {
|
|
199
|
+
return new rules_config_1.CliUsage('wp-start-update', '3-point squash-update this feature branch from main (no PR).');
|
|
200
|
+
}
|
|
201
|
+
finishUpdateUsage() {
|
|
202
|
+
return new rules_config_1.CliUsage('wp-finish-update', 'Validate + finalize a resolved 3-point merge (no PR).');
|
|
203
|
+
}
|
|
204
|
+
syncMainUsage() {
|
|
205
|
+
return new rules_config_1.CliUsage('wp-sync-main', 'Go to main, fast-forward it, reap dead worktrees and branches, and sweep orphan directories.');
|
|
206
|
+
}
|
|
207
|
+
checkPrUsage() {
|
|
208
|
+
return new rules_config_1.CliUsage('wp-check-pr', 'CI check: verify this PR was created through the webpieces gated flow (valid gate token).');
|
|
209
|
+
}
|
|
210
|
+
reviewUpsertUsage() {
|
|
211
|
+
return new rules_config_1.CliUsage('wp-review-upsert-pr', 'Validate the merge, build, extract the diff, and brief required reviewers.');
|
|
212
|
+
}
|
|
213
|
+
awaitReviewsUsage() {
|
|
214
|
+
return new rules_config_1.CliUsage('wp-await-reviews', 'Block until every reviewer verdict has landed.');
|
|
215
|
+
}
|
|
216
|
+
landUsage() {
|
|
217
|
+
return new rules_config_1.CliUsage('wp-land-pr', 'Squash-merge a PR into main with its description as the commit body.', [new rules_config_1.CliFlag(PR, 'The PR number to land.', true)]);
|
|
218
|
+
}
|
|
219
|
+
pushDevUsage() {
|
|
220
|
+
return new rules_config_1.CliUsage('wp-push-dev', 'Publish a disposable copy of this branch for shared dev.', [
|
|
221
|
+
new rules_config_1.CliFlag(LIST, 'List published dev copies.'),
|
|
222
|
+
new rules_config_1.CliFlag(REMOVE, "Delete this branch's dev copy."),
|
|
223
|
+
new rules_config_1.CliFlag(RESOLVE, 'Compose other published copies, optionally one named branch.', true),
|
|
224
|
+
new rules_config_1.CliFlag(REBASE_RESOLUTION, 'Replay an existing resolution onto new commits.'),
|
|
225
|
+
new rules_config_1.CliFlag(FORCE, 'Discard the published resolution and overwrite it.'),
|
|
226
|
+
]);
|
|
227
|
+
}
|
|
228
|
+
finishPushDevUsage() {
|
|
229
|
+
return new rules_config_1.CliUsage('wp-finish-push-dev', 'Commit a resolved dev composition and publish it.', [new rules_config_1.CliFlag(ABORT, 'Throw the resolve away without publishing.')]);
|
|
230
|
+
}
|
|
231
|
+
awaitChecksUsage() {
|
|
232
|
+
return new rules_config_1.CliUsage('wp-await-checks', 'Block until checks on one PR stop running.', [
|
|
233
|
+
new rules_config_1.CliFlag(PR, 'REQUIRED. The PR number to wait on.', true),
|
|
234
|
+
]);
|
|
235
|
+
}
|
|
236
|
+
writeReviewUsage() {
|
|
237
|
+
return new rules_config_1.CliUsage('wp-write-review', 'Submit one reviewer verdict for one checklist.', [
|
|
238
|
+
new rules_config_1.CliFlag(CHECKLIST, 'REQUIRED. The checklist id.', true),
|
|
239
|
+
new rules_config_1.CliFlag(FILE, 'The verdict JSON file. Omit to read stdin.', true),
|
|
240
|
+
new rules_config_1.CliFlag(CHECK, 'Only check whether this checklist may still be reviewed.'),
|
|
241
|
+
]);
|
|
242
|
+
}
|
|
243
|
+
writeReviewFixesUsage() {
|
|
244
|
+
return new rules_config_1.CliUsage('wp-write-review-fixes', 'Record the coordinator response to red findings.', [new rules_config_1.CliFlag(FILE, 'JSON file. Omit to read stdin.', true)]);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
exports.PrGateCliApp = PrGateCliApp;
|
|
248
|
+
exports.PrGateCliApp = PrGateCliApp = tslib_1.__decorate([
|
|
249
|
+
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
250
|
+
tslib_1.__metadata("design:paramtypes", [pr_gate_app_1.PrGateApp,
|
|
251
|
+
cleanup_options_1.CleanupUsage,
|
|
252
|
+
write_review_command_1.WriteReviewInput,
|
|
253
|
+
write_review_fixes_command_1.WriteReviewFixesInput])
|
|
254
|
+
], PrGateCliApp);
|
|
255
|
+
//# sourceMappingURL=pr-gate-cli-app.js.map
|