|
| 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 |
0 commit comments