Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src-tauri/crates/agent-claude/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,32 @@ use tokio::process::{Child, ChildStdin, Command};
use tokio::sync::mpsc;

/// Tokens of transcript we are willing to replay on a handoff.

/// `CREATE_NO_WINDOW`. Stroke is a GUI process, so on Windows every console
/// program it starts (`claude --version`, the chat itself) got a console of
/// its own: a black cmd window popped up on top of the app each time, and the
/// focus jumping to it could take WebView2 down with it. Unix has nothing
/// like it, so off Windows these are no-ops.
#[cfg(windows)]
const CREATE_NO_WINDOW: u32 = 0x0800_0000;

/// Start this console program with no console window (Windows).
pub fn quiet(cmd: &mut Command) -> &mut Command {
#[cfg(windows)]
cmd.creation_flags(CREATE_NO_WINDOW);
cmd
}

/// The blocking-`Command` form of [`quiet`].
pub fn quiet_std(cmd: &mut std::process::Command) -> &mut std::process::Command {
#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
cmd.creation_flags(CREATE_NO_WINDOW);
}
cmd
}

const REPLAY_BUDGET: usize = 60_000;

/// Bound on buffered events. Deep enough to absorb a fast burst, shallow enough
Expand Down Expand Up @@ -191,7 +217,7 @@ impl AgentAdapter for ClaudeAdapter {
}

async fn probe(&self) -> Result<Availability, AgentError> {
let out = Command::new(&self.bin).arg("--version").output().await;
let out = quiet(Command::new(&self.bin).arg("--version")).output().await;
match out {
Ok(o) if o.status.success() => Ok(Availability::Ready {
version: Some(String::from_utf8_lossy(&o.stdout).trim().to_string()),
Expand All @@ -210,7 +236,7 @@ impl AgentAdapter for ClaudeAdapter {
let mcp_config = self.write_mcp_config(&ctx).await?;
let args = self.args(&ctx, mcp_config.as_ref());

let mut child = Command::new(&self.bin)
let mut child = quiet(&mut Command::new(&self.bin))
.args(&args)
.envs(ctx.env.iter().map(|(k, v)| (k, v)))
.current_dir(&ctx.cwd)
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/crates/agent-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl AgentAdapter for CliAdapter {
let listing = self.refresh_models();
// `--version` is the cheapest liveness check that does not hit the
// network or consume credits.
let version = Command::new(self.spec.bin)
let version = agent_claude::quiet(&mut Command::new(self.spec.bin))
.arg("--version")
.stdin(Stdio::null())
.output()
Expand Down Expand Up @@ -259,6 +259,7 @@ pub(crate) fn spawn_turn(
resuming: bool,
) -> Result<TurnHandle, AgentError> {
let mut cmd = Command::new(spec.bin);
agent_claude::quiet(&mut cmd);
cmd.args(&args)
.envs(spec.env.iter().copied())
.envs(ctx.env.iter().map(|(k, v)| (k, v)))
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/crates/agent-cli/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn leak(listed: Vec<Listed>) -> &'static [ModelSpec] {
/// Run a CLI's list command and read its answer. Blocks, so it runs on a
/// thread of its own.
pub(crate) fn read(bin: &str, list: &ListModels) -> Option<Vec<Listed>> {
let child = std::process::Command::new(bin)
let child = agent_claude::quiet_std(&mut std::process::Command::new(bin))
.args(list.args)
.stdin(Stdio::null())
.stdout(Stdio::piped())
Expand Down Expand Up @@ -169,7 +169,7 @@ pub(crate) async fn codex_default(bin: &str) -> Option<String> {
.and_then(|text| top_level(text, "model"))?;
let out = tokio::time::timeout(
Duration::from_secs(5),
tokio::process::Command::new(bin)
agent_claude::quiet(&mut tokio::process::Command::new(bin))
.args(["debug", "models"])
.stdin(Stdio::null())
.stderr(Stdio::null())
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/crates/agent-cli/src/opencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ kill -TERM 0"#;
/// opencode 2 moved the server's API under `/api` with new routes, which the
/// session below does not speak; on 2 and later each turn is an `opencode run`.
pub(crate) async fn serve_api_moved(bin: &str) -> bool {
let out = Command::new(bin)
let out = agent_claude::quiet(&mut Command::new(bin))
.arg("--version")
.stdin(Stdio::null())
.output()
Expand Down
10 changes: 10 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ fn guard_windows_webview(window: &tauri::WebviewWindow) {
ICoreWebView2AcceleratorKeyPressedEventArgs2, COREWEBVIEW2_KEY_EVENT_KIND,
COREWEBVIEW2_KEY_EVENT_KIND_KEY_DOWN, COREWEBVIEW2_KEY_EVENT_KIND_SYSTEM_KEY_DOWN,
COREWEBVIEW2_PROCESS_FAILED_KIND, COREWEBVIEW2_PROCESS_FAILED_KIND_BROWSER_PROCESS_EXITED,
COREWEBVIEW2_PROCESS_FAILED_KIND_RENDER_PROCESS_EXITED,
};
use webview2_com::{AcceleratorKeyPressedEventHandler, ProcessFailedEventHandler};
use windows_core::Interface;
Expand Down Expand Up @@ -253,6 +254,15 @@ fn guard_windows_webview(window: &tauri::WebviewWindow) {
tauri::async_runtime::spawn(async move {
let _ = host.set_decorations(true);
});
} else if kind == COREWEBVIEW2_PROCESS_FAILED_KIND_RENDER_PROCESS_EXITED {
// Only the page's process went (the browser is still up): the
// window stayed white with nothing to click. Load the page
// again; it reconnects the way a launch does.
log::error!("webview2: render process exited, reloading the page");
let host = host.clone();
tauri::async_runtime::spawn(async move {
let _ = host.reload();
});
}
Ok(())
}));
Expand Down
Loading