feat(session): live marker, lastActivity, self fields; details on ⌘→

Merged
GR
3d ago
+730-101

Summary

Three gaps found while first using the codev session command-line interface (CLI), batched in one pull request (PR), plus a key change for the session details panel. Version 1.0.99.

1. Which sessions are running (list, show). Every session in the JSON now carries live, and pid and status (busy / idle) when it is running. list --live shows only running sessions (all of them, not the newest 30); list --not-live shows the rest. Data comes from each account's sessions/<pid>.json, the same registration self already reads (src/cli/session-self.ts), now read for every pid with one ps call.

  • A session counts as running only when its pid is alive and the process started at the time the file states (procStart), so a leftover file whose pid was reused does not count. A file with no procStart (older Claude Code) does not count either, the same rule self's proofFor applies.
  • Running sessions that history.jsonl does not have (a fresh /branch copy before its first prompt) are now listed, shown and resumable too.
  • --pretty gains a LIVE column, and its legend always explains ✗ (transcript gone, cannot be resumed). It was read as "not running" before.

2. lastActivity. lastActive is the last prompt: history.jsonl records only what the user types. So a session that worked for two hours after one prompt still showed the prompt time. lastActivity is the later of that and the last timestamped record in the transcript, read by scanning back from the end of the file (shared with view's reader). lastActive is unchanged.

  • Why "the later of": one real session had a prompt in history.jsonl 16 hours after the last record in its transcript, so the transcript alone would show activity older than the last prompt.
  • A transcript usually ends in records that carry no timestamp (cost-state, bridge-session, custom-title, …). The scan skips them and reads only a record's own top-level timestamp.

3. self JSON now has lastActive, promptCount, lastActivity and live: true. self --pretty already printed the first two.

4. Details panel under a row: ⌘→ opens, ⌘← closes (Esc too). ⌘↓ / ⌘↑ still work. ↑ / ↓ move between sessions, so the same arrows with ⌘ doing something else felt wrong. In the search box, ⌘→ keeps its usual "caret to the end" job until the caret is at the end, and only then opens the panel. Settings → Shortcuts gets a Selected Session section (⌘→ / ←, ⌘I, ⌘⇧C, right-click). None of these keys were listed anywhere in the app.

Measured

  • list --live on a machine with two accounts listed 29 running sessions, the same count as the registration files whose process is alive.
  • list --all over 844 sessions: 0.95 s → 1.45 s (reading each transcript's tail, plus one ps).
  • macOS ps -p fails the whole call, printing nothing, when one pid is out of range (process id too large). Without a fallback, one odd file name would show every session as stopped. A real-ps test caught this; the reader now retries one pid at a time.

Tests

  • 141 CLI tests pass (yarn vitest run src/cli); tsc --noEmit is clean; the CLI also compiles with the packaging tsc flags (--target es2020) and runs.
  • New tests: the live marker with a reused pid, --live / --not-live, a running session that is not in history, lastActivity vs lastActive, the --pretty legend, self's new fields, isLive, registrationFrom, readProcesses against the real ps, and readLastActivity at chunk sizes that split lines.
  • Mutation-checked: removing the start-time comparison, restoring the executable-name fallback for a file with no procStart, removing the "later of" rule, and removing the --not-live filter each turn tests red.
  • Follow-up: #175. The Sessions tab and this CLI use different rules for "running"; that issue proposes making them one.
  • The CLI tests inject the process lookup, so a fixture pid can never match a real process on the test machine.
  • The ⌘→ / ⌘← change has no automated test; the UI keys have none in this repo. A packaged 1.0.99 build is being tried by hand.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Session listings now identify currently running sessions, including sessions not yet present in history, and show last-prompt and last-activity times.
    • Added --live and --not-live filters, with updated default listing limits for live or path-based searches.
    • Updated session detail shortcuts and added selected-session shortcuts to the help panel.
  • Documentation
    • Updated session CLI, output fields, and keyboard shortcut guidance.
  • Chores
    • Updated the app version to 1.0.99.