All your AI agent sessions in one place — browse, search, resume. Rust + GPUI.
Rust
feat: start new Claude Code and Codex sessions with recent project sessions
Corey Chiu23e6a74dc0e1
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.jsonnew file mode 100644index 0000000..2eb1f56--- /dev/null+++ b/.claude-plugin/marketplace.json@@ -0,0 +1,15 @@+{+ "name": "wake",+ "owner": {+ "name": "Corey Chiu",+ "url": "https://github.com/iAmCorey"+ },+ "description": "Wake — every coding-agent session on this machine, searchable and readable by your agents",+ "plugins": [+ {+ "name": "wake",+ "source": "./plugins/wake",+ "description": "Every new session starts with this project's recent sessions (from Claude Code, Codex and the other agents Wake indexes), and Wake's MCP tools let Claude search and read any earlier session. Needs the Wake app."+ }+ ]+}diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 13846bc..f04accd 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,9 @@## [Unreleased]+- New: Every new Claude Code session can start with the project's recent sessions from Wake — install the Wake plugin with one command, and it adds Wake's MCP tools too. Codex gets the same through Codex hooks. Both are in Settings → Connect+- Fix: Looking up a project's sessions from a folder that has no history of its own no longer returns sessions started in your home folder or at the filesystem root+- Update: Copy buttons in Settings → Connect are icons now; hover one to see what it copies- Fix: Search results show the text around each match, with every search term highlighted, instead of a dozen characters- Fix: A session you delete in Wake shows up again when you put its file back from the Trash; sessions that live in an agent's own database are now hidden from Wake instead of claiming to go to the Trash- Fix: A failed search, star or pin change, or a list that stops loading now says so instead of failing silentlydiff --git a/DESIGN.md b/DESIGN.mdindex d737831..b8faa2e 100644--- a/DESIGN.md+++ b/DESIGN.md@@ -135,7 +135,7 @@ macOS 不设置横跨三栏的自定义 header。主窗口透明标题栏高 44p- 行内容 = 行首元素 + 标题 + 计数;计数一律 Label 档 muted。- 组头 "Agents"/"Projects" 用 Body 档常规字重 + muted 色(与主导航同字号同字重,仅靠颜色区分——加粗会让组头压过它统辖的行)。行首是 13px 的折叠 chevron(收起指右、展开指下),坐在与导航行同一个 18px 行首槽位里、中心压 26.75 轴(用户 2026-09-22 定:箭头放到开头,对准上面菜单的图标与红绿灯的红灯;原先 chevron 跟在文字后);chevron 取 15px(与导航行图标同档,描边粗细一致),**不占 18px 槽位、按自己的框居中压轴**,再接统一的 `ICON_TEXT_GAP`——槽位居中再接同一间距,墨迹到文字会比导航行空出一截(chevron 墨迹只有约 5px 宽,用户同日"间隔太大");按框压轴后墨迹到文字视觉约 10.9px 与导航行相当,文字起点比导航行标签左 1.5px。- 底部工具条常驻,总高 44px(含顶部 1px hairline),两端分置的**纯图标条**(2026-09-21 三轮定稿:六个一样的 ghost 图标挤一排分不出层级;带边框底色的分段盒子放在侧栏里像一个走错地方的表单控件——参照 Zed 状态栏 / Xcode 导航条,不带盒子):按钮统一 28×28、6px 圆角、14px 图标、2px 间距;**左端**——Sessions(messages-square,双气泡;单气泡的 message-square 留给消息级用途)/ Memory(brain)/ Insights(chart-column)三颗页切换,再接 brush-cleaning "Clean Up Sessions"(它是叠在会话视图上的模式,也靠左),当前页(或打开中的清理)那颗用侧栏行的选中色(`sidebar_accent` 底 + `sidebar_accent_foreground` 图标)做圆角底,与导航行选中态同一套语言;**右端只有齿轮 "Settings"**。左内边距 12.75 = 26.75(侧栏中轴)− 14(按钮半宽):最左那颗图标的中心与红绿灯红灯中心、导航行行首在同一条轴上。未选中的一律透明底、muted 图标,hover 才出色。**Refresh 不在工具条**:它住在每页页头右端(All Sessions 页头在 Sort 左侧,Memory / Insights 页头单独一个;tooltip 就叫 "Refresh"),会话页与 Insights 走整库重扫(Insights 的数据是扫描收尾派生的),Memory 页只同步记忆(读 Settings → Memory locations 的当下配置,不重扫会话;用户 2026-09-22 定各刷各的);进行中转圈并禁用,⌘R 恒为刷会话。Settings 同时进入 Wake 菜单并绑定 `⌘,`(其他平台 `Ctrl+,`),保持单例窗口。-- Settings 默认 820×600,采用 180px 窄侧栏 + 内容页结构,固定为 General / Session locations / Memory locations / Remote hosts / Connect / Data / Updates / About 八项(侧栏项原叫 Locations,有了 Memory locations 后改成与页标题一致的 Session locations,用户 2026-09-21 定)(Connect 为 0.5.0 新增,插在 Remote hosts 与 Data 之间——两页都是"把 Wake 接到外部"的集成面,Data 之后是纯本地信息;Memory locations 是记忆可见层二期加的,紧挨 Locations——两页都是"Wake 读哪里");About 与功能设置分离并钉在侧栏底部,Wake 菜单的 About Wake 直达同一页。About 沿用 Kooky/Birth 的信息顺序:产品图标、名称、版本、tagline、GitHub、短分隔线、版权/许可证与作者署名。Updates 是独立功能页,仅在用户点击页面按钮或 macOS Wake 菜单的 Check for Updates 时读取 GitHub 最新正式 Release 元数据,明确呈现检查中/最新版/有新版/失败四种状态;有新版时打开 Release 页供用户下载,不后台检查、不自行覆盖应用包。内部常规文字按钮统一沿用主界面的 24px 高、6px 圆角和主题交互色,普通页面动作使用 muted 填充 + hairline;发现新版后的 View Update 是需要用户继续完成的主操作,使用 32px 高 primary 填充和轻阴影。Appearance 分段选择器也使用同一材质。General 只放真实可用的全局偏好,当前为持久化的 System / Light / Dark 外观选择与 Language(跟随系统或固定某个语言包,0.5.2 起);不提供默认 “Open In” 终端。Data 只展示 Wake 本地存储位置、会话数与磁盘占用并提供文件管理器入口,不重复放刷新或清库动作;常规 Refresh 的唯一入口仍是主侧栏底部。Locations 页按 AgentId 声明序以 agent 分组,品牌名只在组头出现一次;本机有数据的组优先,未检测到的 agent 默认收进可展开区。每条路径以路径为主信息、会话数/不可用状态为 muted 副信息,最右为逐路径开关;停用时只降低文字层级,开关与菜单保持完整对比度。行本身不承担编辑,`…` 菜单集中 Edit / Show in Finder / 自定义 Remove。顶部操作为低强调的 Add location,Restore defaults 收进页级 `…` 菜单且无偏离时禁用。添加/编辑仍复用 agent 下拉 + 可手输路径 + 目录选择表单;关闭 location 后保留配置、停止扫描/监听并从会话与搜索结果排除,重新开启即增量扫回;纯路径管理不做内容校验。**Memory locations 页与 Locations 同版式**(2026-09-21 记忆可见层二期):标题 "Memory locations" + 一句说明 + 右侧 Add location + 页级 `…` 里的 Restore defaults;按 AgentId 声明序分组,一行一个记忆来源——各家默认的(Claude 的 auto-memory 树与 `~/.claude/CLAUDE.md`、Codex 的 memories 目录、逐线程库、`~/.codex/AGENTS.md` 与 `rules/`、Gemini 的 `~/.gemini/GEMINI.md`、ZCode 的记忆树)、项目根模式(`<project>/CLAUDE.md`、`<project>/.cursor/rules` 一类,原样显示占位符)与用户加的自定义目录/文件;路径为主信息、文件数(或 "Not found")为 muted 副信息,最右逐来源开关;`…` 菜单:默认来源只有 Show in Finder(项目模式连这个也没有),自定义来源多 Edit / Remove。添加/编辑与 Session locations 是同一个表单(`open_path_form`),差别是字段叫 "Folder or file"、选择器也收文件。改动不换 roster,只补一轮增量扫描,记忆流随之更新。Remote hosts 页沿用 Locations 的版式:标题 + 说明,右侧低强调的 Sync now / Add host;host 列表为单张 popover 底圆角卡,一行一台(名字为主信息、同步状态为 muted 副信息,失败用 danger),`…` 菜单集中 Sync now / Remove,最右为开关;添加走与 location 同材质的单字段表单弹窗,SSH 前提说明放在字段下方。列表与详情页的远程会话以 `@host` 徽章标识:列表行为 primary 淡底填充胶囊(与 muted 项目胶囊区分),详情页与 model/source 同排用 primary 描边。Connect 页沿用 Data 页的版式,**只放状态与动作,不放文档**(用户 2026-09-08 三轮定稿:平级双卡带代码块、嵌套同卡、缩进从属卡都试过,根源是设置窗里塞了 README 内容,怎么排都像教程):标题 + 一句说明(不点名 MCP、不写 read-only 声明);「MCP server」卡 84px 一行显示 wake-mcp 名称与 mono 字体的 `~/…` 路径,右侧 Copy path,不放"Ready"状态行,只在找不到二进制时给一行 danger 文案;「MCP clients」卡三行(Claude Code / Codex / Cursor),17px 品牌图标领行、客户端名为主信息、用法提示为 muted 副信息、右侧是 ghost 的 Show/Hide 切换(chevron 图标 + 文案,muted 前景,用户 2026-09-08 追加)加 Copy command / Copy config;代码块**默认收起**,展开后出现在该行下方、左缘对齐到文字轴(行内边距 16 + 图标 17 + 间距 12),secondary 填充 + 主题圆角的 mono 逐行渲染,Settings 重开即复位。0.6.x 起页面是**四个区块**(用户 2026-09-11 定稿):MCP server / MCP clients / Command line / Skill——MCP server / Command line / Skill 各一张 84px 信息卡、MCP clients 仍是三行客户端列表(wake-mcp、wake-cli 是二进制名与 mono 路径 + Copy path;wake-cli 那张在 Copy path **左侧**多一个 Copy command,复制「把它放进 PATH」的那行命令——右侧留给两张卡同名的 Copy path,纵向才对得齐;deb/tar 已装进 `…/bin` 或 Windows 上没有可粘命令时这个按钮不出现;Skill 是 `npx skills add …` + Copy command),区块标题为「Agents」时看不出这块特指 MCP,故改名 MCP clients 与上方 MCP server 成对。**说明性 caption 一律不放**——那正是"设置窗里塞 README"的复发形态;Setup guide 链接改挂在区块标题右端,规则是**每个面的第一个区块挂自己的文档**:MCP server → docs/mcp.md,Command line → docs/cli.md(MCP clients 与 Skill 分属这两个面的第二块,不重复挂)。四块之后整页**超过一屏、需要滚动**——2026-09-08 那条"一屏放下"的约束随第三、四个区块作废,滚动容器本来就在(`flex_1().min_h_0().overflow_y_scroll()`),卡片记得 `flex_shrink_0` 否则会被压扁。复制反馈是按钮原地变 "Copied"(check 图标)1.6s 后复原,**不弹通知**——gpui-component 的 toast 在窗口失活或被悬停时暂停自动关闭,在 Settings 从属窗里经常就挂着不走(用户 2026-09-08 反馈),且主界面的 Copy Session ID / Copy code 本来就不弹;页面只展示不代写别家配置。+- Settings 默认 820×600,采用 180px 窄侧栏 + 内容页结构,固定为 General / Session locations / Memory locations / Remote hosts / Connect / Data / Updates / About 八项(侧栏项原叫 Locations,有了 Memory locations 后改成与页标题一致的 Session locations,用户 2026-09-21 定)(Connect 为 0.5.0 新增,插在 Remote hosts 与 Data 之间——两页都是"把 Wake 接到外部"的集成面,Data 之后是纯本地信息;Memory locations 是记忆可见层二期加的,紧挨 Locations——两页都是"Wake 读哪里");About 与功能设置分离并钉在侧栏底部,Wake 菜单的 About Wake 直达同一页。About 沿用 Kooky/Birth 的信息顺序:产品图标、名称、版本、tagline、GitHub、短分隔线、版权/许可证与作者署名。Updates 是独立功能页,仅在用户点击页面按钮或 macOS Wake 菜单的 Check for Updates 时读取 GitHub 最新正式 Release 元数据,明确呈现检查中/最新版/有新版/失败四种状态;有新版时打开 Release 页供用户下载,不后台检查、不自行覆盖应用包。内部常规文字按钮统一沿用主界面的 24px 高、6px 圆角和主题交互色,普通页面动作使用 muted 填充 + hairline;发现新版后的 View Update 是需要用户继续完成的主操作,使用 32px 高 primary 填充和轻阴影。Appearance 分段选择器也使用同一材质。General 只放真实可用的全局偏好,当前为持久化的 System / Light / Dark 外观选择与 Language(跟随系统或固定某个语言包,0.5.2 起);不提供默认 “Open In” 终端。Data 只展示 Wake 本地存储位置、会话数与磁盘占用并提供文件管理器入口,不重复放刷新或清库动作;常规 Refresh 的唯一入口仍是主侧栏底部。Locations 页按 AgentId 声明序以 agent 分组,品牌名只在组头出现一次;本机有数据的组优先,未检测到的 agent 默认收进可展开区。每条路径以路径为主信息、会话数/不可用状态为 muted 副信息,最右为逐路径开关;停用时只降低文字层级,开关与菜单保持完整对比度。行本身不承担编辑,`…` 菜单集中 Edit / Show in Finder / 自定义 Remove。顶部操作为低强调的 Add location,Restore defaults 收进页级 `…` 菜单且无偏离时禁用。添加/编辑仍复用 agent 下拉 + 可手输路径 + 目录选择表单;关闭 location 后保留配置、停止扫描/监听并从会话与搜索结果排除,重新开启即增量扫回;纯路径管理不做内容校验。**Memory locations 页与 Locations 同版式**(2026-09-21 记忆可见层二期):标题 "Memory locations" + 一句说明 + 右侧 Add location + 页级 `…` 里的 Restore defaults;按 AgentId 声明序分组,一行一个记忆来源——各家默认的(Claude 的 auto-memory 树与 `~/.claude/CLAUDE.md`、Codex 的 memories 目录、逐线程库、`~/.codex/AGENTS.md` 与 `rules/`、Gemini 的 `~/.gemini/GEMINI.md`、ZCode 的记忆树)、项目根模式(`<project>/CLAUDE.md`、`<project>/.cursor/rules` 一类,原样显示占位符)与用户加的自定义目录/文件;路径为主信息、文件数(或 "Not found")为 muted 副信息,最右逐来源开关;`…` 菜单:默认来源只有 Show in Finder(项目模式连这个也没有),自定义来源多 Edit / Remove。添加/编辑与 Session locations 是同一个表单(`open_path_form`),差别是字段叫 "Folder or file"、选择器也收文件。改动不换 roster,只补一轮增量扫描,记忆流随之更新。Remote hosts 页沿用 Locations 的版式:标题 + 说明,右侧低强调的 Sync now / Add host;host 列表为单张 popover 底圆角卡,一行一台(名字为主信息、同步状态为 muted 副信息,失败用 danger),`…` 菜单集中 Sync now / Remove,最右为开关;添加走与 location 同材质的单字段表单弹窗,SSH 前提说明放在字段下方。列表与详情页的远程会话以 `@host` 徽章标识:列表行为 primary 淡底填充胶囊(与 muted 项目胶囊区分),详情页与 model/source 同排用 primary 描边。Connect 页沿用 Data 页的版式,**只放状态与动作,不放文档**(用户 2026-09-08 三轮定稿:平级双卡带代码块、嵌套同卡、缩进从属卡都试过,根源是设置窗里塞了 README 内容,怎么排都像教程):标题 + 一句说明(不点名 MCP、不写 read-only 声明);「MCP server」卡 84px 一行显示 wake-mcp 名称与 mono 字体的 `~/…` 路径,右侧复制钮,不放"Ready"状态行,只在找不到二进制时给一行 danger 文案;「MCP clients」卡三行(Claude Code / Codex / Cursor),17px 品牌图标领行、客户端名为主信息、用法提示为 muted 副信息、右侧是 ghost 的 Show/Hide 切换(chevron 图标 + 文案,muted 前景,用户 2026-09-08 追加)加复制钮;代码块**默认收起**,展开后出现在该行下方、左缘对齐到文字轴(行内边距 16 + 图标 17 + 间距 12),secondary 填充 + 主题圆角的 mono 逐行渲染,Settings 重开即复位。0.6.x 起页面是**四个区块**(用户 2026-09-11 定稿):MCP server / MCP clients / Command line / Skill——MCP server / Command line / Skill 各一张 84px 信息卡、MCP clients 仍是三行客户端列表(wake-mcp、wake-cli 是二进制名与 mono 路径 + 复制路径的钮;wake-cli 那张在它**左侧**多一个终端图标的复制钮,复制「把它放进 PATH」的那行命令——两颗一样的复制图标并排分不清,所以换字形;最右留给两张卡同为复制路径的那颗,纵向才对得齐;deb/tar 已装进 `…/bin` 或 Windows 上没有可粘命令时这个按钮不出现;Skill 是 `npx skills add …` + 复制钮),区块标题为「Agents」时看不出这块特指 MCP,故改名 MCP clients 与上方 MCP server 成对。**说明性 caption 一律不放**——那正是"设置窗里塞 README"的复发形态;Setup guide 链接改挂在区块标题右端,规则是**每个面的第一个区块挂自己的文档**:MCP server → docs/mcp.md,Command line → docs/cli.md(MCP clients 与 Skill 分属这两个面的第二块,不重复挂)。最上面另有两块 **Claude Code plugin** / **Codex hooks**(新会话开场带上项目最近的会话;标题用各家正名,用户 2026-10-09 定),各是一个面、各挂自己的 Setup guide(docs/cli.md 的两节);卡是 48px 一行,只有一句用法(正文字号、前景色,与卡片标题行同一种字)+ 右端复制钮,不摆等宽命令、不加品牌图与名字行(区块标题已点名);Windows 上两块都不画。四块之后整页**超过一屏、需要滚动**——2026-09-08 那条"一屏放下"的约束随第三、四个区块作废,滚动容器本来就在(`flex_1().min_h_0().overflow_y_scroll()`),卡片记得 `flex_shrink_0` 否则会被压扁。**复制钮一律只有图标**(用户 2026-10-09 定:卡上已经摆着要复制的东西或一句用法,按钮上再写 Copy path / Copy command 是重复):与文字按钮同材质、同 24px 高的方钮,13px 图标,说明在 tooltip;复制反馈是图标原地变 check(tooltip 变 Copied)1.6s 后复原,**不弹通知**——gpui-component 的 toast 在窗口失活或被悬停时暂停自动关闭,在 Settings 从属窗里经常就挂着不走(用户 2026-09-08 反馈),且主界面的 Copy Session ID / Copy code 本来就不弹;页面只展示不代写别家配置。- 工具条内的**状态行"常态沉默"**:仅刷新中或监听不可用时出现在按钮行上方;文案须可 truncate,窄侧栏放不下长句(故为 "Live updates off" 而非带操作建议的整句)。刷新中行首是与页头 Refresh 按钮 loading 态同一个 Spinner(12px、muted 色),文字下方 8px 处一条 3px 进度条(`Progress`,primary 色、轨道同色 20%;会话扫描按 done/total 定值,总数未知 / 记忆同步 / 远程同步走不定值滑动;2026-09-22 用户要的),出错时行首回到静态 refresh-cw 图标。- 手动 Refresh 始终后台运行;进度复用侧栏状态行,完成后发通知("Sessions refreshed" / "Memory refreshed"),不用模态框阻断浏览、搜索或阅读。- 不把项目包装成卡片,不堆叠分支、时间或重复图标。项目行不加彩色标识——同一图标重复十几次不传递信息。diff --git a/README.md b/README.mdindex c2fa11f..c31ec6b 100644--- a/README.md+++ b/README.md@@ -134,7 +134,7 @@ wake-cli refresh # update the index while WakeIt prints what the MCP tools return, asserted byte for byte in the test suite apart from a trailing newline the CLI adds, so an agent driving it through a shell sees what a connected one does. Full reference in [docs/cli.md](docs/cli.md).-To make an agent reach for it without being told, install the bundled skill with `npx skills add iAmCorey/Wake` (or copy `skills/wake/` into `~/.claude/skills/wake/`). Claude Code can go one step further and receive the project's recent sessions the moment a session starts, through a `SessionStart` hook that runs `wake-cli` — the recipe is in [docs/cli.md](docs/cli.md#teaching-an-agent-to-use-it).+To make an agent reach for it without being told, install the bundled skill with `npx skills add iAmCorey/Wake` (or copy `skills/wake/` into `~/.claude/skills/wake/`). Every new session can also start with the project's recent sessions already in context: for Claude Code, `claude plugin marketplace add iAmCorey/Wake && claude plugin install wake@wake` installs the Wake plugin, which does this and adds Wake's MCP tools in one go ([Claude Code plugin](docs/cli.md#claude-code-plugin)); Codex gets the same through [Codex hooks](docs/cli.md#codex-hooks). Both are in Settings → Connect.## Zoomdiff --git a/crates/wake-core/src/bin/wake_cli.rs b/crates/wake-core/src/bin/wake_cli.rsindex 5c5ce99..ee8a886 100644--- a/crates/wake-core/src/bin/wake_cli.rs+++ b/crates/wake-core/src/bin/wake_cli.rs@@ -7,11 +7,13 @@//! wake-cli setup 路径、进 PATH、给 agent 的说明//! wake-cli index 库不存在时建一次(见 scanner::build_index)//! wake-cli refresh 库已在、Wake 没开时增量刷一轮(见 scanner::refresh_index)+//! wake-cli context 当前目录所在项目最近的会话,给 SessionStart 钩子//! wake-cli --version | --help//!//! 输出就是 MCP 工具那份文本、一字不改(tests/cli.rs 逐字节卡),所以 docs 与//! 将来的 Skill 只需描述一份格式。解析在 `wake_core::cli`,这里只做 I/O 与退-//! 出码。查询一律只读打开索引(`mcp::open_index`),**绝不 open_or_rebuild**;+//! 出码。查询一律只读打开索引(工具走 `mcp::open_index`;`setup` / `context` 不读会话+//! 文件,直接 `Store::open_read_only`、不建 roster),**绝不 open_or_rebuild**;//! 写库的只有 `index` 与 `refresh` 两个子命令,都先拿 `db::IndexLock`——规矩与//! 理由在 `scanner::build_index` / `refresh_index`,别在这里复述或放宽。//!@@ -55,6 +57,7 @@ fn main() -> ExitCode {Action::Setup => write(ok(setup(&inv.db))),Action::Index => write(index(&db_path(&inv.db))),Action::Refresh => write(refresh(&db_path(&inv.db))),+ Action::Context => context(&inv.db),Action::Tool { tool, args } => run(&inv.db, tool, &args),}}@@ -86,6 +89,26 @@ fn run(db: &Option<PathBuf>, tool: &str, args: &serde_json::Value) -> ExitCode {)))}+/// 新会话开场的上下文:当前目录(钩子在会话目录里跑)所在项目最近的会话。没有就一个字都+/// 不写、退 0——钩子的输出原样进 agent 的上下文,连空行都是噪音。缺库、读不出照常走诊断+/// 出口,钩子那头自己吞掉+fn context(db: &Option<PathBuf>) -> ExitCode {+ let dir = match std::env::current_dir() {+ Ok(dir) => dir,+ Err(e) => return write(refuse(format!("cannot read the current directory: {e}"))),+ };+ // 只读库里的会话行、不读会话文件,不必把 roster 建起来(与 setup 同理);库不存在或+ // 太老由 open_read_only 给出 "launch Wake once"。哪天要读会话文件了,改回 open_index+ let store = match Store::open_read_only(&db_path(db)) {+ Ok(store) => store,+ Err(e) => return write(refuse(format!("{e:#}"))),+ };+ match tools::session_start_context(&store, &dir).transpose() {+ None => ExitCode::SUCCESS,+ Some(result) => write(cli::report(result)),+ }+}+/// 建一次索引,然后说一句人话。建不建、凭什么敢建全在 `scanner::build_index`,/// 这里只剩措辞。场景是"装了 Wake 但从没启动过":skill 让 agent 跑这一条自救fn index(path: &Path) -> Report {diff --git a/crates/wake-core/src/cli.rs b/crates/wake-core/src/cli.rsindex 29c27ed..605d13a 100644--- a/crates/wake-core/src/cli.rs+++ b/crates/wake-core/src/cli.rs@@ -114,6 +114,11 @@ const PLAIN: &[PlainSpec] = &[action: Action::Refresh,summary: "update an existing index while Wake is closed",},+ PlainSpec {+ name: "context",+ action: Action::Context,+ summary: "this folder's project, its recent sessions — for a session-start hook; prints nothing when there are none",+ },];const F_PROJECT: FlagSpec = FlagSpec::new(@@ -266,6 +271,9 @@ pub enum Action {Index,/// 增量刷一轮已有的索引。**只在 Wake 没运行时**——它在跑就退让Refresh,+ /// 当前目录所在项目最近的会话,给 SessionStart 钩子(`tools::session_start_context`);+ /// 没有就一个字都不写+ Context,/// 一次工具调用。`args` **恒为 JSON object**——mcp/mod.rs 那道/// `arguments` 形状检查在这条路上不可达,别再补一遍Tool {@@ -785,6 +793,53 @@ project on the machine is in scope. Everything is read-only.";/// 与 `wake-cli setup` 同一个来源pub const SKILL_INSTALL: &str = "npx skills add iAmCorey/Wake";+/// Claude Code 插件的安装命令:仓库根的 `.claude-plugin/marketplace.json` 就是插件市场,插件+/// 在 `plugins/wake/`(SessionStart 钩子调 `wake-cli context` + wake-mcp)。与 Settings →+/// Connect、`wake-cli setup` 同一个来源+pub const CLAUDE_PLUGIN_INSTALL: &str =+ "claude plugin marketplace add iAmCorey/Wake && claude plugin install wake@wake";++/// 这个平台给不给新会话开场的两家接法(Claude Code plugin / Codex hooks)。Windows 上不给:+/// 插件的脚本是 sh,Codex 钩子在 Windows 上走哪个 shell 也没核实。判断只在这里——设置页与+/// `wake-cli setup` 各自问它;片段函数本身不分平台,i18n 的死条目检查在 Windows 上也得看得见+/// 这两句用法(片段给 None 时 Windows CI 必红,2026-10-09 Codex review)+pub const SESSION_START_HOOKS: bool = !cfg!(target_os = "windows");++/// 让每个新会话一开场就拿到这个项目最近的会话(`wake-cli context`)的两家接法,各用各家的+/// 正名(用户 2026-10-09 定:不自己起名字):**Claude Code plugin** 装仓库里的插件,MCP 一起+/// 带上;**Codex hooks** 是 Codex 官方的钩子功能,给一段用户级配置——Codex 插件里的钩子只在+/// 桌面版手动安装时生效、插件里的 MCP 只认远端服务,做成插件命令行用户什么都拿不到;用户加的+/// 钩子 Codex 一律要在 /hooks 里批准过才跑。Settings → Connect 的两块与 `wake-cli setup`+/// 同源,给不给看 `SESSION_START_HOOKS`+pub fn claude_plugin_snippet() -> crate::mcp::SetupSnippet {+ crate::mcp::SetupSnippet {+ client: "Claude Code",+ agent: AgentId::ClaudeCode,+ hint: "Run in a terminal to install the Wake plugin",+ copy_label: "Copy command",+ text: CLAUDE_PLUGIN_INSTALL.to_string(),+ }+}++/// 见 `claude_plugin_snippet`+pub fn codex_hooks_snippet(cli_bin: &Path) -> crate::mcp::SetupSnippet {+ // 路径先按 sh 引好,整条再引成 TOML 字符串+ let command = crate::mcp::json_quote(&format!(+ "{} context 2>/dev/null || true",+ sh_quote(&cli_bin.to_string_lossy())+ ));+ crate::mcp::SetupSnippet {+ client: "Codex",+ agent: AgentId::Codex,+ hint: "Add to ~/.codex/config.toml, then approve it in /hooks",+ copy_label: "Copy config",+ text: format!(+ "[[hooks.SessionStart]]\nmatcher = \"startup|clear\"\n\n\+ [[hooks.SessionStart.hooks]]\ntype = \"command\"\ncommand = {command}\ntimeout = 30"+ ),+ }+}+/// 把 CLI 放进 PATH 的那一条**可粘命令**,给 GUI 的 Copy 按钮用。与/// `wake-cli setup` 打印的是同一个来源。返回 None 的两种情况都不该给按钮:/// 已经装在 `…/bin` 里(deb / tar)、以及 Windows——那边 path_hint 给的是@@ -847,6 +902,11 @@ fn path_hint(bin: &Path) -> Option<String> {})}+/// `wake-cli setup` 里一段可复制的配置:`## {标题} — {怎么用这段}`、片段、一句说明+fn snippet_section(title: &str, s: &crate::mcp::SetupSnippet, note: &str) -> String {+ format!("\n## {title} — {}\n\n{}\n\n{note}\n", s.hint, s.text)+}+/// `## {标题} — {怎么用这段}` 与 `wake-mcp setup` 同形,两个 bin 的输出读起来/// 才是一家人pub fn setup_text(f: &SetupFacts<'_>) -> String {@@ -869,6 +929,19 @@ pub fn setup_text(f: &SetupFacts<'_>) -> String {project. Manual install: copy `skills/wake/` from the repository into\n\`~/.claude/skills/wake/`.\n"));+ if SESSION_START_HOOKS {+ out.push_str(&snippet_section(+ "Claude Code plugin",+ &claude_plugin_snippet(),+ "Every new session starts with this project's recent sessions, and Claude gets\n\+ Wake's MCP tools to read them.",+ ));+ out.push_str(&snippet_section(+ "Codex hooks",+ &codex_hooks_snippet(f.cli_bin),+ "Every new Codex session starts with this project's recent sessions.",+ ));+ }// 片段按 agent 认,不按下标——那个顺序是 Connect 页的事;hint 也用它自己// 带的,两个 bin 的 setup 输出才真的同形if let Some(snippet) = f.mcp_bin.and_then(|mcp| {@@ -876,10 +949,10 @@ pub fn setup_text(f: &SetupFacts<'_>) -> String {.into_iter().find(|s| s.agent == AgentId::ClaudeCode)}) {- out.push_str(&format!(- "\n## Tool-calling clients: prefer MCP — {}\n\n{}\n\n\- `wake-mcp setup` prints the same for Codex and Cursor.\n",- snippet.hint, snippet.text+ out.push_str(&snippet_section(+ "Tool-calling clients: prefer MCP",+ &snippet,+ "`wake-mcp setup` prints the same for Codex and Cursor.",));}out.push_str("\nFull reference: docs/cli.md\n");@@ -1197,6 +1270,7 @@ mod tests {assert_eq!(p(&["setup"]).unwrap().action, Action::Setup);assert_eq!(p(&["index"]).unwrap().action, Action::Index);assert_eq!(p(&["refresh"]).unwrap().action, Action::Refresh);+ assert_eq!(p(&["context"]).unwrap().action, Action::Context);assert!(USAGE.lines().count() < 15, "USAGE 不该长回参考手册");assert!(!USAGE.ends_with('\n'));}@@ -1353,6 +1427,13 @@ mod tests {assert!(t.contains(SKILL_INSTALL), "{t}");assert!(t.contains("~/.claude/skills/wake/"), "{t}");assert!(t.contains("claude mcp add"));+ // 开场上下文的两段跟着平台走(Windows 上不给),判断只在 SESSION_START_HOOKS+ assert_eq!(+ t.contains("## Claude Code plugin"),+ SESSION_START_HOOKS,+ "{t}"+ );+ assert_eq!(t.contains("## Codex hooks"), SESSION_START_HOOKS, "{t}");let t = setup_text(&SetupFacts {cli_bin: &cli_bin,@@ -1369,6 +1450,27 @@ mod tests {.ends_with("Note: no Wake index at /tmp/wake.db"));}+ #[test]+ fn plugin_and_hooks_snippets_call_context_with_the_given_binary() {+ // 片段不分平台(Windows 上不显示由 SESSION_START_HOOKS 管),这条三个平台都跑+ let bin = PathBuf::from("/Apps/My Wake.app/Contents/MacOS/wake-cli");+ assert_eq!(claude_plugin_snippet().text, CLAUDE_PLUGIN_INSTALL);+ let codex = codex_hooks_snippet(&bin);+ assert!(+ codex.text.starts_with("[[hooks.SessionStart]]"),+ "{}",+ codex.text+ );+ // 带空格的路径按 sh 引好,外面再套一层 TOML basic string+ assert!(+ codex.text.contains(+ "command = \"'/Apps/My Wake.app/Contents/MacOS/wake-cli' context 2>/dev/null || true\""+ ),+ "{}",+ codex.text+ );+ }+#[test]fn path_command_is_pasteable_or_absent() {let bundled = PathBuf::from("/Apps/Wake.app/Contents/MacOS/wake-cli");diff --git a/crates/wake-core/src/mcp/mod.rs b/crates/wake-core/src/mcp/mod.rsindex 877a626..f89b892 100644--- a/crates/wake-core/src/mcp/mod.rs+++ b/crates/wake-core/src/mcp/mod.rs@@ -257,20 +257,25 @@ pub fn sibling_file(stem: &str) -> Option<PathBuf> {pub struct SetupSnippet {/// 客户端名("Claude Code")pub client: &'static str,- /// 对应的 agent(UI 取品牌图标用)+ /// 对应的 agent(MCP clients 那一行的品牌图标)pub agent: AgentId,/// 怎么用这段("Run in a terminal" / "Add to ~/.codex/config.toml")pub hint: &'static str,- /// 复制按钮文案("Copy command" / "Copy config")——UI 只给按钮不展示片段+ /// 复制钮的说明("Copy command" / "Copy config";Connect 页的复制钮只有图标,这句进 tooltip)pub copy_label: &'static str,pub text: String,}+/// 接入片段里的字符串字面量:带引号、按 JSON 转义——TOML basic string 与 JSON 的转义+/// 子集兼容,一个写法同时给 TOML 与 JSON 两种配置用,Windows 的反斜杠与含空格路径都安全+pub(crate) fn json_quote(s: &str) -> String {+ serde_json::to_string(s).unwrap_or_default()+}+/// 三家客户端的接入片段(UI 的 Connect 页与 `wake-mcp setup` 同源)。路径一律-/// 按 JSON 字符串转义——TOML basic string 与 JSON 的转义子集兼容,Windows 的-/// 反斜杠与含空格路径都安全+/// 经 `json_quote`pub fn setup_snippets(bin: &Path) -> Vec<SetupSnippet> {- let quoted = serde_json::to_string(&bin.to_string_lossy()).unwrap_or_default();+ let quoted = json_quote(&bin.to_string_lossy());vec![SetupSnippet {client: "Claude Code",diff --git a/crates/wake-core/src/mcp/tools.rs b/crates/wake-core/src/mcp/tools.rsindex 2627fbd..303dfaf 100644--- a/crates/wake-core/src/mcp/tools.rs+++ b/crates/wake-core/src/mcp/tools.rs@@ -269,6 +269,49 @@ pub fn invoke(call(&ctx, name, args)}+/// 新会话开场注入几条、看多久以内的(`wake-cli context`;插件与 Codex 钩子都调它)+const CONTEXT_SESSIONS: i64 = 5;+const CONTEXT_DAYS: i64 = 14;++/// 新会话开场的上下文(`wake-cli context`,Claude Code 插件与 Codex 的 SessionStart 钩子+/// 调它):`dir` 所在项目最近两周的几条会话,查询与条目都是 wake_list_sessions 那一份+/// (`recent_roots` / `push_session_lines`)。认不出项目、这段时间没有会话时给 None——钩子的+/// 输出原样进 agent 的上下文,"没有结果"的提示与已知项目清单在这里只是噪音。不是 MCP 工具、+/// 没有要逐字节对齐的另一面,只读库里的会话行、不读会话文件,所以不经 ToolContext、不要 roster+pub fn session_start_context(+ store: &Store,+ dir: &std::path::Path,+) -> Result<Option<String>, ToolError> {+ let project_paths = resolve_project_paths(&dir.to_string_lossy(), &store.list_projects(true)?);+ if project_paths.is_empty() {+ return Ok(None);+ }+ let since = crate::db::now_ms() - CONTEXT_DAYS * crate::cleanup::DAY;+ let (sessions, total) = recent_roots(+ store,+ project_paths,+ Vec::new(),+ Some(since),+ false,+ CONTEXT_SESSIONS,+ )?;+ if sessions.is_empty() {+ return Ok(None);+ }+ let mut out = format!(+ "Wake: {total} session{} in this project in the last {CONTEXT_DAYS} days{}:\n\n",+ plural(total),+ if total > sessions.len() as i64 {+ format!(", the {} most recent", sessions.len())+ } else {+ String::new()+ }+ );+ push_session_lines(&mut out, &sessions);+ out.push_str("\nRead one with the wake_get_session tool, or run `wake-cli show <key>`.\n");+ Ok(Some(out))+}+// ---------------------------------------------------------------- 参数读取fn str_arg<'a>(args: &'a Value, name: &str) -> Result<Option<&'a str>, ToolError> {@@ -904,17 +947,20 @@ fn get_memory(ctx: &ToolContext, key: &str, args: &Value) -> ToolResult {Ok(out)}-fn list_sessions(ctx: &ToolContext, args: &Value) -> ToolResult {- let agents = agents_arg(args)?;- let since = since_arg(ctx, args)?;- let starred = bool_arg(args, "starred", false)?;- let limit = int_arg(args, "limit", 20, 1, MAX_LIST_SESSIONS)?;- let project = project_scope!(ctx, args);- // 字段全列、不带 ..Default:新增筛选字段时这里必须表态(与 workbench- // current_filter 同一约定)- let (sessions, total) = ctx.store.list_sessions(&SessionFilter {- agents: agents.clone(),- favorite_only: starred,+/// 最近的根会话:wake_list_sessions 与新会话开场的上下文共用这一份筛选——不含归档、按+/// 更新时间、置顶不优先。字段全列、不带 ..Default:新增筛选字段时这里必须表态(与+/// workbench current_filter 同一约定)+fn recent_roots(+ store: &Store,+ project_paths: Vec<String>,+ agents: Vec<AgentId>,+ updated_since: Option<i64>,+ favorite_only: bool,+ limit: i64,+) -> Result<(Vec<SessionMeta>, i64), ToolError> {+ Ok(store.list_sessions(&SessionFilter {+ agents,+ favorite_only,include_archived: false,roots_only: true,title_query: None,@@ -922,11 +968,35 @@ fn list_sessions(ctx: &ToolContext, args: &Value) -> ToolResult {ascending: false,limit,offset: 0,- updated_since: since,- project_paths: project.clone().unwrap_or_default(),+ updated_since,+ project_paths,// "最近"就是最近:GUI 的置顶优先在这里会让 limit 先被旧置顶会话占掉ignore_pins: true,- })?;+ })?)+}++/// 会话清单的条目,一条一行("- " + `session_line`)+fn push_session_lines(out: &mut String, sessions: &[SessionMeta]) {+ for s in sessions {+ out.push_str("- ");+ out.push_str(&session_line(s));+ }+}++fn list_sessions(ctx: &ToolContext, args: &Value) -> ToolResult {+ let agents = agents_arg(args)?;+ let since = since_arg(ctx, args)?;+ let starred = bool_arg(args, "starred", false)?;+ let limit = int_arg(args, "limit", 20, 1, MAX_LIST_SESSIONS)?;+ let project = project_scope!(ctx, args);+ let (sessions, total) = recent_roots(+ ctx.store,+ project.clone().unwrap_or_default(),+ agents.clone(),+ since,+ starred,+ limit,+ )?;let scope = scope_note(&project, &agents, since, starred);let mut out = String::new();if sessions.is_empty() {@@ -939,10 +1009,7 @@ fn list_sessions(ctx: &ToolContext, args: &Value) -> ToolResult {plural(total),sessions.len()));- for s in &sessions {- out.push_str("- ");- out.push_str(&session_line(s));- }+ push_session_lines(&mut out, &sessions);out.push_str("\nRead one with wake_get_session using its key.\n");out.push_str(&index_note(ctx.store));Ok(out)diff --git a/crates/wake-core/src/services/context.rs b/crates/wake-core/src/services/context.rsindex c405379..d16ae39 100644--- a/crates/wake-core/src/services/context.rs+++ b/crates/wake-core/src/services/context.rs@@ -15,6 +15,12 @@ use chrono::{NaiveDate, NaiveDateTime};/// 各 adapter 经 `project_name_of` 取的路径尾段,不必再自己切一遍)。/// 返回空 = 没匹配上,调用方据此报"未知项目",**不要退化成不过滤**。pub fn resolve_project_paths(arg: &str, projects: &[ProjectInfo]) -> Vec<String> {+ let home = crate::adapters::home_dir().map(|h| h.to_string_lossy().into_owned());+ resolve_in(arg, projects, home.as_deref())+}++/// `resolve_project_paths` 的本体,家目录由调用方给(单测不碰环境)+fn resolve_in(arg: &str, projects: &[ProjectInfo], home: Option<&str>) -> Vec<String> {let arg = crate::adapters::expand_tilde(arg.trim());let wanted = strip_trailing_sep(&arg);if wanted.is_empty() {@@ -27,8 +33,14 @@ pub fn resolve_project_paths(arg: &str, projects: &[ProjectInfo]) -> Vec<String>{return vec![p.path.clone()];}+ // 最长的祖先,但文件系统根与家目录不算:从 Dock 起的进程 cwd 是 "/"、在家目录随手+ // 开的 agent 落在 "~",它们是一切路径的祖先——拿来当"这个目录所在的项目",在还没有+ // 会话的新项目里一问就是一堆不相干的会话(SessionStart 钩子注入的正是这个,2026-10-09)let mut best: Option<&ProjectInfo> = None;- for p in projects.iter().filter(|p| !p.path.is_empty()) {+ for p in projects+ .iter()+ .filter(|p| !p.path.is_empty() && !catch_all(&p.path, home))+ {if path_owns(&p.path, wanted) && best.is_none_or(|b| p.path.len() > b.path.len()) {best = Some(p);}@@ -56,18 +68,31 @@ pub fn resolve_project_paths(arg: &str, projects: &[ProjectInfo]) -> Vec<String>matched}+/// 一切路径的祖先、当不了"所在项目"的目录:文件系统根(`/`、`C:\`)与家目录+fn catch_all(path: &str, home: Option<&str>) -> bool {+ let p = strip_trailing_sep(path);+ // 盘符根两种写法都认:Unix 上 `\` 不是分隔符,`C:\` 剥不掉尾巴(镜像来的 Windows 路径)+ let drive_root = after_drive(p).is_some_and(|rest| matches!(rest, "" | "\\" | "/"));+ let root = p.chars().all(std::path::is_separator) || drive_root;+ root || home.is_some_and(|h| strip_trailing_sep(h) == p)+}+/// 是"路径"而非"项目名"的判据。不能只看 `Path::is_absolute`:Windows 上它对/// `/Users/…` 返回 false,而索引里的远程镜像会话(以及 CI 上的 fixture)全是/// POSIX 路径;反过来 Unix 上也认 `C:\…` 形态,一个盘符串不可能是项目名fn looks_like_path(s: &str) -> bool {- let bytes = s.as_bytes();- let drive = bytes.len() >= 3- && bytes[0].is_ascii_alphabetic()- && bytes[1] == b':'- && (bytes[2] == b'\\' || bytes[2] == b'/');+ let drive = after_drive(s).is_some_and(|rest| rest.starts_with(['\\', '/']));std::path::Path::new(s).is_absolute() || s.starts_with(std::path::is_separator) || drive}+/// 盘符(`C:`)之后的部分;不以盘符开头给 None+fn after_drive(s: &str) -> Option<&str> {+ match s.as_bytes() {+ [d, b':', ..] if d.is_ascii_alphabetic() => Some(&s[2..]),+ _ => None,+ }+}+fn strip_trailing_sep(s: &str) -> &str {let trimmed = s.trim_end_matches(std::path::is_separator);// 文件系统根("/")剥光了会变空串,保留原样@@ -192,6 +217,29 @@ mod tests {assert!(resolve_project_paths(" ", &p).is_empty());}+ /// 根与家目录是一切路径的祖先,不当"所在项目":还没有会话的新项目问不出它们的会话;+ /// 真正的上级项目照常,人就站在家目录里时也照常是它+ #[test]+ fn root_and_home_are_nobodys_enclosing_project() {+ let mut p = fixtures();+ p.push(project("/", ""));+ p.push(project("/Users/t", "t"));+ let home = Some("/Users/t/");+ assert!(resolve_in("/Users/t/Github/brand-new", &p, home).is_empty());+ assert!(resolve_in("/opt/elsewhere", &p, home).is_empty());+ assert_eq!(+ resolve_in("/Users/t/Github/wake/src", &p, home),+ vec!["/Users/t/Github/wake".to_string()]+ );+ assert_eq!(+ resolve_in("/Users/t", &p, home),+ vec!["/Users/t".to_string()]+ );+ assert_eq!(resolve_in("/", &p, home), vec!["/".to_string()]);+ assert!(catch_all(r"C:\", None));+ assert!(!catch_all("/Users/t/Github", home));+ }+#[test]fn drive_letter_paths_are_paths_on_every_platform() {let p = vec![project(r"C:\Users\t\Github\wake", "wake")];diff --git a/crates/wake-core/tests/cli.rs b/crates/wake-core/tests/cli.rsindex 2c7967c..03f44b6 100644--- a/crates/wake-core/tests/cli.rs+++ b/crates/wake-core/tests/cli.rs@@ -18,7 +18,7 @@ use wake_core::adapters::{create_adapter_roster_for, create_adapters_for, AgentAuse wake_core::cli;use wake_core::db::{self, Store};use wake_core::mcp::tools::{self, TranscriptCache};-use wake_core::models::SessionFilter;+use wake_core::models::{SessionFilter, SessionMeta};use wake_core::scanner::{run_scan, NullEvents};mod common;@@ -84,13 +84,17 @@ fn call(tools::invoke(store, adapters, &TranscriptCache::default(), tool, args)}-/// 唯一的 spawn 实现。不要 .env_clear():子进程的 roster 全靠继承-/// WAKE_HOME/HOMEfn cli_raw(args: &[&str]) -> (String, String, Option<i32>) {- let out = Command::new(env!("CARGO_BIN_EXE_wake-cli"))- .args(args)- .output()- .expect("spawn wake-cli");+ cli_raw_with(args, |_| {})+}++/// 唯一的 spawn 实现(`with` 改环境与工作目录)。不要 .env_clear():子进程的+/// roster 全靠继承 WAKE_HOME/HOME+fn cli_raw_with(args: &[&str], with: impl FnOnce(&mut Command)) -> (String, String, Option<i32>) {+ let mut cmd = Command::new(env!("CARGO_BIN_EXE_wake-cli"));+ cmd.args(args);+ with(&mut cmd);+ let out = cmd.output().expect("spawn wake-cli");(String::from_utf8(out.stdout).expect("stdout is utf-8"),String::from_utf8(out.stderr).expect("stderr is utf-8"),@@ -753,3 +757,103 @@ fn refresh_refuses_when_only_remote_memories_would_be_lost() {.unwrap();assert_eq!(left, 1, "远程记忆不许被清掉");}++/// `context` 给 SessionStart 钩子用:当前目录所在项目最近两周的会话,子目录归到所在项目;+/// 认不出项目、两周内没有会话时一个字节都不输出、退 0——钩子的输出原样进 agent 的上下文。+/// 家目录不当"所在项目":在家目录随手开的会话不该被塞进每个新项目+#[test]+fn context_prints_this_folders_recent_sessions_or_nothing() {+ let tmp = tempfile::tempdir().unwrap();+ let home = std::fs::canonicalize(tmp.path()).unwrap();+ let project = home.join("app");+ let fresh = home.join("fresh");+ std::fs::create_dir_all(project.join("src")).unwrap();+ std::fs::create_dir_all(&fresh).unwrap();+ let db = home.join("wake.db");+ {+ let store = Store::open(&db).unwrap();+ let now = db::now_ms();+ let session = |id: &str, at: &Path, updated_at: i64| SessionMeta {+ project_path: at.to_string_lossy().into_owned(),+ created_at: updated_at,+ updated_at,+ ..common::meta(&format!("claude-code:{id}"), &format!("about {id}"))+ };+ store+ .write_meta_only(&[+ (session("recent", &project, now), 1),+ (session("stale", &project, now - 30 * 86_400_000), 1),+ (session("in-home", &home, now), 1),+ ])+ .unwrap();+ }+ let context = |dir: &Path| {+ let (out, _, code) = cli_raw_with(&["--db", db.to_str().unwrap(), "context"], |cmd| {+ cmd.env("WAKE_HOME", &home).current_dir(dir);+ });+ (out, code)+ };+ let (text, code) = context(&project.join("src"));+ assert_eq!(code, Some(0));+ assert!(+ text.starts_with("Wake: 1 session in this project in the last 14 days:"),+ "{text}"+ );+ assert!(text.contains("`claude-code:recent`"), "{text}");+ assert!(!text.contains("stale"), "两周以前的不列: {text}");+ assert!(!text.contains("in-home"), "家目录的会话不跟进来: {text}");++ let elsewhere = tempfile::tempdir().unwrap();+ for dir in [fresh.as_path(), elsewhere.path()] {+ assert_eq!(context(dir), (String::new(), Some(0)), "{}", dir.display());+ }+}++/// 插件只是一层壳:清单、钩子、MCP 配置都指向仓库里真实存在的脚本,钩子调的是 `wake-cli+/// context`,启动脚本找的正是各平台打包落下二进制的地方。`claude plugin validate` 不在 CI+/// 里跑,这里卡住最容易漂的几处+#[test]+fn the_claude_code_plugin_points_at_real_files() {+ let repo = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");+ let json = |path: PathBuf| -> Value {+ serde_json::from_str(&std::fs::read_to_string(path).unwrap()).unwrap()+ };+ let market = json(repo.join(".claude-plugin/marketplace.json"));+ let entry = &market["plugins"][0];+ let id = format!(+ "{}@{}",+ entry["name"].as_str().unwrap(),+ market["name"].as_str().unwrap()+ );+ assert!(cli::CLAUDE_PLUGIN_INSTALL.ends_with(&id), "{id}");+ let plugin = repo.join(entry["source"].as_str().unwrap());+ let manifest = json(plugin.join(".claude-plugin/plugin.json"));+ assert_eq!(manifest["name"], entry["name"]);++ let hooks = json(plugin.join("hooks/hooks.json"));+ let command = hooks["hooks"]["SessionStart"][0]["hooks"][0]["command"]+ .as_str()+ .unwrap();+ assert!(+ command.contains("${CLAUDE_PLUGIN_ROOT}/scripts/session-start"),+ "{command}"+ );+ let start = std::fs::read_to_string(plugin.join("scripts/session-start")).unwrap();+ assert!(start.contains("wake-cli context"), "{start}");++ let mcp = json(plugin.join(".mcp.json"));+ let args = &mcp["mcpServers"]["wake"]["args"];+ assert_eq!(args[0], "${CLAUDE_PLUGIN_ROOT}/scripts/wake");+ assert_eq!(args[1], "wake-mcp");+ let launcher = std::fs::read_to_string(plugin.join("scripts/wake")).unwrap();+ assert!(launcher.contains("/Applications/Wake.app/Contents/MacOS"));+ // tar 包装进 ~/.local/bin、deb 装进 /usr/bin+ let linux = std::fs::read_to_string(repo.join("scripts/make-linux.sh")).unwrap();+ for dir in ["$HOME/.local/bin", "/usr/bin"] {+ assert!(launcher.contains(dir), "启动脚本没找 {dir}");+ assert!(+ linux.contains(&format!("{dir}/wake-cli")),+ "Linux 打包不再落在 {dir}"+ );+ }+}diff --git a/crates/wake-core/tests/common/mod.rs b/crates/wake-core/tests/common/mod.rsindex 55f4851..7814c1d 100644--- a/crates/wake-core/tests/common/mod.rs+++ b/crates/wake-core/tests/common/mod.rs@@ -8,6 +8,33 @@ use std::fs;use std::path::{Path, PathBuf};use wake_core::db::{IndexLock, Ownership};+use wake_core::models::{AgentId, SessionMeta};++/// 一条最小的会话元数据(Claude Code、无模型无 token);测试按需用 `..meta(..)` 改字段。+/// SessionMeta 没有 Default,新字段只补这一处+pub fn meta(key: &str, title: &str) -> SessionMeta {+ SessionMeta {+ host: String::new(),+ key: key.to_string(),+ id: key.split(':').nth(1).unwrap_or(key).to_string(),+ agent: AgentId::ClaudeCode,+ title: title.to_string(),+ project_path: "/tmp/proj".into(),+ project_name: "proj".into(),+ file_path: format!("/tmp/fixtures/{key}.jsonl"),+ created_at: 1_700_000_000_000,+ updated_at: 1_700_000_100_000,+ message_count: 2,+ size_bytes: 128,+ git_branch: None,+ model: None,+ tokens_used: None,+ archived: false,+ source: None,+ favorite: false,+ pinned: false,+ }+}/// dsh 默认落盘的 zstd 多帧日志:首帧 header 行、次帧事件批,帧直接连接(写端每次 append/// 一帧,解码器解到 EOF)diff --git a/crates/wake-core/tests/db_roundtrip.rs b/crates/wake-core/tests/db_roundtrip.rsindex a80f92e..3e015bc 100644--- a/crates/wake-core/tests/db_roundtrip.rs+++ b/crates/wake-core/tests/db_roundtrip.rs@@ -8,6 +8,7 @@ use wake_core::db::{self, IndexLock, Ownership, Store, Wait};use wake_core::models::*;mod common;+use common::meta;fn temp_store() -> (tempfile::TempDir, Store) {let dir = tempfile::tempdir().expect("tempdir");@@ -15,30 +16,6 @@ fn temp_store() -> (tempfile::TempDir, Store) {(dir, store)}-fn meta(key: &str, title: &str) -> SessionMeta {- SessionMeta {- host: String::new(),- key: key.to_string(),- id: key.split(':').nth(1).unwrap_or(key).to_string(),- agent: AgentId::ClaudeCode,- title: title.to_string(),- project_path: "/tmp/proj".into(),- project_name: "proj".into(),- file_path: format!("/tmp/fixtures/{key}.jsonl"),- created_at: 1_700_000_000_000,- updated_at: 1_700_000_100_000,- message_count: 2,- size_bytes: 128,- git_branch: None,- model: None,- tokens_used: None,- archived: false,- source: None,- favorite: false,- pinned: false,- }-}-fn unit(seq: i64, role: Role, text: &str) -> IndexUnit {IndexUnit {seq,diff --git a/crates/wake/locales/zh-Hans.json b/crates/wake/locales/zh-Hans.jsonindex f3ece81..66791be 100644--- a/crates/wake/locales/zh-Hans.json+++ b/crates/wake/locales/zh-Hans.json@@ -492,5 +492,10 @@"Choose the language Wake uses.": "选择 Wake 的界面语言。","Theme": "主题","Its branch stays and shows the whole conversation.": "它的分支会留下,显示完整的对话。",- "Its {} branches stay and show the whole conversation.": "它的 {} 个分支会留下,显示完整的对话。"+ "Its {} branches stay and show the whole conversation.": "它的 {} 个分支会留下,显示完整的对话。",+ "Add to ~/.codex/config.toml, then approve it in /hooks": "加进 ~/.codex/config.toml,再在 Codex 的 /hooks 里批准",+ "Claude Code plugin": "Claude Code 插件",+ "Codex hooks": "Codex Hooks",+ "Run in a terminal to install the Wake plugin": "在终端里运行,安装 Wake 插件",+ "Copy the command that adds wake-cli to PATH": "拷贝把 wake-cli 加进 PATH 的命令"}diff --git a/crates/wake/src/i18n.rs b/crates/wake/src/i18n.rsindex 4c775f4..fa03d81 100644--- a/crates/wake/src/i18n.rs+++ b/crates/wake/src/i18n.rs@@ -648,10 +648,16 @@ mod tests {/// (`t(s.hint)` / `t(s.copy_label)`),所以这些 key 的英文原文不在 UI 源码里,/// 而在 `setup_snippets` 里。**不要把它们塞进 `assembled_elsewhere`**——/// wake-core 不参与 i18n,可以随时改这些字面量,恰恰最需要棘轮看着;- /// 这里直接问那个 API,改了名就在这里红,而不是变成一条静默的死译文+ /// 这里直接问那个 API,改了名就在这里红,而不是变成一条静默的死译文。开场上下文的两块+ /// 在 Windows 上不显示,但片段函数不分平台、语言包也不分平台,所以这里照列fn from_wake_core(key: &str) -> bool {- wake_core::mcp::setup_snippets(std::path::Path::new("x"))- .iter()+ let x = std::path::Path::new("x");+ wake_core::mcp::setup_snippets(x)+ .into_iter()+ .chain([+ wake_core::cli::claude_plugin_snippet(),+ wake_core::cli::codex_hooks_snippet(x),+ ]).any(|s| s.hint == key || s.copy_label == key)}diff --git a/crates/wake/src/settings.rs b/crates/wake/src/settings.rsindex a442f37..5b89a08 100644--- a/crates/wake/src/settings.rs+++ b/crates/wake/src/settings.rs@@ -33,6 +33,10 @@ const SETTINGS_PAGE_TOP: Zpx = Zpx(38.);/// Connect 页两条 Setup guide 的去处:MCP 面与命令行面各自的完整文档const CONNECT_GUIDE_URL: &str = "https://github.com/iAmCorey/Wake/blob/main/docs/mcp.md";const CONNECT_CLI_GUIDE_URL: &str = "https://github.com/iAmCorey/Wake/blob/main/docs/cli.md";+const CONNECT_PLUGIN_GUIDE_URL: &str =+ "https://github.com/iAmCorey/Wake/blob/main/docs/cli.md#claude-code-plugin";+const CONNECT_CODEX_HOOKS_GUIDE_URL: &str =+ "https://github.com/iAmCorey/Wake/blob/main/docs/cli.md#codex-hooks";fn icon(path: &'static str) -> Icon {Icon::empty().path(path)@@ -230,6 +234,10 @@ struct ConnectInfo {/// MCP clients 卡的三行:文案与片段来自 wake-core,与 `wake-mcp setup`/// 同源;GUI 只展示与复制,不代写别家配置snippets: Vec<wake_core::mcp::SetupSnippet>,+ /// Claude Code plugin 与 Codex hooks 两块各一行,与 `wake-cli setup` 同源;这个平台不给+ /// (`cli::SESSION_START_HOOKS` 为假,即 Windows)时是 None,两块都不画+ claude_plugin: Option<wake_core::mcp::SetupSnippet>,+ codex_hooks: Option<wake_core::mcp::SetupSnippet>,}impl ConnectInfo {@@ -238,6 +246,10 @@ impl ConnectInfo {let cli = BinaryFacts::probe("wake-cli");Self {snippets: wake_core::mcp::setup_snippets(std::path::Path::new(&mcp.path)),+ claude_plugin: wake_core::cli::SESSION_START_HOOKS+ .then(wake_core::cli::claude_plugin_snippet),+ codex_hooks: wake_core::cli::SESSION_START_HOOKS+ .then(|| wake_core::cli::codex_hooks_snippet(std::path::Path::new(&cli.path))),cli_path_command: wake_core::cli::path_command(std::path::Path::new(&cli.path)),mcp,cli,@@ -253,7 +265,7 @@ pub(crate) struct SettingsView {connect: ConnectInfo,/// Connect 页里展开了代码片段的行(按 snippets 下标);Settings 重开即复位connect_shown: std::collections::HashSet<usize>,- /// 刚复制过的按钮 id:按钮原地显示 "Copied" 1.6s。不用 toast——gpui-component 的+ /// 刚复制过的按钮 id:图标原地变对勾(tooltip 说 Copied)1.6s。不用 toast——gpui-component 的/// 通知在窗口失活或被悬停时会暂停自动关闭,Settings 这种从属窗里它常常就/// 挂着不走(用户 2026-09-08 反馈);主界面的 Copy Session ID / Copy code 也/// 从不弹通知@@ -820,30 +832,35 @@ impl SettingsView {)}- /// Settings → Connect 的复制按钮:写剪贴板,按钮原地变 "Copied" 片刻后复原+ /// Settings → Connect 的复制钮:只有图标,说明在 tooltip——卡上已经摆着要复制的东西或+ /// 一句用法,按钮再写一遍 "Copy path" / "Copy command" 是重复(用户 2026-10-09 定,整页+ /// 统一)。写剪贴板后图标原地变对勾、tooltip 说 Copied,1.6s 复原fn copy_button(&self,id: SharedString,- label: &'static str,+ tooltip: &'static str,+ text: String,+ cx: &Context<Self>,+ ) -> Button {+ self.copy_button_with("icons/copy.svg", id, tooltip, text, cx)+ }++ /// 同一张卡上的第二个复制钮换个字形:wake-cli 卡的路径与"放进 PATH"的命令并排,+ /// 两个一样的图标分不清+ fn copy_button_with(+ &self,+ glyph: &'static str,+ id: SharedString,+ tooltip: &'static str,text: String,cx: &Context<Self>,) -> Button {let copied = self.copied.as_ref() == Some(&id);let clicked_id = id.clone();- settings_button(- Button::new(id)- .icon(- icon(if copied {- "icons/check.svg"- } else {- "icons/copy.svg"- })- .with_size(zpx(13.)),- )- .label(if copied { t("Copied") } else { label }),- cx,- )- .on_click(cx.listener(move |this, _, _, cx| {+ let button = Button::new(id)+ .icon(icon(if copied { "icons/check.svg" } else { glyph }).with_size(zpx(13.)))+ .tooltip(if copied { t("Copied") } else { tooltip });+ settings_button(button, cx).on_click(cx.listener(move |this, _, _, cx| {cx.write_to_clipboard(ClipboardItem::new_string(text.clone()));this.show_copied(clicked_id.clone(), cx);}))@@ -869,11 +886,11 @@ impl SettingsView {.detach();}- /// Settings → Connect:把 Wake 的索引以 MCP 只读暴露给 coding agent。页面只放- /// **状态与动作**:server 卡(路径 + Copy path)、Agents 卡(每家一行一个- /// Copy 钮)、一句 caption 加 Setup guide 链接。代码块与工具表都不放——那是- /// README 的内容,塞进设置窗怎么排都像教程(用户 2026-09-08 三轮定稿)。- /// 只展示与复制,不代写别家配置;片段与 `wake-mcp setup` 同源(wake-core mcp)+ /// Settings → Connect:把 Wake 的索引只读接给 coding agent。页面只放**状态与动作**:+ /// 每块一张卡(二进制路径、一句用法或每家一行)+ 只有图标的复制钮,区块标题右端挂+ /// Setup guide。代码块与工具表都不放——那是 README 的内容,塞进设置窗怎么排都像教程+ /// (用户 2026-09-08 三轮定稿)。只展示与复制,不代写别家配置;片段与 `wake-mcp setup` /+ /// `wake-cli setup` 同源(wake-core 的 mcp / cli)fn render_connect(&mut self, cx: &mut Context<Self>) -> AnyElement {let theme = cx.theme();let dark = theme.mode.is_dark();@@ -1009,7 +1026,7 @@ impl SettingsView {settings_info_card(primary,mono_details(f.display.clone(), f.exists),- // Copy path 恒在最右,两张卡的同名动作才对得齐;附加动作放它左边+ // 复制路径的钮恒在最右,两张卡的同一个动作才对得齐;附加动作放它左边h_flex().flex_shrink_0().gap(SPACE_SM)@@ -1020,11 +1037,13 @@ impl SettingsView {zpx(84.),cx,)+ .into_any_element()};let copy_cli_command = info.cli_path_command.clone().map(|cmd| {- self.copy_button(+ self.copy_button_with(+ "icons/terminal.svg","connect-copy-cli-command".into(),- t("Copy command"),+ t("Copy the command that adds wake-cli to PATH"),cmd,cx,)@@ -1043,6 +1062,19 @@ impl SettingsView {zpx(84.),cx,);+ // 一行卡:区块标题已经点了名,卡里只放一句怎么用 + 复制钮(用户 2026-10-09:名字行+ // 多余、两行没必要、一张等宽一张正文挨着太杂;命令在复制钮里,不必摆出来)+ let one_line_card = |s: &wake_core::mcp::SetupSnippet, id: &'static str| {+ settings_info_card(+ t(s.hint),+ Vec::new(),+ self.copy_button(id.into(), t(s.copy_label), s.text.clone(), cx)+ .into_any_element(),+ zpx(48.),+ cx,+ )+ .into_any_element()+ };let section = |label: &'static str| {div()@@ -1054,7 +1086,7 @@ impl SettingsView {};// 区块标题右侧的文档链接:MCP 面与命令行面各链自己那份,页尾只放一条// 会让读 CLI 那半页的人点进 MCP 的参考里。设置窗里不放文档,所以这页- // 只有状态、动作与这两个去处,没有解释性的散文(用户 2026-09-11 定)+ // 只有状态、动作与这几个去处,没有解释性的散文(用户 2026-09-11 定)let titled = |label: &'static str, guide: Option<(&'static str, &'static str)>| {h_flex().flex_shrink_0()@@ -1073,47 +1105,81 @@ impl SettingsView {}))};- // 四个区块同一种写法,有没有文档链接写在参数里,不靠两种拼法- // 区分。规则一句话:**每个面的第一个区块挂自己的文档**——- // MCP 面 = MCP server + MCP clients,命令行面 = Command line- // + Skill,所以链接落在第一、第三块上。第五个区块该不该有- // 链接,照这条判就行,不用再拍脑袋- let rows = [- titled(+ // 区块同一种写法:(标题, 文档链接, 卡),有没有链接、有没有这块都写在数据里,+ // 间距一律"不是第一块就加",不靠各块自己记。链接的规则一句话:**每个面的第一个+ // 区块挂自己的文档**——Claude Code plugin、Codex hooks 各是一面,MCP 面 = MCP server+ // + MCP clients,命令行面 = Command line + Skill。两家的开场上下文放最前:插件一条+ // 命令就把 MCP 与开场上下文一起装好,是最省事的那条路。标题用各家的正名(用户+ // 2026-10-09 定:不自己起名字;Codex 那个是它官方的 hooks,不是插件);这两块+ // Windows 上没有(片段给 None)+ let sections = [+ (+ t("Claude Code plugin"),+ Some(("connect-plugin-setup-guide", CONNECT_PLUGIN_GUIDE_URL)),+ info.claude_plugin+ .as_ref()+ .map(|s| one_line_card(s, "connect-copy-plugin")),+ ),+ (+ t("Codex hooks"),+ Some((+ "connect-codex-hooks-setup-guide",+ CONNECT_CODEX_HOOKS_GUIDE_URL,+ )),+ info.codex_hooks+ .as_ref()+ .map(|s| one_line_card(s, "connect-copy-codex-hooks")),+ ),+ (t("MCP server"),Some(("connect-setup-guide", CONNECT_GUIDE_URL)),- )- .into_any_element(),- binary_card("wake-mcp", "connect-copy-path", &info.mcp, None).into_any_element(),- titled(t("MCP clients"), None)- .pt(SPACE_LG)- .into_any_element(),- v_flex()- .w_full()- .flex_shrink_0()- .overflow_hidden()- .rounded(theme.radius_lg)- .border_1()- .border_color(theme.border)- .bg(theme.popover)- .children(agent_rows)- .into_any_element(),- titled(+ Some(binary_card(+ "wake-mcp",+ "connect-copy-path",+ &info.mcp,+ None,+ )),+ ),+ (+ t("MCP clients"),+ None,+ Some(+ v_flex()+ .w_full()+ .flex_shrink_0()+ .overflow_hidden()+ .rounded(theme.radius_lg)+ .border_1()+ .border_color(theme.border)+ .bg(theme.popover)+ .children(agent_rows)+ .into_any_element(),+ ),+ ),+ (t("Command line"),Some(("connect-cli-setup-guide", CONNECT_CLI_GUIDE_URL)),- )- .pt(SPACE_LG)- .into_any_element(),- binary_card(- "wake-cli",- "connect-copy-cli-path",- &info.cli,- copy_cli_command,- )- .into_any_element(),- titled(t("Skill"), None).pt(SPACE_LG).into_any_element(),- skill_card.into_any_element(),+ Some(binary_card(+ "wake-cli",+ "connect-copy-cli-path",+ &info.cli,+ copy_cli_command,+ )),+ ),+ (t("Skill"), None, Some(skill_card.into_any_element())),];+ let rows = sections+ .into_iter()+ .filter_map(|(title, guide, card)| card.map(|card| (title, guide, card)))+ .enumerate()+ .flat_map(|(ix, (title, guide, card))| {+ [+ titled(title, guide)+ .when(ix > 0, |this| this.pt(SPACE_LG))+ .into_any_element(),+ card,+ ]+ });Self::rows_page("settings-connect-scroll",t("Connect"),diff --git a/docs/cli.md b/docs/cli.mdindex 61b7de0..d5bb0fb 100644--- a/docs/cli.md+++ b/docs/cli.md@@ -35,6 +35,7 @@ wake-cli show KEY [OPTIONS]wake-cli projects [OPTIONS]wake-cli memories [OPTIONS]wake-cli setup+wake-cli contextwake-cli indexwake-cli refreshwake-cli --help | --version@@ -117,68 +118,24 @@ wake-cli show 'wake://memory/claude-code:/Users/me/.claude/projects/-Users-me-apPrints this binary's path, the index path, how to put it on your `PATH`, a paste-able block that tells an agent when and how to use it, and — when `wake-mcp` sits next to it — the one-line MCP setup for Claude Code. It installs nothing and never edits another tool's config files. The one thing it can write is Wake's own: resolving the default index path creates Wake's data directory and migrates an index left by the old `vibex` builds (`--db` skips that).-To make this automatic instead of per-project, install the skill (next section).+To make this automatic instead of per-project, install the skill (see [Teaching an agent to use it](#teaching-an-agent-to-use-it)).-## Teaching an agent to use it--Two ways to teach it, same content — and a third that skips the teaching by handing the-agent this project's recent sessions before it asks.+### `context`-**A skill, once, for every project** — the repository ships one at `skills/wake/`:+Prints the recent sessions of the project the current directory belongs to — up to five+from the last 14 days, in the same lines `sessions` uses — and nothing at all when there+are none:```bash-npx skills add iAmCorey/Wake-```--That works for Claude Code, Codex and anything else that reads the skills format. To do-it by hand, copy `skills/wake/` into `~/.claude/skills/wake/`. The skill tells the agent-*when* to look back — earlier conversations, past decisions, where work stopped, whether-an error has been seen before — and how to read keys, references and pages.--**A paste block, for one project** — `wake-cli setup` prints a short version you can drop-into that project's `CLAUDE.md` or `AGENTS.md`. Use this when you would rather not-install anything, or want the guidance to live in the repository.--**Automatically, at session start (Claude Code)** — a `SessionStart` hook runs a command-when a session begins and hands its output to the agent as context. This one lists the-project's recent sessions, so the agent already knows what happened here before you say-"continue from yesterday":--```json-{- "hooks": {- "SessionStart": [- {- "matcher": "startup|resume",- "hooks": [- {- "type": "command",- "command": "wake-cli sessions --project \"$CLAUDE_PROJECT_DIR\" --limit 5 --since 14d 2>/dev/null || true",- "timeout": 30- }- ]- }- ]- }-}+cd ~/Github/my-app && wake-cli context```-Put it in `~/.claude/settings.json` to get it in every project, or in a project's-`.claude/settings.json`. A few things to know:--- If `wake-cli` is not on your `PATH`, use its full path (see *Where it lives*).-- Keep the trailing `|| true`. A hook that exits `2` stops the session from starting, and- `wake-cli` exits `2` when there is no index yet.-- What gets injected is titles, keys and dates — a handful of lines, not transcripts. The- agent still reads a session with `show` when it needs the details.-- `startup|resume` skips `/clear` and compaction; drop the matcher to run on those too.-- A lookup made by the hook is not the agent asking Wake, so it does not show up in- Insights under *Agents asking Wake*; the lookups the agent then makes on its own do.-- Only Claude Code has this hook. Codex and Gemini CLI have no equivalent, so there the- skill is the way in.+It is what the [Claude Code plugin](#claude-code-plugin) and the [Codex hooks](#codex-hooks) setup run: whatever the hook+prints lands in the new session's context, where a "no sessions" reply or a list of other+projects would only be noise. A subfolder counts as its project, as with `--project+"$PWD"`. Your home folder and the filesystem root never count as the project a folder+belongs to — sessions started there are not about the project you open next.-None of the three writes to another tool's configuration; Wake only ever prints, and the-hook is yours to add.### `index`@@ -295,6 +252,110 @@ Two things to know:- Ten minutes is a sensible interval: a refresh with nothing new takes well under a second,and every reply already says how fresh the index is.+## Teaching an agent to use it++Two ways to teach it, same content. To hand every new session this project's recent+sessions before the agent even asks, see [Claude Code plugin](#claude-code-plugin) and+[Codex hooks](#codex-hooks).++**A skill, once, for every project** — the repository ships one at `skills/wake/`:++```bash+npx skills add iAmCorey/Wake+```++That works for Claude Code, Codex and anything else that reads the skills format. To do+it by hand, copy `skills/wake/` into `~/.claude/skills/wake/`. The skill tells the agent+*when* to look back — earlier conversations, past decisions, where work stopped, whether+an error has been seen before — and how to read keys, references and pages.++**A paste block, for one project** — `wake-cli setup` prints a short version you can drop+into that project's `CLAUDE.md` or `AGENTS.md`. Use this when you would rather not+install anything, or want the guidance to live in the repository.++## Claude Code plugin++The Wake plugin starts every new Claude Code session with this project's recent sessions+already in its context — from Claude Code, Codex and every other agent Wake indexes — so+"continue from yesterday" needs no explaining, and it adds Wake's MCP tools so Claude can+open any of them with `wake_get_session`. Underneath it is a session-start hook that runs+[`wake-cli context`](#context), which prints nothing in a project without recent history.+It needs Wake 0.8.9 or later and covers macOS and Linux. Settings → Connect shows the+command with a Copy button.++```bash+claude plugin marketplace add iAmCorey/Wake && claude plugin install wake@wake+```++Inside a session, `/plugin marketplace add iAmCorey/Wake` and then `/plugin install+wake@wake` do the same. The plugin carries no binaries of its own: it runs the `wake-cli`+and `wake-mcp` inside your installed Wake (set `WAKE_BIN_DIR` to their folder if Wake+lives somewhere other than the usual place). If you added the `wake` MCP server by hand+earlier, remove it with `claude mcp remove wake` so the tools are not listed twice.+`claude plugin update wake@wake` updates it, or turn on auto-update for the `wake`+marketplace in `/plugin`.++**Without the plugin**, the same hook goes in `~/.claude/settings.json` (every project) or+in a project's `.claude/settings.json`; add the MCP server as [docs/mcp.md](mcp.md#claude-code)+shows:++```json+{+ "hooks": {+ "SessionStart": [+ {+ "matcher": "startup|clear",+ "hooks": [+ {+ "type": "command",+ "command": "wake-cli context 2>/dev/null || true",+ "timeout": 30+ }+ ]+ }+ ]+ }+}+```++Use `wake-cli`'s full path if it is not on your `PATH` (see *Where it lives*).++## Codex hooks++Codex gets the same start through its own [hooks](https://developers.openai.com/codex/hooks).+Add this to `~/.codex/config.toml` — Settings → Connect shows it with your path to+`wake-cli` filled in:++```toml+[[hooks.SessionStart]]+matcher = "startup|clear"++[[hooks.SessionStart.hooks]]+type = "command"+command = "/Applications/Wake.app/Contents/MacOS/wake-cli context 2>/dev/null || true"+timeout = 30+```++Codex runs a hook you added only after you approve it: start Codex and open `/hooks`. For+Wake's tools in Codex, add the MCP server as [docs/mcp.md](mcp.md#codex) shows. There is no+Codex plugin: Codex runs a plugin's hooks only when the plugin was installed by hand in its+desktop app, and a plugin's MCP server has to be a remote one, so a plugin could not do this+from the command line. Like the Claude Code plugin, this needs Wake 0.8.9 or later and covers+macOS and Linux.++For both:++- What gets injected is titles, keys, dates and models for up to five sessions — not+ transcripts. The agent reads one with `wake_get_session` or `wake-cli show` when it needs+ the details.+- `startup|clear` covers new sessions and `/clear`. A resumed or compacted session keeps+ its own history, so the hook stays out of those.+- A lookup made by the hook is not the agent asking Wake, so it does not show up in+ Insights under *Agents asking Wake*; the lookups the agent then makes on its own do.+- None of this edits another tool's configuration: Claude Code installs its own plugin,+ and the hook settings are yours to paste.+- On Windows, use the skill and the MCP server for now.+## When`--since` accepts a relative window — `30m`, `24h`, `7d`, `2w` — or an absolute date/time: `2026-09-01`, `"2026-09-01 09:30"`, `2026-09-01T09:30:00Z`. Date-times without a zone are read in local time.@@ -329,7 +390,7 @@ Exactly one trailing newline is added when the text does not already end with on| `1` | it ran and failed — unknown or ambiguous key, a transcript that would not parse, a query that errored, or a failed write to stdout || `2` | the command line was wrong, or the index is missing / unreadable / too old |-Empty results are never an error, so `wake-cli search x || fallback` does not fire just because nothing was ever discussed about `x`. Diagnostics go to stderr, prefixed `wake-cli: `, so `wake-cli show <key> > out.md` cannot capture one. Two commands treat a missing index as normal rather than as the `2` above. `setup` always exits `0`, even with no index, and reports a missing one as a `Note:` line on stdout — "not set up yet" is the normal state for someone running it. `index` exits `0` both when it builds one and when it declines because one already exists or because Wake or another writer holds the index; a build that starts and then fails exits `1`. `refresh` exits `0` when it updates the index and when it declines because Wake or another writer holds the index; it exits `2` when there is no index, when `--db` is not a Wake index, or when the index holds remote-host sessions or memories whose mirrors are not next to that path (a copy or an alias in another directory); a scan that starts and then fails exits `1`.+Empty results are never an error, so `wake-cli search x || fallback` does not fire just because nothing was ever discussed about `x`. Diagnostics go to stderr, prefixed `wake-cli: `, so `wake-cli show <key> > out.md` cannot capture one. Two commands treat a missing index as normal rather than as the `2` above. `setup` always exits `0`, even with no index, and reports a missing one as a `Note:` line on stdout — "not set up yet" is the normal state for someone running it. `index` exits `0` both when it builds one and when it declines because one already exists or because Wake or another writer holds the index; a build that starts and then fails exits `1`. `context` exits `0` and prints nothing when the folder has no recent sessions or belongs to no indexed project. `refresh` exits `0` when it updates the index and when it declines because Wake or another writer holds the index; it exits `2` when there is no index, when `--db` is not a Wake index, or when the index holds remote-host sessions or memories whose mirrors are not next to that path (a copy or an alias in another directory); a scan that starts and then fails exits `1`.Both a mistyped option (`--sinse 7d`) and a value the tools reject (`--since 7dd`) exit `2` — from a user's seat they are the same mistake, and the layer that caught it is not visible. This is a deliberate difference from `wake-mcp call`, which exits `1` for anything the tool layer rejects — its JSON-RPC envelope already carries the classification, so the exit code never had to. (`wake-mcp` still uses `2` for its own argv problems: a missing tool name, unparsable JSON, or an index it cannot open.)diff --git a/docs/mcp.md b/docs/mcp.mdindex da5727e..9ef362c 100644--- a/docs/mcp.md+++ b/docs/mcp.md@@ -12,7 +12,7 @@ It covers everything Wake indexes: sessions from every supported agent on this m| Linux | next to `wake`: `~/.local/bin/wake-mcp` (tar.gz install) or `/usr/bin/wake-mcp` (deb) || Windows | next to `Wake.exe` in the unpacked zip |-Settings → Connect in Wake shows the exact path for your install with a *Copy path* button, and one *Copy command* / *Copy config* button per client (*Show* reveals the snippet before you copy it). `wake-mcp setup` prints the same snippets from a terminal. Updating Wake keeps the path, so there is nothing to redo after an update.+Settings → Connect in Wake shows the exact path for your install with a copy button next to it, and one copy button per client (*Show* reveals the snippet before you copy it). `wake-mcp setup` prints the same snippets from a terminal. Updating Wake keeps the path, so there is nothing to redo after an update.## Setup@@ -22,6 +22,11 @@ Settings → Connect in Wake shows the exact path for your install with a *Copyclaude mcp add --scope user wake -- "/Applications/Wake.app/Contents/MacOS/wake-mcp"```+Or install the Wake plugin instead, which adds this server and starts every new session with+the project's recent sessions — `claude plugin marketplace add iAmCorey/Wake && claude plugin+install wake@wake` (see [Claude Code plugin](cli.md#claude-code-plugin)). Use one or the other, not+both, or the tools are listed twice.+### CodexAdd to `~/.codex/config.toml`:@@ -85,9 +90,10 @@ Before asking me for context about this repository, check earlier sessions withwake_list_sessions with the current directory, then wake_get_session for the relevant one.```-Claude Code can also be handed the project's recent sessions automatically when a session-starts, through a `SessionStart` hook that runs `wake-cli` — see-[Automatically, at session start](cli.md#teaching-an-agent-to-use-it) in the command-line guide.+Claude Code and Codex can also be handed the project's recent sessions automatically when a+session starts, through a hook that runs `wake-cli context` — see+[Claude Code plugin](cli.md#claude-code-plugin) and [Codex hooks](cli.md#codex-hooks) in the+command-line guide. The Claude Code plugin brings this MCP server along.### A worked example@@ -131,7 +137,7 @@ All five tools are read-only and return Markdown text (`content[0].text`). Param| Parameter | Type | Meaning ||---|---|---|-| `project` | string | Scope to one project. Pass an absolute path — the agent's working directory is ideal — or a project name. Path matching is three-tier: an exact match of an indexed project path; otherwise the longest indexed project that contains the path (you are in a subdirectory); otherwise every indexed project below the path (a monorepo root or a parent folder). A bare name matches the project name case-insensitively. When nothing matches, the reply lists the known projects instead of erroring. |+| `project` | string | Scope to one project. Pass an absolute path — the agent's working directory is ideal — or a project name. Path matching is three-tier: an exact match of an indexed project path; otherwise the longest indexed project that contains the path (you are in a subdirectory) — your home folder and the filesystem root never count here, since sessions started there are not about the project you are in; otherwise every indexed project below the path (a monorepo root or a parent folder). A bare name matches the project name case-insensitively. When nothing matches, the reply lists the known projects instead of erroring. || `agents` | string[] | Only these agents. Ids: `claude-code`, `codex`, `grok`, `dsh`, `cursor`, `opencode`, `pi`, `omp`, `kiro`, `kimi`, `gemini`, `copilot`, `antigravity`, `qoder`, `hermes`, `openclaw`, `codebuddy`, `workbuddy`, `zcode`, `craft-agents`, `devin`, `kilo`. Display names (`"Claude Code"`, `"Gemini CLI"`) and a few aliases (`claude`, `deepseek`, `opencode2`, `craft`) are accepted too. || `since` | string | Only sessions updated at or after this time. Relative: `30m`, `24h`, `7d`, `2w`. Absolute: `2026-09-01`, `2026-09-01 09:30`, `2026-09-01T09:30:00Z`. Naive date-times are read in local time. || `limit` | integer | Maximum items to return; values outside the allowed range are clamped. |diff --git a/plugins/wake/.claude-plugin/plugin.json b/plugins/wake/.claude-plugin/plugin.jsonnew file mode 100644index 0000000..5dfbf36--- /dev/null+++ b/plugins/wake/.claude-plugin/plugin.json@@ -0,0 +1,13 @@+{+ "name": "wake",+ "displayName": "Wake",+ "description": "Every new session starts with this project's recent sessions, and Wake's MCP tools let Claude search and read any earlier session from any coding agent. Read-only; needs the Wake app.",+ "author": {+ "name": "Corey Chiu",+ "url": "https://github.com/iAmCorey"+ },+ "homepage": "https://github.com/iAmCorey/Wake",+ "repository": "https://github.com/iAmCorey/Wake",+ "license": "MIT",+ "keywords": ["sessions", "history", "memory", "context", "mcp"]+}diff --git a/plugins/wake/.mcp.json b/plugins/wake/.mcp.jsonnew file mode 100644index 0000000..ff1263c--- /dev/null+++ b/plugins/wake/.mcp.json@@ -0,0 +1,8 @@+{+ "mcpServers": {+ "wake": {+ "command": "sh",+ "args": ["${CLAUDE_PLUGIN_ROOT}/scripts/wake", "wake-mcp"]+ }+ }+}diff --git a/plugins/wake/hooks/hooks.json b/plugins/wake/hooks/hooks.jsonnew file mode 100644index 0000000..7e5bfec--- /dev/null+++ b/plugins/wake/hooks/hooks.json@@ -0,0 +1,16 @@+{+ "hooks": {+ "SessionStart": [+ {+ "matcher": "startup|clear",+ "hooks": [+ {+ "type": "command",+ "command": "sh \"${CLAUDE_PLUGIN_ROOT}/scripts/session-start\"",+ "timeout": 30+ }+ ]+ }+ ]+ }+}diff --git a/plugins/wake/scripts/session-start b/plugins/wake/scripts/session-startnew file mode 100755index 0000000..059a954--- /dev/null+++ b/plugins/wake/scripts/session-start@@ -0,0 +1,8 @@+#!/bin/sh+# SessionStart hook: prints this project's recent sessions, which Claude Code adds to the+# new session's context. `wake-cli context` prints nothing when the project has no recent+# sessions. When Wake is not installed or has no index yet, this stays quiet too — a hook+# should never get in the way of starting a session.+cd "${CLAUDE_PROJECT_DIR:-.}" 2>/dev/null || exit 0+sh "$(dirname "$0")/wake" wake-cli context 2>/dev/null+exit 0diff --git a/plugins/wake/scripts/wake b/plugins/wake/scripts/wakenew file mode 100755index 0000000..1c7182e--- /dev/null+++ b/plugins/wake/scripts/wake@@ -0,0 +1,24 @@+#!/bin/sh+# Runs one of the binaries that ship with the Wake app (wake-cli, wake-mcp) and passes+# the remaining arguments through. The plugin carries no binaries of its own: it uses+# the copy inside the installed app, so it is always the version the app's index needs.+#+# Looked up in order: $WAKE_BIN_DIR (set it when Wake lives somewhere else), the macOS+# app in /Applications or ~/Applications, the Linux install locations, then PATH.+name=$1+shift+for dir in "$WAKE_BIN_DIR" \+ /Applications/Wake.app/Contents/MacOS \+ "$HOME/Applications/Wake.app/Contents/MacOS" \+ "$HOME/.local/bin" \+ /usr/bin \+ /usr/local/bin; do+ if [ -n "$dir" ] && [ -x "$dir/$name" ]; then+ exec "$dir/$name" "$@"+ fi+done+if command -v "$name" >/dev/null 2>&1; then+ exec "$name" "$@"+fi+echo "Wake's $name was not found. Install Wake (https://github.com/iAmCorey/Wake), or set WAKE_BIN_DIR to the folder that holds it." >&2+exit 127