protocol

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: AGPL-3.0 Imports: 17 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 protocol 定义单次 Runtime 操作的事件、错误、生命周期、渲染和 stdin 控制契约。

ProcessOutput 通过同一个 renderer 串行化所有事件,只允许一个终态 result, 并拒绝其后的任何事件。成功发射的 warning 会以有界快照形式汇总到权威 result 中。

contracttest 子包为命令集成测试校验原始 NDJSON 分帧、公共结构、终态语义与 warning 汇总。

Index

Constants

View Source
const MaxResultWarningSummaries = 256

MaxResultWarningSummaries 是终态 result 最多保留的 warning 快照数。 warningCount 仍会统计全部已发射的 warning。

View Source
const Version = 1

Version 是当前 Runtime NDJSON 协议版本。

Variables

View Source
var (
	// ErrResultAlreadyEmitted 表示调用方试图发射第二个终态 result。
	ErrResultAlreadyEmitted = errors.New("protocol result already emitted")
	// ErrOutputWriteFailed 表示 renderer 已无法把协议事件写到目标输出。
	ErrOutputWriteFailed = errors.New("protocol output write failed")
	// ErrEventAfterResult 表示调用方试图在终态 result 后继续发射非 result 事件。
	ErrEventAfterResult = errors.New("protocol event emitted after result")
)

Functions

func IsKnownCapability

func IsKnownCapability(value Capability) bool

IsKnownCapability 报告 value 是否为稳定能力标识。

func IsKnownCode

func IsKnownCode(value Code) bool

IsKnownCode 报告 value 是否为 OK 或错误定义中的稳定错误码。

func IsKnownLifecycleTransition

func IsKnownLifecycleTransition(from, to StateStatus) bool

IsKnownLifecycleTransition 报告 from 到 to 是否位于静态迁移表中。

func IsKnownProgressStatus

func IsKnownProgressStatus(value ProgressStatus) bool

IsKnownProgressStatus 报告 value 是否为稳定进度状态。

func IsKnownRemediation

func IsKnownRemediation(value Remediation) bool

IsKnownRemediation 报告 value 是否为稳定处置动作。

func IsKnownStage

func IsKnownStage(value Stage) bool

IsKnownStage 报告 value 是否为稳定的 Runtime stage。

func IsKnownStateStatus

func IsKnownStateStatus(value StateStatus) bool

IsKnownStateStatus 报告 value 是否为稳定生命周期状态。

func WithControlCommandID

func WithControlCommandID(details map[string]any, commandID string) map[string]any

WithControlCommandID 复制 details,并把副本关联到一个控制命令。

Types

type Capability

type Capability string

Capability 是 hello 事件公告的稳定能力标识。

const (
	CapabilityStdinCancel Capability = "stdin.cancel"
	CapabilityStateV1     Capability = "state.v1"
	CapabilityLogStream   Capability = "log.stream"
	// CapabilityStdinShutdown 与 CapabilityStdinStatus 是 backend supervise 早已
	// 接受、却一直没有公告的两条 stdin 控制命令。README 与架构文档都规定
	// 「实际可用命令以 hello.capabilities 为准」,不公告等于让守规矩的调用方
	// 永远不发 shutdown,优雅关闭退化成 Job 强杀。
	CapabilityStdinShutdown Capability = "stdin.shutdown"
	CapabilityStdinStatus   Capability = "stdin.status"
)

协议 v1 的能力标识全集,逐项含义见 doc/架构设计.md「能力标识全集」。

func AllCapabilities

func AllCapabilities() []Capability

AllCapabilities 按文档顺序返回全部稳定能力标识的防御性副本。

type Code

type Code string

Code 是稳定且机器可读的协议结果码或错误码。

