import { resolveReadableSystemPath } from './path-security'; const FILE_READING_COMMANDS = new Set(['cat', 'ls']); function statusError(message: string, statusCode: number): Error & { statusCode: number } { return Object.assign(new Error(message), { statusCode }); } // Legacy `cat`/`ls` args must pass the same path gate as /system/fs/read. export async function validateLegacyExecRequest(command: string, args: string[]): Promise { if (!FILE_READING_COMMANDS.has(command)) { return; } const pathArgs = args.filter((arg) => !arg.startsWith('-')); if (command === 'cat' && pathArgs.length === 0) { throw statusError('cat requires at least one file path', 400); } await Promise.all(pathArgs.map(async (requestedPath) => { const resolved = await resolveReadableSystemPath(requestedPath); if (command === 'ls') { return; } if (!resolved) { throw statusError('Failed to validate file path', 400); } })); }