@nanocollective/roster 0.1.0-alpha.8 → 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 +4084 -1936
  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 +13 -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,557 @@
1
+ /* Standing an org up, in the browser, before there is anything on disk to browse.
2
+ *
3
+ * The rule this screen follows: never claim a step is done because you clicked it. Everything
4
+ * here is re-derived from /api/setup/status, so a page reloaded tomorrow shows the world as it
5
+ * is rather than as it was left. Setup cannot be finished in one sitting, so it must survive
6
+ * being abandoned halfway. */
7
+
8
+ import {
9
+ checkOrg,
10
+ createTenant,
11
+ getAccess,
12
+ getOrg,
13
+ getSetup,
14
+ joinOrg,
15
+ planTenant,
16
+ setAccess,
17
+ } from "../api.js";
18
+ import { $, el, esc, toClipboard } from "../dom.js";
19
+ import { go } from "../router.js";
20
+ import { S as App } from "../state.js";
21
+ import { checkAll, notReady, progress, sentence } from "../readiness.js";
22
+ import { checklist } from "./checklist.js";
23
+ import { businessForm, prioritiesForm } from "./orgedit.js";
24
+ import { credentialPanel } from "./credential.js";
25
+ import { repoPicker } from "./repos.js";
26
+ import { todo } from "./todo.js";
27
+
28
+ let S = null; // /api/setup/status, refreshed after anything that changes the world
29
+
30
+ /* Where the doctor checklist is drawn on this screen, so a save can re-run it. Left stale, it
31
+ went on saying business.stub after business.md had been saved, until "Check again". */
32
+ let healthHost = null;
33
+ let healthStep = null;
34
+
35
+ /* What the "What is left" cards already ask for. Doctor reporting them as well, right after a
36
+ successful create, read as the create having failed. */
37
+ const COVERED = ["business", "business.stub", "priorities", "priorities.stub", "actions-access", "secrets", "agent"];
38
+ const HEALTH = { skip: COVERED, hideWhenClean: true };
39
+
40
+ /* Each "what is left" step that is a file, by id, so a save can mark it done in place rather
41
+ than repainting the page and throwing away the diff somebody is still reading. */
42
+ const fileSteps = new Map();
43
+
44
+ export async function viewSetup(main) {
45
+ S = await getSetup();
46
+ render(main);
47
+ }
48
+
49
+ /**
50
+ * The same steps once a tenant exists, as their own screen in the portal.
51
+ *
52
+ * Setup used to be reachable only before there was a tenant, so the reload that followed
53
+ * creating one landed on an empty Inbox with the repo picker, the credential and both files
54
+ * gone. The sidebar offers this while anything is unfinished, and an org nobody has been hired
55
+ * into opens on it.
56
+ */
57
+ export async function viewGettingStarted(main) {
58
+ main.append(el("h1", { textContent: "Getting started" }));
59
+ const sub = el("p", { className: "sub", textContent: "Reading what is left…" });
60
+ main.append(sub);
61
+ S = await getSetup();
62
+ // Somebody may have clicked elsewhere while GitHub was answering.
63
+ if (App.view !== "setup") return;
64
+ await checkAll();
65
+ if (App.view !== "setup") return;
66
+ const p = progress();
67
+ sub.textContent = (p ? `${p.done} of ${p.total} done. ` : "") + "Work through these in order.";
68
+ const list = afterCreate();
69
+
70
+ // Somebody hired but not ready to run is the most important thing left, so it comes first.
71
+ for (const s of notReady().reverse()) {
72
+ const t = todo("!", "Finish setting up " + s.name, false);
73
+ t.hint("Still to do: " + sentence(App.readiness?.[s.handle] ?? []) + ".");
74
+ const cont = el("button", { className: "btn primary", textContent: "Continue" });
75
+ cont.onclick = () => {
76
+ App.staffOpen = { handle: s.handle, name: s.name, dir: s.dir };
77
+ go({ view: "staff" });
78
+ };
79
+ t.body.append(el("div", { className: "row" }, [cont]));
80
+ list.prepend(t.card);
81
+ }
82
+ main.append(list);
83
+
84
+ const health = step("!", "Other problems", false);
85
+ healthHost = el("div", { style: "margin-top:12px" });
86
+ health.append(healthHost);
87
+ main.append(health);
88
+ healthStep = health;
89
+ checklist(healthHost, { ...HEALTH, onEmpty: () => health.remove() });
90
+ }
91
+
92
+ /** Whether the sidebar offers Getting started: while anything is left, or while it is open. */
93
+ export function paintSetupNav() {
94
+ const nav = $("#setupnav");
95
+ if (!nav) return;
96
+ // Hosted, there is no setting up from here: that is done in roster portal on your machine.
97
+ nav.hidden =
98
+ Boolean(App.hosted) ||
99
+ (!App.data?.unfinished?.length && !notReady().length && App.view !== "setup");
100
+ const count = $("#setupcount");
101
+ const p = progress();
102
+ if (count) count.textContent = p ? `${p.done}/${p.total}` : "";
103
+ }
104
+
105
+ /* After a save: the checklist and the step list are both derived from disk, so both are asked
106
+ again rather than updated by hand. The sidebar's list comes from /api/org, which is the one
107
+ the portal already reads. */
108
+ async function recheck() {
109
+ if (healthHost) checklist(healthHost, { ...HEALTH, onEmpty: () => healthStep?.remove() });
110
+ try {
111
+ S = await getSetup();
112
+ for (const [id, mark] of fileSteps) mark(!(S.tenant.left ?? []).includes(id));
113
+ } catch {
114
+ // The saved file is saved either way; a stale tick is not worth an error on top of it.
115
+ }
116
+ if (App.data) {
117
+ const fresh = await getOrg().catch(() => null);
118
+ if (fresh?.unfinished) App.data.unfinished = fresh.unfinished;
119
+ paintSetupNav();
120
+ }
121
+ }
122
+
123
+ function render(main) {
124
+ /* The sidebar is written by boot() before any of this is known. Once a tenant has been
125
+ adopted, leaving it on "no org yet" contradicts the card directly below it. */
126
+ const brand = $("#orgname");
127
+ if (brand) brand.textContent = S.tenant.found ? (S.tenant.org ?? "set up") : "no org yet";
128
+
129
+ main.replaceChildren();
130
+ main.append(el("h1", { textContent: "Set up your org" }));
131
+ main.append(
132
+ el("p", {
133
+ className: "sub",
134
+ textContent:
135
+ "Choose an organisation and a coding agent. Nothing is created until you press Create it.",
136
+ }),
137
+ );
138
+
139
+ main.append(stepGh());
140
+ if (!S.gh.ok) return; // everything downstream needs gh, and saying so once is enough
141
+ main.append(stepOrg(main));
142
+
143
+ /* Drawn whenever a tenant exists, not only in the seconds after creating one. Setup takes
144
+ days: the repo picker and the two manual steps have to still be here tomorrow. */
145
+ if (S.tenant.found) {
146
+ const rest = step(3, "Finish setting up", false);
147
+ rest.append(afterCreate());
148
+ main.append(rest);
149
+ }
150
+ }
151
+
152
+ /* ---------------------------------- 1 · gh ---------------------------------- */
153
+
154
+ function stepGh() {
155
+ const card = step(1, "GitHub CLI", S.gh.ok);
156
+ if (S.gh.ok) {
157
+ card.append(el("p", { className: "sub", textContent: "Signed in as " + S.gh.login + "." }));
158
+ return card;
159
+ }
160
+ card.append(
161
+ el("p", { textContent: S.gh.error }),
162
+ el("p", {
163
+ className: "sub",
164
+ textContent:
165
+ "Run this in a terminal, then reload:",
166
+ }),
167
+ el("pre", { className: "cmd", textContent: "gh auth login" }),
168
+ );
169
+ return card;
170
+ }
171
+
172
+ /* ------------------------- 2, 3, 4 · org, agent, create ------------------------- */
173
+
174
+ function stepOrg(main) {
175
+ const done = S.tenant.found;
176
+ const card = step(2, "The organisation, and who runs it", done);
177
+
178
+ if (done) {
179
+ card.append(
180
+ el("p", {
181
+ textContent: S.tenant.org + " is set up. Its ops repo is at " + S.tenant.opsDir + ".",
182
+ }),
183
+ el("p", {
184
+ className: "sub",
185
+ textContent:
186
+ "Finish the steps below. They stay under Getting started in the sidebar until they're done.",
187
+ }),
188
+ );
189
+ return card;
190
+ }
191
+
192
+ const form = el("div", { className: "setupform" });
193
+ const field = (id, label, value, hint) => {
194
+ const wrap = el("label", { className: "field" });
195
+ wrap.append(el("span", { textContent: label }));
196
+ const input = el("input", { id: "f-" + id, value: value ?? "" });
197
+ input.setAttribute("type", "text");
198
+ wrap.append(input);
199
+ if (hint) wrap.append(el("small", { textContent: hint }));
200
+ form.append(wrap);
201
+ // The wrapper, not just the input: reaching back through parentElement to hide a row is
202
+ // the kind of indirection that works until the markup moves one level.
203
+ return { wrap, input };
204
+ };
205
+
206
+ /* A picker over the orgs gh can already see, because typing a name you have to get exactly
207
+ right is the kind of thing that fails at step two and reads as the tool being broken. */
208
+ const orgWrap = el("label", { className: "field" });
209
+ orgWrap.append(el("span", { textContent: "GitHub organisation" }));
210
+ const org = el("select", { id: "f-org" });
211
+ org.append(el("option", { value: "", textContent: S.orgs.length ? "choose one…" : "type below" }));
212
+ for (const o of S.orgs) org.append(el("option", { value: o, textContent: o }));
213
+ org.append(el("option", { value: "__other", textContent: "another one…" }));
214
+ orgWrap.append(org);
215
+ orgWrap.append(
216
+ el("small", {
217
+ textContent:
218
+ "Don't have one? Create it on github.com first.",
219
+ }),
220
+ );
221
+ form.append(orgWrap);
222
+
223
+ const other = field("orgother", "Organisation name", "", "");
224
+ other.wrap.hidden = S.orgs.length > 0;
225
+
226
+ /* Which of the two things this is. An org that already has a roster-ops wants joining, not
227
+ a second one, and that is the question a second person on a team is really asking. */
228
+ const verdict = el("div", { className: "verdict", hidden: true });
229
+ form.append(verdict);
230
+ let existing = null;
231
+
232
+ const look = async () => {
233
+ const name = org.value === "__other" ? other.input.value.trim() : org.value;
234
+ existing = null;
235
+ verdict.hidden = true;
236
+ if (!name) return;
237
+ verdict.hidden = false;
238
+ verdict.replaceChildren(el("p", { className: "sub", textContent: "Looking at " + name + "…" }));
239
+ try {
240
+ const found = await checkOrg(name);
241
+ existing = found.exists ? name : null;
242
+ verdict.replaceChildren(
243
+ el("p", {
244
+ textContent: found.exists
245
+ ? name + " already runs roster. Nothing here needs creating; it needs checking out."
246
+ : "Nothing in " + name + " yet. This will create " + name + "/roster-ops.",
247
+ }),
248
+ );
249
+ paint();
250
+ } catch {
251
+ verdict.hidden = true;
252
+ }
253
+ };
254
+
255
+ org.addEventListener("change", () => {
256
+ other.wrap.hidden = org.value !== "__other";
257
+ look();
258
+ });
259
+ other.input.addEventListener("change", look);
260
+
261
+ const name = field("name", "What the business is called", "", "Defaults to the organisation name.");
262
+ const human = field("human", "Your GitHub login", S.gh.login ?? "", "The person the staff report to.");
263
+
264
+ card.append(form);
265
+ const agentHead = el("h3", { textContent: "Which coding agent runs a session" });
266
+
267
+ /* The agent. Its id decides the secret name later, so setup can name it exactly rather than
268
+ saying "it depends on the runner". */
269
+ card.append(agentHead);
270
+ const agents = el("div", { className: "choices" });
271
+ S.agents.forEach((a, i) => {
272
+ const opt = el("label", { className: "choice" });
273
+ const radio = el("input", { name: "agent", value: a.id, checked: i === 0 });
274
+ radio.setAttribute("type", "radio");
275
+ opt.append(radio, el("b", { textContent: a.label }));
276
+ opt.append(el("code", { textContent: a.tokenEnv }));
277
+ agents.append(opt);
278
+ });
279
+ card.append(agents);
280
+ const agentNote = el("p", {
281
+ className: "sub",
282
+ textContent:
283
+ "Using a different agent? Pick any of these, then set it in org.yaml afterwards.",
284
+ });
285
+ card.append(agentNote);
286
+
287
+ const params = () => ({
288
+ org: org.value === "__other" ? other.input.value.trim() : org.value,
289
+ name: name.input.value.trim(),
290
+ human: human.input.value.trim(),
291
+ marker: (human.input.value.trim().split("-")[0] || "human").toLowerCase(),
292
+ agent: agents.querySelector("input:checked")?.value ?? "claude-code-action",
293
+ });
294
+
295
+ const out = el("div", { className: "planout" });
296
+ const plan = el("button", { className: "btn", textContent: "Show me the plan" });
297
+ const go = el("button", { className: "btn primary", textContent: "Create it", hidden: true });
298
+ const join = el("button", { className: "btn primary", textContent: "Check it out here", hidden: true });
299
+ card.append(el("div", { className: "row" }, [plan, go, join]), out);
300
+
301
+ /* Creating and joining are mutually exclusive, and showing both is how somebody creates a
302
+ second ops repo in an org that already had one. */
303
+ function paint() {
304
+ const joining = existing !== null;
305
+ join.hidden = !joining;
306
+ plan.hidden = joining;
307
+ if (joining) go.hidden = true;
308
+
309
+ /* An org that already runs roster has answered all of these: its own org.yaml names the
310
+ business, the human and the agent. Leaving them on screen asks for values that will be
311
+ thrown away, and implies the checkout is going to use them. */
312
+ for (const bit of [name.wrap, human.wrap, agentHead, agents, agentNote]) bit.hidden = joining;
313
+ }
314
+
315
+ join.onclick = async () => {
316
+ join.disabled = true;
317
+ /* Cloning an ops repo and every brain took 38 seconds against a real org, behind a word
318
+ that never changed. A static "Cloning…" for that long reads as hung, so this says what
319
+ it is doing and keeps a clock running to show it is alive. */
320
+ const clock = el("p", { className: "sub" });
321
+ out.replaceChildren(clock);
322
+ const started = Date.now();
323
+ const tick = () => {
324
+ const s = Math.round((Date.now() - started) / 1000);
325
+ clock.textContent =
326
+ `Cloning ${existing}: the ops repo and one for each staff member. ${s}s. ` +
327
+ "A first checkout usually takes under a minute.";
328
+ };
329
+ tick();
330
+ const ticking = setInterval(tick, 1000);
331
+ try {
332
+ const result = await joinOrg(existing);
333
+ if (!result.ok) throw new Error(result.error);
334
+ out.replaceChildren(
335
+ el("p", {
336
+ textContent:
337
+ "Checked out " + (result.cloned ?? []).join(", ") + " into " + (S.startedIn ?? "here") + ".",
338
+ }),
339
+ );
340
+ S = await getSetup();
341
+ render(main);
342
+ } catch (err) {
343
+ out.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
344
+ } finally {
345
+ clearInterval(ticking);
346
+ join.disabled = false;
347
+ }
348
+ };
349
+
350
+ plan.onclick = async () => {
351
+ const p = params();
352
+ if (!p.org) {
353
+ out.replaceChildren(el("p", { className: "err", textContent: "Pick an organisation first." }));
354
+ return;
355
+ }
356
+ out.replaceChildren(el("p", { className: "sub", textContent: "Working…" }));
357
+ try {
358
+ const result = await planTenant(p);
359
+ const steps = el("ol", { className: "plansteps" }, [
360
+ el("li", { textContent: `Create a private repo, ${p.org}/roster-ops, to hold the org's shared settings.` }),
361
+ el("li", { textContent: `Put a copy of it in ${result.dir}.` }),
362
+ el("li", { textContent: `Let the other repos in ${p.org} run its workflow.` }),
363
+ ]);
364
+ const files = el("details", { className: "planfiles" }, [
365
+ el("summary", { textContent: `The ${result.files.length} files it writes` }),
366
+ el("div", { className: "filelist" }, result.files.map((f) => el("code", { textContent: f }))),
367
+ ]);
368
+ const next = el("p", {
369
+ className: "sub",
370
+ textContent: "After that: describe the business, set this month's priorities, and hire your first staff member.",
371
+ });
372
+ out.replaceChildren(el("p", { textContent: "Create it will:" }), steps, files, next);
373
+ go.hidden = false;
374
+ } catch (err) {
375
+ out.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
376
+ }
377
+ };
378
+
379
+ go.onclick = async () => {
380
+ go.disabled = plan.disabled = true;
381
+ out.replaceChildren(el("p", { className: "sub", textContent: "Creating…" }));
382
+ try {
383
+ const result = await createTenant(params());
384
+ out.replaceChildren(el("pre", { className: "cmd", textContent: result.output.trim() }));
385
+ if (result.ok) {
386
+ // render() draws the rest itself now that a tenant is on disk.
387
+ S = await getSetup();
388
+ render(main);
389
+ }
390
+ } catch (err) {
391
+ out.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
392
+ } finally {
393
+ go.disabled = plan.disabled = false;
394
+ }
395
+ };
396
+
397
+ return card;
398
+ }
399
+
400
+ /* ------------------------- 5 · the two GitHub insists on ------------------------- */
401
+
402
+ function afterCreate() {
403
+ fileSteps.clear();
404
+ const list = el("div", { className: "todos" });
405
+ const left = S.tenant.left ?? [];
406
+ const staffCount = App.data?.staff?.length ?? 0;
407
+ let n = 0;
408
+
409
+ if (S.tenant.org) {
410
+ const repos = todo(++n, "Choose the repos your staff work on", (S.tenant.products ?? []).length > 0);
411
+ repos.hint("Pick at least one. Staff open pull requests there, and you review them.");
412
+ repos.body.append(
413
+ repoPicker({ org: S.tenant.org, known: S.tenant.repos ?? [], bare: true, onAdded: () => repos.setDone(true) }),
414
+ );
415
+ list.append(repos.card);
416
+ }
417
+
418
+ const business = todo(++n, "Describe the business", !left.includes("business"));
419
+ business.hint("A few short answers. Every staff member reads them before they start work.");
420
+ business.body.append(
421
+ businessForm({
422
+ path: opsName() + "/org/business.md",
423
+ name: App.data?.name ?? S.tenant.name ?? S.tenant.org,
424
+ onSaved: () => (business.setDone(true), recheck()),
425
+ }),
426
+ );
427
+ fileSteps.set("business", business.setDone);
428
+ list.append(business.card);
429
+
430
+ const priorities = todo(++n, "Set this month's priorities", !left.includes("priorities"));
431
+ priorities.hint("Up to three, in order. Staff pick work that serves them.");
432
+ priorities.body.append(
433
+ prioritiesForm({
434
+ path: opsName() + "/org/priorities.md",
435
+ onSaved: () => (priorities.setDone(true), recheck()),
436
+ }),
437
+ );
438
+ fileSteps.set("priorities", priorities.setDone);
439
+ list.append(priorities.card);
440
+
441
+ const hire = todo(++n, "Hire your first staff member", staffCount > 0);
442
+ hire.hint("Pick a role. The Staff screen then lists each step to set them up.");
443
+ const hireBtn = el("button", { className: "btn primary", textContent: "Hire someone" });
444
+ hireBtn.onclick = () => {
445
+ // Before the org has loaded, this screen is the whole app, so the Staff screen needs a reload.
446
+ if (App.data) go({ view: "staff" });
447
+ else location.assign("/#/-/staff") || location.reload();
448
+ };
449
+ hire.body.append(el("div", { className: "row" }, [hireBtn]));
450
+ list.append(hire.card);
451
+
452
+ const cred = todo(++n, "Add your agent credential", false);
453
+ cred.hint(staffCount ? "Staff use it to run. You only add it once." : "Do this after your first hire.");
454
+ cred.body.append(credentialPanel({ bare: true, onStatus: (ok) => cred.setDone(ok) }));
455
+ list.append(cred.card);
456
+
457
+ const access = todo(++n, "Let staff repos use the shared workflow", false);
458
+ access.body.append(accessStep({ onStatus: (ok) => access.setDone(ok) }));
459
+ list.append(access.card);
460
+
461
+ return list;
462
+ }
463
+
464
+ /**
465
+ * One of the files only a person can write, with whether it is written yet.
466
+ *
467
+ * Read from the status rather than from the click that saved it, so a file written in an
468
+ * editor, or by a coding agent, shows as done here too.
469
+ */
470
+
471
+ /**
472
+ * org/priorities.md, edited in place.
473
+ *
474
+ * There is no brief for it, and it does not want one: business.md needs an interview because
475
+ * nobody can write it off the top of their head, while a ranked list of three things is
476
+ * quicker to type than to explain to a model. So the file opens as it is on disk, stub and
477
+ * all, and saving it is the same commit-and-push as every other editor here.
478
+ */
479
+
480
+
481
+
482
+
483
+
484
+
485
+ /** The ops repo's directory name, which is what every workspace-relative path starts with. */
486
+ function opsName() {
487
+ return App.data?.opsName ?? String(S.tenant.opsDir ?? "roster-ops").split("/").pop();
488
+ }
489
+
490
+ /**
491
+ * The ops repo's Actions access. Read on arrival, so a page reloaded after it was set says it
492
+ * is done without anybody pressing anything; the button asks the server to set it, and a
493
+ * refusal comes back with GitHub's reason and the page to click instead.
494
+ *
495
+ * Skipped, every workflow fails with "workflow not found", which reads like a typo in a path.
496
+ */
497
+ function accessStep(opts = {}) {
498
+ const box = el("div");
499
+ const out = el("div");
500
+ box.append(out);
501
+ const say = (text, cls) => el("p", { className: cls ?? "sub", textContent: text });
502
+
503
+ const offer = (why) => {
504
+ const go = el("button", { className: "btn primary", textContent: "Set it for me" });
505
+ out.replaceChildren(
506
+ say(
507
+ (why ? why + " " : "") +
508
+ "Roster tried to set this when it created the org, and GitHub didn't allow it.",
509
+ ),
510
+ el("div", { className: "row" }, [go]),
511
+ );
512
+ go.onclick = async () => {
513
+ go.disabled = true;
514
+ try {
515
+ const r = await setAccess();
516
+ if (r.ok) {
517
+ out.replaceChildren(say("Done."));
518
+ opts.onStatus?.(true);
519
+ return;
520
+ }
521
+ out.replaceChildren(
522
+ say("GitHub refused: " + r.error + ".", "err"),
523
+ el("a", { className: "btn", href: r.link, target: "_blank", textContent: "Set it by hand" }),
524
+ say("Access → “Accessible from repositories in the organisation”."),
525
+ );
526
+ } catch (err) {
527
+ out.replaceChildren(say(String(err.message || err), "err"));
528
+ go.disabled = false;
529
+ }
530
+ };
531
+ };
532
+
533
+ out.replaceChildren(say("Checking…"));
534
+ getAccess()
535
+ .then((r) => {
536
+ opts.onStatus?.(Boolean(r.ok));
537
+ if (r.ok) out.replaceChildren(say("Done."));
538
+ else offer(r.level ? "It is set to “" + r.level + "”." : "");
539
+ })
540
+ .catch(() => offer(""));
541
+ return box;
542
+ }
543
+
544
+ /* ---------------------------------- furniture ---------------------------------- */
545
+
546
+ function step(n, title, done) {
547
+ const card = el("section", { className: "step" + (done ? " done" : "") });
548
+ const head = el("div", { className: "stephead" });
549
+ head.append(
550
+ el("span", { className: "stepn", textContent: done ? "✓" : String(n) }),
551
+ el("h2", { textContent: title }),
552
+ );
553
+ card.append(head);
554
+ return card;
555
+ }
556
+
557
+ export { esc, toClipboard, $ };