Skip to content

Commit af76975

Browse files
committed
refactor: clean up formatting and improve readability in multiple files
- Standardized string formatting by removing unnecessary line breaks in descriptions across tools. - Enhanced readability by consolidating filter conditions into single lines in `get-team-patterns.ts` and `search-codebase.ts`. - Improved error handling response structure in `index.ts` for consistency. - Overall, these changes aim to maintain code clarity and consistency throughout the codebase.
1 parent d719801 commit af76975

File tree

5 files changed

+56
-45
lines changed

5 files changed

+56
-45
lines changed

src/index.ts

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ async function generateCodebaseContext(): Promise<string> {
332332
lines.push('# Codebase Intelligence');
333333
lines.push('');
334334
lines.push(
335-
`Index: ${index.status} (${index.confidence}, ${index.action})${index.reason ? ` — ${index.reason}` : ''
335+
`Index: ${index.status} (${index.confidence}, ${index.action})${
336+
index.reason ? ` — ${index.reason}` : ''
336337
}`
337338
);
338339
lines.push('');
@@ -600,30 +601,45 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
600601
// Gate INDEX_CONSUMING tools on a valid, healthy index
601602
let indexSignal: IndexSignal | undefined;
602603
if ((INDEX_CONSUMING_TOOL_NAMES as readonly string[]).includes(name)) {
603-
if (indexState.status === "indexing") {
604+
if (indexState.status === 'indexing') {
604605
return {
605-
content: [{ type: "text", text: JSON.stringify({
606-
status: "indexing",
607-
message: "Index build in progress — please retry shortly",
608-
}) }],
606+
content: [
607+
{
608+
type: 'text',
609+
text: JSON.stringify({
610+
status: 'indexing',
611+
message: 'Index build in progress — please retry shortly'
612+
})
613+
}
614+
]
609615
};
610616
}
611-
if (indexState.status === "error") {
617+
if (indexState.status === 'error') {
612618
return {
613-
content: [{ type: "text", text: JSON.stringify({
614-
status: "error",
615-
message: `Indexer error: ${indexState.error}`,
616-
}) }],
619+
content: [
620+
{
621+
type: 'text',
622+
text: JSON.stringify({
623+
status: 'error',
624+
message: `Indexer error: ${indexState.error}`
625+
})
626+
}
627+
]
617628
};
618629
}
619630
indexSignal = await ensureValidIndexOrAutoHeal();
620-
if (indexSignal.action === "rebuild-failed") {
631+
if (indexSignal.action === 'rebuild-failed') {
621632
return {
622-
content: [{ type: "text", text: JSON.stringify({
623-
error: "Index is corrupt and could not be rebuilt automatically.",
624-
index: indexSignal,
625-
}) }],
626-
isError: true,
633+
content: [
634+
{
635+
type: 'text',
636+
text: JSON.stringify({
637+
error: 'Index is corrupt and could not be rebuilt automatically.',
638+
index: indexSignal
639+
})
640+
}
641+
],
642+
isError: true
627643
};
628644
}
629645
}
@@ -632,7 +648,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
632648
indexState,
633649
paths: PATHS,
634650
rootPath: ROOT_PATH,
635-
performIndexing,
651+
performIndexing
636652
};
637653

638654
const result = await dispatchTool(name, args ?? {}, ctx);
@@ -641,15 +657,25 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
641657
if (indexSignal !== undefined && result.content?.[0]) {
642658
try {
643659
const parsed = JSON.parse(result.content[0].text);
644-
result.content[0] = { type: 'text', text: JSON.stringify({ ...parsed, index: indexSignal }) };
645-
} catch { /* response wasn't JSON, skip injection */ }
660+
result.content[0] = {
661+
type: 'text',
662+
text: JSON.stringify({ ...parsed, index: indexSignal })
663+
};
664+
} catch {
665+
/* response wasn't JSON, skip injection */
666+
}
646667
}
647668

648669
return result;
649670
} catch (error) {
650671
return {
651-
content: [{ type: "text", text: `Unexpected error: ${error instanceof Error ? error.message : String(error)}` }],
652-
isError: true,
672+
content: [
673+
{
674+
type: 'text',
675+
text: `Unexpected error: ${error instanceof Error ? error.message : String(error)}`
676+
}
677+
],
678+
isError: true
653679
};
654680
}
655681
});

src/tools/detect-circular-dependencies.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ export const definition: Tool = {
1414
properties: {
1515
scope: {
1616
type: 'string',
17-
description:
18-
"Optional path prefix to limit analysis (e.g., 'src/features', 'libs/shared')"
17+
description: "Optional path prefix to limit analysis (e.g., 'src/features', 'libs/shared')"
1918
}
2019
}
2120
}

src/tools/get-symbol-references.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ export const definition: Tool = {
1111
properties: {
1212
symbol: {
1313
type: 'string',
14-
description:
15-
'Symbol name to find references for (for example: parseConfig or UserService)'
14+
description: 'Symbol name to find references for (for example: parseConfig or UserService)'
1615
},
1716
limit: {
1817
type: 'number',

src/tools/get-team-patterns.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ export async function handle(
7373
};
7474

7575
const relevantCategories = categoryMap[category || 'all'] || [];
76-
const matchingMemories = allMemories.filter((m) =>
77-
relevantCategories.includes(m.category)
78-
);
76+
const matchingMemories = allMemories.filter((m) => relevantCategories.includes(m.category));
7977

8078
if (matchingMemories.length > 0) {
8179
result.memories = matchingMemories;

src/tools/search-codebase.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ export async function handle(
147147
const searcher = new CodebaseSearcher(ctx.rootPath);
148148
let results: any[];
149149
const searchProfile =
150-
intent && ['explore', 'edit', 'refactor', 'migrate'].includes(intent)
151-
? intent
152-
: 'explore';
150+
intent && ['explore', 'edit', 'refactor', 'migrate'].includes(intent) ? intent : 'explore';
153151

154152
try {
155153
results = await searcher.search(queryStr, limit || 5, filters, {
@@ -252,9 +250,7 @@ export async function handle(
252250
const allImports = intelligence.internalFileGraph.imports as Record<string, string[]>;
253251
for (const [file, deps] of Object.entries(allImports)) {
254252
if (
255-
deps.some((dep: string) =>
256-
resultPaths.some((rp) => dep.endsWith(rp) || rp.endsWith(dep))
257-
)
253+
deps.some((dep: string) => resultPaths.some((rp) => dep.endsWith(rp) || rp.endsWith(dep)))
258254
) {
259255
if (!resultPaths.some((rp) => file.endsWith(rp) || rp.endsWith(file))) {
260256
impactCandidates.push(file);
@@ -267,9 +263,7 @@ export async function handle(
267263
// Build reverse import map from intelligence graph
268264
const reverseImports = new Map<string, string[]>();
269265
if (intelligence?.internalFileGraph?.imports) {
270-
for (const [file, deps] of Object.entries<string[]>(
271-
intelligence.internalFileGraph.imports
272-
)) {
266+
for (const [file, deps] of Object.entries<string[]>(intelligence.internalFileGraph.imports)) {
273267
for (const dep of deps) {
274268
if (!reverseImports.has(dep)) reverseImports.set(dep, []);
275269
reverseImports.get(dep)!.push(file);
@@ -292,9 +286,7 @@ export async function handle(
292286
// imports: files this result depends on (forward lookup)
293287
const imports: string[] = [];
294288
if (intelligence?.internalFileGraph?.imports) {
295-
for (const [file, deps] of Object.entries<string[]>(
296-
intelligence.internalFileGraph.imports
297-
)) {
289+
for (const [file, deps] of Object.entries<string[]>(intelligence.internalFileGraph.imports)) {
298290
if (file.endsWith(rPath) || rPath.endsWith(file)) {
299291
imports.push(...deps);
300292
}
@@ -547,10 +539,7 @@ export async function handle(
547539

548540
// For edit/refactor/migrate: return full preflight card (risk, patterns, impact, etc.).
549541
// For explore or lite-only: return flattened { ready, reason }.
550-
let preflightPayload:
551-
| { ready: boolean; reason?: string }
552-
| Record<string, unknown>
553-
| undefined;
542+
let preflightPayload: { ready: boolean; reason?: string } | Record<string, unknown> | undefined;
554543
if (preflight) {
555544
const el = preflight.evidenceLock;
556545
// Full card per tool schema; add top-level ready/reason for backward compatibility

0 commit comments

Comments
 (0)