#!/usr/bin/env bash
set -euo pipefail

if [[ $# -eq 0 ]]; then
  echo "_agent-build-scope: command required" >&2
  exit 2
fi

export PATH="$HOME/.claude/bin:$PATH"

# The git shim refuses without its pinned real git, so a machine that received the shims
# without running their installer would have no working git for the whole session.
if [[ ! -s "$HOME/.local/state/overdeck/shim-real/git" ]]; then
  "$HOME/.claude/bin/install-git-guard-real" >/dev/null ||
    echo "_agent-build-scope: no real git could be pinned — git will refuse until install-git-guard-real succeeds" >&2
fi

# Mark the agent tree so cpu-guard's node shim skips re-scoping our children into build.slice.
export AGENT_BUILD_SCOPE_ACTIVE=1

# CPU-priority routing (measured 2026-07-13): interactive codex/claude parse+render competes
# for CPU at equal weight (100) against the harness's own codex exec agents in app.slice, under
# load ~20-70. Route every agent into agent.slice so concurrent headless harness jobs share the
# same aggregate ceiling as interactive agents.
exec "$HOME/.claude/lib/confine.sh" agent "$@"
