File size: 93,402 Bytes
2c916e8
1
2
{"repo_name": "goose.nvim", "file_name": "/goose.nvim/lua/goose/ui/file_picker.lua", "inference_info": {"prefix_code": "local M = {}\n\nlocal function get_best_picker()\n  local config = require(\"goose.config\")\n\n  local prefered_picker =  config.get('prefered_picker')\n  if prefered_picker and prefered_picker ~= \"\" then\n    return prefered_picker\n  end\n  \n  if pcall(require, \"telescope\") then return \"telescope\" end\n  if pcall(require, \"fzf-lua\") then return \"fzf\" end\n  if pcall(require, \"mini.pick\") then return \"mini.pick\" end\n  if pcall(require, \"snacks\") then return \"snacks\" end\n  return nil\nend\n\nlocal function format_file(path)\n  -- when path is something like: file.extension dir1/dir2 -> format to dir1/dir2/file.extension\n  local file_match, path_match = path:match(\"^(.-)\\t(.-)$\")\n  if file_match and path_match then\n    path = path_match .. \"/\" .. file_match\n  end\n\n  return {\n    name = vim.fn.fnamemodify(path, \":t\"),\n    path = path\n  }\nend\n\nlocal function telescope_ui(callback)\n  local builtin = require(\"telescope.builtin\")\n  local actions = require(\"telescope.actions\")\n  local action_state = require(\"telescope.actions.state\")\n\n  builtin.find_files({\n    attach_mappings = function(prompt_bufnr, map)\n      actions.select_default:replace(function()\n        local selection = action_state.get_selected_entry()\n        actions.close(prompt_bufnr)\n\n        if selection and callback then\n          callback(selection.value)\n        end\n      end)\n      return true\n    end\n  })\nend\n\nlocal function fzf_ui(callback)\n  local fzf_lua = require(\"fzf-lua\")\n\n  fzf_lua.files({\n    actions = {\n      [\"default\"] = function(selected)\n        if not selected or #selected == 0 then return end\n\n        local file = fzf_lua.path.entry_to_file(selected[1])\n\n        if file and file.path and callback then\n          callback(file.path)\n        end\n      end,\n    },\n  })\nend\n\nlocal function mini_pick_ui(callback)\n  local mini_pick = require(\"mini.pick\")\n  mini_pick.builtin.files(nil, ", "suffix_code": ")\nend\n\nlocal function snacks_picker_ui(callback)\n  local Snacks = require(\"snacks\")\n\n  Snacks.picker.files({\n    confirm = function(picker)\n      local items = picker:selected({ fallback = true })\n      picker:close()\n\n      if items and items[1] and callback then\n        callback(items[1].file)\n      end\n    end,\n  })\nend\n\nfunction M.pick(callback)\n  local picker = get_best_picker()\n\n  if not picker then\n    return\n  end\n\n  local wrapped_callback = function(selected_file)\n    local file_name = format_file(selected_file)\n    callback(file_name)\n  end\n\n  vim.schedule(function()\n    if picker == \"telescope\" then\n      telescope_ui(wrapped_callback)\n    elseif picker == \"fzf\" then\n      fzf_ui(wrapped_callback)\n    elseif picker == \"mini.pick\" then\n      mini_pick_ui(wrapped_callback)\n    elseif picker == \"snacks\" then\n      snacks_picker_ui(wrapped_callback)\n    else\n      callback(nil)\n    end\n  end)\nend\n\nreturn M\n", "middle_code": "{\n    source = {\n      choose = function(selected)\n        if selected and callback then\n          callback(selected)\n        end\n        return false\n      end,\n    },\n  }", "code_description": null, "fill_type": "CLASS_TYPE", "language_type": "lua", "sub_task_type": null}, "context_code": [["/goose.nvim/lua/goose/core.lua", "local M = {}\nlocal state = require(\"goose.state\")\nlocal context = require(\"goose.context\")\nlocal session = require(\"goose.session\")\nlocal ui = require(\"goose.ui.ui\")\nlocal job = require('goose.job')\n\nfunction M.select_session()\n  local all_sessions = session.get_all_workspace_sessions()\n  local filtered_sessions = vim.tbl_filter(function(s)\n    return s.description ~= '' and s ~= nil\n  end, all_sessions)\n\n  ui.select_session(filtered_sessions, function(selected_session)\n    if not selected_session then return end\n    state.active_session = selected_session\n    if state.windows then\n      ui.render_output()\n      ui.scroll_to_bottom()\n    else\n      M.open()\n    end\n  end)\nend\n\nfunction M.open(opts)\n  opts = opts or { focus = \"input\", new_session = false }\n\n  if not M.goose_ok() then return end\n\n  local are_windows_closed = state.windows == nil\n\n  if are_windows_closed then\n    state.windows = ui.create_windows()\n  end\n\n  if opts.new_session then\n    state.active_session = nil\n    state.last_sent_context = nil\n    ui.clear_output()\n  else\n    if not state.active_session then\n      state.active_session = session.get_last_workspace_session()\n    end\n\n    if are_windows_closed or ui.is_output_empty() then\n      ui.render_output()\n      ui.scroll_to_bottom()\n    end\n  end\n\n  if opts.focus == \"input\" then\n    ui.focus_input({ restore_position = are_windows_closed })\n  elseif opts.focus == \"output\" then\n    ui.focus_output({ restore_position = are_windows_closed })\n  end\nend\n\nfunction M.run(prompt, opts)\n  if not M.goose_ok() then return false end\n  M.before_run(opts)\n\n  -- Add small delay to ensure stop is complete\n  vim.defer_fn(function()\n    job.execute(prompt,\n      {\n        on_start = function()\n          M.after_run(prompt)\n        end,\n        on_output = function(output)\n          -- Reload all modified file buffers\n          vim.cmd('checktime')\n\n          -- for new sessions, session data can only be retrieved after running the command, retrieve once\n          if not state.active_session and state.new_session_name then\n            state.active_session = session.get_by_name(state.new_session_name)\n          end\n        end,\n        on_error = function(err)\n          vim.notify(\n            err,\n            vim.log.levels.ERROR\n          )\n\n          ui.close_windows(state.windows)\n        end,\n        on_exit = function()\n          state.goose_run_job = nil\n          require('goose.review').check_cleanup_breakpoint()\n        end\n      }\n    )\n  end, 10)\nend\n\nfunction M.after_run(prompt)\n  require('goose.review').set_breakpoint()\n  context.unload_attachments()\n  state.last_sent_context = vim.deepcopy(context.context)\n  require('goose.history').write(prompt)\n\n  if state.windows then\n    ui.render_output()\n  end\nend\n\nfunction M.before_run(opts)\n  M.stop()\n\n  opts = opts or {}\n\n  M.open({\n    new_session = opts.new_session or not state.active_session,\n  })\n\n  -- sync session workspace to current workspace if there is missmatch\n  if state.active_session then\n    local session_workspace = state.active_session.workspace\n    local current_workspace = vim.fn.getcwd()\n\n    if session_workspace ~= current_workspace then\n      session.update_session_workspace(state.active_session.name, current_workspace)\n      state.active_session.workspace = current_workspace\n    end\n  end\nend\n\nfunction M.add_file_to_context()\n  local picker = require('goose.ui.file_picker')\n  require('goose.ui.mention').mention(function(mention_cb)\n    picker.pick(function(file)\n      mention_cb(file.name)\n      context.add_file(file.path)\n    end)\n  end)\nend\n\nfunction M.configure_provider()\n  local info_mod = require(\"goose.info\")\n  require(\"goose.provider\").select(function(selection)\n    if not selection then return end\n\n    info_mod.set_config_value(info_mod.GOOSE_INFO.PROVIDER, selection.provider)\n    info_mod.set_config_value(info_mod.GOOSE_INFO.MODEL, selection.model)\n\n    if state.windows then\n      require('goose.ui.topbar').render()\n    else\n      vim.notify(\"Changed provider to \" .. selection.display, vim.log.levels.INFO)\n    end\n  end)\nend\n\nfunction M.stop()\n  if (state.goose_run_job) then job.stop(state.goose_run_job) end\n  state.goose_run_job = nil\n  if state.windows then\n    ui.stop_render_output()\n    ui.render_output()\n    ui.write_to_input({})\n    require('goose.history').index = nil\n  end\nend\n\nfunction M.goose_ok()\n  if vim.fn.executable('goose') == 0 then\n    vim.notify(\n      \"goose command not found - please install and configure goose before using this plugin\",\n      vim.log.levels.ERROR\n    )\n    return false\n  end\n  return true\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/review.lua", "local Path = require('plenary.path')\nlocal M = {}\n\nM.__changed_files = nil\nM.__current_file_index = nil\nM.__diff_tab = nil\n\nlocal git = {\n  is_project = function()\n    if M.__is_git_project ~= nil then\n      return M.__is_git_project\n    end\n\n    local git_dir = Path:new(vim.fn.getcwd()):joinpath('.git')\n    M.__is_git_project = git_dir:exists() and git_dir:is_dir()\n    return M.__is_git_project\n  end,\n\n  list_changed_files = function()\n    local result = vim.fn.system('git ls-files -m -o --exclude-standard')\n    return result\n  end,\n\n  is_tracked = function(file_path)\n    local success = os.execute('git ls-files --error-unmatch \"' .. file_path .. '\" > /dev/null 2>&1')\n    return success == 0\n  end,\n\n  get_head_content = function(file_path, output_path)\n    local success = os.execute('git show HEAD:\"' .. file_path .. '\" > \"' .. output_path .. '\" 2>/dev/null')\n    return success == 0\n  end\n}\n\nlocal function require_git_project(fn, silent)\n  return function(...)\n    if not git.is_project() then\n      if not silent then\n        vim.notify(\"Error: Not in a git project.\")\n      end\n      return\n    end\n    return fn(...)\n  end\nend\n\n-- File helpers\nlocal function get_snapshot_dir()\n  local cwd = vim.fn.getcwd()\n  local cwd_hash = vim.fn.sha256(cwd)\n  return Path:new(vim.fn.stdpath('data')):joinpath('goose', 'snapshot', cwd_hash)\nend\n\nlocal function revert_file(file_path, snapshot_path)\n  if snapshot_path then\n    Path:new(snapshot_path):copy({ destination = file_path, override = true })\n  elseif git.is_tracked(file_path) then\n    local temp_file = Path:new(vim.fn.tempname())\n    if git.get_head_content(file_path, tostring(temp_file)) then\n      temp_file:copy({ destination = file_path, override = true })\n      temp_file:rm()\n    end\n  else\n    local absolute_path = vim.fn.fnamemodify(file_path, \":p\")\n    local bufnr = vim.fn.bufnr(absolute_path)\n    if bufnr ~= -1 then\n      vim.api.nvim_command('silent! bdelete! ' .. bufnr)\n    end\n    Path:new(file_path):rm()\n  end\n\n  vim.cmd('checktime')\n  return true\nend\n\nlocal function close_diff_tab()\n  if M.__diff_tab and vim.api.nvim_tabpage_is_valid(M.__diff_tab) then\n    pcall(vim.api.nvim_del_augroup_by_name, \"GooseDiffCleanup\" .. M.__diff_tab)\n\n    local windows = vim.api.nvim_tabpage_list_wins(M.__diff_tab)\n\n    local buffers = {}\n    for _, win in ipairs(windows) do\n      local buf = vim.api.nvim_win_get_buf(win)\n      table.insert(buffers, buf)\n    end\n\n    vim.api.nvim_set_current_tabpage(M.__diff_tab)\n    pcall(vim.cmd, 'tabclose')\n\n    for _, buf in ipairs(buffers) do\n      if vim.api.nvim_buf_is_valid(buf) then\n        local visible = false\n        for _, win in ipairs(vim.api.nvim_list_wins()) do\n          if vim.api.nvim_win_get_buf(win) == buf then\n            visible = true\n            break\n          end\n        end\n\n        if not visible then\n          pcall(vim.api.nvim_buf_delete, buf, { force = true })\n        end\n      end\n    end\n  end\n  M.__diff_tab = nil\nend\n\nlocal function files_are_different(file1, file2)\n  local result = vim.fn.system('cmp -s \"' .. file1 .. '\" \"' .. file2 .. '\"; echo $?')\n  return tonumber(result) ~= 0\nend\n\nlocal function get_changed_files()\n  local files = {}\n  local snapshot_base = get_snapshot_dir()\n\n  if not snapshot_base:exists() then return files end\n\n  local git_files = git.list_changed_files()\n  for file in git_files:gmatch(\"[^\\n]+\") do\n    local snapshot_file = snapshot_base:joinpath(file)\n\n    if snapshot_file:exists() then\n      if files_are_different(file, tostring(snapshot_file)) then\n        table.insert(files, { file, tostring(snapshot_file) })\n      end\n    else\n      table.insert(files, { file, nil })\n    end\n  end\n\n  M.__changed_files = files\n  return files\nend\n\nlocal function show_file_diff(file_path, snapshot_path)\n  close_diff_tab()\n\n  vim.cmd('tabnew')\n  M.__diff_tab = vim.api.nvim_get_current_tabpage()\n\n  if snapshot_path then\n    -- Compare with snapshot file\n    vim.cmd('edit ' .. snapshot_path)\n    vim.cmd('setlocal readonly buftype=nofile nomodifiable')\n    vim.cmd('diffthis')\n\n    vim.cmd('vsplit ' .. file_path)\n    vim.cmd('diffthis')\n  else\n    -- If file is tracked by git, compare with HEAD, otherwise just open it\n    if git.is_tracked(file_path) then\n      -- Create a temporary file from the HEAD version\n      local temp_file = vim.fn.tempname()\n      if git.get_head_content(file_path, temp_file) then\n        -- First edit the current file\n        vim.cmd('edit ' .. file_path)\n        local file_type = vim.bo.filetype\n\n        -- Then split with HEAD version on the left\n        vim.cmd('leftabove vsplit ' .. temp_file)\n        vim.cmd('setlocal readonly buftype=nofile nomodifiable filetype=' .. file_type)\n        vim.cmd('diffthis')\n\n        -- Go back to current file window and enable diff there\n        vim.cmd('wincmd l')\n        vim.cmd('diffthis')\n      else\n        -- File is not tracked by git, just open it\n        vim.cmd('edit ' .. file_path)\n      end\n    else\n      -- File is not tracked by git, just open it\n      vim.cmd('edit ' .. file_path)\n    end\n  end\n\n  -- auto close tab if any diff window is closed\n  local augroup = vim.api.nvim_create_augroup(\"GooseDiffCleanup\" .. M.__diff_tab, { clear = true })\n  local tab_windows = vim.api.nvim_tabpage_list_wins(M.__diff_tab)\n  vim.api.nvim_create_autocmd(\"WinClosed\", {\n    group = augroup,\n    pattern = tostring(tab_windows[1]) .. ',' .. tostring(tab_windows[2]),\n    callback = function() close_diff_tab() end\n  })\nend\n\nlocal function display_file_at_index(idx)\n  local file_data = M.__changed_files[idx]\n  local file_name = vim.fn.fnamemodify(file_data[1], \":t\")\n  vim.notify(string.format(\"Showing file %d of %d: %s\", idx, #M.__changed_files, file_name))\n  show_file_diff(file_data[1], file_data[2])\nend\n\n-- Public functions\n\nM.review = require_git_project(function()\n  local files = get_changed_files()\n\n  if #files == 0 then\n    vim.notify(\"No changes to review.\")\n    return\n  end\n\n  if #files == 1 then\n    M.__current_file_index = 1\n    show_file_diff(files[1][1], files[1][2])\n  else\n    vim.ui.select(vim.tbl_map(function(f) return f[1] end, files),\n      { prompt = \"Select a file to review:\" },\n      function(choice, idx)\n        if not choice then return end\n        M.__current_file_index = idx\n        show_file_diff(files[idx][1], files[idx][2])\n      end)\n  end\nend)\n\nM.next_diff = require_git_project(function()\n  if not M.__changed_files or not M.__current_file_index or M.__current_file_index >= #M.__changed_files then\n    local files = get_changed_files()\n    if #files == 0 then\n      vim.notify(\"No changes to review.\")\n      return\n    end\n    M.__current_file_index = 1\n  else\n    M.__current_file_index = M.__current_file_index + 1\n  end\n\n  display_file_at_index(M.__current_file_index)\nend)\n\nM.prev_diff = require_git_project(function()\n  if not M.__changed_files or #M.__changed_files == 0 then\n    local files = get_changed_files()\n    if #files == 0 then\n      vim.notify(\"No changes to review.\")\n      return\n    end\n    M.__current_file_index = #files\n  else\n    if not M.__current_file_index or M.__current_file_index <= 1 then\n      M.__current_file_index = #M.__changed_files\n    else\n      M.__current_file_index = M.__current_file_index - 1\n    end\n  end\n\n  display_file_at_index(M.__current_file_index)\nend)\n\nM.close_diff = function()\n  close_diff_tab()\nend\n\nM.check_cleanup_breakpoint = function()\n  local changed_files = get_changed_files()\n  if #changed_files == 0 then\n    local snapshot_base = get_snapshot_dir()\n    if snapshot_base:exists() then\n      snapshot_base:rm({ recursive = true })\n    end\n  end\nend\n\nM.set_breakpoint = require_git_project(function()\n  local snapshot_base = get_snapshot_dir()\n\n  if snapshot_base:exists() then\n    snapshot_base:rm({ recursive = true })\n  end\n\n  snapshot_base:mkdir({ parents = true })\n\n  for file in git.list_changed_files():gmatch(\"[^\\n]+\") do\n    local source_file = Path:new(file)\n    local target_file = snapshot_base:joinpath(file)\n    target_file:parent():mkdir({ parents = true })\n    source_file:copy({ destination = target_file })\n  end\nend, true)\n\nM.revert_all = require_git_project(function()\n  local files = get_changed_files()\n\n  if #files == 0 then\n    vim.notify(\"No changes to revert.\")\n    return\n  end\n\n  if vim.fn.input(\"Revert all \" .. #files .. \" changed files? (y/n): \"):lower() ~= \"y\" then\n    return\n  end\n\n  local success_count = 0\n  for _, file_data in ipairs(files) do\n    if revert_file(file_data[1], file_data[2]) then\n      success_count = success_count + 1\n    end\n  end\n\n  vim.notify(\"Reverted \" .. success_count .. \" of \" .. #files .. \" files.\")\nend)\n\nM.revert_current = require_git_project(function()\n  local files = get_changed_files()\n  local current_file = vim.fn.expand('%:p')\n  local rel_path = vim.fn.fnamemodify(current_file, ':.')\n\n  local changed_file = nil\n  for _, file_data in ipairs(files) do\n    if file_data[1] == rel_path then\n      changed_file = file_data\n      break\n    end\n  end\n\n  if not changed_file then\n    vim.notify(\"No changes to revert.\")\n    return\n  end\n\n  if vim.fn.input(\"Revert current file? (y/n): \"):lower() ~= \"y\" then\n    return\n  end\n\n  if revert_file(changed_file[1], changed_file[2]) then\n    vim.cmd('e!')\n  end\nend)\n\nM.reset_git_status = function()\n  M.__is_git_project = nil\nend\n\nreturn M"], ["/goose.nvim/lua/goose/context.lua", "-- Gathers editor context\n\nlocal template = require(\"goose.template\")\nlocal util = require(\"goose.util\")\nlocal config = require(\"goose.config\");\n\nlocal M = {}\n\nM.context = {\n  -- current file\n  current_file = nil,\n  cursor_data = nil,\n\n  -- attachments\n  mentioned_files = nil,\n  selections = nil,\n  linter_errors = nil\n}\n\nfunction M.unload_attachments()\n  M.context.mentioned_files = nil\n  M.context.selections = nil\n  M.context.linter_errors = nil\nend\n\nfunction M.load()\n  if util.is_current_buf_a_file() then\n    local current_file = M.get_current_file()\n    local cursor_data = M.get_current_cursor_data()\n\n    M.context.current_file = current_file\n    M.context.cursor_data = cursor_data\n    M.context.linter_errors = M.check_linter_errors()\n  end\n\n  local current_selection = M.get_current_selection()\n  if current_selection then\n    local selection = M.new_selection(\n      M.context.current_file,\n      current_selection.text,\n      current_selection.lines\n    )\n    M.add_selection(selection)\n  end\nend\n\nfunction M.check_linter_errors()\n  local diagnostics = vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR })\n  if #diagnostics == 0 then\n    return nil\n  end\n\n  local message = \"Found \" .. #diagnostics .. \" error\" .. (#diagnostics > 1 and \"s\" or \"\") .. \":\"\n\n  for i, diagnostic in ipairs(diagnostics) do\n    local line_number = diagnostic.lnum + 1 -- Convert to 1-based line numbers\n    local short_message = diagnostic.message:gsub(\"%s+\", \" \"):gsub(\"^%s\", \"\"):gsub(\"%s$\", \"\")\n    message = message .. \"\\n Line \" .. line_number .. \": \" .. short_message\n  end\n\n  return message\nend\n\nfunction M.new_selection(file, content, lines)\n  return {\n    file = file,\n    content = util.indent_code_block(content),\n    lines = lines\n  }\nend\n\nfunction M.add_selection(selection)\n  if not M.context.selections then\n    M.context.selections = {}\n  end\n\n  table.insert(M.context.selections, selection)\nend\n\nfunction M.add_file(file)\n  if not M.context.mentioned_files then\n    M.context.mentioned_files = {}\n  end\n\n  if vim.fn.filereadable(file) ~= 1 then\n    vim.notify(\"File not added to context. Could not read.\")\n    return\n  end\n\n  if not vim.tbl_contains(M.context.mentioned_files, file) then\n    table.insert(M.context.mentioned_files, file)\n  end\nend\n\nfunction M.delta_context()\n  local context = vim.deepcopy(M.context)\n  local last_context = require('goose.state').last_sent_context\n  if not last_context then return context end\n\n  -- no need to send file context again\n  if context.current_file and context.current_file.name == last_context and last_context.current_file.name then\n    context.current_file = nil\n  end\n\n  return context\nend\n\nfunction M.get_current_file()\n  local file = vim.fn.expand('%:p')\n  if not file or file == \"\" or vim.fn.filereadable(file) ~= 1 then\n    return nil\n  end\n  return {\n    path = file,\n    name = vim.fn.fnamemodify(file, \":t\"),\n    extension = vim.fn.fnamemodify(file, \":e\")\n  }\nend\n\nfunction M.get_current_cursor_data()\n  if not (config.get(\"context\") and config.get(\"context\").cursor_data) then\n    return nil\n  end\n\n  local cursor_pos = vim.fn.getcurpos()\n  local cursor_content = vim.trim(vim.api.nvim_get_current_line())\n  return { line = cursor_pos[2], col = cursor_pos[3], line_content = cursor_content }\nend\n\nfunction M.get_current_selection()\n  -- Return nil if not in a visual mode\n  if not vim.fn.mode():match(\"[vV\\022]\") then\n    return nil\n  end\n\n  -- Save current position and register state\n  local current_pos = vim.fn.getpos(\".\")\n  local old_reg = vim.fn.getreg('x')\n  local old_regtype = vim.fn.getregtype('x')\n\n  -- Capture selection text and position\n  vim.cmd('normal! \"xy')\n  local text = vim.fn.getreg('x')\n\n  -- Get line numbers\n  vim.cmd(\"normal! `<\")\n  local start_line = vim.fn.line(\".\")\n  vim.cmd(\"normal! `>\")\n  local end_line = vim.fn.line(\".\")\n\n  -- Restore state\n  vim.fn.setreg('x', old_reg, old_regtype)\n  vim.cmd('normal! gv')\n  vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Esc>', true, false, true), 'nx', true)\n  vim.fn.setpos('.', current_pos)\n\n  return {\n    text = text and text:match(\"[^%s]\") and text or nil,\n    lines = start_line .. \", \" .. end_line\n  }\nend\n\nfunction M.format_message(prompt)\n  local info = require('goose.info')\n  local context = nil\n\n  if info.parse_goose_info().goose_mode == info.GOOSE_MODE.CHAT then\n    -- For chat mode only send selection context\n    context = {\n      selections = M.context.selections\n    }\n  else\n    context = M.delta_context()\n  end\n\n  context.prompt = prompt\n  return template.render_template(context)\nend\n\nfunction M.extract_from_message(text)\n  local context = {\n    prompt = template.extract_tag('user-query', text) or text,\n    selected_text = template.extract_tag('manually-added-selection', text)\n  }\n  return context\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/ui/output_renderer.lua", "local M = {}\n\nlocal state = require(\"goose.state\")\nlocal formatter = require(\"goose.ui.session_formatter\")\n\nlocal LABELS = {\n  GENERATING_RESPONSE = \"Thinking...\"\n}\n\nM._cache = {\n  last_modified = 0,\n  output_lines = nil,\n  session_path = nil,\n  check_counter = 0\n}\n\nM._animation = {\n  frames = { \"·\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\" },\n  current_frame = 1,\n  timer = nil,\n  loading_line = nil,\n  fps = 10,\n}\n\nfunction M.render_markdown()\n  if vim.fn.exists(\":RenderMarkdown\") > 0 then\n    vim.cmd(':RenderMarkdown')\n  end\nend\n\nfunction M._should_refresh_content()\n  if not state.active_session then return true end\n\n  local session_path = state.active_session.path\n\n  if session_path ~= M._cache.session_path then\n    M._cache.session_path = session_path\n    return true\n  end\n\n  if vim.fn.filereadable(session_path) == 0 then return false end\n\n  local stat = vim.loop.fs_stat(session_path)\n  if not stat then return false end\n\n  if state.goose_run_job then\n    M._cache.check_counter = (M._cache.check_counter + 1) % 3\n    if M._cache.check_counter == 0 then\n      local has_file_changed = stat.mtime.sec > M._cache.last_modified\n      if has_file_changed then\n        M._cache.last_modified = stat.mtime.sec\n        return true\n      end\n    end\n  end\n\n  if stat.mtime.sec > M._cache.last_modified then\n    M._cache.last_modified = stat.mtime.sec\n    return true\n  end\n\n  return false\nend\n\nfunction M._read_session(force_refresh)\n  if not state.active_session then return nil end\n\n  if not force_refresh and not M._should_refresh_content() and M._cache.output_lines then\n    return M._cache.output_lines\n  end\n\n  local session_path = state.active_session.path\n  local output_lines = formatter.format_session(session_path)\n  M._cache.output_lines = output_lines\n  return output_lines\nend\n\nfunction M._update_loading_animation(windows)\n  if not M._animation.loading_line then return false end\n\n  local buffer_line_count = vim.api.nvim_buf_line_count(windows.output_buf)\n  if M._animation.loading_line <= 0 or M._animation.loading_line >= buffer_line_count then\n    return false\n  end\n\n  local zero_index = M._animation.loading_line - 1\n  local loading_text = LABELS.GENERATING_RESPONSE .. \" \" ..\n      M._animation.frames[M._animation.current_frame]\n\n  local ns_id = vim.api.nvim_create_namespace('loading_animation')\n  vim.api.nvim_buf_clear_namespace(windows.output_buf, ns_id, zero_index, zero_index + 1)\n\n  vim.api.nvim_buf_set_extmark(windows.output_buf, ns_id, zero_index, 0, {\n    virt_text = { { loading_text, \"Comment\" } },\n    virt_text_pos = \"overlay\",\n    hl_mode = \"replace\"\n  })\n\n  return true\nend\n\nM._refresh_timer = nil\n\nfunction M._start_content_refresh_timer(windows)\n  if M._refresh_timer then\n    pcall(vim.fn.timer_stop, M._refresh_timer)\n    M._refresh_timer = nil\n  end\n\n  M._refresh_timer = vim.fn.timer_start(300, function()\n    if state.goose_run_job then\n      if M._should_refresh_content() then\n        vim.schedule(function()\n          local current_frame = M._animation.current_frame\n          M.render(windows, true)\n          M._animation.current_frame = current_frame\n        end)\n      end\n\n      if state.goose_run_job then\n        M._start_content_refresh_timer(windows)\n      end\n    else\n      if M._refresh_timer then\n        pcall(vim.fn.timer_stop, M._refresh_timer)\n        M._refresh_timer = nil\n      end\n      vim.schedule(function() M.render(windows, true) end)\n    end\n  end)\nend\n\nfunction M._animate_loading(windows)\n  local function start_animation_timer()\n    if M._animation.timer then\n      pcall(vim.fn.timer_stop, M._animation.timer)\n      M._animation.timer = nil\n    end\n\n    M._animation.timer = vim.fn.timer_start(math.floor(1000 / M._animation.fps), function()\n      M._animation.current_frame = (M._animation.current_frame % #M._animation.frames) + 1\n\n      vim.schedule(function()\n        M._update_loading_animation(windows)\n      end)\n\n      if state.goose_run_job then\n        start_animation_timer()\n      else\n        M._animation.timer = nil\n      end\n    end)\n  end\n\n  M._start_content_refresh_timer(windows)\n\n  start_animation_timer()\nend\n\nfunction M.render(windows, force_refresh)\n  local function render()\n    if not state.active_session and not state.new_session_name then\n      return\n    end\n\n    if not force_refresh and state.goose_run_job and M._animation.loading_line then\n      return\n    end\n\n    local output_lines = M._read_session(force_refresh)\n    local is_new_session = state.new_session_name ~= nil\n\n    if not output_lines then\n      if is_new_session then\n        output_lines = { \"\" }\n      else\n        return\n      end\n    else\n      state.new_session_name = nil\n    end\n\n    M.handle_loading(windows, output_lines)\n\n    M.write_output(windows, output_lines)\n\n    M.handle_auto_scroll(windows)\n  end\n  render()\n  require('goose.ui.mention').highlight_all_mentions(windows.output_buf)\n  require('goose.ui.topbar').render()\n  M.render_markdown()\nend\n\nfunction M.stop()\n  if M._animation and M._animation.timer then\n    pcall(vim.fn.timer_stop, M._animation.timer)\n    M._animation.timer = nil\n  end\n\n  if M._refresh_timer then\n    pcall(vim.fn.timer_stop, M._refresh_timer)\n    M._refresh_timer = nil\n  end\n\n  M._animation.loading_line = nil\n  M._cache = {\n    last_modified = 0,\n    output_lines = nil,\n    session_path = nil,\n    check_counter = 0\n  }\nend\n\nfunction M.handle_loading(windows, output_lines)\n  if state.goose_run_job then\n    if #output_lines > 2 then\n      for _, line in ipairs(formatter.separator) do\n        table.insert(output_lines, line)\n      end\n    end\n\n    -- Replace this line with our extmark animation\n    local empty_loading_line = \" \" -- Just needs to be a non-empty string for the extmark to attach to\n    table.insert(output_lines, empty_loading_line)\n    table.insert(output_lines, \"\")\n\n    M._animation.loading_line = #output_lines - 1\n\n    -- Always ensure animation is running when there's an active job\n    -- This is the key fix - we always start animation for an active job\n    M._animate_loading(windows)\n\n    vim.schedule(function()\n      M._update_loading_animation(windows)\n    end)\n  else\n    M._animation.loading_line = nil\n\n    local ns_id = vim.api.nvim_create_namespace('loading_animation')\n    vim.api.nvim_buf_clear_namespace(windows.output_buf, ns_id, 0, -1)\n\n    if M._animation.timer then\n      pcall(vim.fn.timer_stop, M._animation.timer)\n      M._animation.timer = nil\n    end\n\n    if M._refresh_timer then\n      pcall(vim.fn.timer_stop, M._refresh_timer)\n      M._refresh_timer = nil\n    end\n  end\nend\n\nfunction M.write_output(windows, output_lines)\n  vim.api.nvim_buf_set_option(windows.output_buf, 'modifiable', true)\n  vim.api.nvim_buf_set_lines(windows.output_buf, 0, -1, false, output_lines)\n  vim.api.nvim_buf_set_option(windows.output_buf, 'modifiable', false)\nend\n\nfunction M.handle_auto_scroll(windows)\n  local line_count = vim.api.nvim_buf_line_count(windows.output_buf)\n  local botline = vim.fn.line('w$', windows.output_win)\n\n  local prev_line_count = vim.b[windows.output_buf].prev_line_count or 0\n  vim.b[windows.output_buf].prev_line_count = line_count\n\n  local was_at_bottom = (botline >= prev_line_count) or prev_line_count == 0\n\n  if was_at_bottom then\n    require(\"goose.ui.ui\").scroll_to_bottom()\n  end\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/ui/window_config.lua", "local M = {}\n\nlocal INPUT_PLACEHOLDER = 'Plan, search, build anything'\nlocal config = require(\"goose.config\").get()\nlocal state = require(\"goose.state\")\nlocal ui_util = require('goose.ui.util')\n\nM.base_window_opts = {\n  relative = 'editor',\n  style = 'minimal',\n  border = 'rounded',\n  zindex = 50,\n  width = 1,\n  height = 1,\n  col = 0,\n  row = 0\n}\n\nfunction M.setup_options(windows)\n  -- Input window/buffer options\n  vim.api.nvim_win_set_option(windows.input_win, 'winhighlight', 'Normal:GooseBackground,FloatBorder:GooseBorder')\n  vim.api.nvim_win_set_option(windows.input_win, 'signcolumn', 'yes')\n  vim.api.nvim_win_set_option(windows.input_win, 'cursorline', false)\n  vim.api.nvim_buf_set_option(windows.input_buf, 'buftype', 'nofile')\n  vim.api.nvim_buf_set_option(windows.input_buf, 'swapfile', false)\n  vim.b[windows.input_buf].completion = false\n\n  -- Output window/buffer options\n  vim.api.nvim_win_set_option(windows.output_win, 'winhighlight', 'Normal:GooseBackground,FloatBorder:GooseBorder')\n  vim.api.nvim_buf_set_option(windows.output_buf, 'filetype', 'markdown')\n  vim.api.nvim_buf_set_option(windows.output_buf, 'modifiable', false)\n  vim.api.nvim_buf_set_option(windows.output_buf, 'buftype', 'nofile')\n  vim.api.nvim_buf_set_option(windows.output_buf, 'swapfile', false)\nend\n\nfunction M.refresh_placeholder(windows, input_lines)\n  -- show placeholder if input buffer is empty - otherwise clear it\n  if not input_lines then\n    input_lines = vim.api.nvim_buf_get_lines(windows.input_buf, 0, -1, false)\n  end\n\n  if #input_lines == 1 and input_lines[1] == \"\" then\n    local ns_id = vim.api.nvim_create_namespace('input-placeholder')\n    vim.api.nvim_buf_set_extmark(windows.input_buf, ns_id, 0, 0, {\n      virt_text = { { INPUT_PLACEHOLDER, 'Comment' } },\n      virt_text_pos = 'overlay',\n    })\n  else\n    vim.api.nvim_buf_clear_namespace(windows.input_buf, vim.api.nvim_create_namespace('input-placeholder'), 0, -1)\n  end\nend\n\nfunction M.setup_autocmds(windows)\n  local group = vim.api.nvim_create_augroup('GooseWindows', { clear = true })\n\n  -- Output window autocmds\n  vim.api.nvim_create_autocmd({ 'WinEnter', 'BufEnter' }, {\n    group = group,\n    buffer = windows.output_buf,\n    callback = function()\n      vim.cmd('stopinsert')\n      state.last_focused_goose_window = \"output\"\n      M.refresh_placeholder(windows)\n    end\n  })\n\n  -- Input window autocmds\n  vim.api.nvim_create_autocmd('WinEnter', {\n    group = group,\n    buffer = windows.input_buf,\n    callback = function()\n      M.refresh_placeholder(windows)\n      state.last_focused_goose_window = \"input\"\n    end\n  })\n\n  vim.api.nvim_create_autocmd({ 'TextChanged', 'TextChangedI' }, {\n    buffer = windows.input_buf,\n    callback = function()\n      local input_lines = vim.api.nvim_buf_get_lines(windows.input_buf, 0, -1, false)\n      state.input_content = input_lines\n      M.refresh_placeholder(windows, input_lines)\n    end\n  })\n\n  vim.api.nvim_create_autocmd('WinClosed', {\n    group = group,\n    pattern = tostring(windows.input_win) .. ',' .. tostring(windows.output_win),\n    callback = function(opts)\n      -- Get the window that was closed\n      local closed_win = tonumber(opts.match)\n      -- If either window is closed, close both\n      if closed_win == windows.input_win or closed_win == windows.output_win then\n        vim.schedule(function()\n          require('goose.ui.ui').close_windows(windows)\n        end)\n      end\n    end\n  })\n\n  vim.api.nvim_create_autocmd('WinLeave', {\n    group = group,\n    pattern = \"*\",\n    callback = function()\n      if not require('goose.ui.ui').is_goose_focused() then\n        require('goose.context').load()\n        state.last_code_win_before_goose = vim.api.nvim_get_current_win()\n      end\n    end\n  })\n\n  vim.api.nvim_create_autocmd('WinLeave', {\n    group = group,\n    buffer = windows.input_buf,\n    callback = function()\n      state.last_input_window_position = vim.api.nvim_win_get_cursor(0)\n    end\n  })\n\n  vim.api.nvim_create_autocmd('WinLeave', {\n    group = group,\n    buffer = windows.output_buf,\n    callback = function()\n      state.last_output_window_position = vim.api.nvim_win_get_cursor(0)\n    end\n  })\nend\n\nfunction M.configure_window_dimensions(windows)\n  local total_width = vim.api.nvim_get_option('columns')\n  local total_height = vim.api.nvim_get_option('lines')\n  local is_fullscreen = config.ui.fullscreen\n\n  local width\n  if is_fullscreen then\n    width = total_width\n  else\n    width = math.floor(total_width * config.ui.window_width)\n  end\n\n  local layout = config.ui.layout\n  local total_usable_height\n  local row, col\n\n  if layout == \"center\" then\n    -- Use a smaller height for floating; allow an optional `floating_height` factor (e.g. 0.8).\n    local fh = config.ui.floating_height\n    total_usable_height = math.floor(total_height * fh)\n    -- Center the floating window vertically and horizontally.\n    row = math.floor((total_height - total_usable_height) / 2)\n    col = is_fullscreen and 0 or math.floor((total_width - width) / 2)\n  else\n    -- \"right\" layout uses the original full usable height.\n    total_usable_height = total_height - 3\n    row = 0\n    col = is_fullscreen and 0 or (total_width - width)\n  end\n\n  local input_height = math.floor(total_usable_height * config.ui.input_height)\n  local output_height = total_usable_height - input_height - 2\n\n  vim.api.nvim_win_set_config(windows.output_win, {\n    relative = 'editor',\n    width = width,\n    height = output_height,\n    col = col,\n    row = row,\n  })\n\n  vim.api.nvim_win_set_config(windows.input_win, {\n    relative = 'editor',\n    width = width,\n    height = input_height,\n    col = col,\n    row = row + output_height + 2,\n  })\nend\n\nfunction M.setup_resize_handler(windows)\n  local function cb()\n    M.configure_window_dimensions(windows)\n    require('goose.ui.topbar').render()\n  end\n\n  vim.api.nvim_create_autocmd('VimResized', {\n    group = vim.api.nvim_create_augroup('GooseResize', { clear = true }),\n    callback = cb\n  })\nend\n\nlocal function recover_input(windows)\n  local input_content = state.input_content\n  require('goose.ui.ui').write_to_input(input_content, windows)\n  require('goose.ui.mention').highlight_all_mentions(windows.input_buf)\nend\n\nfunction M.setup_after_actions(windows)\n  recover_input(windows)\nend\n\nlocal function handle_submit(windows)\n  local input_content = table.concat(vim.api.nvim_buf_get_lines(windows.input_buf, 0, -1, false), '\\n')\n  vim.api.nvim_buf_set_lines(windows.input_buf, 0, -1, false, {})\n  vim.api.nvim_exec_autocmds('TextChanged', {\n    buffer = windows.input_buf,\n    modeline = false\n  })\n\n  -- Switch to the output window\n  vim.api.nvim_set_current_win(windows.output_win)\n\n  -- Always scroll to the bottom when submitting a new prompt\n  local line_count = vim.api.nvim_buf_line_count(windows.output_buf)\n  vim.api.nvim_win_set_cursor(windows.output_win, { line_count, 0 })\n\n  -- Run the command with the input content\n  require(\"goose.core\").run(input_content)\nend\n\nfunction M.setup_keymaps(windows)\n  local window_keymap = config.keymap.window\n  local api = require('goose.api')\n\n  vim.keymap.set({  'n' }, window_keymap.submit, function()\n    handle_submit(windows)\n  end, { buffer = windows.input_buf, silent = false })\n\n  vim.keymap.set({  'i' }, window_keymap.submit_insert, function()\n    handle_submit(windows)\n  end, { buffer = windows.input_buf, silent = false })\n\n  vim.keymap.set('n', window_keymap.close, function()\n    api.close()\n  end, { buffer = windows.input_buf, silent = true })\n\n  vim.keymap.set('n', window_keymap.close, function()\n    api.close()\n  end, { buffer = windows.output_buf, silent = true })\n\n  vim.keymap.set('n', window_keymap.next_message, function()\n    require('goose.ui.navigation').goto_next_message()\n  end, { buffer = windows.output_buf, silent = true })\n\n  vim.keymap.set('n', window_keymap.prev_message, function()\n    require('goose.ui.navigation').goto_prev_message()\n  end, { buffer = windows.output_buf, silent = true })\n\n  vim.keymap.set('n', window_keymap.next_message, function()\n    require('goose.ui.navigation').goto_next_message()\n  end, { buffer = windows.input_buf, silent = true })\n\n  vim.keymap.set('n', window_keymap.prev_message, function()\n    require('goose.ui.navigation').goto_prev_message()\n  end, { buffer = windows.input_buf, silent = true })\n\n  vim.keymap.set({ 'n', 'i' }, window_keymap.stop, function()\n    api.stop()\n  end, { buffer = windows.output_buf, silent = true })\n\n  vim.keymap.set({ 'n', 'i' }, window_keymap.stop, function()\n    api.stop()\n  end, { buffer = windows.input_buf, silent = true })\n\n  vim.keymap.set('i', window_keymap.mention_file, function()\n    require('goose.core').add_file_to_context()\n  end, { buffer = windows.input_buf, silent = true })\n\n  vim.keymap.set({ 'n', 'i' }, window_keymap.toggle_pane, function()\n    api.toggle_pane()\n  end, { buffer = windows.input_buf, silent = true })\n\n  vim.keymap.set({ 'n', 'i' }, window_keymap.toggle_pane, function()\n    api.toggle_pane()\n  end, { buffer = windows.output_buf, silent = true })\n\n  vim.keymap.set({ 'n', 'i' }, window_keymap.prev_prompt_history,\n    ui_util.navigate_history('prev', window_keymap.prev_prompt_history, api.prev_history, api.next_history),\n    { buffer = windows.input_buf, silent = true })\n\n  vim.keymap.set({ 'n', 'i' }, window_keymap.next_prompt_history,\n    ui_util.navigate_history('next', window_keymap.next_prompt_history, api.prev_history, api.next_history),\n    { buffer = windows.input_buf, silent = true })\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/util.lua", "local M = {}\n\nfunction M.template(str, vars)\n  return (str:gsub(\"{(.-)}\", function(key)\n    return tostring(vars[key] or \"\")\n  end))\nend\n\nfunction M.uid()\n  return tostring(os.time()) .. \"-\" .. tostring(math.random(1000, 9999))\nend\n\nfunction M.is_current_buf_a_file()\n  local bufnr = vim.api.nvim_get_current_buf()\n  local buftype = vim.api.nvim_buf_get_option(bufnr, \"buftype\")\n  local filepath = vim.fn.expand('%:p')\n\n  -- Valid files have empty buftype\n  -- This excludes special buffers like help, terminal, nofile, etc.\n  return buftype == \"\" and filepath ~= \"\"\nend\n\nfunction M.indent_code_block(text)\n  if not text then return nil end\n  local lines = vim.split(text, \"\\n\", true)\n\n  local first, last = nil, nil\n  for i, line in ipairs(lines) do\n    if line:match(\"[^%s]\") then\n      first = first or i\n      last = i\n    end\n  end\n\n  if not first then return \"\" end\n\n  local content = {}\n  for i = first, last do\n    table.insert(content, lines[i])\n  end\n\n  local min_indent = math.huge\n  for _, line in ipairs(content) do\n    if line:match(\"[^%s]\") then\n      min_indent = math.min(min_indent, line:match(\"^%s*\"):len())\n    end\n  end\n\n  if min_indent < math.huge and min_indent > 0 then\n    for i, line in ipairs(content) do\n      if line:match(\"[^%s]\") then\n        content[i] = line:sub(min_indent + 1)\n      end\n    end\n  end\n\n  return vim.trim(table.concat(content, \"\\n\"))\nend\n\n-- Get timezone offset in seconds for various timezone formats\nfunction M.get_timezone_offset(timezone)\n  -- Handle numeric timezone formats (+HHMM, -HHMM)\n  if timezone:match(\"^[%+%-]%d%d:?%d%d$\") then\n    local sign = timezone:sub(1, 1) == \"+\" and 1 or -1\n    local hours = tonumber(timezone:match(\"^[%+%-](%d%d)\"))\n    local mins = tonumber(timezone:match(\"^[%+%-]%d%d:?(%d%d)$\") or \"00\")\n    return sign * (hours * 3600 + mins * 60)\n  end\n\n  -- Map of common timezone abbreviations to their offset in seconds from UTC\n  local timezone_map = {\n    -- Zero offset timezones\n    [\"UTC\"] = 0,\n    [\"GMT\"] = 0,\n\n    -- North America\n    [\"EST\"] = -5 * 3600,\n    [\"EDT\"] = -4 * 3600,\n    [\"CST\"] = -6 * 3600,\n    [\"CDT\"] = -5 * 3600,\n    [\"MST\"] = -7 * 3600,\n    [\"MDT\"] = -6 * 3600,\n    [\"PST\"] = -8 * 3600,\n    [\"PDT\"] = -7 * 3600,\n    [\"AKST\"] = -9 * 3600,\n    [\"AKDT\"] = -8 * 3600,\n    [\"HST\"] = -10 * 3600,\n\n    -- Europe\n    [\"WET\"] = 0,\n    [\"WEST\"] = 1 * 3600,\n    [\"CET\"] = 1 * 3600,\n    [\"CEST\"] = 2 * 3600,\n    [\"EET\"] = 2 * 3600,\n    [\"EEST\"] = 3 * 3600,\n    [\"MSK\"] = 3 * 3600,\n    [\"BST\"] = 1 * 3600,\n\n    -- Asia & Middle East\n    [\"IST\"] = 5.5 * 3600,\n    [\"PKT\"] = 5 * 3600,\n    [\"HKT\"] = 8 * 3600,\n    [\"PHT\"] = 8 * 3600,\n    [\"JST\"] = 9 * 3600,\n    [\"KST\"] = 9 * 3600,\n\n    -- Australia & Pacific\n    [\"AWST\"] = 8 * 3600,\n    [\"ACST\"] = 9.5 * 3600,\n    [\"AEST\"] = 10 * 3600,\n    [\"AEDT\"] = 11 * 3600,\n    [\"NZST\"] = 12 * 3600,\n    [\"NZDT\"] = 13 * 3600,\n  }\n\n  -- Handle special cases for ambiguous abbreviations\n  if timezone == \"CST\" and not timezone_map[timezone] then\n    -- In most contexts, CST refers to Central Standard Time (US)\n    return -6 * 3600\n  end\n\n  -- Return the timezone offset or default to UTC (0)\n  return timezone_map[timezone] or 0\nend\n\n-- Reset all ANSI styling\nfunction M.ansi_reset()\n  return \"\\27[0m\"\nend\n\n--- Convert a datetime string to a human-readable \"time ago\" format\n-- @param dateTime string: Datetime string (e.g., \"2025-03-02 12:39:02 UTC\")\n-- @return string: Human-readable time ago string (e.g., \"2 hours ago\")\nfunction M.time_ago(dateTime)\n  -- Parse the input datetime string\n  local year, month, day, hour, min, sec, zone = dateTime:match(\n    \"(%d+)%-(%d+)%-(%d+)%s+(%d+):(%d+):(%d+)%s+([%w%+%-/:]+)\")\n\n  -- If parsing fails, try another common format\n  if not year then\n    year, month, day, hour, min, sec = dateTime:match(\"(%d+)%-(%d+)%-(%d+)[T ](%d+):(%d+):(%d+)\")\n    -- No timezone specified, treat as local time\n  end\n\n  -- Return early if we couldn't parse the date\n  if not year then\n    return \"Invalid date format\"\n  end\n\n  -- Convert string values to numbers\n  year, month, day = tonumber(year), tonumber(month), tonumber(day)\n  hour, min, sec = tonumber(hour), tonumber(min), tonumber(sec)\n\n  -- Get current time for comparison\n  local now = os.time()\n\n  -- Create date table for the input time\n  local date_table = {\n    year = year,\n    month = month,\n    day = day,\n    hour = hour,\n    min = min,\n    sec = sec,\n    isdst = false -- Ignore DST for consistency\n  }\n\n  -- Calculate timestamp based on whether timezone is specified\n  local timestamp\n\n  if zone then\n    -- Get the timezone offset from our comprehensive map\n    local input_offset_seconds = M.get_timezone_offset(zone)\n\n    -- Get the local timezone offset\n    local local_offset_seconds = os.difftime(os.time(os.date(\"*t\", now)), os.time(os.date(\"!*t\", now)))\n\n    -- Calculate the hour in the local timezone\n    -- First convert the input time to UTC, then to local time\n    local adjusted_hour = hour - (input_offset_seconds / 3600) + (local_offset_seconds / 3600)\n\n    -- Update the date table with adjusted hours and minutes\n    date_table.hour = math.floor(adjusted_hour)\n    date_table.min = math.floor(min + ((adjusted_hour % 1) * 60))\n\n    -- Get timestamp in local timezone\n    timestamp = os.time(date_table)\n  else\n    -- No timezone specified, assume it's already in local time\n    timestamp = os.time(date_table)\n  end\n\n  -- Calculate time difference in seconds\n  local diff = now - timestamp\n\n  -- Format the relative time based on the difference\n  if diff < 0 then\n    return \"in the future\"\n  elseif diff < 60 then\n    return \"just now\"\n  elseif diff < 3600 then\n    local mins = math.floor(diff / 60)\n    return mins == 1 and \"1 minute ago\" or mins .. \" minutes ago\"\n  elseif diff < 86400 then\n    local hours = math.floor(diff / 3600)\n    return hours == 1 and \"1 hour ago\" or hours .. \" hours ago\"\n  elseif diff < 604800 then\n    local days = math.floor(diff / 86400)\n    return days == 1 and \"1 day ago\" or days .. \" days ago\"\n  elseif diff < 2592000 then\n    local weeks = math.floor(diff / 604800)\n    return weeks == 1 and \"1 week ago\" or weeks .. \" weeks ago\"\n  elseif diff < 31536000 then\n    local months = math.floor(diff / 2592000)\n    return months == 1 and \"1 month ago\" or months .. \" months ago\"\n  else\n    local years = math.floor(diff / 31536000)\n    return years == 1 and \"1 year ago\" or years .. \" years ago\"\n  end\nend\n\n-- Simple YAML key/value setter\n-- Note: This is a basic implementation that assumes simple YAML structure\n-- It will either update an existing key or append a new key at the end\nfunction M.set_yaml_value(path, key, value)\n  if not path then\n    return false, \"No file path provided\"\n  end\n\n  -- Read the current content\n  local lines = {}\n  local key_pattern = \"^%s*\" .. vim.pesc(key) .. \":%s*\"\n  local found = false\n\n  local file = io.open(path, \"r\")\n  if not file then\n    return false, \"Could not open file\"\n  end\n\n  for line in file:lines() do\n    if line:match(key_pattern) then\n      -- Update existing key\n      lines[#lines + 1] = string.format(\"%s: %s\", key, value)\n      found = true\n    else\n      lines[#lines + 1] = line\n    end\n  end\n  file:close()\n\n  -- If key wasn't found, append it\n  if not found then\n    lines[#lines + 1] = string.format(\"%s: %s\", key, value)\n  end\n\n  -- Write back to file\n  file = io.open(path, \"w\")\n  if not file then\n    return false, \"Could not open file for writing\"\n  end\n  file:write(table.concat(lines, \"\\n\"))\n  file:close()\n\n  return true\nend\n\nreturn M"], ["/goose.nvim/lua/goose/template.lua", "-- Template rendering functionality\n\nlocal M = {}\n\nlocal Renderer = {}\n\nfunction Renderer.escape(data)\n  return tostring(data or ''):gsub(\"[\\\">/<'&]\", {\n    [\"&\"] = \"&amp;\",\n    [\"<\"] = \"&lt;\",\n    [\">\"] = \"&gt;\",\n    ['\"'] = \"&quot;\",\n    [\"'\"] = \"&#39;\",\n    [\"/\"] = \"&#47;\"\n  })\nend\n\nfunction Renderer.render(tpl, args)\n  tpl = tpl:gsub(\"\\n\", \"\\\\n\")\n\n  local compiled = load(Renderer.parse(tpl))()\n\n  local buffer = {}\n  local function exec(data)\n    if type(data) == \"function\" then\n      local args = args or {}\n      setmetatable(args, { __index = _G })\n      load(string.dump(data), nil, nil, args)(exec)\n    else\n      table.insert(buffer, tostring(data or ''))\n    end\n  end\n  exec(compiled)\n\n  -- First replace all escaped newlines with actual newlines\n  local result = table.concat(buffer, ''):gsub(\"\\\\n\", \"\\n\")\n  -- Then reduce multiple consecutive newlines to a single newline\n  result = result:gsub(\"\\n\\n+\", \"\\n\")\n  return vim.trim(result)\nend\n\nfunction Renderer.parse(tpl)\n  local str =\n      \"return function(_)\" ..\n      \"function __(...)\" ..\n      \"_(require('template').escape(...))\" ..\n      \"end \" ..\n      \"_[=[\" ..\n      tpl:\n      gsub(\"[][]=[][]\", ']=]_\"%1\"_[=['):\n      gsub(\"<%%=\", \"]=]_(\"):\n      gsub(\"<%%\", \"]=]__(\"):\n      gsub(\"%%>\", \")_[=[\"):\n      gsub(\"<%?\", \"]=] \"):\n      gsub(\"%?>\", \" _[=[\") ..\n      \"]=] \" ..\n      \"end\"\n\n  return str\nend\n\n-- Find the plugin root directory\nlocal function get_plugin_root()\n  local path = debug.getinfo(1, \"S\").source:sub(2)\n  local lua_dir = vim.fn.fnamemodify(path, \":h:h\")\n  return vim.fn.fnamemodify(lua_dir, \":h\") -- Go up one more level\nend\n\n-- Read the Jinja template file\nlocal function read_template(template_path)\n  local file = io.open(template_path, \"r\")\n  if not file then\n    error(\"Failed to read template file: \" .. template_path)\n    return nil\n  end\n\n  local content = file:read(\"*all\")\n  file:close()\n  return content\nend\n\nfunction M.cleanup_indentation(template)\n  local res = vim.split(template, \"\\n\")\n  for i, line in ipairs(res) do\n    res[i] = line:gsub(\"^%s+\", \"\")\n  end\n  return table.concat(res, \"\\n\")\nend\n\nfunction M.render_template(template_vars)\n  local plugin_root = get_plugin_root()\n  local template_path = plugin_root .. \"/template/prompt.tpl\"\n\n  local template = read_template(template_path)\n  if not template then return nil end\n\n  template = M.cleanup_indentation(template)\n\n  return Renderer.render(template, template_vars)\nend\n\nfunction M.extract_tag(tag, text)\n  local start_tag = \"<\" .. tag .. \">\"\n  local end_tag = \"</\" .. tag .. \">\"\n\n  -- Use pattern matching to find the content between the tags\n  -- Make search start_tag and end_tag more robust with pattern escaping\n  local pattern = vim.pesc(start_tag) .. \"(.-)\" .. vim.pesc(end_tag)\n  local content = text:match(pattern)\n\n  if content then\n    return vim.trim(content)\n  end\n\n  -- Fallback to the original method if pattern matching fails\n  local query_start = text:find(start_tag)\n  local query_end = text:find(end_tag)\n\n  if query_start and query_end then\n    -- Extract and trim the content between the tags\n    local query_content = text:sub(query_start + #start_tag, query_end - 1)\n    return vim.trim(query_content)\n  end\n\n  return nil\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/ui/ui.lua", "local M = {}\n\nlocal state = require(\"goose.state\")\nlocal renderer = require('goose.ui.output_renderer')\n\nfunction M.scroll_to_bottom()\n  local line_count = vim.api.nvim_buf_line_count(state.windows.output_buf)\n  vim.api.nvim_win_set_cursor(state.windows.output_win, { line_count, 0 })\n\n  vim.defer_fn(function()\n    renderer.render_markdown()\n  end, 200)\nend\n\nfunction M.close_windows(windows)\n  if not windows then return end\n\n  if M.is_goose_focused() then M.return_to_last_code_win() end\n\n  renderer.stop()\n\n  -- Close windows and delete buffers\n  pcall(vim.api.nvim_win_close, windows.input_win, true)\n  pcall(vim.api.nvim_win_close, windows.output_win, true)\n  pcall(vim.api.nvim_buf_delete, windows.input_buf, { force = true })\n  pcall(vim.api.nvim_buf_delete, windows.output_buf, { force = true })\n\n  -- Clear autocmd groups\n  pcall(vim.api.nvim_del_augroup_by_name, 'GooseResize')\n  pcall(vim.api.nvim_del_augroup_by_name, 'GooseWindows')\n\n  state.windows = nil\nend\n\nfunction M.return_to_last_code_win()\n  local last_win = state.last_code_win_before_goose\n  if last_win and vim.api.nvim_win_is_valid(last_win) then\n    vim.api.nvim_set_current_win(last_win)\n  end\nend\n\nfunction M.create_windows()\n  local configurator = require(\"goose.ui.window_config\")\n  local input_buf = vim.api.nvim_create_buf(false, true)\n  local output_buf = vim.api.nvim_create_buf(false, true)\n\n  require('goose.ui.highlight').setup()\n\n  local input_win = vim.api.nvim_open_win(input_buf, false, configurator.base_window_opts)\n  local output_win = vim.api.nvim_open_win(output_buf, false, configurator.base_window_opts)\n  local windows = {\n    input_buf = input_buf,\n    output_buf = output_buf,\n    input_win = input_win,\n    output_win = output_win\n  }\n\n  configurator.setup_options(windows)\n  configurator.refresh_placeholder(windows)\n  configurator.setup_autocmds(windows)\n  configurator.setup_resize_handler(windows)\n  configurator.setup_keymaps(windows)\n  configurator.setup_after_actions(windows)\n  configurator.configure_window_dimensions(windows)\n  return windows\nend\n\nfunction M.focus_input(opts)\n  opts = opts or {}\n  local windows = state.windows\n  vim.api.nvim_set_current_win(windows.input_win)\n\n  if opts.restore_position and state.last_input_window_position then\n    vim.api.nvim_win_set_cursor(0, state.last_input_window_position)\n  end\nend\n\nfunction M.focus_output(opts)\n  opts = opts or {}\n\n  local windows = state.windows\n  vim.api.nvim_set_current_win(windows.output_win)\n\n  if opts.restore_position and state.last_output_window_position then\n    vim.api.nvim_win_set_cursor(0, state.last_output_window_position)\n  end\nend\n\nfunction M.is_goose_focused()\n  if not state.windows then return false end\n  -- are we in a goose window?\n  local current_win = vim.api.nvim_get_current_win()\n  return M.is_goose_window(current_win)\nend\n\nfunction M.is_goose_window(win)\n  local windows = state.windows\n  return win == windows.input_win or win == windows.output_win\nend\n\nfunction M.is_output_empty()\n  local windows = state.windows\n  if not windows or not windows.output_buf then return true end\n  local lines = vim.api.nvim_buf_get_lines(windows.output_buf, 0, -1, false)\n  return #lines == 0 or (#lines == 1 and lines[1] == \"\")\nend\n\nfunction M.clear_output()\n  local windows = state.windows\n\n  -- Clear any extmarks/namespaces first\n  local ns_id = vim.api.nvim_create_namespace('loading_animation')\n  vim.api.nvim_buf_clear_namespace(windows.output_buf, ns_id, 0, -1)\n\n  -- Stop any running timers in the output module\n  if renderer._animation.timer then\n    pcall(vim.fn.timer_stop, renderer._animation.timer)\n    renderer._animation.timer = nil\n  end\n  if renderer._refresh_timer then\n    pcall(vim.fn.timer_stop, renderer._refresh_timer)\n    renderer._refresh_timer = nil\n  end\n\n  -- Reset animation state\n  renderer._animation.loading_line = nil\n\n  -- Clear cache to force refresh on next render\n  renderer._cache = {\n    last_modified = 0,\n    output_lines = nil,\n    session_path = nil,\n    check_counter = 0\n  }\n\n  -- Clear all buffer content\n  vim.api.nvim_buf_set_option(windows.output_buf, 'modifiable', true)\n  vim.api.nvim_buf_set_lines(windows.output_buf, 0, -1, false, {})\n  vim.api.nvim_buf_set_option(windows.output_buf, 'modifiable', false)\n\n  require('goose.ui.topbar').render()\n  renderer.render_markdown()\nend\n\nfunction M.render_output()\n  renderer.render(state.windows, false)\nend\n\nfunction M.stop_render_output()\n  renderer.stop()\nend\n\nfunction M.toggle_fullscreen()\n  local windows = state.windows\n  if not windows then return end\n\n  local ui_config = require(\"goose.config\").get(\"ui\")\n  ui_config.fullscreen = not ui_config.fullscreen\n\n  require(\"goose.ui.window_config\").configure_window_dimensions(windows)\n  require('goose.ui.topbar').render()\n\n  if not M.is_goose_focused() then\n    vim.api.nvim_set_current_win(windows.output_win)\n  end\nend\n\nfunction M.select_session(sessions, cb)\n  local util = require(\"goose.util\")\n\n  vim.ui.select(sessions, {\n    prompt = \"\",\n    format_item = function(session)\n      local parts = {}\n\n      if session.description then\n        table.insert(parts, session.description)\n      end\n\n      if session.message_count then\n        table.insert(parts, session.message_count .. \" messages\")\n      end\n\n      local modified = util.time_ago(session.modified)\n      if modified then\n        table.insert(parts, modified)\n      end\n\n      return table.concat(parts, \" ~ \")\n    end\n  }, function(session_choice)\n    cb(session_choice)\n  end)\nend\n\nfunction M.toggle_pane()\n  local current_win = vim.api.nvim_get_current_win()\n  if current_win == state.windows.input_win then\n    -- When moving from input to output, exit insert mode first\n    vim.cmd('stopinsert')\n    vim.api.nvim_set_current_win(state.windows.output_win)\n  else\n    -- When moving from output to input, just change window\n    -- (don't automatically enter insert mode)\n    vim.api.nvim_set_current_win(state.windows.input_win)\n\n    -- Fix placeholder text when switching to input window\n    local lines = vim.api.nvim_buf_get_lines(state.windows.input_buf, 0, -1, false)\n    if #lines == 1 and lines[1] == \"\" then\n      -- Only show placeholder if the buffer is empty\n      require('goose.ui.window_config').refresh_placeholder(state.windows)\n    else\n      -- Clear placeholder if there's text in the buffer\n      vim.api.nvim_buf_clear_namespace(state.windows.input_buf, vim.api.nvim_create_namespace('input-placeholder'), 0, -1)\n    end\n  end\nend\n\nfunction M.write_to_input(text, windows)\n  if not windows then windows = state.windows end\n  if not windows then return end\n\n  -- Check if input_buf is valid\n  if not windows.input_buf or type(windows.input_buf) ~= \"number\" or not vim.api.nvim_buf_is_valid(windows.input_buf) then\n    return\n  end\n\n  local lines\n\n  -- Check if text is already a table/list of lines\n  if type(text) == \"table\" then\n    lines = text\n  else\n    -- If it's a string, split it into lines\n    lines = {}\n    for line in (text .. '\\n'):gmatch('(.-)\\n') do\n      table.insert(lines, line)\n    end\n\n    -- If no newlines were found (empty result), use the original text\n    if #lines == 0 then\n      lines = { text }\n    end\n  end\n\n  vim.api.nvim_buf_set_lines(windows.input_buf, 0, -1, false, lines)\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/api.lua", "local core = require(\"goose.core\")\n\nlocal ui = require(\"goose.ui.ui\")\nlocal state = require(\"goose.state\")\nlocal review = require(\"goose.review\")\nlocal history = require(\"goose.history\")\n\nlocal M = {}\n\n-- Core API functions\n\nfunction M.open_input()\n  core.open({ new_session = false, focus = \"input\" })\n  vim.cmd('startinsert')\nend\n\nfunction M.open_input_new_session()\n  core.open({ new_session = true, focus = \"input\" })\n  vim.cmd('startinsert')\nend\n\nfunction M.open_output()\n  core.open({ new_session = false, focus = \"output\" })\nend\n\nfunction M.close()\n  ui.close_windows(state.windows)\nend\n\nfunction M.toggle()\n  if state.windows == nil then\n    local focus = state.last_focused_goose_window or \"input\"\n    core.open({ new_session = false, focus = focus })\n  else\n    M.close()\n  end\nend\n\nfunction M.toggle_focus()\n  if not ui.is_goose_focused() then\n    local focus = state.last_focused_goose_window or \"input\"\n    core.open({ new_session = false, focus = focus })\n  else\n    ui.return_to_last_code_win()\n  end\nend\n\nfunction M.change_mode(mode)\n  local info_mod = require(\"goose.info\")\n  info_mod.set_config_value(info_mod.GOOSE_INFO.MODE, mode)\n\n  if state.windows then\n    require('goose.ui.topbar').render()\n  else\n    vim.notify('Goose mode changed to ' .. mode)\n  end\nend\n\nfunction M.goose_mode_chat()\n  M.change_mode(require('goose.info').GOOSE_MODE.CHAT)\nend\n\nfunction M.goose_mode_auto()\n  M.change_mode(require('goose.info').GOOSE_MODE.AUTO)\nend\n\nfunction M.configure_provider()\n  core.configure_provider()\nend\n\nfunction M.stop()\n  core.stop()\nend\n\nfunction M.run(prompt)\n  core.run(prompt, {\n    ensure_ui = true,\n    new_session = false,\n    focus = \"output\"\n  })\nend\n\nfunction M.run_new_session(prompt)\n  core.run(prompt, {\n    ensure_ui = true,\n    new_session = true,\n    focus = \"output\"\n  })\nend\n\nfunction M.toggle_fullscreen()\n  if not state.windows then\n    core.open({ new_session = false, focus = \"output\" })\n  end\n\n  ui.toggle_fullscreen()\nend\n\nfunction M.select_session()\n  core.select_session()\nend\n\nfunction M.toggle_pane()\n  if not state.windows then\n    core.open({ new_session = false, focus = \"output\" })\n    return\n  end\n\n  ui.toggle_pane()\nend\n\nfunction M.diff_open()\n  review.review()\nend\n\nfunction M.diff_next()\n  review.next_diff()\nend\n\nfunction M.diff_prev()\n  review.prev_diff()\nend\n\nfunction M.diff_close()\n  review.close_diff()\nend\n\nfunction M.diff_revert_all()\n  review.revert_all()\nend\n\nfunction M.diff_revert_this()\n  review.revert_current()\nend\n\nfunction M.set_review_breakpoint()\n  review.set_breakpoint()\nend\n\nfunction M.prev_history()\n  local prev_prompt = history.prev()\n  if prev_prompt then\n    ui.write_to_input(prev_prompt)\n  end\nend\n\nfunction M.next_history()\n  local next_prompt = history.next()\n  if next_prompt then\n    ui.write_to_input(next_prompt)\n  end\nend\n\n-- Command definitions that call the API functions\nM.commands = {\n  toggle = {\n    name = \"Goose\",\n    desc = \"Open goose. Close if opened\",\n    fn = function()\n      M.toggle()\n    end\n  },\n\n  toggle_focus = {\n    name = \"GooseToggleFocus\",\n    desc = \"Toggle focus between goose and last window\",\n    fn = function()\n      M.toggle_focus()\n    end\n  },\n\n  open_input = {\n    name = \"GooseOpenInput\",\n    desc = \"Opens and focuses on input window on insert mode\",\n    fn = function()\n      M.open_input()\n    end\n  },\n\n  open_input_new_session = {\n    name = \"GooseOpenInputNewSession\",\n    desc = \"Opens and focuses on input window on insert mode. Creates a new session\",\n    fn = function()\n      M.open_input_new_session()\n    end\n  },\n\n  open_output = {\n    name = \"GooseOpenOutput\",\n    desc = \"Opens and focuses on output window\",\n    fn = function()\n      M.open_output()\n    end\n  },\n\n  close = {\n    name = \"GooseClose\",\n    desc = \"Close UI windows\",\n    fn = function()\n      M.close()\n    end\n  },\n\n  stop = {\n    name = \"GooseStop\",\n    desc = \"Stop goose while it is running\",\n    fn = function()\n      M.stop()\n    end\n  },\n\n  toggle_fullscreen = {\n    name = \"GooseToggleFullscreen\",\n    desc = \"Toggle between normal and fullscreen mode\",\n    fn = function()\n      M.toggle_fullscreen()\n    end\n  },\n\n  select_session = {\n    name = \"GooseSelectSession\",\n    desc = \"Select and load a goose session\",\n    fn = function()\n      M.select_session()\n    end\n  },\n\n  toggle_pane = {\n    name = \"GooseTogglePane\",\n    desc = \"Toggle between input and output panes\",\n    fn = function()\n      M.toggle_pane()\n    end\n  },\n\n  goose_mode_chat = {\n    name = \"GooseModeChat\",\n    desc = \"Set goose mode to `chat`. (Tool calling disabled. No editor context besides selections)\",\n    fn = function()\n      M.goose_mode_chat()\n    end\n  },\n\n  goose_mode_auto = {\n    name = \"GooseModeAuto\",\n    desc = \"Set goose mode to `auto`. (Default mode with full agent capabilities)\",\n    fn = function()\n      M.goose_mode_auto()\n    end\n  },\n\n  configure_provider = {\n    name = \"GooseConfigureProvider\",\n    desc = \"Quick provider and model switch from predefined list\",\n    fn = function()\n      M.configure_provider()\n    end\n  },\n\n  run = {\n    name = \"GooseRun\",\n    desc = \"Run goose with a prompt (continue last session)\",\n    fn = function(opts)\n      M.run(opts.args)\n    end\n  },\n\n  run_new_session = {\n    name = \"GooseRunNewSession\",\n    desc = \"Run goose with a prompt (new session)\",\n    fn = function(opts)\n      M.run_new_session(opts.args)\n    end\n  },\n\n  -- Updated diff command names\n  diff_open = {\n    name = \"GooseDiff\",\n    desc = \"Opens a diff tab of a modified file since the last goose prompt\",\n    fn = function()\n      M.diff_open()\n    end\n  },\n\n  diff_next = {\n    name = \"GooseDiffNext\",\n    desc = \"Navigate to next file diff\",\n    fn = function()\n      M.diff_next()\n    end\n  },\n\n  diff_prev = {\n    name = \"GooseDiffPrev\",\n    desc = \"Navigate to previous file diff\",\n    fn = function()\n      M.diff_prev()\n    end\n  },\n\n  diff_close = {\n    name = \"GooseDiffClose\",\n    desc = \"Close diff view tab and return to normal editing\",\n    fn = function()\n      M.diff_close()\n    end\n  },\n\n  diff_revert_all = {\n    name = \"GooseRevertAll\",\n    desc = \"Revert all file changes since the last goose prompt\",\n    fn = function()\n      M.diff_revert_all()\n    end\n  },\n\n  diff_revert_this = {\n    name = \"GooseRevertThis\",\n    desc = \"Revert current file changes since the last goose prompt\",\n    fn = function()\n      M.diff_revert_this()\n    end\n  },\n\n  set_review_breakpoint = {\n    name = \"GooseSetReviewBreakpoint\",\n    desc = \"Set a review breakpoint to track changes\",\n    fn = function()\n      M.set_review_breakpoint()\n    end\n  },\n}\n\nfunction M.setup()\n  -- Register commands without arguments\n  for key, cmd in pairs(M.commands) do\n    if key ~= \"run\" and key ~= \"run_new_session\" then\n      vim.api.nvim_create_user_command(cmd.name, cmd.fn, {\n        desc = cmd.desc\n      })\n    end\n  end\n\n  -- Register commands with arguments\n  vim.api.nvim_create_user_command(M.commands.run.name, M.commands.run.fn, {\n    desc = M.commands.run.desc,\n    nargs = \"+\"\n  })\n\n  vim.api.nvim_create_user_command(M.commands.run_new_session.name, M.commands.run_new_session.fn, {\n    desc = M.commands.run_new_session.desc,\n    nargs = \"+\"\n  })\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/session.lua", "local M = {}\n\nfunction M.get_all_sessions()\n  local handle = io.popen('goose session list --format json')\n  if not handle then return nil end\n\n  local result = handle:read(\"*a\")\n  handle:close()\n\n  local success, sessions = pcall(vim.fn.json_decode, result)\n  if not success or not sessions or next(sessions) == nil then return nil end\n\n  return vim.tbl_map(function(session)\n    return {\n      workspace = session.metadata.working_dir,\n      description = session.metadata.description,\n      message_count = session.metadata.message_count,\n      tokens = session.metadata.total_tokens,\n      modified = session.modified,\n      name = session.id,\n      path = session.path\n    }\n  end, sessions)\nend\n\nfunction M.get_all_workspace_sessions()\n  local sessions = M.get_all_sessions()\n  if not sessions then return nil end\n\n  local workspace = vim.fn.getcwd()\n  sessions = vim.tbl_filter(function(session)\n    return session.workspace == workspace\n  end, sessions)\n\n  table.sort(sessions, function(a, b)\n    return a.modified > b.modified\n  end)\n\n  return sessions\nend\n\nfunction M.get_last_workspace_session()\n  local sessions = M.get_all_workspace_sessions()\n  if not sessions then return nil end\n  return sessions[1]\nend\n\nfunction M.get_by_name(name)\n  local sessions = M.get_all_sessions()\n  if not sessions then return nil end\n\n  for _, session in ipairs(sessions) do\n    if session.name == name then\n      return session\n    end\n  end\n\n  return nil\nend\n\nfunction M.update_session_workspace(session_name, workspace_path)\n  local session = M.get_by_name(session_name)\n  if not session then return false end\n\n  local file = io.open(session.path, \"r\")\n  if not file then return false end\n\n  local first_line = file:read(\"*line\")\n  local rest = file:read(\"*all\")\n  file:close()\n\n  -- Parse and update metadata\n  local success, metadata = pcall(vim.fn.json_decode, first_line)\n  if not success then return false end\n\n  metadata.working_dir = workspace_path\n\n  -- Write back: metadata line + rest of the file\n  file = io.open(session.path, \"w\")\n  if not file then return false end\n\n  file:write(vim.fn.json_encode(metadata) .. \"\\n\")\n  if rest and rest ~= \"\" then\n    file:write(rest)\n  end\n  file:close()\n\n  return true\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/ui/session_formatter.lua", "local M = {}\n\nlocal context_module = require('goose.context')\n\nM.separator = {\n  \"---\",\n  \"\"\n}\n\nfunction M.format_session(session_path)\n  if vim.fn.filereadable(session_path) == 0 then return nil end\n\n  local session_lines = vim.fn.readfile(session_path)\n  if #session_lines == 0 then return nil end\n\n  local output_lines = { \"\" }\n\n  local need_separator = false\n\n  for i = 2, #session_lines do\n    local success, message = pcall(vim.fn.json_decode, session_lines[i])\n    if not success then goto continue end\n\n    local message_lines = M._format_message(message)\n    if message_lines then\n      if need_separator then\n        for _, line in ipairs(M.separator) do\n          table.insert(output_lines, line)\n        end\n      else\n        need_separator = true\n      end\n\n      vim.list_extend(output_lines, message_lines)\n    end\n\n    ::continue::\n  end\n\n  return output_lines\nend\n\nfunction M._format_user_message(lines, text)\n  local context = context_module.extract_from_message(text)\n  for _, line in ipairs(vim.split(context.prompt, \"\\n\")) do\n    table.insert(lines, \"> \" .. line)\n  end\n\n  if context.selected_text then\n    table.insert(lines, \"\")\n    for _, line in ipairs(vim.split(context.selected_text, \"\\n\")) do\n      table.insert(lines, line)\n    end\n  end\nend\n\nfunction M._format_message(message)\n  if not message.content then return nil end\n\n  local lines = {}\n  local has_content = false\n\n  for _, part in ipairs(message.content) do\n    if part.type == 'text' and part.text and part.text ~= \"\" then\n      local text = vim.trim(part.text)\n      has_content = true\n\n      if message.role == 'user' then\n        M._format_user_message(lines, text)\n      elseif message.role == 'assistant' then\n        for _, line in ipairs(vim.split(text, \"\\n\")) do\n          table.insert(lines, line)\n        end\n      end\n    elseif part.type == 'toolRequest' then\n      if has_content then\n        table.insert(lines, \"\")\n      end\n      M._format_tool(lines, part)\n      has_content = true\n    end\n  end\n\n  if has_content then\n    table.insert(lines, \"\")\n  end\n\n  return has_content and lines or nil\nend\n\nfunction M._format_context(lines, type, value)\n  if not type or not value then return end\n\n  -- escape new lines\n  value = value:gsub(\"\\n\", \"\\\\n\")\n\n  local formatted_action = ' **' .. type .. '** ` ' .. value .. ' `'\n  table.insert(lines, formatted_action)\nend\n\nfunction M._format_tool(lines, part)\n  local tool = part.toolCall.value\n  if not tool then return end\n\n\n  if tool.name == 'developer__shell' then\n    M._format_context(lines, '🚀 run', tool.arguments.command)\n  elseif tool.name == 'developer__text_editor' then\n    local path = tool.arguments.path\n    local file_name = vim.fn.fnamemodify(path, \":t\")\n\n    if tool.arguments.command == 'str_replace' or tool.arguments.command == 'write' then\n      M._format_context(lines, '✏️ write to', file_name)\n    elseif tool.arguments.command == 'view' then\n      M._format_context(lines, '👀 view', file_name)\n    else\n      M._format_context(lines, '✨ command', tool.arguments.command)\n    end\n  else\n    M._format_context(lines, '🔧 tool', tool.name)\n  end\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/job.lua", "-- goose.nvim/lua/goose/job.lua\n-- Contains goose job execution logic\n\nlocal context = require(\"goose.context\")\nlocal state = require(\"goose.state\")\nlocal Job = require('plenary.job')\nlocal util = require(\"goose.util\")\n\nlocal M = {}\n\nfunction M.build_args(prompt)\n  if not prompt then return nil end\n  local message = context.format_message(prompt)\n  local args = { \"run\", \"--text\", message }\n\n  if state.active_session then\n    table.insert(args, \"--name\")\n    table.insert(args, state.active_session.name)\n    table.insert(args, \"--resume\")\n  else\n    local session_name = util.uid()\n    state.new_session_name = session_name\n    table.insert(args, \"--name\")\n    table.insert(args, session_name)\n  end\n\n  return args\nend\n\nfunction M.execute(prompt, handlers)\n  if not prompt then\n    return nil\n  end\n\n  local args = M.build_args(prompt)\n\n  state.goose_run_job = Job:new({\n    command = 'goose',\n    args = args,\n    on_start = function()\n      vim.schedule(function()\n        handlers.on_start()\n      end)\n    end,\n    on_stdout = function(_, out)\n      if out then\n        vim.schedule(function()\n          handlers.on_output(out)\n        end)\n      end\n    end,\n    on_stderr = function(_, err)\n      if err then\n        vim.schedule(function()\n          handlers.on_error(err)\n        end)\n      end\n    end,\n    on_exit = function()\n      vim.schedule(function()\n        handlers.on_exit()\n      end)\n    end\n  })\n\n  state.goose_run_job:start()\nend\n\nfunction M.stop(job)\n  if job then\n    pcall(function()\n      vim.uv.process_kill(job.handle)\n      job:shutdown()\n    end)\n  end\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/history.lua", "local M = {}\n\nlocal Path = require('plenary.path')\nlocal cached_history = nil\nlocal prompt_before_history = nil\n\nM.index = nil\n\nlocal function get_history_file()\n  local data_path = Path:new(vim.fn.stdpath('data')):joinpath('goose')\n  if not data_path:exists() then\n    data_path:mkdir({ parents = true })\n  end\n  return data_path:joinpath('history.txt')\nend\n\nM.write = function(prompt)\n  local file = io.open(get_history_file().filename, \"a\")\n  if file then\n    -- Escape any newlines in the prompt\n    local escaped_prompt = prompt:gsub(\"\\n\", \"\\\\n\")\n    file:write(escaped_prompt .. \"\\n\")\n    file:close()\n    -- Invalidate cache when writing new history\n    cached_history = nil\n  end\nend\n\nM.read = function()\n  -- Return cached result if available\n  if cached_history then\n    return cached_history\n  end\n\n  local line_by_index = {}\n  local file = io.open(get_history_file().filename, \"r\")\n\n  if file then\n    local lines = {}\n\n    -- Read all non-empty lines\n    for line in file:lines() do\n      if line:gsub(\"%s\", \"\") ~= \"\" then\n        -- Unescape any escaped newlines\n        local unescaped_line = line:gsub(\"\\\\n\", \"\\n\")\n        table.insert(lines, unescaped_line)\n      end\n    end\n    file:close()\n\n    -- Reverse the array to have index 1 = most recent\n    for i = 1, #lines do\n      line_by_index[i] = lines[#lines - i + 1]\n    end\n  end\n\n  -- Cache the result\n  cached_history = line_by_index\n  return line_by_index\nend\n\nM.prev = function()\n  local history = M.read()\n\n  if not M.index or M.index == 0 then\n    prompt_before_history = require('goose.state').input_content\n  end\n\n  -- Initialize or increment index\n  M.index = (M.index or 0) + 1\n\n  -- Cap at the end of history\n  if M.index > #history then\n    M.index = #history\n  end\n\n  return history[M.index]\nend\n\nM.next = function()\n  -- Return nil for invalid cases\n  if not M.index then\n    return nil\n  end\n\n  if M.index <= 1 then\n    M.index = nil\n    return prompt_before_history\n  end\n\n  M.index = M.index - 1\n  return M.read()[M.index]\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/info.lua", "local M = {}\nlocal util = require('goose.util')\n\nM.GOOSE_INFO = {\n  MODEL = \"GOOSE_MODEL\",\n  PROVIDER = \"GOOSE_PROVIDER\",\n  MODE = \"GOOSE_MODE\",\n  CONFIG = \"Config file\"\n}\n\nM.GOOSE_MODE = {\n  CHAT = \"chat\",\n  AUTO = \"auto\"\n}\n\n-- Parse the output of `goose info -v` command\nfunction M.parse_goose_info()\n  local result = {}\n\n  local handle = io.popen(\"goose info -v\")\n  if not handle then\n    return result\n  end\n\n  local output = handle:read(\"*a\")\n  handle:close()\n\n  local model = output:match(M.GOOSE_INFO.MODEL .. \":%s*(.-)\\n\") or output:match(M.GOOSE_INFO.MODEL .. \":%s*(.-)$\")\n  if model then\n    result.goose_model = vim.trim(model)\n  end\n\n  local provider = output:match(M.GOOSE_INFO.PROVIDER .. \":%s*(.-)\\n\") or output:match(M.GOOSE_INFO.PROVIDER .. \":%s*(.-)$\")\n  if provider then\n    result.goose_provider = vim.trim(provider)\n  end\n\n  local mode = output:match(M.GOOSE_INFO.MODE .. \":%s*(.-)\\n\") or output:match(M.GOOSE_INFO.MODE .. \":%s*(.-)$\")\n  if mode then\n    result.goose_mode = vim.trim(mode)\n  end\n\n  local config_file = output:match(M.GOOSE_INFO.CONFIG .. \":%s*(.-)\\n\") or\n      output:match(M.GOOSE_INFO.CONFIG .. \":%s*(.-)$\")\n  if config_file then\n    result.config_file = vim.trim(config_file)\n  end\n\n  return result\nend\n\n-- Set a value in the goose config file\nfunction M.set_config_value(key, value)\n  local info = M.parse_goose_info()\n  if not info.config_file then\n    return false, \"Could not find config file path\"\n  end\n\n  return util.set_yaml_value(info.config_file, key, value)\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/ui/topbar.lua", "local M = {}\n\nlocal state = require(\"goose.state\")\n\nlocal LABELS = {\n  NEW_SESSION_TITLE = \"New session\",\n}\n\nlocal function format_model_info()\n  local info = require(\"goose.info\").parse_goose_info()\n  local config = require(\"goose.config\").get()\n  local parts = {}\n\n  if config.ui.display_model then\n    local model = info.goose_model and (info.goose_model:match(\"[^/]+$\") or info.goose_model) or \"\"\n    if model ~= \"\" then\n      table.insert(parts, model)\n    end\n  end\n\n  if config.ui.display_goose_mode then\n    local mode = info.goose_mode\n    if mode then\n      table.insert(parts, \"[\" .. mode .. \"]\")\n    end\n  end\n\n  return table.concat(parts, \" \")\nend\n\n\nlocal function create_winbar_text(description, model_info, win_width)\n  local available_width = win_width - 2 -- 2 padding spaces\n\n  -- If total length exceeds available width, truncate description\n  if #description + 1 + #model_info > available_width then\n    local space_for_desc = available_width - #model_info - 4 -- -4 for \"... \"\n    description = description:sub(1, space_for_desc) .. \"... \"\n  end\n\n  local padding = string.rep(\" \", available_width - #description - #model_info)\n  return string.format(\" %s%s%s \", description, padding, model_info)\nend\n\nlocal function update_winbar_highlights(win_id)\n  local current = vim.api.nvim_win_get_option(win_id, 'winhighlight')\n  local parts = vim.split(current, \",\")\n\n  -- Remove any existing winbar highlights\n  parts = vim.tbl_filter(function(part)\n    return not part:match(\"^WinBar:\") and not part:match(\"^WinBarNC:\")\n  end, parts)\n\n  if not vim.tbl_contains(parts, \"Normal:GooseNormal\") then\n    table.insert(parts, \"Normal:GooseNormal\")\n  end\n\n  table.insert(parts, \"WinBar:GooseSessionDescription\")\n  table.insert(parts, \"WinBarNC:GooseSessionDescription\")\n\n  vim.api.nvim_win_set_option(win_id, 'winhighlight', table.concat(parts, \",\"))\nend\n\nlocal function get_session_desc()\n  local session_desc = LABELS.NEW_SESSION_TITLE\n\n  if state.active_session then\n    local session = require('goose.session').get_by_name(state.active_session.name)\n    if session and session.description ~= \"\" then\n      session_desc = session.description\n    end\n  end\n\n  return session_desc\nend\n\nfunction M.render()\n  local win = state.windows.output_win\n\n  vim.schedule(function()\n    vim.wo[win].winbar = create_winbar_text(\n      get_session_desc(),\n      format_model_info(),\n      vim.api.nvim_win_get_width(win)\n    )\n\n    update_winbar_highlights(win)\n  end)\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/config.lua", "-- Default and user-provided settings for goose.nvim\n\nlocal M = {}\n\n-- Default configuration\nM.defaults = {\n  prefered_picker = nil,\n  default_global_keymaps = true,\n  keymap = {\n    global = {\n      toggle = '<leader>gg',\n      open_input = '<leader>gi',\n      open_input_new_session = '<leader>gI',\n      open_output = '<leader>go',\n      toggle_focus = '<leader>gt',\n      close = '<leader>gq',\n      toggle_fullscreen = '<leader>gf',\n      select_session = '<leader>gs',\n      goose_mode_chat = '<leader>gmc',\n      goose_mode_auto = '<leader>gma',\n      configure_provider = '<leader>gp',\n      diff_open = '<leader>gd',\n      diff_next = '<leader>g]',\n      diff_prev = '<leader>g[',\n      diff_close = '<leader>gc',\n      diff_revert_all = '<leader>gra',\n      diff_revert_this = '<leader>grt'\n    },\n    window = {\n      submit = '<cr>',\n      submit_insert = '<cr>',\n      close = '<esc>',\n      stop = '<C-c>',\n      next_message = ']]',\n      prev_message = '[[',\n      mention_file = '@',\n      toggle_pane = '<tab>',\n      prev_prompt_history = '<up>',\n      next_prompt_history = '<down>'\n    }\n  },\n  ui = {\n    window_width = 0.35,\n    input_height = 0.15,\n    fullscreen = false,\n    layout = \"right\",\n    floating_height = 0.8,\n    display_model = true,\n    display_goose_mode = true\n  },\n  providers = {\n    --[[\n    Define available providers and their models for quick model switching\n    anthropic|azure|bedrock|databricks|google|groq|ollama|openai|openrouter\n    Example:\n    openrouter = {\n      \"anthropic/claude-3.5-sonnet\",\n      \"openai/gpt-4.1\",\n    },\n    ollama = {\n      \"cogito:14b\"\n    }\n    --]]\n  },\n  context = {\n    cursor_data = false, -- Send cursor position and current line content as context data\n  },\n}\n\n-- Active configuration\nM.values = vim.deepcopy(M.defaults)\n\nfunction M.setup(opts)\n  opts = opts or {}\n\n  if opts.default_global_keymaps == false then\n    M.values.keymap.global = {}\n  end\n\n  -- Merge user options with defaults (deep merge for nested tables)\n  for k, v in pairs(opts) do\n    if type(v) == \"table\" and type(M.values[k]) == \"table\" then\n      M.values[k] = vim.tbl_deep_extend(\"force\", M.values[k], v)\n    else\n      M.values[k] = v\n    end\n  end\nend\n\nfunction M.get(key)\n  if key then\n    return M.values[key]\n  end\n  return M.values\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/ui/mention.lua", "local M = {}\n\nlocal mentions_namespace = vim.api.nvim_create_namespace(\"GooseMentions\")\n\nfunction M.highlight_all_mentions(buf)\n  -- Pattern for mentions\n  local mention_pattern = \"@[%w_%-%.][%w_%-%.]*\"\n\n  -- Clear existing extmarks\n  vim.api.nvim_buf_clear_namespace(buf, mentions_namespace, 0, -1)\n\n  -- Get all lines in buffer\n  local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)\n\n  for row, line in ipairs(lines) do\n    local start_idx = 1\n    -- Find all mentions in the line\n    while true do\n      local mention_start, mention_end = line:find(mention_pattern, start_idx)\n      if not mention_start then break end\n\n      -- Add extmark for this mention\n      vim.api.nvim_buf_set_extmark(buf, mentions_namespace, row - 1, mention_start - 1, {\n        end_col = mention_end,\n        hl_group = \"GooseMention\",\n      })\n\n      -- Move to search for the next mention\n      start_idx = mention_end + 1\n    end\n  end\nend\n\nlocal function insert_mention(windows, row, col, name)\n  local current_line = vim.api.nvim_buf_get_lines(windows.input_buf, row - 1, row, false)[1]\n\n  local insert_name = '@' .. name .. \" \"\n\n  local new_line = current_line:sub(1, col) .. insert_name .. current_line:sub(col + 2)\n  vim.api.nvim_buf_set_lines(windows.input_buf, row - 1, row, false, { new_line })\n\n  -- Highlight all mentions in the updated buffer\n  M.highlight_all_mentions(windows.input_buf)\n\n  vim.defer_fn(function()\n    vim.cmd('startinsert')\n    vim.api.nvim_set_current_win(windows.input_win)\n    vim.api.nvim_win_set_cursor(windows.input_win, { row, col + 1 + #insert_name + 1 })\n  end, 100)\nend\n\nfunction M.mention(get_name)\n  local windows = require('goose.state').windows\n\n  local mention_key = require('goose.config').get('keymap').window.mention_file\n  -- insert @ in case we just want the character\n  if mention_key == '@' then\n    vim.api.nvim_feedkeys('@', 'in', true)\n  end\n\n  local cursor_pos = vim.api.nvim_win_get_cursor(windows.input_win)\n  local row, col = cursor_pos[1], cursor_pos[2]\n\n  get_name(function(name)\n    insert_mention(windows, row, col, name)\n  end)\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/provider.lua", "local M = {}\n\nfunction M.select(cb)\n  local config = require(\"goose.config\")\n\n  -- Create a flat list of all provider/model combinations\n  local model_options = {}\n\n  for provider, models in pairs(config.get(\"providers\")) do\n    for _, model in ipairs(models) do\n      table.insert(model_options, {\n        provider = provider,\n        model = model,\n        display = provider .. \": \" .. model\n      })\n    end\n  end\n\n  if #model_options == 0 then\n    vim.notify(\"No models configured in providers\", vim.log.levels.ERROR)\n    return\n  end\n\n  vim.ui.select(model_options, {\n    prompt = \"Select model:\",\n    format_item = function(item)\n      return item.display\n    end\n  }, function(selection)\n    cb(selection)\n  end)\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/keymap.lua", "local api = require(\"goose.api\")\n\nlocal M = {}\n\n-- Binds a keymap config with its api fn\n-- Name of api fn & keymap global config should always be the same\nfunction M.setup(keymap)\n  local cmds = api.commands\n  local global = keymap.global\n\n  for key, mapping in pairs(global) do\n    if type(mapping) == \"string\" then\n      vim.keymap.set(\n        { 'n', 'v' },\n        mapping,\n        function() api[key]() end,\n        { silent = false, desc = cmds[key] and cmds[key].desc }\n      )\n    end\n  end\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/ui/util.lua", "-- UI utility functions\nlocal M = {}\n\n-- Navigate through prompt history with consideration for multi-line input\n-- Only triggers history navigation at text boundaries when using arrow keys\nfunction M.navigate_history(direction, key, prev_history_fn, next_history_fn)\n  return function()\n    -- Check if using arrow keys\n    local is_arrow_key = key == '<up>' or key == '<down>'\n\n    if is_arrow_key then\n      -- Get cursor position info\n      local cursor_pos = vim.api.nvim_win_get_cursor(0)\n      local current_line = cursor_pos[1]\n      local line_count = vim.api.nvim_buf_line_count(0)\n\n      -- Navigate history only at boundaries\n      if (direction == 'prev' and current_line <= 1) or\n          (direction == 'next' and current_line >= line_count) then\n        if direction == 'prev' then prev_history_fn() else next_history_fn() end\n      else\n        -- Otherwise use normal navigation\n        vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, false, true), 'n', false)\n      end\n    else\n      -- Not arrow keys, always use history navigation\n      if direction == 'prev' then prev_history_fn() else next_history_fn() end\n    end\n  end\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/ui/navigation.lua", "local M = {}\n\nlocal state = require('goose.state')\nlocal session_formatter = require('goose.ui.session_formatter')\nlocal SEPARATOR_TEXT = session_formatter.separator[1]\n\nlocal function re_focus()\n  vim.cmd(\"normal! zt\")\nend\n\nfunction M.goto_next_message()\n  require('goose.ui.ui').focus_output()\n  local windows = state.windows\n  local win = windows.output_win\n  local buf = windows.output_buf\n\n  local current_line = vim.api.nvim_win_get_cursor(win)[1]\n  local line_count = vim.api.nvim_buf_line_count(buf)\n\n  for i = current_line, line_count do\n    local line = vim.api.nvim_buf_get_lines(buf, i - 1, i, false)[1]\n    if line == SEPARATOR_TEXT then\n      vim.api.nvim_win_set_cursor(win, { i + 1, 0 })\n      re_focus()\n      return\n    end\n  end\nend\n\nfunction M.goto_prev_message()\n  require('goose.ui.ui').focus_output()\n  local windows = state.windows\n  local win = windows.output_win\n  local buf = windows.output_buf\n  local current_line = vim.api.nvim_win_get_cursor(win)[1]\n  local current_message_start = nil\n\n  -- Find if we're at a message start\n  local at_message_start = false\n  if current_line > 1 then\n    local prev_line = vim.api.nvim_buf_get_lines(buf, current_line - 2, current_line - 1, false)[1]\n    at_message_start = prev_line == SEPARATOR_TEXT\n  end\n\n  -- Find current message start\n  for i = current_line - 1, 1, -1 do\n    local line = vim.api.nvim_buf_get_lines(buf, i - 1, i, false)[1]\n    if line == SEPARATOR_TEXT then\n      current_message_start = i + 1\n      break\n    end\n  end\n\n  -- Go to first line if no separator found\n  if not current_message_start then\n    vim.api.nvim_win_set_cursor(win, { 1, 0 })\n    re_focus()\n    return\n  end\n\n  -- If not at message start, go to current message start\n  if not at_message_start and current_line > current_message_start then\n    vim.api.nvim_win_set_cursor(win, { current_message_start, 0 })\n    re_focus()\n    return\n  end\n\n  -- Find previous message start\n  for i = current_message_start - 2, 1, -1 do\n    local line = vim.api.nvim_buf_get_lines(buf, i - 1, i, false)[1]\n    if line == SEPARATOR_TEXT then\n      vim.api.nvim_win_set_cursor(win, { i + 1, 0 })\n      re_focus()\n      return\n    end\n  end\n\n  -- If no previous message, go to first line\n  vim.api.nvim_win_set_cursor(win, { 1, 0 })\n  re_focus()\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/init.lua", "local M = {}\nlocal config = require(\"goose.config\")\nlocal keymap = require(\"goose.keymap\")\nlocal api = require(\"goose.api\")\n\nfunction M.setup(opts)\n  config.setup(opts)\n  api.setup()\n  keymap.setup(config.get(\"keymap\"))\nend\n\nreturn M\n"], ["/goose.nvim/lua/goose/ui/highlight.lua", "local M = {}\n\nfunction M.setup()\n  vim.api.nvim_set_hl(0, 'GooseBorder', { fg = '#616161' })\n  vim.api.nvim_set_hl(0, 'GooseBackground', { link = \"Normal\" })\n  vim.api.nvim_set_hl(0, 'GooseSessionDescription', { link = \"Comment\" })\n  vim.api.nvim_set_hl(0, \"GooseMention\", { link = \"Special\" })\nend\n\nreturn M\n"], ["/goose.nvim/plugin/goose.lua", "-- Plugin loader for goose.nvim\nif vim.g.loaded_goose_nvim == 1 then\n  return\nend\nvim.g.loaded_goose_nvim = 1\n"], ["/goose.nvim/lua/goose/state.lua", "local M = {}\n\n-- ui\nM.windows = nil\nM.input_content = {}\nM.last_focused_goose_window = nil\nM.last_input_window_position = nil\nM.last_output_window_position = nil\nM.last_code_win_before_goose = nil\n\n-- context\nM.last_sent_context = nil\n\n-- session\nM.active_session = nil\nM.new_session_name = nil\n\n-- job\nM.goose_run_job = nil\n\nreturn M\n"]], "task_instance_info": {"created_time": "2025-08-21 00:38:48", "created_task_model": "DeepSeek-R1", "class_skeleton": "{}", "code_description": "This code segment functions to: Configure the selection handling process for a user interface component by defining how chosen items are processed and communicated to external logic while suppressing default behavior."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```lua\n[TASK_BEGIN]\nfunction(item)\n  if item then\n    callback(item)\n  end\nend\n[TASK_END]\n```", "inference_time": "2025-08-21 00-39-09"}, "editdistance_info": {"edit_distance": 22.2222, "calculate_time": "2025-08-21 00:39:09", "true_code_clean": "{\n    source = {\n      choose = function(selected)\n        if selected and callback then\n          callback(selected)\n        end\n        return false\n      end,\n    },\n  }", "predict_code_clean": "function(item)\n  if item then\n    callback(item)\n  end\nend"}}