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

+25 -10
View File
@@ -390,26 +390,41 @@ func (b *Backthink) think(parent context.Context, tr Trigger) {
return
}
state := b.currentState(cctx)
decision := b.Decide(DecisionInput{Trigger: tr.Source, Import: tr.Import, At: at, UserState: state})
// P2 (design/20 §2): her own conclusion decides whether to push and to which
// channel — not the trigger's importance. parseProactive recovers the decision
// robustly and fails safe (malformed/ambiguous → no push).
message, channelHint, push := parseProactive(conclusion)
pushRes := PushResult{Route: RouteNone, Detail: decision.Reason}
if decision.ShouldPush {
pushRes = b.pusher.Push(cctx, b.buildProactiveMessage(conclusion))
state := b.currentState(cctx)
// The "do not disturb" gate (asleep/working/busy/quiet) still applies as a hard
// safety; the frequency gate (PushGate) is applied inside the pusher.
shouldPush := push && b.disturbAllowed(at, state)
recordConclusion := message
if recordConclusion == "" {
recordConclusion = conclusion
}
pushRes := PushResult{Route: RouteNone, Detail: b.interruptReason(push, at, state)}
if shouldPush {
pushRes = b.pusher.Push(cctx, PushRequest{
Message: b.buildProactiveMessage(message, channelHint),
ChannelHint: channelHint,
})
}
b.record(Record{
Trigger: tr.Source,
At: at,
Conclusion: conclusion,
ShouldPush: decision.ShouldPush,
Conclusion: recordConclusion,
ShouldPush: shouldPush,
PushResult: pushRes,
})
if decision.ShouldPush {
b.log.Info("backthink proactive push", "source", tr.Source, "route", pushRes.Route, "pushed", pushRes.Pushed, "reason", decision.Reason)
if shouldPush {
b.log.Info("backthink proactive push", "source", tr.Source, "route", pushRes.Route, "pushed", pushRes.Pushed, "reason", pushRes.Detail)
} else {
b.log.Debug("backthink did not interrupt", "source", tr.Source, "reason", decision.Reason)
b.log.Debug("backthink did not interrupt", "source", tr.Source, "reason", pushRes.Detail)
}
}