Each accessibility C API call (ax_bounds, ax_offset, ax_cursor_offset)
previously rebuilt the entire StringMap independently — O(total_bytes)
allocation and work per call. VoiceOver fires multiple queries per
interaction, so this was wasteful.
Introduce AccessibilityContext: a pre-computed, self-contained snapshot
built once per cache window (~500ms). It contains the terminal text,
viewport byte range, cursor offset, per-byte viewport cell info, and a
grid-to-offset lookup table. All data is owned (no raw Pin pointers),
so it is safe to cache in Swift without holding the terminal mutex.
The C API now exposes context lifecycle functions
(ghostty_surface_ax_context_new/free) and query functions that accept
the context handle. The Swift layer wraps the context pointer in an
AXContextHandle class so ARC frees it when the CachedValue expires.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>