Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Redesign JSON output for wt list --format=json to be query-friendly
Maximilian Roos236eae81f8d4
diff --git a/docs/content/list.md b/docs/content/list.mdindex ec11d745a..5c2503627 100644--- a/docs/content/list.md+++ b/docs/content/list.md@@ -137,29 +137,41 @@ Query structured data with `--format=json`:```bash# Worktrees with conflicts-wt list --format=json | jq '.[] | select(.status.branch_state == "Conflicts")'+wt list --format=json | jq '.[] | select(.branch_state == "conflicts")'# Uncommitted changes-wt list --format=json | jq '.[] | select(.status.working_tree.modified)'+wt list --format=json | jq '.[] | select(.working_tree.modified)'# Current worktree-wt list --format=json | jq '.[] | select(.is_current == true)'+wt list --format=json | jq '.[] | select(.is_current)'# Branches ahead of main-wt list --format=json | jq '.[] | select(.status.main_divergence == "Ahead")'+wt list --format=json | jq '.[] | select(.main.ahead > 0)'++# Integrated branches (ready to clean up)+wt list --format=json | jq '.[] | select(.branch_state == "integrated" or .branch_state == "same_commit")'```-**Status fields:**-- `working_tree`: `{untracked, modified, staged, renamed, deleted}`-- `branch_state`: `""` | `"Conflicts"` | `"MergeTreeConflicts"` | `"TreesMatch"` | `"NoAddedChanges"` | `"MergeAddsNothing"`-- `git_operation`: `""` | `"Rebase"` | `"Merge"`-- `main_divergence`: `""` | `"Ahead"` | `"Behind"` | `"Diverged"`-- `upstream_divergence`: `""` | `"Ahead"` | `"Behind"` | `"Diverged"`--**Position fields:**-- `is_main` — Main worktree-- `is_current` — Current directory-- `is_previous` — Previous worktree from [wt switch](@/switch.md)+**Fields:**++| Field | Description |+|-------|-------------|+| `branch` | Branch name (null for detached HEAD) |+| `path` | Worktree path (absent for branches without worktrees) |+| `kind` | `"worktree"` or `"branch"` |+| `commit` | `{sha, short_sha, message, timestamp}` |+| `working_tree` | `{staged, modified, untracked, renamed, deleted, diff, diff_vs_main}` |+| `branch_state` | `"conflicts"` `"rebase"` `"merge"` `"would_conflict"` `"same_commit"` `"integrated"` |+| `integration_reason` | `"trees_match"` `"no_added_changes"` `"merge_adds_nothing"` (when `branch_state == "integrated"`) |+| `main` | `{ahead, behind, diff}` (absent when `is_main`) |+| `remote` | `{name, branch, ahead, behind}` (absent when no tracking branch) |+| `worktree` | `{state, reason, detached, bare}` |+| `is_main` | Main worktree |+| `is_current` | Current worktree |+| `is_previous` | Previous worktree from [wt switch](@/switch.md) |+| `pr` | `{ci, source, stale, url}` — CI status from PR or branch (absent when no CI) |+| `statusline` | Pre-formatted status with ANSI colors |+| `symbols` | Raw status symbols without colors (e.g., `"!?↓"`) |## See alsodiff --git a/src/cli.rs b/src/cli.rsindex 34752b3ea..9b48e8d2c 100644--- a/src/cli.rs+++ b/src/cli.rs@@ -1410,29 +1410,41 @@ Query structured data with `--format=json`:```console# Worktrees with conflicts-wt list --format=json | jq '.[] | select(.status.branch_state == "Conflicts")'+wt list --format=json | jq '.[] | select(.branch_state == "conflicts")'# Uncommitted changes-wt list --format=json | jq '.[] | select(.status.working_tree.modified)'+wt list --format=json | jq '.[] | select(.working_tree.modified)'# Current worktree-wt list --format=json | jq '.[] | select(.is_current == true)'+wt list --format=json | jq '.[] | select(.is_current)'# Branches ahead of main-wt list --format=json | jq '.[] | select(.status.main_divergence == "Ahead")'-```--**Status fields:**-- `working_tree`: `{untracked, modified, staged, renamed, deleted}`-- `branch_state`: `""` | `"Conflicts"` | `"MergeTreeConflicts"` | `"TreesMatch"` | `"NoAddedChanges"` | `"MergeAddsNothing"`-- `git_operation`: `""` | `"Rebase"` | `"Merge"`-- `main_divergence`: `""` | `"Ahead"` | `"Behind"` | `"Diverged"`-- `upstream_divergence`: `""` | `"Ahead"` | `"Behind"` | `"Diverged"`--**Position fields:**-- `is_main` — Main worktree-- `is_current` — Current directory-- `is_previous` — Previous worktree from [wt switch](@/switch.md)+wt list --format=json | jq '.[] | select(.main.ahead > 0)'++# Integrated branches (ready to clean up)+wt list --format=json | jq '.[] | select(.branch_state == "integrated" or .branch_state == "same_commit")'+```++**Fields:**++| Field | Description |+|-------|-------------|+| `branch` | Branch name (null for detached HEAD) |+| `path` | Worktree path (absent for branches without worktrees) |+| `kind` | `"worktree"` or `"branch"` |+| `commit` | `{sha, short_sha, message, timestamp}` |+| `working_tree` | `{staged, modified, untracked, renamed, deleted, diff, diff_vs_main}` |+| `branch_state` | `"conflicts"` `"rebase"` `"merge"` `"would_conflict"` `"same_commit"` `"integrated"` |+| `integration_reason` | `"trees_match"` `"no_added_changes"` `"merge_adds_nothing"` (when `branch_state == "integrated"`) |+| `main` | `{ahead, behind, diff}` (absent when `is_main`) |+| `remote` | `{name, branch, ahead, behind}` (absent when no tracking branch) |+| `worktree` | `{state, reason, detached, bare}` |+| `is_main` | Main worktree |+| `is_current` | Current worktree |+| `is_previous` | Previous worktree from [wt switch](@/switch.md) |+| `pr` | `{ci, source, stale, url}` — CI status from PR or branch (absent when no CI) |+| `statusline` | Pre-formatted status with ANSI colors |+| `symbols` | Raw status symbols without colors (e.g., `"!?↓"`) |## See alsodiff --git a/src/commands/list/ci_status.rs b/src/commands/list/ci_status.rsindex ee9af9336..216720f8e 100644--- a/src/commands/list/ci_status.rs+++ b/src/commands/list/ci_status.rs@@ -213,13 +213,13 @@ pub enum CiSource {Branch,}-/// PR/MR status including CI state and staleness+/// CI status from PR/MR or branch workflow#[derive(Debug, Clone, Serialize, Deserialize)]pub struct PrStatus {pub ci_status: CiStatus,/// Source of the CI status (PR/MR or branch workflow)pub source: CiSource,- /// True if local HEAD differs from PR HEAD (unpushed changes)+ /// True if local HEAD differs from remote HEAD (unpushed changes)pub is_stale: bool,/// URL to the PR/MR (if available)#[serde(skip_serializing_if = "Option::is_none")]diff --git a/src/commands/list/collect.rs b/src/commands/list/collect.rsindex e15cc5519..046b26b38 100644--- a/src/commands/list/collect.rs+++ b/src/commands/list/collect.rs@@ -30,11 +30,13 @@ use super::model::{ListItem, UpstreamStatus, WorktreeData,};+use super::model::WorkingTreeStatus;+/// Context for status symbol computation during result processingstruct StatusContext {has_merge_tree_conflicts: bool,user_marker: Option<String>,- working_tree_symbols: Option<String>,+ working_tree_status: Option<WorkingTreeStatus>,has_conflicts: bool,}@@ -89,13 +91,13 @@ pub(super) enum TaskResult {item_idx: usize,branch_diff: BranchDiffTotals,},- /// Working tree diff and symbols (?, !, +, », ✘)+ /// Working tree diff and statusWorkingTreeDiff {item_idx: usize,working_tree_diff: LineDiff,working_tree_diff_with_main: Option<LineDiff>,- /// Symbols for uncommitted changes (?, !, +, », ✘)- working_tree_symbols: String,+ /// Working tree change flags+ working_tree_status: WorkingTreeStatus,has_conflicts: bool,},/// Potential merge conflicts with main (merge-tree simulation)@@ -242,7 +244,7 @@ fn drain_results(.map(|_| StatusContext {has_merge_tree_conflicts: false,user_marker: None,- working_tree_symbols: None,+ working_tree_status: None,has_conflicts: false,}).collect();@@ -345,7 +347,7 @@ fn drain_results(item_idx,working_tree_diff,working_tree_diff_with_main,- working_tree_symbols,+ working_tree_status,has_conflicts,} => {if let ItemKind::Worktree(data) = &mut items[item_idx].kind {@@ -353,7 +355,7 @@ fn drain_results(data.working_tree_diff_with_main = Some(working_tree_diff_with_main);}// Store for status_symbols computation- status_contexts[item_idx].working_tree_symbols = Some(working_tree_symbols);+ status_contexts[item_idx].working_tree_status = Some(working_tree_status);status_contexts[item_idx].has_conflicts = has_conflicts;}TaskResult::MergeTreeConflicts {@@ -793,7 +795,7 @@ pub fn collect(item_default_branch,ctx.has_merge_tree_conflicts,ctx.user_marker.clone(),- ctx.working_tree_symbols.as_deref(),+ ctx.working_tree_status,ctx.has_conflicts,);@@ -1075,7 +1077,7 @@ pub fn populate_items(item_default_branch,ctx.has_merge_tree_conflicts,ctx.user_marker.clone(),- ctx.working_tree_symbols.as_deref(),+ ctx.working_tree_status,ctx.has_conflicts,);});diff --git a/src/commands/list/collect_progressive_impl.rs b/src/commands/list/collect_progressive_impl.rsindex 528a5c670..d765a8f50 100644--- a/src/commands/list/collect_progressive_impl.rs+++ b/src/commands/list/collect_progressive_impl.rs@@ -30,7 +30,9 @@ use worktrunk::styling::warning_message;use super::ci_status::PrStatus;use super::collect::{ExpectedResults, TaskKind, TaskResult, detect_git_operation};-use super::model::{AheadBehind, BranchDiffTotals, CommitDetails, UpstreamStatus};+use super::model::{+ AheadBehind, BranchDiffTotals, CommitDetails, UpstreamStatus, WorkingTreeStatus,+};// ============================================================================// Options and Context@@ -342,7 +344,7 @@ impl Task for BranchDiffTask {}}-/// Task 5 (worktree only): Working tree diff + status symbols+/// Task 5 (worktree only): Working tree diff + status flagspub struct WorkingTreeDiffTask;impl Task for WorkingTreeDiffTask {@@ -358,14 +360,14 @@ impl Task for WorkingTreeDiffTask {item_idx: ctx.item_idx,working_tree_diff: LineDiff::default(),working_tree_diff_with_main: None,- working_tree_symbols: String::new(),+ working_tree_status: WorkingTreeStatus::default(),has_conflicts: false,};}};- let (working_tree_symbols, is_dirty, has_conflicts) =- parse_status_for_symbols(&status_output);+ let (working_tree_status, is_dirty, has_conflicts) =+ parse_working_tree_status(&status_output);let working_tree_diff = if is_dirty {repo.working_tree_diff_stats().unwrap_or_default()@@ -382,7 +384,7 @@ impl Task for WorkingTreeDiffTask {item_idx: ctx.item_idx,working_tree_diff,working_tree_diff_with_main,- working_tree_symbols,+ working_tree_status,has_conflicts,}}@@ -643,9 +645,9 @@ pub fn collect_branch_progressive(// Helper Functions// ============================================================================-/// Parse git status output to extract working tree symbols and conflict state.-/// Returns (symbols, is_dirty, has_conflicts).-fn parse_status_for_symbols(status_output: &str) -> (String, bool, bool) {+/// Parse git status output to extract working tree status and conflict state.+/// Returns (WorkingTreeStatus, is_dirty, has_conflicts).+fn parse_working_tree_status(status_output: &str) -> (WorkingTreeStatus, bool, bool) {let mut has_untracked = false;let mut has_modified = false;let mut has_staged = false;@@ -695,23 +697,17 @@ fn parse_status_for_symbols(status_output: &str) -> (String, bool, bool) {}}- // Build working tree string (priority order: staged > modified > untracked)- // Only show top 3 most actionable symbols to save space- // Renamed (») and deleted (✘) are still detected for is_dirty but not displayed- let mut working_tree = String::new();- if has_staged {- working_tree.push('+');- }- if has_modified {- working_tree.push('!');- }- if has_untracked {- working_tree.push('?');- }+ let working_tree_status = WorkingTreeStatus::new(+ has_staged,+ has_modified,+ has_untracked,+ has_renamed,+ has_deleted,+ );- let is_dirty = has_untracked || has_modified || has_staged || has_renamed || has_deleted;+ let is_dirty = working_tree_status.is_dirty();- (working_tree, is_dirty, has_conflicts)+ (working_tree_status, is_dirty, has_conflicts)}#[cfg(test)]@@ -721,16 +717,16 @@ mod tests {#[test]fn test_parse_status_ad_not_conflict() {// AD = added to index, deleted from worktree (not a conflict)- let (symbols, is_dirty, has_conflicts) = parse_status_for_symbols("AD file.txt\n");+ let (status, is_dirty, has_conflicts) = parse_working_tree_status("AD file.txt\n");assert!(!has_conflicts, "AD should not be treated as conflict");assert!(is_dirty);- assert!(symbols.contains('+'), "AD should show staged symbol");+ assert!(status.staged, "AD should show staged symbol");}#[test]fn test_parse_status_da_not_conflict() {// DA = deleted from index, then restored to worktree (not a conflict)- let (_, is_dirty, has_conflicts) = parse_status_for_symbols("DA file.txt\n");+ let (_, is_dirty, has_conflicts) = parse_working_tree_status("DA file.txt\n");assert!(!has_conflicts, "DA should not be treated as conflict");assert!(is_dirty);}@@ -738,21 +734,21 @@ mod tests {#[test]fn test_parse_status_uu_is_conflict() {// UU = both modified (actual conflict)- let (_, _, has_conflicts) = parse_status_for_symbols("UU file.txt\n");+ let (_, _, has_conflicts) = parse_working_tree_status("UU file.txt\n");assert!(has_conflicts, "UU should be treated as conflict");}#[test]fn test_parse_status_aa_is_conflict() {// AA = both added (actual conflict)- let (_, _, has_conflicts) = parse_status_for_symbols("AA file.txt\n");+ let (_, _, has_conflicts) = parse_working_tree_status("AA file.txt\n");assert!(has_conflicts, "AA should be treated as conflict");}#[test]fn test_parse_status_dd_is_conflict() {// DD = both deleted (actual conflict)- let (_, _, has_conflicts) = parse_status_for_symbols("DD file.txt\n");+ let (_, _, has_conflicts) = parse_working_tree_status("DD file.txt\n");assert!(has_conflicts, "DD should be treated as conflict");}@@ -761,7 +757,7 @@ mod tests {// All U codes indicate conflictsfor code in ["AU", "UA", "DU", "UD"] {let input = format!("{} file.txt\n", code);- let (_, _, has_conflicts) = parse_status_for_symbols(&input);+ let (_, _, has_conflicts) = parse_working_tree_status(&input);assert!(has_conflicts, "{} should be treated as conflict", code);}}@@ -769,7 +765,7 @@ mod tests {#[test]fn test_parse_status_md_not_conflict() {// MD = modified in index, deleted from worktree (not a conflict)- let (_, is_dirty, has_conflicts) = parse_status_for_symbols("MD file.txt\n");+ let (_, is_dirty, has_conflicts) = parse_working_tree_status("MD file.txt\n");assert!(!has_conflicts, "MD should not be treated as conflict");assert!(is_dirty);}@@ -777,30 +773,24 @@ mod tests {#[test]fn test_parse_status_intent_to_add() {// " A" = intent-to-add (git add -N): file recorded but content not staged- let (symbols, is_dirty, has_conflicts) = parse_status_for_symbols(" A file.txt\n");+ let (status, is_dirty, has_conflicts) = parse_working_tree_status(" A file.txt\n");assert!(!has_conflicts,"intent-to-add should not be treated as conflict");assert!(is_dirty, "intent-to-add should be dirty");- assert!(- symbols.contains('!'),- "intent-to-add should show modified symbol"- );+ assert!(status.modified, "intent-to-add should show modified symbol");}#[test]fn test_parse_status_type_change() {// " T" = type change in worktree (e.g., file changed to symlink)- let (symbols, is_dirty, has_conflicts) = parse_status_for_symbols(" T file.txt\n");+ let (status, is_dirty, has_conflicts) = parse_working_tree_status(" T file.txt\n");assert!(!has_conflicts,"type change should not be treated as conflict");assert!(is_dirty, "type change should be dirty");- assert!(- symbols.contains('!'),- "type change should show modified symbol"- );+ assert!(status.modified, "type change should show modified symbol");}}diff --git a/src/commands/list/json_output.rs b/src/commands/list/json_output.rsnew file mode 100644index 000000000..7afc518f3--- /dev/null+++ b/src/commands/list/json_output.rs@@ -0,0 +1,462 @@+//! JSON output types for `wt list --format=json`+//!+//! This module defines the structured JSON output format, designed for:+//! - Query-friendly filtering with jq+//! - Self-describing field names+//! - Alignment with CLI status subcolumns+//!+//! ## Structure+//!+//! Fields are organized by concept, matching the status display subcolumns:+//! - `working_tree`: staged/modified/untracked changes+//! - `branch_state`: conflicts, rebase, merge, would_conflict, same_commit, integrated+//! - `main`: relationship to main branch (ahead/behind/diff)+//! - `remote`: relationship to tracking branch+//! - `worktree`: worktree-specific state (locked, prunable, etc.)++use std::path::PathBuf;++use serde::Serialize;+use worktrunk::git::LineDiff;++use super::ci_status::PrStatus;+use super::model::{ItemKind, ListItem, UpstreamStatus};++/// JSON output for a single list item+#[derive(Debug, Clone, Serialize)]+pub struct JsonItem {+ /// Branch name, null for detached HEAD+ pub branch: Option<String>,++ /// Filesystem path to the worktree+ #[serde(skip_serializing_if = "Option::is_none")]+ pub path: Option<PathBuf>,++ /// Item kind: "worktree" or "branch"+ pub kind: &'static str,++ /// Commit information+ pub commit: JsonCommit,++ /// Working tree state (staged, modified, untracked changes)+ #[serde(skip_serializing_if = "Option::is_none")]+ pub working_tree: Option<JsonWorkingTree>,++ /// Branch state: conflicts, rebase, merge, would_conflict, same_commit, integrated+ #[serde(skip_serializing_if = "Option::is_none")]+ pub branch_state: Option<&'static str>,++ /// Why branch is integrated (only present when branch_state == "integrated")+ /// Values: trees_match, no_added_changes, merge_adds_nothing+ #[serde(skip_serializing_if = "Option::is_none")]+ pub integration_reason: Option<&'static str>,++ /// Relationship to main branch (absent when is_main == true)+ #[serde(skip_serializing_if = "Option::is_none")]+ pub main: Option<JsonMain>,++ /// Relationship to remote tracking branch (absent when no tracking branch)+ #[serde(skip_serializing_if = "Option::is_none")]+ pub remote: Option<JsonRemote>,++ /// Worktree-specific state+ #[serde(skip_serializing_if = "Option::is_none")]+ pub worktree: Option<JsonWorktree>,++ /// This is the main worktree+ pub is_main: bool,++ /// This is the current worktree (matches $PWD)+ #[serde(skip_serializing_if = "std::ops::Not::not")]+ pub is_current: bool,++ /// This was the previous worktree (from wt switch)+ #[serde(skip_serializing_if = "std::ops::Not::not")]+ pub is_previous: bool,++ /// CI status from PR or branch workflow+ #[serde(skip_serializing_if = "Option::is_none")]+ pub pr: Option<JsonPr>,++ /// Pre-formatted statusline for statusline tools (tmux, starship)+ #[serde(skip_serializing_if = "Option::is_none")]+ pub statusline: Option<String>,++ /// Raw status symbols without ANSI colors (e.g., "+! ✖ ↑")+ #[serde(skip_serializing_if = "Option::is_none")]+ pub symbols: Option<String>,+}++/// Commit information+#[derive(Debug, Clone, Serialize)]+pub struct JsonCommit {+ /// Full commit SHA+ pub sha: String,++ /// Short commit SHA (7 characters)+ pub short_sha: String,++ /// Commit message (first line)+ pub message: String,++ /// Unix timestamp of commit+ pub timestamp: i64,+}++/// Working tree state+#[derive(Debug, Clone, Serialize)]+pub struct JsonWorkingTree {+ /// Has staged files (+)+ pub staged: bool,++ /// Has modified files (!)+ pub modified: bool,++ /// Has untracked files (?)+ pub untracked: bool,++ /// Has renamed files (»)+ pub renamed: bool,++ /// Has deleted files (✘)+ pub deleted: bool,++ /// Lines added/deleted in working tree vs HEAD+ #[serde(skip_serializing_if = "Option::is_none")]+ pub diff: Option<JsonDiff>,++ /// Lines added/deleted in working tree vs main branch+ #[serde(skip_serializing_if = "Option::is_none")]+ pub diff_vs_main: Option<JsonDiff>,+}++/// Line diff statistics+#[derive(Debug, Clone, Serialize)]+pub struct JsonDiff {+ pub added: usize,+ pub deleted: usize,+}++impl From<LineDiff> for JsonDiff {+ fn from(d: LineDiff) -> Self {+ Self {+ added: d.added,+ deleted: d.deleted,+ }+ }+}++/// Relationship to main branch+#[derive(Debug, Clone, Serialize)]+pub struct JsonMain {+ /// Commits ahead of main+ pub ahead: usize,++ /// Commits behind main+ pub behind: usize,++ /// Lines added/deleted vs main branch+ #[serde(skip_serializing_if = "Option::is_none")]+ pub diff: Option<JsonDiff>,+}++/// Relationship to remote tracking branch+#[derive(Debug, Clone, Serialize)]+pub struct JsonRemote {+ /// Remote name (e.g., "origin")+ pub name: String,++ /// Remote branch name (e.g., "feature-login")+ pub branch: String,++ /// Commits ahead of remote+ pub ahead: usize,++ /// Commits behind remote+ pub behind: usize,+}++/// Worktree-specific state+#[derive(Debug, Clone, Serialize)]+pub struct JsonWorktree {+ /// Worktree state: "no_worktree", "path_mismatch", "prunable", "locked" (absent when normal)+ #[serde(skip_serializing_if = "Option::is_none")]+ pub state: Option<&'static str>,++ /// Reason for locked/prunable state+ #[serde(skip_serializing_if = "Option::is_none")]+ pub reason: Option<String>,++ /// HEAD is detached (not on a branch)+ pub detached: bool,++ /// Bare repository+ pub bare: bool,+}++/// CI status from PR or branch workflow+#[derive(Debug, Clone, Serialize)]+pub struct JsonPr {+ /// CI status: "passed", "running", "failed", "conflicts", "no_ci", "error"+ pub ci: &'static str,++ /// Source: "pull_request" or "branch"+ pub source: &'static str,++ /// True if local HEAD differs from remote HEAD (unpushed changes)+ pub stale: bool,++ /// URL to the PR/MR (if available)+ #[serde(skip_serializing_if = "Option::is_none")]+ pub url: Option<String>,+}++impl JsonItem {+ /// Convert a ListItem to the new JSON structure+ pub fn from_list_item(item: &ListItem) -> Self {+ let (kind_str, worktree_data) = match &item.kind {+ ItemKind::Worktree(data) => ("worktree", Some(data.as_ref())),+ ItemKind::Branch => ("branch", None),+ };++ let is_main = worktree_data.map(|d| d.is_main).unwrap_or(false);+ let is_current = worktree_data.map(|d| d.is_current).unwrap_or(false);+ let is_previous = worktree_data.map(|d| d.is_previous).unwrap_or(false);++ // Commit info+ let sha = item.head.clone();+ let short_sha = if sha.len() >= 7 {+ sha[..7].to_string()+ } else {+ sha.clone()+ };+ let commit = JsonCommit {+ sha,+ short_sha,+ message: item+ .commit+ .as_ref()+ .map(|c| c.commit_message.clone())+ .unwrap_or_default(),+ timestamp: item.commit.as_ref().map(|c| c.timestamp).unwrap_or(0),+ };++ // Working tree (only for worktrees with status symbols)+ let working_tree = worktree_data.and_then(|data| {+ item.status_symbols.as_ref().map(|symbols| {+ let wt = &symbols.working_tree;+ // working_tree_diff_with_main is Option<Option<LineDiff>>:+ // None = not computed, Some(None) = skipped, Some(Some(diff)) = computed+ let diff_vs_main = data+ .working_tree_diff_with_main+ .flatten()+ .map(JsonDiff::from);+ JsonWorkingTree {+ staged: wt.staged,+ modified: wt.modified,+ untracked: wt.untracked,+ renamed: wt.renamed,+ deleted: wt.deleted,+ diff: data.working_tree_diff.map(JsonDiff::from),+ diff_vs_main,+ }+ })+ });++ // Branch state and integration reason - now directly from BranchState+ let (branch_state, integration_reason) = item+ .status_symbols+ .as_ref()+ .map(|symbols| {+ let state = symbols.branch_state.as_json_str();+ let reason = symbols+ .branch_state+ .integration_reason()+ .map(|r| r.as_json_str());+ (state, reason)+ })+ .unwrap_or((None, None));++ // Main relationship (absent when is_main)+ let main = if is_main {+ None+ } else {+ item.counts.map(|counts| JsonMain {+ ahead: counts.ahead,+ behind: counts.behind,+ diff: item.branch_diff.map(|bd| JsonDiff::from(bd.diff)),+ })+ };++ // Remote relationship+ let remote = item+ .upstream+ .as_ref()+ .and_then(|u| upstream_to_json(u, &item.branch));++ // Worktree state+ let worktree = worktree_data.map(|data| {+ let (state, reason) = worktree_state_to_json(data, item.status_symbols.as_ref());+ JsonWorktree {+ state,+ reason,+ detached: data.detached,+ bare: data.bare,+ }+ });++ // Path+ let path = worktree_data.map(|d| d.path.clone());++ // PR status+ let pr = item+ .pr_status+ .as_ref()+ .and_then(|opt| opt.as_ref())+ .map(pr_status_to_json);++ // Statusline and symbols (raw, without ANSI codes)+ let statusline = item.display.statusline.clone();+ let symbols = item+ .status_symbols+ .as_ref()+ .map(format_raw_symbols)+ .filter(|s| !s.is_empty());++ JsonItem {+ branch: item.branch.clone(),+ path,+ kind: kind_str,+ commit,+ working_tree,+ branch_state,+ integration_reason,+ main,+ remote,+ worktree,+ is_main,+ is_current,+ is_previous,+ pr,+ statusline,+ symbols,+ }+ }+}++/// Convert UpstreamStatus to JsonRemote+fn upstream_to_json(upstream: &UpstreamStatus, branch: &Option<String>) -> Option<JsonRemote> {+ upstream.active().map(|(remote, ahead, behind)| {+ // Use local branch name since UpstreamStatus only stores the remote name,+ // not the full tracking refspec. In most cases these match (e.g., feature -> origin/feature).+ JsonRemote {+ name: remote.to_string(),+ branch: branch.clone().unwrap_or_default(),+ ahead,+ behind,+ }+ })+}++/// Extract worktree state and reason from WorktreeData+fn worktree_state_to_json(+ data: &super::model::WorktreeData,+ status_symbols: Option<&super::model::StatusSymbols>,+) -> (Option<&'static str>, Option<String>) {+ use super::model::WorktreeState;++ // Check status symbols for worktree state+ if let Some(symbols) = status_symbols {+ match symbols.worktree_state {+ WorktreeState::None => {}+ WorktreeState::Branch => return (Some("no_worktree"), None),+ WorktreeState::PathMismatch => return (Some("path_mismatch"), None),+ WorktreeState::Prunable => return (Some("prunable"), data.prunable.clone()),+ WorktreeState::Locked => return (Some("locked"), data.locked.clone()),+ }+ }++ // Fallback: check direct fields when status_symbols is None+ // This can happen early in progressive rendering before status is computed+ if data.prunable.is_some() {+ return (Some("prunable"), data.prunable.clone());+ }+ if data.locked.is_some() {+ return (Some("locked"), data.locked.clone());+ }++ (None, None)+}++/// Convert PrStatus to JsonPr+fn pr_status_to_json(pr: &PrStatus) -> JsonPr {+ use super::ci_status::{CiSource, CiStatus};++ let ci = match pr.ci_status {+ CiStatus::Passed => "passed",+ CiStatus::Running => "running",+ CiStatus::Failed => "failed",+ CiStatus::Conflicts => "conflicts",+ CiStatus::NoCI => "no_ci",+ CiStatus::Error => "error",+ };++ let source = match pr.source {+ CiSource::PullRequest => "pull_request",+ CiSource::Branch => "branch",+ };++ JsonPr {+ ci,+ source,+ stale: pr.is_stale,+ url: pr.url.clone(),+ }+}++/// Format status symbols as raw characters (no ANSI codes)+fn format_raw_symbols(symbols: &super::model::StatusSymbols) -> String {+ let mut result = String::new();++ // Working tree symbols+ let wt_symbols = symbols.working_tree.to_symbols();+ if !wt_symbols.is_empty() {+ result.push_str(&wt_symbols);+ }++ // Branch state+ let branch_state = symbols.branch_state.to_string();+ if !branch_state.is_empty() {+ result.push_str(&branch_state);+ }++ // Main divergence+ let main_div = symbols.main_divergence.to_string();+ if !main_div.is_empty() {+ result.push_str(&main_div);+ }++ // Upstream divergence+ let upstream_div = symbols.upstream_divergence.to_string();+ if !upstream_div.is_empty() {+ result.push_str(&upstream_div);+ }++ // Worktree state+ let wt_state = symbols.worktree_state.to_string();+ if !wt_state.is_empty() {+ result.push_str(&wt_state);+ }++ // User marker+ if let Some(ref marker) = symbols.user_marker {+ result.push_str(marker);+ }++ result+}++/// Convert a list of ListItems to JSON output+pub fn to_json_items(items: &[ListItem]) -> Vec<JsonItem> {+ items.iter().map(JsonItem::from_list_item).collect()+}diff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rsindex ea0604b3a..6f6e176ec 100644--- a/src/commands/list/mod.rs+++ b/src/commands/list/mod.rs@@ -120,6 +120,7 @@ pub mod ci_status;pub(crate) mod collect;mod collect_progressive_impl;mod columns;+mod json_output;pub(crate) mod layout;pub mod model;pub mod progressive;@@ -189,9 +190,10 @@ pub fn handle_list(match format {crate::OutputFormat::Json => {- // Display fields are already computed in collect()+ // Convert to new JSON structure+ let json_items = json_output::to_json_items(&items);let json =- serde_json::to_string_pretty(&items).context("Failed to serialize to JSON")?;+ serde_json::to_string_pretty(&json_items).context("Failed to serialize to JSON")?;crate::output::data(json)?;}crate::OutputFormat::Table => {diff --git a/src/commands/list/model.rs b/src/commands/list/model.rsindex ea2904cc7..5da9778e1 100644--- a/src/commands/list/model.rs+++ b/src/commands/list/model.rs@@ -21,9 +21,9 @@ pub struct DisplayFields {/// Pre-formatted single-line representation for statusline tools./// Format: `branch status @working commits ^branch_diff upstream ci` (2-space separators)///- /// Use via JSON: `wt list --format=json | jq '.[] | select(.is_current) | .status_line'`+ /// Use via JSON: `wt list --format=json | jq '.[] | select(.is_current) | .statusline'`#[serde(skip_serializing_if = "Option::is_none")]- pub status_line: Option<String>,+ pub statusline: Option<String>,}impl DisplayFields {@@ -57,7 +57,7 @@ impl DisplayFields {upstream_display,ci_status_display,status_display: None,- status_line: None,+ statusline: None,}}}@@ -218,7 +218,7 @@ pub struct ListItem {pub branch_diff: Option<BranchDiffTotals>,/// Whether HEAD's tree SHA matches main's tree SHA./// True when committed content is identical regardless of commit history.- /// Internal field used to compute BranchOpState::TreesMatch.+ /// Internal field used to compute `BranchState::Integrated(TreesMatch)`.#[serde(skip)]pub committed_trees_match: Option<bool>,/// Whether branch has file changes beyond the merge-base with main.@@ -476,7 +476,7 @@ impl ListItem {&self.upstream,&self.pr_status,);- self.display.status_line = Some(self.format_statusline());+ self.display.statusline = Some(self.format_statusline());if let ItemKind::Worktree(ref mut wt_data) = self.kind&& let Some(ref working_tree_diff) = wt_data.working_tree_diff@@ -497,7 +497,7 @@ impl ListItem {default_branch: Option<&str>,has_merge_tree_conflicts: bool,user_marker: Option<String>,- working_tree_symbols: Option<&str>,+ working_tree_status: Option<WorkingTreeStatus>,has_conflicts: bool,) {// Common fields for both worktrees and branches@@ -535,15 +535,15 @@ impl ListItem {&data.working_tree_diff_with_main,);- // Apply priority: Conflicts > Rebase > Merge > MergeTreeConflicts > base_state- let branch_op_state = if has_conflicts {- BranchOpState::Conflicts+ // Apply priority: Conflicts > Rebase > Merge > WouldConflict > base_state+ let branch_state = if has_conflicts {+ BranchState::Conflicts} else if data.git_operation == GitOperationState::Rebase {- BranchOpState::Rebase+ BranchState::Rebase} else if data.git_operation == GitOperationState::Merge {- BranchOpState::Merge+ BranchState::Merge} else if has_merge_tree_conflicts {- BranchOpState::MergeTreeConflicts+ BranchState::WouldConflict} else {base_state};@@ -556,11 +556,11 @@ impl ListItem {};self.status_symbols = Some(StatusSymbols {- branch_op_state,+ branch_state,worktree_state,main_divergence,upstream_divergence,- working_tree: working_tree_symbols.unwrap_or("").to_string(),+ working_tree: working_tree_status.unwrap_or_default(),user_marker,});}@@ -568,37 +568,37 @@ impl ListItem {// Simplified status computation for branches// Only compute symbols that apply to branches (no working tree, git operation, or worktree attrs)- // Branch op state - branches can show MergeTreeConflicts or integration states- let branch_op_state = if has_merge_tree_conflicts {- BranchOpState::MergeTreeConflicts+ // Branch state - branches can show WouldConflict or integration states+ let branch_state = if has_merge_tree_conflicts {+ BranchState::WouldConflict} else if self.is_ancestor == Some(true) {// Branch HEAD is ancestor of main - same commit or already merged- BranchOpState::SameCommit+ BranchState::SameCommit} else if self.has_file_changes == Some(false) {// No file changes beyond merge-base - content is integrated- BranchOpState::NoAddedChanges+ BranchState::Integrated(IntegrationReason::NoAddedChanges)} else if self.committed_trees_match == Some(true) {// Tree SHA matches main - content is identical- BranchOpState::TreesMatch+ BranchState::Integrated(IntegrationReason::TreesMatch)} else if self.would_merge_add == Some(false) {// Merge simulation shows no changes would be added (--full only)- BranchOpState::MergeAddsNothing+ BranchState::Integrated(IntegrationReason::MergeAddsNothing)} else if let Some(ref c) = self.counts {if c.ahead == 0 {- BranchOpState::SameCommit+ BranchState::SameCommit} else {- BranchOpState::None+ BranchState::None}} else {- BranchOpState::None+ BranchState::None};self.status_symbols = Some(StatusSymbols {- branch_op_state,+ branch_state,worktree_state: WorktreeState::Branch,main_divergence,upstream_divergence,- working_tree: String::new(),+ working_tree: WorkingTreeStatus::default(),user_marker,});}@@ -608,20 +608,20 @@ impl ListItem {/// Determine branch state for a worktree.///-/// Returns a [`BranchOpState`] that corresponds to an [`worktrunk::git::IntegrationReason`] when-/// the branch content is considered integrated into main.+/// Returns a [`BranchState`] indicating whether the branch content is integrated into main+/// and how (via [`IntegrationReason`]).////// # States (priority order)////// 1. **`SameCommit`**: Branch HEAD is ancestor of main (same commit or already merged).///-/// 2. **`NoAddedChanges`**: Commits exist but no file changes beyond merge-base.+/// 2. **`Integrated(NoAddedChanges)`**: Commits exist but no file changes beyond merge-base./// The three-dot diff (`main...branch`) is empty.///-/// 3. **`TreesMatch`**: Tree SHA matches main, or working tree matches main.+/// 3. **`Integrated(TreesMatch)`**: Tree SHA matches main, or working tree matches main./// Examples: merge commits that pull in main, rebases, squash merges.///-/// 4. **`MergeAddsNothing`**: Merge simulation adds nothing to main.+/// 4. **`Integrated(MergeAddsNothing)`**: Merge simulation adds nothing to main./// Catches squash-merged branches where main has advanced.////// # Parameters@@ -642,26 +642,26 @@ fn determine_worktree_base_state(would_merge_add: Option<bool>,working_tree_diff: Option<&LineDiff>,working_tree_diff_with_main: &Option<Option<LineDiff>>,-) -> BranchOpState {+) -> BranchState {if is_main || default_branch.is_none() {- return BranchOpState::None;+ return BranchState::None;}let is_clean = working_tree_diff.map(|d| d.is_empty()).unwrap_or(true);// Priority 1: Branch is ancestor of main (same commit or already merged)if is_ancestor == Some(true) && is_clean {- return BranchOpState::SameCommit;+ return BranchState::SameCommit;}// Priority 2: No file changes beyond merge-base (squash-merged)if has_file_changes == Some(false) && is_clean {- return BranchOpState::NoAddedChanges;+ return BranchState::Integrated(IntegrationReason::NoAddedChanges);}// Priority 3: Tree SHA matches main (squash merge/rebase with identical content)if committed_trees_match && is_clean {- return BranchOpState::TreesMatch;+ return BranchState::Integrated(IntegrationReason::TreesMatch);}// Priority 4: Working tree matches main@@ -671,15 +671,15 @@ fn determine_worktree_base_state(.is_some_and(|diff| diff.is_empty());if working_tree_matches_main {- return BranchOpState::TreesMatch;+ return BranchState::Integrated(IntegrationReason::TreesMatch);}// Priority 5: Merge simulation shows no changes (--full only)if would_merge_add == Some(false) && is_clean {- return BranchOpState::MergeAddsNothing;+ return BranchState::Integrated(IntegrationReason::MergeAddsNothing);}- BranchOpState::None+ BranchState::None}/// Main branch divergence state@@ -858,30 +858,21 @@ impl serde::Serialize for WorktreeState {}}-/// Combined branch and operation state+/// Branch state: operation states, conflict states, or integration states////// Represents the primary state of a branch/worktree in a single position./// Priority order determines which symbol is shown when multiple conditions apply:/// 1. Conflicts (✘) - blocking, must resolve/// 2. Rebase (⤴) - active operation/// 3. Merge (⤵) - active operation-/// 4. MergeTreeConflicts (✗) - potential problem-/// 5. SameCommit (·) - removable, maps to [`IntegrationReason::SameCommit`]-/// 6. NoAddedChanges (⊂) - removable, maps to [`IntegrationReason::NoAddedChanges`]-/// 7. TreesMatch (⊂) - removable, maps to [`IntegrationReason::TreesMatch`]-/// 8. MergeAddsNothing (⊂) - removable, maps to [`IntegrationReason::MergeAddsNothing`]+/// 4. WouldConflict (✗) - potential problem (merge-tree simulation)+/// 5. SameCommit (·) - removable, branch is ancestor of main+/// 6. Integrated (⊂) - removable, content is in main via different history///-/// Integration states use two symbols:-/// - `·` for identical commit (SameCommit)-/// - `⊂` for content integrated via different history (all others)-///-/// [`IntegrationReason::SameCommit`]: worktrunk::git::IntegrationReason::SameCommit-/// [`IntegrationReason::TreesMatch`]: worktrunk::git::IntegrationReason::TreesMatch-/// [`IntegrationReason::NoAddedChanges`]: worktrunk::git::IntegrationReason::NoAddedChanges-/// [`IntegrationReason::MergeAddsNothing`]: worktrunk::git::IntegrationReason::MergeAddsNothing-#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, strum::IntoStaticStr)]-pub enum BranchOpState {- #[strum(serialize = "")]+/// The `Integrated` variant carries an [`IntegrationReason`] explaining how the+/// content was integrated (trees match, no added changes, or merge adds nothing).+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]+pub enum BranchState {/// Normal working branch#[default]None,@@ -892,68 +883,94 @@ pub enum BranchOpState {/// Merge in progressMerge,/// Merge-tree conflicts with main (simulated via git merge-tree)- MergeTreeConflicts,- /// Branch HEAD is same commit as main or ancestor of main.- /// Maps to [`worktrunk::git::IntegrationReason::SameCommit`].+ WouldConflict,+ /// Branch HEAD is same commit as main or ancestor of mainSameCommit,- /// Tree SHA matches main - identical file contents.- /// Maps to [`worktrunk::git::IntegrationReason::TreesMatch`].+ /// Content is integrated into main via different history+ Integrated(IntegrationReason),+}++/// Reason why branch content is considered integrated into main+///+/// These explain HOW the content was integrated, separate from the fact+/// that it IS integrated.+#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]+#[serde(rename_all = "snake_case")]+pub enum IntegrationReason {+ /// Tree SHA matches main - identical file contentsTreesMatch,- /// No file changes beyond merge-base (three-dot diff empty).- /// Maps to [`worktrunk::git::IntegrationReason::NoAddedChanges`].+ /// No file changes beyond merge-base (three-dot diff empty)NoAddedChanges,- /// Merge simulation adds nothing to main.- /// Maps to [`worktrunk::git::IntegrationReason::MergeAddsNothing`].+ /// Merge simulation adds nothing to mainMergeAddsNothing,}-impl std::fmt::Display for BranchOpState {+impl IntegrationReason {+ /// Returns the JSON string representation for integration_reason field.+ pub fn as_json_str(self) -> &'static str {+ match self {+ Self::TreesMatch => "trees_match",+ Self::NoAddedChanges => "no_added_changes",+ Self::MergeAddsNothing => "merge_adds_nothing",+ }+ }+}++impl std::fmt::Display for BranchState {fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {match self {Self::None => Ok(()),Self::Conflicts => write!(f, "✘"),Self::Rebase => write!(f, "⤴"),Self::Merge => write!(f, "⤵"),- Self::MergeTreeConflicts => write!(f, "✗"),+ Self::WouldConflict => write!(f, "✗"),Self::SameCommit => write!(f, "·"),- // All other integration states use ⊂ (content is subset of main)- Self::TreesMatch | Self::NoAddedChanges | Self::MergeAddsNothing => write!(f, "⊂"),+ // All integration reasons use ⊂ (content is subset of main)+ Self::Integrated(_) => write!(f, "⊂"),}}}-impl BranchOpState {+impl BranchState {/// Returns styled symbol with appropriate color, or None for None variant.////// Color semantics:/// - ERROR (red): Conflicts - blocking problems- /// - WARNING (yellow): Rebase, Merge, MergeTreeConflicts - active/stuck states- /// - HINT (dimmed): SameCommit, TreesMatch, NoAddedChanges, MergeAddsNothing - low urgency removability indicators+ /// - WARNING (yellow): Rebase, Merge, WouldConflict - active/stuck states+ /// - HINT (dimmed): SameCommit, Integrated - low urgency removability indicatorspub fn styled(&self) -> Option<String> {use color_print::cformat;match self {Self::None => None,Self::Conflicts => Some(cformat!("<red>{self}</>")),- Self::Rebase | Self::Merge | Self::MergeTreeConflicts => {- Some(cformat!("<yellow>{self}</>"))- }- Self::SameCommit | Self::TreesMatch | Self::NoAddedChanges | Self::MergeAddsNothing => {- Some(cformat!("<dim>{self}</>"))- }+ Self::Rebase | Self::Merge | Self::WouldConflict => Some(cformat!("<yellow>{self}</>")),+ Self::SameCommit | Self::Integrated(_) => Some(cformat!("<dim>{self}</>")),}}- /// Returns true if this state indicates the branch content is integrated into main.- /// These states correspond to [`worktrunk::git::IntegrationReason`] variants.- pub fn is_integrated(&self) -> bool {- matches!(- self,- Self::SameCommit | Self::TreesMatch | Self::NoAddedChanges | Self::MergeAddsNothing- )+ /// Returns the integration reason if this is an integrated state, None otherwise.+ pub fn integration_reason(&self) -> Option<IntegrationReason> {+ match self {+ Self::Integrated(reason) => Some(*reason),+ _ => None,+ }+ }++ /// Returns the JSON string representation for branch_state field.+ pub fn as_json_str(self) -> Option<&'static str> {+ match self {+ Self::None => None,+ Self::Conflicts => Some("conflicts"),+ Self::Rebase => Some("rebase"),+ Self::Merge => Some("merge"),+ Self::WouldConflict => Some("would_conflict"),+ Self::SameCommit => Some("same_commit"),+ Self::Integrated(_) => Some("integrated"),+ }}}-impl serde::Serialize for BranchOpState {+impl serde::Serialize for BranchState {fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>whereS: serde::Serializer,@@ -1001,7 +1018,7 @@ impl PositionMask {const STAGED: usize = 0; // + (staged changes)const MODIFIED: usize = 1; // ! (modified files)const UNTRACKED: usize = 2; // ? (untracked files)- const BRANCH_OP_STATE: usize = 3; // Combined: branch state + git operation+ const BRANCH_STATE: usize = 3; // Branch state (conflicts, rebase, merge, integrated, etc.)const MAIN_DIVERGENCE: usize = 4;const UPSTREAM_DIVERGENCE: usize = 5;const WORKTREE_STATE: usize = 6;@@ -1014,7 +1031,7 @@ impl PositionMask {1, // STAGED: + (1 char)1, // MODIFIED: ! (1 char)1, // UNTRACKED: ? (1 char)- 1, // BRANCH_OP_STATE: ✘⤴⤵✗·⊂ (1 char, priority: conflicts > rebase > merge > merge-tree > same-commit > integrated)+ 1, // BRANCH_STATE: ✘⤴⤵✗·⊂ (1 char, priority: conflicts > rebase > merge > would_conflict > same_commit > integrated)1, // MAIN_DIVERGENCE: ^, ↑, ↓, ↕ (1 char)1, // UPSTREAM_DIVERGENCE: ⇡, ⇣, ⇅ (1 char)1, // WORKTREE_STATE: / for branches, ⚑⊟⊞ for worktrees (priority: path_mismatch > prunable > locked)@@ -1061,9 +1078,9 @@ impl PositionMask {/// - Working tree symbols (+!?): Can have multiple types of changes#[derive(Debug, Clone, Default)]pub struct StatusSymbols {- /// Combined branch and operation state (mutually exclusive with priority)- /// Priority: Conflicts (✘) > Rebase (⤴) > Merge (⤵) > MergeTreeConflicts (✗) > SameCommit (·) > others (⊂)- pub(crate) branch_op_state: BranchOpState,+ /// Branch state (mutually exclusive with priority)+ /// Priority: Conflicts (✘) > Rebase (⤴) > Merge (⤵) > WouldConflict (✗) > SameCommit (·) > Integrated (⊂)+ pub(crate) branch_state: BranchState,/// Worktree state: / for branches, ⚑⊟⊞ for worktrees (priority: path_mismatch > prunable > locked)pub(crate) worktree_state: WorktreeState,@@ -1074,8 +1091,8 @@ pub struct StatusSymbols {/// Remote/upstream divergence state (mutually exclusive)pub(crate) upstream_divergence: UpstreamDivergence,- /// Working tree changes: +, !, ? (NOT mutually exclusive, can have multiple)- pub(crate) working_tree: String,+ /// Working tree changes (NOT mutually exclusive, can have multiple)+ pub(crate) working_tree: WorkingTreeStatus,/// User-defined status annotation (custom labels, e.g., 💬, 🤖)pub(crate) user_marker: Option<String>,@@ -1124,11 +1141,11 @@ impl StatusSymbols {/// Check if symbols are emptypub fn is_empty(&self) -> bool {- self.branch_op_state == BranchOpState::None+ self.branch_state == BranchState::None&& self.worktree_state == WorktreeState::None&& self.main_divergence == MainDivergence::None&& self.upstream_divergence == UpstreamDivergence::None- && self.working_tree.is_empty()+ && !self.working_tree.is_dirty()&& self.user_marker.is_none()}@@ -1156,19 +1173,19 @@ impl StatusSymbols {use color_print::cformat;// Working tree symbols split into 3 fixed columns for vertical alignment- let style_working = |sym: char| -> (String, bool) {- if self.working_tree.contains(sym) {+ let style_working = |has: bool, sym: char| -> (String, bool) {+ if has {(cformat!("<cyan>{sym}</>"), true)} else {(String::new(), false)}};- let (staged_str, has_staged) = style_working('+');- let (modified_str, has_modified) = style_working('!');- let (untracked_str, has_untracked) = style_working('?');+ let (staged_str, has_staged) = style_working(self.working_tree.staged, '+');+ let (modified_str, has_modified) = style_working(self.working_tree.modified, '!');+ let (untracked_str, has_untracked) = style_working(self.working_tree.untracked, '?');- let (branch_op_state_str, has_branch_op_state) = self- .branch_op_state+ let (branch_state_str, has_branch_state) = self+ .branch_state.styled().map_or((String::new(), false), |s| (s, true));let (main_divergence_str, has_main_divergence) = self@@ -1199,9 +1216,9 @@ impl StatusSymbols {(PositionMask::MODIFIED, modified_str, has_modified),(PositionMask::UNTRACKED, untracked_str, has_untracked),(- PositionMask::BRANCH_OP_STATE,- branch_op_state_str,- has_branch_op_state,+ PositionMask::BRANCH_STATE,+ branch_state_str,+ has_branch_state,),(PositionMask::MAIN_DIVERGENCE,@@ -1227,35 +1244,74 @@ impl StatusSymbols {}}-/// Working tree changes parsed into structured booleans-#[derive(Debug, Clone, serde::Serialize)]-struct WorkingTreeChanges {- untracked: bool,- modified: bool,- staged: bool,- renamed: bool,- deleted: bool,+/// Working tree changes as structured booleans+///+/// This is the canonical internal representation. Display strings are derived from this.+#[derive(Debug, Clone, Copy, Default, serde::Serialize)]+pub struct WorkingTreeStatus {+ pub staged: bool,+ pub modified: bool,+ pub untracked: bool,+ pub renamed: bool,+ pub deleted: bool,}-impl WorkingTreeChanges {- fn from_symbols(symbols: &str) -> Self {+impl WorkingTreeStatus {+ /// Create from git status parsing results+ pub fn new(+ staged: bool,+ modified: bool,+ untracked: bool,+ renamed: bool,+ deleted: bool,+ ) -> Self {Self {- untracked: symbols.contains('?'),- modified: symbols.contains('!'),- staged: symbols.contains('+'),- renamed: symbols.contains('»'),- deleted: symbols.contains('✘'),+ staged,+ modified,+ untracked,+ renamed,+ deleted,+ }+ }++ /// Returns true if any changes are present+ pub fn is_dirty(&self) -> bool {+ self.staged || self.modified || self.untracked || self.renamed || self.deleted+ }++ /// Format as display string for JSON serialization and raw output (e.g., "+!?").+ ///+ /// For styled terminal rendering, use `StatusSymbols::styled_symbols()` instead.+ pub fn to_symbols(self) -> String {+ let mut s = String::with_capacity(5);+ if self.staged {+ s.push('+');+ }+ if self.modified {+ s.push('!');+ }+ if self.untracked {+ s.push('?');+ }+ if self.renamed {+ s.push('»');+ }+ if self.deleted {+ s.push('✘');}+ s}}/// Status variant names (for queryability)///-/// Field order matches display order in STATUS SYMBOLS: working_tree → branch_op_state → ...+/// Field order matches display order in STATUS SYMBOLS: working_tree → branch_state → ...#[derive(Debug, Clone, serde::Serialize)]struct QueryableStatus {- working_tree: WorkingTreeChanges,- branch_op_state: &'static str,+ working_tree: WorkingTreeStatus,+ branch_state: &'static str,+ #[serde(skip_serializing_if = "Option::is_none")]+ integration_reason: Option<IntegrationReason>,main_divergence: &'static str,upstream_divergence: &'static str,worktree_state: &'static str,@@ -1265,11 +1321,11 @@ struct QueryableStatus {/// Status symbols (for display)///-/// Field order matches display order in STATUS SYMBOLS: working_tree → branch_op_state → ...+/// Field order matches display order in STATUS SYMBOLS: working_tree → branch_state → ...#[derive(Debug, Clone, serde::Serialize)]struct DisplaySymbols {working_tree: String,- branch_op_state: String,+ branch_state: String,main_divergence: String,upstream_divergence: String,worktree_state: String,@@ -1285,8 +1341,11 @@ impl serde::Serialize for StatusSymbols {use serde::ser::SerializeStruct;let mut state = serializer.serialize_struct("StatusSymbols", 2)?;+ // Get branch state string and optional integration reason+ let branch_state_str = self.branch_state.as_json_str().unwrap_or("");+ let integration_reason = self.branch_state.integration_reason();+// Status variant names (derived via strum::IntoStaticStr)- let branch_op_state_variant: &'static str = self.branch_op_state.into();let main_divergence_variant: &'static str = self.main_divergence.into();let upstream_divergence_variant: &'static str = self.upstream_divergence.into();@@ -1294,8 +1353,9 @@ impl serde::Serialize for StatusSymbols {let worktree_state_variant: &'static str = self.worktree_state.into();let queryable_status = QueryableStatus {- working_tree: WorkingTreeChanges::from_symbols(&self.working_tree),- branch_op_state: branch_op_state_variant,+ working_tree: self.working_tree,+ branch_state: branch_state_str,+ integration_reason,main_divergence: main_divergence_variant,upstream_divergence: upstream_divergence_variant,worktree_state: worktree_state_variant,@@ -1303,8 +1363,8 @@ impl serde::Serialize for StatusSymbols {};let display_symbols = DisplaySymbols {- working_tree: self.working_tree.clone(),- branch_op_state: self.branch_op_state.to_string(),+ working_tree: self.working_tree.to_symbols(),+ branch_state: self.branch_state.to_string(),main_divergence: self.main_divergence.to_string(),upstream_divergence: self.upstream_divergence.to_string(),worktree_state: self.worktree_state.to_string(),@@ -1322,3 +1382,118 @@ impl serde::Serialize for StatusSymbols {fn git_operation_is_none(state: &GitOperationState) -> bool {*state == GitOperationState::None}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn test_working_tree_status_is_dirty() {+ // Empty status is not dirty+ assert!(!WorkingTreeStatus::default().is_dirty());++ // Each flag individually makes it dirty+ assert!(WorkingTreeStatus::new(true, false, false, false, false).is_dirty());+ assert!(WorkingTreeStatus::new(false, true, false, false, false).is_dirty());+ assert!(WorkingTreeStatus::new(false, false, true, false, false).is_dirty());+ assert!(WorkingTreeStatus::new(false, false, false, true, false).is_dirty());+ assert!(WorkingTreeStatus::new(false, false, false, false, true).is_dirty());++ // Multiple flags+ assert!(WorkingTreeStatus::new(true, true, true, true, true).is_dirty());+ }++ #[test]+ fn test_working_tree_status_to_symbols() {+ // Empty+ assert_eq!(WorkingTreeStatus::default().to_symbols(), "");++ // Individual symbols+ assert_eq!(+ WorkingTreeStatus::new(true, false, false, false, false).to_symbols(),+ "+"+ );+ assert_eq!(+ WorkingTreeStatus::new(false, true, false, false, false).to_symbols(),+ "!"+ );+ assert_eq!(+ WorkingTreeStatus::new(false, false, true, false, false).to_symbols(),+ "?"+ );+ assert_eq!(+ WorkingTreeStatus::new(false, false, false, true, false).to_symbols(),+ "»"+ );+ assert_eq!(+ WorkingTreeStatus::new(false, false, false, false, true).to_symbols(),+ "✘"+ );++ // Combined symbols (order: staged, modified, untracked, renamed, deleted)+ assert_eq!(+ WorkingTreeStatus::new(true, true, false, false, false).to_symbols(),+ "+!"+ );+ assert_eq!(+ WorkingTreeStatus::new(true, true, true, false, false).to_symbols(),+ "+!?"+ );+ assert_eq!(+ WorkingTreeStatus::new(true, true, true, true, true).to_symbols(),+ "+!?»✘"+ );+ }++ #[test]+ fn test_branch_state_as_json_str() {+ assert_eq!(BranchState::None.as_json_str(), None);+ assert_eq!(BranchState::Conflicts.as_json_str(), Some("conflicts"));+ assert_eq!(BranchState::Rebase.as_json_str(), Some("rebase"));+ assert_eq!(BranchState::Merge.as_json_str(), Some("merge"));+ assert_eq!(+ BranchState::WouldConflict.as_json_str(),+ Some("would_conflict")+ );+ assert_eq!(BranchState::SameCommit.as_json_str(), Some("same_commit"));+ assert_eq!(+ BranchState::Integrated(IntegrationReason::TreesMatch).as_json_str(),+ Some("integrated")+ );+ }++ #[test]+ fn test_integration_reason_as_json_str() {+ assert_eq!(IntegrationReason::TreesMatch.as_json_str(), "trees_match");+ assert_eq!(+ IntegrationReason::NoAddedChanges.as_json_str(),+ "no_added_changes"+ );+ assert_eq!(+ IntegrationReason::MergeAddsNothing.as_json_str(),+ "merge_adds_nothing"+ );+ }++ #[test]+ fn test_branch_state_integration_reason() {+ // Non-integrated states return None+ assert_eq!(BranchState::None.integration_reason(), None);+ assert_eq!(BranchState::Conflicts.integration_reason(), None);+ assert_eq!(BranchState::SameCommit.integration_reason(), None);++ // Integrated states return the reason+ assert_eq!(+ BranchState::Integrated(IntegrationReason::TreesMatch).integration_reason(),+ Some(IntegrationReason::TreesMatch)+ );+ assert_eq!(+ BranchState::Integrated(IntegrationReason::NoAddedChanges).integration_reason(),+ Some(IntegrationReason::NoAddedChanges)+ );+ assert_eq!(+ BranchState::Integrated(IntegrationReason::MergeAddsNothing).integration_reason(),+ Some(IntegrationReason::MergeAddsNothing)+ );+ }+}diff --git a/src/commands/statusline.rs b/src/commands/statusline.rsindex 83caee2f5..e1073fa68 100644--- a/src/commands/statusline.rs+++ b/src/commands/statusline.rs@@ -262,9 +262,9 @@ fn get_git_status(repo: &Repository, cwd: &Path) -> Result<Option<String>> {},)?;- // Return the pre-formatted status line- if let Some(ref status_line) = items[0].display.status_line {- Ok(Some(status_line.clone()))+ // Return the pre-formatted statusline+ if let Some(ref statusline) = items[0].display.statusline {+ Ok(Some(statusline.clone()))} else {// Fallback: just show branch nameOk(Some(wt.branch.as_deref().unwrap_or("HEAD").to_string()))diff --git a/tests/snapshots/integration__integration_tests__help__help_list_long.snap b/tests/snapshots/integration__integration_tests__help__help_list_long.snapindex 9959cda50..50280e3de 100644--- a/tests/snapshots/integration__integration_tests__help__help_list_long.snap+++ b/tests/snapshots/integration__integration_tests__help__help_list_long.snap@@ -145,28 +145,40 @@ Rows are dimmed when the branch content is already in main ([2m·[0m same commQuery structured data with [2m--format=json[0m:[2m# Worktrees with conflicts[0m- [2mwt list --format=json | jq '.[] | select(.status.branch_state == "Conflicts")'[0m+ [2mwt list --format=json | jq '.[] | select(.branch_state == "conflicts")'[0m[2m[0m[2m# Uncommitted changes[0m- [2mwt list --format=json | jq '.[] | select(.status.working_tree.modified)'[0m+ [2mwt list --format=json | jq '.[] | select(.working_tree.modified)'[0m[2m[0m[2m# Current worktree[0m- [2mwt list --format=json | jq '.[] | select(.is_current == true)'[0m+ [2mwt list --format=json | jq '.[] | select(.is_current)'[0m[2m[0m[2m# Branches ahead of main[0m- [2mwt list --format=json | jq '.[] | select(.status.main_divergence == "Ahead")'[0m--[1mStatus fields:[0m-- [2mworking_tree[0m: [2m{untracked, modified, staged, renamed, deleted}[0m-- [2mbranch_state[0m: [2m""[0m | [2m"Conflicts"[0m | [2m"MergeTreeConflicts"[0m | [2m"TreesMatch"[0m | [2m"NoAddedChanges"[0m | [2m"MergeAddsNothing"[0m-- [2mgit_operation[0m: [2m""[0m | [2m"Rebase"[0m | [2m"Merge"[0m-- [2mmain_divergence[0m: [2m""[0m | [2m"Ahead"[0m | [2m"Behind"[0m | [2m"Diverged"[0m-- [2mupstream_divergence[0m: [2m""[0m | [2m"Ahead"[0m | [2m"Behind"[0m | [2m"Diverged"[0m--[1mPosition fields:[0m-- [2mis_main[0m — Main worktree-- [2mis_current[0m — Current directory-- [2mis_previous[0m — Previous worktree from wt switch+ [2mwt list --format=json | jq '.[] | select(.main.ahead > 0)'[0m+ [2m[0m+ [2m# Integrated branches (ready to clean up)[0m+ [2mwt list --format=json | jq '.[] | select(.branch_state == "integrated" or .branch_state == "same_commit")'[0m++[1mFields:[0m++ Field Description+ ────────────────── ─────────────────────────────────────────────────────────────────────────────────────────+ [2mbranch[0m Branch name (null for detached HEAD)+ [2mpath[0m Worktree path (absent for branches without worktrees)+ [2mkind[0m [2m"worktree"[0m or [2m"branch"[0m+ [2mcommit[0m [2m{sha, short_sha, message, timestamp}[0m+ [2mworking_tree[0m [2m{staged, modified, untracked, renamed, deleted, diff, diff_vs_main}[0m+ [2mbranch_state[0m [2m"conflicts"[0m [2m"rebase"[0m [2m"merge"[0m [2m"would_conflict"[0m [2m"same_commit"[0m [2m"integrated"[0m+ [2mintegration_reason[0m [2m"trees_match"[0m [2m"no_added_changes"[0m [2m"merge_adds_nothing"[0m (when [2mbranch_state == "integrated"[0m)+ [2mmain[0m [2m{ahead, behind, diff}[0m (absent when [2mis_main[0m)+ [2mremote[0m [2m{name, branch, ahead, behind}[0m (absent when no tracking branch)+ [2mworktree[0m [2m{state, reason, detached, bare}[0m+ [2mis_main[0m Main worktree+ [2mis_current[0m Current worktree+ [2mis_previous[0m Previous worktree from wt switch+ [2mpr[0m [2m{ci, source, stale, url}[0m — CI status from PR or branch (absent when no CI)+ [2mstatusline[0m Pre-formatted status with ANSI colors+ [2msymbols[0m Raw status symbols without colors (e.g., [2m"!?↓"[0m)[32mSee also[0mdiff --git a/tests/snapshots/integration__integration_tests__list__json_tree_matches_main_after_merge.snap b/tests/snapshots/integration__integration_tests__list__json_tree_matches_main_after_merge.snapindex 844f1e2f0..edf05f5f6 100644--- a/tests/snapshots/integration__integration_tests__list__json_tree_matches_main_after_merge.snap+++ b/tests/snapshots/integration__integration_tests__list__json_tree_matches_main_after_merge.snap@@ -23,98 +23,77 @@ exit_code: 0----- stdout -----[{- "head_sha": "133d1f05a73a1478707f3438625069c7ebd8eb27","branch": "main",- "timestamp": 0,- "commit_message": "Same content on main",- "ahead": 0,- "behind": 0,- "upstream_remote": null,- "upstream_ahead": 0,- "upstream_behind": 0,- "pr_status": null,- "status": {- "working_tree": {- "untracked": false,- "modified": false,- "staged": false,- "renamed": false,- "deleted": false- },- "branch_op_state": "",- "main_divergence": "IsMain",- "upstream_divergence": "",- "worktree_state": ""- },- "status_symbols": {- "working_tree": "",- "branch_op_state": "",- "main_divergence": "^",- "upstream_divergence": "",- "worktree_state": ""- },- "status_line": "main /u001b[2m^/u001b[22m",- "type": "worktree","path": "[REPO]",- "bare": false,- "detached": false,- "working_tree_diff": {- "added": 0,- "deleted": 0+ "kind": "worktree",+ "commit": {+ "sha": "133d1f05a73a1478707f3438625069c7ebd8eb27",+ "short_sha": "133d1f0",+ "message": "Same content on main",+ "timestamp": 0+ },+ "working_tree": {+ "staged": false,+ "modified": false,+ "untracked": false,+ "renamed": false,+ "deleted": false,+ "diff": {+ "added": 0,+ "deleted": 0+ },+ "diff_vs_main": {+ "added": 0,+ "deleted": 0+ }},- "working_tree_diff_with_main": {- "added": 0,- "deleted": 0+ "worktree": {+ "detached": false,+ "bare": false},"is_main": true,- "is_current": true+ "is_current": true,+ "statusline": "main /u001b[2m^/u001b[22m",+ "symbols": "^"},{- "head_sha": "d78d130165cc11f6df39113ded5bbf1c16f8ebc3","branch": "feature-merged",- "timestamp": 0,- "commit_message": "Merge main into feature",- "ahead": 2,- "behind": 0,- "upstream_remote": null,- "upstream_ahead": 0,- "upstream_behind": 0,- "pr_status": null,- "status": {- "working_tree": {- "untracked": false,- "modified": false,- "staged": false,- "renamed": false,- "deleted": false- },- "branch_op_state": "NoAddedChanges",- "main_divergence": "Ahead",- "upstream_divergence": "",- "worktree_state": ""+ "path": "[REPO].feature-merged",+ "kind": "worktree",+ "commit": {+ "sha": "d78d130165cc11f6df39113ded5bbf1c16f8ebc3",+ "short_sha": "d78d130",+ "message": "Merge main into feature",+ "timestamp": 0},- "status_symbols": {- "working_tree": "",- "branch_op_state": "⊂",- "main_divergence": "↑",- "upstream_divergence": "",- "worktree_state": ""+ "working_tree": {+ "staged": false,+ "modified": false,+ "untracked": false,+ "renamed": false,+ "deleted": false,+ "diff": {+ "added": 0,+ "deleted": 0+ },+ "diff_vs_main": {+ "added": 0,+ "deleted": 0+ }},- "commits_display": "/u001b[32m↑2/u001b[0m",- "status_line": "feature-merged /u001b[2m⊂/u001b[22m/u001b[2m↑/u001b[22m /u001b[32m↑2/u001b[0m",- "type": "worktree",- "path": "[REPO].feature-merged",- "bare": false,- "detached": false,- "working_tree_diff": {- "added": 0,- "deleted": 0+ "branch_state": "integrated",+ "integration_reason": "no_added_changes",+ "main": {+ "ahead": 2,+ "behind": 0},- "working_tree_diff_with_main": {- "added": 0,- "deleted": 0+ "worktree": {+ "detached": false,+ "bare": false},- "is_main": false+ "is_main": false,+ "statusline": "feature-merged /u001b[2m⊂/u001b[22m/u001b[2m↑/u001b[22m /u001b[32m↑2/u001b[0m",+ "symbols": "⊂↑"}]diff --git a/tests/snapshots/integration__integration_tests__list__json_with_display_fields.snap b/tests/snapshots/integration__integration_tests__list__json_with_display_fields.snapindex 2e2675e14..c9dbb9aa1 100644--- a/tests/snapshots/integration__integration_tests__list__json_with_display_fields.snap+++ b/tests/snapshots/integration__integration_tests__list__json_with_display_fields.snap@@ -23,140 +23,105 @@ exit_code: 0----- stdout -----[{- "head_sha": "a27cd57d20a6211799da676e70edefa5152f99fe","branch": "main",- "timestamp": 0,- "commit_message": "Main commit 2",- "ahead": 0,- "behind": 0,- "upstream_remote": null,- "upstream_ahead": 0,- "upstream_behind": 0,- "pr_status": null,- "status": {- "working_tree": {- "untracked": false,- "modified": false,- "staged": false,- "renamed": false,- "deleted": false- },- "branch_op_state": "",- "main_divergence": "IsMain",- "upstream_divergence": "",- "worktree_state": ""- },- "status_symbols": {- "working_tree": "",- "branch_op_state": "",- "main_divergence": "^",- "upstream_divergence": "",- "worktree_state": ""- },- "status_line": "main /u001b[2m^/u001b[22m",- "type": "worktree","path": "[REPO]",- "bare": false,- "detached": false,- "working_tree_diff": {- "added": 0,- "deleted": 0+ "kind": "worktree",+ "commit": {+ "sha": "a27cd57d20a6211799da676e70edefa5152f99fe",+ "short_sha": "a27cd57",+ "message": "Main commit 2",+ "timestamp": 0},- "working_tree_diff_with_main": {- "added": 0,- "deleted": 0+ "working_tree": {+ "staged": false,+ "modified": false,+ "untracked": false,+ "renamed": false,+ "deleted": false,+ "diff": {+ "added": 0,+ "deleted": 0+ },+ "diff_vs_main": {+ "added": 0,+ "deleted": 0+ }+ },+ "worktree": {+ "detached": false,+ "bare": false},"is_main": true,- "is_current": true+ "is_current": true,+ "statusline": "main /u001b[2m^/u001b[22m",+ "symbols": "^"},{- "head_sha": "f16cd37915d5ee93903252f5cf877c76c54f3d50","branch": "feature-ahead",- "timestamp": 0,- "commit_message": "Feature commit 2",- "ahead": 2,- "behind": 2,- "upstream_remote": null,- "upstream_ahead": 0,- "upstream_behind": 0,- "pr_status": null,- "status": {- "working_tree": {- "untracked": true,- "modified": true,- "staged": false,- "renamed": false,- "deleted": false- },- "branch_op_state": "",- "main_divergence": "Diverged",- "upstream_divergence": "",- "worktree_state": ""+ "path": "[REPO].feature-ahead",+ "kind": "worktree",+ "commit": {+ "sha": "f16cd37915d5ee93903252f5cf877c76c54f3d50",+ "short_sha": "f16cd37",+ "message": "Feature commit 2",+ "timestamp": 0},- "status_symbols": {- "working_tree": "!?",- "branch_op_state": "",- "main_divergence": "↕",- "upstream_divergence": "",- "worktree_state": ""+ "working_tree": {+ "staged": false,+ "modified": true,+ "untracked": true,+ "renamed": false,+ "deleted": false,+ "diff": {+ "added": 1,+ "deleted": 1+ }},- "commits_display": "/u001b[32m↑2/u001b[0m /u001b[2m/u001b[31m↓2/u001b[0m",- "status_line": "feature-ahead /u001b[36m!/u001b[39m/u001b[36m?/u001b[39m/u001b[2m↕/u001b[22m @/u001b[32m+1/u001b[0m /u001b[31m-1/u001b[0m /u001b[32m↑2/u001b[0m /u001b[2m/u001b[31m↓2/u001b[0m",- "type": "worktree",- "path": "[REPO].feature-ahead",- "bare": false,- "detached": false,- "working_tree_diff": {- "added": 1,- "deleted": 1+ "main": {+ "ahead": 2,+ "behind": 2+ },+ "worktree": {+ "detached": false,+ "bare": false},- "working_tree_diff_with_main": null,"is_main": false,- "working_diff_display": "/u001b[32m+1/u001b[0m /u001b[31m-1/u001b[0m"+ "statusline": "feature-ahead /u001b[36m!/u001b[39m/u001b[36m?/u001b[39m/u001b[2m↕/u001b[22m @/u001b[32m+1/u001b[0m /u001b[31m-1/u001b[0m /u001b[32m↑2/u001b[0m /u001b[2m/u001b[31m↓2/u001b[0m",+ "symbols": "!?↕"},{- "head_sha": "6c3da84215d400bf6e05a7f9cd1efcfbd825b9e9","branch": "feature-behind",- "timestamp": 0,- "commit_message": "Initial commit on main",- "ahead": 0,- "behind": 2,- "upstream_remote": null,- "upstream_ahead": 0,- "upstream_behind": 0,- "pr_status": null,- "status": {- "working_tree": {- "untracked": false,- "modified": false,- "staged": false,- "renamed": false,- "deleted": false- },- "branch_op_state": "SameCommit",- "main_divergence": "Behind",- "upstream_divergence": "",- "worktree_state": ""+ "path": "[REPO].feature-behind",+ "kind": "worktree",+ "commit": {+ "sha": "6c3da84215d400bf6e05a7f9cd1efcfbd825b9e9",+ "short_sha": "6c3da84",+ "message": "Initial commit on main",+ "timestamp": 0},- "status_symbols": {- "working_tree": "",- "branch_op_state": "·",- "main_divergence": "↓",- "upstream_divergence": "",- "worktree_state": ""+ "working_tree": {+ "staged": false,+ "modified": false,+ "untracked": false,+ "renamed": false,+ "deleted": false,+ "diff": {+ "added": 0,+ "deleted": 0+ }},- "commits_display": "/u001b[2m/u001b[31m↓2/u001b[0m",- "status_line": "feature-behind /u001b[2m·/u001b[22m/u001b[2m↓/u001b[22m /u001b[2m/u001b[31m↓2/u001b[0m",- "type": "worktree",- "path": "[REPO].feature-behind",- "bare": false,- "detached": false,- "working_tree_diff": {- "added": 0,- "deleted": 0+ "branch_state": "same_commit",+ "main": {+ "ahead": 0,+ "behind": 2+ },+ "worktree": {+ "detached": false,+ "bare": false},- "working_tree_diff_with_main": null,- "is_main": false+ "is_main": false,+ "statusline": "feature-behind /u001b[2m·/u001b[22m/u001b[2m↓/u001b[22m /u001b[2m/u001b[31m↓2/u001b[0m",+ "symbols": "·↓"}]diff --git a/tests/snapshots/integration__integration_tests__list__json_with_git_operation.snap b/tests/snapshots/integration__integration_tests__list__json_with_git_operation.snapindex 4541405d1..d693e9dbb 100644--- a/tests/snapshots/integration__integration_tests__list__json_with_git_operation.snap+++ b/tests/snapshots/integration__integration_tests__list__json_with_git_operation.snap@@ -23,98 +23,76 @@ exit_code: 0----- stdout -----[{- "head_sha": "f4fa1ba1ca52a38a0036c3c9dd8b486a83ced1e5","branch": "main",- "timestamp": 0,- "commit_message": "Main conflicting changes",- "ahead": 0,- "behind": 0,- "upstream_remote": null,- "upstream_ahead": 0,- "upstream_behind": 0,- "pr_status": null,- "status": {- "working_tree": {- "untracked": false,- "modified": false,- "staged": false,- "renamed": false,- "deleted": false- },- "branch_op_state": "",- "main_divergence": "IsMain",- "upstream_divergence": "",- "worktree_state": ""- },- "status_symbols": {- "working_tree": "",- "branch_op_state": "",- "main_divergence": "^",- "upstream_divergence": "",- "worktree_state": ""- },- "status_line": "main /u001b[2m^/u001b[22m",- "type": "worktree","path": "[REPO]",- "bare": false,- "detached": false,- "working_tree_diff": {- "added": 0,- "deleted": 0+ "kind": "worktree",+ "commit": {+ "sha": "f4fa1ba1ca52a38a0036c3c9dd8b486a83ced1e5",+ "short_sha": "f4fa1ba",+ "message": "Main conflicting changes",+ "timestamp": 0+ },+ "working_tree": {+ "staged": false,+ "modified": false,+ "untracked": false,+ "renamed": false,+ "deleted": false,+ "diff": {+ "added": 0,+ "deleted": 0+ },+ "diff_vs_main": {+ "added": 0,+ "deleted": 0+ }},- "working_tree_diff_with_main": {- "added": 0,- "deleted": 0+ "worktree": {+ "detached": false,+ "bare": false},"is_main": true,- "is_current": true+ "is_current": true,+ "statusline": "main /u001b[2m^/u001b[22m",+ "symbols": "^"},{- "head_sha": "f4fa1ba1ca52a38a0036c3c9dd8b486a83ced1e5","branch": "feature",- "timestamp": 0,- "commit_message": "Main conflicting changes",- "ahead": 0,- "behind": 0,- "upstream_remote": null,- "upstream_ahead": 0,- "upstream_behind": 0,- "pr_status": null,- "status": {- "working_tree": {- "untracked": false,- "modified": false,- "staged": false,- "renamed": false,- "deleted": false- },- "branch_op_state": "Conflicts",- "main_divergence": "",- "upstream_divergence": "",- "worktree_state": ""+ "path": "[REPO].feature",+ "kind": "worktree",+ "commit": {+ "sha": "f4fa1ba1ca52a38a0036c3c9dd8b486a83ced1e5",+ "short_sha": "f4fa1ba",+ "message": "Main conflicting changes",+ "timestamp": 0},- "status_symbols": {- "working_tree": "",- "branch_op_state": "✘",- "main_divergence": "",- "upstream_divergence": "",- "worktree_state": ""+ "working_tree": {+ "staged": false,+ "modified": false,+ "untracked": false,+ "renamed": false,+ "deleted": false,+ "diff": {+ "added": 0,+ "deleted": 0+ },+ "diff_vs_main": {+ "added": 0,+ "deleted": 0+ }},- "status_line": "feature /u001b[31m✘/u001b[39m",- "type": "worktree",- "path": "[REPO].feature",- "bare": false,- "detached": true,- "working_tree_diff": {- "added": 0,- "deleted": 0+ "branch_state": "conflicts",+ "main": {+ "ahead": 0,+ "behind": 0},- "working_tree_diff_with_main": {- "added": 0,- "deleted": 0+ "worktree": {+ "detached": true,+ "bare": false},- "git_operation": "rebase",- "is_main": false+ "is_main": false,+ "statusline": "feature /u001b[31m✘/u001b[39m",+ "symbols": "✘"}]diff --git a/tests/snapshots/integration__integration_tests__list__json_with_metadata.snap b/tests/snapshots/integration__integration_tests__list__json_with_metadata.snapindex 2071eaf61..2e759d821 100644--- a/tests/snapshots/integration__integration_tests__list__json_with_metadata.snap+++ b/tests/snapshots/integration__integration_tests__list__json_with_metadata.snap@@ -23,144 +23,116 @@ exit_code: 0----- stdout -----[{- "head_sha": "b834638e33dbc6b37002685ee0777f4b8f1af904","branch": "main",- "timestamp": 0,- "commit_message": "Initial commit",- "ahead": 0,- "behind": 0,- "upstream_remote": null,- "upstream_ahead": 0,- "upstream_behind": 0,- "pr_status": null,- "status": {- "working_tree": {- "untracked": false,- "modified": false,- "staged": false,- "renamed": false,- "deleted": false- },- "branch_op_state": "",- "main_divergence": "IsMain",- "upstream_divergence": "",- "worktree_state": ""- },- "status_symbols": {- "working_tree": "",- "branch_op_state": "",- "main_divergence": "^",- "upstream_divergence": "",- "worktree_state": ""- },- "status_line": "main /u001b[2m^/u001b[22m",- "type": "worktree","path": "[REPO]",- "bare": false,- "detached": false,- "working_tree_diff": {- "added": 0,- "deleted": 0+ "kind": "worktree",+ "commit": {+ "sha": "b834638e33dbc6b37002685ee0777f4b8f1af904",+ "short_sha": "b834638",+ "message": "Initial commit",+ "timestamp": 0},- "working_tree_diff_with_main": {- "added": 0,- "deleted": 0+ "working_tree": {+ "staged": false,+ "modified": false,+ "untracked": false,+ "renamed": false,+ "deleted": false,+ "diff": {+ "added": 0,+ "deleted": 0+ },+ "diff_vs_main": {+ "added": 0,+ "deleted": 0+ }+ },+ "worktree": {+ "detached": false,+ "bare": false},"is_main": true,- "is_current": true+ "is_current": true,+ "statusline": "main /u001b[2m^/u001b[22m",+ "symbols": "^"},{- "head_sha": "b834638e33dbc6b37002685ee0777f4b8f1af904","branch": "feature-detached",- "timestamp": 0,- "commit_message": "Initial commit",- "ahead": 0,- "behind": 0,- "upstream_remote": null,- "upstream_ahead": 0,- "upstream_behind": 0,- "pr_status": null,- "status": {- "working_tree": {- "untracked": false,- "modified": false,- "staged": false,- "renamed": false,- "deleted": false- },- "branch_op_state": "SameCommit",- "main_divergence": "",- "upstream_divergence": "",- "worktree_state": ""+ "path": "[REPO].feature-detached",+ "kind": "worktree",+ "commit": {+ "sha": "b834638e33dbc6b37002685ee0777f4b8f1af904",+ "short_sha": "b834638",+ "message": "Initial commit",+ "timestamp": 0},- "status_symbols": {- "working_tree": "",- "branch_op_state": "·",- "main_divergence": "",- "upstream_divergence": "",- "worktree_state": ""+ "working_tree": {+ "staged": false,+ "modified": false,+ "untracked": false,+ "renamed": false,+ "deleted": false,+ "diff": {+ "added": 0,+ "deleted": 0+ },+ "diff_vs_main": {+ "added": 0,+ "deleted": 0+ }},- "status_line": "feature-detached /u001b[2m·/u001b[22m",- "type": "worktree",- "path": "[REPO].feature-detached",- "bare": false,- "detached": false,- "working_tree_diff": {- "added": 0,- "deleted": 0+ "branch_state": "same_commit",+ "main": {+ "ahead": 0,+ "behind": 0},- "working_tree_diff_with_main": {- "added": 0,- "deleted": 0+ "worktree": {+ "detached": false,+ "bare": false},- "is_main": false+ "is_main": false,+ "statusline": "feature-detached /u001b[2m·/u001b[22m",+ "symbols": "·"},{- "head_sha": "b834638e33dbc6b37002685ee0777f4b8f1af904","branch": "locked-feature",- "timestamp": 0,- "commit_message": "Initial commit",- "ahead": 0,- "behind": 0,- "upstream_remote": null,- "upstream_ahead": 0,- "upstream_behind": 0,- "pr_status": null,- "status": {- "working_tree": {- "untracked": false,- "modified": false,- "staged": false,- "renamed": false,- "deleted": false- },- "branch_op_state": "SameCommit",- "main_divergence": "",- "upstream_divergence": "",- "worktree_state": "Locked"+ "path": "[REPO].locked-feature",+ "kind": "worktree",+ "commit": {+ "sha": "b834638e33dbc6b37002685ee0777f4b8f1af904",+ "short_sha": "b834638",+ "message": "Initial commit",+ "timestamp": 0},- "status_symbols": {- "working_tree": "",- "branch_op_state": "·",- "main_divergence": "",- "upstream_divergence": "",- "worktree_state": "⊞"+ "working_tree": {+ "staged": false,+ "modified": false,+ "untracked": false,+ "renamed": false,+ "deleted": false,+ "diff": {+ "added": 0,+ "deleted": 0+ },+ "diff_vs_main": {+ "added": 0,+ "deleted": 0+ }},- "status_line": "locked-feature /u001b[2m·/u001b[22m/u001b[33m⊞/u001b[39m",- "type": "worktree",- "path": "[REPO].locked-feature",- "bare": false,- "detached": false,- "locked": "Testing",- "working_tree_diff": {- "added": 0,- "deleted": 0+ "branch_state": "same_commit",+ "main": {+ "ahead": 0,+ "behind": 0},- "working_tree_diff_with_main": {- "added": 0,- "deleted": 0+ "worktree": {+ "state": "locked",+ "reason": "Testing",+ "detached": false,+ "bare": false},- "is_main": false+ "is_main": false,+ "statusline": "locked-feature /u001b[2m·/u001b[22m/u001b[33m⊞/u001b[39m",+ "symbols": "·⊞"}]diff --git a/tests/snapshots/integration__integration_tests__list__json_with_user_marker.snap b/tests/snapshots/integration__integration_tests__list__json_with_user_marker.snapindex 55c08e6f6..eb407c50c 100644--- a/tests/snapshots/integration__integration_tests__list__json_with_user_marker.snap+++ b/tests/snapshots/integration__integration_tests__list__json_with_user_marker.snap@@ -23,145 +23,114 @@ exit_code: 0----- stdout -----[{- "head_sha": "b834638e33dbc6b37002685ee0777f4b8f1af904","branch": "main",- "timestamp": 0,- "commit_message": "Initial commit",- "ahead": 0,- "behind": 0,- "upstream_remote": null,- "upstream_ahead": 0,- "upstream_behind": 0,- "pr_status": null,- "status": {- "working_tree": {- "untracked": false,- "modified": false,- "staged": false,- "renamed": false,- "deleted": false- },- "branch_op_state": "",- "main_divergence": "IsMain",- "upstream_divergence": "",- "worktree_state": ""- },- "status_symbols": {- "working_tree": "",- "branch_op_state": "",- "main_divergence": "^",- "upstream_divergence": "",- "worktree_state": ""- },- "status_line": "main /u001b[2m^/u001b[22m",- "type": "worktree","path": "[REPO]",- "bare": false,- "detached": false,- "working_tree_diff": {- "added": 0,- "deleted": 0+ "kind": "worktree",+ "commit": {+ "sha": "b834638e33dbc6b37002685ee0777f4b8f1af904",+ "short_sha": "b834638",+ "message": "Initial commit",+ "timestamp": 0},- "working_tree_diff_with_main": {- "added": 0,- "deleted": 0+ "working_tree": {+ "staged": false,+ "modified": false,+ "untracked": false,+ "renamed": false,+ "deleted": false,+ "diff": {+ "added": 0,+ "deleted": 0+ },+ "diff_vs_main": {+ "added": 0,+ "deleted": 0+ }+ },+ "worktree": {+ "detached": false,+ "bare": false},"is_main": true,- "is_current": true+ "is_current": true,+ "statusline": "main /u001b[2m^/u001b[22m",+ "symbols": "^"},{- "head_sha": "b834638e33dbc6b37002685ee0777f4b8f1af904","branch": "with-status",- "timestamp": 0,- "commit_message": "Initial commit",- "ahead": 0,- "behind": 0,- "upstream_remote": null,- "upstream_ahead": 0,- "upstream_behind": 0,- "pr_status": null,- "status": {- "working_tree": {- "untracked": false,- "modified": false,- "staged": false,- "renamed": false,- "deleted": false- },- "branch_op_state": "SameCommit",- "main_divergence": "",- "upstream_divergence": "",- "worktree_state": "",- "user_marker": "🔧"+ "path": "[REPO].with-status",+ "kind": "worktree",+ "commit": {+ "sha": "b834638e33dbc6b37002685ee0777f4b8f1af904",+ "short_sha": "b834638",+ "message": "Initial commit",+ "timestamp": 0},- "status_symbols": {- "working_tree": "",- "branch_op_state": "·",- "main_divergence": "",- "upstream_divergence": "",- "worktree_state": "",- "user_marker": "🔧"+ "working_tree": {+ "staged": false,+ "modified": false,+ "untracked": false,+ "renamed": false,+ "deleted": false,+ "diff": {+ "added": 0,+ "deleted": 0+ },+ "diff_vs_main": {+ "added": 0,+ "deleted": 0+ }},- "status_line": "with-status /u001b[2m·/u001b[22m🔧",- "type": "worktree",- "path": "[REPO].with-status",- "bare": false,- "detached": false,- "working_tree_diff": {- "added": 0,- "deleted": 0+ "branch_state": "same_commit",+ "main": {+ "ahead": 0,+ "behind": 0},- "working_tree_diff_with_main": {- "added": 0,- "deleted": 0+ "worktree": {+ "detached": false,+ "bare": false},- "is_main": false+ "is_main": false,+ "statusline": "with-status /u001b[2m·/u001b[22m🔧",+ "symbols": "·🔧"},{- "head_sha": "b834638e33dbc6b37002685ee0777f4b8f1af904","branch": "without-status",- "timestamp": 0,- "commit_message": "Initial commit",- "ahead": 0,- "behind": 0,- "upstream_remote": null,- "upstream_ahead": 0,- "upstream_behind": 0,- "pr_status": null,- "status": {- "working_tree": {- "untracked": false,- "modified": false,- "staged": false,- "renamed": false,- "deleted": false- },- "branch_op_state": "SameCommit",- "main_divergence": "",- "upstream_divergence": "",- "worktree_state": ""+ "path": "[REPO].without-status",+ "kind": "worktree",+ "commit": {+ "sha": "b834638e33dbc6b37002685ee0777f4b8f1af904",+ "short_sha": "b834638",+ "message": "Initial commit",+ "timestamp": 0},- "status_symbols": {- "working_tree": "",- "branch_op_state": "·",- "main_divergence": "",- "upstream_divergence": "",- "worktree_state": ""+ "working_tree": {+ "staged": false,+ "modified": false,+ "untracked": false,+ "renamed": false,+ "deleted": false,+ "diff": {+ "added": 0,+ "deleted": 0+ },+ "diff_vs_main": {+ "added": 0,+ "deleted": 0+ }},- "status_line": "without-status /u001b[2m·/u001b[22m",- "type": "worktree",- "path": "[REPO].without-status",- "bare": false,- "detached": false,- "working_tree_diff": {- "added": 0,- "deleted": 0+ "branch_state": "same_commit",+ "main": {+ "ahead": 0,+ "behind": 0},- "working_tree_diff_with_main": {- "added": 0,- "deleted": 0+ "worktree": {+ "detached": false,+ "bare": false},- "is_main": false+ "is_main": false,+ "statusline": "without-status /u001b[2m·/u001b[22m",+ "symbols": "·"}]