@webpieces/pr-gate 0.4.982 → 0.4.984

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 (37) hide show
  1. package/package.json +7 -6
  2. package/src/scripts/commands/build-dev-command.d.ts +27 -0
  3. package/src/scripts/commands/build-dev-command.js +99 -0
  4. package/src/scripts/commands/build-dev-command.js.map +1 -0
  5. package/src/scripts/commands/push-dev-command.d.ts +49 -19
  6. package/src/scripts/commands/push-dev-command.js +95 -32
  7. package/src/scripts/commands/push-dev-command.js.map +1 -1
  8. package/src/scripts/pr-gate-app.d.ts +10 -2
  9. package/src/scripts/pr-gate-app.js +15 -2
  10. package/src/scripts/pr-gate-app.js.map +1 -1
  11. package/src/scripts/pr-gate-cli-app.d.ts +1 -0
  12. package/src/scripts/pr-gate-cli-app.js +9 -2
  13. package/src/scripts/pr-gate-cli-app.js.map +1 -1
  14. package/src/scripts/workflow/build-affected.d.ts +7 -0
  15. package/src/scripts/workflow/build-affected.js +12 -4
  16. package/src/scripts/workflow/build-affected.js.map +1 -1
  17. package/src/scripts/workflow/build-gate-log.d.ts +4 -2
  18. package/src/scripts/workflow/build-gate-log.js +11 -3
  19. package/src/scripts/workflow/build-gate-log.js.map +1 -1
  20. package/src/scripts/workflow/dev-build.d.ts +31 -0
  21. package/src/scripts/workflow/dev-build.js +63 -0
  22. package/src/scripts/workflow/dev-build.js.map +1 -0
  23. package/src/scripts/workflow/dev-copy-on-main.d.ts +49 -0
  24. package/src/scripts/workflow/dev-copy-on-main.js +99 -0
  25. package/src/scripts/workflow/dev-copy-on-main.js.map +1 -0
  26. package/src/scripts/workflow/dev-deploy-refs.d.ts +13 -2
  27. package/src/scripts/workflow/dev-deploy-refs.js +17 -5
  28. package/src/scripts/workflow/dev-deploy-refs.js.map +1 -1
  29. package/src/scripts/workflow/dev-resolve-runner.d.ts +55 -8
  30. package/src/scripts/workflow/dev-resolve-runner.js +150 -22
  31. package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
  32. package/src/scripts/workflow/push-dev-state.d.ts +27 -0
  33. package/src/scripts/workflow/push-dev-state.js +41 -3
  34. package/src/scripts/workflow/push-dev-state.js.map +1 -1
  35. package/src/scripts/wp-build-dev.d.ts +2 -0
  36. package/src/scripts/wp-build-dev.js +13 -0
  37. package/src/scripts/wp-build-dev.js.map +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"build-affected.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-affected.ts"],"names":[],"mappings":";;;;AAAA,0DAAkJ;AAClJ,sEAA+D;AAC/D,yCAA2D;AAC3D,qDAAgD;AAChD,yDAAoD;AAEpD,iGAAiG;AACjG,8FAA8F;AAC9F,iGAAiG;AACjG,oFAAoF;AACpF,oGAAoG;AACpG,iEAAiE;AAEjE;;;;GAIG;AACH,MAAa,gBAAgB;IACzB,KAAK,CAAS,CAAC,sCAAsC;IACrD,YAAY,CAAS,CAAC,gDAAgD;IACtE,eAAe,CAAS,CAAC,gCAAgC;IACzD,qGAAqG;IACrG,uGAAuG;IACvG,KAAK,CAAS;IAEd,YAAY,KAAa,EAAE,YAAoB,EAAE,eAAuB,EAAE,KAAa;QACnF,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAdD,4CAcC;AAED,qGAAqG;AAE9F,IAAM,aAAa,GAAnB,MAAM,aAAa;IAED;IACA;IACA;IACA;IAJrB,YACqB,QAAsB,EACtB,SAAoB,EACpB,YAA4B,EAC5B,cAA8B;QAH9B,aAAQ,GAAR,QAAQ,CAAc;QACtB,cAAS,GAAT,SAAS,CAAW;QACpB,iBAAY,GAAZ,YAAY,CAAgB;QAC5B,mBAAc,GAAd,cAAc,CAAgB;IAChD,CAAC;IAEJ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YAAY,EAAE,OAAO,EAAE,WAAW,CAAC;YAChE,wCAAwC,IAAI,CAAC,YAAY,KAAK,CACjE,CAAC;IACN,CAAC;CACJ,CAAA;AAvGY,sCAAa;wBAAb,aAAa;IADzB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGN,6BAAY;QACX,wBAAS;QACN,iCAAc;QACZ,mCAAc;GAL1C,aAAa,CAuGzB","sourcesContent":["import { loadAndValidate, CliExitError, DEFAULT_BUILD_COMMAND, BuildsLog, BuildTermination, HOTFIX_BUILD_COMMAND } from '@webpieces/rules-config';\nimport { BranchIdentity } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { BuildGateLog } from './build-gate-log';\nimport { StageOutputLog } from './stage-output-log';\n\n// Single source of truth for RUNNING the build gate. `wp-start-upsert-pr` runs NO build; stage ②\n// (`wp-review-upsert-pr`) runs it authoritatively before any reviewer is spawned, and stage ③\n// (`wp-finish-upsert-pr`) re-runs it only when HEAD has moved since. nx `affected` only rebuilds\n// changed projects. The fallback command itself lives in @webpieces/rules-config as\n// DEFAULT_BUILD_COMMAND — whole-repo-build-guard prints the same string, and one definition is what\n// keeps the refusal message naming the build that actually runs.\n\n/**\n * The caller-supplied framing for the build gate (label, re-run command, failure headline, stage id). Kept\n * as a parameter object so runBuildGate stays agnostic of who invokes it. A class (not an object literal)\n * per the codebase's data-structure convention.\n */\nexport class BuildGateOptions {\n label: string; // section header shown above the gate\n rerunCommand: string; // command the AI re-runs after fixing the build\n failureHeadline: string; // first line printed on failure\n // WHICH stage's gate this is — REVIEW_STAGE, FINISH_STAGE or BUILD_STAGE. Required, with no default:\n // it decides the captured log's filename, and a default would silently make two stages share one file.\n stage: string;\n\n constructor(label: string, rerunCommand: string, failureHeadline: string, stage: string) {\n this.label = label;\n this.rerunCommand = rerunCommand;\n this.failureHeadline = failureHeadline;\n this.stage = stage;\n }\n}\n\n/** Runs the authoritative nx-affected build gate for wp-review-upsert-pr and wp-finish-upsert-pr. */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildAffected {\n constructor(\n private readonly buildLog: BuildGateLog,\n private readonly buildsLog: BuildsLog,\n private readonly stageConsole: StageOutputLog,\n private readonly branchIdentity: BranchIdentity,\n ) {}\n\n /**\n * Resolve the exact build command this gate will run: the project's configured\n * PrGateConfig.buildCommand, or the default affected-ci command when none is set.\n */\n resolveBuildCommand(repoRoot: string): string {\n if (this.branchIdentity.isHotfix()) return HOTFIX_BUILD_COMMAND;\n const configured = loadAndValidate(repoRoot).prGate.buildCommand;\n return configured !== undefined && configured.trim() !== ''\n ? configured\n : DEFAULT_BUILD_COMMAND;\n }\n\n /**\n * Run the configured build gate with consistent framing, throwing CliExitError(buildCode) on\n * failure so the bin's main()/runMain owns the exit. THE single source of truth for running a build:\n * wp-build, wp-review-upsert-pr and wp-finish-upsert-pr all call THIS (only the BuildGateOptions\n * differ), and there is no other way to reach the spawn.\n *\n * ─── EVERY BUILD ON THIS MACHINE IS LEDGERED FROM HERE ───────────────────────────────────────────\n * A START row goes into `~/.webpieces/builds.log` before the spawn and a DONE row after it, in a\n * `finally` so a throw on the failure path still closes the pair. `opts.stage` — `build` | `review` |\n * `finish` — IS the caller id the row records; there is deliberately no second `caller` field, since\n * two spellings of one fact is the shim `.claude/rules/no-backwards-compat.md` rejects.\n *\n * The ledger is best-effort by construction (see BuildsLog): it can never throw, so no build can die\n * because a log file was busy.\n */\n async runBuildGate(repoRoot: string, opts: BuildGateOptions): Promise<void> {\n return this.run(repoRoot, opts, false);\n }\n\n /** The human escape hatch uses the same gate but follows build.log on the terminal while it runs. */\n async runBuildGateStreaming(repoRoot: string, opts: BuildGateOptions): Promise<void> {\n return this.run(repoRoot, opts, true);\n }\n\n private async run(repoRoot: string, opts: BuildGateOptions, stream: boolean): Promise<void> {\n const buildCommand = this.resolveBuildCommand(repoRoot);\n // TWO lines on the happy path — the command, then the result. The old framing spent a banner and a\n // paragraph explaining how to reproduce a build that was about to pass anyway; that explanation is\n // only useful when the build FAILS, so it now lives solely on the failure path below.\n //\n // `say`, so it survives a stage that is capturing its own console (see StageOutputLog): the\n // command being run and the result of running it are exactly what a caller watching a long build\n // needs to see live.\n //\n // The log's path goes out FIRST, before the command line and before any work (issue #1393): for\n // `wp-build` it is the very first line on stdout, so a caller that backgrounds the build, or whose\n // harness captures the console into a file of its own, already knows which file to read.\n const logPath = await this.buildLog.pathFor(repoRoot, opts.stage);\n this.stageConsole.say(this.buildLog.startLine(logPath));\n this.stageConsole.say(`\\n${opts.label}: ${buildCommand}\\n`);\n const ticket = this.buildsLog.start(opts.stage, repoRoot);\n let termination = new BuildTermination(1, null);\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the DONE row must be written whether the\n // build passed, failed, or the spawn itself blew up; the throw is re-raised untouched below\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n termination = stream\n ? await this.buildLog.runStreaming(repoRoot, buildCommand, logPath)\n : await this.buildLog.run(repoRoot, buildCommand, logPath);\n } finally {\n this.buildsLog.finish(ticket, termination);\n }\n const buildCode =\n termination.code === null || termination.signal !== null ? 1 : termination.code;\n if (buildCode !== 0) {\n throw new CliExitError(\n buildCode,\n this.failureText(opts, buildCommand, logPath, termination),\n );\n }\n this.stageConsole.say(this.buildLog.successMessage(logPath));\n }\n\n /**\n * The failure text: this gate's own headline, then the pointer at the log the build already wrote.\n *\n * There is no second, streamed variant any more. Capturing used to be behind an EXPERIMENTAL\n * machine-local opt-in, which meant the refusal an agent read depended on a file almost nobody had —\n * and the un-captured branch's advice was \"run the build again yourself\", which is the single most\n * expensive thing an agent can be told. Reading a FILE is now the only answer this gate gives.\n */\n private failureText(\n opts: BuildGateOptions,\n buildCommand: string,\n logPath: string,\n termination: BuildTermination,\n ): string {\n return (\n `\\n❌ ${opts.failureHeadline}\\n` +\n this.buildLog.failureMessage(buildCommand, logPath, termination) +\n `Fix what that log shows, then re-run ${opts.rerunCommand}.\\n`\n );\n }\n}\n"]}
1
+ {"version":3,"file":"build-affected.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-affected.ts"],"names":[],"mappings":";;;;AAAA,0DAAkJ;AAClJ,sEAA+D;AAC/D,yCAA2D;AAC3D,qDAAgD;AAChD,yDAAoD;AAEpD,iGAAiG;AACjG,8FAA8F;AAC9F,iGAAiG;AACjG,oFAAoF;AACpF,oGAAoG;AACpG,iEAAiE;AAEjE;;;;GAIG;AACH,MAAa,gBAAgB;IACzB,KAAK,CAAS,CAAC,sCAAsC;IACrD,YAAY,CAAS,CAAC,gDAAgD;IACtE,eAAe,CAAS,CAAC,gCAAgC;IACzD,qGAAqG;IACrG,uGAAuG;IACvG,KAAK,CAAS;IAEd,YAAY,KAAa,EAAE,YAAoB,EAAE,eAAuB,EAAE,KAAa;QACnF,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAdD,4CAcC;AAED,qGAAqG;AAE9F,IAAM,aAAa,GAAnB,MAAM,aAAa;IAED;IACA;IACA;IACA;IAJrB,YACqB,QAAsB,EACtB,SAAoB,EACpB,YAA4B,EAC5B,cAA8B;QAH9B,aAAQ,GAAR,QAAQ,CAAc;QACtB,cAAS,GAAT,SAAS,CAAW;QACpB,iBAAY,GAAZ,YAAY,CAAgB;QAC5B,mBAAc,GAAd,cAAc,CAAgB;IAChD,CAAC;IAEJ;;;OAGG;IACH,mBAAmB,CAAC,QAAgB;QAChC,IAAI,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE;YAAE,OAAO,mCAAoB,CAAC;QAChE,MAAM,UAAU,GAAG,IAAA,8BAAe,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACjE,OAAO,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,IAA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CAAC;YAChE,wCAAwC,IAAI,CAAC,YAAY,KAAK,CACjE,CAAC;IACN,CAAC;CACJ,CAAA;AAhHY,sCAAa;wBAAb,aAAa;IADzB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGN,6BAAY;QACX,wBAAS;QACN,iCAAc;QACZ,mCAAc;GAL1C,aAAa,CAgHzB","sourcesContent":["import { loadAndValidate, CliExitError, DEFAULT_BUILD_COMMAND, BuildsLog, BuildTermination, HOTFIX_BUILD_COMMAND } from '@webpieces/rules-config';\nimport { BranchIdentity } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { BuildGateLog } from './build-gate-log';\nimport { StageOutputLog } from './stage-output-log';\n\n// Single source of truth for RUNNING the build gate. `wp-start-upsert-pr` runs NO build; stage ②\n// (`wp-review-upsert-pr`) runs it authoritatively before any reviewer is spawned, and stage ③\n// (`wp-finish-upsert-pr`) re-runs it only when HEAD has moved since. nx `affected` only rebuilds\n// changed projects. The fallback command itself lives in @webpieces/rules-config as\n// DEFAULT_BUILD_COMMAND — whole-repo-build-guard prints the same string, and one definition is what\n// keeps the refusal message naming the build that actually runs.\n\n/**\n * The caller-supplied framing for the build gate (label, re-run command, failure headline, stage id). Kept\n * as a parameter object so runBuildGate stays agnostic of who invokes it. A class (not an object literal)\n * per the codebase's data-structure convention.\n */\nexport class BuildGateOptions {\n label: string; // section header shown above the gate\n rerunCommand: string; // command the AI re-runs after fixing the build\n failureHeadline: string; // first line printed on failure\n // WHICH stage's gate this is — REVIEW_STAGE, FINISH_STAGE or BUILD_STAGE. Required, with no default:\n // it decides the captured log's filename, and a default would silently make two stages share one file.\n stage: string;\n\n constructor(label: string, rerunCommand: string, failureHeadline: string, stage: string) {\n this.label = label;\n this.rerunCommand = rerunCommand;\n this.failureHeadline = failureHeadline;\n this.stage = stage;\n }\n}\n\n/** Runs the authoritative nx-affected build gate for wp-review-upsert-pr and wp-finish-upsert-pr. */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildAffected {\n constructor(\n private readonly buildLog: BuildGateLog,\n private readonly buildsLog: BuildsLog,\n private readonly stageConsole: StageOutputLog,\n private readonly branchIdentity: BranchIdentity,\n ) {}\n\n /**\n * Resolve the exact build command this gate will run: the project's configured\n * PrGateConfig.buildCommand, or the default affected-ci command when none is set.\n */\n resolveBuildCommand(repoRoot: string): string {\n if (this.branchIdentity.isHotfix()) return HOTFIX_BUILD_COMMAND;\n const configured = loadAndValidate(repoRoot).prGate.buildCommand;\n return configured !== undefined && configured.trim() !== ''\n ? configured\n : DEFAULT_BUILD_COMMAND;\n }\n\n /**\n * Run the configured build gate with consistent framing, throwing CliExitError(buildCode) on\n * failure so the bin's main()/runMain owns the exit. THE single source of truth for running a build:\n * wp-build, wp-review-upsert-pr and wp-finish-upsert-pr all call THIS (only the BuildGateOptions\n * differ), and there is no other way to reach the spawn.\n *\n * ─── EVERY BUILD ON THIS MACHINE IS LEDGERED FROM HERE ───────────────────────────────────────────\n * A START row goes into `~/.webpieces/builds.log` before the spawn and a DONE row after it, in a\n * `finally` so a throw on the failure path still closes the pair. `opts.stage` — `build` | `review` |\n * `finish` — IS the caller id the row records; there is deliberately no second `caller` field, since\n * two spellings of one fact is the shim `.claude/rules/no-backwards-compat.md` rejects.\n *\n * The ledger is best-effort by construction (see BuildsLog): it can never throw, so no build can die\n * because a log file was busy.\n */\n async runBuildGate(repoRoot: string, opts: BuildGateOptions): Promise<void> {\n return this.run(repoRoot, this.resolveBuildCommand(repoRoot), opts, false);\n }\n\n /** The human escape hatch uses the same gate but follows build.log on the terminal while it runs. */\n async runBuildGateStreaming(repoRoot: string, opts: BuildGateOptions): Promise<void> {\n return this.run(repoRoot, this.resolveBuildCommand(repoRoot), opts, true);\n }\n\n /**\n * The same gate — log file, heartbeat, ledger rows, failure rendering — for a command the CALLER\n * resolved. Used only by the dev build (#1397), whose command is `commands.push-dev.buildCommand` and\n * has no default (DevBuild owns that read and its refusal). Everything after the command is shared,\n * so a dev build fails exactly the way `wp-build` does.\n */\n async runBuildGateWith(repoRoot: string, buildCommand: string, opts: BuildGateOptions): Promise<void> {\n return this.run(repoRoot, buildCommand, opts, false);\n }\n\n private async run(repoRoot: string, buildCommand: string, opts: BuildGateOptions, stream: boolean): Promise<void> {\n // TWO lines on the happy path — the command, then the result. The old framing spent a banner and a\n // paragraph explaining how to reproduce a build that was about to pass anyway; that explanation is\n // only useful when the build FAILS, so it now lives solely on the failure path below.\n //\n // `say`, so it survives a stage that is capturing its own console (see StageOutputLog): the\n // command being run and the result of running it are exactly what a caller watching a long build\n // needs to see live.\n //\n // The log's path goes out FIRST, before the command line and before any work (issue #1393): for\n // `wp-build` it is the very first line on stdout, so a caller that backgrounds the build, or whose\n // harness captures the console into a file of its own, already knows which file to read.\n const logPath = await this.buildLog.pathFor(repoRoot, opts.stage);\n this.stageConsole.say(this.buildLog.startLine(logPath));\n this.stageConsole.say(`\\n${opts.label}: ${buildCommand}\\n`);\n const ticket = this.buildsLog.start(opts.stage, repoRoot);\n let termination = new BuildTermination(1, null);\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the DONE row must be written whether the\n // build passed, failed, or the spawn itself blew up; the throw is re-raised untouched below\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n termination = stream\n ? await this.buildLog.runStreaming(repoRoot, buildCommand, logPath)\n : await this.buildLog.run(repoRoot, buildCommand, logPath);\n } finally {\n this.buildsLog.finish(ticket, termination);\n }\n const buildCode =\n termination.code === null || termination.signal !== null ? 1 : termination.code;\n if (buildCode !== 0) {\n throw new CliExitError(\n buildCode,\n this.failureText(opts, buildCommand, logPath, termination),\n );\n }\n this.stageConsole.say(this.buildLog.successMessage(logPath));\n }\n\n /**\n * The failure text: this gate's own headline, then the pointer at the log the build already wrote.\n *\n * There is no second, streamed variant any more. Capturing used to be behind an EXPERIMENTAL\n * machine-local opt-in, which meant the refusal an agent read depended on a file almost nobody had —\n * and the un-captured branch's advice was \"run the build again yourself\", which is the single most\n * expensive thing an agent can be told. Reading a FILE is now the only answer this gate gives.\n */\n private failureText(\n opts: BuildGateOptions,\n buildCommand: string,\n logPath: string,\n termination: BuildTermination,\n ): string {\n return (\n `\\n❌ ${opts.failureHeadline}\\n` +\n this.buildLog.failureMessage(buildCommand, logPath, termination) +\n `Fix what that log shows, then re-run ${opts.rerunCommand}.\\n`\n );\n }\n}\n"]}
@@ -15,8 +15,10 @@ export declare const FAILURE_TAIL_LINES = 20;
15
15
  export declare const REVIEW_STAGE = "review";
