automation

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: 34 Imported by: 0 modules, 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 automation 实现 XOps v2 自动化编排用例服务(ADR-007 / ADR-008 / ADR-009 / ADR-010 / Plan P3-T4)。

核心交付范围与安全不变量:

  • 并行批量 exec(BatchExec):受 core/conc.Nursery(RunWait)有界并发监督(0 裸 go),支持节点与标签排除过滤、 单节点独立隔离 OperationStream(确定性 EOF + panic defer 终态事件)、ScopedRootFS 沙箱输出目录(--out-dir) 及确定性排序聚合报告;严格遵循 gate.WithAuthorized 包裹 pool.WithLease、严分 OutcomeNotStarted 与 OutcomeUnknown (绝不重试并忠实上报 AuditOutcomeUnknown)并在 Gate Halted 熔断态立即拒绝执行;
  • Playbook vNext 判别式 AST 执行器(RunPlaybook):穷尽分派 shell / script / copy / template / ensure 五类封闭动作, 严格驱动纯函数 EnsureFSM 状态机与 FoldPlaybookReport 确定性折叠;两步审批绑定 100% 由显式入参确定、零门控前抽熵漂移; copy / template / script 严守双模态本地 FS 隔离(MCP 路径缺席 OperatorReadFS 即 Fail-Closed,沙箱源与输出经 ScopedRootFS), 远端路径全程 0 path/filepath 并在非 DirectOperator 配置档下执行 Round-2 软链规范化与受保护路径复核。

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilContext              = errors.New("usecase/automation: context 不能为 nil")
	ErrInvalidConfig           = errors.New("usecase/automation: 无效的 ServiceConfig 配置")
	ErrServiceNotInitialized   = errors.New("usecase/automation: Service 未初始化")
	ErrInvalidRequest          = errors.New("usecase/automation: 无效的自动化执行请求")
	ErrNoTargets               = errors.New("usecase/automation: 筛选后不存在可执行目标节点")
	ErrOperatorReadUnavailable = errors.New("usecase/automation: 未配置 OperatorReadFS,拒绝读取操作员本地源路径")
	ErrScopedFSUnavailable     = errors.New("usecase/automation: 未配置 ScopedRootFS")
	ErrInventoryUnavailable    = errors.New("usecase/automation: 未配置 InventoryService,无法按选择器解析目标节点")
	ErrTemplateRender          = errors.New("usecase/automation: 模板解析或渲染失败")
	ErrBatchFailed             = errors.New("usecase/automation: 批量命令执行存在失败节点")
	ErrPlaybookFailed          = errors.New("usecase/automation: Playbook 执行存在失败步骤")
	ErrPlaybookAborted         = errors.New("usecase/automation: Playbook 执行被策略中止")
	ErrUncertainOutcome        = errors.New("usecase/automation: 存在执行结果未知(OutcomeUnknown),严禁重试")
	ErrUncertainDurability     = errors.New("usecase/automation: 远端变更已应用但持久性不确定,严禁重试")
	ErrUnsupportedAction       = errors.New("usecase/automation: 不支持的 Playbook 步骤动作类型")
	ErrSymlinkPolicyDenied     = errors.New("usecase/automation: 符号链接策略不允许当前读取或远端展开超限")
)

本包导出的不可变哨兵错误,供 core/engine、CLI/MCP 与测试经 errors.Is 精确区分故障类别。

Functions

This section is empty.

Types

type BatchExecReport

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

BatchExecReport 表示跨节点批量 exec 按 NodeID 确定性排序折叠的不可变汇总报告;零值恒无效。

func (BatchExecReport) CanonicalJSON

func (r BatchExecReport) CanonicalJSON() ([]byte, error)

CanonicalJSON 使用 Go 1.27 encoding/json/v2 Deterministic(true) 序列化规范报告。

func (BatchExecReport) Duration

func (r BatchExecReport) Duration() algebraic.Duration

func (BatchExecReport) FailedCount

func (r BatchExecReport) FailedCount() int

func (BatchExecReport) HasUnknownOutcome

func (r BatchExecReport) HasUnknownOutcome() bool

func (BatchExecReport) IsValid

func (r BatchExecReport) IsValid() bool

BatchExecReport 只读访问器与确定性 JSON 编码。

func (BatchExecReport) IsZero

func (r BatchExecReport) IsZero() bool

func (BatchExecReport) MarshalJSONTo

func (r BatchExecReport) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 实现 BatchExecReport 的 Go 1.27 encoding/json/v2 确定性编码;零值失败关闭。

func (BatchExecReport) NotStartedCount

func (r BatchExecReport) NotStartedCount() int

func (BatchExecReport) Results

func (r BatchExecReport) Results() []BatchNodeResult

func (BatchExecReport) SucceededCount

func (r BatchExecReport) SucceededCount() int

func (BatchExecReport) UnknownCount

func (r BatchExecReport) UnknownCount() int

type BatchExecRequest

