LoadSession fully parses a JSONL file into a ViewSession.
(root, encodedRepo, sessionID string)
| 261 | |
| 262 | // LoadSession fully parses a JSONL file into a ViewSession. |
| 263 | func LoadSession(root, encodedRepo, sessionID string) (*ViewSession, error) { |
| 264 | path := filepath.Join(root, encodedRepo, sessionID+".jsonl") |
| 265 | f, err := os.Open(path) |
| 266 | if err != nil { |
| 267 | return nil, fmt.Errorf("open session file: %w", err) |
| 268 | } |
| 269 | defer f.Close() |
| 270 | |
| 271 | vs := &ViewSession{Files: make([]*FileGroup, 0)} |
| 272 | fileIndex := make(map[string]*FileGroup) |
| 273 | |
| 274 | scanner := bufio.NewScanner(f) |
| 275 | buf := make([]byte, 0, 1024*1024) |
| 276 | scanner.Buffer(buf, 10*1024*1024) |
| 277 | |
| 278 | for scanner.Scan() { |
| 279 | var rec map[string]any |
| 280 | if err := json.Unmarshal(scanner.Bytes(), &rec); err != nil { |
| 281 | continue // skip malformed lines |
| 282 | } |
| 283 | typ, _ := rec["type"].(string) |
| 284 | |
| 285 | switch typ { |
| 286 | case "session_start": |
| 287 | if ts, ok := rec["timestamp"].(string); ok { |
| 288 | vs.Summary.Timestamp, _ = time.Parse(time.RFC3339, ts) |
| 289 | } |
| 290 | if cwd, ok := rec["cwd"].(string); ok { |
| 291 | vs.Summary.CWD = cwd |
| 292 | } |
| 293 | if branch, ok := rec["gitBranch"].(string); ok { |
| 294 | vs.Summary.GitBranch = branch |
| 295 | } |
| 296 | if model, ok := rec["model"].(string); ok { |
| 297 | vs.Summary.Model = model |
| 298 | } |
| 299 | if rm, ok := rec["reviewMode"].(string); ok { |
| 300 | vs.Summary.ReviewMode = rm |
| 301 | } |
| 302 | if v, ok := rec["diffFrom"].(string); ok { |
| 303 | vs.Summary.DiffFrom = v |
| 304 | } |
| 305 | if v, ok := rec["diffTo"].(string); ok { |
| 306 | vs.Summary.DiffTo = v |
| 307 | } |
| 308 | if v, ok := rec["diffCommit"].(string); ok { |
| 309 | vs.Summary.DiffCommit = v |
| 310 | } |
| 311 | |
| 312 | case "llm_request": |
| 313 | fp, _ := rec["filePath"].(string) |
| 314 | tt, _ := rec["taskType"].(string) |
| 315 | reqNo := 0 |
| 316 | if n, ok := rec["request_no"].(float64); ok { |
| 317 | reqNo = int(n) |
| 318 | } |
| 319 | msgs := rec["messages"] |
| 320 |