@webpieces/pr-gate 0.3.222 β†’ 0.3.224

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/pr-gate",
3
- "version": "0.3.222",
3
+ "version": "0.3.224",
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",
@@ -24,7 +24,7 @@
24
24
  "directory": "packages/tooling/pr-gate"
25
25
  },
26
26
  "dependencies": {
27
- "@webpieces/rules-config": "0.3.222"
27
+ "@webpieces/rules-config": "0.3.224"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public"
@@ -67,6 +67,8 @@ function upsertPr(repoRoot, baseBranch, body) {
67
67
  }
68
68
  async function main() {
69
69
  const repoRoot = (0, child_process_1.execSync)('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();
70
+ // Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.
71
+ (0, rules_config_1.writeTemplate)(repoRoot, 'webpieces.git-workflow.md');
70
72
  const mergeDir = (0, merge_state_1.mergeDirFor)(repoRoot, (0, git_readAiBranchName_1.getFeatureName)());
71
73
  // 1. Finish any in-progress conflict resolution: validate + commit + finalize the branch swap.
72
74
  // No marker (or already validated) => no merge in progress => nothing to do (the common case).
@@ -76,6 +78,10 @@ async function main() {
76
78
  }
77
79
  // 2. REQUIRE the AI-authored review.json (throws InformAiError with the schema if missing/invalid).
78
80
  const review = (0, rules_config_1.loadReviewJson)((0, rules_config_1.reviewJsonPath)(repoRoot, (0, git_readAiBranchName_1.getFeatureName)()));
81
+ // 2b. The build gate validates the WORKING TREE but we push HEAD β€” so they MUST be identical, or a
82
+ // fix edited after the merge commit builds green yet a stale commit gets pushed (CI then fails on
83
+ // the committed tree). Require a clean tree here; the tooling won't commit your work for you.
84
+ (0, git_exec_1.assertCleanTree)(repoRoot);
79
85
  // 3. Authoritative build gate, then push, then post.
80
86
  (0, build_affected_1.runBuildGate)(repoRoot, new build_affected_1.BuildGateOptions('πŸ› οΈ Build gate (authoritative)', 'pnpm wp-finish-upsert-pr', 'Build failed β€” no PR created/updated.'));
81
87
  // After finalize the local branch is the numbered generation (base2/…); the remote branch and
@@ -1 +1 @@
1
- {"version":3,"file":"git-finishUpsertPr.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-finishUpsertPr.ts"],"names":[],"mappings":";;;AAqFA,oBA+BC;;AAnHD,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAMiC;AACjC,0EAAiE;AACjE,4DAA0D;AAC1D,kDAAmD;AACnD,8DAA2E;AAC3E,wDAAsE;AACtE,oDAAgD;AAChD,wDAAsD;AACtD,sDAKgC;AAEhC,sGAAsG;AACtG,uGAAuG;AACvG,uGAAuG;AACvG,8FAA8F;AAC9F,qGAAqG;AACrG,+BAA+B;AAE/B,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,SAAS,MAAM,CAAC,IAAc;IAC1B,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACnE,CAAC;AAED,SAAS,cAAc,CAAC,QAAgB,EAAE,WAAoB,EAAE,MAAkB;IAC9E,MAAM,MAAM,GAAG,IAAA,8BAAe,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;IAChD,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,YAAY,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC;IAChE,MAAM,WAAW,GAAG,MA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IAAA,8BAAc,EAAC,IAAA,wBAAQ,EAAC,2BAA2B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAChG,IAAA,uBAAY,EAAC,IAAI,CAAC,CAAC;IAEnB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,qBAAqB,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;IACtE,MAAM,IAAI,GAAG,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACpD,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AACxC,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAU,EAAE,EAAE;QACxB,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport {\n loadAndValidate,\n loadReviewJson,\n prDirFor,\n reviewJsonPath,\n ReviewJson,\n} from '@webpieces/rules-config';\nimport { getFeatureName } from './workflow/git-readAiBranchName';\nimport { baseBranchName } from './workflow/branch-naming';\nimport { ensurePushed } from './workflow/git-exec';\nimport { runBuildGate, BuildGateOptions } from './workflow/build-affected';\nimport { mergeDirFor, readMergeMarker } from './workflow/merge-state';\nimport { mergeEnd } from './workflow/merge-end';\nimport { MergeContext } from './workflow/merge-start';\nimport {\n computeGateResults,\n countAddedDisables,\n renderDashboard,\n DashboardInput,\n} from '../dashboard/dashboard';\n\n// FINISH of the AI-first PR flow. Runs after the AI has written review.json (see wp-start-upsert-pr).\n// Responsibilities, in order: (1) if a 3-point merge was in progress, validate + commit + FINALIZE the\n// AI's resolution via merge-END (so the PR is posted from the finalized feature branch, not the squash\n// branch); (2) REQUIRE review.json (hard-fail with the schema if absent/invalid); (3) run the\n// authoritative build gate; (4) render the dashboard; (5) create/update the PR via `gh`. This is the\n// ONLY command that posts PRs.\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\nfunction gitOut(args: string[]): string {\n const result = spawnSync('git', args, { encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n}\n\nfunction buildDashboard(repoRoot: string, buildPassed: boolean, review: ReviewJson): string {\n const config = loadAndValidate(repoRoot).prGate;\n const forkPoint = gitOut(['merge-base', 'origin/main', 'HEAD']);\n const featureHead = gitOut(['rev-parse', 'HEAD']);\n const mainHead = gitOut(['rev-parse', 'origin/main']);\n const range = `${forkPoint}..${featureHead}`;\n const changedFiles = gitOut(['diff', range, '--name-only']).split('\\n').filter((f: string): boolean => f.trim() !== '');\n const patch = gitOut(['diff', range]);\n const title = gitOut(['log', '-1', '--format=%s']);\n\n const gateResults = computeGateResults(config.gates, changedFiles);\n const disables = countAddedDisables(patch);\n const input = new DashboardInput(title, gateResults, disables, buildPassed, forkPoint, featureHead, mainHead, review);\n return renderDashboard(input);\n}\n\n// The PR always lives on the stable base branch (the local branch may be a numbered generation\n// base2/base3/…). Look up / create / merge against `baseBranch`, never the numbered branch, or\n// generation 2+ would fail to find its PR and open a duplicate.\nfunction upsertPr(repoRoot: string, baseBranch: string, body: string): void {\n const prDir = prDirFor(repoRoot, getFeatureName());\n fs.mkdirSync(prDir, { recursive: true });\n const bodyFile = path.join(prDir, 'pr-body.md');\n fs.writeFileSync(bodyFile, body + '\\n');\n\n const existing = gitOut(['log', '-1', '--format=%s']); // title fallback\n const prNumber = spawnSync(\n 'gh', ['pr', 'list', '--head', baseBranch, '--json', 'number', '--jq', '.[0].number'],\n { encoding: 'utf8' },\n );\n const num = prNumber.status === 0 ? (prNumber.stdout ?? '').trim() : '';\n\n if (num === '') {\n process.stdout.write('Creating PR...\\n');\n const create = spawnSync('gh', ['pr', 'create', '--head', baseBranch, '--base', 'main', '--title', existing, '--body-file', bodyFile], { stdio: 'inherit' });\n if (create.status !== 0) {\n process.stderr.write('⚠️ gh pr create failed β€” create the PR manually with the body in:\\n ' + bodyFile + '\\n');\n return;\n }\n } else {\n process.stdout.write(`Updating PR #${num}...\\n`);\n spawnSync('gh', ['pr', 'edit', num, '--body-file', bodyFile], { stdio: 'inherit' });\n }\n spawnSync('gh', ['pr', 'merge', baseBranch, '--auto', '--squash'], { stdio: 'inherit' });\n}\n\nexport async function main(): Promise<void> {\n const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();\n const mergeDir = mergeDirFor(repoRoot, getFeatureName());\n\n // 1. Finish any in-progress conflict resolution: validate + commit + finalize the branch swap.\n // No marker (or already validated) => no merge in progress => nothing to do (the common case).\n const marker = readMergeMarker(mergeDir);\n if (marker && !marker.validated) {\n await mergeEnd(\n repoRoot, mergeDir,\n new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber),\n marker.conflictedFiles,\n );\n }\n\n // 2. REQUIRE the AI-authored review.json (throws InformAiError with the schema if missing/invalid).\n const review = loadReviewJson(reviewJsonPath(repoRoot, getFeatureName()));\n\n // 3. Authoritative build gate, then push, then post.\n runBuildGate(repoRoot, new BuildGateOptions(\n 'πŸ› οΈ Build gate (authoritative)', 'pnpm wp-finish-upsert-pr', 'Build failed β€” no PR created/updated.',\n ));\n // After finalize the local branch is the numbered generation (base2/…); the remote branch and\n // PR live on the stable base name β€” push and upsert against that.\n const base = baseBranchName(execSync('git branch --show-current', { encoding: 'utf8' }).trim());\n ensurePushed(base);\n\n process.stdout.write('\\n' + SEP + 'πŸ“‹ Dashboard + PR\\n' + SEP + '\\n');\n const body = buildDashboard(repoRoot, true, review);\n upsertPr(repoRoot, base, body);\n process.stdout.write('\\nβœ… Done.\\n');\n}\n\nif (require.main === module) {\n main().catch((err: Error) => {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(message + '\\n');\n process.exit(1);\n });\n}\n"]}
1
+ {"version":3,"file":"git-finishUpsertPr.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-finishUpsertPr.ts"],"names":[],"mappings":";;;AAsFA,oBAsCC;;AA3HD,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAOiC;AACjC,0EAAiE;AACjE,4DAA0D;AAC1D,kDAAoE;AACpE,8DAA2E;AAC3E,wDAAsE;AACtE,oDAAgD;AAChD,wDAAsD;AACtD,sDAKgC;AAEhC,sGAAsG;AACtG,uGAAuG;AACvG,uGAAuG;AACvG,8FAA8F;AAC9F,qGAAqG;AACrG,+BAA+B;AAE/B,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,SAAS,MAAM,CAAC,IAAc;IAC1B,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACnE,CAAC;AAED,SAAS,cAAc,CAAC,QAAgB,EAAE,WAAoB,EAAE,MAAkB;IAC9E,MAAM,MAAM,GAAG,IAAA,8BAAe,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;IAChD,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,Y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8FAA8F;IAC9F,IAAA,0BAAe,EAAC,QAAQ,CAAC,CAAC;IAE1B,qDAAqD;IACrD,IAAA,6BAAY,EAAC,QAAQ,EAAE,IAAI,iCAAgB,CACvC,iCAAiC,EAAE,0BAA0B,EAAE,uCAAuC,CACzG,CAAC,CAAC;IACH,8FAA8F;IAC9F,kEAAkE;IAClE,MAAM,IAAI,GAAG,IAAA,8BAAc,EAAC,IAAA,wBAAQ,EAAC,2BAA2B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAChG,IAAA,uBAAY,EAAC,IAAI,CAAC,CAAC;IAEnB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,qBAAqB,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;IACtE,MAAM,IAAI,GAAG,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACpD,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AACxC,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAU,EAAE,EAAE;QACxB,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport {\n loadAndValidate,\n loadReviewJson,\n prDirFor,\n reviewJsonPath,\n ReviewJson,\n writeTemplate,\n} from '@webpieces/rules-config';\nimport { getFeatureName } from './workflow/git-readAiBranchName';\nimport { baseBranchName } from './workflow/branch-naming';\nimport { assertCleanTree, ensurePushed } from './workflow/git-exec';\nimport { runBuildGate, BuildGateOptions } from './workflow/build-affected';\nimport { mergeDirFor, readMergeMarker } from './workflow/merge-state';\nimport { mergeEnd } from './workflow/merge-end';\nimport { MergeContext } from './workflow/merge-start';\nimport {\n computeGateResults,\n countAddedDisables,\n renderDashboard,\n DashboardInput,\n} from '../dashboard/dashboard';\n\n// FINISH of the AI-first PR flow. Runs after the AI has written review.json (see wp-start-upsert-pr).\n// Responsibilities, in order: (1) if a 3-point merge was in progress, validate + commit + FINALIZE the\n// AI's resolution via merge-END (so the PR is posted from the finalized feature branch, not the squash\n// branch); (2) REQUIRE review.json (hard-fail with the schema if absent/invalid); (3) run the\n// authoritative build gate; (4) render the dashboard; (5) create/update the PR via `gh`. This is the\n// ONLY command that posts PRs.\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\nfunction gitOut(args: string[]): string {\n const result = spawnSync('git', args, { encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n}\n\nfunction buildDashboard(repoRoot: string, buildPassed: boolean, review: ReviewJson): string {\n const config = loadAndValidate(repoRoot).prGate;\n const forkPoint = gitOut(['merge-base', 'origin/main', 'HEAD']);\n const featureHead = gitOut(['rev-parse', 'HEAD']);\n const mainHead = gitOut(['rev-parse', 'origin/main']);\n const range = `${forkPoint}..${featureHead}`;\n const changedFiles = gitOut(['diff', range, '--name-only']).split('\\n').filter((f: string): boolean => f.trim() !== '');\n const patch = gitOut(['diff', range]);\n const title = gitOut(['log', '-1', '--format=%s']);\n\n const gateResults = computeGateResults(config.gates, changedFiles);\n const disables = countAddedDisables(patch);\n const input = new DashboardInput(title, gateResults, disables, buildPassed, forkPoint, featureHead, mainHead, review);\n return renderDashboard(input);\n}\n\n// The PR always lives on the stable base branch (the local branch may be a numbered generation\n// base2/base3/…). Look up / create / merge against `baseBranch`, never the numbered branch, or\n// generation 2+ would fail to find its PR and open a duplicate.\nfunction upsertPr(repoRoot: string, baseBranch: string, body: string): void {\n const prDir = prDirFor(repoRoot, getFeatureName());\n fs.mkdirSync(prDir, { recursive: true });\n const bodyFile = path.join(prDir, 'pr-body.md');\n fs.writeFileSync(bodyFile, body + '\\n');\n\n const existing = gitOut(['log', '-1', '--format=%s']); // title fallback\n const prNumber = spawnSync(\n 'gh', ['pr', 'list', '--head', baseBranch, '--json', 'number', '--jq', '.[0].number'],\n { encoding: 'utf8' },\n );\n const num = prNumber.status === 0 ? (prNumber.stdout ?? '').trim() : '';\n\n if (num === '') {\n process.stdout.write('Creating PR...\\n');\n const create = spawnSync('gh', ['pr', 'create', '--head', baseBranch, '--base', 'main', '--title', existing, '--body-file', bodyFile], { stdio: 'inherit' });\n if (create.status !== 0) {\n process.stderr.write('⚠️ gh pr create failed β€” create the PR manually with the body in:\\n ' + bodyFile + '\\n');\n return;\n }\n } else {\n process.stdout.write(`Updating PR #${num}...\\n`);\n spawnSync('gh', ['pr', 'edit', num, '--body-file', bodyFile], { stdio: 'inherit' });\n }\n spawnSync('gh', ['pr', 'merge', baseBranch, '--auto', '--squash'], { stdio: 'inherit' });\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 const mergeDir = mergeDirFor(repoRoot, getFeatureName());\n\n // 1. Finish any in-progress conflict resolution: validate + commit + finalize the branch swap.\n // No marker (or already validated) => no merge in progress => nothing to do (the common case).\n const marker = readMergeMarker(mergeDir);\n if (marker && !marker.validated) {\n await mergeEnd(\n repoRoot, mergeDir,\n new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber),\n marker.conflictedFiles,\n );\n }\n\n // 2. REQUIRE the AI-authored review.json (throws InformAiError with the schema if missing/invalid).\n const review = loadReviewJson(reviewJsonPath(repoRoot, getFeatureName()));\n\n // 2b. The build gate validates the WORKING TREE but we push HEAD β€” so they MUST be identical, or a\n // fix edited after the merge commit builds green yet a stale commit gets pushed (CI then fails on\n // the committed tree). Require a clean tree here; the tooling won't commit your work for you.\n assertCleanTree(repoRoot);\n\n // 3. Authoritative build gate, then push, then post.\n runBuildGate(repoRoot, new BuildGateOptions(\n 'πŸ› οΈ Build gate (authoritative)', 'pnpm wp-finish-upsert-pr', 'Build failed β€” no PR created/updated.',\n ));\n // After finalize the local branch is the numbered generation (base2/…); the remote branch and\n // PR live on the stable base name β€” push and upsert against that.\n const base = baseBranchName(execSync('git branch --show-current', { encoding: 'utf8' }).trim());\n ensurePushed(base);\n\n process.stdout.write('\\n' + SEP + 'πŸ“‹ Dashboard + PR\\n' + SEP + '\\n');\n const body = buildDashboard(repoRoot, true, review);\n upsertPr(repoRoot, base, body);\n process.stdout.write('\\nβœ… Done.\\n');\n}\n\nif (require.main === module) {\n main().catch((err: Error) => {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(message + '\\n');\n process.exit(1);\n });\n}\n"]}
@@ -9,37 +9,19 @@ const path = tslib_1.__importStar(require("path"));
9
9
  const git_readAiBranchName_1 = require("./workflow/git-readAiBranchName");
