Skip to content

feat(hooks): record Codex hook trust on sync with --trust - #829

Merged
runkids merged 15 commits into
runkids:mainfrom
salmonumbrella:feat/codex-hook-trust
Nov 17, 2026
Merged

runkids merged 15 commits into
runkids:mainfrom
salmonumbrella:feat/codex-hook-trust

Conversation

@salmonumbrella

@salmonumbrella salmonumbrella commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Type

  • Bug fix
  • Small improvement (docs, typo, minor refactor)
  • Feature proposal (proposals/ only — see CONTRIBUTING.md)
  • Approved feature or large change (the linked issue has the approved label)

Maintainer note: the maintainer took the branch over from e3afd64c and pushed the commits after it. The contributor's original commits are unchanged. This description covers the branch as it is now; the direction is in this comment.

What changed

  • New opt-in --trust flag on skillshare hooks sync, global mode only. After the sync writes, it asks Codex which of the hooks Skillshare owns are new or changed, in every Codex home it manages, account homes like codex-2 included.
  • Confirmation. Those hooks are listed with their full commands and confirmed once. --yes (-y) skips the question. Without a terminal and without --yes, nothing is trusted and the command exits with an error that names --yes. --json never asks: without --yes it reports the hooks as needed and exits non-zero. A hook that is already trusted needs no answer.
  • Trust is recorded only for what was shown. The listing returns a revision of the hooks that need trust and their hashes. The write takes that revision and is refused when the hooks changed in between.
  • The hash comes from Codex itself: one short-lived codex app-server per home, hooks/list for each hook's currentHash, then config/batchWrite on hooks.state."<key>".trusted_hash. Same calls the TUI's /hooks review makes, so Skillshare never computes or guesses the hash.
  • Only trusted_hash changes. enabled and the rest of config.toml stay as they are; a Skillshare hook that's disabled in Codex is reported, not switched on. Hooks Skillshare doesn't own are never touched.
  • No state file, and nothing is cleared. Skillshare keeps no record of the trust it wrote. When a hook moves or is removed, its old entry stays in config.toml. It only ever matches a hook with the same event, matcher and handler at that position, which is the hook the user already approved.
  • Symlinked default home. For ~/.codex the app-server is started without CODEX_HOME. Codex resolves the symlinks of CODEX_HOME but not of ~/.codex, so a symlinked default home used to get a trust key the user's own Codex never looks up.
  • One home does not stop the others. A home Codex cannot list, or whose write fails, is left out and named in the error; the other homes are still trusted. Codex reports a home it cannot load (for example an invalid config.toml) inside a successful reply, and that is treated as a failed listing.
  • Dashboard. The Hooks page (global scope) has a "Trust Codex hooks" button when a hook is bound to a Codex target and nothing is waiting to be synced. The dialog shows each hook that needs trust with its command and records trust only after the user confirms. Two routes back it: POST /api/hooks/codex-trust/preview and POST /api/hooks/codex-trust.
  • A trust preview releases the hooks operation lock before it waits on Codex, so a slow Codex does not fail other hooks operations.
  • If codex isn't on PATH or the app-server fails, the hook files are still written and the command fails with "hook files were written, but Codex trust was not recorded". --json results get a codexTrust list.
  • sync hooks, hooks list and project mode reject --trust. Plain hooks sync is unchanged and never starts Codex.
  • Help, all five shell completions, the hooks reference page and its four translations, the built-in skill reference and all eleven dashboard locales are updated.

Why

Codex won't run a user-level hook until it's trusted, and trust is keyed by the hook's position in hooks.json. Only /hooks in the TUI writes it, so every hook Skillshare adds or moves starts untrusted and codex exec skips it silently. Today that means opening /hooks in every Codex home after every sync, or running with --dangerously-bypass-hook-trust, which trusts everything.

feat-hooks-record-Codex-hook-trust-on-sync-with-trust.mp4

Usage

skillshare hooks sync --trust -g          # lists the commands, asks once
skillshare hooks sync --trust --yes -g    # no question, for scripts
skillshare hooks sync --trust --yes --json -g
Codex trust
  stop      needs trust  codex  /home/me/.codex/hooks.json:stop:1:0
            ./notify.sh

? Trust 1 hook in Codex?  Yes  No

Codex trust
✓ stop      trusted  codex  /home/me/.codex/hooks.json:stop:1:0

Needs codex on PATH. Default is off.

Closes #828

Not covered

  • Project-level Codex hooks (.codex/hooks.json) and hooks.projects roots. Their trust also depends on Codex trusting the project, so --trust refuses project mode.
  • Plugin hooks. Codex also checks a hash of the whole plugin bundle for those, which this does not record.
  • Old trust entries are not removed from config.toml (see above).
  • In --json mode the reason for a trust failure is not printed; the exit code and the needed rows are the signal. This is how every --json hooks result reports an error.
  • The dashboard does not show a standing per-hook trust status; it asks Codex when the dialog opens.

Checks

On 65b5c9eb, inside the devcontainer:

  • make check passed.
  • python3 scripts/ai-context.py check passed.
  • End to end against the real Codex 0.167.0 binary in a throwaway HOME with a default home and an account home:
    • --yes --json: both homes trusted; a second run reports both unchanged.
    • Account home with an invalid config.toml: the default home is trusted, the account home is named in the error, exit code 1.
    • No codex-trust.json is created.

Earlier on this branch, before the last three commits (the code paths they exercise did not change since), also against real Codex 0.167.0:

  • No terminal and no --yes: the commands are listed, the command fails, nothing is written.
  • Default home as a symlink with CODEX_HOME unset: the key is written as ~/.codex/... and the user's Codex reports the hook trusted.
  • Interactive question driven through a pty: No leaves the hook modified, Yes makes it trusted.
  • Two trust previews at once through the dashboard API both return 200.

Not done: the dashboard dialog has component tests but no browser screenshot, the interactive question has no automated test, and the website build was not run.

Checklist

  • I've read CONTRIBUTING.md, including its AI-assisted contributions section
  • I've reviewed every line of the diff and can explain it
  • Tests included and passing (make check)
  • No unrelated changes in the diff
  • Scope is focused — one concern per PR

