Heuristic:AI QL Tuui UUID Text Cache
| Knowledge Sources | |
|---|---|
| Domains | Command_Picker, IPC, Caching |
| Last Updated | 2026-10-24 20:38 GMT |
Overview
Bridge selected text between the text-grab phase and the chat injection phase using a UUID-keyed in-memory cache, since IPC messages cannot carry large text payloads directly.
Description
The command picker flow spans two windows: the global shortcut grabs text in the source application, then a popup window opens for template selection, and finally the main window receives the text for chat. Text cannot be passed through a single IPC call chain because the popup window and main window are separate BrowserWindow instances with separate IPC interactions. The UUID text cache pattern stores the grabbed text in a module-level strDict keyed by a UUID, returns the UUID to the caller, and the UUID is later used to retrieve and delete the cached text. The cache is single-entry: each putCachedText clears all previous entries.
Usage
Apply this heuristic when you need to pass data between separate windows or IPC calls without serializing it through every message. The symptom is needing to carry a text payload through multiple IPC hops where intermediate handlers don't need the content.
The Insight (Rule of Thumb)
- Action: Store text in a module-level dict keyed by
uuidv4(); pass the UUID through IPC; retrieve and delete on consumption. - Value:
putCachedText(text)returns UUID;getCachedText(id)returns text and deletes the entry. - Trade-off: Single-entry cache: each put clears all previous entries. Text is lost if the consuming window crashes before retrieval.
- Lifetime: Cache entry lives until consumed (read-then-delete) or overwritten by next put.
Reasoning
Passing text through multiple IPC hops (grab → popup → main window) requires the text to be serialized in each IPC message. For large selections, this is wasteful and error-prone. The UUID cache decouples the text payload from the IPC control flow: only the UUID (36 characters) is sent through messages. The single-entry design is intentional — there is only one active command-picker flow at a time, so multiple cached texts would be a bug. The read-then-delete semantics ensure no stale text persists.
Code Evidence
UUID text cache from `src/main/aid/utils.ts:1-21`:
import { v4 as uuidv4 } from 'uuid'
const textCache: strDict = {}
export const getCachedText = (id: string): string => {
const prompt = textCache[id]
delete textCache[id] // read-then-delete
return prompt
}
export const putCachedText = (text: string): string => {
Object.keys(textCache).forEach((key) => {
delete textCache[key] // clear all previous entries
})
const id = uuidv4()
textCache[id] = text
return id
}
Usage in Commander from `src/main/aid/commander.ts:51-53`:
const textId = putCachedText(text) // cache text, get UUID
const sourceApp = await automator.getForemostApp()
window.openCommandPicker({ textId, sourceApp, startTime })
Retrieval in IPC handler from `src/main/IPCs.ts:230-234`:
const prompt = response.prompt
const request = { prompt, input: getCachedText(response.id) }
commandSelectionInvoke(request)