execution

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package execution 提供 XOps v2 纯函数领域核的命令执行计划、多方言安全引用与执行结果代数和类型。

本包恪守 100% 纯数学与零副作用铁律(零 os、零 net、零 context、零 sync/sync/atomic、零反射):

  • LaunchProfile / LaunchDialect / Interpreter / LoginMode:显式区分服务端直通(server)与 受控解释器(sh/bash/zsh/powershell/pwsh/cmd),以及登录模式与 POSIX Bourne 强校验(INV-E4);
  • CommandPlan:不可变命令/脚本执行计划,承载工作目录(pathalg.RemotePath)、环境变量校验、 algebraic.Duration 超时、输出上限、零反射 //xops:canonicalhash 规范摘要、多方言无 OS 引用渲染与脱敏摘要;
  • ExecutionOutcome 与 ExitStatus:封闭代数和类型(RFC §3.6),严格保证仅有效 *OutcomeNotStarted 允许重试(CanRetry() == true),*OutcomeCompleted 与 *OutcomeUnknown 及零值/nil 恒不可重试。

Index

Constants

View Source
const (
	// DefaultMaxOutputBytes 表示未显式指定输出上限时的默认命令输出截断上限(4 MiB)。
	DefaultMaxOutputBytes uint64 = 4 << 20
	// MaxAllowedOutputBytes 表示单次命令计划允许配置的最大输出上限(64 MiB)。
	MaxAllowedOutputBytes uint64 = 64 << 20
)

Variables

View Source
var (
	ErrInvalidLaunchDialect            = errors.New("execution: 无效的启动方言 LaunchDialect")
	ErrInvalidInterpreter              = errors.New("execution: 无效的解释器 Interpreter")
	ErrInvalidLoginMode                = errors.New("execution: 无效的登录模式 LoginMode")
	ErrInvalidLaunchProfile            = errors.New("execution: 无效的启动配置 LaunchProfile")
	ErrUnsupportedExecutionCombination = errors.New("execution: 不支持的启动方言、解释器、登录模式或工作目录组合")
	ErrNotPOSIXBourne                  = errors.New("execution: 当前启动配置不满足 POSIX Bourne 解释器要求")
	ErrInvalidPlanKind                 = errors.New("execution: 无效的计划类型 PlanKind")
	ErrInvalidCommandPlan              = errors.New("execution: 无效的命令执行计划 CommandPlan")
	ErrInvalidEnvVar                   = errors.New("execution: 无效的环境变量键值")
	ErrInvalidShellQuote               = errors.New("execution: 无法对包含非法控制字符或不可转义序列的文本进行安全引用")
	ErrInvalidPhase                    = errors.New("execution: 无效的执行阶段枚举")
	ErrInvalidExitStatus               = errors.New("execution: 无效的退出状态 ExitStatus")
	ErrInvalidExecutionOutcome         = errors.New("execution: 无效的执行结果 ExecutionOutcome")
	ErrNilWriter                       = errors.New("execution: WriteCanonical 或编码目标不能为 nil")
	ErrNilReceiver                     = errors.New("execution: 反序列化目标接收者不能为 nil")
)

本包导出的规范哨兵错误,所有非法组合、越界输入、JSON null 及零值调用均严格失败关闭。

Functions

func CanRetryOutcome

func CanRetryOutcome(o ExecutionOutcome) bool

CanRetryOutcome 穷尽判定任意 ExecutionOutcome 是否允许安全重试;仅有效 *OutcomeNotStarted 返回 true。

func EncodePowerShellUTF16LEBase64

func EncodePowerShellUTF16LEBase64(script string) (string, error)

EncodePowerShellUTF16LEBase64 将 PowerShell 脚本文本编码为标准 UTF-16LE Base64, 供 powershell.exe / pwsh 的 -EncodedCommand 参数安全传递(彻底隔离外层 POSIX/cmd 引号解析)。

func EqualExitStatus

func EqualExitStatus(a, b ExitStatus) bool

EqualExitStatus 严格比较两个 ExitStatus 是否均有效且完全一致(nil 或零值恒返回 false)。

func EqualOutcome

func EqualOutcome(a, b ExecutionOutcome) bool

EqualOutcome 严格比较两个 ExecutionOutcome 是否均有效且完全一致(nil 或零值恒返回 false)。

func MarshalExitStatusTo

func MarshalExitStatusTo(enc *jsontext.Encoder, status ExitStatus) error

MarshalExitStatusTo 将任意有效 ExitStatus 编码至 Go 1.27 JSON/v2 流;nil 或无效零值失败关闭。

func MarshalOutcomeTo

func MarshalOutcomeTo(enc *jsontext.Encoder, outcome ExecutionOutcome) error

MarshalOutcomeTo 将任意有效 ExecutionOutcome 编码至 Go 1.27 JSON/v2 流;nil 或无效零值失败关闭。

