@webpieces/pr-gate 0.3.300 → 0.3.302

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 (32) hide show
  1. package/package.json +4 -6
  2. package/src/index.js +4 -3
  3. package/src/index.js.map +1 -1
  4. package/src/scripts/git-gatherInfo.js +2 -2
  5. package/src/scripts/git-gatherInfo.js.map +1 -1
  6. package/src/scripts/workflow/build-affected.js +3 -4
  7. package/src/scripts/workflow/build-affected.js.map +1 -1
  8. package/src/scripts/workflow/git-findForkPoint.js +1 -1
  9. package/src/scripts/workflow/git-findForkPoint.js.map +1 -1
  10. package/src/scripts/workflow/git-validateUpToDate.js +1 -1
  11. package/src/scripts/workflow/git-validateUpToDate.js.map +1 -1
  12. package/src/scripts/workflow/merge-end.js +1 -1
  13. package/src/scripts/workflow/merge-end.js.map +1 -1
  14. package/src/scripts/workflow/merge-start.js +3 -3
  15. package/src/scripts/workflow/merge-start.js.map +1 -1
  16. package/src/scripts/workflow/open-pr-check.js +2 -2
  17. package/src/scripts/workflow/open-pr-check.js.map +1 -1
  18. package/src/scripts/workflow/run-update.js.map +1 -1
  19. package/src/scripts/{wp-update-end.js → wp-finish-update.js} +5 -5
  20. package/src/scripts/wp-finish-update.js.map +1 -0
  21. package/src/scripts/{wp-update-start.js → wp-start-update.js} +9 -9
  22. package/src/scripts/wp-start-update.js.map +1 -0
  23. package/src/scripts/wp-build-affected.js +0 -25
  24. package/src/scripts/wp-build-affected.js.map +0 -1
  25. package/src/scripts/wp-git-gather.d.ts +0 -2
  26. package/src/scripts/wp-git-gather.js +0 -15
  27. package/src/scripts/wp-git-gather.js.map +0 -1
  28. package/src/scripts/wp-update-end.d.ts +0 -2
  29. package/src/scripts/wp-update-end.js.map +0 -1
  30. package/src/scripts/wp-update-start.js.map +0 -1
  31. /package/src/scripts/{wp-build-affected.d.ts → wp-finish-update.d.ts} +0 -0
  32. /package/src/scripts/{wp-update-start.d.ts → wp-start-update.d.ts} +0 -0
package/package.json CHANGED
@@ -1,16 +1,14 @@
1
1
  {
2
2
  "name": "@webpieces/pr-gate",
3
- "version": "0.3.300",
3
+ "version": "0.3.302",
4
4
  "description": "Gated PR system: 3-point squash-merge, merge validation gate, and red/yellow/green PR dashboard. Standalone scripts, no Nx dependency required.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
7
7
  "bin": {
8
- "wp-git-gather": "./src/scripts/wp-git-gather.js",
9
8
  "wp-finish-upsert-pr": "./src/scripts/git-finishUpsertPr.js",
10
- "wp-build-affected": "./src/scripts/wp-build-affected.js",
11
9
  "wp-start-upsert-pr": "./src/scripts/wp-start-upsert-pr.js",
12
- "wp-update-start": "./src/scripts/wp-update-start.js",
13
- "wp-update-end": "./src/scripts/wp-update-end.js"
10
+ "wp-start-update": "./src/scripts/wp-start-update.js",
11
+ "wp-finish-update": "./src/scripts/wp-finish-update.js"
14
12
  },
15
13
  "files": [
16
14
  "src/**/*"
@@ -23,7 +21,7 @@
23
21
  "directory": "packages/tooling/pr-gate"
24
22
  },
25
23
  "dependencies": {
26
- "@webpieces/rules-config": "0.3.300"
24
+ "@webpieces/rules-config": "0.3.302"
27
25
  },
28
26
  "publishConfig": {
29
27
  "access": "public"
package/src/index.js CHANGED
@@ -3,9 +3,10 @@
3
3
  //
4
4
  // Now published to npm via the release workflow (OIDC trusted publishing).
5
5
  // Public surface is intentionally small for now. The package mainly ships bin
6
- // commands (wp-update-start, wp-update-end, wp-git-gather, wp-finish-upsert-pr, wp-start-upsert-pr,
7
- // wp-build-affected). Shared library exports (dashboard gate computation, etc.) back
8
- // the dashboard those commands render.
6
+ // commands (wp-start-update, wp-finish-update, wp-finish-upsert-pr, wp-start-upsert-pr).
7
+ // The build gate and 3-point merge-info gathering are internal `workflow/` library functions
8
+ // (runBuildAffected, gatherInfo), not bins. Shared library exports (dashboard gate computation,
9
+ // etc.) back the dashboard those commands render.
9
10
  Object.defineProperty(exports, "__esModule", { value: true });
10
11
  exports.renderDashboard = exports.countAddedDisables = exports.computeGateResults = exports.DashboardInput = exports.DisableCounts = exports.GateResult = void 0;
11
12
  var dashboard_1 = require("./dashboard/dashboard");
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/pr-gate/src/index.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,oGAAoG;AACpG,qFAAqF;AACrF,uCAAuC;;;AAEvC,mDAO+B;AAN3B,uGAAA,UAAU,OAAA;AACV,0GAAA,aAAa,OAAA;AACb,2GAAA,cAAc,OAAA;AACd,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,4GAAA,eAAe,OAAA","sourcesContent":["// @webpieces/pr-gate — gated PR system.\n//\n// Now published to npm via the release workflow (OIDC trusted publishing).\n// Public surface is intentionally small for now. The package mainly ships bin\n// commands (wp-update-start, wp-update-end, wp-git-gather, wp-finish-upsert-pr, wp-start-upsert-pr,\n// wp-build-affected). Shared library exports (dashboard gate computation, etc.) back\n// the dashboard those commands render.\n\nexport {\n GateResult,\n DisableCounts,\n DashboardInput,\n computeGateResults,\n countAddedDisables,\n renderDashboard,\n} from './dashboard/dashboard';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/pr-gate/src/index.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,yFAAyF;AACzF,6FAA6F;AAC7F,gGAAgG;AAChG,kDAAkD;;;AAElD,mDAO+B;AAN3B,uGAAA,UAAU,OAAA;AACV,0GAAA,aAAa,OAAA;AACb,2GAAA,cAAc,OAAA;AACd,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,4GAAA,eAAe,OAAA","sourcesContent":["// @webpieces/pr-gate — gated PR system.\n//\n// Now published to npm via the release workflow (OIDC trusted publishing).\n// Public surface is intentionally small for now. The package mainly ships bin\n// commands (wp-start-update, wp-finish-update, wp-finish-upsert-pr, wp-start-upsert-pr).\n// The build gate and 3-point merge-info gathering are internal `workflow/` library functions\n// (runBuildAffected, gatherInfo), not bins. Shared library exports (dashboard gate computation,\n// etc.) back the dashboard those commands render.\n\nexport {\n GateResult,\n DisableCounts,\n DashboardInput,\n computeGateResults,\n countAddedDisables,\n renderDashboard,\n} from './dashboard/dashboard';\n"]}
@@ -52,8 +52,8 @@ function printHashPoints(hashes, currentBranch, mergeDir) {
52
52
  }
53
53
  // Gather the 3-point merge context for the current feature branch (fetches main, finds the fork
54
54
  // point, writes updatemain-hashes.json) and RETURN whether the branch is already even with main.
55
- // NEVER calls process.exit: it is called both as a library (merge-start) and via the wp-git-gather
56
- // bin. Callers decide what to do with an up-to-date branch; the bin just prints and exits 0.
55
+ // NEVER calls process.exit: it is called as a library (from merge-start). Callers decide what to
56
+ // do with an up-to-date branch.
57
57
  async function gatherInfo() {
58
58
  const currentBranch = (0, child_process_1.execSync)('git branch --show-current', { encoding: 'utf8' }).trim();
59
59
  const featureName = (0, git_readAiBranchName_1.getFeatureName)();
@@ -1 +1 @@
1
- {"version":3,"file":"git-gatherInfo.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-gatherInfo.ts"],"names":[],"mappings":";;;AA8DA,gCAyCC;;AAvGD,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAuD;AACvD,0EAAiE;AACjE,oEAA6D;AAC7D,wDAAqD;AACrD,kDAAsD;AAEtD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAQvE,sGAAsG;AACtG,sGAAsG;AACtG,oGAAoG;AACpG,6EAA6E;AAC7E,MAAa,gBAAgB;IACzB,eAAe,CAAU;IACzB,MAAM,CAAa;IAEnB,YAAY,eAAwB,EAAE,MAAkB;QACpD,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,MAAM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":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { CliExitError } from '@webpieces/rules-config';\nimport { getFeatureName } from './workflow/git-readAiBranchName';\nimport { findForkPoint } from './workflow/git-findForkPoint';\nimport { mergeDirFor } from './workflow/merge-state';\nimport { assertCleanTree } from './workflow/git-exec';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\ninterface HashPoints {\n hashForkPoint: string;\n hashFeatureHead: string;\n hashMainHead: string;\n}\n\n// Result of gathering merge context: whether the branch is already even with main (fork point == main\n// HEAD, so there is nothing to merge) plus the 3 hash points. A class (not an object literal) per the\n// codebase's data-structure convention. gatherInfo RETURNS this instead of calling process.exit — a\n// library function must never exit the process (see CliExitError / runMain).\nexport class GatherInfoResult {\n alreadyUpToDate: boolean;\n hashes: HashPoints;\n\n constructor(alreadyUpToDate: boolean, hashes: HashPoints) {\n this.alreadyUpToDate = alreadyUpToDate;\n this.hashes = hashes;\n }\n}\n\nfunction validateCleanTree(currentBranch: string, repoRoot: string): void {\n if (currentBranch === 'main') {\n throw new CliExitError(1, '❌ Error: Already on main branch. No need to update from main.');\n }\n process.stderr.write(`Current branch: ${currentBranch}\\n`);\n // Require a fully-committed tree (tracked AND untracked). The old check used `git diff-index`,\n // which is tracked-only, so a stale untracked dir slipped through and was later swept into the\n // squash commit by `git add -A`. assertCleanTree uses `git status --porcelain` (untracked-aware,\n // gitignore-respecting) and aborts with instructions — the tooling never commits your work for you.\n assertCleanTree(repoRoot);\n}\n\nfunction printHashPoints(hashes: HashPoints, currentBranch: string, mergeDir: string): void {\n process.stderr.write('📍 The 3 Hash Points:\\n');\n process.stderr.write(` 1. Fork point (A): ${hashes.hashForkPoint}\\n`);\n process.stderr.write(` (where ${currentBranch} diverged from main)\\n`);\n process.stderr.write('\\n');\n process.stderr.write(` 2. Feature HEAD (B): ${hashes.hashFeatureHead}\\n`);\n process.stderr.write(` (tip of ${currentBranch})\\n`);\n process.stderr.write('\\n');\n process.stderr.write(` 3. Main HEAD (C): ${hashes.hashMainHead}\\n`);\n process.stderr.write(' (current origin/main)\\n');\n process.stderr.write('\\n');\n process.stderr.write(`Merge directory: ${mergeDir}\\n`);\n process.stderr.write('\\n');\n}\n\n// Gather the 3-point merge context for the current feature branch (fetches main, finds the fork\n// point, writes updatemain-hashes.json) and RETURN whether the branch is already even with main.\n// NEVER calls process.exit: it is called both as a library (merge-start) and via the wp-git-gather\n// bin. Callers decide what to do with an up-to-date branch; the bin just prints and exits 0.\nexport async function gatherInfo(): Promise<GatherInfoResult> {\n const currentBranch = execSync('git branch --show-current', { encoding: 'utf8' }).trim();\n const featureName = getFeatureName();\n const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();\n const mergeDir = mergeDirFor(repoRoot, featureName);\n fs.mkdirSync(mergeDir, { recursive: true });\n\n validateCleanTree(currentBranch, repoRoot);\n\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('📍 Gathering Merge Context\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n process.stderr.write('Fetching latest changes from origin/main...\\n');\n spawnSync('git', ['fetch', 'origin', 'main'], { stdio: 'inherit' });\n\n await findForkPoint('merge');\n\n const hashesFile = path.join(mergeDir, 'updatemain-hashes.json');\n const hashes = JSON.parse(fs.readFileSync(hashesFile, 'utf8')) as HashPoints;\n\n printHashPoints(hashes, currentBranch, mergeDir);\n\n if (hashes.hashForkPoint === hashes.hashMainHead) {\n process.stderr.write(SEP);\n process.stderr.write('✅ Already up to date with main!\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n process.stderr.write('Your branch has not diverged from main.\\n');\n process.stderr.write('There are no new changes from main to merge.\\n');\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n return new GatherInfoResult(true, hashes);\n }\n\n process.stderr.write('Main has advanced. Merge will be needed.\\n');\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n return new GatherInfoResult(false, hashes);\n}\n"]}
1
+ {"version":3,"file":"git-gatherInfo.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-gatherInfo.ts"],"names":[],"mappings":";;;AA8DA,gCAyCC;;AAvGD,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAuD;AACvD,0EAAiE;AACjE,oEAA6D;AAC7D,wDAAqD;AACrD,kDAAsD;AAEtD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAQvE,sGAAsG;AACtG,sGAAsG;AACtG,oGAAoG;AACpG,6EAA6E;AAC7E,MAAa,gBAAgB;IACzB,eAAe,CAAU;IACzB,MAAM,CAAa;IAEnB,YAAY,eAAwB,EAAE,MAAkB;QACpD,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AARD,4CAQC;AAED,SAAS,iBAAiB,CAAC,aAAqB,EAAE,QAAgB;IAC9D,IAAI,aAAa,KAAK,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,2BAAY,CAAC,CAAC,EAAE,+DAA+D,CAAC,CAAC;IAC/F,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,aAAa,IAAI,CAAC,CAAC;IAC3D,+FAA+F;IAC/F,+FAA+F;IAC/F,iGAAiG;IACjG,oGAAoG;IACpG,IAAA,0BAAe,EAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,eAAe,CAAC,MAAkB,EAAE,aAAqB,EAAE,QAAgB;IAChF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAChD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,MAAM,CAAC,aAAa,IAAI,CAAC,CAAC;IACzE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,aAAa,wBAAwB,CAAC,C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gDAAgD,CAAC,CAAC;QACvE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;IACnE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,IAAI,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { CliExitError } from '@webpieces/rules-config';\nimport { getFeatureName } from './workflow/git-readAiBranchName';\nimport { findForkPoint } from './workflow/git-findForkPoint';\nimport { mergeDirFor } from './workflow/merge-state';\nimport { assertCleanTree } from './workflow/git-exec';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\ninterface HashPoints {\n hashForkPoint: string;\n hashFeatureHead: string;\n hashMainHead: string;\n}\n\n// Result of gathering merge context: whether the branch is already even with main (fork point == main\n// HEAD, so there is nothing to merge) plus the 3 hash points. A class (not an object literal) per the\n// codebase's data-structure convention. gatherInfo RETURNS this instead of calling process.exit — a\n// library function must never exit the process (see CliExitError / runMain).\nexport class GatherInfoResult {\n alreadyUpToDate: boolean;\n hashes: HashPoints;\n\n constructor(alreadyUpToDate: boolean, hashes: HashPoints) {\n this.alreadyUpToDate = alreadyUpToDate;\n this.hashes = hashes;\n }\n}\n\nfunction validateCleanTree(currentBranch: string, repoRoot: string): void {\n if (currentBranch === 'main') {\n throw new CliExitError(1, '❌ Error: Already on main branch. No need to update from main.');\n }\n process.stderr.write(`Current branch: ${currentBranch}\\n`);\n // Require a fully-committed tree (tracked AND untracked). The old check used `git diff-index`,\n // which is tracked-only, so a stale untracked dir slipped through and was later swept into the\n // squash commit by `git add -A`. assertCleanTree uses `git status --porcelain` (untracked-aware,\n // gitignore-respecting) and aborts with instructions — the tooling never commits your work for you.\n assertCleanTree(repoRoot);\n}\n\nfunction printHashPoints(hashes: HashPoints, currentBranch: string, mergeDir: string): void {\n process.stderr.write('📍 The 3 Hash Points:\\n');\n process.stderr.write(` 1. Fork point (A): ${hashes.hashForkPoint}\\n`);\n process.stderr.write(` (where ${currentBranch} diverged from main)\\n`);\n process.stderr.write('\\n');\n process.stderr.write(` 2. Feature HEAD (B): ${hashes.hashFeatureHead}\\n`);\n process.stderr.write(` (tip of ${currentBranch})\\n`);\n process.stderr.write('\\n');\n process.stderr.write(` 3. Main HEAD (C): ${hashes.hashMainHead}\\n`);\n process.stderr.write(' (current origin/main)\\n');\n process.stderr.write('\\n');\n process.stderr.write(`Merge directory: ${mergeDir}\\n`);\n process.stderr.write('\\n');\n}\n\n// Gather the 3-point merge context for the current feature branch (fetches main, finds the fork\n// point, writes updatemain-hashes.json) and RETURN whether the branch is already even with main.\n// NEVER calls process.exit: it is called as a library (from merge-start). Callers decide what to\n// do with an up-to-date branch.\nexport async function gatherInfo(): Promise<GatherInfoResult> {\n const currentBranch = execSync('git branch --show-current', { encoding: 'utf8' }).trim();\n const featureName = getFeatureName();\n const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();\n const mergeDir = mergeDirFor(repoRoot, featureName);\n fs.mkdirSync(mergeDir, { recursive: true });\n\n validateCleanTree(currentBranch, repoRoot);\n\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('📍 Gathering Merge Context\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n process.stderr.write('Fetching latest changes from origin/main...\\n');\n spawnSync('git', ['fetch', 'origin', 'main'], { stdio: 'inherit' });\n\n await findForkPoint('merge');\n\n const hashesFile = path.join(mergeDir, 'updatemain-hashes.json');\n const hashes = JSON.parse(fs.readFileSync(hashesFile, 'utf8')) as HashPoints;\n\n printHashPoints(hashes, currentBranch, mergeDir);\n\n if (hashes.hashForkPoint === hashes.hashMainHead) {\n process.stderr.write(SEP);\n process.stderr.write('✅ Already up to date with main!\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n process.stderr.write('Your branch has not diverged from main.\\n');\n process.stderr.write('There are no new changes from main to merge.\\n');\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n return new GatherInfoResult(true, hashes);\n }\n\n process.stderr.write('Main has advanced. Merge will be needed.\\n');\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n return new GatherInfoResult(false, hashes);\n}\n"]}
@@ -7,10 +7,9 @@ exports.runConfiguredBuildGate = runConfiguredBuildGate;
7
7
  exports.runBuildGate = runBuildGate;
8
8
  const child_process_1 = require("child_process");
9
9
  const rules_config_1 = require("@webpieces/rules-config");
10
- // Single source of truth for the build gate. Both `wp-build-affected` (CI + local) and the
11
- // merge validation gate (`wp-finish-upsert-pr`) run THIS, so "what CI runs" and "what the
12
- // PR command runs" can never drift. nx `affected` only rebuilds changed projects, so this
13
- // stays fast on a large monorepo.
10
+ // Single source of truth for the build gate. The PR flow's advisory gate (`wp-start-upsert-pr`)
11
+ // and authoritative merge gate (`wp-finish-upsert-pr`) both run THIS, so the two can never drift.
12
+ // nx `affected` only rebuilds changed projects, so this stays fast on a large monorepo.
14
13
  // `--base=$(git merge-base origin/main HEAD)` (the fork point) instead of `--base=origin/main`:
15
14
  // origin/main rebuilds projects touched by OTHER people's merged PRs (your branch still holds the
16
15
  // pre-merge versions, so nx sees them as "affected"). The fork point scopes affected to only YOUR
@@ -1 +1 @@
1
- {"version":3,"file":"build-affected.js","sourceRoot":"","sources":["../../../../../../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CAAC;AAED,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;GAKG;AACH,MAAa,gBAAgB;IACzB,KAAK,CAAS,CAAY,sCAAsC;IAChE,YAAY,CAAS,CAAK,gDAAgD;IAC1E,eAAe,CAAS,CAAE,gCAAgC;IAE1D,YAAY,KAAa,EAAE,YAAoB,EAAE,eAAuB;QACpE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;CACJ;AAVD,4CAUC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,QAAgB,EAAE,IAAsB;IACjE,MAAM,YAAY,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACnD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;IAClE,OAAO,CAAC,MAAM,CAAC,KAAK,CAChB,6GAA6G;QAC7G,OAAO,YAAY,MAAM,CAC5B,CAAC;IACF,MAAM,SAAS,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IACnD,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,2BAAY,CAAC,SAAS,EAC5B,OAAO,IAAI,CAAC,eAAe,MAAM;YACjC,uEAAuE,IAAI,CAAC,YAAY,OAAO;YAC/F,OAAO,YAAY,IAAI,CAC1B,CAAC;IACN,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import { spawnSync } from 'child_process';\nimport { loadAndValidate, CliExitError } from '@webpieces/rules-config';\n\n// Single source of truth for the build gate. Both `wp-build-affected` (CI + local) and the\n// merge validation gate (`wp-finish-upsert-pr`) run THIS, so \"what CI runs\" and \"what the\n// PR command runs\" can never drift. nx `affected` only rebuilds changed projects, so this\n// stays fast on a large monorepo.\n// `--base=$(git merge-base origin/main HEAD)` (the fork point) instead of `--base=origin/main`:\n// origin/main rebuilds projects touched by OTHER people's merged PRs (your branch still holds the\n// pre-merge versions, so nx sees them as \"affected\"). The fork point scopes affected to only YOUR\n// branch's changes. The `$(...)` resolves because runBuildAffected runs with shell: true.\nexport const DEFAULT_BUILD_COMMAND = 'pnpm nx affected --target=ci --base=$(git merge-base origin/main HEAD)';\n\n/**\n * Resolve the exact build command this gate will run for a repo: the project's configured\n * PrGateConfig.buildCommand, or the default affected-ci command when none is set. Callers\n * print this so the AI knows precisely which command to run locally to get the gate passing.\n */\nexport function resolveBuildCommand(repoRoot: string): string {\n const configured = loadAndValidate(repoRoot).prGate.buildCommand;\n return configured !== undefined && configured.trim() !== '' ? configured : DEFAULT_BUILD_COMMAND;\n}\n\n/**\n * Run the build gate. Returns the process exit code (0 = pass). `buildCommand` overrides\n * the default (sourced from PrGateConfig.buildCommand by callers); empty/undefined uses the\n * default affected-ci command.\n */\nexport function runBuildAffected(repoRoot: string, buildCommand?: string): number {\n const cmd = buildCommand !== undefined && buildCommand.trim() !== '' ? buildCommand : DEFAULT_BUILD_COMMAND;\n process.stdout.write(`\\n▶ Build gate: ${cmd}\\n\\n`);\n const result = spawnSync(cmd, { stdio: 'inherit', cwd: repoRoot, shell: true });\n return result.status ?? 1;\n}\n\n/**\n * Run the build gate using the project's configured command (PrGateConfig.buildCommand). The\n * finish-upsert-pr gate and wp-start-upsert-pr both call THIS so they provably build with the same\n * command — the resolution the AI validates is built exactly as the PR command builds it.\n * Returns the exit code; callers print their own re-run hint.\n */\nexport function runConfiguredBuildGate(repoRoot: string): number {\n return runBuildAffected(repoRoot, loadAndValidate(repoRoot).prGate.buildCommand);\n}\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * The two facts that differ between the wp-start (advisory) and wp-finish (authoritative) build\n * gates. Everything else — resolve command, run it, print the re-run hint, exit non-zero on failure\n * — is identical, so it lives once in runBuildGate and the difference is passed in here. A class (not\n * an object literal) 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\n constructor(label: string, rerunCommand: string, failureHeadline: string) {\n this.label = label;\n this.rerunCommand = rerunCommand;\n this.failureHeadline = failureHeadline;\n }\n}\n\n/**\n * Run the configured build gate with consistent framing, throwing CliExitError(buildCode) on failure\n * so the bin's main()/runMain owns the exit. Single source of truth: wp-start-upsert-pr and\n * wp-finish-upsert-pr both call THIS (only the BuildGateOptions differ) so a fix to the gate flow is\n * made once, not in two near-identical copies.\n */\nexport function runBuildGate(repoRoot: string, opts: BuildGateOptions): void {\n const buildCommand = resolveBuildCommand(repoRoot);\n process.stdout.write('\\n' + SEP + opts.label + '\\n' + SEP + '\\n');\n process.stdout.write(\n `Running the build gate. To get it passing, run the SAME command yourself and fix everything it reports:\\n\\n` +\n ` ${buildCommand}\\n\\n`,\n );\n const buildCode = runConfiguredBuildGate(repoRoot);\n if (buildCode !== 0) {\n throw new CliExitError(buildCode,\n `\\n❌ ${opts.failureHeadline}\\n\\n` +\n `Run THIS exact command to reproduce and fix all errors, then re-run ${opts.rerunCommand}:\\n\\n` +\n ` ${buildCommand}\\n`,\n );\n }\n process.stdout.write('\\n✅ Build passed.\\n');\n}\n"]}
1
+ {"version":3,"file":"build-affected.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-affected.ts"],"names":[],"mappings":";;;AAiBA,kDAGC;AAOD,4CAKC;AAQD,wDAEC;AA4BD,oCAgBC;AAtFD,iDAA0C;AAC1C,0DAAwE;AAExE,gGAAgG;AAChG,kGAAkG;AAClG,wFAAwF;AACxF,gGAAgG;AAChG,kGAAkG;AAClG,kGAAkG;AAClG,0FAA0F;AAC7E,QAAA,qBAA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AAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;CACJ;AAVD,4CAUC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,QAAgB,EAAE,IAAsB;IACjE,MAAM,YAAY,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACnD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;IAClE,OAAO,CAAC,MAAM,CAAC,KAAK,CAChB,6GAA6G;QAC7G,OAAO,YAAY,MAAM,CAC5B,CAAC;IACF,MAAM,SAAS,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IACnD,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,2BAAY,CAAC,SAAS,EAC5B,OAAO,IAAI,CAAC,eAAe,MAAM;YACjC,uEAAuE,IAAI,CAAC,YAAY,OAAO;YAC/F,OAAO,YAAY,IAAI,CAC1B,CAAC;IACN,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import { spawnSync } from 'child_process';\nimport { loadAndValidate, CliExitError } from '@webpieces/rules-config';\n\n// Single source of truth for the build gate. The PR flow's advisory gate (`wp-start-upsert-pr`)\n// and authoritative merge gate (`wp-finish-upsert-pr`) both run THIS, so the two can never drift.\n// nx `affected` only rebuilds changed projects, so this stays fast on a large monorepo.\n// `--base=$(git merge-base origin/main HEAD)` (the fork point) instead of `--base=origin/main`:\n// origin/main rebuilds projects touched by OTHER people's merged PRs (your branch still holds the\n// pre-merge versions, so nx sees them as \"affected\"). The fork point scopes affected to only YOUR\n// branch's changes. The `$(...)` resolves because runBuildAffected runs with shell: true.\nexport const DEFAULT_BUILD_COMMAND = 'pnpm nx affected --target=ci --base=$(git merge-base origin/main HEAD)';\n\n/**\n * Resolve the exact build command this gate will run for a repo: the project's configured\n * PrGateConfig.buildCommand, or the default affected-ci command when none is set. Callers\n * print this so the AI knows precisely which command to run locally to get the gate passing.\n */\nexport function resolveBuildCommand(repoRoot: string): string {\n const configured = loadAndValidate(repoRoot).prGate.buildCommand;\n return configured !== undefined && configured.trim() !== '' ? configured : DEFAULT_BUILD_COMMAND;\n}\n\n/**\n * Run the build gate. Returns the process exit code (0 = pass). `buildCommand` overrides\n * the default (sourced from PrGateConfig.buildCommand by callers); empty/undefined uses the\n * default affected-ci command.\n */\nexport function runBuildAffected(repoRoot: string, buildCommand?: string): number {\n const cmd = buildCommand !== undefined && buildCommand.trim() !== '' ? buildCommand : DEFAULT_BUILD_COMMAND;\n process.stdout.write(`\\n▶ Build gate: ${cmd}\\n\\n`);\n const result = spawnSync(cmd, { stdio: 'inherit', cwd: repoRoot, shell: true });\n return result.status ?? 1;\n}\n\n/**\n * Run the build gate using the project's configured command (PrGateConfig.buildCommand). The\n * finish-upsert-pr gate and wp-start-upsert-pr both call THIS so they provably build with the same\n * command — the resolution the AI validates is built exactly as the PR command builds it.\n * Returns the exit code; callers print their own re-run hint.\n */\nexport function runConfiguredBuildGate(repoRoot: string): number {\n return runBuildAffected(repoRoot, loadAndValidate(repoRoot).prGate.buildCommand);\n}\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * The two facts that differ between the wp-start (advisory) and wp-finish (authoritative) build\n * gates. Everything else — resolve command, run it, print the re-run hint, exit non-zero on failure\n * — is identical, so it lives once in runBuildGate and the difference is passed in here. A class (not\n * an object literal) 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\n constructor(label: string, rerunCommand: string, failureHeadline: string) {\n this.label = label;\n this.rerunCommand = rerunCommand;\n this.failureHeadline = failureHeadline;\n }\n}\n\n/**\n * Run the configured build gate with consistent framing, throwing CliExitError(buildCode) on failure\n * so the bin's main()/runMain owns the exit. Single source of truth: wp-start-upsert-pr and\n * wp-finish-upsert-pr both call THIS (only the BuildGateOptions differ) so a fix to the gate flow is\n * made once, not in two near-identical copies.\n */\nexport function runBuildGate(repoRoot: string, opts: BuildGateOptions): void {\n const buildCommand = resolveBuildCommand(repoRoot);\n process.stdout.write('\\n' + SEP + opts.label + '\\n' + SEP + '\\n');\n process.stdout.write(\n `Running the build gate. To get it passing, run the SAME command yourself and fix everything it reports:\\n\\n` +\n ` ${buildCommand}\\n\\n`,\n );\n const buildCode = runConfiguredBuildGate(repoRoot);\n if (buildCode !== 0) {\n throw new CliExitError(buildCode,\n `\\n❌ ${opts.failureHeadline}\\n\\n` +\n `Run THIS exact command to reproduce and fix all errors, then re-run ${opts.rerunCommand}:\\n\\n` +\n ` ${buildCommand}\\n`,\n );\n }\n process.stdout.write('\\n✅ Build passed.\\n');\n}\n"]}
@@ -14,7 +14,7 @@ const SEP = '━━━━━━━━━━━━━━━━━━━━━━
14
14
  function printMergeFromMainError(commit, parent, featureName, currentBranch) {
15
15
  process.stderr.write('\n');
16
16
  process.stderr.write(SEP);
17
- process.stderr.write('❌ This branch merged main without pnpm wp-update-start\n');
17
+ process.stderr.write('❌ This branch merged main without pnpm wp-start-update\n');
18
18
  process.stderr.write(SEP);
19
19
  process.stderr.write('\n');
20
20
  process.stderr.write(`Merge commit detected: ${commit}\n`);
@@ -1 +1 @@
1
- {"version":3,"file":"git-findForkPoint.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-findForkPoint.ts"],"names":[],"mappings":";;AA2EA,gDAEC;AAED,sCAqDC;AAED,oBAEC;;AAxID,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAA0E;AAC1E,iEAAwD;AACxD,+CAA4C;AAE5C,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE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AO,CAAC,MAAM,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC;QAC9B,aAAa,EAAE,SAAS;QACxB,eAAe,EAAE,WAAW;QAC5B,YAAY,EAAE,UAAU;QACxB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACtC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAEZ,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,MAAM,aAAa,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC,CAAC;IAClF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,SAAS,IAAI,MAAM,eAAe,CAAC,CAAC;AAC1F,CAAC;AAEM,KAAK,UAAU,IAAI;IACtB,MAAM,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAC/C,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;IAAE,IAAA,sBAAO,EAAC,IAAI,CAAC,CAAC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { prDirFor, CliExitError, runMain } from '@webpieces/rules-config';\nimport { getFeatureName } from './git-readAiBranchName';\nimport { mergeDirFor } from './merge-state';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\nfunction printMergeFromMainError(commit: string, parent: string, featureName: string, currentBranch: string): void {\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('❌ This branch merged main without pnpm wp-update-start\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n process.stderr.write(`Merge commit detected: ${commit}\\n`);\n process.stderr.write(`Parent from main: ${parent}\\n`);\n process.stderr.write('\\n');\n process.stderr.write('This prevents clean squash-merge. To recover, follow these steps:\\n');\n process.stderr.write('\\n');\n process.stderr.write('1. Fetch the latest main (works on the primary repo AND in a worktree):\\n');\n process.stderr.write(' git fetch origin main\\n');\n process.stderr.write('\\n');\n process.stderr.write('2. Create a new branch OFF origin/main — do NOT `git checkout main`\\n');\n process.stderr.write(' (it fatals inside a worktree: \"main is already checked out at <primary>\"):\\n');\n process.stderr.write(` git checkout -b ${featureName}-v2 origin/main\\n`);\n process.stderr.write('\\n');\n process.stderr.write('3. Squash merge your old branch:\\n');\n process.stderr.write(` git merge --squash ${currentBranch}\\n`);\n process.stderr.write('\\n');\n process.stderr.write('4. Commit the squashed changes:\\n');\n process.stderr.write(` git add -A && git commit -m \"Squashed from ${currentBranch}\"\\n`);\n process.stderr.write('\\n');\n process.stderr.write('5. If you have an existing PR:\\n');\n process.stderr.write(` - Create a NEW PR for ${featureName}-v2\\n`);\n process.stderr.write(` - Close the old PR for ${currentBranch}\\n`);\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n}\n\nfunction checkMergeCommits(mergeCommits: string[], outputDir: string, prefix: string, featureName: string, currentBranch: string): void {\n process.stderr.write(`Found ${mergeCommits.length} merge commit(s) to check...\\n`);\n\n for (const commit of mergeCommits) {\n const parentsResult = spawnSync('git', ['rev-list', '--parents', '-n', '1', commit], { encoding: 'utf8' });\n const parents = (parentsResult.stdout ?? '').trim().split(' ').slice(1);\n\n for (const parent of parents) {\n const ancestorCheck = spawnSync('git', ['merge-base', '--is-ancestor', parent, 'origin/main']);\n const reverseCheck = spawnSync('git', ['merge-base', '--is-ancestor', 'origin/main', parent]);\n\n if (ancestorCheck.status === 0 && reverseCheck.status === 0) {\n const errorJson = JSON.stringify({\n error: 'Merge from main detected',\n mergeCommit: commit,\n parentFromMain: parent,\n timestamp: new Date().toISOString(),\n }, null, 2);\n\n fs.writeFileSync(path.join(outputDir, `${prefix}forkpoint-error.json`), errorJson + '\\n');\n printMergeFromMainError(commit, parent, featureName, currentBranch);\n throw new CliExitError(1, '');\n }\n }\n }\n process.stderr.write('✅ No improper merges from main detected\\n');\n}\n\n// Single source of truth for the per-feature dir fork-point output is written to — the SAME nested\n// home the readers use (git-gatherInfo / merge-start read updatemain-hashes.json from mergeDirFor;\n// the review flow reads from prDirFor). Previously findForkPoint wrote to the legacy flat\n// `.webpieces/<workflow>-<feature>/` while readers looked under `.webpieces/merge-info/<feature>/`,\n// so the hash file was written to one path and read from another. Routing the writer through these\n// same helpers is what keeps them from diverging again — guarded by git-findForkPoint.spec.ts.\nexport function forkPointOutputDir(repoRoot: string, featureName: string, workflow: string): string {\n return workflow === 'review' ? prDirFor(repoRoot, featureName) : mergeDirFor(repoRoot, featureName);\n}\n\nexport async function findForkPoint(workflow: string): Promise<void> {\n if (workflow !== 'review' && workflow !== 'merge') {\n throw new CliExitError(1,\n 'ERROR: Workflow argument required\\n' +\n 'Usage: git-findForkPoint <workflow>\\n' +\n \" workflow: 'review' or 'merge'\",\n );\n }\n\n const featureName = getFeatureName();\n const currentBranch = execSync('git branch --show-current', { encoding: 'utf8' }).trim();\n const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();\n\n const outputDir = forkPointOutputDir(repoRoot, featureName, workflow);\n const prefix = workflow === 'review' ? 'review-' : 'updatemain-';\n fs.mkdirSync(outputDir, { recursive: true });\n\n spawnSync('git', ['fetch', 'origin', 'main'], { stdio: 'ignore' });\n\n const featureHead = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();\n const originMain = execSync('git rev-parse origin/main', { encoding: 'utf8' }).trim();\n\n process.stderr.write('Finding fork point using git merge-base...\\n');\n\n const forkPointResult = spawnSync('git', ['merge-base', 'origin/main', 'HEAD'], { encoding: 'utf8' });\n const forkPoint = (forkPointResult.stdout ?? '').trim();\n\n if (!forkPoint || forkPointResult.status !== 0) {\n throw new CliExitError(1, 'ERROR: Could not find common ancestor with origin/main');\n }\n\n process.stderr.write(`✅ Fork point found: ${forkPoint.slice(0, 7)}\\n`);\n process.stderr.write('Checking for improper merges from main...\\n');\n\n const mergeCommitsResult = spawnSync('git', ['log', `${forkPoint}..HEAD`, '--merges', '--format=%H'], { encoding: 'utf8' });\n const mergeCommitsRaw = (mergeCommitsResult.stdout ?? '').trim();\n const mergeCommits = mergeCommitsRaw ? mergeCommitsRaw.split('\\n') : [];\n\n if (mergeCommits.length > 0) {\n checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch);\n } else {\n process.stderr.write('✅ No merge commits found (clean history)\\n');\n }\n\n const hashesJson = JSON.stringify({\n hashForkPoint: forkPoint,\n hashFeatureHead: featureHead,\n hashMainHead: originMain,\n timestamp: new Date().toISOString(),\n }, null, 2);\n\n fs.writeFileSync(path.join(outputDir, `${prefix}hashes.json`), hashesJson + '\\n');\n process.stderr.write(`✅ Hash points written to: ${outputDir}/${prefix}hashes.json\\n`);\n}\n\nexport async function main(): Promise<void> {\n await findForkPoint(process.argv[2] ?? '');\n}\n\nif (require.main === module) runMain(main);\n"]}
1
+ {"version":3,"file":"git-findForkPoint.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-findForkPoint.ts"],"names":[],"mappings":";;AA2EA,gDAEC;AAED,sCAqDC;AAED,oBAEC;;AAxID,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAA0E;AAC1E,iEAAwD;AACxD,+CAA4C;AAE5C,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,SAAS,uBAAuB,CAAC,MAAc,EAAE,MAAc,EAAE,WAAmB,EAAE,aAAqB;IACvG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAC;IACjF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,CAAC,M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,CAAC,SAAS,EAAE,GAAG,MAAM,aAAa,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC,CAAC;IAClF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,SAAS,IAAI,MAAM,eAAe,CAAC,CAAC;AAC1F,CAAC;AAEM,KAAK,UAAU,IAAI;IACtB,MAAM,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAC/C,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;IAAE,IAAA,sBAAO,EAAC,IAAI,CAAC,CAAC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { prDirFor, CliExitError, runMain } from '@webpieces/rules-config';\nimport { getFeatureName } from './git-readAiBranchName';\nimport { mergeDirFor } from './merge-state';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\nfunction printMergeFromMainError(commit: string, parent: string, featureName: string, currentBranch: string): void {\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('❌ This branch merged main without pnpm wp-start-update\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n process.stderr.write(`Merge commit detected: ${commit}\\n`);\n process.stderr.write(`Parent from main: ${parent}\\n`);\n process.stderr.write('\\n');\n process.stderr.write('This prevents clean squash-merge. To recover, follow these steps:\\n');\n process.stderr.write('\\n');\n process.stderr.write('1. Fetch the latest main (works on the primary repo AND in a worktree):\\n');\n process.stderr.write(' git fetch origin main\\n');\n process.stderr.write('\\n');\n process.stderr.write('2. Create a new branch OFF origin/main — do NOT `git checkout main`\\n');\n process.stderr.write(' (it fatals inside a worktree: \"main is already checked out at <primary>\"):\\n');\n process.stderr.write(` git checkout -b ${featureName}-v2 origin/main\\n`);\n process.stderr.write('\\n');\n process.stderr.write('3. Squash merge your old branch:\\n');\n process.stderr.write(` git merge --squash ${currentBranch}\\n`);\n process.stderr.write('\\n');\n process.stderr.write('4. Commit the squashed changes:\\n');\n process.stderr.write(` git add -A && git commit -m \"Squashed from ${currentBranch}\"\\n`);\n process.stderr.write('\\n');\n process.stderr.write('5. If you have an existing PR:\\n');\n process.stderr.write(` - Create a NEW PR for ${featureName}-v2\\n`);\n process.stderr.write(` - Close the old PR for ${currentBranch}\\n`);\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n}\n\nfunction checkMergeCommits(mergeCommits: string[], outputDir: string, prefix: string, featureName: string, currentBranch: string): void {\n process.stderr.write(`Found ${mergeCommits.length} merge commit(s) to check...\\n`);\n\n for (const commit of mergeCommits) {\n const parentsResult = spawnSync('git', ['rev-list', '--parents', '-n', '1', commit], { encoding: 'utf8' });\n const parents = (parentsResult.stdout ?? '').trim().split(' ').slice(1);\n\n for (const parent of parents) {\n const ancestorCheck = spawnSync('git', ['merge-base', '--is-ancestor', parent, 'origin/main']);\n const reverseCheck = spawnSync('git', ['merge-base', '--is-ancestor', 'origin/main', parent]);\n\n if (ancestorCheck.status === 0 && reverseCheck.status === 0) {\n const errorJson = JSON.stringify({\n error: 'Merge from main detected',\n mergeCommit: commit,\n parentFromMain: parent,\n timestamp: new Date().toISOString(),\n }, null, 2);\n\n fs.writeFileSync(path.join(outputDir, `${prefix}forkpoint-error.json`), errorJson + '\\n');\n printMergeFromMainError(commit, parent, featureName, currentBranch);\n throw new CliExitError(1, '');\n }\n }\n }\n process.stderr.write('✅ No improper merges from main detected\\n');\n}\n\n// Single source of truth for the per-feature dir fork-point output is written to — the SAME nested\n// home the readers use (git-gatherInfo / merge-start read updatemain-hashes.json from mergeDirFor;\n// the review flow reads from prDirFor). Previously findForkPoint wrote to the legacy flat\n// `.webpieces/<workflow>-<feature>/` while readers looked under `.webpieces/merge-info/<feature>/`,\n// so the hash file was written to one path and read from another. Routing the writer through these\n// same helpers is what keeps them from diverging again — guarded by git-findForkPoint.spec.ts.\nexport function forkPointOutputDir(repoRoot: string, featureName: string, workflow: string): string {\n return workflow === 'review' ? prDirFor(repoRoot, featureName) : mergeDirFor(repoRoot, featureName);\n}\n\nexport async function findForkPoint(workflow: string): Promise<void> {\n if (workflow !== 'review' && workflow !== 'merge') {\n throw new CliExitError(1,\n 'ERROR: Workflow argument required\\n' +\n 'Usage: git-findForkPoint <workflow>\\n' +\n \" workflow: 'review' or 'merge'\",\n );\n }\n\n const featureName = getFeatureName();\n const currentBranch = execSync('git branch --show-current', { encoding: 'utf8' }).trim();\n const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();\n\n const outputDir = forkPointOutputDir(repoRoot, featureName, workflow);\n const prefix = workflow === 'review' ? 'review-' : 'updatemain-';\n fs.mkdirSync(outputDir, { recursive: true });\n\n spawnSync('git', ['fetch', 'origin', 'main'], { stdio: 'ignore' });\n\n const featureHead = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();\n const originMain = execSync('git rev-parse origin/main', { encoding: 'utf8' }).trim();\n\n process.stderr.write('Finding fork point using git merge-base...\\n');\n\n const forkPointResult = spawnSync('git', ['merge-base', 'origin/main', 'HEAD'], { encoding: 'utf8' });\n const forkPoint = (forkPointResult.stdout ?? '').trim();\n\n if (!forkPoint || forkPointResult.status !== 0) {\n throw new CliExitError(1, 'ERROR: Could not find common ancestor with origin/main');\n }\n\n process.stderr.write(`✅ Fork point found: ${forkPoint.slice(0, 7)}\\n`);\n process.stderr.write('Checking for improper merges from main...\\n');\n\n const mergeCommitsResult = spawnSync('git', ['log', `${forkPoint}..HEAD`, '--merges', '--format=%H'], { encoding: 'utf8' });\n const mergeCommitsRaw = (mergeCommitsResult.stdout ?? '').trim();\n const mergeCommits = mergeCommitsRaw ? mergeCommitsRaw.split('\\n') : [];\n\n if (mergeCommits.length > 0) {\n checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch);\n } else {\n process.stderr.write('✅ No merge commits found (clean history)\\n');\n }\n\n const hashesJson = JSON.stringify({\n hashForkPoint: forkPoint,\n hashFeatureHead: featureHead,\n hashMainHead: originMain,\n timestamp: new Date().toISOString(),\n }, null, 2);\n\n fs.writeFileSync(path.join(outputDir, `${prefix}hashes.json`), hashesJson + '\\n');\n process.stderr.write(`✅ Hash points written to: ${outputDir}/${prefix}hashes.json\\n`);\n}\n\nexport async function main(): Promise<void> {\n await findForkPoint(process.argv[2] ?? '');\n}\n\nif (require.main === module) runMain(main);\n"]}
@@ -39,7 +39,7 @@ async function main() {
39
39
  process.stdout.write(SEP);
40
40
  process.stdout.write('\n');
41
41
  process.stdout.write('1. Update your branch with latest main:\n');
42
- process.stdout.write(' pnpm wp-update-start\n');
42
+ process.stdout.write(' pnpm wp-start-update\n');
43
43
  process.stdout.write('\n');
44
44
  process.stdout.write('2. ⚠️ IMPORTANT: REVIEW THE CODE AFTER MERGE!\n');
45
45
  process.stdout.write(' - Check for merge conflicts\n');
@@ -1 +1 @@
1
- {"version":3,"file":"git-validateUpToDate.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-validateUpToDate.ts"],"names":[],"mappings":";;AAKA,oBAqEC;AA1ED,iDAAoD;AACpD,0DAAgE;AAEhE,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEhE,KAAK,UAAU,IAAI;IACtB,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,2BAA2B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAElF,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAClE,OAAO;IACX,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC9E,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,MAAM,IAAI,CAAC,CAAC;IACpD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAA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━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\nexport async function main(): Promise<void> {\n const branch = execSync('git branch --show-current', { encoding: 'utf8' }).trim();\n\n if (branch === 'main') {\n process.stdout.write('✅ On main branch - no validation needed\\n');\n return;\n }\n\n process.stdout.write('Validating branch is up to date with origin/main...\\n');\n process.stdout.write(`Current branch: ${branch}\\n`);\n process.stdout.write('\\n');\n\n process.stdout.write('Fetching latest from origin/main...\\n');\n spawnSync('git', ['fetch', 'origin', 'main', '--quiet'], { stdio: 'inherit' });\n\n const isUpToDate = spawnSync('git', ['merge-base', '--is-ancestor', 'origin/main', 'HEAD']).status === 0;\n\n if (isUpToDate) {\n process.stdout.write('✅ Branch is up to date with origin/main\\n');\n return;\n }\n\n const behindResult = spawnSync('git', ['rev-list', '--count', 'HEAD..origin/main'], { encoding: 'utf8' });\n const commitsBehind = (behindResult.stdout ?? '').trim();\n\n const recentResult = spawnSync('git', ['log', '--oneline', 'HEAD..origin/main'], { encoding: 'utf8' });\n const recentLines = (recentResult.stdout ?? '').split('\\n').filter((l: string) => l).slice(0, 5).join('\\n');\n\n process.stdout.write('\\n');\n process.stdout.write(SEP);\n process.stdout.write('❌ ERROR: Branch is NOT up to date with origin/main\\n');\n process.stdout.write(SEP);\n process.stdout.write('\\n');\n process.stdout.write(`Your branch is ${commitsBehind} commit(s) behind origin/main\\n`);\n process.stdout.write('\\n');\n process.stdout.write('Recent commits in origin/main not in your branch:\\n');\n process.stdout.write(recentLines + '\\n');\n process.stdout.write('\\n');\n process.stdout.write(SEP);\n process.stdout.write('⚠️ CRITICAL: You must update your branch first!\\n');\n process.stdout.write(SEP);\n process.stdout.write('\\n');\n process.stdout.write('1. Update your branch with latest main:\\n');\n process.stdout.write(' pnpm wp-update-start\\n');\n process.stdout.write('\\n');\n process.stdout.write('2. ⚠️ IMPORTANT: REVIEW THE CODE AFTER MERGE!\\n');\n process.stdout.write(' - Check for merge conflicts\\n');\n process.stdout.write(' - Review how your changes interact with new main code\\n');\n process.stdout.write(' - Test that everything still works\\n');\n process.stdout.write(' - This is where things often go wrong!\\n');\n process.stdout.write('\\n');\n process.stdout.write('3. After reviewing, run your command again\\n');\n process.stdout.write('\\n');\n process.stdout.write(SEP);\n process.stdout.write('Why this matters:\\n');\n process.stdout.write(SEP);\n process.stdout.write('\\n');\n process.stdout.write('- Your test plan should cover how your changes work with\\n');\n process.stdout.write(' the LATEST code from main, not outdated code\\n');\n process.stdout.write('- Merging main might introduce conflicts or integration\\n');\n process.stdout.write(' issues that need testing\\n');\n process.stdout.write('- Your changes might interact unexpectedly with new code\\n');\n process.stdout.write(' from main\\n');\n process.stdout.write('\\n');\n process.stdout.write(SEP);\n\n // The full guidance was already printed to stdout above; throw with an empty message so runMain\n // exits 1 without echoing a redundant line.\n throw new CliExitError(1, '');\n}\n\nif (require.main === module) runMain(main);\n"]}
1
+ {"version":3,"file":"git-validateUpToDate.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-validateUpToDate.ts"],"names":[],"mappings":";;AAKA,oBAqEC;AA1ED,iDAAoD;AACpD,0DAAgE;AAEhE,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEhE,KAAK,UAAU,IAAI;IACtB,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,2BAA2B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAElF,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAClE,OAAO;IACX,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC9E,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,MAAM,IAAI,CAAC,CAAC;IACpD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;I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6CAA6C,CAAC,CAAC;IACpE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;IACrE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC5C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,4DAA4D,CAAC,CAAC;IACnF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACzE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAClF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IACrD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,4DAA4D,CAAC,CAAC;IACnF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IACtC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE1B,gGAAgG;IAChG,4CAA4C;IAC5C,MAAM,IAAI,2BAAY,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;IAAE,IAAA,sBAAO,EAAC,IAAI,CAAC,CAAC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport { CliExitError, runMain } from '@webpieces/rules-config';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\nexport async function main(): Promise<void> {\n const branch = execSync('git branch --show-current', { encoding: 'utf8' }).trim();\n\n if (branch === 'main') {\n process.stdout.write('✅ On main branch - no validation needed\\n');\n return;\n }\n\n process.stdout.write('Validating branch is up to date with origin/main...\\n');\n process.stdout.write(`Current branch: ${branch}\\n`);\n process.stdout.write('\\n');\n\n process.stdout.write('Fetching latest from origin/main...\\n');\n spawnSync('git', ['fetch', 'origin', 'main', '--quiet'], { stdio: 'inherit' });\n\n const isUpToDate = spawnSync('git', ['merge-base', '--is-ancestor', 'origin/main', 'HEAD']).status === 0;\n\n if (isUpToDate) {\n process.stdout.write('✅ Branch is up to date with origin/main\\n');\n return;\n }\n\n const behindResult = spawnSync('git', ['rev-list', '--count', 'HEAD..origin/main'], { encoding: 'utf8' });\n const commitsBehind = (behindResult.stdout ?? '').trim();\n\n const recentResult = spawnSync('git', ['log', '--oneline', 'HEAD..origin/main'], { encoding: 'utf8' });\n const recentLines = (recentResult.stdout ?? '').split('\\n').filter((l: string) => l).slice(0, 5).join('\\n');\n\n process.stdout.write('\\n');\n process.stdout.write(SEP);\n process.stdout.write('❌ ERROR: Branch is NOT up to date with origin/main\\n');\n process.stdout.write(SEP);\n process.stdout.write('\\n');\n process.stdout.write(`Your branch is ${commitsBehind} commit(s) behind origin/main\\n`);\n process.stdout.write('\\n');\n process.stdout.write('Recent commits in origin/main not in your branch:\\n');\n process.stdout.write(recentLines + '\\n');\n process.stdout.write('\\n');\n process.stdout.write(SEP);\n process.stdout.write('⚠️ CRITICAL: You must update your branch first!\\n');\n process.stdout.write(SEP);\n process.stdout.write('\\n');\n process.stdout.write('1. Update your branch with latest main:\\n');\n process.stdout.write(' pnpm wp-start-update\\n');\n process.stdout.write('\\n');\n process.stdout.write('2. ⚠️ IMPORTANT: REVIEW THE CODE AFTER MERGE!\\n');\n process.stdout.write(' - Check for merge conflicts\\n');\n process.stdout.write(' - Review how your changes interact with new main code\\n');\n process.stdout.write(' - Test that everything still works\\n');\n process.stdout.write(' - This is where things often go wrong!\\n');\n process.stdout.write('\\n');\n process.stdout.write('3. After reviewing, run your command again\\n');\n process.stdout.write('\\n');\n process.stdout.write(SEP);\n process.stdout.write('Why this matters:\\n');\n process.stdout.write(SEP);\n process.stdout.write('\\n');\n process.stdout.write('- Your test plan should cover how your changes work with\\n');\n process.stdout.write(' the LATEST code from main, not outdated code\\n');\n process.stdout.write('- Merging main might introduce conflicts or integration\\n');\n process.stdout.write(' issues that need testing\\n');\n process.stdout.write('- Your changes might interact unexpectedly with new code\\n');\n process.stdout.write(' from main\\n');\n process.stdout.write('\\n');\n process.stdout.write(SEP);\n\n // The full guidance was already printed to stdout above; throw with an empty message so runMain\n // exits 1 without echoing a redundant line.\n throw new CliExitError(1, '');\n}\n\nif (require.main === module) runMain(main);\n"]}
@@ -14,7 +14,7 @@ const merge_state_1 = require("./merge-state");
14
14
  // the branch context, it (optionally) validates + commits the AI's conflict resolution, then ALWAYS
15
15
  // finalizes the merge — force-pushes `<branch>Squash` to the stable feature branch and renames it
16
16
  // BACK to that same feature name (local == remote == PR head), stamps a clean main-sync status,
17
- // clears the marker and sweeps stale tmp. The shared runUpdateFromMain (clean path / validated resume), wp-update-end, and
17
+ // clears the marker and sweeps stale tmp. The shared runUpdateFromMain (clean path / validated resume), wp-finish-update, and
18
18
  // wp-finish-upsert-pr (conflict resolution) all call THIS, so finalization happens in exactly one
19
19
  // place and the conflict path can no longer post a PR from the un-swapped squash branch.
20
20
  const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
@@ -1 +1 @@
1
- {"version":3,"file":"merge-end.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/merge-end.ts"],"names":[],"mappings":";;AAqJA,4BA8BC;;AAnLD,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAGiC;AACjC,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AC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,oBAAoB,CAAC,EAAE,EAAE,CAAC,CAAC;QAChE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACjE,CAAC;IAED,gGAAgG;IAChG,mGAAmG;IACnG,6EAA6E;IAC7E,MAAM,WAAW,GAAG,IAAA,6BAAe,EAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;IACvD,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;IACjD,IAAA,8BAAgB,EAAC,QAAQ,CAAC,CAAC;IAC3B,MAAM,IAAA,mBAAQ,GAAE,CAAC;AACrB,CAAC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport {\n MERGE_EXPLANATION_FILE, stampCleanMainSyncStatus, CliExitError,\n MutationVerb, BranchMutationEvent, logBranchMutation,\n} from '@webpieces/rules-config';\nimport { baseBranchName } from './branch-naming';\nimport { cleanTmp } from './cleanTmp';\nimport { assertNoUntracked, runGitChecked } from './git-exec';\nimport { MergeContext } from './merge-start';\nimport { clearMergeMarker, readMergeMarker, perFileContextDir, scanConflictMarkers, scanMergeExplanations } from './merge-state';\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 the merge — force-pushes `<branch>Squash` to the stable feature branch and renames it\n// BACK to that same feature name (local == remote == PR head), stamps a clean main-sync status,\n// clears the marker and sweeps stale tmp. The shared runUpdateFromMain (clean path / validated resume), wp-update-end, and\n// wp-finish-upsert-pr (conflict resolution) all call THIS, so finalization happens in exactly one\n// place and the conflict path can no longer post a PR from the un-swapped squash branch.\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// Validate the AI's resolution of the conflicted files — the part of the process the AI owns\n// (branch creation/finalization is the script's job, so it is not re-checked here). Throws\n// CliExitError with a fix instruction on any failure; returns only when all three checks pass.\nfunction validateResolution(repoRoot: string, mergeDir: string, conflictedFiles: string[]): void {\n // 1. Scoped conflict-marker scan (only the conflicted files — O(conflicts), not O(repo)).\n const scan = 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: pnpm wp-finish-upsert-pr',\n );\n }\n\n // 2. Ensure git itself has no remaining unmerged entries.\n const unmerged = execSync('git diff --name-only --diff-filter=U', { encoding: 'utf8' }).trim();\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: pnpm wp-finish-upsert-pr',\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\n // its per-file context dir, proving the AI deliberately 3-point merged it (and recording how)\n // rather than blindly taking one side. A sidecar file works for any type, incl. JSON/deletes.\n const explanations = scanMergeExplanations(mergeDir, conflictedFiles);\n if (!explanations.clean) {\n const missing = explanations.filesWithMarkers\n .map((file: string): string => ` - ${file}\\n → ${path.join(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: pnpm wp-finish-upsert-pr',\n );\n }\n process.stdout.write('✅ Merge explanations present for all resolved files.\\n');\n}\n\nfunction localBranchExists(name: string): boolean {\n return spawnSync('git', ['show-ref', '--verify', '--quiet', `refs/heads/${name}`]).status === 0;\n}\n\n// Force-push the squash branch to the stable feature branch (where the single PR lives), then RENAME\n// the local squash branch back to that SAME feature name — so the local branch, the remote branch,\n// and the PR head are all one name (no `wpN` divergence). On a CLEAN sync (`!hadConflict`) the\n// pre-merge snapshot is disposable, so it's deleted at the very end; a CONFLICT sync keeps it (paired\n// with its `merge-<n>/` context). Ends with an explicit \"here is exactly what I did\" recap.\nfunction finalizeBranch(repoRoot: string, verb: MutationVerb, ctx: MergeContext, hadConflict: boolean): void {\n process.stdout.write('\\n' + SEP + '🗑️ Finalizing\\n' + SEP + '\\n');\n const base = baseBranchName(ctx.currentBranch);\n runGitChecked(['branch', '-D', ctx.currentBranch], 'Failed to delete old feature branch');\n\n const remoteExists = spawnSync('git', ['ls-remote', '--exit-code', '--heads', 'origin', base]).status === 0;\n if (remoteExists) {\n process.stdout.write(ctx.prNumber ? `Updating PR #${ctx.prNumber} (force-with-lease)...\\n` : 'Updating remote branch (force-with-lease)...\\n');\n runGitChecked(['push', '-u', '--force-with-lease', 'origin', `${ctx.squashBranch}:${base}`], 'Failed to push to origin');\n } else {\n process.stdout.write('No remote branch — local only.\\n');\n }\n runGitChecked(['checkout', ctx.squashBranch], 'Failed to checkout squash branch');\n // Free the rename target: `base` is normally the branch we just deleted (ctx.currentBranch), but on\n // a backward-compat sync from a leftover `…wpN` a separate stale `base` can linger — drop it too.\n if (base !== ctx.currentBranch && localBranchExists(base)) {\n runGitChecked(['branch', '-D', base], 'Failed to delete stale base branch');\n }\n 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(execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim());\n\n // Clean sync → the pre-merge snapshot was never needed; delete it (LAST, so any earlier finalize\n // failure above keeps it). Conflict sync → keep it as the undo point + trail.\n const backupKept = hadConflict;\n if (!backupKept && localBranchExists(ctx.backupBranch)) {\n 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 printSyncRecap(base, ctx.backupBranch, ctx.prNumber, remoteExists, backupKept);\n}\n\n// The explicit, numbered \"here is exactly what I did\" recap the AI (and human) reads after a sync.\n// The whole point of the branch-name change is that step 4 can now say \"same name as remote/PR\" —\n// there is no confusing local-vs-remote divergence left to explain.\nfunction printSyncRecap(feature: string, backupBranch: string, prNumber: string, pushed: boolean, backupKept: boolean): void {\n const remoteLine = pushed\n ? `landed back on ${feature} (== origin/${feature}${prNumber ? ` == PR #${prNumber}` : ''} — names match)`\n : `landed back on ${feature} (local only — no remote branch yet)`;\n const step1 = backupKept\n ? `snapshotted your pre-merge state → ${backupBranch} (kept — this merge had conflicts)`\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/**\n * Complete a 3-point squash merge. `conflictedFiles` non-null means a conflict was resolved by the AI\n * and must be validated + committed before finalizing; null means a clean merge that merge-START\n * already committed (finalize only). Either way the merge ends fully finalized on the feature branch.\n */\nexport async function mergeEnd(\n repoRoot: string, verb: MutationVerb, mergeDir: string, ctx: MergeContext, conflictedFiles: string[] | null,\n): Promise<void> {\n if (conflictedFiles !== null) {\n process.stdout.write('\\n' + SEP + '🔎 Validating Merge Resolution\\n' + SEP + '\\n');\n validateResolution(repoRoot, mergeDir, conflictedFiles);\n // Stage the AI's resolved conflicts, but NEVER sweep untracked files into the squash commit\n // (a blanket `git add -A` once swept a stale untracked dir in). Fail on untracked so the AI\n // commits or deletes them explicitly; then `git add -u` stages tracked resolutions only.\n assertNoUntracked(repoRoot);\n runGitChecked(['add', '-u'], 'Failed to stage resolved files');\n\n const nothingStaged = spawnSync('git', ['diff-index', '--quiet', '--cached', 'HEAD', '--']).status === 0;\n if (!nothingStaged) {\n 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 // correct even for the validated-resume path (conflictedFiles=null yet a conflict). Read it BEFORE\n // clearMergeMarker so finalize knows whether to keep the pre-merge snapshot.\n const hadConflict = readMergeMarker(mergeDir) !== null;\n finalizeBranch(repoRoot, verb, ctx, hadConflict);\n clearMergeMarker(mergeDir);\n await cleanTmp();\n}\n"]}
1
+ {"version":3,"file":"merge-end.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/merge-end.ts"],"names":[],"mappings":";;AAqJA,4BA8BC;;AAnLD,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAGiC;AACjC,mDAAiD;AACjD,yCAAsC;AACtC,yCAA8D;AAE9D,+CAAiI;AAEjI,sGAAsG;AACtG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EAAE,CAAC,CAAC;QAChE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACjE,CAAC;IAED,gGAAgG;IAChG,mGAAmG;IACnG,6EAA6E;IAC7E,MAAM,WAAW,GAAG,IAAA,6BAAe,EAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;IACvD,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;IACjD,IAAA,8BAAgB,EAAC,QAAQ,CAAC,CAAC;IAC3B,MAAM,IAAA,mBAAQ,GAAE,CAAC;AACrB,CAAC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport {\n MERGE_EXPLANATION_FILE, stampCleanMainSyncStatus, CliExitError,\n MutationVerb, BranchMutationEvent, logBranchMutation,\n} from '@webpieces/rules-config';\nimport { baseBranchName } from './branch-naming';\nimport { cleanTmp } from './cleanTmp';\nimport { assertNoUntracked, runGitChecked } from './git-exec';\nimport { MergeContext } from './merge-start';\nimport { clearMergeMarker, readMergeMarker, perFileContextDir, scanConflictMarkers, scanMergeExplanations } from './merge-state';\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 the merge — force-pushes `<branch>Squash` to the stable feature branch and renames it\n// BACK to that same feature name (local == remote == PR head), stamps a clean main-sync status,\n// clears the marker and sweeps stale tmp. The shared runUpdateFromMain (clean path / validated resume), wp-finish-update, and\n// wp-finish-upsert-pr (conflict resolution) all call THIS, so finalization happens in exactly one\n// place and the conflict path can no longer post a PR from the un-swapped squash branch.\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// Validate the AI's resolution of the conflicted files — the part of the process the AI owns\n// (branch creation/finalization is the script's job, so it is not re-checked here). Throws\n// CliExitError with a fix instruction on any failure; returns only when all three checks pass.\nfunction validateResolution(repoRoot: string, mergeDir: string, conflictedFiles: string[]): void {\n // 1. Scoped conflict-marker scan (only the conflicted files — O(conflicts), not O(repo)).\n const scan = 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: pnpm wp-finish-upsert-pr',\n );\n }\n\n // 2. Ensure git itself has no remaining unmerged entries.\n const unmerged = execSync('git diff --name-only --diff-filter=U', { encoding: 'utf8' }).trim();\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: pnpm wp-finish-upsert-pr',\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\n // its per-file context dir, proving the AI deliberately 3-point merged it (and recording how)\n // rather than blindly taking one side. A sidecar file works for any type, incl. JSON/deletes.\n const explanations = scanMergeExplanations(mergeDir, conflictedFiles);\n if (!explanations.clean) {\n const missing = explanations.filesWithMarkers\n .map((file: string): string => ` - ${file}\\n → ${path.join(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: pnpm wp-finish-upsert-pr',\n );\n }\n process.stdout.write('✅ Merge explanations present for all resolved files.\\n');\n}\n\nfunction localBranchExists(name: string): boolean {\n return spawnSync('git', ['show-ref', '--verify', '--quiet', `refs/heads/${name}`]).status === 0;\n}\n\n// Force-push the squash branch to the stable feature branch (where the single PR lives), then RENAME\n// the local squash branch back to that SAME feature name — so the local branch, the remote branch,\n// and the PR head are all one name (no `wpN` divergence). On a CLEAN sync (`!hadConflict`) the\n// pre-merge snapshot is disposable, so it's deleted at the very end; a CONFLICT sync keeps it (paired\n// with its `merge-<n>/` context). Ends with an explicit \"here is exactly what I did\" recap.\nfunction finalizeBranch(repoRoot: string, verb: MutationVerb, ctx: MergeContext, hadConflict: boolean): void {\n process.stdout.write('\\n' + SEP + '🗑️ Finalizing\\n' + SEP + '\\n');\n const base = baseBranchName(ctx.currentBranch);\n runGitChecked(['branch', '-D', ctx.currentBranch], 'Failed to delete old feature branch');\n\n const remoteExists = spawnSync('git', ['ls-remote', '--exit-code', '--heads', 'origin', base]).status === 0;\n if (remoteExists) {\n process.stdout.write(ctx.prNumber ? `Updating PR #${ctx.prNumber} (force-with-lease)...\\n` : 'Updating remote branch (force-with-lease)...\\n');\n runGitChecked(['push', '-u', '--force-with-lease', 'origin', `${ctx.squashBranch}:${base}`], 'Failed to push to origin');\n } else {\n process.stdout.write('No remote branch — local only.\\n');\n }\n runGitChecked(['checkout', ctx.squashBranch], 'Failed to checkout squash branch');\n // Free the rename target: `base` is normally the branch we just deleted (ctx.currentBranch), but on\n // a backward-compat sync from a leftover `…wpN` a separate stale `base` can linger — drop it too.\n if (base !== ctx.currentBranch && localBranchExists(base)) {\n runGitChecked(['branch', '-D', base], 'Failed to delete stale base branch');\n }\n 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(execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim());\n\n // Clean sync → the pre-merge snapshot was never needed; delete it (LAST, so any earlier finalize\n // failure above keeps it). Conflict sync → keep it as the undo point + trail.\n const backupKept = hadConflict;\n if (!backupKept && localBranchExists(ctx.backupBranch)) {\n 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 printSyncRecap(base, ctx.backupBranch, ctx.prNumber, remoteExists, backupKept);\n}\n\n// The explicit, numbered \"here is exactly what I did\" recap the AI (and human) reads after a sync.\n// The whole point of the branch-name change is that step 4 can now say \"same name as remote/PR\" —\n// there is no confusing local-vs-remote divergence left to explain.\nfunction printSyncRecap(feature: string, backupBranch: string, prNumber: string, pushed: boolean, backupKept: boolean): void {\n const remoteLine = pushed\n ? `landed back on ${feature} (== origin/${feature}${prNumber ? ` == PR #${prNumber}` : ''} — names match)`\n : `landed back on ${feature} (local only — no remote branch yet)`;\n const step1 = backupKept\n ? `snapshotted your pre-merge state → ${backupBranch} (kept — this merge had conflicts)`\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/**\n * Complete a 3-point squash merge. `conflictedFiles` non-null means a conflict was resolved by the AI\n * and must be validated + committed before finalizing; null means a clean merge that merge-START\n * already committed (finalize only). Either way the merge ends fully finalized on the feature branch.\n */\nexport async function mergeEnd(\n repoRoot: string, verb: MutationVerb, mergeDir: string, ctx: MergeContext, conflictedFiles: string[] | null,\n): Promise<void> {\n if (conflictedFiles !== null) {\n process.stdout.write('\\n' + SEP + '🔎 Validating Merge Resolution\\n' + SEP + '\\n');\n validateResolution(repoRoot, mergeDir, conflictedFiles);\n // Stage the AI's resolved conflicts, but NEVER sweep untracked files into the squash commit\n // (a blanket `git add -A` once swept a stale untracked dir in). Fail on untracked so the AI\n // commits or deletes them explicitly; then `git add -u` stages tracked resolutions only.\n assertNoUntracked(repoRoot);\n runGitChecked(['add', '-u'], 'Failed to stage resolved files');\n\n const nothingStaged = spawnSync('git', ['diff-index', '--quiet', '--cached', 'HEAD', '--']).status === 0;\n if (!nothingStaged) {\n 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 // correct even for the validated-resume path (conflictedFiles=null yet a conflict). Read it BEFORE\n // clearMergeMarker so finalize knows whether to keep the pre-merge snapshot.\n const hadConflict = readMergeMarker(mergeDir) !== null;\n finalizeBranch(repoRoot, verb, ctx, hadConflict);\n clearMergeMarker(mergeDir);\n await cleanTmp();\n}\n"]}
@@ -16,9 +16,9 @@ const merge_state_1 = require("./merge-state");
16
16
  // process doc, then hands control back to the AI. On a clean merge it commits the squash and returns
