task page: a thread to ask Engineering or Review, on the chat stream
The task page's thread holds the creator's questions with their answers, and notes, oldest first. Its composer is the chat's (click anywhere to focus, docked on the page's own colour) with a quiet "Asking Engineering · change" line that follows what is typed and switches with change; for teammates, or before anyone can answer, it adds a note. chat-stream.js follows the thread with the chat's pieces: the thinking line, the streaming draft that the answered question settles into, background sends reconciled by id; the conversation ignores question streams. New copy accepted for now and listed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+351
−14
docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+11 −0internal/equipo/app.go+1 −0internal/equipo/chat_page.go+1 −1internal/equipo/copy.go+11 −0internal/equipo/static/ask-target.js+44 −0internal/equipo/static/chat-stream.js+54 −6internal/equipo/static/equipo.css+9 −0internal/equipo/templates/chrome.html+1 −1internal/equipo/templates/work_task.html+26 −3internal/equipo/work_pages.go+113 −3internal/headless/browser_thread_test.go+80 −0
Intent
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index affb544a..8e0d5f4e 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -4839,6 +4839,17 @@ records remain unchanged. |
| | `work.reason.account_unavailable` | no model account was ready | Thin v1 slice 4 review and checks (task card, task and Tasks pages, sidebar) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `work.review_findings` | Review found | Thin v1 slice 4 review and checks (task card, task and Tasks pages, sidebar) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `work.needs_empty` | Nothing needs you right now. | Thin v1 slice 4 review and checks (task card, task and Tasks pages, sidebar) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `work.thread` | Questions and notes | Thin v1 slice 4b ask the implementer (task page thread) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `work.thread_empty` | No questions or notes yet. | Thin v1 slice 4b ask the implementer (task page thread) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `work.ask.target` | Asking %s | Thin v1 slice 4b ask the implementer (task page thread) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `work.ask.change` | change | Thin v1 slice 4b ask the implementer (task page thread) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `work.ask.placeholder` | Ask %s about this work | Thin v1 slice 4b ask the implementer (task page thread) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `work.ask.queued` | Waiting for its turn… | Thin v1 slice 4b ask the implementer (task page thread) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `work.ask.failed` | %s couldn't answer: %s. | Thin v1 slice 4b ask the implementer (task page thread) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `work.ask.cancelled` | Question cancelled. | Thin v1 slice 4b ask the implementer (task page thread) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `work.ask.reason.session_gone` | its session for this work is no longer kept | Thin v1 slice 4b ask the implementer (task page thread) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `work.ask.reason.task_ended` | the task has ended | Thin v1 slice 4b ask the implementer (task page thread) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `chat.activity.read_change` | Looking at the change… | Thin v1 slice 4b ask the implementer (task page thread) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `work.step` | %s, attempt %d: %s | Thin v1 slice 4 review and checks (task card, task and Tasks pages, sidebar) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `work.steps` | Steps | Thin v1 slice 4 review and checks (task card, task and Tasks pages, sidebar) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `chat.card.home_ask` | Use %s for new projects? | Thin v1 slice 2b home card and receipts (chat page) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
diff --git a/internal/equipo/app.go b/internal/equipo/app.go| index 0da04f6b..d18ecbc5 100644 |
| --- a/internal/equipo/app.go |
| +++ b/internal/equipo/app.go |
| @@ -187,6 +187,7 @@ func RouterWithStore(d *db.DB, cfg Config, mailer mail.Sender, logger *slog.Logg |
| } |
| r.Get("/tasks", a.workTasks) |
| r.Post("/tasks/{id}/notes", a.workThread) |
| + r.Post("/tasks/{id}/ask", a.workAsk) |
| r.Post("/conversation/tasks/{id}/retry", a.workTaskAction(true)) |
| r.Post("/conversation/tasks/{id}/cancel", a.workTaskAction(false)) |
| r.Get("/tasks/new", a.taskForm) |
diff --git a/internal/equipo/chat_page.go b/internal/equipo/chat_page.go| index 3c0f0c43..c13c48bd 100644 |
| --- a/internal/equipo/chat_page.go |
| +++ b/internal/equipo/chat_page.go |
| @@ -294,7 +294,7 @@ func (a *application) chatNotebookReset(w http.ResponseWriter, r *http.Request) |
| } |
| func chatError(err error) error { |
| - for from, to := range map[error]error{chat.ErrBusy: ErrConflict, chat.ErrInvalid: ErrInvalid, chat.ErrConflict: ErrConflict, chat.ErrNotFound: ErrNotFound, chat.ErrForbidden: ErrForbidden, chat.ErrNotAllowed: ErrInvalid, chat.ErrTaskEnded: ErrConflict, chat.ErrNotRetryable: ErrConflict} { |
| + for from, to := range map[error]error{chat.ErrBusy: ErrConflict, chat.ErrInvalid: ErrInvalid, chat.ErrConflict: ErrConflict, chat.ErrNotFound: ErrNotFound, chat.ErrForbidden: ErrForbidden, chat.ErrNotAllowed: ErrInvalid, chat.ErrTaskEnded: ErrConflict, chat.ErrNotRetryable: ErrConflict, chat.ErrNotAskable: ErrConflict} { |
| if errors.Is(err, from) { |
| return to |
| } |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index 9e85f89d..1c731e7a 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -557,6 +557,17 @@ var pageCopy = map[string]string{ |
| "work.reason.account_unavailable": "no model account was ready", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "work.review_findings": "Review found", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "work.needs_empty": "Nothing needs you right now.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "work.thread": "Questions and notes", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "work.thread_empty": "No questions or notes yet.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "work.ask.target": "Asking %s", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "work.ask.change": "change", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "work.ask.placeholder": "Ask %s about this work", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "work.ask.queued": "Waiting for its turn…", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "work.ask.failed": "%s couldn't answer: %s.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "work.ask.cancelled": "Question cancelled.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "work.ask.reason.session_gone": "its session for this work is no longer kept", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "work.ask.reason.task_ended": "the task has ended", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "chat.activity.read_change": "Looking at the change…", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "work.task_count": "Tasks: %d", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.moving_in": "Moving in…", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.exploring": "Looking at new access…", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
diff --git a/internal/equipo/static/ask-target.js b/internal/equipo/static/ask-target.js| new file mode 100644 |
| index 00000000..2c6d37fa |
| --- /dev/null |
| +++ b/internal/equipo/static/ask-target.js |
| @@ -0,0 +1,44 @@ |
| +// The task thread's quiet "Asking Engineering · change" line. Without a |
| +// choice Equipo decides (Review when the question addresses it, else |
| +// Engineering), and the line follows what is typed; change picks the |
| +// other specialist explicitly. Without script Equipo decides. |
| +(function () { |
| + "use strict"; |
| + var line = document.querySelector("[equipo-ask-target]"); |
| + var root = document.querySelector("[data-chat-stream][data-task]"); |
| + if (!line || !root) return; |
| + var form = line.closest("form"); |
| + var input = form.querySelector("textarea"); |
| + var chosen = form.querySelector("[data-ask-specialist]"); |
| + var label = line.querySelector("[data-ask-line]"); |
| + var change = line.querySelector("[data-ask-change]"); |
| + var sep = line.querySelector("[data-ask-sep]"); |
| + var choices = (line.dataset.choices || "").split(",").filter(Boolean); |
| + var review = /\breview(?:er|ers|ed|ing|s)?\b/i; |
| + function name(s) { return root.dataset["name" + s.charAt(0).toUpperCase() + s.slice(1)] || s; } |
| + function current() { |
| + if (chosen.value) return chosen.value; |
| + if (choices.indexOf("review") >= 0 && review.test(input.value)) return "review"; |
| + return choices[0]; |
| + } |
| + function show() { |
| + var who = name(current()); |
| + label.textContent = (root.dataset.askFormat || "%s").replace("%s", who); |
| + input.placeholder = (root.dataset.askPlaceholder || "%s").replace("%s", who); |
| + input.setAttribute("aria-label", input.placeholder); |
| + } |
| + if (change && choices.length > 1) { |
| + change.hidden = false; |
| + if (sep) sep.hidden = false; |
| + change.addEventListener("click", function () { |
| + var at = choices.indexOf(current()); |
| + chosen.value = choices[(at + 1) % choices.length]; |
| + show(); |
| + input.focus({ preventScroll: true }); |
| + }); |
| + } |
| + input.addEventListener("input", show); |
| + // After a question goes, the next one starts undecided again. |
| + form.addEventListener("equipo:sent", function () { chosen.value = ""; show(); }); |
| + show(); |
| +})(); |
diff --git a/internal/equipo/static/chat-stream.js b/internal/equipo/static/chat-stream.js| index ed820518..037a26d1 100644 |
| --- a/internal/equipo/static/chat-stream.js |
| +++ b/internal/equipo/static/chat-stream.js |
| @@ -4,10 +4,23 @@ |
| // runner's offline line. The page works without it; replies then |
| // appear on reload. Applies an event only if it is newer (cursor, and |
| // delta offsets), as person API v1 clients must. |
| +// |
| +// A task page's thread ([data-chat-stream][data-task]) uses the same |
| +// pieces for questions to the specialists: a question's answer streams |
| +// as delta and activity events whose resource is "question", under the |
| +// question's id, and the answered question settles into its draft. The |
| +// conversation ignores those; the thread ignores everything else. |
| (function () { |
| "use strict"; |
| var root = document.querySelector("[data-chat-stream]"); |
| if (!root || !window.EventSource || !window.fetch) return; |
| + // thread is the task whose questions this page follows ("" in the chat); |
| + // asked maps each of its questions to the specialist answering it. |
| + var thread = root.dataset.task || "", asked = {}; |
| + root.querySelectorAll("[data-turn], [data-turn-id]").forEach(function (el) { |
| + var id = el.dataset.turn || el.dataset.turnId; |
| + if (thread && id) asked[id] = asked[id] || ""; |
| + }); |
| var feed = root.querySelector("[equipo-feed]"); |
| var offline = root.querySelector("[equipo-offline]"); |
| var form = document.getElementById("composer"); |
| @@ -239,6 +252,8 @@ |
| if (!el) { |
| el = template("equipo-thinking-template"); |
| el.dataset.turn = turn; |
| + var who = el.querySelector("[data-who]"); |
| + if (who && asked[turn]) who.textContent = root.dataset["name" + asked[turn].charAt(0).toUpperCase() + asked[turn].slice(1)] || ""; |
| var label = kind && root.dataset[kind === "move_in" ? "movingIn" : "exploring"]; |
| if (label) { |
| el.dataset.kind = kind; |
| @@ -372,6 +387,30 @@ |
| if (e.cursor <= cursor) return; |
| cursor = e.cursor; |
| var v = e.data; |
| + var question = e.resource === "question"; |
| + if (thread) { |
| + // The thread: its own questions' streams; everything else about |
| + // the task is rendered by the server, like a committed reply. |
| + if (type === "question") { |
| + if (v.task_id !== thread) return; |
| + asked[v.id] = v.specialist; |
| + if (v.state === "answered" || v.state === "failed" || v.state === "cancelled") delete drafts[v.id]; |
| + if (v.state === "running") { |
| + // Its turn came: the waiting line becomes the thinking line. |
| + var waiting = feed.querySelector('[equipo-thinking][data-turn="' + CSS.escape(v.id) + '"]'); |
| + if (waiting) setActivity(waiting, root.dataset.thinking); |
| + } |
| + refresh().catch(function () { location.reload(); }); |
| + return; |
| + } |
| + if (type === "task" || type === "step") { |
| + if (v.id === thread || v.task_id === thread) refresh().catch(function () { location.reload(); }); |
| + return; |
| + } |
| + if ((type !== "delta" && type !== "activity") || !question || !(v.turn_id in asked)) return; |
| + } else if (question || type === "question") { |
| + return; |
| + } |
| if (type === "delta") { |
| var d = drafts[v.turn_id] || { text: "", bytes: 0 }; |
| if (v.offset !== d.bytes) return; |
| @@ -419,7 +458,7 @@ |
| // Cards (and the tasks on them) are rendered by the server, like |
| // committed replies. |
| refresh().catch(function () { location.reload(); }); |
| - } else if (type === "runner") { |
| + } else if (type === "runner" && offline) { |
| offline.hidden = !!v.online; |
| } |
| } |
| @@ -458,12 +497,15 @@ |
| feed.insertBefore(el, feed.querySelector("[equipo-thinking]")); |
| scroll(); |
| } |
| - function post(el, text, id) { |
| + function post(el, text, id, extra) { |
| el.dataset.pending = ""; |
| delete el.dataset.sendFailed; |
| var old = el.querySelector("[data-retry-send]"); |
| if (old) old.remove(); |
| - fetch(form.action, { method: "POST", credentials: "same-origin", headers: { "Accept": "application/json" }, body: new URLSearchParams({ body: text, request_id: id }) }) |
| + var params = new URLSearchParams(extra || {}); |
| + params.set("body", text); |
| + params.set("request_id", id); |
| + fetch(form.action, { method: "POST", credentials: "same-origin", headers: { "Accept": "application/json" }, body: params }) |
| .then(function (r) { if (!r.ok) throw new Error("send"); return r.json(); }) |
| .then(function (sent) { |
| local.delete(el); |
| @@ -479,7 +521,7 @@ |
| retry.setAttribute("rst-btn", ""); |
| retry.dataset.retrySend = ""; |
| retry.textContent = form.dataset.retry; |
| - retry.addEventListener("click", function () { post(el, text, id); }); |
| + retry.addEventListener("click", function () { post(el, text, id, extra); }); |
| el.querySelector("[equipo-bubble]").append(retry); |
| }); |
| } |
| @@ -496,7 +538,13 @@ |
| lastSend = Date.now(); |
| place(el); |
| scroll(true); |
| - post(el, text, requestID()); |
| + // The form's other fields as they are now (who a question is for). |
| + var extra = {}; |
| + form.querySelectorAll("input[type=hidden][name]").forEach(function (i) { |
| + if (i.name !== "request_id") extra[i.name] = i.value; |
| + }); |
| + post(el, text, requestID(), extra); |
| + form.dispatchEvent(new CustomEvent("equipo:sent")); |
| } |
| form.addEventListener("submit", function (event) { event.preventDefault(); send(); }); |
| input.addEventListener("keydown", function (event) { |
| @@ -508,7 +556,7 @@ |
| function open() { |
| source = new EventSource("/api/v1/events?after=" + cursor); |
| - ["message", "turn", "delta", "runner", "activity", "card", "task", "step"].forEach(function (type) { |
| + ["message", "turn", "delta", "runner", "activity", "card", "task", "step", "question"].forEach(function (type) { |
| source.addEventListener(type, function (event) { failures = 0; apply(type, event.data); }); |
| }); |
| source.addEventListener("ping", function () { failures = 0; }); |
diff --git a/internal/equipo/static/equipo.css b/internal/equipo/static/equipo.css| index ec6050d4..e8e9640b 100644 |
| --- a/internal/equipo/static/equipo.css |
| +++ b/internal/equipo/static/equipo.css |
| @@ -345,3 +345,12 @@ html:has([equipo-conversation]) { overflow: hidden; scrollbar-gutter: auto; } |
| [equipo-card-decision] { margin: var(--rst-sp-2) 0 0; } |
| [equipo-conversation] [equipo-card-decision] [rst-btn], [equipo-card-decision] [rst-btn] { min-block-size: 2.25rem; font-size: var(--rst-fs-base); } |
| @media (pointer: coarse) { [equipo-card-decision] [rst-btn] { min-block-size: 2.75rem; } } |
| + |
| +/* The task thread: questions to the specialists and notes, like the |
| + chat, with the same compose box docked at the bottom of the page on |
| + the page's own colour. */ |
| +[equipo-thread] { margin-block-start: var(--rst-sp-6); } |
| +[equipo-thread] [equipo-feed] { margin: 0 0 var(--rst-sp-4); } |
| +[equipo-thread] #chat-composer { position: sticky; inset-block-end: 0; z-index: 1; padding-inline: 0; background: var(--rst-bg); } |
| +[equipo-ask-target] { display: flex; align-items: baseline; gap: var(--rst-sp-1); min-width: 0; margin: 0; color: var(--rst-text-muted); font-size: var(--rst-fs-sm); } |
| +#composer [equipo-ask-target] button { margin-inline-start: 0; } |
diff --git a/internal/equipo/templates/chrome.html b/internal/equipo/templates/chrome.html| index a9e40d59..6be2bead 100644 |
| --- a/internal/equipo/templates/chrome.html |
| +++ b/internal/equipo/templates/chrome.html |
| @@ -1,6 +1,6 @@ |
| {{define "rail-brand"}}<span hidden></span>{{end}} |
| {{define "title"}}{{copy .Title}} · {{copy "brand"}}{{end}} |
| -{{define "head"}}{{.Live.Head (T "rastrillo.ui.live.paused") (T "rastrillo.ui.live.unconfirmed")}}<link rel="stylesheet" href="{{asset "static/equipo.css"}}"><script defer src="{{asset "static/nav-stream.js"}}"></script>{{if .ChatStream}}<script defer src="{{asset "static/chat-stream.js"}}"></script><script defer src="{{asset "static/chat-compose.js"}}"></script>{{else if eq .Key "conversation"}}<script defer blocking="render" src="{{asset "static/chat-navigation.js"}}"></script><script defer src="{{asset "static/chat.js"}}"></script><script defer src="{{asset "static/chat-send.js"}}"></script>{{end}}{{end}} |
| +{{define "head"}}{{.Live.Head (T "rastrillo.ui.live.paused") (T "rastrillo.ui.live.unconfirmed")}}<link rel="stylesheet" href="{{asset "static/equipo.css"}}"><script defer src="{{asset "static/nav-stream.js"}}"></script>{{if .ChatStream}}<script defer src="{{asset "static/chat-stream.js"}}"></script><script defer src="{{asset "static/chat-compose.js"}}"></script><script defer src="{{asset "static/ask-target.js"}}"></script>{{else if eq .Key "conversation"}}<script defer blocking="render" src="{{asset "static/chat-navigation.js"}}"></script><script defer src="{{asset "static/chat.js"}}"></script><script defer src="{{asset "static/chat-send.js"}}"></script>{{end}}{{end}} |
| {{define "up"}}/work{{if .Key}}#nav-{{.Key}}{{end}}{{end}} |
| {{define "up-label"}}{{.TeamName}}{{end}} |
| {{define "brand"}}<a rst-shell-brand href="/work">{{icon "users"}}{{.TeamName}}</a>{{end}} |
diff --git a/internal/equipo/templates/work_task.html b/internal/equipo/templates/work_task.html| index 4f9fc18f..383b0e9d 100644 |
| --- a/internal/equipo/templates/work_task.html |
| +++ b/internal/equipo/templates/work_task.html |
| @@ -11,8 +11,31 @@ |
| {{if or .Retry .Cancel}}<div equipo-actions>{{if .Retry}}<form method="post" action="/conversation/tasks/{{.ID}}/retry"><input type="hidden" name="from" value="task"><button rst-btn type="submit" data-task-retry>{{copy "work.retry"}}</button></form>{{end}}{{if .Cancel}}<form method="post" action="/conversation/tasks/{{.ID}}/cancel"><input type="hidden" name="from" value="task"><button rst-btn type="submit" data-task-cancel>{{copy "work.cancel"}}</button></form>{{end}}</div>{{end}} |
| {{if .Findings}}<h2>{{copy "work.findings"}}</h2><ul equipo-work-list>{{range .Findings}}<li><p>{{.Text}}</p>{{if .Path}}<p equipo-card-note>{{.Path}}:{{.Line}}</p>{{end}}</li>{{end}}</ul>{{end}} |
| {{if .Steps}}<h2>{{copy "work.steps"}}</h2><ul equipo-work-list>{{range .Steps}}<li data-step="{{.ID}}" data-state="{{.State}}" data-specialist="{{.Specialist}}"><p>{{.Line}}</p>{{with .Result}}<p equipo-card-note data-result>{{.}}</p>{{end}}{{if .Summary}}<p>{{.Summary}}</p>{{end}}{{if .Findings}}<p equipo-card-note>{{copy "work.review_findings"}}</p><ul>{{range .Findings}}<li><p>{{.Text}}</p>{{if .Path}}<p equipo-card-note>{{.Path}}{{if .Line}}:{{.Line}}{{end}}</p>{{end}}</li>{{end}}</ul>{{end}}{{if .LogTail}}<pre equipo-work-log>{{.LogTail}}</pre>{{end}}</li>{{end}}</ul>{{end}} |
| -<h2>{{copy "work.notes"}}</h2> |
| -{{if .Thread}}<ul equipo-work-list>{{range .Thread}}<li><p equipo-card-note>{{.Author}}</p><p>{{.Text}}</p></li>{{end}}</ul>{{else}}<p data-empty-state="work.notes_empty">{{copy "work.notes_empty"}}</p>{{end}} |
| -<form method="post" action="/tasks/{{.ID}}/notes" equipo-form><input type="hidden" name="request_id" value="{{$.RequestID}}"><textarea rst-input name="body" required maxlength="4000" rows="2" aria-label="{{copy "work.note_add"}}"></textarea><button rst-btn type="submit">{{copy "work.note_add"}}</button></form> |
| +</section>{{end}} |
| +{{with .Thin.Task}}{{$thread := $.Thin.Thread}}<section equipo-thread data-chat-stream data-task="{{.ID}}" data-cursor="{{$thread.Cursor}}" data-elapsed="{{copy "chat.elapsed"}}" data-thinking="{{copy "chat.activity.thinking"}}" data-ask-format="{{copy "work.ask.target"}}" data-ask-placeholder="{{copy "work.ask.placeholder"}}" data-name-engineering="{{copy "work.specialist.engineering"}}" data-name-review="{{copy "work.specialist.review"}}"> |
| +<h2>{{copy "work.thread"}}</h2> |
| +<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-bubble><p equipo-message-body></p></div></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"}}<span data-who></span></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-ended-template><li equipo-system-note data-ended=""><p></p></li></template> |
| +<ol equipo-feed> |
| +{{range $thread.Items}}{{if .Note}}<li equipo-message="incoming" data-note="{{.ID}}"><div equipo-message-meta><strong>{{.Author}}</strong><time datetime="{{.At.Format "2006-01-02T15:04:05Z07:00"}}">{{.At.Format "15:04"}}</time></div><div equipo-bubble><p equipo-message-body>{{.Text}}</p></div></li> |
| +{{else}}<li equipo-message="{{if .Own}}own{{else}}incoming{{end}}" data-message="{{.ID}}"><div equipo-message-meta><strong{{if .Own}} equipo-visually-hidden{{end}}>{{.Author}}</strong><time datetime="{{.At.Format "2006-01-02T15:04:05Z07:00"}}">{{.At.Format "15:04"}}</time></div><div equipo-bubble><p equipo-message-body>{{.Text}}</p></div></li> |
| +{{if .Answered}}<li equipo-message="incoming" data-message="a{{.ID}}" data-turn-id="{{.ID}}"><div equipo-message-meta><strong>{{icon "message-circle"}}<span data-who>{{.Who}}</span></strong><time></time></div><div equipo-bubble><div equipo-message-body equipo-markdown>{{chatMarkdown .Answer}}</div></div></li> |
| +{{else if .Waiting}}<li equipo-message="incoming" equipo-thinking data-turn="{{.ID}}" data-started="{{.At.UnixMilli}}" aria-busy="true"><div equipo-message-meta><strong>{{icon "message-circle"}}<span data-who>{{.Who}}</span></strong><time></time></div><div equipo-bubble><div equipo-message-body equipo-markdown data-stream-text></div><p equipo-activity-line><span equipo-activity>{{.Waiting}}</span><span equipo-activity-sep aria-hidden="true">·</span><span equipo-elapsed></span></p></div></li> |
| +{{else}}<li equipo-system-note data-ended="{{.ID}}"><p>{{.Ended}}</p></li> |
| +{{end}}{{end}}{{else}}<li data-empty-state="work.thread_empty">{{copy "work.thread_empty"}}</li>{{end}} |
| +</ol> |
| +<div id="chat-composer"> |
| +{{if $thread.Ask}}{{$first := index $thread.Choices 0}}<form id="composer" equipo-form method="post" action="/tasks/{{.ID}}/ask" data-retry="{{copy "conversation.retry"}}"> |
| +<input type="hidden" name="request_id" value="{{$.RequestID}}"> |
| +<input type="hidden" name="specialist" value="" data-ask-specialist> |
| +<textarea id="chat-body" rst-input name="body" required maxlength="4000" rows="1" aria-label="{{printf (copy "work.ask.placeholder") (index $thread.Names $first)}}" placeholder="{{printf (copy "work.ask.placeholder") (index $thread.Names $first)}}"></textarea> |
| +<div equipo-composer-tools><p equipo-ask-target data-choices="{{range $i, $c := $thread.Choices}}{{if $i}},{{end}}{{$c}}{{end}}"><span data-ask-line>{{printf (copy "work.ask.target") (index $thread.Names $first)}}</span>{{if gt (len $thread.Choices) 1}}<span aria-hidden="true" data-ask-sep hidden> · </span><button type="button" equipo-link data-ask-change hidden>{{copy "work.ask.change"}}</button>{{end}}</p><button rst-btn="primary" type="submit">{{copy "conversation.send_short"}}</button></div> |
| +</form>{{else}}<form id="composer" equipo-form method="post" action="/tasks/{{.ID}}/notes" data-retry="{{copy "conversation.retry"}}"> |
| +<input type="hidden" name="request_id" value="{{$.RequestID}}"> |
| +<textarea id="chat-body" rst-input name="body" required maxlength="4000" rows="1" aria-label="{{copy "work.note_add"}}" placeholder="{{copy "work.note_add"}}"></textarea> |
| +<div equipo-composer-tools><button rst-btn="primary" type="submit">{{copy "conversation.send_short"}}</button></div> |
| +</form>{{end}} |
| +</div> |
| </section>{{end}} |
| {{end}} |
diff --git a/internal/equipo/work_pages.go b/internal/equipo/work_pages.go| index 2ad4af57..b003b343 100644 |
| --- a/internal/equipo/work_pages.go |
| +++ b/internal/equipo/work_pages.go |
| @@ -5,7 +5,9 @@ import ( |
| "crypto/rand" |
| "fmt" |
| "net/http" |
| + "slices" |
| "strings" |
| + "time" |
| "github.com/go-chi/chi/v5" |
| @@ -146,6 +148,73 @@ type projectLine struct { |
| Tasks int |
| } |
| +// threadView is a task page's thread: the creator's questions to the |
| +// specialists with their answers, and notes, oldest first. Ask is set for |
| +// the task's creator when a specialist can answer: the composer then |
| +// asks (Asking Engineering · change); otherwise it adds a note. |
| +type threadView struct { |
| + Cursor int64 |
| + Items []threadItem |
| + Ask bool |
| + // Choices are the specialists that can answer, the default first. |
| + Choices []string |
| + // Names are their names, for the ask line and the answers. |
| + Names map[string]string |
| +} |
| + |
| +// threadItem is a note, or a question with its answer, its waiting line |
| +// or its ending. |
| +type threadItem struct { |
| + ID, Text, Author, Answer, Who, Ended, Waiting string |
| + Note, Own, Answered bool |
| + At time.Time |
| +} |
| + |
| +func threadOf(t wire.Task, viewer string, cursor int64) threadView { |
| + v := threadView{Cursor: cursor, Names: map[string]string{}} |
| + for _, n := range t.Thread { |
| + v.Items = append(v.Items, threadItem{ID: n.ID, Text: n.Text, Author: n.Author, Note: true, At: n.At}) |
| + } |
| + for _, q := range t.Questions { |
| + who := specialistName(q.Specialist) |
| + it := threadItem{ID: q.ID, Text: q.Text, Author: q.Asker, Who: who, Own: q.Asker == viewer, At: q.CreatedAt} |
| + switch q.State { |
| + case wire.QuestionAnswered: |
| + it.Answered, it.Answer = true, q.Answer |
| + case wire.QuestionQueued: |
| + it.Waiting = copyText("work.ask.queued") |
| + case wire.QuestionRunning: |
| + it.Waiting = copyText("chat.activity.thinking") |
| + case wire.QuestionCancelled: |
| + it.Ended = copyText("work.ask.cancelled") |
| + default: |
| + reason := copyText("work.ask.reason." + q.Reason) |
| + if reason == "" { |
| + reason = copyText("work.reason." + q.Reason) |
| + } |
| + if reason == "" { |
| + reason = copyText("work.reason.other") |
| + } |
| + it.Ended = fmt.Sprintf(copyText("work.ask.failed"), who, reason) |
| + } |
| + v.Items = append(v.Items, it) |
| + } |
| + slices.SortStableFunc(v.Items, func(a, b threadItem) int { return a.At.Compare(b.At) }) |
| + if t.Creator != viewer || wire.FinalStage(t.Stage) { |
| + return v |
| + } |
| + for _, sp := range []string{wire.SpecialistEngineering, wire.SpecialistReview} { |
| + for _, s := range t.Steps { |
| + if s.Specialist == sp && s.Askable && s.State == wire.StepDone && !slices.Contains(v.Choices, sp) { |
| + v.Choices = append(v.Choices, sp) |
| + v.Names[sp] = specialistName(sp) |
| + } |
| + } |
| + } |
| + v.Ask = len(v.Choices) > 0 |
| + return v |
| +} |
| + |
| // workView is what the thin Tasks and Projects pages show. |
| type workView struct { |
| Tasks []taskLine |
| @@ -154,6 +223,8 @@ type workView struct { |
| Project *projectLine |
| // Needs is the Tasks page filtered to what needs the person. |
| Needs bool |
| + // Thread is the task page's thread. |
| + Thread threadView |
| } |
| // workTasks is GET /tasks: every team task, newest first, optionally |
| @@ -217,6 +288,12 @@ func (a *application) workTask(w http.ResponseWriter, r *http.Request) bool { |
| a.failure(w, r, ErrForbidden) |
| return true |
| } |
| + // The cursor first: the thread then follows every event after it. |
| + cursor, err := a.store.Chat().Cursor(ctx) |
| + if err != nil { |
| + a.failure(w, r, chatError(err)) |
| + return true |
| + } |
| t, err := a.store.Chat().Task(ctx, address, id) |
| if err != nil { |
| a.failure(w, r, chatError(err)) |
| @@ -228,6 +305,7 @@ func (a *application) workTask(w http.ResponseWriter, r *http.Request) bool { |
| return true |
| } |
| data.Thin.Task, data.Title, data.RequestID = taskLineOf(t, address), "nav.tasks", rand.Text() |
| + data.Thin.Thread, data.ChatStream = threadOf(t, address, cursor), true |
| render(w, "work_task", data) |
| return true |
| } |
| @@ -343,8 +421,40 @@ func (a *application) workTaskAction(retry bool) http.HandlerFunc { |
| // workThread adds the person's note to a task's thread. |
| func (a *application) workThread(w http.ResponseWriter, r *http.Request) { |
| id := chi.URLParam(r, "id") |
| - a.chatActionTo(w, r, "/tasks/"+id, func(ctx context.Context, address string) error { |
| - _, err := a.store.Chat().PostThread(ctx, address, id, wire.PostThread{Text: r.PostFormValue("body"), IdempotencyKey: r.PostFormValue("request_id")}) |
| - return err |
| + a.threadAction(w, r, id, func(ctx context.Context, address string) (string, error) { |
| + e, err := a.store.Chat().PostThread(ctx, address, id, wire.PostThread{Text: r.PostFormValue("body"), IdempotencyKey: r.PostFormValue("request_id")}) |
| + return e.ID, err |
| + }) |
| +} |
| + |
| +// workAsk is the task page's composer asking a specialist: the same Ask |
| +// a device makes, as the session's person. |
| +func (a *application) workAsk(w http.ResponseWriter, r *http.Request) { |
| + id := chi.URLParam(r, "id") |
| + a.threadAction(w, r, id, func(ctx context.Context, address string) (string, error) { |
| + q, err := a.store.Chat().Ask(ctx, address, id, wire.AskQuestion{Text: r.PostFormValue("body"), IdempotencyKey: r.PostFormValue("request_id"), Specialist: r.PostFormValue("specialist")}) |
| + return q.ID, err |
| }) |
| } |
| + |
| +// threadAction posts to a task's thread. chat-stream.js sends in the |
| +// background and reconciles its bubble by the returned id; without |
| +// script the form returns to the task page. |
| +func (a *application) threadAction(w http.ResponseWriter, r *http.Request, id string, act func(context.Context, string) (string, error)) { |
| + w.Header().Set("Cache-Control", "no-store") |
| + ctx, address, ok := sessionContext(r) |
| + if !ok { |
| + a.failure(w, r, ErrForbidden) |
| + return |
| + } |
| + posted, err := act(ctx, address) |
| + if err != nil { |
| + a.failure(w, r, chatError(err)) |
| + return |
| + } |
| + if strings.Contains(r.Header.Get("Accept"), "application/json") { |
| + runnerJSON(w, http.StatusOK, map[string]any{"message": map[string]string{"id": posted}}) |
| + return |
| + } |
| + http.Redirect(w, r, "/tasks/"+id, http.StatusSeeOther) |
| +} |
diff --git a/internal/headless/browser_thread_test.go b/internal/headless/browser_thread_test.go| new file mode 100644 |
| index 00000000..71fbda77 |
| --- /dev/null |
| +++ b/internal/headless/browser_thread_test.go |
| @@ -0,0 +1,80 @@ |
| +//go:build browser |
| + |
| +package headless |
| + |
| +import ( |
| + "context" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/browsertest" |
| + "github.com/chromedp/chromedp" |
| +) |
| + |
| +// Ask the implementer from the task page (Paul, 2026-11-07): the thread |
| +// has the chat's quiet composer (a click anywhere in it focuses the |
| +// message, the dock is the page's own colour) and a quiet "Asking |
| +// Engineering · change" line that follows what is typed and switches |
| +// with change. A question shows at once; its answer streams into a |
| +// thinking line labelled with the specialist and settles in place, with |
| +// no reload. At 1280 with a mouse and 390 with touch. |
| +func TestBrowserTaskThread(t *testing.T) { |
| + for _, size := range []struct { |
| + w, h int64 |
| + pointer bool |
| + }{{1280, 900, true}, {390, 844, false}} { |
| + _, inst, r := localEnv(t) |
| + r.start(t) |
| + c := inst.Cookie() |
| + p := openPage(t, inst.URL, c.Name, c.Value, size.w, size.h, size.pointer) |
| + p.send("tool:record_task:oficina/sample|Fix the README typo|teh\ntool:start_task:$task|edit:README.md|teh panes|the panes") |
| + card := taskCard("Fix the README typo") |
| + // Engineering, checks and review take a while under load. |
| + for i := 0; ; i++ { |
| + err := chromedp.Do(p.ctx, browsertest.Wait(card+`?.querySelector('[equipo-stage]')?.textContent==='Ready to merge'`)) |
| + if err == nil { |
| + break |
| + } |
| + if i == 12 { |
| + t.Fatal(err) |
| + } |
| + } |
| + var link string |
| + p.run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { |
| + var err error |
| + link, err = chromedp.Evaluate[string](card+`.querySelector('a[href^="/tasks/"]').href`)(ctx, target) |
| + return err |
| + })) |
| + p.run(chromedp.Navigate(link), browsertest.Wait(`!!document.querySelector('[data-chat-stream][data-task] #composer')`)) |
| + p.check(`(()=>{window.__nav=performance.getEntriesByType('navigation').length;return true})()`, "mark") |
| + line := `document.querySelector('[data-ask-line]').textContent` |
| + p.check(line+`==='Asking Engineering' && !document.querySelector('[data-ask-change]').hidden && document.querySelector('#chat-body').placeholder==='Ask Engineering about this work'`, "the ask line") |
| + // It follows what is typed, and change switches it. |
| + p.check(`(()=>{const i=document.querySelector('#chat-body');i.value='Review, were you unsure?';i.dispatchEvent(new Event('input'));return `+line+`==='Asking Review'})()`, "addressing Review") |
| + p.check(`(()=>{const i=document.querySelector('#chat-body');i.value='';i.dispatchEvent(new Event('input'));document.querySelector('[data-ask-change]').click();return `+line+`==='Asking Review' && document.querySelector('[data-ask-specialist]').value==='review'})()`, "change to Review") |
| + p.check(`(()=>{document.querySelector('[data-ask-change]').click();return `+line+`==='Asking Engineering' && document.querySelector('[data-ask-specialist]').value==='engineering'})()`, "change back") |
| + // The chat's composer: a click in its padding focuses the message. |
| + p.check(`(()=>{document.activeElement&&document.activeElement.blur();document.querySelector('[equipo-thread] h2').scrollIntoView({block:'start'});return true})()`, "blur") |
| + var at []float64 |
| + p.run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { |
| + var err error |
| + at, err = chromedp.Evaluate[[]float64](`(()=>{const b=document.querySelector('#composer').getBoundingClientRect();return [b.x+5,b.y+b.height/2]})()`)(ctx, target) |
| + return err |
| + })) |
| + if size.pointer { |
| + p.run(chromedp.MouseClickXY(at[0], at[1])) |
| + } else { |
| + p.run(chromedp.TapXY(at[0], at[1])) |
| + } |
| + p.run(browsertest.Wait(`document.activeElement===document.querySelector('#chat-body')`)) |
| + p.check(`(`+effectiveBackground+`)(document.querySelector('#chat-composer'))===(`+effectiveBackground+`)(document.querySelector('[equipo-thread]'))`, "the dock is not the page's colour") |
| + p.check(`getComputedStyle(document.querySelector('#chat-composer')).position==='sticky'`, "the composer is not docked") |
| + // Ask: the question at once, then the answer streams and settles. |
| + p.check(`(()=>{document.querySelector('#chat-body').value='What did you change and why? ask:git';document.querySelector('#composer').requestSubmit();return true})()`, "ask") |
| + p.check(`[...document.querySelectorAll('[equipo-thread] [equipo-message="own"] [equipo-message-body]')].some(e=>e.textContent.startsWith('What did you change'))`, "the question did not show at once") |
| + p.run(browsertest.Wait(`(()=>{const e=document.querySelector('[equipo-thread] [equipo-thinking]');if(!e)return false;e.__live=true;return e.querySelector('[data-who]').textContent==='Engineering'})()`)) |
| + p.run(browsertest.Wait(`(()=>{const a=document.querySelector('[equipo-thread] [equipo-message="incoming"][data-turn-id]');return !!a && a.__live===true && !a.hasAttribute('equipo-thinking') && a.textContent.includes('From my session: Replaced') && a.textContent.includes('The change: +')})()`)) |
| + p.check(`performance.getEntriesByType('navigation').length===window.__nav`, "the page reloaded") |
| + p.check(`document.querySelector('[data-ask-specialist]').value===''`, "the next question keeps the last choice") |
| + p.stop() |
| + } |
| +} |