Documentation
¶
Index ¶
- Constants
- func BuildSSHAuthMethods() []ssh.AuthMethod
- func NewAskUserTool(deps *AskUserDeps) tool.InvokableTool
- func NewEnhancedTodoReadTool(store *EnhancedTodoStore) tool.InvokableTool
- func NewEnhancedTodoWriteTool(store *EnhancedTodoStore) tool.InvokableTool
- func NewTaskGetTool(mgr *SubagentTaskManager) tool.InvokableTool
- func NewTaskListTool(mgr *SubagentTaskManager) tool.InvokableTool
- func NewTaskStopTool(mgr *SubagentTaskManager) tool.InvokableTool
- func NewTeamCreateTool(manager *team.Manager) tool.InvokableTool
- func NewTeamDeleteTool(manager *team.Manager) tool.InvokableTool
- func NewTeamListTool(manager *team.Manager) tool.InvokableTool
- func NewTeamSendMessageTool(manager *team.Manager) tool.InvokableTool
- func NewTeamSpawnTool(manager *team.Manager) tool.InvokableTool
- func ShellQuote(s string) string
- type AskUserAnswer
- type AskUserBatchResponse
- type AskUserDeps
- type AskUserInput
- type AskUserOption
- type AskUserQuestion
- type AskUserResponse
- type BackgroundManager
- func (bm *BackgroundManager) DrainNotifications() []BgNotification
- func (bm *BackgroundManager) GetTask(id string) *BgTask
- func (bm *BackgroundManager) ListTasks() []*BgTask
- func (bm *BackgroundManager) Run(ctx context.Context, command string) string
- func (bm *BackgroundManager) RunningCount() int
- func (bm *BackgroundManager) SetNotifier(n BgNotifier)
- func (bm *BackgroundManager) SetStorage(s *StorageManager)
- type BgNotification
- type BgNotifier
- type BgTask
- type BgTaskStatus
- type CommandCategory
- type ConflictResult
- type ConflictStatus
- type EditInput
- type EditOp
- type EnhancedTodoInput
- type EnhancedTodoItem
- type EnhancedTodoStore
- func (s *EnhancedTodoStore) Add(items []EnhancedTodoItem) error
- func (s *EnhancedTodoStore) HasIncomplete() bool
- func (s *EnhancedTodoStore) HasItems() bool
- func (s *EnhancedTodoStore) IncompleteSummary() string
- func (s *EnhancedTodoStore) Items() []TodoItem
- func (s *EnhancedTodoStore) Load() error
- func (s *EnhancedTodoStore) Modify(id, status, title string) error
- func (s *EnhancedTodoStore) Remove(id string) error
- func (s *EnhancedTodoStore) SaveSync() error
- func (s *EnhancedTodoStore) SetOnChange(fn func([]EnhancedTodoItem))
- func (s *EnhancedTodoStore) Snapshot() []EnhancedTodoItem
- func (s *EnhancedTodoStore) Summary() string
- func (s *EnhancedTodoStore) Update(items []EnhancedTodoItem) error
- type Env
- func (e *Env) CanNest() bool
- func (e *Env) CloneForSubagent() *Env
- func (e *Env) IsRemote() bool
- func (e *Env) NewCheckBackgroundTool(bm *BackgroundManager) tool.InvokableTool
- func (e *Env) NewEditTool() tool.InvokableTool
- func (e *Env) NewExecuteTool(bm *BackgroundManager) tool.InvokableTool
- func (e *Env) NewGlobTool() tool.InvokableTool
- func (e *Env) NewGrepTool() tool.InvokableTool
- func (e *Env) NewReadTool() tool.InvokableTool
- func (e *Env) NewSubagentTool(deps *SubagentDeps) tool.InvokableTool
- func (e *Env) NewSwitchEnvTool() tool.InvokableTool
- func (e *Env) NewTodoReadTool() tool.InvokableTool
- func (e *Env) NewTodoWriteTool() tool.InvokableTool
- func (e *Env) NewWriteTool() tool.InvokableTool
- func (e *Env) Pwd() string
- func (e *Env) ResetToLocal(pwd, platform string)
- func (e *Env) ResolvePath(path string) string
- func (e *Env) SetSSH(executor *SSHExecutor, remotePwd string)
- type ExecuteInput
- type Executor
- type FileInfo
- type FileState
- type FileTracker
- func (ft *FileTracker) CheckConflict(path string) (ConflictResult, error)
- func (ft *FileTracker) CreateBackup(path string, content []byte) (string, error)
- func (ft *FileTracker) TrackRead(path string, content []byte, modTime time.Time)
- func (ft *FileTracker) UpdateAfterWrite(path string, content []byte, modTime time.Time)
- type GlobInput
- type GrepInput
- type LocalExecutor
- func (l *LocalExecutor) Exec(ctx context.Context, command, workDir string, timeout time.Duration) (string, string, error)
- func (l *LocalExecutor) Label() string
- func (l *LocalExecutor) MkdirAll(_ context.Context, path string, perm os.FileMode) error
- func (l *LocalExecutor) Platform() string
- func (l *LocalExecutor) ReadFile(_ context.Context, path string) ([]byte, error)
- func (l *LocalExecutor) Stat(_ context.Context, path string) (*FileInfo, error)
- func (l *LocalExecutor) WriteFile(_ context.Context, path string, data []byte, perm os.FileMode) error
- type MCPCapabilities
- type MCPConnection
- type MCPManager
- func (m *MCPManager) AddServer(ctx context.Context, name string, cfg *config.MCPServer) error
- func (m *MCPManager) Close() error
- func (m *MCPManager) Connect(ctx context.Context, name string, cfg *config.MCPServer) error
- func (m *MCPManager) Disconnect(name string) error
- func (m *MCPManager) GetAllTools() []MCPToolInfo
- func (m *MCPManager) GetServerStatus() []MCPServerStatus
- func (m *MCPManager) InvokeMCPTool(ctx context.Context, serverName, toolName string, args json.RawMessage) (string, error)
- func (m *MCPManager) ListResources(ctx context.Context, serverName string) ([]MCPResource, error)
- func (m *MCPManager) ReadResource(ctx context.Context, serverName, uri string) (string, error)
- func (m *MCPManager) RemoveServer(name string) error
- type MCPResource
- type MCPServerState
- type MCPServerStatus
- type MCPStatus
- type MCPToolInfo
- type OAuthToken
- type PersistedResult
- type PlanStatus
- type PlanStore
- func (s *PlanStore) Approve()
- func (s *PlanStore) Clear()
- func (s *PlanStore) Content() string
- func (s *PlanStore) Feedback() string
- func (s *PlanStore) HasApprovedPlan() bool
- func (s *PlanStore) Reject(feedback string)
- func (s *PlanStore) SetDraft(title, content string)
- func (s *PlanStore) Status() PlanStatus
- func (s *PlanStore) Submit(title, content string)
- func (s *PlanStore) Title() string
- type ReadInput
- type ReconnectPolicy
- type SSHExecutor
- func (s *SSHExecutor) Close() error
- func (s *SSHExecutor) Exec(ctx context.Context, command, workDir string, timeout time.Duration) (string, string, error)
- func (s *SSHExecutor) Label() string
- func (s *SSHExecutor) MkdirAll(ctx context.Context, path string, _ os.FileMode) error
- func (s *SSHExecutor) Platform() string
- func (s *SSHExecutor) ReadFile(ctx context.Context, path string) ([]byte, error)
- func (s *SSHExecutor) Stat(ctx context.Context, path string) (*FileInfo, error)
- func (s *SSHExecutor) WriteFile(ctx context.Context, path string, data []byte, perm os.FileMode) error
- type StorageManager
- func (sm *StorageManager) AppendAsync(path string, data []byte, mode os.FileMode)
- func (sm *StorageManager) Cleanup() error
- func (sm *StorageManager) Close() error
- func (sm *StorageManager) FileHistoryDir() string
- func (sm *StorageManager) OAuthDir() string
- func (sm *StorageManager) PlansDir() string
- func (sm *StorageManager) TasksDir() string
- func (sm *StorageManager) TodosDir() string
- func (sm *StorageManager) ToolResultsDir() string
- func (sm *StorageManager) Write(path string, data []byte, mode os.FileMode) error
- func (sm *StorageManager) WriteAsync(path string, data []byte, mode os.FileMode)
- type StreamChunk
- type SubagentDeps
- type SubagentNotification
- type SubagentNotifier
- type SubagentProgressFn
- type SubagentTask
- type SubagentTaskManager
- func (m *SubagentTaskManager) DrainNotifications() []SubagentNotification
- func (m *SubagentTaskManager) Get(taskID string) (*SubagentTask, error)
- func (m *SubagentTaskManager) List(statusFilter SubagentTaskStatus) []*SubagentTask
- func (m *SubagentTaskManager) RunningCount() int
- func (m *SubagentTaskManager) Stop(taskID string) error
- func (m *SubagentTaskManager) Submit(ctx context.Context, task *SubagentTask, ...) (taskID, result string, err error)
- type SubagentTaskStatus
- type SubagentTokenFn
- type SwitchEnvInput
- type TaskLog
- type TodoAction
- type TodoFileFormat
- type TodoItem
- type TodoStatus
- type TodoStore
- type TokenStore
- type ToolProgressMsg
- type ToolResultStore
- type WriteEntry
- type WriteInput
- type WriteQueue
Constants ¶
const ( AgentTypeExplore = "explore" AgentTypeGeneral = "general" AgentTypeCoordinator = "coordinator" )
const ( StatusNotStarted = "not_started" StatusInProgress = "in_progress" StatusCompleted = "completed" StatusSkipped = "skipped" )
const MaxEditFileSize = 10 * 1024 * 1024 // 10MB
const MaxReadFileSize = 10 * 1024 * 1024 // 10MB
const MaxSubagentDepth = 3
MaxSubagentDepth is the maximum allowed nesting depth for subagents.
const MaxWriteFileSize = 10 * 1024 * 1024 // 10MB
Variables ¶
This section is empty.
Functions ¶
func BuildSSHAuthMethods ¶
func BuildSSHAuthMethods() []ssh.AuthMethod
BuildSSHAuthMethods builds a list of SSH auth methods by checking the SSH agent socket and common private key files in ~/.ssh/.
func NewAskUserTool ¶
func NewAskUserTool(deps *AskUserDeps) tool.InvokableTool
NewAskUserTool creates the ask_user tool that allows the agent to ask the user a question during execution, optionally with selectable choices.
func NewEnhancedTodoReadTool ¶
func NewEnhancedTodoReadTool(store *EnhancedTodoStore) tool.InvokableTool
NewEnhancedTodoReadTool creates the todoread tool backed by an EnhancedTodoStore.
func NewEnhancedTodoWriteTool ¶
func NewEnhancedTodoWriteTool(store *EnhancedTodoStore) tool.InvokableTool
NewEnhancedTodoWriteTool creates the todowrite tool backed by an EnhancedTodoStore.
func NewTaskGetTool ¶
func NewTaskGetTool(mgr *SubagentTaskManager) tool.InvokableTool
NewTaskGetTool creates the task_get tool.
func NewTaskListTool ¶
func NewTaskListTool(mgr *SubagentTaskManager) tool.InvokableTool
NewTaskListTool creates the task_list tool.
func NewTaskStopTool ¶
func NewTaskStopTool(mgr *SubagentTaskManager) tool.InvokableTool
NewTaskStopTool creates the task_stop tool.
func NewTeamCreateTool ¶
func NewTeamCreateTool(manager *team.Manager) tool.InvokableTool
func NewTeamDeleteTool ¶
func NewTeamDeleteTool(manager *team.Manager) tool.InvokableTool
func NewTeamListTool ¶
func NewTeamListTool(manager *team.Manager) tool.InvokableTool
func NewTeamSendMessageTool ¶
func NewTeamSendMessageTool(manager *team.Manager) tool.InvokableTool
func NewTeamSpawnTool ¶
func NewTeamSpawnTool(manager *team.Manager) tool.InvokableTool
func ShellQuote ¶
Types ¶
type AskUserAnswer ¶
type AskUserAnswer struct {
QuestionHeader string `json:"question_header"`
Answer string `json:"answer"`
Selected []string `json:"selected,omitempty"`
}
AskUserAnswer is a single answer in a batch response.
type AskUserBatchResponse ¶
type AskUserBatchResponse struct {
Answers []AskUserAnswer `json:"answers"`
}
AskUserBatchResponse is the structured response for batch questions.
type AskUserDeps ¶
type AskUserDeps struct {
NotifyFn func(question string, options []string) // sends question to TUI
ResponseCh <-chan AskUserResponse // receives user answer
BatchNotifyFn func(questions []AskUserQuestion) // sends batch questions to TUI
BatchResponseCh <-chan AskUserBatchResponse // receives batch answers
}
AskUserDeps holds the dependencies for the ask_user tool.
type AskUserInput ¶
type AskUserInput struct {
Questions []AskUserQuestion `json:"questions,omitempty"`
Question string `json:"question,omitempty"`
Options []askUserOption `json:"options,omitempty"`
}
AskUserInput supports both batch and legacy input formats.
type AskUserOption ¶
type AskUserOption struct {
Label string `json:"label"`
Description string `json:"description,omitempty"`
}
AskUserOption is an enhanced option with a label and optional description.
type AskUserQuestion ¶
type AskUserQuestion struct {
Question string `json:"question"`
Header string `json:"header,omitempty"`
Options []AskUserOption `json:"options,omitempty"`
MultiSelect bool `json:"multi_select,omitempty"`
}
AskUserQuestion is a single question in a batch request.
type AskUserResponse ¶
type AskUserResponse struct {
Answer string
}
AskUserResponse is the user's answer to an ask_user question.
type BackgroundManager ¶
type BackgroundManager struct {
// contains filtered or unexported fields
}
BackgroundManager manages background task execution and notifications.
func NewBackgroundManager ¶
func NewBackgroundManager(env *Env) *BackgroundManager
NewBackgroundManager creates a new background task manager.
func (*BackgroundManager) DrainNotifications ¶
func (bm *BackgroundManager) DrainNotifications() []BgNotification
DrainNotifications returns and clears all pending completion notifications.
func (*BackgroundManager) GetTask ¶
func (bm *BackgroundManager) GetTask(id string) *BgTask
GetTask returns a snapshot of the task's current state.
func (*BackgroundManager) ListTasks ¶
func (bm *BackgroundManager) ListTasks() []*BgTask
ListTasks returns snapshots of all tasks.
func (*BackgroundManager) Run ¶
func (bm *BackgroundManager) Run(ctx context.Context, command string) string
Run starts a command in the background and returns immediately.
func (*BackgroundManager) RunningCount ¶
func (bm *BackgroundManager) RunningCount() int
RunningCount returns the number of currently running tasks.
func (*BackgroundManager) SetNotifier ¶
func (bm *BackgroundManager) SetNotifier(n BgNotifier)
SetNotifier sets the callback for TUI notifications.
func (*BackgroundManager) SetStorage ¶
func (bm *BackgroundManager) SetStorage(s *StorageManager)
SetStorage sets the optional StorageManager for TaskLog integration.
type BgNotification ¶
type BgNotification struct {
TaskID string
Command string
Status BgTaskStatus
Output string
}
BgNotification is a completion notification queued for injection.
type BgNotifier ¶
type BgNotifier func(taskID, command, status string)
BgNotifier is called on background task lifecycle events.
type BgTask ¶
type BgTask struct {
ID string
Command string
Description string
Status BgTaskStatus
Output string
Started time.Time
Ended time.Time
Timeout time.Duration // 0 means use default (5 minutes)
}
BgTask is a single background task.
type BgTaskStatus ¶
type BgTaskStatus string
BgTaskStatus represents the state of a background task.
const ( BgStatusRunning BgTaskStatus = "running" BgStatusDone BgTaskStatus = "done" BgStatusFailed BgTaskStatus = "failed" BgStatusTimeout BgTaskStatus = "timeout" )
type CommandCategory ¶
type CommandCategory string
CommandCategory classifies a shell command for UI and policy decisions.
const ( CmdSearch CommandCategory = "search" CmdRead CommandCategory = "read" CmdList CommandCategory = "list" CmdSafe CommandCategory = "safe" CmdGit CommandCategory = "git" CmdMutating CommandCategory = "mutating" )
func (CommandCategory) IsCollapsible ¶
func (c CommandCategory) IsCollapsible() bool
IsCollapsible returns true for categories whose output is read-only and can be collapsed in the TUI to save space.
type ConflictResult ¶
type ConflictResult struct {
Status ConflictStatus
OldHash string
NewHash string
OldModTime time.Time
NewModTime time.Time
}
ConflictResult holds the details of a conflict check.
type ConflictStatus ¶
type ConflictStatus int
ConflictStatus describes the result of a conflict check.
const ( ConflictNone ConflictStatus = iota ConflictModified ConflictFileGone )
type EditInput ¶
type EditInput struct {
FilePath string `json:"file_path"`
OldString string `json:"old_string"`
NewString string `json:"new_string"`
ReplaceAll bool `json:"replace_all,omitempty"`
StartLine int `json:"start_line,omitempty"`
EndLine int `json:"end_line,omitempty"`
Edits []EditOp `json:"edits,omitempty"`
}
type EnhancedTodoInput ¶
type EnhancedTodoInput struct {
Action TodoAction `json:"action,omitempty"`
Items []EnhancedTodoItem `json:"items,omitempty"`
ID string `json:"id,omitempty"`
Status string `json:"status,omitempty"`
Title string `json:"title,omitempty"`
// legacy compat
Todos []TodoItem `json:"todos,omitempty"`
}
EnhancedTodoInput is the unified JSON input for the todowrite enhanced tool.
type EnhancedTodoItem ¶
type EnhancedTodoItem struct {
ID string `json:"id"`
Title string `json:"title"`
Status string `json:"status"`
BlockedBy []string `json:"blocked_by,omitempty"`
Summary string `json:"summary,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
}
EnhancedTodoItem represents a single todo entry with dependency support.
type EnhancedTodoStore ¶
type EnhancedTodoStore struct {
// contains filtered or unexported fields
}
EnhancedTodoStore is a concurrency-safe store with dependency tracking and optional persistence.
func NewEnhancedTodoStore ¶
func NewEnhancedTodoStore(sessionID string, storage *StorageManager) *EnhancedTodoStore
NewEnhancedTodoStore creates a store, loading persisted data if storage is non-nil.
func (*EnhancedTodoStore) Add ¶
func (s *EnhancedTodoStore) Add(items []EnhancedTodoItem) error
Add appends new items, checking for ID conflicts with existing items.
func (*EnhancedTodoStore) HasIncomplete ¶
func (s *EnhancedTodoStore) HasIncomplete() bool
HasIncomplete returns true if any items are not_started or in_progress.
func (*EnhancedTodoStore) HasItems ¶
func (s *EnhancedTodoStore) HasItems() bool
HasItems returns true if there are any items.
func (*EnhancedTodoStore) IncompleteSummary ¶
func (s *EnhancedTodoStore) IncompleteSummary() string
IncompleteSummary returns a message listing incomplete items.
func (*EnhancedTodoStore) Items ¶
func (s *EnhancedTodoStore) Items() []TodoItem
Items converts enhanced items to legacy TodoItem format for backward TUI compatibility.
func (*EnhancedTodoStore) Load ¶
func (s *EnhancedTodoStore) Load() error
Load reads persisted state from disk. Errors from missing or corrupt files are ignored.
func (*EnhancedTodoStore) Modify ¶
func (s *EnhancedTodoStore) Modify(id, status, title string) error
Modify changes a single item by ID.
func (*EnhancedTodoStore) Remove ¶
func (s *EnhancedTodoStore) Remove(id string) error
Remove deletes an item by ID. Fails if other items depend on it.
func (*EnhancedTodoStore) SaveSync ¶
func (s *EnhancedTodoStore) SaveSync() error
SaveSync synchronously writes state to disk (for graceful shutdown). It drains any pending async writes first, then writes the current state.
func (*EnhancedTodoStore) SetOnChange ¶
func (s *EnhancedTodoStore) SetOnChange(fn func([]EnhancedTodoItem))
SetOnChange registers a callback invoked after every mutation.
func (*EnhancedTodoStore) Snapshot ¶
func (s *EnhancedTodoStore) Snapshot() []EnhancedTodoItem
Snapshot returns a deep copy of items.
func (*EnhancedTodoStore) Summary ¶
func (s *EnhancedTodoStore) Summary() string
Summary returns a human-readable summary string.
func (*EnhancedTodoStore) Update ¶
func (s *EnhancedTodoStore) Update(items []EnhancedTodoItem) error
Update replaces the entire list (legacy-compatible full-replacement semantics).
type Env ¶
type Env struct {
Exec Executor
TodoStore *TodoStore
FileTracker *FileTracker
OnEnvChange func(envLabel string, isLocal bool, err error)
Depth int // subagent nesting depth, 0 for top-level
// contains filtered or unexported fields
}
Env holds the execution context (local or remote) and is shared by all tools.
func (*Env) CloneForSubagent ¶
CloneForSubagent creates a copy of this Env with the same executor and pwd but an isolated TodoStore, suitable for use by a subagent.
func (*Env) NewCheckBackgroundTool ¶
func (e *Env) NewCheckBackgroundTool(bm *BackgroundManager) tool.InvokableTool
func (*Env) NewEditTool ¶
func (e *Env) NewEditTool() tool.InvokableTool
func (*Env) NewExecuteTool ¶
func (e *Env) NewExecuteTool(bm *BackgroundManager) tool.InvokableTool
func (*Env) NewGlobTool ¶
func (e *Env) NewGlobTool() tool.InvokableTool
func (*Env) NewGrepTool ¶
func (e *Env) NewGrepTool() tool.InvokableTool
func (*Env) NewReadTool ¶
func (e *Env) NewReadTool() tool.InvokableTool
func (*Env) NewSubagentTool ¶
func (e *Env) NewSubagentTool(deps *SubagentDeps) tool.InvokableTool
NewSubagentTool creates the "subagent" tool that delegates tasks to a child agent.
func (*Env) NewSwitchEnvTool ¶
func (e *Env) NewSwitchEnvTool() tool.InvokableTool
func (*Env) NewTodoReadTool ¶
func (e *Env) NewTodoReadTool() tool.InvokableTool
func (*Env) NewTodoWriteTool ¶
func (e *Env) NewTodoWriteTool() tool.InvokableTool
func (*Env) NewWriteTool ¶
func (e *Env) NewWriteTool() tool.InvokableTool
func (*Env) ResetToLocal ¶
ResetToLocal restores this Env to use the local executor.
func (*Env) ResolvePath ¶
ResolvePath resolves a file path relative to the working directory. Absolute paths are cleaned and returned as-is. Relative paths are joined with Pwd and cleaned. Logs a warning if the resolved relative path escapes the working directory.
func (*Env) SetSSH ¶
func (e *Env) SetSSH(executor *SSHExecutor, remotePwd string)
SetSSH switches this Env to use a remote SSH executor.
type ExecuteInput ¶
type Executor ¶
type Executor interface {
// ReadFile returns the contents of the file at path.
ReadFile(ctx context.Context, path string) ([]byte, error)
// WriteFile writes data to the file at path, creating parent dirs as needed.
WriteFile(ctx context.Context, path string, data []byte, perm os.FileMode) error
// MkdirAll creates a directory tree.
MkdirAll(ctx context.Context, path string, perm os.FileMode) error
// Stat returns basic info about a file (exists, is dir, etc.).
Stat(ctx context.Context, path string) (*FileInfo, error)
// Exec runs a command and returns stdout, stderr, and any error.
Exec(ctx context.Context, command string, workDir string, timeout time.Duration) (stdout, stderr string, err error)
// Platform returns the OS/arch string of the target machine.
Platform() string
// Label returns a human-readable description (e.g. "local" or "user@host:/path").
Label() string
}
Executor abstracts file and command operations so tools can work transparently on both local and remote (SSH) machines.
type FileState ¶
type FileState struct {
Path string
ContentHash string // MD5 hex
ModTime time.Time
Version int
BackupPath string
}
FileState tracks the known state of a single file.
type FileTracker ¶
type FileTracker struct {
// contains filtered or unexported fields
}
FileTracker detects external modifications to files the agent has read.
func NewFileTracker ¶
func NewFileTracker(storage *StorageManager) *FileTracker
NewFileTracker returns a FileTracker backed by the given StorageManager.
func (*FileTracker) CheckConflict ¶
func (ft *FileTracker) CheckConflict(path string) (ConflictResult, error)
CheckConflict compares current disk state with the tracked state. Returns ConflictNone if path is untracked or unchanged.
func (*FileTracker) CreateBackup ¶
func (ft *FileTracker) CreateBackup(path string, content []byte) (string, error)
CreateBackup writes a backup copy into the file-history directory. Returns the backup file path.
func (*FileTracker) TrackRead ¶
func (ft *FileTracker) TrackRead(path string, content []byte, modTime time.Time)
TrackRead records the hash and mod-time of a file that was just read.
func (*FileTracker) UpdateAfterWrite ¶
func (ft *FileTracker) UpdateAfterWrite(path string, content []byte, modTime time.Time)
UpdateAfterWrite updates the tracked state for a file that was just written.
type GrepInput ¶
type GrepInput struct {
Pattern string `json:"pattern"`
Path string `json:"path"`
Include string `json:"include,omitempty"`
CaseInsensitive bool `json:"case_insensitive,omitempty"`
MaxResults int `json:"max_results,omitempty"`
OutputMode string `json:"output_mode,omitempty"` // "content" (default), "files_with_matches", "count"
BeforeContext int `json:"before_context,omitempty"` // -B lines
AfterContext int `json:"after_context,omitempty"` // -A lines
Context int `json:"context,omitempty"` // -C lines (overrides before/after)
Offset int `json:"offset,omitempty"` // skip N results for pagination
Multiline bool `json:"multiline,omitempty"` // rg --multiline
FileType string `json:"file_type,omitempty"` // rg --type
}
GrepInput defines the input for the grep tool.
type LocalExecutor ¶
type LocalExecutor struct {
// contains filtered or unexported fields
}
func NewLocalExecutor ¶
func NewLocalExecutor(platform string) *LocalExecutor
func (*LocalExecutor) Label ¶
func (l *LocalExecutor) Label() string
func (*LocalExecutor) Platform ¶
func (l *LocalExecutor) Platform() string
type MCPCapabilities ¶
type MCPCapabilities struct {
Tools bool `json:"tools"`
Resources bool `json:"resources"`
Prompts bool `json:"prompts"`
}
MCPCapabilities summarises what a server supports.
type MCPConnection ¶
type MCPConnection struct {
Name string
Config *config.MCPServer
State MCPServerState
Client *client.Client
Tools []MCPToolInfo
Capabilities *MCPCapabilities
RetryCount int
LastError error
LastConnected time.Time
// contains filtered or unexported fields
}
MCPConnection tracks a single MCP server.
type MCPManager ¶
type MCPManager struct {
// contains filtered or unexported fields
}
MCPManager manages multiple MCP server connections with reconnection, dynamic add/remove, resource discovery and tool invocation.
func NewMCPManager ¶
func NewMCPManager(tokenStore *TokenStore, onState func(string, MCPServerState)) *MCPManager
NewMCPManager creates an MCPManager. tokenStore may be nil. onState may be nil (no callbacks).
func (*MCPManager) Close ¶
func (m *MCPManager) Close() error
Close disconnects all servers and cancels the manager context.
func (*MCPManager) Connect ¶
Connect creates a client for the given server config, starts it, initialises the MCP session and discovers tools and capabilities.
func (*MCPManager) Disconnect ¶
func (m *MCPManager) Disconnect(name string) error
Disconnect gracefully closes a server connection and removes it.
func (*MCPManager) GetAllTools ¶
func (m *MCPManager) GetAllTools() []MCPToolInfo
GetAllTools returns tools from all connected servers.
func (*MCPManager) GetServerStatus ¶
func (m *MCPManager) GetServerStatus() []MCPServerStatus
GetServerStatus returns a snapshot of all server statuses.
func (*MCPManager) InvokeMCPTool ¶
func (m *MCPManager) InvokeMCPTool(ctx context.Context, serverName, toolName string, args json.RawMessage) (string, error)
InvokeMCPTool calls a tool on the named server. If the call fails it attempts one reconnection before returning an error.
func (*MCPManager) ListResources ¶
func (m *MCPManager) ListResources(ctx context.Context, serverName string) ([]MCPResource, error)
ListResources returns the resources advertised by the named server.
func (*MCPManager) ReadResource ¶
ReadResource reads a single resource from the named server.
func (*MCPManager) RemoveServer ¶
func (m *MCPManager) RemoveServer(name string) error
RemoveServer disconnects and removes a server.
type MCPResource ¶
type MCPResource struct {
URI string `json:"uri"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
MimeType string `json:"mimeType,omitempty"`
}
MCPResource describes a resource exposed by an MCP server.
type MCPServerState ¶
type MCPServerState string
MCPServerState represents the connection state of an MCP server.
const ( MCPDisconnected MCPServerState = "disconnected" MCPConnecting MCPServerState = "connecting" MCPConnected MCPServerState = "connected" MCPReconnecting MCPServerState = "reconnecting" MCPFailed MCPServerState = "failed" )
type MCPServerStatus ¶
type MCPServerStatus struct {
Name string `json:"name"`
State MCPServerState `json:"state"`
ToolCount int `json:"tool_count"`
Error string `json:"error,omitempty"`
}
MCPServerStatus is a snapshot of one server connection.
type MCPToolInfo ¶
type MCPToolInfo struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema json.RawMessage `json:"input_schema"`
ServerName string `json:"server_name"`
}
MCPToolInfo describes a tool exposed by an MCP server.
type OAuthToken ¶
type OAuthToken struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
Scopes []string `json:"scopes,omitempty"`
Provider string `json:"provider"`
}
OAuthToken represents an OAuth token for an MCP provider.
type PersistedResult ¶
type PersistedResult struct {
FilePath string `json:"filepath"`
OriginalSize int `json:"original_size"`
Preview string `json:"preview"`
HasMore bool `json:"has_more"`
}
PersistedResult describes a tool result that has been spilled to disk.
type PlanStatus ¶
type PlanStatus string
PlanStatus represents the lifecycle state of a plan.
const ( PlanDraft PlanStatus = "draft" PlanSubmitted PlanStatus = "submitted" PlanApproved PlanStatus = "approved" PlanRejected PlanStatus = "rejected" )
type PlanStore ¶
type PlanStore struct {
// contains filtered or unexported fields
}
PlanStore is a concurrency-safe in-memory store for the active plan.
func (*PlanStore) Clear ¶
func (s *PlanStore) Clear()
Clear resets the plan store to empty draft state.
func (*PlanStore) HasApprovedPlan ¶
HasApprovedPlan returns true if a plan is currently approved.
func (*PlanStore) Status ¶
func (s *PlanStore) Status() PlanStatus
Status returns the current plan status.
type ReconnectPolicy ¶
type ReconnectPolicy struct {
InitialDelay time.Duration
MaxDelay time.Duration
MaxRetries int
Multiplier float64
}
ReconnectPolicy configures exponential backoff for reconnection attempts.
func DefaultReconnectPolicy ¶
func DefaultReconnectPolicy() *ReconnectPolicy
DefaultReconnectPolicy returns a sensible default policy.
type SSHExecutor ¶
type SSHExecutor struct {
// contains filtered or unexported fields
}
func NewSSHExecutor ¶
func NewSSHExecutor(addr, user string, authMethods []ssh.AuthMethod) (*SSHExecutor, error)
NewSSHExecutor connects to a remote host and returns an executor. It tries the SSH agent first, then common key paths.
func (*SSHExecutor) Close ¶
func (s *SSHExecutor) Close() error
func (*SSHExecutor) Label ¶
func (s *SSHExecutor) Label() string
func (*SSHExecutor) Platform ¶
func (s *SSHExecutor) Platform() string
type StorageManager ¶
type StorageManager struct {
// contains filtered or unexported fields
}
StorageManager provides persistence under ~/.jcode/storage/.
func NewStorageManager ¶
func NewStorageManager(sessionID string) (*StorageManager, error)
NewStorageManager creates the storage root and all subdirectories.
func (*StorageManager) AppendAsync ¶
func (sm *StorageManager) AppendAsync(path string, data []byte, mode os.FileMode)
AppendAsync enqueues an append to be flushed by the WriteQueue.
func (*StorageManager) Cleanup ¶
func (sm *StorageManager) Cleanup() error
Cleanup removes old files from the todos and tasks directories, keeping the most recent entries by modification time.
func (*StorageManager) Close ¶
func (sm *StorageManager) Close() error
Close drains the write queue.
func (*StorageManager) FileHistoryDir ¶
func (sm *StorageManager) FileHistoryDir() string
FileHistoryDir returns the file-history directory path.
func (*StorageManager) OAuthDir ¶
func (sm *StorageManager) OAuthDir() string
OAuthDir returns the oauth directory path.
func (*StorageManager) PlansDir ¶
func (sm *StorageManager) PlansDir() string
PlansDir returns the plans directory path.
func (*StorageManager) TasksDir ¶
func (sm *StorageManager) TasksDir() string
TasksDir returns the tasks directory path.
func (*StorageManager) TodosDir ¶
func (sm *StorageManager) TodosDir() string
TodosDir returns the todos directory path.
func (*StorageManager) ToolResultsDir ¶
func (sm *StorageManager) ToolResultsDir() string
ToolResultsDir returns the tool-results directory path.
func (*StorageManager) Write ¶
Write synchronously writes data to path, creating parent directories.
func (*StorageManager) WriteAsync ¶
func (sm *StorageManager) WriteAsync(path string, data []byte, mode os.FileMode)
WriteAsync enqueues a write to be flushed by the WriteQueue.
type StreamChunk ¶
StreamChunk represents a chunk of command output (for future streaming support).
type SubagentDeps ¶
type SubagentDeps struct {
ChatModel model.ToolCallingChatModel
ModelFactory *internalmodel.ModelFactory // optional, for multi-model subagents
TaskManager *SubagentTaskManager // optional, for async background tasks
Notifier SubagentNotifier
ProgressFn SubagentProgressFn // intermediate tool call/result events
TokenFn SubagentTokenFn // optional: token usage update after each model turn
Recorder *session.Recorder // records subagent start/result to session JSONL
Tracer *telemetry.LangfuseTracer // optional: Langfuse tracer for nested spans
}
SubagentDeps holds dependencies injected into the subagent tool at creation time.
type SubagentNotification ¶
type SubagentNotification struct {
TaskID string
Name string
AgentType string
Status SubagentTaskStatus
Summary string
}
SubagentNotification is produced when a background task changes state.
type SubagentNotifier ¶
SubagentNotifier receives subagent lifecycle events for TUI display.
type SubagentProgressFn ¶
type SubagentProgressFn func(agentName, event, toolName, detail string)
SubagentProgressFn receives intermediate progress events (tool calls, tool results) from a running subagent so the TUI can display live progress.
type SubagentTask ¶
type SubagentTask struct {
ID string
Name string
AgentType string
Model string
Status SubagentTaskStatus
Depth int
ParentID string
Output string
Error string
Started time.Time
Ended time.Time
Cancel context.CancelFunc
}
SubagentTask holds the state of a single subagent task.
type SubagentTaskManager ¶
type SubagentTaskManager struct {
// contains filtered or unexported fields
}
SubagentTaskManager tracks synchronous and asynchronous subagent tasks.
func NewSubagentTaskManager ¶
func NewSubagentTaskManager(maxParallel, maxCompleted int) *SubagentTaskManager
NewSubagentTaskManager creates a task manager. maxParallel limits concurrently running background tasks (0 = unlimited). maxCompleted is the number of completed tasks retained before eviction.
func (*SubagentTaskManager) DrainNotifications ¶
func (m *SubagentTaskManager) DrainNotifications() []SubagentNotification
DrainNotifications returns and clears all pending notifications.
func (*SubagentTaskManager) Get ¶
func (m *SubagentTaskManager) Get(taskID string) (*SubagentTask, error)
Get returns a copy-safe snapshot of a task by ID.
func (*SubagentTaskManager) List ¶
func (m *SubagentTaskManager) List(statusFilter SubagentTaskStatus) []*SubagentTask
List returns tasks matching the given status filter. An empty statusFilter returns all tasks.
func (*SubagentTaskManager) RunningCount ¶
func (m *SubagentTaskManager) RunningCount() int
RunningCount returns the number of currently running tasks.
func (*SubagentTaskManager) Stop ¶
func (m *SubagentTaskManager) Stop(taskID string) error
Stop cancels a running background task.
func (*SubagentTaskManager) Submit ¶
func (m *SubagentTaskManager) Submit( ctx context.Context, task *SubagentTask, runFn func(ctx context.Context) (string, error), background bool, ) (taskID, result string, err error)
Submit runs or enqueues a task. When background is false the call blocks and returns the final result. When background is true the task is launched in a goroutine and the task ID is returned immediately.
type SubagentTaskStatus ¶
type SubagentTaskStatus string
SubagentTaskStatus represents the lifecycle state of a subagent task.
const ( TaskStatusPending SubagentTaskStatus = "pending" TaskStatusRunning SubagentTaskStatus = "running" TaskStatusCompleted SubagentTaskStatus = "completed" TaskStatusFailed SubagentTaskStatus = "failed" TaskStatusStopped SubagentTaskStatus = "stopped" )
type SubagentTokenFn ¶
type SubagentTokenFn func(totalTokens int64)
SubagentTokenFn is called after each model turn with the cumulative token delta (tokens used by this subagent since it started) so the TUI can display progress.
type SwitchEnvInput ¶
type SwitchEnvInput struct {
Target string `json:"target"`
}
type TaskLog ¶
type TaskLog struct {
// contains filtered or unexported fields
}
TaskLog writes output from a background task to disk.
func NewTaskLog ¶
func NewTaskLog(storage *StorageManager, taskID string) (*TaskLog, error)
NewTaskLog opens (or creates) a log file for the task in the tasks dir.
type TodoAction ¶
type TodoAction string
TodoAction identifies the operation to perform.
const ( TodoActionUpdate TodoAction = "update" TodoActionAdd TodoAction = "add" TodoActionModify TodoAction = "modify" TodoActionRemove TodoAction = "remove" TodoActionRead TodoAction = "read" )
type TodoFileFormat ¶
type TodoFileFormat struct {
Version int `json:"version"`
SessionID string `json:"session_id"`
UpdatedAt time.Time `json:"updated_at"`
Items []EnhancedTodoItem `json:"items"`
}
TodoFileFormat is the on-disk JSON structure.
type TodoItem ¶
type TodoItem struct {
ID int `json:"id"`
Title string `json:"title"`
Status TodoStatus `json:"status"`
}
TodoItem represents a single todo entry.
func ExtractTodosFromPlan ¶
ExtractTodosFromPlan parses the ## Plan or ## Steps section from plan markdown and returns TodoItems with status=pending.
type TodoStatus ¶
type TodoStatus string
TodoStatus represents the state of a todo item.
const ( TodoPending TodoStatus = "pending" TodoInProgress TodoStatus = "in_progress" TodoCompleted TodoStatus = "completed" TodoCancelled TodoStatus = "cancelled" )
type TodoStore ¶
type TodoStore struct {
OnUpdate func(items []TodoItem) // called after Update() with a snapshot copy
// contains filtered or unexported fields
}
TodoStore is a concurrency-safe in-memory store for todo items.
func (*TodoStore) HasIncomplete ¶
HasIncomplete returns true if any items are not completed/cancelled.
func (*TodoStore) IncompleteSummary ¶
IncompleteSummary returns a message listing the incomplete items, for use as an agent reminder.
type TokenStore ¶
type TokenStore struct {
// contains filtered or unexported fields
}
TokenStore persists OAuth tokens as JSON files.
func NewTokenStore ¶
func NewTokenStore(dir string) *TokenStore
NewTokenStore returns a TokenStore that reads/writes in dir.
func (*TokenStore) Delete ¶
func (ts *TokenStore) Delete(provider string) error
Delete removes the token file for a provider.
func (*TokenStore) Get ¶
func (ts *TokenStore) Get(provider string) (*OAuthToken, error)
Get reads the token for a provider. Returns nil, nil if not found.
func (*TokenStore) Save ¶
func (ts *TokenStore) Save(provider string, token OAuthToken) error
Save writes the token for a provider as JSON with 0600 permissions.
type ToolProgressMsg ¶
ToolProgressMsg conveys partial progress for long-running commands.
type ToolResultStore ¶
type ToolResultStore struct {
// contains filtered or unexported fields
}
ToolResultStore persists large tool outputs to disk.
func NewToolResultStore ¶
func NewToolResultStore(storage *StorageManager) *ToolResultStore
NewToolResultStore creates a ToolResultStore with a 50 000 char threshold.
func (*ToolResultStore) PersistIfLarge ¶
func (ts *ToolResultStore) PersistIfLarge(toolName, result string) (PersistedResult, bool)
PersistIfLarge writes result to disk if it exceeds the threshold. Returns the persisted metadata and true, or zero value and false if small.
type WriteEntry ¶
WriteEntry represents a single pending write or append operation.
type WriteInput ¶
type WriteQueue ¶
type WriteQueue struct {
// contains filtered or unexported fields
}
WriteQueue batches writes and flushes them on a timer or on demand.
func NewWriteQueue ¶
func NewWriteQueue(interval time.Duration) *WriteQueue
NewWriteQueue starts a background drainLoop at the given interval.
func (*WriteQueue) Close ¶
func (wq *WriteQueue) Close()
Close signals the drainLoop to stop and drains remaining entries.
func (*WriteQueue) DrainSync ¶
func (wq *WriteQueue) DrainSync()
DrainSync synchronously flushes all pending writes.
func (*WriteQueue) Enqueue ¶
func (wq *WriteQueue) Enqueue(path string, entry WriteEntry)
Enqueue adds an entry for the given path, non-blocking.