docs(comments): 注释中文化 · internal/runtime/orchestration(29 文件,纯替换)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

- 只翻注释/文档字符串:剥离注释后代码行逐字节不变(机械校验只剩允许的行尾注释形态)
- 裁决编号与 design 节号(02.4.3 / 11.4.2 / design/05 §9 等)逐字保留
- 复核:go build 绿;orchestration 及其子包(audit/comm)测试绿;gofmt 干净
This commit is contained in:
AskaEth committed 2026-10-04 13:30:04 +08:00
1 parent fe90f64a56
commit eb1828ee7a
29 files changed
+751 -949

No files matched your search

+59 -70
View File
@@ -9,65 +9,59 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
)
// Status is the lifecycle state of a spawned sub-agent.
// Status 是已派发子代理的生命周期状态。
//
// The lifecycle is pending -> running -> one of the terminal states
// (done, failed, aborted). A sub-agent is terminal exactly when Terminal
// reports true.
// 生命周期为 pending -> running -> 终结态之一(done、failed、aborted)。
// 当且仅当 Terminal 报告 true 时,子代理处于终结态。
type Status string
const (
// StatusPending means the sub-agent was created but has not started.
// StatusPending 表示子代理已创建但尚未开始。
StatusPending Status = "pending"
// StatusRunning means the sub-agent's loop is executing.
// StatusRunning 表示子代理的循环正在执行。
StatusRunning Status = "running"
// StatusDone means the loop completed and produced a result.
// StatusDone 表示循环已完成并产出结果。
StatusDone Status = "done"
// StatusFailed means the loop returned an error.
// StatusFailed 表示循环返回了错误。
StatusFailed Status = "failed"
// StatusAborted means the sub-agent was canceled or timed out.
// StatusAborted 表示子代理被取消或超时。
StatusAborted Status = "aborted"
)
// Terminal reports whether s is a final state. Pending and running are not
// terminal; every sub-agent ends in one of the three terminal states.
// Terminal 报告 s 是否为终态。pending 与 running 不是终态;每个子代理都以三种终结态
// 之一收尾。
func (s Status) Terminal() bool {
return s == StatusDone || s == StatusFailed || s == StatusAborted
}
// AgentSpec describes a sub-agent to spawn. Goal is required; the rest are
// optional and bound onto the sub-agent for the upper layer to interpret.
// AgentSpec 描述一个待派发的子代理。Goal 必填;其余字段可选,绑定到子代理上供上层
// 解读。
type AgentSpec struct {
// Goal is the objective the sub-agent works toward. It is required.
// Goal 是子代理要达成的目标。必填。
Goal string
// RoleID selects the role/persona the sub-agent is bound to.
// RoleID 选择子代理绑定的角色/persona。
RoleID string
// PersonaID is the role the sub-agent actually runs as (design/22 §8-2): it
// answers with that role's instructions and reads/writes that role's memory
// scope — "她以该角色身份临时替班". Spawn stamps it onto the sub-agent run's
// session env, which is the single input the loop resolves the prompt, the
// memory namespace, the emotion and the thinking knobs from, so the four can
// never disagree. Blank keeps the pre-existing behavior byte for byte: the
// sub-agent inherits the spawning turn's env, i.e. the parent session's role.
// The id must be one this process can run with its own agent
// (*Scheduler).PersonaKnown; Spawn rejects an unknown one with
// ErrUnknownPersona instead of silently falling back to the default role.
// PersonaID 是子代理实际充当的角色(design/22 §8-2):它以该角色的指令作答,
// 读写该角色的记忆作用域 ——「她以该角色身份临时替班」。Spawn 把它盖到子代理
// 运行的会话 env 上,而那是循环解析提示词、记忆命名空间、情绪与思考旋钮的唯一
// 输入,因此四者不可能互相矛盾。留空则逐字节保持既有行为:子代理继承派发回合的
// env,即父会话的角色。该 id 必须是本进程能以自身 agent 运行的角色
// ((*Scheduler).PersonaKnown);Spawn 会拒绝未知 id 并返回 ErrUnknownPersona,
// 而不是静默回落到默认角色。
PersonaID string
// Mode selects the behavior mode (e.g. "engineer") for the role.
// Mode 选择该角色的行为模式(例如 "engineer")。
Mode string
// Context is the initial, isolated conversation context. Spawn deep-copies
// it, so later mutation by the caller does not affect the sub-agent.
// Context 是初始的、隔离的会话上下文。Spawn 会深拷贝它,因此调用方此后的修改
// 不会影响子代理。
Context []model.Message
// AttachInfo is free-form attachment/injection text supplied at spawn.
// AttachInfo 是派发时提供的自由形式附加/注入文本。
AttachInfo string
// ParentSession is the session whose live flow graph owns the branch, so the
// sub-agent's span and its inner steps render as a swimlane of the spawning
// session's graph instead of as a graph of their own (design/19 §2). The
// spawning tool takes it from loop.FlowOwnerFromContext. Blank disables the
// flow attribution; it never affects which session the sub-agent runs in, so
// its checkpoint, memory and stream isolation are unchanged.
// ParentSession 是拥有该分支的会话,其实时流程图将承载子代理的 span 及其内部
// 步骤,使它们渲染成派发会话图的一条泳道,而不是自成一张图(design/19 §2)。
// 派发工具从 loop.FlowOwnerFromContext 取得它。留空则关闭流图归属;它绝不影响
// 子代理在哪个会话里运行,因此其 checkpoint、记忆与流隔离都不变。
ParentSession string
// Data carries an optional structured payload for the caller's use.
// Data 承载供调用方使用的可选结构化载荷。
Data any
// ToolWhitelist 限定该子代理可执行的工具集合(design/05 §7 裁决 02.4.1):
// 缺省(nil/空)=继承主 agent 的全量工具集;显式列出=只放行所列工具,
@@ -78,70 +72,65 @@ type AgentSpec struct {
Timeout time.Duration
}
// Progress event names published on the agent-to-agent bus via the Scheduler's
// comm probe. External subscribers can match on these to drive a monitoring
// panel (DevDocs/design/05-子代理.md §9).
// 经 comm 探针发布到 agent 间总线上的进度事件名。外部订阅方可据此匹配,驱动一个
// 监控面板(DevDocs/design/05-子代理.md §9)。
const (
// EventDispatched is published when a sub-agent is created.
// EventDispatched 在子代理被创建时发布。
EventDispatched = "subagent.dispatched"
// EventStarted is published when a sub-agent begins running.
// EventStarted 在子代理开始运行时发布。
EventStarted = "subagent.started"
// EventDone is published when a sub-agent finishes successfully.
// EventDone 在子代理成功结束时发布。
EventDone = "subagent.done"
// EventFailed is published when a sub-agent fails.
// EventFailed 在子代理失败时发布。
EventFailed = "subagent.failed"
// EventAborted is published when a sub-agent is canceled or times out.
// EventAborted 在子代理被取消或超时时发布。
EventAborted = "subagent.aborted"
)
// Progress is the status snapshot carried by a progress event's Data payload.
// Progress 是进度事件 Data 载荷所承载的状态快照。
type Progress struct {
// AgentID is the spawned sub-agent id.
// AgentID 是已派发的子代理 id。
AgentID string
// Goal is the sub-agent's objective.
// Goal 是子代理的目标。
Goal string
// RoleID is the bound role/persona.
// RoleID 是绑定的角色/persona。
RoleID string
// Mode is the bound behavior mode.
// Mode 是绑定的行为模式。
Mode string
// Status is the sub-agent's status at publish time.
// Status 是子代理在发布时刻的状态。
Status Status
}
// Sentinel errors returned by the Scheduler. They are wrapped with %w at call
// sites so callers can test with errors.Is.
// Scheduler 返回的哨兵错误。调用点以 %w 包装它们,因此调用方可用 errors.Is 判断。
var (
// ErrMissingGoal is returned by Spawn when the spec Goal is blank.
// ErrMissingGoal 在 spec 的 Goal 为空时由 Spawn 返回。
ErrMissingGoal = errors.New("orchestration: missing goal")
// ErrNoRunner is returned when a sub-agent runs with no loop runner
// configured (Options.Loop was nil).
// ErrNoRunner 在子代理运行时未配置循环 runner(Options.Loop 为 nil)时返回。
ErrNoRunner = errors.New("orchestration: no loop runner configured")
// ErrNoApprover is returned by Approve when no *audit.Approver was injected.
// ErrNoApprover 在未注入 *audit.Approver 时由 Approve 返回。
ErrNoApprover = errors.New("orchestration: no approver configured")
// ErrNoMemory is returned by SinkMemory when no *memory.Store was injected.
// ErrNoMemory 在未注入 *memory.Store 时由 SinkMemory 返回。
ErrNoMemory = errors.New("orchestration: no memory store configured")
// ErrAgentNotFound is returned by Abort when the sub-agent id is unknown.
// ErrAgentNotFound 在子代理 id 未知时由 Abort 返回。
ErrAgentNotFound = errors.New("orchestration: sub-agent not found")
// ErrUnknownPersona is returned by Spawn when a spec names a role this process
// has no per-role agent for (design/22 §8-2). It is a rejection, not a
// fallback: running the sub-agent with the default role's prompt while the
// caller asked for another role would silently defeat the request.
// ErrUnknownPersona 在 spec 指名了一个本进程没有对应按角色 agent 的角色时由
// Spawn 返回(design/22 §8-2)。它是拒绝,不是回退:调用方要的是另一个角色,
// 却用默认角色的提示词运行子代理,那会静默地背离请求本意。
ErrUnknownPersona = errors.New("orchestration: unknown persona")
// ErrNoScheduler is returned by the spawn tool when it was built without a
// scheduler (a wiring mistake, reported instead of panicking).
// ErrNoScheduler 在派发工具被构建时未带调度器(接线错误,如实报告而不 panic)
// 时由该工具返回。
ErrNoScheduler = errors.New("orchestration: no scheduler configured")
)
// cloneMessages returns a deep copy of msgs: the message slice and each message's
// content parts are copied so the result shares no memory with the input. It is
// used at Spawn to give each sub-agent an isolated context. A nil input yields
// nil; a non-nil empty input yields a non-nil empty slice.
// cloneMessages 返回 msgs 的深拷贝:消息切片与每条消息的内容分段都被复制,因此结果
// 与入参不共享内存。它在 Spawn 处用于给每个子代理一个隔离上下文。nil 入参产出 nil;
// 非 nil 的空入参产出非 nil 的空切片。
func cloneMessages(msgs []model.Message) []model.Message {
if msgs == nil {
return nil
@@ -158,8 +147,8 @@ func cloneMessages(msgs []model.Message) []model.Message {
return out
}
// compactText shortens s to at most n runes for inclusion in a summary, appending
// an ellipsis when it was truncated. It never splits a multi-byte rune.
// compactText 把 s 截短到至多 n 个字符以用于摘要,被截断时追加省略号。它绝不切开
// 多字节字符。
func compactText(s string, n int) string {
s = strings.TrimSpace(s)
r := []rune(s)