@devrik-tools/claude-gates 0.4.0 → 0.6.0

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.
Files changed (56) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/README.es.md +25 -4
  3. package/README.md +21 -5
  4. package/cli/config.mjs +126 -124
  5. package/cli/init.mjs +303 -276
  6. package/cli/install.mjs +281 -175
  7. package/cli/materialize.mjs +103 -102
  8. package/cli/registry.mjs +139 -136
  9. package/cli/smoke-fixtures.json +51 -0
  10. package/cli/task.mjs +140 -140
  11. package/package.json +1 -1
  12. package/plugins/gates/.claude-plugin/plugin.json +1 -1
  13. package/plugins/gates/hooks/ask-adoption.mjs +147 -147
  14. package/plugins/gates/hooks/doctor.mjs +207 -207
  15. package/plugins/gates/hooks/gates/atomic-commit/index.mjs +229 -0
  16. package/plugins/gates/hooks/gates/audit-before-build/index.mjs +110 -88
  17. package/plugins/gates/hooks/gates/autonomous-mode/index.mjs +50 -50
  18. package/plugins/gates/hooks/gates/bash-commands/index.mjs +215 -215
  19. package/plugins/gates/hooks/gates/brief-before-delegate/index.mjs +269 -265
  20. package/plugins/gates/hooks/gates/capability-map/index.mjs +377 -0
  21. package/plugins/gates/hooks/gates/circuit-breaker/index.mjs +527 -501
  22. package/plugins/gates/hooks/gates/diagnosis-before-patch/index.mjs +48 -43
  23. package/plugins/gates/hooks/gates/feature-catalog/index.mjs +83 -83
  24. package/plugins/gates/hooks/gates/force-parallel/index.mjs +134 -119
  25. package/plugins/gates/hooks/gates/forge-flow/index.mjs +134 -134
  26. package/plugins/gates/hooks/gates/implementation-pipeline/index.mjs +187 -187
  27. package/plugins/gates/hooks/gates/intent-flow/index.mjs +260 -260
  28. package/plugins/gates/hooks/gates/lint-commit/index.mjs +152 -149
  29. package/plugins/gates/hooks/gates/mandatory-flow/index.mjs +180 -180
  30. package/plugins/gates/hooks/gates/never-assume/index.mjs +59 -58
  31. package/plugins/gates/hooks/gates/no-blocking/index.mjs +163 -148
  32. package/plugins/gates/hooks/gates/no-coauthor/index.mjs +127 -0
  33. package/plugins/gates/hooks/gates/no-lint-suppression/index.mjs +183 -0
  34. package/plugins/gates/hooks/gates/protected-paths/index.mjs +149 -144
  35. package/plugins/gates/hooks/gates/recurrence-lock/index.mjs +91 -89
  36. package/plugins/gates/hooks/gates/reuse-before-build/index.mjs +263 -159
  37. package/plugins/gates/hooks/gates/risk-level/index.mjs +265 -263
  38. package/plugins/gates/hooks/gates/root-cause-first/index.mjs +57 -56
  39. package/plugins/gates/hooks/gates/root-whitelist/index.mjs +211 -131
  40. package/plugins/gates/hooks/gates/rule-skill-autodiscovery/index.mjs +181 -184
  41. package/plugins/gates/hooks/gates/sdd-specs/index.mjs +256 -256
  42. package/plugins/gates/hooks/gates/staged-lint/index.mjs +187 -0
  43. package/plugins/gates/hooks/gates/stop-pending/index.mjs +169 -164
  44. package/plugins/gates/hooks/gates/test-matrix/index.mjs +187 -187
  45. package/plugins/gates/hooks/gates/tool-map/index.mjs +168 -143
  46. package/plugins/gates/hooks/hooks.json +51 -0
  47. package/plugins/gates/hooks/lib/config.mjs +179 -172
  48. package/plugins/gates/hooks/lib/hook-io.mjs +367 -357
  49. package/plugins/gates/hooks/lib/signals.mjs +172 -127
  50. package/plugins/gates/hooks/wiring-check.mjs +227 -227
  51. package/plugins/tasks/.claude-plugin/plugin.json +1 -1
  52. package/plugins/tasks/hooks/hooks.json +26 -26
  53. package/plugins/tasks/hooks/lib/task-store.mjs +217 -197
  54. package/plugins/tasks/hooks/register-requests.mjs +145 -145
  55. package/plugins/tasks/hooks/session-tasks.mjs +108 -108
  56. package/registry.json +171 -1