const (
	CodeOK                        Code = "OK"
	CodeInvalidArgument           Code = "INVALID_ARGUMENT"
	CodeInvalidControlCommand     Code = "INVALID_CONTROL_COMMAND"
	CodeInvalidVersion            Code = "INVALID_VERSION"
	CodeUnsupportedMode           Code = "UNSUPPORTED_MODE"
	CodeProtocolMismatch          Code = "PROTOCOL_MISMATCH"
	CodeOperationCancelled        Code = "OPERATION_CANCELLED"
	CodeOutputWriteFailed         Code = "OUTPUT_WRITE_FAILED"
	CodeInternalError             Code = "INTERNAL_ERROR"
	CodePathOutsideManagedRoot    Code = "PATH_OUTSIDE_MANAGED_ROOT"
	CodeUnsafeReparsePoint        Code = "UNSAFE_REPARSE_POINT"
	CodeDirectoryOccupied         Code = "DIRECTORY_OCCUPIED"
	CodeMutationInProgress        Code = "MUTATION_IN_PROGRESS"
	CodeBackendAlreadyRunning     Code = "BACKEND_ALREADY_RUNNING"
	CodeBackendStillRunning       Code = "BACKEND_STILL_RUNNING"
	CodeMutexOperationFailed      Code = "MUTEX_OPERATION_FAILED"
	CodeStateWriteFailed          Code = "STATE_WRITE_FAILED"
	CodeUpdateStateAmbiguous      Code = "UPDATE_STATE_AMBIGUOUS"
	CodeNetworkUnavailable        Code = "NETWORK_UNAVAILABLE"
	CodeMirrorExhausted           Code = "MIRROR_EXHAUSTED"
	CodeGitBranchNotFound         Code = "GIT_BRANCH_NOT_FOUND"
	CodeGitRemoteResolveFailed    Code = "GIT_REMOTE_RESOLVE_FAILED"
	CodeGitCloneFailed            Code = "GIT_CLONE_FAILED"
	CodeGitRepositoryInvalid      Code = "GIT_REPOSITORY_INVALID"
	CodeGitVersionMismatch        Code = "GIT_VERSION_MISMATCH"
	CodeGitRepoSwapFailed         Code = "GIT_REPO_SWAP_FAILED"
	CodeGitRepoCleanupFailed      Code = "GIT_REPO_CLEANUP_FAILED"
	CodeUVDownloadFailed          Code = "UV_DOWNLOAD_FAILED"
	CodeUVChecksumMismatch        Code = "UV_CHECKSUM_MISMATCH"
	CodeUVVersionMismatch         Code = "UV_VERSION_MISMATCH"
	CodeUVExecFailed              Code = "UV_EXEC_FAILED"
	CodePythonVersionFileMissing  Code = "PYTHON_VERSION_FILE_MISSING"
	CodePythonVersionInvalid      Code = "PYTHON_VERSION_INVALID"
	CodePythonVersionUnsupported  Code = "PYTHON_VERSION_UNSUPPORTED"
	CodePythonVersionIncompatible Code = "PYTHON_VERSION_INCOMPATIBLE"
	CodePythonInstallFailed       Code = "PYTHON_INSTALL_FAILED"
	CodePythonVersionMismatch     Code = "PYTHON_VERSION_MISMATCH"
	CodeLockfileMissing           Code = "LOCKFILE_MISSING"
	CodeLockfileOutdated          Code = "LOCKFILE_OUTDATED"
	CodeDependencySyncFailed      Code = "DEPENDENCY_SYNC_FAILED"
	CodeEnvironmentBroken         Code = "ENVIRONMENT_BROKEN"
	CodeEnvironmentRebuildFailed  Code = "ENVIRONMENT_REBUILD_FAILED"
	CodeBackendEntryNotFound      Code = "BACKEND_ENTRY_NOT_FOUND"
	CodeBackendSpawnFailed        Code = "BACKEND_SPAWN_FAILED"
	CodeBackendExitedBeforeReady  Code = "BACKEND_EXITED_BEFORE_READY"
	CodeBackendHealthTimeout      Code = "BACKEND_HEALTH_TIMEOUT"
	CodeBackendHealthInvalid      Code = "BACKEND_HEALTH_INVALID"
	CodeBackendIdentityMismatch   Code = "BACKEND_IDENTITY_MISMATCH"
	CodeBackendExitedUnexpectedly Code = "BACKEND_EXITED_UNEXPECTEDLY"
	CodeBackendRestartFailed      Code = "BACKEND_RESTART_FAILED"
	CodeBackendShutdownFailed     Code = "BACKEND_SHUTDOWN_FAILED"
	CodeBackendForceTerminated    Code = "BACKEND_FORCE_TERMINATED"
	// CodeBackendOrphansReaped 是 warning-only 码(增补 1 C14):后端主进程自己退出,
	// Job 里残留的孤儿被 Runtime 回收;与 BACKEND_FORCE_TERMINATED 互斥。
	CodeBackendOrphansReaped Code = "BACKEND_ORPHANS_REAPED"
)

