Skip to content

Commit b4e0275

Browse files
committed
refactor: clean up CLI command output and improve error message formatting
- Consolidated console.log statements in src/cli.ts for better readability. - Enhanced error message formatting in src/core/symbol-references.ts and src/tools/search-codebase.ts for consistency. - Streamlined conditional object construction in src/tools/search-codebase.ts for clarity.
1 parent 1676134 commit b4e0275

File tree

5 files changed

+35
-31
lines changed

5 files changed

+35
-31
lines changed

src/cli.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,14 @@ function printUsage(): void {
5151
console.log('');
5252
console.log('Commands:');
5353
console.log(' memory <list|add|remove> Memory CRUD');
54-
console.log(
55-
' search --query <q> Search the indexed codebase'
56-
);
54+
console.log(' search --query <q> Search the indexed codebase');
5755
console.log(' [--intent explore|edit|refactor|migrate]');
5856
console.log(' [--limit <n>] [--lang <l>] [--framework <f>] [--layer <l>]');
5957
console.log(' metadata Project structure, frameworks, deps');
6058
console.log(' status Index state and progress');
6159
console.log(' reindex [--incremental] [--reason <r>] Re-index the codebase');
6260
console.log(' style-guide [--query <q>] [--category <c>] Style guide rules');
63-
console.log(
64-
' patterns [--category all|di|state|testing|libraries] Team patterns'
65-
);
61+
console.log(' patterns [--category all|di|state|testing|libraries] Team patterns');
6662
console.log(' refs --symbol <name> [--limit <n>] Symbol references');
6763
console.log(' cycles [--scope <path>] Circular dependency detection');
6864
console.log('');
@@ -202,9 +198,15 @@ export async function handleCliCommand(argv: string[]): Promise<void> {
202198
query: flags['query'],
203199
...(flags['intent'] ? { intent: flags['intent'] } : {}),
204200
...(flags['limit'] ? { limit: Number(flags['limit']) } : {}),
205-
...(flags['lang'] ? { filters: { language: flags['lang'] } } : {}),
206-
...(flags['framework'] ? { filters: { framework: flags['framework'] } } : {}),
207-
...(flags['layer'] ? { filters: { layer: flags['layer'] } } : {})
201+
...(flags['lang'] || flags['framework'] || flags['layer']
202+
? {
203+
filters: {
204+
...(flags['lang'] ? { language: flags['lang'] } : {}),
205+
...(flags['framework'] ? { framework: flags['framework'] } : {}),
206+
...(flags['layer'] ? { layer: flags['layer'] } : {})
207+
}
208+
}
209+
: {})
208210
};
209211
break;
210212
}

