From 9ef07eff462efadd80d59bdc445de40be5ed2b2f Mon Sep 17 00:00:00 2001 From: sid1057 Date: Mon, 26 Jan 2026 22:26:39 +0300 Subject: [PATCH] feat(oss-mode): Add support for open-source mode features --- README.md | 1 + lua/codex/init.lua | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 47339a4..70399a7 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ return { border = 'rounded', -- Options: 'single', 'double', or 'rounded' width = 0.8, -- Width of the floating window (0.0 to 1.0) height = 0.8, -- Height of the floating window (0.0 to 1.0) + oss = false, -- Select the local open source model provider model = nil, -- Optional: pass a string to use a specific model (e.g., 'o3-mini') autoinstall = true, -- Automatically install the Codex CLI if not found panel = false, -- Open Codex in a side-panel (vertical split) instead of floating window diff --git a/lua/codex/init.lua b/lua/codex/init.lua index 4378b46..2ad43d3 100644 --- a/lua/codex/init.lua +++ b/lua/codex/init.lua @@ -13,10 +13,11 @@ local config = { width = 0.8, height = 0.8, cmd = 'codex', + oss = false, -- Select the local open source model provider model = nil, -- Default to the latest model autoinstall = true, - panel = false, -- if true, open Codex in a side-panel instead of floating window - use_buffer = false, -- if true, capture Codex stdout into a normal buffer instead of a terminal + panel = false, -- if true, open Codex in a side-panel instead of floating window + use_buffer = false, -- if true, capture Codex stdout into a normal buffer instead of a terminal } function M.setup(user_config) @@ -91,7 +92,7 @@ end --- Open Codex in a side-panel (vertical split) instead of floating window local function open_panel() -- Create a vertical split on the right and show the buffer - vim.cmd('vertical rightbelow vsplit') + vim.cmd 'vertical rightbelow vsplit' local win = vim.api.nvim_get_current_win() vim.api.nvim_win_set_buf(win, state.buf) -- Adjust width according to config (percentage of total columns) @@ -142,7 +143,11 @@ function M.open() 'You can install manually with:', ' npm install -g @openai/codex', }) - if config.panel then open_panel() else open_window() end + if config.panel then + open_panel() + else + open_window() + end end end) return @@ -159,7 +164,11 @@ function M.open() '', 'Or enable autoinstall in setup: require("codex").setup{ autoinstall = true }', }) - if config.panel then open_panel() else open_window() end + if config.panel then + open_panel() + else + open_window() + end return end end @@ -172,11 +181,19 @@ function M.open() state.buf = create_clean_buf() end - if config.panel then open_panel() else open_window() end + if config.panel then + open_panel() + else + open_window() + end if not state.job then -- assemble command local cmd_args = type(config.cmd) == 'string' and { config.cmd } or vim.deepcopy(config.cmd) + if config.oss then + table.insert(cmd_args, '--oss') + end + if config.model then table.insert(cmd_args, '-m') table.insert(cmd_args, config.model) @@ -188,7 +205,9 @@ function M.open() cwd = vim.loop.cwd(), stdout_buffered = true, on_stdout = function(_, data) - if not data then return end + if not data then + return + end for _, line in ipairs(data) do if line ~= '' then vim.api.nvim_buf_set_lines(state.buf, -1, -1, false, { line }) @@ -196,7 +215,9 @@ function M.open() end end, on_stderr = function(_, data) - if not data then return end + if not data then + return + end for _, line in ipairs(data) do if line ~= '' then vim.api.nvim_buf_set_lines(state.buf, -1, -1, false, { '[ERR] ' .. line })