Improve memory inspection presentation

Reformat /memory into the same structured console style as the other polished commands and enumerate discovered instruction files in ancestry order with line counts and previews. This makes repo instruction memory easier to inspect without changing the underlying discovery behavior.

Constraint: Memory reporting must reflect only the instruction files discovered from current directory ancestry
Rejected: Add memory editing commands in the same slice | presentation polish was a cleaner, lower-risk improvement to ship first
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep instruction-file ordering stable so ancestry-based memory debugging stays predictable
Tested: cargo fmt --manifest-path ./rust/Cargo.toml --all; cargo clippy --manifest-path ./rust/Cargo.toml --workspace --all-targets -- -D warnings; cargo test --manifest-path ./rust/Cargo.toml --workspace
Not-tested: Manual inspection of repos with many nested CLAUDE files
This commit is contained in:
Yeachan-Heo
2026-03-31 21:08:19 +00:00
parent 1adf11d572
commit 88cd2e31df

View File

@@ -877,27 +877,33 @@ fn render_config_report() -> Result<String, Box<dyn std::error::Error>> {
} }
fn render_memory_report() -> Result<String, Box<dyn std::error::Error>> { fn render_memory_report() -> Result<String, Box<dyn std::error::Error>> {
let project_context = ProjectContext::discover(env::current_dir()?, DEFAULT_DATE)?; let cwd = env::current_dir()?;
let project_context = ProjectContext::discover(&cwd, DEFAULT_DATE)?;
let mut lines = vec![format!( let mut lines = vec![format!(
"memory: files={}", "Memory
Working directory {}
Instruction files {}",
cwd.display(),
project_context.instruction_files.len() project_context.instruction_files.len()
)]; )];
if project_context.instruction_files.is_empty() { if project_context.instruction_files.is_empty() {
lines.push("Discovered files".to_string());
lines.push( lines.push(
" No CLAUDE instruction files discovered in the current directory ancestry." " No CLAUDE instruction files discovered in the current directory ancestry."
.to_string(), .to_string(),
); );
} else { } else {
for file in project_context.instruction_files { lines.push("Discovered files".to_string());
for (index, file) in project_context.instruction_files.iter().enumerate() {
let preview = file.content.lines().next().unwrap_or("").trim(); let preview = file.content.lines().next().unwrap_or("").trim();
let preview = if preview.is_empty() { let preview = if preview.is_empty() {
"<empty>" "<empty>"
} else { } else {
preview preview
}; };
lines.push(format!(" {}. {}", index + 1, file.path.display(),));
lines.push(format!( lines.push(format!(
" {} ({}) {}", " lines={} preview={}",
file.path.display(),
file.content.lines().count(), file.content.lines().count(),
preview preview
)); ));
@@ -1334,8 +1340,9 @@ mod tests {
format_cost_report, format_model_report, format_model_switch_report, format_cost_report, format_model_report, format_model_switch_report,
format_permissions_report, format_permissions_switch_report, format_resume_report, format_permissions_report, format_permissions_switch_report, format_resume_report,
format_status_report, normalize_permission_mode, parse_args, parse_git_status_metadata, format_status_report, normalize_permission_mode, parse_args, parse_git_status_metadata,
render_init_claude_md, render_repl_help, resume_supported_slash_commands, status_context, render_init_claude_md, render_memory_report, render_repl_help,
CliAction, SlashCommand, StatusUsage, DEFAULT_MODEL, resume_supported_slash_commands, status_context, CliAction, SlashCommand, StatusUsage,
DEFAULT_MODEL,
}; };
use runtime::{ContentBlock, ConversationMessage, MessageRole}; use runtime::{ContentBlock, ConversationMessage, MessageRole};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@@ -1564,6 +1571,15 @@ mod tests {
assert!(status.contains("Memory files 4")); assert!(status.contains("Memory files 4"));
} }
#[test]
fn memory_report_uses_sectioned_layout() {
let report = render_memory_report().expect("memory report should render");
assert!(report.contains("Memory"));
assert!(report.contains("Working directory"));
assert!(report.contains("Instruction files"));
assert!(report.contains("Discovered files"));
}
#[test] #[test]
fn config_report_uses_sectioned_layout() { fn config_report_uses_sectioned_layout() {
let report = super::render_config_report().expect("config report should render"); let report = super::render_config_report().expect("config report should render");