@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.
- package/dist/cli/claude-sm.js +51 -5
- package/dist/cli/claude-sm.js.map +2 -2
- package/dist/cli/codex-sm.js +52 -19
- package/dist/cli/codex-sm.js.map +2 -2
- package/dist/cli/commands/db.js +143 -0
- package/dist/cli/commands/db.js.map +7 -0
- package/dist/cli/commands/login.js +50 -0
- package/dist/cli/commands/login.js.map +7 -0
- package/dist/cli/commands/migrate.js +178 -0
- package/dist/cli/commands/migrate.js.map +7 -0
- package/dist/cli/commands/onboard.js +158 -2
- package/dist/cli/commands/onboard.js.map +2 -2
- package/dist/cli/commands/skills.js +15 -2
- package/dist/cli/commands/skills.js.map +2 -2
- package/dist/cli/index.js +118 -834
- package/dist/cli/index.js.map +3 -3
- package/dist/core/context/dual-stack-manager.js +1 -1
- package/dist/core/context/dual-stack-manager.js.map +1 -1
- package/dist/core/context/frame-database.js +1 -0
- package/dist/core/context/frame-database.js.map +2 -2
- package/dist/core/context/frame-manager.js +59 -2
- package/dist/core/context/frame-manager.js.map +2 -2
- package/dist/core/database/database-adapter.js +6 -1
- package/dist/core/database/database-adapter.js.map +2 -2
- package/dist/core/database/sqlite-adapter.js +60 -2
- package/dist/core/database/sqlite-adapter.js.map +2 -2
- package/dist/integrations/claude-code/subagent-client.js +106 -3
- package/dist/integrations/claude-code/subagent-client.js.map +2 -2
- package/dist/servers/railway/config.js +51 -0
- package/dist/servers/railway/config.js.map +7 -0
- package/dist/servers/railway/index-enhanced.js +156 -0
- package/dist/servers/railway/index-enhanced.js.map +7 -0
- package/dist/servers/railway/index.js +843 -82
- package/dist/servers/railway/index.js.map +3 -3
- package/dist/servers/railway/minimal.js +48 -3
- package/dist/servers/railway/minimal.js.map +2 -2
- package/dist/servers/railway/storage-test.js +455 -0
- package/dist/servers/railway/storage-test.js.map +7 -0
- package/dist/skills/claude-skills.js +13 -12
- package/dist/skills/claude-skills.js.map +2 -2
- package/dist/skills/recursive-agent-orchestrator.js +27 -18
- package/dist/skills/recursive-agent-orchestrator.js.map +2 -2
- package/dist/skills/unified-rlm-orchestrator.js.map +2 -2
- package/package.json +13 -21
- package/scripts/README-TESTING.md +186 -0
- package/scripts/analyze-cli-security.js +288 -0
- package/scripts/archive/add-phase-tasks-to-linear.js +163 -0
- package/scripts/archive/analyze-linear-duplicates.js +214 -0
- package/scripts/archive/analyze-remaining-duplicates.js +230 -0
- package/scripts/archive/analyze-sta-duplicates.js +292 -0
- package/scripts/archive/analyze-sta-graphql.js +399 -0
- package/scripts/archive/cancel-duplicate-tasks.ts +246 -0
- package/scripts/archive/check-all-duplicates.ts +419 -0
- package/scripts/archive/clean-duplicate-tasks.js +114 -0
- package/scripts/archive/cleanup-duplicate-tasks.ts +286 -0
- package/scripts/archive/create-phase-tasks.js +387 -0
- package/scripts/archive/delete-linear-duplicates.js +182 -0
- package/scripts/archive/delete-remaining-duplicates.js +158 -0
- package/scripts/archive/delete-sta-duplicates.js +201 -0
- package/scripts/archive/delete-sta-oauth.js +201 -0
- package/scripts/archive/export-sta-tasks.js +62 -0
- package/scripts/archive/install-auto-sync.js +266 -0
- package/scripts/archive/install-chromadb-hooks.sh +133 -0
- package/scripts/archive/install-enhanced-clear-hooks.sh +431 -0
- package/scripts/archive/install-post-task-hooks.sh +289 -0
- package/scripts/archive/install-stackmemory-hooks.sh +420 -0
- package/scripts/archive/merge-linear-duplicates-safe.ts +362 -0
- package/scripts/archive/merge-linear-duplicates.ts +180 -0
- package/scripts/archive/remove-sta-tasks.js +70 -0
- package/scripts/archive/setup-background-sync.sh +168 -0
- package/scripts/archive/setup-claude-auto-triggers.sh +181 -0
- package/scripts/archive/setup-claude-autostart.sh +305 -0
- package/scripts/archive/setup-git-hooks.sh +25 -0
- package/scripts/archive/setup-linear-oauth.sh +46 -0
- package/scripts/archive/setup-mcp.sh +113 -0
- package/scripts/archive/setup-railway-deployment.sh +81 -0
- package/scripts/auto-handoff.sh +262 -0
- package/scripts/background-sync-manager.js +416 -0
- package/scripts/benchmark-performance.ts +57 -0
- package/scripts/check-redis.ts +48 -0
- package/scripts/chromadb-auto-loader.sh +128 -0
- package/scripts/chromadb-context-loader.js +479 -0
- package/scripts/claude-chromadb-hook.js +460 -0
- package/scripts/claude-code-wrapper.sh +66 -0
- package/scripts/claude-linear-skill.js +455 -0
- package/scripts/claude-pre-commit.sh +302 -0
- package/scripts/claude-sm-autostart.js +532 -0
- package/scripts/claude-sm-setup.sh +367 -0
- package/scripts/claude-with-chromadb.sh +69 -0
- package/scripts/claude-worktree-manager.sh +323 -0
- package/scripts/claude-worktree-monitor.sh +371 -0
- package/scripts/claude-worktree-setup.sh +327 -0
- package/scripts/clean-linear-backlog.js +273 -0
- package/scripts/cleanup-old-sessions.sh +57 -0
- package/scripts/codex-wrapper.sh +88 -0
- package/scripts/create-sandbox.sh +269 -0
- package/scripts/debug-linear-update.js +174 -0
- package/scripts/delete-linear-tasks.js +167 -0
- package/scripts/deploy.sh +89 -0
- package/scripts/deployment/railway.sh +352 -0
- package/scripts/deployment/test-deployment.js +194 -0
- package/scripts/detect-and-rehydrate.js +162 -0
- package/scripts/detect-and-rehydrate.mjs +165 -0
- package/scripts/development/create-demo-tasks.js +143 -0
- package/scripts/development/debug-frame-test.js +16 -0
- package/scripts/development/demo-auto-sync.js +128 -0
- package/scripts/development/fix-all-imports.js +213 -0
- package/scripts/development/fix-imports.js +229 -0
- package/scripts/development/fix-lint-loop.cjs +103 -0
- package/scripts/development/fix-project-id.ts +161 -0
- package/scripts/development/fix-strict-mode-issues.ts +291 -0
- package/scripts/development/reorganize-structure.sh +228 -0
- package/scripts/development/test-persistence-direct.js +148 -0
- package/scripts/development/test-persistence.js +114 -0
- package/scripts/development/test-tasks.js +93 -0
- package/scripts/development/update-imports.js +212 -0
- package/scripts/fetch-linear-status.js +125 -0
- package/scripts/git-hooks/README.md +310 -0
- package/scripts/git-hooks/branch-context-manager.sh +342 -0
- package/scripts/git-hooks/post-checkout-stackmemory.sh +63 -0
- package/scripts/git-hooks/post-commit-stackmemory.sh +305 -0
- package/scripts/git-hooks/pre-commit-stackmemory.sh +275 -0
- package/scripts/hooks/cleanup-shell.sh +130 -0
- package/scripts/hooks/task-complete.sh +114 -0
- package/scripts/initialize.ts +129 -0
- package/scripts/install-claude-hooks-auto.js +104 -0
- package/scripts/install-claude-hooks.sh +133 -0
- package/scripts/install-global.sh +296 -0
- package/scripts/install.sh +235 -0
- package/scripts/linear-auto-sync.js +262 -0
- package/scripts/linear-auto-sync.sh +161 -0
- package/scripts/linear-sync-daemon.js +150 -0
- package/scripts/linear-task-review.js +237 -0
- package/scripts/list-linear-tasks.ts +178 -0
- package/scripts/mcp-proxy.js +66 -0
- package/scripts/opencode-wrapper.sh +85 -0
- package/scripts/publish-local.js +74 -0
- package/scripts/query-chromadb.ts +201 -0
- package/scripts/railway-env-setup.sh +39 -0
- package/scripts/reconcile-local-tasks.js +170 -0
- package/scripts/recreate-frames-db.js +89 -0
- package/scripts/setup/claude-integration.js +138 -0
- package/scripts/setup/configure-alias.js +125 -0
- package/scripts/setup/configure-codex-alias.js +161 -0
- package/scripts/setup/configure-opencode-alias.js +175 -0
- package/scripts/setup-claude-integration.js +204 -0
- package/scripts/setup-claude-integration.sh +183 -0
- package/scripts/setup-railway-deployment.sh +37 -0
- package/scripts/setup.sh +31 -0
- package/scripts/show-linear-summary.ts +172 -0
- package/scripts/stackmemory-auto-handoff.sh +231 -0
- package/scripts/stackmemory-daemon.sh +40 -0
- package/scripts/start-linear-sync-daemon.sh +141 -0
- package/scripts/start-temporal-paradox.sh +214 -0
- package/scripts/status.ts +159 -0
- package/scripts/sync-and-clean-tasks.js +258 -0
- package/scripts/sync-frames-from-railway.js +228 -0
- package/scripts/sync-linear-graphql.js +303 -0
- package/scripts/sync-linear-tasks.js +186 -0
- package/scripts/test-auto-triggers.sh +57 -0
- package/scripts/test-browser-mcp.js +74 -0
- package/scripts/test-chromadb-full.js +115 -0
- package/scripts/test-chromadb-hooks.sh +28 -0
- package/scripts/test-chromadb-sync.ts +245 -0
- package/scripts/test-cli-security.js +293 -0
- package/scripts/test-hooks-persistence.sh +220 -0
- package/scripts/test-installation-scenarios.sh +359 -0
- package/scripts/test-installation.sh +224 -0
- package/scripts/test-mcp.js +163 -0
- package/scripts/test-pre-publish-quick.sh +75 -0
- package/scripts/test-quality-gates.sh +263 -0
- package/scripts/test-railway-db.js +222 -0
- package/scripts/test-redis-storage.ts +490 -0
- package/scripts/test-rlm-basic.sh +122 -0
- package/scripts/test-rlm-comprehensive.sh +260 -0
- package/scripts/test-rlm-e2e.sh +268 -0
- package/scripts/test-rlm-simple.js +90 -0
- package/scripts/test-rlm.js +110 -0
- package/scripts/test-session-handoff.sh +165 -0
- package/scripts/test-shell-integration.sh +275 -0
- package/scripts/testing/ab-test-runner.ts +508 -0
- package/scripts/testing/collect-metrics.ts +457 -0
- package/scripts/testing/quick-effectiveness-demo.js +187 -0
- package/scripts/testing/real-performance-test.js +422 -0
- package/scripts/testing/run-effectiveness-tests.sh +176 -0
- package/scripts/testing/scripts/testing/ab-test-runner.js +363 -0
- package/scripts/testing/scripts/testing/collect-metrics.js +292 -0
- package/scripts/testing/simple-effectiveness-test.js +310 -0
- package/scripts/testing/src/core/context/context-bridge.js +253 -0
- package/scripts/testing/src/core/context/frame-manager.js +746 -0
- package/scripts/testing/src/core/context/shared-context-layer.js +437 -0
- package/scripts/testing/src/core/database/database-adapter.js +54 -0
- package/scripts/testing/src/core/errors/index.js +291 -0
- package/scripts/testing/src/core/errors/recovery.js +268 -0
- package/scripts/testing/src/core/monitoring/logger.js +145 -0
- package/scripts/testing/src/core/retrieval/context-retriever.js +516 -0
- package/scripts/testing/src/core/session/index.js +1 -0
- package/scripts/testing/src/core/session/session-manager.js +323 -0
- package/scripts/testing/src/core/trace/cli-trace-wrapper.js +140 -0
- package/scripts/testing/src/core/trace/db-trace-wrapper.js +251 -0
- package/scripts/testing/src/core/trace/debug-trace.js +398 -0
- package/scripts/testing/src/core/trace/index.js +120 -0
- package/scripts/testing/src/core/trace/linear-api-wrapper.js +204 -0
- package/scripts/update-linear-status.js +268 -0
- package/scripts/update-linear-tasks-fixed.js +284 -0
- package/scripts/verify-railway-schema.ts +35 -0
- package/templates/claude-hooks/hooks.json +5 -0
- package/templates/claude-hooks/on-clear.js +56 -0
- package/templates/claude-hooks/on-startup.js +56 -0
- package/templates/claude-hooks/tool-use-trace.js +67 -0
- package/dist/features/tui/components/analytics-panel.js +0 -157
- package/dist/features/tui/components/analytics-panel.js.map +0 -7
- package/dist/features/tui/components/frame-visualizer.js +0 -377
- package/dist/features/tui/components/frame-visualizer.js.map +0 -7
- package/dist/features/tui/components/pr-tracker.js +0 -135
- package/dist/features/tui/components/pr-tracker.js.map +0 -7
- package/dist/features/tui/components/session-monitor.js +0 -299
- package/dist/features/tui/components/session-monitor.js.map +0 -7
- package/dist/features/tui/components/subagent-fleet.js +0 -395
- package/dist/features/tui/components/subagent-fleet.js.map +0 -7
- package/dist/features/tui/components/task-board.js +0 -1139
- package/dist/features/tui/components/task-board.js.map +0 -7
- package/dist/features/tui/index.js +0 -408
- package/dist/features/tui/index.js.map +0 -7
- package/dist/features/tui/services/data-service.js +0 -641
- package/dist/features/tui/services/data-service.js.map +0 -7
- package/dist/features/tui/services/linear-task-reader.js +0 -102
- package/dist/features/tui/services/linear-task-reader.js.map +0 -7
- package/dist/features/tui/services/websocket-client.js +0 -162
- package/dist/features/tui/services/websocket-client.js.map +0 -7
- package/dist/features/tui/terminal-compat.js +0 -220
- package/dist/features/tui/terminal-compat.js.map +0 -7
- package/dist/features/tui/types.js +0 -1
- package/dist/features/tui/types.js.map +0 -7
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# StackMemory Post-Commit Hook
|
|
3
|
+
# Updates tasks based on commit content and syncs with external systems
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
# Colors for output
|
|
8
|
+
RED='\033[0;31m'
|
|
9
|
+
GREEN='\033[0;32m'
|
|
10
|
+
YELLOW='\033[1;33m'
|
|
11
|
+
BLUE='\033[0;34m'
|
|
12
|
+
NC='\033[0m' # No Color
|
|
13
|
+
|
|
14
|
+
# Configuration
|
|
15
|
+
STACKMEMORY_ENABLED=true
|
|
16
|
+
AUTO_UPDATE_TASKS=true
|
|
17
|
+
SYNC_LINEAR=true
|
|
18
|
+
PARSE_COMMIT_MESSAGES=true
|
|
19
|
+
UPDATE_TASK_PROGRESS=true
|
|
20
|
+
CREATE_COMPLETION_FRAMES=true
|
|
21
|
+
|
|
22
|
+
log_info() {
|
|
23
|
+
echo -e "${BLUE}ℹ️ $1${NC}"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
log_success() {
|
|
27
|
+
echo -e "${GREEN}✅ $1${NC}"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
log_warning() {
|
|
31
|
+
echo -e "${YELLOW}⚠️ $1${NC}"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
log_error() {
|
|
35
|
+
echo -e "${RED}❌ $1${NC}"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Check if StackMemory is available
|
|
39
|
+
check_stackmemory() {
|
|
40
|
+
if ! command -v stackmemory >/dev/null 2>&1; then
|
|
41
|
+
log_warning "StackMemory CLI not found, skipping post-commit actions"
|
|
42
|
+
STACKMEMORY_ENABLED=false
|
|
43
|
+
return 0
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
if [ ! -d ".stackmemory" ]; then
|
|
47
|
+
log_info "StackMemory not initialized in this repo"
|
|
48
|
+
STACKMEMORY_ENABLED=false
|
|
49
|
+
return 0
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
return 0
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# Get commit information
|
|
56
|
+
get_commit_info() {
|
|
57
|
+
local commit_hash=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
|
|
58
|
+
local commit_msg=$(git log -1 --pretty=%B 2>/dev/null | head -1 || echo "")
|
|
59
|
+
local commit_author=$(git log -1 --pretty=%an 2>/dev/null || echo "unknown")
|
|
60
|
+
local branch=$(git branch --show-current 2>/dev/null || echo "unknown")
|
|
61
|
+
local files_changed=$(git diff-tree --no-commit-id --name-only -r HEAD 2>/dev/null | wc -l | tr -d ' ')
|
|
62
|
+
|
|
63
|
+
echo "$commit_hash|$commit_msg|$commit_author|$branch|$files_changed"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
# Parse commit message for task-related information
|
|
67
|
+
parse_commit_message() {
|
|
68
|
+
local commit_msg="$1"
|
|
69
|
+
local task_actions=""
|
|
70
|
+
|
|
71
|
+
# Look for task completion indicators
|
|
72
|
+
if echo "$commit_msg" | grep -iE "(complete|done|finish|resolve|close)" >/dev/null; then
|
|
73
|
+
task_actions="${task_actions}completion,"
|
|
74
|
+
fi
|
|
75
|
+
|
|
76
|
+
# Look for fix indicators
|
|
77
|
+
if echo "$commit_msg" | grep -iE "(fix|bug|error|issue)" >/dev/null; then
|
|
78
|
+
task_actions="${task_actions}fix,"
|
|
79
|
+
fi
|
|
80
|
+
|
|
81
|
+
# Look for feature indicators
|
|
82
|
+
if echo "$commit_msg" | grep -iE "(feat|feature|add|implement)" >/dev/null; then
|
|
83
|
+
task_actions="${task_actions}feature,"
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
# Look for refactor indicators
|
|
87
|
+
if echo "$commit_msg" | grep -iE "(refactor|clean|reorganize)" >/dev/null; then
|
|
88
|
+
task_actions="${task_actions}refactor,"
|
|
89
|
+
fi
|
|
90
|
+
|
|
91
|
+
# Look for test indicators
|
|
92
|
+
if echo "$commit_msg" | grep -iE "(test|spec)" >/dev/null; then
|
|
93
|
+
task_actions="${task_actions}test,"
|
|
94
|
+
fi
|
|
95
|
+
|
|
96
|
+
# Look for task IDs (e.g., STA-123, TASK-456, #123)
|
|
97
|
+
local task_ids=$(echo "$commit_msg" | grep -oE "(STA-[0-9]+|TASK-[0-9]+|#[0-9]+|tsk-[a-zA-Z0-9]+)" | tr '\n' ',' || echo "")
|
|
98
|
+
|
|
99
|
+
echo "${task_actions}${task_ids}"
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
# Update task progress based on commit
|
|
103
|
+
update_task_progress() {
|
|
104
|
+
if [ "$STACKMEMORY_ENABLED" != "true" ] || [ "$UPDATE_TASK_PROGRESS" != "true" ]; then
|
|
105
|
+
return 0
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
local commit_info="$1"
|
|
109
|
+
IFS='|' read -r commit_hash commit_msg commit_author branch files_changed <<< "$commit_info"
|
|
110
|
+
|
|
111
|
+
log_info "Updating task progress based on commit..."
|
|
112
|
+
|
|
113
|
+
# Parse commit message for task information
|
|
114
|
+
local parsed_info=$(parse_commit_message "$commit_msg")
|
|
115
|
+
|
|
116
|
+
# Get currently active tasks
|
|
117
|
+
local active_tasks=$(stackmemory tasks list --status in-progress 2>/dev/null || echo "")
|
|
118
|
+
|
|
119
|
+
if [ -z "$active_tasks" ] || [ "$active_tasks" = "No tasks found" ]; then
|
|
120
|
+
log_info "No active tasks to update"
|
|
121
|
+
return 0
|
|
122
|
+
fi
|
|
123
|
+
|
|
124
|
+
# If commit indicates completion
|
|
125
|
+
if echo "$parsed_info" | grep -q "completion"; then
|
|
126
|
+
log_info "Commit indicates task completion"
|
|
127
|
+
|
|
128
|
+
# Get the most recently started task
|
|
129
|
+
local recent_task=$(echo "$active_tasks" | head -1 | grep -oE "tsk-[a-zA-Z0-9]+" | head -1 || echo "")
|
|
130
|
+
|
|
131
|
+
if [ -n "$recent_task" ]; then
|
|
132
|
+
log_info "Marking task $recent_task as completed"
|
|
133
|
+
if stackmemory task done "$recent_task" >/dev/null 2>&1; then
|
|
134
|
+
log_success "Task $recent_task marked as completed"
|
|
135
|
+
else
|
|
136
|
+
log_warning "Failed to update task $recent_task"
|
|
137
|
+
fi
|
|
138
|
+
fi
|
|
139
|
+
fi
|
|
140
|
+
|
|
141
|
+
# Extract specific task IDs from commit message
|
|
142
|
+
local task_ids=$(echo "$parsed_info" | grep -oE "(STA-[0-9]+|tsk-[a-zA-Z0-9]+)" || echo "")
|
|
143
|
+
|
|
144
|
+
for task_id in $task_ids; do
|
|
145
|
+
if [ -n "$task_id" ]; then
|
|
146
|
+
log_info "Found task reference: $task_id"
|
|
147
|
+
|
|
148
|
+
# Try to update the specific task
|
|
149
|
+
if echo "$parsed_info" | grep -q "completion"; then
|
|
150
|
+
stackmemory task done "$task_id" >/dev/null 2>&1 && log_success "Completed task $task_id"
|
|
151
|
+
else
|
|
152
|
+
# Just update progress
|
|
153
|
+
stackmemory task update "$task_id" --progress 75 >/dev/null 2>&1 && log_info "Updated progress for $task_id"
|
|
154
|
+
fi
|
|
155
|
+
fi
|
|
156
|
+
done
|
|
157
|
+
|
|
158
|
+
return 0
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
# Create completion frame for significant commits
|
|
162
|
+
create_completion_frame() {
|
|
163
|
+
if [ "$STACKMEMORY_ENABLED" != "true" ] || [ "$CREATE_COMPLETION_FRAMES" != "true" ]; then
|
|
164
|
+
return 0
|
|
165
|
+
fi
|
|
166
|
+
|
|
167
|
+
local commit_info="$1"
|
|
168
|
+
IFS='|' read -r commit_hash commit_msg commit_author branch files_changed <<< "$commit_info"
|
|
169
|
+
|
|
170
|
+
# Only create frames for significant commits (multiple files or completion words)
|
|
171
|
+
if [ "$files_changed" -lt 3 ] && ! echo "$commit_msg" | grep -iE "(complete|done|finish|resolve|feat|feature)" >/dev/null; then
|
|
172
|
+
return 0
|
|
173
|
+
fi
|
|
174
|
+
|
|
175
|
+
log_info "Creating completion frame for significant commit..."
|
|
176
|
+
|
|
177
|
+
# Create a completion frame
|
|
178
|
+
local frame_name="Commit: $(echo "$commit_msg" | cut -c1-50)"
|
|
179
|
+
|
|
180
|
+
if stackmemory start_frame --name "$frame_name" --type write >/dev/null 2>&1; then
|
|
181
|
+
# Add commit details as anchors
|
|
182
|
+
stackmemory add_anchor --type FACT --text "Commit $commit_hash on branch $branch" >/dev/null 2>&1
|
|
183
|
+
stackmemory add_anchor --type FACT --text "Modified $files_changed files" >/dev/null 2>&1
|
|
184
|
+
|
|
185
|
+
if [ -n "$commit_author" ] && [ "$commit_author" != "unknown" ]; then
|
|
186
|
+
stackmemory add_anchor --type FACT --text "Author: $commit_author" >/dev/null 2>&1
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
# Add commit message as observation
|
|
190
|
+
stackmemory context add observation "Post-commit: $commit_msg" >/dev/null 2>&1
|
|
191
|
+
|
|
192
|
+
# Close the frame with summary
|
|
193
|
+
stackmemory close_frame --summary "Completed commit with $files_changed file changes" >/dev/null 2>&1
|
|
194
|
+
|
|
195
|
+
log_success "Completion frame created"
|
|
196
|
+
else
|
|
197
|
+
log_warning "Failed to create completion frame"
|
|
198
|
+
fi
|
|
199
|
+
|
|
200
|
+
return 0
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
# Sync with Linear if enabled
|
|
204
|
+
sync_with_linear() {
|
|
205
|
+
if [ "$STACKMEMORY_ENABLED" != "true" ] || [ "$SYNC_LINEAR" != "true" ]; then
|
|
206
|
+
return 0
|
|
207
|
+
fi
|
|
208
|
+
|
|
209
|
+
# Check if Linear is configured
|
|
210
|
+
if ! stackmemory linear status >/dev/null 2>&1; then
|
|
211
|
+
log_info "Linear not configured, skipping sync"
|
|
212
|
+
return 0
|
|
213
|
+
fi
|
|
214
|
+
|
|
215
|
+
local commit_info="$1"
|
|
216
|
+
IFS='|' read -r commit_hash commit_msg commit_author branch files_changed <<< "$commit_info"
|
|
217
|
+
|
|
218
|
+
# Look for Linear issue references in commit message
|
|
219
|
+
local linear_ids=$(echo "$commit_msg" | grep -oE "(STA-[0-9]+|ENG-[0-9]+)" || echo "")
|
|
220
|
+
|
|
221
|
+
if [ -n "$linear_ids" ]; then
|
|
222
|
+
log_info "Found Linear issue references: $linear_ids"
|
|
223
|
+
|
|
224
|
+
for linear_id in $linear_ids; do
|
|
225
|
+
log_info "Updating Linear issue $linear_id..."
|
|
226
|
+
|
|
227
|
+
# Update Linear issue with commit information
|
|
228
|
+
local update_text="Commit: $commit_hash - $commit_msg"
|
|
229
|
+
|
|
230
|
+
# Try to add comment to Linear issue
|
|
231
|
+
if stackmemory linear update_task --linear_id "$linear_id" --comment "$update_text" >/dev/null 2>&1; then
|
|
232
|
+
log_success "Updated Linear issue $linear_id"
|
|
233
|
+
else
|
|
234
|
+
log_warning "Failed to update Linear issue $linear_id"
|
|
235
|
+
fi
|
|
236
|
+
done
|
|
237
|
+
fi
|
|
238
|
+
|
|
239
|
+
# Run general sync
|
|
240
|
+
log_info "Running Linear sync..."
|
|
241
|
+
if stackmemory linear sync --direction to_linear >/dev/null 2>&1; then
|
|
242
|
+
log_success "Linear sync completed"
|
|
243
|
+
else
|
|
244
|
+
log_warning "Linear sync failed (may be normal if no changes)"
|
|
245
|
+
fi
|
|
246
|
+
|
|
247
|
+
return 0
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
# Record commit metrics
|
|
251
|
+
record_commit_metrics() {
|
|
252
|
+
if [ "$STACKMEMORY_ENABLED" != "true" ]; then
|
|
253
|
+
return 0
|
|
254
|
+
fi
|
|
255
|
+
|
|
256
|
+
local commit_info="$1"
|
|
257
|
+
IFS='|' read -r commit_hash commit_msg commit_author branch files_changed <<< "$commit_info"
|
|
258
|
+
|
|
259
|
+
# Add commit event to StackMemory context
|
|
260
|
+
if command -v stackmemory >/dev/null 2>&1; then
|
|
261
|
+
stackmemory context add observation "Commit completed: $commit_hash ($files_changed files on $branch)" >/dev/null 2>&1 || true
|
|
262
|
+
|
|
263
|
+
# Update context with commit statistics
|
|
264
|
+
local current_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
|
265
|
+
stackmemory context add decision "Last commit: $current_time - $commit_msg" >/dev/null 2>&1 || true
|
|
266
|
+
fi
|
|
267
|
+
|
|
268
|
+
return 0
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
# Main execution
|
|
272
|
+
main() {
|
|
273
|
+
log_info "📝 StackMemory post-commit hook starting..."
|
|
274
|
+
|
|
275
|
+
# Core checks
|
|
276
|
+
check_stackmemory
|
|
277
|
+
|
|
278
|
+
if [ "$STACKMEMORY_ENABLED" != "true" ]; then
|
|
279
|
+
log_info "StackMemory not available, skipping post-commit actions"
|
|
280
|
+
return 0
|
|
281
|
+
fi
|
|
282
|
+
|
|
283
|
+
# Get commit information
|
|
284
|
+
local commit_info=$(get_commit_info)
|
|
285
|
+
IFS='|' read -r commit_hash commit_msg commit_author branch files_changed <<< "$commit_info"
|
|
286
|
+
|
|
287
|
+
log_info "Processing commit $commit_hash on branch $branch"
|
|
288
|
+
log_info "Message: $commit_msg"
|
|
289
|
+
log_info "Files changed: $files_changed"
|
|
290
|
+
|
|
291
|
+
# Execute post-commit actions
|
|
292
|
+
if [ "$AUTO_UPDATE_TASKS" = "true" ]; then
|
|
293
|
+
update_task_progress "$commit_info"
|
|
294
|
+
fi
|
|
295
|
+
|
|
296
|
+
create_completion_frame "$commit_info"
|
|
297
|
+
record_commit_metrics "$commit_info"
|
|
298
|
+
sync_with_linear "$commit_info"
|
|
299
|
+
|
|
300
|
+
log_success "🎉 Post-commit processing completed!"
|
|
301
|
+
return 0
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
# Run main function
|
|
305
|
+
main "$@"
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# StackMemory Pre-Commit Hook
|
|
3
|
+
# Validates tasks, runs checks, and maintains project integrity
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
# Colors for output
|
|
8
|
+
RED='\033[0;31m'
|
|
9
|
+
GREEN='\033[0;32m'
|
|
10
|
+
YELLOW='\033[1;33m'
|
|
11
|
+
BLUE='\033[0;34m'
|
|
12
|
+
NC='\033[0m' # No Color
|
|
13
|
+
|
|
14
|
+
# Configuration
|
|
15
|
+
STACKMEMORY_ENABLED=true
|
|
16
|
+
VALIDATE_TASKS=true
|
|
17
|
+
VALIDATE_LINT=true
|
|
18
|
+
VALIDATE_TYPES=true
|
|
19
|
+
VALIDATE_TESTS_CRITICAL=false
|
|
20
|
+
AUTO_UPDATE_TASKS=true
|
|
21
|
+
|
|
22
|
+
log_info() {
|
|
23
|
+
echo -e "${BLUE}ℹ️ $1${NC}"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
log_success() {
|
|
27
|
+
echo -e "${GREEN}✅ $1${NC}"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
log_warning() {
|
|
31
|
+
echo -e "${YELLOW}⚠️ $1${NC}"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
log_error() {
|
|
35
|
+
echo -e "${RED}❌ $1${NC}"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Check if StackMemory is available
|
|
39
|
+
check_stackmemory() {
|
|
40
|
+
if ! command -v stackmemory >/dev/null 2>&1; then
|
|
41
|
+
log_warning "StackMemory CLI not found, skipping task validation"
|
|
42
|
+
STACKMEMORY_ENABLED=false
|
|
43
|
+
return 0
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
if [ ! -d ".stackmemory" ]; then
|
|
47
|
+
log_info "StackMemory not initialized in this repo"
|
|
48
|
+
STACKMEMORY_ENABLED=false
|
|
49
|
+
return 0
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
return 0
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# Validate task states before commit
|
|
56
|
+
validate_tasks() {
|
|
57
|
+
if [ "$STACKMEMORY_ENABLED" != "true" ] || [ "$VALIDATE_TASKS" != "true" ]; then
|
|
58
|
+
return 0
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
log_info "Validating task states..."
|
|
62
|
+
|
|
63
|
+
# Check for any tasks marked as "in-progress" that might need updates
|
|
64
|
+
local in_progress_tasks=$(stackmemory tasks list --status in-progress 2>/dev/null | grep -c "in-progress" || echo "0")
|
|
65
|
+
|
|
66
|
+
if [ "$in_progress_tasks" -gt 0 ]; then
|
|
67
|
+
log_info "Found $in_progress_tasks in-progress tasks"
|
|
68
|
+
|
|
69
|
+
if [ "$AUTO_UPDATE_TASKS" = "true" ]; then
|
|
70
|
+
log_info "Auto-updating task progress based on commit..."
|
|
71
|
+
|
|
72
|
+
# Get commit message to infer task updates
|
|
73
|
+
local commit_msg=""
|
|
74
|
+
if [ -f ".git/COMMIT_EDITMSG" ]; then
|
|
75
|
+
commit_msg=$(cat .git/COMMIT_EDITMSG | head -1)
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
# Parse commit for task completion indicators
|
|
79
|
+
if echo "$commit_msg" | grep -iE "(complete|done|finish|fix|resolve)" >/dev/null; then
|
|
80
|
+
log_info "Commit indicates task completion"
|
|
81
|
+
# Could auto-complete tasks here, but being conservative
|
|
82
|
+
log_warning "Consider updating task status manually: stackmemory task done <task-id>"
|
|
83
|
+
fi
|
|
84
|
+
fi
|
|
85
|
+
fi
|
|
86
|
+
|
|
87
|
+
# Check for blocked tasks
|
|
88
|
+
local blocked_tasks=$(stackmemory tasks list --status blocked 2>/dev/null | grep -c "blocked" || echo "0")
|
|
89
|
+
if [ "$blocked_tasks" -gt 0 ]; then
|
|
90
|
+
log_warning "Found $blocked_tasks blocked tasks - consider addressing before commit"
|
|
91
|
+
fi
|
|
92
|
+
|
|
93
|
+
# Validate no critical errors in tasks
|
|
94
|
+
if stackmemory status 2>&1 | grep -i "error" >/dev/null; then
|
|
95
|
+
log_error "StackMemory reports errors - please check with: stackmemory status"
|
|
96
|
+
return 1
|
|
97
|
+
fi
|
|
98
|
+
|
|
99
|
+
log_success "Task validation passed"
|
|
100
|
+
return 0
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# Run linting checks
|
|
104
|
+
validate_lint() {
|
|
105
|
+
if [ "$VALIDATE_LINT" != "true" ]; then
|
|
106
|
+
return 0
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
log_info "Running lint checks..."
|
|
110
|
+
|
|
111
|
+
# Check if package.json has lint script
|
|
112
|
+
if [ -f "package.json" ] && grep -q '"lint"' package.json; then
|
|
113
|
+
if npm run lint --silent >/dev/null 2>&1; then
|
|
114
|
+
log_success "Lint checks passed"
|
|
115
|
+
else
|
|
116
|
+
log_error "Lint checks failed - run 'npm run lint' to see details"
|
|
117
|
+
return 1
|
|
118
|
+
fi
|
|
119
|
+
elif [ -f "Cargo.toml" ]; then
|
|
120
|
+
# Rust project
|
|
121
|
+
if cargo clippy --quiet -- -D warnings >/dev/null 2>&1; then
|
|
122
|
+
log_success "Clippy checks passed"
|
|
123
|
+
else
|
|
124
|
+
log_error "Clippy checks failed - run 'cargo clippy' to see details"
|
|
125
|
+
return 1
|
|
126
|
+
fi
|
|
127
|
+
else
|
|
128
|
+
log_info "No lint configuration found, skipping"
|
|
129
|
+
fi
|
|
130
|
+
|
|
131
|
+
return 0
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
# Run type checks
|
|
135
|
+
validate_types() {
|
|
136
|
+
if [ "$VALIDATE_TYPES" != "true" ]; then
|
|
137
|
+
return 0
|
|
138
|
+
fi
|
|
139
|
+
|
|
140
|
+
log_info "Running type checks..."
|
|
141
|
+
|
|
142
|
+
# TypeScript projects
|
|
143
|
+
if [ -f "tsconfig.json" ]; then
|
|
144
|
+
if command -v tsc >/dev/null 2>&1; then
|
|
145
|
+
if tsc --noEmit --incremental false >/dev/null 2>&1; then
|
|
146
|
+
log_success "TypeScript type checks passed"
|
|
147
|
+
else
|
|
148
|
+
log_error "TypeScript type checks failed - run 'tsc --noEmit' to see details"
|
|
149
|
+
return 1
|
|
150
|
+
fi
|
|
151
|
+
elif npm run typecheck --silent >/dev/null 2>&1; then
|
|
152
|
+
log_success "Type checks passed"
|
|
153
|
+
else
|
|
154
|
+
log_warning "TypeScript found but no tsc command or typecheck script"
|
|
155
|
+
fi
|
|
156
|
+
# Python projects with mypy
|
|
157
|
+
elif [ -f "mypy.ini" ] || [ -f "pyproject.toml" ]; then
|
|
158
|
+
if command -v mypy >/dev/null 2>&1; then
|
|
159
|
+
if mypy . >/dev/null 2>&1; then
|
|
160
|
+
log_success "MyPy type checks passed"
|
|
161
|
+
else
|
|
162
|
+
log_error "MyPy type checks failed - run 'mypy .' to see details"
|
|
163
|
+
return 1
|
|
164
|
+
fi
|
|
165
|
+
fi
|
|
166
|
+
# Rust projects
|
|
167
|
+
elif [ -f "Cargo.toml" ]; then
|
|
168
|
+
if cargo check --quiet >/dev/null 2>&1; then
|
|
169
|
+
log_success "Rust type checks passed"
|
|
170
|
+
else
|
|
171
|
+
log_error "Rust compilation failed - run 'cargo check' to see details"
|
|
172
|
+
return 1
|
|
173
|
+
fi
|
|
174
|
+
else
|
|
175
|
+
log_info "No type checking configuration found, skipping"
|
|
176
|
+
fi
|
|
177
|
+
|
|
178
|
+
return 0
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
# Run critical tests (if enabled)
|
|
182
|
+
validate_critical_tests() {
|
|
183
|
+
if [ "$VALIDATE_TESTS_CRITICAL" != "true" ]; then
|
|
184
|
+
return 0
|
|
185
|
+
fi
|
|
186
|
+
|
|
187
|
+
log_info "Running critical tests..."
|
|
188
|
+
|
|
189
|
+
# Look for critical test markers
|
|
190
|
+
if [ -f "package.json" ] && grep -q '"test:critical"' package.json; then
|
|
191
|
+
if npm run test:critical --silent >/dev/null 2>&1; then
|
|
192
|
+
log_success "Critical tests passed"
|
|
193
|
+
else
|
|
194
|
+
log_error "Critical tests failed"
|
|
195
|
+
return 1
|
|
196
|
+
fi
|
|
197
|
+
elif [ -f "Cargo.toml" ]; then
|
|
198
|
+
# Run tests marked as critical
|
|
199
|
+
if cargo test --quiet critical_ >/dev/null 2>&1; then
|
|
200
|
+
log_success "Critical tests passed"
|
|
201
|
+
else
|
|
202
|
+
log_warning "No critical tests found or they failed"
|
|
203
|
+
fi
|
|
204
|
+
else
|
|
205
|
+
log_info "No critical test configuration found, skipping"
|
|
206
|
+
fi
|
|
207
|
+
|
|
208
|
+
return 0
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
# Save current context before commit
|
|
212
|
+
save_context() {
|
|
213
|
+
if [ "$STACKMEMORY_ENABLED" != "true" ]; then
|
|
214
|
+
return 0
|
|
215
|
+
fi
|
|
216
|
+
|
|
217
|
+
log_info "Saving StackMemory context..."
|
|
218
|
+
|
|
219
|
+
# Get current branch and commit info for context
|
|
220
|
+
local branch=$(git branch --show-current 2>/dev/null || echo "unknown")
|
|
221
|
+
local staged_files=$(git diff --cached --name-only | wc -l | tr -d ' ')
|
|
222
|
+
|
|
223
|
+
# Save context with commit information
|
|
224
|
+
if command -v stackmemory >/dev/null 2>&1; then
|
|
225
|
+
# Create a pre-commit context frame
|
|
226
|
+
stackmemory context add observation "Pre-commit validation on branch '$branch' with $staged_files staged files" >/dev/null 2>&1 || true
|
|
227
|
+
|
|
228
|
+
# Save current state
|
|
229
|
+
stackmemory status >/dev/null 2>&1 || true
|
|
230
|
+
|
|
231
|
+
log_success "Context saved"
|
|
232
|
+
fi
|
|
233
|
+
|
|
234
|
+
return 0
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
# Main execution
|
|
238
|
+
main() {
|
|
239
|
+
log_info "🚀 StackMemory pre-commit hook starting..."
|
|
240
|
+
|
|
241
|
+
# Core checks
|
|
242
|
+
check_stackmemory
|
|
243
|
+
save_context
|
|
244
|
+
|
|
245
|
+
# Validation pipeline
|
|
246
|
+
local failed=false
|
|
247
|
+
|
|
248
|
+
if ! validate_tasks; then
|
|
249
|
+
failed=true
|
|
250
|
+
fi
|
|
251
|
+
|
|
252
|
+
if ! validate_lint; then
|
|
253
|
+
failed=true
|
|
254
|
+
fi
|
|
255
|
+
|
|
256
|
+
if ! validate_types; then
|
|
257
|
+
failed=true
|
|
258
|
+
fi
|
|
259
|
+
|
|
260
|
+
if ! validate_critical_tests; then
|
|
261
|
+
failed=true
|
|
262
|
+
fi
|
|
263
|
+
|
|
264
|
+
if [ "$failed" = "true" ]; then
|
|
265
|
+
log_error "Pre-commit validation failed!"
|
|
266
|
+
log_info "Fix the issues above and try committing again"
|
|
267
|
+
exit 1
|
|
268
|
+
fi
|
|
269
|
+
|
|
270
|
+
log_success "🎉 Pre-commit validation passed!"
|
|
271
|
+
return 0
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
# Run main function
|
|
275
|
+
main "$@"
|