Daily roll-up: earlier days as day boxes on the conversation page
WIP: store reads, page, template, CSS, chat-stream.js, contract tests. Copy pending its delegated pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 files changed,
+1,174
−126
internal/equipo/chat/days.go+370 −0internal/equipo/chat_days.go+375 −0internal/equipo/chat_page.go+35 −44internal/equipo/copy.go+58 −44internal/equipo/static/chat-stream.js+40 −1internal/equipo/static/equipo.css+33 −0internal/equipo/templates/chat.html+26 −12internal/equipo/work_pages.go+0 −25internal/thintest/rollup_pages_test.go+237 −0
diff --git a/internal/equipo/chat/days.go b/internal/equipo/chat/days.go| new file mode 100644 |
| index 00000000..1675c910 |
| --- /dev/null |
| +++ b/internal/equipo/chat/days.go |
| @@ -0,0 +1,370 @@ |
| +package chat |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "time" |
| + |
| + "gorm.io/gorm" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/housekeeping" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// The conversation page's daily roll-up (Paul, 2026-11-12: "at the end |
| +// of the day, the day's conversation gets rolled up and summarised into |
| +// a box"). These are reads only: the transcript, the coordinator's |
| +// context and its notebook are what they were. What a day held is read |
| +// from records (messages, tasks, answered cards), never from a model. |
| + |
| +// Now is the store's clock (tests move it). |
| +func (s *Store) Now() time.Time { return s.now() } |
| + |
| +// Zone is the person's time zone, the one their days end in: the |
| +// housekeeping loop's, UTC until a person's zone is known. |
| +func (s *Store) Zone(person string) *time.Location { return (&txn{s: s}).zone(person) } |
| + |
| +// DayStart is the start of at's day in loc, in UTC. |
| +func DayStart(at time.Time, loc *time.Location) time.Time { return housekeeping.DayStart(at, loc) } |
| + |
| +// NextDay is the start of the day after the one starting at start. |
| +func NextDay(start time.Time, loc *time.Location) time.Time { |
| + l := start.In(loc) |
| + return time.Date(l.Year(), l.Month(), l.Day()+1, 0, 0, 0, 0, loc).UTC() |
| +} |
| + |
| +// maxDayScan bounds how many messages EarlierDays reads to find days. |
| +const maxDayScan = 20000 |
| + |
| +// EarlierDays is the start of each of the person's latest n days before |
| +// before that have a message, newest first. |
| +func (s *Store) EarlierDays(ctx context.Context, person string, before time.Time, n int) (out []time.Time, err error) { |
| + loc := s.Zone(person) |
| + err = s.read(ctx, func(tx *gorm.DB) error { |
| + if err := s.authority.CurrentPerson(ctx, tx); err != nil { |
| + return err |
| + } |
| + cut, scanned := before, 0 |
| + for len(out) < n && scanned < maxDayScan { |
| + var at []time.Time |
| + if err := tx.Model(&messageRecord{}).Where("person = ? AND created_at < ?", person, cut).Order("created_at DESC").Limit(500).Pluck("created_at", &at).Error; err != nil { |
| + return err |
| + } |
| + for _, t := range at { |
| + if d := DayStart(t, loc); len(out) == 0 || d.Before(out[len(out)-1]) { |
| + if len(out) == n { |
| + break |
| + } |
| + out = append(out, d) |
| + } |
| + } |
| + if len(at) < 500 || len(out) == n { |
| + return nil |
| + } |
| + // The next page starts before the day already found: one query |
| + // per day, not one per message. |
| + cut, scanned = out[len(out)-1], scanned+len(at) |
| + } |
| + return nil |
| + }) |
| + return out, err |
| +} |
| + |
| +// MessageAt is when one of the person's messages was written. |
| +func (s *Store) MessageAt(ctx context.Context, person, id string) (at time.Time, err error) { |
| + err = s.read(ctx, func(tx *gorm.DB) error { |
| + if err := s.authority.CurrentPerson(ctx, tx); err != nil { |
| + return err |
| + } |
| + var m messageRecord |
| + if err := tx.Select("created_at").Where("id = ? AND person = ?", id, person).First(&m).Error; errors.Is(err, gorm.ErrRecordNotFound) { |
| + return ErrNotFound |
| + } else if err != nil { |
| + return err |
| + } |
| + at = m.CreatedAt |
| + return nil |
| + }) |
| + return at, err |
| +} |
| + |
| +// Window is a stretch of the person's conversation as the page shows |
| +// it: the messages written in it (the newest limit), the cards that |
| +// stand among them, and the tasks those cards name. |
| +type Window struct { |
| + Messages []wire.Message |
| + Cards []wire.Card |
| + Tasks []wire.Task |
| +} |
| + |
| +// Placed is where a card stands in the conversation: a card a turn |
| +// produced stands with that turn's last message; any other at the time |
| +// it showed (after quiet hours). |
| +func placed(c cardRecord, lastOfTurn map[string]time.Time) (time.Time, bool) { |
| + if c.TurnID != "" { |
| + at, ok := lastOfTurn[c.TurnID] |
| + return at, ok |
| + } |
| + if c.VisibleAt != nil && c.VisibleAt.After(c.CreatedAt) { |
| + return *c.VisibleAt, true |
| + } |
| + return c.CreatedAt, true |
| +} |
| + |
| +func within(at, from, to time.Time) bool { |
| + return !at.Before(from) && (to.IsZero() || at.Before(to)) |
| +} |
| + |
| +// Window reads [from, to) of the person's conversation; a zero to is |
| +// open-ended (today). |
| +func (s *Store) Window(ctx context.Context, person string, from, to time.Time, limit int) (out Window, err error) { |
| + err = s.read(ctx, func(tx *gorm.DB) error { |
| + if err := s.authority.CurrentPerson(ctx, tx); err != nil { |
| + return err |
| + } |
| + q := tx.Where("person = ? AND created_at >= ?", person, from) |
| + if !to.IsZero() { |
| + q = q.Where("created_at < ?", to) |
| + } |
| + var rows []messageRecord |
| + if err := q.Order("seq DESC").Limit(limit).Find(&rows).Error; err != nil { |
| + return err |
| + } |
| + out.Messages = make([]wire.Message, 0, len(rows)) |
| + var turns []string |
| + for i := len(rows) - 1; i >= 0; i-- { |
| + out.Messages = append(out.Messages, messageView(rows[i])) |
| + if rows[i].TurnID != "" { |
| + turns = append(turns, rows[i].TurnID) |
| + } |
| + } |
| + if err := withFiles(tx, out.Messages); err != nil { |
| + return err |
| + } |
| + t := &txn{s: s, db: tx} |
| + last, err := t.lastOfTurns(person, turns) |
| + if err != nil { |
| + return err |
| + } |
| + // Cards with no turn showed at most a night after they were made. |
| + cq := tx.Where("person = ? AND (held IS NULL OR held = ?)", person, false).Where(tx.Where("turn_id IN ?", turns).Or("turn_id = ? AND created_at >= ?", "", from.Add(-24*time.Hour))) |
| + if !to.IsZero() { |
| + cq = cq.Where("created_at < ?", to) |
| + } |
| + var cards []cardRecord |
| + if err := cq.Order("created_at, id").Find(&cards).Error; err != nil { |
| + return err |
| + } |
| + names := map[string]bool{} |
| + for _, c := range cards { |
| + if at, ok := placed(c, last); !ok || !within(at, from, to) { |
| + continue |
| + } |
| + v, err := t.cardView(c) |
| + if err != nil { |
| + return err |
| + } |
| + out.Cards = append(out.Cards, v) |
| + if c.TaskID != "" { |
| + names[c.TaskID] = true |
| + } |
| + } |
| + out.Tasks, err = t.tasksNamed(names) |
| + return err |
| + }) |
| + return out, err |
| +} |
| + |
| +func (t *txn) lastOfTurns(person string, turns []string) (map[string]time.Time, error) { |
| + out := map[string]time.Time{} |
| + if len(turns) == 0 { |
| + return out, nil |
| + } |
| + var rows []messageRecord |
| + if err := t.db.Select("turn_id", "created_at").Where("person = ? AND turn_id IN ?", person, turns).Find(&rows).Error; err != nil { |
| + return nil, err |
| + } |
| + for _, m := range rows { |
| + if m.CreatedAt.After(out[m.TurnID]) { |
| + out[m.TurnID] = m.CreatedAt |
| + } |
| + } |
| + return out, nil |
| +} |
| + |
| +func (t *txn) tasksNamed(ids map[string]bool) ([]wire.Task, error) { |
| + if len(ids) == 0 { |
| + return nil, nil |
| + } |
| + list := make([]string, 0, len(ids)) |
| + for id := range ids { |
| + list = append(list, id) |
| + } |
| + var rows []taskRecord |
| + if err := t.db.Where("id IN ?", list).Order("created_at, id").Find(&rows).Error; err != nil { |
| + return nil, err |
| + } |
| + out := make([]wire.Task, 0, len(rows)) |
| + for _, k := range rows { |
| + v, err := t.taskView(k) |
| + if err != nil { |
| + return nil, err |
| + } |
| + out = append(out, v) |
| + } |
| + return out, nil |
| +} |
| + |
| +// Underway are the stages of a task that is being worked on: its |
| +// creator sees it until it ends, whatever day it started. |
| +var Underway = []string{wire.StageInProgress, wire.StageInReview, wire.StageReadyToMerge, wire.StageMerging} |
| + |
| +// StillOpen is what stands in the person's conversation before before |
| +// and may need them: cards still asking (a question, a decision, access, |
| +// a home to confirm) and the cards of their tasks still underway, with |
| +// the tasks those cards name. The page shows these whatever day they |
| +// are from; whether a card still asks is the page's reading of it. |
| +func (s *Store) StillOpen(ctx context.Context, person string, before time.Time) (out Window, err error) { |
| + err = s.read(ctx, func(tx *gorm.DB) error { |
| + if err := s.authority.CurrentPerson(ctx, tx); err != nil { |
| + return err |
| + } |
| + var cards []cardRecord |
| + if err := tx.Where("person = ? AND (held IS NULL OR held = ?)", person, false). |
| + Where(tx.Where("kind IN ? AND state = ?", []string{wire.CardQuestion, wire.CardAccess, wire.CardMerge, wire.CardDirection, wire.CardMergeShips, wire.CardMergePolicy}, wire.CardOpen). |
| + Or("kind = ? AND state = ?", wire.CardHome, wire.CardHomeAsk). |
| + Or("kind = ? AND task_id IN (SELECT id FROM chat_tasks WHERE creator = ? AND stage IN ?)", wire.CardTask, person, Underway)). |
| + Order("created_at, id").Find(&cards).Error; err != nil { |
| + return err |
| + } |
| + var turns []string |
| + for _, c := range cards { |
| + if c.TurnID != "" { |
| + turns = append(turns, c.TurnID) |
| + } |
| + } |
| + t := &txn{s: s, db: tx} |
| + last, err := t.lastOfTurns(person, turns) |
| + if err != nil { |
| + return err |
| + } |
| + names := map[string]bool{} |
| + for _, c := range cards { |
| + at, ok := placed(c, last) |
| + if !ok { |
| + // A turn with no message: never shown in the feed, so it |
| + // stands with the earlier days rather than nowhere. |
| + at = c.CreatedAt |
| + } |
| + if !at.Before(before) { |
| + continue |
| + } |
| + v, err := t.cardView(c) |
| + if err != nil { |
| + return err |
| + } |
| + out.Cards = append(out.Cards, v) |
| + if c.TaskID != "" { |
| + names[c.TaskID] = true |
| + } |
| + } |
| + out.Tasks, err = t.tasksNamed(names) |
| + return err |
| + }) |
| + return out, err |
| +} |
| + |
| +// DayTask is a task as a day's summary names it. |
| +type DayTask struct { |
| + ID, Title, Stage string |
| + CreatedAt time.Time |
| + DoneAt, MergedAt *time.Time |
| +} |
| + |
| +// Decision is a card the person answered, and when. |
| +type Decision struct { |
| + Card wire.Card |
| + At time.Time |
| + // Task is the task the card asked about, when it names one. |
| + Task *DayTask |
| +} |
| + |
| +// Rollup is what [from, to) of the person's conversation held, for its |
| +// days' summaries: when each message was written, the person's tasks |
| +// started, finished or merged then, and the decisions they made. |
| +type Rollup struct { |
| + Messages []time.Time |
| + Tasks []DayTask |
| + Decisions []Decision |
| +} |
| + |
| +// decisionKinds are the cards whose answer is a decision of the |
| +// person's: merge or wait, a direction, a policy question, a question. |
| +var decisionKinds = []string{wire.CardMerge, wire.CardDirection, wire.CardMergeShips, wire.CardMergePolicy, wire.CardQuestion} |
| + |
| +// Rollup reads [from, to) for the day boxes. |
| +func (s *Store) Rollup(ctx context.Context, person string, from, to time.Time) (out Rollup, err error) { |
| + err = s.read(ctx, func(tx *gorm.DB) error { |
| + if err := s.authority.CurrentPerson(ctx, tx); err != nil { |
| + return err |
| + } |
| + if err := tx.Model(&messageRecord{}).Where("person = ? AND created_at >= ? AND created_at < ?", person, from, to).Order("seq").Pluck("created_at", &out.Messages).Error; err != nil { |
| + return err |
| + } |
| + 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)). |
| + Order("created_at, id").Find(&tasks).Error; err != nil { |
| + return err |
| + } |
| + for _, k := range tasks { |
| + out.Tasks = append(out.Tasks, dayTask(k)) |
| + } |
| + // An answer is the person's message with the card's choice; a card |
| + // answered without one (no message) counts when it changed. |
| + var cards []cardRecord |
| + if err := tx.Where("person = ? AND state = ? AND kind IN ? AND updated_at >= ?", person, wire.CardAnswered, decisionKinds, from).Order("created_at, id").Find(&cards).Error; err != nil { |
| + return err |
| + } |
| + t := &txn{s: s, db: tx} |
| + named := map[string]*DayTask{} |
| + for _, c := range cards { |
| + at := c.UpdatedAt |
| + if c.AnswerMessage != "" { |
| + var m messageRecord |
| + if err := tx.Select("created_at").Where("id = ? AND person = ?", c.AnswerMessage, person).First(&m).Error; err == nil { |
| + at = m.CreatedAt |
| + } else if !errors.Is(err, gorm.ErrRecordNotFound) { |
| + return err |
| + } |
| + } |
| + if !within(at, from, to) { |
| + continue |
| + } |
| + v, err := t.cardView(c) |
| + if err != nil { |
| + return err |
| + } |
| + d := Decision{Card: v, At: at} |
| + if c.TaskID != "" { |
| + if named[c.TaskID] == nil { |
| + var k taskRecord |
| + if err := tx.Select("id", "title", "stage", "created_at", "done_at", "merged_at").Where("id = ?", c.TaskID).First(&k).Error; err == nil { |
| + dt := dayTask(k) |
| + named[c.TaskID] = &dt |
| + } else if !errors.Is(err, gorm.ErrRecordNotFound) { |
| + return err |
| + } |
| + } |
| + d.Task = named[c.TaskID] |
| + } |
| + out.Decisions = append(out.Decisions, d) |
| + } |
| + return nil |
| + }) |
| + return out, err |
| +} |
| + |
| +func dayTask(k taskRecord) DayTask { |
| + return DayTask{ID: k.ID, Title: k.Title, Stage: k.Stage, CreatedAt: k.CreatedAt, DoneAt: k.DoneAt, MergedAt: k.MergedAt} |
| +} |
diff --git a/internal/equipo/chat_days.go b/internal/equipo/chat_days.go| new file mode 100644 |
| index 00000000..24232c32 |
| --- /dev/null |
| +++ b/internal/equipo/chat_days.go |
| @@ -0,0 +1,375 @@ |
| +package equipo |
| + |
| +import ( |
| + "context" |
| + "fmt" |
| + "net/url" |
| + "slices" |
| + "sort" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/chat" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// The daily roll-up (Paul, 2026-11-12): "the value of the scrollback |
| +// diminishes and just becomes a distraction". Once a day is over in the |
| +// person's zone it shows as one day box: its date, what was started, |
| +// merged or finished, what the person decided and what is still open, |
| +// all read from records (no model, no tokens), and "Show the |
| +// conversation", which opens the day's transcript in place. Today is |
| +// never rolled up. |
| +// |
| +// The transcript opens inline rather than on a page of its own: the |
| +// day's cards keep working where they stand, a link to one of its |
| +// messages (/conversation?message=) lands in the one conversation with |
| +// the composer under it, and the live feed keeps an opened day open |
| +// across its refreshes. Without script the same link is a plain |
| +// /conversation?day= page with that day open. |
| +// |
| +// Whatever still needs the person is never rolled away: cards still |
| +// asking and tasks still underway from earlier days stand together at |
| +// the top of today. |
| + |
| +// earlierDayBoxes is how many earlier days with messages the page shows. |
| +const earlierDayBoxes = 14 |
| + |
| +// maxDayMessages bounds one day's transcript, and today's. |
| +const maxDayMessages = 1000 |
| + |
| +// dayListMax is how many items a day box names in one row. |
| +const dayListMax = 5 |
| + |
| +// chatDay is one earlier day on the conversation page. |
| +type chatDay struct { |
| + Key, Label string |
| + Messages string |
| + // Rows are what the day held, in a fixed order: started, merged, |
| + // finished, decided, still open. A day with none is Quiet: talk only. |
| + Rows []dayRow |
| + Quiet bool |
| + // Expanded days carry their transcript; Toggle is the link that |
| + // opens or closes it (the page's other open days kept). |
| + Expanded bool |
| + Toggle string |
| + Feed chatFeed |
| +} |
| + |
| +// chatFeed is a run of conversation lines and whose they are. |
| +type chatFeed struct { |
| + Lines []chatLine |
| + Address string |
| +} |
| + |
| +// Today is today's lines; Earlier what still needs the person from |
| +// earlier days. |
| +func (v chatView) Today(address string) chatFeed { return chatFeed{v.Messages, address} } |
| +func (v chatView) Earlier(address string) chatFeed { return chatFeed{v.Open, address} } |
| + |
| +// dayRow is a row of a day box: its label, its items, and how many more |
| +// there are. A stacked row (decisions) puts each item on its own line. |
| +type dayRow struct { |
| + Key, Label string |
| + Items []dayItem |
| + More string |
| + Stack bool |
| +} |
| + |
| +// dayItem names a task (a link) or, with no task, says what was asked; |
| +// Note is what a decision decided. |
| +type dayItem struct { |
| + TaskID, Text, Note string |
| +} |
| + |
| +func (r *dayRow) add(it dayItem) { |
| + if slices.Contains(r.Items, it) { |
| + return |
| + } |
| + r.Items = append(r.Items, it) |
| +} |
| + |
| +func (r *dayRow) trim() { |
| + if n := len(r.Items) - dayListMax; n > 0 { |
| + r.Items, r.More = r.Items[:dayListMax], fmt.Sprintf(copyText("chat.day.more"), n) |
| + } |
| +} |
| + |
| +// dayRowOrder is the order of a day box's rows. |
| +var dayRowOrder = []string{"started", "merged", "finished", "decided", "open"} |
| + |
| +func newDayRows() map[string]*dayRow { |
| + out := map[string]*dayRow{} |
| + for _, key := range dayRowOrder { |
| + out[key] = &dayRow{Key: key, Label: copyText("chat.day." + key), Stack: key == "decided"} |
| + } |
| + return out |
| +} |
| + |
| +// dayKey is the day's name in URLs and ids. |
| +func dayKey(start time.Time, loc *time.Location) string { return start.In(loc).Format("2006-01-02") } |
| + |
| +// parseDay reads a day key as the start of that day in loc. |
| +func parseDay(key string, loc *time.Location) (time.Time, bool) { |
| + t, err := time.ParseInLocation("2006-01-02", key, loc) |
| + if err != nil { |
| + return time.Time{}, false |
| + } |
| + return t.UTC(), true |
| +} |
| + |
| +// dayLabel is how a day is named: "Tuesday 11 November", with the year |
| +// when it is not this one. |
| +func dayLabel(start, today time.Time, loc *time.Location) string { |
| + l := start.In(loc) |
| + if l.Year() != today.In(loc).Year() { |
| + return l.Format("Monday 2 January 2006") |
| + } |
| + return l.Format("Monday 2 January") |
| +} |
| + |
| +// dayToggle is the link that opens (or closes) one day, keeping the |
| +// other open days open. |
| +func dayToggle(key string, open map[string]bool) string { |
| + var keys []string |
| + for k := range open { |
| + if k != key { |
| + keys = append(keys, k) |
| + } |
| + } |
| + if !open[key] { |
| + keys = append(keys, key) |
| + } |
| + sort.Strings(keys) |
| + path := "/conversation" |
| + if len(keys) > 0 { |
| + path += "?" + url.Values{"day": keys}.Encode() |
| + } |
| + return path + "#day-" + key |
| +} |
| + |
| +// asksPerson is whether a card from an earlier day still needs the |
| +// person: a question, decision or access card still open, or the card of |
| +// a task still underway. |
| +func asksPerson(c wire.Card, v chatCard, tasks map[string]wire.Task) bool { |
| + if c.Kind == wire.CardTask { |
| + t, ok := tasks[c.TaskID] |
| + return ok && v.Task != nil && slices.Contains(chat.Underway, t.Stage) |
| + } |
| + return v.Open |
| +} |
| + |
| +// receiptKind is whether a card shows as a quiet receipt line. |
| +func receiptKind(c wire.Card) bool { |
| + return c.Kind == wire.CardProject || c.Kind == wire.CardTask || c.Kind == wire.CardCombined || c.Kind == wire.CardHousekeeping || c.Kind == wire.CardHome && c.State != wire.CardHomeAsk |
| +} |
| + |
| +// decisionNote is what an answered card decided, in the words its card |
| +// shows once answered. |
| +func decisionNote(c wire.Card) string { |
| + key := "" |
| + switch c.Kind { |
| + case wire.CardMerge: |
| + key = "chat.card.merge_chose_" + c.Choice |
| + case wire.CardDirection: |
| + key = "chat.card.direction_chose_" + c.Choice |
| + case wire.CardMergeShips: |
| + key = "chat.card.ships_chose_" + c.Choice |
| + case wire.CardMergePolicy: |
| + key = "chat.card.policy_chose_" + c.Choice |
| + } |
| + if text := copyText(key); key != "" && text != "" { |
| + return text |
| + } |
| + return fmt.Sprintf(copyText("chat.card.answered"), c.Choice) |
| +} |
| + |
| +// earlierDays is the page's earlier days, oldest first, with the ones |
| +// asked for (expand) open, and what still needs the person from before |
| +// today, as loose lines for the top of today. |
| +func (a *application) earlierDays(ctx context.Context, address string, loc *time.Location, today time.Time, expand map[time.Time]bool, choices []string, tasks map[string]wire.Task) ([]chatDay, []chatLine, error) { |
| + chats := a.store.Chat() |
| + starts, err := chats.EarlierDays(ctx, address, today, earlierDayBoxes) |
| + if err != nil { |
| + return nil, nil, err |
| + } |
| + for d := range expand { |
| + if !slices.ContainsFunc(starts, d.Equal) { |
| + starts = append(starts, d) |
| + } |
| + } |
| + slices.SortFunc(starts, func(x, y time.Time) int { return x.Compare(y) }) |
| + open, err := chats.StillOpen(ctx, address, today) |
| + if err != nil { |
| + return nil, nil, err |
| + } |
| + for _, t := range open.Tasks { |
| + tasks[t.ID] = t |
| + } |
| + // What still needs the person: loose lines, in the order they came. |
| + var loose []chatLine |
| + shown := map[string]bool{} |
| + byDay := map[time.Time][]wire.Card{} |
| + for _, c := range open.Cards { |
| + v := cardView(c, choices, tasks) |
| + if !asksPerson(c, v, tasks) { |
| + continue |
| + } |
| + v.Receipt = receiptKind(c) |
| + at := c.CreatedAt |
| + if c.VisibleAt != nil && c.VisibleAt.After(at) { |
| + at = *c.VisibleAt |
| + } |
| + loose = append(loose, chatLine{ID: c.ID, CardOnly: true, Cards: []chatCard{v}, CreatedAt: at}) |
| + shown[c.ID] = true |
| + byDay[chat.DayStart(at, loc)] = append(byDay[chat.DayStart(at, loc)], c) |
| + } |
| + if len(starts) == 0 { |
| + return nil, loose, nil |
| + } |
| + roll, err := chats.Rollup(ctx, address, starts[0], today) |
| + if err != nil { |
| + return nil, nil, err |
| + } |
| + counts := map[time.Time]int{} |
| + for _, at := range roll.Messages { |
| + counts[chat.DayStart(at, loc)]++ |
| + } |
| + // 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 { |
| + return nil, loose, nil |
| + } |
| + days := make([]chatDay, len(starts)) |
| + rows := make([]map[string]*dayRow, len(starts)) |
| + index := map[time.Time]int{} |
| + opened := map[string]bool{} |
| + for _, d := range starts { |
| + if expand[d] { |
| + opened[dayKey(d, loc)] = true |
| + } |
| + } |
| + 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)} |
| + rows[i] = newDayRows() |
| + days[i].Messages = copyText("chat.day.messages_one") |
| + if n := counts[d]; n != 1 { |
| + days[i].Messages = fmt.Sprintf(copyText("chat.day.messages"), n) |
| + } |
| + } |
| + in := func(at *time.Time) (int, bool) { |
| + if at == nil { |
| + return 0, false |
| + } |
| + i, ok := index[chat.DayStart(*at, loc)] |
| + return i, ok |
| + } |
| + for _, t := range roll.Tasks { |
| + it := dayItem{TaskID: t.ID, Text: t.Title} |
| + if i, ok := in(&t.CreatedAt); ok { |
| + rows[i]["started"].add(it) |
| + } |
| + if i, ok := in(t.MergedAt); ok { |
| + rows[i]["merged"].add(it) |
| + } else if i, ok := in(t.DoneAt); ok && t.Stage == wire.StageDone { |
| + rows[i]["finished"].add(it) |
| + } |
| + } |
| + for _, d := range roll.Decisions { |
| + i, ok := in(&d.At) |
| + if !ok { |
| + continue |
| + } |
| + it := dayItem{Text: d.Card.Question, Note: decisionNote(d.Card)} |
| + if d.Task != nil { |
| + it.TaskID, it.Text = d.Task.ID, d.Task.Title |
| + } |
| + rows[i]["decided"].add(it) |
| + } |
| + for start, cards := range byDay { |
| + i, ok := index[start] |
| + if !ok { |
| + continue |
| + } |
| + for _, c := range cards { |
| + if t, ok := tasks[c.TaskID]; ok && c.TaskID != "" { |
| + rows[i]["open"].add(dayItem{TaskID: t.ID, Text: t.Title}) |
| + } else { |
| + rows[i]["open"].add(dayItem{Text: cardView(c, choices, tasks).Line}) |
| + } |
| + } |
| + } |
| + for i := range days { |
| + d := &days[i] |
| + for _, key := range dayRowOrder { |
| + if r := rows[i][key]; len(r.Items) > 0 { |
| + r.trim() |
| + d.Rows = append(d.Rows, *r) |
| + } |
| + } |
| + d.Quiet = len(d.Rows) == 0 |
| + if !d.Expanded { |
| + continue |
| + } |
| + start := starts[i] |
| + win, err := chats.Window(ctx, address, start, chat.NextDay(start, loc), maxDayMessages) |
| + if err != nil { |
| + return nil, nil, err |
| + } |
| + for _, t := range win.Tasks { |
| + tasks[t.ID] = t |
| + } |
| + // A card still asking stands at the top of today, once. |
| + cards := slices.DeleteFunc(win.Cards, func(c wire.Card) bool { return shown[c.ID] }) |
| + d.Feed = chatFeed{Lines: feedLines(win.Messages, cards, choices, tasks), Address: address} |
| + } |
| + return days, loose, nil |
| +} |
| + |
| +// feedLines places a stretch's messages and cards as the page shows |
| +// them: a receipt sits where its action happened, before the reply of |
| +// its turn (or after the person's message while the turn runs); other |
| +// cards come after the turn's last message, in event order; a card no |
| +// turn produced stands at its own time. |
| +func feedLines(msgs []wire.Message, cards []wire.Card, choices []string, tasks map[string]wire.Task) []chatLine { |
| + var out []chatLine |
| + last := map[string]int{} |
| + for i, m := range msgs { |
| + out = append(out, chatLine{ID: m.ID, Text: m.Text, TurnID: m.TurnID, Own: m.Role == wire.RolePerson, CreatedAt: m.CreatedAt, Switched: switchedText(m.Switched), Files: m.Attachments}) |
| + last[m.TurnID] = i |
| + } |
| + reply := map[string]int{} |
| + for i, m := range out { |
| + if !m.Own { |
| + if _, ok := reply[m.TurnID]; !ok { |
| + reply[m.TurnID] = i |
| + } |
| + } |
| + } |
| + var loose []chatLine |
| + for _, c := range cards { |
| + v := cardView(c, choices, tasks) |
| + if c.Kind == wire.CardTask && v.Task == nil { |
| + continue |
| + } |
| + v.Receipt = receiptKind(c) |
| + if i, ok := reply[c.TurnID]; ok && v.Receipt && c.TurnID != "" { |
| + out[i].Receipts = append(out[i].Receipts, v) |
| + } else if i, ok := last[c.TurnID]; ok && c.TurnID != "" { |
| + out[i].Cards = append(out[i].Cards, v) |
| + } else if c.TurnID == "" { |
| + // A receipt held through quiet hours stands where it showed. |
| + at := c.CreatedAt |
| + if c.VisibleAt != nil && c.VisibleAt.After(at) { |
| + at = *c.VisibleAt |
| + } |
| + loose = append(loose, chatLine{ID: c.ID, CardOnly: true, Cards: []chatCard{v}, CreatedAt: at}) |
| + } |
| + } |
| + for _, l := range loose { |
| + at := sort.Search(len(out), func(i int) bool { return out[i].CreatedAt.After(l.CreatedAt) }) |
| + out = slices.Insert(out, at, l) |
| + } |
| + return out |
| +} |
diff --git a/internal/equipo/chat_page.go b/internal/equipo/chat_page.go| index 4a1add1a..0926959e 100644 |
| --- a/internal/equipo/chat_page.go |
| +++ b/internal/equipo/chat_page.go |
| @@ -6,8 +6,6 @@ import ( |
| "errors" |
| "fmt" |
| "net/http" |
| - "slices" |
| - "sort" |
| "strconv" |
| "strings" |
| "time" |
| @@ -25,8 +23,12 @@ import ( |
| type chatView struct { |
| // Draft is the composer's opening words: "Ask about this" on a task |
| // opens the conversation with the task referenced (?about=tk...). |
| - Draft string |
| + Draft string |
| + // Messages are today's; Days the earlier days, oldest first; Open what |
| + // still needs the person from them, at the top of today. |
| Messages []chatLine |
| + Days []chatDay |
| + Open []chatLine |
| Waiting []wire.Turn |
| Ended *chatEnded |
| // NoConnection is the card for a turn held because nothing the person |
| @@ -202,8 +204,6 @@ func (a *application) chatPage(w http.ResponseWriter, r *http.Request) { |
| a.failure(w, r, chatError(err)) |
| return |
| } |
| - // A task's "From your conversation" link: older history up to it. |
| - snap.Messages = a.withMessage(ctx, address, snap.Messages, r.URL.Query().Get("message")) |
| data, err := a.page(r, "conversation") |
| if err != nil { |
| a.failure(w, r, err) |
| @@ -217,56 +217,46 @@ func (a *application) chatPage(w http.ResponseWriter, r *http.Request) { |
| view.Draft = fmt.Sprintf(copyText("work.ask_about.draft"), t.Title) |
| } |
| } |
| - last := map[string]int{} |
| - for i, m := range snap.Messages { |
| - view.Messages = append(view.Messages, chatLine{ID: m.ID, Text: m.Text, TurnID: m.TurnID, Own: m.Role == wire.RolePerson, CreatedAt: m.CreatedAt, Switched: switchedText(m.Switched), Files: m.Attachments}) |
| - last[m.TurnID] = i |
| + // Today, in the person's zone, is the conversation; each earlier day |
| + // is a day box (chat_days.go), open when asked for (?day=) or when a |
| + // task's "From your conversation" link names one of its messages. |
| + chats := a.store.Chat() |
| + loc := chats.Zone(address) |
| + today := chat.DayStart(chats.Now(), loc) |
| + expand := map[time.Time]bool{} |
| + for _, key := range r.URL.Query()["day"] { |
| + if d, ok := parseDay(key, loc); ok && d.Before(today) { |
| + expand[d] = true |
| + } |
| + } |
| + if id := r.URL.Query().Get("message"); id != "" { |
| + if at, err := chats.MessageAt(ctx, address, id); err == nil && at.Before(today) { |
| + expand[chat.DayStart(at, loc)] = true |
| + } |
| } |
| - choices, err := a.store.Chat().ProjectChoices(ctx, address) |
| + win, err := chats.Window(ctx, address, today, time.Time{}, maxDayMessages) |
| if err != nil { |
| a.failure(w, r, chatError(err)) |
| return |
| } |
| - // A receipt sits where its action happened: before the reply of its |
| - // turn (or after the person's message while the turn runs). Cards come |
| - // in event order. |
| - reply := map[string]int{} |
| - for i, m := range view.Messages { |
| - if !m.Own { |
| - if _, ok := reply[m.TurnID]; !ok { |
| - reply[m.TurnID] = i |
| - } |
| - } |
| + choices, err := chats.ProjectChoices(ctx, address) |
| + if err != nil { |
| + a.failure(w, r, chatError(err)) |
| + return |
| } |
| - var loose []chatLine |
| tasks := map[string]wire.Task{} |
| for _, t := range snap.Tasks { |
| tasks[t.ID] = t |
| } |
| - for _, c := range snap.Cards { |
| - v := cardView(c, choices, tasks) |
| - if c.Kind == wire.CardTask && v.Task == nil { |
| - continue |
| - } |
| - v.Receipt = c.Kind == wire.CardProject || c.Kind == wire.CardTask || c.Kind == wire.CardCombined || c.Kind == wire.CardHousekeeping || c.Kind == wire.CardHome && c.State != wire.CardHomeAsk |
| - if i, ok := reply[c.TurnID]; ok && v.Receipt && c.TurnID != "" { |
| - view.Messages[i].Receipts = append(view.Messages[i].Receipts, v) |
| - } else if i, ok := last[c.TurnID]; ok && c.TurnID != "" { |
| - view.Messages[i].Cards = append(view.Messages[i].Cards, v) |
| - } else if c.TurnID == "" { |
| - // A receipt held through quiet hours stands where it showed. |
| - at := c.CreatedAt |
| - if c.VisibleAt != nil && c.VisibleAt.After(at) { |
| - at = *c.VisibleAt |
| - } |
| - loose = append(loose, chatLine{ID: c.ID, CardOnly: true, Cards: []chatCard{v}, CreatedAt: at}) |
| - } |
| + for _, t := range win.Tasks { |
| + tasks[t.ID] = t |
| } |
| - // Cards no turn produced stand at their own time among the messages. |
| - for _, l := range loose { |
| - at := sort.Search(len(view.Messages), func(i int) bool { return view.Messages[i].CreatedAt.After(l.CreatedAt) }) |
| - view.Messages = slices.Insert(view.Messages, at, l) |
| + view.Days, view.Open, err = a.earlierDays(ctx, address, loc, today, expand, choices, tasks) |
| + if err != nil { |
| + a.failure(w, r, chatError(err)) |
| + return |
| } |
| + view.Messages = feedLines(win.Messages, win.Cards, choices, tasks) |
| // Nothing can answer: no turn shows the thinking line or a timer |
| // until an attempt starts on a connection. A turn waiting for one, and |
| // any queued behind it, get a quiet status under the person's message; |
| @@ -324,7 +314,8 @@ func (a *application) chatPage(w http.ResponseWriter, r *http.Request) { |
| break |
| } |
| } |
| - if latest != nil && (latest.State == wire.TurnFailed || latest.State == wire.TurnCancelled) { |
| + // A turn that ended unanswered on an earlier day is history there. |
| + if latest != nil && !latest.CreatedAt.Before(today) && (latest.State == wire.TurnFailed || latest.State == wire.TurnCancelled) { |
| key := "chat." + latest.State |
| switch { |
| case latest.Reason == wire.ReasonStorageFull: |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index ece1d409..a7b361ab 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -1641,50 +1641,64 @@ var pageCopy = map[string]string{ |
| "specialist.instructions": "Instructions", |
| // Merge authority (spec 2026-11-11-equipo-merge-authority.md). |
| - "chat.merge.stance_merge": "Merge %s? I'd merge: %s, but %s.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.stance_wait": "Merge %s? I'd wait: %s.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.why.approved": "approved by Review", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.why.small": "a small change, %d lines in %d files", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.why.small_one": "a small change, %d lines in one file", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.why.not_shipping": "nothing ships until a release", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.why.exact_revert": "it exactly reverts %s", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.environment": "checks couldn't run because %s", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.no_checks": "it has no checks to run", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.protocol": "your runner needs an update before I merge on my own", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.facts": "the runner didn't say what changed", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.small": "it's larger than I can merge on my own (%d lines in %d files)", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.small_one": "it's larger than I can merge on my own (%d lines in one file)", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.special": "it changes a symlink, a submodule or a file mode", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.sensitive": "it touches %s (%s)", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.signing": "it changes signing or version settings", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.ships": "merging to %s's main branch ships to users", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.ships_unknown": "I don't know yet whether merging to %s's main branch ships to users", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.policy": "I ask before every merge in this project", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.revert": "it doesn't exactly revert %s", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.eligible": "it was ready before I could merge on my own", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.sandbox": "its checks ran outside the sandbox", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.not.hosted": "its hosted checks passed, but I need to verify those runs before I can merge it on my own", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.area.migrations": "the database schema", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.area.auth_secrets": "sign-in, keys or secrets", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.area.payments": "payments", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.area.ci_config": "the checks or CI setup", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.area.dependencies": "dependencies", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.area.release_signing": "release or signing settings", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.area.infrastructure": "infrastructure", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.area.project": "a path I must ask about", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.card.wait_mac": "Wait for a Mac", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.card.merge_chose_wait_mac": "Waiting for a Mac.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.ships_question": "Does merging to %s's main branch ship to users?", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.card.ships": "It ships", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.card.not_ships": "It doesn't", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.card.ships_chose_ships": "Merging to main ships to users, so I'll ask before merging without checks.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.card.ships_chose_not_ships": "Main isn't a release, so I can merge small changes on my own when the other rules allow.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.card.merge_policy_stale": "The merge rules changed since I asked, so nothing was saved.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.merge.policy_confirm": "Change how Equipo merges %s: %s?", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.card.save": "Save", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.card.cancel": "Cancel", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.card.policy_chose_save": "Saved.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "chat.card.policy_chose_cancel": "Left as it was.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.stance_merge": "Merge %s? I'd merge: %s, but %s.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.stance_wait": "Merge %s? I'd wait: %s.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.why.approved": "approved by Review", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.why.small": "a small change, %d lines in %d files", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.why.small_one": "a small change, %d lines in one file", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.why.not_shipping": "nothing ships until a release", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.why.exact_revert": "it exactly reverts %s", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.environment": "checks couldn't run because %s", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.no_checks": "it has no checks to run", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.protocol": "your runner needs an update before I merge on my own", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.facts": "the runner didn't say what changed", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.small": "it's larger than I can merge on my own (%d lines in %d files)", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.small_one": "it's larger than I can merge on my own (%d lines in one file)", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.special": "it changes a symlink, a submodule or a file mode", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.sensitive": "it touches %s (%s)", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.signing": "it changes signing or version settings", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.ships": "merging to %s's main branch ships to users", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.ships_unknown": "I don't know yet whether merging to %s's main branch ships to users", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.policy": "I ask before every merge in this project", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.revert": "it doesn't exactly revert %s", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.eligible": "it was ready before I could merge on my own", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.sandbox": "its checks ran outside the sandbox", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.not.hosted": "its hosted checks passed, but I need to verify those runs before I can merge it on my own", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.area.migrations": "the database schema", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.area.auth_secrets": "sign-in, keys or secrets", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.area.payments": "payments", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.area.ci_config": "the checks or CI setup", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.area.dependencies": "dependencies", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.area.release_signing": "release or signing settings", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.area.infrastructure": "infrastructure", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.area.project": "a path I must ask about", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.card.wait_mac": "Wait for a Mac", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.card.merge_chose_wait_mac": "Waiting for a Mac.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.ships_question": "Does merging to %s's main branch ship to users?", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.card.ships": "It ships", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.card.not_ships": "It doesn't", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.card.ships_chose_ships": "Merging to main ships to users, so I'll ask before merging without checks.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.card.ships_chose_not_ships": "Main isn't a release, so I can merge small changes on my own when the other rules allow.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.card.merge_policy_stale": "The merge rules changed since I asked, so nothing was saved.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.merge.policy_confirm": "Change how Equipo merges %s: %s?", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.card.save": "Save", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.card.cancel": "Cancel", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.card.policy_chose_save": "Saved.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "chat.card.policy_chose_cancel": "Left as it was.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + // The daily roll-up (2026-11-12): earlier days on the conversation page. |
| + "chat.day.today": "Today", |
| + "chat.day.still_open": "Still open from earlier days", |
| + "chat.day.started": "Started", |
| + "chat.day.merged": "Merged", |
| + "chat.day.finished": "Finished", |
| + "chat.day.decided": "You decided", |
| + "chat.day.open": "Still open", |
| + "chat.day.quiet": "Nothing started or decided.", |
| + "chat.day.more": "and %d more", |
| + "chat.day.messages": "%d messages", |
| + "chat.day.messages_one": "1 message", |
| + "chat.day.show": "Show the conversation", |
| + "chat.day.hide": "Hide the conversation", |
| "chat.merge.policy.rules": "merge on my own when all the rules are met, up to %d lines in %d files", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| "chat.merge.policy.ask": "ask before every merge", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| "chat.merge.policy.ships_unknown": "I don't know yet whether main ships to users", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
diff --git a/internal/equipo/static/chat-stream.js b/internal/equipo/static/chat-stream.js| index fd00e5fb..cb35bf03 100644 |
| --- a/internal/equipo/static/chat-stream.js |
| +++ b/internal/equipo/static/chat-stream.js |
| @@ -757,8 +757,20 @@ |
| following = atBottom(); |
| return true; |
| } |
| + // Earlier days the reader opened stay open across refreshes: the page |
| + // is asked for them (?day=), as the server rendered them. |
| + var days = new Set(); |
| + feed.querySelectorAll("[equipo-day][data-expanded]").forEach(function (el) { days.add(el.dataset.day); }); |
| + function pageURL() { |
| + if (!days.size) return location.pathname; |
| + return location.pathname + "?" + Array.from(days).sort().map(function (d) { return "day=" + encodeURIComponent(d); }).join("&"); |
| + } |
| + // refreshed settles once a refresh started after this call has run. |
| + function refreshed() { |
| + return inflight ? inflight.then(refreshed, refreshed) : refresh(); |
| + } |
| function load() { |
| - return fetch(location.pathname, { credentials: "same-origin", headers: { "Accept": "text/html" } }) |
| + return fetch(pageURL(), { credentials: "same-origin", headers: { "Accept": "text/html" } }) |
| .then(function (r) { if (!r.ok) throw new Error("refresh"); return r.text(); }) |
| .then(function (body) { |
| var doc = new DOMParser().parseFromString(body, "text/html"); |
| @@ -995,6 +1007,33 @@ |
| card.toggleAttribute("data-open", open); |
| more.setAttribute("aria-expanded", String(open)); |
| }); |
| + // "Show the conversation" opens an earlier day in place (its link, |
| + // ?day=, is the page without script); "Hide the conversation" closes |
| + // it. The day's box stays where the reader is looking. |
| + feed.addEventListener("click", function (event) { |
| + var toggle = event.target.closest("[data-day-toggle]"); |
| + if (!toggle || event.button || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; |
| + event.preventDefault(); |
| + var day = toggle.dataset.dayToggle; |
| + var opening = !days.has(day); |
| + if (opening) days.add(day); else days.delete(day); |
| + toggle.setAttribute("aria-busy", "true"); |
| + following = false; |
| + function place() { |
| + var li = feed.querySelector('[equipo-day][data-day="' + CSS.escape(day) + '"]'); |
| + if (!li) return; |
| + if (box) { |
| + box.scrollTop += li.getBoundingClientRect().top - box.getBoundingClientRect().top - 8; |
| + following = atBottom(); |
| + } |
| + var again = li.querySelector("[data-day-toggle]"); |
| + if (again) again.focus({ preventScroll: true }); |
| + } |
| + refreshed().then(place, function () { |
| + if (opening) days.delete(day); else days.add(day); |
| + toggle.removeAttribute("aria-busy"); |
| + }); |
| + }); |
| // Card actions (Change, Remove, answers) post in the background and the |
| // card events re-render the feed; without script the forms still work. |
| feed.addEventListener("submit", function (event) { |
diff --git a/internal/equipo/static/equipo.css b/internal/equipo/static/equipo.css| index 3bee6432..4c408b31 100644 |
| --- a/internal/equipo/static/equipo.css |
| +++ b/internal/equipo/static/equipo.css |
| @@ -1563,3 +1563,36 @@ label[equipo-sp-label] { cursor: pointer; } |
| [equipo-mach-facts] dd + dt { margin-block-start: var(--rst-sp-2); } |
| } |
| [equipo-machines] [equipo-conn-add-foot] > a { flex: none; white-space: nowrap; } |
| + |
| +/* The daily roll-up (chat_days.go): each earlier day is one quiet box, |
| + its date, what it held and the way into its transcript; the |
| + transcript opens under the box when asked for. */ |
| +[equipo-day] { list-style: none; display: flex; flex-direction: column; gap: var(--rst-sp-4); min-width: 0; } |
| +[equipo-day-box] { align-self: stretch; max-inline-size: 36rem; box-sizing: border-box; padding: var(--rst-sp-3) var(--rst-sp-4); border: 1px solid var(--rst-line); border-radius: calc(2 * var(--rst-radius)); background: var(--rst-surface); color: var(--rst-text-muted); font-size: var(--rst-fs-sm); } |
| +[equipo-day-head] { display: flex; align-items: baseline; gap: var(--rst-sp-3); } |
| +[equipo-day-head] h2 { flex: 1; min-width: 0; margin: 0; font-size: var(--rst-fs-sm); font-weight: 600; color: var(--rst-text); } |
| +[equipo-day-count] { flex: none; font-size: var(--rst-fs-xs); font-variant-numeric: tabular-nums; white-space: nowrap; } |
| +[equipo-day-rows] { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--rst-sp-1) var(--rst-sp-4); margin: var(--rst-sp-3) 0 0; } |
| +[equipo-day-row] { display: contents; } |
| +[equipo-day-row] dt { color: var(--rst-text-muted); } |
| +[equipo-day-row] dd { margin: 0; min-width: 0; color: var(--rst-text); overflow-wrap: anywhere; } |
| +[equipo-day-row] dd[data-stack] { display: flex; flex-direction: column; gap: var(--rst-sp-1); } |
| +[equipo-day-item] a { color: inherit; text-decoration-color: color-mix(in oklab, currentColor 35%, transparent); text-underline-offset: 2px; } |
| +[equipo-day-item] a:hover { text-decoration-color: currentColor; } |
| +[equipo-day-decision], [equipo-day-more] { color: var(--rst-text-muted); } |
| +[equipo-day-quiet] { margin: var(--rst-sp-2) 0 0; } |
| +[equipo-day-toggle] { display: inline-flex; align-items: center; gap: var(--rst-sp-1); margin-block-start: var(--rst-sp-3); min-block-size: 1.75rem; color: var(--rst-text-muted); text-decoration: none; } |
| +[equipo-day-toggle]:hover { color: var(--rst-text); } |
| +[equipo-day-toggle]:hover span { text-decoration: underline; text-underline-offset: 2px; } |
| +[equipo-day-toggle] .icon { inline-size: 1em; block-size: 1em; transition: transform .2s cubic-bezier(.16, 1, .3, 1); } |
| +[equipo-day-toggle][aria-expanded="true"] .icon { transform: rotate(180deg); } |
| +[equipo-day-toggle][aria-busy="true"] { opacity: .6; } |
| +[equipo-day-feed] { margin: 0; } |
| +[equipo-day-divider] { list-style: none; display: flex; align-items: center; gap: var(--rst-sp-3); color: var(--rst-text-muted); font-size: var(--rst-fs-xs); } |
| +[equipo-day-divider]::before, [equipo-day-divider]::after { content: ""; flex: 1; border-block-start: 1px solid var(--rst-line); } |
| +@media (max-width: 479.98px) { |
| + [equipo-day-rows] { grid-template-columns: minmax(0, 1fr); row-gap: 0; } |
| + [equipo-day-row] dt { margin-block-start: var(--rst-sp-2); font-size: var(--rst-fs-xs); } |
| + [equipo-day-row]:first-child dt { margin-block-start: 0; } |
| +} |
| +@media (prefers-reduced-motion: reduce) { [equipo-day-toggle] .icon { transition: none; } } |
diff --git a/internal/equipo/templates/chat.html b/internal/equipo/templates/chat.html| index 3bb93efc..20f609dd 100644 |
| --- a/internal/equipo/templates/chat.html |
| +++ b/internal/equipo/templates/chat.html |
| @@ -13,6 +13,26 @@ |
| {{end}}</li>{{end}} |
| {{define "work-task-receipt"}}{{with .Task}}<p equipo-card-line>{{icon "check-circle"}}<span><a href="/tasks/{{.ID}}">{{.Title}}</a></span><span equipo-stage data-stage="{{.Stage}}" data-needs="{{.NeedsYou}}">{{.StageLine}}</span></p>{{if and .Pushed (not .MergedLine)}}<p equipo-card-note data-pushed><span>{{.Pushed}}</span><a href="{{.URL}}" rel="noopener" target="_blank" data-open-amadan>{{copy "work.open"}}</a></p>{{end}}{{if or .ChecksLine .ReviewLine}}<p equipo-card-note data-judged>{{with .ChecksLine}}<span data-checks>{{.}}</span>{{end}}{{with .ReviewLine}}<span data-verdict>{{.}}</span>{{end}}</p>{{end}}{{if .MergedLine}}<p equipo-card-note data-merged><span>{{.MergedLine}}</span><a href="{{.RepoURL}}" rel="noopener" target="_blank" data-open-amadan>{{copy "work.open"}}</a></p>{{end}}{{if .PreviewURL}}<p equipo-card-note data-preview><a href="{{.PreviewURL}}" rel="noopener" target="_blank">{{.PreviewLine}}</a></p>{{end}}{{end}}{{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}}">{{template "work-task-actions" .Task}}</span>{{end}}{{end}} |
| {{define "message-files"}}{{with .}}<div equipo-message-files>{{range .}}{{if eq .Kind "image"}}<a equipo-file-thumb href="/conversation/attachments/{{.ID}}" target="_blank" rel="noopener" data-attachment="{{.ID}}"><img src="/conversation/attachments/{{.ID}}/preview" alt="{{.Name}}"{{if .Width}} width="{{.Width}}" height="{{.Height}}"{{end}} loading="lazy" decoding="async"></a>{{else}}<a equipo-file-chip href="/conversation/attachments/{{.ID}}" target="_blank" rel="noopener" data-attachment="{{.ID}}">{{icon "file-text"}}<span equipo-file-name>{{.Name}}</span><span equipo-file-size>{{fileSize .Size}}</span></a>{{end}}{{end}}</div>{{end}}{{end}} |
| +{{define "chat-lines"}}{{$address := .Address}}{{range .Lines}} |
| +{{if .CardOnly}}{{range .Cards}}{{template "chat-card" .}}{{end}}{{else}} |
| +{{range .Receipts}}{{template "chat-card" .}}{{end}} |
| +<li equipo-message="{{if .Own}}own{{else}}incoming{{end}}" data-message="{{.ID}}" data-turn-id="{{.TurnID}}"> |
| +<div equipo-message-meta><strong{{if .Own}} equipo-visually-hidden{{end}}>{{if .Own}}{{$address}}{{else}}{{icon "message-circle"}}{{copy "conversation.coordinator"}}{{end}}</strong><time datetime="{{.CreatedAt.Format "2006-01-02T15:04:05Z07:00"}}">{{.CreatedAt.Format "15:04"}}</time></div> |
| +{{if .Own}}{{template "message-files" .Files}}{{end}}<div equipo-bubble>{{if .Own}}<p equipo-message-body>{{.Text}}</p>{{else}}<div equipo-message-body equipo-markdown>{{chatMarkdown .Text}}</div>{{end}}</div> |
| +{{with .Waiting}}<p equipo-card-note data-waiting-connection>{{.}}</p>{{end}} |
| +{{with .Queued}}<p equipo-card-note data-queued>{{.}}</p>{{end}} |
| +{{with .Switched}}<p equipo-card-note data-switched>{{.}}</p>{{end}} |
| +</li> |
| +{{range .Cards}}{{template "chat-card" .}}{{end}}{{end}}{{end}}{{end}} |
| +{{define "chat-day"}}<li equipo-day id="day-{{.Key}}" data-day="{{.Key}}"{{if .Expanded}} data-expanded{{end}}> |
| +<section equipo-day-box aria-labelledby="day-title-{{.Key}}"> |
| +<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> |
| +</section> |
| +{{if .Expanded}}<ol equipo-feed equipo-day-feed id="day-feed-{{.Key}}" aria-labelledby="day-title-{{.Key}}">{{template "chat-lines" .Feed}}</ol>{{end}} |
| +</li>{{end}} |
| +{{define "day-row"}}<div equipo-day-row data-row="{{.Key}}"><dt>{{.Label}}</dt><dd{{if .Stack}} data-stack{{end}}>{{range $i, $it := .Items}}{{if and $i (not $.Stack)}}, {{end}}<span equipo-day-item>{{if .TaskID}}<a href="/tasks/{{.TaskID}}">{{.Text}}</a>{{else}}{{.Text}}{{end}}{{with .Note}} <span equipo-day-decision>{{.}}</span>{{end}}</span>{{end}}{{with .More}} <span equipo-day-more>{{.}}</span>{{end}}</dd></div>{{end}} |
| {{define "content"}} |
| <div equipo-conversation data-chat-stream data-thinking-set="{{.ThinkingSet}}" data-thinking-words="{{.ThinkingWords}}" data-cursor="{{.Chat.Cursor}}" data-person="{{.Address}}" data-elapsed="{{copy "chat.elapsed"}}" data-moving-in="{{copy "chat.moving_in"}}" data-exploring="{{copy "chat.exploring"}}" data-queued-note="{{copy "chat.queued"}}"> |
| <header equipo-chat-header><h1>{{copy "conversation.title"}}</h1><a href="/conversation/settings/notebook" equipo-header-button aria-label="{{copy "chat.notebook.link"}}" title="{{copy "chat.notebook.link"}}">{{icon "notebook"}}</a><a href="/housekeeping" equipo-header-button aria-label="{{copy "chat.housekeeping.link"}}" title="{{copy "chat.housekeeping.link"}}" data-housekeeping-link>{{icon "list-checks"}}</a><a href="/conversation/settings/connections" equipo-header-button aria-label="{{copy "chat.connections.title"}}" title="{{copy "chat.connections.title"}}" data-connections-link>{{icon "plug"}}</a></header> |
| @@ -26,18 +46,12 @@ |
| <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-ended-template><li equipo-system-note data-ended=""><p></p></li></template> |
| <ol equipo-feed> |
| -{{range .Chat.Messages}} |
| -{{if .CardOnly}}{{range .Cards}}{{template "chat-card" .}}{{end}}{{else}} |
| -{{range .Receipts}}{{template "chat-card" .}}{{end}} |
| -<li equipo-message="{{if .Own}}own{{else}}incoming{{end}}" data-message="{{.ID}}" data-turn-id="{{.TurnID}}"> |
| -<div equipo-message-meta><strong{{if .Own}} equipo-visually-hidden{{end}}>{{if .Own}}{{$.Address}}{{else}}{{icon "message-circle"}}{{copy "conversation.coordinator"}}{{end}}</strong><time datetime="{{.CreatedAt.Format "2006-01-02T15:04:05Z07:00"}}">{{.CreatedAt.Format "15:04"}}</time></div> |
| -{{if .Own}}{{template "message-files" .Files}}{{end}}<div equipo-bubble>{{if .Own}}<p equipo-message-body>{{.Text}}</p>{{else}}<div equipo-message-body equipo-markdown>{{chatMarkdown .Text}}</div>{{end}}</div> |
| -{{with .Waiting}}<p equipo-card-note data-waiting-connection>{{.}}</p>{{end}} |
| -{{with .Queued}}<p equipo-card-note data-queued>{{.}}</p>{{end}} |
| -{{with .Switched}}<p equipo-card-note data-switched>{{.}}</p>{{end}} |
| -</li> |
| -{{range .Cards}}{{template "chat-card" .}}{{end}}{{end}} |
| -{{else}}<li data-empty-state="conversation.empty">{{copy "conversation.empty"}}</li>{{end}} |
| +{{range .Chat.Days}}{{template "chat-day" .}}{{end}} |
| +{{if .Chat.Days}}<li equipo-day-divider data-today><span>{{copy "chat.day.today"}}</span></li>{{end}} |
| +{{with .Chat.Open}}<li equipo-system-note data-still-open><p>{{copy "chat.day.still_open"}}</p></li>{{end}} |
| +{{template "chat-lines" (.Chat.Earlier .Address)}} |
| +{{template "chat-lines" (.Chat.Today .Address)}} |
| +{{if not (or .Chat.Days .Chat.Open .Chat.Messages)}}<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}} |
| {{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}} |
diff --git a/internal/equipo/work_pages.go b/internal/equipo/work_pages.go| index 8b833330..b956ab8f 100644 |
| --- a/internal/equipo/work_pages.go |
| +++ b/internal/equipo/work_pages.go |
| @@ -746,31 +746,6 @@ func workBack(r *http.Request, id string) string { |
| var taskIDPattern = regexp.MustCompile(`^tk[a-z0-9]{1,40}$`) |
| -// withMessage extends the conversation's newest messages back to want |
| -// (at most 1,000 older ones), so a task's link to the message it was |
| -// noted from finds it. |
| -func (a *application) withMessage(ctx context.Context, address string, msgs []wire.Message, want string) []wire.Message { |
| - has := func(ms []wire.Message) bool { |
| - return slices.ContainsFunc(ms, func(m wire.Message) bool { return m.ID == want }) |
| - } |
| - if want == "" || len(msgs) == 0 || has(msgs) { |
| - return msgs |
| - } |
| - before := msgs[0].ID |
| - for range 5 { |
| - page, err := a.store.Chat().Messages(ctx, address, before, 200) |
| - if err != nil || len(page.Items) == 0 { |
| - return msgs |
| - } |
| - msgs = append(append([]wire.Message{}, page.Items...), msgs...) |
| - if has(page.Items) || page.Before == "" { |
| - return msgs |
| - } |
| - before = page.Before |
| - } |
| - return msgs |
| -} |
| - |
| // workUncombine is Undo on a task Equipo combined into another; it |
| // returns to the task page it came from (the folded or the surviving one). |
| func (a *application) workUncombine(w http.ResponseWriter, r *http.Request) { |
diff --git a/internal/thintest/rollup_pages_test.go b/internal/thintest/rollup_pages_test.go| new file mode 100644 |
| index 00000000..31a00e7e |
| --- /dev/null |
| +++ b/internal/thintest/rollup_pages_test.go |
| @@ -0,0 +1,237 @@ |
| +package thintest |
| + |
| +import ( |
| + "html" |
| + "regexp" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/chat" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// backdate moves everything the conversation has recorded so far back |
| +// by d, as though it had happened then: messages, turns, cards and tasks. |
| +func (r *toolRig) backdate(d time.Duration) { |
| + r.t.Helper() |
| + db := r.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"}, |
| + {"chat_tasks", "created_at"}, {"chat_tasks", "updated_at"}, {"chat_tasks", "done_at"}, {"chat_tasks", "merged_at"}, |
| + } { |
| + rows, err := db.Query("SELECT rowid, " + tc.col + " FROM " + tc.table + " WHERE " + tc.col + " IS NOT NULL") |
| + if err != nil { |
| + r.t.Fatal(err) |
| + } |
| + at := map[int64]time.Time{} |
| + for rows.Next() { |
| + var id int64 |
| + var t time.Time |
| + if err := rows.Scan(&id, &t); err != nil { |
| + r.t.Fatal(err) |
| + } |
| + at[id] = t |
| + } |
| + rows.Close() |
| + for id, t := range at { |
| + r.setAt(tc.table, tc.col, "rowid = ?", id, t.Add(-d)) |
| + } |
| + } |
| +} |
| + |
| +func (r *toolRig) setAt(table, col, where string, arg any, at time.Time) { |
| + r.t.Helper() |
| + if _, err := r.inst.DB.Writer().Exec("UPDATE "+table+" SET "+col+" = ? WHERE "+where, at.UTC(), arg); err != nil { |
| + r.t.Fatal(err) |
| + } |
| +} |
| + |
| +// messageID is the id of the person's message with text. |
| +func (r *toolRig) messageID(text string) string { |
| + r.t.Helper() |
| + var id string |
| + if err := r.inst.DB.Writer().QueryRow("SELECT id FROM chat_messages WHERE text = ? AND role = ?", text, wire.RolePerson).Scan(&id); err != nil { |
| + r.t.Fatal(text, err) |
| + } |
| + return id |
| +} |
| + |
| +// cutOut is the part of page from the first from to the next to. |
| +func cutOut(t *testing.T, page, from, to string) string { |
| + t.Helper() |
| + _, rest, ok := strings.Cut(page, from) |
| + if !ok { |
| + t.Fatalf("no %s in page", from) |
| + } |
| + part, _, _ := strings.Cut(rest, to) |
| + return part |
| +} |
| + |
| +// rollupRig is a conversation with yesterday behind it: two tasks |
| +// recorded and started; one merged without checks on the person's word |
| +// (a decision); one waiting at Ready to merge with its merge card still |
| +// asking (open). Yesterday's last message was written a moment before |
| +// midnight, today's first at midnight exactly. |
| +type rollupRig struct { |
| + *toolRig |
| + today, yesterday time.Time |
| + asked, merged string |
| + askCard wire.Card |
| + lastWord, firstDay string |
| +} |
| + |
| +func newRollupRig(t *testing.T) *rollupRig { |
| + r := &rollupRig{toolRig: newToolRigAt(t, wire.ProtocolMergeFacts)} |
| + ctx := r.ctx |
| + base := strings.Repeat("1", 40) |
| + r.asked = r.judgedTask("w", "Swipe back on iOS", base, strings.Repeat("2", 40), wire.ChecksCannotRun, "needs_macos") |
| + r.askCard = r.mergeCardsWait(r.asked) |
| + r.merged = r.judgedTask("x", "Edge swipe on iPad", base, strings.Repeat("4", 40), wire.ChecksCannotRun, "needs_macos") |
| + card := r.mergeCardsWait(r.merged) |
| + if _, err := r.client.Answer(ctx, card.ID, wire.ChoiceMerge, card.Revision); err != nil { |
| + t.Fatal(err) |
| + } |
| + m := r.dispatched(wire.SpecialistMerge, base, strings.Repeat("4", 40), 0) |
| + r.mergedStep("x-m", m, strings.Repeat("f", 40)) |
| + r.wait("done", func(c *Conversation) bool { return c.Tasks[r.merged].Stage == wire.StageDone }) |
| + r.expect(wire.FrameForgetTask) |
| + r.next("Leave the iOS one until a Mac is free.") |
| + // All of that was yesterday, around midday. |
| + r.today = chat.DayStart(r.inst.Store.Chat().Now(), r.inst.Store.Chat().Zone(Owner)) |
| + r.yesterday = r.today.AddDate(0, 0, -1) |
| + r.backdate(r.inst.Store.Chat().Now().Sub(r.yesterday.Add(12 * time.Hour))) |
| + r.lastWord = r.messageID("Leave the iOS one until a Mac is free.") |
| + r.setAt("chat_messages", "created_at", "id = ?", r.lastWord, r.today.Add(-time.Nanosecond)) |
| + r.next("Good morning. What is left?") |
| + r.firstDay = r.messageID("Good morning. What is left?") |
| + r.setAt("chat_messages", "created_at", "id = ?", r.firstDay, r.today) |
| + return r |
| +} |
| + |
| +func (r *rollupRig) key(d time.Time) string { return d.Format("2006-01-02") } |
| + |
| +// TestRollupDayBox: once a day is over in the person's zone it is one |
| +// day box at its place in the scrollback: its date, what was started, |
| +// merged and decided, and what is still open, each task a link; none of |
| +// its messages. The day ends at midnight: a message a moment before is |
| +// yesterday's, one at midnight today's. Today is never rolled up. What |
| +// still asks the person (the open merge card, the task underway) stands |
| +// at the top of today with its buttons, never inside the box. |
| +func TestRollupDayBox(t *testing.T) { |
| + r := newRollupRig(t) |
| + page := r.get(r.inst.Cookie(), "/conversation", 200) |
| + y, today := r.key(r.yesterday), r.key(r.today) |
| + if !strings.Contains(page, `<li equipo-day id="day-`+y+`" data-day="`+y+`">`) || !strings.Contains(page, `<time datetime="`+y+`">`+r.yesterday.Format("Monday 2 January")+`</time>`) { |
| + t.Fatalf("no box for yesterday: %s", page) |
| + } |
| + if strings.Contains(page, `id="day-`+today+`"`) || strings.Count(page, "<li equipo-day ") != 1 { |
| + t.Fatalf("today rolled up, or a box too many: %s", page) |
| + } |
| + box := cutOut(t, page, `id="day-`+y+`"`, "</li>") |
| + row := func(key string) string { return cutOut(t, box, `data-row="`+key+`"`, "</div>") } |
| + for _, want := range []struct{ row, text string }{ |
| + {"started", `<a href="/tasks/` + r.asked + `">Swipe back on iOS</a>`}, |
| + {"started", `<a href="/tasks/` + r.merged + `">Edge swipe on iPad</a>`}, |
| + {"merged", `<a href="/tasks/` + r.merged + `">Edge swipe on iPad</a>`}, |
| + {"decided", `<a href="/tasks/` + r.merged + `">Edge swipe on iPad</a> <span equipo-day-decision>Merging without checks.</span>`}, |
| + {"open", `<a href="/tasks/` + r.asked + `">Swipe back on iOS</a>`}, |
| + } { |
| + if !strings.Contains(row(want.row), want.text) { |
| + t.Fatalf("%s row lacks %q: %s", want.row, want.text, box) |
| + } |
| + } |
| + if strings.Contains(row("merged"), r.asked) || strings.Contains(row("open"), r.merged) { |
| + t.Fatalf("a task in the wrong row: %s", box) |
| + } |
| + if !strings.Contains(box, `href="/conversation?day=`+y+`#day-`+y+`"`) || !strings.Contains(box, "Show the conversation") || strings.Contains(box, "data-message") { |
| + t.Fatalf("box not collapsed with its way in: %s", box) |
| + } |
| + // The day boundary: a moment before midnight is rolled up, midnight is |
| + // today's. |
| + if strings.Contains(page, `data-message="`+r.lastWord+`"`) || strings.Contains(page, "Leave the iOS one until a Mac is free.") { |
| + t.Fatalf("yesterday's last message outside its box: %s", page) |
| + } |
| + if !strings.Contains(page, `data-message="`+r.firstDay+`"`) { |
| + t.Fatalf("today's first message rolled up: %s", page) |
| + } |
| + // What still needs the person stands at the top of today, once, with |
| + // its buttons. |
| + todayPart := page[strings.Index(page, "data-today"):] |
| + if !strings.Contains(todayPart, "data-still-open") || strings.Count(page, `data-card="`+r.askCard.ID+`"`) != 1 || !strings.Contains(cutOut(t, todayPart, `data-card="`+r.askCard.ID+`"`, "</li>"), `data-merge-choice="merge"`) { |
| + t.Fatalf("the open merge card is not at the top of today: %s", page) |
| + } |
| + if !strings.Contains(todayPart, `<a href="/tasks/`+r.asked+`">Swipe back on iOS</a>`) { |
| + t.Fatalf("the task underway is not at the top of today: %s", todayPart) |
| + } |
| + if strings.Index(todayPart, `data-card="`+r.askCard.ID+`"`) > strings.Index(todayPart, `data-message="`+r.firstDay+`"`) { |
| + t.Fatal("open items after today's messages") |
| + } |
| + // The transcript itself is unchanged: the API's snapshot still has |
| + // yesterday's messages. |
| + snap, err := r.client.Snapshot(r.ctx) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + found := false |
| + for _, m := range snap.Messages { |
| + found = found || m.ID == r.lastWord |
| + } |
| + if !found { |
| + t.Fatal("yesterday's messages left the transcript") |
| + } |
| +} |
| + |
| +// TestRollupExpand: Show the conversation (?day=) opens the day's |
| +// transcript in place, under its box: its messages and its receipts, |
| +// with Hide the conversation. A card still asking is shown once, at the |
| +// top of today. A task's "From your conversation" link to a message on |
| +// an earlier day opens that day at the message; Ask about this still |
| +// fills the composer; days that do not exist or are today open nothing. |
| +func TestRollupExpand(t *testing.T) { |
| + r := newRollupRig(t) |
| + y := r.key(r.yesterday) |
| + page := r.get(r.inst.Cookie(), "/conversation?day="+y, 200) |
| + if !strings.Contains(page, `<li equipo-day id="day-`+y+`" data-day="`+y+`" data-expanded>`) { |
| + t.Fatalf("day not open: %s", page) |
| + } |
| + feed := cutOut(t, page, `id="day-feed-`+y+`"`, "data-today") |
| + if !strings.Contains(feed, `data-message="`+r.lastWord+`"`) || !strings.Contains(feed, "Leave the iOS one until a Mac is free.") || !strings.Contains(feed, `<a href="/tasks/`+r.merged+`">Edge swipe on iPad</a>`) { |
| + t.Fatalf("the day's transcript is not under its box: %s", feed) |
| + } |
| + if strings.Contains(feed, `data-message="`+r.firstDay+`"`) { |
| + t.Fatal("today's message in yesterday's transcript") |
| + } |
| + if !strings.Contains(page, `href="/conversation#day-`+y+`" data-day-toggle="`+y+`" aria-expanded="true"`) || !strings.Contains(page, "Hide the conversation") { |
| + t.Fatalf("no way to close the day: %s", page) |
| + } |
| + if n := strings.Count(page, `data-card="`+r.askCard.ID+`"`); n != 1 { |
| + t.Fatalf("the open card shows %d times", n) |
| + } |
| + // Nonsense and today open nothing. |
| + for _, q := range []string{"day=" + r.key(r.today), "day=yesterday", "day=" + r.key(r.today.AddDate(0, 0, 3))} { |
| + if p := r.get(r.inst.Cookie(), "/conversation?"+q, 200); strings.Contains(p, "data-expanded") || strings.Count(p, "<li equipo-day ") != 1 { |
| + t.Fatalf("?%s opened something: %s", q, p) |
| + } |
| + } |
| + // The task page's link to the message it was noted from. |
| + task := r.get(r.inst.Cookie(), "/tasks/"+r.asked, 200) |
| + m := regexp.MustCompile(`href="(/conversation\?message=[^"#]+)#m-([^"]+)"`).FindStringSubmatch(task) |
| + if m == nil { |
| + t.Fatalf("no link to the conversation on the task page: %s", task) |
| + } |
| + linked := r.get(r.inst.Cookie(), html.UnescapeString(m[1]), 200) |
| + if !strings.Contains(linked, `data-day="`+y+`" data-expanded`) || !strings.Contains(cutOut(t, linked, `id="day-feed-`+y+`"`, "data-today"), `data-message="`+m[2]+`"`) { |
| + t.Fatalf("the link did not open its day at the message %s: %s", m[2], linked) |
| + } |
| + ask := r.get(r.inst.Cookie(), "/conversation?about="+r.merged, 200) |
| + if !strings.Contains(ask, "Edge swipe on iPad") || !strings.Contains(ask, "autofocus>") { |
| + t.Fatalf("Ask about this lost its draft: %s", ask) |
| + } |
| + // A teammate's day is their own: no box, no task of the owner's. |
| + mate := r.memberCookie() |
| + if p := r.get(mate, "/conversation?day="+y, 200); strings.Contains(p, "<li equipo-day ") || strings.Contains(p, "Leave the iOS one") { |
| + t.Fatalf("a teammate sees the owner's day: %s", p) |
| + } |
| +} |