All your AI agent sessions in one place — browse, search, resume. Rust + GPUI.
Rust
fix(grok): don't list sessions closed before the first message
Corey Chiufb1137f07421
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ce68201..d94bcaf 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,7 @@## [Unreleased]+- Fix: Grok Build sessions closed before the first message no longer show up as empty Untitled sessions (#55, thanks @yangmingyuan380)- Fix: Open In offers Codex Desktop when the app is installed as Codex.app (#55, thanks @yangmingyuan380)## [0.8.7] — 2026-10-09diff --git a/crates/wake-core/src/adapters/grok.rs b/crates/wake-core/src/adapters/grok.rsindex 4ec889a..8f75a63 100644--- a/crates/wake-core/src/adapters/grok.rs+++ b/crates/wake-core/src/adapters/grok.rs@@ -250,6 +250,70 @@ fn apply_tool_update(images}+/// `sessionUpdate` 的分类。解析按它分派,`file_ref` 判空壳也问它(`opens_message`),+/// 两边是同一个判据、不会分家+#[derive(Clone, Copy)]+enum UpdateKind {+ /// user / agent 的文本 chunk+ Chunk(Role),+ Thought,+ ToolCall,+ /// 只回填已有的调用,自己不起消息+ ToolCallUpdate,+ /// 已知的非内容更新:任务后台化 / 压缩等+ Known,+ Unknown,+}++impl UpdateKind {+ fn of(update: &Value) -> Self {+ match update.get("sessionUpdate").and_then(Value::as_str) {+ Some("user_message_chunk") => Self::Chunk(Role::User),+ Some("agent_message_chunk") => Self::Chunk(Role::Assistant),+ Some("agent_thought_chunk") => Self::Thought,+ Some("tool_call") => Self::ToolCall,+ Some("tool_call_update") => Self::ToolCallUpdate,+ Some(+ "task_backgrounded"+ | "task_completed"+ | "auto_compact_started"+ | "auto_compact_completed"+ | "compaction_checkpoint"+ | "plan"+ | "current_mode_update",+ ) => Self::Known,+ _ => Self::Unknown,+ }+ }++ fn opens_message(self) -> bool {+ match self {+ Self::Chunk(_) | Self::Thought | Self::ToolCall => true,+ Self::ToolCallUpdate | Self::Known | Self::Unknown => false,+ }+ }+}++/// 一条会起消息的更新都没有的 updates.jsonl:Grok 一开会话就落盘,没发消息就关掉的+/// 会话只剩插件钩子之类的流水,原先被收成一条条 Untitled 空记录(PR #55)。流式读、+/// 命中即停,不设大小上限(理由同 cursor.rs 的 `is_turn_marker_only`:钩子输出多大+/// 没有结构保证)。读不出来按有内容放行,交给解析去报错+fn is_empty_shell(path: &Path) -> bool {+ let Ok(file) = fs::File::open(path) else {+ return false;+ };+ for row in jsonl_values(BufReader::new(file)) {+ let Ok(row) = row else {+ return false;+ };+ let update = row.as_ref().and_then(|row| row.pointer("/params/update"));+ if update.is_some_and(|update| UpdateKind::of(update).opens_message()) {+ return false;+ }+ }+ true+}+fn parse_grok_updates(path: &Path, decode_images: bool) -> Result<(Vec<TranscriptMessage>, u32)> {let _image_budget = transcript_image_decode_budget(decode_images);let file = fs::File::open(path)?;@@ -267,18 +331,15 @@ fn parse_grok_updates(path: &Path, decode_images: bool) -> Result<(Vec<Transcripunknown += 1;continue;};- match update.get("sessionUpdate").and_then(|v| v.as_str()) {- Some("user_message_chunk") => {- append_message_chunk(&mut rp, update, Role::User, ts, decode_images);- }- Some("agent_message_chunk") => {- append_message_chunk(&mut rp, update, Role::Assistant, ts, decode_images);+ match UpdateKind::of(update) {+ UpdateKind::Chunk(role) => {+ append_message_chunk(&mut rp, update, role, ts, decode_images);}- Some("agent_thought_chunk") => {+ UpdateKind::Thought => {rp.ensure(Role::Assistant, ts);rp.cur_thinking.push_str(chunk_text(update));}- Some("tool_call") => {+ UpdateKind::ToolCall => {rp.ensure(Role::Assistant, ts);let id = update.get("toolCallId")@@ -292,7 +353,7 @@ fn parse_grok_updates(path: &Path, decode_images: bool) -> Result<(Vec<Transcriprp.cur_tools.push(tool_call_view(id.to_string(), name, &input, None, false));}- Some("tool_call_update") => {+ UpdateKind::ToolCallUpdate => {let Some(id) = update.get("toolCallId").and_then(|v| v.as_str()) else {continue;};@@ -312,17 +373,8 @@ fn parse_grok_updates(path: &Path, decode_images: bool) -> Result<(Vec<Transcripappend_images_to_message_end(message, images);}}- // 已知的非内容更新:任务后台化/压缩等- Some(- "task_backgrounded"- | "task_completed"- | "auto_compact_started"- | "auto_compact_completed"- | "compaction_checkpoint"- | "plan"- | "current_mode_update",- ) => {}- _ => {+ UpdateKind::Known => {}+ UpdateKind::Unknown => {unknown += 1;}}@@ -415,7 +467,7 @@ impl AgentAdapter for GrokAdapter {return Ok(refs);};// session_search.sqlite 等根级文件对 read_dir 自然失败跳过;- // 会话主文件的判定(存在、非空、native_id)统一走 file_ref+ // 会话主文件的判定(存在、非空、不是空壳、native_id)统一走 file_reffor cwd_dir in cwds.flatten() {let Ok(sessions) = fs::read_dir(cwd_dir.path()) else {continue;@@ -436,6 +488,9 @@ impl AgentAdapter for GrokAdapter {}let session_dir = path.parent()?;let mut r = default_file_ref(self.agent(), path)?;+ if is_empty_shell(path) {+ return None;+ }r.native_id = session_dir.file_name()?.to_string_lossy().to_string();Some(r)}diff --git a/crates/wake-core/tests/adapter_contracts.rs b/crates/wake-core/tests/adapter_contracts.rsindex b7eeac9..65a3449 100644--- a/crates/wake-core/tests/adapter_contracts.rs+++ b/crates/wake-core/tests/adapter_contracts.rs@@ -1900,6 +1900,61 @@ fn grok_parse_contract() {);}+/// 没发过消息就关掉的 Grok 会话只剩插件钩子之类的流水,不列(PR #55)。判据与解析器是+/// 同一个分类:只有思考、只有工具调用的会话照列,列出来的都解析得出消息,空壳一条都没有。+/// 钩子行的真实格式还没见过样本,这里只要它不是会起消息的更新;current_mode_update 是+/// 认得的非内容更新+#[test]+fn grok_skips_sessions_without_content() {+ use serde_json::json;+ setup();+ let home = tempfile::tempdir().unwrap();+ let cwd = home+ .path()+ .join("sessions")+ .join("%2FUsers%2Ftester%2FGithub%2Fwakefx");+ fs::create_dir_all(&cwd).unwrap();+ // 根在构造时按目录形状定下,sessions/ 得先在+ let adapter = GrokAdapter::new().with_custom_root(home.path().to_path_buf());+ let text =+ |kind: &str| json!({"sessionUpdate": kind, "content": {"type": "text", "text": "看看"}});+ let hook = json!({"sessionUpdate": "hook_execution", "hook": "session_start"});+ let mode = json!({"sessionUpdate": "current_mode_update", "currentModeId": "default"});+ for (id, updates, listed) in [+ ("shell", vec![hook.clone(), mode.clone()], false),+ ("thought", vec![text("agent_thought_chunk")], true),+ (+ "tool",+ vec![json!({"sessionUpdate": "tool_call", "title": "Grep"})],+ true,+ ),+ ("chat", vec![hook, mode, text("user_message_chunk")], true),+ ] {+ let dir = cwd.join(id);+ fs::create_dir_all(&dir).unwrap();+ let path = dir.join("updates.jsonl");+ let body: String = updates+ .iter()+ .map(|update| format!("{}\n", json!({"params": {"update": update}})))+ .collect();+ fs::write(&path, body).unwrap();+ // 列表与监听都只经 file_ref+ assert_eq!(adapter.file_ref(&path).is_some(), listed, "{id}");+ let parsed = adapter+ .parse_session(&fs_ref(AgentId::Grok, &path, id))+ .unwrap();+ assert_eq!(parsed.meta.message_count > 0, listed, "{id}");+ }+ let mut ids: Vec<String> = adapter+ .list_session_files()+ .unwrap()+ .into_iter()+ .map(|r| r.native_id)+ .collect();+ ids.sort_unstable();+ assert_eq!(ids, ["chat", "thought", "tool"]);+}+#[test]fn kimi_parse_contract() {setup();