First-time setup for the Durable Agents stack (Mastra + Trigger.dev). Run once before using the main skill.
Setup Guide
Runs once. After setup is verified, remove the setup reference block from SKILL.md.
Execution Rules
These apply for the entire setup without exception.
Run every step in sequence. No skipping, no asking the user whether to continue.
Never stop for user input. Every known failure has a recovery path in this file. Go there, fix it, resume.
If a fix is not in this file, find the solution independently. Read logs, inspect the DB, check config files. Do not ask the user.
Never change package versions or swap libraries to fix an error. All versions in package.json are pinned intentionally. If a version mismatch appears to be the problem, the fix is in the configuration — not in bumping or changing a dependency.
After any recovery, re-run only the step that failed — not the full ./setup.sh — unless the recovery section says otherwise.
Confirm expected output before moving to the next step. Each step specifies what success looks like. Match it before continuing.
Report only at completion or on a genuinely unrecoverable failure. Unrecoverable means: not covered in this file, and independent investigation finds no path forward.
Prerequisites
Node.js 18+
Docker with Docker Compose
Docker daemon running
An AI provider API key (any OpenAI-compatible endpoint)
Setup Steps
Step 0: Check if already running
Before doing anything, verify the stack is not already up.
curl -s http://localhost:3000/health
If this returns {"status":"ok",...}, the stack is already running. Skip to the Post-Setup Checklist and confirm all checks pass. If they do, setup is complete — do not re-run anything.
If the API is not up, check whether the containers exist but are stopped:
cd trigger-infra && docker compose -p trigger ps
If containers exist but are stopped, bring them back up:
docker compose -p trigger up -d
cd ..
npm run dev
Then re-run the health check. Only proceed to Step 1 if no prior setup exists.
Step 1: Clone and enter the repo
git clone https://github.com/ainakwalamonk/durableclaw.git
cd mastra-triggers-openclaw
If it fails at any stage, go to the matching recovery section below. Fix it, then resume manually from that step.
Step 3: Verify infrastructure
Start the worker first (separate terminal), then run the test:
npm run trigger:dev # keep running
npm run trigger:test# in another terminal
trigger:test fires dummy-task via the Trigger.dev API and polls for completion. Pass = full Trigger.dev pipeline is working.
Step 4: Start the full system
npm run dev
Step 5: Health check
curl http://localhost:3000/health
Expected: {"status":"ok","timestamp":"..."}
Step 6: Configure LLM from the openclaw gateway
Do not hardcode or guess LLM credentials. Read them from the openclaw project on this machine.
Check in this order until you find the values:
Look for a gateway environment file or gateway service config in the openclaw project directory (e.g. gateway/.env, gateway/config.json, docker-compose.yml service named gateway, or any .env at the project root that contains AI_BASE_URL, AI_API_KEY, or MODEL_ID).
Look for an openclaw config JSON (e.g. openclaw.config.json, config/openclaw.json, or any JSON referencing model/provider settings).
If neither exists, check running Docker containers for an AI gateway service:
Once you have AI_BASE_URL, AI_API_KEY, and MODEL_ID, write them to .env in this project:
sed -i ''"s|^AI_BASE_URL=.*|AI_BASE_URL=<value>|" .env
sed -i ''"s|^AI_API_KEY=.*|AI_API_KEY=<value>|" .env
sed -i ''"s|^MODEL_ID=.*|MODEL_ID=<value>|" .env
Step 7: Smoke test
Run the infrastructure smoke test:
npm run trigger:test
Expected: dummy-task completes with status COMPLETED. This test makes no LLM call — a pass here means the full Trigger.dev pipeline is operational.
If Step 6 failed to find real LLM credentials and .env is missing AI_BASE_URL, AI_API_KEY, or MODEL_ID, fill them with placeholders only for this test so the worker starts:
Then re-run npm run trigger:test. Placeholders are only acceptable here — Step 8 requires real credentials. If you used placeholders, resolve the LLM config from the openclaw gateway before continuing.
If the smoke test fails, the problem is in the infrastructure — go to the Recovery section. Do not debug LLM credentials until this passes.
Step 8: Test the AI pipeline
Once real LLM credentials are in .env from Step 6:
curl -X POST http://localhost:3000/pipeline \
-H "Content-Type: application/json" \
-d '{"prompt": "Build a URL shortener service"}'
Expected: JSON with plan, review, and run IDs.
Step 9: Verify Trigger.dev dashboard
Open http://localhost:3040 and confirm the run appears.
Recovery
Docker not installed or not running
docker info
macOS:
brew install --cask docker
# Open Docker Desktop and wait for it to start
This project uses ESM. import statements are hoisted above all code execution, including dotenv.config(). Any module that reads env vars at the top level will fail if loaded statically before .env is parsed.
Fix: all run/test commands use --env-file=.env (already in package.json). Do not remove that flag.
AGENT.md files and the Trigger.dev worker
Trigger.dev v3 bundles code for the worker. External .md files are not bundled by default — fs.readFileSync on AGENT.md will throw ENOENT in the worker.
Fix: embed agent instructions as a string constant directly in the agent's .ts file. Do not use fs.readFileSync for agent instructions.
Architecture
Path
Purpose
src/config/model.ts
Model singleton. Requires AI_BASE_URL, AI_API_KEY, MODEL_ID.