Documentation
¶
Overview ¶
Package budget assembles token-budgeted context packets from loaded context files, fitting entries by score within the configured limit.
Index ¶
- func AssemblePacket(ctx *entity.Context, budget int) *assembledPacket
- func EstimateSliceTokens(items []string) int
- func ExtractAllConventions(ctx *entity.Context) []string
- func FillSection(entries []score.Entry, budget int) ([]string, []string)
- func FitItems(items []string, budget int) []string
- func OutputAgentJSON(cmd *cobra.Command, ctx *entity.Context, budget int) error
- func OutputAgentMarkdown(cmd *cobra.Command, ctx *entity.Context, budget int) error
- func ParseEntryBlocks(ctx *entity.Context, fileName string) []index.EntryBlock
- func RenderMarkdownPacket(pkt *assembledPacket) string
- func Split(total int, a, b []score.Entry) (int, int)
- func TotalEntryTokens(entries []score.Entry) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssemblePacket ¶
AssemblePacket builds a context packet respecting the token budget.
Allocation tiers:
- Tier 1 (always): constitution, read order, instruction
- Tier 2 (40%): active tasks
- Tier 3 (20%): conventions
- Tier 4+5 (remaining): decisions and learnings, scored by relevance
Parameters:
- ctx: Loaded context containing the files
- budget: Token budget to respect
Returns:
- *AssembledPacket: Assembled packet within budget
func EstimateSliceTokens ¶
EstimateSliceTokens sums token estimates for a string slice.
Parameters:
- items: Strings to estimate
Returns:
- int: Total estimated tokens
func ExtractAllConventions ¶
ExtractAllConventions extracts all bullet items from CONVENTIONS.md (not limited to 5 like the old implementation).
Parameters:
- ctx: Loaded context containing the files
Returns:
- []string: All convention bullet items; nil if the file is not found
func FillSection ¶
FillSection selects scored entries to fill a budget, with graceful degradation.
Includes full entries by score order until ~80% of the budget is consumed. Remaining entries get title-only summaries.
Parameters:
- entries: Scored entries sorted by score descending
- budget: Token budget for this section
Returns:
- []string: Full entry bodies that fit in the budget
- []string: Title-only summaries for entries that didn't fit
func FitItems ¶
FitItems returns items that fit within a token budget.
Items are included in order until the budget would be exceeded.
Parameters:
- items: String items to include
- budget: Maximum token budget
Returns:
- []string: Items that fit within the budget
func OutputAgentJSON ¶
OutputAgentJSON writes the context packet as pretty-printed JSON.
Uses budget-aware assembly to score entries and respect the token budget.
Parameters:
- cmd: Cobra command for output stream
- ctx: Loaded context containing the files
- budget: Token budget for content selection
Returns:
- error: Non-nil if JSON encoding fails
func OutputAgentMarkdown ¶
OutputAgentMarkdown writes the context packet as formatted Markdown.
Uses budget-aware assembly to score entries and respect the token budget. Output includes sections for constitution, tasks, conventions, decisions (full body), learnings (full body), and title-only summaries.
Parameters:
- cmd: Cobra command for output stream
- ctx: Loaded context containing the files
- budget: Token budget for content selection
Returns:
- error: Always nil (included for interface consistency)
func ParseEntryBlocks ¶
func ParseEntryBlocks(ctx *entity.Context, fileName string) []index.EntryBlock
ParseEntryBlocks parses a context file into entry blocks.
Parameters:
- ctx: Loaded context
- fileName: Name of the file to parse (e.g., config.Decision)
Returns:
- []index.EntryBlock: Parsed entry blocks; nil if the file is not found
func RenderMarkdownPacket ¶
func RenderMarkdownPacket(pkt *assembledPacket) string
RenderMarkdownPacket renders an assembled packet as Markdown.
Parameters:
- pkt: Assembled packet to render
Returns:
- string: Formatted Markdown output
func Split ¶
Split divides a token budget between two scored sections.
Each section gets at least 30% of the budget (if content exists). The remaining 40% is allocated proportionally to content size.
Parameters:
- total: Total tokens to split
- a: First section's scored entries
- b: Second section's scored entries
Returns:
- int: Budget for section a
- int: Budget for section b
func TotalEntryTokens ¶
TotalEntryTokens sums pre-computed token counts for scored entries.
Parameters:
- entries: Scored entries with token estimates
Returns:
- int: Total tokens
Types ¶
This section is empty.