All your AI agent sessions in one place — browse, search, resume. Rust + GPUI.
Rust
feat: let a memory location be a <project>/… path (#67)
Corey Chiuaf1cfb7cf92c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 114d9ab..b25c8ea 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,6 +4,7 @@- Fix: Refresh picks up sessions you deleted in OpenCode while it was still running, instead of listing them until Wake restarts (#70, thanks @lin-code-world)- Fix: On Windows and Linux, adding a memory location offers a file picker next to the folder picker, so a single file no longer has to be typed in by hand (#68, thanks @lin-code-world)+- New: A memory location can be written as `<project>/CODEBUDDY.md`, like the built-in project files, to read that file or folder in every project (#67, thanks @lin-code-world)## [0.9.3] — 2026-10-13diff --git a/crates/wake-core/src/adapters/mod.rs b/crates/wake-core/src/adapters/mod.rsindex c98d739..d41ecf6 100644--- a/crates/wake-core/src/adapters/mod.rs+++ b/crates/wake-core/src/adapters/mod.rs@@ -148,19 +148,15 @@ pub trait AgentAdapter: Send + Sync {/// 缺根返回 Ok(空)、读失败报 Err(scanner 只冻结这些来源的行);scanner 在每轮/// 扫描收尾按 (agent, host) 整组替换入库,消失的文件随之出库。项目归属不在这里/// 算:填 `session_key` 指向所属会话,读库时按它连 sessions 表解析(见 MemoryDoc)。- /// 默认实现读通用形态(目录 / 文件 / 项目模式)、不缓存——没有自家记忆的 agent- /// 只有被用户加了自定义来源或有项目指令文件时才走到。远程装饰器必须转发并改写- /// key / host / session_key+ /// 默认实现读通用形态(目录 / 文件 / 项目模式),缓存用共用的 `SHARED_MEMORY_CACHE`——+ /// 没有自家记忆的 agent 只有被用户加了自定义来源或有项目指令文件时才走到。远程装饰器+ /// 必须转发并改写 key / host / session_keyfn list_memories(&self,sources: &[MemorySource],projects: &[std::path::PathBuf],) -> Result<Vec<MemoryDoc>> {- cached_memory_docs(- &MemoryCache::new(),- self.agent(),- &generic_units(sources, projects),- )+ generic_memory_docs(&SHARED_MEMORY_CACHE, self.agent(), sources, projects)}/// 本实例默认读记忆的来源(Settings → Memory locations 的行):按实例的根派生,/// 不看存不存在。项目模式(`<project>/CLAUDE.md` 一类)不在这里报——那是 agent 级@@ -807,7 +803,9 @@ fn unit_place(source: &MemorySource) -> Option<UnitPlace> {UnitPlace::Dir { dir: path, ext }}MemorySourceKind::File | MemorySourceKind::ProjectFile => UnitPlace::File(path),- MemorySourceKind::Custom => UnitPlace::Path { path, ext: "md" },+ MemorySourceKind::Custom | MemorySourceKind::ProjectCustom => {+ UnitPlace::Path { path, ext: "md" }+ }MemorySourceKind::ProjectTree | MemorySourceKind::ThreadDb => return None,})}@@ -1048,6 +1046,12 @@ pub(crate) struct MemoryCache(std::sync::Mutex<std::collections::HashMap<String, (i64, Vec<MemoryDoc>)>>,);+/// 没有自家缓存的 agent 共用的一份(默认 `list_memories`、scanner 里没有实例的那一家):+/// 用户加的 `<project>/…` 会在每个项目根下展开,不缓存就是每轮把匹配到的文件整份重读。+/// 槽按 agent + 来源分(`cached_memory_docs`),两家同名的来源不会互相顶替+pub(crate) static SHARED_MEMORY_CACHE: std::sync::LazyLock<MemoryCache> =+ std::sync::LazyLock::new(MemoryCache::new);+impl MemoryCache {pub(crate) fn new() -> Self {Self(std::sync::Mutex::new(std::collections::HashMap::new()))@@ -1146,11 +1150,12 @@ pub(crate) fn cached_memory_docs(units: &[MemoryUnit],) -> Result<Vec<MemoryDoc>> {use std::hash::{Hash as _, Hasher as _};- // 缓存槽按这次读的来源分:scanner 逐来源调,各来源的指纹互不干扰+ // 缓存槽按 agent + 这次读的来源分:scanner 逐来源调,各来源的指纹互不干扰;共用的+ // 那份缓存里两家可能有同名的来源(`<project>/AGENTS.md`)let mut key: Vec<&str> = units.iter().map(|u| u.source.as_str()).collect();key.sort_unstable();key.dedup();- let key = key.join("\n");+ let key = format!("{}\n{}", agent.as_str(), key.join("\n"));let mut listing: Vec<(&MemoryUnit, Vec<FileStamp>)> = Vec::new();let mut hasher = std::collections::hash_map::DefaultHasher::new();for unit in units {diff --git a/crates/wake-core/src/models.rs b/crates/wake-core/src/models.rsindex 9b48e65..89c834a 100644--- a/crates/wake-core/src/models.rs+++ b/crates/wake-core/src/models.rs@@ -900,6 +900,9 @@ pub enum MemorySourceKind {ProjectFile,/// 每个已索引的本地项目根下的一个目录:`<project>/<rel>/*.<ext>`ProjectDir { ext: &'static str },+ /// 用户添加的项目模式(`<project>/CODEBUDDY.md`):每个项目根下的这条路径,形状读时才看,+ /// 同 `Custom`(#67)+ ProjectCustom,}/// 记忆的一个来源 = Settings → Memory locations 的一行。各家 adapter 按自己的根报默认@@ -919,7 +922,9 @@ impl MemorySource {pub fn is_pattern(&self) -> bool {matches!(self.kind,- MemorySourceKind::ProjectFile | MemorySourceKind::ProjectDir { .. }+ MemorySourceKind::ProjectFile+ | MemorySourceKind::ProjectDir { .. }+ | MemorySourceKind::ProjectCustom)}@@ -933,7 +938,8 @@ impl MemorySource {}MemorySourceKind::ProjectTree| MemorySourceKind::ProjectFile- | MemorySourceKind::ProjectDir { .. } => MemoryScope::Project,+ | MemorySourceKind::ProjectDir { .. }+ | MemorySourceKind::ProjectCustom => MemoryScope::Project,MemorySourceKind::ThreadDb => MemoryScope::Thread,}}@@ -943,22 +949,53 @@ impl MemorySource {pub fn id(&self) -> String {let path = self.path.to_string_lossy();if self.is_pattern() {- format!("<project>/{path}")+ format!("{PROJECT_PATTERN}/{path}")} else {path.to_string()}}- /// 用户添加的来源(Settings → Memory locations 的 Add location):目录或文件,读时才看+ /// 用户添加的来源(Settings → Memory locations 的 Add location):目录或文件,读时才看;+ /// 写成 `<project>/…` 规范形的是项目模式。只认规范形:库里记的必须就是 `id()`,+ /// Settings 才能按它删改(表单存的就是 `project_pattern` 给的规范形)pub fn custom(agent: AgentId, path: std::path::PathBuf) -> Self {- Self {- agent,- kind: MemorySourceKind::Custom,- path,+ let raw = path.to_str();+ match raw.and_then(|raw| project_pattern(raw).filter(|canon| canon == raw)) {+ Some(canon) => Self {+ agent,+ kind: MemorySourceKind::ProjectCustom,+ path: std::path::PathBuf::from(&canon[PROJECT_PATTERN.len() + 1..]),+ },+ None => Self {+ agent,+ kind: MemorySourceKind::Custom,+ path,+ },}}}+/// 项目模式写法的开头:`<project>/CLAUDE.md` = 每个项目根下的 CLAUDE.md+pub const PROJECT_PATTERN: &str = "<project>";++/// `<project>/…` 写法的规范形:相对项目根的那段逐段都得是普通名字(`..`、盘符、根都不收,+/// 免得读到项目根外面去),一律用 `/` 连(Windows 上手输的 `\`、多余的分隔符都规整掉);+/// 不是这种写法给 None+pub fn project_pattern(text: &str) -> Option<String> {+ let rest = text.strip_prefix(PROJECT_PATTERN)?;+ if !rest.starts_with(std::path::is_separator) {+ return None;+ }+ let parts = std::path::Path::new(rest.trim_start_matches(std::path::is_separator))+ .components()+ .map(|c| match c {+ std::path::Component::Normal(part) => part.to_str(),+ _ => None,+ })+ .collect::<Option<Vec<_>>>()?;+ (!parts.is_empty()).then(|| format!("{PROJECT_PATTERN}/{}", parts.join("/")))+}+/// 用户记忆(对每个项目都成立)在一次筛选里怎么算——它是唯一带特殊语义的层级#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum UserMemories {diff --git a/crates/wake-core/src/scanner.rs b/crates/wake-core/src/scanner.rsindex 348c01d..d25ea60 100644--- a/crates/wake-core/src/scanner.rs+++ b/crates/wake-core/src/scanner.rs@@ -807,10 +807,9 @@ fn sync_memories(adapters: &[Box<dyn AgentAdapter>], store: &Arc<Store>) -> boollet one = std::slice::from_ref(&source);let read = match planned.adapter {Some(ix) => adapters[ix].list_memories(one, &projects),- // 该家没有本地实例(会话 location 全停用):项目指令文件与自定义路径照读;- // 没有实例就没处放缓存,这种配置少见、每轮重读+ // 该家没有本地实例(会话 location 全停用):项目指令文件与自定义路径照读None => crate::adapters::generic_memory_docs(- &crate::adapters::MemoryCache::new(),+ &crate::adapters::SHARED_MEMORY_CACHE,planned.agent,one,&projects,diff --git a/crates/wake-core/tests/adapter_contracts.rs b/crates/wake-core/tests/adapter_contracts.rsindex 5d80497..02fa08c 100644--- a/crates/wake-core/tests/adapter_contracts.rs+++ b/crates/wake-core/tests/adapter_contracts.rs@@ -6943,6 +6943,55 @@ fn zcode_lists_project_memories() {assert!(all_memories(&fresh).unwrap().is_empty());}+/// 用户在 Memory locations 里加的 `<project>/…`(#67):与内置的项目指令文件一样按每个项目根+/// 展开,形状读时才看(文件读它自己、目录读直属 *.md)。库里记的是 `project_pattern` 的规范形,+/// 也就是 `id()`——只认规范形,Settings 按 id 删改才对得上+#[test]+fn custom_project_patterns_expand_under_every_project() {+ setup();+ assert_eq!(+ project_pattern("<project>//.codebuddy/rules/").as_deref(),+ Some("<project>/.codebuddy/rules")+ );+ for bad in ["<project>/", "<project>/../x", "<project>CODEBUDDY.md"] {+ assert_eq!(project_pattern(bad), None, "{bad}");+ }+ let messy = MemorySource::custom(AgentId::Codebuddy, PathBuf::from("<project>//CODEBUDDY.md"));+ assert_eq!(+ messy.kind,+ MemorySourceKind::Custom,+ "不是规范形的照旧是具体路径"+ );++ let project = tempfile::tempdir().unwrap();+ fs::write(project.path().join("CODEBUDDY.md"), "# project rules\n").unwrap();+ let rules = project.path().join(".codebuddy").join("rules");+ fs::create_dir_all(&rules).unwrap();+ fs::write(rules.join("style.md"), "# style\n").unwrap();+ let ids = ["<project>/CODEBUDDY.md", "<project>/.codebuddy/rules"];+ let sources: Vec<MemorySource> = ids+ .iter()+ .map(|id| MemorySource::custom(AgentId::Codebuddy, PathBuf::from(id)))+ .collect();+ assert_eq!(+ sources.iter().map(MemorySource::id).collect::<Vec<_>>(),+ ids+ );+ let adapter = CodebuddyAdapter::new().with_custom_root(project.path().join("nowhere"));+ let docs = adapter+ .list_memories(&sources, &[project.path().to_path_buf()])+ .unwrap();+ let got: Vec<(&str, &str)> = docs+ .iter()+ .map(|d| (d.title.as_str(), d.source.as_str()))+ .collect();+ assert_eq!(got, [("CODEBUDDY.md", ids[0]), ("style.md", ids[1])]);+ let project_str = project.path().to_string_lossy();+ assert!(docs+ .iter()+ .all(|d| d.scope == MemoryScope::Project && d.project_path == project_str));+}+/// 记忆可见层二期:用户写给 agent 的指令文件也进记忆层——各家 home 里的全局文件/// (`~/.claude/CLAUDE.md`、`~/.codex/AGENTS.md` + `rules/*.rules`、`~/.gemini/GEMINI.md`)/// 由各家 `memory_sources` 报,项目根下的(CLAUDE.md / AGENTS.md / GEMINI.md /diff --git a/crates/wake/locales/zh-Hans.json b/crates/wake/locales/zh-Hans.jsonindex f246c0f..d93e239 100644--- a/crates/wake/locales/zh-Hans.json+++ b/crates/wake/locales/zh-Hans.json@@ -117,6 +117,7 @@"Enable host": "启用主机","Enable location": "启用位置","Enter an absolute folder path": "请输入绝对路径",+ "Enter an absolute path, or a path under <project>/": "请输入绝对路径,或 <project>/ 开头的项目内路径","Export failed": "导出失败","Exported": "已导出","Failed": "失败",diff --git a/crates/wake/src/settings.rs b/crates/wake/src/settings.rsindex 9cefca0..834f00d 100644--- a/crates/wake/src/settings.rs+++ b/crates/wake/src/settings.rs@@ -1582,7 +1582,7 @@ impl SettingsView {});}) as RowAction});- let reveal = (!row.pattern && row.exists).then(|| row.raw.clone());+ let reveal = row.reveal();let remove: Option<RowAction> = row.custom.then(|| {let workbench = workbench.clone();let (agent, stored) = (row.agent, row.raw.clone());diff --git a/crates/wake/src/workbench.rs b/crates/wake/src/workbench.rsindex a101018..5506072 100644--- a/crates/wake/src/workbench.rs+++ b/crates/wake/src/workbench.rs@@ -2486,6 +2486,13 @@ pub(crate) struct MemoryLocationRow {pub(crate) enabled: bool,}+impl MemoryLocationRow {+ /// Show in Finder 挂的路径:具体路径且当下存在才有(项目模式不对应某一个路径)+ pub(crate) fn reveal(&self) -> Option<SharedString> {+ (self.exists && !self.pattern).then(|| self.raw.clone())+ }+}+#[derive(Clone)]pub(crate) struct MemoryLocationSettingsSnapshot {pub(crate) rows: Vec<MemoryLocationRow>,@@ -3944,13 +3951,8 @@ impl Workbench {/// 先判、只判一次(is_absolute 三端同判据,空串它也判 false;**必须判在剪尾之前**:/// `//` 剪完是空串,拿剪后的去判会退回未剪形态放行,2026-08-25 review);尾分隔符/// 剪掉(展示与重叠判定都吃这份),裸根("/"、"C:\")剪完会失去绝对性、原样保留。- /// 不是绝对路径就弹提示、给 None- fn absolute_form_path(- &self,- raw: &str,- window: &mut Window,- cx: &mut Context<Self>,- ) -> Option<String> {+ /// 不是绝对路径给 None,提示由调用方弹+ fn absolute_form_path(raw: &str) -> Option<String> {let expanded = expand_tilde(raw.trim());let expanded = if cfg!(target_os = "windows") {expanded.replace('/', "\\")@@ -3958,10 +3960,6 @@ impl Workbench {expanded};if !std::path::Path::new(&expanded).is_absolute() {- window.push_notification(- Notification::warning(t("Enter an absolute folder path")),- cx,- );return None;}let trimmed = expanded.trim_end_matches(std::path::is_separator);@@ -3983,7 +3981,11 @@ impl Workbench {window: &mut Window,cx: &mut Context<Self>,) -> bool {- let Some(path) = self.absolute_form_path(&raw_text, window, cx) else {+ let Some(path) = Self::absolute_form_path(&raw_text) else {+ window.push_notification(+ Notification::warning(t("Enter an absolute folder path")),+ cx,+ );return false;};// 各家归一化(codex:直选 sessions 树/平铺 archived 上提到家层,侧档@@ -4294,7 +4296,7 @@ impl Workbench {init_agent: row.agent,init_path: row.raw.clone(),pick_files: true,- reveal: row.exists.then(|| row.raw.clone()),+ reveal: row.reveal(),remove: Some(Rc::new(move |this, window, cx| {this.delete_memory_source(remove_old.0, remove_old.1.clone(), window, cx)})),@@ -4317,7 +4319,18 @@ impl Workbench {window: &mut Window,cx: &mut Context<Self>,) -> bool {- let Some(path) = self.absolute_form_path(&raw_text, window, cx) else {+ // `<project>/…` 是项目模式(#67):存规范形,与 `MemorySource::id()` 同一个写法+ let raw = raw_text.trim();+ let path = if raw.starts_with(PROJECT_PATTERN) {+ project_pattern(raw)+ } else {+ Self::absolute_form_path(raw)+ };+ let Some(path) = path else {+ window.push_notification(+ Notification::warning(t("Enter an absolute path, or a path under <project>/")),+ cx,+ );return false;};if old@@ -4326,17 +4339,14 @@ impl Workbench {{return true;}- // 与面板同一份来源清单查重:该家的默认具体路径(项目模式不算)与已有的自定义+ // 与面板同一份来源清单查重(按来源 id:具体路径就是路径,项目模式是 `<project>/…`):+ // 该家的默认来源与已有的自定义let (customs, disabled) = self.store.memory_source_overrides().unwrap_or_default();let duplicate =wake_core::adapters::memory_source_plan(&self.adapters, &customs, &disabled).into_iter().flat_map(|p| p.sources)- .any(|p| {- p.source.agent == agent_new- && !p.source.is_pattern()- && p.source.path.to_string_lossy() == path- });+ .any(|p| p.source.agent == agent_new && p.source.id() == path);if duplicate {window.push_notification(Notification::info(t("This path is already in Wake's memory locations")),