Documentation
¶
Overview ¶
Package context provides context-building utilities for AI chat workflows. It supports manual file selection, token counting, and structured export of repository files for pasting into AI conversations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountTokens ¶
CountTokens estimates the number of tokens in text using a word-based approximation. The multiplier (1.3) accounts for sub-word tokenisation used by models like GPT-4 (cl100k_base encoding). This is intentionally a simple heuristic — exact counts are not required for context budgeting.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder tracks a set of selected files and provides export functionality for AI chat workflows. All paths are validated against a repository root to prevent directory traversal.
func NewBuilder ¶
NewBuilder creates a Builder anchored at the given repository root. The root is resolved to an absolute path; an error is returned if resolution fails.
func (*Builder) Add ¶
Add reads the file at path and adds it to the context. Relative paths are resolved against the repo root. Paths that escape the root are rejected. Adding a file that is already present is a no-op.
func (*Builder) Export ¶
Export renders the context as structured markdown suitable for pasting into an AI chat window. Each file is preceded by a heading and wrapped in a fenced code block with the appropriate language tag.
func (*Builder) Files ¶
func (b *Builder) Files() []ContextFile
Files returns a copy of the selected files.
func (*Builder) Remove ¶
Remove removes a file from the context by its path. If the file is not present, this is a no-op.
func (*Builder) TotalTokens ¶
TotalTokens returns the sum of token counts across all selected files.
type ContextFile ¶
type ContextFile struct {
Path string // repo-relative path
Content string // raw file content
Tokens int // estimated token count
}
ContextFile describes a single file selected for inclusion in the AI context window.