mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-25 14:53:34 +00:00
Compact memory_tree output format
- Directories indicated by trailing `/` instead of is_directory field
- Files are plain strings, dirs with children are objects
- Remove redundant name/path (just show name in tree)
- Remove preview and updated_at (use memory_read if needed)
- Output is just the tree array, no wrapper object
Example: ["MEMORY.md", {"daily/": ["2024-01-15.md"]}, "projects/"]
Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
3f7624eefc
commit
b316a7f4f5
+20
-26
@@ -330,6 +330,8 @@ impl MemoryTreeTool {
|
||||
}
|
||||
|
||||
/// Recursively build tree structure.
|
||||
///
|
||||
/// Returns a compact format where directories end with `/` and may have children.
|
||||
async fn build_tree(
|
||||
&self,
|
||||
path: &str,
|
||||
@@ -344,34 +346,28 @@ impl MemoryTreeTool {
|
||||
.workspace
|
||||
.list(path)
|
||||
.await
|
||||
.map_err(|e| ToolError::ExecutionFailed(format!("List failed: {}", e)))?;
|
||||
.map_err(|e| ToolError::ExecutionFailed(format!("Tree failed: {}", e)))?;
|
||||
|
||||
let mut result = Vec::new();
|
||||
for entry in entries {
|
||||
let mut node = serde_json::json!({
|
||||
"name": entry.name(),
|
||||
"path": entry.path,
|
||||
"is_directory": entry.is_directory,
|
||||
});
|
||||
// Directories end with `/`, files don't
|
||||
let display_path = if entry.is_directory {
|
||||
format!("{}/", entry.name())
|
||||
} else {
|
||||
entry.name().to_string()
|
||||
};
|
||||
|
||||
if entry.is_directory && current_depth < max_depth {
|
||||
// Recurse into directory
|
||||
let children =
|
||||
Box::pin(self.build_tree(&entry.path, current_depth + 1, max_depth)).await?;
|
||||
if !children.is_empty() {
|
||||
node["children"] = serde_json::Value::Array(children);
|
||||
}
|
||||
} else if !entry.is_directory {
|
||||
// Include file metadata
|
||||
if let Some(updated) = entry.updated_at {
|
||||
node["updated_at"] = serde_json::Value::String(updated.to_rfc3339());
|
||||
}
|
||||
if let Some(preview) = &entry.content_preview {
|
||||
node["preview"] = serde_json::Value::String(preview.clone());
|
||||
if children.is_empty() {
|
||||
result.push(serde_json::Value::String(display_path));
|
||||
} else {
|
||||
result.push(serde_json::json!({ display_path: children }));
|
||||
}
|
||||
} else {
|
||||
result.push(serde_json::Value::String(display_path));
|
||||
}
|
||||
|
||||
result.push(node);
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
@@ -426,13 +422,11 @@ impl Tool for MemoryTreeTool {
|
||||
|
||||
let tree = self.build_tree(path, 1, depth).await?;
|
||||
|
||||
let output = serde_json::json!({
|
||||
"root": if path.is_empty() { "/" } else { path },
|
||||
"depth": depth,
|
||||
"tree": tree,
|
||||
});
|
||||
|
||||
Ok(ToolOutput::success(output, start.elapsed()))
|
||||
// Compact output: just the tree array
|
||||
Ok(ToolOutput::success(
|
||||
serde_json::Value::Array(tree),
|
||||
start.elapsed(),
|
||||
))
|
||||
}
|
||||
|
||||
fn requires_sanitization(&self) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user