Skip to content

Commit 772a779

Browse files
committed
Support @cursor context
1 parent b1a15fe commit 772a779

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

CHANGELOG.md

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

55
- Support timeout on `eca_shell_command` with default to 1min.
6+
- Support `@cursor` context representing the current editor cursor position. #103
67

78
## 0.50.2
89

docs/protocol.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ interface ChatPromptParams {
340340
*/
341341
type ChatModel = string;
342342

343-
type ChatContext = FileContext | DirectoryContext | WebContext | RepoMapContext | McpResourceContext;
343+
type ChatContext = FileContext | DirectoryContext | WebContext | RepoMapContext | CursorContext |McpResourceContext;
344344

345345
/**
346346
* Context related to a file in the workspace
@@ -394,6 +394,33 @@ interface RepoMapContext {
394394
type: 'repoMap';
395395
}
396396

397+
/**
398+
* Context about the cursor position in editor, sent by client.
399+
* Clients should track path and cursor position.
400+
*/
401+
interface CursorContext {
402+
type: 'cursor';
403+
404+
/**
405+
* File path of where the cursor is.
406+
*/
407+
path: string;
408+
409+
/**
410+
* Cursor position, if not using a selection start should be equal to end.
411+
*/
412+
position: {
413+
start: {
414+
line: number;
415+
character: number;
416+
},
417+
end: {
418+
line: number;
419+
character: number;
420+
}
421+
}
422+
}
423+
397424
/***
398425
* A MCP resource available from a MCP server.
399426
*/

src/eca/features/context.clj

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
(defn raw-contexts->refined [contexts db config]
3838
(concat (agents-file-contexts db config)
39-
(mapcat (fn [{:keys [type path lines-range uri]}]
39+
(mapcat (fn [{:keys [type path lines-range position uri]}]
4040
(case (name type)
4141
"file" [{:type :file
4242
:path path
@@ -50,6 +50,9 @@
5050
:path filename
5151
:content (llm-api/refine-file-context filename nil)}))))
5252
"repoMap" [{:type :repoMap}]
53+
"cursor" [{:type :cursor
54+
:path path
55+
:position position}]
5356
"mcpResource" (try
5457
(mapv
5558
(fn [{:keys [text]}]
@@ -59,7 +62,8 @@
5962
(:contents (f.mcp/get-resource! uri db)))
6063
(catch Exception e
6164
(logger/warn logger-tag (format "Error getting MCP resource %s: %s" uri (.getMessage e)))
62-
[]))))
65+
[]))
66+
nil))
6367
contexts)))
6468

6569
(defn ^:private contexts-for [root-filename query config]
@@ -114,7 +118,8 @@
114118
:path (shared/uri->filename uri)})
115119
(:workspace-folders @db*))
116120
mcp-resources (mapv #(assoc % :type "mcpResource") (f.mcp/all-resources @db*))]
117-
(concat [{:type "repoMap"}]
121+
(concat [{:type "repoMap"}
122+
{:type "cursor"}]
118123
root-dirs
119124
relative-files
120125
workspace-files

src/eca/features/prompt.clj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@
6161
""
6262
"<contexts description=\"Manually provided by user, usually when provided user knows that your task is related to those files, so consider reliying on it but use tools to read/find any extra files/contexts if really needed.\">"
6363
(reduce
64-
(fn [context-str {:keys [type path content partial uri]}]
64+
(fn [context-str {:keys [type path position content partial uri]}]
6565
(str context-str (case type
6666
:file (if partial
6767
(format "<file partial=true path=\"%s\">...\n%s\n...</file>\n" path content)
6868
(format "<file path=\"%s\">%s</file>\n" path content))
6969
:repoMap (format "<repoMap description=\"Workspaces structure in a tree view, spaces represent file hierarchy\" >%s</repoMap>\n" @repo-map*)
70+
:cursor (format "<cursor description=\"Editor cursor position\" path=\"%s\" start=\"%s\" end=\"%s\"/>"
71+
path
72+
(str (:line (:start position)) ":" (:character (:start position)))
73+
(str (:line (:end position)) ":" (:character (:end position))))
7074
:mcpResource (format "<resource uri=\"%s\">%s</resource>\n" uri content)
7175
"")))
7276
""

0 commit comments

Comments
 (0)