Documentation
¶
Index ¶
- func RunShellArgumentsContainNetworkTarget(rawArguments string) bool
- func RunShellCommandHasNetworkTarget(command string) bool
- func RunWorkerProcess(ctx context.Context, stdin io.Reader, stdout io.Writer) error
- func ValidateSystemSandboxRuntime(sandboxEnabled bool, mode string) error
- func ValidateToolSpec(spec ToolSpec) error
- type AgentInfo
- type ApplyPatchTool
- type ApprovalDecision
- type ApprovalDisposition
- type ApprovalHandler
- type ApprovalRequest
- type ArgumentDecoder
- type DelegateSubAgentError
- type DelegateSubAgentHandler
- type DelegateSubAgentRequest
- type DelegateSubAgentResult
- type DelegateSubAgentScope
- type DelegateSubAgentTool
- type DiffFile
- type DiffHunk
- type DiffPreview
- type ExecuteRequest
- type ExecuteResult
- type ExecutionContext
- type Executor
- func (e *Executor) Execute(ctx context.Context, name, rawArgs string, execCtx *ExecutionContext) (string, error)
- func (e *Executor) ExecuteForMode(ctx context.Context, mode planpkg.AgentMode, name, rawArgs string, ...) (string, error)
- func (e *Executor) ExecuteRequest(ctx context.Context, req ExecuteRequest) (ExecuteResult, error)
- type GitDiffTool
- type GitStatusTool
- type ListFilesTool
- type OutputNormalizer
- type PermissionEngine
- type ReadFileTool
- type RegisterOptions
- type RegistrationMeta
- type RegistrationSource
- type Registry
- func (r *Registry) Add(tool Tool)
- func (r *Registry) Count() int
- func (r *Registry) Definitions() []llm.ToolDefinition
- func (r *Registry) DefinitionsForMode(mode planpkg.AgentMode) []llm.ToolDefinition
- func (r *Registry) DefinitionsForModeWithFilters(mode planpkg.AgentMode, allowlist, denylist []string) []llm.ToolDefinition
- func (r *Registry) FindByExtensionID(extensionID string) []RegistrationMeta
- func (r *Registry) FindByOriginalName(name string) []RegistrationMeta
- func (r *Registry) Get(name string) (ResolvedTool, bool)
- func (r *Registry) List() []ResolvedTool
- func (r *Registry) Register(tool Tool, opts RegisterOptions) error
- func (r *Registry) ResolveForMode(mode planpkg.AgentMode, name string) (ResolvedTool, error)
- func (r *Registry) ResolveForModeWithFilters(mode planpkg.AgentMode, allowlist, denylist []string) []ResolvedTool
- func (r *Registry) Spec(name string) (ToolSpec, bool)
- func (r *Registry) Unregister(name string) error
- type RegistryError
- type RegistryErrorCode
- type ReplaceInFileTool
- type ResolvedTool
- type RunShellTool
- type RunTestsTool
- type SafetyClass
- type SearchTextTool
- type SubAgentToolCallRecord
- type SystemSandboxBackendCapabilities
- type SystemSandboxRuntimeStatus
- type TaskOutputTool
- type TaskStopTool
- type Tool
- type ToolErrorCode
- type ToolExecError
- type ToolSpec
- type ToolSpecProvider
- type TranscriptMessage
- type UpdatePlanTool
- type WebFetchTool
- type WebSearchTool
- type WorktreeInfo
- type WriteFileTool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunShellArgumentsContainNetworkTarget ¶
RunShellArgumentsContainNetworkTarget reports whether serialized run_shell tool arguments (JSON) contain a network-targeted command.
func RunShellCommandHasNetworkTarget ¶
RunShellCommandHasNetworkTarget reports whether a run_shell command string contains an explicit network target URL.
func RunWorkerProcess ¶
func ValidateSystemSandboxRuntime ¶
ValidateSystemSandboxRuntime verifies whether the configured system sandbox mode is usable in the current runtime. It is fail-closed for required mode.
func ValidateToolSpec ¶
Types ¶
type ApplyPatchTool ¶
type ApplyPatchTool struct{}
func (ApplyPatchTool) Definition ¶
func (ApplyPatchTool) Definition() llm.ToolDefinition
func (ApplyPatchTool) Run ¶
func (ApplyPatchTool) Run(ctx context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
Example ¶
workspace, err := os.MkdirTemp("", "apply-patch-example")
if err != nil {
fmt.Println("error:", err)
return
}
defer os.RemoveAll(workspace)
path := filepath.Join(workspace, "sample.txt")
if err := os.WriteFile(path, []byte("alpha\nbeta\n"), 0o644); err != nil {
fmt.Println("error:", err)
return
}
tool := ApplyPatchTool{}
payload, _ := json.Marshal(map[string]any{
"patch": "*** Begin Patch\n*** Update File: sample.txt\n@@\n alpha\n-beta\n+gamma\n*** End Patch",
})
if _, err := tool.Run(context.Background(), payload, &ExecutionContext{Workspace: workspace, Session: session.New(workspace)}); err != nil {
fmt.Println("error:", err)
return
}
data, err := os.ReadFile(path)
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Print(string(data))
Output: alpha gamma
type ApprovalDecision ¶ added in v0.1.6
type ApprovalDecision struct {
Disposition ApprovalDisposition
}
func NormalizeApprovalDecision ¶ added in v0.1.6
func NormalizeApprovalDecision(d ApprovalDecision) ApprovalDecision
func (ApprovalDecision) Approved ¶ added in v0.1.6
func (d ApprovalDecision) Approved() bool
func (ApprovalDecision) ReusableForAllTools ¶ added in v0.1.6
func (d ApprovalDecision) ReusableForAllTools() bool
func (ApprovalDecision) ReusableForSameTool ¶ added in v0.1.6
func (d ApprovalDecision) ReusableForSameTool() bool
type ApprovalDisposition ¶ added in v0.1.6
type ApprovalDisposition string
const ( ApprovalApproveOnce ApprovalDisposition = "approve_once" ApprovalApproveSameToolSession ApprovalDisposition = "approve_same_tool_session" ApprovalApproveAllSession ApprovalDisposition = "approve_all_session" ApprovalDeny ApprovalDisposition = "deny" )
type ApprovalHandler ¶
type ApprovalHandler func(ApprovalRequest) (ApprovalDecision, error)
type ApprovalRequest ¶
type ArgumentDecoder ¶
type ArgumentDecoder interface {
Decode(string, ResolvedTool) (json.RawMessage, error)
}
type DelegateSubAgentError ¶
type DelegateSubAgentHandler ¶
type DelegateSubAgentHandler func(context.Context, DelegateSubAgentRequest, *ExecutionContext) (DelegateSubAgentResult, error)
type DelegateSubAgentRequest ¶
type DelegateSubAgentRequest struct {
Agent string `json:"agent"`
Task string `json:"task"`
Scope DelegateSubAgentScope `json:"scope"`
Timeout string `json:"timeout"`
Isolation string `json:"isolation"`
Output string `json:"output"`
RunInBackground bool `json:"run_in_background"`
ResumeSessionID string `json:"resume_session_id,omitempty"`
}
type DelegateSubAgentResult ¶
type DelegateSubAgentResult struct {
OK bool `json:"ok"`
Status string `json:"status,omitempty"`
InvocationID string `json:"invocation_id"`
Agent string `json:"agent"`
TaskID string `json:"task_id,omitempty"`
ResultReadTool string `json:"result_read_tool,omitempty"`
StopTool string `json:"stop_tool,omitempty"`
Summary string `json:"summary,omitempty"`
Content string `json:"content,omitempty"`
Error *DelegateSubAgentError `json:"error,omitempty"`
Transcript []TranscriptMessage `json:"transcript,omitempty"`
TranscriptSessionID string `json:"transcript_session_id,omitempty"`
Task string `json:"task,omitempty"`
ModifiedFiles []string `json:"modified_files,omitempty"`
Worktree *WorktreeInfo `json:"worktree,omitempty"`
// ToolCalls carries structured tool call records from the subagent session.
// Populated by the executor for TUI restoration; excluded from JSON via
// json:"-" so it never reaches the parent LLM context.
ToolCalls []SubAgentToolCallRecord `json:"-"`
}
type DelegateSubAgentScope ¶
type DelegateSubAgentTool ¶
type DelegateSubAgentTool struct {
// contains filtered or unexported fields
}
func NewDelegateSubAgentTool ¶ added in v0.1.8
func NewDelegateSubAgentTool(agents []AgentInfo) DelegateSubAgentTool
func (DelegateSubAgentTool) Definition ¶
func (t DelegateSubAgentTool) Definition() llm.ToolDefinition
func (DelegateSubAgentTool) Run ¶
func (DelegateSubAgentTool) Run(ctx context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
func (DelegateSubAgentTool) Spec ¶
func (DelegateSubAgentTool) Spec() ToolSpec
type DiffFile ¶ added in v0.1.8
type DiffFile struct {
Path string `json:"path"`
NewPath string `json:"new_path,omitempty"`
ChangeType string `json:"change_type"` // add, delete, modify, move
Added int `json:"added"`
Removed int `json:"removed"`
Hunks []DiffHunk `json:"hunks"`
Truncated bool `json:"truncated"`
}
DiffFile describes changes to a single file.
type DiffHunk ¶ added in v0.1.8
type DiffHunk struct {
OldStart int `json:"old_start"`
OldLines int `json:"old_lines"`
NewStart int `json:"new_start"`
NewLines int `json:"new_lines"`
Lines []string `json:"lines"`
}
DiffHunk represents one unified-diff hunk.
type DiffPreview ¶ added in v0.1.8
type DiffPreview struct {
Files []DiffFile `json:"files"`
TotalFiles int `json:"total_files"`
TotalAdded int `json:"total_added"`
TotalRemoved int `json:"total_removed"`
Truncated bool `json:"truncated"`
}
DiffPreview carries structured code change detail for editing tools. It is an optional, backward-compatible field added to tool result JSON.
type ExecuteRequest ¶
type ExecuteRequest struct {
Name string
RawArgs string
Mode planpkg.AgentMode
Context *ExecutionContext
}
type ExecuteResult ¶
type ExecutionContext ¶
type ExecutionContext struct {
Workspace string
WritableRoots []string
ApprovalPolicy string
ApprovalMode string
AwayPolicy string
SandboxEnabled bool
SystemSandboxMode string
SkipShellApproval bool
SandboxEscalationApproved bool
LeaseID string
RunID string
FSRead []string
FSWrite []string
ExecAllowlist []sandboxpkg.ExecRule
NetworkAllowlist []sandboxpkg.NetworkRule
Lease *sandboxpkg.Lease
LeaseKeyring map[string][]byte
Approval ApprovalHandler
Session *session.Session
TaskManager runtimepkg.TaskManager
// Extensions is an optional passthrough hook for callers that need extension context.
// It stays untyped here to keep tools/extension packages decoupled.
Extensions any
Mode planpkg.AgentMode
Stdin io.Reader
Stdout io.Writer
AllowedTools map[string]struct{}
DeniedTools map[string]struct{}
DelegateSubAgent DelegateSubAgentHandler
}
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
func NewExecutor ¶
func (*Executor) ExecuteForMode ¶
func (*Executor) ExecuteRequest ¶
func (e *Executor) ExecuteRequest(ctx context.Context, req ExecuteRequest) (ExecuteResult, error)
type GitDiffTool ¶ added in v1.0.0
type GitDiffTool struct{}
func (GitDiffTool) Definition ¶ added in v1.0.0
func (GitDiffTool) Definition() llm.ToolDefinition
func (GitDiffTool) Run ¶ added in v1.0.0
func (GitDiffTool) Run(ctx context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
type GitStatusTool ¶ added in v1.0.0
type GitStatusTool struct{}
func (GitStatusTool) Definition ¶ added in v1.0.0
func (GitStatusTool) Definition() llm.ToolDefinition
func (GitStatusTool) Run ¶ added in v1.0.0
func (GitStatusTool) Run(ctx context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
type ListFilesTool ¶
type ListFilesTool struct{}
func (ListFilesTool) Definition ¶
func (ListFilesTool) Definition() llm.ToolDefinition
func (ListFilesTool) Run ¶
func (ListFilesTool) Run(ctx context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
type OutputNormalizer ¶
type OutputNormalizer interface {
Normalize(string, ResolvedTool) string
}
type PermissionEngine ¶
type PermissionEngine interface {
Check(context.Context, ResolvedTool, *ExecutionContext) error
}
type ReadFileTool ¶
type ReadFileTool struct{}
func (ReadFileTool) Definition ¶
func (ReadFileTool) Definition() llm.ToolDefinition
func (ReadFileTool) Run ¶
func (ReadFileTool) Run(_ context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
type RegisterOptions ¶
type RegisterOptions struct {
Source RegistrationSource
ExtensionID string
OriginalName string
// AllowOriginalNameShadowBuiltin permits extension registrations to reuse an
// existing builtin original tool name. This is only intended for bridge
// aliases whose tool key is source-aware and unique.
AllowOriginalNameShadowBuiltin bool
}
type RegistrationMeta ¶
type RegistrationSource ¶
type RegistrationSource string
const ( RegistrationSourceBuiltin RegistrationSource = "builtin" RegistrationSourceExtension RegistrationSource = "extension" )
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func DefaultRegistry ¶
func (*Registry) Add ¶
Add keeps backward compatibility with tests and call sites that used the old API.
func (*Registry) Definitions ¶
func (r *Registry) Definitions() []llm.ToolDefinition
func (*Registry) DefinitionsForMode ¶
func (r *Registry) DefinitionsForMode(mode planpkg.AgentMode) []llm.ToolDefinition
func (*Registry) DefinitionsForModeWithFilters ¶
func (*Registry) FindByExtensionID ¶
func (r *Registry) FindByExtensionID(extensionID string) []RegistrationMeta
func (*Registry) FindByOriginalName ¶
func (r *Registry) FindByOriginalName(name string) []RegistrationMeta
func (*Registry) List ¶
func (r *Registry) List() []ResolvedTool
func (*Registry) ResolveForMode ¶
func (*Registry) ResolveForModeWithFilters ¶
func (r *Registry) ResolveForModeWithFilters(mode planpkg.AgentMode, allowlist, denylist []string) []ResolvedTool
func (*Registry) Unregister ¶
type RegistryError ¶
type RegistryError struct {
Code RegistryErrorCode
Message string
ToolKey string
OriginalToolName string
Source RegistrationSource
ExtensionID string
ConflictWith RegistrationMeta
Cause error
}
func (*RegistryError) Error ¶
func (e *RegistryError) Error() string
func (*RegistryError) Unwrap ¶
func (e *RegistryError) Unwrap() error
type RegistryErrorCode ¶
type RegistryErrorCode string
const ( RegistryErrorDuplicateName RegistryErrorCode = "duplicate_name" RegistryErrorInvalidSource RegistryErrorCode = "invalid_source" RegistryErrorInvalidSchema RegistryErrorCode = "invalid_schema" RegistryErrorInvalidTool RegistryErrorCode = "invalid_tool" RegistryErrorInvalidToolKey RegistryErrorCode = "invalid_tool_key" RegistryErrorNotFound RegistryErrorCode = "not_found" )
type ReplaceInFileTool ¶
type ReplaceInFileTool struct{}
func (ReplaceInFileTool) Definition ¶
func (ReplaceInFileTool) Definition() llm.ToolDefinition
func (ReplaceInFileTool) Run ¶
func (ReplaceInFileTool) Run(ctx context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
type ResolvedTool ¶
type ResolvedTool struct {
Definition llm.ToolDefinition
Spec ToolSpec
Tool Tool
}
type RunShellTool ¶
type RunShellTool struct{}
func (RunShellTool) Definition ¶
func (RunShellTool) Definition() llm.ToolDefinition
func (RunShellTool) Run ¶
func (RunShellTool) Run(ctx context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
type RunTestsTool ¶ added in v1.0.0
type RunTestsTool struct{}
func (RunTestsTool) Definition ¶ added in v1.0.0
func (RunTestsTool) Definition() llm.ToolDefinition
func (RunTestsTool) Run ¶ added in v1.0.0
func (RunTestsTool) Run(ctx context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
func (RunTestsTool) Spec ¶ added in v1.0.0
func (RunTestsTool) Spec() ToolSpec
type SafetyClass ¶
type SafetyClass string
const ( SafetyClassSafe SafetyClass = "safe" SafetyClassModerate SafetyClass = "moderate" SafetyClassSensitive SafetyClass = "sensitive" SafetyClassDestructive SafetyClass = "destructive" )
type SearchTextTool ¶
type SearchTextTool struct{}
func (SearchTextTool) Definition ¶
func (SearchTextTool) Definition() llm.ToolDefinition
func (SearchTextTool) Run ¶
func (SearchTextTool) Run(ctx context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
type SubAgentToolCallRecord ¶ added in v0.1.8
type SubAgentToolCallRecord struct {
ToolName string `json:"ToolName"`
ToolCallID string `json:"ToolCallID"`
CompactBody string `json:"CompactBody"`
Status string `json:"Status"`
DetailLines []string `json:"DetailLines,omitempty"`
}
SubAgentToolCallRecord is a JSON-serializable record of a tool call made by a subagent. JSON tags match tui.SubAgentToolCall for direct unmarshal.
type SystemSandboxBackendCapabilities ¶
type SystemSandboxBackendCapabilities struct {
Name string
Known bool
ShellNetworkIsolation bool
WorkerNetworkIsolation bool
}
func SystemSandboxBackendCapabilitiesForName ¶
func SystemSandboxBackendCapabilitiesForName(name string) SystemSandboxBackendCapabilities
type SystemSandboxRuntimeStatus ¶
type SystemSandboxRuntimeStatus struct {
SandboxEnabled bool
RequestedMode string
Mode string
GOOS string
BackendEnabled bool
BackendName string
RequiredCapable bool
CapabilityLevel string
ShellNetworkIsolation bool
WorkerNetworkIsolation bool
Fallback bool
Message string
}
SystemSandboxRuntimeStatus describes system sandbox runtime state after configuration and platform/backend probing are applied.
func ResolveSystemSandboxRuntimeStatus ¶
func ResolveSystemSandboxRuntimeStatus(sandboxEnabled bool, mode string) (SystemSandboxRuntimeStatus, error)
ResolveSystemSandboxRuntimeStatus reports the effective runtime status of system sandbox mode under the current process OS and backend availability.
type TaskOutputTool ¶
type TaskOutputTool struct{}
func (TaskOutputTool) Definition ¶
func (TaskOutputTool) Definition() llm.ToolDefinition
func (TaskOutputTool) Run ¶
func (TaskOutputTool) Run(ctx context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
func (TaskOutputTool) Spec ¶
func (TaskOutputTool) Spec() ToolSpec
type TaskStopTool ¶
type TaskStopTool struct{}
func (TaskStopTool) Definition ¶
func (TaskStopTool) Definition() llm.ToolDefinition
func (TaskStopTool) Run ¶
func (TaskStopTool) Run(ctx context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
func (TaskStopTool) Spec ¶
func (TaskStopTool) Spec() ToolSpec
type Tool ¶
type Tool interface {
Definition() llm.ToolDefinition
Run(context.Context, json.RawMessage, *ExecutionContext) (string, error)
}
type ToolErrorCode ¶
type ToolErrorCode string
const ( ToolErrorInvalidArgs ToolErrorCode = "invalid_args" ToolErrorPermissionDenied ToolErrorCode = "permission_denied" ToolErrorTimeout ToolErrorCode = "timeout" ToolErrorToolFailed ToolErrorCode = "tool_failed" ToolErrorInternal ToolErrorCode = "internal_error" )
type ToolExecError ¶
type ToolExecError struct {
Code ToolErrorCode
Message string
Retryable bool
Cause error
}
func AsToolExecError ¶
func AsToolExecError(err error) (*ToolExecError, bool)
func NewToolExecError ¶
func NewToolExecError(code ToolErrorCode, message string, retryable bool, cause error) *ToolExecError
func (*ToolExecError) Error ¶
func (e *ToolExecError) Error() string
func (*ToolExecError) Unwrap ¶
func (e *ToolExecError) Unwrap() error
type ToolSpec ¶
type ToolSpec struct {
Name string
ReadOnly bool
ConcurrencySafe bool
Destructive bool
SafetyClass SafetyClass
StrictArgs bool
SearchHint string
AllowedModes []planpkg.AgentMode
DefaultTimeoutS int
MaxTimeoutS int
MaxResultChars int
}
func DefaultToolSpec ¶
func DefaultToolSpec(def llm.ToolDefinition) ToolSpec
func MergeToolSpec ¶
func NormalizeToolSpec ¶
type ToolSpecProvider ¶
type ToolSpecProvider interface {
Spec() ToolSpec
}
type TranscriptMessage ¶ added in v0.1.8
TranscriptMessage represents a single message in a subagent's transcript.
type UpdatePlanTool ¶
type UpdatePlanTool struct{}
func (UpdatePlanTool) Definition ¶
func (UpdatePlanTool) Definition() llm.ToolDefinition
func (UpdatePlanTool) Run ¶
func (UpdatePlanTool) Run(_ context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
type WebFetchTool ¶
func NewWebFetchTool ¶
func NewWebFetchTool() WebFetchTool
func (WebFetchTool) Definition ¶
func (WebFetchTool) Definition() llm.ToolDefinition
func (WebFetchTool) Run ¶
func (t WebFetchTool) Run(ctx context.Context, raw json.RawMessage, _ *ExecutionContext) (string, error)
type WebSearchTool ¶
func NewWebSearchTool ¶
func NewWebSearchTool() WebSearchTool
func (WebSearchTool) Definition ¶
func (WebSearchTool) Definition() llm.ToolDefinition
func (WebSearchTool) Run ¶
func (t WebSearchTool) Run(ctx context.Context, raw json.RawMessage, _ *ExecutionContext) (string, error)
type WorktreeInfo ¶ added in v0.1.8
type WorktreeInfo struct {
Path string `json:"path,omitempty"`
Branch string `json:"branch,omitempty"`
State string `json:"state,omitempty"` // "changed" | "unknown"
}
WorktreeInfo carries worktree isolation metadata in a subagent result.
type WriteFileTool ¶
type WriteFileTool struct{}
func (WriteFileTool) Definition ¶
func (WriteFileTool) Definition() llm.ToolDefinition
func (WriteFileTool) Run ¶
func (WriteFileTool) Run(ctx context.Context, raw json.RawMessage, execCtx *ExecutionContext) (string, error)
Source Files
¶
- apply_patch.go
- approval.go
- approval_channel.go
- delegate_subagent.go
- diff_preview.go
- errors.go
- executor.go
- git_diff.go
- git_status.go
- helpers.go
- list_files.go
- read_file.go
- registry.go
- registry_errors.go
- replace_in_file.go
- rollback_helpers.go
- run_shell.go
- run_tests.go
- search_text.go
- spec.go
- system_sandbox.go
- system_sandbox_backend.go
- system_sandbox_darwin_profile.go
- system_sandbox_env.go
- system_sandbox_linux_fs.go
- system_sandbox_process_runner.go
- system_sandbox_process_runner_other.go
- task_output.go
- task_stop.go
- update_plan.go
- web_fetch.go
- web_helpers.go
- web_search.go
- worker.go
- worker_process.go
- write_file.go