@webpieces/ai-hook-rules 0.3.156 → 0.3.158
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.158",
|
|
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",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"directory": "packages/tooling/ai-hook-rules"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@webpieces/rules-config": "0.3.
|
|
38
|
+
"@webpieces/rules-config": "0.3.158"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
@@ -8,13 +8,14 @@ const FIX_HINT_STALE_MAIN = [
|
|
|
8
8
|
'Then switch back to main and create your branch.',
|
|
9
9
|
];
|
|
10
10
|
const FIX_HINT_NON_MAIN = [
|
|
11
|
-
'You
|
|
12
|
-
'
|
|
13
|
-
'
|
|
11
|
+
'You should only branch off main, not off a feature branch!',
|
|
12
|
+
'Run: git checkout main && git pull origin main',
|
|
13
|
+
'Then create your branch from main.',
|
|
14
|
+
'If you truly need to branch off a non-main branch, a human must approve that — it is highly unusual.',
|
|
14
15
|
];
|
|
15
16
|
const branchCreationGuard = {
|
|
16
17
|
name: 'branch-creation-guard',
|
|
17
|
-
description: 'Block new-branch creation when main is stale, or
|
|
18
|
+
description: 'Block new-branch creation when main is stale, or when not on main.',
|
|
18
19
|
scope: 'bash',
|
|
19
20
|
files: [],
|
|
20
21
|
defaultOptions: {},
|
|
@@ -30,10 +31,7 @@ const branchCreationGuard = {
|
|
|
30
31
|
if (currentBranch === 'main') {
|
|
31
32
|
return checkMainIsUpToDate(ctx, requestedName);
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
return [new types_1.Violation(1, truncate(ctx.command), `You are on '${currentBranch}', not main. Branch names created from non-main branches MUST use the "sub/" prefix. Required name: "sub/${requestedName}". Create it now with that name. Do NOT ask the user.`)];
|
|
34
|
+
return [new types_1.Violation(1, truncate(ctx.command), `You are on '${currentBranch}', not main. You should only branch off main! Switch to main first: git checkout main && git pull origin main. If you truly need to branch off a non-main branch, a human must approve that — it is highly unusual.`)];
|
|
37
35
|
},
|
|
38
36
|
};
|
|
39
37
|
function checkMainIsUpToDate(ctx, requestedName) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch-creation-guard.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/branch-creation-guard.ts"],"names":[],"mappings":";;AAAA,iDAAyC;AAEzC,oCAA0C;AAE1C,MAAM,mBAAmB,GAAsB;IAC3C,mCAAmC;IACnC,gDAAgD;IAChD,kDAAkD;CACrD,CAAC;AAEF,MAAM,iBAAiB,GAAsB;IACzC
|
|
1
|
+
{"version":3,"file":"branch-creation-guard.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/branch-creation-guard.ts"],"names":[],"mappings":";;AAAA,iDAAyC;AAEzC,oCAA0C;AAE1C,MAAM,mBAAmB,GAAsB;IAC3C,mCAAmC;IACnC,gDAAgD;IAChD,kDAAkD;CACrD,CAAC;AAEF,MAAM,iBAAiB,GAAsB;IACzC,4DAA4D;IAC5D,gDAAgD;IAChD,oCAAoC;IACpC,sGAAsG;CACzG,CAAC;AAEF,MAAM,mBAAmB,GAAa;IAClC,IAAI,EAAE,uBAAuB;IAC7B,WAAW,EAAE,oEAAoE;IACjF,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,EAAE;IACT,cAAc,EAAE,EAAE;IAClB,OAAO,E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CAAC;AAED,MAAM,eAAe,GAAa;IAC9B,mCAAmC;IACnC,iCAAiC;IACjC,8CAA8C;CACjD,CAAC;AAEF,SAAS,iBAAiB,CAAC,OAAe;IACtC,KAAK,MAAM,OAAO,IAAI,eAAe,EAAE,CAAC;QACpC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChC,IAAI,CAAC;YAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,QAAQ,CAAC,CAAS;IACvB,MAAM,GAAG,GAAG,GAAG,CAAC;IAChB,OAAO,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC;AACvD,CAAC;AAED,kBAAe,mBAAmB,CAAC","sourcesContent":["import { execSync } from 'child_process';\nimport type { BashRule, BashContext, Violation } from '../types';\nimport { Violation as V } from '../types';\n\nconst FIX_HINT_STALE_MAIN: readonly string[] = [\n 'Local main is behind origin/main.',\n 'Run: git checkout main && git pull origin main',\n 'Then switch back to main and create your branch.',\n];\n\nconst FIX_HINT_NON_MAIN: readonly string[] = [\n 'You should only branch off main, not off a feature branch!',\n 'Run: git checkout main && git pull origin main',\n 'Then create your branch from main.',\n 'If you truly need to branch off a non-main branch, a human must approve that — it is highly unusual.',\n];\n\nconst branchCreationGuard: BashRule = {\n name: 'branch-creation-guard',\n description: 'Block new-branch creation when main is stale, or when not on main.',\n scope: 'bash',\n files: [],\n defaultOptions: {},\n fixHint: [...FIX_HINT_STALE_MAIN, ...FIX_HINT_NON_MAIN],\n\n check(ctx: BashContext): readonly Violation[] {\n const requestedName = extractBranchName(ctx.command);\n if (!requestedName) return [];\n\n const currentBranch = execSync('git rev-parse --abbrev-ref HEAD', {\n cwd: ctx.workspaceRoot,\n encoding: 'utf8',\n }).trim();\n\n if (currentBranch === 'main') {\n return checkMainIsUpToDate(ctx, requestedName);\n }\n\n return [new V(\n 1,\n truncate(ctx.command),\n `You are on '${currentBranch}', not main. You should only branch off main! Switch to main first: git checkout main && git pull origin main. If you truly need to branch off a non-main branch, a human must approve that — it is highly unusual.`,\n )];\n },\n};\n\nfunction checkMainIsUpToDate(ctx: BashContext, requestedName: string): readonly Violation[] {\n execSync('git fetch origin main --quiet', {\n cwd: ctx.workspaceRoot,\n encoding: 'utf8',\n });\n const countStr = execSync('git rev-list HEAD..origin/main --count', {\n cwd: ctx.workspaceRoot,\n encoding: 'utf8',\n }).trim();\n const count = parseInt(countStr, 10);\n if (count > 0) {\n return [new V(\n 1,\n truncate(ctx.command),\n `Local main is ${count} commit(s) behind origin/main. Run 'git pull origin main' first, then retry creating branch '${requestedName}'.`,\n )];\n }\n return [];\n}\n\nconst BRANCH_PATTERNS: RegExp[] = [\n /git\\s+checkout\\s+-[bB]\\s+([^\\s]+)/,\n /git\\s+switch\\s+-[cC]\\s+([^\\s]+)/,\n /git\\s+branch\\s+(?!-[dDmMrRla])([^\\s-][^\\s]*)/,\n];\n\nfunction extractBranchName(command: string): string | null {\n for (const pattern of BRANCH_PATTERNS) {\n const m = pattern.exec(command);\n if (m) return m[1];\n }\n return null;\n}\n\nfunction truncate(s: string): string {\n const MAX = 120;\n return s.length <= MAX ? s : s.slice(0, MAX) + '…';\n}\n\nexport default branchCreationGuard;\n"]}
|