@su-record/vibe 2.8.24 → 2.8.25
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/dist/cli/commands/config.d.ts +17 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +207 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/index.d.ts +2 -0
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +2 -0
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/info.d.ts.map +1 -1
- package/dist/cli/commands/info.js +2 -0
- package/dist/cli/commands/info.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +78 -54
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/stats.d.ts +13 -0
- package/dist/cli/commands/stats.d.ts.map +1 -0
- package/dist/cli/commands/stats.js +280 -0
- package/dist/cli/commands/stats.js.map +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +33 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/postinstall/constants.d.ts.map +1 -1
- package/dist/cli/postinstall/constants.js +1 -0
- package/dist/cli/postinstall/constants.js.map +1 -1
- package/dist/cli/setup/GlobalInstaller.d.ts.map +1 -1
- package/dist/cli/setup/GlobalInstaller.js +7 -7
- package/dist/cli/setup/GlobalInstaller.js.map +1 -1
- package/dist/cli/setup/ProjectSetup.d.ts.map +1 -1
- package/dist/cli/setup/ProjectSetup.js +18 -12
- package/dist/cli/setup/ProjectSetup.js.map +1 -1
- package/dist/infra/lib/ContextCompressor.d.ts.map +1 -1
- package/dist/infra/lib/ContextCompressor.js +10 -4
- package/dist/infra/lib/ContextCompressor.js.map +1 -1
- package/dist/infra/lib/ProjectCache.d.ts +2 -2
- package/dist/infra/lib/ProjectCache.d.ts.map +1 -1
- package/dist/infra/lib/ProjectCache.js +4 -3
- package/dist/infra/lib/ProjectCache.js.map +1 -1
- package/dist/infra/lib/utils.d.ts +24 -0
- package/dist/infra/lib/utils.d.ts.map +1 -1
- package/dist/infra/lib/utils.js +41 -0
- package/dist/infra/lib/utils.js.map +1 -1
- package/dist/infra/orchestrator/SmartRouter.d.ts +3 -0
- package/dist/infra/orchestrator/SmartRouter.d.ts.map +1 -1
- package/dist/infra/orchestrator/SmartRouter.js +11 -1
- package/dist/infra/orchestrator/SmartRouter.js.map +1 -1
- package/dist/infra/orchestrator/SmartRouter.test.d.ts +5 -0
- package/dist/infra/orchestrator/SmartRouter.test.d.ts.map +1 -0
- package/dist/infra/orchestrator/SmartRouter.test.js +457 -0
- package/dist/infra/orchestrator/SmartRouter.test.js.map +1 -0
- package/dist/tools/convention/analyzeComplexity.d.ts.map +1 -1
- package/dist/tools/convention/analyzeComplexity.js +18 -10
- package/dist/tools/convention/analyzeComplexity.js.map +1 -1
- package/dist/tools/convention/checkCouplingCohesion.d.ts.map +1 -1
- package/dist/tools/convention/checkCouplingCohesion.js +14 -6
- package/dist/tools/convention/checkCouplingCohesion.js.map +1 -1
- package/dist/tools/semantic/analyzeDependencyGraph.d.ts.map +1 -1
- package/dist/tools/semantic/analyzeDependencyGraph.js +1 -1
- package/dist/tools/semantic/analyzeDependencyGraph.js.map +1 -1
- package/dist/tools/semantic/findReferences.d.ts.map +1 -1
- package/dist/tools/semantic/findReferences.js +13 -13
- package/dist/tools/semantic/findReferences.js.map +1 -1
- package/dist/tools/semantic/findSymbol.d.ts.map +1 -1
- package/dist/tools/semantic/findSymbol.js +12 -13
- package/dist/tools/semantic/findSymbol.js.map +1 -1
- package/dist/tools/semantic/lsp.d.ts.map +1 -1
- package/dist/tools/semantic/lsp.js +22 -14
- package/dist/tools/semantic/lsp.js.map +1 -1
- package/hooks/hooks.json +29 -0
- package/hooks/scripts/__tests__/keyword-detector.test.js +199 -0
- package/hooks/scripts/__tests__/pre-tool-guard.test.js +286 -0
- package/hooks/scripts/__tests__/sentinel-guard.test.js +210 -0
- package/hooks/scripts/auto-commit.js +65 -0
- package/hooks/scripts/auto-format.js +64 -0
- package/hooks/scripts/auto-test.js +81 -0
- package/hooks/scripts/code-check.js +139 -0
- package/hooks/scripts/command-log.js +32 -0
- package/hooks/scripts/context-save.js +60 -6
- package/hooks/scripts/hud-status.js +32 -2
- package/hooks/scripts/llm-orchestrate.js +95 -17
- package/hooks/scripts/pr-test-gate.js +52 -0
- package/package.json +1 -1
- package/skills/agents-md/rubrics/what-to-keep.md +49 -0
- package/skills/agents-md/templates/agents-md.md +36 -0
- package/skills/arch-guard/agents/detector.md +48 -0
- package/skills/arch-guard/agents/reporter.md +48 -0
- package/skills/arch-guard/agents/rule-generator.md +49 -0
- package/skills/arch-guard/agents/violation-checker.md +51 -0
- package/skills/arch-guard/frameworks/clean-architecture.md +108 -0
- package/skills/arch-guard/frameworks/solid.md +102 -0
- package/skills/arch-guard/scripts/check-boundaries.js +90 -0
- package/skills/arch-guard/templates/arch-rules.json +47 -0
- package/skills/arch-guard/templates/violation-report.md +53 -0
- package/skills/brand-assets/rubrics/asset-checklist.md +98 -0
- package/skills/brand-assets/templates/brand-guide.md +161 -0
- package/skills/capability-loop/agents/capability-designer.md +61 -0
- package/skills/capability-loop/agents/failure-analyst.md +55 -0
- package/skills/capability-loop/agents/implementer.md +50 -0
- package/skills/capability-loop/agents/tester.md +53 -0
- package/skills/capability-loop/templates/capability-spec.md +118 -0
- package/skills/capability-loop/templates/failure-analysis.md +118 -0
- package/skills/characterization-test/agents/behavior-capturer.md +50 -0
- package/skills/characterization-test/agents/coverage-checker.md +54 -0
- package/skills/characterization-test/agents/reporter.md +50 -0
- package/skills/characterization-test/agents/test-writer.md +49 -0
- package/skills/characterization-test/rubrics/coverage-criteria.md +53 -0
- package/skills/characterization-test/templates/test-template.ts +101 -0
- package/skills/claude-md-guide/rubrics/anti-patterns.md +88 -0
- package/skills/claude-md-guide/templates/claude-md.md +54 -0
- package/skills/commerce-patterns/rubrics/checkout-flow.md +48 -0
- package/skills/commerce-patterns/templates/product-schema.md +85 -0
- package/skills/commit-push-pr/agents/change-analyzer.md +55 -0
- package/skills/commit-push-pr/agents/message-writer.md +50 -0
- package/skills/commit-push-pr/agents/pr-writer.md +58 -0
- package/skills/commit-push-pr/agents/reviewer.md +52 -0
- package/skills/commit-push-pr/rubrics/commit-message.md +73 -0
- package/skills/commit-push-pr/templates/pr-body.md +63 -0
- package/skills/context7-usage/rubrics/when-to-use.md +50 -0
- package/skills/create-prd/agents/edge-case-finder.md +48 -0
- package/skills/create-prd/agents/prioritizer.md +60 -0
- package/skills/create-prd/agents/requirements-writer.md +48 -0
- package/skills/create-prd/agents/researcher.md +55 -0
- package/skills/create-prd/agents/reviewer.md +54 -0
- package/skills/create-prd/frameworks/jobs-to-be-done.md +96 -0
- package/skills/create-prd/frameworks/rice-scoring.md +97 -0
- package/skills/create-prd/orchestrator.md +70 -0
- package/skills/create-prd/rubrics/completeness.md +58 -0
- package/skills/create-prd/templates/prd.md +139 -0
- package/skills/design-audit/agents/a11y-auditor.md +43 -0
- package/skills/design-audit/agents/performance-auditor.md +46 -0
- package/skills/design-audit/agents/responsive-auditor.md +46 -0
- package/skills/design-audit/agents/scorer.md +47 -0
- package/skills/design-audit/agents/slop-detector.md +47 -0
- package/skills/design-audit/frameworks/core-web-vitals.md +107 -0
- package/skills/design-audit/frameworks/wcag-checklist.md +64 -0
- package/skills/design-audit/orchestrator.md +64 -0
- package/skills/design-audit/rubrics/ai-slop-patterns.md +83 -0
- package/skills/design-audit/rubrics/scoring.md +63 -0
- package/skills/design-audit/templates/report.md +88 -0
- package/skills/design-critique/rubrics/ux-heuristics.md +143 -0
- package/skills/design-critique/templates/critique-report.md +86 -0
- package/skills/design-distill/templates/design-system.md +132 -0
- package/skills/design-normalize/rubrics/token-naming.md +117 -0
- package/skills/design-normalize/templates/token-audit.md +89 -0
- package/skills/design-polish/rubrics/polish-checklist.md +68 -0
- package/skills/design-polish/templates/polish-report.md +64 -0
- package/skills/design-teach/rubrics/brand-personality.md +73 -0
- package/skills/design-teach/templates/design-context.json +36 -0
- package/skills/e2e-commerce/templates/test-scenarios.md +170 -0
- package/skills/event-comms/templates/email-invite.md +99 -0
- package/skills/event-comms/templates/sns-post.md +133 -0
- package/skills/event-ops/rubrics/contingency.md +85 -0
- package/skills/event-ops/templates/d-day-checklist.md +65 -0
- package/skills/event-planning/rubrics/timeline.md +70 -0
- package/skills/event-planning/templates/event-plan.md +91 -0
- package/skills/exec-plan/agents/decomposer.md +47 -0
- package/skills/exec-plan/agents/dependency-mapper.md +44 -0
- package/skills/exec-plan/agents/estimator.md +43 -0
- package/skills/exec-plan/agents/validator.md +55 -0
- package/skills/exec-plan/orchestrator.md +70 -0
- package/skills/exec-plan/rubrics/complexity-scoring.md +75 -0
- package/skills/exec-plan/templates/plan.md +147 -0
- package/skills/git-worktree/rubrics/when-to-use.md +55 -0
- package/skills/handoff/agents/context-summarizer.md +51 -0
- package/skills/handoff/agents/document-writer.md +63 -0
- package/skills/handoff/agents/state-collector.md +53 -0
- package/skills/handoff/agents/verifier.md +48 -0
- package/skills/handoff/rubrics/completeness.md +62 -0
- package/skills/handoff/templates/handoff.md +107 -0
- package/skills/parallel-research/agents/best-practices.md +43 -0
- package/skills/parallel-research/agents/codebase-patterns.md +46 -0
- package/skills/parallel-research/agents/framework-docs.md +45 -0
- package/skills/parallel-research/agents/security-advisory.md +46 -0
- package/skills/parallel-research/agents/synthesizer.md +52 -0
- package/skills/parallel-research/experts/best-practices.md +50 -0
- package/skills/parallel-research/experts/codebase-patterns.md +70 -0
- package/skills/parallel-research/experts/framework-docs.md +65 -0
- package/skills/parallel-research/experts/security-advisory.md +69 -0
- package/skills/parallel-research/orchestrator.md +65 -0
- package/skills/parallel-research/templates/synthesis.md +101 -0
- package/skills/prioritization-frameworks/rubrics/frameworks.md +79 -0
- package/skills/prioritization-frameworks/templates/scoring-matrix.md +69 -0
- package/skills/priority-todos/rubrics/prioritization.md +70 -0
- package/skills/priority-todos/templates/todo-board.md +59 -0
- package/skills/seo-checklist/frameworks/structured-data.md +153 -0
- package/skills/seo-checklist/rubrics/content-seo.md +42 -0
- package/skills/seo-checklist/rubrics/technical-seo.md +48 -0
- package/skills/techdebt/agents/analyzer.md +50 -0
- package/skills/techdebt/agents/fixer.md +41 -0
- package/skills/techdebt/agents/reviewer.md +47 -0
- package/skills/techdebt/agents/scanner.md +44 -0
- package/skills/techdebt/orchestrator.md +70 -0
- package/skills/techdebt/rubrics/severity.md +51 -0
- package/skills/techdebt/scripts/scan.js +90 -0
- package/skills/techdebt/templates/report.md +86 -0
- package/skills/tool-fallback/rubrics/fallback-chain.md +58 -0
- package/skills/typescript-advanced-types/rubrics/type-patterns.md +109 -0
- package/skills/ui-ux-pro-max/rubrics/interaction-states.md +83 -0
- package/skills/ui-ux-pro-max/rubrics/responsive-breakpoints.md +99 -0
- package/skills/user-personas/rubrics/research-methods.md +56 -0
- package/skills/user-personas/templates/persona.md +89 -0
- package/skills/vercel-react-best-practices/rubrics/performance.md +82 -0
- package/skills/vercel-react-best-practices/rubrics/server-components.md +86 -0
- package/skills/vibe-docs/SKILL.md +171 -0
- package/skills/vibe-docs/templates/architecture.md +80 -0
- package/skills/vibe-docs/templates/readme.md +84 -0
- package/skills/vibe-docs/templates/release-notes.md +74 -0
- package/skills/vibe-figma/rubrics/extraction-checklist.md +51 -0
- package/skills/vibe-figma/templates/figma-handoff.md +96 -0
- package/skills/vibe-figma-analyze/rubrics/analysis-dimensions.md +53 -0
- package/skills/vibe-figma-codegen/rubrics/code-quality.md +54 -0
- package/skills/vibe-figma-consolidate/templates/consolidation-report.md +95 -0
- package/skills/vibe-figma-convert/rubrics/conversion-rules.md +83 -0
- package/skills/vibe-figma-convert/templates/component.md +152 -0
- package/skills/vibe-figma-extract/rubrics/image-rules.md +67 -0
- package/skills/vibe-figma-frame/rubrics/frame-selection.md +55 -0
- package/skills/vibe-figma-pipeline/rubrics/pipeline-stages.md +96 -0
- package/skills/vibe-figma-rules/rubrics/naming-conventions.md +70 -0
- package/skills/vibe-figma-style/rubrics/style-mapping.md +100 -0
- package/skills/video-production/rubrics/quality-checklist.md +58 -0
- package/skills/video-production/templates/production-plan.md +104 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { execFileSync, execSync } from 'child_process';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const SCRIPT = path.resolve(__dirname, '..', 'sentinel-guard.js');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Run sentinel-guard.js with argv arguments.
|
|
11
|
+
* Returns { stdout, exitCode }.
|
|
12
|
+
*/
|
|
13
|
+
function runGuard(args = []) {
|
|
14
|
+
try {
|
|
15
|
+
const stdout = execFileSync('node', [SCRIPT, ...args], {
|
|
16
|
+
encoding: 'utf-8',
|
|
17
|
+
timeout: 5000,
|
|
18
|
+
});
|
|
19
|
+
return { stdout: stdout.trim(), exitCode: 0 };
|
|
20
|
+
} catch (err) {
|
|
21
|
+
return { stdout: (err.stdout || '').trim(), exitCode: err.status };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Run sentinel-guard.js with stdin JSON payload (using shell pipe).
|
|
27
|
+
* The script reads stdin via fs.openSync('/dev/stdin'), which requires
|
|
28
|
+
* a real pipe — execFileSync input option does not work.
|
|
29
|
+
*/
|
|
30
|
+
function runGuardWithStdin(payload) {
|
|
31
|
+
const json = typeof payload === 'string' ? payload : JSON.stringify(payload);
|
|
32
|
+
// Escape single quotes in JSON for shell safety
|
|
33
|
+
const escaped = json.replace(/'/g, "'\\''");
|
|
34
|
+
try {
|
|
35
|
+
const stdout = execSync(`echo '${escaped}' | node ${SCRIPT}`, {
|
|
36
|
+
encoding: 'utf-8',
|
|
37
|
+
timeout: 5000,
|
|
38
|
+
});
|
|
39
|
+
return { stdout: stdout.trim(), exitCode: 0 };
|
|
40
|
+
} catch (err) {
|
|
41
|
+
return { stdout: (err.stdout || '').trim(), exitCode: err.status };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ══════════════════════════════════════════════════
|
|
46
|
+
// Sentinel path protection
|
|
47
|
+
// ══════════════════════════════════════════════════
|
|
48
|
+
describe('sentinel-guard', () => {
|
|
49
|
+
describe('Write/Edit to sentinel paths via argv', () => {
|
|
50
|
+
it('should block Write to src/infra/lib/autonomy/', () => {
|
|
51
|
+
const result = runGuard([
|
|
52
|
+
'Write',
|
|
53
|
+
JSON.stringify({ file_path: 'src/infra/lib/autonomy/policy.ts' }),
|
|
54
|
+
]);
|
|
55
|
+
expect(result.exitCode).toBe(2);
|
|
56
|
+
expect(result.stdout).toContain('block');
|
|
57
|
+
expect(result.stdout).toContain('Sentinel files are protected');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should block Edit to sentinel path', () => {
|
|
61
|
+
const result = runGuard([
|
|
62
|
+
'Edit',
|
|
63
|
+
JSON.stringify({ file_path: 'src/infra/lib/autonomy/config.ts' }),
|
|
64
|
+
]);
|
|
65
|
+
expect(result.exitCode).toBe(2);
|
|
66
|
+
expect(result.stdout).toContain('block');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should block Write with backslash path separators', () => {
|
|
70
|
+
const result = runGuard([
|
|
71
|
+
'Write',
|
|
72
|
+
JSON.stringify({ file_path: 'src\\infra\\lib\\autonomy\\file.ts' }),
|
|
73
|
+
]);
|
|
74
|
+
expect(result.exitCode).toBe(2);
|
|
75
|
+
expect(result.stdout).toContain('Sentinel files are protected');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should block Write with ./ prefix', () => {
|
|
79
|
+
const result = runGuard([
|
|
80
|
+
'Write',
|
|
81
|
+
JSON.stringify({ file_path: './src/infra/lib/autonomy/index.ts' }),
|
|
82
|
+
]);
|
|
83
|
+
expect(result.exitCode).toBe(2);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('Write/Edit to sentinel paths via stdin', () => {
|
|
88
|
+
it('should block Edit via stdin payload', () => {
|
|
89
|
+
const result = runGuardWithStdin({
|
|
90
|
+
tool_name: 'Edit',
|
|
91
|
+
tool_input: { file_path: './src/infra/lib/autonomy/config.ts' },
|
|
92
|
+
});
|
|
93
|
+
expect(result.exitCode).toBe(2);
|
|
94
|
+
expect(result.stdout).toContain('block');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should block Write via stdin payload', () => {
|
|
98
|
+
const result = runGuardWithStdin({
|
|
99
|
+
tool_name: 'Write',
|
|
100
|
+
tool_input: { file_path: 'src/infra/lib/autonomy/policy.ts' },
|
|
101
|
+
});
|
|
102
|
+
expect(result.exitCode).toBe(2);
|
|
103
|
+
expect(result.stdout).toContain('Sentinel files are protected');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('allowed operations', () => {
|
|
108
|
+
it('should allow Write to non-sentinel paths', () => {
|
|
109
|
+
const result = runGuard([
|
|
110
|
+
'Write',
|
|
111
|
+
JSON.stringify({ file_path: 'src/cli/commands/init.ts' }),
|
|
112
|
+
]);
|
|
113
|
+
expect(result.exitCode).toBe(0);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should allow Read to sentinel paths (read is not blocked)', () => {
|
|
117
|
+
const result = runGuard([
|
|
118
|
+
'Read',
|
|
119
|
+
JSON.stringify({ file_path: 'src/infra/lib/autonomy/policy.ts' }),
|
|
120
|
+
]);
|
|
121
|
+
expect(result.exitCode).toBe(0);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should allow Bash commands that do not target sentinel paths', () => {
|
|
125
|
+
const result = runGuard([
|
|
126
|
+
'Bash',
|
|
127
|
+
JSON.stringify({ command: 'ls -la src/cli/' }),
|
|
128
|
+
]);
|
|
129
|
+
expect(result.exitCode).toBe(0);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('dangerous bash commands targeting sentinel paths', () => {
|
|
134
|
+
it('should block rm -rf targeting sentinel path', () => {
|
|
135
|
+
const result = runGuard([
|
|
136
|
+
'Bash',
|
|
137
|
+
JSON.stringify({ command: 'rm -rf src/infra/lib/autonomy/' }),
|
|
138
|
+
]);
|
|
139
|
+
expect(result.exitCode).toBe(2);
|
|
140
|
+
expect(result.stdout).toContain('block');
|
|
141
|
+
expect(result.stdout).toContain('Dangerous command targeting sentinel path');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('should block kill -9 targeting sentinel path', () => {
|
|
145
|
+
const result = runGuard([
|
|
146
|
+
'Bash',
|
|
147
|
+
JSON.stringify({ command: 'kill -9 1234 && rm src/infra/lib/autonomy/x' }),
|
|
148
|
+
]);
|
|
149
|
+
expect(result.exitCode).toBe(2);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('should allow rm -rf on non-sentinel paths', () => {
|
|
153
|
+
const result = runGuard([
|
|
154
|
+
'Bash',
|
|
155
|
+
JSON.stringify({ command: 'rm -rf dist/' }),
|
|
156
|
+
]);
|
|
157
|
+
expect(result.exitCode).toBe(0);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('should allow dangerous commands not targeting sentinel paths', () => {
|
|
161
|
+
const result = runGuard([
|
|
162
|
+
'Bash',
|
|
163
|
+
JSON.stringify({ command: 'rm -rf /tmp/junk' }),
|
|
164
|
+
]);
|
|
165
|
+
expect(result.exitCode).toBe(0);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe('Bash command containing sentinel path in command string', () => {
|
|
170
|
+
it('should block when command string itself starts with sentinel path', () => {
|
|
171
|
+
const result = runGuard([
|
|
172
|
+
'Bash',
|
|
173
|
+
JSON.stringify({ command: 'src/infra/lib/autonomy/run.sh' }),
|
|
174
|
+
]);
|
|
175
|
+
expect(result.exitCode).toBe(2);
|
|
176
|
+
expect(result.stdout).toContain('Sentinel files are protected');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('should not block non-dangerous commands referencing sentinel path mid-string', () => {
|
|
180
|
+
// isSentinelPath only checks startsWith, and the DANGEROUS_BASH_RE +
|
|
181
|
+
// includes check requires both a dangerous command and sentinel path
|
|
182
|
+
const result = runGuard([
|
|
183
|
+
'Bash',
|
|
184
|
+
JSON.stringify({ command: 'cat src/infra/lib/autonomy/policy.ts | wc -l' }),
|
|
185
|
+
]);
|
|
186
|
+
// 'cat' is not a dangerous command, command does not start with sentinel path
|
|
187
|
+
expect(result.exitCode).toBe(0);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe('stdin vs argv priority', () => {
|
|
192
|
+
it('should prefer stdin payload over argv', () => {
|
|
193
|
+
const payload = JSON.stringify({
|
|
194
|
+
tool_name: 'Write',
|
|
195
|
+
tool_input: { file_path: 'src/infra/lib/autonomy/x.ts' },
|
|
196
|
+
});
|
|
197
|
+
const escaped = payload.replace(/'/g, "'\\''");
|
|
198
|
+
try {
|
|
199
|
+
execSync(`echo '${escaped}' | node ${SCRIPT} Read '{}'`, {
|
|
200
|
+
encoding: 'utf-8',
|
|
201
|
+
timeout: 5000,
|
|
202
|
+
});
|
|
203
|
+
expect.unreachable('should have exited with code 2');
|
|
204
|
+
} catch (err) {
|
|
205
|
+
expect(err.status).toBe(2);
|
|
206
|
+
expect(err.stdout).toContain('block');
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stop Hook - 에이전트 응답 완료 시 자동 커밋
|
|
3
|
+
*
|
|
4
|
+
* 변경사항이 있으면 자동으로 git add + commit.
|
|
5
|
+
* 커밋 메시지는 변경 파일 목록 기반으로 생성.
|
|
6
|
+
* feature branch에서만 동작 (main/master 보호).
|
|
7
|
+
*/
|
|
8
|
+
import { execSync } from 'child_process';
|
|
9
|
+
import { PROJECT_DIR } from './utils.js';
|
|
10
|
+
|
|
11
|
+
const PROTECTED_BRANCHES = ['main', 'master', 'develop', 'production'];
|
|
12
|
+
const MAX_FILES_IN_MSG = 5;
|
|
13
|
+
|
|
14
|
+
function getCurrentBranch() {
|
|
15
|
+
return execSync('git branch --show-current', {
|
|
16
|
+
cwd: PROJECT_DIR,
|
|
17
|
+
encoding: 'utf-8',
|
|
18
|
+
}).trim();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function hasChanges() {
|
|
22
|
+
const status = execSync('git status --porcelain', {
|
|
23
|
+
cwd: PROJECT_DIR,
|
|
24
|
+
encoding: 'utf-8',
|
|
25
|
+
}).trim();
|
|
26
|
+
return status.length > 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getChangedFiles() {
|
|
30
|
+
const status = execSync('git status --porcelain', {
|
|
31
|
+
cwd: PROJECT_DIR,
|
|
32
|
+
encoding: 'utf-8',
|
|
33
|
+
}).trim();
|
|
34
|
+
return status.split('\n')
|
|
35
|
+
.map(line => line.slice(3).trim())
|
|
36
|
+
.filter(f => f.length > 0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function buildCommitMessage(files) {
|
|
40
|
+
const shown = files.slice(0, MAX_FILES_IN_MSG);
|
|
41
|
+
const remaining = files.length - shown.length;
|
|
42
|
+
let msg = `auto: update ${shown.join(', ')}`;
|
|
43
|
+
if (remaining > 0) msg += ` (+${remaining} more)`;
|
|
44
|
+
return msg;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const branch = getCurrentBranch();
|
|
49
|
+
if (PROTECTED_BRANCHES.includes(branch)) {
|
|
50
|
+
// Never auto-commit to protected branches
|
|
51
|
+
process.exit(0);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!hasChanges()) process.exit(0);
|
|
55
|
+
|
|
56
|
+
const files = getChangedFiles();
|
|
57
|
+
const msg = buildCommitMessage(files);
|
|
58
|
+
|
|
59
|
+
execSync('git add -A', { cwd: PROJECT_DIR, stdio: 'ignore' });
|
|
60
|
+
execSync(`git commit -m "${msg}"`, { cwd: PROJECT_DIR, stdio: 'ignore' });
|
|
61
|
+
|
|
62
|
+
console.log(`[AUTO-COMMIT] ${msg}`);
|
|
63
|
+
} catch {
|
|
64
|
+
// Auto-commit failure should never block
|
|
65
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostToolUse Hook - Write/Edit 후 자동 포맷
|
|
3
|
+
*
|
|
4
|
+
* 프로젝트에 설치된 포매터를 감지하고 수정된 파일에 자동 실행.
|
|
5
|
+
* Prettier(JS/TS), Black(Python), gofmt(Go) 지원.
|
|
6
|
+
* 200ms 이내 완료 목표 — 단일 파일만 처리.
|
|
7
|
+
*/
|
|
8
|
+
import { execSync } from 'child_process';
|
|
9
|
+
import { existsSync } from 'fs';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import { PROJECT_DIR } from './utils.js';
|
|
12
|
+
|
|
13
|
+
const CODE_EXT_RE = /\.(ts|tsx|js|jsx|mjs|cjs|css|scss|json|md|html|vue|svelte)$/;
|
|
14
|
+
const PYTHON_EXT_RE = /\.py$/;
|
|
15
|
+
const GO_EXT_RE = /\.go$/;
|
|
16
|
+
|
|
17
|
+
function getFilePath() {
|
|
18
|
+
const input = JSON.parse(process.env.TOOL_INPUT || '{}');
|
|
19
|
+
return input.file_path || input.path || '';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function hasBin(name) {
|
|
23
|
+
try {
|
|
24
|
+
execSync(`which ${name}`, { stdio: 'ignore' });
|
|
25
|
+
return true;
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function hasPrettier() {
|
|
32
|
+
return existsSync(path.join(PROJECT_DIR, 'node_modules', '.bin', 'prettier'));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function formatFile(filePath) {
|
|
36
|
+
const resolved = path.resolve(filePath);
|
|
37
|
+
if (!existsSync(resolved)) return;
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
if (CODE_EXT_RE.test(filePath) && hasPrettier()) {
|
|
41
|
+
execSync(`npx prettier --write "${resolved}"`, {
|
|
42
|
+
cwd: PROJECT_DIR,
|
|
43
|
+
stdio: 'ignore',
|
|
44
|
+
timeout: 5000,
|
|
45
|
+
});
|
|
46
|
+
console.log(`[AUTO-FORMAT] prettier: ${path.basename(resolved)}`);
|
|
47
|
+
} else if (PYTHON_EXT_RE.test(filePath) && hasBin('black')) {
|
|
48
|
+
execSync(`black --quiet "${resolved}"`, { stdio: 'ignore', timeout: 5000 });
|
|
49
|
+
console.log(`[AUTO-FORMAT] black: ${path.basename(resolved)}`);
|
|
50
|
+
} else if (GO_EXT_RE.test(filePath) && hasBin('gofmt')) {
|
|
51
|
+
execSync(`gofmt -w "${resolved}"`, { stdio: 'ignore', timeout: 5000 });
|
|
52
|
+
console.log(`[AUTO-FORMAT] gofmt: ${path.basename(resolved)}`);
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
// Format failure should never block — silently continue
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const filePath = getFilePath();
|
|
61
|
+
if (filePath) formatFile(filePath);
|
|
62
|
+
} catch {
|
|
63
|
+
// Silent fail
|
|
64
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostToolUse Hook - Write/Edit 후 관련 테스트 자동 실행
|
|
3
|
+
*
|
|
4
|
+
* 수정된 파일에 대응하는 테스트 파일을 찾아 실행.
|
|
5
|
+
* 실패 시 마지막 5줄만 출력해서 context window 오염 방지.
|
|
6
|
+
* exit 0 항상 — 차단하지 않고 에이전트에게 결과만 전달.
|
|
7
|
+
*/
|
|
8
|
+
import { execSync } from 'child_process';
|
|
9
|
+
import { existsSync } from 'fs';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import { PROJECT_DIR } from './utils.js';
|
|
12
|
+
|
|
13
|
+
const CODE_EXT_RE = /\.(ts|tsx|js|jsx)$/;
|
|
14
|
+
const TEST_SUFFIXES = ['.test.', '.spec.'];
|
|
15
|
+
const MAX_OUTPUT_LINES = 5;
|
|
16
|
+
|
|
17
|
+
function getFilePath() {
|
|
18
|
+
const input = JSON.parse(process.env.TOOL_INPUT || '{}');
|
|
19
|
+
return input.file_path || input.path || '';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isTestFile(filePath) {
|
|
23
|
+
return TEST_SUFFIXES.some(s => filePath.includes(s));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function findTestFile(filePath) {
|
|
27
|
+
const dir = path.dirname(filePath);
|
|
28
|
+
const ext = path.extname(filePath);
|
|
29
|
+
const base = path.basename(filePath, ext);
|
|
30
|
+
|
|
31
|
+
// src/foo.ts → src/foo.test.ts, src/__tests__/foo.test.ts
|
|
32
|
+
const candidates = [
|
|
33
|
+
path.join(dir, `${base}.test${ext}`),
|
|
34
|
+
path.join(dir, `${base}.spec${ext}`),
|
|
35
|
+
path.join(dir, '__tests__', `${base}.test${ext}`),
|
|
36
|
+
path.join(dir, '__tests__', `${base}.spec${ext}`),
|
|
37
|
+
];
|
|
38
|
+
return candidates.find(c => existsSync(c)) || null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function hasVitest() {
|
|
42
|
+
return existsSync(path.join(PROJECT_DIR, 'node_modules', '.bin', 'vitest'));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function hasJest() {
|
|
46
|
+
return existsSync(path.join(PROJECT_DIR, 'node_modules', '.bin', 'jest'));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const filePath = getFilePath();
|
|
51
|
+
if (!filePath || !CODE_EXT_RE.test(filePath)) process.exit(0);
|
|
52
|
+
|
|
53
|
+
const testFile = isTestFile(filePath) ? filePath : findTestFile(filePath);
|
|
54
|
+
if (!testFile) process.exit(0);
|
|
55
|
+
|
|
56
|
+
const relPath = path.relative(PROJECT_DIR, testFile);
|
|
57
|
+
let cmd = '';
|
|
58
|
+
if (hasVitest()) {
|
|
59
|
+
cmd = `npx vitest run "${relPath}" --reporter=verbose`;
|
|
60
|
+
} else if (hasJest()) {
|
|
61
|
+
cmd = `npx jest "${relPath}" --no-coverage`;
|
|
62
|
+
} else {
|
|
63
|
+
process.exit(0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
console.log(`[AUTO-TEST] Running: ${relPath}`);
|
|
67
|
+
const output = execSync(cmd, {
|
|
68
|
+
cwd: PROJECT_DIR,
|
|
69
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
70
|
+
timeout: 60000,
|
|
71
|
+
}).toString();
|
|
72
|
+
|
|
73
|
+
const tail = output.trim().split('\n').slice(-MAX_OUTPUT_LINES).join('\n');
|
|
74
|
+
console.log(`[AUTO-TEST] PASSED\n${tail}`);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
const stderr = err.stderr ? err.stderr.toString() : '';
|
|
77
|
+
const stdout = err.stdout ? err.stdout.toString() : '';
|
|
78
|
+
const combined = (stdout + '\n' + stderr).trim();
|
|
79
|
+
const tail = combined.split('\n').slice(-MAX_OUTPUT_LINES).join('\n');
|
|
80
|
+
console.log(`[AUTO-TEST] FAILED\n${tail}`);
|
|
81
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* PostToolUse Hook - Write/Edit 후 코드 품질 검사 + 관찰 자동 캡처
|
|
3
3
|
*/
|
|
4
4
|
import { getToolsBaseUrl, PROJECT_DIR } from './utils.js';
|
|
5
|
+
import { readFileSync } from 'fs';
|
|
5
6
|
|
|
6
7
|
const BASE_URL = getToolsBaseUrl();
|
|
7
8
|
|
|
@@ -34,6 +35,143 @@ function classifyObservation(files) {
|
|
|
34
35
|
return { type: 'feature', title: 'Code modified' };
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Detect `any` type usage and return line-level findings
|
|
40
|
+
*/
|
|
41
|
+
function detectAnyType(lines) {
|
|
42
|
+
const findings = [];
|
|
43
|
+
lines.forEach((line, i) => {
|
|
44
|
+
if (/:\s*any\b|<any>|as\s+any\b/.test(line)) {
|
|
45
|
+
findings.push({
|
|
46
|
+
line: i + 1,
|
|
47
|
+
match: line.trim(),
|
|
48
|
+
suggestion: 'Replace with: unknown + type guard pattern: if (typeof x === \'string\') { ... }'
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return findings;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Detect functions exceeding 50 lines
|
|
57
|
+
*/
|
|
58
|
+
function detectLongFunctions(lines) {
|
|
59
|
+
const findings = [];
|
|
60
|
+
let fnStart = -1;
|
|
61
|
+
let fnName = '';
|
|
62
|
+
let depth = 0;
|
|
63
|
+
|
|
64
|
+
for (let i = 0; i < lines.length; i++) {
|
|
65
|
+
const line = lines[i];
|
|
66
|
+
const fnMatch = line.match(/(?:function\s+(\w+)|(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s*)?\()/);
|
|
67
|
+
if (fnMatch && depth === 0) {
|
|
68
|
+
fnStart = i;
|
|
69
|
+
fnName = fnMatch[1] || fnMatch[2] || 'anonymous';
|
|
70
|
+
}
|
|
71
|
+
depth += (line.match(/\{/g) || []).length - (line.match(/\}/g) || []).length;
|
|
72
|
+
if (fnStart !== -1 && depth <= 0) {
|
|
73
|
+
const length = i - fnStart + 1;
|
|
74
|
+
if (length > 50) {
|
|
75
|
+
findings.push({
|
|
76
|
+
line: fnStart + 1,
|
|
77
|
+
match: `function '${fnName}' is ${length} lines`,
|
|
78
|
+
suggestion: `Extract lines ${fnStart + 20}–${i + 1} into a separate helper function`
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
fnStart = -1;
|
|
82
|
+
depth = 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return findings;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Detect nesting depth exceeding 3 levels
|
|
90
|
+
*/
|
|
91
|
+
function detectDeepNesting(lines) {
|
|
92
|
+
const findings = [];
|
|
93
|
+
let depth = 0;
|
|
94
|
+
let reported = false;
|
|
95
|
+
|
|
96
|
+
lines.forEach((line, i) => {
|
|
97
|
+
depth += (line.match(/\{/g) || []).length - (line.match(/\}/g) || []).length;
|
|
98
|
+
if (depth > 3 && !reported) {
|
|
99
|
+
findings.push({
|
|
100
|
+
line: i + 1,
|
|
101
|
+
match: `nesting depth ${depth} at line ${i + 1}`,
|
|
102
|
+
suggestion: 'Use early return pattern: if (!condition) return; — instead of wrapping in else'
|
|
103
|
+
});
|
|
104
|
+
reported = true;
|
|
105
|
+
}
|
|
106
|
+
if (depth <= 3) reported = false;
|
|
107
|
+
});
|
|
108
|
+
return findings;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Detect console.log statements
|
|
113
|
+
*/
|
|
114
|
+
function detectConsoleLogs(lines) {
|
|
115
|
+
const findings = [];
|
|
116
|
+
lines.forEach((line, i) => {
|
|
117
|
+
if (/console\.log\(/.test(line)) {
|
|
118
|
+
findings.push({
|
|
119
|
+
line: i + 1,
|
|
120
|
+
match: line.trim(),
|
|
121
|
+
suggestion: 'Remove or replace with debugLog utility'
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return findings;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Detect magic numbers (bare numeric literals ≥2 digits, outside comments/strings)
|
|
130
|
+
*/
|
|
131
|
+
function detectMagicNumbers(lines) {
|
|
132
|
+
const findings = [];
|
|
133
|
+
lines.forEach((line, i) => {
|
|
134
|
+
const stripped = line.replace(/\/\/.*$/, '').replace(/(['"`]).*?\1/g, '""');
|
|
135
|
+
const nums = stripped.match(/\b\d{2,}\b/g) || [];
|
|
136
|
+
if (nums.length > 0) {
|
|
137
|
+
findings.push({
|
|
138
|
+
line: i + 1,
|
|
139
|
+
match: `magic number(s): ${nums.join(', ')}`,
|
|
140
|
+
suggestion: `Extract to named constant: const LIMIT = ${nums[0]};`
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return findings;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Run all self-heal detectors and emit [SELF-HEAL] messages
|
|
149
|
+
*/
|
|
150
|
+
function emitSelfHealMessages(filePath) {
|
|
151
|
+
let content;
|
|
152
|
+
try {
|
|
153
|
+
content = readFileSync(filePath, 'utf-8');
|
|
154
|
+
} catch {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const lines = content.split('\n');
|
|
159
|
+
const detectors = [
|
|
160
|
+
{ label: 'any type detected', fn: detectAnyType },
|
|
161
|
+
{ label: 'function too long', fn: detectLongFunctions },
|
|
162
|
+
{ label: 'nesting too deep', fn: detectDeepNesting },
|
|
163
|
+
{ label: 'console.log found', fn: detectConsoleLogs },
|
|
164
|
+
{ label: 'magic number', fn: detectMagicNumbers },
|
|
165
|
+
];
|
|
166
|
+
|
|
167
|
+
for (const { label, fn } of detectors) {
|
|
168
|
+
const findings = fn(lines).slice(0, 2);
|
|
169
|
+
for (const f of findings) {
|
|
170
|
+
console.log(`[SELF-HEAL] ${label} at line ${f.line} → ${f.suggestion}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
37
175
|
async function main() {
|
|
38
176
|
// 1. Code quality check (changed files only — never scan entire project)
|
|
39
177
|
try {
|
|
@@ -50,6 +188,7 @@ async function main() {
|
|
|
50
188
|
if (critical.length > 0) {
|
|
51
189
|
console.log('[CODE CHECK]', critical.join(' | '));
|
|
52
190
|
}
|
|
191
|
+
emitSelfHealMessages(files[0]);
|
|
53
192
|
}
|
|
54
193
|
} catch {
|
|
55
194
|
// Silently continue on check failure — never block progress
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PreToolUse Hook - 모든 Bash 명령어를 타임스탬프와 함께 로깅
|
|
3
|
+
*
|
|
4
|
+
* 로그 위치: .claude/command-log.txt
|
|
5
|
+
* exit 0 항상 통과 (로깅만 수행, 차단하지 않음)
|
|
6
|
+
*/
|
|
7
|
+
import { appendFileSync, mkdirSync, existsSync } from 'fs';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { PROJECT_DIR } from './utils.js';
|
|
10
|
+
|
|
11
|
+
const LOG_DIR = path.join(PROJECT_DIR, '.claude');
|
|
12
|
+
const LOG_FILE = path.join(LOG_DIR, 'command-log.txt');
|
|
13
|
+
const MAX_CMD_LENGTH = 500;
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const input = JSON.parse(process.env.TOOL_INPUT || '{}');
|
|
17
|
+
const command = input.command || '';
|
|
18
|
+
if (!command) process.exit(0);
|
|
19
|
+
|
|
20
|
+
const timestamp = new Date().toISOString();
|
|
21
|
+
const truncated = command.length > MAX_CMD_LENGTH
|
|
22
|
+
? command.slice(0, MAX_CMD_LENGTH) + '...(truncated)'
|
|
23
|
+
: command;
|
|
24
|
+
|
|
25
|
+
const entry = `[${timestamp}] ${truncated}\n`;
|
|
26
|
+
|
|
27
|
+
if (!existsSync(LOG_DIR)) mkdirSync(LOG_DIR, { recursive: true });
|
|
28
|
+
appendFileSync(LOG_FILE, entry);
|
|
29
|
+
} catch {
|
|
30
|
+
// Never block on logging failure
|
|
31
|
+
}
|
|
32
|
+
process.exit(0);
|