@@ -1,143 +1,168 @@
1
- // tool-map — maintains the per-project tool map so a discovery is never repeated. It is
2
- // the write half of the discovery pair (reuse-before-build is the read half). When a new
3
- // tool is created WITH its audit declared, this gate records what that tool covers into
4
- // .ai/tool-map.json, so next time reuse-before-build finds it and does not block.
5
- //
6
- // It never reaches the network and takes no judgment: it only appends a deterministic
7
- // record (path + the audit line the author already wrote) to a JSON file. The cloud search
8
- // that decides "does something already exist?" is the assistant's / the CLI's job. This
9
- // gate never denies — it observes a legitimate build and remembers it. It warns once when
10
- // it could not record, so a silent write failure does not go unnoticed.
11
- //
12
- // ── What a project can configure (params) ───────────────────────────────────────────
13
- // toolMapFile path to the per-project tool map, relative to the project root.
14
- // Default .ai/tool-map.json.
15
-
16
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
17
- import { dirname, extname, join } from 'node:path';
18
- import {
19
- runGate,
20
- warn,
21
- toolInGroups,
22
- writtenContentOf,
23
- writtenPathOf,
24
- } from '../../lib/hook-io.mjs';
25
-
26
- const GATE_ID = 'tool-map';
27
- const CONFIG_KEY = 'maintainToolMap';
28
-
29
- const DEFAULT_TOOL_MAP_FILE = join('.ai', 'tool-map.json');
30
- const JSON_INDENT = 2;
31
- const MAX_AUDIT_LENGTH = 300;
32
-
33
- const EXECUTABLE_EXTENSIONS = new Set([
34
- '.js',
35
- '.mjs',
36
- '.cjs',
37
- '.ts',
38
- '.py',
39
- '.sh',
40
- '.ps1',
41
- ]);
42
- const TOOL_FOLDERS = ['scripts/', 'hooks/', 'tools/', 'gates/'];
43
-
44
- // Phrases that mark a line as the author's audit statement. Matched against one line at a
45
- // time (no wrapping `.*`, which backtracks): the matching line is captured whole.
46
- const AUDIT_PHRASE_PATTERN =
47
- /(already exists|no existing tool|there is no plugin|audited|nothing does this|justification:)/i;
48
-
49
- /** The first line of `content` that states an audit, trimmed — or null when none does. */
50
- function auditLineOf(content) {
51
- for (const line of content.split('\n')) {
52
- if (AUDIT_PHRASE_PATTERN.test(line)) return line.trim();
53
- }
54
- return null;
55
- }
56
-
57
- function projectRootOf(startDirectory) {
58
- let current = startDirectory;
59
- while (true) {
60
- if (existsSync(join(current, '.git'))) return current;
61
- const parent = dirname(current);
62
- if (parent === current) return null;
63
- current = parent;
64
- }
65
- }
66
-
67
- function isExecutableToolPath(filePath) {
68
- const normalized = filePath.replace(/\\/g, '/');
69
- const inToolFolder = TOOL_FOLDERS.some((folder) =>
70
- normalized.includes(folder),
71
- );
72
- return (
73
- inToolFolder && EXECUTABLE_EXTENSIONS.has(extname(filePath).toLowerCase())
74
- );
75
- }
76
-
77
- function readMap(path) {
78
- if (!existsSync(path)) return { tools: [] };
79
- try {
80
- const parsed = JSON.parse(readFileSync(path, 'utf8'));
81
- return Array.isArray(parsed.tools) ? parsed : { tools: [] };
82
- } catch {
83
- return { tools: [] };
84
- }
85
- }
86
-
87
- /** Appends the tool's record to the map file, warning (never blocking) if it cannot. */
88
- function recordTool(mapPath, normalizedPath, auditLine, toolMapFile) {
89
- const map = readMap(mapPath);
90
- if (map.tools.some((tool) => tool.path === normalizedPath)) return; // already recorded
91
-
92
- map.tools.push({
93
- path: normalizedPath,
94
- audit: auditLine.slice(0, MAX_AUDIT_LENGTH),
95
- recordedAt: new Date().toISOString(),
96
- });
97
-
98
- try {
99
- mkdirSync(dirname(mapPath), { recursive: true });
100
- writeFileSync(
101
- mapPath,
102
- `${JSON.stringify(map, null, JSON_INDENT)}\n`,
103
- 'utf8',
104
- );
105
- } catch (error) {
106
- warn(
107
- GATE_ID,
108
- `Could not record this tool in ${toolMapFile}: ${error?.message ?? error}. ` +
109
- 'The build proceeds, but the discovery was not remembered.',
110
- );
111
- }
112
- }
113
-
114
- runGate(
115
- {
116
- id: GATE_ID,
117
- configKey: CONFIG_KEY,
118
- enabledByDefault: false,
119
- defaultParams: { toolMapFile: DEFAULT_TOOL_MAP_FILE },
120
- },
121
- ({ toolName, toolInput, parameters }) => {
122
- if (!toolInGroups(toolName, ['write'])) return;
123
-
124
- const filePath = writtenPathOf(toolInput);
125
- if (!isExecutableToolPath(filePath)) return;
126
-
127
- // Only a build that declared its audit is worth recording: that line IS the reason
128
- // this tool exists and what it was checked against.
129
- const content = writtenContentOf(toolInput);
130
- const auditLine = auditLineOf(content);
131
- if (!auditLine) return;
132
-
133
- const root = projectRootOf(process.cwd());
134
- if (!root) return;
135
- const toolMapFile = parameters.toolMapFile ?? DEFAULT_TOOL_MAP_FILE;
136
- recordTool(
137
- join(root, toolMapFile),
138
- filePath.replace(/\\/g, '/'),
139
- auditLine,
140
- toolMapFile,
141
- );
142
- },
143
- );
1
+ // tool-map — maintains the per-project tool map so a discovery is never repeated. It is
2
+ // the write half of the discovery pair (reuse-before-build is the read half). When a new
3
+ // tool is created WITH its audit declared, this gate records what that tool covers into
4
+ // .ai/tool-map.json, so next time reuse-before-build finds it and does not block.
5
+ //
6
+ // It never reaches the network and takes no judgment: it only appends a deterministic
7
+ // record (path + the audit line the author already wrote) to a JSON file. The cloud search
8
+ // that decides "does something already exist?" is the assistant's / the CLI's job. This
9
+ // gate never denies — it observes a legitimate build and remembers it. It warns once when
10
+ // it could not record, so a silent write failure does not go unnoticed.
11
+ //
12
+ // ── What a project can configure (params) ───────────────────────────────────────────
13
+ // toolMapFile path to the per-project tool map, relative to the project root.
14
+ // Default .ai/tool-map.json.
15
+
16
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
17
+ import { dirname, extname, join } from 'node:path';
18
+ import {
19
+ runGate,
20
+ warn,
21
+ toolInGroups,
22
+ writtenContentOf,
23
+ writtenPathOf,
24
+ } from '../../lib/hook-io.mjs';
25
+
26
+ const GATE_ID = 'tool-map';
27
+ const CONFIG_KEY = 'maintainToolMap';
28
+
29
+ const DEFAULT_TOOL_MAP_FILE = join('.ai', 'tool-map.json');
30
+ const JSON_INDENT = 2;
31
+ const MAX_AUDIT_LENGTH = 300;
32
+
33
+ // Kept in sync with reuse-before-build's scope (its read half): a file this gate would NOT
34
+ // record is a file reuse-before-build would still flag, and the pair must agree on what
35
+ // counts as a tool/helper. Extensions and folders are broad because a reusable helper lives
36
+ // in many places (lib/utils/composables/components), not only the four original tool dirs.
37
+ const EXECUTABLE_EXTENSIONS = new Set([
38
+ '.js',
39
+ '.mjs',
40
+ '.cjs',
41
+ '.ts',
42
+ '.tsx',
43
+ '.jsx',
44
+ '.vue',
45
+ '.py',
46
+ '.sh',
47
+ '.ps1',
48
+ '.rb',
49
+ '.go',
50
+ ]);
51
+ const TOOL_FOLDERS = [
52
+ 'scripts/',
53
+ 'hooks/',
54
+ 'tools/',
55
+ 'gates/',
56
+ 'lib/',
57
+ 'libs/',
58
+ 'utils/',
59
+ 'util/',
60
+ 'helpers/',
61
+ 'helper/',
62
+ 'composables/',
63
+ 'components/',
64
+ 'services/',
65
+ 'shared/',
66
+ 'common/',
67
+ ];
68
+
69
+ // Phrases that mark a line as the author's audit statement. Matched against one line at a
70
+ // time (no wrapping `.*`, which backtracks): the matching line is captured whole.
71
+ const AUDIT_PHRASE_PATTERN =
72
+ /(already exists|no existing tool|there is no plugin|audited|nothing does this|justification:)/i;
73
+
74
+ /** The first line of `content` that states an audit, trimmed — or null when none does. */
75
+ function auditLineOf(content) {
76
+ for (const line of content.split('\n')) {
77
+ if (AUDIT_PHRASE_PATTERN.test(line)) return line.trim();
78
+ }
79
+ return null;
80
+ }
81
+
82
+ function projectRootOf(startDirectory) {
83
+ let current = startDirectory;
84
+ while (true) {
85
+ if (existsSync(join(current, '.git'))) return current;
86
+ const parent = dirname(current);
87
+ if (parent === current) return null;
88
+ current = parent;
89
+ }
90
+ }
91
+
92
+ function isExecutableToolPath(filePath) {
93
+ const normalized = filePath.replace(/\\/g, '/');
94
+ const inToolFolder = TOOL_FOLDERS.some((folder) =>
95
+ normalized.includes(folder),
96
+ );
97
+ return (
98
+ inToolFolder && EXECUTABLE_EXTENSIONS.has(extname(filePath).toLowerCase())
99
+ );
100
+ }
101
+
102
+ function readMap(path) {
103
+ if (!existsSync(path)) return { tools: [] };
104
+ try {
105
+ const parsed = JSON.parse(readFileSync(path, 'utf8'));
106
+ return Array.isArray(parsed.tools) ? parsed : { tools: [] };
107
+ } catch {
108
+ return { tools: [] };
109
+ }
110
+ }
111
+
112
+ /** Appends the tool's record to the map file, warning (never blocking) if it cannot. */
113
+ function recordTool(mapPath, normalizedPath, auditLine, toolMapFile) {
114
+ const map = readMap(mapPath);
115
+ if (map.tools.some((tool) => tool.path === normalizedPath)) return; // already recorded
116
+
117
+ map.tools.push({
118
+ path: normalizedPath,
119
+ audit: auditLine.slice(0, MAX_AUDIT_LENGTH),
120
+ recordedAt: new Date().toISOString(),
121
+ });
122
+
123
+ try {
124
+ mkdirSync(dirname(mapPath), { recursive: true });
125
+ writeFileSync(
126
+ mapPath,
127
+ `${JSON.stringify(map, null, JSON_INDENT)}\n`,
128
+ 'utf8',
129
+ );
130
+ } catch (error) {
131
+ warn(
132
+ GATE_ID,
133
+ `Could not record this tool in ${toolMapFile}: ${error?.message ?? error}. ` +
134
+ 'The build proceeds, but the discovery was not remembered.',
135
+ );
136
+ }
137
+ }
138
+
139
+ runGate(
140
+ {
141
+ id: GATE_ID,
142
+ configKey: CONFIG_KEY,
143
+ enabledByDefault: false,
144
+ defaultParams: { toolMapFile: DEFAULT_TOOL_MAP_FILE },
145
+ },
146
+ ({ toolName, toolInput, parameters }) => {
147
+ if (!toolInGroups(toolName, ['write'])) return;
148
+
149
+ const filePath = writtenPathOf(toolInput);
150
+ if (!isExecutableToolPath(filePath)) return;
151
+
152
+ // Only a build that declared its audit is worth recording: that line IS the reason
153
+ // this tool exists and what it was checked against.
154
+ const content = writtenContentOf(toolInput);
155
+ const auditLine = auditLineOf(content);
156
+ if (!auditLine) return;
157
+
158
+ const root = projectRootOf(process.cwd());
159
+ if (!root) return;
160
+ const toolMapFile = parameters.toolMapFile ?? DEFAULT_TOOL_MAP_FILE;
161
+ recordTool(
162
+ join(root, toolMapFile),
163
+ filePath.replace(/\\/g, '/'),
164
+ auditLine,
165
+ toolMapFile,
166
+ );
167
+ },
168
+ );
@@ -301,6 +301,16 @@
301
301
  }
