specmem-hardwicksoftware 3.7.0 → 3.7.1

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.
@@ -41,27 +41,72 @@ const HOOKS_DIR = path.join(CLAUDE_CONFIG_DIR, 'hooks');
41
41
  const COMMANDS_DIR = path.join(CLAUDE_CONFIG_DIR, 'commands');
42
42
  // stores per-project MCP configs in ~/.claude.json under "projects" key
43
43
  const CLAUDE_JSON_PATH = path.join(HOME_DIR, '.claude.json');
44
- // SpecMem directory detection - works from both src/ and dist/
44
+ // SpecMem directory detection - dynamically resolves from how specmem was launched
45
+ // Handles bootstrap.cjs AND bootstrap.js, works with ANY install location
46
+ function hasBootstrap(dir) {
47
+ return fs.existsSync(path.join(dir, 'bootstrap.cjs')) ||
48
+ fs.existsSync(path.join(dir, 'bootstrap.js'));
49
+ }
45
50
  function getSpecmemRoot() {
46
- // Check environment variable first
47
- if (process.env.SPECMEM_ROOT) {
51
+ // 1. Check environment variable (explicit override)
52
+ if (process.env.SPECMEM_ROOT && hasBootstrap(process.env.SPECMEM_ROOT)) {
48
53
  return process.env.SPECMEM_ROOT;
49
54
  }
50
- // Try to detect from current file location
51
- // When compiled: dist/init/claudeConfigInjector.js -> need to go up 2 levels
52
- // When in src: src/init/claudeConfigInjector.ts -> need to go up 2 levels
53
- const currentDir = __dirname;
54
- const possibleRoot = path.resolve(currentDir, '..', '..');
55
- // Verify by checking for bootstrap.js
56
- const bootstrapPath = path.join(possibleRoot, 'bootstrap.js');
57
- if (fs.existsSync(bootstrapPath)) {
58
- return possibleRoot;
59
- }
60
- // Fallback to cwd
61
- return process.cwd();
55
+ // 2. Detect from current file location (__dirname is most reliable)
56
+ // dist/init/claudeConfigInjector.js -> go up 2 levels to package root
57
+ const fromThisFile = path.resolve(__dirname, '..', '..');
58
+ if (hasBootstrap(fromThisFile)) {
59
+ return fromThisFile;
60
+ }
61
+ // 3. Detect from process.argv - what script launched us
62
+ // e.g. node /usr/local/lib/.../bootstrap.cjs or /usr/lib/.../bin/specmem-cli.cjs
63
+ for (const arg of process.argv) {
64
+ if (typeof arg === 'string' && arg.includes('specmem')) {
65
+ // Resolve symlinks to get real path
66
+ try {
67
+ const realArg = fs.realpathSync(arg);
68
+ // Walk up from the script to find package root
69
+ let candidate = path.dirname(realArg);
70
+ for (let i = 0; i < 4; i++) {
71
+ if (hasBootstrap(candidate)) return candidate;
72
+ if (fs.existsSync(path.join(candidate, 'package.json'))) {
73
+ try {
74
+ const pkg = JSON.parse(fs.readFileSync(path.join(candidate, 'package.json'), 'utf-8'));
75
+ if (pkg.name === 'specmem-hardwicksoftware') return candidate;
76
+ } catch { /* ignore */ }
77
+ }
78
+ candidate = path.dirname(candidate);
79
+ }
80
+ } catch { /* ignore resolve errors */ }
81
+ }
82
+ }
83
+ // 4. Try resolving the `specmem` command via PATH (execSync imported at top)
84
+ try {
85
+ const whichResult = execSync('which specmem 2>/dev/null', { encoding: 'utf-8' }).trim();
86
+ if (whichResult) {
87
+ const realBin = fs.realpathSync(whichResult);
88
+ // specmem binary is at <root>/bin/specmem-cli.cjs -> go up 2 levels
89
+ const candidate = path.resolve(path.dirname(realBin), '..');
90
+ if (hasBootstrap(candidate)) return candidate;
91
+ }
92
+ } catch { /* which not available or specmem not in PATH */ }
93
+ // 5. Fallback to cwd (dev mode - running from source)
94
+ if (hasBootstrap(process.cwd())) {
95
+ return process.cwd();
96
+ }
97
+ // 6. Last resort - return __dirname-based path even without bootstrap
98
+ return fromThisFile;
99
+ }
100
+ // Find the actual bootstrap file (cjs or js)
101
+ function findBootstrapPath(root) {
102
+ for (const name of ['bootstrap.cjs', 'bootstrap.js']) {
103
+ const p = path.join(root, name);
104
+ if (fs.existsSync(p)) return p;
105
+ }
106
+ return path.join(root, 'bootstrap.cjs'); // default
62
107
  }
63
108
  const SPECMEM_ROOT = getSpecmemRoot();
64
- const BOOTSTRAP_PATH = path.join(SPECMEM_ROOT, 'bootstrap.js');
109
+ const BOOTSTRAP_PATH = findBootstrapPath(SPECMEM_ROOT);
65
110
  const SOURCE_HOOKS_DIR = path.join(SPECMEM_ROOT, 'claude-hooks');
66
111
  const SOURCE_COMMANDS_DIR = path.join(SPECMEM_ROOT, 'commands');
67
112
  // ============================================================================
@@ -155,7 +200,7 @@ export function isSpecmemMcpConfigured(projectPath) {
155
200
  return false;
156
201
  }
157
202
  const specmem = config.mcpServers.specmem;
158
- // Check if it points to a valid bootstrap.js
203
+ // Check if it points to a valid bootstrap file (cjs or js)
159
204
  if (!specmem.args || specmem.args.length < 2) {
160
205
  return false;
161
206
  }
@@ -167,8 +212,8 @@ export function isSpecmemMcpConfigured(projectPath) {
167
212
  // If projectPath specified, check if env has correct project path
168
213
  if (projectPath) {
169
214
  const configuredPath = specmem.env?.SPECMEM_PROJECT_PATH;
170
- // ${PWD} is expanded at runtime by Code, so it's valid
171
- if (configuredPath && configuredPath !== '${PWD}' && configuredPath !== projectPath) {
215
+ // ${PWD} and ${cwd} are expanded at runtime by Claude Code, so they're valid
216
+ if (configuredPath && configuredPath !== '${PWD}' && configuredPath !== '${cwd}' && configuredPath !== projectPath) {
172
217
  return false;
173
218
  }
174
219
  }
@@ -179,11 +224,11 @@ export function isSpecmemMcpConfigured(projectPath) {
179
224
  * Returns true if changes were made
180
225
  */
181
226
  function configureMcpServer() {
182
- // Verify bootstrap.js exists
227
+ // Verify bootstrap file exists (cjs or js)
183
228
  if (!fs.existsSync(BOOTSTRAP_PATH)) {
184
229
  return {
185
230
  configured: false,
186
- error: `bootstrap.js not found at ${BOOTSTRAP_PATH}`
231
+ error: `bootstrap not found at ${BOOTSTRAP_PATH}`
187
232
  };
188
233
  }
189
234
  const config = safeReadJson(CONFIG_PATH, {});
@@ -265,8 +310,9 @@ function fixProjectMcpConfigs() {
265
310
  // Scan all project entries
266
311
  for (const [projectPath, projectConfig] of Object.entries(claudeJson.projects)) {
267
312
  const config = projectConfig;
268
- // Check if this project has a specmem MCP server config
269
- if (config?.mcpServers?.specmem) {
313
+ if (!config) continue;
314
+ // Case 1: Project has specmem MCP config but with outdated path
315
+ if (config.mcpServers?.specmem) {
270
316
  const specmem = config.mcpServers.specmem;
271
317
  const args = specmem.args || [];
272
318
  // Check if the args contain an outdated specmem path
@@ -275,28 +321,49 @@ function fixProjectMcpConfigs() {
275
321
  if (typeof arg === 'string' &&
276
322
  arg.includes('specmem') &&
277
323
  arg !== BOOTSTRAP_PATH &&
278
- (arg.endsWith('index.js') || arg.endsWith('bootstrap.js'))) {
324
+ (arg.endsWith('index.js') || arg.endsWith('bootstrap.js') || arg.endsWith('bootstrap.cjs'))) {
279
325
  needsUpdate = true;
280
326
  return BOOTSTRAP_PATH;
281
327
  }
282
328
  return arg;
283
329
  });
284
330
  if (needsUpdate) {
285
- // Update the args
286
331
  specmem.args = updatedArgs;
287
- // Ensure SPECMEM_PROJECT_PATH is set to actual project path
288
- // CRITICAL: ${PWD} doesn't get expanded by Code, use literal path
289
332
  if (!specmem.env) {
290
333
  specmem.env = {};
291
334
  }
292
335
  if (!specmem.env.SPECMEM_PROJECT_PATH || specmem.env.SPECMEM_PROJECT_PATH === '${PWD}' || specmem.env.SPECMEM_PROJECT_PATH === '${cwd}') {
293
- specmem.env.SPECMEM_PROJECT_PATH = projectPath; // Use the actual project path key
336
+ specmem.env.SPECMEM_PROJECT_PATH = projectPath;
294
337
  }
295
338
  logger.info({ projectPath, oldArgs: args, newArgs: updatedArgs }, '[ConfigInjector] Fixed outdated specmem path in project config');
296
339
  fixed++;
297
340
  modified = true;
298
341
  }
299
342
  }
343
+ // Case 2: Project has mcpServers but NO specmem entry (empty {} or missing key)
344
+ // This empty override hides the global config.json MCP server, so we inject it
345
+ else if (config.mcpServers && !config.mcpServers.specmem) {
346
+ // Don't clobber other MCP servers - only add specmem
347
+ config.mcpServers.specmem = {
348
+ command: 'node',
349
+ args: ['--max-old-space-size=250', BOOTSTRAP_PATH],
350
+ env: {
351
+ HOME: HOME_DIR,
352
+ SPECMEM_PROJECT_PATH: '${cwd}',
353
+ SPECMEM_WATCHER_ROOT_PATH: '${cwd}',
354
+ SPECMEM_CODEBASE_PATH: '${cwd}',
355
+ SPECMEM_DB_HOST: process.env.SPECMEM_DB_HOST || 'localhost',
356
+ SPECMEM_DB_PORT: process.env.SPECMEM_DB_PORT || '5432',
357
+ SPECMEM_SESSION_WATCHER_ENABLED: 'true',
358
+ SPECMEM_WATCHER_ENABLED: 'true',
359
+ SPECMEM_DASHBOARD_ENABLED: 'true',
360
+ SPECMEM_DASHBOARD_PORT: process.env.SPECMEM_DASHBOARD_PORT || '8595',
361
+ }
362
+ };
363
+ logger.info({ projectPath }, '[ConfigInjector] Injected specmem MCP server into project with empty mcpServers');
364
+ fixed++;
365
+ modified = true;
366
+ }
300
367
  }
301
368
  // Write back if modified
302
369
  if (modified) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "specmem-hardwicksoftware",
3
- "version": "3.7.0",
3
+ "version": "3.7.1",
4
4
  "type": "module",
5
5
  "description": "Persistent memory system for coding sessions - semantic search with pgvector, token compression, team coordination, file watching. Needs root: installs system-wide hooks, manages docker/PostgreSQL, writes global configs, handles screen sessions. justcalljon.pro",
6
6
  "main": "dist/index.js",