diff options
| -rw-r--r-- | llm-tools-hl.el | 41 | ||||
| -rw-r--r-- | llm-tools-pkg.el | 5 | ||||
| -rw-r--r-- | llm-tools-web.el | 32 | ||||
| -rw-r--r-- | llm-tools.el | 37 |
4 files changed, 108 insertions, 7 deletions
diff --git a/llm-tools-hl.el b/llm-tools-hl.el index b095a6e..daf9edd 100644 --- a/llm-tools-hl.el +++ b/llm-tools-hl.el | |||
| @@ -1,4 +1,35 @@ | |||
| 1 | ;; -*- lexical-binding: t; -*- | 1 | ;; llm-tools-hl.el --- Hashline file operations for llm-tools -*- lexical-binding: t; -*- |
| 2 | |||
| 3 | ;; Copyright (C) 2026 Vineet K | ||
| 4 | |||
| 5 | ;; Author: Vineet K <git@vineetk.net> | ||
| 6 | ;; Version: 1.0 | ||
| 7 | ;; Keywords: llm, gptel | ||
| 8 | ;; Package-Requires: ((emacs "28.1")) | ||
| 9 | |||
| 10 | ;; This program is free software; you can redistribute it and/or modify | ||
| 11 | ;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 13 | ;; (at your option) any later version. | ||
| 14 | |||
| 15 | ;; This program is distributed in the hope that it will be useful, | ||
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;; Hashline-based file operations for the llm-tools package. | ||
| 26 | ;; Provides functions for reading, editing, and verifying files using | ||
| 27 | ;; a content-addressed line format. | ||
| 28 | |||
| 29 | ;;; Code: | ||
| 30 | |||
| 31 | (require 'cl-lib) | ||
| 32 | |||
| 2 | (defvar llm-tools--hl-bigrams | 33 | (defvar llm-tools--hl-bigrams |
| 3 | (list "aa" "ab" "ac" "ad" "ae" "af" "ag" "ah" "ai" "aj" "ak" "al" "am" "an" | 34 | (list "aa" "ab" "ac" "ad" "ae" "af" "ag" "ah" "ai" "aj" "ak" "al" "am" "an" |
| 4 | "ao" "ap" "aq" "ar" "as" "at" "au" "av" "aw" "ax" "ay" "az" "ba" "bb" | 35 | "ao" "ap" "aq" "ar" "as" "at" "au" "av" "aw" "ax" "ay" "az" "ba" "bb" |
| @@ -119,7 +150,7 @@ single string." | |||
| 119 | (not (string-prefix-p "#" trimmed))))) | 150 | (not (string-prefix-p "#" trimmed))))) |
| 120 | 151 | ||
| 121 | (defun llm-tools--hl-parse-op-line-for-verify (line) | 152 | (defun llm-tools--hl-parse-op-line-for-verify (line) |
| 122 | "Parse a single operation LINE (e.g. \"+ 4ei\") into a `hl-verify-op`." | 153 | "Parse a single operation LINE (e.g. \"+ 4ei\") into a `hl-verify-op'." |
| 123 | (let* ((trimmed (string-trim line)) | 154 | (let* ((trimmed (string-trim line)) |
| 124 | (ch (substring trimmed 0 1))) | 155 | (ch (substring trimmed 0 1))) |
| 125 | (make-hl-verify-op | 156 | (make-hl-verify-op |
| @@ -334,7 +365,7 @@ line in the on-disk file." | |||
| 334 | (string-to-number (substring anchor 0 (- (length anchor) 2)))) | 365 | (string-to-number (substring anchor 0 (- (length anchor) 2)))) |
| 335 | 366 | ||
| 336 | (defun llm-tools--hl-parse-op-line (line) | 367 | (defun llm-tools--hl-parse-op-line (line) |
| 337 | "Parse a single operation LINE into an `hl-op` struct. | 368 | "Parse a single operation LINE into an `hl-op' struct. |
| 338 | LINE must start with `+`, `<`, `-`, or `=`, followed by a space, | 369 | LINE must start with `+`, `<`, `-`, or `=`, followed by a space, |
| 339 | followed by an anchor (or range)." | 370 | followed by an anchor (or range)." |
| 340 | (string-match "^[+<=-] \\(.*\\)" line) ; returns index or nil | 371 | (string-match "^[+<=-] \\(.*\\)" line) ; returns index or nil |
| @@ -349,7 +380,7 @@ followed by an anchor (or range)." | |||
| 349 | ("=" (make-hl-op :type 'replace :range (split-string anchor "\\.\\.")))))) | 380 | ("=" (make-hl-op :type 'replace :range (split-string anchor "\\.\\.")))))) |
| 350 | 381 | ||
| 351 | (defun llm-tools--hl-parse-section (section) | 382 | (defun llm-tools--hl-parse-section (section) |
| 352 | "Parse SECTION (body after `@@ PATH`) into a list of `hl-op` structs. | 383 | "Parse SECTION (body after `@@ PATH`) into a list of `hl-op' structs. |
| 353 | Skips comment lines (starting with `#`) and blank lines." | 384 | Skips comment lines (starting with `#`) and blank lines." |
| 354 | (let (ops op) | 385 | (let (ops op) |
| 355 | (dolist (line (string-lines section)) | 386 | (dolist (line (string-lines section)) |
| @@ -414,7 +445,7 @@ FILENAME." | |||
| 414 | (- offset (- b a 1))))) | 445 | (- offset (- b a 1))))) |
| 415 | 446 | ||
| 416 | (defun llm-tools--hl-apply-replace (range payload content offset) | 447 | (defun llm-tools--hl-apply-replace (range payload content offset) |
| 417 | "Replace lines from (car RANGE) to (cadr RANGE) with PAYLOAD (nil → '(\"\"))" | 448 | "Replace lines from (car RANGE) to (cadr RANGE) with PAYLOAD (nil to '(\"\"))" |
| 418 | (let ((a (+ (llm-tools--hl-anchor-to-line-num (car range)) offset)) | 449 | (let ((a (+ (llm-tools--hl-anchor-to-line-num (car range)) offset)) |
| 419 | (b (+ (llm-tools--hl-anchor-to-line-num (cadr range)) offset)) | 450 | (b (+ (llm-tools--hl-anchor-to-line-num (cadr range)) offset)) |
| 420 | (payload (or payload '("")))) | 451 | (payload (or payload '("")))) |
diff --git a/llm-tools-pkg.el b/llm-tools-pkg.el new file mode 100644 index 0000000..eb18f92 --- /dev/null +++ b/llm-tools-pkg.el | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | (define-package 'llm-tools "1.0" | ||
| 2 | "Opinionated tools for use by an LLM." | ||
| 3 | '((emacs "28.1") (gptel "0.9.6") (magit "3.3.0")) | ||
| 4 | :keywords '("llm" "gptel") | ||
| 5 | :url "https://git.vineetk.net/llm-tools.el/") \ No newline at end of file | ||
diff --git a/llm-tools-web.el b/llm-tools-web.el index cadf175..f5e10a0 100644 --- a/llm-tools-web.el +++ b/llm-tools-web.el | |||
| @@ -1,4 +1,34 @@ | |||
| 1 | ;;; Web tools, taken from gptel-agent -*- lexical-binding: t; -*- | 1 | ;;; llm-tools-web.el --- Web tools for llm-tools -*- lexical-binding: t; -*- |
| 2 | |||
| 3 | ;; Copyright (C) 2026 Vineet K | ||
| 4 | |||
| 5 | ;; Author: Vineet K <git@vineetk.net> | ||
| 6 | ;; Version: 1.0 | ||
| 7 | ;; Keywords: llm, gptel, processes | ||
| 8 | ;; Package-Requires: ((emacs "28.1")) | ||
| 9 | |||
| 10 | ;; This program is free software; you can redistribute it and/or modify | ||
| 11 | ;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 13 | ;; (at your option) any later version. | ||
| 14 | |||
| 15 | ;; This program is distributed in the hope that it will be useful, | ||
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;; Web tools for the llm-tools package, adapted from gptel-agent. | ||
| 26 | ;; Provides functions for web searching and URL fetching. | ||
| 27 | |||
| 28 | ;;; Code: | ||
| 29 | |||
| 30 | (require 'cl-lib) | ||
| 31 | |||
| 2 | (defun llm-tools--fetch-with-timeout (url url-cb tool-cb failed-msg &rest args) | 32 | (defun llm-tools--fetch-with-timeout (url url-cb tool-cb failed-msg &rest args) |
| 3 | "Fetch URL and call URL-CB in the result buffer. | 33 | "Fetch URL and call URL-CB in the result buffer. |
| 4 | 34 | ||
diff --git a/llm-tools.el b/llm-tools.el index 4fa4258..99798f0 100644 --- a/llm-tools.el +++ b/llm-tools.el | |||
| @@ -1,4 +1,39 @@ | |||
| 1 | ;; -*- lexical-binding: t; -*- | 1 | ;; llm-tools.el --- Opinionated tools for use by an LLM -*- lexical-binding: t; -*- |
| 2 | |||
| 3 | ;; Copyright (C) 2026 Vineet K | ||
| 4 | |||
| 5 | ;; Author: Vineet K <git@vineetk.net> | ||
| 6 | ;; Version: 1.0 | ||
| 7 | ;; Keywords: llm, gptel | ||
| 8 | ;; Package-Requires: ((emacs "28.1") (gptel "0.9.6") (magit "3.3.0")) | ||
| 9 | |||
| 10 | ;; This program is free software; you can redistribute it and/or modify | ||
| 11 | ;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 13 | ;; (at your option) any later version. | ||
| 14 | |||
| 15 | ;; This program is distributed in the hope that it will be useful, | ||
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;; This package provides a set of opinionated tools for use by an LLM via GPTel. | ||
| 26 | ;; It includes tools for file operations, web search, and bash execution. | ||
| 27 | |||
| 28 | ;;; Code: | ||
| 29 | |||
| 30 | (require 'cl-lib) | ||
| 31 | (require 'magit) | ||
| 32 | |||
| 33 | (defgroup llm-tools nil | ||
| 34 | "Opinionated tools for use by an LLM." | ||
| 35 | :group 'convenience) | ||
| 36 | |||
| 2 | (require 'llm-tools-hl) | 37 | (require 'llm-tools-hl) |
| 3 | (require 'llm-tools-web) | 38 | (require 'llm-tools-web) |
| 4 | 39 | ||
