-
Notifications
You must be signed in to change notification settings - Fork 0
feat: v3.3 — lifecycle, custom rules, views, compaction & archival #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
corvid-agent
wants to merge
8
commits into
main
Choose a base branch
from
feat/hash-cache-phase1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
db0e0ef
feat: content hashing for smart change detection (Phase 1)
corvid-agent 2f9d4fc
fix: resolve cargo fmt formatting issues
corvid-agent cf9e41e
feat: staleness detection, change classification, and AI-driven spec …
corvid-agent b1480a1
fix: normalize path separators for cross-platform cache keys
corvid-agent 2f688cb
fix: make cursor provider tests case-insensitive
corvid-agent b91d005
fix: resolve cargo fmt formatting issues
corvid-agent da0b8a4
feat: v3.3 lifecycle, custom rules, views, compaction, and archival
corvid-agent 8512e7c
fix: address PR review feedback from Copilot and CorvidAgent
corvid-agent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| /target | ||
| .specsync/ | ||
|
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| use colored::Colorize; | ||
| use std::fs; | ||
| use std::path::Path; | ||
|
|
||
| use crate::validator::find_spec_files; | ||
|
|
||
| /// Result of archiving tasks in a single tasks.md file. | ||
| pub struct ArchiveResult { | ||
| pub tasks_path: String, | ||
| pub archived_count: usize, | ||
| } | ||
|
|
||
| /// Archive completed tasks across all companion tasks.md files. | ||
| /// Moves `- [x]` items to an `## Archive` section at the bottom. | ||
| pub fn archive_tasks(root: &Path, specs_dir: &Path, dry_run: bool) -> Vec<ArchiveResult> { | ||
| let spec_files = find_spec_files(specs_dir); | ||
| let mut results = Vec::new(); | ||
|
|
||
| for spec_path in &spec_files { | ||
| // Find the companion tasks.md in the same directory | ||
| let spec_dir = match spec_path.parent() { | ||
| Some(d) => d, | ||
| None => continue, | ||
| }; | ||
| let tasks_path = spec_dir.join("tasks.md"); | ||
| if !tasks_path.exists() { | ||
| continue; | ||
| } | ||
|
|
||
| let content = match fs::read_to_string(&tasks_path) { | ||
| Ok(c) => c, | ||
| Err(_) => continue, | ||
| }; | ||
|
|
||
| let rel_path = tasks_path | ||
| .strip_prefix(root) | ||
| .unwrap_or(&tasks_path) | ||
| .to_string_lossy() | ||
| .to_string(); | ||
|
|
||
| if let Some((new_content, count)) = archive_completed_tasks(&content) { | ||
| if count > 0 { | ||
| if !dry_run { | ||
| if let Err(e) = fs::write(&tasks_path, &new_content) { | ||
| eprintln!( | ||
| "{} Failed to write {}: {e}", | ||
| "error:".red().bold(), | ||
| rel_path | ||
| ); | ||
| continue; | ||
| } | ||
| } | ||
| results.push(ArchiveResult { | ||
| tasks_path: rel_path, | ||
| archived_count: count, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| results | ||
| } | ||
|
|
||
| /// Archive completed tasks in a tasks.md file. | ||
| /// Returns (new_content, archived_count) if any tasks were archived. | ||
| fn archive_completed_tasks(content: &str) -> Option<(String, usize)> { | ||
| let mut completed_tasks: Vec<String> = Vec::new(); | ||
| let mut remaining_lines: Vec<String> = Vec::new(); | ||
| let mut in_archive = false; | ||
| let mut existing_archive: Vec<String> = Vec::new(); | ||
|
|
||
| for line in content.lines() { | ||
| let trimmed = line.trim(); | ||
|
|
||
| // Track if we're in the archive section | ||
| if trimmed == "## Archive" { | ||
| in_archive = true; | ||
| continue; | ||
| } | ||
| if in_archive { | ||
| if trimmed.starts_with("## ") { | ||
| // Exited archive section into next section | ||
| in_archive = false; | ||
| remaining_lines.push(line.to_string()); | ||
| } else { | ||
| existing_archive.push(line.to_string()); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| // Check for completed tasks outside the archive section | ||
| if trimmed.starts_with("- [x]") || trimmed.starts_with("- [X]") { | ||
| completed_tasks.push(line.to_string()); | ||
| } else { | ||
| remaining_lines.push(line.to_string()); | ||
| } | ||
| } | ||
|
|
||
| if completed_tasks.is_empty() { | ||
| return None; | ||
| } | ||
|
|
||
| let count = completed_tasks.len(); | ||
|
|
||
| // Build new content: remaining lines + archive section | ||
| let mut new_content = remaining_lines.join("\n"); | ||
|
|
||
| // Ensure trailing newline before archive section | ||
| if !new_content.ends_with('\n') { | ||
| new_content.push('\n'); | ||
| } | ||
| new_content.push('\n'); | ||
| new_content.push_str("## Archive\n\n"); | ||
|
|
||
| // Add existing archive entries first | ||
| for line in &existing_archive { | ||
| if !line.trim().is_empty() { | ||
| new_content.push_str(line); | ||
| new_content.push('\n'); | ||
| } | ||
| } | ||
|
|
||
| // Add newly archived tasks | ||
| for task in &completed_tasks { | ||
| new_content.push_str(task); | ||
| new_content.push('\n'); | ||
| } | ||
|
|
||
| Some((new_content, count)) | ||
| } | ||
|
|
||
| /// Count completed tasks across all tasks.md files (for warnings in check command). | ||
| pub fn count_completed_tasks(specs_dir: &Path) -> usize { | ||
| let spec_files = find_spec_files(specs_dir); | ||
| let mut total = 0; | ||
|
|
||
| for spec_path in &spec_files { | ||
| let spec_dir = match spec_path.parent() { | ||
| Some(d) => d, | ||
| None => continue, | ||
| }; | ||
| let tasks_path = spec_dir.join("tasks.md"); | ||
| if !tasks_path.exists() { | ||
| continue; | ||
| } | ||
| if let Ok(content) = fs::read_to_string(&tasks_path) { | ||
| total += content | ||
| .lines() | ||
| .filter(|l| { | ||
| let t = l.trim(); | ||
| t.starts_with("- [x]") || t.starts_with("- [X]") | ||
| }) | ||
| .count(); | ||
| } | ||
| } | ||
|
|
||
| total | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_archive_completed_tasks() { | ||
| let content = r#"--- | ||
| spec: test.spec.md | ||
| --- | ||
|
|
||
| ## Tasks | ||
|
|
||
| - [ ] Uncompleted task | ||
| - [x] Done task 1 | ||
| - [ ] Another open task | ||
| - [x] Done task 2 | ||
|
|
||
| ## Gaps | ||
|
|
||
| Nothing here. | ||
| "#; | ||
|
|
||
| let (new_content, count) = archive_completed_tasks(content).unwrap(); | ||
| assert_eq!(count, 2); | ||
| assert!(new_content.contains("## Archive")); | ||
| assert!(new_content.contains("- [x] Done task 1")); | ||
| assert!(new_content.contains("- [x] Done task 2")); | ||
| assert!(new_content.contains("- [ ] Uncompleted task")); | ||
| // Archived tasks should not appear in the Tasks section | ||
| assert!(!new_content[..new_content.find("## Archive").unwrap()].contains("- [x]")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_archive_no_completed() { | ||
| let content = r#"## Tasks | ||
|
|
||
| - [ ] Open task | ||
| "#; | ||
|
|
||
| assert!(archive_completed_tasks(content).is_none()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_archive_preserves_existing() { | ||
| let content = r#"## Tasks | ||
|
|
||
| - [x] New done task | ||
|
|
||
| ## Archive | ||
|
|
||
| - [x] Previously archived | ||
| "#; | ||
|
|
||
| let (new_content, count) = archive_completed_tasks(content).unwrap(); | ||
| assert_eq!(count, 1); | ||
| assert!(new_content.contains("- [x] Previously archived")); | ||
| assert!(new_content.contains("- [x] New done task")); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This truncation uses
&content[..30_000], which can panic at runtime if the string contains non-UTF8-boundary bytes (non-ASCII / multibyte UTF-8). Truncate by character boundary (or use a safe byte/char truncation helper) to avoid panics when source files contain Unicode.