#!/usr/bin/env bash
# systemctl — GENERATED by generate-tool-shims from tools.json rule "cpuquota-on-agent-slice".
# 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 "systemctl"; then
  echo "$name: tool shim has no usable pinned systemctl (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='(set-property[^;|&]*agent[^;|&]*CPUQuota=[0-9])'
if [[ "${AGENT_BUILD_SCOPE_ACTIVE:-}" == "1" ]] && [[ "$cmd" =~ $_pattern ]]; then
  cat >&2 <<'MSG'
tool-shim (cpuquota-on-agent-slice): CPU is a rate, not a stock: CPUQuota on an agent slice starves every session shell to silent death under fleet load (2026-08-15: quota=150% killed 50 sessions'\'' Bash children, nr_throttled 2.88M). Policy: CPUWeight only. Clearing an existing quota (CPUQuota=) is allowed.
Use instead: systemctl --user set-property agent.slice CPUWeight=<n>   # weight yields; quota kills
MSG
  exit 76
fi

exec "$real" "$@"