17
17
  // the branch context so the caller (runUpdateFromMain) can run merge-END to finalize. It NEVER
18
18
  // finalizes or posts a PR — that is merge-END's / wp-finish-upsert-pr's job. Shared so
19
- // runUpdateFromMain (and, via it, wp-update-start + wp-start-upsert-pr) all set up a merge through
19
+ // runUpdateFromMain (and, via it, wp-start-update + wp-start-upsert-pr) all set up a merge through
20
20
  // one code path. `finishCommand` names the command the AI runs to finish after resolving conflicts
21
- // (standalone update → `wp-update-end`; PR flow → `wp-finish-upsert-pr`).
21
+ // (standalone update → `wp-finish-update`; PR flow → `wp-finish-upsert-pr`).
22
22
  const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
23
23
  // The four branch names merge-END needs to finalize a merge (swap squash→feature, push, clean up).
24
24
  class MergeContext {
@@ -104,7 +104,7 @@ function saveConflictContext(conflictedFiles, mergeDir, forkPoint, featureHead,
104
104
  // is a template constant with {{...}} placeholders so this stays a small filler function.
105
105
  const MERGE_PROCESS_TEMPLATE = `# AI-Assisted Squash-Merge Conflict Resolution (generated)
106
106
 
107
- This file was generated by \`pnpm wp-update-start\` when the 3-point squash-merge hit conflicts.
107
+ This file was generated by \`pnpm wp-start-update\` when the 3-point squash-merge hit conflicts.
108
108
  It is the single source of truth for the merge process — follow it exactly.
109
109
 
110
110
  You are on branch \`{{SQUASH_BRANCH}}\` with conflict markers in the working tree.
@@ -1 +1 @@
1
- {"version":3,"file":"merge-start.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/merge-start.ts"],"names":[],"mappings":";;;AA4SA,gCAgEC;;AA5WD,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAGiC;AACjC,sDAA+C;AAC/C,mDAA6F;AAC7F,yCAA2C;AAC3C,+CAAiG;AAEjG,qGAAqG;AACrG,oGAAoG;AACpG,qGAAqG;AACrG,+FAA+F;AAC/F,uFAAuF;AACvF,mGAAmG;AACnG,mGAAmG;AACnG,0EAA0E;AAE1E,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAQvE,mGAAmG;AACnG,MAAa,YAAY;IACrB,aAAa,CAAS;IACtB,YAAY,CAAS;IACrB,YAAY,CAAS;IACrB,QAAQ,CAAS;IAEjB,YAAY,aAAqB,EAAE,YAAoB,EAAE,YAAoB,EAAE,QAAgB;QAC3F,IAAI,CAAC,aAAa,GA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C,CAAC;IAErE,MAAM,aAAa,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACzG,IAAI,aAAa,EAAE,CAAC;QAChB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,wDAAwD,CAAC,CAAC;IACnF,CAAC;SAAM,CAAC;QACJ,IAAA,wBAAa,EAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,mBAAmB,aAAa,EAAE,CAAC,EAAE,+BAA+B,CAAC,CAAC;IACzG,CAAC;IACD,OAAO,IAAI,gBAAgB,CAAC,OAAO,EAAE,IAAI,YAAY,CAAC,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;AAC1H,CAAC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport {\n WEBPIECES_TMP_DIR, MERGE_EXPLANATION_FILE, CliExitError,\n MutationVerb, BranchMutationEvent, logBranchMutation,\n} from '@webpieces/rules-config';\nimport { gatherInfo } from '../git-gatherInfo';\nimport { baseBranchName, nextFreePreMergeNumber, preMergeBackupName } from './branch-naming';\nimport { runGitChecked } from './git-exec';\nimport { MergeMarker, perFileContextDir, writeMergeMarker, mergeRunDirFor } from './merge-state';\n\n// merge-START: the first half of the 3-point squash-merge lifecycle. Brings origin/main into a fresh\n// `<branch>Squash`, and on conflict writes the 3-point context files + the unvalidated marker + the\n// process doc, then hands control back to the AI. On a clean merge it commits the squash and returns\n// the branch context so the caller (runUpdateFromMain) can run merge-END to finalize. It NEVER\n// finalizes or posts a PR — that is merge-END's / wp-finish-upsert-pr's job. Shared so\n// runUpdateFromMain (and, via it, wp-update-start + wp-start-upsert-pr) all set up a merge through\n// one code path. `finishCommand` names the command the AI runs to finish after resolving conflicts\n// (standalone update → `wp-update-end`; PR flow → `wp-finish-upsert-pr`).\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\ninterface HashPoints {\n hashForkPoint: string;\n hashFeatureHead: string;\n hashMainHead: string;\n}\n\n// The four branch names merge-END needs to finalize a merge (swap squash→feature, push, clean up).\nexport class MergeContext {\n currentBranch: string;\n squashBranch: string;\n backupBranch: string;\n prNumber: string;\n\n constructor(currentBranch: string, squashBranch: string, backupBranch: string, prNumber: string) {\n this.currentBranch = currentBranch;\n this.squashBranch = squashBranch;\n this.backupBranch = backupBranch;\n this.prNumber = prNumber;\n }\n}\n\n// Outcome of merge-start: 'clean' carries the context for merge-END to finalize; 'conflict' means the\n// marker + context files were written and the caller should hand back to the AI (exit 2).\nexport class MergeStartResult {\n status: 'clean' | 'conflict';\n context: MergeContext | null;\n runDir: string; // this sync's numbered `merge-<n>/` dir — passed to merge-END so it reads THIS marker\n\n constructor(status: 'clean' | 'conflict', context: MergeContext | null, runDir: string) {\n this.status = status;\n this.context = context;\n this.runDir = runDir;\n }\n}\n\n// Detect the PR by its STABLE feature branch — pass baseBranchName(currentBranch) so a leftover\n// `…wpN` from the old scheme still resolves to the one name the PR lives on.\nfunction detectPr(baseBranch: string): string {\n const result = spawnSync(\n 'gh', ['pr', 'list', '--head', baseBranch, '--json', 'number', '--jq', '.[0].number'],\n { encoding: 'utf8' },\n );\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n}\n\n// The one number `n` for a sync and the two things it names: the pre-merge backup branch and its\n// paired conflict-context run dir.\nclass SyncSlot {\n backupBranch: string;\n runDir: string;\n\n constructor(backupBranch: string, runDir: string) {\n this.backupBranch = backupBranch;\n this.runDir = runDir;\n }\n}\n\n// Pick the first free `<branch>PreMerge<n>` slot number, then WIPE the paired `<home>/merge-<n>/` run\n// dir — a fresh sync means no merge is in progress, so any leftover `merge-<n>` is stale (its own sync\n// ended, or its branch was deleted) and MUST NOT leak its old per-file merge-explanation.md into this\n// merge's validation. Returns the backup branch name + the (now-empty) run dir path, both keyed on `n`.\nfunction chooseSyncSlot(home: string, currentBranch: string): SyncSlot {\n const n = nextFreePreMergeNumber(\n currentBranch,\n (name: string): boolean => spawnSync('git', ['show-ref', '--verify', '--quiet', `refs/heads/${name}`]).status === 0,\n );\n const runDir = mergeRunDirFor(home, n);\n fs.rmSync(runDir, { recursive: true, force: true });\n return new SyncSlot(preMergeBackupName(currentBranch, n), runDir);\n}\n\n// Snapshot the pre-merge state onto the caller-chosen `backupBranch` (`<currentBranch>PreMerge<n>`),\n// never overwriting. The slot number `n` is picked once in mergeStart and shared with the paired\n// `merge-<n>/` context dir. A clean sync deletes this snapshot at finalize; only conflict syncs keep it.\nfunction createBackup(currentBranch: string, backupBranch: string): void {\n process.stdout.write('\\n' + SEP + '💾 Creating Pre-Merge Backup\\n' + SEP + '\\n');\n runGitChecked(['checkout', '-b', backupBranch], 'Failed to create backup branch');\n runGitChecked(['checkout', currentBranch], 'Failed to return to feature branch');\n process.stdout.write(`✅ Backup created: ${backupBranch}\\n\\n`);\n}\n\nfunction saveConflictContext(\n conflictedFiles: string[], mergeDir: string, forkPoint: string, featureHead: string, mainHead: string,\n): void {\n for (const file of conflictedFiles) {\n const fileDir = perFileContextDir(mergeDir, file);\n fs.mkdirSync(fileDir, { recursive: true });\n\n const fork = spawnSync('git', ['show', `${forkPoint}:${file}`], { encoding: 'utf8' });\n fs.writeFileSync(path.join(fileDir, 'A-forkpoint.txt'), fork.status === 0 ? (fork.stdout ?? '') : '(file did not exist)\\n');\n const feature = spawnSync('git', ['show', `${featureHead}:${file}`], { encoding: 'utf8' });\n fs.writeFileSync(path.join(fileDir, 'B-feature.txt'), feature.status === 0 ? (feature.stdout ?? '') : '(file did not exist)\\n');\n const main = spawnSync('git', ['show', `${mainHead}:${file}`], { encoding: 'utf8' });\n fs.writeFileSync(path.join(fileDir, 'C-main.txt'), main.status === 0 ? (main.stdout ?? '') : '(file did not exist)\\n');\n\n const ba = spawnSync('git', ['diff', forkPoint, featureHead, '--', file], { encoding: 'utf8' });\n fs.writeFileSync(path.join(fileDir, 'B-A.diff'), ba.stdout ?? '');\n const ca = spawnSync('git', ['diff', forkPoint, mainHead, '--', file], { encoding: 'utf8' });\n fs.writeFileSync(path.join(fileDir, 'C-A.diff'), ca.stdout ?? '');\n }\n}\n\n// Single source of truth for the merge process. The script WRITES it at conflict time (rather\n// than the AI relying on a separate hand-maintained doc), parameterized with the live MERGE_DIR\n// and conflicted-file list, so the instructions can never drift from the actual layout. The body\n// is a template constant with {{...}} placeholders so this stays a small filler function.\nconst MERGE_PROCESS_TEMPLATE = `# AI-Assisted Squash-Merge Conflict Resolution (generated)\n\nThis file was generated by \\`pnpm wp-update-start\\` when the 3-point squash-merge hit conflicts.\nIt is the single source of truth for the merge process — follow it exactly.\n\nYou are on branch \\`{{SQUASH_BRANCH}}\\` with conflict markers in the working tree.\n\\`MERGE_DIR = {{MERGE_DIR}}\\`\n\n## How the gate works\n\n- Resolve every conflicted file in the working tree.\n- Run **\\`pnpm {{FINISH_COMMAND}}\\`** — the validation + finish gate. It scans for leftover conflict\n markers, checks each conflicted file has a written merge explanation, validates, and commits the\n merge. (In the PR flow this command is \\`wp-finish-upsert-pr\\`, which additionally runs the\n \\`nx affected\\` build, renders the dashboard, and creates/updates the PR.)\n- **Do NOT run \\`git add\\` / \\`git commit\\` / \\`git push\\` / \\`gh pr\\` yourself.** They are blocked by\n the \\`merge-in-progress-guard\\` hook until the gate validates. The gate does the commit.\n\n## STEP 1 — Load the merge context\n\nPer conflicted file, \\`MERGE_DIR/updatemain-<safe_path>/\\` holds (\\`<safe_path>\\` = path with \\`/\\`→\\`__\\`):\n\n\\`\\`\\`\nA-forkpoint.txt # file at fork point (base)\nB-feature.txt # file on your feature branch\nC-main.txt # file on main\nB-A.diff # what your feature changed (B−A)\nC-A.diff # what main changed (C−A)\n\\`\\`\\`\n\n\\`updatemain-hashes.json\\` holds A/B/C commit hashes. To see why main changed:\n\\`git log <A>..<C> --oneline\\`.\n\n## STEP 2 — Resolve each conflicted file\n\nFor each file: read the working-tree file (the markers) and its \\`B-A.diff\\` / \\`C-A.diff\\` (intent),\nthen Edit to the resolved version, removing ALL conflict markers.\n\nStrategies: goals align & non-overlapping → merge both · one side removes what the other modifies\n→ prefer the removal · same lines, simple (imports/format) → merge both · same lines, complex or\nconflicting goals → ask the user · feature re-implements what main already squashed → prefer\nmain's, then re-apply only the genuinely new feature work.\n\n**Then write a merge explanation** for each conflicted file — NOT a comment in the source (that\nbreaks for JSON and deleted files). Write it next to that file's diffs, at:\n\n\\`\\`\\`\nMERGE_DIR/updatemain-<safe_path>/{{EXPLANATION_FILE}}\n\\`\\`\\`\n\n(\\`<safe_path>\\` = the conflict file path with \\`/\\` → \\`__\\`, the same dir that holds its\n\\`A-forkpoint.txt\\` / \\`B-A.diff\\` / \\`C-A.diff\\`.) In it, explain in a few sentences how you resolved\nthis file: which side you took where, what you combined from B-A.diff vs C-A.diff, and why. The\ngate fails if any conflicted file's explanation is missing or empty. Do not paste A/B/C context\nblocks into the source code.\n\n## STEP 3 — Run the gate (validates the merge AND finalizes it)\n\n\\`\\`\\`\npnpm {{FINISH_COMMAND}}\n\\`\\`\\`\n\n- Leftover conflict markers → fix those files and re-run.\n- Missing merge explanation → write it (see STEP 2) and re-run.\n- Build failure → fix the TypeScript/lint errors and re-run (the gate re-stages for you).\n- Missing review.json (PR flow only) → write it in the printed format (your PR review), then re-run.\n- On success it commits and finalizes the merge (in the PR flow it also renders the dashboard and\n creates/updates the PR).\n\n## Conflicted files\n\n{{FILE_LIST}}\n\n## If you need to bail out\n\nA numbered backup branch was created (e.g. \\`<feature>PreMerge1\\`). To abandon:\n\n\\`\\`\\`\ngit merge --abort 2>/dev/null; git checkout <feature> ; git branch -D {{SQUASH_BRANCH}}\n\\`\\`\\`\n\nThen delete \\`{{MERGE_DIR}}/\\` for a clean slate.\n`;\n\nfunction mergeProcessDoc(mergeDir: string, squashBranch: string, conflictedFiles: string[], finishCommand: string): string {\n const fileList = conflictedFiles.map((f: string): string => `- \\`${f}\\``).join('\\n');\n return MERGE_PROCESS_TEMPLATE\n .replace(/\\{\\{SQUASH_BRANCH\\}\\}/g, squashBranch)\n .replace(/\\{\\{MERGE_DIR\\}\\}/g, mergeDir)\n .replace(/\\{\\{EXPLANATION_FILE\\}\\}/g, MERGE_EXPLANATION_FILE)\n .replace(/\\{\\{FINISH_COMMAND\\}\\}/g, finishCommand)\n .replace(/\\{\\{FILE_LIST\\}\\}/g, fileList);\n}\n\n// Returns the absolute path of the written doc.\nfunction writeMergeProcessDoc(repoRoot: string, mergeDir: string, squashBranch: string, conflictedFiles: string[], finishCommand: string): string {\n const docDir = path.join(repoRoot, WEBPIECES_TMP_DIR, 'instruct-ai');\n fs.mkdirSync(docDir, { recursive: true });\n const docPath = path.join(docDir, 'webpieces.mergeprocess.md');\n fs.writeFileSync(docPath, mergeProcessDoc(mergeDir, squashBranch, conflictedFiles, finishCommand));\n return docPath;\n}\n\n// The AI-facing \"what just happened / what to do next\" recap on the conflict path. Explicit and\n// numbered so an agent (or human) can't miss where the context lives or which command finishes.\nfunction printConflictHandback(\n docPath: string, mergeDir: string, squashBranch: string, conflictedFiles: string[], finishCommand: string,\n): void {\n process.stdout.write('\\n' + SEP + `⚠️ Conflicts in ${conflictedFiles.length} file(s) — handing control back to you\\n` + SEP + '\\n');\n process.stdout.write('Here is exactly what I did and what you need to do:\\n\\n');\n process.stdout.write('What I did:\\n');\n process.stdout.write(' 1. snapshotted your pre-merge state to a PreMerge branch\\n');\n process.stdout.write(' 2. pulled origin/main and squash-merged your work onto it\\n');\n process.stdout.write(` 3. hit conflicts — you are now on the transient branch ${squashBranch}\\n\\n`);\n process.stdout.write('What you need to do:\\n');\n process.stdout.write(` 1. read the merge process doc: ${docPath}\\n`);\n process.stdout.write(` 2. resolve each conflicted file below (its 3-point A/B/C context + diffs are in\\n`);\n process.stdout.write(` ${mergeDir}/updatemain-<file>/), and write that file's merge-explanation.md\\n`);\n process.stdout.write(` 3. run pnpm ${finishCommand} — it validates, commits, and finalizes (do NOT git add/commit/push yourself)\\n\\n`);\n process.stdout.write('Conflicted files:\\n');\n for (const file of conflictedFiles) process.stdout.write(` - ${file}\\n`);\n process.stdout.write('\\n' + SEP);\n}\n\n// Write the conflict context files + the unvalidated marker + the process doc. Does NOT exit — the\n// caller decides (runUpdateFromMain exits 2 to hand back to the AI).\nfunction handleConflictsHandback(\n repoRoot: string, mergeDir: string, currentBranch: string, squashBranch: string,\n backupBranch: string, prNumber: string, hashes: HashPoints, finishCommand: string,\n): void {\n const raw = execSync('git diff --name-only --diff-filter=U', { encoding: 'utf8' }).trim();\n const conflictedFiles = raw.split('\\n').filter((f: string): boolean => f.trim() !== '');\n fs.mkdirSync(mergeDir, { recursive: true }); // run dir was wiped at sync start — create it fresh\n fs.writeFileSync(path.join(mergeDir, 'updatemain-conflicted-files.txt'), raw + '\\n');\n // Copy the A/B/C hashes into THIS run dir so the merge-process doc's `MERGE_DIR/updatemain-hashes.json`\n // pointer is accurate (gatherInfo writes the source copy into the feature home before the slot is known).\n fs.writeFileSync(path.join(mergeDir, 'updatemain-hashes.json'), JSON.stringify(hashes, null, 2) + '\\n');\n saveConflictContext(conflictedFiles, mergeDir, hashes.hashForkPoint, hashes.hashFeatureHead, hashes.hashMainHead);\n\n const marker = new MergeMarker(\n currentBranch, squashBranch, backupBranch, prNumber, conflictedFiles,\n hashes.hashForkPoint, hashes.hashFeatureHead, hashes.hashMainHead, false,\n );\n writeMergeMarker(mergeDir, marker);\n const docPath = writeMergeProcessDoc(repoRoot, mergeDir, squashBranch, conflictedFiles, finishCommand);\n printConflictHandback(docPath, mergeDir, squashBranch, conflictedFiles, finishCommand);\n}\n\n// Short sha of a ref (best-effort — '' if it can't resolve), for the branch-mutation log's\n// oldMain→newMain annotation.\nfunction shortSha(ref: string): string {\n const result = spawnSync('git', ['rev-parse', '--short', ref], { encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n}\n\n// Log the CONFLICT phase with the conflicted-file list + the artifact paths a resolver needs — the\n// per-file 3-point context dir and the generated merge-process doc — so the branch-mutation log alone\n// tells the next agent where to look (no reflog/log archaeology).\nfunction logConflict(repoRoot: string, verb: MutationVerb, mergeDir: string): void {\n const raw = spawnSync('git', ['diff', '--name-only', '--diff-filter=U'], { cwd: repoRoot, encoding: 'utf8' });\n const files = (raw.status === 0 ? (raw.stdout ?? '') : '').split('\\n').map((f: string): string => f.trim()).filter((f: string): boolean => f !== '');\n const event = new BranchMutationEvent(verb, 'CONFLICT');\n event.conflict = true;\n event.conflictFiles = files;\n event.artifacts = [\n path.join(mergeDir, 'updatemain-<file>'),\n path.join(repoRoot, WEBPIECES_TMP_DIR, 'instruct-ai', 'webpieces.mergeprocess.md'),\n ];\n logBranchMutation(repoRoot, event);\n}\n\nexport async function mergeStart(repoRoot: string, verb: MutationVerb, home: string, finishCommand: string): Promise<MergeStartResult> {\n const currentBranch = execSync('git branch --show-current', { encoding: 'utf8' }).trim();\n if (currentBranch.endsWith('Squash')) {\n throw new CliExitError(1, `❌ On a leftover ${currentBranch} branch with no merge marker. Clean up: git branch -D ${currentBranch}`);\n }\n\n // One number `n` for this sync drives BOTH the backup branch and its `merge-<n>/` context dir.\n const slot = chooseSyncSlot(home, currentBranch);\n const backupBranch = slot.backupBranch;\n const mergeDir = slot.runDir;\n\n process.stdout.write('\\n' + SEP + '🔄 Squash-Merge Update from Main\\n' + SEP + '\\n');\n // gatherInfo RETURNS (never exits): an already-even-with-main branch is NOT special-cased here —\n // we flow straight on. The squash merge below becomes a no-op that the `nothingStaged` path\n // (further down) handles, so the caller still proceeds to push + build. (Previously gatherInfo\n // process.exit(0)'d on this case, silently killing wp-start-upsert-pr before push/build.)\n const info = await gatherInfo();\n const hashes = info.hashes;\n if (info.alreadyUpToDate) {\n process.stdout.write('ℹ️ Branch already even with main; nothing to merge, continuing to push/build.\\n');\n }\n\n const prNumber = detectPr(baseBranchName(currentBranch));\n process.stdout.write(prNumber ? `Existing PR #${prNumber} will be updated.\\n` : 'No existing PR (one can be created later).\\n');\n\n createBackup(currentBranch, backupBranch);\n const backupEvent = new BranchMutationEvent(verb, 'BACKUP');\n backupEvent.fromBranch = currentBranch;\n backupEvent.toBranch = backupBranch;\n logBranchMutation(repoRoot, backupEvent);\n\n const squashBranch = `${currentBranch}Squash`;\n if (spawnSync('git', ['show-ref', '--verify', '--quiet', `refs/heads/${squashBranch}`]).status === 0) {\n throw new CliExitError(1, `❌ Stale ${squashBranch} from a previous run. Delete it: git branch -D ${squashBranch}`);\n }\n\n // Branch the squash off origin/main directly — worktree-native. Never checks out or mutates local\n // `main`, which fatals inside a linked worktree (`git checkout main` → \"'main' is already checked\n // out at <primary>\"). origin/main was already fetched in gatherInfo() above, and the fork point +\n // all three hash points (A/B/C) are computed purely from origin/main, so the squash merge base is\n // identical to the old checkout-main + pull path — this is a behavior-preserving change on the\n // primary repo and an unblock inside worktrees.\n const originMainSha = shortSha('origin/main');\n runGitChecked(['checkout', '-b', squashBranch, 'origin/main'], 'Failed to create squash branch off origin/main');\n const baseEvent = new BranchMutationEvent(verb, 'PULL');\n baseEvent.newMain = originMainSha;\n logBranchMutation(repoRoot, baseEvent);\n\n process.stdout.write('\\n' + SEP + `🔀 Squash merging ${currentBranch}\\n` + SEP + '\\n');\n const merge = spawnSync('git', ['merge', '--squash', currentBranch], { stdio: 'inherit' });\n if (merge.status !== 0) {\n handleConflictsHandback(repoRoot, mergeDir, currentBranch, squashBranch, backupBranch, prNumber, hashes, finishCommand);\n logConflict(repoRoot, verb, mergeDir);\n return new MergeStartResult('conflict', null, mergeDir);\n }\n logBranchMutation(repoRoot, new BranchMutationEvent(verb, 'SQUASH'));\n\n const nothingStaged = spawnSync('git', ['diff-index', '--quiet', '--cached', 'HEAD', '--']).status === 0;\n if (nothingStaged) {\n process.stdout.write('ℹ️ Already up-to-date with main (nothing to merge).\\n');\n } else {\n runGitChecked(['commit', '-m', `Squash merge of ${currentBranch}`], 'Failed to commit squash merge');\n }\n return new MergeStartResult('clean', new MergeContext(currentBranch, squashBranch, backupBranch, prNumber), mergeDir);\n}\n"]}
1
+ {"version":3,"file":"merge-start.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/merge-start.ts"],"names":[],"mappings":";;;AA4SA,gCAgEC;;AA5WD,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAGiC;AACjC,sDAA+C;AAC/C,mDAA6F;AAC7F,yCAA2C;AAC3C,+CAAiG;AAEjG,qGAAqG;AACrG,oGAAoG;AACpG,qGAAqG;AACrG,+FAA+F;AAC/F,uFAAuF;AACvF,mGAAmG;AACnG,mGAAmG;AACnG,6EAA6E;AAE7E,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAQvE,mGAAmG;AACnG,MAAa,YAAY;IACrB,aAAa,CAAS;IACtB,YAAY,CAAS;IACrB,YAAY,CAAS;IACrB,QAAQ,CAAS;IAEjB,YAAY,aAAqB,EAAE,YAAoB,EAAE,YAAoB,EAAE,QAAgB;QAC3F,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAZD,oCAYC;AAED,sGAAsG;AACtG,0FAA0F;AAC1F,MAAa,gBAAgB;IACzB,MAAM,CAAuB;IAC7B,OAAO,CAAsB;IAC7B,MAAM,CAAS,CAAC,sFAAsF;IAEtG,YAAY,MAA4B,EAAE,OAA4B,EAAE,MAAc;QAClF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAVD,4CAUC;AAED,gGAAgG;AAChG,6EAA6E;AAC7E,SA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AAC1H,CAAC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport {\n WEBPIECES_TMP_DIR, MERGE_EXPLANATION_FILE, CliExitError,\n MutationVerb, BranchMutationEvent, logBranchMutation,\n} from '@webpieces/rules-config';\nimport { gatherInfo } from '../git-gatherInfo';\nimport { baseBranchName, nextFreePreMergeNumber, preMergeBackupName } from './branch-naming';\nimport { runGitChecked } from './git-exec';\nimport { MergeMarker, perFileContextDir, writeMergeMarker, mergeRunDirFor } from './merge-state';\n\n// merge-START: the first half of the 3-point squash-merge lifecycle. Brings origin/main into a fresh\n// `<branch>Squash`, and on conflict writes the 3-point context files + the unvalidated marker + the\n// process doc, then hands control back to the AI. On a clean merge it commits the squash and returns\n// the branch context so the caller (runUpdateFromMain) can run merge-END to finalize. It NEVER\n// finalizes or posts a PR — that is merge-END's / wp-finish-upsert-pr's job. Shared so\n// runUpdateFromMain (and, via it, wp-start-update + wp-start-upsert-pr) all set up a merge through\n// one code path. `finishCommand` names the command the AI runs to finish after resolving conflicts\n// (standalone update → `wp-finish-update`; PR flow → `wp-finish-upsert-pr`).\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\ninterface HashPoints {\n hashForkPoint: string;\n hashFeatureHead: string;\n hashMainHead: string;\n}\n\n// The four branch names merge-END needs to finalize a merge (swap squash→feature, push, clean up).\nexport class MergeContext {\n currentBranch: string;\n squashBranch: string;\n backupBranch: string;\n prNumber: string;\n\n constructor(currentBranch: string, squashBranch: string, backupBranch: string, prNumber: string) {\n this.currentBranch = currentBranch;\n this.squashBranch = squashBranch;\n this.backupBranch = backupBranch;\n this.prNumber = prNumber;\n }\n}\n\n// Outcome of merge-start: 'clean' carries the context for merge-END to finalize; 'conflict' means the\n// marker + context files were written and the caller should hand back to the AI (exit 2).\nexport class MergeStartResult {\n status: 'clean' | 'conflict';\n context: MergeContext | null;\n runDir: string; // this sync's numbered `merge-<n>/` dir — passed to merge-END so it reads THIS marker\n\n constructor(status: 'clean' | 'conflict', context: MergeContext | null, runDir: string) {\n this.status = status;\n this.context = context;\n this.runDir = runDir;\n }\n}\n\n// Detect the PR by its STABLE feature branch — pass baseBranchName(currentBranch) so a leftover\n// `…wpN` from the old scheme still resolves to the one name the PR lives on.\nfunction detectPr(baseBranch: string): string {\n const result = spawnSync(\n 'gh', ['pr', 'list', '--head', baseBranch, '--json', 'number', '--jq', '.[0].number'],\n { encoding: 'utf8' },\n );\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n}\n\n// The one number `n` for a sync and the two things it names: the pre-merge backup branch and its\n// paired conflict-context run dir.\nclass SyncSlot {\n backupBranch: string;\n runDir: string;\n\n constructor(backupBranch: string, runDir: string) {\n this.backupBranch = backupBranch;\n this.runDir = runDir;\n }\n}\n\n// Pick the first free `<branch>PreMerge<n>` slot number, then WIPE the paired `<home>/merge-<n>/` run\n// dir — a fresh sync means no merge is in progress, so any leftover `merge-<n>` is stale (its own sync\n// ended, or its branch was deleted) and MUST NOT leak its old per-file merge-explanation.md into this\n// merge's validation. Returns the backup branch name + the (now-empty) run dir path, both keyed on `n`.\nfunction chooseSyncSlot(home: string, currentBranch: string): SyncSlot {\n const n = nextFreePreMergeNumber(\n currentBranch,\n (name: string): boolean => spawnSync('git', ['show-ref', '--verify', '--quiet', `refs/heads/${name}`]).status === 0,\n );\n const runDir = mergeRunDirFor(home, n);\n fs.rmSync(runDir, { recursive: true, force: true });\n return new SyncSlot(preMergeBackupName(currentBranch, n), runDir);\n}\n\n// Snapshot the pre-merge state onto the caller-chosen `backupBranch` (`<currentBranch>PreMerge<n>`),\n// never overwriting. The slot number `n` is picked once in mergeStart and shared with the paired\n// `merge-<n>/` context dir. A clean sync deletes this snapshot at finalize; only conflict syncs keep it.\nfunction createBackup(currentBranch: string, backupBranch: string): void {\n process.stdout.write('\\n' + SEP + '💾 Creating Pre-Merge Backup\\n' + SEP + '\\n');\n runGitChecked(['checkout', '-b', backupBranch], 'Failed to create backup branch');\n runGitChecked(['checkout', currentBranch], 'Failed to return to feature branch');\n process.stdout.write(`✅ Backup created: ${backupBranch}\\n\\n`);\n}\n\nfunction saveConflictContext(\n conflictedFiles: string[], mergeDir: string, forkPoint: string, featureHead: string, mainHead: string,\n): void {\n for (const file of conflictedFiles) {\n const fileDir = perFileContextDir(mergeDir, file);\n fs.mkdirSync(fileDir, { recursive: true });\n\n const fork = spawnSync('git', ['show', `${forkPoint}:${file}`], { encoding: 'utf8' });\n fs.writeFileSync(path.join(fileDir, 'A-forkpoint.txt'), fork.status === 0 ? (fork.stdout ?? '') : '(file did not exist)\\n');\n const feature = spawnSync('git', ['show', `${featureHead}:${file}`], { encoding: 'utf8' });\n fs.writeFileSync(path.join(fileDir, 'B-feature.txt'), feature.status === 0 ? (feature.stdout ?? '') : '(file did not exist)\\n');\n const main = spawnSync('git', ['show', `${mainHead}:${file}`], { encoding: 'utf8' });\n fs.writeFileSync(path.join(fileDir, 'C-main.txt'), main.status === 0 ? (main.stdout ?? '') : '(file did not exist)\\n');\n\n const ba = spawnSync('git', ['diff', forkPoint, featureHead, '--', file], { encoding: 'utf8' });\n fs.writeFileSync(path.join(fileDir, 'B-A.diff'), ba.stdout ?? '');\n const ca = spawnSync('git', ['diff', forkPoint, mainHead, '--', file], { encoding: 'utf8' });\n fs.writeFileSync(path.join(fileDir, 'C-A.diff'), ca.stdout ?? '');\n }\n}\n\n// Single source of truth for the merge process. The script WRITES it at conflict time (rather\n// than the AI relying on a separate hand-maintained doc), parameterized with the live MERGE_DIR\n// and conflicted-file list, so the instructions can never drift from the actual layout. The body\n// is a template constant with {{...}} placeholders so this stays a small filler function.\nconst MERGE_PROCESS_TEMPLATE = `# AI-Assisted Squash-Merge Conflict Resolution (generated)\n\nThis file was generated by \\`pnpm wp-start-update\\` when the 3-point squash-merge hit conflicts.\nIt is the single source of truth for the merge process — follow it exactly.\n\nYou are on branch \\`{{SQUASH_BRANCH}}\\` with conflict markers in the working tree.\n\\`MERGE_DIR = {{MERGE_DIR}}\\`\n\n## How the gate works\n\n- Resolve every conflicted file in the working tree.\n- Run **\\`pnpm {{FINISH_COMMAND}}\\`** — the validation + finish gate. It scans for leftover conflict\n markers, checks each conflicted file has a written merge explanation, validates, and commits the\n merge. (In the PR flow this command is \\`wp-finish-upsert-pr\\`, which additionally runs the\n \\`nx affected\\` build, renders the dashboard, and creates/updates the PR.)\n- **Do NOT run \\`git add\\` / \\`git commit\\` / \\`git push\\` / \\`gh pr\\` yourself.** They are blocked by\n the \\`merge-in-progress-guard\\` hook until the gate validates. The gate does the commit.\n\n## STEP 1 — Load the merge context\n\nPer conflicted file, \\`MERGE_DIR/updatemain-<safe_path>/\\` holds (\\`<safe_path>\\` = path with \\`/\\`→\\`__\\`):\n\n\\`\\`\\`\nA-forkpoint.txt # file at fork point (base)\nB-feature.txt # file on your feature branch\nC-main.txt # file on main\nB-A.diff # what your feature changed (B−A)\nC-A.diff # what main changed (C−A)\n\\`\\`\\`\n\n\\`updatemain-hashes.json\\` holds A/B/C commit hashes. To see why main changed:\n\\`git log <A>..<C> --oneline\\`.\n\n## STEP 2 — Resolve each conflicted file\n\nFor each file: read the working-tree file (the markers) and its \\`B-A.diff\\` / \\`C-A.diff\\` (intent),\nthen Edit to the resolved version, removing ALL conflict markers.\n\nStrategies: goals align & non-overlapping → merge both · one side removes what the other modifies\n→ prefer the removal · same lines, simple (imports/format) → merge both · same lines, complex or\nconflicting goals → ask the user · feature re-implements what main already squashed → prefer\nmain's, then re-apply only the genuinely new feature work.\n\n**Then write a merge explanation** for each conflicted file — NOT a comment in the source (that\nbreaks for JSON and deleted files). Write it next to that file's diffs, at:\n\n\\`\\`\\`\nMERGE_DIR/updatemain-<safe_path>/{{EXPLANATION_FILE}}\n\\`\\`\\`\n\n(\\`<safe_path>\\` = the conflict file path with \\`/\\` → \\`__\\`, the same dir that holds its\n\\`A-forkpoint.txt\\` / \\`B-A.diff\\` / \\`C-A.diff\\`.) In it, explain in a few sentences how you resolved\nthis file: which side you took where, what you combined from B-A.diff vs C-A.diff, and why. The\ngate fails if any conflicted file's explanation is missing or empty. Do not paste A/B/C context\nblocks into the source code.\n\n## STEP 3 — Run the gate (validates the merge AND finalizes it)\n\n\\`\\`\\`\npnpm {{FINISH_COMMAND}}\n\\`\\`\\`\n\n- Leftover conflict markers → fix those files and re-run.\n- Missing merge explanation → write it (see STEP 2) and re-run.\n- Build failure → fix the TypeScript/lint errors and re-run (the gate re-stages for you).\n- Missing review.json (PR flow only) → write it in the printed format (your PR review), then re-run.\n- On success it commits and finalizes the merge (in the PR flow it also renders the dashboard and\n creates/updates the PR).\n\n## Conflicted files\n\n{{FILE_LIST}}\n\n## If you need to bail out\n\nA numbered backup branch was created (e.g. \\`<feature>PreMerge1\\`). To abandon:\n\n\\`\\`\\`\ngit merge --abort 2>/dev/null; git checkout <feature> ; git branch -D {{SQUASH_BRANCH}}\n\\`\\`\\`\n\nThen delete \\`{{MERGE_DIR}}/\\` for a clean slate.\n`;\n\nfunction mergeProcessDoc(mergeDir: string, squashBranch: string, conflictedFiles: string[], finishCommand: string): string {\n const fileList = conflictedFiles.map((f: string): string => `- \\`${f}\\``).join('\\n');\n return MERGE_PROCESS_TEMPLATE\n .replace(/\\{\\{SQUASH_BRANCH\\}\\}/g, squashBranch)\n .replace(/\\{\\{MERGE_DIR\\}\\}/g, mergeDir)\n .replace(/\\{\\{EXPLANATION_FILE\\}\\}/g, MERGE_EXPLANATION_FILE)\n .replace(/\\{\\{FINISH_COMMAND\\}\\}/g, finishCommand)\n .replace(/\\{\\{FILE_LIST\\}\\}/g, fileList);\n}\n\n// Returns the absolute path of the written doc.\nfunction writeMergeProcessDoc(repoRoot: string, mergeDir: string, squashBranch: string, conflictedFiles: string[], finishCommand: string): string {\n const docDir = path.join(repoRoot, WEBPIECES_TMP_DIR, 'instruct-ai');\n fs.mkdirSync(docDir, { recursive: true });\n const docPath = path.join(docDir, 'webpieces.mergeprocess.md');\n fs.writeFileSync(docPath, mergeProcessDoc(mergeDir, squashBranch, conflictedFiles, finishCommand));\n return docPath;\n}\n\n// The AI-facing \"what just happened / what to do next\" recap on the conflict path. Explicit and\n// numbered so an agent (or human) can't miss where the context lives or which command finishes.\nfunction printConflictHandback(\n docPath: string, mergeDir: string, squashBranch: string, conflictedFiles: string[], finishCommand: string,\n): void {\n process.stdout.write('\\n' + SEP + `⚠️ Conflicts in ${conflictedFiles.length} file(s) — handing control back to you\\n` + SEP + '\\n');\n process.stdout.write('Here is exactly what I did and what you need to do:\\n\\n');\n process.stdout.write('What I did:\\n');\n process.stdout.write(' 1. snapshotted your pre-merge state to a PreMerge branch\\n');\n process.stdout.write(' 2. pulled origin/main and squash-merged your work onto it\\n');\n process.stdout.write(` 3. hit conflicts — you are now on the transient branch ${squashBranch}\\n\\n`);\n process.stdout.write('What you need to do:\\n');\n process.stdout.write(` 1. read the merge process doc: ${docPath}\\n`);\n process.stdout.write(` 2. resolve each conflicted file below (its 3-point A/B/C context + diffs are in\\n`);\n process.stdout.write(` ${mergeDir}/updatemain-<file>/), and write that file's merge-explanation.md\\n`);\n process.stdout.write(` 3. run pnpm ${finishCommand} — it validates, commits, and finalizes (do NOT git add/commit/push yourself)\\n\\n`);\n process.stdout.write('Conflicted files:\\n');\n for (const file of conflictedFiles) process.stdout.write(` - ${file}\\n`);\n process.stdout.write('\\n' + SEP);\n}\n\n// Write the conflict context files + the unvalidated marker + the process doc. Does NOT exit — the\n// caller decides (runUpdateFromMain exits 2 to hand back to the AI).\nfunction handleConflictsHandback(\n repoRoot: string, mergeDir: string, currentBranch: string, squashBranch: string,\n backupBranch: string, prNumber: string, hashes: HashPoints, finishCommand: string,\n): void {\n const raw = execSync('git diff --name-only --diff-filter=U', { encoding: 'utf8' }).trim();\n const conflictedFiles = raw.split('\\n').filter((f: string): boolean => f.trim() !== '');\n fs.mkdirSync(mergeDir, { recursive: true }); // run dir was wiped at sync start — create it fresh\n fs.writeFileSync(path.join(mergeDir, 'updatemain-conflicted-files.txt'), raw + '\\n');\n // Copy the A/B/C hashes into THIS run dir so the merge-process doc's `MERGE_DIR/updatemain-hashes.json`\n // pointer is accurate (gatherInfo writes the source copy into the feature home before the slot is known).\n fs.writeFileSync(path.join(mergeDir, 'updatemain-hashes.json'), JSON.stringify(hashes, null, 2) + '\\n');\n saveConflictContext(conflictedFiles, mergeDir, hashes.hashForkPoint, hashes.hashFeatureHead, hashes.hashMainHead);\n\n const marker = new MergeMarker(\n currentBranch, squashBranch, backupBranch, prNumber, conflictedFiles,\n hashes.hashForkPoint, hashes.hashFeatureHead, hashes.hashMainHead, false,\n );\n writeMergeMarker(mergeDir, marker);\n const docPath = writeMergeProcessDoc(repoRoot, mergeDir, squashBranch, conflictedFiles, finishCommand);\n printConflictHandback(docPath, mergeDir, squashBranch, conflictedFiles, finishCommand);\n}\n\n// Short sha of a ref (best-effort — '' if it can't resolve), for the branch-mutation log's\n// oldMain→newMain annotation.\nfunction shortSha(ref: string): string {\n const result = spawnSync('git', ['rev-parse', '--short', ref], { encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n}\n\n// Log the CONFLICT phase with the conflicted-file list + the artifact paths a resolver needs — the\n// per-file 3-point context dir and the generated merge-process doc — so the branch-mutation log alone\n// tells the next agent where to look (no reflog/log archaeology).\nfunction logConflict(repoRoot: string, verb: MutationVerb, mergeDir: string): void {\n const raw = spawnSync('git', ['diff', '--name-only', '--diff-filter=U'], { cwd: repoRoot, encoding: 'utf8' });\n const files = (raw.status === 0 ? (raw.stdout ?? '') : '').split('\\n').map((f: string): string => f.trim()).filter((f: string): boolean => f !== '');\n const event = new BranchMutationEvent(verb, 'CONFLICT');\n event.conflict = true;\n event.conflictFiles = files;\n event.artifacts = [\n path.join(mergeDir, 'updatemain-<file>'),\n path.join(repoRoot, WEBPIECES_TMP_DIR, 'instruct-ai', 'webpieces.mergeprocess.md'),\n ];\n logBranchMutation(repoRoot, event);\n}\n\nexport async function mergeStart(repoRoot: string, verb: MutationVerb, home: string, finishCommand: string): Promise<MergeStartResult> {\n const currentBranch = execSync('git branch --show-current', { encoding: 'utf8' }).trim();\n if (currentBranch.endsWith('Squash')) {\n throw new CliExitError(1, `❌ On a leftover ${currentBranch} branch with no merge marker. Clean up: git branch -D ${currentBranch}`);\n }\n\n // One number `n` for this sync drives BOTH the backup branch and its `merge-<n>/` context dir.\n const slot = chooseSyncSlot(home, currentBranch);\n const backupBranch = slot.backupBranch;\n const mergeDir = slot.runDir;\n\n process.stdout.write('\\n' + SEP + '🔄 Squash-Merge Update from Main\\n' + SEP + '\\n');\n // gatherInfo RETURNS (never exits): an already-even-with-main branch is NOT special-cased here —\n // we flow straight on. The squash merge below becomes a no-op that the `nothingStaged` path\n // (further down) handles, so the caller still proceeds to push + build. (Previously gatherInfo\n // process.exit(0)'d on this case, silently killing wp-start-upsert-pr before push/build.)\n const info = await gatherInfo();\n const hashes = info.hashes;\n if (info.alreadyUpToDate) {\n process.stdout.write('ℹ️ Branch already even with main; nothing to merge, continuing to push/build.\\n');\n }\n\n const prNumber = detectPr(baseBranchName(currentBranch));\n process.stdout.write(prNumber ? `Existing PR #${prNumber} will be updated.\\n` : 'No existing PR (one can be created later).\\n');\n\n createBackup(currentBranch, backupBranch);\n const backupEvent = new BranchMutationEvent(verb, 'BACKUP');\n backupEvent.fromBranch = currentBranch;\n backupEvent.toBranch = backupBranch;\n logBranchMutation(repoRoot, backupEvent);\n\n const squashBranch = `${currentBranch}Squash`;\n if (spawnSync('git', ['show-ref', '--verify', '--quiet', `refs/heads/${squashBranch}`]).status === 0) {\n throw new CliExitError(1, `❌ Stale ${squashBranch} from a previous run. Delete it: git branch -D ${squashBranch}`);\n }\n\n // Branch the squash off origin/main directly — worktree-native. Never checks out or mutates local\n // `main`, which fatals inside a linked worktree (`git checkout main` → \"'main' is already checked\n // out at <primary>\"). origin/main was already fetched in gatherInfo() above, and the fork point +\n // all three hash points (A/B/C) are computed purely from origin/main, so the squash merge base is\n // identical to the old checkout-main + pull path — this is a behavior-preserving change on the\n // primary repo and an unblock inside worktrees.\n const originMainSha = shortSha('origin/main');\n runGitChecked(['checkout', '-b', squashBranch, 'origin/main'], 'Failed to create squash branch off origin/main');\n const baseEvent = new BranchMutationEvent(verb, 'PULL');\n baseEvent.newMain = originMainSha;\n logBranchMutation(repoRoot, baseEvent);\n\n process.stdout.write('\\n' + SEP + `🔀 Squash merging ${currentBranch}\\n` + SEP + '\\n');\n const merge = spawnSync('git', ['merge', '--squash', currentBranch], { stdio: 'inherit' });\n if (merge.status !== 0) {\n handleConflictsHandback(repoRoot, mergeDir, currentBranch, squashBranch, backupBranch, prNumber, hashes, finishCommand);\n logConflict(repoRoot, verb, mergeDir);\n return new MergeStartResult('conflict', null, mergeDir);\n }\n logBranchMutation(repoRoot, new BranchMutationEvent(verb, 'SQUASH'));\n\n const nothingStaged = spawnSync('git', ['diff-index', '--quiet', '--cached', 'HEAD', '--']).status === 0;\n if (nothingStaged) {\n process.stdout.write('ℹ️ Already up-to-date with main (nothing to merge).\\n');\n } else {\n runGitChecked(['commit', '-m', `Squash merge of ${currentBranch}`], 'Failed to commit squash merge');\n }\n return new MergeStartResult('clean', new MergeContext(currentBranch, squashBranch, backupBranch, prNumber), mergeDir);\n}\n"]}
@@ -12,7 +12,7 @@ const SEP = '━━━━━━━━━━━━━━━━━━━━━━
12
12
  // This is a HARD GATE, not an advisory hint: it FAILS FAST if `gh` cannot answer (not installed, not
