@webpieces/agent-workflow-rules 0.4.984 → 0.4.985

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/agent-workflow-rules",
3
- "version": "0.4.984",
3
+ "version": "0.4.985",
4
4
  "description": "Independent workflow guards, guard hook, installation and shim management for AI coding agents.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -24,20 +24,20 @@
24
24
  "directory": "packages/tooling/agent-workflow-rules"
25
25
  },
26
26
  "dependencies": {
27
- "@webpieces/hook-runtime": "0.4.984",
28
- "@webpieces/rules-config": "0.4.984",
27
+ "@webpieces/hook-runtime": "0.4.985",
28
+ "@webpieces/rules-config": "0.4.985",
29
29
  "inversify": "7.10.4",
30
30
  "reflect-metadata": "0.2.2",
31
- "@webpieces/tooling-common": "0.4.984",
32
- "@webpieces/repo-workflow-core": "0.4.984",
31
+ "@webpieces/tooling-common": "0.4.985",
32
+ "@webpieces/repo-workflow-core": "0.4.985",
33
33
  "tslib": "2.8.1",
34
- "@webpieces/rules-sdk": "0.4.984"
34
+ "@webpieces/rules-sdk": "0.4.985"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
39
  "devDependencies": {
40
- "@webpieces/tooling-testkit": "0.4.984"
40
+ "@webpieces/tooling-testkit": "0.4.985"
41
41
  },
42
42
  "types": "./src/index.d.ts",
43
43
  "bin": {
@@ -27,10 +27,11 @@ function fixHintFor(upsertPrCommand) {
27
27
  ' instructs you to write summary.json and run `pnpm wp-finish-upsert-pr`, which assembles the\n' +
28
28
  ' dashboard and creates/updates the PR — and pushes for you. A failing build = no push, no PR.\n\n' +
29
29
  'JUST WANT IT ON THE SHARED DEV SERVER (no PR, not landing on main):\n' +
30
- ` ${rules_config_1.WP_PUSH_DEV}\n` +
31
- ' It publishes a DISPOSABLE copy of your branch that the dev environment composes and rebuilds.\n' +
32
- " Your feature branch is never moved and never acquires another developer's commits, which is\n" +
33
- ' the whole reason the copy exists. Do NOT open a PR to main just to test something in dev.\n\n' +
30
+ ` ${rules_config_1.WP_START_PUSH_DEV} → ${rules_config_1.WP_BUILD_PUSH_DEV} → ${rules_config_1.WP_FINISH_PUSH_DEV}\n` +
31
+ ' Brings your branch up to date with main, checks and builds it against dev on a throwaway merge,\n' +
32
+ ' then publishes a DISPOSABLE copy of it that the dev environment composes and deploys. Your\n' +
33
+ " feature branch never acquires another developer's commits, which is the whole reason the copy\n" +
34
+ ' exists. Do NOT open a PR to main just to test something in dev.\n\n' +
34
35
  'ON A /hotfix/ BRANCH (cut from the production sha, so it must NOT take main):\n' +
35
36
  ' pnpm wp-upsert-hotfix-pr\n' +
36
37
  ' One command: hotfix-ci (build + test), no merge from main, one fast-forward push, then it\n' +
@@ -80,7 +81,7 @@ function truncate(s) {
80
81
  *
81
82
  * The refspec is the one place the AI already stated its intent unambiguously, so reading it is strictly
82
83
  * better than making the AI choose between two hints it has no way to disambiguate. A push whose
83
- * destination is the dev namespace or the dev branch itself gets the `wp-push-dev` remedy on the `→`
84
+ * destination is the dev namespace or the dev branch itself gets the dev-deploy (`wp-start-push-dev`) remedy on the `→`
84
85
  * line; everything else keeps the PR-flow remedy it has always had.
85
86
  */
86
87
  // webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file
@@ -124,8 +125,8 @@ class PrCreationOrPushGuardRule extends hook_runtime_2.BashRuleBase {
124
125
  if (this.aimedAtDevEnvironment(ctx)) {
125
126
  return [
126
127
  new hook_runtime_1.Violation(1, truncate(ctx.command), 'Manual push is blocked — but this one is aimed at the shared DEV environment, which has its own\n' +
127
- `gated command. Use \`${rules_config_1.WP_PUSH_DEV}\` (publishes a disposable copy; never moves your branch, never\n` +
128
- `opens a PR). Do NOT use ${this.upsertPrCommand} for this — that lands on main. Full flow: READ ${docPath}.`),
128
+ `gated flow: \`${rules_config_1.WP_START_PUSH_DEV}\` → \`${rules_config_1.WP_BUILD_PUSH_DEV}\` → \`${rules_config_1.WP_FINISH_PUSH_DEV}\` (publishes a\n` +
129
+ `disposable copy; never opens a PR). Do NOT use ${this.upsertPrCommand} for this — that lands on main. Full flow: READ ${docPath}.`),
129
130
  ];
130
131
  }
131
132
  return [
@@ -1 +1 @@
1
- {"version":3,"file":"pr-creation-or-push-guard.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/agent-workflow-rules/src/core/rules/pr-creation-or-push-guard.ts"],"names":[],"mappings":";;;AAAA,0DAAwJ;AACxJ,mDAA2D;AAI3D,0DAAyD;AACzD,0DAAuD;AACvD,0DAAkD;AAElD,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAElD;;;;;;;;;GASG;AACH,mKAAmK;AACnK,SAAS,UAAU,CAAC,eAAuB;IACvC,OAAO,IAAI,sBAAO,CACd,8DAA8D,EAC9D,oGAAoG;QAChG,4BAA4B;QAC5B,mDAAmD;QACnD,KAAK,eAAe,IAAI;QACxB,iGAAiG;QACjG,iGAAiG;QACjG,oGAAoG;QACpG,uEAAuE;QACvE,KAAK,0BAAW,IAAI;QACpB,mGAAmG;QACnG,iGAAiG;QACjG,iGAAiG;QACjG,iFAAiF;QACjF,8BAA8B;QAC9B,+FAA+F;QAC/F,4EAA4E;QAC5E,kGAAkG;QAClG,+FAA+F;QAC/F,6FAA6F;QAC7F,8FAA8F;QAC9F,uEAAuE;QACvE,2HAA2H;QAC3H,yEAAyE,CAChF,CAAC;AACN,CAAC;AAED,kGAAkG;AAClG,mGAAmG;AACnG,mGAAmG;AACnG,yBAAyB;AACzB,mKAAmK;AACnK,SAAS,iBAAiB,CAAC,GAAW;IAClC,yFAAyF;IACzF,IAAI,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAE5C,IAAI,6BAA6B,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAEzD,MAAM,UAAU,GAAG,6BAA6B,CAAC,I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OAAO,GAAG,CAC3M;SACJ,CAAC;IACN,CAAC;IAED;;;;;;OAMG;IACK,qBAAqB,CAAC,GAAgB;QAC1C,MAAM,SAAS,GAAG,IAAA,8BAAe,EAAC,GAAG,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;QACrE,OAAO,qBAAqB,CACxB,GAAG,CAAC,WAAW,EACf,SAAS,CAAC,eAAe,KAAK,EAAE;YAC5B,CAAC,CAAC,2CAA4B;YAC9B,CAAC,CAAC,SAAS,CAAC,eAAe,EAC/B,SAAS,CAAC,SAAS,KAAK,EAAE,CAAC,CAAC,CAAC,iCAAkB,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CACxE,CAAC;IACN,CAAC;CACJ;AAjED,8DAiEC","sourcesContent":["import { DEFAULT_DEV_BRANCH, DEFAULT_DEV_BRANCH_NAMESPACE, RepoRootFinder, WP_PUSH_DEV, loadAndValidate, writeTemplate } from '@webpieces/rules-config';\nimport { PR_LIFECYCLE_GUARD_KEY } from '../../policy-keys';\nimport { PrLifecycleGuardConfig } from \"../../configs/rule-configs\";\n\nimport type { BashContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { BashRuleBase } from '@webpieces/hook-runtime';\nimport { FixHint } from '@webpieces/hook-runtime';\n\nconst INSTRUCT_FILE = 'webpieces.git-workflow.md';\n\n/**\n * The hint BRANCHES ON INTENT, and that is not polish.\n *\n * There are now two legitimate destinations for a blocked push — land it on `main`, or get it onto the\n * shared dev server — and the block alone cannot tell them apart. The old flat hint said \"everything goes\n * through `wp-start-upsert-pr`\", so an AI told \"put my branch on dev\" would try `git push`, get blocked,\n * read this, and open a PR to main: the exact opposite of what it was asked to do, and the destructive\n * direction of the two. Naming both destinations is what makes the dev flow discoverable at all — nothing\n * else the AI can see mentions it.\n */\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction fixHintFor(upsertPrCommand: string): FixHint {\n return new FixHint(\n 'Direct PR creation/update AND manual `git push` are blocked.',\n 'Never push or open/update a PR by hand. There are TWO gated destinations — pick by what you were\\n' +\n 'actually trying to do:\\n\\n' +\n 'LANDING ON MAIN (a PR, prod-quality, reviewed):\\n' +\n ` ${upsertPrCommand}\\n` +\n ' It updates the branch from main (3-point merge) and runs the real build (nx affected), then\\n' +\n ' instructs you to write summary.json and run `pnpm wp-finish-upsert-pr`, which assembles the\\n' +\n ' dashboard and creates/updates the PR — and pushes for you. A failing build = no push, no PR.\\n\\n' +\n 'JUST WANT IT ON THE SHARED DEV SERVER (no PR, not landing on main):\\n' +\n ` ${WP_PUSH_DEV}\\n` +\n ' It publishes a DISPOSABLE copy of your branch that the dev environment composes and rebuilds.\\n' +\n \" Your feature branch is never moved and never acquires another developer's commits, which is\\n\" +\n ' the whole reason the copy exists. Do NOT open a PR to main just to test something in dev.\\n\\n' +\n 'ON A /hotfix/ BRANCH (cut from the production sha, so it must NOT take main):\\n' +\n ' pnpm wp-upsert-hotfix-pr\\n' +\n ' One command: hotfix-ci (build + test), no merge from main, one fast-forward push, then it\\n' +\n ' creates or updates the bannered PR to main and never auto-merges it.\\n\\n' +\n 'All of them push internally as child processes this hook never sees, so the gated commands are\\n' +\n 'unaffected by this guard. There is nothing to paste or attest to; the commands do the work.\\n' +\n 'A HUMAN who has personally inspected the work may run `pnpm wp-human-post-pr` themselves.\\n' +\n 'That is an interactive human attestation and visibly skips automated build/review. AI must\\n' +\n \"never run it for the human or answer `human` on the human's behalf.\\n\" +\n 'Full branch → update → PR flow: READ the instruct-ai git-workflow doc at the absolute path on the violation line above.\\n' +\n \"Add this to your memory so you don't forget next time and waste tokens.\",\n );\n}\n\n// Detect every way an agent could push or open/update a PR directly, so the ONLY path left is the\n// gated flow (wp-start-upsert-pr → wp-finish-upsert-pr, whose internal `git push` / `gh pr create`\n// run as child processes the hook never sees). Read-only `gh pr list` / `gh api .../pulls` GET are\n// intentionally allowed.\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction isBlockedPrOrPush(cmd: string): boolean {\n // A manual push is always blocked — the gated flow pushes for you behind the build gate.\n if (/\\bgit\\s+push\\b/.test(cmd)) return true;\n\n if (/\\bgh\\s+pr\\s+(create|edit)\\b/.test(cmd)) return true;\n\n const ghApiPulls = /\\bgh\\s+api\\b[^\\n]*\\/pulls\\b/.test(cmd);\n if (\n ghApiPulls &&\n (/--method\\s+POST/i.test(cmd) ||\n /-X\\s+POST/i.test(cmd) ||\n /\\s-f\\b/.test(cmd) ||\n /\\s-F\\b/.test(cmd) ||\n /--field\\b/.test(cmd))\n ) {\n return true;\n }\n\n const curlPulls = /\\bcurl\\b[^\\n]*api\\.github\\.com[^\\n]*\\/pulls\\b/.test(cmd);\n if (\n curlPulls &&\n (/-X\\s*POST/i.test(cmd) || /--request\\s+POST/i.test(cmd) || /(\\s-d\\b|--data\\b)/.test(cmd))\n ) {\n return true;\n }\n return false;\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction truncate(s: string): string {\n const MAX = 120;\n return s.length <= MAX ? s : s.slice(0, MAX) + '…';\n}\n\n/**\n * Does this blocked push AIM at the shared dev environment?\n *\n * The refspec is the one place the AI already stated its intent unambiguously, so reading it is strictly\n * better than making the AI choose between two hints it has no way to disambiguate. A push whose\n * destination is the dev namespace or the dev branch itself gets the `wp-push-dev` remedy on the `→`\n * line; everything else keeps the PR-flow remedy it has always had.\n */\n// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file\nfunction targetsDevEnvironment(cmd: string, namespace: string, devBranch: string): boolean {\n if (cmd.includes(`${namespace}/`)) return true;\n const push = /\\bgit\\s+push\\b([^\\n;&|]*)/.exec(cmd);\n if (push === null) return false;\n // Split on whitespace AND `:` so both halves of a `HEAD:<dest>` refspec are examined. Matching whole\n // tokens (never a substring) keeps a branch merely NAMED `develop` from reading as the dev branch.\n return push[1]\n .split(/[\\s:]+/)\n .some(\n (token: string): boolean => token === devBranch || token === `refs/heads/${devBranch}`,\n );\n}\n\nexport class PrCreationOrPushGuardRule extends BashRuleBase<PrLifecycleGuardConfig> {\n /**\n * The gated command this guard names, handed in by the LOADER from `commands.guardHints\n * .prCreationOrPush` (already defaulted there). It is a constructor parameter, not a config field:\n * the field `pr-creation-or-push-guard.upsertPrCommand` was a SECOND SPELLING that beat the\n * commands section at the point of use, and the loader's name-keyed injection that fed it could\n * miss a rename without failing the build. One spelling, wired at compile time.\n */\n private readonly upsertPrCommand: string;\n\n constructor(config: PrLifecycleGuardConfig, upsertPrCommand: string) {\n super(config, 'pr-creation-or-push-guard', PR_LIFECYCLE_GUARD_KEY);\n this.upsertPrCommand = upsertPrCommand;\n }\n\n readonly description =\n 'Block manual `git push` and direct PR creation/edit so AI uses the gated flow; a human may personally use the interactive wp-human-post-pr escape hatch.';\n get fixHint(): FixHint {\n return fixHintFor(this.upsertPrCommand);\n }\n\n check(ctx: BashContext): readonly Violation[] {\n if (!isBlockedPrOrPush(ctx.commandCode)) return [];\n // Materialize the doc we are about to send the AI to. Pointing at a path that does not exist\n // (nothing has run a `wp-*` command in this tree yet) costs the AI a turn to discover; a STALE\n // copy from an older @webpieces is just as bad, so overwrite rather than write-if-missing.\n writeTemplate(ctx.workspaceRoot, INSTRUCT_FILE);\n const docPath = new RepoRootFinder().instructAiDocPath(ctx.workspaceRoot, INSTRUCT_FILE);\n if (this.aimedAtDevEnvironment(ctx)) {\n return [\n new V(\n 1,\n truncate(ctx.command),\n 'Manual push is blocked — but this one is aimed at the shared DEV environment, which has its own\\n' +\n `gated command. Use \\`${WP_PUSH_DEV}\\` (publishes a disposable copy; never moves your branch, never\\n` +\n `opens a PR). Do NOT use ${this.upsertPrCommand} for this — that lands on main. Full flow: READ ${docPath}.`,\n ),\n ];\n }\n return [\n new V(\n 1,\n truncate(ctx.command),\n `Manual push / direct PR is blocked — AI uses the gated flow (${this.upsertPrCommand}). A human may personally run pnpm wp-human-post-pr; AI never answers its attestation. Full flow: READ ${docPath}.`,\n ),\n ];\n }\n\n /**\n * Read the configured dev refs, falling back to the defaults when this repo has no `pr-gate` section\n * at all (a consumer that has not adopted the gate still gets a correct hint for the default names).\n *\n * Calling the loader here is safe by construction: an INVALID config blocks every Bash call long\n * before a rule runs, so reaching this line already means the config loaded.\n */\n private aimedAtDevEnvironment(ctx: BashContext): boolean {\n const devDeploy = loadAndValidate(ctx.governedRoot).prGate.devDeploy;\n return targetsDevEnvironment(\n ctx.commandCode,\n devDeploy.branchNamespace === ''\n ? DEFAULT_DEV_BRANCH_NAMESPACE\n : devDeploy.branchNamespace,\n devDeploy.devBranch === '' ? DEFAULT_DEV_BRANCH : devDeploy.devBranch,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"pr-creation-or-push-guard.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/agent-workflow-rules/src/core/rules/pr-creation-or-push-guard.ts"],"names":[],"mappings":";;;AAAA,0DAAqM;AACrM,mDAA2D;AAI3D,0DAAyD;AACzD,0DAAuD;AACvD,0DAAkD;AAElD,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAElD;;;;;;;;;GASG;AACH,mKAAmK;AACnK,SAAS,UAAU,CAAC,eAAuB;IACvC,OAAO,IAAI,sBAAO,CACd,8DAA8D,EAC9D,oGAAoG;QAChG,4BAA4B;QAC5B,mDAAmD;QACnD,KAAK,eAAe,IAAI;QACxB,iGAAiG;QACjG,iGAAiG;QACjG,oGAAoG;QACpG,uEAAuE;QACvE,KAAK,gCAAiB,QAAQ,gCAAiB,QAAQ,iCAAkB,IAAI;QAC7E,qGAAqG;QACrG,gGAAgG;QAChG,mGAAmG;QACnG,uEAAuE;QACvE,iFAAiF;QACjF,8BAA8B;QAC9B,+FAA+F;QAC/F,4EAA4E;QAC5E,kGAAkG;QAClG,+FAA+F;QAC/F,6FAA6F;QAC7F,8FAA8F;QAC9F,uEAAuE;QACvE,2HAA2H;QAC3H,yEAAyE,CAChF,CAAC;AAC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AAI,wBAAC,CACD,CAAC,EACD,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EACrB,mGAAmG;oBAC/F,iBAAiB,gCAAiB,UAAU,gCAAiB,UAAU,iCAAkB,mBAAmB;oBAC5G,kDAAkD,IAAI,CAAC,eAAe,mDAAmD,OAAO,GAAG,CAC1I;aACJ,CAAC;QACN,CAAC;QACD,OAAO;YACH,IAAI,wBAAC,CACD,CAAC,EACD,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EACrB,gEAAgE,IAAI,CAAC,eAAe,0GAA0G,OAAO,GAAG,CAC3M;SACJ,CAAC;IACN,CAAC;IAED;;;;;;OAMG;IACK,qBAAqB,CAAC,GAAgB;QAC1C,MAAM,SAAS,GAAG,IAAA,8BAAe,EAAC,GAAG,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;QACrE,OAAO,qBAAqB,CACxB,GAAG,CAAC,WAAW,EACf,SAAS,CAAC,eAAe,KAAK,EAAE;YAC5B,CAAC,CAAC,2CAA4B;YAC9B,CAAC,CAAC,SAAS,CAAC,eAAe,EAC/B,SAAS,CAAC,SAAS,KAAK,EAAE,CAAC,CAAC,CAAC,iCAAkB,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CACxE,CAAC;IACN,CAAC;CACJ;AAjED,8DAiEC","sourcesContent":["import { DEFAULT_DEV_BRANCH, DEFAULT_DEV_BRANCH_NAMESPACE, RepoRootFinder, WP_BUILD_PUSH_DEV, WP_FINISH_PUSH_DEV, WP_START_PUSH_DEV, loadAndValidate, writeTemplate } from '@webpieces/rules-config';\nimport { PR_LIFECYCLE_GUARD_KEY } from '../../policy-keys';\nimport { PrLifecycleGuardConfig } from \"../../configs/rule-configs\";\n\nimport type { BashContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { BashRuleBase } from '@webpieces/hook-runtime';\nimport { FixHint } from '@webpieces/hook-runtime';\n\nconst INSTRUCT_FILE = 'webpieces.git-workflow.md';\n\n/**\n * The hint BRANCHES ON INTENT, and that is not polish.\n *\n * There are now two legitimate destinations for a blocked push — land it on `main`, or get it onto the\n * shared dev server — and the block alone cannot tell them apart. The old flat hint said \"everything goes\n * through `wp-start-upsert-pr`\", so an AI told \"put my branch on dev\" would try `git push`, get blocked,\n * read this, and open a PR to main: the exact opposite of what it was asked to do, and the destructive\n * direction of the two. Naming both destinations is what makes the dev flow discoverable at all — nothing\n * else the AI can see mentions it.\n */\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction fixHintFor(upsertPrCommand: string): FixHint {\n return new FixHint(\n 'Direct PR creation/update AND manual `git push` are blocked.',\n 'Never push or open/update a PR by hand. There are TWO gated destinations — pick by what you were\\n' +\n 'actually trying to do:\\n\\n' +\n 'LANDING ON MAIN (a PR, prod-quality, reviewed):\\n' +\n ` ${upsertPrCommand}\\n` +\n ' It updates the branch from main (3-point merge) and runs the real build (nx affected), then\\n' +\n ' instructs you to write summary.json and run `pnpm wp-finish-upsert-pr`, which assembles the\\n' +\n ' dashboard and creates/updates the PR — and pushes for you. A failing build = no push, no PR.\\n\\n' +\n 'JUST WANT IT ON THE SHARED DEV SERVER (no PR, not landing on main):\\n' +\n ` ${WP_START_PUSH_DEV} → ${WP_BUILD_PUSH_DEV} → ${WP_FINISH_PUSH_DEV}\\n` +\n ' Brings your branch up to date with main, checks and builds it against dev on a throwaway merge,\\n' +\n ' then publishes a DISPOSABLE copy of it that the dev environment composes and deploys. Your\\n' +\n \" feature branch never acquires another developer's commits, which is the whole reason the copy\\n\" +\n ' exists. Do NOT open a PR to main just to test something in dev.\\n\\n' +\n 'ON A /hotfix/ BRANCH (cut from the production sha, so it must NOT take main):\\n' +\n ' pnpm wp-upsert-hotfix-pr\\n' +\n ' One command: hotfix-ci (build + test), no merge from main, one fast-forward push, then it\\n' +\n ' creates or updates the bannered PR to main and never auto-merges it.\\n\\n' +\n 'All of them push internally as child processes this hook never sees, so the gated commands are\\n' +\n 'unaffected by this guard. There is nothing to paste or attest to; the commands do the work.\\n' +\n 'A HUMAN who has personally inspected the work may run `pnpm wp-human-post-pr` themselves.\\n' +\n 'That is an interactive human attestation and visibly skips automated build/review. AI must\\n' +\n \"never run it for the human or answer `human` on the human's behalf.\\n\" +\n 'Full branch → update → PR flow: READ the instruct-ai git-workflow doc at the absolute path on the violation line above.\\n' +\n \"Add this to your memory so you don't forget next time and waste tokens.\",\n );\n}\n\n// Detect every way an agent could push or open/update a PR directly, so the ONLY path left is the\n// gated flow (wp-start-upsert-pr → wp-finish-upsert-pr, whose internal `git push` / `gh pr create`\n// run as child processes the hook never sees). Read-only `gh pr list` / `gh api .../pulls` GET are\n// intentionally allowed.\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction isBlockedPrOrPush(cmd: string): boolean {\n // A manual push is always blocked — the gated flow pushes for you behind the build gate.\n if (/\\bgit\\s+push\\b/.test(cmd)) return true;\n\n if (/\\bgh\\s+pr\\s+(create|edit)\\b/.test(cmd)) return true;\n\n const ghApiPulls = /\\bgh\\s+api\\b[^\\n]*\\/pulls\\b/.test(cmd);\n if (\n ghApiPulls &&\n (/--method\\s+POST/i.test(cmd) ||\n /-X\\s+POST/i.test(cmd) ||\n /\\s-f\\b/.test(cmd) ||\n /\\s-F\\b/.test(cmd) ||\n /--field\\b/.test(cmd))\n ) {\n return true;\n }\n\n const curlPulls = /\\bcurl\\b[^\\n]*api\\.github\\.com[^\\n]*\\/pulls\\b/.test(cmd);\n if (\n curlPulls &&\n (/-X\\s*POST/i.test(cmd) || /--request\\s+POST/i.test(cmd) || /(\\s-d\\b|--data\\b)/.test(cmd))\n ) {\n return true;\n }\n return false;\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction truncate(s: string): string {\n const MAX = 120;\n return s.length <= MAX ? s : s.slice(0, MAX) + '…';\n}\n\n/**\n * Does this blocked push AIM at the shared dev environment?\n *\n * The refspec is the one place the AI already stated its intent unambiguously, so reading it is strictly\n * better than making the AI choose between two hints it has no way to disambiguate. A push whose\n * destination is the dev namespace or the dev branch itself gets the dev-deploy (`wp-start-push-dev`) remedy on the `→`\n * line; everything else keeps the PR-flow remedy it has always had.\n */\n// webpieces-disable no-function-outside-class -- module-level guard helper, matches the rest of this file\nfunction targetsDevEnvironment(cmd: string, namespace: string, devBranch: string): boolean {\n if (cmd.includes(`${namespace}/`)) return true;\n const push = /\\bgit\\s+push\\b([^\\n;&|]*)/.exec(cmd);\n if (push === null) return false;\n // Split on whitespace AND `:` so both halves of a `HEAD:<dest>` refspec are examined. Matching whole\n // tokens (never a substring) keeps a branch merely NAMED `develop` from reading as the dev branch.\n return push[1]\n .split(/[\\s:]+/)\n .some(\n (token: string): boolean => token === devBranch || token === `refs/heads/${devBranch}`,\n );\n}\n\nexport class PrCreationOrPushGuardRule extends BashRuleBase<PrLifecycleGuardConfig> {\n /**\n * The gated command this guard names, handed in by the LOADER from `commands.guardHints\n * .prCreationOrPush` (already defaulted there). It is a constructor parameter, not a config field:\n * the field `pr-creation-or-push-guard.upsertPrCommand` was a SECOND SPELLING that beat the\n * commands section at the point of use, and the loader's name-keyed injection that fed it could\n * miss a rename without failing the build. One spelling, wired at compile time.\n */\n private readonly upsertPrCommand: string;\n\n constructor(config: PrLifecycleGuardConfig, upsertPrCommand: string) {\n super(config, 'pr-creation-or-push-guard', PR_LIFECYCLE_GUARD_KEY);\n this.upsertPrCommand = upsertPrCommand;\n }\n\n readonly description =\n 'Block manual `git push` and direct PR creation/edit so AI uses the gated flow; a human may personally use the interactive wp-human-post-pr escape hatch.';\n get fixHint(): FixHint {\n return fixHintFor(this.upsertPrCommand);\n }\n\n check(ctx: BashContext): readonly Violation[] {\n if (!isBlockedPrOrPush(ctx.commandCode)) return [];\n // Materialize the doc we are about to send the AI to. Pointing at a path that does not exist\n // (nothing has run a `wp-*` command in this tree yet) costs the AI a turn to discover; a STALE\n // copy from an older @webpieces is just as bad, so overwrite rather than write-if-missing.\n writeTemplate(ctx.workspaceRoot, INSTRUCT_FILE);\n const docPath = new RepoRootFinder().instructAiDocPath(ctx.workspaceRoot, INSTRUCT_FILE);\n if (this.aimedAtDevEnvironment(ctx)) {\n return [\n new V(\n 1,\n truncate(ctx.command),\n 'Manual push is blocked — but this one is aimed at the shared DEV environment, which has its own\\n' +\n `gated flow: \\`${WP_START_PUSH_DEV}\\` → \\`${WP_BUILD_PUSH_DEV}\\` → \\`${WP_FINISH_PUSH_DEV}\\` (publishes a\\n` +\n `disposable copy; never opens a PR). Do NOT use ${this.upsertPrCommand} for this — that lands on main. Full flow: READ ${docPath}.`,\n ),\n ];\n }\n return [\n new V(\n 1,\n truncate(ctx.command),\n `Manual push / direct PR is blocked — AI uses the gated flow (${this.upsertPrCommand}). A human may personally run pnpm wp-human-post-pr; AI never answers its attestation. Full flow: READ ${docPath}.`,\n ),\n ];\n }\n\n /**\n * Read the configured dev refs, falling back to the defaults when this repo has no `pr-gate` section\n * at all (a consumer that has not adopted the gate still gets a correct hint for the default names).\n *\n * Calling the loader here is safe by construction: an INVALID config blocks every Bash call long\n * before a rule runs, so reaching this line already means the config loaded.\n */\n private aimedAtDevEnvironment(ctx: BashContext): boolean {\n const devDeploy = loadAndValidate(ctx.governedRoot).prGate.devDeploy;\n return targetsDevEnvironment(\n ctx.commandCode,\n devDeploy.branchNamespace === ''\n ? DEFAULT_DEV_BRANCH_NAMESPACE\n : devDeploy.branchNamespace,\n devDeploy.devBranch === '' ? DEFAULT_DEV_BRANCH : devDeploy.devBranch,\n );\n }\n}\n"]}