Skip to content

Commit 5ca71cc

Browse files
committed
Improve system prompt to add project env context.
1 parent 31d65c8 commit 5ca71cc

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

resources/prompts/additional_system_info.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Project Environment Context
1+
## Project Environment Context
22

33
Workspaces: {workspaceRoots}
44

resources/prompts/agent_behavior.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1+
# ECA — Editor Code Assistant
2+
13
You are ECA (Editor Code Assistant), an AI coding assistant that operates on an editor.
24

35
You are pair programming with a USER to solve their coding task. Each time the USER sends a message, we may automatically attach some context information about their current state, such as passed contexts, rules defined by USER, project structure, and more. This information may or may not be relevant to the coding task, it is up for you to decide.
46

57
You are an agent - please keep going until the user's query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved. Autonomously resolve the query to the best of your ability before coming back to the user.
68

7-
<edit_file_instructions>
9+
## Edit file instructions
10+
811
NEVER show the code edits or new files to the user - only call the proper tool. The system will apply and display the edits.
912
For each file, give a short description of what needs to be edited, then use the available tool. You can use the tool multiple times in a response, and you can keep writing text after using a tool. Prefer multiple tool calls for specific code block changes instead of one big call changing the whole file or unnecessary parts of the code.
10-
</edit_file_instructions>
1113

12-
<communication>
14+
## Communication
15+
1316
The chat is markdown mode.
1417
When using markdown in assistant messages, use backticks to format file, directory, function, and class names.
1518
Pay attention to the language name after the code block backticks start, use the full language name like 'javascript' instead of 'js'.
16-
</communication>
1719

18-
<tool_calling>
20+
## Tool calling
21+
1922
You have tools at your disposal to solve the coding task. Follow these rules regarding tool calls:
2023
1. ALWAYS follow the tool call schema exactly as specified and make sure to provide all necessary parameters.
2124
2. If you need additional information that you can get via tool calls, prefer that over asking the user.
2225
3. If you are not sure about file content or codebase structure pertaining to the user's request, use your tools to read files and gather the relevant information: do NOT guess or make up an answer.
2326
4. You have the capability to call multiple tools in a single response, batch your tool calls together for optimal performance.
24-
</tool_calling>

src/eca/features/prompt.clj

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,28 @@
6161