13
13
  // authenticated, offline). We must NOT degrade "couldn't ask GitHub" into "no PR" — a 3-point update
14
14
  // makes a new branch generation and the existing PR would be left pointing at the OLD branch (stale),
15
- // so running wp-update-start blind when a PR might exist is exactly the disaster we are guarding
15
+ // so running wp-start-update blind when a PR might exist is exactly the disaster we are guarding
16
16
  // against. Refuse rather than guess.
17
17
  function openPrForBranch(repoRoot, currentBranch) {
18
18
  const base = (0, branch_naming_1.baseBranchName)(currentBranch);
@@ -22,7 +22,7 @@ function openPrForBranch(repoRoot, currentBranch) {
22
22
  throw new rules_config_1.CliExitError(2, '\n' + SEP + '❌ Could not ask GitHub whether an open PR exists for this branch\n' + SEP + '\n' +
23
23
  `gh failed for base branch "${base}": ${detail}\n\n` +
24
24
  'This check must NOT be skipped: a 3-point update creates a NEW branch generation, so if a\n' +
25
- 'PR already exists, wp-update-start would leave it pointing at the OLD branch. Fix gh first\n' +
25
+ 'PR already exists, wp-start-update would leave it pointing at the OLD branch. Fix gh first\n' +
26
26
  '(install / `gh auth login` / restore network), then re-run — or, if a PR does exist, use\n' +
27
27
  'the PR flow: pnpm wp-start-upsert-pr → /wp-merge → pnpm wp-finish-upsert-pr\n');
28
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"open-pr-check.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/open-pr-check.ts"],"names":[],"mappings":";;AAeA,0CAkBC;AAjCD,iDAA0C;AAC1C,0DAAuD;AACvD,mDAAiD;AAEjD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,mGAAmG;AACnG,6GAA6G;AAC7G,8CAA8C;AAC9C,EAAE;AACF,qGAAqG;AACrG,qGAAqG;AACrG,sGAAsG;AACtG,iGAAiG;AACjG,qCAAqC;AACrC,SAAgB,eAAe,CAAC,QAAgB,EAAE,aAAqB;IACnE,MAAM,IAAI,GAAG,IAAA,8BAAc,EAAC,aAAa,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,IAAA,yBAAS,EACpB,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,EAClG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,CACtC,CAAC;IACF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC;QAC5G,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,IAAI,GAAG,GAAG,GAAG,oEAAoE,GAAG,GAAG,GAAG,IAAI;YAC9F,8BAA8B,IAAI,MAAM,MAAM,MAAM;YACpD,6FAA6F;YAC7F,8FAA8F;YAC9F,4FAA4F;YAC5F,+EAA+E,CAClF,CAAC;IACN,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import { spawnSync } from 'child_process';\nimport { CliExitError } from '@webpieces/rules-config';\nimport { baseBranchName } from './branch-naming';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// The open PR (if any) tracking a feature branch, looked up by its STABLE base name (the PR always\n// lives on the stable feature name, and a leftover `…wpN` still resolves there). Returns '' ONLY when GitHub\n// answered and there is genuinely no open PR.\n//\n// This is a HARD GATE, not an advisory hint: it FAILS FAST if `gh` cannot answer (not installed, not\n// authenticated, offline). We must NOT degrade \"couldn't ask GitHub\" into \"no PR\" — a 3-point update\n// makes a new branch generation and the existing PR would be left pointing at the OLD branch (stale),\n// so running wp-update-start blind when a PR might exist is exactly the disaster we are guarding\n// against. Refuse rather than guess.\nexport function openPrForBranch(repoRoot: string, currentBranch: string): string {\n const base = baseBranchName(currentBranch);\n const result = spawnSync(\n 'gh', ['pr', 'list', '--head', base, '--state', 'open', '--json', 'number', '--jq', '.[0].number'],\n { cwd: repoRoot, encoding: 'utf8' },\n );\n if (result.status !== 0) {\n const detail = (result.stderr ?? '').trim() || (result.error ? result.error.message : 'gh exited non-zero');\n throw new CliExitError(2,\n '\\n' + SEP + '❌ Could not ask GitHub whether an open PR exists for this branch\\n' + SEP + '\\n' +\n `gh failed for base branch \"${base}\": ${detail}\\n\\n` +\n 'This check must NOT be skipped: a 3-point update creates a NEW branch generation, so if a\\n' +\n 'PR already exists, wp-update-start would leave it pointing at the OLD branch. Fix gh first\\n' +\n '(install / `gh auth login` / restore network), then re-run — or, if a PR does exist, use\\n' +\n 'the PR flow: pnpm wp-start-upsert-pr → /wp-merge → pnpm wp-finish-upsert-pr\\n',\n );\n }\n return (result.stdout ?? '').trim();\n}\n"]}
1
+ {"version":3,"file":"open-pr-check.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/open-pr-check.ts"],"names":[],"mappings":";;AAeA,0CAkBC;AAjCD,iDAA0C;AAC1C,0DAAuD;AACvD,mDAAiD;AAEjD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,mGAAmG;AACnG,6GAA6G;AAC7G,8CAA8C;AAC9C,EAAE;AACF,qGAAqG;AACrG,qGAAqG;AACrG,sGAAsG;AACtG,iGAAiG;AACjG,qCAAqC;AACrC,SAAgB,eAAe,CAAC,QAAgB,EAAE,aAAqB;IACnE,MAAM,IAAI,GAAG,IAAA,8BAAc,EAAC,aAAa,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,IAAA,yBAAS,EACpB,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,EAClG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,CACtC,CAAC;IACF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC;QAC5G,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,IAAI,GAAG,GAAG,GAAG,oEAAoE,GAAG,GAAG,GAAG,IAAI;YAC9F,8BAA8B,IAAI,MAAM,MAAM,MAAM;YACpD,6FAA6F;YAC7F,8FAA8F;YAC9F,4FAA4F;YAC5F,+EAA+E,CAClF,CAAC;IACN,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import { spawnSync } from 'child_process';\nimport { CliExitError } from '@webpieces/rules-config';\nimport { baseBranchName } from './branch-naming';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// The open PR (if any) tracking a feature branch, looked up by its STABLE base name (the PR always\n// lives on the stable feature name, and a leftover `…wpN` still resolves there). Returns '' ONLY when GitHub\n// answered and there is genuinely no open PR.\n//\n// This is a HARD GATE, not an advisory hint: it FAILS FAST if `gh` cannot answer (not installed, not\n// authenticated, offline). We must NOT degrade \"couldn't ask GitHub\" into \"no PR\" — a 3-point update\n// makes a new branch generation and the existing PR would be left pointing at the OLD branch (stale),\n// so running wp-start-update blind when a PR might exist is exactly the disaster we are guarding\n// against. Refuse rather than guess.\nexport function openPrForBranch(repoRoot: string, currentBranch: string): string {\n const base = baseBranchName(currentBranch);\n const result = spawnSync(\n 'gh', ['pr', 'list', '--head', base, '--state', 'open', '--json', 'number', '--jq', '.[0].number'],\n { cwd: repoRoot, encoding: 'utf8' },\n );\n if (result.status !== 0) {\n const detail = (result.stderr ?? '').trim() || (result.error ? result.error.message : 'gh exited non-zero');\n throw new CliExitError(2,\n '\\n' + SEP + '❌ Could not ask GitHub whether an open PR exists for this branch\\n' + SEP + '\\n' +\n `gh failed for base branch \"${base}\": ${detail}\\n\\n` +\n 'This check must NOT be skipped: a 3-point update creates a NEW branch generation, so if a\\n' +\n 'PR already exists, wp-start-update would leave it pointing at the OLD branch. Fix gh first\\n' +\n '(install / `gh auth login` / restore network), then re-run — or, if a PR does exist, use\\n' +\n 'the PR flow: pnpm wp-start-upsert-pr → /wp-merge → pnpm wp-finish-upsert-pr\\n',\n );\n }\n return (result.stdout ?? '').trim();\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"run-update.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/run-update.ts"],"names":[],"mappings":";;AAqBA,8CAOC;AA5BD,0DAA+F;AAC/F,iEAAwD;AACxD,+CAAoF;AACpF,+CAAyD;AACzD,2CAAuC;AAiBhC,KAAK,UAAU,iBAAiB,CAAC,QAAgB,EAAE,IAAkB,EAAE,aAAqB;IAC/F,IAAA,gCAAiB,EAAC,QAAQ,EAAE,IAAI,kCAAmB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IACpE,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAG,IAAI,kCAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACjD,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC;IACtB,IAAA,gCAAiB,EAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACjC,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,QAAgB,EAAE,IAAkB,EAAE,aAAqB;IAChF,MAAM,IAAI,GAAG,IAAA,yBAAW,EAAC,QAAQ,EAAE,IAAA,qCAAc,GAAE,CAAC,CAAC;IAErD,qFAAqF;IACrF,MAAM,SAAS,GAAG,IAAA,mCAAqB,EAAC,IAAI,CAAC,CAAC;IAC9C,IAAI,SAAS,EAAE,CAAC;QACZ,MAAM,QAAQ,GAAG,IAAA,6BAAe,EAAC,SAAS,CAAC,CAAC;QAC5C,IAAI,QAAQ,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS;YAAE,OAAO,mBAAmB,CAAC;QACzE,mFAAmF;QACnF,MAAM,IAAA,oBAAQ,EACV,QAAQ,EAAE,IAAI,EAAE,SAAS,EACzB,IAAI,0BAAY,CAAC,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,QAAQ,CAAC,EACzG,IAAI,CACP,CAAC;QACF,OAAO,WAAW,CAAC;IACvB,CAAC;IAED,4FAA4F;IAC5F,uDAAuD;IACvD,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAU,EAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;IACrE,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QAC1D,OAAO,UAAU,CAAC;IACtB,CAAC;IACD,MAAM,IAAA,oBAAQ,EAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACpE,OAAO,WAAW,CAAC;AACvB,CAAC","sourcesContent":["import { MutationVerb, BranchMutationEvent, logBranchMutation } from '@webpieces/rules-config';\nimport { getFeatureName } from './git-readAiBranchName';\nimport { mergeDirFor, readMergeMarker, findActiveMergeRunDir } from './merge-state';\nimport { mergeStart, MergeContext } from './merge-start';\nimport { mergeEnd } from './merge-end';\n\n// The shared \"sync this feature branch from main\" engine — a thin composition of the two lifecycle\n// primitives (merge-START brings main in, merge-END finalizes). It is an INTERNAL function, not a\n// bin: `wp-update-start` (standalone) and `wp-start-upsert-pr` (PR flow) both call it. It NEVER\n// creates a PR and — unlike the old wp-git-update bin — it does NOT process.exit; it RETURNS an\n// outcome so each caller can print the handoff that fits its context.\n//\n// `finishCommand` is the command the AI is told to run after resolving conflicts — the standalone\n// caller passes `wp-update-end`, the PR flow passes `wp-finish-upsert-pr`.\n//\n// `verb` is the invoking bin, threaded through purely so every branch mutation (backup, checkout,\n// pull, squash, rename) is recorded in `.webpieces/hooks/branch-mutations.log` under the command the\n// user actually ran — the audit trail that used to exist only in `git reflog`.\n\nexport type UpdateOutcome = 'finalized' | 'conflict' | 'unvalidatedResume';\n\nexport async function runUpdateFromMain(repoRoot: string, verb: MutationVerb, finishCommand: string): Promise<UpdateOutcome> {\n logBranchMutation(repoRoot, new BranchMutationEvent(verb, 'START'));\n const outcome = await runUpdate(repoRoot, verb, finishCommand);\n const end = new BranchMutationEvent(verb, 'END');\n end.outcome = outcome;\n logBranchMutation(repoRoot, end);\n return outcome;\n}\n\nasync function runUpdate(repoRoot: string, verb: MutationVerb, finishCommand: string): Promise<UpdateOutcome> {\n const home = mergeDirFor(repoRoot, getFeatureName());\n\n // Resume path: an in-progress merge is the `merge-<n>/` run dir that holds a marker.\n const activeDir = findActiveMergeRunDir(home);\n if (activeDir) {\n const existing = readMergeMarker(activeDir);\n if (existing === null || !existing.validated) return 'unvalidatedResume';\n // Already validated → just finalize the branch swap (reads THIS run dir's marker).\n await mergeEnd(\n repoRoot, verb, activeDir,\n new MergeContext(existing.currentBranch, existing.squashBranch, existing.backupBranch, existing.prNumber),\n null,\n );\n return 'finalized';\n }\n\n // Fresh update: mergeStart picks the slot number, creates its own `merge-<n>/` run dir, and\n // returns that path for merge-END to finalize against.\n const result = await mergeStart(repoRoot, verb, home, finishCommand);\n if (result.status === 'conflict' || result.context === null) {\n return 'conflict';\n }\n await mergeEnd(repoRoot, verb, result.runDir, result.context, null);\n return 'finalized';\n}\n"]}
1
+ {"version":3,"file":"run-update.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/run-update.ts"],"names":[],"mappings":";;AAqBA,8CAOC;AA5BD,0DAA+F;AAC/F,iEAAwD;AACxD,+CAAoF;AACpF,+CAAyD;AACzD,2CAAuC;AAiBhC,KAAK,UAAU,iBAAiB,CAAC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AAC;IACrE,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QAC1D,OAAO,UAAU,CAAC;IACtB,CAAC;IACD,MAAM,IAAA,oBAAQ,EAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACpE,OAAO,WAAW,CAAC;AACvB,CAAC","sourcesContent":["import { MutationVerb, BranchMutationEvent, logBranchMutation } from '@webpieces/rules-config';\nimport { getFeatureName } from './git-readAiBranchName';\nimport { mergeDirFor, readMergeMarker, findActiveMergeRunDir } from './merge-state';\nimport { mergeStart, MergeContext } from './merge-start';\nimport { mergeEnd } from './merge-end';\n\n// The shared \"sync this feature branch from main\" engine — a thin composition of the two lifecycle\n// primitives (merge-START brings main in, merge-END finalizes). It is an INTERNAL function, not a\n// bin: `wp-start-update` (standalone) and `wp-start-upsert-pr` (PR flow) both call it. It NEVER\n// creates a PR and — unlike the old wp-git-update bin — it does NOT process.exit; it RETURNS an\n// outcome so each caller can print the handoff that fits its context.\n//\n// `finishCommand` is the command the AI is told to run after resolving conflicts — the standalone\n// caller passes `wp-finish-update`, the PR flow passes `wp-finish-upsert-pr`.\n//\n// `verb` is the invoking bin, threaded through purely so every branch mutation (backup, checkout,\n// pull, squash, rename) is recorded in `.webpieces/hooks/branch-mutations.log` under the command the\n// user actually ran — the audit trail that used to exist only in `git reflog`.\n\nexport type UpdateOutcome = 'finalized' | 'conflict' | 'unvalidatedResume';\n\nexport async function runUpdateFromMain(repoRoot: string, verb: MutationVerb, finishCommand: string): Promise<UpdateOutcome> {\n logBranchMutation(repoRoot, new BranchMutationEvent(verb, 'START'));\n const outcome = await runUpdate(repoRoot, verb, finishCommand);\n const end = new BranchMutationEvent(verb, 'END');\n end.outcome = outcome;\n logBranchMutation(repoRoot, end);\n return outcome;\n}\n\nasync function runUpdate(repoRoot: string, verb: MutationVerb, finishCommand: string): Promise<UpdateOutcome> {\n const home = mergeDirFor(repoRoot, getFeatureName());\n\n // Resume path: an in-progress merge is the `merge-<n>/` run dir that holds a marker.\n const activeDir = findActiveMergeRunDir(home);\n if (activeDir) {\n const existing = readMergeMarker(activeDir);\n if (existing === null || !existing.validated) return 'unvalidatedResume';\n // Already validated → just finalize the branch swap (reads THIS run dir's marker).\n await mergeEnd(\n repoRoot, verb, activeDir,\n new MergeContext(existing.currentBranch, existing.squashBranch, existing.backupBranch, existing.prNumber),\n null,\n );\n return 'finalized';\n }\n\n // Fresh update: mergeStart picks the slot number, creates its own `merge-<n>/` run dir, and\n // returns that path for merge-END to finalize against.\n const result = await mergeStart(repoRoot, verb, home, finishCommand);\n if (result.status === 'conflict' || result.context === null) {\n return 'conflict';\n }\n await mergeEnd(repoRoot, verb, result.runDir, result.context, null);\n return 'finalized';\n}\n"]}
@@ -8,12 +8,12 @@ const git_readAiBranchName_1 = require("./workflow/git-readAiBranchName");
8
8
  const merge_state_1 = require("./workflow/merge-state");
9
9
  const merge_end_1 = require("./workflow/merge-end");
10
10
  const merge_start_1 = require("./workflow/merge-start");
11
- // wp-update-end — finalize half of the 3-point squash-merge lifecycle. Run it AFTER `wp-update-start`
11
+ // wp-finish-update — finalize half of the 3-point squash-merge lifecycle. Run it AFTER `wp-start-update`
12
12
  // handed back conflicts and you resolved them. Given an in-progress merge marker it validates +
13
13
  // commits the AI's resolution (when the marker is not yet validated) and ALWAYS finalizes the branch
14
14
  // swap (squash→feature, push, stamp clean, clear marker). It does NOT run the build gate / dashboard
15
15
  // / PR — that is wp-finish-upsert-pr (the PR flow's finish). Refuses to run when there is no merge in
16
- // progress (a clean `wp-update-start` finalizes on its own — there is nothing left for this to do).
16
+ // progress (a clean `wp-start-update` finalizes on its own — there is nothing left for this to do).
17
17
  async function main() {
18
18
  const repoRoot = (0, child_process_1.execSync)('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();
19
19
  const home = (0, merge_state_1.mergeDirFor)(repoRoot, (0, git_readAiBranchName_1.getFeatureName)());
@@ -22,14 +22,14 @@ async function main() {
22
22
  const marker = activeDir ? (0, merge_state_1.readMergeMarker)(activeDir) : null;
23
23
  if (!activeDir || !marker) {
24
24
  throw new rules_config_1.CliExitError(1, '❌ No merge in progress (no marker) — nothing to finalize.\n' +
25
- 'Start one with: pnpm wp-update-start (a clean update finalizes itself).');
25
+ 'Start one with: pnpm wp-start-update (a clean update finalizes itself).');
26
26
  }
27
27
  // Not yet validated => a conflict resolution the AI owns, so validate + commit it first; already
28
28
  // validated => clean merge (or previously validated) => finalize only.
29
29
  const conflictedFiles = marker.validated ? null : marker.conflictedFiles;
30
- await (0, merge_end_1.mergeEnd)(repoRoot, 'wp-update-end', activeDir, new merge_start_1.MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber), conflictedFiles);
30
+ await (0, merge_end_1.mergeEnd)(repoRoot, 'wp-finish-update', activeDir, new merge_start_1.MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber), conflictedFiles);
31
31
  process.stdout.write('\n✅ Merge finalized on ' + marker.currentBranch + '.\n');
32
32
  }
33
33
  if (require.main === module)
34
34
  (0, rules_config_1.runMain)(main);
35
- //# sourceMappingURL=wp-update-end.js.map
35
+ //# sourceMappingURL=wp-finish-update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wp-finish-update.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/wp-finish-update.ts"],"names":[],"mappings":";;;AAeA,oBAuBC;AArCD,iDAAyC;AACzC,0DAAgE;AAChE,0EAAiE;AACjE,wDAA6F;AAC7F,oDAAgD;AAChD,wDAAsD;AAEtD,yGAAyG;AACzG,gGAAgG;AAChG,qGAAqG;AACrG,qGAAqG;AACrG,sGAAsG;AACtG,oGAAoG;AAE7F,KAAK,UAAU,IAAI;IACtB,MAAM,QAAQ,GAAG,IAAA,wBAAQ,EAAC,+BAA+B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxF,MAAM,IAAI,GAAG,IAAA,yBAAW,EAAC,QAAQ,EAAE,IAAA,qCAAc,GAAE,CAAC,CAAC;IAErD,sEAAsE;IACtE,MAAM,SAAS,GAAG,IAAA,mCAAqB,EAAC,IAAI,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,IAAA,6BAAe,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7D,IAAI,CAAC,SAAS,IAAI,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,6DAA6D;YAC7D,2EAA2E,CAC9E,CAAC;IACN,CAAC;IAED,iGAAiG;IACjG,uEAAuE;IACvE,MAAM,eAAe,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC;IACzE,MAAM,IAAA,oBAAQ,EACV,QAAQ,EAAE,kBAAkB,EAAE,SAAS,EACvC,IAAI,0BAAY,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,EACjG,eAAe,CAClB,CAAC;IACF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,GAAG,MAAM,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;AACnF,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;IAAE,IAAA,sBAAO,EAAC,IAAI,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { execSync } from 'child_process';\nimport { CliExitError, runMain } from '@webpieces/rules-config';\nimport { getFeatureName } from './workflow/git-readAiBranchName';\nimport { mergeDirFor, readMergeMarker, findActiveMergeRunDir } from './workflow/merge-state';\nimport { mergeEnd } from './workflow/merge-end';\nimport { MergeContext } from './workflow/merge-start';\n\n// wp-finish-update — finalize half of the 3-point squash-merge lifecycle. Run it AFTER `wp-start-update`\n// handed back conflicts and you resolved them. Given an in-progress merge marker it validates +\n// commits the AI's resolution (when the marker is not yet validated) and ALWAYS finalizes the branch\n// swap (squash→feature, push, stamp clean, clear marker). It does NOT run the build gate / dashboard\n// / PR — that is wp-finish-upsert-pr (the PR flow's finish). Refuses to run when there is no merge in\n// progress (a clean `wp-start-update` finalizes on its own — there is nothing left for this to do).\n\nexport async function main(): Promise<void> {\n const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();\n const home = mergeDirFor(repoRoot, getFeatureName());\n\n // The in-progress merge is the `merge-<n>/` run dir holding a marker.\n const activeDir = findActiveMergeRunDir(home);\n const marker = activeDir ? readMergeMarker(activeDir) : null;\n if (!activeDir || !marker) {\n throw new CliExitError(1,\n '❌ No merge in progress (no marker) — nothing to finalize.\\n' +\n 'Start one with: pnpm wp-start-update (a clean update finalizes itself).',\n );\n }\n\n // Not yet validated => a conflict resolution the AI owns, so validate + commit it first; already\n // validated => clean merge (or previously validated) => finalize only.\n const conflictedFiles = marker.validated ? null : marker.conflictedFiles;\n await mergeEnd(\n repoRoot, 'wp-finish-update', activeDir,\n new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber),\n conflictedFiles,\n );\n process.stdout.write('\\n✅ Merge finalized on ' + marker.currentBranch + '.\\n');\n}\n\nif (require.main === module) runMain(main);\n"]}
@@ -7,13 +7,13 @@ const child_process_1 = require("child_process");
7
7
  const rules_config_1 = require("@webpieces/rules-config");
8
8
  const open_pr_check_1 = require("./workflow/open-pr-check");
9
9
  const run_update_1 = require("./workflow/run-update");
10
- // wp-update-start: the "sync this feature branch from main" entry point (the redirect target of the
10
+ // wp-start-update: the "sync this feature branch from main" entry point (the redirect target of the
11
11
  // redirect-how-to-merge-main guard). It runs the FULL 3-point squash-update via the shared
12
- // runUpdateFromMain engine: on a CLEAN merge it finalizes everything (no need to call wp-update-end);
12
+ // runUpdateFromMain engine: on a CLEAN merge it finalizes everything (no need to call wp-finish-update);
13
13
  // on CONFLICT it writes the 3-point context + merge process doc and hands back — you resolve, then
14
- // run `wp-update-end` to finalize. It NEVER creates a PR (that is the wp-*-upsert-pr flow).
14
+ // run `wp-finish-update` to finalize. It NEVER creates a PR (that is the wp-*-upsert-pr flow).
15
15
  const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
16
- // If a PR is already OPEN for this branch, wp-update-start must refuse. The 3-point update re-squashes
16
+ // If a PR is already OPEN for this branch, wp-start-update must refuse. The 3-point update re-squashes
17
17
  // your branch onto main and force-pushes it to origin/<feature> — the PR head — but it does NOT refresh
18
18
  // the PR body/review or run the authoritative build gate. So it would push new code onto an open PR
19
19
  // without an updated review. The PR flow (wp-start-upsert-pr → wp-finish-upsert-pr) is the ONLY correct
