(msg: RenderableMessage)
| 131 | */ |
| 132 | const promptTextCache = new WeakMap<RenderableMessage, string | null>(); |
| 133 | function stickyPromptText(msg: RenderableMessage): string | null { |
| 134 | // Cache keyed on message object — messages are append-only and don't |
| 135 | // mutate, so a WeakMap hit is always valid. The walk (StickyTracker, |
| 136 | // per-scroll-tick) calls this 5-50+ times with the SAME messages every |
| 137 | // tick; the system-reminder strip allocates a fresh string on each |
| 138 | // parse. WeakMap self-GCs on compaction/clear (messages[] replaced). |
| 139 | const cached = promptTextCache.get(msg); |
| 140 | if (cached !== undefined) return cached; |
| 141 | const result = computeStickyPromptText(msg); |
| 142 | promptTextCache.set(msg, result); |
| 143 | return result; |
| 144 | } |
| 145 | function computeStickyPromptText(msg: RenderableMessage): string | null { |
| 146 | let raw: string | null = null; |
| 147 | if (msg.type === 'user') { |
no test coverage detected