@webpieces/pr-gate 0.4.976 → 0.4.977

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 (29) hide show
  1. package/package.json +6 -6
  2. package/src/scripts/commands/cleanup-command.js +12 -12
  3. package/src/scripts/commands/cleanup-command.js.map +1 -1
  4. package/src/scripts/commands/human-post-pr-command.js +1 -1
  5. package/src/scripts/commands/human-post-pr-command.js.map +1 -1
  6. package/src/scripts/commands/land-pr-command.js +1 -1
  7. package/src/scripts/commands/land-pr-command.js.map +1 -1
  8. package/src/scripts/commands/reap-worktree-command.js +4 -5
  9. package/src/scripts/commands/reap-worktree-command.js.map +1 -1
  10. package/src/scripts/commands/review-upsert-pr-command.js +1 -1
  11. package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
  12. package/src/scripts/commands/start-upsert-pr-command.js +1 -1
  13. package/src/scripts/commands/start-upsert-pr-command.js.map +1 -1
  14. package/src/scripts/commands/sync-main-command.js +4 -4
  15. package/src/scripts/commands/sync-main-command.js.map +1 -1
  16. package/src/scripts/commands/worktree-cleanup.d.ts +4 -4
  17. package/src/scripts/commands/worktree-cleanup.js +4 -4
  18. package/src/scripts/commands/worktree-cleanup.js.map +1 -1
  19. package/src/scripts/workflow/checklist-detector.d.ts +2 -2
  20. package/src/scripts/workflow/checklist-detector.js +4 -4
  21. package/src/scripts/workflow/checklist-detector.js.map +1 -1
  22. package/src/scripts/workflow/checklist-scanner.js +3 -3
  23. package/src/scripts/workflow/checklist-scanner.js.map +1 -1
  24. package/src/scripts/workflow/merge-end.d.ts +3 -2
  25. package/src/scripts/workflow/merge-end.js +6 -3
  26. package/src/scripts/workflow/merge-end.js.map +1 -1
  27. package/src/scripts/workflow/pr-context-writer.d.ts +1 -1
  28. package/src/scripts/workflow/pr-context-writer.js +3 -3
  29. package/src/scripts/workflow/pr-context-writer.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"merge-end.js","sourceRoot":"","sources":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5F,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;QACpC,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAClE,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,gDAAgD,CAAC;QACrH,MAAM,KAAK,GAAG,UAAU;YACpB,CAAC,CAAC,sCAAsC,YAAY,YAAY,UAAU,GAAG;YAC7E,CAAC,CAAC,sCAAsC,YAAY,+CAA+C,CAAC;QACxG,MAAM,OAAO,GAAG,UAAU;YACtB,CAAC,CAAC,oDAAoD,OAAO,cAAc;gBACzE,gGAAgG;gBAChG,0DAA0D,YAAY,MAAM;YAC9E,CAAC,CAAC,IAAI,CAAC;QACX,OAAO,CAAC,MAAM,CAAC,KAAK,CAChB,IAAI,GAAG,GAAG,GAAG,gDAAgD,GAAG,GAAG,GAAG,IAAI;YAC1E,SAAS,KAAK,IAAI;YAClB,4BAA4B;YAC5B,2CAA2C;YAC3C,SAAS,UAAU,MAAM;YACzB,OAAO,CACV,CAAC;IACN,CAAC;CACJ,CAAA;AArMY,4BAAQ;mBAAR,QAAQ;IADpB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGF,4BAAY;QACT,mBAAQ;QAChB,kBAAO;QACJ,wBAAU;GALlC,QAAQ,CAqMpB","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { MERGE_EXPLANATION_FILE, CliExitError } from '@webpieces/rules-config';\nimport { stampCleanMainSyncStatus, MutationVerb, BranchMutationEvent, logBranchMutation } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { BranchNaming } from './branch-naming';\nimport { CleanTmp } from './cleanTmp';\nimport { GitExec } from './git-exec';\nimport { MergeContext } from './merge-start';\nimport { MergeState } from './merge-state';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// What finalizing actually did, for the recap. Data-only. `pushed` and `pushDeferred` are distinct on\n// purpose: \"we chose not to push yet\" must not be reported like \"there was no remote to push to\".\nclass SyncRecap {\n pushed: boolean;\n pushDeferred: boolean;\n hadConflict: boolean;\n backupKept: boolean;\n\n constructor(pushed: boolean, pushDeferred: boolean, hadConflict: boolean, backupKept: boolean) {\n this.pushed = pushed;\n this.pushDeferred = pushDeferred;\n this.hadConflict = hadConflict;\n this.backupKept = backupKept;\n }\n}\n\n// How a merge should be finalized. Data-only (per CLAUDE.md, classes for data) — bundled rather than\n// added as more positional params, which mergeEnd already has enough of.\nexport class MergeEndOptions {\n // Non-null means the AI resolved a conflict and it must be validated + committed before finalizing.\n // Null means merge-START already committed a clean merge, so finalize only.\n conflictedFiles: string[] | null;\n\n /**\n * Whether finalizing may push the squashed branch to origin.\n *\n * FALSE for the PR flow (`wp-start-upsert-pr` / `wp-finish-upsert-pr`), which pushes EXACTLY ONCE,\n * from GatedPrPublisher, after summary.json + every BLOCK checklist + the authoritative build gate\n * have passed and the gated PR body is already up. Code must not reach the remote ahead of its\n * review, and an early push here is also what fires `pull_request:synchronize` against a PR body\n * still carrying the previous run's gate token — the flap the whole gate redesign is removing.\n *\n * TRUE for the update-only flow (`wp-start-update` / `wp-finish-update`), which has no later push;\n * finalizing IS the end of that flow, so not pushing would silently strand the rewrite locally.\n */\n pushRemote: boolean;\n\n constructor(conflictedFiles: string[] | null, pushRemote: boolean) {\n this.conflictedFiles = conflictedFiles;\n this.pushRemote = pushRemote;\n }\n}\n\n// merge-END: the second half of the 3-point squash-merge lifecycle, symmetric with merge-START. Given\n// the branch context, it (optionally) validates + commits the AI's conflict resolution, then ALWAYS\n// finalizes — force-pushes `<branch>Squash` to the stable feature branch and renames it BACK to that\n// same feature name (local == remote == PR head), stamps a clean main-sync status, clears the marker,\n// and sweeps stale tmp. RunUpdate (clean path / validated resume), wp-finish-update, and\n// wp-finish-upsert-pr (conflict resolution) all call THIS, so finalization happens in exactly one place.\n@injectable(bindingScopeValues.Singleton)\nexport class MergeEnd {\n constructor(\n private readonly branchNaming: BranchNaming,\n private readonly cleanTmpService: CleanTmp,\n private readonly gitExec: GitExec,\n private readonly mergeState: MergeState,\n ) {}\n\n /**\n * Complete a 3-point squash merge. See {@link MergeEndOptions} for what `conflictedFiles` and\n * `pushRemote` mean. Either way the merge ends fully finalized on the feature branch.\n */\n async mergeEnd(\n repoRoot: string, verb: MutationVerb, mergeDir: string, ctx: MergeContext, options: MergeEndOptions,\n ): Promise<void> {\n const conflictedFiles = options.conflictedFiles;\n if (conflictedFiles !== null) {\n process.stdout.write('\\n' + SEP + '🔎 Validating Merge Resolution\\n' + SEP + '\\n');\n await this.validateResolution(repoRoot, verb, mergeDir, conflictedFiles);\n // Stage the AI's resolved conflicts, but NEVER sweep untracked files into the squash commit.\n // Fail on untracked so the AI commits or deletes them explicitly; then `git add -u` stages\n // tracked resolutions only.\n await this.gitExec.assertNoUntracked(repoRoot);\n await this.gitExec.runGitChecked(['add', '-u'], 'Failed to stage resolved files');\n\n const nothingStaged = (await this.gitExec.tryGit(['diff-index', '--quiet', '--cached', 'HEAD', '--'], process.cwd())).ok;\n if (!nothingStaged) {\n await this.gitExec.runGitChecked(\n ['commit', '-m', `Squash merge of ${ctx.currentBranch} (conflicts resolved)`],\n 'Failed to commit resolved merge',\n );\n }\n fs.writeFileSync(path.join(mergeDir, 'conflicts-resolved'), '');\n process.stdout.write('\\n✅ Merge validated and committed.\\n');\n }\n\n // A marker in THIS run dir means the sync hit conflicts (marker is written only on hand-back).\n // Read it BEFORE clearMergeMarker so finalize knows whether to keep the pre-merge snapshot.\n const hadConflict = this.mergeState.readMergeMarker(mergeDir) !== null;\n await this.finalizeBranch(repoRoot, verb, ctx, hadConflict, options.pushRemote);\n this.mergeState.clearMergeMarker(mergeDir);\n await this.cleanTmpService.cleanTmp();\n }\n\n // Validate the AI's resolution of the conflicted files. Throws CliExitError with a fix instruction\n // on any failure; returns only when all three checks pass.\n // `verb` is the bin the AI actually ran (wp-finish-update or wp-finish-upsert-pr) — every \"re-run\"\n // instruction below is rendered from it. It used to be hardcoded to wp-finish-upsert-pr, which told\n // someone in the update-only flow to finish with the PR command: a pairing that does not exist.\n private async validateResolution(repoRoot: string, verb: MutationVerb, mergeDir: string, conflictedFiles: string[]): Promise<void> {\n const reRun = `pnpm ${verb}`;\n // 1. Scoped conflict-marker scan (only the conflicted files — O(conflicts), not O(repo)).\n const scan = this.mergeState.scanConflictMarkers(repoRoot, conflictedFiles);\n if (!scan.clean) {\n throw new CliExitError(1,\n '❌ Unresolved conflict markers (<<<<<<< / ======= / >>>>>>>) remain in:\\n' +\n scan.filesWithMarkers.map((file: string): string => ` - ${file}`).join('\\n') +\n `\\n\\nResolve them, then re-run: ${reRun}`,\n );\n }\n\n // 2. Ensure git itself has no remaining unmerged entries.\n const unmerged = await this.gitExec.gitQuery(['diff', '--name-only', '--diff-filter=U'], process.cwd(), 'Failed to list unmerged files (git diff --diff-filter=U).');\n if (unmerged !== '') {\n throw new CliExitError(1,\n '❌ Git still reports unmerged files:\\n' + unmerged +\n '\\n\\nResolve and `git add` them, then re-run: ' + reRun,\n );\n }\n process.stdout.write('✅ No conflict markers in resolved files.\\n');\n\n // 3. Explanation check — every conflicted file must have a non-empty merge-explanation.md in its\n // per-file context dir, proving the AI deliberately 3-point merged it (and recording how).\n const explanations = this.mergeState.scanMergeExplanations(mergeDir, conflictedFiles);\n if (!explanations.clean) {\n const missing = explanations.filesWithMarkers\n .map((file: string): string => ` - ${file}\\n → ${path.join(this.mergeState.perFileContextDir(mergeDir, file), MERGE_EXPLANATION_FILE)}`)\n .join('\\n');\n throw new CliExitError(1,\n `❌ Missing/empty merge explanation (${MERGE_EXPLANATION_FILE}) for:\\n` +\n missing +\n '\\n\\nWrite a few sentences on how you resolved each (which side, what you combined, why),\\n' +\n 'then re-run: ' + reRun,\n );\n }\n process.stdout.write('✅ Merge explanations present for all resolved files.\\n');\n }\n\n private async localBranchExists(name: string): Promise<boolean> {\n return (await this.gitExec.tryGit(['show-ref', '--verify', '--quiet', `refs/heads/${name}`], process.cwd())).ok;\n }\n\n // Force-push the squash branch to the stable feature branch (where the single PR lives) — unless the\n // caller owns the push (see MergeEndOptions.pushRemote) — then RENAME the local squash branch back to\n // that SAME feature name. On a CLEAN sync the pre-merge snapshot is disposable, so it's deleted at the\n // very end; a CONFLICT sync — or a sync we did not push — keeps it.\n // eslint-disable-next-line @typescript-eslint/max-params\n private async finalizeBranch(repoRoot: string, verb: MutationVerb, ctx: MergeContext, hadConflict: boolean, pushRemote: boolean): Promise<void> {\n process.stdout.write('\\n' + SEP + '🗑️ Finalizing\\n' + SEP + '\\n');\n const base = this.branchNaming.baseBranchName(ctx.currentBranch);\n await this.gitExec.runGitChecked(['branch', '-D', ctx.currentBranch], 'Failed to delete old feature branch');\n\n const pushed = pushRemote ? await this.pushFinalized(ctx, base) : this.explainNoPush();\n await this.gitExec.runGitChecked(['checkout', ctx.squashBranch], 'Failed to checkout squash branch');\n // Free the rename target: `base` is normally the branch we just deleted, but a backward-compat\n // sync from a leftover `…wpN` can leave a separate stale `base` lingering — drop it too.\n if (base !== ctx.currentBranch && await this.localBranchExists(base)) {\n await this.gitExec.runGitChecked(['branch', '-D', base], 'Failed to delete stale base branch');\n }\n await this.gitExec.runGitChecked(['branch', '-m', base], 'Failed to rename squash branch to the feature name');\n const renameEvent = new BranchMutationEvent(verb, 'RENAME');\n renameEvent.fromBranch = ctx.currentBranch;\n renameEvent.toBranch = base;\n logBranchMutation(repoRoot, renameEvent);\n\n // Branch now contains origin/main — stamp a clean main-sync status so the feature-branch-guard\n // unblocks edits immediately (no wait for the async refresher).\n stampCleanMainSyncStatus(repoRoot);\n\n // Clean sync → the pre-merge snapshot was never needed; delete it LAST. Conflict sync → keep it.\n // ALSO keep it when we did not push: the squash rewrite then exists ONLY in this working copy, so\n // deleting the snapshot would leave a history rewrite with no copy anywhere. It is disposable only\n // once origin has the result, and in the PR flow that does not happen until wp-finish-upsert-pr.\n const backupKept = hadConflict || !pushed;\n if (!backupKept && await this.localBranchExists(ctx.backupBranch)) {\n await this.gitExec.runGitChecked(['branch', '-D', ctx.backupBranch], 'Failed to delete clean-merge backup');\n }\n\n const finalizeEvent = new BranchMutationEvent(verb, 'FINALIZE');\n finalizeEvent.fromBranch = ctx.currentBranch;\n finalizeEvent.toBranch = base;\n finalizeEvent.outcome = 'finalized';\n finalizeEvent.artifacts = [backupKept ? `backup=${ctx.backupBranch}` : `backupDeleted=${ctx.backupBranch}`, `remotePR=${base}`];\n logBranchMutation(repoRoot, finalizeEvent);\n\n this.printSyncRecap(base, ctx.backupBranch, ctx.prNumber, new SyncRecap(pushed, !pushRemote, hadConflict, backupKept));\n }\n\n // Say WHY nothing was pushed, so an unpushed branch never looks like a failure. Always returns false\n // (nothing was pushed), which also keeps the pre-merge snapshot alive — see the backupKept comment.\n private explainNoPush(): boolean {\n process.stdout.write(\n 'Not pushing — the PR flow pushes exactly ONCE, from pnpm wp-finish-upsert-pr, after summary.json\\n' +\n 'and the build gate pass and the gated PR body is written. Your work stays local until then\\n' +\n '(the pre-merge snapshot below is kept as well, so nothing is only in one place).\\n',\n );\n return false;\n }\n\n // Push the finalized squash branch to the stable feature branch. Returns whether a push actually\n // happened — false when there is no remote branch yet (a brand-new branch is local until something\n // creates it, which in the PR flow is `gh pr create` after GatedPrPublisher's push).\n private async pushFinalized(ctx: MergeContext, base: string): Promise<boolean> {\n const remoteExists = (await this.gitExec.tryGit(['ls-remote', '--exit-code', '--heads', 'origin', base], process.cwd())).ok;\n if (!remoteExists) {\n process.stdout.write('No remote branch — local only.\\n');\n return false;\n }\n process.stdout.write(ctx.prNumber ? `Updating PR #${ctx.prNumber} (force-with-lease)...\\n` : 'Updating remote branch (force-with-lease)...\\n');\n await this.gitExec.runGitChecked(['push', '-u', '--force-with-lease', 'origin', `${ctx.squashBranch}:${base}`], 'Failed to push to origin');\n return true;\n }\n\n // Where the branch ended up, in the recap's own words. Three distinct outcomes, and \"deferred\" must\n // never read like the failure the other two could be mistaken for.\n private remoteRecapLine(feature: string, prNumber: string, recap: SyncRecap): string {\n if (recap.pushed) {\n return `landed back on ${feature} (== origin/${feature}${prNumber ? ` == PR #${prNumber}` : ''} — names match)`;\n }\n if (recap.pushDeferred) {\n return `landed back on ${feature} (local — by design; pnpm wp-finish-upsert-pr does the one push)`;\n }\n return `landed back on ${feature} (local only — no remote branch yet)`;\n }\n\n // The explicit, numbered \"here is exactly what I did\" recap the AI (and human) reads after a sync.\n private printSyncRecap(feature: string, backupBranch: string, prNumber: string, recap: SyncRecap): void {\n const backupKept = recap.backupKept;\n const remoteLine = this.remoteRecapLine(feature, prNumber, recap);\n const keptReason = recap.hadConflict ? 'this merge had conflicts' : 'not pushed yet — wp-finish-upsert-pr will push';\n const step1 = backupKept\n ? `snapshotted your pre-merge state → ${backupBranch} (kept — ${keptReason})`\n : `snapshotted your pre-merge state → ${backupBranch} (auto-removed — clean merge, no undo needed)`;\n const trailer = backupKept\n ? ` Pre-merge snapshot trail: git branch --list '${feature}PreMerge*'\\n` +\n ` Its conflict context lives in the paired merge-<n>/ folder under .webpieces/merge-info/\\n` +\n ` Prune this run's snapshot when safe: git branch -D ${backupBranch}\\n\\n`\n : '\\n';\n process.stdout.write(\n '\\n' + SEP + '✅ Sync complete — here is exactly what I did\\n' + SEP + '\\n' +\n ` 1. ${step1}\\n` +\n ` 2. pulled origin/main\\n` +\n ` 3. squash-merged your work onto main\\n` +\n ` 4. ${remoteLine}\\n\\n` +\n trailer,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"merge-end.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/merge-end.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,0DAA+E;AAC/E,sEAA4H;AAC5H,yCAA2D;AAC3D,mDAA+C;AAC/C,yCAAsC;AACtC,yCAAqC;AAEr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E,KAAK,CAAC,CAAC;QAClE,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,gDAAgD,CAAC;QACrH,MAAM,KAAK,GAAG,UAAU;YACpB,CAAC,CAAC,sCAAsC,YAAY,YAAY,UAAU,GAAG;YAC7E,CAAC,CAAC,sCAAsC,YAAY,+CAA+C,CAAC;QACxG,MAAM,OAAO,GAAG,UAAU;YACtB,CAAC,CAAC,oDAAoD,OAAO,cAAc;gBACzE,gGAAgG;gBAChG,0DAA0D,YAAY,MAAM;YAC9E,CAAC,CAAC,IAAI,CAAC;QACX,OAAO,CAAC,MAAM,CAAC,KAAK,CAChB,IAAI,GAAG,GAAG,GAAG,gDAAgD,GAAG,GAAG,GAAG,IAAI;YAC1E,SAAS,KAAK,IAAI;YAClB,4BAA4B;YAC5B,2CAA2C;YAC3C,SAAS,UAAU,MAAM;YACzB,OAAO,CACV,CAAC;IACN,CAAC;CACJ,CAAA;AAtMY,4BAAQ;mBAAR,QAAQ;IADpB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGF,4BAAY;QACT,mBAAQ;QAChB,kBAAO;QACJ,wBAAU;QACN,0CAAqB;GANjD,QAAQ,CAsMpB","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { MERGE_EXPLANATION_FILE, CliExitError } from '@webpieces/rules-config';\nimport { MainSyncStatusService, MutationVerb, BranchMutationEvent, logBranchMutation } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { BranchNaming } from './branch-naming';\nimport { CleanTmp } from './cleanTmp';\nimport { GitExec } from './git-exec';\nimport { MergeContext } from './merge-start';\nimport { MergeState } from './merge-state';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// What finalizing actually did, for the recap. Data-only. `pushed` and `pushDeferred` are distinct on\n// purpose: \"we chose not to push yet\" must not be reported like \"there was no remote to push to\".\nclass SyncRecap {\n pushed: boolean;\n pushDeferred: boolean;\n hadConflict: boolean;\n backupKept: boolean;\n\n constructor(pushed: boolean, pushDeferred: boolean, hadConflict: boolean, backupKept: boolean) {\n this.pushed = pushed;\n this.pushDeferred = pushDeferred;\n this.hadConflict = hadConflict;\n this.backupKept = backupKept;\n }\n}\n\n// How a merge should be finalized. Data-only (per CLAUDE.md, classes for data) — bundled rather than\n// added as more positional params, which mergeEnd already has enough of.\nexport class MergeEndOptions {\n // Non-null means the AI resolved a conflict and it must be validated + committed before finalizing.\n // Null means merge-START already committed a clean merge, so finalize only.\n conflictedFiles: string[] | null;\n\n /**\n * Whether finalizing may push the squashed branch to origin.\n *\n * FALSE for the PR flow (`wp-start-upsert-pr` / `wp-finish-upsert-pr`), which pushes EXACTLY ONCE,\n * from GatedPrPublisher, after summary.json + every BLOCK checklist + the authoritative build gate\n * have passed and the gated PR body is already up. Code must not reach the remote ahead of its\n * review, and an early push here is also what fires `pull_request:synchronize` against a PR body\n * still carrying the previous run's gate token — the flap the whole gate redesign is removing.\n *\n * TRUE for the update-only flow (`wp-start-update` / `wp-finish-update`), which has no later push;\n * finalizing IS the end of that flow, so not pushing would silently strand the rewrite locally.\n */\n pushRemote: boolean;\n\n constructor(conflictedFiles: string[] | null, pushRemote: boolean) {\n this.conflictedFiles = conflictedFiles;\n this.pushRemote = pushRemote;\n }\n}\n\n// merge-END: the second half of the 3-point squash-merge lifecycle, symmetric with merge-START. Given\n// the branch context, it (optionally) validates + commits the AI's conflict resolution, then ALWAYS\n// finalizes — force-pushes `<branch>Squash` to the stable feature branch and renames it BACK to that\n// same feature name (local == remote == PR head), stamps a clean main-sync status, clears the marker,\n// and sweeps stale tmp. RunUpdate (clean path / validated resume), wp-finish-update, and\n// wp-finish-upsert-pr (conflict resolution) all call THIS, so finalization happens in exactly one place.\n@injectable(bindingScopeValues.Singleton)\nexport class MergeEnd {\n constructor(\n private readonly branchNaming: BranchNaming,\n private readonly cleanTmpService: CleanTmp,\n private readonly gitExec: GitExec,\n private readonly mergeState: MergeState,\n private readonly mainSyncStatus: MainSyncStatusService,\n ) {}\n\n /**\n * Complete a 3-point squash merge. See {@link MergeEndOptions} for what `conflictedFiles` and\n * `pushRemote` mean. Either way the merge ends fully finalized on the feature branch.\n */\n async mergeEnd(\n repoRoot: string, verb: MutationVerb, mergeDir: string, ctx: MergeContext, options: MergeEndOptions,\n ): Promise<void> {\n const conflictedFiles = options.conflictedFiles;\n if (conflictedFiles !== null) {\n process.stdout.write('\\n' + SEP + '🔎 Validating Merge Resolution\\n' + SEP + '\\n');\n await this.validateResolution(repoRoot, verb, mergeDir, conflictedFiles);\n // Stage the AI's resolved conflicts, but NEVER sweep untracked files into the squash commit.\n // Fail on untracked so the AI commits or deletes them explicitly; then `git add -u` stages\n // tracked resolutions only.\n await this.gitExec.assertNoUntracked(repoRoot);\n await this.gitExec.runGitChecked(['add', '-u'], 'Failed to stage resolved files');\n\n const nothingStaged = (await this.gitExec.tryGit(['diff-index', '--quiet', '--cached', 'HEAD', '--'], process.cwd())).ok;\n if (!nothingStaged) {\n await this.gitExec.runGitChecked(\n ['commit', '-m', `Squash merge of ${ctx.currentBranch} (conflicts resolved)`],\n 'Failed to commit resolved merge',\n );\n }\n fs.writeFileSync(path.join(mergeDir, 'conflicts-resolved'), '');\n process.stdout.write('\\n✅ Merge validated and committed.\\n');\n }\n\n // A marker in THIS run dir means the sync hit conflicts (marker is written only on hand-back).\n // Read it BEFORE clearMergeMarker so finalize knows whether to keep the pre-merge snapshot.\n const hadConflict = this.mergeState.readMergeMarker(mergeDir) !== null;\n await this.finalizeBranch(repoRoot, verb, ctx, hadConflict, options.pushRemote);\n this.mergeState.clearMergeMarker(mergeDir);\n await this.cleanTmpService.cleanTmp();\n }\n\n // Validate the AI's resolution of the conflicted files. Throws CliExitError with a fix instruction\n // on any failure; returns only when all three checks pass.\n // `verb` is the bin the AI actually ran (wp-finish-update or wp-finish-upsert-pr) — every \"re-run\"\n // instruction below is rendered from it. It used to be hardcoded to wp-finish-upsert-pr, which told\n // someone in the update-only flow to finish with the PR command: a pairing that does not exist.\n private async validateResolution(repoRoot: string, verb: MutationVerb, mergeDir: string, conflictedFiles: string[]): Promise<void> {\n const reRun = `pnpm ${verb}`;\n // 1. Scoped conflict-marker scan (only the conflicted files — O(conflicts), not O(repo)).\n const scan = this.mergeState.scanConflictMarkers(repoRoot, conflictedFiles);\n if (!scan.clean) {\n throw new CliExitError(1,\n '❌ Unresolved conflict markers (<<<<<<< / ======= / >>>>>>>) remain in:\\n' +\n scan.filesWithMarkers.map((file: string): string => ` - ${file}`).join('\\n') +\n `\\n\\nResolve them, then re-run: ${reRun}`,\n );\n }\n\n // 2. Ensure git itself has no remaining unmerged entries.\n const unmerged = await this.gitExec.gitQuery(['diff', '--name-only', '--diff-filter=U'], process.cwd(), 'Failed to list unmerged files (git diff --diff-filter=U).');\n if (unmerged !== '') {\n throw new CliExitError(1,\n '❌ Git still reports unmerged files:\\n' + unmerged +\n '\\n\\nResolve and `git add` them, then re-run: ' + reRun,\n );\n }\n process.stdout.write('✅ No conflict markers in resolved files.\\n');\n\n // 3. Explanation check — every conflicted file must have a non-empty merge-explanation.md in its\n // per-file context dir, proving the AI deliberately 3-point merged it (and recording how).\n const explanations = this.mergeState.scanMergeExplanations(mergeDir, conflictedFiles);\n if (!explanations.clean) {\n const missing = explanations.filesWithMarkers\n .map((file: string): string => ` - ${file}\\n → ${path.join(this.mergeState.perFileContextDir(mergeDir, file), MERGE_EXPLANATION_FILE)}`)\n .join('\\n');\n throw new CliExitError(1,\n `❌ Missing/empty merge explanation (${MERGE_EXPLANATION_FILE}) for:\\n` +\n missing +\n '\\n\\nWrite a few sentences on how you resolved each (which side, what you combined, why),\\n' +\n 'then re-run: ' + reRun,\n );\n }\n process.stdout.write('✅ Merge explanations present for all resolved files.\\n');\n }\n\n private async localBranchExists(name: string): Promise<boolean> {\n return (await this.gitExec.tryGit(['show-ref', '--verify', '--quiet', `refs/heads/${name}`], process.cwd())).ok;\n }\n\n // Force-push the squash branch to the stable feature branch (where the single PR lives) — unless the\n // caller owns the push (see MergeEndOptions.pushRemote) — then RENAME the local squash branch back to\n // that SAME feature name. On a CLEAN sync the pre-merge snapshot is disposable, so it's deleted at the\n // very end; a CONFLICT sync — or a sync we did not push — keeps it.\n // eslint-disable-next-line @typescript-eslint/max-params\n private async finalizeBranch(repoRoot: string, verb: MutationVerb, ctx: MergeContext, hadConflict: boolean, pushRemote: boolean): Promise<void> {\n process.stdout.write('\\n' + SEP + '🗑️ Finalizing\\n' + SEP + '\\n');\n const base = this.branchNaming.baseBranchName(ctx.currentBranch);\n await this.gitExec.runGitChecked(['branch', '-D', ctx.currentBranch], 'Failed to delete old feature branch');\n\n const pushed = pushRemote ? await this.pushFinalized(ctx, base) : this.explainNoPush();\n await this.gitExec.runGitChecked(['checkout', ctx.squashBranch], 'Failed to checkout squash branch');\n // Free the rename target: `base` is normally the branch we just deleted, but a backward-compat\n // sync from a leftover `…wpN` can leave a separate stale `base` lingering — drop it too.\n if (base !== ctx.currentBranch && await this.localBranchExists(base)) {\n await this.gitExec.runGitChecked(['branch', '-D', base], 'Failed to delete stale base branch');\n }\n await this.gitExec.runGitChecked(['branch', '-m', base], 'Failed to rename squash branch to the feature name');\n const renameEvent = new BranchMutationEvent(verb, 'RENAME');\n renameEvent.fromBranch = ctx.currentBranch;\n renameEvent.toBranch = base;\n logBranchMutation(repoRoot, renameEvent);\n\n // Branch now contains origin/main — stamp a clean main-sync status so the feature-branch-guard\n // unblocks edits immediately (no wait for the async refresher).\n await this.mainSyncStatus.stampCleanMainSyncStatus(repoRoot);\n\n // Clean sync → the pre-merge snapshot was never needed; delete it LAST. Conflict sync → keep it.\n // ALSO keep it when we did not push: the squash rewrite then exists ONLY in this working copy, so\n // deleting the snapshot would leave a history rewrite with no copy anywhere. It is disposable only\n // once origin has the result, and in the PR flow that does not happen until wp-finish-upsert-pr.\n const backupKept = hadConflict || !pushed;\n if (!backupKept && await this.localBranchExists(ctx.backupBranch)) {\n await this.gitExec.runGitChecked(['branch', '-D', ctx.backupBranch], 'Failed to delete clean-merge backup');\n }\n\n const finalizeEvent = new BranchMutationEvent(verb, 'FINALIZE');\n finalizeEvent.fromBranch = ctx.currentBranch;\n finalizeEvent.toBranch = base;\n finalizeEvent.outcome = 'finalized';\n finalizeEvent.artifacts = [backupKept ? `backup=${ctx.backupBranch}` : `backupDeleted=${ctx.backupBranch}`, `remotePR=${base}`];\n logBranchMutation(repoRoot, finalizeEvent);\n\n this.printSyncRecap(base, ctx.backupBranch, ctx.prNumber, new SyncRecap(pushed, !pushRemote, hadConflict, backupKept));\n }\n\n // Say WHY nothing was pushed, so an unpushed branch never looks like a failure. Always returns false\n // (nothing was pushed), which also keeps the pre-merge snapshot alive — see the backupKept comment.\n private explainNoPush(): boolean {\n process.stdout.write(\n 'Not pushing — the PR flow pushes exactly ONCE, from pnpm wp-finish-upsert-pr, after summary.json\\n' +\n 'and the build gate pass and the gated PR body is written. Your work stays local until then\\n' +\n '(the pre-merge snapshot below is kept as well, so nothing is only in one place).\\n',\n );\n return false;\n }\n\n // Push the finalized squash branch to the stable feature branch. Returns whether a push actually\n // happened — false when there is no remote branch yet (a brand-new branch is local until something\n // creates it, which in the PR flow is `gh pr create` after GatedPrPublisher's push).\n private async pushFinalized(ctx: MergeContext, base: string): Promise<boolean> {\n const remoteExists = (await this.gitExec.tryGit(['ls-remote', '--exit-code', '--heads', 'origin', base], process.cwd())).ok;\n if (!remoteExists) {\n process.stdout.write('No remote branch — local only.\\n');\n return false;\n }\n process.stdout.write(ctx.prNumber ? `Updating PR #${ctx.prNumber} (force-with-lease)...\\n` : 'Updating remote branch (force-with-lease)...\\n');\n await this.gitExec.runGitChecked(['push', '-u', '--force-with-lease', 'origin', `${ctx.squashBranch}:${base}`], 'Failed to push to origin');\n return true;\n }\n\n // Where the branch ended up, in the recap's own words. Three distinct outcomes, and \"deferred\" must\n // never read like the failure the other two could be mistaken for.\n private remoteRecapLine(feature: string, prNumber: string, recap: SyncRecap): string {\n if (recap.pushed) {\n return `landed back on ${feature} (== origin/${feature}${prNumber ? ` == PR #${prNumber}` : ''} — names match)`;\n }\n if (recap.pushDeferred) {\n return `landed back on ${feature} (local — by design; pnpm wp-finish-upsert-pr does the one push)`;\n }\n return `landed back on ${feature} (local only — no remote branch yet)`;\n }\n\n // The explicit, numbered \"here is exactly what I did\" recap the AI (and human) reads after a sync.\n private printSyncRecap(feature: string, backupBranch: string, prNumber: string, recap: SyncRecap): void {\n const backupKept = recap.backupKept;\n const remoteLine = this.remoteRecapLine(feature, prNumber, recap);\n const keptReason = recap.hadConflict ? 'this merge had conflicts' : 'not pushed yet — wp-finish-upsert-pr will push';\n const step1 = backupKept\n ? `snapshotted your pre-merge state → ${backupBranch} (kept — ${keptReason})`\n : `snapshotted your pre-merge state → ${backupBranch} (auto-removed — clean merge, no undo needed)`;\n const trailer = backupKept\n ? ` Pre-merge snapshot trail: git branch --list '${feature}PreMerge*'\\n` +\n ` Its conflict context lives in the paired merge-<n>/ folder under .webpieces/merge-info/\\n` +\n ` Prune this run's snapshot when safe: git branch -D ${backupBranch}\\n\\n`\n : '\\n';\n process.stdout.write(\n '\\n' + SEP + '✅ Sync complete — here is exactly what I did\\n' + SEP + '\\n' +\n ` 1. ${step1}\\n` +\n ` 2. pulled origin/main\\n` +\n ` 3. squash-merged your work onto main\\n` +\n ` 4. ${remoteLine}\\n\\n` +\n trailer,\n );\n }\n}\n"]}
@@ -31,7 +31,7 @@ export declare class PrContextWriter {
31
31
  * *.sql / Dockerfile / .env* file a checklist most wants to key on). `includeDeletions` is on for the
32
32
  * same reason: a DELETED migration is exactly what a checklist wants to see.
33
33
  */
34
- ensure(repoRoot: string, featureName: string, basis: DiffBasis, stage: string, changedFiles?: readonly string[], diffDir?: string): ChecklistReviewContext;
34
+ ensure(repoRoot: string, featureName: string, basis: DiffBasis, stage: string, changedFiles?: readonly string[], diffDir?: string): Promise<ChecklistReviewContext>;
35
35
  /** The context WITHOUT persisting it — for a caller that must write later (after materializing). */
36
36
  contextFor(repoRoot: string, featureName: string, basis: DiffBasis): ChecklistReviewContext;
37
37
  private changedFiles;
@@ -39,13 +39,13 @@ let PrContextWriter = class PrContextWriter {
39
39
  * same reason: a DELETED migration is exactly what a checklist wants to see.
40
40
  */
41
41
  // eslint-disable-next-line @typescript-eslint/max-params
42
- ensure(repoRoot, featureName, basis, stage, changedFiles, diffDir = '') {
42
+ async ensure(repoRoot, featureName, basis, stage, changedFiles, diffDir = '') {
43
43
  if (basis.unresolved)
44
44
  return new rules_config_1.ChecklistReviewContext();
45
45
  // Reuse the caller's changed-file set when it has one. ChecklistScanner already computed exactly
46
46
  // this list to do its matching, and recomputing it here was a second `git diff --name-only` per
47
47
  // command for a list we were handed — and a second chance for the two to disagree.
48
- const changed = changedFiles ?? this.changedFiles(repoRoot, basis);
48
+ const changed = changedFiles ?? await this.changedFiles(repoRoot, basis);
49
49
  const p = this.reviewJsonService.writePrContext(repoRoot, featureName, new rules_config_1.PrContext(basis.base, basis.headSha, [...changed], basis.dirty, basis.dirtyFiles, basis.diffCommand, diffDir, new Date().toISOString(), basis.hashMainHead), stage);
50
50
  return new rules_config_1.ChecklistReviewContext(basis.base, p, basis.fileDiffCommand, diffDir, basis.dirty);
51
51
  }
@@ -55,7 +55,7 @@ let PrContextWriter = class PrContextWriter {
55
55
  return new rules_config_1.ChecklistReviewContext();
56
56
  return new rules_config_1.ChecklistReviewContext(basis.base, this.reviewJsonService.prContextPath(repoRoot, featureName), basis.fileDiffCommand, '', basis.dirty);
57
57
  }
58
- changedFiles(repoRoot, basis) {
58
+ async changedFiles(repoRoot, basis) {
59
59
  const opts = new rules_config_1.ChangedFilesOptions();
60
60
  opts.tsOnly = false;
61
61
  opts.includeDeletions = true;
@@ -1 +1 @@
1
- {"version":3,"file":"pr-context-writer.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/pr-context-writ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D,OAAO,IAAI,qCAAsB,CAC7B,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,QAAQ,EAAE,WAAW,CAAC,EACvE,KAAK,CAAC,eAAe,EAAE,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IAEO,YAAY,CAAC,QAAgB,EAAE,KAAgB;QACnD,MAAM,IAAI,GAAG,IAAI,kCAAmB,EAAE,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACjF,CAAC;CACJ,CAAA;AAlDY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGL,wBAAS;QACD,gCAAiB;GAHhD,eAAe,CAkD3B","sourcesContent":["import {\n ChangedFilesOptions, ChecklistReviewContext, DiffScope, PrContext, ReviewJsonService,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { DiffBasis } from './diff-basis';\n\n/**\n * Writes `pr-context.json` (the 3-point base/head sha + the FULL changed-file set) and returns the context\n * every printed review instruction inlines.\n *\n * Extracted so `wp-start-upsert-pr` and `wp-review-upsert-pr` cannot diverge. It used to live only in wp-start,\n * which meant `wp-review-upsert-pr` — the command wp-start tells the AI to run FIRST — silently rendered its\n * reviewer blocks with NO `git diff` command and NO full-file-set path whenever wp-start had not run this\n * cycle. A reviewer handed filenames and no way to read the diff is exactly the failure this instruction\n * exists to prevent, and it failed silently, which is worse.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class PrContextWriter {\n constructor(\n private readonly diffScope: DiffScope,\n private readonly reviewJsonService: ReviewJsonService,\n ) {}\n\n /**\n * Compute + persist the context against the {@link DiffBasis} the CALLER already resolved, so the range\n * a reviewer is told to diff is byte-identical to the one the pattern matching used. Returns an EMPTY\n * context when the basis has no fork point — callers must say so out loud rather than quietly omit the\n * lines it would have filled; see ChecklistInstructionsService.diffLines.\n *\n * Taking a DiffBasis rather than a bare `forkPoint: string` is the fix, not a refactor: with a lone sha\n * this method had no way to know whether the tree was dirty, so it recorded `head:'HEAD'` and every\n * downstream reader assembled a commit-to-commit command that shows nothing when work is uncommitted.\n *\n * Two things mirror ChecklistScanner deliberately: no head argument to `getChangedFiles` (so the working\n * tree and untracked files are included, not just commits), and `tsOnly:false` (the default drops every\n * *.sql / Dockerfile / .env* file a checklist most wants to key on). `includeDeletions` is on for the\n * same reason: a DELETED migration is exactly what a checklist wants to see.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n ensure(repoRoot: string, featureName: string, basis: DiffBasis, stage: string, changedFiles?: readonly string[], diffDir = ''): ChecklistReviewContext {\n if (basis.unresolved) return new ChecklistReviewContext();\n // Reuse the caller's changed-file set when it has one. ChecklistScanner already computed exactly\n // this list to do its matching, and recomputing it here was a second `git diff --name-only` per\n // command for a list we were handed — and a second chance for the two to disagree.\n const changed = changedFiles ?? this.changedFiles(repoRoot, basis);\n const p = this.reviewJsonService.writePrContext(repoRoot, featureName, new PrContext(\n basis.base, basis.headSha, [...changed],\n basis.dirty, basis.dirtyFiles, basis.diffCommand, diffDir, new Date().toISOString(),\n basis.hashMainHead,\n ), stage);\n return new ChecklistReviewContext(basis.base, p, basis.fileDiffCommand, diffDir, basis.dirty);\n }\n\n /** The context WITHOUT persisting it — for a caller that must write later (after materializing). */\n contextFor(repoRoot: string, featureName: string, basis: DiffBasis): ChecklistReviewContext {\n if (basis.unresolved) return new ChecklistReviewContext();\n return new ChecklistReviewContext(\n basis.base, this.reviewJsonService.prContextPath(repoRoot, featureName),\n basis.fileDiffCommand, '', basis.dirty);\n }\n\n private changedFiles(repoRoot: string, basis: DiffBasis): string[] {\n const opts = new ChangedFilesOptions();\n opts.tsOnly = false;\n opts.includeDeletions = true;\n return this.diffScope.getChangedFiles(repoRoot, basis.base, undefined, opts);\n }\n}\n"]}
1
+ {"version":3,"file":"pr-context-writer.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/pr-context-writer.ts"],"names":[],"mappings":";;;;AAAA,0DAEiC;AACjC,yCAA2D;AAG3D;;;;;;;;;;;GAWG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAEH;IACA;IAFrB,YACqB,SAAoB,EACpB,iBAAoC;QADpC,cAAS,GAAT,SAAS,CAAW;QACpB,sBAAiB,GAAjB,iBAAiB,CAAmB;IACtD,CAAC;IAEJ;;;;;;;;;;;;;;OAcG;IACH,yDAAyD;IACzD,KAAK,CAAC,MAAM,CAAC,QAAgB,EAAE,WAAmB,EAAE,KAAgB,EAAE,KAAa,EAAE,YAAgC,EAAE,OAAO,GAAG,EAAE;QAC/H,IAAI,KAAK,CAAC,UAAU;YAAE,OAAO,IAAI,qCAAsB,EAAE,CAAC;QAC1D,iGAAiG;QACjG,gGAAgG;QAChG,mFAAmF;QACnF,MAAM,OAAO,GAAG,YAAY,IAAI,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACzE,MAAM,CAAC,GAAG,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,wBAAS,CAChF,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,EACvC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EACnF,KAAK,CAAC,YAAY,CACrB,EAAE,KAAK,CAAC,CAAC;QACV,OAAO,IAAI,qCAAsB,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,eAAe,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IAClG,CAAC;IAED,oGAAoG;IACpG,UAAU,CAAC,QAAgB,EAAE,WAAmB,EAAE,KAAgB;QAC9D,IAAI,KAAK,CAAC,UAAU;YAAE,OAAO,IAAI,qCAAsB,EAAE,CAAC;QAC1D,OAAO,IAAI,qCAAsB,CAC7B,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,QAAQ,EAAE,WAAW,CAAC,EACvE,KAAK,CAAC,eAAe,EAAE,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,YAAY,CAAC,QAAgB,EAAE,KAAgB;QACzD,MAAM,IAAI,GAAG,IAAI,kCAAmB,EAAE,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACjF,CAAC;CACJ,CAAA;AAlDY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGL,wBAAS;QACD,gCAAiB;GAHhD,eAAe,CAkD3B","sourcesContent":["import {\n ChangedFilesOptions, ChecklistReviewContext, DiffScope, PrContext, ReviewJsonService,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { DiffBasis } from './diff-basis';\n\n/**\n * Writes `pr-context.json` (the 3-point base/head sha + the FULL changed-file set) and returns the context\n * every printed review instruction inlines.\n *\n * Extracted so `wp-start-upsert-pr` and `wp-review-upsert-pr` cannot diverge. It used to live only in wp-start,\n * which meant `wp-review-upsert-pr` — the command wp-start tells the AI to run FIRST — silently rendered its\n * reviewer blocks with NO `git diff` command and NO full-file-set path whenever wp-start had not run this\n * cycle. A reviewer handed filenames and no way to read the diff is exactly the failure this instruction\n * exists to prevent, and it failed silently, which is worse.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class PrContextWriter {\n constructor(\n private readonly diffScope: DiffScope,\n private readonly reviewJsonService: ReviewJsonService,\n ) {}\n\n /**\n * Compute + persist the context against the {@link DiffBasis} the CALLER already resolved, so the range\n * a reviewer is told to diff is byte-identical to the one the pattern matching used. Returns an EMPTY\n * context when the basis has no fork point — callers must say so out loud rather than quietly omit the\n * lines it would have filled; see ChecklistInstructionsService.diffLines.\n *\n * Taking a DiffBasis rather than a bare `forkPoint: string` is the fix, not a refactor: with a lone sha\n * this method had no way to know whether the tree was dirty, so it recorded `head:'HEAD'` and every\n * downstream reader assembled a commit-to-commit command that shows nothing when work is uncommitted.\n *\n * Two things mirror ChecklistScanner deliberately: no head argument to `getChangedFiles` (so the working\n * tree and untracked files are included, not just commits), and `tsOnly:false` (the default drops every\n * *.sql / Dockerfile / .env* file a checklist most wants to key on). `includeDeletions` is on for the\n * same reason: a DELETED migration is exactly what a checklist wants to see.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n async ensure(repoRoot: string, featureName: string, basis: DiffBasis, stage: string, changedFiles?: readonly string[], diffDir = ''): Promise<ChecklistReviewContext> {\n if (basis.unresolved) return new ChecklistReviewContext();\n // Reuse the caller's changed-file set when it has one. ChecklistScanner already computed exactly\n // this list to do its matching, and recomputing it here was a second `git diff --name-only` per\n // command for a list we were handed — and a second chance for the two to disagree.\n const changed = changedFiles ?? await this.changedFiles(repoRoot, basis);\n const p = this.reviewJsonService.writePrContext(repoRoot, featureName, new PrContext(\n basis.base, basis.headSha, [...changed],\n basis.dirty, basis.dirtyFiles, basis.diffCommand, diffDir, new Date().toISOString(),\n basis.hashMainHead,\n ), stage);\n return new ChecklistReviewContext(basis.base, p, basis.fileDiffCommand, diffDir, basis.dirty);\n }\n\n /** The context WITHOUT persisting it — for a caller that must write later (after materializing). */\n contextFor(repoRoot: string, featureName: string, basis: DiffBasis): ChecklistReviewContext {\n if (basis.unresolved) return new ChecklistReviewContext();\n return new ChecklistReviewContext(\n basis.base, this.reviewJsonService.prContextPath(repoRoot, featureName),\n basis.fileDiffCommand, '', basis.dirty);\n }\n\n private async changedFiles(repoRoot: string, basis: DiffBasis): Promise<string[]> {\n const opts = new ChangedFilesOptions();\n opts.tsOnly = false;\n opts.includeDeletions = true;\n return this.diffScope.getChangedFiles(repoRoot, basis.base, undefined, opts);\n }\n}\n"]}