Documentation
¶
Index ¶
- func DescribeFlags(flagged []string) string
- func DescribeRedactions(hits []string) string
- func ValidatePath(workspaceRoot, requestedPath string) (string, error)
- type ApprovalGate
- func (g *ApprovalGate) IsAutoApproved(toolName string) bool
- func (g *ApprovalGate) IsDenied(toolName string) bool
- func (g *ApprovalGate) RequestApproval(toolName string, args json.RawMessage, preview string) (bool, error)
- func (g *ApprovalGate) SetInputReader(r *bufio.Reader)
- func (g *ApprovalGate) SetPermissions(autoApprove, deny []string)
- func (g *ApprovalGate) WrapExecution(ctx context.Context, tool Tool, args json.RawMessage) (Result, error)
- type CodeSearchTool
- type FilePatchTool
- type FileReadTool
- type FileWriteTool
- type Preview
- type Previewer
- type Registry
- type Result
- type ShellExecTool
- type ShellGuard
- type Tool
- type ToolSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DescribeFlags ¶ added in v0.5.0
DescribeFlags renders the advisory warnings shown in the approval preview.
func DescribeRedactions ¶ added in v0.5.0
DescribeRedactions renders a note listing which secret patterns were masked.
func ValidatePath ¶ added in v0.4.0
ValidatePath ensures that the requested path resolves to a location within the workspace root. It converts relative paths to absolute, cleans them, evaluates symlinks, and rejects any path that escapes the workspace boundary.
Returns the cleaned absolute path if valid.
Types ¶
type ApprovalGate ¶
type ApprovalGate struct {
OnPresent func(toolName string, args json.RawMessage, preview string) (bool, error)
// contains filtered or unexported fields
}
func NewApprovalGate ¶
func NewApprovalGate() *ApprovalGate
func NewApprovalGateWithPermissions ¶ added in v0.2.0
func NewApprovalGateWithPermissions(autoApprove, deny []string) *ApprovalGate
func (*ApprovalGate) IsAutoApproved ¶ added in v0.2.0
func (g *ApprovalGate) IsAutoApproved(toolName string) bool
func (*ApprovalGate) IsDenied ¶ added in v0.2.0
func (g *ApprovalGate) IsDenied(toolName string) bool
func (*ApprovalGate) RequestApproval ¶
func (g *ApprovalGate) RequestApproval(toolName string, args json.RawMessage, preview string) (bool, error)
func (*ApprovalGate) SetInputReader ¶ added in v0.5.0
func (g *ApprovalGate) SetInputReader(r *bufio.Reader)
SetInputReader makes the gate read approval answers from r. Callers that already read from the same stream must pass their existing reader so that buffered data is not lost between the prompt and the gate.
func (*ApprovalGate) SetPermissions ¶ added in v0.2.0
func (g *ApprovalGate) SetPermissions(autoApprove, deny []string)
func (*ApprovalGate) WrapExecution ¶
func (g *ApprovalGate) WrapExecution(ctx context.Context, tool Tool, args json.RawMessage) (Result, error)
WrapExecution handles the full preview → approval → execute flow. If the tool implements Previewer, a preview is generated first and shown to the user before execution. Denied operations never call Execute.
type CodeSearchTool ¶ added in v0.4.0
type CodeSearchTool struct {
IgnoreMatcher ignore.Matcher
SensitiveMatcher *ignore.SensitiveMatcher
WorkspaceRoot string
}
CodeSearchTool searches for patterns across workspace files.
func (*CodeSearchTool) Execute ¶ added in v0.4.0
func (c *CodeSearchTool) Execute(ctx context.Context, args json.RawMessage) (Result, error)
func (*CodeSearchTool) RequiresApproval ¶ added in v0.4.0
func (c *CodeSearchTool) RequiresApproval() bool
func (*CodeSearchTool) Spec ¶ added in v0.4.0
func (c *CodeSearchTool) Spec() ToolSpec
type FilePatchTool ¶
type FilePatchTool struct {
IgnoreMatcher ignore.Matcher
SensitiveMatcher *ignore.SensitiveMatcher
WorkspaceRoot string
OnModified func(path string)
}
func (*FilePatchTool) Execute ¶
func (f *FilePatchTool) Execute(ctx context.Context, args json.RawMessage) (Result, error)
Execute applies the patch. This is called ONLY after approval.
func (*FilePatchTool) Preview ¶ added in v0.4.0
func (f *FilePatchTool) Preview(ctx context.Context, args json.RawMessage) (Preview, error)
Preview generates a diff preview of the proposed patch WITHOUT modifying any files. This is called before approval.
func (*FilePatchTool) RequiresApproval ¶
func (f *FilePatchTool) RequiresApproval() bool
func (*FilePatchTool) Spec ¶
func (f *FilePatchTool) Spec() ToolSpec
type FileReadTool ¶
type FileReadTool struct {
IgnoreMatcher ignore.Matcher
SensitiveMatcher *ignore.SensitiveMatcher
WorkspaceRoot string
}
func (*FileReadTool) Execute ¶
func (f *FileReadTool) Execute(ctx context.Context, args json.RawMessage) (Result, error)
func (*FileReadTool) RequiresApproval ¶
func (f *FileReadTool) RequiresApproval() bool
func (*FileReadTool) Spec ¶
func (f *FileReadTool) Spec() ToolSpec
type FileWriteTool ¶
type FileWriteTool struct {
IgnoreMatcher ignore.Matcher
SensitiveMatcher *ignore.SensitiveMatcher
WorkspaceRoot string
OnModified func(path string)
}
func (*FileWriteTool) Execute ¶
func (f *FileWriteTool) Execute(ctx context.Context, args json.RawMessage) (Result, error)
Execute writes the file. This is called ONLY after approval.
func (*FileWriteTool) Preview ¶ added in v0.4.0
func (f *FileWriteTool) Preview(ctx context.Context, args json.RawMessage) (Preview, error)
Preview generates a diff preview of the proposed change WITHOUT modifying any files. This is called before approval.
func (*FileWriteTool) RequiresApproval ¶
func (f *FileWriteTool) RequiresApproval() bool
func (*FileWriteTool) Spec ¶
func (f *FileWriteTool) Spec() ToolSpec
type Preview ¶ added in v0.4.0
type Preview struct {
Description string `json:"description,omitempty"`
Diff string `json:"diff,omitempty"`
Command string `json:"command,omitempty"`
WorkDir string `json:"work_dir,omitempty"`
}
Preview contains the information shown to the user before approval.
type Previewer ¶ added in v0.4.0
Previewer is an optional interface that tools can implement to provide a preview of the proposed change before execution. This enables the approval-before-execution flow where the user sees a diff/command preview and approves before any filesystem changes are made.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *Registry
type Result ¶
type ShellExecTool ¶
type ShellExecTool struct {
Timeout time.Duration
WorkspaceRoot string
MaxOutputBytes int
// Guard applies secret redaction to output and surfaces advisory
// sensitive-path warnings in the approval preview. May be nil.
Guard *ShellGuard
}
func (*ShellExecTool) Execute ¶
func (s *ShellExecTool) Execute(ctx context.Context, args json.RawMessage) (Result, error)
func (*ShellExecTool) Preview ¶ added in v0.4.0
func (s *ShellExecTool) Preview(ctx context.Context, args json.RawMessage) (Preview, error)
Preview returns command execution metadata without running the command.
func (*ShellExecTool) RequiresApproval ¶
func (s *ShellExecTool) RequiresApproval() bool
func (*ShellExecTool) Spec ¶
func (s *ShellExecTool) Spec() ToolSpec
type ShellGuard ¶ added in v0.5.0
type ShellGuard struct {
// SensitiveMatcher identifies paths that should never be referenced by a
// shell command. May be nil, in which case only secret redaction applies.
SensitiveMatcher *ignore.SensitiveMatcher
// RedactSecretOutput disables redaction of secret-shaped values in output.
RedactSecretOutput bool
}
ShellGuard applies defense-in-depth filtering around shell_exec.
An arbitrary `sh -c` string cannot be reliably confined: command substitution, pipes, variables and interpreters can all reach outside the workspace no matter how the command line is inspected. GoCode therefore does not claim to sandbox the shell. What it can enforce is that secrets which come back on stdout/stderr are not handed to the model or written into a session transcript, and that commands referencing known-sensitive paths are surfaced in the approval preview so the user can decline them.
The file tools remain the hard boundary: those are genuinely confined to the workspace by ValidatePath and the sensitive-file matcher.
func (*ShellGuard) FlagSensitivePaths ¶ added in v0.5.0
func (g *ShellGuard) FlagSensitivePaths(command string) []string
FlagSensitivePaths returns the sensitive paths referenced by a shell command. This is advisory: it powers the approval preview, it does not block execution, because a shell string cannot be reliably confined.
func (*ShellGuard) RedactSecrets ¶ added in v0.5.0
func (g *ShellGuard) RedactSecrets(output string) (string, []string)
RedactSecrets replaces secret-shaped values in command output with a marker and returns the redacted text plus the set of pattern names that matched. With redaction disabled the text is returned unchanged.