checkPlanModeToolRestriction method
Guards against modifying production source code in /plan mode. Permits modifying planning and task files (*.md, tasks.md, implementation_plan.md).
Implementation
MCPToolResult? checkPlanModeToolRestriction(
String toolName,
Map<String, dynamic> arguments,
) {
if (_codingSubMode != '/plan') return null;
if (toolName == 'fs_write_file' ||
toolName == 'fs_replace_text' ||
toolName == 'fs_delete_file' ||
toolName == 'fs_delete' ||
toolName == 'fs_create_dir' ||
toolName == 'fs_move') {
final targetPath = (arguments['path'] ??
arguments['file_path'] ??
arguments['target'] ??
'')
.toString();
final lower = targetPath.toLowerCase();
final isPlanOrDocFile = lower.endsWith('.md') ||
lower.endsWith('.txt') ||
lower.endsWith('.json') ||
lower.endsWith('.yaml') ||
lower.endsWith('.yml') ||
lower.endsWith('tasks') ||
lower.endsWith('plan');
if (!isPlanOrDocFile && targetPath.isNotEmpty) {
final rejectNotice =
'⚠️ **Disallowed in /plan Mode**: Direct modification of source code file "$targetPath" is not allowed in /plan mode.\n'
'Please formulate your planned changes inside `tasks.md` or `implementation_plan.md`.\n'
'To implement code changes, please ask the user or switch to `/code` mode.';
_log('Blocked source code edit in /plan mode: $targetPath');
return MCPToolResult.error(rejectNotice);
}
}
return null;
}