1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//! `path show <provider> --session …` — emits a markdown summary for a single
//! session. Designed to back fzf's `--preview` window during interactive
//! derive selection, but also runnable on its own to inspect a session.
//!
//! Internally this derives the session's Path and renders it via
//! `toolpath_md` at `summary` detail, which keeps the output to file-level
//! diffstats — short enough for a preview pane, rich enough to choose by.
#![cfg(not(target_os = "emscripten"))]
use anyhow::Result;
use clap::Subcommand;
use toolpath::v1::Graph;
#[derive(Subcommand, Debug)]
pub enum ShowSource {
/// Show a Claude conversation as a markdown summary
Claude {
/// Project path (e.g., /Users/alex/myproject)
#[arg(short, long)]
project: String,
/// Session id (the file stem of the JSONL)
#[arg(short, long)]
session: String,
},
/// Show a Gemini CLI conversation as a markdown summary
Gemini {
/// Project path (e.g., /Users/alex/myproject)
#[arg(short, long)]
project: String,
/// Session UUID (the directory name under chats/)
#[arg(short, long)]
session: String,
},
/// Show a Codex CLI session as a markdown summary
Codex {
/// Session id, UUID, or filename stem
#[arg(short, long)]
session: String,
/// Compatibility shim for the unified `path share` preview template; ignored.
#[arg(long, hide = true)]
project: Option<std::path::PathBuf>,
},
/// Show an opencode session as a markdown summary
Opencode {
/// Session id (`ses_…`)
#[arg(short, long)]
session: String,
/// Compatibility shim for the unified `path share` preview template; ignored.
#[arg(long, hide = true)]
project: Option<std::path::PathBuf>,
},
/// Show a Pi (pi.dev) session as a markdown summary
Pi {
/// Project path
#[arg(short, long)]
project: String,
/// Session id
#[arg(short, long)]
session: String,
/// Override the Pi sessions base directory (default: ~/.pi/agent/sessions)
#[arg(long)]
base: Option<std::path::PathBuf>,
},
}
pub fn run(source: ShowSource, ansi: bool) -> Result<()> {
let path = derive_one(source)?;
let doc = Graph::from_path(path);
let opts = toolpath_md::RenderOptions {
detail: toolpath_md::Detail::Summary,
front_matter: false,
};
let md = toolpath_md::render(&doc, &opts);
if ansi {
print!("{}", crate::term::markdown_to_ansi(&md));
} else {
print!("{md}");
}
Ok(())
}
fn derive_one(source: ShowSource) -> Result<toolpath::v1::Path> {
match source {
ShowSource::Claude { project, session } => {
let manager = toolpath_claude::ClaudeConvo::new();
let convo = manager
.read_conversation(&project, &session)
.map_err(|e| anyhow::anyhow!("{}", e))?;
let cfg = toolpath_claude::derive::DeriveConfig {
project_path: Some(project),
include_thinking: false,
};
Ok(toolpath_claude::derive::derive_path(&convo, &cfg))
}
ShowSource::Gemini { project, session } => {
let manager = toolpath_gemini::GeminiConvo::new();
let convo = manager
.read_conversation(&project, &session)
.map_err(|e| anyhow::anyhow!("{}", e))?;
let cfg = toolpath_gemini::derive::DeriveConfig {
project_path: Some(project),
include_thinking: false,
};
Ok(toolpath_gemini::derive::derive_path(&convo, &cfg))
}
ShowSource::Codex {
session,
project: _,
} => {
let manager = toolpath_codex::CodexConvo::new();
let s = manager
.read_session(&session)
.map_err(|e| anyhow::anyhow!("{}", e))?;
let cfg = toolpath_codex::derive::DeriveConfig { project_path: None };
Ok(toolpath_codex::derive::derive_path(&s, &cfg))
}
ShowSource::Opencode {
session,
project: _,
} => {
let manager = toolpath_opencode::OpencodeConvo::new();
let s = manager
.read_session(&session)
.map_err(|e| anyhow::anyhow!("{}", e))?;
let cfg = toolpath_opencode::derive::DeriveConfig::default();
Ok(toolpath_opencode::derive::derive_path_with_resolver(
&s,
&cfg,
manager.resolver(),
))
}
ShowSource::Pi {
project,
session,
base,
} => {
let manager = if let Some(p) = base {
let resolver = toolpath_pi::PathResolver::new().with_sessions_dir(&p);
toolpath_pi::PiConvo::with_resolver(resolver)
} else {
toolpath_pi::PiConvo::new()
};
let s = manager
.read_session(&project, &session)
.map_err(|e| anyhow::anyhow!("{}", e))?;
let cfg = toolpath_pi::DeriveConfig::default();
Ok(toolpath_pi::derive::derive_path(&s, &cfg))
}
}
}