memory-resident-injection完了

This commit is contained in:
2026-04-27 18:30:21 +09:00
parent e8559d4bee
commit 695cfa05a7
7 changed files with 40 additions and 103 deletions
+31
View File
@@ -63,6 +63,20 @@ impl WorkspaceLayout {
Self { root: root.into() }
}
/// Resolve a layout from a `MemoryConfig`, falling back to
/// `default_root` (typically the Pod's pwd) when the manifest does
/// not pin `workspace_root` explicitly. Single source of truth for
/// the `workspace_root.unwrap_or(pwd)` convention used across the
/// codebase (controller wiring, scope-deny build, system-prompt
/// resident-injection).
pub fn resolve(cfg: &manifest::MemoryConfig, default_root: &Path) -> Self {
let root = cfg
.workspace_root
.clone()
.unwrap_or_else(|| default_root.to_path_buf());
Self::new(root)
}
pub fn root(&self) -> &Path {
&self.root
}
@@ -295,4 +309,21 @@ mod tests {
.unwrap_err();
assert!(matches!(err, LintError::InvalidPath(_)));
}
#[test]
fn resolve_uses_workspace_root_when_set() {
let cfg = manifest::MemoryConfig {
workspace_root: Some(PathBuf::from("/explicit")),
..Default::default()
};
let layout = WorkspaceLayout::resolve(&cfg, Path::new("/fallback"));
assert_eq!(layout.root(), Path::new("/explicit"));
}
#[test]
fn resolve_falls_back_to_default_when_workspace_root_missing() {
let cfg = manifest::MemoryConfig::default();
let layout = WorkspaceLayout::resolve(&cfg, Path::new("/fallback"));
assert_eq!(layout.root(), Path::new("/fallback"));
}
}
+1 -5
View File
@@ -241,11 +241,7 @@ impl PodController {
// companion deny rules on the generic CRUD scope were
// already applied during `Pod::from_manifest`.
if let Some(mem) = memory_config.as_ref() {
let workspace_root = mem
.workspace_root
.clone()
.unwrap_or_else(|| pwd_for_tools.clone());
let layout = memory::WorkspaceLayout::new(workspace_root);
let layout = memory::WorkspaceLayout::resolve(mem, &pwd_for_tools);
let search_cfg = memory::tool::SearchConfig::from(mem);
worker.register_tool(memory::tool::read_tool(layout.clone()));
worker.register_tool(memory::tool::write_tool(layout.clone()));
+2 -10
View File
@@ -569,11 +569,7 @@ impl<C: LlmClient, St: Store> Pod<C, St> {
.memory
.as_ref()
.map(|mem| {
let workspace_root = mem
.workspace_root
.clone()
.unwrap_or_else(|| self.pwd.clone());
let layout = memory::WorkspaceLayout::new(workspace_root);
let layout = memory::WorkspaceLayout::resolve(mem, &self.pwd);
memory::collect_resident_knowledge(&layout)
})
.unwrap_or_default()
@@ -1567,11 +1563,7 @@ pub enum PodError {
fn build_scope_with_memory(manifest: &PodManifest, pwd: &Path) -> Result<Scope, PodError> {
let mut scope_config = manifest.scope.clone();
if let Some(mem) = manifest.memory.as_ref() {
let root = mem
.workspace_root
.clone()
.unwrap_or_else(|| pwd.to_path_buf());
let layout = memory::WorkspaceLayout::new(root);
let layout = memory::WorkspaceLayout::resolve(mem, pwd);
scope_config.deny.extend(memory::deny_write_rules(&layout));
}
Scope::from_config(&scope_config).map_err(PodError::Scope)