@stackmemoryai/stackmemory 0.3.17 โ†’ 0.3.19

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 (234) hide show
  1. package/dist/cli/claude-sm.js +51 -5
  2. package/dist/cli/claude-sm.js.map +2 -2
  3. package/dist/cli/codex-sm.js +52 -19
  4. package/dist/cli/codex-sm.js.map +2 -2
  5. package/dist/cli/commands/db.js +143 -0
  6. package/dist/cli/commands/db.js.map +7 -0
  7. package/dist/cli/commands/login.js +50 -0
  8. package/dist/cli/commands/login.js.map +7 -0
  9. package/dist/cli/commands/migrate.js +178 -0
  10. package/dist/cli/commands/migrate.js.map +7 -0
  11. package/dist/cli/commands/onboard.js +158 -2
  12. package/dist/cli/commands/onboard.js.map +2 -2
  13. package/dist/cli/commands/skills.js +15 -2
  14. package/dist/cli/commands/skills.js.map +2 -2
  15. package/dist/cli/index.js +118 -834
  16. package/dist/cli/index.js.map +3 -3
  17. package/dist/core/context/dual-stack-manager.js +1 -1
  18. package/dist/core/context/dual-stack-manager.js.map +1 -1
  19. package/dist/core/context/frame-database.js +1 -0
  20. package/dist/core/context/frame-database.js.map +2 -2
  21. package/dist/core/context/frame-manager.js +59 -2
  22. package/dist/core/context/frame-manager.js.map +2 -2
  23. package/dist/core/database/database-adapter.js +6 -1
  24. package/dist/core/database/database-adapter.js.map +2 -2
  25. package/dist/core/database/sqlite-adapter.js +60 -2
  26. package/dist/core/database/sqlite-adapter.js.map +2 -2
  27. package/dist/integrations/claude-code/subagent-client.js +106 -3
  28. package/dist/integrations/claude-code/subagent-client.js.map +2 -2
  29. package/dist/servers/railway/config.js +51 -0
  30. package/dist/servers/railway/config.js.map +7 -0
  31. package/dist/servers/railway/index-enhanced.js +156 -0
  32. package/dist/servers/railway/index-enhanced.js.map +7 -0
  33. package/dist/servers/railway/index.js +843 -82
  34. package/dist/servers/railway/index.js.map +3 -3
  35. package/dist/servers/railway/minimal.js +48 -3
  36. package/dist/servers/railway/minimal.js.map +2 -2
  37. package/dist/servers/railway/storage-test.js +455 -0
  38. package/dist/servers/railway/storage-test.js.map +7 -0
  39. package/dist/skills/claude-skills.js +13 -12
  40. package/dist/skills/claude-skills.js.map +2 -2
  41. package/dist/skills/recursive-agent-orchestrator.js +27 -18
  42. package/dist/skills/recursive-agent-orchestrator.js.map +2 -2
  43. package/dist/skills/unified-rlm-orchestrator.js.map +2 -2
  44. package/package.json +13 -21
  45. package/scripts/README-TESTING.md +186 -0
  46. package/scripts/analyze-cli-security.js +288 -0
  47. package/scripts/archive/add-phase-tasks-to-linear.js +163 -0
  48. package/scripts/archive/analyze-linear-duplicates.js +214 -0
  49. package/scripts/archive/analyze-remaining-duplicates.js +230 -0
  50. package/scripts/archive/analyze-sta-duplicates.js +292 -0
  51. package/scripts/archive/analyze-sta-graphql.js +399 -0
  52. package/scripts/archive/cancel-duplicate-tasks.ts +246 -0
  53. package/scripts/archive/check-all-duplicates.ts +419 -0
  54. package/scripts/archive/clean-duplicate-tasks.js +114 -0
  55. package/scripts/archive/cleanup-duplicate-tasks.ts +286 -0
  56. package/scripts/archive/create-phase-tasks.js +387 -0
  57. package/scripts/archive/delete-linear-duplicates.js +182 -0
  58. package/scripts/archive/delete-remaining-duplicates.js +158 -0
  59. package/scripts/archive/delete-sta-duplicates.js +201 -0
  60. package/scripts/archive/delete-sta-oauth.js +201 -0
  61. package/scripts/archive/export-sta-tasks.js +62 -0
  62. package/scripts/archive/install-auto-sync.js +266 -0
  63. package/scripts/archive/install-chromadb-hooks.sh +133 -0
  64. package/scripts/archive/install-enhanced-clear-hooks.sh +431 -0
  65. package/scripts/archive/install-post-task-hooks.sh +289 -0
  66. package/scripts/archive/install-stackmemory-hooks.sh +420 -0
  67. package/scripts/archive/merge-linear-duplicates-safe.ts +362 -0
  68. package/scripts/archive/merge-linear-duplicates.ts +180 -0
  69. package/scripts/archive/remove-sta-tasks.js +70 -0
  70. package/scripts/archive/setup-background-sync.sh +168 -0
  71. package/scripts/archive/setup-claude-auto-triggers.sh +181 -0
  72. package/scripts/archive/setup-claude-autostart.sh +305 -0
  73. package/scripts/archive/setup-git-hooks.sh +25 -0
  74. package/scripts/archive/setup-linear-oauth.sh +46 -0
  75. package/scripts/archive/setup-mcp.sh +113 -0
  76. package/scripts/archive/setup-railway-deployment.sh +81 -0
  77. package/scripts/auto-handoff.sh +262 -0
  78. package/scripts/background-sync-manager.js +416 -0
  79. package/scripts/benchmark-performance.ts +57 -0
  80. package/scripts/check-redis.ts +48 -0
  81. package/scripts/chromadb-auto-loader.sh +128 -0
  82. package/scripts/chromadb-context-loader.js +479 -0
  83. package/scripts/claude-chromadb-hook.js +460 -0
  84. package/scripts/claude-code-wrapper.sh +66 -0
  85. package/scripts/claude-linear-skill.js +455 -0
  86. package/scripts/claude-pre-commit.sh +302 -0
  87. package/scripts/claude-sm-autostart.js +532 -0
  88. package/scripts/claude-sm-setup.sh +367 -0
  89. package/scripts/claude-with-chromadb.sh +69 -0
  90. package/scripts/claude-worktree-manager.sh +323 -0
  91. package/scripts/claude-worktree-monitor.sh +371 -0
  92. package/scripts/claude-worktree-setup.sh +327 -0
  93. package/scripts/clean-linear-backlog.js +273 -0
  94. package/scripts/cleanup-old-sessions.sh +57 -0
  95. package/scripts/codex-wrapper.sh +88 -0
  96. package/scripts/create-sandbox.sh +269 -0
  97. package/scripts/debug-linear-update.js +174 -0
  98. package/scripts/delete-linear-tasks.js +167 -0
  99. package/scripts/deploy.sh +89 -0
  100. package/scripts/deployment/railway.sh +352 -0
  101. package/scripts/deployment/test-deployment.js +194 -0
  102. package/scripts/detect-and-rehydrate.js +162 -0
  103. package/scripts/detect-and-rehydrate.mjs +165 -0
  104. package/scripts/development/create-demo-tasks.js +143 -0
  105. package/scripts/development/debug-frame-test.js +16 -0
  106. package/scripts/development/demo-auto-sync.js +128 -0
  107. package/scripts/development/fix-all-imports.js +213 -0
  108. package/scripts/development/fix-imports.js +229 -0
  109. package/scripts/development/fix-lint-loop.cjs +103 -0
  110. package/scripts/development/fix-project-id.ts +161 -0
  111. package/scripts/development/fix-strict-mode-issues.ts +291 -0
  112. package/scripts/development/reorganize-structure.sh +228 -0
  113. package/scripts/development/test-persistence-direct.js +148 -0
  114. package/scripts/development/test-persistence.js +114 -0
  115. package/scripts/development/test-tasks.js +93 -0
  116. package/scripts/development/update-imports.js +212 -0
  117. package/scripts/fetch-linear-status.js +125 -0
  118. package/scripts/git-hooks/README.md +310 -0
  119. package/scripts/git-hooks/branch-context-manager.sh +342 -0
  120. package/scripts/git-hooks/post-checkout-stackmemory.sh +63 -0
  121. package/scripts/git-hooks/post-commit-stackmemory.sh +305 -0
  122. package/scripts/git-hooks/pre-commit-stackmemory.sh +275 -0
  123. package/scripts/hooks/cleanup-shell.sh +130 -0
  124. package/scripts/hooks/task-complete.sh +114 -0
  125. package/scripts/initialize.ts +129 -0
  126. package/scripts/install-claude-hooks-auto.js +104 -0
  127. package/scripts/install-claude-hooks.sh +133 -0
  128. package/scripts/install-global.sh +296 -0
  129. package/scripts/install.sh +235 -0
  130. package/scripts/linear-auto-sync.js +262 -0
  131. package/scripts/linear-auto-sync.sh +161 -0
  132. package/scripts/linear-sync-daemon.js +150 -0
  133. package/scripts/linear-task-review.js +237 -0
  134. package/scripts/list-linear-tasks.ts +178 -0
  135. package/scripts/mcp-proxy.js +66 -0
  136. package/scripts/opencode-wrapper.sh +85 -0
  137. package/scripts/publish-local.js +74 -0
  138. package/scripts/query-chromadb.ts +201 -0
  139. package/scripts/railway-env-setup.sh +39 -0
  140. package/scripts/reconcile-local-tasks.js +170 -0
  141. package/scripts/recreate-frames-db.js +89 -0
  142. package/scripts/setup/claude-integration.js +138 -0
  143. package/scripts/setup/configure-alias.js +125 -0
  144. package/scripts/setup/configure-codex-alias.js +161 -0
  145. package/scripts/setup/configure-opencode-alias.js +175 -0
  146. package/scripts/setup-claude-integration.js +204 -0
  147. package/scripts/setup-claude-integration.sh +183 -0
  148. package/scripts/setup-railway-deployment.sh +37 -0
  149. package/scripts/setup.sh +31 -0
  150. package/scripts/show-linear-summary.ts +172 -0
  151. package/scripts/stackmemory-auto-handoff.sh +231 -0
  152. package/scripts/stackmemory-daemon.sh +40 -0
  153. package/scripts/start-linear-sync-daemon.sh +141 -0
  154. package/scripts/start-temporal-paradox.sh +214 -0
  155. package/scripts/status.ts +159 -0
  156. package/scripts/sync-and-clean-tasks.js +258 -0
  157. package/scripts/sync-frames-from-railway.js +228 -0
  158. package/scripts/sync-linear-graphql.js +303 -0
  159. package/scripts/sync-linear-tasks.js +186 -0
  160. package/scripts/test-auto-triggers.sh +57 -0
  161. package/scripts/test-browser-mcp.js +74 -0
  162. package/scripts/test-chromadb-full.js +115 -0
  163. package/scripts/test-chromadb-hooks.sh +28 -0
  164. package/scripts/test-chromadb-sync.ts +245 -0
  165. package/scripts/test-cli-security.js +293 -0
  166. package/scripts/test-hooks-persistence.sh +220 -0
  167. package/scripts/test-installation-scenarios.sh +359 -0
  168. package/scripts/test-installation.sh +224 -0
  169. package/scripts/test-mcp.js +163 -0
  170. package/scripts/test-pre-publish-quick.sh +75 -0
  171. package/scripts/test-quality-gates.sh +263 -0
  172. package/scripts/test-railway-db.js +222 -0
  173. package/scripts/test-redis-storage.ts +490 -0
  174. package/scripts/test-rlm-basic.sh +122 -0
  175. package/scripts/test-rlm-comprehensive.sh +260 -0
  176. package/scripts/test-rlm-e2e.sh +268 -0
  177. package/scripts/test-rlm-simple.js +90 -0
  178. package/scripts/test-rlm.js +110 -0
  179. package/scripts/test-session-handoff.sh +165 -0
  180. package/scripts/test-shell-integration.sh +275 -0
  181. package/scripts/testing/ab-test-runner.ts +508 -0
  182. package/scripts/testing/collect-metrics.ts +457 -0
  183. package/scripts/testing/quick-effectiveness-demo.js +187 -0
  184. package/scripts/testing/real-performance-test.js +422 -0
  185. package/scripts/testing/run-effectiveness-tests.sh +176 -0
  186. package/scripts/testing/scripts/testing/ab-test-runner.js +363 -0
  187. package/scripts/testing/scripts/testing/collect-metrics.js +292 -0
  188. package/scripts/testing/simple-effectiveness-test.js +310 -0
  189. package/scripts/testing/src/core/context/context-bridge.js +253 -0
  190. package/scripts/testing/src/core/context/frame-manager.js +746 -0
  191. package/scripts/testing/src/core/context/shared-context-layer.js +437 -0
  192. package/scripts/testing/src/core/database/database-adapter.js +54 -0
  193. package/scripts/testing/src/core/errors/index.js +291 -0
  194. package/scripts/testing/src/core/errors/recovery.js +268 -0
  195. package/scripts/testing/src/core/monitoring/logger.js +145 -0
  196. package/scripts/testing/src/core/retrieval/context-retriever.js +516 -0
  197. package/scripts/testing/src/core/session/index.js +1 -0
  198. package/scripts/testing/src/core/session/session-manager.js +323 -0
  199. package/scripts/testing/src/core/trace/cli-trace-wrapper.js +140 -0
  200. package/scripts/testing/src/core/trace/db-trace-wrapper.js +251 -0
  201. package/scripts/testing/src/core/trace/debug-trace.js +398 -0
  202. package/scripts/testing/src/core/trace/index.js +120 -0
  203. package/scripts/testing/src/core/trace/linear-api-wrapper.js +204 -0
  204. package/scripts/update-linear-status.js +268 -0
  205. package/scripts/update-linear-tasks-fixed.js +284 -0
  206. package/scripts/verify-railway-schema.ts +35 -0
  207. package/templates/claude-hooks/hooks.json +5 -0
  208. package/templates/claude-hooks/on-clear.js +56 -0
  209. package/templates/claude-hooks/on-startup.js +56 -0
  210. package/templates/claude-hooks/tool-use-trace.js +67 -0
  211. package/dist/features/tui/components/analytics-panel.js +0 -157
  212. package/dist/features/tui/components/analytics-panel.js.map +0 -7
  213. package/dist/features/tui/components/frame-visualizer.js +0 -377
  214. package/dist/features/tui/components/frame-visualizer.js.map +0 -7
  215. package/dist/features/tui/components/pr-tracker.js +0 -135
  216. package/dist/features/tui/components/pr-tracker.js.map +0 -7
  217. package/dist/features/tui/components/session-monitor.js +0 -299
  218. package/dist/features/tui/components/session-monitor.js.map +0 -7
  219. package/dist/features/tui/components/subagent-fleet.js +0 -395
  220. package/dist/features/tui/components/subagent-fleet.js.map +0 -7
  221. package/dist/features/tui/components/task-board.js +0 -1139
  222. package/dist/features/tui/components/task-board.js.map +0 -7
  223. package/dist/features/tui/index.js +0 -408
  224. package/dist/features/tui/index.js.map +0 -7
  225. package/dist/features/tui/services/data-service.js +0 -641
  226. package/dist/features/tui/services/data-service.js.map +0 -7
  227. package/dist/features/tui/services/linear-task-reader.js +0 -102
  228. package/dist/features/tui/services/linear-task-reader.js.map +0 -7
  229. package/dist/features/tui/services/websocket-client.js +0 -162
  230. package/dist/features/tui/services/websocket-client.js.map +0 -7
  231. package/dist/features/tui/terminal-compat.js +0 -220
  232. package/dist/features/tui/terminal-compat.js.map +0 -7
  233. package/dist/features/tui/types.js +0 -1
  234. 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 "$@"