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

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 (145) hide show
  1. package/README.md +5 -0
  2. package/dist/cli.js +4067 -1950
  3. package/dist/worker/assets/assets/css/base.css +312 -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 +101 -0
  9. package/dist/worker/assets/assets/css/inbox.css +199 -0
  10. package/dist/worker/assets/assets/css/layout.css +175 -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 +161 -0
  16. package/dist/worker/assets/assets/js/app.js +465 -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 +585 -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 +4430 -0
  65. package/docs/README.md +2 -2
  66. package/docs/architecture.md +1 -1
  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 +9 -3
  75. package/docs/concepts.md +33 -20
  76. package/docs/cost.md +3 -3
  77. package/docs/developing.md +27 -9
  78. package/docs/doctor-codes.md +3 -1
  79. package/docs/export.md +2 -0
  80. package/docs/getting-started.md +44 -27
  81. package/docs/hosting.md +89 -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/org-yaml.md +3 -0
  89. package/docs/portal.md +143 -45
  90. package/docs/prompts.md +6 -0
  91. package/docs/security.md +57 -11
  92. package/docs/session-workflow.md +14 -0
  93. package/docs/staff-yaml.md +17 -1
  94. package/docs/upgrading.md +3 -3
  95. package/docs/writing-a-charter.md +19 -6
  96. package/package.json +4 -3
  97. package/templates/brain/.github/workflows/%%STAFF%%-daily.yaml +20 -1
  98. package/templates/brain/.github/workflows/%%STAFF%%-mention.yaml +53 -13
  99. package/templates/brain/staff.yaml +4 -1
  100. package/templates/briefs/amend.md +4 -3
  101. package/templates/briefs/priorities.md +46 -0
  102. package/templates/ops/.github/workflows/session.yaml +137 -3
  103. package/templates/ops/compose.mjs +35 -8
  104. package/templates/ops/org/operating.md +29 -10
  105. package/templates/ops/prompts/daily.md +23 -4
  106. package/templates/ops/prompts/mention.md +19 -0
  107. package/templates/ops/run-record.mjs +5 -3
  108. package/templates/portal/css/base.css +34 -0
  109. package/templates/portal/css/health.css +14 -1
  110. package/templates/portal/css/home.css +101 -0
  111. package/templates/portal/css/inbox.css +21 -4
  112. package/templates/portal/css/layout.css +29 -3
  113. package/templates/portal/css/markdown.css +19 -0
  114. package/templates/portal/css/search.css +48 -0
  115. package/templates/portal/css/setup.css +79 -4
  116. package/templates/portal/index.html +15 -9
  117. package/templates/portal/js/api.js +30 -4
  118. package/templates/portal/js/app.js +90 -7
  119. package/templates/portal/js/dialog.js +36 -0
  120. package/templates/portal/js/homesort.js +174 -0
  121. package/templates/portal/js/icons.js +41 -0
  122. package/templates/portal/js/inflight.js +18 -0
  123. package/templates/portal/js/md.js +5 -2
  124. package/templates/portal/js/mdedit.js +84 -0
  125. package/templates/portal/js/readiness.js +70 -0
  126. package/templates/portal/js/refresh.js +10 -2
  127. package/templates/portal/js/search.js +366 -0
  128. package/templates/portal/js/state.js +11 -5
  129. package/templates/portal/js/views/app.js +1 -2
  130. package/templates/portal/js/views/brain.js +1 -1
  131. package/templates/portal/js/views/checklist.js +19 -4
  132. package/templates/portal/js/views/credential.js +42 -51
  133. package/templates/portal/js/views/health.js +11 -6
  134. package/templates/portal/js/views/hire.js +593 -0
  135. package/templates/portal/js/views/home.js +585 -0
  136. package/templates/portal/js/views/inbox.js +237 -68
  137. package/templates/portal/js/views/org.js +31 -111
  138. package/templates/portal/js/views/orgedit.js +240 -0
  139. package/templates/portal/js/views/paste.js +111 -66
  140. package/templates/portal/js/views/prompt.js +94 -40
  141. package/templates/portal/js/views/repos.js +10 -10
  142. package/templates/portal/js/views/runs.js +21 -4
  143. package/templates/portal/js/views/setup.js +130 -163
  144. package/templates/portal/js/views/staff.js +181 -301
  145. package/templates/portal/js/views/todo.js +62 -0
