mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-15 16:08:18 +00:00
The perf suite had no terminal scenario, so nothing guarded the terminal row cache (#2239) against regressions. The new terminalTui scenario streams a full-screen TUI into the terminal at 10 fps (every row rewritten, only the spinner row changed, the title updated, as agent CLIs do) while typing in an editor, through a hidden action registered only in dev and perf builds. rowsRebuiltPerTuiFrame counts row elements rebuilt per frame independently of MutationObserver batching and fails when no terminal output arrives; budget 3 (about 1.4 with the cache, the screen height without it). Co-authored-by: brunobelloni <14021404+brunobelloni@users.noreply.github.com>
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
type TuiWindow = Window & { __stopTuiRows?: () => number };
|
|
|
|
/** Runs in the page; count replacements independently of observer delivery batches. */
|
|
export function startTuiRowObserver() {
|
|
const container = document.querySelector(".xterm .xterm-rows");
|
|
if (!container?.childElementCount) throw new Error("terminal row renderer did not open");
|
|
let rebuilt = 0;
|
|
const count = (records: MutationRecord[]) => {
|
|
for (const record of records) if (record.target.parentNode === container) rebuilt++;
|
|
};
|
|
const observer = new MutationObserver(count);
|
|
observer.observe(container, { childList: true, subtree: true });
|
|
(window as TuiWindow).__stopTuiRows = () => {
|
|
count(observer.takeRecords());
|
|
observer.disconnect();
|
|
return rebuilt;
|
|
};
|
|
}
|
|
|
|
export function stopTuiRowObserver(): number {
|
|
const w = window as TuiWindow;
|
|
const stop = w.__stopTuiRows;
|
|
delete w.__stopTuiRows;
|
|
if (!stop) throw new Error("terminal row observer did not start");
|
|
const rebuilt = stop();
|
|
if (!rebuilt) throw new Error("terminal TUI did not render any rows");
|
|
return rebuilt;
|
|
}
|