@webpieces/ai-hook-rules 0.3.160 → 0.3.161

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.
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ // Plain JS shim — delegates to compiled TypeScript.
3
+ // Must NOT be converted to TypeScript (needs to exist pre-build for pnpm bin symlinks).
4
+ // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
5
+ 'use strict';
6
+
7
+ const path = require('path');
8
+ const fs = require('fs');
9
+ const compiled = path.join(__dirname, '..', 'src', 'adapters', 'claude-code-hook.js');
10
+
11
+ if (fs.existsSync(compiled)) {
12
+ require(compiled).main();
13
+ } else {
14
+ console.error(' [ai-hook-rules] Package not built yet. Run the build first, or install from npm.');
15
+ process.exit(1);
16
+ }
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ // Plain JS shim — delegates to compiled TypeScript.
3
+ // Must NOT be converted to TypeScript (needs to exist pre-build for pnpm bin symlinks).
4
+ // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
5
+ 'use strict';
6
+
7
+ const path = require('path');
8
+ const fs = require('fs');
9
+ const compiled = path.join(__dirname, '..', 'src', 'bin', 'dev-hook-install.js');
10
+
11
+ if (fs.existsSync(compiled)) {
12
+ require(compiled).main();
13
+ } else {
14
+ console.error(' [ai-hook-rules] Package not built yet. Run `nx build ai-hook-rules` first.');
15
+ process.exit(1);
16
+ }
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ // Plain JS shim — delegates to compiled TypeScript.
3
+ // Must NOT be converted to TypeScript (needs to exist pre-build for pnpm bin symlinks).
4
+ // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
5
+ 'use strict';
6
+
7
+ const path = require('path');
8
+ const fs = require('fs');
9
+ const compiled = path.join(__dirname, '..', 'src', 'bin', 'dev-hook-uninstall.js');
10
+
11
+ if (fs.existsSync(compiled)) {
12
+ require(compiled).main();
13
+ } else {
14
+ console.error(' [ai-hook-rules] Package not built yet. Run `nx build ai-hook-rules` first.');
15
+ process.exit(1);
16
+ }
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@webpieces/ai-hook-rules",
3
- "version": "0.3.160",
3
+ "version": "0.3.161",
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",
7
7
  "bin": {
8
- "wp-ai-hook": "./src/adapters/claude-code-hook.js",
8
+ "wp-ai-hook": "./bin/wp-ai-hook.js",
9
9
  "wp-setup-ai-hooks": "./bin/wp-setup-ai-hooks.js",
10
10
  "wp-setup-global-ai-hooks": "./bin/wp-setup-global-ai-hooks.js",
11
+ "wp-dev-hook-install": "./bin/wp-dev-hook-install.js",
12
+ "wp-dev-hook-uninstall": "./bin/wp-dev-hook-uninstall.js",
11
13
  "wp-git-update": "./src/scripts/git-updateFromMain.js",
12
14
  "wp-git-gather": "./src/scripts/git-gatherInfo.js",
13
15
  "wp-git-merge-complete": "./src/scripts/git-mergeComplete.js"
@@ -34,7 +36,7 @@
34
36
  "directory": "packages/tooling/ai-hook-rules"
35
37
  },
36
38
  "dependencies": {
37
- "@webpieces/rules-config": "0.3.160"
39
+ "@webpieces/rules-config": "0.3.161"
38
40
  },