type Common

type Common struct {
	Protocol    int       `json:"protocol"`
	Type        EventType `json:"type"`
	OperationID string    `json:"operationId"`
	Sequence    uint64    `json:"sequence"`
	Timestamp   string    `json:"timestamp"`
}

Common 包含所有协议事件共享的字段。

type ControlAction

type ControlAction func() error

ControlAction 提交一个已接受的控制命令。

type ControlCommand

type ControlCommand struct {
	Protocol  int         `json:"protocol"`
	Command   ControlKind `json:"command"`
	CommandID string      `json:"commandId"`
}

ControlCommand 是带协议版本的 stdin 控制请求。

type ControlDisposition

type ControlDisposition uint8

ControlDisposition 表示预处理后的命令能否被接受。

const (
	ControlDispositionUnknown ControlDisposition = iota
	ControlAccepted
	ControlNotApplicable
)

type ControlHandler

type ControlHandler interface {
	PrepareControl(ControlCommand) (ControlDisposition, ControlAction, error)
	CurrentControlStage() Stage
}

ControlHandler 预处理控制命令,但不立即施加副作用。 PrepareControl、其返回的 action 与 CurrentControlStage 都在 ControlReader.mu 持有期间运行, 因此不得回调当前 ControlReader 的 StopAccepting。

type ControlKind

type ControlKind string

ControlKind 标识一种 stdin 控制命令。

const (
	ControlCancel   ControlKind = "cancel"
	ControlShutdown ControlKind = "shutdown"
	ControlStatus   ControlKind = "status"
)

type ControlReader

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

ControlReader 读取并分派以换行符分隔的 stdin 控制命令。

func NewControlReader

func NewControlReader(
	input io.Reader,
	warnings ControlWarningEmitter,
	handler ControlHandler,
	allowed ...ControlKind,
) (*ControlReader, error)

NewControlReader 构造带输入与去重上限的 stdin 控制读取器。

func (*ControlReader) InputClosed

func (r *ControlReader) InputClosed() bool

InputClosed 报告 Run 是否因输入到达 EOF 而结束。 因 StopAccepting 或 ctx 取消结束时返回 false;Run 之前恒为 false。

func (*ControlReader) Run

func (r *ControlReader) Run(ctx context.Context) error

Run 同步读取控制命令,直到 EOF 或基础设施错误。 ControlReader 只能运行一次;并发或后续调用都会返回错误。

func (*ControlReader) StopAccepting

func (r *ControlReader) StopAccepting()

StopAccepting 阻止后续控制处理,并等待执行中的 prepare、action 或 warning 完成。 它不会中断正在阻塞的 stdin 读取。

type ControlShutdownPolicy

type ControlShutdownPolicy interface {
	StopAfterShutdown(ControlCommand) bool
}

ControlShutdownPolicy 可选地决定 accepted shutdown 是否立即停止 reader。 未实现该接口时保持默认行为:shutdown 先停止 reader,再执行 action。

type ControlWarningEmitter

type ControlWarningEmitter interface {
	EmitWarning(WarningEvent) error
}

ControlWarningEmitter 发射无效控制输入产生的 warning。 EmitWarning 在 ControlReader.mu 持有期间运行,因此不得回调当前 ControlReader 的 StopAccepting。

type Emitter

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

Emitter 通过 ProcessOutput 写出类型化协议事件。

func (*Emitter) EmitError

func (e *Emitter) EmitError(event ErrorEvent) error

EmitError 发射操作 error。

func (*Emitter) EmitLog

func (e *Emitter) EmitLog(event LogEvent) error

EmitLog 发射一行受管进程日志。

func (*Emitter) EmitProgress

func (e *Emitter) EmitProgress(event ProgressEvent) error

EmitProgress 发射 progress 事件。

func (*Emitter) EmitResult

func (e *Emitter) EmitResult(event ResultEvent) error

EmitResult 发射操作 result。

func (*Emitter) EmitState

func (e *Emitter) EmitState(event StateEvent) error

