@webpieces/pr-gate 0.4.820 → 0.4.822

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.
@@ -10,6 +10,7 @@ const diff_basis_1 = require("../workflow/diff-basis");
10
10
  const git_exec_1 = require("../workflow/git-exec");
11
11
  const pr_context_writer_1 = require("../workflow/pr-context-writer");
12
12
  const run_update_1 = require("../workflow/run-update");
13
+ const hotfix_instructions_1 = require("../workflow/hotfix-instructions");
13
14
  const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
14
15
  // STAGE ① of the AI-first PR flow: the deterministic setup — update from main / drive the 3-point merge —
15
16
  // then hand the AI ONE next command, `wp-review-upsert-pr`.
@@ -30,7 +31,9 @@ let StartUpsertPrCommand = class StartUpsertPrCommand {
30
31
  runUpdate;
31
32
  diffBasisResolver;
32
33
  prContextWriter;
33
- constructor(repoRootFinder, aiBranchName, branchNaming, gitExec, runUpdate, diffBasisResolver, prContextWriter) {
34
+ branchIdentity;
35
+ hotfixInstructions;
36
+ constructor(repoRootFinder, aiBranchName, branchNaming, gitExec, runUpdate, diffBasisResolver, prContextWriter, branchIdentity, hotfixInstructions) {
34
37
  this.repoRootFinder = repoRootFinder;
35
38
  this.aiBranchName = aiBranchName;
36
39
  this.branchNaming = branchNaming;
@@ -38,6 +41,8 @@ let StartUpsertPrCommand = class StartUpsertPrCommand {
38
41
  this.runUpdate = runUpdate;
39
42
  this.diffBasisResolver = diffBasisResolver;
40
43
  this.prContextWriter = prContextWriter;
44
+ this.branchIdentity = branchIdentity;
45
+ this.hotfixInstructions = hotfixInstructions;
41
46
  }
42
47
  async run() {
43
48
  const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
@@ -54,10 +59,19 @@ let StartUpsertPrCommand = class StartUpsertPrCommand {
54
59
  // Nothing here pushes. This command reviews; wp-finish-upsert-pr pushes ONCE, after summary.json,
55
60
  // every BLOCK checklist, and the authoritative build gate — so no unreviewed commit reaches the
56
61
  // remote, and there is no early `synchronize` firing against a PR body with a stale gate token.
57
- await this.updateBranchFromMain(repoRoot);
62
+ const hotfix = this.branchIdentity.isHotfix();
63
+ await this.updateBranchFromMain(repoRoot, hotfix);
58
64
  // No build gate here — a conflicted merge may still be unresolved, so there is nothing worth
59
65
  // building. Stage ② finalizes the merge FIRST, then builds; see the class comment.
60
- this.handOffToReview(repoRoot);
66
+ if (hotfix)
67
+ this.handOffHotfixToFinish(repoRoot);
68
+ else
69
+ this.handOffToReview(repoRoot);
70
+ }
71
+ handOffHotfixToFinish(repoRoot) {
72
+ const featureName = this.aiBranchName.getFeatureName();
73
+ const context = this.prContextWriter.ensure(repoRoot, featureName, this.diffBasisResolver.resolve(repoRoot), 'stage1-start');
74
+ process.stdout.write(this.hotfixInstructions.afterStart((0, rules_config_1.summaryJsonPath)(repoRoot, featureName), this.contextLines(context)));
61
75
  }
62
76
  /**
63
77
  * Hand the AI its ONE next step: `wp-review-upsert-pr`.
@@ -89,19 +103,19 @@ let StartUpsertPrCommand = class StartUpsertPrCommand {
89
103
  if (context.baseSha.trim() === '')
90
104
  return '';
91
105
  const cmd = context.fileDiffCommand.replace(' -- <file>', '');
92
- return (`${cmd === '' ? '' : `Your diff: ${cmd}\n`}` +
93
- `Full changed-file set + base/head sha: ${context.prContextPath}\n`);
106
+ return `${cmd === '' ? '' : `Your diff: ${cmd}\n`}` + `Full changed-file set + base/head sha: ${context.prContextPath}\n`;
94
107
  }
95
108
  // Bring the branch up to date with main via the shared 3-point engine (in-process). On conflict the
96
109
  // merge process doc it writes names `wp-review-upsert-pr` as the finish command — that is the command
97
110
  // that now validates and commits a conflict resolution, so it is what the doc must send the AI to.
98
- async updateBranchFromMain(repoRoot) {
111
+ async updateBranchFromMain(repoRoot, hotfix) {
99
112
  process.stdout.write('\n' + SEP + '① Updating branch from main\n' + SEP + '\n');
100
113
  // pushRemote=false — finish owns the single push (see MergeEndOptions).
101
- const outcome = await this.runUpdate.runUpdateFromMain(repoRoot, 'wp-start-upsert-pr', 'wp-review-upsert-pr', false);
114
+ const next = hotfix ? 'wp-finish-upsert-pr' : 'wp-review-upsert-pr';
115
+ const outcome = await this.runUpdate.runUpdateFromMain(repoRoot, 'wp-start-upsert-pr', next, false);
102
116
  if (outcome === 'conflict' || outcome === 'unvalidatedResume') {
103
- throw new rules_config_1.CliExitError(2, '\n⏸️ Conflicts — resolve them, then run pnpm wp-review-upsert-pr (it validates the merge, builds it,\n' +
104
- ' and only then briefs the reviewers).');
117
+ const command = hotfix ? 'pnpm wp-finish-upsert-pr' : 'pnpm wp-review-upsert-pr';
118
+ throw new rules_config_1.CliExitError(2, `\n⏸️ Conflicts — resolve them, then run ${command} ` + (hotfix ? '(it validates the merge, requires the summary, then runs compilation and tests).' : '(it validates the merge, builds it, and only then briefs the reviewers).'));
105
119
  }
106
120
  }
107
121
  };
@@ -114,6 +128,8 @@ exports.StartUpsertPrCommand = StartUpsertPrCommand = tslib_1.__decorate([
114
128
  git_exec_1.GitExec,
115
129
  run_update_1.RunUpdate,
116
130
  diff_basis_1.DiffBasisResolver,
117
- pr_context_writer_1.PrContextWriter])
131
+ pr_context_writer_1.PrContextWriter,
132
+ rules_config_1.BranchIdentity,
133
+ hotfix_instructions_1.HotfixInstructions])
118
134
  ], StartUpsertPrCommand);
119
135
  //# sourceMappingURL=start-upsert-pr-command.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"start-upsert-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/start-upsert-pr-command.ts"],"names":[],"mappings":";;;;AACA,0DAA8G;AAC9G,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,uDAA2D;AAC3D,mDAA+C;AAC/C,qEAAgE;AAChE,uDAAmD;AAEnD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,0GAA0G;AAC1G,4DAA4D;AAC5D,EAAE;AACF,4GAA4G;AAC5G,2GAA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AO,KAAK,UAAU,IAAI,OAAO,KAAK,mBAAmB,EAAE,CAAC;YAC5D,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,yGAAyG;gBACzG,yCAAyC,CAC5C,CAAC;QACN,CAAC;IACL,CAAC;CACJ,CAAA;AAxFY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QACZ,4BAAY;QACjB,kBAAO;QACL,sBAAS;QACD,8BAAiB;QACnB,mCAAe;GAR5C,oBAAoB,CAwFhC","sourcesContent":["import { execSync } from 'child_process';\nimport { writeTemplate, CliExitError, RepoRootFinder, ChecklistReviewContext } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { DiffBasisResolver } from '../workflow/diff-basis';\nimport { GitExec } from '../workflow/git-exec';\nimport { PrContextWriter } from '../workflow/pr-context-writer';\nimport { RunUpdate } from '../workflow/run-update';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// STAGE ① of the AI-first PR flow: the deterministic setup — update from main / drive the 3-point merge —\n// then hand the AI ONE next command, `wp-review-upsert-pr`.\n//\n// It runs NO build gate, and that is still deliberate, but the reason has changed. It is not that the build\n// belongs only at the end: it is that at THIS point a conflicted 3-point merge may still be unresolved, so\n// there is nothing worth building yet. The gate moved FORWARD, not away — stage ② finalizes the merge and\n// then builds, so reviewers never judge a branch that does not compile, and wp-finish-upsert-pr skips the\n// rebuild when HEAD has not moved since. `pr-gate.buildCommand` is therefore no longer a finish-only knob.\n//\n// This command NEVER creates/updates a PR and NEVER pushes: all `gh` posting and the ONE push live in\n// finish, behind summary.json + the checklists + the build gate.\n@injectable(bindingScopeValues.Singleton)\nexport class StartUpsertPrCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly gitExec: GitExec,\n private readonly runUpdate: RunUpdate,\n private readonly diffBasisResolver: DiffBasisResolver,\n private readonly prContextWriter: PrContextWriter,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n // Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n // NOTE: the server-side CI gate is NOT scaffolded here any more — `wp-install-ai-hooks` owns it.\n // This printed copy-to-.github + branch-protection instructions on EVERY run, at an agent doing\n // feature work that could not act on them: marking a check required needs a repo admin. Setup\n // belongs in the setup command; see templates/webpieces.ci-gate-setup.md.\n\n // Precondition: a fully-committed tree. This flow squash-updates the branch and builds it — the\n // tooling must not commit your work for you, and building a dirty working tree would let an\n // uncommitted change build green over a different commit than the one that ships. Fail if dirty.\n this.gitExec.assertCleanTree(repoRoot);\n\n // Nothing here pushes. This command reviews; wp-finish-upsert-pr pushes ONCE, after summary.json,\n // every BLOCK checklist, and the authoritative build gate — so no unreviewed commit reaches the\n // remote, and there is no early `synchronize` firing against a PR body with a stale gate token.\n await this.updateBranchFromMain(repoRoot);\n\n // No build gate here — a conflicted merge may still be unresolved, so there is nothing worth\n // building. Stage ② finalizes the merge FIRST, then builds; see the class comment.\n this.handOffToReview(repoRoot);\n }\n\n /**\n * Hand the AI its ONE next step: `wp-review-upsert-pr`.\n *\n * This prints exactly one command on purpose. It used to print three (run the checklist, write\n * summary.json, then finish), and a three-item list is a list with a step to skip. Stage ② now owns all\n * of it — it validates the 3-point merge, builds, materializes the diff, briefs the reviewers, AND\n * prints the summary.json schema — so there is nothing here to enumerate. Notably summary.json is NOT\n * requested here any more: asking for a written PR summary before the branch is known to compile invites\n * one that describes code that does not build.\n */\n private handOffToReview(repoRoot: string): void {\n // Persist the review-format + process instructions where any failure message can cite them.\n writeTemplate(repoRoot, 'webpieces.review-checklists.md');\n // Persist the PR diff context (base sha + the full changed-file set) so it exists even if the AI\n // stops here. Stage ② rewrites it with the materialized-diff dir once it has one.\n const context = this.prContextWriter.ensure(\n repoRoot, this.aiBranchName.getFeatureName(), this.diffBasisResolver.resolve(repoRoot), 'stage1-start');\n process.stdout.write('\\n' + SEP + '② Brief the reviewers and write the PR summary, then finish\\n' + SEP + '\\n');\n process.stdout.write(\n `Branch is updated (nothing pushed yet — finish does the one push, behind the build gate).\\n` +\n `${this.contextLines(context)}\\n` +\n `▶ NEXT run: pnpm wp-review-upsert-pr\\n` +\n ` It validates the 3-point merge, runs the build gate, extracts this branch's diff for the\\n` +\n ` reviewers, and prints what to spawn plus the summary.json schema. Everything else waits on it —\\n` +\n ` wp-finish-upsert-pr refuses to open a PR until it has run.\\n\\n`,\n );\n }\n\n // The diff facts, stated where the instruction to use them is — not in a separate block above it. The\n // command comes from the resolved basis; hand-writing `<base> HEAD` here is empty on a dirty tree.\n private contextLines(context: ChecklistReviewContext): string {\n if (context.baseSha.trim() === '') return '';\n const cmd = context.fileDiffCommand.replace(' -- <file>', '');\n return (\n `${cmd === '' ? '' : `Your diff: ${cmd}\\n`}` +\n `Full changed-file set + base/head sha: ${context.prContextPath}\\n`\n );\n }\n\n // Bring the branch up to date with main via the shared 3-point engine (in-process). On conflict the\n // merge process doc it writes names `wp-review-upsert-pr` as the finish command — that is the command\n // that now validates and commits a conflict resolution, so it is what the doc must send the AI to.\n private async updateBranchFromMain(repoRoot: string): Promise<void> {\n process.stdout.write('\\n' + SEP + '① Updating branch from main\\n' + SEP + '\\n');\n // pushRemote=false — finish owns the single push (see MergeEndOptions).\n const outcome = await this.runUpdate.runUpdateFromMain(repoRoot, 'wp-start-upsert-pr', 'wp-review-upsert-pr', false);\n if (outcome === 'conflict' || outcome === 'unvalidatedResume') {\n throw new CliExitError(2,\n '\\n⏸️ Conflicts — resolve them, then run pnpm wp-review-upsert-pr (it validates the merge, builds it,\\n' +\n ' and only then briefs the reviewers).',\n );\n }\n }\n}\n"]}
1
+ {"version":3,"file":"start-upsert-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/start-upsert-pr-command.ts"],"names":[],"mappings":";;;;AACA,0DAA+I;AAC/I,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,uDAA2D;AAC3D,mDAA+C;AAC/C,qEAAgE;AAChE,uDAAmD;AACnD,yEAAqE;AAErE,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,0GAA0G;AAC1G,4DAA4D;AAC5D,EAAE;AACF,4GAA4G;AAC5G,2GAA2G;AAC3G,0GAA0G;AAC1G,0GAA0G;AAC1G,2GAA2G;AAC3G,EAAE;AACF,sGAAsG;AACtG,iEAAiE;AAE1D,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAER;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IATrB,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,YAA0B,EAC1B,OAAgB,EAChB,SAAoB,EACpB,iBAAoC,EACpC,eAAgC,EAChC,cAA8B,EAC9B,kBAAsC;QARtC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,YAAO,GAAP,OAAO,CAAS;QAChB,cAAS,GAAT,SAAS,CAAW;QACpB,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,oBAAe,GAAf,eAAe,CAAiB;QAChC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,uBAAkB,GAAlB,kBAAkB,CAAoB;IACxD,CAAC;IAEJ,KAAK,CAAC,GAAG;QACL,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,gGAAgG;QAChG,IAAA,4BAAa,EAAC,QAAQ,EAAE,2BAA2B,CAAC,CAAC;QACrD,iGAAiG;QACjG,gGAAgG;Q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CAAC;YAC5D,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,0BAA0B,CAAC;YACjF,MAAM,IAAI,2BAAY,CAAC,CAAC,EAAE,4CAA4C,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,kFAAkF,CAAC,CAAC,CAAC,0EAA0E,CAAC,CAAC,CAAC;QACnQ,CAAC;IACL,CAAC;CACJ,CAAA;AA7FY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QACZ,4BAAY;QACjB,kBAAO;QACL,sBAAS;QACD,8BAAiB;QACnB,mCAAe;QAChB,6BAAc;QACV,wCAAkB;GAVlD,oBAAoB,CA6FhC","sourcesContent":["import { execSync } from 'child_process';\nimport { writeTemplate, CliExitError, RepoRootFinder, ChecklistReviewContext, BranchIdentity, summaryJsonPath } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { DiffBasisResolver } from '../workflow/diff-basis';\nimport { GitExec } from '../workflow/git-exec';\nimport { PrContextWriter } from '../workflow/pr-context-writer';\nimport { RunUpdate } from '../workflow/run-update';\nimport { HotfixInstructions } from '../workflow/hotfix-instructions';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// STAGE ① of the AI-first PR flow: the deterministic setup — update from main / drive the 3-point merge —\n// then hand the AI ONE next command, `wp-review-upsert-pr`.\n//\n// It runs NO build gate, and that is still deliberate, but the reason has changed. It is not that the build\n// belongs only at the end: it is that at THIS point a conflicted 3-point merge may still be unresolved, so\n// there is nothing worth building yet. The gate moved FORWARD, not away — stage ② finalizes the merge and\n// then builds, so reviewers never judge a branch that does not compile, and wp-finish-upsert-pr skips the\n// rebuild when HEAD has not moved since. `pr-gate.buildCommand` is therefore no longer a finish-only knob.\n//\n// This command NEVER creates/updates a PR and NEVER pushes: all `gh` posting and the ONE push live in\n// finish, behind summary.json + the checklists + the build gate.\n@injectable(bindingScopeValues.Singleton)\nexport class StartUpsertPrCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly gitExec: GitExec,\n private readonly runUpdate: RunUpdate,\n private readonly diffBasisResolver: DiffBasisResolver,\n private readonly prContextWriter: PrContextWriter,\n private readonly branchIdentity: BranchIdentity,\n private readonly hotfixInstructions: HotfixInstructions,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n // Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n // NOTE: the server-side CI gate is NOT scaffolded here any more — `wp-install-ai-hooks` owns it.\n // This printed copy-to-.github + branch-protection instructions on EVERY run, at an agent doing\n // feature work that could not act on them: marking a check required needs a repo admin. Setup\n // belongs in the setup command; see templates/webpieces.ci-gate-setup.md.\n\n // Precondition: a fully-committed tree. This flow squash-updates the branch and builds it — the\n // tooling must not commit your work for you, and building a dirty working tree would let an\n // uncommitted change build green over a different commit than the one that ships. Fail if dirty.\n this.gitExec.assertCleanTree(repoRoot);\n\n // Nothing here pushes. This command reviews; wp-finish-upsert-pr pushes ONCE, after summary.json,\n // every BLOCK checklist, and the authoritative build gate — so no unreviewed commit reaches the\n // remote, and there is no early `synchronize` firing against a PR body with a stale gate token.\n const hotfix = this.branchIdentity.isHotfix();\n await this.updateBranchFromMain(repoRoot, hotfix);\n\n // No build gate here — a conflicted merge may still be unresolved, so there is nothing worth\n // building. Stage ② finalizes the merge FIRST, then builds; see the class comment.\n if (hotfix) this.handOffHotfixToFinish(repoRoot);\n else this.handOffToReview(repoRoot);\n }\n\n private handOffHotfixToFinish(repoRoot: string): void {\n const featureName = this.aiBranchName.getFeatureName();\n const context = this.prContextWriter.ensure(repoRoot, featureName, this.diffBasisResolver.resolve(repoRoot), 'stage1-start');\n process.stdout.write(this.hotfixInstructions.afterStart(summaryJsonPath(repoRoot, featureName), this.contextLines(context)));\n }\n\n /**\n * Hand the AI its ONE next step: `wp-review-upsert-pr`.\n *\n * This prints exactly one command on purpose. It used to print three (run the checklist, write\n * summary.json, then finish), and a three-item list is a list with a step to skip. Stage ② now owns all\n * of it — it validates the 3-point merge, builds, materializes the diff, briefs the reviewers, AND\n * prints the summary.json schema — so there is nothing here to enumerate. Notably summary.json is NOT\n * requested here any more: asking for a written PR summary before the branch is known to compile invites\n * one that describes code that does not build.\n */\n private handOffToReview(repoRoot: string): void {\n // Persist the review-format + process instructions where any failure message can cite them.\n writeTemplate(repoRoot, 'webpieces.review-checklists.md');\n // Persist the PR diff context (base sha + the full changed-file set) so it exists even if the AI\n // stops here. Stage ② rewrites it with the materialized-diff dir once it has one.\n const context = this.prContextWriter.ensure(repoRoot, this.aiBranchName.getFeatureName(), this.diffBasisResolver.resolve(repoRoot), 'stage1-start');\n process.stdout.write('\\n' + SEP + '② Brief the reviewers and write the PR summary, then finish\\n' + SEP + '\\n');\n process.stdout.write(\n `Branch is updated (nothing pushed yet — finish does the one push, behind the build gate).\\n` +\n `${this.contextLines(context)}\\n` +\n `▶ NEXT run: pnpm wp-review-upsert-pr\\n` +\n ` It validates the 3-point merge, runs the build gate, extracts this branch's diff for the\\n` +\n ` reviewers, and prints what to spawn plus the summary.json schema. Everything else waits on it —\\n` +\n ` wp-finish-upsert-pr refuses to open a PR until it has run.\\n\\n`,\n );\n }\n\n // The diff facts, stated where the instruction to use them is — not in a separate block above it. The\n // command comes from the resolved basis; hand-writing `<base> HEAD` here is empty on a dirty tree.\n private contextLines(context: ChecklistReviewContext): string {\n if (context.baseSha.trim() === '') return '';\n const cmd = context.fileDiffCommand.replace(' -- <file>', '');\n return `${cmd === '' ? '' : `Your diff: ${cmd}\\n`}` + `Full changed-file set + base/head sha: ${context.prContextPath}\\n`;\n }\n\n // Bring the branch up to date with main via the shared 3-point engine (in-process). On conflict the\n // merge process doc it writes names `wp-review-upsert-pr` as the finish command — that is the command\n // that now validates and commits a conflict resolution, so it is what the doc must send the AI to.\n private async updateBranchFromMain(repoRoot: string, hotfix: boolean): Promise<void> {\n process.stdout.write('\\n' + SEP + '① Updating branch from main\\n' + SEP + '\\n');\n // pushRemote=false — finish owns the single push (see MergeEndOptions).\n const next = hotfix ? 'wp-finish-upsert-pr' : 'wp-review-upsert-pr';\n const outcome = await this.runUpdate.runUpdateFromMain(repoRoot, 'wp-start-upsert-pr', next, false);\n if (outcome === 'conflict' || outcome === 'unvalidatedResume') {\n const command = hotfix ? 'pnpm wp-finish-upsert-pr' : 'pnpm wp-review-upsert-pr';\n throw new CliExitError(2, `\\n⏸️ Conflicts — resolve them, then run ${command} ` + (hotfix ? '(it validates the merge, requires the summary, then runs compilation and tests).' : '(it validates the merge, builds it, and only then briefs the reviewers).'));\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { BuildsLog } from '@webpieces/rules-config';
1
+ import { BuildsLog, BranchIdentity } from '@webpieces/rules-config';
2
2
  import { BuildGateLog } from './build-gate-log';
3
3
  import { StageOutputLog } from './stage-output-log';
4
4
  /**
@@ -18,7 +18,8 @@ export declare class BuildAffected {
18
18
  private readonly buildLog;
19
19
  private readonly buildsLog;
20
20
  private readonly stageConsole;
21
- constructor(buildLog: BuildGateLog, buildsLog: BuildsLog, stageConsole: StageOutputLog);
21
+ private readonly branchIdentity;
22
+ constructor(buildLog: BuildGateLog, buildsLog: BuildsLog, stageConsole: StageOutputLog, branchIdentity: BranchIdentity);
22
23
  /**
23
24
  * Resolve the exact build command this gate will run: the project's configured
24
25
  * PrGateConfig.buildCommand, or the default affected-ci command when none is set.
@@ -37,16 +37,20 @@ let BuildAffected = class BuildAffected {
37
37
  buildLog;
38
38
  buildsLog;
39
39
  stageConsole;
40
- constructor(buildLog, buildsLog, stageConsole) {
40
+ branchIdentity;
41
+ constructor(buildLog, buildsLog, stageConsole, branchIdentity) {
41
42
  this.buildLog = buildLog;
42
43
  this.buildsLog = buildsLog;
43
44
  this.stageConsole = stageConsole;
45
+ this.branchIdentity = branchIdentity;
44
46
  }
45
47
  /**
46
48
  * Resolve the exact build command this gate will run: the project's configured
47
49
  * PrGateConfig.buildCommand, or the default affected-ci command when none is set.
48
50
  */
49
51
  resolveBuildCommand(repoRoot) {
52
+ if (this.branchIdentity.isHotfix())
53
+ return rules_config_1.HOTFIX_BUILD_COMMAND;
50
54
  const configured = (0, rules_config_1.loadAndValidate)(repoRoot).prGate.buildCommand;
51
55
  return configured !== undefined && configured.trim() !== '' ? configured : rules_config_1.DEFAULT_BUILD_COMMAND;
52
56
  }
@@ -102,9 +106,7 @@ let BuildAffected = class BuildAffected {
102
106
  * expensive thing an agent can be told. Reading a FILE is now the only answer this gate gives.
103
107
  */
104
108
  failureText(opts, buildCommand, logPath, termination) {
105
- return `\n❌ ${opts.failureHeadline}\n` +
106
- this.buildLog.failureMessage(buildCommand, logPath, termination) +
107
- `Fix what that log shows, then re-run ${opts.rerunCommand}.\n`;
109
+ return `\n❌ ${opts.failureHeadline}\n` + this.buildLog.failureMessage(buildCommand, logPath, termination) + `Fix what that log shows, then re-run ${opts.rerunCommand}.\n`;
108
110
  }
109
111
  };
110
112
  exports.BuildAffected = BuildAffected;
@@ -112,6 +114,7 @@ exports.BuildAffected = BuildAffected = tslib_1.__decorate([
112
114
  (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
113
115
  tslib_1.__metadata("design:paramtypes", [build_gate_log_1.BuildGateLog,
114
116
  rules_config_1.BuildsLog,
115
- stage_output_log_1.StageOutputLog])
117
+ stage_output_log_1.StageOutputLog,
118
+ rules_config_1.BranchIdentity])
116
119
  ], BuildAffected);
117
120
  //# sourceMappingURL=build-affected.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-affected.js","sourceRoot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c,CAAC,OAAO,CAAC,CAAC,CAAC;IACjE,CAAC;IAED;;;;;;;OAOG;IACK,WAAW,CACf,IAAsB,EAAE,YAAoB,EAAE,OAAe,EAAE,WAA6B;QAE5F,OAAO,OAAO,IAAI,CAAC,eAAe,IAAI;YAClC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EAAE,OAAO,EAAE,WAAW,CAAC;YAChE,wCAAwC,IAAI,CAAC,YAAY,KAAK,CAAC;IACvE,CAAC;CACJ,CAAA;AA1EY,sCAAa;wBAAb,aAAa;IADzB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGN,6BAAY;QACX,wBAAS;QACN,iCAAc;GAJxC,aAAa,CA0EzB","sourcesContent":["import {\n loadAndValidate, CliExitError, DEFAULT_BUILD_COMMAND, BuildsLog, BuildTermination,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { BuildGateLog } from './build-gate-log';\nimport { StageOutputLog } from './stage-output-log';\n\n// Single source of truth for RUNNING the build gate. `wp-start-upsert-pr` runs NO build; stage ②\n// (`wp-review-upsert-pr`) runs it authoritatively before any reviewer is spawned, and stage ③\n// (`wp-finish-upsert-pr`) re-runs it only when HEAD has moved since. nx `affected` only rebuilds\n// changed projects. The fallback command itself lives in @webpieces/rules-config as\n// DEFAULT_BUILD_COMMAND — whole-repo-build-guard prints the same string, and one definition is what\n// keeps the refusal message naming the build that actually runs.\n\n\n/**\n * The caller-supplied framing for the build gate (label, re-run command, failure headline, stage id). Kept\n * as a parameter object so runBuildGate stays agnostic of who invokes it. A class (not an object literal)\n * per the codebase's data-structure convention.\n */\nexport class BuildGateOptions {\n label: string; // section header shown above the gate\n rerunCommand: string; // command the AI re-runs after fixing the build\n failureHeadline: string; // first line printed on failure\n // WHICH stage's gate this is — REVIEW_STAGE, FINISH_STAGE or BUILD_STAGE. Required, with no default:\n // it decides the captured log's filename, and a default would silently make two stages share one file.\n stage: string;\n\n constructor(label: string, rerunCommand: string, failureHeadline: string, stage: string) {\n this.label = label;\n this.rerunCommand = rerunCommand;\n this.failureHeadline = failureHeadline;\n this.stage = stage;\n }\n}\n\n/** Runs the authoritative nx-affected build gate for wp-review-upsert-pr and wp-finish-upsert-pr. */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildAffected {\n constructor(\n private readonly buildLog: BuildGateLog,\n private readonly buildsLog: BuildsLog,\n private readonly stageConsole: StageOutputLog,\n ) {}\n\n /**\n * Resolve the exact build command this gate will run: the project's configured\n * PrGateConfig.buildCommand, or the default affected-ci command when none is set.\n */\n resolveBuildCommand(repoRoot: string): string {\n const configured = loadAndValidate(repoRoot).prGate.buildCommand;\n return configured !== undefined && configured.trim() !== '' ? configured : DEFAULT_BUILD_COMMAND;\n }\n\n /**\n * Run the configured build gate with consistent framing, throwing CliExitError(buildCode) on\n * failure so the bin's main()/runMain owns the exit. THE single source of truth for running a build:\n * wp-build, wp-review-upsert-pr and wp-finish-upsert-pr all call THIS (only the BuildGateOptions\n * differ), and there is no other way to reach the spawn.\n *\n * ─── EVERY BUILD ON THIS MACHINE IS LEDGERED FROM HERE ───────────────────────────────────────────\n * A START row goes into `~/.webpieces/builds.log` before the spawn and a DONE row after it, in a\n * `finally` so a throw on the failure path still closes the pair. `opts.stage` — `build` | `review` |\n * `finish` — IS the caller id the row records; there is deliberately no second `caller` field, since\n * two spellings of one fact is the shim `.claude/rules/no-backwards-compat.md` rejects.\n *\n * The ledger is best-effort by construction (see BuildsLog): it can never throw, so no build can die\n * because a log file was busy.\n */\n async runBuildGate(repoRoot: string, opts: BuildGateOptions): Promise<void> {\n const buildCommand = this.resolveBuildCommand(repoRoot);\n // TWO lines on the happy path — the command, then the result. The old framing spent a banner and a\n // paragraph explaining how to reproduce a build that was about to pass anyway; that explanation is\n // only useful when the build FAILS, so it now lives solely on the failure path below.\n //\n // `say`, so it survives a stage that is capturing its own console (see StageOutputLog): the\n // command being run and the result of running it are exactly what a caller watching a long build\n // needs to see live.\n this.stageConsole.say(`\\n${opts.label}: ${buildCommand}\\n`);\n const logPath = this.buildLog.pathFor(repoRoot, opts.stage);\n const ticket = this.buildsLog.start(opts.stage, repoRoot);\n let termination = new BuildTermination(1, null);\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the DONE row must be written whether the\n // build passed, failed, or the spawn itself blew up; the throw is re-raised untouched below\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n termination = await this.buildLog.run(repoRoot, buildCommand, logPath);\n } finally {\n this.buildsLog.finish(ticket, termination);\n }\n const buildCode = termination.code === null || termination.signal !== null ? 1 : termination.code;\n if (buildCode !== 0) {\n throw new CliExitError(buildCode, this.failureText(opts, buildCommand, logPath, termination));\n }\n this.stageConsole.say(this.buildLog.successMessage(logPath));\n }\n\n /**\n * The failure text: this gate's own headline, then the pointer at the log the build already wrote.\n *\n * There is no second, streamed variant any more. Capturing used to be behind an EXPERIMENTAL\n * machine-local opt-in, which meant the refusal an agent read depended on a file almost nobody had —\n * and the un-captured branch's advice was \"run the build again yourself\", which is the single most\n * expensive thing an agent can be told. Reading a FILE is now the only answer this gate gives.\n */\n private failureText(\n opts: BuildGateOptions, buildCommand: string, logPath: string, termination: BuildTermination,\n ): string {\n return `\\n❌ ${opts.failureHeadline}\\n` +\n this.buildLog.failureMessage(buildCommand, logPath, termination) +\n `Fix what that log shows, then re-run ${opts.rerunCommand}.\\n`;\n }\n}\n"]}
1
+ {"version":3,"file":"build-affected.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-affected.ts"],"names":[],"mappings":";;;;AAAA,0DAAkK;AAClK,yCAA2D;AAC3D,qDAAgD;AAChD,yDAAoD;AAEpD,iGAAiG;AACjG,8FAA8F;AAC9F,iGAAiG;AACjG,oFAAoF;AACpF,oGAAoG;AACpG,iEAAiE;AAEjE;;;;GAIG;AACH,MAAa,gBAAgB;IACzB,KAAK,CAAS,CAAC,sCAAsC;IACrD,YAAY,CAAS,CAAC,gDAAgD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AAC,cAAc,CAAC,YAAY,EAAE,OAAO,EAAE,WAAW,CAAC,GAAG,wCAAwC,IAAI,CAAC,YAAY,KAAK,CAAC;IAC/K,CAAC;CACJ,CAAA;AAxEY,sCAAa;wBAAb,aAAa;IADzB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGN,6BAAY;QACX,wBAAS;QACN,iCAAc;QACZ,6BAAc;GAL1C,aAAa,CAwEzB","sourcesContent":["import { loadAndValidate, CliExitError, DEFAULT_BUILD_COMMAND, BuildsLog, BuildTermination, BranchIdentity, HOTFIX_BUILD_COMMAND } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { BuildGateLog } from './build-gate-log';\nimport { StageOutputLog } from './stage-output-log';\n\n// Single source of truth for RUNNING the build gate. `wp-start-upsert-pr` runs NO build; stage ②\n// (`wp-review-upsert-pr`) runs it authoritatively before any reviewer is spawned, and stage ③\n// (`wp-finish-upsert-pr`) re-runs it only when HEAD has moved since. nx `affected` only rebuilds\n// changed projects. The fallback command itself lives in @webpieces/rules-config as\n// DEFAULT_BUILD_COMMAND — whole-repo-build-guard prints the same string, and one definition is what\n// keeps the refusal message naming the build that actually runs.\n\n/**\n * The caller-supplied framing for the build gate (label, re-run command, failure headline, stage id). Kept\n * as a parameter object so runBuildGate stays agnostic of who invokes it. A class (not an object literal)\n * per the codebase's data-structure convention.\n */\nexport class BuildGateOptions {\n label: string; // section header shown above the gate\n rerunCommand: string; // command the AI re-runs after fixing the build\n failureHeadline: string; // first line printed on failure\n // WHICH stage's gate this is — REVIEW_STAGE, FINISH_STAGE or BUILD_STAGE. Required, with no default:\n // it decides the captured log's filename, and a default would silently make two stages share one file.\n stage: string;\n\n constructor(label: string, rerunCommand: string, failureHeadline: string, stage: string) {\n this.label = label;\n this.rerunCommand = rerunCommand;\n this.failureHeadline = failureHeadline;\n this.stage = stage;\n }\n}\n\n/** Runs the authoritative nx-affected build gate for wp-review-upsert-pr and wp-finish-upsert-pr. */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildAffected {\n constructor(\n private readonly buildLog: BuildGateLog,\n private readonly buildsLog: BuildsLog,\n private readonly stageConsole: StageOutputLog,\n private readonly branchIdentity: BranchIdentity,\n ) {}\n\n /**\n * Resolve the exact build command this gate will run: the project's configured\n * PrGateConfig.buildCommand, or the default affected-ci command when none is set.\n */\n resolveBuildCommand(repoRoot: string): string {\n if (this.branchIdentity.isHotfix()) return HOTFIX_BUILD_COMMAND;\n const configured = loadAndValidate(repoRoot).prGate.buildCommand;\n return configured !== undefined && configured.trim() !== '' ? configured : DEFAULT_BUILD_COMMAND;\n }\n\n /**\n * Run the configured build gate with consistent framing, throwing CliExitError(buildCode) on\n * failure so the bin's main()/runMain owns the exit. THE single source of truth for running a build:\n * wp-build, wp-review-upsert-pr and wp-finish-upsert-pr all call THIS (only the BuildGateOptions\n * differ), and there is no other way to reach the spawn.\n *\n * ─── EVERY BUILD ON THIS MACHINE IS LEDGERED FROM HERE ───────────────────────────────────────────\n * A START row goes into `~/.webpieces/builds.log` before the spawn and a DONE row after it, in a\n * `finally` so a throw on the failure path still closes the pair. `opts.stage` — `build` | `review` |\n * `finish` — IS the caller id the row records; there is deliberately no second `caller` field, since\n * two spellings of one fact is the shim `.claude/rules/no-backwards-compat.md` rejects.\n *\n * The ledger is best-effort by construction (see BuildsLog): it can never throw, so no build can die\n * because a log file was busy.\n */\n async runBuildGate(repoRoot: string, opts: BuildGateOptions): Promise<void> {\n const buildCommand = this.resolveBuildCommand(repoRoot);\n // TWO lines on the happy path — the command, then the result. The old framing spent a banner and a\n // paragraph explaining how to reproduce a build that was about to pass anyway; that explanation is\n // only useful when the build FAILS, so it now lives solely on the failure path below.\n //\n // `say`, so it survives a stage that is capturing its own console (see StageOutputLog): the\n // command being run and the result of running it are exactly what a caller watching a long build\n // needs to see live.\n this.stageConsole.say(`\\n${opts.label}: ${buildCommand}\\n`);\n const logPath = this.buildLog.pathFor(repoRoot, opts.stage);\n const ticket = this.buildsLog.start(opts.stage, repoRoot);\n let termination = new BuildTermination(1, null);\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the DONE row must be written whether the\n // build passed, failed, or the spawn itself blew up; the throw is re-raised untouched below\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n termination = await this.buildLog.run(repoRoot, buildCommand, logPath);\n } finally {\n this.buildsLog.finish(ticket, termination);\n }\n const buildCode = termination.code === null || termination.signal !== null ? 1 : termination.code;\n if (buildCode !== 0) {\n throw new CliExitError(buildCode, this.failureText(opts, buildCommand, logPath, termination));\n }\n this.stageConsole.say(this.buildLog.successMessage(logPath));\n }\n\n /**\n * The failure text: this gate's own headline, then the pointer at the log the build already wrote.\n *\n * There is no second, streamed variant any more. Capturing used to be behind an EXPERIMENTAL\n * machine-local opt-in, which meant the refusal an agent read depended on a file almost nobody had —\n * and the un-captured branch's advice was \"run the build again yourself\", which is the single most\n * expensive thing an agent can be told. Reading a FILE is now the only answer this gate gives.\n */\n private failureText(opts: BuildGateOptions, buildCommand: string, logPath: string, termination: BuildTermination): string {\n return `\\n❌ ${opts.failureHeadline}\\n` + this.buildLog.failureMessage(buildCommand, logPath, termination) + `Fix what that log shows, then re-run ${opts.rerunCommand}.\\n`;\n }\n}\n"]}
@@ -0,0 +1,38 @@
1
+ import { BranchIdentity, PrSummary, ReviewJsonService } from '@webpieces/rules-config';
2
+ import { AiBranchName } from './git-readAiBranchName';
3
+ import { BuildAffected } from './build-affected';
4
+ import { BuildArtifactGate } from './build-artifact-gate';
5
+ import { ChecklistScan, ChecklistScanner } from './checklist-scanner';
6
+ import { DiffMaterializer } from './diff-materializer';
7
+ import { GitExec } from './git-exec';
8
+ import { MergeEnd } from './merge-end';
9
+ import { MergeState } from './merge-state';
10
+ import { PrContextWriter } from './pr-context-writer';
11
+ import { ProvenanceEnforcer, ProvenanceReport } from './provenance-enforcer';
12
+ export declare class HotfixFinishState {
13
+ readonly featureName: string;
14
+ readonly currentBranch: string;
15
+ readonly review: PrSummary;
16
+ readonly scan: ChecklistScan;
17
+ readonly provenance: ProvenanceReport;
18
+ constructor(featureName: string, currentBranch: string, review: PrSummary, scan: ChecklistScan, provenance: ProvenanceReport);
19
+ }
20
+ /** Validates and builds the emergency flow before FinishUpsertPrCommand publishes anything. */
21
+ export declare class HotfixFinishPreparer {
22
+ private readonly branchIdentity;
23
+ private readonly aiBranchName;
24
+ private readonly gitExec;
25
+ private readonly reviewJsonService;
26
+ private readonly buildAffected;
27
+ private readonly buildArtifactGate;
28
+ private readonly mergeState;
29
+ private readonly mergeEnd;
30
+ private readonly checklistScanner;
31
+ private readonly materializer;
32
+ private readonly prContextWriter;
33
+ private readonly provenanceEnforcer;
34
+ constructor(branchIdentity: BranchIdentity, aiBranchName: AiBranchName, gitExec: GitExec, reviewJsonService: ReviewJsonService, buildAffected: BuildAffected, buildArtifactGate: BuildArtifactGate, mergeState: MergeState, mergeEnd: MergeEnd, checklistScanner: ChecklistScanner, materializer: DiffMaterializer, prContextWriter: PrContextWriter, provenanceEnforcer: ProvenanceEnforcer);
35
+ prepare(repoRoot: string): Promise<HotfixFinishState>;
36
+ private finalizeMerge;
37
+ private gitOut;
38
+ }
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HotfixFinishPreparer = exports.HotfixFinishState = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const child_process_1 = require("child_process");
6
+ const rules_config_1 = require("@webpieces/rules-config");
7
+ const inversify_1 = require("inversify");
8
+ const git_readAiBranchName_1 = require("./git-readAiBranchName");
9
+ const build_affected_1 = require("./build-affected");
10
+ const build_artifact_gate_1 = require("./build-artifact-gate");
11
+ const build_gate_log_1 = require("./build-gate-log");
12
+ const checklist_scanner_1 = require("./checklist-scanner");
13
+ const diff_materializer_1 = require("./diff-materializer");
14
+ const git_exec_1 = require("./git-exec");
15
+ const merge_start_1 = require("./merge-start");
16
+ const merge_end_1 = require("./merge-end");
17
+ const merge_state_1 = require("./merge-state");
18
+ const pr_context_writer_1 = require("./pr-context-writer");
19
+ const provenance_enforcer_1 = require("./provenance-enforcer");
20
+ class HotfixFinishState {
21
+ featureName;
22
+ currentBranch;
23
+ review;
24
+ scan;
25
+ provenance;
26
+ constructor(featureName, currentBranch, review, scan, provenance) {
27
+ this.featureName = featureName;
28
+ this.currentBranch = currentBranch;
29
+ this.review = review;
30
+ this.scan = scan;
31
+ this.provenance = provenance;
32
+ }
33
+ }
34
+ exports.HotfixFinishState = HotfixFinishState;
35
+ /** Validates and builds the emergency flow before FinishUpsertPrCommand publishes anything. */
36
+ let HotfixFinishPreparer = class HotfixFinishPreparer {
37
+ branchIdentity;
38
+ aiBranchName;
39
+ gitExec;
40
+ reviewJsonService;
41
+ buildAffected;
42
+ buildArtifactGate;
43
+ mergeState;
44
+ mergeEnd;
45
+ checklistScanner;
46
+ materializer;
47
+ prContextWriter;
48
+ provenanceEnforcer;
49
+ constructor(branchIdentity, aiBranchName, gitExec, reviewJsonService, buildAffected, buildArtifactGate, mergeState, mergeEnd, checklistScanner, materializer, prContextWriter, provenanceEnforcer) {
50
+ this.branchIdentity = branchIdentity;
51
+ this.aiBranchName = aiBranchName;
52
+ this.gitExec = gitExec;
53
+ this.reviewJsonService = reviewJsonService;
54
+ this.buildAffected = buildAffected;
55
+ this.buildArtifactGate = buildArtifactGate;
56
+ this.mergeState = mergeState;
57
+ this.mergeEnd = mergeEnd;
58
+ this.checklistScanner = checklistScanner;
59
+ this.materializer = materializer;
60
+ this.prContextWriter = prContextWriter;
61
+ this.provenanceEnforcer = provenanceEnforcer;
62
+ }
63
+ async prepare(repoRoot) {
64
+ await this.finalizeMerge(repoRoot);
65
+ this.gitExec.assertCleanTree(repoRoot);
66
+ const featureName = this.aiBranchName.getFeatureName();
67
+ const review = this.reviewJsonService.loadSummaryJson((0, rules_config_1.summaryJsonPath)(repoRoot, featureName), []);
68
+ const headBefore = this.gitOut(repoRoot, ['rev-parse', 'HEAD']);
69
+ await this.buildAffected.runBuildGate(repoRoot, new build_affected_1.BuildGateOptions('🛠️ Hotfix build gate (build + test only)', 'pnpm wp-finish-upsert-pr', 'Hotfix build failed — no PR created/updated.', build_gate_log_1.FINISH_STAGE));
70
+ this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);
71
+ this.gitExec.assertCleanTree(repoRoot);
72
+ if (headBefore === '' || this.gitOut(repoRoot, ['rev-parse', 'HEAD']) !== headBefore) {
73
+ throw new rules_config_1.InformAiError('Hotfix HEAD changed while compilation/tests were running. Re-run pnpm wp-finish-upsert-pr so the build receipt covers the exact commit pushed.');
74
+ }
75
+ const config = (0, rules_config_1.loadAndValidate)(repoRoot).prGate;
76
+ const scan = this.checklistScanner.scan(repoRoot, config.checklists, new checklist_scanner_1.ChecklistScanOptions(false, ''));
77
+ if (!scan.basis.unresolved) {
78
+ this.materializer.materialize(repoRoot, featureName, scan.basis, scan.changedFiles, config.reviewDiffExclude);
79
+ this.prContextWriter.ensure(repoRoot, featureName, scan.basis, 'stage3-hotfix', scan.changedFiles, this.materializer.diffDirFor(repoRoot, featureName));
80
+ }
81
+ const currentBranch = this.branchIdentity.current();
82
+ const provenance = this.provenanceEnforcer.enforce([], currentBranch, repoRoot, config);
83
+ return new HotfixFinishState(featureName, currentBranch, review, scan, provenance);
84
+ }
85
+ async finalizeMerge(repoRoot) {
86
+ const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());
87
+ const activeDir = this.mergeState.findActiveMergeRunDir(home);
88
+ const marker = activeDir ? this.mergeState.readMergeMarker(activeDir) : null;
89
+ if (!activeDir || !marker || marker.validated)
90
+ return;
91
+ await this.mergeEnd.mergeEnd(repoRoot, 'wp-finish-upsert-pr', activeDir, new merge_start_1.MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber), new merge_end_1.MergeEndOptions(marker.conflictedFiles, false));
92
+ }
93
+ gitOut(repoRoot, args) {
94
+ const result = (0, child_process_1.spawnSync)('git', args, { cwd: repoRoot, encoding: 'utf8' });
95
+ return result.status === 0 ? (result.stdout ?? '').trim() : '';
96
+ }
97
+ };
98
+ exports.HotfixFinishPreparer = HotfixFinishPreparer;
99
+ exports.HotfixFinishPreparer = HotfixFinishPreparer = tslib_1.__decorate([
100
+ (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
101
+ tslib_1.__metadata("design:paramtypes", [rules_config_1.BranchIdentity,
102
+ git_readAiBranchName_1.AiBranchName,
103
+ git_exec_1.GitExec,
104
+ rules_config_1.ReviewJsonService,
105
+ build_affected_1.BuildAffected,
106
+ build_artifact_gate_1.BuildArtifactGate,
107
+ merge_state_1.MergeState,
108
+ merge_end_1.MergeEnd,
109
+ checklist_scanner_1.ChecklistScanner,
110
+ diff_materializer_1.DiffMaterializer,
111
+ pr_context_writer_1.PrContextWriter,
112
+ provenance_enforcer_1.ProvenanceEnforcer])
113
+ ], HotfixFinishPreparer);
114
+ //# sourceMappingURL=hotfix-finish-preparer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hotfix-finish-preparer.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/hotfix-finish-preparer.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,0DAAwI;AACxI,yCAA2D;AAC3D,iEAAsD;AACtD,qDAAmE;AACnE,+DAA0D;AAC1D,qDAAgD;AAChD,2DAA4F;AAC5F,2DAAuD;AACvD,yCAAqC;AACrC,+CAA6C;AAC7C,2CAAwD;AACxD,+CAA2C;AAC3C,2DAAsD;AACtD,+DAA6E;AAE7E,MAAa,iBAAiB;IAEb;IACA;IACA;IACA;IACA;IALb,YACa,WAAmB,EACnB,aAAqB,EACrB,MAAiB,EACjB,IAAmB,EACnB,UAA4B;QAJ5B,gBAAW,GAAX,WAAW,CAAQ;QACnB,kBAAa,GAAb,aAAa,CAAQ;QACrB,WAAM,GAAN,MAAM,CAAW;QACjB,SAAI,GAAJ,IAAI,CAAe;QACnB,eAAU,GAAV,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CAAC;IACnE,CAAC;CACJ,CAAA;AAnDY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QACjB,kBAAO;QACG,gCAAiB;QACrB,8BAAa;QACT,uCAAiB;QACxB,wBAAU;QACZ,oBAAQ;QACA,oCAAgB;QACpB,oCAAgB;QACb,mCAAe;QACZ,wCAAkB;GAblD,oBAAoB,CAmDhC","sourcesContent":["import { spawnSync } from 'child_process';\nimport { BranchIdentity, InformAiError, PrSummary, ReviewJsonService, loadAndValidate, summaryJsonPath } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { BuildAffected, BuildGateOptions } from './build-affected';\nimport { BuildArtifactGate } from './build-artifact-gate';\nimport { FINISH_STAGE } from './build-gate-log';\nimport { ChecklistScan, ChecklistScanOptions, ChecklistScanner } from './checklist-scanner';\nimport { DiffMaterializer } from './diff-materializer';\nimport { GitExec } from './git-exec';\nimport { MergeContext } from './merge-start';\nimport { MergeEnd, MergeEndOptions } from './merge-end';\nimport { MergeState } from './merge-state';\nimport { PrContextWriter } from './pr-context-writer';\nimport { ProvenanceEnforcer, ProvenanceReport } from './provenance-enforcer';\n\nexport class HotfixFinishState {\n constructor(\n readonly featureName: string,\n readonly currentBranch: string,\n readonly review: PrSummary,\n readonly scan: ChecklistScan,\n readonly provenance: ProvenanceReport,\n ) {}\n}\n\n/** Validates and builds the emergency flow before FinishUpsertPrCommand publishes anything. */\n@injectable(bindingScopeValues.Singleton)\nexport class HotfixFinishPreparer {\n constructor(\n private readonly branchIdentity: BranchIdentity,\n private readonly aiBranchName: AiBranchName,\n private readonly gitExec: GitExec,\n private readonly reviewJsonService: ReviewJsonService,\n private readonly buildAffected: BuildAffected,\n private readonly buildArtifactGate: BuildArtifactGate,\n private readonly mergeState: MergeState,\n private readonly mergeEnd: MergeEnd,\n private readonly checklistScanner: ChecklistScanner,\n private readonly materializer: DiffMaterializer,\n private readonly prContextWriter: PrContextWriter,\n private readonly provenanceEnforcer: ProvenanceEnforcer,\n ) {}\n\n async prepare(repoRoot: string): Promise<HotfixFinishState> {\n await this.finalizeMerge(repoRoot);\n this.gitExec.assertCleanTree(repoRoot);\n const featureName = this.aiBranchName.getFeatureName();\n const review = this.reviewJsonService.loadSummaryJson(summaryJsonPath(repoRoot, featureName), []);\n const headBefore = this.gitOut(repoRoot, ['rev-parse', 'HEAD']);\n await this.buildAffected.runBuildGate(repoRoot, new BuildGateOptions('🛠️ Hotfix build gate (build + test only)', 'pnpm wp-finish-upsert-pr', 'Hotfix build failed — no PR created/updated.', FINISH_STAGE));\n this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);\n this.gitExec.assertCleanTree(repoRoot);\n if (headBefore === '' || this.gitOut(repoRoot, ['rev-parse', 'HEAD']) !== headBefore) {\n throw new InformAiError('Hotfix HEAD changed while compilation/tests were running. Re-run pnpm wp-finish-upsert-pr so the build receipt covers the exact commit pushed.');\n }\n const config = loadAndValidate(repoRoot).prGate;\n const scan = this.checklistScanner.scan(repoRoot, config.checklists, new ChecklistScanOptions(false, ''));\n if (!scan.basis.unresolved) {\n this.materializer.materialize(repoRoot, featureName, scan.basis, scan.changedFiles, config.reviewDiffExclude);\n this.prContextWriter.ensure(repoRoot, featureName, scan.basis, 'stage3-hotfix', scan.changedFiles, this.materializer.diffDirFor(repoRoot, featureName));\n }\n const currentBranch = this.branchIdentity.current();\n const provenance = this.provenanceEnforcer.enforce([], currentBranch, repoRoot, config);\n return new HotfixFinishState(featureName, currentBranch, review, scan, provenance);\n }\n\n private async finalizeMerge(repoRoot: string): Promise<void> {\n const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());\n const activeDir = this.mergeState.findActiveMergeRunDir(home);\n const marker = activeDir ? this.mergeState.readMergeMarker(activeDir) : null;\n if (!activeDir || !marker || marker.validated) return;\n await this.mergeEnd.mergeEnd(repoRoot, 'wp-finish-upsert-pr', activeDir, new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber), new MergeEndOptions(marker.conflictedFiles, false));\n }\n\n private gitOut(repoRoot: string, args: string[]): string {\n const result = spawnSync('git', args, { cwd: repoRoot, encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ /** Pure instructions for the two hotfix handoffs, kept identical across stages ① and ②. */
2
+ export declare class HotfixInstructions {
3
+ afterStart(summaryPath: string, context: string): string;
4
+ reviewNoOp(summaryPath: string): string;
5
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HotfixInstructions = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const rules_config_1 = require("@webpieces/rules-config");
6
+ const inversify_1 = require("inversify");
7
+ const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
8
+ const PRE_FINISH_NOTICE = 'Compilation and tests will run during pnpm wp-finish-upsert-pr; they have not run yet.';
9
+ /** Pure instructions for the two hotfix handoffs, kept identical across stages ① and ②. */
10
+ let HotfixInstructions = class HotfixInstructions {
11
+ afterStart(summaryPath, context) {
12
+ return ('\n' +
13
+ SEP +
14
+ '⚠️ HOT FIX ⚠️ — reviews and policy checks are bypassed\n' +
15
+ SEP +
16
+ '\n' +
17
+ PRE_FINISH_NOTICE +
18
+ '\n\n' +
19
+ context +
20
+ '\n' +
21
+ (0, rules_config_1.summaryJsonSchemaHint)(summaryPath) +
22
+ '\n\n' +
23
+ 'No reviewer agent runs for this /hotfix/ branch. After writing that meaningful summary, run:\n' +
24
+ ' pnpm wp-finish-upsert-pr\n\n');
25
+ }
26
+ reviewNoOp(summaryPath) {
27
+ return ('\n' +
28
+ SEP +
29
+ '⚠️ HOT FIX ⚠️\n' +
30
+ SEP +
31
+ '\n' +
32
+ PRE_FINISH_NOTICE +
33
+ '\n\n' +
34
+ 'Required and optional reviews are bypassed for this /hotfix/ branch. No reviewer agent ran.\n' +
35
+ 'No build, checklist scan,\n' +
36
+ 'diff materialization, reviewer briefing, or review receipt was produced by this command.\n\n' +
37
+ (0, rules_config_1.summaryJsonSchemaHint)(summaryPath) +
38
+ '\n\n' +
39
+ 'Write the required summary, then run: pnpm wp-finish-upsert-pr\n\n');
40
+ }
41
+ };
42
+ exports.HotfixInstructions = HotfixInstructions;
43
+ exports.HotfixInstructions = HotfixInstructions = tslib_1.__decorate([
44
+ (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
45
+ ], HotfixInstructions);
46
+ //# sourceMappingURL=hotfix-instructions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hotfix-instructions.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/hotfix-instructions.ts"],"names":[],"mappings":";;;;AAAA,0DAAgE;AAChE,yCAA2D;AAE3D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AACvE,MAAM,iBAAiB,GAAG,wFAAwF,CAAC;AAEnH,2FAA2F;AAEpF,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC3B,UAAU,CAAC,WAAmB,EAAE,OAAe;QAC3C,OAAO,CACH,IAAI;YACJ,GAAG;YACH,0DAA0D;YAC1D,GAAG;YACH,IAAI;YACJ,iBAAiB;YACjB,MAAM;YACN,OAAO;YACP,IAAI;YACJ,IAAA,oCAAqB,EAAC,WAAW,CAAC;YAClC,MAAM;YACN,gGAAgG;YAChG,gCAAgC,CACnC,CAAC;IACN,CAAC;IAED,UAAU,CAAC,WAAmB;QAC1B,OAAO,CACH,IAAI;YACJ,GAAG;YACH,iBAAiB;YACjB,GAAG;YACH,IAAI;YACJ,iBAAiB;YACjB,MAAM;YACN,+FAA+F;YAC/F,6BAA6B;YAC7B,8FAA8F;YAC9F,IAAA,oCAAqB,EAAC,WAAW,CAAC;YAClC,MAAM;YACN,oEAAoE,CACvE,CAAC;IACN,CAAC;CACJ,CAAA;AApCY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,kBAAkB,CAoC9B","sourcesContent":["import { summaryJsonSchemaHint } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\nconst PRE_FINISH_NOTICE = 'Compilation and tests will run during pnpm wp-finish-upsert-pr; they have not run yet.';\n\n/** Pure instructions for the two hotfix handoffs, kept identical across stages ① and ②. */\n@injectable(bindingScopeValues.Singleton)\nexport class HotfixInstructions {\n afterStart(summaryPath: string, context: string): string {\n return (\n '\\n' +\n SEP +\n '⚠️ HOT FIX ⚠️ — reviews and policy checks are bypassed\\n' +\n SEP +\n '\\n' +\n PRE_FINISH_NOTICE +\n '\\n\\n' +\n context +\n '\\n' +\n summaryJsonSchemaHint(summaryPath) +\n '\\n\\n' +\n 'No reviewer agent runs for this /hotfix/ branch. After writing that meaningful summary, run:\\n' +\n ' pnpm wp-finish-upsert-pr\\n\\n'\n );\n }\n\n reviewNoOp(summaryPath: string): string {\n return (\n '\\n' +\n SEP +\n '⚠️ HOT FIX ⚠️\\n' +\n SEP +\n '\\n' +\n PRE_FINISH_NOTICE +\n '\\n\\n' +\n 'Required and optional reviews are bypassed for this /hotfix/ branch. No reviewer agent ran.\\n' +\n 'No build, checklist scan,\\n' +\n 'diff materialization, reviewer briefing, or review receipt was produced by this command.\\n\\n' +\n summaryJsonSchemaHint(summaryPath) +\n '\\n\\n' +\n 'Write the required summary, then run: pnpm wp-finish-upsert-pr\\n\\n'\n );\n }\n}\n"]}