cntx-ui 3.0.9 → 3.1.0

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.
@@ -2,7 +2,7 @@
2
2
  import { readFileSync, existsSync } from 'fs';
3
3
  import { dirname, join } from 'path';
4
4
  import { fileURLToPath } from 'url';
5
- import { startServer, initConfig } from '../server.js';
5
+ import { startServer, initConfig, getStatus, setupMCP, generateBundle } from '../server.js';
6
6
  const __dirname = dirname(fileURLToPath(import.meta.url));
7
7
  let packagePath = join(__dirname, '..', 'package.json');
8
8
  if (!existsSync(packagePath)) {
@@ -30,11 +30,27 @@ async function main() {
30
30
  case 'init':
31
31
  console.log('🚀 Initializing cntx-ui...');
32
32
  await initConfig();
33
- console.log('🎉 cntx-ui initialized with full scaffolding!');
34
33
  break;
35
34
  case 'mcp':
36
35
  await startServer({ withMcp: true, skipFileWatcher: true, skipBundleGeneration: true });
37
36
  break;
37
+ case 'bundle':
38
+ const bundleName = args[1] || 'master';
39
+ try {
40
+ await generateBundle(bundleName);
41
+ console.log(`✅ Bundle '${bundleName}' generated successfully`);
42
+ }
43
+ catch (error) {
44
+ console.error(`❌ Failed to generate bundle '${bundleName}': ${error.message}`);
45
+ process.exit(1);
46
+ }
47
+ break;
48
+ case 'status':
49
+ await getStatus();
50
+ break;
51
+ case 'setup-mcp':
52
+ setupMCP();
53
+ break;
38
54
  case 'version':
39
55
  case '-v':
40
56
  case '--version':
@@ -49,6 +65,9 @@ Usage:
49
65
  cntx-ui watch [port] Start the visual dashboard and intelligence engine (default: 3333)
50
66
  cntx-ui init Initialize cntx-ui configuration in the current directory
51
67
  cntx-ui mcp Start the Model Context Protocol (MCP) server on stdio
68
+ cntx-ui bundle [name] Generate specific bundle (default: master)
69
+ cntx-ui status Show current project status
70
+ cntx-ui setup-mcp Add this project to Claude Desktop MCP config
52
71
  cntx-ui version Show current version
53
72
  cntx-ui help Show this help information
54
73
 
package/dist/server.js CHANGED
@@ -5,7 +5,8 @@
5
5
  import { createServer } from 'http';
6
6
  import { join, dirname, extname } from 'path';
7
7
  import { fileURLToPath, parse } from 'url';
8
- import { existsSync, mkdirSync, readFileSync } from 'fs';
8
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, copyFileSync, cpSync } from 'fs';
9
+ import { homedir } from 'os';
9
10
  // Import our modular components
10
11
  import ConfigurationManager from './lib/configuration-manager.js';
11
12
  import FileSystemManager from './lib/file-system-manager.js';
@@ -218,8 +219,195 @@ export async function startServer(options = {}) {
218
219
  server.startMCPServer();
219
220
  return await server.listen(options.port, options.host);
220
221
  }
222
+ // Initialize project configuration
221
223
  export async function initConfig(cwd = process.cwd()) {
222
224
  const server = new CntxServer(cwd);
223
- // Implementation matches previous init logic
224
- return [];
225
+ // 1. Initialize directory structure
226
+ if (!existsSync(server.CNTX_DIR)) {
227
+ mkdirSync(server.CNTX_DIR, { recursive: true });
228
+ console.log('📁 Created .cntx directory');
229
+ }
230
+ // 2. Create .mcp.json for Claude Code discovery
231
+ const mcpConfigPath = join(cwd, '.mcp.json');
232
+ const mcpConfig = {
233
+ mcpServers: {
234
+ "cntx-ui": {
235
+ command: "cntx-ui",
236
+ args: ["mcp"],
237
+ cwd: "."
238
+ }
239
+ }
240
+ };
241
+ writeFileSync(mcpConfigPath, JSON.stringify(mcpConfig, null, 2), 'utf8');
242
+ console.log('📄 Created .mcp.json for agent auto-discovery');
243
+ // 3. Initialize basic configuration with better defaults and auto-suggestions
244
+ server.configManager.loadConfig();
245
+ const suggestedBundles = {
246
+ master: ['**/*']
247
+ };
248
+ // Directory-based auto-suggestions
249
+ const commonDirs = [
250
+ { dir: 'src/components', name: 'ui-components' },
251
+ { dir: 'src/services', name: 'services' },
252
+ { dir: 'src/lib', name: 'libraries' },
253
+ { dir: 'src/hooks', name: 'react-hooks' },
254
+ { dir: 'server', name: 'backend-api' },
255
+ { dir: 'tests', name: 'test-suite' }
256
+ ];
257
+ commonDirs.forEach(d => {
258
+ if (existsSync(join(cwd, d.dir))) {
259
+ suggestedBundles[d.name] = [`${d.dir}/**`];
260
+ console.log(`💡 Suggested bundle: ${d.name} (${d.dir}/**)`);
261
+ }
262
+ });
263
+ server.configManager.saveConfig({
264
+ bundles: suggestedBundles
265
+ });
266
+ // 4. Create robust default .cntxignore
267
+ const ignorePath = join(cwd, '.cntxignore');
268
+ if (!existsSync(ignorePath)) {
269
+ const defaultIgnore = `# Binary files
270
+ *.db
271
+ *.db-journal
272
+ *.png
273
+ *.jpg
274
+ *.jpeg
275
+ *.ico
276
+ *.icns
277
+ *.gif
278
+ *.zip
279
+ *.tar.gz
280
+
281
+ # Generated files
282
+ **/gen/**
283
+ **/dist/**
284
+ **/build/**
285
+ **/node_modules/**
286
+ **/.next/**
287
+ **/.cache/**
288
+
289
+ # cntx-ui internals
290
+ .cntx/**
291
+ .mcp.json
292
+ `;
293
+ writeFileSync(ignorePath, defaultIgnore, 'utf8');
294
+ console.log('📄 Created .cntxignore with smart defaults');
295
+ }
296
+ console.log('⚙️ Basic configuration initialized');
297
+ const templateDir = join(__dirname, 'templates');
298
+ // Copy agent configuration files
299
+ const agentFiles = [
300
+ 'agent-config.yaml',
301
+ 'agent-instructions.md'
302
+ ];
303
+ for (const file of agentFiles) {
304
+ const sourcePath = join(templateDir, file);
305
+ const destPath = join(server.CNTX_DIR, file);
306
+ if (existsSync(sourcePath) && !existsSync(destPath)) {
307
+ copyFileSync(sourcePath, destPath);
308
+ console.log(`📄 Created ${file}`);
309
+ }
310
+ }
311
+ // Copy agent-rules directory structure
312
+ const agentRulesSource = join(templateDir, 'agent-rules');
313
+ const agentRulesDest = join(server.CNTX_DIR, 'agent-rules');
314
+ if (existsSync(agentRulesSource) && !existsSync(agentRulesDest)) {
315
+ cpSync(agentRulesSource, agentRulesDest, { recursive: true });
316
+ console.log('📁 Created agent-rules directory with templates');
317
+ }
318
+ // Copy activities framework
319
+ const activitiesDir = join(server.CNTX_DIR, 'activities');
320
+ if (!existsSync(activitiesDir)) {
321
+ mkdirSync(activitiesDir, { recursive: true });
322
+ }
323
+ // Copy activities README
324
+ const activitiesReadmeSource = join(templateDir, 'activities', 'README.md');
325
+ const activitiesReadmeDest = join(activitiesDir, 'README.md');
326
+ if (existsSync(activitiesReadmeSource) && !existsSync(activitiesReadmeDest)) {
327
+ copyFileSync(activitiesReadmeSource, activitiesReadmeDest);
328
+ console.log('📄 Created activities/README.md');
329
+ }
330
+ // Copy activities lib directory (MDC templates)
331
+ const activitiesLibSource = join(templateDir, 'activities', 'lib');
332
+ const activitiesLibDest = join(activitiesDir, 'lib');
333
+ if (existsSync(activitiesLibSource) && !existsSync(activitiesLibDest)) {
334
+ cpSync(activitiesLibSource, activitiesLibDest, { recursive: true });
335
+ console.log('📁 Created activities/lib with MDC templates');
336
+ }
337
+ // Copy activities.json from templates
338
+ const activitiesJsonPath = join(activitiesDir, 'activities.json');
339
+ const templateActivitiesJsonPath = join(templateDir, 'activities', 'activities.json');
340
+ if (!existsSync(activitiesJsonPath) && existsSync(templateActivitiesJsonPath)) {
341
+ copyFileSync(templateActivitiesJsonPath, activitiesJsonPath);
342
+ console.log('📄 Created activities.json with bundle example activity');
343
+ }
344
+ // Copy example activity from templates
345
+ const activitiesDestDir = join(activitiesDir, 'activities');
346
+ const templateActivitiesDir = join(templateDir, 'activities', 'activities');
347
+ if (!existsSync(activitiesDestDir) && existsSync(templateActivitiesDir)) {
348
+ cpSync(templateActivitiesDir, activitiesDestDir, { recursive: true });
349
+ console.log('📁 Created example activity with templates');
350
+ }
351
+ return server.initMessages;
352
+ }
353
+ export async function generateBundle(name) {
354
+ const server = new CntxServer(process.cwd());
355
+ await server.init({ skipFileWatcher: true });
356
+ return await server.bundleManager.regenerateBundle(name);
357
+ }
358
+ export async function getStatus() {
359
+ const server = new CntxServer(process.cwd());
360
+ await server.init({ skipFileWatcher: true });
361
+ const bundles = server.bundleManager.getAllBundleInfo();
362
+ const totalFiles = server.fileSystemManager.getAllFiles().length;
363
+ console.log('📊 cntx-ui Status');
364
+ console.log('================');
365
+ console.log(`Total files: ${totalFiles}`);
366
+ console.log(`Bundles: ${bundles.length}`);
367
+ bundles.forEach(bundle => {
368
+ console.log(` • ${bundle.name}: ${bundle.fileCount} files (${Math.round(bundle.size / 1024)}KB)`);
369
+ });
370
+ return {
371
+ totalFiles,
372
+ bundles: bundles.length,
373
+ bundleDetails: bundles
374
+ };
375
+ }
376
+ export function setupMCP() {
377
+ const configPath = join(homedir(), 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json');
378
+ const projectPath = process.cwd();
379
+ console.log('🔧 Setting up MCP integration...');
380
+ console.log(`Project: ${projectPath}`);
381
+ console.log(`Claude config: ${configPath}`);
382
+ try {
383
+ let config = {};
384
+ if (existsSync(configPath)) {
385
+ config = JSON.parse(readFileSync(configPath, 'utf8'));
386
+ }
387
+ if (!config.mcpServers) {
388
+ config.mcpServers = {};
389
+ }
390
+ config.mcpServers['cntx-ui'] = {
391
+ command: 'npx',
392
+ args: ['cntx-ui', 'mcp'],
393
+ cwd: projectPath
394
+ };
395
+ // Ensure directory exists
396
+ mkdirSync(dirname(configPath), { recursive: true });
397
+ writeFileSync(configPath, JSON.stringify(config, null, 2));
398
+ console.log('✅ MCP integration configured');
399
+ console.log('💡 Restart Claude Desktop to apply changes');
400
+ }
401
+ catch (error) {
402
+ console.error('❌ Failed to setup MCP:', error.message);
403
+ console.log('💡 You may need to manually add the configuration to Claude Desktop');
404
+ }
405
+ }
406
+ // Auto-start server when run directly
407
+ const isMainModule = import.meta.url === `file://${process.argv[1]}`;
408
+ if (isMainModule) {
409
+ console.log('🚀 Starting cntx-ui server...');
410
+ const server = new CntxServer();
411
+ server.init();
412
+ server.listen(3333, 'localhost');
225
413
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cntx-ui",
3
3
  "type": "module",
4
- "version": "3.0.9",
4
+ "version": "3.1.0",
5
5
  "description": "Autonomous Repository Intelligence engine with web UI and MCP server. Unified semantic code understanding, local RAG, and agent working memory.",
6
6
  "keywords": [
7
7
  "repository-intelligence",
@@ -42,7 +42,7 @@
42
42
  "check:version-sync": "node scripts/check-version-sync.mjs",
43
43
  "release:ci": "node scripts/release-from-package.mjs",
44
44
  "prepublishOnly": "npm run build",
45
- "test:local": "npm pack && npm install -g ./cntx-ui-3.0.8.tgz"
45
+ "test:local": "npm pack && npm install -g ./cntx-ui-3.1.0.tgz"
46
46
  },
47
47
  "dependencies": {
48
48
  "@xenova/transformers": "^2.17.2",