command

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package command 提供统一的 Worker Command 分发器。

Dispatcher 负责启动各 lane 订阅(cmd.run、cmd.control、cmd.interaction、cmd.file), 并将收到的统一 WorkerCommand 分发到对应的 handler。 其中 cmd.run lane 使用手动确认订阅(SubscribeManualDurable),其余 lane 使用自动确认订阅(Subscribe)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	OrgID    uint
	WorkerID uint
}

Config 是 Dispatcher 的配置。

type ControlHandler

type ControlHandler interface {
	HandleControlCommand(ctx context.Context, cmd messaging.WorkerCommand) error
}

ControlHandler 处理 cmd.control lane 的 cancel 命令。

type Dispatcher

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

Dispatcher 是统一的 worker 命令分发器。

func New

func New(cfg Config, sub Subscriber, handlers Handlers) (*Dispatcher, error)

New 创建新的 Dispatcher。

func (*Dispatcher) Run

func (d *Dispatcher) Run(ctx context.Context) error

Run 并发启动五个 lane 订阅并阻塞,直到 ctx 取消或任一订阅异常退出。

run lane 使用手动 Ack 订阅(SubscribeManualDurable), 因为 run handler 需要先将消息持久化到本地 inbox 再 Ack, 以实现 at-least-once 的崩溃恢复语义。

其余 lane(control、interaction、skill、file)使用自动 Ack 订阅 (Subscribe),因为它们的 handler 同步完成处理,无需手动控制确认时机。

任一订阅异常退出时会取消其他 lane 的 context。

type FileHandler added in v0.2.5

type FileHandler interface {
	HandleFileCommand(ctx context.Context, cmd messaging.WorkerCommand) error
}

FileHandler 处理 cmd.file lane 的项目文件命令。

type Handlers

type Handlers struct {
	Run         RunHandler
	Control     ControlHandler
	Interaction InteractionHandler
	File        FileHandler
}

Handlers 显式包含四类 handler,构造时一次性校验。

type InteractionHandler

type InteractionHandler interface {
	HandleInteractionCommand(ctx context.Context, cmd messaging.WorkerCommand) error
}

InteractionHandler 处理 cmd.interaction lane 的 approval/question 命令。

type RunHandler

type RunHandler interface {
	HandleRunCommand(ctx context.Context, cmd messaging.WorkerCommand, delivery eventbus.ManualDelivery) error
}

RunHandler 处理 cmd.run lane 的 agent run 命令。 delivery 提供手动 Ack 控制(Term/Nak/Ack/NakWithDelay/InProgress), handler 根据处理阶段决定确认方式:

  • 永久错误 → Term(不再重试)
  • 临时错误 → NakWithDelay(延迟重试)
  • 成功持久化后 → Ack(异步执行)

type Subscriber

type Subscriber interface {
	Subscribe(ctx context.Context, topic string, consumer string, handler func(msg *nats.Msg)) error
	SubscribeManualDurable(ctx context.Context, topic string, consumer string, handler func(msg *nats.Msg)) error
}

Subscriber 是 Dispatcher 所需的最小订阅接口。 包含自动确认和手动确认两种订阅方式。

Directories

Path Synopsis
Package interaction 处理 cmd.interaction lane 的交互式命令 (approval.resolve 和 question.answer),通过 Resolver 接口转发。
Package interaction 处理 cmd.interaction lane 的交互式命令 (approval.resolve 和 question.answer),通过 Resolver 接口转发。
Package projectfile handles project file commands on the worker that owns the workspace.
Package projectfile handles project file commands on the worker that owns the workspace.
run
Package run 提供 worker agent run 命令的 cmd.run lane handler。
Package run 提供 worker agent run 命令的 cmd.run lane handler。
inbox
Package inbox provides a strongly-typed durable inbox for worker run commands.
Package inbox provides a strongly-typed durable inbox for worker run commands.

Jump to

Keyboard shortcuts

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