Add CustomMessageEntry rendering infrastructure

- Add renderCustomMessage to HookAPI for registering custom renderers
- Add CustomMessageRenderer type and CustomMessageRenderOptions
- Store customMessageRenderers in LoadedHook
- Add getCustomMessageRenderer(customType) to HookRunner
- SessionContext.entries now aligned with messages (same length, corresponding indices)

TUI can now correlate messages with their source entries to identify
custom_message entries and use hook-provided renderers.
This commit is contained in:
Mario Zechner 2025-12-26 23:02:53 +01:00
parent 3ecaaa5937
commit 11a7845ceb
7 changed files with 83 additions and 10 deletions

View file

@ -5,6 +5,7 @@
import { spawn } from "node:child_process";
import type { LoadedHook, SendHandler } from "./loader.js";
import type {
CustomMessageRenderer,
ExecOptions,
ExecResult,
HookError,
@ -203,6 +204,20 @@ export class HookRunner {
return false;
}
/**
* Get a custom message renderer for the given customType.
* Returns the first renderer found across all hooks, or undefined if none.
*/
getCustomMessageRenderer(customType: string): CustomMessageRenderer | undefined {
for (const hook of this.hooks) {
const renderer = hook.customMessageRenderers.get(customType);
if (renderer) {
return renderer;
}
}
return undefined;
}
/**
* Create the event context for handlers.
*/