@nanocollective/roster 0.1.0-beta.3 → 0.1.0-beta.31

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 (147) hide show
  1. package/README.md +8 -0
  2. package/dist/agents-POITEZRI.js +232 -0
  3. package/dist/chunk-FF2WBNNW.js +370 -0
  4. package/dist/chunk-GDAJPOHK.js +562 -0
  5. package/dist/cli.js +3391 -1239
  6. package/dist/compose-5DBEHSEV.js +17 -0
  7. package/dist/connectors-5E5ZMGZV.js +23 -0
  8. package/dist/worker/assets/assets/css/astryx.css +948 -0
  9. package/dist/worker/assets/assets/css/base.css +51 -110
  10. package/dist/worker/assets/assets/css/brain.css +28 -2
  11. package/dist/worker/assets/assets/css/connectors.css +58 -0
  12. package/dist/worker/assets/assets/css/graph.css +9 -12
  13. package/dist/worker/assets/assets/css/health.css +4 -7
  14. package/dist/worker/assets/assets/css/home.css +155 -60
  15. package/dist/worker/assets/assets/css/inbox.css +11 -0
  16. package/dist/worker/assets/assets/css/layout.css +18 -22
  17. package/dist/worker/assets/assets/css/markdown.css +22 -1
  18. package/dist/worker/assets/assets/css/routines.css +43 -0
  19. package/dist/worker/assets/assets/css/runs.css +5 -3
  20. package/dist/worker/assets/assets/css/search.css +3 -6
  21. package/dist/worker/assets/assets/css/setup.css +8 -15
  22. package/dist/worker/assets/assets/js/api.js +3 -0
  23. package/dist/worker/assets/assets/js/app.js +28 -1
  24. package/dist/worker/assets/assets/js/astryx-ui.js +34 -0
  25. package/dist/worker/assets/assets/js/dom.js +1 -1
  26. package/dist/worker/assets/assets/js/homesort.js +66 -20
  27. package/dist/worker/assets/assets/js/icons.js +6 -0
  28. package/dist/worker/assets/assets/js/md.js +7 -2
  29. package/dist/worker/assets/assets/js/mention.js +2 -1
  30. package/dist/worker/assets/assets/js/readiness.js +36 -0
  31. package/dist/worker/assets/assets/js/refcard.js +216 -0
  32. package/dist/worker/assets/assets/js/refresh.js +8 -2
  33. package/dist/worker/assets/assets/js/report.js +51 -0
  34. package/dist/worker/assets/assets/js/select.js +362 -0
  35. package/dist/worker/assets/assets/js/state.js +14 -1
  36. package/dist/worker/assets/assets/js/views/connectors.js +428 -0
  37. package/dist/worker/assets/assets/js/views/graph.js +67 -28
  38. package/dist/worker/assets/assets/js/views/health.js +11 -5
  39. package/dist/worker/assets/assets/js/views/home.js +453 -174
  40. package/dist/worker/assets/assets/js/views/inbox.js +82 -17
  41. package/dist/worker/assets/assets/js/views/notready.js +60 -0
  42. package/dist/worker/assets/assets/js/views/org.js +16 -1
  43. package/dist/worker/assets/assets/js/views/people.js +109 -0
  44. package/dist/worker/assets/assets/js/views/routines.js +395 -0
  45. package/dist/worker/assets/assets/js/views/runonce.js +5 -0
  46. package/dist/worker/assets/assets/js/views/runs.js +14 -2
  47. package/dist/worker/assets/assets/js/views/staff.js +18 -3
  48. package/dist/worker/assets/docs-images/brain.jpg +0 -0
  49. package/dist/worker/assets/docs-images/home.jpg +0 -0
  50. package/dist/worker/assets/docs-images/org.jpg +0 -0
  51. package/dist/worker/assets/docs-images/prompt.jpg +0 -0
  52. package/dist/worker/assets/docs-images/setup-org.jpg +0 -0
  53. package/dist/worker/assets/docs-images/setup-plan.jpg +0 -0
  54. package/dist/worker/assets/docs-images/staff.jpg +0 -0
  55. package/dist/worker/assets/index.html +19 -3
  56. package/dist/worker/index.js +4478 -1098
  57. package/docs/README.md +2 -0
  58. package/docs/architecture.md +23 -4
  59. package/docs/commands.md +111 -9
  60. package/docs/concepts.md +2 -1
  61. package/docs/connectors.md +169 -0
  62. package/docs/cost.md +1 -1
  63. package/docs/developing.md +3 -3
  64. package/docs/doctor-codes.md +8 -2
  65. package/docs/export.md +4 -3
  66. package/docs/extending.md +1 -1
  67. package/docs/getting-started.md +20 -3
  68. package/docs/hosting.md +67 -3
  69. package/docs/images/brain.jpg +0 -0
  70. package/docs/images/home.jpg +0 -0
  71. package/docs/images/org.jpg +0 -0
  72. package/docs/images/prompt.jpg +0 -0
  73. package/docs/images/setup-org.jpg +0 -0
  74. package/docs/images/setup-plan.jpg +0 -0
  75. package/docs/images/staff.jpg +0 -0
  76. package/docs/memory.md +3 -2
  77. package/docs/org-yaml.md +58 -5
  78. package/docs/portal.md +52 -11
  79. package/docs/prompts.md +3 -2
  80. package/docs/routines.md +65 -0
  81. package/docs/security.md +37 -4
  82. package/docs/session-workflow.md +31 -8
  83. package/docs/staff-yaml.md +7 -3
  84. package/docs/troubleshooting.md +1 -1
  85. package/docs/upgrading.md +1 -1
  86. package/docs/writing-a-charter.md +1 -1
  87. package/package.json +8 -1
  88. package/templates/brain/.gitattributes +3 -0
  89. package/templates/brain/.github/workflows/%%STAFF%%-daily.yaml +24 -15
  90. package/templates/brain/.github/workflows/%%STAFF%%-mention.yaml +12 -10
  91. package/templates/brain/CHARTER.md +2 -2
  92. package/templates/brain/STATE.md +16 -0
  93. package/templates/brain/memory/INDEX.md +1 -1
  94. package/templates/brain/staff.yaml +3 -0
  95. package/templates/ops/.gitattributes +3 -0
  96. package/templates/ops/.github/workflows/session.yaml +92 -13
  97. package/templates/ops/agents.mjs +38 -11
  98. package/templates/ops/compose.mjs +60 -2
  99. package/templates/ops/connectors.mjs +722 -0
  100. package/templates/ops/org/operating.md +10 -0
  101. package/templates/ops/org/voice.md +21 -3
  102. package/templates/ops/prompts/_identity.md +20 -0
  103. package/templates/ops/prompts/daily.md +70 -19
  104. package/templates/ops/prompts/mention.md +7 -2
  105. package/templates/ops/status-week.mjs +169 -0
  106. package/templates/portal/css/astryx.css +948 -0
  107. package/templates/portal/css/base.css +51 -110
  108. package/templates/portal/css/brain.css +28 -2
  109. package/templates/portal/css/connectors.css +58 -0
  110. package/templates/portal/css/graph.css +9 -12
  111. package/templates/portal/css/health.css +4 -7
  112. package/templates/portal/css/home.css +155 -60
  113. package/templates/portal/css/inbox.css +11 -0
  114. package/templates/portal/css/layout.css +18 -22
  115. package/templates/portal/css/markdown.css +22 -1
  116. package/templates/portal/css/routines.css +43 -0
  117. package/templates/portal/css/runs.css +5 -3
  118. package/templates/portal/css/search.css +3 -6
  119. package/templates/portal/css/setup.css +8 -15
  120. package/templates/portal/index.html +19 -3
  121. package/templates/portal/js/api.js +3 -0
  122. package/templates/portal/js/app.js +28 -1
  123. package/templates/portal/js/astryx-ui.js +34 -0
  124. package/templates/portal/js/dom.js +1 -1
  125. package/templates/portal/js/homesort.js +66 -20
  126. package/templates/portal/js/icons.js +6 -0
  127. package/templates/portal/js/md.js +7 -2
  128. package/templates/portal/js/mention.js +2 -1
  129. package/templates/portal/js/readiness.js +36 -0
  130. package/templates/portal/js/refcard.js +216 -0
  131. package/templates/portal/js/refresh.js +8 -2
  132. package/templates/portal/js/report.js +51 -0
  133. package/templates/portal/js/select.js +362 -0
  134. package/templates/portal/js/state.js +14 -1
  135. package/templates/portal/js/views/connectors.js +428 -0
  136. package/templates/portal/js/views/graph.js +67 -28
  137. package/templates/portal/js/views/health.js +11 -5
  138. package/templates/portal/js/views/home.js +453 -174
  139. package/templates/portal/js/views/inbox.js +82 -17
  140. package/templates/portal/js/views/notready.js +60 -0
  141. package/templates/portal/js/views/org.js +16 -1
  142. package/templates/portal/js/views/people.js +109 -0
  143. package/templates/portal/js/views/routines.js +395 -0
  144. package/templates/portal/js/views/runonce.js +5 -0
  145. package/templates/portal/js/views/runs.js +14 -2
  146. package/templates/portal/js/views/staff.js +18 -3
  147. package/templates/skill/SKILL.md +115 -0
