Documentation
¶
Index ¶
- Constants
- Variables
- func AuditDigest(content []byte) string
- func BuildPlan(plan capability.Plan, deps *Deps, reg *CommandRegistry)
- func JoinCommandLine(name string, args []string) string
- func Provide[T any](d *Deps, key deps.Key[T], value T)
- func RegisterFactory(f Factory)
- func SplitCommandLine(input string) ([]string, error)
- type AuditChange
- type AuditOptions
- type AuditSnapshot
- type BashArgs
- type BashExecOptions
- type BashTool
- func (t *BashTool) Close()
- func (t *BashTool) Definition() *coretool.Definition
- func (t *BashTool) Description() string
- func (t *BashTool) Execute(ctx context.Context, arguments string) (*coretool.Result, error)
- func (t *BashTool) Manager() *tmux.Manager
- func (t *BashTool) Name() string
- func (t *BashTool) RunForeground(ctx context.Context, command string, options BashExecOptions) (*Execution, error)
- func (t *BashTool) RunForegroundTool(ctx context.Context, command string, options BashExecOptions) (*coretool.Result, error)
- func (t *BashTool) SetCommandNames(fn func() []string)
- func (t *BashTool) SetCommandResolver(fn func(string) (Command, bool))
- func (t *BashTool) SetEgressResolver(fn func(callID string) (string, string))
- func (t *BashTool) SetScannerProxy(proxy string)
- func (t *BashTool) SetScannerProxyCA(caPath string)
- func (t *BashTool) Start(ctx context.Context, command string, options BashExecOptions) (*Execution, error)
- func (t *BashTool) WithAudit(audit *FileAudit) *BashTool
- func (t *BashTool) WithEgressResolver(fn func(callID string) (string, string)) *BashTool
- func (t *BashTool) WithScannerProxy(proxy string) *BashTool
- func (t *BashTool) WithScannerProxyCA(caPath string) *BashTool
- type Command
- type CommandRegistry
- func (r *CommandRegistry) All() []Command
- func (r *CommandRegistry) ExecuteBashForeground(ctx context.Context, command string, options BashExecOptions) (*tool.Result, error)
- func (r *CommandRegistry) ExecuteTool(ctx context.Context, name, arguments string) (*tool.Result, error)
- func (r *CommandRegistry) Get(name string) (Command, bool)
- func (r *CommandRegistry) GetTool(name string) (tool.Tool, bool)
- func (r *CommandRegistry) GroupNames(group string) []string
- func (r *CommandRegistry) Has(name string) bool
- func (r *CommandRegistry) Names() []string
- func (r *CommandRegistry) Register(cmd Command, group string)
- func (r *CommandRegistry) RegisterTool(t tool.Tool)
- func (r *CommandRegistry) Run(ctx context.Context, tokens []string, parent *Execution) (details any, err error)
- func (r *CommandRegistry) SetLogger(logger telemetry.Logger)
- func (r *CommandRegistry) ToolDefinitions() []*tool.Definition
- func (r *CommandRegistry) Tools() []tool.Tool
- func (r *CommandRegistry) UsageDocs() string
- type Deps
- type EditPatch
- type Execution
- type Factory
- type FileAudit
- func (a *FileAudit) Around(ctx context.Context, workDir string, fn func() error) error
- func (a *FileAudit) Close()
- func (a *FileAudit) Configure(config *filepb.WatchConfig)
- func (a *FileAudit) Enabled() bool
- func (a *FileAudit) Options() AuditOptions
- func (a *FileAudit) Record(ctx context.Context, access *filepb.Access)
- func (a *FileAudit) RecordFile(ctx context.Context, op filepb.AccessOp, path string, access *filepb.Access)
- func (a *FileAudit) State() *filepb.WatchState
- func (a *FileAudit) Subscribe(handler func(*filepb.Access)) func()
- type GlobArgs
- type GlobTool
- type ListArgs
- type ListEntry
- type ListResult
- type ListTool
- type LoggerAware
- type ReadArgs
- type ReadTool
- type SkillSource
- type VirtualFileReader
- type VirtualGlobber
- type WriteArgs
- type WriteTool
Constants ¶
const ( // DefaultAuditMaxEntries bounds one snapshot walk. A work dir larger than // this is not diffed at all — see TakeSnapshot. DefaultAuditMaxEntries = 20000 )
Variables ¶
var DefaultAuditIgnore = []string{".git", "node_modules", ".cairn", "__pycache__", ".venv"}
DefaultAuditIgnore are the path segments a snapshot never walks: the directories where a build or a checkout produces thousands of changes that say nothing about what the agent was doing.
Functions ¶
func AuditDigest ¶
AuditDigest is the content hash carried by a write observation. It is what lets a consumer tell a rewrite that changed nothing from one that changed everything, without storing either version.
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
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
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 ¶
Types ¶
type AuditChange ¶
AuditChange is one difference between two snapshots.
func DiffSnapshots ¶
func DiffSnapshots(before, after AuditSnapshot) []AuditChange
DiffSnapshots reports what happened to the work dir between two snapshots, sorted by path so the same pair always produces the same sequence.
A file present in both is reported only when its size or modification time moved. That misses a rewrite that restored the previous bytes within the filesystem's timestamp resolution — the price of not hashing every file in the tree twice per command.
type AuditOptions ¶
AuditOptions is the snapshot and reporting policy. A peer sets it at runtime through the file namespace's Configure.
type AuditSnapshot ¶
type AuditSnapshot map[string]auditEntry
AuditSnapshot is a work dir's regular files at one moment, keyed by absolute path.
func TakeSnapshot ¶
func TakeSnapshot(root string, options AuditOptions) (AuditSnapshot, error)
TakeSnapshot walks root and records every regular file it is willing to look at.
It returns an error rather than a partial listing when the tree exceeds MaxEntries: a diff against a truncated snapshot invents a deletion for every file that fell off the end, and a wrong audit trail is worse than an absent one. The caller reports the refusal instead.
type BashArgs ¶
type BashArgs struct {
Command string `` /* 176-byte string literal not displayed */
Wait int `` /* 217-byte string literal not displayed */
Timeout int `` /* 245-byte string literal not displayed */
// contains filtered or unexported fields
}
func (BashArgs) TimeoutSpecified ¶
func (*BashArgs) UnmarshalJSON ¶
UnmarshalJSON preserves the distinction between an omitted timeout (use the tool default) and an explicit timeout of zero (no command deadline).
type BashExecOptions ¶ added in v0.4.0
type BashExecOptions struct {
Name string
WorkDir string
Env map[string]string
Timeout time.Duration
TimeoutSet bool
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 applies the explicit wait/background contract.
type BashTool ¶
type BashTool struct {
// contains filtered or unexported fields
}
func NewBashTool ¶
func (*BashTool) Definition ¶
func (t *BashTool) Definition() *coretool.Definition
func (*BashTool) Description ¶
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 remain foreground (AOP tool.call) use this instead of Execute.
func (*BashTool) SetCommandNames ¶
func (*BashTool) SetCommandResolver ¶ added in v0.4.0
func (*BashTool) SetEgressResolver ¶
func (*BashTool) SetScannerProxy ¶
func (*BashTool) SetScannerProxyCA ¶
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) WithAudit ¶
WithAudit attaches the file-access audit trail. Shell commands are the one place the runtime cannot observe a file access directly, so what this buys is the work dir diff taken around every execution.
func (*BashTool) WithEgressResolver ¶
func (*BashTool) WithScannerProxy ¶
func (*BashTool) WithScannerProxyCA ¶
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 ¶
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) ExecuteBashForeground ¶
func (r *CommandRegistry) ExecuteBashForeground(ctx context.Context, command string, options BashExecOptions) (*tool.Result, error)
ExecuteBashForeground runs the transport-facing Bash path through the same panic boundary as ordinary tool execution.
func (*CommandRegistry) ExecuteTool ¶
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
ScannerProxyCA string // CA PEM path for the MITM hub; injected so children trust intercepted HTTPS
// EgressResolver, when set, supersedes ScannerProxy/ScannerProxyCA per
// execution: given the current tool-call id it returns the proxy URL (with
// the id as the proxy username, so captured flows attribute to it) and the
// CA path from live hub state (empty while the hub is not intercepting).
EgressResolver func(callID string) (proxyURL, caPath string)
Logger telemetry.Logger
NodeName string
NodeMeta map[string]any
TavilyKeys string // comma-separated Tavily API keys
PlaywrightSession string
Events aop.EventEmitter
Hooks *hooks.Registry
// FileAudit collects what the file tools and shell executions did to the
// filesystem. Nil leaves them unobserved.
FileAudit *FileAudit
}
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.
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.
type Factory ¶
type Factory struct {
Capability capability.ID
Build func(deps *Deps, reg *CommandRegistry)
}
type FileAudit ¶
type FileAudit struct {
// contains filtered or unexported fields
}
FileAudit is the runtime's file-access audit trail: what the agent read, what it wrote, and what its shell commands left behind.
An agent that operates on a machine is answerable for what it touched there, and a tool call alone does not say it. This type is where the tools in this package report that, and it publishes each observation as an aop.file.Access so the file namespace answers both "operate on this file" and "who touched it" — one mechanism rather than two.
Recording is off the critical path by construction: it is non-blocking and lossy under pressure. A file access must never be slower because someone is watching, so a full queue drops the observation and counts it.
Coverage is honest rather than complete. Tool-level records are exact. Shell executions are covered by diffing the work dir around them (Around), which sees every write but no read at all — an unmodified read leaves nothing behind to find. That difference is on the wire as AccessSource.
A nil *FileAudit is a working no-op, so a runtime that never wired one up costs nothing and no call site needs a nil check.
func NewFileAudit ¶
func NewFileAudit() *FileAudit
NewFileAudit starts an audit trail. Nothing is published until something subscribes, and subscribers see every observation recorded after they attach.
func (*FileAudit) Around ¶
Around brackets fn with two snapshots of workDir and records the difference as SNAPSHOT observations attributed to the invocation in ctx.
What it cannot do is separate the command's own writes from anything else that changed the work dir while it ran — a detached session, a background build — which is exactly what AccessSource SNAPSHOT tells a consumer.
func (*FileAudit) Close ¶
func (a *FileAudit) Close()
Close stops the publisher and waits for queued observations to drain.
func (*FileAudit) Configure ¶
func (a *FileAudit) Configure(config *filepb.WatchConfig)
Configure applies a peer's watch policy. A nil config restores the defaults, which is what a peer that asked to observe with no opinion should get.
func (*FileAudit) Options ¶
func (a *FileAudit) Options() AuditOptions
Options returns the active policy. Callers about to do expensive work — a snapshot walk above all — check Enabled first.
func (*FileAudit) Record ¶
Record publishes one observation. The caller supplies what it knows; identity, timing and the invocation context are filled in here so no call site has to remember them. It never blocks.
func (*FileAudit) RecordFile ¶
func (a *FileAudit) RecordFile(ctx context.Context, op filepb.AccessOp, path string, access *filepb.Access)
RecordFile reports one exact, tool-level access. The size is read from the file unless the caller already knows it.
func (*FileAudit) State ¶
func (a *FileAudit) State() *filepb.WatchState
State is the reply a peer gets to Configure. Dropped rides along so a consumer can say the trail has a hole in it rather than presenting a short history as a complete one.
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 ¶
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 ListResult ¶ added in v0.4.0
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 (*ListTool) Definition ¶ added in v0.4.0
func (t *ListTool) Definition() *coretool.Definition
func (*ListTool) Description ¶ added in v0.4.0
type LoggerAware ¶ added in v0.3.0
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 ¶
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 VirtualGlobber ¶
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 (*WriteTool) Definition ¶
func (t *WriteTool) Definition() *coretool.Definition