Documentation
¶
Overview ¶
Package prompt assembles the system prompt from composable, layered blocks instead of one monolithic string. Each block renders one concern (identity, repo map, skills, LSP state, memory, pre-flight diagnostics, mode rules) and reports its token cost, so the engine can budget the prefix, disable blocks at runtime (the tuning surface), and keep the per-turn prompt cache-stable.
Layers:
L0 — identity + universal contract (always on, mode rules) L1 — dynamic session state (LSP, plan mode, pre-flight, auto-fixes) L2 — skills catalog (relevance-filtered when it grows past a threshold) L3 — project knowledge (repo map, project context, memory warm start)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assemble ¶
Assemble renders the system prompt from the layered block list and returns the prompt plus a per-block token-cost map (useful for budgeting and tests). The result is deterministic for a given Input, so the engine can cache it once per turn and reuse it across loop iterations (provider prompt caching).
func DefaultTuningPath ¶
func DefaultTuningPath() string
DefaultTuningPath returns ~/.config/brocode/tuning.json (matching BroCode's other global-state files). Returns "" when the home dir is unavailable.
Types ¶
type Block ¶
Block is one composable segment of the system prompt. Render returns "" to skip the block. Always marks blocks that render even when tuning disables the optional ones (identity + mode rules are the irreducible contract).
type Input ¶
type Input struct {
// Mode is the active engine mode: BUILDER, PLANNER, or MINER.
Mode string
// Iteration is the loop iteration (1-based). Blocks that must appear only
// in the first prompt (pre-flight diagnostics, auto-fix results) check it.
Iteration int
// ProjectCtx is the compact structural project overview ("" disables).
ProjectCtx string
// RepoMap is the deterministic project map ("" disables).
RepoMap string
// Stacks are the repo's detected languages ("go", "node", "ts", ...)
// with their evidence files. They render a one-line STACK hint ("STACK:
// go (go.mod, main.go)") and bias the skill-catalog ranking so
// stack-specific skills follow the repo instead of the model's guess.
Stacks []Stack
// Skills is the full installed skill catalog (empty disables the block).
Skills []SkillEntry
// UserPrompt is the current turn's query, used to relevance-filter the
// skills catalog when it exceeds the tuning threshold.
UserPrompt string
// ScopeHint is the smart-scope markdown (relevance-ranked files extracted
// from the user prompt) shown only on iteration 1 so the model focuses
// exploration. Empty disables.
ScopeHint string
// MemoryWarm is the BM25-selected cross-session memory excerpt ("" skips).
MemoryWarm string
// KnowledgeHints is the Smart Context Graph summary — a compact list of
// previously analyzed files related to the current prompt, with their
// content hashes so the model can skip stale re-reads. "" when knowledge
// store is disabled or no match.
KnowledgeHints string
// NotesHints is the distilled self-aware context — facts/decisions/gotchas/
// hot files recalled from past sessions (from the notes store). Shown only
// when relevant so the model starts with verified prior knowledge.
NotesHints string
// LSPAvailable is the number of reachable language servers (0 = none).
LSPAvailable int
// Preflight holds engine-gathered diagnostics + code windows, shown only
// on iteration 1 so the cached prefix stays stable afterwards.
Preflight string
// PreflightAuto reports fixes the engine already applied pre-turn; the
// model must not redo them. Shown only on iteration 1.
PreflightAuto string
// PlanMode renders the read-only PLAN-pass directive when set.
PlanMode bool
// ActivePlan carries the active task plan from .brocode/current_plan.md.
ActivePlan string
// AgentPrompt carries custom instructions from an active user-defined CustomAgent.
AgentPrompt string
// Tuning carries the runtime surface (block toggles, rule toggles, skill
// catalog budgets). Nil falls back to DefaultTuning.
Tuning *Tuning
}
Input is everything Assemble needs to render one turn's system prompt.
type Rule ¶
Rule is one numbered engine-mode rule. Rules live as data (not a hardcoded string) so the tuning surface can disable individual rules by ID without a recompile, and the prompt builder can account for each rule's token cost. The Text carries its own leading number to keep the default rendered output byte-identical to the pre-refactor prompt; disabling a rule leaves a number gap, which is intentional (the rule is off, not silently renumbered).
type SkillEntry ¶
SkillEntry is the minimal catalog metadata the prompt needs to advertise a skill. The model loads the full SKILL.md itself via read_file (progressive disclosure level 2), so only name+description ever enter the prompt.
type Tuning ¶
type Tuning struct {
// BlockEnabled toggles named blocks off (nil/absent = all enabled).
// The identity + mode blocks are Always and cannot be disabled.
BlockEnabled map[string]bool `json:"blocks,omitempty"`
// RulesOff lists rule IDs to disable, keyed by mode ("BUILDER", "PLANNER",
// "MINER"). Rule IDs are the stable identifiers in rules.go (b1, b2, ...).
RulesOff map[string][]string `json:"rules_off,omitempty"`
// SkillCatalogThreshold: above this many installed skills, the catalog is
// relevance-filtered instead of listed in full.
SkillCatalogThreshold int `json:"skill_catalog_threshold"`
// SkillCatalogCap is the max skills listed when filtering is active.
SkillCatalogCap int `json:"skill_catalog_cap"`
// SkillCatalogMin keeps at least this many skills even with a weak prompt.
SkillCatalogMin int `json:"skill_catalog_min"`
}
Tuning is the runtime tuning surface for the system prompt. It lets users disable blocks, disable individual mode rules, and set the skill-catalog budgets without recompiling — the "tuning instruction" layer of the prompt architecture. Persisted as JSON at DefaultTuningPath; a missing or corrupt file falls back to DefaultTuning (never blocks a run).
func DefaultTuning ¶
func DefaultTuning() *Tuning
DefaultTuning returns the shipping defaults: every block on, every rule on, and a relevance-filtered catalog once more than 15 skills are installed.
func LoadTuning ¶
LoadTuning reads the tuning file, merging only the fields present over the defaults so a partial file cannot accidentally disable everything. A missing or corrupt file yields DefaultTuning — tuning must never break a run.