/** * Default Tools Extension * * Reads a `tools` object from settings.json and applies explicitly configured tool states. * Only applies when --tools is not passed on the CLI. * * ~/.pi/agent/settings.json: * { "tools": { "read": true, "bash": true, "grep": true, "find": true, "ls": true } } * * .pi/settings.json (project override, merged with global): * { "tools": { "ls": false } } */ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { loadSettings } from "../_char_common/settings"; function readToolsConfig(cwd: string): Record { const tools = loadSettings(cwd).tools; if (!tools || typeof tools !== "object" || Array.isArray(tools)) return {}; return Object.fromEntries( Object.entries(tools).filter( (entry): entry is [string, boolean] => typeof entry[1] === "boolean", ), ); } export default function (pi: ExtensionAPI) { pi.on("session_start", async (_event, ctx) => { // Skip if --tools was provided on CLI if (pi.getFlag("--tools") !== undefined) return; const configured = Object.entries(readToolsConfig(ctx.cwd)); if (configured.length === 0) return; const active = new Set(pi.getActiveTools()); for (const [tool, enabled] of configured) { if (enabled) active.add(tool); else active.delete(tool); } pi.setActiveTools([...active]); }); }