{ config, lib, pkgs, ... }: let cfg = config.development.pi-coding-agent; configDir = "${config.xdg.configHome}/pi"; in { options.development.pi-coding-agent = { enable = lib.mkEnableOption "Pi Coding Agent"; package = lib.mkOption { type = lib.types.package; default = pkgs.pi; description = "The Pi Coding Agent package to use."; }; }; config = lib.mkIf cfg.enable { home.sessionVariables = { PI_CODING_AGENT_DIR = configDir; }; home.file = { "${configDir}/skills".source = ./skills; "${configDir}/prompts".source = ./prompts; "${configDir}/agents".source = ./agents; }; programs.pi-coding-agent = { enable = true; inherit configDir; keybindings = { "tui.editor.cursorUp" = [ "up" "ctrl+p" ]; "tui.editor.cursorDown" = [ "down" "ctrl+n" ]; "tui.editor.deleteWordBackward" = [ "ctrl+w" "alt+backspace" ]; "tui.editor.historyPrevious" = "ctrl+up"; }; settings = { defaultTools = [ "read" "bash" "edit" "write" "grep" "find" "ls" ]; defaultProjectTrust = "ask"; compaction = { enabled = true; reserveTokens = 16384; keepRecentTokens = 20000; }; retry = { enabled = true; maxRetries = 3; baseDelayMs = 2000; maxAgentDelayMs = 60000; }; theme = "dark"; packages = [ "npm:@termdraw/pi" "npm:pi-mcp-adapter" "npm:@henryqw/pi-subagent" ]; skills = [ "${configDir}/skills" ]; prompts = [ "${configDir}/prompts" ]; themes = [ "${configDir}/themes" ]; enableSkillCommands = true; context = ./CONTEXT.md; }; extraPackages = with pkgs; [ nodejs bun ]; }; }; }