降噪A(策略一/二/五): - channelbridge/light.go: 非owner分级门——小事件当系统消息登记(不进loop)、非owner轻响应(她判断回/不回,规则优先mention/关键词+轻LLM兜底fail-closed静默) - backthink 触发降噪: SubjectSystemEvent 低价值不唤醒thinking(仅高价值/owner才think), iot/reminder不受影响 - quiet hours: 安静时段非owner无信号静默,被@才回(非硬性静默); config QUIET_START/END_HOUR 单源共用 限流B(策略三/四): - adapter/flowgate.go: per-adapter 滑窗限流器+总上限+审查剔噪闸门(Admit两连:速率+上限/审查), owner私聊绕过 - channelbridge/flowgate.go: onMessage入站最前挂闸, 超限/被剔不占worker槽; 审查模型NewLLMReviewer复用model.Adapter(仅>80%阈值触发+跨分钟节流,失败回退FIFO,绝不判身份) - config: ChannelAccount 加 GroupMsgPerMin(默认6)/MsgPerMin/MaxMessages(默认50), CHANNELS_JSON每账号, 向后兼容 - 被剔消息走OnRejected审计不静默丢 main wire接线: 加modelAdapter字段+Review注入(reviewFor nil-safe,无LLM回退FIFO) 全仓 go build/vet/test 绿(53包)+交叉编译, 零新依赖, 前端无涉
74 lines
2.6 KiB
Go
74 lines
2.6 KiB
Go
package backthink
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/bus"
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/iot"
|
|
)
|
|
|
|
// Bus subjects the service subscribes to for event-triggered thinking. They are
|
|
// the contract defined by design/12 §1: an IoT state change, a reminder firing,
|
|
// or a generic system event.
|
|
const (
|
|
// SubjectReminderTrigger is the bus subject on which reminders fire.
|
|
SubjectReminderTrigger = "reminder.trigger"
|
|
// SubjectSystemEvent is the bus subject for generic system events.
|
|
SubjectSystemEvent = "system.event"
|
|
)
|
|
|
|
// SystemEvent is the optional typed payload a caller may publish to
|
|
// SubjectSystemEvent to convey a system notice. Import defaults to Normal. Under
|
|
// design/12 §6 策略一, a low-value system notice (a join/leave ping, generic
|
|
// platform noise) is downgraded to a registration-only record and does not wake a
|
|
// full thinking pass; only a high-importance (owner-relevant) system event thinks,
|
|
// so a busy public platform cannot trigger a flood of expensive reflections.
|
|
type SystemEvent struct {
|
|
Summary string
|
|
Import Importance
|
|
}
|
|
|
|
// Trigger describes what woke a thinking pass: the source subsystem, a
|
|
// human-readable summary and the event's estimated importance.
|
|
type Trigger struct {
|
|
Source string
|
|
Summary string
|
|
Import Importance
|
|
}
|
|
|
|
// heartbeatTrigger is the periodic, low-importance trigger. Low importance means
|
|
// the pass rarely interrupts the user, honouring "默认不发送 chat 类型消息".
|
|
func heartbeatTrigger() Trigger {
|
|
return Trigger{Source: "heartbeat", Summary: "periodic autonomous reflection", Import: ImportanceLow}
|
|
}
|
|
|
|
// triggerForEvent maps a bus event to a Trigger. An IoT device change is treated
|
|
// as normal importance, a reminder firing as high importance, and a generic
|
|
// system event as normal importance.
|
|
func triggerForEvent(e bus.Event) Trigger {
|
|
switch e.Subject {
|
|
case iot.DeviceUpdateSubject:
|
|
if d, ok := e.Payload.(iot.DeviceUpdate); ok {
|
|
return Trigger{
|
|
Source: e.Subject,
|
|
Summary: fmt.Sprintf("device %s (%s) %s", d.Device.ID, d.Device.Type, d.Action),
|
|
Import: ImportanceNormal,
|
|
}
|
|
}
|
|
return Trigger{Source: e.Subject, Summary: e.Subject, Import: ImportanceNormal}
|
|
case SubjectReminderTrigger:
|
|
return Trigger{Source: e.Subject, Summary: e.Subject, Import: ImportanceHigh}
|
|
case SubjectSystemEvent:
|
|
tr := Trigger{Source: e.Subject, Summary: e.Subject, Import: ImportanceNormal}
|
|
if sy, ok := e.Payload.(SystemEvent); ok {
|
|
if sy.Summary != "" {
|
|
tr.Summary = sy.Summary
|
|
}
|
|
tr.Import = sy.Import
|
|
}
|
|
return tr
|
|
default:
|
|
return Trigger{Source: e.Subject, Summary: e.Subject, Import: ImportanceNormal}
|
|
}
|
|
}
|