@webpieces/pr-gate 0.4.823 → 0.4.825

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.
Files changed (36) hide show
  1. package/package.json +4 -3
  2. package/src/index.d.ts +1 -1
  3. package/src/index.js +1 -1
  4. package/src/index.js.map +1 -1
  5. package/src/scripts/commands/build-command.d.ts +3 -0
  6. package/src/scripts/commands/build-command.js +29 -17
  7. package/src/scripts/commands/build-command.js.map +1 -1
  8. package/src/scripts/commands/check-pr-command.d.ts +10 -3
  9. package/src/scripts/commands/check-pr-command.js +31 -10
  10. package/src/scripts/commands/check-pr-command.js.map +1 -1
  11. package/src/scripts/commands/human-post-pr-command.d.ts +52 -0
  12. package/src/scripts/commands/human-post-pr-command.js +260 -0
  13. package/src/scripts/commands/human-post-pr-command.js.map +1 -0
  14. package/src/scripts/pr-gate-app.d.ts +5 -1
  15. package/src/scripts/pr-gate-app.js +10 -1
  16. package/src/scripts/pr-gate-app.js.map +1 -1
  17. package/src/scripts/workflow/build-affected.d.ts +3 -0
  18. package/src/scripts/workflow/build-affected.js +16 -3
  19. package/src/scripts/workflow/build-affected.js.map +1 -1
  20. package/src/scripts/workflow/build-gate-log.d.ts +4 -1
  21. package/src/scripts/workflow/build-gate-log.js +20 -5
  22. package/src/scripts/workflow/build-gate-log.js.map +1 -1
  23. package/src/scripts/workflow/build-log-follower.d.ts +13 -0
  24. package/src/scripts/workflow/build-log-follower.js +48 -0
  25. package/src/scripts/workflow/build-log-follower.js.map +1 -0
  26. package/src/scripts/workflow/gated-pr-publisher.d.ts +1 -1
  27. package/src/scripts/workflow/gated-pr-publisher.js +20 -7
  28. package/src/scripts/workflow/gated-pr-publisher.js.map +1 -1
  29. package/src/scripts/workflow/push-dev-state.js +30 -17
  30. package/src/scripts/workflow/push-dev-state.js.map +1 -1
  31. package/src/scripts/wp-human-post-pr.d.ts +2 -0
  32. package/src/scripts/wp-human-post-pr.js +15 -0
  33. package/src/scripts/wp-human-post-pr.js.map +1 -0
  34. package/src/scripts/workflow/git-validateUpToDate.d.ts +0 -1
  35. package/src/scripts/workflow/git-validateUpToDate.js +0 -70
  36. package/src/scripts/workflow/git-validateUpToDate.js.map +0 -1
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HumanPostPrCommand = exports.HumanPostedPr = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const child_process_1 = require("child_process");
6
+ const fs = tslib_1.__importStar(require("fs"));
7
+ const path = tslib_1.__importStar(require("path"));
8
+ const readline = tslib_1.__importStar(require("readline"));
9
+ const rules_config_1 = require("@webpieces/rules-config");
10
+ const inversify_1 = require("inversify");
11
+ const git_readAiBranchName_1 = require("../workflow/git-readAiBranchName");
12
+ const branch_naming_1 = require("../workflow/branch-naming");
13
+ const gated_pr_publisher_1 = require("../workflow/gated-pr-publisher");
14
+ const git_exec_1 = require("../workflow/git-exec");
15
+ const merge_state_1 = require("../workflow/merge-state");
16
+ const squash_settings_enforcer_1 = require("../workflow/squash-settings-enforcer");
17
+ const build_command_1 = require("./build-command");
18
+ const RETRY_COMMAND = 'pnpm wp-human-post-pr';
19
+ /** The PR identity returned by GitHub after posting. Data-only, per CLAUDE.md. */
20
+ class HumanPostedPr {
21
+ number;
22
+ url;
23
+ constructor(number, url) {
24
+ this.number = number;
25
+ this.url = url;
26
+ }
27
+ }
28
+ exports.HumanPostedPr = HumanPostedPr;
29
+ /**
30
+ * Interactive, human-attested PR escape hatch.
31
+ *
32
+ * The first answer is an attestation, not identity detection: a process cannot prove who typed it. The
33
+ * fail-closed ordering is the security property here — every answer except the literal normalized
34
+ * `human` returns before repository discovery, git, GitHub, or any write.
35
+ */
36
+ let HumanPostPrCommand = class HumanPostPrCommand {
37
+ repoRootFinder;
38
+ branchIdentity;
39
+ branchNaming;
40
+ aiBranchName;
41
+ gitExec;
42
+ mergeState;
43
+ reviewJsonService;
44
+ mainSyncStatus;
45
+ gateTokenService;
46
+ publisher;
47
+ squashSettings;
48
+ buildCommand;
49
+ constructor(repoRootFinder, branchIdentity, branchNaming, aiBranchName, gitExec, mergeState, reviewJsonService, mainSyncStatus, gateTokenService, publisher, squashSettings, buildCommand) {
50
+ this.repoRootFinder = repoRootFinder;
51
+ this.branchIdentity = branchIdentity;
52
+ this.branchNaming = branchNaming;
53
+ this.aiBranchName = aiBranchName;
54
+ this.gitExec = gitExec;
55
+ this.mergeState = mergeState;
56
+ this.reviewJsonService = reviewJsonService;
57
+ this.mainSyncStatus = mainSyncStatus;
58
+ this.gateTokenService = gateTokenService;
59
+ this.publisher = publisher;
60
+ this.squashSettings = squashSettings;
61
+ this.buildCommand = buildCommand;
62
+ }
63
+ async run() {
64
+ const answer = (await this.question('Are you human or AI (human/AI)?\n'))
65
+ .trim()
66
+ .toLowerCase();
67
+ if (answer !== 'human') {
68
+ throw new rules_config_1.CliExitError(1, 'wp-human-post-pr requires an explicit human attestation. Nothing was changed.');
69
+ }
70
+ const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
71
+ const currentBranch = this.branchIdentity.current();
72
+ if (currentBranch === '' || currentBranch === 'HEAD') {
73
+ throw new rules_config_1.CliExitError(1, 'wp-human-post-pr requires a checked-out feature branch; detached HEAD is not publishable.');
74
+ }
75
+ if (currentBranch === 'main') {
76
+ throw new rules_config_1.CliExitError(1, 'wp-human-post-pr refuses main. Check out a clean feature branch and rerun it.');
77
+ }
78
+ const baseBranch = this.branchNaming.baseBranchName(currentBranch);
79
+ this.gitExec.assertCleanTree(repoRoot);
80
+ this.assertNoUnvalidatedMerge(repoRoot);
81
+ this.fetchMain(repoRoot);
82
+ const forkPoint = this.git(['merge-base', 'origin/main', 'HEAD'], repoRoot, 'Could not resolve the pure-main fork point against freshly fetched origin/main.');
83
+ const summaryPath = this.reviewJsonService.summaryJsonPath(repoRoot, this.aiBranchName.getFeatureName());
84
+ await this.ensureSummary(summaryPath, forkPoint);
85
+ const summary = this.reviewJsonService.loadSummaryJson(summaryPath, [], '', {}, RETRY_COMMAND);
86
+ const status = this.mainSyncStatus.computeMainSyncStatus(repoRoot);
87
+ this.assertCurrentMain(status);
88
+ const buildRan = await this.askToBuild();
89
+ if (buildRan)
90
+ this.gitExec.assertCleanTree(repoRoot);
91
+ this.post(repoRoot, baseBranch, summaryPath, summary, buildRan);
92
+ }
93
+ /** The safe body-before-push publication shared with the automated flow via GatedPrPublisher. */
94
+ post(repoRoot, baseBranch, summaryPath, summary, buildRan) {
95
+ const headSha = this.git(['rev-parse', 'HEAD'], repoRoot, 'Could not resolve feature HEAD.');
96
+ const gateSalt = this.gateSalt(repoRoot);
97
+ const initialRef = this.resolvePr(baseBranch);
98
+ const initialBody = this.renderBody(summary, initialRef.url, gateSalt, headSha, buildRan);
99
+ const bodyFile = path.join(this.reviewJsonService.prDirFor(repoRoot, this.aiBranchName.getFeatureName()), 'pr-body.md');
100
+ fs.mkdirSync(path.dirname(bodyFile), { recursive: true });
101
+ fs.writeFileSync(bodyFile, initialBody + '\n');
102
+ const published = this.publisher.publish(baseBranch, this.titleFrom(summary, baseBranch), bodyFile, RETRY_COMMAND);
103
+ if (published.createFailed) {
104
+ throw new rules_config_1.CliExitError(1, `gh pr create failed. The validated body remains at ${bodyFile}; summary.json was not consumed.`);
105
+ }
106
+ const finalRef = this.resolvePr(baseBranch);
107
+ if (finalRef.number === '') {
108
+ throw new rules_config_1.CliExitError(1, 'The branch was pushed but GitHub did not return its open PR; summary.json was not consumed.');
109
+ }
110
+ const finalBody = this.renderBody(summary, finalRef.url, gateSalt, headSha, buildRan);
111
+ if (finalBody !== initialBody)
112
+ this.backfillBody(finalRef.number, bodyFile, finalBody);
113
+ this.squashSettings.ensure();
114
+ const archive = this.reviewJsonService.archiveSummaryJson(summaryPath);
115
+ if (archive !== '')
116
+ process.stdout.write(`Archived this run's summary.json → ${archive} (audit only) ✓\n`);
117
+ process.stdout.write(`✅ Human-attested PR posted (${buildRan ? 'local wp-build passed; automated review skipped' : 'local build/review skipped'}): ${finalRef.url}\n`);
118
+ }
119
+ async askToBuild() {
120
+ const answer = (await this.question('Run ' + 'wp-build here (If no, CI will run it in the cloud) Y/N?\n'))
121
+ .trim()
122
+ .toLowerCase();
123
+ if (answer === 'n' || answer === 'no')
124
+ return false;
125
+ if (answer !== 'y' && answer !== 'yes') {
126
+ throw new rules_config_1.CliExitError(1, 'Please answer Y or N. No PR was pushed or edited.');
127
+ }
128
+ await this.buildCommand.runStreaming(new build_command_1.BuildOptions(false));
129
+ return true;
130
+ }
131
+ assertNoUnvalidatedMerge(repoRoot) {
132
+ const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());
133
+ const active = this.mergeState.findActiveMergeRunDir(home);
134
+ const marker = active === null ? null : this.mergeState.readMergeMarker(active);
135
+ if (marker === null || marker.validated)
136
+ return;
137
+ throw new rules_config_1.CliExitError(1, 'wp-human-post-pr refuses an active, unvalidated 3-point merge. Resolve it and run the supported ' +
138
+ 'Webpieces finish/update flow before posting.');
139
+ }
140
+ fetchMain(repoRoot) {
141
+ this.gitExec.runGitChecked(['fetch', 'origin', 'main'], 'Could not refresh origin/main; wp-human-post-pr will not evaluate or publish against a stale ref');
142
+ }
143
+ gateSalt(repoRoot) {
144
+ return (0, rules_config_1.loadAndValidate)(repoRoot).prGate.gateSalt;
145
+ }
146
+ async ensureSummary(summaryPath, forkPoint) {
147
+ if (fs.existsSync(summaryPath))
148
+ return;
149
+ process.stdout.write('\nCopy/paste the following instruction into AI:\n\n' +
150
+ `Write ONLY ${summaryPath}.\n` +
151
+ 'Do not run pnpm wp-review-upsert-pr, pnpm wp-finish-upsert-pr, push, or create/update a PR.\n' +
152
+ `Summarize exactly: git diff ${forkPoint} HEAD\n` +
153
+ `Changed files: git diff --name-only ${forkPoint} HEAD\n\n` +
154
+ this.reviewJsonService.summaryJsonSchemaHint(summaryPath) +
155
+ '\n\n');
156
+ const answer = (await this.question("I don't see summary.json and we at least need that to short circuit pushing.\n" +
157
+ 'Please paste the instructions above into AI. When it is done generating summary.json, continue? (Y/N)\n'))
158
+ .trim()
159
+ .toLowerCase();
160
+ if (answer !== 'y' && answer !== 'yes') {
161
+ throw new rules_config_1.CliExitError(1, 'No PR was pushed or edited. Rerun pnpm wp-human-post-pr when summary.json is ready.');
162
+ }
163
+ }
164
+ assertCurrentMain(status) {
165
+ if (!status.hasForkPoint || status.forkPoint === null) {
166
+ throw new rules_config_1.CliExitError(1, 'Could not establish a pure-main fork point. Use the Webpieces update process; do not merge or rebase manually.');
167
+ }
168
+ if (status.forkPoint === status.originMain)
169
+ return;
170
+ const conflicts = status.conflictFiles.length === 0
171
+ ? 'Conflicts: (none predicted)'
172
+ : 'Conflicts (files changed on both sides; conservative prediction):\n' +
173
+ status.conflictFiles.map((file) => ` - ${file}`).join('\n');
174
+ const update = status.openPr === ''
175
+ ? ' pnpm wp-start-update\n # if conflicts are reported, resolve them, then:\n pnpm wp-finish-update'
176
+ : ' pnpm wp-start-upsert-pr\n pnpm wp-review-upsert-pr\n pnpm wp-finish-upsert-pr';
177
+ throw new rules_config_1.CliExitError(1, 'Your branch is behind origin/main.\n\n' +
178
+ 'Ask AI to run the Webpieces update process, then rerun pnpm wp-human-post-pr.\n' +
179
+ 'This is usually very quick unless you have conflicts.\n\n' +
180
+ update +
181
+ '\n\n' +
182
+ conflicts);
183
+ }
184
+ renderBody(summary, prUrl, gateSalt, headSha, buildRan) {
185
+ const lines = [];
186
+ if (prUrl !== '')
187
+ lines.push(prUrl, '');
188
+ lines.push(`Risk: ${summary.riskScore}/100 ${summary.riskEmoji} (${summary.riskLevel})`);
189
+ lines.push(`Summary authored by ${summary.agent} (${summary.model})`);
190
+ lines.push('');
191
+ lines.push(buildRan
192
+ ? 'Flags: ⚠️ HUMAN ESCAPE HATCH — local wp-build passed; automated reviewer stages were explicitly skipped.'
193
+ : 'Flags: ⚠️ HUMAN ESCAPE HATCH — local build and automated reviewer stages were explicitly skipped; cloud CI will run.');
194
+ if (summary.summary.trim() !== '')
195
+ lines.push('', summary.summary.trim());
196
+ lines.push('', `Generated by webpieces-ts wp-human-post-pr (human-attested; ${buildRan ? 'local wp-build passed, automated review skipped' : 'local build/review skipped'})`);
197
+ const marker = this.gateTokenService.gateTokenMarker(gateSalt, headSha);
198
+ if (marker !== '')
199
+ lines.push('', marker);
200
+ return lines.join('\n').replace(/\|/g, '\u00a6').replace(/#{2,}/g, '#');
201
+ }
202
+ titleFrom(summary, branch) {
203
+ return summary.title === '' ? branch.replace(/[-/]+/g, ' ').trim() : summary.title;
204
+ }
205
+ resolvePr(branch) {
206
+ const result = (0, child_process_1.spawnSync)('gh', ['pr', 'view', branch, '--json', 'number,url', '--jq', '"\\(.number)\\t\\(.url)"'], { encoding: 'utf8' });
207
+ if (result.status !== 0)
208
+ return new HumanPostedPr('', '');
209
+ const parts = (result.stdout ?? '').trim().split('\t');
210
+ return new HumanPostedPr(parts[0] ?? '', parts[1] ?? '');
211
+ }
212
+ backfillBody(prNumber, bodyFile, body) {
213
+ fs.writeFileSync(bodyFile, body + '\n');
214
+ if (this.editPrBody(prNumber, bodyFile) !== 0) {
215
+ throw new rules_config_1.CliExitError(1, `Could not update PR #${prNumber} with its final human-bypass body. The validated body remains at ${bodyFile}. ` +
216
+ `Fix GitHub access, then re-run ${RETRY_COMMAND}; summary.json was not consumed.`);
217
+ }
218
+ }
219
+ editPrBody(prNumber, bodyFile) {
220
+ return (0, child_process_1.spawnSync)('gh', ['pr', 'edit', prNumber, '--body-file', bodyFile], {
221
+ stdio: 'inherit',
222
+ }).status;
223
+ }
224
+ git(args, cwd, failure) {
225
+ return this.gitExec.gitQuery(args, cwd, failure);
226
+ }
227
+ // Seam: overridden in specs. EOF resolves to '' and therefore fails closed.
228
+ question(prompt) {
229
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
230
+ return new Promise((resolve) => {
231
+ let answered = false;
232
+ rl.question(prompt, (answer) => {
233
+ answered = true;
234
+ rl.close();
235
+ resolve(answer);
236
+ });
237
+ rl.on('close', () => {
238
+ if (!answered)
239
+ resolve('');
240
+ });
241
+ });
242
+ }
243
+ };
244
+ exports.HumanPostPrCommand = HumanPostPrCommand;
245
+ exports.HumanPostPrCommand = HumanPostPrCommand = tslib_1.__decorate([
246
+ (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
247
+ tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
248
+ rules_config_1.BranchIdentity,
249
+ branch_naming_1.BranchNaming,
250
+ git_readAiBranchName_1.AiBranchName,
251
+ git_exec_1.GitExec,
252
+ merge_state_1.MergeState,
253
+ rules_config_1.ReviewJsonService,
254
+ rules_config_1.MainSyncStatusService,
255
+ rules_config_1.GateTokenService,
256
+ gated_pr_publisher_1.GatedPrPublisher,
257
+ squash_settings_enforcer_1.SquashSettingsEnforcer,
258
+ build_command_1.BuildCommand])
259
+ ], HumanPostPrCommand);
260
+ //# sourceMappingURL=human-post-pr-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"human-post-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/human-post-pr-command.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,+CAAyB;AACzB,mDAA6B;AAC7B,2DAAqC;AACrC,0DAUiC;AACjC,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,uEAAkE;AAClE,mDAA+C;AAC/C,yDAAqD;AACrD,mFAA8E;AAC9E,mDAA6D;AAE7D,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAE9C,kFAAkF;AAClF,MAAa,aAAa;IACtB,MAAM,CAAS;IACf,GAAG,CAAS;IAEZ,YAAY,MAAc,EAAE,GAAW;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;CACJ;AARD,sCAQC;AAED;;;;;;GAMG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAEN;IACA;IACA;IAC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AE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACtF,OAAO,IAAI,OAAO,CAAS,CAAC,OAAgC,EAAQ,EAAE;YAClE,IAAI,QAAQ,GAAG,KAAK,CAAC;YACrB,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAc,EAAQ,EAAE;gBACzC,QAAQ,GAAG,IAAI,CAAC;gBAChB,EAAE,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAS,EAAE;gBACtB,IAAI,CAAC,QAAQ;oBAAE,OAAO,CAAC,EAAE,CAAC,CAAC;YAC/B,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AAlSY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACd,6BAAc;QAChB,4BAAY;QACZ,mCAAY;QACjB,kBAAO;QACJ,wBAAU;QACH,gCAAiB;QACpB,oCAAqB;QACnB,+BAAgB;QACvB,qCAAgB;QACX,iDAAsB;QACxB,4BAAY;GAbtC,kBAAkB,CAkS9B","sourcesContent":["import { spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as readline from 'readline';\nimport {\n BranchIdentity,\n CliExitError,\n GateTokenService,\n MainSyncStatus,\n MainSyncStatusService,\n PrSummary,\n RepoRootFinder,\n ReviewJsonService,\n loadAndValidate,\n} from '@webpieces/rules-config';\nimport { bindingScopeValues, injectable } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { GatedPrPublisher } from '../workflow/gated-pr-publisher';\nimport { GitExec } from '../workflow/git-exec';\nimport { MergeState } from '../workflow/merge-state';\nimport { SquashSettingsEnforcer } from '../workflow/squash-settings-enforcer';\nimport { BuildCommand, BuildOptions } from './build-command';\n\nconst RETRY_COMMAND = 'pnpm wp-human-post-pr';\n\n/** The PR identity returned by GitHub after posting. Data-only, per CLAUDE.md. */\nexport class HumanPostedPr {\n number: string;\n url: string;\n\n constructor(number: string, url: string) {\n this.number = number;\n this.url = url;\n }\n}\n\n/**\n * Interactive, human-attested PR escape hatch.\n *\n * The first answer is an attestation, not identity detection: a process cannot prove who typed it. The\n * fail-closed ordering is the security property here — every answer except the literal normalized\n * `human` returns before repository discovery, git, GitHub, or any write.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class HumanPostPrCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly branchIdentity: BranchIdentity,\n private readonly branchNaming: BranchNaming,\n private readonly aiBranchName: AiBranchName,\n private readonly gitExec: GitExec,\n private readonly mergeState: MergeState,\n private readonly reviewJsonService: ReviewJsonService,\n private readonly mainSyncStatus: MainSyncStatusService,\n private readonly gateTokenService: GateTokenService,\n private readonly publisher: GatedPrPublisher,\n private readonly squashSettings: SquashSettingsEnforcer,\n private readonly buildCommand: BuildCommand,\n ) {}\n\n async run(): Promise<void> {\n const answer = (await this.question('Are you human or AI (human/AI)?\\n'))\n .trim()\n .toLowerCase();\n if (answer !== 'human') {\n throw new CliExitError(\n 1,\n 'wp-human-post-pr requires an explicit human attestation. Nothing was changed.',\n );\n }\n\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n const currentBranch = this.branchIdentity.current();\n if (currentBranch === '' || currentBranch === 'HEAD') {\n throw new CliExitError(\n 1,\n 'wp-human-post-pr requires a checked-out feature branch; detached HEAD is not publishable.',\n );\n }\n if (currentBranch === 'main') {\n throw new CliExitError(\n 1,\n 'wp-human-post-pr refuses main. Check out a clean feature branch and rerun it.',\n );\n }\n const baseBranch = this.branchNaming.baseBranchName(currentBranch);\n this.gitExec.assertCleanTree(repoRoot);\n this.assertNoUnvalidatedMerge(repoRoot);\n this.fetchMain(repoRoot);\n\n const forkPoint = this.git(\n ['merge-base', 'origin/main', 'HEAD'],\n repoRoot,\n 'Could not resolve the pure-main fork point against freshly fetched origin/main.',\n );\n const summaryPath = this.reviewJsonService.summaryJsonPath(\n repoRoot,\n this.aiBranchName.getFeatureName(),\n );\n await this.ensureSummary(summaryPath, forkPoint);\n const summary = this.reviewJsonService.loadSummaryJson(summaryPath, [], '', {}, RETRY_COMMAND);\n\n const status = this.mainSyncStatus.computeMainSyncStatus(repoRoot);\n this.assertCurrentMain(status);\n const buildRan = await this.askToBuild();\n if (buildRan) this.gitExec.assertCleanTree(repoRoot);\n\n this.post(repoRoot, baseBranch, summaryPath, summary, buildRan);\n }\n\n /** The safe body-before-push publication shared with the automated flow via GatedPrPublisher. */\n private post(\n repoRoot: string,\n baseBranch: string,\n summaryPath: string,\n summary: PrSummary,\n buildRan: boolean,\n ): void {\n const headSha = this.git(\n ['rev-parse', 'HEAD'],\n repoRoot,\n 'Could not resolve feature HEAD.',\n );\n const gateSalt = this.gateSalt(repoRoot);\n const initialRef = this.resolvePr(baseBranch);\n const initialBody = this.renderBody(summary, initialRef.url, gateSalt, headSha, buildRan);\n const bodyFile = path.join(\n this.reviewJsonService.prDirFor(repoRoot, this.aiBranchName.getFeatureName()),\n 'pr-body.md',\n );\n fs.mkdirSync(path.dirname(bodyFile), { recursive: true });\n fs.writeFileSync(bodyFile, initialBody + '\\n');\n\n const published = this.publisher.publish(\n baseBranch,\n this.titleFrom(summary, baseBranch),\n bodyFile,\n RETRY_COMMAND,\n );\n if (published.createFailed) {\n throw new CliExitError(\n 1,\n `gh pr create failed. The validated body remains at ${bodyFile}; summary.json was not consumed.`,\n );\n }\n\n const finalRef = this.resolvePr(baseBranch);\n if (finalRef.number === '') {\n throw new CliExitError(\n 1,\n 'The branch was pushed but GitHub did not return its open PR; summary.json was not consumed.',\n );\n }\n const finalBody = this.renderBody(summary, finalRef.url, gateSalt, headSha, buildRan);\n if (finalBody !== initialBody) this.backfillBody(finalRef.number, bodyFile, finalBody);\n this.squashSettings.ensure();\n const archive = this.reviewJsonService.archiveSummaryJson(summaryPath);\n if (archive !== '')\n process.stdout.write(`Archived this run's summary.json → ${archive} (audit only) ✓\\n`);\n process.stdout.write(\n `✅ Human-attested PR posted (${buildRan ? 'local wp-build passed; automated review skipped' : 'local build/review skipped'}): ${finalRef.url}\\n`,\n );\n }\n\n private async askToBuild(): Promise<boolean> {\n const answer = (\n await this.question('Run ' + 'wp-build here (If no, CI will run it in the cloud) Y/N?\\n')\n )\n .trim()\n .toLowerCase();\n if (answer === 'n' || answer === 'no') return false;\n if (answer !== 'y' && answer !== 'yes') {\n throw new CliExitError(1, 'Please answer Y or N. No PR was pushed or edited.');\n }\n await this.buildCommand.runStreaming(new BuildOptions(false));\n return true;\n }\n\n private assertNoUnvalidatedMerge(repoRoot: string): void {\n const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());\n const active = this.mergeState.findActiveMergeRunDir(home);\n const marker = active === null ? null : this.mergeState.readMergeMarker(active);\n if (marker === null || marker.validated) return;\n throw new CliExitError(\n 1,\n 'wp-human-post-pr refuses an active, unvalidated 3-point merge. Resolve it and run the supported ' +\n 'Webpieces finish/update flow before posting.',\n );\n }\n\n protected fetchMain(repoRoot: string): void {\n this.gitExec.runGitChecked(\n ['fetch', 'origin', 'main'],\n 'Could not refresh origin/main; wp-human-post-pr will not evaluate or publish against a stale ref',\n );\n }\n\n protected gateSalt(repoRoot: string): string {\n return loadAndValidate(repoRoot).prGate.gateSalt;\n }\n\n private async ensureSummary(summaryPath: string, forkPoint: string): Promise<void> {\n if (fs.existsSync(summaryPath)) return;\n process.stdout.write(\n '\\nCopy/paste the following instruction into AI:\\n\\n' +\n `Write ONLY ${summaryPath}.\\n` +\n 'Do not run pnpm wp-review-upsert-pr, pnpm wp-finish-upsert-pr, push, or create/update a PR.\\n' +\n `Summarize exactly: git diff ${forkPoint} HEAD\\n` +\n `Changed files: git diff --name-only ${forkPoint} HEAD\\n\\n` +\n this.reviewJsonService.summaryJsonSchemaHint(summaryPath) +\n '\\n\\n',\n );\n const answer = (\n await this.question(\n \"I don't see summary.json and we at least need that to short circuit pushing.\\n\" +\n 'Please paste the instructions above into AI. When it is done generating summary.json, continue? (Y/N)\\n',\n )\n )\n .trim()\n .toLowerCase();\n if (answer !== 'y' && answer !== 'yes') {\n throw new CliExitError(\n 1,\n 'No PR was pushed or edited. Rerun pnpm wp-human-post-pr when summary.json is ready.',\n );\n }\n }\n\n private assertCurrentMain(status: MainSyncStatus): void {\n if (!status.hasForkPoint || status.forkPoint === null) {\n throw new CliExitError(\n 1,\n 'Could not establish a pure-main fork point. Use the Webpieces update process; do not merge or rebase manually.',\n );\n }\n if (status.forkPoint === status.originMain) return;\n const conflicts =\n status.conflictFiles.length === 0\n ? 'Conflicts: (none predicted)'\n : 'Conflicts (files changed on both sides; conservative prediction):\\n' +\n status.conflictFiles.map((file: string): string => ` - ${file}`).join('\\n');\n const update =\n status.openPr === ''\n ? ' pnpm wp-start-update\\n # if conflicts are reported, resolve them, then:\\n pnpm wp-finish-update'\n : ' pnpm wp-start-upsert-pr\\n pnpm wp-review-upsert-pr\\n pnpm wp-finish-upsert-pr';\n throw new CliExitError(\n 1,\n 'Your branch is behind origin/main.\\n\\n' +\n 'Ask AI to run the Webpieces update process, then rerun pnpm wp-human-post-pr.\\n' +\n 'This is usually very quick unless you have conflicts.\\n\\n' +\n update +\n '\\n\\n' +\n conflicts,\n );\n }\n\n private renderBody(\n summary: PrSummary,\n prUrl: string,\n gateSalt: string,\n headSha: string,\n buildRan: boolean,\n ): string {\n const lines: string[] = [];\n if (prUrl !== '') lines.push(prUrl, '');\n lines.push(`Risk: ${summary.riskScore}/100 ${summary.riskEmoji} (${summary.riskLevel})`);\n lines.push(`Summary authored by ${summary.agent} (${summary.model})`);\n lines.push('');\n lines.push(\n buildRan\n ? 'Flags: ⚠️ HUMAN ESCAPE HATCH — local wp-build passed; automated reviewer stages were explicitly skipped.'\n : 'Flags: ⚠️ HUMAN ESCAPE HATCH — local build and automated reviewer stages were explicitly skipped; cloud CI will run.',\n );\n if (summary.summary.trim() !== '') lines.push('', summary.summary.trim());\n lines.push(\n '',\n `Generated by webpieces-ts wp-human-post-pr (human-attested; ${buildRan ? 'local wp-build passed, automated review skipped' : 'local build/review skipped'})`,\n );\n const marker = this.gateTokenService.gateTokenMarker(gateSalt, headSha);\n if (marker !== '') lines.push('', marker);\n return lines.join('\\n').replace(/\\|/g, '\\u00a6').replace(/#{2,}/g, '#');\n }\n\n private titleFrom(summary: PrSummary, branch: string): string {\n return summary.title === '' ? branch.replace(/[-/]+/g, ' ').trim() : summary.title;\n }\n\n protected resolvePr(branch: string): HumanPostedPr {\n const result = spawnSync(\n 'gh',\n ['pr', 'view', branch, '--json', 'number,url', '--jq', '\"\\\\(.number)\\\\t\\\\(.url)\"'],\n { encoding: 'utf8' },\n );\n if (result.status !== 0) return new HumanPostedPr('', '');\n const parts = (result.stdout ?? '').trim().split('\\t');\n return new HumanPostedPr(parts[0] ?? '', parts[1] ?? '');\n }\n\n protected backfillBody(prNumber: string, bodyFile: string, body: string): void {\n fs.writeFileSync(bodyFile, body + '\\n');\n if (this.editPrBody(prNumber, bodyFile) !== 0) {\n throw new CliExitError(\n 1,\n `Could not update PR #${prNumber} with its final human-bypass body. The validated body remains at ${bodyFile}. ` +\n `Fix GitHub access, then re-run ${RETRY_COMMAND}; summary.json was not consumed.`,\n );\n }\n }\n\n protected editPrBody(prNumber: string, bodyFile: string): number | null {\n return spawnSync('gh', ['pr', 'edit', prNumber, '--body-file', bodyFile], {\n stdio: 'inherit',\n }).status;\n }\n\n protected git(args: string[], cwd: string, failure: string): string {\n return this.gitExec.gitQuery(args, cwd, failure);\n }\n\n // Seam: overridden in specs. EOF resolves to '' and therefore fails closed.\n protected question(prompt: string): Promise<string> {\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout });\n return new Promise<string>((resolve: (value: string) => void): void => {\n let answered = false;\n rl.question(prompt, (answer: string): void => {\n answered = true;\n rl.close();\n resolve(answer);\n });\n rl.on('close', (): void => {\n if (!answered) resolve('');\n });\n });\n }\n}\n"]}
@@ -16,6 +16,7 @@ import { WriteReviewFixesCommand, WriteReviewFixesOptions } from './commands/wri
16
16
  import { AwaitChecksCommand, AwaitChecksOptions } from './commands/await-checks-command';
