aboutsummaryrefslogtreecommitdiffstats
path: root/modules/development/pi-coding-agent/default.nix
blob: e560a98e4624a56a751a06d7457b0b282b033c61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{
  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;
      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
      ];
    };
  };
}