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

Function LoadSession

internal/viewer/store.go:290–565  ·  view source on GitHub ↗

LoadSession fully parses a JSONL file into a ViewSession.

(root, encodedRepo, sessionID string)

Source from the content-addressed store, hash-verified

288
289// LoadSession fully parses a JSONL file into a ViewSession.
290func LoadSession(root, encodedRepo, sessionID string) (*ViewSession, error) {
291 path := filepath.Join(root, encodedRepo, sessionID+".jsonl")
292 f, err := os.Open(path)
293 if err != nil {
294 return nil, fmt.Errorf("open session file: %w", err)
295 }
296 defer f.Close()
297
298 vs := &ViewSession{Files: make([]*FileGroup, 0)}
299 fileIndex := make(map[string]*FileGroup)
300
301 scanner := bufio.NewScanner(f)
302 buf := make([]byte, 0, 1024*1024)
303 scanner.Buffer(buf, 10*1024*1024)
304
305 for scanner.Scan() {
306 var rec map[string]any
307 if err := json.Unmarshal(scanner.Bytes(), &rec); err != nil {
308 continue // skip malformed lines
309 }
310 typ, _ := rec["type"].(string)
311
312 switch typ {
313 case "session_start":
314 if ts, ok := rec["timestamp"].(string); ok {
315 vs.Summary.Timestamp, _ = time.Parse(time.RFC3339, ts)
316 }
317 if cwd, ok := rec["cwd"].(string); ok {
318 vs.Summary.CWD = cwd
319 }
320 if branch, ok := rec["gitBranch"].(string); ok {
321 vs.Summary.GitBranch = branch
322 }
323 if model, ok := rec["model"].(string); ok {
324 vs.Summary.Model = model
325 }
326 if rm, ok := rec["reviewMode"].(string); ok {
327 vs.Summary.ReviewMode = rm
328 }
329 if v, ok := rec["diffFrom"].(string); ok {
330 vs.Summary.DiffFrom = v
331 }
332 if v, ok := rec["diffTo"].(string); ok {
333 vs.Summary.DiffTo = v
334 }
335 if v, ok := rec["diffCommit"].(string); ok {
336 vs.Summary.DiffCommit = v
337 }
338
339 case "llm_request":
340 fp, _ := rec["filePath"].(string)
341 tt, _ := rec["taskType"].(string)
342 reqNo := 0
343 if n, ok := rec["request_no"].(float64); ok {
344 reqNo = int(n)
345 }
346 msgs := rec["messages"]
347

Calls 3

taskDoneSucceededFunction · 0.85
CloseMethod · 0.80
TaskTypeTypeAlias · 0.70