package loop import ( "fmt" "log/slog" "time" "git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model" ) // weekdaysCN maps time.Weekday (0=Sunday) to a Chinese weekday label. var weekdaysCN = [...]string{"周日", "周一", "周二", "周三", "周四", "周五", "周六"} // loadTimezone resolves the configured IANA timezone into a *time.Location for // the per-round time injection. An empty name (or one that fails to load) yields // nil, disabling injection entirely (backward compatible, graceful degradation). func loadTimezone(name string, log *slog.Logger) (*time.Location, string) { if name == "" { return nil, "" } loc, err := time.LoadLocation(name) if err != nil { log.Warn("timezone load failed; time injection disabled", "tz", name, "error", err) return nil, "" } return loc, name } // currentTimeBlock renders one per-round "current time" system message so the // model knows the wall-clock time each round (not a first-turn snapshot). It is // called from assembleContext only when a timezone was configured. It provides // the raw clock — whether it is "late and time to sleep" is the persona prompt's // job, not a hard-coded rule here. func (l *Loop) currentTimeBlock() model.Message { now := time.Now().In(l.timeLocation) text := fmt.Sprintf("当前时间:%s %s,时区 %s", now.Format("2006-01-02 15:04"), weekdaysCN[now.Weekday()], l.timeZoneName, ) return model.TextMessage(model.RoleSystem, text) }