check_before_modification
Verify if a file can be modified by checking AI metadata rules before making changes to ensure compliance and prevent unauthorized alterations.
Instructions
Check if a file can be modified according to AI metadata rules
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Path to the file to check |
Implementation Reference
- src/index.ts:832-838 (handler)MCP server tool handler for 'check_before_modification' that parses file metadata, retrieves approval status, calls RuleEngine for validation, and returns the result.case 'check_before_modification': { const filePath = args.filePath as string; const metadata = await this.metadataParser.parseFileMetadata(filePath); const approvals = await this.memoryManager.getFileApprovalStatus(filePath); const checkResult = await this.ruleEngine.checkBeforeModification(filePath, metadata, approvals); return { content: [{ type: 'text', text: JSON.stringify(checkResult, null, 2) }] }; }
- src/index.ts:628-638 (registration)Registration of the 'check_before_modification' tool in the MCP server's tool list, including name, description, and input schema.{ name: 'check_before_modification', description: 'Check if a file can be modified according to AI metadata rules', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the file to check' } }, required: ['filePath'] } },
- src/index.ts:631-638 (schema)Input schema definition for the 'check_before_modification' tool, specifying the required 'filePath' parameter.inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the file to check' } }, required: ['filePath'] } },
- src/rule-engine.ts:44-97 (helper)Core logic implementation in RuleEngine that performs the actual checks for file modification permissions, approvals, risks, stability, and applies enabled rules.async checkBeforeModification(filePath: string, metadata: AIMetadata | null, approvals: ApprovalStatus | null): Promise<{ allowed: boolean; reasons: string[]; warnings: string[]; }> { const result = { allowed: true, reasons: [] as string[], warnings: [] as string[] }; if (!metadata) { result.warnings.push('No @ai-metadata found in file'); return result; } // Check edit permissions if (metadata.editPermissions === 'read-only') { result.allowed = false; result.reasons.push('File is marked as read-only'); } // Check if file requires dev approval if (metadata.breakingChangesRisk === 'high' && (!approvals?.devApproved)) { result.allowed = false; result.reasons.push('High-risk file requires dev approval before modification'); } // Check if review is required if (metadata.reviewRequired && (!approvals?.codeReviewApproved)) { result.allowed = false; result.reasons.push('File requires code review approval before modification'); } // Check stability if (metadata.stability === 'deprecated') { result.warnings.push('This file is deprecated - consider if modification is necessary'); } // Apply custom rules for (const rule of this.rules.filter(r => r.enabled)) { const ruleResult = this.evaluateRule(rule, metadata, approvals, filePath); if (!ruleResult.passed) { if (rule.priority > 8) { result.allowed = false; result.reasons.push(ruleResult.message); } else { result.warnings.push(ruleResult.message); } } } return result; }