6262
(defn contexts-str [refined-contexts repo-map*]
6363
(multi-str
64-
"<contexts description=\"User-Provided Snippet. This content is current and accurate. Treat this as sufficient context for answering the query.\">"
64+
"<contexts description=\"User-Provided. This content is current and accurate. Treat this as sufficient context for answering the query.\">"
65+
""
6566
(reduce
66-
(fn [context-str {:keys [type path position content lines-range uri]}]
67+
(fn [context-str {:keys [type path position content lines-range uri] :as a}]
6768
(str context-str (case type
6869
:file (if lines-range
69-
(format "<file line-start=%s line-end=%s path=\"%s\">%s</file>\n"
70+
(format "<file line-start=%s line-end=%s path=\"%s\">%s</file>\n\n"
7071
(:start lines-range)
7172
(:end lines-range)
7273
path
7374
content)
74-
(format "<file path=\"%s\">%s</file>\n" path content))
75+
(format "<file path=\"%s\">%s</file>\n\n" path content))
7576
:agents-file (multi-str
7677
(format "<agents-file description=\"Instructions following AGENTS.md spec.\" path=\"%s\">" path)
7778
content
78-
"</agents-file>\n")
79-
:repoMap (format "<repoMap description=\"Workspaces structure in a tree view, spaces represent file hierarchy\" >%s</repoMap>\n" @repo-map*)
80-
:cursor (format "<cursor description=\"User editor cursor position (line:character)\" path=\"%s\" start=\"%s\" end=\"%s\"/>\n"
79+
"</agents-file>\n\n")
80+
:repoMap (format "<repoMap description=\"Workspaces structure in a tree view, spaces represent file hierarchy\" >%s</repoMap>\n\n" @repo-map*)
81+
:cursor (format "<cursor description=\"User editor cursor position (line:character)\" path=\"%s\" start=\"%s\" end=\"%s\"/>\n\n"
8182
path
8283
(str (:line (:start position)) ":" (:character (:start position)))
8384
(str (:line (:end position)) ":" (:character (:end position))))
84-
:mcpResource (format "<resource uri=\"%s\">%s</resource>\n" uri content)
85+
:mcpResource (format "<resource uri=\"%s\">%s</resource>\n\n" uri content)
8586
"")))
8687
""
8788
refined-contexts)
@@ -91,7 +92,9 @@
9192
(multi-str
9293
(eca-chat-prompt behavior config)
9394
(when (seq rules)
94-
["<rules description=\"Rules defined by user\">\n"
95+
["## Rules"
96+
""
97+
"<rules description=\"Rules defined by user\">\n"
9598
(reduce
9699
(fn [rule-str {:keys [name content]}]
97100
(str rule-str (format "<rule name=\"%s\">%s</rule>\n" name content)))
@@ -100,7 +103,9 @@
100103
"</rules>"])
101104
""
102105
(when (seq refined-contexts)
103-
[(contexts-str refined-contexts repo-map*)])
106+
["## Contexts"
107+
""
108+
(contexts-str refined-contexts repo-map*)])
104109
""
105110
(replace-vars
106111
(load-builtin-prompt "additional_system_info.md")

test/eca/features/prompt_test.clj

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
{:name "rule2" :content "Second rule"}]
1616
fake-repo-map (delay "TREE")
1717
behavior "agent"
18-
result (prompt/build-chat-instructions refined-contexts rules fake-repo-map behavior {} (h/db))]
18+
config {}
19+
result (prompt/build-chat-instructions refined-contexts rules fake-repo-map behavior config (h/db))]
1920
(is (string/includes? result "You are ECA"))
2021
(is (string/includes? result "<rules description=\"Rules defined by user\">"))
2122
(is (string/includes? result "<rule name=\"rule1\">First rule</rule>"))
2223
(is (string/includes? result "<rule name=\"rule2\">Second rule</rule>"))
23-
(is (string/includes? result "<contexts description=\"User-Provided Snippet. This content is current and accurate. Treat this as sufficient context for answering the query.\">"))
24+
(is (string/includes? result "<contexts description=\"User-Provided. This content is current and accurate. Treat this as sufficient context for answering the query.\">"))
2425
(is (string/includes? result "<file path=\"foo.clj\">(ns foo)</file>"))
2526
(is (string/includes? result "<file line-start=1 line-end=1 path=\"bar.clj\">(def a 1)</file>"))
2627
(is (string/includes? result "<repoMap description=\"Workspaces structure in a tree view, spaces represent file hierarchy\" >TREE</repoMap>"))
@@ -36,15 +37,16 @@
3637
{:name "rule2" :content "Second rule"}]
3738
fake-repo-map (delay "TREE")
3839
behavior "plan"
39-
result (prompt/build-chat-instructions refined-contexts rules fake-repo-map behavior {} (h/db))]
40+
config {}
41+
result (prompt/build-chat-instructions refined-contexts rules fake-repo-map behavior config (h/db))]
4042
(is (string/includes? result "You are ECA"))
4143
(is (string/includes? result "<rules description=\"Rules defined by user\">"))
4244
(is (string/includes? result "<rule name=\"rule1\">First rule</rule>"))
4345
(is (string/includes? result "<rule name=\"rule2\">Second rule</rule>"))
44-
(is (string/includes? result "<contexts description=\"User-Provided Snippet. This content is current and accurate. Treat this as sufficient context for answering the query.\">"))
45-
(is (string/includes? result "<file path=\"foo.clj\">(ns foo)</file>"))
46-
(is (string/includes? result "<file line-start=1 line-end=1 path=\"bar.clj\">(def a 1)</file>"))
47-
(is (string/includes? result "<repoMap description=\"Workspaces structure in a tree view, spaces represent file hierarchy\" >TREE</repoMap>"))
48-
(is (string/includes? result "<resource uri=\"custom://my-resource\">some-cool-content</resource>"))
49-
(is (string/includes? result "</contexts>"))
50-
(is (string? result)))))
46+
(is (string/includes? result "<contexts description=\"User-Provided. This content is current and accurate. Treat this as sufficient context for answering the query.\">"))
47+
(is (string/includes? result "<file path=\"foo.clj\">(ns foo)</file>"))
48+
(is (string/includes? result "<file line-start=1 line-end=1 path=\"bar.clj\">(def a 1)</file>"))
49+
(is (string/includes? result "<repoMap description=\"Workspaces structure in a tree view, spaces represent file hierarchy\" >TREE</repoMap>"))
50+
(is (string/includes? result "<resource uri=\"custom://my-resource\">some-cool-content</resource>"))
51+
(is (string/includes? result "</contexts>"))
52+
(is (string? result)))))

0 commit comments

Comments
 (0)