Skip to content

fix(chat): build Claude's question and plan cards from the transcript's pending tool call - #254

Closed
devswha wants to merge 6 commits into
mainfrom
fix/claude-cards-from-transcript
Closed

devswha wants to merge 6 commits into
mainfrom
fix/claude-cards-from-transcript

Conversation

@devswha

@devswha devswha commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Closes #211

Read this first: what real Claude Code 2.1.286 does

The issue asked to verify when Claude writes the tool_use to its transcript. On 2.1.286 it writes an AskUserQuestion call only once it is answered: in three real dialogs (a session's first question, and a turn's second question twice) the file did not change while the dialog was up. So on this version the pending call is never in the file while the card is needed, the screen is still what gets read, and a real cut-off dialog still gets only the last-resort card. This PR is correct and safe for a Claude that does write the call while it waits, and changes nothing harmful for one that does not, but it does not fix #140 on 2.1.286. A source that has the call while it is pending (Claude's PreToolUse hook gets the tool input) would be the next step; that is not in this PR.

What changes

Claude Code's AskUserQuestion, its answer review and the plan approval are tool calls, so their text is in the session transcript. The card's questions, options, descriptions and plan now come from the pending tool_use there, and the screen only says where the dialog stands (which question, which row has the cursor, which boxes are checked, whether it is still the last thing on screen). This follows the shape of the omo cards from #237.

When a card is offered

All of these must hold:

  • herdr names the pane's agent claude. A shell, Codex or gjc pane showing the same text gets nothing.
  • The transcript (found through herdr's session id and claude-store.ts) has an AskUserQuestion or ExitPlanMode call in the current turn with no tool_result.
  • The screen shows that call live: the rows above the hint match the call's option labels by number, the tabs (when whole) are the call's headers, the question over the rows is the call's, exactly one row has the cursor, and the dialog's hint is the last thing on screen.

The transcript has three answers, and each is handled differently:

transcript says result
pending call card from the call, only if the screen matches it
newest call of the turn already has its result no card while the screen still shows that same call; any other dialog on screen is a new call not written yet and is read from the screen
no such call in the turn, or no transcript found the screen alone is read, exactly as before

The last two rows exist because of the finding above: a transcript without the call cannot mean "no dialog". The first version of this branch treated an answered call as "no card", and the real run then showed a turn's second question losing its card to the last-resort one; that is fixed and tested.

Prompt ids are still content hashes, a stale answer still gets 409 prompt_changed, and answers are still send_keys navigation from the cursor on screen. Tool approvals and the unnumbered menus are untouched.

Cost on the 2 s poll: the transcript is looked at only while the screen shows one of the three dialogs; that costs one agent.get and one stat. The file's last 1 MiB is read again only when its size or mtime changed.

Before / after

The same tests on main's server/prompt.ts and on this branch (HERDR_TEST_MODE=unit bun test ./server/prompt.test.ts -t "Claude's dialogs on a prompt poll"):

test before after
a dialog cut off by a short pane gets its card whole fail (no card) pass
a description that starts like a row does not hide the card fail (no card) pass
the whole dialog reads its text from the call; an answer for another card is 409 fail (description cut at the wrap) pass
no card for the dialog's text in a shell or another agent's pane pass pass
no card once the transcript shows the call answered fail (card offered) pass
no card from a transcript whose pending call is not the dialog on screen fail (card offered) pass
no card once the screen moved on, though the call is pending pass pass
without a transcript the screen alone is read pass pass

Before: 3 pass, 5 fail. After: 8 pass.

Real Claude Code 2.1.286, isolated test pane

One session, two AskUserQuestion calls in one turn, driven only through /api/pane/prompt and /api/pane/prompt/answer: the folder-trust card answered 200; "Color" got its card and the answer 200; "Storage" got its question card (not the last-resort one), a wrong prompt id got 409, the answer 200; the transcript's tool results then read "Pick a color"="Green" and …="In-memory cache", and no card was left. Both question cards were read from the screen (descriptions cut at the wrap), because the calls were not in the file.

Contract test against real herdr (server/prompt.contract.test.ts): a pane shows only rows 3 to 6 of a question. Before it got the last-resort card (fallback: true); after it gets the question's own card with all four options, and answering the first one (above the screen's top) lands on that row.

Commands

bun run typecheck
bun run generate:types --check
bun run test:unit                                   # 699 pass, 0 fail
bun test ./server/prompt.contract.test.ts ./server/omo-prompt.contract.test.ts   # 5 pass, 0 fail

Limits

  • Not seen on real Claude Code: a card built from the transcript. Every transcript-built card in this PR comes from fixtures and a stand-in program.
  • The plan approval and the answer review were not run on real Claude Code in this work.
  • The cut-off and wrapped screens in the tests are built from a live 120-column capture of Claude Code 2.1.286 by dropping its top lines; Claude was not run in a short pane.
  • The same question asked twice in one turn: while the second one is not written, the answered first one matches the screen and it gets the last-resort card.
  • A multiple choice cut off above its first option gets no card: which boxes are checked is on rows out of view.
  • ExitPlanMode's "Exit plan mode?" variant (no plan text) is still read by the screen readers only.
  • Permission prompts do not take their body from the pending tool call; the issue lists that, the brief did not, so it is left for a follow-up.

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

…screen

Seen live on Claude Code 2.1.286: a turn's second AskUserQuestion was not in the transcript while its dialog was up, so the answered first call took its card away. An answered call now only rules out its own dialog still on screen.
@devswha

devswha commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Closing without merging. On Claude Code 2.1.286 the pending question is not in the session file until it is answered, so this path does not fire, and it adds about 220 lines to code that sends keys. The finding is recorded on #211. The branch stays in case a later Claude writes the call while it waits.

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.

Build Claude's question and plan cards from the transcript's tool call, not the screen A dialog the prompt parser can't read leaves only the key bar

1 participant