leek/agent-skills / skills/autopilot
autopilot
VerifiedBuild a whole spec while you are away. Asks every question up front, then a runner drives parallel fresh top-level Claude Code, Codex, or Grok sessions, one per ticket in its own worktree, onto one integration branch, delivered as one PR or a stack of PRs.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 10.5 KB |
| agents/openai.yaml | config | 264 B |
| references/worker.md | markdown | 9.7 KB |
| scripts/autopilot.shexecutable | script | 13.5 KB |
| scripts/land.shexecutable | script | 6.2 KB |
| scripts/lib/observer.sh | script | 9.9 KB |
| scripts/lib/output.sh | script | 2.4 KB |
| scripts/lib/process.sh | script | 5.0 KB |
| scripts/lib/provider.sh | script | 12.2 KB |
| scripts/lib/runner.sh | script | 33.5 KB |
| scripts/lib/state.sh | script | 7.9 KB |
| scripts/lib/tickets.sh | script | 6.9 KB |
| scripts/lib/tmux.sh | script | 7.5 KB |
| scripts/result-schema.json | config | 526 B |
| scripts/test-land.sh | script | 4.4 KB |
| scripts/test-root-key.shexecutable | script | 8.6 KB |
| scripts/test-run.sh | script | 12.7 KB |
| scripts/test-tmux.shexecutable | script | 10.6 KB |
scripts/lib/state.sh
View on GitHub#!/bin/bash
# Persisted Autopilot state and terminal result lifecycle.
set -e
json_failure() {
local reason="$1"
if command -v jq >/dev/null 2>&1; then
jq -cn --arg reason "$reason" '{status:"failed",completed_ref:"",next_ref:"",summary:"Autopilot stopped.",reason:$reason}'
else
local escaped="${reason//\\/\\\\}"
escaped="${escaped//\"/\\\"}"
printf '{"status":"failed","completed_ref":"","next_ref":"","summary":"Autopilot stopped.","reason":"%s"}\n' "$escaped"
fi
}
# The physical path of an existing file or directory: every symbolic link
# resolved, in the directories and in the file itself.
physical_path() {
local target="$1" parent name link hops=0
while :; do
if [[ -d "$target" ]]; then
(cd "$target" && pwd -P)
return
fi
[[ -e "$target" ]] || return 1
parent="$(cd "$(dirname "$target")" && pwd -P)" || return 1
name="$(basename "$target")"
if [[ ! -L "$parent/$name" ]]; then
printf '%s/%s\n' "${parent%/}" "$name"
return 0
fi
hops=$((hops + 1))
[[ "$hops" -le 40 ]] || return 1
link="$(readlink "$parent/$name")" || return 1
[[ "$link" == /* ]] || link="$parent/$link"
target="$link"
done
}
# One spelling per root, so every way of naming one tracker gives one STATE_KEY
# and one LOCK_DIR: no trailing slash, absolute, physical. A relative root is
# read against the --repo directory (the current directory by default), then
# against the repository root when it exists only there. A root that does not
# exist keeps its name under its physical parent directory.
canonical_root_ref() {
local ref="$1" candidate parent
while [[ "$ref" == */ && "$ref" != "/" ]]; do
ref="${ref%/}"
done
if [[ "$ref" == /* ]]; then
candidate="$ref"
else
candidate="$ORIGINAL_DIR/$ref"
if [[ ! -e "$candidate" && -e "$REPO_ROOT/$ref" ]]; then
candidate="$REPO_ROOT/$ref"
fi
fi
if [[ -e "$candidate" ]]; then
physical_path "$candidate"
return
fi
parent="$(dirname "$candidate")"
if [[ -d "$parent" ]]; then
parent="$(cd "$parent" && pwd -P)" || return 1
printf '%s/%s\n' "${parent%/}" "$(basename "$candidate")"
else
printf '%s\n' "$candidate"
fi
}
# Sets the state, lock, and run paths for REPO_ROOT and the canonical ROOT_REF.
resolve_state_paths() {
STATE_DIR="$GIT_DIR/autopilot"
STATE_KEY="$(printf '%s\0%s' "$REPO_ROOT" "$ROOT_REF" | git hash-object --stdin)"
STATE_FILE="$STATE_DIR/$STATE_KEY.json"
LOCK_DIR="$STATE_DIR/$STATE_KEY.lock"
RUNS_DIR="$STATE_DIR/runs"
}
read_state_fields() {
local state_file="$1" query="$2" sentinel="__AUTOPILOT_STATE_END__" snapshot last_index
snapshot="$(jq -jr --arg sentinel "$sentinel" \
"(($query) + [\$sentinel]) | map(if . == null then \"\" else tostring end) | join(\"\\u001f\")" \
"$state_file")" || return 1
IFS=$'\x1f' read -r -a STATE_FIELDS <<<"$snapshot"
last_index=$((${#STATE_FIELDS[@]} - 1))
unset "STATE_FIELDS[$last_index]"
}
persist_state() {
[[ "$STATE_ACTIVE" == "true" && -n "$STATE_FILE" && -n "$RUN_ID" ]] || return 0
local state_temp run_state_temp
state_temp="$(mktemp "$STATE_DIR/.state.XXXXXX")" || return 1
jq -cn \
--arg run_id "$RUN_ID" \
--arg root_ref "$ROOT_REF" \
--arg repo_root "$REPO_ROOT" \
--arg created_at "$CREATED_AT" \
--arg status "$RUN_STATUS" \
--arg phase "$RUN_PHASE" \
--arg provider "$PROVIDER" \
--arg model "$WORKER_MODEL" \
--arg model_source "$WORKER_MODEL_SOURCE" \
--arg reported_model "$REPORTED_MODEL" \
--arg effort "$WORKER_EFFORT" \
--arg effort_source "$WORKER_EFFORT_SOURCE" \
--arg runner_pid "$RUNNER_PID_STATE" \
--arg runner_process_started "$RUNNER_PROCESS_STARTED" \
--argjson workers "${WORKERS_JSON:-[]}" \
--arg integration "$INTEGRATION_DIR" \
--arg branch "$BRANCH" \
--arg notes "$NOTES_DIR" \
--arg delivery "$DELIVERY" \
--arg cleanup "$CLEANUP" \
--arg concurrency "$CONCURRENCY" \
--arg finished_at "$FINISHED_AT" \
--arg iteration "$ITERATION" \
--arg max_iterations "$MAX_ITERATIONS" \
--arg heartbeat_seconds "$HEARTBEAT_SECONDS" \
--arg quiet_seconds "$QUIET_SECONDS" \
--arg log_file "$LOG_FILE" \
--arg log_mirror_file "$LOG_MIRROR_FILE" \
--arg activity_file "$ACTIVITY_FILE" \
--arg tmux_session "$TMUX_SESSION" \
--arg tmux_launch_id "$TMUX_LAUNCH_ID" \
--arg summary "$SUMMARY" \
--arg reason "$REASON" \
--arg completed_ref "$LAST_COMPLETED_REF" \
--arg next_ref "$NEXT_REF_STATE" \
--arg result_file "$RESULT_FILE_STATE" \
'{
version: 4,
run_id: $run_id,
root_ref: $root_ref,
repo_root: $repo_root,
created_at: $created_at,
status: $status,
phase: $phase,
provider: $provider,
model: $model,
model_source: $model_source,
reported_model: (if $reported_model == "" then null else $reported_model end),
effort: $effort,
effort_source: $effort_source,
runner_pid: (if $runner_pid == "" then null else ($runner_pid | tonumber) end),
runner_process_started: (if $runner_process_started == "" then null else $runner_process_started end),
workers: $workers,
integration: (if $integration == "" then null else $integration end),
branch: (if $branch == "" then null else $branch end),
notes: (if $notes == "" then null else $notes end),
delivery: $delivery,
cleanup: $cleanup,
concurrency: ($concurrency | tonumber),
finished_at: (if $finished_at == "" then null else $finished_at end),
iteration: ($iteration | tonumber),
max_iterations: ($max_iterations | tonumber),
heartbeat_seconds: ($heartbeat_seconds | tonumber),
quiet_seconds: ($quiet_seconds | tonumber),
log_file: $log_file,
log_mirror_file: (if $log_mirror_file == "" then null else $log_mirror_file end),
activity_file: $activity_file,
tmux_session: (if $tmux_session == "" then null else $tmux_session end),
tmux_launch_id: (if $tmux_launch_id == "" then null else $tmux_launch_id end),
summary: $summary,
reason: $reason,
completed_ref: $completed_ref,
next_ref: $next_ref,
result_file: (if $result_file == "" then null else $result_file end)
}' >"$state_temp"
run_state_temp="$(mktemp "$RUN_DIR/.state.XXXXXX")" || {
rm -f -- "$state_temp"
return 1
}
cp -- "$state_temp" "$run_state_temp" || {
rm -f -- "$state_temp" "$run_state_temp"
return 1
}
mv -- "$run_state_temp" "$RUN_DIR/state.json"
mv -- "$state_temp" "$STATE_FILE"
}
transition_to_terminal() {
RUN_STATUS="$1"
RUN_PHASE="terminal"
FINISHED_AT="$(timestamp)"
RUNNER_PID_STATE=""
WORKERS_JSON="[]"
}
record_terminal_state() {
local status="$1" summary="$2" reason="$3"
[[ "$STATE_ACTIVE" == "true" && -n "$RUN_ID" ]] || return 0
transition_to_terminal "$status"
SUMMARY="$summary"
REASON="$reason"
LAST_COMPLETED_REF=""
NEXT_REF_STATE=""
RESULT_FILE_STATE="$RUN_DIR/last-result.json"
jq -cn \
--arg status "$status" \
--arg summary "$summary" \
--arg reason "$reason" \
'{status:$status,completed_ref:"",next_ref:"",summary:$summary,reason:$reason}' >"$RESULT_FILE_STATE" || true
persist_state || true
}
record_failure_state() {
record_terminal_state "failed" "Autopilot stopped." "$1"
}
validate_state() {
local state_file="$1"
jq -e --arg root "$ROOT_REF" --arg repo "$REPO_ROOT" '
(.version == 1 or .version == 2 or .version == 3 or .version == 4) and
.root_ref == $root and
.repo_root == $repo and
(.run_id | type == "string" and length > 0)
' "$state_file" >/dev/null 2>&1
}
run_log_file() {
printf '%s/%s/autopilot.log' "$RUNS_DIR" "$1"
}
state_log_file() {
local state_file="$1"
local run_id log_file
read_state_fields "$state_file" '[.run_id, (.log_file // "")]'
run_id="${STATE_FIELDS[0]:-}"
log_file="${STATE_FIELDS[1]:-}"
[[ -n "$log_file" ]] || log_file="$(run_log_file "$run_id")"
printf '%s' "$log_file"
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |