@stackmemoryai/stackmemory 0.3.17 → 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 (212) hide show
  1. package/dist/cli/commands/skills.js +15 -2
  2. package/dist/cli/commands/skills.js.map +2 -2
  3. package/dist/cli/index.js +113 -834
  4. package/dist/cli/index.js.map +3 -3
  5. package/dist/core/context/dual-stack-manager.js +1 -1
  6. package/dist/core/context/dual-stack-manager.js.map +1 -1
  7. package/dist/core/context/frame-manager.js +3 -0
  8. package/dist/core/context/frame-manager.js.map +2 -2
  9. package/dist/integrations/claude-code/subagent-client.js +106 -3
  10. package/dist/integrations/claude-code/subagent-client.js.map +2 -2
  11. package/dist/servers/railway/config.js +51 -0
  12. package/dist/servers/railway/config.js.map +7 -0
  13. package/dist/servers/railway/index-enhanced.js +156 -0
  14. package/dist/servers/railway/index-enhanced.js.map +7 -0
  15. package/dist/servers/railway/minimal.js +48 -3
  16. package/dist/servers/railway/minimal.js.map +2 -2
  17. package/dist/servers/railway/storage-test.js +455 -0
  18. package/dist/servers/railway/storage-test.js.map +7 -0
  19. package/dist/skills/claude-skills.js +13 -12
  20. package/dist/skills/claude-skills.js.map +2 -2
  21. package/dist/skills/recursive-agent-orchestrator.js +27 -18
  22. package/dist/skills/recursive-agent-orchestrator.js.map +2 -2
  23. package/dist/skills/unified-rlm-orchestrator.js.map +2 -2
  24. package/package.json +6 -18
  25. package/scripts/README-TESTING.md +186 -0
  26. package/scripts/analyze-cli-security.js +288 -0
  27. package/scripts/archive/add-phase-tasks-to-linear.js +163 -0
  28. package/scripts/archive/analyze-linear-duplicates.js +214 -0
  29. package/scripts/archive/analyze-remaining-duplicates.js +230 -0
  30. package/scripts/archive/analyze-sta-duplicates.js +292 -0
  31. package/scripts/archive/analyze-sta-graphql.js +399 -0
  32. package/scripts/archive/cancel-duplicate-tasks.ts +246 -0
  33. package/scripts/archive/check-all-duplicates.ts +419 -0
  34. package/scripts/archive/clean-duplicate-tasks.js +114 -0
  35. package/scripts/archive/cleanup-duplicate-tasks.ts +286 -0
  36. package/scripts/archive/create-phase-tasks.js +387 -0
  37. package/scripts/archive/delete-linear-duplicates.js +182 -0
  38. package/scripts/archive/delete-remaining-duplicates.js +158 -0
  39. package/scripts/archive/delete-sta-duplicates.js +201 -0
  40. package/scripts/archive/delete-sta-oauth.js +201 -0
  41. package/scripts/archive/export-sta-tasks.js +62 -0
  42. package/scripts/archive/install-auto-sync.js +266 -0
  43. package/scripts/archive/install-chromadb-hooks.sh +133 -0
  44. package/scripts/archive/install-enhanced-clear-hooks.sh +431 -0
  45. package/scripts/archive/install-post-task-hooks.sh +289 -0
  46. package/scripts/archive/install-stackmemory-hooks.sh +420 -0
  47. package/scripts/archive/merge-linear-duplicates-safe.ts +362 -0
  48. package/scripts/archive/merge-linear-duplicates.ts +180 -0
  49. package/scripts/archive/remove-sta-tasks.js +70 -0
  50. package/scripts/archive/setup-background-sync.sh +168 -0
  51. package/scripts/archive/setup-claude-auto-triggers.sh +181 -0
  52. package/scripts/archive/setup-claude-autostart.sh +305 -0
  53. package/scripts/archive/setup-git-hooks.sh +25 -0
  54. package/scripts/archive/setup-linear-oauth.sh +46 -0
  55. package/scripts/archive/setup-mcp.sh +113 -0
  56. package/scripts/archive/setup-railway-deployment.sh +81 -0
  57. package/scripts/auto-handoff.sh +262 -0
  58. package/scripts/background-sync-manager.js +416 -0
  59. package/scripts/benchmark-performance.ts +57 -0
  60. package/scripts/check-redis.ts +48 -0
  61. package/scripts/chromadb-auto-loader.sh +128 -0
  62. package/scripts/chromadb-context-loader.js +479 -0
  63. package/scripts/claude-chromadb-hook.js +460 -0
  64. package/scripts/claude-code-wrapper.sh +66 -0
  65. package/scripts/claude-linear-skill.js +455 -0
  66. package/scripts/claude-pre-commit.sh +302 -0
  67. package/scripts/claude-sm-autostart.js +532 -0
  68. package/scripts/claude-sm-setup.sh +367 -0
  69. package/scripts/claude-with-chromadb.sh +69 -0
  70. package/scripts/claude-worktree-manager.sh +323 -0
  71. package/scripts/claude-worktree-monitor.sh +371 -0
  72. package/scripts/claude-worktree-setup.sh +327 -0
  73. package/scripts/clean-linear-backlog.js +273 -0
  74. package/scripts/cleanup-old-sessions.sh +57 -0
  75. package/scripts/codex-wrapper.sh +88 -0
  76. package/scripts/create-sandbox.sh +269 -0
  77. package/scripts/debug-linear-update.js +174 -0
  78. package/scripts/delete-linear-tasks.js +167 -0
  79. package/scripts/deploy.sh +89 -0
  80. package/scripts/deployment/railway.sh +352 -0
  81. package/scripts/deployment/test-deployment.js +194 -0
  82. package/scripts/detect-and-rehydrate.js +162 -0
  83. package/scripts/detect-and-rehydrate.mjs +165 -0
  84. package/scripts/development/create-demo-tasks.js +143 -0
  85. package/scripts/development/debug-frame-test.js +16 -0
  86. package/scripts/development/demo-auto-sync.js +128 -0
  87. package/scripts/development/fix-all-imports.js +213 -0
  88. package/scripts/development/fix-imports.js +229 -0
  89. package/scripts/development/fix-lint-loop.cjs +103 -0
  90. package/scripts/development/fix-project-id.ts +161 -0
  91. package/scripts/development/fix-strict-mode-issues.ts +291 -0
  92. package/scripts/development/reorganize-structure.sh +228 -0
  93. package/scripts/development/test-persistence-direct.js +148 -0
  94. package/scripts/development/test-persistence.js +114 -0
  95. package/scripts/development/test-tasks.js +93 -0
  96. package/scripts/development/update-imports.js +212 -0
  97. package/scripts/fetch-linear-status.js +125 -0
  98. package/scripts/git-hooks/README.md +310 -0
  99. package/scripts/git-hooks/branch-context-manager.sh +342 -0
  100. package/scripts/git-hooks/post-checkout-stackmemory.sh +63 -0
  101. package/scripts/git-hooks/post-commit-stackmemory.sh +305 -0
  102. package/scripts/git-hooks/pre-commit-stackmemory.sh +275 -0
  103. package/scripts/hooks/cleanup-shell.sh +130 -0
  104. package/scripts/hooks/task-complete.sh +114 -0
  105. package/scripts/initialize.ts +129 -0
  106. package/scripts/install-claude-hooks-auto.js +104 -0
  107. package/scripts/install-claude-hooks.sh +133 -0
  108. package/scripts/install-global.sh +296 -0
  109. package/scripts/install.sh +235 -0
  110. package/scripts/linear-auto-sync.js +262 -0
  111. package/scripts/linear-auto-sync.sh +161 -0
  112. package/scripts/linear-sync-daemon.js +150 -0
  113. package/scripts/linear-task-review.js +237 -0
  114. package/scripts/list-linear-tasks.ts +178 -0
  115. package/scripts/mcp-proxy.js +66 -0
  116. package/scripts/opencode-wrapper.sh +85 -0
  117. package/scripts/publish-local.js +74 -0
  118. package/scripts/query-chromadb.ts +201 -0
  119. package/scripts/railway-env-setup.sh +39 -0
  120. package/scripts/reconcile-local-tasks.js +170 -0
  121. package/scripts/recreate-frames-db.js +89 -0
  122. package/scripts/setup/claude-integration.js +138 -0
  123. package/scripts/setup/configure-alias.js +125 -0
  124. package/scripts/setup/configure-codex-alias.js +161 -0
  125. package/scripts/setup/configure-opencode-alias.js +175 -0
  126. package/scripts/setup-claude-integration.js +204 -0
  127. package/scripts/setup-claude-integration.sh +183 -0
  128. package/scripts/setup.sh +31 -0
  129. package/scripts/show-linear-summary.ts +172 -0
  130. package/scripts/stackmemory-auto-handoff.sh +231 -0
  131. package/scripts/stackmemory-daemon.sh +40 -0
  132. package/scripts/start-linear-sync-daemon.sh +141 -0
  133. package/scripts/start-temporal-paradox.sh +214 -0
  134. package/scripts/status.ts +159 -0
  135. package/scripts/sync-and-clean-tasks.js +258 -0
  136. package/scripts/sync-frames-from-railway.js +228 -0
  137. package/scripts/sync-linear-graphql.js +303 -0
  138. package/scripts/sync-linear-tasks.js +186 -0
  139. package/scripts/test-auto-triggers.sh +57 -0
  140. package/scripts/test-browser-mcp.js +74 -0
  141. package/scripts/test-chromadb-full.js +115 -0
  142. package/scripts/test-chromadb-hooks.sh +28 -0
  143. package/scripts/test-chromadb-sync.ts +245 -0
  144. package/scripts/test-cli-security.js +293 -0
  145. package/scripts/test-hooks-persistence.sh +220 -0
  146. package/scripts/test-installation-scenarios.sh +359 -0
  147. package/scripts/test-installation.sh +224 -0
  148. package/scripts/test-mcp.js +163 -0
  149. package/scripts/test-pre-publish-quick.sh +75 -0
  150. package/scripts/test-quality-gates.sh +263 -0
  151. package/scripts/test-railway-db.js +222 -0
  152. package/scripts/test-redis-storage.ts +490 -0
  153. package/scripts/test-rlm-basic.sh +122 -0
  154. package/scripts/test-rlm-comprehensive.sh +260 -0
  155. package/scripts/test-rlm-e2e.sh +268 -0
  156. package/scripts/test-rlm-simple.js +90 -0
  157. package/scripts/test-rlm.js +110 -0
  158. package/scripts/test-session-handoff.sh +165 -0
  159. package/scripts/test-shell-integration.sh +275 -0
  160. package/scripts/testing/ab-test-runner.ts +508 -0
  161. package/scripts/testing/collect-metrics.ts +457 -0
  162. package/scripts/testing/quick-effectiveness-demo.js +187 -0
  163. package/scripts/testing/real-performance-test.js +422 -0
  164. package/scripts/testing/run-effectiveness-tests.sh +176 -0
  165. package/scripts/testing/scripts/testing/ab-test-runner.js +363 -0
  166. package/scripts/testing/scripts/testing/collect-metrics.js +292 -0
  167. package/scripts/testing/simple-effectiveness-test.js +310 -0
  168. package/scripts/testing/src/core/context/context-bridge.js +253 -0
  169. package/scripts/testing/src/core/context/frame-manager.js +746 -0
  170. package/scripts/testing/src/core/context/shared-context-layer.js +437 -0
  171. package/scripts/testing/src/core/database/database-adapter.js +54 -0
  172. package/scripts/testing/src/core/errors/index.js +291 -0
  173. package/scripts/testing/src/core/errors/recovery.js +268 -0
  174. package/scripts/testing/src/core/monitoring/logger.js +145 -0
  175. package/scripts/testing/src/core/retrieval/context-retriever.js +516 -0
  176. package/scripts/testing/src/core/session/index.js +1 -0
  177. package/scripts/testing/src/core/session/session-manager.js +323 -0
  178. package/scripts/testing/src/core/trace/cli-trace-wrapper.js +140 -0
  179. package/scripts/testing/src/core/trace/db-trace-wrapper.js +251 -0
  180. package/scripts/testing/src/core/trace/debug-trace.js +398 -0
  181. package/scripts/testing/src/core/trace/index.js +120 -0
  182. package/scripts/testing/src/core/trace/linear-api-wrapper.js +204 -0
  183. package/scripts/update-linear-status.js +268 -0
  184. package/scripts/update-linear-tasks-fixed.js +284 -0
  185. package/templates/claude-hooks/hooks.json +5 -0
  186. package/templates/claude-hooks/on-clear.js +56 -0
  187. package/templates/claude-hooks/on-startup.js +56 -0
  188. package/templates/claude-hooks/tool-use-trace.js +67 -0
  189. package/dist/features/tui/components/analytics-panel.js +0 -157
  190. package/dist/features/tui/components/analytics-panel.js.map +0 -7
  191. package/dist/features/tui/components/frame-visualizer.js +0 -377
  192. package/dist/features/tui/components/frame-visualizer.js.map +0 -7
  193. package/dist/features/tui/components/pr-tracker.js +0 -135
  194. package/dist/features/tui/components/pr-tracker.js.map +0 -7
  195. package/dist/features/tui/components/session-monitor.js +0 -299
  196. package/dist/features/tui/components/session-monitor.js.map +0 -7
  197. package/dist/features/tui/components/subagent-fleet.js +0 -395
  198. package/dist/features/tui/components/subagent-fleet.js.map +0 -7
  199. package/dist/features/tui/components/task-board.js +0 -1139
  200. package/dist/features/tui/components/task-board.js.map +0 -7
  201. package/dist/features/tui/index.js +0 -408
  202. package/dist/features/tui/index.js.map +0 -7
  203. package/dist/features/tui/services/data-service.js +0 -641
  204. package/dist/features/tui/services/data-service.js.map +0 -7
  205. package/dist/features/tui/services/linear-task-reader.js +0 -102
  206. package/dist/features/tui/services/linear-task-reader.js.map +0 -7
  207. package/dist/features/tui/services/websocket-client.js +0 -162
  208. package/dist/features/tui/services/websocket-client.js.map +0 -7
  209. package/dist/features/tui/terminal-compat.js +0 -220
  210. package/dist/features/tui/terminal-compat.js.map +0 -7
  211. package/dist/features/tui/types.js +0 -1
  212. package/dist/features/tui/types.js.map +0 -7
@@ -0,0 +1,310 @@
1
+ # StackMemory Git Hooks
2
+
3
+ Automated git workflow integration that syncs tasks, validates code, and maintains project context across branches.
4
+
5
+ ## 🚀 Quick Start
6
+
7
+ ```bash
8
+ # Install all hooks
9
+ ./scripts/install-stackmemory-hooks.sh
10
+
11
+ # Check status
12
+ ./scripts/install-stackmemory-hooks.sh status
13
+
14
+ # Selective installation
15
+ ./scripts/install-stackmemory-hooks.sh --selective
16
+ ```
17
+
18
+ ## 📋 Available Hooks
19
+
20
+ ### Pre-Commit Hook
21
+ **File**: `pre-commit-stackmemory.sh`
22
+
23
+ **What it does**:
24
+ - ✅ Validates task states and warns about blocked tasks
25
+ - ✅ Runs lint checks (npm/cargo)
26
+ - ✅ Performs type checking (TypeScript/Python/Rust)
27
+ - ✅ Saves StackMemory context before commit
28
+ - âš ī¸ Optionally runs critical tests
29
+
30
+ **Configuration**:
31
+ ```bash
32
+ # In the hook file, modify these variables:
33
+ VALIDATE_TASKS=true # Check task states
34
+ VALIDATE_LINT=true # Run linting
35
+ VALIDATE_TYPES=true # Run type checking
36
+ VALIDATE_TESTS_CRITICAL=false # Run critical tests
37
+ AUTO_UPDATE_TASKS=true # Auto-update task progress
38
+ ```
39
+
40
+ ### Post-Commit Hook
41
+ **File**: `post-commit-stackmemory.sh`
42
+
43
+ **What it does**:
44
+ - 📝 Parses commit messages for task completion indicators
45
+ - ✅ Auto-updates task status based on commit content
46
+ - đŸŽ¯ Creates completion frames for significant commits
47
+ - 📊 Records commit metrics in StackMemory
48
+ - 🔄 Syncs with Linear when configured
49
+
50
+ **Configuration**:
51
+ ```bash
52
+ AUTO_UPDATE_TASKS=true # Auto-update based on commits
53
+ SYNC_LINEAR=true # Sync with Linear issues
54
+ PARSE_COMMIT_MESSAGES=true # Parse commit messages
55
+ UPDATE_TASK_PROGRESS=true # Update task progress
56
+ CREATE_COMPLETION_FRAMES=true # Create completion frames
57
+ ```
58
+
59
+ ### Post-Checkout Hook (Branch Context)
60
+ **File**: `post-checkout-stackmemory.sh`
61
+
62
+ **What it does**:
63
+ - đŸŒŋ Detects branch switches
64
+ - 💾 Saves context when leaving a branch
65
+ - 📂 Loads context when entering a branch
66
+ - đŸˇī¸ Provides branch-specific guidance
67
+ - 🔍 Filters tasks by branch prefix
68
+
69
+ **Configuration**:
70
+ ```bash
71
+ BRANCH_ISOLATION_ENABLED=true # Enable branch isolation
72
+ AUTO_SWITCH_CONTEXT=true # Auto-load branch context
73
+ PRESERVE_CONTEXT=true # Save context on branch switch
74
+ BRANCH_PREFIX_FILTERING=true # Filter tasks by branch name
75
+ ```
76
+
77
+ ## đŸŽ¯ Workflow Examples
78
+
79
+ ### Feature Development
80
+ ```bash
81
+ # 1. Create feature branch
82
+ git checkout -b feature/STA-123-user-auth
83
+ # → Hook creates initial context frame
84
+ # → Shows feature development guidance
85
+
86
+ # 2. Start working
87
+ stackmemory task add "Implement user authentication" --priority high
88
+ stackmemory start_frame --name "User auth implementation"
89
+
90
+ # 3. Make commits
91
+ git add .
92
+ git commit -m "feat: implement JWT authentication"
93
+ # → Hook parses commit for completion indicators
94
+ # → Auto-updates task progress
95
+ # → Creates completion frame
96
+
97
+ # 4. Switch branches
98
+ git checkout main
99
+ # → Hook saves feature branch context
100
+ # → Loads main branch context
101
+ ```
102
+
103
+ ### Bug Fix Workflow
104
+ ```bash
105
+ # 1. Create bugfix branch
106
+ git checkout -b bugfix/fix-login-issue
107
+ # → Hook detects bugfix branch type
108
+ # → Suggests creating high-priority bug task
109
+
110
+ # 2. Work on fix
111
+ stackmemory task add "Fix login validation bug" --priority critical
112
+ git add .
113
+ git commit -m "fix: resolve login validation for empty emails"
114
+ # → Hook detects "fix" keyword
115
+ # → Marks related tasks as completed
116
+ # → Syncs with Linear if configured
117
+ ```
118
+
119
+ ## âš™ī¸ Configuration Options
120
+
121
+ ### Environment Variables
122
+ ```bash
123
+ # Disable specific hook features
124
+ export STACKMEMORY_HOOKS_DISABLED=true # Disable all hooks
125
+ export STACKMEMORY_NO_LINEAR_SYNC=true # Disable Linear sync
126
+ export STACKMEMORY_NO_AUTO_TASKS=true # Disable auto task updates
127
+
128
+ # Hook-specific settings
129
+ export STACKMEMORY_LINT_DISABLED=true # Skip lint checks
130
+ export STACKMEMORY_TYPE_CHECK_DISABLED=true # Skip type checking
131
+ ```
132
+
133
+ ### Project-Specific Configuration
134
+ Create `.stackmemory/hooks.config` in your project:
135
+ ```json
136
+ {
137
+ "enabled": true,
138
+ "preCommit": {
139
+ "validateTasks": true,
140
+ "validateLint": true,
141
+ "validateTypes": true,
142
+ "runCriticalTests": false
143
+ },
144
+ "postCommit": {
145
+ "autoUpdateTasks": true,
146
+ "syncLinear": true,
147
+ "createCompletionFrames": true
148
+ },
149
+ "branchContext": {
150
+ "isolationEnabled": true,
151
+ "autoSwitchContext": true,
152
+ "preserveContext": true
153
+ },
154
+ "commitParsing": {
155
+ "completionKeywords": ["complete", "done", "finish", "resolve"],
156
+ "taskIdPatterns": ["STA-\\d+", "TASK-\\d+", "tsk-[a-zA-Z0-9]+"]
157
+ }
158
+ }
159
+ ```
160
+
161
+ ## 🔧 Troubleshooting
162
+
163
+ ### Common Issues
164
+
165
+ **Hook not executing**:
166
+ ```bash
167
+ # Check if hooks are executable
168
+ ls -la .git/hooks/pre-commit
169
+ chmod +x .git/hooks/pre-commit
170
+
171
+ # Check hook status
172
+ ./scripts/install-stackmemory-hooks.sh status
173
+ ```
174
+
175
+ **StackMemory not found**:
176
+ ```bash
177
+ # Install StackMemory CLI
178
+ npm install -g @stackmemoryai/stackmemory
179
+
180
+ # Initialize in project
181
+ stackmemory init
182
+ ```
183
+
184
+ **Linear sync failing**:
185
+ ```bash
186
+ # Check Linear auth
187
+ stackmemory linear status
188
+
189
+ # Setup Linear if needed
190
+ stackmemory linear setup
191
+ ```
192
+
193
+ **Lint/type check failures**:
194
+ ```bash
195
+ # Check if tools are installed
196
+ npm run lint # or cargo clippy
197
+ npm run typecheck # or tsc --noEmit
198
+
199
+ # Disable in hook if not needed
200
+ # Edit hook file and set VALIDATE_LINT=false
201
+ ```
202
+
203
+ ### Debug Mode
204
+ Enable debug output in hooks:
205
+ ```bash
206
+ # Add to top of hook files
207
+ set -x # Enable debug output
208
+ ```
209
+
210
+ ### Skip Hooks Temporarily
211
+ ```bash
212
+ # Skip all hooks for one commit
213
+ git commit -m "message" --no-verify
214
+
215
+ # Skip specific hook checks
216
+ STACKMEMORY_LINT_DISABLED=true git commit -m "message"
217
+ ```
218
+
219
+ ## 📊 Integration Details
220
+
221
+ ### Commit Message Parsing
222
+ The hooks automatically detect these patterns:
223
+
224
+ **Task Completion**:
225
+ - `complete`, `done`, `finish`, `resolve`, `close`
226
+ - Example: `"feat: complete user authentication module"`
227
+
228
+ **Task Types**:
229
+ - `feat`/`feature` → Feature development
230
+ - `fix`/`bugfix` → Bug fixing
231
+ - `refactor` → Code refactoring
232
+ - `test` → Testing work
233
+
234
+ **Task IDs**:
235
+ - `STA-123` → Linear issue reference
236
+ - `tsk-abc123` → StackMemory task ID
237
+ - `#123` → Generic issue reference
238
+
239
+ ### Linear Integration
240
+ When Linear is configured:
241
+ - Commit references to `STA-123` automatically update Linear issues
242
+ - Task completion syncs status changes
243
+ - Comments are added to Linear issues with commit details
244
+
245
+ ### Branch Context Isolation
246
+ - Each branch maintains separate task context
247
+ - Context is automatically saved/restored on branch switches
248
+ - Branch naming conventions trigger specific workflows:
249
+ - `feature/` → Feature development guidance
250
+ - `bugfix/` → Bug fix workflow
251
+ - `hotfix/` → Critical fix workflow
252
+
253
+ ## đŸŽ›ī¸ Customization
254
+
255
+ ### Adding Custom Validation
256
+ Edit `pre-commit-stackmemory.sh` and add custom functions:
257
+
258
+ ```bash
259
+ # Add custom validation
260
+ validate_custom_rules() {
261
+ log_info "Running custom validation..."
262
+
263
+ # Your custom validation here
264
+ if ! my_custom_check; then
265
+ log_error "Custom validation failed"
266
+ return 1
267
+ fi
268
+
269
+ return 0
270
+ }
271
+
272
+ # Add to main execution pipeline
273
+ if ! validate_custom_rules; then
274
+ failed=true
275
+ fi
276
+ ```
277
+
278
+ ### Custom Commit Parsing
279
+ Edit `post-commit-stackmemory.sh` to add custom commit message parsing:
280
+
281
+ ```bash
282
+ parse_commit_message() {
283
+ local commit_msg="$1"
284
+
285
+ # Add your custom patterns
286
+ if echo "$commit_msg" | grep -iE "deploy|release"; then
287
+ task_actions="${task_actions}deployment,"
288
+ fi
289
+
290
+ # Continue with existing logic...
291
+ }
292
+ ```
293
+
294
+ ## 🔄 Updating Hooks
295
+
296
+ ```bash
297
+ # Reinstall hooks (preserves configuration)
298
+ ./scripts/install-stackmemory-hooks.sh --force
299
+
300
+ # Update specific hook
301
+ cp scripts/git-hooks/pre-commit-stackmemory.sh .git/hooks/pre-commit
302
+ chmod +x .git/hooks/pre-commit
303
+ ```
304
+
305
+ ## 📚 Related Documentation
306
+
307
+ - [StackMemory CLI Reference](../CLI.md)
308
+ - [Linear Integration Guide](../LINEAR.md)
309
+ - [Task Management Workflows](../TASKS.md)
310
+ - [Git Workflow Best Practices](../GIT_WORKFLOW.md)
@@ -0,0 +1,342 @@
1
+ #!/bin/bash
2
+ # StackMemory Branch Context Manager
3
+ # Manages task isolation and context switching between branches
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
+ log_info() {
15
+ echo -e "${BLUE}â„šī¸ $1${NC}"
16
+ }
17
+
18
+ log_success() {
19
+ echo -e "${GREEN}✅ $1${NC}"
20
+ }
21
+
22
+ log_warning() {
23
+ echo -e "${YELLOW}âš ī¸ $1${NC}"
24
+ }
25
+
26
+ log_error() {
27
+ echo -e "${RED}❌ $1${NC}"
28
+ }
29
+
30
+ # Configuration
31
+ BRANCH_ISOLATION_ENABLED=true
32
+ AUTO_SWITCH_CONTEXT=true
33
+ PRESERVE_CONTEXT=true
34
+ BRANCH_PREFIX_FILTERING=true
35
+
36
+ # Get current branch
37
+ get_current_branch() {
38
+ git branch --show-current 2>/dev/null || echo "HEAD"
39
+ }
40
+
41
+ # Get previous branch from reflog
42
+ get_previous_branch() {
43
+ git reflog --no-merges -1 --format='%gd %gs' | grep 'checkout:' | sed 's/.*checkout: moving from \([^ ]*\) to.*/\1/' || echo ""
44
+ }
45
+
46
+ # Check if StackMemory is available
47
+ check_stackmemory() {
48
+ if ! command -v stackmemory >/dev/null 2>&1; then
49
+ log_warning "StackMemory CLI not found"
50
+ return 1
51
+ fi
52
+
53
+ if [ ! -d ".stackmemory" ]; then
54
+ log_warning "StackMemory not initialized"
55
+ return 1
56
+ fi
57
+
58
+ return 0
59
+ }
60
+
61
+ # Save branch context before switching
62
+ save_branch_context() {
63
+ local branch="$1"
64
+
65
+ if ! check_stackmemory; then
66
+ return 0
67
+ fi
68
+
69
+ log_info "Saving context for branch: $branch"
70
+
71
+ # Create branch-specific context backup
72
+ local branch_context_dir=".stackmemory/branches"
73
+ mkdir -p "$branch_context_dir"
74
+
75
+ local context_file="$branch_context_dir/${branch//\//_}.json"
76
+
77
+ # Save current state
78
+ local branch_context=$(cat << EOF
79
+ {
80
+ "branch": "$branch",
81
+ "timestamp": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
82
+ "active_tasks": [],
83
+ "context_frames": [],
84
+ "last_commit": "$(git rev-parse HEAD 2>/dev/null || echo 'none')",
85
+ "working_directory_clean": $(git diff-index --quiet HEAD 2>/dev/null && echo 'true' || echo 'false')
86
+ }
87
+ EOF
88
+ )
89
+
90
+ # Get active tasks and add to context
91
+ if stackmemory tasks list --status in-progress >/dev/null 2>&1; then
92
+ local active_tasks=$(stackmemory tasks list --status in-progress 2>/dev/null | grep -oE "tsk-[a-zA-Z0-9]+" || echo "")
93
+
94
+ if [ -n "$active_tasks" ]; then
95
+ log_info "Found $(echo "$active_tasks" | wc -w | tr -d ' ') active tasks on branch $branch"
96
+
97
+ # Save task details
98
+ for task_id in $active_tasks; do
99
+ local task_info=$(stackmemory task show "$task_id" 2>/dev/null || echo "")
100
+ if [ -n "$task_info" ]; then
101
+ echo "$task_info" > "$branch_context_dir/${branch//\//_}_${task_id}.task"
102
+ fi
103
+ done
104
+ fi
105
+ fi
106
+
107
+ # Get current context frames
108
+ if stackmemory context show >/dev/null 2>&1; then
109
+ local context_frames=$(stackmemory context show 2>/dev/null || echo "")
110
+ if [ -n "$context_frames" ]; then
111
+ echo "$context_frames" > "$branch_context_dir/${branch//\//_}.context"
112
+ fi
113
+ fi
114
+
115
+ # Save the context summary
116
+ echo "$branch_context" > "$context_file"
117
+
118
+ log_success "Context saved for branch: $branch"
119
+ return 0
120
+ }
121
+
122
+ # Load branch context after switching
123
+ load_branch_context() {
124
+ local branch="$1"
125
+
126
+ if ! check_stackmemory; then
127
+ return 0
128
+ fi
129
+
130
+ log_info "Loading context for branch: $branch"
131
+
132
+ local branch_context_dir=".stackmemory/branches"
133
+ local context_file="$branch_context_dir/${branch//\//_}.json"
134
+
135
+ # Check if context exists for this branch
136
+ if [ ! -f "$context_file" ]; then
137
+ log_info "No saved context for branch: $branch (this is normal for new branches)"
138
+
139
+ # Initialize new branch context
140
+ initialize_branch_context "$branch"
141
+ return 0
142
+ fi
143
+
144
+ # Load previous context
145
+ log_info "Restoring context from previous work on branch: $branch"
146
+
147
+ # Restore context frames if available
148
+ local context_frames_file="$branch_context_dir/${branch//\//_}.context"
149
+ if [ -f "$context_frames_file" ]; then
150
+ local saved_context=$(cat "$context_frames_file")
151
+ if [ -n "$saved_context" ]; then
152
+ log_info "Previous context frames available"
153
+ # Note: We don't automatically restore frames to avoid conflicts
154
+ # Users can manually check with: cat .stackmemory/branches/$(current_branch).context
155
+ fi
156
+ fi
157
+
158
+ # Show active tasks from this branch
159
+ local task_files=("$branch_context_dir/${branch//\//_}_tsk-"*.task)
160
+ if [ -f "${task_files[0]}" ]; then
161
+ local task_count=$(ls -1 "$branch_context_dir/${branch//\//_}_tsk-"*.task 2>/dev/null | wc -l | tr -d ' ')
162
+ log_info "Found $task_count saved tasks from previous work on this branch"
163
+
164
+ # Optionally reactivate tasks
165
+ log_info "To reactivate tasks, run: stackmemory tasks list --all | grep 'your-task'"
166
+ fi
167
+
168
+ log_success "Context loaded for branch: $branch"
169
+ return 0
170
+ }
171
+
172
+ # Initialize context for new branch
173
+ initialize_branch_context() {
174
+ local branch="$1"
175
+
176
+ log_info "Initializing new branch context: $branch"
177
+
178
+ # Determine branch type and purpose from name
179
+ local branch_type="feature"
180
+ local suggested_tasks=""
181
+
182
+ # Parse branch name for context
183
+ if echo "$branch" | grep -qE "^(feature|feat)/"; then
184
+ branch_type="feature"
185
+ suggested_tasks="Consider creating a feature task for this branch"
186
+ elif echo "$branch" | grep -qE "^(bugfix|fix)/"; then
187
+ branch_type="bugfix"
188
+ suggested_tasks="Consider creating a bug fix task for this branch"
189
+ elif echo "$branch" | grep -qE "^(hotfix)/"; then
190
+ branch_type="hotfix"
191
+ suggested_tasks="Consider creating a hotfix task with high priority"
192
+ elif echo "$branch" | grep -qE "^(refactor)/"; then
193
+ branch_type="refactor"
194
+ suggested_tasks="Consider creating a refactoring task for this branch"
195
+ elif echo "$branch" | grep -qE "^(test|testing)/"; then
196
+ branch_type="test"
197
+ suggested_tasks="Consider creating a testing task for this branch"
198
+ fi
199
+
200
+ # Create initial context frame for the branch
201
+ local frame_name="Branch: $branch"
202
+ if stackmemory start_frame --name "$frame_name" --type task >/dev/null 2>&1; then
203
+ log_success "Created initial frame for branch: $branch"
204
+
205
+ # Add branch information as anchors
206
+ stackmemory add_anchor --type FACT --text "Working on branch: $branch" >/dev/null 2>&1
207
+ stackmemory add_anchor --type FACT --text "Branch type: $branch_type" >/dev/null 2>&1
208
+
209
+ if [ -n "$suggested_tasks" ]; then
210
+ stackmemory add_anchor --type TODO --text "$suggested_tasks" >/dev/null 2>&1
211
+ fi
212
+
213
+ log_info "Branch context initialized with type: $branch_type"
214
+ fi
215
+
216
+ return 0
217
+ }
218
+
219
+ # Handle branch switching
220
+ handle_branch_switch() {
221
+ local previous_branch="$1"
222
+ local current_branch="$2"
223
+
224
+ log_info "Branch switch detected: $previous_branch → $current_branch"
225
+
226
+ # Save context from previous branch
227
+ if [ -n "$previous_branch" ] && [ "$previous_branch" != "HEAD" ] && [ "$PRESERVE_CONTEXT" = "true" ]; then
228
+ save_branch_context "$previous_branch"
229
+ fi
230
+
231
+ # Load context for current branch
232
+ if [ "$AUTO_SWITCH_CONTEXT" = "true" ]; then
233
+ load_branch_context "$current_branch"
234
+ fi
235
+
236
+ # Show branch-specific guidance
237
+ provide_branch_guidance "$current_branch"
238
+
239
+ return 0
240
+ }
241
+
242
+ # Provide branch-specific guidance
243
+ provide_branch_guidance() {
244
+ local branch="$1"
245
+
246
+ # Skip guidance for main branches
247
+ if echo "$branch" | grep -qE "^(main|master|develop|dev)$"; then
248
+ log_info "On main branch: $branch"
249
+ return 0
250
+ fi
251
+
252
+ # Provide contextual guidance based on branch name
253
+ if echo "$branch" | grep -qE "^(feature|feat)/"; then
254
+ log_info "💡 Feature branch detected. Consider:"
255
+ log_info " â€ĸ Creating a task: stackmemory task add 'Implement feature X'"
256
+ log_info " â€ĸ Planning implementation: stackmemory start_frame --name 'Feature planning'"
257
+ elif echo "$branch" | grep -qE "^(bugfix|fix)/"; then
258
+ log_info "🐛 Bug fix branch detected. Consider:"
259
+ log_info " â€ĸ Creating a bug fix task with priority: stackmemory task add 'Fix bug X' --priority high"
260
+ log_info " â€ĸ Starting debugging frame: stackmemory start_frame --name 'Debug session' --type debug"
261
+ elif echo "$branch" | grep -qE "^(hotfix)/"; then
262
+ log_warning "🚨 Hotfix branch detected. Consider:"
263
+ log_warning " â€ĸ Creating urgent task: stackmemory task add 'Hotfix X' --priority critical"
264
+ log_warning " â€ĸ Tracking progress carefully for production release"
265
+ fi
266
+
267
+ return 0
268
+ }
269
+
270
+ # Filter tasks by branch prefix
271
+ filter_tasks_by_branch() {
272
+ local branch="$1"
273
+
274
+ if [ "$BRANCH_PREFIX_FILTERING" != "true" ]; then
275
+ return 0
276
+ fi
277
+
278
+ # Extract prefix from branch name (e.g., STA-123 from STA-123/feature-name)
279
+ local prefix=$(echo "$branch" | grep -oE "^[A-Z]+-[0-9]+" || echo "")
280
+
281
+ if [ -n "$prefix" ]; then
282
+ log_info "Branch prefix detected: $prefix"
283
+ log_info "Showing related tasks..."
284
+
285
+ # Show tasks that match the prefix
286
+ if stackmemory tasks list --search "$prefix" >/dev/null 2>&1; then
287
+ local matching_tasks=$(stackmemory tasks list --search "$prefix" 2>/dev/null || echo "")
288
+ if [ -n "$matching_tasks" ] && [ "$matching_tasks" != "No tasks found" ]; then
289
+ echo ""
290
+ echo "$matching_tasks"
291
+ echo ""
292
+ fi
293
+ fi
294
+ fi
295
+
296
+ return 0
297
+ }
298
+
299
+ # Main execution function
300
+ main() {
301
+ local action="${1:-switch}"
302
+ local previous_branch="${2:-}"
303
+ local current_branch="${3:-}"
304
+
305
+ # Auto-detect branch information if not provided
306
+ if [ -z "$current_branch" ]; then
307
+ current_branch=$(get_current_branch)
308
+ fi
309
+
310
+ if [ -z "$previous_branch" ] && [ "$action" = "switch" ]; then
311
+ previous_branch=$(get_previous_branch)
312
+ fi
313
+
314
+ case "$action" in
315
+ "switch")
316
+ if [ "$BRANCH_ISOLATION_ENABLED" = "true" ]; then
317
+ handle_branch_switch "$previous_branch" "$current_branch"
318
+ filter_tasks_by_branch "$current_branch"
319
+ fi
320
+ ;;
321
+ "save")
322
+ save_branch_context "$current_branch"
323
+ ;;
324
+ "load")
325
+ load_branch_context "$current_branch"
326
+ ;;
327
+ "init")
328
+ initialize_branch_context "$current_branch"
329
+ ;;
330
+ *)
331
+ log_error "Usage: $0 {switch|save|load|init} [previous_branch] [current_branch]"
332
+ exit 1
333
+ ;;
334
+ esac
335
+
336
+ return 0
337
+ }
338
+
339
+ # Run main function if script is executed directly
340
+ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
341
+ main "$@"
342
+ fi
@@ -0,0 +1,63 @@
1
+ #!/bin/bash
2
+ # StackMemory Post-Checkout Hook
3
+ # Handles branch context switching and task isolation
4
+
5
+ set -e
6
+
7
+ # Hook parameters from git
8
+ prev_head="$1"
9
+ new_head="$2"
10
+ is_branch_checkout="$3"
11
+
12
+ # Colors for output
13
+ RED='\033[0;31m'
14
+ GREEN='\033[0;32m'
15
+ YELLOW='\033[1;33m'
16
+ BLUE='\033[0;34m'
17
+ NC='\033[0m' # No Color
18
+
19
+ log_info() {
20
+ echo -e "${BLUE}â„šī¸ $1${NC}"
21
+ }
22
+
23
+ log_success() {
24
+ echo -e "${GREEN}✅ $1${NC}"
25
+ }
26
+
27
+ log_warning() {
28
+ echo -e "${YELLOW}âš ī¸ $1${NC}"
29
+ }
30
+
31
+ # Only process branch checkouts
32
+ if [ "$is_branch_checkout" != "1" ]; then
33
+ exit 0
34
+ fi
35
+
36
+ # Check if StackMemory is available
37
+ if ! command -v stackmemory >/dev/null 2>&1 || [ ! -d ".stackmemory" ]; then
38
+ exit 0
39
+ fi
40
+
41
+ # Get script directory
42
+ SCRIPT_DIR="$(dirname "$0")"
43
+ REPO_ROOT="$(git rev-parse --show-toplevel)"
44
+
45
+ # Source the branch context manager
46
+ if [ -f "$REPO_ROOT/scripts/git-hooks/branch-context-manager.sh" ]; then
47
+ source "$REPO_ROOT/scripts/git-hooks/branch-context-manager.sh"
48
+ else
49
+ log_warning "Branch context manager not found, skipping branch isolation"
50
+ exit 0
51
+ fi
52
+
53
+ # Get branch names
54
+ current_branch=$(git branch --show-current 2>/dev/null || echo "HEAD")
55
+ previous_branch=$(git name-rev --name-only "$prev_head" 2>/dev/null | sed 's/^[^/]*\///' || echo "")
56
+
57
+ log_info "🔀 Branch checkout detected: switching to $current_branch"
58
+
59
+ # Handle the branch switch
60
+ main "switch" "$previous_branch" "$current_branch"
61
+
62
+ log_success "Branch context switch completed"
63
+ exit 0