prompt

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 13 Imported by: 0

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

View Source
const MaxFileBytes = 64 * 1024

MaxFileBytes caps each expanded file to keep prompts bounded.

View Source
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:

  1. caveman rules (per cfg.Caveman level)
  2. agent identity (2 lines)
  3. project context (AGENTS.md/CLAUDE.md walk-up + global)
  4. tool manifest (≤2 lines per tool, respects ToolDescChars budget)
  5. skills manifest (one line per skill, raw input)
  6. knowledge blocks (with staleness note when expired)
  7. behavioral nudge

budget enforcement: if total exceeds SystemPromptBudget, sections are dropped in this priority order — last in, first out:

  1. drop records from the tail (lowest-priority first)
  2. trim the skills manifest
  3. drop context files from the tail (deepest first)
  4. log a warning if still over.

func EstimateTokens

func EstimateTokens(s string) int

EstimateTokens is a rough char/4 heuristic — fine for budget checks.

func ExpandAtPaths

func ExpandAtPaths(text, cwd string) string

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

func FormatContextWarning(inputTokens, contextLimit int) string

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

func ShouldWarn(inputTokens, contextLimit int) bool

ShouldWarn reports whether usage has crossed the threshold. Cheap helper for callers that want to dedupe (warn once per session).

Types

type ContextFile

type ContextFile struct {
	Path string
	Body string
}

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.

Jump to

Keyboard shortcuts

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