Repository navigation
Herdr: Guard Codex prompts at the PTY writer - #312
Merged
Merged
Conversation
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.
Guard Codex Prompts at the Herdr PTY Writer
Give Stark and other automated callers a way to send a prompt only to the Codex chat they inspected. On Linux, Herdr checks the intended pane, terminal, and rendered Codex thread immediately before writing the prompt and Enter.
Rationale
A single Herdr pane can host several Codex conversations over time. For example, Codex can run
/newin the same process and terminal. Its footer can already show the new conversation while Herdr still has the previous session ID from a lifecycle report. The same terminal can also switch from the message composer to a picker. If Stark checks the pane and queues a prompt before either change, an ordinary send can reach the new chat or press Enter in the picker.Codex owns the active conversation and the text it renders. Herdr owns the terminal input queue and the pseudoterminal (PTY) writer that sends keystrokes to Codex. The check belongs at that writer, where Herdr can recheck the screen and process before sending any bytes. See Stark's doctor delivery integration and the picker issue.
Key Changes
herdr agent prompt. The caller supplies the pane ID, terminal ID, and expected Codex chat ID. An older Herdr server rejects the guarded request shape before it can send input. The ordinary prompt command still supports interactive use.1 - Why the Codex Status Line Shows the Thread ID
Codex already supports the
thread-idandcontext-usedstatus line items. This PR uses that existing Codex CLI configuration. Start the Codex TUI in the pane that will receive guarded prompts with:codex -c 'tui.status_line=["thread-id","context-used"]'The footer shows the active thread ID followed by the existing context usage display, for example
11111111-2222-4333-8444-555555555555 · Context 2% used. The guard in this PR expects that layout. It uses the thread ID to identify the conversation that Codex is actually displaying. Context usage stays visible to the operator and forms part of the expected layout. If the footer omits the ID, the guarded send refuses before writing.The disposable same-process
/newtest changed the rendered ID before the new conversation's first turn, while the cached session and terminal still identified the old one. The guard refused the old target. A matching prompt in a stable chat produced one native user-message record.2 - What a Successful Guard Proves
A successful guard means Herdr wrote to the expected terminal while it observed the expected Codex composer. The native Codex transcript establishes receipt. The guard covers prompt delivery only. Closing a chat or a pane is a separate operation.