Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ directories = "6.0.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
toml = "0.8"
unicode-width = "0.2"

[[bin]]
name = "tmux-deck"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Monitoring multi session Realtime preview.
- 📄 Easy management Windows and Panes between Sessions
- 👀 Realtime Preview
- 🤖 Claude Code status markers (working / waiting / done) driven by hooks
- 🛰️ Claude agent view (`d`): lists Claude Code background sessions (`claude agents`) grouped by directory — state, name, summary, PRs, elapsed. `Enter` attaches via `claude attach`, `p` toggles a transcript preview, `s` generates an execution summary (`claude -p`)
- 🛰️ Claude agent view (`d`): lists Claude Code background sessions (`claude agents`) grouped by directory — state, name, summary, PRs, elapsed. `Enter` attaches via `claude attach`, `p` toggles a preview (`v` switches transcript ↔ reconstructed screen), `s` generates an execution summary (`claude -p`)
- ⚙️ Easy Configure

# Quick Start
Expand Down
4 changes: 4 additions & 0 deletions docs/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ interval = 50
# selected background session in the agent view (press `s`). Accepts any
# `claude --model` value: an alias (haiku / sonnet / opus) or a full model id.
summary_model = "haiku"
# Default preview mode in the agent view (`p`): "transcript" reconstructs the
# conversation; "screen" reconstructs the terminal screen from `claude logs`.
# Toggle at runtime with `v`.
preview_mode = "transcript"

# -----------------------------------------------------------------------------
[theme]
Expand Down
70 changes: 68 additions & 2 deletions src/actor/ui_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ pub struct UIActor {
/// Results of background `claude -p` summary jobs: (session id, Ok(text)/Err).
agent_summary_tx: mpsc::Sender<(String, Result<String, String>)>,
agent_summary_rx: mpsc::Receiver<(String, Result<String, String>)>,
/// Results of background `claude logs` fetches for the screen preview.
agent_logs_tx: mpsc::Sender<(String, Vec<u8>)>,
agent_logs_rx: mpsc::Receiver<(String, Vec<u8>)>,
/// Sessions whose `claude logs` fetch is in flight, and when each id was
/// last fetched (to throttle refresh).
logs_inflight: std::collections::HashSet<String>,
logs_fetched_at: std::collections::HashMap<String, std::time::Instant>,
}

impl UIActor {
Expand All @@ -72,6 +79,7 @@ impl UIActor {
spawn_key_event_poller(key_tx);

let (agent_summary_tx, agent_summary_rx) = mpsc::channel(8);
let (agent_logs_tx, agent_logs_rx) = mpsc::channel(8);

Self {
terminal,
Expand All @@ -84,6 +92,10 @@ impl UIActor {
refresh_control,
agent_summary_tx,
agent_summary_rx,
agent_logs_tx,
agent_logs_rx,
logs_inflight: std::collections::HashSet::new(),
logs_fetched_at: std::collections::HashMap::new(),
}
}

Expand Down Expand Up @@ -122,6 +134,13 @@ impl UIActor {
self.state.set_summary_result(id, result);
}

// Completed `claude logs` fetches for the screen preview.
Some((id, bytes)) = self.agent_logs_rx.recv() => {
self.logs_inflight.remove(&id);
self.logs_fetched_at.insert(id.clone(), std::time::Instant::now());
self.state.update_agent_logs(id, bytes);
}

// TmuxActor responses
Some(response) = self.tmux_res_rx.recv() => {
self.handle_tmux_response(response);
Expand All @@ -148,8 +167,13 @@ impl UIActor {
.await;
}
}
// The agent view reloads background sessions from disk.
ViewMode::Dashboard => self.state.refresh_agents(),
// The agent view reloads background sessions from
// disk and, in screen-preview mode, refreshes the
// selected session's `claude logs`.
ViewMode::Dashboard => {
self.state.refresh_agents();
self.maybe_fetch_logs();
}
ViewMode::MultiPreview => {}
}
}
Expand Down Expand Up @@ -365,6 +389,10 @@ impl UIActor {
self.state.toggle_agent_preview();
return Ok(false);
}
KeyCode::Char('v') if self.state.view_mode == ViewMode::Dashboard => {
self.state.cycle_preview_mode();
return Ok(false);
}
KeyCode::Char('s') if self.state.view_mode == ViewMode::Dashboard => {
self.state.open_agent_summary();
self.request_agent_summary();
Expand Down Expand Up @@ -513,6 +541,44 @@ impl UIActor {
Ok(())
}

/// In screen-preview mode, fetch the selected session's `claude logs`
/// output in the background, throttled per session. No-op unless the
/// preview is open in screen mode.
fn maybe_fetch_logs(&mut self) {
if !self.state.agent_preview
|| self.state.agent_preview_mode != crate::app::PreviewMode::Screen
{
return;
}
let Some(session) = self.state.selected_agent() else {
return;
};
let id = session.id.clone();
if self.logs_inflight.contains(&id) {
return;
}
// Throttle: refetch a given session at most every ~3s.
let fresh = self
.logs_fetched_at
.get(&id)
.is_some_and(|t| t.elapsed() < Duration::from_secs(3));
if fresh {
return;
}
self.logs_inflight.insert(id.clone());
let tx = self.agent_logs_tx.clone();
tokio::spawn(async move {
let bytes = tokio::process::Command::new("claude")
.arg("logs")
.arg(&id)
.output()
.await
.map(|o| o.stdout)
.unwrap_or_default();
let _ = tx.send((id, bytes)).await;
});
}

/// Kick off an execution summary for the selected background session by
/// running `claude -p` (stateless, against a transcript digest) in a
/// background task. The result is delivered over `agent_summary_rx`.
Expand Down
54 changes: 52 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@ use crate::config::{
};
use crate::group::GroupStore;

/// How the agent-view preview panel renders the selected session.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PreviewMode {
/// Reconstructed conversation from the transcript JSONL (fast, plain).
Transcript,
/// Reconstructed terminal screen from `claude logs` (faithful, heavier).
Screen,
}

impl PreviewMode {
pub fn from_str(s: &str) -> Self {
match s {
"screen" => Self::Screen,
_ => Self::Transcript,
}
}

pub fn label(self) -> &'static str {
match self {
Self::Transcript => "transcript",
Self::Screen => "screen",
}
}
}

/// State of an on-demand execution summary for a background session.
#[derive(Debug, Clone)]
pub enum SummaryStatus {
Expand Down Expand Up @@ -435,12 +460,17 @@ pub struct UIState {
/// Set to a session id when the user asks to attach; the UI loop consumes it
/// to run `claude attach <id>` and clears it.
pub pending_attach: Option<String>,
/// Whether the agent-view transcript preview panel is shown (`p`).
/// Whether the agent-view preview panel is shown (`p`).
pub agent_preview: bool,
/// How the preview renders (transcript vs screen); toggled with `v`.
pub agent_preview_mode: PreviewMode,
/// Whether the execution-summary popup is open (`s`); independent of preview.
pub agent_summary_open: bool,
/// On-demand execution summaries, keyed by session short id.
pub agent_summaries: HashMap<String, SummaryStatus>,
/// Cached `claude logs` output (raw PTY bytes) per session id, for the
/// screen preview mode.
pub agent_logs: HashMap<String, Vec<u8>>,
/// Agent-view config (e.g. summary model).
pub agents_config: AgentsConfig,

Expand Down Expand Up @@ -509,8 +539,10 @@ impl UIState {
agent_selected: 0,
pending_attach: None,
agent_preview: false,
agent_preview_mode: PreviewMode::from_str(&config.agents.preview_mode),
agent_summary_open: false,
agent_summaries: HashMap::new(),
agent_logs: HashMap::new(),
agents_config: config.agents,

pane_content: String::new(),
Expand Down Expand Up @@ -646,11 +678,29 @@ impl UIState {
self.agent_sessions.get(self.agent_selected)
}

/// Toggle the transcript preview panel for the selected session.
/// Toggle the preview panel for the selected session.
pub fn toggle_agent_preview(&mut self) {
self.agent_preview = !self.agent_preview;
}

/// Switch the preview between transcript and screen rendering (`v`).
pub fn cycle_preview_mode(&mut self) {
self.agent_preview_mode = match self.agent_preview_mode {
PreviewMode::Transcript => PreviewMode::Screen,
PreviewMode::Screen => PreviewMode::Transcript,
};
}

/// Store freshly fetched `claude logs` output for the screen preview.
pub fn update_agent_logs(&mut self, id: String, bytes: Vec<u8>) {
self.agent_logs.insert(id, bytes);
}

/// Cached `claude logs` bytes for a session, if fetched.
pub fn agent_logs_for(&self, id: &str) -> Option<&Vec<u8>> {
self.agent_logs.get(id)
}

/// Open the execution-summary popup (independent of the preview panel).
pub fn open_agent_summary(&mut self) {
self.agent_summary_open = true;
Expand Down
5 changes: 5 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,17 @@ pub struct AgentsConfig {
/// selected background session (agent view, `s`). Accepts a `claude`
/// `--model` value such as an alias (`haiku`, `sonnet`, `opus`) or a full id.
pub summary_model: String,
/// Default preview mode in the agent view: `transcript` (reconstructed
/// conversation) or `screen` (reconstructed terminal screen via
/// `claude logs`). Toggle at runtime with `v`.
pub preview_mode: String,
}

impl Default for AgentsConfig {
fn default() -> Self {
Self {
summary_model: "haiku".to_string(),
preview_mode: "transcript".to_string(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod cli;
mod config;
mod group;
mod hook;
mod termscreen;
mod ui;

use std::io;
Expand Down
Loading