Documentation
¶
Index ¶
- Constants
- func BuildSystemPrompt(opts SystemPromptOptions) string
- func LoadAgentsMD(cwd, agentHome string) (string, error)
- type Changed
- type Sources
- func (s *Sources) Built() string
- func (s *Sources) Freeze() (pc session.PromptContext, ok bool)
- func (s *Sources) OwnerBook() string
- func (s *Sources) OwnerRole() string
- func (s *Sources) Pinned() (time.Time, string)
- func (s *Sources) RecordBuilt(system string)
- func (s *Sources) Regenerate() (changed []Changed, revert func())
- func (s *Sources) Reload() (changed []Changed, revert func())
- func (s *Sources) Restore(pc session.PromptContext)
- func (s *Sources) Snapshot() (agentsMD, skillsIndex, memoryIndex string)
- func (s *Sources) WithClock(clock func() time.Time) *Sources
- func (s *Sources) WithOwnerBook(load func() string) *Sources
- func (s *Sources) WithOwnerRole(load func() string) *Sources
- type SystemPromptOptions
Constants ¶
const ( LabelDate = "Date" LabelGit = "Last commit" )
Labels of the Changed entries Regenerate adds to Reload's.
Variables ¶
This section is empty.
Functions ¶
func BuildSystemPrompt ¶
func BuildSystemPrompt(opts SystemPromptOptions) string
BuildSystemPrompt constructs the system prompt from components.
func LoadAgentsMD ¶
LoadAgentsMD discovers and concatenates AGENTS.md files in priority order.
Priority (lowest first, content concatenated):
- <agentHome>/AGENTS.md (global)
- Walk: root → ... → cwd/.. (ancestor directories, root first, deepest last)
- cwd/AGENTS.md (project-local, highest priority)
agentHome defaults to $MOA_CONFIG_DIR, then ~/.config/moa. Duplicate paths are deduplicated.
Types ¶
type Changed ¶ added in v0.35.0
Changed names one input whose content on disk differs from what the session holds, along with the fresh content.
type Sources ¶ added in v0.35.0
type Sources struct {
// contains filtered or unexported fields
}
Sources holds the prompt inputs that live on disk, so they can be re-read while a session is open.
These were captured by value when a session was built, which made a session the only place they existed: editing AGENTS.md or adding a memory had no effect until a restart. Keeping them behind one guarded holder lets a reload update every consumer — the base prompt builder, new subagents — from a single place, instead of each one owning a copy that drifts.
func NewSources ¶ added in v0.35.0
func NewSources(cwd string, memStore *memory.Store, agentsMD, skillsIndex, memoryIndex string) *Sources
NewSources captures what a session was built with. cwd and memStore are kept so Reload can re-read the same places the build read.
func (*Sources) Built ¶ added in v0.49.0
Built returns the base prompt last recorded with RecordBuilt.
func (*Sources) Freeze ¶ added in v0.49.0
func (s *Sources) Freeze() (pc session.PromptContext, ok bool)
Freeze returns the values and the prompt as one consistent set, for the session to persist. ok is false until a prompt was recorded.
func (*Sources) OwnerBook ¶ added in v0.41.0
OwnerBook returns the current project-book section ("" when there is none).
func (*Sources) OwnerRole ¶ added in v0.41.0
OwnerRole returns the current owner role section ("" when there is none).
func (*Sources) Pinned ¶ added in v0.49.0
Pinned returns the date and the git section the prompt is built with.
func (*Sources) RecordBuilt ¶ added in v0.49.0
RecordBuilt records the base prompt just built from these values, as the one the session runs with.
func (*Sources) Regenerate ¶ added in v0.49.0
Regenerate is Reload plus a new date and git section: what a compaction or Start fresh does, since the session's cached prefix is lost anyway. The prompt renders only the day, so a new time on the same day changes nothing the model sees. revert undoes all of it.
func (*Sources) Reload ¶ added in v0.35.0
Reload re-reads the three inputs and returns the ones that differ, having stored the fresh values.
Nothing changed is the common case — a reload run "just in case" — and it must stay free: callers use an empty result to leave the conversation, and its cached prompt prefix, completely untouched.
The returned revert function restores the previous values. A caller that records the new state and then fails to apply it would report success while leaving the session on the old prompt, and the next reload would see no difference and do nothing — the change lost for good.
func (*Sources) Restore ¶ added in v0.49.0
func (s *Sources) Restore(pc session.PromptContext)
Restore replaces the values with a frozen set, so the session goes on with the context it had rather than what is on disk now. The loaders stay: a regeneration still reads the disk.
func (*Sources) Snapshot ¶ added in v0.35.0
Snapshot returns the current values as one consistent set.
func (*Sources) WithClock ¶ added in v0.49.0
WithClock pins the date and the git section the prompt is built with, reading them now; clock is also what a regeneration reads. Nil means time.Now.
func (*Sources) WithOwnerBook ¶ added in v0.41.0
WithOwnerBook attaches the project-book loader and reads it once. A nil loader leaves the session without a book section, which is the state of every codebase that has no owner.
func (*Sources) WithOwnerRole ¶ added in v0.41.0
WithOwnerRole attaches the owner role loader and reads it once. Only an owner's own conversation has one.
type SystemPromptOptions ¶
type SystemPromptOptions struct {
AgentsMD string // AGENTS.md content (concatenated from all levels)
Tools []core.ToolSpec // registered tools
CWD string // working directory shown to the agent
HasVerify bool // .moa/verify.json was loaded
MemoryIndex string // pre-formatted memory index (one line per fact)
SkillsIndex string // pre-formatted skills index
// OwnerRole is the project owner's own role prompt, set only for an owner's
// conversation. OwnerBook is the owner's book index, injected into every
// session of a codebase that has one.
OwnerRole string
OwnerBook string
// AsyncQuestions marks a session whose ask_user does not wait for the
// answer: the prompt then carries the rule for what to do while one is
// open. Set only on a session's own prompt, never inherited by subagents,
// which have no ask_user.
AsyncQuestions bool
// Now, if non-zero, is the clock used for the date line. Zero means time.Now.
// Callers that rebuild the prompt (MCP tool-set changes) should pin this so
// a later rebuild does not restamp the date and miss the GPT-5.6 cache.
Now time.Time
// Git, if non-nil, is the git section as-is (empty means omit it). Nil
// means look up git.Context(CWD) live.
Git *string
}
SystemPromptOptions configures system prompt generation.