char-slop/ai-dots
ai dotfiles
git clone https://git.t4t.associates/char-slop/ai-dots
c535dce
main
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 > { 18const tools = loadSettings ( cwd ). tools ; 19if ( ! tools || typeof tools !== "object" || Array . isArray ( tools )) return {}; 20 21return Object . fromEntries ( 22Object . entries ( tools ). filter ( 23( entry ) :entry is[ string , boolean ] => typeof entry [ 1 ] === "boolean" , 24), 25); 26} 27 28export default function ( pi :ExtensionAPI ) { 29pi . on ( "session_start" , async ( _event , ctx ) => { 30// Skip if --tools was provided on CLI 31if ( pi . getFlag ( "--tools" ) !== undefined ) return ; 32 33const configured = Object . entries ( readToolsConfig ( ctx . cwd )); 34if ( configured . length === 0 ) return ; 35 36const active = new Set ( pi . getActiveTools ()); 37for ( const [ tool , enabled ] of configured ) { 38if ( enabled ) active . add ( tool ); 39else active . delete ( tool ); 40} 41pi . setActiveTools ([ ...active ]); 42}); 43}