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

+19 -19
View File
@@ -2,44 +2,44 @@ package loop
import "context"
// loopSessionIDKey is the context key for the session id the current Run is
// driving. It is seeded at the top of Run and read where the loop emits a
// session-scoped UI event (capacity_awaken), so the event carries the right
// session rather than being treated as global.
// loopSessionIDKey 是当前 Run 所驱动 session id 的 context key。
// 它在 Run 顶部播种,并在循环发出会话级 UI 事件
// (capacity_awaken)处读取,使事件携带正确的会话,
// 而不是被当作全局事件。
type loopSessionIDKey struct{}
// withLoopSession returns a context carrying the Run's session id.
// withLoopSession 返回携带 Run 会话 id 的 context。
func withLoopSession(ctx context.Context, sessionID string) context.Context {
return context.WithValue(ctx, loopSessionIDKey{}, sessionID)
}
// loopSession returns the session id on ctx, or "" when none was seeded (a
// defensive fallback for a caller that drives the loop outside Run).
// loopSession 返回 ctx 上的 session id;未播种时返回 ""(为在
// Run 之外驱动循环的调用方提供的防御性兜底)。
func loopSession(ctx context.Context) string {
s, _ := ctx.Value(loopSessionIDKey{}).(string)
return s
}
// SessionFromContext returns the session id the enclosing Run is driving, or ""
// when none was attached. It is exported so a tool executing inside the loop can
// attribute the work it starts (a spawned sub-agent, a background task) to the
// conversation that launched it — never inferred from model output.
// SessionFromContext 返回外层 Run 所驱动的 session id;未挂载时
// 返回 ""。它导出是为了让循环内执行的工具能把其启动的工作
// (派生的子代理、后台任务)归属到发起它的会话 —— 绝不
// 从模型输出推断。
func SessionFromContext(ctx context.Context) string { return loopSession(ctx) }
// loopTurnIDKey is the context key for the assistant turn the current Run is
// producing. The gateway attaches it (WithTurnID) before starting a turn so the
// streaming events the loop emits can be correlated to that turn by the client.
// loopTurnIDKey 是当前 Run 正在产出的 assistant turn 的 context key。
// gateway 在开始一个 turn 前挂载它(WithTurnID),使循环发出的
// 流式事件能被客户端关联到该 turn。
type loopTurnIDKey struct{}
// WithTurnID attaches turnID to ctx so the streaming events the loop emits carry
// the turn they belong to. It is exported because the gateway calls it once per
// turn, before Run; a caller that attaches none leaves the events' TurnID empty,
// which keeps the correlation fields backward compatible.
// WithTurnID 把 turnID 挂到 ctx 上,使循环发出的流式事件携带
// 所属的 turn。它导出是因为 gateway 每个 turn 在 Run 之前调用一次;
// 未挂载的调用方会让事件的 TurnID 为空,
// 从而保持关联字段向后兼容。
func WithTurnID(ctx context.Context, turnID string) context.Context {
return context.WithValue(ctx, loopTurnIDKey{}, turnID)
}
// loopTurn returns the turn id on ctx, or "" when none was attached.
// loopTurn 返回 ctx 上的 turn id;未挂载时返回 ""。
func loopTurn(ctx context.Context) string {
s, _ := ctx.Value(loopTurnIDKey{}).(string)
return s