budget

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package budget assembles token-budgeted context packets from loaded context files, fitting entries by score within the configured limit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssemblePacket

func AssemblePacket(ctx *entity.Context, budget int) *assembledPacket

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

func EstimateSliceTokens(items []string) int

EstimateSliceTokens sums token estimates for a string slice.

Parameters:

  • items: Strings to estimate

Returns:

  • int: Total estimated tokens

func ExtractAllConventions

func ExtractAllConventions(ctx *entity.Context) []string

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

func FillSection(entries []score.Entry, budget int) ([]string, []string)

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

func FitItems(items []string, budget int) []string

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

func OutputAgentJSON(
	cmd *cobra.Command, ctx *entity.Context, budget int,
) error

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

func OutputAgentMarkdown(
	cmd *cobra.Command, ctx *entity.Context, budget int,
) error

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

func Split(total int, a, b []score.Entry) (int, int)

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

func TotalEntryTokens(entries []score.Entry) int

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL