Skip to content

0x0w1/jig / .agents/skills/jig-update

jig-update

Flagged

Use when updating every detected jig installation for Claude Code, Codex, and Antigravity across current project and user scopes, including Claude Code plugins and existing standalone .claude/skills copies, while preserving each installed skill selection.

FileKindSize
SKILL.mdskill md20.3 KB
scripts/update-claude-standalone.shexecutablescript21.9 KB

scripts/update-claude-standalone.sh

View on GitHub
#!/usr/bin/env sh
set -eu

ROOT=
VERSION=
SCOPE=
DRY_RUN=0
TEMP_ROOT=
TRANSACTION_ACTIVE=0
TRANSACTION_STATE=
TRANSACTION_DIRS=

log() {
  printf '%s\n' "$*"
}

error() {
  printf 'ERROR: %s\n' "$*" >&2
  exit 1
}

usage() {
  cat <<'EOF'
Usage: sh update-claude-standalone.sh --root <.claude/skills path> --version <vX.Y.Z> [--scope <project|user>] [--dry-run]
EOF
}

rollback_changes() {
  [ "$TRANSACTION_ACTIVE" -eq 1 ] || return 0

  log "ROLLBACK restoring standalone installation: $ROOT"
  rollback_failed=0
  while IFS="	" read -r state_id destination destination_existed backup_existed; do
    [ -n "$state_id" ] || continue
    if [ "$destination_existed" -eq 1 ]; then
      if ! mkdir -p "$(dirname "$destination")" >/dev/null 2>&1 \
        || ! cp "$TEMP_ROOT/rollback/$state_id.destination" "$destination" >/dev/null 2>&1; then
        printf 'ERROR: rollback could not restore %s\n' "$destination" >&2
        rollback_failed=1
      fi
    else
      if ! rm -f "$destination" >/dev/null 2>&1; then
        printf 'ERROR: rollback could not remove %s\n' "$destination" >&2
        rollback_failed=1
      fi
    fi

    if [ "$backup_existed" -eq 1 ]; then
      if ! cp "$TEMP_ROOT/rollback/$state_id.backup" "$destination.bak" >/dev/null 2>&1; then
        printf 'ERROR: rollback could not restore %s.bak\n' "$destination" >&2
        rollback_failed=1
      fi
    else
      if ! rm -f "$destination.bak" >/dev/null 2>&1; then
        printf 'ERROR: rollback could not remove %s.bak\n' "$destination" >&2
        rollback_failed=1
      fi
    fi
  done < "$TRANSACTION_STATE"

  if [ -s "$TRANSACTION_DIRS" ]; then
    awk '{ print length($0) "\t" $0 }' "$TRANSACTION_DIRS" \
      | sort -rn \
      | cut -f 2- > "$TEMP_ROOT/rollback-directories.txt"
    while IFS= read -r created_directory; do
      [ -n "$created_directory" ] || continue
      if ! rmdir "$created_directory" >/dev/null 2>&1 && [ -d "$created_directory" ]; then
        printf 'ERROR: rollback could not remove directory %s\n' "$created_directory" >&2
        rollback_failed=1
      fi
    done < "$TEMP_ROOT/rollback-directories.txt"
  fi
  if [ "$rollback_failed" -eq 1 ]; then
    printf 'ERROR: rollback was incomplete; inspect the standalone root before retrying: %s\n' "$ROOT" >&2
  fi
  TRANSACTION_ACTIVE=0
}

cleanup() {
  cleanup_status=$?
  trap - EXIT HUP INT TERM
  rollback_changes
  [ -z "$TEMP_ROOT" ] || rm -rf "$TEMP_ROOT"
  exit "$cleanup_status"
}

trap cleanup EXIT
trap 'exit 129' HUP
trap 'exit 130' INT
trap 'exit 143' TERM

while [ "$#" -gt 0 ]; do
  case "$1" in
    --root)
      shift
      [ "$#" -gt 0 ] || error "--root requires a path"
      ROOT="$1"
      ;;
    --version)
      shift
      [ "$#" -gt 0 ] || error "--version requires a release tag"
      VERSION="$1"
      ;;
    --scope)
      shift
      [ "$#" -gt 0 ] || error "--scope requires project or user"
      SCOPE="$1"
      ;;
    --dry-run)
      DRY_RUN=1
      ;;
    -h|--help)
      usage
      exit 0
      ;;
    *)
      error "unknown option: $1"
      ;;
  esac
  shift
done

[ -n "$ROOT" ] || error "--root is required"
[ -n "$VERSION" ] || error "--version is required"

case "$ROOT" in
  .claude/skills|./.claude/skills|*/.claude/skills) ;;
  *) error "root must be a project or user .claude/skills directory: $ROOT" ;;
esac

case "$VERSION" in
  *[!A-Za-z0-9._-]*|'') error "invalid version: $VERSION" ;;
esac

[ -d "$ROOT" ] || error "standalone skill root does not exist: $ROOT"
ROOT=$(cd "$ROOT" && pwd -P)

if [ -z "$SCOPE" ]; then
  USER_SKILL_ROOT=$(cd "${HOME:?}" && pwd -P)/.claude/skills
  if [ "$ROOT" = "$USER_SKILL_ROOT" ]; then
    SCOPE=user
  else
    SCOPE=project
  fi
fi
case "$SCOPE" in
  project|user) ;;
  *) error "scope must be project or user: $SCOPE" ;;
esac

ROOT_OWNER=$(cd "$ROOT/../.." && pwd -P)
CURRENT_DIRECTORY=$(pwd -P)
if [ "$ROOT_OWNER" = "$CURRENT_DIRECTORY" ] \
  && [ -f "$CURRENT_DIRECTORY/manifest.tsv" ] \
  && [ -f "$CURRENT_DIRECTORY/skills/jig-update/SKILL.md" ] \
  && [ -f "$CURRENT_DIRECTORY/scripts/build-dist.sh" ]; then
  error "refusing to replace the jig source repository's .claude/skills development mirror"
fi

frontmatter_name() {
  awk '
    NR == 1 && $0 == "---" { frontmatter = 1; next }
    frontmatter && $0 == "---" { exit }
    frontmatter && /^name: / { sub(/^name: /, ""); print; exit }
  ' "$1"
}

canonical_title() {
  sed -n '/^# / { p; q; }' "$1"
}

validate_payload_relative_path() {
  payload_skill="$1"
  payload_path="$2"

  [ -n "$payload_path" ] \
    || error "unsafe payload path for $payload_skill: <empty>"
  case "$payload_path" in
    /*) error "unsafe payload path for $payload_skill: $payload_path (absolute path)" ;;
    */) error "unsafe payload path for $payload_skill: $payload_path (directory path)" ;;
    *//*) error "unsafe payload path for $payload_skill: $payload_path (empty component)" ;;
    *[!A-Za-z0-9._/-]*) error "unsafe payload path for $payload_skill: $payload_path (unsupported character)" ;;
  esac

  payload_old_ifs=$IFS
  IFS='/'; set -- $payload_path; IFS=$payload_old_ifs
  for payload_component in "$@"; do
    case "$payload_component" in
      ''|.|..) error "unsafe payload path for $payload_skill: $payload_path (non-file component)" ;;
      .jig-provenance|.jig-installation|*.bak)
        error "unsafe payload path for $payload_skill: $payload_path (reserved component)"
        ;;
    esac
  done
}

