bootstrap

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package bootstrap renders persisted memories into the SessionStart payload that an agent receives at the very beginning of a session.

The output is a single Markdown document that combines:

  • a fixed system directive block (telling the agent how to use mememory),
  • the loaded memories grouped by type,
  • a stats block reporting how much of the bootstrap budget is consumed.

The bootstrap budget is denominated in tokens and bounded by MaxBootstrapTokens — a deliberately conservative ceiling so that bootstrap never dominates the agent's context window. Token counts are estimated from byte length using BytesPerToken; the estimate is intentionally simple (no per-tokenizer accuracy) because the goal is to give the user a sense of scale, not millimeter precision.

Index

Constants

View Source
const BytesPerToken = 3.5

BytesPerToken is the average bytes-per-token ratio used to estimate token counts from raw payload size. The value is tuned for mixed Cyrillic prose and source code; per-tokenizer accuracy is explicitly out of scope. The estimate is reported alongside the raw byte count so the user can apply their own correction if they care.

View Source
const MaxBootstrapTokens = 30_000

MaxBootstrapTokens is the soft ceiling on how many tokens the bootstrap payload should occupy. It is independent of the model and the context window — bootstrap is meant to stay small enough that it never crowds out the actual conversation regardless of which agent loads it.

30_000 tokens corresponds to roughly 15% of a 200K-token context window, which we consider the upper bound of "comfortable bootstrap weight" for the smallest mainstream context. On larger windows the absolute share is lower and there is no need to inflate the budget.

Variables

This section is empty.

Functions

func CheckBudget added in v0.4.0

func CheckBudget(memories []t.Memory) string

CheckBudget returns a non-empty warning string if the given memory set would render into a bootstrap payload exceeding MaxBootstrapTokens. Used by the remember tool to flag the user when a newly stored bootstrap memory pushes the total over the budget — they can keep the memory but should know they are now in overflow territory.

Returns an empty string when the budget is fine. The check renders the body without the stats block (the stats describe the body, not themselves) so the warning reflects the actual cost.

func EstimateTokens added in v0.4.0

func EstimateTokens(bytes int) int

EstimateTokens converts a byte count into an approximate token count using BytesPerToken. The estimate is rounded to the nearest integer.

func Format

func Format(ctx Context) string

Format renders a Context into the Markdown payload that the SessionStart hook prints to stdout. Returns an empty string if no memories were loaded at all (caller should suppress the hook output entirely in that case).

Types

type Context added in v0.4.0

type Context struct {
	Project     ProjectInfo
	GlobalMems  []t.Memory
	ProjectMems []t.Memory
}

Context bundles everything Format needs to render bootstrap output. It is constructed by the CLI after resolving the project and fetching memories from the admin API.

type ProjectInfo added in v0.4.0

type ProjectInfo struct {
	Name   string
	Source string
}

ProjectInfo describes the resolved project name and the source it came from. The source is reported in the stats block so the user can see at a glance which detection rule was applied (--project flag, .mememory file, git, or cwd fallback).

Jump to

Keyboard shortcuts

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