type BatchExecRequest struct {
	Targets           []TargetNode
	Selector          algebraic.Option[playbook.TargetSelector]
	CLIOptions        option.OptionLayer
	ExcludeNodes      []inventory.NodeID
	ExcludeTags       []inventory.Tag
	Command           execution.CommandPlan
	Concurrency       int
	MaxOutputBytes    uint64
	OutputDir         algebraic.Option[pathalg.LocalDir]
	FailFast          bool
	Risk              algebraic.Option[security.RiskLevel]
	Approval          algebraic.Option[gate.ApprovalSubmission]
	OperationStream   *events.OperationStream
	NodeStreams       map[inventory.NodeID]*events.OperationStream
	NodeStreamFactory NodeStreamFactory
}

BatchExecRequest 描述并发批量 exec 用例的强类型输入(P3-T4)。 Targets 与 Selector 可组合使用:两者并存时先按 Selector 筛选 Targets;仅提供 Selector 时经 Inventory 解析。

type BatchNodeResult

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

BatchNodeResult 表示批量 exec 单个节点的不可变执行结果快照;零值恒无效。

func (BatchNodeResult) Duration

func (r BatchNodeResult) Duration() algebraic.Duration

func (BatchNodeResult) Err

func (r BatchNodeResult) Err() error

func (BatchNodeResult) ErrorMessage

func (r BatchNodeResult) ErrorMessage() string

func (BatchNodeResult) IsNotStarted

func (r BatchNodeResult) IsNotStarted() bool

func (BatchNodeResult) IsOutcomeUnknown

func (r BatchNodeResult) IsOutcomeUnknown() bool

func (BatchNodeResult) IsValid

func (r BatchNodeResult) IsValid() bool

BatchNodeResult 只读访问器与语义判定(严分 OutcomeNotStarted / OutcomeCompleted / OutcomeUnknown)。

func (BatchNodeResult) IsZero

func (r BatchNodeResult) IsZero() bool

func (BatchNodeResult) MarshalJSONTo

func (r BatchNodeResult) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 实现 BatchNodeResult 的 Go 1.27 encoding/json/v2 确定性编码(零裸 time.Duration);零值失败关闭。

func (BatchNodeResult) NodeID

func (r BatchNodeResult) NodeID() inventory.NodeID

func (BatchNodeResult) Outcome

func (BatchNodeResult) Stderr

func (r BatchNodeResult) Stderr() []byte

func (BatchNodeResult) StderrFile

func (BatchNodeResult) Stdout

func (r BatchNodeResult) Stdout() []byte

func (BatchNodeResult) StdoutFile

func (BatchNodeResult) Succeeded

func (r BatchNodeResult) Succeeded() bool

func (BatchNodeResult) Truncated

func (r BatchNodeResult) Truncated() bool

type NodeStreamFactory

type NodeStreamFactory func(nodeID inventory.NodeID, traceID security.TraceID, opID security.OperationID) (*events.OperationStream, error)

NodeStreamFactory 按需为动态解析的单个节点构造独立隔离的 OperationStream; 回调在门控授权之后、派发节点工作协程之前同步执行,流由 automation.Service 在节点结束或 panic 时确定性闭合。

type PlaybookRequest

type PlaybookRequest struct {
	Playbook          playbook.Playbook
	Targets           []TargetNode
	CLIOptions        option.OptionLayer
	DefaultProfile    algebraic.Option[execution.LaunchProfile]
	ScopedSourceRoot  algebraic.Option[pathalg.LocalDir]
	Concurrency       int
	Timeout           algebraic.Option[algebraic.Duration]
	ExtraVars         map[string]string
	Risk              algebraic.Option[security.RiskLevel]
	Approval          algebraic.Option[gate.ApprovalSubmission]
	OperationStream   *events.OperationStream
	NodeStreams       map[inventory.NodeID]*events.OperationStream
	NodeStreamFactory NodeStreamFactory
}

PlaybookRequest 描述 Playbook vNext 判别式 AST 执行用例的强类型输入(P3-T4)。

type PlaybookRunResult

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

PlaybookRunResult 封装 Playbook 执行的不可变折叠报表与元状态;零值恒无效。

func (PlaybookRunResult) Aborted

func (r PlaybookRunResult) Aborted() bool

func (PlaybookRunResult) Duration

func (r PlaybookRunResult) Duration() algebraic.Duration

func (PlaybookRunResult) HasUnknownOutcome

func (r PlaybookRunResult) HasUnknownOutcome() bool

func (PlaybookRunResult) IsValid

func (r PlaybookRunResult) IsValid() bool

PlaybookRunResult 只读访问器(零值恒无效并失败关闭)。

func (PlaybookRunResult) IsZero

func (r PlaybookRunResult) IsZero() bool

func (PlaybookRunResult) MarshalJSONTo

func (r PlaybookRunResult) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 实现 PlaybookRunResult 的 Go 1.27 encoding/json/v2 确定性编码;零值失败关闭。

func (PlaybookRunResult) Report

type Service

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

Service 是 XOps v2 自动化批量执行与 Playbook vNext 执行用例服务;零值恒未初始化并严格失败关闭。

func NewService

func NewService(cfg ServiceConfig) (*Service, error)

