feat(backthink): 自主思考 P2——结构化推送决策+渠道选择(design/20)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

- proactive.go(新): parseProactive 从结论解析 [我决定:push|no_push][渠道:...]<正文>;
  兼容大小写/全半角冒号; 无标记回退(无/nothing=不推); 畸形/孤标记 fail-safe 不推
- context.go: guidancePrompt 引导结构化结尾+保留P1温暖引导
- push.go: PushRequest{Message,ChannelHint}; Pusher.Push 路由(auto→active优先/IM兜底,
  web→仅active, im→仅IM, 具体平台→IM+platform打标+缺IM回退默认记detail); buildProactiveMessage
- backthink.go: think() 用 parseProactive→ShouldPush=push&&disturbAllowed(不再被tr.Import卡死)
- decide.go: disturbAllowed(asleep/working/quiet 硬性不打扰门) 取代旧import门(保留旧Decide兼容)
- 测试: parseProactive 6组+think端到端(真实pusher:kook→IM/无标记→active/no_push→不推/睡眠→门拦截)
   +buildProactiveMessage+具体平台无IM回退; 后端 build/vet/test 全绿
- 注: 生产 Active/IM sink 未注入 wire.go backthink.Deps(另一步); 多平台IM受单IMAdapter接口限制
This commit is contained in:
Aska committed 2026-09-07 19:34:51 +08:00
1 parent 93aff2fea5
commit 2283383b9e
8 files changed
+688 -47

No files matched your search

+28
View File
@@ -128,6 +128,34 @@ func (b *Backthink) Decide(in DecisionInput) Decision {
}
}
// disturbAllowed is the hard "do not disturb" safety gate for an autonomous push
// (design/12 §2 first principle). Unlike Decide it deliberately ignores trigger
// importance — which design/20 P2 replaces with her own judgment — and only blocks
// when it is genuinely inappropriate to interrupt: the user is asleep, working or
// busy, or it is inside the quiet-hours window. The frequency gate (PushGate)
// applies separately inside the pusher.
func (b *Backthink) disturbAllowed(at time.Time, s UserState) bool {
if s.Sleeping || s.Working || s.Busy {
return false
}
return !b.inQuietHours(at)
}
// interruptReason is the short human-readable note recorded/logged when no push
// goes out (or as the pre-push intent). It keeps the panel self-explanatory:
// either she concluded no push, or the do-not-disturb gate refused a push she
// wanted.
func (b *Backthink) interruptReason(push bool, at time.Time, s UserState) string {
switch {
case !push:
return "conclusion requested no push"
case !b.disturbAllowed(at, s):
return "proactive push blocked by do-not-disturb"
default:
return "proactive push approved"
}
}
// 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.