@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
@@ -0,0 +1,428 @@
1
+ /* The Connectors screen: outside services the staff can use in their runs.
2
+ *
3
+ * What is connected, as cards, and what can be, as a grid. Picking one opens a sheet with how
4
+ * to get its key, the key, who gets it, and Save. A key is checked with the service before it is
5
+ * stored, goes to GitHub as a secret, and is never shown again. A service that only signs in
6
+ * (Notion) signs in through the hosted portal instead.
7
+ */
8
+
9
+ import { getConnectors, post } from "../api.js";
10
+ import { sheet } from "../dialog.js";
11
+ import { el, toClipboard } from "../dom.js";
12
+ import { icon } from "../icons.js";
13
+ import { render } from "../router.js";
14
+ import { S } from "../state.js";
15
+
16
+ /* The last answer, so a repaint after Save does not flash an empty screen. */
17
+ let last = null;
18
+
19
+ export function viewConnectors(m) {
20
+ m.append(el("h1", { textContent: "Connectors" }));
21
+ const notice = signInNotice();
22
+ if (notice) m.append(notice);
23
+ const body = el("div");
24
+ m.append(body);
25
+ if (last) draw(body, last);
26
+ else body.append(el("p", { className: "sub", textContent: "Loading…" }));
27
+ getConnectors()
28
+ .then((d) => {
29
+ if (d.error) throw new Error(d.error);
30
+ last = d;
31
+ body.replaceChildren();
32
+ draw(body, d);
33
+ })
34
+ .catch((err) => body.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) })));
35
+ }
36
+
37
+ /** A sign-in that came back with a problem says so once, from the URL it came back to. */
38
+ function signInNotice() {
39
+ const q = (location.hash.split("?")[1] ?? "");
40
+ const e = new URLSearchParams(q).get("e");
41
+ if (!e) return null;
42
+ history.replaceState?.(null, "", location.hash.replace(/\?.*$/, ""));
43
+ return el("p", { className: "err connerr", textContent: e });
44
+ }
45
+
46
+ function draw(body, d) {
47
+ const have = new Set(d.connectors.map((c) => c.catalogue ?? c.id));
48
+
49
+ if (d.connectors.length) {
50
+ const list = el("div", { className: "connlist" });
51
+ for (const c of d.connectors) list.append(row(c, d));
52
+ body.append(el("h2", { className: "connhead", textContent: "Connected" }), list);
53
+ }
54
+
55
+ const grid = el("div", { className: "conngrid" });
56
+ for (const e of d.catalogue) {
57
+ if (have.has(e.id)) continue;
58
+ // One Notion, whichever this portal can do: signing in where it keeps sign-ins, a key elsewhere.
59
+ if (e.auth === "oauth" && !d.signIn) continue;
60
+ if (e.id === "notion-key" && d.signIn && !have.has("notion-key")) continue;
61
+ const card = el("button", { className: "conncard" }, [
62
+ el("span", { className: "connicon" }, [icon("plug")]),
63
+ el("span", {}, [el("b", { textContent: shortName(e) }), el("small", { textContent: e.summary })]),
64
+ ]);
65
+ card.onclick = () => open(e, null, d);
66
+ grid.append(card);
67
+ }
68
+ const own = el("button", { className: "conncard" }, [
69
+ el("span", { className: "connicon" }, [icon("plug")]),
70
+ el("span", {}, [el("b", { textContent: "Custom server" }), el("small", { textContent: "Any MCP server, by its URL." })]),
71
+ ]);
72
+ own.onclick = () => openCustom(d);
73
+ grid.append(own);
74
+ body.append(el("h2", { className: "connhead", textContent: d.connectors.length ? "Add another" : "Add a service" }), grid);
75
+ body.append(...ownAgent());
76
+ }
77
+
78
+ /* --------------------- this portal as an MCP server, elsewhere --------------------- */
79
+
80
+ /** How to add this portal's MCP server to Claude Code, Codex, Claude or anything else. */
81
+ function ownAgent() {
82
+ const head = el("h2", { className: "connhead", textContent: "Connect your own agent" });
83
+ if (!S.hosted) {
84
+ return [head, el("p", { className: "sub", textContent: "Needs the hosted portal: roster portal deploy." })];
85
+ }
86
+ const url = location.origin + "/mcp";
87
+ // Named after the org, so a second Roster in the same agent gets tools of its own.
88
+ const slug = String(S.data?.name ?? S.data?.org ?? "")
89
+ .toLowerCase()
90
+ .replace(/[^a-z0-9]+/g, "-")
91
+ .replace(/^-|-$/g, "");
92
+ const name = slug ? "roster-" + slug : "roster";
93
+ const rows = [
94
+ ["Claude Code", `claude mcp add --transport http ${name} ${url}`, "Then run /mcp and sign in."],
95
+ ["Codex", `codex mcp add ${name} --url ${url} && codex mcp login ${name}`, ""],
96
+ ["Claude", url, "Settings → Connectors → Add custom connector."],
97
+ ["Anything else", url, ""],
98
+ ];
99
+ const list = el("div", { className: "connlist" });
100
+ for (const [label, text, then] of rows) {
101
+ const copy = el("button", { className: "ghbtn", textContent: "Copy" });
102
+ copy.onclick = () => toClipboard(text, copy, "Copy");
103
+ list.append(
104
+ el("div", { className: "connrow connmcp" }, [
105
+ el("b", { textContent: label }),
106
+ el("div", { className: "connline" }, [el("code", { textContent: text }), copy]),
107
+ then ? el("small", { textContent: then }) : null,
108
+ ].filter(Boolean)),
109
+ );
110
+ }
111
+ return [head, el("p", { className: "sub", textContent: "Sign in with GitHub when it asks." }), list];
112
+ }
113
+
114
+ /** "Notion (integration key)" is only Notion where it is the one Notion on offer. */
115
+ function shortName(e) {
116
+ return e.name.replace(/ \(.*\)$/, "");
117
+ }
118
+
119
+ function row(c, d) {
120
+ const e = d.catalogue.find((x) => x.id === (c.catalogue ?? c.id));
121
+ const status = c.problem
122
+ ? el("span", { className: "chip hot", textContent: "Needs fixing" })
123
+ : c.auth === "oauth"
124
+ ? c.signedIn
125
+ ? el("span", { className: "chip ok", textContent: "Signed in" })
126
+ : el("span", { className: "chip warm", textContent: "Not signed in" })
127
+ : c.keys === "stored"
128
+ ? el("span", { className: "chip ok", textContent: "Key stored" })
129
+ : c.keys === "unknown"
130
+ ? el("span", { className: "chip", textContent: "Key not checked" })
131
+ : el("span", { className: "chip warm", textContent: c.keys === "partial" ? "Key on some repos" : "No key" });
132
+
133
+ const who = el("div", { className: "connwho" });
134
+ for (const h of c.staff) who.append(el("span", { className: "chip", textContent: h }));
135
+ if (c.readOnly) who.append(el("span", { className: "chip cool", textContent: "read only" }));
136
+
137
+ const edit = el("button", { className: "ghbtn", textContent: "Edit" });
138
+ edit.onclick = () => open(e ?? custom(c), c, d);
139
+ edit.disabled = !d.canWrite || (!e && Boolean(c.problem));
140
+ const remove = el("button", { className: "ghbtn", textContent: "Remove" });
141
+ remove.disabled = !d.canWrite;
142
+ remove.onclick = () => confirmRemove(c, remove);
143
+
144
+ return el("div", { className: "connrow" }, [
145
+ el("span", { className: "connicon" }, [icon("plug")]),
146
+ el("div", { className: "conntext" }, [
147
+ el("b", { textContent: c.name }),
148
+ c.problem ? el("span", { className: "err", textContent: c.problem }) : who,
149
+ ]),
150
+ status,
151
+ el("div", { className: "row connacts" }, [edit, remove]),
152
+ ]);
153
+ }
154
+
155
+ /** A server the catalogue does not describe: who has it, and its key when it takes one. */
156
+ function custom(c) {
157
+ const fields = c.auth === "key" && c.secrets.length === 1 ? [{ id: "token", label: c.secrets[0].label, secret: true }] : [];
158
+ return { id: c.id, name: c.name, summary: c.url ?? "", fields, steps: [], auth: c.auth };
159
+ }
160
+
161
+ /* --------------------------- a server of your own ---------------------------- */
162
+
163
+ function openCustom(d) {
164
+ let box = null;
165
+ const node = customForm(d, () => box?.close());
166
+ box = sheet({ node, onClose: () => {} });
167
+ if (!box) document.querySelector("#main")?.append(node);
168
+ }
169
+
170
+ function customForm(d, close) {
171
+ const out = el("div", { className: "connform" });
172
+ out.append(el("h2", { className: "sheettitle", textContent: "Connect a custom server" }));
173
+
174
+ const input = (placeholder, type = "text") => el("input", { type, autocomplete: "off", spellcheck: false, placeholder });
175
+ const name = input("acme");
176
+ const url = input("https://mcp.acme.dev/mcp");
177
+ const header = input("Authorization");
178
+ header.value = "Authorization";
179
+ const key = input("Bearer …", "password");
180
+ const field = (label, node) => el("label", { className: "field" }, [el("span", { textContent: label }), node]);
181
+ out.append(el("div", { className: "setupform" }, [field("Name", name), field("URL", url)]));
182
+
183
+ // How it signs in: a key in a header, the hosted portal's sign-in, or nothing.
184
+ let auth = "key";
185
+ const keyFields = el("div", { className: "setupform" }, [field("Header", header), field("Value", key)]);
186
+ const choices = el("div", { className: "connstaff" });
187
+ for (const [value, label] of [["key", "Key"], ["oauth", "Sign in"], ["none", "No key"]]) {
188
+ if (value === "oauth" && !d.signIn) continue;
189
+ const radio = el("input", { type: "radio", name: "connauth", checked: value === auth });
190
+ radio.onchange = () => {
191
+ auth = value;
192
+ keyFields.hidden = auth !== "key";
193
+ save.textContent = auth === "oauth" ? "Sign in" : "Save";
194
+ };
195
+ choices.append(el("label", { className: "conntick" }, [radio, el("span", { textContent: label })]));
196
+ }
197
+ out.append(el("h3", { className: "connsub", textContent: "Sign-in" }), choices, keyFields);
198
+
199
+ const picked = new Set(d.staff.length === 1 ? [d.staff[0].handle] : []);
200
+ out.append(el("h3", { className: "connsub", textContent: "Who can use it" }), staffPicker(d, picked));
201
+
202
+ const status = el("div");
203
+ const cancel = el("button", { className: "ghbtn", textContent: "Cancel" });
204
+ cancel.onclick = close;
205
+ const save = el("button", { className: "ghbtn primary", textContent: "Save" });
206
+ save.disabled = !d.canWrite;
207
+ const fail = (msg) => status.replaceChildren(el("p", { className: "err", textContent: msg }));
208
+ save.onclick = async () => {
209
+ const id = name.value.trim().toLowerCase();
210
+ if (!id) return fail("Give it a name.");
211
+ if (!picked.size) return fail("Pick at least one staff member.");
212
+ if (auth === "key" && !key.value.trim()) return fail("Paste the key, or pick No key.");
213
+ const label = save.textContent;
214
+ save.disabled = true;
215
+ save.textContent = auth === "oauth" ? "Opening…" : "Saving…";
216
+ try {
217
+ if (auth === "oauth") {
218
+ const r = await post({ id, staff: [...picked], custom: { url: url.value.trim() } }, "/api/connectors/signin");
219
+ location.href = r.url;
220
+ return;
221
+ }
222
+ await post(
223
+ {
224
+ id,
225
+ staff: [...picked],
226
+ custom: { url: url.value.trim(), header: header.value.trim() },
227
+ values: { token: auth === "key" ? key.value.trim() : "" },
228
+ },
229
+ "/api/connectors/save",
230
+ );
231
+ last = null;
232
+ close();
233
+ render();
234
+ } catch (err) {
235
+ save.disabled = false;
236
+ save.textContent = label;
237
+ fail(String(err.message || err));
238
+ }
239
+ };
240
+
241
+ out.append(status, el("div", { className: "row connfoot" }, [save, cancel]));
242
+ return out;
243
+ }
244
+
245
+ function staffPicker(d, picked) {
246
+ const who = el("div", { className: "connstaff" });
247
+ // An empty picker and then "Pick at least one staff member." had no way out.
248
+ if (!d.staff.length) {
249
+ who.append(el("p", { className: "sub", textContent: "Nobody is hired yet, so there is nobody to give it to. Hire someone first." }));
250
+ return who;
251
+ }
252
+ for (const s of d.staff) {
253
+ const box = el("input", { type: "checkbox", checked: picked.has(s.handle) });
254
+ box.onchange = () => (box.checked ? picked.add(s.handle) : picked.delete(s.handle));
255
+ who.append(el("label", { className: "conntick" }, [box, el("span", { textContent: s.name })]));
256
+ }
257
+ return who;
258
+ }
259
+
260
+ async function confirmRemove(c, btn) {
261
+ if (btn.dataset.sure !== "1") {
262
+ btn.dataset.sure = "1";
263
+ btn.textContent = "Remove " + c.name + "?";
264
+ btn.classList.add("danger");
265
+ return;
266
+ }
267
+ btn.disabled = true;
268
+ btn.textContent = "Removing…";
269
+ try {
270
+ await post({ id: c.id }, "/api/connectors/remove");
271
+ last = null;
272
+ render();
273
+ } catch (err) {
274
+ btn.textContent = String(err.message || err);
275
+ }
276
+ }
277
+
278
+ /* --------------------------------- the sheet --------------------------------- */
279
+
280
+ function open(e, c, d) {
281
+ let box = null;
282
+ const node = form(e, c, d, () => box?.close());
283
+ box = sheet({ node, onClose: () => {} });
284
+ if (!box) document.querySelector("#main")?.append(node);
285
+ }
286
+
287
+ function form(e, c, d, close) {
288
+ const out = el("div", { className: "connform" });
289
+ out.append(el("h2", { className: "sheettitle", textContent: (c ? "" : "Connect ") + shortName(e) }));
290
+ if (!c || !c.known) out.append(el("p", { className: "sub", textContent: e.summary }));
291
+
292
+ const oauth = e.auth === "oauth";
293
+ if (!c && e.steps.length && !oauth) {
294
+ const ol = el("ol", { className: "connsteps" });
295
+ for (const s of e.steps) ol.append(el("li", { textContent: s }));
296
+ out.append(ol);
297
+ if (e.link) {
298
+ out.append(
299
+ el("a", { className: "ghbtn", href: e.link, target: "_blank", rel: "noopener", textContent: "Open " + shortName(e) }),
300
+ );
301
+ }
302
+ }
303
+
304
+ const fields = el("div", { className: "setupform" });
305
+ const inputs = {};
306
+ for (const f of e.fields) {
307
+ const input = el("input", {
308
+ type: f.secret ? "password" : "text",
309
+ autocomplete: "off",
310
+ spellcheck: false,
311
+ placeholder: f.secret && c ? "Leave empty to keep the stored key" : f.required ? "" : "Optional",
312
+ value: f.secret ? "" : (c?.settings?.[f.id] ?? ""),
313
+ });
314
+ inputs[f.id] = { input, f };
315
+ fields.append(el("label", { className: "field" }, [el("span", { textContent: f.label }), input]));
316
+ }
317
+ if (e.fields.length) out.append(fields);
318
+
319
+ const checked = el("div", { className: "conncheck" });
320
+ const secretInputs = Object.values(inputs).filter((x) => x.f.secret);
321
+ if (e.canCheck && secretInputs.length) {
322
+ const check = el("button", { className: "ghbtn", textContent: "Check key" });
323
+ check.onclick = async () => {
324
+ check.disabled = true;
325
+ check.textContent = "Checking…";
326
+ try {
327
+ const r = await post({ id: e.id, values: valuesOf(inputs) }, "/api/connectors/check");
328
+ checked.replaceChildren(result(r));
329
+ } catch (err) {
330
+ checked.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
331
+ } finally {
332
+ check.disabled = false;
333
+ check.textContent = "Check key";
334
+ }
335
+ };
336
+ out.append(el("div", { className: "row" }, [check]), checked);
337
+ }
338
+
339
+ const picked = new Set(c ? c.staff : (e.suggest ?? []).filter((h) => d.staff.some((s) => s.handle === h)));
340
+ if (!picked.size && d.staff.length === 1) picked.add(d.staff[0].handle);
341
+ out.append(el("h3", { className: "connsub", textContent: "Who can use it" }), staffPicker(d, picked));
342
+
343
+ let ro = null;
344
+ if (e.readOnly) {
345
+ ro = el("input", { type: "checkbox", checked: Boolean(c?.readOnly) });
346
+ out.append(el("label", { className: "conntick" }, [ro, el("span", { textContent: "Read only" })]));
347
+ }
348
+
349
+ const status = el("div");
350
+ const cancel = el("button", { className: "ghbtn", textContent: "Cancel" });
351
+ cancel.onclick = close;
352
+ const save = el("button", { className: "ghbtn primary" });
353
+
354
+ if (oauth && !c?.signedIn) {
355
+ save.textContent = "Sign in to " + e.name;
356
+ save.disabled = !d.signIn || !d.canWrite;
357
+ if (!d.signIn) {
358
+ out.append(el("p", { className: "sub", textContent: "Signing in needs the hosted portal." }));
359
+ }
360
+ save.onclick = async () => {
361
+ if (!picked.size) return status.replaceChildren(el("p", { className: "err", textContent: "Pick at least one staff member." }));
362
+ save.disabled = true;
363
+ save.textContent = "Opening " + e.name + "…";
364
+ try {
365
+ const r = await post({ id: e.id, staff: [...picked], readOnly: Boolean(ro?.checked) }, "/api/connectors/signin");
366
+ location.href = r.url;
367
+ } catch (err) {
368
+ save.disabled = false;
369
+ save.textContent = "Sign in to " + e.name;
370
+ status.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
371
+ }
372
+ };
373
+ } else {
374
+ save.textContent = "Save";
375
+ save.disabled = !d.canWrite;
376
+ save.onclick = async () => {
377
+ if (!picked.size) return status.replaceChildren(el("p", { className: "err", textContent: "Pick at least one staff member." }));
378
+ save.disabled = true;
379
+ save.textContent = "Saving…";
380
+ try {
381
+ await post(
382
+ {
383
+ id: e.id,
384
+ staff: [...picked],
385
+ readOnly: Boolean(ro?.checked),
386
+ settings: settingsOf(inputs),
387
+ values: valuesOf(inputs, true),
388
+ },
389
+ "/api/connectors/save",
390
+ );
391
+ last = null;
392
+ close();
393
+ render();
394
+ } catch (err) {
395
+ save.disabled = false;
396
+ save.textContent = "Save";
397
+ status.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
398
+ }
399
+ };
400
+ }
401
+
402
+ out.append(status, el("div", { className: "row connfoot" }, [save, cancel]));
403
+ if (!d.canWrite) out.append(el("p", { className: "sub", textContent: "You are view-only, so you cannot change connectors." }));
404
+ return out;
405
+ }
406
+
407
+ function result(r) {
408
+ if (r.state === "ok") return el("p", { className: "okline", textContent: "The key works." });
409
+ if (r.state === "limited") return el("p", { className: "okline", textContent: r.note });
410
+ if (r.state === "rejected") return el("p", { className: "err", textContent: r.note });
411
+ return el("p", { className: "sub", textContent: r.note });
412
+ }
413
+
414
+ /** Every field's value, for checking; only the keys, for storing. */
415
+ function valuesOf(inputs, keysOnly = false) {
416
+ const out = {};
417
+ for (const [id, { input, f }] of Object.entries(inputs)) {
418
+ if (keysOnly && !f.secret) continue;
419
+ out[id] = String(input.value ?? "").trim();
420
+ }
421
+ return out;
422
+ }
423
+
424
+ function settingsOf(inputs) {
425
+ const out = {};
426
+ for (const [id, { input, f }] of Object.entries(inputs)) if (!f.secret) out[id] = String(input.value ?? "").trim();
427
+ return out;
428
+ }
@@ -53,8 +53,13 @@ function drawGraph(canvas, wrap, s) {
53
53
  }
