/**
 * Tool registry — the bag of tools the pi session passes to the model.
 *
 * Phase 2 ships the four core coding tools. Phase 3 or later will add Grep,
 * Glob, LS, NotebookEdit, etc. so the surface fully matches Claude SDK's.
 */
import type { PiTool } from './types.js';
import type { PiToolDef } from '../providers/types.js';
import { readTool } from './read.js';
import { writeTool } from './write.js';
import { editTool } from './edit.js';
import { bashTool } from './bash.js';

export const PI_TOOLS: PiTool[] = [readTool, writeTool, editTool, bashTool];

const TOOL_BY_NAME = new Map<string, PiTool>();
for (const t of PI_TOOLS) {
  TOOL_BY_NAME.set(t.name, t);
  // Some models lowercase or otherwise normalise tool names. Register
  // common aliases so we don't 404 a legitimate call over a casing nit.
  TOOL_BY_NAME.set(t.name.toLowerCase(), t);
}

export function findTool(name: string): PiTool | undefined {
  return TOOL_BY_NAME.get(name) || TOOL_BY_NAME.get(name.toLowerCase());
}

export function toolDefsForProvider(): PiToolDef[] {
  return PI_TOOLS.map((t) => ({
    name: t.name,
    description: t.description,
    inputSchema: t.inputSchema,
  }));
}
