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
@@ -11,33 +11,33 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/logger"
|
||||
)
|
||||
|
||||
// StateProvider supplies the user's current condition for the interrupt decision
|
||||
// (design/12 §2). Production wires IoT/telemetry and calendar; tests inject a
|
||||
// mock. It must be concurrency-safe.
|
||||
// StateProvider 为打扰决策提供用户当前状况
|
||||
// (design/12 §2)。生产接线 IoT/遥测与日历;测试注入
|
||||
// mock。它必须并发安全。
|
||||
type StateProvider interface {
|
||||
// Current returns the user's current UserState. A nil-able error means "use
|
||||
// a neutral state"; a hard error is logged by the caller and treated as
|
||||
// neutral.
|
||||
// Current 返回用户当前的 UserState。可 nil 的错误表示「用
|
||||
// 中性状态」;硬错误由调用方记日志并按
|
||||
// 中性处理。
|
||||
Current(ctx context.Context) (UserState, error)
|
||||
}
|
||||
|
||||
// IoTStateProvider is a best-effort StateProvider built over an iot.Manager. It
|
||||
// scans the managed devices and reads heart-rate and sleep signals from any
|
||||
// device whose id/name/type mentions the corresponding keyword (e.g. "heart",
|
||||
// "心率", "sleep", "睡眠"). Work/busy come from a device/state flag; when nothing
|
||||
// matches it returns a neutral state rather than an error, so the service still
|
||||
// runs without full telemetry wiring.
|
||||
// IoTStateProvider 是基于 iot.Manager 的尽力而为 StateProvider。它
|
||||
// 扫描纳管设备,并从任何 id/名称/类型提到对应关键词的设备
|
||||
// 读取心率与睡眠信号(例如 "heart"、
|
||||
// "心率"、"sleep"、"睡眠")。工作/忙碌来自设备/状态标志;什么都不
|
||||
// 匹配时它返回中性状态而不是错误,因此即便没有完整
|
||||
// 遥测接线,服务也能运行。
|
||||
type IoTStateProvider struct {
|
||||
mgr *iot.Manager
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
// NewIoTStateProvider wraps mgr as a StateProvider.
|
||||
// NewIoTStateProvider 把 mgr 包装为 StateProvider。
|
||||
func NewIoTStateProvider(mgr *iot.Manager, log *slog.Logger) *IoTStateProvider {
|
||||
return &IoTStateProvider{mgr: mgr, log: logger.WithSource(baseLog(log), "services/backthink")}
|
||||
}
|
||||
|
||||
// Current implements StateProvider.
|
||||
// Current 实现 StateProvider。
|
||||
func (p *IoTStateProvider) Current(ctx context.Context) (UserState, error) {
|
||||
if p.mgr == nil {
|
||||
return UserState{}, fmt.Errorf("backthink: state: %w", iot.ErrProviderNotRegistered)
|
||||
@@ -71,7 +71,7 @@ func (p *IoTStateProvider) Current(ctx context.Context) (UserState, error) {
|
||||
return state, nil
|
||||
}
|
||||
|
||||
// numState reads the first numeric value among keys from a device's state map.
|
||||
// numState 从设备状态 map 中按 keys 读取首个数值。
|
||||
func numState(d iot.Device, keys ...string) (int, bool) {
|
||||
for _, k := range keys {
|
||||
v, ok := d.State[k]
|
||||
@@ -94,13 +94,13 @@ func numState(d iot.Device, keys ...string) (int, bool) {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// boolState reads a bool (or a "sleep"/"asleep" string) among keys.
|
||||
// boolState 在 keys 中读取一个 bool(或 "sleep"/"asleep" 字符串)。
|
||||
func boolState(d iot.Device, keys ...string) bool {
|
||||
b, _ := boolStateOK(d, keys...)
|
||||
return b
|
||||
}
|
||||
|
||||
// boolStateOK reports whether a bool-typed state flag was found and its value.
|
||||
// boolStateOK 报告是否找到了 bool 类型的状态标志及其取值。
|
||||
func boolStateOK(d iot.Device, keys ...string) (bool, bool) {
|
||||
for _, k := range keys {
|
||||
v, ok := d.State[k]
|
||||
|
||||
Reference in new issue
Block a user