Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
mac app: run on Linux too (xdg-open, desktop-app mark, tray icon, single instance)
Lin (kwant bot)ed77da23037f
diff --git a/apps/mac/Cargo.lock b/apps/mac/Cargo.lockindex bf8f443a..f9469b8a 100644--- a/apps/mac/Cargo.lock+++ b/apps/mac/Cargo.lock@@ -144,6 +144,18 @@ dependencies = ["password-hash",]+[[package]]+name = "async-broadcast"+version = "0.7.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532"+dependencies = [+ "event-listener 5.4.2",+ "event-listener-strategy",+ "futures-core",+ "pin-project-lite",+]+[[package]]name = "async-channel"version = "1.9.0"@@ -179,6 +191,20 @@ dependencies = ["tokio",]+[[package]]+name = "async-executor"+version = "1.14.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c96bf972d85afc50bf5ab8fe2d54d1586b4e0b46c97c50a0c9e71e2f7bcd812a"+dependencies = [+ "async-task",+ "concurrent-queue",+ "fastrand",+ "futures-lite",+ "pin-project-lite",+ "slab",+]+[[package]]name = "async-imap"version = "0.12.0"@@ -202,6 +228,88 @@ dependencies = ["tokio",]+[[package]]+name = "async-io"+version = "2.6.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc"+dependencies = [+ "autocfg",+ "cfg-if",+ "concurrent-queue",+ "futures-io",+ "futures-lite",+ "parking",+ "polling",+ "rustix",+ "slab",+ "windows-sys 0.61.2",+]++[[package]]+name = "async-lock"+version = "3.4.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "290f7f2596bd5b78a9fec8088ccd89180d7f9f55b94b0576823bbbdc72ee8311"+dependencies = [+ "event-listener 5.4.2",+ "event-listener-strategy",+ "pin-project-lite",+]++[[package]]+name = "async-process"+version = "2.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "fc50921ec0055cdd8a16de48773bfeec5c972598674347252c0399676be7da75"+dependencies = [+ "async-channel 2.5.0",+ "async-io",+ "async-lock",+ "async-signal",+ "async-task",+ "blocking",+ "cfg-if",+ "event-listener 5.4.2",+ "futures-lite",+ "rustix",+]++[[package]]+name = "async-recursion"+version = "1.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4f8abc12baad266b1c8cec146854c195b5864b4221d4b2ca7296a7ae82d9e451"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 3.0.9",+]++[[package]]+name = "async-signal"+version = "0.2.14"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "52b5aaafa020cf5053a01f2a60e8ff5dccf550f0f77ec54a4e47285ac2bab485"+dependencies = [+ "async-io",+ "async-lock",+ "atomic-waker",+ "cfg-if",+ "futures-core",+ "futures-io",+ "rustix",+ "signal-hook-registry",+ "slab",+ "windows-sys 0.61.2",+]++[[package]]+name = "async-task"+version = "4.7.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de"+[[package]]name = "async-trait"version = "0.1.92"@@ -426,6 +534,19 @@ dependencies = ["objc2",]+[[package]]+name = "blocking"+version = "1.7.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a70e4329df6cb94385eed412ec92375c3cdd8a6e502493d1229b6414e4036dfa"+dependencies = [+ "async-channel 2.5.0",+ "async-task",+ "futures-io",+ "futures-lite",+ "piper",+]+[[package]]name = "brotli"version = "9.0.0"@@ -1283,6 +1404,33 @@ dependencies = ["simdutf8",]+[[package]]+name = "endi"+version = "1.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "66b7e2430c6dff6a955451e2cfc438f09cea1965a9d6f87f7e3b90decc014099"++[[package]]+name = "enumflags2"+version = "0.7.12"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1027f7680c853e056ebcec683615fb6fbbc07dbaa13b4d5d9442b146ded4ecef"+dependencies = [+ "enumflags2_derive",+ "serde",+]++[[package]]+name = "enumflags2_derive"+version = "0.7.12"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 2.0.119",+]+[[package]]name = "equivalent"version = "1.0.3"@@ -1547,6 +1695,19 @@ version = "0.3.34"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed"+[[package]]+name = "futures-lite"+version = "2.6.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad"+dependencies = [+ "fastrand",+ "futures-core",+ "futures-io",+ "parking",+ "pin-project-lite",+]+[[package]]name = "futures-macro"version = "0.3.34"@@ -1956,6 +2117,12 @@ version = "0.5.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"+[[package]]+name = "hermit-abi"+version = "0.5.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e17592d60ebacc7d5e169f4663c5f84f9161cc90328abcfe8456f41e4dfcb284"+[[package]]name = "hex"version = "0.4.3"@@ -2567,6 +2734,7 @@ dependencies = ["serde_json","tauri","tauri-build",+ "tauri-plugin-single-instance","tauri-plugin-updater","tokio","tracing",@@ -3339,6 +3507,16 @@ version = "0.2.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"+[[package]]+name = "ordered-stream"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9aa2b01e1d916879f73a53d01d1d6cee68adbb31d6d9177a8cfce093cced1d50"+dependencies = [+ "futures-core",+ "pin-project-lite",+]+[[package]]name = "osakit"version = "0.3.1"@@ -3535,6 +3713,17 @@ version = "0.1.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "13bee6c73da26345c729282832b60b0363cf3dd9f4bfd81d8551b7a1c889a113"+[[package]]+name = "piper"+version = "0.2.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1"+dependencies = [+ "atomic-waker",+ "fastrand",+ "futures-io",+]+[[package]]name = "pkcs1"version = "0.7.5"@@ -3594,6 +3783,20 @@ dependencies = ["miniz_oxide 0.8.9",]+[[package]]+name = "polling"+version = "3.11.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218"+dependencies = [+ "cfg-if",+ "concurrent-queue",+ "hermit-abi",+ "pin-project-lite",+ "rustix",+ "windows-sys 0.61.2",+]+[[package]]name = "pom"version = "1.1.0"@@ -5244,6 +5447,22 @@ dependencies = ["walkdir",]+[[package]]+name = "tauri-plugin-single-instance"+version = "2.5.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "726b6da0dd5bd1344f84f4108a622c07d01923baacb5c803a605189672c5352f"+dependencies = [+ "serde",+ "serde_json",+ "tauri",+ "thiserror 2.0.21",+ "tokio",+ "tracing",+ "windows-sys 0.61.2",+ "zbus",+]+[[package]]name = "tauri-plugin-updater"version = "2.14.0"@@ -5927,6 +6146,17 @@ version = "0.7.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "4fc6c929ffa10fb34f4a3c7e9a73620a83ef2e85e47f9ec3381b8289e6762f42"+[[package]]+name = "uds_windows"+version = "1.2.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e"+dependencies = [+ "memoffset",+ "tempfile",+ "windows-sys 0.61.2",+]+[[package]]name = "unicase"version = "2.10.0"@@ -6890,6 +7120,76 @@ dependencies = ["synstructure",]+[[package]]+name = "zbus"+version = "5.19.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5db4be7c075cb421e4b7ee645541604239bd243ba7c357511f4ff3a74b555907"+dependencies = [+ "async-broadcast",+ "async-executor",+ "async-io",+ "async-lock",+ "async-process",+ "async-recursion",+ "async-task",+ "async-trait",+ "blocking",+ "enumflags2",+ "event-listener 5.4.2",+ "futures-core",+ "futures-lite",+ "hex",+ "libc",+ "ordered-stream",+ "rustix",+ "serde",+ "serde_repr",+ "tracing",+ "uds_windows",+ "uuid",+ "windows-sys 0.61.2",+ "winnow 1.0.4",+ "zbus_macros",+ "zbus_names",+ "zvariant",+]++[[package]]+name = "zbus_macros"+version = "5.19.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2990635d09ade6df1868f72f8cac69a876a90981e8bd3c40b1be413f8dc88f40"+dependencies = [+ "proc-macro-crate 3.5.0",+ "proc-macro2",+ "quote",+ "syn 3.0.9",+ "zbus_names",+ "zvariant",+ "zvariant_utils",+]++[[package]]+name = "zbus_names"+version = "4.3.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "812a12be4ead7a59e18ea8f047d08add0066b73bc62fc1467066a2472ae088dd"+dependencies = [+ "serde",+ "winnow 1.0.4",+ "zvariant",+]++[[package]]+name = "zcheapstr"+version = "1.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "939f186d9ecebe044315a5cb6d6f78568bbc21152adc954d5a0c2f58bdbc9920"+dependencies = [+ "serde",+]+[[package]]name = "zerocopy"version = "0.8.63"@@ -7020,3 +7320,44 @@ dependencies = ["log","simd-adler32",]++[[package]]+name = "zvariant"+version = "5.15.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "80bf6d6cd6a4b601acb64cfb8284cdc643fcfa75ef26ae3c46ec8aa4e8a1fbb7"+dependencies = [+ "endi",+ "enumflags2",+ "serde",+ "winnow 1.0.4",+ "zcheapstr",+ "zvariant_derive",+ "zvariant_utils",+]++[[package]]+name = "zvariant_derive"+version = "5.15.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ef2672456ba1cb54b5eaec136e63135b3c7495fb938e53b28a62e633496d486d"+dependencies = [+ "proc-macro-crate 3.5.0",+ "proc-macro2",+ "quote",+ "syn 3.0.9",+ "zvariant_utils",+]++[[package]]+name = "zvariant_utils"+version = "4.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "bad0294361a320b694a328460dc73add56c306150f5cb6bfafc44446120008a3"+dependencies = [+ "proc-macro2",+ "quote",+ "serde",+ "syn 3.0.9",+ "winnow 1.0.4",+]diff --git a/apps/mac/Cargo.toml b/apps/mac/Cargo.tomlindex d78fbf36..06639709 100644--- a/apps/mac/Cargo.toml+++ b/apps/mac/Cargo.toml@@ -23,6 +23,10 @@ dirs = "5.0"tracing = "0.1"tracing-subscriber = { version = "0.3", features = ["env-filter"] }+# A second launch focuses the running app (macOS does this itself)+[target.'cfg(not(target_os = "macos"))'.dependencies]+tauri-plugin-single-instance = "2"+[profile.release]codegen-units = 4lto = "thin"diff --git a/apps/mac/README.md b/apps/mac/README.mdindex b7ab2735..5f8d61c6 100644--- a/apps/mac/README.md+++ b/apps/mac/README.md@@ -24,6 +24,17 @@ A Tauri v2 shell around kwant. The app links the `kwnt` crate and runs the same- `kwant --check` starts kwant headless on a free port with a throwaway data dir, waits for`/api/health` and exits 0. CI runs it on the built app.+**On Linux** (first builds, beta) the same code runs with these differences, all behind+`cfg(target_os = "macos")` so the Mac app is unchanged:+- links open with `xdg-open` instead of `/usr/bin/open`;+- the page sees `window.__KWANT_APP__ = 'linux'` (the frontend treats `'mac'` and `'linux'` alike,+ `frontend/src/externalLinks.ts` `DESKTOP_APPS`);+- the tray shows the coloured app icon (`icons/32x32.png`), not the black menu-bar template, and+ the approval count next to it shows only where the panel draws AppIndicator labels;+- a second launch from the app menu focuses the running window (`tauri-plugin-single-instance`,+ over D-Bus; without a session bus it starts normally), the way a Dock click does on macOS;+- `$SHELL` falls back to `/bin/bash` for the login PATH, and the log is `~/.kwnt/desktop-app.log`.+This crate is its own Cargo workspace with its own `Cargo.lock`, so Tauri never enters the buildof the `kwnt` crate.diff --git a/apps/mac/src/links.rs b/apps/mac/src/links.rsindex b651ecc5..60022485 100644--- a/apps/mac/src/links.rs+++ b/apps/mac/src/links.rs@@ -54,11 +54,21 @@ pub fn new_window(url: &Url, port: u16) -> Link {}}-/// Opens the address in the default browser (macOS `open`). Only http(s) and mailto reach here.+/// The program that hands an address to the default browser: `open` on macOS, `xdg-open`+/// (looked up on PATH) on Linux desktops.+pub const fn browser_opener() -> &'static str {+ if cfg!(target_os = "macos") {+ "/usr/bin/open"+ } else {+ "xdg-open"+ }+}++/// Opens the address in the default browser ([`browser_opener`]). Only http(s) and mailto reach here.pub fn open_in_browser(url: &Url) {let url = url.as_str().to_string();std::thread::spawn(- move || match std::process::Command::new("/usr/bin/open").arg(&url).status() {+ move || match std::process::Command::new(browser_opener()).arg(&url).status() {Ok(s) if s.success() => {}Ok(s) => tracing::warn!(status = %s, "the browser didn't open the link"),Err(e) => tracing::warn!(error = %e, "couldn't open the link in the browser"),@@ -119,6 +129,14 @@ mod tests {assert_eq!(nav("tauri://evil/index.html"), Link::Drop);}+ #[test]+ fn links_open_with_the_desktop_s_own_opener() {+ #[cfg(target_os = "macos")]+ assert_eq!(browser_opener(), "/usr/bin/open");+ #[cfg(target_os = "linux")]+ assert_eq!(browser_opener(), "xdg-open");+ }+#[test]fn new_windows_never_open_in_the_app() {assert_eq!(popup("https://accounts.google.com/"), Link::Browser);diff --git a/apps/mac/src/main.rs b/apps/mac/src/main.rsindex 32fa77b6..8651e7f6 100644--- a/apps/mac/src/main.rs+++ b/apps/mac/src/main.rs@@ -1,5 +1,5 @@-//! kwant for Mac: the kwant server in this process, its UI in a window, and a menu-bar icon.-//! Closing the window keeps kwant running; Quit in the menu stops it.+//! kwant for Mac (and Linux): the kwant server in this process, its UI in a window, and a+//! menu-bar (tray) icon. Closing the window keeps kwant running; Quit in the menu stops it.mod links;mod startup;@@ -17,6 +17,32 @@ use tauri::{const MAIN: &str = "main";+/// Tells kwant's page it runs in the app, so sign-ins say "finish in your browser". The page+/// knows these marks (frontend/src/externalLinks.ts DESKTOP_APPS).+#[cfg(target_os = "macos")]+const APP_MARK: &str = "window.__KWANT_APP__ = 'mac';";+#[cfg(not(target_os = "macos"))]+const APP_MARK: &str = "window.__KWANT_APP__ = 'linux';";++/// The menu icon. macOS tints a black template icon for the menu bar; Linux panels show the+/// picture as it is, so they get the coloured app icon (a black glyph vanishes on dark panels).+#[cfg(target_os = "macos")]+const TRAY_ICON: &[u8] = include_bytes!("../icons/tray-template.png");+#[cfg(not(target_os = "macos"))]+const TRAY_ICON: &[u8] = include_bytes!("../icons/32x32.png");++/// The shell asked for the login PATH when `$SHELL` is unset.+#[cfg(target_os = "macos")]+const FALLBACK_SHELL: &str = "/bin/zsh";+#[cfg(not(target_os = "macos"))]+const FALLBACK_SHELL: &str = "/bin/bash";++/// The app's own log in the data dir.+#[cfg(target_os = "macos")]+const LOG_FILE: &str = "mac-app.log";+#[cfg(not(target_os = "macos"))]+const LOG_FILE: &str = "desktop-app.log";+/// The running server, when this app started one (not when it attached to another kwant).struct Server {stop: Mutex<Option<tokio::sync::oneshot::Sender<()>>>,@@ -70,7 +96,14 @@ fn main() {}};- let app = tauri::Builder::default()+ let builder = tauri::Builder::default();+ // A second launch from the app menu focuses this window instead of opening another kwant.+ // (macOS does this itself: a second click on the app reaches RunEvent::Reopen.)+ #[cfg(not(target_os = "macos"))]+ let builder = builder.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {+ open_window(app)+ }));+ let app = builder.plugin(tauri_plugin_updater::Builder::new().build()).manage(Target { port }).setup(move |app| {@@ -100,10 +133,10 @@ fn main() {});}-/// Finder starts apps with a bare PATH, so the claude, codex and grok CLIs would be missing.-/// Runs before any thread exists, so setting the variable is safe.+/// Finder (and a Linux app menu) starts apps with a bare PATH, so the claude, codex and grok CLIs+/// would be missing. Runs before any thread exists, so setting the variable is safe.fn fix_path() {- let shell = std::env::var("SHELL").unwrap_or_else(|_| "/bin/zsh".to_string());+ let shell = std::env::var("SHELL").unwrap_or_else(|_| FALLBACK_SHELL.to_string());let login = startup::login_shell_path(&shell, Duration::from_secs(3));let current = std::env::var("PATH").unwrap_or_default();let home = dirs::home_dir().unwrap_or_default();@@ -157,8 +190,7 @@ fn open_window(handle: &tauri::AppHandle) {.title("kwant").inner_size(1280.0, 820.0).min_inner_size(900.0, 600.0)- // Tells kwant's page it runs in the app, so sign-ins say "finish in your browser"- .initialization_script("window.__KWANT_APP__ = 'mac';")+ .initialization_script(APP_MARK)// The window only shows kwant; every other page opens in the default browser.on_navigation(move |url| match links::navigation(url, port) {links::Link::Stay => true,@@ -208,10 +240,10 @@ fn build_tray(handle: &tauri::AppHandle) -> tauri::Result<()> {let quit = MenuItem::with_id(handle, "quit", "Quit kwant", true, Some("CmdOrCtrl+Q"))?;let separator = PredefinedMenuItem::separator(handle)?;let menu = Menu::with_items(handle, &[&open, &status, &separator, &quit])?;- let icon = tauri::image::Image::from_bytes(include_bytes!("../icons/tray-template.png"))?;+ let icon = tauri::image::Image::from_bytes(TRAY_ICON)?;let tray = TrayIconBuilder::with_id("kwant").icon(icon)- .icon_as_template(true)+ .icon_as_template(cfg!(target_os = "macos")).tooltip("kwant").menu(&menu).show_menu_on_left_click(true)@@ -310,13 +342,14 @@ fn check() -> i32 {}}-/// Logs go to ~/.kwnt/mac-app.log: an app opened from Finder has no terminal.+/// Logs go to ~/.kwnt/mac-app.log (desktop-app.log on Linux): an app opened from Finder or an+/// app menu has no terminal.fn init_logging(data_dir: &std::path::Path) {let _ = std::fs::create_dir_all(data_dir);let file = std::fs::OpenOptions::new().create(true).append(true)- .open(data_dir.join("mac-app.log"));+ .open(data_dir.join(LOG_FILE));let filter = tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"));match file {diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex c45a43fe..9cfb116f 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -106,7 +106,7 @@ import { personFetch } from './auth';import { teamChannelOf, teamOfChannel } from './teamChannel';import { PromptContext, suggestedPrompts } from './suggestedPrompts';import { isNotificationOpen, showDeviceNotification } from './push';-import { inMacApp, leaveForSignIn, mcpSignIn, pollUntil, signInChanged } from './externalLinks';+import { inDesktopApp, leaveForSignIn, mcpSignIn, pollUntil, signInChanged } from './externalLinks';// Kwant and Tools editors are their own chunks. They stay mounted (rendering nothing while closed),// so both load right after start-up and opening them never waits.@@ -1775,7 +1775,7 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({// Same flow as the servers screen: the window opens inside the click, the address comes after.// In the Mac app the sign-in opens in the default browser and the server is watched instead.const handleSuggestionSignIn = async (serverId: string): Promise<string | void> => {- const macApp = inMacApp();+ const macApp = inDesktopApp();const popup = macApp ? null : window.open('', 'kwnt-mcp-oauth', 'popup,width=520,height=720');const before = macApp ? await mcpSignIn(serverId).catch(() => undefined) : undefined;let url: string;diff --git a/frontend/src/components/ClaudeSignIn.tsx b/frontend/src/components/ClaudeSignIn.tsxindex 7aad9f9d..6a0bcfea 100644--- a/frontend/src/components/ClaudeSignIn.tsx+++ b/frontend/src/components/ClaudeSignIn.tsx@@ -3,7 +3,7 @@ import { AlertTriangle, ExternalLink, Loader2, LogIn, LogOut, RotateCcw } from 'import { ClaudeLoginError, ClaudeLoginSession, claudeLoginApi, isClaudeSignInUrl, isLoginActive, loginFailure } from '../claudeLogin';import type { EngineInfo } from '../engines';import { playSfx } from '../audio/chiptune';-import { inMacApp } from '../externalLinks';+import { inDesktopApp } from '../externalLinks';const POLL_MS = 2000;@@ -17,7 +17,7 @@ const link = 'inline-flex items-center gap-1 font-medium text-sky-300 underline* `noopener` would make window.open return null, so the opener is cut by hand before navigating. */function openBlankTab(): Window | null {// The Mac app opens no second window; the link below opens in the default browser.- if (inMacApp()) return null;+ if (inDesktopApp()) return null;try {const tab = window.open('about:blank', '_blank');if (tab) tab.opener = null;@@ -73,7 +73,7 @@ export const ClaudeSignIn: React.FC<{ onSignedIn: () => void; focusRequest?: numplaySfx('click');const t = openBlankTab();tab.current = t;- toBrowser.current = inMacApp();+ toBrowser.current = inDesktopApp();setBlocked(!t && !toBrowser.current);setBusy('start');setError(null);@@ -233,7 +233,7 @@ export const ClaudeSignIn: React.FC<{ onSignedIn: () => void; focusRequest?: num</p>{url && (<p className="text-[11px] text-zinc-400">- {blocked ? 'Your browser didn’t open a new tab. ' : inMacApp() ? 'Opened claude.ai in your browser. ' : 'Closed the tab? '}+ {blocked ? 'Your browser didn’t open a new tab. ' : inDesktopApp() ? 'Opened claude.ai in your browser. ' : 'Closed the tab? '}<a href={url} target="_blank" rel="noopener noreferrer" className={link} onClick={() => setBlocked(false)}>{blocked ? 'Open claude.ai to sign in' : 'Open claude.ai again'} <ExternalLink size={10} aria-hidden="true" /></a>diff --git a/frontend/src/components/ConnectionSuggestionCard.tsx b/frontend/src/components/ConnectionSuggestionCard.tsxindex b186e8d6..a778c4fb 100644--- a/frontend/src/components/ConnectionSuggestionCard.tsx+++ b/frontend/src/components/ConnectionSuggestionCard.tsx@@ -1,7 +1,7 @@import React, { useEffect, useRef, useState } from 'react';import { AlertTriangle, CheckCircle2, ExternalLink, Link2, Loader2, Plug } from 'lucide-react';import { ModernAvatar } from './ModernAvatar';-import { inMacApp } from '../externalLinks';+import { inDesktopApp } from '../externalLinks';import {CardState,ConnectApi,@@ -173,7 +173,7 @@ export interface ConnectionSuggestionCardProps {export const ConnectionSuggestionCard: React.FC<ConnectionSuggestionCardProps> = ({ api = defaultConnectApi, ...props }) => {const [state, setState] = useState<CardState>(() => initialState(props.meta));const stopRef = useRef<(() => void) | null>(null);- const mac = inMacApp();+ const mac = inDesktopApp();// An app connected earlier (or from another card) shows as connected when the card appears.useEffect(() => {diff --git a/frontend/src/components/ConnectionsView.tsx b/frontend/src/components/ConnectionsView.tsxindex 1e0ac6a5..949d9515 100644--- a/frontend/src/components/ConnectionsView.tsx+++ b/frontend/src/components/ConnectionsView.tsx@@ -20,7 +20,7 @@ import {storedLabel,usedByText,} from '../connections';-import { inMacApp } from '../externalLinks';+import { inDesktopApp } from '../externalLinks';const TONES: Record<Tone, string> = {amber: 'border-amber-500/30 bg-amber-500/10 text-amber-200',@@ -179,14 +179,14 @@ export const ComposioAppSearch: React.FC<{const connect = async (app: ComposioApp) => {// open the tab now, while the click still counts as the person's, then point it at Composio// The Mac app opens no second window: its links go to the default browser.- const tab = typeof window !== 'undefined' && !inMacApp() ? window.open('', '_blank') : null;+ const tab = typeof window !== 'undefined' && !inDesktopApp() ? window.open('', '_blank') : null;if (tab) tab.opener = null;setConnecting(app.slug);setError(null);try {const { redirect_url } = await api.connect(app.slug);if (tab) tab.location.href = redirect_url;- else if (inMacApp()) window.location.assign(redirect_url);+ else if (inDesktopApp()) window.location.assign(redirect_url);else window.open(redirect_url, '_blank', 'noopener,noreferrer');setOpened(app.name);} catch (err) {@@ -228,7 +228,7 @@ export const ComposioAppSearch: React.FC<{{error && <p className="px-3 py-2 rounded-lg border border-rose-500/20 bg-rose-500/5 text-xs text-rose-300">{error}</p>}{opened && (<p className="text-xs text-emerald-200">- Opened {opened}’s sign-in on Composio in {inMacApp() ? 'your browser' : 'a new tab'}. Its tools reach your bots through the Composio server once you finish there.+ Opened {opened}’s sign-in on Composio in {inDesktopApp() ? 'your browser' : 'a new tab'}. Its tools reach your bots through the Composio server once you finish there.</p>)}{apps && apps.length === 0 && <p className="text-xs text-zinc-400">No Composio apps match.</p>}diff --git a/frontend/src/components/McpServersModal.tsx b/frontend/src/components/McpServersModal.tsxindex 6978b1ac..bc06ac7b 100644--- a/frontend/src/components/McpServersModal.tsx+++ b/frontend/src/components/McpServersModal.tsx@@ -57,7 +57,7 @@ import {readOAuthMessage,isBlankRequired,} from '../mcp';-import { inMacApp, leaveForSignIn, pollUntil, signInChanged } from '../externalLinks';+import { inDesktopApp, leaveForSignIn, pollUntil, signInChanged } from '../externalLinks';interface McpServersModalProps {isOpen: boolean;@@ -386,7 +386,7 @@ export const McpServersModal: React.FC<McpServersModalProps> = ({ isOpen, onClosconst popupWatch = useRef<number | null>(null);/** Mac app: stops watching the server for a sign-in finished in the browser. */const signInWatch = useRef<(() => void) | null>(null);- const macApp = inMacApp();+ const macApp = inDesktopApp();const refresh = useCallback(async (): Promise<McpServer[] | null> => {try {diff --git a/frontend/src/components/McpSuggestionCard.tsx b/frontend/src/components/McpSuggestionCard.tsxindex 59ec7711..09c28b6f 100644--- a/frontend/src/components/McpSuggestionCard.tsx+++ b/frontend/src/components/McpSuggestionCard.tsx@@ -2,7 +2,7 @@ import React, { useState } from 'react';import { AlertTriangle, CheckCircle2, ExternalLink, Globe, KeyRound, Loader2, MinusCircle, Monitor, Plug } from 'lucide-react';import { ModernAvatar } from './ModernAvatar';import { Suggestion, SuggestionMeta, failureText, inputKey, inputLabel, installPayload, runsLine, suggestionView } from '../mcpSuggestions';-import { inMacApp } from '../externalLinks';+import { inDesktopApp } from '../externalLinks';export interface McpSuggestionCardProps {meta: SuggestionMeta;@@ -246,7 +246,7 @@ export const McpSuggestionCard: React.FC<McpSuggestionCardProps> = ({className="inline-flex items-center gap-1.5 min-h-[40px] sm:min-h-[34px] px-3.5 rounded-xl text-sm font-medium bg-amber-500 text-zinc-950 hover:bg-amber-400 disabled:opacity-60 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-amber-400">{busy === 'signin' && <Loader2 size={13} className="animate-spin motion-reduce:animate-none" aria-hidden="true" />}- {busy === 'signin' ? (inMacApp() ? 'Finish signing in in your browser…' : 'Waiting for sign-in…') : signInError ? 'Try signing in again' : 'Sign in'}+ {busy === 'signin' ? (inDesktopApp() ? 'Finish signing in in your browser…' : 'Waiting for sign-in…') : signInError ? 'Try signing in again' : 'Sign in'}</button>{signInError && (<span role="alert" className="text-rose-300 break-words">diff --git a/frontend/src/connectionSuggestions.ts b/frontend/src/connectionSuggestions.tsindex 79b6ac1f..f2f76ab0 100644--- a/frontend/src/connectionSuggestions.ts+++ b/frontend/src/connectionSuggestions.ts@@ -6,7 +6,7 @@import { parseMetaObject } from './questions';import { ConnectionsError, connectionsApi } from './connections';-import { inMacApp, pollUntil } from './externalLinks';+import { inDesktopApp, pollUntil } from './externalLinks';/** Whether the space's Composio connector could start a sign-in when the bot posted the card. */export type ComposioReady = 'ready' | 'off' | 'needs_key' | 'not_added';@@ -115,7 +115,7 @@ export function startConnect({api = defaultConnectApi,win = window as unknown as OpenWin,- mac = inMacApp(),+ mac = inDesktopApp(),everyMs,forMs,}: { api?: ConnectApi; win?: OpenWin; mac?: boolean; everyMs?: number; forMs?: number } = {},@@ -123,7 +123,7 @@ export function startConnect(let stop: (() => void) | null = null;let cancelled = false;// Open the tab now, while the click still counts as the person's; the address comes after the fetch.- // The Mac app opens no second window: its outside links go to the default browser.+ // The desktop app opens no second window: its outside links go to the default browser.const tab = mac ? null : win.open('', '_blank');if (tab) tab.opener = null;onState({ phase: 'opening' });diff --git a/frontend/src/externalLinks.ts b/frontend/src/externalLinks.tsindex 25844331..1e8ae68a 100644--- a/frontend/src/externalLinks.ts+++ b/frontend/src/externalLinks.ts@@ -1,6 +1,6 @@/*** Sign-ins that leave kwant. In a browser they open in a popup or, when it is blocked, in this- * tab, and kwnt's callback page brings the tab back. The Mac app's window only ever shows kwant+ * tab, and kwnt's callback page brings the tab back. The desktop app's window only ever shows kwant* (apps/mac/src/links.rs): every outside page opens in the default browser, with no opener and* no way to come back by itself, so the app watches the server for the finished sign-in instead.*/@@ -11,17 +11,22 @@ export const OAUTH_RETURN_KEY = 'kwnt-mcp-oauth-return';type AppWindow = { __KWANT_APP__?: unknown };-/** True inside the kwant Mac app, which marks its window with `__KWANT_APP__ = 'mac'`. */-export const inMacApp = (w: unknown = typeof window !== 'undefined' ? window : undefined): boolean =>- !!w && (w as AppWindow).__KWANT_APP__ === 'mac';+/** The marks the desktop app sets on its window (apps/mac/src/main.rs APP_MARK), one per OS. */+export const DESKTOP_APPS: readonly string[] = ['mac', 'linux'];++/** True inside the kwant desktop app, which marks its window with `__KWANT_APP__ = 'mac'` or `'linux'`. */+export const inDesktopApp = (w: unknown = typeof window !== 'undefined' ? window : undefined): boolean => {+ const mark = w ? (w as AppWindow).__KWANT_APP__ : undefined;+ return typeof mark === 'string' && DESKTOP_APPS.includes(mark);+};/*** Goes to a sign-in page from this tab. In a browser the tab leaves kwant and the callback page- * returns it; in the Mac app the navigation is turned into the default browser and the window+ * returns it; in the desktop app the navigation is turned into the default browser and the window* stays where it is.*/export function leaveForSignIn(url: string, w: Window = window): void {- if (!inMacApp(w)) {+ if (!inDesktopApp(w)) {try {w.sessionStorage.setItem(OAUTH_RETURN_KEY, '1');} catch {diff --git a/frontend/tests/externalLinks.test.mjs b/frontend/tests/externalLinks.test.mjsindex c680d342..98ceb042 100644--- a/frontend/tests/externalLinks.test.mjs+++ b/frontend/tests/externalLinks.test.mjs@@ -7,7 +7,7 @@ const source = await readFile(new URL('../src/externalLinks.ts', import.meta.urlconst { outputText } = ts.transpileModule(source, {compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2020 },});-const { OAUTH_RETURN_KEY, inMacApp, leaveForSignIn, signInChanged, pollUntil, mcpSignIn } = await import(+const { OAUTH_RETURN_KEY, DESKTOP_APPS, inDesktopApp, leaveForSignIn, signInChanged, pollUntil, mcpSignIn } = await import(`data:text/javascript;base64,${Buffer.from(outputText).toString('base64')}`);@@ -29,12 +29,21 @@ test('the callback page and the app agree on the return mark', async () => {assert.match(rust, new RegExp(`RETURN_KEY: &str = "${OAUTH_RETURN_KEY}"`));});-test('only the Mac app’s mark counts as the Mac app', () => {- assert.equal(inMacApp(fakeWindow('mac')), true);- assert.equal(inMacApp(fakeWindow()), false);- assert.equal(inMacApp(fakeWindow('windows')), false);- assert.equal(inMacApp(fakeWindow(true)), false);- assert.equal(inMacApp(undefined), false);+test('only the desktop app’s marks count as the desktop app', () => {+ assert.equal(inDesktopApp(fakeWindow('mac')), true);+ assert.equal(inDesktopApp(fakeWindow('linux')), true);+ assert.equal(inDesktopApp(fakeWindow()), false);+ assert.equal(inDesktopApp(fakeWindow('windows')), false);+ assert.equal(inDesktopApp(fakeWindow(true)), false);+ assert.equal(inDesktopApp(fakeWindow('includes')), false);+ assert.equal(inDesktopApp(undefined), false);+});++test('every mark the desktop app sets is one the page knows', async () => {+ const rust = await readFile(new URL('../../apps/mac/src/main.rs', import.meta.url), 'utf8');+ const marks = [...rust.matchAll(/__KWANT_APP__ = '(\w+)'/g)].map((m) => m[1]);+ assert.deepEqual(marks.sort(), ['linux', 'mac']);+ for (const mark of marks) assert.ok(DESKTOP_APPS.includes(mark), mark);});test('a browser tab that leaves to sign in is marked so the callback brings it back', () => {