EmitState 发射生命周期 state 事件。

func (*Emitter) EmitWarning

func (e *Emitter) EmitWarning(event WarningEvent) error

EmitWarning 发射非终态 warning。

func (*Emitter) OperationID

func (e *Emitter) OperationID() string

OperationID 返回此 Emitter 所有事件共享的 ULID。

type ErrorDefinition

type ErrorDefinition struct {
	Code        Code
	ExitCode    int
	Retryable   bool
	Remediation []Remediation
}

ErrorDefinition 包含错误码对应的稳定行为四元组。

func AllErrorDefinitions

func AllErrorDefinitions() []ErrorDefinition

AllErrorDefinitions 按文档顺序返回全部稳定错误定义的防御性副本。

func LookupErrorDefinition

func LookupErrorDefinition(code Code) (ErrorDefinition, bool)

LookupErrorDefinition 返回 code 对应的稳定定义及是否存在。

type ErrorEvent

type ErrorEvent struct {
	Common
	Code        string         `json:"code"`
	Stage       Stage          `json:"stage"`
	Message     string         `json:"message"`
	Retryable   bool           `json:"retryable"`
	Remediation []string       `json:"remediation"`
	Details     map[string]any `json:"details"`
}

ErrorEvent 报告操作的主错误。

func NewErrorEvent

func NewErrorEvent(code Code, stage Stage, message string, details map[string]any) (ErrorEvent, error)

NewErrorEvent 根据 code 的稳定定义构造 error 事件。

type EventRenderer

type EventRenderer interface {
	RenderHello(HelloEvent) error
	RenderProgress(ProgressEvent) error
	RenderState(StateEvent) error
	RenderLog(LogEvent) error
	RenderWarning(WarningEvent) error
	RenderError(ErrorEvent) error
	RenderResult(ResultEvent) error
}

EventRenderer 在 Common 字段填充后投影协议事件。 渲染发生在 ProcessOutput 的串行化锁内,因此实现不得改变业务语义, 也不得回调当前 Emitter 或 ProcessOutput。

type EventType

type EventType string

EventType 标识一种 NDJSON 事件。

const (
	TypeHello    EventType = "hello"
	TypeProgress EventType = "progress"
	TypeState    EventType = "state"
	TypeLog      EventType = "log"
	TypeWarning  EventType = "warning"
	TypeError    EventType = "error"
	TypeResult   EventType = "result"
)

type ExitCode

type ExitCode = int

ExitCode 是进程结果的粗粒度分类。

const (
	ExitCodeSuccess            ExitCode = 0
	ExitCodeInvalidArgument    ExitCode = 2
	ExitCodeProtocolMismatch   ExitCode = 10
	ExitCodePreconditionFailed ExitCode = 20
	ExitCodeNetworkFailure     ExitCode = 30
	ExitCodeGitFailure         ExitCode = 40
	ExitCodeEnvironmentFailure ExitCode = 50
	ExitCodeBackendFailure     ExitCode = 60
	ExitCodeOperationConflict  ExitCode = 70
	ExitCodeOperationCancelled ExitCode = 130
)

type HelloEvent

type HelloEvent struct {
	Common
	RuntimeVersion string   `json:"runtimeVersion"`
	Command        string   `json:"command"`
	Capabilities   []string `json:"capabilities"`
}

HelloEvent 描述 Runtime 及即将开始的操作。

type HumanRenderer

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

HumanRenderer 把协议事件投影为确定性的人类可读文本。

func NewHumanRenderer

func NewHumanRenderer(stdout, stderr io.Writer) (*HumanRenderer, error)

NewHumanRenderer 创建 human renderer,并按 human 输出契约把事件路由到 stdout 或 stderr。

func (*HumanRenderer) RenderError

func (r *HumanRenderer) RenderError(event ErrorEvent) error

RenderError 把 error 事件渲染到 stderr。

func (*HumanRenderer) RenderHello

func (r *HumanRenderer) RenderHello(event HelloEvent) error

RenderHello 把 hello 事件渲染到 stdout。

func (*HumanRenderer) RenderLog

func (r *HumanRenderer) RenderLog(event LogEvent) error

RenderLog 仅把 stdout stream 写到 stdout,其他 stream 写到 stderr。

