module ContextPackPlanner

Overview

Pack documents into a token budget, highest priority first. Greedy packing is a rule of thumb: it is deterministic and easy to read, but it is not an optimal selection. Token counts are your own estimates.

Defined in:

context_pack_planner.cr

Constant Summary

REQUIRED = ["doc_id", "tokens", "priority"] of ::String
USAGE = "usage: context-pack-planner docs.csv --budget 1000\nCSV columns: doc_id, tokens, priority. The budget is set by you and the token counts are your own estimates; greedy packing is a rule of thumb, not an optimal selection. More: https://www.onegtmlab.dev/glossary/context-engineering"
VERSION = "1.0.0"

Class Method Summary

Class Method Detail

def self.cli(args : Array(String), stdout : IO, stderr : IO) : Int32 #

Command line entry. Returns the exit code: 0 ok, 1 bad input or file, 2 usage.


[View source]
def self.parse_csv(text : String) : Array(Array(String)) #

Small CSV reader: comma separated, double quoted fields may hold commas, line breaks and "" for a quote mark. Returns rows of raw cell strings.


[View source]
def self.plan(docs : Array(Doc), budget : Int64) : Plan #

Sort by priority (high first), then tokens (small first), then doc_id. Add each document that still fits; skip the rest and keep going.


[View source]
def self.read_docs(text : String) : Array(Doc) #

[View source]
def self.render(plan : Plan) : String #

[View source]
def self.table(rows : Array(Array(String))) : String #

[View source]