monomind 1.9.3 → 1.9.5

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.
@@ -52,8 +52,29 @@ if (!entryPoint) {
52
52
  process.exit(0);
53
53
  }
54
54
 
55
+ // Skip if another build is already in progress (avoids SQLite BUSY on concurrent init + session-start)
56
+ const lockPath = path.join(graphDir, 'build.lock');
57
+ const now = Date.now();
58
+ try {
59
+ const stat = fs.statSync(lockPath);
60
+ // Stale lock older than 5 minutes — remove it and proceed
61
+ if (now - stat.mtimeMs < 5 * 60 * 1000) {
62
+ console.log('[graph] build already in progress — skipping');
63
+ process.exit(0);
64
+ }
65
+ fs.unlinkSync(lockPath);
66
+ } catch { /* lock does not exist — proceed */ }
67
+
68
+ // Write lock file; the build process removes it on completion
69
+ try { fs.writeFileSync(lockPath, String(process.pid)); } catch { /* non-fatal */ }
70
+
55
71
  // Spawn a detached node process to run buildAsync from @monoes/monograph (ESM)
56
- const script = `import { buildAsync } from ${JSON.stringify('file://' + entryPoint)}; await buildAsync(${JSON.stringify(projectDir)});`;
72
+ const script = `
73
+ import { buildAsync } from ${JSON.stringify('file://' + entryPoint)};
74
+ import { unlinkSync } from 'fs';
75
+ try { await buildAsync(${JSON.stringify(projectDir)}); } finally {
76
+ try { unlinkSync(${JSON.stringify(lockPath)}); } catch {}
77
+ }`;
57
78
  const child = spawn(process.execPath, ['--input-type=module', '--eval', script], {
58
79
  detached: true,
59
80
  stdio: ['ignore', logFd, logFd],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monomind",
3
- "version": "1.9.3",
3
+ "version": "1.9.5",
4
4
  "description": "Monomind - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -89,18 +89,14 @@ const initAction = async (ctx) => {
89
89
  return { success: false, exitCode: 1 };
90
90
  }
91
91
  spinner.succeed('Monomind initialized successfully!');
92
- // Trigger background monograph build + continuous watch
92
+ // Trigger background monograph watch (includes initial build on start).
93
+ // Only one spawn — avoids SQLite BUSY from concurrent build + watch + session-start hook.
93
94
  try {
94
95
  const { spawn } = await import('child_process');
95
- for (const args of [
96
- ['monograph', 'build', '--code-only'],
97
- ['monograph', 'watch'],
98
- ]) {
99
- const proc = spawn(process.execPath, [process.argv[1], ...args], {
100
- detached: true, stdio: 'ignore', cwd: ctx.cwd, env: process.env,
101
- });
102
- proc.unref();
103
- }
96
+ const proc = spawn(process.execPath, [process.argv[1], 'monograph', 'watch'], {
97
+ detached: true, stdio: 'ignore', cwd: ctx.cwd, env: process.env,
98
+ });
99
+ proc.unref();
104
100
  output.printInfo('◈ Building knowledge graph in background… (watch mode active)');
105
101
  }
106
102
  catch {
@@ -350,25 +350,62 @@ export async function executeInit(options) {
350
350
  return result;
351
351
  }
352
352
  /**
353
- * Initialize the Monograph knowledge graph (native TypeScript, no Python required).
354
- * Fire-and-forget build init does not wait for it to complete.
353
+ * Initialize the Monograph knowledge graph.
354
+ * Spawns buildAsync as a detached child process to avoid SQLite lock contention.
355
+ * Uses the same build.lock file as graphify-freshen.cjs — if a session-start
356
+ * hook build is already running, we skip to avoid SQLITE_BUSY.
355
357
  */
356
358
  async function initKnowledgeGraph(targetDir, result) {
357
- const { mkdirSync } = await import('fs');
359
+ const { mkdirSync, statSync, unlinkSync, writeFileSync, existsSync } = await import('fs');
358
360
  const outputDir = path.join(targetDir, '.monomind', 'graph');
359
361
  mkdirSync(outputDir, { recursive: true });
362
+ const lockPath = path.join(outputDir, 'build.lock');
363
+ const now = Date.now();
364
+ // If graphify-freshen.cjs (session-start hook) already holds a fresh lock, skip.
360
365
  try {
361
- const { buildAsync } = await import('@monoes/monograph');
362
- buildAsync(targetDir, { codeOnly: false })
363
- .then(() => { })
364
- .catch((err) => {
365
- console.warn('[monograph] Background build failed:', err);
366
- });
367
- result.created.files.push('.monomind/monograph.db (knowledge graph building in background)');
366
+ const stat = statSync(lockPath);
367
+ if (now - stat.mtimeMs < 5 * 60 * 1000) {
368
+ result.skipped.push('knowledge graph build: already in progress (session-start hook running)');
369
+ return;
370
+ }
371
+ unlinkSync(lockPath);
372
+ }
373
+ catch { /* no lock — proceed */ }
374
+ // Resolve @monoes/monograph from the CLI package's own node_modules first
375
+ // (correct for npm/npx installs), then fall back to user project node_modules.
376
+ let entryPoint = null;
377
+ try {
378
+ const cliRequire = createRequire(import.meta.url);
379
+ entryPoint = cliRequire.resolve('@monoes/monograph/dist/src/index.js');
368
380
  }
369
- catch (err) {
370
- result.skipped.push('knowledge graph: monograph package unavailable');
381
+ catch {
382
+ const fallback = path.join(targetDir, 'node_modules', '@monoes', 'monograph', 'dist', 'src', 'index.js');
383
+ if (existsSync(fallback))
384
+ entryPoint = fallback;
385
+ }
386
+ if (!entryPoint) {
387
+ result.skipped.push('knowledge graph: @monoes/monograph not found');
388
+ return;
371
389
  }
390
+ // Acquire lock before spawning so graphify-freshen.cjs sees it and skips
391
+ try {
392
+ writeFileSync(lockPath, String(process.pid));
393
+ }
394
+ catch { /* non-fatal */ }
395
+ const { spawn } = await import('child_process');
396
+ const script = `
397
+ import { buildAsync } from ${JSON.stringify('file://' + entryPoint)};
398
+ import { unlinkSync } from 'fs';
399
+ try { await buildAsync(${JSON.stringify(targetDir)}); } finally {
400
+ try { unlinkSync(${JSON.stringify(lockPath)}); } catch {}
401
+ }`;
402
+ const child = spawn(process.execPath, ['--input-type=module', '--eval', script], {
403
+ detached: true,
404
+ stdio: 'ignore',
405
+ cwd: targetDir,
406
+ });
407
+ child.unref();
408
+ result.created.files.push('.monomind/graph/ (knowledge graph building in background)');
372
409
  }
373
410
  /**
374
411
  * Start the monomind daemon with background workers.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monoes/monomindcli",
3
- "version": "1.9.3",
3
+ "version": "1.9.5",
4
4
  "type": "module",
5
5
  "description": "Monomind CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
6
6
  "main": "dist/src/index.js",