commands

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPlan added in v0.4.0

func BuildPlan(plan capability.Plan, deps *Deps, reg *CommandRegistry)

BuildPlan is the only factory assembly path. Factory membership is keyed by capability identity; groups are selection metadata owned by descriptors.

func JoinCommandLine added in v0.4.0

func JoinCommandLine(name string, args []string) string

JoinCommandLine builds a command line that SplitCommandLine can losslessly parse. It is intended for trusted internal callers that already have args.

func Provide added in v0.4.0

func Provide[T any](d *Deps, key deps.Key[T], value T)

Provide stores a typed dependency, allocating the bag on first use so a literal-constructed Deps cannot drop it silently.

func RegisterFactory

func RegisterFactory(f Factory)

func SplitCommandLine

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

Types

type BashArgs

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

type BashExecOptions added in v0.4.0

type BashExecOptions struct {
	Name     string
	WorkDir  string
	Env      map[string]string
	Timeout  time.Duration
	OnOutput func([]byte)
	Stdin    io.Reader
	Stdout   io.Writer
	Stderr   io.Writer
}

BashExecOptions controls one foreground execution without mutating the BashTool defaults. Runner/WebAgent transports use this entry point while the agent-facing Execute method keeps its auto-background behavior.

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() *coretool.Definition

func (*BashTool) Description

func (t *BashTool) Description() string

func (*BashTool) Execute

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

func (*BashTool) Manager

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

func (*BashTool) Name

func (t *BashTool) Name() string

func (*BashTool) RunForeground added in v0.4.0

func (t *BashTool) RunForeground(ctx context.Context, command string, options BashExecOptions) (*Execution, error)

RunForeground executes command through the same tmux/registered-command router used by the bash agent tool, streams raw output, and waits for the final session state. Non-zero exits are represented by Info.ExitCode rather than returned as transport errors.

func (*BashTool) RunForegroundTool added in v0.4.0

func (t *BashTool) RunForegroundTool(ctx context.Context, command string, options BashExecOptions) (*coretool.Result, error)

RunForegroundTool executes a command in the foreground and returns the collected ToolResult (bounded text and media), streaming raw output through options.OnOutput. Transports that must not auto-background (AOP tool.call) use this instead of Execute.

func (*BashTool) SetCommandNames

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

func (*BashTool) SetCommandResolver added in v0.4.0

func (t *BashTool) SetCommandResolver(fn func(string) (Command, bool))

func (*BashTool) SetScannerProxy

func (t *BashTool) SetScannerProxy(proxy string)

func (*BashTool) Start added in v0.4.0

func (t *BashTool) Start(ctx context.Context, command string, options BashExecOptions) (*Execution, error)

Start resolves command through the built-in registry or the system shell and always returns an Execution backed by one PTY session.

func (*BashTool) WithScannerProxy

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

type Command

type Command struct {
	Name           string
	Usage          string
	QuickReference string
	// DescriptionPath points at the OKF markdown concept whose frontmatter
	// description is advertised to management and composer surfaces.
	DescriptionPath string
	Run             func(context.Context, *Execution) (any, error)
	SetProxy        func(string)
	GetProxy        func() string
	SetDefaultSpace func(string)
	Close           func()
}

Command describes one built-in command accepted by the Bash tool. Runtime state belongs to Execution; command-specific dependencies are captured by Run at construction time.

func NewTmuxCommand

func NewTmuxCommand(bash *BashTool) Command

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) ExecuteTool

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

func (*CommandRegistry) Get

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

func (*CommandRegistry) GetTool

func (r *CommandRegistry) GetTool(name string) (tool.Tool, 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 tool.Tool)

func (*CommandRegistry) Run added in v0.4.0

func (r *CommandRegistry) Run(ctx context.Context, tokens []string, parent *Execution) (details any, err error)

Run executes a nested built-in command inside an existing Execution. The child shares the outer PTY session and file descriptors; it does not create a second lifecycle or an ID-less execution.

func (*CommandRegistry) SetLogger added in v0.3.0

func (r *CommandRegistry) SetLogger(logger telemetry.Logger)

func (*CommandRegistry) ToolDefinitions

func (r *CommandRegistry) ToolDefinitions() []*tool.Definition

func (*CommandRegistry) Tools

func (r *CommandRegistry) Tools() []tool.Tool

func (*CommandRegistry) UsageDocs

func (r *CommandRegistry) UsageDocs() string

type Deps

type Deps struct {
	*deps.Bag

	WorkDir     string
	BashTimeout int
	SkillStore  SkillSource
	RunnerMode  bool

	Provider          provider.Provider
	ScannerProxy      string
	Logger            telemetry.Logger
	NodeName          string
	NodeMeta          map[string]any
	TavilyKeys        string // comma-separated Tavily API keys
	PlaywrightSession string
	DataBus           *eventbus.Bus[output.ToolDataEvent]
	Hooks             *hooks.Registry
}

Deps carries everything a Factory may need. Values whose type pkg/commands must not import (scanner engines, resources, IOA client, scan options) travel in the Bag under keys owned by their own package.

func (*Deps) GetLogger added in v0.2.7

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

func (*Deps) Skip added in v0.4.0

func (d *Deps) Skip(id, dep string)

Skip reports that a factory bailed out because a dependency is missing. It exists because these sites used to return silently, leaving the tool absent from the registry with nothing in the log to explain it.

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 Execution added in v0.4.0

type Execution struct {
	ID      string
	Command string
	Args    []string
	Dir     string
	Env     []string

	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer

	State     tmux.State
	ExitCode  int
	StartedAt time.Time
	EndedAt   time.Time
	KillCause string
	Details   any
	// contains filtered or unexported fields
}

Execution is one shell or built-in command invocation. Its ID is always the ID of the underlying PTY session, so existing tmux attach/read/write/kill operations continue to address the same runtime object.

func (*Execution) Duration added in v0.4.0

func (e *Execution) Duration() time.Duration

func (*Execution) Kill added in v0.4.0

func (e *Execution) Kill() error

func (*Execution) Wait added in v0.4.0

func (e *Execution) Wait(ctx context.Context) error

Wait waits for the PTY session. Canceling the wait also kills the session, matching the previous foreground Bash execution behavior.

type Factory

type Factory struct {
	Capability capability.ID
	Build      func(deps *Deps, reg *CommandRegistry)
}

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() *coretool.Definition

func (*GlobTool) Description

func (t *GlobTool) Description() string

func (*GlobTool) Execute

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

func (*GlobTool) Name

func (t *GlobTool) Name() string

type ListArgs added in v0.4.0

type ListArgs struct {
	Path string `json:"path,omitempty" jsonschema:"description=Directory path to list (absolute or relative to working directory; default: .)"`
}

type ListEntry added in v0.4.0

type ListEntry struct {
	Name        string `json:"name"`
	IsDirectory bool   `json:"isDirectory"`
	Size        int64  `json:"size"`
}

type ListResult added in v0.4.0

type ListResult struct {
	Path      string      `json:"path"`
	Entries   []ListEntry `json:"entries"`
	Truncated bool        `json:"truncated,omitempty"`
}

type ListTool added in v0.4.0

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

ListTool lists directory entries through the host filesystem API.

func NewListTool added in v0.4.0

func NewListTool(workDir string) *ListTool

func (*ListTool) Definition added in v0.4.0

func (t *ListTool) Definition() *coretool.Definition

func (*ListTool) Description added in v0.4.0

func (t *ListTool) Description() string

func (*ListTool) Execute added in v0.4.0

func (t *ListTool) Execute(ctx context.Context, arguments string) (*coretool.Result, error)

func (*ListTool) Name added in v0.4.0

func (t *ListTool) Name() string

type LoggerAware added in v0.3.0

type LoggerAware interface {
	InitLogger(telemetry.Logger)
}

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() *coretool.Definition

func (*ReadTool) Description

func (t *ReadTool) Description() string

func (*ReadTool) Execute

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

func (*ReadTool) Name

func (t *ReadTool) Name() string

type SkillSource added in v0.4.0

type SkillSource interface {
	VirtualFileReader
	VirtualGlobber
}

SkillSource is the slice of skills.Store the built-in tools need; declaring it here keeps pkg/commands from importing the skill store itself.

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 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() *coretool.Definition

func (*WriteTool) Description

func (t *WriteTool) Description() string

func (*WriteTool) Execute

func (t *WriteTool) Execute(ctx context.Context, arguments string) (*coretool.Result, 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