Open-source SEO, GEO, and marketing skills for AI agents.
feat(chat): Claude-Code-style "Beaming…" loading indicator
Yuting Zhonga7954fa04225
diff --git a/src/components/beaming-indicator.test.tsx b/src/components/beaming-indicator.test.tsxnew file mode 100644index 00000000..24f0fd33--- /dev/null+++ b/src/components/beaming-indicator.test.tsx@@ -0,0 +1,51 @@+// @vitest-environment jsdom+import { afterEach, describe, expect, it, vi } from "vitest";+import { render, screen, act } from "@testing-library/react";++import { BeamingGlyph, BeamingHeadline } from "./beaming-indicator";++afterEach(() => {+ vi.useRealTimers();+});++describe("BeamingHeadline", () => {+ it("renders a verb and the prefix", () => {+ render(<BeamingHeadline prefix="CMO" />);+ // Status node carries the verb in aria-label so the test doesn't+ // depend on which random verb mounted.+ const node = screen.getByRole("status");+ expect(node).toBeInTheDocument();+ expect(node.getAttribute("aria-label")).toMatch(/\w+…/);+ // Prefix rendered too.+ expect(node.textContent ?? "").toMatch(/CMO/);+ });++ it("rotates the verb on a timer", () => {+ vi.useFakeTimers();+ render(<BeamingHeadline prefix="CMO" />);+ const node = screen.getByRole("status");+ const first = node.getAttribute("aria-label");+ // Advance past the verb interval (2.5s) plus margin.+ act(() => {+ vi.advanceTimersByTime(3_000);+ });+ const second = node.getAttribute("aria-label");+ // Random cycle picks a different verb each tick, so labels must differ.+ expect(second).not.toBe(first);+ });+});++describe("BeamingGlyph", () => {+ it("renders a glyph by default", () => {+ const { container } = render(<BeamingGlyph />);+ // The glyph is inside the only span we render.+ const span = container.querySelector("span[aria-hidden]");+ expect(span).not.toBeNull();+ expect((span?.textContent ?? "").length).toBeGreaterThan(0);+ });++ it("honors an explicit glyph prop", () => {+ const { container } = render(<BeamingGlyph glyph="✶" />);+ expect(container.textContent).toBe("✶");+ });+});diff --git a/src/components/beaming-indicator.tsx b/src/components/beaming-indicator.tsxnew file mode 100644index 00000000..0acc5483--- /dev/null+++ b/src/components/beaming-indicator.tsx@@ -0,0 +1,148 @@+"use client";++import { useEffect, useState } from "react";+import { cn } from "@/lib/utils";++/**+ * Active "agent is working" indicator. Mimics the Claude Code CLI's+ * "✳ Beaming…" / "✳ Pondering…" pattern: an asterisk glyph that+ * morphs every ~120 ms paired with a quirky verb that swaps every+ * ~2.5 s. The point is to make the chat view obviously alive during+ * the 10–20s pre-first-token wait — a single small pulsing dot is+ * easy to miss and reads as "stuck".+ *+ * Pure visual. The verb cycles independently of any backend signal —+ * lifecycle/tool info, when available, is shown by the parent in a+ * separate row (we don't try to claim the model is "Pondering" while+ * it's actually executing a tool call). Use this only in the "we+ * don't have a better label" branch of WorkingStatus.+ */++// Quirky verbs lifted in spirit from Claude Code. Kept short so they+// don't reflow the headline as they swap. New entries should also be+// gerunds ("-ing") so the trailing "…" reads naturally.+const VERBS = [+ "Beaming",+ "Brewing",+ "Cogitating",+ "Computing",+ "Conjuring",+ "Crunching",+ "Deliberating",+ "Distilling",+ "Effervescing",+ "Elaborating",+ "Mulling",+ "Musing",+ "Percolating",+ "Pondering",+ "Processing",+ "Ruminating",+ "Simmering",+ "Spinning",+ "Sublimating",+ "Synthesizing",+ "Thinking",+ "Tinkering",+ "Whirring",+] as const;++// Glyph sequence the leading "✳" morphs through. Bright/sparse to dense/full+// and back so the eye reads it as one pulsing thing rather than a flicker.+const GLYPHS = ["✳", "✺", "✷", "✸", "✹", "✷", "✺"] as const;++const GLYPH_INTERVAL_MS = 130;+const VERB_INTERVAL_MS = 2_500;++function useTickingIndex(intervalMs: number, length: number): number {+ const [idx, setIdx] = useState(0);+ useEffect(() => {+ if (length <= 1) return;+ const id = setInterval(() => {+ setIdx((i) => (i + 1) % length);+ }, intervalMs);+ return () => clearInterval(id);+ }, [intervalMs, length]);+ return idx;+}++function useRandomCycle(intervalMs: number, length: number): number {+ // Random pick each tick (skip same-as-current so it always moves) so+ // the user doesn't see the same fixed sequence and decide it's a loop.+ const [idx, setIdx] = useState(() => Math.floor(Math.random() * length));+ useEffect(() => {+ if (length <= 1) return;+ const id = setInterval(() => {+ setIdx((current) => {+ if (length <= 1) return current;+ let next = Math.floor(Math.random() * length);+ if (next === current) next = (next + 1) % length;+ return next;+ });+ }, intervalMs);+ return () => clearInterval(id);+ }, [intervalMs, length]);+ return idx;+}++export function BeamingHeadline({+ className,+ prefix,+}: {+ className?: string;+ /** Optional agent name prefix, rendered before the verb (e.g. "CMO ·"). */+ prefix?: string | null;+}) {+ const glyphIdx = useTickingIndex(GLYPH_INTERVAL_MS, GLYPHS.length);+ const verbIdx = useRandomCycle(VERB_INTERVAL_MS, VERBS.length);+ const glyph = GLYPHS[glyphIdx]!;+ const verb = VERBS[verbIdx]!;+ return (+ <span+ role="status"+ aria-label={`${verb}…`}+ className={cn("inline-flex items-baseline gap-1.5", className)}+ >+ <BeamingGlyph glyph={glyph} />+ <span className="italic text-muted-foreground">+ {prefix ? `${prefix} ` : ""}+ {verb}+ <AnimatedDots />+ </span>+ </span>+ );+}++/** Just the morphing glyph, for places that already render their own text. */+export function BeamingGlyph({+ className,+ glyph,+}: {+ className?: string;+ glyph?: string;+}) {+ const idx = useTickingIndex(GLYPH_INTERVAL_MS, GLYPHS.length);+ const ch = glyph ?? GLYPHS[idx]!;+ return (+ <span+ aria-hidden+ className={cn(+ "inline-block text-sky-500 motion-safe:transition-opacity",+ className,+ )}+ >+ {ch}+ </span>+ );+}++/** Trailing "…" that grows from "." to "..." over time. */+function AnimatedDots() {+ const idx = useTickingIndex(450, 4); // 0=" ", 1=".", 2="..", 3="..."+ const dots = idx === 0 ? "" : ".".repeat(idx);+ return (+ <span aria-hidden className="inline-block w-3 text-left">+ {dots}+ </span>+ );+}diff --git a/src/components/live-transcript.test.tsx b/src/components/live-transcript.test.tsxindex 8cb8a206..45c168f0 100644--- a/src/components/live-transcript.test.tsx+++ b/src/components/live-transcript.test.tsx@@ -96,8 +96,10 @@ describe("LiveTranscript empty state", () => {expect(screen.queryByText(/no messages yet/i),).not.toBeInTheDocument();- // WorkingStatus pulse is shown via the role="status" RunningDot.- expect(screen.getByText(/Starting CMO/i)).toBeInTheDocument();+ // WorkingStatus shows BeamingHeadline in "beam" mode (no specific+ // tool/lifecycle info yet). The agent prefix is rendered alongside+ // a cycling verb; assert on the prefix since the verb rotates.+ expect(screen.getByText(/CMO/)).toBeInTheDocument();});});diff --git a/src/components/live-transcript.tsx b/src/components/live-transcript.tsxindex b8e08708..58ef5353 100644--- a/src/components/live-transcript.tsx+++ b/src/components/live-transcript.tsx@@ -28,6 +28,7 @@ import { toast } from "sonner";import { Button } from "@/components/ui/button";import { Markdown } from "@/components/markdown";import { RunningDot } from "@/components/running-dot";+import { BeamingGlyph, BeamingHeadline } from "@/components/beaming-indicator";import { SlashCommandPopover } from "@/components/slash-command-popover";import { cn } from "@/lib/utils";import {@@ -1095,31 +1096,44 @@ function WorkingStatus({0,);- let headline = `${agentDisplayName} is thinking…`;+ // Two display modes:+ // - `beam`: cycle through "Pondering… / Cogitating… / Beaming…" verbs+ // with a morphing ✳ glyph. Used whenever we have nothing more+ // specific to say (pre-first-token wait, between tool calls). This+ // keeps the chat visibly alive during the 10-20s Codex pause that+ // used to read as "stuck".+ // - `static`: render a fixed headline + subtitle (specific tool in+ // flight, last tool result, wrapping up assistant text). The+ // specific info is more useful than a quirky verb, so we keep it.+ //+ // The leading glyph is morphing in both modes so the eye always has+ // something animating.+ let mode: "beam" | "static" = "beam";+ let headline: string = `${agentDisplayName} is thinking…`;let subtitle: string | null = null;+ let beamPrefix: string | null = agentDisplayName;if (!lastEvent || lastEvent.kind === "user_message" || lastEvent.kind === "unknown") {- // Pre-first-event window. For a kickoff this can be 10-20s while- // Codex chews through the system prompt. Use the gateway lifecycle- // hint if we got one — it tells us OpenClaw is alive and which phase- // it's in — otherwise fall back to a generic "starting" message.+ // Pre-first-event window — typical kickoff wait. Use the gateway+ // lifecycle hint as the subtitle so power users see "calling the+ // model…" but the headline still gets the Beaming treatment.+ mode = "beam";+ beamPrefix = agentDisplayName;const lifecycleSummary = lifecyclePhase? humanLifecyclePhase(lifecyclePhase): null;- headline = lifecycleSummary- ? `${agentDisplayName} · ${lifecycleSummary}`- : `Starting ${agentDisplayName}…`;- subtitle = lifecycleSummary- ? "Waiting on the model's first token."- : "Delivering the brief to OpenClaw.";+ subtitle = lifecycleSummary ?? "Delivering the brief to OpenClaw.";} else if (inFlightToolCall) {+ mode = "static";headline = `Calling ${formatToolName(inFlightToolCall.name)}…`;subtitle = inFlightToolCall.label ?? null;} else if (lastEvent.kind === "tool_result") {- headline = `${agentDisplayName} is thinking…`;+ mode = "beam";+ beamPrefix = agentDisplayName;subtitle = lastEvent.ok? `Last step · ${formatToolName(lastEvent.name)} ✓`: `Last step · ${formatToolName(lastEvent.name)} failed — retrying`;} else if (lastEvent.kind === "assistant_text") {+ mode = "static";headline = `${agentDisplayName} is wrapping up…`;}@@ -1132,10 +1146,16 @@ function WorkingStatus({return (<div className="flex items-start gap-2.5 rounded-md border border-dashed border-muted-foreground/25 bg-muted/10 px-3 py-2 text-xs">- <RunningDot size="sm" aria-label="" />+ <span className="mt-0.5">+ <BeamingGlyph />+ </span><div className="min-w-0 flex-1 space-y-0.5"><div className="flex items-baseline gap-2">- <span className="italic text-muted-foreground">{headline}</span>+ {mode === "beam" ? (+ <BeamingHeadline prefix={beamPrefix} />+ ) : (+ <span className="italic text-muted-foreground">{headline}</span>+ )}{elapsedMs != null && (<span className="tabular-nums text-[10px] text-muted-foreground/70">{formatElapsed(elapsedMs)}