/** * Continuous assistant response text tracking via event hook. * * Listens for `message.updated` and `message.part.updated` events from * the OpenCode `event` hook to build a live cache of the latest assistant * response text per session. Eliminates the need to poll `getSessionMessages()` * in `handleSessionIdle()` for last-message fallback. * * The cache is bounded to 5 entries (FIFO eviction) to prevent unbounded * memory growth over long plugin lifetimes. * * @module session-tracker/capture/last-message-capture */ /** * Continuously tracks the latest assistant response text from * `message.updated` / `message.part.updated` events. * * Maintains a bounded FIFO cache keyed by `messageID` with at most * 5 entries. Provides lookup by sessionID for `handleSessionIdle()`. * * The optional `onLastMessageUpdate` callback allows wiring to * `SessionWriter.updateFrontmatter()` for continuous `.md` frontmatter * updates as text streams in. */ export declare class LastMessageCapture { /** Bounded cache: messageID → { sessionID, lastText }. */ private messages; /** FIFO insertion order tracking for bounded eviction. */ private insertionOrder; /** Maximum number of message entries before FIFO eviction. */ private readonly maxEntries; /** Optional callback invoked when a non-empty text update arrives. */ private readonly onLastMessageUpdate?; /** * @param deps - Optional dependencies. * @param deps.onLastMessageUpdate - Callback invoked when a non-empty * assistant text part is captured. Receives the sessionID and the * full text. Useful for wiring to `SessionWriter.updateFrontmatter()`. */ constructor(deps?: { onLastMessageUpdate?: (sessionID: string, text: string) => void; }); /** * Handles an event from the OpenCode `event` hook pipeline. * * Processes: * - `message.updated` — registers a new message entry when the role is * `"assistant"`, using `event.properties.info.id` as the key. * - `message.part.updated` — updates the tracked `lastText` for an * existing message when the part type is `"text"`. Invokes the * `onLastMessageUpdate` callback when the accumulated text is non-empty. * * All other event types are silently ignored. * * @param event - Raw event payload from the OpenCode event hook. */ handleEvent(event: Record): void; /** * Processes a `message.updated` event. * * Extracts the role, messageID, and sessionID from the event properties. * If the role is `"assistant"`, registers the messageID in the bounded * cache with an empty `lastText` (accumulated later via part updates). * * @param event - The raw event payload. */ private handleMessageUpdated; /** * Processes a `message.part.updated` event. * * Extracts the `messageID` and part data from the event. If the part * type is `"text"` and the messageID is already tracked in the cache, * appends the new text to the existing `lastText`. Invokes the * `onLastMessageUpdate` callback when the accumulated text is non-empty. * * @param event - The raw event payload. */ private handleMessagePartUpdated; /** * Retrieves the latest tracked assistant text for a given session. * * Iterates through tracked entries in insertion order (most recent last) * and returns the first matching non-empty combined text (including formatted thinking). * Returns `undefined` if no assistant text has been tracked for this session. * * @param sessionID - The session identifier to look up. * @returns The latest assistant text, or `undefined` if not found. */ getLastMessage(sessionID: string): string | undefined; /** * Removes all tracked message entries for a given session. * * Called when a session terminates (session.deleted, session.error) to * free cache space and prevent stale text from being returned for * recycled session IDs. * * @param sessionID - The session identifier to clear. */ clearSession(sessionID: string): void; } //# sourceMappingURL=last-message-capture.d.ts.map