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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use crateExtensionType;
use ;
use Value;
/// Detects the AI provider format by analyzing distinctive fields in the session data
///
/// Detection strategy:
/// - Gemini: first line is a session-meta record with `sessionId` and
/// `projectHash` fields but *no* `messages` array (legacy single-object
/// Gemini exports are no longer supported)
/// - Copilot: first line is a `type == "session.start"` event whose
/// `data.producer` field identifies a Copilot agent (e.g.
/// `copilot-agent`, `copilot-cli`). Legacy single-object dumps under
/// `~/.copilot/history-session-state/` are no longer supported.
/// - Claude Code: contains `parentUuid` field in log entries
/// - Codex: contains a record whose `type` is one of `session_meta`,
/// `turn_context`, `event_msg`, or `response_item` — **or** as a final
/// fallback when no other marker is present
///
/// Callers walking a streaming source should prefer
/// [`classify_records`] instead: it returns `None` when the records seen
/// so far are indeterminate, letting the caller decide whether to read more
/// before committing to a provider (see `analyzer::stream_analyze_autodetect`).
/// Streaming-friendly classifier that only commits to a provider when the
/// records carry a distinctive marker.
///
/// Returns `None` when every record seen so far is indeterminate (a Claude
/// metadata preamble, an empty record, a record without any recognised
/// `type` discriminator, …). The streaming auto-detect path uses the
/// `None` signal to decide whether to peek one more JSONL line before
/// falling back to the default.
///
/// Why this matters: the previous design buffered a fixed `AUTODETECT_PEEK_LINES`
/// (8) records and then called [`detect_extension_type`], which silently
/// committed to Codex (the default) once that buffer was exhausted. A Claude
/// session whose `parentUuid`-bearing record sat past a long metadata
/// prelude could then be mis-classified as Codex and have its usage
/// silently dropped. With this function the caller can keep reading until
/// a positive signal appears, so there is no arbitrary limit to the
/// preamble length we tolerate.