Skip to content

Instantly share code, notes, and snippets.

@brand-it
Created August 13, 2026 18:27
Show Gist options
  • Select an option

  • Save brand-it/0d8e4e491dbb7e08ad2bafaf15d745a0 to your computer and use it in GitHub Desktop.

Select an option

Save brand-it/0d8e4e491dbb7e08ad2bafaf15d745a0 to your computer and use it in GitHub Desktop.
Mac extention for OMP to keep the PC awake when it is doing things. Places a little ☕ icon when it is working. just add it to `~/.omp/agent/extensions/caffeinate.ts`
import { spawn, type ChildProcess } from "node:child_process";
export default function (pi: { on: Function }) {
let caffeinate: ChildProcess | undefined;
const stop = (ctx: { ui: { setWorkingMessage(message?: string): void } }) => {
const wakeLock = caffeinate;
caffeinate = undefined;
wakeLock?.kill();
ctx.ui.setWorkingMessage();
};
pi.on("agent_start", (_event: unknown, ctx: { ui: { setWorkingMessage(message?: string): void } }) => {
if (process.platform !== "darwin" || caffeinate) return;
const wakeLock = spawn("/usr/bin/caffeinate", ["-i", "-w", String(process.pid)], {
detached: true,
stdio: "ignore",
});
caffeinate = wakeLock;
wakeLock.once("spawn", () => {
if (caffeinate === wakeLock) ctx.ui.setWorkingMessage("☕ Working…");
});
wakeLock.once("error", () => {
if (caffeinate === wakeLock) stop(ctx);
});
wakeLock.once("exit", () => {
if (caffeinate === wakeLock) stop(ctx);
});
wakeLock.unref();
});
pi.on(
"tool_execution_start",
(
event: { intent?: unknown },
ctx: {
ui: { setWorkingMessage(message?: string): void };
setTimeout(callback: () => void, ms?: number): unknown;
},
) => {
if (!caffeinate) return;
const intent = typeof event.intent === "string" ? event.intent.trim() : "";
ctx.setTimeout(() => {
if (caffeinate) ctx.ui.setWorkingMessage(intent ? `☕ ${intent}` : "☕ Working…");
}, 0);
},
);
pi.on(
"agent_end",
(
event: { isTerminal?: boolean },
ctx: {
isIdle(): boolean;
setTimeout(callback: () => void, ms?: number): unknown;
ui: { setWorkingMessage(message?: string): void };
},
) => {
if (event.isTerminal === false) return;
ctx.setTimeout(() => {
if (ctx.isIdle()) stop(ctx);
}, 0);
},
);
pi.on("session_shutdown", (_event: unknown, ctx: { ui: { setWorkingMessage(message?: string): void } }) => {
stop(ctx);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment