oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import (
4 "bytes"
5 "context"
6 "net/http"
7
8 "amadan.net/oficina/equipo/internal/wire"
9)
10
11// The sidebar reads the thin core (person API v1 data) only, and
12// follows the event stream: Conversation, Tasks with the active count,
13// Projects, Needs you, then the specialists the thin core runs with
14// what they are doing, and People. Pages the thin core does not back
15// (journey, playbooks, templates, the old coordinator and connection
16// settings) are not in it; the slice 7 sweep deletes them.
17
18// railItems are the sidebar's pages, in order.
19var railItems = []NavItem{
20 {Key: "conversation", Href: "/conversation", CopyKey: "nav.conversation", Icon: "message-circle"},
21 {Key: "projects", Href: "/projects", CopyKey: "nav.projects", Icon: "folder"},
22 {Key: "tasks", Href: "/tasks", CopyKey: "nav.tasks", Icon: "check-circle"},
23 {Key: "needs-you", Href: "/tasks?needs=you", CopyKey: "nav.needs-you", Icon: "inbox"},
24 {Key: "usage", Href: "/usage", CopyKey: "nav.usage", Icon: "gauge"},
25 {Key: "people", Group: "team", Href: "/people", CopyKey: "nav.people", Icon: "users"},
26 {Key: "settings-hub", Group: "team", Href: "/conversation/settings", CopyKey: "nav.settings", Icon: "sliders"},
27}
28
29// railSpecialist is one specialist the thin core runs: idle, or working
30// on a task. The row is compact (the team panel, 2026-11-11): the
31// specialist, its living mark and clock, then the task's title and what
32// it is doing now in plain words. Its drawer (team_panel.go) has the rest.
33type railSpecialist struct {
34 Key, Icon, CopyKey string
35 // Task is the task its newest running step works on, Step that step.
36 Task *wire.Task
37 Step *wire.Step
38 // Now is the step's newest activity line in plain words.
39 Now string
40}
41
42// railCount is a quiet count: shown only above zero, "Unavailable" when
43// it could not be read.
44type railCount struct {
45 N int
46 Known bool
47}
48
49// railView is the sidebar's state.
50type railView struct {
51 Cursor int64
52 Tasks, Projects, Needs railCount
53 Specialists []railSpecialist
54 // Usage marks Usage with a dot: a connection limited or needing a
55 // sign-in, or a metered one paused (Connections rev 3 §6).
56 Usage bool
57}
58
59// specialistRail are the sidebar's specialist rows.
60var specialistRail = []struct{ specialist, icon, copyKey string }{
61 {wire.SpecialistEngineering, "code", "nav.engineering"},
62 {wire.SpecialistCopy, "type", "copy.title"},
63 {wire.SpecialistReview, "check-circle", "nav.review"},
64 {wire.SpecialistChecks, "shield", "nav.checks"},
65}
66
67func (a *application) rail(ctx context.Context, person string) railView {
68 c := a.store.Chat()
69 v := railView{}
70 if top, err := c.Cursor(ctx); err == nil {
71 v.Cursor = top
72 }
73 tasks, err := c.Tasks(ctx, person)
74 working := map[string][]wire.Task{}
75 if err == nil {
76 n := 0
77 for _, k := range tasks.Items {
78 if wire.FinalStage(k.Stage) {
79 continue
80 }
81 n++
82 // Every specialist running a step of it (Research can run
83 // while Engineering's step waits after it), once each.
84 seen := map[string]bool{}
85 for i := len(k.Steps) - 1; i >= 0; i-- {
86 if st := k.Steps[i]; st.State == wire.StepRunning && !seen[stepKey(st)] {
87 seen[stepKey(st)] = true
88 working[stepKey(st)] = append(working[stepKey(st)], k)
89 }
90 }
91 }
92 v.Tasks = railCount{n, true}
93 if cards, err := c.OpenMergeCards(ctx, person); err == nil {
94 needs := 0
95 for _, k := range tasks.Items {
96 card, open := cards[k.ID]
97 var cp *wire.Card
98 if open {
99 cp = &card
100 }
101 if needsViewer(k, person, cp) {
102 needs++
103 }
104 }
105 if questions, err := c.OpenStandaloneCards(ctx, person); err == nil {
106 v.Needs = railCount{needs + len(questions), true}
107 }
108 }
109 }
110 if conns, err := c.Connections(ctx, person); err == nil {
111 v.Usage = usageAttention(conns)
112 }
113 if p, err := c.Projects(ctx, person); err == nil {
114 v.Projects = railCount{len(p.Items), true}
115 }
116 rows := specialistRail
117 // Every specialist added to the team or to a project (data-defined,
118 // such as Design) has its own row after the built-in ones.
119 if added, err := c.Specialists(ctx, person); err == nil {
120 rows = append(rows[:len(rows):len(rows)], addedRows(added.Items)...)
121 }
122 for _, s := range rows {
123 line := railSpecialist{Key: s.specialist, Icon: s.icon, CopyKey: s.copyKey}
124 if ks := working[s.specialist]; len(ks) > 0 {
125 k := ks[0]
126 st := *keyStep(k, s.specialist, wire.StepRunning)
127 line.Task, line.Step = &k, &st
128 line.Now = copyText("work.activity.working")
129 if n := len(st.Activity); n > 0 {
130 line.Now = humaneActivity(st.Activity[n-1])
131 }
132 }
133 v.Specialists = append(v.Specialists, line)
134 }
135 return v
136}
137
138// railFragment is GET /nav/rail: the sidebar alone, for the stream
139// script to swap in when a task, step or project changes.
140func (a *application) railFragment(w http.ResponseWriter, r *http.Request) {
141 data, err := a.page(r, r.URL.Query().Get("key"))
142 if err != nil {
143 a.failure(w, r, err)
144 return
145 }
146 w.Header().Set("Cache-Control", "no-store")
147 var buf bytes.Buffer
148 if err := pages["work_tasks"].ExecuteTemplate(&buf, "region:rail", data); err != nil {
149 http.Error(w, copyRenderFailure, http.StatusInternalServerError)
150 return
151 }
152 w.Header().Set("Content-Type", "text/html; charset=utf-8")
153 buf.WriteTo(w)
154}
155
156// addedRows are the sidebar rows of the active data-defined specialists,
157// oldest first: keyed by id, with their profile's name and icon.
158func addedRows(items []wire.Specialist) []struct{ specialist, icon, copyKey string } {
159 var out []struct{ specialist, icon, copyKey string }
160 for i := len(items) - 1; i >= 0; i-- {
161 sp := items[i]
162 if sp.State != wire.SpecialistActive || makerName(sp.Profile) == "" {
163 continue
164 }
165 out = append(out, struct{ specialist, icon, copyKey string }{sp.ID, makerIcon(sp.Profile), makerCopyKey(sp.Profile)})
166 }
167 return out
168}
169