func QuoteCmdArg

func QuoteCmdArg(arg string) (string, error)

QuoteCmdArg 对 Windows cmd.exe 参数执行保守失败关闭引用。 由于 cmd.exe 对换行、%VAR%、!VAR! 与元字符存在不可安全屏蔽的二次展开风险, 本函数严格拒绝换行、控制/Cf 字符与危险元字符;当含空白/逗号/分号/等号需加双引号时, 同步拒绝尾部反斜杠以防 Win32 CommandLineToArgvW 将 \" 解释为转义引号。

func QuotePOSIX

func QuotePOSIX(arg string) (string, error)

QuotePOSIX 使用 POSIX 单引号规则对单个参数执行无 OS 依赖的安全引用。 拒绝 NUL、非法 UTF-8、控制字符(允许 \n/\r/\t)及 Unicode Cf/Bidi 字符;空串编码为 ””。

func QuotePowerShell

func QuotePowerShell(arg string) (string, error)

QuotePowerShell 使用 PowerShell 单引号字面量规则对参数安全引用。 除拒绝 NUL/非法 UTF-8/控制/Cf 字符外,还将 ASCII 单引号与 PowerShell 解析器视作等价引号的 Unicode 弯引号(U+2018..U+201B)一并拒绝或转义,阻断引号逃逸注入。

Types

type CommandPlan

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

CommandPlan 表示经过完整校验与规范排序的不可变远端命令/脚本执行计划; 零值恒无效,且经 //xops:canonicalhash 由 xopsvet/digestcover 校验 WriteCanonical 全字段覆盖。

func NewCommandPlan

func NewCommandPlan(spec CommandPlanSpec) (CommandPlan, error)

NewCommandPlan 校验执行配置、命令/参数载荷、工作目录、环境变量、超时与输出上限,构造不可变 CommandPlan。

func (CommandPlan) Argv

func (p CommandPlan) Argv() []string

Argv 返回参数向量的防御性拷贝(纯 command 模式或无位置参数脚本返回 nil)。

func (CommandPlan) CanonicalJSON

func (p CommandPlan) CanonicalJSON() ([]byte, error)

CanonicalJSON 使用 Go 1.27 encoding/json/v2 Deterministic(true) 编码确定性 JSON。

func (CommandPlan) Command

func (p CommandPlan) Command() string

Command 返回原始命令或脚本文本(argv 模式下为空串)。

func (CommandPlan) Digest

func (p CommandPlan) Digest() (security.Digest, error)

Digest 计算并返回 CommandPlan 的确定性 SHA-256 规范摘要(直接兼容 security.OperationBinding)。

func (CommandPlan) Env

func (p CommandPlan) Env() map[string]string

Env 返回环境变量映射的全新拷贝,隔离外部修改。

func (CommandPlan) EnvValue

func (p CommandPlan) EnvValue(key string) (string, bool)

EnvValue 按键二分查找单个环境变量值;无效计划或键不存在返回 ("", false)。

func (CommandPlan) Equal

func (p CommandPlan) Equal(other CommandPlan) bool

Equal 严格比对两个 CommandPlan 是否均有效且全部字段完全一致(无效零值永不相等)。

func (CommandPlan) IsValid

func (p CommandPlan) IsValid() bool

IsValid 报告 CommandPlan 是否经构造器合法初始化。

func (CommandPlan) IsZero

func (p CommandPlan) IsZero() bool

IsZero 报告 CommandPlan 是否为无效零值。

func (CommandPlan) Kind

func (p CommandPlan) Kind() PlanKind

Kind 返回计划操作类型。

func (CommandPlan) MarshalJSONTo

func (p CommandPlan) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者);对零值失败关闭。

func (CommandPlan) MaxOutputBytes

func (p CommandPlan) MaxOutputBytes() uint64

MaxOutputBytes 返回输出字节上限;无效零值返回 0。

func (CommandPlan) PTY

func (p CommandPlan) PTY() bool

PTY 报告是否请求分配伪终端。

func (CommandPlan) Profile

func (p CommandPlan) Profile() LaunchProfile

Profile 返回启动配置副本。

func (CommandPlan) RedactedSummary

func (p CommandPlan) RedactedSummary() string

RedactedSummary 返回单行脱敏展示摘要(绝不暴露环境变量值与内联凭据)。

func (CommandPlan) RenderCommand

func (p CommandPlan) RenderCommand() (string, error)

RenderCommand 按启动方言、解释器、登录模式、工作目录与环境变量确定性渲染远端执行命令行(零 OS 调用)。 对于 PlanKindScript,RenderCommand 输出目标解释器标准输入消费命令:

  • POSIX:无位置参数时为 "<interp> [-l] -s",携带位置参数 Argv 时为 "<interp> [-l] -s -- <QuotePOSIX(arg)...>";
  • PowerShell:恒为 "<exe> -NoProfile -NonInteractive -Command -",前言、脚本正文与位置参数均经 StdinPayload() 投递。

