oficina / equipo Public

Thinking line cycles its set's phrases; picking a set saves it

The first phrase holds about 3 s, then the situation's phrases come in
a shuffled order every 3 to 4 s, never twice in a row; a situation with
one or two phrases adds the set's thinking ones; a new activity switches
at once; words change under reduced motion too. On the Thinking words
page a pick saves at once (Paul's iPhone choice was never saved).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 0839223f7e877e47039b16c92420063f99f520c1 parent f2602d3
3 files changed, +146 −13
  • internal/equipo/static/chat-stream.js +51 −10
  • internal/equipo/static/thinking-preview.js +6 −1
  • internal/thintest/thinking_browser_test.go +89 −2
diff --git a/internal/equipo/static/chat-stream.js b/internal/equipo/static/chat-stream.js
index 2e671281..c0b3aecf 100644
--- a/internal/equipo/static/chat-stream.js
+++ b/internal/equipo/static/chat-stream.js
@@ -94,15 +94,58 @@
for (var i = 0; i < turn.length; i++) h = (h * 31 + turn.charCodeAt(i)) >>> 0;
return ids.length ? ids[h % ids.length] : "professional";
}
+ // The phrases a situation cycles through: its own, and when it has
+ // only one or two, the set's thinking phrases too, so the line always
+ // moves after the threshold.
function phrases(li) {
if (li.dataset.kind) return [];
- return (WORDS[setFor(li)] || {})[li.situation || "think"] || [];
+ var set = WORDS[setFor(li)] || {}, own = set[li.situation || "think"] || [];
+ if (own.length > 2) return own;
+ return own.concat((set.think || []).filter(function (p) { return own.indexOf(p) < 0; }));
+ }
+ // A situation starts on its first phrase; after about 3 s the rest come
+ // in a shuffled order, one every 3 to 4 s, none again until all have
+ // shown, and never the same one twice in a row.
+ var FIRST = 3000;
+ function shuffled(n, avoid) {
+ var out = [];
+ for (var i = 0; i < n; i++) out.push(i);
+ for (var j = n - 1; j > 0; j--) {
+ var k = Math.floor(Math.random() * (j + 1)), t = out[j];
+ out[j] = out[k];
+ out[k] = t;
+ }
+ if (n > 1 && out[0] === avoid) out.push(out.shift());
+ return out;
}
function themed(li, label) {
var list = phrases(li);
- li.wordAt = Date.now();
li.dataset.thinkingWords = setFor(li);
- return list.length ? list[(li.wordIndex || 0) % list.length] : label;
+ li.wordAt = Date.now();
+ if (!list.length) return label;
+ var key = setFor(li) + "/" + (li.situation || "think") + "/" + list.length;
+ if (li.wordKey !== key) {
+ // A new situation (or set): its first phrase at once.
+ li.wordKey = key;
+ li.wordOrder = [0].concat(shuffled(list.length, 0).filter(function (i) { return i !== 0; }));
+ li.wordPos = 0;
+ li.wordDelay = FIRST;
+ }
+ return list[li.wordOrder[li.wordPos] % list.length];
+ }
+ // The next phrase of the situation, when its time has come.
+ function cycle(li) {
+ var list = phrases(li);
+ if (list.length < 2 || !li.wordOrder || Date.now() - (li.wordAt || 0) < li.wordDelay) return;
+ var last = li.wordOrder[li.wordPos];
+ li.wordPos++;
+ if (li.wordPos >= li.wordOrder.length) {
+ li.wordOrder = shuffled(list.length, last);
+ li.wordPos = 0;
+ }
+ li.wordDelay = 3000 + Math.random() * 1000;
+ li.wordAt = Date.now();
+ draw(li, list[li.wordOrder[li.wordPos] % list.length], false);
}
// The thinking line comes alive: the sparkle, and the drawn phrase
// beside the label, which stays for screen readers.
@@ -187,7 +230,6 @@
var span = li.querySelector("[equipo-activity]");
situation = situation || "think";
if (!span || !label || span.textContent === label && li.situation === situation) return;
- if (li.situation !== situation) li.wordIndex = 0;
li.situation = situation;
span.textContent = label;
var line = li.querySelector("[equipo-activity-line]");
@@ -304,16 +346,15 @@
var out = el.querySelector("[equipo-elapsed]");
var started = Number(el.dataset.started) || Date.now();
if (out) out.textContent = format.replace("{n}", String(Math.max(0, Math.floor((Date.now() - started) / 1000))));
- // The set's phrases take turns, slowly, while the activity holds.
- if (el.wordAt && !el.hasAttribute("data-streaming") && Date.now() - el.wordAt > 6000 && phrases(el).length > 1) {
- el.wordIndex = (el.wordIndex || 0) + 1;
- var span = el.querySelector("[equipo-activity]");
- draw(el, themed(el, span ? span.textContent : ""), false);
- }
if (LOOK.star.every && !el.hasAttribute("data-streaming") && Date.now() - (el.flourished || 0) > LOOK.star.every) flourish(el);
});
}
setInterval(tick, 1000);
+ // The set's phrases take turns while the activity holds (words are
+ // content: they change under reduced motion too, without the motion).
+ setInterval(function () {
+ feed.querySelectorAll("[equipo-thinking]:not([data-streaming])").forEach(cycle);
+ }, 250);
function showDraft(turn) {
var el = bubble(turn);
var text = drafts[turn] ? drafts[turn].text : "";
diff --git a/internal/equipo/static/thinking-preview.js b/internal/equipo/static/thinking-preview.js
index 603cb3ff..6912e60a 100644
--- a/internal/equipo/static/thinking-preview.js
+++ b/internal/equipo/static/thinking-preview.js
@@ -31,8 +31,13 @@
line.dataset.set = set;
step++;
}
+ // Picking a set saves it at once (on a phone the button below is easy
+ // to miss): the page returns with "Saved." and the preview of that set.
root.addEventListener("change", function (e) {
- if (e.target.name === "set") { step = 0; randomSet = ""; show(); }
+ if (e.target.name !== "set") return;
+ step = 0; randomSet = ""; show();
+ var form = e.target.form;
+ if (form && form.requestSubmit) form.requestSubmit();
});
show();
setInterval(show, 2200);
diff --git a/internal/thintest/thinking_browser_test.go b/internal/thintest/thinking_browser_test.go
index 4ad2f348..18bf77d5 100644
--- a/internal/thintest/thinking_browser_test.go
+++ b/internal/thintest/thinking_browser_test.go
@@ -3,11 +3,15 @@
package thintest
import (
+ "context"
"encoding/json"
"fmt"
"testing"
"amadan.net/oficina/equipo/internal/wire"
+ "github.com/chromedp/cdproto/cdp"
+ "github.com/chromedp/cdproto/page"
+ "github.com/chromedp/chromedp"
)
// TestBrowserThinkingWords: the Thinking words page previews the chosen
@@ -45,11 +49,20 @@ func TestBrowserThinkingWords(t *testing.T) {
p.open("/settings/thinking")
preview := `document.querySelector('[data-preview-phrase]').textContent`
p.wait(anyOf("professional")+`.includes(`+preview+`)`, "the preview shows Professional")
+ // Picking a set saves it at once (Paul, iPhone: the button below was
+ // easy to miss, and the line kept the default).
p.check(`(()=>{document.querySelector('[data-set="pirate"] label').click();return document.querySelector('input[value="pirate"]').checked})()`, "pick Pirate adventure")
- p.wait(anyOf("pirate")+`.includes(`+preview+`)`, "the preview shows Pirate adventure at once")
+ p.wait(`location.search.includes('saved=1') && document.querySelector('input[value="pirate"]').checked && document.querySelector('[equipo-saved]')`, "picking saved the set")
+ p.wait(anyOf("pirate")+`.includes(`+preview+`)`, "the preview shows Pirate adventure")
p.check(`document.querySelector('[data-preview-line]').dataset.set==='pirate'`, "preview set")
+ if got, _ := r.client.Thinking(r.ctx); got.Set != "pirate" {
+ t.Fatalf("saved %s", got.Set)
+ }
p.shot(fmt.Sprintf("ux1-thinking-words-%d", size.w))
- p.stayed("preview")
+ cur, _ := r.client.Thinking(r.ctx)
+ if _, err := r.client.SetThinking(r.ctx, "professional", cur.Revision); err != nil {
+ t.Fatal(err)
+ }
p.stop()
}
@@ -60,6 +73,7 @@ func TestBrowserThinkingWords(t *testing.T) {
line := `document.querySelector('[equipo-thinking][data-turn="` + r.turn + `"]')`
phrase := line + `?.querySelector('[equipo-phrase] [data-in]')?.textContent`
p.wait(in("professional", "think")+`.includes(`+phrase+`)`, "Professional while thinking")
+ _ = p
cur, _ := r.client.Thinking(r.ctx)
if _, err := r.client.SetThinking(r.ctx, "galaxy", cur.Revision); err != nil {
t.Fatal(err)
@@ -81,3 +95,76 @@ func TestBrowserThinkingWords(t *testing.T) {
p.wait(`(()=>{const l=`+line+`;const s=l?.dataset.thinkingWords;const all={professional:`+in("professional", "search")+`,playful:`+in("playful", "search")+`,galaxy:`+in("galaxy", "search")+`,bridge:`+in("bridge", "search")+`,pirate:`+in("pirate", "search")+`,terminal:`+in("terminal", "search")+`};return !!s && s!=='random' && (all[s]||[]).includes(`+phrase+`)})()`, "Random took one set for the turn")
p.stayed("conversation")
}
+
+// TestBrowserThinkingCycles: Paul, staging f2602d3, an iPhone: "Still says
+// 'Thinking' for me. Shouldn't it cycle if it goes over a waiting
+// threshold?" With a fake clock: the first phrase holds until about 3 s,
+// then the set's phrases come one after another, every 3 to 4 s, never
+// the same twice in a row; a new activity switches to its own phrases at
+// once (a situation with only two adds the thinking ones); under reduced
+// motion the words still change.
+func TestBrowserThinkingCycles(t *testing.T) {
+ r := newToolRig(t)
+ words, _ := r.client.Thinking(r.ctx)
+ var think, read []string
+ for _, s := range words.Sets {
+ if s.ID == wire.DefaultThinking {
+ think, read = s.Phrases["think"], s.Phrases["read"]
+ }
+ }
+ js := func(v any) string { raw, _ := json.Marshal(v); return string(raw) }
+ for _, motion := range []string{"no-preference", "reduce"} {
+ p := openInner(t, r.inst.URL, r.inst.Cookie(), 390, 844, true, "dark", motion)
+ p.do(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error {
+ _, err := cdp.Call(ctx, target, page.AddScriptToEvaluateOnNewDocument, page.AddScriptToEvaluateOnNewDocumentParams{Source: `(()=>{const real=Date.now.bind(Date);window.__skew=0;Date.now=()=>real()+window.__skew;})()`})
+ return err
+ }))
+ p.open("/conversation")
+ line := `document.querySelector('[equipo-thinking][data-turn="` + r.turn + `"]')`
+ phrase := line + `?.querySelector('[equipo-phrase] [data-in]')?.textContent`
+ p.wait(phrase+`===`+js(think[0]), "the first thinking phrase")
+ p.check(phrase+`===`+js(think[0]), "changed before the threshold")
+ seen := []string{think[0]}
+ for i := 0; i < 7; i++ {
+ skew := 4100
+ if i == 0 {
+ skew = 3100
+ }
+ p.check(fmt.Sprintf(`(()=>{window.__skew+=%d;return true})()`, skew), "advance the clock")
+ p.wait(phrase+`!==`+js(seen[len(seen)-1])+` && `+js(think)+`.includes(`+phrase+`)`, fmt.Sprintf("phrase %d after the threshold", i+1))
+ seen = append(seen, eval[string](p, phrase))
+ }
+ distinct := map[string]bool{}
+ for i, s := range seen {
+ distinct[s] = true
+ if i > 0 && s == seen[i-1] {
+ t.Fatalf("%s: the same phrase twice in a row: %v", motion, seen)
+ }
+ }
+ if len(distinct) != len(think) {
+ t.Fatalf("%s: not every phrase came round: %v", motion, seen)
+ }
+ // A new activity: its own phrases at once, then (only two of its
+ // own) the thinking ones join the rotation.
+ if err := r.runner.Send(r.ctx, "cyc-read-"+motion, wire.FrameActivity, wire.ActivityReport{TurnID: r.turn, Attempt: 1, Kind: wire.ActivityTool, Tool: wire.ToolReadFile}); err != nil {
+ t.Fatal(err)
+ }
+ p.wait(phrase+`===`+js(read[0]), "the reading phrase at once")
+ pool := append(append([]string{}, read...), think...)
+ last := read[0]
+ for i := 0; i < 5; i++ {
+ p.check(`(()=>{window.__skew+=4100;return true})()`, "advance the clock")
+ p.wait(phrase+`!==`+js(last)+` && `+js(pool)+`.includes(`+phrase+`)`, "reading cycles with the thinking phrases")
+ last = eval[string](p, phrase)
+ }
+ if motion == "reduce" {
+ p.check(`getComputedStyle(document.querySelector('[equipo-sparkle] path')).animationName==='none'`, "the mark moves under reduced motion")
+ }
+ p.stayed("conversation")
+ p.stop()
+ // The next pass starts from the thinking situation again.
+ if err := r.runner.Send(r.ctx, "cyc-think-"+motion, wire.FrameActivity, wire.ActivityReport{TurnID: r.turn, Attempt: 1, Kind: wire.ActivityThink}); err != nil {
+ t.Fatal(err)
+ }
+ }
+}