@salmonumbrella
salmonumbrella marked this pull request as ready for review November 10, 2026 10:41
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T07:43:39.007953Z 12cc066 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: da9d766c65

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +88 to +90
for key, r := range state.Records {
if r.Root != "" || s.agentOf(r.Target) != "codex" {
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict trust to records owned by the active config

When two global configs are selected through SKILLSHARE_CONFIG, they intentionally share StateDir, so this loop also collects the other config's Codex records. Running hooks sync --trust -g for config B therefore trusts config A's hooks even if B has no Codex entries in its source or preview; the normal planner avoids crossing this boundary by checking r.Owner against the source config. Filter records by the active config's absolute owner and preserve that ownership in codex-trust.json so trust reconciliation cannot cross config scopes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a6433dd. TrustCodex filters ledger records by the active absolute config owner and persists hashes per owner and hooks.json path. Legacy v1 hashes are cleanup-only. Covered by TestCodexTrustIsScopedByConfigOwner and TestCodexTrustMigratesLegacyStateForRemovedHooks.

Comment thread internal/hooks/codex_trust.go Outdated
Comment on lines +166 to +170
entry, ok := positions[codexPosition(h.Key)]
if !ok {
continue
}
result := CodexTrust{Target: target, Entry: entry, Key: h.Key, Action: "unchanged", Disabled: !h.Enabled}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Revalidate hook identity after Codex reads hooks.json

If another editor or tool prepends or replaces a group in hooks.json while codex app-server starts, positions still describes the earlier file while hooks/list returns the new handlers. Matching solely by source path and event/group index then assigns the old owned entry to the new unmanaged handler and records that handler's currentHash, allowing --trust to authorize a hook Skillshare does not own. Verify that the native snapshot used to locate ownership is still the snapshot represented by the listing before constructing trust edits.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a6433dd. TrustCodex rereads hooks.json after hooks/list and aborts before constructing edits if its existence or bytes changed since the ownership snapshot. Covered by TestCodexTrustRevalidatesHooksSnapshotAfterList, which prepends an unmanaged group during listing and verifies no trust write.

Comment thread internal/hooks/codex_trust.go Outdated
Comment on lines +195 to +196
if err := server.SetTrust(edits); err != nil {
return results, written, err

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Report trust changes only after the batch write succeeds

If config/batchWrite rejects the edit batch or times out, results already contains trusted and cleared actions even though those writes have not been confirmed. Returning these rows unchanged causes printHooksTrust and --json to report completed trust changes despite the failed operation. Append successful mutation actions only after SetTrust succeeds, or explicitly mark those actions as failed or unconfirmed while preserving any genuinely unchanged rows.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a6433dd. On SetTrust failure, TrustCodex returns only unchanged rows; trusted and cleared actions are reported only after config/batchWrite succeeds. Covered by TestCodexTrustDoesNotReportUnconfirmedEdits for both failed trust and failed clear calls.

@salmonumbrella

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a6433dd63a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/hooks/codex_trust.go Outdated
homes := map[string]string{}
owned := map[string]map[string]record{}
for key, r := range state.Records {
if r.Owner != owner || r.Root != "" || s.agentOf(r.Target) != "codex" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Locate all file records before applying the owner filter

If configs A and B manage the same Codex home, the documented hooks edit ... --sync workflow (website/docs/reference/commands/hooks.md:25) can make B's existing group identical to A's; planShared permits this in-place update. Filtering out A's record before trustCodexHome calls locate leaves one holder for two identical native groups, so the ownership predicate at internal/hooks/plan.go:372 rejects B's record. Consequently, B's hooks sync --trust -g succeeds without recording trust for its hook, which remains untrusted. Locate against all per-file records, then restrict the resulting positions to the active owner.

AGENTS.md reference: AGENTS.md:L36-L36

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a50ca323: locate now sees every record for the canonical hooks file before applying the active-owner filter; TestCodexTrustLocatesIdenticalHooksAcrossConfigOwners covers shared-path and symlink-alias cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The earlier a50ca323 fix is already in this PR as rebased commit 6ff2322d: git range-diff a6433dd6..a50ca323 03719577..6ff2322d reports the patches equal. The branch was subsequently updated to c369ce70; the fix was not lost.

The current follow-up eb992186bdbec67b43a410347f2426964146a19a preserves locating all records for the canonical file before applying the active-owner filter and corrects the alias test's expected keys. TestCodexTrustLocatesIdenticalHooksAcrossConfigOwners covers both shared-path and symlink-alias cases. ac3af435 merges current upstream main without rewriting the published branch.

@runkids

runkids commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Reviewed at a6433dd. I reproduced two P2 issues:

  1. Identical hooks across configs are silently skipped (internal/hooks/codex_trust.go:97). With configs A and B sharing a Codex home, create different hooks, then edit B’s existing hook to match A’s. B’s hooks sync --trust -g succeeds without recording trust. Filtering records by owner before locate makes the native group count differ from the holder count. This confirms the latest Codex finding: locate against all per-file records, then select positions owned by the active config.

  2. Switching Codex homes discards trust-cleanup receipts (internal/hooks/codex_trust.go:128–131). Trust a hook, change CODEX_HOME, sync with --trust, then restore the original home and remove the hook with another trust sync. The original trusted_hash remains. The parked hook is excluded from active positions; its matching hash prevents clearing, but the empty returned keep map causes its saved receipt to be deleted. Keep receipts for still-owned parked registrations so cleanup can resume when the home becomes active again.

Verification: the existing internal/hooks suite passed in a temporary container using the devcontainer image. Two temporary Go-overlay regression checks reproduced the failures above. Real Codex E2E was not run. No additional findings in the rules, spec, consumer, or cleanup passes.

@salmonumbrella

Copy link
Copy Markdown
Contributor Author

Fixed in a50ca323: identical hooks now locate across all config owners and symlink aliases before owner filtering; TestCodexTrustLocatesIdenticalHooksAcrossConfigOwners covers both.
Fixed in a50ca323: parked receipts remain only for still-owned matching hook positions, including ambiguous duplicates, so later cleanup still works; TestCodexTrustKeepsReceiptsForParkedHomes, TestCodexTrustKeepsParkedReceiptsWhenDuplicateCountsAreAmbiguous, and TestCodexTrustClearsRemovedReceiptsWhileAnotherHookIsParked cover this.
Left go test ./internal/hooks -run '^TestCodexTrust(LocatesIdenticalHooksAcrossConfigOwners|KeepsReceiptsForParkedHomes|KeepsParkedReceiptsWhenDuplicateCountsAreAmbiguous|ClearsRemovedReceiptsWhileAnotherHookIsParked)$' -count=1 to upstream CI because Boat returned 429 and Namespace did not yield a usable Go test run; upstream checks are running.

@salmonumbrella

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: a50ca32344

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@runkids

runkids commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Re-reviewed at a50ca32 (changes since a6433dd). Both P2 issues from the last round are fixed:

  1. Identical hooks across configs — locate now runs against every record for the canonical hooks.json, and the owner filter is applied afterwards, so the group count and holder count agree again.
  2. Parked receipts — receipts for still-owned registrations in a parked home are kept while the hash still matches, and cleanup resumes once the home is active again. I also checked that the CLI can reach this path: the new home gets its own record key, so the sync succeeds and trust runs.

Two small notes, neither blocking:

  • Symlinked home spelling (low). homes is keyed by the raw path while owned is now keyed by the canonical path (codex_trust.go:118-129). If a home was trusted as ~/.codex and CODEX_HOME later points at a symlink to the same directory, both spellings end up in homes, so the same file gets two app-server runs, duplicate rows under "Codex trust", and two entries in codex-trust.json. Nothing is trusted or cleared wrongly. I have not confirmed this against a real Codex; keying homes by canonical path too would likely close it.
  • Redundant branch (optional). The parked[key] check inside the locate loop (codex_trust.go:218-220) is covered by the fallback loop just below, since locate only returns positions whose hash matches. Removing it would not change behaviour.

Verification: read against locate and the planner's parked handling; CI is green on a50ca32. I did not run a real Codex end to end this round.

Before merge: please tick the "reviewed every line of the diff" box once you have read it, and update the branch, which is behind main.

salmonumbrella and others added 4 commits November 10, 2026 11:38
Codex runs a user-level hook only after its trusted_hash is stored in that
home's config.toml, keyed by the hook's position in hooks.json. Only the
TUI's /hooks review writes it, so every hook Skillshare adds or moves starts
untrusted and codex exec skips it without a word.

`hooks sync --trust` (global mode, opt-in) asks each Codex home's
`codex app-server` for the current hash of the hooks Skillshare owns and
writes trusted_hash through config/batchWrite, the same calls /hooks makes,
so the hash is always the one Codex computes. It changes nothing else in
config.toml: disabled hooks stay disabled and are reported. Trust it wrote
is remembered in the hooks state directory, so when a hook moves or is
removed the next --trust sync clears the old position, unless that trust
has changed since. Without codex on PATH the hook files are still written
and the command fails saying trust was not recorded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Scope trust selection and saved hashes to the active config owner so a global config cannot trust or reconcile another config’s hooks.

Recheck hooks.json after hooks/list to avoid trusting a handler from a stale position, and only report trusted or cleared actions after config/batchWrite succeeds. Keep v1 ownerless hashes cleanup-only so upgraded installs clear stale trust after hook removal without trusting foreign hooks.
Locate hooks using all records for their canonical file before selecting the active config owner, so identical hooks remain identifiable across shared and symlinked homes. Keep cleanup receipts for parked registrations whose native group still matches, including when duplicate counts make locate ambiguous, while clearing receipts for removed hooks.

Add regressions for identical hooks across config owners, symlink aliases, parked-home restoration, ambiguous duplicates, and stale receipt cleanup.
Canonicalize current-owner and legacy trust receipts so symlink spellings of one hooks.json are processed once. Remove the redundant parked-position branch because the hash-matching fallback below covers it. Add regression coverage for current and legacy receipts.
@salmonumbrella

Copy link
Copy Markdown
Contributor Author

Fixed in c369ce70: active-owner and legacy v1 receipts now coalesce by canonical hooks.json path, so symlink spellings use one app-server; covered by TestCodexTrustCoalescesSymlinkedHomes and TestCodexTrustCoalescesLegacySymlinkedHomesForRemovedHooks.
Removed the redundant parked-position assignment; the matching-hash fallback preserves parked receipts, covered by TestCodexTrustKeepsParkedReceiptsWhenDuplicateCountsAreAmbiguous.

@salmonumbrella

Copy link
Copy Markdown
Contributor Author

Verification: ~/.fleet/local-test go test ./internal/hooks -run '^TestCodexTrustCoalescesSymlinkedHomes$' -count=1 returned 75 (no slot at normal memory pressure). The focused regression tests TestCodexTrustCoalescesSymlinkedHomes and TestCodexTrustCoalescesLegacySymlinkedHomesForRemovedHooks, plus broader build and integration checks, are left to upstream CI. No full suite ran locally.

@salmonumbrella

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c369ce709f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/hooks/codex_trust_test.go Outdated
Comment on lines +346 to +347
firstKey := fmt.Sprintf("%s:session_start:%d:0", hooksPath, firstIndex)
secondKey := fmt.Sprintf("%s:session_start:%d:0", hooksPath, secondIndex)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Build the alias test's expected keys from the canonical home

On symlink-capable platforms, this subtest retains codex-alias/hooks.json in hooksPath, but TrustCodex now starts the fake server under the canonical home, and fakeCodexServer.ListHooks constructs keys from that home. Consequently, the assertion immediately below compares a .codex/hooks.json key against a codex-alias/hooks.json key and fails; the subsequent hash assertion uses the wrong prefix too. Canonicalize the path used for both expected keys so the required make check can pass. Go tests could not be run here because the devcontainer is unavailable.

AGENTS.md reference: AGENTS.md:L80-L81

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in eb992186bdbec67b43a410347f2426964146a19a. The shared-owner alias test now derives both expected native keys from the canonical hooks path. Related trust-key and receipt assertions also use canonical paths so a symlinked temporary-home prefix is handled consistently. Covered by TestCodexTrustLocatesIdenticalHooksAcrossConfigOwners, including its shared-path and symlink-alias cases.

Comment thread internal/hooks/codex_trust_test.go Outdated
Comment on lines +418 to +419
e.service.ConfigDirs["codex"] = alias
save(t, e.service, Mutation{Name: "owned", Entry: codexTrustEntry(t, "echo owned")})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid the alias resync in the coalescing test fixture

When this test changes the configured home to the alias, the existing ledger still contains the real .codex/hooks.json path. The subsequent save retains that path for planning, but planShared checks it against the new alias base, so checkPath returns an “outside” error and the helper fails before the coalescing assertions are reached. The duplicate receipts already exercise coalescing without this extra resync; remove that dependency on unsupported ledger-path migration so this new test does not block the required make check.

AGENTS.md reference: AGENTS.md:L80-L81

Useful? React with 👍 / 👎.

@salmonumbrella salmonumbrella Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in eb992186bdbec67b43a410347f2426964146a19a. TestCodexTrustCoalescesSymlinkedHomes now changes the home spelling only for trust reconciliation; it no longer resyncs the real-path ledger through an alias. The duplicate receipts still exercise coalescing, and the test retains its one-app-server and one-canonical-receipt assertions.

Follow-up e3afd64c6ee3be229bda690731032756d92ebebd fixes the CI assertion fixture: it decodes the reconciled on-disk JSON into a fresh state value, because json.Unmarshal into the seeded nonempty map retains deleted alias entries. The one-home, canonical-path and one-app-server assertions remain intact. Upstream Nix, unit and Docker-offline logs all identified that same fixture failure; exact-head Test run 43156808237 and Nix 43156808189 now pass, including the named regression.

Comment thread internal/hooks/codex_trust.go Outdated
if path == "" {
continue
}
path = canonicalPath(path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Canonicalize the home when hooks.json no longer exists

When reconciling real-path and symlink legacy receipts after removing the last hook from a Skillshare-created file, planShared deletes hooks.json. canonicalPath then cannot resolve the complete path and returns its original spelling, leaving the two receipts in separate groups despite their parent directories identifying the same home. Cleanup consequently starts Codex twice, and the newly added TestCodexTrustCoalescesLegacySymlinkedHomesForRemovedHooks fails its starts == 1 assertion. Resolve the existing parent directory and append hooks.json so missing-file cleanup coalesces too and the required make check can pass.

AGENTS.md reference: AGENTS.md:L80-L81

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in eb992186bdbec67b43a410347f2426964146a19a. canonicalCodexHooksPath resolves the hooks file when present and otherwise resolves its parent home before appending the filename. Trust grouping, active-home matching and receipt coalescing use that same boundary, including after the last hook file is removed. TestCodexTrustCoalescesLegacySymlinkedHomesForRemovedHooks retains its single-app-server assertion, alongside the active-owner coalescing and parked-home regressions.

Resolve existing home directories when hook files have been removed so trust receipts for symlink aliases reconcile once. Correct canonical key expectations and exercise coalescing without unsupported ledger migration.
@salmonumbrella

Copy link
Copy Markdown
Contributor Author

@codex review

Please review eb992186bdbec67b43a410347f2426964146a19a, which fixes the alias fixtures and canonicalizes removed hooks paths. The earlier a50ca323 patch is already included as rebased commit 6ff2322d; their range-diff is equal. ac3af435 updates the branch from upstream main.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

JSON decoding retains existing map entries, so reusing the seeded receipt map makes the alias appear to survive reconciliation. Decode the persisted state into a new value to verify its actual contents.
@salmonumbrella

Copy link
Copy Markdown
Contributor Author

@runkids please check

@runkids runkids added feature New feature or request pending labels Nov 15, 2026
@runkids

runkids commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thanks for the fixes since my last review. I re-reviewed the changes since a50ca32 (c369ce7, eb99218, e3afd64). The symlink coalescing and the removed redundant branch look right, and CI is green.

Two things for the next round:

  1. The confirmation step from hooks sync: optionally record Codex hook trust for the hooks it writes #828. The interface is settled there: list the hooks to be newly trusted with their commands, ask once, --yes to skip, and trust nothing without a terminal unless --yes is given. Please add it here.

  2. Trust keys when ~/.codex is a symlink (P2). Codex builds the hook key from the hooks.json path string (hook_key(key_source, …) in codex-rs/hooks/src/engine/discovery.rs). It canonicalizes CODEX_HOME when the variable is set, but uses ~/.codex as-is when it isn't (codex-rs/utils/home-dir/src/lib.rs). startCodexAppServer always sets CODEX_HOME (internal/hooks/codex_trust.go:442), so the trust it writes is keyed by the resolved path.

    Scenario: ~/.codex is a dotfiles symlink to ~/dotfiles/codex, and CODEX_HOME is unset. hooks sync --trust -g records trusted_hash under …/dotfiles/codex/hooks.json:…, while the user's Codex looks up ~/.codex/hooks.json:…, so the hook stays untrusted under codex exec. This is in the PR as a whole, not only the latest commits.

    One way to close it: for the default home, start the app-server without CODEX_HOME, so keys are computed the way the user's Codex computes them. I found this by reading the Codex source and have not run it against a real Codex, so a test with a symlinked default home would help confirm it.

Verification: I read the delta and the Codex source; I did not run the tests locally.

@runkids runkids removed the pending label Nov 15, 2026
@runkids

runkids commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks for all the work on this, and for turning the review rounds around so quickly.

I'm going to take the branch from here and push the remaining changes myself, so you don't need to do the two items I asked for on the 15th. Your commits stay as they are. Please hold off on pushing to feat/codex-hook-trust while I work on it.

The direction:

  1. Confirmation step, as settled in hooks sync: optionally record Codex hook trust for the hooks it writes #828: list the hooks that would be newly trusted with their commands, ask once, --yes to skip, and trust nothing without a terminal unless --yes is given.
  2. Trust keys when the default home is a symlink, so the key matches what the user's Codex computes.
  3. No codex-trust.json, and no clearing of old trust. This changes what I wrote in hooks sync: optionally record Codex hook trust for the hooks it writes #828, where I said clearing needs no confirmation. Looking at it again, a leftover entry only ever matches a hook with the same event, matcher and handler at that position, which is the hook the user already approved. Clearing is tidiness, not safety, and the receipts file is where most of the edge cases in the review rounds came from. Old entries will stay in config.toml, and the docs will say so.
  4. Dashboard: the Hooks page gets the same action. It shows the hooks that need trust with their commands, and records trust only after the user confirms in the dialog.
flowchart TD
    A["hooks sync --trust -g"] --> B["Write hook files, same as today"]
    B --> C["Ask Codex for the trust status of the hooks Skillshare owns, per Codex home"]
    C --> D{"Any hook new or changed?"}
    D -- No --> E["Report unchanged, done"]
    D -- Yes --> F["List those hooks with their commands"]
    F --> G{"--yes given?"}
    G -- Yes --> K["Record trusted_hash through Codex"]
    G -- No --> H{"Terminal attached?"}
    H -- No --> I["Trust nothing, exit with an error that names --yes"]
    H -- Yes --> J{"Confirm once"}
    J -- Yes --> K
    J -- No --> L["Trust nothing"]
Loading

In the dashboard, the dialog takes the place of the terminal question.

You asked for the clearing in #828, so if dropping it breaks something in your setup, tell me and I'll look at it again.

…eipts file

`hooks sync --trust` recorded trust for every owned hook without showing
what it was trusting, and tracked its own writes in codex-trust.json so
it could clear them later. Codex's review exists so that a person sees a
command before it runs, and the receipts file was the source of most of
the edge cases found in review.

Trust is now two steps. A preview asks Codex which owned hooks are new
or changed and returns them with their commands and a revision; the
write takes that revision and is refused when the hooks changed since.
The CLI lists the hooks and asks once, `--yes` skips the question, and
without a terminal nothing is trusted unless `--yes` is given. The
dashboard gets the same two steps as API routes.

Nothing is cleared any more: a leftover entry only matches a hook with
the same event, matcher and handler at that position, which is the hook
the user already approved. That removes codex-trust.json.

The app-server is started without CODEX_HOME for the default home.
Codex resolves the symlinks of CODEX_HOME but not of ~/.codex, so a
symlinked default home got a trust key the user's own Codex never looks
up.

A home whose write fails no longer stops the other homes, and the error
names which were recorded. A preview releases the hooks operation lock
before it waits on Codex, so a slow Codex does not fail other hooks
operations.

Refs runkids#828
The dashboard could sync Codex hooks but left them untrusted, so Codex
skipped them until the user ran the CLI or approved each one in Codex.

The Sync box now offers "Trust Codex hooks" in the global scope when a
hook is bound to a Codex target. The dialog shows each hook that needs
trust with its full command and records trust for exactly that list; a
change since the list was shown is refused. The button is hidden while
changes are pending, because trust covers the hooks on disk and the next
sync would invalidate it.

Refs runkids#828
…states

Only the happy path was tested, so a regression in the states where the
dialog must not offer a write would have passed. The docs sentence on
several Codex homes now says what is isolated: a failed write, not a
home that cannot be listed.

Refs runkids#828
…he handlers

hooks_handlers.go had grown past 500 lines and mixed orchestration with
the confirmation prompt and every print function, which the CLI layering
rule asks to keep apart. The code is moved unchanged: the prompt goes to
hooks_prompt.go and the printing to hooks_render.go.
…topping

With several Codex homes, one home Codex could not list aborted the whole
trust run, so a broken account home kept every other home untrusted.

A home that fails to list is now reported and left out, and the other
homes are previewed and trusted as usual. The CLI warns before the
question and exits with an error that names the home; the dashboard
dialog shows the same note. When no home can be listed the preview still
fails.

Codex answers a home it cannot load, such as one with an invalid
config.toml, with a successful reply that has no hooks and the reason in
`errors`. That was read as a home without hooks and passed silently. It
is now a failed listing that carries Codex's own message.

Refs runkids#828
@runkids

runkids commented Nov 17, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 65b5c9eb6b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/hooks/codex_trust.go Outdated
Comment on lines +200 to +201
if revision != plan.Revision {
return plan, fmt.Errorf("Codex hooks changed since they were listed: %w", ErrStaleRevision)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve healthy-home progress when a re-list fails

When two homes have untrusted hooks in the preview but one fails its second hooks/list call during TrustCodex (for example, an app-server timeout after confirmation), the failed home's edits are omitted from needed, changing plan.Revision. This guard then returns ErrStaleRevision before any SetTrust, so the healthy home is not trusted and the actual listing error is masked. Both trustCodexHooks and CodexTrustDialog use this preview-then-apply flow, meaning failure isolation only works when the same homes fail in both passes. Validate the reviewed keys and hashes per home so a failed re-list can be reported without stopping unchanged, reviewed homes.

Useful? React with 👍 / 👎.

The revision was one digest over every home's hooks. When a home was
listed in the preview but failed to list again at the write, its hooks
dropped out of the digest, so the write was refused as stale: the homes
the user had just reviewed stayed untrusted and the real listing error
was hidden behind "changed since they were listed".

The revision now has one part per home. A home is refused only when its
own hooks changed; a home that cannot be listed any more is reported and
the reviewed homes are still trusted.

Refs runkids#828
@runkids

runkids commented Nov 17, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 12cc0663e3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Keep the next release on the patch version the maintainer asked for,
instead of the 0.31.0 that Release Please derives from the feat commit.

Release-As: 0.30.10
@runkids
runkids merged commit ed3c825 into runkids:main Nov 17, 2026
9 checks passed
runkids added a commit that referenced this pull request Nov 17, 2026
The squash commit of #829 carries this footer in the middle of its
message, followed by co-author trailers, so Release Please did not read
it and moved the release to 0.31.0. Keep the next release on the patch
version the maintainer asked for.

Release-As: 0.30.10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hooks sync: optionally record Codex hook trust for the hooks it writes

2 participants