char-slop/ai-dots

ai dotfiles

git clone https://git.t4t.associates/char-slop/ai-dots

Charlotte Sompi: compact reasoning, computer-usec535dce

main
1.4 KiB43 linesraw
1/**
2 * Default Tools Extension
3 *
4 * Reads a `tools` object from settings.json and applies explicitly configured tool states.
5 * Only applies when --tools is not passed on the CLI.
6 *
7 * ~/.pi/agent/settings.json:
8 *   { "tools": { "read": true, "bash": true, "grep": true, "find": true, "ls": true } }
9 *
10 * .pi/settings.json (project override, merged with global):
11 *   { "tools": { "ls": false } }
12 */
13
14import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
15import { loadSettings } from "../_char_common/settings";
16
17function readToolsConfig(cwd: string): Record<string, boolean> {
18  const tools = loadSettings(cwd).tools;
19  if (!tools || typeof tools !== "object" || Array.isArray(tools)) return {};
20
21  return Object.fromEntries(
22    Object.entries(tools).filter(
23      (entry): entry is [string, boolean] => typeof entry[1] === "boolean",
24    ),
25  );
26}
27
28export default function (pi: ExtensionAPI) {
29  pi.on("session_start", async (_event, ctx) => {
30    // Skip if --tools was provided on CLI
31    if (pi.getFlag("--tools") !== undefined) return;
32
33    const configured = Object.entries(readToolsConfig(ctx.cwd));
34    if (configured.length === 0) return;
35
36    const active = new Set(pi.getActiveTools());
37    for (const [tool, enabled] of configured) {
38      if (enabled) active.add(tool);
39      else active.delete(tool);
40    }
41    pi.setActiveTools([...active]);
42  });
43}