shell

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package shell 提供 Shell/Bash 接缝与 tool-bash。

对齐上游:packages/shell/shell + bash-local + bash-sandbox + tool-bash(M37)

本文件实现:ShellExecRequest→Resolve→ShellExecSpec + RunResult(5 个正交字段: exitCode / signal / timedOut / aborted / timeoutMs)+ 前台运行(基于 pkg/subprocess, 64KB 截断 + spill 拿完整流)+ 后台 Job(基于 pkg/jobs)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatOutput

func FormatOutput(r *BashResult) string

FormatOutput 生成模型向文本(截断时引导读 spill)。

Types

type BashResult

type BashResult struct {
	// Output 内联输出(可能截断为 TAIL)。
	Output string `json:"output"`
	// Truncated 是否截断。
	Truncated bool `json:"truncated"`
	// SpillPath 完整流 spill 路径(截断时提供)。
	SpillPath string `json:"spillPath,omitempty"`
	// Result 运行事实。
	Result RunResult `json:"result"`
}

BashResult 是 tool-bash 的模型向结果。

type BashTool

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

BashTool 是工具实现(复用 Shell)。

func NewBashTool

func NewBashTool(sandboxMode string) *BashTool

NewBashTool 创建 bash 工具。

func (*BashTool) Exec

func (b *BashTool) Exec(req ExecRequest) (*BashResult, error)

Exec 执行命令并返回模型向结果。

type ExecRequest

type ExecRequest struct {
	// Command 待执行的命令字符串。
	Command string
	// Cwd 工作目录(空则继承)。
	Cwd string
	// TimeoutMs 超时毫秒;<=0 表示不超时。
	TimeoutMs int
	// Env 附加环境。
	Env map[string]string
}

ExecRequest 是一次 shell 执行请求。

type ExecSpec

type ExecSpec struct {
	// Argv shell 包装后的 argv(bash -c / cmd /c / powershell)。
	Argv []string
	// Cwd 工作目录。
	Cwd string
	// TimeoutMs 超时。
	TimeoutMs int
	// Env 附加环境。
	Env map[string]string
	// SandboxMode 生效沙箱模式(read-only/workspace-write/danger)。
	SandboxMode string
}

ExecSpec 是 resolve 后的完整执行规格。

type RunResult

type RunResult struct {
	// ExitCode 退出码;被信号杀死或异常时可能为 -1。
	ExitCode int    `json:"exitCode"`
	Signal   string `json:"signal,omitempty"`
	// TimedOut 是否因超时被强杀。
	TimedOut bool `json:"timedOut"`
	// Aborted 是否因取消被终止。
	Aborted bool `json:"aborted"`
	// TimeoutMs 本次运行的超时毫秒(0 表示未设超时)。
	TimeoutMs int `json:"timeoutMs"`
}

RunResult 是一次运行的结果(5 个正交字段)。

type Shell

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

Shell 是 shell 执行器。

func New

func New(sandboxMode string) *Shell

New 创建 shell 执行器(sandbox 传 read-only/workspace-write/danger;空默认 workspace-write)。

func (*Shell) Resolve

func (s *Shell) Resolve(req ExecRequest) ExecSpec

Resolve 把命令解析为执行规格。

func (*Shell) Run

func (s *Shell) Run(req ExecRequest) (RunResult, BashResult, error)

Run 前台执行并等待结果,返回结果 + 收集输出。

Jump to

Keyboard shortcuts

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