NewService 严格校验必填出站依赖与容量上下界,构造不可绕过能力门控的 automation.Service。

func (*Service) BatchExec

func (s *Service) BatchExec(ctx context.Context, req BatchExecRequest) (BatchExecReport, error)

BatchExec 在 core/conc.Nursery(RunWait)有界并发监督下对多节点执行同一不可变 CommandPlan:

  • 严格遵循 gate.WithAuthorized[security.CapExecute] 外包 pool.WithLease 嵌套序(ADR-008 / ADR-009);
  • 非 DirectOperator 配置档下对 Command.WorkDir 执行 Round-2 软链规范化与执行前 TOCTOU 复核;
  • 两步审批绑定完全由排序后目标节点、连接计划摘要、命令摘要与显式参数确定(零门控前抽熵漂移);
  • 支持单节点独立隔离 OperationStream(确定性 EOF + panic defer 终态事件)与 ScopedRootFS --out-dir 原子落盘;
  • 严分 OutcomeNotStarted 与 OutcomeUnknown,任一节点出现 OutcomeUnknown 时绝不重试并忠实上报 AuditOutcomeUnknown。

func (*Service) RunPlaybook

func (s *Service) RunPlaybook(ctx context.Context, req PlaybookRequest) (PlaybookRunResult, error)

RunPlaybook 执行声明式 Playbook vNext 不可变 AST(P3-T4):

  • 全程遵守 gate.WithAuthorized[security.CapExecute] 外包 pool.WithLease;
  • 两步审批绑定 100% 由显式 Playbook 规范摘要、排序目标集合、合并变量摘要与远端路径集合确定(零门控前抽熵漂移);
  • 非 DirectOperator 配置档下对全部 copy/template 远端写目标(含 ensure.action 内嵌写步骤)执行 Round-2 软链规范化探测;
  • 按双模态本地 FS 隔离原则加载 script/copy/template 源内容(MCP 缺席 OperatorReadFS 即 Fail-Closed);
  • 穷尽执行 5 类封闭 StepAction、驱动 EnsureFSM 状态机并经 playbook.FoldPlaybookReport 产出确定性不可变报表。

type ServiceConfig

type ServiceConfig struct {
	Gate               gate.Authorizer      // 必填:能力门控授权器(ADR-008)
	Pool               *pool.Pool           // 必填:双通道纯内存 Actor 连接池(ADR-009)
	Clock              ports.Clock          // 必填:确定性时钟端口
	Entropy            ports.Entropy        // 必填:显式熵源端口
	Env                ports.EnvPort        // 可选:SendEnv 环境变量过滤端口
	ScopedFS           ports.ScopedRootFS   // 可选:沙箱本地文件系统端口(--out-dir 与沙箱源文件)
	OperatorReadFS     ports.OperatorReadFS // 可选:操作员只读本地源端口(MCP 路径留 nil)
	Inventory          *ucinv.Service       // 可选:资产与目标解析服务(按 TargetSelector 动态解析节点)
	SystemBus          *events.SystemBus    // 可选:非阻塞诊断总线
	DefaultConcurrency int                  // 可选:默认并发度(0 默认 8,上限 64)
	MaxScriptBytes     int64                // 可选:脚本文件字节上限(0 默认 4 MiB,上限 16 MiB)
	MaxTemplateBytes   int64                // 可选:模板文件字节上限(0 默认 4 MiB,上限 16 MiB)
	MaxCopyBytes       int64                // 可选:copy 文件字节上限(0 默认 64 MiB,上限 64 MiB)
}

ServiceConfig 定义自动化用例服务 Service 的显式出站依赖配置; MCP 路径物理不注入 OperatorReadFS,使需读取操作员任意路径的 Playbook 步骤自动 Fail-Closed。

type TargetNode

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

TargetNode 表示经校验的不可变目标节点执行快照(含 Merkle 连接计划、标签与可选节点默认启动配置);零值恒无效。

func NewTargetNode

func NewTargetNode(spec TargetNodeSpec) (TargetNode, error)

NewTargetNode 校验节点标识、Merkle 连接计划、标签与可选启动配置并构造不可变 TargetNode。

func (TargetNode) DefaultProfile

func (t TargetNode) DefaultProfile() algebraic.Option[execution.LaunchProfile]

func (TargetNode) IsValid

func (t TargetNode) IsValid() bool

IsValid / IsZero / 只读访问器(零值恒无效并失败关闭)。

func (TargetNode) IsZero

func (t TargetNode) IsZero() bool

func (TargetNode) NodeID

func (t TargetNode) NodeID() inventory.NodeID

func (TargetNode) Plan

func (TargetNode) Tags

func (t TargetNode) Tags() []inventory.Tag

type TargetNodeSpec

type TargetNodeSpec struct {
	NodeID         inventory.NodeID
	Plan           plan.SealedConnectionPlan
	Tags           []inventory.Tag
	DefaultProfile algebraic.Option[execution.LaunchProfile]
}

TargetNodeSpec 是构造不可变目标节点快照 TargetNode 的显式入参规格。

Jump to

Keyboard shortcuts

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