oficina / equipo Public

Show project and stream context on thinking indicators

Playful phrases remain on running rows, while queued and waiting rows show a quiet, explicit status. Context comes from the turn’s own message, with separate labels for access discovery and getting acquainted rather than guessed project names. Scheduling allows one dispatched conversation turn at a time, so three indicators do not mean three active coordinators; I also added guards against late activity and duplicate failure notices. JavaScript checks passed, but dependency restrictions blocked Go tests, and full browser verification remains outstanding.

Equipo task tkplvk6zce6q, Engineering step attempt 1.
Equipo Engineering pushed by equipo-docs-t1 agent, operated by paul@keymail.dev 2a3830646f59709fbdfac26d0886f3ebb8e27729 parent a069080
7 files changed, +127 −10
  • internal/equipo/chat/store.go +31 −3
  • internal/equipo/chat/turn_context_test.go +22 −0
  • internal/equipo/static/chat-stream.js +32 −4
  • internal/equipo/static/equipo.css +4 −0
  • internal/equipo/static/tests/turn-context.test.cjs +33 −0
  • internal/equipo/templates/chat.html +3 −3
  • internal/wire/api.go +2 −0

CI failed — run details

diff --git a/internal/equipo/chat/store.go b/internal/equipo/chat/store.go
index eb9b2aed..75ce5a1e 100644
--- a/internal/equipo/chat/store.go
+++ b/internal/equipo/chat/store.go
@@ -200,11 +200,19 @@ func (t *txn) messageEvent(m messageRecord) error {
}
func (t *txn) turnView(r turnRecord) (wire.Turn, error) {
- ids := []string{}
- if err := t.db.Model(&messageRecord{}).Where("turn_id = ? AND role = ?", r.ID, wire.RolePerson).Order("seq").Pluck("id", &ids).Error; err != nil {
+ var inputs []messageRecord
+ if err := t.db.Select("id", "text").Where("turn_id = ? AND role = ?", r.ID, wire.RolePerson).Order("seq").Find(&inputs).Error; err != nil {
return wire.Turn{}, err
}
- v := wire.Turn{ID: r.ID, Revision: r.Revision, Kind: r.Kind, State: r.State, Reason: r.Reason, Attempt: r.Attempt, MessageIDs: ids, ReplyID: r.ReplyID, Connection: r.Connection, CreatedAt: r.CreatedAt, UpdatedAt: r.UpdatedAt}
+ ids := make([]string, 0, len(inputs))
+ for _, input := range inputs {
+ ids = append(ids, input.ID)
+ }
+ text := ""
+ if len(inputs) > 0 {
+ text = inputs[0].Text
+ }
+ v := wire.Turn{ID: r.ID, Revision: r.Revision, Kind: r.Kind, State: r.State, Reason: r.Reason, Attempt: r.Attempt, MessageIDs: ids, ReplyID: r.ReplyID, Connection: r.Connection, CreatedAt: r.CreatedAt, UpdatedAt: r.UpdatedAt, Context: turnContext(r.Kind, text)}
if r.Timing != "" && r.State == wire.TurnReplied {
v.Timing = &wire.TurnTiming{}
if err := json.Unmarshal([]byte(r.Timing), v.Timing); err != nil {
@@ -729,3 +737,23 @@ func (s *Store) Sweep(ctx context.Context) error {
return t.expireAttempts()
})
}
+
+// A short quotation of the turn's input is grounded context even before the
+// coordinator has identified a project. Background streams have explicit names.
+func turnContext(kind, text string) string {
+ switch kind {
+ case wire.TurnExplore:
+ return "Access discovery"
+ case wire.TurnMoveIn:
+ return "Getting acquainted"
+ }
+ text = strings.Join(strings.Fields(text), " ")
+ if text == "" {
+ return "Conversation"
+ }
+ runes := []rune(text)
+ if len(runes) > 80 {
+ text = string(runes[:80]) + "…"
+ }
+ return "Conversation · " + text
+}
diff --git a/internal/equipo/chat/turn_context_test.go b/internal/equipo/chat/turn_context_test.go
new file mode 100644
index 00000000..eaec4ec0
--- /dev/null
+++ b/internal/equipo/chat/turn_context_test.go
@@ -0,0 +1,22 @@
+package chat
+
+import (
+ "strings"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+func TestTurnContext(t *testing.T) {
+ for _, tc := range []struct{ kind, text, want string }{
+ {wire.TurnExplore, "Equipo", "Access discovery"},
+ {wire.TurnMoveIn, "", "Getting acquainted"},
+ {wire.TurnPerson, "", "Conversation"},
+ {wire.TurnPerson, " Equipo · Rename\n projects ", "Conversation · Equipo · Rename projects"},
+ {wire.TurnPerson, strings.Repeat("界", 81), "Conversation · " + strings.Repeat("界", 80) + "…"},
+ } {
+ if got := turnContext(tc.kind, tc.text); got != tc.want {
+ t.Errorf("turnContext(%q, %q) = %q, want %q", tc.kind, tc.text, got, tc.want)
+ }
+ }
+}
diff --git a/internal/equipo/static/chat-stream.js b/internal/equipo/static/chat-stream.js
index d7baa8f1..c2d60247 100644
--- a/internal/equipo/static/chat-stream.js
+++ b/internal/equipo/static/chat-stream.js
@@ -306,6 +306,8 @@
// now with the server's attributes, time and markdown. No reflow.
function settle(live, server) {
clearTimeout(live.holding);
+ var context = live.querySelector("[equipo-turn-context]");
+ if (context) context.remove();
var line = live.querySelector("[equipo-activity-line]");
Array.from(live.attributes).forEach(function (a) { live.removeAttribute(a.name); });
Array.from(server.attributes).forEach(function (a) { live.setAttribute(a.name, a.value); });
@@ -332,6 +334,19 @@
}
// kind is a turn the coordinator takes on its own (move_in, explore):
// its line says so before any activity arrives.
+ function turnContext(el, v) {
+ var label = el.querySelector("[equipo-turn-context]");
+ if (!label) return;
+ el.dataset.state = v.state || "queued";
+ el.dataset.context = v.context || el.dataset.context || (v.kind === "explore" ? "Access discovery" : v.kind === "move_in" ? "Getting acquainted" : "Conversation");
+ label.textContent = el.dataset.context + " · " + (el.dataset.state === "running" ? "Running" : el.dataset.state === "waiting" ? "Waiting" : "Queued");
+ }
+ function copyContext(old, fresh) {
+ var label = fresh.querySelector("[equipo-turn-context]"), mine = old.querySelector("[equipo-turn-context]");
+ if (label && mine) mine.textContent = label.textContent;
+ old.dataset.state = fresh.dataset.state || "";
+ old.dataset.context = fresh.dataset.context || "";
+ }
function bubble(turn, kind) {
var el = lineFor(turn);
if (!el && !kind && pending.length) {
@@ -369,7 +384,7 @@
function lineFor(turn) {
return turn ? feed.querySelector('[equipo-thinking][data-turn="' + CSS.escape(turn) + '"]') : null;
}
- function optimistic(who) {
+ function optimistic(who, text) {
// Nothing can answer: the server's quiet status says so instead.
if (!thread && feed.querySelector("[data-no-connection]")) return null;
var el = template("equipo-thinking-template");
@@ -379,6 +394,8 @@
var name = el.querySelector("[data-who]");
if (name && who) name.textContent = root.dataset["name" + who.charAt(0).toUpperCase() + who.slice(1)] || "";
el.dataset.started = String(Date.now());
+ text = (text || input.value).trim().replace(/\s+/g, " ");
+ turnContext(el, { state: "queued", context: text ? "Conversation · " + Array.from(text).slice(0, 80).join("") : "Conversation" });
pending.push(el);
feed.append(el);
enliven(el);
@@ -542,10 +559,12 @@
}
var who = el.querySelector("[data-who]"), whoMine = old.querySelector("[data-who]");
if (who && whoMine && who.textContent) whoMine.textContent = who.textContent;
+ copyContext(old, el);
return old;
}
if (!old) return el;
delete keep[turn];
+ if (el.hasAttribute("equipo-thinking")) copyContext(old, el);
return el.hasAttribute("equipo-thinking") ? old : settle(old, el);
}));
local.forEach(function (el) { place(el); });
@@ -595,6 +614,7 @@
} else if (question || type === "question") {
return;
}
+ if ((type === "delta" || type === "activity") && ended[v.turn_id]) return;
if (type === "delta") {
var d = drafts[v.turn_id];
// A new attempt (a failover, a recovery) starts its draft afresh.
@@ -634,6 +654,7 @@
} else if (v.state === "queued" || v.state === "running" || v.state === "waiting") {
delete ended[v.id];
var shownDraft = bubble(v.id, v.kind);
+ turnContext(shownDraft, v);
if (drafts[v.id] && drafts[v.id].attempt !== v.attempt) {
// The refused attempt's words go; the next attempt's follow.
delete drafts[v.id];
@@ -642,6 +663,10 @@
}
// Going again on a connection: the status and the card go.
if (heldNow || feed.querySelector('[data-message] [data-waiting-connection]')) refreshSoon();
+ } else if (v.state === "replied" && v.reply_id) {
+ delete drafts[v.id];
+ ended[v.id] = true;
+ refreshSoon();
} else if (v.state === "replied" && !v.reply_id) {
// A turn that ended with nothing to say (an empty explore).
delete drafts[v.id];
@@ -659,7 +684,7 @@
var note = template("equipo-ended-template");
note.dataset.ended = v.id;
note.querySelector("p").textContent = v.state !== "failed" ? form.dataset.cancelled : v.reason === "runner_storage_full" && form.dataset.failedStorage ? form.dataset.failedStorage : form.dataset.failed;
- feed.append(note);
+ if (!feed.querySelector('[data-ended="' + CSS.escape(v.id) + '"]')) feed.append(note);
scroll();
}
} else if (type === "activity") {
@@ -763,6 +788,9 @@
delete el.dataset.pending;
// A conversation send names its turn; a thread question is its own.
claim(line, thread ? sent.message.id : sent.turn && sent.turn.id);
+ // Only an optimistic line uses the response: a newer stream event may
+ // already have updated an adopted line. Refresh supplies authoritative context.
+ if (!thread && sent.turn) refreshSoon();
if (feed.querySelector('[data-message="' + CSS.escape(sent.message.id) + '"]')) {
el.remove();
return;
@@ -787,7 +815,7 @@
retry.setAttribute("rst-btn", "");
retry.dataset.retrySend = "";
retry.textContent = form.dataset.retry;
- retry.addEventListener("click", function () { post(el, text, id, extra, files, optimistic(extra.specialist)); });
+ retry.addEventListener("click", function () { post(el, text, id, extra, files, optimistic(extra.specialist, text)); });
el.querySelector("[equipo-bubble]").append(retry);
});
}
@@ -812,7 +840,7 @@
lastSend = Date.now();
place(el);
// The coordinator's line, now: nothing waits on the network.
- var line = optimistic(who);
+ var line = optimistic(who, text);
scroll(true);
// The form's other fields as they are now (who a question is for).
var extra = {};
diff --git a/internal/equipo/static/equipo.css b/internal/equipo/static/equipo.css
index b557db40..1ed4ccac 100644
--- a/internal/equipo/static/equipo.css
+++ b/internal/equipo/static/equipo.css
@@ -1440,3 +1440,7 @@ label[equipo-sp-label] { cursor: pointer; }
[equipo-team-facts] { flex-direction: column; }
[equipo-team-facts] > * + *::before { content: none; }
}
+
+[equipo-turn-context] { margin: 0; color: var(--rst-text-muted); font-size: var(--rst-fs-sm); overflow-wrap: anywhere; }
+[equipo-thinking][data-state="queued"] [equipo-activity-line],
+[equipo-thinking][data-state="waiting"] [equipo-activity-line] { display: none; }
diff --git a/internal/equipo/static/tests/turn-context.test.cjs b/internal/equipo/static/tests/turn-context.test.cjs
new file mode 100644
index 00000000..62608c79
--- /dev/null
+++ b/internal/equipo/static/tests/turn-context.test.cjs
@@ -0,0 +1,33 @@
+// Run with node --test internal/equipo/static/tests/turn-context.test.cjs
+const {test} = require('node:test');
+const assert = require('node:assert/strict');
+const fs = require('node:fs');
+const vm = require('node:vm');
+const source = fs.readFileSync(__dirname + '/../chat-stream.js', 'utf8');
+const scope = {};
+vm.runInNewContext(source.slice(source.indexOf(' function turnContext('), source.indexOf(' function bubble(')), scope);
+function row() {
+ const label = {textContent: ''};
+ return {dataset: {}, querySelector: () => label};
+}
+test('simultaneous streams retain separate grounded context and state', () => {
+ const conversation = row(), discovery = row(), waiting = row();
+ scope.turnContext(conversation, {context: 'Conversation · Equipo · Rename projects', state: 'running'});
+ scope.turnContext(discovery, {kind: 'explore', state: 'queued'});
+ scope.turnContext(waiting, {state: 'waiting'});
+ assert.equal(conversation.querySelector().textContent, 'Conversation · Equipo · Rename projects · Running');
+ assert.equal(discovery.querySelector().textContent, 'Access discovery · Queued');
+ assert.equal(waiting.querySelector().textContent, 'Conversation · Waiting');
+ scope.turnContext(discovery, {state: 'running'});
+ assert.equal(discovery.querySelector().textContent, 'Access discovery · Running');
+});
+test('refresh and optimistic adoption replace context and state without replacing the row', () => {
+ const optimistic = row(), server = row();
+ scope.turnContext(optimistic, {state: 'queued'});
+ scope.turnContext(server, {context: 'Conversation · Rename projects', state: 'waiting'});
+ scope.copyContext(optimistic, server);
+ assert.equal(optimistic.dataset.state, 'waiting');
+ assert.equal(optimistic.querySelector().textContent, 'Conversation · Rename projects · Waiting');
+ scope.turnContext(optimistic, {state: 'running'});
+ assert.equal(optimistic.querySelector().textContent, 'Conversation · Rename projects · Running');
+});
diff --git a/internal/equipo/templates/chat.html b/internal/equipo/templates/chat.html
index 40aa6c2d..d8d9e096 100644
--- a/internal/equipo/templates/chat.html
+++ b/internal/equipo/templates/chat.html
@@ -1,6 +1,6 @@
{{define "up-label"}}{{copy "nav.work"}}{{end}}
{{define "title"}}{{copy "conversation.title"}}{{end}}
-{{define "chat-card"}}<li equipo-card="{{.Kind}}"{{if .Receipt}} equipo-receipt{{end}} data-card="{{.ID}}" data-state="{{.State}}" data-turn-id="{{.TurnID}}">
+{{define "chat-card"}}<li equipo-card="{{.Kind}}"{{if .Receipt}} equipo-receipt{{end}} data-card="{{.ID}}" data-state="{{.State}}" data-context="{{.Context}}" data-turn-id="{{.TurnID}}">
{{if and .Receipt (eq .Kind "task")}}{{template "work-task-receipt" .}}
{{else if eq .Kind "housekeeping"}}<p equipo-card-line data-digest>{{icon "list-checks"}}<span>{{.Line}} <a href="/housekeeping" data-digest-link>{{copy "chat.housekeeping.link"}}</a></span></p>
{{else if .Receipt}}<p equipo-card-line>{{icon "folder"}}<span>{{.Line}}</span></p>{{if .Open}}<button type="button" equipo-receipt-more aria-expanded="false" aria-controls="acts-{{.ID}}" aria-label="{{copy "chat.card.more"}}">⋯</button><span equipo-receipt-actions id="acts-{{.ID}}">{{if or (eq .Kind "home") (eq .Kind "combined")}}<form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form><input type="hidden" name="revision" value="{{.Revision}}"><button equipo-link name="choice" value="undo" type="submit" data-card-undo>{{copy "chat.card.undo"}}</button></form>{{else}}<details equipo-change><summary equipo-link>{{.Change}}</summary><form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form><input type="hidden" name="revision" value="{{.Revision}}"><select rst-input name="choice" aria-label="{{.Change}}">{{range .Choices}}<option>{{.}}</option>{{end}}</select><button rst-btn="primary" type="submit">{{copy "chat.card.use"}}</button></form></details>{{if .Remove}}<form method="post" action="/conversation/projects/{{.ProjectID}}/remove" data-card-form><button equipo-link type="submit">{{copy "chat.card.remove"}}</button></form>{{end}}{{end}}</span>{{end}}
@@ -21,7 +21,7 @@
<template equipo-own-template><li equipo-message="own" data-message=""><div equipo-message-meta><strong equipo-visually-hidden>{{.Address}}</strong><time></time></div><div equipo-message-files hidden></div><div equipo-bubble><p equipo-message-body></p></div></li></template>
<template equipo-file-template><a equipo-file-chip href="" target="_blank" rel="noopener" data-attachment="">{{icon "file-text"}}<span equipo-file-name></span><span equipo-file-size></span></a></template>
<template equipo-chip-template><li equipo-chip data-state="uploading"><span equipo-chip-thumb>{{icon "file-text"}}</span><span equipo-chip-text><span equipo-chip-name></span><span equipo-chip-note></span></span><span equipo-chip-progress role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><i></i></span><button type="button" equipo-chip-remove>{{icon "x"}}</button></li></template>
-<template equipo-thinking-template><li equipo-message="incoming" equipo-thinking data-turn="" data-started="" aria-busy="true"><div equipo-message-meta><strong>{{icon "message-circle"}}{{copy "conversation.coordinator"}}</strong><time></time></div><div equipo-bubble><div equipo-message-body equipo-markdown data-stream-text></div><p equipo-activity-line><span equipo-activity>{{copy "chat.activity.thinking"}}</span><span equipo-activity-sep aria-hidden="true">·</span><span equipo-elapsed></span></p></div></li></template>
+<template equipo-thinking-template><li equipo-message="incoming" equipo-thinking data-state="queued" data-turn="" data-started="" aria-busy="true"><div equipo-message-meta><strong>{{icon "message-circle"}}{{copy "conversation.coordinator"}}</strong><time></time></div><div equipo-bubble><div equipo-message-body equipo-markdown data-stream-text></div><p equipo-turn-context>Conversation · Queued</p><p equipo-activity-line><span equipo-activity>{{copy "chat.activity.thinking"}}</span><span equipo-activity-sep aria-hidden="true">·</span><span equipo-elapsed></span></p></div></li></template>
<template equipo-ended-template><li equipo-system-note data-ended=""><p></p></li></template>
<ol equipo-feed>
{{range .Chat.Messages}}
@@ -35,7 +35,7 @@
</li>
{{range .Cards}}{{template "chat-card" .}}{{end}}{{end}}
{{else}}<li data-empty-state="conversation.empty">{{copy "conversation.empty"}}</li>{{end}}
-{{range .Chat.Waiting}}<li equipo-message="incoming" equipo-thinking data-turn="{{.ID}}"{{with .Kind}} data-kind="{{.}}"{{end}} data-started="{{.CreatedAt.UnixMilli}}" aria-busy="true"><div equipo-message-meta><strong>{{icon "message-circle"}}{{copy "conversation.coordinator"}}</strong><time></time></div><div equipo-bubble><div equipo-message-body equipo-markdown data-stream-text></div><p equipo-activity-line><span equipo-activity>{{if eq .Kind "move_in"}}{{copy "chat.moving_in"}}{{else if eq .Kind "explore"}}{{copy "chat.exploring"}}{{else}}{{copy "chat.activity.thinking"}}{{end}}</span><span equipo-activity-sep aria-hidden="true">·</span><span equipo-elapsed></span></p></div></li>{{end}}
+{{range .Chat.Waiting}}<li equipo-message="incoming" equipo-thinking data-state="{{.State}}" data-context="{{.Context}}" data-turn="{{.ID}}"{{with .Kind}} data-kind="{{.}}"{{end}} data-started="{{.CreatedAt.UnixMilli}}" aria-busy="true"><div equipo-message-meta><strong>{{icon "message-circle"}}{{copy "conversation.coordinator"}}</strong><time></time></div><div equipo-bubble><div equipo-message-body equipo-markdown data-stream-text></div><p equipo-turn-context>{{.Context}} · {{if eq .State "running"}}Running{{else if eq .State "waiting"}}Waiting{{else}}Queued{{end}}</p><p equipo-activity-line><span equipo-activity>{{if eq .Kind "move_in"}}{{copy "chat.moving_in"}}{{else if eq .Kind "explore"}}{{copy "chat.exploring"}}{{else}}{{copy "chat.activity.thinking"}}{{end}}</span><span equipo-activity-sep aria-hidden="true">·</span><span equipo-elapsed></span></p></div></li>{{end}}
{{with .Chat.NoConnection}}<li equipo-card="no_connection" data-no-connection="{{.TurnID}}"><p equipo-card-line>{{.Line}}</p><p equipo-actions><a rst-btn="primary" href="/conversation/settings/connections/add" data-add-connection>{{copy "chat.no_connection.add"}}</a></p></li>{{end}}
{{with .Chat.Ended}}<li equipo-system-note data-ended="{{.ID}}"><p>{{copy .Key}}</p></li>{{end}}
</ol>
diff --git a/internal/wire/api.go b/internal/wire/api.go
index c9ad36ad..f4311ef9 100644
--- a/internal/wire/api.go
+++ b/internal/wire/api.go
@@ -202,6 +202,8 @@ const (
// Turn is one coordinator answer to one or more queued person messages,
// or a turn the coordinator takes on its own (Kind move_in or explore).
type Turn struct {
+ // Context identifies the stream from its own input, never an inferred project.
+ Context string `json:"context"`
ID string `json:"id"`
Revision int64 `json:"revision"`
Kind string `json:"kind"`