Skip to content

Commit 78f3b82

Browse files
fix(csa-acp): include AgentThought in output for claude-code (#375) (#377)
* fix(csa-acp): include thoughts in output and stream to stderr #375 * chore(lockfile): update weave.lock
1 parent ae16992 commit 78f3b82

5 files changed

Lines changed: 71 additions & 24 deletions

File tree

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["crates/*"]
33
resolver = "2"
44

55
[workspace.package]
6-
version = "0.1.101"
6+
version = "0.1.102"
77
edition = "2024"
88
rust-version = "1.85"
99
license = "Apache-2.0"

crates/csa-acp/src/connection.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,17 +498,27 @@ fn stream_new_agent_messages(
498498

499499
let mut messages = Vec::new();
500500
for event in &events_ref[*processed_index..] {
501-
if let SessionEvent::AgentMessage(chunk) = event {
502-
messages.push(chunk.clone());
501+
match event {
502+
SessionEvent::AgentMessage(chunk) => {
503+
messages.push((chunk.clone(), false));
504+
}
505+
SessionEvent::AgentThought(chunk) => {
506+
messages.push((chunk.clone(), true));
507+
}
508+
_ => {}
503509
}
504510
}
505511
*processed_index = events_ref.len();
506512
messages
507513
};
508514

509-
for chunk in &new_messages {
515+
for (chunk, is_thought) in &new_messages {
510516
if stream_stdout_to_stderr {
511-
eprint!("[stdout] {chunk}");
517+
if *is_thought {
518+
eprint!("[thought] {chunk}");
519+
} else {
520+
eprint!("[stdout] {chunk}");
521+
}
512522
}
513523
spool_chunk(output_spool, chunk.as_bytes());
514524
}
@@ -525,8 +535,11 @@ fn spool_chunk(spool: &mut Option<std::fs::File>, bytes: &[u8]) {
525535
fn collect_agent_output(events: &[SessionEvent]) -> String {
526536
let mut output = String::new();
527537
for event in events {
528-
if let SessionEvent::AgentMessage(chunk) = event {
529-
output.push_str(chunk);
538+
match event {
539+
SessionEvent::AgentMessage(chunk) | SessionEvent::AgentThought(chunk) => {
540+
output.push_str(chunk);
541+
}
542+
_ => {}
530543
}
531544
}
532545
output

crates/csa-acp/src/connection_tests.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,40 @@ async fn env_remove_strips_claudecode_from_child() {
100100
);
101101
}
102102

103+
#[test]
104+
fn test_collect_agent_output_includes_thoughts() {
105+
let events = vec![
106+
SessionEvent::AgentMessage("Hello".to_string()),
107+
SessionEvent::AgentThought("Thinking...".to_string()),
108+
SessionEvent::AgentMessage(" world".to_string()),
109+
];
110+
let output = collect_agent_output(&events);
111+
assert_eq!(output, "HelloThinking... world");
112+
}
113+
114+
#[test]
115+
fn stream_new_agent_messages_includes_thoughts_in_spool() {
116+
let events = Rc::new(RefCell::new(Vec::new()));
117+
events
118+
.borrow_mut()
119+
.push(SessionEvent::AgentMessage("hello".to_string()));
120+
events
121+
.borrow_mut()
122+
.push(SessionEvent::AgentThought("...thinking".to_string()));
123+
124+
let temp = tempfile::tempdir().expect("tempdir");
125+
let spool_path = temp.path().join("output.log");
126+
let mut spool = open_output_spool_file(Some(&spool_path));
127+
let mut index = 0;
128+
129+
stream_new_agent_messages(&events, &mut index, false, &mut spool);
130+
assert_eq!(
131+
std::fs::read_to_string(&spool_path).expect("read spool"),
132+
"hello...thinking"
133+
);
134+
assert_eq!(index, 2);
135+
}
136+
103137
#[test]
104138
fn stream_new_agent_messages_writes_spool_incrementally() {
105139
let events = Rc::new(RefCell::new(Vec::new()));

weave.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
2-
csa = "0.1.100"
3-
weave = "0.1.100"
2+
csa = "0.1.101"
3+
weave = "0.1.101"
44
last_migrated_at = "2026-03-08T12:08:01.820964091Z"
55

66
[migrations]

0 commit comments

Comments
 (0)