shell

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package shell provides an Eino-compatible shell execution tool.

The package intentionally exposes the execution boundary as configuration: callers own workspace containment, sandboxing, and environment policy.

Result preserves the original decoded JSON object in RawJSON so consumers can inspect unknown top-level fields added by future versions. RawJSON is never emitted when marshaling results produced by this package.

Index

Constants

View Source
const (
	// DefaultShellBinary preserves the current local-symphony shell behavior.
	DefaultShellBinary = "sh"

	// OutputCapBytes is the default per-stream stdout/stderr output cap.
	OutputCapBytes = 256 * 1024

	// DefaultOutputCapBytes aliases OutputCapBytes for constructor option
	// defaulting.
	DefaultOutputCapBytes = OutputCapBytes
)
View Source
const (
	// DefaultTimeoutSeconds is applied when timeout_seconds is omitted or zero.
	DefaultTimeoutSeconds = 60

	// MaxTimeoutSeconds is the maximum accepted per-call timeout.
	MaxTimeoutSeconds = 600
)
View Source
const (
	ErrCategoryValidation = "validation"
	ErrCategoryTimeout    = "timeout"
	ErrCategoryCanceled   = "canceled"
	ErrCategoryExecFailed = "exec_failed"
	ErrCategoryUnknown    = "unknown"
)
View Source
const Name = "shell"

Name is the model-facing tool name.

Variables

This section is empty.

Functions

func Schema

func Schema() json.RawMessage

Schema returns a fresh JSON Schema copy for shell arguments.

Types

type Args

type Args struct {
	Cmd            string `json:"cmd"`
	TimeoutSeconds int    `json:"timeout_seconds,omitempty"`
}

Args is the parsed input shape for the tool.

type Options

type Options struct {
	// Env is the process environment for commands. A nil slice inherits the
	// parent process environment, matching os/exec behavior.
	Env []string

	// ShellBinary is the executable used with "-lc". Empty uses
	// DefaultShellBinary.
	ShellBinary string

	// OutputCapBytes caps stdout and stderr independently. Zero uses
	// DefaultOutputCapBytes.
	OutputCapBytes int
}

Options configures shell tool behavior that is intentionally owned by the caller rather than hidden inside the tool.

type Result

type Result struct {
	Outcome         result.Outcome  `json:"outcome"`
	ExitCode        int             `json:"exit_code"`
	Stdout          string          `json:"stdout"`
	Stderr          string          `json:"stderr"`
	StdoutTruncated bool            `json:"stdout_truncated,omitempty"`
	StderrTruncated bool            `json:"stderr_truncated,omitempty"`
	DurationMS      int64           `json:"duration_ms"`
	TimedOut        bool            `json:"timed_out,omitempty"`
	Error           *ResultError    `json:"error,omitempty"`
	RawJSON         json.RawMessage `json:"-"`
}

Result is the structured envelope returned to the model.

func (Result) IsRetryable

func (r Result) IsRetryable() bool

IsRetryable reports whether the agent loop should retry the same call.

func (*Result) UnmarshalJSON

func (r *Result) UnmarshalJSON(raw []byte) error

UnmarshalJSON decodes Result and preserves the original object in RawJSON.

type ResultError

type ResultError struct {
	Category string `json:"category"`
	Message  string `json:"message"`
}

ResultError is the structured failure envelope nested inside Result.

type Tool

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

Tool executes shell commands in a configured workspace directory.

func New

func New(workspacePath string, opts ...Options) (*Tool, error)

New constructs a Tool from an absolute workspace path.

func (*Tool) Info

func (t *Tool) Info(_ context.Context) (*schema.ToolInfo, error)

Info returns the Eino ToolInfo for shell.

func (*Tool) InvokableRun

func (t *Tool) InvokableRun(ctx context.Context, argsJSON string, _ ...tool.Option) (string, error)

InvokableRun is the Eino tool entry point.

func (*Tool) Run

func (t *Tool) Run(ctx context.Context, args Args) Result

Run executes the tool with parsed args.

Jump to

Keyboard shortcuts

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