Skip to content

fix: drop toLocaleString() thousands separators from LLM-facing tool output - #773

Merged
will-lamerton merged 2 commits into
Nano-Collective:mainfrom
MsfPablo:fix/tolocalestring-llm-payload
Aug 5, 2026
Merged

will-lamerton merged 2 commits into
Nano-Collective:mainfrom
MsfPablo:fix/tolocalestring-llm-payload

Conversation

@MsfPablo

@MsfPablo MsfPablo commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #768. toLocaleString() was leaking comma thousands-separators into strings returned to the model as tool results, not just into the terminal display. Comma separators cost extra tokens and carry no meaning for the model — this was flagged as good-first-issue material by the maintainer.

Fixed the LLM-facing (execute/validator) paths:

  • source/tools/read-file.tsx — metadata output (size, lines, tokens), large-file metadata output, and the minified/binary-content validator error message
  • source/tools/list-directory.tsx — per-entry byte size in the directory listing
  • source/utils/file-content-loader.ts — binary-file and large-file metadata shown when a file is loaded via @file mention (this content is inlined into the chat message sent to the model)

Left toLocaleString() in place everywhere it's actually display-only, per the issue's own guidance (Formatter components vs execute functions):

  • The Ink <Text> formatter components in read-file.tsx, list-directory.tsx, search-file-contents.tsx, find-files.tsx — these render to the terminal, never to the model
  • compact-handler.ts, context-max-handler.ts, auto-compact.ts — checked these too since they also format token counts, but their formatted strings only go to onAddToChatQueue (local terminal display); the actual conversation array passed to the model (setMessages(...)) doesn't include them, so they're out of scope

Test plan

  • pnpm run test:format, test:lint, test:types — all clean
  • pnpm run test:ava on the three affected spec files — 84 tests pass
  • One existing test (read-file.spec.tsx, minified-content validator) asserted the old comma-formatted output (/15,000 characters/); updated it to match the fixed output (/15000 characters/) since that was testing the exact behavior this issue asks to remove

…output

toLocaleString() was used on numbers in strings returned to the model
(read_file's metadata/output paths, its minified-content validator
error, list_directory's per-entry size, and file-content-loader's
@file-mention metadata), not just in display components. Comma
separators cost extra tokens and carry no meaning for the model.

Left toLocaleString() untouched everywhere it belongs: the Ink
`<Text>` formatter components (read-file.tsx, list-directory.tsx,
search-file-contents.tsx, find-files.tsx) and the chat-queue-only
compaction/context messages (compact-handler.ts,
context-max-handler.ts, auto-compact.ts), which never reach the model.

Updated the one existing test that asserted the old comma-formatted
output (read-file.spec.tsx's minified-content validator test).

Fixes Nano-Collective#768

@akramcodez akramcodez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM another great PR @MsfPablo

@will-lamerton

Copy link
Copy Markdown
Member

@will-lamerton
will-lamerton merged commit 7bee4db into Nano-Collective:main Aug 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

toLocaleString() thousands separators leak into LLM-facing tool results

3 participants