MCPcopy Index your code
hub / github.com/PatrickSys/codebase-context / handleMapCli

Function handleMapCli

src/cli-map.ts:44–105  ·  view source on GitHub ↗
(args: string[])

Source from the content-addressed store, hash-verified

42}
43
44export 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)

Callers 2

handleCliCommandFunction · 0.85

Calls 6

printMapUsageFunction · 0.85
resolveMapRootPathFunction · 0.85
createProjectStateFunction · 0.85
buildCodebaseMapFunction · 0.85
renderMapMarkdownFunction · 0.85
renderMapPrettyFunction · 0.85

Tested by

no test coverage detected