@nanocollective/roster 0.1.0-alpha.9 → 0.1.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/README.md +6 -0
  2. package/dist/cli.js +4189 -1971
  3. package/dist/worker/assets/assets/css/base.css +327 -0
  4. package/dist/worker/assets/assets/css/brain.css +116 -0
  5. package/dist/worker/assets/assets/css/diff.css +33 -0
  6. package/dist/worker/assets/assets/css/graph.css +39 -0
  7. package/dist/worker/assets/assets/css/health.css +75 -0
  8. package/dist/worker/assets/assets/css/home.css +114 -0
  9. package/dist/worker/assets/assets/css/inbox.css +199 -0
  10. package/dist/worker/assets/assets/css/layout.css +181 -0
  11. package/dist/worker/assets/assets/css/markdown.css +96 -0
  12. package/dist/worker/assets/assets/css/runs.css +13 -0
  13. package/dist/worker/assets/assets/css/search.css +48 -0
  14. package/dist/worker/assets/assets/css/setup.css +194 -0
  15. package/dist/worker/assets/assets/js/api.js +191 -0
  16. package/dist/worker/assets/assets/js/app.js +500 -0
  17. package/dist/worker/assets/assets/js/dialog.js +196 -0
  18. package/dist/worker/assets/assets/js/dom.js +131 -0
  19. package/dist/worker/assets/assets/js/homesort.js +174 -0
  20. package/dist/worker/assets/assets/js/icons.js +142 -0
  21. package/dist/worker/assets/assets/js/inflight.js +18 -0
  22. package/dist/worker/assets/assets/js/lightbox.js +273 -0
  23. package/dist/worker/assets/assets/js/md.js +406 -0
  24. package/dist/worker/assets/assets/js/mdedit.js +84 -0
  25. package/dist/worker/assets/assets/js/mention.js +264 -0
  26. package/dist/worker/assets/assets/js/readiness.js +70 -0
  27. package/dist/worker/assets/assets/js/refresh.js +197 -0
  28. package/dist/worker/assets/assets/js/router.js +20 -0
  29. package/dist/worker/assets/assets/js/search.js +366 -0
  30. package/dist/worker/assets/assets/js/state.js +213 -0
  31. package/dist/worker/assets/assets/js/textdiff.js +96 -0
  32. package/dist/worker/assets/assets/js/views/app.js +145 -0
  33. package/dist/worker/assets/assets/js/views/brain.js +260 -0
  34. package/dist/worker/assets/assets/js/views/changed.js +157 -0
  35. package/dist/worker/assets/assets/js/views/checklist.js +115 -0
  36. package/dist/worker/assets/assets/js/views/credential.js +84 -0
  37. package/dist/worker/assets/assets/js/views/docs.js +174 -0
  38. package/dist/worker/assets/assets/js/views/files.js +139 -0
  39. package/dist/worker/assets/assets/js/views/graph.js +436 -0
  40. package/dist/worker/assets/assets/js/views/health.js +304 -0
  41. package/dist/worker/assets/assets/js/views/hire.js +593 -0
  42. package/dist/worker/assets/assets/js/views/home.js +621 -0
  43. package/dist/worker/assets/assets/js/views/inbox.js +1558 -0
  44. package/dist/worker/assets/assets/js/views/memory.js +150 -0
  45. package/dist/worker/assets/assets/js/views/org.js +195 -0
  46. package/dist/worker/assets/assets/js/views/orgedit.js +240 -0
  47. package/dist/worker/assets/assets/js/views/paste.js +216 -0
  48. package/dist/worker/assets/assets/js/views/prompt.js +457 -0
  49. package/dist/worker/assets/assets/js/views/repos.js +97 -0
  50. package/dist/worker/assets/assets/js/views/runonce.js +94 -0
  51. package/dist/worker/assets/assets/js/views/runs.js +182 -0
  52. package/dist/worker/assets/assets/js/views/setup.js +557 -0
  53. package/dist/worker/assets/assets/js/views/staff.js +291 -0
  54. package/dist/worker/assets/assets/js/views/todo.js +62 -0
  55. package/dist/worker/assets/assets/js/yaml.js +134 -0
  56. package/dist/worker/assets/docs-images/brain.jpg +0 -0
  57. package/dist/worker/assets/docs-images/home.jpg +0 -0
  58. package/dist/worker/assets/docs-images/org.jpg +0 -0
  59. package/dist/worker/assets/docs-images/prompt.jpg +0 -0
  60. package/dist/worker/assets/docs-images/setup-org.jpg +0 -0
  61. package/dist/worker/assets/docs-images/setup-plan.jpg +0 -0
  62. package/dist/worker/assets/docs-images/staff.jpg +0 -0
  63. package/dist/worker/assets/index.html +82 -0
  64. package/dist/worker/index.js +5143 -0
  65. package/docs/README.md +2 -2
  66. package/docs/architecture.md +23 -4
  67. package/docs/charters/analyst.md +65 -0
  68. package/docs/charters/community.md +63 -0
  69. package/docs/charters/designer.md +65 -0
  70. package/docs/charters/devops.md +65 -0
  71. package/docs/charters/pm.md +70 -0
  72. package/docs/charters/qa.md +65 -0
  73. package/docs/charters/writer.md +63 -0
  74. package/docs/commands.md +36 -9
  75. package/docs/concepts.md +34 -21
  76. package/docs/cost.md +3 -3
  77. package/docs/developing.md +28 -10
  78. package/docs/doctor-codes.md +3 -1
  79. package/docs/export.md +2 -0
  80. package/docs/getting-started.md +49 -29
  81. package/docs/hosting.md +114 -43
  82. package/docs/images/brain.jpg +0 -0
  83. package/docs/images/home.jpg +0 -0
  84. package/docs/images/org.jpg +0 -0
  85. package/docs/images/prompt.jpg +0 -0
  86. package/docs/images/staff.jpg +0 -0
  87. package/docs/manual-steps.md +3 -2
  88. package/docs/memory.md +2 -1
  89. package/docs/org-yaml.md +3 -0
  90. package/docs/portal.md +144 -45
  91. package/docs/prompts.md +6 -0
  92. package/docs/security.md +70 -11
  93. package/docs/session-workflow.md +24 -6
  94. package/docs/staff-yaml.md +21 -2
  95. package/docs/upgrading.md +3 -3
  96. package/docs/writing-a-charter.md +19 -6
  97. package/package.json +4 -3
  98. package/templates/brain/.github/workflows/%%STAFF%%-daily.yaml +20 -1
  99. package/templates/brain/.github/workflows/%%STAFF%%-mention.yaml +53 -13
  100. package/templates/brain/CHARTER.md +2 -2
  101. package/templates/brain/STATE.md +16 -0
  102. package/templates/brain/memory/INDEX.md +1 -1
  103. package/templates/brain/staff.yaml +4 -1
  104. package/templates/briefs/amend.md +4 -3
  105. package/templates/briefs/priorities.md +46 -0
  106. package/templates/ops/.github/workflows/session.yaml +150 -3
  107. package/templates/ops/compose.mjs +35 -8
  108. package/templates/ops/org/operating.md +29 -10
  109. package/templates/ops/org/voice.md +2 -1
  110. package/templates/ops/prompts/daily.md +51 -14
  111. package/templates/ops/prompts/mention.md +24 -2
  112. package/templates/ops/run-record.mjs +5 -3
  113. package/templates/ops/status-week.mjs +169 -0
  114. package/templates/portal/css/base.css +49 -0
  115. package/templates/portal/css/health.css +14 -1
  116. package/templates/portal/css/home.css +114 -0
  117. package/templates/portal/css/inbox.css +21 -4
  118. package/templates/portal/css/layout.css +35 -3
  119. package/templates/portal/css/markdown.css +19 -0
  120. package/templates/portal/css/search.css +48 -0
  121. package/templates/portal/css/setup.css +79 -4
  122. package/templates/portal/index.html +15 -9
  123. package/templates/portal/js/api.js +60 -4
  124. package/templates/portal/js/app.js +125 -7
  125. package/templates/portal/js/dialog.js +36 -0
  126. package/templates/portal/js/homesort.js +174 -0
  127. package/templates/portal/js/icons.js +41 -0
  128. package/templates/portal/js/inflight.js +18 -0
  129. package/templates/portal/js/md.js +5 -2
  130. package/templates/portal/js/mdedit.js +84 -0
  131. package/templates/portal/js/readiness.js +70 -0
  132. package/templates/portal/js/refresh.js +10 -2
  133. package/templates/portal/js/search.js +366 -0
  134. package/templates/portal/js/state.js +11 -5
  135. package/templates/portal/js/views/app.js +1 -2
  136. package/templates/portal/js/views/brain.js +1 -1
  137. package/templates/portal/js/views/checklist.js +19 -4
  138. package/templates/portal/js/views/credential.js +42 -51
  139. package/templates/portal/js/views/health.js +11 -6
  140. package/templates/portal/js/views/hire.js +593 -0
  141. package/templates/portal/js/views/home.js +621 -0
  142. package/templates/portal/js/views/inbox.js +237 -68
  143. package/templates/portal/js/views/org.js +31 -111
  144. package/templates/portal/js/views/orgedit.js +240 -0
  145. package/templates/portal/js/views/paste.js +111 -66
  146. package/templates/portal/js/views/prompt.js +94 -40
  147. package/templates/portal/js/views/repos.js +10 -10
  148. package/templates/portal/js/views/runs.js +21 -4
  149. package/templates/portal/js/views/setup.js +130 -163
  150. package/templates/portal/js/views/staff.js +181 -301
  151. package/templates/portal/js/views/todo.js +62 -0
