remove_instruments
Remove debug instrumentation from code files to clean up after debugging sessions. Specify a file path or clear all instrumented files.
Instructions
Remove debug instruments from files.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | No | Path to file to remove instruments from. If not specified, removes from all instrumented files. |
Implementation Reference
- src/index.ts:209-250 (handler)Main execution logic for the remove_instruments tool. Handles removal from a specific file or all files by coordinating with Instrumenter and SessionManager.case 'remove_instruments': { if (!sessionManager.isActive() || !instrumenter) { return { content: [{ type: 'text', text: 'No active debug session.' }], isError: true, }; } const file = args?.file as string | undefined; if (file) { // Remove from specific file const instruments = sessionManager.getInstrumentsByFile(file); for (const instrument of instruments) { instrumenter.removeInstrument(instrument); sessionManager.removeInstrument(instrument.id); } return { content: [ { type: 'text', text: `Removed ${instruments.length} instrument(s) from ${file}`, }, ], }; } else { // Remove from all files const instruments = sessionManager.getInstruments(); for (const instrument of instruments) { instrumenter.removeInstrument(instrument); } sessionManager.clearInstruments(); return { content: [ { type: 'text', text: `Removed ${instruments.length} instrument(s) from all files`, }, ], }; } }
- src/index.ts:80-92 (schema)Input schema definition for the remove_instruments tool, defining the optional 'file' parameter.{ name: 'remove_instruments', description: 'Remove debug instruments from files.', inputSchema: { type: 'object', properties: { file: { type: 'string', description: 'Path to file to remove instruments from. If not specified, removes from all instrumented files.', }, }, }, },
- src/instrumenter.ts:40-56 (helper)Instrumenter.removeInstrument: Core logic to remove the instrumentation code block from the target file using region-based regex removal.removeInstrument(instrument: Instrument): boolean { if (!existsSync(instrument.file)) { return false; } const content = readFileSync(instrument.file, 'utf-8'); const regionId = `${REGION_PREFIX}-${instrument.id}`; const newContent = this.removeRegion(content, regionId, instrument.language); if (newContent !== content) { writeFileSync(instrument.file, newContent); return true; } return false; }
- src/session.ts:78-83 (helper)SessionManager.removeInstrument: Removes instrument tracking entry from the session's internal instruments Map.removeInstrument(id: string): boolean { if (!this.session) { throw new Error('No active debug session'); } return this.session.instruments.delete(id); }
- src/session.ts:97-101 (helper)SessionManager.clearInstruments: Clears all instrument tracking from the session.clearInstruments(): void { if (this.session) { this.session.instruments.clear(); } }