aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-12 16:25:18 +0200
committeruser <user@clank>2026-08-12 19:34:35 +0200
commit521212c3afc3db4b7fbce736b8146608f07f5cba (patch)
treef9dd1f52e65564ab53241fe4bd7d59579df8e49d
parentchrome: indent the input behind a ❯ prompt glyph (diff)
downloadsl0ppi-521212c3afc3db4b7fbce736b8146608f07f5cba.tar.gz
sl0ppi-521212c3afc3db4b7fbce736b8146608f07f5cba.tar.xz
sl0ppi-521212c3afc3db4b7fbce736b8146608f07f5cba.zip
slop-tool-boxes: green heartbeat pulse; unfreeze top border when it fits
Two changes that both come back to "what should an in-flight box look like", plus the icon that was left out of it. PULSE: single hue, brightness only. The old pulse interpolated a 4-color synthwave ring (amber -> pink -> violet -> cyan) over 4s, which at that period reads as a slow hue *drift*, not a pulse -- you notice the color has changed, never that it is beating. Now it is one hue (green, i.e. "in progress") modulated dim <-> bright: #0d4023 to #3bff7a, via a raised cosine so there is no direction-reversal snap at the turn, then gamma ^1.7 to bias it toward the dim end. The border rests dark and spikes bright, which is what makes it read as a heartbeat. CYCLE_MS 4000 -> 800 (1.25Hz), and 800 is now the only pulse-speed knob. There is a hard floor of ~400ms documented at the constant: a brightness pulse IS a flicker, and 3-30Hz is the photosensitive-seizure band -- this repo has already shipped one seizure-grade flicker bug (NOTES.md), so the constant carries the warning rather than relying on memory. The upper bound is render cadence, not taste: the pulse never forces a repaint, it samples wall-clock time on renders that were happening anyway (~10fps while the spinner runs), so 800ms is ~8 samples per beat. Much faster and consecutive renders land on distant brightnesses -- the beat degrades into jitter. TOP BORDER: freeze only when we actually must. 0d671ce stopped the full-redraw flicker by freezing the call slot's top border for the whole time the result streams. That was broader than the bug requires. The bug is specifically "recolor a line that sits ABOVE the viewport": tui.js does `if (firstChanged < prevViewportTop) fullRender(true)`, so an off-screen recolor repaints everything, every tick. While the box still fits on screen, firstChanged lands inside the viewport and tui diffs from there down -- cheap. So canPulseTopBorder() compares callH + resultH against rows - RESERVED_ROWS and only freezes past that, which gives short tool calls their top and bottom borders beating in unison again. resultH is one frame stale (the call slot renders before the result slot). Harmless, because a box only grows: worst case is one extra full redraw on the frame it crosses the threshold, and then it is frozen. RESERVED_ROWS (14, for input box + footer + topbar) is deliberately generous in the same direction -- over-estimating freezes a box that could have animated, which nobody can see; under-estimating buys back the flicker. A frozen border now holds HOLD_PAINT, a fixed mid-beat green (pulseRGB(0.5)), instead of whatever phase the pulse happened to be at when content last changed. Same number of writes, but it looks deliberately held rather than randomly stuck. Resuming the pulse invalidates callActiveW so the frozen lines cannot be served stale. ICON: the pending ◉ takes the border's paint, so it beats with the frame instead of sitting there as a static amber dot. This is why the label is built inside build() now -- it has to be rebuilt per paint. It costs nothing extra: the icon shares the top border's line, which is already being rewritten. Also picks up the sl0peration -> turn doc-comment rename in the header, which is unified into the same hunk as the pulse comment above it.
-rw-r--r--pi-ext/slop-tool-boxes.ts129
1 files changed, 100 insertions, 29 deletions
diff --git a/pi-ext/slop-tool-boxes.ts b/pi-ext/slop-tool-boxes.ts
index 1a7d532..2fef6b4 100644
--- a/pi-ext/slop-tool-boxes.ts
+++ b/pi-ext/slop-tool-boxes.ts
@@ -2,10 +2,11 @@
* sl0p Tool Boxes
*
* Reframes the built-in tool rows (bash, read, edit, write, grep, find, ls)
- * in the same rounded-border "sl0peration" style used by the last-prompt
+ * in the same rounded-border "turn" style used by the last-prompt
* topbar widget — a labelled top border and a rounded bottom, with the body
* simply indented to sit under the box interior. While a tool executes the
- * top/bottom borders pulse; when it finalizes they solidify to the status color.
+ * top/bottom borders pulse green; when it finalizes they solidify to the status
+ * color.
*
* There are no side rails: we run the agent inside a zellij fork that draws its
* own border around the pane, so per-box verticals were redundant chrome.
@@ -90,26 +91,45 @@ function borderColorFor(status: Status): string {
// 3. Only the horizontal top/bottom borders pulse. The body lines are a
// STATIC color (gray dotted while in-flight, solid status color once
// settled), so a repaint never has to recolor body lines.
-const PULSE: Array<[number, number, number]> = [
- [0xff, 0x8a, 0x1e], // amber
- [0xff, 0x2e, 0x88], // hot pink
- [0xb0, 0x5c, 0xff], // violet
- [0x2e, 0xd6, 0xff], // cyan
-];
-const CYCLE_MS = 4000; // one full palette trip (~4s), advanced by wall-clock time
+//
+// The pulse is a single hue — green, i.e. "in progress" — modulated in
+// BRIGHTNESS only (dim green <-> bright green). An earlier version cycled a
+// 4-color synthwave palette over 4s, which read as a slow hue drift rather than
+// a pulse.
+const PULSE_DIM: [number, number, number] = [0x0d, 0x40, 0x23]; // deep green, near-idle
+const PULSE_BRIGHT: [number, number, number] = [0x3b, 0xff, 0x7a]; // hot green, peak
+
+// One full dim->bright->dim beat. This is the ONLY knob for pulse speed.
+//
+// SAFETY FLOOR: do not go below ~400ms. A brightness pulse is a flicker, and
+// 3-30Hz is the photosensitive-seizure band (this repo already shipped one
+// seizure-grade flicker bug — see NOTES.md). 800ms = 1.25Hz: fast enough to
+// read as a heartbeat, well clear of the danger band.
+//
+// UPPER practical bound comes from render cadence, not taste: the pulse never
+// forces a repaint (invariant above), it just samples wall-clock time on renders
+// that were happening anyway (~10fps while the spinner runs). At 800ms that is
+// ~8 samples per beat — smooth. Much faster and consecutive renders land on
+// distant brightnesses, so it degrades into random jitter instead of a pulse.
+const CYCLE_MS = 800;
function lerp(a: number, b: number, t: number): number {
return Math.round(a + (b - a) * t);
}
+
+// phase in [0,1) -> green at that point in the beat.
+// Raised cosine for a smooth ramp with no direction-reversal snap, then gamma
+// (^1.7) to bias it toward the dim end: the border rests dark and spikes bright,
+// which reads as a *pulse* rather than a sine-wave fade.
function pulseRGB(phase: number): [number, number, number] {
- const n = PULSE.length;
- const x = ((((phase % 1) + 1) % 1) * n);
- const i = Math.floor(x) % n;
- const j = (i + 1) % n;
- const t = x - Math.floor(x);
- const a = PULSE[i];
- const b = PULSE[j];
- return [lerp(a[0], b[0], t), lerp(a[1], b[1], t), lerp(a[2], b[2], t)];
+ const p = (((phase % 1) + 1) % 1);
+ const wave = (1 - Math.cos(2 * Math.PI * p)) / 2; // 0 -> 1 -> 0
+ const t = Math.pow(wave, 1.7);
+ return [
+ lerp(PULSE_DIM[0], PULSE_BRIGHT[0], t),
+ lerp(PULSE_DIM[1], PULSE_BRIGHT[1], t),
+ lerp(PULSE_DIM[2], PULSE_BRIGHT[2], t),
+ ];
}
function fgRGB(rgb: [number, number, number], s: string): string {
return `\x1b[38;2;${rgb[0]};${rgb[1]};${rgb[2]}m${s}\x1b[39m`;
@@ -150,6 +170,40 @@ function pulsePaint(): Paint {
const rgb = pulseRGB((Date.now() % CYCLE_MS) / CYCLE_MS);
return (s: string) => fgRGB(rgb, s);
}
+
+// Deterministic "held" green for a top border we are not allowed to animate
+// (box taller than the viewport — see canPulseTopBorder). Picking a fixed
+// mid-beat color instead of "whatever the pulse happened to be when content last
+// changed" makes the frozen border look intentional rather than randomly stuck.
+const HOLD_PAINT: Paint = ((rgb: [number, number, number]) => (s: string) => fgRGB(rgb, s))(
+ pulseRGB(0.5),
+);
+
+// Rows of terminal chrome that are never transcript: the input box, footer,
+// status line and the last-prompt topbar widget. Deliberately generous —
+// over-estimating just means we freeze a box we could have animated (harmless),
+// while under-estimating risks the full-screen redraw we are avoiding.
+const RESERVED_ROWS = 14;
+
+// May the CALL slot animate its top border?
+//
+// The flicker-#4 bug is specifically "recolor a line that sits ABOVE the
+// viewport": tui.js does `if (firstChanged < prevViewportTop) fullRender(true)`,
+// so an off-screen top border repaints the entire screen on every render tick.
+// That only happens once the box is taller than the screen. While the whole box
+// still fits, firstChanged lands inside the viewport and tui diffs from there
+// down — cheap for a small box, and it means short tool calls get a top border
+// that pulses in unison with the bottom one.
+//
+// `resultH` is one frame stale (the call slot renders before the result slot).
+// That is fine: the box only grows, so the worst case is a single extra full
+// redraw on the frame it crosses the threshold, then it freezes.
+function canPulseTopBorder(st: FrameState, callH: number): boolean {
+ const rows = process.stdout.rows;
+ if (!rows) return false; // unknown viewport -> assume the worst, freeze
+ const boxH = callH + (st.resultH ?? 0);
+ return boxH <= rows - RESERVED_ROWS;
+}
function solidPaint(theme: Theme, color: string): Paint {
return (s: string) => theme.fg(color, s);
}
@@ -166,9 +220,12 @@ function stopAllAnim(): void {
activeIds.clear();
}
-function statusIcon(status: Status, theme: Theme): string {
+// `paint` overrides the pending color so the in-flight ◉ beats in sync with the
+// green borders instead of sitting there as a static amber dot. It lives on the
+// same line as the top border, so painting it costs no extra repaint.
+function statusIcon(status: Status, theme: Theme, paint?: Paint): string {
if (status === "error") return theme.fg("error", "✗");
- if (status === "pending") return theme.fg("warning", "◉");
+ if (status === "pending") return (paint ?? ((s: string) => theme.fg("warning", s)))("◉");
return theme.fg("success", "✓");
}
@@ -432,6 +489,9 @@ type FrameState = {
callActiveW?: number;
callActiveInner?: string[];
callActiveLines?: string[];
+ // Height of the result slot as of its last render, so the call slot can tell
+ // whether the whole box still fits on screen (see canPulseTopBorder).
+ resultH?: number;
resultRef?: any;
resultExpanded?: boolean;
resultW: number;
@@ -541,9 +601,6 @@ function registerFramedTool(pi: ExtensionAPI, def: ToolDef) {
render(width: number): string[] {
const activeNow = isActiveRow(st);
const status: Status = activeNow ? "pending" : st.status;
- const base =
- statusIcon(status, theme) + " " + theme.fg("toolTitle", theme.bold(displayName));
- const label = st.summaryText ? base + " " + theme.fg("accent", st.summaryText) : base;
const inner = innerLines(width);
// IMPORTANT (anti-flicker): body lines carry NO border color; only the
// horizontal top/bottom borders pulse. Anything that recolors every body
@@ -553,6 +610,12 @@ function registerFramedTool(pi: ExtensionAPI, def: ToolDef) {
// 1-2 border lines. (NOTES.md)
const rt = RUNTIME_TOOLS.has(displayName) ? runtimeLabel(st, theme) : undefined;
const build = (border: Paint): string[] => {
+ // Label is rebuilt per paint so the pending ◉ pulses with the border.
+ const base =
+ statusIcon(status, theme, activeNow ? border : undefined) +
+ " " +
+ theme.fg("toolTitle", theme.bold(displayName));
+ const label = st.summaryText ? base + " " + theme.fg("accent", st.summaryText) : base;
const out = [frameTop(width, label, border), ...frameBody(inner, width, TOOL_BG[displayName])];
// While the result slot hasn't started rendering yet (still-running
// tool), close the box here so the frame is never bottomless.
@@ -564,16 +627,23 @@ function registerFramedTool(pi: ExtensionAPI, def: ToolDef) {
// Pre-output (no result slot yet): the whole box is short + visible,
// so keep the live pulse (and ticking runtime in the bottom border).
if (!st.resultActive) return build(pulsePaint());
- // Result is streaming below — this slot owns the TOP border, which may
- // be scrolled off-screen. Freeze the pulse color while our content +
- // width are unchanged so the top border is byte-identical between the
- // spinner's render ticks; otherwise every tick recolors an off-screen
- // line and tui.js escalates to a full-screen redraw (violent flicker
- // on tall, top-clipped tool boxes). See NOTES.md.
+ // Result is streaming below and this slot owns the TOP border. If the
+ // whole box still fits on screen, that border is in-viewport and safe
+ // to animate, so top and bottom beat together.
+ if (canPulseTopBorder(st, 1 + inner.length)) {
+ st.callActiveW = -1; // frozen lines are stale once we resume pulsing
+ return build(pulsePaint());
+ }
+ // Box is taller than the screen: the top border is (or is about to
+ // be) scrolled ABOVE the viewport. Freeze it at a fixed green while
+ // content + width are unchanged, so it stays byte-identical between
+ // the spinner's render ticks; otherwise every tick recolors an
+ // off-screen line and tui.js escalates to a full-screen redraw
+ // (violent flicker on tall, top-clipped tool boxes). See NOTES.md.
if (width !== st.callActiveW || inner !== st.callActiveInner) {
st.callActiveW = width;
st.callActiveInner = inner;
- st.callActiveLines = build(pulsePaint());
+ st.callActiveLines = build(HOLD_PAINT);
}
return st.callActiveLines!;
}
@@ -651,6 +721,7 @@ function registerFramedTool(pi: ExtensionAPI, def: ToolDef) {
...frameBody(inner, width, TOOL_BG[displayName]),
frameBottom(width, border, rt),
];
+ st.resultH = inner.length + 1; // body + bottom border, for canPulseTopBorder
if (activeNow) {
cw = -1;
return build(pulsePaint());