Approve installed Codex hooks

Merged
LA
6mo ago
+1239-162

Summary

  • Trust cmux-owned Codex hook entries during install by writing Codex's hooks.state trusted_hash format.
  • Remove the marked cmux trust block on reinstall and uninstall.
  • Add coverage that generated Codex hook trust hashes match Codex's normalized hook identity.

Verification

  • ./scripts/reload.sh --tag codhk
  • Built CLI smoke check: temp CODEX_HOME, /tmp/cmux-cli hooks codex install --yes, then Codex 0.130.0 app-server hooks/list reported all five cmux hooks as trusted.
  • Did not run the Python socket test suite locally because this checkout forbids local test runs.

[!NOTE]
Medium Risk
Updates Codex hook install/uninstall to rewrite config.toml and compute persistent trust hashes, which could affect users’ existing hook and feature configuration if edge cases are missed. Includes migration and legacy-detection logic plus extensive tests, but touches config parsing and hook ownership matching.

Overview
Codex hook installation now auto-approves cmux-owned hooks by writing a cmux-marked hooks.state block into config.toml, with deterministic sha256: trusted_hash values derived from each installed hook’s canonical identity.

The install/uninstall flow also migrates away from the deprecated codex_hooks flag to features.hooks, removes only cmux-managed blocks on reinstall/uninstall (and avoids adding trust if the prior trust marker is malformed), detects and replaces legacy Codex hook command forms, and preserves the prior relative position of cmux hooks when merging with third-party hook entries.

Adds broad regression coverage in test_codex_feed_hooks.py for trust-hash generation/escaping, legacy migrations, hook ordering, malformed marker handling, and unreadable/invalid config.toml behavior.

Reviewed by Cursor Bugbot for commit b2e4e8387b2ed1594e0b8f80759388b51be190c0. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Auto-approve cmux-installed Codex hooks by writing deterministic sha256: trust hashes to hooks.state during install and pruning them on reinstall/uninstall. Also migrate deprecated codex_hooks to features.hooks with cmux markers while preserving user config and hook order.

  • New Features

    • Install writes a cmux-marked hooks.state block for Codex: keys are the normalized real hooks.json path plus event/group/handler index; values are sha256: of Codex’s canonical hook identity (includes matcher and timeout; statusMessage when present).
    • Manage a cmux-marked features.hooks setting: migrate from codex_hooks (table or dotted form), insert in the real [features] table or as features.hooks, and print “Enabled hooks …” (adds “and approved cmux hooks” when trust entries are written).
  • Bug Fixes

    • Preserve cmux hook insertion position with third‑party hooks; replace legacy cmux codex-hook/cmux feed-hook commands with current cmux hooks ... (legacy commands are not trusted); never mutate non‑cmux hooks.
    • Harden ownership and TOML handling: match exact cmux hook/feed command strings, TOML‑escape trust keys, scan past bracketed arrays, skip adding trust if a prior cmux trust marker is unclosed, remove only the cmux trust block on uninstall and drop an empty [features] table from our install, edit only real [features]/features.hooks entries, and surface unreadable config.toml errors without overwriting the file.

Summary by CodeRabbit

  • New Features

    • Adds a TOML "hook trust" block with deterministic SHA‑256 trust hashes for approved hooks.
  • Improvements

    • Install/uninstall now add/remove the hook-trust state, handle TOML begin/end markers, and preserve cmux-owned hook insertion positions when merging with third‑party hooks.
    • Post-install message reflects when both hooks and approved-hook state are enabled.
    • Uninstall preserves unowned trust entries if a cmux marker is malformed.
  • Tests

    • Added tests for trust-hash generation, TOML escaping, position preservation, and uninstall behavior.

Review Change Stack