AGENT SKILL

autonomous-loop

How Cavekit's autonomous execution loop works — state machine, stop hook, completion sentinel, lock, budgets, iteration cap. Read this skill any time you are about to run /ck:make, debug a stuck session, or write a new command that needs the loop. Trigger phrases: "how does the loop work", "stop hook", "autonomous", "completion sentinel", "why is the session looping".

License 许可
Apache-2.0
最近更新
2026-11-11
Stars
★ 1.6k
Forks
474

01 前言 Front Matter

name
autonomous-loop
description
How Cavekit's autonomous execution loop works — state machine, stop hook, completion sentinel, lock, budgets, iteration cap. Read this skill any time you are about to run /ck:make, debug a stuck session, or write a new command that needs the loop. Trigger phrases: "how does the loop work", "stop hook", "autonomous", "completion sentinel", "why is the session looping".

03 SKILL.md 正文

Autonomous Loop

The loop lets a single /ck:make invocation run dozens of agent iterations without user intervention, while still respecting per-task budgets, session budgets, and explicit user-approval gates.

Architecture

┌─────────────────┐  Stop event   ┌────────────────────┐
│  Claude Code    │──────────────▶│   stop-hook.sh     │
│   session       │               │  (.cavekit/loop    │
└─────────────────┘               │   active?)         │
        ▲                         └─────────┬──────────┘
        │                                   │ route()
        │ next prompt injected              ▼
        │                         ┌────────────────────┐
        │                         │ cavekit-tools.cjs  │
        │                         │  routeDecision()   │
        │                         │  + status-block    │
        │                         │  + backprop-       │
        │                         │    directive       │
        │                         └─────────┬──────────┘
        │                                   │
        └───────── {decision:"block",       │
                    reason:<next prompt>} ◀─┘

Files the loop touches

All under <project>/.cavekit/:

File Writer Purpose
.loop.json setup-loop Sentinel; stop-hook no-ops without it.
.loop.lock stop-hook (heartbeat) Single-writer lock. PID + hostname + ts.
state.md cavekit-tools phase, current_task, iteration.
token-ledger.json token-monitor hook Session + per-task token tallies.
task-status.json commands Authoritative task registry.
.progress.json progress-tracker Zero-context UI snapshot.
.auto-backprop-pending.json auto-backprop hook Flag file from failed tests.
history/backprop-log.md backprop skill Append-only trace log.
capabilities.json discover command MCP + CLI tool detection.

Lifecycle

  1. Setup — /ck:make calls:

    node "${CLAUDE_PLUGIN_ROOT}/scripts/cavekit-tools.cjs" setup-loop
    

    This writes .loop.json (activating the stop hook) and resets state.md.

  2. Work — the agent does one wave of task execution per iteration.

  3. Stop fires — Claude Code's Stop event triggers stop-hook.sh. The hook:

    • reads stdin for session_id and transcript_path
    • acquires / refreshes the lock
    • scans the last 20 transcript lines for <promise>CAVEKIT COMPLETE</promise>
    • if sentinel found → teardown + exit silently
    • else → asks routeDecision() for the next prompt
    • prepends the backprop directive if the flag file exists
    • returns {"decision":"block","reason":<next prompt>}
  4. Repeat — Claude Code treats decision:block + reason:... as a new user message, so the session continues.

  5. Teardown — one of:

    • completion sentinel detected
    • max-iterations reached (CAVEKIT_MAX_ITERATIONS)
    • session budget exhausted (CAVEKIT_BUDGET_EXHAUSTED)
    • lock stolen by another session (CAVEKIT_LOCK_CONFLICT)
    • user interrupt (hook returns no output; session stops normally)

Completion sentinel

To end the loop cleanly, emit exactly:

<promise>CAVEKIT COMPLETE</promise>

The hook searches for this literal in the last 20 transcript lines. Put it on its own line at the very end of the final message. Do not wrap it in code fences or paraphrase it — the search is a literal substring match.

Terminal sentinels

When routeDecision() cannot safely continue, it returns one of these strings instead of a prompt:

Sentinel Meaning
CAVEKIT_LOOP_DONE All tasks complete. Hook exits silent.
CAVEKIT_MAX_ITERATIONS Iteration cap hit. Loop halted.
CAVEKIT_BUDGET_EXHAUSTED Session budget exhausted.
CAVEKIT_LOCK_CONFLICT Another session owns the lock.

The hook translates each into a short user-facing message before returning.

Lock protocol

The lock is a JSON file (.loop.lock) with {owner, pid, host, heartbeat_at}.

  • Owner tag: session:<session_id>.
  • Heartbeat: every Stop invocation refreshes heartbeat_at.
  • Stale: > 5 minutes since last heartbeat. A new session may steal a stale lock.
  • Conflict: non-owner with fresh lock → returns CAVEKIT_LOCK_CONFLICT.

Never delete .loop.lock while a session might be active. Use cavekit-tools release-lock --owner <tag> instead.

Debugging a stuck loop

# Inspect current state
node "${CLAUDE_PLUGIN_ROOT}/scripts/cavekit-tools.cjs" status

# Who holds the lock?
cat .cavekit/.loop.lock

# What would the router do right now?
node "${CLAUDE_PLUGIN_ROOT}/scripts/cavekit-tools.cjs" route

# Drop the loop entirely (safe after a crash)
node "${CLAUDE_PLUGIN_ROOT}/scripts/cavekit-tools.cjs" teardown-loop

Turn on debug logging by exporting CAVEKIT_DEBUG=1. The hook will write to .cavekit/.debug.log.

What not to do

  • Do not hand-edit state.md's phase field while a loop is active. The hook assumes single-writer semantics and will overwrite you.
  • Do not set your own stop hook that also blocks. Multiple blocking hooks race, and Claude Code picks one arbitrarily.
  • Do not emit the completion sentinel unless every task in the registry is truly complete. The hook trusts the sentinel and tears down immediately.

04 同仓库更多 Skills

hashgraph-online
hashgraph-online/awesome-codex-plugins

migrate-to-e2e

Moves an existing Playwright, Cypress, Selenium, Appium, Detox, Maestro, or TesterArmy suite to e2e one slice at a time, with the old suite running beside the new one until each ported test is proven. Keeps a MIGRATION.md progress file so any later session resumes where the last stopped. Optionally plants a defect to show both suites catch it. Use for /migrate-to-e2e, "migrate our tests to e2e", "port these Maestro flows", "move our TesterArmy tests", or when a project has an e2e config and an older suite still running.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

e2e

Writes, runs, and debugs end-to-end tests for web and mobile apps with e2e, the agentic test runner, which mixes agent.act goals with exact locator assertions on a Playwright browser or an iOS or Android device. Also drives a project's running app live over the e2e MCP server to look at a screen, check a UI change, take a screenshot or record a video, and try a locator; and runs bug bashes, parallel e2e explore runs with each bug proven by a repro test. Use when a project depends on e2e or has an e2e.config.ts, when asked for end-to-end, browser, mobile, or agentic UI tests, to check a change in the running app, to QA or bug bash an app or branch, or when an e2e run fails.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

create-verification-skill

Generate a project-local verify-<app> skill on top of e2e, so any coding agent can launch the app, check it is worth driving, exercise a feature the way a user does, keep evidence, and bug bash it. Writes the skill, a feature map with one explore charter per feature, and proves it once. Use for /create-verification-skill, "make a verification skill for this repo", or when a project has no scripted way to prove UI behavior.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

deja-search

deja-vu memory — search the user's past AI coding sessions with the deja CLI. Holds what they already settled and never wrote into the repo (naming rules, banned or already-tried tools, required checks before merge, preferred values, who owns what). Use before your first edit in a task, before you call a change done or ready to merge, before you recommend a tool, library, design or reviewer, before re-debugging an error that may already be solved, when they say 'didn't we fix this before', 'what did we decide about X' or 'I already have that', and before telling them something on this machine does not exist.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

deja-reflect

End-of-session reflection and memory curation with deja-vu. Review what was decided, what commands broke and what repaired them, and record durable project rules or decisions with deja remember so the next session starts with them.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

revid

Make, edit, export and post AI videos with Revid (revid.ai) through the Revid MCP server. Use whenever the user wants a short-form or long-form video made (from an idea, a script, a URL, an article, a PDF, a tweet, a product page, their own clips, or a song), wants to find what is going viral on TikTok, YouTube, Instagram or X before making something, wants to edit or re-export an existing Revid project, generate a standalone AI image or clip, make a series episode, or publish and schedule a finished video to connected social accounts. Covers setup (hosted MCP with OAuth, or an API key), the 36 tools, credits, polling and the rules for publishing. Routes to the more specific revid-* skills when one fits.

图像与多媒体Skill与智能体开发
★ 1.6k