assert_safe_destination() {
  destination_boundary="$1"
  destination_relative="$2"
  destination_label="$3"
  destination_kind=${4:-payload}

  if [ "$destination_kind" = payload ]; then
    validate_payload_relative_path "$destination_label" "$destination_relative"
  else
    case "$destination_relative" in
      .jig-provenance|.jig-installation) ;;
      *) error "unsafe internal destination for $destination_label: $destination_relative" ;;
    esac
  fi
  [ -d "$destination_boundary" ] \
    || error "unsafe destination boundary for $destination_label: $destination_boundary"
  [ ! -L "$destination_boundary" ] \
    || error "unsafe symlink destination boundary for $destination_label: $destination_boundary"

  destination_current="$destination_boundary"
  destination_old_ifs=$IFS
  IFS='/'; set -- $destination_relative; IFS=$destination_old_ifs
  for destination_component in "$@"; do
    destination_current="$destination_current/$destination_component"
    [ ! -L "$destination_current" ] \
      || error "unsafe symlink payload path for $destination_label: $destination_relative"
  done

  case "$destination_current" in
    "$destination_boundary"/*) ;;
    *) error "payload path escapes destination boundary for $destination_label: $destination_relative" ;;
  esac
}

write_provenance() {
  provenance_destination="$1"
  provenance_skill="$2"
  provenance_directory="$3"
  printf '%s\n' \
    'format=1' \
    'repository=0x0w1/jig' \
    "skill=$provenance_skill" \
    "directory=$provenance_directory" \
    > "$provenance_destination"
}

provenance_is_valid() {
  provenance_path="$1"
  provenance_skill="$2"
  provenance_directory="$3"
  provenance_expected="$TEMP_ROOT/provenance-check"
  write_provenance "$provenance_expected" "$provenance_skill" "$provenance_directory"
  cmp -s "$provenance_expected" "$provenance_path"
}

LEDGER="$ROOT/.jig-installation"
ledger_value() {
  ledger_key="$1"
  sed -n "s/^$ledger_key=//p" "$LEDGER" | head -n 1
}

validate_ledger() {
  [ -f "$LEDGER" ] || return 1
  [ "$(wc -l < "$LEDGER" | tr -d ' ')" = 6 ] \
    && [ "$(grep -c '^format=' "$LEDGER")" = 1 ] \
    && [ "$(grep -c '^repository=' "$LEDGER")" = 1 ] \
    && [ "$(grep -c '^version=' "$LEDGER")" = 1 ] \
    && [ "$(grep -c '^target=' "$LEDGER")" = 1 ] \
    && [ "$(grep -c '^scope=' "$LEDGER")" = 1 ] \
    && [ "$(grep -c '^skills=' "$LEDGER")" = 1 ] \
    && [ "$(ledger_value format)" = 1 ] \
    && [ "$(ledger_value repository)" = 0x0w1/jig ] \
    && [ "$(ledger_value target)" = claude-code ] \
    && [ "$(ledger_value scope)" = "$SCOPE" ] \
    && [ -n "$(ledger_value version)" ] \
    && [ -n "$(ledger_value skills)" ] \
    && validate_ledger_mappings
}

validate_ledger_mappings() {
  ledger_mappings=$(ledger_value skills | tr ',' ' ')
  [ -n "$ledger_mappings" ] || return 1
  for ledger_mapping in $ledger_mappings; do
    case "$ledger_mapping" in
      *=*) ;;
      *) return 1 ;;
    esac
    ledger_skill=${ledger_mapping%%=*}
    ledger_directory=${ledger_mapping#*=}
    case "$ledger_skill:$ledger_directory" in
      *[!A-Za-z0-9._:-]*|:*|*:) return 1 ;;
    esac
    case "$ledger_directory" in
      *=*) return 1 ;;
    esac
  done
}

ledger_owns_mapping() {
  ledger_mapping="$1=$2"
  ledger_value skills | tr ',' '\n' | grep -Fx "$ledger_mapping" >/dev/null 2>&1
}

selection_mapping_is_owned() {
  selected_skill="$1"
  selected_directory="$2"
  ledger_owns_mapping "$selected_skill" "$selected_directory" && return 0
  if [ "$selected_skill" = jig-setup ]; then
    case "$selected_directory" in
      project-setup|jig-project-setup)
        ledger_owns_mapping project-setup "$selected_directory"
        return $?
        ;;
    esac
  fi
  return 1
}

selection_provenance_is_valid() {
  selected_provenance="$1"
  selected_skill="$2"
  selected_directory="$3"
  provenance_is_valid "$selected_provenance" "$selected_skill" "$selected_directory" && return 0
  if [ "$selected_skill" = jig-setup ]; then
    case "$selected_directory" in
      project-setup|jig-project-setup)
        provenance_is_valid "$selected_provenance" project-setup "$selected_directory"
        return $?
        ;;
    esac
  fi
  return 1
}

LEDGER_PRESENT=0
if [ -e "$LEDGER" ]; then
  [ ! -L "$LEDGER" ] || error "standalone installation ledger must not be a symlink: $LEDGER"
  [ -f "$LEDGER" ] || error "standalone installation ledger is not a regular file: $LEDGER"
  validate_ledger || error "standalone installation ledger is malformed or belongs to another scope: $LEDGER"
  LEDGER_PRESENT=1
  log "INSTALLED_VERSION $(ledger_value version) scope=$SCOPE"
else
  log "INSTALLED_VERSION unknown scope=$SCOPE"
fi

SENTINEL="$ROOT/jig-update/SKILL.md"
[ -f "$SENTINEL" ] || error "not a standalone jig installation: missing $SENTINEL"
if [ "$LEDGER_PRESENT" -eq 1 ]; then
  ledger_owns_mapping jig-update jig-update \
    || error "standalone installation ledger does not own jig-update"
else
  [ "$(frontmatter_name "$SENTINEL")" = jig-update ] \
    || error "not a standalone jig installation: jig-update name marker is missing"
  grep -Fx '# jig Update' "$SENTINEL" >/dev/null 2>&1 \
    || error "not a standalone jig installation: jig-update title marker is missing"
  grep -F '0x0w1/jig' "$SENTINEL" >/dev/null 2>&1 \
    || error "not a standalone jig installation: jig provenance is missing"
fi

TEMP_ROOT=$(mktemp -d)
MANIFEST="$TEMP_ROOT/manifest.tsv"
FILES="$TEMP_ROOT/files.tsv"
SELECTIONS="$TEMP_ROOT/selections.tsv"
APPLY_PLAN="$TEMP_ROOT/apply.tsv"
TRANSACTION_STATE="$TEMP_ROOT/transaction-state.tsv"
TRANSACTION_DIRS="$TEMP_ROOT/transaction-dirs.txt"
: > "$SELECTIONS"
: > "$APPLY_PLAN"
: > "$TRANSACTION_STATE"
: > "$TRANSACTION_DIRS"

RAW_ROOT=${JIG_UPDATE_RAW_BASE_URL:-https://raw.githubusercontent.com/0x0w1/jig}
RELEASE_ROOT="${RAW_ROOT%/}/$VERSION"

curl -fsSL "$RELEASE_ROOT/dist/manifest.tsv" -o "$MANIFEST" \
  || error "could not download manifest for $VERSION"
if ! curl -fsSL "$RELEASE_ROOT/dist/files.tsv" -o "$FILES"; then
  : > "$FILES"
fi

if ! awk -F '\t' '
  !/^#/ && NF >= 1 {
    if ($1 !~ /^[a-z0-9][a-z0-9-]*$/ || seen[$1]++) exit 1
  }
' "$MANIFEST"; then
  error "release manifest contains an unsafe or duplicate skill identifier"
fi

write_expected_files() {
  expected_skill="$1"
  expected_destination="$2"
  expected_rows=$(awk -F '\t' -v selected="$expected_skill" '
    !/^#/ && $1 == selected { count++ }
    END { print count + 0 }
  ' "$FILES")

  if [ "$expected_rows" -eq 0 ]; then
    printf 'SKILL.md\n' > "$expected_destination"
  else
    if awk -F '\t' -v selected="$expected_skill" '
      !/^#/ && $1 == selected && NF != 2 { bad = 1 }
      END { exit bad ? 0 : 1 }
    ' "$FILES"; then
      error "release file catalog contains a malformed path row for $expected_skill"
    fi
    awk -F '\t' -v selected="$expected_skill" '
      !/^#/ && $1 == selected { print $2 }
    ' "$FILES" > "$expected_destination"
  fi

  while IFS= read -r expected_relative; do
    validate_payload_relative_path "$expected_skill" "$expected_relative"
  done < "$expected_destination"
}

# An unprefixed standalone directory takes the plugin payload; a jig- prefixed one takes
# the prefixed payload, which now ships only under dist/antigravity. Codex stopped being an
# installer target when it gained a plugin system, and dist/codex went with it; the file
# content was identical, so a prefixed mapping resolves the same payload as before.
PREFIXED_PAYLOAD_ROOT="dist/antigravity/.agents/skills"

source_url() {
  source_skill="$1"
  source_directory="$2"
  source_relative="$3"
  if [ "$source_skill" = jig-setup ] && [ "$source_directory" = project-setup ]; then
    printf '%s/dist/claude-code-plugin/jig/skills/jig-setup/%s\n' "$RELEASE_ROOT" "$source_relative"
  elif [ "$source_skill" = jig-setup ] && [ "$source_directory" = jig-project-setup ]; then
    printf '%s/%s/jig-setup/%s\n' "$RELEASE_ROOT" "$PREFIXED_PAYLOAD_ROOT" "$source_relative"
  elif [ "$source_directory" = "$source_skill" ]; then
    printf '%s/dist/claude-code-plugin/jig/skills/%s/%s\n' "$RELEASE_ROOT" "$source_skill" "$source_relative"
  else
    printf '%s/%s/%s/%s\n' "$RELEASE_ROOT" "$PREFIXED_PAYLOAD_ROOT" "$source_directory" "$source_relative"
  fi
}

FOUND=0
VERIFIED=0

for skill in $(awk -F '\t' '!/^#/ && NF >= 1 { print $1 }' "$MANIFEST"); do
  case "$skill" in
    jig-*) prefixed="$skill" ;;
    *) prefixed="jig-$skill" ;;
  esac

  candidates="$skill"
  [ "$prefixed" = "$skill" ] || candidates="$candidates $prefixed"
  [ "$skill" != jig-setup ] || candidates="$candidates project-setup jig-project-setup"

  for directory_name in $candidates; do
    skill_root="$ROOT/$directory_name"
    [ -d "$skill_root" ] || continue
    FOUND=$((FOUND + 1))

    if [ "$LEDGER_PRESENT" -eq 1 ] && ! selection_mapping_is_owned "$skill" "$directory_name"; then
      log "SKIP skill directory not owned by installation ledger: $skill_root"
      continue
    fi

    canonical_entry="$TEMP_ROOT/canonical-$FOUND"
    canonical_url=$(source_url "$skill" "$directory_name" SKILL.md)
    curl -fsSL "$canonical_url" -o "$canonical_entry" \
      || error "could not download $canonical_url"

    skill_entry="$skill_root/SKILL.md"
    provenance="$skill_root/.jig-provenance"
    if [ -e "$provenance" ]; then
      [ ! -L "$provenance" ] || error "skill provenance must not be a symlink: $provenance"
      [ -f "$provenance" ] || error "skill provenance is not a regular file: $provenance"
      if ! selection_provenance_is_valid "$provenance" "$skill" "$directory_name"; then
        if [ "$LEDGER_PRESENT" -eq 1 ]; then
          error "installed skill provenance conflicts with the installation ledger: $skill_root"
        fi
        log "SKIP skill directory with invalid provenance: $skill_root"
        continue
      fi
    else
      expected_title=$(canonical_title "$canonical_entry")
      installed_title=
      [ ! -f "$skill_entry" ] || installed_title=$(canonical_title "$skill_entry")
      installed_name=
      [ ! -f "$skill_entry" ] || installed_name=$(frontmatter_name "$skill_entry")
      markerless_identity_matches=0
      if [ "$installed_name" = "$directory_name" ] && [ "$installed_title" = "$expected_title" ]; then
        markerless_identity_matches=1
      elif [ "$skill" = jig-setup ] && [ "$installed_title" = '# Project Setup' ]; then
        case "$directory_name:$installed_name" in
          project-setup:project-setup|jig-project-setup:jig-project-setup)
            markerless_identity_matches=1
            ;;
        esac
      fi
      if [ ! -f "$skill_entry" ] \
        || [ -z "$expected_title" ] \
        || [ "$markerless_identity_matches" -ne 1 ]; then
        log "SKIP ambiguous markerless skill directory: $skill_root"
        continue
      fi
    fi

    VERIFIED=$((VERIFIED + 1))
    printf '%s\t%s\n' "$skill" "$directory_name" >> "$SELECTIONS"
  done
done

[ "$FOUND" -gt 0 ] || error "no installed jig skills matched the release manifest"
[ "$VERIFIED" -gt 0 ] || error "no installed skill directory has verifiable jig ownership"
awk -F '\t' '$1 == "jig-update" && $2 == "jig-update" { found = 1 } END { exit found ? 0 : 1 }' "$SELECTIONS" \
  || error "the jig-update sentinel directory was not safely verified"

VALIDATION_COUNT=0
while IFS="	" read -r skill directory_name; do
  [ -n "$skill" ] || continue
  VALIDATION_COUNT=$((VALIDATION_COUNT + 1))
  skill_root="$ROOT/$directory_name"
  expected="$TEMP_ROOT/validated-expected-$VALIDATION_COUNT"
  write_expected_files "$skill" "$expected"
  while IFS= read -r relative_path; do
    assert_safe_destination "$skill_root" "$relative_path" "$skill"
  done < "$expected"
done < "$SELECTIONS"

PLAN_COUNT=0
while IFS="	" read -r skill directory_name; do
  [ -n "$skill" ] || continue
  skill_root="$ROOT/$directory_name"
  expected="$TEMP_ROOT/expected-$VERIFIED-$PLAN_COUNT"
  write_expected_files "$skill" "$expected"

  while IFS= read -r relative_path; do
    assert_safe_destination "$skill_root" "$relative_path" "$skill"
    PLAN_COUNT=$((PLAN_COUNT + 1))
    staged="$TEMP_ROOT/staged-$PLAN_COUNT"
    payload_url=$(source_url "$skill" "$directory_name" "$relative_path")
    curl -fsSL "$payload_url" -o "$staged" \
      || error "could not download $payload_url"
    destination="$skill_root/$relative_path"

    if [ -f "$destination" ] && cmp -s "$staged" "$destination"; then
      log "PASS unchanged file: $destination"
    else
      printf '%s\t%s\t%s\t%s\t%s\t%s\n' \
        "$destination" "$staged" "$skill_root" "$relative_path" "$skill" payload \
        >> "$APPLY_PLAN"
    fi
  done < "$expected"

  PLAN_COUNT=$((PLAN_COUNT + 1))
  staged_provenance="$TEMP_ROOT/staged-$PLAN_COUNT"
  write_provenance "$staged_provenance" "$skill" "$directory_name"
  if [ -f "$skill_root/.jig-provenance" ] \
    && cmp -s "$staged_provenance" "$skill_root/.jig-provenance"; then
    log "PASS unchanged provenance: $skill_root/.jig-provenance"
  else
    printf '%s\t%s\t%s\t%s\t%s\t%s\n' \
      "$skill_root/.jig-provenance" "$staged_provenance" "$skill_root" '.jig-provenance' "$skill provenance" internal \
      >> "$APPLY_PLAN"
  fi

  find "$skill_root" -type f ! -name '*.bak' ! -name '.jig-provenance' | while IFS= read -r installed_file; do
    relative_file=${installed_file#"$skill_root/"}
    if ! grep -Fx "$relative_file" "$expected" >/dev/null 2>&1; then
      log "LEFTOVER $installed_file"
    fi
  done
done < "$SELECTIONS"

SKILLS_VALUE=$(awk -F '\t' '
  BEGIN { separator = "" }
  { printf "%s%s=%s", separator, $1, $2; separator = "," }
  END { print "" }
' "$SELECTIONS")
PLAN_COUNT=$((PLAN_COUNT + 1))
STAGED_LEDGER="$TEMP_ROOT/staged-$PLAN_COUNT"
printf '%s\n' \
  'format=1' \
  'repository=0x0w1/jig' \
  "version=$VERSION" \
  'target=claude-code' \
  "scope=$SCOPE" \
  "skills=$SKILLS_VALUE" \
  > "$STAGED_LEDGER"
if [ -f "$LEDGER" ] && cmp -s "$STAGED_LEDGER" "$LEDGER"; then
  log "PASS unchanged installation ledger: $LEDGER"
else
  printf '%s\t%s\t%s\t%s\t%s\t%s\n' \
    "$LEDGER" "$STAGED_LEDGER" "$ROOT" '.jig-installation' 'standalone ledger' internal \
    >> "$APPLY_PLAN"
fi

if [ ! -s "$APPLY_PLAN" ]; then
  log "PASS standalone installation already matches $VERSION: $ROOT"
  exit 0
fi

if [ "$DRY_RUN" -eq 1 ]; then
  while IFS="	" read -r destination staged destination_boundary destination_relative destination_label destination_kind; do
    [ -n "$destination" ] || continue
    log "PLAN update file: $destination"
  done < "$APPLY_PLAN"
  exit 0
fi

mkdir -p "$TEMP_ROOT/rollback"
state_id=0
while IFS="	" read -r destination staged destination_boundary destination_relative destination_label destination_kind; do
  [ -n "$destination" ] || continue
  assert_safe_destination "$destination_boundary" "$destination_relative" "$destination_label" "$destination_kind"
  [ "$destination" = "$destination_boundary/$destination_relative" ] \
    || error "destination plan mismatch for $destination_label: $destination"
  state_id=$((state_id + 1))
  destination_existed=0
  backup_existed=0
  if [ -e "$destination" ]; then
    [ -f "$destination" ] || error "update destination is not a regular file: $destination"
    destination_existed=1
    cp "$destination" "$TEMP_ROOT/rollback/$state_id.destination" \
      || error "could not stage rollback copy for $destination"
  fi
  if [ -e "$destination.bak" ]; then
    [ -f "$destination.bak" ] || error "backup destination is not a regular file: $destination.bak"
    backup_existed=1
    cp "$destination.bak" "$TEMP_ROOT/rollback/$state_id.backup" \
      || error "could not stage rollback copy for $destination.bak"
  fi
  printf '%s\t%s\t%s\t%s\n' \
    "$state_id" "$destination" "$destination_existed" "$backup_existed" \
    >> "$TRANSACTION_STATE"

  missing_parent=$(dirname "$destination")
  while [ ! -e "$missing_parent" ] && [ "$missing_parent" != "$ROOT" ]; do
    printf '%s\n' "$missing_parent" >> "$TRANSACTION_DIRS"
    missing_parent=$(dirname "$missing_parent")
  done
done < "$APPLY_PLAN"
sort -u "$TRANSACTION_DIRS" -o "$TRANSACTION_DIRS"

TRANSACTION_ACTIVE=1
while IFS="	" read -r destination staged destination_boundary destination_relative destination_label destination_kind; do
  [ -n "$destination" ] || continue
  assert_safe_destination "$destination_boundary" "$destination_relative" "$destination_label" "$destination_kind"
  [ "$destination" = "$destination_boundary/$destination_relative" ] \
    || error "destination plan mismatch for $destination_label: $destination"
  mkdir -p "$(dirname "$destination")" \
    || error "could not create destination directory for $destination"
  if [ -f "$destination" ]; then
    cp "$destination" "$destination.bak" \
      || error "could not back up $destination"
  fi
  cp "$staged" "$destination" \
    || error "could not install $destination"
  log "UPDATED $destination"
done < "$APPLY_PLAN"
TRANSACTION_ACTIVE=0

log "UPDATED_VERSION $VERSION scope=$SCOPE skills=$SKILLS_VALUE"
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: 472kUpdated 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