daemon/README.md

Great Minds Daemon

The daemon is an Agent SDK-based long-running process that replaces the previous cron-based pipeline. It supersedes pipeline-runner.sh, heartbeat.sh, feature-dream.sh, and memory-maintain.sh.

What It Does

The daemon runs a continuous event loop that:

  1. Watches for new PRDs in prds/ using chokidar file watcher — triggers the full pipeline instantly
  2. Polls GitHub issues every 5 minutes across all monitored repos
  3. Runs heartbeat health checks every 5 minutes (site status, git status, memory)
  4. Runs featureDream every 4 hours when idle (board reviews or brainstorms new products)
  5. Runs memory maintenance every 6 hours (prunes duplicates, consolidates)

Pipeline Phases

When a PRD is detected, the full GSD pipeline runs:

PhaseAgentsWhat Happens
Debate R1Steve + Elon (parallel)Stake positions on design vs. engineering
Debate R2Steve + Elon (parallel)Challenge each other, lock decisions
EssenceRick RubinDistill the core idea
ConsolidationPhil JacksonMerge decisions into blueprint
PlanPlanner + Sara BlakelyCreate build plan + gut-check
BuildBuilder agentExecute the plan, produce deliverables
QA Pass 1Margaret HamiltonVerify requirements, auto-fix if BLOCK
QA Pass 2Margaret HamiltonIntegration check
Creative ReviewJony Ive + Maya Angelou + Aaron SorkinVisual, copy, and demo script
Board ReviewJensen + Oprah + Buffett + ShondaStrategic evaluation
ShipShipper + Marcus AureliusDeploy + retrospective

Architecture

daemon/
  bin/greatminds-daemon    Shell launcher
  src/
    daemon.ts              Main event loop (watcher + timers + queue)
    pipeline.ts            GSD pipeline as TypeScript functions
    agents.ts              Prompt templates for all 14 personas
    dream.ts               featureDream cycle (IMPROVE / DREAM)
    health.ts              Heartbeat, git monitor, memory maintenance
    config.ts              Paths, intervals, repo list
    logger.ts              Console + file logging

Configuration

Edit src/config.ts to change:

  • Repo paths
  • GitHub repos to monitor
  • Sites to health-check
  • Polling intervals
  • Dream/maintenance intervals

Running Locally vs. on Server

Locally:

cd daemon && npm install && ./bin/greatminds-daemon

On server (with tmux for persistence):

tmux new -s daemon
cd ~/projects/great-minds/daemon
npm install && ./bin/greatminds-daemon
# Ctrl+B, D to detach

With Docker:

cd daemon && docker compose up -d

featureDream Cycle

When the daemon is idle (no active PRDs), it enters the featureDream cycle every 4 hours. This alternates between two modes:

  • IMPROVE — the board reviews existing products and files GitHub issues for improvements
  • DREAM — agents brainstorm new product ideas, write speculative PRDs, and evaluate them

Memory Maintenance

Every 6 hours, the daemon consolidates memory: pruning duplicate entries, merging related learnings, and verifying that memory index references still resolve to real files. This keeps the agency's persistent memory lean and accurate.

Logs

Logs write to both console (stdout) and /tmp/claude-shared/daemon.log. When running in Docker, use docker compose logs -f to tail output.

Telegram Notifications

The daemon sends real-time notifications to Telegram for pipeline events: starts, completions, failures, and hung agent detection. This lets you monitor the agency from your phone.

Setup

  1. Message @BotFather on Telegram and create a new bot (/newbot)
  2. Copy the bot token
  3. Send a message to your bot, then fetch your chat ID via https://api.telegram.org/bot<TOKEN>/getUpdates
  4. Set environment variables (see table below)

What Gets Notified

  • Pipeline started (PRD name)
  • Pipeline completed (duration, phases)
  • Pipeline failed (error, phase, retry count)
  • Agent hung (agent name, timeout duration)
  • PRD archived to failed (after all retries exhausted)

Crash Recovery

When a pipeline phase fails, the daemon retries it up to 2 times with exponential backoff (30s, then 60s). If all retries are exhausted, the PRD is moved to prds/failed/ so it does not block the queue. A Telegram notification is sent on each failure and on final archival.

Hung Agent Detection

Individual agents are killed if they exceed the agent timeout (default: 10 minutes). The entire pipeline is aborted if it exceeds the pipeline timeout (default: 60 minutes). Hung agents trigger a Telegram alert and the phase is retried or skipped depending on remaining retry budget.

Token Ledger

The daemon tracks token usage and estimated cost per agent across every pipeline run. Use /agency-tokens to view the ledger. This helps identify which agents are expensive and where to optimize prompt size or model choice.

Bug Memory

Known bugs are stored in daemon/buglog.json (currently 8 entries). Agents query the buglog before debugging to avoid re-investigating known issues. New bugs can be added manually or by agents during QA passes.

Environment Variables

VariableDefaultDescription
TELEGRAM_BOT_TOKENTelegram bot token from BotFather
TELEGRAM_CHAT_IDTelegram chat ID for notifications
AGENT_TIMEOUT_MS600000 (10 min)Max time for a single agent call
PIPELINE_TIMEOUT_MS3600000 (60 min)Max time for the entire pipeline

Stopping

Send SIGINT (Ctrl+C) or SIGTERM. The daemon will finish its current agent call before exiting gracefully.