MCPcopy Create free account
hub / github.com/alibaba/open-code-review / LoadComments

Function LoadComments

internal/session/comments.go:14–67  ·  view source on GitHub ↗

LoadComments replays one session's JSONL and returns every review comment recorded in it, in file-completion order. It mirrors resume replay semantics: a later checkpoint for the same fingerprint supersedes the earlier one, and a subsequent review_item_failed drops it. Comments that were persisted w

(repoDir, sessionID string)

Source from the content-addressed store, hash-verified

12// earlier one, and a subsequent review_item_failed drops it. Comments that
13// were persisted without a path inherit the record's file path.
14func LoadComments(repoDir, sessionID string) ([]model.LlmComment, error) {
15 path, err := SessionFilePath(repoDir, sessionID)
16 if err != nil {
17 return nil, err
18 }
19 type group struct {
20 comments []model.LlmComment
21 }
22 var order []*group
23 byFingerprint := map[string]*group{}
24 err = walkSessionFile(path, func(rec summaryRecord) {
25 switch rec.Type {
26 case "review_item_done", "review_item_reused":
27 var comments []model.LlmComment
28 if len(rec.Comments) > 0 {
29 if err := json.Unmarshal(rec.Comments, &comments); err != nil {
30 return
31 }
32 }
33 filePath := rec.FilePath
34 if filePath == "" {
35 filePath = rec.NewPath
36 }
37 for i := range comments {
38 if comments[i].Path == "" {
39 comments[i].Path = filePath
40 }
41 }
42 if rec.Fingerprint != "" {
43 if g, ok := byFingerprint[rec.Fingerprint]; ok {
44 g.comments = comments
45 return
46 }
47 }
48 g := &group{comments: comments}
49 order = append(order, g)
50 if rec.Fingerprint != "" {
51 byFingerprint[rec.Fingerprint] = g
52 }
53 case "review_item_failed":
54 if g, ok := byFingerprint[rec.Fingerprint]; ok {
55 g.comments = nil
56 }
57 }
58 })
59 if err != nil {
60 return nil, err
61 }
62 var out []model.LlmComment
63 for _, g := range order {
64 out = append(out, g.comments...)
65 }
66 return out, nil
67}

Calls 2

SessionFilePathFunction · 0.85
walkSessionFileFunction · 0.85