@@ -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
+ }
@@ -0,0 +1,264 @@
1
+ /* Typing `@` should offer the org.
2
+ *
3
+ * A mention is not decoration here: a staff member's workflow gates on their `@handle`, so a
4
+ * reply that misspells it is a reply nobody is woken by, and a reply that spells a bot's login
5
+ * where a handle belongs looks right and does nothing. Both failures are silent, which is the
6
+ * kind this portal exists to stop. The roster is small and it is already on the page, so it is
7
+ * offered rather than remembered.
8
+ *
9
+ * Everyone is here, and each row says what mentioning it actually does: a staff handle wakes
10
+ * them, a human gets a notification, an App gets neither and is listed so you can recognise the
11
+ * name rather than address it.
12
+ */
13
+
14
+ import { el, esc } from "./dom.js";
15
+ import { humansOf, S } from "./state.js";
16
+
17
+ /**
18
+ * Everyone a mention actually reaches, in the order they are worth offering.
19
+ *
20
+ * Staff first: waking one is the reason to type `@` in this app at all. Then the humans, who
21
+ * get a notification.
22
+ *
23
+ * **The Apps are deliberately not here.** `@some-org-cto` is a login, not an inbox: GitHub
24
+ * delivers nothing for mentioning a GitHub App, and an agent wakes on its own handle and not
25
+ * on the name of the identity it posts as. A list you pick from should contain only things
26
+ * that do something; an entry that says "notifies nobody" is a trap with a label on it, and it
27
+ * pushed the entries that work off the bottom of the box.
28
+ *
29
+ * Nothing here knows what any of these people are called. Every row comes off `org.yaml` and
30
+ * the manifests, so an org with a head of ops and a designer gets a head of ops and a designer.
31
+ */
32
+ export function mentionable() {
33
+ const out = [];
34
+
35
+ for (const s of S.data?.staff ?? []) {
36
+ const at = String(s.mention ?? "@" + s.handle);
37
+ out.push({
38
+ text: at,
39
+ label: s.name ?? s.handle,
40
+ note: "wakes them, usually within a minute",
41
+ kind: "staff",
42
+ terms: [at.replace(/^@/, ""), s.handle, s.name ?? ""],
43
+ });
44
+ }
45
+
46
+ for (const h of humansOf()) {
47
+ if (!h.github) continue;
48
+ out.push({
49
+ text: "@" + h.github,
50
+ label: h.name ?? h.github,
51
+ note: h.role ? h.role + " · notifies them" : "notifies them",
52
+ kind: "human",
53
+ terms: [h.github, h.name ?? ""],
54
+ });
55
+ }
56
+
57
+ return out;
58
+ }
59
+
60
+ /** What is being typed after an `@`, or null. Only at a word boundary: an email is not a mention. */
61
+ export function queryAt(text, caret) {
62
+ const before = String(text ?? "").slice(0, caret);
63
+ const m = /(?:^|[\s(<[{>,;:"'`])@([A-Za-z0-9][\w.-]*)?$/.exec(before);
64
+ if (!m) return null;
65
+ const query = m[1] ?? "";
66
+ return { query, start: caret - query.length - 1 };
67
+ }
68
+
69
+ /** The matches for a query, best first. Prefix beats substring; order beats neither. */
70
+ export function matches(query, all = mentionable()) {
71
+ const q = query.toLowerCase();
72
+ if (!q) return all;
73
+ const rank = (c) => {
74
+ const terms = c.terms.map((t) => String(t).toLowerCase()).filter(Boolean);
75
+ if (terms.some((t) => t.startsWith(q))) return 0;
76
+ if (terms.some((t) => t.includes(q))) return 1;
77
+ return 2;
78
+ };
79
+ return all
80
+ .map((c, i) => ({ c, i, r: rank(c) }))
81
+ .filter((x) => x.r < 2)
82
+ .sort((a, b) => a.r - b.r || a.i - b.i)
83
+ .map((x) => x.c);
84
+ }
85
+
86
+ /**
87
+ * Wire a textarea up to the list.
88
+ *
89
+ * Attaching adds listeners and nothing else: the popup is built the first time somebody types
90
+ * an `@`, so a screen that renders fifty boxes pays for none of them, and a DOM without
91
+ * `getComputedStyle` (the test shim) never reaches the part that needs one.
92
+ */
93
+ export function attachMentions(ta) {
94
+ if (!ta?.addEventListener) return;
95
+
96
+ let pop = null;
97
+ let items = [];
98
+ let at = 0;
99
+ let anchor = null;
100
+
101
+ const close = () => {
102
+ if (pop) pop.hidden = true;
103
+ anchor = null;
104
+ };
105
+
106
+ const open = (found, q) => {
107
+ items = found;
108
+ at = 0;
109
+ anchor = q;
110
+ if (!pop) {
111
+ pop = el("div", { className: "mentions" });
112
+ pop.setAttribute("role", "listbox");
113
+ // mousedown, not click: the textarea must not lose the caret before the pick lands.
114
+ pop.addEventListener("mousedown", (e) => {
115
+ const row = e.target.closest?.("[data-at]");
116
+ if (!row) return;
117
+ e.preventDefault();
118
+ pick(items[Number(row.dataset.at)]);
119
+ });
120
+ host(ta).append(pop);
121
+ }
122
+ pop.hidden = false;
123
+ paint();
124
+ place();
125
+ };
126
+
127
+ const paint = () => {
128
+ pop.replaceChildren(
129
+ ...items.map((c, i) => {
130
+ const row = el("button", { className: "mrow " + c.kind, type: "button" });
131
+ row.dataset.at = String(i);
132
+ row.setAttribute("aria-selected", String(i === at));
133
+ row.innerHTML =
134
+ '<span class="mat">' + esc(c.text) + "</span>" +
135
+ '<span class="mname">' + esc(c.label) + "</span>" +
136
+ '<span class="mnote">' + esc(c.note) + "</span>";
137
+ return row;
138
+ }),
139
+ );
140
+ };
141
+
142
+ const move = (by) => {
143
+ at = (at + by + items.length) % items.length;
144
+ paint();
145
+ pop.children[at]?.scrollIntoView?.({ block: "nearest" });
146
+ };
147
+
148
+ const pick = (choice) => {
149
+ if (!choice || !anchor) return;
150
+ const caret = ta.selectionStart ?? ta.value.length;
151
+ const after = ta.value.slice(caret);
152
+ // A space, unless there already is one: nobody wants to type it and nobody wants two.
153
+ const tail = /^\s/.test(after) ? "" : " ";
154
+ ta.value = ta.value.slice(0, anchor.start) + choice.text + tail + after;
155
+ const to = anchor.start + choice.text.length + tail.length;
156
+ ta.setSelectionRange?.(to, to);
157
+ close();
158
+ ta.focus?.();
159
+ // So the box's own listeners — the draft, the grow, the "this is what wakes them" line —
160
+ // see the text that is now in it.
161
+ if (typeof Event === "function") ta.dispatchEvent(new Event("input", { bubbles: true }));
162
+ };
163
+
164
+ const look = () => {
165
+ const caret = ta.selectionStart ?? 0;
166
+ const q = queryAt(ta.value, caret);
167
+ if (!q) return close();
168
+ const found = matches(q.query);
169
+ if (!found.length) return close();
170
+ open(found, q);
171
+ };
172
+
173
+ ta.addEventListener("input", look);
174
+ ta.addEventListener("click", close);
175
+ ta.addEventListener("blur", close);
176
+ ta.addEventListener("keydown", (e) => {
177
+ if (!anchor || !pop || pop.hidden) return;
178
+ if (e.key === "ArrowDown") { e.preventDefault(); move(1); return; }
179
+ if (e.key === "ArrowUp") { e.preventDefault(); move(-1); return; }
180
+ if (e.key === "Enter" || e.key === "Tab") {
181
+ // ⌘⏎ is "send", and it means that whether or not this list is open.
182
+ if (e.metaKey || e.ctrlKey) return;
183
+ e.preventDefault();
184
+ // Nothing else on the page may see it: in a dialog, a stray Enter submits.
185
+ e.stopPropagation();
186
+ pick(items[at]);
187
+ return;
188
+ }
189
+ if (e.key === "Escape") {
190
+ // Dismiss the list, not the dialog around it.
191
+ e.preventDefault();
192
+ e.stopPropagation();
193
+ close();
194
+ }
195
+ });
196
+
197
+ /** Where the popup lives: the first positioned ancestor, so a modal keeps it on top. */
198
+ function host(node) {
199
+ const parent = node.parentElement ?? node.parentNode;
200
+ if (!parent) return node;
201
+ if (typeof getComputedStyle === "function" && getComputedStyle(parent).position === "static") {
202
+ parent.style.position = "relative";
203
+ }
204
+ return parent;
205
+ }
206
+
207
+ /**
208
+ * Under the caret, not under the box.
209
+ *
210
+ * Measured with a mirror: a div with the textarea's own metrics, holding the text up to the
211
+ * caret and a marker after it. There is no other way to ask a textarea where its caret is.
212
+ * If any of that is unavailable, it falls back to the bottom of the box, which is worse but
213
+ * never wrong.
214
+ */
215
+ function place() {
216
+ const under = ta.offsetTop + ta.offsetHeight;
217
+ let top = under;
218
+ let left = ta.offsetLeft;
219
+ let line = 18;
220
+ if (typeof getComputedStyle === "function" && ta.parentElement) {
221
+ const style = getComputedStyle(ta);
222
+ const mirror = el("div", { className: "mmirror" });
223
+ for (const prop of [
224
+ "fontFamily", "fontSize", "fontWeight", "fontStyle", "letterSpacing", "textTransform",
225
+ "lineHeight", "paddingTop", "paddingRight", "paddingBottom", "paddingLeft",
226
+ "borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth",
227
+ ]) {
228
+ mirror.style[prop] = style[prop];
229
+ }
230
+ mirror.style.width = ta.offsetWidth + "px";
231
+ mirror.style.left = ta.offsetLeft + "px";
232
+ mirror.style.top = ta.offsetTop + "px";
233
+ mirror.textContent = ta.value.slice(0, ta.selectionStart ?? 0);
234
+ const mark = el("span", { textContent: "​" });
235
+ mirror.append(mark);
236
+ ta.parentElement.append(mirror);
237
+ line = Number.parseFloat(style.lineHeight) || 18;
238
+ top = ta.offsetTop + mark.offsetTop - (ta.scrollTop ?? 0) + line;
239
+ left = ta.offsetLeft + mark.offsetLeft;
240
+ mirror.remove();
241
+ // A caret near the bottom of a long box would put the list off the card.
242
+ if (top > under) top = under;
243
+ }
244
+ pop.style.top = Math.round(top) + "px";
245
+ pop.style.left = Math.round(left) + "px";
246
+
247
+ /* Both edges, measured after placing, because until it is placed it has no size.
248
+ A `<dialog>` scrolls its own box, so anything hanging outside it is not merely ugly:
249
+ it is clipped, and the entries you were about to pick are the ones that go missing. */
250
+ const host = pop.offsetParent ?? pop.parentElement;
251
+ const wide = host?.clientWidth ?? 0;
252
+ if (wide && left + pop.offsetWidth > wide - 8) {
253
+ pop.style.left = Math.max(0, Math.round(wide - pop.offsetWidth - 8)) + "px";
254
+ }
255
+ const tall = host?.clientHeight ?? 0;
256
+ if (tall && top + pop.offsetHeight > tall - 8) {
257
+ // Above the line being typed if it fits there, which is where an editor would put it.
258
+ // Otherwise as low as it can sit and still be whole.
259
+ const above = top - line - pop.offsetHeight;
260
+ pop.style.top =
261
+ Math.round(above >= 0 ? above : Math.max(0, tall - pop.offsetHeight - 8)) + "px";
262
+ }
263
+ }
264
+ }
@@ -0,0 +1,70 @@
1
+ /* Whether each staff member can actually run yet.
2
+ *
3
+ * A hire that had its App created but not installed, and no credential, looked finished: the
4
+ * card said so and Getting started went away. This is the one answer every screen asks. */
5
+
6
+ import { getStaffProgress } from "./api.js";
7
+ import { S } from "./state.js";
8
+
9
+ /** What is left for one staff member, as short instructions. Empty when they are ready. */
10
+ export async function whatsLeft(s, fresh = false) {
11
+ const left = [];
12
+ if (s.rig?.charterStub) left.push("write the charter");
13
+ const p = await getStaffProgress(s.handle, fresh).catch(() => ({}));
14
+ if (p.installed === false) left.push(p.app ? "install the GitHub App" : "create the GitHub App");
15
+ if (p.credential === false) left.push("add the agent credential");
16
+ if (p.ran === false) left.push("run once");
17
+ S.readiness = { ...(S.readiness ?? {}), [s.handle]: left };
18
+ return left;
19
+ }
20
+
21
+ /** Every staff member's, then `then` once all have answered. */
22
+ export function checkAll(then) {
23
+ return Promise.all((S.data?.staff ?? []).map((s) => whatsLeft(s))).then(() => then?.());
24
+ }
25
+
26
+ /** The staff with anything left, from what has been checked so far. */
27
+ export function notReady() {
28
+ return (S.data?.staff ?? []).filter((s) => (S.readiness?.[s.handle] ?? []).length);
29
+ }
30
+
31
+ /** "install the GitHub App, add the agent credential and run once" */
32
+ export function sentence(left) {
33
+ if (left.length < 2) return left.join("");
34
+ return left.slice(0, -1).join(", ") + " and " + left.at(-1);
35
+ }
36
+
37
+ /** Per staff member: hire, the GitHub App, the charter, the agent credential, a first run. */
38
+ const STAFF_STEPS = 5;
39
+
40
+ /**
41
+ * Setup as a count, from the same answers as everything above: the org's three steps (create
42
+ * it, business.md, priorities.md), then five per staff member. With nobody hired, the first
43
+ * hire's five are counted as still to do.
44
+ *
45
+ * Null until every staff member's readiness has answered. A count that starts high and drops
46
+ * when GitHub replies reads as steps coming undone.
47
+ */
48
+ export function progress(
49
+ unfinished = S.data?.unfinished ?? [],
50
+ staff = S.data?.staff ?? [],
51
+ readiness = S.readiness ?? {},
52
+ ) {
53
+ const orgSteps = 3;
54
+ let done = orgSteps - unfinished.filter((id) => id !== "hire").length;
55
+ let total = orgSteps;
56
+ if (!staff.length) return { done, total: total + STAFF_STEPS };
57
+ for (const s of staff) {
58
+ const left = readiness[s.handle];
59
+ if (!left) return null;
60
+ total += STAFF_STEPS;
61
+ done += STAFF_STEPS - left.length;
62
+ }
63
+ return { done, total };
64
+ }
65
+
66
+ /** One staff member's own count, or null before their readiness is known. */
67
+ export function staffProgress(handle, readiness = S.readiness ?? {}) {
68
+ const left = readiness[handle];
69
+ return left ? { done: STAFF_STEPS - left.length, total: STAFF_STEPS } : null;
70
+ }
@@ -0,0 +1,197 @@
1
+ /* Re-reading the world, and saying so.
2
+ *
3
+ * Everything is read from disk per request, so a refresh is just re-fetching. Without it a
4
+ * run that lands while the page is open stays invisible until a reload, which is what made
5
+ * the diffs look days old.
6
+ *
7
+ * Its own module because both the shell and the inbox need it, and importing the shell from
8
+ * a view would make the module graph a ring. */
9
+
10
+ import { getInbox, getOrg, getSync } from "./api.js";
11
+ import { $, ago, el, esc } from "./dom.js";
12
+ import { render } from "./router.js";
13
+ import { sortHome } from "./homesort.js";
14
+ import { humansOf, openCount, S, unreadCount } from "./state.js";
15
+
16
+ /**
17
+ * The inbox, fetched at most once at a time.
18
+ *
19
+ * Two things want it the moment the page opens: the sidebar, which counts what is waiting on
20
+ * you, and the Inbox screen, if that is where the URL landed. Both used to ask separately, and
21
+ * the second one paid a second round trip through every repo on GitHub to learn what the first
22
+ * was already finding out.
23
+ *
24
+ * So the request is shared. `force` always goes to GitHub — it is the refresh button — and
25
+ * everything else takes whatever is in flight or already loaded.
26
+ */
27
+ let inflight = null;
28
+
29
+ export function ensureInbox(force) {
30
+ if (!force && S.inbox) return Promise.resolve(S.inbox);
31
+ if (!force && inflight) return inflight;
32
+ const asked = getInbox(force)
33
+ .then((data) => {
34
+ S.inbox = data;
35
+ if (inflight === asked) inflight = null;
36
+ return data;
37
+ })
38
+ .catch((err) => {
39
+ if (inflight === asked) inflight = null;
40
+ throw err;
41
+ });
42
+ inflight = asked;
43
+ return asked;
44
+ }
45
+
46
+ /**
47
+ * The two sidebar counts, wherever they are asked for.
48
+ *
49
+ * They live here rather than on the Inbox screen because they are the shell's, and because the
50
+ * whole point of this pass is that they are right before anybody has opened that screen. While
51
+ * the first fetch is out they show a placeholder rather than nothing: an empty badge reads as
52
+ * "zero", and zero is a different claim from "still counting".
53
+ */
54
+ export function stampCounts() {
55
+ const waiting = !S.inbox;
56
+ for (const [sel, n] of [
57
+ ["#homecount", needsCount],
58
+ ["#inboxcount", openCount],
59
+ ["#unreadcount", unreadCount],
60
+ ]) {
61
+ const slot = document.querySelector(sel);
62
+ if (!slot) continue;
63
+ slot.textContent = waiting ? "" : String(n());
64
+ slot.classList.toggle("wait", waiting);
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Count what is waiting on you without opening the screen that lists it.
70
+ *
71
+ * The badges used to fill in only once something else caused a render with an inbox loaded,
72
+ * which in practice meant "after you visit the Inbox". A sidebar that says nothing until you
73
+ * look at it is not a sidebar.
74
+ */
75
+ /** What Home's "Needs you" holds, for the sidebar. */
76
+ function needsCount() {
77
+ if (!S.inbox || !S.data) return 0;
78
+ return sortHome(S.inbox.items ?? [], S.data.staff, humansOf(), S.live?.staff ?? []).needs.length;
79
+ }
80
+
81
+ export function countInBackground() {
82
+ stampCounts();
83
+ return ensureInbox(false)
84
+ .then(stampCounts)
85
+ .catch(() => stampCounts());
86
+ }
87
+
88
+ export async function refreshAll(soft) {
89
+ const bar = $("#refreshall");
90
+ bar?.classList.add("spin");
91
+ try {
92
+ // Pull first. The portal reads the working tree, so a run that has landed on GitHub is
93
+ // invisible here until the checkout catches up.
94
+ S.sync = await getSync();
95
+ S.data = await getOrg();
96
+ S.inbox = null; // the inbox re-fetches itself on next paint
97
+ inflight = null;
98
+ S.loadedAt = new Date();
99
+ if (!soft) render();
100
+ stampLoaded();
101
+ // The badges are now claiming a count from before the sync. Re-ask, and say so meanwhile.
102
+ countInBackground();
103
+ } finally {
104
+ bar?.classList.remove("spin");
105
+ }
106
+ }
107
+
108
+ /**
109
+ * The same thing, for coming back to the tab.
110
+ *
111
+ * Asked for by a focus event rather than by a person, so it has to earn every visible effect.
112
+ * A full refresh drops the inbox, which sends the next paint to GitHub for four seconds and
113
+ * throws away whatever was on screen — including a half-written issue. Almost every focus
114
+ * finds nothing new, so this one syncs, looks, and only then does any of that.
115
+ */
116
+ export async function refreshQuietly() {
117
+ const bar = $("#refreshall");
118
+ bar?.classList.add("spin");
119
+ try {
120
+ S.sync = await getSync();
121
+ const data = await getOrg();
122
+ const changed = shape(data) !== shape(S.data);
123
+ S.data = data;
124
+ S.loadedAt = new Date();
125
+ stampLoaded();
126
+ // Something landed in a checkout: the inbox is stale too, and the screen should say so.
127
+ if (changed || (S.sync?.results ?? []).some((r) => r.pulled)) {
128
+ S.inbox = null;
129
+ inflight = null;
130
+ render();
131
+ countInBackground();
132
+ }
133
+ } finally {
134
+ bar?.classList.remove("spin");
135
+ }
136
+ }
137
+
138
+ /** The export minus its timestamp, which is stamped per request and always differs. */
139
+ function shape(data) {
140
+ if (!data) return "";
141
+ const { generatedAt, ...rest } = data;
142
+ return JSON.stringify(rest);
143
+ }
144
+
145
+ export function stampLoaded() {
146
+ const s = $("#loaded");
147
+ if (s && S.loadedAt) s.textContent = "data " + ago(S.loadedAt.toISOString());
148
+ }
149
+
150
+ /* A repo that could not be fast-forwarded is the difference between "nothing happened
151
+ today" and "something happened and you cannot see it", so it is said out loud. */
152
+ export function syncNotice() {
153
+ const stuck = (S.sync?.results ?? []).filter((r) => r.skipped || r.error || r.behind > 0);
154
+ if (!stuck.length) return null;
155
+ const d = el("div", { className: "notice" });
156
+ const lines = el("div");
157
+ lines.innerHTML = stuck
158
+ .map(
159
+ (r) =>
160
+ "<b>" + esc(r.dir) + "</b> " +
161
+ (r.error
162
+ ? "could not sync: " + esc(r.error)
163
+ : r.skipped === "dirty"
164
+ ? "is " + r.behind + " behind and has uncommitted changes, so it was not pulled. " +
165
+ "Commit or stash them, then pull."
166
+ : r.skipped === "diverged"
167
+ ? "has diverged (" + r.ahead + " ahead, " + r.behind + " behind). " +
168
+ "Push or rebase it by hand: a merge is not this button's to make."
169
+ : r.skipped === "no-remote"
170
+ ? "has no remote"
171
+ : "is " + r.behind + " behind"),
172
+ )
173
+ .join("<br>");
174
+ d.append(lines);
175
+
176
+ /* The same conservative pull `roster portal` runs on a refresh, on demand: fetch, and pull
177
+ only what is clean and fast-forward. It is here because the answer to "commit those and
178
+ pull" should not be to reload the page and hope. */
179
+ const status = el("span", { className: "meta" });
180
+ const pull = el("button", { className: "ghbtn", textContent: "Pull now" });
181
+ pull.onclick = async () => {
182
+ pull.disabled = true;
183
+ status.textContent = "pulling…";
184
+ status.className = "meta";
185
+ S.sync = await getSync();
186
+ const pulled = (S.sync?.results ?? []).filter((r) => r.pulled);
187
+ // Anything that landed is on disk now, so the export and the inbox are both behind it.
188
+ if (pulled.length) await refreshAll(false);
189
+ else {
190
+ pull.disabled = false;
191
+ status.textContent = "nothing could be pulled";
192
+ render();
193
+ }
194
+ };
195
+ d.append(el("div", { className: "row", style: "margin-top:10px" }, [pull, status]));
196
+ return d;
197
+ }
@@ -0,0 +1,20 @@
1
+ /* One indirection, so a view can ask for a repaint without importing the shell that owns it.
2
+ app.js registers the real renderer at boot; views import `render` and `go`. */
3
+
4
+ import { S } from "./state.js";
5
+
6
+ let renderer = () => {};
7
+
8
+ export function onRender(fn) {
9
+ renderer = fn;
10
+ }
11
+
12
+ export function render() {
13
+ renderer();
14
+ }
15
+
16
+ /** Change some state and repaint. The one way a view navigates. */
17
+ export function go(patch) {
18
+ Object.assign(S, patch);
19
+ render();
20
+ }