From 9622bf4c1e741878a1701b9ea1daa7f3a00c1b91 Mon Sep 17 00:00:00 2001 From: VallierDev <24893073+VallierDev@users.noreply.github.com> Date: Sat, 17 Oct 2026 23:30:13 +0800 Subject: [PATCH] fix(viewer): accept terminal RPC answers on the terminal channel The official Mac host answers check_env on the BINARY terminal channel next to TERM frames; the viewer parsed it as a TERM frame and closed. Verified live: Mac host terminal opens and echoes input. Co-Authored-By: Claude Opus 5.5 --- src/viewer/tools/terminal.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/viewer/tools/terminal.rs b/src/viewer/tools/terminal.rs index 5d838a3..4a3e9a0 100644 --- a/src/viewer/tools/terminal.rs +++ b/src/viewer/tools/terminal.rs @@ -40,7 +40,9 @@ impl Terminal { let worker=tokio::spawn(async move { let mut decoder=Decoder::default(); while let Some((channel,data))=rx.recv().await { - if channel==CONTROL { + // Terminal RPC answers (check_env) come on CONTROL or, from the official Mac host, on BINARY + // next to TERM frames (as this project's host does). + if channel==CONTROL || (channel==BINARY && !data.starts_with(b"TERM")) { if let Some(r)=blob(&data,22) {if let (Some(h),Some(body))=(blob(r,1),blob(r,24)) { if let Some(t)=p.lock().unwrap().remove(&(24,uint(h,1))) {let _=t.send(Ok(body.to_vec()));} }}continue @@ -85,7 +87,12 @@ impl Terminal { // "not implemented", not "unavailable"; go on and let OPEN report availability. match tokio::time::timeout(std::time::Duration::from_secs(3),self.request((24,id),CONTROL,wire::envelope(id,21,&r))).await{ Err(_)=>Ok(()), - Ok(b)=>{let b=b?;if uint(&b,1)!=0 {return Err("Terminal environment unavailable".into())}Ok(())} + Ok(b)=>{let b=b?;let code=uint(&b,1); + if code!=0 { + let message=blob(&b,2).map(|m|String::from_utf8_lossy(m).chars().take(80).collect::()).unwrap_or_default(); + log::info!("Terminal check_env: code={code} message={message:?}"); + return Err("Terminal environment unavailable".into()) + }Ok(())} } } pub async fn list_sessions(&self)->Result,String>{