summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gptel-tools-hl.el60
1 files changed, 42 insertions, 18 deletions
diff --git a/gptel-tools-hl.el b/gptel-tools-hl.el
index d186dd3..45d44fe 100644
--- a/gptel-tools-hl.el
+++ b/gptel-tools-hl.el
@@ -59,24 +59,48 @@ Precisely: https://raw.githubusercontent.com/can1357/oh-my-pi/85003ca/packages/c
59 59
60(defun hl-file-read (file) 60(defun hl-file-read (file)
61 "Return FILE contents in hashline format." 61 "Return FILE contents in hashline format."
62 (let ((lines (with-temp-buffer 62 (with-temp-buffer
63 (insert-file-contents-literally file) 63 (insert-file-contents-literally file)
64 (string-lines (buffer-string))))) 64 (let ((lines (string-lines (buffer-string))))
65 (string-join 65 (string-join
66 (cl-mapcar (lambda (line i) 66 (cl-mapcar (lambda (line i)
67 (format "%d:%2s|%s" i (hl-hash line) line)) 67 (format "%d%2s|%s" i (hl-hash line) line))
68 lines 68 lines
69 (number-sequence 1 (length lines))) 69 (number-sequence 1 (length lines)))
70 "\n"))) 70 "\n"))))
71 71
72(defun hl-file-read-range (file beg end)
73 "Return FILE contents in hashline format from lines BEG to END."
74 (with-temp-buffer
75 (insert-file-contents-literally file)
76 (let ((lines (cl-subseq (string-lines (buffer-string))
77 (1- beg) end)))
78 (string-join
79 (cl-mapcar (lambda (line i)
80 (format "%d%2s|%s" i (hl-hash line) line))
81 lines
82 (number-sequence beg (+ beg (1- (length lines)))))
83 "\n"))))
84
85;; FIXME might be redundant with =hl-file-line-hash= if I'm only
86;; verifying the hash of the anchors and telling LLM to re-read the
87;; file when they don't match
72(defun hl-file-read-hashes (file) 88(defun hl-file-read-hashes (file)
73 "Return FILE contents in hashline format without content." 89 "Return FILE contents in hashline format without content."
74 (let ((lines (with-temp-buffer 90 (with-temp-buffer
75 (insert-file-contents-literally file) 91 (insert-file-contents-literally file)
76 (string-lines (buffer-string))))) 92 (let ((lines (string-lines (buffer-string))))
77 (string-join 93 (string-join
78 (cl-mapcar (lambda (line i) 94 (cl-mapcar (lambda (line i)
79 (format "%d:%2s" i (hl-hash line))) 95 (format "%d%2s" i (hl-hash line)))
80 lines 96 lines
81 (number-sequence 1 (length lines))) 97 (number-sequence 1 (length lines)))
82 "\n"))) 98 "\n"))))
99
100(defun hl-file-line-hash (file n)
101 "Return the hash of the Nth line in FILE."
102 (with-temp-buffer
103 (insert-file-contents-literally file)
104 (let ((lines (string-lines (buffer-string))))
105 (hl-hash (elt lines (1- n))))))
106