# --- Halfcycle cheap pass before a tool runs (generated; do not edit) ---
# Before each tool call: when the call is one Halfcycle's check could not ask
# about, answer here, write the call's time line, and do not start the check.
# Generated from the check's own list of risky spellings; anything it is not
# sure of goes on to the check.
halfcycle_pt_skip() {
  local hc_t=${EPOCHREALTIME:-} hc_status
  [ "${BASH_VERSINFO[0]:-0}" -ge 5 ] || return 1
  case $hc_t in [0-9]*[.,][0-9][0-9][0-9]*) ;; *) return 1 ;; esac
  hc_pt_live_text= hc_pt_live_sid= hc_pt_live_agent= hc_pt_live_dir=
  hc_pt_own_file= hc_pt_own_agent_id= hc_pt_own_tool_use_id=
  halfcycle_pt_agent "$@" || return 1
  halfcycle_pt_quiet || return 1
  halfcycle_pt_live || return 1
  halfcycle_pt_own_copy || return 1
  halfcycle_pt_own_read || return 1
  halfcycle_pt_time_line "$hc_t" || return 1
  halfcycle_pt_own_write "$hc_t"
  return 0
}
halfcycle_pt_agent() {
  hc_pt_agent=
  [ "$#" -le 2 ] && return 0
  [ "$#" -eq 4 ] && [ "$3" = --agent ] && [ "$4" = codex ] && { hc_pt_agent=codex; return 0; }
  return 1
}
halfcycle_pt_own_read() {
  local LC_ALL=C hc_val hc_dir hc_re='^[A-Za-z0-9_-]{1,128}$'
  halfcycle_pt_string tool_name || return 1
  case $hc_val in
    Bash|PowerShell) ;;
    *) return 0 ;;
  esac
  halfcycle_pt_string session_id
  case $? in 0) ;; 1) return 0 ;; *) return 1 ;; esac
  [[ $hc_val =~ $hc_re ]] || return 0
  hc_dir=${TMPDIR:-/tmp}
  while [ "${hc_dir%/}" != "$hc_dir" ]; do hc_dir=${hc_dir%/}; done
  hc_pt_own_file=$hc_dir/halfcycle-own-$hc_val.jsonl
  halfcycle_pt_optional 'agent_id' || return 1
  hc_pt_own_agent_id=$hc_val
  halfcycle_pt_optional 'tool_use_id' || return 1
  hc_pt_own_tool_use_id=$hc_val
  return 0
}
halfcycle_pt_own_write() {
  local LC_ALL=C hc_at hc_line
  [ -n "$hc_pt_own_file" ] || return 0
  halfcycle_pt_stamp "$1" || return 0
  printf -v hc_line '{"at":"%s","kind":"shell","agent":%s,"toolUse":%s}' "$hc_at" "$hc_pt_own_agent_id" "$hc_pt_own_tool_use_id" || return 0
  umask 077
  { printf '%s\n' "$hc_line" >> "$hc_pt_own_file"; } 2>/dev/null
  return 0
}
halfcycle_pt_stamp() {
  local hc_secs hc_frac
  hc_secs=${1%%[.,]*}
  hc_frac=${1#*[.,]}
  TZ=UTC0 printf -v hc_at '%(%Y-%m-%dT%H:%M:%S)T' "$hc_secs" || return 1
  hc_at=$hc_at.${hc_frac:0:3}Z
}
halfcycle_pt_live() {
  local LC_ALL=C hc_val hc_sid hc_agent= hc_cwd hc_dir hc_file hc_text= hc_ng=0 hc_re='^[A-Za-z0-9_-]{1,128}$'
  local -a hc_files
  halfcycle_pt_string session_id
  case $? in 0) hc_sid=$hc_val ;; 1) return 0 ;; *) return 1 ;; esac
  [[ $hc_sid =~ $hc_re ]] || return 0
  halfcycle_pt_string agent_id
  case $? in 0) hc_agent=$hc_val ;; 1) ;; *) return 1 ;; esac
  if [ -n "$hc_agent" ]; then
    [[ $hc_agent =~ $hc_re ]] || return 0
    hc_agent=-$hc_agent
  fi
  halfcycle_pt_string cwd
  case $? in 0) hc_cwd=$hc_val ;; 1) return 0 ;; *) return 1 ;; esac
  [ -n "$hc_cwd" ] || return 0
  case $hc_cwd in *'\'*|*[$'\n\r']*) return 1 ;; esac
  hc_dir=${TMPDIR:-/tmp}
  while [ "${hc_dir%/}" != "$hc_dir" ]; do hc_dir=${hc_dir%/}; done
  shopt -q nullglob && hc_ng=1
  shopt -s nullglob
  hc_files=("$hc_dir"/halfcycle-live-"$hc_sid"/halfcycle-session-[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z]-"$hc_sid".live"$hc_agent")
  [ "$hc_ng" = 1 ] || shopt -u nullglob
  [ "${#hc_files[@]}" -eq 1 ] || return 1
  hc_file=$hc_dir/${hc_files[0]##*/}
  IFS= read -r -d '' hc_text < "$hc_file" 2>/dev/null
  [ "${hc_text%%$'\n'*}" = "$hc_cwd" ] || return 1
  { printf '%s' "$hc_text" > "$hc_file"; } 2>/dev/null || return 1
  hc_pt_live_text=$hc_text hc_pt_live_sid=$hc_sid hc_pt_live_agent=${hc_agent#-} hc_pt_live_dir=$hc_dir
  return 0
}
halfcycle_pt_own_copy() {
  local LC_ALL=C hc_val hc_top hc_rest hc_d hc_f hc_text= hc_ng=0 hc_others=0
  local -a hc_files
  halfcycle_pt_string tool_name || return 1
  case $hc_val in
    Write|Edit|MultiEdit) ;;
    *) return 0 ;;
  esac
  halfcycle_pt_string file_path || return 1
  case $hc_val in /*) ;; *) return 1 ;; esac
  case $hc_val in *'\'*|*[$'\n\r']*) return 1 ;; esac
  hc_rest=${hc_pt_live_text#*$'\n'}
  hc_top=${hc_rest%%$'\n'*}
  case $hc_top in /?*) ;; *) return 1 ;; esac
  shopt -q nullglob && hc_ng=1
  shopt -s nullglob
  hc_files=("$hc_pt_live_dir"/halfcycle-live-"$hc_pt_live_sid"/halfcycle-session-[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z]-"$hc_pt_live_sid".live-*)
  [ "$hc_ng" = 1 ] || shopt -u nullglob
  for hc_f in "${hc_files[@]}"; do
    if [ -n "$hc_pt_live_agent" ]; then
      case $hc_f in *.live-"$hc_pt_live_agent") continue ;; esac
    fi
    hc_others=1
  done
  case $hc_val in
    "$hc_top"/?*) ;;
    *) [ -z "$hc_pt_live_agent" ] && [ "$hc_others" = 0 ] && return 0; return 1 ;;
  esac
  hc_rest=${hc_val#"$hc_top"/}
  case /$hc_rest/ in *//*|*/./*|*/../*) return 1 ;; esac
  hc_d=$hc_top
  while :; do
    case $hc_rest in */*) ;; *) break ;; esac
    hc_d=$hc_d/${hc_rest%%/*}
    hc_rest=${hc_rest#*/}
    [ -h "$hc_d" ] && return 1
    [ -d "$hc_d" ] || break
    { [ -e "$hc_d/.git" ] || [ -h "$hc_d/.git" ]; } && return 1
  done
  [ -z "$hc_pt_live_agent" ] && return 0
  [ "$hc_others" = 0 ] && return 0
  shopt -q nullglob && hc_ng=1
  shopt -s nullglob
  hc_files=("$hc_pt_live_dir"/halfcycle-live-"$hc_pt_live_sid"/halfcycle-session-[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z]-"$hc_pt_live_sid".live)
  [ "$hc_ng" = 1 ] || shopt -u nullglob
  [ "${#hc_files[@]}" -eq 1 ] || return 1
  IFS= read -r -d '' hc_text < "$hc_pt_live_dir/${hc_files[0]##*/}" 2>/dev/null
  case $hc_text in *$'\n'*$'\n'*) ;; *) return 1 ;; esac
  hc_text=${hc_text#*$'\n'}
  hc_text=${hc_text%%$'\n'*}
  [ -n "$hc_text" ] || return 1
  [ "$hc_text" = "$hc_top" ] && return 1
  return 0
}
halfcycle_pt_quiet() {
  local LC_ALL=C hc_status hc_ext=0
  shopt -q extglob && hc_ext=1
  shopt -s nocasematch extglob
  halfcycle_pt_quiet_input
  hc_status=$?
  shopt -u nocasematch
  [ "$hc_ext" = 1 ] || shopt -u extglob
  return $hc_status
}
halfcycle_pt_quiet_input() {
  local hc_tool hc_val hc_c hc_w hc_q hc_a hc_marked
  case $hc_input in '{'*'}'*) ;; *) return 1 ;; esac
  case $hc_input in *$'\xe2\x84\xaa'*) return 1 ;; esac
  halfcycle_pt_string tool_name || return 1
  hc_tool=$hc_val
  case ${hc_pt_agent:-} in
    '') ;;
    codex) case $hc_tool in Bash) ;; *) return 1 ;; esac ;;
    *) return 1 ;;
  esac
  case $hc_input in *'"tool_input":{'*) ;; *) return 1 ;; esac
  halfcycle_pt_once '"tool_input"' || return 1
  case $hc_tool in
    Bash)
      halfcycle_pt_string command
      case $? in 1) return 0 ;; 2) return 1 ;; esac
      halfcycle_pt_normalise "$hc_val" || return 1
      halfcycle_pt_glued && return 1
      halfcycle_pt_words || return 1
      halfcycle_pt_credential || return 1
      halfcycle_pt_redirects
      return ;;
    Read)
      halfcycle_pt_string file_path
      case $? in 1) return 0 ;; 2) return 1 ;; esac
      halfcycle_pt_normalise "$hc_val" || return 1
      halfcycle_pt_credential
      return ;;
    Grep)
      halfcycle_pt_string path
      case $? in
        0) halfcycle_pt_normalise "$hc_val" || return 1; halfcycle_pt_credential || return 1 ;;
        2) return 1 ;;
      esac
      halfcycle_pt_string glob
      case $? in 1) return 0 ;; 2) return 1 ;; esac
      halfcycle_pt_normalise "$hc_val" || return 1
      halfcycle_pt_credential
      return ;;
    Write|Edit|MultiEdit)
      halfcycle_pt_string file_path
      case $? in 1) return 0 ;; 2) return 1 ;; esac
      case $hc_val in *'\'*) return 1 ;; esac
      case $hc_val in /*|'~'*) ;; *) return 1 ;; esac
      hc_c=$hc_val hc_marked=
      halfcycle_pt_records
      return ;;
    *) return 1 ;;
  esac
}
halfcycle_pt_once() {
  local hc_rest
  case $hc_input in *"$1"*) ;; *) return 1 ;; esac
  hc_rest=${hc_input#*"$1"}
  case $hc_rest in *"$1"*) return 1 ;; esac
  return 0
}
halfcycle_pt_string() {
  local hc_k="\"$1\"" hc_rest hc_piece hc_run hc_v=
  hc_val=
  case $hc_input in *"$hc_k"*) ;; *) return 1 ;; esac
  hc_rest=${hc_input#*"$hc_k"}
  case $hc_rest in *"$hc_k"*) return 2 ;; esac
  case $hc_rest in ':"'*) hc_rest=${hc_rest#:\"} ;; *) return 2 ;; esac
  while :; do
    case $hc_rest in *'"'*) ;; *) return 2 ;; esac
    hc_piece=${hc_rest%%\"*}
    hc_rest=${hc_rest#*\"}
    hc_run=${hc_piece##*[!\\]}
    hc_v=$hc_v$hc_piece
    case ${#hc_run} in *[13579]) hc_v=$hc_v\" ;; *) break ;; esac
  done
  hc_val=$hc_v
  return 0
}
halfcycle_pt_optional() {
  halfcycle_pt_string "$1"
  case $? in
    0) if [ -n "$hc_val" ]; then hc_val="\"$hc_val\""; else hc_val=null; fi ;;
    1) hc_val=null ;;
    *) return 1 ;;
  esac
  return 0
}
halfcycle_pt_normalise() {
  local hc_v=$1 hc_m=$'\x01' hc_breaks=$' \x09\x0a\x0d\x0b\x0c;&|()<>`/$='
  hc_w= hc_q= hc_c= hc_marked=
  [ "${#hc_v}" -le 16384 ] || return 1
  case $hc_v in *'\u'*|*"$hc_m"*) return 1 ;; esac
  hc_v=${hc_v//\\\\/$hc_m}
  hc_v=${hc_v//"$hc_m"\\n/}
  hc_v=${hc_v//\\[nrtbf]/ }
  hc_v=${hc_v//\\\//\/}
  hc_v=${hc_v//\\\"/\"}
  case $hc_v in *'\'*) return 1 ;; esac
  case $hc_v in *"$hc_m"*) hc_marked=1 ;; esac
  hc_q=$hc_v
  hc_c=${hc_v//[\"\']/}
  hc_w=" ${hc_c//[$hc_breaks]/ } "
  hc_a=${hc_c//$hc_m/}
  hc_a=${hc_a//[*?]/}
  return 0
}
halfcycle_pt_glued() {
  local hc_b=$' \x09\x0a\x0d\x0b\x0c;&|()<>`/=' hc_re
  case $hc_c in *[A-Za-z0-9_]=*) ;; *) return 1 ;; esac
  hc_re="[^$hc_b]\\$|}[^$hc_b\$]|\\$[A-Za-z_][A-Za-z0-9_]*[^A-Za-z0-9_$hc_b\$\\{]"
  [[ $hc_c =~ $hc_re ]]
}
halfcycle_pt_has() {
  if [ -n "$hc_marked" ]; then
    [[ $hc_a == *"${1// /}"* && $hc_w == *$2* ]]
  else
    [[ $hc_w == *"$1"* ]]
  fi
}
halfcycle_pt_words() {
  halfcycle_pt_has ' rm ' $'[ \x01]?(\x01)r?(\x01)m[ \x01]' && return 1
  halfcycle_pt_has ' unlink ' $'[ \x01]?(\x01)u?(\x01)n?(\x01)l?(\x01)i?(\x01)n?(\x01)k[ \x01]' && return 1
  halfcycle_pt_has ' find ' $'[ \x01]?(\x01)f?(\x01)i?(\x01)n?(\x01)d[ \x01]' && { halfcycle_pt_has ' -delete ' $'[ \x01]?(\x01)-?(\x01)d?(\x01)e?(\x01)l?(\x01)e?(\x01)t?(\x01)e[ \x01]' || halfcycle_pt_has ' rm ' $'[ \x01]?(\x01)r?(\x01)m[ \x01]' || halfcycle_pt_has ' unlink ' $'[ \x01]?(\x01)u?(\x01)n?(\x01)l?(\x01)i?(\x01)n?(\x01)k[ \x01]'; } && return 1
  halfcycle_pt_has ' git ' $'[ \x01]?(\x01)g?(\x01)i?(\x01)t[ \x01]' && halfcycle_pt_has ' rm ' $'[ \x01]?(\x01)r?(\x01)m[ \x01]' && return 1
  halfcycle_pt_has ' git ' $'[ \x01]?(\x01)g?(\x01)i?(\x01)t[ \x01]' && halfcycle_pt_has ' reset ' $'[ \x01]?(\x01)r?(\x01)e?(\x01)s?(\x01)e?(\x01)t[ \x01]' && return 1
  halfcycle_pt_has ' git ' $'[ \x01]?(\x01)g?(\x01)i?(\x01)t[ \x01]' && halfcycle_pt_has ' checkout ' $'[ \x01]?(\x01)c?(\x01)h?(\x01)e?(\x01)c?(\x01)k?(\x01)o?(\x01)u?(\x01)t[ \x01]' && return 1
  halfcycle_pt_has ' git ' $'[ \x01]?(\x01)g?(\x01)i?(\x01)t[ \x01]' && halfcycle_pt_has ' switch ' $'[ \x01]?(\x01)s?(\x01)w?(\x01)i?(\x01)t?(\x01)c?(\x01)h[ \x01]' && return 1
  halfcycle_pt_has ' git ' $'[ \x01]?(\x01)g?(\x01)i?(\x01)t[ \x01]' && halfcycle_pt_has ' restore ' $'[ \x01]?(\x01)r?(\x01)e?(\x01)s?(\x01)t?(\x01)o?(\x01)r?(\x01)e[ \x01]' && return 1
  halfcycle_pt_has ' git ' $'[ \x01]?(\x01)g?(\x01)i?(\x01)t[ \x01]' && halfcycle_pt_has ' clean ' $'[ \x01]?(\x01)c?(\x01)l?(\x01)e?(\x01)a?(\x01)n[ \x01]' && return 1
  halfcycle_pt_has ' git ' $'[ \x01]?(\x01)g?(\x01)i?(\x01)t[ \x01]' && halfcycle_pt_has ' stash ' $'[ \x01]?(\x01)s?(\x01)t?(\x01)a?(\x01)s?(\x01)h[ \x01]' && { halfcycle_pt_has ' drop ' $'[ \x01]?(\x01)d?(\x01)r?(\x01)o?(\x01)p[ \x01]' || halfcycle_pt_has ' clear ' $'[ \x01]?(\x01)c?(\x01)l?(\x01)e?(\x01)a?(\x01)r[ \x01]'; } && return 1
  halfcycle_pt_has ' git ' $'[ \x01]?(\x01)g?(\x01)i?(\x01)t[ \x01]' && halfcycle_pt_has ' worktree ' $'[ \x01]?(\x01)w?(\x01)o?(\x01)r?(\x01)k?(\x01)t?(\x01)r?(\x01)e?(\x01)e[ \x01]' && halfcycle_pt_has ' remove ' $'[ \x01]?(\x01)r?(\x01)e?(\x01)m?(\x01)o?(\x01)v?(\x01)e[ \x01]' && return 1
  halfcycle_pt_has ' git ' $'[ \x01]?(\x01)g?(\x01)i?(\x01)t[ \x01]' && halfcycle_pt_has ' push ' $'[ \x01]?(\x01)p?(\x01)u?(\x01)s?(\x01)h[ \x01]' && return 1
  halfcycle_pt_has ' git ' $'[ \x01]?(\x01)g?(\x01)i?(\x01)t[ \x01]' && halfcycle_pt_has ' branch ' $'[ \x01]?(\x01)b?(\x01)r?(\x01)a?(\x01)n?(\x01)c?(\x01)h[ \x01]' && return 1
  halfcycle_pt_has ' psql ' $'[ \x01]?(\x01)p?(\x01)s?(\x01)q?(\x01)l[ \x01]' && return 1
  halfcycle_pt_has ' mysql ' $'[ \x01]?(\x01)m?(\x01)y?(\x01)s?(\x01)q?(\x01)l[ \x01]' && return 1
  halfcycle_pt_has ' mariadb ' $'[ \x01]?(\x01)m?(\x01)a?(\x01)r?(\x01)i?(\x01)a?(\x01)d?(\x01)b[ \x01]' && return 1
  halfcycle_pt_has ' sqlite3 ' $'[ \x01]?(\x01)s?(\x01)q?(\x01)l?(\x01)i?(\x01)t?(\x01)e?(\x01)3[ \x01]' && return 1
  halfcycle_pt_has ' dropdb ' $'[ \x01]?(\x01)d?(\x01)r?(\x01)o?(\x01)p?(\x01)d?(\x01)b[ \x01]' && return 1
  halfcycle_pt_has ' redis-cli ' $'[ \x01]?(\x01)r?(\x01)e?(\x01)d?(\x01)i?(\x01)s?(\x01)-?(\x01)c?(\x01)l?(\x01)i[ \x01]' && return 1
  halfcycle_pt_has ' prisma ' $'[ \x01]?(\x01)p?(\x01)r?(\x01)i?(\x01)s?(\x01)m?(\x01)a[ \x01]' && return 1
  halfcycle_pt_has ' rails ' $'[ \x01]?(\x01)r?(\x01)a?(\x01)i?(\x01)l?(\x01)s[ \x01]' && return 1
  halfcycle_pt_has ' rake ' $'[ \x01]?(\x01)r?(\x01)a?(\x01)k?(\x01)e[ \x01]' && return 1
  halfcycle_pt_has ' bundle ' $'[ \x01]?(\x01)b?(\x01)u?(\x01)n?(\x01)d?(\x01)l?(\x01)e[ \x01]' && return 1
  halfcycle_pt_has ' auth ' $'[ \x01]?(\x01)a?(\x01)u?(\x01)t?(\x01)h[ \x01]' && return 1
  halfcycle_pt_has ' find-generic-password ' $'[ \x01]?(\x01)f?(\x01)i?(\x01)n?(\x01)d?(\x01)-?(\x01)g?(\x01)e?(\x01)n?(\x01)e?(\x01)r?(\x01)i?(\x01)c?(\x01)-?(\x01)p?(\x01)a?(\x01)s?(\x01)s?(\x01)w?(\x01)o?(\x01)r?(\x01)d[ \x01]' && return 1
  halfcycle_pt_has ' find-internet-password ' $'[ \x01]?(\x01)f?(\x01)i?(\x01)n?(\x01)d?(\x01)-?(\x01)i?(\x01)n?(\x01)t?(\x01)e?(\x01)r?(\x01)n?(\x01)e?(\x01)t?(\x01)-?(\x01)p?(\x01)a?(\x01)s?(\x01)s?(\x01)w?(\x01)o?(\x01)r?(\x01)d[ \x01]' && return 1
  halfcycle_pt_has ' publish ' $'[ \x01]?(\x01)p?(\x01)u?(\x01)b?(\x01)l?(\x01)i?(\x01)s?(\x01)h[ \x01]' && return 1
  halfcycle_pt_has ' npm ' $'[ \x01]?(\x01)n?(\x01)p?(\x01)m[ \x01]' && halfcycle_pt_has ' publish ' $'[ \x01]?(\x01)p?(\x01)u?(\x01)b?(\x01)l?(\x01)i?(\x01)s?(\x01)h[ \x01]' && return 1
  halfcycle_pt_has ' upload ' $'[ \x01]?(\x01)u?(\x01)p?(\x01)l?(\x01)o?(\x01)a?(\x01)d[ \x01]' && return 1
  halfcycle_pt_has ' push ' $'[ \x01]?(\x01)p?(\x01)u?(\x01)s?(\x01)h[ \x01]' && return 1
  halfcycle_pt_has ' release ' $'[ \x01]?(\x01)r?(\x01)e?(\x01)l?(\x01)e?(\x01)a?(\x01)s?(\x01)e[ \x01]' && halfcycle_pt_has ' create ' $'[ \x01]?(\x01)c?(\x01)r?(\x01)e?(\x01)a?(\x01)t?(\x01)e[ \x01]' && return 1
  halfcycle_pt_has ' nuget ' $'[ \x01]?(\x01)n?(\x01)u?(\x01)g?(\x01)e?(\x01)t[ \x01]' && halfcycle_pt_has ' push ' $'[ \x01]?(\x01)p?(\x01)u?(\x01)s?(\x01)h[ \x01]' && return 1
  halfcycle_pt_has ' deploy ' $'[ \x01]?(\x01)d?(\x01)e?(\x01)p?(\x01)l?(\x01)o?(\x01)y[ \x01]' && return 1
  halfcycle_pt_has ' apply ' $'[ \x01]?(\x01)a?(\x01)p?(\x01)p?(\x01)l?(\x01)y[ \x01]' && return 1
  halfcycle_pt_has ' destroy ' $'[ \x01]?(\x01)d?(\x01)e?(\x01)s?(\x01)t?(\x01)r?(\x01)o?(\x01)y[ \x01]' && return 1
  halfcycle_pt_has ' delete ' $'[ \x01]?(\x01)d?(\x01)e?(\x01)l?(\x01)e?(\x01)t?(\x01)e[ \x01]' && return 1
  halfcycle_pt_has ' --prod ' $'[ \x01]?(\x01)-?(\x01)-?(\x01)p?(\x01)r?(\x01)o?(\x01)d[ \x01]' && return 1
  halfcycle_pt_has ' --production ' $'[ \x01]?(\x01)-?(\x01)-?(\x01)p?(\x01)r?(\x01)o?(\x01)d?(\x01)u?(\x01)c?(\x01)t?(\x01)i?(\x01)o?(\x01)n[ \x01]' && return 1
  halfcycle_pt_has ' truncate ' $'[ \x01]?(\x01)t?(\x01)r?(\x01)u?(\x01)n?(\x01)c?(\x01)a?(\x01)t?(\x01)e[ \x01]' && return 1
  halfcycle_pt_has ' cp ' $'[ \x01]?(\x01)c?(\x01)p[ \x01]' && halfcycle_pt_has ' dev ' $'[ \x01]?(\x01)d?(\x01)e?(\x01)v[ \x01]' && halfcycle_pt_has ' null ' $'[ \x01]?(\x01)n?(\x01)u?(\x01)l?(\x01)l[ \x01]' && return 1
  return 0
}
halfcycle_pt_in() {
  if [ -n "$hc_marked" ]; then
    [[ $hc_a == *"${1// /}"* && ( $hc_x == *$2* || $hc_y == *$2* ) ]] ||
      [[ ${hc_y//$'\x01'/} == *"${1// /}"* && $hc_y == *$2* ]]
  else
    [[ $hc_x == *"$1"* || $hc_y == *"$1"* ]]
  fi
}
halfcycle_pt_credential() {
  local hc_x=${hc_w//[*?]/} hc_y=${hc_w//[*?]/x}
  halfcycle_pt_in ' .env' $'[ \x01]?(\x01).?(\x01)e?(\x01)n?(\x01)v' && return 1
  halfcycle_pt_in ' id_rsa' $'[ \x01]?(\x01)i?(\x01)d?(\x01)_?(\x01)r?(\x01)s?(\x01)a' && return 1
  halfcycle_pt_in ' id_ed25519' $'[ \x01]?(\x01)i?(\x01)d?(\x01)_?(\x01)e?(\x01)d?(\x01)2?(\x01)5?(\x01)5?(\x01)1?(\x01)9' && return 1
  halfcycle_pt_in ' id_ecdsa' $'[ \x01]?(\x01)i?(\x01)d?(\x01)_?(\x01)e?(\x01)c?(\x01)d?(\x01)s?(\x01)a' && return 1
  halfcycle_pt_in ' service-account' $'[ \x01]?(\x01)s?(\x01)e?(\x01)r?(\x01)v?(\x01)i?(\x01)c?(\x01)e?(\x01)-?(\x01)a?(\x01)c?(\x01)c?(\x01)o?(\x01)u?(\x01)n?(\x01)t' && return 1
  halfcycle_pt_in '.pem ' $'.?(\x01)p?(\x01)e?(\x01)m[ \x01]' && return 1
  halfcycle_pt_in '.key ' $'.?(\x01)k?(\x01)e?(\x01)y[ \x01]' && return 1
  halfcycle_pt_in '.p12 ' $'.?(\x01)p?(\x01)1?(\x01)2[ \x01]' && return 1
  halfcycle_pt_in '.pfx ' $'.?(\x01)p?(\x01)f?(\x01)x[ \x01]' && return 1
  halfcycle_pt_in ' .netrc ' $'[ \x01]?(\x01).?(\x01)n?(\x01)e?(\x01)t?(\x01)r?(\x01)c[ \x01]' && return 1
  halfcycle_pt_in ' .npmrc ' $'[ \x01]?(\x01).?(\x01)n?(\x01)p?(\x01)m?(\x01)r?(\x01)c[ \x01]' && return 1
  halfcycle_pt_in ' .pypirc ' $'[ \x01]?(\x01).?(\x01)p?(\x01)y?(\x01)p?(\x01)i?(\x01)r?(\x01)c[ \x01]' && return 1
  halfcycle_pt_in ' credentials.json ' $'[ \x01]?(\x01)c?(\x01)r?(\x01)e?(\x01)d?(\x01)e?(\x01)n?(\x01)t?(\x01)i?(\x01)a?(\x01)l?(\x01)s?(\x01).?(\x01)j?(\x01)s?(\x01)o?(\x01)n[ \x01]' && return 1
  halfcycle_pt_in ' .credentials.json ' $'[ \x01]?(\x01).?(\x01)c?(\x01)r?(\x01)e?(\x01)d?(\x01)e?(\x01)n?(\x01)t?(\x01)i?(\x01)a?(\x01)l?(\x01)s?(\x01).?(\x01)j?(\x01)s?(\x01)o?(\x01)n[ \x01]' && return 1
  halfcycle_pt_in ' .aws ' $'[ \x01]?(\x01).?(\x01)a?(\x01)w?(\x01)s[ \x01]' && halfcycle_pt_in ' credentials ' $'[ \x01]?(\x01)c?(\x01)r?(\x01)e?(\x01)d?(\x01)e?(\x01)n?(\x01)t?(\x01)i?(\x01)a?(\x01)l?(\x01)s[ \x01]' && return 1
  halfcycle_pt_in ' .docker ' $'[ \x01]?(\x01).?(\x01)d?(\x01)o?(\x01)c?(\x01)k?(\x01)e?(\x01)r[ \x01]' && halfcycle_pt_in ' config.json ' $'[ \x01]?(\x01)c?(\x01)o?(\x01)n?(\x01)f?(\x01)i?(\x01)g?(\x01).?(\x01)j?(\x01)s?(\x01)o?(\x01)n[ \x01]' && return 1
  halfcycle_pt_in ' .config ' $'[ \x01]?(\x01).?(\x01)c?(\x01)o?(\x01)n?(\x01)f?(\x01)i?(\x01)g[ \x01]' && halfcycle_pt_in ' gh ' $'[ \x01]?(\x01)g?(\x01)h[ \x01]' && halfcycle_pt_in ' hosts.yml ' $'[ \x01]?(\x01)h?(\x01)o?(\x01)s?(\x01)t?(\x01)s?(\x01).?(\x01)y?(\x01)m?(\x01)l[ \x01]' && return 1
  halfcycle_pt_in ' .halfcycle ' $'[ \x01]?(\x01).?(\x01)h?(\x01)a?(\x01)l?(\x01)f?(\x01)c?(\x01)y?(\x01)c?(\x01)l?(\x01)e[ \x01]' && halfcycle_pt_in ' account.json ' $'[ \x01]?(\x01)a?(\x01)c?(\x01)c?(\x01)o?(\x01)u?(\x01)n?(\x01)t?(\x01).?(\x01)j?(\x01)s?(\x01)o?(\x01)n[ \x01]' && return 1
  halfcycle_pt_in ' .halfcycle ' $'[ \x01]?(\x01).?(\x01)h?(\x01)a?(\x01)l?(\x01)f?(\x01)c?(\x01)y?(\x01)c?(\x01)l?(\x01)e[ \x01]' && halfcycle_pt_in ' engagements ' $'[ \x01]?(\x01)e?(\x01)n?(\x01)g?(\x01)a?(\x01)g?(\x01)e?(\x01)m?(\x01)e?(\x01)n?(\x01)t?(\x01)s[ \x01]' && halfcycle_pt_in ' env ' $'[ \x01]?(\x01)e?(\x01)n?(\x01)v[ \x01]' && return 1
  return 0
}
halfcycle_pt_holds() {
  if [ -n "$hc_marked" ]; then
    [[ $hc_a == *"$1"* && $hc_c == *$2* ]]
  else
    [[ $hc_c == *"$1"* ]]
  fi
}
halfcycle_pt_records() {
  halfcycle_pt_holds 'ENGAGEMENT.md' $'E?(\x01)N?(\x01)G?(\x01)A?(\x01)G?(\x01)E?(\x01)M?(\x01)E?(\x01)N?(\x01)T?(\x01).?(\x01)m?(\x01)d' && return 1
  halfcycle_pt_holds 'project-log.md' $'p?(\x01)r?(\x01)o?(\x01)j?(\x01)e?(\x01)c?(\x01)t?(\x01)-?(\x01)l?(\x01)o?(\x01)g?(\x01).?(\x01)m?(\x01)d' && return 1
  halfcycle_pt_holds 'product-spec.md' $'p?(\x01)r?(\x01)o?(\x01)d?(\x01)u?(\x01)c?(\x01)t?(\x01)-?(\x01)s?(\x01)p?(\x01)e?(\x01)c?(\x01).?(\x01)m?(\x01)d' && return 1
  halfcycle_pt_holds 'architecture-overview.md' $'a?(\x01)r?(\x01)c?(\x01)h?(\x01)i?(\x01)t?(\x01)e?(\x01)c?(\x01)t?(\x01)u?(\x01)r?(\x01)e?(\x01)-?(\x01)o?(\x01)v?(\x01)e?(\x01)r?(\x01)v?(\x01)i?(\x01)e?(\x01)w?(\x01).?(\x01)m?(\x01)d' && return 1
  halfcycle_pt_holds 'invariants.md' $'i?(\x01)n?(\x01)v?(\x01)a?(\x01)r?(\x01)i?(\x01)a?(\x01)n?(\x01)t?(\x01)s?(\x01).?(\x01)m?(\x01)d' && return 1
  halfcycle_pt_holds 'system.json' $'s?(\x01)y?(\x01)s?(\x01)t?(\x01)e?(\x01)m?(\x01).?(\x01)j?(\x01)s?(\x01)o?(\x01)n' && return 1
  halfcycle_pt_holds 'phases' $'p?(\x01)h?(\x01)a?(\x01)s?(\x01)e?(\x01)s' && return 1
  halfcycle_pt_holds 'features' $'f?(\x01)e?(\x01)a?(\x01)t?(\x01)u?(\x01)r?(\x01)e?(\x01)s' && return 1
  halfcycle_pt_holds 'decisions' $'d?(\x01)e?(\x01)c?(\x01)i?(\x01)s?(\x01)i?(\x01)o?(\x01)n?(\x01)s' && return 1
  halfcycle_pt_holds 'build-tasks.json' $'b?(\x01)u?(\x01)i?(\x01)l?(\x01)d?(\x01)-?(\x01)t?(\x01)a?(\x01)s?(\x01)k?(\x01)s?(\x01).?(\x01)j?(\x01)s?(\x01)o?(\x01)n' && return 1
  halfcycle_pt_holds 'task-plan.json' $'t?(\x01)a?(\x01)s?(\x01)k?(\x01)-?(\x01)p?(\x01)l?(\x01)a?(\x01)n?(\x01).?(\x01)j?(\x01)s?(\x01)o?(\x01)n' && return 1
  halfcycle_pt_holds 'build-records' $'b?(\x01)u?(\x01)i?(\x01)l?(\x01)d?(\x01)-?(\x01)r?(\x01)e?(\x01)c?(\x01)o?(\x01)r?(\x01)d?(\x01)s' && return 1
  halfcycle_pt_holds '.claude' $'.?(\x01)c?(\x01)l?(\x01)a?(\x01)u?(\x01)d?(\x01)e' && return 1
  return 0
}
halfcycle_pt_redirects() {
  local hc_s=$hc_c hc_rest hc_pre hc_qc hc_body hc_abs= hc_bt=$'\x60'
  case $hc_c in *'>'*) ;; *) return 0 ;; esac
  if [ -z "$hc_marked" ] && ! { halfcycle_pt_has ' bash ' $'[ \x01]?(\x01)b?(\x01)a?(\x01)s?(\x01)h[ \x01]' || halfcycle_pt_has ' sh ' $'[ \x01]?(\x01)s?(\x01)h[ \x01]' || halfcycle_pt_has ' zsh ' $'[ \x01]?(\x01)z?(\x01)s?(\x01)h[ \x01]' || halfcycle_pt_has ' dash ' $'[ \x01]?(\x01)d?(\x01)a?(\x01)s?(\x01)h[ \x01]' || halfcycle_pt_has ' ksh ' $'[ \x01]?(\x01)k?(\x01)s?(\x01)h[ \x01]' || halfcycle_pt_has ' eval ' $'[ \x01]?(\x01)e?(\x01)v?(\x01)a?(\x01)l[ \x01]' || halfcycle_pt_has ' -S ' $'[ \x01]?(\x01)-?(\x01)S[ \x01]' || halfcycle_pt_has ' --split-string ' $'[ \x01]?(\x01)-?(\x01)-?(\x01)s?(\x01)p?(\x01)l?(\x01)i?(\x01)t?(\x01)-?(\x01)s?(\x01)t?(\x01)r?(\x01)i?(\x01)n?(\x01)g[ \x01]'; }; then
    case $hc_q in *'<<'*|*'${'*|*'$(('*) ;; *)
      case " $hc_q" in *[[:space:]\;\&\|\(\)$hc_bt]'#'*) ;; *)
        hc_s= hc_rest=$hc_q
        while :; do
          case $hc_rest in *[\"\']*) ;; *) hc_s=$hc_s$hc_rest; break ;; esac
          hc_pre=${hc_rest%%[\"\']*}
          hc_rest=${hc_rest:${#hc_pre}}
          hc_qc=${hc_rest:0:1}
          hc_rest=${hc_rest:1}
          case $hc_rest in *"$hc_qc"*) ;; *) return 1 ;; esac
          hc_body=${hc_rest%%"$hc_qc"*}
          hc_rest=${hc_rest#*"$hc_qc"}
          case $hc_qc$hc_body in '"'*'$('*|'"'*"$hc_bt"*) hc_s=$hc_c; break ;; esac
          hc_s=$hc_s$hc_pre${hc_body//'>'/}
        done
        ;;
      esac
      ;;
    esac
  fi
  while :; do
    case $hc_s in *'>'*) ;; *) break ;; esac
    hc_s=${hc_s#*'>'}
    case $hc_s in
      '>'*) hc_s=${hc_s#'>'}; continue ;;
      '&'*|'('*) continue ;;
      '|'*) hc_s=${hc_s#'|'} ;;
    esac
    hc_pre=${hc_s%%[![:space:]]*}
    hc_pre=${hc_s:${#hc_pre}}
    case $hc_pre in /*|'~'*) hc_abs=1 ;; *) return 1 ;; esac
  done
  [ -z "$hc_abs" ] && return 0
  halfcycle_pt_records
}
halfcycle_pt_resolve() {
  local - IFS=/ hc_part hc_out=
  local -a hc_parts
  set -f
  hc_parts=($1)
  for hc_part in "${hc_parts[@]}"; do
    case $hc_part in
      ''|.) ;;
      ..) hc_out=${hc_out%/*} ;;
      *) hc_out=$hc_out/$hc_part ;;
    esac
  done
  hc_path=${hc_out:-/}
}
halfcycle_pt_branch() {
  local hc_dir hc_dotgit hc_gitdir hc_text hc_line hc_ptr hc_path
  hc_branch=null
  case $1 in /*) ;; *) return 0 ;; esac
  hc_dir=$1
  while [ -n "$hc_dir" ] && [ "$hc_dir" != / ]; do
    [ -L "$hc_dir" ] && return 1
    hc_dir=${hc_dir%/*}
  done
  halfcycle_pt_resolve "$1"
  hc_dir=$hc_path
  [ -d "$hc_dir" ] || return 0
  while :; do
    hc_dotgit=${hc_dir%/}/.git
    if [ -e "$hc_dotgit" ]; then
      if [ -d "$hc_dotgit" ]; then
        hc_gitdir=$hc_dotgit
      else
        hc_text=
        IFS= read -r -d '' hc_text < "$hc_dotgit" 2>/dev/null
        hc_ptr=
        while IFS= read -r hc_line || [ -n "$hc_line" ]; do
          case $hc_line in
            gitdir:*)
              hc_line=${hc_line#gitdir:}
              hc_line=${hc_line#"${hc_line%%[!$' \t']*}"}
              hc_line=${hc_line%"${hc_line##*[!$' \t']}"}
              [ -n "$hc_line" ] && { hc_ptr=$hc_line; break; }
              ;;
          esac
        done <<< "$hc_text"
        [ -n "$hc_ptr" ] || return 0
        case $hc_ptr in /*) halfcycle_pt_resolve "$hc_ptr" ;; *) halfcycle_pt_resolve "$hc_dir/$hc_ptr" ;; esac
        hc_gitdir=$hc_path
      fi
      hc_text=
      IFS= read -r -d '' hc_text < "$hc_gitdir/HEAD" 2>/dev/null || [ -n "$hc_text" ] || return 0
      case $hc_text in *[!$'\x01'-$'\x7f']*) return 1 ;; esac
      hc_text=${hc_text#"${hc_text%%[![:space:]]*}"}
      hc_text=${hc_text%"${hc_text##*[![:space:]]}"}
      case $hc_text in ref:*) ;; *) return 0 ;; esac
      hc_text=${hc_text#ref:}
      hc_text=${hc_text#"${hc_text%%[!$' \t']*}"}
      case $hc_text in refs/heads/?*) ;; *) return 0 ;; esac
      hc_text=${hc_text#refs/heads/}
      case $hc_text in *[$'\n\r']*) return 0 ;; esac
      case $hc_text in *[$'\x01'-$'\x1f']*) return 1 ;; esac
      hc_text=${hc_text//\\/\\\\}
      hc_text=${hc_text//\"/\\\"}
      hc_branch="\"$hc_text\""
      return 0
    fi
    [ "$hc_dir" = / ] && return 0
    hc_dir=${hc_dir%/*}
    [ -n "$hc_dir" ] || hc_dir=/
  done
}
halfcycle_pt_time_line() {
  local LC_ALL=C hc_val hc_id hc_home hc_folder hc_branch hc_at hc_secs hc_frac hc_dir hc_line hc_f_session_id hc_f_agent_id hc_f_transcript_path hc_f_tool_use_id
  local hc_re='^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'
  [ -n "${GUARD_SERVICE_TOKEN:-}" ] || return 0
  [ -n "${GUARD_ENGAGEMENT_ID:-}" ] || return 0
  hc_id=$GUARD_ENGAGEMENT_ID
  [[ $hc_id =~ $hc_re ]] || return 0
  hc_home=${HOME:-}
  [ -n "$hc_home" ] || return 1
  halfcycle_pt_optional 'session_id' || return 1
  hc_f_session_id=$hc_val
  halfcycle_pt_optional 'agent_id' || return 1
  hc_f_agent_id=$hc_val
  halfcycle_pt_optional 'transcript_path' || return 1
  hc_f_transcript_path=$hc_val
  halfcycle_pt_optional 'tool_use_id' || return 1
  hc_f_tool_use_id=$hc_val
  halfcycle_pt_string cwd
  case $? in
    0) hc_folder=$hc_val ;;
    1) hc_folder= ;;
    *) return 1 ;;
  esac
  case $hc_folder in *'\'*) return 1 ;; esac
  if [ -z "$hc_folder" ]; then
    cd -P . 2>/dev/null || return 1
    hc_folder=$PWD
    case $hc_folder in *[$'\x01'-$'\x1f']*|*'\'*|*'"'*) return 1 ;; esac
  fi
  halfcycle_pt_branch "$hc_folder" || return 1
  halfcycle_pt_stamp "$1" || return 1
  printf -v hc_line '{"at":"%s","event":"action","session":%s,"agent":%s,"folder":"%s","branch":%s,"transcript":%s,"toolUse":%s}' "$hc_at" "$hc_f_session_id" "$hc_f_agent_id" "$hc_folder" "$hc_branch" "$hc_f_transcript_path" "$hc_f_tool_use_id"
  hc_dir=$hc_home/.halfcycle/engagements/$hc_id/time-log
  umask 077
  { printf '%s\n' "$hc_line" >> "$hc_dir/events.jsonl"; } 2>/dev/null ||
    { mkdir -p "$hc_dir" && printf '%s\n' "$hc_line" >> "$hc_dir/events.jsonl"; } 2>/dev/null
  return 0
}
# --- end Halfcycle cheap pass ---------------------------------------------
