-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: enhance list command with last modified timestamps and sorting #421
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
Conversation
- Add lastModified field showing when each change was last modified - Default sort order is now "recent" (most recently modified first) - Add --sort option to choose between "recent" and "name" ordering - Add --json option for programmatic access with structured output - Fall back to directory mtime for empty change directories - Display relative time (e.g., "2h ago", "3d ago") in human output
📝 WalkthroughWalkthroughThe pull request adds sorting and JSON output capabilities to a CLI list command by introducing Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant ListCommand
participant FileSystem as File System
participant Formatter
User->>CLI: list --sort recent --json
CLI->>ListCommand: execute(path, mode, { sort: 'recent', json: true })
ListCommand->>FileSystem: scan change directories
FileSystem-->>ListCommand: directory entries
ListCommand->>FileSystem: get lastModified for each change
FileSystem-->>ListCommand: mtime values
Note over ListCommand: Sort by lastModified (descending)
alt json flag = true
ListCommand->>Formatter: formatAsJSON(changes with status)
Formatter-->>ListCommand: JSON string
else json flag = false
ListCommand->>Formatter: formatAsText(changes with timeAgo)
Formatter-->>ListCommand: formatted text
end
ListCommand-->>User: output (JSON or text)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Review CompleteYour review story is ready! Comment !reviewfast on this PR to re-generate the story. |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/core/list.ts (2)
27-40: Consider handling transient file errors in the walk.If a file is deleted between
readdirandfs.stat, the function will throw an unhandled error. This is a race condition that could occur if files are being modified concurrently.🔎 Proposed fix to handle transient file errors
async function walk(dir: string): Promise<void> { const entries = await fs.readdir(dir, { withFileTypes: true }); for (const entry of entries) { const fullPath = path.join(dir, entry.name); - if (entry.isDirectory()) { - await walk(fullPath); - } else { - const stat = await fs.stat(fullPath); - if (latest === null || stat.mtime > latest) { - latest = stat.mtime; + try { + if (entry.isDirectory()) { + await walk(fullPath); + } else { + const stat = await fs.stat(fullPath); + if (latest === null || stat.mtime > latest) { + latest = stat.mtime; + } } + } catch { + // Ignore files that disappear between readdir and stat } } }
154-192: Consider supporting--sortand--jsonfor specs mode in a follow-up.The new
sortandjsonoptions are only implemented for 'changes' mode. For consistency, users might expect these options to work for specs as well. This could be addressed in a future enhancement.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/cli/index.tssrc/core/list.ts
🧰 Additional context used
🧬 Code graph analysis (2)
src/cli/index.ts (1)
src/core/list.ts (1)
ListCommand(77-194)
src/core/list.ts (1)
src/utils/task-progress.ts (1)
getTaskProgressForChange(27-35)
🔇 Additional comments (5)
src/cli/index.ts (1)
99-106: LGTM! CLI options properly integrated.The new
--sortand--jsonoptions are correctly defined with appropriate defaults, and the action handler properly processes these options before passing them toListCommand.execute. The fallback to'recent'when sort is anything other than'name'provides sensible default behavior.src/core/list.ts (4)
8-18: LGTM! Clean interface definitions.The
ChangeInfointerface properly includes the newlastModifiedfield, andListOptionsprovides a well-typed options object with appropriate optional fields and literal types for thesortoption.
53-75: LGTM! Well-structured relative time formatting.The function correctly handles various time ranges with a logical progression from days to minutes to "just now". Using
toLocaleDateString()for dates older than 30 days provides appropriate locale-aware formatting.
77-79: LGTM! Clean signature update with sensible defaults.The execute method signature properly accepts the new options parameter with default values, and the destructuring with defaults makes the code clean and maintainable.
121-139: LGTM! Sorting and JSON output implementation.The sorting logic correctly handles both modes (recent by timestamp descending, name alphabetically), and the JSON output provides a well-structured format with ISO date strings suitable for programmatic consumption.
Summary
lastModifiedfield showing when each change was last modified (based on most recent file in the change directory)recent(most recently modified first) instead of alphabetical--sortoption to choose betweenrecentandnameordering--jsonoption for programmatic access with structured outputExample Output
JSON output (
--json):{ "changes": [ { "name": "add-claude-code-skills", "completedTasks": 0, "totalTasks": 22, "lastModified": "2025-12-29T08:04:49.323Z", "status": "in-progress" } ] }Test plan
openspec listshows changes sorted by most recentopenspec list --sort nameshows alphabetical orderopenspec list --jsonoutputs structured JSON🤖 Generated with Claude Code
Summary by CodeRabbit
--sortflag to list changes by name or recent modification date (default: recent).--jsonflag for structured JSON output format.✏️ Tip: You can customize this high-level summary in your review settings.