← back to Designer Wallcoverings
DW-Agents/dw-agents/COMPLETE-MONITORING-OVERVIEW.md
328 lines
# 🎯 Complete Task Orchestrator Monitoring System
## Overview
The Task Orchestrator (port 9900) is the **central nervous system** for all DW operations. It automatically monitors and tracks EVERYTHING from Shopify to Claude Code.
**Dashboard:** http://45.61.58.125:9900/
---
## What Gets Monitored (Every 60 seconds)
### 1. ✅ Claude Code TodoWrite Tasks
**Source:** Claude Code IDE
**Sync Script:** `/root/DW-Agents/sync-todos-to-orchestrator.js`
Every time you use TodoWrite in Claude Code:
- ✅ Automatically synced to Task Orchestrator
- ✅ Shows up as a task with proper status
- ✅ Includes agent URLs detected from content
- ✅ Preserves your todo descriptions and status
**Example:**
```
Claude Code: TodoWrite "Fix York crash loop"
↓
Task Orchestrator: Creates task "Fix York crash loop"
↓
Visible at http://45.61.58.125:9900/
```
### 2. ✅ Shopify Orders
**Source:** Shopify API
**Monitors:** New orders in last 5 minutes
When a customer places an order:
- ✅ Auto-detected within 60 seconds
- ✅ Creates task with order details
- ✅ Includes customer name, email, items, total
- ✅ High priority if order > $500
- ✅ Auto-assigned to `purchasing-office` agent
**Example:**
```
Shopify: New order #1234 from John Smith - $750
↓
Task Orchestrator: "New Order: #1234 - John Smith" (HIGH priority)
↓
Assigned to: purchasing-office
```
### 3. ✅ New Client Signups
**Source:** Client signup agent (port 9885)
**Monitors:** Pending signup approvals
When someone signs up for an account:
- ✅ Auto-detected from agent stats
- ✅ Creates task for review
- ✅ High priority
- ✅ Auto-assigned to `marketing` agent
### 4. ✅ PM2 Process Failures
**Source:** PM2 process manager
**Monitors:** Process crashes and restarts
When a process crashes or restarts repeatedly:
- ✅ Auto-detected if > 5 restarts
- ✅ Creates CRITICAL priority task
- ✅ Includes process name, PID, restart count
- ✅ Auto-assigned to `server-uptime` agent
**Example:**
```
PM2: york-update-server restarted 10 times
↓
Task Orchestrator: "Process Issue: york-update-server" (CRITICAL)
↓
Assigned to: server-uptime
```
### 5. ✅ Agent Work Reports
**Source:** Individual agents via webhook
**Method:** Agents call `/api/webhook/task`
When agents start work:
- ✅ York reports product sync jobs
- ✅ (Soon) All 11 agents will report their work
- ✅ Shows live progress
- ✅ Auto-updates to completed
---
## Auto-Detection Configuration
**Location:** `/root/DW-Agents/agent-task-orchestrator/task-orchestrator-agent.ts:334`
```typescript
// Runs every 60 seconds
setInterval(autoDetectTasks, 60000);
```
### What It Does:
1. **TodoWrite Sync** (Line 338-347)
- Executes `sync-todos-to-orchestrator.js`
- Merges Claude Code todos with orchestrator tasks
- Silent fail if no changes
2. **Shopify Orders** (Line 349-406)
- HTTPS GET to Shopify API
- Checks last 5 minutes of orders
- Deduplicates by order ID
- Creates task with full order details
3. **Client Signups** (Line 408-449)
- HTTP GET to signup agent stats
- Checks for pending signups
- Creates review task if pending > 0
4. **PM2 Process Monitor** (Line 452-498)
- Executes `pm2 jlist`
- Checks for errored status or > 5 restarts
- Creates critical task for failing processes
- Deduplicates within 10-minute window
---
## Task Flow Diagram
```
┌─────────────────────────────────────────────────────────────┐
│ TASK ORCHESTRATOR │
│ Port 9900 - Running 24/7 │
└─────────────────────────────────────────────────────────────┘
▲
│
┌───────────────────┼───────────────────┐
│ │ │
│ │ │
┌────▼────┐ ┌──────▼─────┐ ┌────▼────┐
│ Claude │ │ Shopify │ │ PM2 │
│ Code │ │ API │ │ Monitor │
│TodoWrite│ │ Orders │ │Failures │
└─────────┘ └────────────┘ └─────────┘
│ │ │
│ │ │
└───────────────────┼───────────────────┘
│
▼
┌───────────────┐
│ Auto-Detect │
│ Every 60s │
└───────────────┘
│
▼
┌───────────────┐
│ Create Tasks │
│ Assign Agents │
│ Track Progress│
└───────────────┘
│
▼
┌───────────────┐
│ Dashboard │
│ Visible to │
│ Everyone │
└───────────────┘
```
---
## Integration Examples
### Example 1: TodoWrite in Claude Code
When you type in Claude Code:
```
TodoWrite: "Fix York crash loop" - in_progress
```
Within 60 seconds, Task Orchestrator creates:
- **Title:** Fix York crash loop
- **Status:** in_progress
- **Agent:** york (auto-detected from "York" in title)
- **URL:** http://45.61.58.125:7234 (auto-detected)
### Example 2: Shopify Order
Customer places order at 2:15 PM:
- **2:16 PM** - Task Orchestrator polls Shopify API
- **2:16 PM** - Detects new order #5678
- **2:16 PM** - Creates task: "New Order: #5678 - Jane Doe"
- **2:16 PM** - Assigns to `purchasing-office`
- **Dashboard** - Shows order with customer details, items, total
### Example 3: York Job
York agent starts product sync:
- **Start** - York calls `/api/webhook/task` with job details
- **Running** - Shows "York Product Update" in progress
- **Progress** - Live updates: "44/2000 products processed"
- **Complete** - York reports completion with stats
- **Dashboard** - Shows completed with duration
---
## Files Involved
1. **Task Orchestrator Agent**
- `/root/DW-Agents/agent-task-orchestrator/task-orchestrator-agent.ts`
- Main orchestrator with auto-detection (line 334)
2. **TodoWrite Sync Script**
- `/root/DW-Agents/sync-todos-to-orchestrator.js`
- Syncs Claude Code todos to orchestrator
3. **Task Database**
- `/root/DW-Agents/tasks-database.json`
- Persistent storage of all tasks
4. **Memory System**
- `/root/DW-Agents/task-memory.json`
- Context and agent performance tracking
5. **Shared Reporter Module**
- `/root/DW-Agents/shared-task-reporter.ts`
- Library for agents to report tasks
---
## Monitoring Dashboard Features
Visit **http://45.61.58.125:9900/** to see:
### Stats Overview
- 📊 Pending tasks count
- 🔄 In Progress tasks count
- ✅ Completed tasks count
- ⚠️ Blocked tasks count
- 📈 Total tasks
- 🤖 Active agents
### Task List (Sortable)
- **Card View** - Visual cards with full details
- **List View** - Spreadsheet-style table (default)
- **Filtering** - By status, agent, priority
- **Real-time Updates** - Auto-refresh every 30 seconds
### Per-Task Information
- Title and description
- Status badge with color coding
- Assigned agent with icon
- Priority level (low/medium/high/critical)
- Created timestamp
- Started timestamp
- Completed timestamp
- Duration (actual or ongoing)
- Progress bar (if in progress)
- Live metrics (if available)
- Action buttons (Assign, Start, Complete, Block)
- Agent dashboard link
### Actions
- **Assign** - Choose from 11 agents via dropdown
- **Start** - Begin working on task
- **Complete** - Mark as done
- **Block** - Flag with reason
- **Create New** - Manual task creation
---
## Verification
To verify the system is working:
1. **Check logs:**
```bash
pm2 logs dw-task-orchestrator --lines 50 | grep "Auto-detecting"
```
You should see:
```
✅ TodoWrite sync completed
🔍 Auto-detecting tasks from system events...
```
2. **Check the dashboard:**
```bash
curl -s http://localhost:9900/health
```
Should return:
```json
{
"status": "ok",
"totalTasks": 123,
"timestamp": "2025-11-07T20:00:00.000Z"
}
```
3. **Test TodoWrite sync:**
- Use TodoWrite in Claude Code
- Wait 60 seconds
- Check http://45.61.58.125:9900/
- Your todo should appear as a task
---
## Summary
✅ **Task Orchestrator monitors EVERYTHING**
- Claude Code TodoWrite → Auto-synced every 60s
- Shopify Orders → Auto-detected every 60s
- Client Signups → Auto-detected every 60s
- PM2 Failures → Auto-detected every 60s
- Agent Work → Reported via webhooks
✅ **All tasks visible in one place**
- http://45.61.58.125:9900/
✅ **Full automation**
- No manual intervention needed
- Tasks auto-assigned to appropriate agents
- Progress tracked automatically
- Completion reported automatically
**Result: Complete visibility into all DW operations! 🎉**