42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import fs from "fs";
|
|
import { RojoTool, RojoToolContext } from "./RojoTool.js";
|
|
import { resolveProjectPath } from "../../storage.js";
|
|
|
|
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(),
|
|
};
|
|
}
|
|
}
|