Fix three critical UX issues in opal-task

Issue 1: Fix recurrence calculation for overdue tasks
- Use completion date (End) as base for next instance, not original due date
- If task due Monday completed Wednesday, next is Wednesday+7d not Monday+7d
- Fallback to Due date if End is not set
- Update test to verify new behavior

Issue 2: Fix description parsing to work without quotes
- Add parseAddArgs() to extract description from non-modifier words
- Description = all words that don't start with +, -, or contain :
- Enables: opal add buy groceries +shop carrots → 'buy groceries carrots'
- Validate description is required (error if only modifiers)
- Validate recurring tasks require due date

Issue 3: Implement flexible command syntax
- Add preprocessArgs() to parse arguments before Cobra routing
- Detect command position and split filters (left) from modifiers (right)
- Rewrite os.Args so Cobra routes correctly
- Enable both 'opal 2 done' and 'opal done 2' syntax
- Commands without modifiers accept filters on either side
- Commands with modifiers enforce [filters] command [modifiers]
- Add confirmation for modify without filters (modifies all tasks)

All commands updated to use preprocessed ParsedArgs from context.
All tests passing (33 tests).
This commit is contained in:
2026-01-04 21:24:14 +01:00
parent 6e6c3dbea4
commit a68d701d14
11 changed files with 273 additions and 56 deletions
+11 -4
View File
@@ -76,12 +76,19 @@ func SpawnNextInstance(completedInstance *Task) error {
}
// Calculate next due date
var nextDue *time.Time
if completedInstance.Due != nil {
next := CalculateNextDue(*completedInstance.Due, *template.RecurrenceDuration)
nextDue = &next
// Use End date (completion time) as base, fallback to Due date if End not set
var baseDate time.Time
if completedInstance.End != nil {
baseDate = *completedInstance.End
} else if completedInstance.Due != nil {
baseDate = *completedInstance.Due
} else {
return fmt.Errorf("recurring instance has no due or end date")
}
next := CalculateNextDue(baseDate, *template.RecurrenceDuration)
nextDue := &next
// Check if we're past 'until' date
if template.Until != nil && nextDue != nil && nextDue.After(*template.Until) {
// Don't spawn, recurrence has expired
+9 -5
View File
@@ -209,14 +209,18 @@ func TestSpawnNextInstance(t *testing.T) {
found = true
// Verify due date was advanced
// New behavior: calculates from End date (completion time), not original due date
if task.Due == nil {
t.Error("New instance should have due date")
} else {
expectedDue := CalculateNextDue(*instance1.Due, duration)
// Allow 1 second tolerance due to Unix timestamp precision
diff := task.Due.Sub(expectedDue)
if diff < -time.Second || diff > time.Second {
t.Errorf("Expected due date %v, got %v (diff: %v)", expectedDue, *task.Due, diff)
// Should be 7 days from when we completed instance1
// Allow reasonable tolerance for test timing
diff := task.Due.Sub(time.Now())
expectedDiff := duration
tolerance := 5 * time.Second
if diff < expectedDiff-tolerance || diff > expectedDiff+tolerance {
t.Errorf("Expected due date ~%v from now, got %v from now (diff: %v)", duration, diff, diff-expectedDiff)
}
}