302
302
  ]
303
303
  },
304
+ {
305
+ "matcher": "Bash|run_command|mcp__.*",
306
+ "hooks": [
307
+ {
308
+ "type": "command",
309
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/gates/staged-lint/index.mjs\"",
310
+ "timeout": 65
311
+ }
312
+ ]
313
+ },
304
314
  {
305
315
  "matcher": "Agent|Task|invoke_subagent|mcp__.*",
306
316
  "hooks": [
@@ -310,6 +320,47 @@
310
320
  "timeout": 30
311
321
  }
312
322
  ]
323
+ },
324
+ {
325
+ "matcher": "Bash|run_command|Agent|Task|invoke_subagent|mcp__.*",
326
+ "hooks": [
327
+ {
328
+ "type": "command",
329
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/gates/no-coauthor/index.mjs\"",
330
+ "timeout": 30
331
+ }
332
+ ]
333
+ },
334
+ {
335
+ "matcher": "Bash|run_command|mcp__.*",
336
+ "hooks": [
337
+ {
338
+ "type": "command",
339
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/gates/atomic-commit/index.mjs\"",
340
+ "timeout": 30
341
+ }
342
+ ]
343
+ },
344
+ {
345
+ "matcher": "Write|Edit|NotebookEdit|write_to_file|replace_file_content|mcp__.*",
346
+ "hooks": [
347
+ {
348
+ "type": "command",
349
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/gates/no-lint-suppression/index.mjs\"",
350
+ "timeout": 30
351
+ }
352
+ ]
353
+ }
354
+ ],
355
+ "UserPromptSubmit": [
356
+ {
357
+ "hooks": [
358
+ {
359
+ "type": "command",
360
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/gates/capability-map/index.mjs\"",
361
+ "timeout": 10
362
+ }
363
+ ]
313
364
  }
314
365
  ],
315
366
  "Stop": [