Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
dist/
*.egg-info/
/target/
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions omp/lore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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";
// Set before awaiting: a compaction during the hook must still re-arm injection.
injected = true;
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}`);
}
});
}

async function runHook(event: string, input: object): Promise<string | undefined> {
const child = Bun.spawn([CARRIER, "hook", "--engine", "omp", "--event", event], {
stdin: new Blob([JSON.stringify(input)]),
stdout: "pipe",
stderr: "pipe",
timeout: HOOK_TIMEOUT_MS,
});
const [stdout, stderr, code] = await Promise.all([
new Response(child.stdout).text(),
new Response(child.stderr).text(),
child.exited,
]);
if (code !== 0) throw new Error(`${CARRIER} exited ${code}: ${stderr.trim()}`);
if (!stdout.trim()) return undefined;
return JSON.parse(stdout).hookSpecificOutput?.additionalContext;
}
3 changes: 3 additions & 0 deletions rust/lore-core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions rust/lore-core/src/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ 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 event = options["event"]
.as_str()
Expand Down Expand Up @@ -1304,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 engine == "codex" {
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)?;
Expand All @@ -1317,7 +1317,7 @@ pub fn hook(cfg: &Config, args: &[String]) -> Result<()> {
)
}
"prompt" => {
if engine == "codex" {
if engine != "claude" {
if cfg.disabled("LORE_DISABLE_INJECT") {
return Ok(());
}
Expand Down Expand Up @@ -1346,7 +1346,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()
Expand Down
51 changes: 51 additions & 0 deletions rust/lore-core/tests/omp_hooks.rs
Original file line number Diff line number Diff line change
@@ -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());
}