prompts

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

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

func ContentHash(content string) string

ContentHash returns the first 16 hex characters of the SHA-256 digest of content.

func FormatReminders

func FormatReminders(msgs []string) string

FormatReminders formats collected reminder strings into a single system message block, or returns empty string if none.

func GetPlanSystemPrompt

func GetPlanSystemPrompt(platform, pwd, envLabel string, envInfo *utils.EnvInfo) string

GetPlanSystemPrompt returns the system prompt for Plan mode (read-only exploration).

func GetSystemPrompt

func GetSystemPrompt(platform, pwd, envLabel string, envInfo *utils.EnvInfo, skillDescriptions string) string

func HasAgentsMd

func HasAgentsMd(pwd string) string

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

func (a *AsyncEnvLoader) Load(ctx context.Context, pwd string) *utils.EnvInfo

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.

func (*AsyncEnvLoader) LoadAsync

func (a *AsyncEnvLoader) LoadAsync(ctx context.Context, pwd string) func() *utils.EnvInfo

LoadAsync starts environment info collection in the background and returns a function that blocks until the result is ready. This enables the caller to kick off env loading and memory loading in parallel.

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

type MemoryConfig struct {
	MaxTotalChars int
	MaxIncDepth   int
}

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:

  1. ~/.jcode/AGENTS.md (global)
  2. {pwd}/AGENTS.md (project-level)
  3. {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.

Jump to

Keyboard shortcuts

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