@webpieces/ai-hook-rules 0.3.173 → 0.3.175

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.173",
3
+ "version": "0.3.175",
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",
@@ -36,7 +36,7 @@
36
36
  "directory": "packages/tooling/ai-hook-rules"
37
37
  },
38
38
  "dependencies": {
39
- "@webpieces/rules-config": "0.3.173"
39
+ "@webpieces/rules-config": "0.3.175"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
@@ -60,7 +60,9 @@ function run(rawInput) {
60
60
  'This project is missing the webpieces AI hook (./node_modules/.bin/wp-ai-hook not found).\n' +
61
61
  '\n' +
62
62
  'Present these options to the human and wait for their choice:\n' +
63
- ' A) PREFERRED: Ask the human to run `npm install @webpieces/ai-hook-rules` (or pnpm install)\n' +
63
+ ' A) PREFERRED: Run from the monorepo root: `pnpm add -Dw @webpieces/ai-hook-rules`\n' +
64
+ ' (the -D flag makes it a devDependency, -w adds it to the workspace root)\n' +
65
+ ' If not a pnpm workspace, run from the project root: `npm install --save-dev @webpieces/ai-hook-rules`\n' +
64
66
  ' B) Skip hooks temporarily: ask human how long (1 hour / 1 day / forever), then write\n' +
65
67
  ' .webpieces/skiphooks with {"expires": <unix epoch seconds>, "reason": "..."}\n' +
66
68
  '\n' +
@@ -1 +1 @@
1
- {"version":3,"file":"global-hook.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/global-hook.ts"],"names":[],"mappings":";;AAAA,2BAA8C;AAC9C,+BAA4B;AAC5B,iDAA0C;AAc1C,SAAS,aAAa,CAAC,GAAW;IAC9B,8DAA8D;I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S,IAAI,KAAK,CAAC;AACvB,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;IACzB,GAAG,CAAC,SAAS,CAAC,CAAC;AACnB,CAAC,CAAC,CAAC","sourcesContent":["import { existsSync, readFileSync } from 'fs';\nimport { join } from 'path';\nimport { spawnSync } from 'child_process';\n\ninterface SkipHooksFile {\n expires: number | null;\n reason?: string;\n}\n\ninterface HookPayload {\n tool_name?: string;\n tool_input?: {\n file_path?: string;\n };\n}\n\nfunction readSkipHooks(cwd: string): SkipHooksFile | null {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const skipPath = join(cwd, '.webpieces', 'skiphooks');\n if (!existsSync(skipPath)) return null;\n return JSON.parse(readFileSync(skipPath, 'utf8')) as SkipHooksFile;\n } catch (err: unknown) {\n // eslint-disable-next-line @webpieces/catch-error-pattern -- intentionally discard; malformed .skiphooks must not crash global hook\n return null;\n }\n}\n\nfunction run(rawInput: string): void {\n const cwd = process.cwd();\n\n let payload: HookPayload | null = null;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n if (rawInput.trim()) {\n payload = JSON.parse(rawInput) as HookPayload;\n }\n } catch (err: unknown) {\n //const error = toError(err); -- malformed stdin is intentionally ignored; must not crash global hook\n }\n\n // 1. Check .skiphooks — if valid and not expired, allow everything\n const skipHooks = readSkipHooks(cwd);\n if (skipHooks !== null) {\n const nowSeconds = Date.now() / 1000;\n if (skipHooks.expires === null || nowSeconds < skipHooks.expires) {\n process.exit(0);\n }\n }\n\n // 2. Always allow writing .webpieces/skiphooks (this is the escape hatch)\n const filePath = payload?.tool_input?.file_path ?? '';\n if (payload?.tool_name === 'Write' && filePath.endsWith('.webpieces/skiphooks')) {\n process.exit(0);\n }\n\n // 3. Delegate to per-repo hook if present\n const localHook = join(cwd, 'node_modules', '.bin', 'wp-ai-hook');\n if (existsSync(localHook)) {\n const result = spawnSync(localHook, [], {\n input: Buffer.from(rawInput),\n encoding: 'buffer',\n });\n if (result.stdout?.length) process.stdout.write(result.stdout);\n if (result.stderr?.length) process.stderr.write(result.stderr);\n process.exit(result.status ?? 0);\n }\n\n // 4. No local hook found — block and instruct AI\n process.stderr.write(\n 'STOP. DO NOT TAKE ANY ACTION. You MUST ask the human and wait for their answer.\\n' +\n '\\n' +\n 'This project is missing the webpieces AI hook (./node_modules/.bin/wp-ai-hook not found).\\n' +\n '\\n' +\n 'Present these options to the human and wait for their choice:\\n' +\n ' A) PREFERRED: Ask the human to run `npm install @webpieces/ai-hook-rules` (or pnpm install)\\n' +\n ' B) Skip hooks temporarily: ask human how long (1 hour / 1 day / forever), then write\\n' +\n ' .webpieces/skiphooks with {\"expires\": <unix epoch seconds>, \"reason\": \"...\"}\\n' +\n '\\n' +\n 'WARNING: DO NOT disable permanently (expires: null) without explicit human permission.\\n' +\n 'You are BLOCKED. Ask the human now and wait for their response.\\n',\n );\n process.exit(2);\n}\n\nlet stdinData = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nprocess.stdin.on('data', (chunk: string) => {\n stdinData += chunk;\n});\nprocess.stdin.on('end', () => {\n run(stdinData);\n});\n"]}
1
+ {"version":3,"file":"global-hook.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/global-hook.ts"],"names":[],"mappings":";;AAAA,2BAA8C;AAC9C,+BAA4B;AAC5B,iDAA0C;AAc1C,SAAS,aAAa,CAAC,GAAW;IAC9B,8DAA8D;IAC9D,IAAI,CAAC;QACD,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,GAAG,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;QACtD,IAAI,CAAC,IAAA,eAAU,EAAC,QAAQ,CAAC;YAAE,OAAO,IAAI,CAAC;QACvC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,iBAAY,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAkB,CAAC;IACvE,CAAC;IAAC,OAAO,G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,EAAE,EAAE;YACpC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;YAC5B,QAAQ,EAAE,QAAQ;SACrB,CAAC,CAAC;QACH,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM;YAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC/D,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM;YAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC/D,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,iDAAiD;IACjD,OAAO,CAAC,MAAM,CAAC,KAAK,CAChB,mFAAmF;QAC/E,IAAI;QACJ,6FAA6F;QAC7F,IAAI;QACJ,iEAAiE;QACjE,uFAAuF;QACvF,iFAAiF;QACjF,8GAA8G;QAC9G,0FAA0F;QAC1F,qFAAqF;QACrF,IAAI;QACJ,0FAA0F;QAC1F,mEAAmE,CAC1E,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC;AAED,IAAI,SAAS,GAAG,EAAE,CAAC;AACnB,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;AACvB,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AAClC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;IACvC,SAAS,IAAI,KAAK,CAAC;AACvB,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;IACzB,GAAG,CAAC,SAAS,CAAC,CAAC;AACnB,CAAC,CAAC,CAAC","sourcesContent":["import { existsSync, readFileSync } from 'fs';\nimport { join } from 'path';\nimport { spawnSync } from 'child_process';\n\ninterface SkipHooksFile {\n expires: number | null;\n reason?: string;\n}\n\ninterface HookPayload {\n tool_name?: string;\n tool_input?: {\n file_path?: string;\n };\n}\n\nfunction readSkipHooks(cwd: string): SkipHooksFile | null {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const skipPath = join(cwd, '.webpieces', 'skiphooks');\n if (!existsSync(skipPath)) return null;\n return JSON.parse(readFileSync(skipPath, 'utf8')) as SkipHooksFile;\n } catch (err: unknown) {\n // eslint-disable-next-line @webpieces/catch-error-pattern -- intentionally discard; malformed .skiphooks must not crash global hook\n return null;\n }\n}\n\nfunction run(rawInput: string): void {\n const cwd = process.cwd();\n\n let payload: HookPayload | null = null;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n if (rawInput.trim()) {\n payload = JSON.parse(rawInput) as HookPayload;\n }\n } catch (err: unknown) {\n //const error = toError(err); -- malformed stdin is intentionally ignored; must not crash global hook\n }\n\n // 1. Check .skiphooks — if valid and not expired, allow everything\n const skipHooks = readSkipHooks(cwd);\n if (skipHooks !== null) {\n const nowSeconds = Date.now() / 1000;\n if (skipHooks.expires === null || nowSeconds < skipHooks.expires) {\n process.exit(0);\n }\n }\n\n // 2. Always allow writing .webpieces/skiphooks (this is the escape hatch)\n const filePath = payload?.tool_input?.file_path ?? '';\n if (payload?.tool_name === 'Write' && filePath.endsWith('.webpieces/skiphooks')) {\n process.exit(0);\n }\n\n // 3. Delegate to per-repo hook if present\n const localHook = join(cwd, 'node_modules', '.bin', 'wp-ai-hook');\n if (existsSync(localHook)) {\n const result = spawnSync(localHook, [], {\n input: Buffer.from(rawInput),\n encoding: 'buffer',\n });\n if (result.stdout?.length) process.stdout.write(result.stdout);\n if (result.stderr?.length) process.stderr.write(result.stderr);\n process.exit(result.status ?? 0);\n }\n\n // 4. No local hook found — block and instruct AI\n process.stderr.write(\n 'STOP. DO NOT TAKE ANY ACTION. You MUST ask the human and wait for their answer.\\n' +\n '\\n' +\n 'This project is missing the webpieces AI hook (./node_modules/.bin/wp-ai-hook not found).\\n' +\n '\\n' +\n 'Present these options to the human and wait for their choice:\\n' +\n ' A) PREFERRED: Run from the monorepo root: `pnpm add -Dw @webpieces/ai-hook-rules`\\n' +\n ' (the -D flag makes it a devDependency, -w adds it to the workspace root)\\n' +\n ' If not a pnpm workspace, run from the project root: `npm install --save-dev @webpieces/ai-hook-rules`\\n' +\n ' B) Skip hooks temporarily: ask human how long (1 hour / 1 day / forever), then write\\n' +\n ' .webpieces/skiphooks with {\"expires\": <unix epoch seconds>, \"reason\": \"...\"}\\n' +\n '\\n' +\n 'WARNING: DO NOT disable permanently (expires: null) without explicit human permission.\\n' +\n 'You are BLOCKED. Ask the human now and wait for their response.\\n',\n );\n process.exit(2);\n}\n\nlet stdinData = '';\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf8');\nprocess.stdin.on('data', (chunk: string) => {\n stdinData += chunk;\n});\nprocess.stdin.on('end', () => {\n run(stdinData);\n});\n"]}
@@ -19,6 +19,9 @@ const noEditOnMain = {
19
19
  'Branch naming convention is defined in webpieces.config.json under no-edit-on-main.branchNamingConvention.',
20
20
  ],
