---
name: auto-commit-on-done
description: Add option to automatically git commit when a task is marked as done
status: ready
parts:
  - src/types/task.rs
  - src/storage.rs
  - src/servers/task.rs
  - CLAUDE.md
estimate:
  optimistic: 2 hours
  normal: 4 hours
  pessimistic: 6 hours
---

# Implementation Plan

## Feature Sizing Checklist

- [x] Each feature can be described in 2-3 sentences
- [x] Each feature is completable in one context window
- [x] No feature tries to do too much

## Task Summary

| ID | Task | Files |
|----|------|-------|
| F1 | Add auto_commit_on_done config setting | `src/types/task.rs` |
| F2 | Track modified files in TaskState | `src/types/task.rs`, `src/storage.rs` |
| F3 | Execute git commit on task done | `src/servers/task.rs` |
| F4 | Document setting in CLAUDE.md | `CLAUDE.md` |

## Tasks

- [ ] **F1**: Add `auto_commit_on_done: bool` field to `ProjectConfig` struct with default `false`. Update `to_toml_with_comments()` to include explanatory comments. Update `merge_with_existing()` and `has_all_settings()` to handle the new field.

- [ ] **F2**: Add `modified_files: Vec<String>` field to `TaskState` struct. This will track files that should be committed when the task is done. Files will be populated from the review files list when `set_task_status` is called with `status="reviewing"`.

- [ ] **F3**: In `set_task_status`, when transitioning to `done` and `auto_commit_on_done` is true:
  1. Get the modified files from TaskState
  2. If no files, succeed silently
  3. Run `git add <files>` for each tracked file
  4. Get description from plan.md frontmatter
  5. Run `git commit -m "Complete task: {name}\n\n{description}"`
  6. If commit fails, block the status change and return error
  7. If succeeds, proceed with status change

- [ ] **F4**: Update CLAUDE.md to document the new `auto_commit_on_done` setting in the Configuration section and example config.toml.

## Key Design Decisions

1. **File Tracking**: Use the files provided to `set_task_status(status="reviewing", files=[...])` as the source of files to commit. These are already tracked and represent the work done for the task.

2. **Commit Message**: Format will be:
   ```
   Complete task: {task-name}
   
   {description from plan.md frontmatter}
   ```

3. **Error Handling**: Git failures block the status change to ensure the user is aware and can fix the issue before marking done.

4. **No Pre-checks**: Let git commands fail naturally rather than checking for .git directory.

## Testing Considerations

- Test with auto_commit_on_done = false (default behavior unchanged)
- Test with auto_commit_on_done = true and files to commit
- Test with auto_commit_on_done = true and no files (should succeed)
- Test git failure scenario (pre-commit hook fails)
- Test in non-git directory

---

## Estimate

**Senior Developer Profile:** 5+ years experience, familiar with Rust and the K4000 codebase.

| Scenario | Time |
|----------|------|
| Optimistic | 2 hours |
| Normal | 4 hours |
| Pessimistic | 6 hours |

### Assumptions
- Developer is familiar with the existing ProjectConfig and TaskState patterns
- Git command execution can use std::process::Command
- No complex git edge cases (merge conflicts, etc.) need handling
