validate_action
Check if an action follows critical safety rules before performing it on a target file to ensure disciplined programming practices.
Instructions
Check if an action follows critical safety rules
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | The action you want to take | |
| targetFile | Yes | The file you want to act on |
Implementation Reference
- src/tools/validation.ts:54-86 (handler)The core handler function that implements the validate_action tool logic, enforcing the read-before-modify safety rule and tracking file history.export async function handleValidateAction( params: { action: string; targetFile: string }, sessionManager: SessionManager ): Promise<ValidationResult> { const session = sessionManager.getSession(); const fileHistory = sessionManager.getFileHistory(params.targetFile); // Only enforce the critical "read before write" rule if (isModificationAction(params.action) && !fileHistory.hasBeenRead) { return { allowed: false, error: 'SAFETY VIOLATION: Cannot modify a file before reading it', reason: 'This prevents accidental data loss and ensures informed changes', resolution: `First read the file "${params.targetFile}" using any file reading tool, then you can modify it` }; } // Track file reads and modifications if (params.action.toLowerCase().includes('read')) { sessionManager.recordFileRead(params.targetFile); } else if (isModificationAction(params.action)) { sessionManager.recordFileModification(params.targetFile); } // All other actions are allowed return { allowed: true, currentPhase: session?.currentPhase, reminder: session ? `You're in ${session.currentPhase} phase. Check ${session.currentPhase.toLowerCase()}_guidance for recommendations.` : 'No active session. Consider starting with plan_workflow or build_custom_workflow.' }; }
- src/tools/validation.ts:8-25 (schema)Defines the tool metadata, description, and input schema (action and targetFile required) for validate_action.{ name: 'validate_action', description: 'Check if an action follows critical safety rules', inputSchema: { type: 'object', properties: { action: { type: 'string', description: 'The action you want to take' }, targetFile: { type: 'string', description: 'The file you want to act on' } }, required: ['action', 'targetFile'] } },
- src/index.ts:149-151 (registration)Registers the validate_action tool by including the output of createValidationTools() in the server's tools list.// Validation tools ...createValidationTools(), // Both validate_action and validate_phase_completion
- src/index.ts:258-264 (registration)Dispatches tool calls for 'validate_action' to the handleValidateAction function in the main server request handler.case 'validate_action': return { content: [{ type: 'text', text: JSON.stringify(await handleValidateAction(args as any, sessionManager), null, 2) }] };