54
54
  const groups = [...members.keys()].sort((a, b) => members.get(b).length - members.get(a).length);
55
55
 
56
- const PALETTE = ["#30d158","#0a84ff","#bf5af2","#ff9f0a","#64d2ff","#ff453a","#ffcc00","#ff375f","#5e5ce6","#ac8e68"];
57
- const colour = new Map(groups.map((g, i) => [g, PALETTE[i % PALETTE.length]]));
56
+ // Astryx's categorical colours, one per group. They are theme tokens, so a group keeps its
57
+ // hue in both themes at the strength each theme wants.
58
+ const PALETTE = ["blue", "green", "purple", "orange", "cyan", "red", "yellow", "pink", "teal", "gray"]
59
+ .map((c) => `--color-icon-${c}`);
60
+ const token = new Map(groups.map((g, i) => [g, PALETTE[i % PALETTE.length]]));
61
+ // For markup, which can take the token as it is.
62
+ const colour = new Map(groups.map((g) => [g, `var(${token.get(g)})`]));
58
63
 
59
64
  // The ring grows with the number of groups so they never crowd, and each group keeps its
60
65
  // angle for the life of the view. That angle is also the direction its members fan out in.
@@ -69,6 +74,9 @@ function drawGraph(canvas, wrap, s) {
69
74
  }));
70
75
 
71
76
  const radius = (n) => n.isGroup ? 16 + Math.sqrt(n.count) * 3.6 : 5.5;
77
+ /* What is drawn and clicked: never smaller on screen than a dot you can read a count in or
78
+ hit with a pointer, however far out the picture is fitted. The layout keeps `radius`. */
79
+ const seen = (n) => Math.max(radius(n), (n.isGroup ? 11 + Math.sqrt(n.count) * 1.4 : 4) / scale);
72
80
 
73
81
  /* Fan a group's members outward along its own angle, in shells, so a big group becomes a
74
82
  wedge pointing away from the middle rather than a ball sitting on its neighbours. */
@@ -148,7 +156,37 @@ function drawGraph(canvas, wrap, s) {
148
156
  recompute();
149
157
  }
150
158
 
151
- const css = (v) => getComputedStyle(document.documentElement).getPropertyValue(v).trim();
159
+ /* A canvas takes colours, not tokens, and the theme's tokens are light-dark() pairs that it
160
+ cannot parse: handed one, it keeps whatever colour it had before, which painted every label
161
+ in the last group's colour. So each token is resolved by an element that wears it, and the
162
+ answers are kept until the theme changes. */
163
+ const probe = el("span", { hidden: true });
164
+ wrap.append(probe);
165
+ const resolved = new Map();
166
+ const css = (v) => {
167
+ if (!resolved.has(v)) {
168
+ probe.style.color = `var(${v})`;
169
+ resolved.set(v, getComputedStyle(probe).color);
170
+ }
171
+ return resolved.get(v);
172
+ };
173
+ const hue = (g) => css(token.get(g) ?? "--ink-faint");
174
+ const forget = () => resolved.clear();
175
+ globalThis.MutationObserver &&
176
+ new MutationObserver(forget).observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
177
+ globalThis.matchMedia?.("(prefers-color-scheme: dark)").addEventListener?.("change", forget);
178
+ const SANS = getComputedStyle(probe).fontFamily || "system-ui, sans-serif";
179
+
180
+ /** Text over the picture: a halo in the card's colour first, so no edge runs through it. */
181
+ function label(text, x, y, ink, weight, px) {
182
+ ctx.font = `${weight} ${px / scale}px ${SANS}`;
183
+ ctx.lineJoin = "round";
184
+ ctx.lineWidth = 4 / scale;
185
+ ctx.strokeStyle = css("--panel");
186
+ ctx.strokeText(text, x, y);
187
+ ctx.fillStyle = css(ink);
188
+ ctx.fillText(text, x, y);
189
+ }
152
190
  let tx = 0, ty = 0, scale = 0.8;
153
191
  let selected = null, hover = null, drag = null, panning = false, lx = 0, ly = 0, moved = 0;
154
192
  const ctx = canvas.getContext("2d");
@@ -166,9 +204,9 @@ function drawGraph(canvas, wrap, s) {
166
204
  };
167
205
  wrap.append(el("div", { className: "gtools" }, [
168
206
  search,
169
- el("button", { textContent: "open all", onclick: () => { for (const g of groups) if (!expanded.has(g)) toggle(g); } }),
170
- el("button", { textContent: "close all", onclick: () => { for (const g of [...expanded]) toggle(g); } }),
171
- el("button", { textContent: "fit", onclick: fit }),
207
+ el("button", { className: "ghbtn sm", textContent: "Open all", onclick: () => { for (const g of groups) if (!expanded.has(g)) toggle(g); } }),
208
+ el("button", { className: "ghbtn sm", textContent: "Close all", onclick: () => { for (const g of [...expanded]) toggle(g); } }),
209
+ el("button", { className: "ghbtn sm", textContent: "Fit", onclick: fit }),
172
210
  ]));
173
211
 
174
212
  const legend = el("div", { className: "legend" });
@@ -242,7 +280,8 @@ function drawGraph(canvas, wrap, s) {
242
280
  const xs = vis.map((n) => n.x), ys = vis.map((n) => n.y);
243
281
  const minx = Math.min(...xs), miny = Math.min(...ys);
244
282
  const w = Math.max(...xs) - minx || 1, h = Math.max(...ys) - miny || 1;
245
- scale = Math.min(1.6, Math.max(0.12, Math.min(rect.width / (w + 260), rect.height / (h + 260))));
283
+ // Room round the edge for the dots and the labels under them, which keep their size on screen.
284
+ scale = Math.min(1.6, Math.max(0.12, Math.min((rect.width - 200) / w, (rect.height - 110) / h)));
246
285
  tx = -(minx + w / 2) * scale;
247
286
  ty = -(miny + h / 2) * scale;
248
287
  }
