(
&self,
path: &Path,
prev: StoredCursor,
project_root: &Path,
max_new_bytes: Option<u64>,
)
| 79 | } |
| 80 | |
| 81 | fn parse_new( |
| 82 | &self, |
| 83 | path: &Path, |
| 84 | prev: StoredCursor, |
| 85 | project_root: &Path, |
| 86 | max_new_bytes: Option<u64>, |
| 87 | ) -> Option<ParsedTranscript> { |
| 88 | let subagent = claude_subagent_identity(path); |
| 89 | // Cheap session scoping: the first/parent cwd describes where the |
| 90 | // session began, but individual Claude rows can carry their own cwd. |
| 91 | // Filter messages per row so sessions that cross worktrees are split |
| 92 | // into the right project stores without losing transcript truth. |
| 93 | let session_cwd = transcript_cwd(path).or_else(|| { |
| 94 | subagent |
| 95 | .as_ref() |
| 96 | .and_then(|info| transcript_cwd(&info.parent_transcript_path)) |
| 97 | }); |
| 98 | |
| 99 | let new = stream_new_jsonl(path, prev, max_new_bytes)?; |
| 100 | let session_id = subagent.as_ref().map_or_else( |
| 101 | || { |
| 102 | path.file_stem() |
| 103 | .and_then(|stem| stem.to_str()) |
| 104 | .unwrap_or("unknown") |
| 105 | .to_string() |
| 106 | }, |
| 107 | |info| info.session_id.clone(), |
| 108 | ); |
| 109 | |
| 110 | let mut messages = Vec::new(); |
| 111 | for line in &new.lines { |
| 112 | let line_cwd = record_cwd(&line.value).or_else(|| session_cwd.clone()); |
| 113 | if !line_cwd |
| 114 | .as_deref() |
| 115 | .is_some_and(|cwd| path_belongs_to_project(cwd, project_root)) |
| 116 | { |
| 117 | continue; |
| 118 | } |
| 119 | if let Some(message) = message_from_line( |
| 120 | &line.value, |
| 121 | &session_id, |
| 122 | path, |
| 123 | line.offset, |
| 124 | session_cwd.as_deref(), |
| 125 | ) { |
| 126 | messages.push(message); |
| 127 | } |
| 128 | } |
| 129 | // No early return when `messages` is empty: this source scans every |
| 130 | // ~/.claude/projects slug and relies on the per-row cwd filter above, |
| 131 | // so transcripts belonging to other projects legitimately parse to |
| 132 | // zero messages. Returning the (empty) transcript lets `ingest_one` |
| 133 | // persist the advanced cursor; returning `None` would pin the cursor |
| 134 | // at 0 and re-read + re-filter the whole file on every sweep. |
| 135 | |
| 136 | let project = project_root.to_string_lossy().to_string(); |
| 137 | let draft = SessionDraft { |
| 138 | session_id, |
nothing calls this directly
no test coverage detected