Repository navigation
Hashline: fix fs_read header mojibake on Windows (¶ → ¶) - #238
Conversation
The literal '¶' for HL_FILE_PREFIX (and '↑'/'↓' for the payload
markers) lived as a bare character literal in the unit's const
block. Without {\$CODEPAGE UTF8} on the unit, FPC reads the .pas
source under the default codepage -- UTF-8 on Linux (so existing
tests passed) but CP1252 on Windows (so the UTF-8 bytes 0xC2 0xB6
got read as two Latin-1 chars). The bytes flowed through
FormatHashlineHeader into fs_read's tool result tagged as CP1252;
downstream UTF-8 re-encoding then promoted them to "¶..." which
is exactly the mojibake Eli hit.
Naive fix (adding the directive alone) regressed the parser: FPC
under {\$CODEPAGE UTF8} promotes a bare `const X = 'literal'` to a
single-codepoint UnicodeString-flavoured value -- Length() returns
1 codepoint instead of 3 UTF-8 bytes, and the validator's
byte-arithmetic Copy(L, p+1, Length(HL_PAYLOAD_BELOW)) captures
only the first byte and the equality check against the real 3-byte
sequence always fails. The validator stopped flagging
"60:↓bad inline payload" as invalid.
Proper fix has two parts:
1. {\$CODEPAGE UTF8} on the unit so concatenation results
(FormatHashlineHeader's HL_FILE_PREFIX + FilePath + ...)
carry CP_UTF8 instead of defaulting to the system ANSI CP
when reaching the JSON serialiser.
2. The special-char constants spelled as raw byte literals on
the FPC side:
HL_FILE_PREFIX: AnsiString = #\$C2#\$B6;
HL_PAYLOAD_ABOVE: AnsiString = #\$E2#\$86#\$91;
HL_PAYLOAD_BELOW: AnsiString = #\$E2#\$86#\$93;
Bypasses the source-codepage interpretation entirely. Unit
initialization SetCodePages each to CP_UTF8 so they identify
as UTF-8 to downstream code that consults StringCodePage.
3. FormatHashlineHeader's result gets an explicit SetCodePage
to CP_UTF8 because string concatenation across mixed-CP
operands produces CP=0 ("use default") even when the bytes
are valid UTF-8 -- explicitly stamping the tag is the only
way to make the JSON serialiser pass the bytes through
verbatim on Windows.
Delphi build untouched (Delphi reads source as UTF-16 already; the
{\$IFDEF FPC} guards everything).
FPC make smoke + full make test (36 targets) green. Eli's
mojibake should disappear on the next Windows rebuild -- fs_read
output should now show "¶C:\..." instead of "¶C:\...".
https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 239dc0cda7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| that's how `¶` (0xC2 0xB6) flips to `¶` (0xC3 0x82 0xC2 0xB6) | ||
| in fs_read output. Stamp the result as CP_UTF8 so the | ||
| downstream serialiser passes the bytes through verbatim. } | ||
| SetCodePage(RawByteString(Result), CP_UTF8, False); |
There was a problem hiding this comment.
Tag the complete hashline output before JSON serialization
On Windows this only stamps the header returned by FormatHashlineHeader, but the actual fs_read result is built by FormatHashlineRead as FormatHashlineHeader(...) + #10 + FormatNumberedLines(...). Per the same code comment, concatenating a CP_UTF8 string with default-codepage operands can produce a CP=0 result, so the string that reaches TJsonObject.PutStr(...).AsJSON from Tool_FSRead/fs_grep can still be treated as CP1252 and re-encoded as ¶. The final concatenated tool output needs to be tagged (or built entirely as CP_UTF8), otherwise the Windows mojibake this commit targets can persist for normal hashline reads.
Useful? React with 👍 / 👎.
Codex P2, legit. My prior commit only tagged FormatHashlineHeader's result. The real flow is: FormatHashlineRead = FormatHashlineHeader + #10 + FormatNumberedLines and that concatenation across mixed-CP operands resets the result's codepage tag back to 0 ("use DefaultSystemCodepage" -- CP1252 on English Windows), so the bytes that reach PasClaw.JSON.PutStr from Tool_FSRead can still be re-encoded as if they were CP1252 chars. The ¶ -> ¶ mojibake the PR targets would persist for normal fs_read calls. Three additional SetCodePage stamps so the full output reaches the JSON serialiser with the UTF-8 tag: - FormatHashlineRead: the final concat result (the actual string Tool_FSRead returns). - FormatNumberedLines: TStringBuilder.ToString resets the tag regardless of what the appended pieces carried; stamping here covers fs_grep's outer builder which appends section bodies. - PasClaw.Tools.FS Tool_FSGrep: the outer TStringBuilder.ToString that concatenates per-file hashline sections also needs the stamp on its return path. FPC make smoke + full make test (36 targets) green. Probe confirms FormatHashlineRead now returns CP=65001 with bytes 0xC2 0xB6 ... (was CP=0 before this commit; only the header was tagged correctly). https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Both changelog files were stuck at the 2026-06-10 TUI / background- subagent / session_search / tool-RPC entries. ~7 weeks of merged PRs (#214 through #244) had landed without a corresponding entry in either file -- the git log was the only record of features like the knowledgebase, inbound MCP server mode, checkpoints + /undo, heartbeat daemon, shell backends (local | docker), send_message, promptware defense, Windows shell-output encoding fixes, fs_grep ripgrep optimisations, OpenTelemetry traces, and `pasclaw agent --quiet`. Added (newest first): 2026-06-13 #244 agent --quiet log-level clamp 2026-06-12 #243 dcc64 search path + agent --quiet / -q #242 OpenTelemetry traces (OTLP/HTTP+JSON) #241 fs_grep tier 5+6 (byte walker + Boyer-Moore-Horspool) #240 fs_grep tier 1-4 (deferred hash + skip-dirs + binary sniff + size cap) 2026-06-11 #239 Windows shell output: auto-detect UTF-8 vs OEM #238 Hashline fs_read header mojibake fix (¶ vs ¶) #237 Windows shell output: OEM codepage decode 2026-06-10 #233 Shell backends (local | docker via IShellBackend) #232 Heartbeat daemon + reversible condensation (CCR) #230 send_message tool + condenser families + promptware defense + task-aware MEMORY.md slicing 2026-06-09 #223 /goal Ralph loop + judge model + JSON-aware condenser #222 /undo wired into agent + sample dprojs #221 Checkpoints (auto-snapshot + TUI /undo) #220 mcp catalog: lenient hub projector #219 mcp: SSE / Streamable HTTP / stdio hub transports #218 Inbound MCP server mode #217 onboard: offer to index docs into the knowledgebase #214 Knowledgebase (RAG over operator-curated docs) Skipped from this changelog (build-system / Delphi-fix / FPC-fix PRs visible in the git log but not user-facing features): #215, #216, #224, #225, #226, #227, #228, #229, #231, #234, #236. Both files (README.md and docs/changelog.md) updated with the same entries -- intentional mirror so a reader on either surface sees the same history. Same prose in both; same footnote refs at the bottom. Validated: every [#N] reference in both files has a matching [#N]: URL footnote (no broken links).
Fixes the
¶C:\...mojibake Eli hit infs_readoutput on Windows. Three-part fix:Root cause
PasClaw.Hashline.pashadHL_FILE_PREFIX = '¶'(and similar for'↑'/'↓') as bare character literals in the const block. Without{$CODEPAGE UTF8}on the unit:0xC2 0xB6got read as two Latin-1 chars. Even when the byte values were preserved correctly, the resultingAnsiStringcarried no codepage tag — whenFormatHashlineHeader's result hit the JSON serialiser, the bytes got re-encoded as if they were CP1252 characters, producing¶(UTF-80xC3 0x82 0xC2 0xB6).Why the naive fix didn't work
Adding
{$CODEPAGE UTF8}alone broke the parser: FPC under that directive promotes a bareconst X = 'literal'to a single-codepoint UnicodeString-flavoured value.Length()returns 1 codepoint instead of 3 UTF-8 bytes, and the validator's byte-arithmeticCopy(L, p+1, Length(HL_PAYLOAD_BELOW))captures only the first byte. The validator silently stopped flagging60:↓bad inline payloadas invalid.Three-part fix
{$CODEPAGE UTF8}on the unit so concatenation results inFormatHashlineHeadercarry CP_UTF8 instead of defaulting to system ANSI when reaching the JSON serialiser.SetCodePages each to CP_UTF8 so they identify as UTF-8 to downstream code.SetCodePage(RawByteString(Result), CP_UTF8, False)inFormatHashlineHeaderbecause concatenation across mixed-CP operands produces CP=0 ("use default") even when the bytes are valid UTF-8 — explicitly stamping the tag is the only way to make the JSON serialiser pass bytes through verbatim on Windows.Delphi build untouched (Delphi reads source as UTF-16 already; everything's
{$IFDEF FPC}-guarded).Test plan
make smokeclean.make testgreen (36 targets).FormatHashlineHeadernow returns CP=65001 with bytes0xC2 0xB6 ...(was CP=0 before fix).fs_read— header should show¶C:\pathnot¶C:\path.https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code