checkpoint
Create a checkpoint before modifying, deleting, or creating files to enable undo functionality. Ensures safe file operations by saving states prior to changes.
Instructions
MANDATORY: ALWAYS call this function FIRST before making ANY file modifications, deletions, or creations. This creates a checkpoint to enable undo functionality. This must be called before every single file operation - no exceptions. Never modify files without calling checkpoint first.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | No | Concise, action-focused description of the next specific change to be made | Manual checkpoint |
| files | Yes | Array of file paths that will be modified, created, or deleted |
Implementation Reference
- src/index.ts:88-103 (handler)MCP tool handler for 'checkpoint': validates input arguments, invokes ChangeTracker.createCheckpoint, formats and returns success response with captured files.case "checkpoint": { const files = args?.files as string[]; const description = (args?.description as string) || "Manual checkpoint"; if (!files || files.length === 0) { throw new Error("Files array is required"); } await changeTracker.createCheckpoint(files, description); return { content: [ { type: "text", text: `✅ Checkpoint created: "${description}"\nFiles captured: ${files.length}\n${files.map(f => ` - ${f}`).join('\n')}`, }, ], }; }
- src/index.ts:25-44 (schema)Tool schema definition for 'checkpoint' including name, description, and inputSchema specifying required 'files' array and optional 'description'.{ name: "checkpoint", description: "MANDATORY: ALWAYS call this function FIRST before making ANY file modifications, deletions, or creations. This creates a checkpoint to enable undo functionality. This must be called before every single file operation - no exceptions. Never modify files without calling checkpoint first.", inputSchema: { type: "object", properties: { files: { type: "array", items: { type: "string" }, description: "Array of file paths that will be modified, created, or deleted", }, description: { type: "string", description: "Concise, action-focused description of the next specific change to be made", default: "Manual checkpoint", }, }, required: ["files"], }, },
- src/index.ts:79-81 (registration)Registers the list of available tools, including 'checkpoint', for the ListToolsRequestSchema.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS, }));
- src/changeTracker.ts:14-43 (helper)Core implementation of checkpoint creation in ChangeTracker class: reads current file contents, identifies new files, creates UndoCheckpoint, pushes to undo stack.async createCheckpoint(files: string[], description: string = "Manual checkpoint"): Promise<void> { const fileContents = new Map<string, string>(); const createdFiles = new Set<string>(); console.error(`[DEBUG] Creating checkpoint: ${description}`); console.error(`[DEBUG] Files to checkpoint: ${files.join(', ')}`); for (const filepath of files) { if (!existsSync(filepath)) { console.error(`[DEBUG] File will be created: ${filepath}`); createdFiles.add(filepath); } else { const content = readFileSync(filepath, "utf-8"); fileContents.set(filepath, content); console.error(`[DEBUG] Captured content for ${filepath}: ${content.length} characters`); } } const checkpoint: UndoCheckpoint = { files: fileContents, createdFiles, timestamp: new Date(), description, }; this.undoStack.push(checkpoint); console.error(`[DEBUG] Checkpoint created. Stack size: ${this.undoStack.length}`); console.error(`[DEBUG] Files to be created: ${Array.from(createdFiles).join(', ') || 'none'}`); console.error(`[DEBUG] Existing files captured: ${fileContents.size}`); }
- src/changeTracker.ts:4-9 (helper)Type definition for UndoCheckpoint used by the checkpoint system.interface UndoCheckpoint { files: Map<string, string>; // filepath -> content createdFiles: Set<string>; // files that were created (didn't exist before) timestamp: Date; description: string; }