@@ -200,6 +200,17 @@ pub struct AcpClient {
200200 /// deltas. Both goose and buzz-agent emit this notification; goose gates
201201 /// on client capability advertisement, buzz-agent emits unconditionally.
202202 goose_usage : UsageTracker ,
203+ /// Accumulated `agent_message_chunk` text for the current turn. Used by the
204+ /// content-delivery fallback: weak local models (e.g. via Buzz shared
205+ /// compute) often answer a conversational prompt in plain assistant
206+ /// `content` instead of calling `buzz messages send`, which would otherwise
207+ /// be silently dropped (buzz-agent's output is its tool calls; streamed
208+ /// text is observability-only). Reset at the start of every turn.
209+ turn_message_text : String ,
210+ /// Whether a `buzz messages send` (or forum-post/comment) publish tool call
211+ /// was observed this turn. When true the fallback does NOT fire — the agent
212+ /// delivered its own reply. Reset at the start of every turn.
213+ turn_sent_message : bool ,
203214}
204215
205216/// Recursively merge `overlay` into `base`, with `overlay` winning on scalar/shape
@@ -492,6 +503,8 @@ impl AcpClient {
492503 active_run_id : None ,
493504 steer_rx : None ,
494505 goose_usage : UsageTracker :: default ( ) ,
506+ turn_message_text : String :: new ( ) ,
507+ turn_sent_message : false ,
495508 } )
496509 }
497510
@@ -685,6 +698,10 @@ impl AcpClient {
685698 // misattributed to this turn.
686699 self . goose_usage . begin_turn ( session_id) ;
687700
701+ // Reset the content-delivery fallback trackers for this turn.
702+ self . turn_message_text . clear ( ) ;
703+ self . turn_sent_message = false ;
704+
688705 self . last_prompt_id = Some ( self . next_id ) ;
689706 let id = self . next_id ;
690707 self . next_id += 1 ;
@@ -780,6 +797,29 @@ impl AcpClient {
780797 self . goose_usage . take ( )
781798 }
782799
800+ /// Take the accumulated assistant `content` text for the completed turn,
801+ /// if and only if the agent did NOT publish a message itself this turn.
802+ ///
803+ /// Returns `Some(trimmed_text)` when the turn produced streamed assistant
804+ /// content but no `buzz messages send` tool call fired — the caller then
805+ /// delivers it as the channel reply (content-delivery fallback). Returns
806+ /// `None` when the agent sent its own message, when there was no content,
807+ /// or when the content is only a bare acknowledgement (which the base
808+ /// prompt forbids publishing). Clears the buffer either way.
809+ pub fn take_undelivered_turn_message ( & mut self ) -> Option < String > {
810+ let text = std:: mem:: take ( & mut self . turn_message_text ) ;
811+ let sent = self . turn_sent_message ;
812+ self . turn_sent_message = false ;
813+ if sent {
814+ return None ;
815+ }
816+ let trimmed = text. trim ( ) ;
817+ if trimmed. is_empty ( ) || is_bare_acknowledgement ( trimmed) {
818+ return None ;
819+ }
820+ Some ( trimmed. to_string ( ) )
821+ }
822+
783823 /// Install a per-turn steer request channel for goose-native
784824 /// non-cancelling mid-turn delivery.
785825 ///
@@ -1531,6 +1571,10 @@ impl AcpClient {
15311571 "agent_message_chunk" => {
15321572 if let Some ( text) = update[ "content" ] [ "text" ] . as_str ( ) {
15331573 tracing:: info!( target: "acp::stream" , "{text}" ) ;
1574+ // Accumulate for the content-delivery fallback (see
1575+ // `turn_message_text`). Streamed assistant text is otherwise
1576+ // observability-only and never posted to the channel.
1577+ self . turn_message_text . push_str ( text) ;
15341578 }
15351579 false
15361580 }
@@ -1544,6 +1588,17 @@ impl AcpClient {
15441588 . and_then ( |v| v. as_str ( ) )
15451589 . unwrap_or ( "unknown" ) ;
15461590 tracing:: info!( target: "acp::tool" , "tool_call: {title} ({kind})" ) ;
1591+ // Detect a message-publish tool call so the fallback knows the
1592+ // agent delivered its own reply. The publish path is the
1593+ // dev-mcp `shell` tool running `buzz messages send` (title is
1594+ // the tool name, rawInput carries the command/args), so scan
1595+ // both title and rawInput for the CLI publish signature.
1596+ if tool_call_is_message_publish ( update) {
1597+ self . turn_sent_message = true ;
1598+ // Debug-level: the model published its own reply, so the
1599+ // content-delivery fallback will stay dormant this turn.
1600+ tracing:: debug!( "agent published its own message via send tool ({title})" ) ;
1601+ }
15471602 true
15481603 }
15491604 "tool_call_update" => {
@@ -1944,6 +1999,73 @@ pub fn model_in_catalog(
19441999 } )
19452000}
19462001
2002+ /// Return true if a `tool_call` session update represents a Buzz message
2003+ /// publish (kind 9 / forum post / comment). The publish path is the dev-mcp
2004+ /// `shell` tool running `buzz messages send` (or `buzz social publish`), so the
2005+ /// tool name alone is not enough — inspect `rawInput` (the command/args) for the
2006+ /// CLI publish signature. Conservative: only matches an actual send subcommand,
2007+ /// not reads like `buzz messages get`.
2008+ fn tool_call_is_message_publish ( update : & serde_json:: Value ) -> bool {
2009+ // Flatten title + rawInput into one lowercase haystack. rawInput is
2010+ // arbitrary JSON (shell command string, or structured args), so serialize
2011+ // whatever is there.
2012+ let mut haystack = String :: new ( ) ;
2013+ if let Some ( title) = update. get ( "title" ) . and_then ( |v| v. as_str ( ) ) {
2014+ haystack. push_str ( title) ;
2015+ haystack. push ( ' ' ) ;
2016+ }
2017+ if let Some ( raw) = update. get ( "rawInput" ) {
2018+ haystack. push_str ( & raw. to_string ( ) ) ;
2019+ }
2020+ let h = haystack. to_ascii_lowercase ( ) ;
2021+ // Match the publish subcommands that actually post to a channel. Guard
2022+ // against read subcommands (get/thread/search/list) sharing the "messages"
2023+ // prefix by requiring the send/publish verb.
2024+ h. contains ( "messages send" ) || h. contains ( "messages send-diff" ) || h. contains ( "social publish" )
2025+ }
2026+
2027+ /// Return true if `text` is a bare acknowledgement the base prompt forbids
2028+ /// publishing ("Got it", "Confirmed", "Standing by", …). Used to keep the
2029+ /// content-delivery fallback from posting filler that a capable agent would
2030+ /// have suppressed. Deliberately conservative — only short, whole-message
2031+ /// acks match, so a substantive reply that merely opens with "Got it, …"
2032+ /// still gets delivered.
2033+ fn is_bare_acknowledgement ( text : & str ) -> bool {
2034+ // Only consider short messages — a real reply with content is never a bare
2035+ // ack even if it starts with one.
2036+ if text. chars ( ) . count ( ) > 40 {
2037+ return false ;
2038+ }
2039+ let normalized: String = text
2040+ . to_ascii_lowercase ( )
2041+ . chars ( )
2042+ . filter ( |c| c. is_alphanumeric ( ) || c. is_whitespace ( ) )
2043+ . collect ( ) ;
2044+ let normalized = normalized. trim ( ) ;
2045+ const BARE_ACKS : & [ & str ] = & [
2046+ "got it" ,
2047+ "confirmed" ,
2048+ "acknowledged" ,
2049+ "ack" ,
2050+ "clear and noted" ,
2051+ "noted" ,
2052+ "aligned" ,
2053+ "standing by" ,
2054+ "parked" ,
2055+ "ok" ,
2056+ "okay" ,
2057+ "will do" ,
2058+ "understood" ,
2059+ "sounds good" ,
2060+ "on it" ,
2061+ "roger" ,
2062+ "roger that" ,
2063+ "i wont reply again" ,
2064+ "i will not reply again" ,
2065+ ] ;
2066+ BARE_ACKS . contains ( & normalized)
2067+ }
2068+
19472069// ─── Drop: kill child process ─────────────────────────────────────────────────
19482070
19492071impl Drop for AcpClient {
@@ -1991,6 +2113,70 @@ fn kill_process_group(_pid: u32) -> bool {
19912113mod tests {
19922114 use super :: * ;
19932115
2116+ #[ test]
2117+ fn tool_call_publish_detection ( ) {
2118+ // A `buzz messages send` shell tool call → detected as a publish.
2119+ let send = serde_json:: json!( {
2120+ "title" : "shell" ,
2121+ "rawInput" : { "command" : "buzz messages send --channel abc --content 'hi'" }
2122+ } ) ;
2123+ assert ! ( tool_call_is_message_publish( & send) ) ;
2124+
2125+ // send-diff variant → detected.
2126+ let diff = serde_json:: json!( {
2127+ "title" : "shell" ,
2128+ "rawInput" : { "command" : "buzz messages send-diff --channel abc" }
2129+ } ) ;
2130+ assert ! ( tool_call_is_message_publish( & diff) ) ;
2131+
2132+ // social publish → detected.
2133+ let social = serde_json:: json!( {
2134+ "title" : "shell" ,
2135+ "rawInput" : { "command" : "buzz social publish --content x" }
2136+ } ) ;
2137+ assert ! ( tool_call_is_message_publish( & social) ) ;
2138+
2139+ // A READ subcommand sharing the "messages" prefix → NOT a publish.
2140+ let read = serde_json:: json!( {
2141+ "title" : "shell" ,
2142+ "rawInput" : { "command" : "buzz messages get --channel abc" }
2143+ } ) ;
2144+ assert ! ( !tool_call_is_message_publish( & read) ) ;
2145+
2146+ // Unrelated tool → not a publish.
2147+ let other = serde_json:: json!( {
2148+ "title" : "read_file" ,
2149+ "rawInput" : { "path" : "/tmp/foo" }
2150+ } ) ;
2151+ assert ! ( !tool_call_is_message_publish( & other) ) ;
2152+ }
2153+
2154+ #[ test]
2155+ fn bare_acknowledgement_detection ( ) {
2156+ // Bare acks the base prompt forbids publishing.
2157+ for ack in [
2158+ "Got it" ,
2159+ "confirmed" ,
2160+ "Standing by" ,
2161+ "OK" ,
2162+ " Noted. " ,
2163+ "will do" ,
2164+ ] {
2165+ assert ! ( is_bare_acknowledgement( ack) , "should be bare ack: {ack:?}" ) ;
2166+ }
2167+ // Substantive replies are NOT bare acks, even if they open with one.
2168+ for real in [
2169+ "Got it — I'll start on the migration and report back when the tests pass." ,
2170+ "I'm doing well, thank you for asking! How are you today?" ,
2171+ "The build failed: missing dependency in Cargo.toml." ,
2172+ ] {
2173+ assert ! (
2174+ !is_bare_acknowledgement( real) ,
2175+ "should NOT be bare ack: {real:?}"
2176+ ) ;
2177+ }
2178+ }
2179+
19942180 #[ test]
19952181 fn stop_reason_parses_all_known_values ( ) {
19962182 assert_eq ! ( StopReason :: from_str( "end_turn" ) , Some ( StopReason :: EndTurn ) ) ;
0 commit comments