@stackmemoryai/stackmemory 0.3.16 โ 0.3.18
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 +48 -2
- package/dist/cli/commands/skills.js +15 -2
- package/dist/cli/commands/skills.js.map +2 -2
- package/dist/cli/index.js +113 -834
- package/dist/cli/index.js.map +3 -3
- package/dist/core/context/dual-stack-manager.js +1 -1
- package/dist/core/context/dual-stack-manager.js.map +1 -1
- package/dist/core/context/frame-manager.js +3 -0
- package/dist/core/context/frame-manager.js.map +2 -2
- package/dist/integrations/claude-code/subagent-client.js +106 -3
- package/dist/integrations/claude-code/subagent-client.js.map +2 -2
- package/dist/servers/railway/config.js +51 -0
- package/dist/servers/railway/config.js.map +7 -0
- package/dist/servers/railway/index-enhanced.js +156 -0
- package/dist/servers/railway/index-enhanced.js.map +7 -0
- package/dist/servers/railway/minimal.js +48 -3
- package/dist/servers/railway/minimal.js.map +2 -2
- package/dist/servers/railway/storage-test.js +455 -0
- package/dist/servers/railway/storage-test.js.map +7 -0
- package/dist/skills/claude-skills.js +13 -12
- package/dist/skills/claude-skills.js.map +2 -2
- package/dist/skills/recursive-agent-orchestrator.js +27 -18
- package/dist/skills/recursive-agent-orchestrator.js.map +2 -2
- package/dist/skills/unified-rlm-orchestrator.js.map +2 -2
- package/package.json +6 -18
- package/scripts/README-TESTING.md +186 -0
- package/scripts/analyze-cli-security.js +288 -0
- package/scripts/archive/add-phase-tasks-to-linear.js +163 -0
- package/scripts/archive/analyze-linear-duplicates.js +214 -0
- package/scripts/archive/analyze-remaining-duplicates.js +230 -0
- package/scripts/archive/analyze-sta-duplicates.js +292 -0
- package/scripts/archive/analyze-sta-graphql.js +399 -0
- package/scripts/archive/cancel-duplicate-tasks.ts +246 -0
- package/scripts/archive/check-all-duplicates.ts +419 -0
- package/scripts/archive/clean-duplicate-tasks.js +114 -0
- package/scripts/archive/cleanup-duplicate-tasks.ts +286 -0
- package/scripts/archive/create-phase-tasks.js +387 -0
- package/scripts/archive/delete-linear-duplicates.js +182 -0
- package/scripts/archive/delete-remaining-duplicates.js +158 -0
- package/scripts/archive/delete-sta-duplicates.js +201 -0
- package/scripts/archive/delete-sta-oauth.js +201 -0
- package/scripts/archive/export-sta-tasks.js +62 -0
- package/scripts/archive/install-auto-sync.js +266 -0
- package/scripts/archive/install-chromadb-hooks.sh +133 -0
- package/scripts/archive/install-enhanced-clear-hooks.sh +431 -0
- package/scripts/archive/install-post-task-hooks.sh +289 -0
- package/scripts/archive/install-stackmemory-hooks.sh +420 -0
- package/scripts/archive/merge-linear-duplicates-safe.ts +362 -0
- package/scripts/archive/merge-linear-duplicates.ts +180 -0
- package/scripts/archive/remove-sta-tasks.js +70 -0
- package/scripts/archive/setup-background-sync.sh +168 -0
- package/scripts/archive/setup-claude-auto-triggers.sh +181 -0
- package/scripts/archive/setup-claude-autostart.sh +305 -0
- package/scripts/archive/setup-git-hooks.sh +25 -0
- package/scripts/archive/setup-linear-oauth.sh +46 -0
- package/scripts/archive/setup-mcp.sh +113 -0
- package/scripts/archive/setup-railway-deployment.sh +81 -0
- package/scripts/auto-handoff.sh +262 -0
- package/scripts/background-sync-manager.js +416 -0
- package/scripts/benchmark-performance.ts +57 -0
- package/scripts/check-redis.ts +48 -0
- package/scripts/chromadb-auto-loader.sh +128 -0
- package/scripts/chromadb-context-loader.js +479 -0
- package/scripts/claude-chromadb-hook.js +460 -0
- package/scripts/claude-code-wrapper.sh +66 -0
- package/scripts/claude-linear-skill.js +455 -0
- package/scripts/claude-pre-commit.sh +302 -0
- package/scripts/claude-sm-autostart.js +532 -0
- package/scripts/claude-sm-setup.sh +367 -0
- package/scripts/claude-with-chromadb.sh +69 -0
- package/scripts/claude-worktree-manager.sh +323 -0
- package/scripts/claude-worktree-monitor.sh +371 -0
- package/scripts/claude-worktree-setup.sh +327 -0
- package/scripts/clean-linear-backlog.js +273 -0
- package/scripts/cleanup-old-sessions.sh +57 -0
- package/scripts/codex-wrapper.sh +88 -0
- package/scripts/create-sandbox.sh +269 -0
- package/scripts/debug-linear-update.js +174 -0
- package/scripts/delete-linear-tasks.js +167 -0
- package/scripts/deploy.sh +89 -0
- package/scripts/deployment/railway.sh +352 -0
- package/scripts/deployment/test-deployment.js +194 -0
- package/scripts/detect-and-rehydrate.js +162 -0
- package/scripts/detect-and-rehydrate.mjs +165 -0
- package/scripts/development/create-demo-tasks.js +143 -0
- package/scripts/development/debug-frame-test.js +16 -0
- package/scripts/development/demo-auto-sync.js +128 -0
- package/scripts/development/fix-all-imports.js +213 -0
- package/scripts/development/fix-imports.js +229 -0
- package/scripts/development/fix-lint-loop.cjs +103 -0
- package/scripts/development/fix-project-id.ts +161 -0
- package/scripts/development/fix-strict-mode-issues.ts +291 -0
- package/scripts/development/reorganize-structure.sh +228 -0
- package/scripts/development/test-persistence-direct.js +148 -0
- package/scripts/development/test-persistence.js +114 -0
- package/scripts/development/test-tasks.js +93 -0
- package/scripts/development/update-imports.js +212 -0
- package/scripts/fetch-linear-status.js +125 -0
- package/scripts/git-hooks/README.md +310 -0
- package/scripts/git-hooks/branch-context-manager.sh +342 -0
- package/scripts/git-hooks/post-checkout-stackmemory.sh +63 -0
- package/scripts/git-hooks/post-commit-stackmemory.sh +305 -0
- package/scripts/git-hooks/pre-commit-stackmemory.sh +275 -0
- package/scripts/hooks/cleanup-shell.sh +130 -0
- package/scripts/hooks/task-complete.sh +114 -0
- package/scripts/initialize.ts +129 -0
- package/scripts/install-claude-hooks-auto.js +104 -0
- package/scripts/install-claude-hooks.sh +133 -0
- package/scripts/install-global.sh +296 -0
- package/scripts/install.sh +235 -0
- package/scripts/linear-auto-sync.js +262 -0
- package/scripts/linear-auto-sync.sh +161 -0
- package/scripts/linear-sync-daemon.js +150 -0
- package/scripts/linear-task-review.js +237 -0
- package/scripts/list-linear-tasks.ts +178 -0
- package/scripts/mcp-proxy.js +66 -0
- package/scripts/opencode-wrapper.sh +85 -0
- package/scripts/publish-local.js +74 -0
- package/scripts/query-chromadb.ts +201 -0
- package/scripts/railway-env-setup.sh +39 -0
- package/scripts/reconcile-local-tasks.js +170 -0
- package/scripts/recreate-frames-db.js +89 -0
- package/scripts/setup/claude-integration.js +138 -0
- package/scripts/setup/configure-alias.js +125 -0
- package/scripts/setup/configure-codex-alias.js +161 -0
- package/scripts/setup/configure-opencode-alias.js +175 -0
- package/scripts/setup-claude-integration.js +204 -0
- package/scripts/setup-claude-integration.sh +183 -0
- package/scripts/setup.sh +31 -0
- package/scripts/show-linear-summary.ts +172 -0
- package/scripts/stackmemory-auto-handoff.sh +231 -0
- package/scripts/stackmemory-daemon.sh +40 -0
- package/scripts/start-linear-sync-daemon.sh +141 -0
- package/scripts/start-temporal-paradox.sh +214 -0
- package/scripts/status.ts +159 -0
- package/scripts/sync-and-clean-tasks.js +258 -0
- package/scripts/sync-frames-from-railway.js +228 -0
- package/scripts/sync-linear-graphql.js +303 -0
- package/scripts/sync-linear-tasks.js +186 -0
- package/scripts/test-auto-triggers.sh +57 -0
- package/scripts/test-browser-mcp.js +74 -0
- package/scripts/test-chromadb-full.js +115 -0
- package/scripts/test-chromadb-hooks.sh +28 -0
- package/scripts/test-chromadb-sync.ts +245 -0
- package/scripts/test-cli-security.js +293 -0
- package/scripts/test-hooks-persistence.sh +220 -0
- package/scripts/test-installation-scenarios.sh +359 -0
- package/scripts/test-installation.sh +224 -0
- package/scripts/test-mcp.js +163 -0
- package/scripts/test-pre-publish-quick.sh +75 -0
- package/scripts/test-quality-gates.sh +263 -0
- package/scripts/test-railway-db.js +222 -0
- package/scripts/test-redis-storage.ts +490 -0
- package/scripts/test-rlm-basic.sh +122 -0
- package/scripts/test-rlm-comprehensive.sh +260 -0
- package/scripts/test-rlm-e2e.sh +268 -0
- package/scripts/test-rlm-simple.js +90 -0
- package/scripts/test-rlm.js +110 -0
- package/scripts/test-session-handoff.sh +165 -0
- package/scripts/test-shell-integration.sh +275 -0
- package/scripts/testing/ab-test-runner.ts +508 -0
- package/scripts/testing/collect-metrics.ts +457 -0
- package/scripts/testing/quick-effectiveness-demo.js +187 -0
- package/scripts/testing/real-performance-test.js +422 -0
- package/scripts/testing/run-effectiveness-tests.sh +176 -0
- package/scripts/testing/scripts/testing/ab-test-runner.js +363 -0
- package/scripts/testing/scripts/testing/collect-metrics.js +292 -0
- package/scripts/testing/simple-effectiveness-test.js +310 -0
- package/scripts/testing/src/core/context/context-bridge.js +253 -0
- package/scripts/testing/src/core/context/frame-manager.js +746 -0
- package/scripts/testing/src/core/context/shared-context-layer.js +437 -0
- package/scripts/testing/src/core/database/database-adapter.js +54 -0
- package/scripts/testing/src/core/errors/index.js +291 -0
- package/scripts/testing/src/core/errors/recovery.js +268 -0
- package/scripts/testing/src/core/monitoring/logger.js +145 -0
- package/scripts/testing/src/core/retrieval/context-retriever.js +516 -0
- package/scripts/testing/src/core/session/index.js +1 -0
- package/scripts/testing/src/core/session/session-manager.js +323 -0
- package/scripts/testing/src/core/trace/cli-trace-wrapper.js +140 -0
- package/scripts/testing/src/core/trace/db-trace-wrapper.js +251 -0
- package/scripts/testing/src/core/trace/debug-trace.js +398 -0
- package/scripts/testing/src/core/trace/index.js +120 -0
- package/scripts/testing/src/core/trace/linear-api-wrapper.js +204 -0
- package/scripts/update-linear-status.js +268 -0
- package/scripts/update-linear-tasks-fixed.js +284 -0
- package/templates/claude-hooks/hooks.json +5 -0
- package/templates/claude-hooks/on-clear.js +56 -0
- package/templates/claude-hooks/on-startup.js +56 -0
- package/templates/claude-hooks/tool-use-trace.js +67 -0
- package/dist/features/tui/components/analytics-panel.js +0 -157
- package/dist/features/tui/components/analytics-panel.js.map +0 -7
- package/dist/features/tui/components/frame-visualizer.js +0 -377
- package/dist/features/tui/components/frame-visualizer.js.map +0 -7
- package/dist/features/tui/components/pr-tracker.js +0 -135
- package/dist/features/tui/components/pr-tracker.js.map +0 -7
- package/dist/features/tui/components/session-monitor.js +0 -299
- package/dist/features/tui/components/session-monitor.js.map +0 -7
- package/dist/features/tui/components/subagent-fleet.js +0 -395
- package/dist/features/tui/components/subagent-fleet.js.map +0 -7
- package/dist/features/tui/components/task-board.js +0 -1139
- package/dist/features/tui/components/task-board.js.map +0 -7
- package/dist/features/tui/index.js +0 -408
- package/dist/features/tui/index.js.map +0 -7
- package/dist/features/tui/services/data-service.js +0 -641
- package/dist/features/tui/services/data-service.js.map +0 -7
- package/dist/features/tui/services/linear-task-reader.js +0 -102
- package/dist/features/tui/services/linear-task-reader.js.map +0 -7
- package/dist/features/tui/services/websocket-client.js +0 -162
- package/dist/features/tui/services/websocket-client.js.map +0 -7
- package/dist/features/tui/terminal-compat.js +0 -220
- package/dist/features/tui/terminal-compat.js.map +0 -7
- package/dist/features/tui/types.js +0 -1
- package/dist/features/tui/types.js.map +0 -7
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Claude-SM Pre-commit Hook - AI-powered code review, refactoring, and testing
|
|
3
|
+
# Integrates with StackMemory for context-aware analysis
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
# Colors for output
|
|
8
|
+
RED='\033[0;31m'
|
|
9
|
+
GREEN='\033[0;32m'
|
|
10
|
+
YELLOW='\033[1;33m'
|
|
11
|
+
BLUE='\033[0;34m'
|
|
12
|
+
NC='\033[0m' # No Color
|
|
13
|
+
|
|
14
|
+
# Configuration
|
|
15
|
+
CLAUDE_REVIEW_ENABLED=${CLAUDE_REVIEW_ENABLED:-true}
|
|
16
|
+
CLAUDE_REFACTOR_ENABLED=${CLAUDE_REFACTOR_ENABLED:-true}
|
|
17
|
+
CLAUDE_TEST_ENABLED=${CLAUDE_TEST_ENABLED:-true}
|
|
18
|
+
CLAUDE_AUTO_FIX=${CLAUDE_AUTO_FIX:-false}
|
|
19
|
+
MAX_FILE_SIZE=${MAX_FILE_SIZE:-100000} # 100KB limit per file
|
|
20
|
+
MAX_TOTAL_SIZE=${MAX_TOTAL_SIZE:-500000} # 500KB total limit
|
|
21
|
+
|
|
22
|
+
# StackMemory context file
|
|
23
|
+
SM_CONTEXT_FILE=".stackmemory/pre-commit-context.json"
|
|
24
|
+
|
|
25
|
+
# Track if we made any changes
|
|
26
|
+
CHANGES_MADE=false
|
|
27
|
+
|
|
28
|
+
echo -e "${BLUE}๐ค Claude-SM Pre-commit Hook Starting...${NC}"
|
|
29
|
+
|
|
30
|
+
# Function to check if Claude is available
|
|
31
|
+
check_claude() {
|
|
32
|
+
if ! command -v claude &> /dev/null; then
|
|
33
|
+
echo -e "${YELLOW}โ Claude CLI not found. Skipping AI review.${NC}"
|
|
34
|
+
exit 0
|
|
35
|
+
fi
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Function to check if StackMemory is available
|
|
39
|
+
check_stackmemory() {
|
|
40
|
+
if ! command -v stackmemory &> /dev/null; then
|
|
41
|
+
echo -e "${YELLOW}โ StackMemory not found. Running without context.${NC}"
|
|
42
|
+
return 1
|
|
43
|
+
fi
|
|
44
|
+
return 0
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# Function to get staged files
|
|
48
|
+
get_staged_files() {
|
|
49
|
+
git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|ts|jsx|tsx|py|go|rs|java)$' || true
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Function to check file size
|
|
53
|
+
check_file_size() {
|
|
54
|
+
local file=$1
|
|
55
|
+
local size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null || echo "0")
|
|
56
|
+
if [ "$size" -gt "$MAX_FILE_SIZE" ]; then
|
|
57
|
+
echo -e "${YELLOW}โ Skipping $file (too large: ${size} bytes)${NC}"
|
|
58
|
+
return 1
|
|
59
|
+
fi
|
|
60
|
+
return 0
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# Function to save context to StackMemory
|
|
64
|
+
save_context() {
|
|
65
|
+
local stage=$1
|
|
66
|
+
local content=$2
|
|
67
|
+
|
|
68
|
+
if check_stackmemory; then
|
|
69
|
+
echo "$content" | stackmemory context add decision "Pre-commit $stage: $content" 2>/dev/null || true
|
|
70
|
+
fi
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
# Function to perform code review
|
|
74
|
+
perform_code_review() {
|
|
75
|
+
local file=$1
|
|
76
|
+
echo -e "${BLUE}๐ Reviewing: $file${NC}"
|
|
77
|
+
|
|
78
|
+
local review_prompt="Review this code for:
|
|
79
|
+
1. Security vulnerabilities
|
|
80
|
+
2. Performance issues
|
|
81
|
+
3. Code smell and anti-patterns
|
|
82
|
+
4. Missing error handling
|
|
83
|
+
5. Potential bugs
|
|
84
|
+
|
|
85
|
+
Be concise. List only critical issues.
|
|
86
|
+
|
|
87
|
+
Code from $file:
|
|
88
|
+
$(cat "$file")"
|
|
89
|
+
|
|
90
|
+
local review_result=$(echo "$review_prompt" | claude 2>/dev/null || echo "Review failed")
|
|
91
|
+
|
|
92
|
+
if echo "$review_result" | grep -iE "vulnerability|security|critical|danger|unsafe" > /dev/null; then
|
|
93
|
+
echo -e "${RED}โ Critical issues found in $file:${NC}"
|
|
94
|
+
echo "$review_result"
|
|
95
|
+
save_context "review" "Critical issues in $file: $review_result"
|
|
96
|
+
return 1
|
|
97
|
+
elif echo "$review_result" | grep -iE "issue|problem|concern|warning" > /dev/null; then
|
|
98
|
+
echo -e "${YELLOW}โ Issues found in $file:${NC}"
|
|
99
|
+
echo "$review_result"
|
|
100
|
+
save_context "review" "Issues in $file: $review_result"
|
|
101
|
+
else
|
|
102
|
+
echo -e "${GREEN}โ No major issues found${NC}"
|
|
103
|
+
fi
|
|
104
|
+
|
|
105
|
+
return 0
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
# Function to suggest refactoring
|
|
109
|
+
suggest_refactoring() {
|
|
110
|
+
local file=$1
|
|
111
|
+
echo -e "${BLUE}๐ง Analyzing refactoring opportunities: $file${NC}"
|
|
112
|
+
|
|
113
|
+
local refactor_prompt="Suggest refactoring for this code. Focus on:
|
|
114
|
+
1. Extracting complex functions
|
|
115
|
+
2. Reducing cyclomatic complexity
|
|
116
|
+
3. Improving naming
|
|
117
|
+
4. DRY principle violations
|
|
118
|
+
5. SOLID principle violations
|
|
119
|
+
|
|
120
|
+
Only suggest if complexity > 10 or obvious improvements exist.
|
|
121
|
+
Be very brief. Show only the most important refactoring.
|
|
122
|
+
|
|
123
|
+
Code from $file:
|
|
124
|
+
$(cat "$file")"
|
|
125
|
+
|
|
126
|
+
local refactor_result=$(echo "$refactor_prompt" | claude 2>/dev/null || echo "")
|
|
127
|
+
|
|
128
|
+
if [ -n "$refactor_result" ] && echo "$refactor_result" | grep -E "function|method|class|extract|rename" > /dev/null; then
|
|
129
|
+
echo -e "${YELLOW}๐ก Refactoring suggestions:${NC}"
|
|
130
|
+
echo "$refactor_result"
|
|
131
|
+
save_context "refactor" "Refactoring suggested for $file"
|
|
132
|
+
|
|
133
|
+
if [ "$CLAUDE_AUTO_FIX" = "true" ]; then
|
|
134
|
+
echo -e "${BLUE}๐ Applying refactoring...${NC}"
|
|
135
|
+
# Here we'd apply the refactoring, but for safety we'll just flag it
|
|
136
|
+
CHANGES_MADE=true
|
|
137
|
+
fi
|
|
138
|
+
fi
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
# Function to generate edge case tests
|
|
142
|
+
generate_edge_tests() {
|
|
143
|
+
local file=$1
|
|
144
|
+
local test_file="${file%.*}.test.${file##*.}"
|
|
145
|
+
|
|
146
|
+
# Skip if test file already exists
|
|
147
|
+
if [ -f "$test_file" ]; then
|
|
148
|
+
echo -e "${BLUE}๐งช Test file exists: $test_file${NC}"
|
|
149
|
+
return 0
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
echo -e "${BLUE}๐งช Generating edge case tests: $file${NC}"
|
|
153
|
+
|
|
154
|
+
local test_prompt="Generate edge case tests for this code. Include:
|
|
155
|
+
1. Null/undefined inputs
|
|
156
|
+
2. Empty arrays/objects
|
|
157
|
+
3. Boundary values
|
|
158
|
+
4. Invalid types
|
|
159
|
+
5. Concurrent access (if applicable)
|
|
160
|
+
|
|
161
|
+
Output only the test code, no explanation.
|
|
162
|
+
Use the appropriate testing framework for the language.
|
|
163
|
+
|
|
164
|
+
Code from $file:
|
|
165
|
+
$(cat "$file")"
|
|
166
|
+
|
|
167
|
+
local test_result=$(echo "$test_prompt" | claude 2>/dev/null || echo "")
|
|
168
|
+
|
|
169
|
+
if [ -n "$test_result" ] && echo "$test_result" | grep -E "test|describe|it\(|expect|assert" > /dev/null; then
|
|
170
|
+
echo -e "${GREEN}โ Edge case tests generated${NC}"
|
|
171
|
+
|
|
172
|
+
if [ "$CLAUDE_AUTO_FIX" = "true" ]; then
|
|
173
|
+
echo "$test_result" > "$test_file"
|
|
174
|
+
git add "$test_file"
|
|
175
|
+
echo -e "${GREEN}โ Test file created: $test_file${NC}"
|
|
176
|
+
CHANGES_MADE=true
|
|
177
|
+
else
|
|
178
|
+
echo -e "${YELLOW}๐ก Suggested test cases:${NC}"
|
|
179
|
+
echo "$test_result" | head -20
|
|
180
|
+
echo "..."
|
|
181
|
+
save_context "test" "Edge cases suggested for $file"
|
|
182
|
+
fi
|
|
183
|
+
fi
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
# Function to run comprehensive analysis
|
|
187
|
+
analyze_file() {
|
|
188
|
+
local file=$1
|
|
189
|
+
local has_issues=false
|
|
190
|
+
|
|
191
|
+
if ! check_file_size "$file"; then
|
|
192
|
+
return 0
|
|
193
|
+
fi
|
|
194
|
+
|
|
195
|
+
echo -e "\n${BLUE}โโโ Analyzing: $file โโโ${NC}"
|
|
196
|
+
|
|
197
|
+
# Code Review
|
|
198
|
+
if [ "$CLAUDE_REVIEW_ENABLED" = "true" ]; then
|
|
199
|
+
if ! perform_code_review "$file"; then
|
|
200
|
+
has_issues=true
|
|
201
|
+
fi
|
|
202
|
+
fi
|
|
203
|
+
|
|
204
|
+
# Refactoring Suggestions
|
|
205
|
+
if [ "$CLAUDE_REFACTOR_ENABLED" = "true" ]; then
|
|
206
|
+
suggest_refactoring "$file"
|
|
207
|
+
fi
|
|
208
|
+
|
|
209
|
+
# Edge Case Testing
|
|
210
|
+
if [ "$CLAUDE_TEST_ENABLED" = "true" ]; then
|
|
211
|
+
generate_edge_tests "$file"
|
|
212
|
+
fi
|
|
213
|
+
|
|
214
|
+
if [ "$has_issues" = "true" ]; then
|
|
215
|
+
return 1
|
|
216
|
+
fi
|
|
217
|
+
return 0
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
# Function to generate commit context
|
|
221
|
+
generate_commit_context() {
|
|
222
|
+
local files="$1"
|
|
223
|
+
|
|
224
|
+
if check_stackmemory; then
|
|
225
|
+
local context=$(stackmemory context show --json 2>/dev/null || echo "{}")
|
|
226
|
+
echo "{
|
|
227
|
+
\"timestamp\": $(date +%s),
|
|
228
|
+
\"files\": $(echo "$files" | jq -R -s -c 'split("\n")[:-1]'),
|
|
229
|
+
\"context\": $context
|
|
230
|
+
}" > "$SM_CONTEXT_FILE"
|
|
231
|
+
fi
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
# Main execution
|
|
235
|
+
main() {
|
|
236
|
+
check_claude
|
|
237
|
+
|
|
238
|
+
# Get staged files
|
|
239
|
+
STAGED_FILES=$(get_staged_files)
|
|
240
|
+
|
|
241
|
+
if [ -z "$STAGED_FILES" ]; then
|
|
242
|
+
echo -e "${YELLOW}No staged files to review${NC}"
|
|
243
|
+
exit 0
|
|
244
|
+
fi
|
|
245
|
+
|
|
246
|
+
# Count files
|
|
247
|
+
FILE_COUNT=$(echo "$STAGED_FILES" | wc -l)
|
|
248
|
+
echo -e "${BLUE}Found $FILE_COUNT staged file(s) for review${NC}"
|
|
249
|
+
|
|
250
|
+
# Check total size
|
|
251
|
+
TOTAL_SIZE=0
|
|
252
|
+
for file in $STAGED_FILES; do
|
|
253
|
+
if [ -f "$file" ]; then
|
|
254
|
+
size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null || echo "0")
|
|
255
|
+
TOTAL_SIZE=$((TOTAL_SIZE + size))
|
|
256
|
+
fi
|
|
257
|
+
done
|
|
258
|
+
|
|
259
|
+
if [ "$TOTAL_SIZE" -gt "$MAX_TOTAL_SIZE" ]; then
|
|
260
|
+
echo -e "${YELLOW}โ Total size too large ($TOTAL_SIZE bytes). Limiting review.${NC}"
|
|
261
|
+
fi
|
|
262
|
+
|
|
263
|
+
# Generate context for StackMemory
|
|
264
|
+
generate_commit_context "$STAGED_FILES"
|
|
265
|
+
|
|
266
|
+
# Analyze each file
|
|
267
|
+
HAS_CRITICAL_ISSUES=false
|
|
268
|
+
for file in $STAGED_FILES; do
|
|
269
|
+
if [ -f "$file" ]; then
|
|
270
|
+
if ! analyze_file "$file"; then
|
|
271
|
+
HAS_CRITICAL_ISSUES=true
|
|
272
|
+
fi
|
|
273
|
+
fi
|
|
274
|
+
done
|
|
275
|
+
|
|
276
|
+
echo -e "\n${BLUE}โโโ Summary โโโ${NC}"
|
|
277
|
+
|
|
278
|
+
# If changes were made, restage files
|
|
279
|
+
if [ "$CHANGES_MADE" = "true" ]; then
|
|
280
|
+
echo -e "${YELLOW}๐ Changes were made. Restaging files...${NC}"
|
|
281
|
+
for file in $STAGED_FILES; do
|
|
282
|
+
if [ -f "$file" ]; then
|
|
283
|
+
git add "$file"
|
|
284
|
+
fi
|
|
285
|
+
done
|
|
286
|
+
fi
|
|
287
|
+
|
|
288
|
+
# Final decision
|
|
289
|
+
if [ "$HAS_CRITICAL_ISSUES" = "true" ]; then
|
|
290
|
+
echo -e "${RED}โ Commit blocked due to critical issues${NC}"
|
|
291
|
+
echo -e "${YELLOW}Fix the issues and try again, or use --no-verify to skip${NC}"
|
|
292
|
+
exit 1
|
|
293
|
+
else
|
|
294
|
+
echo -e "${GREEN}โ
Pre-commit checks passed${NC}"
|
|
295
|
+
|
|
296
|
+
# Save successful review to StackMemory
|
|
297
|
+
save_context "completed" "Pre-commit checks passed for $(echo "$STAGED_FILES" | wc -l) files"
|
|
298
|
+
fi
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
# Run main function
|
|
302
|
+
main "$@"
|