omega-tool-model
First-party Omega tool-use model source, serving harnesses, and verification records
Brought by drakestapleton
omega-tool-model / deployment / fast / install.py
| 1 | import os |
| 2 | """Operator installation instrument; no Python is used by the running service/client.""" |
| 3 | from pathlib import Path |
| 4 | from datetime import datetime,timezone |
| 5 | import json,hashlib,os,subprocess,time |
| 6 | R=Path(__file__).resolve().parent |
| 7 | D=(Path(os.path.expanduser('~')) / '/.local/share/omega-tool-model/round40-fast'.lstrip('/')) |
| 8 | U=(Path(os.path.expanduser('~')) / '/.config/systemd/user/omega-tool-model.service'.lstrip('/')) |
| 9 | L=(Path(os.path.expanduser('~')) / '/.local/bin/omega-tool-model'.lstrip('/')) |
| 10 | BOARD=(Path(os.path.expanduser('~')) / '/handoffs/BOARD.md'.lstrip('/')) |
| 11 | old=json.loads((R/'before-switch.json').read_text()) |
| 12 | assert json.loads((R/'regression-results.json').read_text())['passed'] |
| 13 | assert json.loads((R/'finish-checks.json').read_text())['passed'] |
| 14 | assert not os.path.lexists(U) |
| 15 | assert L.is_symlink() and os.readlink(L)==old['old_target'] |
| 16 | def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest() |
| 17 | for p,want in json.loads((D/'STAGED.json').read_text())['pins'].items():assert sha(Path(p))==want,p |
| 18 | assert sha(D/'server')==sha(R/'server-rows') |
| 19 | assert sha(D/'client')==sha(R/'client') |
| 20 | records=[] |
| 21 | def run(args): |
| 22 | q=subprocess.run(args,capture_output=True,text=True,timeout=30) |
| 23 | records.append(dict(command=args,returncode=q.returncode,stdout=q.stdout,stderr=q.stderr)) |
| 24 | (R/'install-commands.json').write_text(json.dumps(records,indent=2)+'\n') |
| 25 | assert q.returncode==0,records[-1] |
| 26 | return q |
| 27 | def board(text): |
| 28 | with BOARD.open('a') as f:f.write('\n'+datetime.now(timezone.utc).isoformat()+' Codex FAST INSTALL '+text+'\n') |
| 29 | board('Drake: "I would like you to try to make that as fast as possible". 5411 unique recorded responses match; checked launch bytes, protocol controls and live repair workflows pass. Starting only the new omega-tool-model.service; existing command remains selected until a service one-shot passes. Undo: stop/disable this unit and restore command symlink to '+old['old_target']+'. Original files retained. No other harness or shared-model changes.') |
| 30 | with U.open('x') as f:f.write((R/'omega-tool-model.service').read_text()) |
| 31 | U.chmod(0o644) |
| 32 | switched=False |
| 33 | try: |
| 34 | run(['systemctl','--user','daemon-reload']) |
| 35 | started=time.perf_counter_ns() |
| 36 | run(['systemctl','--user','enable','--now','omega-tool-model.service']) |
| 37 | q=run([str(D/'client'),'--demo']) |
| 38 | expected=json.loads((R.parent/'one-shot.json').read_text())['expected'] |
| 39 | assert q.stdout==expected |
| 40 | (R/'service-one-shot.json').write_text(json.dumps(dict(returncode=q.returncode,stdout=q.stdout,elapsed_from_service_start_ns=time.perf_counter_ns()-started),indent=2)+'\n') |
| 41 | board('Replacement service one-shot proved at '+str(R/'service-one-shot.json')+'. Switching only '+str(L)+' from '+old['old_target']+' to '+str(D/'client')+'. Undo remains stop/disable new unit and restore the recorded old symlink. No files removed.') |
| 42 | assert os.readlink(L)==old['old_target'] |
| 43 | tmp=L.with_name('omega-tool-model.fast-next') |
| 44 | assert not os.path.lexists(tmp) |
| 45 | tmp.symlink_to(D/'client');os.replace(tmp,L);switched=True |
| 46 | q=run([str(L),'--demo']);assert q.stdout==expected |
| 47 | run(['systemctl','--user','is-enabled','omega-tool-model.service']) |
| 48 | run(['systemctl','--user','is-active','omega-tool-model.service']) |
| 49 | state=run(['systemctl','--user','show','omega-tool-model.service','--property=MainPID,ActiveState,SubState,Result']) |
| 50 | for p,want in json.loads((D/'STAGED.json').read_text())['pins'].items():assert sha(Path(p))==want,p |
| 51 | m=dict(status='deployed',deployment_type='native_resident_streaming_service',installed=True,command=str(L),release=str(D),service='omega-tool-model.service',service_state=state.stdout,checkpoint='$HOME/.local/share/omega-tool-model/round40/model.ck',checkpoint_sha256=sha((Path(os.path.expanduser('~')) / '/.local/share/omega-tool-model/round40/model.ck'.lstrip('/'))),server_sha256=sha(D/'server'),client_sha256=sha(D/'client'),original_runtime=old['old_target'],automatic_tool_execution=False,persistent_server=True,external_listener=False,shared_model_changed=False,harness_routing_changed=False,removed=[],one_shot=str(R/'service-one-shot.json'),exact_output_states=5411,qualification=str(R/'regression-results.json'),failure_controls=str(R/'finish-checks.json'),installed_at=datetime.now(timezone.utc).isoformat(),rollback='Stop/disable only omega-tool-model.service and restore command symlink to '+old['old_target']) |
| 52 | assert m['checkpoint_sha256']=='7c7b5b5260f2d9453b6076b64e7f23e88341d96498584f2dfaa229c31ad2e346' |
| 53 | for label,path in [('previous-deployment',R.parent/'DEPLOYED.json'),('previous-model-deployment',(Path(os.path.expanduser('~')) / '/handoffs/tool-omega-20261104/DEPLOYED.json'.lstrip('/')))]: |
| 54 | (R/(label+'.json')).write_bytes(path.read_bytes()) |
| 55 | for path in [R/'DEPLOYED.json',D/'DEPLOYED.json',R.parent/'DEPLOYED.json',(Path(os.path.expanduser('~')) / '/handoffs/tool-omega-20261104/DEPLOYED.json'.lstrip('/'))]:path.write_text(json.dumps(m,indent=2)+'\n') |
| 56 | print('Resident service active and enabled. Installed command one-shot passed; exact original weights preserved.') |
| 57 | except BaseException: |
| 58 | if switched and L.is_symlink() and L.resolve()==D/'client': |
| 59 | tmp=L.with_name('omega-tool-model.rollback-next');assert not os.path.lexists(tmp) |
| 60 | tmp.symlink_to(old['old_target']);os.replace(tmp,L) |
| 61 | subprocess.run(['systemctl','--user','disable','--now','omega-tool-model.service'],capture_output=True) |
| 62 | board('Installation failed; new service disabled and original command restored if switched. See install-commands.json. No other services changed.') |
| 63 | raise |