Skip to content

The CLI cannot use a real tokenizer, only the built-in estimate #6

Description

@royalpinto007

analyzePayload and compact both accept a counter option, and the README is honest that the default is an estimate within roughly 10-15% of real BPE counts. But bin/tokencut.mjs never passes one, so the CLI, which is how most people will use this, can only ever give the estimate.

That matters most in the place the number is load-bearing: --max trims real messages out of a payload based on it. Being 15% out means either dropping messages that did not need to go, or leaving a payload that still overflows.

Proposal

A --tokenizer <module> flag that dynamically imports a module exporting count(text) -> number and passes it as counter. Ship nothing extra by default, so the zero-dependency promise holds, and document using gpt-tokenizer or @anthropic-ai/tokenizer as an example.

Acceptance

  • --tokenizer ./my-counter.mjs is used for both analyze and compact
  • A module that does not export count fails with a clear message rather than a stack trace
  • Still zero runtime dependencies
  • README shows one worked example

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions