-
-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathagent-shell-pi.el
More file actions
132 lines (107 loc) · 4.76 KB
/
agent-shell-pi.el
File metadata and controls
132 lines (107 loc) · 4.76 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
;;; agent-shell-pi.el --- Pi coding agent configurations -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Alvaro Ramirez
;; Author: Alvaro Ramirez https://xenodium.com
;; URL: https://github.com/xenodium/agent-shell
;; This package is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This package is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; This file includes Pi coding agent-specific configurations.
;;
;; Pi is a minimal terminal coding agent by Mario Zechner.
;; See https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent
;;
;; This integration requires the pi-acp adapter to be installed.
;;
;;; Code:
(eval-when-compile
(require 'cl-lib))
(require 'shell-maker)
(require 'acp)
(declare-function agent-shell--indent-string "agent-shell")
(declare-function agent-shell-make-agent-config "agent-shell")
(autoload 'agent-shell-make-agent-config "agent-shell")
(declare-function agent-shell--make-acp-client "agent-shell")
(declare-function agent-shell--dwim "agent-shell")
(defcustom agent-shell-pi-acp-command
'("pi-acp")
"Command and parameters for the Pi ACP client.
The first element is the command name, and the rest are command parameters.
Pi requires the pi-acp adapter for ACP integration."
:type '(repeat string)
:group 'agent-shell)
(defcustom agent-shell-pi-environment
nil
"Environment variables for the Pi client.
This should be a list of environment variables to be used when
starting the Pi client process.
Example usage to set custom environment variables:
(setq agent-shell-pi-environment
(`agent-shell-make-environment-variables'
\"ANTHROPIC_API_KEY\" \"your-key\"
\"PI_CODING_AGENT_DIR\" \"~/.pi/agent\"))"
:type '(repeat string)
:group 'agent-shell)
(defun agent-shell-pi-make-agent-config ()
"Create a Pi coding agent configuration.
Returns an agent configuration alist using `agent-shell-make-agent-config'."
(agent-shell-make-agent-config
:identifier 'pi
:mode-line-name "Pi"
:buffer-name "Pi"
:shell-prompt "Pi> "
:shell-prompt-regexp "Pi> "
:welcome-function #'agent-shell-pi--welcome-message
:client-maker (lambda (buffer)
(agent-shell-pi-make-client :buffer buffer))
:install-instructions "See https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent for Pi installation.
Requires pi-acp adapter for ACP integration."))
(defun agent-shell-pi-start-agent ()
"Start an interactive Pi coding agent shell."
(interactive)
(agent-shell--dwim :config (agent-shell-pi-make-agent-config)
:new-shell t))
(cl-defun agent-shell-pi-make-client (&key buffer)
"Create a Pi client using BUFFER as context.
Pi uses OAuth login via the `/login' command, so no API key
environment variables are required by default."
(unless buffer
(error "Missing required argument: :buffer"))
(when (and (boundp 'agent-shell-pi-command) agent-shell-pi-command)
(user-error "Please migrate to use agent-shell-pi-acp-command and eval (setq agent-shell-pi-command nil)"))
(agent-shell--make-acp-client :command (car agent-shell-pi-acp-command)
:command-params (cdr agent-shell-pi-acp-command)
:environment-variables agent-shell-pi-environment
:context-buffer buffer))
(defun agent-shell-pi--welcome-message (config)
"Return Pi welcome message using `shell-maker' CONFIG."
(let ((art (agent-shell--indent-string 4 (agent-shell-pi--ascii-art)))
(message (string-trim-left (shell-maker-welcome-message config) "\n")))
(concat "\n\n"
art
"\n\n"
message)))
(defun agent-shell-pi--ascii-art ()
"Pi ASCII art."
(let* ((is-dark (eq (frame-parameter nil 'background-mode) 'dark))
(text (string-trim "
██████╗ ██╗
██╔══██╗██║
██████╔╝██║
██╔═══╝ ██║
██║ ██║
╚═╝ ╚═╝
" "\n")))
(propertize text 'font-lock-face (if is-dark
'(:foreground "#ff6b6b" :inherit fixed-pitch)
'(:foreground "#c0392b" :inherit fixed-pitch)))))
(provide 'agent-shell-pi)
;;; agent-shell-pi.el ends here