func (*HumanRenderer) RenderProgress

func (r *HumanRenderer) RenderProgress(event ProgressEvent) error

RenderProgress 把 progress 事件渲染到 stdout。

func (*HumanRenderer) RenderResult

func (r *HumanRenderer) RenderResult(event ResultEvent) error

RenderResult 把成功 result 渲染到 stdout,把失败 result 渲染到 stderr。

func (*HumanRenderer) RenderState

func (r *HumanRenderer) RenderState(event StateEvent) error

RenderState 把 state 事件渲染到 stdout。

func (*HumanRenderer) RenderWarning

func (r *HumanRenderer) RenderWarning(event WarningEvent) error

RenderWarning 把 warning 事件渲染到 stderr。

type LifecycleEmitter

type LifecycleEmitter interface {
	OperationEmitter
	EmitState(StateEvent) error
}

LifecycleEmitter 在操作事件之外还可发射生命周期迁移或只读状态快照。

type LifecycleMachine

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

LifecycleMachine 校验并应用进程内生命周期迁移。

func NewLifecycleMachine

func NewLifecycleMachine(initial StateStatus) (*LifecycleMachine, error)

NewLifecycleMachine 从已持久化的稳定生命周期状态创建状态机。

func (*LifecycleMachine) Current

func (m *LifecycleMachine) Current() StateStatus

Current 返回当前生命周期状态。

func (*LifecycleMachine) Initial

func (m *LifecycleMachine) Initial() StateStatus

Initial 返回构造状态机时使用的稳定状态。

func (*LifecycleMachine) RestartUsed

func (m *LifecycleMachine) RestartUsed() bool

RestartUsed 报告自动后端重启机会是否已经使用。

func (*LifecycleMachine) RollbackPreparation

func (m *LifecycleMachine) RollbackPreparation() error

RollbackPreparation 在发生受管状态变更前恢复稳定初始状态。

func (*LifecycleMachine) Transition

func (m *LifecycleMachine) Transition(next StateStatus) error

Transition 在静态迁移表和当前实例的状态化守卫都允许时把状态机移动到 next。 状态化守卫拒绝终态迁移、自循环,以及绕过或重复使用单次自动重启。

type LifecycleTransition

type LifecycleTransition struct {
	From StateStatus
	To   StateStatus
}

LifecycleTransition 表示一条合法的生命周期状态迁移。

func AllLifecycleTransitions

func AllLifecycleTransitions() []LifecycleTransition

AllLifecycleTransitions 按协议顺序返回生命周期迁移表的防御性副本。

type LogEvent

type LogEvent struct {
	Common
	Source  string `json:"source"`
	Stream  string `json:"stream"`
	Message string `json:"message"`
}

LogEvent 携带受管进程的一行可显示日志。

type NDJSONRenderer

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

NDJSONRenderer 把每个协议事件渲染为一个以换行符结束的 JSON object。

func NewNDJSONRenderer

func NewNDJSONRenderer(output io.Writer) (*NDJSONRenderer, error)

NewNDJSONRenderer 为 output 创建 NDJSON renderer。

func (*NDJSONRenderer) RenderError

func (r *NDJSONRenderer) RenderError(event ErrorEvent) error

RenderError 渲染 error 事件。

func (*NDJSONRenderer) RenderHello

func (r *NDJSONRenderer) RenderHello(event HelloEvent) error

RenderHello 渲染 hello 事件。

func (*NDJSONRenderer) RenderLog

func (r *NDJSONRenderer) RenderLog(event LogEvent) error

RenderLog 渲染 log 事件。

func (*NDJSONRenderer) RenderProgress

func (r *NDJSONRenderer) RenderProgress(event ProgressEvent) error

RenderProgress 渲染 progress 事件。

func (*NDJSONRenderer) RenderResult

func (r *NDJSONRenderer) RenderResult(event ResultEvent) error

RenderResult 渲染 result 事件。

func (*NDJSONRenderer) RenderState

func (r *NDJSONRenderer) RenderState(event StateEvent) error

RenderState 渲染 state 事件。

func (*NDJSONRenderer) RenderWarning

func (r *NDJSONRenderer) RenderWarning(event WarningEvent) error

RenderWarning 渲染 warning 事件。

type OperationEmitter

