start-vibing 3.0.7 → 3.0.9
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/README.md +64 -51
- package/package.json +1 -1
- package/template/.claude/CLAUDE.md +717 -229
- package/template/.claude/agents/claude-md-compactor.md +2 -14
- package/template/.claude/agents/documenter.md +0 -7
- package/template/.claude/agents/domain-updater.md +2 -7
- package/template/.claude/config/README.md +10 -8
- package/template/.claude/config/domain-mapping.json +1 -1
- package/template/.claude/settings.json +0 -129
- package/template/.claude/skills/api-docs/SKILL.md +206 -0
- package/template/.claude/skills/claude-seo/SKILL.md +84 -0
- package/template/.claude/skills/codebase-knowledge/domains/claude-system.md +51 -416
- package/template/.claude/skills/codebase-knowledge/domains/mcp-integration.md +37 -204
- package/template/.claude/skills/mongoose-patterns/SKILL.md +141 -452
- package/template/.claude/skills/playwright-testing/SKILL.md +251 -0
- package/template/.claude/skills/skill-creator/SKILL.md +106 -0
- package/template/.claude/skills/test-infrastructure/SKILL.md +242 -0
- package/template/CLAUDE.md +65 -701
- package/template/.claude/agents/_archive/01-orchestration/agent-selector.md +0 -130
- package/template/.claude/agents/_archive/01-orchestration/checkpoint-manager.md +0 -142
- package/template/.claude/agents/_archive/01-orchestration/context-manager.md +0 -138
- package/template/.claude/agents/_archive/01-orchestration/error-recovery.md +0 -182
- package/template/.claude/agents/_archive/01-orchestration/orchestrator.md +0 -114
- package/template/.claude/agents/_archive/01-orchestration/parallel-coordinator.md +0 -141
- package/template/.claude/agents/_archive/01-orchestration/task-decomposer.md +0 -121
- package/template/.claude/agents/_archive/01-orchestration/workflow-router.md +0 -119
- package/template/.claude/agents/_archive/02-typescript/bun-runtime-expert.md +0 -197
- package/template/.claude/agents/_archive/02-typescript/esm-resolver.md +0 -193
- package/template/.claude/agents/_archive/02-typescript/import-alias-enforcer.md +0 -158
- package/template/.claude/agents/_archive/02-typescript/ts-generics-helper.md +0 -183
- package/template/.claude/agents/_archive/02-typescript/ts-migration-helper.md +0 -238
- package/template/.claude/agents/_archive/02-typescript/ts-strict-checker.md +0 -180
- package/template/.claude/agents/_archive/02-typescript/ts-types-analyzer.md +0 -199
- package/template/.claude/agents/_archive/02-typescript/type-definition-writer.md +0 -187
- package/template/.claude/agents/_archive/02-typescript/zod-schema-designer.md +0 -212
- package/template/.claude/agents/_archive/02-typescript/zod-validator.md +0 -158
- package/template/.claude/agents/_archive/03-testing/playwright-assertions.md +0 -265
- package/template/.claude/agents/_archive/03-testing/playwright-e2e.md +0 -247
- package/template/.claude/agents/_archive/03-testing/playwright-fixtures.md +0 -234
- package/template/.claude/agents/_archive/03-testing/playwright-multi-viewport.md +0 -256
- package/template/.claude/agents/_archive/03-testing/playwright-page-objects.md +0 -247
- package/template/.claude/agents/_archive/03-testing/test-cleanup-manager.md +0 -248
- package/template/.claude/agents/_archive/03-testing/test-data-generator.md +0 -254
- package/template/.claude/agents/_archive/03-testing/tester-integration.md +0 -278
- package/template/.claude/agents/_archive/03-testing/tester-unit.md +0 -207
- package/template/.claude/agents/_archive/03-testing/vitest-config.md +0 -287
- package/template/.claude/agents/_archive/04-docker/container-health.md +0 -255
- package/template/.claude/agents/_archive/04-docker/deployment-validator.md +0 -225
- package/template/.claude/agents/_archive/04-docker/docker-compose-designer.md +0 -281
- package/template/.claude/agents/_archive/04-docker/docker-env-manager.md +0 -235
- package/template/.claude/agents/_archive/04-docker/docker-multi-stage.md +0 -241
- package/template/.claude/agents/_archive/04-docker/dockerfile-optimizer.md +0 -208
- package/template/.claude/agents/_archive/05-database/database-seeder.md +0 -273
- package/template/.claude/agents/_archive/05-database/mongodb-query-optimizer.md +0 -230
- package/template/.claude/agents/_archive/05-database/mongoose-aggregation.md +0 -306
- package/template/.claude/agents/_archive/05-database/mongoose-index-optimizer.md +0 -182
- package/template/.claude/agents/_archive/05-database/mongoose-schema-designer.md +0 -267
- package/template/.claude/agents/_archive/06-security/auth-session-validator.md +0 -68
- package/template/.claude/agents/_archive/06-security/input-sanitizer.md +0 -80
- package/template/.claude/agents/_archive/06-security/owasp-checker.md +0 -97
- package/template/.claude/agents/_archive/06-security/permission-auditor.md +0 -100
- package/template/.claude/agents/_archive/06-security/security-auditor.md +0 -84
- package/template/.claude/agents/_archive/06-security/sensitive-data-scanner.md +0 -83
- package/template/.claude/agents/_archive/07-documentation/api-documenter.md +0 -136
- package/template/.claude/agents/_archive/07-documentation/changelog-manager.md +0 -105
- package/template/.claude/agents/_archive/07-documentation/claude-md-compactor.md +0 -214
- package/template/.claude/agents/_archive/07-documentation/documenter.md +0 -184
- package/template/.claude/agents/_archive/07-documentation/domain-updater.md +0 -138
- package/template/.claude/agents/_archive/07-documentation/jsdoc-generator.md +0 -114
- package/template/.claude/agents/_archive/07-documentation/readme-generator.md +0 -135
- package/template/.claude/agents/_archive/08-git/branch-manager.md +0 -58
- package/template/.claude/agents/_archive/08-git/commit-manager.md +0 -78
- package/template/.claude/agents/_archive/09-quality/code-reviewer.md +0 -71
- package/template/.claude/agents/_archive/09-quality/quality-checker.md +0 -67
- package/template/.claude/agents/_archive/10-research/best-practices-finder.md +0 -89
- package/template/.claude/agents/_archive/10-research/competitor-analyzer.md +0 -106
- package/template/.claude/agents/_archive/10-research/pattern-researcher.md +0 -93
- package/template/.claude/agents/_archive/10-research/research-cache-manager.md +0 -76
- package/template/.claude/agents/_archive/10-research/research-web.md +0 -98
- package/template/.claude/agents/_archive/10-research/tech-evaluator.md +0 -101
- package/template/.claude/agents/_archive/11-ui-ux/accessibility-auditor.md +0 -136
- package/template/.claude/agents/_archive/11-ui-ux/design-system-enforcer.md +0 -125
- package/template/.claude/agents/_archive/11-ui-ux/skeleton-generator.md +0 -118
- package/template/.claude/agents/_archive/11-ui-ux/ui-desktop.md +0 -132
- package/template/.claude/agents/_archive/11-ui-ux/ui-mobile.md +0 -125
- package/template/.claude/agents/_archive/11-ui-ux/ui-tablet.md +0 -110
- package/template/.claude/agents/_archive/12-performance/api-latency-analyzer.md +0 -156
- package/template/.claude/agents/_archive/12-performance/bundle-analyzer.md +0 -113
- package/template/.claude/agents/_archive/12-performance/memory-leak-detector.md +0 -137
- package/template/.claude/agents/_archive/12-performance/performance-profiler.md +0 -115
- package/template/.claude/agents/_archive/12-performance/query-optimizer.md +0 -124
- package/template/.claude/agents/_archive/12-performance/render-optimizer.md +0 -154
- package/template/.claude/agents/_archive/13-debugging/build-error-fixer.md +0 -207
- package/template/.claude/agents/_archive/13-debugging/debugger.md +0 -149
- package/template/.claude/agents/_archive/13-debugging/error-stack-analyzer.md +0 -141
- package/template/.claude/agents/_archive/13-debugging/network-debugger.md +0 -208
- package/template/.claude/agents/_archive/13-debugging/runtime-error-fixer.md +0 -181
- package/template/.claude/agents/_archive/13-debugging/type-error-resolver.md +0 -185
- package/template/.claude/agents/_archive/14-validation/final-validator.md +0 -93
- package/template/.claude/agents/_archive/_backup/analyzer.md +0 -134
- package/template/.claude/agents/_archive/_backup/code-reviewer.md +0 -279
- package/template/.claude/agents/_archive/_backup/commit-manager.md +0 -219
- package/template/.claude/agents/_archive/_backup/debugger.md +0 -280
- package/template/.claude/agents/_archive/_backup/documenter.md +0 -237
- package/template/.claude/agents/_archive/_backup/domain-updater.md +0 -197
- package/template/.claude/agents/_archive/_backup/final-validator.md +0 -169
- package/template/.claude/agents/_archive/_backup/orchestrator.md +0 -149
- package/template/.claude/agents/_archive/_backup/performance.md +0 -232
- package/template/.claude/agents/_archive/_backup/quality-checker.md +0 -240
- package/template/.claude/agents/_archive/_backup/research.md +0 -315
- package/template/.claude/agents/_archive/_backup/security-auditor.md +0 -192
- package/template/.claude/agents/_archive/_backup/tester.md +0 -566
- package/template/.claude/agents/_archive/_backup/ui-ux-reviewer.md +0 -247
- package/template/.claude/commands/feature.md +0 -48
- package/template/.claude/commands/fix.md +0 -80
- package/template/.claude/commands/research.md +0 -107
- package/template/.claude/commands/validate.md +0 -72
- package/template/.claude/config/mcp-config.json +0 -344
- package/template/.claude/hooks/SETUP.md +0 -126
- package/template/.claude/hooks/run-hook.cmd +0 -46
- package/template/.claude/hooks/run-hook.sh +0 -43
- package/template/.claude/hooks/run-hook.ts +0 -230
- package/template/.claude/hooks/security-check.js +0 -202
- package/template/.claude/hooks/stop-validator.ts +0 -1667
- package/template/.claude/hooks/user-prompt-submit.ts +0 -104
- package/template/.claude/scripts/mcp-quick-install.ts +0 -151
- package/template/.claude/scripts/setup-mcps.ts +0 -651
- package/template/.claude/skills/hook-development/SKILL.md +0 -343
- package/template/.claude/skills/playwright-automation/SKILL.md +0 -438
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Universal Hook Runner
|
|
4
|
-
*
|
|
5
|
-
* Runs hooks with multiple runtime fallbacks:
|
|
6
|
-
* 1. bun (primary - fastest TypeScript execution)
|
|
7
|
-
* 2. npx tsx (TypeScript fallback)
|
|
8
|
-
* 3. python3 (Python fallback)
|
|
9
|
-
* 4. python (Python fallback)
|
|
10
|
-
*
|
|
11
|
-
* IMPORTANT: TypeScript files are the source of truth.
|
|
12
|
-
* Python files are only for environments without Node.js/Bun.
|
|
13
|
-
*
|
|
14
|
-
* Usage: npx tsx run-hook.ts <hook-name>
|
|
15
|
-
* The hook-name should be without extension (e.g., "stop-validator")
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { spawnSync } from 'child_process';
|
|
19
|
-
import { existsSync, unlinkSync } from 'fs';
|
|
20
|
-
import { join, dirname } from 'path';
|
|
21
|
-
import { fileURLToPath } from 'url';
|
|
22
|
-
|
|
23
|
-
// Get hooks directory - handle both ESM and CJS contexts
|
|
24
|
-
const getHooksDir = (): string => {
|
|
25
|
-
try {
|
|
26
|
-
if (typeof import.meta.url !== 'undefined') {
|
|
27
|
-
return dirname(fileURLToPath(import.meta.url));
|
|
28
|
-
}
|
|
29
|
-
} catch {
|
|
30
|
-
// Fallback for environments where import.meta is not available
|
|
31
|
-
}
|
|
32
|
-
return process.cwd();
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const HOOKS_DIR = getHooksDir();
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Remove deprecated settings.local.json if it exists.
|
|
39
|
-
* This file was previously tracked but should not be used anymore.
|
|
40
|
-
* All hooks should use the universal runner via settings.json.
|
|
41
|
-
*/
|
|
42
|
-
function cleanupDeprecatedFiles(): void {
|
|
43
|
-
const claudeDir = join(HOOKS_DIR, '..');
|
|
44
|
-
const settingsLocalPath = join(claudeDir, 'settings.local.json');
|
|
45
|
-
|
|
46
|
-
if (existsSync(settingsLocalPath)) {
|
|
47
|
-
try {
|
|
48
|
-
unlinkSync(settingsLocalPath);
|
|
49
|
-
console.error('[run-hook] Removed deprecated settings.local.json');
|
|
50
|
-
} catch {
|
|
51
|
-
// Ignore errors - file may be locked or read-only
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function checkRuntime(cmd: string): boolean {
|
|
57
|
-
try {
|
|
58
|
-
const result = spawnSync(cmd, ['--version'], {
|
|
59
|
-
stdio: 'pipe',
|
|
60
|
-
shell: true,
|
|
61
|
-
timeout: 5000,
|
|
62
|
-
windowsHide: true,
|
|
63
|
-
});
|
|
64
|
-
return result.status === 0;
|
|
65
|
-
} catch {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
interface RuntimeResult {
|
|
71
|
-
exitCode: number;
|
|
72
|
-
output: string;
|
|
73
|
-
error?: string;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function runWithRuntime(
|
|
77
|
-
cmd: string,
|
|
78
|
-
args: string[],
|
|
79
|
-
input: string
|
|
80
|
-
): RuntimeResult {
|
|
81
|
-
try {
|
|
82
|
-
const result = spawnSync(cmd, args, {
|
|
83
|
-
input,
|
|
84
|
-
shell: true,
|
|
85
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
86
|
-
timeout: 30000,
|
|
87
|
-
windowsHide: true,
|
|
88
|
-
encoding: 'utf8',
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
exitCode: result.status ?? 1,
|
|
93
|
-
output: result.stdout?.toString() || '',
|
|
94
|
-
error: result.stderr?.toString() || undefined,
|
|
95
|
-
};
|
|
96
|
-
} catch (err) {
|
|
97
|
-
return {
|
|
98
|
-
exitCode: 1,
|
|
99
|
-
output: '',
|
|
100
|
-
error: err instanceof Error ? err.message : 'Unknown error',
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async function runHook(hookName: string, stdinData: string): Promise<void> {
|
|
106
|
-
const tsPath = join(HOOKS_DIR, `${hookName}.ts`);
|
|
107
|
-
|
|
108
|
-
// Runtime detection order - TypeScript ONLY (source of truth)
|
|
109
|
-
// Python files are deprecated and should be removed
|
|
110
|
-
const runtimes: Array<{ name: string; cmd: string }> = [
|
|
111
|
-
{ name: 'bun', cmd: 'bun' },
|
|
112
|
-
{ name: 'npx-tsx', cmd: 'npx tsx' },
|
|
113
|
-
];
|
|
114
|
-
|
|
115
|
-
for (const runtime of runtimes) {
|
|
116
|
-
if (!existsSync(tsPath)) {
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (!checkRuntime(runtime.cmd.split(' ')[0])) {
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const result = runWithRuntime(runtime.cmd, [tsPath], stdinData);
|
|
125
|
-
|
|
126
|
-
// Handle exit codes according to Claude Code hook specification:
|
|
127
|
-
// - Exit code 0: Success (stdout in transcript)
|
|
128
|
-
// - Exit code 2: Blocking error (stderr feeds back to Claude)
|
|
129
|
-
// - Other: Non-blocking error
|
|
130
|
-
|
|
131
|
-
if (result.exitCode === 0) {
|
|
132
|
-
// Success - output stdout
|
|
133
|
-
process.stdout.write(result.output);
|
|
134
|
-
process.exit(0);
|
|
135
|
-
} else if (result.exitCode === 2) {
|
|
136
|
-
// Blocking error - for Stop hooks, JSON is in stdout
|
|
137
|
-
// Pass through both stdout (JSON response) and stderr (debug logs)
|
|
138
|
-
process.stdout.write(result.output);
|
|
139
|
-
if (result.error) {
|
|
140
|
-
process.stderr.write(result.error);
|
|
141
|
-
}
|
|
142
|
-
process.exit(2);
|
|
143
|
-
} else {
|
|
144
|
-
// Non-blocking error or runtime not found
|
|
145
|
-
if (result.error?.includes('not found')) {
|
|
146
|
-
// Runtime not available, try next
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
// Hook failed but not blocking
|
|
150
|
-
process.stdout.write(result.output);
|
|
151
|
-
if (result.error) {
|
|
152
|
-
process.stderr.write(result.error);
|
|
153
|
-
}
|
|
154
|
-
process.exit(result.exitCode);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// No runtime available - return safe default
|
|
159
|
-
console.error(`[run-hook] No runtime available to run hook: ${hookName}`);
|
|
160
|
-
console.error('[run-hook] Please install bun or Node.js (for npx tsx)');
|
|
161
|
-
const safeDefault = JSON.stringify({
|
|
162
|
-
decision: 'approve',
|
|
163
|
-
continue: true,
|
|
164
|
-
reason: 'Hook runtime not available, allowing by default',
|
|
165
|
-
});
|
|
166
|
-
process.stdout.write(safeDefault);
|
|
167
|
-
process.exit(0);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async function readStdinWithTimeout(timeoutMs: number): Promise<string> {
|
|
171
|
-
return new Promise((resolve) => {
|
|
172
|
-
const timeout = setTimeout(() => {
|
|
173
|
-
process.stdin.destroy();
|
|
174
|
-
resolve('{}');
|
|
175
|
-
}, timeoutMs);
|
|
176
|
-
|
|
177
|
-
let data = '';
|
|
178
|
-
process.stdin.setEncoding('utf8');
|
|
179
|
-
process.stdin.on('data', (chunk: string) => {
|
|
180
|
-
data += chunk;
|
|
181
|
-
});
|
|
182
|
-
process.stdin.on('end', () => {
|
|
183
|
-
clearTimeout(timeout);
|
|
184
|
-
resolve(data || '{}');
|
|
185
|
-
});
|
|
186
|
-
process.stdin.on('error', () => {
|
|
187
|
-
clearTimeout(timeout);
|
|
188
|
-
resolve('{}');
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// Handle case where stdin is empty/closed immediately
|
|
192
|
-
if (process.stdin.readableEnded) {
|
|
193
|
-
clearTimeout(timeout);
|
|
194
|
-
resolve('{}');
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Main
|
|
200
|
-
async function main(): Promise<void> {
|
|
201
|
-
// Log hook invocation for debugging (writes to stderr so it doesn't affect JSON output)
|
|
202
|
-
const hookName = process.argv[2];
|
|
203
|
-
const timestamp = new Date().toISOString();
|
|
204
|
-
console.error(`[run-hook] ${timestamp} - Hook invoked: ${hookName || 'none'}`);
|
|
205
|
-
|
|
206
|
-
// Clean up deprecated files on every hook run
|
|
207
|
-
cleanupDeprecatedFiles();
|
|
208
|
-
|
|
209
|
-
if (!hookName) {
|
|
210
|
-
console.error('[run-hook] Usage: bun run-hook.ts <hook-name>');
|
|
211
|
-
process.exit(1);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Read stdin with timeout to avoid hanging
|
|
215
|
-
const stdinData = await readStdinWithTimeout(2000);
|
|
216
|
-
console.error(`[run-hook] ${hookName} - stdin received, length: ${stdinData.length}`);
|
|
217
|
-
await runHook(hookName, stdinData);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
main().catch((err) => {
|
|
221
|
-
console.error('[run-hook] Fatal error:', err);
|
|
222
|
-
// Return safe default on error
|
|
223
|
-
const safeDefault = JSON.stringify({
|
|
224
|
-
decision: 'approve',
|
|
225
|
-
continue: true,
|
|
226
|
-
reason: 'Hook runner error, allowing by default',
|
|
227
|
-
});
|
|
228
|
-
process.stdout.write(safeDefault);
|
|
229
|
-
process.exit(0);
|
|
230
|
-
});
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook de Seguranca Pre-Tool
|
|
3
|
-
*
|
|
4
|
-
* Este hook e executado ANTES de qualquer ferramenta ser chamada.
|
|
5
|
-
* Sua funcao e bloquear acoes potencialmente perigosas.
|
|
6
|
-
*
|
|
7
|
-
* Baseado em: OpenSSF Security Guide for AI Code Assistants
|
|
8
|
-
* https://best.openssf.org/Security-Focused-Guide-for-AI-Code-Assistant-Instructions
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// Padroes perigosos que devem ser bloqueados
|
|
12
|
-
const DANGEROUS_PATTERNS = {
|
|
13
|
-
// Comandos destrutivos
|
|
14
|
-
commands: [
|
|
15
|
-
/rm\s+-rf\s+[\/~]/i, // rm -rf com path perigoso
|
|
16
|
-
/rm\s+-rf\s+\*/i, // rm -rf *
|
|
17
|
-
/sudo\s+rm/i, // sudo rm
|
|
18
|
-
/mkfs/i, // formatar disco
|
|
19
|
-
/dd\s+if=/i, // dd (pode destruir dados)
|
|
20
|
-
/>\s*\/dev\//i, // escrever em devices
|
|
21
|
-
/chmod\s+777/i, // permissoes muito abertas
|
|
22
|
-
/curl.*\|\s*(ba)?sh/i, // curl pipe to shell
|
|
23
|
-
/wget.*\|\s*(ba)?sh/i, // wget pipe to shell
|
|
24
|
-
],
|
|
25
|
-
|
|
26
|
-
// Padroes de codigo inseguro
|
|
27
|
-
code: [
|
|
28
|
-
/eval\s*\(/i, // eval()
|
|
29
|
-
/new\s+Function\s*\(/i, // new Function()
|
|
30
|
-
/innerHTML\s*=/i, // innerHTML assignment (XSS)
|
|
31
|
-
/document\.write\s*\(/i, // document.write (XSS)
|
|
32
|
-
/dangerouslySetInnerHTML/i, // React dangerous prop
|
|
33
|
-
/\$\{.*\}\s*\)/i, // Template injection em queries
|
|
34
|
-
],
|
|
35
|
-
|
|
36
|
-
// Exposicao de dados sensiveis
|
|
37
|
-
sensitive: [
|
|
38
|
-
/password\s*[:=]/i, // Senha hardcoded
|
|
39
|
-
/api[_-]?key\s*[:=]/i, // API key hardcoded
|
|
40
|
-
/secret\s*[:=]/i, // Secret hardcoded
|
|
41
|
-
/private[_-]?key/i, // Private key
|
|
42
|
-
/BEGIN\s+(RSA|DSA|EC)\s+PRIVATE/i, // Chave privada PEM
|
|
43
|
-
],
|
|
44
|
-
|
|
45
|
-
// Patterns especificos do projeto
|
|
46
|
-
project: [
|
|
47
|
-
/userId.*req\.body/i, // userId do request body
|
|
48
|
-
/userId.*input\./i, // userId do input tRPC
|
|
49
|
-
/findById\(.*input/i, // Query sem validacao de owner
|
|
50
|
-
/z\.any\(\)/i, // Zod any (sem validacao)
|
|
51
|
-
],
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// Arquivos que nao devem ser modificados
|
|
55
|
-
const PROTECTED_FILES = ['.env', '.env.local', '.env.production', '.env.development', 'bun.lockb'];
|
|
56
|
-
|
|
57
|
-
// Diretorios que nao devem ser acessados
|
|
58
|
-
const PROTECTED_DIRS = ['/etc', '/var', '/usr', '/root', '/home', 'node_modules', '.git/objects'];
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Verifica se um comando/codigo contem padroes perigosos
|
|
62
|
-
* @param {string} content - Conteudo a verificar
|
|
63
|
-
* @param {string} category - Categoria de padroes
|
|
64
|
-
* @returns {Object} - { blocked: boolean, reason: string }
|
|
65
|
-
*/
|
|
66
|
-
function checkDangerousPatterns(content, category) {
|
|
67
|
-
const patterns = DANGEROUS_PATTERNS[category] || [];
|
|
68
|
-
|
|
69
|
-
for (const pattern of patterns) {
|
|
70
|
-
if (pattern.test(content)) {
|
|
71
|
-
return {
|
|
72
|
-
blocked: true,
|
|
73
|
-
reason: `Padrao perigoso detectado: ${pattern.toString()}`,
|
|
74
|
-
category,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return { blocked: false };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Verifica se um arquivo e protegido
|
|
84
|
-
* @param {string} filePath - Caminho do arquivo
|
|
85
|
-
* @returns {boolean}
|
|
86
|
-
*/
|
|
87
|
-
function isProtectedFile(filePath) {
|
|
88
|
-
return PROTECTED_FILES.some(
|
|
89
|
-
(protected) => filePath.endsWith(protected) || filePath.includes(protected)
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Verifica se um diretorio e protegido
|
|
95
|
-
* @param {string} dirPath - Caminho do diretorio
|
|
96
|
-
* @returns {boolean}
|
|
97
|
-
*/
|
|
98
|
-
function isProtectedDir(dirPath) {
|
|
99
|
-
return PROTECTED_DIRS.some(
|
|
100
|
-
(protected) => dirPath.startsWith(protected) || dirPath.includes(protected)
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Hook principal - executado antes de cada tool call
|
|
106
|
-
* @param {Object} toolCall - Dados da chamada de ferramenta
|
|
107
|
-
* @returns {Object} - { allowed: boolean, reason?: string }
|
|
108
|
-
*/
|
|
109
|
-
function preToolHook(toolCall) {
|
|
110
|
-
const { name, args } = toolCall;
|
|
111
|
-
|
|
112
|
-
// Verificar comandos bash
|
|
113
|
-
if (name === 'bash' && args.command) {
|
|
114
|
-
const result = checkDangerousPatterns(args.command, 'commands');
|
|
115
|
-
if (result.blocked) {
|
|
116
|
-
return {
|
|
117
|
-
allowed: false,
|
|
118
|
-
reason: `Comando bloqueado: ${result.reason}`,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Verificar escrita de arquivos
|
|
124
|
-
if (['file_write', 'file_edit'].includes(name)) {
|
|
125
|
-
// Verificar arquivo protegido
|
|
126
|
-
if (args.path && isProtectedFile(args.path)) {
|
|
127
|
-
return {
|
|
128
|
-
allowed: false,
|
|
129
|
-
reason: `Arquivo protegido: ${args.path}`,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Verificar conteudo perigoso
|
|
134
|
-
if (args.content) {
|
|
135
|
-
const codeResult = checkDangerousPatterns(args.content, 'code');
|
|
136
|
-
if (codeResult.blocked) {
|
|
137
|
-
return {
|
|
138
|
-
allowed: false,
|
|
139
|
-
reason: `Codigo inseguro: ${codeResult.reason}`,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const sensitiveResult = checkDangerousPatterns(args.content, 'sensitive');
|
|
144
|
-
if (sensitiveResult.blocked) {
|
|
145
|
-
return {
|
|
146
|
-
allowed: false,
|
|
147
|
-
reason: `Dados sensiveis detectados: ${sensitiveResult.reason}`,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const projectResult = checkDangerousPatterns(args.content, 'project');
|
|
152
|
-
if (projectResult.blocked) {
|
|
153
|
-
return {
|
|
154
|
-
allowed: false,
|
|
155
|
-
reason: `Violacao de regra do projeto: ${projectResult.reason}`,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Verificar leitura de diretorios protegidos
|
|
162
|
-
if (name === 'file_read' && args.path) {
|
|
163
|
-
if (isProtectedDir(args.path)) {
|
|
164
|
-
return {
|
|
165
|
-
allowed: false,
|
|
166
|
-
reason: `Diretorio protegido: ${args.path}`,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Permitir por padrao
|
|
172
|
-
return { allowed: true };
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Log de seguranca para auditoria
|
|
177
|
-
* @param {string} action - Acao tomada
|
|
178
|
-
* @param {Object} details - Detalhes
|
|
179
|
-
*/
|
|
180
|
-
function logSecurityEvent(action, details) {
|
|
181
|
-
const timestamp = new Date().toISOString();
|
|
182
|
-
const logEntry = {
|
|
183
|
-
timestamp,
|
|
184
|
-
action,
|
|
185
|
-
...details,
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
// Em producao, enviar para sistema de logging
|
|
189
|
-
console.log('[SECURITY]', JSON.stringify(logEntry));
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Exportar para uso pelo SDK
|
|
193
|
-
module.exports = {
|
|
194
|
-
preToolHook,
|
|
195
|
-
checkDangerousPatterns,
|
|
196
|
-
isProtectedFile,
|
|
197
|
-
isProtectedDir,
|
|
198
|
-
logSecurityEvent,
|
|
199
|
-
DANGEROUS_PATTERNS,
|
|
200
|
-
PROTECTED_FILES,
|
|
201
|
-
PROTECTED_DIRS,
|
|
202
|
-
};
|