mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-20 06:04:15 +00:00
docs(coding-agent): improve extensions.md, add missing examples
- Add cross-links to session.md, keybindings.md, themes.md - Document truncateLine, highlightCode, getLanguageFromPath utilities - Add examples for previously undocumented APIs: - message-renderer.ts: registerMessageRenderer with Box styling - session-name.ts: setSessionName/getSessionName - event-bus.ts: pi.events for inter-extension communication - bookmark.ts: setLabel for entry bookmarking - Update examples table in extensions.md and README.md
This commit is contained in:
parent
c565fa9af8
commit
930207130b
6 changed files with 285 additions and 68 deletions
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* Custom message rendering example.
|
||||
*
|
||||
* Shows how to use registerMessageRenderer to control how custom messages
|
||||
* appear in the TUI, with colors, formatting, and expandable details.
|
||||
*
|
||||
* Usage: /status [message] - sends a status message with custom rendering
|
||||
*/
|
||||
|
||||
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
||||
import { Box, Text } from "@mariozechner/pi-tui";
|
||||
|
||||
export default function (pi: ExtensionAPI) {
|
||||
// Register custom renderer for "status-update" messages
|
||||
pi.registerMessageRenderer("status-update", (message, { expanded }, theme) => {
|
||||
const details = message.details as { level: string; timestamp: number } | undefined;
|
||||
const level = details?.level ?? "info";
|
||||
|
||||
// Color based on level
|
||||
const color = level === "error" ? "error" : level === "warn" ? "warning" : "success";
|
||||
const prefix = theme.fg(color, `[${level.toUpperCase()}]`);
|
||||
|
||||
let text = `${prefix} ${message.content}`;
|
||||
|
||||
// Show timestamp when expanded
|
||||
if (expanded && details?.timestamp) {
|
||||
const time = new Date(details.timestamp).toLocaleTimeString();
|
||||
text += `\n${theme.fg("dim", ` at ${time}`)}`;
|
||||
}
|
||||
|
||||
// Use Box with customMessageBg for consistent styling
|
||||
const box = new Box(1, 1, (t) => theme.bg("customMessageBg", t));
|
||||
box.addChild(new Text(text, 0, 0));
|
||||
return box;
|
||||
});
|
||||
|
||||
// Command to send status messages
|
||||
pi.registerCommand("status", {
|
||||
description: "Send a status message (usage: /status [warn|error] message)",
|
||||
handler: async (args, _ctx) => {
|
||||
const parts = args.trim().split(/\s+/);
|
||||
let level = "info";
|
||||
let content = args.trim();
|
||||
|
||||
// Check for level prefix
|
||||
if (parts[0] === "warn" || parts[0] === "error") {
|
||||
level = parts[0];
|
||||
content = parts.slice(1).join(" ") || "Status update";
|
||||
}
|
||||
|
||||
pi.sendMessage({
|
||||
customType: "status-update",
|
||||
content,
|
||||
display: true,
|
||||
details: { level, timestamp: Date.now() },
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue