Skip to content

Herdr: Guard Codex prompts at the PTY writer - #312

Merged
Unique-Divine merged 4 commits into
mainfrom
ud/core-doctor-delivery-proof
Dec 2, 2026
Merged

Unique-Divine merged 4 commits into
mainfrom
ud/core-doctor-delivery-proof

Conversation

@Unique-Divine

@Unique-Divine Unique-Divine commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

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 /new in 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

  • Add an opt-in guarded form of 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.
  • Recheck the foreground process, screen and input revisions, rendered thread ID, and empty composer at the PTY writer. Require the dim placeholder so typed text that looks like the placeholder cannot pass the check.
  • Return a distinct result for a refusal before writing. If a write is partial or the acknowledgement is uncertain, check the intended native Codex transcript before treating the message as received or retrying.

1 - Why the Codex Status Line Shows the Thread ID

Codex already supports the thread-id and context-used status 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 /new test 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.

@Unique-Divine
Unique-Divine marked this pull request as ready for review December 2, 2026 20:34
@Unique-Divine
Unique-Divine merged commit 758a097 into main Dec 2, 2026
18 checks passed
@Unique-Divine
Unique-Divine deleted the ud/core-doctor-delivery-proof branch December 2, 2026 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant