Skip to content

Commit 344a645

Browse files
committed
fix: surface tool errors before formatter routing; render libraries topUsed
P1: tools return { status: 'error', message } without setting isError on the MCP envelope. formatJson now detects this before routing to a command formatter, which would otherwise render a misleading empty box. P2: get_team_patterns --category libraries returns topUsed instead of patterns. Add LibraryEntry type, make PatternResponse.patterns optional, and render topUsed in formatPatterns under a TOP LIBRARIES section.
1 parent c22264b commit 344a645

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/cli-formatters.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import path from 'path';
77
import type {
88
PatternResponse,
99
PatternEntry,
10+
LibraryEntry,
1011
SearchResponse,
1112
SearchResultItem,
1213
RefsResponse,
@@ -153,6 +154,18 @@ export function formatPatterns(data: PatternResponse): void {
153154
}
154155
}
155156

157+
const topUsed = data.topUsed;
158+
if (topUsed && topUsed.length > 0) {
159+
lines.push('');
160+
lines.push('\u2500'.repeat(66));
161+
lines.push('');
162+
lines.push('TOP LIBRARIES');
163+
for (const lib of topUsed.slice(0, 15) as LibraryEntry[]) {
164+
const src = padRight(lib.source ?? '', 52);
165+
lines.push(` ${src} ${lib.count} imports`);
166+
}
167+
}
168+
156169
if (goldenFiles && goldenFiles.length > 0) {
157170
lines.push('');
158171
lines.push('\u2500'.repeat(66));
@@ -607,6 +620,16 @@ export function formatJson(
607620
return;
608621
}
609622

623+
// Tools return { status: 'error', message: '...' } in their JSON payload but
624+
// don't always set isError on the MCP envelope. Route these to stderr before
625+
// a command formatter would render a misleading empty box.
626+
if (typeof data === 'object' && data !== null && (data as Record<string, unknown>).status === 'error') {
627+
const d = data as Record<string, unknown>;
628+
const msg = typeof d.message === 'string' ? d.message : JSON.stringify(d, null, 2);
629+
process.stderr.write(`Error: ${msg}\n`);
630+
return;
631+
}
632+
610633
switch (command) {
611634
case 'metadata': {
612635
try {

src/tools/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,17 @@ export interface GoldenFile {
105105
score: number;
106106
}
107107

108+
export interface LibraryEntry {
109+
source: string;
110+
count: number;
111+
}
112+
108113
export interface PatternResponse {
109-
patterns: Record<string, PatternCategory>;
114+
patterns?: Record<string, PatternCategory>;
110115
goldenFiles?: GoldenFile[];
111116
memories?: Array<{ type: string; memory: string }>;
112117
conflicts?: PatternConflict[];
118+
topUsed?: LibraryEntry[];
113119
}
114120

115121
// --- Metadata response types ---

0 commit comments

Comments
 (0)