From 389f1a7e240eca36443649d6b283c21cfeb51c08 Mon Sep 17 00:00:00 2001 From: Vineet Kumar Date: Thu, 28 May 2026 14:29:57 -0400 Subject: get ready for packaging --- llm-tools-hl.el | 41 ++++++++++++++++++++++++++++++++++++----- llm-tools-pkg.el | 5 +++++ llm-tools-web.el | 32 +++++++++++++++++++++++++++++++- llm-tools.el | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 llm-tools-pkg.el 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 @@ -;; -*- lexical-binding: t; -*- +;; llm-tools-hl.el --- Hashline file operations for llm-tools -*- lexical-binding: t; -*- + +;; Copyright (C) 2026 Vineet K + +;; Author: Vineet K +;; Version: 1.0 +;; Keywords: llm, gptel +;; Package-Requires: ((emacs "28.1")) + +;; This program 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 of the License, or +;; (at your option) any later version. + +;; This program 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 this program. If not, see . + +;;; Commentary: + +;; Hashline-based file operations for the llm-tools package. +;; Provides functions for reading, editing, and verifying files using +;; a content-addressed line format. + +;;; Code: + +(require 'cl-lib) + (defvar llm-tools--hl-bigrams (list "aa" "ab" "ac" "ad" "ae" "af" "ag" "ah" "ai" "aj" "ak" "al" "am" "an" "ao" "ap" "aq" "ar" "as" "at" "au" "av" "aw" "ax" "ay" "az" "ba" "bb" @@ -119,7 +150,7 @@ single string." (not (string-prefix-p "#" trimmed))))) (defun llm-tools--hl-parse-op-line-for-verify (line) - "Parse a single operation LINE (e.g. \"+ 4ei\") into a `hl-verify-op`." + "Parse a single operation LINE (e.g. \"+ 4ei\") into a `hl-verify-op'." (let* ((trimmed (string-trim line)) (ch (substring trimmed 0 1))) (make-hl-verify-op @@ -334,7 +365,7 @@ line in the on-disk file." (string-to-number (substring anchor 0 (- (length anchor) 2)))) (defun llm-tools--hl-parse-op-line (line) - "Parse a single operation LINE into an `hl-op` struct. + "Parse a single operation LINE into an `hl-op' struct. LINE must start with `+`, `<`, `-`, or `=`, followed by a space, followed by an anchor (or range)." (string-match "^[+<=-] \\(.*\\)" line) ; returns index or nil @@ -349,7 +380,7 @@ followed by an anchor (or range)." ("=" (make-hl-op :type 'replace :range (split-string anchor "\\.\\.")))))) (defun llm-tools--hl-parse-section (section) - "Parse SECTION (body after `@@ PATH`) into a list of `hl-op` structs. + "Parse SECTION (body after `@@ PATH`) into a list of `hl-op' structs. Skips comment lines (starting with `#`) and blank lines." (let (ops op) (dolist (line (string-lines section)) @@ -414,7 +445,7 @@ FILENAME." (- offset (- b a 1))))) (defun llm-tools--hl-apply-replace (range payload content offset) - "Replace lines from (car RANGE) to (cadr RANGE) with PAYLOAD (nil → '(\"\"))" + "Replace lines from (car RANGE) to (cadr RANGE) with PAYLOAD (nil to '(\"\"))" (let ((a (+ (llm-tools--hl-anchor-to-line-num (car range)) offset)) (b (+ (llm-tools--hl-anchor-to-line-num (cadr range)) offset)) (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 @@ +(define-package 'llm-tools "1.0" + "Opinionated tools for use by an LLM." + '((emacs "28.1") (gptel "0.9.6") (magit "3.3.0")) + :keywords '("llm" "gptel") + :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 @@ -;;; Web tools, taken from gptel-agent -*- lexical-binding: t; -*- +;;; llm-tools-web.el --- Web tools for llm-tools -*- lexical-binding: t; -*- + +;; Copyright (C) 2026 Vineet K + +;; Author: Vineet K +;; Version: 1.0 +;; Keywords: llm, gptel, processes +;; Package-Requires: ((emacs "28.1")) + +;; This program 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 of the License, or +;; (at your option) any later version. + +;; This program 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 this program. If not, see . + +;;; Commentary: + +;; Web tools for the llm-tools package, adapted from gptel-agent. +;; Provides functions for web searching and URL fetching. + +;;; Code: + +(require 'cl-lib) + (defun llm-tools--fetch-with-timeout (url url-cb tool-cb failed-msg &rest args) "Fetch URL and call URL-CB in the result buffer. 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 @@ -;; -*- lexical-binding: t; -*- +;; llm-tools.el --- Opinionated tools for use by an LLM -*- lexical-binding: t; -*- + +;; Copyright (C) 2026 Vineet K + +;; Author: Vineet K +;; Version: 1.0 +;; Keywords: llm, gptel +;; Package-Requires: ((emacs "28.1") (gptel "0.9.6") (magit "3.3.0")) + +;; This program 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 of the License, or +;; (at your option) any later version. + +;; This program 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 this program. If not, see . + +;;; Commentary: + +;; This package provides a set of opinionated tools for use by an LLM via GPTel. +;; It includes tools for file operations, web search, and bash execution. + +;;; Code: + +(require 'cl-lib) +(require 'magit) + +(defgroup llm-tools nil + "Opinionated tools for use by an LLM." + :group 'convenience) + (require 'llm-tools-hl) (require 'llm-tools-web) -- cgit v1.2.3