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 Session locations panel; single-instance adapter roster

Corey Chiuf1357e13f53d
diff --git a/DESIGN.md b/DESIGN.md
index 2f96e52..be732c1 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -126,14 +126,15 @@ UI 语言英文;会话正文保持原语言。元信息分隔符固定为前后
### 资料库侧栏
-- 顶部是唯一的全文搜索入口,文案 "Search sessions",右侧显示 `⌘K`,右侧并排 refresh 按钮;Search/All Sessions/Starred 固定不随滚动。
-- 搜索行必须有防溢出结构:标签文字 `flex_1 + min_w_0 + truncate`,图标与 `⌘K` 徽标显式 `flex_shrink_0`。裸文字子元素的最小宽度被内容锁死,侧栏一窄就会把 refresh 按钮挤出边界裁掉。
+- 顶部是唯一的全文搜索入口,文案 "Search sessions",右侧显示 `⌘K`;Search/All Sessions/Starred 固定不随滚动。
+- 搜索行必须有防溢出结构:标签文字 `flex_1 + min_w_0 + truncate`,图标与 `⌘K` 徽标显式 `flex_shrink_0`。裸文字子元素的最小宽度被内容锁死,侧栏一窄就会把右侧元素挤出边界裁掉。
- **行分两级**(侧栏纵向层级的来源,不得拉平):主导航 All Sessions/Starred 32px 行高 + Body 14;分组展开项(agent/项目)26px 行高 + Caption 12 + 整行右移 `SUB_INDENT` 12px 表达从属。
- **每行必须有行首元素**,由 `RowLead` 枚举强制(`Icon` 或 `Brand` 两态,无 `None`):主导航用 Lucide 单线图标,agent 行用品牌 PNG,项目行用 `folder.svg`。槽位定宽 `LEAD_BOX` 管右侧文字起点统一,槽内居中管中轴对齐。
- 线条图标比实心品牌图视觉轻,同档里给小一号:分组项 Lucide 14 / 品牌图 18,主导航 Lucide 15。
- 行内容 = 行首元素 + 标题 + 计数;计数一律 Label 档 muted。
- 组头 "Agents"/"Projects" 用 Body 档常规字重 + muted 色(与主导航同字号同字重,仅靠颜色和"无行首图标"区分——加粗会让组头压过它统辖的行),带 13px chevron 可折叠。
-- 底部状态栏"常态沉默":仅刷新中或监听不可用时出现,顶部 hairline 分隔;文案须可 truncate,窄侧栏放不下长句(故为 "Live updates off" 而非带操作建议的整句)。
+- 底部工具条常驻,顶部 hairline 分隔,按钮靠右排列(次要操作区:透明底、hover 才出色,不与导航行选中态抢注意力)——左为 "Session locations"(硬盘图标,开面板列出每家 agent 的数据路径、会话数,点击行在 Finder 打开),右为 refresh。
+- 工具条内的**状态行"常态沉默"**:仅刷新中或监听不可用时出现在按钮行上方;文案须可 truncate,窄侧栏放不下长句(故为 "Live updates off" 而非带操作建议的整句)。
- 不把项目包装成卡片,不堆叠分支、时间或重复图标。项目行不加彩色标识——同一图标重复十几次不传递信息。
### 会话流
@@ -189,7 +190,7 @@ emoji 不再承担界面或正文结构图标职责。
- UI chrome 只使用内嵌 Lucide 单线 SVG,不使用 Unicode 或 emoji 图标;Agent 身份用内嵌品牌 PNG,经 `img()` 渲染并**保持原色**(不得用 `text_color` 着色,选中态也不变色)。
- 品牌 PNG 登记在 `assets.rs` 的 `brands!` 宏,文件名 = `AgentId::as_str()`,路径含 `.png`。入库前须裁掉透明边并保持正方形;带白色/彩色底的 app-icon 风格图必须先抠底,否则在侧栏材质上会露出白方块。
- 品牌图标侧栏分组项 18px、内容区(列表/搜索/详情)15px;Lucide 行内图标 13–15px;主操作与工具栏图标 14–16px;空态图标 22–26px。
-- 面板圆角 12px,列表与侧栏选择 8px,按钮固定 6px,快捷键标签 5px。
+- 面板圆角 12px,列表与侧栏选择 8px,按钮固定 6px,快捷键标签 5px,badge 胶囊 4px。代码里前两档走 `theme.radius_lg` / `theme.radius`,后三档见 `ui.rs` 的 `RADIUS_BUTTON` / `RADIUS_KBD` / `RADIUS_BADGE`——不要再写裸数字。
- 常驻界面零投影、零渐变、无装饰性描边。菜单、命令面板、确认框和通知由组件库提供浮层阴影。
- 相邻的自定义材质只用一套 token 和圆角语言,避免每个按钮各自模拟玻璃。
diff --git a/PRODUCT.md b/PRODUCT.md
index b3fab64..fdc26b6 100644
--- a/PRODUCT.md
+++ b/PRODUCT.md
@@ -28,7 +28,7 @@ Corey 本人(独立开发者,主力工具 Claude Code 与 Codex,中文为主)。
## Capabilities and Constraints
-已实现:十三家 adapter、FTS5 trigram 搜索(<3 码点 LIKE 降级)、**搜索跳转定位**(2026-08-18:⌘K 命中直达详情页对应消息并高亮,seq 契约保证)、详情页逐消息渲染(气泡/工具折叠簇/thinking/tree-sitter 高亮;2026-08-17 由整篇 markdown 方案升级)、恢复/收藏/置顶/导出/删除(废纸篓+墓碑)、文件监听增量、测试套件(wake-core 23 测试 + CI + pre-commit,合成 fixture)。
+已实现:十三家 adapter、FTS5 trigram 搜索(<3 码点 LIKE 降级)、**搜索跳转定位**(2026-08-18:⌘K 命中直达详情页对应消息并高亮,seq 契约保证)、详情页逐消息渲染(气泡/工具折叠簇/thinking/tree-sitter 高亮;2026-08-17 由整篇 markdown 方案升级)、恢复/收藏/置顶/导出/删除(废纸篓+墓碑)、文件监听增量、测试套件(wake-core 27 测试 + CI + pre-commit,合成 fixture)。
约束:对 agent 数据目录只读;绝不写 Codex 的 SQLite;不读凭证;GPUI 无 SF Symbols(图标用 lucide SVG 自备)。
已支持十三家 agent:Claude Code、Codex、Copilot CLI、Cursor(CLI transcripts)、OpenCode(含 OpenCode 2 beta,2026-08-20 同 adapter 双表支持,v2 会话标 opencode2 徽章)、Kiro、Gemini CLI(2026-08-17 P1 五家落地)+ Pi、Oh My Pi、Grok Build、Kimi Code、Antigravity CLI(2026-08-19 对齐 kooky 内置 roster;Antigravity 正文加密仅元数据卡片)+ DeepSeek Harness(dsh,2026-08-20,zstd 事件日志透明解压;格式由源码推断,当天用户跑出真实会话完成首验)。做不了的:Cursor IDE chats 正文加密,Windsurf/Trae 加密,Amp/Factory(Droid)/Warp 云端无本地数据,Reasonix 本机零会话格式未实测。
diff --git a/crates/wake-core/src/adapters/antigravity.rs b/crates/wake-core/src/adapters/antigravity.rs
index 62d79db..73c6291 100644
--- a/crates/wake-core/src/adapters/antigravity.rs
+++ b/crates/wake-core/src/adapters/antigravity.rs
@@ -156,10 +156,6 @@ impl AgentAdapter for AntigravityAdapter {
AgentId::Antigravity
}
- fn detect(&self) -> bool {
- self.db.is_file()
- }
-
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
let Some(rows) = self.rows() else {
return Ok(Vec::new());
@@ -209,8 +205,7 @@ impl AgentAdapter for AntigravityAdapter {
})
}
- fn watch_paths(&self) -> Vec<PathBuf> {
- // SQLite 库变更 watcher 不追踪(只认 .jsonl),依赖手动/启动时刷新
- Vec::new()
+ fn data_roots(&self) -> Vec<PathBuf> {
+ vec![self.db.clone()]
}
}
diff --git a/crates/wake-core/src/adapters/claude.rs b/crates/wake-core/src/adapters/claude.rs
index efad4c8..249bd07 100644
--- a/crates/wake-core/src/adapters/claude.rs
+++ b/crates/wake-core/src/adapters/claude.rs
@@ -466,10 +466,6 @@ impl AgentAdapter for ClaudeAdapter {
AgentId::ClaudeCode
}
- fn detect(&self) -> bool {
- self.root.is_dir()
- }
-
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
let mut refs = Vec::new();
let Ok(projects) = fs::read_dir(&self.root) else {
@@ -566,12 +562,8 @@ impl AgentAdapter for ClaudeAdapter {
v
}
- fn watch_paths(&self) -> Vec<PathBuf> {
- if self.detect() {
- vec![self.root.clone()]
- } else {
- Vec::new()
- }
+ fn data_roots(&self) -> Vec<PathBuf> {
+ vec![self.root.clone()]
}
}
diff --git a/crates/wake-core/src/adapters/codex.rs b/crates/wake-core/src/adapters/codex.rs
index c81ad2d..139cd61 100644
--- a/crates/wake-core/src/adapters/codex.rs
+++ b/crates/wake-core/src/adapters/codex.rs
@@ -18,7 +18,12 @@ pub struct CodexAdapter {
impl CodexAdapter {
pub fn new() -> Self {
- let root = dirs::home_dir().unwrap_or_default().join(".codex");
+ // codex 认 CODEX_HOME(kooky 的 CodexUsageMonitor 同样处理)。
+ // 采信前探真会话目录而不是只看根目录在不在——后者会让 CODEX_HOME
+ // 指向空目录的机器整家会话凭空消失(与 opencode 探库文件同一规则)
+ let root = super::env_dir("CODEX_HOME")
+ .filter(|p| p.join("sessions").is_dir() || p.join("archived_sessions").is_dir())
+ .unwrap_or_else(|| dirs::home_dir().unwrap_or_default().join(".codex"));
Self {
sessions_dir: root.join("sessions"),
archived_dir: root.join("archived_sessions"),
@@ -433,10 +438,6 @@ impl AgentAdapter for CodexAdapter {
AgentId::Codex
}
- fn detect(&self) -> bool {
- self.sessions_dir.is_dir() || self.archived_dir.is_dir()
- }
-
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
let mut refs = list_jsonl_refs(&self.sessions_dir, AgentId::Codex, rollout_native_id);
refs.extend(list_jsonl_refs(&self.archived_dir, AgentId::Codex, rollout_native_id));
@@ -546,14 +547,7 @@ impl AgentAdapter for CodexAdapter {
})
}
- fn watch_paths(&self) -> Vec<PathBuf> {
- let mut v = Vec::new();
- if self.sessions_dir.is_dir() {
- v.push(self.sessions_dir.clone());
- }
- if self.archived_dir.is_dir() {
- v.push(self.archived_dir.clone());
- }
- v
+ fn data_roots(&self) -> Vec<PathBuf> {
+ vec![self.sessions_dir.clone(), self.archived_dir.clone()]
}
}
diff --git a/crates/wake-core/src/adapters/copilot.rs b/crates/wake-core/src/adapters/copilot.rs
index e24e6b1..eb207f1 100644
--- a/crates/wake-core/src/adapters/copilot.rs
+++ b/crates/wake-core/src/adapters/copilot.rs
@@ -178,10 +178,6 @@ impl AgentAdapter for CopilotAdapter {
AgentId::Copilot
}
- fn detect(&self) -> bool {
- self.db.is_file()
- }
-
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
let Some(rows) = self.rows() else {
return Ok(Vec::new());
@@ -231,8 +227,7 @@ impl AgentAdapter for CopilotAdapter {
})
}
- fn watch_paths(&self) -> Vec<PathBuf> {
- // SQLite 库变更 watcher 不追踪(只认 .jsonl),依赖手动/启动时刷新
- Vec::new()
+ fn data_roots(&self) -> Vec<PathBuf> {
+ vec![self.db.clone()]
}
}
diff --git a/crates/wake-core/src/adapters/cursor.rs b/crates/wake-core/src/adapters/cursor.rs
index 242ef80..dda9ec6 100644
--- a/crates/wake-core/src/adapters/cursor.rs
+++ b/crates/wake-core/src/adapters/cursor.rs
@@ -269,10 +269,6 @@ impl AgentAdapter for CursorAdapter {
AgentId::Cursor
}
- fn detect(&self) -> bool {
- self.root.is_dir()
- }
-
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
let mut refs = Vec::new();
let Ok(projects) = fs::read_dir(&self.root) else {
@@ -372,11 +368,7 @@ impl AgentAdapter for CursorAdapter {
Ok(parse_cursor_jsonl(&file)?.messages)
}
- fn watch_paths(&self) -> Vec<PathBuf> {
- if self.detect() {
- vec![self.root.clone()]
- } else {
- Vec::new()
- }
+ fn data_roots(&self) -> Vec<PathBuf> {
+ vec![self.root.clone()]
}
}
diff --git a/crates/wake-core/src/adapters/dsh.rs b/crates/wake-core/src/adapters/dsh.rs
index 25a8310..18837bf 100644
--- a/crates/wake-core/src/adapters/dsh.rs
+++ b/crates/wake-core/src/adapters/dsh.rs
@@ -376,10 +376,6 @@ impl AgentAdapter for DshAdapter {
AgentId::Dsh
}
- fn detect(&self) -> bool {
- self.root.is_dir()
- }
-
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
let mut refs = Vec::new();
// 固定两层:<project-dir>/<session-dir>/session.jsonl[.zstd],
@@ -468,11 +464,7 @@ impl AgentAdapter for DshAdapter {
}
}
- fn watch_paths(&self) -> Vec<PathBuf> {
- if self.detect() {
- vec![self.root.clone()]
- } else {
- Vec::new()
- }
+ fn data_roots(&self) -> Vec<PathBuf> {
+ vec![self.root.clone()]
}
}
diff --git a/crates/wake-core/src/adapters/gemini.rs b/crates/wake-core/src/adapters/gemini.rs
index 6119fa4..caa4d2d 100644
--- a/crates/wake-core/src/adapters/gemini.rs
+++ b/crates/wake-core/src/adapters/gemini.rs
@@ -207,10 +207,6 @@ impl AgentAdapter for GeminiAdapter {
AgentId::Gemini
}
- fn detect(&self) -> bool {
- self.root.is_dir()
- }
-
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
let mut refs = Vec::new();
let Ok(slugs) = fs::read_dir(&self.root) else {
@@ -272,11 +268,7 @@ impl AgentAdapter for GeminiAdapter {
})
}
- fn watch_paths(&self) -> Vec<PathBuf> {
- if self.detect() {
- vec![self.root.clone()]
- } else {
- Vec::new()
- }
+ fn data_roots(&self) -> Vec<PathBuf> {
+ vec![self.root.clone()]
}
}
diff --git a/crates/wake-core/src/adapters/grok.rs b/crates/wake-core/src/adapters/grok.rs
index a1b998f..2732030 100644
--- a/crates/wake-core/src/adapters/grok.rs
+++ b/crates/wake-core/src/adapters/grok.rs
@@ -287,10 +287,6 @@ impl AgentAdapter for GrokAdapter {
AgentId::Grok
}
- fn detect(&self) -> bool {
- self.root.is_dir()
- }
-
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
let mut refs = Vec::new();
let Ok(cwds) = fs::read_dir(&self.root) else {
@@ -351,11 +347,7 @@ impl AgentAdapter for GrokAdapter {
})
}
- fn watch_paths(&self) -> Vec<PathBuf> {
- if self.detect() {
- vec![self.root.clone()]
- } else {
- Vec::new()
- }
+ fn data_roots(&self) -> Vec<PathBuf> {
+ vec![self.root.clone()]
}
}
diff --git a/crates/wake-core/src/adapters/kimi.rs b/crates/wake-core/src/adapters/kimi.rs
index d815e72..e2ae365 100644
--- a/crates/wake-core/src/adapters/kimi.rs
+++ b/crates/wake-core/src/adapters/kimi.rs
@@ -224,10 +224,6 @@ impl AgentAdapter for KimiAdapter {
AgentId::Kimi
}
- fn detect(&self) -> bool {
- self.root.is_dir()
- }
-
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
let mut refs = Vec::new();
let Ok(wds) = fs::read_dir(&self.root) else {
@@ -288,11 +284,7 @@ impl AgentAdapter for KimiAdapter {
})
}
- fn watch_paths(&self) -> Vec<PathBuf> {
- if self.detect() {
- vec![self.root.clone()]
- } else {
- Vec::new()
- }
+ fn data_roots(&self) -> Vec<PathBuf> {
+ vec![self.root.clone()]
}
}
diff --git a/crates/wake-core/src/adapters/kiro.rs b/crates/wake-core/src/adapters/kiro.rs
index eb272e0..c2c50ae 100644
--- a/crates/wake-core/src/adapters/kiro.rs
+++ b/crates/wake-core/src/adapters/kiro.rs
@@ -161,10 +161,6 @@ impl AgentAdapter for KiroAdapter {
AgentId::Kiro
}
- fn detect(&self) -> bool {
- self.root.is_dir()
- }
-
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
Ok(list_jsonl_refs(&self.root, AgentId::Kiro, str::to_string))
}
@@ -192,11 +188,7 @@ impl AgentAdapter for KiroAdapter {
})
}
- fn watch_paths(&self) -> Vec<PathBuf> {
- if self.detect() {
- vec![self.root.clone()]
- } else {
- Vec::new()
- }
+ fn data_roots(&self) -> Vec<PathBuf> {
+ vec![self.root.clone()]
}
}
diff --git a/crates/wake-core/src/adapters/mod.rs b/crates/wake-core/src/adapters/mod.rs
index 12fdb67..6a0138d 100644
--- a/crates/wake-core/src/adapters/mod.rs
+++ b/crates/wake-core/src/adapters/mod.rs
@@ -22,8 +22,12 @@ use std::path::Path;
/// 保证 FTS 的 seq 与详情页消息序号一致(搜索跳转依赖)。
pub trait AgentAdapter: Send + Sync {
fn agent(&self) -> AgentId;
- /// 数据根目录是否存在
- fn detect(&self) -> bool;
+ /// 本机是否有这家的数据。由 data_roots 派生,**不要覆写**——它必须与
+ /// 面板逐路径的 exists() 同一判据,手写版本(is_dir/is_file)与之打架
+ /// 正是 2026-08-24 数轮 review 反复修的源头之一
+ fn detect(&self) -> bool {
+ self.data_roots().iter().any(|p| p.exists())
+ }
/// 枚举全部会话文件。契约是"枚举必须廉价、绝不做全量解析":多数家纯 stat,
/// SQLite 型跑元数据查询,dsh 读有界首行(子代理标志只存在于文件头)。
/// 故障就地降级为空列表,不外溢炸掉整轮扫描。
@@ -65,12 +69,44 @@ pub trait AgentAdapter: Send + Sync {
fn session_paths(&self, meta: &SessionMeta) -> Vec<String> {
vec![meta.file_path.clone()]
}
- /// 文件监听根目录
- fn watch_paths(&self) -> Vec<std::path::PathBuf>;
+ /// 本家会话文件所在的根位置(目录,或 SQLite 型的库文件),**不论当前存不存在**。
+ /// 这是路径的**唯一事实源**:watch_paths 由它派生,"Scanned locations" 面板
+ /// 直接展示它,按路径前缀统计会话数也依赖它——故语义定死为"其子树(或其本身)
+ /// 拥有本家 session 文件的位置",凭据/配置/索引这类不产生会话的文件不列。
+ /// 新增 adapter 必须实现:没有默认值,漏了编译就过不去
+ fn data_roots(&self) -> Vec<std::path::PathBuf>;
+ /// 文件监听根目录。默认 = data_roots 中现存的目录,十三家实测全部吻合:
+ /// 目录型给出自己的 root,SQLite 型的根是库文件、天然筛空(watcher 只认
+ /// .jsonl,库变更靠启动/手动刷新),codex 的 sessions + archived 一并覆盖。
+ /// 只有当监听范围确实不同于数据根时才覆写——否则一次根路径搬迁
+ /// (如 CODEX_HOME / XDG_DATA_HOME)就要在两处各改一遍,漏一处则静默失去实时更新
+ fn watch_paths(&self) -> Vec<std::path::PathBuf> {
+ self.data_roots().into_iter().filter(|p| p.is_dir()).collect()
+ }
+}
+
+/// 环境变量指定的数据根。**只能读进程环境**:从 Dock 启动的 GUI 不继承用户
+/// shell 的 env,kooky 处理 CODEX_HOME 时同样只能做到这一步("the best
+/// available")。所以调用方拿它当**候选**而非唯一真相,默认路径仍要探。
+/// 空值视作未设。
+/// **调用方必须把返回值当候选**:探到真实数据(目录型看会话子目录、SQLite 型
+/// 看库文件)才采信,否则回落默认位置——变量指向一个存在但空的目录时,不该让
+/// 整家会话凭空消失
+pub(crate) fn env_dir(key: &str) -> Option<std::path::PathBuf> {
+ std::env::var_os(key)
+ .filter(|v| !v.is_empty())
+ .map(std::path::PathBuf::from)
}
+/// 全量十三家 roster,**不按 detect 过滤**。这是全应用唯一的构造点:
+/// scanner/watcher/resume/Session locations 面板共享 Workbench 启动时的
+/// 同一份实例。缺根的家由各自 list_session_files 降级为 Ok(空)(scanner
+/// 对 Err 会 `?` 截断整轮,新 adapter 必须维持这条降级约定,contract 测试
+/// 有卡)。**不要为任何用途二次构造 roster**:根路径是构造时刻对 env
+/// (CODEX_HOME/XDG_DATA_HOME)与文件系统的快照,两份实例可能解析出不同的
+/// 根,UI 就会展示一个扫描器并不在读的路径
pub fn create_adapters() -> Vec<Box<dyn AgentAdapter>> {
- let all: Vec<Box<dyn AgentAdapter>> = vec![
+ vec![
Box::new(claude::ClaudeAdapter::new()),
Box::new(codex::CodexAdapter::new()),
Box::new(copilot::CopilotAdapter::new()),
@@ -84,8 +120,7 @@ pub fn create_adapters() -> Vec<Box<dyn AgentAdapter>> {
Box::new(kimi::KimiAdapter::new()),
Box::new(antigravity::AntigravityAdapter::new()),
Box::new(dsh::DshAdapter::new()),
- ];
- all.into_iter().filter(|a| a.detect()).collect()
+ ]
}
/// 从解析后的消息派生 FTS 单元(text + tool 名称/输入摘要)
diff --git a/crates/wake-core/src/adapters/opencode.rs b/crates/wake-core/src/adapters/opencode.rs
index aa0bee9..e5cd948 100644
--- a/crates/wake-core/src/adapters/opencode.rs
+++ b/crates/wake-core/src/adapters/opencode.rs
@@ -66,15 +66,27 @@ fn has_v2(conn: &rusqlite::Connection) -> bool {
.is_ok()
}
+/// opencode 走 XDG 规范——二进制里就是 `process.env.XDG_DATA_HOME ||
+/// ~/.local/share`。设过这个变量的机器,库根本不在默认位置(GitHub #2 的现场
+/// 疑似如此)。Dock 启动的 Wake 读不到用户 shell 的 env,故两处都探、以实际
+/// 存在的那个为准
+fn db_path() -> PathBuf {
+ let default = dirs::home_dir()
+ .unwrap_or_default()
+ .join(".local")
+ .join("share")
+ .join("opencode")
+ .join("opencode.db");
+ super::env_dir("XDG_DATA_HOME")
+ .map(|x| x.join("opencode").join("opencode.db"))
+ .filter(|p| p.is_file())
+ .unwrap_or(default)
+}
+
impl OpencodeAdapter {
pub fn new() -> Self {
Self {
- db: dirs::home_dir()
- .unwrap_or_default()
- .join(".local")
- .join("share")
- .join("opencode")
- .join("opencode.db"),
+ db: db_path(),
rows_cache: MtimeCache::new(),
}
}
@@ -400,10 +412,6 @@ impl AgentAdapter for OpencodeAdapter {
AgentId::Opencode
}
- fn detect(&self) -> bool {
- self.db.is_file()
- }
-
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
let Some(rows) = self.rows() else {
return Ok(Vec::new());
@@ -453,7 +461,7 @@ impl AgentAdapter for OpencodeAdapter {
})
}
- fn watch_paths(&self) -> Vec<PathBuf> {
- Vec::new()
+ fn data_roots(&self) -> Vec<PathBuf> {
+ vec![self.db.clone()]
}
}
diff --git a/crates/wake-core/src/adapters/pi.rs b/crates/wake-core/src/adapters/pi.rs
index cc0b59f..ecc230f 100644
--- a/crates/wake-core/src/adapters/pi.rs
+++ b/crates/wake-core/src/adapters/pi.rs
@@ -230,10 +230,6 @@ impl AgentAdapter for PiAdapter {
self.agent
}
- fn detect(&self) -> bool {
- self.root.is_dir()
- }
-
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
Ok(list_jsonl_refs(&self.root, self.agent, native_id_of))
}
@@ -265,11 +261,7 @@ impl AgentAdapter for PiAdapter {
})
}
- fn watch_paths(&self) -> Vec<PathBuf> {
- if self.detect() {
- vec![self.root.clone()]
- } else {
- Vec::new()
- }
+ fn data_roots(&self) -> Vec<PathBuf> {
+ vec![self.root.clone()]
}
}
diff --git a/crates/wake-core/src/db.rs b/crates/wake-core/src/db.rs
index 81369e8..c05ee15 100644
--- a/crates/wake-core/src/db.rs
+++ b/crates/wake-core/src/db.rs
@@ -385,6 +385,30 @@ impl Store {
Ok(map)
}
+ /// 各数据源目录下的会话数(Session locations 面板用):一次扫表按
+ /// **(agent, 数据根)** 归属,免去每个目录一次往返。**不过滤 archived**
+ /// ——归档目录本就该显示自己的量,那正是 agent_counts(WHERE archived = 0)
+ /// 看不见的那部分。
+ /// 必须连 agent 一起比,且边界走 path_under:CODEX_HOME / XDG_DATA_HOME
+ /// 允许把一家的数据根搬进另一家的树下,只认裸路径前缀会把整批会话静默
+ /// 记到别家行上
+ pub fn counts_by_path_prefix(&self, sources: &[(String, String)]) -> Result<Vec<i64>> {
+ let conn = self.read.lock().unwrap();
+ let mut stmt = conn.prepare_cached("SELECT agent_id, file_path FROM sessions")?;
+ let rows = stmt.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?)))?;
+ let mut counts = vec![0i64; sources.len()];
+ for row in rows {
+ let (agent, path) = row?;
+ if let Some(i) = sources
+ .iter()
+ .position(|(a, root)| *a == agent && path_under(&path, root))
+ {
+ counts[i] += 1;
+ }
+ }
+ Ok(counts)
+ }
+
/// 全文搜索:trigram MATCH(每段 ≥3 码点)或 LIKE 降级。返回 (hits, degraded)
pub fn search(
&self,
@@ -634,3 +658,14 @@ pub fn default_db_path() -> std::path::PathBuf {
}
db
}
+
+/// 会话文件是否落在这个数据根下。边界必须落在分隔符上,否则 `…/sessions`
+/// 会把兄弟目录 `…/sessions-old` 一并吞掉;SQLite 型的数据根就是库文件本身,
+/// 其会话是 `<db>#<id>` 虚拟路径,故 '#' 同样算边界
+fn path_under(path: &str, root: &str) -> bool {
+ match path.strip_prefix(root) {
+ Some("") => true,
+ Some(rest) => rest.starts_with('/') || rest.starts_with('#'),
+ None => false,
+ }
+}
diff --git a/crates/wake-core/src/services/terminal.rs b/crates/wake-core/src/services/terminal.rs
index 7322af9..f66962d 100644
--- a/crates/wake-core/src/services/terminal.rs
+++ b/crates/wake-core/src/services/terminal.rs
@@ -594,6 +594,30 @@ 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);
+ }
+}
+
pub fn reveal_in_finder(path: &str) {
// SQLite 型会话是 <db>#<id> 虚拟路径,磁盘上不存在——reveal 库文件本体
let p = if Path::new(path).exists() {
@@ -601,5 +625,7 @@ pub fn reveal_in_finder(path: &str) {
} else {
path.rsplit_once('#').map(|(db, _)| db).unwrap_or(path)
};
- let _ = Command::new("open").args(["-R", p]).status();
+ let mut cmd = Command::new("open");
+ cmd.args(["-R", p]);
+ spawn_and_reap(cmd);
}
diff --git a/crates/wake-core/src/watcher.rs b/crates/wake-core/src/watcher.rs
index 61c7eec..61aa5ae 100644
--- a/crates/wake-core/src/watcher.rs
+++ b/crates/wake-core/src/watcher.rs
@@ -16,6 +16,20 @@ pub struct SessionWatcher {
_thread: std::thread::JoinHandle<()>,
}
+/// 事件路径 → 归属 agent:取**最长匹配根**,不是第一个命中。env 自定义根
+/// (CODEX_HOME/XDG_DATA_HOME)可以落在别家数据树内,此时事件路径同时匹配
+/// 两个根,按 roster 顺序取首个会把事件分给外层那家——file_ref 又对 .jsonl
+/// 很宽松,会以错误的 agent 入库(错 key + 同 file_path 还会触发 UNIQUE 冲突)。
+/// 更深的根必然是更具体的归属;Path::starts_with 按组件比较,同名前缀兄弟
+/// 目录不会误匹配
+pub fn resolve_watch_agent(roots: &[(PathBuf, AgentId)], path: &Path) -> Option<AgentId> {
+ roots
+ .iter()
+ .filter(|(root, _)| path.starts_with(root))
+ .max_by_key(|(root, _)| root.components().count())
+ .map(|(_, agent)| *agent)
+}
+
pub fn start_watcher(
adapters: Arc<Vec<Box<dyn AgentAdapter>>>,
store: Arc<Store>,
@@ -38,12 +52,7 @@ pub fn start_watcher(
}
let thread = std::thread::spawn(move || {
- let resolve_agent = |path: &Path| -> Option<AgentId> {
- roots
- .iter()
- .find(|(root, _)| path.starts_with(root))
- .map(|(_, agent)| *agent)
- };
+ let resolve_agent = |path: &Path| resolve_watch_agent(&roots, path);
let mut pending: HashMap<PathBuf, AgentId> = HashMap::new();
let mut removed: Vec<PathBuf> = Vec::new();
diff --git a/crates/wake-core/tests/adapter_contracts.rs b/crates/wake-core/tests/adapter_contracts.rs
index a931087..f178ffe 100644
--- a/crates/wake-core/tests/adapter_contracts.rs
+++ b/crates/wake-core/tests/adapter_contracts.rs
@@ -111,6 +111,11 @@ fn setup() -> &'static TestEnv {
.expect("write dsh subagent log");
std::env::set_var("HOME", home.path());
+ // 测试只受这个假 HOME 支配:opencode 认 XDG_DATA_HOME、codex 认
+ // CODEX_HOME,开发者或 CI 机器上设了它们,adapter 就会绕过 fixture
+ // 去读真实库(实测 opencode 的两个契约测试会因此挂掉)
+ std::env::remove_var("XDG_DATA_HOME");
+ std::env::remove_var("CODEX_HOME");
TestEnv {
copilot_db,
opencode_db,
@@ -842,6 +847,85 @@ fn assert_seq_contract(adapter: &dyn AgentAdapter, r: &SessionFileRef) {
assert_eq!(s.meta.message_count, t.meta.message_count, "[{tag}] message_count 两侧不一致");
}
+#[test]
+fn watch_paths_derive_from_data_roots() {
+ // watch_paths 没有各家实现,统一由 data_roots 的"现存目录"子集派生——
+ // 直接断言派生关系本体,外加 SQLite 型必须无监听目录这条语义守卫
+ // (watcher 只认 .jsonl,库变更靠启动/手动刷新;有人把库文件的父目录
+ // 塞进 data_roots 就会破)
+ let _env = setup();
+ for a in wake_core::adapters::create_adapters() {
+ let tag = a.agent().as_str();
+ let watched = a.watch_paths();
+ let expect: Vec<std::path::PathBuf> =
+ a.data_roots().into_iter().filter(|p| p.is_dir()).collect();
+ assert_eq!(watched, expect, "[{tag}] watch_paths 必须等于 data_roots 的现存目录子集");
+ if matches!(a.agent(), AgentId::Copilot | AgentId::Opencode | AgentId::Antigravity) {
+ assert!(watched.is_empty(), "[{tag}] SQLite 型不该有监听目录");
+ }
+ }
+}
+
+#[test]
+fn overlapping_watch_roots_dispatch_to_deepest() {
+ // env 自定义根可以落在别家数据树内(CODEX_HOME=~/.claude/projects/codex
+ // 这类):事件分派必须取最长匹配根,首个命中会把 codex 的 rollout 交给
+ // claude 的 file_ref(对 .jsonl 宽松)以错误 agent 入库。
+ // 兄弟目录同名前缀(projects vs projects-old)靠 Path 组件语义天然免疫
+ use std::path::{Path, PathBuf};
+ let roots = vec![
+ (PathBuf::from("/h/.claude/projects"), AgentId::ClaudeCode),
+ (PathBuf::from("/h/.claude/projects/codex/sessions"), AgentId::Codex),
+ ];
+ let deep = Path::new("/h/.claude/projects/codex/sessions/2026/08/rollout-x.jsonl");
+ assert_eq!(
+ wake_core::watcher::resolve_watch_agent(&roots, deep),
+ Some(AgentId::Codex),
+ "嵌套根必须归最深那家"
+ );
+ let shallow = Path::new("/h/.claude/projects/p1/sess.jsonl");
+ assert_eq!(
+ wake_core::watcher::resolve_watch_agent(&roots, shallow),
+ Some(AgentId::ClaudeCode)
+ );
+ let sibling = Path::new("/h/.claude/projects-old/p1/sess.jsonl");
+ assert_eq!(
+ wake_core::watcher::resolve_watch_agent(&roots, sibling),
+ None,
+ "同名前缀兄弟目录不该匹配"
+ );
+}
+
+#[test]
+fn data_roots_contract() {
+ // roster 单实例契约:create_adapters 返回全量十三家(不按 detect 过滤,
+ // scanner 对缺根家靠各自 list_session_files 降级为空);每家必须给出
+ // 绝对路径的数据根——"Session locations" 面板、watch_paths 派生、按
+ // (agent, 根) 计数全都建立在它上面
+ let _env = setup();
+ let adapters = wake_core::adapters::create_adapters();
+ assert_eq!(adapters.len(), 13, "全量 roster 必须十三家,含本机没装的");
+ for a in &adapters {
+ let tag = a.agent().as_str();
+ let roots = a.data_roots();
+ assert!(!roots.is_empty(), "[{tag}] data_roots 不能为空");
+ for r in &roots {
+ assert!(r.is_absolute(), "[{tag}] 路径须为绝对路径: {r:?}");
+ }
+ }
+ // 假 HOME 里造过数据的四家必须被 detect(默认实现 = data_roots 任一存在)
+ // 认出;其中三家是 SQLite 型,它们 watch_paths 恒空,这正是 data_roots
+ // 独立存在的理由
+ let detected: Vec<&str> = adapters
+ .iter()
+ .filter(|a| a.detect())
+ .map(|a| a.agent().as_str())
+ .collect();
+ for expect in ["copilot", "opencode", "antigravity", "dsh"] {
+ assert!(detected.contains(&expect), "{expect} 应被检出,实际 {detected:?}");
+ }
+}
+
#[test]
fn dsh_torn_final_frame_terminates() {
// 半写的末帧:写端每次 append 一帧,扫描与 dsh 天然并发,必然读到。
diff --git a/crates/wake-core/tests/db_roundtrip.rs b/crates/wake-core/tests/db_roundtrip.rs
index d4972b0..3aea6b5 100644
--- a/crates/wake-core/tests/db_roundtrip.rs
+++ b/crates/wake-core/tests/db_roundtrip.rs
@@ -133,3 +133,34 @@ fn list_sessions_filters_and_counts() {
assert_eq!(total, 1);
assert_eq!(sessions[0].key, "codex:s5");
}
+
+#[test]
+fn path_counts_respect_agent_and_boundary() {
+ // Session locations 面板的计数按数据根归属。两条真实风险:
+ // ① 自定义 CODEX_HOME/XDG_DATA_HOME 可以落在别家根之下,只比路径前缀
+ // 不看 agent,会把这家的会话整批记到别家行上;
+ // ② 裸 starts_with 没有边界,`…/sessions` 会连 `…/sessions-old` 一起吞。
+ let (_d, store) = temp_store();
+ let mut claude = meta("claude-code:a", "claude one");
+ claude.file_path = "/home/u/.claude/projects/a.jsonl".into();
+ // codex 的根被搬进了 claude 的树下(CODEX_HOME 允许这么设)
+ let mut codex = meta("codex:b", "codex one");
+ codex.agent = AgentId::Codex;
+ codex.file_path = "/home/u/.claude/projects/codex/sessions/b.jsonl".into();
+ // 同名前缀的兄弟目录:不该算进 `…/sessions`
+ let mut sibling = meta("codex:c", "codex sibling");
+ sibling.agent = AgentId::Codex;
+ sibling.file_path = "/home/u/.claude/projects/codex/sessions-old/c.jsonl".into();
+ store
+ .write_meta_only(&[(claude, 0), (codex, 0), (sibling, 0)])
+ .expect("seed sessions");
+
+ let counts = store
+ .counts_by_path_prefix(&[
+ ("claude-code".into(), "/home/u/.claude/projects".into()),
+ ("codex".into(), "/home/u/.claude/projects/codex/sessions".into()),
+ ])
+ .expect("counts");
+ assert_eq!(counts[0], 1, "codex 的会话不该被记到 claude 行");
+ assert_eq!(counts[1], 1, "sessions-old 不该算进 sessions");
+}
diff --git a/crates/wake-core/tests/scanner_finale.rs b/crates/wake-core/tests/scanner_finale.rs
index 9347a00..1b6f29d 100644
--- a/crates/wake-core/tests/scanner_finale.rs
+++ b/crates/wake-core/tests/scanner_finale.rs
@@ -28,9 +28,6 @@ impl AgentAdapter for FailingAdapter {
fn agent(&self) -> AgentId {
AgentId::ClaudeCode
}
- fn detect(&self) -> bool {
- true
- }
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
bail!("simulated data source failure")
}
@@ -40,8 +37,8 @@ impl AgentAdapter for FailingAdapter {
fn parse_transcript(&self, _: &SessionFileRef) -> Result<ParsedTranscript> {
bail!("unreachable")
}
- fn watch_paths(&self) -> Vec<std::path::PathBuf> {
- Vec::new()
+ fn data_roots(&self) -> Vec<std::path::PathBuf> {
+ vec![std::path::PathBuf::from("/nonexistent/test-adapter")]
}
}
@@ -91,9 +88,6 @@ impl AgentAdapter for SeedAdapter {
fn agent(&self) -> AgentId {
AgentId::Codex
}
- fn detect(&self) -> bool {
- true
- }
fn list_session_files(&self) -> Result<Vec<SessionFileRef>> {
Ok(vec![self.r.clone()])
}
@@ -115,8 +109,8 @@ impl AgentAdapter for SeedAdapter {
fn parse_transcript(&self, _: &SessionFileRef) -> Result<ParsedTranscript> {
bail!("transcript not needed in scan")
}
- fn watch_paths(&self) -> Vec<std::path::PathBuf> {
- Vec::new()
+ fn data_roots(&self) -> Vec<std::path::PathBuf> {
+ vec![std::path::PathBuf::from("/nonexistent/test-adapter")]
}
}
diff --git a/crates/wake/assets/icons/hard-drive.svg b/crates/wake/assets/icons/hard-drive.svg
new file mode 100644
index 0000000..977dfb1
--- /dev/null
+++ b/crates/wake/assets/icons/hard-drive.svg
@@ -0,0 +1,18 @@
+<!-- @license lucide-static v0.462.0 - ISC -->
+<svg
+ class="lucide lucide-hard-drive"
+ 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"
+>
+ <line x1="22" x2="2" y1="12" y2="12" />
+ <path d="M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z" />
+ <line x1="6" x2="6.01" y1="16" y2="16" />
+ <line x1="10" x2="10.01" y1="16" y2="16" />
+</svg>
diff --git a/crates/wake/src/assets.rs b/crates/wake/src/assets.rs
index 35e27da..1a11e4b 100644
--- a/crates/wake/src/assets.rs
+++ b/crates/wake/src/assets.rs
@@ -82,6 +82,7 @@ icons!(
"circle-x",
"file-text",
"more-horizontal",
+ "hard-drive",
);
impl AssetSource for Assets {
diff --git a/crates/wake/src/format.rs b/crates/wake/src/format.rs
index c185143..834bac7 100644
--- a/crates/wake/src/format.rs
+++ b/crates/wake/src/format.rs
@@ -46,6 +46,29 @@ pub fn fmt_tokens(n: Option<i64>) -> String {
}
}
+/// 绝对路径 → `~/…` 形式,**不折叠中段**。数据源面板要如实给出完整路径
+/// (display_file_path 那种 `~/a/…/file` 的折叠在那里会把信息吃掉)
+pub fn tilde_path(p: &str) -> String {
+ // HOME 进程内不变,缓存住:display_file_path 经由本函数落在详情页
+ // header 上,那是每帧都跑的路径
+ static HOME: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
+ let home = HOME.get_or_init(|| {
+ dirs::home_dir()
+ .map(|h| h.to_string_lossy().to_string())
+ .filter(|h| !h.is_empty())
+ });
+ // 边界必须落在分隔符上:裸 starts_with 会把 HOME 的同名前缀兄弟目录
+ // 也折叠掉(HOME=/Users/al 时 /Users/al-data → "~-data",一个并不存在
+ // 的 HOME 相对路径)。自定义 CODEX_HOME / XDG_DATA_HOME 让这种根变得可能
+ match home {
+ Some(h) => match p.strip_prefix(h.as_str()) {
+ Some(rest) if rest.is_empty() || rest.starts_with('/') => format!("~{rest}"),
+ _ => p.to_string(),
+ },
+ None => p.to_string(),
+ }
+}
+
/// 会话文件路径的展示形态(详情页路径行):SQLite 虚拟路径剥 `#<id>`、
/// HOME 缩成 `~`、深路径折叠中段(根目录 + … + 文件名)。
/// 仅用于展示——Reveal in Finder 仍传原始完整路径。
@@ -56,11 +79,7 @@ pub fn display_file_path(path: &str) -> String {
.filter(|(db, _)| db.ends_with(".db"))
.map(|(db, _)| db)
.unwrap_or(path);
- let tilde = dirs::home_dir()
- .map(|h| h.to_string_lossy().to_string())
- .filter(|h| !h.is_empty() && p.starts_with(h.as_str()))
- .map(|h| format!("~{}", &p[h.len()..]))
- .unwrap_or_else(|| p.to_string());
+ let tilde = tilde_path(p);
let parts: Vec<&str> = tilde.split('/').collect();
match (parts.first(), parts.get(1), parts.last()) {
// 超过 根/次级/…/文件 四段的深路径折叠中段
diff --git a/crates/wake/src/ui.rs b/crates/wake/src/ui.rs
index 2c22356..13b8580 100644
--- a/crates/wake/src/ui.rs
+++ b/crates/wake/src/ui.rs
@@ -71,6 +71,16 @@ pub const ROW_HEIGHT: Pixels = px(32.);
/// 配 FONT_CAPTION 形成侧栏纵向层级(macOS 原生侧栏惯例)
pub const ROW_HEIGHT_SUB: Pixels = px(26.);
+// ---------------- 圆角 ----------------
+// 四档见 DESIGN.md:面板 12 = `theme.radius_lg`,列表与侧栏选择 8 = `theme.radius`
+// (这两档走主题 token),其余三档无 token,在此定名以免散成魔法数字。
+/// 按钮圆角。**用户钉死 6px,勿改**
+pub const RADIUS_BUTTON: Pixels = px(6.);
+/// 快捷键标签
+pub const RADIUS_KBD: Pixels = px(5.);
+/// 小胶囊 badge(项目名 / model / source / 各处计数共用)
+pub const RADIUS_BADGE: Pixels = px(4.);
+
// ---------------- 交互态文字 ----------------
/// gpui 陷阱兜底:`.hover()`/`.active()` 闭包的 text 样式对 base 是**整体替换**
diff --git a/crates/wake/src/workbench.rs b/crates/wake/src/workbench.rs
index 42fc206..29b4a25 100644
--- a/crates/wake/src/workbench.rs
+++ b/crates/wake/src/workbench.rs
@@ -45,7 +45,7 @@ use wake_core::services::{exporter, terminal};
use wake_core::watcher::{start_watcher, SessionWatcher};
use crate::ui::*;
-use crate::format::{abs_date, display_file_path, fmt_tokens, one_line, relative_time};
+use crate::format::{abs_date, display_file_path, fmt_tokens, one_line, relative_time, tilde_path};
actions!(wake, [ToggleSearch, RefreshSessions, PaletteUp, PaletteDown]);
@@ -410,6 +410,20 @@ pub struct Workbench {
_subs: Vec<Subscription>,
}
+/// "Session locations" 面板的一行(= 一个数据源路径)。文本字段一律
+/// SharedString:dialog builder 每帧重跑,clone 只该是 refcount 而非堆分配
+struct DataSourceRow {
+ agent: AgentId,
+ /// `~/…` 展示形态
+ display: SharedString,
+ /// 原始完整路径,交给 Finder
+ raw: SharedString,
+ /// 会话数,或路径不可用时的状态词
+ tally: SharedString,
+ /// 路径当前存在(行是否可点)
+ exists: bool,
+}
+
impl Workbench {
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
let db_path = wake_core::db::default_db_path();
@@ -645,6 +659,149 @@ impl Workbench {
});
}
+ /// "Wake 读哪些路径"面板(侧栏底部数据源钮)。列全十三家含本机没装的,
+ /// 呼应"只读你的目录、零网络"的产品承诺。数据在打开前一次算好 move 进
+ /// 闭包——dialog builder 在宿主 render 期间执行,闭包内 read 宿主 entity
+ /// 必 double-lease panic
+ fn show_data_sources(&mut self, window: &mut Window, cx: &mut Context<Self>) {
+ // 数据源**必须**读 self.adapters——与 scanner/watcher/refresh 同一份
+ // 实例。根路径是构造时刻对 env(CODEX_HOME/XDG_DATA_HOME)与文件系统
+ // 的快照,二次构造(旧 all_data_sources 的做法)可能解析出不同的根,
+ // 面板就会展示一个本次会话根本不会读的路径——连着几轮 review 修的
+ // 都是这一个根因的不同投影;同一份实例下不一致没有存在空间。
+ // 先摊平成"一路径一行",prefixes 与各行由**同一份** flat 派生:两次
+ // 独立 flat_map 再按位置 zip 计数,靠的是遍历顺序一致这条隐形契约。
+ // 文本一律预先算成 SharedString:dialog builder 存的是 Rc<dyn Fn>,
+ // 面板开着时每帧重跑,留 format!/String::clone 在里面就是每帧堆分配
+ let flat: Vec<(AgentId, PathBuf)> = self
+ .adapters
+ .iter()
+ .flat_map(|a| {
+ let agent = a.agent();
+ a.data_roots().into_iter().map(move |r| (agent, r))
+ })
+ .collect();
+ // 带上 agent:计数按 (agent, 根) 归属,不然一家的根被 env 搬进另一家
+ // 树下时,会话会整批记到别家行上
+ let prefixes: Vec<(String, String)> = flat
+ .iter()
+ .map(|(a, r)| (a.as_str().to_string(), r.to_string_lossy().to_string()))
+ .collect();
+ let counts = self
+ .store
+ .counts_by_path_prefix(&prefixes)
+ .unwrap_or_else(|_| vec![0; prefixes.len()]);
+ let rows: Vec<DataSourceRow> = flat
+ .iter()
+ .zip(prefixes)
+ .zip(counts)
+ .map(|(((agent, root), (_, raw)), n)| {
+ // 存在性逐路径判断:某家的归档目录可能还没建,不该按整家一刀切
+ let exists = root.exists();
+ DataSourceRow {
+ agent: *agent,
+ display: tilde_path(&raw).into(),
+ raw: raw.into(),
+ tally: if exists { n.to_string().into() } else { "Not found".into() },
+ exists,
+ }
+ })
+ .collect();
+ window.open_dialog(cx, move |dialog, _window, cx| {
+ let theme = cx.theme();
+ // 左右内边距从默认 24 收到 14,让出的 10px 由标题与各行自己的
+ // px(10) 补回:内容绝对位置不变,而 hover 底色能向外铺满这 10px。
+ // 早先用容器负 margin 做,被 overflow_y_scroll 的裁剪吃掉了
+ dialog.w(px(620.)).pl(px(14.)).pr(px(14.)).child(
+ v_flex()
+ .gap(SPACE_SM)
+ .child(
+ // 显式收行高:默认按 1.5 倍算,16px 标题会撑出 24px 的块,
+ // 上下白边把标题与列表推得过开
+ div()
+ .px(px(10.))
+ .text_size(FONT_HEADING)
+ .line_height(px(20.))
+ .font_semibold()
+ .text_color(theme.foreground)
+ .child("Session locations"),
+ )
+ .child(
+ v_flex()
+ .id("data-source-list")
+ .max_h(px(400.))
+ .overflow_y_scroll()
+ .children(rows.iter().enumerate().map(|(ix, row)| {
+ let raw = row.raw.clone();
+ h_flex()
+ .id(("data-source-row", ix))
+ .h(ROW_HEIGHT_SUB)
+ .w_full()
+ // 行内 padding + dialog 让出的等量边距:hover
+ // 底色左右各留 10px 呼吸,内容仍与标题左对齐
+ .px(px(10.))
+ .rounded(theme.radius)
+ .gap(SPACE_SM)
+ .items_center()
+ .when(row.exists, |el| {
+ el.cursor_pointer()
+ .hover(|s| s.bg(theme.secondary_hover))
+ .on_click(move |_, _, _| {
+ terminal::open_in_finder(&raw)
+ })
+ })
+ .child(
+ img(row.agent.brand_icon(theme.mode.is_dark()))
+ .size(px(14.))
+ .flex_shrink_0(),
+ )
+ .child(
+ div()
+ .w(px(118.))
+ .flex_shrink_0()
+ .truncate()
+ .text_size(FONT_CAPTION)
+ .text_color(theme.foreground)
+ .child(row.agent.display_name()),
+ )
+ .child(
+ div()
+ .flex_1()
+ .min_w_0()
+ .truncate()
+ .text_size(FONT_CAPTION)
+ .text_color(theme.muted_foreground)
+ .child(row.display.clone()),
+ )
+ .child(
+ h_flex()
+ .w(px(88.))
+ .flex_shrink_0()
+ .justify_end()
+ .text_size(FONT_LABEL)
+ .child({
+ // 有目录取中性灰(同项目名 badge);目录不在
+ // 取 warning 淡底 tint——这是"本机没这家"的
+ // 陈述而非报错,不用实心告警色。文字实色,
+ // 只有底叠 opacity
+ // 有目录取中性灰(同项目名 badge);目录不在
+ // 取 warning 淡底 tint——这是"本机没这家"的
+ // 陈述而非报错,不用实心告警色。文字实色,
+ // 只有底叠 opacity
+ let (bg, fg) = if row.exists {
+ (theme.muted, theme.muted_foreground)
+ } else {
+ (theme.warning.opacity(0.14), theme.warning)
+ };
+ badge(row.tally.clone(), bg, fg)
+ }),
+ )
+ })),
+ ),
+ )
+ });
+ }
+
fn on_bg_event(&mut self, ev: BgEvent, window: &mut Window, cx: &mut Context<Self>) {
match ev {
BgEvent::Progress(p) => {
@@ -1369,40 +1526,6 @@ impl Workbench {
.child("⌘K"),
),
)
- .child({
- let busy = self.scan.scanning;
- div()
- .id("refresh")
- .size(ROW_HEIGHT)
- .flex_shrink_0()
- .rounded(theme.radius)
- .bg(theme.secondary)
- .flex()
- .items_center()
- .justify_center()
- .text_color(theme.muted_foreground)
- .when(!busy, |el| {
- el.cursor_pointer()
- .hover(|s| {
- s.bg(theme.secondary_hover)
- .text_color(theme.foreground)
- })
- .active(|s| {
- s.bg(theme.secondary_active)
- .text_color(theme.foreground)
- })
- .on_click(cx.listener(|this, _, window, cx| {
- this.refresh_sessions(window, cx)
- }))
- })
- .child(if busy {
- Spinner::new().small().into_any_element()
- } else {
- icon("icons/refresh-cw.svg")
- .with_size(px(14.))
- .into_any_element()
- })
- }),
),
)
.child(
@@ -1522,18 +1645,57 @@ impl Workbench {
}))
}),
)
- .when_some(status, |this, status| {
- this.child(
- h_flex()
- .flex_shrink_0()
- .px(SPACE_XL)
- .py_3()
- .border_t_1()
- .border_color(theme.sidebar_border)
- .text_size(FONT_LABEL)
- .child(status),
- )
- })
+ // 底部工具条:次要操作(数据源、刷新)与扫描状态同处一区,与上方
+ // 导航行只用一条 border 分隔。按钮透明底、hover 才出色,不跟导航
+ // 行的选中态抢注意力;图标-only 元素改 text_color 不丢字号
+ .child(
+ v_flex()
+ .flex_shrink_0()
+ .border_t_1()
+ .border_color(theme.sidebar_border)
+ .when_some(status, |this, status| {
+ this.child(
+ h_flex().px(SPACE_XL).pt(SPACE_MD).text_size(FONT_LABEL).child(status),
+ )
+ })
+ .child(
+ h_flex()
+ .px(SIDEBAR_EDGE)
+ .py(SPACE_SM)
+ .items_center()
+ .justify_end()
+ .gap_1()
+ .child(sidebar_tool_btn(
+ "data-sources",
+ "Session locations",
+ // 扫描期间禁用:面板的计数是打开那一刻查库所得、
+ // 之后不再跟进(dialog builder 里是静态 rows),
+ // 首扫途中开出来会是 0 或半截数字且一直不更新
+ !self.scan.scanning,
+ icon("icons/hard-drive.svg").with_size(px(14.)).into_any_element(),
+ cx.listener(|this, _, window, cx| {
+ this.show_data_sources(window, cx)
+ }),
+ cx,
+ ))
+ .child(sidebar_tool_btn(
+ "refresh",
+ "Refresh sessions",
+ !self.scan.scanning,
+ if self.scan.scanning {
+ Spinner::new().small().into_any_element()
+ } else {
+ icon("icons/refresh-cw.svg")
+ .with_size(px(14.))
+ .into_any_element()
+ },
+ cx.listener(|this, _, window, cx| {
+ this.refresh_sessions(window, cx)
+ }),
+ cx,
+ )),
+ ),
+ )
}
fn render_session_list(&self, cx: &Context<Self>) -> impl IntoElement {
@@ -1551,7 +1713,7 @@ impl Workbench {
let sort_menu = Button::new("sort-sessions")
.ghost()
.small()
- .rounded(px(6.))
+ .rounded(RADIUS_BUTTON)
.icon(icon("icons/arrow-up-down.svg").with_size(px(13.)))
.label(sort_label)
.tooltip("Sort sessions")
@@ -1667,7 +1829,7 @@ impl Workbench {
div()
.max_w(px(540.))
.min_w_0()
- .rounded(px(12.))
+ .rounded(theme.radius_lg)
.bg(theme.muted)
.px(px(12.))
.py(px(7.))
@@ -1808,7 +1970,7 @@ impl Workbench {
let delete_entity = export_entity.clone();
let more_menu = Button::new("more-actions")
.ghost()
- .rounded(px(6.))
+ .rounded(RADIUS_BUTTON)
.icon(icon("icons/more-horizontal.svg").with_size(px(16.)))
.dropdown_menu(move |menu, _, _| {
let export_entity = export_entity.clone();
@@ -1934,7 +2096,7 @@ impl Workbench {
// 右段 Button 用 custom variant 与左段 hover 完全一致
h_flex()
.h(px(28.))
- .rounded(px(6.))
+ .rounded(RADIUS_BUTTON)
.border_1()
.border_color(theme.border)
.bg(theme.secondary)
@@ -2395,7 +2557,7 @@ fn tool_cluster(
.min_w_0()
.px(px(8.))
.py(px(5.))
- .rounded(px(5.))
+ .rounded(RADIUS_KBD)
.bg(theme.muted)
.text_size(FONT_LABEL)
.font_family(mono.clone())
@@ -2419,7 +2581,7 @@ fn badge(name: impl Into<SharedString>, bg: Hsla, fg: Hsla) -> impl IntoElement
.min_w_0()
.px(px(6.))
.py(px(1.))
- .rounded(px(4.))
+ .rounded(RADIUS_BADGE)
.bg(bg)
.text_color(fg)
.font_medium()
@@ -2432,7 +2594,7 @@ fn outline_badge(name: impl Into<SharedString>, color: Hsla) -> impl IntoElement
.min_w_0()
.px(px(6.))
.py(px(1.))
- .rounded(px(4.))
+ .rounded(RADIUS_BADGE)
.border_1()
.border_color(color)
.text_color(color)
@@ -2440,6 +2602,39 @@ fn outline_badge(name: impl Into<SharedString>, color: Hsla) -> impl IntoElement
.child(div().truncate().child(name.into()))
}
+/// 侧栏底部工具条的图标按钮。透明底、hover 才出色——底部是次要操作区,
+/// 不与导航行的选中态抢注意力;图标-only 元素改 text_color 不丢字号。
+/// enabled=false(刷新进行中)只留静态内容,连 tooltip 与点击一起摘掉
+fn sidebar_tool_btn(
+ id: &'static str,
+ tooltip: &'static str,
+ enabled: bool,
+ content: AnyElement,
+ on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
+ cx: &Context<Workbench>,
+) -> Stateful<Div> {
+ let theme = cx.theme();
+ div()
+ .id(id)
+ .size(ROW_HEIGHT)
+ .flex_shrink_0()
+ .rounded(theme.radius)
+ .flex()
+ .items_center()
+ .justify_center()
+ .text_color(theme.muted_foreground)
+ .when(enabled, |el| {
+ el.cursor_pointer()
+ .hover(|s| s.bg(theme.secondary_hover).text_color(theme.foreground))
+ .active(|s| s.bg(theme.secondary_active))
+ .tooltip(move |window, cx| {
+ gpui_component::tooltip::Tooltip::new(tooltip).build(window, cx)
+ })
+ .on_click(on_click)
+ })
+ .child(content)
+}
+
/// Things 风源列表行:图标 + 文字 + 计数,6px 圆角选中胶囊
#[allow(clippy::too_many_arguments)]
fn sidebar_row(
@@ -2515,12 +2710,17 @@ fn sidebar_row(
.child(label.into()),
)
.when_some(count, |this, n| {
+ // 与 Session locations 面板同款胶囊。底色随行态切换而不是
+ // 固定 muted:常态行底是 sidebar,用 accent 衬;选中行底本身
+ // 就是 accent,退回 sidebar 材质反衬。固定 muted 会在浅色
+ // 常态(#E8E8E5 vs #EDEDEA)和深色选中(#323230 vs #343432)
+ // 两处糊进背景里
+ let bg = if active { theme.sidebar } else { theme.sidebar_accent };
this.child(
div()
.flex_shrink_0()
.text_size(FONT_LABEL)
- .text_color(theme.muted_foreground)
- .child(n.to_string()),
+ .child(badge(n.to_string(), bg, theme.muted_foreground)),
)
}),
)
@@ -2544,7 +2744,7 @@ fn tool_btn(
};
Button::new(id)
.ghost()
- .rounded(px(6.))
+ .rounded(RADIUS_BUTTON)
.icon(ic)
.tooltip(tooltip)
.on_click(on_click)
diff --git a/scripts/test.sh b/scripts/test.sh
index f583046..bbd72c7 100755
--- a/scripts/test.sh
+++ b/scripts/test.sh
@@ -1,7 +1,7 @@
#!/bin/zsh
# Wake 本地测试入口——改完代码跑一跑(对齐 kooky 的 `swift test` 习惯)。
#
-# scripts/test.sh # 数据层 23 测试 + UI 编译门槛,~秒级
+# scripts/test.sh # 数据层 27 测试 + UI 编译门槛,~秒级
# scripts/test.sh --smoke # 追加真实数据冒烟:全量扫描统计(人眼对量级,
# # 基准见 CLAUDE.md;只读你本机的 agent 数据)
set -euo pipefail