main
John Lauer Keep Codex turns running across editor reloads; fix hidden-tab startup and composer fade in the optional package 4307d94 1mo ago
from pathlib import Path
import os,shutil,sys,argparse,subprocess
root=Path(__file__).resolve().parent
parser=argparse.ArgumentParser();parser.add_argument('--home',type=Path);args=parser.parse_args()
home=args.home or Path.home(); dest=home/'.local/share/adom/codex'; bindir=home/'.local/bin'
dest.mkdir(parents=True,exist_ok=True);bindir.mkdir(parents=True,exist_ok=True)
for n in ['adom_codex.py','dashboard','skills','docs','videos','package.json','runtime']:
 src=root/n;out=dest/n
 if src.resolve()==out.resolve():continue
 if src.is_dir():shutil.copytree(src,out,dirs_exist_ok=True)
 elif src.exists():shutil.copy2(src,out)
launcher=bindir/'adom-codex'
launcher.write_text('#!/bin/sh\nexec python3 "'+str(dest/'adom_codex.py')+'" "$@"\n');launcher.chmod(0o755)
codex_home=home/'.codex' if args.home else Path(os.environ.get('CODEX_HOME',home/'.codex'));codex_home.mkdir(parents=True,exist_ok=True)
skill=codex_home/'skills/codex-adom'
for entry in (dest/'skills').iterdir():
 if entry.is_dir() and (entry/'SKILL.md').is_file():shutil.copytree(entry,codex_home/'skills'/entry.name,dirs_exist_ok=True)
path=codex_home/'AGENTS.md';old=path.read_text() if path.exists() else ''
a='<!-- adom/codex:begin -->';b='<!-- adom/codex:end -->'
block=f'''{a}
## Adom ecosystem entry point
For Adom work, run `adom-codex context` and read `{skill}/SKILL.md` before choosing tools. Recheck dynamic target and board state on resume. For opening videos/files/folders, follow codex-adom-desktop-artifacts; for choosing verbs and background controls, follow codex-adom-bridge-workflows. For PCB routing, power pours or copper-ablation design, follow codex-adom-electrical-routing. Use existing Adom skills for task-specific guidance. Preserve user configuration, foreground preferences, and pinned development bridges.
{b}'''
if (a in old)!=(b in old) or old.count(a)>1 or old.count(b)>1:raise RuntimeError('Malformed managed block; preserving AGENTS.md for review')
if a in old:
 start=old.index(a);end=old.index(b)+len(b)
 if end<start:raise RuntimeError('Malformed managed block')
 new=old[:start]+block+old[end:]
else:new=old.rstrip()+'\n\n'+block+'\n'
if old!=new:
 if path.exists():shutil.copy2(path,path.with_name('AGENTS.md.before-adom-codex'))
 temp=path.with_name('.AGENTS.md.adom-codex.tmp');temp.write_text(new);temp.replace(path)
runtime_args=['--home',str(home)] if args.home else []
subprocess.run([sys.executable,str(dest/'runtime/manage.py'),'install',*runtime_args],check=True)
print('OK: Codex ecosystem entry point, skills, CLI, dashboard and container integration installed. Start a new Codex session to load instructions; reload the editor to activate runtime/UI changes.')