Skip to content

leek/agent-skills / skills/autopilot

autopilot

Verified

Build 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.

FileKindSize
SKILL.mdskill md10.5 KB
agents/openai.yamlconfig264 B
references/worker.mdmarkdown9.7 KB
scripts/autopilot.shexecutablescript13.5 KB
scripts/land.shexecutablescript6.2 KB
scripts/lib/observer.shscript9.9 KB
scripts/lib/output.shscript2.4 KB
scripts/lib/process.shscript5.0 KB
scripts/lib/provider.shscript12.2 KB
scripts/lib/runner.shscript33.5 KB
scripts/lib/state.shscript7.9 KB
scripts/lib/tickets.shscript6.9 KB
scripts/lib/tmux.shscript7.5 KB
scripts/result-schema.jsonconfig526 B
scripts/test-land.shscript4.4 KB
scripts/test-root-key.shexecutablescript8.6 KB
scripts/test-run.shscript12.7 KB
scripts/test-tmux.shexecutablescript10.6 KB

scripts/lib/observer.sh

View on GitHub
#!/bin/bash
# Status, log following, history, and observer command presentation.

set -e

FOLLOW_STATE_STATUS=""
FOLLOW_STATE_RUNNER_PID=""
FOLLOW_STATE_RUNNER_STARTED=""

print_observer_commands() {
  local emitter="$1" tmux_session="${2:-}" tmux_alive="${3:-true}"

  "$emitter" "status: $(shell_join bash "$SCRIPT_PATH" --status --root "$ROOT_REF" --repo "$REPO_ROOT")"
  "$emitter" "follow: $(shell_join bash "$SCRIPT_PATH" --follow --root "$ROOT_REF" --repo "$REPO_ROOT")"
  "$emitter" "history: $(shell_join bash "$SCRIPT_PATH" --history --root "$ROOT_REF" --repo "$REPO_ROOT")"
  if [[ -n "$tmux_session" && "$tmux_alive" == "true" ]]; then
    "$emitter" "attach: $(shell_join tmux attach -t "$tmux_session")"
  elif [[ -n "$tmux_session" ]]; then
    "$emitter" "tmux session has already exited; use status or follow"
  fi
}

