Skip to main content

Module command_log

Module command_log 

Source
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§

CommandLog
Bounded FIFO ring of CommandLogEntry. Pure state — no global, no I/O — so its push/evict/snapshot contract is unit-testable in isolation.
CommandLogEntry
One executed command in the transcript: the resolved command line, how long it took, how it finished, and its captured (bounded) output.

Enums§

CommandStatus
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 history is 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 raw Output exactly as Command::output would.
snapshot
Oldest-first snapshot of the global log. Returns empty on a poisoned lock rather than panicking.