@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.
Files changed (213) hide show
  1. package/README.md +48 -2
  2. package/dist/cli/commands/skills.js +15 -2
  3. package/dist/cli/commands/skills.js.map +2 -2
  4. package/dist/cli/index.js +113 -834
  5. package/dist/cli/index.js.map +3 -3
  6. package/dist/core/context/dual-stack-manager.js +1 -1
  7. package/dist/core/context/dual-stack-manager.js.map +1 -1
  8. package/dist/core/context/frame-manager.js +3 -0
  9. package/dist/core/context/frame-manager.js.map +2 -2
  10. package/dist/integrations/claude-code/subagent-client.js +106 -3
  11. package/dist/integrations/claude-code/subagent-client.js.map +2 -2
  12. package/dist/servers/railway/config.js +51 -0
  13. package/dist/servers/railway/config.js.map +7 -0
  14. package/dist/servers/railway/index-enhanced.js +156 -0
  15. package/dist/servers/railway/index-enhanced.js.map +7 -0
  16. package/dist/servers/railway/minimal.js +48 -3
  17. package/dist/servers/railway/minimal.js.map +2 -2
  18. package/dist/servers/railway/storage-test.js +455 -0
  19. package/dist/servers/railway/storage-test.js.map +7 -0
  20. package/dist/skills/claude-skills.js +13 -12
  21. package/dist/skills/claude-skills.js.map +2 -2
  22. package/dist/skills/recursive-agent-orchestrator.js +27 -18
  23. package/dist/skills/recursive-agent-orchestrator.js.map +2 -2
  24. package/dist/skills/unified-rlm-orchestrator.js.map +2 -2
  25. package/package.json +6 -18
  26. package/scripts/README-TESTING.md +186 -0
  27. package/scripts/analyze-cli-security.js +288 -0
  28. package/scripts/archive/add-phase-tasks-to-linear.js +163 -0
  29. package/scripts/archive/analyze-linear-duplicates.js +214 -0
  30. package/scripts/archive/analyze-remaining-duplicates.js +230 -0
  31. package/scripts/archive/analyze-sta-duplicates.js +292 -0
  32. package/scripts/archive/analyze-sta-graphql.js +399 -0
  33. package/scripts/archive/cancel-duplicate-tasks.ts +246 -0
  34. package/scripts/archive/check-all-duplicates.ts +419 -0
  35. package/scripts/archive/clean-duplicate-tasks.js +114 -0
  36. package/scripts/archive/cleanup-duplicate-tasks.ts +286 -0
  37. package/scripts/archive/create-phase-tasks.js +387 -0
  38. package/scripts/archive/delete-linear-duplicates.js +182 -0
  39. package/scripts/archive/delete-remaining-duplicates.js +158 -0
  40. package/scripts/archive/delete-sta-duplicates.js +201 -0
  41. package/scripts/archive/delete-sta-oauth.js +201 -0
  42. package/scripts/archive/export-sta-tasks.js +62 -0
  43. package/scripts/archive/install-auto-sync.js +266 -0
  44. package/scripts/archive/install-chromadb-hooks.sh +133 -0
  45. package/scripts/archive/install-enhanced-clear-hooks.sh +431 -0
  46. package/scripts/archive/install-post-task-hooks.sh +289 -0
  47. package/scripts/archive/install-stackmemory-hooks.sh +420 -0
  48. package/scripts/archive/merge-linear-duplicates-safe.ts +362 -0
  49. package/scripts/archive/merge-linear-duplicates.ts +180 -0
  50. package/scripts/archive/remove-sta-tasks.js +70 -0
  51. package/scripts/archive/setup-background-sync.sh +168 -0
  52. package/scripts/archive/setup-claude-auto-triggers.sh +181 -0
  53. package/scripts/archive/setup-claude-autostart.sh +305 -0
  54. package/scripts/archive/setup-git-hooks.sh +25 -0
  55. package/scripts/archive/setup-linear-oauth.sh +46 -0
  56. package/scripts/archive/setup-mcp.sh +113 -0
  57. package/scripts/archive/setup-railway-deployment.sh +81 -0
  58. package/scripts/auto-handoff.sh +262 -0
  59. package/scripts/background-sync-manager.js +416 -0
  60. package/scripts/benchmark-performance.ts +57 -0
  61. package/scripts/check-redis.ts +48 -0
  62. package/scripts/chromadb-auto-loader.sh +128 -0
  63. package/scripts/chromadb-context-loader.js +479 -0
  64. package/scripts/claude-chromadb-hook.js +460 -0
  65. package/scripts/claude-code-wrapper.sh +66 -0
  66. package/scripts/claude-linear-skill.js +455 -0
  67. package/scripts/claude-pre-commit.sh +302 -0
  68. package/scripts/claude-sm-autostart.js +532 -0
  69. package/scripts/claude-sm-setup.sh +367 -0
  70. package/scripts/claude-with-chromadb.sh +69 -0
  71. package/scripts/claude-worktree-manager.sh +323 -0
  72. package/scripts/claude-worktree-monitor.sh +371 -0
  73. package/scripts/claude-worktree-setup.sh +327 -0
  74. package/scripts/clean-linear-backlog.js +273 -0
  75. package/scripts/cleanup-old-sessions.sh +57 -0
  76. package/scripts/codex-wrapper.sh +88 -0
  77. package/scripts/create-sandbox.sh +269 -0
  78. package/scripts/debug-linear-update.js +174 -0
  79. package/scripts/delete-linear-tasks.js +167 -0
  80. package/scripts/deploy.sh +89 -0
  81. package/scripts/deployment/railway.sh +352 -0
  82. package/scripts/deployment/test-deployment.js +194 -0
  83. package/scripts/detect-and-rehydrate.js +162 -0
  84. package/scripts/detect-and-rehydrate.mjs +165 -0
  85. package/scripts/development/create-demo-tasks.js +143 -0
  86. package/scripts/development/debug-frame-test.js +16 -0
  87. package/scripts/development/demo-auto-sync.js +128 -0
  88. package/scripts/development/fix-all-imports.js +213 -0
  89. package/scripts/development/fix-imports.js +229 -0
  90. package/scripts/development/fix-lint-loop.cjs +103 -0
  91. package/scripts/development/fix-project-id.ts +161 -0
  92. package/scripts/development/fix-strict-mode-issues.ts +291 -0
  93. package/scripts/development/reorganize-structure.sh +228 -0
  94. package/scripts/development/test-persistence-direct.js +148 -0
  95. package/scripts/development/test-persistence.js +114 -0
  96. package/scripts/development/test-tasks.js +93 -0
  97. package/scripts/development/update-imports.js +212 -0
  98. package/scripts/fetch-linear-status.js +125 -0
  99. package/scripts/git-hooks/README.md +310 -0
  100. package/scripts/git-hooks/branch-context-manager.sh +342 -0
  101. package/scripts/git-hooks/post-checkout-stackmemory.sh +63 -0
  102. package/scripts/git-hooks/post-commit-stackmemory.sh +305 -0
  103. package/scripts/git-hooks/pre-commit-stackmemory.sh +275 -0
  104. package/scripts/hooks/cleanup-shell.sh +130 -0
  105. package/scripts/hooks/task-complete.sh +114 -0
  106. package/scripts/initialize.ts +129 -0
  107. package/scripts/install-claude-hooks-auto.js +104 -0
  108. package/scripts/install-claude-hooks.sh +133 -0
  109. package/scripts/install-global.sh +296 -0
  110. package/scripts/install.sh +235 -0
  111. package/scripts/linear-auto-sync.js +262 -0
  112. package/scripts/linear-auto-sync.sh +161 -0
  113. package/scripts/linear-sync-daemon.js +150 -0
  114. package/scripts/linear-task-review.js +237 -0
  115. package/scripts/list-linear-tasks.ts +178 -0
  116. package/scripts/mcp-proxy.js +66 -0
  117. package/scripts/opencode-wrapper.sh +85 -0
  118. package/scripts/publish-local.js +74 -0
  119. package/scripts/query-chromadb.ts +201 -0
  120. package/scripts/railway-env-setup.sh +39 -0
  121. package/scripts/reconcile-local-tasks.js +170 -0
  122. package/scripts/recreate-frames-db.js +89 -0
  123. package/scripts/setup/claude-integration.js +138 -0
  124. package/scripts/setup/configure-alias.js +125 -0
  125. package/scripts/setup/configure-codex-alias.js +161 -0
  126. package/scripts/setup/configure-opencode-alias.js +175 -0
  127. package/scripts/setup-claude-integration.js +204 -0
  128. package/scripts/setup-claude-integration.sh +183 -0
  129. package/scripts/setup.sh +31 -0
  130. package/scripts/show-linear-summary.ts +172 -0
  131. package/scripts/stackmemory-auto-handoff.sh +231 -0
  132. package/scripts/stackmemory-daemon.sh +40 -0
  133. package/scripts/start-linear-sync-daemon.sh +141 -0
  134. package/scripts/start-temporal-paradox.sh +214 -0
  135. package/scripts/status.ts +159 -0
  136. package/scripts/sync-and-clean-tasks.js +258 -0
  137. package/scripts/sync-frames-from-railway.js +228 -0
  138. package/scripts/sync-linear-graphql.js +303 -0
  139. package/scripts/sync-linear-tasks.js +186 -0
  140. package/scripts/test-auto-triggers.sh +57 -0
  141. package/scripts/test-browser-mcp.js +74 -0
  142. package/scripts/test-chromadb-full.js +115 -0
  143. package/scripts/test-chromadb-hooks.sh +28 -0
  144. package/scripts/test-chromadb-sync.ts +245 -0
  145. package/scripts/test-cli-security.js +293 -0
  146. package/scripts/test-hooks-persistence.sh +220 -0
  147. package/scripts/test-installation-scenarios.sh +359 -0
  148. package/scripts/test-installation.sh +224 -0
  149. package/scripts/test-mcp.js +163 -0
  150. package/scripts/test-pre-publish-quick.sh +75 -0
  151. package/scripts/test-quality-gates.sh +263 -0
  152. package/scripts/test-railway-db.js +222 -0
  153. package/scripts/test-redis-storage.ts +490 -0
  154. package/scripts/test-rlm-basic.sh +122 -0
  155. package/scripts/test-rlm-comprehensive.sh +260 -0
  156. package/scripts/test-rlm-e2e.sh +268 -0
  157. package/scripts/test-rlm-simple.js +90 -0
  158. package/scripts/test-rlm.js +110 -0
  159. package/scripts/test-session-handoff.sh +165 -0
  160. package/scripts/test-shell-integration.sh +275 -0
  161. package/scripts/testing/ab-test-runner.ts +508 -0
  162. package/scripts/testing/collect-metrics.ts +457 -0
  163. package/scripts/testing/quick-effectiveness-demo.js +187 -0
  164. package/scripts/testing/real-performance-test.js +422 -0
  165. package/scripts/testing/run-effectiveness-tests.sh +176 -0
  166. package/scripts/testing/scripts/testing/ab-test-runner.js +363 -0
  167. package/scripts/testing/scripts/testing/collect-metrics.js +292 -0
  168. package/scripts/testing/simple-effectiveness-test.js +310 -0
  169. package/scripts/testing/src/core/context/context-bridge.js +253 -0
  170. package/scripts/testing/src/core/context/frame-manager.js +746 -0
  171. package/scripts/testing/src/core/context/shared-context-layer.js +437 -0
  172. package/scripts/testing/src/core/database/database-adapter.js +54 -0
  173. package/scripts/testing/src/core/errors/index.js +291 -0
  174. package/scripts/testing/src/core/errors/recovery.js +268 -0
  175. package/scripts/testing/src/core/monitoring/logger.js +145 -0
  176. package/scripts/testing/src/core/retrieval/context-retriever.js +516 -0
  177. package/scripts/testing/src/core/session/index.js +1 -0
  178. package/scripts/testing/src/core/session/session-manager.js +323 -0
  179. package/scripts/testing/src/core/trace/cli-trace-wrapper.js +140 -0
  180. package/scripts/testing/src/core/trace/db-trace-wrapper.js +251 -0
  181. package/scripts/testing/src/core/trace/debug-trace.js +398 -0
  182. package/scripts/testing/src/core/trace/index.js +120 -0
  183. package/scripts/testing/src/core/trace/linear-api-wrapper.js +204 -0
  184. package/scripts/update-linear-status.js +268 -0
  185. package/scripts/update-linear-tasks-fixed.js +284 -0
  186. package/templates/claude-hooks/hooks.json +5 -0
  187. package/templates/claude-hooks/on-clear.js +56 -0
  188. package/templates/claude-hooks/on-startup.js +56 -0
  189. package/templates/claude-hooks/tool-use-trace.js +67 -0
  190. package/dist/features/tui/components/analytics-panel.js +0 -157
  191. package/dist/features/tui/components/analytics-panel.js.map +0 -7
  192. package/dist/features/tui/components/frame-visualizer.js +0 -377
  193. package/dist/features/tui/components/frame-visualizer.js.map +0 -7
  194. package/dist/features/tui/components/pr-tracker.js +0 -135
  195. package/dist/features/tui/components/pr-tracker.js.map +0 -7
  196. package/dist/features/tui/components/session-monitor.js +0 -299
  197. package/dist/features/tui/components/session-monitor.js.map +0 -7
  198. package/dist/features/tui/components/subagent-fleet.js +0 -395
  199. package/dist/features/tui/components/subagent-fleet.js.map +0 -7
  200. package/dist/features/tui/components/task-board.js +0 -1139
  201. package/dist/features/tui/components/task-board.js.map +0 -7
  202. package/dist/features/tui/index.js +0 -408
  203. package/dist/features/tui/index.js.map +0 -7
  204. package/dist/features/tui/services/data-service.js +0 -641
  205. package/dist/features/tui/services/data-service.js.map +0 -7
  206. package/dist/features/tui/services/linear-task-reader.js +0 -102
  207. package/dist/features/tui/services/linear-task-reader.js.map +0 -7
  208. package/dist/features/tui/services/websocket-client.js +0 -162
  209. package/dist/features/tui/services/websocket-client.js.map +0 -7
  210. package/dist/features/tui/terminal-compat.js +0 -220
  211. package/dist/features/tui/terminal-compat.js.map +0 -7
  212. package/dist/features/tui/types.js +0 -1
  213. package/dist/features/tui/types.js.map +0 -7
