Documentation
¶
Index ¶
- func CanExecuteTool(turns []llm.Message, toolName string) bool
- func CleanContent(content string) string
- func CountTurnsSinceTaskStart(turns []llm.Message) int
- func ExtractTurnNumber(content string) int
- func GetPendingDiff(turns []llm.Message) *string
- func GetTaskCheckpoint(turns []llm.Message) *string
- func GetTaskDepth(turns []llm.Message) int
- func HasUnfinishedTaskInHistory(turns []llm.Message) bool
- func StripRuntimeNotice(content string) string
- func StripTurnNumber(content string) string
- type InternalMeta
- type Manager
- func (m *Manager) AppendMessage(msg llm.Message) error
- func (m *Manager) AppendMessages(messages []llm.Message) error
- func (m *Manager) CheckpointManager() *checkpoint.Manager
- func (m *Manager) Cleanup() error
- func (m *Manager) CommitTurns(message string) error
- func (m *Manager) CreateBranch() (string, error)
- func (m *Manager) CreateCheckpoint() (string, error)
- func (m *Manager) CurrentBranch() string
- func (m *Manager) Enabled() bool
- func (m *Manager) GetDiffSinceCheckpoint(checkpointID string) (string, error)
- func (m *Manager) GetLastMessage() *llm.Message
- func (m *Manager) GetSystemPrompt() string
- func (m *Manager) GetTurnCount() int
- func (m *Manager) HasUnfinishedTask() bool
- func (m *Manager) Initialize() error
- func (m *Manager) ModifyLastMessage(modifier func(*llm.Message)) error
- func (m *Manager) ParentBranch(branchName string) string
- func (m *Manager) ReadMessagesForLLM() ([]llm.Message, error)
- func (m *Manager) ReadTurnsForLLM() ([]llm.Message, error)
- func (m *Manager) ReplaceLastToolResult(content ToolContent) error
- func (m *Manager) RestoreFileToStart(path string) ([]byte, error)
- func (m *Manager) RestoreFileToTaskStart(path string) ([]byte, error)
- func (m *Manager) RollbackToCheckpoint(checkpointID string) error
- func (m *Manager) SetEnabled(enabled bool)
- func (m *Manager) SetSystemPrompt(prompt string)
- func (m *Manager) SwitchBranch(branchName string) error
- type Middleware
- type RuntimeNoticeConfig
- type ToolContent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanExecuteTool ¶
CanExecuteTool checks if a tool can be executed given current state
func CleanContent ¶
CleanContent removes both turn number and runtime notice from content
func CountTurnsSinceTaskStart ¶
CountTurnsSinceTaskStart counts turns since the last Tasks.Start
func ExtractTurnNumber ¶
ExtractTurnNumber extracts the turn number from a message content Returns 0 if no turn number found
func GetPendingDiff ¶
GetPendingDiff returns the checkpoint ID if there's a pending diff awaiting accept/decline
func GetTaskCheckpoint ¶
GetTaskCheckpoint returns the checkpoint ID for the current task
func GetTaskDepth ¶
GetTaskDepth returns the current task nesting depth
func HasUnfinishedTaskInHistory ¶
HasUnfinishedTaskInHistory checks if the most recent Tasks.Start tool result has "task started" (meaning we're still working on it)
func StripRuntimeNotice ¶
StripRuntimeNotice removes the runtime notice suffix from content
func StripTurnNumber ¶
StripTurnNumber removes the turn number prefix from content
Types ¶
type InternalMeta ¶
type InternalMeta struct {
CheckpointID string `json:"checkpoint_id,omitempty"` // checkpoint at task start (for rollback)
HasChanges bool `json:"has_changes,omitempty"` // true if task made file changes
}
InternalMeta contains metadata for context tool operations
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles context tools git repo for conversation branch tracking
func NewManager ¶
func NewManager(contextDir string, checkpointMgr *checkpoint.Manager) (*Manager, error)
NewManager creates a context tools manager whose git repository lives in contextDir. That directory belongs to the session, so a task started in one turn is still open in the next.
func (*Manager) AppendMessage ¶
AppendMessage appends a single message to turns.jsonl
func (*Manager) AppendMessages ¶
AppendMessages appends multiple messages to turns.jsonl (batch write) Used at the end of a successful iteration to persist the buffer
func (*Manager) CheckpointManager ¶
func (m *Manager) CheckpointManager() *checkpoint.Manager
CheckpointManager returns the associated checkpoint manager
func (*Manager) CommitTurns ¶
CommitTurns commits the current turns.jsonl state
func (*Manager) CreateBranch ¶
CreateBranch creates a new branch and switches to it
func (*Manager) CreateCheckpoint ¶
CreateCheckpoint creates a named checkpoint at the current file state
func (*Manager) CurrentBranch ¶
CurrentBranch returns the current branch name
func (*Manager) GetDiffSinceCheckpoint ¶
GetDiffSinceCheckpoint gets the diff of file changes since a checkpoint
func (*Manager) GetLastMessage ¶
GetLastMessage returns the cached last message (nil if empty)
func (*Manager) GetSystemPrompt ¶
GetSystemPrompt returns the stored system prompt
func (*Manager) GetTurnCount ¶
GetTurnCount returns the number of assistant messages (turns)
func (*Manager) HasUnfinishedTask ¶
HasUnfinishedTask checks if there's an unfinished Tasks.Start in history
func (*Manager) Initialize ¶
Initialize sets up the context tools git repository
func (*Manager) ModifyLastMessage ¶
ModifyLastMessage modifies the last message in turns.jsonl Used for patterns like appending intervention hints to last tool result
func (*Manager) ParentBranch ¶
ParentBranch returns the parent branch of the given branch
func (*Manager) ReadMessagesForLLM ¶
ReadMessagesForLLM reads turns from file and prepends system prompt This is the primary method for getting messages to send to the LLM
func (*Manager) ReadTurnsForLLM ¶
ReadTurnsForLLM reads all messages from current branch's turns.jsonl This is the primary way to get message history for LLM calls
func (*Manager) ReplaceLastToolResult ¶
func (m *Manager) ReplaceLastToolResult(content ToolContent) error
ReplaceLastToolResult replaces the content of the last tool result message
func (*Manager) RestoreFileToStart ¶
RestoreFileToStart restores a file to its state at conversation start
func (*Manager) RestoreFileToTaskStart ¶
RestoreFileToTaskStart restores a file to its state at current task start
func (*Manager) RollbackToCheckpoint ¶
RollbackToCheckpoint rolls back file system to a checkpoint state
func (*Manager) SetEnabled ¶
SetEnabled enables or disables context tools
func (*Manager) SetSystemPrompt ¶
SetSystemPrompt stores the system prompt (kept in RAM, prepended when reading)
func (*Manager) SwitchBranch ¶
SwitchBranch switches to an existing branch
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware processes LLM responses before storage
func NewMiddleware ¶
func NewMiddleware(manager *Manager, config RuntimeNoticeConfig) *Middleware
NewMiddleware creates a new context tools middleware
func (*Middleware) InjectTurnNumber ¶
func (m *Middleware) InjectTurnNumber(content string) string
InjectTurnNumber is a simpler version that only injects turn number Use this when you don't need runtime notices
func (*Middleware) ProcessAssistantMessage ¶
func (m *Middleware) ProcessAssistantMessage(content string) string
ProcessAssistantMessage injects turn number and optional runtime notice into an assistant message before it's stored to history
type RuntimeNoticeConfig ¶
type RuntimeNoticeConfig struct {
TaskWarnTurns int // Warn after N turns in task (default: 5)
TaskCriticalTurns int // Critical warning after N turns (default: 10)
ContextCapacityWarn int // Warn at N% context capacity (default: 80)
MaxNestedDepth int // Max task nesting depth warning (default: 2)
NotifyFileChanges bool // Notify about file changes in task
}
RuntimeNoticeConfig configures when runtime notices are injected
type ToolContent ¶
type ToolContent struct {
Result string `json:"result"`
Diff string `json:"diff,omitempty"` // for completed task
Success *bool `json:"success,omitempty"` // for completed task (nil = true)
Internal *InternalMeta `json:"_internal,omitempty"`
}
ToolContent represents the parsed content of a tool result
func ParseToolContent ¶
func ParseToolContent(msg llm.Message) *ToolContent
ParseToolContent parses the content field of a tool message