From 47c13ce295e1db9b1df41a41ee72e16ee98593cd Mon Sep 17 00:00:00 2001 From: theprimeagain Date: Sat, 28 Feb 2026 11:46:21 -0700 Subject: small and better change for viewing logs and better work checking --- lua/99/extensions/work/worker.lua | 51 +++++++-------- lua/99/init.lua | 127 +++++++++++++++++--------------------- lua/99/logger/logger.lua | 6 ++ lua/99/state/tracking.lua | 10 +++ 4 files changed, 98 insertions(+), 96 deletions(-) (limited to 'lua') diff --git a/lua/99/extensions/work/worker.lua b/lua/99/extensions/work/worker.lua index 7bc65d9..60825f3 100644 --- a/lua/99/extensions/work/worker.lua +++ b/lua/99/extensions/work/worker.lua @@ -108,31 +108,18 @@ end function M.craft_prompt(worker) return string.format( [[ - - - -Inspect and understand all changed code -* git diff -* git diff --staged -* commits that have not been pushed to remote - - - -Take the current pending and commited changes and figure out what is -left to change to complete the work item. The work item is described in - -Carefully review all the changes and before you respond. -respond with proper Search Format described in and an example in - -If you see bugs, also report those - - - -if there are steps to test the project. run the tests and add to the list the failures -and how to fix them - - - +## You must complete the checklist +[ ] - Inspect and understand all changed code + [ ] - git diff + [ ] - git diff --staged + [ ] - commits that have not been pushed to remote +[ ] - Take the current pending and commited changes and figure out what is left + to change to complete the work item. The work item is described in +[ ] - Carefully review all the changes and before you respond. + respond with proper Search Format described in and an example in +[ ] - If you see bugs, also report those +[ ] - if there are tests, run the tests + %s @@ -155,4 +142,18 @@ function M.search() }) end +function M.vibe() + local _99 = require("99") + hydrate_current_work_item() + + assert( + M.current_work_item, + 'you must call "set_work" and set your current work item before calling this' + ) + + M.last_work_search = _99.vibe({ + additional_prompt = M.craft_prompt(M), + }) +end + return M diff --git a/lua/99/init.lua b/lua/99/init.lua index 3935dd4..393c427 100644 --- a/lua/99/init.lua +++ b/lua/99/init.lua @@ -2,6 +2,7 @@ --- task for me to do in the future to make this a bit more clean and only have --- stuff that makes sense for the api to be in here... but for now.. ia m sorry local Logger = require("99.logger.logger") +local Tracking = require("99.state.tracking") local Level = require("99.logger.level") local ops = require("99.ops") local Window = require("99.window") @@ -198,8 +199,8 @@ local _99_state --- takes your current selection and sends that along with the prompt provided and replaces --- your visual selection with the results --- @field view_logs fun(): nil ---- views the most recent logs and setups the machine to view older and new logs ---- this is still pretty rough and will change in the near future +--- views the most recent logs. we dont have a way to view older logs in a reasonable right now +--- I want to rework the log viewing --- @field stop_all_requests fun(): nil --- stops all in flight requests. this means that the underlying process will --- be killed (OpenCode) and any result will be discared @@ -215,6 +216,39 @@ local _99 = { FATAL = Level.FATAL, } +--- @param requests _99.Prompt[] +---@param cb fun(r: _99.Prompt): nil +local function capture_request(requests, cb) + local str_requests = Tracking.to_selectable_list(requests) + + Window.capture_select_input("99 Select Request", { + content = str_requests, + cb = function(success, result) + if not success or result == "" then + return + end + + local idx = tonumber(vim.fn.matchstr(result, "^\\d\\+")) + if idx == nil then + return + end + local r = requests[idx] + if not r then + print( + "request not found... potentially report bug: " .. vim.inspect(idx) + ) + return + end + assert( + r:valid(), + "request is not valid... not sure how we got here. please report bug and this word: " + .. vim.inspect(r.operation) + ) + cb(r) + end, + }) +end + --- @param cb fun(context: _99.Prompt, o: _99.ops.Opts?): nil --- @param name string --- @param context _99.Prompt @@ -284,46 +318,18 @@ end function _99.open() local requests = _99_state.tracking:successful() - local str_requests = {} - for i, r in ipairs(requests) do - table.insert(str_requests, string.format("%d: %s", i, r:summary())) - end - - Window.capture_select_input("99", { - content = str_requests, - cb = function(success, result) - if not success or result == "" then - return - end - - local idx = tonumber(vim.fn.matchstr(result, "^\\d\\+")) - if idx == nil then - return - end - local r = requests[idx] - if not r then - print( - "request not found... potentially report bug: " .. vim.inspect(idx) - ) - return - end - assert( - r:valid(), - "request is not valid... not sure how we got here. please report bug and this word: " - .. vim.inspect(r.operation) - ) - if r.operation == "visual" then - --- TODO: this is its own work item for being able to have a global mark - --- section in which i keep track of marks for the lifetime of the - --- editor and when you close the editor, then it should lose them - print("visual not supported: i will figure this out... at some point") - elseif r.operation == "search" or r.operation == "vibe" then - _99.open_qfix_for_request(r) - elseif r.operation == "tutorial" then - _99.open_tutorial(r) - end - end, - }) + capture_request(requests, function(r) + if r.operation == "visual" then + --- TODO: this is its own work item for being able to have a global mark + --- section in which i keep track of marks for the lifetime of the + --- editor and when you close the editor, then it should lose them + print("visual not supported: i will figure this out... at some point") + elseif r.operation == "search" or r.operation == "vibe" then + _99.open_qfix_for_request(r) + elseif r.operation == "tutorial" then + _99.open_tutorial(r) + end + end) end --- @param opts? _99.ops.Opts @@ -380,36 +386,15 @@ function _99.visual(opts) return context.xid end ---- View all the logs that are currently cached. Cached log count is determined ---- by _99.Logger.Options that are passed in. function _99.view_logs() - _99_state.__view_log_idx = 1 - local logs = Logger.logs() - if #logs == 0 then - print("no logs to display") - return - end - Window.display_full_screen_message(logs[1]) -end - -function _99.prev_request_logs() - local logs = Logger.logs() - if #logs == 0 then - print("no logs to display") - return - end - _99_state.__view_log_idx = math.min(_99_state.__view_log_idx + 1, #logs) - Window.display_full_screen_message(logs[_99_state.__view_log_idx]) -end - -function _99.next_request_logs() - local logs = Logger.logs() - if #logs == 0 then - print("no logs to display") - return - end - _99_state.__view_log_idx = math.max(_99_state.__view_log_idx - 1, 1) - Window.display_full_screen_message(logs[_99_state.__view_log_idx]) + local requests = _99_state.tracking.history + capture_request(requests, function(r) + local logs = Logger.logs_by_id(r.xid) + if logs == nil then + logs = { "No logs found for request: " .. r.xid } + end + Window.display_full_screen_message(logs) + end) end --- @param request _99.Prompt diff --git a/lua/99/logger/logger.lua b/lua/99/logger/logger.lua index 003aab2..e9a11c8 100644 --- a/lua/99/logger/logger.lua +++ b/lua/99/logger/logger.lua @@ -277,6 +277,12 @@ function Logger.logs() return out end +--- @param xid number +--- @return string[] | nil +function Logger.logs_by_id(xid) + return logger_cache[xid] +end + --- @param level number ---@param msg string ---@param ... any diff --git a/lua/99/state/tracking.lua b/lua/99/state/tracking.lua index bfeb430..220681d 100644 --- a/lua/99/state/tracking.lua +++ b/lua/99/state/tracking.lua @@ -197,4 +197,14 @@ function Tracking.setup(opts) end end +--- @param requests _99.Prompt[] +--- @return string[] +function Tracking.to_selectable_list(requests) + local str_requests = {} + for i, r in ipairs(requests) do + table.insert(str_requests, string.format("%d: %s", i, r:summary())) + end + return str_requests +end + return Tracking -- cgit v1.3-3-g829e