From a408b4668b20cf3376334216b4133cd9dc7a8a32 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 14 Jul 2026 00:27:49 +0000 Subject: [PATCH] feat: Add support for Continue Conversation Implemented support for the `-c` (`--continue`) and `--cid` (`--conversation`) options from the `llm` CLI. Added new configurations `continue_conversation` and `conversation_id` in `lua/llm/config.lua`. Added argument parsing logic in `lua/llm/commands.lua` and updated the prompt building functions to append them correctly. Added unit tests for `get_conversation_args` in `tests/spec/commands_spec.lua`. Updated `BACKLOG.md` to remove the item and re-rank the remaining ones. Co-authored-by: julwrites <18639913+julwrites@users.noreply.github.com> --- BACKLOG.md | 27 +++++++++++++-------------- lua/llm/commands.lua | 15 +++++++++++++++ lua/llm/config.lua | 10 ++++++++++ tests/spec/commands_spec.lua | 28 ++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 14 deletions(-) diff --git a/BACKLOG.md b/BACKLOG.md index fd4e5d4..9c4a3a2 100644 --- a/BACKLOG.md +++ b/BACKLOG.md @@ -37,17 +37,16 @@ - [Gap 11]: Missing support for System Fragment (`--sf`, `--system-fragment`). ## Ranked Backlog -1. [Gap 4] - [Medium Impact/Low Effort] - Add functionality to Continue Conversations (`-c`, `--continue`, `--cid`, `--conversation`) easily from previous prompt sessions. -2. [Gap 7] - [Medium Impact/Low Effort] - Add support for Schema Options (`--schema`, `--schema-multi`) in prompts. -3. [Gap 8] - [Medium Impact/Low Effort] - Add support to Save as Template (`--save`). -4. [Tech Debt 5] - [Medium Impact/Medium Effort] - Refactor duplicated command construction logic in `lua/llm/commands.lua`. -5. [Gap 1] - [Medium Impact/Medium Effort] - Implement Multi-modal attachment support for models that accept images or other data types (`-a`, `--attachment`, `--at`, `--attachment-type`). -6. [Gap 3] - [Medium Impact/Medium Effort] - Implement Extended Tool Options (`--functions`, `--td`, `--ta`, `--cl`). -7. [Tech Debt 2] - [Medium Impact/Medium Effort] - Enhance async job handling logic in `job.lua` for edge cases. -8. [Gap 2] - [Low Impact/Low Effort] - Expose token Usage tracking (`-u`, `--usage`) visually after execution. -9. [Gap 5] - [Low Impact/Low Effort] - Enable dynamic Query Selection (`-q`, `--query`). -10. [Gap 6] - [Low Impact/Low Effort] - Add options for explicit Async Execution (`--async`) and blocking Stream Control (`--no-stream`). -11. [Tech Debt 3] - [Low Impact/Low Effort] - Write explicit unit tests for `interactive_prompt_with_fragments` in `commands.lua`. -12. [Gap 9] - [Low Impact/Low Effort] - Add support for Extract Last (`--xl`, `--extract-last`). -13. [Gap 10] - [Low Impact/Low Effort] - Add support for Logging options (`-d`, `--database`, `-n`, `--no-log`, `--log`). -14. [Gap 11] - [Low Impact/Low Effort] - Add support for System Fragment (`--sf`, `--system-fragment`). +1. [Gap 7] - [Medium Impact/Low Effort] - Add support for Schema Options (`--schema`, `--schema-multi`) in prompts. +2. [Gap 8] - [Medium Impact/Low Effort] - Add support to Save as Template (`--save`). +3. [Tech Debt 5] - [Medium Impact/Medium Effort] - Refactor duplicated command construction logic in `lua/llm/commands.lua`. +4. [Gap 1] - [Medium Impact/Medium Effort] - Implement Multi-modal attachment support for models that accept images or other data types (`-a`, `--attachment`, `--at`, `--attachment-type`). +5. [Gap 3] - [Medium Impact/Medium Effort] - Implement Extended Tool Options (`--functions`, `--td`, `--ta`, `--cl`). +6. [Tech Debt 2] - [Medium Impact/Medium Effort] - Enhance async job handling logic in `job.lua` for edge cases. +7. [Gap 2] - [Low Impact/Low Effort] - Expose token Usage tracking (`-u`, `--usage`) visually after execution. +8. [Gap 5] - [Low Impact/Low Effort] - Enable dynamic Query Selection (`-q`, `--query`). +9. [Gap 6] - [Low Impact/Low Effort] - Add options for explicit Async Execution (`--async`) and blocking Stream Control (`--no-stream`). +10. [Tech Debt 3] - [Low Impact/Low Effort] - Write explicit unit tests for `interactive_prompt_with_fragments` in `commands.lua`. +11. [Gap 9] - [Low Impact/Low Effort] - Add support for Extract Last (`--xl`, `--extract-last`). +12. [Gap 10] - [Low Impact/Low Effort] - Add support for Logging options (`-d`, `--database`, `-n`, `--no-log`, `--log`). +13. [Gap 11] - [Low Impact/Low Effort] - Add support for System Fragment (`--sf`, `--system-fragment`). diff --git a/lua/llm/commands.lua b/lua/llm/commands.lua index 10ac3aa..e0d963d 100644 --- a/lua/llm/commands.lua +++ b/lua/llm/commands.lua @@ -132,6 +132,18 @@ function M.get_template_params_args() return {} end +-- Get conversation arguments if specified +function M.get_conversation_args() + local args = {} + local cid = config.get("conversation_id") + if cid and cid ~= "" then + return { "--cid", cid } + elseif config.get("continue_conversation") then + return { "-c" } + end + return {} +end + -- Run an llm command and return the result function M.get_pre_response_message(source, prompt, fragment_paths) @@ -261,6 +273,7 @@ function M.prompt(prompt, fragment_paths, bufnr) vim.list_extend(cmd_parts, M.get_model_options_args()) vim.list_extend(cmd_parts, M.get_template_arg()) vim.list_extend(cmd_parts, M.get_template_params_args()) + vim.list_extend(cmd_parts, M.get_conversation_args()) if fragment_paths then for _, fragment in ipairs(fragment_paths) do @@ -316,6 +329,7 @@ function M.prompt_with_current_file(prompt, fragment_paths, bufnr) vim.list_extend(cmd_parts, M.get_model_options_args()) vim.list_extend(cmd_parts, M.get_template_arg()) vim.list_extend(cmd_parts, M.get_template_params_args()) + vim.list_extend(cmd_parts, M.get_conversation_args()) -- Add user-specified fragments if fragment_paths then @@ -375,6 +389,7 @@ function M.prompt_with_selection(prompt, fragment_paths, from_visual_mode, bufnr vim.list_extend(cmd_parts, M.get_model_options_args()) vim.list_extend(cmd_parts, M.get_template_arg()) vim.list_extend(cmd_parts, M.get_template_params_args()) + vim.list_extend(cmd_parts, M.get_conversation_args()) if fragment_paths then vim.list_extend(cmd_parts, M.get_fragment_args(fragment_paths)) end diff --git a/lua/llm/config.lua b/lua/llm/config.lua index f780c9f..8911149 100644 --- a/lua/llm/config.lua +++ b/lua/llm/config.lua @@ -67,6 +67,16 @@ M.defaults = { type = "table", desc = "Key/value parameters for the template (e.g., {name = 'World'})" }, + continue_conversation = { + default = false, + type = "boolean", + desc = "Continue the most recent conversation" + }, + conversation_id = { + default = nil, + type = "string", + desc = "Continue the conversation with the given ID" + }, -- Add more config options here } diff --git a/tests/spec/commands_spec.lua b/tests/spec/commands_spec.lua index afd0654..4f10bde 100644 --- a/tests/spec/commands_spec.lua +++ b/tests/spec/commands_spec.lua @@ -160,6 +160,34 @@ describe('llm.commands', function() -- This is a new test suite for llm.commands end) end) + describe('get_conversation_args', function() + it('should return {--cid, cid} if conversation_id is set', function() + package.loaded['llm.config'].get = spy.new(function(key) + if key == 'conversation_id' then return 'test-id' end + return nil + end) + local result = commands.get_conversation_args() + assert.same({ '--cid', 'test-id' }, result) + end) + + it('should return {-c} if continue_conversation is true', function() + package.loaded['llm.config'].get = spy.new(function(key) + if key == 'continue_conversation' then return true end + return nil + end) + local result = commands.get_conversation_args() + assert.same({ '-c' }, result) + end) + + it('should return {} if neither are set', function() + package.loaded['llm.config'].get = spy.new(function(key) + return nil + end) + local result = commands.get_conversation_args() + assert.same({}, result) + end) + end) + describe('prompt', function() it('should call api.run_streaming_command with the correct arguments', function() commands.prompt('test prompt', {}, 1)