feat(emotion): A1 情绪系统接线 + refactor: 拆分 channelbridge.go
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

A1 情绪接线:
- loop 回合边界钩子(TurnEnd/OnTurnEnd/settleTurn, Result.Mood); 每轮一次非每步
- persona/emotion: React(valence五档) + Machine.Move(BFS最短合法路径一步) + Observer(observe/decay/好感度,仅变化才emit); 好感度步长读角色配置(cyrene delta=10, 0..700)
- 落库 Mood(web session_persist.res.Mood + IM channelbridge/persist; user消息不带mood); WS mood事件(BroadcastMood,仅变化); per-persona隔离; 群聊/陌生人只读不写不发
- cmd/cyrene/emotion.go 生产接线 + wire.go 注入 loop.Options.OnTurnEnd
- 22 测试(状态机被loop调用/Mood非空落库/mood帧shape/只变化才发/群聊只读) + 真二进制冒烟
- Docs: api-client v0.32 §3.7 情绪事件 + 开源对照清单(companion 应用对照)
- 诚实: 本机无LLM凭据→未活体验证'模型返回后完整轮次'一环

拆分 channelbridge.go 816→257(纯搬移零逻辑): connect/inbound/outbound/blacklist/helpers.go; A1 的 IM mood 调用点落在新 inbound.go, 故与本提交同批

回滚 6 个 gofmt 顺手格式化文件(capacity_loop_test/flow/source_test/findchannel_test/admin_channels_platform_test/history) 缩 diff, 含 history.go 注释被转弯引号
This commit is contained in:
AskaEth committed 2026-09-30 08:51:38 +08:00
1 parent 610b330025
commit 1a85de555d
27 files changed
+1946 -594

No files matched your search

+57
View File
@@ -155,6 +155,63 @@ func (m *Machine) ensure(from EmotionState) map[EmotionState]struct{} {
return m.transitions[from]
}
// Move aims the machine at target, walking the persona's installed transition
// table. A direct edge is taken when present; otherwise the first hop of a
// shortest legal path is taken, so a caller can aim at an emotion without
// knowing the intermediate states. A target that is unreachable from the current
// state, an empty target, or the current state itself leaves the machine
// unchanged rather than forcing an illegal move. The resulting state is
// returned.
func (m *Machine) Move(target EmotionState) EmotionState {
m.mu.Lock()
defer m.mu.Unlock()
if target == "" || target == m.current {
return m.current
}
if m.allowed(m.current, target) {
m.current = target
return m.current
}
if hop, ok := m.firstHopTo(target); ok {
m.current = hop
}
return m.current
}
// firstHopTo returns the first state on a shortest transition path from the
// current state to target, and whether such a path exists. Ties between equally
// short paths are broken arbitrarily, which is invisible to callers: any first
// hop on a shortest legal path moves the machine in the wanted direction.
func (m *Machine) firstHopTo(target EmotionState) (EmotionState, bool) {
type node struct {
state EmotionState
first EmotionState
}
queue := make([]node, 0, len(m.transitions[m.current]))
for next := range m.transitions[m.current] {
if next == target {
return next, true
}
queue = append(queue, node{state: next, first: next})
}
seen := map[EmotionState]struct{}{m.current: {}}
for len(queue) > 0 {
cur := queue[0]
queue = queue[1:]
if _, ok := seen[cur.state]; ok {
continue
}
seen[cur.state] = struct{}{}
for next := range m.transitions[cur.state] {
if next == target {
return cur.first, true
}
queue = append(queue, node{state: next, first: cur.first})
}
}
return "", false
}
// Decay drifts the emotion one position toward calm whenever DecayRate is
// positive; otherwise it leaves the current state unchanged. The new state is
// returned.