#5548, Suge8 (magpie 0.1.3106, Claude Code 2.1.318, macOS, interactive
mode, Pi over OpenAI Chat): a compacted Pi conversation told whole to a
new Claude Code reached it as its four images and the closing notes
only; the history, which had `ls` output naming screenshots (a.jpg, …),
came into the next prompt, out of order.
Cause: send pasted a message's text piece and, without waiting for it
to show, the image after it; only the last text piece was waited for.
Claude Code 2.1.318 tries each pasted line ending in .png, .jpg, .jpeg,
.gif or .webp as an image file before it takes the words in (for a
relative name it asks the clipboard through osascript, about 0.45s),
and keeps one "pasting" mark for every paste. The image's read ended
first and cleared it, so the Enter after the closing notes sent the
prompt without the words.
Fix:
- send waits for every text piece to show before the next piece, not
only the last one.
- shown counts a "[Pasted text #N" only with N past the paste before
it, else the words' own last line: images and pasted text share
Claude Code's numbering, so send keeps one number for both, and the
prompt drawn again shows the earlier "[Pasted text #1". An inline
paste (800 bytes and 2 line breaks at most) takes no number in
2.1.318, so the number stays exact. A paste not shown within
shownWait is still gone past, as before.
- Every paste goes through send, the WSL and queued (busy) messages
too; a message of an image alone has no text to wait for, and one of
text alone was already waited for.
Tests: the fake Claude Code now does what 2.1.318 does here: it draws a
long paste as "[Pasted text #N +B lines]" numbered with the images,
draws the prompt again as a paste starts, takes words naming an image
file in after 1s, and keeps one pasting mark (an Enter while it is set
is lost). TestShimWaitsForWordsNamingImages sends [words naming foo.png,
image, an ls naming bar.png and baz.png, image, closing notes], and the
same naming .txt files. TestShimPastesImages now expects its second
image as #3: the "and" between two images is 4 line breaks, pasted text
as 2.1.318 numbers it.
Run, at this tree on 9e6687e3, and again after a rebase on 30ae0e3f
(go vet and go test ./internal/claudetui/ ok, the new test red on its
old tui.go):
- gofmt -l: clean. go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./..., go build, GOOS=linux go build -tags nogui,
GOOS=windows go build: ok.
- go test ./internal/claudetui/: ok (115s); with -race: ok (118s);
the two image tests -race -count=10: ok.
- go test -tags nogui ./...: claudetui and the gateway's Claude tests
ok. TestAlmaProvidersSeenDecodeOnce (agent), TestMarshalRawIsEncodingJSON,
TestMarshalSizedIsJSONMarshal, FuzzMarshalRaw,
TestServeWSLListensBesideLoopback (gateway) and TestPluginSOCKSProxy
(plugin) fail on this machine (go1.27.3, HTTPS_PROXY set) at 9e6687e3
without this change too; not looked into here.
- Real Claude Code 2.1.318 (claude-haiku-5-5) through a helper built
from this tree, the issue's message driven straight into
claude-tui-helper, in a sandbox CLAUDE_CONFIG_DIR: s-png (a line
"foo.png") 3/3 and s-txt ("foo.txt") 2/2 recorded the whole prompt,
807 chars, the words first and the image as [Image #2]. The old
helper in the same setup, s-png 4/4: the words came after the image
and the closing notes ("[Image #1] (The images…" first,
imagePasteIds [1]); not lost this time, as the clipboard answered
sooner than in the report.
Broken by hand:
- The old tui.go: TestShimWaitsForWordsNamingImages/.png fails, "Claude
Code was sent "echo: [Image #1:red][Image #2:blue]\n\n(The images
above are the tool's results.)\nReply with the codeword."", the
words missing; /.txt passes.
- Each piece waited for, but shown taking any "[Pasted text #": both
cases fail: the second image is missing, and with .png the ls too.
Taken from Suge8's own branch commit 15b05052 (byte-identical tui.go code
to the patch ggbdpq rebased on #5548; this one also carries the
subsystem doc and the fake's 2.1.318 numbering). The patch's
replay_image_test.go and its FAKE_SLOW_PASTE fake mode are left out:
they cover the same case as TestShimWaitsForWordsNamingImages with a
second fake.
Review run at this tree on origin/main 9700dd7cd (wsl-run,
magpie-desktop, Go 1.26.8):
- gofmt -l internal/claudetui, go vet ./internal/claudetui: clean
- go test -count=1 ./internal/claudetui/: ok (119s)
- -race -count=3 TestShimWaitsForWordsNamingImages|TestShimPastesImages: ok
Broken by hand: main's tui.go: TestShimWaitsForWordsNamingImages/.png
red, the words missing ("echo: [Image #1:red][Image #2:blue]...").
Known edge (Suge8's): the words' tail can match early when a piece's
last line equals an earlier piece's; it then goes on as before the fix.
Reported-by: Suge8
Co-authored-by: Suge8 <nnyless@foxmail.com>
Co-authored-by: ggbdpq <ggbdpq@gmail.com>