16
16
  export declare const FINISH_STAGE = "finish";
17
17
  export declare const BUILD_STAGE = "build";
18
- /** The one fixed log name — see BuildGateLog.fileNameFor for why only `wp-build` gets one. */
18
+ export declare const DEV_BUILD_STAGE = "build-dev";
19
+ /** The fixed log names — see BuildGateLog.fileNameFor for why only the two ad-hoc builds get one. */
19
20
  export declare const BUILD_LOG_NAME = "build.log";
21
+ export declare const DEV_BUILD_LOG_NAME = "build-dev.log";
20
22
  /**
21
23
  * The heartbeat's state: the line count reported on the PREVIOUS tick, so a tick that has not moved can
22
24
  * say so. Stateful per RUN, which is why it is constructed per run rather than injected.
@@ -66,7 +68,7 @@ export declare class BuildGateLog {
66
68
  pathFor(repoRoot: string, stage: string): Promise<string>;
67
69
  /** The same path, and '' when no log has been WRITTEN there yet. Used by finish's skip path. */
68
70
  existingLogFor(repoRoot: string, stage: string): Promise<string>;
69
- /** `build.log` for `wp-build`; `build-gate-<stage>-<branch>-<shortSha>.log` for the PR-flow stages. */
71
+ /** `build.log` for `wp-build`; `build-dev.log` for the dev build; `build-gate-<stage>-<branch>-<shortSha>.log` for the PR-flow stages. */
70
72
  fileNameFor(repoRoot: string, stage: string): Promise<string>;
71
73
  /**
72
74
  * Run `buildCommand` with its stdout AND stderr redirected in full to `logPath`, printing a heartbeat
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BuildGateLog = exports.BuildLogHeartbeat = exports.BUILD_LOG_NAME = exports.BUILD_STAGE = exports.FINISH_STAGE = exports.REVIEW_STAGE = exports.FAILURE_TAIL_LINES = exports.HEARTBEAT_MS = void 0;
3
+ exports.BuildGateLog = exports.BuildLogHeartbeat = exports.DEV_BUILD_LOG_NAME = exports.BUILD_LOG_NAME = exports.DEV_BUILD_STAGE = exports.BUILD_STAGE = exports.FINISH_STAGE = exports.REVIEW_STAGE = exports.FAILURE_TAIL_LINES = exports.HEARTBEAT_MS = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs = tslib_1.__importStar(require("fs"));
6
6
  const rules_config_1 = require("@webpieces/rules-config");
@@ -48,8 +48,12 @@ exports.REVIEW_STAGE = 'review';
48
48
  exports.FINISH_STAGE = 'finish';
49
49
  // `wp-build`, which is not a stage of the PR flow but runs the SAME gate (BuildAffected.runBuildGate).
50
50
  exports.BUILD_STAGE = 'build';
51
- /** The one fixed log name — see BuildGateLog.fileNameFor for why only `wp-build` gets one. */
51
+ // `wp-build-dev` and the pre-publish build of `wp-push-dev` / `wp-finish-push-dev` (#1397): the SAME gate,
52
+ // running `commands.push-dev.buildCommand` instead.
53
+ exports.DEV_BUILD_STAGE = 'build-dev';
54
+ /** The fixed log names — see BuildGateLog.fileNameFor for why only the two ad-hoc builds get one. */
52
55
  exports.BUILD_LOG_NAME = 'build.log';
56
+ exports.DEV_BUILD_LOG_NAME = 'build-dev.log';
53
57
  /**
54
58
  * The heartbeat's state: the line count reported on the PREVIOUS tick, so a tick that has not moved can
55
59
  * say so. Stateful per RUN, which is why it is constructed per run rather than injected.
@@ -119,10 +123,14 @@ let BuildGateLog = class BuildGateLog {
119
123
  const file = await this.resolvePath(repoRoot, stage);
120
124
  return fs.existsSync(file) ? file : '';
121
125
  }
122
- /** `build.log` for `wp-build`; `build-gate-<stage>-<branch>-<shortSha>.log` for the PR-flow stages. */
126
+ /** `build.log` for `wp-build`; `build-dev.log` for the dev build; `build-gate-<stage>-<branch>-<shortSha>.log` for the PR-flow stages. */
123
127
  async fileNameFor(repoRoot, stage) {
124
128
  if (stage === exports.BUILD_STAGE)
125
129
  return exports.BUILD_LOG_NAME;
130
+ // Fixed, like build.log: the dev build runs on a THROWAWAY branch whose name and sha say nothing
131
+ // to the reader, and history comes from the same rotation.
132
+ if (stage === exports.DEV_BUILD_STAGE)
133
+ return exports.DEV_BUILD_LOG_NAME;
126
134
  const branch = this.slug(tooling_common_1.gitCheckout.branch(repoRoot) ?? '');
127
135
  const sha = this.slug(await this.gitOut(repoRoot, ['rev-parse', '--short', 'HEAD']));
128
136
  return `build-gate-${this.slug(stage)}-${branch === '' ? 'nobranch' : branch}-${sha === '' ? 'nosha' : sha}.log`;
@@ -1 +1 @@
1
- {"version":3,"file":"build-gate-log.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-gate-log.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,0DAA2D;AAC3D,8DAA8G;AAC9G,yCAA2D;AAE3D,mDAA8C;AAC9C,yDAAoD;AACpD,6DAAwD;AAExD,0GAA0G;AAC1G,yGAAyG;AACzG,2GAA2G;AAC3G,mGAAmG;AACnG,kGAAkG;AAClG,EAAE;AACF,uGAAuG;AACvG,kGAAkG;AAClG,EAAE;AACF,0GAA0G;AAC1G,sGAAsG;AACtG,wGAAwG;AACxG,2GAA2G;AAC3G,2GAA2G;AAC3G,wGAAwG;AACxG,qGAAqG;AACrG,EAAE;AACF,sIAAsI;AACtI,kHAAkH;AAClH,0GAA0G;AAC1G,kGAAkG;AAClG,EAAE;AACF,uGAAuG;AACvG,0GAA0G;AAC1G,uGAAuG;AAEvG;uEACuE;AAC1D,QAAA,YAAY,GAAG,MAAM,CAAC;AAEnC;;sCAEsC;AACzB,QAAA,kBAAkB,GAAG,EAAE,CAAC;AAErC;;GAEG;AACU,QAAA,YAAY,GAAG,QAAQ,CAAC;AACxB,QAAA,YAAY,GAAG,QAAQ,CAAC;AACrC,uGAAuG;AAC1F,QAAA,WAAW,GAAG,OAAO,CAAC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;IAEO,KAAK,CAAC,WAAW,CAAC,QAAgB,EAAE,KAAa;QACrD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;IAClF,CAAC;IAED,wGAAwG;IAChG,IAAI,CAAC,KAAa;QACtB,OAAO,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,qGAAqG;IACrG,8DAA8D;IACtD,KAAK,CAAC,MAAM,CAAC,QAAgB,EAAE,IAAc;QACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;QAC7D,IAAI,CAAC,MAAM,CAAC,EAAE;YAAE,OAAO,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAChC,CAAC;CACJ,CAAA;AA3IY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGT,2BAAW;QACJ,iCAAc;QACvB,8BAAa;QACP,iCAAgB;GALvC,YAAY,CA2IxB","sourcesContent":["import * as fs from 'fs';\nimport { BuildTermination } from '@webpieces/rules-config';\nimport { gitCheckout, GitProcessApi, NativeProcessApi, ShellTerminationDto } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GateLogFile } from './gate-log-file';\nimport { StageOutputLog } from './stage-output-log';\nimport { BuildLogFollower } from './build-log-follower';\n\n// ─── Why ───────────────────────────────────────────────────────────────────────────────────────────────\n// The build gate already builds everything. When the output only ever went to the CONSOLE, an agent that\n// wanted a different slice of it re-ran the WHOLE BUILD to get it: one measured session spent 23.9 minutes\n// across nine `nx affected` runs, five of them with NO code change in between — `| tail -50`, then\n// `> /tmp/file`, then `| grep`, then `| sed -n '1100,1230p'`. ~19 minutes spent re-reading a log.\n//\n// So the build's output is not streamed; it is REDIRECTED, in full, to a file whose path the caller is\n// handed on completion. Reading a different slice is then a `grep` of a FILE, not a second build.\n//\n// ─── Why a redirect and not `tee` ──────────────────────────────────────────────────────────────────────\n// An earlier cut of this used `cmd 2>&1 | tee log`, to keep the terminal byte-identical. That is what\n// makes the transcript expensive in the first place — an AI caller carries every line of it in context.\n// The redirect keeps the console to a handful of lines (a heartbeat, then a pointer at the file), which is\n// the entire productivity claim. Losing `tee` also deletes the `$?`-into-a-side-file dance it needed: in a\n// pipeline the shell reports TEE's status, which is 0 whether the build passed or failed, so the status\n// had to be smuggled out through a side file. With no pipe, the child's own exit code IS the answer.\n//\n// ─── Why async (a child that does not block, not a synchronous spawn) ──────────────────────────────────────────────────────────────\n// A synchronous spawn blocks the event loop for the length of the build, so NOTHING can print while it runs — and\n// a silent terminal for 3–7 minutes is indistinguishable from a hang. The heartbeat is the reason this is\n// async, and it is why `run` returns a Promise and `BuildAffected.runBuildGate` is async with it.\n//\n// It is also the reason the heartbeat goes through `StageOutputLog.say` rather than `process.stdout` —\n// stage ② and stage ③ capture their own console output to a file, and a heartbeat captured into a file is\n// a heartbeat nobody can see. The 600-second watchdog that kills a silent command does not read files.\n\n/** How often the heartbeat reports the log's size. Hardcoded: a knob here would be a knob the PR gate's\n * own build never receives, and the two must stay the same command. */\nexport const HEARTBEAT_MS = 10_000;\n\n/** How many trailing log lines the failure message echoes, so the immediate cause is visible without a\n * second command. Small on purpose — the FULL log is one grep away and the message must not become the\n * transcript it exists to replace. */\nexport const FAILURE_TAIL_LINES = 20;\n\n/**\n * Which stage's gate is being captured. The value decides the log FILENAME.\n */\nexport const REVIEW_STAGE = 'review';\nexport const FINISH_STAGE = 'finish';\n// `wp-build`, which is not a stage of the PR flow but runs the SAME gate (BuildAffected.runBuildGate).\nexport const BUILD_STAGE = 'build';\n\n/** The one fixed log name — see BuildGateLog.fileNameFor for why only `wp-build` gets one. */\nexport const BUILD_LOG_NAME = 'build.log';\n\n/**\n * The heartbeat's state: the line count reported on the PREVIOUS tick, so a tick that has not moved can\n * say so. Stateful per RUN, which is why it is constructed per run rather than injected.\n *\n * `still` is the load-bearing word. A build that is linking, or waiting on a cold nx cache, produces no\n * output for minutes; without `still` the caller sees the same number twice and cannot tell a stalled\n * BUILD from a stalled REPORTER.\n */\nexport class BuildLogHeartbeat {\n private previous: number | null = null;\n\n constructor(\n private readonly files: GateLogFile,\n private readonly logPath: string,\n private readonly displayPath: string,\n ) {}\n\n /** One heartbeat line — `<path> size <n> lines`, plus ` still` when <n> has not moved. */\n tick(): string {\n const count = this.files.lineCount(this.logPath);\n const still = this.previous !== null && count === this.previous ? ' still' : '';\n this.previous = count;\n return `${this.displayPath} size ${count} lines${still}`;\n }\n}\n\n/**\n * Captures the build gate's full output to a file, reports progress while it runs, and renders the\n * pointer the caller is handed instead of a rebuild instruction.\n *\n * WHERE the file goes, how the previous run is kept, and what the pointer reads like are `GateLogFile`'s\n * — one mechanism, shared with the stage console log, so there is a single answer to \"where is it?\".\n *\n * ─── One directory, two naming schemes, one rule each ──────────────────────────────────────────────────\n * Every build log sits in `<tree>/.webpieces/logs/` (GateLogFile.logsPath — inside the checkout the\n * command ran in, a linked worktree's own root included; issue #1393).\n * • `wp-build` (BUILD_STAGE) writes ONE fixed name, `build.log`. History comes from the rotation.\n * • stage ② and stage ③ write `build-gate-<stage>-<branch>-<shortSha>.log`, because those two gates CAN\n * run against one commit and a failure message from one must not be pointing at a file the other\n * overwrote.\n * Nobody needs to type either name: the absolute path is printed as the FIRST line of the build, before\n * it starts, and again in the closing pointer.\n *\n * ─── Concurrency ───────────────────────────────────────────────────────────────────────────────────────\n * The DIRECTORY is per checkout — a linked worktree writes under its own root — so \"N agents in N\n * worktrees\" is safe by construction rather than by naming. The residual case is two builds in the SAME\n * worktree at once, which is already unsupported: both would be driving one git index.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildGateLog {\n constructor(\n private readonly files: GateLogFile,\n private readonly stageConsole: StageOutputLog,\n private readonly git: GitProcessApi,\n private readonly processes: NativeProcessApi,\n ) {}\n\n /** Absolute path of the log for `stage` at the current HEAD, creating its directory. */\n pathFor(repoRoot: string, stage: string): Promise<string> {\n return this.resolvePath(repoRoot, stage);\n }\n\n /** The same path, and '' when no log has been WRITTEN there yet. Used by finish's skip path. */\n async existingLogFor(repoRoot: string, stage: string): Promise<string> {\n const file = await this.resolvePath(repoRoot, stage);\n return fs.existsSync(file) ? file : '';\n }\n\n /** `build.log` for `wp-build`; `build-gate-<stage>-<branch>-<shortSha>.log` for the PR-flow stages. */\n async fileNameFor(repoRoot: string, stage: string): Promise<string> {\n if (stage === BUILD_STAGE) return BUILD_LOG_NAME;\n const branch = this.slug(gitCheckout.branch(repoRoot) ?? '');\n const sha = this.slug(await this.gitOut(repoRoot, ['rev-parse', '--short', 'HEAD']));\n return `build-gate-${this.slug(stage)}-${branch === '' ? 'nobranch' : branch}-${sha === '' ? 'nosha' : sha}.log`;\n }\n\n /**\n * Run `buildCommand` with its stdout AND stderr redirected in full to `logPath`, printing a heartbeat\n * every HEARTBEAT_MS so the caller can see it is alive. Returns the BUILD's raw termination facts.\n * Nothing is truncated. Ordinary AI-facing callers do not stream; the explicitly human-attested\n * PR escape hatch may wrap this with runStreaming(), which follows the same durable file live.\n */\n async run(repoRoot: string, buildCommand: string, logPath: string): Promise<BuildTermination> {\n this.files.rotate(logPath);\n const fd = fs.openSync(logPath, 'w');\n const heartbeat = new BuildLogHeartbeat(\n this.files,\n logPath,\n this.files.displayPath(repoRoot, logPath),\n );\n const timer = setInterval((): void => {\n this.stageConsole.say(`${heartbeat.tick()}\\n`);\n }, HEARTBEAT_MS);\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the timer and the fd MUST be released\n // whatever the child does, and the exit code is returned rather than thrown so runBuildGate owns\n // the one CliExitError.\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return this.recordTermination(await this.processes.runShellToFile(buildCommand, repoRoot, fd), fd);\n } finally {\n clearInterval(timer);\n fs.closeSync(fd);\n }\n }\n\n /** Human-only variant: preserve the durable log and follow its appended bytes live. */\n runStreaming(\n repoRoot: string,\n buildCommand: string,\n logPath: string,\n ): Promise<BuildTermination> {\n // run() synchronously rotates and opens the file before reaching its first await, so the follower\n // cannot accidentally replay the previous build that was at this path.\n const completion = this.run(repoRoot, buildCommand, logPath);\n const follower = new BuildLogFollower(logPath, this.stageConsole);\n follower.start();\n return completion.finally((): void => follower.stop());\n }\n\n /** The `FullLog : <path>` line printed before the build starts — see GateLogFile.startLine. */\n startLine(logPath: string): string {\n return this.files.startLine(logPath);\n }\n\n /**\n * The success summary: the caller is told WHERE the full output is, not handed the output.\n */\n successMessage(logPath: string): string {\n return `\\nBuild success\\n${this.files.pointer(logPath)}`;\n }\n\n /**\n * The ENTIRE message the caller gets on a failed build. It names the log, echoes the last\n * FAILURE_TAIL_LINES lines so the immediate cause needs no second command, and forbids the rebuild\n * this whole file exists to prevent.\n *\n * The last sentence is not filler. If the log holds no visible failure then something upstream is wrong\n * (a runner that died without printing, a truncated redirect), and the worst possible response is an\n * agent guessing or rebuilding — so it is told to surface the contradiction to the human and stop.\n */\n failureMessage(buildCommand: string, logPath: string, termination: BuildTermination): string {\n return (\n `\\nBuild Failed: ${buildCommand}\\n${this.files.pointer(logPath)}\\n` +\n `${this.terminationRecord(termination)}\\n` +\n `Last ${FAILURE_TAIL_LINES} lines of that log:\\n${this.files.tail(logPath, FAILURE_TAIL_LINES)}\\n` +\n `Read that FILE for the failures. Do NOT re-run the build to see them.\\n` +\n `If you do not see failures in that log, report that to the user and stop.\\n`\n );\n }\n\n // The child's close code AND signal. A command that never starts (a shell that is missing, a cwd that\n // vanished) fails CLOSED to 1 — calling a build that never ran green is the one outcome that must be\n // impossible — and the reason is APPENDED TO THE LOG, so the failure message's pointer still leads to\n // it rather than to an empty file.\n private recordTermination(ended: ShellTerminationDto, fd: number): BuildTermination {\n if (ended.startError !== null) {\n fs.writeSync(fd, `\\nThe build command could not be started: ${ended.startError}\\n`);\n return new BuildTermination(1, null);\n }\n const termination = new BuildTermination(ended.code, ended.signal);\n if (ended.code === null || ended.signal !== null)\n fs.writeSync(fd, `\\n${this.terminationRecord(termination)}\\n`);\n return termination;\n }\n\n /** One stable, human-readable spelling shared by the FullLog and the immediate failure output. */\n private terminationRecord(termination: BuildTermination): string {\n const code = termination.code === null ? 'null' : String(termination.code);\n const signal = termination.signal === null ? 'none' : termination.signal;\n return `Build process termination: exit code ${code}; signal ${signal}.`;\n }\n\n private async resolvePath(repoRoot: string, stage: string): Promise<string> {\n return this.files.logsPath(repoRoot, await this.fileNameFor(repoRoot, stage));\n }\n\n // Anything that is not a filename-safe character becomes '-', so `dean/feat` cannot create directories.\n private slug(value: string): string {\n return value.replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '');\n }\n\n // One local git read. Fails SOFT to '' — a missing branch/sha degrades the FILENAME, and degrading a\n // filename may never be the reason a build gate does not run.\n private async gitOut(repoRoot: string, args: string[]): Promise<string> {\n const result = await this.git.run(['-C', repoRoot, ...args]);\n if (!result.ok) return '';\n return result.stdout.trim();\n }\n}\n"]}
1
+ {"version":3,"file":"build-gate-log.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-gate-log.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,0DAA2D;AAC3D,8DAA8G;AAC9G,yCAA2D;AAE3D,mDAA8C;AAC9C,yDAAoD;AACpD,6DAAwD;AAExD,0GAA0G;AAC1G,yGAAyG;AACzG,2GAA2G;AAC3G,mGAAmG;AACnG,kGAAkG;AAClG,EAAE;AACF,uGAAuG;AACvG,kGAAkG;AAClG,EAAE;AACF,0GAA0G;AAC1G,sGAAsG;AACtG,wGAAwG;AACxG,2GAA2G;AAC3G,2GAA2G;AAC3G,wGAA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CAAC,IAAI,EAAE,CAAC;IAChC,CAAC;CACJ,CAAA;AA9IY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGT,2BAAW;QACJ,iCAAc;QACvB,8BAAa;QACP,iCAAgB;GALvC,YAAY,CA8IxB","sourcesContent":["import * as fs from 'fs';\nimport { BuildTermination } from '@webpieces/rules-config';\nimport { gitCheckout, GitProcessApi, NativeProcessApi, ShellTerminationDto } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GateLogFile } from './gate-log-file';\nimport { StageOutputLog } from './stage-output-log';\nimport { BuildLogFollower } from './build-log-follower';\n\n// ─── Why ───────────────────────────────────────────────────────────────────────────────────────────────\n// The build gate already builds everything. When the output only ever went to the CONSOLE, an agent that\n// wanted a different slice of it re-ran the WHOLE BUILD to get it: one measured session spent 23.9 minutes\n// across nine `nx affected` runs, five of them with NO code change in between — `| tail -50`, then\n// `> /tmp/file`, then `| grep`, then `| sed -n '1100,1230p'`. ~19 minutes spent re-reading a log.\n//\n// So the build's output is not streamed; it is REDIRECTED, in full, to a file whose path the caller is\n// handed on completion. Reading a different slice is then a `grep` of a FILE, not a second build.\n//\n// ─── Why a redirect and not `tee` ──────────────────────────────────────────────────────────────────────\n// An earlier cut of this used `cmd 2>&1 | tee log`, to keep the terminal byte-identical. That is what\n// makes the transcript expensive in the first place — an AI caller carries every line of it in context.\n// The redirect keeps the console to a handful of lines (a heartbeat, then a pointer at the file), which is\n// the entire productivity claim. Losing `tee` also deletes the `$?`-into-a-side-file dance it needed: in a\n// pipeline the shell reports TEE's status, which is 0 whether the build passed or failed, so the status\n// had to be smuggled out through a side file. With no pipe, the child's own exit code IS the answer.\n//\n// ─── Why async (a child that does not block, not a synchronous spawn) ──────────────────────────────────────────────────────────────\n// A synchronous spawn blocks the event loop for the length of the build, so NOTHING can print while it runs — and\n// a silent terminal for 3–7 minutes is indistinguishable from a hang. The heartbeat is the reason this is\n// async, and it is why `run` returns a Promise and `BuildAffected.runBuildGate` is async with it.\n//\n// It is also the reason the heartbeat goes through `StageOutputLog.say` rather than `process.stdout` —\n// stage ② and stage ③ capture their own console output to a file, and a heartbeat captured into a file is\n// a heartbeat nobody can see. The 600-second watchdog that kills a silent command does not read files.\n\n/** How often the heartbeat reports the log's size. Hardcoded: a knob here would be a knob the PR gate's\n * own build never receives, and the two must stay the same command. */\nexport const HEARTBEAT_MS = 10_000;\n\n/** How many trailing log lines the failure message echoes, so the immediate cause is visible without a\n * second command. Small on purpose — the FULL log is one grep away and the message must not become the\n * transcript it exists to replace. */\nexport const FAILURE_TAIL_LINES = 20;\n\n/**\n * Which stage's gate is being captured. The value decides the log FILENAME.\n */\nexport const REVIEW_STAGE = 'review';\nexport const FINISH_STAGE = 'finish';\n// `wp-build`, which is not a stage of the PR flow but runs the SAME gate (BuildAffected.runBuildGate).\nexport const BUILD_STAGE = 'build';\n// `wp-build-dev` and the pre-publish build of `wp-push-dev` / `wp-finish-push-dev` (#1397): the SAME gate,\n// running `commands.push-dev.buildCommand` instead.\nexport const DEV_BUILD_STAGE = 'build-dev';\n\n/** The fixed log names — see BuildGateLog.fileNameFor for why only the two ad-hoc builds get one. */\nexport const BUILD_LOG_NAME = 'build.log';\nexport const DEV_BUILD_LOG_NAME = 'build-dev.log';\n\n/**\n * The heartbeat's state: the line count reported on the PREVIOUS tick, so a tick that has not moved can\n * say so. Stateful per RUN, which is why it is constructed per run rather than injected.\n *\n * `still` is the load-bearing word. A build that is linking, or waiting on a cold nx cache, produces no\n * output for minutes; without `still` the caller sees the same number twice and cannot tell a stalled\n * BUILD from a stalled REPORTER.\n */\nexport class BuildLogHeartbeat {\n private previous: number | null = null;\n\n constructor(\n private readonly files: GateLogFile,\n private readonly logPath: string,\n private readonly displayPath: string,\n ) {}\n\n /** One heartbeat line — `<path> size <n> lines`, plus ` still` when <n> has not moved. */\n tick(): string {\n const count = this.files.lineCount(this.logPath);\n const still = this.previous !== null && count === this.previous ? ' still' : '';\n this.previous = count;\n return `${this.displayPath} size ${count} lines${still}`;\n }\n}\n\n/**\n * Captures the build gate's full output to a file, reports progress while it runs, and renders the\n * pointer the caller is handed instead of a rebuild instruction.\n *\n * WHERE the file goes, how the previous run is kept, and what the pointer reads like are `GateLogFile`'s\n * — one mechanism, shared with the stage console log, so there is a single answer to \"where is it?\".\n *\n * ─── One directory, two naming schemes, one rule each ──────────────────────────────────────────────────\n * Every build log sits in `<tree>/.webpieces/logs/` (GateLogFile.logsPath — inside the checkout the\n * command ran in, a linked worktree's own root included; issue #1393).\n * • `wp-build` (BUILD_STAGE) writes ONE fixed name, `build.log`. History comes from the rotation.\n * • stage ② and stage ③ write `build-gate-<stage>-<branch>-<shortSha>.log`, because those two gates CAN\n * run against one commit and a failure message from one must not be pointing at a file the other\n * overwrote.\n * Nobody needs to type either name: the absolute path is printed as the FIRST line of the build, before\n * it starts, and again in the closing pointer.\n *\n * ─── Concurrency ───────────────────────────────────────────────────────────────────────────────────────\n * The DIRECTORY is per checkout — a linked worktree writes under its own root — so \"N agents in N\n * worktrees\" is safe by construction rather than by naming. The residual case is two builds in the SAME\n * worktree at once, which is already unsupported: both would be driving one git index.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildGateLog {\n constructor(\n private readonly files: GateLogFile,\n private readonly stageConsole: StageOutputLog,\n private readonly git: GitProcessApi,\n private readonly processes: NativeProcessApi,\n ) {}\n\n /** Absolute path of the log for `stage` at the current HEAD, creating its directory. */\n pathFor(repoRoot: string, stage: string): Promise<string> {\n return this.resolvePath(repoRoot, stage);\n }\n\n /** The same path, and '' when no log has been WRITTEN there yet. Used by finish's skip path. */\n async existingLogFor(repoRoot: string, stage: string): Promise<string> {\n const file = await this.resolvePath(repoRoot, stage);\n return fs.existsSync(file) ? file : '';\n }\n\n /** `build.log` for `wp-build`; `build-dev.log` for the dev build; `build-gate-<stage>-<branch>-<shortSha>.log` for the PR-flow stages. */\n async fileNameFor(repoRoot: string, stage: string): Promise<string> {\n if (stage === BUILD_STAGE) return BUILD_LOG_NAME;\n // Fixed, like build.log: the dev build runs on a THROWAWAY branch whose name and sha say nothing\n // to the reader, and history comes from the same rotation.\n if (stage === DEV_BUILD_STAGE) return DEV_BUILD_LOG_NAME;\n const branch = this.slug(gitCheckout.branch(repoRoot) ?? '');\n const sha = this.slug(await this.gitOut(repoRoot, ['rev-parse', '--short', 'HEAD']));\n return `build-gate-${this.slug(stage)}-${branch === '' ? 'nobranch' : branch}-${sha === '' ? 'nosha' : sha}.log`;\n }\n\n /**\n * Run `buildCommand` with its stdout AND stderr redirected in full to `logPath`, printing a heartbeat\n * every HEARTBEAT_MS so the caller can see it is alive. Returns the BUILD's raw termination facts.\n * Nothing is truncated. Ordinary AI-facing callers do not stream; the explicitly human-attested\n * PR escape hatch may wrap this with runStreaming(), which follows the same durable file live.\n */\n async run(repoRoot: string, buildCommand: string, logPath: string): Promise<BuildTermination> {\n this.files.rotate(logPath);\n const fd = fs.openSync(logPath, 'w');\n const heartbeat = new BuildLogHeartbeat(\n this.files,\n logPath,\n this.files.displayPath(repoRoot, logPath),\n );\n const timer = setInterval((): void => {\n this.stageConsole.say(`${heartbeat.tick()}\\n`);\n }, HEARTBEAT_MS);\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the timer and the fd MUST be released\n // whatever the child does, and the exit code is returned rather than thrown so runBuildGate owns\n // the one CliExitError.\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return this.recordTermination(await this.processes.runShellToFile(buildCommand, repoRoot, fd), fd);\n } finally {\n clearInterval(timer);\n fs.closeSync(fd);\n }\n }\n\n /** Human-only variant: preserve the durable log and follow its appended bytes live. */\n runStreaming(\n repoRoot: string,\n buildCommand: string,\n logPath: string,\n ): Promise<BuildTermination> {\n // run() synchronously rotates and opens the file before reaching its first await, so the follower\n // cannot accidentally replay the previous build that was at this path.\n const completion = this.run(repoRoot, buildCommand, logPath);\n const follower = new BuildLogFollower(logPath, this.stageConsole);\n follower.start();\n return completion.finally((): void => follower.stop());\n }\n\n /** The `FullLog : <path>` line printed before the build starts — see GateLogFile.startLine. */\n startLine(logPath: string): string {\n return this.files.startLine(logPath);\n }\n\n /**\n * The success summary: the caller is told WHERE the full output is, not handed the output.\n */\n successMessage(logPath: string): string {\n return `\\nBuild success\\n${this.files.pointer(logPath)}`;\n }\n\n /**\n * The ENTIRE message the caller gets on a failed build. It names the log, echoes the last\n * FAILURE_TAIL_LINES lines so the immediate cause needs no second command, and forbids the rebuild\n * this whole file exists to prevent.\n *\n * The last sentence is not filler. If the log holds no visible failure then something upstream is wrong\n * (a runner that died without printing, a truncated redirect), and the worst possible response is an\n * agent guessing or rebuilding — so it is told to surface the contradiction to the human and stop.\n */\n failureMessage(buildCommand: string, logPath: string, termination: BuildTermination): string {\n return (\n `\\nBuild Failed: ${buildCommand}\\n${this.files.pointer(logPath)}\\n` +\n `${this.terminationRecord(termination)}\\n` +\n `Last ${FAILURE_TAIL_LINES} lines of that log:\\n${this.files.tail(logPath, FAILURE_TAIL_LINES)}\\n` +\n `Read that FILE for the failures. Do NOT re-run the build to see them.\\n` +\n `If you do not see failures in that log, report that to the user and stop.\\n`\n );\n }\n\n // The child's close code AND signal. A command that never starts (a shell that is missing, a cwd that\n // vanished) fails CLOSED to 1 — calling a build that never ran green is the one outcome that must be\n // impossible — and the reason is APPENDED TO THE LOG, so the failure message's pointer still leads to\n // it rather than to an empty file.\n private recordTermination(ended: ShellTerminationDto, fd: number): BuildTermination {\n if (ended.startError !== null) {\n fs.writeSync(fd, `\\nThe build command could not be started: ${ended.startError}\\n`);\n return new BuildTermination(1, null);\n }\n const termination = new BuildTermination(ended.code, ended.signal);\n if (ended.code === null || ended.signal !== null)\n fs.writeSync(fd, `\\n${this.terminationRecord(termination)}\\n`);\n return termination;\n }\n\n /** One stable, human-readable spelling shared by the FullLog and the immediate failure output. */\n private terminationRecord(termination: BuildTermination): string {\n const code = termination.code === null ? 'null' : String(termination.code);\n const signal = termination.signal === null ? 'none' : termination.signal;\n return `Build process termination: exit code ${code}; signal ${signal}.`;\n }\n\n private async resolvePath(repoRoot: string, stage: string): Promise<string> {\n return this.files.logsPath(repoRoot, await this.fileNameFor(repoRoot, stage));\n }\n\n // Anything that is not a filename-safe character becomes '-', so `dean/feat` cannot create directories.\n private slug(value: string): string {\n return value.replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '');\n }\n\n // One local git read. Fails SOFT to '' — a missing branch/sha degrades the FILENAME, and degrading a\n // filename may never be the reason a build gate does not run.\n private async gitOut(repoRoot: string, args: string[]): Promise<string> {\n const result = await this.git.run(['-C', repoRoot, ...args]);\n if (!result.ok) return '';\n return result.stdout.trim();\n }\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import { BuildAffected } from './build-affected';
2
+ import { DevDeployRefs } from './dev-deploy-refs';
3
+ /** The example printed when the key is missing. An example, never a fallback: nothing ever RUNS it. */
4
+ export declare const EXAMPLE_DEV_BUILD_COMMAND = "pnpm nx affected --target=ci --base=origin/dev --head=HEAD";
5
+ /**
6
+ * The dev-scoped build (#1397): `commands.push-dev.buildCommand`, run through the SAME build gate as
7
+ * `wp-build` and the PR gate (`BuildAffected.runBuildGateWith`) — one log-file capture, one heartbeat, one
8
+ * ledger row pair, one failure rendering. Only the command and the log name (`build-dev.log`) differ.
9
+ *
10
+ * WHY A SECOND COMMAND AND NOT `commands.pr-gate.buildCommand`: the PR gate builds what this branch
11
+ * changes against `main`. Before a dev publish the question is different — does this copy build once it is
12
+ * merged with what is ALREADY on `dev` — and the cheap way to answer it builds only what differs from
13
+ * `origin/dev`. The two are different builds, so they are two keys.
14
+ *
15
+ * NO DEFAULT, deliberately (`.claude/rules/no-rule-defaults.md`): which build vouches for a dev publish is
16
+ * the consumer's decision. Missing ⇒ the command refuses before it touches anything, naming the key and
17
+ * printing the entry to paste.
18
+ */
19
+ export declare class DevBuild {
20
+ private readonly buildAffected;
21
+ private readonly refs;
22
+ constructor(buildAffected: BuildAffected, refs: DevDeployRefs);
23
+ /** The configured command, or the refusal naming the key. Called BEFORE any git write, so it fails fast. */
24
+ command(repoRoot: string): string;
25
+ /**
26
+ * Run the dev build on the CURRENT checkout. Throws CliExitError on a red build, with the `FullLog :`
27
+ * pointer, exactly like `wp-build`. `rerunCommand` is what the failure text tells the reader to run
28
+ * after fixing it.
29
+ */
30
+ run(repoRoot: string, rerunCommand: string): Promise<void>;
31
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DevBuild = exports.EXAMPLE_DEV_BUILD_COMMAND = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const rules_config_1 = require("@webpieces/rules-config");
6
+ const inversify_1 = require("inversify");
7
+ const build_affected_1 = require("./build-affected");
8
+ const build_gate_log_1 = require("./build-gate-log");
9
+ const dev_deploy_refs_1 = require("./dev-deploy-refs");
10
+ const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
11
+ /** The example printed when the key is missing. An example, never a fallback: nothing ever RUNS it. */
12
+ exports.EXAMPLE_DEV_BUILD_COMMAND = 'pnpm nx affected --target=ci --base=origin/dev --head=HEAD';
13
+ /**
14
+ * The dev-scoped build (#1397): `commands.push-dev.buildCommand`, run through the SAME build gate as
15
+ * `wp-build` and the PR gate (`BuildAffected.runBuildGateWith`) — one log-file capture, one heartbeat, one
16
+ * ledger row pair, one failure rendering. Only the command and the log name (`build-dev.log`) differ.
17
+ *
18
+ * WHY A SECOND COMMAND AND NOT `commands.pr-gate.buildCommand`: the PR gate builds what this branch
19
+ * changes against `main`. Before a dev publish the question is different — does this copy build once it is
20
+ * merged with what is ALREADY on `dev` — and the cheap way to answer it builds only what differs from
21
+ * `origin/dev`. The two are different builds, so they are two keys.
22
+ *
23
+ * NO DEFAULT, deliberately (`.claude/rules/no-rule-defaults.md`): which build vouches for a dev publish is
24
+ * the consumer's decision. Missing ⇒ the command refuses before it touches anything, naming the key and
25
+ * printing the entry to paste.
26
+ */
27
+ let DevBuild = class DevBuild {
28
+ buildAffected;
29
+ refs;
30
+ constructor(buildAffected, refs) {
31
+ this.buildAffected = buildAffected;
32
+ this.refs = refs;
33
+ }
34
+ /** The configured command, or the refusal naming the key. Called BEFORE any git write, so it fails fast. */
35
+ command(repoRoot) {
36
+ const configured = this.refs.devBuildCommand(repoRoot);
37
+ if (configured !== undefined && configured.trim() !== '')
38
+ return configured;
39
+ throw new rules_config_1.CliExitError(2, '\n' + SEP + '⛔ `commands.push-dev.buildCommand` is not configured\n' + SEP + '\n'
40
+ + `${rules_config_1.WP_PUSH_DEV} builds your copy merged with origin/dev before it publishes, and ${rules_config_1.WP_BUILD_DEV}\n`
41
+ + 'runs that build on its own. WHICH build is this repo\'s decision, so there is no default.\n'
42
+ + 'Nothing was merged, built or published.\n\n'
43
+ + 'Add this to webpieces.config.json, inside "commands", choosing a command that builds only what\n'
44
+ + 'differs from origin/dev in this repo:\n\n'
45
+ + ` "push-dev": { "buildCommand": "${exports.EXAMPLE_DEV_BUILD_COMMAND}" }\n`);
46
+ }
47
+ /**
48
+ * Run the dev build on the CURRENT checkout. Throws CliExitError on a red build, with the `FullLog :`
49
+ * pointer, exactly like `wp-build`. `rerunCommand` is what the failure text tells the reader to run
50
+ * after fixing it.
51
+ */
52
+ run(repoRoot, rerunCommand) {
53
+ const command = this.command(repoRoot);
54
+ return this.buildAffected.runBuildGateWith(repoRoot, command, new build_affected_1.BuildGateOptions('🛠️ dev build (commands.push-dev.buildCommand)', rerunCommand, 'Dev build failed — nothing was published.', build_gate_log_1.DEV_BUILD_STAGE));
55
+ }
56
+ };
57
+ exports.DevBuild = DevBuild;
58
+ exports.DevBuild = DevBuild = tslib_1.__decorate([
59
+ (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
60
+ tslib_1.__metadata("design:paramtypes", [build_affected_1.BuildAffected,
61
+ dev_deploy_refs_1.DevDeployRefs])
62
+ ], DevBuild);
63
+ //# sourceMappingURL=dev-build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-build.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/dev-build.ts"],"names":[],"mappings":";;;;AAAA,0DAAkF;AAClF,yCAA2D;AAE3D,qDAAmE;AACnE,qDAAmD;AACnD,uDAAkD;AAElD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,uGAAuG;AAC1F,QAAA,yBAAyB,GAAG,4DAA4D,CAAC;AAEtG;;;;;;;;;;;;;GAaG;AAEI,IAAM,QAAQ,GAAd,MAAM,QAAQ;IAEI;IACA;IAFrB,YACqB,aAA4B,EAC5B,IAAmB;QADnB,kBAAa,GAAb,aAAa,CAAe;QAC5B,SAAI,GAAJ,IAAI,CAAe;IACrC,CAAC;IAEJ,4GAA4G;IAC5G,OAAO,CAAC,QAAgB;QACpB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,OAAO,UAAU,CAAC;QAC5E,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,IAAI,GAAG,GAAG,GAAG,wDAAwD,GAAG,GAAG,GAAG,IAAI;cAChF,GAAG,0BAAW,qEAAqE,2BAAY,IAAI;cACnG,6FAA6F;cAC7F,6CAA6C;cAC7C,kGAAkG;cAClG,2CAA2C;cAC3C,oCAAoC,iCAAyB,OAAO,CAAC,CAAC;IAChF,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,QAAgB,EAAE,YAAoB;QACtC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,iCAAgB,CAC9E,iDAAiD,EACjD,YAAY,EACZ,2CAA2C,EAC3C,gCAAe,CAClB,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AAlCY,4BAAQ;mBAAR,QAAQ;IADpB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGD,8BAAa;QACtB,+BAAa;GAH/B,QAAQ,CAkCpB","sourcesContent":["import { CliExitError, WP_BUILD_DEV, WP_PUSH_DEV } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { BuildAffected, BuildGateOptions } from './build-affected';\nimport { DEV_BUILD_STAGE } from './build-gate-log';\nimport { DevDeployRefs } from './dev-deploy-refs';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/** The example printed when the key is missing. An example, never a fallback: nothing ever RUNS it. */\nexport const EXAMPLE_DEV_BUILD_COMMAND = 'pnpm nx affected --target=ci --base=origin/dev --head=HEAD';\n\n/**\n * The dev-scoped build (#1397): `commands.push-dev.buildCommand`, run through the SAME build gate as\n * `wp-build` and the PR gate (`BuildAffected.runBuildGateWith`) — one log-file capture, one heartbeat, one\n * ledger row pair, one failure rendering. Only the command and the log name (`build-dev.log`) differ.\n *\n * WHY A SECOND COMMAND AND NOT `commands.pr-gate.buildCommand`: the PR gate builds what this branch\n * changes against `main`. Before a dev publish the question is different — does this copy build once it is\n * merged with what is ALREADY on `dev` — and the cheap way to answer it builds only what differs from\n * `origin/dev`. The two are different builds, so they are two keys.\n *\n * NO DEFAULT, deliberately (`.claude/rules/no-rule-defaults.md`): which build vouches for a dev publish is\n * the consumer's decision. Missing ⇒ the command refuses before it touches anything, naming the key and\n * printing the entry to paste.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class DevBuild {\n constructor(\n private readonly buildAffected: BuildAffected,\n private readonly refs: DevDeployRefs,\n ) {}\n\n /** The configured command, or the refusal naming the key. Called BEFORE any git write, so it fails fast. */\n command(repoRoot: string): string {\n const configured = this.refs.devBuildCommand(repoRoot);\n if (configured !== undefined && configured.trim() !== '') return configured;\n throw new CliExitError(2,\n '\\n' + SEP + '⛔ `commands.push-dev.buildCommand` is not configured\\n' + SEP + '\\n'\n + `${WP_PUSH_DEV} builds your copy merged with origin/dev before it publishes, and ${WP_BUILD_DEV}\\n`\n + 'runs that build on its own. WHICH build is this repo\\'s decision, so there is no default.\\n'\n + 'Nothing was merged, built or published.\\n\\n'\n + 'Add this to webpieces.config.json, inside \"commands\", choosing a command that builds only what\\n'\n + 'differs from origin/dev in this repo:\\n\\n'\n + ` \"push-dev\": { \"buildCommand\": \"${EXAMPLE_DEV_BUILD_COMMAND}\" }\\n`);\n }\n\n /**\n * Run the dev build on the CURRENT checkout. Throws CliExitError on a red build, with the `FullLog :`\n * pointer, exactly like `wp-build`. `rerunCommand` is what the failure text tells the reader to run\n * after fixing it.\n */\n run(repoRoot: string, rerunCommand: string): Promise<void> {\n const command = this.command(repoRoot);\n return this.buildAffected.runBuildGateWith(repoRoot, command, new BuildGateOptions(\n '🛠️ dev build (commands.push-dev.buildCommand)',\n rerunCommand,\n 'Dev build failed — nothing was published.',\n DEV_BUILD_STAGE,\n ));\n }\n}\n"]}
@@ -0,0 +1,49 @@
1
+ import { NativeProcessApi } from '@webpieces/tooling-common';
2
+ import { GitExec } from './git-exec';
3
+ /**
4
+ * How much of one dev copy is already on `origin/main`. Data-only per CLAUDE.md.
5
+ *
6
+ * `changed` is every file the copy changes relative to its merge-base with `origin/main`; `landed` is the
7
+ * subset whose content on `origin/main` is now identical to the copy's.
8
+ */
9
+ export declare class DevCopyLanding {
10
+ readonly changed: string[];
11
+ readonly landed: string[];
12
+ constructor(changed: string[], landed: string[]);
13
+ /** Every file the copy changes already has the copy's content on main — removing it takes nothing off dev. */
14
+ fullyOnMain(): boolean;
15
+ /** Some, but not all, of the copy's files are already on main. */
16
+ partlyOnMain(): boolean;
17
+ }
18
+ /** The merged PR a copy's branch landed through, for the refusal message. Data-only. */
19
+ export declare class MergedPr {
20
+ readonly num: string;
21
+ readonly mergedAt: string;
22
+ constructor(num: string, mergedAt: string);
23
+ }
24
+ /**
25
+ * Answers "is this dev copy already on `origin/main`?" for `wp-push-dev --remove` (#1401).
26
+ *
27
+ * WHY: developers ran `--remove` after their PR landed, as a "done, clean up" habit. On a repo that composes
28
+ * `dev` = `origin/main` + every copy, that remove takes nothing off dev (main keeps the change there) and
29
+ * still triggers a full recompose that can redeploy every service. Only rolling back a copy that broke dev is
30
+ * a real reason to remove.
31
+ *
32
+ * HOW: a pure content check, no GitHub dependency. The files the copy changes since its merge-base with
33
+ * `origin/main` (`git diff A...B`), minus the files where `origin/main` and the copy still differ
34
+ * (`git diff A B`), are the files already landed. Both refs must already be fetched. `--no-renames` so a
35
+ * rename counts both its old and new path rather than hiding the deletion.
36
+ */
37
+ export declare class DevCopyOnMain {
38
+ private readonly gitExec;
39
+ private readonly processes;
40
+ constructor(gitExec: GitExec, processes: NativeProcessApi);
41
+ landing(repoRoot: string, copyRef: string): Promise<DevCopyLanding>;
42
+ /**
43
+ * The merged PR whose head was `branch`, or null. It only decorates the refusal message, so a `gh` that
44
+ * is missing, unauthenticated or offline yields null rather than an error: the content check above has
45
+ * already decided.
46
+ */
47
+ mergedPr(repoRoot: string, branch: string): Promise<MergedPr | null>;
48
+ private names;
49
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DevCopyOnMain = exports.MergedPr = exports.DevCopyLanding = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const tooling_common_1 = require("@webpieces/tooling-common");
6
+ const inversify_1 = require("inversify");
7
+ const git_exec_1 = require("./git-exec");
8
+ const MAIN_REF = 'refs/remotes/origin/main';
9
+ /**
10
+ * How much of one dev copy is already on `origin/main`. Data-only per CLAUDE.md.
11
+ *
12
+ * `changed` is every file the copy changes relative to its merge-base with `origin/main`; `landed` is the
13
+ * subset whose content on `origin/main` is now identical to the copy's.
14
+ */
15
+ class DevCopyLanding {
16
+ changed;
17
+ landed;
18
+ constructor(changed, landed) {
19
+ this.changed = changed;
20
+ this.landed = landed;
21
+ }
22
+ /** Every file the copy changes already has the copy's content on main — removing it takes nothing off dev. */
23
+ fullyOnMain() {
24
+ return this.landed.length === this.changed.length;
25
+ }
26
+ /** Some, but not all, of the copy's files are already on main. */
27
+ partlyOnMain() {
28
+ return this.landed.length > 0 && !this.fullyOnMain();
29
+ }
30
+ }
31
+ exports.DevCopyLanding = DevCopyLanding;
32
+ /** The merged PR a copy's branch landed through, for the refusal message. Data-only. */
33
+ class MergedPr {
34
+ num;
35
+ mergedAt;
36
+ constructor(num, mergedAt) {
37
+ this.num = num;
38
+ this.mergedAt = mergedAt;
39
+ }
40
+ }
41
+ exports.MergedPr = MergedPr;
42
+ // `<number> <mergedAt>` as the --jq below prints it; an empty list prints `null null`, which does not match.
43
+ const PR_LINE = /^(\d+) (\S+)$/;
44
+ /**
45
+ * Answers "is this dev copy already on `origin/main`?" for `wp-push-dev --remove` (#1401).
46
+ *
47
+ * WHY: developers ran `--remove` after their PR landed, as a "done, clean up" habit. On a repo that composes
48
+ * `dev` = `origin/main` + every copy, that remove takes nothing off dev (main keeps the change there) and
49
+ * still triggers a full recompose that can redeploy every service. Only rolling back a copy that broke dev is
50
+ * a real reason to remove.
51
+ *
52
+ * HOW: a pure content check, no GitHub dependency. The files the copy changes since its merge-base with
53
+ * `origin/main` (`git diff A...B`), minus the files where `origin/main` and the copy still differ
54
+ * (`git diff A B`), are the files already landed. Both refs must already be fetched. `--no-renames` so a
55
+ * rename counts both its old and new path rather than hiding the deletion.
56
+ */
57
+ let DevCopyOnMain = class DevCopyOnMain {
58
+ gitExec;
59
+ processes;
60
+ constructor(gitExec, processes) {
61
+ this.gitExec = gitExec;
62
+ this.processes = processes;
63
+ }
64
+ async landing(repoRoot, copyRef) {
65
+ const copy = `refs/remotes/origin/${copyRef}`;
66
+ const changed = await this.names(repoRoot, [`${MAIN_REF}...${copy}`], `Failed to list the files ${copyRef} changes since its merge-base with origin/main (git diff ${MAIN_REF}...${copy}). Nothing was removed.`);
67
+ const stillDiffer = new Set(await this.names(repoRoot, [MAIN_REF, copy], `Failed to compare ${copyRef} with origin/main (git diff ${MAIN_REF} ${copy}). Nothing was removed.`));
68
+ const landed = changed.filter((f) => !stillDiffer.has(f));
69
+ return new DevCopyLanding(changed, landed);
70
+ }
71
+ /**
72
+ * The merged PR whose head was `branch`, or null. It only decorates the refusal message, so a `gh` that
73
+ * is missing, unauthenticated or offline yields null rather than an error: the content check above has
74
+ * already decided.
75
+ */
76
+ async mergedPr(repoRoot, branch) {
77
+ const result = await this.processes.run('gh', [
78
+ 'pr', 'list', '--head', branch, '--state', 'merged', '--limit', '1',
79
+ '--json', 'number,mergedAt', '--jq', '.[0] | "\\(.number) \\(.mergedAt)"',
80
+ ], repoRoot);
81
+ if (!result.ok)
82
+ return null;
83
+ const match = PR_LINE.exec(result.stdout.trim());
84
+ if (match === null)
85
+ return null;
86
+ return new MergedPr(match[1], match[2]);
87
+ }
88
+ async names(repoRoot, revs, failMsg) {
89
+ const out = await this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--no-renames', ...revs], repoRoot, failMsg);
90
+ return out.split('\n').map((l) => l.trim()).filter((l) => l !== '');
91
+ }
92
+ };
93
+ exports.DevCopyOnMain = DevCopyOnMain;
94
+ exports.DevCopyOnMain = DevCopyOnMain = tslib_1.__decorate([
95
+ (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
96
+ tslib_1.__metadata("design:paramtypes", [git_exec_1.GitExec,
97
+ tooling_common_1.NativeProcessApi])
98
+ ], DevCopyOnMain);
99
+ //# sourceMappingURL=dev-copy-on-main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-copy-on-main.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/dev-copy-on-main.ts"],"names":[],"mappings":";;;;AAAA,8DAA6D;AAC7D,yCAA2D;AAE3D,yCAAqC;AAErC,MA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AAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAS,EAAW,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IACzG,CAAC;CACJ,CAAA;AApCY,sCAAa;wBAAb,aAAa;IADzB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGP,kBAAO;QACL,iCAAgB;GAHvC,aAAa,CAoCzB","sourcesContent":["import { NativeProcessApi } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GitExec } from './git-exec';\n\nconst MAIN_REF = 'refs/remotes/origin/main';\n\n/**\n * How much of one dev copy is already on `origin/main`. Data-only per CLAUDE.md.\n *\n * `changed` is every file the copy changes relative to its merge-base with `origin/main`; `landed` is the\n * subset whose content on `origin/main` is now identical to the copy's.\n */\nexport class DevCopyLanding {\n constructor(\n readonly changed: string[],\n readonly landed: string[],\n ) {}\n\n /** Every file the copy changes already has the copy's content on main — removing it takes nothing off dev. */\n fullyOnMain(): boolean {\n return this.landed.length === this.changed.length;\n }\n\n /** Some, but not all, of the copy's files are already on main. */\n partlyOnMain(): boolean {\n return this.landed.length > 0 && !this.fullyOnMain();\n }\n}\n\n/** The merged PR a copy's branch landed through, for the refusal message. Data-only. */\nexport class MergedPr {\n constructor(\n readonly num: string,\n readonly mergedAt: string,\n ) {}\n}\n\n// `<number> <mergedAt>` as the --jq below prints it; an empty list prints `null null`, which does not match.\nconst PR_LINE = /^(\\d+) (\\S+)$/;\n\n/**\n * Answers \"is this dev copy already on `origin/main`?\" for `wp-push-dev --remove` (#1401).\n *\n * WHY: developers ran `--remove` after their PR landed, as a \"done, clean up\" habit. On a repo that composes\n * `dev` = `origin/main` + every copy, that remove takes nothing off dev (main keeps the change there) and\n * still triggers a full recompose that can redeploy every service. Only rolling back a copy that broke dev is\n * a real reason to remove.\n *\n * HOW: a pure content check, no GitHub dependency. The files the copy changes since its merge-base with\n * `origin/main` (`git diff A...B`), minus the files where `origin/main` and the copy still differ\n * (`git diff A B`), are the files already landed. Both refs must already be fetched. `--no-renames` so a\n * rename counts both its old and new path rather than hiding the deletion.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class DevCopyOnMain {\n constructor(\n private readonly gitExec: GitExec,\n private readonly processes: NativeProcessApi,\n ) {}\n\n async landing(repoRoot: string, copyRef: string): Promise<DevCopyLanding> {\n const copy = `refs/remotes/origin/${copyRef}`;\n const changed = await this.names(repoRoot, [`${MAIN_REF}...${copy}`],\n `Failed to list the files ${copyRef} changes since its merge-base with origin/main (git diff ${MAIN_REF}...${copy}). Nothing was removed.`);\n const stillDiffer = new Set(await this.names(repoRoot, [MAIN_REF, copy],\n `Failed to compare ${copyRef} with origin/main (git diff ${MAIN_REF} ${copy}). Nothing was removed.`));\n const landed = changed.filter((f: string): boolean => !stillDiffer.has(f));\n return new DevCopyLanding(changed, landed);\n }\n\n /**\n * The merged PR whose head was `branch`, or null. It only decorates the refusal message, so a `gh` that\n * is missing, unauthenticated or offline yields null rather than an error: the content check above has\n * already decided.\n */\n async mergedPr(repoRoot: string, branch: string): Promise<MergedPr | null> {\n const result = await this.processes.run('gh', [\n 'pr', 'list', '--head', branch, '--state', 'merged', '--limit', '1',\n '--json', 'number,mergedAt', '--jq', '.[0] | \"\\\\(.number) \\\\(.mergedAt)\"',\n ], repoRoot);\n if (!result.ok) return null;\n const match = PR_LINE.exec(result.stdout.trim());\n if (match === null) return null;\n return new MergedPr(match[1], match[2]);\n }\n\n private async names(repoRoot: string, revs: string[], failMsg: string): Promise<string[]> {\n const out = await this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--no-renames', ...revs], repoRoot, failMsg);\n return out.split('\\n').map((l: string): string => l.trim()).filter((l: string): boolean => l !== '');\n }\n}\n"]}
@@ -29,6 +29,12 @@ export declare class DevDeployRefs {
29
29
  constructor(gitExec: GitExec);
30
30
  /** The `pr-gate.devDeploy` block — `dev-include` / `dev` / `dev-remove` unless the consumer overrode it. */
31
31
  config(repoRoot: string): DevDeployConfig;
32
+ /**
33
+ * `commands.push-dev.buildCommand`, or `undefined` when the consumer has not configured it. There is
34
+ * no default (#1397, `.claude/rules/no-rule-defaults.md`); DevBuild turns `undefined` into the refusal
35
+ * that names the key.
36
+ */
37
+ devBuildCommand(repoRoot: string): string | undefined;
32
38
  /** The checked-out branch name, or `'HEAD'` on a detached HEAD (which {@link assertPushable} refuses). */
33
39
  currentBranch(repoRoot: string): string;
34
40
  /**
@@ -77,7 +83,12 @@ export declare class DevDeployRefs {
77
83
  * stale refs rehearses a composition CI will not build.
78
84
  */
79
85
  fetchCopies(repoRoot: string, refs: string[]): Promise<void>;
80
- /** How many commits `origin/<ref>` has that `HEAD` does not — the clobber signal. 0 = safe to publish. */
81
- commitsOnlyOnRemote(repoRoot: string, ref: string): Promise<number>;
86
+ /**
87
+ * The subject of every commit `origin/<ref>` has that `HEAD` does not — the clobber signal. Empty =
88
+ * safe to publish. Subjects rather than a count, because a commit this flow wrote itself (a recorded
89
+ * conflict resolution, see DevResolveRunner) is re-derived by the next publish's check against dev and
90
+ * is therefore safe to replace, while anything else on the copy is somebody's work.
91
+ */
92
+ subjectsOnlyOnRemote(repoRoot: string, ref: string): Promise<string[]>;
82
93
  private refusal;
83
94
  }
@@ -47,6 +47,14 @@ let DevDeployRefs = class DevDeployRefs {
47
47
  config(repoRoot) {
48
48
  return (0, rules_config_1.loadAndValidate)(repoRoot).prGate.devDeploy;
49
49
  }
50
+ /**
51
+ * `commands.push-dev.buildCommand`, or `undefined` when the consumer has not configured it. There is
52
+ * no default (#1397, `.claude/rules/no-rule-defaults.md`); DevBuild turns `undefined` into the refusal
53
+ * that names the key.
54
+ */
55
+ devBuildCommand(repoRoot) {
56
+ return (0, rules_config_1.loadAndValidate)(repoRoot).commands.pushDev.buildCommand;
57
+ }
50
58
  /** The checked-out branch name, or `'HEAD'` on a detached HEAD (which {@link assertPushable} refuses). */
51
59
  currentBranch(repoRoot) {
52
60
  return tooling_common_1.gitCheckout.requireBranch(repoRoot);
@@ -148,11 +156,15 @@ let DevDeployRefs = class DevDeployRefs {
148
156
  const specs = refs.map((r) => `+refs/heads/${r}:refs/remotes/origin/${r}`);
149
157
  await this.gitExec.runGitChecked(['-C', repoRoot, 'fetch', 'origin', ...specs], 'Failed to fetch the dev copy refs from origin');
150
158
  }
151
- /** How many commits `origin/<ref>` has that `HEAD` does not — the clobber signal. 0 = safe to publish. */
152
- async commitsOnlyOnRemote(repoRoot, ref) {
153
- const out = await this.gitExec.gitQuery(['rev-list', '--count', `HEAD..refs/remotes/origin/${ref}`], repoRoot, `Failed to compare HEAD against origin/${ref} (git rev-list --count).`);
154
- const count = Number(out);
155
- return Number.isInteger(count) ? count : 0;
159
+ /**
160
+ * The subject of every commit `origin/<ref>` has that `HEAD` does not — the clobber signal. Empty =
161
+ * safe to publish. Subjects rather than a count, because a commit this flow wrote itself (a recorded
162
+ * conflict resolution, see DevResolveRunner) is re-derived by the next publish's check against dev and
163
+ * is therefore safe to replace, while anything else on the copy is somebody's work.
164
+ */
165
+ async subjectsOnlyOnRemote(repoRoot, ref) {
166
+ const out = await this.gitExec.gitQuery(['log', '--format=%s', `HEAD..refs/remotes/origin/${ref}`], repoRoot, `Failed to compare HEAD against origin/${ref} (git log HEAD..origin/${ref}).`);
167
+ return out.split('\n').filter((l) => l.trim() !== '');
156
168
  }
157
169
  refusal(headline, body) {
158
170
  return '\n' + SEP + `⛔ ${headline}\n` + SEP + '\n' + body + `\nRun \`${rules_config_1.WP_PUSH_DEV} --help\` for the full command.\n`;