MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / transcript_cwd

Function transcript_cwd

src/sessions/claude.rs:184–202  ·  view source on GitHub ↗

Reads the session `cwd` from an early line of a Claude transcript.

(path: &Path)

Source from the content-addressed store, hash-verified

182
183/// Reads the session `cwd` from an early line of a Claude transcript.
184pub(crate) fn transcript_cwd(path: &Path) -> Option<PathBuf> {
185 use std::io::BufRead;
186 let file = std::fs::File::open(path).ok()?;
187 let reader = std::io::BufReader::new(file);
188 for line in reader.lines().take(CWD_PROBE_LINES).map_while(Result::ok) {
189 let trimmed = line.trim();
190 if trimmed.is_empty() {
191 continue;
192 }
193 if let Ok(value) = serde_json::from_str::<Value>(trimmed) {
194 if let Some(cwd) = value.get("cwd").and_then(Value::as_str) {
195 if !cwd.is_empty() {
196 return Some(PathBuf::from(cwd));
197 }
198 }
199 }
200 }
201 None
202}
203
204/// Map one Claude transcript line to a provider-neutral message, or `None` for
205/// lines that carry no conversational text (tool-result-only, meta lines, …).

Callers 2

run_cwdFunction · 0.85
parse_newMethod · 0.85

Calls 2

takeMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected