|
5 | 5 | * Provides persistent code indexing for Claude Code. |
6 | 6 | * |
7 | 7 | * Usage: |
8 | | - * node build/index.js - Start MCP server (default) |
9 | | - * node build/index.js scan <path> - Scan for .aidex directories |
10 | | - * node build/index.js init <path> - Index a project |
| 8 | + * node build/index.js - Start MCP server (default) |
| 9 | + * node build/index.js scan <path> - Scan for .aidex directories |
| 10 | + * node build/index.js init <path> - Index a project |
| 11 | + * node build/index.js global-init <path> - Scan, index unindexed, register in global DB |
11 | 12 | */ |
12 | 13 |
|
13 | 14 | import { createServer } from './server/mcp-server.js'; |
14 | | -import { scan, init } from './commands/index.js'; |
| 15 | +import { scan, init, globalInit } from './commands/index.js'; |
15 | 16 | import { setupMcpClients, unsetupMcpClients } from './commands/setup.js'; |
16 | 17 | import { PRODUCT_NAME, PRODUCT_NAME_LOWER } from './constants.js'; |
17 | 18 | import { stopViewer } from './viewer/server.js'; |
@@ -79,6 +80,59 @@ async function main() { |
79 | 80 | return; |
80 | 81 | } |
81 | 82 |
|
| 83 | + // CLI mode: global-init |
| 84 | + if (args[0] === 'global-init') { |
| 85 | + const searchPath = args[1]; |
| 86 | + if (!searchPath) { |
| 87 | + console.error(`Usage: ${PRODUCT_NAME_LOWER} global-init <path> [--index-unindexed]`); |
| 88 | + process.exit(1); |
| 89 | + } |
| 90 | + |
| 91 | + const indexUnindexed = args.includes('--index-unindexed'); |
| 92 | + const showProgress = args.includes('--show-progress'); |
| 93 | + |
| 94 | + console.log(`Scanning: ${searchPath}${indexUnindexed ? ' (will index unindexed projects)' : ''}${showProgress ? ' (with progress UI)' : ''}`); |
| 95 | + const result = await globalInit({ |
| 96 | + path: searchPath, |
| 97 | + indexUnindexed, |
| 98 | + showProgress, |
| 99 | + }); |
| 100 | + |
| 101 | + if (!result.success) { |
| 102 | + console.error(`Error: ${result.error}`); |
| 103 | + process.exit(1); |
| 104 | + } |
| 105 | + |
| 106 | + console.log(`Done!`); |
| 107 | + console.log(` Registered: ${result.registered}`); |
| 108 | + console.log(` New: ${result.newProjects}`); |
| 109 | + console.log(` Updated: ${result.updatedProjects}`); |
| 110 | + console.log(` Removed: ${result.removedProjects}`); |
| 111 | + |
| 112 | + if (result.indexedResults && result.indexedResults.length > 0) { |
| 113 | + const ok = result.indexedResults.filter(r => r.success).length; |
| 114 | + const fail = result.indexedResults.filter(r => !r.success).length; |
| 115 | + console.log(` Indexed: ${ok} succeeded, ${fail} failed`); |
| 116 | + } |
| 117 | + |
| 118 | + if (result.unindexedProjects.length > 0) { |
| 119 | + console.log(`\n Unindexed projects found: ${result.unindexedProjects.length}`); |
| 120 | + for (const p of result.unindexedProjects) { |
| 121 | + console.log(` ${p.name} (${p.path}) ~${p.estimatedFiles} files`); |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + if (result.largeProjects && result.largeProjects.length > 0) { |
| 126 | + console.log(`\n Large projects skipped (>500 files): ${result.largeProjects.length}`); |
| 127 | + for (const p of result.largeProjects) { |
| 128 | + console.log(` ${p.name} (${p.path}) ~${p.estimatedFiles} files`); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + console.log(`\n Totals: ${result.totals.projects} projects | ${result.totals.files} files | ${result.totals.methods} methods | ${result.totals.types} types`); |
| 133 | + return; |
| 134 | + } |
| 135 | + |
82 | 136 | // CLI mode: setup |
83 | 137 | if (args[0] === 'setup') { |
84 | 138 | setupMcpClients(); |
|
0 commit comments