Skip to content

Conversation

@bborn
Copy link
Owner

@bborn bborn commented Feb 1, 2026

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:

# ~/.config/task/hooks/task.blocked
#!/bin/bash
curl -X POST "https://your-webhook.com" \
  -d "{\"task_id\": \"$TASK_ID\", \"title\": \"$TASK_TITLE\"}"

All Events

Event When Emitted
task.created New task created
task.updated Task fields changed
task.deleted Task removed
task.started Execution begins
task.blocked Task needs user input
task.completed Task finished
task.failed Execution failed

How It Works

  1. Place executable scripts in ~/.config/task/hooks/
  2. Name script after event type (e.g., task.blocked)
  3. Script runs automatically when event occurs

Environment variables available:

  • TASK_ID, TASK_TITLE, TASK_STATUS, TASK_PROJECT
  • TASK_EVENT, TASK_TIMESTAMP

Example

# Desktop notification when task needs input
cat > ~/.config/task/hooks/task.blocked << 'EOF'
#!/bin/bash
osascript -e "display notification \"$TASK_TITLE needs input\" with title \"Task Blocked\""
EOF
chmod +x ~/.config/task/hooks/task.blocked

Design

Kept it minimal:

  • No HTTP/SSE server - hooks are simpler and cross-platform
  • No webhook management - just put scripts in hooks dir
  • No ty events watch - use ty events list for history

Net +545 lines (simplified from ~3200 in initial implementation)

Closes #853

bborn and others added 6 commits February 1, 2026 07:32
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>
@bborn
Copy link
Owner Author

bborn commented Feb 1, 2026

Simplification Update

After review, I've dramatically simplified the events system:

Removed:

  • SSE HTTP server (275 lines)
  • ty events watch command
  • Webhook management
  • Verbose documentation

Kept:

  • Simple hook-based system
  • 6 essential event types: created, updated, deleted, started, completed, failed
  • Environment variables passed to hook scripts

Result: Net +523 lines (was ~3200 before simplification)

The core functionality remains: scripts in ~/.config/task/hooks/ run when tasks change state. This is the simplest cross-platform solution that achieves the goal.

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>
@bborn bborn changed the title Add comprehensive event/hook system for task automation Add simple hook-based event system for task automation Feb 2, 2026
@bborn bborn merged commit 2f4416b into main Feb 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants