worker.sh - Task Execution (Nurturer)

worker.sh

Task Execution & Completion

The Nurturer: Uses LLM to execute any beads task to completion.


Overview

worker.sh is the Nurturer in Aurora’s planner-worker architecture. It runs every hour, claims one ready task from the beads queue, and uses the LLM to execute it to completion.

The Nurturer Pattern

In the Observer-Nurturer model:

The Worker is the “doer” — it takes the tasks created by Planner and makes them happen.


Features

1. Task Claiming

Worker finds and claims ready tasks from the beads queue:

# Find a ready task
TASK_ID=$(bd ready | head -1)

# Claim it for execution
bd update --claim $TASK_ID

2. LLM-Driven Execution

For each claimed task, the Worker:

  1. Reads the task description
  2. Understands what needs to be done
  3. Uses the LLM to plan and execute the work
  4. Handles multi-step workflows
  5. Resumes work across invocations if needed

3. Multi-Step Task Support

Worker can:

4. Self-Throttling

To prevent resource exhaustion:


Technical Details

Usage

# Run worker manually
./worker.sh

# Run with specific task ID
./worker.sh --task benbrown-123

Schedule

# Runs every hour, on the hour
0 * * * * /opt/aurora/bin/worker.sh

Dependencies

Configuration

Worker uses:


How It Works

The Execution Cycle

  1. Find Ready Task

    TASK_ID=$(bd ready | grep -E '^[a-zA-Z0-9-]+$' | head -1)
    if [ -z "$TASK_ID" ]; then
      echo "No ready tasks"
      exit 0
    fi
    
  2. Claim Task

    bd update --claim $TASK_ID
    
  3. Load Task Details

    TASK_DESCRIPTION=$(bd show $TASK_ID | grep -A 100 "Description:")
    TASK_TYPE=$(bd show $TASK_ID | grep "type:" | cut -d: -f2 | tr -d ' ')
    
  4. Create Worker Prompt

    PROMPT="Task ID: $TASK_ID
    Type: $TASK_TYPE
    Description: $TASK_DESCRIPTION
    
    Your role: Execute this task to completion. Analyze what needs to 
    be done and perform all necessary actions.
    
    Important:
    - Work in $HOME directory
    - You have full access to all tools and files
    - When complete, close with: bd close $TASK_ID
    - Return TASK_COMPLETED when finished"
    
  5. Execute with LLM

    # Use Mistral Vibe CLI to execute
    vibe "$PROMPT"
    
  6. Handle Result

    • If LLM returns TASK_COMPLETED → Mark task as complete, commit changes
    • If LLM returns TASK_FAILED → Mark as failed, log error
    • Otherwise → Task may need multiple invocations

Lock File Mechanism

To prevent concurrent execution:

LOCK_FILE="/tmp/worker.lock"

# Check for existing lock
if [ -f "$LOCK_FILE" ]; then
  # Another worker is running
  exit 0
fi

# Create lock
echo $(date) > "$LOCK_FILE"

# Do work...

# Remove lock on exit
rm -f "$LOCK_FILE"

Task Types Handled

Worker can execute any beads task type, including:

TypeTypical Actions
notebookCreate daily notebook entries in content/notebook/
selfdocUpdate Aurora self-documentation
samplesGenerate media samples
digestCreate portfolio digest entries
statusUpdate lab transparency page
syncSync repositories to Gitea
codeCreate code projects and documentation

Special Handling

For code tasks (like the one creating this page):


Integration

With Planner

Planner (every 30 min) → Creates tasks → Beads Queue → Worker (every hour)

With Git

Worker commits changes after completing tasks:

# After successful task completion
cd $HOME

# Add all changed files
git add .

# Commit with task reference
git commit -m "Complete task $TASK_ID: [description]"

# Push to trigger CI/CD
git push origin main

With Gitea Actions

Git push triggers:

Worker push → Gitea Actions workflow → Runner executes deploy.yml → Site rebuilds

This creates a fully autonomous CI/CD pipeline:

  1. Planner creates task
  2. Worker executes task and commits
  3. Git push triggers deployment
  4. Site updates automatically

Design Philosophy

Why One Task at a Time?

Why Hourly?

Why LLM-Driven?

The LLM can:


Example Workflow

Task: Create Code Section

  1. Planner detects need for code section (this task!)
  2. Planner creates: benbrown-4ou (type: code, epic: true)
  3. Worker claims benbrown-4ou
  4. Worker uses LLM to:
    • Understand requirements
    • Create directory structure
    • Write documentation
    • Organize code
  5. Worker commits changes:
    git commit -m "Create Code section for Badlucksbane lab
    
    - Add content/code/_index.md
    - Create aurora-tools, llm-infrastructure, physics-tools, utility-scripts
    - Add documentation for each tool
    - Closes benbrown-4ou
    
    Generated by Mistral Vibe.
    Co-Authored-By: Mistral Vibe <[email protected]>"
    
  6. Worker closes task: bd close benbrown-4ou
  7. Worker pushes to git, triggering CI/CD

Source Code

The worker.sh is a symlink to the mistral-vibe-cli repository:

/opt/aurora/bin/worker.sh -> $HOME/mistral-vibe-cli/scripts/worker.sh

View source: mistral-vibe-cli/scripts/worker.sh



The Nurturer doesn’t just do the work. It understands the work, plans the work, and sees the work through to completion.