@@ -40,10 +40,10 @@ func (m *Manager) ExtractAIModelFromBranch(branchName string) string {
40
40
if ! strings .HasPrefix (branchName , BranchPrefix + "/" ) {
41
41
return ""
42
42
}
43
-
43
+
44
44
// 移除 codeagent/ 前缀
45
45
branchWithoutPrefix := strings .TrimPrefix (branchName , BranchPrefix + "/" )
46
-
46
+
47
47
// 分割获取 aimodel 部分
48
48
parts := strings .Split (branchWithoutPrefix , "/" )
49
49
if len (parts ) >= 2 {
@@ -53,7 +53,7 @@ func (m *Manager) ExtractAIModelFromBranch(branchName string) string {
53
53
return aiModel
54
54
}
55
55
}
56
-
56
+
57
57
return ""
58
58
}
59
59
@@ -289,16 +289,14 @@ func (m *Manager) recoverExistingWorkspaces() {
289
289
func (m * Manager ) recoverPRWorkspace (org , repo , worktreePath , remoteURL string , prNumber int , aiModel string ) error {
290
290
// 从 worktree 路径提取 PR 信息
291
291
worktreeDir := filepath .Base (worktreePath )
292
- var timestamp , sessionSuffix string
293
-
292
+ var timestamp string
293
+
294
294
if aiModel != "" {
295
295
// 有AI模型的情况: aimodel-repo-pr-number-timestamp
296
296
timestamp = strings .TrimPrefix (worktreeDir , aiModel + "-" + repo + "-pr-" + strconv .Itoa (prNumber )+ "-" )
297
- sessionSuffix = strings .TrimPrefix (worktreeDir , aiModel + "-" + repo + "-pr-" )
298
297
} else {
299
298
// 没有AI模型的情况: repo-pr-number-timestamp
300
299
timestamp = strings .TrimPrefix (worktreeDir , repo + "-pr-" + strconv .Itoa (prNumber )+ "-" )
301
- sessionSuffix = strings .TrimPrefix (worktreeDir , repo + "-pr-" )
302
300
}
303
301
304
302
// 将 timestamp 字符串转换为时间
@@ -311,7 +309,8 @@ func (m *Manager) recoverPRWorkspace(org, repo, worktreePath, remoteURL string,
311
309
}
312
310
313
311
// 创建对应的 session 目录(与 repo 同级)
314
- sessionPath := filepath .Join (m .baseDir , org , fmt .Sprintf ("%s-session-%s" , repo , sessionSuffix ))
312
+ // 新的session目录格式:{aiModel}-{repo}-session-{prNumber}-{timestamp}
313
+ sessionPath := filepath .Join (m .baseDir , org , fmt .Sprintf ("%s-%s-session-%d-%s" , aiModel , repo , prNumber , timestamp ))
315
314
316
315
// 恢复工作空间对象
317
316
ws := & models.Workspace {
@@ -488,8 +487,10 @@ func (m *Manager) GetWorktreeCount() int {
488
487
return total
489
488
}
490
489
491
- func (m * Manager ) CreateSessionPath (underPath , repo string , prNumber int , suffix string ) (string , error ) {
492
- sessionPath := filepath .Join (underPath , fmt .Sprintf ("%s-session-%d-%s" , repo , prNumber , suffix ))
490
+ func (m * Manager ) CreateSessionPath (underPath , aiModel , repo string , prNumber int , suffix string ) (string , error ) {
491
+ // 新的session目录格式:{aiModel}-{repo}-session-{prNumber}-{timestamp}
492
+ // 只保留时间戳部分,避免重复信息
493
+ sessionPath := filepath .Join (underPath , fmt .Sprintf ("%s-%s-session-%d-%s" , aiModel , repo , prNumber , suffix ))
493
494
if err := os .MkdirAll (sessionPath , 0755 ); err != nil {
494
495
log .Errorf ("Failed to create session directory: %v" , err )
495
496
return "" , err
@@ -616,21 +617,21 @@ func (m *Manager) GetWorkspaceByPR(pr *github.PullRequest) *models.Workspace {
616
617
func (m * Manager ) GetAllWorkspacesByPR (pr * github.PullRequest ) []* models.Workspace {
617
618
orgRepoPath := fmt .Sprintf ("%s/%s" , pr .GetBase ().GetRepo ().GetOwner ().GetLogin (), pr .GetBase ().GetRepo ().GetName ())
618
619
prNumber := pr .GetNumber ()
619
-
620
+
620
621
var workspaces []* models.Workspace
621
-
622
+
622
623
m .mutex .RLock ()
623
624
defer m .mutex .RUnlock ()
624
-
625
+
625
626
// 遍历所有工作空间,找到与该PR相关的
626
- for key , ws := range m .workspaces {
627
+ for _ , ws := range m .workspaces {
627
628
// 检查是否是该PR的工作空间
628
- if ws .PRNumber == prNumber &&
629
- fmt .Sprintf ("%s/%s" , ws .Org , ws .Repo ) == orgRepoPath {
629
+ if ws .PRNumber == prNumber &&
630
+ fmt .Sprintf ("%s/%s" , ws .Org , ws .Repo ) == orgRepoPath {
630
631
workspaces = append (workspaces , ws )
631
632
}
632
633
}
633
-
634
+
634
635
return workspaces
635
636
}
636
637
@@ -693,7 +694,7 @@ func (m *Manager) CreateWorkspaceFromPRWithAI(pr *github.PullRequest, aiModel st
693
694
694
695
// 创建 session 目录
695
696
suffix := strings .TrimPrefix (filepath .Base (worktree .Worktree ), fmt .Sprintf ("%s-pr-%d-" , repo , pr .GetNumber ()))
696
- sessionPath , err := m .CreateSessionPath (filepath .Dir (repoManager .GetRepoPath ()), repo , pr .GetNumber (), suffix )
697
+ sessionPath , err := m .CreateSessionPath (filepath .Dir (repoManager .GetRepoPath ()), aiModel , repo , pr .GetNumber (), suffix )
697
698
if err != nil {
698
699
log .Errorf ("Failed to create session directory: %v" , err )
699
700
return nil
0 commit comments