func (CommandPlan) StdinPayload

func (p CommandPlan) StdinPayload() (string, bool)

StdinPayload 返回需要经远端 stdin 投递的脚本完整载荷(含在目标解释器内执行的 WorkDir/Env 前言与脚本正文; PowerShell 携带位置参数 Argv 时以 "& {\n<script>\n} <QuotePowerShell(arg)...>" 形式安全传参)。 PlanKindCommand 或无效零值恒返回 ("", false),实现 (RenderCommand, StdinPayload) 显式统一执行契约。

func (CommandPlan) Timeout

Timeout 返回可选执行超时(algebraic.Duration)。

func (*CommandPlan) UnmarshalJSONFrom

func (p *CommandPlan) UnmarshalJSONFrom(dec *jsontext.Decoder) error

UnmarshalJSONFrom 实现 encoding/json/v2.UnmarshalerFrom;对 JSON null、缺失必需字段或非法值失败关闭。

func (CommandPlan) WorkDir

WorkDir 返回可选远端 POSIX 工作目录。

func (CommandPlan) WriteCanonical

func (p CommandPlan) WriteCanonical(w io.Writer) error

WriteCanonical 以零反射、长度前缀与域分离方式将 CommandPlan 全字段写入 w(受 digestcover 校验)。

type CommandPlanSpec

type CommandPlanSpec struct {
	Kind           PlanKind
	Profile        LaunchProfile
	Command        string
	Argv           []string
	WorkDir        algebraic.Option[pathalg.RemotePath]
	Env            map[string]string
	Timeout        algebraic.Option[algebraic.Duration]
	MaxOutputBytes algebraic.Option[uint64]
	PTY            bool
}

CommandPlanSpec 是构造不可变 CommandPlan 的显式入参规格。 PlanKindCommand 要求 Command 与 Argv 二选一且互斥;PlanKindScript 要求非空脚本文本 Command,并允许附带可选位置参数 Argv; MaxOutputBytes 未设置时取 DefaultMaxOutputBytes,显式 Some(0) 失败关闭。

type ExecPhase

type ExecPhase uint8

ExecPhase 标识请求已发送后执行结果陷入未知的运行阶段;零值 ExecPhaseUnknown 失败关闭。

const (
	ExecPhaseUnknown       ExecPhase = iota // 未知阶段(零值失败关闭)
	ExecPhaseRequestSent                    // 启动请求已发出但未收到确定响应
	ExecPhaseRunning                        // 远端进程运行期间失联或中止
	ExecPhaseWaitingExit                    // 已进入退出等待阶段但未收到终止帧
	ExecPhaseTransportLost                  // 底层 SSH 传输断开或被拆断
	ExecPhaseTimedOut                       // 执行超时(远端进程可能仍在运行)
	ExecPhaseCanceled                       // 本地主动取消(无法证明远端已终止)
)

func ParseExecPhase

func ParseExecPhase(raw string) (ExecPhase, error)

ParseExecPhase 严格解析规范小写执行阶段文本。

func (ExecPhase) AppendText

func (p ExecPhase) AppendText(b []byte) ([]byte, error)

func (ExecPhase) IsValid

func (p ExecPhase) IsValid() bool

func (ExecPhase) IsZero

func (p ExecPhase) IsZero() bool

func (ExecPhase) MarshalText

func (p ExecPhase) MarshalText() ([]byte, error)

func (ExecPhase) String

func (p ExecPhase) String() string

func (*ExecPhase) UnmarshalText

func (p *ExecPhase) UnmarshalText(text []byte) error

type ExecutionOutcome

type ExecutionOutcome interface {
	Kind() OutcomeKind
	CanRetry() bool
	IsValid() bool
	// contains filtered or unexported methods
}

ExecutionOutcome 是命令执行终态的封闭代数和类型(RFC §3.6 / INV-C6): 仅含三个具体变体 *OutcomeNotStarted、*OutcomeCompleted 与 *OutcomeUnknown; 严格不变量:CanRetry() 仅对有效 *OutcomeNotStarted 返回 true,其余一律失败关闭返回 false。

func UnmarshalOutcomeFrom

func UnmarshalOutcomeFrom(dec *jsontext.Decoder) (ExecutionOutcome, error)

UnmarshalOutcomeFrom 从 Go 1.27 JSON/v2 流严格解码多态 ExecutionOutcome; 对 JSON null、缺失必需字段或跨变体混用字段一律失败关闭。

type ExitCode

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

ExitCode 表示远端显式回报的整数退出码(兼容 POSIX 0..255 与 Windows int32 退出码)。

func NewExitCode

