Skip to content

Commit ef386de

Browse files
fix(init): fix initialization scripts for out-of-box usage
- Add scripts/*.ts to esbuild so npm run init/status work - Fix MCP server path to dist/integrations/mcp/server.js - Fix MCP config path with platform detection (macOS vs Linux) - Fix install.sh to delegate to real CLI instead of embedded shim - Copy scripts/ and esbuild.config.js during global install - Fix mcp:start script path in package.json - Update status.ts to match actual database schema Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 32aa734 commit ef386de

5 files changed

Lines changed: 150 additions & 117 deletions

File tree

esbuild.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@ import esbuild from 'esbuild';
33
import { glob } from 'glob';
44

55
// Get all TypeScript files except tests
6-
const entryPoints = glob.sync('src/**/*.ts', {
6+
const srcEntries = glob.sync('src/**/*.ts', {
77
ignore: ['**/*.test.ts', '**/*.spec.ts', '**/__tests__/**'],
88
});
99

10+
// Get script files
11+
const scriptEntries = glob.sync('scripts/*.ts', {
12+
ignore: ['**/*.test.ts', '**/*.spec.ts'],
13+
});
14+
15+
const entryPoints = [...srcEntries, ...scriptEntries];
16+
1017
// ESM polyfill for __dirname and __filename
1118
const esmBanner = `import { fileURLToPath as __fileURLToPath } from 'url';
1219
import { dirname as __pathDirname } from 'path';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"prepublishOnly": "npm run build && npm run test:pre-publish",
6565
"quality": "npm run lint && npm run test:run && npm run build",
6666
"dev": "tsx watch src/mcp/mcp-server.ts",
67-
"mcp:start": "node dist/src/integrations/mcp/server.js",
67+
"mcp:start": "node dist/integrations/mcp/server.js",
6868
"mcp:dev": "tsx src/mcp/mcp-server.ts",
6969
"status": "node dist/scripts/status.js",
7070
"linear:sync": "node scripts/sync-linear-graphql.js",

scripts/initialize.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,28 @@ if (!existsSync(jsonlPath)) {
8383
}
8484

8585
// 5. Create MCP config for Claude Code
86-
const mcpConfigPath = join(
87-
process.env['HOME'] || '~',
88-
'.config',
89-
'claude',
90-
'mcp.json'
91-
);
86+
const isMacOS = process.platform === 'darwin';
87+
const mcpConfigPath = isMacOS
88+
? join(
89+
process.env['HOME'] || '~',
90+
'Library',
91+
'Application Support',
92+
'Claude',
93+
'claude_desktop_config.json'
94+
)
95+
: join(
96+
process.env['HOME'] || '~',
97+
'.config',
98+
'claude',
99+
'claude_desktop_config.json'
100+
);
92101
console.log(chalk.blue('\n📝 MCP Configuration for Claude Code:\n'));
93102

94103
const mcpConfig = {
95104
mcpServers: {
96105
stackmemory: {
97106
command: 'node',
98-
args: [join(projectRoot, 'dist', 'mcp-server.js')],
107+
args: [join(projectRoot, 'dist', 'integrations', 'mcp', 'server.js')],
99108
env: {
100109
PROJECT_ROOT: projectRoot,
101110
},

scripts/install.sh

Lines changed: 14 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ mkdir -p "$INSTALL_DIR"
4343

4444
# Copy all necessary files
4545
cp -r "$CURRENT_DIR/src" "$INSTALL_DIR/" 2>/dev/null || true
46-
cp -r "$CURRENT_DIR/attention-scoring" "$INSTALL_DIR/" 2>/dev/null || true
46+
cp -r "$CURRENT_DIR/scripts" "$INSTALL_DIR/" 2>/dev/null || true
47+
cp -r "$CURRENT_DIR/attention-scoring" "$INSTALL_DIR/" 2>/dev/null || true
4748
cp -r "$CURRENT_DIR/p2p-sync" "$INSTALL_DIR/" 2>/dev/null || true
4849
cp "$CURRENT_DIR/package.json" "$INSTALL_DIR/"
4950
cp "$CURRENT_DIR/tsconfig.json" "$INSTALL_DIR/"
51+
cp "$CURRENT_DIR/esbuild.config.js" "$INSTALL_DIR/"
5052

5153
# 2. Install dependencies
5254
echo -e "${GREEN}[2/5]${NC} Installing dependencies..."
@@ -90,7 +92,7 @@ for CONFIG_DIR in "$MCP_CONFIG_DIR" "$ALT_MCP_DIR"; do
9092
9193
config.mcpServers.stackmemory = {
9294
command: 'node',
93-
args: ['$INSTALL_DIR/dist/src/mcp-server.js'],
95+
args: ['$INSTALL_DIR/dist/integrations/mcp/server.js'],
9496
env: {
9597
STACKMEMORY_GLOBAL: 'true'
9698
}
@@ -106,7 +108,7 @@ for CONFIG_DIR in "$MCP_CONFIG_DIR" "$ALT_MCP_DIR"; do
106108
"mcpServers": {
107109
"stackmemory": {
108110
"command": "node",
109-
"args": ["$INSTALL_DIR/dist/src/mcp-server.js"],
111+
"args": ["$INSTALL_DIR/dist/integrations/mcp/server.js"],
110112
"env": {
111113
"STACKMEMORY_GLOBAL": "true"
112114
}
@@ -124,75 +126,25 @@ echo -e "${GREEN}[5/5]${NC} Creating global command..."
124126
# Create bin directory if it doesn't exist
125127
mkdir -p "$HOME/.local/bin"
126128

127-
# Create the global stackmemory command
129+
# Create the global stackmemory command - delegates to the real CLI
128130
cat > "$HOME/.local/bin/stackmemory" << 'EOF'
129131
#!/usr/bin/env node
130132
131133
const { spawn } = require('child_process');
132134
const path = require('path');
133-
const fs = require('fs');
134135
const os = require('os');
135136
136137
const installDir = path.join(os.homedir(), '.stackmemory');
137-
const mcpServer = path.join(installDir, 'dist', 'src', 'mcp-server.js');
138-
139-
// Check if we're in a git repo
140-
function isGitRepo() {
141-
try {
142-
require('child_process').execSync('git rev-parse --git-dir', { stdio: 'ignore' });
143-
return true;
144-
} catch (e) {
145-
return false;
146-
}
147-
}
138+
const cliPath = path.join(installDir, 'dist', 'cli', 'index.js');
148139
149-
// Auto-initialize if in git repo
150-
if (isGitRepo() && !fs.existsSync('.stackmemory')) {
151-
console.log('🎯 Initializing StackMemory in this repository...');
152-
153-
fs.mkdirSync('.stackmemory', { recursive: true });
154-
155-
const config = {
156-
projectId: path.basename(process.cwd()),
157-
userId: process.env.USER || 'default',
158-
initialized: new Date().toISOString()
159-
};
160-
161-
fs.writeFileSync('.stackmemory/config.json', JSON.stringify(config, null, 2));
162-
fs.writeFileSync('.stackmemory/frames.jsonl', '');
163-
164-
// Add to .gitignore
165-
if (fs.existsSync('.gitignore')) {
166-
const gitignore = fs.readFileSync('.gitignore', 'utf8');
167-
if (!gitignore.includes('.stackmemory')) {
168-
fs.appendFileSync('.gitignore', '\n# StackMemory\n.stackmemory/*.db\n.stackmemory/*.db-*\n');
169-
}
170-
}
171-
172-
console.log('✅ StackMemory initialized!');
173-
}
140+
// Pass all arguments to the real CLI
141+
const args = process.argv.slice(2);
142+
const child = spawn('node', [cliPath, ...args], {
143+
env: { ...process.env, PROJECT_ROOT: process.cwd() },
144+
stdio: 'inherit'
145+
});
174146
175-
// Handle commands
176-
const command = process.argv[2];
177-
178-
switch(command) {
179-
case 'init':
180-
// Already handled above
181-
break;
182-
case 'status':
183-
require(path.join(installDir, 'dist', 'scripts', 'status.js'));
184-
break;
185-
case 'test':
186-
require(path.join(installDir, 'dist', 'test', 'test-framework.js'));
187-
break;
188-
default:
189-
// Start MCP server
190-
const child = spawn('node', [mcpServer], {
191-
env: { ...process.env, PROJECT_ROOT: process.cwd() },
192-
stdio: 'inherit'
193-
});
194-
child.on('exit', code => process.exit(code));
195-
}
147+
child.on('exit', code => process.exit(code || 0));
196148
EOF
197149

198150
chmod +x "$HOME/.local/bin/stackmemory"

0 commit comments

Comments
 (0)