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

Function LoadSession

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

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

Calls 5

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