func NewExitCode(code int32) *ExitCode

NewExitCode 构造携带显式退出码的不可变 *ExitCode。

func (*ExitCode) Code

func (e *ExitCode) Code() (int32, bool)

Code 返回退出码与有效性标志;无效零值返回 (0, false) 以防与退出码 0 混淆。

func (*ExitCode) IsSuccess

func (e *ExitCode) IsSuccess() bool

IsSuccess 当且仅当有效且退出码显式为 0 时返回 true。

func (*ExitCode) IsValid

func (e *ExitCode) IsValid() bool

IsValid 报告 *ExitCode 是否经构造器合法初始化。

func (*ExitCode) Kind

func (e *ExitCode) Kind() ExitStatusKind

Kind 有效时返回 ExitStatusKindCode,无效时失败关闭返回 ExitStatusKindInvalid。

func (ExitCode) MarshalJSONTo

func (e ExitCode) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 为 ExitCode、ExitSignal、ExitUnknown 提供值接收者 json/v2 编码(零值失败关闭)。

type ExitSignal

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

ExitSignal 表示远端进程因 POSIX 信号终止(RFC 4254 exit-signal)。

func NewExitSignal

func NewExitSignal(signal string, coreDumped bool, message string) (*ExitSignal, error)

NewExitSignal 校验信号名称(长度 1..32 的大写 ASCII 信号标识)并构造 *ExitSignal。

func (*ExitSignal) CoreDumped

func (e *ExitSignal) CoreDumped() bool

CoreDumped 报告服务端是否声明产生了 core dump。

func (*ExitSignal) IsSuccess

func (*ExitSignal) IsSuccess() bool

IsSuccess 信号终止恒返回 false。

func (*ExitSignal) IsValid

func (e *ExitSignal) IsValid() bool

IsValid 报告 *ExitSignal 是否有效。

func (*ExitSignal) Kind

func (e *ExitSignal) Kind() ExitStatusKind

Kind 有效时返回 ExitStatusKindSignal,无效时返回 ExitStatusKindInvalid。

func (ExitSignal) MarshalJSONTo

func (e ExitSignal) MarshalJSONTo(enc *jsontext.Encoder) error

func (*ExitSignal) Message

func (e *ExitSignal) Message() string

Message 返回经脱敏的信号终止附加说明。

func (*ExitSignal) Signal

func (e *ExitSignal) Signal() string

Signal 返回规范化信号名(如 "KILL"、"TERM");无效返回空串。

type ExitStatus

type ExitStatus interface {
	Kind() ExitStatusKind
	IsValid() bool
	IsSuccess() bool
	// contains filtered or unexported methods
}

ExitStatus 是命令终止状态的封闭代数和类型(*ExitCode | *ExitSignal | *ExitUnknown)。 缺失退出状态绝不等价于退出码 0;仅有效 *ExitCode(0) 的 IsSuccess() 为 true。

func UnmarshalExitStatusFrom

func UnmarshalExitStatusFrom(dec *jsontext.Decoder) (ExitStatus, error)

UnmarshalExitStatusFrom 从 Go 1.27 JSON/v2 流严格解码多态 ExitStatus;null/缺失字段/串用字段均失败关闭。

type ExitStatusKind

type ExitStatusKind uint8

ExitStatusKind 标识 ExitStatus 的判别类别;零值 ExitStatusKindInvalid 失败关闭。

const (
	ExitStatusKindInvalid ExitStatusKind = iota // 无效退出状态(零值失败关闭)
	ExitStatusKindCode                          // 显式整数退出码(*ExitCode)
	ExitStatusKindSignal                        // 信号终止(*ExitSignal)
	ExitStatusKindUnknown                       // 远端关闭通道但未回报退出码或信号(*ExitUnknown)
)

func ParseExitStatusKind

func ParseExitStatusKind(raw string) (ExitStatusKind, error)

ParseExitStatusKind 严格解析退出状态类别("code"、"signal"、"unknown")。

func (ExitStatusKind) AppendText

func (k ExitStatusKind) AppendText(b []byte) ([]byte, error)

AppendText 实现 encoding.TextAppender(值接收者);对非法值失败关闭。

func (ExitStatusKind) IsValid

func (k ExitStatusKind) IsValid() bool

IsValid 报告 k 是否为合法退出状态类别。

func (ExitStatusKind) IsZero

func (k ExitStatusKind) IsZero() bool

IsZero 报告 k 是否为无效零值。

func (ExitStatusKind) MarshalText

func (k ExitStatusKind) MarshalText() ([]byte, error)

MarshalText 实现 encoding.TextMarshaler(值接收者)。

func (ExitStatusKind) String

func (k ExitStatusKind) String() string

String 返回退出状态类别的规范小写文本。

func (*ExitStatusKind) UnmarshalText

func (k *ExitStatusKind) UnmarshalText(text []byte) error

UnmarshalText 实现 encoding.TextUnmarshaler;失败时重置为 ExitStatusKindInvalid 并失败关闭。

type ExitUnknown

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

ExitUnknown 表示远端会话结束但未回报退出码或信号(例如缺失 exit-status 帧)。

func NewExitUnknown

func NewExitUnknown(reason string) *ExitUnknown

NewExitUnknown 构造携带脱敏原因说明的 *ExitUnknown。

func (*ExitUnknown) IsSuccess

func (*ExitUnknown) IsSuccess() bool

IsSuccess 未知退出状态恒返回 false(绝不将缺失退出码推断为成功)。

func (*ExitUnknown) IsValid

func (e *ExitUnknown) IsValid() bool

IsValid 报告 *ExitUnknown 是否有效。

func (*ExitUnknown) Kind

func (e *ExitUnknown) Kind() ExitStatusKind

Kind 有效时返回 ExitStatusKindUnknown,无效时返回 ExitStatusKindInvalid。

func (ExitUnknown) MarshalJSONTo

func (e ExitUnknown) MarshalJSONTo(enc *jsontext.Encoder) error

func (*ExitUnknown) Reason

func (e *ExitUnknown) Reason() string

Reason 返回脱敏原因文本;无效返回空串。

type Interpreter

type Interpreter uint8

Interpreter 表示命令或脚本执行时使用的远端解释器;零值 InterpreterInvalid 失败关闭。

const (
	InterpreterInvalid    Interpreter = iota // 无效解释器(零值失败关闭)
	InterpreterServer                        // 服务端默认直通(原样发送 SSH exec 载荷)
	InterpreterSH                            // POSIX /bin/sh 解释器
	InterpreterBash                          // GNU Bash 解释器
	InterpreterZsh                           // Zsh 解释器
	InterpreterPowerShell                    // Windows powershell.exe
	InterpreterPwsh                          // 跨平台 PowerShell Core (pwsh)
	InterpreterCmd                           // Windows cmd.exe
)

func ParseInterpreter

func ParseInterpreter(raw string) (Interpreter, error)

ParseInterpreter 严格解析规范解释器标识(server/sh/bash/zsh/powershell/pwsh/cmd)。

func (Interpreter) AppendText

func (i Interpreter) AppendText(b []byte) ([]byte, error)

AppendText 实现 encoding.TextAppender(值接收者);对非法值失败关闭。

func (Interpreter) IsPOSIXShell

func (i Interpreter) IsPOSIXShell() bool

IsPOSIXShell 报告解释器本身是否属于 POSIX Bourne 族(sh/bash/zsh)。

func (Interpreter) IsPowerShell

func (i Interpreter) IsPowerShell() bool

IsPowerShell 报告解释器是否为 powershell 或 pwsh。

func (Interpreter) IsValid

func (i Interpreter) IsValid() bool

IsValid 报告 i 是否为受支持的合法解释器。

func (Interpreter) IsZero

func (i Interpreter) IsZero() bool

IsZero 报告 i 是否为无效零值。

func (Interpreter) MarshalText

func (i Interpreter) MarshalText() ([]byte, error)

MarshalText 实现 encoding.TextMarshaler(值接收者)。

func (Interpreter) String

func (i Interpreter) String() string

String 返回解释器规范小写标识;非法值返回 "invalid"。

func (*Interpreter) UnmarshalText

func (i *Interpreter) UnmarshalText(text []byte) error

UnmarshalText 实现 encoding.TextUnmarshaler;失败时重置为 InterpreterInvalid 并失败关闭。

type LaunchDialect

type LaunchDialect uint8

LaunchDialect 表示 SSH 服务端用于解析外层启动命令的方言;零值 DialectUnknown 失败关闭。

const (
	DialectUnknown    LaunchDialect = iota // 未知服务端方言(零值;仅 server 直通允许)
	DialectPOSIX                           // POSIX Bourne 兼容启动方言(sh/bash/zsh/dash/ash)
	DialectPowerShell                      // Windows/跨平台 PowerShell 启动方言
	DialectCmd                             // Windows cmd.exe 启动方言
	DialectRaw                             // 原始直通方言(不执行任何外层壳引用或包装)
)

func ParseLaunchDialect

func ParseLaunchDialect(raw string) (LaunchDialect, error)

ParseLaunchDialect 严格解析规范小写启动方言名称("posix"、"powershell"、"cmd"、"raw")。

func (LaunchDialect) AppendText

func (d LaunchDialect) AppendText(b []byte) ([]byte, error)

AppendText 实现 encoding.TextAppender(值接收者);对零值/非法值失败关闭。

func (LaunchDialect) IsValid

func (d LaunchDialect) IsValid() bool

IsValid 报告 d 是否为已明确声明的合法启动方言(不含零值 DialectUnknown)。

func (LaunchDialect) IsZero

func (d LaunchDialect) IsZero() bool

IsZero 报告 d 是否处于未知零值状态。

func (LaunchDialect) MarshalText

func (d LaunchDialect) MarshalText() ([]byte, error)

MarshalText 实现 encoding.TextMarshaler(值接收者)。

func (LaunchDialect) String

func (d LaunchDialect) String() string

String 返回启动方言的规范小写文本;零值返回 "unknown"。

func (*LaunchDialect) UnmarshalText

func (d *LaunchDialect) UnmarshalText(text []byte) error

UnmarshalText 实现 encoding.TextUnmarshaler;失败时重置为 DialectUnknown 并失败关闭。

type LaunchProfile

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

LaunchProfile 表示经过兼容性矩阵校验的不可变命令启动配置(方言 × 解释器 × 登录模式); 零值恒无效并失败关闭,且经 //xops:canonicalhash 校验全字段规范摘要覆盖。

func DefaultServerLaunchProfile

func DefaultServerLaunchProfile() LaunchProfile

DefaultServerLaunchProfile 返回默认服务端直通启动配置(DialectUnknown + server + inherit)。

func NewLaunchProfile

func NewLaunchProfile(spec LaunchProfileSpec) (LaunchProfile, error)

NewLaunchProfile 按严格兼容性矩阵校验并构造不可变 LaunchProfile。

func POSIXLaunchProfile

func POSIXLaunchProfile(interp Interpreter, login LoginMode) (LaunchProfile, error)

POSIXLaunchProfile 便捷构造 POSIX 启动方言下指定解释器与登录模式的不可变 LaunchProfile。

func (LaunchProfile) Dialect

func (p LaunchProfile) Dialect() LaunchDialect

Dialect 返回生效启动方言;未声明或无效配置返回 DialectUnknown。

func (LaunchProfile) DialectOption

func (p LaunchProfile) DialectOption() algebraic.Option[LaunchDialect]

DialectOption 返回可选启动方言 Option[LaunchDialect]。

func (LaunchProfile) Equal

func (p LaunchProfile) Equal(other LaunchProfile) bool

Equal 严格比对两个 LaunchProfile 是否均有效且三元组完全一致(无效零值永不相等)。

func (LaunchProfile) Interpreter

func (p LaunchProfile) Interpreter() Interpreter

Interpreter 返回生效解释器;无效零值返回 InterpreterInvalid。

func (LaunchProfile) IsPOSIXBourne

func (p LaunchProfile) IsPOSIXBourne() bool

IsPOSIXBourne 报告当前启动配置是否满足 INV-E4 的 POSIX Bourne 解释器要求 (即 server+DialectPOSIX,或已知 POSIX 方言下的 sh/bash/zsh)。

func (LaunchProfile) IsValid

func (p LaunchProfile) IsValid() bool

IsValid 报告 LaunchProfile 是否经构造器合法初始化。

func (LaunchProfile) IsZero

func (p LaunchProfile) IsZero() bool

IsZero 报告 LaunchProfile 是否为无效零值。

func (LaunchProfile) LoginMode

func (p LaunchProfile) LoginMode() LoginMode

LoginMode 返回生效登录模式;无效零值返回 LoginModeUnset。

func (LaunchProfile) MarshalJSONTo

func (p LaunchProfile) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者);对零值失败关闭。

func (*LaunchProfile) UnmarshalJSONFrom

func (p *LaunchProfile) UnmarshalJSONFrom(dec *jsontext.Decoder) error

UnmarshalJSONFrom 实现 encoding/json/v2.UnmarshalerFrom;对 JSON null、缺失必需字段或非法组合失败关闭。

func (LaunchProfile) ValidatePOSIXBourne

func (p LaunchProfile) ValidatePOSIXBourne() error

ValidatePOSIXBourne 校验当前配置是否满足 POSIX Bourne 要求,不满足时返回 ErrNotPOSIXBourne。

func (LaunchProfile) WriteCanonical

func (p LaunchProfile) WriteCanonical(w io.Writer) error

WriteCanonical 以零反射、长度前缀与域分离方式写入 LaunchProfile 全字段规范字节流(受 digestcover 校验)。

type LaunchProfileSpec

type LaunchProfileSpec struct {
	Dialect     algebraic.Option[LaunchDialect]
	Interpreter Interpreter
	Login       LoginMode
}

LaunchProfileSpec 是构造不可变 LaunchProfile 的显式入参规格。

type LoginMode

type LoginMode uint8

LoginMode 表示显式解释器的登录环境模式;零值 LoginModeUnset 失败关闭。

