oficina / base Public

Wordless thinking dots; show Equipo's glance and hold it 1.5 s

The thinking bubble no longer says "Thinking…": until Equipo says
anything it shows three soft dots shimmering through teal, violet and
rose (still with reduced motion, one of each), named "Thinking…" for
assistive tech. Scripts off, the status line is unchanged.

Equipo's live-only glance event (no id, cursor 0) replaces the dots or
activity line with a fade, and later activity lines leave it be. A reply
arriving before the glance has shown 1.5 s waits, then crossfades in
place; a glance after the first delta is ignored. Nothing keeps it.

The relay passes a glance only for the person's turn in flight before
its first words (not team_update, ended or other turns), cleaned to one
plain line of at most 60 characters, and writes it without an id so the
browser's cursor is untouched. The fake emits glances live only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 0fb51cd05a61d0ff2d518d04be5f12899244deb2 parent 40db0b8
8 files changed, +570 −49
  • internal/browsertest/ask_test.go +1 −1
  • internal/browsertest/thinking_test.go +164 −4
  • internal/equipo/equipo_test.go +73 −0
  • internal/equipo/equipotest/chat.go +39 −11
  • internal/look/static/app.css +15 −0
  • internal/look/static/ask.js +88 −23
  • internal/web/ask_relay.go +119 −10
  • internal/web/relay_internal_test.go +71 −0
