diff --git a/renderer.lua b/renderer.lua index cd21d7d..55ab68c 100644 --- a/renderer.lua +++ b/renderer.lua @@ -107,4 +107,55 @@ function M.tool_call_end(content, is_error) end end +-- Phase 3: Norris autonomous mode frames. Banner-style on enter/exit, +-- step counter per iteration, red HALT banner when the destructive-op +-- gate fires. The interactive prompt also gets a ⚡ marker when Norris +-- is active (handled in repl.lua's prompt() function per PHASE0.md §9). +-- See docs/PHASE3.md §3 renderer row. + +function M.norris_begin(goal) + emit(A.bold, A.cyan, "─── NORRIS MODE ─────────────────────────", + A.reset, "\n") + if goal and goal ~= "" then + emit(A.dim, " goal: ", A.reset, goal, "\n") + end + emit(A.bold, A.cyan, "─────────────────────────────────────────", + A.reset, "\n") +end + +function M.norris_step(n, max_n, descr) + emit(A.dim, (" ─ step %d/%d ─ "):format(n, max_n), A.reset) + if descr and descr ~= "" then emit(A.dim, descr, A.reset) end + emit("\n") +end + +function M.norris_halt(step_n, max_n, reason, action) + emit(A.bold, A.red, "─── NORRIS HALT ──────────────────────────", + A.reset, "\n") + emit(A.dim, " step: ", A.reset, ("%d/%d"):format(step_n, max_n), "\n") + emit(A.dim, " reason: ", A.reset, A.red, tostring(reason), A.reset, "\n") + -- action may be a long string (command line or JSON-serialized tool call); + -- truncate at 400 chars to keep the banner readable + local act = tostring(action or ""):gsub("\n", " ") + if #act > 400 then act = act:sub(1, 397) .. "..." end + emit(A.dim, " action: ", A.reset, act, "\n") + emit(A.bold, A.red, "──────────────────────────────────────────", + A.reset, "\n") +end + +-- Norris loop exit. status ∈ {"done", "aborted", "budget_exhausted", +-- "stalled", "broker_error"}. +function M.norris_end(status, reason) + local color = (status == "done") and A.cyan or A.red + local label = status:upper():gsub("_", " ") + emit(A.bold, color, "─── NORRIS ", label, " ──", + (" "):rep(math.max(0, 28 - #label)), + A.reset, "\n") + if reason and reason ~= "" then + emit(A.dim, " ", reason, A.reset, "\n") + end + emit(A.bold, color, "──────────────────────────────────────────", + A.reset, "\n") +end + return M