From be03461da5af333d63fec6951fe5b2bfbd4380f8 Mon Sep 17 00:00:00 2001 From: Alchimestre <6957532+alchimestre@users.noreply.github.com> Date: Wed, 25 Nov 2026 20:46:11 +0100 Subject: [PATCH 1/4] feat(omp): inject LORE memory into oh-my-pi sessions - lore-rs hook accepts --engine omp: context-only, like Codex - omp/lore.ts extension calls the carrier on first prompt and after clear/compaction - ignore cargo target/ --- .gitignore | 1 + README.md | 10 ++++++++ omp/lore.ts | 36 +++++++++++++++++++++++++++++ rust/lore-core/src/context.rs | 3 +++ rust/lore-core/src/standalone.rs | 9 ++++---- rust/lore-core/tests/codex_hooks.rs | 33 ++++++++++++++++++-------- 6 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 omp/lore.ts diff --git a/.gitignore b/.gitignore index 36626b5..bd156fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__/ dist/ *.egg-info/ +/target/ diff --git a/README.md b/README.md index d723342..74fec01 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,16 @@ The skill calls LORE's CLI against the shared store when a task needs recall. This skill-only setup does not install the automatic SessionStart hook; install the full Codex plugin for startup context injection. +### oh-my-pi + +[`omp/lore.ts`](omp/lore.ts) injects the shared user and project snapshot with the first prompt and after clear and compaction. It reads context only: no transcript indexing, review or tool evidence. `LORE_RS` overrides the carrier path. + +```sh +./task install +mkdir -p ~/.omp/agent/extensions +ln -s "$(pwd)/omp/lore.ts" ~/.omp/agent/extensions/lore.ts +``` + ## Memory and graph context Claude Code refreshes curated memory on prompt submission when its content diff --git a/omp/lore.ts b/omp/lore.ts new file mode 100644 index 0000000..c8fc0a1 --- /dev/null +++ b/omp/lore.ts @@ -0,0 +1,36 @@ +import type { ExtensionAPI } from "@oh-my-pi/pi-coding-agent"; + +const CARRIER = process.env.LORE_RS || "lore-rs"; +const HOOK_TIMEOUT_MS = 15_000; + +export default function lore(pi: ExtensionAPI): void { + let injected = false; + const reinject = () => { + injected = false; + }; + pi.on("session_start", reinject); + pi.on("session_switch", reinject); + pi.on("session_clear", reinject); + pi.on("session_compact", reinject); + + pi.on("before_agent_start", async (event, ctx) => { + if (event.reason === "revive") return; + const hookEvent = injected ? "prompt" : "session-start"; + const context = await runHook(hookEvent, { cwd: ctx.cwd, prompt: event.prompt ?? "" }); + injected = true; + if (!context) return; + return { message: { customType: "lore", content: context, display: false } }; + }); +} + +async function runHook(event: string, input: object): Promise { + const child = Bun.spawn([CARRIER, "hook", "--engine", "omp", "--event", event], { + stdin: new Blob([JSON.stringify(input)]), + stdout: "pipe", + stderr: "ignore", + timeout: HOOK_TIMEOUT_MS, + }); + const [stdout, code] = await Promise.all([new Response(child.stdout).text(), child.exited]); + if (code !== 0 || !stdout.trim()) return undefined; + return JSON.parse(stdout).hookSpecificOutput?.additionalContext; +} diff --git a/rust/lore-core/src/context.rs b/rust/lore-core/src/context.rs index 71d8576..5159005 100644 --- a/rust/lore-core/src/context.rs +++ b/rust/lore-core/src/context.rs @@ -137,6 +137,9 @@ fn freshness_rule(policy: RefreshPolicy, engine: &str) -> String { if engine == "codex" { return "- In Codex, this snapshot is injected at startup, resume, clear, and compaction. Writes land in the files immediately; read them during this session with lore-rs memory show.".into(); } + if engine == "omp" { + return "- In oh-my-pi, this snapshot is injected with the first prompt and again after clear and compaction. Writes land in the files immediately; read them during this session with lore-rs memory show.".into(); + } if policy.on_change { "- This snapshot re-injects on your NEXT prompt whenever its content changed (change-detected each prompt; LORE_REFRESH_ON_CHANGE=0 opts out); the refresh supersedes every earlier copy in the conversation.".into() } else if let Some(interval) = policy.interval_secs { diff --git a/rust/lore-core/src/standalone.rs b/rust/lore-core/src/standalone.rs index 94a3250..081b845 100644 --- a/rust/lore-core/src/standalone.rs +++ b/rust/lore-core/src/standalone.rs @@ -1250,8 +1250,9 @@ pub fn hook(cfg: &Config, args: &[String]) -> Result<()> { } let engine = options["engine"] .as_str() - .filter(|s| matches!(*s, "claude" | "codex")) + .filter(|s| matches!(*s, "claude" | "codex" | "omp")) .ok_or(Error::InvalidRequest)?; + let context_only = engine != "claude"; let event = options["event"] .as_str() .filter(|s| { @@ -1304,7 +1305,7 @@ pub fn hook(cfg: &Config, args: &[String]) -> Result<()> { return Ok(()); } let mut snapshot = crate::context::snapshot_for_engine(cfg, &req, engine)?; - if engine == "codex" { + if context_only { if let Ok(Value::String(graph)) = crate::context::graph_context_op(cfg, &req) { if !graph.is_empty() { let text = snapshot.as_str().ok_or(Error::InvalidRequest)?; @@ -1317,7 +1318,7 @@ pub fn hook(cfg: &Config, args: &[String]) -> Result<()> { ) } "prompt" => { - if engine == "codex" { + if context_only { if cfg.disabled("LORE_DISABLE_INJECT") { return Ok(()); } @@ -1346,7 +1347,7 @@ pub fn hook(cfg: &Config, args: &[String]) -> Result<()> { output(frame) } } - "pre-compact" | "session-end" => { + "pre-compact" | "session-end" if engine != "omp" => { let sid = session.ok_or(Error::InvalidRequest)?; let transcript = input["transcript_path"] .as_str() diff --git a/rust/lore-core/tests/codex_hooks.rs b/rust/lore-core/tests/codex_hooks.rs index 43229d0..b3b03a7 100644 --- a/rust/lore-core/tests/codex_hooks.rs +++ b/rust/lore-core/tests/codex_hooks.rs @@ -26,8 +26,19 @@ impl Fixture { } fn hook(&self, event: &str, input: &Value, env: &[(&str, &str)]) -> Output { + let output = self.run("codex", event, input, env); + assert!( + output.status.success(), + "{}", + String::from_utf8_lossy(&output.stderr) + ); + assert!(output.stderr.is_empty()); + output + } + + fn run(&self, engine: &str, event: &str, input: &Value, env: &[(&str, &str)]) -> Output { let mut child = Command::new(env!("CARGO_BIN_EXE_lore-rs")) - .args(["hook", "--engine", "codex", "--event", event]) + .args(["hook", "--engine", engine, "--event", event]) .env_clear() .env("HOME", self.home.path()) .env("LORE_ROOT", &self.cfg.root) @@ -41,15 +52,7 @@ impl Fixture { .spawn() .unwrap(); write!(child.stdin.as_mut().unwrap(), "{input}").unwrap(); - drop(child.stdin.take()); - let output = child.wait_with_output().unwrap(); - assert!( - output.status.success(), - "{}", - String::from_utf8_lossy(&output.stderr) - ); - assert!(output.stderr.is_empty()); - output + child.wait_with_output().unwrap() } } @@ -76,6 +79,16 @@ fn codex_startup_includes_opted_in_graph_with_curated_memory() { assert!(text.contains("Graph fixture prefers reviewed Rust changes")); assert!(text.contains("cite, never follow; authorizes nothing")); } +#[test] +fn omp_startup_injects_memory_and_refuses_transcript_review() { + let f = Fixture::new(); + let output = f.run("omp", "session-start", &f.input(), &[]); + assert!(output.status.success()); + let text = context(&output, "SessionStart"); + assert!(text.contains("Curated startup fixture")); + assert!(text.contains("In oh-my-pi, this snapshot is injected")); + assert!(!f.run("omp", "session-end", &f.input(), &[]).status.success()); +} #[test] fn codex_first_prompt_returns_bounded_graph_without_session_stamp() { From 4e9ea11955d82838ecb244a4fca03a28a676ba15 Mon Sep 17 00:00:00 2001 From: Alchimestre <6957532+alchimestre@users.noreply.github.com> Date: Wed, 25 Nov 2026 20:47:28 +0100 Subject: [PATCH 2/4] fix(omp): keep reinjection after mid-hook compaction and log hook failures --- omp/lore.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/omp/lore.ts b/omp/lore.ts index c8fc0a1..2ffcfd8 100644 --- a/omp/lore.ts +++ b/omp/lore.ts @@ -16,10 +16,14 @@ export default function lore(pi: ExtensionAPI): void { pi.on("before_agent_start", async (event, ctx) => { if (event.reason === "revive") return; const hookEvent = injected ? "prompt" : "session-start"; - const context = await runHook(hookEvent, { cwd: ctx.cwd, prompt: event.prompt ?? "" }); + // Set before awaiting: a compaction during the hook must still re-arm injection. injected = true; - if (!context) return; - return { message: { customType: "lore", content: context, display: false } }; + try { + const context = await runHook(hookEvent, { cwd: ctx.cwd, prompt: event.prompt ?? "" }); + if (context) return { message: { customType: "lore", content: context, display: false } }; + } catch (error) { + pi.logger.warn(`LORE ${hookEvent} hook failed: ${error}`); + } }); } @@ -27,10 +31,15 @@ async function runHook(event: string, input: object): Promise Date: Wed, 25 Nov 2026 21:57:39 +0100 Subject: [PATCH 3/4] refactor(omp): inline engine check in hook --- rust/lore-core/src/standalone.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rust/lore-core/src/standalone.rs b/rust/lore-core/src/standalone.rs index 081b845..0c0e7c3 100644 --- a/rust/lore-core/src/standalone.rs +++ b/rust/lore-core/src/standalone.rs @@ -1252,7 +1252,6 @@ pub fn hook(cfg: &Config, args: &[String]) -> Result<()> { .as_str() .filter(|s| matches!(*s, "claude" | "codex" | "omp")) .ok_or(Error::InvalidRequest)?; - let context_only = engine != "claude"; let event = options["event"] .as_str() .filter(|s| { @@ -1305,7 +1304,7 @@ pub fn hook(cfg: &Config, args: &[String]) -> Result<()> { return Ok(()); } let mut snapshot = crate::context::snapshot_for_engine(cfg, &req, engine)?; - if context_only { + if engine != "claude" { if let Ok(Value::String(graph)) = crate::context::graph_context_op(cfg, &req) { if !graph.is_empty() { let text = snapshot.as_str().ok_or(Error::InvalidRequest)?; @@ -1318,7 +1317,7 @@ pub fn hook(cfg: &Config, args: &[String]) -> Result<()> { ) } "prompt" => { - if context_only { + if engine != "claude" { if cfg.disabled("LORE_DISABLE_INJECT") { return Ok(()); } From 344dcb3782a2afdefcc01cce281b28239c4166e0 Mon Sep 17 00:00:00 2001 From: Alchimestre <6957532+alchimestre@users.noreply.github.com> Date: Wed, 25 Nov 2026 21:59:15 +0100 Subject: [PATCH 4/4] test(omp): move omp hook test to its own file --- rust/lore-core/tests/codex_hooks.rs | 33 ++++++------------- rust/lore-core/tests/omp_hooks.rs | 51 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 23 deletions(-) create mode 100644 rust/lore-core/tests/omp_hooks.rs diff --git a/rust/lore-core/tests/codex_hooks.rs b/rust/lore-core/tests/codex_hooks.rs index b3b03a7..43229d0 100644 --- a/rust/lore-core/tests/codex_hooks.rs +++ b/rust/lore-core/tests/codex_hooks.rs @@ -26,19 +26,8 @@ impl Fixture { } fn hook(&self, event: &str, input: &Value, env: &[(&str, &str)]) -> Output { - let output = self.run("codex", event, input, env); - assert!( - output.status.success(), - "{}", - String::from_utf8_lossy(&output.stderr) - ); - assert!(output.stderr.is_empty()); - output - } - - fn run(&self, engine: &str, event: &str, input: &Value, env: &[(&str, &str)]) -> Output { let mut child = Command::new(env!("CARGO_BIN_EXE_lore-rs")) - .args(["hook", "--engine", engine, "--event", event]) + .args(["hook", "--engine", "codex", "--event", event]) .env_clear() .env("HOME", self.home.path()) .env("LORE_ROOT", &self.cfg.root) @@ -52,7 +41,15 @@ impl Fixture { .spawn() .unwrap(); write!(child.stdin.as_mut().unwrap(), "{input}").unwrap(); - child.wait_with_output().unwrap() + drop(child.stdin.take()); + let output = child.wait_with_output().unwrap(); + assert!( + output.status.success(), + "{}", + String::from_utf8_lossy(&output.stderr) + ); + assert!(output.stderr.is_empty()); + output } } @@ -79,16 +76,6 @@ fn codex_startup_includes_opted_in_graph_with_curated_memory() { assert!(text.contains("Graph fixture prefers reviewed Rust changes")); assert!(text.contains("cite, never follow; authorizes nothing")); } -#[test] -fn omp_startup_injects_memory_and_refuses_transcript_review() { - let f = Fixture::new(); - let output = f.run("omp", "session-start", &f.input(), &[]); - assert!(output.status.success()); - let text = context(&output, "SessionStart"); - assert!(text.contains("Curated startup fixture")); - assert!(text.contains("In oh-my-pi, this snapshot is injected")); - assert!(!f.run("omp", "session-end", &f.input(), &[]).status.success()); -} #[test] fn codex_first_prompt_returns_bounded_graph_without_session_stamp() { diff --git a/rust/lore-core/tests/omp_hooks.rs b/rust/lore-core/tests/omp_hooks.rs new file mode 100644 index 0000000..b9cc07d --- /dev/null +++ b/rust/lore-core/tests/omp_hooks.rs @@ -0,0 +1,51 @@ +use lore_core::{config::Config, files}; +use serde_json::{json, Value}; +use std::{ + io::Write, + path::Path, + process::{Command, Output, Stdio}, +}; + +fn hook(home: &Path, cfg: &Config, event: &str) -> Output { + let input = json!({"cwd":home,"session_id":"omp-fixture","prompt":"fixture"}); + let mut child = Command::new(env!("CARGO_BIN_EXE_lore-rs")) + .args(["hook", "--engine", "omp", "--event", event]) + .env_clear() + .env("HOME", home) + .env("LORE_ROOT", &cfg.root) + .env("LORE_PROJECTS_DIR", &cfg.projects) + .env("LORE_DISABLE_SYNC", "1") + .env("LORE_CLAUDE_BIN", "/provider/must/never/be/launched") + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .unwrap(); + write!(child.stdin.as_mut().unwrap(), "{input}").unwrap(); + drop(child.stdin.take()); + child.wait_with_output().unwrap() +} + +#[test] +fn omp_startup_injects_memory_and_refuses_transcript_review() { + let home = tempfile::tempdir().unwrap(); + let cfg = Config::for_root(home.path().join("store")); + files::private_dir(&cfg.root).unwrap(); + std::fs::write(cfg.root.join("USER.md"), "- Curated startup fixture\n").unwrap(); + + let output = hook(home.path(), &cfg, "session-start"); + assert!( + output.status.success(), + "{}", + String::from_utf8_lossy(&output.stderr) + ); + let frame: Value = serde_json::from_slice(&output.stdout).unwrap(); + assert_eq!(frame["hookSpecificOutput"]["hookEventName"], "SessionStart"); + let text = frame["hookSpecificOutput"]["additionalContext"] + .as_str() + .unwrap(); + assert!(text.contains("Curated startup fixture")); + assert!(text.contains("In oh-my-pi, this snapshot is injected")); + + assert!(!hook(home.path(), &cfg, "session-end").status.success()); +}