@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
@@ -1,8 +1,8 @@
1
1
  /* The shell: boot, the sidebar, and dispatching a view into <main>. */
2
2
 
3
- import { getOrg } from "./api.js";
3
+ import { getOrgWithProgress, getSession } from "./api.js";
4
4
  import { $, el, store } from "./dom.js";
5
- import { icon, iconHTML } from "./icons.js";
5
+ import { icon, iconHTML, staffIcon } from "./icons.js";
6
6
  import { installLightbox } from "./lightbox.js";
7
7
  import { setPeople } from "./md.js";
8
8
  import {
@@ -14,21 +14,25 @@ import {
14
14
  syncNotice,
15
15
  } from "./refresh.js";
16
16
  import { onRender } from "./router.js";
17
- import { ORG_WIDE, S, VIEWS, applyHash, readHash, writeHash } from "./state.js";
17
+ import { ORG_WIDE, S, VIEWS, applyHash, humanLabel, readHash, writeHash } from "./state.js";
18
18
  import { viewBrain } from "./views/brain.js";
19
19
  import { viewChanged } from "./views/changed.js";
20
20
  import { viewDocs } from "./views/docs.js";
21
21
  import { viewGraph } from "./views/graph.js";
22
22
  import { viewHealth } from "./views/health.js";
23
+ import { openSearch } from "./search.js";
24
+ import { viewHome } from "./views/home.js";
23
25
  import { viewInbox, viewPrs } from "./views/inbox.js";
24
26
  import { viewOrg } from "./views/org.js";
25
27
  import { viewPrompt } from "./views/prompt.js";
26
28
  import { viewRuns } from "./views/runs.js";
29
+ import { sentence, whatsLeft } from "./readiness.js";
27
30
  import { paintSetupNav, viewGettingStarted, viewSetup } from "./views/setup.js";
28
31
  import { viewStaff } from "./views/staff.js";
29
32
 
30
33
  const SCREEN = {
31
34
  setup: viewGettingStarted,
35
+ home: viewHome,
32
36
  inbox: viewInbox,
33
37
  prs: viewPrs,
34
38
  runs: viewRuns,
@@ -56,8 +60,8 @@ const NEEDS = ["org", "name", "opsName", "staff"];
56
60
  /** The org-wide screens in the sidebar, by button. */
57
61
  const NAV = [
58
62
  ["#setupnav", "setup"],
63
+ ["#homenav", "home"],
59
64
  ["#inboxnav", "inbox"],
60
- ["#prsnav", "prs"],
61
65
  ["#runsnav", "runs"],
62
66
  ["#staffnav", "staff"],
63
67
  ["#orgnav", "org"],
@@ -92,14 +96,16 @@ export async function boot() {
92
96
  /* Before there is a tenant the server answers every data route with `mode: setup`. That is
93
97
  not an error state: it is the first thing a new user ever sees, and the whole page becomes
94
98
  the thing that fixes it. */
95
- const first = await getOrg();
99
+ const [first, session] = await Promise.all([loadWithProgress(), getSession()]);
100
+ S.hosted = session?.hosted ? session : null;
101
+ if (S.hosted) showSignedIn(S.hosted.login);
96
102
  if (first && first.mode === "setup") {
97
103
  document.body.dataset.setup = "1";
98
104
  $("#orgname").textContent = "no org yet";
99
105
  /* Every one of these reads a tenant, so during setup they answer 409 and the sidebar is a
100
106
  row of four dead ends beside an empty Staff heading. There is one thing to do on this
101
107
  screen; the navigation comes back with the org. */
102
- for (const el of document.querySelectorAll("#inboxnav, #prsnav, #runsnav, #orgnav, #staffnav, #docsnav, #refreshall, .sect, #stafflist")) {
108
+ for (const el of document.querySelectorAll("#sidesearch, #homenav, #inboxnav, #runsnav, #orgnav, #staffnav, #docsnav, #refreshall, .sect, #stafflist")) {
103
109
  el.hidden = true;
104
110
  }
105
111
  for (const slot of document.querySelectorAll("[data-icon]")) {
@@ -111,6 +117,8 @@ export async function boot() {
111
117
 
112
118
  S.data = first;
113
119
  S.loadedAt = new Date();
120
+ S.staffOpen = null; // an open hire list survives a refresh, not a page load
121
+ S.readiness = null;
114
122
  S.staffHandle = S.data.staff[0]?.handle ?? null;
115
123
  $("#orgname").textContent = S.data.name + " · " + S.data.staff.length + " staff";
116
124
 
@@ -126,7 +134,7 @@ export async function boot() {
126
134
  /* An org nobody has been hired into has an empty Inbox, which says nothing about what to do
127
135
  next. It opens on what is left instead, unless a link or a click asked for somewhere else. */
128
136
  if (early) S.view = early;
129
- else if (!linked && (S.data.unfinished ?? []).includes("hire")) S.view = "setup";
137
+ else if (!linked && !S.hosted && (S.data.unfinished ?? []).includes("hire")) S.view = "setup";
130
138
  initStaffFold();
131
139
  paintSidebar();
132
140
 
@@ -139,6 +147,19 @@ export async function boot() {
139
147
  addEventListener("focus", () => {
140
148
  if (S.loadedAt && Date.now() - S.loadedAt > 60000) refreshQuietly();
141
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";
142
163
  addEventListener("keydown", (e) => {
143
164
  if (e.key === "r" && !e.metaKey && !e.ctrlKey &&
144
165
  !/^(INPUT|TEXTAREA|SELECT)$/.test(e.target?.tagName ?? "")) {
@@ -251,6 +272,7 @@ function initStaffFold() {
251
272
  }
252
273
 
253
274
  function paintSidebar() {
275
+ paintInboxLinks();
254
276
  const host = $("#stafflist");
255
277
  host.replaceChildren();
256
278
  paintedRoster = S.data.staff.map((s) => s.handle).join(" ");
@@ -261,11 +283,20 @@ function paintSidebar() {
261
283
  const head = el("button", { className: "nav staffrow" });
262
284
  head.dataset.staff = s.handle;
263
285
  head.setAttribute("aria-expanded", String(open));
286
+ const dot = el("span", { className: "readydot", hidden: true });
264
287
  head.append(
265
288
  icon("chevron", "caret"),
289
+ icon(staffIcon(s), "ic"),
266
290
  el("span", { className: "t", textContent: s.name }),
291
+ dot,
267
292
  el("span", { className: "hh", textContent: s.handle }),
268
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
+ });
269
300
 
270
301
  const views = el("div", { className: "staffviews" });
271
302
  views.hidden = !open;
@@ -304,7 +335,43 @@ function paintSidebar() {
304
335
  }
305
336
 
306
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
+
307
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
+ }
308
375
  for (const b of document.querySelectorAll(".nav")) {
309
376
  if (!b.dataset.view) continue;
310
377
  const mine = !b.dataset.staff || b.dataset.staff === S.staffHandle;
@@ -342,6 +409,57 @@ function render() {
342
409
  (SCREEN[S.view] ?? viewBrain)(m);
343
410
  }
344
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
+
345
463
  /* --------------------------------- theme ---------------------------------- */
346
464
 
347
465
  /* Three states on purpose: "system" is the default and has to be reachable again after
@@ -158,3 +158,39 @@ export function askYes({ title, hint, confirm = "Continue" }) {
158
158
  cancel.focus();
159
159
  });
160
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
+ }
@@ -0,0 +1,174 @@
1
+ /* Where every issue and pull request goes on Home.
2
+ *
3
+ * Every open item lands in exactly one place, so nothing is missed and nothing shows twice:
4
+ *
5
+ * needs an ask on a person, or a pull request ready to merge
6
+ * requests something a person asked a staff member for
7
+ * staff a staff member's own work: their status issue, a peer's ask, their own issues
8
+ * elsewhere draft pull requests, and product or ops issues nobody has put on a person
9
+ *
10
+ * `unread` is not a place: it lists what in `staff` and `elsewhere` has activity you have not
11
+ * seen (from your GitHub notifications), since those two are otherwise off Home. Items in the
12
+ * other places carry their own unread mark.
13
+ *
14
+ * Closed items only matter when a staff member closed them today: that is "Closed today", with
15
+ * Reopen beside each, because staff now close things without asking. */
16
+
17
+ /** The kinds an ask on a person carries. Older trackers used other words for a chore. */
18
+ const KINDS = ["decision", "review", "chore"];
19
+ const CHORE_WORDS = ["setup", "submit", "data", "blocked"];
20
+
21
+ const lower = (s) => String(s ?? "").toLowerCase();
22
+
23
+ /** How old a run report can be and still be this morning's. */
24
+ const REPORT_HOURS = 20;
25
+
26
+ /** A run report as lines, without the @mention it opens with. */
27
+ function reportLines(body) {
28
+ return String(body ?? "")
29
+ .split("\n")
30
+ .map((l) => l.replace(/^\s*(@[\w-]+\s*)+/, "").replace(/^[-*]\s+/, "").trim())
31
+ .filter(Boolean)
32
+ .slice(0, 5);
33
+ }
34
+
35
+ /**
36
+ * @param items the inbox list: open and recently closed issues and pull requests
37
+ * @param staff S.data.staff: handle, name, brain, statusIssue, mention
38
+ * @param humans [{ github, marker }]
39
+ * @param live /api/live's staff list, or [] before it has answered
40
+ * @param now for "today", in the viewer's own day
41
+ */
42
+ export function sortHome(items, staff, humans, live = [], now = new Date()) {
43
+ const people = new Set(humans.map((h) => lower(h.github)).filter(Boolean));
44
+ const markers = new Set(humans.map((h) => lower(h.marker)).filter(Boolean));
45
+ const byBrain = new Map(staff.filter((s) => s.brain).map((s) => [s.brain, s]));
46
+ const working = new Set();
47
+ for (const l of live) {
48
+ const s = staff.find((x) => x.handle === l.handle);
49
+ for (const r of l.running ?? []) if (s && r.issue) working.add(`${s.brain}#${r.issue}`);
50
+ }
51
+
52
+ const out = {
53
+ reports: [],
54
+ needs: [],
55
+ requests: [],
56
+ staff: [],
57
+ elsewhere: [],
58
+ unread: [],
59
+ closedToday: [],
60
+ };
61
+ const today = dayOf(now);
62
+
63
+ for (const item of items) {
64
+ const owner = byBrain.get(item.repo) ?? null;
65
+
66
+ if (item.state !== "OPEN") {
67
+ if (
68
+ owner &&
69
+ item.kind === "issue" &&
70
+ item.closedAt &&
71
+ dayOf(new Date(item.closedAt)) === today &&
72
+ !people.has(lower(item.closedBy))
73
+ ) {
74
+ out.closedToday.push({ item, staff: owner, reason: reasonOf(item, people) });
75
+ }
76
+ continue;
77
+ }
78
+
79
+ // The run report: the last word on a status issue, from the staff member, in the last day.
80
+ const c = item.lastComment;
81
+ if (
82
+ owner &&
83
+ item.number === owner.statusIssue &&
84
+ c &&
85
+ !people.has(lower(c.author)) &&
86
+ now - new Date(c.createdAt) < REPORT_HOURS * 3_600_000
87
+ ) {
88
+ out.reports.push({ staff: owner, item, at: c.createdAt, lines: reportLines(c.body) });
89
+ }
90
+
91
+ const place = placeOf(item, owner, people, markers);
92
+ const entry = { item, staff: owner, ...place };
93
+ if (place.place === "requests") {
94
+ entry.status = working.has(`${item.repo}#${item.number}`)
95
+ ? "working"
96
+ : item.lastComment && !people.has(lower(item.lastComment.author))
97
+ ? "answered"
98
+ : "waiting";
99
+ }
100
+ out[place.place].push(entry);
101
+ }
102
+
103
+ const oldest = (a, b) => a.item.createdAt.localeCompare(b.item.createdAt);
104
+ out.needs.sort(oldest);
105
+ out.requests.sort((a, b) => b.item.updatedAt.localeCompare(a.item.updatedAt));
106
+ out.closedToday.sort((a, b) => b.item.closedAt.localeCompare(a.item.closedAt));
107
+ out.unread = [...out.staff, ...out.elsewhere]
108
+ .filter((e) => e.item.unread)
109
+ .sort((a, b) => b.item.updatedAt.localeCompare(a.item.updatedAt));
110
+ return out;
111
+ }
112
+
113
+ /** Which place an open item belongs in, and for an ask, which kind it is. */
114
+ export function placeOf(item, owner, people, markers) {
115
+ if (item.kind === "pr") {
116
+ return item.draft ? { place: "elsewhere", why: "draft" } : { place: "needs", kind: "merge" };
117
+ }
118
+
119
+ const labels = (item.labels ?? []).map(lower);
120
+ const onPerson =
121
+ (item.assignees ?? []).some((a) => people.has(lower(a))) ||
122
+ labels.some((l) => markers.has(l));
123
+ const byPerson = people.has(lower(item.author));
124
+ /* You had the last word on an ask: approved it, answered it, said go with the default. It is
125
+ waiting on them now, so it is one of your requests until they reply or close it. If they
126
+ reply, the last word is theirs and it is back on you. */
127
+ const youAnswered = Boolean(item.lastComment) && people.has(lower(item.lastComment.author));
128
+
129
+ if (!owner) {
130
+ if (!onPerson || byPerson) {
131
+ return { place: "elsewhere", why: item.role === "product" ? "contributor" : "other" };
132
+ }
133
+ return youAnswered ? { place: "requests" } : { place: "needs", kind: kindOf(labels) };
134
+ }
135
+ if (item.number === owner.statusIssue || labels.includes("keep-open")) {
136
+ return { place: "staff", why: "status" };
137
+ }
138
+ if (byPerson) return { place: "requests" };
139
+ if (onPerson) return youAnswered ? { place: "requests" } : { place: "needs", kind: kindOf(labels) };
140
+ return {
141
+ place: "staff",
142
+ why: labels.some((l) => l.startsWith("from-")) ? "peer" : "own",
143
+ };
144
+ }
145
+
146
+ function kindOf(labels) {
147
+ const found = KINDS.find((k) => labels.includes(k));
148
+ if (found) return found;
149
+ return labels.some((l) => CHORE_WORDS.includes(l)) ? "chore" : "ask";
150
+ }
151
+
152
+ /** The one line a staff member closed it with: their last comment's first line. */
153
+ function reasonOf(item, people) {
154
+ const c = item.lastComment;
155
+ if (!c || people.has(lower(c.author))) return "";
156
+ const line = String(c.body ?? "")
157
+ .split("\n")
158
+ .map((l) => l.trim())
159
+ .find(Boolean);
160
+ return line ? line.replace(/^[#>*\s-]+/, "").slice(0, 160) : "";
161
+ }
162
+
163
+ /** A date as the viewer's own calendar day. */
164
+ export function dayOf(d) {
165
+ return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
166
+ }
167
+
168
+ /** Whole days from today to a YYYY-MM-DD date: 0 today, negative once it has passed. */
169
+ export function daysUntil(date, now = new Date()) {
170
+ const [y, m, d] = String(date).split("-").map(Number);
171
+ const due = new Date(y, m - 1, d);
172
+ const start = new Date(now.getFullYear(), now.getMonth(), now.getDate());
173
+ return Math.round((due - start) / 86_400_000);
174
+ }
@@ -13,6 +13,30 @@
13
13
  */
14
14
 
15
15
  const PATHS = {
16
+ "search":
17
+ "<circle cx=\"11\" cy=\"11\" r=\"8\" /> <path d=\"m21 21-4.3-4.3\" />",
18
+ "lightbulb":
19
+ "<path d=\"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5\" /> <path d=\"M9 18h6\" /> <path d=\"M10 22h4\" />",
20
+ "code":
21
+ "<polyline points=\"16 18 22 12 16 6\" /> <polyline points=\"8 6 2 12 8 18\" />",
22
+ "megaphone":
23
+ "<path d=\"m3 11 18-5v12L3 14v-3z\" /> <path d=\"M11.6 16.8a3 3 0 1 1-5.8-1.6\" />",
24
+ "life-buoy":
25
+ "<circle cx=\"12\" cy=\"12\" r=\"10\" /> <path d=\"m4.93 4.93 4.24 4.24\" /> <path d=\"m14.83 9.17 4.24-4.24\" /> <path d=\"m14.83 14.83 4.24 4.24\" /> <path d=\"m9.17 14.83-4.24 4.24\" /> <circle cx=\"12\" cy=\"12\" r=\"4\" />",
26
+ "compass":
27
+ "<circle cx=\"12\" cy=\"12\" r=\"10\" /> <polygon points=\"16.24 7.76 14.12 14.12 7.76 16.24 9.88 9.88 16.24 7.76\" />",
28
+ "brush":
29
+ "<path d=\"m9.06 11.9 8.07-8.06a2.85 2.85 0 1 1 4.03 4.03l-8.06 8.08\" /> <path d=\"M7.07 14.94c-1.66 0-3 1.35-3 3.02 0 1.33-2.5 1.52-2 2.02 1.08 1.1 2.49 2.02 4 2.02 2.2 0 4-1.8 4-4.04a3.01 3.01 0 0 0-3-3.02z\" />",
30
+ "bug":
31
+ "<path d=\"m8 2 1.88 1.88\" /> <path d=\"M14.12 3.88 16 2\" /> <path d=\"M9 7.13v-1a3.003 3.003 0 1 1 6 0v1\" /> <path d=\"M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6\" /> <path d=\"M12 20v-9\" /> <path d=\"M6.53 9C4.6 8.8 3 7.1 3 5\" /> <path d=\"M6 13H2\" /> <path d=\"M3 21c0-2.1 1.7-3.9 3.8-4\" /> <path d=\"M20.97 5c0 2.1-1.6 3.8-3.5 4\" /> <path d=\"M22 13h-4\" /> <path d=\"M17.2 17c2.1.1 3.8 1.9 3.8 4\" />",
32
+ "server":
33
+ "<rect width=\"20\" height=\"8\" x=\"2\" y=\"2\" rx=\"2\" ry=\"2\" /> <rect width=\"20\" height=\"8\" x=\"2\" y=\"14\" rx=\"2\" ry=\"2\" /> <line x1=\"6\" x2=\"6.01\" y1=\"6\" y2=\"6\" /> <line x1=\"6\" x2=\"6.01\" y1=\"18\" y2=\"18\" />",
34
+ "book-open":
35
+ "<path d=\"M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z\" /> <path d=\"M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z\" />",
36
+ "bar-chart":
37
+ "<line x1=\"12\" x2=\"12\" y1=\"20\" y2=\"10\" /> <line x1=\"18\" x2=\"18\" y1=\"20\" y2=\"4\" /> <line x1=\"6\" x2=\"6\" y1=\"20\" y2=\"16\" />",
38
+ "users":
39
+ "<path d=\"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2\" /> <circle cx=\"9\" cy=\"7\" r=\"4\" /> <path d=\"M22 21v-2a4 4 0 0 0-3-3.87\" /> <path d=\"M16 3.13a4 4 0 0 1 0 7.75\" />",
16
40
  "check":
17
41
  "<path d=\"M20 6 9 17l-5-5\" />",
18
42
  "chevron":
@@ -96,6 +120,23 @@ export function icon(name, cls = "") {
96
120
  return span.firstChild ?? span;
97
121
  }
98
122
 
123
+ /* A staff member's icon: `icon:` in their staff.yaml, or one picked from their role. */
124
+ const ROLE_ICONS = {
125
+ cto: "code",
126
+ cmo: "megaphone",
127
+ support: "life-buoy",
128
+ pm: "compass",
129
+ designer: "brush",
130
+ qa: "bug",
131
+ devops: "server",
132
+ writer: "book-open",
133
+ analyst: "bar-chart",
134
+ community: "users",
135
+ };
136
+ export function staffIcon(s) {
137
+ return s?.icon && hasIcon(s.icon) ? s.icon : (ROLE_ICONS[s?.handle] ?? "person");
138
+ }
139
+
99
140
  export function hasIcon(name) {
100
141
  return Object.hasOwn(PATHS, name);
101
142
  }
@@ -0,0 +1,18 @@
1
+ /* How many requests the page has open. The setup dialog waits for this to reach zero before it
2
+ * shows itself, because the list it draws is only final once every answer is back. */
3
+
4
+ let open = 0;
5
+
6
+ if (typeof globalThis.fetch === "function" && !globalThis.fetch.counted) {
7
+ const real = globalThis.fetch.bind(globalThis);
8
+ const counted = (...args) => {
9
+ open++;
10
+ return real(...args).finally(() => {
11
+ open--;
12
+ });
13
+ };
14
+ counted.counted = true;
15
+ globalThis.fetch = counted;
16
+ }
17
+
18
+ export const pending = () => open;
@@ -361,7 +361,9 @@ function mdAsset(src, opts) {
361
361
  return path ? "/api/file?path=" + encodeURIComponent(opts.file.staffDir + "/" + path) : src;
362
362
  }
363
363
 
364
- const REF_RE = /(^|[\s(>])([\w.-]+\/[\w.-]+)?#(\d+)\b/g;
364
+ /* #123, repo#123 and owner/repo#123. The short repo form is how the staff write about the other
365
+ repos in their own org (pip-web#172), and it was left as plain text. */
366
+ const REF_RE = /(^|[\s(>])((?:[\w.-]+\/)?[\w.-]+)?#(\d+)\b/g;
365
367
  // GitHub's own username shape, plus the short aliases the agents answer to.
366
368
  const AT_RE = /(^|[\s(>])@([a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38})\b/gi;
367
369
 
@@ -381,7 +383,8 @@ export function chips(html, opts = {}) {
381
383
  if (inA) return p;
382
384
  return p
383
385
  .replace(REF_RE, (m, pre, repo, n) => {
384
- const target = repo || opts.repo;
386
+ const owner = String(opts.repo ?? "").split("/")[0];
387
+ const target = !repo ? opts.repo : repo.includes("/") ? repo : owner ? owner + "/" + repo : "";
385
388
  if (!target) return m;
386
389
  // /issues/N redirects to /pull/N when it is a PR, so one form is always right.
387
390
  return pre + '<a class="ref" href="https://github.com/' + target + "/issues/" + n +
@@ -0,0 +1,84 @@
1
+ /* Colour behind a textarea, for the files people edit here.
2
+ *
3
+ * The textarea stays the thing you type into, so undo, selection, spellcheck and ⌘S all work
4
+ * as they always did. Its text is made transparent and a <pre> with the same box sits behind
5
+ * it, redrawn on every keystroke. The editors grow to fit rather than scroll, which is what
6
+ * keeps the two lined up without syncing a scroll position.
7
+ *
8
+ * Markdown here is a per-line tokeniser, like yaml.js: enough to read by, and anything it does
9
+ * not recognise is plain text rather than an error.
10
+ */
11
+
12
+ import { el, esc } from "./dom.js";
13
+ import { yamlHTML } from "./yaml.js";
14
+
15
+ /**
16
+ * Wrap a textarea so its contents are highlighted. Returns the wrapper, which is what goes on
17
+ * the page in place of the textarea.
18
+ * @param {"md"|"yaml"} lang
19
+ */
20
+ export function highlighted(ta, lang = "md") {
21
+ const wrap = el("div", { className: "hled" });
22
+ const back = el("pre", { className: "hlback" });
23
+ back.setAttribute?.("aria-hidden", "true");
24
+ ta.classList?.add("hlfront");
25
+ wrap.append(back, ta);
26
+ /* The colours only line up if both boxes set text identically, and the textarea's box comes
27
+ from whichever class it already had, so it is read rather than restated in CSS. */
28
+ const match = () => {
29
+ if (typeof getComputedStyle !== "function" || !ta.isConnected) return;
30
+ const cs = getComputedStyle(ta);
31
+ for (const k of ["font", "lineHeight", "letterSpacing", "tabSize", "padding", "borderWidth", "borderStyle", "borderRadius"]) {
32
+ back.style[k] = cs[k];
33
+ }
34
+ };
35
+ const paint = () => {
36
+ match();
37
+ // A trailing newline in a textarea is a line; in a <pre> it is not, without something after it.
38
+ back.innerHTML = (lang === "yaml" ? yamlHTML(ta.value) : markdownHTML(ta.value)) + "\n ";
39
+ };
40
+ ta.addEventListener("input", paint);
41
+ paint();
42
+ // Setting .value from code fires no input event, so the owner can ask for a repaint.
43
+ wrap.repaint = paint;
44
+ return wrap;
45
+ }
46
+
47
+ /** Escaped, highlighted HTML for markdown source. */
48
+ export function markdownHTML(text) {
49
+ let fenced = false;
50
+ return String(text ?? "")
51
+ .split("\n")
52
+ .map((line) => {
53
+ if (/^\s*(```|~~~)/.test(line)) {
54
+ fenced = !fenced;
55
+ return span("mdfence", line);
56
+ }
57
+ if (fenced) return span("mdcode", line);
58
+ if (/^#{1,6}\s/.test(line)) return span("mdh", line);
59
+ if (/^\s*>/.test(line)) return span("mdq", line);
60
+ if (/^\s*([-*_])(\s*\1){2,}\s*$/.test(line)) return span("mdfence", line);
61
+ const list = /^(\s*)([-*+]|\d+[.)])(\s+)(.*)$/.exec(line);
62
+ if (list) return esc(list[1]) + span("mdl", list[2]) + esc(list[3]) + inline(list[4]);
63
+ return inline(line);
64
+ })
65
+ .join("\n");
66
+ }
67
+
68
+ const span = (cls, text) => '<span class="' + cls + '">' + esc(text) + "</span>";
69
+
70
+ /** Inline marks, on one line. Code spans first, so nothing inside one is read as markup. */
71
+ function inline(line) {
72
+ return line
73
+ .split(/(`[^`]+`)/)
74
+ .map((part, i) => (i % 2 ? span("mdc", part) : marks(part)))
75
+ .join("");
76
+ }
77
+
78
+ function marks(text) {
79
+ return esc(text)
80
+ .replace(/\{\{[^}]*\}\}/g, (m) => '<span class="mdt">' + m + "</span>")
81
+ .replace(/(\*\*|__)(?=\S)(.+?)(?<=\S)\1/g, '<span class="mdb">$1$2$1</span>')
82
+ .replace(/(^|[^*\w])([*_])(?=\S)([^*_]+?)(?<=\S)\2(?![*\w])/g, '$1<span class="mdi">$2$3$2</span>')
83
+ .replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, '<span class="mdk">[$1]</span><span class="mdu">($2)</span>');
84
+ }