From 59a2a1ca6d588cd0e8e16f79ccb4d166b814ef17 Mon Sep 17 00:00:00 2001 From: quangdang46 Date: Wed, 3 Jun 2026 14:26:25 +0700 Subject: [PATCH] feat(palace): add MemoryScope::All and Wing/Room variants (jcode shape) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit jcode's `MemoryScope::All` does a fan-out across project + global palaces in one call, and jcode adapters commonly need to scope a remember/forget to a specific wing or (wing, room) tuple. mempalace's existing `MemoryScope` enum has only `{Local, Global, Auto}` — none of which match jcode's `{Project, Global, All}` semantics. Add three new variants to the `MemoryScope` enum (non-breaking): - `All` — fan out to local + global palaces - `Wing(String)` — limit to a specific wing - `Room { wing, room }` — limit to a specific (wing, room) Add three helper methods on the enum (mirroring jcode's API): - `includes_project()` — true for Local/Auto/All/Wing/Room - `includes_global()` — true for Global/All - `is_all()` — true for All Note: `Wing` and `Room` are conceptually local-palace-only (named scopes don't span multiple palaces), so they return `true` for `includes_project` and `false` for `includes_global`. The `Copy` derive is removed because the new `Wing(String)` and `Room { wing, room }` variants can't be `Copy`. `Clone` is added. This is technically a breaking change for code that matched on the enum by value (e.g. `match scope { ... }` would still work, but `let x = scope; let y = scope;` would now require an explicit `.clone()`). The trait's other call sites already pass by reference. This is PR 3/8 in the jcode → mempalace Mode C library migration series. Independent of the trait-method PRs (1/2/4) — pure enum extension. Co-Authored-By: Claude Opus 4.8 --- crates/core/src/palace.rs | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/crates/core/src/palace.rs b/crates/core/src/palace.rs index 0f31326..a05914e 100644 --- a/crates/core/src/palace.rs +++ b/crates/core/src/palace.rs @@ -218,7 +218,7 @@ impl SearchScope { /// /// Used by the library API to disambiguate reads that could touch either /// the global palace or the project-local palace. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Default)] #[non_exhaustive] pub enum MemoryScope { /// Read/write only the project-local palace (from @@ -230,6 +230,43 @@ pub enum MemoryScope { /// Default for standalone CLI usage. #[default] Auto, + // -- mp-migration 3/8: jcode-compat multi-scope variants -- + /// Read/write both local and global palaces in a single call + /// (jcode's `MemoryScope::All`). The default implementation + /// fans out to the local + global palaces and merges results. + All, + /// Read/write only the named wing (jcode's per-wing scoping). + /// String is the wing name (e.g. "driftwood", "wing_kai"). + Wing(String), + /// Read/write only the named (wing, room) tuple. + Room { wing: String, room: String }, +} + +impl MemoryScope { + /// Does this scope include the project-local palace? + /// Maps to jcode's `MemoryScope::includes_project()`. + pub fn includes_project(&self) -> bool { + match self { + MemoryScope::Local | MemoryScope::Auto | MemoryScope::All => true, + MemoryScope::Global => false, + MemoryScope::Wing(_) | MemoryScope::Room { .. } => true, // named scopes are in the local palace + } + } + + /// Does this scope include the global palace? + /// Maps to jcode's `MemoryScope::includes_global()`. + pub fn includes_global(&self) -> bool { + match self { + MemoryScope::Global | MemoryScope::All => true, + MemoryScope::Local | MemoryScope::Auto => false, + MemoryScope::Wing(_) | MemoryScope::Room { .. } => false, // named scopes are in the local palace + } + } + + /// True if this is the jcode-compat `All` variant. + pub fn is_all(&self) -> bool { + matches!(self, MemoryScope::All) + } } /// Retrieval fusion mode for combining vector and graph-based search.