@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.
- package/dist/cli/commands/skills.js +15 -2
- package/dist/cli/commands/skills.js.map +2 -2
- package/dist/cli/index.js +113 -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-manager.js +3 -0
- package/dist/core/context/frame-manager.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/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 +6 -18
- 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.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/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,431 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Enhanced Pre-Clear Context Preservation Hooks
|
|
4
|
+
# Comprehensive session state capture before /clear or /compact
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
echo "๐ง Enhanced Pre-Clear Context Preservation Setup"
|
|
9
|
+
echo "================================================"
|
|
10
|
+
echo ""
|
|
11
|
+
|
|
12
|
+
# Check if StackMemory is installed
|
|
13
|
+
if ! command -v stackmemory &> /dev/null; then
|
|
14
|
+
echo "โ StackMemory is not installed"
|
|
15
|
+
echo "Install with: npm install -g @stackmemoryai/stackmemory"
|
|
16
|
+
exit 1
|
|
17
|
+
fi
|
|
18
|
+
|
|
19
|
+
# Check if in a project directory
|
|
20
|
+
if [ ! -d ".stackmemory" ]; then
|
|
21
|
+
echo "โ ๏ธ StackMemory not initialized in this directory"
|
|
22
|
+
echo "Run: stackmemory init"
|
|
23
|
+
read -p "Initialize now? (y/n): " -n 1 -r
|
|
24
|
+
echo
|
|
25
|
+
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
26
|
+
stackmemory init
|
|
27
|
+
else
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
echo "โ
StackMemory detected"
|
|
33
|
+
echo ""
|
|
34
|
+
|
|
35
|
+
# Create enhanced configuration
|
|
36
|
+
echo "๐ Configuring enhanced pre-clear preservation..."
|
|
37
|
+
|
|
38
|
+
CONFIG_FILE=".stackmemory/config.json"
|
|
39
|
+
if [ ! -f "$CONFIG_FILE" ]; then
|
|
40
|
+
echo '{}' > "$CONFIG_FILE"
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
# Update config with enhanced preservation settings
|
|
44
|
+
node -e "
|
|
45
|
+
const fs = require('fs');
|
|
46
|
+
const config = JSON.parse(fs.readFileSync('$CONFIG_FILE', 'utf8'));
|
|
47
|
+
|
|
48
|
+
// Enhanced clear survival
|
|
49
|
+
config.clearSurvival = {
|
|
50
|
+
...config.clearSurvival,
|
|
51
|
+
enhancedPreservation: true,
|
|
52
|
+
captureLevel: 'comprehensive',
|
|
53
|
+
preserveConversationState: true,
|
|
54
|
+
preserveCognitiveState: true,
|
|
55
|
+
preserveCodeContext: true,
|
|
56
|
+
preserveEnvironmentState: true
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Pre-clear hooks configuration
|
|
60
|
+
config.preClearHooks = {
|
|
61
|
+
captureWorkingState: true,
|
|
62
|
+
captureConversationHistory: true,
|
|
63
|
+
captureCognitiveModel: true,
|
|
64
|
+
captureCodeContext: true,
|
|
65
|
+
captureEnvironmentSnapshot: true,
|
|
66
|
+
generateDifferentialBackup: true,
|
|
67
|
+
createRecoveryPoints: true,
|
|
68
|
+
enableTimestampedBackups: true
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
fs.writeFileSync('$CONFIG_FILE', JSON.stringify(config, null, 2));
|
|
72
|
+
console.log('โ
Enhanced configuration updated');
|
|
73
|
+
"
|
|
74
|
+
|
|
75
|
+
echo ""
|
|
76
|
+
|
|
77
|
+
# Install enhanced Claude Code hooks
|
|
78
|
+
echo "๐ช Installing enhanced Claude Code hooks..."
|
|
79
|
+
|
|
80
|
+
CLAUDE_HOOKS_DIR="$HOME/.claude/hooks"
|
|
81
|
+
mkdir -p "$CLAUDE_HOOKS_DIR"
|
|
82
|
+
|
|
83
|
+
# Enhanced pre-clear hook with comprehensive capture
|
|
84
|
+
cat > "$CLAUDE_HOOKS_DIR/on-pre-clear" << 'EOF'
|
|
85
|
+
#!/bin/bash
|
|
86
|
+
# Enhanced Pre-Clear Context Preservation
|
|
87
|
+
# Captures comprehensive session state before /clear or /compact
|
|
88
|
+
|
|
89
|
+
echo "๐ง Pre-Clear: Capturing comprehensive context..."
|
|
90
|
+
|
|
91
|
+
# Create timestamped backup directory
|
|
92
|
+
TIMESTAMP=$(date "+%Y%m%d_%H%M%S")
|
|
93
|
+
BACKUP_DIR=".stackmemory/pre-clear/backup-$TIMESTAMP"
|
|
94
|
+
mkdir -p "$BACKUP_DIR"
|
|
95
|
+
|
|
96
|
+
# 1. Capture working state
|
|
97
|
+
echo " ๐ Capturing working state..."
|
|
98
|
+
{
|
|
99
|
+
echo "# Working State Snapshot - $(date)"
|
|
100
|
+
echo ""
|
|
101
|
+
echo "## Current Task"
|
|
102
|
+
stackmemory status --current-task 2>/dev/null || echo "No active task"
|
|
103
|
+
echo ""
|
|
104
|
+
echo "## Active Files (Recent)"
|
|
105
|
+
git diff --name-only HEAD~1 2>/dev/null | head -20 || echo "No recent changes"
|
|
106
|
+
echo ""
|
|
107
|
+
echo "## Git Status"
|
|
108
|
+
git status --short 2>/dev/null || echo "Not a git repo"
|
|
109
|
+
echo ""
|
|
110
|
+
echo "## Recent Commands"
|
|
111
|
+
history | tail -20 | cut -c 8- 2>/dev/null || echo "No history available"
|
|
112
|
+
} > "$BACKUP_DIR/working-state.md"
|
|
113
|
+
|
|
114
|
+
# 2. Capture conversation context
|
|
115
|
+
echo " ๐ฌ Capturing conversation context..."
|
|
116
|
+
{
|
|
117
|
+
echo "# Conversation Context - $(date)"
|
|
118
|
+
echo ""
|
|
119
|
+
echo "## Current Session"
|
|
120
|
+
stackmemory handoff --show 2>/dev/null | head -50 || echo "No handoff available"
|
|
121
|
+
echo ""
|
|
122
|
+
echo "## Recent Activity"
|
|
123
|
+
stackmemory log --recent 2>/dev/null | head -20 || echo "No recent activity"
|
|
124
|
+
} > "$BACKUP_DIR/conversation-context.md"
|
|
125
|
+
|
|
126
|
+
# 3. Capture code context
|
|
127
|
+
echo " ๐ป Capturing code context..."
|
|
128
|
+
{
|
|
129
|
+
echo "# Code Context - $(date)"
|
|
130
|
+
echo ""
|
|
131
|
+
echo "## Modified Files Detail"
|
|
132
|
+
if command -v git &> /dev/null; then
|
|
133
|
+
git diff --stat HEAD~5 2>/dev/null | head -30
|
|
134
|
+
echo ""
|
|
135
|
+
echo "## Recent Commit Messages"
|
|
136
|
+
git log --oneline -10 2>/dev/null
|
|
137
|
+
echo ""
|
|
138
|
+
echo "## Branch Information"
|
|
139
|
+
git branch -vv 2>/dev/null | head -10
|
|
140
|
+
fi
|
|
141
|
+
echo ""
|
|
142
|
+
echo "## Project Structure Changes"
|
|
143
|
+
find . -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" -o -name "*.py" \
|
|
144
|
+
-not -path "./node_modules/*" -not -path "./.git/*" \
|
|
145
|
+
-newer .stackmemory/last-clear.timestamp 2>/dev/null | head -20 || \
|
|
146
|
+
find . -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" -o -name "*.py" \
|
|
147
|
+
-not -path "./node_modules/*" -not -path "./.git/*" | head -20
|
|
148
|
+
} > "$BACKUP_DIR/code-context.md"
|
|
149
|
+
|
|
150
|
+
# 4. Capture cognitive state
|
|
151
|
+
echo " ๐ง Capturing cognitive state..."
|
|
152
|
+
{
|
|
153
|
+
echo "# Cognitive State - $(date)"
|
|
154
|
+
echo ""
|
|
155
|
+
echo "## Current Focus"
|
|
156
|
+
stackmemory workflow --status 2>/dev/null || echo "No active workflow"
|
|
157
|
+
echo ""
|
|
158
|
+
echo "## Mental Model"
|
|
159
|
+
echo "- Working on: $(git log --oneline -1 --pretty=format:'%s' 2>/dev/null || echo 'Unknown')"
|
|
160
|
+
echo "- Branch: $(git branch --show-current 2>/dev/null || echo 'unknown')"
|
|
161
|
+
echo "- Last activity: $(date -r .stackmemory/last-activity 2>/dev/null || echo 'unknown')"
|
|
162
|
+
echo ""
|
|
163
|
+
echo "## Pending Actions"
|
|
164
|
+
grep -r "TODO\|FIXME\|XXX\|HACK" . \
|
|
165
|
+
--include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" --include="*.py" \
|
|
166
|
+
--exclude-dir=node_modules --exclude-dir=.git 2>/dev/null | head -10 || echo "No pending actions found"
|
|
167
|
+
echo ""
|
|
168
|
+
echo "## Current Problems/Blockers"
|
|
169
|
+
git grep -n "BUG\|ERROR\|BROKEN" -- "*.ts" "*.tsx" "*.js" "*.jsx" "*.py" 2>/dev/null | head -5 || echo "No known issues"
|
|
170
|
+
} > "$BACKUP_DIR/cognitive-state.md"
|
|
171
|
+
|
|
172
|
+
# 5. Capture environment snapshot
|
|
173
|
+
echo " ๐ Capturing environment snapshot..."
|
|
174
|
+
{
|
|
175
|
+
echo "# Environment Snapshot - $(date)"
|
|
176
|
+
echo ""
|
|
177
|
+
echo "## Working Directory"
|
|
178
|
+
echo "Path: $(pwd)"
|
|
179
|
+
echo "Files: $(find . -maxdepth 2 -type f | wc -l) files, $(find . -maxdepth 2 -type d | wc -l) directories"
|
|
180
|
+
echo ""
|
|
181
|
+
echo "## Package Information"
|
|
182
|
+
if [ -f "package.json" ]; then
|
|
183
|
+
echo "### package.json"
|
|
184
|
+
jq '.name, .version, .main, .scripts' package.json 2>/dev/null || cat package.json | head -20
|
|
185
|
+
fi
|
|
186
|
+
if [ -f "requirements.txt" ]; then
|
|
187
|
+
echo "### requirements.txt"
|
|
188
|
+
head -20 requirements.txt
|
|
189
|
+
fi
|
|
190
|
+
if [ -f "Cargo.toml" ]; then
|
|
191
|
+
echo "### Cargo.toml"
|
|
192
|
+
head -20 Cargo.toml
|
|
193
|
+
fi
|
|
194
|
+
echo ""
|
|
195
|
+
echo "## Environment Variables (Safe)"
|
|
196
|
+
env | grep -E "NODE_ENV|DEBUG|PORT" | head -10 2>/dev/null || echo "No relevant env vars"
|
|
197
|
+
} > "$BACKUP_DIR/environment.md"
|
|
198
|
+
|
|
199
|
+
# 6. Save StackMemory state
|
|
200
|
+
echo " ๐ Saving StackMemory state..."
|
|
201
|
+
stackmemory clear --save 2>/dev/null || echo "Failed to save clear state"
|
|
202
|
+
stackmemory handoff --generate 2>/dev/null || echo "Failed to generate handoff"
|
|
203
|
+
|
|
204
|
+
# 7. Create comprehensive summary
|
|
205
|
+
echo " ๐ Creating comprehensive summary..."
|
|
206
|
+
{
|
|
207
|
+
echo "# Pre-Clear Comprehensive Summary"
|
|
208
|
+
echo "Generated: $(date)"
|
|
209
|
+
echo "Trigger: ${CLEAR_TRIGGER:-manual}"
|
|
210
|
+
echo ""
|
|
211
|
+
echo "## Session Overview"
|
|
212
|
+
echo "- Directory: $(pwd)"
|
|
213
|
+
echo "- Git branch: $(git branch --show-current 2>/dev/null || echo 'unknown')"
|
|
214
|
+
echo "- Files changed: $(git diff --name-only | wc -l) unstaged, $(git diff --cached --name-only | wc -l) staged"
|
|
215
|
+
echo "- Last commit: $(git log --oneline -1 2>/dev/null || echo 'unknown')"
|
|
216
|
+
echo ""
|
|
217
|
+
echo "## Context Statistics"
|
|
218
|
+
echo "- Backup size: $(du -sh "$BACKUP_DIR" | cut -f1)"
|
|
219
|
+
echo "- Files backed up: $(find "$BACKUP_DIR" -type f | wc -l)"
|
|
220
|
+
echo "- Timestamp: $TIMESTAMP"
|
|
221
|
+
echo ""
|
|
222
|
+
echo "## Recovery Instructions"
|
|
223
|
+
echo "1. After /clear, run: stackmemory clear --restore"
|
|
224
|
+
echo "2. Review context: cat $BACKUP_DIR/*.md"
|
|
225
|
+
echo "3. Resume work from: $(git branch --show-current 2>/dev/null || pwd)"
|
|
226
|
+
echo ""
|
|
227
|
+
echo "## Quick Recovery Commands"
|
|
228
|
+
echo "\`\`\`bash"
|
|
229
|
+
echo "# Restore StackMemory state"
|
|
230
|
+
echo "stackmemory clear --restore"
|
|
231
|
+
echo ""
|
|
232
|
+
echo "# Review what you were working on"
|
|
233
|
+
echo "cat $BACKUP_DIR/working-state.md"
|
|
234
|
+
echo "cat $BACKUP_DIR/cognitive-state.md"
|
|
235
|
+
echo ""
|
|
236
|
+
echo "# Continue from where you left off"
|
|
237
|
+
echo "git status"
|
|
238
|
+
echo "stackmemory workflow --status"
|
|
239
|
+
echo "\`\`\`"
|
|
240
|
+
} > "$BACKUP_DIR/RECOVERY_GUIDE.md"
|
|
241
|
+
|
|
242
|
+
# 8. Create recovery timestamp
|
|
243
|
+
touch .stackmemory/last-clear.timestamp
|
|
244
|
+
|
|
245
|
+
# 9. Update activity tracker
|
|
246
|
+
stackmemory monitor --activity 2>/dev/null || echo "timestamp:$(date)" > .stackmemory/last-activity
|
|
247
|
+
|
|
248
|
+
echo ""
|
|
249
|
+
echo "โ
Comprehensive context captured in: $BACKUP_DIR"
|
|
250
|
+
echo "๐ Recovery guide: $BACKUP_DIR/RECOVERY_GUIDE.md"
|
|
251
|
+
echo ""
|
|
252
|
+
echo "๐ Ready for /clear - context will be restored automatically"
|
|
253
|
+
echo "๐ก After /clear, run: stackmemory clear --restore"
|
|
254
|
+
echo ""
|
|
255
|
+
EOF
|
|
256
|
+
chmod +x "$CLAUDE_HOOKS_DIR/on-pre-clear"
|
|
257
|
+
|
|
258
|
+
# Enhanced post-clear restoration hook
|
|
259
|
+
cat > "$CLAUDE_HOOKS_DIR/on-post-clear" << 'EOF'
|
|
260
|
+
#!/bin/bash
|
|
261
|
+
# Enhanced Post-Clear Context Restoration
|
|
262
|
+
# Restores comprehensive session state after /clear
|
|
263
|
+
|
|
264
|
+
echo "๐ Post-Clear: Restoring comprehensive context..."
|
|
265
|
+
|
|
266
|
+
# Find the most recent backup
|
|
267
|
+
LATEST_BACKUP=$(find .stackmemory/pre-clear -name "backup-*" -type d | sort | tail -1)
|
|
268
|
+
|
|
269
|
+
if [ -z "$LATEST_BACKUP" ]; then
|
|
270
|
+
echo "โ ๏ธ No pre-clear backup found"
|
|
271
|
+
echo "๐ก Make sure to run pre-clear hooks before using /clear"
|
|
272
|
+
exit 1
|
|
273
|
+
fi
|
|
274
|
+
|
|
275
|
+
echo "๐ Found backup: $(basename "$LATEST_BACKUP")"
|
|
276
|
+
|
|
277
|
+
# 1. Restore StackMemory state
|
|
278
|
+
echo " ๐ Restoring StackMemory state..."
|
|
279
|
+
stackmemory clear --restore 2>/dev/null && echo " โ
Clear state restored" || echo " โ ๏ธ Clear state restoration failed"
|
|
280
|
+
stackmemory handoff --load 2>/dev/null && echo " โ
Handoff loaded" || echo " โ ๏ธ Handoff load failed"
|
|
281
|
+
|
|
282
|
+
# 2. Display recovery information
|
|
283
|
+
echo ""
|
|
284
|
+
echo "๐ง Context Recovery Summary:"
|
|
285
|
+
echo ""
|
|
286
|
+
|
|
287
|
+
# Show working state
|
|
288
|
+
if [ -f "$LATEST_BACKUP/working-state.md" ]; then
|
|
289
|
+
echo "๐ Working State:"
|
|
290
|
+
grep -A 5 "## Current Task" "$LATEST_BACKUP/working-state.md" | tail -n +2
|
|
291
|
+
echo ""
|
|
292
|
+
fi
|
|
293
|
+
|
|
294
|
+
# Show cognitive state
|
|
295
|
+
if [ -f "$LATEST_BACKUP/cognitive-state.md" ]; then
|
|
296
|
+
echo "๐ง Mental Model:"
|
|
297
|
+
grep -A 5 "## Current Focus" "$LATEST_BACKUP/cognitive-state.md" | tail -n +2
|
|
298
|
+
echo ""
|
|
299
|
+
fi
|
|
300
|
+
|
|
301
|
+
# Show code context
|
|
302
|
+
if [ -f "$LATEST_BACKUP/code-context.md" ]; then
|
|
303
|
+
echo "๐ป Code Context:"
|
|
304
|
+
echo " Modified files:"
|
|
305
|
+
grep -A 10 "## Modified Files Detail" "$LATEST_BACKUP/code-context.md" | tail -n +2 | head -5
|
|
306
|
+
echo ""
|
|
307
|
+
fi
|
|
308
|
+
|
|
309
|
+
# 3. Show recovery guide
|
|
310
|
+
echo "๐ Full Recovery Guide: $LATEST_BACKUP/RECOVERY_GUIDE.md"
|
|
311
|
+
echo ""
|
|
312
|
+
echo "๐ฏ Quick Actions:"
|
|
313
|
+
echo " 1. Review context: cat $LATEST_BACKUP/*.md"
|
|
314
|
+
echo " 2. Check git status: git status"
|
|
315
|
+
echo " 3. Resume workflow: stackmemory workflow --status"
|
|
316
|
+
echo ""
|
|
317
|
+
|
|
318
|
+
# 4. Auto-restore workflow if available
|
|
319
|
+
if command -v stackmemory >/dev/null 2>&1; then
|
|
320
|
+
echo "๐ Auto-restoring workflow state..."
|
|
321
|
+
stackmemory workflow --status 2>/dev/null || echo " No active workflow to restore"
|
|
322
|
+
fi
|
|
323
|
+
|
|
324
|
+
echo "โ
Context restoration complete"
|
|
325
|
+
echo "๐ก Review backup files for detailed context"
|
|
326
|
+
EOF
|
|
327
|
+
chmod +x "$CLAUDE_HOOKS_DIR/on-post-clear"
|
|
328
|
+
|
|
329
|
+
# Enhanced clear command interceptor
|
|
330
|
+
cat > "$CLAUDE_HOOKS_DIR/on-command-clear" << 'EOF'
|
|
331
|
+
#!/bin/bash
|
|
332
|
+
# Enhanced Clear Command Interceptor
|
|
333
|
+
# Triggers comprehensive preservation before /clear
|
|
334
|
+
|
|
335
|
+
echo "๐ Intercepting /clear command..."
|
|
336
|
+
|
|
337
|
+
# Set trigger environment variable
|
|
338
|
+
export CLEAR_TRIGGER="command_clear"
|
|
339
|
+
|
|
340
|
+
# Run pre-clear preservation
|
|
341
|
+
if [ -f "$HOME/.claude/hooks/on-pre-clear" ]; then
|
|
342
|
+
"$HOME/.claude/hooks/on-pre-clear"
|
|
343
|
+
else
|
|
344
|
+
echo "โ ๏ธ Pre-clear hook not found"
|
|
345
|
+
# Fallback to basic preservation
|
|
346
|
+
stackmemory clear --save 2>/dev/null || echo "Failed to save state"
|
|
347
|
+
stackmemory handoff --generate 2>/dev/null || echo "Failed to generate handoff"
|
|
348
|
+
fi
|
|
349
|
+
|
|
350
|
+
echo ""
|
|
351
|
+
echo "โ
Ready for /clear"
|
|
352
|
+
echo "๐ After /clear, restoration will run automatically"
|
|
353
|
+
EOF
|
|
354
|
+
chmod +x "$CLAUDE_HOOKS_DIR/on-command-clear"
|
|
355
|
+
|
|
356
|
+
# Enhanced compact interceptor
|
|
357
|
+
cat > "$CLAUDE_HOOKS_DIR/on-command-compact" << 'EOF'
|
|
358
|
+
#!/bin/bash
|
|
359
|
+
# Enhanced Compact Command Interceptor
|
|
360
|
+
# Handles /compact operations with preservation
|
|
361
|
+
|
|
362
|
+
echo "๐๏ธ Intercepting /compact command..."
|
|
363
|
+
|
|
364
|
+
# Set trigger environment variable
|
|
365
|
+
export CLEAR_TRIGGER="command_compact"
|
|
366
|
+
|
|
367
|
+
# Compact is similar to clear but may preserve more recent context
|
|
368
|
+
# Run enhanced preservation
|
|
369
|
+
if [ -f "$HOME/.claude/hooks/on-pre-clear" ]; then
|
|
370
|
+
"$HOME/.claude/hooks/on-pre-clear"
|
|
371
|
+
else
|
|
372
|
+
echo "โ ๏ธ Pre-clear hook not found"
|
|
373
|
+
stackmemory clear --save 2>/dev/null || echo "Failed to save state"
|
|
374
|
+
fi
|
|
375
|
+
|
|
376
|
+
echo ""
|
|
377
|
+
echo "โ
Ready for /compact"
|
|
378
|
+
echo "๐ Context will be preserved and available for restoration"
|
|
379
|
+
EOF
|
|
380
|
+
chmod +x "$CLAUDE_HOOKS_DIR/on-command-compact"
|
|
381
|
+
|
|
382
|
+
echo "โ
Enhanced Claude Code hooks installed"
|
|
383
|
+
echo ""
|
|
384
|
+
|
|
385
|
+
# Test the enhanced preservation system
|
|
386
|
+
echo "๐งช Testing enhanced preservation..."
|
|
387
|
+
|
|
388
|
+
if [ -f "$CLAUDE_HOOKS_DIR/on-pre-clear" ]; then
|
|
389
|
+
echo "Running test preservation..."
|
|
390
|
+
export CLEAR_TRIGGER="test"
|
|
391
|
+
"$CLAUDE_HOOKS_DIR/on-pre-clear" >/dev/null 2>&1
|
|
392
|
+
|
|
393
|
+
if [ -d ".stackmemory/pre-clear" ]; then
|
|
394
|
+
BACKUP_COUNT=$(find .stackmemory/pre-clear -name "backup-*" -type d | wc -l)
|
|
395
|
+
echo "โ
Test successful - $BACKUP_COUNT backup(s) created"
|
|
396
|
+
else
|
|
397
|
+
echo "โ ๏ธ Test failed - no backup directory created"
|
|
398
|
+
fi
|
|
399
|
+
else
|
|
400
|
+
echo "โ Test failed - hook not installed"
|
|
401
|
+
fi
|
|
402
|
+
|
|
403
|
+
echo ""
|
|
404
|
+
echo "โ
Enhanced Pre-Clear Context Preservation Setup Complete!"
|
|
405
|
+
echo ""
|
|
406
|
+
echo "๐ What's been configured:"
|
|
407
|
+
echo " โข Comprehensive working state capture"
|
|
408
|
+
echo " โข Conversation context preservation"
|
|
409
|
+
echo " โข Code context and git state backup"
|
|
410
|
+
echo " โข Cognitive state and mental model capture"
|
|
411
|
+
echo " โข Environment snapshot"
|
|
412
|
+
echo " โข Timestamped recovery points"
|
|
413
|
+
echo ""
|
|
414
|
+
echo "๐ช Enhanced hooks installed:"
|
|
415
|
+
echo " ~/.claude/hooks/on-pre-clear # Comprehensive preservation"
|
|
416
|
+
echo " ~/.claude/hooks/on-post-clear # Auto-restoration"
|
|
417
|
+
echo " ~/.claude/hooks/on-command-clear # /clear interceptor"
|
|
418
|
+
echo " ~/.claude/hooks/on-command-compact # /compact interceptor"
|
|
419
|
+
echo ""
|
|
420
|
+
echo "๐ฏ Usage:"
|
|
421
|
+
echo " โข Context automatically preserved before /clear or /compact"
|
|
422
|
+
echo " โข Auto-restoration after context reset"
|
|
423
|
+
echo " โข Manual trigger: ~/.claude/hooks/on-pre-clear"
|
|
424
|
+
echo " โข View backups: ls .stackmemory/pre-clear/"
|
|
425
|
+
echo ""
|
|
426
|
+
echo "๐ก The system captures comprehensive session state including:"
|
|
427
|
+
echo " โข What you were working on"
|
|
428
|
+
echo " โข Code changes and git status"
|
|
429
|
+
echo " โข Conversation history and context"
|
|
430
|
+
echo " โข Mental model and cognitive state"
|
|
431
|
+
echo " โข Environment and project configuration"
|