/** * OAS pi runtime bridge — minimal glue. * * The kernel materializes every spawned instance's exact set in * .agents/skills; this bridge contributes it inside an instance, plus the * pre-workspace oas-getting-started bootstrap outside one, and drives the * memory session events. Ambient skills coexist with the OAS-composed set. */ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { appendLogEntry, PACKAGED_SKILLS_DIR } from "./core-loader.mjs"; import { existsSync, readFileSync } from "node:fs"; import { join } from "node:path"; export default function (pi: ExtensionAPI) { const agentHome = process.env.PI_AGENT_HOME; const isInstance = !!agentHome && existsSync(join(agentHome, "instance.json")); pi.on("resources_discover", async () => { if (isInstance) { const local = join(agentHome!, ".agents", "skills"); return existsSync(local) ? { skillPaths: [local] } : undefined; } const gettingStarted = join(PACKAGED_SKILLS_DIR, "oas-getting-started"); return existsSync(gettingStarted) ? { skillPaths: [gettingStarted] } : undefined; }); if (isInstance) { pi.on("session_compact", async (event) => { if (!existsSync(join(agentHome!, "STATE.md"))) return; try { const summary = (event.compactionEntry?.summary ?? "").replace(/\s+/g, " ").trim(); appendLogEntry( join(agentHome!, "log.md"), `**Compaction** (${event.reason}): ${summary.slice(0, 400)}${summary.length > 400 ? "…" : ""}`, "Instance Log", ); } catch { /* memory automation must never break a session */ } pi.sendMessage({ customType: "oas-memory", content: "Context was just compacted. Before continuing, update ./STATE.md (Plan/Progress/Next) so a fresh session could resume from files alone.", display: false, }, { deliverAs: "steer" }); }); pi.on("session_start", async (event) => { if (event.reason !== "startup" && event.reason !== "resume" && event.reason !== "new") return; const statePath = join(agentHome!, "STATE.md"); if (!existsSync(statePath)) return; const state = readFileSync(statePath, "utf8"); const touched = !/_No task assigned yet/.test(state) || !/_\(the single next action/.test(state); if (event.reason === "startup" && !touched) return; pi.sendMessage({ customType: "oas-memory", content: `You are agent instance home ${agentHome}. Read ./STATE.md and the recent entries of ./log.md now, then continue from STATE.md's "Next" section. Keep STATE.md current as you work.`, display: false, }, { deliverAs: "steer", triggerTurn: false }); }); } }