Skip to content

Commit f4b33cc

Browse files
committed
config
1 parent b0f619b commit f4b33cc

File tree

8 files changed

+111
-40
lines changed

8 files changed

+111
-40
lines changed

docs/configuration.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,21 @@ You can configure which model and system prompt ECA will use during its inline c
405405
}
406406
```
407407

408+
## Rewrite
409+
410+
You can configure which model and system prompt ECA will use during its rewrite feature:
411+
412+
=== "Example"
413+
414+
```javascript title="~/.config/eca/config.json"
415+
{
416+
"rewrite": {
417+
"model": "github-copilot/gpt-4.1",
418+
"systemPromptFile": "/path/to/my-prompt.md"
419+
}
420+
}
421+
```
422+
408423
## Opentelemetry integration
409424

410425
To configure, add your OTLP collector config via `:otlp` map following [otlp auto-configure settings](https://opentelemetry.io/docs/languages/java/configuration/#properties-general). Example:
@@ -516,6 +531,10 @@ To configure, add your OTLP collector config via `:otlp` map following [otlp aut
516531
model?: string;
517532
systemPromptFile?: string;
518533
};
534+
rewrite?: {
535+
model?: string;
536+
systemPromptFile?: string;
537+
};
519538
otlp?: {[key: string]: string};
520539
netrcFile?: string;
521540
}
@@ -589,6 +608,9 @@ To configure, add your OTLP collector config via `:otlp` map following [otlp aut
589608
"completion": {
590609
"model": "openai/gpt-4.1",
591610
"systemPromptFile": "prompts/inline_completion.md"
611+
},
612+
"rewrite": {
613+
"systemPromptFile": "prompts/rewrite.md"
592614
}
593615
}
594616
```

docs/features.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ Hooks are actions that can run before or after an specific event, useful to noti
135135

136136
For more details, check [hooks configuration](./configuration.md#hooks).
137137

138+
## Rewrite
139+
140+
Rewrite allow user to select part of the text and ask ECA to rewrite it using a configured model.
141+
142+
![](./images/features/rewrite.gif)
143+
138144
## Completion (alpha)
139145

140146
Inline code completion
@@ -148,9 +154,3 @@ For mode details check [configuration](./configuration.md#completion).
148154
ECA has support for [OpenTelemetry](https://opentelemetry.io/)(otlp), if configured, server tasks, tool calls, and more will be metrified via otlp API.
149155

150156
For more details check [its configuration](./configuration.md#opentelemetry-integration).
151-
152-
153-
## Edit
154-
155-
Soon
156-

docs/protocol.md

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ interface ChatPromptParams {
353353
* Different models may have different capabilities, response styles,
354354
* and performance characteristics.
355355
*/
356-
model?: ChatModel;
356+
model?: Model;
357357

358358
/**
359359
* The chat behavior used by server to handle chat communication and actions.
@@ -370,7 +370,7 @@ interface ChatPromptParams {
370370
/**
371371
* The LLM model name.
372372
*/
373-
type ChatModel = string;
373+
type Model = string;
374374

375375
type ChatContext = FileContext | DirectoryContext | WebContext | RepoMapContext | CursorContext |McpResourceContext;
376376

@@ -500,7 +500,7 @@ interface ChatPromptResponse {
500500
/*
501501
* The model used for this chat request.
502502
*/
503-
model: ChatModel;
503+
model: Model;
504504

505505
/**
506506
* What the server is doing after receing this prompt
@@ -540,7 +540,7 @@ interface ChatContentReceivedParams {
540540
* Different types of content that can be received from the LLM
541541
*/
542542
type ChatContent =
543-
| ChatTextContent
543+
ChatTextContent
544544
| ChatURLContent
545545
| ChatProgressContent
546546
| ChatUsageContent
@@ -1420,12 +1420,6 @@ interface RewritePromptParams {
14201420
*/
14211421
prompt: string;
14221422

1423-
/**
1424-
* The model used for this rewrite.
1425-
* If null, server will use default model.
1426-
*/
1427-
model?: ChatModel;
1428-
14291423
/**
14301424
* Optional path of the file.
14311425
* Useful for give context to LLM about the file path.
@@ -1448,7 +1442,55 @@ interface RewritePromptResponse {
14481442
* The status of this rewrite.
14491443
*/
14501444
status: 'prompting';
1445+
1446+
/**
1447+
* The model used by this rewrite request.
1448+
*/
1449+
model: Model;
1450+
}
1451+
```
1452+
1453+
### Rewrite Content Received (⬅️)
1454+
1455+
A server notification with a new content from the rewrite LLM request.
1456+
1457+
_Notification:_
1458+
1459+
* method: `rewrite/contentReceived`
1460+
* params: `RewriteContentReceivedParams` defined as follows:
1461+
1462+
```typescript
1463+
interface RewriteContentReceivedParams {
1464+
/**
1465+
* The rewrite identifier this content belongs to
1466+
*/
1467+
rewriteId: string;
1468+
1469+
/**
1470+
* The content received
1471+
*/
1472+
content: RewriteContent;
1473+
}
1474+
1475+
interface RewriteStartedContent {
1476+
type: 'started';
14511477
}
1478+
1479+
interface RewriteTextContent {
1480+
type: 'text';
1481+
1482+
text: string;
1483+
}
1484+
1485+
interface RewriteFinishedContent {
1486+
type: 'finished';
1487+
}
1488+
1489+
type RewriteContent =
1490+
RewriteStartedContent
1491+
| RewriteTextContent
1492+
| RewriteFinishedContent;
1493+
14521494
```
14531495

14541496
## Configuration
@@ -1473,7 +1515,7 @@ interface ConfigUpdatedParams {
14731515
/**
14741516
* The models the user can use in chat.
14751517
*/
1476-
models?: ChatModel[];
1518+
models?: Model[];
14771519

14781520
/**
14791521
* The chat behaviors the user can select.
@@ -1487,7 +1529,7 @@ interface ConfigUpdatedParams {
14871529
* Server returns this when starting and only when makes sense to
14881530
* force update a model, like a config change.
14891531
*/
1490-
selectModel?: ChatModel;
1532+
selectModel?: Model;
14911533

14921534
/**
14931535
* The behavior for client select in chat, if that is present

images/features/rewrite.gif

1.71 MB
Loading

src/eca/config.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
:maxEntriesPerDir 50}}
137137
:completion {:model "openai/gpt-4.1"
138138
:systemPromptFile "prompts/inline_completion.md"}
139+
:rewrite {:systemPromptFile "prompts/rewrite.md"}
139140
:netrcFile nil
140141
:env "prod"})
141142

src/eca/features/prompt.clj

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
(defn ^:private title-prompt-template* [] (slurp (io/resource "prompts/title.md")))
2626
(def ^:private title-prompt-template (memoize title-prompt-template*))
2727

28-
(defn ^:private rewrite-prompt-template* [] (slurp (io/resource "prompts/rewrite.md")))
29-
(def ^:private rewrite-prompt-template (memoize rewrite-prompt-template*))
30-
3128
(defn ^:private compact-prompt-template* [file-path]
3229
(if (fs/relative? file-path)
3330
(slurp (io/resource file-path))
@@ -106,22 +103,31 @@
106103
[(contexts-str refined-contexts repo-map*)])))
107104

108105
(defn build-rewrite-instructions [text path full-text range config]
109-
(replace-vars
110-
(rewrite-prompt-template)
111-
{:text text
112-
:path (when path
113-
(str "- File path: " path))
114-
:rangeText (multi-str
115-
(str "- Start line: " (-> range :start :line))
116-
(str "- Start character: " (-> range :start :character))
117-
(str "- End line: " (-> range :end :line))
118-
(str "- End character: " (-> range :end :character)))
119-
:fullText (when full-text
120-
(multi-str
121-
"- Full file content"
122-
"```"
123-
full-text
124-
"```"))}))
106+
(let [prompt-file (-> config :rewrite :systemPromptFile)
107+
prompt-str (cond
108+
;; Absolute path
109+
(and prompt-file (string/starts-with? prompt-file "/"))
110+
(slurp prompt-file)
111+
112+
;; Resource path
113+
:else
114+
(load-builtin-prompt (some-> prompt-file (string/replace-first #"prompts/" ""))))]
115+
(replace-vars
116+
prompt-str
117+
{:text text
118+
:path (when path
119+
(str "- File path: " path))
120+
:rangeText (multi-str
121+
(str "- Start line: " (-> range :start :line))
122+
(str "- Start character: " (-> range :start :character))
123+
(str "- End line: " (-> range :end :line))
124+
(str "- End character: " (-> range :end :character)))
125+
:fullText (when full-text
126+
(multi-str
127+
"- Full file content"
128+
"```"
129+
full-text
130+
"```"))})))
125131

126132
(defn init-prompt [db]
127133
(replace-vars

src/eca/features/rewrite.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
:content content}))
1919

2020
(defn prompt
21-
[{:keys [id prompt text path range model]} db* config messenger metrics]
21+
[{:keys [id prompt text path range]} db* config messenger metrics]
2222
(let [db @db*
23-
full-model (or model
23+
full-model (or (get-in config [:rewrite :model])
2424
(llm-api/default-model db config))
2525
[provider model] (string/split full-model #"/" 2)
2626
model-capabilities (get-in db [:models full-model])

src/eca/features/tools/filesystem.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
(smart-edit/apply-smart-edit file-content original-content new-content path)))
241241

242242

243-
(defn ^:private edit-file [arguments {:keys [db]}]
243+
(defn ^:private edit-file [arguments {:keys [_db]}]
244244
(or (tools.util/invalid-arguments arguments (concat (path-validations)
245245
[["path" fs/readable? "File $path is not readable"]]))
246246
(let [path (get arguments "path")

0 commit comments

Comments
 (0)