automation

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 33 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)、 评估期内存借用 CommandTexts 护栏黑名单通道与确定性排序聚合报告;严格遵循 gate.WithAuthorized 包裹 pool.WithLease、 严分 OutcomeNotStarted 与 OutcomeUnknown(绝不重试并忠实上报 AuditOutcomeUnknown)并在 Gate Halted 熔断态立即拒绝执行;
  • Playbook vNext 判别式 AST 执行器(RunPlaybook):穷尽分派 shell / script / copy / template / ensure 五类封闭动作, 支持顶层 settings(concurrency / timeout / execution / privilege)、6 级 execution 继承链 (CLI > Playbook step > Playbook settings > Node > Global > server)、StepShell/StepScript 提权与 auto 探测、 普通步骤确定性安全重试(OutcomeUnknown 永不重试、EnsureFSM 幂等边界、0 time.Sleep)与 CommandTexts 黑名单校验; 严格驱动纯函数 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              = autoplan.ErrNilContext
	ErrInvalidConfig           = autoplan.ErrInvalidConfig
	ErrServiceNotInitialized   = autoplan.ErrServiceNotInitialized
	ErrInvalidRequest          = autoplan.ErrInvalidRequest
	ErrNoTargets               = autoplan.ErrNoTargets
	ErrOperatorReadUnavailable = autoplan.ErrOperatorReadUnavailable
	ErrScopedFSUnavailable     = autoplan.ErrScopedFSUnavailable
	ErrInventoryUnavailable    = autoplan.ErrInventoryUnavailable
	ErrTemplateRender          = autoplan.ErrTemplateRender
	ErrBatchFailed             = autoplan.ErrBatchFailed
	ErrPlaybookFailed          = autoplan.ErrPlaybookFailed
	ErrPlaybookAborted         = autoplan.ErrPlaybookAborted
	ErrUncertainOutcome        = autoplan.ErrUncertainOutcome
	ErrUncertainDurability     = autoplan.ErrUncertainDurability
	ErrUnsupportedAction       = autoplan.ErrUnsupportedAction
	ErrSymlinkPolicyDenied     = autoplan.ErrSymlinkPolicyDenied
)

本包导出的不可变哨兵错误(只读重导出自内部叶包 autoplan),供 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
	AllowDNSResolve     bool // 可选:允许经 CanonicalResolverPort 执行主机名规范化(零值 false;MCP/DisallowForwardAgent 下强制 false)
	AllowFullAdHocTier4 bool // 可选:允许非 IP AdHoc 受 OpenSSH 全量 Tier-4 升级(零值 false;MCP/DisallowForwardAgent 下强制 false)
	ExcludeNodes        []inventory.NodeID
	ExcludeTags         []inventory.Tag
	Command             execution.CommandPlan
	ExecutionOverride   algebraic.Option[execution.LaunchProfile]
	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
	AllowDNSResolve         bool // 可选:允许经 CanonicalResolverPort 执行主机名规范化(零值 false;MCP/DisallowForwardAgent 下强制 false)
	AllowFullAdHocTier4     bool // 可选:允许非 IP AdHoc 受 OpenSSH 全量 Tier-4 升级(零值 false;MCP/DisallowForwardAgent 下强制 false)
	DefaultProfile          algebraic.Option[execution.LaunchProfile]
	Privilege               algebraic.Option[inventory.PrivilegePolicy]
	PrivilegePasswordRef    algebraic.Option[secret.Ref]
	PrivilegeTargetUser     algebraic.Option[option.Username]
	PromptPrivilegePassword bool
	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 / M1-T4)。 请求级 DefaultProfile、Concurrency、Timeout 与 Privilege 作为 CLI 覆写层,严格高于 Playbook settings / step / Node / Global。

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 / M1-T4):

  • 全程遵守 gate.WithAuthorized[security.CapExecute] 外包 pool.WithLease;
  • 合并 Playbook settings(concurrency/timeout/execution/privilege)与请求级 CLI 覆写;
  • 提取 StepShell/StepScript/StepEnsure 命令与脚本文本经 GateRequestSpec.CommandTexts 执行黑名单拦截(0 审计泄漏);
  • 两步审批绑定 100% 由显式 Playbook 规范摘要、排序目标集合、合并变量摘要与远端路径集合确定(零门控前抽熵漂移);
  • 非 DirectOperator 配置档下对全部 copy/template 远端写目标(含 ensure.action 内嵌写步骤)执行 Round-2 软链规范化探测;
  • 按双模态本地 FS 隔离原则加载 script/copy/template 源内容(MCP 缺席 OperatorReadFS 即 Fail-Closed);
  • 穷尽执行 5 类封闭 StepAction、支持 StepShell/StepScript 提权与普通步骤确定性安全重试、驱动 EnsureFSM 并经 FoldPlaybookReport 折叠报表。

type ServiceConfig

type ServiceConfig struct {
	Gate                 gate.Authorizer                           // 必填:能力门控授权器(ADR-008)
	Pool                 *pool.Pool                                // 必填:双通道纯内存 Actor 连接池(ADR-009)
	Clock                ports.Clock                               // 必填:确定性时钟与可取消定时器端口(0 time.Sleep)
	Entropy              ports.Entropy                             // 必填:显式熵源端口
	Env                  ports.EnvPort                             // 可选:SendEnv 环境变量过滤端口
	ScopedFS             ports.ScopedRootFS                        // 可选:沙箱本地文件系统端口(--out-dir 与沙箱源文件)
	OperatorReadFS       ports.OperatorReadFS                      // 可选:操作员只读本地源端口(MCP 路径留 nil)
	Inventory            *ucinv.Service                            // 可选:资产与目标解析服务(按 TargetSelector 动态解析节点)
	ShellProbe           ports.ShellProbePort                      // 可选:2 阶段远端 Shell 方言探测端口(提权前重投影未知外层方言)
	Escalator            ports.PrivilegeEscalationPort             // 可选:远端提权执行端口(Playbook StepShell/StepScript 提权)
	Vault                ports.SecretVault                         // 可选:全作用域凭据库端口(借用提权口令,0 明文消费)
	Interaction          ports.InteractionPort                     // 可选:人工交互端口(交互式提权口令提示,MCP 留 nil)
	SystemBus            *events.SystemBus                         // 可选:非阻塞诊断总线
	DiagnosticSink       ports.DiagnosticSink                      // 可选:ADR-019 C3 无锁脱敏诊断输出端口(Playbook/MCP ForwardAgent 裁剪告警)
	DisallowForwardAgent bool                                      // 可选:物理禁止 Agent 转发(MCP 视图置 true;Playbook 路径恒执行裁剪与显式拒绝)
	DefaultExecution     algebraic.Option[execution.LaunchProfile] // 可选:全局默认远端启动配置(6 级继承链 Global 层)
	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) Privilege added in v1.3.0

func (TargetNode) PrivilegePasswordRef added in v1.3.0

func (t TargetNode) PrivilegePasswordRef() algebraic.Option[secret.Ref]

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]
	Privilege            algebraic.Option[inventory.PrivilegePolicy]
	PrivilegePasswordRef algebraic.Option[secret.Ref]
}

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

Directories

Path Synopsis
internal
autoplan
Package autoplan 提供 core/internal/usecase/automation 的无状态计划规划、变量合并、摘要计算、 模板渲染、远端 POSIX 路径规范化校验、结果状态分类与流式事件发射辅助函数。
Package autoplan 提供 core/internal/usecase/automation 的无状态计划规划、变量合并、摘要计算、 模板渲染、远端 POSIX 路径规范化校验、结果状态分类与流式事件发射辅助函数。

Jump to

Keyboard shortcuts

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