// lvmh worker bridge: headless pi session via SDK; the lvmh plugin (installed // at /root/.pi/agent/extensions/lvmh-agent.ts) dials the daemon and delivers // web prompts through pi.sendUserMessage. This process just hosts the session. // Global npm layout: resolve pi via absolute path (NODE_PATH does not apply to ESM). import { createAgentSession } from "/usr/local/lib/node_modules/@earendil-works/pi-coding-agent/dist/index.js"; process.on("unhandledRejection", (err) => { console.error("[lvmh-bridge] unhandledRejection:", err); }); try { const { session } = await createAgentSession(); // SDK does not bind extensions implicitly (unlike TUI/RPC modes); without // bindExtensions the session_start event never fires, so the lvmh plugin // would never dial the daemon. await session.bindExtensions({ mode: "rpc" }); console.error(`[lvmh-bridge] session up, cwd=${process.cwd()}`); session.subscribe((event) => { // Keep the loop warm; the extension does the mirroring. if (event.type === "agent_settled") { console.error("[lvmh-bridge] agent settled"); } }); for (const sig of ["SIGTERM", "SIGINT"]) { process.on(sig, () => { console.error(`[lvmh-bridge] ${sig}, exiting`); process.exit(0); }); } // Stay alive forever. setInterval(() => {}, 1 << 30); } catch (err) { console.error("[lvmh-bridge] failed to create agent session", err); process.exit(1); }