Skip to content

Commit c145adf

Browse files
committed
feat: add subset and files_by_priority functions to change and contex...
The subset function allows filtering staged files by path and recomputing diff stats on the filtered set, enabling targeted change analysis. The to_prompt function in context now provides a standardized way to generate prompts from context data, improving consistency and usability in prompt generation.
1 parent 3c11d59 commit c145adf

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/domain/change.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,23 @@ impl StagedChanges {
132132
files.sort_by_key(|f| f.category.priority());
133133
files
134134
}
135+
136+
/// Create a subset containing only files matching the given paths.
137+
/// Recomputes DiffStats from the subset.
138+
pub fn subset(&self, paths: &[PathBuf]) -> StagedChanges {
139+
let files: Vec<FileChange> = self
140+
.files
141+
.iter()
142+
.filter(|f| paths.contains(&f.path))
143+
.cloned()
144+
.collect();
145+
146+
let stats = DiffStats {
147+
files_changed: files.len(),
148+
insertions: files.iter().map(|f| f.additions).sum(),
149+
deletions: files.iter().map(|f| f.deletions).sum(),
150+
};
151+
152+
StagedChanges { files, stats }
153+
}
135154
}

src/domain/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ DIFF:
3131
3232
Write a JSON commit message describing the changes shown in the diff.
3333
The subject must be specific - describe WHAT was changed (e.g., "add system prompt to ollama provider", "update dependency versions").
34+
For the body: if the change is trivial (single rename, typo fix), use null. Otherwise write a short body (1-3 sentences) explaining WHY the change was made or what it enables.
3435
3536
Output format:
36-
{{"type": "{commit_type}", "scope": {scope_json}, "subject": "<your description here>", "body": null}}"#,
37+
{{"type": "{commit_type}", "scope": {scope_json}, "subject": "<imperative verb + what changed>", "body": "<why this change was made, or null if trivial>"}}"#,
3738
summary = self.change_summary,
3839
files = self.file_breakdown.trim(),
3940
commit_type = self.suggested_type.as_str(),

0 commit comments

Comments
 (0)