type OperationEmitter interface {
	EmitProgress(ProgressEvent) error
	EmitWarning(WarningEvent) error
	EmitError(ErrorEvent) error
	EmitResult(ResultEvent) error
}

OperationEmitter 发射一次性操作允许产生的事件。

type Option

type Option func(*emitterOptions) error

Option 配置 Emitter。

func WithClock

func WithClock(clock func() time.Time) Option

WithClock 注入事件时钟,主要供测试使用。

func WithOperationID

func WithOperationID(operationID string) Option

WithOperationID 注入已有的规范 ULID。

type ProcessOutput

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

ProcessOutput 独占进程级事件 renderer、sequence、串行化锁与单 Emitter 预约。

func NewProcessOutput

func NewProcessOutput(output io.Writer) (*ProcessOutput, error)

NewProcessOutput 创建进程内唯一的 NDJSON 输出所有者。

func NewProcessOutputWithRenderer

func NewProcessOutputWithRenderer(renderer EventRenderer) (*ProcessOutput, error)

NewProcessOutputWithRenderer 创建由 renderer 投影事件而非直接写 NDJSON 的 ProcessOutput。

func (*ProcessOutput) NewEmitter

func (o *ProcessOutput) NewEmitter(
	runtimeVersion string,
	command string,
	capabilities []string,
	options ...Option,
) (*Emitter, error)

NewEmitter 为单次操作预约此 ProcessOutput,并立即写出必须位于首位的 hello 事件。 同一个 ProcessOutput 不能创建第二个 Emitter。

type ProgressEvent

type ProgressEvent struct {
	Common
	Stage   Stage          `json:"stage"`
	Status  ProgressStatus `json:"status"`
	Current *int64         `json:"current,omitempty"`
	Total   *int64         `json:"total,omitempty"`
	Percent *float64       `json:"percent,omitempty"`
	Message string         `json:"message"`
}

ProgressEvent 报告稳定 stage 的执行进度。

type ProgressStatus

type ProgressStatus string

ProgressStatus 标识一个 stage 的进度状态。

const (
	ProgressPending   ProgressStatus = "pending"
	ProgressRunning   ProgressStatus = "running"
	ProgressSucceeded ProgressStatus = "succeeded"
	ProgressSkipped   ProgressStatus = "skipped"
	ProgressFailed    ProgressStatus = "failed"
	ProgressCancelled ProgressStatus = "cancelled"
)

func AllProgressStatuses

func AllProgressStatuses() []ProgressStatus

AllProgressStatuses 按文档顺序返回全部稳定进度状态的防御性副本。

type Remediation

type Remediation string

Remediation 是向协议消费方公开的稳定处置动作标识。

const (
	RemediationRetry              Remediation = "retry"
	RemediationRetrySync          Remediation = "retry-sync"
	RemediationRetryOtherMirror   Remediation = "retry-other-mirror"
	RemediationRebuildEnvironment Remediation = "rebuild-environment"
	RemediationStopBackend        Remediation = "stop-backend"
	RemediationRestartBackend     Remediation = "restart-backend"
	RemediationSelectVersion      Remediation = "select-version"
	RemediationUpdateDesktop      Remediation = "update-desktop"
	RemediationRunDoctor          Remediation = "run-doctor"
	RemediationCleanup            Remediation = "cleanup"
	RemediationOpenLog            Remediation = "open-log"
	RemediationContactSupport     Remediation = "contact-support"
)

func AllRemediations

func AllRemediations() []Remediation

AllRemediations 返回全部稳定处置动作的防御性副本。

type ResultEvent

type ResultEvent struct {
	Common
	Success     bool           `json:"success"`
	Code        string         `json:"code"`
	Stage       Stage          `json:"stage"`
	Status      string         `json:"status"`
	Message     string         `json:"message"`
	Retryable   bool           `json:"retryable"`
	Remediation []string       `json:"remediation"`
	Details     map[string]any `json:"details"`
}

ResultEvent 表示顶层操作的最终结果。

func NewFailureResult

func NewFailureResult(primary ErrorEvent, status, message string, details map[string]any) ResultEvent

NewFailureResult 构造失败 result,并复述主错误的稳定四元组。

func NewSuccessResult

