fix(hooks): make Codex hooks effective (PostToolUse socket, alternation-aware Grep, per-turn UserPromptSubmit)#245
Open
zzet wants to merge 1 commit into
Open
fix(hooks): make Codex hooks effective (PostToolUse socket, alternation-aware Grep, per-turn UserPromptSubmit)#245zzet wants to merge 1 commit into
zzet wants to merge 1 commit into
Conversation
…lternation-aware Grep, per-turn UserPromptSubmit The Codex hook integration fired correctly but delivered almost no graph value. Three independent gaps, now closed. 1. PostToolUse enrichment reached a removed HTTP API. lookupEnclosingSymbol and lookupFileCallerCount queried http://localhost:<port>/api/graph/*, an endpoint that was retired when the web surface moved onto the daemon — so every enclosing-symbol / caller lookup silently returned nothing regardless of configuration. The PreToolUse twin was already migrated to the AF_UNIX daemon socket; PostToolUse was left behind. Route both through one shared daemonFileSummaryRaw helper (get_file_summary over the socket), compute the enclosing symbol from node line spans client-side, and report importer count from the file's dependents. Deletes queryGortex and the net/http dependency. 2. PreToolUse skipped Codex's multi-keyword Grep patterns. Codex wraps grep in Bash and batches keywords behind '|' (place_edges|location_edge|...), so the whole pattern is never a bare identifier and classifyGrepPattern skipped it — 91% of probes were skipped_non_symbol. Split alternation patterns and probe each identifier-shaped alternative, aggregating hits; steer pure-text patterns (phrases, hyphenated words) toward search_text. 3. Codex had no per-turn reinforcement. A SessionStart orientation fades as context grows and Codex forgets MCP tools. Wire a Codex UserPromptSubmit hook (the event Codex supports without a matcher) that re-surfaces prompt-relevant graph symbols on every turn, reusing the existing buildUserPromptSubmitContext path already shared with Claude Code and Kimi. Adds a socket seam (fileSummaryFn) plus unit tests for enclosingNode, parseFileSummary, alternation splitting, and the Codex UserPromptSubmit install + dispatch. The vestigial --port flag is retained for backward compatibility but is no longer consumed. Fixes #241
2182359 to
9f5fbac
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #241.
Codex's hooks fired correctly but delivered almost no graph value. The investigation confirmed all three reported gaps and one was worse than diagnosed — the PostToolUse HTTP endpoint doesn't just fail on an occupied port, it no longer exists. This PR closes all three, cross-referenced against the official Codex hooks spec.
1. PostToolUse enrichment reached a removed HTTP API (root cause)
lookupEnclosingSymbol/lookupFileCallerCountqueriedhttp://localhost:<port>/api/graph/symbol-atand/api/graph/file-callers. Those routes were retired when the web surface migrated onto the daemon — the daemon's HTTP surface (only with--http-addr) serves/v1/*+/mcp, never/api/graph/*. So every lookup silently returned nothing regardless of port or configuration, and since Codex runs in softenrichmode where PostToolUse carries the value, Codex got ~zero enrichment.The PreToolUse twin was already migrated to the AF_UNIX daemon socket (commit that "route[d] file-indexed probe through daemon socket"); PostToolUse was left behind. This routes both through one shared
daemonFileSummaryRawhelper (get_file_summaryover the socket), computes the enclosing symbol from node line-spans client-side, and reports importer count from the file'sdependents. DeletesqueryGortexand thenet/httpdependency.2. PreToolUse skipped Codex's multi-keyword Grep patterns
Codex wraps grep in Bash and batches keywords behind
|(e.g.place_edges|location_edge|normalize), so the whole pattern is never a bare identifier andclassifyGrepPatternskipped it — 91% of probes wereskipped_non_symbol. Now alternation patterns are split and each identifier-shaped alternative is probed (hits aggregated + deduped); pure-text patterns (phrases, hyphenated words) are steered towardsearch_text, the correct graph equivalent for literal search. The single-pattern fast path is unchanged.3. Codex had no per-turn reinforcement
A SessionStart orientation fades as context grows and Codex forgets MCP tools — the core adoption concern in the issue thread. This wires a Codex
UserPromptSubmithook (the event Codex supports without a matcher, per the spec) that re-surfaces prompt-relevant graph symbols on every turn, reusing the existingbuildUserPromptSubmitContextpath already shared with Claude Code and Kimi.Tests
enclosingNode(line-span resolution),parseFileSummary,splitAlternation, alternation probing (hit / mixed / pure-text / unreachable), CodexUserPromptSubmitinstall + dispatch.go build ./...,go test -race ./internal/hooks/... ./internal/agents/codex/..., andgo test ./cmd/gortex/...all pass.Notes / follow-ups (not in this PR)
--portflag is now vestigial (kept for backward compatibility with existing hook configs).apply_patchand MCP tools — an edit-redirect forapply_patchis a plausible future addition but stays out of scope (edit-blocking is env-gated/experimental).command_windows; the spec's TOML example showscommandWindows. Flagged for separate Windows-only verification — untouched here.UserPromptSubmitpayload omits apromptfield, the new hook degrades to a silent no-op.