Commit 2c9e0cc
Persist job logs, unified TUI log viewer, and test/prod isolation (#326)
## Summary
- **Job log persistence**: Write agent NDJSON output to per-job log
files on disk during execution for post-mortem debugging
(`internal/daemon/joblog.go`, `worker.go`)
- **Stream formatter**: Rich CLI rendering of NDJSON agent output with
colored tool call grouping, markdown text wrapping via glamour, and
Codex reasoning item display (`cmd/roborev/streamfmt.go`)
- **Unified TUI log viewer**: View agent logs for any job state
(running, completed, failed) in the TUI using the same `streamFormatter`
as the CLI. Replaces the previous tail-only view with full log
rendering, left/right navigation between jobs, and live polling for
running jobs
- **`/api/job/log` endpoint**: Serves raw NDJSON from disk log files,
with startup-race handling for running jobs that haven't written output
yet
- **Test/prod isolation**: Fix test suite pollution of production
`~/.roborev/activity.log` and daemon takeover by `go run` binaries. Add
`ProdLogBarrier` hard test barrier that fails the suite if test activity
leaks into production logs
## Changes
### Job log persistence
- `internal/daemon/joblog.go`: `JobLogPath`, `OpenJobLog`,
`CleanJobLogs` for per-job NDJSON files in `~/.roborev/logs/`
- `internal/daemon/worker.go`: Tee agent output to disk log during
execution
- `cmd/roborev/log_cmd.go`: CLI `roborev log <id>` with `--raw` and
`--path` flags, `roborev log clean` for manual cleanup
### Stream formatter
- `cmd/roborev/streamfmt.go`: Gutter-grouped tool calls (cyan name, dim
args), markdown text via glamour, Codex reasoning items (dimmed italic),
configurable width for TUI use
- `cmd/roborev/log_cmd.go`: `renderJobLog` pipes NDJSON through
`streamFormatter`, preserves non-JSON lines (stderr/diagnostics) in all
positions
### TUI log viewer
- `cmd/roborev/tui.go`: `fetchJobLog` fetches raw NDJSON from
`/api/job/log`, renders through `streamFormatter`, displays with
scroll/follow. `logVisibleLines()` centralizes viewport calculation
accounting for optional command-line header
- `cmd/roborev/tui_handlers.go`: `l` key opens log for any job state,
left/right navigation between jobs, pgup/pgdown/home/end/g scroll
controls
- Nil vs empty `logLines` semantics: nil = "Waiting for output...",
empty = "(no output)"
- Failed jobs with no log file show stored error in flash message
### `/api/job/log` endpoint
- `internal/daemon/server.go`: `handleJobLog` serves raw NDJSON with
`X-Job-Status` header. Returns empty 200 for running jobs with no log
file yet (startup race)
### Test/prod isolation
- `internal/daemon/testmain_test.go`: `TestMain` sets `ROBOREV_DATA_DIR`
to temp dir, preventing `NewServer` from writing to prod logs
- `testmain_test.go`: Root package `TestMain` isolates `e2e_test.go`
- `cmd/roborev/main.go`: `shouldRefuseAutoStartDaemon` rejects go-build
cache binaries (from `go run`) that would kill the prod daemon via
version-mismatch restart
- `internal/testenv/barrier.go`: `ProdLogBarrier` snapshots prod log
sizes before tests, scans new lines after for test markers
(`event:"test"`, `version:"dev"` daemon starts, test PID runtime files).
Runs in `TestMain` of all three packages that create `daemon.Server`
## Test plan
- [x] `go test ./...` passes with zero prod log pollution
- [x] `ProdLogBarrier` unit tests verify detection of all pollution
types
- [x] Mixed JSON/plain-text log rendering preserves correct ordering
- [x] TUI log view errNoLog flash shows job error for failed jobs
- [x] Running job empty fetch keeps "Waiting for output..." visible
- [x] `logVisibleLines()` accounts for command-line header
- [x] Paging keys use consistent viewport calculation
- [x] Stream formatter handles Codex reasoning items
- [x] Left/right navigation follows global direction convention
- [x] EPIPE handling for piped output
- [x] Running job with no log file returns empty 200
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 39906d4 commit 2c9e0cc
24 files changed
Lines changed: 3906 additions & 339 deletions
File tree
- cmd/roborev
- internal
- daemon
- testenv
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
0 commit comments