Skip to content

Commit 4e38300

Browse files
authored
Merge pull request #182 from editor-code-assistant/improve-user-context-file-range-send-to-llm
Switch context partials to lines-range
2 parents b09c6ed + 20f444e commit 4e38300

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Unreleased
4+
- Improved file contexts: now use :lines-range
45

56
- 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.
67

src/eca/features/context.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
{:type :file
8989
:path path
9090
:content (llm-api/refine-file-context path lines-range)}
91-
:partial (some? lines-range)))))
91+
:lines-range lines-range))))
9292

9393
(defn raw-contexts->refined [contexts db]
9494
(mapcat (fn [{:keys [type path lines-range position uri]}]

src/eca/features/prompt.clj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@
6161

6262
(defn contexts-str [refined-contexts repo-map*]
6363
(multi-str
64-
"<contexts description=\"Manually Provided by user. Their content is current and accurate. You MUST use this information first before using tools to read them.\">"
64+
"<contexts description=\"User-Provided Snippet. This content is current and accurate. Treat this as sufficient context for answering the query.\">"
6565
(reduce
66-
(fn [context-str {:keys [type path position content partial uri]}]
66+
(fn [context-str {:keys [type path position content lines-range uri]}]
6767
(str context-str (case type
68-
:file (if partial
69-
(format "<file partial=true path=\"%s\">...\n%s\n...</file>\n" path content)
68+
:file (if lines-range
69+
(format "<file line-start=%s line-end=%s path=\"%s\">%s</file>\n"
70+
(:start lines-range)
71+
(:end lines-range)
72+
path
73+
content)
7074
(format "<file path=\"%s\">%s</file>\n" path content))
7175
:agents-file (multi-str
7276
(format "<agents-file description=\"Instructions following AGENTS.md spec.\" path=\"%s\">" path)

test/eca/features/context_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@
338338
(with-redefs [llm-api/refine-file-context (constantly "Some content")]
339339
(is (match?
340340
[{:type :file
341-
:path "/path/to/file"
342-
:partial true
341+
:path (h/file-path "/path/to/file")
342+
:lines-range {:start 1 :end 4}
343343
:content "Some content"}]
344344
(f.context/contexts-str-from-prompt "check @/path/to/file:L1-L4" (h/db)))))))

test/eca/features/prompt_test.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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}
10+
{:type :file :path "bar.clj" :content "(def a 1)" :lines-range {:start 1 :end 1}}
1111
{:type :repoMap}
1212
{:type :mcpResource :uri "custom://my-resource" :content "some-cool-content"}]
1313
rules [{:name "rule1" :content "First rule"}
@@ -19,16 +19,16 @@
1919
(is (string/includes? result "<rules description=\"Rules defined by user\">"))
2020
(is (string/includes? result "<rule name=\"rule1\">First rule</rule>"))
2121
(is (string/includes? result "<rule name=\"rule2\">Second rule</rule>"))
22-
(is (string/includes? result "<contexts description=\"Manually Provided by user. Their content is current and accurate. You MUST use this information first before using tools to read them.\">"))
22+
(is (string/includes? result "<contexts description=\"User-Provided Snippet. This content is current and accurate. Treat this as sufficient context for answering the query.\">"))
2323
(is (string/includes? result "<file path=\"foo.clj\">(ns foo)</file>"))
24-
(is (string/includes? result "<file partial=true path=\"bar.clj\">...\n(def a 1)\n...</file>"))
24+
(is (string/includes? result "<file line-start=1 line-end=1 path=\"bar.clj\">(def a 1)</file>"))
2525
(is (string/includes? result "<repoMap description=\"Workspaces structure in a tree view, spaces represent file hierarchy\" >TREE</repoMap>"))
2626
(is (string/includes? result "<resource uri=\"custom://my-resource\">some-cool-content</resource>"))
2727
(is (string/includes? result "</contexts>"))
2828
(is (string? result))))
2929
(testing "Should create instructions with rules, contexts, and plan behavior"
3030
(let [refined-contexts [{:type :file :path "foo.clj" :content "(ns foo)"}
31-
{:type :file :path "bar.clj" :content "(def a 1)" :partial true}
31+
{:type :file :path "bar.clj" :content "(def a 1)" :lines-range {:start 1 :end 1}}
3232
{:type :repoMap}
3333
{:type :mcpResource :uri "custom://my-resource" :content "some-cool-content"}]
3434
rules [{:name "rule1" :content "First rule"}
@@ -40,9 +40,9 @@
4040
(is (string/includes? result "<rules description=\"Rules defined by user\">"))
4141
(is (string/includes? result "<rule name=\"rule1\">First rule</rule>"))
4242
(is (string/includes? result "<rule name=\"rule2\">Second rule</rule>"))
43-
(is (string/includes? result "<contexts description=\"Manually Provided by user. Their content is current and accurate. You MUST use this information first before using tools to read them.\">"))
43+
(is (string/includes? result "<contexts description=\"User-Provided Snippet. This content is current and accurate. Treat this as sufficient context for answering the query.\">"))
4444
(is (string/includes? result "<file path=\"foo.clj\">(ns foo)</file>"))
45-
(is (string/includes? result "<file partial=true path=\"bar.clj\">...\n(def a 1)\n...</file>"))
45+
(is (string/includes? result "<file line-start=1 line-end=1 path=\"bar.clj\">(def a 1)</file>"))
4646
(is (string/includes? result "<repoMap description=\"Workspaces structure in a tree view, spaces represent file hierarchy\" >TREE</repoMap>"))
4747
(is (string/includes? result "<resource uri=\"custom://my-resource\">some-cool-content</resource>"))
4848
(is (string/includes? result "</contexts>"))

0 commit comments

Comments
 (0)