diff --git a/.crumb b/.crumb index 771c481..6f6d499 100644 --- a/.crumb +++ b/.crumb @@ -3,14 +3,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-26T15:08:57Z", + "compiled_at": "2026-10-28T22:18:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:eb2e2857e3e1d89df6e7818eec06498e00429e6836885d4eefae061292d28fcc", + "digest": "sha256:4aa3fae3f74477b1aa65d962eb7d8de5726c25a1d6467b69a2fd4f0693721438", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 13, - "generated_at_commit": "4554fcaacd60ac4229b42a2befc3786389831b28", - "source_tree": "sha256:c86ae02d74b5242e82f339ed284a1953c93e2682bc175a41ea2cffd9c3415cd0" + "files": 14, + "generated_at_commit": "1962f7559b6cd73ddbce7293942dd875893f4087", + "source_tree": "sha256:34b1fb5daedec8b201165a2256c1e465e56f356101bc6bc37bcf7476ff2bab0b" } }, "layer": "tooling", diff --git a/AGENTS.md b/AGENTS.md index 2e40d95..a56d865 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ # agent-archive (central archive of AI agent chats on the DGX Spark) -> A single Rust binary that collects every AI agent chat on the DGX Spark (Claude Code, Codex, OpenCode, Gemini/Antigravity on Spark and MacBook, Muse) into plain JSONL records plus a verbatim raw mirror of the source files. This repository holds the collector code and small test fixtures only; the archive data itself lives outside the repository. No network access except a read-only `ssh`/`scp` pull from the MacBook. +> A single Rust binary that collects every AI agent chat on the DGX Spark (OMP, Claude Code, Codex, OpenCode, Gemini/Antigravity on Spark and MacBook, Muse) into plain JSONL records plus a verbatim raw mirror of the source files. This repository holds the collector code and small test fixtures only; the archive data itself lives outside the repository. No network access except a read-only `ssh`/`scp` pull from the MacBook. Shared rules: read https://www.aienos.com/agents/RULES.md first. This file adds what is specific to this repository; where the two differ, this file wins here. diff --git a/README.md b/README.md index 578dd8e..603ec9b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # agent-archive -One central, long-term archive of every AI agent chat on the DGX Spark: Claude Code, Codex, OpenCode, +One central, long-term archive of every AI agent chat on the DGX Spark: OMP, Claude Code, Codex, OpenCode, Gemini/Antigravity (Spark and MacBook) and Muse. Plain JSONL files, one common record per message, plus a verbatim mirror of the original source files. Single Rust binary, no Python, no network except a read-only `ssh`/`scp` pull from the MacBook. @@ -54,7 +54,7 @@ and the raw mirror never writes bytes it already has. ## Record schema ```json -{"ts":"2026-10-04T20:00:00.000Z","agent":"claude|codex|opencode|gemini|muse","host":"spark|macbook", +{"ts":"2026-10-04T20:00:00.000Z","agent":"claude|codex|opencode|gemini|muse|omp","host":"spark|macbook", "session":"","role":"user|assistant|system","text":"...","model":null,"cwd":null, "src":{"path":"...","pos":123}} ``` @@ -81,6 +81,10 @@ agent-archive debug-pb FILE # dump a raw protobuf blob (for Gemini | opencode | `~/.local/share/opencode/opencode.db` (opened read-only), `text` parts; raw mirror is `raw/opencode/spark/opencode-rows.jsonl` (one JSON line per text part, with its message JSON) because the database is live | unit-tested against a small database the test builds with the tables and columns the query reads; no sample of the live database is stored in this repo | | gemini | per-conversation sqlite `.db` in `~/.gemini/antigravity{,-cli,-ide}/conversations` (Spark) and, via `ssh` + `scp` to the host alias `macbook` (an entry in the local ssh config), `~/.gemini/antigravity{,-cli,-ide}/conversations` on the Mac into `raw/gemini/macbook/` | UNVERIFIED format: step blobs are protobuf with no schema available; field numbers (user text 19.3.1, reply 20.1, time 5.1) were inferred from sampling. Reply "thinking" text (20.3) is not turned into records. Mac WAL files are pulled but a `-shm` is not, so uncommitted Mac data may be missed | | muse | `~/.local/share/muse/sessions/**/session.jsonl`; user text from `runtime.user_intent.accepted`, replies from `assistant_message_committed` | partly verified (unit-tested on `tests/fixtures/muse.jsonl`): the original design note named `turn.input.user` / `run.output.delta`, but those did not occur in the 81 sessions on disk when this parser was written, so the events above are used instead. Framed `retained_frame` lines are only kept in raw | +| omp | `~/.omp/agent/sessions/**/*.jsonl` (profile `default`) and `~/.omp/profiles//agent/sessions/**/*.jsonl`, subagent transcripts nested in session directories included; raw mirror is `raw/omp///`. `message` lines with role user/assistant/developer (`developer` becomes `system`), text blocks only; session id and cwd from the `session` line, model from the message (`provider/model`) or the last `model_change` | unit-tested on `tests/fixtures/omp.jsonl` (synthetic, in the real format). The first line of a session file is a space-padded `title` record, apparently so the title can be rewritten in place; the raw mirror only appends, so it keeps that line as first read | + +A source whose directory or database does not exist (for example a retired harness) is skipped without +an error. The Mac pull is skipped (with a log line) if the ssh connection fails, and runs at most every 5 minutes. `~/.gemini/antigravity-cli/history.jsonl` is command history only and is mirrored raw. diff --git a/src/collectors.rs b/src/collectors.rs index 0412ba2..91557c5 100644 --- a/src/collectors.rs +++ b/src/collectors.rs @@ -28,17 +28,22 @@ fn blocks_text(c: &Value, kinds: &[&str]) -> String { } // ---------------- generic JSONL driver ---------------- -fn drive_jsonl(store: &mut Store, agent: &str, host: &str, base: &Path, file: &Path, mut parse: F) -> std::io::Result<()> +fn drive_jsonl(store: &mut Store, agent: &str, host: &str, base: &Path, file: &Path, parse: F) -> std::io::Result<()> where F: FnMut(&str, &str, u64, &mut Value) -> Vec { - let key = rel(file, base); - let cur = store.cursor(agent, &key).cloned(); + drive_jsonl_key(store, agent, host, &rel(file, base), file, parse) +} + +/// `key` is both the cursor key and the path under `raw///`. +fn drive_jsonl_key(store: &mut Store, agent: &str, host: &str, key: &str, file: &Path, mut parse: F) -> std::io::Result<()> +where F: FnMut(&str, &str, u64, &mut Value) -> Vec { + let cur = store.cursor(agent, key).cloned(); let (pos0, mut aux) = match &cur { Some(Value::Object(o)) => (o.get("pos").and_then(|p| p.as_u64()).unwrap_or(0), cur.clone().unwrap()), Some(v) => (v.as_u64().unwrap_or(0), json!({})), None => (0, json!({})), }; if let Ok(m) = std::fs::metadata(file) { if m.len() == pos0 && cur.is_some() { return Ok(()); } } - let raw = store.root.join("raw").join(agent).join(host).join(&key); + let raw = store.root.join("raw").join(agent).join(host).join(key); let mut recs: Vec = Vec::new(); let path_s = file.to_string_lossy().to_string(); let (newpos, reset) = tail_lines(&store.root, file, &raw, pos0, |line, pos| { recs.extend(parse(line, &path_s, pos, &mut aux)); })?; @@ -46,7 +51,7 @@ where F: FnMut(&str, &str, u64, &mut Value) -> Vec { for r in recs { store.emit(r, dup)?; } let mut nv = if aux.is_object() { aux } else { json!({}) }; nv["pos"] = json!(newpos); - store.set_cursor(agent, &key, nv); + store.set_cursor(agent, key, nv); Ok(()) } @@ -154,6 +159,71 @@ pub fn collect_muse(store: &mut Store, cfg: &Cfg) -> std::io::Result<()> { Ok(()) } +// ---------------- omp ---------------- +/// OMP session JSONL: a `session` line (id, cwd), `model_change` lines, and `message` lines whose +/// `message.role` is user / assistant / developer / toolResult. Only text blocks become records. +/// `aux` carries the per-file session id, cwd and model. +pub fn parse_omp(line: &str, path: &str, pos: u64, host: &str, aux: &mut Value) -> Vec { + let Ok(v) = serde_json::from_str::(line) else { return vec![] }; + match v.get("type").and_then(|t| t.as_str()) { + Some("session") => { + if let Some(s) = v.get("id").and_then(|x| x.as_str()) { aux["session"] = json!(s); } + if let Some(c) = v.get("cwd").and_then(|x| x.as_str()) { aux["cwd"] = json!(c); } + return vec![]; + } + Some("model_change") => { + if let Some(m) = v.get("model").and_then(|x| x.as_str()) { aux["model"] = json!(m); } + return vec![]; + } + Some("message") => {} + _ => return vec![], + } + let m = &v["message"]; + let role = match m.get("role").and_then(|r| r.as_str()) { Some("user") => "user", Some("assistant") => "assistant", Some("developer") => "system", _ => return vec![] }; + let Some(ts) = v.get("timestamp").and_then(|t| t.as_str()).and_then(norm_ts) else { return vec![] }; + let text = blocks_text(&m["content"], &["text"]); + if text.trim().is_empty() { return vec![]; } + let session = aux.get("session").and_then(|s| s.as_str()).map(String::from).unwrap_or_else(|| { + let stem = Path::new(path).file_stem().map(|s| s.to_string_lossy().to_string()).unwrap_or_default(); + stem.rsplit_once('_').map(|(_, id)| id.to_string()).unwrap_or(stem) + }); + let model = match (m.get("provider").and_then(|x| x.as_str()), m.get("model").and_then(|x| x.as_str())) { + (Some(p), Some(md)) => Some(format!("{p}/{md}")), + (None, Some(md)) => Some(md.to_string()), + _ => aux.get("model").and_then(|x| x.as_str()).map(String::from), + }; + vec![Record { ts, agent: "omp".into(), host: host.into(), session, role: role.into(), text, model, + cwd: aux.get("cwd").and_then(|m| m.as_str()).map(String::from), src_path: path.into(), src_pos: pos }] +} + +/// Session roots: `~/.omp/agent/sessions` as profile `default`, and `~/.omp/profiles//agent/sessions`. +/// Raw copies land in `raw/omp///`. +pub fn collect_omp(store: &mut Store, cfg: &Cfg) -> std::io::Result<()> { + let omp = cfg.home.join(".omp"); + let mut roots = vec![("default".to_string(), omp.join("agent/sessions"))]; + if let Ok(rd) = std::fs::read_dir(omp.join("profiles")) { + let mut named: Vec<(String, PathBuf)> = rd.flatten() + .map(|e| (e.file_name().to_string_lossy().to_string(), e.path().join("agent/sessions"))) + .collect(); + named.sort(); + roots.extend(named); + } + for (profile, base) in roots { + let mut files = vec![]; walk(&base, "jsonl", &mut files); + files.sort(); + for f in files { + let key = format!("{profile}/{}", rel(&f, &base)); + let host = cfg.host.clone(); + // A subagent file deleted between walk and read is skipped; every other error stops the pass. + match drive_jsonl_key(store, "omp", &cfg.host, &key, &f, |l, p, pos, aux| parse_omp(l, p, pos, &host, aux)) { + Err(e) if e.kind() == std::io::ErrorKind::NotFound => continue, + r => r?, + } + } + } + Ok(()) +} + // ---------------- opencode ---------------- pub fn collect_opencode(store: &mut Store, cfg: &Cfg) -> std::io::Result<()> { let dbp = cfg.home.join(".local/share/opencode/opencode.db"); diff --git a/src/core.rs b/src/core.rs index 35324f9..f6b04e6 100644 --- a/src/core.rs +++ b/src/core.rs @@ -123,7 +123,7 @@ pub fn private_copy(root: &Path, src: &Path, dst: &Path) -> std::io::Result<()> pub const LATEST_LINES: usize = 20000; pub const TXT_MAX_CHARS: usize = 8000; -pub const AGENTS: [&str; 5] = ["claude", "codex", "opencode", "gemini", "muse"]; +pub const AGENTS: [&str; 6] = ["claude", "codex", "opencode", "gemini", "muse", "omp"]; #[derive(Clone, Debug, PartialEq)] pub struct Record { diff --git a/src/main.rs b/src/main.rs index 866b5b4..e5751fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,8 +15,8 @@ fn default_root() -> PathBuf { pub fn pass(store: &mut Store, cfg: &Cfg, mac: bool) { type C = fn(&mut Store, &Cfg) -> std::io::Result<()>; - let steps: [(&str, C); 5] = [("claude", collect_claude), ("codex", collect_codex), ("opencode", collect_opencode), - ("gemini", collect_gemini), ("muse", collect_muse)]; + let steps: [(&str, C); 6] = [("claude", collect_claude), ("codex", collect_codex), ("opencode", collect_opencode), + ("gemini", collect_gemini), ("muse", collect_muse), ("omp", collect_omp)]; for (name, f) in steps { if let Err(e) = f(store, cfg) { eprintln!("collector {name} failed: {e}"); } } @@ -41,7 +41,7 @@ fn arg(args: &[String], name: &str) -> Option { fn status(root: &std::path::Path) -> std::io::Result<()> { let today = format!("{}.jsonl", chrono::Utc::now().format("%Y-%m-%d")); let st = Store::open(root)?; - println!("{:<9} {:<26} {:>12} {:>8} {}", "agent", "last record", "today", "sources", "preview"); + println!("{:<9} {:<26} {:>12} {:>8} preview", "agent", "last record", "today", "sources"); for a in AGENTS { let tail = load_tail(root, a, 1)?; let (last, prev) = tail.last().map(|(t, r)| (t.clone(), r.text.chars().take(80).collect::().replace('\n', " "))).unwrap_or(("-".into(), String::new())); @@ -242,6 +242,67 @@ mod tests { assert_eq!(fs::metadata(root.join("raw/claude/spark/-p/sess1.jsonl")).unwrap().len() as usize, more_complete_len); } + #[test] + fn omp_parser_text_roles_session_cwd_model() { + let mut aux = serde_json::json!({}); + let p = "/s/-tmp/2026-10-27T15-28-55-484Z_01a17dfa-90bc-74e6-a642-d39b97cce56c.jsonl"; + let recs: Vec<_> = fixture("omp.jsonl").lines().flat_map(|l| parse_omp(l, p, 0, "spark", &mut aux)).collect(); + let got: Vec<(&str, &str)> = recs.iter().map(|r| (r.role.as_str(), r.text.as_str())).collect(); + assert_eq!(got, [("user", "testing"), ("assistant", "DONE")]); + assert_eq!(recs[0].session, "01a17dfa-90bc-74e6-a642-d39b97cce56c"); + assert_eq!(recs[0].cwd.as_deref(), Some("/tmp")); + assert_eq!(recs[0].model.as_deref(), Some("spark/qwen3.6-35b-a3b-fp8")); + assert_eq!(recs[1].model.as_deref(), Some("spark/qwen3.6-35b-a3b-fp8")); + assert_eq!(recs[1].ts, "2026-10-27T15:29:55.275Z"); + } + + #[test] + fn omp_pass_profiles_and_nested_subagents() { + let home = tmp("omphome"); + let root = tmp("omproot"); + let fx = fixture("omp.jsonl"); + let def = home.join(".omp/agent/sessions/-tmp/2026-10-27T15-28-55-484Z_aaaa"); + let named = home.join(".omp/profiles/work/agent/sessions/-p"); + fs::create_dir_all(&def).unwrap(); + fs::create_dir_all(&named).unwrap(); + fs::create_dir_all(home.join(".omp/profiles/empty/agent")).unwrap(); + fs::write(def.with_extension("jsonl"), &fx).unwrap(); + fs::write(def.join("0-Sub.jsonl"), &fx).unwrap(); + fs::write(def.join("0-Sub.log"), "not a transcript").unwrap(); + fs::write(named.join("s.jsonl"), &fx).unwrap(); + let cfg = Cfg { home, host: "spark".into(), mac: false }; + let mut st = Store::open(&root).unwrap(); + pass(&mut st, &cfg, false); + // the three files share one session id but differ in src.path, so all six records are kept + assert_eq!(count(&root, "omp"), 6); + let raw = root.join("raw/omp/spark"); + assert_eq!(fs::read_to_string(raw.join("default/-tmp/2026-10-27T15-28-55-484Z_aaaa.jsonl")).unwrap(), fx); + assert_eq!(fs::read_to_string(raw.join("default/-tmp/2026-10-27T15-28-55-484Z_aaaa/0-Sub.jsonl")).unwrap(), fx); + assert_eq!(fs::read_to_string(raw.join("work/-p/s.jsonl")).unwrap(), fx); + assert!(!raw.join("default/-tmp/2026-10-27T15-28-55-484Z_aaaa/0-Sub.log").exists()); + pass(&mut st, &cfg, false); + assert_eq!(count(&root, "omp"), 6); + } + + #[test] + fn missing_harness_dirs_are_a_silent_no_op() { + let home = tmp("emptyhome"); + let root = tmp("emptyroot"); + let cfg = Cfg { home, host: "spark".into(), mac: false }; + let mut st = Store::open(&root).unwrap(); + for a in AGENTS { + let r = match a { + "claude" => collect_claude(&mut st, &cfg), "codex" => collect_codex(&mut st, &cfg), + "opencode" => collect_opencode(&mut st, &cfg), "gemini" => collect_gemini(&mut st, &cfg), + "muse" => collect_muse(&mut st, &cfg), "omp" => collect_omp(&mut st, &cfg), + _ => unreachable!(), + }; + assert!(r.is_ok(), "{a}: {r:?}"); + assert_eq!(count(&root, a), 0); + } + assert_eq!(fs::read_dir(root.join("raw")).unwrap().count(), 0); + } + #[test] fn opencode_collects_text_parts() { let home = tmp("ochome"); diff --git a/tests/fixtures/omp.jsonl b/tests/fixtures/omp.jsonl new file mode 100644 index 0000000..e0451dc --- /dev/null +++ b/tests/fixtures/omp.jsonl @@ -0,0 +1,9 @@ +{"type":"title","v":1,"title":"","updatedAt":"2026-10-27T15:28:55.484Z","pad":" "} +{"type":"session","version":3,"id":"01a17dfa-90bc-74e6-a642-d39b97cce56c","timestamp":"2026-10-27T15:28:55.484Z","cwd":"/tmp"} +{"type":"model_change","id":"99580e83","parentId":null,"timestamp":"2026-10-27T15:28:55.529Z","runtime":{"version":"18.13.1"},"model":"spark/qwen3.6-35b-a3b-fp8","resolvedModelIsFallback":false} +{"type":"message","id":"86708134","parentId":"99580e83","timestamp":"2026-10-27T15:29:01.899Z","runtime":{"version":"18.13.1"},"message":{"role":"user","content":[{"type":"text","text":"testing"}],"attribution":"user","timestamp":1793114941857}} +{"type":"custom","customType":"system-prompt-digest","id":"768f60fa","parentId":"86708134","timestamp":"2026-10-27T15:29:55.275Z","runtime":{"version":"18.13.1"}} +{"type":"message","id":"a1b2c3d4","parentId":"768f60fa","timestamp":"2026-10-27T15:29:50.000Z","runtime":{"version":"18.13.1"},"message":{"role":"assistant","content":[{"type":"thinking","thinking":"hidden"},{"type":"toolCall","id":"c1","name":"read","arguments":{"path":"x"}}],"provider":"spark","model":"qwen3.6-35b-a3b-fp8"}} +{"type":"message","id":"e5f6a7b8","parentId":"a1b2c3d4","timestamp":"2026-10-27T15:29:51.000Z","runtime":{"version":"18.13.1"},"message":{"role":"toolResult","toolCallId":"c1","content":[{"type":"text","text":"file body"}]}} +{"type":"message","id":"a6e5838e","parentId":"e5f6a7b8","timestamp":"2026-10-27T15:29:55.275Z","runtime":{"version":"18.13.1"},"message":{"role":"assistant","content":[{"type":"thinking","thinking":"hidden"},{"type":"text","text":"DONE"}],"provider":"spark","model":"qwen3.6-35b-a3b-fp8","stopReason":"stop"}} +{"type":"custom","customType":"session_exit","id":"9dd4a356","parentId":"a6e5838e","timestamp":"2026-10-27T15:31:35.917Z","runtime":{"version":"18.13.1"}}