@@ -25,7 +25,7 @@ function assertNoOpenPr(repoRoot) {
25
25
  if (openPr === '')
26
26
  return;
27
27
  throw new rules_config_1.CliExitError(2, '\n' + SEP + `⛔ An open PR (#${openPr}) already tracks this branch\n` + SEP + '\n' +
28
- 'wp-update-start re-squashes your branch onto main and force-pushes it, but it does NOT refresh\n' +
28
+ 'wp-start-update re-squashes your branch onto main and force-pushes it, but it does NOT refresh\n' +
29
29
  `the PR body/review — so PR #${openPr} would get new code without an updated review. Use the PR\n` +
30
30
  'flow instead — it re-merges main AND updates the PR:\n' +
31
31
  ' 1. pnpm wp-start-upsert-pr\n' +
@@ -39,7 +39,7 @@ async function main() {
39
39
  // An open PR means the PR flow must be used — a 3-point update would strand the PR on the old
40
40
  // branch generation. Fails fast if GitHub can't be reached (never guesses "no PR").
41
41
  assertNoOpenPr(repoRoot);
42
- const outcome = await (0, run_update_1.runUpdateFromMain)(repoRoot, 'wp-update-start', 'wp-update-end');
42
+ const outcome = await (0, run_update_1.runUpdateFromMain)(repoRoot, 'wp-start-update', 'wp-finish-update');
43
43
  if (outcome === 'conflict') {
44
44
  // Context + marker + merge process doc already written by merge-start; hand back to the AI.
45
45
  throw new rules_config_1.CliExitError(2, '');
@@ -47,10 +47,10 @@ async function main() {
47
47
  if (outcome === 'unvalidatedResume') {
48
48
  throw new rules_config_1.CliExitError(1, '\n' + SEP + '⏸️ Merge in progress — not yet validated\n' + SEP + '\n' +
49
49
  'Resolve the remaining conflicts in the working tree, then run:\n' +
50
- ' pnpm wp-update-end\n');
50
+ ' pnpm wp-finish-update\n');
51
51
  }
52
- process.stdout.write('\n✅ Updated from main — clean. No need to call wp-update-end.\n');
52
+ process.stdout.write('\n✅ Updated from main — clean. No need to call wp-finish-update.\n');
53
53
  }
54
54
  if (require.main === module)
55
55
  (0, rules_config_1.runMain)(main);
56
- //# sourceMappingURL=wp-update-start.js.map
56
+ //# sourceMappingURL=wp-start-update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wp-start-update.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/wp-start-update.ts"],"names":[],"mappings":";;;AAoBA,wCAaC;AAED,oBAsBC;AAxDD,iDAAyC;AACzC,0DAA+E;AAC/E,4DAA2D;AAC3D,sDAA0D;AAE1D,oGAAoG;AACpG,2FAA2F;AAC3F,yGAAyG;AACzG,mGAAmG;AACnG,+FAA+F;AAE/F,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,uGAAuG;AACvG,wGAAwG;AACxG,oGAAoG;AACpG,wGAAwG;AACxG,2GAA2G;AAC3G,uGAAuG;AACvG,SAAgB,cAAc,CAAC,QAAgB;IAC3C,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,iCAAiC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACvG,MAAM,MAAM,GAAG,IAAA,+BAAe,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjD,IAAI,MAAM,KAAK,EAAE;QAAE,OAAO;IAC1B,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,IAAI,GAAG,GAAG,GAAG,kBAAkB,MAAM,gCAAgC,GAAG,GAAG,GAAG,IAAI;QAClF,kGAAkG;QAClG,+BAA+B,MAAM,6DAA6D;QAClG,wDAAwD;QACxD,gCAAgC;QAChC,wCAAwC;QACxC,iCAAiC,CACpC,CAAC;AACN,CAAC;AAEM,KAAK,UAAU,IAAI;IACtB,MAAM,QAAQ,GAAG,IAAA,wBAAQ,EAAC,+BAA+B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxF,gGAAgG;IAChG,IAAA,4BAAa,EAAC,QAAQ,EAAE,2BAA2B,CAAC,CAAC;IAErD,8FAA8F;IAC9F,oFAAoF;IACpF,cAAc,CAAC,QAAQ,CAAC,CAAC;IAEzB,MAAM,OAAO,GAAG,MAAM,IAAA,8BAAiB,EAAC,QAAQ,EAAE,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;IACzF,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;QACzB,4FAA4F;QAC5F,MAAM,IAAI,2BAAY,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClC,CAAC;IACD,IAAI,OAAO,KAAK,mBAAmB,EAAE,CAAC;QAClC,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,IAAI,GAAG,GAAG,GAAG,6CAA6C,GAAG,GAAG,GAAG,IAAI;YACvE,kEAAkE;YAClE,2BAA2B,CAC9B,CAAC;IACN,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oEAAoE,CAAC,CAAC;AAC/F,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;IAAE,IAAA,sBAAO,EAAC,IAAI,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { execSync } from 'child_process';\nimport { writeTemplate, CliExitError, runMain } from '@webpieces/rules-config';\nimport { openPrForBranch } from './workflow/open-pr-check';\nimport { runUpdateFromMain } from './workflow/run-update';\n\n// wp-start-update: the \"sync this feature branch from main\" entry point (the redirect target of the\n// redirect-how-to-merge-main guard). It runs the FULL 3-point squash-update via the shared\n// runUpdateFromMain engine: on a CLEAN merge it finalizes everything (no need to call wp-finish-update);\n// on CONFLICT it writes the 3-point context + merge process doc and hands back — you resolve, then\n// run `wp-finish-update` to finalize. It NEVER creates a PR (that is the wp-*-upsert-pr flow).\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// If a PR is already OPEN for this branch, wp-start-update must refuse. The 3-point update re-squashes\n// your branch onto main and force-pushes it to origin/<feature> — the PR head — but it does NOT refresh\n// the PR body/review or run the authoritative build gate. So it would push new code onto an open PR\n// without an updated review. The PR flow (wp-start-upsert-pr → wp-finish-upsert-pr) is the ONLY correct\n// path once a PR exists: it re-merges main AND updates the PR. Fail fast and steer there. (openPrForBranch\n// itself fails fast if GitHub can't be reached — we never assume \"no PR\" when we simply couldn't ask.)\nexport function assertNoOpenPr(repoRoot: string): void {\n const branch = execSync('git rev-parse --abbrev-ref HEAD', { cwd: repoRoot, encoding: 'utf8' }).trim();\n const openPr = openPrForBranch(repoRoot, branch);\n if (openPr === '') return;\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ An open PR (#${openPr}) already tracks this branch\\n` + SEP + '\\n' +\n 'wp-start-update re-squashes your branch onto main and force-pushes it, but it does NOT refresh\\n' +\n `the PR body/review — so PR #${openPr} would get new code without an updated review. Use the PR\\n` +\n 'flow instead — it re-merges main AND updates the PR:\\n' +\n ' 1. pnpm wp-start-upsert-pr\\n' +\n ' 2. /wp-merge (only if conflicts)\\n' +\n ' 3. pnpm wp-finish-upsert-pr\\n',\n );\n}\n\nexport async function main(): Promise<void> {\n const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();\n // Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n\n // An open PR means the PR flow must be used — a 3-point update would strand the PR on the old\n // branch generation. Fails fast if GitHub can't be reached (never guesses \"no PR\").\n assertNoOpenPr(repoRoot);\n\n const outcome = await runUpdateFromMain(repoRoot, 'wp-start-update', 'wp-finish-update');\n if (outcome === 'conflict') {\n // Context + marker + merge process doc already written by merge-start; hand back to the AI.\n throw new CliExitError(2, '');\n }\n if (outcome === 'unvalidatedResume') {\n throw new CliExitError(1,\n '\\n' + SEP + '⏸️ Merge in progress — not yet validated\\n' + SEP + '\\n' +\n 'Resolve the remaining conflicts in the working tree, then run:\\n' +\n ' pnpm wp-finish-update\\n',\n );\n }\n process.stdout.write('\\n✅ Updated from main — clean. No need to call wp-finish-update.\\n');\n}\n\nif (require.main === module) runMain(main);\n"]}
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.main = main;
5
- const child_process_1 = require("child_process");
6
- const rules_config_1 = require("@webpieces/rules-config");
7
- const build_affected_1 = require("./workflow/build-affected");
8
- // Single shared build entry point. CI runs this AND the PR command runs this, so the two can
9
- // never diverge. The build command is sourced from PrGateConfig.buildCommand (webpieces.config.json
10
- // "pr-gate" section), defaulting to `pnpm nx affected --target=ci --base=$(git merge-base origin/main HEAD)`.
11
- // The `--base` is the FORK POINT (git merge-base), NOT origin/main: basing on origin/main would mark
12
- // projects touched by other people's already-merged PRs as "affected" (your branch still has their
13
- // pre-merge versions), wasting a rebuild. The fork point scopes "affected" to only your branch's work.
14
- async function main() {
15
- const repoRoot = (0, child_process_1.execSync)('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();
16
- const config = (0, rules_config_1.loadAndValidate)(repoRoot).prGate;
17
- const code = (0, build_affected_1.runBuildAffected)(repoRoot, config.buildCommand);
18
- // A non-zero build must fail the process with that exact code — throw so runMain (the single exit
19
- // site) translates it; a clean build returns and the process exits 0 naturally.
20
- if (code !== 0)
21
- throw new rules_config_1.CliExitError(code, '');
22
- }
23
- if (require.main === module)
24
- (0, rules_config_1.runMain)(main);
25
- //# sourceMappingURL=wp-build-affected.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wp-build-affected.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/wp-build-affected.ts"],"names":[],"mappings":";;;AAWA,oBAOC;AAjBD,iDAAyC;AACzC,0DAAiF;AACjF,8DAA6D;AAE7D,6FAA6F;AAC7F,oGAAoG;AACpG,8GAA8G;AAC9G,qGAAqG;AACrG,mGAAmG;AACnG,uGAAuG;AAChG,KAAK,UAAU,IAAI;IACtB,MAAM,QAAQ,GAAG,IAAA,wBAAQ,EAAC,+BAA+B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxF,MAAM,MAAM,GAAG,IAAA,8BAAe,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;IAChD,MAAM,IAAI,GAAG,IAAA,iCAAgB,EAAC,QAAQ,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAC7D,kGAAkG;IAClG,gFAAgF;IAChF,IAAI,IAAI,KAAK,CAAC;QAAE,MAAM,IAAI,2BAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACrD,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;IAAE,IAAA,sBAAO,EAAC,IAAI,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { execSync } from 'child_process';\nimport { loadAndValidate, CliExitError, runMain } from '@webpieces/rules-config';\nimport { runBuildAffected } from './workflow/build-affected';\n\n// Single shared build entry point. CI runs this AND the PR command runs this, so the two can\n// never diverge. The build command is sourced from PrGateConfig.buildCommand (webpieces.config.json\n// \"pr-gate\" section), defaulting to `pnpm nx affected --target=ci --base=$(git merge-base origin/main HEAD)`.\n// The `--base` is the FORK POINT (git merge-base), NOT origin/main: basing on origin/main would mark\n// projects touched by other people's already-merged PRs as \"affected\" (your branch still has their\n// pre-merge versions), wasting a rebuild. The fork point scopes \"affected\" to only your branch's work.\nexport async function main(): Promise<void> {\n const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();\n const config = loadAndValidate(repoRoot).prGate;\n const code = runBuildAffected(repoRoot, config.buildCommand);\n // A non-zero build must fail the process with that exact code — throw so runMain (the single exit\n // site) translates it; a clean build returns and the process exits 0 naturally.\n if (code !== 0) throw new CliExitError(code, '');\n}\n\nif (require.main === module) runMain(main);\n"]}
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export declare function main(): Promise<void>;
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.main = main;
5
- const rules_config_1 = require("@webpieces/rules-config");
6
- const git_gatherInfo_1 = require("./git-gatherInfo");
7
- // Thin bin wrapper around gatherInfo(): the diagnostic entry point that just prints the 3-point merge
8
- // context. gatherInfo NEVER exits the process — that is this wrapper's job, delegated to runMain (the
9
- // single sanctioned process.exit site). The real flow calls gatherInfo() as a library from merge-start.
10
- async function main() {
11
- await (0, git_gatherInfo_1.gatherInfo)();
12
- }
13
- if (require.main === module)
14
- (0, rules_config_1.runMain)(main);
15
- //# sourceMappingURL=wp-git-gather.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wp-git-gather.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/wp-git-gather.ts"],"names":[],"mappings":";;;AAOA,oBAEC;AARD,0DAAkD;AAClD,qDAA8C;AAE9C,sGAAsG;AACtG,sGAAsG;AACtG,wGAAwG;AACjG,KAAK,UAAU,IAAI;IACtB,MAAM,IAAA,2BAAU,GAAE,CAAC;AACvB,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;IAAE,IAAA,sBAAO,EAAC,IAAI,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { runMain } from '@webpieces/rules-config';\nimport { gatherInfo } from './git-gatherInfo';\n\n// Thin bin wrapper around gatherInfo(): the diagnostic entry point that just prints the 3-point merge\n// context. gatherInfo NEVER exits the process — that is this wrapper's job, delegated to runMain (the\n// single sanctioned process.exit site). The real flow calls gatherInfo() as a library from merge-start.\nexport async function main(): Promise<void> {\n await gatherInfo();\n}\n\nif (require.main === module) runMain(main);\n"]}
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export declare function main(): Promise<void>;
@@ -1 +0,0 @@
1
- {"version":3,"file":"wp-update-end.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/wp-update-end.ts"],"names":[],"mappings":";;;AAeA,oBAuBC;AArCD,iDAAyC;AACzC,0DAAgE;AAChE,0EAAiE;AACjE,wDAA6F;AAC7F,oDAAgD;AAChD,wDAAsD;AAEtD,sGAAsG;AACtG,gGAAgG;AAChG,qGAAqG;AACrG,qGAAqG;AACrG,sGAAsG;AACtG,oGAAoG;AAE7F,KAAK,UAAU,IAAI;IACtB,MAAM,QAAQ,GAAG,IAAA,wBAAQ,EAAC,+BAA+B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxF,MAAM,IAAI,GAAG,IAAA,yBAAW,EAAC,QAAQ,EAAE,IAAA,qCAAc,GAAE,CAAC,CAAC;IAErD,sEAAsE;IACtE,MAAM,SAAS,GAAG,IAAA,mCAAqB,EAAC,IAAI,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,IAAA,6BAAe,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7D,IAAI,CAAC,SAAS,IAAI,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,6DAA6D;YAC7D,2EAA2E,CAC9E,CAAC;IACN,CAAC;IAED,iGAAiG;IACjG,uEAAuE;IACvE,MAAM,eAAe,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC;IACzE,MAAM,IAAA,oBAAQ,EACV,QAAQ,EAAE,eAAe,EAAE,SAAS,EACpC,IAAI,0BAAY,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,EACjG,eAAe,CAClB,CAAC;IACF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,GAAG,MAAM,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;AACnF,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;IAAE,IAAA,sBAAO,EAAC,IAAI,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { execSync } from 'child_process';\nimport { CliExitError, runMain } from '@webpieces/rules-config';\nimport { getFeatureName } from './workflow/git-readAiBranchName';\nimport { mergeDirFor, readMergeMarker, findActiveMergeRunDir } from './workflow/merge-state';\nimport { mergeEnd } from './workflow/merge-end';\nimport { MergeContext } from './workflow/merge-start';\n\n// wp-update-end — finalize half of the 3-point squash-merge lifecycle. Run it AFTER `wp-update-start`\n// handed back conflicts and you resolved them. Given an in-progress merge marker it validates +\n// commits the AI's resolution (when the marker is not yet validated) and ALWAYS finalizes the branch\n// swap (squash→feature, push, stamp clean, clear marker). It does NOT run the build gate / dashboard\n// / PR — that is wp-finish-upsert-pr (the PR flow's finish). Refuses to run when there is no merge in\n// progress (a clean `wp-update-start` finalizes on its own — there is nothing left for this to do).\n\nexport async function main(): Promise<void> {\n const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();\n const home = mergeDirFor(repoRoot, getFeatureName());\n\n // The in-progress merge is the `merge-<n>/` run dir holding a marker.\n const activeDir = findActiveMergeRunDir(home);\n const marker = activeDir ? readMergeMarker(activeDir) : null;\n if (!activeDir || !marker) {\n throw new CliExitError(1,\n '❌ No merge in progress (no marker) — nothing to finalize.\\n' +\n 'Start one with: pnpm wp-update-start (a clean update finalizes itself).',\n );\n }\n\n // Not yet validated => a conflict resolution the AI owns, so validate + commit it first; already\n // validated => clean merge (or previously validated) => finalize only.\n const conflictedFiles = marker.validated ? null : marker.conflictedFiles;\n await mergeEnd(\n repoRoot, 'wp-update-end', activeDir,\n new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber),\n conflictedFiles,\n );\n process.stdout.write('\\n✅ Merge finalized on ' + marker.currentBranch + '.\\n');\n}\n\nif (require.main === module) runMain(main);\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"wp-update-start.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/wp-update-start.ts"],"names":[],"mappings":";;;AAoBA,wCAaC;AAED,oBAsBC;AAxDD,iDAAyC;AACzC,0DAA+E;AAC/E,4DAA2D;AAC3D,sDAA0D;AAE1D,oGAAoG;AACpG,2FAA2F;AAC3F,sGAAsG;AACtG,mGAAmG;AACnG,4FAA4F;AAE5F,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,uGAAuG;AACvG,wGAAwG;AACxG,oGAAoG;AACpG,wGAAwG;AACxG,2GAA2G;AAC3G,uGAAuG;AACvG,SAAgB,cAAc,CAAC,QAAgB;IAC3C,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,iCAAiC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACvG,MAAM,MAAM,GAAG,IAAA,+BAAe,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjD,IAAI,MAAM,KAAK,EAAE;QAAE,OAAO;IAC1B,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,IAAI,GAAG,GAAG,GAAG,kBAAkB,MAAM,gCAAgC,GAAG,GAAG,GAAG,IAAI;QAClF,kGAAkG;QAClG,+BAA+B,MAAM,6DAA6D;QAClG,wDAAwD;QACxD,gCAAgC;QAChC,wCAAwC;QACxC,iCAAiC,CACpC,CAAC;AACN,CAAC;AAEM,KAAK,UAAU,IAAI;IACtB,MAAM,QAAQ,GAAG,IAAA,wBAAQ,EAAC,+BAA+B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxF,gGAAgG;IAChG,IAAA,4BAAa,EAAC,QAAQ,EAAE,2BAA2B,CAAC,CAAC;IAErD,8FAA8F;IAC9F,oFAAoF;IACpF,cAAc,CAAC,QAAQ,CAAC,CAAC;IAEzB,MAAM,OAAO,GAAG,MAAM,IAAA,8BAAiB,EAAC,QAAQ,EAAE,iBAAiB,EAAE,eAAe,CAAC,CAAC;IACtF,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;QACzB,4FAA4F;QAC5F,MAAM,IAAI,2BAAY,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClC,CAAC;IACD,IAAI,OAAO,KAAK,mBAAmB,EAAE,CAAC;QAClC,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,IAAI,GAAG,GAAG,GAAG,6CAA6C,GAAG,GAAG,GAAG,IAAI;YACvE,kEAAkE;YAClE,wBAAwB,CAC3B,CAAC;IACN,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iEAAiE,CAAC,CAAC;AAC5F,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;IAAE,IAAA,sBAAO,EAAC,IAAI,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { execSync } from 'child_process';\nimport { writeTemplate, CliExitError, runMain } from '@webpieces/rules-config';\nimport { openPrForBranch } from './workflow/open-pr-check';\nimport { runUpdateFromMain } from './workflow/run-update';\n\n// wp-update-start: the \"sync this feature branch from main\" entry point (the redirect target of the\n// redirect-how-to-merge-main guard). It runs the FULL 3-point squash-update via the shared\n// runUpdateFromMain engine: on a CLEAN merge it finalizes everything (no need to call wp-update-end);\n// on CONFLICT it writes the 3-point context + merge process doc and hands back — you resolve, then\n// run `wp-update-end` to finalize. It NEVER creates a PR (that is the wp-*-upsert-pr flow).\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// If a PR is already OPEN for this branch, wp-update-start must refuse. The 3-point update re-squashes\n// your branch onto main and force-pushes it to origin/<feature> — the PR head — but it does NOT refresh\n// the PR body/review or run the authoritative build gate. So it would push new code onto an open PR\n// without an updated review. The PR flow (wp-start-upsert-pr → wp-finish-upsert-pr) is the ONLY correct\n// path once a PR exists: it re-merges main AND updates the PR. Fail fast and steer there. (openPrForBranch\n// itself fails fast if GitHub can't be reached — we never assume \"no PR\" when we simply couldn't ask.)\nexport function assertNoOpenPr(repoRoot: string): void {\n const branch = execSync('git rev-parse --abbrev-ref HEAD', { cwd: repoRoot, encoding: 'utf8' }).trim();\n const openPr = openPrForBranch(repoRoot, branch);\n if (openPr === '') return;\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ An open PR (#${openPr}) already tracks this branch\\n` + SEP + '\\n' +\n 'wp-update-start re-squashes your branch onto main and force-pushes it, but it does NOT refresh\\n' +\n `the PR body/review — so PR #${openPr} would get new code without an updated review. Use the PR\\n` +\n 'flow instead — it re-merges main AND updates the PR:\\n' +\n ' 1. pnpm wp-start-upsert-pr\\n' +\n ' 2. /wp-merge (only if conflicts)\\n' +\n ' 3. pnpm wp-finish-upsert-pr\\n',\n );\n}\n\nexport async function main(): Promise<void> {\n const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();\n // Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n\n // An open PR means the PR flow must be used — a 3-point update would strand the PR on the old\n // branch generation. Fails fast if GitHub can't be reached (never guesses \"no PR\").\n assertNoOpenPr(repoRoot);\n\n const outcome = await runUpdateFromMain(repoRoot, 'wp-update-start', 'wp-update-end');\n if (outcome === 'conflict') {\n // Context + marker + merge process doc already written by merge-start; hand back to the AI.\n throw new CliExitError(2, '');\n }\n if (outcome === 'unvalidatedResume') {\n throw new CliExitError(1,\n '\\n' + SEP + '⏸️ Merge in progress — not yet validated\\n' + SEP + '\\n' +\n 'Resolve the remaining conflicts in the working tree, then run:\\n' +\n ' pnpm wp-update-end\\n',\n );\n }\n process.stdout.write('\\n✅ Updated from main — clean. No need to call wp-update-end.\\n');\n}\n\nif (require.main === module) runMain(main);\n"]}