Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889import type { Plugin } from "@opencode-ai/plugin"
const Notify: Plugin = async (ctx) => { // Build a from-URI with context (similar to claude-hook) async function buildFrom(): Promise<string> { const user = (await ctx.$`whoami`.quiet().nothrow().text()).trim() || "unknown" const host = (await ctx.$`hostname -s`.quiet().nothrow().text()).trim() || "unknown" const cwd = ctx.directory
const parts: string[] = [] parts.push(`pid=${process.pid}`)
// Zellij context const zellij = process.env.ZELLIJ if (zellij) { const session = process.env.ZELLIJ_SESSION_NAME || "" const tab = ( await ctx.$`zellij action query-tab-names` .quiet() .nothrow() .text() ) .trim() .split("\n")[0] const pane = process.env.ZELLIJ_PANE_ID || "" const zj = [session, tab, pane].filter(Boolean).join(".") if (zj) parts.push(`zellij=${encodeURIComponent(zj)}`) }
// Niri window ID for focus-on-click try { const niriJson = await ctx.$`niri msg focused-window --json` .quiet() .nothrow() .text() const niriId = JSON.parse(niriJson)?.id if (niriId) parts.push(`niri_window=${niriId}`) } catch {}
return `${user}@${host}:${cwd}?${parts.join("&")}` }
// Debounce: skip if we notified very recently let lastNotifyTime = 0 const DEBOUNCE_MS = 3000
async function notify( type: string, title: string, body: string, urgency: string, ) { const now = Date.now() if (now - lastNotifyTime < DEBOUNCE_MS) return lastNotifyTime = now
const from = await buildFrom() // Use setsid to detach so Bun's shell doesn't kill pw-play mid-sound ctx .$`setsid claude-notify --type ${type} --title ${title} --body ${body} --urgency ${urgency} --from ${from}` .quiet() .nothrow() }
return { async event({ event }) { if ( event.type === "session.status" && event.properties.status.type === "idle" ) { await notify("idle", "opencode", "Session idle", "normal") }
if (event.type === "permission.asked") { await notify( "permission", "opencode", "Permission needed", "critical", ) } }, }}
export default Notify