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

+42 -42
View File
@@ -6,72 +6,72 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/capability/restrict"
)
// SessionEnv is the per-conversation context that gates memory injection and
// extraction for one Run call. It travels on the call's context rather than on
// the shared Loop because Loop is reused across concurrent sessions (every
// channel/group/stranger message resolves its own isolation boundary); storing it
// on the Loop struct would race.
// SessionEnv 是每次 Run 调用中控制记忆注入与
// 提取的按会话上下文。它挂在调用的 context 上而不是
// 共享的 Loop 上,因为 Loop 会在并发会话间复用(每条
// channel/群聊/陌生人消息都解析出自己的隔离边界);把它
// 存在 Loop 结构体上会产生数据竞争。
type SessionEnv struct {
// ActorEnv is the resolved actor environment: owner, group_member, stranger.
// It is the strongly-typed identity lane decided structurally by the channel
// layer (design/11 §0), never inferred from prompt text.
// ActorEnv 是解析出的 actor 环境:owner、group_member、stranger。
// 它是由 channel 层结构化判定的强类型身份车道
//(design/11 §0),绝不从提示词文本推断。
ActorEnv restrict.ActorEnv
// MemWritable reports whether this conversation may write shared memory. It is
// true only for the owner's private conversation; group chats and strangers
// are read-only (design/02 §3, design/11 §2).
// MemWritable 报告该会话是否可以写共享记忆。它仅
// 在主人的私聊中为 true;群聊与陌生人
// 只读(design/02 §3, design/11 §2)。
MemWritable bool
// PersonaID is the role this conversation speaks as (design/22 §2/§4.2), resolved
// per turn by the caller (normally the gateway's session-binding resolver). Empty
// means "inherit the loop's configured role" (Options.PersonaID, the global default
// role), which keeps every pre-multi-character caller — channelbridge, backthink,
// internal autonomous passes — behaving exactly as before. It scopes the system
// prompt, the memory namespace, the emotion machine and the thinking budget; it is
// NOT an identity or permission input: ActorEnv/MemWritable alone decide access
// (project red line).
// PersonaID 是该会话发言所作为的角色(design/22 §2/§4.2),由调用方
// 每 turn 解析(通常是 gateway 的会话绑定解析器)。为空
// 表示「继承循环配置的角色」(Options.PersonaID,全局默认
// 角色),这使所有多角色之前的调用方 —— channelbridge、backthink、
// 内部自主流程 —— 行为与从前完全一致。它界定系统
// 提示词、记忆命名空间、情绪机与思考预算的作用域;它
// 不是身份或权限输入:仅由 ActorEnv/MemWritable 决定访问
// (项目红线)。
PersonaID string
}
// Restricted reports whether this is a group-chat or stranger conversation, i.e.
// the read-only memory isolation context. Because MemWritable is true only for
// the owner's private conversation, !MemWritable is exactly the restricted set.
// Restricted 报告这是否为群聊或陌生人会话,即
// 只读记忆隔离上下文。由于 MemWritable 仅在
// 主人的私聊中为 true,!MemWritable 恰好就是受限集合。
func (e SessionEnv) Restricted() bool { return !e.MemWritable }
// OwnerEnv returns the full-access owner session environment (private
// conversation, memory read+write). It is the Web main-session and internal
// automated-task default, matching the pre-existing owner-full behavior. It binds
// no explicit role (PersonaID is empty), so the loop falls back to its configured
// default role — the caller that knows the session's role sets PersonaID on the
// returned value (design/22 §4.2).
// OwnerEnv 返回全权限的主人会话环境(私聊,
// 记忆读写)。它是 Web 主会话与内部
// 自动化任务的默认值,与既有的 owner 全权限行为一致。它不绑定
// 显式角色(PersonaID 为空),因此循环回退到其配置的
// 默认角色 —— 知道会话角色的调用方在返回值上
// 设置 PersonaID(design/22 §4.2)。
func OwnerEnv() SessionEnv {
return SessionEnv{ActorEnv: restrict.ActorOwner, MemWritable: true}
}
// defaultSessionEnv is the owner-full environment used when a caller attaches no
// explicit env: full memory read and write, the pre-existing behavior.
// defaultSessionEnv 是调用方未挂载显式 env 时使用的
// owner 全权限环境:记忆全读写,即既有行为。
func defaultSessionEnv() SessionEnv {
return OwnerEnv()
}
type sessionEnvKey struct{}
// WithSessionEnv attaches env to ctx so Run's memory gates honor the
// group/stranger read-only isolation per call. It is concurrency-safe: the env
// travels with the call's context and is never stored on the shared Loop.
// WithSessionEnv 把 env 挂到 ctx 上,使 Run 的记忆门按调用遵循
// 群聊/陌生人只读隔离。它是并发安全的:env
// 随调用的 context 传递,绝不存放在共享的 Loop 上。
func WithSessionEnv(ctx context.Context, env SessionEnv) context.Context {
return context.WithValue(ctx, sessionEnvKey{}, env)
}
// SessionEnvFrom returns the environment attached to ctx by WithSessionEnv, or the
// owner-full default when none was attached (backward compatible). It is the read
// side of WithSessionEnv, for a caller that receives only a context — a Chatter
// implementation that must know the turn's role/isolation boundary, or a test
// asserting what an inbound path resolved. The value is display/scope metadata
// only: identity and permission were already decided by the actor metadata before
// the env existed (project red line).
// SessionEnvFrom 返回 WithSessionEnv 挂到 ctx 上的环境;
// 未挂载时返回 owner 全权限默认值(向后兼容)。它是
// WithSessionEnv 的读侧,供只拿到 context 的调用方使用 —— 例如
// 必须知道该 turn 角色/隔离边界的 Chatter 实现,或
// 断言某入站路径解析结果的测试。该值仅是展示/作用域元数据:
// 身份与权限在 env 存在之前就已由 actor 元数据决定
// (项目红线)。
func SessionEnvFrom(ctx context.Context) SessionEnv { return sessionEnvFrom(ctx) }
// sessionEnvFrom returns the env attached to ctx, or the owner-full default when
// none was attached (backward compatible).
// sessionEnvFrom 返回挂到 ctx 上的 env;未挂载时返回
// owner 全权限默认值(向后兼容)。
func sessionEnvFrom(ctx context.Context) SessionEnv {
if ctx == nil {
return defaultSessionEnv()