debug-toolkit 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +236 -0
- package/SKILL.md +104 -0
- package/dist/capture.d.ts +46 -0
- package/dist/capture.js +246 -0
- package/dist/capture.js.map +1 -0
- package/dist/cleanup.d.ts +12 -0
- package/dist/cleanup.js +103 -0
- package/dist/cleanup.js.map +1 -0
- package/dist/cli.d.ts +40 -0
- package/dist/cli.js +109 -0
- package/dist/cli.js.map +1 -0
- package/dist/context.d.ts +59 -0
- package/dist/context.js +338 -0
- package/dist/context.js.map +1 -0
- package/dist/demo.d.ts +12 -0
- package/dist/demo.js +347 -0
- package/dist/demo.js.map +1 -0
- package/dist/hook.d.ts +17 -0
- package/dist/hook.js +106 -0
- package/dist/hook.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +203 -0
- package/dist/index.js.map +1 -0
- package/dist/injected.js +151 -0
- package/dist/instrument.d.ts +15 -0
- package/dist/instrument.js +87 -0
- package/dist/instrument.js.map +1 -0
- package/dist/mcp.d.ts +14 -0
- package/dist/mcp.js +420 -0
- package/dist/mcp.js.map +1 -0
- package/dist/memory.d.ts +73 -0
- package/dist/memory.js +291 -0
- package/dist/memory.js.map +1 -0
- package/dist/methodology.d.ts +7 -0
- package/dist/methodology.js +100 -0
- package/dist/methodology.js.map +1 -0
- package/dist/proxy.d.ts +12 -0
- package/dist/proxy.js +168 -0
- package/dist/proxy.js.map +1 -0
- package/dist/security.d.ts +27 -0
- package/dist/security.js +158 -0
- package/dist/security.js.map +1 -0
- package/dist/session.d.ts +53 -0
- package/dist/session.js +94 -0
- package/dist/session.js.map +1 -0
- package/package.json +33 -0
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mcp.ts — MCP server with 9 tools + 1 resource.
|
|
3
|
+
*
|
|
4
|
+
* Design principles:
|
|
5
|
+
* 1. One tool = one complete outcome. No chatty multi-step protocols.
|
|
6
|
+
* 2. Preprocess, don't dump. Summarize and highlight, never return raw arrays.
|
|
7
|
+
* 3. Every response tells the agent what to do next.
|
|
8
|
+
* 4. Context window space is precious — keep responses compact.
|
|
9
|
+
* 5. Memory: save diagnoses, recall past fixes for similar errors.
|
|
10
|
+
*/
|
|
11
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
12
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import { basename } from "node:path";
|
|
15
|
+
import { createSession, loadSession, saveSession, newHypothesisId, } from "./session.js";
|
|
16
|
+
import { instrumentFile } from "./instrument.js";
|
|
17
|
+
import { cleanupSession } from "./cleanup.js";
|
|
18
|
+
import { drainCaptures, runAndCapture, getRecentCaptures, readTauriLogs } from "./capture.js";
|
|
19
|
+
import { investigate } from "./context.js";
|
|
20
|
+
import { validateCommand } from "./security.js";
|
|
21
|
+
import { remember, recall, memoryStats } from "./memory.js";
|
|
22
|
+
import { METHODOLOGY } from "./methodology.js";
|
|
23
|
+
let cwd = process.cwd();
|
|
24
|
+
export function setCwd(dir) { cwd = dir; }
|
|
25
|
+
function text(data) {
|
|
26
|
+
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
27
|
+
}
|
|
28
|
+
export function createMcpServer() {
|
|
29
|
+
const server = new McpServer({ name: "debug-toolkit", version: "0.4.0" }, { capabilities: { tools: {}, resources: {} } });
|
|
30
|
+
// ━━━ RESOURCE: debug_methodology ━━━
|
|
31
|
+
// Always-available debugging methodology. The "hot memory" tier.
|
|
32
|
+
server.registerResource("debug_methodology", "debug://methodology", {
|
|
33
|
+
description: "The debugging methodology — how to use debug-toolkit effectively. Read this before your first debugging session.",
|
|
34
|
+
mimeType: "text/markdown",
|
|
35
|
+
}, async () => ({
|
|
36
|
+
contents: [{ uri: "debug://methodology", mimeType: "text/markdown", text: METHODOLOGY }],
|
|
37
|
+
}));
|
|
38
|
+
// ━━━ TOOL 1: debug_investigate ━━━
|
|
39
|
+
// The killer feature. One call: error in, full context out.
|
|
40
|
+
server.registerTool("debug_investigate", {
|
|
41
|
+
title: "Investigate Error",
|
|
42
|
+
description: `The primary debugging tool. Give it an error message or stack trace and it returns:
|
|
43
|
+
- Error classification (type, severity, plain-language suggestion)
|
|
44
|
+
- Source code snippets from the exact files/lines in the stack trace
|
|
45
|
+
- Git context (branch, recent changes to those files)
|
|
46
|
+
- Runtime environment (Node version, frameworks, env vars)
|
|
47
|
+
|
|
48
|
+
This is a COMPLETE investigation — no follow-up calls needed to understand the error.
|
|
49
|
+
Start every debugging session with this tool.`,
|
|
50
|
+
inputSchema: {
|
|
51
|
+
error: z.string().describe("Error message, stack trace, or terminal output"),
|
|
52
|
+
sessionId: z.string().optional().describe("Existing session ID, or omit to auto-create"),
|
|
53
|
+
problem: z.string().optional().describe("Bug description (used if creating new session)"),
|
|
54
|
+
},
|
|
55
|
+
}, async ({ error: errorText, sessionId, problem }) => {
|
|
56
|
+
// Auto-create session if needed
|
|
57
|
+
let session;
|
|
58
|
+
if (sessionId) {
|
|
59
|
+
session = loadSession(cwd, sessionId);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
session = createSession(cwd, problem ?? errorText.split("\n")[0]?.slice(0, 100) ?? "Debug session");
|
|
63
|
+
}
|
|
64
|
+
// Run the investigation engine
|
|
65
|
+
const result = investigate(errorText, cwd);
|
|
66
|
+
// Check memory for past solutions to similar errors
|
|
67
|
+
const pastSolutions = recall(cwd, errorText, 3);
|
|
68
|
+
// Store as capture
|
|
69
|
+
session.captures.push({
|
|
70
|
+
id: `inv_${Date.now()}`, timestamp: new Date().toISOString(),
|
|
71
|
+
source: "environment", markerTag: null, data: { type: "investigation", error: result.error },
|
|
72
|
+
hypothesisId: null,
|
|
73
|
+
});
|
|
74
|
+
saveSession(cwd, session);
|
|
75
|
+
const response = {
|
|
76
|
+
sessionId: session.id,
|
|
77
|
+
error: result.error,
|
|
78
|
+
sourceCode: result.sourceCode.map((s) => ({
|
|
79
|
+
file: s.relativePath,
|
|
80
|
+
errorLine: s.errorLine,
|
|
81
|
+
snippet: s.lines,
|
|
82
|
+
})),
|
|
83
|
+
git: result.git,
|
|
84
|
+
environment: result.environment,
|
|
85
|
+
userFrames: result.frames.filter((f) => f.isUserCode).map((f) => ({
|
|
86
|
+
fn: f.fn,
|
|
87
|
+
file: basename(f.file),
|
|
88
|
+
line: f.line,
|
|
89
|
+
})),
|
|
90
|
+
};
|
|
91
|
+
// Include past solutions if found (with staleness + causal info)
|
|
92
|
+
if (pastSolutions.length > 0) {
|
|
93
|
+
const fresh = pastSolutions.filter((s) => !s.staleness.stale);
|
|
94
|
+
response.pastSolutions = pastSolutions.map((s) => ({
|
|
95
|
+
problem: s.problem,
|
|
96
|
+
diagnosis: s.diagnosis,
|
|
97
|
+
files: s.files,
|
|
98
|
+
relevance: Math.round(s.relevance * 100) + "%",
|
|
99
|
+
stale: s.staleness.stale,
|
|
100
|
+
staleness: s.staleness.stale ? s.staleness.reason : undefined,
|
|
101
|
+
rootCause: s.rootCause ?? undefined,
|
|
102
|
+
}));
|
|
103
|
+
response.nextStep = fresh.length > 0
|
|
104
|
+
? `Found ${fresh.length} fresh past solution(s). Review them before investigating further.`
|
|
105
|
+
: `Found ${pastSolutions.length} past solution(s) but all are outdated (code changed). Investigate fresh.`;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
response.nextStep = result.error.suggestion
|
|
109
|
+
? `Suggested fix: ${result.error.suggestion}`
|
|
110
|
+
: "Use debug_instrument to add logging, then debug_capture to see the output.";
|
|
111
|
+
}
|
|
112
|
+
return text(response);
|
|
113
|
+
});
|
|
114
|
+
// ━━━ TOOL 2: debug_instrument ━━━
|
|
115
|
+
server.registerTool("debug_instrument", {
|
|
116
|
+
title: "Instrument Code",
|
|
117
|
+
description: `Add tagged debug logging to a source file. The logging:
|
|
118
|
+
- Respects the file's indentation
|
|
119
|
+
- Is tagged with a marker (e.g., [DBG_001]) for tracking
|
|
120
|
+
- Can be linked to a hypothesis
|
|
121
|
+
- Auto-cleans when you call debug_cleanup
|
|
122
|
+
|
|
123
|
+
Supports JS/TS/Python/Go.`,
|
|
124
|
+
inputSchema: {
|
|
125
|
+
sessionId: z.string(),
|
|
126
|
+
filePath: z.string().describe("File to instrument"),
|
|
127
|
+
lineNumber: z.number().describe("Insert AFTER this line (0-indexed)"),
|
|
128
|
+
expression: z.string().describe("What to log (e.g., 'req.body', 'state.count')"),
|
|
129
|
+
hypothesis: z.string().optional().describe("What you're testing (auto-creates hypothesis)"),
|
|
130
|
+
},
|
|
131
|
+
}, async ({ sessionId, filePath, lineNumber, expression, hypothesis }) => {
|
|
132
|
+
const session = loadSession(cwd, sessionId);
|
|
133
|
+
// Auto-create hypothesis if description provided
|
|
134
|
+
let hypId;
|
|
135
|
+
if (hypothesis) {
|
|
136
|
+
const hyp = {
|
|
137
|
+
id: newHypothesisId(), text: hypothesis, status: "testing", evidence: [],
|
|
138
|
+
};
|
|
139
|
+
session.hypotheses.push(hyp);
|
|
140
|
+
hypId = hyp.id;
|
|
141
|
+
saveSession(cwd, session);
|
|
142
|
+
}
|
|
143
|
+
const r = instrumentFile({ cwd, session, filePath, lineNumber, expression, hypothesisId: hypId });
|
|
144
|
+
return text({
|
|
145
|
+
markerTag: r.markerTag,
|
|
146
|
+
file: basename(filePath),
|
|
147
|
+
line: lineNumber,
|
|
148
|
+
code: r.insertedCode,
|
|
149
|
+
hypothesis: hypothesis ?? null,
|
|
150
|
+
nextStep: `Run your app and use debug_capture to see [${r.markerTag}] output.`,
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
// ━━━ TOOL 3: debug_capture ━━━
|
|
154
|
+
server.registerTool("debug_capture", {
|
|
155
|
+
title: "Capture Runtime Output",
|
|
156
|
+
description: `Collect runtime output. Two modes:
|
|
157
|
+
1. Run a command and capture its output (e.g., 'npm test', 'curl localhost:3000')
|
|
158
|
+
2. Drain buffered terminal/browser output from the dev server
|
|
159
|
+
|
|
160
|
+
Returns tagged captures linked to hypotheses, plus any errors detected.
|
|
161
|
+
Results are paginated — only the most recent captures are returned.`,
|
|
162
|
+
inputSchema: {
|
|
163
|
+
sessionId: z.string(),
|
|
164
|
+
command: z.string().optional().describe("Command to run (e.g., 'npm test')"),
|
|
165
|
+
limit: z.number().optional().describe("Max results (default 30)"),
|
|
166
|
+
},
|
|
167
|
+
}, async ({ sessionId, command, limit }) => {
|
|
168
|
+
const session = loadSession(cwd, sessionId);
|
|
169
|
+
if (command) {
|
|
170
|
+
const safe = validateCommand(command);
|
|
171
|
+
const caps = await runAndCapture(safe, 30_000);
|
|
172
|
+
session.captures.push(...caps);
|
|
173
|
+
saveSession(cwd, session);
|
|
174
|
+
}
|
|
175
|
+
drainCaptures(cwd, session);
|
|
176
|
+
// Also drain Tauri log files if this is a Tauri project
|
|
177
|
+
const tauriLogs = readTauriLogs(cwd, 30);
|
|
178
|
+
if (tauriLogs.length > 0) {
|
|
179
|
+
session.captures.push(...tauriLogs);
|
|
180
|
+
saveSession(cwd, session);
|
|
181
|
+
}
|
|
182
|
+
const recent = getRecentCaptures(session, { limit: limit ?? 30 });
|
|
183
|
+
// Separate tagged (from instrumentation) vs untagged (ambient) captures
|
|
184
|
+
const tagged = recent.captures.filter((c) => c.markerTag);
|
|
185
|
+
const errors = recent.captures.filter((c) => {
|
|
186
|
+
const d = c.data;
|
|
187
|
+
return d?.stream === "stderr" || d?.text?.toLowerCase().includes("error");
|
|
188
|
+
});
|
|
189
|
+
return text({
|
|
190
|
+
total: recent.total,
|
|
191
|
+
showing: recent.showing,
|
|
192
|
+
tagged: tagged.map((c) => ({
|
|
193
|
+
tag: c.markerTag,
|
|
194
|
+
hypothesis: c.hypothesisId,
|
|
195
|
+
data: c.data,
|
|
196
|
+
})),
|
|
197
|
+
errors: errors.slice(0, 10).map((c) => c.data?.text),
|
|
198
|
+
output: recent.captures.slice(0, 15).map((c) => ({
|
|
199
|
+
source: c.source,
|
|
200
|
+
data: c.data,
|
|
201
|
+
})),
|
|
202
|
+
nextStep: errors.length > 0
|
|
203
|
+
? "Errors detected. Use debug_investigate with the error text for full context."
|
|
204
|
+
: tagged.length > 0
|
|
205
|
+
? "Instrumented output captured. Review tagged data to confirm/reject hypotheses."
|
|
206
|
+
: "No tagged output yet. Make sure the instrumented code path is executed.",
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
// ━━━ TOOL 4: debug_verify ━━━
|
|
210
|
+
// Compound: snapshot + run + diff + assert — all in one call
|
|
211
|
+
server.registerTool("debug_verify", {
|
|
212
|
+
title: "Verify Fix",
|
|
213
|
+
description: `After applying a fix, run this to verify it works. In one call it:
|
|
214
|
+
1. Runs your test/command
|
|
215
|
+
2. Captures all output
|
|
216
|
+
3. Checks for errors
|
|
217
|
+
4. Reports pass/fail
|
|
218
|
+
|
|
219
|
+
Use this before cleanup to confirm the fix actually works.`,
|
|
220
|
+
inputSchema: {
|
|
221
|
+
sessionId: z.string(),
|
|
222
|
+
command: z.string().describe("Command that should succeed after the fix (e.g., 'npm test')"),
|
|
223
|
+
expectNoErrors: z.boolean().optional().describe("Fail if ANY stderr output (default: true)"),
|
|
224
|
+
},
|
|
225
|
+
}, async ({ sessionId, command, expectNoErrors }) => {
|
|
226
|
+
const session = loadSession(cwd, sessionId);
|
|
227
|
+
const safe = validateCommand(command);
|
|
228
|
+
const captures = await runAndCapture(safe, 60_000);
|
|
229
|
+
session.captures.push(...captures);
|
|
230
|
+
saveSession(cwd, session);
|
|
231
|
+
const exitCapture = captures.find((c) => {
|
|
232
|
+
const d = c.data;
|
|
233
|
+
return d?.stream === "meta" && d?.text?.startsWith("exit:");
|
|
234
|
+
});
|
|
235
|
+
const exitCode = exitCapture
|
|
236
|
+
? parseInt(exitCapture.data.text.split(":")[1] ?? "1")
|
|
237
|
+
: null;
|
|
238
|
+
const errors = captures.filter((c) => {
|
|
239
|
+
const d = c.data;
|
|
240
|
+
return d?.stream === "stderr" && d?.text?.toLowerCase().includes("error");
|
|
241
|
+
});
|
|
242
|
+
const noErrors = expectNoErrors !== false;
|
|
243
|
+
const passed = exitCode === 0 && (noErrors ? errors.length === 0 : true);
|
|
244
|
+
return text({
|
|
245
|
+
passed,
|
|
246
|
+
exitCode,
|
|
247
|
+
errorCount: errors.length,
|
|
248
|
+
errors: errors.slice(0, 5).map((c) => c.data?.text),
|
|
249
|
+
output: captures.slice(0, 10).map((c) => c.data?.text),
|
|
250
|
+
nextStep: passed
|
|
251
|
+
? "Fix verified! Use debug_cleanup to remove instrumentation and close the session."
|
|
252
|
+
: "Fix failed. Review the errors above and try a different approach.",
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
// ━━━ TOOL 5: debug_cleanup ━━━
|
|
256
|
+
server.registerTool("debug_cleanup", {
|
|
257
|
+
title: "Cleanup & Close",
|
|
258
|
+
description: `Remove ALL debug instrumentation from source files, verify removal, and close the session.
|
|
259
|
+
Idempotent — safe to call multiple times. Files are restored to their pre-instrumented state.`,
|
|
260
|
+
inputSchema: {
|
|
261
|
+
sessionId: z.string(),
|
|
262
|
+
diagnosis: z.string().optional().describe("Root cause summary (for the session record)"),
|
|
263
|
+
rootCause: z.object({
|
|
264
|
+
trigger: z.string().describe("What caused the error"),
|
|
265
|
+
errorFile: z.string().describe("Where the error manifested"),
|
|
266
|
+
causeFile: z.string().describe("Where the actual bug was"),
|
|
267
|
+
fixDescription: z.string().describe("One-line fix description"),
|
|
268
|
+
}).optional().describe("Causal chain — what caused the error and what fixed it"),
|
|
269
|
+
},
|
|
270
|
+
}, async ({ sessionId, diagnosis, rootCause }) => {
|
|
271
|
+
const session = loadSession(cwd, sessionId);
|
|
272
|
+
if (diagnosis) {
|
|
273
|
+
session.diagnosis = diagnosis;
|
|
274
|
+
saveSession(cwd, session);
|
|
275
|
+
}
|
|
276
|
+
const r = cleanupSession(cwd, session);
|
|
277
|
+
// Save to memory for future recall
|
|
278
|
+
if (diagnosis && session.problem) {
|
|
279
|
+
const errorCap = session.captures.find((c) => c.data?.type === "investigation");
|
|
280
|
+
const errorData = errorCap?.data;
|
|
281
|
+
remember(cwd, {
|
|
282
|
+
id: session.id,
|
|
283
|
+
timestamp: new Date().toISOString(),
|
|
284
|
+
problem: session.problem,
|
|
285
|
+
errorType: errorData?.error?.type ?? "Unknown",
|
|
286
|
+
category: errorData?.error?.category ?? "runtime",
|
|
287
|
+
diagnosis,
|
|
288
|
+
files: session.instrumentation.map((i) => basename(i.filePath)),
|
|
289
|
+
rootCause: rootCause,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
const stats = memoryStats(cwd);
|
|
293
|
+
return text({
|
|
294
|
+
cleaned: r.cleaned,
|
|
295
|
+
verified: r.verified,
|
|
296
|
+
files: r.filesProcessed.map((f) => basename(f)),
|
|
297
|
+
errors: r.errors.length > 0 ? r.errors : undefined,
|
|
298
|
+
savedToMemory: !!diagnosis,
|
|
299
|
+
memoryEntries: stats.entries,
|
|
300
|
+
message: r.verified
|
|
301
|
+
? `Done. ${r.cleaned} file(s) cleaned.${diagnosis ? " Diagnosis saved to memory." : ""}`
|
|
302
|
+
: `Cleanup had issues: ${r.errors.join(", ")}`,
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
// ━━━ TOOL 7: debug_recall ━━━
|
|
306
|
+
server.registerTool("debug_recall", {
|
|
307
|
+
title: "Recall Past Solutions",
|
|
308
|
+
description: `Search debug memory for past solutions to similar errors.
|
|
309
|
+
Returns past diagnoses ranked by relevance. Check this BEFORE deep investigation —
|
|
310
|
+
the same error may have been solved before in this project.`,
|
|
311
|
+
inputSchema: {
|
|
312
|
+
query: z.string().describe("Error message, error type, or description to search for"),
|
|
313
|
+
limit: z.number().optional().describe("Max results (default: 5)"),
|
|
314
|
+
},
|
|
315
|
+
}, async ({ query, limit }) => {
|
|
316
|
+
const matches = recall(cwd, query, limit ?? 5);
|
|
317
|
+
const stats = memoryStats(cwd);
|
|
318
|
+
if (matches.length === 0) {
|
|
319
|
+
return text({
|
|
320
|
+
matches: [],
|
|
321
|
+
memoryEntries: stats.entries,
|
|
322
|
+
message: stats.entries === 0
|
|
323
|
+
? "No debug memory yet. Complete a debug session with a diagnosis to start building memory."
|
|
324
|
+
: `No matches found in ${stats.entries} stored sessions. This is a new error.`,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
const staleCount = matches.filter((m) => m.staleness.stale).length;
|
|
328
|
+
return text({
|
|
329
|
+
matches: matches.map((m) => ({
|
|
330
|
+
problem: m.problem,
|
|
331
|
+
errorType: m.errorType,
|
|
332
|
+
diagnosis: m.diagnosis,
|
|
333
|
+
files: m.files,
|
|
334
|
+
relevance: Math.round(m.relevance * 100) + "%",
|
|
335
|
+
date: m.timestamp,
|
|
336
|
+
stale: m.staleness.stale,
|
|
337
|
+
staleness: m.staleness.stale ? m.staleness.reason : undefined,
|
|
338
|
+
rootCause: m.rootCause ?? undefined,
|
|
339
|
+
})),
|
|
340
|
+
message: `Found ${matches.length} past solution(s).${staleCount > 0 ? ` ${staleCount} may be outdated (code has changed since).` : ""} Top match: "${matches[0].diagnosis}"`,
|
|
341
|
+
nextStep: staleCount === matches.length
|
|
342
|
+
? "All past solutions are outdated — code has changed. Investigate fresh with debug_investigate."
|
|
343
|
+
: "If a past solution applies, try the same fix. Otherwise proceed with debug_investigate.",
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
// ━━━ TOOL 8: debug_patterns ━━━
|
|
347
|
+
server.registerTool("debug_patterns", {
|
|
348
|
+
title: "Detect Bug Patterns",
|
|
349
|
+
description: `Analyze debug memory to detect patterns across all past sessions:
|
|
350
|
+
- Recurring errors (same error type in same file, 3+ times)
|
|
351
|
+
- Hot files (files that appear in many debug sessions)
|
|
352
|
+
- Regressions (bugs that were fixed but came back)
|
|
353
|
+
- Error clusters (multiple errors in a short time window — cascading failures)
|
|
354
|
+
|
|
355
|
+
Use this periodically to understand your project's debugging health.`,
|
|
356
|
+
inputSchema: {},
|
|
357
|
+
}, async () => {
|
|
358
|
+
const stats = memoryStats(cwd);
|
|
359
|
+
if (stats.entries === 0) {
|
|
360
|
+
return text({
|
|
361
|
+
patterns: [],
|
|
362
|
+
message: "No debug memory yet. Complete debug sessions to start detecting patterns.",
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
const patterns = stats.patterns;
|
|
366
|
+
const critical = patterns.filter((p) => p.severity === "critical");
|
|
367
|
+
const warnings = patterns.filter((p) => p.severity === "warning");
|
|
368
|
+
return text({
|
|
369
|
+
memoryEntries: stats.entries,
|
|
370
|
+
patterns: patterns.map((p) => ({
|
|
371
|
+
type: p.type,
|
|
372
|
+
severity: p.severity,
|
|
373
|
+
message: p.message,
|
|
374
|
+
details: p.data,
|
|
375
|
+
})),
|
|
376
|
+
summary: patterns.length === 0
|
|
377
|
+
? `${stats.entries} sessions analyzed. No concerning patterns detected.`
|
|
378
|
+
: `${patterns.length} pattern(s) found: ${critical.length} critical, ${warnings.length} warnings.`,
|
|
379
|
+
nextStep: critical.length > 0
|
|
380
|
+
? `Critical: ${critical[0].message}. Consider refactoring this code.`
|
|
381
|
+
: patterns.length > 0
|
|
382
|
+
? `Top finding: ${patterns[0].message}`
|
|
383
|
+
: undefined,
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
// ━━━ TOOL 9: debug_session ━━━
|
|
387
|
+
server.registerTool("debug_session", {
|
|
388
|
+
title: "Session Status",
|
|
389
|
+
description: `Get current session state: hypotheses, active instruments, recent captures.
|
|
390
|
+
Lightweight — returns a summary, not the full capture history.`,
|
|
391
|
+
inputSchema: {
|
|
392
|
+
sessionId: z.string(),
|
|
393
|
+
},
|
|
394
|
+
}, async ({ sessionId }) => {
|
|
395
|
+
const session = loadSession(cwd, sessionId);
|
|
396
|
+
const recent = getRecentCaptures(session, { limit: 10 });
|
|
397
|
+
return text({
|
|
398
|
+
id: session.id,
|
|
399
|
+
status: session.status,
|
|
400
|
+
problem: session.problem,
|
|
401
|
+
hypotheses: session.hypotheses.map((h) => ({
|
|
402
|
+
id: h.id, text: h.text, status: h.status, evidenceCount: h.evidence.length,
|
|
403
|
+
})),
|
|
404
|
+
instruments: session.instrumentation.filter((i) => i.active).map((i) => ({
|
|
405
|
+
tag: i.markerTag, file: basename(i.filePath), line: i.lineNumber, hypothesis: i.hypothesisId,
|
|
406
|
+
})),
|
|
407
|
+
recentCaptures: recent.showing > 0
|
|
408
|
+
? { count: recent.total, recent: recent.captures.slice(0, 5).map((c) => ({ source: c.source, tag: c.markerTag, data: c.data })) }
|
|
409
|
+
: null,
|
|
410
|
+
diagnosis: session.diagnosis,
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
return server;
|
|
414
|
+
}
|
|
415
|
+
export async function startMcpServer() {
|
|
416
|
+
const server = createMcpServer();
|
|
417
|
+
const transport = new StdioServerTransport();
|
|
418
|
+
await server.connect(transport);
|
|
419
|
+
}
|
|
420
|
+
//# sourceMappingURL=mcp.js.map
|
package/dist/mcp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EACL,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,GAEzD,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,aAAa,EAAqB,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,WAAW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
|
4
|
+
* Three tiers of intelligence:
|
|
5
|
+
* 1. Recall — search past diagnoses for similar errors (keyword overlap)
|
|
6
|
+
* 2. Staleness — flag outdated diagnoses when code has changed since
|
|
7
|
+
* 3. Patterns — detect recurring errors, hot files, regression trends
|
|
8
|
+
*
|
|
9
|
+
* Implementation: JSON file + in-memory inverted index.
|
|
10
|
+
* Zero native dependencies. Fast enough for hundreds of sessions.
|
|
11
|
+
*/
|
|
12
|
+
export interface MemoryEntry {
|
|
13
|
+
id: string;
|
|
14
|
+
timestamp: string;
|
|
15
|
+
problem: string;
|
|
16
|
+
errorType: string;
|
|
17
|
+
category: string;
|
|
18
|
+
diagnosis: string;
|
|
19
|
+
files: string[];
|
|
20
|
+
keywords: string[];
|
|
21
|
+
gitSha: string | null;
|
|
22
|
+
rootCause: CausalLink | null;
|
|
23
|
+
}
|
|
24
|
+
export interface CausalLink {
|
|
25
|
+
trigger: string;
|
|
26
|
+
errorFile: string;
|
|
27
|
+
causeFile: string;
|
|
28
|
+
fixDescription: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Check staleness of a memory entry — have the referenced files changed?
|
|
32
|
+
*/
|
|
33
|
+
export interface StalenessInfo {
|
|
34
|
+
stale: boolean;
|
|
35
|
+
reason: string | null;
|
|
36
|
+
commitsBehind: number;
|
|
37
|
+
filesChanged: string[];
|
|
38
|
+
}
|
|
39
|
+
export interface PatternInsight {
|
|
40
|
+
type: "recurring_error" | "hot_file" | "regression" | "error_cluster";
|
|
41
|
+
severity: "info" | "warning" | "critical";
|
|
42
|
+
message: string;
|
|
43
|
+
data: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Detect patterns across all stored debug sessions.
|
|
47
|
+
* Cheap — just scans the JSON array, no external calls.
|
|
48
|
+
*/
|
|
49
|
+
export declare function detectPatterns(cwd: string): PatternInsight[];
|
|
50
|
+
/**
|
|
51
|
+
* Save a completed debug session to memory.
|
|
52
|
+
* Auto-captures the current git SHA for staleness tracking.
|
|
53
|
+
*/
|
|
54
|
+
export declare function remember(cwd: string, entry: Omit<MemoryEntry, "keywords" | "gitSha" | "rootCause"> & {
|
|
55
|
+
rootCause?: CausalLink | null;
|
|
56
|
+
}): MemoryEntry;
|
|
57
|
+
/**
|
|
58
|
+
* Search past debug sessions for similar errors.
|
|
59
|
+
* Returns matches ranked by relevance, with staleness info and causal chains.
|
|
60
|
+
*/
|
|
61
|
+
export declare function recall(cwd: string, query: string, limit?: number): Array<MemoryEntry & {
|
|
62
|
+
relevance: number;
|
|
63
|
+
staleness: StalenessInfo;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Get memory stats.
|
|
67
|
+
*/
|
|
68
|
+
export declare function memoryStats(cwd: string): {
|
|
69
|
+
entries: number;
|
|
70
|
+
oldestDate: string | null;
|
|
71
|
+
newestDate: string | null;
|
|
72
|
+
patterns: PatternInsight[];
|
|
73
|
+
};
|