-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·187 lines (157 loc) · 5.3 KB
/
install.sh
File metadata and controls
executable file
·187 lines (157 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# StackMemory Universal Installer
# Works across ALL Claude Code instances automatically
set -e
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${BLUE}🚀 StackMemory Universal Installer${NC}\n"
# Detect OS
OS="unknown"
if [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
else
echo -e "${RED}Unsupported OS: $OSTYPE${NC}"
exit 1
fi
# Set paths based on OS
if [ "$OS" = "macos" ]; then
MCP_CONFIG_DIR="$HOME/Library/Application Support/Claude"
ALT_MCP_DIR="$HOME/.config/claude"
elif [ "$OS" = "linux" ]; then
MCP_CONFIG_DIR="$HOME/.config/claude"
ALT_MCP_DIR="$HOME/.local/share/claude"
fi
INSTALL_DIR="$HOME/.stackmemory"
CURRENT_DIR="$(pwd)"
echo -e "${YELLOW}Installing StackMemory globally...${NC}\n"
# 1. Install to home directory
echo -e "${GREEN}[1/5]${NC} Setting up StackMemory in $INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
# Copy all necessary files
cp -r "$CURRENT_DIR/src" "$INSTALL_DIR/" 2>/dev/null || true
cp -r "$CURRENT_DIR/scripts" "$INSTALL_DIR/" 2>/dev/null || true
cp -r "$CURRENT_DIR/attention-scoring" "$INSTALL_DIR/" 2>/dev/null || true
cp -r "$CURRENT_DIR/p2p-sync" "$INSTALL_DIR/" 2>/dev/null || true
cp "$CURRENT_DIR/package.json" "$INSTALL_DIR/"
cp "$CURRENT_DIR/tsconfig.json" "$INSTALL_DIR/"
cp "$CURRENT_DIR/esbuild.config.js" "$INSTALL_DIR/"
# 2. Install dependencies
echo -e "${GREEN}[2/5]${NC} Installing dependencies..."
cd "$INSTALL_DIR"
npm install --silent --production 2>/dev/null || npm install --production
# 3. Build TypeScript
echo -e "${GREEN}[3/5]${NC} Building TypeScript files..."
npm run build --silent 2>/dev/null || npm run build
# 4. Create global MCP config
echo -e "${GREEN}[4/5]${NC} Configuring Claude Code MCP..."
# Try both possible config directories
for CONFIG_DIR in "$MCP_CONFIG_DIR" "$ALT_MCP_DIR"; do
if [ ! -d "$CONFIG_DIR" ]; then
mkdir -p "$CONFIG_DIR"
fi
MCP_CONFIG="$CONFIG_DIR/claude_desktop_config.json"
# Create or update MCP configuration
if [ -f "$MCP_CONFIG" ]; then
# Backup existing
cp "$MCP_CONFIG" "$MCP_CONFIG.backup.$(date +%s)"
# Parse and update existing config
node -e "
const fs = require('fs');
const configPath = '$MCP_CONFIG';
let config = {};
try {
config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
} catch (e) {
config = {};
}
if (!config.mcpServers) {
config.mcpServers = {};
}
config.mcpServers.stackmemory = {
command: 'node',
args: ['$INSTALL_DIR/dist/integrations/mcp/server.js'],
env: {
STACKMEMORY_GLOBAL: 'true'
}
};
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
console.log('✓ Updated MCP config at ' + configPath);
"
else
# Create new config
cat > "$MCP_CONFIG" << EOF
{
"mcpServers": {
"stackmemory": {
"command": "node",
"args": ["$INSTALL_DIR/dist/integrations/mcp/server.js"],
"env": {
"STACKMEMORY_GLOBAL": "true"
}
}
}
}
EOF
echo -e "✓ Created MCP config at $MCP_CONFIG"
fi
done
# 5. Create command-line tool
echo -e "${GREEN}[5/5]${NC} Creating global command..."
# Create bin directory if it doesn't exist
mkdir -p "$HOME/.local/bin"
# Create the global stackmemory command - delegates to the real CLI
cat > "$HOME/.local/bin/stackmemory" << 'EOF'
#!/usr/bin/env node
const { spawn } = require('child_process');
const path = require('path');
const os = require('os');
const installDir = path.join(os.homedir(), '.stackmemory');
const cliPath = path.join(installDir, 'dist', 'cli', 'index.js');
// Pass all arguments to the real CLI
const args = process.argv.slice(2);
const child = spawn('node', [cliPath, ...args], {
env: { ...process.env, PROJECT_ROOT: process.cwd() },
stdio: 'inherit'
});
child.on('exit', code => process.exit(code || 0));
EOF
chmod +x "$HOME/.local/bin/stackmemory"
# Add to PATH if not already there
add_to_path() {
local shell_rc="$1"
if [ -f "$shell_rc" ]; then
if ! grep -q "/.local/bin" "$shell_rc"; then
echo '' >> "$shell_rc"
echo '# StackMemory' >> "$shell_rc"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$shell_rc"
echo -e "✓ Added to PATH in $shell_rc"
fi
fi
}
add_to_path "$HOME/.bashrc"
add_to_path "$HOME/.zshrc"
add_to_path "$HOME/.bash_profile"
echo ""
echo -e "${GREEN}✅ StackMemory installed successfully!${NC}"
echo ""
echo -e "${BLUE}🎯 Installation Complete:${NC}"
echo " • Global MCP server configured for Claude Code"
echo " • Command 'stackmemory' available globally"
echo " • Auto-detects git repositories"
echo ""
echo -e "${YELLOW}⚠️ Required Actions:${NC}"
echo " 1. Restart Claude Code to load the MCP server"
echo " 2. Run: source ~/.bashrc (or restart terminal)"
echo ""
echo -e "${GREEN}📝 Test Installation:${NC}"
echo " cd any-git-repo"
echo " stackmemory init # Initialize in repo"
echo " stackmemory status # Check status"
echo " stackmemory test # Run test suite"
echo ""
echo -e "${BLUE}The MCP server is now available in ALL Claude Code instances!${NC}"