@@ -0,0 +1,500 @@
1
+ /* The shell: boot, the sidebar, and dispatching a view into <main>. */
2
+
3
+ import { getOrgWithProgress, getSession } from "./api.js";
4
+ import { $, el, store } from "./dom.js";
5
+ import { icon, iconHTML, staffIcon } from "./icons.js";
6
+ import { installLightbox } from "./lightbox.js";
7
+ import { setPeople } from "./md.js";
8
+ import {
9
+ countInBackground,
10
+ refreshAll,
11
+ refreshQuietly,
12
+ stampCounts,
13
+ stampLoaded,
14
+ syncNotice,
15
+ } from "./refresh.js";
16
+ import { onRender } from "./router.js";
17
+ import { ORG_WIDE, S, VIEWS, applyHash, humanLabel, readHash, writeHash } from "./state.js";
18
+ import { viewBrain } from "./views/brain.js";
19
+ import { viewChanged } from "./views/changed.js";
20
+ import { viewDocs } from "./views/docs.js";
21
+ import { viewGraph } from "./views/graph.js";
22
+ import { viewHealth } from "./views/health.js";
23
+ import { openSearch } from "./search.js";
24
+ import { viewHome } from "./views/home.js";
25
+ import { viewInbox, viewPrs } from "./views/inbox.js";
26
+ import { viewOrg } from "./views/org.js";
27
+ import { viewPrompt } from "./views/prompt.js";
28
+ import { viewRuns } from "./views/runs.js";
29
+ import { sentence, whatsLeft } from "./readiness.js";
30
+ import { paintSetupNav, viewGettingStarted, viewSetup } from "./views/setup.js";
31
+ import { viewStaff } from "./views/staff.js";
32
+
33
+ const SCREEN = {
34
+ setup: viewGettingStarted,
35
+ home: viewHome,
36
+ inbox: viewInbox,
37
+ prs: viewPrs,
38
+ runs: viewRuns,
39
+ org: viewOrg,
40
+ staff: viewStaff,
41
+ docs: viewDocs,
42
+ brain: viewBrain,
43
+ memory: viewBrain,
44
+ prompt: viewPrompt,
45
+ graph: viewGraph,
46
+ changed: viewChanged,
47
+ health: viewHealth,
48
+ };
49
+
50
+ /**
51
+ * Fields of the org export this page cannot render without.
52
+ *
53
+ * The portal reads its stylesheets and modules per request, so editing one and reloading
54
+ * works. Its *server* is loaded once, at start. A portal left running across an upgrade
55
+ * therefore serves new assets against an old API, and the first sign of it was an Org screen
56
+ * asking for `undefined/org.yaml`. A missing field is version skew, and skew should say so.
57
+ */
58
+ const NEEDS = ["org", "name", "opsName", "staff"];
59
+
60
+ /** The org-wide screens in the sidebar, by button. */
61
+ const NAV = [
62
+ ["#setupnav", "setup"],
63
+ ["#homenav", "home"],
64
+ ["#inboxnav", "inbox"],
65
+ ["#runsnav", "runs"],
66
+ ["#staffnav", "staff"],
67
+ ["#orgnav", "org"],
68
+ ["#docsnav", "docs"],
69
+ ];
70
+
71
+ export async function boot() {
72
+ initTheme();
73
+
74
+ /* Bound before the first request rather than after it. The sidebar is markup, so it is on
75
+ screen and clickable while /api/org is still building the export, and a click in that
76
+ window used to do nothing at all: the first click on Staff after a load was simply lost.
77
+ Now it is remembered and honoured once there is something to render. */
78
+ let early = null;
79
+ for (const [id, view] of NAV) {
80
+ const b = $(id);
81
+ if (!b) continue;
82
+ b.onclick = () => {
83
+ if (!S.data) {
84
+ early = view;
85
+ return;
86
+ }
87
+ S.view = view;
88
+ render();
89
+ };
90
+ }
91
+
92
+ /* Before the first render, and once: it is delegated, so it covers every image any screen
93
+ draws from here on, including the setup screen. */
94
+ installLightbox();
95
+
96
+ /* Before there is a tenant the server answers every data route with `mode: setup`. That is
97
+ not an error state: it is the first thing a new user ever sees, and the whole page becomes
98
+ the thing that fixes it. */
99
+ const [first, session] = await Promise.all([loadWithProgress(), getSession()]);
100
+ S.hosted = session?.hosted ? session : null;
101
+ if (S.hosted) showSignedIn(S.hosted.login);
102
+ if (first && first.mode === "setup") {
103
+ document.body.dataset.setup = "1";
104
+ $("#orgname").textContent = "no org yet";
105
+ /* Every one of these reads a tenant, so during setup they answer 409 and the sidebar is a
106
+ row of four dead ends beside an empty Staff heading. There is one thing to do on this
107
+ screen; the navigation comes back with the org. */
108
+ for (const el of document.querySelectorAll("#sidesearch, #homenav, #inboxnav, #runsnav, #orgnav, #staffnav, #docsnav, #refreshall, .sect, #stafflist")) {
109
+ el.hidden = true;
110
+ }
111
+ for (const slot of document.querySelectorAll("[data-icon]")) {
112
+ slot.innerHTML = iconHTML(slot.dataset.icon);
113
+ }
114
+ await viewSetup($("#main"));
115
+ return;
116
+ }
117
+
118
+ S.data = first;
119
+ S.loadedAt = new Date();
120
+ S.staffOpen = null; // an open hire list survives a refresh, not a page load
121
+ S.readiness = null;
122
+ S.staffHandle = S.data.staff[0]?.handle ?? null;
123
+ $("#orgname").textContent = S.data.name + " · " + S.data.staff.length + " staff";
124
+
125
+ learnPeople();
126
+ // The shell's own icons are markup, so they are filled in once the module is running
127
+ // rather than pasted into index.html as inline SVG nobody would ever read.
128
+ for (const slot of document.querySelectorAll("[data-icon]")) {
129
+ slot.innerHTML = iconHTML(slot.dataset.icon);
130
+ }
131
+ onRender(render);
132
+ const linked = readHash() !== null;
133
+ applyHash();
134
+ /* An org nobody has been hired into has an empty Inbox, which says nothing about what to do
135
+ next. It opens on what is left instead, unless a link or a click asked for somewhere else. */
136
+ if (early) S.view = early;
137
+ else if (!linked && !S.hosted && (S.data.unfinished ?? []).includes("hire")) S.view = "setup";
138
+ initStaffFold();
139
+ paintSidebar();
140
+
141
+ $("#refreshall").onclick = () => refreshAll(false);
142
+
143
+ /* Coming back to the tab after a run should show the run — and coming back to it thirty
144
+ seconds after leaving it should show nothing at all. Clicking into the window used to
145
+ re-read every repo on GitHub and repaint the screen under you; now it looks first and
146
+ only repaints when something actually moved. */
147
+ addEventListener("focus", () => {
148
+ if (S.loadedAt && Date.now() - S.loadedAt > 60000) refreshQuietly();
149
+ });
150
+ /* ⌘K (Ctrl+K off a Mac) opens search from anywhere, even from inside a text box: it is the
151
+ one shortcut that should never be swallowed by whatever has focus. The sidebar's field
152
+ opens the same dialog. */
153
+ addEventListener("keydown", (e) => {
154
+ if ((e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey && e.key.toLowerCase() === "k") {
155
+ e.preventDefault();
156
+ openSearch();
157
+ }
158
+ });
159
+ const side = $("#sidesearch");
160
+ if (side) side.onclick = () => openSearch();
161
+ const key = $("#searchkey");
162
+ if (key && !/Mac|iPhone|iPad/.test(navigator.platform ?? "")) key.textContent = "Ctrl K";
163
+ addEventListener("keydown", (e) => {
164
+ if (e.key === "r" && !e.metaKey && !e.ctrlKey &&
165
+ !/^(INPUT|TEXTAREA|SELECT)$/.test(e.target?.tagName ?? "")) {
166
+ e.preventDefault();
167
+ refreshAll(false);
168
+ }
169
+ });
170
+ setInterval(stampLoaded, 30000);
171
+
172
+ /* What is waiting on you is the first thing this page should be able to tell you, and it used
173
+ to be the one thing it would not say until you clicked Inbox. One request, shared with
174
+ whichever screen renders next. */
175
+ countInBackground();
176
+
177
+ // Only the state changes here. This used to re-run half of boot on every navigation,
178
+ // which stacked up a focus listener, a keydown listener and an interval each time.
179
+ addEventListener("hashchange", () => {
180
+ S.applyingHash = true;
181
+ applyHash();
182
+ S.applyingHash = false;
183
+ render();
184
+ });
185
+
186
+ render();
187
+ }
188
+
189
+ /** Say it plainly, rather than rendering half a page built on values that are not there. */
190
+ function stale(missing) {
191
+ const m = $("#main");
192
+ m.replaceChildren();
193
+ const box = el("div", { className: "notice" });
194
+ box.innerHTML =
195
+ "<b>This page is newer than the portal serving it.</b><br>" +
196
+ "The stylesheets and modules are read per request, but the server is not: it was loaded " +
197
+ "when <code>roster portal</code> started. Stop it and start it again.<br><br>" +
198
+ "<span class=\"meta\">/api/org is not sending: " + missing.join(", ") + "</span>";
199
+ m.append(box);
200
+ $("#orgname").textContent = "restart needed";
201
+ }
202
+
203
+ /* Who `@cto` and `@you` are, so a mention in a thread can point somewhere useful
204
+ instead of at github.com/cto, which is nobody.
205
+ A staff mention goes to their repo on GitHub. It used to open their Brain screen here, which
206
+ read as the page hijacking a click: you are in the middle of a thread, and a mention is
207
+ about the work, not about their memory. */
208
+ function learnPeople() {
209
+ const people = new Map();
210
+ for (const s of S.data.staff) {
211
+ if (!s.brain) continue;
212
+ const to = { href: "https://github.com/" + s.brain, title: s.name + " · " + s.brain };
213
+ people.set(String(s.handle).toLowerCase(), to);
214
+ if (s.mention) people.set(String(s.mention).replace(/^@/, "").toLowerCase(), to);
215
+ for (const b of s.bots ?? []) people.set(String(b).toLowerCase(), to);
216
+ }
217
+ const human = S.data.human ?? {};
218
+ if (human.github) {
219
+ people.set(String(human.github).toLowerCase(), {
220
+ href: "https://github.com/" + human.github,
221
+ title: human.name ?? human.github,
222
+ });
223
+ }
224
+ setPeople(people);
225
+ }
226
+
227
+ /* ------------------------------- the sidebar ------------------------------ */
228
+
229
+ /**
230
+ * Staff are rows that unfold into their own views.
231
+ *
232
+ * This used to be a dropdown, then the chosen name repeated underneath it, then four
233
+ * unlabelled views — three pieces you had to assemble into "these belong to that person".
234
+ * Nesting says it instead.
235
+ */
236
+ let paintedRoster = null;
237
+
238
+ /**
239
+ * The Staff heading is a fold, and folded it carries the count.
240
+ *
241
+ * It starts folded, so the count is not decoration: a bare "STAFF" heading over nothing is how
242
+ * a loaded org would look if the export came back empty, and those two states have to be
243
+ * tellable apart at a glance. The count sits on the heading rather than beside it so there is
244
+ * one thing to click.
245
+ */
246
+ let staffOpen = true;
247
+
248
+ function paintStaffFold() {
249
+ const b = $("#stafffold");
250
+ if (b) b.setAttribute("aria-expanded", String(staffOpen));
251
+ const list = $("#stafflist");
252
+ if (list) list.hidden = !staffOpen;
253
+ const n = $("#staffcount");
254
+ if (n) {
255
+ n.textContent = "(" + (S.data?.staff?.length ?? 0) + ")";
256
+ n.hidden = staffOpen;
257
+ }
258
+ }
259
+
260
+ function initStaffFold() {
261
+ // Folded until you say otherwise: the count on the heading is enough to know the roster is
262
+ // there, and the four org-wide screens above it are where a session starts.
263
+ staffOpen = store("roster.staffopen") === "1";
264
+ paintStaffFold();
265
+ const b = $("#stafffold");
266
+ if (!b) return;
267
+ b.onclick = () => {
268
+ staffOpen = !staffOpen;
269
+ store("roster.staffopen", staffOpen ? "1" : "0");
270
+ paintStaffFold();
271
+ };
272
+ }
273
+
274
+ function paintSidebar() {
275
+ paintInboxLinks();
276
+ const host = $("#stafflist");
277
+ host.replaceChildren();
278
+ paintedRoster = S.data.staff.map((s) => s.handle).join(" ");
279
+
280
+ for (const s of S.data.staff) {
281
+ const open = s.handle === S.staffHandle;
282
+
283
+ const head = el("button", { className: "nav staffrow" });
284
+ head.dataset.staff = s.handle;
285
+ head.setAttribute("aria-expanded", String(open));
286
+ const dot = el("span", { className: "readydot", hidden: true });
287
+ head.append(
288
+ icon("chevron", "caret"),
289
+ icon(staffIcon(s), "ic"),
290
+ el("span", { className: "t", textContent: s.name }),
291
+ dot,
292
+ el("span", { className: "hh", textContent: s.handle }),
293
+ );
294
+ whatsLeft(s).then((left) => {
295
+ paintSetupNav();
296
+ if (!left.length) return;
297
+ dot.hidden = false;
298
+ head.title = "Not ready to run: " + sentence(left);
299
+ });
300
+
301
+ const views = el("div", { className: "staffviews" });
302
+ views.hidden = !open;
303
+ for (const [id, label] of VIEWS) {
304
+ const b = el("button", { className: "nav subnav", textContent: label });
305
+ b.dataset.view = id;
306
+ b.dataset.staff = s.handle;
307
+ b.onclick = () => {
308
+ if (S.staffHandle !== s.handle) S.openFile = null;
309
+ S.staffHandle = s.handle;
310
+ S.view = id;
311
+ render();
312
+ };
313
+ views.append(b);
314
+ }
315
+
316
+ head.onclick = () => {
317
+ // Clicking the staff member you are already on folds them away; clicking another
318
+ // switches to them and keeps whichever view you were reading.
319
+ if (S.staffHandle === s.handle && !views.hidden) {
320
+ views.hidden = true;
321
+ head.setAttribute("aria-expanded", "false");
322
+ return;
323
+ }
324
+ S.staffHandle = s.handle;
325
+ S.openFile = null;
326
+ if (ORG_WIDE.has(S.view)) S.view = "brain";
327
+ render();
328
+ };
329
+
330
+ host.append(head, views);
331
+ }
332
+
333
+ // A refresh can hire or retire someone, and the folded heading is where that number shows.
334
+ paintStaffFold();
335
+ }
336
+
337
+ /** Which rows are lit, and which staff member is unfolded. */
338
+ /* The inbox's filters, as links under Inbox: everything, what is on you, decisions, then one
339
+ per staff member. They replaced two dropdowns on the Inbox screen itself. */
340
+ function paintInboxLinks() {
341
+ const sub = $("#inboxsub");
342
+ if (!sub) return;
343
+ sub.replaceChildren();
344
+ // Inbox itself is everything. Under it: each staff member, then the product repos' issues.
345
+ const links = [
346
+ ["", "All", "inbox"],
347
+ ...S.data.staff.map((s) => [s.handle, s.name, staffIcon(s)]),
348
+ ["@issues", "Issues", "issue-open"],
349
+ ];
350
+ for (const [who, label, glyph] of links) {
351
+ const b = el("button", { className: "nav subnav inboxlink" }, [
352
+ icon(glyph, "ic"),
353
+ el("span", { className: "t", textContent: label }),
354
+ ...(who === "@unread" ? [el("span", { className: "n", id: "unreadcount" })] : []),
355
+ ]);
356
+ b.dataset.who = who;
357
+ b.onclick = () => {
358
+ S.view = "inbox";
359
+ S.inboxStaff = who;
360
+ S.inboxFilter = "";
361
+ S.inboxOpen = null;
362
+ render();
363
+ };
364
+ sub.append(b);
365
+ }
366
+ }
367
+
368
+ function markSidebar() {
369
+ const sub = $("#inboxsub");
370
+ if (sub) sub.hidden = S.view !== "inbox";
371
+ for (const b of document.querySelectorAll(".inboxlink")) {
372
+ const on = S.view === "inbox" && b.dataset.who === (S.inboxStaff || "");
373
+ b.setAttribute("aria-current", String(on));
374
+ }
375
+ for (const b of document.querySelectorAll(".nav")) {
376
+ if (!b.dataset.view) continue;
377
+ const mine = !b.dataset.staff || b.dataset.staff === S.staffHandle;
378
+ b.setAttribute("aria-current", String(mine && b.dataset.view === S.view));
379
+ }
380
+ for (const head of document.querySelectorAll(".staffrow")) {
381
+ const open = head.dataset.staff === S.staffHandle && !ORG_WIDE.has(S.view);
382
+ head.setAttribute("aria-expanded", String(open));
383
+ head.setAttribute("aria-selected", String(head.dataset.staff === S.staffHandle));
384
+ if (head.nextElementSibling) head.nextElementSibling.hidden = !open;
385
+ }
386
+ }
387
+
388
+ /* --------------------------------- render --------------------------------- */
389
+
390
+ function render() {
391
+ /* Checked on every paint rather than once at boot, because `refreshAll` re-fetches the
392
+ export and a portal can go stale under a page that is already open. */
393
+ const missing = NEEDS.filter((k) => S.data?.[k] === undefined);
394
+ if (missing.length) return stale(missing);
395
+
396
+ // A refresh can add or remove a staff member, and the sidebar is built once.
397
+ const roster = S.data.staff.map((s) => s.handle).join(" ");
398
+ if (roster !== paintedRoster) paintSidebar();
399
+ paintSetupNav();
400
+ markSidebar();
401
+ stampCounts();
402
+ writeHash(true);
403
+ stampLoaded();
404
+
405
+ const m = $("#main");
406
+ m.replaceChildren();
407
+ const notice = syncNotice();
408
+ if (notice) m.append(notice);
409
+ (SCREEN[S.view] ?? viewBrain)(m);
410
+ }
411
+
412
+ /* ------------------------------- first load -------------------------------- */
413
+
414
+ /**
415
+ * The first read of the org, with what it is doing on screen. A cold start reads every
416
+ * repository from GitHub, which can take a while, and "Loading…" for fifteen seconds reads as
417
+ * broken. One row per repository, saying which step it is on, and a tick when it is ready.
418
+ */
419
+ async function loadWithProgress() {
420
+ const main = $("#main");
421
+ const rows = new Map();
422
+ const list = el("div", { className: "loadlist" });
423
+ const head = el("p", { className: "sub", textContent: "Reading the org from GitHub…" });
424
+ // Only once something is actually slow: a warm load is over before this would be read.
425
+ const show = setTimeout(() => main.replaceChildren(head, list), 400);
426
+ try {
427
+ return await getOrgWithProgress((repo, step) => {
428
+ let row = rows.get(repo);
429
+ if (!row) {
430
+ row = el("div", { className: "loadrow" }, [
431
+ el("span", { className: "loadmark" }),
432
+ el("b", { textContent: repo }),
433
+ el("span", { className: "meta" }),
434
+ ]);
435
+ rows.set(repo, row);
436
+ list.append(row);
437
+ }
438
+ const ready = step === "ready" || step === "up to date";
439
+ row.classList.toggle("done", ready);
440
+ row.lastChild.textContent = ready ? "ready" : step;
441
+ });
442
+ } finally {
443
+ clearTimeout(show);
444
+ }
445
+ }
446
+
447
+ /* -------------------------------- signed in -------------------------------- */
448
+
449
+ /**
450
+ * On a hosted portal: who you are, and the way out. Setting the org up is not done from here,
451
+ * so its entry goes too.
452
+ */
453
+ function showSignedIn(login) {
454
+ $("#setupnav")?.setAttribute("hidden", "");
455
+ const out = el("button", { className: "nav", textContent: "Sign out " + login });
456
+ out.onclick = async () => {
457
+ await fetch("/auth/logout", { method: "POST" }).catch(() => {});
458
+ location.href = "/";
459
+ };
460
+ $(".sidefoot")?.prepend(out);
461
+ }
462
+
463
+ /* --------------------------------- theme ---------------------------------- */
464
+
465
+ /* Three states on purpose: "system" is the default and has to be reachable again after
466
+ someone has tried both others. */
467
+ const THEMES = ["system", "light", "dark"];
468
+
469
+ function applyTheme(name) {
470
+ if (name === "system") document.documentElement.removeAttribute("data-theme");
471
+ else document.documentElement.setAttribute("data-theme", name);
472
+ const b = $("#theme");
473
+ if (b) {
474
+ b.replaceChildren(
475
+ icon(name === "light" ? "sun" : name === "dark" ? "moon" : "monitor", "ic"),
476
+ "Theme",
477
+ el("span", { className: "n", textContent: name }),
478
+ );
479
+ }
480
+ }
481
+
482
+ function initTheme() {
483
+ let theme = store("roster.theme") ?? "system";
484
+ if (!THEMES.includes(theme)) theme = "system";
485
+ applyTheme(theme);
486
+ const b = $("#theme");
487
+ if (b) {
488
+ b.onclick = () => {
489
+ theme = THEMES[(THEMES.indexOf(theme) + 1) % THEMES.length];
490
+ store("roster.theme", theme);
491
+ applyTheme(theme);
492
+ };
493
+ }
494
+ }
495
+
496
+ export { render };
497
+
498
+ boot().catch((e) => {
499
+ $("#main").innerHTML = '<p class="empty err">' + String(e?.message ?? e) + "</p>";
500
+ });
@@ -0,0 +1,196 @@
1
+ /* Asking for more than a sentence.
2
+ *
3
+ * `prompt()` is one line with no wrapping, which is the wrong shape for describing a change to
4
+ * a prompt: the useful answers are two or three sentences and often a bullet list. Native
5
+ * `<dialog>` gives the backdrop, the focus trap and Escape without any of it being written
6
+ * here, which is the whole reason to use it rather than a div.
7
+ */
8
+
9
+ import { el, grow } from "./dom.js";
10
+ import { attachMentions } from "./mention.js";
11
+
12
+ /**
13
+ * Whether a click was on the backdrop, which is not the same question as "is the target the
14
+ * dialog".
15
+ *
16
+ * Picking a name from the `@` list used to close the whole dialog and throw away what you had
17
+ * typed. The list hides itself on mousedown so the caret survives the pick, so by the time the
18
+ * `click` lands the row is gone and the event retargets to the nearest thing still under the
19
+ * pointer, which is the dialog. A target test alone reads that as a backdrop click.
20
+ *
21
+ * So the pointer has to actually be outside the dialog's own box. `detail` of 0 is a click
22
+ * synthesised by the keyboard, which reports 0,0 and would otherwise look like the top corner
23
+ * of the page.
24
+ */
25
+ export function onBackdrop(e, rect) {
26
+ if (!rect || e.currentTarget !== e.target || !e.detail) return false;
27
+ return (
28
+ e.clientX < rect.left ||
29
+ e.clientX > rect.right ||
30
+ e.clientY < rect.top ||
31
+ e.clientY > rect.bottom
32
+ );
33
+ }
34
+
35
+ /**
36
+ * @param decorate given the textarea, returns a node to sit under it. This is how the reply
37
+ * box carries its attachments: the control has to write into the box it is beside.
38
+ * @param allowEmpty saying nothing is an answer for some of these. Closing an issue without
39
+ * a parting comment is the normal case, not a cancelled dialog.
40
+ * @returns the text, or null if they cancelled.
41
+ */
42
+ export function askText({
43
+ title,
44
+ hint,
45
+ value = "",
46
+ placeholder = "",
47
+ confirm = "Continue",
48
+ decorate,
49
+ allowEmpty = false,
50
+ }) {
51
+ const box = document.createElement("dialog");
52
+ // The shim in the tests has no dialog element. Falling back keeps a view renderable there
53
+ // rather than throwing halfway through a paint.
54
+ if (typeof box.showModal !== "function") {
55
+ return Promise.resolve(globalThis.prompt?.(title, value) ?? null);
56
+ }
57
+
58
+ box.className = "ask";
59
+ box.append(el("h3", { textContent: title }));
60
+ if (hint) box.append(el("p", { className: "askhint", textContent: hint }));
61
+
62
+ const ta = el("textarea", { value, placeholder, rows: 5 });
63
+ box.append(ta);
64
+ /* Before the ⌘⏎ handler below, so that when the `@` list is open its own Enter wins. Every
65
+ dialog this function opens is prose that may need to reach somebody, and a mention is how
66
+ it reaches them. */
67
+ attachMentions(ta);
68
+ const under = decorate?.(ta);
69
+ if (under) box.append(under);
70
+
71
+ const cancel = el("button", { className: "ghbtn", textContent: "Cancel" });
72
+ const go = el("button", { className: "ghbtn primary", textContent: confirm });
73
+ box.append(
74
+ el("div", { className: "row askrow" }, [
75
+ el("span", { className: "meta", textContent: "⌘⏎ to " + confirm.toLowerCase() }),
76
+ cancel,
77
+ go,
78
+ ]),
79
+ );
80
+
81
+ return new Promise((resolve) => {
82
+ let answer = null;
83
+ const done = (text) => {
84
+ answer = text;
85
+ box.close();
86
+ };
87
+ const said = () => ta.value.trim() || (allowEmpty ? "" : null);
88
+ cancel.onclick = () => done(null);
89
+ go.onclick = () => done(said());
90
+ ta.addEventListener("keydown", (e) => {
91
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
92
+ e.preventDefault();
93
+ done(said());
94
+ }
95
+ });
96
+ // Escape and the backdrop both close it, and both mean no.
97
+ box.addEventListener("close", () => {
98
+ box.remove();
99
+ resolve(answer);
100
+ });
101
+ box.addEventListener("click", (e) => {
102
+ if (onBackdrop(e, box.getBoundingClientRect?.())) done(null);
103
+ });
104
+
105
+ document.body.append(box);
106
+ box.showModal();
107
+ grow(ta);
108
+ ta.focus();
109
+ // Put the caret at the end of a pre-filled answer rather than selecting it, so typing
110
+ // adds to what a finding already said instead of replacing it.
111
+ ta.setSelectionRange?.(ta.value.length, ta.value.length);
112
+ });
113
+ }
114
+
115
+ /**
116
+ * Asking before something that cannot be taken back: a merge, a push, a new repo, a paid run.
117
+ *
118
+ * Native `confirm()` looked like the browser rather than this page, and it blocks the whole
119
+ * tab, which froze browser automation mid-run. This is the same `<dialog>` as askText, so the
120
+ * backdrop, Escape and the focus trap come free. The wording is the caller's: `title` is the
121
+ * question, `hint` says what will happen.
122
+ *
123
+ * @returns true only for the confirm button. Escape, Cancel and the backdrop are all no.
124
+ */
125
+ export function askYes({ title, hint, confirm = "Continue" }) {
126
+ const box = document.createElement("dialog");
127
+ // The test shim has no dialog element; see askText.
128
+ if (typeof box.showModal !== "function") {
129
+ return Promise.resolve(Boolean(globalThis.confirm?.(hint ? title + "\n\n" + hint : title)));
130
+ }
131
+
132
+ box.className = "ask";
133
+ box.append(el("h3", { textContent: title }));
134
+ if (hint) box.append(el("p", { className: "askhint", textContent: hint }));
135
+
136
+ const cancel = el("button", { className: "ghbtn", textContent: "Cancel" });
137
+ const go = el("button", { className: "ghbtn primary", textContent: confirm });
138
+ box.append(el("div", { className: "row askrow" }, [cancel, go]));
139
+
140
+ return new Promise((resolve) => {
141
+ let answer = false;
142
+ const done = (yes) => {
143
+ answer = yes;
144
+ box.close();
145
+ };
146
+ cancel.onclick = () => done(false);
147
+ go.onclick = () => done(true);
148
+ box.addEventListener("close", () => {
149
+ box.remove();
150
+ resolve(answer);
151
+ });
152
+ box.addEventListener("click", (e) => {
153
+ if (onBackdrop(e, box.getBoundingClientRect?.())) done(false);
154
+ });
155
+ document.body.append(box);
156
+ box.showModal();
157
+ // Cancel has the focus, so an Enter pressed out of habit does not merge anything.
158
+ cancel.focus();
159
+ });
160
+ }
161
+
162
+ /**
163
+ * A larger dialog for a whole task: hiring someone, or finishing their setup. Native <dialog>
164
+ * again, appended to <body> rather than to the screen, so a background refresh repainting the
165
+ * screen leaves it open with whatever was typed into it.
166
+ *
167
+ * @returns {{set: (node: Node) => void, close: () => void, isOpen: () => boolean} | null}
168
+ * null where there is no dialog element (the test shim), and the caller draws inline instead.
169
+ */
170
+ export function sheet({ node, onClose, side = false }) {
171
+ const box = document.createElement("dialog");
172
+ if (typeof box.showModal !== "function") return null;
173
+ // `side` slides in from the right at full height, for reading a thread beside the page.
174
+ box.className = side ? "sheet side" : "sheet";
175
+ const body = el("div", { className: "sheetbody" });
176
+ body.append(node);
177
+ box.append(body);
178
+ let open = true;
179
+ const close = () => {
180
+ if (!open) return;
181
+ open = false;
182
+ box.close();
183
+ box.remove();
184
+ onClose?.();
185
+ };
186
+ box.addEventListener("cancel", (e) => {
187
+ e.preventDefault();
188
+ close();
189
+ });
190
+ box.addEventListener("click", (e) => {
191
+ if (onBackdrop(e, box.getBoundingClientRect())) close();
192
+ });
193
+ document.body.append(box);
194
+ box.showModal();
195
+ return { set: (n) => body.replaceChildren(n), close, isOpen: () => open };
196
+ }