docs(comments): 注释中文化 · internal/runtime/model + internal/services/backthink(54 文件,纯替换)
- 只翻注释/文档字符串:`go/scanner` 剥注释后按 token 序列+literal 逐 token 比对,**54/54 文件 SAME**;
改动文件总行数与 HEAD 漂移 = 0(严格 1:1,无合并/拆行)
- 裁决编号与 design 节号逐字保留(03.4.1/03.4.2/03.4.3/14.4.1/14.4.5/07.4.2-4、design/04 §3.1/§3.2 等);
`chat_template_kwargs` / `enable_thinking` / `reasoning_effort` / `thinking:{type}` 字段名与形状说明未动
- 存疑译法(已登记):`persona` 在叙事语境用「角色」、标识符语境保留 `persona`(仓库既有模块本身混用);
`rung`→「级」;`provider` 存在「提供商/提供者」两种落笔(可按需一键统一)
- 复核:build/vet 绿 + 两包测试绿;gofmt 干净;残留英文注释 0 条
- 既有存量(未修,只报告):`model/anthropic_test.go` 612 行 >500;`applyAnthropicEvent` 115 行 >80
This commit is contained in:
1 parent
f5cf117482
commit
3dc1232bc2
54 files changed
+1923
-1923
No files matched your search
@@ -7,24 +7,24 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
|
||||
)
|
||||
|
||||
// recentContextCount is how many of the most recent main-session messages are
|
||||
// folded into one autonomous think as conversation context. Compile-time so no
|
||||
// magic number appears in the run path.
|
||||
// recentContextCount 是折进一次自主思考作为对话上下文的最新
|
||||
// 主会话消息条数。编译期常量,因此
|
||||
// 运行路径里不出现魔法数字。
|
||||
const recentContextCount = 20
|
||||
|
||||
// recentProvider returns the most recent messages of a session in oldest-first
|
||||
// order, the tail an autonomous think reads to "see" the main conversation.
|
||||
// *history.Store satisfies it; tests inject a fake. It is the narrow slice of
|
||||
// history.HistoryStore that the thinker actually depends on, matching the loop's
|
||||
// own checkpointStore style of minimal seam interfaces.
|
||||
// recentProvider 以最旧在前的顺序返回会话最近的消息,
|
||||
// 即一次自主思考为「看到」主对话而读取的尾部。
|
||||
// *history.Store 满足它;测试注入 fake。它是 thinker 实际
|
||||
// 依赖的那一小片 history.HistoryStore,与 loop 自己的
|
||||
// checkpointStore 风格的最小接缝接口一致。
|
||||
type recentProvider interface {
|
||||
Recent(ctx context.Context, sessionID string, n int) ([]history.Message, error)
|
||||
}
|
||||
|
||||
// mainContext returns the most recent main-session messages converted to model
|
||||
// messages (oldest-first) for one autonomous think. A nil provider, a failed read
|
||||
// or an empty tail all yield nil so the think degrades to the guidance prompt
|
||||
// alone rather than failing the pass (design/20 §2).
|
||||
// mainContext 把最近的主会话消息转换为 model 消息
|
||||
// (最旧在前),供一次自主思考使用。提供者为 nil、读取失败
|
||||
// 或尾部为空都得到 nil,因此该次思考降级为仅用引导提示词,
|
||||
// 而不是让这一轮失败(design/20 §2)。
|
||||
func mainContext(ctx context.Context, prov recentProvider) []model.Message {
|
||||
if prov == nil {
|
||||
return nil
|
||||
@@ -40,9 +40,9 @@ func mainContext(ctx context.Context, prov recentProvider) []model.Message {
|
||||
return msgs
|
||||
}
|
||||
|
||||
// mapHistoryMessage converts one persisted chat message into a model message,
|
||||
// translating the history role and preserving an image part when the message
|
||||
// carries one so a multimodal main model still sees it.
|
||||
// mapHistoryMessage 把一条持久化的 chat 消息转换为 model 消息,
|
||||
// 翻译历史角色,并在消息携带图片时保留该图片片段,
|
||||
// 因此多模态主模型仍能看到它。
|
||||
func mapHistoryMessage(h history.Message) model.Message {
|
||||
msg := model.Message{
|
||||
Role: historyRoleToModel(h.Role),
|
||||
@@ -54,8 +54,8 @@ func mapHistoryMessage(h history.Message) model.Message {
|
||||
return msg
|
||||
}
|
||||
|
||||
// historyRoleToModel maps a persisted chat role to the model's role vocabulary,
|
||||
// defaulting unknown roles to the user lane.
|
||||
// historyRoleToModel 把持久化的 chat 角色映射到 model 的角色词汇,
|
||||
// 未知角色默认为 user 通道。
|
||||
func historyRoleToModel(role string) model.Role {
|
||||
switch role {
|
||||
case history.RoleAssistant:
|
||||
@@ -67,9 +67,9 @@ func historyRoleToModel(role string) model.Role {
|
||||
}
|
||||
}
|
||||
|
||||
// thinkInput assembles the full input for one unattended think: the recent
|
||||
// main-session context (if any) followed by a single guidance prompt turn, so the
|
||||
// runtime reflects on real conversation rather than an empty macro prompt.
|
||||
// thinkInput 拼装一次无人值守思考的完整输入:最近的主会话语境
|
||||
// (若有)后跟单个引导提示词回合,因此
|
||||
// 运行时针对真实对话反思,而不是空泛的宏提示词。
|
||||
func thinkInput(recent []model.Message, trigger string) []model.Message {
|
||||
out := make([]model.Message, 0, len(recent)+1)
|
||||
out = append(out, recent...)
|
||||
@@ -77,19 +77,19 @@ func thinkInput(recent []model.Message, trigger string) []model.Message {
|
||||
return out
|
||||
}
|
||||
|
||||
// guidancePrompt is the instruction handed to the runtime for one unattended
|
||||
// autonomous thought. Unlike the old backgroundPrompt it deliberately encourages a
|
||||
// warm, targeted proactive message and drops the "do not produce a chat-style
|
||||
// message" suppression. Identity/permission stay on the actor metadata + owner env,
|
||||
// never on this prompt text (red line); the prompt only describes the running
|
||||
// environment (memories readable/writable, tools callable) that the env already
|
||||
// grants.
|
||||
// guidancePrompt 是交给运行时的一次无人值守自主思考的
|
||||
// 指令。与旧 backgroundPrompt 不同,它刻意鼓励
|
||||
// 温暖、有针对性的主动消息,并去掉「不要产生 chat 风格
|
||||
// 消息」的抑制。身份/权限始终在 actor 元数据 + owner env 上,
|
||||
// 绝不在这段提示词文本上(红线);提示词只描述运行
|
||||
// 环境(记忆可读/可写、工具可调用),而那是 env 已经
|
||||
// 授予的。
|
||||
//
|
||||
// The prompt asks for a compact structured closing — a push/no_push decision, an
|
||||
// optional target channel and the message body — so the service can honor her own
|
||||
// judgment instead of gating on the trigger's importance (design/20 §2 P2). The
|
||||
// format is guidance, not a contract: parseProactive fails safe when she omits or
|
||||
// mangles it.
|
||||
// 提示词要求一个紧凑的结构化收尾——push/no_push 决策、
|
||||
// 可选的目标渠道与消息正文——好让服务尊重她自己的
|
||||
// 判断,而不是按触发的重要度把关(design/20 §2 P2)。该
|
||||
// 格式是引导而非契约:她省略或
|
||||
// 写乱该格式时,parseProactive 失败安全。
|
||||
//
|
||||
// 启动轮(裁决 07.4.4,design/12 §1)走 startupPrompt:以角色口吻说一句拟人化的
|
||||
// 「回来」问候。
|
||||
|
||||
Reference in new issue
Block a user