[ 'type' => 'string', 'description' => 'Relative path, e.g. "application/controller/loginController.php".', 'required' => true, ], ]; } public function execute(array $args): mixed { $path = (string) ($args['path'] ?? ''); if ($path === '' || str_contains($path, '..')) { return 'ERROR: invalid path'; } // Application root = three levels up from this plugin file: // application/module/ai/plugins/tools/fileRead.php // ↑ ↑ ↑ ↑ ↑ ↑ // app module ai plugins tools this $root = realpath(__DIR__ . '/../../../../../'); if ($root === false) return 'ERROR: cannot resolve app root'; $abs = realpath($root . DIRECTORY_SEPARATOR . $path); if ($abs === false || !is_file($abs)) return 'ERROR: file not found'; if (strpos($abs, $root) !== 0) return 'ERROR: path escapes root'; $body = (string) file_get_contents($abs); if (strlen($body) > 8192) $body = substr($body, 0, 8192) . "\n…[truncated]"; return $body; } }