Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ require("eca").setup({
usage_string_format = "{messageCost} / {sessionCost}",

-- === BEHAVIOR ===
behavior = {
behaviour = {
-- Set keymaps automatically
auto_set_keymaps = true,

-- Focus sidebar automatically when opening
auto_focus_sidebar = true,

-- Start server automatically
auto_start_server = false,
auto_start_server = true,

-- Download server automatically if not found
auto_download = true,
Expand Down Expand Up @@ -114,7 +114,7 @@ require("eca").setup({
### Minimalist
```lua
require("eca").setup({
behavior = { show_status_updates = false },
behaviour = { show_status_updates = false },
windows = { width = 30 },
chat = {
headers = {
Expand All @@ -128,7 +128,7 @@ require("eca").setup({
### Visual/UX focused
```lua
require("eca").setup({
behavior = { auto_focus_sidebar = true },
behaviour = { auto_focus_sidebar = true },
windows = {
width = 50,
wrap = true,
Expand All @@ -149,7 +149,7 @@ require("eca").setup({
require("eca").setup({
debug = true,
server_args = "--log-level debug",
behavior = {
behaviour = {
auto_start_server = true,
show_status_updates = true,
},
Expand All @@ -164,7 +164,7 @@ require("eca").setup({
### Performance-oriented
```lua
require("eca").setup({
behavior = {
behaviour = {
auto_focus_sidebar = false,
show_status_updates = false,
},
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Advanced setup example:
opts = {
debug = false,
server_path = "",
behavior = {
behaviour = {
auto_set_keymaps = true,
auto_focus_sidebar = true,
},
Expand Down
4 changes: 2 additions & 2 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Solutions:
Symptoms: `<leader>ec` doesn't open chat

Solutions:
- Ensure `behavior.auto_set_keymaps = true`
- Ensure `behaviour.auto_set_keymaps = true`
- Confirm your `<leader>` key (default: `\`)
- Configure shortcuts manually:

Expand All @@ -61,5 +61,5 @@ Symptoms: Lag when typing, slow responses

Solutions:
- Reduce window width: `windows.width = 25`
- Disable visual updates: `behavior.show_status_updates = false`
- Disable visual updates: `behaviour.show_status_updates = false`
- Use the minimalist configuration preset
5 changes: 0 additions & 5 deletions lua/eca/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ local M = {}
function M.chat(opts)
opts = opts or {}
local eca = require("eca")

if not M.is_server_running() then
M.start_server()
end

eca.open_sidebar(opts)
end

Expand Down
44 changes: 0 additions & 44 deletions lua/eca/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -343,50 +343,6 @@ function M.setup()
desc = "Emergency fix for treesitter issues in ECA chat",
})

vim.api.nvim_create_user_command("EcaChatSelectModel", function()
local eca = require("eca")

if not eca or not eca.current or not eca.current.sidebar then
Logger.notify("No active ECA sidebar found", vim.log.levels.WARN)
return
end

local chat = eca.current.sidebar
local models = chat.mediator:models()

vim.ui.select(models, {
prompt = "Select ECA Chat Model:",
}, function(choice)
if choice then
chat.mediator:update_selected_model(choice)
end
end)
end, {
desc = "Select current ECA Chat model",
})

vim.api.nvim_create_user_command("EcaChatSelectBehavior", function()
local eca = require("eca")

if not eca or not eca.current or not eca.current.sidebar then
Logger.notify("No active ECA sidebar found", vim.log.levels.WARN)
return
end

local chat = eca.current.sidebar
local behaviors = chat.mediator:behaviors()

vim.ui.select(behaviors, {
prompt = "Select ECA Chat Behavior:",
}, function(choice)
if choice then
chat.mediator:update_selected_behavior(choice)
end
end)
end, {
desc = "Select current ECA Chat behavior",
})

Logger.debug("ECA commands registered")
end

Expand Down
4 changes: 2 additions & 2 deletions lua/eca/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ M._defaults = {
file = "",
max_file_size_mb = 10, -- Maximum log file size in MB before warning
},
behavior = {
behaviour = {
auto_set_keymaps = true,
auto_focus_sidebar = true,
auto_start_server = false, -- Automatically start server on setup
auto_start_server = true, -- Automatically start server on setup
auto_download = true, -- Automatically download server if not found
show_status_updates = true, -- Show status updates in notifications
},
Expand Down
12 changes: 5 additions & 7 deletions lua/eca/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function H.keymaps()
require("eca.api").focus()
end, { noremap = true })

if Config.behavior and Config.behavior.auto_set_keymaps then
if Config.behaviour.auto_set_keymaps then
Utils.safe_keymap_set({ "n", "v" }, Config.mappings.chat, function()
require("eca.api").chat()
end, { desc = "eca: open chat" })
Expand Down Expand Up @@ -245,12 +245,10 @@ function M.setup(opts)
M.state = require("eca.state").new()
M.server = Server.new()
M.mediator = require("eca.mediator").new(M.server, M.state)

if Config.behavior and Config.behavior.auto_start_server then
vim.defer_fn(function()
M.server:start()
end, 100) -- Small delay to ensure everything is loaded
end
-- Start server automatically in background
vim.defer_fn(function()
M.server:start()
end, 100) -- Small delay to ensure everything is loaded

M.did_setup = true
end
Expand Down
16 changes: 0 additions & 16 deletions lua/eca/mediator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,14 @@ function mediator:send(method, params, callback)
self.server:send_request(method, params, callback)
end

function mediator:behaviors()
return self.state.config.behaviors.list
end

function mediator:selected_behavior()
return self.state.config.behaviors.selected
end

function mediator:update_selected_behavior(behavior)
self.state:update_selected_behavior(behavior)
end

function mediator:models()
return self.state.config.models.list
end

function mediator:selected_model()
return self.state.config.models.selected
end

function mediator:update_selected_model(model)
self.state:update_selected_model(model)
end

function mediator:tokens_session()
return self.state.usage.tokens.session
end
Expand Down
43 changes: 22 additions & 21 deletions lua/eca/path_finder.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local uv = vim.uv or vim.loop
local Utils = require("eca.utils")
local Config = require("eca.config")
local Logger = require("eca.logger")

---@class eca.PathFinder
Expand Down Expand Up @@ -99,7 +100,7 @@ function M:_write_version_file(version)
file:write(version)
file:close()
else
Logger.warn("Could not write version file: " .. self._version_file)
Logger.notify("Could not write version file: " .. self._version_file, vim.log.levels.WARN)
end
end

Expand Down Expand Up @@ -135,7 +136,7 @@ function M:_download_latest_server(server_path, version)

local download_path = self._cache_dir .. "/" .. artifact_name

Logger.debug("Downloading latest ECA server version from: " .. download_url)
Logger.notify("Downloading latest ECA server version from: " .. download_url, vim.log.levels.INFO)

-- Ensure cache directory exists
vim.fn.mkdir(self._cache_dir, "p")
Expand All @@ -149,7 +150,8 @@ function M:_download_latest_server(server_path, version)

local download_result = os.execute(download_cmd)
if download_result ~= 0 then
error("Failed to download ECA server from: " .. download_url)
Logger.notify("Failed to download ECA server from: " .. download_url, vim.log.levels.ERROR)
return false
end

-- Extract if it's a zip file
Expand All @@ -159,38 +161,42 @@ function M:_download_latest_server(server_path, version)

local extract_result = os.execute(extract_cmd)
if extract_result ~= 0 then
error("Failed to extract ECA server")
Logger.notify("Failed to extract ECA server", vim.log.levels.ERROR)
return false
end

-- Remove the zip file after extraction
os.remove(download_path)
end

-- Make executable (if not Windows)
if not uv.os_uname().sysname:lower():match("windows") then
if not vim.loop.os_uname().sysname:lower():match("windows") then
Copy link

Copilot AI Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using deprecated vim.loop instead of vim.uv. Should use vim.uv.os_uname() for consistency with the import at the top of the file.

Suggested change
if not vim.loop.os_uname().sysname:lower():match("windows") then
if not uv.os_uname().sysname:lower():match("windows") then

Copilot uses AI. Check for mistakes.
os.execute("chmod +x " .. vim.fn.shellescape(server_path))
end

if not Utils.file_exists(server_path) then
error("ECA server binary not found after download and extraction")
Logger.notify("ECA server binary not found after download and extraction", vim.log.levels.ERROR)
return false
end

-- Write version file
self:_write_version_file(version)

Logger.debug("ECA server downloaded successfully")

Logger.notify("ECA server downloaded successfully", vim.log.levels.INFO)
return true
end

---@return string
function M:find(custom_path)
function M:find()
-- Check for custom server path first
local custom_path = Config.server_path
if custom_path and custom_path:gsub("%s+", "") ~= "" then
if not Utils.file_exists(custom_path) then
error("Custom server path does not exist: " .. custom_path)
if Utils.file_exists(custom_path) then
Logger.debug("Using custom server path: " .. custom_path)
return custom_path
else
Logger.notify("Custom server path does not exist: " .. custom_path, vim.log.levels.WARN)
end
return custom_path
end

local server_path = self:_get_extension_server_path()
Expand All @@ -209,18 +215,13 @@ function M:find(custom_path)
-- Download if server doesn't exist or version is outdated
if not server_exists or (latest_version and current_version ~= latest_version) then
if not latest_version then
Logger.warn("Could not check for latest version, using existing server")
Logger.notify("Could not check for latest version, using existing server", vim.log.levels.WARN)
return server_path
end

local success

local ok, err = pcall(function()
success = self:_download_latest_server(server_path, latest_version)
end)

if not ok or not success then
error((err and tostring(err)) or "Failed to download ECA server")
local success = self:_download_latest_server(server_path, latest_version)
if not success then
error("Failed to download ECA server")
end
end

Expand Down
Loading