diff --git a/CHANGELOG.md b/CHANGELOG.md index ed971958..d96e920f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased +- Improved file contexts: now use :lines-range - BREAKING ECA now only supports standard plain-text netrc as credential file reading. Drop authinfo and gpg decryption support. Users can choose to pass in their own provisioned netrc file from various secure source with `:netrcFile` in ECA config. diff --git a/src/eca/features/context.clj b/src/eca/features/context.clj index 1a7ab683..a622a6ad 100644 --- a/src/eca/features/context.clj +++ b/src/eca/features/context.clj @@ -88,7 +88,7 @@ {:type :file :path path :content (llm-api/refine-file-context path lines-range)} - :partial (some? lines-range))))) + :lines-range lines-range)))) (defn raw-contexts->refined [contexts db] (mapcat (fn [{:keys [type path lines-range position uri]}] diff --git a/src/eca/features/prompt.clj b/src/eca/features/prompt.clj index baf21362..4e8506dd 100644 --- a/src/eca/features/prompt.clj +++ b/src/eca/features/prompt.clj @@ -61,12 +61,16 @@ (defn contexts-str [refined-contexts repo-map*] (multi-str - "" + "" (reduce - (fn [context-str {:keys [type path position content partial uri]}] + (fn [context-str {:keys [type path position content lines-range uri]}] (str context-str (case type - :file (if partial - (format "...\n%s\n...\n" path content) + :file (if lines-range + (format "%s\n" + (:start lines-range) + (:end lines-range) + path + content) (format "%s\n" path content)) :agents-file (multi-str (format "" path) diff --git a/test/eca/features/context_test.clj b/test/eca/features/context_test.clj index 6595c777..62db77b5 100644 --- a/test/eca/features/context_test.clj +++ b/test/eca/features/context_test.clj @@ -338,7 +338,7 @@ (with-redefs [llm-api/refine-file-context (constantly "Some content")] (is (match? [{:type :file - :path "/path/to/file" - :partial true + :path (h/file-path "/path/to/file") + :lines-range {:start 1 :end 4} :content "Some content"}] (f.context/contexts-str-from-prompt "check @/path/to/file:L1-L4" (h/db))))))) diff --git a/test/eca/features/prompt_test.clj b/test/eca/features/prompt_test.clj index 8c364bbb..91978d5b 100644 --- a/test/eca/features/prompt_test.clj +++ b/test/eca/features/prompt_test.clj @@ -7,7 +7,7 @@ (deftest build-instructions-test (testing "Should create instructions with rules, contexts, and behavior" (let [refined-contexts [{:type :file :path "foo.clj" :content "(ns foo)"} - {:type :file :path "bar.clj" :content "(def a 1)" :partial true} + {:type :file :path "bar.clj" :content "(def a 1)" :lines-range {:start 1 :end 1}} {:type :repoMap} {:type :mcpResource :uri "custom://my-resource" :content "some-cool-content"}] rules [{:name "rule1" :content "First rule"} @@ -19,16 +19,16 @@ (is (string/includes? result "")) (is (string/includes? result "First rule")) (is (string/includes? result "Second rule")) - (is (string/includes? result "")) + (is (string/includes? result "")) (is (string/includes? result "(ns foo)")) - (is (string/includes? result "...\n(def a 1)\n...")) + (is (string/includes? result "(def a 1)")) (is (string/includes? result "TREE")) (is (string/includes? result "some-cool-content")) (is (string/includes? result "")) (is (string? result)))) (testing "Should create instructions with rules, contexts, and plan behavior" (let [refined-contexts [{:type :file :path "foo.clj" :content "(ns foo)"} - {:type :file :path "bar.clj" :content "(def a 1)" :partial true} + {:type :file :path "bar.clj" :content "(def a 1)" :lines-range {:start 1 :end 1}} {:type :repoMap} {:type :mcpResource :uri "custom://my-resource" :content "some-cool-content"}] rules [{:name "rule1" :content "First rule"} @@ -40,9 +40,9 @@ (is (string/includes? result "")) (is (string/includes? result "First rule")) (is (string/includes? result "Second rule")) - (is (string/includes? result "")) + (is (string/includes? result "")) (is (string/includes? result "(ns foo)")) - (is (string/includes? result "...\n(def a 1)\n...")) + (is (string/includes? result "(def a 1)")) (is (string/includes? result "TREE")) (is (string/includes? result "some-cool-content")) (is (string/includes? result ""))