@@ -13,10 +13,14 @@ import {
13
13
  stampLoaded,
14
14
  syncNotice,
15
15
  } from "./refresh.js";
16
+ import { installRefs } from "./refcard.js";
17
+ import { installSelects } from "./select.js";
16
18
  import { onRender } from "./router.js";
17
19
  import { ORG_WIDE, S, VIEWS, applyHash, humanLabel, readHash, writeHash } from "./state.js";
18
20
  import { viewBrain } from "./views/brain.js";
19
21
  import { viewChanged } from "./views/changed.js";
22
+ import { viewConnectors } from "./views/connectors.js";
23
+ import { viewRoutines } from "./views/routines.js";
20
24
  import { viewDocs } from "./views/docs.js";
21
25
  import { viewGraph } from "./views/graph.js";
22
26
  import { viewHealth } from "./views/health.js";
@@ -38,6 +42,8 @@ const SCREEN = {
38
42
  runs: viewRuns,
39
43
  org: viewOrg,
40
44
  staff: viewStaff,
45
+ connectors: viewConnectors,
46
+ routines: viewRoutines,
41
47
  docs: viewDocs,
42
48
  brain: viewBrain,
43
49
  memory: viewBrain,
@@ -64,12 +70,15 @@ const NAV = [
64
70
  ["#inboxnav", "inbox"],
65
71
  ["#runsnav", "runs"],
66
72
  ["#staffnav", "staff"],
73
+ ["#routinesnav", "routines"],
74
+ ["#connectorsnav", "connectors"],
67
75
  ["#orgnav", "org"],
68
76
  ["#docsnav", "docs"],
69
77
  ];
70
78
 
71
79
  export async function boot() {
72
80
  initTheme();
81
+ initIcon();
73
82
 
74
83
  /* Bound before the first request rather than after it. The sidebar is markup, so it is on
75
84
  screen and clickable while /api/org is still building the export, and a click in that
@@ -92,12 +101,15 @@ export async function boot() {
92
101
  /* Before the first render, and once: it is delegated, so it covers every image any screen
93
102
  draws from here on, including the setup screen. */
94
103
  installLightbox();
104
+ installRefs();
105
+ installSelects();
95
106
 
96
107
  /* Before there is a tenant the server answers every data route with `mode: setup`. That is
97
108
  not an error state: it is the first thing a new user ever sees, and the whole page becomes
98
109
  the thing that fixes it. */
99
110
  const [first, session] = await Promise.all([loadWithProgress(), getSession()]);
100
111
  S.hosted = session?.hosted ? session : null;
112
+ S.me = session?.login || null;
101
113
  if (S.hosted) showSignedIn(S.hosted.login);
102
114
  if (first && first.mode === "setup") {
103
115
  document.body.dataset.setup = "1";
@@ -105,7 +117,7 @@ export async function boot() {
105
117
  /* Every one of these reads a tenant, so during setup they answer 409 and the sidebar is a
106
118
  row of four dead ends beside an empty Staff heading. There is one thing to do on this
107
119
  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")) {
120
+ for (const el of document.querySelectorAll("#sidesearch, #homenav, #inboxnav, #runsnav, #orgnav, #staffnav, #routinesnav, #connectorsnav, #docsnav, #refreshall, .sect, #stafflist")) {
109
121
  el.hidden = true;
110
122
  }
111
123
  for (const slot of document.querySelectorAll("[data-icon]")) {
@@ -392,6 +404,9 @@ function render() {
392
404
  export and a portal can go stale under a page that is already open. */
393
405
  const missing = NEEDS.filter((k) => S.data?.[k] === undefined);
394
406
  if (missing.length) return stale(missing);
407
+ /* A staff member's screen with nobody hired threw on the missing staff member and left the
408
+ page blank. A hash like #/-/brain still lands here, so it gets Home, which says what to do. */
409
+ if (!S.data.staff.length && !ORG_WIDE.has(S.view)) S.view = "home";
395
410
 
396
411
  // A refresh can add or remove a staff member, and the sidebar is built once.
397
412
  const roster = S.data.staff.map((s) => s.handle).join(" ");
@@ -479,6 +494,18 @@ function applyTheme(name) {
479
494
  }
480
495
  }
481
496
 
497
+ /* The org's own icon, if its ops repo has one at portal/icon.*: in the sidebar and the tab. */
498
+ function initIcon() {
499
+ const img = document.createElement("img");
500
+ img.className = "mark";
501
+ img.alt = "";
502
+ img.onload = () => {
503
+ document.querySelector(".brand .mark")?.replaceWith(img);
504
+ document.querySelector('link[rel="icon"]')?.setAttribute("href", "/icon");
505
+ };
506
+ img.src = "/icon";
507
+ }
508
+
482
509
  function initTheme() {
483
510
  let theme = store("roster.theme") ?? "system";
484
511
  if (!THEMES.includes(theme)) theme = "system";
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Generated by scripts/astryx.mjs from @astryxdesign/core 0.7.11. Do not edit.
3
+ *
4
+ * Astryx's own class strings for the controls the portal builds in its own markup, element by
5
+ * element, as the React components put them. css/astryx.css carries their rules unchanged.
6
+ * Astryx: Copyright (c) Meta Platforms, Inc. and affiliates. MIT licence.
7
+ */
8
+
9
+ /** Selector: the trigger, the layer it opens, and a row in its list, with the row's states. */
10
+ export const SELECTOR = {
11
+ "frame": "x9f619 x1vjfegm x1litavf x1y0btm7 xvy26l8 x6q1khz xohk9ji x1832zxr xvdfih8 x10xzikg x12zzom9 xuedmi6 x12w9bfk xlr8y92 x1gnnqk1 x1xqjsvb xuihb5h x1a2a7pz x1n2onr6 x78zum5 x6s0dn4 x1qughib x1txdalj xh8yej3 xrrkdod x9ynric xcr08ib x1w61h2b x1tgivj0 x1ypdohk x16khyan x1uogy3y xe5am2i xj646f7",
12
+ "button": "x78zum5 x6s0dn4 x1qughib x1txdalj x1iyjqo2 xs83m0k x1r8uery xeuugli x1717udv x1ghz6dp xc342km xng3xce xjbqb8w xjb2p0i x1qlqyl8 x15bjb6t x1heor9g x1ypdohk x16khyan x1a2a7pz",
13
+ "buttonOpen": "x78zum5 x6s0dn4 x1qughib x1txdalj x1iyjqo2 xs83m0k x1r8uery xeuugli x1717udv x1ghz6dp xc342km xng3xce xjbqb8w xjb2p0i x1qlqyl8 x15bjb6t x1heor9g x1ypdohk x16khyan x1a2a7pz",
14
+ "value": "x1iyjqo2 xeuugli xb3r6kr xlyipyv xuxw1ft x1yc453h",
15
+ "chevron": "x3nfvp2 x6s0dn4 xl56j7k xv9yike xomy6nw x14eyxzr x1qzu985 x2lah0s x11xpdln xuedmi6 xlr8y92 x1g0ag68",
16
+ "chevronOpen": "x3nfvp2 x6s0dn4 xl56j7k xv9yike xomy6nw x14eyxzr x1qzu985 x2lah0s x11xpdln xuedmi6 xlr8y92 x1g0ag68 x19jd1h0",
17
+ "layer": "x9ynric xjm74w1 xxovm9e xw6l6zx x1j61x8r x1yc453h x7ssn7h xzugeeo x6mezaz x1i21sxh xp3md9m x19pm5ym xeaf4i8 x1lldw8n x1h4wwuj xxydokm x1qkaldv x1c9qq8g xdj266r x1lziwak xexx8yu x18d9i69 x1c1uobl xyri2b xc342km xng3xce x1rea2x4 xjbqb8w xrhngw9 xjsfl84 x1047aw6 xax9j7h xdt8ak2 x1rs4lu4 x1vii845 xojybgt x1qfll2g xyvxpqs x1f17rg1 x1ex41ac xypflj0 xihxjaz x9f619 xc0b1yq x3v4n1 x144kxal x119uzjn xrzjruh xl1vlw0 x2g3n7u xaqowwx x9uej1z x10got5w x128ha8g xskzprw",
18
+ "layerInner": "x1k57tk5 x1vidyx5 x1t137rt x1jhp3zv xx47ajj x1wfwxd8 x1vwwbsn x1n2onr6 x1prclbq xiki222 x11m9jtl x1i5ehqx",
19
+ "listbox": "x9f619 x2lwn1j x1uh1i8a x1odjw0f x1a2a7pz xu0wf1k x1hc1fzr x19991ni xuedmi6 x7jh41u xuh6ohu xwji4o3 x15tucas x1j4r261 x2hg6jq",
20
+ "option": "x9f619 x78zum5 x6s0dn4 x1qughib x1txdalj xh8yej3 xlsj2fj xh6dtrn x9ynric xcr08ib x1tgivj0 xjbqb8w xc342km xng3xce x1ypdohk x16khyan x1yc453h x1t137rt x1vofgu7",
21
+ "optionMain": "x78zum5 x6s0dn4 x1txdalj x98rzlu xeuugli",
22
+ "optionRow": "x1k57tk5 x11j6mr8 x1t137rt xciu248 x1uy843r x1wfwxd8 x1jumodi x78zum5 x6s0dn4 x1txdalj xw1s368 x1n2onr6 x9f619 x1yc453h xt970qd xnjsko4 x2u8bby xeuugli",
23
+ "optionLabelOuter": "x78zum5 xdt5ytf x98rzlu xeuugli x1yc453h",
24
+ "optionLabel": "x5tbw38 xjm74w1 xw6l6zx xb3r6kr xlyipyv xuxw1ft",
25
+ "optionEnd": "x3nfvp2 x6s0dn4 xl56j7k x2lah0s xgomdpo xjl7jj",
26
+ "check": "x3nfvp2 x6s0dn4 xl56j7k x2lah0s xqwr325 xomy6nw x14eyxzr x1qzu985",
27
+ "selected": "x1e4wzip",
28
+ "highlighted": "x1lmrjuc",
29
+ "keyboard": "xak0ai5 x9ssot5 x19bwoy8 x1c097ug",
30
+ "disabled": "xbyyjgo xt0e3qv"
31
+ };
32
+
33
+ /** The layer's inline style: `{anchor}` is the trigger's anchor name. */
34
+ export const LAYER_STYLE = "--x---_layer-keyboard-max-block-size: 100vh; --x---_layer-keyboard-overflow: visible; --x---_layer-keyboard-inset-block-end: initial; position-anchor: {anchor}; position-area: self-block-end span-self-inline-end; position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline, --astryx-layer-slide-below-start-same, --astryx-layer-slide-below-start-opposite;";
@@ -108,7 +108,7 @@ export async function toClipboard(text, btn, label) {
108
108
  };
109
109
  try {
110
110
  await navigator.clipboard.writeText(text);
111
- said("copied · " + Math.round(text.length / 1000) + "k");
111
+ said(text.length < 1000 ? "copied" : "copied · " + Math.round(text.length / 1000) + "k");
112
112
  return true;
113
113
  } catch {
114
114
  /* fall through */
@@ -20,18 +20,31 @@ const CHORE_WORDS = ["setup", "submit", "data", "blocked"];
20
20
 
21
21
  const lower = (s) => String(s ?? "").toLowerCase();
22
22
 
23
- /** How old a run report can be and still be this morning's. */
24
- const REPORT_HOURS = 20;
23
+ /** An @login in prose, not in an email address or a path. As GitHub links them. */
24
+ const MENTION = /(?<![\w@/.-])@([a-z\d](?:[a-z\d-]{0,38}))/gi;
25
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);
26
+ /** Who wrote the newest word on an item: its last comment, or the issue itself. */
27
+ const writerOf = (item) => lower(item.lastComment ? item.lastComment.author : item.author);
28
+
29
+ /**
30
+ * The people the newest word on an item asks for something, by login: whoever it @mentions,
31
+ * from the last comment, or from the body when nobody has replied. A mention is how a staff
32
+ * member pulls somebody in ("@ben this costs money, so it needs your OK too"), and it used to
33
+ * reach their GitHub notifications and nowhere on Home.
34
+ *
35
+ * Never the writer, and never the item's own author: staff mention the person whose request
36
+ * they are answering on every reply, and that is an answer to a request, not a new ask.
37
+ */
38
+ export function askedIn(item, people) {
39
+ const last = item.lastComment;
40
+ const said = last
41
+ ? (last.mentions ?? [...String(last.body ?? "").matchAll(MENTION)].map((m) => m[1]))
42
+ : [...String(item.body ?? "").matchAll(MENTION)].map((m) => m[1]);
43
+ const skip = new Set([writerOf(item), lower(item.author)]);
44
+ return [...new Set(said.map(lower))].filter((l) => people.has(l) && !skip.has(l));
33
45
  }
34
46
 
47
+
35
48
  /**
36
49
  * @param items the inbox list: open and recently closed issues and pull requests
37
50
  * @param staff S.data.staff: handle, name, brain, statusIssue, mention
@@ -76,16 +89,10 @@ export function sortHome(items, staff, humans, live = [], now = new Date()) {
76
89
  continue;
77
90
  }
78
91
 
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) });
92
+ /* The report: the body of a staff member's status issue, which every run rewrites. Not its
93
+ comments, which used to be the reports and grew into a thread nobody wanted to scroll. */
94
+ if (owner && item.number === owner.statusIssue && String(item.body ?? "").trim()) {
95
+ out.reports.push({ staff: owner, item, at: item.updatedAt, body: String(item.body).trim() });
89
96
  }
90
97
 
91
98
  const place = placeOf(item, owner, people, markers);
@@ -97,6 +104,12 @@ export function sortHome(items, staff, humans, live = [], now = new Date()) {
97
104
  ? "answered"
98
105
  : "waiting";
99
106
  }
107
+ if (place.place === "needs") {
108
+ /* On nobody in particular, such as a pull request nobody was assigned: the first person's,
109
+ as the staff are told "something that fits nobody's area goes to" them. */
110
+ entry.for = whoFor(item, humans);
111
+ if (!entry.for.length && humans[0]?.github) entry.for = [humans[0].github];
112
+ }
100
113
  out[place.place].push(entry);
101
114
  }
102
115
 
@@ -117,9 +130,11 @@ export function placeOf(item, owner, people, markers) {
117
130
  }
118
131
 
119
132
  const labels = (item.labels ?? []).map(lower);
133
+ const asked = askedIn(item, people);
120
134
  const onPerson =
121
135
  (item.assignees ?? []).some((a) => people.has(lower(a))) ||
122
- labels.some((l) => markers.has(l));
136
+ labels.some((l) => markers.has(l)) ||
137
+ asked.length > 0;
123
138
  const byPerson = people.has(lower(item.author));
124
139
  /* You had the last word on an ask: approved it, answered it, said go with the default. It is
125
140
  waiting on them now, so it is one of your requests until they reply or close it. If they
@@ -130,11 +145,14 @@ export function placeOf(item, owner, people, markers) {
130
145
  if (!onPerson || byPerson) {
131
146
  return { place: "elsewhere", why: item.role === "product" ? "contributor" : "other" };
132
147
  }
148
+ if (asked.length) return { place: "needs", kind: kindOf(labels) };
133
149
  return youAnswered ? { place: "requests" } : { place: "needs", kind: kindOf(labels) };
134
150
  }
135
151
  if (item.number === owner.statusIssue || labels.includes("keep-open")) {
136
152
  return { place: "staff", why: "status" };
137
153
  }
154
+ // Somebody was asked by the newest word on it, whoever started it: it is on them now.
155
+ if (asked.length) return { place: "needs", kind: kindOf(labels) };
138
156
  if (byPerson) return { place: "requests" };
139
157
  if (onPerson) return youAnswered ? { place: "requests" } : { place: "needs", kind: kindOf(labels) };
140
158
  return {
@@ -143,6 +161,34 @@ export function placeOf(item, owner, people, markers) {
143
161
  };
144
162
  }
145
163
 
164
+ /**
165
+ * The people an ask is on, by login: whoever it is assigned to, whoever's label it carries, and
166
+ * whoever its newest word @mentions. Not whoever wrote that word, who has passed it on. Empty
167
+ * means nobody in particular, such as a pull request nobody was asked to look at.
168
+ */
169
+ export function whoFor(item, humans) {
170
+ const labels = new Set((item.labels ?? []).map(lower));
171
+ const assigned = new Set((item.assignees ?? []).map(lower));
172
+ const asked = new Set(askedIn(item, new Set(humans.map((h) => lower(h.github)).filter(Boolean))));
173
+ // Whoever had the last word has passed it on: an ask they answered is not on them any more.
174
+ const writer = writerOf(item);
175
+ return humans
176
+ .filter(
177
+ (h) =>
178
+ (h.github && assigned.has(lower(h.github))) ||
179
+ (h.marker && labels.has(lower(h.marker))) ||
180
+ (h.github && asked.has(lower(h.github))),
181
+ )
182
+ .filter((h) => !item.lastComment || lower(h.github) !== writer)
183
+ .map((h) => h.github);
184
+ }
185
+
186
+ /** Whether an ask is for this login: it is on them, or on nobody in particular. */
187
+ export function isFor(entry, login) {
188
+ if (!login || !entry.for?.length) return true;
189
+ return entry.for.some((g) => lower(g) === lower(login));
190
+ }
191
+
146
192
  function kindOf(labels) {
147
193
  const found = KINDS.find((k) => labels.includes(k));
148
194
  if (found) return found;
@@ -13,6 +13,8 @@
13
13
  */
14
14
 
15
15
  const PATHS = {
16
+ "plug":
17
+ "<path d=\"M12 22v-5\" /> <path d=\"M9 8V2\" /> <path d=\"M15 8V2\" /> <path d=\"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z\" />",
16
18
  "search":
17
19
  "<circle cx=\"11\" cy=\"11\" r=\"8\" /> <path d=\"m21 21-4.3-4.3\" />",
18
20
  "lightbulb":
@@ -43,6 +45,8 @@ const PATHS = {
43
45
  "<path d=\"m6 9 6 6 6-6\" />",
44
46
  "close":
45
47
  "<path d=\"M18 6 6 18\" /> <path d=\"m6 6 12 12\" />",
48
+ "trash":
49
+ "<path d=\"M3 6h18\" /> <path d=\"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6\" /> <path d=\"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2\" /> <line x1=\"10\" x2=\"10\" y1=\"11\" y2=\"17\" /> <line x1=\"14\" x2=\"14\" y1=\"11\" y2=\"17\" />",
46
50
  "closed":
47
51
  "<circle cx=\"12\" cy=\"12\" r=\"10\" /> <path d=\"m15 9-6 6\" /> <path d=\"m9 9 6 6\" />",
48
52
  "commit":
@@ -81,6 +85,8 @@ const PATHS = {
81
85
  "<path d=\"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48\" />",
82
86
  "person":
83
87
  "<circle cx=\"12\" cy=\"8\" r=\"5\" /> <path d=\"M20 21a8 8 0 0 0-16 0\" />",
88
+ "clock":
89
+ "<circle cx=\"12\" cy=\"12\" r=\"10\" /> <path d=\"M12 6v6l4 2\" />",
84
90
  "play":
85
91
  "<path d=\"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z\" />",
86
92
  // The pair for the lightbox's zoom controls. `dash` above is the other half.
@@ -64,8 +64,13 @@ function htmlToMarkdown(html, breakAs, stripUnknown) {
64
64
  .replace(/<(strong|b)[^>]*>([\s\S]*?)<\/\1>/gi, (_m, _t, x) => "**" + x.trim() + "**")
65
65
  .replace(/<(em|i)[^>]*>([\s\S]*?)<\/\1>/gi, (_m, _t, x) => "*" + x.trim() + "*")
66
66
  .replace(/<code[^>]*>([\s\S]*?)<\/code>/gi, (_m, x) => "`" + x.trim() + "`")
67
- .replace(/<img[^>]*alt=["']([^"']*)["'][^>]*>/gi, "$1")
68
- .replace(/<img[^>]*>/gi, "")
67
+ /* A screenshot dragged into an issue on GitHub is written as an <img> tag, not as markdown,
68
+ and dropping it to its alt text left the word "Image" where the picture was. */
69
+ .replace(/<img[^>]*>/gi, (tag) => {
70
+ const src = /\ssrc=["'](https?:\/\/[^"'\s]+)["']/i.exec(tag)?.[1];
71
+ const alt = (/\salt=["']([^"']*)["']/i.exec(tag)?.[1] ?? "").replace(/[[\]]/g, "");
72
+ return src ? "![" + alt + "](" + src + ")" : alt;
73
+ })
69
74
  // Only http(s). A `javascript:` href would be escaped downstream anyway, but a link that
70
75
  // cannot go anywhere useful is better dropped than rendered.
71
76
  .replace(
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import { el, esc } from "./dom.js";
15
+ import { canRun } from "./readiness.js";
15
16
  import { humansOf, S } from "./state.js";
16
17
 
17
18
  /**
@@ -37,7 +38,7 @@ export function mentionable() {
37
38
  out.push({
38
39
  text: at,
39
40
  label: s.name ?? s.handle,
40
- note: "wakes them, usually within a minute",
41
+ note: canRun(s.handle) ? "wakes them, usually within a minute" : "not set up yet, so nothing wakes them",
41
42
  kind: "staff",
42
43
  terms: [at.replace(/^@/, ""), s.handle, s.name ?? ""],
43
44
  });
@@ -28,6 +28,42 @@ export function notReady() {
28
28
  return (S.data?.staff ?? []).filter((s) => (S.readiness?.[s.handle] ?? []).length);
29
29
  }
30
30
 
31
+ /**
32
+ * Whether a run started now could work: nothing left but the first run itself. Unknown counts
33
+ * as able, so a slow answer from GitHub never greys out a working org's buttons.
34
+ */
35
+ export function canRun(handle) {
36
+ return !(S.readiness?.[handle] ?? []).some((x) => x !== "run once");
37
+ }
38
+
39
+ /** Whether they have never finished a run, as far as is known. */
40
+ export function neverRan(handle) {
41
+ return (S.readiness?.[handle] ?? []).includes("run once");
42
+ }
43
+
44
+ /** Forget every answer, so the next screen asks again: after a refresh, or a step finishing. */
45
+ export function forgetReadiness() {
46
+ S.readiness = null;
47
+ }
48
+
49
+ /** The roster command for each step: the only way to do them from a hosted portal. */
50
+ export const ROSTER = "npx @nanocollective/roster@latest";
51
+ export const ORG_STEPS = {
52
+ hire: ["Hire someone", "hire cto --apply"],
53
+ business: ["Say what the business is, in org/business.md", "brief discover"],
54
+ priorities: ["Say what matters this month, in org/priorities.md", "brief priorities"],
55
+ };
56
+ const STEP_COMMANDS = {
57
+ "write the charter": (h) => `brief charter ${h}`,
58
+ "create the GitHub App": (h) => `app ${h} --apply`,
59
+ "install the GitHub App": (h) => `app ${h} --apply`,
60
+ "add the agent credential": () => "credential --apply",
61
+ "run once": (h) => `run ${h} --apply`,
62
+ };
63
+ export function stepCommand(what, handle) {
64
+ return STEP_COMMANDS[what]?.(handle) ?? "";
65
+ }
66
+
31
67
  /** "install the GitHub App, add the agent credential and run once" */
32
68
  export function sentence(left) {
33
69
  if (left.length < 2) return left.join("");
@@ -0,0 +1,216 @@
1
+ /* What a #175 is, without leaving the page.
2
+ *
3
+ * Half of a status report is issue numbers, and the only way to find out what one was used to
4
+ * be a click through to GitHub, which is a new tab and the end of whatever you were reading.
5
+ * Hovering one now shows a card with its title, state and opening lines, the way GitHub does,
6
+ * and clicking it opens the thread in a side sheet over the page you were on.
7
+ *
8
+ * Only for the org's own repos: the server reads nothing else, so a chip pointing anywhere
9
+ * else stays a plain link. ⌘-click and middle-click still go to GitHub, as a link should.
10
+ */
11
+
12
+ import { getRepos, getThread } from "./api.js";
13
+ import { ago, el, esc } from "./dom.js";
14
+ import { iconHTML } from "./icons.js";
15
+ import { openThread } from "./views/home.js";
16
+ import { tone } from "./views/inbox.js";
17
+
18
+ const REF_HREF = /^https:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/(?:issues|pull)\/(\d+)/;
19
+ const SHOW_AFTER = 350;
20
+ const HIDE_AFTER = 200;
21
+ // Long enough to hover the same few numbers on a report without asking again; short enough
22
+ // that a card is not an hour out of date.
23
+ const FRESH_FOR = 5 * 60_000;
24
+
25
+ let known = null;
26
+ const cache = new Map();
27
+ let card = null;
28
+ let showing = null;
29
+ let showTimer = 0;
30
+ let hideTimer = 0;
31
+
32
+ export function installRefs() {
33
+ /* Read once, off disk. A failure leaves every chip a plain link, which is what they were. */
34
+ getRepos()
35
+ .then((r) => {
36
+ known = new Set((r?.repos ?? []).map((x) => x.owner + "/" + x.name));
37
+ })
38
+ .catch(() => {});
39
+
40
+ document.addEventListener?.("click", (e) => {
41
+ const ref = refOf(e.target);
42
+ if (!ref || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
43
+ e.preventDefault();
44
+ hide();
45
+ openThread(ref);
46
+ });
47
+
48
+ document.addEventListener?.("pointerover", (e) => {
49
+ if (e.pointerType === "touch") return;
50
+ if (card?.contains(e.target)) {
51
+ clearTimeout(hideTimer);
52
+ return;
53
+ }
54
+ const a = e.target?.closest?.("a.ref");
55
+ const ref = refOf(e.target);
56
+ if (!ref) return;
57
+ clearTimeout(hideTimer);
58
+ if (showing === a) return;
59
+ // The card says everything the native tooltip did, and both at once is clutter.
60
+ a.removeAttribute("title");
61
+ clearTimeout(showTimer);
62
+ showTimer = setTimeout(() => show(a, ref), SHOW_AFTER);
63
+ });
64
+
65
+ document.addEventListener?.("pointerout", (e) => {
66
+ const from = e.target?.closest?.("a.ref, .refcard");
67
+ if (!from || from.contains(e.relatedTarget)) return;
68
+ clearTimeout(showTimer);
69
+ hideTimer = setTimeout(hide, HIDE_AFTER);
70
+ });
71
+
72
+ addEventListener?.("keydown", (e) => e.key === "Escape" && hide());
73
+ addEventListener?.("scroll", hide, true);
74
+ addEventListener?.("hashchange", hide);
75
+ }
76
+
77
+ /** The repo and number a chip points at, if it is one of the org's own. */
78
+ function refOf(target) {
79
+ const a = target?.closest?.("a.ref");
80
+ if (!a || !known) return null;
81
+ const m = REF_HREF.exec(a.getAttribute("href") ?? "");
82
+ if (!m || !known.has(m[1])) return null;
83
+ return { repo: m[1], number: Number(m[2]), kind: a.classList.contains("pr") ? "pr" : undefined };
84
+ }
85
+
86
+ function peek(ref) {
87
+ const key = ref.repo + "#" + ref.number;
88
+ const hit = cache.get(key);
89
+ if (hit && Date.now() - hit.at < FRESH_FOR) return hit.p;
90
+ const p = getThread(ref.repo, ref.number, ref.kind ?? "").then((t) => {
91
+ if (!t || t.error) throw new Error(t?.error ?? "could not read it");
92
+ return t;
93
+ });
94
+ // A failure is not kept: the next hover asks again.
95
+ p.catch(() => cache.delete(key));
96
+ cache.set(key, { at: Date.now(), p });
97
+ return p;
98
+ }
99
+
100
+ function show(a, ref) {
101
+ if (!a.isConnected) return;
102
+ showing = a;
103
+ ensureCard();
104
+ card.replaceChildren(
105
+ el("div", { className: "rcmeta", textContent: ref.repo + " #" + ref.number }),
106
+ el("div", { className: "sk sk-line" }),
107
+ el("div", { className: "sk sk-line" }),
108
+ );
109
+ open(a);
110
+ peek(ref)
111
+ .then((t) => {
112
+ if (showing === a) {
113
+ fill(t);
114
+ place(a);
115
+ }
116
+ })
117
+ .catch((e) => {
118
+ if (showing !== a) return;
119
+ card.replaceChildren(
120
+ el("div", { className: "rcmeta", textContent: ref.repo + " #" + ref.number }),
121
+ el("p", {
122
+ className: "rcbody",
123
+ // A bare #213 is read as this repo's, and the writer often meant another one.
124
+ textContent: /could not resolve|not found/i.test(e.message)
125
+ ? "There is no #" + ref.number + " in " + ref.repo + "."
126
+ : "Couldn't read it: " + e.message,
127
+ }),
128
+ );
129
+ });
130
+ }
131
+
132
+ function fill(t) {
133
+ const merged = t.state === "MERGED";
134
+ const shut = t.state !== "OPEN";
135
+ const glyph = merged ? "merged" : t.draft ? "draft" : shut ? "issue-closed" : "issue-open";
136
+ const word = merged ? "Merged" : shut ? "Closed" : t.draft ? "Draft" : "Open";
137
+ const excerpt = plain(t.body);
138
+ const comments = t.commentCount ?? t.comments?.length ?? 0;
139
+
140
+ card.innerHTML =
141
+ '<div class="rcmeta">' +
142
+ '<span class="rcstate ' + (merged ? "merged" : shut ? "closed" : "open") + '">' +
143
+ iconHTML(glyph) + word + "</span>" +
144
+ "<span>" + esc(t.repo) + " " + (t.kind === "pr" ? "PR " : "") + "#" + t.number + "</span>" +
145
+ "</div>" +
146
+ '<div class="rctitle">' + esc(t.title) + "</div>" +
147
+ (excerpt ? '<p class="rcbody">' + esc(excerpt) + "</p>" : "") +
148
+ (t.labels?.length
149
+ ? '<div class="rclabels">' +
150
+ t.labels.map((l) => '<span class="chip ' + tone(l) + '">' + esc(l) + "</span>").join("") +
151
+ "</div>"
152
+ : "") +
153
+ '<div class="rcfoot">' +
154
+ esc(t.author) + " · updated " + ago(t.updatedAt) +
155
+ (comments ? " · " + comments + (comments === 1 ? " comment" : " comments") : "") +
156
+ "</div>";
157
+ }
158
+
159
+ /** The opening of a body as a sentence: no headings, tables, images or link syntax. */
160
+ function plain(body) {
161
+ const text = String(body ?? "")
162
+ .replace(/<!--[\s\S]*?-->/g, "")
163
+ .replace(/```[\s\S]*?```/g, " ")
164
+ .replace(/!\[[^\]]*\]\([^)]*\)/g, "")
165
+ .replace(/\[([^\]]*)\]\([^)]*\)/g, "$1")
166
+ .split("\n")
167
+ .map((l) => l.replace(/^\s*(#{1,6}\s+|>\s?|[-*+]\s+(\[[ x]\]\s+)?|\d+\.\s+)/i, "").trim())
168
+ .filter((l) => l && !/^\|/.test(l) && !/^[-|:\s]+$/.test(l))
169
+ .join(" ")
170
+ .replace(/[*_`]/g, "")
171
+ .replace(/\s+/g, " ")
172
+ .trim();
173
+ return text.length > 220 ? text.slice(0, 219).trimEnd() + "…" : text;
174
+ }
175
+
176
+ function ensureCard() {
177
+ if (card) return;
178
+ card = el("div", { className: "refcard", role: "tooltip" });
179
+ /* A popover goes in the top layer, so the card shows over an open side sheet too. A plain
180
+ fixed div would sit underneath a modal <dialog> however high its z-index. */
181
+ if (typeof card.showPopover === "function") card.setAttribute("popover", "manual");
182
+ document.body.append(card);
183
+ }
184
+
185
+ function open(a) {
186
+ // The top layer is ordered by when things were shown. Reopening puts the card above a
187
+ // sheet that opened after it last showed.
188
+ if (card.matches?.(":popover-open")) card.hidePopover();
189
+ if (typeof card.showPopover === "function") card.showPopover();
190
+ else card.hidden = false;
191
+ card.classList.add("on");
192
+ place(a);
193
+ }
194
+
195
+ /** Under the chip, or above it when there is no room below; never off the side. */
196
+ function place(a) {
197
+ const r = a.getBoundingClientRect();
198
+ const w = card.offsetWidth;
199
+ const h = card.offsetHeight;
200
+ const gap = 8;
201
+ const left = Math.max(12, Math.min(r.left, innerWidth - w - 12));
202
+ const below = r.bottom + gap + h <= innerHeight - 12;
203
+ const top = below ? r.bottom + gap : Math.max(12, r.top - gap - h);
204
+ card.style.left = left + "px";
205
+ card.style.top = top + "px";
206
+ }
207
+
208
+ function hide() {
209
+ clearTimeout(showTimer);
210
+ clearTimeout(hideTimer);
211
+ showing = null;
212
+ if (!card) return;
213
+ card.classList.remove("on");
214
+ if (card.matches?.(":popover-open")) card.hidePopover();
215
+ else if (typeof card.showPopover !== "function") card.hidden = true;
216
+ }
@@ -10,7 +10,8 @@
10
10
  import { getInbox, getOrg, getSync } from "./api.js";
11
11
  import { $, ago, el, esc } from "./dom.js";
12
12
  import { render } from "./router.js";
13
- import { sortHome } from "./homesort.js";
13
+ import { isFor, sortHome } from "./homesort.js";
14
+ import { checkAll, forgetReadiness } from "./readiness.js";
14
15
  import { humansOf, openCount, S, unreadCount } from "./state.js";
15
16
 
16
17
  /**
@@ -75,7 +76,9 @@ export function stampCounts() {
75
76
  /** What Home's "Needs you" holds, for the sidebar. */
76
77
  function needsCount() {
77
78
  if (!S.inbox || !S.data) return 0;
78
- return sortHome(S.inbox.items ?? [], S.data.staff, humansOf(), S.live?.staff ?? []).needs.length;
79
+ return sortHome(S.inbox.items ?? [], S.data.staff, humansOf(), S.live?.staff ?? []).needs.filter(
80
+ (e) => isFor(e, S.me),
81
+ ).length;
79
82
  }
80
83
 
81
84
  export function countInBackground() {
@@ -96,6 +99,9 @@ export async function refreshAll(soft) {
96
99
  S.inbox = null; // the inbox re-fetches itself on next paint
97
100
  inflight = null;
98
101
  S.loadedAt = new Date();
102
+ // A step may have been finished since: a first run, a credential added on another machine.
103
+ forgetReadiness();
104
+ checkAll(() => !soft && render());
99
105
  if (!soft) render();
100
106
  stampLoaded();
101
107
  // The badges are now claiming a count from before the sync. Re-ask, and say so meanwhile.