(args: string[])
| 42 | } |
| 43 | |
| 44 | export async function handleMapCli(args: string[]): Promise<void> { |
| 45 | const useJson = args.includes('--json'); |
| 46 | const usePretty = args.includes('--pretty'); |
| 47 | const useExport = args.includes('--export'); |
| 48 | const useFull = args.includes('--full'); |
| 49 | const showHelp = args.includes('--help') || args.includes('-h'); |
| 50 | |
| 51 | if (showHelp) { |
| 52 | printMapUsage(); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | const rootPath = resolveMapRootPath(); |
| 57 | |
| 58 | // Build a minimal project state — same pattern as the MCP resource path. |
| 59 | const baseDir = path.join(rootPath, CODEBASE_CONTEXT_DIRNAME); |
| 60 | const paths = { |
| 61 | baseDir, |
| 62 | memory: path.join(baseDir, MEMORY_FILENAME), |
| 63 | intelligence: path.join(baseDir, INTELLIGENCE_FILENAME), |
| 64 | keywordIndex: path.join(baseDir, KEYWORD_INDEX_FILENAME), |
| 65 | vectorDb: path.join(baseDir, VECTOR_DB_DIRNAME) |
| 66 | }; |
| 67 | |
| 68 | let indexExists = false; |
| 69 | try { |
| 70 | await fs.access(paths.keywordIndex); |
| 71 | indexExists = true; |
| 72 | } catch { |
| 73 | // no index yet |
| 74 | } |
| 75 | |
| 76 | const indexState: IndexState = { status: indexExists ? 'ready' : 'idle' }; |
| 77 | |
| 78 | const project = createProjectState(rootPath); |
| 79 | project.indexState = indexState; |
| 80 | |
| 81 | try { |
| 82 | const map = await buildCodebaseMap(project, { mode: useFull ? 'full' : 'bounded' }); |
| 83 | |
| 84 | if (useExport) { |
| 85 | const outPath = path.join(rootPath, 'CODEBASE_MAP.md'); |
| 86 | await fs.writeFile(outPath, renderMapMarkdown(map), 'utf-8'); |
| 87 | console.log(`Wrote ${outPath}`); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | if (useJson) { |
| 92 | console.log(JSON.stringify(map, null, 2)); |
| 93 | } else if (usePretty) { |
| 94 | console.log(renderMapPretty(map)); |
| 95 | } else { |
| 96 | console.log(renderMapMarkdown(map)); |
| 97 | } |
| 98 | } catch (error) { |
| 99 | console.error( |
| 100 | 'Error building codebase map:', |
| 101 | error instanceof Error ? error.message : String(error) |
no test coverage detected