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
@@ -6,26 +6,26 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Importance is the estimated severity of an event that woke a thinking pass.
|
||||
// Under design/20 §2 P2 it no longer decides *whether* she wants to speak (her
|
||||
// conclusion does); it decides the hard-gate exemptions: a critical safety event
|
||||
// punches through work/busy and quiet hours (裁决 07.4.2), and a high event still
|
||||
// passes quiet hours (the pre-existing cascade semantics).
|
||||
// Importance 是唤醒一轮思考的事件估计严重度。
|
||||
// 在 design/20 §2 P2 之下,它不再决定她*想不想*说话(那由她的
|
||||
// 结论决定);它决定硬门豁免:critical 安全事件
|
||||
// 穿透工作/忙碌与安静时段(裁决 07.4.2),而 high 事件仍
|
||||
// 通过安静时段(既有的级联语义)。
|
||||
type Importance int
|
||||
|
||||
const (
|
||||
// ImportanceLow is a routine trigger (e.g. the periodic heartbeat).
|
||||
// ImportanceLow 是例行触发(如周期性心跳)。
|
||||
ImportanceLow Importance = iota
|
||||
// ImportanceNormal is an ordinary event worth reflecting on (device change).
|
||||
// ImportanceNormal 是值得反思的普通事件(设备变化)。
|
||||
ImportanceNormal
|
||||
// ImportanceHigh is a notable event (a reminder the user set firing).
|
||||
// ImportanceHigh 是值得注意的事件(用户设置的提醒触发)。
|
||||
ImportanceHigh
|
||||
// ImportanceCritical is a safety-critical event that punches through
|
||||
// work/busy and quiet hours (裁决 07.4.2 安全域豁免).
|
||||
// ImportanceCritical 是穿透
|
||||
// 工作/忙碌与安静时段的安全关键事件(裁决 07.4.2 安全域豁免)。
|
||||
ImportanceCritical
|
||||
)
|
||||
|
||||
// String returns a stable label for logs and records.
|
||||
// String 返回用于日志与记录的稳定标签。
|
||||
func (i Importance) String() string {
|
||||
switch i {
|
||||
case ImportanceLow:
|
||||
@@ -41,55 +41,55 @@ func (i Importance) String() string {
|
||||
}
|
||||
}
|
||||
|
||||
// longIdleThreshold is the gap after the owner's last message beyond which the
|
||||
// activity gate only lets a genuinely important event through — except heartbeat
|
||||
// passes, which are never held by a long-silent gap (裁决 07.4.3). Compile-time
|
||||
// so no magic number appears.
|
||||
// longIdleThreshold 是主人最后一条消息之后的间隔,超过它活动门
|
||||
// 只放行真正重要的事件——但心跳轮除外,
|
||||
// 它们永远不会被长期静默的间隔拦下(裁决 07.4.3)。编译期
|
||||
// 常量,因此不出现魔法数字。
|
||||
const longIdleThreshold = 2 * time.Hour
|
||||
|
||||
// UserState describes the user's current condition as observed from device
|
||||
// telemetry (heart rate, sleep) and schedule (work, busy). It is the negative
|
||||
// signal in the interrupt decision: a sleeping, working or busy user is left
|
||||
// alone. Boredom (0..1) is the soft positive dial that widens interruption.
|
||||
// UserState 描述由设备遥测(心率、睡眠)与日程(工作、忙碌)
|
||||
// 观察到的用户当前状况。它是打扰决策里的负向
|
||||
// 信号:睡眠、工作或忙碌中的用户不被打扰。
|
||||
// 无聊度(0..1)是放宽打扰的软性正向旋钮。
|
||||
type UserState struct {
|
||||
// HeartRateBPM is the current heart rate, 0 when unknown.
|
||||
// HeartRateBPM 是当前心率,未知时为 0。
|
||||
HeartRateBPM int
|
||||
// Sleeping reports whether the user is currently asleep from sleep tracking.
|
||||
// Sleeping 报告睡眠追踪显示用户当前是否睡着。
|
||||
Sleeping bool
|
||||
// Working reports whether the user is in a work/scheduled block.
|
||||
// Working 报告用户是否处于工作/日程时段。
|
||||
Working bool
|
||||
// Busy reports whether the user is marked busy (calendar / do-not-disturb).
|
||||
// Busy 报告用户是否被标记为忙碌(日历 / 免打扰)。
|
||||
Busy bool
|
||||
// Boredom ranges 0..1. Higher boredom means the user is idle and more open
|
||||
// to a gentle interruption. Under design/20 §2 P2 the push intent is her own
|
||||
// conclusion, so this dial no longer gates the decision; it is kept as a
|
||||
// telemetry signal her judgment already absorbs.
|
||||
// Boredom 取值 0..1。无聊度越高表示用户越空闲、越愿意
|
||||
// 被温和地打扰。在 design/20 §2 P2 之下推送意图来自她自己的
|
||||
// 结论,所以这个旋钮不再为决策把关;它作为一个
|
||||
// 她的判断本就会吸收的遥测信号保留下来。
|
||||
Boredom float64
|
||||
}
|
||||
|
||||
// String returns a concise human-readable summary for logs/records.
|
||||
// String 返回用于日志/记录的简洁可读摘要。
|
||||
func (s UserState) String() string {
|
||||
return fmt.Sprintf("bpm=%d sleeping=%v working=%v busy=%v boredom=%.2f",
|
||||
s.HeartRateBPM, s.Sleeping, s.Working, s.Busy, s.Boredom)
|
||||
}
|
||||
|
||||
// DecisionInput is the set of signals Decide weighs: the event's importance, the
|
||||
// current wall-clock time, the user's current state and their boredom.
|
||||
// DecisionInput 是 Decide 所称量的信号集合:事件重要度、
|
||||
// 当前墙钟时间、用户当前状态及其无聊度。
|
||||
type DecisionInput struct {
|
||||
// Trigger is a human-readable source label, recorded for traceability.
|
||||
// Trigger 是可读的来源标签,为可追溯而记录。
|
||||
Trigger string
|
||||
// Import is the event's estimated importance.
|
||||
// Import 是事件的估计重要度。
|
||||
Import Importance
|
||||
// At is the current wall-clock time, in the local timezone used for the
|
||||
// do-not-disturb window.
|
||||
// At 是当前墙钟时间,处于免打扰窗口所用的
|
||||
// 本地时区。
|
||||
At time.Time
|
||||
// UserState carries the user's physiological/schedule condition.
|
||||
// UserState 携带用户的生理/日程状况。
|
||||
UserState UserState
|
||||
// LastActivity is the wall-clock time of the owner's most recent message.
|
||||
// HasActivity reports whether a user message was found; when false the
|
||||
// activity gate falls through without guessing.
|
||||
// LastActivity 是主人最近一条消息的墙钟时间。
|
||||
// HasActivity 报告是否找到了用户消息;为 false 时
|
||||
// 活动门直接落空、不靠猜。
|
||||
LastActivity time.Time
|
||||
// HasActivity reports whether LastActivity is meaningful.
|
||||
// HasActivity 报告 LastActivity 是否有意义。
|
||||
HasActivity bool
|
||||
// ConclusionPush 是她自己思考结论的推送意愿(design/20 §2 P2):「想不想说」
|
||||
// 由她的结论决定,本决策只回答「此刻能不能说」。
|
||||
@@ -99,11 +99,11 @@ type DecisionInput struct {
|
||||
Heartbeat bool
|
||||
}
|
||||
|
||||
// Decision is the outcome of Decide.
|
||||
// Decision 是 Decide 的结果。
|
||||
type Decision struct {
|
||||
// ShouldPush reports whether the user should be interrupted.
|
||||
// ShouldPush 报告是否应打扰用户。
|
||||
ShouldPush bool
|
||||
// Reason is a short human-readable justification, surfaced on the panel.
|
||||
// Reason 是简短可读的理由,会在面板上呈现。
|
||||
Reason string
|
||||
}
|
||||
|
||||
@@ -192,9 +192,9 @@ func (b *Backthink) activityHeld(in DecisionInput) (bool, string) {
|
||||
return false, ""
|
||||
}
|
||||
|
||||
// inQuietHours reports whether at falls inside the configured do-not-disturb
|
||||
// window. The window may wrap midnight (e.g. 23:00-07:00); two equal non-zero
|
||||
// hours disable it.
|
||||
// inQuietHours 报告 at 是否落在已配置的免打扰
|
||||
// 窗口内。窗口可以跨午夜(如 23:00-07:00);两个相等的非零
|
||||
// 钟点会禁用它。
|
||||
func (b *Backthink) inQuietHours(at time.Time) bool {
|
||||
h := at.Hour()
|
||||
start, end := b.cfg.QuietStartHour, b.cfg.QuietEndHour
|
||||
@@ -204,24 +204,24 @@ func (b *Backthink) inQuietHours(at time.Time) bool {
|
||||
return h >= start || h < end
|
||||
}
|
||||
|
||||
// PushKind classifies a proactive message into one of a few flavors so the
|
||||
// frequency gate can limit each flavor within a window, avoiding same-style spam
|
||||
// (design/12 §6 策略二). It is a soft tag derived from the message body's
|
||||
// keywords — it affects pacing, never identity or permission.
|
||||
// PushKind 把主动消息归类成几种风格,好让
|
||||
// 频率门能在窗口内限制每种风格,避免同一风格刷屏
|
||||
// (design/12 §6 策略二)。它是由消息正文关键词导出的软标签
|
||||
// ——它只影响节奏,绝不影响身份或权限。
|
||||
type PushKind int
|
||||
|
||||
const (
|
||||
// KindGreeting is a warm hello / good-morning / good-night opener.
|
||||
// KindGreeting 是温暖的打招呼 / 早安 / 晚安开场。
|
||||
KindGreeting PushKind = iota
|
||||
// KindReminder is a nudge about a schedule, task or deadline.
|
||||
// KindReminder 是关于日程、任务或截止时间的提醒。
|
||||
KindReminder
|
||||
// KindShare is a discovery, observation or interesting find.
|
||||
// KindShare 是发现、观察或有意思的见闻。
|
||||
KindShare
|
||||
// KindCare is a warm, caring check-in about the owner's wellbeing.
|
||||
// KindCare 是对主人身心状况的温暖关心问候。
|
||||
KindCare
|
||||
)
|
||||
|
||||
// String returns a stable label for logs and records.
|
||||
// String 返回用于日志与记录的稳定标签。
|
||||
func (k PushKind) String() string {
|
||||
switch k {
|
||||
case KindGreeting:
|
||||
@@ -237,11 +237,11 @@ func (k PushKind) String() string {
|
||||
}
|
||||
}
|
||||
|
||||
// classifyPush assigns a PushKind to a proactive message from its keyword
|
||||
// content. A message that matches no flavor defaults to KindCare (the warm,
|
||||
// generic intent of an unsolicited proactive note), which is the least
|
||||
// spam-prone grouping. Priority is reminder > care > greeting > share so the
|
||||
// dominant intent wins when several keywords co-occur.
|
||||
// classifyPush 按关键词内容给主动消息指派 PushKind。
|
||||
// 不匹配任何风格的消息默认为 KindCare(一条主动问候的
|
||||
// 温暖、泛化意图),那是最不容易
|
||||
// 刷屏的分组。优先级为 reminder > care > greeting > share,
|
||||
// 因此多个关键词共现时主流意图获胜。
|
||||
func classifyPush(message string) PushKind {
|
||||
switch {
|
||||
case hasAnyKeyword(message, kindReminderKeywords...):
|
||||
@@ -257,9 +257,9 @@ func classifyPush(message string) PushKind {
|
||||
}
|
||||
}
|
||||
|
||||
// keyword sets for classifyPush. They are package vars (not consts) so the
|
||||
// classification stays flexible and testable, but they are immutable by
|
||||
// convention and never mutated at run time.
|
||||
// classifyPush 所用的关键词集合。它们是包级变量(非常量)以便
|
||||
// 分类保持灵活可测,但按约定不可变,
|
||||
// 从不在运行时改写。
|
||||
var (
|
||||
kindReminderKeywords = []string{"提醒", "记得", "别忘了", "该去", "日程", "会议", "体检", "吃药", "喝药", "到点", "几点", "还有", "迟到", "明天", "马上", "最后", "截止"}
|
||||
kindCareKeywords = []string{"关心", "最近", "辛苦", "注意身体", "照顾好", "好好休息", "心情", "还好", "想你了", "想我", "担心", "保重", "你还好", "陪你", "累"}
|
||||
@@ -267,7 +267,7 @@ var (
|
||||
kindShareKeywords = []string{"发现", "分享", "看到", "听说", "注意到", "告诉你", "有个", "想到", "有意思", "有趣", "你知道吗"}
|
||||
)
|
||||
|
||||
// hasAnyKeyword reports whether s contains any of the given substrings.
|
||||
// hasAnyKeyword 报告 s 是否包含给定子串中的任意一个。
|
||||
func hasAnyKeyword(s string, subs ...string) bool {
|
||||
for _, sub := range subs {
|
||||
if strings.Contains(s, sub) {
|
||||
|
||||
Reference in new issue
Block a user