#!/usr/bin/env python3
"""Verify CARBON uses Codex's built-in Browser and native file-link contract."""

from pathlib import Path


PLUGIN = Path(__file__).resolve().parents[1]


def require(path: Path, *phrases: str) -> None:
    source = path.read_text(encoding="utf-8")
    for phrase in phrases:
        assert phrase in source, f"{path.relative_to(PLUGIN)} is missing {phrase!r}"


def main() -> int:
    require(
        PLUGIN / "server" / "index.js",
        'preferredSurface: "in-app-browser"',
        "codexBrowserUrl",
        "codexChatLink",
        "codexFileLink",
        "Navigate Codex's built-in Browser",
        'externalBrowserFallback: "explicit-only"',
        'name: "carbon_command_progress"',
        "launchCommandProgressViewer",
        "writeLiveCommandArtifact",
    )
    require(
        PLUGIN / "runtime" / "carbon" / "references" / "command-result-reporting.md",
        "In Codex, navigate the built-in Browser",
        "`codexBrowserUrl`",
        "`codexChatLink`",
        "`codexFileLink`",
        "Do not navigate the built-in browser to `file://`",
        "carbon_command_progress",
        "without waiting",
    )
    require(
        PLUGIN / "skills" / "carbon" / "agents" / "openai.yaml",
        "Codex's built-in Browser",
        "codexBrowserUrl",
    )
    require(
        PLUGIN / ".codex-plugin" / "plugin.json",
        "open a live execution plan in the built-in Browser before testing",
    )
    print("PASS: Codex reports use the protected built-in Browser URL, native file fallback, host-specific links, and explicit-only external-browser fallback.")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