39
41
  "publishConfig": {
40
42
  "access": "public"
@@ -0,0 +1 @@
1
+ export declare function main(): void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.main = main;
4
+ const fs_1 = require("fs");
5
+ const os_1 = require("os");
6
+ const path_1 = require("path");
7
+ function main() {
8
+ const cwd = process.cwd();
9
+ const distHookPath = (0, path_1.join)(cwd, 'dist', 'packages', 'tooling', 'ai-hook-rules', 'src', 'adapters', 'claude-code-hook.js');
10
+ if (!(0, fs_1.existsSync)(distHookPath)) {
11
+ console.error(`[wp-dev-hook-install] Local build not found at: ${distHookPath}`);
12
+ console.error(' Run `nx build ai-hook-rules` first.');
13
+ process.exit(1);
14
+ }
15
+ const homeDir = (0, os_1.homedir)();
16
+ const webpiecesDir = (0, path_1.join)(homeDir, '.webpieces');
17
+ const backupPath = (0, path_1.join)(webpiecesDir, 'dev-hook-backup.json');
18
+ const claudeSettingsPath = (0, path_1.join)(homeDir, '.claude', 'settings.json');
19
+ if ((0, fs_1.existsSync)(backupPath)) {
20
+ console.error('[wp-dev-hook-install] Dev hook is already installed (backup file exists).');
21
+ console.error(' Run `wp-dev-hook-uninstall` first to remove the current dev hook.');
22
+ process.exit(1);
23
+ }
24
+ let settings = {};
25
+ if ((0, fs_1.existsSync)(claudeSettingsPath)) {
26
+ settings = JSON.parse((0, fs_1.readFileSync)(claudeSettingsPath, 'utf8'));
27
+ }
28
+ // Save whatever hooks exist now (may be undefined/null) so uninstall can restore them
29
+ const backup = { previousHooks: settings.hooks ?? null };
30
+ if (!(0, fs_1.existsSync)(webpiecesDir)) {
31
+ (0, fs_1.mkdirSync)(webpiecesDir, { recursive: true });
32
+ }
33
+ (0, fs_1.writeFileSync)(backupPath, JSON.stringify(backup, null, 4) + '\n');
34
+ // Replace hooks with a single entry pointing at the local dist build
35
+ const hookCommand = `node ${distHookPath}`;
36
+ settings.hooks = {
37
+ PreToolUse: [
38
+ {
39
+ matcher: 'Write|Edit|MultiEdit|Bash',
40
+ hooks: [{ type: 'command', command: hookCommand }],
41
+ },
42
+ ],
43
+ };
44
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(claudeSettingsPath), { recursive: true });
45
+ (0, fs_1.writeFileSync)(claudeSettingsPath, JSON.stringify(settings, null, 4) + '\n');
46
+ console.log(` Dev hook installed → ${hookCommand}`);
47
+ console.log('');
48
+ console.log(' RESTART Claude Code to activate the local build hook.');
49
+ console.log(' Run `wp-dev-hook-uninstall` when done testing.');
50
+ }
51
+ if (require.main === module) {
52
+ main();
53
+ }
54
+ //# sourceMappingURL=dev-hook-install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-hook-install.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/bin/dev-hook-install.ts"],"names":[],"mappings":";;AAqBA,oBAmDC;AAxED,2BAAwE;AACxE,2BAA6B;AAC7B,+BAAqC;AAmBrC,SAAgB,IAAI;IAChB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,YAAY,GAAG,IAAA,WAAI,EAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,KAAK,EAAE,UAAU,EAAE,qBAAqB,CAAC,CAAC;IAEzH,IAAI,CAAC,IAAA,eAAU,EAAC,YAAY,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,KAAK,CAAC,mDAAmD,YAAY,EAAE,CAAC,CAAC;QACjF,OAAO,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;QACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,MAAM,OAAO,GAAG,IAAA,YAAO,GAAE,CAAC;IAC1B,MAAM,YAAY,GAAG,IAAA,WAAI,EAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACjD,MAAM,UAAU,GAAG,IAAA,WAAI,EAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC;IAC9D,MAAM,kBAAkB,GAAG,IAAA,WAAI,EAAC,OAAO,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;IAErE,IAAI,IAAA,eAAU,EAAC,UAAU,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,KAAK,CAAC,2EAA2E,CAAC,CAAC;QAC3F,OAAO,CAAC,KAAK,CAAC,qEAAqE,CAAC,CAAC;QACrF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,IAAI,QAAQ,GAAmB,EAAE,CAAC;IAClC,IAAI,IAAA,eAAU,EAAC,kBAAkB,CAAC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IAAI,KAAK,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,CAAC;AACX,CAAC","sourcesContent":["import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';\nimport { homedir } from 'os';\nimport { join, dirname } from 'path';\n\ninterface HookEntry {\n matcher: string;\n hooks: Array<{ type: string; command: string }>;\n}\n\ninterface ClaudeSettings {\n hooks?: {\n PreToolUse?: HookEntry[];\n };\n // webpieces-disable no-any-unknown -- opaque settings bag; arbitrary keys allowed\n [key: string]: unknown;\n}\n\ninterface DevHookBackup {\n previousHooks: ClaudeSettings['hooks'] | null;\n}\n\nexport function main(): void {\n const cwd = process.cwd();\n const distHookPath = join(cwd, 'dist', 'packages', 'tooling', 'ai-hook-rules', 'src', 'adapters', 'claude-code-hook.js');\n\n if (!existsSync(distHookPath)) {\n console.error(`[wp-dev-hook-install] Local build not found at: ${distHookPath}`);\n console.error(' Run `nx build ai-hook-rules` first.');\n process.exit(1);\n }\n\n const homeDir = homedir();\n const webpiecesDir = join(homeDir, '.webpieces');\n const backupPath = join(webpiecesDir, 'dev-hook-backup.json');\n const claudeSettingsPath = join(homeDir, '.claude', 'settings.json');\n\n if (existsSync(backupPath)) {\n console.error('[wp-dev-hook-install] Dev hook is already installed (backup file exists).');\n console.error(' Run `wp-dev-hook-uninstall` first to remove the current dev hook.');\n process.exit(1);\n }\n\n let settings: ClaudeSettings = {};\n if (existsSync(claudeSettingsPath)) {\n settings = JSON.parse(readFileSync(claudeSettingsPath, 'utf8')) as ClaudeSettings;\n }\n\n // Save whatever hooks exist now (may be undefined/null) so uninstall can restore them\n const backup: DevHookBackup = { previousHooks: settings.hooks ?? null };\n if (!existsSync(webpiecesDir)) {\n mkdirSync(webpiecesDir, { recursive: true });\n }\n writeFileSync(backupPath, JSON.stringify(backup, null, 4) + '\\n');\n\n // Replace hooks with a single entry pointing at the local dist build\n const hookCommand = `node ${distHookPath}`;\n settings.hooks = {\n PreToolUse: [\n {\n matcher: 'Write|Edit|MultiEdit|Bash',\n hooks: [{ type: 'command', command: hookCommand }],\n },\n ],\n };\n\n mkdirSync(dirname(claudeSettingsPath), { recursive: true });\n writeFileSync(claudeSettingsPath, JSON.stringify(settings, null, 4) + '\\n');\n\n console.log(` Dev hook installed → ${hookCommand}`);\n console.log('');\n console.log(' RESTART Claude Code to activate the local build hook.');\n console.log(' Run `wp-dev-hook-uninstall` when done testing.');\n}\n\nif (require.main === module) {\n main();\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function main(): void;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.main = main;
4
+ const fs_1 = require("fs");
5
+ const os_1 = require("os");
6
+ const path_1 = require("path");
7
+ function main() {
8
+ const homeDir = (0, os_1.homedir)();
9
+ const backupPath = (0, path_1.join)(homeDir, '.webpieces', 'dev-hook-backup.json');
10
+ const claudeSettingsPath = (0, path_1.join)(homeDir, '.claude', 'settings.json');
11
+ if (!(0, fs_1.existsSync)(backupPath)) {
12
+ console.error('[wp-dev-hook-uninstall] No dev hook backup found — dev hook was not installed.');
13
+ process.exit(1);
14
+ }
15
+ const backup = JSON.parse((0, fs_1.readFileSync)(backupPath, 'utf8'));
16
+ let settings = {};
17
+ if ((0, fs_1.existsSync)(claudeSettingsPath)) {
18
+ settings = JSON.parse((0, fs_1.readFileSync)(claudeSettingsPath, 'utf8'));
19
+ }
20
+ if (backup.previousHooks === null) {
21
+ delete settings.hooks;
22
+ }
23
+ else {
24
+ settings.hooks = backup.previousHooks;
25
+ }
26
+ (0, fs_1.writeFileSync)(claudeSettingsPath, JSON.stringify(settings, null, 4) + '\n');
27
+ (0, fs_1.rmSync)(backupPath);
28
+ console.log(' Dev hook removed. Previous hook configuration restored.');
29
+ console.log(' RESTART Claude Code to return to normal hook.');
30
+ }
31
+ if (require.main === module) {
32
+ main();
33
+ }
34
+ //# sourceMappingURL=dev-hook-uninstall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-hook-u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AEnB,OAAO,CAAC,GAAG,CAAC,2DAA2D,CAAC,CAAC;IACzE,OAAO,CAAC,GAAG,CAAC,iDAAiD,CAAC,CAAC;AACnE,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,CAAC;AACX,CAAC","sourcesContent":["import { existsSync, readFileSync, writeFileSync, rmSync } from 'fs';\nimport { homedir } from 'os';\nimport { join } from 'path';\n\ninterface HookEntry {\n matcher: string;\n hooks: Array<{ type: string; command: string }>;\n}\n\ninterface ClaudeSettings {\n hooks?: {\n PreToolUse?: HookEntry[];\n };\n // webpieces-disable no-any-unknown -- opaque settings bag; arbitrary keys allowed\n [key: string]: unknown;\n}\n\ninterface DevHookBackup {\n previousHooks: ClaudeSettings['hooks'] | null;\n}\n\nexport function main(): void {\n const homeDir = homedir();\n const backupPath = join(homeDir, '.webpieces', 'dev-hook-backup.json');\n const claudeSettingsPath = join(homeDir, '.claude', 'settings.json');\n\n if (!existsSync(backupPath)) {\n console.error('[wp-dev-hook-uninstall] No dev hook backup found — dev hook was not installed.');\n process.exit(1);\n }\n\n const backup = JSON.parse(readFileSync(backupPath, 'utf8')) as DevHookBackup;\n\n let settings: ClaudeSettings = {};\n if (existsSync(claudeSettingsPath)) {\n settings = JSON.parse(readFileSync(claudeSettingsPath, 'utf8')) as ClaudeSettings;\n }\n\n if (backup.previousHooks === null) {\n delete settings.hooks;\n } else {\n settings.hooks = backup.previousHooks;\n }\n\n writeFileSync(claudeSettingsPath, JSON.stringify(settings, null, 4) + '\\n');\n rmSync(backupPath);\n\n console.log(' Dev hook removed. Previous hook configuration restored.');\n console.log(' RESTART Claude Code to return to normal hook.');\n}\n\nif (require.main === module) {\n main();\n}\n"]}