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

Function LoadSession

internal/viewer/store.go:311–569  ·  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

309
310// LoadSession fully parses a JSONL file into a ViewSession.
311func LoadSession(root, encodedRepo, sessionID string) (*ViewSession, error) {
312 path := filepath.Join(root, encodedRepo, sessionID+".jsonl")
313 f, err := os.Open(path)
314 if err != nil {
315 return nil, fmt.Errorf("open session file: %w", err)
316 }
317 defer f.Close()
318
319 vs := &ViewSession{Files: make([]*FileGroup, 0)}
320 vs.Summary.Aborted = true
321 fileIndex := make(map[string]*FileGroup)
322
323 readErr := readJSONLLines(f, func(line []byte) {
324 var rec map[string]any
325 if err := json.Unmarshal(line, &rec); err != nil {
326 return // skip malformed lines
327 }
328 typ, _ := rec["type"].(string)
329
330 switch typ {
331 case "session_start":
332 if ts, ok := rec["timestamp"].(string); ok {
333 vs.Summary.Timestamp, _ = time.Parse(time.RFC3339, ts)
334 }
335 if cwd, ok := rec["cwd"].(string); ok {
336 vs.Summary.CWD = cwd
337 }
338 if branch, ok := rec["gitBranch"].(string); ok {
339 vs.Summary.GitBranch = branch
340 }
341 if model, ok := rec["model"].(string); ok {
342 vs.Summary.Model = model
343 }
344 if rm, ok := rec["reviewMode"].(string); ok {
345 vs.Summary.ReviewMode = rm
346 }
347 if v, ok := rec["diffFrom"].(string); ok {
348 vs.Summary.DiffFrom = v
349 }
350 if v, ok := rec["diffTo"].(string); ok {
351 vs.Summary.DiffTo = v
352 }
353 if v, ok := rec["diffCommit"].(string); ok {
354 vs.Summary.DiffCommit = v
355 }
356
357 case "llm_request":
358 fp, _ := rec["filePath"].(string)
359 tt, _ := rec["taskType"].(string)
360 reqNo := 0
361 if n, ok := rec["request_no"].(float64); ok {
362 reqNo = int(n)
363 }
364 msgs := rec["messages"]
365
366 tc := &TaskCard{RequestMessages: msgs, RequestNo: reqNo}
367
368 fg := fileIndex[fp]

Calls 5

readJSONLLinesFunction · 0.85
taskDoneSucceededFunction · 0.85
applySessionEndFunction · 0.85
CloseMethod · 0.80
TaskTypeTypeAlias · 0.70