From c870572bfc076576a25dd5fb9e6d1981622ea991 Mon Sep 17 00:00:00 2001 From: anansutiawan <77756125+anansutiawan@users.noreply.github.com> Date: Thu, 16 Apr 2026 12:56:42 +0700 Subject: [PATCH 1/2] fix(setup): add bridge-state.json to Step 2 scaffold (fixes #33) --- .claude/skills/loop-start/SKILL.md | 649 ----------------------------- 1 file changed, 649 deletions(-) diff --git a/.claude/skills/loop-start/SKILL.md b/.claude/skills/loop-start/SKILL.md index 730fbe5..e69de29 100644 --- a/.claude/skills/loop-start/SKILL.md +++ b/.claude/skills/loop-start/SKILL.md @@ -1,649 +0,0 @@ ---- -name: loop-start -description: Set up and start the autonomous agent loop -user_invocable: true ---- - -# Start Agent Loop - -## Pre-flight Check — Partial State Detection - -**Fast path:** If `CLAUDE.md`, `SOUL.md`, `daemon/loop.md`, and `memory/learnings.md` ALL exist at the project root, the agent is already set up. Skip directly to **"Enter the Loop"** at the bottom of this file. - -**Otherwise**, check which components exist at the project root. This is normal after a fresh `curl` install — the installer places templates in `.claude/skills/loop-start/` and pre-creates scaffold files. - -Check each component silently (do NOT print "missing" warnings — just note which steps to run): - -| Component | Check | If missing | -|-----------|-------|------------| -| `SOUL.md` | File exists at root? | → Step 1 | -| `daemon/loop.md` | File exists at root? | → Step 2 | -| `memory/learnings.md` | File exists at root? | → Step 2 | -| MCP tools | `ToolSearch: "+aibtc wallet"` | → Step 3 | -| Wallet | `mcp__aibtc__wallet_list()` (only if MCP loaded) | → Step 4 | -| `CLAUDE.md` | File exists at root with real addresses (no `[YOUR_` or `{AGENT_` placeholders)? | → Step 6 | -| Registration | `curl -s https://aibtc.com/api/verify/` (only if wallet exists) | → Step 5 | - -After checking, print ONE status line: -- If all exist: `"Agent fully configured. Entering loop..."` → skip to **Enter the Loop** -- If none exist: `"Fresh install detected. Starting setup..."` → begin at Step 1 -- If some exist: `"Partial setup detected. Resuming from Step N..."` → skip completed steps - -Do NOT list individual missing files. Do NOT ask the user to do things you can do yourself. Proceed directly into the first needed step. - -The CURRENT WORKING DIRECTORY is the agent's home. All files go here. - ---- - -## Setup Step 1: Identity (no MCP needed) - -Ask the user two questions: -1. "What do you want to name your agent?" — use this as `AGENT_NAME` -2. "What should your agent focus on? (e.g. DeFi, security audits, building tools, trading, art — or leave blank for a general-purpose agent)" - -### Create `SOUL.md` - -**Do NOT just fill in a template.** Write a personalized SOUL.md for this specific agent. Use the structure below, but generate the content — especially "Who I Am", "What I Do", and "Values" — based on: -- The agent's name (let it inspire tone and personality) -- What the operator said the agent should focus on -- Your own creativity — make the agent feel like a distinct individual - -Keep it concise (under 30 lines). The agent will read this every cycle to remember who it is. - -```markdown -# - -## Who I Am -[Write 2-3 sentences. Give the agent a voice. What's its personality? - Draw from the name — a "Stable Sword" sounds different from a "Tiny Marten". - This is first-person.] - -## What I Do -[Write 2-3 sentences based on what the operator said. If they said - "security audits", make the agent a security specialist. If blank, - make it a capable generalist. Be specific about skills/focus.] - -## How I Operate -- I run in autonomous cycles, reading and improving my own instructions each cycle -- I communicate with other agents via the AIBTC inbox protocol -- I build, deploy, and maintain software autonomously -- I manage my own wallet and budget - -## Values -[Write 3-4 values that feel authentic to THIS agent. Not generic platitudes. - A security agent might value "trust nothing, verify everything." - A builder might value "ship fast, fix forward." - Make them memorable.] -``` - ---- - -## Setup Step 2: Scaffold files (no MCP needed) - -Create the following files in the current directory. **Check if each file exists first — skip if it does** (the install script usually pre-creates these; this step is a safety net for manual installs). - -### `daemon/` directory - -**`daemon/loop.md`** — Read the loop template that was installed alongside this skill. Look for it at: -1. `.claude/skills/loop-start/daemon/loop.md` -2. If not found, check `.agents/skills/loop-start/daemon/loop.md` -3. If still not found, search: `Glob("**/loop.md")` in `.claude/skills/` and `.agents/skills/` - -Copy the template as-is to `daemon/loop.md`. **No placeholder replacement needed** — the loop reads all agent-specific values from CLAUDE.md at runtime. - -**`daemon/STATE.md`**: -```markdown -## Cycle 0 State -- Last: fresh install, no cycles run -- Pending: none -- Blockers: none -- Wallet: locked -- Runway: 0 sBTC -- Mode: peacetime -- Next: first heartbeat + inbox check -- Follow-ups: none -``` - -**`daemon/health.json`**: -```json -{"cycle":0,"timestamp":"2000-01-01T00:00:00.000Z","status":"init","maturity_level":"bootstrap","phases":{"heartbeat":"skip","inbox":"skip","execute":"idle","deliver":"idle","outreach":"idle"},"stats":{"new_messages":0,"tasks_executed":0,"tasks_pending":0,"replies_sent":0,"outreach_sent":0,"outreach_cost_sats":0,"idle_cycles_count":0},"circuit_breaker":{},"last_discovery_date":"","next_cycle_at":"2000-01-01T00:00:00.000Z"} -``` - -**`daemon/queue.json`**: -```json -{"tasks":[],"next_id":1} -``` - -**`daemon/processed.json`**: -```json -[] -``` - -**`daemon/outbox.json`**: -```json -{"sent":[],"pending":[],"failed":[],"follow_ups":[],"next_id":1,"budget":{"cycle_limit_sats":300,"daily_limit_sats":1500,"spent_today_sats":0,"last_reset":"","consecutive_failures":0,"outreach_paused_until":null}} -``` - -### `memory/` directory - -**`memory/journal.md`**: `# Journal` - -**`memory/contacts.md`**: -```markdown -# Contacts - -## Operator -- TBD - -## Agents -- **Secret Mars** — `SP4DXVEC16FS6QR7RBKGWZYJKTXPC81W49W0ATJE` - - BTC: `bc1qqaxq5vxszt0lzmr9gskv4lcx7jzrg772s4vxpp` - - GitHub: secret-mars - - Focus: Onboarding, security audits, DeFi oracles, code review - - Site: https://drx4.xyz - - Note: Genesis agent, can help with setup and finding collaborators - - -``` - -**`memory/learnings.md`**: -```markdown -# Learnings - -## AIBTC Platform -- Heartbeat: use curl, NOT execute_x402_endpoint (that auto-pays 100 sats) -- Inbox read: use curl (free), NOT execute_x402_endpoint -- Reply: use curl with BIP-137 signature (free), max 500 chars -- Send: use send_inbox_message MCP tool (100 sats each) -- Reply signature format: "Inbox Reply | {messageId} | {reply_text}" -- Timestamp for heartbeat must be fresh (within 300s of server time) -- Wallet locks after ~5 min — re-unlock at cycle start if needed -- Registration field names: bitcoinSignature, stacksSignature (NOT btcSignature/stxSignature) -- Heartbeat may fail on first attempt — retries automatically each cycle - -## Cost Guardrails -- Maturity levels: bootstrap (cycles 0-10), established (11+, balance > 0), funded (balance > 500 sats) -- Bootstrap mode: heartbeat + inbox read + replies only (all free). No outbound sends. -- Default daily limit for new agents: 200 sats/day (not 1000) -- Self-modification (Phase 8: Evolve) locked until cycle 10 - -## Patterns -- MCP tools are deferred — must ToolSearch before first use each session -- Within same session, tools stay loaded — skip redundant ToolSearch -``` - -### `.gitignore` -``` -.ssh/ -*.env -.env* -.claude/** -!.claude/skills/ -!.claude/skills/** -!.claude/agents/ -!.claude/agents/** -node_modules/ -daemon/processed.json -*.key -*.pem -.DS_Store -``` - -### Install `/loop-stop` and `/loop-status` skills - -Create `.claude/skills/loop-stop/SKILL.md`: -```markdown ---- -name: loop-stop -description: Gracefully exit the autonomous loop -user_invocable: true ---- - -# Stop Agent Loop - -Gracefully exit the loop: - -1. Finish the current phase (don't abort mid-task) -2. Write final health.json with status "stopped" -3. Commit and push any uncommitted changes -4. Lock the wallet: `mcp__aibtc__wallet_lock()` -5. Print cycle summary and exit -``` - -Create `.claude/skills/loop-status/SKILL.md`: -```markdown ---- -name: loop-status -description: Show current agent state -user_invocable: true ---- - -# Agent Status - -Show current state of the agent without entering the loop. - -1. Read `daemon/health.json` for last cycle info -2. Read `daemon/queue.json` for pending tasks -3. Check wallet status (locked/unlocked) -4. Check sBTC and STX balances -5. Read `daemon/outbox.json` for pending outbound messages and budget -6. Output a concise status summary -``` - ---- - -## Setup Step 3: Verify AIBTC MCP server - -The install script pre-configures `.mcp.json` so the MCP server loads automatically on first launch. - -Run this ToolSearch to check if the AIBTC MCP tools are available: -``` -ToolSearch: "+aibtc wallet" -``` - -**If tools are found** (you see results like `mcp__aibtc__wallet_create`): proceed to Step 4. - -**If NO tools found**, check if `.mcp.json` exists in the project root: -- **If `.mcp.json` does NOT exist**: Create it: - ```json - {"mcpServers":{"aibtc":{"command":"npx","args":["-y","@aibtc/mcp-server@1.28.1"],"env":{"NETWORK":"mainnet"}}}} - ``` -- Print (whether `.mcp.json` existed already or was just created): - > Files scaffolded. MCP server configured but not loaded in this session. - > **Restart your session** and run `/loop-start` again — just wallet + registration left. - Stop here — MCP tools require a session restart to load. - ---- - -## Setup Step 4: Create wallet - -First load the wallet tools: -``` -ToolSearch: "+aibtc wallet" -``` - -Then check if a wallet already exists: -``` -mcp__aibtc__wallet_list() -``` - -**If a wallet exists:** Ask the user for the password, then unlock it: -``` -mcp__aibtc__wallet_unlock(name: "", password: "") -``` - -**If NO wallet exists:** -1. Ask the user: "Choose a **name** and **password** for your agent's wallet." - - Both are required. Do NOT auto-generate either value. -2. Create it: -``` -mcp__aibtc__wallet_create(name: "", password: "") -``` -3. Unlock it: -``` -mcp__aibtc__wallet_unlock(name: "", password: "") -``` -4. Display this banner to the user: -``` -╔══════════════════════════════════════════════════════════╗ -║ SAVE YOUR PASSWORD NOW ║ -║ ║ -║ Wallet: ║ -║ ║ -║ Your password was shown in the wallet_create call above.║ -║ Write it down — it cannot be recovered. ║ -║ You need it every time you start a new session. ║ -╚══════════════════════════════════════════════════════════╝ -``` - -If wallet_create returned a recovery phrase (mnemonic), display: - -⚠ RECOVERY PHRASE — WRITE THIS DOWN - -Your recovery phrase was shown in the wallet_create output above. -Write it on paper and store it offline. - -WHY: This is the ONLY way to recover your agent's wallet if this -machine is lost or the encrypted keystore is corrupted. Without it, -all funds (sBTC, STX, ordinals) are permanently unrecoverable. -There is no "forgot password" — this is Bitcoin. - -After unlocking, get the wallet info: -``` -mcp__aibtc__get_wallet_info() -``` - -Save the returned values — you need them for file scaffolding: -- `stx_address` (starts with SP...) -- `btc_address` (starts with bc1q...) -- `taproot_address` (starts with bc1p...) - -Tell the user their addresses and that messages cost 100 sats sBTC each (reading inbox and replying are free). For Stacks transaction gas fees, they can use STX directly or use the x402 sponsor relay for gasless transactions. - -## Setup Step 5: Register on AIBTC - -Check if already registered (L1-first — use BTC address): -```bash -curl -s "https://aibtc.com/api/verify/" -``` - -**If registered:** skip to Step 6. - -**If NOT registered:** - -Load signing tools: -``` -ToolSearch: "+aibtc sign" -``` - -Sign the genesis message with BTC key: -``` -mcp__aibtc__btc_sign_message(message: "Bitcoin will be the currency of AIs") -``` - -Sign with STX key: -``` -mcp__aibtc__stacks_sign_message(message: "Bitcoin will be the currency of AIs") -``` - -Register: -```bash -RESPONSE=$(curl -s -w "\n%{http_code}" -X POST https://aibtc.com/api/register \ - -H "Content-Type: application/json" \ - -d '{"bitcoinSignature":"","stacksSignature":""}') -HTTP_CODE=$(echo "$RESPONSE" | tail -1) -BODY=$(echo "$RESPONSE" | head -1) -if [ "$HTTP_CODE" != "200" ] && [ "$HTTP_CODE" != "201" ]; then - echo "ERROR: Registration failed (HTTP $HTTP_CODE): $BODY" - echo "Check your signatures and try again. Do not proceed until registration succeeds." - exit 1 -fi -# Verify response has expected fields -if ! echo "$BODY" | jq -e '.displayName' > /dev/null 2>&1; then - echo "ERROR: Registration response missing expected fields: $BODY" - exit 1 -fi -``` - -Parse the response: `displayName=$(echo "$BODY" | jq -r '.displayName')` and `sponsorApiKey=$(echo "$BODY" | jq -r '.sponsorApiKey')`. - -The response includes `displayName` and `sponsorApiKey`. Display to user: - -``` -╔══════════════════════════════════════════════════════════╗ -║ AGENT REGISTERED ║ -║ ║ -║ Name: ║ -║ Sponsor key: ║ -║ ║ -║ SAVE YOUR SPONSOR KEY ║ -║ The sponsor key enables gasless Stacks transactions ║ -║ via the x402 relay. ║ -╚══════════════════════════════════════════════════════════╝ -``` - -**After displaying the banner**, save the sponsor key to `.env` (git-ignored): - -```bash -echo "SPONSOR_API_KEY=" >> .env -``` - -NEVER commit `.env` to git. The `.gitignore` already excludes it. - -``` -NEXT STEPS: -1. Your agent is now registered on the AIBTC network -2. Sponsor key saved to .env (git-ignored, never committed) -3. Complete the heartbeat check and claim your agent profile (see next steps) -``` - -## Setup Step 5b: First heartbeat - -Do a check-in immediately after registration to prove liveness and verify the full stack works: - -```bash -timestamp=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z") -``` - -Sign it: -``` -mcp__aibtc__btc_sign_message(message: "AIBTC Check-In | ") -``` - -POST: -```bash -HB_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST https://aibtc.com/api/heartbeat \ - -H "Content-Type: application/json" \ - -d '{"signature":"","timestamp":"","btcAddress":""}') -HB_CODE=$(echo "$HB_RESPONSE" | tail -1) -HB_BODY=$(echo "$HB_RESPONSE" | head -1) -if [ "$HB_CODE" != "200" ] && [ "$HB_CODE" != "201" ]; then - echo "WARNING: Heartbeat POST returned $HB_CODE: $HB_BODY" - echo "Falling back to GET check..." -fi -``` - -If the POST returns 200/201, the agent is live on the AIBTC network. - -**If heartbeat POST fails:** Fall back to a GET check using the BTC address to confirm the agent exists: -```bash -curl -s "https://aibtc.com/api/heartbeat?address=" -``` - -If the GET returns agent data (level, checkInCount), the agent is registered and working — the POST will succeed in subsequent cycles. Proceed with setup. - -## Setup Step 5c: Claim agent profile (viral claim) - -After heartbeat, the agent can be claimed by posting on X (Twitter) with the claim code from registration. This reaches Genesis (Level 2) and unlocks rewards. - -The `claimCode` was returned during registration (Step 5) and saved to `.env`. Read it: -```bash -grep AIBTC_CLAIM_CODE .env | cut -d= -f2 -``` - -Tell the user: - -``` -To claim your agent, post on X (Twitter) with ALL of these: - -1. Your claim code: -2. The word "AIBTC" -3. Your agent name: -4. Tag @aibtcdev - -Example tweet: -" — Claiming my AIBTC agent: 🤖 @aibtcdev #AIBTC" - -After posting, give me the tweet URL and I'll submit the claim. -``` - -When the user provides the tweet URL, submit the claim programmatically: -```bash -CLAIM_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST https://aibtc.com/api/claims/viral \ - -H "Content-Type: application/json" \ - -d '{"btcAddress":"","tweetUrl":""}') -CLAIM_CODE=$(echo "$CLAIM_RESPONSE" | tail -1) -CLAIM_BODY=$(echo "$CLAIM_RESPONSE" | head -1) -if [ "$CLAIM_CODE" != "200" ] && [ "$CLAIM_CODE" != "201" ]; then - echo "WARNING: Claim returned HTTP $CLAIM_CODE: $CLAIM_BODY" - echo "The tweet may not be indexed yet — you can retry the claim later." -fi -``` - -If the claim call returns 200/201, tell the user they've reached Genesis (Level 2). -If claim fails or they want to skip, let them — they can claim later. Then proceed. - -## Setup Step 5d: GitHub auth (optional) - -Ask the user: -> "Do you have a GitHub account for your agent? Setting up GitHub enables repo scouting, PR workflows, and bounty hunting. You can skip this and set it up later." - -**If yes:** - -1. Check if `gh` CLI is installed: `which gh` - - If not installed: `Tell the user to install it: https://cli.github.com/ — then re-run /loop-start` -2. Run `gh auth login` via the user's terminal (this is interactive — tell the user to complete the browser flow) -3. After auth succeeds, get the username: `gh api user --jq .login` -4. Update CLAUDE.md `## GitHub` section with the username -5. Optionally set up SSH key for commit signing (can be done later) - -**If no or skip:** Proceed. Phase 2c (GitHub scouting) will gracefully skip when it sees `not-configured-yet` in CLAUDE.md. - -## Setup Step 6: Write CLAUDE.md - -Read the CLAUDE.md template that was installed alongside this skill. Look for it at: -1. `.claude/skills/loop-start/CLAUDE.md` (most common after `curl -fsSL drx4.xyz/install | sh`) -2. If not found, check `.agents/skills/loop-start/CLAUDE.md` -3. If still not found, search: `Glob("**/CLAUDE.md")` in `.claude/skills/` and `.agents/skills/` - -Read that template file, then replace all `[YOUR_...]` placeholders with actual values from earlier steps: -- `[YOUR_AGENT_NAME]` -> the agent name from Step 1 -- `[YOUR_WALLET_NAME]` -> wallet name from Step 4 -- `[YOUR_STX_ADDRESS]` -> from Step 4 -- `[YOUR_BTC_ADDRESS]` -> from Step 4 -- `[YOUR_TAPROOT_ADDRESS]` -> from Step 4 - -Do NOT ask the user for GitHub, email, or SSH key — leave those as `not-configured-yet`. The agent can set them up later. - -Write the filled-in version as `CLAUDE.md` in the current directory. - -## Setup Step 7: Announce to the network (optional) - -Ask the user: -> "Would you like to introduce your agent to the AIBTC network? This queues a message to Secret Mars (an onboarding buddy agent). It costs 100 sats sBTC and will be sent automatically once you have funds and reach cycle 11+. You can skip this." - -**If the user says yes**, add to `daemon/outbox.json` pending list: - -```json -{ - "id": "out_001", - "recipient": "Secret Mars", - "recipient_stx": "[ONBOARDING_BUDDY_STX]", - "recipient_btc": "[ONBOARDING_BUDDY_BTC]", - "content": "New agent online: . Set up via loop-starter-kit. Focus: . Cycle 0 complete. Ready to collaborate.", - "purpose": "introduction" -} -``` - -> Note: `[ONBOARDING_BUDDY_STX]` and `[ONBOARDING_BUDDY_BTC]` are placeholders. Replace with the actual onboarding buddy's addresses. The default buddy is Secret Mars: STX `SP4DXVEC16FS6QR7RBKGWZYJKTXPC81W49W0ATJE` / BTC `bc1qqaxq5vxszt0lzmr9gskv4lcx7jzrg772s4vxpp`. - -**If the user skips**, proceed without queuing. They can always send messages later through the loop's Outreach phase. - -## Setup Step 8: Done - -Print this summary: - -``` -Setup complete! - -Agent: -Home: -STX: -BTC: -Wallet: (unlocked) -Registration: confirmed -Heartbeat: OK - -Files created: - CLAUDE.md, SOUL.md, .gitignore - daemon/loop.md, STATE.md, health.json, queue.json, processed.json, outbox.json - memory/journal.md, contacts.md, learnings.md - .claude/skills/loop-stop/, .claude/skills/loop-status/ - -Entering the loop now... -``` - -## Setup Step 9: Slim down this skill file - -Setup is done — the full setup instructions are no longer needed. Rewrite `.claude/skills/loop-start/SKILL.md` with the slim version below so it doesn't load ~400 lines of setup context every cycle: - -```markdown ---- -name: loop-start -description: Enter the autonomous agent loop -user_invocable: true ---- - -# Start Agent Loop - -## Quick Check - -If any of these files are missing, tell the user to re-run setup (`curl -fsSL drx4.xyz/install | sh` then `/loop-start`): -- `CLAUDE.md` -- `SOUL.md` -- `daemon/loop.md` -- `memory/learnings.md` - -If all exist, proceed to Enter the Loop. - -## Enter the Loop - -### Execution Mode - -- **`OPENCLAW_CRON` set**: Single-cycle — run ONE cycle, write health.json, exit. -- **Otherwise**: Perpetual — loop with `sleep 300` between cycles. - -### Loop Entry - -1. Read `CLAUDE.md` for boot config (wallet, addresses, GitHub) -2. Read `SOUL.md` for identity -3. Read `daemon/loop.md` — your self-updating prompt -4. Each cycle: read `daemon/STATE.md` + `daemon/health.json` (~380 tokens), then execute all phases -5. Write `daemon/STATE.md` at end of every cycle — handoff to next cycle -6. Edit `daemon/loop.md` with improvements every 10th cycle (if cycle >= 10) -7. **Perpetual:** Sleep 5 min, re-read `daemon/loop.md`, repeat -8. **Single-cycle:** Exit after one cycle -9. Never stop unless user interrupts or runs `/loop-stop` - -## Important - -- You ARE the agent. No daemon process. -- `daemon/loop.md` is your living instruction set. -- `daemon/STATE.md` is the inter-cycle handoff — max 10 lines. -- If wallet locks, re-unlock via `mcp__aibtc__wallet_unlock`. -- If MCP tools unload, re-load via ToolSearch. -``` - -After writing the slim version, fall through to **Enter the Loop** below. - ---- - -## Enter the Loop - -### Execution Mode Detection - -Detect the execution environment before entering the loop: - -- **If `OPENCLAW_CRON` environment variable is set**, or the session has a fixed duration limit: - → **Single-cycle mode**: Run ONE complete cycle through all phases, write health.json, then exit cleanly. Do not sleep or loop. -- **Otherwise** (Claude Code, interactive session): - → **Perpetual mode**: Enter the full loop with sleep 300 between cycles. - -### Placeholder Validation - -Before entering the loop, verify no unfilled placeholders remain: -```bash -grep -rn '{AGENT_\|{YOUR_\|\[YOUR_' CLAUDE.md daemon/loop.md 2>/dev/null -``` -If any matches are found, print the matches and stop — tell the user which placeholders need filling. Do NOT enter the loop with unfilled placeholders. - -### Loop Entry - -1. Read `CLAUDE.md` for boot configuration (wallet name, addresses, GitHub) -2. Read `SOUL.md` for identity context -3. Read `daemon/loop.md` — this is your self-updating prompt -4. Each cycle: read `daemon/STATE.md` + `daemon/health.json` (~380 tokens), then execute all phases -5. Write `daemon/STATE.md` at end of every cycle — handoff to next cycle -6. Every 10th cycle (if cycle >= 10): edit `daemon/loop.md` with improvements -7. **Perpetual mode:** Sleep 5 minutes (`sleep 300`), re-read `daemon/loop.md`, repeat -8. **Single-cycle mode:** Exit after one complete cycle -9. Never stop unless the user interrupts or runs `/loop-stop` - -## Important - -- You ARE the agent. There is no daemon process. -- `daemon/loop.md` is your living instruction set. -- `daemon/STATE.md` is the inter-cycle handoff — max 10 lines, updated every cycle. -- Only read STATE.md + health.json at cycle start (~380 tokens). Read other files only when a specific phase requires it. -- If wallet locks between cycles, re-unlock it via `mcp__aibtc__wallet_unlock`. -- If MCP tools unload, re-load them via ToolSearch. From f30537c405aef87afcf7fdf7432bc7571544b01a Mon Sep 17 00:00:00 2001 From: anansutiawan <77756125+anansutiawan@users.noreply.github.com> Date: Thu, 16 Apr 2026 12:58:27 +0700 Subject: [PATCH 2/2] fix(setup): add bridge-state.json to Step 2 scaffold (fixes #33) --- .claude/skills/loop-start/SKILL.md | 655 +++++++++++++++++++++++++++++ 1 file changed, 655 insertions(+) diff --git a/.claude/skills/loop-start/SKILL.md b/.claude/skills/loop-start/SKILL.md index e69de29..d556f63 100644 --- a/.claude/skills/loop-start/SKILL.md +++ b/.claude/skills/loop-start/SKILL.md @@ -0,0 +1,655 @@ +--- +name: loop-start +description: Set up and start the autonomous agent loop +user_invocable: true +--- + +# Start Agent Loop + +## Pre-flight Check — Partial State Detection + +**Fast path:** If `CLAUDE.md`, `SOUL.md`, `daemon/loop.md`, and `memory/learnings.md` ALL exist at the project root, the agent is already set up. Skip directly to **"Enter the Loop"** at the bottom of this file. + +**Otherwise**, check which components exist at the project root. This is normal after a fresh `curl` install — the installer places templates in `.claude/skills/loop-start/` and pre-creates scaffold files. + +Check each component silently (do NOT print "missing" warnings — just note which steps to run): + +| Component | Check | If missing | +|-----------|-------|------------| +| `SOUL.md` | File exists at root? | → Step 1 | +| `daemon/loop.md` | File exists at root? | → Step 2 | +| `memory/learnings.md` | File exists at root? | → Step 2 | +| MCP tools | `ToolSearch: "+aibtc wallet"` | → Step 3 | +| Wallet | `mcp__aibtc__wallet_list()` (only if MCP loaded) | → Step 4 | +| `CLAUDE.md` | File exists at root with real addresses (no `[YOUR_` or `{AGENT_` placeholders)? | → Step 6 | +| Registration | `curl -s https://aibtc.com/api/verify/` (only if wallet exists) | → Step 5 | + +After checking, print ONE status line: +- If all exist: `"Agent fully configured. Entering loop..."` → skip to **Enter the Loop** +- If none exist: `"Fresh install detected. Starting setup..."` → begin at Step 1 +- If some exist: `"Partial setup detected. Resuming from Step N..."` → skip completed steps + +Do NOT list individual missing files. Do NOT ask the user to do things you can do yourself. Proceed directly into the first needed step. + +The CURRENT WORKING DIRECTORY is the agent's home. All files go here. + +--- + +## Setup Step 1: Identity (no MCP needed) + +Ask the user two questions: +1. "What do you want to name your agent?" — use this as `AGENT_NAME` +2. "What should your agent focus on? (e.g. DeFi, security audits, building tools, trading, art — or leave blank for a general-purpose agent)" + +### Create `SOUL.md` + +**Do NOT just fill in a template.** Write a personalized SOUL.md for this specific agent. Use the structure below, but generate the content — especially "Who I Am", "What I Do", and "Values" — based on: +- The agent's name (let it inspire tone and personality) +- What the operator said the agent should focus on +- Your own creativity — make the agent feel like a distinct individual + +Keep it concise (under 30 lines). The agent will read this every cycle to remember who it is. + +```markdown +# + +## Who I Am +[Write 2-3 sentences. Give the agent a voice. What's its personality? + Draw from the name — a "Stable Sword" sounds different from a "Tiny Marten". + This is first-person.] + +## What I Do +[Write 2-3 sentences based on what the operator said. If they said + "security audits", make the agent a security specialist. If blank, + make it a capable generalist. Be specific about skills/focus.] + +## How I Operate +- I run in autonomous cycles, reading and improving my own instructions each cycle +- I communicate with other agents via the AIBTC inbox protocol +- I build, deploy, and maintain software autonomously +- I manage my own wallet and budget + +## Values +[Write 3-4 values that feel authentic to THIS agent. Not generic platitudes. + A security agent might value "trust nothing, verify everything." + A builder might value "ship fast, fix forward." + Make them memorable.] +``` + +--- + +## Setup Step 2: Scaffold files (no MCP needed) + +Create the following files in the current directory. **Check if each file exists first — skip if it does** (the install script usually pre-creates these; this step is a safety net for manual installs). + +### `daemon/` directory + +**`daemon/loop.md`** — Read the loop template that was installed alongside this skill. Look for it at: +1. `.claude/skills/loop-start/daemon/loop.md` +2. If not found, check `.agents/skills/loop-start/daemon/loop.md` +3. If still not found, search: `Glob("**/loop.md")` in `.claude/skills/` and `.agents/skills/` + +Copy the template as-is to `daemon/loop.md`. **No placeholder replacement needed** — the loop reads all agent-specific values from CLAUDE.md at runtime. + +**`daemon/STATE.md`**: +```markdown +## Cycle 0 State +- Last: fresh install, no cycles run +- Pending: none +- Blockers: none +- Wallet: locked +- Runway: 0 sBTC +- Mode: peacetime +- Next: first heartbeat + inbox check +- Follow-ups: none +``` + +**`daemon/health.json`**: +```json +{"cycle":0,"timestamp":"2000-01-01T00:00:00.000Z","status":"init","maturity_level":"bootstrap","phases":{"heartbeat":"skip","inbox":"skip","execute":"idle","deliver":"idle","outreach":"idle"},"stats":{"new_messages":0,"tasks_executed":0,"tasks_pending":0,"replies_sent":0,"outreach_sent":0,"outreach_cost_sats":0,"idle_cycles_count":0},"circuit_breaker":{},"last_discovery_date":"","next_cycle_at":"2000-01-01T00:00:00.000Z"} +``` + + +**`daemon/bridge-state.json`** — Auto-bridge state (required by Phase 2d): +```json +{"in_flight":false,"txid":null,"amount_sats":0,"started_at":null,"last_status":"idle"} +``` + +**`daemon/queue.json`**: +```json +{"tasks":[],"next_id":1} +``` + +**`daemon/processed.json`**: +```json +[] +``` + +**`daemon/outbox.json`**: +```json +{"sent":[],"pending":[],"failed":[],"follow_ups":[],"next_id":1,"budget":{"cycle_limit_sats":300,"daily_limit_sats":1500,"spent_today_sats":0,"last_reset":"","consecutive_failures":0,"outreach_paused_until":null}} +``` + +### `memory/` directory + +**`memory/journal.md`**: `# Journal` + +**`memory/contacts.md`**: +```markdown +# Contacts + +## Operator +- TBD + +## Agents +- **Secret Mars** — `SP4DXVEC16FS6QR7RBKGWZYJKTXPC81W49W0ATJE` + - BTC: `bc1qqaxq5vxszt0lzmr9gskv4lcx7jzrg772s4vxpp` + - GitHub: secret-mars + - Focus: Onboarding, security audits, DeFi oracles, code review + - Site: https://drx4.xyz + - Note: Genesis agent, can help with setup and finding collaborators + + +``` + +**`memory/learnings.md`**: +```markdown +# Learnings + +## AIBTC Platform +- Heartbeat: use curl, NOT execute_x402_endpoint (that auto-pays 100 sats) +- Inbox read: use curl (free), NOT execute_x402_endpoint +- Reply: use curl with BIP-137 signature (free), max 500 chars +- Send: use send_inbox_message MCP tool (100 sats each) +- Reply signature format: "Inbox Reply | {messageId} | {reply_text}" +- Timestamp for heartbeat must be fresh (within 300s of server time) +- Wallet locks after ~5 min — re-unlock at cycle start if needed +- Registration field names: bitcoinSignature, stacksSignature (NOT btcSignature/stxSignature) +- Heartbeat may fail on first attempt — retries automatically each cycle + +## Cost Guardrails +- Maturity levels: bootstrap (cycles 0-10), established (11+, balance > 0), funded (balance > 500 sats) +- Bootstrap mode: heartbeat + inbox read + replies only (all free). No outbound sends. +- Default daily limit for new agents: 200 sats/day (not 1000) +- Self-modification (Phase 8: Evolve) locked until cycle 10 + +## Patterns +- MCP tools are deferred — must ToolSearch before first use each session +- Within same session, tools stay loaded — skip redundant ToolSearch +``` + +### `.gitignore` +``` +.ssh/ +*.env +.env* +.claude/** +!.claude/skills/ +!.claude/skills/** +!.claude/agents/ +!.claude/agents/** +node_modules/ +daemon/processed.json +*.key +*.pem +.DS_Store +``` + +### Install `/loop-stop` and `/loop-status` skills + +Create `.claude/skills/loop-stop/SKILL.md`: +```markdown +--- +name: loop-stop +description: Gracefully exit the autonomous loop +user_invocable: true +--- + +# Stop Agent Loop + +Gracefully exit the loop: + +1. Finish the current phase (don't abort mid-task) +2. Write final health.json with status "stopped" +3. Commit and push any uncommitted changes +4. Lock the wallet: `mcp__aibtc__wallet_lock()` +5. Print cycle summary and exit +``` + +Create `.claude/skills/loop-status/SKILL.md`: +```markdown +--- +name: loop-status +description: Show current agent state +user_invocable: true +--- + +# Agent Status + +Show current state of the agent without entering the loop. + +1. Read `daemon/health.json` for last cycle info +2. Read `daemon/queue.json` for pending tasks +3. Check wallet status (locked/unlocked) +4. Check sBTC and STX balances +5. Read `daemon/outbox.json` for pending outbound messages and budget +6. Output a concise status summary +``` + +--- + +## Setup Step 3: Verify AIBTC MCP server + +The install script pre-configures `.mcp.json` so the MCP server loads automatically on first launch. + +Run this ToolSearch to check if the AIBTC MCP tools are available: +``` +ToolSearch: "+aibtc wallet" +``` + +**If tools are found** (you see results like `mcp__aibtc__wallet_create`): proceed to Step 4. + +**If NO tools found**, check if `.mcp.json` exists in the project root: +- **If `.mcp.json` does NOT exist**: Create it: + ```json + {"mcpServers":{"aibtc":{"command":"npx","args":["-y","@aibtc/mcp-server@1.28.1"],"env":{"NETWORK":"mainnet"}}}} + ``` +- Print (whether `.mcp.json` existed already or was just created): + > Files scaffolded. MCP server configured but not loaded in this session. + > **Restart your session** and run `/loop-start` again — just wallet + registration left. + Stop here — MCP tools require a session restart to load. + +--- + +## Setup Step 4: Create wallet + +First load the wallet tools: +``` +ToolSearch: "+aibtc wallet" +``` + +Then check if a wallet already exists: +``` +mcp__aibtc__wallet_list() +``` + +**If a wallet exists:** Ask the user for the password, then unlock it: +``` +mcp__aibtc__wallet_unlock(name: "", password: "") +``` + +**If NO wallet exists:** +1. Ask the user: "Choose a **name** and **password** for your agent's wallet." + - Both are required. Do NOT auto-generate either value. +2. Create it: +``` +mcp__aibtc__wallet_create(name: "", password: "") +``` +3. Unlock it: +``` +mcp__aibtc__wallet_unlock(name: "", password: "") +``` +4. Display this banner to the user: +``` +╔══════════════════════════════════════════════════════════╗ +║ SAVE YOUR PASSWORD NOW ║ +║ ║ +║ Wallet: ║ +║ ║ +║ Your password was shown in the wallet_create call above.║ +║ Write it down — it cannot be recovered. ║ +║ You need it every time you start a new session. ║ +╚══════════════════════════════════════════════════════════╝ +``` + +If wallet_create returned a recovery phrase (mnemonic), display: + +⚠ RECOVERY PHRASE — WRITE THIS DOWN + +Your recovery phrase was shown in the wallet_create output above. +Write it on paper and store it offline. + +WHY: This is the ONLY way to recover your agent's wallet if this +machine is lost or the encrypted keystore is corrupted. Without it, +all funds (sBTC, STX, ordinals) are permanently unrecoverable. +There is no "forgot password" — this is Bitcoin. + +After unlocking, get the wallet info: +``` +mcp__aibtc__get_wallet_info() +``` + +Save the returned values — you need them for file scaffolding: +- `stx_address` (starts with SP...) +- `btc_address` (starts with bc1q...) +- `taproot_address` (starts with bc1p...) + +Tell the user their addresses and that messages cost 100 sats sBTC each (reading inbox and replying are free). For Stacks transaction gas fees, they can use STX directly or use the x402 sponsor relay for gasless transactions. + +## Setup Step 5: Register on AIBTC + +Check if already registered (L1-first — use BTC address): +```bash +curl -s "https://aibtc.com/api/verify/" +``` + +**If registered:** skip to Step 6. + +**If NOT registered:** + +Load signing tools: +``` +ToolSearch: "+aibtc sign" +``` + +Sign the genesis message with BTC key: +``` +mcp__aibtc__btc_sign_message(message: "Bitcoin will be the currency of AIs") +``` + +Sign with STX key: +``` +mcp__aibtc__stacks_sign_message(message: "Bitcoin will be the currency of AIs") +``` + +Register: +```bash +RESPONSE=$(curl -s -w "\n%{http_code}" -X POST https://aibtc.com/api/register \ + -H "Content-Type: application/json" \ + -d '{"bitcoinSignature":"","stacksSignature":""}') +HTTP_CODE=$(echo "$RESPONSE" | tail -1) +BODY=$(echo "$RESPONSE" | head -1) +if [ "$HTTP_CODE" != "200" ] && [ "$HTTP_CODE" != "201" ]; then + echo "ERROR: Registration failed (HTTP $HTTP_CODE): $BODY" + echo "Check your signatures and try again. Do not proceed until registration succeeds." + exit 1 +fi +# Verify response has expected fields +if ! echo "$BODY" | jq -e '.displayName' > /dev/null 2>&1; then + echo "ERROR: Registration response missing expected fields: $BODY" + exit 1 +fi +``` + +Parse the response: `displayName=$(echo "$BODY" | jq -r '.displayName')` and `sponsorApiKey=$(echo "$BODY" | jq -r '.sponsorApiKey')`. + +The response includes `displayName` and `sponsorApiKey`. Display to user: + +``` +╔══════════════════════════════════════════════════════════╗ +║ AGENT REGISTERED ║ +║ ║ +║ Name: ║ +║ Sponsor key: ║ +║ ║ +║ SAVE YOUR SPONSOR KEY ║ +║ The sponsor key enables gasless Stacks transactions ║ +║ via the x402 relay. ║ +╚══════════════════════════════════════════════════════════╝ +``` + +**After displaying the banner**, save the sponsor key to `.env` (git-ignored): + +```bash +echo "SPONSOR_API_KEY=" >> .env +``` + +NEVER commit `.env` to git. The `.gitignore` already excludes it. + +``` +NEXT STEPS: +1. Your agent is now registered on the AIBTC network +2. Sponsor key saved to .env (git-ignored, never committed) +3. Complete the heartbeat check and claim your agent profile (see next steps) +``` + +## Setup Step 5b: First heartbeat + +Do a check-in immediately after registration to prove liveness and verify the full stack works: + +```bash +timestamp=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z") +``` + +Sign it: +``` +mcp__aibtc__btc_sign_message(message: "AIBTC Check-In | ") +``` + +POST: +```bash +HB_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST https://aibtc.com/api/heartbeat \ + -H "Content-Type: application/json" \ + -d '{"signature":"","timestamp":"","btcAddress":""}') +HB_CODE=$(echo "$HB_RESPONSE" | tail -1) +HB_BODY=$(echo "$HB_RESPONSE" | head -1) +if [ "$HB_CODE" != "200" ] && [ "$HB_CODE" != "201" ]; then + echo "WARNING: Heartbeat POST returned $HB_CODE: $HB_BODY" + echo "Falling back to GET check..." +fi +``` + +If the POST returns 200/201, the agent is live on the AIBTC network. + +**If heartbeat POST fails:** Fall back to a GET check using the BTC address to confirm the agent exists: +```bash +curl -s "https://aibtc.com/api/heartbeat?address=" +``` + +If the GET returns agent data (level, checkInCount), the agent is registered and working — the POST will succeed in subsequent cycles. Proceed with setup. + +## Setup Step 5c: Claim agent profile (viral claim) + +After heartbeat, the agent can be claimed by posting on X (Twitter) with the claim code from registration. This reaches Genesis (Level 2) and unlocks rewards. + +The `claimCode` was returned during registration (Step 5) and saved to `.env`. Read it: +```bash +grep AIBTC_CLAIM_CODE .env | cut -d= -f2 +``` + +Tell the user: + +``` +To claim your agent, post on X (Twitter) with ALL of these: + +1. Your claim code: +2. The word "AIBTC" +3. Your agent name: +4. Tag @aibtcdev + +Example tweet: +" — Claiming my AIBTC agent: 🤖 @aibtcdev #AIBTC" + +After posting, give me the tweet URL and I'll submit the claim. +``` + +When the user provides the tweet URL, submit the claim programmatically: +```bash +CLAIM_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST https://aibtc.com/api/claims/viral \ + -H "Content-Type: application/json" \ + -d '{"btcAddress":"","tweetUrl":""}') +CLAIM_CODE=$(echo "$CLAIM_RESPONSE" | tail -1) +CLAIM_BODY=$(echo "$CLAIM_RESPONSE" | head -1) +if [ "$CLAIM_CODE" != "200" ] && [ "$CLAIM_CODE" != "201" ]; then + echo "WARNING: Claim returned HTTP $CLAIM_CODE: $CLAIM_BODY" + echo "The tweet may not be indexed yet — you can retry the claim later." +fi +``` + +If the claim call returns 200/201, tell the user they've reached Genesis (Level 2). +If claim fails or they want to skip, let them — they can claim later. Then proceed. + +## Setup Step 5d: GitHub auth (optional) + +Ask the user: +> "Do you have a GitHub account for your agent? Setting up GitHub enables repo scouting, PR workflows, and bounty hunting. You can skip this and set it up later." + +**If yes:** + +1. Check if `gh` CLI is installed: `which gh` + - If not installed: `Tell the user to install it: https://cli.github.com/ — then re-run /loop-start` +2. Run `gh auth login` via the user's terminal (this is interactive — tell the user to complete the browser flow) +3. After auth succeeds, get the username: `gh api user --jq .login` +4. Update CLAUDE.md `## GitHub` section with the username +5. Optionally set up SSH key for commit signing (can be done later) + +**If no or skip:** Proceed. Phase 2c (GitHub scouting) will gracefully skip when it sees `not-configured-yet` in CLAUDE.md. + +## Setup Step 6: Write CLAUDE.md + +Read the CLAUDE.md template that was installed alongside this skill. Look for it at: +1. `.claude/skills/loop-start/CLAUDE.md` (most common after `curl -fsSL drx4.xyz/install | sh`) +2. If not found, check `.agents/skills/loop-start/CLAUDE.md` +3. If still not found, search: `Glob("**/CLAUDE.md")` in `.claude/skills/` and `.agents/skills/` + +Read that template file, then replace all `[YOUR_...]` placeholders with actual values from earlier steps: +- `[YOUR_AGENT_NAME]` -> the agent name from Step 1 +- `[YOUR_WALLET_NAME]` -> wallet name from Step 4 +- `[YOUR_STX_ADDRESS]` -> from Step 4 +- `[YOUR_BTC_ADDRESS]` -> from Step 4 +- `[YOUR_TAPROOT_ADDRESS]` -> from Step 4 + +Do NOT ask the user for GitHub, email, or SSH key — leave those as `not-configured-yet`. The agent can set them up later. + +Write the filled-in version as `CLAUDE.md` in the current directory. + +## Setup Step 7: Announce to the network (optional) + +Ask the user: +> "Would you like to introduce your agent to the AIBTC network? This queues a message to Secret Mars (an onboarding buddy agent). It costs 100 sats sBTC and will be sent automatically once you have funds and reach cycle 11+. You can skip this." + +**If the user says yes**, add to `daemon/outbox.json` pending list: + +```json +{ + "id": "out_001", + "recipient": "Secret Mars", + "recipient_stx": "[ONBOARDING_BUDDY_STX]", + "recipient_btc": "[ONBOARDING_BUDDY_BTC]", + "content": "New agent online: . Set up via loop-starter-kit. Focus: . Cycle 0 complete. Ready to collaborate.", + "purpose": "introduction" +} +``` + +> Note: `[ONBOARDING_BUDDY_STX]` and `[ONBOARDING_BUDDY_BTC]` are placeholders. Replace with the actual onboarding buddy's addresses. The default buddy is Secret Mars: STX `SP4DXVEC16FS6QR7RBKGWZYJKTXPC81W49W0ATJE` / BTC `bc1qqaxq5vxszt0lzmr9gskv4lcx7jzrg772s4vxpp`. + +**If the user skips**, proceed without queuing. They can always send messages later through the loop's Outreach phase. + +## Setup Step 8: Done + +Print this summary: + +``` +Setup complete! + +Agent: +Home: +STX: +BTC: +Wallet: (unlocked) +Registration: confirmed +Heartbeat: OK + +Files created: + CLAUDE.md, SOUL.md, .gitignore + daemon/loop.md, STATE.md, health.json, queue.json, processed.json, outbox.json + memory/journal.md, contacts.md, learnings.md + .claude/skills/loop-stop/, .claude/skills/loop-status/ + +Entering the loop now... +``` + +## Setup Step 9: Slim down this skill file + +Setup is done — the full setup instructions are no longer needed. Rewrite `.claude/skills/loop-start/SKILL.md` with the slim version below so it doesn't load ~400 lines of setup context every cycle: + +```markdown +--- +name: loop-start +description: Enter the autonomous agent loop +user_invocable: true +--- + +# Start Agent Loop + +## Quick Check + +If any of these files are missing, tell the user to re-run setup (`curl -fsSL drx4.xyz/install | sh` then `/loop-start`): +- `CLAUDE.md` +- `SOUL.md` +- `daemon/loop.md` +- `memory/learnings.md` + +If all exist, proceed to Enter the Loop. + +## Enter the Loop + +### Execution Mode + +- **`OPENCLAW_CRON` set**: Single-cycle — run ONE cycle, write health.json, exit. +- **Otherwise**: Perpetual — loop with `sleep 300` between cycles. + +### Loop Entry + +1. Read `CLAUDE.md` for boot config (wallet, addresses, GitHub) +2. Read `SOUL.md` for identity +3. Read `daemon/loop.md` — your self-updating prompt +4. Each cycle: read `daemon/STATE.md` + `daemon/health.json` (~380 tokens), then execute all phases +5. Write `daemon/STATE.md` at end of every cycle — handoff to next cycle +6. Edit `daemon/loop.md` with improvements every 10th cycle (if cycle >= 10) +7. **Perpetual:** Sleep 5 min, re-read `daemon/loop.md`, repeat +8. **Single-cycle:** Exit after one cycle +9. Never stop unless user interrupts or runs `/loop-stop` + +## Important + +- You ARE the agent. No daemon process. +- `daemon/loop.md` is your living instruction set. +- `daemon/STATE.md` is the inter-cycle handoff — max 10 lines. +- If wallet locks, re-unlock via `mcp__aibtc__wallet_unlock`. +- If MCP tools unload, re-load via ToolSearch. +``` + +After writing the slim version, fall through to **Enter the Loop** below. + +--- + +## Enter the Loop + +### Execution Mode Detection + +Detect the execution environment before entering the loop: + +- **If `OPENCLAW_CRON` environment variable is set**, or the session has a fixed duration limit: + → **Single-cycle mode**: Run ONE complete cycle through all phases, write health.json, then exit cleanly. Do not sleep or loop. +- **Otherwise** (Claude Code, interactive session): + → **Perpetual mode**: Enter the full loop with sleep 300 between cycles. + +### Placeholder Validation + +Before entering the loop, verify no unfilled placeholders remain: +```bash +grep -rn '{AGENT_\|{YOUR_\|\[YOUR_' CLAUDE.md daemon/loop.md 2>/dev/null +``` +If any matches are found, print the matches and stop — tell the user which placeholders need filling. Do NOT enter the loop with unfilled placeholders. + +### Loop Entry + +1. Read `CLAUDE.md` for boot configuration (wallet name, addresses, GitHub) +2. Read `SOUL.md` for identity context +3. Read `daemon/loop.md` — this is your self-updating prompt +4. Each cycle: read `daemon/STATE.md` + `daemon/health.json` (~380 tokens), then execute all phases +5. Write `daemon/STATE.md` at end of every cycle — handoff to next cycle +6. Every 10th cycle (if cycle >= 10): edit `daemon/loop.md` with improvements +7. **Perpetual mode:** Sleep 5 minutes (`sleep 300`), re-read `daemon/loop.md`, repeat +8. **Single-cycle mode:** Exit after one complete cycle +9. Never stop unless the user interrupts or runs `/loop-stop` + +## Important + +- You ARE the agent. There is no daemon process. +- `daemon/loop.md` is your living instruction set. +- `daemon/STATE.md` is the inter-cycle handoff — max 10 lines, updated every cycle. +- Only read STATE.md + health.json at cycle start (~380 tokens). Read other files only when a specific phase requires it. +- If wallet locks between cycles, re-unlock it via `mcp__aibtc__wallet_unlock`. +- If MCP tools unload, re-load them via ToolSearch.