File tree Expand file tree Collapse file tree 6 files changed +31
-10
lines changed
Expand file tree Collapse file tree 6 files changed +31
-10
lines changed Original file line number Diff line number Diff line change 22
33## Unreleased
44
5+ - Add support for file contexts with line ranges.
6+
57## 0.10.3
68
79- Fix openai ` max_output_tokens ` message.
Original file line number Diff line number Diff line change @@ -289,6 +289,14 @@ interface FileContext {
289289 * Path to the file
290290 */
291291 path: string ;
292+
293+ /**
294+ * Range of lines to retrive from file, if nil consider whole file.
295+ */
296+ linesRange? : {
297+ start: number ;
298+ end: number ;
299+ }
292300}
293301
294302/**
Original file line number Diff line number Diff line change 1818(def ^:private logger-tag " [CHAT]" )
1919
2020(defn ^:private raw-contexts->refined [contexts]
21- (mapcat (fn [{:keys [type path]}]
21+ (mapcat (fn [{:keys [type path lines-range ]}]
2222 (case type
2323 " file" [{:type :file
2424 :path path
25- :content (llm-api/refine-file-context path)}]
25+ :partial (boolean lines-range)
26+ :content (llm-api/refine-file-context path lines-range)}]
2627 " directory" (->> (fs/glob path " **" )
2728 (remove fs/directory?)
2829 (map (fn [path]
2930 (let [filename (str (fs/canonicalize path))]
3031 {:type :file
3132 :path filename
32- :content (llm-api/refine-file-context filename)}))))
33+ :content (llm-api/refine-file-context filename nil )}))))
3334 " repoMap" [{:type :repoMap }]))
3435 contexts))
3536
Original file line number Diff line number Diff line change 3131 " "
3232 " <contexts>"
3333 (reduce
34- (fn [context-str {:keys [type path content]}]
34+ (fn [context-str {:keys [type path content partial ]}]
3535 (str context-str (case type
36- :file (format " <file path=\" %s\" >%s</file>\n " path content)
36+ :file (if partial
37+ (format " <file partial=true path=\" %s\" >...\n %s\n ...</file>\n " path content)
38+ (format " <file path=\" %s\" >%s</file>\n " path content))
3739 :repoMap (format " <repoMap description=\" Workspaces structure in a tree view, spaces represent file hierarchy\" >%s</repoMap>" @repo-map*)
3840 " " )))
3941 " "
Original file line number Diff line number Diff line change 1515 (llm-providers.ollama/list-models {:host (:host (:ollama config))
1616 :port (:port (:ollama config))}))
1717
18- (defn refine-file-context [path]
19- ; ; TODO ask LLM for the most relevant parts of the path
20- (slurp path))
18+ ; ; TODO ask LLM for the most relevant parts of the path
19+ (defn refine-file-context [path lines-range]
20+ (let [content (slurp path)]
21+ (if lines-range
22+ (let [lines (string/split-lines content)
23+ start (dec (:start lines-range))
24+ end (min (count lines) (:end lines-range))]
25+ (string/join " \n " (subvec lines start end)))
26+ content)))
2127
2228(defn ^:private anthropic-api-key [config]
2329 (or (:anthropicApiKey config)
Original file line number Diff line number Diff line change 11(ns eca.features.prompt-test
22 (:require
3+ [clojure.string :as string]
34 [clojure.test :refer [deftest is testing]]
4- [eca.features.prompt :as prompt]
5- [clojure.string :as string]))
5+ [eca.features.prompt :as prompt]))
66
77(deftest build-instructions-test
88 (testing " Should create instructions with rules, contexts, and behavior"
99 (let [refined-contexts [{:type :file :path " foo.clj" :content " (ns foo)" }
10+ {:type :file :path " bar.clj" :content " (def a 1)" :partial true }
1011 {:type :repoMap :path nil :content nil }]
1112 rules [{:name " rule1" :content " First rule" }
1213 {:name " rule2" :content " Second rule" }]
1920 (is (string/includes? result " <rule name=\" rule2\" >Second rule</rule>" ))
2021 (is (string/includes? result " <contexts>" ))
2122 (is (string/includes? result " <file path=\" foo.clj\" >(ns foo)</file>" ))
23+ (is (string/includes? result " <file partial=true path=\" bar.clj\" >...\n (def a 1)\n ...</file>" ))
2224 (is (string/includes? result " <repoMap description=\" Workspaces structure in a tree view, spaces represent file hierarchy\" >TREE</repoMap>" ))
2325 (is (string/includes? result " </contexts>" ))
2426 (is (string? result)))))
You can’t perform that action at this time.
0 commit comments