Skip to content

Commit 8c7f33f

Browse files
committed
Fix directories not working in user prompt.
Fixes #273
1 parent c45ab26 commit 8c7f33f

3 files changed

Lines changed: 34 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Improve error handling on chat messages, avoiding stuck and losing chat history. #272
6+
- Fix directories not working in user prompt. #273
67

78
## 0.92.2
89

src/eca/features/context.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@
126126
"Extract all contexts (@something) and refine them.
127127
Parse lines if present in contexts like @/path/to/file:L1-L4"
128128
[prompt db]
129-
(let [;; Capture @<path> with optional :L<start>-L<end>
129+
(let [ ;; Capture @<path> with optional :L<start>-L<end>
130130
context-pattern #"@([^\s:]+)(?::L(\d+)-L(\d+))?"
131131
matches (re-seq context-pattern prompt)
132132
raw-contexts (mapv (fn [[_ path s e]]
133-
(assoc-some {:type "file"
133+
(assoc-some {:type (if (fs/directory? path) "directory" "file")
134134
:path path}
135135
:lines-range (when (and s e)
136136
{:start (Integer/parseInt s)

test/eca/features/context_test.clj

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -321,22 +321,22 @@
321321
:path b-file
322322
:content b-content}])
323323
(#'f.context/parse-agents-file a-file)))))))
324-
(testing "Missing referenced file is ignored"
325-
(let [a-file (h/file-path "/fake/AGENTS.md")
326-
a-content (multi-str
327-
"- do foo"
328-
"- check @missing.md for missing things")
329-
missing-file (h/file-path "/fake/missing.md")]
330-
(with-redefs [llm-api/refine-file-context (fn [p _l]
331-
(condp = p
332-
a-file a-content
333-
missing-file nil))]
334-
(is (match?
335-
(m/in-any-order
336-
[{:type :agents-file
337-
:path a-file
338-
:content a-content}])
339-
(#'f.context/parse-agents-file a-file))))))
324+
(testing "Missing referenced file is ignored"
325+
(let [a-file (h/file-path "/fake/AGENTS.md")
326+
a-content (multi-str
327+
"- do foo"
328+
"- check @missing.md for missing things")
329+
missing-file (h/file-path "/fake/missing.md")]
330+
(with-redefs [llm-api/refine-file-context (fn [p _l]
331+
(condp = p
332+
a-file a-content
333+
missing-file nil))]
334+
(is (match?
335+
(m/in-any-order
336+
[{:type :agents-file
337+
:path a-file
338+
:content a-content}])
339+
(#'f.context/parse-agents-file a-file))))))
340340

341341
(deftest contexts-str-from-prompt-test
342342
(testing "not context mention"
@@ -359,4 +359,18 @@
359359
:path "/path/to/file"
360360
:lines-range {:start 1 :end 4}
361361
:content "Some content"}]
362-
(f.context/contexts-str-from-prompt "check @/path/to/file:L1-L4" (h/db)))))))
362+
(f.context/contexts-str-from-prompt "check @/path/to/file:L1-L4" (h/db))))))
363+
(testing "directory"
364+
(with-redefs [fs/readable? (constantly true)
365+
fs/directory? (fn [path]
366+
(= "/path/to/folder" path))
367+
fs/glob (constantly ["/path/to/folder/foo.txt" "/path/to/folder/bar.s"])
368+
llm-api/refine-file-context (constantly "Some content")]
369+
(is (match?
370+
[{:type :file
371+
:path "/path/to/folder/foo.txt"
372+
:content "Some content"}
373+
{:type :file
374+
:path "/path/to/folder/bar.s"
375+
:content "Some content"}]
376+
(f.context/contexts-str-from-prompt "check @/path/to/folder" (h/db)))))))

0 commit comments

Comments
 (0)