feat: Phase 1+2 架构进化 — 连续思考链/主动消息决策/情感状态机/离线自主思考 (86文件)

Phase 1 (基础设施):
- ThinkChain 思考链连续性 + 差异化思考提示词 (persistent)
- AutonomousToolPolicy 工具安全策略 (safe/unsafe/conditional)
- MessageScheduler 自适应消息节奏 (Idle/Available/Busy)
- SessionEnrichmentStore 渐进式上下文丰富 (5层)
- ConversationBus 事件总线 + ResponseCache (dedup)
- pkg/logger 统一日志 + 所有 handler 替换 fmt.Printf
- NPE 守卫/链路优化/数据库表修复/Go workspace

Phase 2 (人格交互):
- EmotionState/EmotionTracker 情感状态机 (5种心情, 情绪衰减)
- ProactiveGuard 主动消息多维决策 (静默时段/紧急度/频率/校验)
- Gateway↔ai-core 在线状态感知链路 (presence notification)
- 离线思考频率控制 + 重连问候 + 离线消息排队

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-23 15:25:12 +08:00
parent b123a36aae
commit 87214b9441
86 changed files with 3085 additions and 582 deletions
@@ -4,7 +4,7 @@ import (
"crypto/rand"
"encoding/json"
"fmt"
"log"
"github.com/yourname/cyrene-ai/pkg/logger"
"net/http"
"strconv"
"strings"
@@ -128,7 +128,7 @@ func (h *ToolHandler) executeTool(w http.ResponseWriter, r *http.Request, toolNa
durationMs := int(time.Since(startTime).Milliseconds())
if err != nil {
log.Printf("[tool-handler] 执行工具 %s 失败: %v", toolName, err)
logger.Printf("[tool-handler] 执行工具 %s 失败: %v", toolName, err)
h.logCall(toolName, req.Arguments, "", err.Error(), false, durationMs, r)
writeError(w, http.StatusInternalServerError, err.Error())
return
@@ -211,7 +211,7 @@ func (h *ToolHandler) logCall(toolName string, args map[string]interface{}, outp
CreatedAt: time.Now(),
}
if err := h.callLogStore.Insert(record); err != nil {
log.Printf("[tool-handler] 记录调用日志失败: %v", err)
logger.Printf("[tool-handler] 记录调用日志失败: %v", err)
}
}()
}
@@ -249,7 +249,7 @@ func (h *ToolHandler) handleCallLogs(w http.ResponseWriter, r *http.Request) {
result, err := h.callLogStore.Query(query)
if err != nil {
log.Printf("[tool-handler] 查询调用记录失败: %v", err)
logger.Printf("[tool-handler] 查询调用记录失败: %v", err)
writeError(w, http.StatusInternalServerError, "查询调用记录失败: "+err.Error())
return
}
@@ -273,7 +273,7 @@ func (h *ToolHandler) handleCallStats(w http.ResponseWriter, r *http.Request) {
stats, err := h.callLogStore.Stats()
if err != nil {
log.Printf("[tool-handler] 查询调用统计失败: %v", err)
logger.Printf("[tool-handler] 查询调用统计失败: %v", err)
writeError(w, http.StatusInternalServerError, "查询调用统计失败: "+err.Error())
return
}
@@ -286,7 +286,7 @@ func writeJSON(w http.ResponseWriter, status int, data interface{}) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
if err := json.NewEncoder(w).Encode(data); err != nil {
log.Printf("[tool-handler] JSON 编码失败: %v", err)
logger.Printf("[tool-handler] JSON 编码失败: %v", err)
}
}