From b95518e787f90412eca640f9e83966f9d14b0dc1 Mon Sep 17 00:00:00 2001 From: titor Date: Mon, 27 Apr 2026 08:00:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BB=B6=E8=BF=9F=E5=88=9B=E5=BB=BA=20s?= =?UTF-8?q?ession=EF=BC=8C=E5=8F=AA=E5=9C=A8=E7=94=A8=E6=88=B7=E7=9C=9F?= =?UTF-8?q?=E6=AD=A3=E5=AF=B9=E8=AF=9D=E6=97=B6=E6=89=8D=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/hxclaw/internal/memory/save.go | 13 ++++--------- cmd/hxclaw/main.go | 5 +++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/hxclaw/internal/memory/save.go b/cmd/hxclaw/internal/memory/save.go index cb8fd02..539b779 100644 --- a/cmd/hxclaw/internal/memory/save.go +++ b/cmd/hxclaw/internal/memory/save.go @@ -12,6 +12,8 @@ import ( var lastContext string +var ErrNeedNewSession = fmt.Errorf("需要创建新会话") + func GetContextPrompt(userInput string) string { db := GetDB() if db == nil { @@ -231,15 +233,8 @@ func SaveChat(userInput, aiReply string, useSessionSummary bool) (int, error) { // 获取或创建 Session session := currentSession if session == nil { - var err error - session, err = db.GetLatestSession() - if err != nil || session == nil { - session, err = createSession() - if err != nil { - return 0, fmt.Errorf("创建会话失败: %v", err) - } - } - currentSession = session + // 如果没有 session,返回错误让用户创建 + return 0, ErrNeedNewSession } // 保存原始 session summary(用于恢复) diff --git a/cmd/hxclaw/main.go b/cmd/hxclaw/main.go index 45786b3..955ec31 100644 --- a/cmd/hxclaw/main.go +++ b/cmd/hxclaw/main.go @@ -279,6 +279,11 @@ func runWithStreaming(agentLoop *agent.AgentLoop, input, sessionKey string, temp memoryCfg = internal.GetProjectConfig().Memory if memoryCfg.Enabled { chatCount, saveErr = memory.SaveChat(originalInput, resp, !memory.ShouldSkipSummaryUpdate(originalInput)) + // 如果需要新 session,提示用户 + if saveErr == memory.ErrNeedNewSession { + fmt.Println("请使用 /new 创建新会话后再对话") + saveErr = nil + } } elapsed := time.Since(startTime)