9e87d432bd
Long write/edit streams made the TUI stutter or freeze for seconds at a
time (ui.loop-blocked warnings, keystrokes starving while the single JS
thread rebuilt previews). Two compounding quadratic paths:
1. parseStreamingJsonThrottled re-parsed the entire accumulated args
buffer on a FIXED 256-byte cadence. The comment claimed this bounded
mid-stream work to O(N), but a constant growth gate still parses an
N-byte buffer N/256 times at O(N) each: O(N^2) with a smaller
constant. The gate now scales geometrically (max(256, len/32)), so
parse points form a geometric progression: O(log N) parses, O(N log N)
total, with mid-stream snapshots staying within ~3% of the stream.
Small buffers keep the exact fixed cadence as before.
2. write.ts formatStreamingContent normalized + split('\n') the WHOLE
accumulated content on every 30Hz reveal tick (renderCall also ran a
full-payload normalize first): O(N) per tick, O(N^2) per stream, per
concurrent writer. The collapsed tail-window path now tracks the
newline count incrementally (append-only resume keyed on the
component's persistent render-state object via WeakMap) and extracts
only the tail window with a backward scan: O(delta + preview lines)
per tick, byte-identical output to the split-based reference. The
expanded (Ctrl+O) path is unchanged in output and skips its
split+join round-trip.
Tests: geometric-gate bounds + freshness + small-buffer cadence in
parse-streaming-json-throttled.test.ts; append-growth/reference-
window/CRLF/trailing-newline/restart battery in
write-streaming-incremental.test.ts. Full write/tool-render battery
(56 tests) and ai streaming-args tests (117 tests) pass.
@oh-my-pi/pi-utils
Shared utilities for oh-my-pi packages. Zero ceremony, Bun-first.
Notable modules
| Module | Purpose |
|---|---|
logger |
Centralized logger writing to ~/.omp/logs/ with rotation (TUI-safe — never stdout) |
prompt |
Handlebars-based prompt templating and formatting helpers |
dirs |
Path helpers for omp config directories (~/.omp, XDG-aware on Linux) |
stream |
readStream / readLines helpers over ReadableStream |
ptree / procmgr |
Process trees, ChildProcess wrapper, process lifecycle management |
postmortem |
Cleanup callbacks on exit, signals, and fatal exceptions |
which |
$which() binary lookup with caching |
fetch-retry |
fetch with retry/backoff policies |
fs-error |
Errno guards (isEnoent and friends) |
env / worker-host |
Environment plumbing and side-effect-free worker-host entry contract (workerHostEntry) |
abortable / async |
AbortSignal-aware stream/promise helpers |
peek-file |
Read the first N bytes of a file with pooled buffers |
frontmatter, glob, mime, temp, format, color, snowflake, tab-spacing, path-tree, sanitize-text |
Smaller single-purpose helpers |
Import from the root barrel or per-module subpaths (@oh-my-pi/pi-utils/<module>).
Install
bun add @oh-my-pi/pi-utils
Ships TypeScript source directly (no build step); requires Bun ≥ 1.3.14.