docs(runtime): internal/runtime/loop 44 个文件注释改中文(逐行 1:1,代码零字节改动)

主人 2026-10-03 拍板「注释一律中文」;本模块按长期分批协议(一个模块一次派工)执行。
注释行数 1329 → 1329 逐行 1:1(含中文 33 → 1304);行尾注释 5 条一并译。
校验:机械校验(非注释改动行)= 空;独立 Go AST 程序(剥注释复渲)证明 44/44 文件代码全等;
全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
gofmt:capacity_loop_test.go / flow.go 改动前即未格式化,按铁律保留原样未动。
This commit is contained in:
AskaEth committed 2026-10-03 22:28:21 +08:00
1 parent 355f81d04a
commit 91e8d7a029
44 files changed
+1315 -1315

No files matched your search

+34 -34
View File
@@ -7,37 +7,37 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
)
// This file owns the loop's per-turn role resolution (DevDocs/design/22 §4.2):
// one process now hosts several roles at once, so everything that used to be read
// off the Loop's construction-time binding — the system prompt (via the agent),
// the memory namespace, the emotion machine and the reasoning knobs — is resolved
// from the turn's SessionEnv instead.
// 本文件拥有循环的按 turn 角色解析(DevDocs/design/22 §4.2):
// 一个进程现在同时承载多个角色,因此过去从
// Loop 构造期绑定读取的一切 —— 系统提示词(经 agent)、
// 记忆命名空间、情绪机与推理旋钮 —— 改为从该 turn 的
// SessionEnv 解析。
//
// The resolution is deliberately three tiny functions over ctx rather than a
// field on the Loop: the Loop is shared by every concurrent session, so storing a
// resolved role on it would race, while ctx already carries the per-turn env.
// Every role-scoped read must go through these helpers, so prompt, memory,
// emotion and thinking can never disagree about "who is answering".
// 解析刻意做成 ctx 上的三个小函数,而不是 Loop 上的
// 字段:Loop 由所有并发会话共享,把解析出的角色存在
// 它上面会产生数据竞争,而 ctx 本就携带按 turn 的 env。
// 所有角色作用域读取都必须走这些辅助函数,使提示词、记忆、
// 情绪与思考永远不会对「谁在回答」产生分歧。
// LoopKnobs are the per-role model/reasoning knobs injected into every request the
// loop builds. It mirrors the three construction-time options
// (Options.Thinking / Options.ReasoningEffort / Options.ThinkingShowToUser) so a
// caller can resolve them per role while the options keep their meaning as the
// default. A nil Thinking and an empty ReasoningEffort mean "do not intervene",
// and a nil ThinkingShowToUser means "broadcast thinking frames as usual".
// LoopKnobs 是注入循环构建的每个请求的按角色模型/推理
// 旋钮。它镜像三个构造期选项
// (Options.Thinking / Options.ReasoningEffort / Options.ThinkingShowToUser),使
// 调用方能按角色解析它们,同时这些选项仍作为
// 默认值生效。nil Thinking 与空 ReasoningEffort 表示「不干预」,
// nil ThinkingShowToUser 表示「照常广播思考帧」。
type LoopKnobs struct {
// Thinking is the reasoning directive (budget / explicit switch) for the role.
// Thinking 是该角色的推理指令(预算 / 显式开关)。
Thinking *model.Thinking
// ReasoningEffort is the OpenAI-compatible strength knob for the role.
// ReasoningEffort 是该角色兼容 OpenAI 的强度旋钮。
ReasoningEffort string
// ThinkingShowToUser gates the thinking frames broadcast for the role's turns.
// ThinkingShowToUser 控制该角色各 turn 的思考帧是否广播。
ThinkingShowToUser *bool
}
// personaFor returns the role the current turn speaks as (design/22 §2): the
// session env's explicit role when the caller resolved one, otherwise the loop's
// configured role (Options.PersonaID, the global default). Both the prompt/memory
// and the emotion hook read it, so a turn can never mix two roles.
// personaFor 返回当前 turn 发言所作为的角色(design/22 §2):调用方
// 解析出角色时取会话环境的显式角色,否则取循环
// 配置的角色(Options.PersonaID,全局默认)。提示词/记忆
// 与情绪钩子都读它,因此一个 turn 绝不会混用两个角色。
func (l *Loop) personaFor(ctx context.Context) string {
if pid := sessionEnvFrom(ctx).PersonaID; pid != "" {
return pid
@@ -45,12 +45,12 @@ func (l *Loop) personaFor(ctx context.Context) string {
return l.personaID
}
// agentFor returns the agent that carries the current turn's system prompt: the
// per-role agent pool entry when one exists, otherwise the loop's default agent
// (design/22 §4.2 方案 A). A session bound to a role that has no registered agent —
// an unknown/deleted persona, or a caller that wired no pool — falls back to the
// default agent rather than failing the turn, and its memory scope still follows
// personaFor, so the fallback can never silently re-scope memory.
// agentFor 返回承载当前 turn 系统提示词的 agent:存在
// 按角色 agent 池条目时用它,否则用循环的默认 agent
// (design/22 §4.2 方案 A)。会话绑定到一个没有注册 agent 的角色 ——
// 未知/已删除的人格,或未接任何池的调用方 —— 时回退到
// 默认 agent 而不是让该 turn 失败,且其记忆作用域仍跟随
// personaFor,因此该回退绝不会悄悄改变记忆作用域。
func (l *Loop) agentFor(ctx context.Context) *agent.Agent {
if len(l.agents) > 0 {
if ag := l.agents[l.personaFor(ctx)]; ag != nil {
@@ -60,11 +60,11 @@ func (l *Loop) agentFor(ctx context.Context) *agent.Agent {
return l.agent
}
// knobsFor resolves the reasoning knobs for the current turn: the resolver's
// per-role values when it knows the role, otherwise the loop's configured
// defaults. A resolver that does not recognize the role (ok = false) deliberately
// keeps the defaults rather than zeroing the knobs, so an unregistered id behaves
// like the default role instead of silently disabling reasoning.
// knobsFor 解析当前 turn 的推理旋钮:解析器
// 认识该角色时用其按角色取值,否则用循环配置的
// 默认值。不认识该角色的解析器(ok = false)刻意
// 保留默认值而不是把旋钮清零,使未注册的 id 表现
// 如同默认角色,而不是悄悄禁用推理。
func (l *Loop) knobsFor(ctx context.Context) LoopKnobs {
def := LoopKnobs{
Thinking: l.thinking,