21
21
  check(ctx) {
22
+ // Only apply to files inside the workspace root
23
+ if (ctx.relativePath.startsWith('..'))
24
+ return [];
22
25
  let currentBranch;
23
26
  // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
24
27
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"no-edit-on-main.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/no-edit-on-main.ts"],"names":[],"mappings":";;AAAA,iDAAyC;AAEzC,oCAA0C;AAC1C,0CAAsC;AAEtC,MAAM,YAAY,GAAa;IAC3B,IAAI,EAAE,iBAAiB;IACvB,WAAW,EAAE,sFAAsF;IACnG,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,CAAC,MAAM,CAAC;IACf,cAAc,EAAE;QACZ,sBAAsB,EAAE,wBAAwB;KACnD;IACD,OAAO,EAAE;QACL,oCAAoC;QACpC,QAAQ;QACR,kDAAkD;QAClD,8DAA8D;QAC9D,4GAA4G;KAC/G;IAED,KAAK,CAAC,GAAgB;QAClB,IAAI,aAAqB,CAAC;QAC1B,8DAA8D;QAC9D,IAAI,CAAC;YACD,aAAa,GAAG,IAAA,wBAAQ,EAAC,iCAAiC,EAAE;gBACxD,GAAG,EAAE,GAAG,CAAC,aAAa;gBACtB,QAAQ,EAAE,MAAM;gBAChB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;aAClC,CAAC,CAAC,IAAI,EAAE,CAAC;QACd,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;YACX,OAAO,EAAE,CAAC;QACd,CAAC;QAED,IAAI,aAAa,KAAK,MAAM;YAAE,OAAO,EAAE,CAAC;QAExC,MAAM,UAAU,GAAI,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAwB;eACzE,yCAAyC,CAAC;QAEjD,OAAO,CAAC,IAAI,iBAAC,CACT,CAAC,EACD,GAAG,CAAC,YAAY,EAChB;gBACI,oCAAoC;gBACpC,yGAAyG;gBACzG,0DAA0D,UAAU,EAAE;gBACtE,2BAA2B,GAAG,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC;aACxE,CAAC,IAAI,CAAC,IAAI,CAAC,CACf,CAAC,CAAC;IACP,CAAC;CACJ,CAAC;AAEF,kBAAe,YAAY,CAAC","sourcesContent":["import { execSync } from 'child_process';\nimport type { FileRule, FileContext, Violation } from '../types';\nimport { Violation as V } from '../types';\nimport { toError } from '../to-error';\n\nconst noEditOnMain: FileRule = {\n name: 'no-edit-on-main',\n description: 'Block file edits when on the main branch — all work must happen on a feature branch.',\n scope: 'file',\n files: ['**/*'],\n defaultOptions: {\n branchNamingConvention: '{whoami}/{featurename}',\n },\n fixHint: [\n 'You should not be working on main.',\n 'Steps:',\n ' 1. git pull origin main ← get latest commits',\n ' 2. git checkout -b <branch-name> ← create feature branch',\n 'Branch naming convention is defined in webpieces.config.json under no-edit-on-main.branchNamingConvention.',\n ],\n\n check(ctx: FileContext): readonly Violation[] {\n let currentBranch: string;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n currentBranch = execSync('git rev-parse --abbrev-ref HEAD', {\n cwd: ctx.workspaceRoot,\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return [];\n }\n\n if (currentBranch !== 'main') return [];\n\n const convention = (ctx.options['branchNamingConvention'] as string | undefined)\n ?? 'feature/<ticket-id>-<short-description>';\n\n return [new V(\n 1,\n ctx.relativePath,\n [\n 'You should not be working on main.',\n 'Do a `git pull origin main` to get latest, then create a feature branch based on the naming convention.',\n `Branch naming convention (from webpieces.config.json): ${convention}`,\n 'Example: git checkout -b ' + convention.replace(/<[^>]+>/g, 'value'),\n ].join('\\n'),\n )];\n },\n};\n\nexport default noEditOnMain;\n"]}
1
+ {"version":3,"file":"no-edit-on-main.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/no-edit-on-main.ts"],"names":[],"mappings":";;AAAA,iDAAyC;AAEzC,oCAA0C;AAC1C,0CAAsC;AAEtC,MAAM,YAAY,GAAa;IAC3B,IAAI,EAAE,iBAAiB;IACvB,WAAW,EAAE,sFAAsF;IACnG,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,CAAC,MAAM,CAAC;IACf,cAAc,EAAE;QACZ,sBAAsB,EAAE,wBAAwB;KACnD;IACD,OAAO,EAAE;QACL,oCAAoC;QACpC,QAAQ;QACR,kDAAkD;QAClD,8DAA8D;QAC9D,4GAA4G;KAC/G;IAED,KAAK,CAAC,GAAgB;QAClB,gDAAgD;QAChD,IAAI,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,EAAE,CAAC;QAEjD,IAAI,aAAqB,CAAC;QAC1B,8DAA8D;QAC9D,IAAI,CAAC;YACD,aAAa,GAAG,IAAA,wBAAQ,EAAC,iCAAiC,EAAE;gBACxD,GAAG,EAAE,GAAG,CAAC,aAAa;gBACtB,QAAQ,EAAE,MAAM;gBAChB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;aAClC,CAAC,CAAC,IAAI,EAAE,CAAC;QACd,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;YACX,OAAO,EAAE,CAAC;QACd,CAAC;QAED,IAAI,aAAa,KAAK,MAAM;YAAE,OAAO,EAAE,CAAC;QAExC,MAAM,UAAU,GAAI,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAwB;eACzE,yCAAyC,CAAC;QAEjD,OAAO,CAAC,IAAI,iBAAC,CACT,CAAC,EACD,GAAG,CAAC,YAAY,EAChB;gBACI,oCAAoC;gBACpC,yGAAyG;gBACzG,0DAA0D,UAAU,EAAE;gBACtE,2BAA2B,GAAG,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC;aACxE,CAAC,IAAI,CAAC,IAAI,CAAC,CACf,CAAC,CAAC;IACP,CAAC;CACJ,CAAC;AAEF,kBAAe,YAAY,CAAC","sourcesContent":["import { execSync } from 'child_process';\nimport type { FileRule, FileContext, Violation } from '../types';\nimport { Violation as V } from '../types';\nimport { toError } from '../to-error';\n\nconst noEditOnMain: FileRule = {\n name: 'no-edit-on-main',\n description: 'Block file edits when on the main branch — all work must happen on a feature branch.',\n scope: 'file',\n files: ['**/*'],\n defaultOptions: {\n branchNamingConvention: '{whoami}/{featurename}',\n },\n fixHint: [\n 'You should not be working on main.',\n 'Steps:',\n ' 1. git pull origin main ← get latest commits',\n ' 2. git checkout -b <branch-name> ← create feature branch',\n 'Branch naming convention is defined in webpieces.config.json under no-edit-on-main.branchNamingConvention.',\n ],\n\n check(ctx: FileContext): readonly Violation[] {\n // Only apply to files inside the workspace root\n if (ctx.relativePath.startsWith('..')) return [];\n\n let currentBranch: string;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n currentBranch = execSync('git rev-parse --abbrev-ref HEAD', {\n cwd: ctx.workspaceRoot,\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return [];\n }\n\n if (currentBranch !== 'main') return [];\n\n const convention = (ctx.options['branchNamingConvention'] as string | undefined)\n ?? 'feature/<ticket-id>-<short-description>';\n\n return [new V(\n 1,\n ctx.relativePath,\n [\n 'You should not be working on main.',\n 'Do a `git pull origin main` to get latest, then create a feature branch based on the naming convention.',\n `Branch naming convention (from webpieces.config.json): ${convention}`,\n 'Example: git checkout -b ' + convention.replace(/<[^>]+>/g, 'value'),\n ].join('\\n'),\n )];\n },\n};\n\nexport default noEditOnMain;\n"]}