Skip to content

Commit f88ab3f

Browse files
1aGhclaude
andcommitted
fix(desktop,studio): Windows — no console flash, Assistant starts with Node — refs #141
The release shell is windows_subsystem = "windows", so every console program it spawns gets a fresh visible console. The activity poller ran curl every 6 s per background sidecar (always >= 2 after onboarding), and has_running_chat on every reap. win_process.rs adds hidden_command (CREATE_NO_WINDOW) and a guard test that fails on any other direct spawn without a `no-console-window:` justification. Tauri's resource_dir is canonicalized to a verbatim \\?\C:\... path. As MAUDE_DEV_SERVER_ROOT it became the ACP adapter's entry, and node cannot start a script from a verbatim path (nodejs/node#62446: EISDIR lstat 'C:'). Stripped in sidecar.rs (strip_verbatim) and paths.ts (stripWin32Verbatim). windowsHide added to the studio's git/claude/adapter/where spawns. Closes #141 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5a0a31c commit f88ab3f

12 files changed

Lines changed: 188 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@1agh/maude": patch
3+
---
4+
5+
The Windows app no longer flashes a console window every few seconds. With more than one project open (always the case right after onboarding), the app checked the other projects for running chats every 6 seconds by starting a command-line program, and Windows showed a window for each one. The Assistant also starts on Windows machines that have Node.js installed: the app passed its own folder to Node in a form (`\\?\C:\…`) Node cannot run a script from.

‎apps/desktop/src-tauri/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mod project_resolve;
2828
mod server_json;
2929
mod sidecar;
3030
mod updater;
31+
mod win_process;
3132
// WKWebView-only: recover from a crashed web content process instead of a white window.
3233
#[cfg(any(target_os = "macos", target_os = "ios"))]
3334
mod web_process;

‎apps/desktop/src-tauri/src/notify.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ async fn poll_one(app: &AppHandle, project_root: &str) {
339339
return;
340340
}
341341
let url = format!("{}/_api/acp/activity", parsed.origin().ascii_serialization());
342-
let out = std::process::Command::new("curl")
342+
let out = crate::win_process::hidden_command("curl")
343343
.args([
344344
"-s",
345345
"--max-time",

‎apps/desktop/src-tauri/src/sidecar.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ fn resolve_login_path() -> Option<String> {
171171
let shell = std::env::var("SHELL").unwrap_or_else(|_| "/bin/sh".to_string());
172172
let (tx, rx) = mpsc::channel();
173173
std::thread::spawn(move || {
174+
// no-console-window: #[cfg(unix)] — there is no console to open.
174175
let out = Command::new(&shell)
175176
.args([
176177
"-ilc",
@@ -440,6 +441,10 @@ pub fn spawn_for(app: &AppHandle, project_root: &str) -> Result<(), String> {
440441
resource_dir.join("studio"),
441442
];
442443
if let Some(studio) = candidates.into_iter().find(|p| p.join("dist").exists()) {
444+
// #141 — resource_dir is a verbatim `\\?\C:\…` path on Windows, and
445+
// `node \\?\C:\…\index.js` (the ACP adapter) dies on it. Export
446+
// the ordinary form; the walk-up probes above don't care.
447+
let studio = crate::win_process::strip_verbatim(&studio);
443448
command = command.env(
444449
"MAUDE_DEV_SERVER_ROOT",
445450
studio.to_string_lossy().to_string(),
@@ -908,7 +913,7 @@ fn has_running_chat(design_root: &std::path::Path) -> bool {
908913
// `curl` rather than a new HTTP crate: this is one loopback GET on a rare
909914
// path, and it mirrors resolve_login_path's existing shell-out-to-a-system-
910915
// binary pattern rather than adding a dependency for it.
911-
let out = std::process::Command::new("curl")
916+
let out = crate::win_process::hidden_command("curl")
912917
.args([
913918
"-s",
914919
"--max-time",
@@ -1027,6 +1032,7 @@ fn terminate(child: CommandChild) {
10271032
let pid = child.pid();
10281033
#[cfg(unix)]
10291034
{
1035+
// no-console-window: #[cfg(unix)] — there is no console to open.
10301036
let _ = std::process::Command::new("kill")
10311037
.args(["-TERM", &pid.to_string()])
10321038
.status();
@@ -1193,6 +1199,7 @@ mod tests {
11931199
/// Re-exec this test binary with a stderr nobody is reading.
11941200
fn broken_stderr_probe(mode: &str) -> Option<i32> {
11951201
let exe = std::env::current_exe().expect("test binary path");
1202+
// no-console-window: test-only re-exec.
11961203
let mut child = std::process::Command::new(exe)
11971204
.args([
11981205
"--exact",
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
//! Windows process hygiene for the shell (issue #141).
2+
//!
3+
//! Two things that are invisible on macOS and broke the Windows app:
4+
//!
5+
//! 1. The release shell is `windows_subsystem = "windows"` (main.rs) — it has
6+
//! no console. Every console program it starts (`curl.exe`) therefore gets a
7+
//! NEW, visible console window, which flashes open and shut. The activity
8+
//! poller ran one every 6 s. [`hidden_command`] sets `CREATE_NO_WINDOW`.
9+
//! (The sidecar itself is fine: tauri-plugin-shell sets the flag for it.)
10+
//!
11+
//! 2. Tauri derives `resource_dir()` from a `std::fs::canonicalize`d exe path,
12+
//! which on Windows is a verbatim path (`\\?\C:\…`). Exported to the sidecar
13+
//! as `MAUDE_DEV_SERVER_ROOT`, it reached the ACP adapter's entry path, and
14+
//! `node \\?\C:\…\index.js` dies with `EISDIR: lstat 'C:'` (nodejs/node#62446)
15+
//! — the Assistant never started for anyone with Node installed.
16+
//! [`strip_verbatim`] turns it back into an ordinary path.
17+
18+
use std::ffi::OsStr;
19+
use std::path::{Path, PathBuf};
20+
use std::process::Command;
21+
22+
/// A `std::process::Command` that never opens a console window on Windows.
23+
/// Use this for every child the shell spawns directly; the guard test below
24+
/// fails on any other direct spawn in `src/`.
25+
pub(crate) fn hidden_command<S: AsRef<OsStr>>(program: S) -> Command {
26+
// no-console-window: this IS the helper.
27+
#[allow(unused_mut)]
28+
let mut cmd = Command::new(program);
29+
#[cfg(windows)]
30+
{
31+
use std::os::windows::process::CommandExt;
32+
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
33+
cmd.creation_flags(CREATE_NO_WINDOW);
34+
}
35+
cmd
36+
}
37+
38+
/// `\\?\C:\x` → `C:\x`, `\\?\UNC\srv\share\x` → `\\srv\share\x`; anything else
39+
/// unchanged. Only the two forms that have an ordinary equivalent are rewritten
40+
/// (`\\?\Volume{…}` has none and is left alone).
41+
pub(crate) fn strip_verbatim(path: &Path) -> PathBuf {
42+
match strip_verbatim_str(&path.to_string_lossy()) {
43+
Some(s) => PathBuf::from(s),
44+
None => path.to_path_buf(),
45+
}
46+
}
47+
48+
fn strip_verbatim_str(s: &str) -> Option<String> {
49+
if let Some(rest) = s.strip_prefix(r"\\?\UNC\") {
50+
return Some(format!(r"\\{rest}"));
51+
}
52+
let rest = s.strip_prefix(r"\\?\")?;
53+
let b = rest.as_bytes();
54+
let is_drive = b.len() >= 2 && b[0].is_ascii_alphabetic() && b[1] == b':';
55+
is_drive.then(|| rest.to_string())
56+
}
57+
58+
#[cfg(test)]
59+
mod tests {
60+
use super::*;
61+
62+
#[test]
63+
fn strips_drive_verbatim_prefix() {
64+
assert_eq!(
65+
strip_verbatim_str(r"\\?\C:\Program Files\Maude\resources\apps\studio").as_deref(),
66+
Some(r"C:\Program Files\Maude\resources\apps\studio")
67+
);
68+
}
69+
70+
#[test]
71+
fn strips_unc_verbatim_prefix() {
72+
assert_eq!(
73+
strip_verbatim_str(r"\\?\UNC\srv\share\Maude").as_deref(),
74+
Some(r"\\srv\share\Maude")
75+
);
76+
}
77+
78+
#[test]
79+
fn leaves_ordinary_and_volume_paths_alone() {
80+
assert_eq!(strip_verbatim_str(r"C:\Program Files\Maude"), None);
81+
assert_eq!(
82+
strip_verbatim_str("/Applications/Maude.app/Contents/Resources"),
83+
None
84+
);
85+
assert_eq!(strip_verbatim_str(r"\\?\Volume{1234}\Maude"), None);
86+
assert_eq!(strip_verbatim_str(r"\\srv\share"), None);
87+
let p = Path::new("/Applications/Maude.app");
88+
assert_eq!(strip_verbatim(p), p.to_path_buf());
89+
}
90+
91+
/// The flash in #141 could not turn a Mac test red, so pin the rule
92+
/// structurally: every direct spawn in the shell goes through
93+
/// `hidden_command`, or says on the line (or the three above) why it may not
94+
/// — `no-console-window: <reason>` (unix-only, test-only).
95+
#[test]
96+
fn every_spawn_is_hidden_or_justified() {
97+
let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
98+
let mut offenders = Vec::new();
99+
for entry in std::fs::read_dir(&src).expect("read src/") {
100+
let path = entry.expect("dir entry").path();
101+
if path.extension().and_then(|e| e.to_str()) != Some("rs") {
102+
continue;
103+
}
104+
let text = std::fs::read_to_string(&path).expect("read source");
105+
let lines: Vec<&str> = text.lines().collect();
106+
for (i, line) in lines.iter().enumerate() {
107+
if !line.contains(concat!("Command", "::new(")) {
108+
continue;
109+
}
110+
let from = i.saturating_sub(3);
111+
if !lines[from..=i]
112+
.iter()
113+
.any(|l| l.contains("no-console-window:"))
114+
{
115+
offenders.push(format!("{}:{}", path.display(), i + 1));
116+
}
117+
}
118+
}
119+
assert!(
120+
offenders.is_empty(),
121+
"use win_process::hidden_command (or justify with `no-console-window:`): {offenders:?}"
122+
);
123+
}
124+
}

‎apps/studio/acp/bridge.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,7 @@ export class AcpBridge {
10921092
if (runtime.bunBeBun) env.BUN_BE_BUN = '1';
10931093
const proc = Bun.spawn([runtime.bin, adapterEntry], {
10941094
cwd: this.opts.repoRoot,
1095+
windowsHide: true, // #141 — never a console window for the adapter on Windows
10951096
env,
10961097
stdin: 'pipe',
10971098
stdout: 'pipe',

‎apps/studio/acp/login-state.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function startSignin(): { ok: boolean; reason?: string } {
4747
if (!bin) return { ok: false, reason: 'Claude Code is not installed.' };
4848
const child = Bun.spawn([bin, 'auth', 'login', '--claudeai'], {
4949
env: scrubAgentEnv(),
50+
windowsHide: true, // #141
5051
stdout: 'ignore',
5152
stderr: 'ignore',
5253
});

‎apps/studio/acp/probe.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ export async function getClaudeAuthStatus(): Promise<ClaudeAuthStatus | null> {
481481
async function readAuthStatusStdout(bin: string): Promise<string> {
482482
const proc = Bun.spawn([bin, 'auth', 'status', '--json'], {
483483
env: scrubAgentEnv(),
484+
windowsHide: true, // #141
484485
// A wrapper that prompts would otherwise block forever on a tty-less read.
485486
stdin: 'ignore',
486487
stdout: 'pipe',

‎apps/studio/generation/runtime-probe.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function cachedProbe(key: string, compute: () => boolean): boolean {
3333
export function hasCommandCached(cmd: string): boolean {
3434
return cachedProbe(`has:${cmd}`, () => {
3535
const finder = process.platform === 'win32' ? 'where' : 'which';
36-
return spawnSync(finder, [cmd], { stdio: 'ignore' }).status === 0;
36+
return spawnSync(finder, [cmd], { stdio: 'ignore', windowsHide: true }).status === 0;
3737
});
3838
}
3939

‎apps/studio/git/service.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ function runGit(
353353
return new Promise((resolveRun) => {
354354
const child = spawn('git', args, {
355355
cwd: dir,
356+
windowsHide: true, // #141 — no console window per git call on Windows
356357
env: { ...process.env, GIT_TERMINAL_PROMPT: '0', ...env },
357358
stdio: ['ignore', 'pipe', 'pipe'],
358359
});

0 commit comments

Comments
 (0)