@stackmemoryai/stackmemory 0.5.61 → 0.5.62

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.
@@ -13,6 +13,9 @@ import {
13
13
  import { join } from 'path';
14
14
  import { execSync } from 'child_process';
15
15
  import chalk from 'chalk';
16
+
17
+ // Parse CLI args for --with-diffmem flag
18
+ const enableDiffMem = process.argv.includes('--with-diffmem');
16
19
  // Type-safe environment variable access
17
20
  function getEnv(key: string, defaultValue?: string): string {
18
21
  const value = process.env[key];
@@ -125,14 +128,93 @@ try {
125
128
  console.log(chalk.yellow('⚠') + ' Build failed - run npm run build manually');
126
129
  }
127
130
 
131
+ // 7. Optional: Initialize DiffMem for long-term user memory
132
+ if (enableDiffMem) {
133
+ console.log(chalk.blue('\n🧠 Setting up DiffMem integration...\n'));
134
+
135
+ const diffmemDir = join(stackDir, 'diffmem');
136
+ const diffmemStorageDir = join(diffmemDir, 'storage');
137
+ const diffmemWorktreesDir = join(diffmemDir, 'worktrees');
138
+
139
+ // Create DiffMem directories
140
+ mkdirSync(diffmemStorageDir, { recursive: true });
141
+ mkdirSync(diffmemWorktreesDir, { recursive: true });
142
+
143
+ // Initialize git repo for storage
144
+ if (!existsSync(join(diffmemStorageDir, '.git'))) {
145
+ try {
146
+ execSync('git init', { cwd: diffmemStorageDir, stdio: 'pipe' });
147
+ execSync('git commit --allow-empty -m "Initialize DiffMem storage"', {
148
+ cwd: diffmemStorageDir,
149
+ stdio: 'pipe',
150
+ });
151
+ console.log(chalk.green('āœ“') + ' Initialized DiffMem storage repository');
152
+ } catch {
153
+ console.log(
154
+ chalk.yellow('⚠') + ' Failed to initialize git repo for DiffMem'
155
+ );
156
+ }
157
+ }
158
+
159
+ // Create DiffMem config
160
+ const diffmemConfigPath = join(diffmemDir, 'config.json');
161
+ const diffmemConfig = {
162
+ enabled: true,
163
+ endpoint: 'http://localhost:8000',
164
+ userId: process.env['USER'] || 'default',
165
+ storagePath: diffmemStorageDir,
166
+ worktreePath: diffmemWorktreesDir,
167
+ };
168
+ writeFileSync(diffmemConfigPath, JSON.stringify(diffmemConfig, null, 2));
169
+ console.log(chalk.green('āœ“') + ' Created DiffMem configuration');
170
+
171
+ // Add DiffMem env vars to .env file
172
+ const envPath = join(projectRoot, '.env');
173
+ const diffmemEnvVars = `
174
+ # DiffMem Configuration (Long-term User Memory)
175
+ DIFFMEM_ENABLED=true
176
+ DIFFMEM_ENDPOINT=http://localhost:8000
177
+ DIFFMEM_USER_ID=${process.env['USER'] || 'default'}
178
+ DIFFMEM_STORAGE_PATH=${diffmemStorageDir}
179
+ DIFFMEM_WORKTREE_PATH=${diffmemWorktreesDir}
180
+ `;
181
+
182
+ if (existsSync(envPath)) {
183
+ const envContent = readFileSync(envPath, 'utf-8');
184
+ if (!envContent.includes('DIFFMEM_')) {
185
+ appendFileSync(envPath, diffmemEnvVars);
186
+ console.log(chalk.green('āœ“') + ' Added DiffMem configuration to .env');
187
+ }
188
+ } else {
189
+ writeFileSync(envPath, diffmemEnvVars.trim() + '\n');
190
+ console.log(chalk.green('āœ“') + ' Created .env with DiffMem configuration');
191
+ }
192
+
193
+ console.log(chalk.green('āœ“') + ' DiffMem integration configured');
194
+ console.log(
195
+ chalk.gray(
196
+ ' Note: DiffMem server must be running for user memory features'
197
+ )
198
+ );
199
+ }
200
+
128
201
  console.log(chalk.green.bold('\nāœ… StackMemory initialized successfully!\n'));
129
202
  console.log(chalk.gray('Next steps:'));
130
203
  console.log(chalk.gray('1. Add the MCP configuration above to Claude Code'));
131
204
  console.log(chalk.gray('2. Restart Claude Code'));
132
205
  console.log(chalk.gray('3. Start using context tracking!'));
206
+ if (enableDiffMem) {
207
+ console.log(chalk.gray('4. Start DiffMem server: npm run diffmem:start'));
208
+ }
133
209
  console.log(chalk.gray('\nUseful commands:'));
134
210
  console.log(
135
211
  chalk.cyan(' npm run mcp:dev') + ' - Start MCP server in dev mode'
136
212
  );
137
213
  console.log(chalk.cyan(' npm run status') + ' - Check StackMemory status');
138
- console.log(chalk.cyan(' npm run analyze') + ' - Analyze context usage\n');
214
+ console.log(chalk.cyan(' npm run analyze') + ' - Analyze context usage');
215
+ if (enableDiffMem) {
216
+ console.log(
217
+ chalk.cyan(' npm run diffmem:start') + ' - Start DiffMem server'
218
+ );
219
+ }
220
+ console.log();