Skip to content

armgit / Wake

Public Imported from GitHub
0

All your AI agent sessions in one place — browse, search, resume. Rust + GPUI.

Rust

Add experimental Linux support

Corey Chiu058d7f4f9399
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a646d6e..7803491 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -10,8 +10,12 @@ env:
jobs:
test:
- name: Test & build (macOS)
- runs-on: macos-14
+ name: Test & build (${{ matrix.os }})
+ runs-on: ${{ matrix.os }}
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [macos-14, ubuntu-24.04]
steps:
- uses: actions/checkout@v4
@@ -21,6 +25,16 @@ jobs:
- name: Cache cargo
uses: Swatinem/rust-cache@v2
+ # gpui Linux 后端的系统依赖(Wayland/X11/字体/音频头文件)
+ - name: Install system dependencies
+ if: runner.os == 'Linux'
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y --no-install-recommends \
+ libasound2-dev libfontconfig1-dev libwayland-dev \
+ libxkbcommon-dev libxkbcommon-x11-dev libssl-dev libzstd-dev \
+ pkg-config cmake clang
+
# 数据层测试:adapter 解析契约 / seq 一致性 / db 往返 / 扫描终态
- name: Test wake-core
run: cargo test -p wake-core
diff --git a/Cargo.lock b/Cargo.lock
index df48036..f774b2e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6167,6 +6167,24 @@ dependencies = [
"once_cell",
]
+[[package]]
+name = "trash"
+version = "5.2.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7602e0c7d66ec2d92a8c917219fbc7894039efa2063b9064260110828a356f46"
+dependencies = [
+ "chrono",
+ "libc",
+ "log",
+ "objc2",
+ "objc2-foundation",
+ "once_cell",
+ "percent-encoding",
+ "scopeguard",
+ "urlencoding",
+ "windows 0.56.0",
+]
+
[[package]]
name = "tree-sitter"
version = "0.25.10"
@@ -6647,6 +6665,12 @@ dependencies = [
"serde_derive",
]
+[[package]]
+name = "urlencoding"
+version = "2.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
+
[[package]]
name = "usvg"
version = "0.45.1"
@@ -6805,6 +6829,7 @@ dependencies = [
"serde",
"serde_json",
"tempfile",
+ "trash",
"walkdir",
"zstd",
]
@@ -7083,6 +7108,16 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+[[package]]
+name = "windows"
+version = "0.56.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1de69df01bdf1ead2f4ac895dc77c9351aefff65b2f3db429a343f9cbf05e132"
+dependencies = [
+ "windows-core 0.56.0",
+ "windows-targets 0.52.6",
+]
+
[[package]]
name = "windows"
version = "0.57.0"
@@ -7128,6 +7163,18 @@ dependencies = [
"windows-core 0.61.2",
]
+[[package]]
+name = "windows-core"
+version = "0.56.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4698e52ed2d08f8658ab0c39512a7c00ee5fe2688c65f8c0a4f06750d729f2a6"
+dependencies = [
+ "windows-implement 0.56.0",
+ "windows-interface 0.56.0",
+ "windows-result 0.1.2",
+ "windows-targets 0.52.6",
+]
+
[[package]]
name = "windows-core"
version = "0.57.0"
@@ -7177,6 +7224,17 @@ dependencies = [
"windows-threading",
]
+[[package]]
+name = "windows-implement"
+version = "0.56.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
[[package]]
name = "windows-implement"
version = "0.57.0"
@@ -7199,6 +7257,17 @@ dependencies = [
"syn 2.0.119",
]
+[[package]]
+name = "windows-interface"
+version = "0.56.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
[[package]]
name = "windows-interface"
version = "0.57.0"
diff --git a/README.md b/README.md
index fdefcff..7063ba9 100644
--- a/README.md
+++ b/README.md
@@ -2,12 +2,12 @@
[![License](https://img.shields.io/github/license/iAmCorey/Wake?style=flat-square)](LICENSE)
[![Release](https://img.shields.io/github/v/release/iAmCorey/Wake?style=flat-square)](https://github.com/iAmCorey/Wake/releases/latest)
-[![Platform](https://img.shields.io/badge/platform-macOS%2014%2B-007AFF?style=flat-square)](https://github.com/iAmCorey/Wake/releases/latest)
+[![Platform](https://img.shields.io/badge/platform-macOS%2014%2B%20%7C%20Linux%20beta-007AFF?style=flat-square)](https://github.com/iAmCorey/Wake/releases/latest)
[![Downloads](https://img.shields.io/github/downloads/iAmCorey/Wake/total?style=flat-square)](https://github.com/iAmCorey/Wake/releases)
[![Stars](https://img.shields.io/github/stars/iAmCorey/Wake?style=flat-square)](https://github.com/iAmCorey/Wake/stargazers)
[![CI](https://img.shields.io/github/actions/workflow/status/iAmCorey/Wake/ci.yml?branch=main&label=CI&style=flat-square)](https://github.com/iAmCorey/Wake/actions/workflows/ci.yml)
-A native macOS app that gathers every coding-agent session on your machine into one place — browse, full-text search, and resume any conversation in seconds. Built with **Rust + GPUI** (gpui 0.2 + gpui-component 0.5).
+A native desktop app that gathers every coding-agent session on your machine into one place — browse, full-text search, and resume any conversation in seconds. Built with **Rust + GPUI** (gpui 0.2 + gpui-component 0.5). macOS first; experimental Linux support since v0.2.5.
Your agent history is scattered across `~/.claude`, `~/.codex`, and ten other private directories. Wake reads them all, read-only, and gives you one fast window into it. Everything stays local: no network requests, ever.
@@ -69,6 +69,19 @@ open dist/Wake.app
The app is ad-hoc signed, so if you download a prebuilt copy instead of building it yourself, macOS Gatekeeper will block the first launch — right-click the app and choose *Open*, or run `xattr -d com.apple.quarantine Wake.app`.
+### Linux (experimental)
+
+Prebuilt arm64 packages are attached to each release: a `.deb`, and a tar.gz with a user-level `install.sh` (no root needed). Or build from source:
+
+```bash
+sudo apt-get install -y libasound2-dev libfontconfig1-dev libwayland-dev \
+ libxkbcommon-dev libxkbcommon-x11-dev libssl-dev libzstd-dev pkg-config cmake clang
+git clone https://github.com/iAmCorey/Wake && cd Wake
+scripts/make-linux.sh # builds dist/wake-<version>-linux-<arch>.tar.gz and .deb
+```
+
+The data layer, rendering and search are fully tested on Linux; terminal-resume targets and desktop integration have seen less real-desktop mileage yet — issues welcome.
+
## Development
```bash
diff --git a/crates/wake-core/Cargo.toml b/crates/wake-core/Cargo.toml
index ff676f3..a1d8a52 100644
--- a/crates/wake-core/Cargo.toml
+++ b/crates/wake-core/Cargo.toml
@@ -15,6 +15,11 @@ notify.workspace = true
chrono.workspace = true
zstd.workspace = true
+# Linux 废纸篓:freedesktop Trash spec 的纯库实现(macOS 走 Finder/osascript,
+# 行为已验证不动;Windows 未做)
+[target.'cfg(target_os = "linux")'.dependencies]
+trash = "5"
+
[dev-dependencies]
tempfile = "3"
diff --git a/crates/wake-core/src/adapters/mod.rs b/crates/wake-core/src/adapters/mod.rs
index fe73c4e..c7d0671 100644
--- a/crates/wake-core/src/adapters/mod.rs
+++ b/crates/wake-core/src/adapters/mod.rs
@@ -12,7 +12,7 @@ pub mod opencode;
pub mod pi;
pub(crate) mod parse_utils;
-mod sqlite_ro;
+pub(crate) mod sqlite_ro;
use crate::models::*;
use anyhow::Result;
diff --git a/crates/wake-core/src/adapters/sqlite_ro.rs b/crates/wake-core/src/adapters/sqlite_ro.rs
index fb996af..3e34dcc 100644
--- a/crates/wake-core/src/adapters/sqlite_ro.rs
+++ b/crates/wake-core/src/adapters/sqlite_ro.rs
@@ -51,3 +51,13 @@ pub fn open_sqlite_ro(db: &Path, tag: &str) -> Option<SqliteRo> {
pub fn virtual_path(db: &Path, id: &str) -> String {
format!("{}#{id}", db.display())
}
+
+/// virtual_path 的逆:磁盘上不存在的路径剥掉 `#<id>` 还原库文件本体,
+/// 真实存在的路径原样返回(文件管理器 reveal 用)。格式知识只在本文件。
+pub fn strip_virtual_path(path: &str) -> &str {
+ if Path::new(path).exists() {
+ path
+ } else {
+ path.rsplit_once('#').map(|(db, _)| db).unwrap_or(path)
+ }
+}
diff --git a/crates/wake-core/src/services/terminal/linux.rs b/crates/wake-core/src/services/terminal/linux.rs
new file mode 100644
index 0000000..4c869ed
--- /dev/null
+++ b/crates/wake-core/src/services/terminal/linux.rs
@@ -0,0 +1,208 @@
+//! Linux 平台原语:终端仿真器 argv 直传(无 AppleScript 层)、freedesktop
+//! 废纸篓(trash crate)、文件管理器(D-Bus ShowItems / xdg-open)、剪贴板
+//! (wl-copy / xclip / xsel)。接口与 macos.rs 同形,策略在 mod.rs。
+//!
+//! 家族探测走 `resolve_clis`(login shell PATH,连 flatpak 的 exports/bin
+//! 一起覆盖),只列装了的。spawn 形制各家见 exec_prefix 注释;失败面统一由
+//! mod.rs 的剪贴板兜底接住(命令已拼好,粘进任何终端都能跑)。
+
+use super::{percent_encode, pipe_to, resolve_cli, resolve_clis, spawn_and_reap, ResumeOutcome};
+use crate::models::{AgentId, SessionMeta};
+use std::collections::HashMap;
+use std::path::{Path, PathBuf};
+use std::process::Command;
+
+/// Open In 下拉的目标终端(Linux 家族)。全部是 shell 命令目标:
+/// `<bin> <exec_prefix…> /bin/sh -c '<command>; exec "$SHELL"'`,命令跑完
+/// 交还交互 shell 保持窗口(与 macOS Ghostty 同策略)。
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum TerminalApp {
+ GnomeTerminal,
+ /// GNOME Console(kgx)——新 GNOME/Ubuntu 的默认终端
+ GnomeConsole,
+ Konsole,
+ XfceTerminal,
+ Ghostty,
+ Kitty,
+ Alacritty,
+ WezTerm,
+ Xterm,
+}
+
+impl TerminalApp {
+ const ALL: [TerminalApp; 9] = [
+ TerminalApp::GnomeTerminal,
+ TerminalApp::GnomeConsole,
+ TerminalApp::Konsole,
+ TerminalApp::XfceTerminal,
+ TerminalApp::Ghostty,
+ TerminalApp::Kitty,
+ TerminalApp::Alacritty,
+ TerminalApp::WezTerm,
+ TerminalApp::Xterm,
+ ];
+
+ pub fn display_name(&self) -> &'static str {
+ match self {
+ TerminalApp::GnomeTerminal => "GNOME Terminal",
+ TerminalApp::GnomeConsole => "Console",
+ TerminalApp::Konsole => "Konsole",
+ TerminalApp::XfceTerminal => "Xfce Terminal",
+ TerminalApp::Ghostty => "Ghostty",
+ TerminalApp::Kitty => "kitty",
+ TerminalApp::Alacritty => "Alacritty",
+ TerminalApp::WezTerm => "WezTerm",
+ TerminalApp::Xterm => "XTerm",
+ }
+ }
+
+ /// 稳定短 id(图标缓存文件名、last-used 记忆用)。恰好也全部是可执行名,
+ /// 探测与启动直接复用
+ pub fn id(&self) -> &'static str {
+ match self {
+ TerminalApp::GnomeTerminal => "gnome-terminal",
+ TerminalApp::GnomeConsole => "kgx",
+ TerminalApp::Konsole => "konsole",
+ TerminalApp::XfceTerminal => "xfce4-terminal",
+ TerminalApp::Ghostty => "ghostty",
+ TerminalApp::Kitty => "kitty",
+ TerminalApp::Alacritty => "alacritty",
+ TerminalApp::WezTerm => "wezterm",
+ TerminalApp::Xterm => "xterm",
+ }
+ }
+
+ /// spawn 前缀:`<bin> <prefix…> <argv…>`,prefix 是各家"后面全是命令 argv"
+ /// 的开关——gnome-terminal/kgx 用 `--`,wezterm 是子命令 `start --`,
+ /// xfce4-terminal 用 `-x`(-e 是单串旧式),kitty 裸接,其余 `-e`
+ fn exec_prefix(&self) -> &'static [&'static str] {
+ match self {
+ TerminalApp::GnomeTerminal | TerminalApp::GnomeConsole => &["--"],
+ TerminalApp::WezTerm => &["start", "--"],
+ TerminalApp::XfceTerminal => &["-x"],
+ TerminalApp::Kitty => &[],
+ TerminalApp::Konsole | TerminalApp::Ghostty | TerminalApp::Alacritty | TerminalApp::Xterm => &["-e"],
+ }
+ }
+}
+
+/// Linux 无深链类恢复目标(Kooky 仅 macOS),全部走 shell 命令
+pub(super) fn deep_link_resume(_meta: &SessionMeta, _term: TerminalApp) -> Option<ResumeOutcome> {
+ None
+}
+
+/// 已安装终端(启动后不变,进程内缓存;一次 login shell 批量探测)
+pub fn installed_terminals() -> &'static [TerminalApp] {
+ use std::sync::OnceLock;
+ static CACHE: OnceLock<Vec<TerminalApp>> = OnceLock::new();
+ CACHE.get_or_init(|| {
+ let bins: Vec<&str> = TerminalApp::ALL.iter().map(|t| t.id()).collect();
+ let found = resolve_clis(&bins);
+ TerminalApp::ALL
+ .into_iter()
+ .filter(|t| matches!(found.get(t.id()), Some(Some(_))))
+ .collect()
+ })
+}
+
+/// 某会话可用的恢复目标(Linux 无 Kooky 这类按 agent 过滤的目标,一律全量)
+pub fn terminals_for(_agent: AgentId) -> Vec<TerminalApp> {
+ installed_terminals().to_vec()
+}
+
+/// Shell 类目标的命令注入:argv 直传,无二次 shell 解析。
+/// gnome-terminal/kgx 经 D-Bus 服务转发、前台进程即刻退出,spawn 成功即算送达
+pub(super) fn launch_shell(term: TerminalApp, command: &str) -> anyhow::Result<()> {
+ let bin = term.id();
+ let exe = resolve_cli(bin).ok_or_else(|| anyhow::anyhow!("{bin} not found"))?;
+ // 命令跑完 exec 用户 shell 保持窗口;$SHELL 缺省退 /bin/sh
+ let keep_open = format!("{command}; exec \"${{SHELL:-/bin/sh}}\"");
+ let mut cmd = Command::new(exe);
+ cmd.args(term.exec_prefix());
+ cmd.args(["/bin/sh", "-c", &keep_open]);
+ spawn_and_reap(cmd)?;
+ Ok(())
+}
+
+/// 终端图标提取:Linux 无 NSWorkspace 等价物(得解析 .desktop + icon theme
+/// 查找),v1 不做——UI 对无图标的终端行本就有无图兜底。此函数跑在启动的
+/// background 线程里,顺手预热 installed_terminals 的 login shell 探测,
+/// 别让首次打开详情页的 render 帧付这几百毫秒(macOS 靠图标提取天然预热)。
+pub fn ensure_app_icons(_cache_dir: &Path) -> HashMap<String, PathBuf> {
+ let _ = installed_terminals();
+ HashMap::new()
+}
+
+/// wl-copy(Wayland 会话优先)→ xclip → xsel,依次试,NotFound/退出失败落
+/// 下家;都不成返回 false——调用方(clipboard_fallback)据此决定还敢不敢
+/// 对用户说 "copied"
+pub(super) fn copy_to_clipboard(text: &str) -> bool {
+ let wl: (&str, &[&str]) = ("wl-copy", &[]);
+ let xclip: (&str, &[&str]) = ("xclip", &["-selection", "clipboard"]);
+ let xsel: (&str, &[&str]) = ("xsel", &["--clipboard", "--input"]);
+ let order = if std::env::var_os("WAYLAND_DISPLAY").is_some() {
+ [wl, xclip, xsel]
+ } else {
+ [xclip, xsel, wl]
+ };
+ order.into_iter().any(|(bin, args)| pipe_to(bin, args, text))
+}
+
+/// 批量删进回收站(freedesktop Trash spec,trash crate 纯库实现,文件
+/// 管理器里可恢复;收 mod.rs 已过滤的真实路径)
+pub(super) fn trash_existing(paths: &[&str]) -> anyhow::Result<()> {
+ trash::delete_all(paths).map_err(|e| anyhow::anyhow!("Failed to move to Trash: {e}"))
+}
+
+/// 致命错误对话框:zenity → kdialog 尽力弹一个,桌面双双缺席时 mod.rs
+/// 已落过 stderr(从 .desktop 启动的场景由 journald 收)
+pub(super) fn alert_dialog(message: &str) {
+ let zenity = Command::new("zenity")
+ .args(["--error", "--title=Wake can't start", &format!("--text={message}")])
+ .status();
+ if zenity.map(|s| s.success()).unwrap_or(false) {
+ return;
+ }
+ let _ = Command::new("kdialog")
+ .args(["--title", "Wake can't start", "--error", message])
+ .status();
+}
+
+/// file:// URL(percent_encode 保留 '/';逗号也会被编码,不会撞
+/// dbus-send 的 array 逗号分隔语法)
+fn file_url(p: &str) -> String {
+ format!("file://{}", percent_encode(p, true))
+}
+
+/// 在文件管理器里进入目录
+pub(super) fn open_dir(path: &str) {
+ let mut cmd = Command::new("xdg-open");
+ cmd.arg(path);
+ let _ = spawn_and_reap(cmd);
+}
+
+/// 选中文件(收 mod.rs 已剥好虚拟后缀的真实路径):先试
+/// org.freedesktop.FileManager1 的 ShowItems(Files/Dolphin/Nemo 都实现),
+/// D-Bus 通道不在(headless、极简桌面)退 xdg-open 父目录。
+/// `--print-reply` 会等到文件管理器 activation 冷启结束——调用方(mod.rs)
+/// 已把整个函数放进短命线程,这里阻塞无妨。
+pub(super) fn reveal_path(path: &str) {
+ let shown = Command::new("dbus-send")
+ .args([
+ "--session",
+ "--print-reply",
+ "--dest=org.freedesktop.FileManager1",
+ "/org/freedesktop/FileManager1",
+ "org.freedesktop.FileManager1.ShowItems",
+ &format!("array:string:{}", file_url(path)),
+ "string:",
+ ])
+ .output()
+ .map(|o| o.status.success())
+ .unwrap_or(false);
+ if shown {
+ return;
+ }
+ let parent = Path::new(path).parent().and_then(|d| d.to_str()).unwrap_or(path);
+ open_dir(parent);
+}
diff --git a/crates/wake-core/src/services/terminal.rs b/crates/wake-core/src/services/terminal/macos.rs
similarity index 57%
rename from crates/wake-core/src/services/terminal.rs
rename to crates/wake-core/src/services/terminal/macos.rs
index f66962d..34631f3 100644
--- a/crates/wake-core/src/services/terminal.rs
+++ b/crates/wake-core/src/services/terminal/macos.rs
@@ -1,123 +1,18 @@
+//! macOS 平台原语:AppleScript/`open` 驱动的终端与 Finder、Finder 废纸篓、
+//! Kooky 深链。接口与 linux.rs 同形,策略(dir/file 分发、路径过滤、
+//! 线程化)在 mod.rs,这里只做动作本身。
+
+use super::{
+ percent_encode, pipe_to, posix_quote, resolve_cli, resume_args, session_bin, spawn_and_reap,
+ ResumeOutcome,
+};
use crate::models::{AgentId, SessionMeta};
use std::collections::HashMap;
use std::path::Path;
use std::process::Command;
-use std::sync::Mutex;
-
-#[derive(Debug, Clone)]
-pub struct ResumeOutcome {
- pub ok: bool,
- pub command: String,
- pub error: Option<String>,
-}
-
-/// GUI 进程 PATH 不含 ~/.local/bin 等,经 login shell 批量解析并缓存
-static CLI_CACHE: Mutex<Option<HashMap<String, Option<String>>>> = Mutex::new(None);
-
-fn resolve_clis(bins: &[&str]) -> HashMap<String, Option<String>> {
- let mut cache = CLI_CACHE.lock().unwrap();
- let map = cache.get_or_insert_with(HashMap::new);
- let missing: Vec<&str> = bins.iter().filter(|b| !map.contains_key(**b)).copied().collect();
- if !missing.is_empty() {
- let script = missing
- .iter()
- .map(|b| format!("printf '%s\\t' {b}; command -v {b} || echo"))
- .collect::<Vec<_>>()
- .join("; ");
- let out = Command::new("/bin/zsh").args(["-lic", &script]).output();
- let stdout = out
- .ok()
- .map(|o| String::from_utf8_lossy(&o.stdout).to_string())
- .unwrap_or_default();
- let mut found: HashMap<&str, String> = HashMap::new();
- for line in stdout.lines() {
- if let Some((name, path)) = line.split_once('\t') {
- if path.starts_with('/') {
- found.insert(name.trim(), path.trim().to_string());
- }
- }
- }
- for b in missing {
- map.insert(b.to_string(), found.get(b).cloned());
- }
- }
- bins.iter()
- .map(|b| (b.to_string(), map.get(*b).cloned().flatten()))
- .collect()
-}
-
-pub fn cli_path(agent: AgentId) -> Option<String> {
- let bin = agent_bin(agent)?;
- resolve_clis(&[bin]).get(bin).cloned().flatten()
-}
-
-/// 会话级二进制:OpenCode v2 beta 与 v1 并存、装为 `opencode2`,
-/// v2 会话(source = "opencode2")必须由它恢复,其余会话走 agent 默认 bin
-fn session_bin(meta: &SessionMeta) -> Option<&'static str> {
- if meta.agent == AgentId::Opencode && meta.source.as_deref() == Some("opencode2") {
- Some("opencode2")
- } else {
- agent_bin(meta.agent)
- }
-}
-
-pub fn agent_bin(agent: AgentId) -> Option<&'static str> {
- match agent {
- AgentId::ClaudeCode => Some("claude"),
- AgentId::Codex => Some("codex"),
- AgentId::Copilot => Some("copilot"),
- AgentId::Cursor => Some("cursor-agent"),
- AgentId::Opencode => Some("opencode"),
- AgentId::Kiro => Some("kiro"),
- AgentId::Gemini => Some("gemini"),
- AgentId::Pi => Some("pi"),
- AgentId::Omp => Some("omp"),
- AgentId::Grok => Some("grok"),
- AgentId::Kimi => Some("kimi"),
- AgentId::Antigravity => Some("agy"),
- // dsh 官方唯一分发形态是 npx(README 只有 `npx @deepseek-ai/dsh web`,
- // 不发全局命令);包名由 resume_args 作首参带上
- AgentId::Dsh => Some("npx"),
- }
-}
-
-fn resume_args(agent: AgentId, id: &str) -> Option<(Vec<String>, bool)> {
- match agent {
- AgentId::ClaudeCode => Some((vec!["--resume".into(), id.into()], true)),
- AgentId::Codex => Some((vec!["resume".into(), id.into()], false)),
- AgentId::Copilot => Some((vec![format!("--resume={id}")], false)),
- AgentId::Cursor => Some((vec!["--resume".into(), id.into()], false)),
- // 参数形制与 kooky 的 resume 集成一致(空格/等号是各家 CLI 实测约束)
- // OpenCode 两代 CLI 同为 --session;v2 会话由 session_bin 换 opencode2
- AgentId::Opencode => Some((vec!["--session".into(), id.into()], false)),
- AgentId::Pi => Some((vec!["--session".into(), id.into()], false)),
- AgentId::Omp => Some((vec!["--resume".into(), id.into()], false)),
- AgentId::Grok => Some((vec!["--resume".into(), id.into()], false)),
- AgentId::Kimi => Some((vec!["--session".into(), id.into()], false)),
- AgentId::Antigravity => Some((vec![format!("--conversation={id}")], false)),
- // dsh 官方 tui bundle 未发布(rc.8 shipped profile 只有 web/headless,
- // help 里的 --profile tui --resume 当下无消费端),web 是唯一交互
- // surface 且无 per-session 深链——resume 退而求其次:cd 到会话 cwd
- // 按官方原样 `npx @deepseek-ai/dsh web` 拉起(workspace 由启动目录
- // 决定),会话在 UI 里即点即续。官方发布 tui bundle 后切回定点 resume
- AgentId::Dsh => Some((vec!["@deepseek-ai/dsh".into(), "web".into()], true)),
- _ => None,
- }
-}
-
-/// POSIX 单引号 quote
-pub fn posix_quote(s: &str) -> String {
- if !s.is_empty()
- && s.chars()
- .all(|c| c.is_ascii_alphanumeric() || "_-./:=".contains(c))
- {
- return s.to_string();
- }
- format!("'{}'", s.replace('\'', r"'\''"))
-}
/// AppleScript 双引号字符串转义
-pub fn applescript_quote(s: &str) -> String {
+fn applescript_quote(s: &str) -> String {
s.replace('\\', r"\\").replace('"', r#"\""#)
}
@@ -189,25 +84,24 @@ impl TerminalApp {
fn is_installed(&self) -> bool {
self.resolved_app_path().is_some()
}
+}
- /// 目标消费什么:shell 命令串,还是会话深链。新增非 shell 目标时
- /// 在此声明,resume_session_in 无需再加旁路。
- fn launch_mode(&self) -> Launch {
- match self {
- TerminalApp::Terminal => Launch::Shell(launch_terminal_app),
- TerminalApp::ITerm => Launch::Shell(launch_iterm),
- TerminalApp::Warp => Launch::Shell(launch_warp),
- TerminalApp::Ghostty => Launch::Shell(launch_ghostty),
- TerminalApp::Kooky => Launch::DeepLink,
- }
- }
+/// 深链类目标整锅接管 resume(不经 agent CLI)。Kooky 是本平台唯一一例;
+/// 新增非 shell 目标在此声明,mod.rs 的 resume_session_in 无需加旁路。
+pub(super) fn deep_link_resume(meta: &SessionMeta, term: TerminalApp) -> Option<ResumeOutcome> {
+ (term == TerminalApp::Kooky).then(|| launch_kooky(meta))
}
-enum Launch {
- /// 在该终端里执行拼好的 shell 命令
- Shell(fn(&str) -> anyhow::Result<()>),
- /// 走会话深链(kooky://),不经过 agent CLI
- DeepLink,
+/// Shell 类目标的命令注入分发(深链目标已被 deep_link_resume 拦下,
+/// Kooky 臂只是护栏)
+pub(super) fn launch_shell(term: TerminalApp, command: &str) -> anyhow::Result<()> {
+ match term {
+ TerminalApp::Terminal => launch_terminal_app(command),
+ TerminalApp::ITerm => launch_iterm(command),
+ TerminalApp::Warp => launch_warp(command),
+ TerminalApp::Ghostty => launch_ghostty(command),
+ TerminalApp::Kooky => anyhow::bail!("Kooky is a deep-link target"),
+ }
}
/// 确保已装终端的应用图标提取到 `cache_dir/<id>.png`(64px),返回 id → 路径。
@@ -392,28 +286,8 @@ fn launch_warp(command: &str) -> anyhow::Result<()> {
Ok(())
}
-fn copy_to_clipboard(text: &str) {
- use std::io::Write;
- if let Ok(mut child) = Command::new("pbcopy").stdin(std::process::Stdio::piped()).spawn() {
- if let Some(stdin) = child.stdin.as_mut() {
- let _ = stdin.write_all(text.as_bytes());
- }
- let _ = child.wait();
- }
-}
-
-/// query 值的保守 percent-encode(unreserved 之外全编)
-fn percent_encode_query(s: &str) -> String {
- let mut out = String::with_capacity(s.len());
- for b in s.bytes() {
- match b {
- b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'.' | b'_' | b'~' => {
- out.push(b as char)
- }
- _ => out.push_str(&format!("%{b:02X}")),
- }
- }
- out
+pub(super) fn copy_to_clipboard(text: &str) -> bool {
+ pipe_to("pbcopy", &[], text)
}
/// KOOKY_ROSTER 之外的 agent 在 kooky 里点名会被拒——改走 kooky-cli 的哑管道:
@@ -430,7 +304,7 @@ fn launch_kooky_cli(meta: &SessionMeta) -> ResumeOutcome {
// agent CLI 走与真终端路径同一次解析(GUI 进程 PATH 不全,过 login shell),
// 顺带承担"装没装"的判断:少了这步,kooky 会开出一个只写着 command not
// found 的 tab,而 Wake 这边照报成功
- let Some(exe) = resolve_clis(&[bin]).get(bin).cloned().flatten() else {
+ let Some(exe) = resolve_cli(bin) else {
return fail(String::new(), format!("Command {bin} not found — is it installed?"));
};
let cmd = std::iter::once(exe.as_str())
@@ -447,8 +321,7 @@ fn launch_kooky_cli(meta: &SessionMeta) -> ResumeOutcome {
cmd.clone()
};
let bail = |reason: String| {
- copy_to_clipboard(&manual);
- fail(shown.clone(), format!("{reason} — command copied, run it manually"))
+ fail(shown.clone(), format!("{reason}. {}", super::clipboard_fallback(&manual)))
};
// 项目挪走了 kooky 的 --cwd 就没法落地。走同一条兜底,别让 Kooky 目标
// 比 Terminal 少一份可手动执行的命令
@@ -482,7 +355,7 @@ fn launch_kooky(meta: &SessionMeta) -> ResumeOutcome {
let mut url = format!("kooky://resume?agent={}&id={}", meta.agent.as_str(), meta.id);
if !meta.project_path.is_empty() && Path::new(&meta.project_path).is_dir() {
url.push_str("&cwd=");
- url.push_str(&percent_encode_query(&meta.project_path));
+ url.push_str(&percent_encode(&meta.project_path, false));
}
let deep_ok = Command::new("open")
.arg(&url)
@@ -505,73 +378,10 @@ fn launch_kooky(meta: &SessionMeta) -> ResumeOutcome {
}
}
-pub fn resume_session_in(meta: &SessionMeta, term: TerminalApp) -> ResumeOutcome {
- // 深链目标不走 shell 命令构建(不依赖 agent CLI)
- let Launch::Shell(run) = term.launch_mode() else {
- return launch_kooky(meta);
- };
- let Some((args, requires_cwd)) = resume_args(meta.agent, &meta.id) else {
- return ResumeOutcome {
- ok: false,
- command: String::new(),
- error: Some(format!("Resume isn't supported for {} yet", meta.agent.display_name())),
- };
- };
- let bin = session_bin(meta);
- let Some(cli) = bin.and_then(|b| resolve_clis(&[b]).get(b).cloned().flatten()) else {
- return ResumeOutcome {
- ok: false,
- command: String::new(),
- error: Some(format!(
- "Command {} not found — is it installed?",
- bin.unwrap_or("?")
- )),
- };
- };
- let cwd_ok = !meta.project_path.is_empty() && Path::new(&meta.project_path).is_dir();
- let core = std::iter::once(cli.as_str())
- .chain(args.iter().map(|s| s.as_str()))
- .map(posix_quote)
- .collect::<Vec<_>>()
- .join(" ");
- let command = if cwd_ok {
- format!("cd {} && {core}", posix_quote(&meta.project_path))
- } else {
- core
- };
- if requires_cwd && !cwd_ok {
- copy_to_clipboard(&command);
- return ResumeOutcome {
- ok: false,
- command,
- error: Some(format!("Project directory no longer exists: {} (command copied — run it manually)", meta.project_path)),
- };
- }
-
- let result = run(&command);
- match result {
- Ok(()) => ResumeOutcome {
- ok: true,
- command,
- error: None,
- },
- Err(e) => {
- copy_to_clipboard(&command);
- ResumeOutcome {
- ok: false,
- command,
- error: Some(format!("Couldn't open terminal ({e}). Command copied to clipboard — paste to run.")),
- }
- }
- }
-}
-
-/// 删除会话文件到废纸篓(macOS 用 Finder,可从废纸篓恢复)
-pub fn trash_paths(paths: &[String]) -> anyhow::Result<()> {
+/// 逐文件让 Finder 删进废纸篓(osascript 首次触发自动化授权会停等用户
+/// 点选,可能长阻塞;首错即断,已删的留在废纸篓可恢复)
+pub(super) fn trash_existing(paths: &[&str]) -> anyhow::Result<()> {
for p in paths {
- if !Path::new(p).exists() {
- continue;
- }
let esc = applescript_quote(p);
let out = osascript(&[format!(
"tell application \"Finder\" to delete (POSIX file \"{esc}\" as alias)"
@@ -583,10 +393,8 @@ pub fn trash_paths(paths: &[String]) -> anyhow::Result<()> {
Ok(())
}
-/// 致命错误提示。GPUI 窗口还没起来时这是唯一能让用户看见的通道,
-/// 否则应用就是无提示秒退。换行先压平——AppleScript 字符串字面量不能跨行。
-pub fn show_fatal_alert(message: &str) {
- eprintln!("[wake] fatal: {message}");
+/// 致命错误对话框。换行先压平——AppleScript 字符串字面量不能跨行。
+pub(super) fn alert_dialog(message: &str) {
let flat = message.replace(['\n', '\r'], " ");
let _ = osascript(&[format!(
"display alert \"Wake can't start\" message \"{}\" as critical",
@@ -594,38 +402,16 @@ pub fn show_fatal_alert(message: &str) {
)]);
}
-/// 起 Finder 子进程并**收尸**。两头都不能选:`status()` 把 UI 线程阻塞到
-/// LaunchServices 往返结束(Finder 冷启上百毫秒);裸 `spawn()` 丢掉 Child 则
-/// 留僵尸——Unix 上 Child 的 Drop 不 wait,实测点几次就攒几个 `<defunct>`,
-/// 直到 Wake 退出才回收。故 spawn 后交给一个短命线程 wait
-fn spawn_and_reap(mut cmd: Command) {
- if let Ok(mut child) = cmd.spawn() {
- std::thread::spawn(move || {
- let _ = child.wait();
- });
- }
-}
-
-/// 在 Finder 里打开这个位置:目录直接进入,文件则退回在父目录中选中它
-/// ——SQLite 型的数据源是库文件,直接 open 会把它丢给默认应用打开
-pub fn open_in_finder(path: &str) {
- if Path::new(path).is_dir() {
- let mut cmd = Command::new("open");
- cmd.arg(path);
- spawn_and_reap(cmd);
- } else {
- reveal_in_finder(path);
- }
+/// 在 Finder 里进入目录
+pub(super) fn open_dir(path: &str) {
+ let mut cmd = Command::new("open");
+ cmd.arg(path);
+ let _ = spawn_and_reap(cmd);
}
-pub fn reveal_in_finder(path: &str) {
- // SQLite 型会话是 <db>#<id> 虚拟路径,磁盘上不存在——reveal 库文件本体
- let p = if Path::new(path).exists() {
- path
- } else {
- path.rsplit_once('#').map(|(db, _)| db).unwrap_or(path)
- };
+/// 在 Finder 里选中文件(收 mod.rs 已剥好虚拟后缀的真实路径)
+pub(super) fn reveal_path(path: &str) {
let mut cmd = Command::new("open");
- cmd.args(["-R", p]);
- spawn_and_reap(cmd);
+ cmd.args(["-R", path]);
+ let _ = spawn_and_reap(cmd);
}
diff --git a/crates/wake-core/src/services/terminal/mod.rs b/crates/wake-core/src/services/terminal/mod.rs
new file mode 100644
index 0000000..b1c7dd4
--- /dev/null
+++ b/crates/wake-core/src/services/terminal/mod.rs
@@ -0,0 +1,315 @@
+//! 会话恢复 / 系统集成服务。策略层(恢复命令拼装、CLI 解析、打开/选中/
+//! 删除的平台无关流程)在本文件;macos.rs / linux.rs 只提供原语(起终端、
+//! 开目录、选中文件、进废纸篓、弹对话框、写剪贴板),两边导出同形接口
+//! (TerminalApp 变体集合各异,UI 只遍历不点名)。
+
+use crate::models::{AgentId, SessionMeta};
+use std::collections::HashMap;
+use std::path::Path;
+use std::process::Command;
+use std::sync::Mutex;
+
+#[cfg(target_os = "macos")]
+mod macos;
+#[cfg(target_os = "macos")]
+use macos as platform;
+
+#[cfg(target_os = "linux")]
+mod linux;
+#[cfg(target_os = "linux")]
+use linux as platform;
+
+// 公共层的 shell 拼装 / login shell / posix_quote 全建立在 POSIX 假设上,
+// 新平台(Windows)进来必须给出自己的模块并重审这些前提,不能静默沿用
+#[cfg(not(any(target_os = "macos", target_os = "linux")))]
+compile_error!("wake terminal services: unsupported platform — add a platform module (POSIX assumptions throughout)");
+
+pub use platform::{ensure_app_icons, installed_terminals, terminals_for, TerminalApp};
+
+#[derive(Debug, Clone)]
+pub struct ResumeOutcome {
+ pub ok: bool,
+ pub command: String,
+ pub error: Option<String>,
+}
+
+/// GUI 进程 PATH 不含 ~/.local/bin 等,经 login shell 批量解析并缓存
+static CLI_CACHE: Mutex<Option<HashMap<String, Option<String>>>> = Mutex::new(None);
+
+/// 解析 PATH 用的 login shell:macOS 固定 zsh(系统默认);Linux 尊重 $SHELL
+/// (bash/zsh/fish 对 `-lic` 与 `command -v` 语义一致),缺省 /bin/bash
+fn login_shell() -> String {
+ if cfg!(target_os = "macos") {
+ return "/bin/zsh".to_string();
+ }
+ std::env::var("SHELL")
+ .ok()
+ .filter(|s| s.starts_with('/'))
+ .unwrap_or_else(|| "/bin/bash".to_string())
+}
+
+fn resolve_clis(bins: &[&str]) -> HashMap<String, Option<String>> {
+ let mut cache = CLI_CACHE.lock().unwrap();
+ let map = cache.get_or_insert_with(HashMap::new);
+ let missing: Vec<&str> = bins.iter().filter(|b| !map.contains_key(**b)).copied().collect();
+ if !missing.is_empty() {
+ let script = missing
+ .iter()
+ .map(|b| format!("printf '%s\\t' {b}; command -v {b} || echo"))
+ .collect::<Vec<_>>()
+ .join("; ");
+ let out = Command::new(login_shell()).args(["-lic", &script]).output();
+ let stdout = out
+ .ok()
+ .map(|o| String::from_utf8_lossy(&o.stdout).to_string())
+ .unwrap_or_default();
+ let mut found: HashMap<&str, String> = HashMap::new();
+ for line in stdout.lines() {
+ if let Some((name, path)) = line.split_once('\t') {
+ if path.starts_with('/') {
+ found.insert(name.trim(), path.trim().to_string());
+ }
+ }
+ }
+ for b in missing {
+ map.insert(b.to_string(), found.get(b).cloned());
+ }
+ }
+ bins.iter()
+ .map(|b| (b.to_string(), map.get(*b).cloned().flatten()))
+ .collect()
+}
+
+/// 单 bin 解析(命中缓存则不起 shell)
+fn resolve_cli(bin: &str) -> Option<String> {
+ resolve_clis(&[bin]).get(bin).cloned().flatten()
+}
+
+pub fn cli_path(agent: AgentId) -> Option<String> {
+ agent_bin(agent).and_then(resolve_cli)
+}
+
+/// 会话级二进制:OpenCode v2 beta 与 v1 并存、装为 `opencode2`,
+/// v2 会话(source = "opencode2")必须由它恢复,其余会话走 agent 默认 bin
+fn session_bin(meta: &SessionMeta) -> Option<&'static str> {
+ if meta.agent == AgentId::Opencode && meta.source.as_deref() == Some("opencode2") {
+ Some("opencode2")
+ } else {
+ agent_bin(meta.agent)
+ }
+}
+
+pub fn agent_bin(agent: AgentId) -> Option<&'static str> {
+ match agent {
+ AgentId::ClaudeCode => Some("claude"),
+ AgentId::Codex => Some("codex"),
+ AgentId::Copilot => Some("copilot"),
+ AgentId::Cursor => Some("cursor-agent"),
+ AgentId::Opencode => Some("opencode"),
+ AgentId::Kiro => Some("kiro"),
+ AgentId::Gemini => Some("gemini"),
+ AgentId::Pi => Some("pi"),
+ AgentId::Omp => Some("omp"),
+ AgentId::Grok => Some("grok"),
+ AgentId::Kimi => Some("kimi"),
+ AgentId::Antigravity => Some("agy"),
+ // dsh 官方唯一分发形态是 npx(README 只有 `npx @deepseek-ai/dsh web`,
+ // 不发全局命令);包名由 resume_args 作首参带上
+ AgentId::Dsh => Some("npx"),
+ }
+}
+
+fn resume_args(agent: AgentId, id: &str) -> Option<(Vec<String>, bool)> {
+ match agent {
+ AgentId::ClaudeCode => Some((vec!["--resume".into(), id.into()], true)),
+ AgentId::Codex => Some((vec!["resume".into(), id.into()], false)),
+ AgentId::Copilot => Some((vec![format!("--resume={id}")], false)),
+ AgentId::Cursor => Some((vec!["--resume".into(), id.into()], false)),
+ // 参数形制与 kooky 的 resume 集成一致(空格/等号是各家 CLI 实测约束)
+ // OpenCode 两代 CLI 同为 --session;v2 会话由 session_bin 换 opencode2
+ AgentId::Opencode => Some((vec!["--session".into(), id.into()], false)),
+ AgentId::Pi => Some((vec!["--session".into(), id.into()], false)),
+ AgentId::Omp => Some((vec!["--resume".into(), id.into()], false)),
+ AgentId::Grok => Some((vec!["--resume".into(), id.into()], false)),
+ AgentId::Kimi => Some((vec!["--session".into(), id.into()], false)),
+ AgentId::Antigravity => Some((vec![format!("--conversation={id}")], false)),
+ // dsh 官方 tui bundle 未发布(rc.8 shipped profile 只有 web/headless,
+ // help 里的 --profile tui --resume 当下无消费端),web 是唯一交互
+ // surface 且无 per-session 深链——resume 退而求其次:cd 到会话 cwd
+ // 按官方原样 `npx @deepseek-ai/dsh web` 拉起(workspace 由启动目录
+ // 决定),会话在 UI 里即点即续。官方发布 tui bundle 后切回定点 resume
+ AgentId::Dsh => Some((vec!["@deepseek-ai/dsh".into(), "web".into()], true)),
+ _ => None,
+ }
+}
+
+/// POSIX 单引号 quote
+pub fn posix_quote(s: &str) -> String {
+ if !s.is_empty()
+ && s.chars()
+ .all(|c| c.is_ascii_alphanumeric() || "_-./:=".contains(c))
+ {
+ return s.to_string();
+ }
+ format!("'{}'", s.replace('\'', r"'\''"))
+}
+
+/// 保守 percent-encode(RFC 3986 unreserved 之外全编;keep_slash 供
+/// file:// URL 保路径分隔)。两平台共用,编码集只此一份。
+pub(crate) fn percent_encode(s: &str, keep_slash: bool) -> String {
+ use std::fmt::Write;
+ let mut out = String::with_capacity(s.len());
+ for b in s.bytes() {
+ match b {
+ b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'.' | b'_' | b'~' => {
+ out.push(b as char)
+ }
+ b'/' if keep_slash => out.push('/'),
+ _ => {
+ let _ = write!(out, "%{b:02X}");
+ }
+ }
+ }
+ out
+}
+
+pub fn resume_session_in(meta: &SessionMeta, term: TerminalApp) -> ResumeOutcome {
+ // 深链类目标(macOS Kooky)由平台整锅接管,不走 shell 命令构建;
+ // 新增非 shell 目标在平台的 deep_link_resume 里声明,这里无需加旁路
+ if let Some(outcome) = platform::deep_link_resume(meta, term) {
+ return outcome;
+ }
+ let Some((args, requires_cwd)) = resume_args(meta.agent, &meta.id) else {
+ return ResumeOutcome {
+ ok: false,
+ command: String::new(),
+ error: Some(format!("Resume isn't supported for {} yet", meta.agent.display_name())),
+ };
+ };
+ let bin = session_bin(meta);
+ let Some(cli) = bin.and_then(resolve_cli) else {
+ return ResumeOutcome {
+ ok: false,
+ command: String::new(),
+ error: Some(format!(
+ "Command {} not found — is it installed?",
+ bin.unwrap_or("?")
+ )),
+ };
+ };
+ let cwd_ok = !meta.project_path.is_empty() && Path::new(&meta.project_path).is_dir();
+ let core = std::iter::once(cli.as_str())
+ .chain(args.iter().map(|s| s.as_str()))
+ .map(posix_quote)
+ .collect::<Vec<_>>()
+ .join(" ");
+ let command = if cwd_ok {
+ format!("cd {} && {core}", posix_quote(&meta.project_path))
+ } else {
+ core
+ };
+ if requires_cwd && !cwd_ok {
+ let hint = clipboard_fallback(&command);
+ return ResumeOutcome {
+ ok: false,
+ command,
+ error: Some(format!("Project directory no longer exists: {}. {hint}", meta.project_path)),
+ };
+ }
+
+ let result = platform::launch_shell(term, &command);
+ match result {
+ Ok(()) => ResumeOutcome {
+ ok: true,
+ command,
+ error: None,
+ },
+ Err(e) => {
+ let hint = clipboard_fallback(&command);
+ ResumeOutcome {
+ ok: false,
+ command,
+ error: Some(format!("Couldn't open terminal ({e}). {hint}")),
+ }
+ }
+ }
+}
+
+/// 失败兜底通知的后半句:剪贴板写成了才说 copied(Linux 可能三个剪贴板
+/// 工具都不在),没写成把命令本体给出来——error 是失败通知唯一展示面
+/// (workbench 只渲染 error 文案),命令不能只活在 ResumeOutcome.command 里
+fn clipboard_fallback(command: &str) -> String {
+ if platform::copy_to_clipboard(command) {
+ "Command copied to clipboard — paste to run.".to_string()
+ } else {
+ format!("Run manually: {command}")
+ }
+}
+
+/// 删除会话文件到系统回收站(可恢复)。虚拟路径 `<db>#<id>` 与已消失的
+/// 文件在此过滤(不变量 3:SQLite 型只 tombstone),平台原语只收真实路径。
+/// 部分失败语义:平台实现可能删到一半报错(macOS 逐文件、Linux 批量),
+/// 调用方按"整批可疑"处理即可——已进回收站的文件可恢复,无害。
+pub fn trash_paths(paths: &[String]) -> anyhow::Result<()> {
+ let existing: Vec<&str> = paths
+ .iter()
+ .map(|s| s.as_str())
+ .filter(|p| Path::new(p).exists())
+ .collect();
+ if existing.is_empty() {
+ return Ok(());
+ }
+ platform::trash_existing(&existing)
+}
+
+/// 致命错误提示。GPUI 窗口还没起来时这是唯一能让用户看见的通道,
+/// 否则应用就是无提示秒退;stderr 始终先落一份。
+pub fn show_fatal_alert(message: &str) {
+ eprintln!("[wake] fatal: {message}");
+ platform::alert_dialog(message);
+}
+
+/// 在文件管理器里打开这个位置:目录直接进入,文件则退回在父目录中选中它
+/// ——SQLite 型的数据源是库文件,直接交给 opener 会把它丢给默认应用打开
+pub fn open_in_file_manager(path: &str) {
+ if Path::new(path).is_dir() {
+ platform::open_dir(path);
+ } else {
+ reveal_in_file_manager(path);
+ }
+}
+
+/// 选中文件。调用点都是 UI 线程的 on_click,而平台原语可能长阻塞
+/// (Linux 的 D-Bus ShowItems 会等文件管理器 activation 冷启)——统一
+/// 甩给短命线程,UI 零等待。
+pub fn reveal_in_file_manager(path: &str) {
+ let real = crate::adapters::sqlite_ro::strip_virtual_path(path).to_string();
+ std::thread::spawn(move || platform::reveal_path(&real));
+}
+
+/// 把 text 经管道写给 `bin args…` 的 stdin(剪贴板工具用),按退出码报成败
+/// ——"copied to clipboard" 的用户提示以此为据,不能 spawn 成功就算数。
+/// 三家 Linux 工具与 pbcopy 都在拿到内容后自行 fork 常驻,wait 即刻返回。
+pub(crate) fn pipe_to(bin: &str, args: &[&str], text: &str) -> bool {
+ use std::io::Write;
+ let Ok(mut child) = Command::new(bin).args(args).stdin(std::process::Stdio::piped()).spawn()
+ else {
+ return false;
+ };
+ if let Some(mut stdin) = child.stdin.take() {
+ let _ = stdin.write_all(text.as_bytes());
+ }
+ child.wait().map(|s| s.success()).unwrap_or(false)
+}
+
+/// 起子进程并**收尸**,spawn 失败上抛。`status()` 不能用:把调用线程阻塞
+/// 到进程结束(文件管理器冷启上百毫秒);裸 `spawn()` 丢掉 Child 也不行:
+/// Unix 上 Child 的 Drop 不 wait,实测点几次就攒几个 `<defunct>`,直到
+/// Wake 退出才回收。故 spawn 后交给一个短命线程 wait。
+fn spawn_and_reap(mut cmd: Command) -> std::io::Result<()> {
+ let mut child = cmd.spawn()?;
+ std::thread::spawn(move || {
+ let _ = child.wait();
+ });
+ Ok(())
+}
diff --git a/crates/wake/assets/icons/window-close.svg b/crates/wake/assets/icons/window-close.svg
new file mode 100644
index 0000000..54cbeea
--- /dev/null
+++ b/crates/wake/assets/icons/window-close.svg
@@ -0,0 +1,16 @@
+<!-- @license lucide-static v0.462.0 - ISC (lucide "x", renamed for gpui-component window controls) -->
+<svg
+ class="lucide lucide-x"
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <path d="M18 6 6 18" />
+ <path d="m6 6 12 12" />
+</svg>
diff --git a/crates/wake/assets/icons/window-maximize.svg b/crates/wake/assets/icons/window-maximize.svg
new file mode 100644
index 0000000..7afcd5a
--- /dev/null
+++ b/crates/wake/assets/icons/window-maximize.svg
@@ -0,0 +1,15 @@
+<!-- @license lucide-static v0.462.0 - ISC (lucide "square", renamed for gpui-component window controls) -->
+<svg
+ class="lucide lucide-square"
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <rect width="18" height="18" x="3" y="3" rx="2" />
+</svg>
diff --git a/crates/wake/assets/icons/window-minimize.svg b/crates/wake/assets/icons/window-minimize.svg
new file mode 100644
index 0000000..db3e837
--- /dev/null
+++ b/crates/wake/assets/icons/window-minimize.svg
@@ -0,0 +1,15 @@
+<!-- @license lucide-static v0.462.0 - ISC (lucide "minus", renamed for gpui-component window controls) -->
+<svg
+ class="lucide lucide-minus"
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <path d="M5 12h14" />
+</svg>
diff --git a/crates/wake/assets/icons/window-restore.svg b/crates/wake/assets/icons/window-restore.svg
new file mode 100644
index 0000000..ab34983
--- /dev/null
+++ b/crates/wake/assets/icons/window-restore.svg
@@ -0,0 +1,16 @@
+<!-- @license lucide-static v0.462.0 - ISC (lucide "copy", renamed for gpui-component window controls) -->
+<svg
+ class="lucide lucide-copy"
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <rect width="14" height="14" x="8" y="8" rx="2" ry="2" />
+ <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />
+</svg>
diff --git a/crates/wake/src/assets.rs b/crates/wake/src/assets.rs
index ceb0e09..093eff1 100644
--- a/crates/wake/src/assets.rs
+++ b/crates/wake/src/assets.rs
@@ -57,6 +57,12 @@ brands!(
);
icons!(
+ // gpui-component TitleBar 的 Linux 窗口控制按钮(IconName::Window* 按这
+ // 四个路径取图;缺了按钮就渲染成隐形热区——2026-08-24 Codex review)
+ "window-minimize",
+ "window-maximize",
+ "window-restore",
+ "window-close",
"star",
"pin",
"download",
diff --git a/crates/wake/src/main.rs b/crates/wake/src/main.rs
index 64d7d54..d7b8190 100644
--- a/crates/wake/src/main.rs
+++ b/crates/wake/src/main.rs
@@ -26,11 +26,12 @@ fn main() {
w.update(cx, |_, window, _| window.remove_window()).ok();
}
});
+ // secondary = macOS 的 cmd、其他平台的 ctrl(gpui keystroke 内建别名)
cx.bind_keys([
- KeyBinding::new("cmd-k", ToggleSearch, Some(KEY_CONTEXT)),
- KeyBinding::new("cmd-r", RefreshSessions, Some(KEY_CONTEXT)),
- KeyBinding::new("cmd-q", Quit, None),
- KeyBinding::new("cmd-w", CloseWindow, None),
+ KeyBinding::new(ui::SEARCH_KEYSTROKE, ToggleSearch, Some(KEY_CONTEXT)),
+ KeyBinding::new("secondary-r", RefreshSessions, Some(KEY_CONTEXT)),
+ KeyBinding::new("secondary-q", Quit, None),
+ KeyBinding::new("secondary-w", CloseWindow, None),
// ⌘K 面板:焦点在搜索输入框,↑↓ 冒泡到面板容器挪选中
KeyBinding::new("up", PaletteUp, Some(PALETTE_CONTEXT)),
KeyBinding::new("down", PaletteDown, Some(PALETTE_CONTEXT)),
@@ -51,15 +52,38 @@ fn main() {
]);
let bounds = Bounds::centered(None, size(px(1180.), px(760.)), cx);
+ // macOS:隐藏系统标题栏、内容顶到窗顶,traffic light 悬浮在侧栏上;
+ // Linux:标准服务端装饰(appears_transparent 仅 macOS/Windows 生效;
+ // GNOME Wayland 不给 SSD 时暂无标题栏,已知限制,实机验收后再定 CSD)。
+ // cfg! 而非 #[cfg]:两支在任一平台都参与类型检查,别让另一支只有 CI 见得到
+ let titlebar = if cfg!(target_os = "macos") {
+ TitlebarOptions {
+ title: None,
+ appears_transparent: true,
+ traffic_light_position: Some(point(px(20.), px(11.))),
+ }
+ } else {
+ TitlebarOptions {
+ title: Some("Wake".into()),
+ appears_transparent: false,
+ traffic_light_position: None,
+ }
+ };
cx.open_window(
WindowOptions {
- titlebar: Some(TitlebarOptions {
- title: None,
- appears_transparent: true,
- traffic_light_position: Some(point(px(20.), px(11.))),
- }),
+ titlebar: Some(titlebar),
window_bounds: Some(WindowBounds::Windowed(bounds)),
window_min_size: Some(size(px(940.), px(620.))),
+ // Linux 桌面按它归组窗口、匹配 .desktop(StartupWMClass=wake)
+ app_id: Some("wake".into()),
+ // Wayland 显式请求 CSD(2026-08-24 Codex review):默认的 Server
+ // 请求在 GNOME/Mutter(无 zxdg-decoration 协议)下会被 gpui 记成
+ // Server 而 compositor 实际什么都不画——窗口既无系统标题栏、
+ // workbench 又按 Server 不挂 TitleBar,彻底没有关窗/拖拽面。
+ // 请求 Client 后:Wayland 全家走 CSD(TitleBar 补位),X11 侧
+ // gpui 探测 compositor 不支持 CSD 时仍自动回报 Server(WM 标题
+ // 栏照常、TitleBar 不挂),macOS 忽略此字段
+ window_decorations: Some(WindowDecorations::Client),
..Default::default()
},
|window, cx| {
diff --git a/crates/wake/src/ui.rs b/crates/wake/src/ui.rs
index 5661754..2db104f 100644
--- a/crates/wake/src/ui.rs
+++ b/crates/wake/src/ui.rs
@@ -24,6 +24,30 @@ pub const FONT_MSG_BODY: Pixels = px(13.);
/// thinking 摘要行(斜体)
pub const FONT_MSG_THINKING: Pixels = px(11.5);
+// ---------------- 平台文案 ----------------
+// 同一处 UI 在不同平台叫不同名字/键(Finder vs 文件管理器、⌘ vs Ctrl),
+// 文案引用这里的常量,别在 render 里散落字面量。cfg! 表达式让两支在任一
+// 平台都过类型检查(名词与 wake-core terminal 的平台实现对应:macos=Finder)。
+
+pub const SHOW_IN_FM: &str =
+ if cfg!(target_os = "macos") { "Show in Finder" } else { "Show in File Manager" };
+pub const REVEAL_IN_FM: &str =
+ if cfg!(target_os = "macos") { "Reveal in Finder" } else { "Reveal in File Manager" };
+
+/// ⌘K 面板的唯一绑定串——main.rs 的 bind_keys 与下方徽标同源,改键只动这里
+pub const SEARCH_KEYSTROKE: &str = "secondary-k";
+
+/// 搜索快捷键徽标,从真实绑定串派生("⌘K"/"Ctrl+K"——secondary→平台键
+/// 与显示形制都由 gpui/Kbd 持有,这里零平台知识)
+pub fn search_key_hint() -> &'static str {
+ use std::sync::OnceLock;
+ static HINT: OnceLock<String> = OnceLock::new();
+ HINT.get_or_init(|| {
+ let key = gpui::Keystroke::parse(SEARCH_KEYSTROKE).expect("SEARCH_KEYSTROKE parses");
+ gpui_component::kbd::Kbd::format(&key)
+ })
+}
+
// ---------------- 间距与结构 ----------------
// 间距刻度:4px 网格。新代码一律引用常量或显式 px();
// 注意 gpui 的 rem 间距类有幽灵值(rem=14px 下 p_2p5=8.75px、p_3=10.5px,
diff --git a/crates/wake/src/workbench.rs b/crates/wake/src/workbench.rs
index 810c694..7e70952 100644
--- a/crates/wake/src/workbench.rs
+++ b/crates/wake/src/workbench.rs
@@ -1186,7 +1186,7 @@ impl Workbench {
.hover(|s| s.bg(theme.secondary_hover))
.active(|s| s.bg(theme.secondary_active))
.on_click(move |_, _, _| {
- terminal::open_in_finder(&path)
+ terminal::open_in_file_manager(&path)
})
.child(
icon("icons/folder.svg")
@@ -1194,7 +1194,7 @@ impl Workbench {
.flex_shrink_0()
.text_color(theme.muted_foreground),
)
- .child("Show in Finder"),
+ .child(SHOW_IN_FM),
)
}),
)
@@ -1965,8 +1965,8 @@ impl Workbench {
});
}
- /// 执行删除:文件进废纸篓 + 自库 tombstone。trash_paths 走 osascript 驱动
- /// Finder,首次触发自动化授权时会一直停着等用户点选——必须离开 UI 线程,
+ /// 执行删除:文件进废纸篓 + 自库 tombstone。trash_paths 可能长阻塞
+ /// (契约见 terminal/mod.rs,平台缘由见各实现 doc)——必须离开 UI 线程,
/// 否则界面在授权框弹出的整段时间里完全冻结。
fn do_delete(
&mut self,
@@ -2084,7 +2084,7 @@ impl Workbench {
// ---------- 渲染 ----------
- fn render_sidebar(&self, cx: &Context<Self>) -> impl IntoElement {
+ fn render_sidebar(&self, window: &Window, cx: &Context<Self>) -> impl IntoElement {
let theme = cx.theme();
let all_active = self.selected_agent.is_none()
&& self.selected_project.is_none()
@@ -2123,13 +2123,20 @@ impl Workbench {
None
};
+ // macOS 恒挂 TitleBar(traffic light 占位 + 拖拽区);Linux 按运行时装饰
+ // 状态:系统给了标题栏(Server)就不挂——TitleBar 的 Linux 实现无条件画
+ // min/max/close 三按钮,会与系统标题栏成双套控制;系统不给(GNOME
+ // Wayland 无 SSD 回落 Client)才挂,此时它是唯一的拖拽区与窗口按钮
+ // (按钮图标 window-*.svg 在 assets 注册表,缺了就是隐形热区)
+ let show_titlebar = cfg!(target_os = "macos")
+ || matches!(window.window_decorations(), Decorations::Client { .. });
v_flex()
.w(px(224.))
.h_full()
.flex_shrink_0()
.bg(theme.sidebar)
// 压平 titlebar 靠 theme.rs 的 title_bar/title_bar_border token,不再叠加覆写
- .child(TitleBar::new())
+ .when(show_titlebar, |this| this.child(TitleBar::new()))
.child(
div()
.flex_shrink_0()
@@ -2188,7 +2195,7 @@ impl Workbench {
div()
.flex_shrink_0()
.text_size(FONT_LABEL)
- .child("⌘K"),
+ .child(search_key_hint()),
),
)
),
@@ -2622,7 +2629,7 @@ impl Workbench {
px(58.),
px(26.),
"No session selected",
- "Pick one from the list, or press ⌘K to search.",
+ format!("Pick one from the list, or press {} to search.", search_key_hint()),
cx,
)),
)
@@ -2652,12 +2659,12 @@ impl Workbench {
}),
)
.item(
- PopupMenuItem::new(" Reveal in Finder")
+ PopupMenuItem::new(format!(" {REVEAL_IN_FM}"))
.icon(icon("icons/folder.svg").with_size(px(15.)))
.on_click(move |_, _, cx| {
reveal_entity.update(cx, |this, _| {
if let Some(detail) = &this.detail {
- terminal::reveal_in_finder(&detail.meta.file_path);
+ terminal::reveal_in_file_manager(&detail.meta.file_path);
}
});
}),
@@ -2967,7 +2974,7 @@ impl Workbench {
.cursor_pointer()
.hover(|s| s.text_colored(theme.foreground, FONT_LABEL))
.on_click(move |_, _, _| {
- terminal::reveal_in_finder(&file_path);
+ terminal::reveal_in_file_manager(&file_path);
})
.child(icon("icons/file-text.svg").with_size(px(12.)).flex_shrink_0())
.child(div().min_w_0().truncate().child(display_file_path(&meta.file_path)))
@@ -3457,7 +3464,7 @@ impl Render for Workbench {
.child(
h_flex()
.size_full()
- .child(self.render_sidebar(cx))
+ .child(self.render_sidebar(window, cx))
.child(self.render_session_list(cx))
.child(self.render_detail(window, cx)),
)
diff --git a/scripts/make-linux.sh b/scripts/make-linux.sh
new file mode 100755
index 0000000..adf3aea
--- /dev/null
+++ b/scripts/make-linux.sh
@@ -0,0 +1,80 @@
+#!/usr/bin/env bash
+# 构建 Linux 发行产物:release 二进制 + .desktop + SVG 图标,打成
+# tar.gz(通用)与 .deb(Debian/Ubuntu)。在 Linux 上跑(CI 或容器);
+# macOS 打包走 scripts/make-app.sh,两边互不认识对方的产物。
+# 用法: scripts/make-linux.sh
+set -euo pipefail
+cd "$(dirname "$0")/.."
+
+ASSETS=crates/wake/assets
+TARGET_DIR=${CARGO_TARGET_DIR:-target}
+VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
+ARCH=$(dpkg --print-architecture 2>/dev/null || uname -m)
+
+# 1. release 构建(二进制名 Wake 来自 [[bin]],macOS 菜单栏需要;
+# Linux 装成小写 wake,CLI 惯例)
+cargo build --release -p wake
+
+STAGE=$(mktemp -d)/wake-${VERSION}-linux-${ARCH}
+mkdir -p "$STAGE"
+cp "$TARGET_DIR/release/Wake" "$STAGE/wake"
+cp "$ASSETS/icon.svg" "$STAGE/wake.svg"
+
+# 2. .desktop(StartupWMClass 对齐 main.rs 的 app_id = "wake")
+cat > "$STAGE/wake.desktop" <<'DESKTOP'
+[Desktop Entry]
+Type=Application
+Name=Wake
+Comment=Browse, search and resume your coding agent sessions
+Exec=wake
+Icon=wake
+Terminal=false
+Categories=Development;Utility;
+StartupWMClass=wake
+DESKTOP
+
+cat > "$STAGE/install.sh" <<'INSTALL'
+#!/usr/bin/env bash
+# 装进用户目录(不需要 root):~/.local/bin + .desktop + 图标
+set -euo pipefail
+cd "$(dirname "$0")"
+install -Dm755 wake "$HOME/.local/bin/wake"
+# 桌面项写绝对路径:~/.local/bin 若是本次新建的,图形会话的 PATH 里还没有它,
+# Exec=wake 会找不到程序直到重新登录(deb 装 /usr/bin 不受此累,保持裸名)
+sed "s|^Exec=wake$|Exec=\"$HOME/.local/bin/wake\"|" wake.desktop \
+ | install -Dm644 /dev/stdin "$HOME/.local/share/applications/wake.desktop"
+install -Dm644 wake.svg "$HOME/.local/share/icons/hicolor/scalable/apps/wake.svg"
+command -v update-desktop-database >/dev/null && update-desktop-database "$HOME/.local/share/applications" || true
+echo "Installed. Make sure ~/.local/bin is on your PATH, then run: wake"
+INSTALL
+chmod +x "$STAGE/install.sh"
+
+# 3. tar.gz
+mkdir -p dist
+tar -C "$(dirname "$STAGE")" -czf "dist/wake-${VERSION}-linux-${ARCH}.tar.gz" "$(basename "$STAGE")"
+
+# 4. .deb(dpkg-deb 在则打;Depends 按 ldd 实测的动态链接面,
+# rusqlite/zstd 是 bundled 静态、不进清单)
+if command -v dpkg-deb >/dev/null; then
+ DEB=$(mktemp -d)/wake_deb
+ mkdir -p "$DEB/DEBIAN"
+ install -Dm755 "$STAGE/wake" "$DEB/usr/bin/wake"
+ install -Dm644 "$STAGE/wake.desktop" "$DEB/usr/share/applications/wake.desktop"
+ install -Dm644 "$STAGE/wake.svg" "$DEB/usr/share/icons/hicolor/scalable/apps/wake.svg"
+ cat > "$DEB/DEBIAN/control" <<CONTROL
+Package: wake
+Version: ${VERSION}
+Section: devel
+Priority: optional
+Architecture: ${ARCH}
+Depends: libc6, libgcc-s1, libfreetype6, libfontconfig1, zlib1g, libxcb1, libxcb-xkb1, libxkbcommon0, libxkbcommon-x11-0, libwayland-client0, libvulkan1, mesa-vulkan-drivers, xdg-utils
+Maintainer: Corey Chiu <[email protected]>
+Homepage: https://github.com/iAmCorey/Wake
+Description: Coding agent session manager
+ Browse, search and resume sessions from Claude Code, Codex and
+ other local coding agents in one place.
+CONTROL
+ dpkg-deb --build --root-owner-group "$DEB" "dist/wake_${VERSION}_${ARCH}.deb" >/dev/null
+fi
+
+ls -lh dist/wake*${VERSION}* | awk '{print $NF, "("$5")"}'