@@ -311,7 +350,7 @@ function drawGraph(canvas, wrap, s) {
311
350
  for (const g of groups) {
312
351
  if (!expanded.has(g) || hidden.has(g)) continue;
313
352
  const gn = groupNodes.get(g);
314
- ctx.strokeStyle = colour.get(g); ctx.globalAlpha = 0.14;
353
+ ctx.strokeStyle = hue(g); ctx.globalAlpha = 0.18;
315
354
  ctx.lineWidth = 1 / scale;
316
355
  for (const id of members.get(g)) {
317
356
  const mn = memberNodes.get(id);
@@ -322,16 +361,18 @@ function drawGraph(canvas, wrap, s) {
322
361
 
323
362
  for (const e of edges) {
324
363
  const lit = !near || (near.has(e.a) && near.has(e.b));
325
- ctx.strokeStyle = near && lit ? css("--accent") : css("--line");
326
- ctx.globalAlpha = near ? (lit ? 0.95 : 0.07) : 0.62;
327
- ctx.lineWidth = Math.min(6, 0.8 + Math.log2(e.weight + 1) * 1.25) / Math.max(1, scale * 0.8);
364
+ // Hairlines, the same width on screen at any zoom; a link made many times is a little
365
+ // heavier, never a bar.
366
+ ctx.strokeStyle = near && lit ? css("--accent") : css("--border-strong");
367
+ ctx.globalAlpha = near ? (lit ? 0.9 : 0.08) : 0.9;
368
+ ctx.lineWidth = (1 + Math.min(1.5, Math.log2(e.weight) * 0.5)) / scale;
328
369
  ctx.beginPath(); ctx.moveTo(e.a.x, e.a.y); ctx.lineTo(e.b.x, e.b.y); ctx.stroke();
329
370
  }
330
371
  ctx.globalAlpha = 1;
331
372
 
332
373
  const painted = shown().sort((a, b) => (b.isGroup ? b.count : 0) - (a.isGroup ? a.count : 0));
333
374
  for (const n of painted) {
334
- const r = radius(n);
375
+ const r = seen(n);
335
376
  const dim = near && !near.has(n);
336
377
  ctx.globalAlpha = dim ? 0.13 : 1;
337
378
 
@@ -341,37 +382,35 @@ function drawGraph(canvas, wrap, s) {
341
382
  if (open) {
342
383
  // Hollow while open: the group is still here, and still the thing you click to fold.
343
384
  ctx.fillStyle = css("--panel"); ctx.fill();
344
- ctx.strokeStyle = colour.get(n.group); ctx.lineWidth = 2.4 / scale; ctx.stroke();
345
- ctx.fillStyle = colour.get(n.group);
385
+ ctx.strokeStyle = hue(n.group); ctx.lineWidth = 2 / scale; ctx.stroke();
386
+ ctx.fillStyle = hue(n.group);
346
387
  } else {
347
- ctx.fillStyle = colour.get(n.group); ctx.fill();
348
- ctx.fillStyle = css("--bg");
388
+ ctx.fillStyle = hue(n.group); ctx.fill();
389
+ ctx.fillStyle = css("--panel");
349
390
  }
350
- ctx.font = "600 " + Math.max(9, r * 0.6) + "px ui-monospace,monospace";
391
+ ctx.font = "600 " + Math.max(9, r * 0.62) + "px " + SANS;
351
392
  ctx.textAlign = "center"; ctx.textBaseline = "middle";
352
393
  ctx.fillText(String(n.count), n.x, n.y + 0.5);
353
394
  ctx.textBaseline = "alphabetic";
354
395
  const text = n.id.length > 24 ? n.id.slice(0, 23) + "..." : n.id;
355
- const fs = Math.max(10, 12 / scale);
356
- ctx.font = "600 " + fs + "px -apple-system,system-ui,sans-serif";
396
+ const fs = 12.5 / scale;
397
+ ctx.font = "600 " + fs + "px " + SANS;
357
398
  const w = ctx.measureText(text).width;
358
- const bx = n.x - w / 2, by = n.y + r + 6, bh = fs * 1.25;
399
+ const bx = n.x - w / 2, by = n.y + r + 6 / scale, bh = fs * 1.25;
359
400
  const clashes = labelBoxes.some((o) =>
360
401
  bx < o.x + o.w + 8 && bx + w + 8 > o.x && by < o.y + o.h + 4 && by + bh + 4 > o.y);
361
402
  if (!clashes || n === hover) {
362
403
  labelBoxes.push({ x: bx, y: by, w, h: bh });
363
404
  ctx.textAlign = "center";
364
- ctx.fillStyle = css(n === hover ? "--ink" : "--ink-dim");
365
- ctx.fillText(text, n.x, by + fs);
405
+ label(text, n.x, by + fs, n === hover ? "--ink" : "--ink", 600, 12.5);
366
406
  }
367
407
  ctx.textAlign = "left";
368
408
  } else {
369
- ctx.fillStyle = colour.get(n.group) ?? css("--ink-faint");
409
+ ctx.fillStyle = hue(n.group);
370
410
  ctx.beginPath(); ctx.arc(n.x, n.y, r, 0, 7); ctx.fill();
371
411
  if (n === selected || n === hover || scale > 1.05) {
372
- ctx.fillStyle = css(n === selected || n === hover ? "--ink" : "--ink-dim");
373
- ctx.font = Math.max(9, 10.5 / scale) + "px ui-monospace,monospace";
374
- ctx.fillText(n.id.length > 26 ? n.id.slice(0, 25) + "..." : n.id, n.x + r + 4, n.y + 3.5);
412
+ const text = n.id.length > 26 ? n.id.slice(0, 25) + "…" : n.id;
413
+ label(text, n.x + r + 5 / scale, n.y + 4 / scale, n === selected || n === hover ? "--ink" : "--ink-dim", 500, 11.5);
375
414
  }
376
415
  }
377
416
  if (n === selected || n === hover) {
@@ -396,8 +435,8 @@ function drawGraph(canvas, wrap, s) {
396
435
  const p = toWorld(ev);
397
436
  // Members first: an open group's node must never swallow a click meant for a fact.
398
437
  const vis = shown();
399
- return vis.filter((n) => !n.isGroup).find((n) => Math.hypot(n.x - p.x, n.y - p.y) < radius(n) + 6)
400
- ?? vis.filter((n) => n.isGroup).find((n) => Math.hypot(n.x - p.x, n.y - p.y) < radius(n) + 5);
438
+ return vis.filter((n) => !n.isGroup).find((n) => Math.hypot(n.x - p.x, n.y - p.y) < seen(n) + 6 / scale)
439
+ ?? vis.filter((n) => n.isGroup).find((n) => Math.hypot(n.x - p.x, n.y - p.y) < seen(n) + 5 / scale);
401
440
  };
402
441
 
403
442
  canvas.onpointerdown = (ev) => {
@@ -8,6 +8,7 @@ import { render } from "../router.js";
8
8
  import { S, staff } from "../state.js";
9
9
  import { checklist } from "./checklist.js";
10
10
  import { amendSheet } from "./prompt.js";
11
+ import { notReadyNote, whenKnown } from "./notready.js";
11
12
  import { runOnce } from "./runonce.js";
12
13
 
13
14
  const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
@@ -86,12 +87,17 @@ export function viewHealth(m) {
86
87
  /* A workflow that has never run is unproven, and the way to prove it is to run it. Here
87
88
  because Health is where "unproven" is read; a success re-runs the checks below. */
88
89
  let doctor = null;
90
+ /* Only once a run could work. With the App or the credential missing, it started a run that
91
+ could only fail; until then the note says what is left instead. */
89
92
  m.append(
90
- runOnce({
91
- staff: s.handle,
92
- name: s.name,
93
- onDone: (ok) => ok && doctor && checklist(doctor.body, { shell: doctor }),
94
- }),
93
+ whenKnown(s, () =>
94
+ notReadyNote(s) ??
95
+ runOnce({
96
+ staff: s.handle,
97
+ name: s.name,
98
+ onDone: (ok) => ok && doctor && checklist(doctor.body, { shell: doctor }),
99
+ }),
100
+ ),
95
101
  );
96
102
 
97
103
  doctor = section(m, "The org, from roster doctor", "doctor");