src/core/symbol-references.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ export async function findSymbolReferences(
8383
chunksRaw = JSON.parse(content);
8484
} catch (error) {
8585
throw new IndexCorruptedError(
86-
`Keyword index missing or unreadable (rebuild required): ${error instanceof Error ? error.message : String(error)
86+
`Keyword index missing or unreadable (rebuild required): ${
87+
error instanceof Error ? error.message : String(error)
8788
}`
8889
);
8990
}

src/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import {
2020
Resource
2121
} from '@modelcontextprotocol/sdk/types.js';
2222
import { CodebaseIndexer } from './core/indexer.js';
23-
import type {
24-
IndexingStats
25-
} from './types/index.js';
23+
import type { IndexingStats } from './types/index.js';
2624
import { analyzerRegistry } from './core/analyzer-registry.js';
2725
import { AngularAnalyzer } from './analyzers/angular/index.js';
2826
import { GenericAnalyzer } from './analyzers/generic/index.js';
@@ -34,9 +32,7 @@ import {
3432
KEYWORD_INDEX_FILENAME,
3533
VECTOR_DB_DIRNAME
3634
} from './constants/codebase-context.js';
37-
import {
38-
appendMemoryFile
39-
} from './memory/store.js';
35+
import { appendMemoryFile } from './memory/store.js';
4036
import { handleCliCommand } from './cli.js';
4137
import { parseGitLogLineToMemory } from './memory/git-memory.js';
4238
import {
@@ -314,7 +310,8 @@ async function generateCodebaseContext(): Promise<string> {
314310
lines.push('# Codebase Intelligence');
315311
lines.push('');
316312
lines.push(
317-
`Index: ${index.status} (${index.confidence}, ${index.action})${index.reason ? ` — ${index.reason}` : ''
313+
`Index: ${index.status} (${index.confidence}, ${index.action})${
314+
index.reason ? ` — ${index.reason}` : ''
318315
}`
319316
);
320317
lines.push('');

src/preflight/evidence-lock.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export function buildEvidenceLock(input: BuildEvidenceLockInput): EvidenceLock {
165165
stressTriggers.push('Insufficient evidence: most evidence sources are empty');
166166
}
167167

168-
// Trigger: low caller coverage
168+
// Trigger: low caller coverage
169169
if (
170170
input.impactCoverage &&
171171
input.impactCoverage.total > 3 &&
@@ -214,9 +214,7 @@ export function buildEvidenceLock(input: BuildEvidenceLockInput): EvidenceLock {
214214
if (!readyToEdit) {
215215
// Code evidence weak/missing
216216
if (codeStrength === 'weak' || codeStrength === 'missing') {
217-
whatWouldHelp.push(
218-
'Search with a more specific query targeting the implementation files'
219-
);
217+
whatWouldHelp.push('Search with a more specific query targeting the implementation files');
220218
}
221219

222220
// Pattern evidence missing

src/tools/search-codebase.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ export async function handle(
175175
text: JSON.stringify(
176176
{
177177
status: 'error',
178-
message: `Auto-heal retry failed: ${retryError instanceof Error ? retryError.message : String(retryError)
179-
}`
178+
message: `Auto-heal retry failed: ${
179+
retryError instanceof Error ? retryError.message : String(retryError)
180+
}`
180181
},
181182
null,
182183
2
@@ -312,7 +313,8 @@ export async function handle(
312313
function buildRelationshipHints(result: SearchResult): RelationshipHints {
313314
const rPath = result.filePath;
314315
// Graph keys are relative paths with forward slashes; normalize for comparison
315-
const rPathNorm = path.relative(ctx.rootPath, rPath).replace(/\\/g, '/') || rPath.replace(/\\/g, '/');
316+
const rPathNorm =
317+
path.relative(ctx.rootPath, rPath).replace(/\\/g, '/') || rPath.replace(/\\/g, '/');
316318

317319
// importedBy: files that import this result (reverse lookup), collect with counts
318320
const importedByMap = new Map<string, number>();
@@ -394,7 +396,6 @@ export async function handle(
394396
const resultPaths = results.map((r) => r.filePath);
395397
const impactCandidates = computeImpactCandidates(resultPaths);
396398

397-
398399
// Use existing pattern intelligence for evidenceLock scoring, but keep the output payload lite.
399400
const preferredPatternsForEvidence: Array<{ pattern: string; example?: string }> = [];
400401
const patterns = intelligence.patterns || {};
@@ -410,7 +411,6 @@ export async function handle(
410411
}
411412
}
412413

413-
414414
let riskLevel: 'low' | 'medium' | 'high' = 'low';
415415
if (impactCandidates.length > 10) {
416416
riskLevel = 'high';
@@ -620,8 +620,12 @@ export async function handle(
620620
}
621621

622622
// Add patterns (do/avoid, capped at 3 each, with adoption %)
623-
const doPatterns = preferredPatternsForOutput.slice(0, 3).map((p) => `${p.pattern}${p.adoption ? ` ${p.adoption}% adoption` : ''}`);
624-
const avoidPatterns = avoidPatternsForOutput.slice(0, 3).map((p) => `${p.pattern}${p.adoption ? ` ${p.adoption}% adoption` : ''} (declining)`);
623+
const doPatterns = preferredPatternsForOutput
624+
.slice(0, 3)
625+
.map((p) => `${p.pattern}${p.adoption ? ` ${p.adoption}% adoption` : ''}`);
626+
const avoidPatterns = avoidPatternsForOutput
627+
.slice(0, 3)
628+
.map((p) => `${p.pattern}${p.adoption ? ` ${p.adoption}% adoption` : ''} (declining)`);
625629
if (doPatterns.length > 0 || avoidPatterns.length > 0) {
626630
decisionCard.patterns = {
627631
...(doPatterns.length > 0 && { do: doPatterns }),
@@ -720,8 +724,8 @@ export async function handle(
720724
confidence: searchQuality.confidence,
721725
...(searchQuality.status === 'low_confidence' &&
722726
searchQuality.nextSteps?.[0] && {
723-
hint: searchQuality.nextSteps[0]
724-
})
727+
hint: searchQuality.nextSteps[0]
728+
})
725729
},
726730
...(preflightPayload && { preflight: preflightPayload }),
727731
results: results.map((r) => {
@@ -737,7 +741,9 @@ export async function handle(
737741
...(r.componentType && r.layer && { type: `${r.componentType}:${r.layer}` }),
738742
...(r.trend && r.trend !== 'Stable' && { trend: r.trend }),
739743
...(r.patternWarning && { patternWarning: r.patternWarning }),
740-
...(relationshipsAndHints.relationships && { relationships: relationshipsAndHints.relationships }),
744+
...(relationshipsAndHints.relationships && {
745+
relationships: relationshipsAndHints.relationships
746+
}),
741747
...(relationshipsAndHints.hints && { hints: relationshipsAndHints.hints }),
742748
...(enrichedSnippet && { snippet: enrichedSnippet })
743749
};

0 commit comments

Comments
 (0)