diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-23 20:12:58 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-23 20:12:58 -0400 |
| commit | 10fa6f4e2e7150ad99827721ada1ae4badcc5e90 (patch) | |
| tree | 960065c8e69f1e7a4150ecf522e2f813c239b5ee /archive/gptel/gptel-tools/git_status.el | |
| parent | f4cc70c69e7707dd4a686637e14885f5443fcca6 (diff) | |
| download | dotemacs-10fa6f4e2e7150ad99827721ada1ae4badcc5e90.tar.gz dotemacs-10fa6f4e2e7150ad99827721ada1ae4badcc5e90.zip | |
chore(ai): archive gptel and remove it from the live config
I archived gptel to archive/gptel/ since I rarely use it. Moved there: the six gptel modules (ai-config, ai-conversations, ai-conversations-browser, ai-mcp, ai-quick-ask, ai-rewrite), the gptel-tools/ directory, custom/gptel-prompts.el, their test files and utilities, and the four gptel-only specs.
Scrubbed from the live config: the ai-config require in init.el, which also drops the whole C-; a keymap; the gptel-mode emojify hook in font-config.el; the gptel-tools entries in the Makefile clean target and the coverage runner; and the gptel feature notes in README. Cancelled the open gptel tasks in todo.org (the AI Open Work issues, the feature-extension brainstorm, the velox gptel-magit bug).
ai-term stays. It is the ghostel Claude launcher, independent of gptel.
Verified: every module loads, a batch init launch reaches completion clean, and the full test suite shows only pre-existing coverage failures unrelated to this change.
Diffstat (limited to 'archive/gptel/gptel-tools/git_status.el')
| -rw-r--r-- | archive/gptel/gptel-tools/git_status.el | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/archive/gptel/gptel-tools/git_status.el b/archive/gptel/gptel-tools/git_status.el new file mode 100644 index 00000000..de76a985 --- /dev/null +++ b/archive/gptel/gptel-tools/git_status.el @@ -0,0 +1,85 @@ +;;; git_status.el --- Read-only git status tool for gptel -*- coding: utf-8; lexical-binding: t; -*- + +;; Author: Craig Jennings <c@cjennings.net> +;; Keywords: convenience, tools, git + +;; This file is not part of GNU Emacs. + +;;; Commentary: + +;; Gptel tool returning `git status --short --branch' for a path under +;; the user's home directory. Read-only: never writes to the repo, +;; never runs anything that could mutate state. Path validation +;; rejects anything outside HOME and any path that doesn't resolve to +;; a directory inside a git working tree. + +;;; Code: + +(require 'gptel) +(require 'cl-lib) + +(defun cj/gptel-git-status--validate-path (path) + "Validate PATH as a usable working directory for a git status call. +PATH must resolve under the user's home directory, must be an +existing directory, and must be inside a git working tree. Returns +the expanded path string on success; signals `error' otherwise." + (let* ((home (file-name-as-directory (file-truename (expand-file-name "~")))) + (full (expand-file-name (or path "~") "~"))) + (unless (string-prefix-p (expand-file-name "~") full) + (error "Path must be within home directory: %s" path)) + (unless (file-directory-p full) + (error "Not a directory: %s" full)) + (let ((resolved (file-truename full))) + (unless (or (string= resolved (directory-file-name home)) + (string-prefix-p home resolved)) + (error "Resolved path must be within home directory: %s" path)) + (setq full resolved)) + (let ((default-directory full)) + (unless (zerop (process-file "git" nil nil nil + "rev-parse" "--is-inside-work-tree")) + (error "Not a git working tree: %s" full))) + full)) + +(defun cj/gptel-git-status--run (path) + "Run `git status --short --branch' in PATH. Return the output. +Color is disabled via `-c color.ui=false' at the git level (`git status' +itself doesn't accept `--no-color' like `git log' / `git diff' do)." + (let* ((dir (cj/gptel-git-status--validate-path path)) + (default-directory dir)) + (with-temp-buffer + (let ((exit (process-file "git" nil t nil + "-c" "color.ui=false" + "status" "--short" "--branch"))) + (unless (zerop exit) + (error "git status exited with %d: %s" exit (buffer-string))) + ;; `--branch' always prints a `## <branch>' header, so empty + ;; output is unreachable. Detect a clean tree by counting the + ;; non-branch lines: if only the header is present, no files + ;; are modified / staged / untracked. + (let* ((out (buffer-string)) + (non-branch-lines + (cl-count-if + (lambda (l) + (and (not (string-empty-p l)) + (not (string-prefix-p "## " l)))) + (split-string out "\n")))) + (if (zerop non-branch-lines) + (format "Clean working tree in %s\n%s" dir (string-trim out)) + out)))))) + +(with-eval-after-load 'gptel + (gptel-make-tool + :name "git_status" + :function (lambda (path) (cj/gptel-git-status--run path)) + :description "Return the output of `git status --short --branch' for a directory in the user's home tree. Read-only. Useful for seeing which files are modified, staged, or untracked, and how the current branch compares to its upstream." + :args (list '(:name "path" + :type string + :description "Directory inside a git working tree. Either an absolute path under the user's home directory or a path relative to it (e.g. 'code/myproject').")) + :category "git" + :confirm nil + :include t) + + (add-to-list 'gptel-tools (gptel-get-tool '("git" "git_status")))) + +(provide 'git_status) +;;; git_status.el ends here |
