import pathlib, subprocess, sys
checkout, home, parent = map(pathlib.Path, sys.argv[1:])
parent.mkdir(parents=True, exist_ok=True)
(parent / 'CLAUDE.local.md').write_text('Instruction marker: ANCESTOR_MARKER\n')
for title in ['Orchard', 'Meadow']:
    repo = parent / title
    repo.mkdir()
    (repo / 'README.md').write_text('# ' + title + '\n')
    (repo / '.gitignore').write_text('CLAUDE.local.md\n')
    def git(*args):
        return subprocess.check_output(['git', '-C', str(repo), *args], text=True)
    git('init', '--quiet', '--initial-branch=main')
    git('add', '--all')
    git('-c', 'user.name=Scenario', '-c', 'user.email=scenario@example.invalid', 'commit', '--quiet', '-m', 'Initial commit')
    (repo / 'CLAUDE.local.md').write_text('Instruction marker: ' + title.upper() + '_LOCAL_MARKER\n')
    subprocess.run(['node', 'apps/server/src/bin.ts', 'project', 'add', str(repo), '--title', title, '--base-dir', str(home)], cwd=checkout, check=True, stdout=subprocess.DEVNULL)
    print(title + ': committed repository added; ignored local marker and shared ancestor marker installed')
