MCPcopy Create free account
hub / github.com/douglance/devsql / load_transcripts

Method load_transcripts

crates/devsql/src/engine.rs:161–254  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

159 }
160
161 fn load_transcripts(&mut self) -> Result<()> {
162 self.conn.execute(
163 "CREATE TABLE IF NOT EXISTS transcripts (
164 rowid INTEGER PRIMARY KEY,
165 type TEXT,
166 content TEXT,
167 tool_name TEXT,
168 session_id TEXT,
169 _source_file TEXT,
170 _session_id TEXT,
171 _project TEXT,
172 _agent_id TEXT,
173 timestamp TEXT,
174 model TEXT,
175 usage_input_tokens INTEGER,
176 usage_output_tokens INTEGER,
177 usage_cache_read_input_tokens INTEGER,
178 usage_cache_creation_input_tokens INTEGER,
179 usage_ephemeral_5m_input_tokens INTEGER,
180 usage_ephemeral_1h_input_tokens INTEGER,
181 usage_service_tier TEXT
182 )",
183 [],
184 )?;
185
186 let Some(config) = self.ccql_config() else {
187 return Ok(());
188 };
189
190 let tx = self.conn.transaction()?;
191 {
192 let mut stmt = tx.prepare(
193 "INSERT INTO transcripts (type, content, tool_name, session_id,
194 _source_file, _session_id, _project, _agent_id, timestamp,
195 model, usage_input_tokens, usage_output_tokens,
196 usage_cache_read_input_tokens, usage_cache_creation_input_tokens,
197 usage_ephemeral_5m_input_tokens, usage_ephemeral_1h_input_tokens,
198 usage_service_tier)
199 VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17)",
200 )?;
201
202 for file in discover_transcript_files(&config) {
203 let content = match std::fs::read_to_string(&file.path) {
204 Ok(c) => c,
205 Err(_) => continue,
206 };
207
208 for line in content.lines() {
209 let Ok(entry) = serde_json::from_str::<Value>(line) else {
210 continue;
211 };
212
213 let msg_type = entry.get("type").and_then(|v| v.as_str()).unwrap_or("");
214 let msg_content = entry
215 .get("content")
216 .and_then(|v| v.as_str())
217 .or_else(|| entry.get("message").and_then(|v| v.as_str()))
218 .unwrap_or("");

Callers 1

load_claude_tablesMethod · 0.80

Calls 5

flattened_usage_fieldsFunction · 0.85
ccql_configMethod · 0.80
commitMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected