This commit is contained in:
seb
2026-10-14 00:21:31 +02:00
parent 74b24686bc
commit f9ed4fe75d
18 changed files with 1508 additions and 279 deletions

View File

@@ -5,6 +5,7 @@ import { isSkillPath, parseSkill, SKILL_EXT } from './skill.js';
import { getApiRouteSkill } from './routes-skills.js';
import { prepareVfs } from './vfs.js';
import { TOOL_DESCRIPTIONS, TOOL_PARAMETER_DESCRIPTIONS } from './prompts.js';
import { parseDraftPath, requestDraftRead } from '../services/draftManager.js';
const DEFAULT_LIMIT = 400;
const MAX_LIMIT = 5000;
@@ -108,18 +109,37 @@ export function createReadFileTool({ googleAuthId }) {
throw new ToolError(`Access denied: path "${filename}" escapes virtual filesystem boundary.`);
}
const virtualSkill = !fs.existsSync(absPath) && isSkillPath(clean) ? getApiRouteSkill(clean) : null;
if (!virtualSkill && !fs.existsSync(absPath)) {
throw new ToolError(
`File not found in virtual filesystem: "${clean}". ` +
'Call find_files to see what is stored, or find_files({ skills: true }) for SKILL files.'
);
}
if (!virtualSkill && !fs.statSync(absPath).isFile()) {
throw new ToolError(`"${clean}" is not a file. Use find_files to list directories.`);
const draftInfo = parseDraftPath(clean);
if (draftInfo.isFolder) {
throw new ToolError('"drafts" is a directory. Use find_files to list its contents.');
}
const raw = virtualSkill ? Buffer.from(virtualSkill.content, 'utf8') : fs.readFileSync(absPath);
let raw;
let virtualSkill = null;
if (draftInfo.isDraft) {
try {
const content = await requestDraftRead({
userId: googleAuthId,
name: draftInfo.name,
});
const str = typeof content === 'string' ? content : JSON.stringify(content ?? {}, null, 2);
raw = Buffer.from(str, 'utf8');
} catch (err) {
throw new ToolError(`Failed to read draft "${draftInfo.name}": ${err.message}`);
}
} else {
virtualSkill = !fs.existsSync(absPath) && isSkillPath(clean) ? getApiRouteSkill(clean) : null;
if (!virtualSkill && !fs.existsSync(absPath)) {
throw new ToolError(
`File not found in virtual filesystem: "${clean}". ` +
'Call find_files to see what is stored, or find_files({ skills: true }) for SKILL files.'
);
}
if (!virtualSkill && !fs.statSync(absPath).isFile()) {
throw new ToolError(`"${clean}" is not a file. Use find_files to list directories.`);
}
raw = virtualSkill ? Buffer.from(virtualSkill.content, 'utf8') : fs.readFileSync(absPath);
}
if (looksBinary(raw)) {
const ext = path.extname(clean).toLowerCase();
throw new ToolError(