const (
	LoginModeUnset    LoginMode = iota // 未初始化零值(失败关闭)
	LoginModeDisabled                  // 显式关闭登录 Shell(non-login)
	LoginModeLogin                     // 显式启用登录 Shell(如 bash -l / zsh -l)
	LoginModeInherit                   // 继承服务端或解释器默认行为(不主动注入登录标志)
)

func ParseLoginMode

func ParseLoginMode(raw string) (LoginMode, error)

ParseLoginMode 严格解析登录模式(支持 canonical: "disabled"/"login"/"inherit" 及常见等价别名)。

func (LoginMode) AppendText

func (m LoginMode) AppendText(b []byte) ([]byte, error)

AppendText 实现 encoding.TextAppender(值接收者);对零值/非法值失败关闭。

func (LoginMode) IsValid

func (m LoginMode) IsValid() bool

IsValid 报告 m 是否为合法登录模式。

func (LoginMode) IsZero

func (m LoginMode) IsZero() bool

IsZero 报告 m 是否为未初始化零值。

func (LoginMode) MarshalText

func (m LoginMode) MarshalText() ([]byte, error)

MarshalText 实现 encoding.TextMarshaler(值接收者)。

func (LoginMode) String

func (m LoginMode) String() string

String 返回登录模式规范小写文本;未初始化返回 "unset"。

func (*LoginMode) UnmarshalText

func (m *LoginMode) UnmarshalText(text []byte) error

UnmarshalText 实现 encoding.TextUnmarshaler;失败时重置为 LoginModeUnset 并失败关闭。

type OutcomeCompleted

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

OutcomeCompleted 表示已收到远端进程终态(退出码、信号或缺失退出帧);严禁自动重试。

func NewOutcomeCompleted

func NewOutcomeCompleted(status ExitStatus, truncated bool) (*OutcomeCompleted, error)

NewOutcomeCompleted 校验 ExitStatus 非空有效并构造 *OutcomeCompleted。

func (*OutcomeCompleted) CanRetry

func (*OutcomeCompleted) CanRetry() bool

CanRetry 已完成执行恒返回 false。

func (*OutcomeCompleted) IsValid

func (o *OutcomeCompleted) IsValid() bool

func (*OutcomeCompleted) Kind

func (o *OutcomeCompleted) Kind() OutcomeKind

func (OutcomeCompleted) MarshalJSONTo

func (o OutcomeCompleted) MarshalJSONTo(enc *jsontext.Encoder) error

func (*OutcomeCompleted) Status

func (o *OutcomeCompleted) Status() ExitStatus

Status 返回终止状态副本;无效零值失败关闭返回 nil。

func (*OutcomeCompleted) Succeeded

func (o *OutcomeCompleted) Succeeded() bool

Succeeded 当且仅当结果有效且退出状态为显式退出码 0 时返回 true。

func (*OutcomeCompleted) Truncated

func (o *OutcomeCompleted) Truncated() bool

Truncated 报告命令输出是否触发上限截断。

type OutcomeKind

type OutcomeKind uint8

OutcomeKind 标识 ExecutionOutcome 的判别类别;零值 OutcomeKindInvalid 失败关闭。

const (
	OutcomeKindInvalid    OutcomeKind = iota // 无效结果(零值失败关闭)
	OutcomeKindNotStarted                    // 确认未启动远端执行(唯一允许重试)
	OutcomeKindCompleted                     // 已取得远端终止结果(严禁自动重试)
	OutcomeKindUnknown                       // 请求已发出但结果不确定(严禁自动重试)
)

func ParseOutcomeKind

func ParseOutcomeKind(raw string) (OutcomeKind, error)

ParseOutcomeKind 严格解析执行结果类别("not_started"、"completed"、"unknown")。

func (OutcomeKind) AppendText

func (k OutcomeKind) AppendText(b []byte) ([]byte, error)

func (OutcomeKind) IsValid

func (k OutcomeKind) IsValid() bool

func (OutcomeKind) IsZero

func (k OutcomeKind) IsZero() bool

func (OutcomeKind) MarshalText

func (k OutcomeKind) MarshalText() ([]byte, error)

func (OutcomeKind) String

func (k OutcomeKind) String() string

func (*OutcomeKind) UnmarshalText

func (k *OutcomeKind) UnmarshalText(text []byte) error

type OutcomeNotStarted

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

OutcomeNotStarted 表示可证明用户操作尚未在远端启动(唯一允许安全重试的变体)。

func NewOutcomeNotStarted

func NewOutcomeNotStarted(phase StartPhase, code, reason string) (*OutcomeNotStarted, error)

NewOutcomeNotStarted 校验启动前阶段与错误代码并构造 *OutcomeNotStarted。

func (*OutcomeNotStarted) CanRetry

func (o *OutcomeNotStarted) CanRetry() bool

CanRetry 当且仅当为有效 *OutcomeNotStarted 时返回 true。

func (*OutcomeNotStarted) Code

