#!/usr/bin/env bash
# ccr — GENERATED by generate-tool-shims from tools.json rule "ccr-start-raw".
# OD_PATH_SHIM_MARKER OD_TOOL_SHIM_MARKER — do not hand-edit; re-run generate-tool-shims.
# Registry hash at generation time: 1c67ba144616
set -e

name="${0##*/}"
SHIM_DIR="$(cd "$(dirname "$(readlink -f -- "${BASH_SOURCE[0]}")")" && pwd)"

GUARD_LIB="$SHIM_DIR/../lib/shim-guard.sh"
if [[ ! -r "$GUARD_LIB" ]]; then
  echo "$name: tool shim cannot read $GUARD_LIB — refusing" >&2
  exit 78
fi
# shellcheck source=../lib/shim-guard.sh
source "$GUARD_LIB"
shim_guard_enter "$name"

if ! shim_pin_read "ccr"; then
  echo "$name: tool shim has no usable pinned ccr (looked in: $SHIM_PIN_TRIED) — run $SHIM_DIR/install-tool-shims-real" >&2
  exit 78
fi
real="$SHIM_PIN_REAL"
shim_guard_clear "$name"

if [[ "$SHIM_REENTRY" == 1 ]]; then
  exec "$real" "$@"
fi

# Matched against "$name $*", not just "$*": the rule text (ported verbatim from
# tools.json) was written to match a full typed command line INCLUDING the binary
# name — args alone would never contain literals like "ccr" or "podman".
cmd="$name $*"
# The pattern MUST be held in a variable, not written inline in [[ =~ <literal> ]]:
# bash strips backslash escapes from an inline pattern before regcomp ever sees them,
# silently turning a boundary/whitespace class into a no-match. A variable reference
# is passed through unquoted-word-split, unmangled.
_pattern='(\bccr\s+start\b)'
if [[ "${AGENT_BUILD_SCOPE_ACTIVE:-}" == "1" ]] && [[ "$cmd" =~ $_pattern ]] && ! [[ "$cmd" == *"ccr-up.sh"* ]]; then
  cat >&2 <<'MSG'
tool-shim (ccr-start-raw): `ccr start` is a long-lived daemon. Naive foreground (or `ccr start | tail`) HANGS the whole run ~46min. The one correct, non-blocking launch is the tested wrapper (detached + flock + readiness-poll, idempotent, cannot hang).
Use instead: bash ~/.claude/workflows/lib/ccr-up.sh <slug>
MSG
  exit 76
fi

exec "$real" "$@"