diff --git a/internal/browsertest/ask_test.go b/internal/browsertest/ask_test.go
index f608b39..3a7d816 100644
--- a/internal/browsertest/ask_test.go
+++ b/internal/browsertest/ask_test.go
@@ -518,7 +518,7 @@ func TestAskComposerSendAndStop(t *testing.T) {
const st = document.querySelector("#ask-panel .ask-status");
if (st.textContent !== "") p.push("status " + st.textContent);
const bubble = document.querySelector("#ask-panel .thread > li:last-child.thinking");
- if (!bubble || bubble.textContent !== "Thinking…") p.push("bubble " + (bubble && bubble.textContent));
+ if (!bubble || bubble.textContent !== "" || bubble.querySelectorAll(".dots > i").length !== 3) p.push("bubble " + (bubble && bubble.innerHTML));
return p.join("; ");
})()`); got != "" {
t.Errorf("while answering: %s", got)
diff --git a/internal/browsertest/thinking_test.go b/internal/browsertest/thinking_test.go
index 0d520ed..d47ea0e 100644
--- a/internal/browsertest/thinking_test.go
+++ b/internal/browsertest/thinking_test.go
@@ -68,7 +68,8 @@ const statusJS = `(() => { const s = document.querySelector("#ask-panel .ask-sta
return JSON.stringify(s.textContent) + (s.getBoundingClientRect().height > 0 ? " shown" : " empty"); })()`
// While the Assistant answers, its thinking bubble sits at the end of the
-// conversation carrying what it is doing, and the status line above the
+// conversation: three soft dots shimmering through Base's palette, no
+// words, until Equipo says what it is doing; the status line above the
// field stays empty; a spark runs round the bubble's edge on a WebGL
// canvas made for it. The bubble becomes the reply in place, streamed or
// not; Stop and a failure take it away; a team_update turn shows none;
@@ -85,7 +86,16 @@ func TestAskThinkingBubble(t *testing.T) {
if got := th.eval(`(() => { const b = document.querySelector(` + strconv.Quote(thinkingSel) + `), list = b.parentElement, p = [];
if (list.lastElementChild !== b) p.push("not at the end of the conversation");
if (document.querySelectorAll("#ask-panel .thinking").length !== 1) p.push(document.querySelectorAll("#ask-panel .thinking").length + " bubbles");
- if (b.textContent !== "Thinking…") p.push("says " + JSON.stringify(b.textContent));
+ if (b.textContent !== "") p.push("says " + JSON.stringify(b.textContent));
+ const d = b.querySelectorAll(":scope > .think-line > .dots > i");
+ if (d.length !== 3) p.push(d.length + " dots");
+ if (b.querySelector(".dots")?.getAttribute("aria-label") !== "Thinking…") p.push("the dots are not named for assistive tech");
+ for (const i of d) {
+ const s = getComputedStyle(i);
+ if (s.animationName !== "think-dot, think-hue") p.push("a dot is still: " + s.animationName);
+ if (i.getBoundingClientRect().width < 4) p.push("a dot is " + i.getBoundingClientRect().width + "px");
+ }
+ if (d.length === 3 && getComputedStyle(d[0]).animationDelay === getComputedStyle(d[2]).animationDelay) p.push("the dots move together");
if (b.getBoundingClientRect().left - list.getBoundingClientRect().left > 20) p.push("not on the Assistant's side");
if (b.classList.contains("no-gl")) p.push("fell back to the CSS sweep");
const c = b.querySelector("canvas");
@@ -164,7 +174,7 @@ func TestAskThinkingBubble(t *testing.T) {
}
drive(t, rig, scriptsDisabled(false))
openPanel(t, rig)
- th.wait(`document.querySelector(` + strconv.Quote(thinkingSel) + `)?.textContent === "Thinking…"`)
+ th.wait(`(() => { const b = document.querySelector(` + strconv.Quote(thinkingSel) + `); return b && b.textContent === "" && b.querySelectorAll(".dots > i").length === 3; })()`)
// Stop takes the bubble away, and its spark with it.
drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel form.composer button.stop`)))
@@ -227,7 +237,8 @@ func TestAskThinkingBubble(t *testing.T) {
}
}
-// With reduced motion the bubble glows, still: no spark, no frames. Without
+// With reduced motion the bubble glows, still, and its dots hold still in
+// teal, violet and rose: no spark, no frames. Without
// WebGL, or when its context is lost, a CSS sweep runs round the edge
// instead.
func TestAskThinkingStillAndFallback(t *testing.T) {
@@ -244,6 +255,14 @@ func TestAskThinkingStillAndFallback(t *testing.T) {
if (window.__raf) p.push(window.__raf + " frames");
if (s.animationName !== "none") p.push("the edge moves: " + s.animationName);
if (!(Number(s.opacity) > 0)) p.push("no glow on the edge");
+ const d = [...b.querySelectorAll(".dots > i")];
+ if (d.length !== 3) p.push(d.length + " dots");
+ for (const i of d) {
+ const c = getComputedStyle(i);
+ if (c.animationName !== "none" || i.getAnimations().length) p.push("a dot moves: " + c.animationName);
+ if (!(Number(c.opacity) > 0.3)) p.push("a dot is faint: " + c.opacity);
+ }
+ if (d.length === 3 && getComputedStyle(d[0]).backgroundColor === getComputedStyle(d[2]).backgroundColor) p.push("the still dots are one colour");
return p.join("; "); })()`); got != "" {
t.Errorf("reduced motion, thinking: %s", got)
}
@@ -361,3 +380,144 @@ func TestAskStreamCountsBytes(t *testing.T) {
t.Errorf("answered: %s Assistant lines, want 1", n)
}
}
+
+// watchJS keeps the thinking bubble in window.__b, where it is, and from
+// now on the page's times (performance.now) at which it first says g
+// (window.__g) and first says anything else after that (window.__x).
+func watchJS(g string) string {
+ return `(() => { const b = document.querySelector(` + strconv.Quote(thinkingSel) + `);
+ window.__b = b; window.__at = [...b.parentElement.children].indexOf(b); window.__r = b.getBoundingClientRect(); window.__g = 0; window.__x = 0;
+ const look = () => { const t = b.textContent, now = performance.now();
+ if (!window.__g && t === ` + strconv.Quote(g) + `) window.__g = now;
+ if (window.__g && !window.__x && t !== ` + strconv.Quote(g) + `) window.__x = now; };
+ new MutationObserver(look).observe(b, { subtree: true, childList: true, characterData: true }); })()`
+}
+
+// inPlaceJS reports how the watched bubble is not the reply text, where it
+// was.
+func inPlaceJS(text string) string {
+ return `(() => { const b = window.__b, p = [], r = b.getBoundingClientRect();
+ if (!b.isConnected || [...b.parentElement.children].indexOf(b) !== window.__at) p.push("moved from " + window.__at);
+ if (b.textContent !== ` + strconv.Quote(text) + ` || !b.dataset.id) p.push("says " + JSON.stringify(b.textContent));
+ if (Math.abs(r.left - window.__r.left) > 0.5) p.push("jumped from " + window.__r.left + " to " + r.left);
+ if (document.querySelector("#ask-panel .thinking, #ask-panel .draft")) p.push("still thinking");
+ return p.join("; "); })()`
+}
+
+// Equipo's glance, a first line on the turn in flight, takes the dots'
+// place in the bubble, fading in, and stays over Equipo's activity lines.
+// A reply that comes soon after waits until the glance has shown for 1.5
+// s, then takes its place where it is; a reply that comes later takes it
+// at once. A glance after the turn's first words, for a team_update turn,
+// or for a turn the page is not answering shows nowhere. Glances are live
+// only, as Equipo sends them: no id, and a page that comes back never sees
+// one again.
+func TestAskGlance(t *testing.T) {
+ rig, f := askBase(t)
+ openPanel(t, rig)
+ th := thinking{t, rig, f}
+ const glance = "Checking your projects"
+
+ // The glance takes the dots' place, fading in, and stays.
+ id := th.send("What's on today?")
+ drive(t, rig, chromedp.Evaluate[chromedp.Void](watchJS(glance)))
+ f.Glance(id, " "+glance+"\n")
+ th.wait(`window.__g > 0`)
+ th.wait(`(() => { const l = document.querySelector(` + strconv.Quote(thinkingSel+" .think-line") + `);
+ return l && l.getAnimations().some(a => a.playState === "running" && Number(a.effect.getKeyframes()[0].opacity) === 0); })()`)
+ if got := th.eval(`(() => { const b = window.__b, p = [];
+ if (b.querySelector(".dots")) p.push("the dots still show");
+ if (!b.matches(".thinking") || !b.querySelector("canvas")) p.push("no longer thinking, with its spark");
+ if (document.querySelectorAll("#ask-panel .thinking").length !== 1) p.push(document.querySelectorAll("#ask-panel .thinking").length + " bubbles");
+ if (document.querySelector("#ask-panel .ask-status").textContent) p.push("the status line says " + document.querySelector("#ask-panel .ask-status").textContent);
+ return p.join("; "); })()`); got != "" {
+ t.Errorf("with a glance: %s", got)
+ }
+ rig.Screen("#ask-panel", "the thinking bubble with Equipo's glance")
+ f.Emit("activity", map[string]string{"turn_id": id, "label": "Looking at what I can do…"})
+
+ // A reply 200 ms after the glance waits until it has shown 1.5 s, then
+ // takes its place.
+ g := harness.Evaluate[float64](rig, `window.__g`)
+ for harness.Evaluate[float64](rig, `performance.now()`) < g+200 {
+ time.Sleep(10 * time.Millisecond)
+ }
+ const soon = "Two meetings and a review."
+ f.Answer(id, soon, true)
+ th.wait(`window.__b.dataset.id && window.__b.textContent === ` + strconv.Quote(soon) + ` && !document.querySelector("#ask-panel .think-line")`)
+ if held := harness.Evaluate[float64](rig, `window.__x - window.__g`); held < 1450 || held > 2500 {
+ t.Errorf("a reply 200 ms after the glance replaced it after %.0f ms, want about 1500", held)
+ }
+ if got := th.eval(inPlaceJS(soon)); got != "" {
+ t.Errorf("the reply soon after a glance: %s", got)
+ }
+
+ // A reply 3 s after the glance takes its place at once.
+ id = th.send("And tomorrow?")
+ drive(t, rig, chromedp.Evaluate[chromedp.Void](watchJS(glance)))
+ f.Glance(id, glance)
+ th.wait(`window.__g > 0`)
+ f.Emit("activity", map[string]string{"turn_id": id, "label": "Looking at what I can do…"})
+ drive(t, rig, chromedp.Sleep(3*time.Second))
+ if got := th.eval(`window.__b.textContent`); got != glance {
+ t.Errorf("3 s after the glance (an activity line came), the bubble says %q", got)
+ }
+ const later = "Nothing yet."
+ drive(t, rig, chromedp.Evaluate[chromedp.Void](`window.__sent = performance.now()`))
+ f.Answer(id, later, false)
+ th.wait(`window.__b.dataset.id && window.__b.textContent === ` + strconv.Quote(later) + ` && !document.querySelector("#ask-panel .think-line")`)
+ if took := harness.Evaluate[float64](rig, `window.__x - window.__sent`); took > 700 {
+ t.Errorf("a reply 3 s after the glance took %.0f ms to replace it", took)
+ }
+ if got := th.eval(inPlaceJS(later)); got != "" {
+ t.Errorf("the reply 3 s after a glance: %s", got)
+ }
+
+ // Without a glance, an activity line still takes the dots' place.
+ id = th.send("What else?")
+ f.Emit("activity", map[string]string{"turn_id": id, "label": "Looking at what I can do…"})
+ th.wait(`document.querySelector(` + strconv.Quote(thinkingSel) + `)?.textContent === "Looking at what I can do…"`)
+
+ // A glance after the first words shows nowhere.
+ f.Stream(id, "Half an answer")
+ th.wait(`document.querySelector("#ask-panel .msg.draft")?.textContent === "Half an answer"`)
+ f.Glance(id, "A late glance")
+ drive(t, rig, chromedp.Sleep(500*time.Millisecond))
+ if got := th.eval(`document.querySelector("#ask-panel .msg.draft")?.textContent + " " + document.querySelector("#ask-panel").textContent.includes("A late glance")`); got != "Half an answer false" {
+ t.Errorf("a glance after the first words: draft and glance shown %s", got)
+ }
+ drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel form.composer button.stop`)))
+ th.wait(`!document.querySelector("#ask-panel .draft, #ask-panel .thinking") && document.querySelector("#ask-panel form.composer button.stop").hidden`)
+
+ // A glance for a turn the page is not answering shows nowhere, nor for
+ // a team_update turn, even on a page that has come back since (whose
+ // stream has not seen the turn start).
+ id = th.send("One more")
+ f.Hold = false
+ quiet := f.EmitTurn("team_update", "running")
+ f.Glance(quiet, "Checking the job")
+ drive(t, rig, chromedp.Sleep(300*time.Millisecond))
+ openPanel(t, rig)
+ th.wait(`document.querySelectorAll(` + strconv.Quote(thinkingSel) + `).length === 1`)
+ f.Glance(quiet, "Checking the job")
+ f.Glance("t_9999", "Someone else's turn")
+ drive(t, rig, chromedp.Sleep(500*time.Millisecond))
+ if got := th.eval(`(() => { const p = document.querySelector("#ask-panel"), b = document.querySelectorAll(` + strconv.Quote(thinkingSel) + `);
+ return [p.textContent.includes("Checking the job"), p.textContent.includes("Someone else"), b.length, b[0] && b[0].querySelectorAll(".dots > i").length].join(" "); })()`); got != "false false 1 3" {
+ t.Errorf("glances for other turns: quiet shown, other shown, bubbles, dots %s; want false false 1 3", got)
+ }
+ f.Glance(id, glance)
+ th.wait(`document.querySelector(` + strconv.Quote(thinkingSel) + `)?.textContent === ` + strconv.Quote(glance))
+
+ // A glance is live only (no id, never sent again) and never kept: the
+ // page that comes back shows the dots, and the events after it still
+ // arrive.
+ openPanel(t, rig)
+ th.wait(`document.querySelectorAll(` + strconv.Quote(thinkingSel+" .dots > i") + `).length === 3`)
+ drive(t, rig, chromedp.Sleep(300*time.Millisecond))
+ if got := th.eval(`document.querySelector("#ask-panel").textContent.includes(` + strconv.Quote(glance) + `) + ""`); got != "false" {
+ t.Errorf("after coming back, the glance shows again")
+ }
+ f.Answer(id, "All done.", false)
+ th.wait(`[...document.querySelectorAll("#ask-panel .msg.coordinator")].some(m => m.dataset.id && m.textContent === "All done.") && !document.querySelector("#ask-panel .thinking")`)
+}
diff --git a/internal/equipo/equipo_test.go b/internal/equipo/equipo_test.go
index 4c4ca37..f5b1f7a 100644
--- a/internal/equipo/equipo_test.go
+++ b/internal/equipo/equipo_test.go
@@ -402,3 +402,76 @@ func TestFakeJobCards(t *testing.T) {
t.Errorf("events: %v", seen)
}
}
+
+// readFrames reads the stream's frames (each its lines) until one holds
+// until, or the stream ends.
+func readFrames(t *testing.T, sc *bufio.Scanner, until string) []string {
+ t.Helper()
+ var frames []string
+ var cur []string
+ for sc.Scan() {
+ if sc.Text() != "" {
+ cur = append(cur, sc.Text())
+ continue
+ }
+ if len(cur) == 0 {
+ continue
+ }
+ f := strings.Join(cur, "\n")
+ cur = nil
+ frames = append(frames, f)
+ if strings.Contains(f, until) {
+ return frames
+ }
+ }
+ t.Fatalf("the stream ended before %q: %q", until, frames)
+ return nil
+}
+
+// The fake sends a glance as Equipo does: live only, without an id line
+// and with cursor 0, so the cursor runs on unbroken past it; a stream
+// that reconnects with its cursor never gets it again.
+func TestFakeGlanceIsLiveOnly(t *testing.T) {
+ f := equipotest.New(t)
+ f.Hold = true
+ c := equipo.New(f.URL)
+ cred := signIn(t, f, c)
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+ defer cancel()
+ sent, err := c.Send(ctx, cred.Token, "What's on today?", "k-1")
+ if err != nil {
+ t.Fatal(err)
+ }
+ res, err := c.Events(ctx, cred.Token, "40")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer res.Body.Close()
+ sc := bufio.NewScanner(res.Body)
+ readFrames(t, sc, `"state":"running"`)
+ f.Glance(sent.Turn.ID, "Checking your diary")
+ f.Say("Two meetings.")
+ frames := readFrames(t, sc, "Two meetings.")
+ if len(frames) != 2 {
+ t.Fatalf("frames after the glance: %q", frames)
+ }
+ if want := "event: glance\ndata: "; !strings.HasPrefix(frames[0], want) || !strings.Contains(frames[0], `"cursor":0,`) ||
+ !strings.Contains(frames[0], `"data":{"text":"Checking your diary","turn_id":"`+sent.Turn.ID+`"}`) {
+ t.Errorf("the glance: %q", frames[0])
+ }
+ if !strings.HasPrefix(frames[1], "id: 44\nevent: message\n") {
+ t.Errorf("after the glance: %q", frames[1])
+ }
+
+ again, err := c.Events(ctx, cred.Token, "40")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer again.Body.Close()
+ frames = readFrames(t, bufio.NewScanner(again.Body), "Two meetings.")
+ for _, fr := range frames {
+ if strings.Contains(fr, "glance") {
+ t.Errorf("replayed the glance: %q", frames)
+ }
+ }
+}
diff --git a/internal/equipo/equipotest/chat.go b/internal/equipo/equipotest/chat.go
index 222bb4b..0975d6c 100644
--- a/internal/equipo/equipotest/chat.go
+++ b/internal/equipo/equipotest/chat.go
@@ -79,7 +79,8 @@ type chat struct {
messages []message
turns map[string]*turn
cards []*card
- events []event
+ events []event // in order; a live event (a glance) has cursor 0
+ cursor int64 // the newest event's cursor, from 40
sent map[string]string // idempotency key to message id
wake chan struct{} // closed at each new event
// runner is why the person's runner cannot answer: "no_runner",
@@ -94,15 +95,26 @@ type chat struct {
func (c *chat) init() {
c.turns, c.sent, c.wake = map[string]*turn{}, map[string]string{}, make(chan struct{})
+ c.cursor = 40
c.address = "paul@tito.io"
}
func (c *chat) next(prefix string) string { c.seq++; return fmt.Sprintf("%s_%04d", prefix, c.seq) }
-// emit records an event; the caller holds cmu.
+// emit records an event at the next cursor; the caller holds cmu.
func (c *chat) emit(typ, resource, id string, rev int64, turnID string, data any) {
- c.events = append(c.events, event{Cursor: int64(len(c.events) + 41), Type: typ, Resource: resource,
- ID: id, Revision: rev, TurnID: turnID, Attempt: 1, Data: data})
+ c.cursor++
+ c.add(event{Cursor: c.cursor, Type: typ, Resource: resource, ID: id, Revision: rev, TurnID: turnID, Attempt: 1, Data: data})
+}
+
+// emitLive records a live event, as Equipo sends a glance: cursor 0, sent
+// only to the streams open now, never again; the caller holds cmu.
+func (c *chat) emitLive(typ, resource, id string, rev int64, turnID string, data any) {
+ c.add(event{Type: typ, Resource: resource, ID: id, Revision: rev, TurnID: turnID, Attempt: 1, Data: data})
+}
+
+func (c *chat) add(e event) {
+ c.events = append(c.events, e)
close(c.wake)
c.wake = make(chan struct{})
}
@@ -364,7 +376,7 @@ func (f *Fake) snapshot(w http.ResponseWriter, r *http.Request) {
writeJSON(w, 200, map[string]any{
"me": map[string]any{"id": f.address, "address": f.address, "role": "owner",
"person": map[string]any{"name": "Paul"}, "team_id": f.Instance, "team_name": "Tito"},
- "messages": f.tail(), "turns": turns, "cards": cards, "cursor": int64(len(f.events) + 40),
+ "messages": f.tail(), "turns": turns, "cards": cards, "cursor": f.cursor,
"available": f.runner == "",
})
}
@@ -503,6 +515,15 @@ func (f *Fake) Stream(id, reply string) {
}
}
+// Glance sends Equipo's glance for the turn with id: one line on what the
+// Assistant is about to do, before the turn's first words. Like a delta it
+// is an event only, never a message and never in a snapshot.
+func (f *Fake) Glance(id, text string) {
+ f.cmu.Lock()
+ defer f.cmu.Unlock()
+ f.emitLive("glance", "turn", id, 0, id, map[string]string{"turn_id": id, "text": text})
+}
+
// FailTurn ends the turn with id unanswered: failed.
func (f *Fake) FailTurn(id string) { f.setTurn(id, "failed", "") }
@@ -603,14 +624,16 @@ func (f *Fake) answer(w http.ResponseWriter, r *http.Request, id string) {
}
// stream is GET events: Server-Sent Events after ?after= (or
-// Last-Event-ID), as Equipo writes them.
+// Last-Event-ID), as Equipo writes them: then, live events (cursor 0, no
+// id line) that come while the stream is open.
func (f *Fake) stream(w http.ResponseWriter, r *http.Request) {
raw := r.URL.Query().Get("after")
if raw == "" {
raw = r.Header.Get("Last-Event-ID")
}
f.cmu.Lock()
- after := int64(len(f.events) + 40)
+ after, next := f.cursor, 0
+ live := len(f.events)
f.cmu.Unlock()
if raw != "" {
n, err := strconv.ParseInt(raw, 10, 64)
@@ -629,19 +652,24 @@ func (f *Fake) stream(w http.ResponseWriter, r *http.Request) {
for {
f.cmu.Lock()
var batch []event
- for _, e := range f.events {
- if e.Cursor > after {
+ for i, e := range f.events[next:] {
+ if e.Cursor > after || (e.Cursor == 0 && next+i >= live) {
batch = append(batch, e)
}
}
+ next = len(f.events)
wake := f.wake
f.cmu.Unlock()
for _, e := range batch {
raw, _ := json.Marshal(e)
- if _, err := fmt.Fprintf(w, "id: %d\nevent: %s\ndata: %s\n\n", e.Cursor, e.Type, raw); err != nil {
+ id := ""
+ if e.Cursor != 0 {
+ id = fmt.Sprintf("id: %d\n", e.Cursor)
+ after = e.Cursor
+ }
+ if _, err := fmt.Fprintf(w, "%sevent: %s\ndata: %s\n\n", id, e.Type, raw); err != nil {
return
}
- after = e.Cursor
}
if rc.Flush() != nil {
return
diff --git a/internal/look/static/app.css b/internal/look/static/app.css
index ed13bf0..4c1bd3f 100644
--- a/internal/look/static/app.css
+++ b/internal/look/static/app.css
@@ -717,6 +717,17 @@ aside.ask-panel { position: absolute; top: 16px; right: 16px; bottom: 16px; widt
var(--spk-rose) 76%, var(--edge-b) 88%, var(--edge-a) 98%, var(--edge-hi)) border-box; }
.msg.thinking.no-gl::before { opacity: 1; animation: sweep 4s linear infinite; }
@keyframes sweep { to { --sweep: 360deg; } }
+/* Before Equipo says anything, the bubble is wordless: three soft dots,
+ each lifting and brightening a beat after the last while their colour
+ drifts through the spark's teal, violet and rose. */
+.msg .dots { display: inline-flex; gap: 6px; align-items: center; height: 1.5em; padding: 0 2px; vertical-align: top; }
+.msg .dots i { width: 6px; height: 6px; border-radius: 50%; color: var(--edge-a); background: currentColor; box-shadow: 0 0 8px -1px currentColor; opacity: .45;
+ animation: think-dot 1.4s ease-in-out infinite, think-hue 4.2s linear infinite; }
+.msg .dots i:nth-child(2) { animation-delay: .18s, -1.4s; }
+.msg .dots i:nth-child(3) { animation-delay: .36s, -2.8s; }
+@keyframes think-dot { 0%, 70%, 100% { opacity: .45; transform: translateY(0) scale(.85); } 35% { opacity: 1; transform: translateY(-2px) scale(1); } }
+@keyframes think-hue { 0%, 100% { color: var(--edge-a); } 33% { color: var(--edge-b); } 66% { color: var(--spk-rose); } }
+@media (forced-colors: active) { .msg .dots i { forced-color-adjust: none; color: CanvasText; box-shadow: none; } }
.ask-page { display: flex; flex-direction: column; padding: 22px 0 0; }
.ask-page .crumb { padding: 0 24px; }
.ask-page .ask-head { padding-left: 24px; }
@@ -825,6 +836,10 @@ main { min-height: 100dvh; }
.msg.thinking { box-shadow: inset 0 0 0 1px var(--theirs-edge), 0 0 16px -3px var(--edge-glow-a), 0 0 26px -6px var(--edge-glow-b); }
.msg.thinking::before, .msg.thinking.no-gl::before { opacity: .7; animation: none;
background: linear-gradient(110deg, var(--edge-a), var(--edge-b) 50%, var(--spk-rose)) border-box; }
+ /* Its dots hold still: one teal, one violet, one rose. */
+ .msg .dots i { animation: none; opacity: .85; }
+ .msg .dots i:nth-child(2) { color: var(--edge-b); }
+ .msg .dots i:nth-child(3) { color: var(--spk-rose); }
}
/* Scratchpad's shared note: a field that grows past one control height. */
diff --git a/internal/look/static/ask.js b/internal/look/static/ask.js
index 0c1f1ad..3e3ce43 100644
--- a/internal/look/static/ask.js
+++ b/internal/look/static/ask.js
@@ -84,9 +84,11 @@ function start(root) {
}
// A message, once: the Assistant's reply takes its streamed draft's
- // place, or becomes its thinking bubble, where it is.
+ // place, or becomes its thinking bubble, where it is (once a glance has
+ // had its time, see held).
function addMessage(m) {
if (!m || !m.id || item("data-id", m.id)) return;
+ if (m.role !== "person" && held(m.turn_id, () => addMessage(m))) return;
const li = document.createElement("li");
li.className = "msg " + (m.role === "person" ? "person" : "coordinator");
li.dataset.id = m.id;
@@ -101,25 +103,37 @@ function start(root) {
// A streamed word: the turn's thinking bubble, if it shows, holds the
// draft. Equipo's offsets count UTF-8 bytes, so each draft keeps its
- // length in bytes (drafted) to place the next word.
+ // length in bytes (drafted) to place the next word. A glance in the
+ // bubble has its time first (held), then crossfades into the first
+ // words; the words that come meanwhile wait for it.
const utf8 = new TextEncoder();
const drafted = new WeakMap();
function delta(d) {
+ if (held(d.turn_id, () => delta(d))) return;
let li = item("data-draft", d.turn_id);
const bubble = !li && bubbles.get(d.turn_id);
if (bubble && bubble.isConnected) {
li = bubble;
bubbles.delete(d.turn_id);
+ const glanced = glances.delete(d.turn_id);
const line = li.querySelector(":scope > .think-line");
- for (const n of [line, li]) for (const a of n.getAnimations()) a.cancel();
- line.style.display = "";
- line.textContent = "";
li.classList.replace("thinking", "draft");
li.classList.add("answered");
delete li.dataset.thinking;
li.dataset.draft = d.turn_id;
li.setAttribute("aria-busy", "true");
spark.stop(li);
+ if (glanced) {
+ const id = d.turn_id;
+ waits.set(id, []);
+ const go = () => release(id);
+ setTimeout(go, 1000); // should the crossfade be cut short
+ swap(line, () => { line.textContent = ""; write(li, line, d); }, go);
+ return;
+ }
+ for (const n of [line, li]) for (const a of n.getAnimations()) a.cancel();
+ line.style.display = "";
+ line.textContent = "";
} else if (!li) {
li = document.createElement("li");
li.className = "msg coordinator draft";
@@ -127,7 +141,9 @@ function start(root) {
li.setAttribute("aria-busy", "true");
thread.append(li);
}
- const box = li.querySelector(":scope > .think-line") || li;
+ write(li, li.querySelector(":scope > .think-line") || li, d);
+ }
+ function write(li, box, d) {
const at = drafted.get(li) || 0;
if (d.offset === at && typeof d.text === "string") {
box.textContent += d.text;
@@ -905,36 +921,79 @@ function start(root) {
// The thinking bubble, one per turn being answered: on the Assistant's
// side, at the end of the conversation, where its answer will appear. It
- // says what the Assistant is doing ("Thinking…", then Equipo's activity
- // lines); the streamed words fill it and the reply becomes it, in place;
- // Stop or a failure takes it away. Its words are in .think-line until
- // the reply has landed. Without scripts the status line says it instead.
+ // starts wordless, three soft dots (named "Thinking…" for assistive
+ // tech), until Equipo says what the Assistant is doing: its glance, or
+ // else its activity lines. The streamed words fill it and the reply
+ // becomes it, in place; Stop or a failure takes it away. Its words are in
+ // .think-line until the reply has landed. Without scripts the status line
+ // says "Thinking…" instead.
const bubbles = new Map();
- function think(id, words) {
+ function think(id) {
const b = bubbles.get(id);
- if (b && b.isConnected) {
- if (words) say(b, words);
- return;
- }
// Its words are already streaming in (a late, stale revision).
- if (item("data-draft", id)) return;
+ if ((b && b.isConnected) || item("data-draft", id)) return;
const li = document.createElement("li");
li.className = "msg coordinator thinking";
li.dataset.thinking = id;
- li.append(span("think-line", words || "Thinking…"));
+ const dots = span("dots");
+ dots.setAttribute("role", "img");
+ dots.setAttribute("aria-label", "Thinking…");
+ dots.append(document.createElement("i"), document.createElement("i"), document.createElement("i"));
+ li.append(span("think-line"));
+ li.firstChild.append(dots);
thread.append(li);
bubbles.set(id, li);
spark.start(li);
scroll();
}
- function say(b, words) {
+ // say puts words in bubble b in place of what it says; shown runs once
+ // they are there.
+ function say(b, words, shown) {
const line = b.querySelector(":scope > .think-line");
- if (line && line.textContent !== words) swap(line, () => { line.textContent = words; });
+ if (line && line.textContent !== words) swap(line, () => { line.textContent = words; if (shown) shown(); });
+ }
+
+ // Equipo's glance: one line on the turn in flight, before its first
+ // words (or never). It takes the bubble's dots or activity line, and
+ // activity lines after it leave it be. It is never kept: a reload shows
+ // the dots again. A reply that comes before the glance has shown for
+ // HOLD waits until it has (held), then takes its place.
+ const HOLD = 1500;
+ const glances = new Map(); // turn id: when its glance showed
+ const waits = new Map(); // turn id: what waits for its glance
+ function glance(g) {
+ const id = g && g.turn_id, text = g && typeof g.text === "string" ? g.text.trim() : "";
+ const b = bubbles.get(id);
+ if (!text || isQuiet(id) || !turn || turn.id !== id || !b || !b.isConnected || !b.classList.contains("thinking") || glances.has(id) || waits.has(id)) return;
+ glances.set(id, performance.now());
+ say(b, text, () => { if (glances.has(id)) glances.set(id, performance.now()); });
+ }
+ // held keeps fn for turn id, to run once its glance has had its time,
+ // and says whether it did.
+ function held(id, fn) {
+ if (!id) return false;
+ const q = waits.get(id);
+ if (q) {
+ q.push(fn);
+ return true;
+ }
+ const left = HOLD - (performance.now() - (glances.has(id) ? glances.get(id) : -Infinity));
+ if (!(left > 0)) return false;
+ waits.set(id, [fn]);
+ setTimeout(() => release(id), left);
+ return true;
+ }
+ function release(id) {
+ const q = waits.get(id);
+ waits.delete(id);
+ for (const fn of q || []) fn();
}
// drop takes turn id's bubble away, and its spark with it.
function drop(id) {
const b = bubbles.get(id);
bubbles.delete(id);
+ glances.delete(id);
+ waits.delete(id);
if (!b) return;
spark.stop(b, true);
b.remove();
@@ -956,6 +1015,7 @@ function start(root) {
function become(b, li) {
const turnID = b.dataset.thinking || b.dataset.draft;
bubbles.delete(turnID);
+ glances.delete(turnID);
spark.stop(b);
const thinking = b.classList.contains("thinking");
b.classList.remove("thinking", "draft");
@@ -1054,7 +1114,7 @@ function start(root) {
status.textContent = line || "Ask Base can't answer right now. It will as soon as it can.";
} else {
status.textContent = "";
- think(t.id, line);
+ think(t.id);
}
return;
}
@@ -1066,9 +1126,11 @@ function start(root) {
settle(t);
}
// settle ends the drafts of turn t (every draft when there is none): a
- // cancelled or failed turn's goes, with any spark still on it (the
- // failure is said in the status line); the rest stay as written.
+ // cancelled or failed turn's goes, with any spark still on it and any
+ // words still waiting for it (the failure is said in the status line);
+ // the rest stay as written.
function settle(t) {
+ if (t && (t.state === "cancelled" || t.state === "failed")) waits.delete(t.id);
for (const d of thread.querySelectorAll("[data-draft]")) {
if (!t || d.dataset.draft === t.id) {
if (t && (t.state === "cancelled" || t.state === "failed")) {
@@ -1090,9 +1152,10 @@ function start(root) {
on("delta", (e) => delta(e.data));
on("card", (e) => (e.data && e.data.kind === "job" ? addJob(e.data) : addCard(e.data)));
on("turn", (e) => setTurn(e.data));
+ on("glance", (e) => glance(e.data));
on("activity", (e) => {
const id = e.data.turn_id, label = e.data.label;
- if (!label || isQuiet(id)) return;
+ if (!label || isQuiet(id) || glances.has(id) || waits.has(id)) return;
const b = bubbles.get(id);
if (b && b.isConnected) say(b, label);
else if (turn && id === turn.id) status.textContent = label;
@@ -1133,6 +1196,8 @@ function start(root) {
const focused = viewing && item("data-job", viewing)?.querySelector(".jobview")?.contains(document.activeElement);
thread.replaceChildren();
bubbles.clear();
+ glances.clear();
+ waits.clear();
pinned = true;
s.messages.forEach(addMessage);
for (const j of s.jobs || []) {
diff --git a/internal/web/ask_relay.go b/internal/web/ask_relay.go
index d9beef5..45d5a01 100644
--- a/internal/web/ask_relay.go
+++ b/internal/web/ask_relay.go
@@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"time"
+ "unicode"
"unicode/utf8"
"github.com/go-chi/chi/v5"
@@ -267,6 +268,7 @@ func relay(d downstream, upstream io.Reader, idle time.Duration, stop func()) {
defer quiet.Stop()
in := bufio.NewReaderSize(upstream, 32<<10)
var ev sseEvent
+ var seen turnsSeen
size, lines := 0, 0
for {
line, err := readLine(in, maxEventBytes-size)
@@ -282,7 +284,7 @@ func relay(d downstream, upstream io.Reader, idle time.Duration, stop func()) {
ev.field(line)
continue
}
- out := ev.frame()
+ out := ev.frame(&seen)
ev, size, lines = sseEvent{}, 0, 0
if out != "" && d.send(out) != nil {
return
@@ -338,24 +340,36 @@ func (e *sseEvent) field(line []byte) {
// frame is what the browser gets for the event: a ping as a comment, a
// conversation event as a fresh frame with a numeric id and its data
-// projected (project), and nothing for anything else.
-func (e sseEvent) frame() string {
+// projected (project, or seen.glance for a glance), and nothing for
+// anything else. A glance is live only: it comes without an id, and goes
+// without one, so the browser's cursor stays where the last conversation
+// event put it. seen hears every turn and delta that passes.
+func (e sseEvent) frame(seen *turnsSeen) string {
if e.typ == "ping" {
return ": ping\n\n"
}
- if _, err := strconv.ParseUint(e.id, 10, 63); err != nil || len(e.data) == 0 {
+ live := e.typ == "glance" && e.id == ""
+ if _, err := strconv.ParseUint(e.id, 10, 63); (err != nil && !live) || len(e.data) == 0 {
return ""
}
var env struct {
+ ID string `json:"id"`
Data json.RawMessage `json:"data"`
}
if err := json.Unmarshal([]byte(strings.Join(e.data, "\n")), &env); err != nil {
return ""
}
- data, ok := project(e.typ, env.Data)
+ var data any
+ ok := false
+ if e.typ == "glance" {
+ data, ok = seen.glance(env.ID, env.Data)
+ } else {
+ data, ok = project(e.typ, env.Data)
+ }
if !ok {
return ""
}
+ seen.note(data)
raw, err := json.Marshal(struct {
Type string `json:"type"`
Data any `json:"data"`
@@ -363,6 +377,9 @@ func (e sseEvent) frame() string {
if err != nil {
return ""
}
+ if live {
+ return "event: " + e.typ + "\ndata: " + string(raw) + "\n\n"
+ }
return "id: " + e.id + "\nevent: " + e.typ + "\ndata: " + string(raw) + "\n\n"
}
@@ -385,11 +402,7 @@ func project(typ string, raw json.RawMessage) (any, bool) {
}
return c.Clean()
case "delta":
- var d struct {
- TurnID string `json:"turn_id"`
- Offset int64 `json:"offset"`
- Text string `json:"text"`
- }
+ var d delta
return d, json.Unmarshal(raw, &d) == nil && d.TurnID != ""
case "activity":
var a struct {
@@ -400,3 +413,99 @@ func project(typ string, raw json.RawMessage) (any, bool) {
}
return nil, false
}
+
+// delta is a few of the reply's words, streamed: Offset counts the UTF-8
+// bytes before them.
+type delta struct {
+ TurnID string `json:"turn_id"`
+ Offset int64 `json:"offset"`
+ Text string `json:"text"`
+}
+
+// glance is Equipo's one line on the turn in flight, said before its first
+// words (or never): Base shows it in the thinking bubble and keeps it
+// nowhere.
+type glance struct {
+ TurnID string `json:"turn_id"`
+ Text string `json:"text"`
+}
+
+// maxGlance bounds a glance, in characters; Equipo keeps to 60.
+const maxGlance = 60
+
+// turnsSeen is what one stream has said of its turns, so a glance passes
+// only for the person's turn in flight before its first words: cur is the
+// newest such turn, past every turn no glance may be for (a team_update
+// turn, an ended one, one whose words have started). A stream that began
+// after its turn started knows none of this, and passes the glance on: the
+// page knows its own turn.
+type turnsSeen struct {
+ cur string
+ past map[string]bool
+}
+
+func (s *turnsSeen) note(data any) {
+ switch v := data.(type) {
+ case equipo.Turn:
+ if v.Kind == equipo.TurnTeamUpdate || !equipo.InFlight(v.State) {
+ s.over(v.ID)
+ } else if !s.past[v.ID] {
+ s.cur = v.ID
+ }
+ case delta:
+ s.over(v.TurnID)
+ }
+}
+
+func (s *turnsSeen) over(id string) {
+ if s.past == nil {
+ s.past = map[string]bool{}
+ }
+ s.past[id] = true
+ if s.cur == id {
+ s.cur = ""
+ }
+}
+
+// glance projects a glance event for turn id (the event's own id, which
+// is the turn's), cleaned (cleanGlance), if it may pass.
+func (s *turnsSeen) glance(id string, raw json.RawMessage) (any, bool) {
+ var g glance
+ if json.Unmarshal(raw, &g) != nil || g.TurnID == "" || (id != "" && id != g.TurnID) ||
+ s.past[g.TurnID] || (s.cur != "" && s.cur != g.TurnID) {
+ return nil, false
+ }
+ g.Text = cleanGlance(g.Text)
+ return g, g.Text != ""
+}
+
+// cleanGlance makes text one line of plain text: no control or format
+// characters, no Markdown emphasis or code marks, runs of space as one,
+// trimmed, and at most maxGlance characters, cut at a word where it can be.
+func cleanGlance(text string) string {
+ text = strings.Map(func(r rune) rune {
+ switch {
+ case r == '*' || r == '`':
+ return -1
+ case unicode.IsSpace(r):
+ return ' '
+ case unicode.In(r, unicode.Cc, unicode.Cf):
+ return -1
+ }
+ return r
+ }, strings.ToValidUTF8(text, ""))
+ r := []rune(strings.Join(strings.Fields(text), " "))
+ if len(r) <= maxGlance {
+ return string(r)
+ }
+ cut := r[:maxGlance]
+ if r[maxGlance] != ' ' {
+ for i := len(cut) - 1; i > 0; i-- {
+ if cut[i] == ' ' {
+ cut = cut[:i]
+ break
+ }
+ }
+ }
+ return strings.TrimRight(string(cut), " ,;:")
+}
diff --git a/internal/web/relay_internal_test.go b/internal/web/relay_internal_test.go
index b13a544..81a53f9 100644
--- a/internal/web/relay_internal_test.go
+++ b/internal/web/relay_internal_test.go
@@ -1,6 +1,7 @@
package web
import (
+ "encoding/json"
"io"
"net/http"
"net/http/httptest"
@@ -139,3 +140,73 @@ func TestRelayJobCards(t *testing.T) {
}
}
}
+
+// glanceEvent is Equipo's glance for turn id saying text. It is live
+// only: no id line, cursor 0. (cursor names it in these tests' text.)
+func glanceEvent(cursor, id, text string) string {
+ raw, _ := json.Marshal(text)
+ return "event: glance\ndata: " + `{"cursor":0,"type":"glance","resource":"turn","id":"` + id + `","revision":0,"turn_id":"` + id + `","data":{"turn_id":"` + id + `","text":` + string(raw) + `},"n":"` + cursor + `"}` + "\n\n"
+}
+
+// turnFrame is a turn event for turn id of kind in state, at cursor.
+func turnFrame(cursor, id, kind, state string) string {
+ return frame(cursor, "turn", `{"cursor":`+cursor+`,"type":"turn","resource":"turn","id":"`+id+`","revision":2,"turn_id":"`+id+`","data":{"id":"`+id+`","kind":"`+kind+`","state":"`+state+`"}}`)
+}
+
+// A glance, Equipo's one line on the turn in flight, passes for the
+// person's turn before its first words, cleaned: one trimmed line of plain
+// text, at most 60 characters, cut at a word. It is dropped for any other
+// turn (a team_update turn, an ended one, one that is not the turn in
+// flight), once the turn's words have started, and when nothing is left
+// of it.
+func TestRelayGlance(t *testing.T) {
+ long := "Looking through every one of your projects and the recent work in them"
+ delta := frame("60", "delta", `{"cursor":60,"type":"delta","resource":"turn","id":"t_1","revision":0,"turn_id":"t_1","data":{"turn_id":"t_1","offset":0,"text":"Here"}}`)
+ upstream := turnFrame("50", "t_1", "", "running") +
+ glanceEvent("51", "t_1", " Checking\n your **projects**\u0007\u202e ") +
+ glanceEvent("52", "t_1", long) +
+ glanceEvent("53", "t_1", " \n** ") +
+ glanceEvent("54", "t_9", "Another turn's glance") +
+ "event: glance\ndata: {\"cursor\":0,\"type\":\"glance\",\"resource\":\"turn\",\"id\":\"t_8\",\"data\":{\"turn_id\":\"t_1\",\"text\":\"Mismatched glance\"}}\n\n" +
+ turnFrame("56", "t_2", "team_update", "running") +
+ glanceEvent("57", "t_2", "Quiet turn's glance") +
+ turnFrame("58", "t_3", "", "replied") +
+ glanceEvent("59", "t_3", "Ended turn's glance") +
+ delta +
+ glanceEvent("61", "t_1", "After the first words")
+ out := relayTo(t, strings.NewReader(upstream), time.Second, func() {})
+ // A glance has no id line, as it came: the page's cursor stays where
+ // the last conversation event put it.
+ for _, want := range []string{
+ "\n\nevent: glance\ndata: {\"type\":\"glance\",\"data\":{\"turn_id\":\"t_1\",\"text\":\"Checking your projects\"}}\n\n",
+ "\n\nevent: glance\ndata: {\"type\":\"glance\",\"data\":{\"turn_id\":\"t_1\",\"text\":\"Looking through every one of your projects and the recent\"}}\n\n",
+ "id: 60\nevent: delta\n",
+ } {
+ if !strings.Contains(out, want) {
+ t.Errorf("relay lacks %q:\n%s", want, out)
+ }
+ }
+ if n := strings.Count(out, "event: glance"); n != 2 {
+ t.Errorf("relayed %d glances, want 2:\n%s", n, out)
+ }
+ if strings.Contains(out, "id: \n") || strings.Contains(out, "id: 0") {
+ t.Errorf("relayed an empty or zero id:\n%s", out)
+ }
+ // Any other event without an id is still not passed on.
+ out = relayTo(t, strings.NewReader(strings.Replace(frame("42", "message", msgEvent), "id: 42\n", "", 1)), time.Second, func() {})
+ if strings.Contains(out, "message") {
+ t.Errorf("relayed a message without an id:\n%s", out)
+ }
+ out = relayTo(t, strings.NewReader(upstream), time.Second, func() {})
+ for _, banned := range []string{"Another", "Mismatched", "Quiet", "Ended", "After the first", "\u0007", "\u202e", "**"} {
+ if strings.Contains(out, banned) {
+ t.Errorf("relayed %q:\n%s", banned, out)
+ }
+ }
+ // A stream that has not seen the turn start (it began after) passes the
+ // glance on: the page knows its turn.
+ out = relayTo(t, strings.NewReader(glanceEvent("70", "t_7", "Checking your projects")), time.Second, func() {})
+ if !strings.HasPrefix(out, "event: glance\n") {
+ t.Errorf("a glance for a turn the stream has not seen:\n%s", out)
+ }
+}