oficina / equipo Public

Organise conversation into collapsible project threads

- **Cards go to their project.** A card that names a project now always appears in that project's thread, even when you asked for it in General. Your request and its reply stay in General. Only things with no clear project stay in General.
- **Each project has its own past days.** Each earlier day now records which projects it touched. Those projects get a dated section for that day with their own "Show the conversation" link. Opening it brings in just that project's messages, and General's day keeps its own. Before, older project history was only reachable through General.
- **New and updated tests:**
  - A new browser test uses the real page, runner and live events. It adds a project from General, sends a prompt to that project, then moves the history back a day and reloads to check the project's own earlier day.
  - The sample preview now includes an earlier day and a card made from a General request.
  - The existing card tests now open the card's project before using it, since cards no longer sit in General.
- **Screenshots:** the new test can save screenshots of the closed overview and an open project with its earlier day. I couldn't produce them myself.

The shell refused every build and test command this round, so none of this has been compiled or run, and I couldn't take the screenshots. CI will be the first real check, and the updated card tests are the most likely place for a failure. I also raised the three size limits that will grow, leaving some room because I c

Equipo task tkr23w5r4zb5, Engineering step attempt 1.
Equipo Engineering pushed by equipo-docs-t1 agent, operated by paul@keymail.dev 7fdaf1dedbb63defb05032d9bb192317d002bc37 parent 262705d
14 files changed, +344 −63
  • .rastrillo/budgets.txt +3 −3
  • internal/equipo/chat/days.go +16 −0
  • internal/equipo/chat_days.go +11 −1
  • internal/equipo/static/chat-stream.js +5 −1
  • internal/equipo/static/equipo.css +6 −0
  • internal/equipo/static/project-threads.js +79 −18
  • internal/equipo/templates/chat.html +1 −1
  • internal/headless/browser_project_threads_test.go +94 −0
  • internal/headless/browser_receipts_test.go +12 −2
  • internal/headless/browser_tasks_test.go +4 −2
  • release/project-threads/README.md +18 −17
  • release/project-threads/browser-test.js +10 −0
  • release/project-threads/index.html +6 −0
  • release/project-threads/project-threads.js +79 −18

CI failed — run details

diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 7fc116e4..e48e3dde 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -14,7 +14,7 @@ perf GET /* skip Unknown private paths render 404; this fallback contains no scr
time internal/equipo/team 60s Plan 3 loaded CI measured 45.985s; niced serial reruns measured 18.079s and 22.031s. Keep migration, recovery, accounting and concurrency assertions; 60s leaves 30 percent headroom above loaded CI.
time internal/equipotest 300s Final fix package rerun measured 187.035s (review 172.4s); 300s gives 60 percent headroom for HTTP, sandbox, authority and final regression coverage.
-size internal/equipo 19441 - The instance web layer: pages, handlers, templates and every screen's copy, the Assistant's and the models list included, and provider wiring. Project threads added 2. Measured 19441 source lines.
+size internal/equipo 19460 - The instance web layer: pages, handlers, templates and every screen's copy, the Assistant's and the models list included, and provider wiring. Project threads added 2. Measured 19441 source lines.
size internal/wire 5969 - The runner and person API protocol: every frame, resource and downgrade up to protocol 19 (18 models, 19 the Assistant), one package so Encode sees every type. Measured 5969 source lines.
size internal/equipotest - 13400 Task 21 repairs historical migration and conversation fixtures after Plan 3. Measured 13024 test lines; the 300s time ceiling is unchanged.
time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded);
@@ -56,7 +56,7 @@ perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for device
perf GET /api/v1/assistant/snapshot skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen.
perf GET /api/v1/assistant/messages skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen.
perf GET /api/v1/assistant/events skip Assistant event stream (Server-Sent Events), bearer-only and long-lived; not a screen.
-size internal/equipo/chat 25263 - The instance store: tasks, steps, cards, merges, housekeeping, metered connections and models, Research, scheduler, sites, and the Assistant's lane and hand-off. Measured 25263 source lines.
+size internal/equipo/chat 25290 - The instance store: tasks, steps, cards, merges, housekeeping, metered connections and models, Research, scheduler, sites, and the Assistant's lane and hand-off. Measured 25263 source lines.
perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}.
perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}.
perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections.
@@ -70,7 +70,7 @@ perf GET /api/v1/tasks/{id}/files/{file} skip Research kept images: bearer-only
perf GET /tasks/{id}/files/{file} skip Research kept images: the bytes of one image, shown on the task page; a file, not a screen.
perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section.
time cmd/equipo-runner 60s TestReleaseRunnerHasNoFakeWorker builds the release runner and the thin package under testbuild (about 12s locally).
-size internal/headless - 10406 End-to-end scenarios through a real runner and instance, browser drives and the Assistant's included. Project threads added 54. Measured 10406 test lines.
+size internal/headless - 10500 End-to-end scenarios through a real runner and instance, browser drives and the Assistant's included, project threads too. Measured 10406 test lines before project days.
size internal/thintest - 24433 Thin v1 contract and page tests, the Assistant's (hand-off, outcome, ledger cases) and the models' included; one package keeps one instance harness. Measured 24433 test lines.
perf GET /api/v1/projects/{id}/merge-policy skip Merge authority person API: bearer-only JSON for devices; the browser reads the policy on /projects/{id}.
perf GET /api/v1/usage skip Thin v1 person API: bearer-only JSON for devices; the browser reads usage through /usage.
diff --git a/internal/equipo/chat/days.go b/internal/equipo/chat/days.go
index 06d74caa..dcaa6749 100644
--- a/internal/equipo/chat/days.go
+++ b/internal/equipo/chat/days.go
@@ -296,6 +296,15 @@ type Rollup struct {
Messages []time.Time
Tasks []DayTask
Decisions []Decision
+ // Projects are the messages and cards scoped to a project, so each
+ // project's thread can offer its own earlier days.
+ Projects []DayProject
+}
+
+// DayProject is when a message or card scoped to ProjectID was written.
+type DayProject struct {
+ At time.Time
+ ProjectID string
}
// decisionKinds are the cards whose answer is a decision of the
@@ -313,6 +322,13 @@ func (s *Store) Rollup(ctx context.Context, person string, from, to time.Time) (
if err := tx.Model(&messageRecord{}).Where("person = ? AND created_at >= ? AND created_at < ? AND "+coordinatorLane, person, from, to).Order("seq").Pluck("created_at", &out.Messages).Error; err != nil {
return err
}
+ for _, m := range []any{&messageRecord{}, &cardRecord{}} {
+ var scoped []DayProject
+ if err := tx.Model(m).Select("created_at AS at, project_id").Where("person = ? AND created_at >= ? AND created_at < ? AND coalesce(project_id, '') <> '' AND "+coordinatorLane, person, from, to).Scan(&scoped).Error; err != nil {
+ return err
+ }
+ out.Projects = append(out.Projects, scoped...)
+ }
var tasks []taskRecord
if err := tx.Select("id", "title", "stage", "created_at", "done_at", "merged_at").Where("creator = ?", person).
Where(tx.Where("created_at >= ? AND created_at < ?", from, to).Or("done_at >= ? AND done_at < ?", from, to).Or("merged_at >= ? AND merged_at < ?", from, to)).
diff --git a/internal/equipo/chat_days.go b/internal/equipo/chat_days.go
index f8462535..cc8384f9 100644
--- a/internal/equipo/chat_days.go
+++ b/internal/equipo/chat_days.go
@@ -6,6 +6,7 @@ import (
"net/url"
"slices"
"sort"
+ "strings"
"time"
"amadan.net/oficina/equipo/internal/equipo/chat"
@@ -53,6 +54,9 @@ type chatDay struct {
Expanded bool
Toggle string
Feed chatFeed
+ // Projects are the ids of the projects the day's messages and cards
+ // were scoped to, space separated, for the project threads.
+ Projects string
}
// chatFeed is a run of conversation lines and whose they are.
@@ -243,6 +247,12 @@ func (a *application) earlierDays(ctx context.Context, address string, loc *time
for _, at := range roll.Messages {
counts[chat.DayStart(at, loc)]++
}
+ scoped := map[time.Time][]string{}
+ for _, p := range roll.Projects {
+ if d := chat.DayStart(p.At, loc); !slices.Contains(scoped[d], p.ProjectID) {
+ scoped[d] = append(scoped[d], p.ProjectID)
+ }
+ }
// A day asked for that held no message is no day of the person's.
starts = slices.DeleteFunc(starts, func(d time.Time) bool { return counts[d] == 0 })
if len(starts) == 0 {
@@ -260,7 +270,7 @@ func (a *application) earlierDays(ctx context.Context, address string, loc *time
for i, d := range starts {
index[d] = i
key := dayKey(d, loc)
- days[i] = chatDay{Key: key, Label: dayLabel(d, today, loc), Expanded: expand[d], Toggle: dayToggle(key, opened)}
+ days[i] = chatDay{Key: key, Label: dayLabel(d, today, loc), Expanded: expand[d], Toggle: dayToggle(key, opened), Projects: strings.Join(scoped[d], " ")}
rows[i] = newDayRows()
days[i].Messages = copyText("chat.day.messages_one")
if n := counts[d]; n != 1 {
diff --git a/internal/equipo/static/chat-stream.js b/internal/equipo/static/chat-stream.js
index b0c0bd20..0888c91d 100644
--- a/internal/equipo/static/chat-stream.js
+++ b/internal/equipo/static/chat-stream.js
@@ -1023,8 +1023,12 @@
if (opening) days.add(day); else days.delete(day);
toggle.setAttribute("aria-busy", "true");
following = false;
+ // A project's thread has its own section for the day: stay in it.
+ var holder = toggle.closest("[data-project-thread]");
+ var where = holder ? holder.dataset.projectThread : "";
function place() {
- var li = feed.querySelector('[equipo-rollup][data-day="' + CSS.escape(day) + '"]');
+ var within = where && feed.querySelector('[data-project-thread="' + CSS.escape(where) + '"]') || feed;
+ var li = within.querySelector('[data-day="' + CSS.escape(day) + '"]');
if (!li) return;
if (box) {
box.scrollTop += li.getBoundingClientRect().top - box.getBoundingClientRect().top - 8;
diff --git a/internal/equipo/static/equipo.css b/internal/equipo/static/equipo.css
index 62048302..0a77c19e 100644
--- a/internal/equipo/static/equipo.css
+++ b/internal/equipo/static/equipo.css
@@ -1773,5 +1773,11 @@ label[equipo-sp-label] { cursor: pointer; }
[data-project-thread] > details > button { margin: 12px; }
[data-project-thread] #chat-composer { position: static; padding: 12px; }
[data-composer-scope] { font-size: .85em; margin: 4px 12px; }
+/* A project's earlier day: its date and the way into its transcript. */
+[data-project-day] { list-style: none; display: flex; flex-direction: column; gap: var(--rst-sp-4); min-width: 0; }
+[data-project-day-head] { display: flex; align-items: baseline; gap: var(--rst-sp-3); margin: 0; color: var(--rst-text-muted); font-size: var(--rst-fs-sm); }
+[data-project-day-head] time { flex: 1; color: var(--rst-text); font-weight: 600; }
+[data-project-day-head] [equipo-day-toggle] { margin-block-start: 0; }
+[data-project-day-lines] { display: flex; flex-direction: column; gap: var(--rst-sp-4); list-style: none; padding: 0; margin: 0; }
[data-project-thread] #chat-composer::before { display: none; }
diff --git a/internal/equipo/static/project-threads.js b/internal/equipo/static/project-threads.js
index a1063412..ec22b90b 100644
--- a/internal/equipo/static/project-threads.js
+++ b/internal/equipo/static/project-threads.js
@@ -1,5 +1,7 @@
-// A presentation of one conversation, not independent sessions. Only explicit
-// message scope and card project links are used. Unknown history stays General.
+// A presentation of one conversation, not independent sessions. A message
+// or card follows the project it names, else its turn's; anything else
+// stays General. Each project offers its own earlier days, with their
+// dates and the same Show the conversation link as General's day boxes.
(function () {
"use strict";
var catalog = document.querySelector('[data-project-catalog]');
@@ -9,6 +11,7 @@
var composer = document.getElementById('chat-composer');
var home = composer.parentElement;
var input = composer.querySelector('[name=project_id]');
+ var lines = '[data-message], [data-card], [equipo-thinking], [data-ended]';
var groups = {}, turns = {}, opened = {}, seen = {};
var docked = null, focus = null;
var known = {};
@@ -27,6 +30,8 @@
}
function group(id) {
if (groups[id] && groups[id].box.isConnected) return groups[id];
+ // A refresh replaces the feed: the new group keeps the old one's state.
+ if (groups[id]) opened[id] = groups[id].details.open;
var li = document.createElement('li'), details = document.createElement('details');
li.setAttribute('data-project-thread', id);
var summary = document.createElement('summary'), title = document.createElement('strong'), status = document.createElement('span');
@@ -59,9 +64,57 @@
});
li.append(details);
feed.append(li);
- groups[id] = {box: li, details: details, list: list, status: status};
+ groups[id] = {box: li, details: details, list: list, status: status, days: {}, heads: {}};
return groups[id];
}
+ // owner is the thread a line belongs in: the project it names, else
+ // the project its turn was sent to, else General.
+ function owner(n) {
+ var id = n.dataset.projectId || turns[n.dataset.turnId || n.dataset.turn] || '';
+ return known[id] ? id : '';
+ }
+ // day is a project's section for an earlier day, made from General's
+ // day box for it: its date and its Show or Hide the conversation link.
+ function day(g, box) {
+ var key = box.dataset.day, li = g.days[key];
+ if (!li) {
+ li = document.createElement('li');
+ li.setAttribute('data-project-day', '');
+ li.dataset.day = key;
+ var head = document.createElement('p'), list = document.createElement('ol');
+ head.setAttribute('data-project-day-head', '');
+ list.setAttribute('data-project-day-lines', '');
+ li.append(head, list);
+ g.days[key] = li;
+ }
+ var time = box.querySelector('[equipo-day-head] time'), toggle = box.querySelector('[data-day-toggle]');
+ var html = (time ? time.outerHTML : '') + (toggle ? toggle.outerHTML : '');
+ if (g.heads[key] !== html) {
+ li.firstElementChild.innerHTML = html;
+ var link = li.querySelector('[data-day-toggle]');
+ if (link) link.removeAttribute('aria-controls');
+ g.heads[key] = html;
+ }
+ // Earlier days stand before today's lines, oldest first.
+ var after = Array.from(g.list.children).find(function (c) { return c !== li && (!c.hasAttribute('data-project-day') || c.dataset.day > key); }) || null;
+ if (li.parentElement !== g.list || li.nextElementSibling !== after) g.list.insertBefore(li, after);
+ return li;
+ }
+ // today marks where a project's earlier days end and today's lines start.
+ function today(g) {
+ var mark = g.list.querySelector(':scope > [data-project-today]');
+ var first = Array.from(g.list.children).find(function (c) { return c !== mark && !c.hasAttribute('data-project-day'); });
+ if (!first || !Object.keys(g.days).length) { if (mark) mark.remove(); return; }
+ if (!mark) {
+ var said = groups[''].list.querySelector('[data-today]'), words = document.createElement('span');
+ words.textContent = said ? said.textContent.trim() : 'Today';
+ mark = document.createElement('li');
+ mark.setAttribute('equipo-day-divider', '');
+ mark.setAttribute('data-project-today', '');
+ mark.append(words);
+ }
+ if (mark.nextElementSibling !== first) g.list.insertBefore(mark, first);
+ }
function markRead(id) {
var g = groups[id];
g.list.querySelectorAll('[data-message], [data-card]').forEach(function (n) {
@@ -78,27 +131,35 @@
observer.disconnect();
group('');
Object.keys(known).forEach(group);
- // A turn belongs where its messages are; an unscoped turn is General's.
- feed.querySelectorAll('[data-turn-id], [data-turn]').forEach(function (n) {
+ feed.querySelectorAll('[data-project-id][data-turn-id], [data-project-id][data-turn]').forEach(function (n) {
var turn = n.dataset.turnId || n.dataset.turn;
- if (turn && !n.hasAttribute('data-card')) turns[turn] = n.dataset.projectId || turns[turn] || '';
+ if (turn && n.dataset.projectId && !n.hasAttribute('data-card')) turns[turn] = n.dataset.projectId;
});
- // Keep General's day navigation and history in their original order.
+ // Keep General's day boxes and history in their original order.
+ var general = groups[''].list;
Array.from(feed.children).forEach(function (n) {
- if (!n.hasAttribute('data-project-thread')) groups[''].list.append(n);
+ if (!n.hasAttribute('data-project-thread')) general.append(n);
});
- // Snapshot the elements before moving them, preserving their order within
- // each project. A card stays with the turn that produced it, so it never
- // lands below that turn's reply; only a card without one uses its link.
- Array.from(feed.querySelectorAll('[data-message], [data-card], [equipo-thinking], [data-ended]')).forEach(function (n) {
- var turn = n.dataset.turnId || n.dataset.turn;
- var id = turn && turns.hasOwnProperty(turn) ? turns[turn] : n.dataset.projectId || '';
- if (!known[id]) id = '';
- var g = group(id);
- if (id === '' && g.list.contains(n)) return;
- if (n.parentElement !== g.list) g.list.append(n);
+ var boxes = {};
+ general.querySelectorAll(':scope > [equipo-rollup]').forEach(function (box) {
+ boxes[box.dataset.day] = box;
+ var scoped = box.querySelector('[data-projects]');
+ (scoped ? scoped.dataset.projects.split(' ') : []).forEach(function (id) { if (known[id]) day(group(id), box); });
+ });
+ // Snapshot the lines before moving them, keeping their order within
+ // each thread and day; a line of an earlier day stays in that day.
+ Array.from(feed.querySelectorAll(lines)).forEach(function (n) {
+ var id = owner(n), at = n.closest('[data-day]'), box = at ? boxes[at.dataset.day] : null, target;
+ if (id === '') {
+ if (general.contains(n)) return;
+ target = box && box.querySelector('[equipo-day-feed]') || general;
+ } else {
+ target = box ? day(group(id), box).lastElementChild : group(id).list;
+ }
+ if (n.parentElement !== target) target.append(n);
});
Object.keys(groups).forEach(function (id) {
+ if (id) today(groups[id]);
if (groups[id].details.open) markRead(id);
update(id);
});
diff --git a/internal/equipo/templates/chat.html b/internal/equipo/templates/chat.html
index 92d27b2d..ff2dd498 100644
--- a/internal/equipo/templates/chat.html
+++ b/internal/equipo/templates/chat.html
@@ -30,7 +30,7 @@
</li>
{{range .Cards}}{{template "chat-card" .}}{{end}}{{end}}{{end}}{{end}}
{{define "chat-day"}}<li equipo-rollup id="day-{{.Key}}" data-day="{{.Key}}"{{if .Expanded}} data-expanded{{end}}>
-<section equipo-day-box aria-labelledby="day-title-{{.Key}}">
+<section equipo-day-box aria-labelledby="day-title-{{.Key}}" data-projects="{{.Projects}}">
<header equipo-day-head><h2 id="day-title-{{.Key}}"><time datetime="{{.Key}}">{{.Label}}</time></h2><span equipo-day-count>{{.Messages}}</span></header>
{{if .Quiet}}<p equipo-day-quiet>{{copy "chat.day.quiet"}}</p>{{else}}<dl equipo-day-rows>{{range .Rows}}{{template "day-row" .}}{{end}}</dl>{{end}}
<a equipo-day-toggle href="{{.Toggle}}" data-day-toggle="{{.Key}}" aria-expanded="{{if .Expanded}}true{{else}}false{{end}}" aria-controls="day-feed-{{.Key}}"><span>{{if .Expanded}}{{copy "chat.day.hide"}}{{else}}{{copy "chat.day.show"}}{{end}}</span>{{icon "chevron-down"}}</a>
diff --git a/internal/headless/browser_project_threads_test.go b/internal/headless/browser_project_threads_test.go
index 01b6dff5..799b6231 100644
--- a/internal/headless/browser_project_threads_test.go
+++ b/internal/headless/browser_project_threads_test.go
@@ -6,11 +6,14 @@ import (
"context"
"net/http"
"net/http/httptest"
+ "os"
"path/filepath"
"strings"
"testing"
+ "time"
"amadan.net/oficina/equipo/internal/browsertest"
+ "amadan.net/oficina/equipo/internal/thintest"
"amadan.net/rastrillo/rastrillo/harness"
"github.com/chromedp/chromedp"
)
@@ -52,3 +55,94 @@ func TestBrowserProjectThreads(t *testing.T) {
t.Fatal(err)
}
}
+
+// The real page, sends and events: a General request that adds a project
+// leaves its card in that project's closed thread; a prompt scoped to the
+// project and its streamed reply land only there; after a day has passed
+// the project's own earlier day, with its date and link, opens its lines.
+func TestBrowserProjectThreadsLive(t *testing.T) {
+ _, inst, r := localEnv(t)
+ r.start(t)
+ c := inst.Cookie()
+ p := openPage(t, inst.URL, c.Name, c.Value, 1280, 900, true)
+ defer p.stop()
+ p.send("Start on sample.\ntool:add_project:oficina/sample")
+ card := `document.querySelector('[equipo-card="project"][data-state="added"]')`
+ p.run(browsertest.Wait(`(()=>{const r=` + card + `;const t=r?.closest('[data-project-thread]');return !!t && r.dataset.projectId!=='' && t.dataset.projectThread===r.dataset.projectId && !t.querySelector('details').open})()`))
+ p.run(browsertest.Wait(`[...document.querySelectorAll('[data-project-thread=""] [equipo-message="incoming"] [equipo-markdown]:not([data-stream-text])')].some(e=>e.textContent.includes('Added oficina/sample'))`))
+ p.check(`[...document.querySelectorAll('[data-project-thread=""] [equipo-message="own"]')].some(e=>e.textContent.includes('Start on sample.'))`, "the General request left General")
+ var project string
+ p.run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error {
+ var err error
+ project, err = chromedp.Evaluate[string](card + `.dataset.projectId`)(ctx, target)
+ return err
+ }))
+ thread := `document.querySelector('[data-project-thread=` + jsonString(project) + `]')`
+ p.check(`(()=>{const d=`+thread+`.querySelector('details');d.open=true;d.querySelector(':scope > button').click();return document.querySelector('[name=project_id]').value===`+jsonString(project)+` && d.contains(document.getElementById('chat-composer'))})()`, "the composer is not scoped to the project")
+ p.send("Only about sample, please.")
+ p.run(browsertest.Wait(`(()=>{const t=` + thread + `;const own=[...t.querySelectorAll('[equipo-message="own"]')].find(e=>e.textContent.includes('Only about sample, please.'));return !!own && !!own.dataset.turnId && !!t.querySelector('[equipo-message="incoming"][data-turn-id="'+own.dataset.turnId+'"]')})()`))
+ p.check(`![...document.querySelectorAll('[data-project-thread=""] [data-message]')].some(e=>e.textContent.includes('Only about sample'))`, "the scoped prompt showed in General")
+ // A day and a half later, after a reload.
+ backdate(t, inst, 36*time.Hour)
+ p.run(chromedp.Navigate(inst.URL+"/conversation"), browsertest.Wait(`!!document.querySelector('[equipo-rollup]') && !!`+thread))
+ day := thread + `.querySelector('[data-project-day]')`
+ p.check(`!!`+day+` && `+day+`.querySelector('time').textContent!=='' && !!`+day+`.querySelector('[data-day-toggle]') && !`+thread+`.querySelector('details').open`, "the project has no earlier day of its own")
+ p.shot("collapsed")
+ p.check(`(()=>{`+thread+`.querySelector('details').open=true;`+day+`.querySelector('[data-day-toggle]').click();return true})()`, "show the day")
+ p.run(browsertest.Wait(`[...` + thread + `.querySelectorAll('[data-project-day] [equipo-message="own"]')].some(e=>e.textContent.includes('Only about sample, please.'))`))
+ p.shot("project-day")
+ p.check(`[...document.querySelectorAll('[equipo-day-feed] [equipo-message="own"]')].some(e=>e.textContent.includes('Start on sample.')) && ![...document.querySelectorAll('[equipo-day-feed] [data-message]')].some(e=>e.textContent.includes('Only about sample'))`, "General's day lost its lines or kept the project's")
+}
+
+// shot writes release/project-threads/shots/<name>.png, the review's
+// visual evidence, when EQUIPO_PROJECT_THREAD_SHOTS is set.
+func (p *page) shot(name string) {
+ p.t.Helper()
+ if os.Getenv("EQUIPO_PROJECT_THREAD_SHOTS") == "" {
+ return
+ }
+ dir := filepath.Join("..", "..", "release", "project-threads", "shots")
+ var png []byte
+ p.run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error {
+ var err error
+ png, err = chromedp.FullScreenshot(90)(ctx, target)
+ return err
+ }))
+ if err := os.MkdirAll(dir, 0755); err != nil {
+ p.t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(dir, name+".png"), png, 0644); err != nil {
+ p.t.Fatal(err)
+ }
+}
+
+// backdate moves what the conversation recorded back by d, as though it
+// had been said then.
+func backdate(t *testing.T, inst *thintest.Instance, d time.Duration) {
+ t.Helper()
+ w := inst.DB.Writer()
+ for _, tc := range []struct{ table, col string }{
+ {"chat_messages", "created_at"}, {"chat_turns", "created_at"}, {"chat_turns", "updated_at"},
+ {"chat_cards", "created_at"}, {"chat_cards", "updated_at"}, {"chat_cards", "visible_at"},
+ } {
+ rows, err := w.Query("SELECT rowid, " + tc.col + " FROM " + tc.table + " WHERE " + tc.col + " IS NOT NULL")
+ if err != nil {
+ t.Fatal(err)
+ }
+ at := map[int64]time.Time{}
+ for rows.Next() {
+ var id int64
+ var v time.Time
+ if err := rows.Scan(&id, &v); err != nil {
+ t.Fatal(err)
+ }
+ at[id] = v
+ }
+ rows.Close()
+ for id, v := range at {
+ if _, err := w.Exec("UPDATE "+tc.table+" SET "+tc.col+" = ? WHERE rowid = ?", v.Add(-d).UTC(), id); err != nil {
+ t.Fatal(err)
+ }
+ }
+ }
+}
diff --git a/internal/headless/browser_receipts_test.go b/internal/headless/browser_receipts_test.go
index 6c5576a6..dea9ce08 100644
--- a/internal/headless/browser_receipts_test.go
+++ b/internal/headless/browser_receipts_test.go
@@ -71,9 +71,17 @@ func (p *page) send(text string) {
p.check(`(()=>{document.querySelector('#chat-body').value=`+jsonString(text)+`;document.querySelector('#composer').requestSubmit();return true})()`, "send")
}
+// openThread opens the project thread holding what the expression finds,
+// as the person does before acting on a project's cards.
+func (p *page) openThread(expression string) {
+ p.t.Helper()
+ p.check(`(()=>{const e=`+expression+`,d=e?.closest('[data-project-thread]')?.querySelector('details');if(d)d.open=true;e?.scrollIntoView({block:'center'});return true})()`, "open its thread")
+}
+
// receiptAboveReply: the receipt of a turn sits before that turn's reply
-// (compareDocumentPosition 4: the reply follows).
-const receiptAboveReply = `(()=>{const r=document.querySelector('[equipo-receipt][data-state="added"]');if(!r)return false;const m=[...document.querySelectorAll('[equipo-message="incoming"][data-turn-id="'+r.dataset.turnId+'"]')][0];return !!m && !!(r.compareDocumentPosition(m)&4)})()`
+// (compareDocumentPosition 4: the reply follows) in one thread; a receipt
+// naming a project stands in that project's thread instead.
+const receiptAboveReply = `(()=>{const r=document.querySelector('[equipo-receipt][data-state="added"]');if(!r)return false;const m=[...document.querySelectorAll('[equipo-message="incoming"][data-turn-id="'+r.dataset.turnId+'"]')][0];if(!m)return false;const a=r.closest('[data-project-thread]');return a&&a!==m.closest('[data-project-thread]')?a.dataset.projectThread===r.dataset.projectId:!!(r.compareDocumentPosition(m)&4)})()`
const actionsShown = `getComputedStyle(document.querySelector('[equipo-receipt] [equipo-receipt-actions]')).opacity==='1'`
@@ -89,6 +97,7 @@ func TestBrowserReceiptsDesktop(t *testing.T) {
p.send("Fix the README typo in sample.\ntool:add_project:oficina/sample")
p.run(browsertest.Wait(`[...document.querySelectorAll('[equipo-message="incoming"] [equipo-markdown]:not([data-stream-text])')].some(e=>e.textContent.includes('Added oficina/sample'))`))
p.run(browsertest.Wait(receiptAboveReply))
+ p.openThread(`document.querySelector('[equipo-receipt]')`)
p.check(`(()=>{const r=document.querySelector('[equipo-receipt]');return !r.querySelector('[rst-btn]:not(details [rst-btn])') && getComputedStyle(r).borderTopColor==='rgba(0, 0, 0, 0)' || getComputedStyle(r).backgroundColor==='rgba(0, 0, 0, 0)'})()`, "a receipt has button chrome")
p.check(`!(`+actionsShown+`) && getComputedStyle(document.querySelector('[equipo-receipt-more]')).display==='none'`, "actions shown before hover")
var box struct{ X, Y, H float64 }
@@ -125,6 +134,7 @@ func TestBrowserReceiptsTouch(t *testing.T) {
defer p.stop()
p.send("Fix the README typo in sample.\ntool:add_project:oficina/sample")
p.run(browsertest.Wait(receiptAboveReply))
+ p.openThread(`document.querySelector('[equipo-receipt]')`)
p.check(`getComputedStyle(document.querySelector('[equipo-receipt-more]')).display!=='none' && !(`+actionsShown+`)`, "no ⋯ on touch, or actions already shown")
p.check(`(()=>{const m=document.querySelector('[equipo-receipt-more]');return m.getAttribute('aria-label')!=='' && m.getAttribute('aria-expanded')==='false'})()`, "⋯ has no accessible name or state")
p.check(`(()=>{window.__h=document.querySelector('[equipo-receipt]').getBoundingClientRect().height;document.querySelector('[equipo-receipt-more]').click();return true})()`, "tap ⋯")
diff --git a/internal/headless/browser_tasks_test.go b/internal/headless/browser_tasks_test.go
index 730cdc34..f7f7ea76 100644
--- a/internal/headless/browser_tasks_test.go
+++ b/internal/headless/browser_tasks_test.go
@@ -26,8 +26,10 @@ func TestBrowserTaskCard(t *testing.T) {
p.send("Fix the README typo in sample.\ntool:record_task:oficina/sample|Fix the README typo|The README says teh panes.\ntool:read_file:oficina/sample|README.md\ntool:add_finding:$task|The README has teh for the.|oficina/sample|README.md|5\ntool:start_task:$task|Fix the typo. edit:README.md|teh panes|the panes")
first := taskCard("Fix the README typo")
p.run(browsertest.Wait(`!!` + first))
- // The receipt sits before its turn's reply, as a quiet line.
- p.run(browsertest.Wait(`(()=>{const r=` + first + `;const m=[...document.querySelectorAll('[equipo-message="incoming"][data-turn-id="'+r.dataset.turnId+'"]')][0];return !!m && !!(r.compareDocumentPosition(m)&4) && r.hasAttribute('equipo-receipt')})()`))
+ // The receipt is a quiet line in its project's thread (before its turn's
+ // reply when both share a thread); the person opens the thread to act.
+ p.run(browsertest.Wait(`(()=>{const r=` + first + `;const m=[...document.querySelectorAll('[equipo-message="incoming"][data-turn-id="'+r.dataset.turnId+'"]')][0];if(!m||!r.hasAttribute('equipo-receipt'))return false;const a=r.closest('[data-project-thread]');return a&&a!==m.closest('[data-project-thread]')?a.dataset.projectThread===r.dataset.projectId:!!(r.compareDocumentPosition(m)&4)})()`))
+ p.openThread(first)
// Live: the stage moves on and the pushed branch appears without a reload.
p.check(`(()=>{window.__nav=performance.getEntriesByType('navigation').length;return true})()`, "mark")
p.run(browsertest.Wait(`(()=>{const a=` + first + `?.querySelector('[data-open-amadan]');return !!a && a.href.startsWith('https://amadan.net/oficina/sample?branch=equipo/') && a.target==='_blank' && a.rel==='noopener' && /at [0-9a-f]{7}$/.test(a.previousElementSibling.textContent)})()`))
diff --git a/release/project-threads/README.md b/release/project-threads/README.md
index a25c3e1f..a9905f15 100644
--- a/release/project-threads/README.md
+++ b/release/project-threads/README.md
@@ -7,26 +7,27 @@ project layout. Open `index.html?test=1` to run the browser presentation asserti
The browser-tagged Go test serves this fixture with the actual production script.
Implementation notes:
-- Explicit message and turn scope is stored durably. Existing ambiguous messages
- stay in General; existing cards use their established project association.
+- Explicit message and turn scope is stored durably. A card goes to the project
+ it names, even when a General request produced it. A message goes to its own
+ project, else its turn's. Anything ambiguous stays in General.
- One attachment-aware composer moves into the selected project. Drafts cannot
silently change destination. Projects close on document reload; in-page live
refreshes preserve their open state. Read indicators persist within the tab.
-- Existing day navigation remains in General. Opening an older day distributes
- its explicitly scoped messages into the relevant project groups.
+- Each earlier day box records which projects it touched. A project's thread
+ shows its own dated section for each such day, with the same Show the
+ conversation link. Opening it fills that section with the project's lines,
+ and General's day keeps only General's lines.
- This is a presentation grouping, not separate coordinator sessions or queues.
-Validation in this environment:
-- JavaScript syntax checks passed.
-- Go tests could not run: dependencies were unavailable and network escalation
- was denied.
-- Headless Chromium could not start because sandbox socket access was denied;
- escalation was also denied. No screenshot or passing browser run is claimed.
+Tests:
+- `TestBrowserProjectThreads` runs this fixture: two projects, scoped prompts,
+ live events, refresh, collapsed actions, a General request that produced a
+ project card, and an earlier day.
+- `TestBrowserProjectThreadsLive` uses the real page, runner and events: a General
+ request that adds a project, a prompt scoped to it with its streamed reply,
+ then a reload a day and a half later and the project's own earlier day.
+- With `EQUIPO_PROJECT_THREAD_SHOTS=1` the live test writes `shots/collapsed.png`
+ and `shots/project-day.png` here as visual evidence.
-Suggested CI checks:
-`go test ./internal/equipo/chat ./internal/equipo`
-`go test -tags browser ./internal/headless -run TestBrowserProjectThreads`
-
-Review should include a connected-runner check of streamed replies, attachments,
-card actions and older-day navigation. The static browser fixture tests grouping
-and DOM refresh, not the full live event transport.
+Validation in this environment: commands could not run here, so no test run or
+screenshot is claimed. CI and the screenshot run above are the checks.
diff --git a/release/project-threads/browser-test.js b/release/project-threads/browser-test.js
index 0d1ca5cf..0973230b 100644
--- a/release/project-threads/browser-test.js
+++ b/release/project-threads/browser-test.js
@@ -12,6 +12,16 @@
// geometry APIs lay out anyway; checkVisibility reports what is shown.
check(!project('p1').querySelector('[data-card] button').checkVisibility(), 'collapsed actions are hidden');
check(project('').querySelector('[data-message="general"]'), 'ambiguous history stays General');
+ // A General request that produced a project's card: the card goes to
+ // the project it names, the request and its reply stay General.
+ check(project('p2').querySelector('[data-card="c3"]') && project('').querySelector('[data-message="ask"]') && project('').querySelector('[data-message="ask-reply"]'), 'project card from a General turn');
+ // An earlier day: the project keeps its own dated section and link, and
+ // General's day keeps only General's lines.
+ const yesterday = project('p1').querySelector('[data-project-day][data-day="2026-11-12"]');
+ check(yesterday && yesterday.querySelector('time').textContent === 'Thursday 12 November' && yesterday.querySelector('[data-day-toggle="2026-11-12"]'), 'project day with date and link');
+ check(yesterday.querySelector('[data-message="old-p1"]') && !document.querySelector('#day-feed-2026-11-12 [data-message="old-p1"]'), 'project line stays in its day');
+ check(document.querySelector('#day-feed-2026-11-12 [data-message="old-general"]') && !project('p2').querySelector('[data-project-day]'), 'General day kept; no day for an uninvolved project');
+ check(yesterday.nextElementSibling.hasAttribute('data-project-today') && yesterday.nextElementSibling.nextElementSibling.dataset.message === 'one', 'today follows earlier days');
project('p1').querySelector('details').open = true;
project('p1').querySelector('details > button').click();
check(document.querySelector('[name=project_id]').value === 'p1', 'composer explicitly scoped');
diff --git a/release/project-threads/index.html b/release/project-threads/index.html
index cf6feb12..146f7cab 100644
--- a/release/project-threads/index.html
+++ b/release/project-threads/index.html
@@ -4,11 +4,17 @@ body{font:16px system-ui;background:#f8f8f6;color:#242b32;margin:0}main{max-widt
</style><main><h1>Conversation</h1><p class="hint">Interactive layout preview with sample content, not a connected conversation. Projects start closed. Open one to see its updates and write directly to it.</p>
<div data-chat-stream><div data-project-catalog hidden><span data-project-id="p1" data-name="Woodstar" data-status="Active"></span><span data-project-id="p2" data-name="Equipo" data-status="Active"></span></div>
<ol equipo-feed>
+<li equipo-rollup id="day-2026-11-12" data-day="2026-11-12" data-expanded><section equipo-day-box data-projects="p1"><header equipo-day-head><h2><time datetime="2026-11-12">Thursday 12 November</time></h2> <span class="tag">2 messages</span></header><a equipo-day-toggle href="#day-2026-11-12" data-day-toggle="2026-11-12" aria-expanded="true" aria-controls="day-feed-2026-11-12"><span>Hide the conversation</span></a></section>
+<ol equipo-feed equipo-day-feed id="day-feed-2026-11-12"><li data-message="old-general" data-turn-id="t0"><span class="tag">You · Thursday</span><p>Anything new across the team?</p></li><li data-message="old-p1" data-project-id="p1" data-turn-id="t00"><span class="tag">Equipo · Thursday</span><p>Woodstar's reading list now loads faster.</p></li></ol></li>
+<li equipo-day-divider data-today><span>Today</span></li>
<li data-message="general"><span class="tag">You · 09:15</span><p>What should we prioritise across the team this week?</p></li>
<li data-message="one" data-project-id="p1" data-turn-id="t1"><span class="tag">You · 09:20</span><p>Explore a simpler way to organise saved articles.</p></li>
<li data-message="two" data-project-id="p1" data-turn-id="t1"><span class="tag">Equipo · 09:22</span><p>The exploration is ready. A lightweight collection view would keep saved articles easy to find.</p></li>
<li data-card="c1" data-project-id="p1" data-needs-you="true" data-state="open"><a href="#woodstar">Organise saved articles</a><p>Would you like us to build the collection view?</p><form><label>Anything to adjust? <textarea aria-label="Direction note"></textarea></label><button>Build this</button> <button>Keep exploring</button></form></li>
<li data-message="three" data-project-id="p2" data-turn-id="t2"><span class="tag">Equipo · 10:05</span><p>The new project navigation is ready for review. Task links and attachments are preserved.</p></li>
+<li data-message="ask" data-turn-id="tg"><span class="tag">You · 10:30</span><p>Add the Equipo navigation work to its project.</p></li>
+<li data-card="c3" data-project-id="p2" data-turn-id="tg" data-needs-you="false" data-state="added"><p>Added to Equipo</p></li>
+<li data-message="ask-reply" data-turn-id="tg"><span class="tag">Equipo · 10:31</span><p>Done. It is in the Equipo thread.</p></li>
<li data-card="c2" data-project-id="p2" data-needs-you="true" data-state="open"><a href="#equipo">Project navigation</a><p>Review is complete. Ready to merge when you are.</p><form><button>Merge change</button> <button>Request changes</button></form></li>
</ol>
<div id="chat-composer"><p data-composer-scope>General conversation</p><form id="composer"><input type="hidden" name="project_id" value=""><textarea aria-label="General conversation" placeholder="What would you like to work on?"></textarea><button>Send</button></form></div></div>
diff --git a/release/project-threads/project-threads.js b/release/project-threads/project-threads.js
index a1063412..ec22b90b 100644
--- a/release/project-threads/project-threads.js
+++ b/release/project-threads/project-threads.js
@@ -1,5 +1,7 @@
-// A presentation of one conversation, not independent sessions. Only explicit
-// message scope and card project links are used. Unknown history stays General.
+// A presentation of one conversation, not independent sessions. A message
+// or card follows the project it names, else its turn's; anything else
+// stays General. Each project offers its own earlier days, with their
+// dates and the same Show the conversation link as General's day boxes.
(function () {
"use strict";
var catalog = document.querySelector('[data-project-catalog]');
@@ -9,6 +11,7 @@
var composer = document.getElementById('chat-composer');
var home = composer.parentElement;
var input = composer.querySelector('[name=project_id]');
+ var lines = '[data-message], [data-card], [equipo-thinking], [data-ended]';
var groups = {}, turns = {}, opened = {}, seen = {};
var docked = null, focus = null;
var known = {};
@@ -27,6 +30,8 @@
}
function group(id) {
if (groups[id] && groups[id].box.isConnected) return groups[id];
+ // A refresh replaces the feed: the new group keeps the old one's state.
+ if (groups[id]) opened[id] = groups[id].details.open;
var li = document.createElement('li'), details = document.createElement('details');
li.setAttribute('data-project-thread', id);
var summary = document.createElement('summary'), title = document.createElement('strong'), status = document.createElement('span');
@@ -59,9 +64,57 @@
});
li.append(details);
feed.append(li);
- groups[id] = {box: li, details: details, list: list, status: status};
+ groups[id] = {box: li, details: details, list: list, status: status, days: {}, heads: {}};
return groups[id];
}
+ // owner is the thread a line belongs in: the project it names, else
+ // the project its turn was sent to, else General.
+ function owner(n) {
+ var id = n.dataset.projectId || turns[n.dataset.turnId || n.dataset.turn] || '';
+ return known[id] ? id : '';
+ }
+ // day is a project's section for an earlier day, made from General's
+ // day box for it: its date and its Show or Hide the conversation link.
+ function day(g, box) {
+ var key = box.dataset.day, li = g.days[key];
+ if (!li) {
+ li = document.createElement('li');
+ li.setAttribute('data-project-day', '');
+ li.dataset.day = key;
+ var head = document.createElement('p'), list = document.createElement('ol');
+ head.setAttribute('data-project-day-head', '');
+ list.setAttribute('data-project-day-lines', '');
+ li.append(head, list);
+ g.days[key] = li;
+ }
+ var time = box.querySelector('[equipo-day-head] time'), toggle = box.querySelector('[data-day-toggle]');
+ var html = (time ? time.outerHTML : '') + (toggle ? toggle.outerHTML : '');
+ if (g.heads[key] !== html) {
+ li.firstElementChild.innerHTML = html;
+ var link = li.querySelector('[data-day-toggle]');
+ if (link) link.removeAttribute('aria-controls');
+ g.heads[key] = html;
+ }
+ // Earlier days stand before today's lines, oldest first.
+ var after = Array.from(g.list.children).find(function (c) { return c !== li && (!c.hasAttribute('data-project-day') || c.dataset.day > key); }) || null;
+ if (li.parentElement !== g.list || li.nextElementSibling !== after) g.list.insertBefore(li, after);
+ return li;
+ }
+ // today marks where a project's earlier days end and today's lines start.
+ function today(g) {
+ var mark = g.list.querySelector(':scope > [data-project-today]');
+ var first = Array.from(g.list.children).find(function (c) { return c !== mark && !c.hasAttribute('data-project-day'); });
+ if (!first || !Object.keys(g.days).length) { if (mark) mark.remove(); return; }
+ if (!mark) {
+ var said = groups[''].list.querySelector('[data-today]'), words = document.createElement('span');
+ words.textContent = said ? said.textContent.trim() : 'Today';
+ mark = document.createElement('li');
+ mark.setAttribute('equipo-day-divider', '');
+ mark.setAttribute('data-project-today', '');
+ mark.append(words);
+ }
+ if (mark.nextElementSibling !== first) g.list.insertBefore(mark, first);
+ }
function markRead(id) {
var g = groups[id];
g.list.querySelectorAll('[data-message], [data-card]').forEach(function (n) {
@@ -78,27 +131,35 @@
observer.disconnect();
group('');
Object.keys(known).forEach(group);
- // A turn belongs where its messages are; an unscoped turn is General's.
- feed.querySelectorAll('[data-turn-id], [data-turn]').forEach(function (n) {
+ feed.querySelectorAll('[data-project-id][data-turn-id], [data-project-id][data-turn]').forEach(function (n) {
var turn = n.dataset.turnId || n.dataset.turn;
- if (turn && !n.hasAttribute('data-card')) turns[turn] = n.dataset.projectId || turns[turn] || '';
+ if (turn && n.dataset.projectId && !n.hasAttribute('data-card')) turns[turn] = n.dataset.projectId;
});
- // Keep General's day navigation and history in their original order.
+ // Keep General's day boxes and history in their original order.
+ var general = groups[''].list;
Array.from(feed.children).forEach(function (n) {
- if (!n.hasAttribute('data-project-thread')) groups[''].list.append(n);
+ if (!n.hasAttribute('data-project-thread')) general.append(n);
});
- // Snapshot the elements before moving them, preserving their order within
- // each project. A card stays with the turn that produced it, so it never
- // lands below that turn's reply; only a card without one uses its link.
- Array.from(feed.querySelectorAll('[data-message], [data-card], [equipo-thinking], [data-ended]')).forEach(function (n) {
- var turn = n.dataset.turnId || n.dataset.turn;
- var id = turn && turns.hasOwnProperty(turn) ? turns[turn] : n.dataset.projectId || '';
- if (!known[id]) id = '';
- var g = group(id);
- if (id === '' && g.list.contains(n)) return;
- if (n.parentElement !== g.list) g.list.append(n);
+ var boxes = {};
+ general.querySelectorAll(':scope > [equipo-rollup]').forEach(function (box) {
+ boxes[box.dataset.day] = box;
+ var scoped = box.querySelector('[data-projects]');
+ (scoped ? scoped.dataset.projects.split(' ') : []).forEach(function (id) { if (known[id]) day(group(id), box); });
+ });
+ // Snapshot the lines before moving them, keeping their order within
+ // each thread and day; a line of an earlier day stays in that day.
+ Array.from(feed.querySelectorAll(lines)).forEach(function (n) {
+ var id = owner(n), at = n.closest('[data-day]'), box = at ? boxes[at.dataset.day] : null, target;
+ if (id === '') {
+ if (general.contains(n)) return;
+ target = box && box.querySelector('[equipo-day-feed]') || general;
+ } else {
+ target = box ? day(group(id), box).lastElementChild : group(id).list;
+ }
+ if (n.parentElement !== target) target.append(n);
});
Object.keys(groups).forEach(function (id) {
+ if (id) today(groups[id]);
if (groups[id].details.open) markRead(id);
update(id);
});