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

+50 -60
View File
@@ -12,94 +12,86 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/trace"
)
// Defaults for the orchestration layer.
// 编排层的默认值。
const (
// DefaultMaxParallel is the maximum number of sub-agents that run at once
// when Options.MaxParallel is non-positive.
// DefaultMaxParallel 是 Options.MaxParallel 为非正数时同时运行的子代理
// 数量上限。
DefaultMaxParallel = 4
// defaultAgentID is the comm probe identity used when Options.AgentID is
// blank and a probe must be built from Bus.
// defaultAgentID 是 Options.AgentID 为空、且必须由 Bus 构建探针时所用的
// comm 探针身份。
defaultAgentID = "orchestrator"
)
// Options configures a Scheduler built by New. All fields are optional; each nil
// dependency degrades gracefully (a missing Loop makes sub-agents fail fast, a
// missing Comm skips progress events, a missing Approver makes Approve error,
// and so on).
// Options 配置由 New 构建的 Scheduler。所有字段都可选;每个为 nil 的依赖都优雅
// 降级(缺 Loop 使子代理快速失败,缺 Comm 跳过进度事件,缺 Approver 使 Approve
// 报错,等等)。
type Options struct {
// MaxParallel caps how many sub-agents execute concurrently. Excess sub-agents
// queue until a slot frees. Non-positive selects DefaultMaxParallel (4).
// MaxParallel 限制同时执行的子代理数量。超出的子代理排队直到有空位。
// 非正数则选用 DefaultMaxParallel(4)。
MaxParallel int
// PerAgentTimeout bounds every sub-agent's run. When it elapses the sub-agent
// is aborted (status aborted). Non-positive means no timeout.
// PerAgentTimeout 约束每个子代理的运行时限。超时后该子代理被中止
// (状态 aborted)。非正数表示不设时限。
PerAgentTimeout time.Duration
// Loop is the execution template: a *loop.Loop used to run every sub-agent.
// It must be safe for concurrent Run calls (as loop.Loop documents); the
// template's agent/tools/guardrails/persona apply to every sub-agent. When
// nil, sub-agents fail fast with ErrNoRunner.
// Loop 是执行模板:用于运行每个子代理的 *loop.Loop。它必须能安全地并发调用
// Run(如 loop.Loop 自身文档所述);模板的 agent/tools/guardrails/persona
// 适用于每个子代理。为 nil 时子代理以 ErrNoRunner 快速失败。
Loop *loop.Loop
// Bus is the in-process event bus used for progress events and, when Comm is
// nil, to build a default comm probe. When nil no events are published.
// Bus 是进程内事件总线,用于发布进度事件;Comm 为 nil 时也由它构建默认
// comm 探针。为 nil 时不发布任何事件。
Bus bus.Bus
// Comm is the comm probe used to publish progress events. When nil, a probe
// bound to AgentID is built from Bus (when Bus is non-nil).
// Comm 是用于发布进度事件的 comm 探针。为 nil 时,用 Bus(Bus 非 nil 时)
// 构建一个绑定到 AgentID 的探针。
Comm *comm.Probe
// Memory is the long-term memory store used by SinkMemory. Optional.
// Memory 是 SinkMemory 所用的长期记忆存储。可选。
Memory *memory.Store
// Tracer emits a per-sub-agent span (kind subagent) around each run. Optional.
// Tracer 为每次运行发射一个子代理 span(kind subagent)。可选。
Tracer *trace.Tracer
// Flow, when non-nil, receives the sub-agent span transitions so a spawned
// branch appears in the flow graph of the session named by
// AgentSpec.ParentSession (design/19 §2). *loop.FlowPublisher is the
// production implementation. Optional: a nil sink leaves sub-agent branches
// unvisualized (the sub-agent's own inner spans still fold into the parent
// graph through the loop's flow branch).
// Flow 非 nil 时接收子代理 span 的状态转移,使派生出的分支出现在
// AgentSpec.ParentSession 所指会话的流程图里(design/19 §2)。
// *loop.FlowPublisher 是生产实现。可选:sink 为 nil 时子代理分支不被可视化
// (子代理自身的内部 span 仍会经循环的 flow 分支折进父图)。
Flow FlowSpanSink
// Approver records sensitive-operation review-and-approve (代审) triggered by
// Approve. Policy judgement belongs to the upper layer. Optional.
// Approver 记录由 Approve 触发的敏感操作「代审」。策略判断属于上层。可选。
Approver *audit.Approver
// PersonaExists reports whether a role id can run with its own instructions,
// i.e. whether the per-role agent pool behind Loop (loop.Options.Agents) has an
// entry for it (design/22 §8-2). It gates AgentSpec.PersonaID: a dispatch naming
// an id this returns false for is rejected with ErrUnknownPersona rather than
// running as the default role's prompt. Nil means "this deployment knows no
// role", so a dispatch that names a role is rejected too — deciding nothing
// silently is the point. Omitting the persona is unaffected by this.
// PersonaExists 报告某个角色 id 能否以自身指令运行,即 Loop 背后的按角色
// agent 池(loop.Options.Agents)里是否有它的条目(design/22 §8-2)。它把守
// AgentSpec.PersonaID:指名了一个它返回 false 的 id 的派发会被拒绝并返回
// ErrUnknownPersona,而不是按默认角色的提示词运行。为 nil 意味着「本部署不认识
// 任何角色」,因此指名角色的派发同样被拒 —— 关键是绝不悄悄替调用方做决定。
// 省略 persona 的派发不受它影响。
PersonaExists func(personaID string) bool
// Logger is the base logger. Nil is replaced with a discard logger tagged with
// source "orchestration".
// Logger 是基础 logger。为 nil 时替换为标注了来源 "orchestration" 的
// 丢弃式 logger。
Logger *slog.Logger
// AgentID is the comm probe identity. When blank and a probe must be built
// from Bus, "orchestrator" is used.
// AgentID 是 comm 探针身份。为空且必须由 Bus 构建探针时,使用
// "orchestrator"。
AgentID string
}
// FlowSpanSink folds a span transition into a session's live flow graph so the
// realtime visualization shows the work in flight (design/19 §1). *loop.FlowPublisher
// is the production implementation; tests substitute a capturing fake. The
// interface keeps orchestration from depending on the concrete publisher beyond
// the loop template it already takes.
// FlowSpanSink 把一个 span 的状态转移折进会话的实时流程图,使实时可视化展示在飞的
// 工作(design/19 §1)。*loop.FlowPublisher 是生产实现;测试替换为捕获式假实现。
// 该接口让编排层除了已有的循环模板之外,不必再依赖那个具体发布器。
type FlowSpanSink interface {
// SpanStarted registers a running placeholder node for a span that just began.
// SpanStarted 为一个刚刚开始的 span 登记运行中的占位节点。
SpanStarted(sessionID string, sp *trace.Span)
// SpanFinished folds a just-finished span into the session graph.
// SpanFinished 把一个刚结束的 span 折进会话图。
SpanFinished(sessionID string, sp *trace.Span)
}
// wrapLoop adapts a *loop.Loop into the runner interface, substituting a no-op
// runner (fail-fast) when the template is nil.
// wrapLoop 把 *loop.Loop 适配成 runner 接口;模板为 nil 时替换为空操作 runner
// (快速失败)。
func wrapLoop(l *loop.Loop) runner {
if l == nil {
return noopRunner{}
@@ -107,12 +99,11 @@ func wrapLoop(l *loop.Loop) runner {
return l
}
// scopedRunner picks the runner that executes sub: without a tool whitelist the
// configured template runs as-is(缺省全开,继承主 agent 全量工具集);with one,
// a *loop.Loop template is derived through WithToolWhitelist so only the listed
// tools pass(design/05 §7 裁决 02.4.1). A non-loop runner (tests inject mocks)
// is returned unchanged — the whitelist still rides the run context for it to
// observe via loop.ToolWhitelistFrom.
// scopedRunner 挑选执行 sub 的 runner:没有工具白名单时按原样运行已配置的模板
// (缺省全开,继承主 agent 全量工具集);有白名单时,为 *loop.Loop 模板经
// WithToolWhitelist 派生出只放行所列工具的新模板(design/05 §7 裁决 02.4.1)。
// 非 loop 的 runner(测试注入的 mock)原样返回 —— 白名单仍随运行上下文传递,它可经
// loop.ToolWhitelistFrom 自行读取。
func (s *Scheduler) scopedRunner(sub *SubAgent) runner {
if len(sub.ToolWhitelist) == 0 {
return s.runner
@@ -123,9 +114,8 @@ func (s *Scheduler) scopedRunner(sub *SubAgent) runner {
return s.runner
}
// effectiveTimeout resolves the deadline one sub-agent runs under: a positive
// per-call override wins; otherwise the scheduler's PerAgentTimeout applies
// (non-positive = no deadline).
// effectiveTimeout 解析某个子代理运行时所受的时限:正的按调用覆盖优先;否则套用
// 调度器的 PerAgentTimeout(非正 = 无期限)。
func effectiveTimeout(override, schedulerDefault time.Duration) time.Duration {
if override > 0 {
return override