Files
magpie/docs
yetone d3c544ddf4 claude: a replayed transcript marks no earlier turn as the one to answer
The interactive mode gives a conversation no run has to a new Claude
Code as its own transcript (replaySession): a user line with the
messages before the last reply, the reply as the assistant line, and
the turn after it typed. The user line was rendered with
renderClaudePrompt, which ran historyEnd again on the cut messages, so
for U0 A0 U1 A1 U2 it was history(U0, A0) + <current_turn>U1, "the turn
to answer now", followed by A1, then U2 typed. U1 was answered already;
the reporter saw the model answer an old question again, and say
earlier tool calls had no results (愛睏柴犬阿茶 on Discord #feedback,
with the analysis and the fix suggested).

renderClaudePrompt is now renderClaudePromptAt(req, historyEnd(...));
replaySession calls it with the split at the end, which tells every
message before the reply inside <conversation_history> and closes it
there, with no <current_turn>. Every other render is unchanged.

Siblings: historyEnd has two callers, replaySession (whose own split,
on the whole request, is right: the reply and the turn typed after it)
and renderClaudePrompt. replaySession is the only place that renders a
cut slice of the messages (grep 'Messages = .*Messages\[:').
renderClaudeTurn (the typed turn) has no history marks.

Run (on mote, mote-run):
- go test ./internal/gateway -run TestClaudeTUIReplayMarksNoEarlierTurnCurrent:
  red on the old code (all 5 subtests: two turns, three turns, tool
  results in both turns, tool results only before the reply, the
  client's calls after the reply), green with the fix.
- Broken by hand: put renderClaudePrompt(&before) back in replaySession,
  the new test went red; restored.
- go vet ./internal/gateway, GOOS=linux and GOOS=windows go vet: ok.
- go test ./internal/gateway -run 'Claude|Replay|Prompt|Turn': ok 124.6s.
- go test ./internal/gateway -run 'Loop|Guard|Doc': ok.
- gofmt -l internal/: clean.

Not tried: a real Claude Code resumed on such a transcript with a real
account (the change to what the model sees was checked in the
transcript file only); the full suite runs after the tag.
2026-11-04 14:26:27 +08:00
..