@@ -0,0 +1,367 @@
1
+ #!/bin/bash
2
+
3
+ # Claude-SM Setup and Integration Script
4
+ # Automatically configures Claude with StackMemory and worktree support
5
+
6
+ set -e
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
10
+ CLAUDE_CONFIG_DIR="${HOME}/.claude"
11
+ STACKMEMORY_BIN="${HOME}/.stackmemory/bin"
12
+
13
+ # Colors
14
+ GREEN='\033[0;32m'
15
+ BLUE='\033[0;34m'
16
+ YELLOW='\033[1;33m'
17
+ RED='\033[0;31m'
18
+ NC='\033[0m'
19
+
20
+ echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
21
+ echo -e "${BLUE}║ Claude-SM Setup & Integration ║${NC}"
22
+ echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
23
+ echo
24
+
25
+ # Check if StackMemory is installed
26
+ check_stackmemory() {
27
+ echo -e "${YELLOW}Checking StackMemory installation...${NC}"
28
+
29
+ if command -v stackmemory &> /dev/null; then
30
+ echo -e "${GREEN}✓ StackMemory found in PATH${NC}"
31
+ return 0
32
+ elif [[ -x "${STACKMEMORY_BIN}/stackmemory" ]]; then
33
+ echo -e "${GREEN}✓ StackMemory found at ${STACKMEMORY_BIN}${NC}"
34
+ return 0
35
+ else
36
+ echo -e "${RED}✗ StackMemory not found${NC}"
37
+ echo " Install with: npm install -g @stackmemoryai/stackmemory"
38
+ return 1
39
+ fi
40
+ }
41
+
42
+ # Install claude-sm command
43
+ install_claude_sm() {
44
+ echo -e "${YELLOW}Installing claude-sm wrapper...${NC}"
45
+
46
+ # Build TypeScript files
47
+ cd "$PROJECT_ROOT"
48
+ npm run build 2>/dev/null || npm run build:cli 2>/dev/null || true
49
+
50
+ # Make bin script executable
51
+ chmod +x "${PROJECT_ROOT}/bin/claude-sm"
52
+
53
+ # Create symlink in StackMemory bin directory
54
+ mkdir -p "$STACKMEMORY_BIN"
55
+ ln -sf "${PROJECT_ROOT}/bin/claude-sm" "${STACKMEMORY_BIN}/claude-sm"
56
+
57
+ # Also create in /usr/local/bin if we have permission
58
+ if [[ -w /usr/local/bin ]]; then
59
+ ln -sf "${PROJECT_ROOT}/bin/claude-sm" /usr/local/bin/claude-sm
60
+ echo -e "${GREEN}✓ Installed claude-sm to /usr/local/bin${NC}"
61
+ else
62
+ echo -e "${GREEN}✓ Installed claude-sm to ${STACKMEMORY_BIN}${NC}"
63
+ echo -e "${YELLOW} Add to PATH: export PATH=\"\$PATH:${STACKMEMORY_BIN}\"${NC}"
64
+ fi
65
+ }
66
+
67
+ # Setup shell aliases and functions
68
+ setup_shell_integration() {
69
+ echo -e "${YELLOW}Setting up shell integration...${NC}"
70
+
71
+ local shell_rc=""
72
+
73
+ # Detect shell
74
+ if [[ -n "$ZSH_VERSION" ]]; then
75
+ shell_rc="${HOME}/.zshrc"
76
+ elif [[ -n "$BASH_VERSION" ]]; then
77
+ shell_rc="${HOME}/.bashrc"
78
+ else
79
+ shell_rc="${HOME}/.profile"
80
+ fi
81
+
82
+ # Create integration script
83
+ cat > "${CLAUDE_CONFIG_DIR}/claude-sm-integration.sh" <<'EOF'
84
+ # Claude-SM Integration
85
+
86
+ # Wrapper function for Claude with automatic worktree detection
87
+ claude() {
88
+ local use_worktree=false
89
+ local use_auto=false
90
+
91
+ # Check if we should auto-detect worktree need
92
+ if [[ " $@ " =~ " --auto " ]] || [[ " $@ " =~ " -a " ]]; then
93
+ use_auto=true
94
+ fi
95
+
96
+ # Auto-detect conditions
97
+ if [[ "$use_auto" == "true" ]] && command -v git &>/dev/null; then
98
+ if git rev-parse --git-dir &>/dev/null 2>&1; then
99
+ # Check for uncommitted changes
100
+ if [[ -n $(git status --porcelain 2>/dev/null) ]]; then
101
+ echo "⚠️ Uncommitted changes detected - using worktree mode"
102
+ use_worktree=true
103
+ fi
104
+
105
+ # Check for other Claude instances
106
+ if [[ -d .claude-worktree-locks ]]; then
107
+ local active_locks=$(find .claude-worktree-locks -name "*.lock" -mtime -1 2>/dev/null | wc -l)
108
+ if [[ $active_locks -gt 0 ]]; then
109
+ echo "⚠️ Other Claude instances detected - using worktree mode"
110
+ use_worktree=true
111
+ fi
112
+ fi
113
+ fi
114
+ fi
115
+
116
+ # Use claude-sm wrapper if available, otherwise fall back to regular claude
117
+ if command -v claude-sm &>/dev/null; then
118
+ if [[ "$use_worktree" == "true" ]]; then
119
+ claude-sm --worktree "$@"
120
+ else
121
+ claude-sm "$@"
122
+ fi
123
+ else
124
+ command claude "$@"
125
+ fi
126
+ }
127
+
128
+ # Convenience aliases
129
+ alias cls='claude-sm' # Claude with StackMemory
130
+ alias clw='claude-sm --worktree' # Claude with worktree
131
+ alias cla='claude-sm --auto' # Claude with auto-detection
132
+ alias clws='claude-sm --worktree --sandbox' # Sandboxed worktree
133
+ alias clwc='claude-sm --worktree --chrome' # Chrome-enabled worktree
134
+
135
+ # Worktree management (if sourced)
136
+ if [[ -f "${HOME}/Dev/stackmemory/scripts/claude-worktree-manager.sh" ]]; then
137
+ source "${HOME}/Dev/stackmemory/scripts/claude-worktree-manager.sh"
138
+ fi
139
+
140
+ # Context shortcuts
141
+ smcw() {
142
+ # Save/load worktree context
143
+ local action="${1:-show}"
144
+ case "$action" in
145
+ save)
146
+ stackmemory context worktree save
147
+ ;;
148
+ load)
149
+ stackmemory context worktree load
150
+ ;;
151
+ list)
152
+ stackmemory context worktree list
153
+ ;;
154
+ *)
155
+ stackmemory context show
156
+ ;;
157
+ esac
158
+ }
159
+
160
+ # Quick worktree status
161
+ claude-status() {
162
+ echo "🤖 Claude Instance Status"
163
+ echo "========================="
164
+
165
+ # Check for active instances
166
+ if [[ -d .claude-worktree-locks ]]; then
167
+ local locks=$(ls -1 .claude-worktree-locks/*.lock 2>/dev/null | wc -l)
168
+ echo "Active instances: $locks"
169
+ else
170
+ echo "Active instances: 0"
171
+ fi
172
+
173
+ # Check git status
174
+ if git rev-parse --git-dir &>/dev/null 2>&1; then
175
+ local branch=$(git rev-parse --abbrev-ref HEAD)
176
+ local changes=$(git status --porcelain | wc -l)
177
+ echo "Current branch: $branch"
178
+ echo "Uncommitted changes: $changes"
179
+ fi
180
+
181
+ # Check worktrees
182
+ if command -v git &>/dev/null; then
183
+ local worktrees=$(git worktree list 2>/dev/null | grep -c "claude-" || echo "0")
184
+ echo "Claude worktrees: $worktrees"
185
+ fi
186
+
187
+ # Check StackMemory
188
+ if command -v stackmemory &>/dev/null; then
189
+ echo "StackMemory: ✓ Available"
190
+ stackmemory status 2>/dev/null | head -3 || true
191
+ else
192
+ echo "StackMemory: ✗ Not found"
193
+ fi
194
+ }
195
+
196
+ export -f claude
197
+ export -f smcw
198
+ export -f claude-status
199
+ EOF
200
+
201
+ # Add to shell RC if not already present
202
+ if ! grep -q "claude-sm-integration.sh" "$shell_rc" 2>/dev/null; then
203
+ echo "" >> "$shell_rc"
204
+ echo "# Claude-SM Integration" >> "$shell_rc"
205
+ echo "source ${CLAUDE_CONFIG_DIR}/claude-sm-integration.sh" >> "$shell_rc"
206
+ echo -e "${GREEN}✓ Added integration to ${shell_rc}${NC}"
207
+ else
208
+ echo -e "${GREEN}✓ Integration already in ${shell_rc}${NC}"
209
+ fi
210
+ }
211
+
212
+ # Setup Git hooks
213
+ setup_git_hooks() {
214
+ echo -e "${YELLOW}Setting up Git hooks...${NC}"
215
+
216
+ # Create global hooks directory
217
+ local hooks_dir="${CLAUDE_CONFIG_DIR}/git-hooks"
218
+ mkdir -p "$hooks_dir"
219
+
220
+ # Pre-commit hook to warn about Claude instances
221
+ cat > "${hooks_dir}/pre-commit" <<'EOF'
222
+ #!/bin/bash
223
+
224
+ # Check for active Claude worktrees
225
+ if [[ -d .claude-worktree-locks ]]; then
226
+ active_locks=$(find .claude-worktree-locks -name "*.lock" -mtime -1 2>/dev/null | wc -l)
227
+ if [[ $active_locks -gt 0 ]]; then
228
+ echo "⚠️ Warning: ${active_locks} active Claude instance(s) detected"
229
+ echo " Consider completing or closing them before committing"
230
+ echo " Run 'claude-status' for details"
231
+ fi
232
+ fi
233
+
234
+ # Check if in a Claude worktree
235
+ current_branch=$(git rev-parse --abbrev-ref HEAD)
236
+ if [[ "$current_branch" == claude-* ]]; then
237
+ echo "📝 Committing in Claude worktree: ${current_branch}"
238
+
239
+ # Auto-save context if StackMemory is available
240
+ if command -v stackmemory &>/dev/null; then
241
+ stackmemory context worktree save --branch "$current_branch" 2>/dev/null || true
242
+ fi
243
+ fi
244
+ EOF
245
+ chmod +x "${hooks_dir}/pre-commit"
246
+
247
+ # Post-checkout hook to load context
248
+ cat > "${hooks_dir}/post-checkout" <<'EOF'
249
+ #!/bin/bash
250
+
251
+ # Load context when switching to Claude worktree
252
+ new_branch=$(git rev-parse --abbrev-ref HEAD)
253
+ if [[ "$new_branch" == claude-* ]]; then
254
+ echo "🔄 Switched to Claude worktree: ${new_branch}"
255
+
256
+ # Load context if available
257
+ if command -v stackmemory &>/dev/null; then
258
+ stackmemory context worktree load --branch "$new_branch" 2>/dev/null || true
259
+ fi
260
+
261
+ # Show instance info
262
+ if [[ -f .claude-instance.json ]]; then
263
+ instance_id=$(grep '"instanceId"' .claude-instance.json | cut -d'"' -f4)
264
+ echo " Instance ID: ${instance_id}"
265
+ fi
266
+ fi
267
+ EOF
268
+ chmod +x "${hooks_dir}/post-checkout"
269
+
270
+ echo -e "${GREEN}✓ Git hooks created in ${hooks_dir}${NC}"
271
+ echo -e "${YELLOW} To use globally: git config --global core.hooksPath ${hooks_dir}${NC}"
272
+ }
273
+
274
+ # Create example configuration
275
+ create_example_config() {
276
+ echo -e "${YELLOW}Creating example configuration...${NC}"
277
+
278
+ cat > "${CLAUDE_CONFIG_DIR}/claude-sm.config.json" <<EOF
279
+ {
280
+ "defaults": {
281
+ "useWorktree": false,
282
+ "autoDetect": true,
283
+ "sandboxMode": false,
284
+ "chromeMode": false,
285
+ "contextEnabled": true
286
+ },
287
+ "worktree": {
288
+ "baseDir": "../",
289
+ "maxActive": 5,
290
+ "autoCleanupDays": 7
291
+ },
292
+ "monitor": {
293
+ "enabled": false,
294
+ "interval": 300
295
+ },
296
+ "aliases": {
297
+ "api": {
298
+ "task": "API development",
299
+ "flags": ["--worktree", "--sandbox"]
300
+ },
301
+ "ui": {
302
+ "task": "UI development",
303
+ "flags": ["--worktree", "--chrome"]
304
+ },
305
+ "debug": {
306
+ "task": "Debugging",
307
+ "flags": ["--worktree"]
308
+ }
309
+ }
310
+ }
311
+ EOF
312
+
313
+ echo -e "${GREEN}✓ Created config at ${CLAUDE_CONFIG_DIR}/claude-sm.config.json${NC}"
314
+ }
315
+
316
+ # Main setup flow
317
+ main() {
318
+ echo "Setting up Claude-SM integration..."
319
+ echo
320
+
321
+ # Create config directory
322
+ mkdir -p "$CLAUDE_CONFIG_DIR"
323
+
324
+ # Run setup steps
325
+ check_stackmemory || {
326
+ echo -e "${RED}StackMemory is required. Please install it first.${NC}"
327
+ exit 1
328
+ }
329
+
330
+ install_claude_sm
331
+ setup_shell_integration
332
+ setup_git_hooks
333
+ create_example_config
334
+
335
+ # Source worktree scripts
336
+ if [[ -f "${SCRIPT_DIR}/claude-worktree-manager.sh" ]]; then
337
+ chmod +x "${SCRIPT_DIR}/claude-worktree-manager.sh"
338
+ echo -e "${GREEN}✓ Worktree manager ready${NC}"
339
+ fi
340
+
341
+ if [[ -f "${SCRIPT_DIR}/claude-worktree-monitor.sh" ]]; then
342
+ chmod +x "${SCRIPT_DIR}/claude-worktree-monitor.sh"
343
+ echo -e "${GREEN}✓ Worktree monitor ready${NC}"
344
+ fi
345
+
346
+ echo
347
+ echo -e "${GREEN}═══════════════════════════════════════${NC}"
348
+ echo -e "${GREEN}✅ Claude-SM setup complete!${NC}"
349
+ echo -e "${GREEN}═══════════════════════════════════════${NC}"
350
+ echo
351
+ echo "Quick start commands:"
352
+ echo " claude-sm - Run Claude with StackMemory"
353
+ echo " claude-sm -w - Run Claude in isolated worktree"
354
+ echo " claude-sm -a - Auto-detect best mode"
355
+ echo " claude-status - Check instance status"
356
+ echo
357
+ echo "Aliases available (after sourcing shell):"
358
+ echo " cls - Claude with StackMemory"
359
+ echo " clw - Claude with worktree"
360
+ echo " cla - Claude with auto-detection"
361
+ echo
362
+ echo -e "${YELLOW}Reload your shell or run:${NC}"
363
+ echo " source ${CLAUDE_CONFIG_DIR}/claude-sm-integration.sh"
364
+ }
365
+
366
+ # Run main
367
+ main "$@"
@@ -0,0 +1,69 @@
1
+ #!/bin/bash
2
+
3
+ # Launch Claude with ChromaDB hooks enabled
4
+ PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
+
6
+ # Load environment
7
+ if [ -f "$PROJECT_ROOT/.env" ]; then
8
+ export $(grep -v '^#' "$PROJECT_ROOT/.env" | xargs)
9
+ fi
10
+
11
+ # Run startup hook to load context
12
+ echo "Loading context from ChromaDB..."
13
+ node "$PROJECT_ROOT/.claude/hooks/on-startup.js"
14
+
15
+ # Start adaptive periodic save in background
16
+ (
17
+ while true; do
18
+ # Check if Claude is active to determine interval
19
+ ACTIVITY_FILE="$HOME/.stackmemory/.claude-activity"
20
+ if [[ -f "$ACTIVITY_FILE" ]]; then
21
+ # Get last activity time
22
+ LAST_ACTIVITY=$(cat "$ACTIVITY_FILE" 2>/dev/null || echo "1970-01-01T00:00:00Z")
23
+ LAST_TIMESTAMP=$(date -j -f "%Y-%m-%dT%H:%M:%S" "${LAST_ACTIVITY%.*}" "+%s" 2>/dev/null || echo "0")
24
+ NOW=$(date "+%s")
25
+ TIME_DIFF=$((NOW - LAST_TIMESTAMP))
26
+
27
+ # Use 1 minute if active in last 10 minutes, 5 minutes otherwise
28
+ if [[ $TIME_DIFF -lt 600 ]]; then
29
+ SLEEP_TIME=60 # 1 minute for active sessions
30
+ else
31
+ SLEEP_TIME=300 # 5 minutes when idle
32
+ fi
33
+ else
34
+ SLEEP_TIME=300 # 5 minutes default
35
+ fi
36
+
37
+ sleep $SLEEP_TIME
38
+ node "$PROJECT_ROOT/.claude/hooks/periodic-save.js" 2>/dev/null
39
+ done
40
+ ) &
41
+ PERIODIC_PID=$!
42
+
43
+ # Cleanup function
44
+ cleanup() {
45
+ echo "Saving final context..."
46
+ node "$PROJECT_ROOT/.claude/hooks/chromadb-save-hook.js" << JSON
47
+ {
48
+ "event": "session_end",
49
+ "data": {
50
+ "summary": "Claude session ended",
51
+ "duration": "$SECONDS seconds"
52
+ }
53
+ }
54
+ JSON
55
+ kill $PERIODIC_PID 2>/dev/null
56
+ exit
57
+ }
58
+
59
+ trap cleanup EXIT INT TERM
60
+
61
+ echo "✨ Claude with ChromaDB hooks is ready!"
62
+ echo " - Context loaded from last 24 hours"
63
+ echo " - Periodic saves every 15 minutes"
64
+ echo " - Linear task updates enabled"
65
+ echo ""
66
+ echo "Press Ctrl+C to exit and save context"
67
+
68
+ # Keep running
69
+ wait