-
Notifications
You must be signed in to change notification settings - Fork 3
Add simple hook-based event system for task automation #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit implements a complete event system for TaskYou that enables automation, integrations, and notifications through multiple delivery mechanisms. ## What's New ### Event System (internal/events) - Created new events package with Manager for centralized event handling - Supports 15+ event types covering the complete task lifecycle - Multiple delivery mechanisms: - Script hooks in ~/.config/task/hooks/ - HTTP webhooks for external integrations - Event log database for audit trail - In-process channels for real-time UI updates - Async event delivery with buffered queue (non-blocking) - Comprehensive test coverage ### Database Event Emission - Added EventEmitter interface in internal/db/events.go - Modified UpdateTaskStatus to emit status change events - Wired up task CRUD operations to emit events - Added comprehensive tests for event emission ### CLI Commands - Added 'ty events' command group - 'ty events list' - View event log with filtering - 'ty events webhooks list/add/remove' - Manage webhooks - JSON output support for automation ### Documentation - Created comprehensive docs/EVENTS.md guide - Added examples/hooks/ directory with example scripts: - Desktop notifications (macOS/Linux) - Slack integration - Time tracking - Custom integrations - Updated README.md with Events & Automation section ### Integration - Integrated events manager into executor lifecycle - Added event emission for all task state changes - Proper cleanup on executor shutdown - Backward compatible with existing hook system ## Event Types - task.created, task.updated, task.deleted - task.status.changed - task.queued, task.started, task.processing - task.blocked, task.completed, task.failed - task.retried, task.interrupted - task.pinned, task.unpinned ## Use Cases Enabled - Desktop/mobile notifications - Slack/Discord/Teams integration - Time tracking and analytics - External task manager sync (Todoist, Linear, Jira) - Custom automation workflows - Audit trail and compliance ## Breaking Changes None. The system is fully backward compatible and opt-in. Closes #853
Event Streaming Implementation: - Add HTTP/SSE server (internal/server/http.go) for real-time event streaming - Add 'ty events watch' command to stream events as newline-delimited JSON - Support filtering by event type, task ID, and project - Integrate HTTP server into both taskd and local daemon - Add comprehensive documentation (docs/EVENTS.md) - Add example event watcher script (examples/event-watcher.sh) - Add example webhook server (examples/webhook-server.js) - Add example hook script (examples/hooks/task.completed) - Update README with event streaming features CI Test Fixes: - Fix SQLite database locking issues by isolating test databases - Each test subtest now uses its own fresh database - Fix CreateTask to insert tags and pinned fields directly - Remove redundant UpdateTask call in moveTask function - Update CI config to run tests sequentially (-p 1 -count=1) - All tests now pass consistently without skipping Event System Features: - Server-Sent Events (SSE) for real-time streaming - Webhook delivery (HTTP POST) - Script hooks (local automation) - Event log (database audit trail) - In-process channels (TUI updates) - Comprehensive event types (created, updated, queued, processing, completed, etc.) Files Added: - internal/server/http.go - examples/event-watcher.sh - examples/webhook-server.js - docs/EVENTS.md - IMPLEMENTATION_SUMMARY.md Files Modified: - .github/workflows/ci.yml (sequential test execution) - README.md (add event streaming to features) - cmd/task/main.go (add 'events watch' command, fix moveTask) - cmd/taskd/main.go (add HTTP server) - internal/db/tasks.go (CreateTask inserts all fields) - cmd/task/cli_test.go (isolated databases per subtest) - internal/executor/executor_test.go (isolated databases per subtest)
- Remove all webhook functionality (AddWebhook, RemoveWebhook, ListWebhooks) - Remove webhook CLI commands (ty events webhooks) - Remove webhook delivery from events manager - Remove webhook example (examples/webhook-server.js) - Update documentation to remove webhook references - Fix staticcheck linter error in watchEvents - Keep only: real-time streaming (ty events watch), script hooks, event log
Accidentally removed eventsWatchCmd when removing webhook commands. This restores the 'ty events watch' CLI command.
- Remove webhook mentions from documentation - Remove webhook from event flow diagram - Remove webhook from test list - Update backward compatibility explanation - Clarify what 'opt-in' means
- Remove SSE HTTP server (275 lines) - overkill for MVP - Remove `ty events watch` command - not needed with hooks - Simplify events.Emitter from 415 to 125 lines - Remove 14 redundant EmitTaskX helper methods - Keep only 6 essential event types: created, updated, deleted, started, completed, failed - Remove verbose docs/EVENTS.md (278 lines) - Remove IMPLEMENTATION_SUMMARY.md (270 lines) - Simplify examples/hooks/ to just 2 essential examples - Update README to reflect simpler hook-based approach The core functionality remains: hooks run in ~/.config/task/hooks/ when task events occur. This is the simplest cross-platform solution that achieves the goal without over-engineering. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Owner
Author
Simplification UpdateAfter review, I've dramatically simplified the events system: Removed:
Kept:
Result: Net +523 lines (was ~3200 before simplification) The core functionality remains: scripts in |
This is the most important event for external automation - it fires when a task becomes blocked and needs user input (e.g., Claude is waiting for feedback). - Add TaskBlocked constant and EmitTaskBlocked method - Emit task.blocked event when status changes to blocked - Add task.blocked example hook script - Update README and docs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Implements a minimal event system for TaskYou that runs scripts when tasks change state. No polling required - external callers get notified immediately.
Key Event: task.blocked
The most important event for automation - fires when a task needs user input:
All Events
How It Works
Environment variables available:
Example
Design
Kept it minimal:
Net +545 lines (simplified from ~3200 in initial implementation)
Closes #853