From 3258cd4f4d5680b27df5c413d42c6d9eda62bd08 Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Tue, 17 Feb 2026 15:39:15 -0600 Subject: [PATCH] feat(orchestrator): add SSE events, queue controls, and mosaic rails sync --- .env.example | 11 ++ .gitignore | 10 ++ .mosaic/README.md | 4 +- .mosaic/orchestrator/config.json | 18 +++ .mosaic/orchestrator/logs/.gitkeep | 1 + .mosaic/orchestrator/results/.gitkeep | 1 + .mosaic/quality-rails.yml | 10 ++ CLAUDE.md | 2 +- SOUL.md | 2 +- apps/orchestrator/README.md | 40 +++-- .../src/api/agents/agent-events.service.ts | 70 +++++++++ .../agents-killswitch.controller.spec.ts | 26 +++- .../src/api/agents/agents.controller.spec.ts | 30 +++- .../src/api/agents/agents.controller.ts | 45 +++++- .../src/api/agents/agents.module.ts | 3 +- .../src/api/queue/queue-api.module.ts | 11 ++ .../src/api/queue/queue.controller.spec.ts | 65 ++++++++ .../src/api/queue/queue.controller.ts | 39 +++++ apps/orchestrator/src/app.module.ts | 2 + .../src/config/orchestrator.config.spec.ts | 4 +- .../src/config/orchestrator.config.ts | 10 +- apps/orchestrator/src/queue/queue.module.ts | 3 +- .../src/queue/queue.service.spec.ts | 11 +- apps/orchestrator/src/queue/queue.service.ts | 64 +++++++- .../src/spawner/agent-lifecycle.service.ts | 18 +++ .../src/spawner/agent-spawner.service.ts | 27 ++++ .../src/app/api/orchestrator/events/route.ts | 50 +++++++ .../app/api/orchestrator/queue/pause/route.ts | 43 ++++++ .../api/orchestrator/queue/resume/route.ts | 43 ++++++ .../app/api/orchestrator/queue/stats/route.ts | 43 ++++++ .../components/widgets/AgentStatusWidget.tsx | 71 +++++---- .../components/widgets/TaskProgressWidget.tsx | 140 +++++++++++++++--- docs/tasks.md | 23 +++ scripts/agent/orchestrator-daemon.sh | 102 +++++++++++++ scripts/agent/orchestrator-worker.sh | 63 ++++++++ 35 files changed, 1016 insertions(+), 89 deletions(-) create mode 100644 .mosaic/orchestrator/config.json create mode 100644 .mosaic/orchestrator/logs/.gitkeep create mode 100644 .mosaic/orchestrator/results/.gitkeep create mode 100644 .mosaic/quality-rails.yml create mode 100644 apps/orchestrator/src/api/agents/agent-events.service.ts create mode 100644 apps/orchestrator/src/api/queue/queue-api.module.ts create mode 100644 apps/orchestrator/src/api/queue/queue.controller.spec.ts create mode 100644 apps/orchestrator/src/api/queue/queue.controller.ts create mode 100644 apps/web/src/app/api/orchestrator/events/route.ts create mode 100644 apps/web/src/app/api/orchestrator/queue/pause/route.ts create mode 100644 apps/web/src/app/api/orchestrator/queue/resume/route.ts create mode 100644 apps/web/src/app/api/orchestrator/queue/stats/route.ts create mode 100755 scripts/agent/orchestrator-daemon.sh create mode 100755 scripts/agent/orchestrator-worker.sh diff --git a/.env.example b/.env.example index 8615344..37ca636 100644 --- a/.env.example +++ b/.env.example @@ -381,6 +381,17 @@ ELEMENT_IMAGE_TAG=latest # Health endpoints (/health/*) remain unauthenticated ORCHESTRATOR_API_KEY=REPLACE_WITH_RANDOM_API_KEY_MINIMUM_32_CHARS +# Runtime safety defaults (recommended for low-memory hosts) +MAX_CONCURRENT_AGENTS=2 +SESSION_CLEANUP_DELAY_MS=30000 +ORCHESTRATOR_QUEUE_NAME=orchestrator-tasks +ORCHESTRATOR_QUEUE_CONCURRENCY=1 +ORCHESTRATOR_QUEUE_MAX_RETRIES=3 +ORCHESTRATOR_QUEUE_BASE_DELAY_MS=1000 +ORCHESTRATOR_QUEUE_MAX_DELAY_MS=60000 +SANDBOX_DEFAULT_MEMORY_MB=256 +SANDBOX_DEFAULT_CPU_LIMIT=1.0 + # ====================== # AI Provider Configuration # ====================== diff --git a/.gitignore b/.gitignore index 1ce13dc..7e684f0 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,13 @@ yarn-error.log* # Orchestrator reports (generated by QA automation, cleaned up after processing) docs/reports/qa-automation/ + +# Repo-local orchestrator runtime artifacts +.mosaic/orchestrator/orchestrator.pid +.mosaic/orchestrator/state.json +.mosaic/orchestrator/tasks.json +.mosaic/orchestrator/matrix_state.json +.mosaic/orchestrator/logs/*.log +.mosaic/orchestrator/results/* +!.mosaic/orchestrator/logs/.gitkeep +!.mosaic/orchestrator/results/.gitkeep diff --git a/.mosaic/README.md b/.mosaic/README.md index 606f88a..3e13da9 100644 --- a/.mosaic/README.md +++ b/.mosaic/README.md @@ -4,12 +4,12 @@ This repository is attached to the machine-wide Mosaic framework. ## Load Order for Agents -1. `~/.mosaic/STANDARDS.md` +1. `~/.config/mosaic/STANDARDS.md` 2. `AGENTS.md` (this repository) 3. `.mosaic/repo-hooks.sh` (repo-specific automation hooks) ## Purpose -- Keep universal standards in `~/.mosaic` +- Keep universal standards in `~/.config/mosaic` - Keep repo-specific behavior in this repo - Avoid copying large runtime configs into each project diff --git a/.mosaic/orchestrator/config.json b/.mosaic/orchestrator/config.json new file mode 100644 index 0000000..ec50f98 --- /dev/null +++ b/.mosaic/orchestrator/config.json @@ -0,0 +1,18 @@ +{ + "enabled": true, + "transport": "matrix", + "matrix": { + "control_room_id": "", + "workspace_id": "", + "homeserver_url": "", + "access_token": "", + "bot_user_id": "" + }, + "worker": { + "runtime": "codex", + "command_template": "bash scripts/agent/orchestrator-worker.sh {task_file}", + "timeout_seconds": 7200, + "max_attempts": 1 + }, + "quality_gates": ["pnpm lint", "pnpm typecheck", "pnpm test"] +} diff --git a/.mosaic/orchestrator/logs/.gitkeep b/.mosaic/orchestrator/logs/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.mosaic/orchestrator/logs/.gitkeep @@ -0,0 +1 @@ + diff --git a/.mosaic/orchestrator/results/.gitkeep b/.mosaic/orchestrator/results/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.mosaic/orchestrator/results/.gitkeep @@ -0,0 +1 @@ + diff --git a/.mosaic/quality-rails.yml b/.mosaic/quality-rails.yml new file mode 100644 index 0000000..816ea24 --- /dev/null +++ b/.mosaic/quality-rails.yml @@ -0,0 +1,10 @@ +enabled: false +template: "" + +# Set enabled: true and choose one template: +# - typescript-node +# - typescript-nextjs +# - monorepo +# +# Apply manually: +# ~/.config/mosaic/bin/mosaic-quality-apply --template