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
@@ -8,26 +8,26 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/trace"
|
||||
)
|
||||
|
||||
// graphUpdateSubject is the bus subject the FlowPublisher publishes each round's
|
||||
// live flow graph on. The gateway hub subscribes to ws.> and relays it as the
|
||||
// WS event type graph_update (design/19 §1).
|
||||
// graphUpdateSubject 是 FlowPublisher 发布每轮实时
|
||||
// flow 图所用的 bus subject。gateway hub 订阅 ws.> 并将其
|
||||
// 作为 WS 事件类型 graph_update 转发(design/19 §1)。
|
||||
const graphUpdateSubject = "ws.graph_update"
|
||||
|
||||
// allowedSessions is the predicate signature used to gate which sessions publish
|
||||
// flow graphs (the owner's web sessions), so IM/stranger/sub-agent turns never
|
||||
// leak into the admin panel. A nil predicate allows every session.
|
||||
// allowedSessions 是用于控制哪些会话可发布
|
||||
// flow 图的谓词签名(主人的 web 会话),使 IM/陌生人/子代理轮次绝不
|
||||
// 泄露进管理面板。谓词为 nil 时允许所有会话。
|
||||
type allowedSessions func(sessionID string) bool
|
||||
|
||||
// FlowPublisher accumulates a per-session flow graph from the loop's trace spans
|
||||
// and publishes ws.graph_update as each span starts/finishes, giving the frontend
|
||||
// a realtime input→think→tool→output graph (design/19 §1). It is nil-tolerant
|
||||
// (a nil publisher is a no-op) and safe for concurrent use; session graphs are
|
||||
// serialized under one mutex because parallel tool spans finish concurrently.
|
||||
// FlowPublisher 从循环的 trace span 累积每会话 flow 图,
|
||||
// 并在每个 span 开始/结束时发布 ws.graph_update,给前端
|
||||
// 一张实时的 input→think→tool→output 图(design/19 §1)。它容忍 nil
|
||||
// (nil 发布者为空操作)且并发安全;会话图
|
||||
// 在同一把互斥锁下串行化,因为并行的工具 span 会并发完成。
|
||||
//
|
||||
// Ownership: one session owns one live round. A Run that declares itself a branch
|
||||
// of another session (loop.WithFlowBranch) never calls StartRound/EndRound and
|
||||
// publishes its spans under the owning session instead, so a sub-agent renders as
|
||||
// a swimlane of the parent's graph rather than as a second graph (design/19 §2).
|
||||
// 归属:一个会话拥有一个实时轮次。声明自己是另一会话分支的
|
||||
// Run(loop.WithFlowBranch)绝不调用 StartRound/EndRound,
|
||||
// 而是把其 span 发布到所属会话下,因此子代理渲染为
|
||||
// 父图的一条泳道,而不是第二张图(design/19 §2)。
|
||||
type FlowPublisher struct {
|
||||
mu sync.Mutex
|
||||
publish func(subject string, payload any)
|
||||
@@ -36,10 +36,10 @@ type FlowPublisher struct {
|
||||
rounds map[string]int
|
||||
}
|
||||
|
||||
// NewFlowPublisher builds a FlowPublisher. publish, when non-nil, is called with
|
||||
// graphUpdateSubject and a *trace.FlowGraph snapshot on every span transition.
|
||||
// allow, when non-nil, gates which session ids are published (returning false
|
||||
// drops the session entirely). Both may be nil (a nil publish is a no-op).
|
||||
// NewFlowPublisher 构建一个 FlowPublisher。publish 非 nil 时,会在
|
||||
// 每次 span 状态迁移时以 graphUpdateSubject 与 *trace.FlowGraph
|
||||
// 快照调用。allow 非 nil 时,控制哪些 session id 可发布(返回
|
||||
// false 则整个会话被丢弃)。两者都可以为 nil(nil publish 为空操作)。
|
||||
func NewFlowPublisher(publish func(subject string, payload any), allow func(sessionID string) bool) *FlowPublisher {
|
||||
return &FlowPublisher{
|
||||
publish: publish,
|
||||
@@ -49,9 +49,9 @@ func NewFlowPublisher(publish func(subject string, payload any), allow func(sess
|
||||
}
|
||||
}
|
||||
|
||||
// StartRound begins a fresh graph for sessionID, seeding an input node from the
|
||||
// user text and publishing the initial frame. It resets the session's previous
|
||||
// round, so each user turn is its own graph.
|
||||
// StartRound 为 sessionID 开始一张新图,用用户文本
|
||||
// 播种一个 input 节点并发布初始帧。它重置该会话的上一
|
||||
// 轮次,因此每个用户 turn 都是自己的一张图。
|
||||
func (p *FlowPublisher) StartRound(sessionID, inputText string) {
|
||||
if sessionID == "" || !p.allowed(sessionID) {
|
||||
return
|
||||
@@ -67,9 +67,9 @@ func (p *FlowPublisher) StartRound(sessionID, inputText string) {
|
||||
p.publishLocked(g)
|
||||
}
|
||||
|
||||
// EndRound finalizes the round by seeding an output node from the reply and
|
||||
// publishing the final frame. It keeps the graph around so a client that misses
|
||||
// the final frame can replay the last snapshot on refresh.
|
||||
// EndRound 用回复播种一个 output 节点并发布最终帧,
|
||||
// 以此收尾该轮次。它保留该图,使错过最终帧的客户端
|
||||
// 刷新时能重放最后一份快照。
|
||||
func (p *FlowPublisher) EndRound(sessionID, outputText string) {
|
||||
if sessionID == "" || !p.allowed(sessionID) {
|
||||
return
|
||||
@@ -84,8 +84,8 @@ func (p *FlowPublisher) EndRound(sessionID, outputText string) {
|
||||
p.publishLocked(g)
|
||||
}
|
||||
|
||||
// SpanStarted records a running placeholder node for a span that just began.
|
||||
// State-transition spans are omitted by the graph builder.
|
||||
// SpanStarted 为一个刚开始的 span 记录一个运行中的占位
|
||||
// 节点。state_transition span 会被图构建器省略。
|
||||
func (p *FlowPublisher) SpanStarted(sessionID string, sp *trace.Span) {
|
||||
if sp == nil || sessionID == "" || !p.allowed(sessionID) {
|
||||
return
|
||||
@@ -101,8 +101,8 @@ func (p *FlowPublisher) SpanStarted(sessionID string, sp *trace.Span) {
|
||||
}
|
||||
}
|
||||
|
||||
// SpanFinished folds a just-finished span into the session graph as a final node
|
||||
// (status done/error) and publishes. It must be called after the span's Finish.
|
||||
// SpanFinished 把一个刚结束的 span 作为最终节点(状态 done/error)
|
||||
// 并入会话图并发布。必须在 span 的 Finish 之后调用。
|
||||
func (p *FlowPublisher) SpanFinished(sessionID string, sp *trace.Span) {
|
||||
if sp == nil || sessionID == "" || !p.allowed(sessionID) {
|
||||
return
|
||||
@@ -117,7 +117,7 @@ func (p *FlowPublisher) SpanFinished(sessionID string, sp *trace.Span) {
|
||||
p.publishLocked(g)
|
||||
}
|
||||
|
||||
// publishLocked publishes a snapshot of g. Callers must hold p.mu.
|
||||
// publishLocked 发布 g 的一份快照。调用方必须持有 p.mu。
|
||||
func (p *FlowPublisher) publishLocked(g *trace.RunGraph) {
|
||||
if p.publish == nil {
|
||||
return
|
||||
@@ -125,7 +125,7 @@ func (p *FlowPublisher) publishLocked(g *trace.RunGraph) {
|
||||
p.publish(graphUpdateSubject, g.Snapshot())
|
||||
}
|
||||
|
||||
// allowed reports whether a session's graphs should be published.
|
||||
// allowed 报告某会话的图是否应当发布。
|
||||
func (p *FlowPublisher) allowed(sessionID string) bool {
|
||||
if p.allow == nil {
|
||||
return true
|
||||
@@ -133,8 +133,8 @@ func (p *FlowPublisher) allowed(sessionID string) bool {
|
||||
return p.allow(sessionID)
|
||||
}
|
||||
|
||||
// lastUserText returns the text of the newest user message in messages, used to
|
||||
// label the round's input node. It returns "" when no user text is present.
|
||||
// lastUserText 返回 messages 中最新用户消息的文本,用于
|
||||
// 标注该轮的 input 节点。没有用户文本时返回 ""。
|
||||
func lastUserText(messages []model.Message) string {
|
||||
for i := len(messages) - 1; i >= 0; i-- {
|
||||
if messages[i].Role != model.RoleUser {
|
||||
|
||||
Reference in new issue
Block a user