mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 14:01:06 +00:00
feat(coding-agent): add a spinner extension (#1131)
When the agent is running, we prefix an animated braille spinner to the title to show busy state. Its cleared when the agent is done
This commit is contained in:
parent
aa83170e0f
commit
71d7a14b18
3 changed files with 63 additions and 0 deletions
|
|
@ -56,6 +56,7 @@ cp permission-gate.ts ~/.pi/agent/extensions/
|
|||
| `modal-editor.ts` | Custom vim-like modal editor via `ctx.ui.setEditorComponent()` |
|
||||
| `rainbow-editor.ts` | Animated rainbow text effect via custom editor |
|
||||
| `notify.ts` | Desktop notifications via OSC 777 when agent finishes (Ghostty, iTerm2, WezTerm) |
|
||||
| `titlebar-spinner.ts` | Braille spinner animation in terminal title while the agent is working |
|
||||
| `summarize.ts` | Summarize conversation with GPT-5.2 and show in transient UI |
|
||||
| `custom-footer.ts` | Custom footer with git branch and token stats via `ctx.ui.setFooter()` |
|
||||
| `custom-header.ts` | Custom header via `ctx.ui.setHeader()` |
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* Titlebar Spinner Extension
|
||||
*
|
||||
* Shows a braille spinner animation in the terminal title while the agent is working.
|
||||
* Uses `ctx.ui.setTitle()` to update the terminal title via the extension API.
|
||||
*
|
||||
* Usage:
|
||||
* pi --extension examples/extensions/titlebar-spinner.ts
|
||||
*/
|
||||
|
||||
import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent";
|
||||
import path from "node:path";
|
||||
|
||||
const BRAILLE_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
||||
|
||||
function getBaseTitle(pi: ExtensionAPI): string {
|
||||
const cwd = path.basename(process.cwd());
|
||||
const session = pi.getSessionName();
|
||||
return session ? `π - ${session} - ${cwd}` : `π - ${cwd}`;
|
||||
}
|
||||
|
||||
export default function (pi: ExtensionAPI) {
|
||||
let timer: ReturnType<typeof setInterval> | null = null;
|
||||
let frameIndex = 0;
|
||||
|
||||
function stopAnimation(ctx: ExtensionContext) {
|
||||
if (timer) {
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
}
|
||||
frameIndex = 0;
|
||||
ctx.ui.setTitle(getBaseTitle(pi));
|
||||
}
|
||||
|
||||
function startAnimation(ctx: ExtensionContext) {
|
||||
stopAnimation(ctx);
|
||||
timer = setInterval(() => {
|
||||
const frame = BRAILLE_FRAMES[frameIndex % BRAILLE_FRAMES.length];
|
||||
const cwd = path.basename(process.cwd());
|
||||
const session = pi.getSessionName();
|
||||
const title = session ? `${frame} π - ${session} - ${cwd}` : `${frame} π - ${cwd}`;
|
||||
ctx.ui.setTitle(title);
|
||||
frameIndex++;
|
||||
}, 80);
|
||||
}
|
||||
|
||||
pi.on("agent_start", async (_event, ctx) => {
|
||||
startAnimation(ctx);
|
||||
});
|
||||
|
||||
pi.on("agent_end", async (_event, ctx) => {
|
||||
stopAnimation(ctx);
|
||||
});
|
||||
|
||||
pi.on("session_shutdown", async (_event, ctx) => {
|
||||
stopAnimation(ctx);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue