Skip to content

Commit 47a6679

Browse files
committed
Adds initial Copilot support #70
1 parent 25cf360 commit 47a6679

File tree

2 files changed

+115
-2
lines changed

2 files changed

+115
-2
lines changed

agent-shell-github.el

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
;;; agent-shell-github.el --- GitHub Copilot agent configurations -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2024 Alvaro Ramirez
4+
5+
;; Author: Alvaro Ramirez https://xenodium.com
6+
;; URL: https://github.com/xenodium/agent-shell
7+
8+
;; This package is free software; you can redistribute it and/or modify
9+
;; it under the terms of the GNU General Public License as published by
10+
;; the Free Software Foundation; either version 3, or (at your option)
11+
;; any later version.
12+
13+
;; This package is distributed in the hope that it will be useful,
14+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
;; GNU General Public License for more details.
17+
18+
;; You should have received a copy of the GNU General Public License
19+
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
20+
21+
;;; Commentary:
22+
;;
23+
;; This file includes GitHub Copilot-specific configurations.
24+
;;
25+
26+
;;; Code:
27+
28+
(eval-when-compile
29+
(require 'cl-lib))
30+
(require 'shell-maker)
31+
(require 'acp)
32+
33+
(declare-function agent-shell--indent-string "agent-shell")
34+
(declare-function agent-shell-make-agent-config "agent-shell")
35+
(declare-function agent-shell--make-acp-client "agent-shell")
36+
(declare-function agent-shell--dwim "agent-shell")
37+
38+
(defcustom agent-shell-github-command
39+
'("copilot" "--acp")
40+
"Command and parameters for the GitHub Copilot agent client.
41+
42+
The first element is the command name, and the rest are command parameters."
43+
:type '(repeat string)
44+
:group 'agent-shell)
45+
46+
(defcustom agent-shell-github-environment
47+
nil
48+
"Environment variables for the GitHub Copilot agent client.
49+
50+
This should be a list of environment variables to be used when
51+
starting the GitHub Copilot agent process."
52+
:type '(repeat string)
53+
:group 'agent-shell)
54+
55+
(defun agent-shell-github-make-copilot-config ()
56+
"Create a GitHub Copilot agent configuration.
57+
58+
Returns an agent configuration alist using `agent-shell-make-agent-config'."
59+
(agent-shell-make-agent-config
60+
:mode-line-name "Copilot"
61+
:buffer-name "Copilot"
62+
:shell-prompt "Copilot> "
63+
:shell-prompt-regexp "Copilot> "
64+
:icon-name "githubcopilot.png"
65+
:welcome-function #'agent-shell-github--welcome-message
66+
:client-maker (lambda (buffer)
67+
(agent-shell-github-make-client :buffer buffer))
68+
:install-instructions "See https://github.com/github/copilot-cli for installation."))
69+
70+
(defun agent-shell-github-start-copilot ()
71+
"Start an interactive GitHub Copilot agent shell."
72+
(interactive)
73+
(agent-shell--dwim :config (agent-shell-github-make-copilot-config)
74+
:new-shell t))
75+
76+
(cl-defun agent-shell-github-make-client (&key buffer)
77+
"Create a GitHub Copilot agent ACP client with BUFFER as context."
78+
(unless buffer
79+
(error "Missing required argument: :buffer"))
80+
(agent-shell--make-acp-client :command (car agent-shell-github-command)
81+
:command-params (cdr agent-shell-github-command)
82+
:environment-variables agent-shell-github-environment
83+
:context-buffer buffer))
84+
85+
(defun agent-shell-github--welcome-message (config)
86+
"Return GitHub Copilot welcome message using `shell-maker' CONFIG."
87+
(let ((art (agent-shell--indent-string 4 (agent-shell-github--ascii-art)))
88+
(message (string-trim-left (shell-maker-welcome-message config) "\n")))
89+
(concat "\n\n"
90+
art
91+
"\n\n"
92+
message)))
93+
94+
(defun agent-shell-github--ascii-art ()
95+
"GitHub Copilot ASCII art."
96+
(let* ((is-dark (eq (frame-parameter nil 'background-mode) 'dark))
97+
(text (string-trim "
98+
██████╗ ██████╗ ██████╗ ██╗ ██╗ ██████╗ ████████╗
99+
██╔════╝ ██╔═══██╗ ██╔══██╗ ██║ ██║ ██╔═══██╗ ╚══██╔══╝
100+
██║ ██║ ██║ ██████╔╝ ██║ ██║ ██║ ██║ ██║
101+
██║ ██║ ██║ ██╔═══╝ ██║ ██║ ██║ ██║ ██║
102+
╚██████╗ ╚██████╔╝ ██║ ██║ ███████╗ ╚██████╔╝ ██║
103+
╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝
104+
" "\n")))
105+
(propertize text 'font-lock-face (if is-dark
106+
'(:foreground "#6e40c9" :inherit fixed-pitch)
107+
'(:foreground "#8250df" :inherit fixed-pitch)))))
108+
109+
(provide 'agent-shell-github)
110+
111+
;;; agent-shell-github.el ends here

agent-shell.el

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
(require 'agent-shell-cursor)
5959
(require 'agent-shell-diff)
6060
(require 'agent-shell-google)
61+
(require 'agent-shell-github)
6162
(require 'agent-shell-goose)
6263
(require 'agent-shell-mistral)
6364
(require 'agent-shell-openai)
@@ -292,11 +293,12 @@ Returns an alist with all specified values."
292293
293294
This function aggregates agents from OpenAI, Anthropic, Google,
294295
Goose, Cursor, Auggie, and others."
295-
(list (agent-shell-anthropic-make-claude-code-config)
296-
(agent-shell-auggie-make-agent-config)
296+
(list (agent-shell-auggie-make-agent-config)
297+
(agent-shell-anthropic-make-claude-code-config)
297298
(agent-shell-openai-make-codex-config)
298299
(agent-shell-cursor-make-agent-config)
299300
(agent-shell-droid-make-agent-config)
301+
(agent-shell-github-make-copilot-config)
300302
(agent-shell-google-make-gemini-config)
301303
(agent-shell-goose-make-agent-config)
302304
(agent-shell-mistral-make-config)

0 commit comments

Comments
 (0)