import os, pathlib, subprocess, sys, time
checkout = pathlib.Path(sys.argv[1]).resolve()
run = pathlib.Path(sys.argv[2]).resolve()
run.mkdir(parents=True, exist_ok=True)
workspace = run / "Grep Demo"
workspace.mkdir(exist_ok=True)
(workspace / "alpha.txt").write_text("alpha before context\nzebra-needle alpha match\nalpha after context\n")
(workspace / "beta.txt").write_text("beta heading\nbeta before context\nzebra-needle beta match\nbeta after context\n")
def command(args):
    return subprocess.run(args, cwd=checkout, check=True, text=True, capture_output=True).stdout
command(["git", "-C", str(workspace), "init", "-q"])
command(["git", "-C", str(workspace), "add", "."])
command(["git", "-C", str(workspace), "-c", "user.name=Demo", "-c", "user.email=demo@example.invalid", "commit", "-qm", "Seed grep example"])
cli = ["node", "apps/server/src/bin.ts"]
home = str(checkout / ".t3")
subprocess.run(cli + ["project", "add", str(workspace), "--title", "Grep Demo", "--base-dir", home], cwd=checkout, capture_output=True)
prompt = "Use your native grep tool exactly once to search for zebra-needle in this project. Use content output mode with one context line before and one after (contextBefore=1, contextAfter=1). Do not use shell, read, or any other tool. Then briefly report the returned matched lines, line numbers, context, and totals."
result = command(cli + ["thread", "start", str(workspace), prompt, "--title", "Content grep verification", "--provider", "cursor", "--model", os.environ["CURSOR_MODEL"], "--base-dir", home, "--json"])
(run / "launch.json").write_text(result)
print(result)
