← Commit history
Publish 0.1.37
4 files changed
+138−3
README.md+2@@ -124,6 +124,8 @@ Version 0.1.34 makes those fixes reach everyone. The background watcher used to Version 0.1.36 replaces a Codex backend that nobody can reach. The engine keeps its real socket in /tmp/codex-daemon-<uid>/, and when /tmp was emptied while the workspace ran (adom/hydrogen#186) the backend lived on with no socket, and the runtime refused every new Codex view with "alive but unavailable" until the process died. When the backend is alive but its socket link points at nothing, the runtime now stops it and starts a new one. A socket that still exists but does not answer is refused as before. +Version 0.1.37 makes Adom's own Codex hooks arrive trusted. Codex runs a hook from `~/.codex/hooks.json` only after the user trusts it under "Review hooks", and again after its entry changes, so the adom/hook update check, `claude-rc hook`, `adom-wiki discover suggest --hook` and Hydrogen's session hooks (`~/.adom/hd-ai-threads-hook.sh`) did nothing until each was trusted by hand. When a Codex view connects, the runtime asks the running backend for its hook list (`hooks/list`) and saves trust for Adom's hooks the way the Trust button does (`config/batchWrite`), so Codex computes each hook's key and hash itself. It trusts only exact commands from Adom's list (the hooks Adom installs, plus any an installer adds to `~/.adom/codex-trusted-hooks.json`, a JSON array of exact commands), only in the user's own `~/.codex/hooks.json` (never a project's `.codex/hooks.json`), only hooks that are untrusted or modified, and never one the user switched off. It runs again whenever `hooks.json` changes, which also heals a hook whose position moved. If the backend refuses (the protocol is experimental), Codex keeps asking as before. Each outcome is one line in `hook-trust.log` in the runtime's state folder, and `--runtime-status` shows the last one.+ Version 0.1.35 gives OpenAI's newest models to fresh installs too. The newest-engine swap from 0.1.30 only ran while a hold was active, which needs the bad build to have arrived first. A workspace that started on the good build (the Hydrogen golden image ships it) was never held, so its Codex kept the build's own older engine and the model picker stopped at GPT-6 Astra. The guard now fetches the newest engine whenever Codex is on the listed fallback build, held or not; reload the editor once and GPT-6.1 Sol is the default. ### Skip the repeated IDE walkthrough
package.json+1−1@@ -4,7 +4,7 @@ "type": "app", "title": "Codex", "brief": "Codex in Adom Hydrogen: ecosystem setup, dock dashboard and live engineering demos.",- "version": "0.1.36",+ "version": "0.1.37", "description": "Codex in Adom Hydrogen with reusable CAD routing, electrical review, copper-ablation and narrated video skills, plus verified KiCad and Fusion demo progressions.", "org": "adom", "needs_sudo": false,
page.json+1−1@@ -4,7 +4,7 @@ "type": "app", "title": "Codex", "brief": "Codex in Adom Hydrogen: ecosystem setup, dock dashboard and live engineering demos.",- "version": "0.1.36",+ "version": "0.1.37", "hero": { "type": "image", "path": "screenshots/hero.png"
runtime/runtime.py+134−1@@ -363,6 +363,135 @@ def ensure_server(binary, args, client_guard=None): raise RuntimeError(f'Codex backend is still starting; inspect {log}') +# ADOM'S OWN CODEX HOOKS ARRIVE TRUSTED. Codex runs a hook from ~/.codex/hooks.json only once it+# is trusted: config.toml holds [hooks.state."<file>:<event>:<group>:<handler>"] trusted_hash,+# a hash of the hook's entry (not of the script it runs). Every Adom hook (the adom/hook update+# check, claude-rc, adom-wiki discovery, Hydrogen's session hooks) sat behind "Review hooks"+# until the user trusted each one by hand, and again whenever an entry moved. The running+# backend computes the key and hash itself (hooks/list) and saves trust the way the Codex Trust+# button does (config/batchWrite), so nothing here copies Codex's hashing rules and one process+# writes config.toml. Rules: an exact command from adom_hook_commands(), only in the user's own+# hooks.json (never a project's .codex/hooks.json, which a cloned repo could ship), only+# untrusted or modified entries, never `enabled`. Any failure (the protocol is experimental)+# leaves Codex's own prompt as it was and logs one line.++def codex_home():+ return Path(os.environ.get('CODEX_HOME', str(Path.home() / '.codex'))).resolve()+++def trusted_hooks_file():+ """Installers add the exact commands they wire into ~/.codex/hooks.json here."""+ return Path.home() / '.adom' / 'codex-trusted-hooks.json'+++def adom_hook_commands():+ """The exact commands of Adom's own Codex hooks: the ones Adom installs today, plus any an+ installer lists in ~/.adom/codex-trusted-hooks.json (a JSON array of strings)."""+ home = str(Path.home())+ commands = {+ f'bash {home}/.adom/hooks/adom-core-update.sh',+ f'{home}/.local/bin/claude-rc hook',+ f'{home}/.local/bin/adom-wiki discover suggest --hook',+ }+ commands |= {f'HD_HOOK_EVENT={event} HD_HOOK_AI=codex ~/.adom/hd-ai-threads-hook.sh'+ for event in ('SessionStart', 'UserPromptSubmit', 'Stop', 'Notification')}+ try:+ listed = json.loads(trusted_hooks_file().read_text())+ except (OSError, ValueError):+ listed = []+ if isinstance(listed, list):+ commands |= {c for c in listed if isinstance(c, str) and c.strip()}+ return commands+++def hooks_to_trust(hooks, allowed, user_file):+ """Pure: {key: {'trusted_hash': hash}} for each hook to trust now."""+ user_file = os.path.realpath(str(user_file))+ value = {}+ for hook in hooks:+ if hook.get('command') not in allowed: continue+ if hook.get('source') != 'user' or hook.get('isManaged'): continue+ if os.path.realpath(str(hook.get('sourcePath') or '')) != user_file: continue+ if str(hook.get('trustStatus', '')).lower() not in ('untrusted', 'modified'): continue+ if hook.get('enabled') is False: continue # switched off by the user: leave it alone+ if not hook.get('key') or not hook.get('currentHash'): continue+ value[hook['key']] = {'trusted_hash': hook['currentHash']}+ return value+++def trust_adom_hooks(sock, allowed):+ """Trust Adom's own hooks through the running backend. Returns the commands trusted."""+ with unix_connect(str(sock), compression=None, max_size=None, open_timeout=5,+ close_timeout=1) as connection:+ request_id = 0+ def rpc(method, params):+ nonlocal request_id+ request_id += 1+ connection.send(json.dumps({'id': request_id, 'method': method, 'params': params}))+ deadline = time.monotonic() + 10+ while time.monotonic() < deadline:+ reply = json.loads(connection.recv(timeout=max(.01, deadline-time.monotonic())))+ if reply.get('id') == request_id:+ if 'error' in reply: raise RuntimeError(f'{method}: {reply["error"]}')+ return reply['result']+ raise RuntimeError(f'{method}: no answer')+ rpc('initialize', {'clientInfo': {'name': 'adom-codex-hook-trust', 'version': '1'},+ 'capabilities': {'experimentalApi': True}})+ connection.send(json.dumps({'method': 'initialized'}))+ listed = rpc('hooks/list', {'cwds': [str(Path.home())]})+ hooks = [hook for entry in listed.get('data', []) for hook in entry.get('hooks', [])]+ value = hooks_to_trust(hooks, allowed, codex_home() / 'hooks.json')+ if not value: return []+ rpc('config/batchWrite', {'edits': [{'keyPath': 'hooks.state', 'mergeStrategy': 'upsert',+ 'value': value}], 'reloadUserConfig': True})+ return sorted({hook['command'] for hook in hooks if hook.get('key') in value})+++def maybe_trust_hooks(sock, directory, now=time.time):+ """Run the trust step once per backend, again whenever hooks.json or the allowed list+ changes, and retry a failure at most every ten minutes. One line per outcome in+ hook-trust.log; the last outcome in hook-trust.json (shown by --runtime-status)."""+ try:+ backend = json.loads((directory / 'server.json').read_text())+ hooks_mtime = (codex_home() / 'hooks.json').stat().st_mtime_ns+ except (OSError, ValueError):+ return None+ allowed = sorted(adom_hook_commands())+ marker = {'pid': backend.get('pid'), 'start_ticks': backend.get('start_ticks'),+ 'hooks_mtime': hooks_mtime,+ 'allowed': hashlib.sha256(json.dumps(allowed).encode()).hexdigest()[:16]}+ state = directory / 'hook-trust.json'+ with (directory / 'hook-trust.lock').open('a') as guard:+ fcntl.flock(guard, fcntl.LOCK_EX)+ try:+ last = json.loads(state.read_text())+ except (OSError, ValueError):+ last = {}+ if last.get('marker') == marker and (not last.get('error') or now() - last.get('at', 0) < 600):+ return last+ record = {'marker': marker, 'at': now(), 'trusted': [], 'error': None}+ try:+ record['trusted'] = trust_adom_hooks(sock, set(allowed))+ line = ('trusted ' + '; '.join(record['trusted'])) if record['trusted'] else 'nothing to trust'+ except Exception as error:+ record['error'] = str(error)[:300]+ line = f'skipped, Codex keeps asking: {record["error"]}'+ with (directory / 'hook-trust.log').open('a') as log:+ log.write(time.strftime('%Y-%m-%d %H:%M:%S ') + f'Adom hooks: {line}\n')+ temporary = state.with_suffix('.tmp')+ temporary.write_text(json.dumps(record, indent=2) + '\n')+ temporary.replace(state)+ return record+++def hook_trust_loop(sock, directory, every=30):+ """While this view is connected: at once, then whenever hooks.json changes."""+ while True:+ try: maybe_trust_hooks(sock, directory)+ except Exception: pass+ time.sleep(every)++ def proxy(sock): # The native Unix listener speaks WebSocket; the extension speaks JSONL. # No message rewriting: IDs, approvals, notifications and usage pass through.@@ -399,7 +528,10 @@ def main(): pending = path.with_name('upgrade.json') upgrade = json.loads(pending.read_text()) if pending.exists() else None if upgrade and upgrade.get('pid') != metadata.get('pid'): upgrade = None- print(json.dumps({**metadata, 'alive': process_matches(metadata), 'upgrade': upgrade}, indent=2))+ trust = path.with_name('hook-trust.json')+ hook_trust = json.loads(trust.read_text()) if trust.exists() else None+ print(json.dumps({**metadata, 'alive': process_matches(metadata), 'upgrade': upgrade,+ 'hookTrust': hook_trust}, indent=2)) return binary = native_binary() args = server_args(argv)@@ -410,6 +542,7 @@ def main(): fcntl.flock(client_guard, fcntl.LOCK_SH) sock = ensure_server(binary, args, client_guard) fcntl.flock(client_guard, fcntl.LOCK_SH)+ threading.Thread(target=hook_trust_loop, args=(sock, state_dir()), daemon=True).start() proxy(sock)