{ config, lib, pkgs, ... }: let cfg = config.development.pi-coding-agent; configDir = "${config.xdg.configHome}/pi"; in { imports = [ ./assertions.nix ]; options.development.pi-coding-agent = { enable = lib.mkEnableOption "Pi Coding Agent"; package = lib.mkOption { type = lib.types.package; readOnly = true; default = config.programs.pi-coding-agent.package; description = "The Pi Coding Agent package to use."; }; }; config = lib.mkIf cfg.enable { home.file = { "${configDir}/skills" = { source = ./skills; }; "${configDir}/prompts" = { source = ./prompts; }; "${configDir}/config/pi-subagent" = { source = ./roles; }; }; programs.pi-coding-agent = { enable = true; inherit configDir; package = pkgs.symlinkJoin { name = "pi-coding-agent-wrapped"; paths = [ pkgs.pi-coding-agent ]; nativeBuildInputs = [ pkgs.makeWrapper ]; postBuild = '' wrapProgram $out/bin/pi \ --set PI_CODING_AGENT_DIR ${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 = 30; 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 = [ pkgs.nodejs pkgs.bun ]; }; }; }