17
17
  import { PushDevCommand, PushDevOptions } from './commands/push-dev-command';
18
18
  import { FinishPushDevCommand, FinishPushDevOptions } from './commands/finish-push-dev-command';
19
+ import { HumanPostPrCommand } from './commands/human-post-pr-command';
19
20
  import { PushDevStateStore } from './workflow/push-dev-state';
20
21
  import { RepoRootFinder } from '@webpieces/rules-config';
21
22
  /**
@@ -42,9 +43,10 @@ export declare class PrGateApp {
42
43
  private readonly awaitChecksCommand;
43
44
  private readonly pushDevCommand;
44
45
  private readonly finishPushDevCommand;
46
+ private readonly humanPostPrCommand;
45
47
  private readonly pushDevStateStore;
46
48
  private readonly repoRootFinder;
47
- constructor(startUpdateCommand: StartUpdateCommand, finishUpdateCommand: FinishUpdateCommand, startUpsertPrCommand: StartUpsertPrCommand, finishUpsertPrCommand: FinishUpsertPrCommand, cleanupCommand: CleanupCommand, syncMainCommand: SyncMainCommand, landPrCommand: LandPrCommand, checkPrCommand: CheckPrCommand, reviewUpsertPrCommand: ReviewUpsertPrCommand, reapWorktreeCommand: ReapWorktreeCommand, buildCommand: BuildCommand, awaitReviewsCommand: AwaitReviewsCommand, writeReviewCommand: WriteReviewCommand, writeReviewFixesCommand: WriteReviewFixesCommand, awaitChecksCommand: AwaitChecksCommand, pushDevCommand: PushDevCommand, finishPushDevCommand: FinishPushDevCommand, pushDevStateStore: PushDevStateStore, repoRootFinder: RepoRootFinder);
49
+ constructor(startUpdateCommand: StartUpdateCommand, finishUpdateCommand: FinishUpdateCommand, startUpsertPrCommand: StartUpsertPrCommand, finishUpsertPrCommand: FinishUpsertPrCommand, cleanupCommand: CleanupCommand, syncMainCommand: SyncMainCommand, landPrCommand: LandPrCommand, checkPrCommand: CheckPrCommand, reviewUpsertPrCommand: ReviewUpsertPrCommand, reapWorktreeCommand: ReapWorktreeCommand, buildCommand: BuildCommand, awaitReviewsCommand: AwaitReviewsCommand, writeReviewCommand: WriteReviewCommand, writeReviewFixesCommand: WriteReviewFixesCommand, awaitChecksCommand: AwaitChecksCommand, pushDevCommand: PushDevCommand, finishPushDevCommand: FinishPushDevCommand, humanPostPrCommand: HumanPostPrCommand, pushDevStateStore: PushDevStateStore, repoRootFinder: RepoRootFinder);
48
50
  /**
49
51
  * Refuse `command` while a `wp-push-dev --resolve` is half-finished.
50
52
  *
@@ -95,6 +97,8 @@ export declare class PrGateApp {
95
97
  startUpsertPr(): Promise<void>;
96
98
  /** `wp-finish-upsert-pr`: finalize merge, authoritative build gate, dashboard, create/update PR. */
97
99
  finishUpsertPr(): Promise<void>;
100
+ /** `wp-human-post-pr`: human-attested post with optional local build and no automated review. */
101
+ humanPostPr(): Promise<void>;
98
102
  /**
99
103
  * `wp-cleanup`: reap what is provably merged AND every zero-commit husk, then report the rest with
100
104
  * the exact flags that take it. `options` carries what argv said — see CleanupOptions.
@@ -21,6 +21,7 @@ const write_review_fixes_command_1 = require("./commands/write-review-fixes-comm
21
21
  const await_checks_command_1 = require("./commands/await-checks-command");
22
22
  const push_dev_command_1 = require("./commands/push-dev-command");
23
23
  const finish_push_dev_command_1 = require("./commands/finish-push-dev-command");
24
+ const human_post_pr_command_1 = require("./commands/human-post-pr-command");
24
25
  const push_dev_state_1 = require("./workflow/push-dev-state");
25
26
  const rules_config_2 = require("@webpieces/rules-config");
26
27
  /**
@@ -47,9 +48,10 @@ let PrGateApp = class PrGateApp {
47
48
  awaitChecksCommand;
48
49
  pushDevCommand;
49
50
  finishPushDevCommand;
51
+ humanPostPrCommand;
50
52
  pushDevStateStore;
51
53
  repoRootFinder;
52
- constructor(startUpdateCommand, finishUpdateCommand, startUpsertPrCommand, finishUpsertPrCommand, cleanupCommand, syncMainCommand, landPrCommand, checkPrCommand, reviewUpsertPrCommand, reapWorktreeCommand, buildCommand, awaitReviewsCommand, writeReviewCommand, writeReviewFixesCommand, awaitChecksCommand, pushDevCommand, finishPushDevCommand, pushDevStateStore, repoRootFinder) {
54
+ constructor(startUpdateCommand, finishUpdateCommand, startUpsertPrCommand, finishUpsertPrCommand, cleanupCommand, syncMainCommand, landPrCommand, checkPrCommand, reviewUpsertPrCommand, reapWorktreeCommand, buildCommand, awaitReviewsCommand, writeReviewCommand, writeReviewFixesCommand, awaitChecksCommand, pushDevCommand, finishPushDevCommand, humanPostPrCommand, pushDevStateStore, repoRootFinder) {
53
55
  this.startUpdateCommand = startUpdateCommand;
54
56
  this.finishUpdateCommand = finishUpdateCommand;
55
57
  this.startUpsertPrCommand = startUpsertPrCommand;
@@ -67,6 +69,7 @@ let PrGateApp = class PrGateApp {
67
69
  this.awaitChecksCommand = awaitChecksCommand;
68
70
  this.pushDevCommand = pushDevCommand;
69
71
  this.finishPushDevCommand = finishPushDevCommand;
72
+ this.humanPostPrCommand = humanPostPrCommand;
70
73
  this.pushDevStateStore = pushDevStateStore;
71
74
  this.repoRootFinder = repoRootFinder;
72
75
  }
@@ -152,6 +155,11 @@ let PrGateApp = class PrGateApp {
152
155
  this.assertNoResolveInProgress('wp-finish-upsert-pr');
153
156
  return this.finishUpsertPrCommand.run();
154
157
  }
158
+ /** `wp-human-post-pr`: human-attested post with optional local build and no automated review. */
159
+ humanPostPr() {
160
+ this.assertNoResolveInProgress('wp-human-post-pr');
161
+ return this.humanPostPrCommand.run();
162
+ }
155
163
  /**
156
164
  * `wp-cleanup`: reap what is provably merged AND every zero-commit husk, then report the rest with
157
165
  * the exact flags that take it. `options` carries what argv said — see CleanupOptions.
@@ -213,6 +221,7 @@ exports.PrGateApp = PrGateApp = tslib_1.__decorate([
213
221
  await_checks_command_1.AwaitChecksCommand,
214
222
  push_dev_command_1.PushDevCommand,
215
223
  finish_push_dev_command_1.FinishPushDevCommand,
224
+ human_post_pr_command_1.HumanPostPrCommand,
216
225
  push_dev_state_1.PushDevStateStore,
217
226
  rules_config_2.RepoRootFinder])
218
227
  ], PrGateApp);
@@ -1 +1 @@
1
- {"version":3,"file":"pr-gate-app.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/pr-gate-app.ts"],"names":[],"mappings":";;;;AAAA,0DAAyD;AACzD,yCAA2D;AAC3D,0EAAqE;AACrE,4EAAuE;AACvE,gFAA0E;AAC1E,kFAA4E;AAC5E,gEAA4D;AAE5D,oEAA+D;AAC/D,gEAA0E;AAC1E,kEAA6D;AAC7D,kFAAmG;AACnG,4EAAuE;AACvE,4DAAsE;AACtE,4EAAuE;AACvE,0EAAyF;AACzF,sFAAyG;AACzG,0EAAyF;AACzF,kEAA6E;AAC7E,gFAAgG;AAChG,8DAA8D;AAC9D,0DAAyD;AAEzD;;;;;GAKG;AAGI,IAAM,SAAS,GAAf,MAAM,SAAS;IAEG;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAnBrB,YACqB,kBAAsC,EACtC,mBAAwC,EACxC,oBAA0C,EAC1C,qBAA4C,EAC5C,cAA8B,EAC9B,eAAgC,EAChC,aAA4B,EAC5B,cAA8B,EAC9B,qBAA4C,EAC5C,mBAAwC,EACxC,YAA0B,EAC1B,mBAAwC,EACxC,kBAAsC,EACtC,uBAAgD,EAChD,kBAAsC,EACtC,cAA8B,EAC9B,oBAA0C,EAC1C,iBAAoC,EACpC,cAA8B;QAlB9B,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,mBAAc,GAAd,cAAc,CAAgB;QAC9B,oBAAe,GAAf,eAAe,CAAiB;QAChC,kBAAa,GAAb,aAAa,CAAe;QAC5B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,0BAAqB,GAArB,qBA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AC;QAC/C,OAAO,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAAsB;QACzB,IAAI,CAAC,yBAAyB,CAAC,YAAY,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,OAA8B,IAAI,gDAAqB,EAAE;QACpE,IAAI,CAAC,yBAAyB,CAAC,qBAAqB,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,+GAA+G;IAC/G,OAAO;QACH,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC;IACrC,CAAC;CACJ,CAAA;AAhKY,8BAAS;oBAAT,SAAS;IAFrB,IAAA,6BAAc,GAAE;IAChB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGI,yCAAkB;QACjB,2CAAmB;QAClB,8CAAoB;QACnB,gDAAqB;QAC5B,gCAAc;QACb,mCAAe;QACjB,+BAAa;QACZ,iCAAc;QACP,gDAAqB;QACvB,2CAAmB;QAC1B,4BAAY;QACL,2CAAmB;QACpB,yCAAkB;QACb,oDAAuB;QAC5B,yCAAkB;QACtB,iCAAc;QACR,8CAAoB;QACvB,kCAAiB;QACpB,6BAAc;GApB1C,SAAS,CAgKrB","sourcesContent":["import { DocumentDesign } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { StartUpdateCommand } from './commands/start-update-command';\nimport { FinishUpdateCommand } from './commands/finish-update-command';\nimport { StartUpsertPrCommand } from './commands/start-upsert-pr-command';\nimport { FinishUpsertPrCommand } from './commands/finish-upsert-pr-command';\nimport { CleanupCommand } from './commands/cleanup-command';\nimport { CleanupOptions } from './commands/cleanup-options';\nimport { SyncMainCommand } from './commands/sync-main-command';\nimport { LandPrCommand, LandPrRequest } from './commands/land-pr-command';\nimport { CheckPrCommand } from './commands/check-pr-command';\nimport { ReviewUpsertPrCommand, ReviewUpsertPrOptions } from './commands/review-upsert-pr-command';\nimport { ReapWorktreeCommand } from './commands/reap-worktree-command';\nimport { BuildCommand, BuildOptions } from './commands/build-command';\nimport { AwaitReviewsCommand } from './commands/await-reviews-command';\nimport { WriteReviewCommand, WriteReviewOptions } from './commands/write-review-command';\nimport { WriteReviewFixesCommand, WriteReviewFixesOptions } from './commands/write-review-fixes-command';\nimport { AwaitChecksCommand, AwaitChecksOptions } from './commands/await-checks-command';\nimport { PushDevCommand, PushDevOptions } from './commands/push-dev-command';\nimport { FinishPushDevCommand, FinishPushDevOptions } from './commands/finish-push-dev-command';\nimport { PushDevStateStore } from './workflow/push-dev-state';\nimport { RepoRootFinder } from '@webpieces/rules-config';\n\n/**\n * The pr-gate application root. `container.get(PrGateApp)` resolves the entire workflow DAG (the command\n * classes → the injected git/merge/dashboard services). `@DocumentDesign` marks it the\n * top-of-DAG the DI-design analyzer roots on, so `role:app` pr-gate draws its design. Each `bin/*`\n * entry resolves THIS and calls the matching command method.\n */\n@DocumentDesign()\n@injectable(bindingScopeValues.Singleton)\nexport class PrGateApp {\n constructor(\n private readonly startUpdateCommand: StartUpdateCommand,\n private readonly finishUpdateCommand: FinishUpdateCommand,\n private readonly startUpsertPrCommand: StartUpsertPrCommand,\n private readonly finishUpsertPrCommand: FinishUpsertPrCommand,\n private readonly cleanupCommand: CleanupCommand,\n private readonly syncMainCommand: SyncMainCommand,\n private readonly landPrCommand: LandPrCommand,\n private readonly checkPrCommand: CheckPrCommand,\n private readonly reviewUpsertPrCommand: ReviewUpsertPrCommand,\n private readonly reapWorktreeCommand: ReapWorktreeCommand,\n private readonly buildCommand: BuildCommand,\n private readonly awaitReviewsCommand: AwaitReviewsCommand,\n private readonly writeReviewCommand: WriteReviewCommand,\n private readonly writeReviewFixesCommand: WriteReviewFixesCommand,\n private readonly awaitChecksCommand: AwaitChecksCommand,\n private readonly pushDevCommand: PushDevCommand,\n private readonly finishPushDevCommand: FinishPushDevCommand,\n private readonly pushDevStateStore: PushDevStateStore,\n private readonly repoRootFinder: RepoRootFinder,\n ) {}\n\n /**\n * Refuse `command` while a `wp-push-dev --resolve` is half-finished.\n *\n * Enforced HERE, at the one place every bin funnels through, rather than in each command: a resolve\n * parks the checkout on a throwaway branch, so every command below would act on a branch that is not\n * the one it thinks it is. Putting the check in nine constructors is nine chances to forget it in the\n * tenth. PushDevStateStore owns the blocked list AND renders the hint from it, so the two cannot drift.\n */\n private assertNoResolveInProgress(command: string): void {\n if (!this.pushDevStateStore.isBlockedDuringResolve(command)) return;\n this.pushDevStateStore.assertIdle(this.repoRootFinder.resolveRepoRoot(process.cwd()), command);\n }\n\n /** `wp-push-dev`: publish a DISPOSABLE copy of this branch for the shared dev environment. No PR, no build. */\n pushDev(opts: PushDevOptions = new PushDevOptions()): Promise<void> {\n return this.pushDevCommand.run(opts);\n }\n\n /** `wp-finish-push-dev`: commit a resolved dev composition and publish it (conflict path only). */\n finishPushDev(opts: FinishPushDevOptions = new FinishPushDevOptions()): Promise<void> {\n return this.finishPushDevCommand.run(opts);\n }\n\n /**\n * INTERNAL (`wp-reap-worktree.js`, no `bin` entry): remove ONE named worktree and its branch.\n * `wp-land-pr` spawns it with cwd = the primary clone so the tree it just landed from can be\n * reaped by a process that is not standing in it.\n */\n reapWorktree(args: string[]): Promise<void> {\n return this.reapWorktreeCommand.run(args);\n }\n\n /**\n * `wp-build`: run this repo's ONE configured build (`commands.pr-gate.buildCommand`) — the same\n * command, resolved by the same resolver, that the PR gate's build stage runs. Not blocked during a\n * `wp-push-dev --resolve`: it mutates nothing and reads no branch state.\n */\n build(opts: BuildOptions): Promise<void> {\n return this.buildCommand.run(opts);\n }\n\n /**\n * `wp-await-reviews`: BLOCK until every reviewer verdict this branch owes has landed, then print\n * them. Not blocked during a `wp-push-dev --resolve`: it reads verdict files and mutates nothing.\n */\n awaitReviews(): Promise<void> {\n return this.awaitReviewsCommand.run();\n }\n\n /**\n * `wp-write-review`: a reviewer subagent submits ONE checklist verdict, with provenance (issue #863).\n * Not blocked during a `wp-push-dev --resolve`: it writes only this branch's review state.\n */\n writeReview(opts: WriteReviewOptions): Promise<void> {\n return this.writeReviewCommand.run(opts);\n }\n\n /** `wp-write-review-fixes`: the coordinator records committed fixes without editing a reviewer verdict. */\n writeReviewFixes(opts: WriteReviewFixesOptions): Promise<void> {\n return this.writeReviewFixesCommand.run(opts);\n }\n\n /**\n * `wp-await-checks --pr <n>`: BLOCK until that PR's checks stop running, then print where they\n * landed. Read-only against GitHub, so it too is allowed during a resolve.\n */\n awaitChecks(opts: AwaitChecksOptions): Promise<void> {\n return this.awaitChecksCommand.run(opts);\n }\n\n /** `wp-start-update`: 3-point squash-update from main (no PR). */\n startUpdate(): Promise<void> {\n this.assertNoResolveInProgress('wp-start-update');\n return this.startUpdateCommand.run();\n }\n\n /** `wp-finish-update`: validate + finalize a resolved 3-point merge (no PR). */\n finishUpdate(): Promise<void> {\n this.assertNoResolveInProgress('wp-finish-update');\n return this.finishUpdateCommand.run();\n }\n\n /** `wp-start-upsert-pr`: update from main (3-point merge), hand off summary.json. No build gate, no push. */\n startUpsertPr(): Promise<void> {\n this.assertNoResolveInProgress('wp-start-upsert-pr');\n return this.startUpsertPrCommand.run();\n }\n\n /** `wp-finish-upsert-pr`: finalize merge, authoritative build gate, dashboard, create/update PR. */\n finishUpsertPr(): Promise<void> {\n this.assertNoResolveInProgress('wp-finish-upsert-pr');\n return this.finishUpsertPrCommand.run();\n }\n\n /**\n * `wp-cleanup`: reap what is provably merged AND every zero-commit husk, then report the rest with\n * the exact flags that take it. `options` carries what argv said — see CleanupOptions.\n */\n cleanup(options: CleanupOptions): Promise<void> {\n this.assertNoResolveInProgress('wp-cleanup');\n return this.cleanupCommand.run(options);\n }\n\n /**\n * `wp-sync-main`: go to main, fast-forward it, reap dead worktrees and branches, and sweep\n * the orphan directories a project move leaves behind. Replaces `git checkout main && git pull\n * origin main` outright — see SyncMainCommand for why the old pair must stop being accepted\n * rather than surviving beside this.\n */\n syncMain(): Promise<void> {\n this.assertNoResolveInProgress('wp-sync-main');\n return this.syncMainCommand.run();\n }\n\n /**\n * `wp-land-pr`: squash-merge a PR into main with the compact commit body — this branch's by default,\n * or the one `--pr <n>` names, which is how a coordinator finishes a gone agent's work.\n */\n landPr(request: LandPrRequest): Promise<void> {\n this.assertNoResolveInProgress('wp-land-pr');\n return this.landPrCommand.run(request);\n }\n\n /**\n * `wp-review-upsert-pr`: STAGE ② — validate the 3-point merge, run the build gate, extract this\n * branch's diff, and brief the reviewer subagents. Unlike the report-only command it replaces, this CAN\n * fail — before any reviewer is spawned, so a broken branch costs no reviewer tokens.\n */\n reviewUpsertPr(opts: ReviewUpsertPrOptions = new ReviewUpsertPrOptions()): Promise<void> {\n this.assertNoResolveInProgress('wp-review-upsert-pr');\n return this.reviewUpsertPrCommand.run(opts);\n }\n\n /** `wp-check-pr`: READ-ONLY CI check — verify the PR body carries a valid HMAC gate token for its head sha. */\n checkPr(): Promise<void> {\n return this.checkPrCommand.run();\n }\n}\n"]}
1
+ {"version":3,"file":"pr-gate-app.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/pr-gate-app.ts"],"names":[],"mappings":";;;;AAAA,0DAAyD;AACzD,yCAA2D;AAC3D,0EAAqE;AACrE,4EAAuE;AACvE,gFAA0E;AAC1E,kFAA4E;AAC5E,gEAA4D;AAE5D,oEAA+D;AAC/D,gEAA0E;AAC1E,kEAA6D;AAC7D,kFAAmG;AACnG,4EAAuE;AACvE,4DAAsE;AACtE,4EAAuE;AACvE,0EAAyF;AACzF,sFAAyG;AACzG,0EAAyF;AACzF,kEAA6E;AAC7E,gFAAgG;AAChG,4EAAsE;AACtE,8DAA8D;AAC9D,0DAAyD;AAEzD;;;;;GAKG;AAGI,IAAM,SAAS,GAAf,MAAM,SAAS;IAEG;IACA;IACA;IACA;I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,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,+GAA+G;IAC/G,OAAO;QACH,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC;IACrC,CAAC;CACJ,CAAA;AA1KY,8BAAS;oBAAT,SAAS;IAFrB,IAAA,6BAAc,GAAE;IAChB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGI,yCAAkB;QACjB,2CAAmB;QAClB,8CAAoB;QACnB,gDAAqB;QAC5B,gCAAc;QACb,mCAAe;QACjB,+BAAa;QACZ,iCAAc;QACP,gDAAqB;QACvB,2CAAmB;QAC1B,4BAAY;QACL,2CAAmB;QACpB,yCAAkB;QACb,oDAAuB;QAC5B,yCAAkB;QACtB,iCAAc;QACR,8CAAoB;QACtB,0CAAkB;QACnB,kCAAiB;QACpB,6BAAc;GArB1C,SAAS,CA0KrB","sourcesContent":["import { DocumentDesign } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { StartUpdateCommand } from './commands/start-update-command';\nimport { FinishUpdateCommand } from './commands/finish-update-command';\nimport { StartUpsertPrCommand } from './commands/start-upsert-pr-command';\nimport { FinishUpsertPrCommand } from './commands/finish-upsert-pr-command';\nimport { CleanupCommand } from './commands/cleanup-command';\nimport { CleanupOptions } from './commands/cleanup-options';\nimport { SyncMainCommand } from './commands/sync-main-command';\nimport { LandPrCommand, LandPrRequest } from './commands/land-pr-command';\nimport { CheckPrCommand } from './commands/check-pr-command';\nimport { ReviewUpsertPrCommand, ReviewUpsertPrOptions } from './commands/review-upsert-pr-command';\nimport { ReapWorktreeCommand } from './commands/reap-worktree-command';\nimport { BuildCommand, BuildOptions } from './commands/build-command';\nimport { AwaitReviewsCommand } from './commands/await-reviews-command';\nimport { WriteReviewCommand, WriteReviewOptions } from './commands/write-review-command';\nimport { WriteReviewFixesCommand, WriteReviewFixesOptions } from './commands/write-review-fixes-command';\nimport { AwaitChecksCommand, AwaitChecksOptions } from './commands/await-checks-command';\nimport { PushDevCommand, PushDevOptions } from './commands/push-dev-command';\nimport { FinishPushDevCommand, FinishPushDevOptions } from './commands/finish-push-dev-command';\nimport { HumanPostPrCommand } from './commands/human-post-pr-command';\nimport { PushDevStateStore } from './workflow/push-dev-state';\nimport { RepoRootFinder } from '@webpieces/rules-config';\n\n/**\n * The pr-gate application root. `container.get(PrGateApp)` resolves the entire workflow DAG (the command\n * classes → the injected git/merge/dashboard services). `@DocumentDesign` marks it the\n * top-of-DAG the DI-design analyzer roots on, so `role:app` pr-gate draws its design. Each `bin/*`\n * entry resolves THIS and calls the matching command method.\n */\n@DocumentDesign()\n@injectable(bindingScopeValues.Singleton)\nexport class PrGateApp {\n constructor(\n private readonly startUpdateCommand: StartUpdateCommand,\n private readonly finishUpdateCommand: FinishUpdateCommand,\n private readonly startUpsertPrCommand: StartUpsertPrCommand,\n private readonly finishUpsertPrCommand: FinishUpsertPrCommand,\n private readonly cleanupCommand: CleanupCommand,\n private readonly syncMainCommand: SyncMainCommand,\n private readonly landPrCommand: LandPrCommand,\n private readonly checkPrCommand: CheckPrCommand,\n private readonly reviewUpsertPrCommand: ReviewUpsertPrCommand,\n private readonly reapWorktreeCommand: ReapWorktreeCommand,\n private readonly buildCommand: BuildCommand,\n private readonly awaitReviewsCommand: AwaitReviewsCommand,\n private readonly writeReviewCommand: WriteReviewCommand,\n private readonly writeReviewFixesCommand: WriteReviewFixesCommand,\n private readonly awaitChecksCommand: AwaitChecksCommand,\n private readonly pushDevCommand: PushDevCommand,\n private readonly finishPushDevCommand: FinishPushDevCommand,\n private readonly humanPostPrCommand: HumanPostPrCommand,\n private readonly pushDevStateStore: PushDevStateStore,\n private readonly repoRootFinder: RepoRootFinder,\n ) {}\n\n /**\n * Refuse `command` while a `wp-push-dev --resolve` is half-finished.\n *\n * Enforced HERE, at the one place every bin funnels through, rather than in each command: a resolve\n * parks the checkout on a throwaway branch, so every command below would act on a branch that is not\n * the one it thinks it is. Putting the check in nine constructors is nine chances to forget it in the\n * tenth. PushDevStateStore owns the blocked list AND renders the hint from it, so the two cannot drift.\n */\n private assertNoResolveInProgress(command: string): void {\n if (!this.pushDevStateStore.isBlockedDuringResolve(command)) return;\n this.pushDevStateStore.assertIdle(\n this.repoRootFinder.resolveRepoRoot(process.cwd()),\n command,\n );\n }\n\n /** `wp-push-dev`: publish a DISPOSABLE copy of this branch for the shared dev environment. No PR, no build. */\n pushDev(opts: PushDevOptions = new PushDevOptions()): Promise<void> {\n return this.pushDevCommand.run(opts);\n }\n\n /** `wp-finish-push-dev`: commit a resolved dev composition and publish it (conflict path only). */\n finishPushDev(opts: FinishPushDevOptions = new FinishPushDevOptions()): Promise<void> {\n return this.finishPushDevCommand.run(opts);\n }\n\n /**\n * INTERNAL (`wp-reap-worktree.js`, no `bin` entry): remove ONE named worktree and its branch.\n * `wp-land-pr` spawns it with cwd = the primary clone so the tree it just landed from can be\n * reaped by a process that is not standing in it.\n */\n reapWorktree(args: string[]): Promise<void> {\n return this.reapWorktreeCommand.run(args);\n }\n\n /**\n * `wp-build`: run this repo's ONE configured build (`commands.pr-gate.buildCommand`) — the same\n * command, resolved by the same resolver, that the PR gate's build stage runs. Not blocked during a\n * `wp-push-dev --resolve`: it mutates nothing and reads no branch state.\n */\n build(opts: BuildOptions): Promise<void> {\n return this.buildCommand.run(opts);\n }\n\n /**\n * `wp-await-reviews`: BLOCK until every reviewer verdict this branch owes has landed, then print\n * them. Not blocked during a `wp-push-dev --resolve`: it reads verdict files and mutates nothing.\n */\n awaitReviews(): Promise<void> {\n return this.awaitReviewsCommand.run();\n }\n\n /**\n * `wp-write-review`: a reviewer subagent submits ONE checklist verdict, with provenance (issue #863).\n * Not blocked during a `wp-push-dev --resolve`: it writes only this branch's review state.\n */\n writeReview(opts: WriteReviewOptions): Promise<void> {\n return this.writeReviewCommand.run(opts);\n }\n\n /** `wp-write-review-fixes`: the coordinator records committed fixes without editing a reviewer verdict. */\n writeReviewFixes(opts: WriteReviewFixesOptions): Promise<void> {\n return this.writeReviewFixesCommand.run(opts);\n }\n\n /**\n * `wp-await-checks --pr <n>`: BLOCK until that PR's checks stop running, then print where they\n * landed. Read-only against GitHub, so it too is allowed during a resolve.\n */\n awaitChecks(opts: AwaitChecksOptions): Promise<void> {\n return this.awaitChecksCommand.run(opts);\n }\n\n /** `wp-start-update`: 3-point squash-update from main (no PR). */\n startUpdate(): Promise<void> {\n this.assertNoResolveInProgress('wp-start-update');\n return this.startUpdateCommand.run();\n }\n\n /** `wp-finish-update`: validate + finalize a resolved 3-point merge (no PR). */\n finishUpdate(): Promise<void> {\n this.assertNoResolveInProgress('wp-finish-update');\n return this.finishUpdateCommand.run();\n }\n\n /** `wp-start-upsert-pr`: update from main (3-point merge), hand off summary.json. No build gate, no push. */\n startUpsertPr(): Promise<void> {\n this.assertNoResolveInProgress('wp-start-upsert-pr');\n return this.startUpsertPrCommand.run();\n }\n\n /** `wp-finish-upsert-pr`: finalize merge, authoritative build gate, dashboard, create/update PR. */\n finishUpsertPr(): Promise<void> {\n this.assertNoResolveInProgress('wp-finish-upsert-pr');\n return this.finishUpsertPrCommand.run();\n }\n\n /** `wp-human-post-pr`: human-attested post with optional local build and no automated review. */\n humanPostPr(): Promise<void> {\n this.assertNoResolveInProgress('wp-human-post-pr');\n return this.humanPostPrCommand.run();\n }\n\n /**\n * `wp-cleanup`: reap what is provably merged AND every zero-commit husk, then report the rest with\n * the exact flags that take it. `options` carries what argv said — see CleanupOptions.\n */\n cleanup(options: CleanupOptions): Promise<void> {\n this.assertNoResolveInProgress('wp-cleanup');\n return this.cleanupCommand.run(options);\n }\n\n /**\n * `wp-sync-main`: go to main, fast-forward it, reap dead worktrees and branches, and sweep\n * the orphan directories a project move leaves behind. Replaces `git checkout main && git pull\n * origin main` outright — see SyncMainCommand for why the old pair must stop being accepted\n * rather than surviving beside this.\n */\n syncMain(): Promise<void> {\n this.assertNoResolveInProgress('wp-sync-main');\n return this.syncMainCommand.run();\n }\n\n /**\n * `wp-land-pr`: squash-merge a PR into main with the compact commit body — this branch's by default,\n * or the one `--pr <n>` names, which is how a coordinator finishes a gone agent's work.\n */\n landPr(request: LandPrRequest): Promise<void> {\n this.assertNoResolveInProgress('wp-land-pr');\n return this.landPrCommand.run(request);\n }\n\n /**\n * `wp-review-upsert-pr`: STAGE ② — validate the 3-point merge, run the build gate, extract this\n * branch's diff, and brief the reviewer subagents. Unlike the report-only command it replaces, this CAN\n * fail — before any reviewer is spawned, so a broken branch costs no reviewer tokens.\n */\n reviewUpsertPr(opts: ReviewUpsertPrOptions = new ReviewUpsertPrOptions()): Promise<void> {\n this.assertNoResolveInProgress('wp-review-upsert-pr');\n return this.reviewUpsertPrCommand.run(opts);\n }\n\n /** `wp-check-pr`: READ-ONLY CI check — verify the PR body carries a valid HMAC gate token for its head sha. */\n checkPr(): Promise<void> {\n return this.checkPrCommand.run();\n }\n}\n"]}
@@ -41,6 +41,9 @@ export declare class BuildAffected {
41
41
  * because a log file was busy.
42
42
  */
43
43
  runBuildGate(repoRoot: string, opts: BuildGateOptions): Promise<void>;
44
+ /** The human escape hatch uses the same gate but follows build.log on the terminal while it runs. */
45
+ runBuildGateStreaming(repoRoot: string, opts: BuildGateOptions): Promise<void>;
46
+ private run;
44
47
  /**
45
48
  * The failure text: this gate's own headline, then the pointer at the log the build already wrote.
46
49
  *
@@ -52,7 +52,9 @@ let BuildAffected = class BuildAffected {
52
52
  if (this.branchIdentity.isHotfix())
53
53
  return rules_config_1.HOTFIX_BUILD_COMMAND;
54
54
  const configured = (0, rules_config_1.loadAndValidate)(repoRoot).prGate.buildCommand;
55
- return configured !== undefined && configured.trim() !== '' ? configured : rules_config_1.DEFAULT_BUILD_COMMAND;
55
+ return configured !== undefined && configured.trim() !== ''
56
+ ? configured
57
+ : rules_config_1.DEFAULT_BUILD_COMMAND;
56
58
  }
57
59
  /**
58
60
  * Run the configured build gate with consistent framing, throwing CliExitError(buildCode) on
@@ -70,6 +72,13 @@ let BuildAffected = class BuildAffected {
70
72
  * because a log file was busy.
71
73
  */
72
74
  async runBuildGate(repoRoot, opts) {
75
+ return this.run(repoRoot, opts, false);
76
+ }
77
+ /** The human escape hatch uses the same gate but follows build.log on the terminal while it runs. */
78
+ async runBuildGateStreaming(repoRoot, opts) {
79
+ return this.run(repoRoot, opts, true);
80
+ }
81
+ async run(repoRoot, opts, stream) {
73
82
  const buildCommand = this.resolveBuildCommand(repoRoot);
74
83
  // TWO lines on the happy path — the command, then the result. The old framing spent a banner and a
75
84
  // paragraph explaining how to reproduce a build that was about to pass anyway; that explanation is
@@ -86,7 +95,9 @@ let BuildAffected = class BuildAffected {
86
95
  // build passed, failed, or the spawn itself blew up; the throw is re-raised untouched below
87
96
  // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
88
97
  try {
89
- termination = await this.buildLog.run(repoRoot, buildCommand, logPath);
98
+ termination = stream
99
+ ? await this.buildLog.runStreaming(repoRoot, buildCommand, logPath)
100
+ : await this.buildLog.run(repoRoot, buildCommand, logPath);
90
101
  }
91
102
  finally {
92
103
  this.buildsLog.finish(ticket, termination);
@@ -106,7 +117,9 @@ let BuildAffected = class BuildAffected {
106
117
  * expensive thing an agent can be told. Reading a FILE is now the only answer this gate gives.
107
118
  */
108
119
  failureText(opts, buildCommand, logPath, termination) {
109
- return `\n❌ ${opts.failureHeadline}\n` + this.buildLog.failureMessage(buildCommand, logPath, termination) + `Fix what that log shows, then re-run ${opts.rerunCommand}.\n`;
120
+ return (`\n❌ ${opts.failureHeadline}\n` +
121
+ this.buildLog.failureMessage(buildCommand, logPath, termination) +
122
+ `Fix what that log shows, then re-run ${opts.rerunCommand}.\n`);
110
123
  }
111
124
  };
112
125
  exports.BuildAffected = BuildAffected;
@@ -1 +1 @@
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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cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IACjE,CAAC;IAED;;;;;;;OAOG;IACK,WAAW,CAAC,IAAsB,EAAE,YAAoB,EAAE,OAAe,EAAE,WAA6B;QAC5G,OAAO,OAAO,IAAI,CAAC,eAAe,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,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"]}
1
+ {"version":3,"file":"build-affected.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-affected.ts"],"names":[],"mappings":";;;;AAAA,0DAQiC;AACjC,yCAA2D;AAC3D,qDAAgD;AAChD,yDAAoD;AAEpD,iGAAiG;AACjG,8FAA8F;AAC9F,iGAAiG;AACjG,oFAAoF;AACpF,oGAAoG;AACpG,iEAAi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W,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;QACpF,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;YAClB,MAAM,IAAI,2BAAY,CAClB,SAAS,EACT,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,CAAC,CAC7D,CAAC;QACN,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IACjE,CAAC;IAED;;;;;;;OAOG;IACK,WAAW,CACf,IAAsB,EACtB,YAAoB,EACpB,OAAe,EACf,WAA6B;QAE7B,OAAO,CACH,OAAO,IAAI,CAAC,eAAe,IAAI;YAC/B,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EAAE,OAAO,EAAE,WAAW,CAAC;YAChE,wCAAwC,IAAI,CAAC,YAAY,KAAK,CACjE,CAAC;IACN,CAAC;CACJ,CAAA;AAlGY,sCAAa;wBAAb,aAAa;IADzB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGN,6BAAY;QACX,wBAAS;QACN,iCAAc;QACZ,6BAAc;GAL1C,aAAa,CAkGzB","sourcesContent":["import {\n loadAndValidate,\n CliExitError,\n DEFAULT_BUILD_COMMAND,\n BuildsLog,\n BuildTermination,\n BranchIdentity,\n HOTFIX_BUILD_COMMAND,\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 * 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() !== ''\n ? configured\n : 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 return this.run(repoRoot, opts, false);\n }\n\n /** The human escape hatch uses the same gate but follows build.log on the terminal while it runs. */\n async runBuildGateStreaming(repoRoot: string, opts: BuildGateOptions): Promise<void> {\n return this.run(repoRoot, opts, true);\n }\n\n private async run(repoRoot: string, opts: BuildGateOptions, stream: boolean): 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 = stream\n ? await this.buildLog.runStreaming(repoRoot, buildCommand, logPath)\n : await this.buildLog.run(repoRoot, buildCommand, logPath);\n } finally {\n this.buildsLog.finish(ticket, termination);\n }\n const buildCode =\n termination.code === null || termination.signal !== null ? 1 : termination.code;\n if (buildCode !== 0) {\n throw new CliExitError(\n buildCode,\n this.failureText(opts, buildCommand, logPath, termination),\n );\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,\n buildCommand: string,\n logPath: string,\n termination: BuildTermination,\n ): string {\n return (\n `\\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}\n"]}
@@ -67,9 +67,12 @@ export declare class BuildGateLog {
67
67
  /**
68
68
  * Run `buildCommand` with its stdout AND stderr redirected in full to `logPath`, printing a heartbeat
69
69
  * every HEARTBEAT_MS so the caller can see it is alive. Returns the BUILD's raw termination facts.
70
- * Nothing is truncated and nothing is streamed.
70
+ * Nothing is truncated. Ordinary AI-facing callers do not stream; the explicitly human-attested
71
+ * PR escape hatch may wrap this with runStreaming(), which follows the same durable file live.
71
72
  */
72
73
  run(repoRoot: string, buildCommand: string, logPath: string): Promise<BuildTermination>;
74
+ /** Human-only variant: preserve the durable log and follow its appended bytes live. */
75
+ runStreaming(repoRoot: string, buildCommand: string, logPath: string): Promise<BuildTermination>;
73
76
  /**
74
77
  * The success summary: the caller is told WHERE the full output is, not handed the output.
75
78
  */