rojects/source/server/rojos/tools/ReadPathMetaTool.ts

42 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2026-07-30 06:44:46 +00:00
import fs from "fs";
import { RojoTool, RojoToolContext } from "./RojoTool";
import { resolveProjectPath } from "../../storage";
2026-07-30 06:44:46 +00:00
export class ReadPathMetaTool extends RojoTool
{
readonly Definition =
{
type: "function",
function:
{
name: "read_path_meta",
description: "Get metadata for a file or directory: type (file/directory), size in bytes, and last-modified time.",
parameters:
{
type: "object",
properties:
{
path: { type: "string", description: "Path relative to the project root." },
},
required: [ "path" ],
},
},
};
async execute( args: Record<string, unknown>, ctx: RojoToolContext ): Promise<unknown>
{
const full = resolveProjectPath( ctx.projectId, args.path as string );
if ( !full ) return { error: "Invalid path" };
if ( !fs.existsSync( full ) ) return { error: "Path does not exist" };
const stat = fs.statSync( full );
return {
type: stat.isDirectory() ? "directory" : "file",
size: stat.size,
modifiedAt: stat.mtime.toISOString(),
};
}
}