index.ts

 1import { resolve, sep } from "node:path";
 2import type { AgentTool } from "@mariozechner/pi-ai";
 3import { ToolInputError } from "../../util/errors.js";
 4
 5export type ToolFactory = (workspacePath: string) => AgentTool<any>;
 6
 7export interface ToolBundle {
 8  name: string;
 9  tools: AgentTool<any>[];
10}
11
12export function ensureWorkspacePath(workspacePath: string, targetPath: string): string {
13  const resolved = resolve(workspacePath, targetPath);
14  const root = workspacePath.endsWith(sep) ? workspacePath : `${workspacePath}${sep}`;
15
16  if (resolved === workspacePath || resolved.startsWith(root)) {
17    return resolved;
18  }
19
20  throw new ToolInputError(`Path escapes workspace: ${targetPath}`);
21}
22
23export { createReadTool } from "./read.js";
24export { createGrepTool } from "./grep.js";
25export { createLsTool } from "./ls.js";
26export { createFindTool } from "./find.js";