Documentation
¶
Overview ¶
Package prompt builds the system prompt for a bee turn.
Layered assembly: caveman rules + agent identity + tool manifest + skills + selected memories + behavioral nudge. Honors the active profile's SystemPromptBudget by truncating low-priority sections.
Inline @path file expansion for user prompts.
Tokens like `@cmd/bee/main.go` in a user message get replaced with the file contents wrapped in a fenced block. Caveats: paths must exist relative to cwd, binaries are skipped, files larger than MaxFileBytes truncate.
Recursive @path import expansion for AGENTS.md / CLAUDE.md context files.
`@./notes.md` or `@~/global.md` inside a context file gets replaced with the imported file's body inline. Depth-capped, cycle-guarded, with fzf-style fuzzy fallback when the exact path misses (so `@plan.md` resolves to `PLAN.md`).
Index ¶
- Constants
- func Assemble(cfg config.Config, regToolSpecs []llm.ToolSpec, skillManifest string, ...) string
- func EstimateTokens(s string) int
- func ExpandAtPaths(text, cwd string) string
- func FormatContextWarning(inputTokens, contextLimit int) string
- func ShouldWarn(inputTokens, contextLimit int) bool
- type ContextFile
Constants ¶
const MaxFileBytes = 64 * 1024
MaxFileBytes caps each expanded file to keep prompts bounded.
const WarningThreshold = 0.70
WarningThreshold is the usage fraction (0..1) at which a warning is emitted.
Variables ¶
This section is empty.
Functions ¶
func Assemble ¶
func Assemble( cfg config.Config, regToolSpecs []llm.ToolSpec, skillManifest string, selectedRecords []knowledge.Record, ctxFiles []ContextFile, ) string
Assemble builds the full system prompt.
section order:
- caveman rules (per cfg.Caveman level)
- agent identity (2 lines)
- project context (AGENTS.md/CLAUDE.md walk-up + global)
- tool manifest (≤2 lines per tool, respects ToolDescChars budget)
- skills manifest (one line per skill, raw input)
- knowledge blocks (with staleness note when expired)
- behavioral nudge
budget enforcement: if total exceeds SystemPromptBudget, sections are dropped in this priority order — last in, first out:
- drop records from the tail (lowest-priority first)
- trim the skills manifest
- drop context files from the tail (deepest first)
- log a warning if still over.
func EstimateTokens ¶
EstimateTokens is a rough char/4 heuristic — fine for budget checks.
func ExpandAtPaths ¶
ExpandAtPaths replaces every `@<rel-path>` token in text with a fenced block containing the file's contents. Failed lookups, binaries, and missing files are left as-is — the model still sees the literal `@path` and can react. Returns the rewritten text.
func FormatContextWarning ¶
FormatContextWarning returns the inline notice to prepend to a tool result. Returns "" when ratio < WarningThreshold or limit <= 0. The ratio is clamped to [0, 1] before formatting — prevents prompt-injection via inflated numbers (a safety-tuned model could otherwise refuse a "200%" claim).
func ShouldWarn ¶
ShouldWarn reports whether usage has crossed the threshold. Cheap helper for callers that want to dedupe (warn once per session).
Types ¶
type ContextFile ¶
ContextFile is one loaded AGENTS.md/CLAUDE.md.
func LoadContextFiles ¶
func LoadContextFiles(cwd, beeHome string) []ContextFile
LoadContextFiles walks from cwd up to filesystem root, collecting any AGENTS.md or CLAUDE.md found. Returns shallowest first (root) to deepest last (cwd). If beeHome is non-empty, it is checked for a global AGENTS.md and prepended.