返回 DeepSeek-Reasonix
rename.go
根目录 / internal / cli / rename.go
1 package cli
2
3 import (
4 "fmt"
5 "strconv"
6 "strings"
7
8 "reasonix/internal/agent"
9 "reasonix/internal/i18n"
10 )
11
12 // runRenameCommand handles "/rename": with no argument it shows usage;
13 // "/rename <new title>" renames the current session;
14 // "/rename <n> <new title>" renames session #n from the /resume list.
15 func (m *chatTUI) runRenameCommand(input string) {
16 args := tokenizeArgs(input) // args[0] == "/rename"
17
18 if len(args) < 2 {
19 m.notice(i18n.M.RenameUsage)
20 return
21 }
22
23 sessions := recentSessions(m.ctrl.SessionDir())
24 title := ""
25 targetPath := ""
26
27 // Check if the first arg after /rename is a session index (a number).
28 idx, err := strconv.Atoi(args[1])
29 if err == nil && len(args) >= 3 {
30 // "/rename <n> <new title>"
31 if idx < 1 || idx > len(sessions) {
32 m.notice(fmt.Sprintf(i18n.M.ResumeBadIndexFmt, len(sessions)))
33 return
34 }
35 targetPath = sessions[idx-1].Path
36 title = strings.TrimSpace(strings.TrimPrefix(input, args[0]+" "+args[1]))
37 } else {
38 // "/rename <new title>" -- rename the current session.
39 if m.ctrl.SessionPath() == "" {
40 m.notice(i18n.M.RenameNoSession)
41 return
42 }
43 targetPath = m.ctrl.SessionPath()
44 title = strings.TrimSpace(strings.TrimPrefix(input, args[0]))
45 }
46
47 if title == "" {
48 m.notice(i18n.M.RenameUsage)
49 return
50 }
51
52 if err := agent.RenameSession(targetPath, title); err != nil {
53 m.notice("rename: " + err.Error())
54 return
55 }
56
57 m.notice(fmt.Sprintf(i18n.M.RenameDoneFmt, title))
58 }
59
59 lines GO