#!/bin/bash
# Entry point of the mm-acp sandbox kit (docker-sbx/kits/mm-acp).
#
# An editor never runs this script. It reaches mm with
#
#     sbx exec -i <sandbox> mm -acp
#
# because an ACP client needs raw stdin/stdout and `sbx run` always allocates
# a terminal. So attaching to this sandbox with `sbx run` prints the wiring
# for the editor, with this sandbox's real name and paths, then opens a shell.
set -u

name="${SANDBOX_NAME:-$(hostname)}"
workspace="${WORKSPACE_DIR:-$PWD}"
config="${AGENT_CONFIG:-}"
if [ -z "$config" ]; then
  config_note="none set — mm reads ./agent.yaml in the workspace, then its built-in defaults"
elif [ "${config#/}" = "$config" ]; then
  config_note="$config (relative to the workspace: ${workspace%/}/$config)"
else
  config_note="$config"
fi

cat <<INFO

  mm $(mm --version 2>/dev/null | awk '{print $2}') in sandbox "$name"
  workspace : $workspace
  config    : $config_note

  This sandbox is meant for an editor (Agent Client Protocol). Register it in
  Zed's settings.json — the editor starts mm inside the sandbox on every
  conversation, and sbx starts the sandbox first when it is stopped:

  {
    "agent_servers": {
      "mini-me (sandbox)": {
        "type": "custom",
        "command": "sbx",
        "args": ["exec", "-i", "$name", "mm", "-acp"]
      }
    }
  }

  Use the absolute path of sbx as "command" if the editor cannot find it
  (\`which sbx\` on the host). To change the configuration file for one
  session, add "-e", "AGENT_CONFIG=/path/in/workspace/agent.yaml" before
  "$name" in "args". Full guide: docs/en/how-to/run-in-a-docker-sandbox.md

  You are now in a shell inside the sandbox. \`mm agent.yaml\` works here too.

INFO
exec bash -l
