#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2025 Jiri Vyskocil
# SPDX-License-Identifier: Apache-2.0
# terok:container — this file is deployed into task containers, not used on the host.

# ACP wrapper for OpenAI Codex.
#
# Sets up per-agent git identity and unrestricted mode before exec-ing
# the real codex-acp adapter.
#
# Instructions: -c model_instructions_file flag points the adapter at
# /home/dev/.terok/instructions.md (per-task, written by
# prepare_agent_config_dir on the host).  Same mechanism as the headless wrapper.
#
# Unlike other agents, Codex has no env var for approval policy — only
# the --yolo CLI flag (which doesn't apply to the ACP adapter) or
# config.toml.  The codex-acp binary accepts -c key=value overrides
# that apply to the same config tree without writing files.

set -euo pipefail

_AGENT_NAME="Codex"
_AGENT_EMAIL="noreply@openai.com"
. /usr/local/share/terok/terok-acp-env.sh

_args=()
if [[ "${TEROK_UNRESTRICTED:-}" == "1" ]]; then
    _args+=(-c approval_policy=never -c sandbox_mode=danger-full-access)
fi
if [[ -f /home/dev/.terok/instructions.md ]]; then
    _args+=(-c 'model_instructions_file="/home/dev/.terok/instructions.md"')
fi

exec npx @zed-industries/codex-acp "${_args[@]}" "$@"
