Persist personal set-aside state with undo and action feedback
14 files changed,
+442
−19
internal/equipo/app.go+1 −0internal/equipo/chat/models.go+1 −1internal/equipo/chat/roster.go+177 −0internal/equipo/chat/roster_test.go+59 −0internal/equipo/chat_page.go+18 −1internal/equipo/chat_roster.go+57 −2internal/equipo/migrations/0086_conversation_roster.sql+4 −0internal/equipo/rail.go+3 −1internal/equipo/static/chat-stream.js+61 −10internal/equipo/static/equipo.css+15 −0internal/equipo/templates/chat.html+7 −4internal/equipo/templates/work_needs.html+1 −0internal/equipo/work_pages.go+9 −0internal/thintest/roster_browser_test.go+29 −0
CI failed — run details
diff --git a/internal/equipo/app.go b/internal/equipo/app.go| index 74dfa493..f7886117 100644 |
| --- a/internal/equipo/app.go |
| +++ b/internal/equipo/app.go |
| @@ -301,6 +301,7 @@ func RouterWithStore(d *db.DB, cfg Config, mailer mail.Sender, logger *slog.Logg |
| r.Get("/conversation/attachments/{id}", a.chatAttachment(false)) |
| r.Get("/conversation/attachments/{id}/preview", a.chatAttachment(true)) |
| r.Post("/conversation/cards/{id}/answer", a.chatCardAnswer) |
| + r.Post("/conversation/cards/{id}/visibility", a.chatCardVisibility) |
| r.Get("/jobs", a.jobsPage) |
| r.Get("/jobs/{id}", a.jobPage) |
| r.Post("/jobs/{id}/messages", a.jobSend) |
diff --git a/internal/equipo/chat/models.go b/internal/equipo/chat/models.go| index 42c8a828..d530a8e7 100644 |
| --- a/internal/equipo/chat/models.go |
| +++ b/internal/equipo/chat/models.go |
| @@ -7,7 +7,7 @@ package chat |
| import "time" |
| // Models are the tables this package owns, for the migration check. |
| -var Models = []any{©AttemptRecord{}, ©ReviewRecord{}, ©FeedbackRecord{}, &turnRecord{}, &messageRecord{}, &eventRecord{}, &commandRecord{}, &inboxRecord{}, &runnerSessionRecord{}, &projectRecord{}, &cardRecord{}, &toolCallRecord{}, &settingRecord{}, &coordinatorRecord{}, ¬ebookRecord{}, &taskRecord{}, &stepRecord{}, &entryRecord{}, &attachmentRecord{}, &starRecord{}, &questionRecord{}, &connectionRecord{}, &usageRecord{}, &distinctRecord{}, &hkRecord{}, &hkFailureRecord{}, &hkSettingsRecord{}, &fileRecord{}, &fileDataRecord{}, &transferRecord{}, &mergePolicyRecord{}, &mergeAuditRecord{}, &specialistRecord{}, &grantRecord{}, &specialistAuditRecord{}, &researchSourceRecord{}, &researchAddressRecord{}, &researchPrefixRecord{}, &researchInventoryRecord{}, &researchRecord{}, &researchFetchRecord{}, &taskFileRecord{}, &taskFileDataRecord{}, &releaseRecord{}, &adviceRecord{}, &assistantHostRecord{}, &handoffRecord{}, &handoffTurnRecord{}, &handoffTaskRecord{}, &handoffActionRecord{}} |
| +var Models = []any{&cardVisibility{}, &cardThreadRecord{}, ©AttemptRecord{}, ©ReviewRecord{}, ©FeedbackRecord{}, &turnRecord{}, &messageRecord{}, &eventRecord{}, &commandRecord{}, &inboxRecord{}, &runnerSessionRecord{}, &projectRecord{}, &cardRecord{}, &toolCallRecord{}, &settingRecord{}, &coordinatorRecord{}, ¬ebookRecord{}, &taskRecord{}, &stepRecord{}, &entryRecord{}, &attachmentRecord{}, &starRecord{}, &questionRecord{}, &connectionRecord{}, &usageRecord{}, &distinctRecord{}, &hkRecord{}, &hkFailureRecord{}, &hkSettingsRecord{}, &fileRecord{}, &fileDataRecord{}, &transferRecord{}, &mergePolicyRecord{}, &mergeAuditRecord{}, &specialistRecord{}, &grantRecord{}, &specialistAuditRecord{}, &researchSourceRecord{}, &researchAddressRecord{}, &researchPrefixRecord{}, &researchInventoryRecord{}, &researchRecord{}, &researchFetchRecord{}, &taskFileRecord{}, &taskFileDataRecord{}, &releaseRecord{}, &adviceRecord{}, &assistantHostRecord{}, &handoffRecord{}, &handoffTurnRecord{}, &handoffTaskRecord{}, &handoffActionRecord{}} |
| type turnRecord struct { |
| ID string `gorm:"primaryKey"` |
diff --git a/internal/equipo/chat/roster.go b/internal/equipo/chat/roster.go| new file mode 100644 |
| index 00000000..fe419546 |
| --- /dev/null |
| +++ b/internal/equipo/chat/roster.go |
| @@ -0,0 +1,177 @@ |
| +package chat |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| + "gorm.io/gorm" |
| + "gorm.io/gorm/clause" |
| +) |
| + |
| +type cardVisibility struct { |
| + Person string `gorm:"primaryKey"` |
| + CardID string `gorm:"primaryKey"` |
| + Aside bool |
| + UpdatedAt time.Time |
| +} |
| + |
| +func (cardVisibility) TableName() string { return "chat_card_visibility" } |
| + |
| +type cardThreadRecord struct { |
| + ID string `gorm:"primaryKey"` |
| + CardID string `gorm:"index:chat_card_thread_card"` |
| + Person string |
| + TurnID string |
| + StepID string |
| + Text string |
| + CreatedAt time.Time |
| +} |
| + |
| +func (cardThreadRecord) TableName() string { return "chat_card_threads" } |
| + |
| +// CardPresentation is browser presentation only. Visibility is separate |
| +// from the decision and never changes a card's revision or authority. |
| +type CardPresentation struct { |
| + Aside bool |
| + Thread []CardThreadTurn |
| + Waiting bool |
| + TurnID string |
| +} |
| +type CardThreadTurn struct { |
| + Own bool |
| + Text string |
| + At time.Time |
| +} |
| + |
| +func (s *Store) SetCardAside(ctx context.Context, person, id string, revision int64, aside bool) error { |
| + return s.tx(ctx, func(t *txn) error { |
| + if err := s.authority.CurrentPerson(ctx, t.db); err != nil { |
| + return err |
| + } |
| + var c cardRecord |
| + if err := t.db.Where("id = ? AND person = ? AND "+coordinatorRole, id, person).First(&c).Error; errors.Is(err, gorm.ErrRecordNotFound) { |
| + return ErrNotFound |
| + } else if err != nil { |
| + return err |
| + } |
| + if c.Revision != revision { |
| + return ErrCardConflict |
| + } |
| + if c.State != wire.CardOpen && c.State != wire.CardHomeAsk && c.Kind != wire.CardTask { |
| + return ErrCardConflict |
| + } |
| + if c.Kind == wire.CardTask { |
| + k, err := t.loadTask(c.TaskID) |
| + if err != nil { |
| + return err |
| + } |
| + v, err := t.taskView(k) |
| + if err != nil { |
| + return err |
| + } |
| + if !v.CopyHold { |
| + return ErrCardConflict |
| + } |
| + } |
| + v := cardVisibility{Person: person, CardID: id, Aside: aside, UpdatedAt: t.now()} |
| + if err := t.db.Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "person"}, {Name: "card_id"}}, DoUpdates: clause.AssignmentColumns([]string{"aside", "updated_at"})}).Create(&v).Error; err != nil { |
| + return err |
| + } |
| + if err := s.authority.Audit(t.db, person, "card.visibility", id); err != nil { |
| + return err |
| + } |
| + return t.cardEvent(c) |
| + }) |
| +} |
| + |
| +func (s *Store) CardPresentations(ctx context.Context, person string, ids []string) (out map[string]CardPresentation, err error) { |
| + out = map[string]CardPresentation{} |
| + if len(ids) == 0 { |
| + return out, nil |
| + } |
| + 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 id IN ? AND "+coordinatorRole, person, ids).Find(&cards).Error; err != nil { |
| + return err |
| + } |
| + for _, c := range cards { |
| + p := CardPresentation{} |
| + var vs []cardVisibility |
| + if err := tx.Where("person = ? AND card_id = ?", person, c.ID).Find(&vs).Error; err != nil { |
| + return err |
| + } |
| + if len(vs) > 0 { |
| + p.Aside = vs[0].Aside |
| + } |
| + var links []cardThreadRecord |
| + if err := tx.Where("person = ? AND card_id = ?", person, c.ID).Order("created_at, id").Find(&links).Error; err != nil { |
| + return err |
| + } |
| + if c.AnswerMessage != "" { |
| + var m messageRecord |
| + if err := tx.Where("person = ? AND id = ?", person, c.AnswerMessage).First(&m).Error; err != nil { |
| + return err |
| + } |
| + links = append([]cardThreadRecord{{TurnID: m.TurnID}}, links...) |
| + } |
| + for _, link := range links { |
| + if link.TurnID != "" { |
| + var ms []messageRecord |
| + if err := tx.Where("person = ? AND turn_id = ?", person, link.TurnID).Order("seq").Find(&ms).Error; err != nil { |
| + return err |
| + } |
| + for _, m := range ms { |
| + p.Thread = append(p.Thread, CardThreadTurn{Own: m.Role == wire.RolePerson, Text: m.Text, At: m.CreatedAt}) |
| + } |
| + var turn turnRecord |
| + if err := tx.Where("person = ? AND id = ?", person, link.TurnID).First(&turn).Error; err != nil { |
| + return err |
| + } |
| + p.Waiting = turn.State == wire.TurnQueued || turn.State == wire.TurnRunning || turn.State == wire.TurnWaiting |
| + p.TurnID = turn.ID |
| + } else { |
| + p.Thread = append(p.Thread, CardThreadTurn{Own: true, Text: link.Text, At: link.CreatedAt}) |
| + var step stepRecord |
| + if err := tx.First(&step, "id = ?", link.StepID).Error; err != nil { |
| + return err |
| + } |
| + p.Waiting = step.State == wire.StepQueued || step.State == wire.StepRunning |
| + if step.Summary != "" { |
| + p.Thread = append(p.Thread, CardThreadTurn{Text: step.Summary, At: step.UpdatedAt}) |
| + } |
| + } |
| + } |
| + out[c.ID] = p |
| + } |
| + return nil |
| + }) |
| + return |
| +} |
| + |
| +// OpenStandaloneCards keeps questions without a task reachable in Needs you. |
| +func (s *Store) OpenStandaloneCards(ctx context.Context, person string) (out []wire.Card, err error) { |
| + err = s.read(ctx, func(tx *gorm.DB) error { |
| + if err := s.authority.CurrentPerson(ctx, tx); err != nil { |
| + return err |
| + } |
| + var cs []cardRecord |
| + if err := tx.Where("person = ? AND coalesce(task_id, '') = '' AND state IN ? AND "+coordinatorRole, person, []string{wire.CardOpen, wire.CardHomeAsk}).Order("created_at, id").Find(&cs).Error; err != nil { |
| + return err |
| + } |
| + t := &txn{s: s, db: tx, ctx: ctx} |
| + for _, c := range cs { |
| + v, err := t.cardView(c) |
| + if err != nil { |
| + return err |
| + } |
| + out = append(out, v) |
| + } |
| + return nil |
| + }) |
| + return |
| +} |
diff --git a/internal/equipo/chat/roster_test.go b/internal/equipo/chat/roster_test.go| new file mode 100644 |
| index 00000000..d6551123 |
| --- /dev/null |
| +++ b/internal/equipo/chat/roster_test.go |
| @@ -0,0 +1,59 @@ |
| +package chat |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "reflect" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +func TestRosterSetAsideNeverAnswersOrCancels(t *testing.T) { |
| + r := newMeteredRig(t) |
| + ctx := context.Background() |
| + now := r.s.now() |
| + c := cardRecord{ID: "c_roster", Person: hkOwner, Kind: wire.CardQuestion, State: wire.CardOpen, Question: "Which page?", Options: "[]", Revision: 1, CreatedAt: now, UpdatedAt: now} |
| + if err := r.s.db.G.Create(&c).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := r.s.SetCardAside(ctx, hkMember, c.ID, 1, true); !errors.Is(err, ErrNotFound) { |
| + t.Fatalf("other person: %v", err) |
| + } |
| + r.removed = true |
| + if err := r.s.SetCardAside(ctx, hkOwner, c.ID, 1, true); !errors.Is(err, ErrForbidden) { |
| + t.Fatalf("removed: %v", err) |
| + } |
| + r.removed = false |
| + if err := r.s.SetCardAside(ctx, hkOwner, c.ID, 0, true); !errors.Is(err, ErrCardConflict) { |
| + t.Fatalf("stale: %v", err) |
| + } |
| + for _, aside := range []bool{true, true, false, true, false} { |
| + if err := r.s.SetCardAside(ctx, hkOwner, c.ID, 1, aside); err != nil { |
| + t.Fatal(err) |
| + } |
| + var after cardRecord |
| + if err := r.s.db.G.First(&after, "id = ?", c.ID).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + if !reflect.DeepEqual(after, c) { |
| + t.Fatalf("set aside answered or changed card: %+v", after) |
| + } |
| + for _, table := range []string{"runner_commands", "chat_messages", "chat_steps"} { |
| + var n int64 |
| + if err := r.s.db.G.Table(table).Count(&n).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + if n != 0 { |
| + t.Fatalf("set aside dispatched or cancelled work: %s=%d", table, n) |
| + } |
| + } |
| + got, err := r.s.CardPresentations(ctx, hkOwner, []string{c.ID}) |
| + if err != nil || got[c.ID].Aside != aside { |
| + t.Fatalf("persistence: %+v %v", got, err) |
| + } |
| + } |
| + if len(r.audits) != 5 { |
| + t.Fatalf("visibility writes not audited: %v", r.audits) |
| + } |
| +} |
diff --git a/internal/equipo/chat_page.go b/internal/equipo/chat_page.go| index 7816979d..401a343f 100644 |
| --- a/internal/equipo/chat_page.go |
| +++ b/internal/equipo/chat_page.go |
| @@ -83,6 +83,7 @@ type chatLine struct { |
| type chatCard struct { |
| wire.Card |
| Line, Change, Agent, Namespace, Note string |
| + Presentation chat.CardPresentation |
| Author, AuthorIcon, Verb string |
| // GrantHow introduces an access card's grant command. |
| GrantHow string |
| @@ -397,6 +398,10 @@ func (a *application) chatPage(w http.ResponseWriter, r *http.Request) { |
| } |
| view.Ended = &chatEnded{ID: latest.ID, Key: key} |
| } |
| + if err := a.presentRoster(ctx, address, &view); err != nil { |
| + a.failure(w, r, chatError(err)) |
| + return |
| + } |
| data.Chat, data.ChatStream, data.RequestID = view, true, rand.Text() |
| data.ThinkingSet, data.ThinkingWords = a.thinkingFor(ctx, address) |
| render(w, "chat", data) |
| @@ -512,6 +517,10 @@ func (a *application) jobPage(w http.ResponseWriter, r *http.Request) { |
| view.Waiting = append(view.Waiting, t) |
| } |
| } |
| + if err := a.presentRoster(ctx, address, &view); err != nil { |
| + a.failure(w, r, chatError(err)) |
| + return |
| + } |
| data.Chat, data.RequestID = view, rand.Text() |
| render(w, "chat", data) |
| } |
| @@ -638,7 +647,15 @@ func (a *application) chatActionTo(w http.ResponseWriter, r *http.Request, back |
| a.failure(w, r, ErrForbidden) |
| return |
| } |
| - if err := act(ctx, address); err != nil && !errors.Is(err, chat.ErrCardConflict) { |
| + if err := act(ctx, address); err != nil { |
| + if errors.Is(err, chat.ErrCardConflict) { |
| + if strings.Contains(r.Header.Get("Accept"), "application/json") { |
| + runnerJSON(w, http.StatusConflict, struct{}{}) |
| + return |
| + } |
| + http.Redirect(w, r, back, http.StatusSeeOther) |
| + return |
| + } |
| a.failure(w, r, chatError(err)) |
| return |
| } |
diff --git a/internal/equipo/chat_roster.go b/internal/equipo/chat_roster.go| index 137ea4d8..2faa41c7 100644 |
| --- a/internal/equipo/chat_roster.go |
| +++ b/internal/equipo/chat_roster.go |
| @@ -1,6 +1,13 @@ |
| package equipo |
| -import "amadan.net/oficina/equipo/internal/wire" |
| +import ( |
| + "amadan.net/oficina/equipo/internal/equipo/chat" |
| + "amadan.net/oficina/equipo/internal/wire" |
| + "context" |
| + "github.com/go-chi/chi/v5" |
| + "net/http" |
| + "strconv" |
| +) |
| func (v *chatCard) rosterAuthor(tasks map[string]wire.Task) { |
| v.Author, v.AuthorIcon, v.Verb = copyText("conversation.coordinator"), "sparkles", copyText("roster.reports") |
| @@ -16,6 +23,54 @@ func (v *chatCard) rosterAuthor(tasks map[string]wire.Task) { |
| who, v.Verb = wire.SpecialistCopy, copyText("roster.holds") |
| } |
| v.Author = specialistName(who) |
| - v.AuthorIcon = map[string]string{wire.SpecialistEngineering: "wrench", wire.SpecialistResearch: "search", wire.SpecialistCopy: "type"}[who] |
| + v.AuthorIcon = map[string]string{wire.SpecialistEngineering: "code", wire.SpecialistResearch: "search", wire.SpecialistCopy: "file-text"}[who] |
| } |
| } |
| + |
| +func (v chatCard) Interactive() bool { |
| + return v.Open && (!v.Receipt || v.Task != nil && v.Task.CopyHold) |
| +} |
| +func (v chatCard) SetAside() bool { return v.Interactive() && v.Presentation.Aside } |
| + |
| +func (a *application) presentRoster(ctx context.Context, address string, view *chatView) error { |
| + var cards []*chatCard |
| + collect := func(lines []chatLine) { |
| + for i := range lines { |
| + for _, cs := range [][]chatCard{lines[i].Cards, lines[i].Receipts} { |
| + for j := range cs { |
| + cards = append(cards, &cs[j]) |
| + } |
| + } |
| + } |
| + } |
| + collect(view.Messages) |
| + collect(view.Open) |
| + for i := range view.Days { |
| + collect(view.Days[i].Feed.Lines) |
| + } |
| + ids := make([]string, 0, len(cards)) |
| + for _, c := range cards { |
| + ids = append(ids, c.ID) |
| + } |
| + ps, err := a.store.Chat().CardPresentations(ctx, address, ids) |
| + if err != nil { |
| + return err |
| + } |
| + for _, c := range cards { |
| + c.Presentation = ps[c.ID] |
| + } |
| + return nil |
| +} |
| +func (a *application) chatCardVisibility(w http.ResponseWriter, r *http.Request) { |
| + a.chatActionTo(w, r, workBack(r, r.PostFormValue("task")), func(ctx context.Context, address string) error { |
| + revision, err := strconv.ParseInt(r.PostFormValue("revision"), 10, 64) |
| + if err != nil { |
| + return chat.ErrInvalid |
| + } |
| + value := r.PostFormValue("aside") |
| + if value != "true" && value != "false" { |
| + return chat.ErrInvalid |
| + } |
| + return a.store.Chat().SetCardAside(ctx, address, chi.URLParam(r, "id"), revision, value == "true") |
| + }) |
| +} |
diff --git a/internal/equipo/migrations/0086_conversation_roster.sql b/internal/equipo/migrations/0086_conversation_roster.sql| new file mode 100644 |
| index 00000000..fdf55845 |
| --- /dev/null |
| +++ b/internal/equipo/migrations/0086_conversation_roster.sql |
| @@ -0,0 +1,4 @@ |
| +-- A person's stream visibility is independent of the decision. |
| +CREATE TABLE chat_card_visibility (person text, card_id text, aside numeric, updated_at datetime, PRIMARY KEY (person, card_id)); |
| +CREATE TABLE chat_card_threads (id text PRIMARY KEY, card_id text, person text, turn_id text, step_id text, text text, created_at datetime); |
| +CREATE INDEX chat_card_thread_card ON chat_card_threads(card_id); |
diff --git a/internal/equipo/rail.go b/internal/equipo/rail.go| index 8be0d83a..a5164114 100644 |
| --- a/internal/equipo/rail.go |
| +++ b/internal/equipo/rail.go |
| @@ -99,7 +99,9 @@ func (a *application) rail(ctx context.Context, person string) railView { |
| needs++ |
| } |
| } |
| - v.Needs = railCount{needs, true} |
| + if questions, err := c.OpenStandaloneCards(ctx, person); err == nil { |
| + v.Needs = railCount{needs + len(questions), true} |
| + } |
| } |
| } |
| if conns, err := c.Connections(ctx, person); err == nil { |
diff --git a/internal/equipo/static/chat-stream.js b/internal/equipo/static/chat-stream.js| index a0646e54..06d92d70 100644 |
| --- a/internal/equipo/static/chat-stream.js |
| +++ b/internal/equipo/static/chat-stream.js |
| @@ -798,6 +798,16 @@ |
| var more = el.querySelector("[equipo-receipt-more]"); |
| if (more) more.setAttribute("aria-expanded", "true"); |
| }); |
| + feed.querySelectorAll("[data-card]").forEach(function (card) { |
| + var inputs = {}; |
| + card.querySelectorAll("textarea, input:not([type=hidden])").forEach(function (el) { if (el.value) inputs[el.name] = el.value; }); |
| + if (Object.keys(inputs).length) cardDrafts.set(card.dataset.card, inputs); |
| + }); |
| + next.querySelectorAll("[data-card]").forEach(function (card) { |
| + var old = cardBusy.get(card.dataset.card); if (old) { card.replaceWith(old); return; } |
| + var values = cardDrafts.get(card.dataset.card); if (!values) return; |
| + card.querySelectorAll("textarea, input:not([type=hidden])").forEach(function (el) { if (values[el.name]) { el.value = values[el.name]; el.closest("form").setAttribute("data-has-content", ""); } }); |
| + }); |
| feed.querySelectorAll("[data-message]").forEach(function (el) { shown[el.dataset.message] = true; }); |
| feed.replaceChildren.apply(feed, Array.from(next.children).map(function (el) { |
| var fresh = el.matches('[equipo-message="incoming"][data-turn-id]') && !shown[el.dataset.message]; |
| @@ -1035,17 +1045,58 @@ |
| 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) { |
| - var f = event.target.closest("[data-card-form]"); |
| - if (!f) return; |
| - event.preventDefault(); |
| - var body = new URLSearchParams(new FormData(f, event.submitter)); |
| - f.querySelectorAll("button").forEach(function (b) { b.disabled = true; }); |
| + // Card actions preserve the card on failure and expose the result in place. |
| + var cardBusy = new Map(), cardDrafts = new Map(), toastTimer; |
| + function cardSubmit(f, button) { |
| + var card = f.closest("[data-card]"), id = card && card.dataset.card; |
| + if (id && cardBusy.has(id)) return; |
| + var body = new URLSearchParams(new FormData(f, button)); |
| + var previous = button && button.innerHTML; |
| + var controls = card || f; |
| + if (id) cardBusy.set(id, card); |
| + controls.setAttribute("aria-busy", "true"); |
| + controls.querySelectorAll("button").forEach(function (b) { b.disabled = true; }); |
| + if (button) { button.setAttribute("aria-busy", "true"); button.textContent = button.dataset.busyLabel || root.dataset.cardBusy; } |
| + var error = controls.querySelector("[equipo-card-error]"); |
| + if (error) error.hidden = true; |
| fetch(f.action, { method: "POST", credentials: "same-origin", headers: { "Accept": "application/json" }, body: body }) |
| - .then(function (r) { if (!r.ok) throw new Error("card"); return refresh(); }) |
| - .catch(function () { refreshSoon(); }); |
| + .then(function (r) { if (!r.ok) throw new Error(r.status === 409 ? "stale" : "card"); |
| + if (id) { cardBusy.delete(id); if (body.get("aside") === null) cardDrafts.delete(id); } |
| + return refreshed(); |
| + }).then(function () { |
| + if (body.get("aside") === "true") { |
| + var stub = feed.querySelector('[data-card="' + CSS.escape(id) + '"] [equipo-aside-stub]'); |
| + var toast = root.querySelector("[equipo-roster-toast]"); |
| + if (stub && toast) { |
| + toast.replaceChildren(document.createTextNode(root.dataset.asideLabel), stub.querySelector("form").cloneNode(true)); |
| + toast.hidden = false; |
| + clearTimeout(toastTimer); toastTimer = setTimeout(function () { toast.hidden = true; }, 7000); |
| + var undo = stub.querySelector("button"); if (undo) undo.focus({preventScroll:true}); |
| + } |
| + } else if (body.get("aside") === "false") { |
| + var toast = root.querySelector("[equipo-roster-toast]"); if (toast) toast.hidden = true; |
| + var restored = feed.querySelector('[data-card="' + CSS.escape(id) + '"] [data-set-aside]'); if (restored) restored.focus({preventScroll:true}); |
| + } |
| + }).catch(function (e) { |
| + if (id) cardBusy.delete(id); |
| + controls.removeAttribute("aria-busy"); |
| + controls.querySelectorAll("button").forEach(function (b) { b.disabled = false; }); |
| + if (button) { button.removeAttribute("aria-busy"); button.innerHTML = previous; } |
| + if (!error) { error = document.createElement("p"); error.setAttribute("equipo-card-error", ""); error.setAttribute("role", "alert"); controls.append(error); } |
| + error.hidden = false; |
| + error.textContent = e.message === "stale" ? root.dataset.cardStale : root.dataset.cardFailed; |
| + var retry = document.createElement("button"); retry.type = "button"; retry.setAttribute("equipo-link", ""); retry.textContent = root.dataset.cardRetry; |
| + retry.addEventListener("click", function () { if (e.message === "stale") refreshed(); else cardSubmit(f, button); }); error.append(retry); |
| + }); |
| + } |
| + root.addEventListener("submit", function (event) { |
| + var f = event.target.closest("[data-card-form]"); if (!f) return; |
| + event.preventDefault(); |
| + // A toast uses the live stub's form, so it has the card's revision. |
| + if (f.closest("[equipo-roster-toast]")) { |
| + var match = feed.querySelector('form[action="' + CSS.escape(f.getAttribute("action")) + '"]'); |
| + if (match) cardSubmit(match, match.querySelector("button")); |
| + } else cardSubmit(f, event.submitter); |
| }); |
| // Sending stays on this page: no navigation, so no page transition. The |
| // bubble shows at once; the background post uses the form's own action |
diff --git a/internal/equipo/static/equipo.css b/internal/equipo/static/equipo.css| index 936f9f88..e5a9628e 100644 |
| --- a/internal/equipo/static/equipo.css |
| +++ b/internal/equipo/static/equipo.css |
| @@ -1815,3 +1815,18 @@ label[equipo-sp-label] { cursor: pointer; } |
| [equipo-roster-card] button { min-block-size: 2.75rem; } |
| [equipo-roster-card] [rst-btn="primary"] { grid-column: 1 / -1; } |
| } |
| +[equipo-set-aside] { position: absolute; inset-block-start: .375rem; inset-inline-end: .375rem; z-index: 1; } |
| +[equipo-set-aside] button { display: grid; place-items: center; border: 0; border-radius: var(--rst-radius); background: transparent; color: var(--rst-text-muted); inline-size: 2.25rem; block-size: 2.25rem; cursor: pointer; } |
| +[equipo-roster-card][data-ask] > [equipo-card-line] { padding-inline-end: 2rem; font-size: 1.125rem; font-weight: 650; line-height: 1.3; } |
| +[equipo-roster-card] button:hover { filter: none; background-color: var(--rst-control-face-hover); } |
| +[equipo-set-aside] button:active { background: var(--rst-control-face-press); transform: translateY(1px); } |
| +[equipo-roster-card] button:focus-visible, [equipo-aside-stub] button:focus-visible { outline: 2px solid var(--rst-accent); outline-offset: 2px; } |
| +[equipo-roster-card] button:disabled { cursor: wait; opacity: .55; } |
| +[equipo-roster-card] button[aria-busy="true"] { opacity: 1; } |
| +[equipo-aside-stub] { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: .5rem; padding: .5rem .75rem; border: 1px dashed var(--rst-control-border); border-radius: calc(2 * var(--rst-radius)); } |
| +[equipo-aside-stub] small { color: var(--rst-text-muted); } |
| +[equipo-roster-toast] { position: absolute; inset-block-end: 6.5rem; inset-inline: 1rem; margin-inline: auto; max-inline-size: 40rem; padding: .75rem 1rem; border: 1px solid var(--rst-light-rim); border-radius: calc(2 * var(--rst-radius)); background: var(--rst-surface); box-shadow: var(--rst-shadow-pop); z-index: 5; display: flex; gap: .75rem; flex-wrap: wrap; align-items: baseline; } |
| +[equipo-roster-toast][hidden] { display: none; } |
| +[equipo-card-error] { color: var(--rst-tone-negative-fg); font-size: var(--rst-fs-sm); margin: 0; } |
| +[equipo-card-error] button { margin-inline-start: .5rem; } |
| +@media (max-width: 500px) { [equipo-chat-header] > [equipo-header-button] { display: none; } [equipo-set-aside] button { inline-size: 2.75rem; } } |
diff --git a/internal/equipo/templates/chat.html b/internal/equipo/templates/chat.html| index abcff7cf..8e2fa4c7 100644 |
| --- a/internal/equipo/templates/chat.html |
| +++ b/internal/equipo/templates/chat.html |
| @@ -1,8 +1,9 @@ |
| {{define "up-label"}}{{copy "nav.work"}}{{end}} |
| {{define "title"}}{{if .Chat.Job}}{{copy "jobs.title"}}{{else}}{{copy "conversation.title"}}{{end}}{{end}} |
| {{define "card-job"}}{{with .Job}}<input type="hidden" name="from" value="job"><input type="hidden" name="job" value="{{.}}">{{end}}{{end}} |
| -{{define "chat-card"}}<li equipo-card="{{.Kind}}"{{if .Receipt}} equipo-receipt{{end}} data-card="{{.ID}}" data-state="{{.State}}" data-turn-id="{{.TurnID}}"> |
| -{{template "roster-byline" .}}<section equipo-roster-card{{if and .Open (not .Receipt)}} data-ask{{end}}{{if .Receipt}} data-flat{{end}}> |
| +{{define "chat-card"}}<li equipo-card="{{.Kind}}"{{if .Receipt}} equipo-receipt{{end}} id="card-{{.ID}}" data-card="{{.ID}}" data-state="{{.State}}" data-turn-id="{{.TurnID}}"> |
| +{{template "roster-byline" .}}{{if .SetAside}}<section equipo-aside-stub><span>{{.Line}} <small>{{copy "roster.aside"}}</small></span>{{template "roster-undo" .}}</section>{{else}}<section equipo-roster-card{{if .Interactive}} data-ask{{end}}{{if .Receipt}} data-flat{{end}}> |
| +{{if .Interactive}}<form method="post" action="/conversation/cards/{{.ID}}/visibility" data-card-form equipo-set-aside><input type="hidden" name="revision" value="{{.Revision}}"><input type="hidden" name="aside" value="true">{{template "card-job" .}}<button type="submit" data-set-aside aria-label="{{copy "roster.set_aside"}}" title="{{copy "roster.set_aside"}}" data-busy-label="{{copy "roster.setting_aside"}}">{{icon "x"}}</button></form>{{end}} |
| {{if and .Receipt (eq .Kind "task")}}{{template "work-task-receipt" .}} |
| {{else if eq .Kind "advice"}}{{if ne .State "resolved"}}<p equipo-card-line data-advice-card>{{icon "lightbulb"}}<span>{{.Line}}</span></p>{{if .Open}}<form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-actions><input type="hidden" name="revision" value="{{.Revision}}">{{template "card-job" .}}<button rst-btn="primary" name="choice" value="act" type="submit" data-advice-choice="act">{{.ActLabel}}</button><button rst-btn name="choice" value="dismiss" type="submit" data-advice-choice="dismiss">{{.DismissLabel}}</button></form>{{else}}{{with .Note}}<p equipo-card-note>{{.}}</p>{{end}}{{end}}{{end}} |
| {{else if eq .Kind "housekeeping"}}<p equipo-card-line data-digest>{{icon "list-checks"}}<span>{{.Line}} <a href="/housekeeping" data-digest-link>{{copy "chat.housekeeping.link"}}</a></span></p> |
| @@ -17,7 +18,8 @@ |
| {{else if eq .Kind "merge"}}<p equipo-card-line>{{.Line}}</p>{{with .PreviewURL}}<p equipo-card-note><a href="{{.}}" rel="noopener" target="_blank" data-preview-link>{{copy "chat.card.preview_link"}}</a></p>{{end}}{{if .Open}}<form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-actions><input type="hidden" name="revision" value="{{.Revision}}">{{template "card-job" .}}{{range .Options}}<button rst-btn="{{if eq . "merge"}}primary{{end}}" name="choice" value="{{.}}" type="submit" data-merge-choice="{{.}}">{{copy (printf "chat.card.%s" .)}}</button>{{end}}</form>{{else}}{{with .Note}}<p equipo-card-note>{{.}}</p>{{end}}{{end}} |
| {{else if or (eq .Kind "merge_ships") (eq .Kind "merge_policy") (eq .Kind "merge_receipt")}}{{if eq .Kind "merge_receipt"}}<div equipo-card-line equipo-markdown data-merge-receipt>{{chatMarkdown .Line}}</div>{{else}}<p equipo-card-line>{{.Line}}</p>{{end}}{{if .Open}}<form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-actions><input type="hidden" name="revision" value="{{.Revision}}">{{template "card-job" .}}{{range .Options}}<button rst-btn="{{if or (eq . "save") (eq . "not_ships")}}primary{{end}}" name="choice" value="{{.}}" type="submit" data-merge-choice="{{.}}">{{copy (printf "chat.card.%s" .)}}</button>{{end}}</form>{{else}}{{with .Note}}<p equipo-card-note>{{.}}</p>{{end}}{{end}} |
| {{else if eq .Kind "access"}}<p equipo-card-line>{{.Line}}</p>{{if .Open}}<details equipo-grant><summary rst-btn>{{copy "chat.card.grant"}}</summary><p>{{.GrantHow}}</p><code>amadan agent grant {{.Agent}} {{.Namespace}}</code><form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form><input type="hidden" name="revision" value="{{.Revision}}">{{template "card-job" .}}<button rst-btn name="choice" value="check" type="submit" data-grant-check>{{copy "chat.card.grant_check"}}</button></form></details>{{end}} |
| -{{end}}</section></li>{{end}} |
| +{{end}}<p equipo-card-error role="alert" hidden></p></section>{{end}}</li>{{end}} |
| +{{define "roster-undo"}}<form method="post" action="/conversation/cards/{{.ID}}/visibility" data-card-form><input type="hidden" name="revision" value="{{.Revision}}"><input type="hidden" name="aside" value="false">{{template "card-job" .}}<button equipo-link type="submit" data-aside-undo data-busy-label="{{copy "roster.restoring"}}">{{copy "roster.undo"}}</button></form>{{end}} |
| {{define "roster-byline"}}<div equipo-roster-byline><span equipo-roster-avatar{{if eq .AuthorIcon "sparkles"}} equipo-coordinator-mark{{end}}>{{if eq .AuthorIcon "sparkles"}}{{template "roster-mark" .}}{{else}}{{icon .AuthorIcon}}{{end}}</span><b>{{.Author}}</b><span>{{.Verb}}</span><time datetime="{{.CreatedAt.Format "2006-01-02T15:04:05Z07:00"}}">{{.CreatedAt.Format "15:04"}}</time></div>{{end}} |
| {{define "roster-mark"}}<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3c1.1 5.8 3.2 7.9 9 9-5.8 1.1-7.9 3.2-9 9-1.1-5.8-3.2-7.9-9-9 5.8-1.1 7.9-3.2 9-9Z"/></svg>{{end}} |
| {{define "work-task-receipt"}}{{with .Task}}<div equipo-roster-report> |
| @@ -48,7 +50,7 @@ |
| </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{{if .Chat.Job}} data-job="{{.Chat.Job.ID}}"{{else}} data-chat-stream{{end}} 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"}}"> |
| +<div equipo-conversation{{if .Chat.Job}} data-job="{{.Chat.Job.ID}}"{{else}} data-chat-stream{{end}} data-card-failed="{{copy "roster.failed"}}" data-card-stale="{{copy "roster.stale"}}" data-card-busy="{{copy "roster.busy"}}" data-card-retry="{{copy "roster.retry"}}" data-aside-label="{{copy "roster.aside"}}" 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>{{with .Chat.Job}}<h1>{{.Label}}</h1><a href="/jobs" equipo-link data-jobs-all>{{copy "jobs.all"}}</a><a href="/conversation" equipo-link data-jobs-back>{{copy "jobs.back"}}</a>{{else}}<h1>{{copy "conversation.title"}}</h1>{{if .Chat.FromBase}}<a href="/jobs" equipo-header-button aria-label="{{copy "jobs.title"}}" title="{{copy "jobs.title"}}" data-jobs-link>{{icon "inbox"}}</a>{{end}}<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>{{end}}</header> |
| <p equipo-offline role="status"{{if not .Chat.Offline}} hidden{{end}}>{{copy "chat.offline"}}</p> |
| <div equipo-scroll tabindex="0" role="region" aria-label="{{copy "conversation.title"}}"> |
| @@ -72,6 +74,7 @@ |
| </ol> |
| </section> |
| </div> |
| +<div equipo-roster-toast role="status" hidden></div> |
| <div equipo-announcements role="status" aria-live="polite" aria-atomic="false"></div> |
| <div id="chat-composer"> |
| {{with .Chat.Job}}<form id="composer" equipo-form equipo-composer method="post" action="/jobs/{{.ID}}/messages" data-job-composer> |
diff --git a/internal/equipo/templates/work_needs.html b/internal/equipo/templates/work_needs.html| index 03a49b47..b115a6c2 100644 |
| --- a/internal/equipo/templates/work_needs.html |
| +++ b/internal/equipo/templates/work_needs.html |
| @@ -2,6 +2,7 @@ |
| {{define "content"}} |
| <section equipo-work equipo-inner data-work-live data-work-region id="work-needs"> |
| {{with .Thin}}<div equipo-page-head><h1>{{copy "nav.needs-you"}}</h1><p>{{if eq (len .Decisions) 0}}{{copy "work.needs_empty"}}{{else if eq (len .Decisions) 1}}{{copy "work.needs.one"}}{{else}}{{printf (copy "work.needs.many") (len .Decisions)}}{{end}}</p></div> |
| +{{range .Questions}}<article equipo-decision><h2>{{.Line}}</h2><a equipo-btn href="/conversation?card={{.ID}}#card-{{.ID}}">{{copy "conversation.title"}}</a></article>{{end}} |
| {{range .Decisions}}{{template "decision" (dict "Task" . "Head" true "From" "needs")}}{{end}} |
| {{with .Groups}}{{template "work-groups" (dict "Groups" . "From" "needs")}}{{end}}{{end}} |
| </section> |
diff --git a/internal/equipo/work_pages.go b/internal/equipo/work_pages.go| index f9f7c25b..0c3a4f12 100644 |
| --- a/internal/equipo/work_pages.go |
| +++ b/internal/equipo/work_pages.go |
| @@ -490,6 +490,7 @@ type workView struct { |
| // the team's tasks waiting on someone else. |
| Needs bool |
| Decisions []taskLine |
| + Questions []chatCard |
| Others []taskLine |
| // Groups are the Tasks page's (or a project's) tasks by what matters. |
| Groups []taskGroup |
| @@ -630,6 +631,14 @@ func (a *application) workTasks(w http.ResponseWriter, r *http.Request) { |
| if r.URL.Query().Get("needs") == "you" { |
| // Needs you: the person's own decisions, then what waits on others. |
| data.Key, data.Title, data.Thin.Needs = "needs-you", "nav.needs-you", true |
| + questions, err := a.store.Chat().OpenStandaloneCards(ctx, address) |
| + if err != nil { |
| + a.failure(w, r, chatError(err)) |
| + return |
| + } |
| + for _, c := range questions { |
| + data.Thin.Questions = append(data.Thin.Questions, cardView(c, nil, nil)) |
| + } |
| for _, t := range all { |
| switch { |
| case t.Group == "needs": |
diff --git a/internal/thintest/roster_browser_test.go b/internal/thintest/roster_browser_test.go| index 7feedc11..3ee33e09 100644 |
| --- a/internal/thintest/roster_browser_test.go |
| +++ b/internal/thintest/roster_browser_test.go |
| @@ -27,3 +27,32 @@ func TestBrowserRosterVisual(t *testing.T) { |
| } |
| } |
| } |
| + |
| +func TestBrowserRosterSetAside(t *testing.T) { |
| + r := newRollupRig(t) |
| + for _, width := range []int64{1280, 390} { |
| + for _, scheme := range []string{"light", "dark"} { |
| + t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) { |
| + p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce") |
| + defer p.stop() |
| + p.open("/conversation") |
| + card := `[data-card="` + r.askCard.ID + `"]` |
| + p.wait(`document.querySelector('`+card+` [data-set-aside]')`, "Set aside") |
| + p.click(card + ` [data-set-aside]`) |
| + p.wait(`document.querySelector('`+card+` [equipo-aside-stub]')`, "persisted stub") |
| + p.check(`!!document.querySelector('[equipo-roster-toast] [data-aside-undo]')`, "toast undo missing") |
| + p.shot(fmt.Sprintf("roster-aside-%d-%s", width, scheme)) |
| + p.open("/conversation") |
| + p.wait(`document.querySelector('`+card+` [equipo-aside-stub]')`, "stub after reload") |
| + p.open("/tasks?needs=you") |
| + p.check(`!!document.querySelector('a[href="/tasks/`+r.asked+`"]')`, "set-aside task left Needs you") |
| + p.open("/conversation") |
| + p.click(card + ` [data-aside-undo]`) |
| + p.wait(`document.querySelector('`+card+` [data-set-aside]')`, "restored card") |
| + p.open("/conversation") |
| + p.check(`!document.querySelector('`+card+` [equipo-aside-stub]')`, "undo did not persist") |
| + p.fits("set aside and undo") |
| + }) |
| + } |
| + } |
| +} |