commit c1f458c46ccf874d5d26089871a41c35992b2c1e
parent 44cad762d23930e849a24fdf3bdb43506f1943f6
Author: Vineet Kumar <git@vineetk.net>
Date: Sat, 23 May 2026 22:47:15 -0400
declare first tool (read_file)
Diffstat:
1 file changed, 37 insertions(+), 0 deletions(-)
diff --git a/gptel-tools.el b/gptel-tools.el
@@ -0,0 +1,37 @@
+;; read_file (hl-file-read)
+(gptel-make-tool
+ :name "read_file"
+ :function 'hl-file-read
+ :description "\
+Read an entire file and return its contents in hashline format. Each
+line is represented as LINE_NUMBER HASH|CONTENT, where LINE_NUMBER is
+the 1-based line number, HASH is a 2-character content-derived bigram,
+and CONTENT is the verbatim line text. Example output:
+
+1aa|const char *TITLE = \"Mr\";
+2ab|void greet(char *name) {
+3cd| return name;
+
+The LINE_NUMBER and HASH together form an anchor (e.g., 1aa, 2ab) that
+uniquely identifies a line by position and content. Copy anchors
+verbatim from the output when referencing lines in edit operations. Do
+not fabricate or modify hashes. Call this tool before editing any file
+to obtain current content and valid anchors. Re-call if anchors no
+longer match after external changes."
+ :args (list '(:name "file"
+ :type string
+ :description "Path to the file to read, relative to the working directory."))
+ :async nil
+ :confirm nil
+ :include t)
+
+;; TODO write_file (with-temp-buffer + insert)
+;; TODO edit_file (hashline + patch apply)
+
+;; TODO bash_readonly (shell-command-to-string, whitelisted commands)
+;; TODO bash (shell-command-to-string, needs heavy filtering)
+
+;; TODO find_files (directory-files-decursively)
+;; TODO grep (just grep :D)
+;; TODO fetch_url (use gptel-agent's one as a base, but needs mime handling like PDFs and images)
+;; TODO web_search (use gptel-agent's eww/shr method as a base)