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

Method load_jhistory

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

Source from the content-addressed store, hash-verified

345 }
346
347 fn load_jhistory(&mut self) -> Result<()> {
348 self.conn.execute(
349 "CREATE TABLE IF NOT EXISTS jhistory (
350 rowid INTEGER PRIMARY KEY,
351 session_id TEXT,
352 ts INTEGER,
353 text TEXT,
354 display TEXT,
355 timestamp INTEGER
356 )",
357 [],
358 )?;
359 self.conn.execute(
360 "CREATE VIEW IF NOT EXISTS codex_history AS SELECT * FROM jhistory",
361 [],
362 )?;
363
364 let jhistory_path = self.codex_data_dir.join("history.jsonl");
365 if !jhistory_path.exists() {
366 return Ok(());
367 }
368
369 let content = std::fs::read_to_string(&jhistory_path)?;
370 for line in content.lines() {
371 if let Ok(entry) = serde_json::from_str::<Value>(line) {
372 let text = entry
373 .get("text")
374 .or_else(|| entry.get("display"))
375 .and_then(json_value_as_string)
376 .unwrap_or_default();
377
378 let session_id = entry
379 .get("session_id")
380 .or_else(|| entry.get("sessionId"))
381 .and_then(json_value_as_string)
382 .unwrap_or_default();
383
384 let ts = entry
385 .get("ts")
386 .and_then(json_number_as_i64)
387 .or_else(|| {
388 entry
389 .get("timestamp")
390 .and_then(json_number_as_i64)
391 .map(normalize_ts_seconds)
392 })
393 .unwrap_or(0);
394
395 let timestamp = ts.saturating_mul(1000);
396
397 self.conn.execute(
398 "INSERT INTO jhistory (session_id, ts, text, display, timestamp)
399 VALUES (?1, ?2, ?3, ?4, ?5)",
400 params![session_id, ts, text.clone(), text, timestamp],
401 )?;
402 }
403 }
404

Callers 1

load_claude_tablesMethod · 0.80

Calls 1

executeMethod · 0.45

Tested by

no test coverage detected