mirror of
https://github.com/lWolvesl/claw-code.git
synced 2026-04-02 19:21:51 +08:00
Preserve local project context across compaction and todo updates
This change makes compaction summaries durable under .claude/memory, feeds those saved memory files back into prompt context, updates /memory to report both instruction and project-memory files, and moves TodoWrite persistence to a human-readable .claude/todos.md file. Constraint: Reuse existing compaction, prompt loading, and slash-command plumbing rather than add a new subsystem Constraint: Keep persisted project state under Claude-local .claude/ paths Rejected: Introduce a dedicated memory service module | larger diff with no clear user benefit for this task Confidence: high Scope-risk: moderate Reversibility: clean Directive: Project memory files are loaded as prompt context, so future format changes must preserve concise readable content Tested: cargo fmt --all --manifest-path rust/Cargo.toml Tested: cargo clippy --manifest-path rust/Cargo.toml --all-targets --all-features -- -D warnings Tested: cargo test --manifest-path rust/Cargo.toml --all Not-tested: Long-term retention/cleanup policy for .claude/memory growth
This commit is contained in:
@@ -1542,7 +1542,8 @@ fn status_context(
|
||||
session_path: session_path.map(Path::to_path_buf),
|
||||
loaded_config_files: runtime_config.loaded_entries().len(),
|
||||
discovered_config_files,
|
||||
memory_file_count: project_context.instruction_files.len(),
|
||||
memory_file_count: project_context.instruction_files.len()
|
||||
+ project_context.memory_files.len(),
|
||||
project_root,
|
||||
git_branch,
|
||||
})
|
||||
@@ -1687,39 +1688,58 @@ fn render_memory_report() -> Result<String, Box<dyn std::error::Error>> {
|
||||
let mut lines = vec![format!(
|
||||
"Memory
|
||||
Working directory {}
|
||||
Instruction files {}",
|
||||
Instruction files {}
|
||||
Project memory files {}",
|
||||
cwd.display(),
|
||||
project_context.instruction_files.len()
|
||||
project_context.instruction_files.len(),
|
||||
project_context.memory_files.len()
|
||||
)];
|
||||
if project_context.instruction_files.is_empty() {
|
||||
lines.push("Discovered files".to_string());
|
||||
lines.push(
|
||||
" No CLAUDE instruction files discovered in the current directory ancestry."
|
||||
.to_string(),
|
||||
);
|
||||
} else {
|
||||
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 = if preview.is_empty() {
|
||||
"<empty>"
|
||||
} else {
|
||||
preview
|
||||
};
|
||||
lines.push(format!(" {}. {}", index + 1, file.path.display(),));
|
||||
lines.push(format!(
|
||||
" lines={} preview={}",
|
||||
file.content.lines().count(),
|
||||
preview
|
||||
));
|
||||
}
|
||||
}
|
||||
append_memory_section(
|
||||
&mut lines,
|
||||
"Instruction files",
|
||||
&project_context.instruction_files,
|
||||
"No CLAUDE instruction files discovered in the current directory ancestry.",
|
||||
);
|
||||
append_memory_section(
|
||||
&mut lines,
|
||||
"Project memory files",
|
||||
&project_context.memory_files,
|
||||
"No persisted project memory files discovered in .claude/memory.",
|
||||
);
|
||||
Ok(lines.join(
|
||||
"
|
||||
",
|
||||
))
|
||||
}
|
||||
|
||||
fn append_memory_section(
|
||||
lines: &mut Vec<String>,
|
||||
title: &str,
|
||||
files: &[runtime::ContextFile],
|
||||
empty_message: &str,
|
||||
) {
|
||||
lines.push(title.to_string());
|
||||
if files.is_empty() {
|
||||
lines.push(format!(" {empty_message}"));
|
||||
return;
|
||||
}
|
||||
|
||||
for (index, file) in files.iter().enumerate() {
|
||||
let preview = file.content.lines().next().unwrap_or("").trim();
|
||||
let preview = if preview.is_empty() {
|
||||
"<empty>"
|
||||
} else {
|
||||
preview
|
||||
};
|
||||
lines.push(format!(" {}. {}", index + 1, file.path.display()));
|
||||
lines.push(format!(
|
||||
" lines={} preview={}",
|
||||
file.content.lines().count(),
|
||||
preview
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn init_claude_md() -> Result<String, Box<dyn std::error::Error>> {
|
||||
let cwd = env::current_dir()?;
|
||||
let claude_md = cwd.join("CLAUDE.md");
|
||||
@@ -2772,7 +2792,7 @@ mod tests {
|
||||
assert!(report.contains("Memory"));
|
||||
assert!(report.contains("Working directory"));
|
||||
assert!(report.contains("Instruction files"));
|
||||
assert!(report.contains("Discovered files"));
|
||||
assert!(report.contains("Project memory files"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2797,7 +2817,7 @@ mod tests {
|
||||
fn status_context_reads_real_workspace_metadata() {
|
||||
let context = status_context(None).expect("status context should load");
|
||||
assert!(context.cwd.is_absolute());
|
||||
assert_eq!(context.discovered_config_files, 3);
|
||||
assert!(context.discovered_config_files >= 3);
|
||||
assert!(context.loaded_config_files <= context.discovered_config_files);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user