-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli_session.py
More file actions
49 lines (41 loc) · 1.7 KB
/
Copy pathcli_session.py
File metadata and controls
49 lines (41 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""CliSessionMeta — typed model for the Cursor CLI ``meta`` blob."""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any
from models.errors import SchemaError
@dataclass(frozen=True)
class CliSessionMeta:
"""The ``meta`` blob at the head of a Cursor CLI ``store.db`` blob graph.
``latestRootBlobId`` is the entry point for the conversation reconstruction
BFS in ``utils/cli_chat_reader.traverse_blobs``; without it, the entire
conversation is unreachable. ``createdAt`` is documented as part of the
meta-blob schema (see ``utils/cli_chat_reader`` module docstring) and is
captured here, but it is not gated on — only ``latestRootBlobId`` is the
hard requirement, since that is the only field whose absence prevents
conversation reconstruction.
"""
latest_root_blob_id: str
created_at: Any = None
raw: dict[str, Any] = field(default_factory=dict)
@classmethod
def from_dict(cls, raw: dict[str, Any]) -> "CliSessionMeta":
if not isinstance(raw, dict):
raise SchemaError(
"CliSessionMeta",
"meta",
hint=f"expected object, got {type(raw).__name__}",
)
latest = raw.get("latestRootBlobId")
if not latest:
raise SchemaError("CliSessionMeta", "latestRootBlobId")
if not isinstance(latest, str):
raise SchemaError(
"CliSessionMeta",
"latestRootBlobId",
hint=f"expected str, got {type(latest).__name__}",
)
return cls(
latest_root_blob_id=latest,
created_at=raw.get("createdAt"),
raw=raw,
)