func (o *OutcomeNotStarted) Code() string

func (*OutcomeNotStarted) IsValid

func (o *OutcomeNotStarted) IsValid() bool

func (*OutcomeNotStarted) Kind

func (o *OutcomeNotStarted) Kind() OutcomeKind

func (OutcomeNotStarted) MarshalJSONTo

func (o OutcomeNotStarted) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 为 OutcomeNotStarted、OutcomeCompleted、OutcomeUnknown 提供值接收者 json/v2 编码(零值失败关闭)。

func (*OutcomeNotStarted) Phase

func (o *OutcomeNotStarted) Phase() StartPhase

func (*OutcomeNotStarted) Reason

func (o *OutcomeNotStarted) Reason() string

type OutcomeUnknown

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

OutcomeUnknown 表示启动请求已发出但未取得确定终态(副作用可能已发生,严禁自动重试)。

func NewOutcomeUnknown

func NewOutcomeUnknown(phase ExecPhase, code, reason string) (*OutcomeUnknown, error)

NewOutcomeUnknown 校验执行阶段与错误代码并构造 *OutcomeUnknown。

func (*OutcomeUnknown) CanRetry

func (*OutcomeUnknown) CanRetry() bool

CanRetry 结果未知恒返回 false(严禁自动重放以防重复副作用)。

func (*OutcomeUnknown) Code

func (o *OutcomeUnknown) Code() string

func (*OutcomeUnknown) IsValid

func (o *OutcomeUnknown) IsValid() bool

func (*OutcomeUnknown) Kind

func (o *OutcomeUnknown) Kind() OutcomeKind

func (OutcomeUnknown) MarshalJSONTo

func (o OutcomeUnknown) MarshalJSONTo(enc *jsontext.Encoder) error

func (*OutcomeUnknown) Phase

func (o *OutcomeUnknown) Phase() ExecPhase

func (*OutcomeUnknown) Reason

func (o *OutcomeUnknown) Reason() string

type PlanKind

type PlanKind uint8

PlanKind 标识命令执行计划的操作类型(普通命令或脚本);零值 PlanKindInvalid 失败关闭。

const (
	PlanKindInvalid PlanKind = iota // 无效计划类型(零值失败关闭)
	PlanKindCommand                 // 单次命令执行(command 字符串或 argv 参数向量)
	PlanKindScript                  // 有界脚本执行(必须绑定非 server 显式解释器)
)

func ParsePlanKind

func ParsePlanKind(raw string) (PlanKind, error)

ParsePlanKind 严格解析规范小写计划类型("command" 或 "script")。

func (PlanKind) AppendText

func (k PlanKind) AppendText(b []byte) ([]byte, error)

AppendText 实现 encoding.TextAppender(值接收者);对非法值失败关闭。

func (PlanKind) IsValid

func (k PlanKind) IsValid() bool

IsValid 报告 k 是否为合法计划类型。

func (PlanKind) IsZero

func (k PlanKind) IsZero() bool

IsZero 报告 k 是否为无效零值。

func (PlanKind) MarshalText

func (k PlanKind) MarshalText() ([]byte, error)

MarshalText 实现 encoding.TextMarshaler(值接收者)。

func (PlanKind) String

func (k PlanKind) String() string

String 返回计划类型的规范小写文本;非法值返回 "invalid"。

func (*PlanKind) UnmarshalText

func (k *PlanKind) UnmarshalText(text []byte) error

UnmarshalText 实现 encoding.TextUnmarshaler;失败时重置为 PlanKindInvalid 并失败关闭。

type StartPhase

type StartPhase uint8

StartPhase 标识命令尚未启动前的失败阶段;零值 StartPhaseUnknown 失败关闭。

const (
	StartPhaseUnknown         StartPhase = iota // 未知阶段(零值失败关闭)
	StartPhaseValidate                          // 本地计划/参数预检失败
	StartPhaseAuthorize                         // 能力门控或审批拒绝
	StartPhaseDial                              // SSH 连接拨号或跳板链建立失败
	StartPhaseSessionOpen                       // SSH 会话通道打开失败
	StartPhaseRequestRejected                   // 服务端明确拒绝 exec/shell/pty 启动请求
)

func ParseStartPhase

func ParseStartPhase(raw string) (StartPhase, error)

ParseStartPhase 严格解析规范小写启动前阶段文本。

func (StartPhase) AppendText

func (p StartPhase) AppendText(b []byte) ([]byte, error)

func (StartPhase) IsValid

func (p StartPhase) IsValid() bool

func (StartPhase) IsZero

func (p StartPhase) IsZero() bool

func (StartPhase) MarshalText

func (p StartPhase) MarshalText() ([]byte, error)

func (StartPhase) String

func (p StartPhase) String() string

func (*StartPhase) UnmarshalText

func (p *StartPhase) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

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