MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / condense_claude_transcript

Function condense_claude_transcript

atomic-agent/src/transcript/condense.rs:35–86  ·  view source on GitHub ↗

Parse a Claude Code JSONL transcript into condensed entries. Reads each line as JSON, extracts user prompts, assistant text responses, and tool calls. Filters out: - Skill content injections (verbose skill instructions in user messages) - Full file contents from Read tool responses - Verbose tool outputs # Arguments `raw` — Raw JSONL bytes from the Claude Code transcript file # Returns A vect

(raw: &[u8])

Source from the content-addressed store, hash-verified

33/// A vector of condensed entries suitable for display and summarization.
34/// Returns an empty vector if the transcript is empty or unparseable.
35pub fn condense_claude_transcript(raw: &[u8]) -> Vec<CondensedEntry> {
36 let mut entries = Vec::new();
37
38 for line in raw.split(|&b| b == b'\n') {
39 if line.is_empty() {
40 continue;
41 }
42
43 let Ok(parsed) = serde_json::from_slice::<TranscriptLine>(line) else {
44 continue;
45 };
46
47 match parsed.r#type.as_str() {
48 "user" => {
49 if let Some(content) = extract_user_content(&parsed.message) {
50 // Skip skill content injections
51 if !content.starts_with(SKILL_CONTENT_PREFIX) {
52 entries.push(CondensedEntry::user(content));
53 }
54 }
55 }
56 "assistant" => {
57 if let Ok(msg) = serde_json::from_value::<AssistantMessage>(parsed.message) {
58 let blocks = match msg.content {
59 AssistantContent::Plain(text) => {
60 if !text.is_empty() {
61 entries.push(CondensedEntry::assistant(&text));
62 }
63 Vec::new()
64 }
65 AssistantContent::Blocks(blocks) => blocks,
66 };
67 for block in &blocks {
68 match block.r#type.as_str() {
69 "text" if !block.text.is_empty() => {
70 entries.push(CondensedEntry::assistant(&block.text));
71 }
72 "tool_use" => {
73 let detail = extract_tool_detail(&block.name, &block.input);
74 entries.push(CondensedEntry::tool(&block.name, detail));
75 }
76 _ => {}
77 }
78 }
79 }
80 }
81 _ => {}
82 }
83 }
84
85 entries
86}
87
88/// Condense a transcript from raw bytes, auto-detecting format.
89///

Calls 5

extract_user_contentFunction · 0.85
extract_tool_detailFunction · 0.85
is_emptyMethod · 0.45
as_strMethod · 0.45
pushMethod · 0.45