Skip to content

Validate ids and token counts, add required items, hygiene for 0.2.0 - #1

Merged
JeremySNR merged 1 commit into
masterfrom
fix/validation-and-hygiene
Sep 2, 2026
Merged

Validate ids and token counts, add required items, hygiene for 0.2.0#1
JeremySNR merged 1 commit into
masterfrom
fix/validation-and-hygiene

Conversation

@JeremySNR

@JeremySNR JeremySNR commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • Validation: duplicate item ids now throw; tokens and tokenizer output must be finite and >= 0 (negative and NaN values previously corrupted tokensUsed).
  • New required?: boolean on Item. A required item or pair group that cannot fit throws with the shortfall instead of silently vanishing.
  • README: documents required and every validation error; corrects the tokenizer section (tiktoken does not count Anthropic tokens).
  • npm run demo now works: examples/demo.ts added and un-ignored.
  • Hygiene: CI workflow, CHANGELOG, package metadata, version 0.2.0.

Test plan

  • npm test: 42 passed (24 before)
  • npm run build
  • npm run demo

Publish this before the three companion packages.

🤖 Generated with Claude Code


Note

Medium Risk
Core fit() behavior changes: new throws for bad inputs and required items that do not fit may break callers that relied on silent exclusion or duplicate ids. Required-item semantics are intentional but callers must set priorities correctly.

Overview
0.2.0 tightens fit() input handling and adds required items, plus release hygiene (CI, changelog, demo).

required?: boolean on Item means a required item or pair group throws with item id, shortfall, budget, and reserve when it cannot be included—instead of being silently excluded. Placement still follows priority; the flag only changes the failure mode. Pair groups must agree on required, like priority.

Validation now rejects duplicate ids and invalid token counts on tokens or tokenizer output (negative, NaN, Infinity, non-number), which previously could corrupt tokensUsed / tokensRemaining.

Docs and tooling: README covers required, validation errors, and corrected Anthropic vs tiktoken guidance; examples/demo.ts and npm run demo (tsx); examples/ un-gitignored; GitHub Actions runs test + build on Node 20; package metadata and version bump to 0.2.0.

Reviewed by Cursor Bugbot for commit 33b2bfe. Bugbot is set up for automated code reviews on this repo. Configure here.

- Reject duplicate item ids
- Reject tokens fields and tokenizer results that are negative, NaN,
  Infinity or not numbers
- Add optional required flag on Item; fit() throws naming the item and
  the token shortfall when a required item or pair group does not fit,
  and pair groups must agree on required
- Add examples/demo.ts (runs with tsx) and stop ignoring examples/
- Correct the README on Anthropic token counting and document the new
  validation errors
- Add CI workflow, CHANGELOG, homepage, bugs, sideEffects and engines
- Bump to 0.2.0

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@JeremySNR JeremySNR left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Reviewed the full diff locally. Duplicate id and token count validation both throw with clear messages (verified with the original failing inputs). The required flag is placed by priority and only changes the failure mode, which is the right semantics, and pair groups are required to agree on it. Demo now runs. 42 tests pass locally. CI green. Merging.

@JeremySNR
JeremySNR merged commit 038c460 into master Sep 2, 2026
3 checks passed
@JeremySNR
JeremySNR deleted the fix/validation-and-hygiene branch September 2, 2026 07:14
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.

1 participant