commands

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Output = &OutputWriter{w: io.Discard}

Output is the global output writer for commands. Commands write to it via fmt.Fprint(commands.Output, ...). The registry configures its destination before each execution.

Functions

func BuildAll

func BuildAll(deps *Deps, reg *CommandRegistry)

func BuildGroup

func BuildGroup(group string, deps *Deps, reg *CommandRegistry)

func ParseArgs

func ParseArgs[T any](arguments string) (T, error)

ParseArgs unmarshals the raw JSON arguments string into a typed struct.

func RegisterFactory

func RegisterFactory(f Factory)

func SchemaOf

func SchemaOf(proto any) map[string]any

SchemaOf generates a JSON Schema (as map[string]any) from a Go struct. Struct fields use standard tags:

json:"name"          → property name; omitempty marks the field as optional
jsonschema:"..."     → description, enum, etc. per invopop/jsonschema

Fields without omitempty are automatically added to the "required" list.

func SplitCommandLine

func SplitCommandLine(input string) ([]string, error)

Types

type AgentTool

type AgentTool interface {
	Name() string
	Description() string
	Definition() ToolDefinition
	Execute(ctx context.Context, arguments string) (ToolResult, error)
}

type BashArgs

type BashArgs struct {
	Command string `` /* 176-byte string literal not displayed */
}

type BashTool

type BashTool struct {
	// contains filtered or unexported fields
}

func NewBashTool

func NewBashTool(workDir string, timeout int) *BashTool

func (*BashTool) Close

func (t *BashTool) Close()

func (*BashTool) Definition

func (t *BashTool) Definition() ToolDefinition

func (*BashTool) Description

func (t *BashTool) Description() string

func (*BashTool) Execute

func (t *BashTool) Execute(ctx context.Context, arguments string) (ToolResult, error)

func (*BashTool) Manager

func (t *BashTool) Manager() *tmux.Manager

func (*BashTool) Name

func (t *BashTool) Name() string

func (*BashTool) SetCommandNames

func (t *BashTool) SetCommandNames(fn func() []string)

func (*BashTool) SetInbox

func (t *BashTool) SetInbox(ib inbox.Inbox)

func (*BashTool) SetScannerProxy

func (t *BashTool) SetScannerProxy(proxy string)

func (*BashTool) WithScannerProxy

func (t *BashTool) WithScannerProxy(proxy string) *BashTool

type Command

type Command interface {
	Name() string
	Usage() string
	Execute(ctx context.Context, args []string) error
}

type CommandRegistry

type CommandRegistry struct {
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry() *CommandRegistry

func (*CommandRegistry) All

func (r *CommandRegistry) All() []Command

func (*CommandRegistry) CloneTools

func (r *CommandRegistry) CloneTools() *CommandRegistry

func (*CommandRegistry) Execute

func (r *CommandRegistry) Execute(ctx context.Context, cmdLine string) (string, error)

func (*CommandRegistry) ExecuteArgs

func (r *CommandRegistry) ExecuteArgs(ctx context.Context, tokens []string) (string, error)

func (*CommandRegistry) ExecuteArgsStreaming

func (r *CommandRegistry) ExecuteArgsStreaming(ctx context.Context, tokens []string, stream io.Writer) (out string, err error)

func (*CommandRegistry) ExecuteTool

func (r *CommandRegistry) ExecuteTool(ctx context.Context, name, arguments string) (result ToolResult, err error)

func (*CommandRegistry) Get

func (r *CommandRegistry) Get(name string) (Command, bool)

func (*CommandRegistry) GetTool

func (r *CommandRegistry) GetTool(name string) (AgentTool, bool)

func (*CommandRegistry) GroupNames

func (r *CommandRegistry) GroupNames(group string) []string

func (*CommandRegistry) Has

func (r *CommandRegistry) Has(name string) bool

func (*CommandRegistry) Names

func (r *CommandRegistry) Names() []string

func (*CommandRegistry) Register

func (r *CommandRegistry) Register(cmd Command, group string)

func (*CommandRegistry) RegisterTool

func (r *CommandRegistry) RegisterTool(t AgentTool)

func (*CommandRegistry) SetOutput

func (r *CommandRegistry) SetOutput(w io.Writer)

func (*CommandRegistry) SetWorkDir

func (r *CommandRegistry) SetWorkDir(dir string)

func (*CommandRegistry) ToolDefinitions

func (r *CommandRegistry) ToolDefinitions() []ToolDefinition

func (*CommandRegistry) Tools

func (r *CommandRegistry) Tools() []AgentTool

func (*CommandRegistry) UsageDocs

func (r *CommandRegistry) UsageDocs() string

type ContentBlock

type ContentBlock struct {
	Type       string `json:"type"`
	Text       string `json:"text,omitempty"`
	MimeType   string `json:"mime_type,omitempty"`
	Base64Data string `json:"base64_data,omitempty"`
}

func ImageBlock

func ImageBlock(mimeType, base64Data string) ContentBlock

func TextBlock

func TextBlock(text string) ContentBlock

type Deps

type Deps struct {
	WorkDir     string
	BashTimeout int
	SkillStore  any

	EngineSet    any
	Resources    any
	IOAClient    any
	Provider     any
	ScannerProxy string
	ScanOpts     []any
	Logger       telemetry.Logger
	NodeName     string
	NodeMeta     map[string]any
	TavilyKeys   string // comma-separated Tavily API keys (build-time fallback)
}

func (*Deps) GetLogger added in v0.2.7

func (d *Deps) GetLogger() telemetry.Logger

type EditPatch

type EditPatch struct {
	OldText    string `` /* 141-byte string literal not displayed */
	NewText    string `json:"new_text"                jsonschema:"description=Replacement text for this edit."`
	ReplaceAll bool   `json:"replace_all,omitempty"   jsonschema:"description=Replace all occurrences of old_text instead of requiring uniqueness."`
}

type Factory

type Factory struct {
	Group string
	Build func(deps *Deps, reg *CommandRegistry)
}

type FunctionDefinition

type FunctionDefinition = provider.FunctionDefinition

type GlobArgs

type GlobArgs struct {
	Pattern string `` /* 143-byte string literal not displayed */
	Path    string `json:"path,omitempty" jsonschema:"description=Base directory for the search (default: working directory)"`
}

type GlobTool

type GlobTool struct {
	// contains filtered or unexported fields
}

func NewGlobTool

func NewGlobTool(workDir string, globbers ...VirtualGlobber) *GlobTool

func (*GlobTool) Definition

func (t *GlobTool) Definition() ToolDefinition

func (*GlobTool) Description

func (t *GlobTool) Description() string

func (*GlobTool) Execute

func (t *GlobTool) Execute(ctx context.Context, arguments string) (ToolResult, error)

func (*GlobTool) Name

func (t *GlobTool) Name() string

type OutputWriter

type OutputWriter struct {
	// contains filtered or unexported fields
}

func (*OutputWriter) Captured

func (o *OutputWriter) Captured() string

func (*OutputWriter) Reset

func (o *OutputWriter) Reset(w io.Writer)

func (*OutputWriter) Write

func (o *OutputWriter) Write(p []byte) (int, error)

type ReadArgs

type ReadArgs struct {
	Path   string `json:"path"            jsonschema:"description=File path to read (absolute or relative to working directory)"`
	Offset int    `json:"offset,omitempty" jsonschema:"description=1-indexed line number to start reading from (default: 1)"`
	Limit  int    `json:"limit,omitempty"  jsonschema:"description=Maximum number of lines to read (default: 2000)"`
}

type ReadTool

type ReadTool struct {
	// contains filtered or unexported fields
}

func NewReadTool

func NewReadTool(workDir string, readers ...VirtualFileReader) *ReadTool

func (*ReadTool) Definition

func (t *ReadTool) Definition() ToolDefinition

func (*ReadTool) Description

func (t *ReadTool) Description() string

func (*ReadTool) Execute

func (t *ReadTool) Execute(ctx context.Context, arguments string) (ToolResult, error)

func (*ReadTool) Name

func (t *ReadTool) Name() string

type TmuxCommand

type TmuxCommand struct {
	// contains filtered or unexported fields
}

func NewTmuxCommand

func NewTmuxCommand(mgr *tmux.Manager) *TmuxCommand

func (*TmuxCommand) Execute

func (t *TmuxCommand) Execute(ctx context.Context, args []string) error

func (*TmuxCommand) Name

func (t *TmuxCommand) Name() string

func (*TmuxCommand) Usage

func (t *TmuxCommand) Usage() string

type ToolDefinition

type ToolDefinition = provider.ToolDefinition

func ToolDef

func ToolDef(name, description string, argsProto any) ToolDefinition

ToolDef builds a complete ToolDefinition from a name, description, and an args struct prototype.

type ToolResult

type ToolResult struct {
	Content   []ContentBlock
	IsError   bool
	Terminate bool
}

func ErrorResult

func ErrorResult(msg string) ToolResult

func TerminateResult

func TerminateResult(s string) ToolResult

func TextResult

func TextResult(s string) ToolResult

func (ToolResult) HasImages

func (r ToolResult) HasImages() bool

func (ToolResult) Text

func (r ToolResult) Text() string

Text returns all text content blocks concatenated, for backward compatibility with code that expects a plain string.

type VirtualFileReader

type VirtualFileReader interface {
	ReadVirtual(path string) (content string, handled bool, err error)
}

type VirtualGlobber

type VirtualGlobber interface {
	GlobVirtual(pattern string) ([]string, bool)
}

type WorkDirAware

type WorkDirAware interface {
	SetWorkDir(dir string)
}

type WriteArgs

type WriteArgs struct {
	Path    string      `json:"path"             jsonschema:"description=File path to write or edit (absolute or relative to working directory)"`
	Content string      `json:"content,omitempty" jsonschema:"description=Full file content for write mode. Ignored when edits is provided."`
	Edits   []EditPatch `` /* 166-byte string literal not displayed */
}

type WriteTool

type WriteTool struct {
	// contains filtered or unexported fields
}

func NewWriteTool

func NewWriteTool(workDir string) *WriteTool

func (*WriteTool) Definition

func (t *WriteTool) Definition() ToolDefinition

func (*WriteTool) Description

func (t *WriteTool) Description() string

func (*WriteTool) Execute

func (t *WriteTool) Execute(ctx context.Context, arguments string) (ToolResult, error)

func (*WriteTool) Name

func (t *WriteTool) Name() string

Jump to

Keyboard shortcuts

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