Documentation
¶
Overview ¶
Package context provides functionality for loading and managing .context/ files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EstimateTokens ¶
EstimateTokens provides a rough token count estimate for content.
Uses a simple heuristic of ~4 characters per token for English text. This is a conservative estimate for Claude/GPT-style tokenizers that tends to slightly overestimate, which is safer for budgeting.
Parameters:
- content: Byte slice to estimate tokens for
Returns:
- int: Estimated token count (0 for empty content)
func EstimateTokensString ¶
EstimateTokensString estimates tokens for a string.
Convenience wrapper around EstimateTokens for string input.
Parameters:
- s: String to estimate tokens for
Returns:
- int: Estimated token count
Types ¶
type Context ¶
Context represents the loaded context from a .context/ directory.
Fields:
- Dir: Path to the context directory
- Files: All loaded context files with their metadata
- TotalTokens: Sum of estimated tokens across all files
- TotalSize: Sum of file sizes in bytes
func Load ¶
Load reads all context files from the specified directory.
If dir is empty, it uses the configured context directory from .contextrc, CTX_DIR environment variable, or the default ".context".
Parameters:
- dir: Directory path to load from, or empty string for default
Returns:
- *Context: Loaded context with files, token counts, and metadata
- error: NotFoundError if directory doesn't exist, or other IO errors
type FileInfo ¶
type FileInfo struct {
Name string
Path string
Size int64
ModTime time.Time
Content []byte
IsEmpty bool
Tokens int
Summary string
}
FileInfo represents metadata about a context file.
Fields:
- Name: Filename (e.g., "TASKS.md")
- Path: Full path to the file
- Size: File size in bytes
- ModTime: Last modification time
- Content: Raw file content
- IsEmpty: True if the file has no meaningful content (only headers/whitespace)
- Tokens: Estimated token count for the content
- Summary: Brief description generated from the content
type NotFoundError ¶
type NotFoundError struct {
Dir string
}
NotFoundError is returned when the context directory doesn't exist.
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
Error implements the error interface for NotFoundError.
Returns:
- string: Error message including the missing directory path