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:
1 parent
355f81d04a
commit
91e8d7a029
44 files changed
+1315
-1315
No files matched your search
@@ -6,48 +6,48 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
|
||||
)
|
||||
|
||||
// This file owns the loop's turn boundary: the point where one user turn has
|
||||
// settled (a Run produced a Result) and the state that follows the persona —
|
||||
// emotion and affection, design/01 §2 — is advanced outside the loop. The loop
|
||||
// itself stays persona- and emotion-agnostic (design/16 §3.3: the engine
|
||||
// generates text; state and persistence belong to the layers around it), so it
|
||||
// only reports the turn and records the mood label the hook hands back.
|
||||
// 本文件拥有循环的 turn 边界:一个用户 turn 落定之处
|
||||
// (Run 产出了 Result),以及紧随人格的状态 ——
|
||||
// 情绪与好感度,design/01 §2 —— 在循环之外推进。循环
|
||||
// 本身保持不感知人格与情绪(design/16 §3.3:引擎
|
||||
// 生成文本;状态与持久化属于其外围分层),因此它
|
||||
// 只上报该 turn 并记录钩子回传的情绪标签。
|
||||
|
||||
// TurnEnd describes one settled turn to the loop's OnTurnEnd hook. It carries
|
||||
// everything an observer needs without the loop knowing what the observer does.
|
||||
// TurnEnd 向循环的 OnTurnEnd 钩子描述一个已落定的 turn。它携带
|
||||
// 观察者所需的全部信息,而循环无需知道观察者做什么。
|
||||
type TurnEnd struct {
|
||||
// SessionID is the conversation the turn belonged to.
|
||||
// SessionID 是该 turn 所属的会话。
|
||||
SessionID string
|
||||
// PersonaID is the role the turn speaks as: the session env's resolved role when
|
||||
// the caller supplied one, otherwise the loop's configured default
|
||||
// (design/22 §4.2). It keeps the observer persona-scoped (design/01 §2): the
|
||||
// emotion machine and affection of that role — and only that role — advance.
|
||||
// PersonaID 是该 turn 发言所作为的角色:调用方提供了会话环境
|
||||
// 解析出的角色时用它,否则用循环配置的默认角色
|
||||
// (design/22 §4.2)。它使观察者保持人格作用域(design/01 §2):该角色
|
||||
// 的情绪机与好感度 —— 且仅该角色 —— 推进。
|
||||
PersonaID string
|
||||
// UserText is the latest user message of the turn ("" when the turn carried
|
||||
// no user text, e.g. a resumed tool round).
|
||||
// UserText 是该 turn 最新的用户消息(该 turn 未携带用户文本时
|
||||
// 为 "",例如恢复的工具轮)。
|
||||
UserText string
|
||||
// AssistantText is the turn's final assistant text.
|
||||
// AssistantText 是该 turn 最终的 assistant 文本。
|
||||
AssistantText string
|
||||
// StopReason classifies how the turn ended.
|
||||
// StopReason 归类该 turn 如何结束。
|
||||
StopReason string
|
||||
// Steps is the number of model steps the turn took.
|
||||
// Steps 是该 turn 经过的模型步数。
|
||||
Steps int
|
||||
// Env is the conversation's resolved isolation environment (owner / group /
|
||||
// stranger), so a hook can keep a restricted conversation read-only.
|
||||
// Env 是会话解析出的隔离环境(owner / group /
|
||||
// stranger),使钩子能让受限会话保持只读。
|
||||
Env SessionEnv
|
||||
}
|
||||
|
||||
// TurnEndHook observes a settled turn and returns the persona's mood label for
|
||||
// it ("" when the caller tracks no emotion). It runs once per settled turn — not
|
||||
// once per model step — so a multi-step tool turn applies its effect exactly
|
||||
// once. It must not block: it runs on the Run path after the answer is complete,
|
||||
// and its return value is carried on Result.Mood to the persistence layer.
|
||||
// TurnEndHook 观察一个已落定的 turn 并返回该 turn 的人格情绪标签
|
||||
// (调用方不追踪情绪时为 "")。它每个落定的 turn 运行一次 —— 而非
|
||||
// 每个模型步一次 —— 因此多步工具 turn 的效果恰好应用
|
||||
// 一次。它不得阻塞:它在答案完成后于 Run 路径上运行,
|
||||
// 其返回值经 Result.Mood 携带至持久化层。
|
||||
type TurnEndHook func(TurnEnd) string
|
||||
|
||||
// settleTurn reports a settled turn to the hook (when wired) and records the
|
||||
// returned mood label on the result, so the persisted assistant message carries
|
||||
// the turn's mood (design/16 §3.3). The conversation environment travels on ctx,
|
||||
// so a group/stranger turn reaches the hook as restricted.
|
||||
// settleTurn 把落定的 turn 上报给钩子(已接线时),并把
|
||||
// 返回的情绪标签记录到结果上,使持久化的 assistant 消息携带
|
||||
// 该 turn 的情绪(design/16 §3.3)。会话环境经 ctx 传递,
|
||||
// 因此群聊/陌生人 turn 以受限身份到达钩子。
|
||||
func (l *Loop) settleTurn(ctx context.Context, sessionID string, msgs []model.Message, res *Result) {
|
||||
if l.onTurnEnd == nil {
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user