10
10
  const git_findForkPoint_1 = require("./workflow/git-findForkPoint");
11
11
  const merge_state_1 = require("./workflow/merge-state");
12
+ const git_exec_1 = require("./workflow/git-exec");
12
13
  const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
13
- function validateCleanTree(currentBranch) {
14
+ function validateCleanTree(currentBranch, repoRoot) {
14
15
  if (currentBranch === 'main') {
15
16
  process.stderr.write('❌ Error: Already on main branch. No need to update from main.\n');
16
17
  process.exit(1);
17
18
  }
18
19
  process.stderr.write(`Current branch: ${currentBranch}\n`);
19
- const hasDirtyFiles = (0, child_process_1.spawnSync)('git', ['diff-index', '--quiet', 'HEAD', '--']).status !== 0;
20
- if (!hasDirtyFiles)
21
- return;
22
- const changedFiles = (0, child_process_1.execSync)('git diff --name-only HEAD', { encoding: 'utf8' }).trim();
23
- process.stderr.write('\n');
24
- process.stderr.write(SEP);
25
- process.stderr.write('❌ ERROR: You have uncommitted changes\n');
26
- process.stderr.write(SEP);
27
- process.stderr.write('\n');
28
- process.stderr.write('Please commit or stash your changes before updating from main.\n');
29
- process.stderr.write('\n');
30
- process.stderr.write('Files with changes:\n');
31
- process.stderr.write(changedFiles + '\n');
32
- process.stderr.write('\n');
33
- process.stderr.write('\x1b[1;31mTo commit your changes, run:\n');
34
- process.stderr.write(' git add -A && git commit -m "your message"\x1b[0m\n');
35
- process.stderr.write('\n');
36
- process.stderr.write('Or to stash them temporarily:\n');
37
- process.stderr.write(' git stash\n');
38
- process.stderr.write(' pnpm wp-git-update\n');
39
- process.stderr.write(' git stash pop\n');
40
- process.stderr.write('\n');
41
- process.stderr.write(SEP);
42
- process.exit(1);
20
+ // Require a fully-committed tree (tracked AND untracked). The old check used `git diff-index`,
21
+ // which is tracked-only, so a stale untracked dir slipped through and was later swept into the
22
+ // squash commit by `git add -A`. assertCleanTree uses `git status --porcelain` (untracked-aware,
23
+ // gitignore-respecting) and aborts with instructions β€” the tooling never commits your work for you.
24
+ (0, git_exec_1.assertCleanTree)(repoRoot);
43
25
  }
44
26
  function printHashPoints(hashes, currentBranch, mergeDir) {
45
27
  process.stderr.write('πŸ“ The 3 Hash Points:\n');
@@ -61,7 +43,7 @@ async function main() {
61
43
  const repoRoot = (0, child_process_1.execSync)('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();
62
44
  const mergeDir = (0, merge_state_1.mergeDirFor)(repoRoot, featureName);
63
45
  fs.mkdirSync(mergeDir, { recursive: true });
64
- validateCleanTree(currentBranch);
46
+ validateCleanTree(currentBranch, repoRoot);
65
47
  process.stderr.write('\n');
66
48
  process.stderr.write(SEP);
67
49
  process.stderr.write('πŸ“ Gathering Merge Context\n');
@@ -1 +1 @@
1
- {"version":3,"file":"git-gatherInfo.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-gatherInfo.ts"],"names":[],"mappings":";;;AAiEA,oBAwCC;;AAxGD,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0EAAiE;AACjE,oEAA6D;AAC7D,wDAAqD;AAErD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAQvE,SAAS,iBAAiB,CAAC,aAAqB;IAC5C,IAAI,aAAa,KAAK,MAAM,EAAE,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iEAAiE,CAAC,CAAC;QACxF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,aAAa,IAAI,CAAC,CAAC;IAE3D,MAAM,aAAa,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IAC7F,IAAI,CAAC,aAAa;QAAE,OAAO;IAE3B,MAAM,YAAY,GAAG,IAAA,wBAAQ,EAAC,2BAA2B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxF,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,yCAAyC,CAAC,CAAC;IAChE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CA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,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,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;AAC/B,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { getFeatureName } from './workflow/git-readAiBranchName';\nimport { findForkPoint } from './workflow/git-findForkPoint';\nimport { mergeDirFor } from './workflow/merge-state';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\ninterface HashPoints {\n hashForkPoint: string;\n hashFeatureHead: string;\n hashMainHead: string;\n}\n\nfunction validateCleanTree(currentBranch: string): void {\n if (currentBranch === 'main') {\n process.stderr.write('❌ Error: Already on main branch. No need to update from main.\\n');\n process.exit(1);\n }\n\n process.stderr.write(`Current branch: ${currentBranch}\\n`);\n\n const hasDirtyFiles = spawnSync('git', ['diff-index', '--quiet', 'HEAD', '--']).status !== 0;\n if (!hasDirtyFiles) return;\n\n const changedFiles = execSync('git diff --name-only HEAD', { encoding: 'utf8' }).trim();\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('❌ ERROR: You have uncommitted changes\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n process.stderr.write('Please commit or stash your changes before updating from main.\\n');\n process.stderr.write('\\n');\n process.stderr.write('Files with changes:\\n');\n process.stderr.write(changedFiles + '\\n');\n process.stderr.write('\\n');\n process.stderr.write('\\x1b[1;31mTo commit your changes, run:\\n');\n process.stderr.write(' git add -A && git commit -m \"your message\"\\x1b[0m\\n');\n process.stderr.write('\\n');\n process.stderr.write('Or to stash them temporarily:\\n');\n process.stderr.write(' git stash\\n');\n process.stderr.write(' pnpm wp-git-update\\n');\n process.stderr.write(' git stash pop\\n');\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.exit(1);\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\nexport async function main(): Promise<void> {\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);\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 process.exit(0);\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}\n\nif (require.main === module) {\n main().catch((err) => {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(message + '\\n');\n process.exit(1);\n });\n}\n"]}
1
+ {"version":3,"file":"git-gatherInfo.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-gatherInfo.ts"],"names":[],"mappings":";;;AA6CA,oBAwCC;;AApFD,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0EAAiE;AACjE,oEAA6D;AAC7D,wDAAqD;AACrD,kDAAsD;AAEtD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAQvE,SAAS,iBAAiB,CAAC,aAAqB,EAAE,QAAgB;IAC9D,IAAI,aAAa,KAAK,MAAM,EAAE,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iEAAiE,CAAC,CAAC;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CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\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\nfunction validateCleanTree(currentBranch: string, repoRoot: string): void {\n if (currentBranch === 'main') {\n process.stderr.write('❌ Error: Already on main branch. No need to update from main.\\n');\n process.exit(1);\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\nexport async function main(): Promise<void> {\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 process.exit(0);\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}\n\nif (require.main === module) {\n main().catch((err) => {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(message + '\\n');\n process.exit(1);\n });\n}\n"]}
@@ -5,6 +5,7 @@ exports.main = main;
5
5
  const tslib_1 = require("tslib");
