返回 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 := mergedResumeEntries(m.ctrl.SessionDir(), resumeListCap)
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 picked := sessions[idx-1]
36 if picked.target.canonical() {
37 m.notice("rename: final-format sessions are renamed from the session title API, not the legacy sidecar")
38 return
39 }
40 targetPath = picked.session.Path
41 title = strings.TrimSpace(strings.TrimPrefix(input, args[0]+" "+args[1]))
42 } else {
43 // "/rename <new title>" -- rename the current session.
44 if m.ctrl.SessionPath() == "" {
45 m.notice(i18n.M.RenameNoSession)
46 return
47 }
48 targetPath = m.ctrl.SessionPath()
49 title = strings.TrimSpace(strings.TrimPrefix(input, args[0]))
50 }
51
52 if title == "" {
53 m.notice(i18n.M.RenameUsage)
54 return
55 }
56
57 if err := agent.RenameSession(targetPath, title); err != nil {
58 m.notice("rename: " + err.Error())
59 return
60 }
61
62 m.notice(fmt.Sprintf(i18n.M.RenameDoneFmt, title))
63 }
64
64 lines GO