context-pack-planner v1.0.0

Crystal CLI and library: packs documents into a token budget you set, highest priority first, and shows what was skipped and why.

context-pack-planner

Crystal command line tool and library. Give it a CSV of documents with your own token estimates and a priority, plus a token budget, and it shows which documents fit into the context you are assembling and which were left out. The rule is greedy packing: sort by priority (highest first), then tokens (smallest first), then doc_id; add each document that still fits, skip the ones that do not fit and keep going. Greedy packing is a rule of thumb, not an optimal selection: a different mix of documents could use the budget better, and the tool does not look for it. The token counts and the budget (--budget, required, above 0) are set by you; the tool counts no tokens itself and assumes no model. Output: the included documents in the order added with a running total, the skipped documents with the reason ("does not fit: needs N, N left"), and the totals: budget, tokens used, tokens left, share of budget used (1 decimal), documents included and skipped, and the highest priority skipped.

Part of the OneGTMLab free GTM tools. Background on the idea: context engineering.

Install

shards build   # then ./bin/context-pack-planner

Use

Input: CSV with the columns doc_id, tokens (a whole number above 0) and priority (a whole number, higher is more important, negative allowed), any order, header case does not matter. A cell may be double quoted. Option: --budget N or --budget=N. A missing --budget, a bad number (the message names the row, the header counts as row 1), a duplicate doc_id, a missing column, an empty file or a missing file stops the run with a message and exit 1. In the example, doc-d and doc-e are skipped because only 50 tokens are left when their turn comes, while the smaller, lower priority doc-f still fits afterwards.

$ bin/context-pack-planner sample.csv --budget 1000
included (in the order added)
doc_id  priority  tokens  running total
doc-a   5         300     300
doc-c   4         200     500
doc-b   4         450     950
doc-f   1         40      990

skipped
doc_id  priority  tokens  reason
doc-d   3         400     does not fit: needs 400, 50 left
doc-e   2         150     does not fit: needs 150, 50 left

budget: 1000 tokens
tokens used: 990
tokens left: 10
share of budget used: 99.0%
documents included: 4
documents skipped: 2
highest priority skipped: doc-d (priority 3)

Test

crystal spec

Offline, no network calls, no dependencies beyond the language runtime. MIT licensed.

Repository

context-pack-planner

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 0
  • about 1 hour ago
  • November 29, 2026
License

MIT License

Links
Synced at

Sun, 29 Nov 2026 03:44:35 GMT

Languages