Expand description
In-memory transcript of the external commands gwm runs (issue #226).
gwm shells out to gh (GitHub status), bootstrap shell steps, and
lifecycle hooks. The single-line statusbar action log (#217) shows only
the most recent action and is ephemeral; this module keeps a bounded,
scrollable history behind the lazygit-style Command Logs modal.
§Why a process-global ring
The exec chokepoints live in library modules with no App handle
(github::run_gh_with runs on a worker thread, #217), so the sink has
to be reachable without threading a logger through every call site. A
LazyLock<Mutex<…>> ring mirrors the existing static caches
(naming’s compiled regexes, the recent-commits cache) and tolerates
cross-thread writes from the off-thread GitHub fetch.
The TUI never renders straight off this global: App takes a
snapshot into state::command_logs so the modal renders from owned
App state. That keeps the render path testable without the global and
is the boundary the modal-render tests inject through.
§Scope (deliberately narrow for the first cut)
Only the captured-output shell commands are logged: gh, bootstrap
steps, hooks, and the user-triggered mutating git ops (pull, push,
sync’s fetch/rebase/merge, and the rename steps — #290). The
read-only sidebar previews (worktree::run_git for git log /
git status) are not — they fire on every selection change and would
bury the real operations in noise (the mutating sync steps go through the
logged run_git_logged sibling
instead). Interactive launchers (.status() / .spawn(), which inherit
the terminal and have no captured output) and the libgit2 worktree ops
(which run no subprocess) are out of scope here.
Structs§
- Command
Log - Bounded FIFO ring of
CommandLogEntry. Pure state — no global, no I/O — so its push/evict/snapshot contract is unit-testable in isolation. - Command
LogEntry - One executed command in the transcript: the resolved command line, how long it took, how it finished, and its captured (bounded) output.
Enums§
- Command
Status - How a logged command finished.
Constants§
- MAX_
ENTRIES - Upper bound on retained entries. Old entries are evicted FIFO once the
ring is full — a transcript, not an audit trail (the operation journal
behind
gwm undo/gwm historyis the durable record).
Functions§
- record
- Record a finished command on the global log. Lock-poison-safe: a poisoned mutex drops the entry rather than panicking — logging must never take down a real operation.
- reset
- Clear the global log. Used by the (future) in-TUI “clear logs” action and by tests that need a clean slate.
- run_
logged - Run
cmd, recording an entry on the global log, and return the rawOutputexactly asCommand::outputwould. - snapshot
- Oldest-first snapshot of the global log. Returns empty on a poisoned lock rather than panicking.