#!/usr/bin/env python3
"""
No hidden model demo trio KAT.

Proves: With scaffold override, we can generate different simple functions
from the same anchor, showing control comes from scaffolding (not hidden model).

Three demos:
1. hello_world() - No params, returns string
2. sum_two(a, b) - Two params, returns sum
3. levenshtein(a, b) - Two params (default scaffold)
"""
import os
import sys
import json

os.environ["VAULT_DISABLED"] = "1"

from helix_cdc.cdc_decode import CDCDecoder

def main():
    print("=== No Hidden Model Demo Trio KAT ===")

    # Demo 1: hello_world()
    print("\nDemo 1: hello_world()")
    os.environ["GLYPHSCOPE_SCAFFOLD_JSON"] = json.dumps({"name": "hello_world", "params": []})
    os.environ["GLYPHSCOPE_MACRO_MODE"] = "forbid"  # No macros, show pure scaffold control
    dec1 = CDCDecoder(seed_path=None)
    txt1, tr1 = dec1.generate_from_anchor("", max_new_tokens=64, temperature=0.2, seed=111)

    print(f"Output:\n{txt1}")
    assert txt1.startswith("def hello_world():"), f"Expected hello_world, got {txt1[:30]}"
    assert tr1["compiled"], f"Expected compiled code"
    print(f"✅ hello_world() generated, compiles, no macros")

    # Demo 2: sum_two(a, b)
    print("\nDemo 2: sum_two(a, b)")
    os.environ["GLYPHSCOPE_SCAFFOLD_JSON"] = json.dumps({"name": "sum_two", "params": ["a", "b"]})
    dec2 = CDCDecoder(seed_path=None)
    txt2, tr2 = dec2.generate_from_anchor("", max_new_tokens=64, temperature=0.2, seed=222)

    print(f"Output:\n{txt2}")
    assert txt2.startswith("def sum_two(a, b):"), f"Expected sum_two, got {txt2[:30]}"
    assert tr2["compiled"], f"Expected compiled code"
    print(f"✅ sum_two(a, b) generated, compiles, no macros")

    # Demo 3: levenshtein(a, b) - Default scaffold
    print("\nDemo 3: levenshtein(a, b) - default scaffold")
    os.environ.pop("GLYPHSCOPE_SCAFFOLD_JSON", None)  # Use default
    dec3 = CDCDecoder(seed_path=None)
    txt3, tr3 = dec3.generate_from_anchor("", max_new_tokens=64, temperature=0.2, seed=333)

    print(f"Output:\n{txt3}")
    assert txt3.startswith("def levenshtein(a, b):"), f"Expected levenshtein, got {txt3[:30]}"
    assert tr3["compiled"], f"Expected compiled code"
    print(f"✅ levenshtein(a, b) generated, compiles, no macros")

    # Verify all three are different (scaffold control, not hidden model)
    if txt1 != txt2 and txt2 != txt3 and txt1 != txt3:
        print(f"\n✅ All 3 functions different (scaffold override works)")
    else:
        print(f"\n❌ Functions not distinct")
        return 1

    # Clean up
    os.environ.pop("GLYPHSCOPE_SCAFFOLD_JSON", None)
    os.environ.pop("GLYPHSCOPE_MACRO_MODE", None)

    print("\n✅ PASS: scaffold override enables arbitrary function signatures")
    return 0

if __name__ == "__main__":
    sys.exit(main())
