Documentation
¶
Overview ¶
Package execution 提供 XOps v2 纯函数领域核的命令执行计划、多方言安全引用与执行结果代数和类型。
本包恪守 100% 纯数学与零副作用铁律(零 os、零 net、零 context、零 sync/sync/atomic、零反射):
- LaunchProfile / LaunchDialect / Interpreter / LoginMode:显式区分服务端直通(server)与 受控解释器(sh/bash/zsh/fish/csh/tcsh/powershell/pwsh/cmd)、外层启动方言 (posix/fish/csh/powershell/cmd/raw),以及登录模式与 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
- Variables
- func CanRetryOutcome(o ExecutionOutcome) bool
- func EncodePowerShellUTF16LEBase64(script string) (string, error)
- func EqualExitStatus(a, b ExitStatus) bool
- func EqualOutcome(a, b ExecutionOutcome) bool
- func MarshalExitStatusTo(enc *jsontext.Encoder, status ExitStatus) error
- func MarshalOutcomeTo(enc *jsontext.Encoder, outcome ExecutionOutcome) error
- func QuoteCmdArg(arg string) (string, error)
- func QuoteCsh(arg string) (string, error)
- func QuoteFish(arg string) (string, error)
- func QuotePOSIX(arg string) (string, error)
- func QuotePowerShell(arg string) (string, error)
- type CommandPlan
- func (p CommandPlan) Argv() []string
- func (p CommandPlan) CanonicalJSON() ([]byte, error)
- func (p CommandPlan) Command() string
- func (p CommandPlan) Digest() (security.Digest, error)
- func (p CommandPlan) Env() map[string]string
- func (p CommandPlan) EnvValue(key string) (string, bool)
- func (p CommandPlan) Equal(other CommandPlan) bool
- func (p CommandPlan) IsValid() bool
- func (p CommandPlan) IsZero() bool
- func (p CommandPlan) Kind() PlanKind
- func (p CommandPlan) MarshalJSONTo(enc *jsontext.Encoder) error
- func (p CommandPlan) MaxOutputBytes() uint64
- func (p CommandPlan) PTY() bool
- func (p CommandPlan) Profile() LaunchProfile
- func (p CommandPlan) RedactedSummary() string
- func (p CommandPlan) RenderCommand() (string, error)
- func (p CommandPlan) StdinPayload() (string, bool)
- func (p CommandPlan) Timeout() algebraic.Option[algebraic.Duration]
- func (p *CommandPlan) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- func (p CommandPlan) WithOuterDialect(d LaunchDialect) (CommandPlan, error)
- func (p CommandPlan) WorkDir() algebraic.Option[pathalg.RemotePath]
- func (p CommandPlan) WriteCanonical(w io.Writer) error
- type CommandPlanSpec
- type ExecPhase
- type ExecutionOutcome
- type ExitCode
- type ExitSignal
- type ExitStatus
- type ExitStatusKind
- type ExitUnknown
- type Interpreter
- func (i Interpreter) AppendText(b []byte) ([]byte, error)
- func (i Interpreter) IsCshFamily() bool
- func (i Interpreter) IsPOSIXShell() bool
- func (i Interpreter) IsPowerShell() bool
- func (i Interpreter) IsUnixShell() bool
- func (i Interpreter) IsValid() bool
- func (i Interpreter) IsZero() bool
- func (i Interpreter) MarshalText() ([]byte, error)
- func (i Interpreter) String() string
- func (i *Interpreter) UnmarshalText(text []byte) error
- type LaunchDialect
- func (d LaunchDialect) AppendText(b []byte) ([]byte, error)
- func (d LaunchDialect) IsUnixShell() bool
- func (d LaunchDialect) IsValid() bool
- func (d LaunchDialect) IsZero() bool
- func (d LaunchDialect) MarshalText() ([]byte, error)
- func (d LaunchDialect) String() string
- func (d *LaunchDialect) UnmarshalText(text []byte) error
- type LaunchProfile
- func (p LaunchProfile) Dialect() LaunchDialect
- func (p LaunchProfile) DialectOption() algebraic.Option[LaunchDialect]
- func (p LaunchProfile) Equal(other LaunchProfile) bool
- func (p LaunchProfile) Interpreter() Interpreter
- func (p LaunchProfile) IsPOSIXBourne() bool
- func (p LaunchProfile) IsValid() bool
- func (p LaunchProfile) IsZero() bool
- func (p LaunchProfile) LoginMode() LoginMode
- func (p LaunchProfile) MarshalJSONTo(enc *jsontext.Encoder) error
- func (p *LaunchProfile) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- func (p LaunchProfile) ValidatePOSIXBourne() error
- func (p LaunchProfile) WriteCanonical(w io.Writer) error
- type LaunchProfileSpec
- type LoginMode
- type OutcomeCompleted
- func (*OutcomeCompleted) CanRetry() bool
- func (o *OutcomeCompleted) IsValid() bool
- func (o *OutcomeCompleted) Kind() OutcomeKind
- func (o OutcomeCompleted) MarshalJSONTo(enc *jsontext.Encoder) error
- func (o *OutcomeCompleted) Status() ExitStatus
- func (o *OutcomeCompleted) Succeeded() bool
- func (o *OutcomeCompleted) Truncated() bool
- type OutcomeKind
- type OutcomeNotStarted
- func (o *OutcomeNotStarted) CanRetry() bool
- func (o *OutcomeNotStarted) Code() string
- func (o *OutcomeNotStarted) IsValid() bool
- func (o *OutcomeNotStarted) Kind() OutcomeKind
- func (o OutcomeNotStarted) MarshalJSONTo(enc *jsontext.Encoder) error
- func (o *OutcomeNotStarted) Phase() StartPhase
- func (o *OutcomeNotStarted) Reason() string
- type OutcomeUnknown
- func (*OutcomeUnknown) CanRetry() bool
- func (o *OutcomeUnknown) Code() string
- func (o *OutcomeUnknown) IsValid() bool
- func (o *OutcomeUnknown) Kind() OutcomeKind
- func (o OutcomeUnknown) MarshalJSONTo(enc *jsontext.Encoder) error
- func (o *OutcomeUnknown) Phase() ExecPhase
- func (o *OutcomeUnknown) Reason() string
- type PlanKind
- type StartPhase
Constants ¶
const ( // DefaultMaxOutputBytes 表示未显式指定输出上限时的默认命令输出截断上限(4 MiB)。 DefaultMaxOutputBytes uint64 = 4 << 20 // MaxAllowedOutputBytes 表示单次命令计划允许配置的最大输出上限(64 MiB)。 MaxAllowedOutputBytes uint64 = 64 << 20 )
Variables ¶
var ( ErrInvalidLaunchDialect = domi18n.Sentinel(domi18n.KeyExecutionInvalidLaunchDialect) ErrInvalidInterpreter = domi18n.Sentinel(domi18n.KeyExecutionInvalidInterpreter) ErrInvalidLoginMode = domi18n.Sentinel(domi18n.KeyExecutionInvalidLoginMode) ErrInvalidLaunchProfile = domi18n.Sentinel(domi18n.KeyExecutionInvalidLaunchProfile) ErrUnsupportedExecutionCombination = domi18n.Sentinel(domi18n.KeyExecutionUnsupportedCombination) ErrNotPOSIXBourne = domi18n.Sentinel(domi18n.KeyExecutionNotPOSIXBourne) ErrInvalidPlanKind = domi18n.Sentinel(domi18n.KeyExecutionInvalidPlanKind) ErrInvalidCommandPlan = domi18n.Sentinel(domi18n.KeyExecutionInvalidCommandPlan) ErrInvalidEnvVar = domi18n.Sentinel(domi18n.KeyExecutionInvalidEnvVar) ErrInvalidShellQuote = domi18n.Sentinel(domi18n.KeyExecutionInvalidShellQuote) ErrInvalidPhase = domi18n.Sentinel(domi18n.KeyExecutionInvalidPhase) ErrInvalidExitStatus = domi18n.Sentinel(domi18n.KeyExecutionInvalidExitStatus) ErrInvalidExecutionOutcome = domi18n.Sentinel(domi18n.KeyExecutionInvalidOutcome) ErrNilWriter = domi18n.Sentinel(domi18n.KeyExecutionNilWriter) ErrNilReceiver = domi18n.Sentinel(domi18n.KeyExecutionNilReceiver) )
本包导出的规范哨兵错误,所有非法组合、越界输入、JSON null 及零值调用均严格失败关闭。
Functions ¶
func CanRetryOutcome ¶
func CanRetryOutcome(o ExecutionOutcome) bool
CanRetryOutcome 穷尽判定任意 ExecutionOutcome 是否允许安全重试;仅有效 *OutcomeNotStarted 返回 true。
func EncodePowerShellUTF16LEBase64 ¶
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 ¶
QuoteCmdArg 对 Windows cmd.exe 参数执行保守失败关闭引用。 由于 cmd.exe 对换行、%VAR%、!VAR! 与元字符存在不可安全屏蔽的二次展开风险, 本函数严格拒绝换行、控制/Cf 字符与危险元字符;当含空白/逗号/分号/等号需加双引号时, 同步拒绝尾部反斜杠以防 Win32 CommandLineToArgvW 将 \" 解释为转义引号。
func QuoteCsh ¶ added in v1.3.0
QuoteCsh 使用 C-shell(csh/tcsh)单引号规则对单个参数执行无 OS 依赖的安全引用。 在 csh/tcsh 单引号内,单引号通过 '\” 逃逸,感叹号 ! 转义为 \! 抑制历史展开, 换行符 \n 转义为 \\\n(杜绝裸换行导致 Unmatched quote);同时严格拒绝 \r(CR)、 NUL、非法 UTF-8、其余控制字符及 Unicode Cf/Bidi 字符;空串编码为 ””。
func QuoteFish ¶ added in v1.3.0
QuoteFish 使用 Fish 单引号规则对单个参数执行无 OS 依赖的安全引用。 Fish 单引号内仅解释 \' 与 \\ 两个转义序列,其余字符均保持字面语义(零变量展开与命令替换); 拒绝 NUL、非法 UTF-8、控制字符(允许 \n/\r/\t)及 Unicode Cf/Bidi 字符;空串编码为 ””。
func QuotePOSIX ¶
QuotePOSIX 使用 POSIX 单引号规则对单个参数执行无 OS 依赖的安全引用。 拒绝 NUL、非法 UTF-8、控制字符(允许 \n/\r/\t)及 Unicode Cf/Bidi 字符;空串编码为 ””。
func QuotePowerShell ¶
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) 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) 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) 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 -- <outerQuote(arg)...>";
- Fish:无位置参数时为 "fish [-l]",携带位置参数 Argv 时为 "fish [-l] -c <outerQuote("source - <fishQuote(arg)...>")>";
- C-shell(csh/tcsh):仅支持零参数脚本 "<interp> -s",携带非空 Argv 失败关闭;
- 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 ¶
func (p CommandPlan) Timeout() algebraic.Option[algebraic.Duration]
Timeout 返回可选执行超时(algebraic.Duration)。
func (*CommandPlan) UnmarshalJSONFrom ¶
func (p *CommandPlan) UnmarshalJSONFrom(dec *jsontext.Decoder) error
UnmarshalJSONFrom 实现 encoding/json/v2.UnmarshalerFrom;对 JSON null、缺失必需字段或非法值失败关闭。
func (CommandPlan) WithOuterDialect ¶ added in v1.3.0
func (p CommandPlan) WithOuterDialect(d LaunchDialect) (CommandPlan, error)
WithOuterDialect 使用指定合法外层启动方言重投影 CommandPlan,完整复用 LaunchProfile 与 CommandPlan 构造不变量校验。 除 Profile.Dialect 外,100% 保留 Interpreter/LoginMode/Kind/Command/Argv/WorkDir/Env/Timeout/MaxOutputBytes/PTY; 无效计划、非法方言或不兼容组合(如非 Unix 方言配 Unix 解释器、csh/tcsh 脚本带 Argv、raw 携带 WorkDir/Env/Argv 等)一律失败关闭。
func (CommandPlan) WorkDir ¶
func (p CommandPlan) WorkDir() algebraic.Option[pathalg.RemotePath]
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, 并允许 POSIX/Fish/PowerShell 解释器附带可选位置参数 Argv(csh/tcsh 脚本携带非空 Argv 失败关闭); MaxOutputBytes 未设置时取 DefaultMaxOutputBytes,显式 Some(0) 失败关闭。
type ExecPhase ¶
type ExecPhase uint8
ExecPhase 标识请求已发送后执行结果陷入未知的运行阶段;零值 ExecPhaseUnknown 失败关闭。
func ParseExecPhase ¶
ParseExecPhase 严格解析规范小写执行阶段文本。
func (ExecPhase) MarshalText ¶
func (*ExecPhase) UnmarshalText ¶
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 (*ExitCode) Kind ¶
func (e *ExitCode) Kind() ExitStatusKind
Kind 有效时返回 ExitStatusKindCode,无效时失败关闭返回 ExitStatusKindInvalid。
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) Kind ¶
func (e *ExitSignal) Kind() ExitStatusKind
Kind 有效时返回 ExitStatusKindSignal,无效时返回 ExitStatusKindInvalid。
func (ExitSignal) MarshalJSONTo ¶
func (e ExitSignal) MarshalJSONTo(enc *jsontext.Encoder) error
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) MarshalText ¶
func (k ExitStatusKind) MarshalText() ([]byte, error)
MarshalText 实现 encoding.TextMarshaler(值接收者)。
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) Kind ¶
func (e *ExitUnknown) Kind() ExitStatusKind
Kind 有效时返回 ExitStatusKindUnknown,无效时返回 ExitStatusKindInvalid。
func (ExitUnknown) MarshalJSONTo ¶
func (e ExitUnknown) MarshalJSONTo(enc *jsontext.Encoder) error
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 InterpreterFish // Fish 解释器 InterpreterCsh // C-shell (csh) 解释器 InterpreterTcsh // TENEX C-shell (tcsh) 解释器 )
func ParseInterpreter ¶
func ParseInterpreter(raw string) (Interpreter, error)
ParseInterpreter 严格解析规范解释器标识(server/sh/bash/zsh/fish/csh/tcsh/powershell/pwsh/cmd)。
func (Interpreter) AppendText ¶
func (i Interpreter) AppendText(b []byte) ([]byte, error)
AppendText 实现 encoding.TextAppender(值接收者);对非法值失败关闭。
func (Interpreter) IsCshFamily ¶ added in v1.3.0
func (i Interpreter) IsCshFamily() bool
IsCshFamily 报告解释器是否属于 C-shell 族(csh 或 tcsh)。
func (Interpreter) IsPOSIXShell ¶
func (i Interpreter) IsPOSIXShell() bool
IsPOSIXShell 报告解释器本身是否属于 POSIX Bourne 族(仅 sh/bash/zsh,严格排除 fish/csh/tcsh 以守 INV-E4)。
func (Interpreter) IsPowerShell ¶
func (i Interpreter) IsPowerShell() bool
IsPowerShell 报告解释器是否为 powershell 或 pwsh。
func (Interpreter) IsUnixShell ¶ added in v1.3.0
func (i Interpreter) IsUnixShell() bool
IsUnixShell 报告解释器是否属于 Unix Shell 族(sh/bash/zsh/fish/csh/tcsh)。
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 // 原始直通方言(不执行任何外层壳引用或包装) DialectFish // Fish 启动方言(fish) DialectCsh // C-shell 启动方言(csh/tcsh) )
func ParseLaunchDialect ¶
func ParseLaunchDialect(raw string) (LaunchDialect, error)
ParseLaunchDialect 严格解析规范小写启动方言名称("posix"、"fish"、"csh"、"powershell"、"cmd"、"raw")。
func (LaunchDialect) AppendText ¶
func (d LaunchDialect) AppendText(b []byte) ([]byte, error)
AppendText 实现 encoding.TextAppender(值接收者);对零值/非法值失败关闭。
func (LaunchDialect) IsUnixShell ¶ added in v1.3.0
func (d LaunchDialect) IsUnixShell() bool
IsUnixShell 报告 d 是否属于 Unix 类外层壳方言(posix/fish/csh);注意这不等价于 INV-E4 的 POSIX Bourne。
func (LaunchDialect) IsValid ¶
func (d LaunchDialect) IsValid() bool
IsValid 报告 d 是否为已明确声明的合法启动方言(不含零值 DialectUnknown)。
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 解释器要求: 严格仅当 Dialect == DialectPOSIX 且解释器为 server 或 sh/bash/zsh 时返回 true; fish/csh/tcsh(无论作外层方言抑或解释器)恒返回 false。
func (LaunchProfile) IsValid ¶
func (p LaunchProfile) IsValid() bool
IsValid 报告 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 失败关闭。
func ParseLoginMode ¶
ParseLoginMode 严格解析登录模式(支持 canonical: "disabled"/"login"/"inherit" 及常见等价别名)。
func (LoginMode) AppendText ¶
AppendText 实现 encoding.TextAppender(值接收者);对零值/非法值失败关闭。
func (LoginMode) MarshalText ¶
MarshalText 实现 encoding.TextMarshaler(值接收者)。
func (*LoginMode) UnmarshalText ¶
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 失败关闭。
func ParsePlanKind ¶
ParsePlanKind 严格解析规范小写计划类型("command" 或 "script")。
func (PlanKind) AppendText ¶
AppendText 实现 encoding.TextAppender(值接收者);对非法值失败关闭。
func (PlanKind) MarshalText ¶
MarshalText 实现 encoding.TextMarshaler(值接收者)。
func (*PlanKind) UnmarshalText ¶
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