specialist-agent 1.6.0 → 2.0.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 (176) hide show
  1. package/.claude-plugin/marketplace.json +77 -0
  2. package/.claude-plugin/plugin.json +43 -0
  3. package/.codex/INSTALL.md +113 -0
  4. package/.cursor-plugin/marketplace.json +9 -0
  5. package/.cursor-plugin/plugin.json +35 -0
  6. package/.opencode/INSTALL.md +123 -0
  7. package/README.md +204 -263
  8. package/agents/analyst-lite.md +48 -0
  9. package/agents/analyst.md +391 -0
  10. package/agents/api-lite.md +43 -0
  11. package/agents/api.md +145 -0
  12. package/agents/cloud-lite.md +1 -1
  13. package/agents/cloud.md +1 -1
  14. package/agents/data-lite.md +1 -1
  15. package/agents/data.md +1 -1
  16. package/agents/debugger-lite.md +46 -0
  17. package/agents/debugger.md +406 -0
  18. package/agents/deps-lite.md +41 -0
  19. package/agents/deps.md +206 -0
  20. package/agents/designer-lite.md +1 -1
  21. package/agents/designer.md +1 -1
  22. package/agents/devops-lite.md +1 -1
  23. package/agents/devops.md +1 -1
  24. package/agents/docs-lite.md +42 -0
  25. package/agents/docs.md +197 -0
  26. package/agents/executor-lite.md +61 -0
  27. package/agents/executor.md +456 -0
  28. package/agents/explorer-lite.md +1 -1
  29. package/agents/explorer.md +1 -1
  30. package/agents/finance-lite.md +1 -1
  31. package/agents/finance.md +1 -1
  32. package/agents/i18n-lite.md +44 -0
  33. package/agents/i18n.md +198 -0
  34. package/agents/legal-lite.md +1 -1
  35. package/agents/legal.md +1 -1
  36. package/agents/memory.md +240 -0
  37. package/agents/orchestrator-lite.md +40 -0
  38. package/agents/orchestrator.md +387 -0
  39. package/agents/pair-lite.md +38 -0
  40. package/agents/pair.md +308 -0
  41. package/agents/perf-lite.md +42 -0
  42. package/agents/perf.md +141 -0
  43. package/agents/planner-lite.md +59 -0
  44. package/agents/planner.md +265 -0
  45. package/agents/refactor-lite.md +42 -0
  46. package/agents/refactor.md +178 -0
  47. package/agents/scout-lite.md +37 -0
  48. package/agents/scout.md +222 -0
  49. package/agents/security-lite.md +1 -1
  50. package/agents/security.md +1 -1
  51. package/agents/starter-lite.md +1 -1
  52. package/agents/starter.md +1 -1
  53. package/agents/tdd-lite.md +43 -0
  54. package/agents/tdd.md +317 -0
  55. package/agents/tester-lite.md +1 -1
  56. package/agents/tester.md +1 -1
  57. package/cli/index.mjs +636 -15
  58. package/hooks/after-review.mjs +130 -0
  59. package/hooks/after-task.mjs +117 -0
  60. package/hooks/before-plan.mjs +155 -0
  61. package/hooks/before-review.mjs +139 -0
  62. package/hooks/hooks.json +81 -0
  63. package/hooks/native/auto-dispatch.mjs +197 -0
  64. package/hooks/native/auto-format.mjs +193 -0
  65. package/hooks/native/security-config.json +31 -0
  66. package/hooks/native/security-guard.mjs +267 -0
  67. package/hooks/native/session-context.mjs +136 -0
  68. package/hooks/native/settings-template.json +50 -0
  69. package/hooks/native/utils.mjs +62 -0
  70. package/hooks/on-error.mjs +129 -0
  71. package/hooks/session-end.mjs +185 -0
  72. package/hooks/session-start.mjs +154 -0
  73. package/package.json +16 -3
  74. package/packs/nextjs/agents/builder.md +24 -1
  75. package/packs/nextjs/agents/doctor.md +70 -4
  76. package/packs/nextjs/agents/migrator.md +24 -1
  77. package/packs/nextjs/agents/reviewer.md +93 -3
  78. package/packs/nextjs/agents-lite/builder.md +1 -1
  79. package/packs/nextjs/agents-lite/doctor.md +1 -1
  80. package/packs/nextjs/agents-lite/migrator.md +1 -1
  81. package/packs/nextjs/agents-lite/reviewer.md +1 -1
  82. package/packs/nextjs/skills/dev-create-component/SKILL.md +1 -1
  83. package/packs/nextjs/skills/dev-create-hook/SKILL.md +1 -1
  84. package/packs/nextjs/skills/dev-create-module/SKILL.md +1 -1
  85. package/packs/nextjs/skills/dev-create-service/SKILL.md +1 -1
  86. package/packs/nextjs/skills/dev-create-test/SKILL.md +1 -1
  87. package/packs/nextjs/skills/dev-generate-types/SKILL.md +1 -1
  88. package/packs/nextjs/skills/docs-onboard/SKILL.md +1 -1
  89. package/packs/nextjs/skills/migration-migrate-component/SKILL.md +1 -1
  90. package/packs/nextjs/skills/migration-migrate-module/SKILL.md +1 -1
  91. package/packs/nextjs/skills/review-check-architecture/SKILL.md +1 -1
  92. package/packs/nextjs/skills/review-fix-violations/SKILL.md +1 -1
  93. package/packs/nextjs/skills/review-review/SKILL.md +1 -1
  94. package/packs/react/agents/builder.md +24 -1
  95. package/packs/react/agents/doctor.md +107 -13
  96. package/packs/react/agents/migrator.md +24 -1
  97. package/packs/react/agents/reviewer.md +113 -9
  98. package/packs/react/agents-lite/builder.md +1 -1
  99. package/packs/react/agents-lite/doctor.md +1 -1
  100. package/packs/react/agents-lite/migrator.md +1 -1
  101. package/packs/react/agents-lite/reviewer.md +1 -1
  102. package/packs/react/skills/dev-create-component/SKILL.md +1 -1
  103. package/packs/react/skills/dev-create-hook/SKILL.md +1 -1
  104. package/packs/react/skills/dev-create-module/SKILL.md +1 -1
  105. package/packs/react/skills/dev-create-service/SKILL.md +1 -1
  106. package/packs/react/skills/dev-create-test/SKILL.md +1 -1
  107. package/packs/react/skills/dev-generate-types/SKILL.md +1 -1
  108. package/packs/react/skills/docs-onboard/SKILL.md +1 -1
  109. package/packs/react/skills/migration-migrate-component/SKILL.md +1 -1
  110. package/packs/react/skills/migration-migrate-module/SKILL.md +1 -1
  111. package/packs/react/skills/review-check-architecture/SKILL.md +1 -1
  112. package/packs/react/skills/review-fix-violations/SKILL.md +1 -1
  113. package/packs/react/skills/review-review/SKILL.md +1 -1
  114. package/packs/svelte/agents/builder.md +24 -1
  115. package/packs/svelte/agents/doctor.md +70 -4
  116. package/packs/svelte/agents/migrator.md +24 -1
  117. package/packs/svelte/agents/reviewer.md +93 -3
  118. package/packs/svelte/agents-lite/builder.md +1 -1
  119. package/packs/svelte/agents-lite/doctor.md +1 -1
  120. package/packs/svelte/agents-lite/migrator.md +1 -1
  121. package/packs/svelte/agents-lite/reviewer.md +1 -1
  122. package/packs/svelte/skills/dev-create-component/SKILL.md +1 -1
  123. package/packs/svelte/skills/dev-create-module/SKILL.md +1 -1
  124. package/packs/svelte/skills/dev-create-service/SKILL.md +1 -1
  125. package/packs/svelte/skills/dev-create-store/SKILL.md +1 -1
  126. package/packs/svelte/skills/dev-create-test/SKILL.md +1 -1
  127. package/packs/svelte/skills/dev-generate-types/SKILL.md +1 -1
  128. package/packs/svelte/skills/docs-onboard/SKILL.md +1 -1
  129. package/packs/svelte/skills/migration-migrate-component/SKILL.md +1 -1
  130. package/packs/svelte/skills/migration-migrate-module/SKILL.md +1 -1
  131. package/packs/svelte/skills/review-check-architecture/SKILL.md +1 -1
  132. package/packs/svelte/skills/review-fix-violations/SKILL.md +1 -1
  133. package/packs/svelte/skills/review-review/SKILL.md +1 -1
  134. package/packs/vue/agents/builder.md +24 -1
  135. package/packs/vue/agents/doctor.md +107 -13
  136. package/packs/vue/agents/migrator.md +24 -1
  137. package/packs/vue/agents/reviewer.md +113 -9
  138. package/packs/vue/agents-lite/builder.md +1 -1
  139. package/packs/vue/agents-lite/doctor.md +1 -1
  140. package/packs/vue/agents-lite/migrator.md +1 -1
  141. package/packs/vue/agents-lite/reviewer.md +1 -1
  142. package/packs/vue/skills/dev-create-component/SKILL.md +1 -1
  143. package/packs/vue/skills/dev-create-composable/SKILL.md +1 -1
  144. package/packs/vue/skills/dev-create-module/SKILL.md +1 -1
  145. package/packs/vue/skills/dev-create-service/SKILL.md +1 -1
  146. package/packs/vue/skills/dev-create-test/SKILL.md +1 -1
  147. package/packs/vue/skills/dev-generate-types/SKILL.md +1 -1
  148. package/packs/vue/skills/docs-onboard/SKILL.md +1 -1
  149. package/packs/vue/skills/migration-migrate-component/SKILL.md +1 -1
  150. package/packs/vue/skills/migration-migrate-module/SKILL.md +1 -1
  151. package/packs/vue/skills/review-check-architecture/SKILL.md +1 -1
  152. package/packs/vue/skills/review-fix-violations/SKILL.md +1 -1
  153. package/packs/vue/skills/review-review/SKILL.md +1 -1
  154. package/skills/audit/SKILL.md +169 -0
  155. package/skills/brainstorm/SKILL.md +245 -0
  156. package/skills/checkpoint/SKILL.md +209 -0
  157. package/skills/debug/SKILL.md +210 -0
  158. package/skills/estimate/SKILL.md +145 -0
  159. package/skills/finish/SKILL.md +211 -0
  160. package/skills/health/SKILL.md +242 -0
  161. package/skills/learn/SKILL.md +260 -0
  162. package/skills/migrate-framework/SKILL.md +172 -0
  163. package/skills/onboard/SKILL.md +168 -0
  164. package/skills/plan/SKILL.md +132 -0
  165. package/skills/recall/SKILL.md +150 -0
  166. package/skills/remember/SKILL.md +158 -0
  167. package/skills/tdd/SKILL.md +156 -0
  168. package/skills/tutorial/SKILL.md +346 -0
  169. package/skills/verify/SKILL.md +168 -0
  170. package/skills/worktree/SKILL.md +168 -0
  171. package/skills/write-skill/SKILL.md +213 -0
  172. package/templates/industry/ecommerce.md +127 -0
  173. package/templates/industry/fintech.md +161 -0
  174. package/templates/industry/saas.md +134 -0
  175. package/templates/session-memory.json +48 -0
  176. package/templates/skill-template/SKILL.md +90 -0
@@ -0,0 +1,197 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Auto-Dispatch — UserPromptSubmit Hook
5
+ *
6
+ * Detects user intent from prompt text and SUGGESTS (never forces)
7
+ * the best specialist agent. Respects explicit @agent mentions.
8
+ *
9
+ * Claude Code event: UserPromptSubmit
10
+ * Stdin: { prompt: "..." }
11
+ * Output: { "additionalContext": "Consider using @agent..." } or {}
12
+ */
13
+
14
+ import { resolve } from 'path';
15
+ import { fileURLToPath } from 'url';
16
+
17
+ const __filename = fileURLToPath(import.meta.url);
18
+
19
+ // ── Intent Map ──────────────────────────────────────────────
20
+ // Each agent maps to keyword groups. Multi-word phrases score higher.
21
+ // weight: multiplier for match score (more specific = higher)
22
+
23
+ const INTENT_MAP = {
24
+ // Core agents
25
+ starter: { phrases: ['new project', 'from scratch', 'scaffold', 'bootstrap', 'starter'], keywords: ['create app', 'init project'], weight: 1.5 },
26
+ builder: { phrases: ['create module', 'build component', 'implement feature', 'add crud'], keywords: ['create', 'build', 'implement', 'add', 'module', 'component', 'service', 'scaffold'], weight: 1 },
27
+ reviewer: { phrases: ['code review', 'review code', 'check quality', 'architecture review'], keywords: ['review', 'audit code', 'quality'], weight: 1.2 },
28
+ doctor: { phrases: ['not working', 'investigate bug', 'trace error', '500 error', '404 error'], keywords: ['bug', 'error', 'broken', 'crash', 'investigate', 'diagnose', 'failing'], weight: 1.2 },
29
+ migrator: { phrases: ['modernize code', 'migrate legacy', 'upgrade framework'], keywords: ['migrate', 'modernize', 'legacy', 'upgrade'], weight: 1.5 },
30
+
31
+ // Workflow agents
32
+ planner: { phrases: ['plan feature', 'design architecture', 'plan implementation'], keywords: ['plan', 'design', 'architect', 'strategy', 'roadmap'], weight: 1 },
33
+ executor: { phrases: ['execute plan', 'run tasks', 'execute all'], keywords: ['execute', 'run plan', 'checkpoint'], weight: 1.5 },
34
+ tdd: { phrases: ['test first', 'test driven', 'red green refactor', 'tdd'], keywords: ['tdd', 'failing test', 'test-driven'], weight: 2 },
35
+ debugger: { phrases: ['debug issue', 'root cause', 'stack trace', 'step through'], keywords: ['debug', 'trace', 'breakpoint', 'root cause'], weight: 1.2 },
36
+ pair: { phrases: ['pair programming', 'pair with me', 'code together'], keywords: ['pair', 'collaborate', 'together'], weight: 1.5 },
37
+ analyst: { phrases: ['requirements spec', 'technical spec', 'user story'], keywords: ['requirements', 'spec', 'user story', 'acceptance criteria'], weight: 1.5 },
38
+ orchestrator: { phrases: ['coordinate agents', 'multi-agent', 'orchestrate'], keywords: ['orchestrate', 'coordinate', 'multi-agent'], weight: 2 },
39
+
40
+ // Specialist agents
41
+ api: { phrases: ['api design', 'rest api', 'graphql', 'openapi', 'api endpoint'], keywords: ['api', 'endpoint', 'rest', 'graphql', 'swagger'], weight: 1.2 },
42
+ perf: { phrases: ['optimize performance', 'slow page', 'performance audit', 'speed up'], keywords: ['performance', 'optimize', 'slow', 'speed', 'bottleneck', 'lighthouse'], weight: 1.2 },
43
+ security: { phrases: ['security audit', 'owasp', 'vulnerability scan', 'auth security'], keywords: ['security', 'vulnerability', 'owasp', 'xss', 'injection', 'auth'], weight: 1.2 },
44
+ finance: { phrases: ['payment integration', 'stripe integration', 'billing system', 'subscription'], keywords: ['payment', 'stripe', 'billing', 'subscription', 'invoice'], weight: 1.5 },
45
+ cloud: { phrases: ['deploy to aws', 'terraform', 'serverless', 'cloud architecture'], keywords: ['aws', 'gcp', 'azure', 'terraform', 'serverless', 'lambda', 'cloud'], weight: 1.2 },
46
+ data: { phrases: ['database design', 'schema design', 'prisma migration', 'data model'], keywords: ['database', 'schema', 'prisma', 'migration', 'sql', 'query', 'orm'], weight: 1.2 },
47
+ devops: { phrases: ['docker setup', 'ci/cd pipeline', 'kubernetes', 'deploy pipeline'], keywords: ['docker', 'kubernetes', 'k8s', 'ci/cd', 'pipeline', 'deploy', 'container'], weight: 1.2 },
48
+ i18n: { phrases: ['internationalization', 'add translations', 'multi-language'], keywords: ['i18n', 'translate', 'internationalization', 'locale', 'language'], weight: 1.5 },
49
+ docs: { phrases: ['generate documentation', 'write docs', 'api docs', 'jsdoc'], keywords: ['documentation', 'docs', 'jsdoc', 'readme'], weight: 1 },
50
+ refactor: { phrases: ['refactor code', 'clean up code', 'extract function', 'reduce complexity'], keywords: ['refactor', 'clean up', 'extract', 'simplify', 'complexity'], weight: 1 },
51
+ deps: { phrases: ['update dependencies', 'dependency audit', 'outdated packages'], keywords: ['dependency', 'dependencies', 'outdated', 'update packages', 'npm audit'], weight: 1.5 },
52
+ legal: { phrases: ['gdpr compliance', 'lgpd', 'ccpa', 'privacy policy', 'data protection'], keywords: ['gdpr', 'lgpd', 'ccpa', 'compliance', 'privacy', 'data protection'], weight: 1.5 },
53
+ designer: { phrases: ['design system', 'component library', 'accessibility audit'], keywords: ['design system', 'accessibility', 'a11y', 'ui library', 'theme'], weight: 1.5 },
54
+ tester: { phrases: ['test strategy', 'test coverage', 'e2e tests', 'testing plan'], keywords: ['test strategy', 'coverage', 'e2e', 'testing'], weight: 1 },
55
+
56
+ // Support agents
57
+ scout: { phrases: ['analyze project', 'project analysis', 'quick scan'], keywords: ['analyze', 'scan', 'overview', 'analysis'], weight: 1 },
58
+ explorer: { phrases: ['explore codebase', 'understand code', 'how does this work'], keywords: ['explore', 'understand', 'codebase', 'how does'], weight: 1 },
59
+ };
60
+
61
+ // Descriptions for suggestions
62
+ const AGENT_DESCRIPTIONS = {
63
+ starter: 'creates projects from scratch with best practices',
64
+ builder: 'builds modules, components, and services with tests',
65
+ reviewer: 'provides unified 3-in-1 review (spec, quality, architecture)',
66
+ doctor: 'investigates bugs with systematic 4-phase diagnosis',
67
+ migrator: 'modernizes legacy code to current standards',
68
+ planner: 'creates adaptive implementation plans by complexity',
69
+ executor: 'executes plans with checkpoints and cost tracking',
70
+ tdd: 'implements test-driven development (RED → GREEN → REFACTOR)',
71
+ debugger: 'performs 4-phase systematic debugging with evidence',
72
+ pair: 'provides real-time pair programming assistance',
73
+ analyst: 'converts requirements into technical specifications',
74
+ orchestrator: 'coordinates multiple agents for complex tasks',
75
+ api: 'designs REST/GraphQL APIs with OpenAPI specs',
76
+ perf: 'optimizes performance with measurable improvements',
77
+ security: 'audits for OWASP vulnerabilities and auth issues',
78
+ finance: 'integrates payments, billing, and subscriptions',
79
+ cloud: 'architects cloud infrastructure with IaC',
80
+ data: 'designs database schemas, migrations, and caching',
81
+ devops: 'sets up Docker, K8s, and CI/CD pipelines',
82
+ i18n: 'implements internationalization and translations',
83
+ docs: 'generates documentation from code',
84
+ refactor: 'refactors code for clarity and maintainability',
85
+ deps: 'manages dependencies and security updates',
86
+ legal: 'ensures GDPR, LGPD, CCPA compliance',
87
+ designer: 'creates design systems with accessibility',
88
+ tester: 'designs test strategies and improves coverage',
89
+ scout: 'provides quick project analysis (~500 tokens)',
90
+ explorer: 'performs deep codebase exploration',
91
+ };
92
+
93
+ // ── Intent Matching Engine (exported for testing) ───────────
94
+
95
+ /**
96
+ * Match user prompt against intent map and return best agent suggestion.
97
+ * @param {string} prompt - The user's prompt text
98
+ * @returns {{ agent: string, score: number, description: string } | null}
99
+ */
100
+ export function matchIntent(prompt) {
101
+ if (!prompt || typeof prompt !== 'string') return null;
102
+
103
+ const lower = prompt.toLowerCase().trim();
104
+
105
+ // Skip if user already mentions an @agent explicitly
106
+ if (/@\w+/.test(lower)) return null;
107
+
108
+ // Skip if prompt is too short (likely greeting or simple question)
109
+ if (lower.split(/\s+/).length < 3) return null;
110
+
111
+ const scores = {};
112
+
113
+ for (const [agent, config] of Object.entries(INTENT_MAP)) {
114
+ let score = 0;
115
+
116
+ // Check phrases first (higher specificity)
117
+ for (const phrase of config.phrases || []) {
118
+ if (lower.includes(phrase.toLowerCase())) {
119
+ score += 2 * config.weight;
120
+ }
121
+ }
122
+
123
+ // Check individual keywords
124
+ for (const keyword of config.keywords || []) {
125
+ if (lower.includes(keyword.toLowerCase())) {
126
+ score += 1 * config.weight;
127
+ }
128
+ }
129
+
130
+ if (score > 0) {
131
+ scores[agent] = score;
132
+ }
133
+ }
134
+
135
+ // Find best match
136
+ const entries = Object.entries(scores).sort((a, b) => b[1] - a[1]);
137
+
138
+ if (entries.length === 0) return null;
139
+
140
+ const [bestAgent, bestScore] = entries[0];
141
+
142
+ // Minimum threshold: score must be >= 2 to suggest
143
+ if (bestScore < 2) return null;
144
+
145
+ return {
146
+ agent: bestAgent,
147
+ score: bestScore,
148
+ description: AGENT_DESCRIPTIONS[bestAgent] || '',
149
+ };
150
+ }
151
+
152
+ // ── Main Execution ──────────────────────────────────────────
153
+
154
+ async function main() {
155
+ let input = null;
156
+
157
+ try {
158
+ const data = await new Promise((resolve) => {
159
+ let buf = '';
160
+ const timeout = setTimeout(() => resolve(buf), 3000);
161
+ process.stdin.setEncoding('utf-8');
162
+ process.stdin.on('data', (chunk) => { buf += chunk; });
163
+ process.stdin.on('end', () => { clearTimeout(timeout); resolve(buf); });
164
+ process.stdin.on('error', () => { clearTimeout(timeout); resolve(''); });
165
+ process.stdin.resume();
166
+ });
167
+
168
+ input = data ? JSON.parse(data) : null;
169
+ } catch {
170
+ // Can't parse input — silently allow (this hook is advisory, not blocking)
171
+ process.exit(0);
172
+ }
173
+
174
+ const prompt = input?.prompt || '';
175
+
176
+ if (!prompt) {
177
+ process.exit(0);
178
+ }
179
+
180
+ const match = matchIntent(prompt);
181
+
182
+ if (match) {
183
+ const output = {
184
+ additionalContext: `Specialist Agent suggests: @${match.agent} — ${match.description}. To use it, mention @${match.agent} in your prompt.`,
185
+ };
186
+ process.stdout.write(JSON.stringify(output));
187
+ }
188
+
189
+ process.exit(0);
190
+ }
191
+
192
+ if (process.argv[1] && resolve(process.argv[1]) === resolve(__filename)) {
193
+ main().catch(() => {
194
+ // Advisory hook — never block on error
195
+ process.exit(0);
196
+ });
197
+ }
@@ -0,0 +1,193 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Auto-Format — PostToolUse Hook (Write|Edit)
5
+ *
6
+ * Automatically formats files after Claude writes or edits them.
7
+ * Detects available formatters (prettier, eslint, biome) by config presence.
8
+ * Never fails — if no formatter found, silently exits.
9
+ *
10
+ * Claude Code event: PostToolUse (matcher: "Write|Edit")
11
+ * Stdin: { tool_input: { file_path: "..." } }
12
+ * Output: silent (no additionalContext needed)
13
+ */
14
+
15
+ import { execSync } from 'child_process';
16
+ import { existsSync } from 'fs';
17
+ import { resolve, extname, normalize, join } from 'path';
18
+ import { fileURLToPath } from 'url';
19
+
20
+ const __filename = fileURLToPath(import.meta.url);
21
+
22
+ // ── Supported Extensions ────────────────────────────────────
23
+
24
+ const FORMATTABLE_EXTENSIONS = new Set([
25
+ '.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs',
26
+ '.vue', '.svelte',
27
+ '.css', '.scss', '.less',
28
+ '.json',
29
+ '.html', '.htm',
30
+ '.md', '.mdx',
31
+ '.yaml', '.yml',
32
+ ]);
33
+
34
+ // ── Formatter Detection ─────────────────────────────────────
35
+
36
+ const PRETTIER_CONFIGS = [
37
+ '.prettierrc',
38
+ '.prettierrc.json',
39
+ '.prettierrc.js',
40
+ '.prettierrc.cjs',
41
+ '.prettierrc.mjs',
42
+ '.prettierrc.yml',
43
+ '.prettierrc.yaml',
44
+ '.prettierrc.toml',
45
+ 'prettier.config.js',
46
+ 'prettier.config.cjs',
47
+ 'prettier.config.mjs',
48
+ ];
49
+
50
+ const BIOME_CONFIGS = [
51
+ 'biome.json',
52
+ 'biome.jsonc',
53
+ ];
54
+
55
+ /**
56
+ * Detect which formatter is available in the project.
57
+ * @param {string} cwd - Project root
58
+ * @returns {'prettier' | 'biome' | null}
59
+ */
60
+ export function detectFormatter(cwd) {
61
+ // Check prettier first (most common)
62
+ for (const config of PRETTIER_CONFIGS) {
63
+ if (existsSync(join(cwd, config))) return 'prettier';
64
+ }
65
+
66
+ // Check package.json for prettier key
67
+ try {
68
+ const pkg = JSON.parse(require('fs').readFileSync(join(cwd, 'package.json'), 'utf-8'));
69
+ if (pkg.prettier) return 'prettier';
70
+ } catch {
71
+ // ignore
72
+ }
73
+
74
+ // Check biome
75
+ for (const config of BIOME_CONFIGS) {
76
+ if (existsSync(join(cwd, config))) return 'biome';
77
+ }
78
+
79
+ return null;
80
+ }
81
+
82
+ /**
83
+ * Validate that a file path is within the project directory.
84
+ * Prevents path traversal attacks.
85
+ * @param {string} filePath - File path to validate
86
+ * @param {string} cwd - Project root
87
+ * @returns {boolean}
88
+ */
89
+ export function isWithinProject(filePath, cwd) {
90
+ try {
91
+ const resolved = resolve(filePath);
92
+ const normalizedCwd = resolve(cwd);
93
+ return resolved.startsWith(normalizedCwd);
94
+ } catch {
95
+ return false;
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Format a file using the detected formatter.
101
+ * @param {string} filePath - File to format
102
+ * @param {string} formatter - 'prettier' or 'biome'
103
+ * @param {string} cwd - Project root
104
+ * @returns {boolean} true if formatted successfully
105
+ */
106
+ export function formatFile(filePath, formatter, cwd) {
107
+ try {
108
+ const quotedPath = `"${filePath}"`;
109
+
110
+ if (formatter === 'prettier') {
111
+ execSync(`npx prettier --write ${quotedPath}`, {
112
+ cwd,
113
+ encoding: 'utf-8',
114
+ timeout: 10000,
115
+ stdio: ['pipe', 'pipe', 'pipe'],
116
+ });
117
+ return true;
118
+ }
119
+
120
+ if (formatter === 'biome') {
121
+ execSync(`npx @biomejs/biome format --write ${quotedPath}`, {
122
+ cwd,
123
+ encoding: 'utf-8',
124
+ timeout: 10000,
125
+ stdio: ['pipe', 'pipe', 'pipe'],
126
+ });
127
+ return true;
128
+ }
129
+
130
+ return false;
131
+ } catch {
132
+ return false;
133
+ }
134
+ }
135
+
136
+ // ── Main Execution ──────────────────────────────────────────
137
+
138
+ async function main() {
139
+ let input = null;
140
+
141
+ try {
142
+ const data = await new Promise((resolve) => {
143
+ let buf = '';
144
+ const timeout = setTimeout(() => resolve(buf), 3000);
145
+ process.stdin.setEncoding('utf-8');
146
+ process.stdin.on('data', (chunk) => { buf += chunk; });
147
+ process.stdin.on('end', () => { clearTimeout(timeout); resolve(buf); });
148
+ process.stdin.on('error', () => { clearTimeout(timeout); resolve(''); });
149
+ process.stdin.resume();
150
+ });
151
+
152
+ input = data ? JSON.parse(data) : null;
153
+ } catch {
154
+ process.exit(0);
155
+ }
156
+
157
+ const filePath = input?.tool_input?.file_path;
158
+
159
+ if (!filePath) {
160
+ process.exit(0);
161
+ }
162
+
163
+ // Check extension
164
+ const ext = extname(filePath).toLowerCase();
165
+ if (!FORMATTABLE_EXTENSIONS.has(ext)) {
166
+ process.exit(0);
167
+ }
168
+
169
+ const cwd = process.cwd();
170
+
171
+ // Security: validate path is within project
172
+ if (!isWithinProject(filePath, cwd)) {
173
+ process.exit(0);
174
+ }
175
+
176
+ // Detect formatter
177
+ const formatter = detectFormatter(cwd);
178
+ if (!formatter) {
179
+ process.exit(0);
180
+ }
181
+
182
+ // Format
183
+ formatFile(filePath, formatter, cwd);
184
+
185
+ // Always exit 0 — formatting is best-effort, never blocking
186
+ process.exit(0);
187
+ }
188
+
189
+ if (process.argv[1] && resolve(process.argv[1]) === resolve(__filename)) {
190
+ main().catch(() => {
191
+ process.exit(0);
192
+ });
193
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "$schema": "https://specialist-agent.dev/schemas/security-hooks-v1.json",
3
+ "version": "1.0.0",
4
+ "description": "Security rules for the native security-guard hook. Customize per-project.",
5
+ "enabled": true,
6
+ "rules": {
7
+ "catastrophic-rm": { "enabled": true, "severity": "CRITICAL" },
8
+ "fork-bomb": { "enabled": true, "severity": "CRITICAL" },
9
+ "disk-wipe": { "enabled": true, "severity": "CRITICAL" },
10
+ "force-push-protected": { "enabled": true, "severity": "HIGH" },
11
+ "hard-reset": { "enabled": true, "severity": "HIGH" },
12
+ "sql-destructive": { "enabled": true, "severity": "HIGH" },
13
+ "pipe-to-shell": { "enabled": true, "severity": "HIGH" },
14
+ "chmod-777": { "enabled": true, "severity": "HIGH" },
15
+ "env-file-read": { "enabled": true, "severity": "MEDIUM" },
16
+ "env-file-write": { "enabled": true, "severity": "MEDIUM" },
17
+ "inline-secrets": { "enabled": true, "severity": "MEDIUM" }
18
+ },
19
+ "allowlist": [
20
+ "rm -rf node_modules",
21
+ "rm -rf dist",
22
+ "rm -rf build",
23
+ "rm -rf .next",
24
+ "rm -rf .nuxt",
25
+ "rm -rf .svelte-kit",
26
+ "rm -rf coverage",
27
+ "rm -rf .turbo",
28
+ "rm -rf .cache"
29
+ ],
30
+ "protectedBranches": ["main", "master", "production", "release"]
31
+ }