read_follow_state() {
  read_state_fields "$1" '[
    (.status // "interrupted"),
    ((.runner_pid // "") | tostring),
    (.runner_process_started // "")
  ]'
  FOLLOW_STATE_STATUS="${STATE_FIELDS[0]:-interrupted}"
  FOLLOW_STATE_RUNNER_PID="${STATE_FIELDS[1]:-}"
  FOLLOW_STATE_RUNNER_STARTED="${STATE_FIELDS[2]:-}"
}

print_status() {
  if [[ ! -f "$STATE_FILE" ]]; then
    emit_stderr "no Autopilot run found for this root"
    jq -cn --arg root "$ROOT_REF" '{status:"none",root:$root,runner_alive:false,worker_alive:false,tmux_alive:false}'
    exit 1
  fi
  validate_state "$STATE_FILE" || runner_failure "runner state is invalid: $STATE_FILE"

  local runner_pid runner_process_started runner_alive worker_alive workers_alive=0 worker_rows worker_pid worker_started
  local current_branch current_delivery current_concurrency
  local tmux_session tmux_alive activity_file last_event_epoch last_event_at current_status current_iteration current_max log_file
  local current_model current_model_source current_reported_model current_effort current_effort_source model_display
  read_state_fields "$STATE_FILE" '[
    ((.runner_pid // "") | tostring),
    (.branch // ""),
    (.runner_process_started // ""),
    (.delivery // ""),
    (.tmux_session // ""),
    (.activity_file // ""),
    (.status // "interrupted"),
    ((.iteration // 0) | tostring),
    ((.max_iterations // 0) | tostring),
    (.model // ""),
    (.model_source // ""),
    (.reported_model // ""),
    (.effort // ""),
    (.effort_source // "")
  ]'
  runner_pid="${STATE_FIELDS[0]:-}"
  current_branch="${STATE_FIELDS[1]:-}"
  runner_process_started="${STATE_FIELDS[2]:-}"
  current_delivery="${STATE_FIELDS[3]:-}"
  tmux_session="${STATE_FIELDS[4]:-}"
  activity_file="${STATE_FIELDS[5]:-}"
  current_status="${STATE_FIELDS[6]:-interrupted}"
  current_iteration="${STATE_FIELDS[7]:-0}"
  current_max="${STATE_FIELDS[8]:-0}"
  current_model="${STATE_FIELDS[9]:-}"
  current_model_source="${STATE_FIELDS[10]:-}"
  current_reported_model="${STATE_FIELDS[11]:-}"
  current_effort="${STATE_FIELDS[12]:-}"
  current_effort_source="${STATE_FIELDS[13]:-}"

  if pid_is_alive "$runner_pid" "$runner_process_started"; then runner_alive=true; else runner_alive=false; fi
  worker_rows="$(jq -r '(.workers // [])[] | [(.pid | tostring), (.process_started // "")] | @tsv' "$STATE_FILE")"
  while IFS=$'\t' read -r worker_pid worker_started; do
    [[ -n "$worker_pid" ]] || continue
    if pid_is_alive "$worker_pid" "$worker_started"; then
      workers_alive=$((workers_alive + 1))
    fi
  done <<<"$worker_rows"
  if [[ "$workers_alive" -gt 0 ]]; then worker_alive=true; else worker_alive=false; fi
  current_concurrency="$(jq -r '(.concurrency // "") | tostring' "$STATE_FILE")"
  tmux_alive=false
  if [[ -n "$tmux_session" ]] && command -v tmux >/dev/null 2>&1 && tmux has-session -t "$tmux_session" 2>/dev/null; then
    tmux_alive=true
  fi
  last_event_epoch="$(file_mtime "$activity_file")"
  last_event_at="$(iso_from_epoch "$last_event_epoch")"
  log_file="$(state_log_file "$STATE_FILE")"

  printf 'Autopilot: status %s (worker session %s/%s); runner %s; workers alive %s\n' \
    "$current_status" "$current_iteration" "$current_max" \
    "$([[ "$runner_alive" == true ]] && printf alive || printf stopped)" \
    "$workers_alive" >&2
  if [[ -n "$current_branch" ]]; then
    emit_stderr "integration branch $current_branch; delivery ${current_delivery:-unknown}; up to ${current_concurrency:-?} workers at once"
  fi
  if [[ -n "$current_model" || -n "$current_reported_model" || -n "$current_effort" ]]; then
    if [[ -n "$current_reported_model" ]]; then
      model_display="$current_reported_model (reported)"
    else
      model_display="${current_model:-unknown} (${current_model_source:-unknown})"
    fi
    emit_stderr "worker session model $model_display, effort ${current_effort:-unknown} (${current_effort_source:-unknown})"
  fi
  emit_stderr "log $log_file"

  jq -c \
    --argjson runner_alive "$runner_alive" \
    --argjson worker_alive "$worker_alive" \
    --argjson workers_alive "$workers_alive" \
    --argjson tmux_alive "$tmux_alive" \
    --arg last_event_at "$last_event_at" \
    '. + {
      runner_alive: $runner_alive,
      worker_alive: $worker_alive,
      workers_alive: $workers_alive,
      tmux_alive: $tmux_alive,
      last_event_at: (if $last_event_at == "" then null else $last_event_at end)
    }' "$STATE_FILE"
}

follow_log() {
  [[ -f "$STATE_FILE" ]] || runner_failure "no Autopilot run found for this root"
  validate_state "$STATE_FILE" || runner_failure "runner state is invalid: $STATE_FILE"

  local follow_run_id follow_state_file log_file current_status runner_pid runner_process_started tail_pid
  read_state_fields "$STATE_FILE" '[.run_id]'
  follow_run_id="${STATE_FIELDS[0]:-}"
  follow_state_file="$RUNS_DIR/$follow_run_id/state.json"
  [[ -f "$follow_state_file" ]] || follow_state_file="$STATE_FILE"
  log_file="$(state_log_file "$follow_state_file")"
  [[ -f "$log_file" ]] || runner_failure "run log not found: $log_file"

  read_follow_state "$follow_state_file"
  current_status="$FOLLOW_STATE_STATUS"
  runner_pid="$FOLLOW_STATE_RUNNER_PID"
  runner_process_started="$FOLLOW_STATE_RUNNER_STARTED"
  if [[ "$current_status" != "running" ]]; then
    emit_stderr "run is $current_status; showing the final log"
    tail -n 50 "$log_file"
    return 0
  fi
  if ! pid_is_alive "$runner_pid" "$runner_process_started"; then
    emit_stderr "runner stopped without recording terminal state"
    tail -n 50 "$log_file"
    return 5
  fi

  emit_stderr "following $log_file until the run stops (Ctrl-C to stop early)"
  tail -n 50 -F "$log_file" &
  tail_pid=$!
  CHILD_PIDS+=("$tail_pid")
  while kill -0 "$tail_pid" 2>/dev/null; do
    sleep 2
    read_follow_state "$follow_state_file"
    current_status="$FOLLOW_STATE_STATUS"
    runner_pid="$FOLLOW_STATE_RUNNER_PID"
    runner_process_started="$FOLLOW_STATE_RUNNER_STARTED"
    if [[ "$current_status" != "running" ]] || ! pid_is_alive "$runner_pid" "$runner_process_started"; then
      sleep 1
      kill "$tail_pid" 2>/dev/null || true
      wait "$tail_pid" 2>/dev/null || true
      CHILD_PIDS=()
      emit_stderr "final log tail"
      tail -n 5 "$log_file"
      if [[ "$current_status" == "running" ]]; then
        emit_stderr "runner stopped without recording terminal state"
        return 5
      fi
      emit_stderr "run reached $current_status"
      return 0
    fi
  done
}

# --wait: block until the run leaves `running`, then print the final state object
# on stdout and exit with the run's terminal code (0 complete, 2 needs_input,
# 3 blocked, 4 failed, 5 runner died / no run). One background call replaces a
# sleep-poll loop.
wait_for_run() {
  if [[ ! -f "$STATE_FILE" ]]; then
    emit_stderr "no Autopilot run found for this root"
    jq -cn --arg root "$ROOT_REF" '{status:"none",root:$root}'
    return 5
  fi
  validate_state "$STATE_FILE" || runner_failure "runner state is invalid: $STATE_FILE"

  local wait_run_id wait_state_file current_status runner_pid runner_process_started interval
  interval="${AUTOPILOT_WAIT_INTERVAL_SECONDS:-15}"
  read_state_fields "$STATE_FILE" '[.run_id]'
  wait_run_id="${STATE_FIELDS[0]:-}"
  wait_state_file="$RUNS_DIR/$wait_run_id/state.json"
  [[ -f "$wait_state_file" ]] || wait_state_file="$STATE_FILE"

  emit_stderr "waiting for run $wait_run_id to leave running (every ${interval}s)"
  while :; do
    read_follow_state "$wait_state_file"
    current_status="$FOLLOW_STATE_STATUS"
    runner_pid="$FOLLOW_STATE_RUNNER_PID"
    runner_process_started="$FOLLOW_STATE_RUNNER_STARTED"
    if [[ "$current_status" != "running" ]]; then
      break
    fi
    if ! pid_is_alive "$runner_pid" "$runner_process_started"; then
      emit_stderr "runner stopped without recording terminal state"
      jq -c . "$wait_state_file"
      return 5
    fi
    sleep "$interval"
  done
  emit_stderr "run reached $current_status"
  jq -c . "$wait_state_file"
  case "$current_status" in
    complete) return 0 ;;
    needs_input) return 2 ;;
    blocked) return 3 ;;
    failed) return 4 ;;
    *) return 5 ;;
  esac
}

print_history() {
  local history_files=() state_file skipped=0
  if [[ -d "$RUNS_DIR" ]]; then
    for state_file in "$RUNS_DIR"/*/state.json; do
      [[ -f "$state_file" ]] || continue
      if jq -e 'type == "object" and (.root_ref | type == "string") and (.repo_root | type == "string") and (.created_at | type == "string")' "$state_file" >/dev/null 2>&1; then
        history_files+=("$state_file")
      else
        skipped=$((skipped + 1))
      fi
    done
  fi

  if [[ "${#history_files[@]}" -eq 0 ]]; then
    emit_stderr "no run history found for this root"
    [[ "$skipped" -eq 0 ]] || emit_stderr "skipped $skipped malformed run state file(s)"
    jq -cn '[]'
    return 0
  fi

  local history count
  history="$(jq -sc --arg root "$ROOT_REF" --arg repo "$REPO_ROOT" '
    map(select(.root_ref == $root and .repo_root == $repo)) | sort_by(.created_at) | reverse
  ' "${history_files[@]}")"
  count="$(printf '%s\n' "$history" | jq 'length')"
  emit_stderr "$count run(s) found for this root"
  [[ "$skipped" -eq 0 ]] || emit_stderr "skipped $skipped malformed run state file(s)"
  printf '%s\n' "$history"
}
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: 471kUpdated Claude CodeCodexVerifiedInstall
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: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
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 availableStars: 322kUpdated Claude CodeCodexVerifiedInstall