-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathformat.ts
More file actions
204 lines (172 loc) · 5.03 KB
/
format.ts
File metadata and controls
204 lines (172 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/**
* Formatting utilities for MCP tool responses
*/
import { isRepoError, type SyncResult } from "../tools/sync.js";
import type { SearchResult, FileInfo } from "./search.js";
import type { SyncMetadata } from "./sync-metadata.js";
import type { ErrorLookupResult } from "./error-lookup.js";
export function formatSyncResult(result: SyncResult): string {
const lines = [
result.success ? "✓ Sync completed" : "⚠ Sync completed with errors",
"",
`Version: ${result.version}`,
result.message,
"",
"Repositories:",
];
for (const repo of result.repos) {
const icon = isRepoError(repo) ? "✗" : "✓";
lines.push(` ${icon} ${repo.name}: ${repo.status}`);
}
return lines.join("\n");
}
export function formatStatus(status: {
reposDir: string;
repos: {
name: string;
description: string;
cloned: boolean;
commit?: string;
}[];
syncMetadata?: SyncMetadata | null;
}): string {
const lines = [
"Aztec MCP Server Status",
"",
`Repos directory: ${status.reposDir}`,
];
if (status.syncMetadata) {
lines.push(`Last synced: ${status.syncMetadata.syncedAt}`);
lines.push(`MCP server version: ${status.syncMetadata.mcpVersion}`);
lines.push(`Aztec version: ${status.syncMetadata.aztecVersion}`);
}
lines.push("");
lines.push("Repositories:");
for (const repo of status.repos) {
const icon = repo.cloned ? "✓" : "○";
const commit = repo.commit ? ` (${repo.commit})` : "";
lines.push(` ${icon} ${repo.name}${commit}`);
lines.push(` ${repo.description}`);
}
const clonedCount = status.repos.filter((r) => r.cloned).length;
if (clonedCount === 0) {
lines.push("");
lines.push("No repositories cloned. Run aztec_sync_repos to get started.");
}
return lines.join("\n");
}
export function formatSearchResults(result: {
success: boolean;
results: SearchResult[];
message: string;
}): string {
const lines = [result.message, ""];
if (!result.success || result.results.length === 0) {
return lines.join("\n");
}
for (const match of result.results) {
lines.push(`**${match.file}:${match.line}**`);
lines.push("```");
lines.push(match.content);
lines.push("```");
lines.push("");
}
return lines.join("\n");
}
export function formatExamplesList(result: {
success: boolean;
examples: FileInfo[];
message: string;
}): string {
const lines = [result.message, ""];
if (!result.success || result.examples.length === 0) {
return lines.join("\n");
}
// Group by repo
const byRepo = new Map<string, FileInfo[]>();
for (const example of result.examples) {
if (!byRepo.has(example.repo)) {
byRepo.set(example.repo, []);
}
byRepo.get(example.repo)!.push(example);
}
for (const [repo, examples] of byRepo) {
lines.push(`**${repo}:**`);
for (const example of examples) {
lines.push(` - ${example.name}`);
}
lines.push("");
}
return lines.join("\n");
}
export function formatExampleContent(result: {
success: boolean;
example?: FileInfo;
content?: string;
message: string;
}): string {
if (!result.success || !result.content) {
return result.message;
}
const lines = [
`**${result.example!.name}** (${result.example!.repo})`,
`Path: ${result.example!.path}`,
"",
"```noir",
result.content,
"```",
];
return lines.join("\n");
}
export function formatFileContent(result: {
success: boolean;
content?: string;
message: string;
}): string {
if (!result.success || !result.content) {
return result.message;
}
return result.content;
}
export function formatErrorLookupResult(result: {
success: boolean;
result: ErrorLookupResult;
message: string;
}): string {
const lines = [result.message, ""];
const { catalogMatches, codeMatches } = result.result;
if (catalogMatches.length > 0) {
lines.push("## Known Errors");
lines.push("");
for (const m of catalogMatches) {
const { entry } = m;
lines.push(`**${entry.name}**`);
if (entry.errorCode !== undefined) lines.push(`- Code: ${entry.errorCode}`);
if (entry.hexSignature) lines.push(`- Hex: ${entry.hexSignature}`);
lines.push(`- Category: ${entry.category}`);
lines.push(`- Source: ${entry.source}`);
lines.push(`- Match: ${m.matchType} (score ${m.score})`);
lines.push(`- **Cause**: ${entry.cause}`);
lines.push(`- **Fix**: ${entry.fix}`);
lines.push("");
}
}
if (codeMatches.length > 0) {
lines.push("## Related Code References");
lines.push("");
for (const match of codeMatches) {
lines.push(`**${match.file}:${match.line}**`);
lines.push("```");
lines.push(match.content);
lines.push("```");
lines.push("");
}
}
if (catalogMatches.length === 0 && codeMatches.length === 0) {
lines.push("No matching errors found. Try:");
lines.push("- A numeric error code (e.g., `2002`)");
lines.push("- A hex signature (e.g., `0xa5b2ba17`)");
lines.push("- An error message substring (e.g., `insufficient fee`)");
}
return lines.join("\n");
}