/**
 * Static-binary build spec — PLAN_RELAY_AGENT T16 (EXPLORE §6 distribution rank 2). Produces a
 * `bun --compile` spec for a one-`curl | sh` install. `npx web-terminal-agent` stays the MVP path
 * (rank 1). The bundle EXCLUDES dev/test deps and any terminal parser (INV11 re-check at the
 * package boundary — the agent is a byte-shuttle, never an ANSI interpreter).
 */
export type BinaryTarget = 'darwin-arm64' | 'darwin-x64' | 'linux-x64' | 'linux-arm64'

export const BINARY_TARGETS: readonly BinaryTarget[] = [
  'darwin-arm64',
  'darwin-x64',
  'linux-x64',
  'linux-arm64',
]

export interface BuildSpec {
  readonly tool: 'bun'
  readonly entry: string
  readonly target: BinaryTarget
  readonly bunTarget: string // bun's --target triple
  readonly outfile: string
  readonly minify: true
  /** Package-name substrings that must NOT appear in the bundle graph (INV11 tripwire). */
  readonly forbiddenDeps: readonly string[]
}

const BUN_TRIPLE: Readonly<Record<BinaryTarget, string>> = {
  'darwin-arm64': 'bun-darwin-arm64',
  'darwin-x64': 'bun-darwin-x64',
  'linux-x64': 'bun-linux-x64',
  'linux-arm64': 'bun-linux-arm64',
}

/** Build the `bun --compile` spec for a target triple. Entry is the CLI. */
export function buildBinaryConfig(target: BinaryTarget): BuildSpec {
  return {
    tool: 'bun',
    entry: 'src/cli.ts',
    target,
    bunTarget: BUN_TRIPLE[target],
    outfile: `dist/web-terminal-agent-${target}`,
    minify: true,
    forbiddenDeps: ['xterm', 'ansi', 'vt100'],
  }
}
