Uh oh!
There was an error while loading. Please reload this page.
feat(runtime): rework FormatJson as file-in-place JSON validator - #658
Merged
Merged
Conversation
luojiyin1987force-pushed
the
feat/formatjson-file-tool
branch
from
July 9, 2026 09:34
cdfdeb6 to
de70385CompareUh oh!
There was an error while loading. Please reload this page.
5 tasks
Astro-Han added a commit
that referenced
this pull request
Jul 11, 2026
#658 added the FormatJson builtin but omitted activityKind and didn't update the builtin-tools semantic-category test expectation, so the 'declares stable semantic categories independently of tool names' test saw FormatJson: undefined and test:dist went red on main. FormatJson reads a file and rewrites it in place (writeFile), same shape as Write/Edit, so 'edit' is the correct category. Sets activityKind: 'edit' on the tool and adds FormatJson: 'edit' to the test expectation.
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 freeto 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
Reworked per the review on #603 (comment on the closed PR). The previous
FormatJson({ content })string→string form was rejected on first-principles grounds: it round-trips the entire JSON payload through the prompt (~2× tokens) for a capability the model already has directly, and burns a standing slot in every session's tool list.This version follows the shape the maintainer said would carry its weight —
FormatJson({ path, sort_keys })that validates/normalizes a JSON file in place and returns only a diagnostic, no content round-trip.Closes#602. Supersedes #603.
Behavior
Both success and failure return a single diagnostic object (matching "valid/error + byte delta"):
{ ok: true, valid: true, path, bytesBefore, bytesAfter, byteDelta, changed }{ ok: false, valid: false, error, byteDelta: 0, changed: false }, leaving the file untouchedChanges
packages/runtime/src/builtin-tools.tsFormatJsontool: readspath, parses (returns{ ok: false, valid: false, error, byteDelta: 0, changed: false }on invalid JSON, leaving the file untouched — no throw), optionally sorts object keys, rewrites with canonical 2-space indentation.permissionRequired: true(in-place file mutation, same asEdit); uses the existing per-path write lock + path resolution.{ ok, path, valid, bytesBefore, bytesAfter, byteDelta, changed }.sortKeysDeep, which preserves__proto__as an own data property (no prototype-pollution).packages/runtime/src/__tests__/builtin-tools.test.tssort_keysordering (incl.__proto__+ nested recursion), invalid JSON returns the structured error diagnostic (no write,byteDelta: 0), already-canonical content reportschanged: false/ zerobyteDelta, unicode handling, diagnostic fields.Verification
npm run -w @maka/runtime typecheck— cleannpm run -w @maka/runtime test— all pass (FormatJson block green)Notes
Strictly
path+sort_keysonly (noindentparam) per the agreed scope. Useful for config hygiene after aWrite.