@webpieces/ai-hook-rules 0.3.187 → 0.3.189
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/ai-hook-rules",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.189",
|
|
4
4
|
"description": "Pluggable write-time validation framework for AI coding agents (@webpieces/ai-hook-rules). Claude Code PreToolUse + openclaw before_tool_call adapters share one rule engine.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"directory": "packages/tooling/ai-hook-rules"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@webpieces/rules-config": "0.3.
|
|
35
|
+
"@webpieces/rules-config": "0.3.189"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
@@ -2,8 +2,9 @@ import { PrCreationGuardConfig } from '@webpieces/rules-config';
|
|
|
2
2
|
import type { BashContext, Violation } from '../types';
|
|
3
3
|
import { BashRuleBase } from '../rule-base';
|
|
4
4
|
export declare class PrCreationGuardRule extends BashRuleBase<PrCreationGuardConfig> {
|
|
5
|
+
private readonly upsertPrCommand;
|
|
5
6
|
constructor(config: PrCreationGuardConfig);
|
|
6
|
-
readonly description = "Block direct PR creation/edit (gh pr / gh api / curl) so PRs go only through
|
|
7
|
-
|
|
7
|
+
readonly description = "Block direct PR creation/edit (gh pr / gh api / curl) so PRs go only through the gated upsert-pr command.";
|
|
8
|
+
get fixHint(): readonly string[];
|
|
8
9
|
check(ctx: BashContext): readonly Violation[];
|
|
9
10
|
}
|
|
@@ -3,13 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PrCreationGuardRule = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const rule_base_1 = require("../rule-base");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const DEFAULT_UPSERT_PR_COMMAND = 'pnpm wp-upsert-pr';
|
|
7
|
+
function fixHintFor(upsertPrCommand) {
|
|
8
|
+
return [
|
|
9
|
+
'Direct PR creation is blocked. Create or update a PR ONLY via the gated command:',
|
|
10
|
+
` ${upsertPrCommand}`,
|
|
11
|
+
'It updates the branch from main (3-point merge), runs the real build (nx affected), and',
|
|
12
|
+
'assembles the PR dashboard — then creates/updates the PR itself. A failing build = no PR.',
|
|
13
|
+
'There is nothing to paste or attest to; the command does the work.',
|
|
14
|
+
];
|
|
15
|
+
}
|
|
13
16
|
// Detect every way an agent could open/update a PR directly, so the ONLY path left is
|
|
14
17
|
// `pnpm wp-upsert-pr` (whose internal `gh pr create` runs as a child process the hook
|
|
15
18
|
// never sees). Read-only `gh pr list` / `gh api .../pulls` GET are intentionally allowed.
|
|
@@ -31,16 +34,20 @@ function truncate(s) {
|
|
|
31
34
|
return s.length <= MAX ? s : s.slice(0, MAX) + '…';
|
|
32
35
|
}
|
|
33
36
|
class PrCreationGuardRule extends rule_base_1.BashRuleBase {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
upsertPrCommand;
|
|
38
|
+
constructor(config) {
|
|
39
|
+
super(config, 'pr-creation-guard');
|
|
40
|
+
this.upsertPrCommand = config.upsertPrCommand ?? DEFAULT_UPSERT_PR_COMMAND;
|
|
41
|
+
}
|
|
42
|
+
description = 'Block direct PR creation/edit (gh pr / gh api / curl) so PRs go only through the gated upsert-pr command.';
|
|
43
|
+
get fixHint() { return fixHintFor(this.upsertPrCommand); }
|
|
37
44
|
check(ctx) {
|
|
38
45
|
if (!isDirectPrCreation(ctx.command))
|
|
39
46
|
return [];
|
|
40
47
|
return [new types_1.Violation(1, truncate(ctx.command), [
|
|
41
48
|
'Direct PR creation/update is blocked.',
|
|
42
49
|
'Use the gated command instead — it runs the build and builds the dashboard:',
|
|
43
|
-
|
|
50
|
+
` ${this.upsertPrCommand}`,
|
|
44
51
|
].join('\n'))];
|
|
45
52
|
}
|
|
46
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pr-creation-guard.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/pr-creation-guard.ts"],"names":[],"mappings":";;;AAGA,oCAA0C;AAC1C,4CAA4C;AAE5C,MAAM,
|
|
1
|
+
{"version":3,"file":"pr-creation-guard.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/pr-creation-guard.ts"],"names":[],"mappings":";;;AAGA,oCAA0C;AAC1C,4CAA4C;AAE5C,MAAM,yBAAyB,GAAG,mBAAmB,CAAC;AAEtD,SAAS,UAAU,CAAC,eAAuB;IACvC,OAAO;QACH,kFAAkF;QAClF,KAAK,eAAe,EAAE;QACtB,yFAAyF;QACzF,2FAA2F;QAC3F,oEAAoE;KACvE,CAAC;AACN,CAAC;AAED,sFAAsF;AACtF,sFAAsF;AACtF,0FAA0F;AAC1F,SAAS,kBAAkB,CAAC,GAAW;IACnC,IAAI,6BAA6B,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAEzD,MAAM,UAAU,GAAG,6BAA6B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3D,IAAI,UAAU,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC9I,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,SAAS,GAAG,+CAA+C,CAAC,I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{ BashContext, Violation } from '../types';\nimport { Violation as V } from '../types';\nimport { BashRuleBase } from '../rule-base';\n\nconst DEFAULT_UPSERT_PR_COMMAND = 'pnpm wp-upsert-pr';\n\nfunction fixHintFor(upsertPrCommand: string): readonly string[] {\n return [\n 'Direct PR creation is blocked. Create or update a PR ONLY via the gated command:',\n ` ${upsertPrCommand}`,\n 'It updates the branch from main (3-point merge), runs the real build (nx affected), and',\n 'assembles the PR dashboard — then creates/updates the PR itself. A failing build = no PR.',\n 'There is nothing to paste or attest to; the command does the work.',\n ];\n}\n\n// Detect every way an agent could open/update a PR directly, so the ONLY path left is\n// `pnpm wp-upsert-pr` (whose internal `gh pr create` runs as a child process the hook\n// never sees). Read-only `gh pr list` / `gh api .../pulls` GET are intentionally allowed.\nfunction isDirectPrCreation(cmd: string): boolean {\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 (ghApiPulls && (/--method\\s+POST/i.test(cmd) || /-X\\s+POST/i.test(cmd) || /\\s-f\\b/.test(cmd) || /\\s-F\\b/.test(cmd) || /--field\\b/.test(cmd))) {\n return true;\n }\n\n const curlPulls = /\\bcurl\\b[^\\n]*api\\.github\\.com[^\\n]*\\/pulls\\b/.test(cmd);\n if (curlPulls && (/-X\\s*POST/i.test(cmd) || /--request\\s+POST/i.test(cmd) || /(\\s-d\\b|--data\\b)/.test(cmd))) {\n return true;\n }\n return false;\n}\n\nfunction truncate(s: string): string {\n const MAX = 120;\n return s.length <= MAX ? s : s.slice(0, MAX) + '…';\n}\n\nexport class PrCreationGuardRule extends BashRuleBase<PrCreationGuardConfig> {\n private readonly upsertPrCommand: string;\n\n constructor(config: PrCreationGuardConfig) {\n super(config, 'pr-creation-guard');\n this.upsertPrCommand = config.upsertPrCommand ?? DEFAULT_UPSERT_PR_COMMAND;\n }\n\n readonly description = 'Block direct PR creation/edit (gh pr / gh api / curl) so PRs go only through the gated upsert-pr command.';\n get fixHint(): readonly string[] { return fixHintFor(this.upsertPrCommand); }\n\n check(ctx: BashContext): readonly Violation[] {\n if (!isDirectPrCreation(ctx.command)) return [];\n return [new V(\n 1,\n truncate(ctx.command),\n [\n 'Direct PR creation/update is blocked.',\n 'Use the gated command instead — it runs the build and builds the dashboard:',\n ` ${this.upsertPrCommand}`,\n ].join('\\n'),\n )];\n }\n}\n"]}
|