# Implementation Plan: Today Task Feature
## Overview
Implement a special "today" task feature that:
- Allows switching to a daily task with `track switch today`
- Auto-creates the task if it doesn't exist
- Inherits incomplete todos and linked scraps from the previous day
- Shows a special WebUI with Google Calendar integration instead of ticket/repository cards
## Database Changes
### 1. Add `is_today_task` flag to tasks table
- Migration to add `is_today_task BOOLEAN DEFAULT 0` column
- Only one task can have this flag set at a time
- Task name format: "Today: YYYY-MM-DD"
## Service Layer Changes
### 2. TaskService: Add today task methods
- `get_or_create_today_task()` - Get today's task or create it
- `get_previous_today_task()` - Find the most recent previous today task
- `is_today_task_name(name: &str)` - Check if a task name matches today format
- Update `create_task()` to support `is_today_task` flag
### 3. TodoService: Add inheritance method
- `copy_incomplete_todos(from_task_id: i64, to_task_id: i64)` - Copy pending todos
- Preserve todo content and order
- Don't copy worktree_requested flag
### 4. ScrapService: Add inheritance method
- `copy_linked_scraps(from_task_id: i64, to_task_id: i64, todo_mapping: HashMap<i64, i64>)` - Copy scraps linked to inherited todos
- Update `active_todo_id` to point to new todo IDs
## CLI Changes
### 5. Update switch command handler
- Detect "today" as special keyword in `Commands::Switch`
- Call `get_or_create_today_task()` when switching to "today"
- Perform inheritance from previous day if creating new today task
## WebUI Changes
### 6. Add Google Calendar integration
- New template: `templates/partials/calendar.html`
- Embed Google Calendar iframe for today's date
- Configuration for calendar ID (via environment variable or config file)
### 7. Update index.html template
- Check if current task is a today task (`task.is_today_task`)
- Conditionally render calendar instead of ticket/repository cards
- Keep description, todos, scraps, and links sections
### 8. Update routes.rs
- Pass `is_today_task` flag to template context
- Add calendar configuration to context
## Implementation Steps
1. **Database Migration** (db/mod.rs)
- Add migration for `is_today_task` column
- Add index on `is_today_task` for quick lookup
2. **Task Service** (services/task_service.rs)
- Implement today task detection and creation logic
- Add methods to find previous today task
3. **Todo Service** (services/todo_service.rs)
- Implement todo copying logic
- Preserve order and content
4. **Scrap Service** (services/scrap_service.rs)
- Implement scrap copying logic with todo ID mapping
5. **CLI Handler** (cli/handler.rs)
- Update switch command to handle "today" keyword
- Orchestrate task creation and inheritance
6. **WebUI Templates** (templates/)
- Create calendar partial
- Update index.html with conditional rendering
- Add CSS for calendar display
7. **WebUI Routes** (webui/routes.rs)
- Pass today task flag to templates
- Add calendar configuration
## Testing Considerations
- Test creating first today task (no previous day)
- Test creating today task with previous day data
- Test switching to existing today task
- Test WebUI rendering for today vs regular tasks
- Test todo/scrap inheritance with various edge cases
## Configuration
- Google Calendar ID: Environment variable `TRACK_CALENDAR_ID` or config file
- Calendar embed URL format: `https://calendar.google.com/calendar/embed?src={CALENDAR_ID}&mode=DAY&dates={YYYYMMDD}`
## Future Enhancements
- Archive old today tasks automatically after N days
- Summary view of completed today tasks
- Weekly/monthly rollup of today tasks