@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,130 @@
1
+ #!/bin/bash
2
+
3
+ # Script to clean up and consolidate StackMemory shell configurations
4
+
5
+ echo "🧹 Cleaning up shell configurations..."
6
+
7
+ # Backup files first
8
+ for file in ~/.zshrc ~/.bash_profile ~/.bashrc; do
9
+ if [ -f "$file" ]; then
10
+ cp "$file" "$file.backup.$(date +%Y%m%d_%H%M%S)"
11
+ echo "✓ Backed up $file"
12
+ fi
13
+ done
14
+
15
+ # Create a consolidated StackMemory configuration
16
+ cat > ~/.stackmemory/shell-integration-consolidated.sh << 'EOF'
17
+ #!/bin/bash
18
+ # Consolidated StackMemory Shell Integration
19
+
20
+ # Auto-start StackMemory services if available
21
+ if command -v stackmemory &> /dev/null; then
22
+ # Review recent context on shell start (silent)
23
+ ~/.stackmemory/bin/sm-review recent 1 2>/dev/null || true
24
+
25
+ # Start daemon if not running
26
+ if ! pgrep -f "stackmemory-daemon" > /dev/null; then
27
+ ~/.stackmemory/bin/stackmemory-daemon start --port 9877 2>/dev/null &
28
+ fi
29
+
30
+ # Configure monitor interval
31
+ ~/.stackmemory/bin/stackmemory-monitor config interval 15 2>/dev/null || true
32
+ fi
33
+
34
+ # Auto-detection on directory/git changes
35
+ if command -v stackmemory &> /dev/null; then
36
+ function __stackmemory_auto() {
37
+ stackmemory auto --check 2>/dev/null &
38
+ }
39
+
40
+ # Override cd to trigger auto-detection
41
+ function cd() {
42
+ builtin cd "$@" && __stackmemory_auto
43
+ }
44
+
45
+ # Override git for branch operations
46
+ function git() {
47
+ command git "$@"
48
+ [[ "$1" =~ ^(clone|checkout|switch|merge|pull)$ ]] && __stackmemory_auto
49
+ }
50
+ fi
51
+
52
+ # Claude Code + StackMemory integration function
53
+ claude_code_with_sm() {
54
+ local original_dir=$(pwd)
55
+ claude-code "$@"
56
+ local exit_code=$?
57
+
58
+ # If still in a StackMemory project, save context
59
+ if [ -d ".stackmemory" ]; then
60
+ echo "📝 Saving StackMemory context..."
61
+ stackmemory status 2>/dev/null
62
+ [ -n "$LINEAR_API_KEY" ] && stackmemory linear sync 2>/dev/null
63
+ fi
64
+
65
+ return $exit_code
66
+ }
67
+
68
+ # Task completion hook
69
+ task_complete() {
70
+ ~/Dev/stackmemory/scripts/task-complete-hook.sh complete "$@"
71
+ }
72
+
73
+ # Linear task check
74
+ check_tasks() {
75
+ ~/Dev/stackmemory/scripts/task-complete-hook.sh check
76
+ }
77
+ EOF
78
+
79
+ chmod +x ~/.stackmemory/shell-integration-consolidated.sh
80
+
81
+ echo "✅ Created consolidated shell integration file"
82
+ echo ""
83
+ echo "To complete cleanup:"
84
+ echo "1. Remove duplicate StackMemory entries from ~/.zshrc and ~/.bash_profile"
85
+ echo "2. Keep only: source ~/.stackmemory/shell-integration-consolidated.sh"
86
+ echo "3. Keep the claude-sm alias"
87
+ echo ""
88
+ echo "Would you like me to do this automatically? (y/n)"
89
+ read -p "> " response
90
+
91
+ if [[ "$response" == "y" || "$response" == "Y" ]]; then
92
+ # Clean up ~/.zshrc
93
+ if [ -f ~/.zshrc ]; then
94
+ # Remove duplicate StackMemory blocks, keeping only essential ones
95
+ sed -i '' '/# StackMemory Auto-Start for Claude Code/,/^fi$/d' ~/.zshrc
96
+ sed -i '' '/# StackMemory Auto-Detection/,/^fi$/d' ~/.zshrc
97
+ sed -i '' '/# Auto-start StackMemory when Claude Code is detected/d' ~/.zshrc
98
+ sed -i '' '/source ~\/.stackmemory\/auto-start.sh/d' ~/.zshrc
99
+
100
+ # Ensure we have the consolidated integration
101
+ if ! grep -q "shell-integration-consolidated.sh" ~/.zshrc; then
102
+ sed -i '' 's|source ~/.stackmemory/shell-integration.sh|source ~/.stackmemory/shell-integration-consolidated.sh|' ~/.zshrc
103
+ fi
104
+
105
+ echo "✓ Cleaned up ~/.zshrc"
106
+ fi
107
+
108
+ # Clean up ~/.bash_profile
109
+ if [ -f ~/.bash_profile ]; then
110
+ # Remove duplicate StackMemory blocks
111
+ sed -i '' '/# StackMemory Auto-Start/,/^fi$/d' ~/.bash_profile
112
+ sed -i '' '/# StackMemory Auto-Detection/,/^fi$/d' ~/.bash_profile
113
+
114
+ # Add consolidated integration if not present
115
+ if ! grep -q "stackmemory/shell-integration" ~/.bash_profile; then
116
+ echo "" >> ~/.bash_profile
117
+ echo "# StackMemory integration" >> ~/.bash_profile
118
+ echo "source ~/.stackmemory/shell-integration-consolidated.sh" >> ~/.bash_profile
119
+ fi
120
+
121
+ echo "✓ Cleaned up ~/.bash_profile"
122
+ fi
123
+
124
+ echo ""
125
+ echo "🎉 Cleanup complete! Please restart your terminal or run:"
126
+ echo " source ~/.zshrc (for zsh)"
127
+ echo " source ~/.bash_profile (for bash)"
128
+ else
129
+ echo "Manual cleanup required. Please edit your shell configs."
130
+ fi
@@ -0,0 +1,114 @@
1
+ #!/bin/bash
2
+
3
+ # Task Completion Hook for StackMemory
4
+ # Integrates with Linear to prompt for next task when current task is completed
5
+
6
+ # Colors for output
7
+ GREEN='\033[0;32m'
8
+ YELLOW='\033[1;33m'
9
+ BLUE='\033[0;34m'
10
+ NC='\033[0m' # No Color
11
+
12
+ # Function to check Linear tasks
13
+ check_linear_tasks() {
14
+ if [ -n "$LINEAR_API_KEY" ]; then
15
+ echo -e "${BLUE}📋 Checking Linear tasks...${NC}"
16
+
17
+ # Run Linear sync to get latest tasks
18
+ stackmemory linear sync 2>/dev/null || true
19
+
20
+ # Get current task status
21
+ local status=$(stackmemory linear status 2>/dev/null)
22
+
23
+ if [ -n "$status" ]; then
24
+ echo -e "${GREEN}Current Linear Status:${NC}"
25
+ echo "$status"
26
+ echo ""
27
+ fi
28
+
29
+ # Get available tasks
30
+ echo -e "${YELLOW}Available Linear tasks:${NC}"
31
+ stackmemory linear list --state "todo,in_progress" 2>/dev/null || echo "No tasks found"
32
+
33
+ echo ""
34
+ echo -e "${BLUE}What would you like to work on next?${NC}"
35
+ echo "Options:"
36
+ echo " 1) Pick a Linear task (enter task ID)"
37
+ echo " 2) Continue with local tasks"
38
+ echo " 3) Review recent context"
39
+ echo " 4) Exit"
40
+
41
+ read -p "Choice (1-4 or task ID): " choice
42
+
43
+ case $choice in
44
+ 1)
45
+ read -p "Enter Linear task ID: " task_id
46
+ echo "Starting work on Linear task: $task_id"
47
+ stackmemory linear start "$task_id" 2>/dev/null || true
48
+ ;;
49
+ 2)
50
+ echo "Continuing with local tasks..."
51
+ ;;
52
+ 3)
53
+ echo -e "${BLUE}Recent context:${NC}"
54
+ stackmemory review recent 5
55
+ ;;
56
+ 4)
57
+ echo "Exiting..."
58
+ exit 0
59
+ ;;
60
+ *)
61
+ # Assume it's a task ID
62
+ if [[ $choice =~ ^[A-Z]+-[0-9]+$ ]]; then
63
+ echo "Starting work on Linear task: $choice"
64
+ stackmemory linear start "$choice" 2>/dev/null || true
65
+ fi
66
+ ;;
67
+ esac
68
+ else
69
+ echo -e "${YELLOW}Linear API key not configured. Skipping Linear integration.${NC}"
70
+ fi
71
+ }
72
+
73
+ # Function to save completion context
74
+ save_completion_context() {
75
+ local task_name="$1"
76
+ local completion_notes="$2"
77
+
78
+ echo -e "${GREEN}✅ Task completed: $task_name${NC}"
79
+
80
+ # Save to StackMemory
81
+ if command -v stackmemory &> /dev/null; then
82
+ stackmemory save-context "Task completed: $task_name. $completion_notes" --type "completion"
83
+ stackmemory review snapshot
84
+ fi
85
+ }
86
+
87
+ # Main execution
88
+ main() {
89
+ # Check if we're in a StackMemory-enabled project
90
+ if [ ! -d ".stackmemory" ]; then
91
+ echo "Not in a StackMemory project. Initialize with: stackmemory init"
92
+ exit 1
93
+ fi
94
+
95
+ # Parse arguments
96
+ case "$1" in
97
+ complete)
98
+ shift
99
+ save_completion_context "$@"
100
+ check_linear_tasks
101
+ ;;
102
+ check)
103
+ check_linear_tasks
104
+ ;;
105
+ *)
106
+ echo "Usage: $0 {complete <task_name> [notes]|check}"
107
+ echo " complete - Mark a task as complete and check for next tasks"
108
+ echo " check - Check Linear for available tasks"
109
+ exit 1
110
+ ;;
111
+ esac
112
+ }
113
+
114
+ main "$@"
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env tsx
2
+ /**
3
+ * Initialize StackMemory in the current project
4
+ */
5
+
6
+ import {
7
+ existsSync,
8
+ mkdirSync,
9
+ writeFileSync,
10
+ readFileSync,
11
+ appendFileSync,
12
+ } from 'fs';
13
+ import { join } from 'path';
14
+ import { execSync } from 'child_process';
15
+ import chalk from 'chalk';
16
+ // Type-safe environment variable access
17
+ function getEnv(key: string, defaultValue?: string): string {
18
+ const value = process.env[key];
19
+ if (value === undefined) {
20
+ if (defaultValue !== undefined) return defaultValue;
21
+ throw new Error(`Environment variable ${key} is required`);
22
+ }
23
+ return value;
24
+ }
25
+
26
+ function getOptionalEnv(key: string): string | undefined {
27
+ return process.env[key];
28
+ }
29
+
30
+ const projectRoot = process.cwd();
31
+
32
+ console.log(chalk.blue.bold('\n🚀 Initializing StackMemory...\n'));
33
+
34
+ // 1. Create .stackmemory directory
35
+ const stackDir = join(projectRoot, '.stackmemory');
36
+ if (!existsSync(stackDir)) {
37
+ mkdirSync(stackDir, { recursive: true });
38
+ console.log(chalk.green('✓') + ' Created .stackmemory directory');
39
+ } else {
40
+ console.log(chalk.yellow('⚠') + ' .stackmemory directory already exists');
41
+ }
42
+
43
+ // 2. Add to .gitignore
44
+ const gitignorePath = join(projectRoot, '.gitignore');
45
+ const gitignoreEntry =
46
+ '\n# StackMemory\n.stackmemory/*.db\n.stackmemory/*.db-*\n';
47
+
48
+ if (existsSync(gitignorePath)) {
49
+ const gitignore = readFileSync(gitignorePath, 'utf-8');
50
+ if (!gitignore.includes('.stackmemory')) {
51
+ appendFileSync(gitignorePath, gitignoreEntry);
52
+ console.log(chalk.green('✓') + ' Added .stackmemory to .gitignore');
53
+ }
54
+ } else {
55
+ writeFileSync(gitignorePath, gitignoreEntry);
56
+ console.log(chalk.green('✓') + ' Created .gitignore with .stackmemory');
57
+ }
58
+
59
+ // 3. Create config file
60
+ const configPath = join(stackDir, 'config.json');
61
+ if (!existsSync(configPath)) {
62
+ const config = {
63
+ projectId: projectRoot.split('/').pop(),
64
+ userId: process.env['USER'] || 'default',
65
+ teamId: 'local',
66
+ initialized: new Date().toISOString(),
67
+ };
68
+ writeFileSync(configPath, JSON.stringify(config, null, 2));
69
+ console.log(chalk.green('✓') + ' Created config file');
70
+ }
71
+
72
+ // 4. Create initial JSONL file
73
+ const jsonlPath = join(stackDir, 'frames.jsonl');
74
+ if (!existsSync(jsonlPath)) {
75
+ const initialFrame = {
76
+ id: 'init_' + Date.now(),
77
+ type: 'system',
78
+ content: 'StackMemory initialized',
79
+ timestamp: Date.now(),
80
+ };
81
+ writeFileSync(jsonlPath, JSON.stringify(initialFrame) + '\n');
82
+ console.log(chalk.green('✓') + ' Created frames.jsonl');
83
+ }
84
+
85
+ // 5. Create MCP config for Claude Code
86
+ const mcpConfigPath = join(
87
+ process.env['HOME'] || '~',
88
+ '.config',
89
+ 'claude',
90
+ 'mcp.json'
91
+ );
92
+ console.log(chalk.blue('\n📝 MCP Configuration for Claude Code:\n'));
93
+
94
+ const mcpConfig = {
95
+ mcpServers: {
96
+ stackmemory: {
97
+ command: 'node',
98
+ args: [join(projectRoot, 'dist', 'mcp-server.js')],
99
+ env: {
100
+ PROJECT_ROOT: projectRoot,
101
+ },
102
+ },
103
+ },
104
+ };
105
+
106
+ console.log(chalk.gray('Add this to your Claude Code MCP configuration:'));
107
+ console.log(chalk.gray('(' + mcpConfigPath + ')\n'));
108
+ console.log(chalk.cyan(JSON.stringify(mcpConfig, null, 2)));
109
+
110
+ // 6. Build the project
111
+ console.log(chalk.blue('\n📦 Building TypeScript files...\n'));
112
+ try {
113
+ execSync('npm run build', { stdio: 'inherit', cwd: projectRoot });
114
+ console.log(chalk.green('✓') + ' Build completed');
115
+ } catch {
116
+ console.log(chalk.yellow('⚠') + ' Build failed - run npm run build manually');
117
+ }
118
+
119
+ console.log(chalk.green.bold('\n✅ StackMemory initialized successfully!\n'));
120
+ console.log(chalk.gray('Next steps:'));
121
+ console.log(chalk.gray('1. Add the MCP configuration above to Claude Code'));
122
+ console.log(chalk.gray('2. Restart Claude Code'));
123
+ console.log(chalk.gray('3. Start using context tracking!'));
124
+ console.log(chalk.gray('\nUseful commands:'));
125
+ console.log(
126
+ chalk.cyan(' npm run mcp:dev') + ' - Start MCP server in dev mode'
127
+ );
128
+ console.log(chalk.cyan(' npm run status') + ' - Check StackMemory status');
129
+ console.log(chalk.cyan(' npm run analyze') + ' - Analyze context usage\n');
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Auto-install Claude hooks during npm install
5
+ * This runs as a postinstall script to set up tracing hooks
6
+ */
7
+
8
+ import { existsSync, mkdirSync, copyFileSync, readFileSync, writeFileSync } from 'fs';
9
+ import { join } from 'path';
10
+ import { homedir } from 'os';
11
+
12
+ import { fileURLToPath } from 'url';
13
+ import { dirname } from 'path';
14
+
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = dirname(__filename);
17
+
18
+ const claudeHooksDir = join(homedir(), '.claude', 'hooks');
19
+ const claudeConfigFile = join(homedir(), '.claude', 'hooks.json');
20
+ const templatesDir = join(__dirname, '..', 'templates', 'claude-hooks');
21
+
22
+ async function installClaudeHooks() {
23
+ try {
24
+ // Create Claude hooks directory if it doesn't exist
25
+ if (!existsSync(claudeHooksDir)) {
26
+ mkdirSync(claudeHooksDir, { recursive: true });
27
+ console.log('📁 Created Claude hooks directory');
28
+ }
29
+
30
+ // Copy hook files
31
+ const hookFiles = ['tool-use-trace.js', 'on-startup.js', 'on-clear.js'];
32
+ let installed = 0;
33
+
34
+ for (const hookFile of hookFiles) {
35
+ const srcPath = join(templatesDir, hookFile);
36
+ const destPath = join(claudeHooksDir, hookFile);
37
+
38
+ if (existsSync(srcPath)) {
39
+ // Backup existing hook if it exists
40
+ if (existsSync(destPath)) {
41
+ const backupPath = `${destPath}.backup-${Date.now()}`;
42
+ copyFileSync(destPath, backupPath);
43
+ console.log(`📋 Backed up existing hook: ${hookFile}`);
44
+ }
45
+
46
+ copyFileSync(srcPath, destPath);
47
+
48
+ // Make executable
49
+ try {
50
+ const { execSync } = await import('child_process');
51
+ execSync(`chmod +x "${destPath}"`, { stdio: 'ignore' });
52
+ } catch {
53
+ // Silent fail on chmod
54
+ }
55
+
56
+ installed++;
57
+ console.log(`✅ Installed hook: ${hookFile}`);
58
+ }
59
+ }
60
+
61
+ // Update hooks.json configuration
62
+ let hooksConfig = {};
63
+ if (existsSync(claudeConfigFile)) {
64
+ try {
65
+ hooksConfig = JSON.parse(readFileSync(claudeConfigFile, 'utf8'));
66
+ console.log('📋 Loaded existing hooks.json');
67
+ } catch (err) {
68
+ console.log('⚠️ Could not parse existing hooks.json, creating new');
69
+ }
70
+ }
71
+
72
+ // Add our hooks (don't overwrite existing hooks unless they're ours)
73
+ const newHooksConfig = {
74
+ ...hooksConfig,
75
+ 'tool-use-approval': join(claudeHooksDir, 'tool-use-trace.js'),
76
+ 'on-startup': join(claudeHooksDir, 'on-startup.js'),
77
+ 'on-clear': join(claudeHooksDir, 'on-clear.js')
78
+ };
79
+
80
+ writeFileSync(claudeConfigFile, JSON.stringify(newHooksConfig, null, 2));
81
+ console.log('🔧 Updated hooks.json configuration');
82
+
83
+ if (installed > 0) {
84
+ console.log(`\n🎉 Successfully installed ${installed} Claude hooks for StackMemory tracing!`);
85
+ console.log('🔍 Tool usage and session data will now be automatically logged');
86
+ console.log(`📁 Traces saved to: ${join(homedir(), '.stackmemory', 'traces')}`);
87
+ console.log('\nTo disable tracing, set DEBUG_TRACE=false in your .env file');
88
+ }
89
+
90
+ return true;
91
+ } catch (error) {
92
+ console.error('❌ Failed to install Claude hooks:', error.message);
93
+ console.error(' This is not critical - StackMemory will still work without hooks');
94
+ return false;
95
+ }
96
+ }
97
+
98
+ // Only run if called directly (not imported)
99
+ if (import.meta.url === `file://${process.argv[1]}`) {
100
+ console.log('🔧 Installing StackMemory Claude Code integration hooks...\n');
101
+ await installClaudeHooks();
102
+ }
103
+
104
+ export { installClaudeHooks };
@@ -0,0 +1,133 @@
1
+ #!/bin/bash
2
+ # Install Claude-SM pre-commit hooks
3
+
4
+ set -e
5
+
6
+ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7
+ REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
8
+ HOOKS_DIR="$REPO_ROOT/.git/hooks"
9
+
10
+ # Colors
11
+ GREEN='\033[0;32m'
12
+ YELLOW='\033[1;33m'
13
+ BLUE='\033[0;34m'
14
+ RED='\033[0;31m'
15
+ NC='\033[0m'
16
+
17
+ echo -e "${BLUE}🔧 Installing Claude-SM Pre-commit Hooks${NC}"
18
+
19
+ # Check if in a git repository
20
+ if [ ! -d "$REPO_ROOT/.git" ]; then
21
+ echo -e "${RED}❌ Not in a git repository${NC}"
22
+ exit 1
23
+ fi
24
+
25
+ # Create hooks directory if it doesn't exist
26
+ mkdir -p "$HOOKS_DIR"
27
+
28
+ # Make the claude-pre-commit.sh executable
29
+ chmod +x "$SCRIPT_DIR/claude-pre-commit.sh"
30
+
31
+ # Check if pre-commit hook exists
32
+ if [ -f "$HOOKS_DIR/pre-commit" ]; then
33
+ echo -e "${YELLOW}⚠ Pre-commit hook already exists${NC}"
34
+ echo "Do you want to:"
35
+ echo " 1) Replace it with Claude-SM hook"
36
+ echo " 2) Add Claude-SM to existing hook"
37
+ echo " 3) Cancel installation"
38
+ read -p "Choice [1-3]: " choice
39
+
40
+ case $choice in
41
+ 1)
42
+ mv "$HOOKS_DIR/pre-commit" "$HOOKS_DIR/pre-commit.backup.$(date +%s)"
43
+ echo -e "${GREEN}✓ Backed up existing hook${NC}"
44
+ ;;
45
+ 2)
46
+ mv "$HOOKS_DIR/pre-commit" "$HOOKS_DIR/pre-commit.original"
47
+ ;;
48
+ 3)
49
+ echo -e "${YELLOW}Installation cancelled${NC}"
50
+ exit 0
51
+ ;;
52
+ *)
53
+ echo -e "${RED}Invalid choice${NC}"
54
+ exit 1
55
+ ;;
56
+ esac
57
+ fi
58
+
59
+ # Create the pre-commit hook
60
+ cat > "$HOOKS_DIR/pre-commit" << 'EOF'
61
+ #!/bin/bash
62
+ # Git pre-commit hook with Claude-SM integration
63
+
64
+ # Run original hook if it exists (for option 2)
65
+ if [ -f .git/hooks/pre-commit.original ]; then
66
+ .git/hooks/pre-commit.original
67
+ if [ $? -ne 0 ]; then
68
+ exit 1
69
+ fi
70
+ fi
71
+
72
+ # Get the directory of this script
73
+ HOOKS_DIR="$(dirname "$0")"
74
+ REPO_ROOT="$(git rev-parse --show-toplevel)"
75
+
76
+ # Run Claude-SM pre-commit
77
+ if [ -f "$REPO_ROOT/scripts/claude-pre-commit.sh" ]; then
78
+ "$REPO_ROOT/scripts/claude-pre-commit.sh"
79
+ else
80
+ echo "⚠ Claude-SM pre-commit script not found"
81
+ fi
82
+ EOF
83
+
84
+ chmod +x "$HOOKS_DIR/pre-commit"
85
+
86
+ # Create configuration file
87
+ cat > "$REPO_ROOT/.claude-precommit" << 'EOF'
88
+ # Claude-SM Pre-commit Configuration
89
+ # Edit these settings to customize behavior
90
+
91
+ # Enable/disable features
92
+ CLAUDE_REVIEW_ENABLED=true # Code review for security/bugs
93
+ CLAUDE_REFACTOR_ENABLED=true # Refactoring suggestions
94
+ CLAUDE_TEST_ENABLED=true # Edge case test generation
95
+ CLAUDE_AUTO_FIX=false # Auto-apply fixes (dangerous!)
96
+
97
+ # Size limits
98
+ MAX_FILE_SIZE=100000 # Max size per file (100KB)
99
+ MAX_TOTAL_SIZE=500000 # Max total size (500KB)
100
+
101
+ # Claude CLI settings
102
+ CLAUDE_MODEL=claude-3-opus # Model to use
103
+ CLAUDE_MAX_TOKENS=4000 # Max tokens per request
104
+
105
+ # File patterns to check (regex)
106
+ INCLUDE_PATTERNS='\\.(js|ts|jsx|tsx|py|go|rs|java)$'
107
+ EXCLUDE_PATTERNS='(node_modules|dist|build|vendor)/'
108
+
109
+ # Severity thresholds
110
+ BLOCK_ON_CRITICAL=true # Block commit on critical issues
111
+ WARN_ON_MEDIUM=true # Show warnings for medium issues
112
+ SUGGEST_IMPROVEMENTS=true # Show improvement suggestions
113
+
114
+ # StackMemory integration
115
+ USE_STACKMEMORY=true # Use SM for context
116
+ SAVE_REVIEW_HISTORY=true # Save reviews to SM
117
+ EOF
118
+
119
+ echo -e "${GREEN}✅ Claude-SM pre-commit hooks installed successfully!${NC}"
120
+ echo ""
121
+ echo "Configuration file created at: .claude-precommit"
122
+ echo ""
123
+ echo "To test the hook, try committing some code:"
124
+ echo " git add <file>"
125
+ echo " git commit -m 'test'"
126
+ echo ""
127
+ echo "To skip the hook for a commit:"
128
+ echo " git commit --no-verify -m 'emergency fix'"
129
+ echo ""
130
+ echo "Environment variables you can set:"
131
+ echo " CLAUDE_AUTO_FIX=true # Auto-apply suggested fixes"
132
+ echo " CLAUDE_REVIEW_ENABLED=false # Skip code review"
133
+ echo " CLAUDE_TEST_ENABLED=false # Skip test generation"