func NewSuccessResult(stage Stage, status string, message string, details map[string]any) ResultEvent

NewSuccessResult 构造成功 result。

type Stage

type Stage string

Stage 标识稳定的 Runtime 操作阶段。

const (
	StageRuntimeHandshake    Stage = "runtime.handshake"
	StageDoctor              Stage = "doctor"
	StageBootstrap           Stage = "bootstrap"
	StageRepair              Stage = "repair"
	StageCleanup             Stage = "cleanup"
	StageUVCheck             Stage = "uv.check"
	StageUVDownload          Stage = "uv.download"
	StageUVVerify            Stage = "uv.verify"
	StageWorkspaceCheck      Stage = "workspace.check"
	StageWorkspaceClone      Stage = "workspace.clone"
	StageWorkspaceVerify     Stage = "workspace.verify"
	StageWorkspaceSwap       Stage = "workspace.swap"
	StageWorkspaceCleanup    Stage = "workspace.cleanup"
	StagePythonCheck         Stage = "python.check"
	StagePythonInstall       Stage = "python.install"
	StageDependenciesCheck   Stage = "dependencies.check"
	StageDependenciesSync    Stage = "dependencies.sync"
	StageDependenciesRebuild Stage = "dependencies.rebuild"
	StageBackendSpawn        Stage = "backend.spawn"
	StageBackendHealth       Stage = "backend.health"
	StageBackendRun          Stage = "backend.run"
	StageBackendRestart      Stage = "backend.restart"
	StageBackendShutdown     Stage = "backend.shutdown"
	StageBackendCleanup      Stage = "backend.cleanup"
)

func AllStages

func AllStages() []Stage

AllStages 按文档顺序返回全部稳定 stage 的防御性副本。

type StateEvent

type StateEvent struct {
	Common
	Stage   Stage          `json:"stage"`
	Status  StateStatus    `json:"status"`
	Message string         `json:"message"`
	Details map[string]any `json:"details"`
}

StateEvent 报告生命周期迁移或只读状态快照。

type StateStatus

type StateStatus string

StateStatus 标识 Runtime 生命周期状态。

const (
	StateUninitialized      StateStatus = "uninitialized"
	StatePreparingUV        StateStatus = "preparing_uv"
	StateSyncingRepository  StateStatus = "syncing_repository"
	StatePreparingPython    StateStatus = "preparing_python"
	StateSyncingEnvironment StateStatus = "syncing_environment"
	StateReadyToStart       StateStatus = "ready_to_start"
	StateStartingBackend    StateStatus = "starting_backend"
	StateRunning            StateStatus = "running"
	StateRestarting         StateStatus = "restarting"
	StateStoppingBackend    StateStatus = "stopping_backend"
	StateEnvironmentBroken  StateStatus = "environment_broken"
	StateBackendFailed      StateStatus = "backend_failed"
	StateStopped            StateStatus = "stopped"
)

func AllStateStatuses

func AllStateStatuses() []StateStatus

AllStateStatuses 按文档顺序返回全部稳定生命周期状态的防御性副本。

type WarningEvent

type WarningEvent struct {
	Common
	Code        string         `json:"code"`
	Stage       Stage          `json:"stage"`
	Message     string         `json:"message"`
	Retryable   bool           `json:"retryable"`
	Remediation []string       `json:"remediation"`
	Details     map[string]any `json:"details"`
}

WarningEvent 报告不会终止操作的异常情况。

func NewWarningEvent

func NewWarningEvent(code Code, stage Stage, message string, details map[string]any) (WarningEvent, error)

NewWarningEvent 根据 code 的稳定定义构造 warning 事件。

type WarningSummary

type WarningSummary struct {
	Code        string         `json:"code"`
	Stage       Stage          `json:"stage"`
	Message     string         `json:"message"`
	Retryable   bool           `json:"retryable"`
	Remediation []string       `json:"remediation"`
	Details     map[string]any `json:"details"`
}

WarningSummary 是已发射 warning 与调用方可变输入隔离的业务字段快照,会随终态 result 返回。

Directories

Path Synopsis
Package contracttest 校验 Runtime 命令发射的原始协议 NDJSON。
Package contracttest 校验 Runtime 命令发射的原始协议 NDJSON。

Jump to

Keyboard shortcuts

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