BREAKING CHANGE: TaskManager has been removed in favor of the new Dataflow architecture Major changes: - Complete TaskManager removal and replacement with Dataflow APIs - Add Canvas task support to WriteAPI with dedicated methods - Enhance QueryAPI with convenience methods and caching - Integrate OnCompletionManager for task completion automation - Remove TaskManagerBridge in favor of DataflowBridge Features added: - Canvas task operations (update, delete, move, duplicate) - QueryAPI convenience methods (getTasksForFile, getTasksDueToday, etc.) - Synchronous cache methods for better performance - OnCompletion event triggering for task automation - Full backward compatibility through API adapters Documentation: - Add canvas-task-api-guide.md for Canvas task usage - Add oncompletion-feature-guide.md for automation features - Add taskmanager-writeapi-gap-analysis.md showing 100% coverage This completes the architectural migration to the event-driven Dataflow system, providing better performance, modularity, and extensibility.
6.9 KiB
OnCompletion Feature Guide
Overview
The OnCompletion feature allows you to define automatic actions that occur when a task is marked as completed. This is useful for workflows like archiving completed tasks, triggering dependent tasks, or moving tasks to different locations.
Architecture
The OnCompletion system consists of:
- OnCompletionManager: Core manager that listens for task completion events
- Action Executors: Individual executors for each action type (delete, move, archive, etc.)
- Event System: Integration with
task-genius:task-completedevent - WriteAPI Integration: Automatic triggering when tasks are completed via API
Setup
The OnCompletion feature is automatically initialized when the plugin loads with indexer enabled. No additional configuration is required.
Usage
Task Metadata Format
Add an onCompletion property to your task metadata:
Simple Format (Emoji)
- [ ] Task content 🏁 delete
- [ ] Task content 🏁 keep
- [ ] Task content 🏁 archive
- [ ] Task content 🏁 move:Projects/Archive.md
- [ ] Task content 🏁 complete:task-id-1,task-id-2
- [ ] Task content 🏁 duplicate:Projects/Templates.md
Dataview Format
- [ ] Task content [onCompletion:: delete]
- [ ] Task content [onCompletion:: keep]
- [ ] Task content [onCompletion:: archive]
- [ ] Task content [onCompletion:: move:Projects/Archive.md]
- [ ] Task content [onCompletion:: complete:task-id-1,task-id-2]
- [ ] Task content [onCompletion:: duplicate:Projects/Templates.md]
JSON Format (Advanced)
- [ ] Task content 🏁 {"type":"move","targetFile":"Archive.md","section":"## Completed"}
- [ ] Task content 🏁 {"type":"complete","taskIds":["id1","id2"],"cascade":true}
- [ ] Task content 🏁 {"type":"archive","archiveFile":"2024-Archive.md","preserveMetadata":true}
Action Types
DELETE
Removes the task from the file when completed.
- [ ] Temporary task 🏁 delete
KEEP
Keeps the task as completed (default behavior, useful for overriding).
- [ ] Important task 🏁 keep
ARCHIVE
Moves the task to an archive file (default: "Archive.md" in same folder).
- [ ] Task to archive 🏁 archive
- [ ] Custom archive 🏁 archive:Completed/2024.md
MOVE
Moves the task to a different file or section.
- [ ] Task to move 🏁 move:Another File.md
- [ ] Move to section 🏁 {"type":"move","targetFile":"File.md","section":"## Done"}
COMPLETE
Automatically completes other tasks when this task is completed.
- [ ] Parent task 🏁 complete:child-task-id-1,child-task-id-2
- [ ] Cascade completion 🏁 {"type":"complete","taskIds":["id1"],"cascade":true}
DUPLICATE
Creates a copy of the task in another location when completed.
- [ ] Template task 🏁 duplicate:Templates/Recurring.md
- [ ] Duplicate and reset 🏁 {"type":"duplicate","targetFile":"Tomorrow.md","resetStatus":true}
Event Flow
- User marks task as completed (via UI, command, or API)
- WriteAPI detects completion and triggers
task-genius:task-completedevent - OnCompletionManager receives the event
- Manager parses the
onCompletionmetadata - Appropriate executor is invoked
- Action is performed (delete, move, archive, etc.)
- Result is logged
Integration Points
WriteAPI
The WriteAPI automatically triggers the completion event:
updateTask()- Whencompleted: trueis setupdateTaskStatus()- When task is marked completeupdateCanvasTask()- Canvas tasks also trigger events
Editor Extensions
monitorTaskCompletedExtension- Monitors inline completionsstatus-switcher- Triggers on status changesstatus-cycler- Triggers on cycle operations
Canvas Support
Canvas tasks fully support OnCompletion:
// Canvas task with onCompletion
{
"type": "text",
"text": "- [ ] Canvas task 🏁 delete",
...
}
Error Handling
If an OnCompletion action fails:
- Error is logged to console
- Task remains completed
- No rollback occurs
- User is not notified (silent failure)
To debug issues:
- Open Developer Console (Ctrl+Shift+I)
- Look for "OnCompletionManager" logs
- Check for parsing or execution errors
Best Practices
- Use simple format for basic actions (delete, keep, archive)
- Use JSON format for complex configurations
- Test actions on non-critical tasks first
- Validate file paths exist before using move/archive
- Use task IDs carefully with complete action
Examples
Daily Task Cleanup
## Daily Tasks
- [ ] Review emails 🏁 delete
- [ ] Update status report 🏁 move:Completed/2024-08.md
- [ ] Team standup 🏁 delete
Project Dependencies
## Project Steps
- [ ] Design mockups 🆔 design-001
- [ ] Implement frontend 🆔 frontend-001 🏁 complete:testing-001
- [ ] Write tests 🆔 testing-001 🏁 complete:deploy-001
- [ ] Deploy to production 🆔 deploy-001
Recurring Task Template
## Templates
- [ ] Weekly review 🏁 duplicate:Next Week.md
- [ ] Monthly report 🏁 {"type":"duplicate","targetFile":"Next Month.md","resetStatus":true}
Configuration
Currently, OnCompletion actions are defined per-task via metadata. Global configuration options may be added in future versions.
Limitations
- Actions are not undoable
- Circular dependencies in
completeaction may cause issues - File operations may fail if target doesn't exist
- No UI for configuring actions (metadata only)
Migration from TaskManager
The OnCompletion feature is fully compatible with the new Dataflow architecture:
| Component | Old (TaskManager) | New (Dataflow) |
|---|---|---|
| Manager | Part of TaskManager | Standalone OnCompletionManager |
| Events | Manual triggering | Automatic via WriteAPI |
| Canvas | Limited support | Full support |
| Performance | Synchronous | Asynchronous |
Testing OnCompletion
To test if OnCompletion is working:
- Create a test task:
- [ ] Test task 🏁 delete
-
Mark it complete using:
- Click the checkbox
- Use keyboard shortcut
- Use WriteAPI
-
Check that the task is deleted
-
Check console for logs:
[Plugin] OnCompletionManager initialized
handleTaskCompleted {task object}
parseResult {config object}
Troubleshooting
OnCompletion not triggering
- Ensure indexer is enabled in settings
- Check that task has valid onCompletion metadata
- Verify task-completed event is firing (check console)
- Ensure OnCompletionManager is loaded
Action failing
- Check file paths are correct
- Ensure target files exist for move/archive
- Verify task IDs exist for complete action
- Check console for specific error messages
Performance issues
- Large batch operations may be slow
- Consider using delete instead of archive for many tasks
- Avoid deep cascade chains in complete action