新增: 历史会话标题自定义编辑与摘要质量修复

- 标题自定义编辑:HISTORY 详情按 e 编辑标题,UserTitle 持久化到缓存且最高优先级
- AI 摘要质量修复:困惑回复检测词表收紧,消息提取过滤噪音,修复 JSON 包裹困惑回复漏网
- 数据维护命令:--fix-titles 清理低质量摘要,--regen-summaries 并发生成
- 修复代码审查 9 个问题:退格 UTF-8 损坏、中文输入、flush 调度、误杀合法摘要、
  按键全局拦截、UserTitle 未同步窗口标题、wt 启动回落、cmd 注入防护、前缀误隐藏会话
- 启动链 wt.exe 回退与 cmd start 标题转义
- gofmt 规范化,新增 launch_test.go
This commit is contained in:
lxy
2026-07-31 21:22:17 +08:00
parent 043a7d9227
commit 95f349bcd7
10 changed files with 1465 additions and 126 deletions
+51 -18
View File
@@ -3,6 +3,7 @@ package internal
import (
"fmt"
"os"
"strings"
"time"
tea "charm.land/bubbletea/v2"
@@ -10,20 +11,22 @@ import (
// Model 主模型
type Model struct {
activeGroup int
cursor int
selected map[int]bool
inputBuf string
width int
height int
launched string
history HistoryState
pendingCmd string
update UpdateState
wsFocus int // workspace 焦点列: 0=tabs 1=list
wsTabCur int // tabs 列光标 (0..len(Groups), 最后一个是历史入口)
forkMode bool // 分叉输入模式
forkBuf string // 分叉方向提示输入
activeGroup int
cursor int
selected map[int]bool
inputBuf string
width int
height int
launched string
history HistoryState
pendingCmd string
update UpdateState
wsFocus int // workspace 焦点列: 0=tabs 1=list
wsTabCur int // tabs 列光标 (0..len(Groups), 最后一个是历史入口)
forkMode bool // 分叉输入模式
forkBuf string // 分叉方向提示输入
editTitleMode bool // 编辑标题模式
editTitleBuf string // 标题编辑缓冲区
// 性能缓存
allSessionsCache []*Session // "全部" tab 会话切片缓存
@@ -88,10 +91,8 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
total += len(pd.Sessions)
}
m.launched = fmt.Sprintf("refreshed: %d projects, %d sessions", len(msg.Projects), total)
if len(msg.UpdatedIDs) > 0 {
return m, m.nextSummaryCmd()
}
return m, nil
// 无论本次是否有文件更新,都尝试补齐缺失的摘要
return m, m.nextSummaryCmd()
case SummaryResultMsg:
m.applySummary(msg.SessionID, msg.Summary, msg.Completed, msg.Pending)
m.cacheDirty = true
@@ -133,6 +134,38 @@ func (m *Model) GetPendingCmd() string {
return m.pendingCmd
}
func (m *Model) confirmEditTitle() (*Model, tea.Cmd) {
s := m.currentSession()
title := strings.TrimSpace(m.editTitleBuf)
m.editTitleMode = false
m.editTitleBuf = ""
if s == nil || title == "" {
return m, nil
}
cmd := m.setUserTitle(s.ID, title)
m.launched = "rename: " + title
return m, cmd
}
func (m *Model) setUserTitle(sessionID, title string) tea.Cmd {
for _, pd := range m.history.Projects {
for _, s := range pd.Sessions {
if s.ID == sessionID {
s.UserTitle = title
break
}
}
}
if m.history.Cache != nil {
if entry, ok := m.history.Cache[sessionID]; ok {
entry.UserTitle = title
m.cacheDirty = true
}
}
// 调度落盘,避免改名只存在内存、被磁盘旧缓存覆盖
return cacheFlushTick()
}
func (m *Model) flushCache() {
if !m.cacheDirty || m.history.Cache == nil {
return