fix(agent): decode \uXXXX (+surrogate pairs) in CDP string results#132
Open
vmemjp wants to merge 1 commit intojustrach:mainfrom
Open
fix(agent): decode \uXXXX (+surrogate pairs) in CDP string results#132vmemjp wants to merge 1 commit intojustrach:mainfrom
vmemjp wants to merge 1 commit intojustrach:mainfrom
Conversation
Owner
|
Can you update this PR to build and test against Zig |
`unescapeJson` in `src/agent_main.zig` passed `\uXXXX` through as literal escape sequences, so `kuri-agent eval` / `text` / `autoSnap` emitted `コン...` instead of `コンテンツ` on any non-ASCII page. Moved the helper into `src/util/json.zig` as `jsonUnescape`, added `\b \f \r \uXXXX` + UTF-16 surrogate pair handling (permissive on malformed input, matching `jsonEscape`'s style), and migrated the five call sites in `agent_main.zig` (`autoSnap`, `cmdEval`, `cmdText`, `cmdHeaders`, `cmdAudit`). 11 new inline tests; `zig build` succeeds and `src/util/json.zig` tests pass on Zig 0.16.0. Measured on ja.wikipedia.org/wiki/Zig_(プログラミング言語) with `-Doptimize=ReleaseFast`: `kuri-agent eval document.body.innerText` went from 15,753 → 9,814 bytes (1.60× fewer bytes, 2.68× fewer chars), wall time 47 → 46 ms (median of 3). Rebased onto upstream/main (e1cc5c4) which migrated to Zig 0.16. Merged against the new `compat.writeToStdout` stdout helper. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
88c7ffe to
0134fd0
Compare
Author
|
Rebased onto upstream/main (e1cc5c4) — the Zig 0.16 migration from #134 and Scope noteGrew from 3 → 5 call sites. The upstream merges added two new sites Verified on Zig 0.16.0
Ready for review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
unescapeJsoninsrc/agent_main.zigpassed\uXXXXsequences through asliterals, so
kuri-agent eval/text/autoSnapemitted\u30b3\u30f3...instead ofコンテンツon any non-ASCII page.Fix
Moved the helper into
src/util/json.zigasjsonUnescape:\uXXXX→ UTF-8 viastd.unicode.utf8Encode\b\f\r(matchingjsonEscapein the same file)jsonEscape's style)Three call sites in
agent_main.zig(autoSnap,cmdEval,cmdText)migrate to the shared helper.
Tests
11 inline tests in
src/util/json.zigcovering basic escapes, BMP\uXXXX, surrogate pairs, and five malformed shapes.zig build testpasses.
Measured impact
kuri-agent eval document.body.innerTexton the Japanese Wikipediaarticle for Zig (
ja.wikipedia.org/wiki/Zig_(プログラミング言語)),built with
-Doptimize=ReleaseFast:mainScope
Only the
kuri-agentoutput path.src/crawler/fetcher.zighas a parallelunescapeJsonwith the same gap — happy to migrate it in a follow-up.Validated with Zig 0.15.2 (
build.zig.zondeclares 0.15.0 minimum).