52 lines
2.3 KiB
JavaScript
52 lines
2.3 KiB
JavaScript
import { z } from "zod";
|
|
import { handleToolError, validateRequired } from "../helpers/errorHandler.js";
|
|
import { getCurrentProjectInfo, callLocalFileEndpoint, buildLocalFileErrorResponse } from "./helpers.js";
|
|
|
|
export function registerAcaiGlobTool(server) {
|
|
server.tool(
|
|
"acai-glob",
|
|
"Find project files by path pattern. Returns compact relative paths only.",
|
|
{
|
|
pattern: z.string().describe("Glob-style pattern relative to the project root, e.g. 'template/estandar/modulos/**/index-base.tpl'"),
|
|
base_path: z.string().optional().describe("Optional base directory relative to the project root"),
|
|
limit: z.number().int().positive().max(200).optional().describe("Maximum number of paths to return"),
|
|
},
|
|
{ readOnlyHint: true, destructiveHint: false },
|
|
async ({ pattern, base_path, limit }) => {
|
|
try {
|
|
const validationError = validateRequired({ pattern }, ["pattern"], "acai-glob");
|
|
if (validationError) return validationError;
|
|
|
|
const { projectSlug, projectDir } = getCurrentProjectInfo();
|
|
const result = await callLocalFileEndpoint("GET", "/api/files/glob", null, {
|
|
project: projectSlug,
|
|
projectDir,
|
|
pattern,
|
|
basePath: base_path,
|
|
limit,
|
|
});
|
|
if (!result.data?.success) {
|
|
return buildLocalFileErrorResponse("acai-glob", result, { pattern, base_path });
|
|
}
|
|
const data = result.data;
|
|
|
|
return {
|
|
content: [{
|
|
type: "text",
|
|
text: JSON.stringify({
|
|
success: true,
|
|
pattern: data.pattern,
|
|
base_path: data.basePath,
|
|
matches: data.matches,
|
|
total_matches: data.totalMatches,
|
|
truncated: data.truncated,
|
|
}, null, 2),
|
|
}],
|
|
};
|
|
} catch (error) {
|
|
return handleToolError(error, "acai-glob", { pattern, base_path });
|
|
}
|
|
}
|
|
);
|
|
}
|