6
6
  const child_process_1 = require("child_process");
7
7
  const fs = tslib_1.__importStar(require("fs"));
8
+ const rules_config_1 = require("@webpieces/rules-config");
8
9
  const git_readAiBranchName_1 = require("./workflow/git-readAiBranchName");
9
10
  const merge_state_1 = require("./workflow/merge-state");
10
11
  const merge_start_1 = require("./workflow/merge-start");
@@ -31,6 +32,8 @@ async function main() {
31
32
  const featureName = (0, git_readAiBranchName_1.getFeatureName)();
32
33
  const mergeDir = (0, merge_state_1.mergeDirFor)(repoRoot, featureName);
33
34
  fs.mkdirSync(mergeDir, { recursive: true });
35
+ // Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.
36
+ (0, rules_config_1.writeTemplate)(repoRoot, 'webpieces.git-workflow.md');
34
37
  const existing = (0, merge_state_1.readMergeMarker)(mergeDir);
35
38
  if (existing) {
36
39
  await handleResume(repoRoot, mergeDir, existing);
@@ -1 +1 @@
1
- {"version":3,"file":"git-updateFromMain.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-updateFromMain.ts"],"names":[],"mappings":";;;AAgCA,oBAkBC;;AAjDD,iDAAyC;AACzC,+CAAyB;AACzB,0EAAiE;AACjE,wDAAmF;AACnF,wDAAkE;AAClE,oDAAgD;AAEhD,uGAAuG;AACvG,uGAAuG;AACvG,mGAAmG;AACnG,sGAAsG;AACtG,qGAAqG;AACrG,mEAAmE;AAEnE,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,KAAK,UAAU,YAAY,CAAC,QAAgB,EAAE,QAAgB,EAAE,MAAmB;IAC/E,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,6CAA6C,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;QAC9F,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kEAAkE,CAAC,CAAC;QACzF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAClE,MAAM,IAAA,oBAAQ,EACV,QAAQ,EAAE,QAAQ,EAClB,IAAI,0BAAY,CAAC,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AC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport { getFeatureName } from './workflow/git-readAiBranchName';\nimport { mergeDirFor, readMergeMarker, MergeMarker } from './workflow/merge-state';\nimport { mergeStart, MergeContext } from './workflow/merge-start';\nimport { mergeEnd } from './workflow/merge-end';\n\n// wp-git-update: the \"sync this feature branch from main\" entry point (also the redirect target of the\n// redirect-how-to-merge-main guard, and the first step wp-start-upsert-pr shells out to). It is a thin\n// composition of the two lifecycle primitives: merge-START brings main in, merge-END finalizes. It\n// NEVER creates a PR. Three cases: a fresh update (start β†’ finalize on clean, hand back on conflict),\n// resuming an already-validated merge (finalize), or resuming an unvalidated one (tell the AI to run\n// wp-finish-upsert-pr, which validates + finalizes via merge-END).\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\nasync function handleResume(repoRoot: string, mergeDir: string, marker: MergeMarker): Promise<void> {\n if (!marker.validated) {\n process.stdout.write('\\n' + SEP + '⏸️ Merge in progress β€” not yet validated\\n' + SEP + '\\n');\n process.stdout.write('Resolve the remaining conflicts in the working tree, then run:\\n');\n process.stdout.write(' pnpm wp-finish-upsert-pr\\n\\n');\n process.exit(1);\n }\n process.stdout.write('Resuming: merge validated β€” finalizing.\\n');\n await mergeEnd(\n repoRoot, mergeDir,\n new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber),\n null,\n );\n}\n\nexport async function main(): Promise<void> {\n const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();\n const featureName = getFeatureName();\n const mergeDir = mergeDirFor(repoRoot, featureName);\n fs.mkdirSync(mergeDir, { recursive: true });\n\n const existing = readMergeMarker(mergeDir);\n if (existing) {\n await handleResume(repoRoot, mergeDir, existing);\n return;\n }\n\n const result = await mergeStart(repoRoot, mergeDir);\n if (result.status === 'conflict' || result.context === null) {\n // Conflicts: marker + context files written, AI hands resolution off to wp-finish-upsert-pr.\n process.exit(2);\n }\n await mergeEnd(repoRoot, mergeDir, result.context, null);\n}\n\nif (require.main === module) {\n main().catch((err: Error) => {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(message + '\\n');\n process.exit(1);\n });\n}\n"]}
1
+ {"version":3,"file":"git-updateFromMain.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-updateFromMain.ts"],"names":[],"mappings":";;;AAiCA,oBAoBC;;AApDD,iDAAyC;AACzC,+CAAyB;AACzB,0DAAwD;AACxD,0EAAiE;AACjE,wDAAmF;AACnF,wDAAkE;AAClE,oDAAgD;AAEhD,uGAAuG;AACvG,uGAAuG;AACvG,mGAAmG;AACnG,sGAAsG;AACtG,qGAAqG;AACrG,mEAAmE;AAEnE,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,KAAK,UAAU,YAAY,CAAC,QAAgB,EAAE,QAAgB,EAAE,MAAmB;IAC/E,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,6CAA6C,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;QAC9F,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kEAAkE,CAAC,CAAC;QACzF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAClE,MAAM,IAAA,oBAAQ,EACV,QA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KAAK,CAAC,CAAC,GAAU,EAAE,EAAE;QACxB,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport { writeTemplate } from '@webpieces/rules-config';\nimport { getFeatureName } from './workflow/git-readAiBranchName';\nimport { mergeDirFor, readMergeMarker, MergeMarker } from './workflow/merge-state';\nimport { mergeStart, MergeContext } from './workflow/merge-start';\nimport { mergeEnd } from './workflow/merge-end';\n\n// wp-git-update: the \"sync this feature branch from main\" entry point (also the redirect target of the\n// redirect-how-to-merge-main guard, and the first step wp-start-upsert-pr shells out to). It is a thin\n// composition of the two lifecycle primitives: merge-START brings main in, merge-END finalizes. It\n// NEVER creates a PR. Three cases: a fresh update (start β†’ finalize on clean, hand back on conflict),\n// resuming an already-validated merge (finalize), or resuming an unvalidated one (tell the AI to run\n// wp-finish-upsert-pr, which validates + finalizes via merge-END).\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\nasync function handleResume(repoRoot: string, mergeDir: string, marker: MergeMarker): Promise<void> {\n if (!marker.validated) {\n process.stdout.write('\\n' + SEP + '⏸️ Merge in progress β€” not yet validated\\n' + SEP + '\\n');\n process.stdout.write('Resolve the remaining conflicts in the working tree, then run:\\n');\n process.stdout.write(' pnpm wp-finish-upsert-pr\\n\\n');\n process.exit(1);\n }\n process.stdout.write('Resuming: merge validated β€” finalizing.\\n');\n await mergeEnd(\n repoRoot, mergeDir,\n new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber),\n null,\n );\n}\n\nexport async function main(): Promise<void> {\n const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();\n const featureName = getFeatureName();\n const mergeDir = mergeDirFor(repoRoot, featureName);\n fs.mkdirSync(mergeDir, { recursive: true });\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 const existing = readMergeMarker(mergeDir);\n if (existing) {\n await handleResume(repoRoot, mergeDir, existing);\n return;\n }\n\n const result = await mergeStart(repoRoot, mergeDir);\n if (result.status === 'conflict' || result.context === null) {\n // Conflicts: marker + context files written, AI hands resolution off to wp-finish-upsert-pr.\n process.exit(2);\n }\n await mergeEnd(repoRoot, mergeDir, result.context, null);\n}\n\nif (require.main === module) {\n main().catch((err: Error) => {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(message + '\\n');\n process.exit(1);\n });\n}\n"]}
@@ -1,3 +1,19 @@
1
+ export declare function uncommittedFiles(cwd: string): string;
2
+ export declare function untrackedFiles(cwd: string): string;
3
+ /**
4
+ * Precondition for every PR/merge entry point: the working tree must be fully committed. The webpieces
5
+ * tooling deliberately does NOT `git add`/`commit` the developer's work for them β€” a blanket `git add
6
+ * -A` once swept a stale untracked directory into a squash commit, and building the working tree while
7
+ * pushing HEAD let an uncommitted fix pass the build gate yet push a stale commit. Aborts with
8
+ * instructions if anything is uncommitted (tracked or untracked, excluding gitignored).
9
+ */
10
+ export declare function assertCleanTree(cwd: string): void;
11
+ /**
12
+ * Narrower guard for the merge-resolve commit point, where tracked resolutions are legitimately in the
13
+ * tree but untracked files must NOT be swept into the squash commit (replaces the old blanket `git add
14
+ * -A`). Lists any untracked files and aborts so the AI commits or deletes them explicitly.
15
+ */
16
+ export declare function assertNoUntracked(cwd: string): void;
1
17
  /**
2
18
  * Run a git command that is expected to succeed; abort the process with a clear message
3
19
  * if it fails. Used for fetch/pull/checkout/commit where silently continuing on failure
@@ -1,8 +1,76 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uncommittedFiles = uncommittedFiles;
4
+ exports.untrackedFiles = untrackedFiles;
5
+ exports.assertCleanTree = assertCleanTree;
6
+ exports.assertNoUntracked = assertNoUntracked;
3
7
  exports.runGitChecked = runGitChecked;
4
8
  exports.ensurePushed = ensurePushed;
5
9
  const child_process_1 = require("child_process");
10
+ const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
11
+ // The AI-facing doc the failure messages point at (generated under .webpieces/instruct-ai, gitignored).
12
+ const GIT_WORKFLOW_DOC = '.webpieces/instruct-ai/webpieces.git-workflow.md';
13
+ // Run a read-only git query from the repo root; abort if git itself errors. Kept `cwd`-explicit (not
14
+ // process.cwd()) because `git ls-files --others` is scoped to the cwd subtree β€” running from a subdir
15
+ // would miss untracked files elsewhere in the repo.
16
+ function gitQuery(args, cwd, failMsg) {
17
+ const out = (0, child_process_1.spawnSync)('git', args, { encoding: 'utf8', cwd });
18
+ if (out.status !== 0) {
19
+ process.stderr.write(`❌ ${failMsg}\n`);
20
+ process.exit(1);
21
+ }
22
+ return out.stdout.trim();
23
+ }
24
+ // Tracked changes (staged + unstaged) AND untracked files, EXCLUDING gitignored paths β€” so `.webpieces/`
25
+ // tooling artifacts never count. Empty string = fully committed. Exported for unit testing.
26
+ function uncommittedFiles(cwd) {
27
+ return gitQuery(['status', '--porcelain'], cwd, 'Failed to run `git status --porcelain` to check the working tree.');
28
+ }
29
+ // Untracked files only (respects .gitignore). Empty string = none. Exported for unit testing.
30
+ function untrackedFiles(cwd) {
31
+ return gitQuery(['ls-files', '--others', '--exclude-standard'], cwd, 'Failed to list untracked files (git ls-files --others).');
32
+ }
33
+ /**
34
+ * Precondition for every PR/merge entry point: the working tree must be fully committed. The webpieces
35
+ * tooling deliberately does NOT `git add`/`commit` the developer's work for them β€” a blanket `git add
36
+ * -A` once swept a stale untracked directory into a squash commit, and building the working tree while
37
+ * pushing HEAD let an uncommitted fix pass the build gate yet push a stale commit. Aborts with
38
+ * instructions if anything is uncommitted (tracked or untracked, excluding gitignored).
39
+ */
40
+ function assertCleanTree(cwd) {
41
+ const dirty = uncommittedFiles(cwd);
42
+ if (dirty === '')
43
+ return;
44
+ process.stderr.write('\n' + SEP);
45
+ process.stderr.write('❌ ERROR: You have uncommitted or untracked changes\n');
46
+ process.stderr.write(SEP + '\n');
47
+ process.stderr.write('The webpieces PR tooling will NOT commit your work for you. Commit your\n');
48
+ process.stderr.write('changes, and either commit or delete any untracked files, then re-run.\n\n');
49
+ process.stderr.write('Working tree (git status --porcelain):\n');
50
+ process.stderr.write(dirty + '\n\n');
51
+ process.stderr.write(`See ${GIT_WORKFLOW_DOC} for the full merge + PR process.\n`);
52
+ process.stderr.write(SEP);
53
+ process.exit(1);
54
+ }
55
+ /**
56
+ * Narrower guard for the merge-resolve commit point, where tracked resolutions are legitimately in the
57
+ * tree but untracked files must NOT be swept into the squash commit (replaces the old blanket `git add
58
+ * -A`). Lists any untracked files and aborts so the AI commits or deletes them explicitly.
59
+ */
60
+ function assertNoUntracked(cwd) {
61
+ const untracked = untrackedFiles(cwd);
62
+ if (untracked === '')
63
+ return;
64
+ process.stderr.write('\n' + SEP);
65
+ process.stderr.write('❌ ERROR: Untracked files present during merge finalize\n');
66
+ process.stderr.write(SEP + '\n');
67
+ process.stderr.write('The tooling will not sweep untracked files into the squash commit. Commit\n');
68
+ process.stderr.write('or delete these, then re-run:\n\n');
69
+ process.stderr.write(untracked + '\n\n');
70
+ process.stderr.write(`See ${GIT_WORKFLOW_DOC} for the full merge + PR process.\n`);
71
+ process.stderr.write(SEP);
72
+ process.exit(1);
73
+ }
6
74
  /**
7
75
  * Run a git command that is expected to succeed; abort the process with a clear message
8
76
  * if it fails. Used for fetch/pull/checkout/commit where silently continuing on failure
@@ -1 +1 @@
1
- {"version":3,"file":"git-exec.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-exec.ts"],"names":[],"mappings":";;AAOA,sCAMC;AAOD,oCAOC;AA3BD,iDAA0C;AAE1C;;;;GAIG;AACH,SAAgB,aAAa,CAAC,IAAc,EAAE,MAAc;IACxD,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAC5D,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,MAAM,SAAS,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,aAAqB;IAC9C,MAAM,YAAY,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACrH,IAAI,YAAY,EAAE,CAAC;QACf,aAAa,CAAC,CAAC,MAAM,EAAE,oBAAoB,EAAE,QAAQ,EAAE,QAAQ,aAAa,EAAE,CAAC,EAAE,uBAAuB,CAAC,CAAC;IAC9G,CAAC;SAAM,CAAC;QACJ,aAAa,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,aAAa,EAAE,CAAC,EAAE,2BAA2B,CAAC,CAAC;IAClG,CAAC;AACL,CAAC","sourcesContent":["import { spawnSync } from 'child_process';\n\n/**\n * Run a git command that is expected to succeed; abort the process with a clear message\n * if it fails. Used for fetch/pull/checkout/commit where silently continuing on failure\n * would operate on stale or wrong state.\n */\nexport function runGitChecked(args: string[], errMsg: string): void {\n const result = spawnSync('git', args, { stdio: 'inherit' });\n if (result.status !== 0) {\n process.stderr.write(`❌ ${errMsg} (git ${args.join(' ')} exited ${String(result.status)})\\n`);\n process.exit(1);\n }\n}\n\n/**\n * Push HEAD to origin/<currentBranch>. Single source of truth shared by wp-start-upsert-pr and\n * wp-finish-upsert-pr (they pushed with identical copy-pasted logic). Uses --force-with-lease for an\n * existing remote branch (the 3-point squash rewrites history) and -u for a brand-new branch.\n */\nexport function ensurePushed(currentBranch: string): void {\n const remoteExists = spawnSync('git', ['ls-remote', '--exit-code', '--heads', 'origin', currentBranch]).status === 0;\n if (remoteExists) {\n runGitChecked(['push', '--force-with-lease', 'origin', `HEAD:${currentBranch}`], 'Failed to push branch');\n } else {\n runGitChecked(['push', '-u', 'origin', `HEAD:${currentBranch}`], 'Failed to push new branch');\n }\n}\n"]}
1
+ {"version":3,"file":"git-exec.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-exec.ts"],"names":[],"mappings":";;AAqBA,4CAEC;AAGD,wCAEC;AASD,0CAaC;AAOD,8CAYC;AAOD,sCAMC;AAOD,oCAOC;AAhGD,iDAA0C;AAE1C,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,wGAAwG;AACxG,MAAM,gBAAgB,GAAG,kDAAkD,CAAC;AAE5E,qGAAqG;AACrG,sGAAsG;AACtG,oDAAoD;AACpD,SAAS,QAAQ,CAAC,IAAc,EAAE,GAAW,EAAE,OAAe;IAC1D,MAAM,GAAG,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IAC9D,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC;QACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,GAAG,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G,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACrH,IAAI,YAAY,EAAE,CAAC;QACf,aAAa,CAAC,CAAC,MAAM,EAAE,oBAAoB,EAAE,QAAQ,EAAE,QAAQ,aAAa,EAAE,CAAC,EAAE,uBAAuB,CAAC,CAAC;IAC9G,CAAC;SAAM,CAAC;QACJ,aAAa,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,aAAa,EAAE,CAAC,EAAE,2BAA2B,CAAC,CAAC;IAClG,CAAC;AACL,CAAC","sourcesContent":["import { spawnSync } from 'child_process';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// The AI-facing doc the failure messages point at (generated under .webpieces/instruct-ai, gitignored).\nconst GIT_WORKFLOW_DOC = '.webpieces/instruct-ai/webpieces.git-workflow.md';\n\n// Run a read-only git query from the repo root; abort if git itself errors. Kept `cwd`-explicit (not\n// process.cwd()) because `git ls-files --others` is scoped to the cwd subtree β€” running from a subdir\n// would miss untracked files elsewhere in the repo.\nfunction gitQuery(args: string[], cwd: string, failMsg: string): string {\n const out = spawnSync('git', args, { encoding: 'utf8', cwd });\n if (out.status !== 0) {\n process.stderr.write(`❌ ${failMsg}\\n`);\n process.exit(1);\n }\n return out.stdout.trim();\n}\n\n// Tracked changes (staged + unstaged) AND untracked files, EXCLUDING gitignored paths β€” so `.webpieces/`\n// tooling artifacts never count. Empty string = fully committed. Exported for unit testing.\nexport function uncommittedFiles(cwd: string): string {\n return gitQuery(['status', '--porcelain'], cwd, 'Failed to run `git status --porcelain` to check the working tree.');\n}\n\n// Untracked files only (respects .gitignore). Empty string = none. Exported for unit testing.\nexport function untrackedFiles(cwd: string): string {\n return gitQuery(['ls-files', '--others', '--exclude-standard'], cwd, 'Failed to list untracked files (git ls-files --others).');\n}\n\n/**\n * Precondition for every PR/merge entry point: the working tree must be fully committed. The webpieces\n * tooling deliberately does NOT `git add`/`commit` the developer's work for them β€” a blanket `git add\n * -A` once swept a stale untracked directory into a squash commit, and building the working tree while\n * pushing HEAD let an uncommitted fix pass the build gate yet push a stale commit. Aborts with\n * instructions if anything is uncommitted (tracked or untracked, excluding gitignored).\n */\nexport function assertCleanTree(cwd: string): void {\n const dirty = uncommittedFiles(cwd);\n if (dirty === '') return;\n process.stderr.write('\\n' + SEP);\n process.stderr.write('❌ ERROR: You have uncommitted or untracked changes\\n');\n process.stderr.write(SEP + '\\n');\n process.stderr.write('The webpieces PR tooling will NOT commit your work for you. Commit your\\n');\n process.stderr.write('changes, and either commit or delete any untracked files, then re-run.\\n\\n');\n process.stderr.write('Working tree (git status --porcelain):\\n');\n process.stderr.write(dirty + '\\n\\n');\n process.stderr.write(`See ${GIT_WORKFLOW_DOC} for the full merge + PR process.\\n`);\n process.stderr.write(SEP);\n process.exit(1);\n}\n\n/**\n * Narrower guard for the merge-resolve commit point, where tracked resolutions are legitimately in the\n * tree but untracked files must NOT be swept into the squash commit (replaces the old blanket `git add\n * -A`). Lists any untracked files and aborts so the AI commits or deletes them explicitly.\n */\nexport function assertNoUntracked(cwd: string): void {\n const untracked = untrackedFiles(cwd);\n if (untracked === '') return;\n process.stderr.write('\\n' + SEP);\n process.stderr.write('❌ ERROR: Untracked files present during merge finalize\\n');\n process.stderr.write(SEP + '\\n');\n process.stderr.write('The tooling will not sweep untracked files into the squash commit. Commit\\n');\n process.stderr.write('or delete these, then re-run:\\n\\n');\n process.stderr.write(untracked + '\\n\\n');\n process.stderr.write(`See ${GIT_WORKFLOW_DOC} for the full merge + PR process.\\n`);\n process.stderr.write(SEP);\n process.exit(1);\n}\n\n/**\n * Run a git command that is expected to succeed; abort the process with a clear message\n * if it fails. Used for fetch/pull/checkout/commit where silently continuing on failure\n * would operate on stale or wrong state.\n */\nexport function runGitChecked(args: string[], errMsg: string): void {\n const result = spawnSync('git', args, { stdio: 'inherit' });\n if (result.status !== 0) {\n process.stderr.write(`❌ ${errMsg} (git ${args.join(' ')} exited ${String(result.status)})\\n`);\n process.exit(1);\n }\n}\n\n/**\n * Push HEAD to origin/<currentBranch>. Single source of truth shared by wp-start-upsert-pr and\n * wp-finish-upsert-pr (they pushed with identical copy-pasted logic). Uses --force-with-lease for an\n * existing remote branch (the 3-point squash rewrites history) and -u for a brand-new branch.\n */\nexport function ensurePushed(currentBranch: string): void {\n const remoteExists = spawnSync('git', ['ls-remote', '--exit-code', '--heads', 'origin', currentBranch]).status === 0;\n if (remoteExists) {\n runGitChecked(['push', '--force-with-lease', 'origin', `HEAD:${currentBranch}`], 'Failed to push branch');\n } else {\n runGitChecked(['push', '-u', 'origin', `HEAD:${currentBranch}`], 'Failed to push new branch');\n }\n}\n"]}
@@ -87,7 +87,11 @@ async function mergeEnd(repoRoot, mergeDir, ctx, conflictedFiles) {
87
87
  if (conflictedFiles !== null) {
88
88
  process.stdout.write('\n' + SEP + 'πŸ”Ž Validating Merge Resolution\n' + SEP + '\n');
89
89
  validateResolution(repoRoot, mergeDir, conflictedFiles);
90
- (0, git_exec_1.runGitChecked)(['add', '-A'], 'Failed to stage resolved files');
90
+ // Stage the AI's resolved conflicts, but NEVER sweep untracked files into the squash commit
91
+ // (a blanket `git add -A` once swept a stale untracked dir in). Fail on untracked so the AI
92
+ // commits or deletes them explicitly; then `git add -u` stages tracked resolutions only.
93
+ (0, git_exec_1.assertNoUntracked)(repoRoot);
94
+ (0, git_exec_1.runGitChecked)(['add', '-u'], 'Failed to stage resolved files');
91
95
  const nothingStaged = (0, child_process_1.spawnSync)('git', ['diff-index', '--quiet', '--cached', 'HEAD', '--']).status === 0;
92
96
  if (!nothingStaged) {
93
97
  (0, git_exec_1.runGitChecked)(['commit', '-m', `Squash merge of ${ctx.currentBranch} (conflicts resolved)`], 'Failed to commit resolved merge');
@@ -1 +1 @@
1
- {"version":3,"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;;;GAIG;AACI,KAAK,UAAU,QAAQ,CAC1B,QAAgB,EAAE,QAAgB,EAAE,GAAiB,EAAE,eAAgC;IAEvF,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,kCAAkC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;QACnF,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;QACxD,IAAA,wBAAa,EAAC,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,gCAAgC,CAAC,CAAC;QAE/D,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;QACzG,IAAI,CAAC,aAAa,EAAE,CAAC;YACjB,IAAA,wBAAa,EACT,CAAC,QAAQ,EAAE,IAAI,EAAE,mBAAmB,GAAG,CAAC,aAAa,uBAAuB,CAAC,EAC7E,iCAAiC,CACpC,CAAC;QACN,CAAC;QACD,EAAE,CAAC,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,cAAc,CAAC,GAAG,CAAC,CAAC;IACpB,IAAA,8BAAgB,EAAC,QAAQ,CAAC,CAAC;IAC3B,MAAM,IAAA,eAAQ,GAAE,CAAC;AACrB,CAAC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { MERGE_EXPLANATION_FILE, stampCleanMainSyncStatus } from '@webpieces/rules-config';\nimport { baseBranchName, nextBranchName } from './branch-naming';\nimport { main as cleanTmp } from './cleanTmp';\nimport { runGitChecked } from './git-exec';\nimport { MergeContext } from './merge-start';\nimport { clearMergeMarker, 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 β€” promotes `<branch>Squash` to the next numbered generation (base β†’ base2),\n// force-pushes to the stable base branch, stamps a clean main-sync status, clears the marker and\n// sweeps stale tmp. Both wp-git-update (clean path /\n// validated resume) and wp-finish-upsert-pr (conflict resolution) call THIS, so finalization happens\n// in exactly one 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). Exits the\n// process 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 process.stderr.write('❌ Unresolved conflict markers (<<<<<<< / ======= / >>>>>>>) remain in:\\n');\n for (const file of scan.filesWithMarkers) process.stderr.write(` - ${file}\\n`);\n process.stderr.write('\\nResolve them, then re-run: pnpm wp-finish-upsert-pr\\n');\n process.exit(1);\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 process.stderr.write('❌ Git still reports unmerged files:\\n' + unmerged + '\\n');\n process.stderr.write('\\nResolve and `git add` them, then re-run: pnpm wp-finish-upsert-pr\\n');\n process.exit(1);\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 process.stderr.write(`❌ Missing/empty merge explanation (${MERGE_EXPLANATION_FILE}) for:\\n`);\n for (const file of explanations.filesWithMarkers) {\n process.stderr.write(` - ${file}\\n β†’ ${path.join(perFileContextDir(mergeDir, file), MERGE_EXPLANATION_FILE)}\\n`);\n }\n process.stderr.write(\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.exit(1);\n }\n process.stdout.write('βœ… Merge explanations present for all resolved files.\\n');\n}\n\n// Promote the squash branch to the NEXT numbered generation, force-push to the stable base\n// branch (where the single PR lives), and stamp clean main-sync. The local branch numbers up\n// (base β†’ base2 β†’ base3) so the generation is visible; the remote/PR name stays `base`.\nfunction finalizeBranch(ctx: MergeContext): void {\n process.stdout.write('\\n' + SEP + 'πŸ—‘οΈ Finalizing\\n' + SEP + '\\n');\n const base = baseBranchName(ctx.currentBranch);\n const next = nextBranchName(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 runGitChecked(['branch', '-m', next], 'Failed to rename squash branch');\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 process.stdout.write(`\\nβœ… Now on ${next} (remote/PR: ${base}), updated from main. Backup: ${ctx.backupBranch}\\n`);\n process.stdout.write(` Delete backup when safe: git branch -D ${ctx.backupBranch}\\n\\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, 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 runGitChecked(['add', '-A'], '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 finalizeBranch(ctx);\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":";;AA4FA,4BA0BC;;AAtHD,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAA2F;AAC3F,mDAAiE;AACjE,yCAA8C;AAC9C,yCAA8D;AAE9D,+CAAgH;AAEhH,sGAAsG;AACtG,oGAAoG;AACpG,kGAAkG;AAClG,iGAAiG;AACjG,qDAAqD;AACrD,qGAAqG;AACrG,wGAAwG;AAExG,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,6F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C,QAAQ,CAAC,CAAC;QAC5B,IAAA,wBAAa,EAAC,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,gCAAgC,CAAC,CAAC;QAE/D,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;QACzG,IAAI,CAAC,aAAa,EAAE,CAAC;YACjB,IAAA,wBAAa,EACT,CAAC,QAAQ,EAAE,IAAI,EAAE,mBAAmB,GAAG,CAAC,aAAa,uBAAuB,CAAC,EAC7E,iCAAiC,CACpC,CAAC;QACN,CAAC;QACD,EAAE,CAAC,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,cAAc,CAAC,GAAG,CAAC,CAAC;IACpB,IAAA,8BAAgB,EAAC,QAAQ,CAAC,CAAC;IAC3B,MAAM,IAAA,eAAQ,GAAE,CAAC;AACrB,CAAC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { MERGE_EXPLANATION_FILE, stampCleanMainSyncStatus } from '@webpieces/rules-config';\nimport { baseBranchName, nextBranchName } from './branch-naming';\nimport { main as cleanTmp } from './cleanTmp';\nimport { assertNoUntracked, runGitChecked } from './git-exec';\nimport { MergeContext } from './merge-start';\nimport { clearMergeMarker, 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 β€” promotes `<branch>Squash` to the next numbered generation (base β†’ base2),\n// force-pushes to the stable base branch, stamps a clean main-sync status, clears the marker and\n// sweeps stale tmp. Both wp-git-update (clean path /\n// validated resume) and wp-finish-upsert-pr (conflict resolution) call THIS, so finalization happens\n// in exactly one 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). Exits the\n// process 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 process.stderr.write('❌ Unresolved conflict markers (<<<<<<< / ======= / >>>>>>>) remain in:\\n');\n for (const file of scan.filesWithMarkers) process.stderr.write(` - ${file}\\n`);\n process.stderr.write('\\nResolve them, then re-run: pnpm wp-finish-upsert-pr\\n');\n process.exit(1);\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 process.stderr.write('❌ Git still reports unmerged files:\\n' + unmerged + '\\n');\n process.stderr.write('\\nResolve and `git add` them, then re-run: pnpm wp-finish-upsert-pr\\n');\n process.exit(1);\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 process.stderr.write(`❌ Missing/empty merge explanation (${MERGE_EXPLANATION_FILE}) for:\\n`);\n for (const file of explanations.filesWithMarkers) {\n process.stderr.write(` - ${file}\\n β†’ ${path.join(perFileContextDir(mergeDir, file), MERGE_EXPLANATION_FILE)}\\n`);\n }\n process.stderr.write(\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.exit(1);\n }\n process.stdout.write('βœ… Merge explanations present for all resolved files.\\n');\n}\n\n// Promote the squash branch to the NEXT numbered generation, force-push to the stable base\n// branch (where the single PR lives), and stamp clean main-sync. The local branch numbers up\n// (base β†’ base2 β†’ base3) so the generation is visible; the remote/PR name stays `base`.\nfunction finalizeBranch(ctx: MergeContext): void {\n process.stdout.write('\\n' + SEP + 'πŸ—‘οΈ Finalizing\\n' + SEP + '\\n');\n const base = baseBranchName(ctx.currentBranch);\n const next = nextBranchName(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 runGitChecked(['branch', '-m', next], 'Failed to rename squash branch');\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 process.stdout.write(`\\nβœ… Now on ${next} (remote/PR: ${base}), updated from main. Backup: ${ctx.backupBranch}\\n`);\n process.stdout.write(` Delete backup when safe: git branch -D ${ctx.backupBranch}\\n\\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, 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 finalizeBranch(ctx);\n clearMergeMarker(mergeDir);\n await cleanTmp();\n}\n"]}
@@ -29,6 +29,12 @@ function runUpdateFromMain() {
29
29
  }
30
30
  function main() {
31
31
  const repoRoot = (0, child_process_1.execSync)('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();
32
+ // Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.
33
+ (0, rules_config_1.writeTemplate)(repoRoot, 'webpieces.git-workflow.md');
34
+ // Precondition: a fully-committed tree. This flow updates, pushes HEAD, and builds β€” the tooling
35
+ // must not commit your work for you, and pushing HEAD while building the working tree would let an
36
+ // uncommitted change build green yet push a stale commit. Fail early with instructions if dirty.
37
+ (0, git_exec_1.assertCleanTree)(repoRoot);
32
38
  runUpdateFromMain();
33
39
  // Local branch may be a numbered generation (base2/…); the remote/PR branch is the stable base.
34
40
  (0, git_exec_1.ensurePushed)((0, branch_naming_1.baseBranchName)((0, child_process_1.execSync)('git branch --show-current', { encoding: 'utf8' }).trim()));
@@ -1 +1 @@
1
- {"version":3,"file":"wp-start-upsert-pr.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/wp-start-upsert-pr.ts"],"names":[],"mappings":";;;AA8BA,oBAsBC;AAnDD,iDAAoD;AACpD,0DAA+E;AAC/E,0EAAiE;AACjE,4DAA0D;AAC1D,8DAA2E;AAC3E,kDAAmD;AAEnD,mGAAmG;AACnG,gGAAgG;AAChG,mGAAmG;AACnG,4FAA4F;AAE5F,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,+FAA+F;AAC/F,qFAAqF;AACrF,SAAS,iBAAiB;IACtB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,+BAA+B,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;IAChF,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,MAAM,EAAE,CAAC,eAAe,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAC1E,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mHAAmH,CAAC,CAAC;QAC1I,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACvE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;IACrC,CAAC;AACL,CAAC;AAED,SAAgB,IAAI;IAChB,MAAM,QAAQ,GAAG,IAAA,wBAAQ,EAAC,+BAA+B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAExF,iBAAiB,EAAE,CAAC;IACpB,gGAAgG;IAChG,IAAA,uBAAY,EAAC,IAAA,8BAAc,EAAC,IAAA,wBAAQ,EAAC,2BAA2B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAEjG,kGAAkG;IAClG,kGAAkG;IAClG,IAAA,6BAAY,EAAC,QAAQ,EAAE,IAAI,iCAAgB,CACvC,4BAA4B,EAAE,yBAAyB,EAAE,yCAAyC,CACrG,CAAC,CAAC;IAEH,sFAAsF;IACtF,MAAM,UAAU,GAAG,IAAA,6BAAc,EAAC,QAAQ,EAAE,IAAA,qCAAc,GAAE,CAAC,CAAC;IAC9D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,gCAAgC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;IACjF,OAAO,CAAC,MAAM,CAAC,KAAK,CAChB,yFAAyF;QACzF,GAAG,IAAA,mCAAoB,EAAC,UAAU,CAAC,MAAM;QACzC,uCAAuC;QACvC,+GAA+G,CAClH,CAAC;AACN,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,CAAC;AACX,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { execSync, spawnSync } from 'child_process';\nimport { reviewJsonPath, reviewJsonSchemaHint } from '@webpieces/rules-config';\nimport { getFeatureName } from './workflow/git-readAiBranchName';\nimport { baseBranchName } from './workflow/branch-naming';\nimport { runBuildGate, BuildGateOptions } from './workflow/build-affected';\nimport { ensurePushed } from './workflow/git-exec';\n\n// START of the AI-first PR flow (webpieces is AI-driven, so we invert trytami's human-first flow):\n// this command does the deterministic setup β€” update from main, push, run the build gate β€” then\n// hands the AI instructions to WRITE review.json and run `wp-finish-upsert-pr` (which reads it and\n// posts the PR). This command NEVER creates/updates a PR; all `gh` posting lives in finish.\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// Step A β€” bring the branch up to date with main via the 3-point engine (child process, so its\n// conflict handback / guard interplay is unaffected by this command's hook context).\nfunction runUpdateFromMain(): void {\n process.stdout.write('\\n' + SEP + 'β‘  Updating branch from main\\n' + SEP + '\\n');\n const result = spawnSync('pnpm', ['wp-git-update'], { stdio: 'inherit' });\n if (result.status === 2) {\n process.stdout.write('\\n⏸️ Conflicts β€” resolve them, then run pnpm wp-finish-upsert-pr (it validates the merge AND finishes the PR).\\n');\n process.exit(2);\n }\n if (result.status !== 0) {\n process.stderr.write('\\n❌ Branch update failed β€” see output above.\\n');\n process.exit(result.status ?? 1);\n }\n}\n\nexport function main(): void {\n const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();\n\n runUpdateFromMain();\n // Local branch may be a numbered generation (base2/…); the remote/PR branch is the stable base.\n ensurePushed(baseBranchName(execSync('git branch --show-current', { encoding: 'utf8' }).trim()));\n\n // Advisory build gate β€” early feedback before the AI writes review.json. wp-finish-upsert-pr runs\n // the authoritative one. Both go through the same shared runBuildGate (only the framing differs).\n runBuildGate(repoRoot, new BuildGateOptions(\n 'β‘‘ Build gate (nx affected)', 'pnpm wp-start-upsert-pr', 'Build failed β€” fix it before reviewing.',\n ));\n\n // Hand the AI its next step: write review.json, then run finish (which posts the PR).\n const reviewPath = reviewJsonPath(repoRoot, getFeatureName());\n process.stdout.write('\\n' + SEP + 'β‘’ Review the PR, then finish\\n' + SEP + '\\n');\n process.stdout.write(\n `Branch is updated, pushed, and the build gate passed. Now review your own changes and\\n` +\n `${reviewJsonSchemaHint(reviewPath)}\\n\\n` +\n `Then run: pnpm wp-finish-upsert-pr\\n` +\n `(It re-validates the build, renders the dashboard with your risk/violations, and creates/updates the PR.)\\n\\n`,\n );\n}\n\nif (require.main === module) {\n main();\n}\n"]}
1
+ {"version":3,"file":"wp-start-upsert-pr.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/wp-start-upsert-pr.ts"],"names":[],"m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ChG,IAAA,uBAAY,EAAC,IAAA,8BAAc,EAAC,IAAA,wBAAQ,EAAC,2BAA2B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAEjG,kGAAkG;IAClG,kGAAkG;IAClG,IAAA,6BAAY,EAAC,QAAQ,EAAE,IAAI,iCAAgB,CACvC,4BAA4B,EAAE,yBAAyB,EAAE,yCAAyC,CACrG,CAAC,CAAC;IAEH,sFAAsF;IACtF,MAAM,UAAU,GAAG,IAAA,6BAAc,EAAC,QAAQ,EAAE,IAAA,qCAAc,GAAE,CAAC,CAAC;IAC9D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,gCAAgC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;IACjF,OAAO,CAAC,MAAM,CAAC,KAAK,CAChB,yFAAyF;QACzF,GAAG,IAAA,mCAAoB,EAAC,UAAU,CAAC,MAAM;QACzC,uCAAuC;QACvC,+GAA+G,CAClH,CAAC;AACN,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,CAAC;AACX,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { execSync, spawnSync } from 'child_process';\nimport { reviewJsonPath, reviewJsonSchemaHint, writeTemplate } from '@webpieces/rules-config';\nimport { getFeatureName } from './workflow/git-readAiBranchName';\nimport { baseBranchName } from './workflow/branch-naming';\nimport { runBuildGate, BuildGateOptions } from './workflow/build-affected';\nimport { assertCleanTree, ensurePushed } from './workflow/git-exec';\n\n// START of the AI-first PR flow (webpieces is AI-driven, so we invert trytami's human-first flow):\n// this command does the deterministic setup β€” update from main, push, run the build gate β€” then\n// hands the AI instructions to WRITE review.json and run `wp-finish-upsert-pr` (which reads it and\n// posts the PR). This command NEVER creates/updates a PR; all `gh` posting lives in finish.\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// Step A β€” bring the branch up to date with main via the 3-point engine (child process, so its\n// conflict handback / guard interplay is unaffected by this command's hook context).\nfunction runUpdateFromMain(): void {\n process.stdout.write('\\n' + SEP + 'β‘  Updating branch from main\\n' + SEP + '\\n');\n const result = spawnSync('pnpm', ['wp-git-update'], { stdio: 'inherit' });\n if (result.status === 2) {\n process.stdout.write('\\n⏸️ Conflicts β€” resolve them, then run pnpm wp-finish-upsert-pr (it validates the merge AND finishes the PR).\\n');\n process.exit(2);\n }\n if (result.status !== 0) {\n process.stderr.write('\\n❌ Branch update failed β€” see output above.\\n');\n process.exit(result.status ?? 1);\n }\n}\n\nexport function main(): 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 // Precondition: a fully-committed tree. This flow updates, pushes HEAD, and builds β€” the tooling\n // must not commit your work for you, and pushing HEAD while building the working tree would let an\n // uncommitted change build green yet push a stale commit. Fail early with instructions if dirty.\n assertCleanTree(repoRoot);\n\n runUpdateFromMain();\n // Local branch may be a numbered generation (base2/…); the remote/PR branch is the stable base.\n ensurePushed(baseBranchName(execSync('git branch --show-current', { encoding: 'utf8' }).trim()));\n\n // Advisory build gate β€” early feedback before the AI writes review.json. wp-finish-upsert-pr runs\n // the authoritative one. Both go through the same shared runBuildGate (only the framing differs).\n runBuildGate(repoRoot, new BuildGateOptions(\n 'β‘‘ Build gate (nx affected)', 'pnpm wp-start-upsert-pr', 'Build failed β€” fix it before reviewing.',\n ));\n\n // Hand the AI its next step: write review.json, then run finish (which posts the PR).\n const reviewPath = reviewJsonPath(repoRoot, getFeatureName());\n process.stdout.write('\\n' + SEP + 'β‘’ Review the PR, then finish\\n' + SEP + '\\n');\n process.stdout.write(\n `Branch is updated, pushed, and the build gate passed. Now review your own changes and\\n` +\n `${reviewJsonSchemaHint(reviewPath)}\\n\\n` +\n `Then run: pnpm wp-finish-upsert-pr\\n` +\n `(It re-validates the build, renders the dashboard with your risk/violations, and creates/updates the PR.)\\n\\n`,\n );\n}\n\nif (require.main === module) {\n main();\n}\n"]}