Documentation
¶
Index ¶
- func CollectReminders(rc *ReminderContext) []string
- func ContentHash(content string) string
- func FormatReminders(msgs []string) string
- func GetPlanSystemPrompt(platform, pwd, envLabel string, envInfo *utils.EnvInfo) string
- func GetSystemPrompt(platform, pwd, envLabel string, envInfo *utils.EnvInfo, ...) string
- func HasAgentsMd(pwd string) string
- type AsyncEnvLoader
- type BuilderConfig
- type CompactConfig
- type CompactResult
- type ContextCompactor
- type MemoryConfig
- type MemoryLoader
- type PromptBlock
- type PromptBlockCache
- type PromptBuilder
- type PromptResult
- type ReminderContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectReminders ¶
func CollectReminders(rc *ReminderContext) []string
CollectReminders evaluates all built-in reminders and returns the messages for those whose condition is met. Returns nil if no reminders fire.
func ContentHash ¶
ContentHash returns the first 16 hex characters of the SHA-256 digest of content.
func FormatReminders ¶
FormatReminders formats collected reminder strings into a single system message block, or returns empty string if none.
func GetPlanSystemPrompt ¶
GetPlanSystemPrompt returns the system prompt for Plan mode (read-only exploration).
func GetSystemPrompt ¶
func HasAgentsMd ¶
HasAgentsMd returns the path to agents.md (case-insensitive) in pwd, or "".
Types ¶
type AsyncEnvLoader ¶
type AsyncEnvLoader struct {
// contains filtered or unexported fields
}
AsyncEnvLoader loads environment info with a timeout. It wraps the synchronous CollectEnvInfo in a goroutine so callers can proceed with other work (e.g. memory loading) concurrently.
func NewAsyncEnvLoader ¶
func NewAsyncEnvLoader(timeout time.Duration) *AsyncEnvLoader
NewAsyncEnvLoader creates a loader with the given timeout.
func (*AsyncEnvLoader) Load ¶
Load collects environment information with a timeout guard. CollectEnvInfo already runs each git sub-command with its own 2s timeout; this wrapper provides an overall deadline so the prompt builder never blocks for longer than the configured duration.
type BuilderConfig ¶
type BuilderConfig struct {
Platform string
Pwd string
EnvLabel string
SkillDescriptions string
PlanMode bool
CacheEnabled bool
}
BuilderConfig is the input for prompt construction.
type CompactConfig ¶
type CompactConfig struct {
Threshold float64 // fraction of context limit that triggers compaction (0-1)
MaxRetries int // max consecutive failures before disabling
BufferTokens int // token headroom to reserve
}
CompactConfig controls context compaction behavior.
type CompactResult ¶
type CompactResult struct {
Summary string
OriginalTokens int64
CompactedTokens int64
PreservedMsgCount int
}
CompactResult describes the outcome of a compaction.
type ContextCompactor ¶
type ContextCompactor struct {
// contains filtered or unexported fields
}
ContextCompactor manages automatic context window compression.
func NewContextCompactor ¶
func NewContextCompactor(cfg CompactConfig) *ContextCompactor
NewContextCompactor creates a compactor with the given config.
func (*ContextCompactor) Compact ¶
func (c *ContextCompactor) Compact( ctx context.Context, messages []*schema.Message, model einomodel.ToolCallingChatModel, contextLimit int, ) ([]*schema.Message, *CompactResult, error)
Compact compresses the message history using the provided model. It keeps the system message and the most recent messages, summarising the rest.
func (*ContextCompactor) IsTripped ¶
func (c *ContextCompactor) IsTripped() bool
IsTripped returns true if compaction has been disabled due to repeated failures.
func (*ContextCompactor) Reset ¶
func (c *ContextCompactor) Reset()
Reset clears the failure counter and re-enables compaction.
func (*ContextCompactor) ShouldCompact ¶
func (c *ContextCompactor) ShouldCompact(tokensUsed int64, contextLimit int) bool
ShouldCompact returns true when token usage exceeds the configured threshold.
type MemoryConfig ¶
MemoryConfig controls how AGENTS.md files are loaded and merged.
type MemoryLoader ¶
type MemoryLoader struct {
// contains filtered or unexported fields
}
MemoryLoader loads and merges multi-level AGENTS.md files with @include support.
func NewMemoryLoader ¶
func NewMemoryLoader(cfg MemoryConfig) *MemoryLoader
NewMemoryLoader creates a MemoryLoader with the given config.
func (*MemoryLoader) Load ¶
func (m *MemoryLoader) Load(pwd string) (string, error)
Load loads and merges multi-level AGENTS.md files:
- ~/.jcode/AGENTS.md (global)
- {pwd}/AGENTS.md (project-level)
- {pwd}/AGENTS.local.md (local, expected gitignored)
Each file's @include directives are resolved recursively. The merged result is truncated to MaxTotalChars.
type PromptBlock ¶
type PromptBlock struct {
Content string
CacheScope string // "global", "session", or "" (no cache)
}
PromptBlock represents a segment of the system prompt.
type PromptBlockCache ¶
type PromptBlockCache struct {
// contains filtered or unexported fields
}
PromptBlockCache caches static prompt blocks to avoid redundant recomputation.
func NewPromptBlockCache ¶
func NewPromptBlockCache() *PromptBlockCache
NewPromptBlockCache returns a new empty cache.
func (*PromptBlockCache) GetOrBuild ¶
func (c *PromptBlockCache) GetOrBuild(contentHash string, buildFn func() *PromptBlock) *PromptBlock
GetOrBuild returns a cached block if the content hash matches, otherwise calls buildFn to create a new block and caches it.
func (*PromptBlockCache) Invalidate ¶
func (c *PromptBlockCache) Invalidate()
Invalidate clears the cached block.
type PromptBuilder ¶
type PromptBuilder struct {
// contains filtered or unexported fields
}
PromptBuilder constructs system prompts with parallel loading and caching.
func NewPromptBuilder ¶
func NewPromptBuilder(cfg BuilderConfig) *PromptBuilder
NewPromptBuilder creates a PromptBuilder with the given config. It reads prompt-related settings from the user's config file.
func (*PromptBuilder) Build ¶
func (b *PromptBuilder) Build(ctx context.Context) (*PromptResult, error)
Build constructs the system prompt. It loads env info and AGENTS.md in parallel, renders the template, and optionally caches static blocks.
type PromptResult ¶
type PromptResult struct {
Blocks []PromptBlock
Full string // concatenated for backward compatibility
}
PromptResult is the output of a prompt build.
type ReminderContext ¶
type ReminderContext struct {
Iteration int
TokensUsed int64
ContextLimit int
HasIncompleteTodo bool
IncompleteTodoN int
ConsecutiveErrors int
EnvLabel string
IsRemote bool
PlanContent string // non-empty when executing an approved plan
}
ReminderContext carries the runtime state needed to evaluate reminder conditions.