delimit-cli 3.11.3 → 3.11.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.
@@ -338,40 +338,36 @@ Run full governance compliance checks. Verify security, policy compliance, evide
338
338
  }
339
339
  log(` ${green('✓')} ${installed} agents installed (${Object.keys(agents).length - installed} already existed)`);
340
340
 
341
- // Step 5: Create CLAUDE.md for first-run guidance
342
- step(5, 'Setting up first-run guidance...');
341
+ // Step 5: Create/update CLAUDE.md and platform instruction files
342
+ step(5, 'Setting up AI instruction files...');
343
343
 
344
344
  const claudeMd = path.join(os.homedir(), 'CLAUDE.md');
345
- if (!fs.existsSync(claudeMd)) {
346
- fs.writeFileSync(claudeMd, getClaudeMdContent());
347
- log(` ${green('✓')} Created ${claudeMd} with first-run guidance`);
345
+ const claudeResult = upsertDelimitSection(claudeMd);
346
+ if (claudeResult.action === 'created') {
347
+ log(` ${green('✓')} Created ${claudeMd} with governance triggers`);
348
+ } else if (claudeResult.action === 'updated') {
349
+ log(` ${green('✓')} Updated Delimit section in ${claudeMd} (version changed)`);
350
+ } else if (claudeResult.action === 'appended') {
351
+ log(` ${green('✓')} Appended Delimit section to ${claudeMd} (user content preserved)`);
348
352
  } else {
349
- // Check if existing CLAUDE.md is an older Delimit version that should be upgraded
350
- const existing = fs.readFileSync(claudeMd, 'utf-8');
351
- if (existing.includes('# Delimit AI Guardrails') || existing.includes('delimit_init') || existing.includes('delimit_lint') || existing.includes('persistent memory, verified execution')) {
352
- fs.writeFileSync(claudeMd, getClaudeMdContent());
353
- log(` ${green('✓')} Updated ${claudeMd} with improved onboarding`);
354
- } else {
355
- log(` ${dim(' CLAUDE.md already exists with custom content — skipped')}`);
356
- }
353
+ log(` ${dim(' CLAUDE.md already up to date')}`);
357
354
  }
358
355
 
359
- // Create instruction files for other platforms
360
- const instructionContent = getClaudeMdContent();
361
-
362
356
  // Codex instructions
363
357
  const codexInstructions = path.join(os.homedir(), '.codex', 'instructions.md');
364
358
  if (fs.existsSync(path.join(os.homedir(), '.codex'))) {
365
- if (!fs.existsSync(codexInstructions) || fs.readFileSync(codexInstructions, 'utf-8').includes('# Delimit')) {
366
- fs.writeFileSync(codexInstructions, instructionContent);
359
+ const codexResult = upsertDelimitSection(codexInstructions);
360
+ if (codexResult.action !== 'unchanged') {
361
+ log(` ${green('✓')} ${codexResult.action === 'created' ? 'Created' : 'Updated'} ${codexInstructions}`);
367
362
  }
368
363
  }
369
364
 
370
365
  // Cursor rules
371
366
  const cursorRules = path.join(os.homedir(), '.cursorrules');
372
367
  if (fs.existsSync(path.join(os.homedir(), '.cursor'))) {
373
- if (!fs.existsSync(cursorRules) || fs.readFileSync(cursorRules, 'utf-8').includes('# Delimit')) {
374
- fs.writeFileSync(cursorRules, instructionContent);
368
+ const cursorResult = upsertDelimitSection(cursorRules);
369
+ if (cursorResult.action !== 'unchanged') {
370
+ log(` ${green('✓')} ${cursorResult.action === 'created' ? 'Created' : 'Updated'} ${cursorRules}`);
375
371
  }
376
372
  }
377
373
 
@@ -540,8 +536,11 @@ echo "[Delimit] ${toolName} not found" >&2; exit 127
540
536
  log('');
541
537
  }
542
538
 
543
- function getClaudeMdContent() {
544
- return `# Delimit
539
+ function getDelimitSection() {
540
+ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf-8'));
541
+ const version = pkg.version || '0.0.0';
542
+ return `<!-- delimit:start v${version} -->
543
+ # Delimit
545
544
 
546
545
  One workspace for every AI coding assistant.
547
546
 
@@ -577,7 +576,67 @@ Add breaking change detection to any repo:
577
576
  - Docs: https://delimit.ai/docs
578
577
  - GitHub: https://github.com/delimit-ai/delimit
579
578
  - Action: https://github.com/marketplace/actions/delimit-api-governance
580
- `;
579
+ <!-- delimit:end -->`;
580
+ }
581
+
582
+ function getClaudeMdContent() {
583
+ return getDelimitSection() + '\n';
584
+ }
585
+
586
+ /**
587
+ * Upsert the Delimit section in a file using <!-- delimit:start --> / <!-- delimit:end --> markers.
588
+ * If markers exist, replaces only that region (preserving user content above/below).
589
+ * If no markers exist but old Delimit content is detected, replaces the whole file.
590
+ * If no Delimit content at all, appends the section.
591
+ * Returns { action: 'created' | 'updated' | 'unchanged' | 'appended' }
592
+ */
593
+ function upsertDelimitSection(filePath) {
594
+ const newSection = getDelimitSection();
595
+ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf-8'));
596
+ const version = pkg.version || '0.0.0';
597
+
598
+ if (!fs.existsSync(filePath)) {
599
+ fs.writeFileSync(filePath, newSection + '\n');
600
+ return { action: 'created' };
601
+ }
602
+
603
+ const existing = fs.readFileSync(filePath, 'utf-8');
604
+
605
+ // Check if markers already exist
606
+ const startMarkerRe = /<!-- delimit:start[^>]*-->/;
607
+ const endMarker = '<!-- delimit:end -->';
608
+ const hasStart = startMarkerRe.test(existing);
609
+ const hasEnd = existing.includes(endMarker);
610
+
611
+ if (hasStart && hasEnd) {
612
+ // Extract current version from the marker
613
+ const versionMatch = existing.match(/<!-- delimit:start v([^ ]+) -->/);
614
+ const currentVersion = versionMatch ? versionMatch[1] : '';
615
+ if (currentVersion === version) {
616
+ return { action: 'unchanged' };
617
+ }
618
+ // Replace only the delimit section
619
+ const before = existing.substring(0, existing.search(startMarkerRe));
620
+ const after = existing.substring(existing.indexOf(endMarker) + endMarker.length);
621
+ fs.writeFileSync(filePath, before + newSection + after);
622
+ return { action: 'updated' };
623
+ }
624
+
625
+ // No markers — check for old Delimit content that should be replaced
626
+ const isOldDelimit = existing.includes('# Delimit AI Guardrails') ||
627
+ existing.includes('delimit_init') ||
628
+ existing.includes('persistent memory, verified execution') ||
629
+ (existing.includes('# Delimit') && existing.includes('delimit_ledger_context'));
630
+
631
+ if (isOldDelimit) {
632
+ fs.writeFileSync(filePath, newSection + '\n');
633
+ return { action: 'updated' };
634
+ }
635
+
636
+ // File exists with user content but no Delimit section — append
637
+ const separator = existing.endsWith('\n') ? '\n' : '\n\n';
638
+ fs.writeFileSync(filePath, existing + separator + newSection + '\n');
639
+ return { action: 'appended' };
581
640
  }
582
641
 
583
642
  function copyDir(src, dest) {
package/lib/api-engine.js CHANGED
@@ -17,13 +17,34 @@ const fs = require('fs');
17
17
  const os = require('os');
18
18
 
19
19
  // Gateway root — the Python engine lives here
20
+ // Resolution order: env var > ~/.delimit/server > ~/.delimit/gateway > bundled gateway
20
21
  const DELIMIT_HOME = process.env.DELIMIT_HOME || path.join(os.homedir(), '.delimit');
21
- const GATEWAY_ROOT = process.env.DELIMIT_GATEWAY_ROOT || path.join(DELIMIT_HOME, 'gateway');
22
+ const GATEWAY_ROOT = (() => {
23
+ if (process.env.DELIMIT_GATEWAY_ROOT) return process.env.DELIMIT_GATEWAY_ROOT;
24
+ // Check ~/.delimit/server (where `delimit setup` installs)
25
+ const serverPath = path.join(DELIMIT_HOME, 'server');
26
+ if (fs.existsSync(path.join(serverPath, 'core'))) return serverPath;
27
+ // Check ~/.delimit/gateway (legacy path)
28
+ const gatewayPath = path.join(DELIMIT_HOME, 'gateway');
29
+ if (fs.existsSync(path.join(gatewayPath, 'core'))) return gatewayPath;
30
+ // Check bundled gateway inside the npm package
31
+ const bundledPath = path.join(__dirname, '..', 'gateway');
32
+ if (fs.existsSync(path.join(bundledPath, 'core'))) return bundledPath;
33
+ // Fallback — will fail with a clear error in runGateway()
34
+ return gatewayPath;
35
+ })();
22
36
 
23
37
  // Python executable — prefer venv if available
24
38
  const PYTHON = (() => {
25
39
  const venvPy = path.join(DELIMIT_HOME, 'venv', 'bin', 'python');
26
40
  if (fs.existsSync(venvPy)) return venvPy;
41
+ // Check common python locations
42
+ for (const cmd of ['python3', 'python']) {
43
+ try {
44
+ execSync(`${cmd} --version`, { stdio: 'pipe' });
45
+ return cmd;
46
+ } catch {}
47
+ }
27
48
  return 'python3';
28
49
  })();
29
50
 
@@ -33,6 +54,20 @@ const PYTHON = (() => {
33
54
  * Returns parsed JSON or throws.
34
55
  */
35
56
  function runGateway(pythonCode, timeoutMs = 30000) {
57
+ // Check that the gateway core exists before trying to run
58
+ if (!fs.existsSync(path.join(GATEWAY_ROOT, 'core'))) {
59
+ const msg = [
60
+ 'Delimit gateway engine not found.',
61
+ '',
62
+ 'Run one of:',
63
+ ' npx delimit-cli setup # full install with MCP server',
64
+ ' delimit setup # if globally installed',
65
+ '',
66
+ 'Or set DELIMIT_GATEWAY_ROOT to your gateway directory.',
67
+ ].join('\n');
68
+ throw new Error(msg);
69
+ }
70
+
36
71
  const tmpFile = path.join(os.tmpdir(), `delimit_${process.pid}_${Date.now()}.py`);
37
72
  try {
38
73
  fs.writeFileSync(tmpFile, pythonCode);
@@ -50,6 +85,18 @@ function runGateway(pythonCode, timeoutMs = 30000) {
50
85
  if (err.stdout) {
51
86
  try { return JSON.parse(err.stdout.trim()); } catch (_) {}
52
87
  }
88
+ // Improve error messages for common failures
89
+ const stderr = err.stderr || '';
90
+ if (stderr.includes('No module named') || stderr.includes('ModuleNotFoundError')) {
91
+ throw new Error(
92
+ `Python dependency missing. Run: npx delimit-cli setup\n\nDetails: ${stderr.trim()}`
93
+ );
94
+ }
95
+ if (err.message && err.message.includes('ENOENT')) {
96
+ throw new Error(
97
+ `Python not found. Install Python 3.9+ and try again.\n\nDetails: ${err.message}`
98
+ );
99
+ }
53
100
  throw new Error(err.stderr || err.message || 'Gateway execution failed');
54
101
  } finally {
55
102
  try { fs.unlinkSync(tmpFile); } catch (_) {}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "delimit-cli",
3
3
  "mcpName": "io.github.delimit-ai/delimit",
4
- "version": "3.11.3",
4
+ "version": "3.11.5",
5
5
  "description": "One workspace for every AI coding assistant. Tasks, memory, and governance carry between Claude Code, Codex, and Gemini CLI.",
6
6
  "main": "index.js",
7
7
  "files": [
package/server.json CHANGED
@@ -7,13 +7,13 @@
7
7
  "url": "https://github.com/delimit-ai/delimit",
8
8
  "source": "github"
9
9
  },
10
- "version": "3.11.3",
10
+ "version": "3.11.5",
11
11
  "websiteUrl": "https://delimit.ai",
12
12
  "packages": [
13
13
  {
14
14
  "registryType": "npm",
15
15
  "identifier": "delimit-cli",
16
- "version": "3.11.3",
16
+ "version": "3.11.5",
17
17
  "transport": {
18
18
  "type": "stdio"
19
19
  }