interplane.Get Omega
Read in your language

omega-tool-model

First-party Omega tool-use model source, serving harnesses, and verification records

Brought by drakestapleton

branch main Branches Tags History

omega-tool-model / deployment / fast / install.py

63 lines · 5482 bytes Raw Blame History
1import os
2"""Operator installation instrument; no Python is used by the running service/client."""
3from pathlib import Path
4from datetime import datetime,timezone
5import json,hashlib,os,subprocess,time
6R=Path(__file__).resolve().parent
7D=(Path(os.path.expanduser('~')) / '/.local/share/omega-tool-model/round40-fast'.lstrip('/'))
8U=(Path(os.path.expanduser('~')) / '/.config/systemd/user/omega-tool-model.service'.lstrip('/'))
9L=(Path(os.path.expanduser('~')) / '/.local/bin/omega-tool-model'.lstrip('/'))
10BOARD=(Path(os.path.expanduser('~')) / '/handoffs/BOARD.md'.lstrip('/'))
11old=json.loads((R/'before-switch.json').read_text())
12assert json.loads((R/'regression-results.json').read_text())['passed']
13assert json.loads((R/'finish-checks.json').read_text())['passed']
14assert not os.path.lexists(U)
15assert L.is_symlink() and os.readlink(L)==old['old_target']
16def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest()
17for p,want in json.loads((D/'STAGED.json').read_text())['pins'].items():assert sha(Path(p))==want,p
18assert sha(D/'server')==sha(R/'server-rows')
19assert sha(D/'client')==sha(R/'client')
20records=[]
21def 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
27def board(text):
28 with BOARD.open('a') as f:f.write('\n'+datetime.now(timezone.utc).isoformat()+' Codex FAST INSTALL '+text+'\n')
29board('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.')
30with U.open('x') as f:f.write((R/'omega-tool-model.service').read_text())
31U.chmod(0o644)
32switched=False
33try:
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.')
57except 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