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

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.
@@ -194,3 +194,6 @@
194
194
  .homesetupsteps{margin:0 0 4px;padding-left:20px;display:flex;flex-direction:column;gap:10px;font-size:13.5px}
195
195
  .homesetupsteps li > span{display:block;margin-bottom:5px}
196
196
  .homesetup .row{margin-top:10px}
197
+ .homesetup > .connline{margin:0 0 4px}
198
+ .homesetup .homesetupor{margin:14px 0 10px}
199
+ .homesetupsteps li > span .ghbtn{margin-left:6px;min-height:24px;padding:1px 10px;font-size:12px}
@@ -60,6 +60,12 @@ const STEP_COMMANDS = {
60
60
  "add the agent credential": () => "credential --apply",
61
61
  "run once": (h) => `run ${h} --apply`,
62
62
  };
63
+ /**
64
+ * The steps that are writing, not wiring: a hosted portal can do these itself (the org's two
65
+ * files on Org, the charter on Staff), so it offers that rather than a command.
66
+ */
67
+ export const IN_PORTAL = new Set(["business", "priorities", "write the charter"]);
68
+
63
69
  export function stepCommand(what, handle) {
64
70
  return STEP_COMMANDS[what]?.(handle) ?? "";
65
71
  }
@@ -296,7 +296,7 @@ export function hireFlow(o) {
296
296
  }
297
297
 
298
298
  /** Three ways to write CHARTER.md. The template is offered only when a worked example fits. */
299
- function charterModes(s, about, onSaved) {
299
+ export function charterModes(s, about, onSaved) {
300
300
  const box = el("div", {}, [el("p", { className: "sub", textContent: "Loading…" })]);
301
301
  const path = s.dir + "/CHARTER.md";
302
302
  getCharterExample(s.handle)
@@ -597,6 +597,9 @@ function team(staff) {
597
597
 
598
598
  /* ------------------------------- setup left ----------------------------- */
599
599
 
600
+ /** The org files a step is about, which can be written on the Org screen. */
601
+ const ORG_FILES = { business: "org/business.md", priorities: "org/priorities.md" };
602
+
600
603
  let readinessAsked = false;
601
604
 
602
605
  /**
@@ -612,33 +615,66 @@ function setupLeft(staff) {
612
615
  if (S.view === "home") render();
613
616
  });
614
617
  }
618
+ // Each step: what, its command, and where to do it here when it is writing rather than wiring.
615
619
  const steps = [];
616
- for (const id of S.data?.unfinished ?? []) if (ORG_STEPS[id]) steps.push(ORG_STEPS[id]);
620
+ for (const id of S.data?.unfinished ?? []) {
621
+ if (!ORG_STEPS[id]) continue;
622
+ const file = ORG_FILES[id];
623
+ const here = file
624
+ ? () => {
625
+ S.orgOpen = file;
626
+ go({ view: "org" });
627
+ }
628
+ : null;
629
+ steps.push([...ORG_STEPS[id], here]);
630
+ }
617
631
  for (const s of notReady()) {
618
632
  for (const what of S.readiness[s.handle]) {
619
- steps.push([`${s.name}: ${what}`, stepCommand(what, s.handle)]);
633
+ const here =
634
+ what === "write the charter"
635
+ ? () => {
636
+ S.writeCharter = s.handle;
637
+ go({ view: "staff" });
638
+ }
639
+ : null;
640
+ steps.push([`${s.name}: ${what}`, stepCommand(what, s.handle), here]);
620
641
  }
621
642
  }
622
643
  if (!steps.length) return null;
644
+ const wiring = steps.filter(([, , here]) => !here).length;
623
645
 
624
646
  const box = el("div", { className: "card homesetup" });
625
- box.append(
626
- el("b", { textContent: "Setup is not finished" }),
627
- el("p", {
628
- className: "sub",
629
- textContent: S.hosted
630
- ? "Nobody runs until these are done. They need your own machine: run each in your workspace, in order."
631
- : "Nobody runs until these are done.",
632
- }),
633
- );
647
+ box.append(el("b", { textContent: "Setup is not finished" }));
648
+ /* Hosted, writing is done here and wiring needs your machine. The portal there has every
649
+ wiring step as a button, which beats a list of commands, so it is offered first; the
650
+ commands stay for anyone who would rather not open it. */
651
+ if (S.hosted && wiring) {
652
+ box.append(
653
+ el("p", {
654
+ className: "sub",
655
+ textContent:
656
+ "Nobody runs until these are done. Writing can be done here. The rest needs your own machine, and the quickest way is the portal there, where each step is a button:",
657
+ }),
658
+ commandLine(`portal --org ${S.data.org}`),
659
+ el("p", { className: "sub homesetupor", textContent: "Or one at a time, in order:" }),
660
+ );
661
+ } else {
662
+ box.append(el("p", { className: "sub", textContent: "Nobody runs until these are done." }));
663
+ }
634
664
  const seen = new Set();
635
665
  const list = el("ol", { className: "homesetupsteps" });
636
- for (const [what, cmd] of steps) {
666
+ for (const [what, cmd, here] of steps) {
637
667
  // The credential is the org's, so two staff members missing it is one step.
638
668
  if (cmd && seen.has(cmd)) continue;
639
669
  seen.add(cmd);
640
- const row = el("li", {}, [el("span", { textContent: cap(what) })]);
641
- if (S.hosted && cmd) row.append(commandLine(cmd));
670
+ const label = el("span", { textContent: cap(what) });
671
+ const row = el("li", {}, [label]);
672
+ if (S.hosted && here) {
673
+ // Writing works from here, and with an AI interviewing you it beats a brief in a terminal.
674
+ const write = el("button", { className: "ghbtn sm", textContent: "Write it here" });
675
+ write.onclick = here;
676
+ label.append(" ", write);
677
+ } else if (S.hosted && cmd) row.append(commandLine(cmd));
642
678
  list.append(row);
643
679
  }
644
680
  box.append(list);
@@ -6,7 +6,7 @@
6
6
  * a hosted portal the command for each step, since setting up is only done on your machine. */
7
7
 
8
8
  import { el, toClipboard } from "../dom.js";
9
- import { canRun, ROSTER, sentence, stepCommand, whatsLeft } from "../readiness.js";
9
+ import { canRun, IN_PORTAL, ROSTER, sentence, stepCommand, whatsLeft } from "../readiness.js";
10
10
  import { go } from "../router.js";
11
11
  import { S } from "../state.js";
12
12
 
@@ -36,8 +36,18 @@ export function notReadyNote(s) {
36
36
  };
37
37
  box.append(el("div", { className: "row" }, [finish]));
38
38
  } else {
39
+ // The charter is writing, which works from here; the rest needs your machine.
40
+ if (left.includes("write the charter")) {
41
+ const write = el("button", { className: "ghbtn primary", textContent: "Write the charter" });
42
+ write.onclick = () => {
43
+ S.writeCharter = s.handle;
44
+ go({ view: "staff" });
45
+ };
46
+ box.append(el("div", { className: "row" }, [write]));
47
+ }
39
48
  const seen = new Set();
40
49
  for (const what of left) {
50
+ if (IN_PORTAL.has(what)) continue;
41
51
  const cmd = stepCommand(what, s.handle);
42
52
  if (!cmd || seen.has(cmd)) continue;
43
53
  seen.add(cmd);
@@ -9,10 +9,10 @@ import { post } from "../api.js";
9
9
  import { askYes, sheet } from "../dialog.js";
10
10
  import { pending } from "../inflight.js";
11
11
  import { ago, el, esc } from "../dom.js";
12
- import { sentence, staffProgress, stepCommand, whatsLeft } from "../readiness.js";
12
+ import { IN_PORTAL, sentence, staffProgress, stepCommand, whatsLeft } from "../readiness.js";
13
13
  import { refreshAll } from "../refresh.js";
14
14
  import { S } from "../state.js";
15
- import { hireFlow, line, rolePicker } from "./hire.js";
15
+ import { charterModes, hireFlow, line, rolePicker } from "./hire.js";
16
16
  import { commandLine } from "./notready.js";
17
17
 
18
18
  /**
@@ -93,6 +93,10 @@ export function viewStaff(m, o = {}) {
93
93
  else pane.replaceChildren();
94
94
  S.staffOpen = null;
95
95
  if (empty && !S.hosted) pick();
96
+ // Home's "Write it here" on a charter lands here with the dialog open.
97
+ const asked = S.writeCharter && S.data.staff.find((s) => s.handle === S.writeCharter);
98
+ S.writeCharter = null;
99
+ if (asked) writeCharter(asked);
96
100
  }
97
101
 
98
102
  // With nobody hired the roles are the page. After that they are a dialog behind Hire someone.
@@ -205,11 +209,20 @@ export function viewStaff(m, o = {}) {
205
209
  warn.textContent =
206
210
  "Not ready to run. " + (p ? `${p.done} of ${p.total} done. ` : "") +
207
211
  "Still to do: " + sentence(left) + ".";
208
- // Hosted has no Finish setting up, so each step comes with what to run instead.
212
+ /* Hosted has no Finish setting up. The charter is writing, which works from here; the
213
+ rest is wiring, which needs your machine, so each of those comes with its command. */
209
214
  if (S.hosted) {
210
- const cmds = [...new Set(left.map((x) => stepCommand(x, s.handle)).filter(Boolean))];
215
+ const cmds = [
216
+ ...new Set(left.filter((x) => !IN_PORTAL.has(x)).map((x) => stepCommand(x, s.handle)).filter(Boolean)),
217
+ ];
211
218
  warn.classList.add("notready");
212
- warn.replaceChildren(el("span", { textContent: warn.textContent }), ...cmds.map(commandLine));
219
+ warn.replaceChildren(el("span", { textContent: warn.textContent }));
220
+ if (left.includes("write the charter")) {
221
+ const write = el("button", { className: "ghbtn primary", textContent: "Write the charter" });
222
+ write.onclick = () => writeCharter(s);
223
+ warn.append(el("div", { className: "row" }, [write]));
224
+ }
225
+ warn.append(...cmds.map(commandLine));
213
226
  }
214
227
  });
215
228
  d.append(warn);
@@ -225,6 +238,18 @@ export function viewStaff(m, o = {}) {
225
238
 
226
239
  /* ------------------------------- retiring ------------------------------- */
227
240
 
241
+ /** The charter's three ways in, in the dialog: the same ones hiring offers. */
242
+ function writeCharter(s) {
243
+ const host = el("div", { className: "charterpane" }, [el("h2", { textContent: s.name + "'s charter" })]);
244
+ host.append(
245
+ charterModes(s, undefined, () => {
246
+ dismiss();
247
+ refreshAll();
248
+ }),
249
+ );
250
+ present(host);
251
+ }
252
+
228
253
  async function retireForm(host, s, cardStatus) {
229
254
  cardStatus.textContent = "planning…";
230
255
  cardStatus.className = "meta";
@@ -820,7 +820,7 @@ __export(compose_exports, {
820
820
  handlesList: () => handlesList,
821
821
  humanSentence: () => humanSentence,
822
822
  parseYaml: () => parseYaml,
823
- readHumans: () => readHumans2,
823
+ readHumans: () => readHumans,
824
824
  render: () => render
825
825
  });
826
826
  import * as nodeFs from "fs";
@@ -1008,7 +1008,7 @@ function lookup2(ctx, path) {
1008
1008
  function truthy(v) {
1009
1009
  return !(v === void 0 || v === null || v === false || v === "" || Array.isArray(v) && v.length === 0);
1010
1010
  }
1011
- function readHumans2(org) {
1011
+ function readHumans(org) {
1012
1012
  const listed = Array.isArray(org?.humans) ? org.humans : org?.humans ? [org.humans] : [];
1013
1013
  const out = [];
1014
1014
  for (const entry of [...listed, org?.human].filter(Boolean)) {
@@ -1019,15 +1019,15 @@ function readHumans2(org) {
1019
1019
  out.push({
1020
1020
  github,
1021
1021
  name: name || github,
1022
- marker: String(entry.marker ?? "").trim() || defaultMarker2(name || github),
1022
+ marker: String(entry.marker ?? "").trim() || defaultMarker(name || github),
1023
1023
  role: entry.role ?? void 0,
1024
- ...handlesOf2(entry.handles).length ? { handles: handlesOf2(entry.handles) } : {},
1024
+ ...handlesOf(entry.handles).length ? { handles: handlesOf(entry.handles) } : {},
1025
1025
  ...entry.view_only === true ? { viewOnly: true } : {}
1026
1026
  });
1027
1027
  }
1028
1028
  return out;
1029
1029
  }
1030
- function handlesOf2(v) {
1030
+ function handlesOf(v) {
1031
1031
  const list2 = Array.isArray(v) ? v : v ? String(v).split(",") : [];
1032
1032
  return list2.map((x) => String(x ?? "").trim()).filter(Boolean);
1033
1033
  }
@@ -1043,7 +1043,7 @@ function humanSentence(humans) {
1043
1043
  if (parts.length < 2) return parts[0] ?? "";
1044
1044
  return `${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1]}`;
1045
1045
  }
1046
- function defaultMarker2(name) {
1046
+ function defaultMarker(name) {
1047
1047
  return String(name).trim().split(/[\s-]+/)[0].toLowerCase().replace(/[^a-z0-9]/g, "") || "human";
1048
1048
  }
1049
1049
  function compose({
@@ -1101,7 +1101,7 @@ function compose({
1101
1101
  }
1102
1102
  const inflightFile = join3(runDir ?? join3(brainsDir, ".roster-run"), "inflight.md");
1103
1103
  const inflight = existsSync5(inflightFile) ? readFileSync6(inflightFile, "utf8").trim() : "";
1104
- const everyone = readHumans2(org);
1104
+ const everyone = readHumans(org);
1105
1105
  const humans = everyone.filter((h) => !h.viewOnly);
1106
1106
  const ctx = {
1107
1107
  org,
@@ -1301,123 +1301,6 @@ function splitRepo(repo) {
1301
1301
  return { owner, name };
1302
1302
  }
1303
1303
 
1304
- // src/lib/humans.ts
1305
- function readHumans(org) {
1306
- const listed = Array.isArray(org?.humans) ? org.humans : org?.humans ? [org.humans] : [];
1307
- const raw = [...listed, org?.human].filter(Boolean);
1308
- const out = [];
1309
- for (const entry of raw) {
1310
- const github = String(entry.github ?? entry.login ?? "").trim();
1311
- const name = String(entry.name ?? github).trim();
1312
- if (!github && !name) continue;
1313
- if (github && out.some((h) => h.github.toLowerCase() === github.toLowerCase())) continue;
1314
- out.push({
1315
- github,
1316
- name: name || github,
1317
- marker: String(entry.marker ?? "").trim() || defaultMarker(name || github),
1318
- role: entry.role === void 0 || entry.role === null ? void 0 : String(entry.role),
1319
- ...handlesOf(entry.handles).length ? { handles: handlesOf(entry.handles) } : {},
1320
- ...entry.view_only === true ? { viewOnly: true } : {}
1321
- });
1322
- }
1323
- return out;
1324
- }
1325
- function handlesOf(v) {
1326
- const list2 = Array.isArray(v) ? v : v ? String(v).split(",") : [];
1327
- return list2.map((x) => String(x ?? "").trim()).filter(Boolean);
1328
- }
1329
- function staffHumans(org) {
1330
- return readHumans(org).filter((h) => !h.viewOnly);
1331
- }
1332
- function isViewOnly(org, login) {
1333
- const l = login.toLowerCase();
1334
- return readHumans(org).some((h) => h.viewOnly && h.github.toLowerCase() === l);
1335
- }
1336
- function defaultMarker(name) {
1337
- return String(name).trim().split(/[\s-]+/)[0].toLowerCase().replace(/[^a-z0-9]/g, "") || "human";
1338
- }
1339
- var clean = (v) => String(v ?? "").replace(/[,{}[\]#"'\n\r]/g, " ").replace(/\s+/g, " ").trim();
1340
- var LOGIN_RE = /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i;
1341
- function tidyPeople(input) {
1342
- const people = [];
1343
- for (const p of input) {
1344
- const github = clean(p.github).replace(/^@/, "");
1345
- const name = clean(p.name) || github;
1346
- if (!github && !name) continue;
1347
- if (!LOGIN_RE.test(github))
1348
- return { people, error: `"${github || name}" is not a GitHub login` };
1349
- if (people.some((h) => h.github.toLowerCase() === github.toLowerCase())) {
1350
- return { people, error: `@${github} is in the list twice` };
1351
- }
1352
- const marker = (clean(p.marker) || defaultMarker(name || github)).toLowerCase().replace(/[^a-z0-9-]/g, "");
1353
- if (people.some((h) => h.marker === marker)) {
1354
- return {
1355
- people,
1356
- error: `two people would share the label "${marker}"; give one a different label`
1357
- };
1358
- }
1359
- const handles = (Array.isArray(p.handles) ? p.handles : String(p.handles ?? "").split(",")).map(clean).filter(Boolean);
1360
- people.push({
1361
- github,
1362
- name,
1363
- marker,
1364
- ...clean(p.role) ? { role: clean(p.role) } : {},
1365
- ...handles.length ? { handles } : {},
1366
- ...p.view_only === true ? { viewOnly: true } : {}
1367
- });
1368
- }
1369
- if (!people.some((h) => !h.viewOnly)) {
1370
- return {
1371
- people,
1372
- error: "someone has to be able to wake the staff: one person cannot be read-only"
1373
- };
1374
- }
1375
- return { people };
1376
- }
1377
- function writeHumans(text2, people) {
1378
- const lines = text2.split("\n");
1379
- const block = [
1380
- "humans:",
1381
- ...people.map((h) => {
1382
- const parts = [`name: ${h.name}`, `github: ${h.github}`, `marker: ${h.marker}`];
1383
- if (h.role) parts.push(`role: ${h.role}`);
1384
- if (h.handles?.length) parts.push(`handles: [${h.handles.join(", ")}]`);
1385
- if (h.viewOnly) parts.push("view_only: true");
1386
- return ` - { ${parts.join(", ")} }`;
1387
- })
1388
- ];
1389
- const out = [];
1390
- let at = -1;
1391
- for (let i = 0; i < lines.length; i++) {
1392
- if (/^humans?:/.test(lines[i])) {
1393
- if (at < 0) at = out.length;
1394
- while (i + 1 < lines.length) {
1395
- const next = lines[i + 1];
1396
- const more = /^\s+\S/.test(next) || /^\s*$/.test(next) && nextIsIndented(lines, i + 1);
1397
- if (!more) break;
1398
- i++;
1399
- }
1400
- continue;
1401
- }
1402
- out.push(lines[i]);
1403
- }
1404
- if (at < 0) {
1405
- const name = out.findIndex((l) => /^name:/.test(l));
1406
- at = name >= 0 ? name + 1 : out.length;
1407
- out.splice(at, 0, "");
1408
- at++;
1409
- }
1410
- out.splice(at, 0, ...block);
1411
- return out.join("\n");
1412
- }
1413
- function nextIsIndented(lines, from) {
1414
- for (let j = from; j < lines.length; j++) {
1415
- if (/^\s*$/.test(lines[j])) continue;
1416
- return /^\s+\S/.test(lines[j]);
1417
- }
1418
- return false;
1419
- }
1420
-
1421
1304
  // src/lib/archive.ts
1422
1305
  async function inflate(bytes, format) {
1423
1306
  try {
@@ -1881,7 +1764,16 @@ async function signedIn(req, url, cfg, doFetch = fetch) {
1881
1764
  }
1882
1765
  });
1883
1766
  const login = (await me.json().catch(() => ({}))).login ?? "";
1884
- if (!login || !await cfg.allowed(login, grant.access_token)) {
1767
+ const verdict = login ? await cfg.allowed(login, grant.access_token) : "no";
1768
+ if (verdict === "unknown") {
1769
+ await revoke(grant.access_token, cfg, doFetch);
1770
+ return page(
1771
+ 503,
1772
+ "GitHub did not answer",
1773
+ `<p>Signing in reads org.yaml from GitHub, and that did not work just now. Try again in a minute.</p><a class="back" href="/">Back to sign in</a>`
1774
+ );
1775
+ }
1776
+ if (verdict !== true && verdict !== "yes") {
1885
1777
  await revoke(grant.access_token, cfg, doFetch);
1886
1778
  return page(
1887
1779
  403,
@@ -3722,6 +3614,123 @@ ${bars}`;
3722
3614
  import { execFileSync as execFileSync2 } from "child_process";
3723
3615
  import { join as join13, relative as relative3 } from "path";
3724
3616
 
3617
+ // src/lib/humans.ts
3618
+ function readHumans2(org) {
3619
+ const listed = Array.isArray(org?.humans) ? org.humans : org?.humans ? [org.humans] : [];
3620
+ const raw = [...listed, org?.human].filter(Boolean);
3621
+ const out = [];
3622
+ for (const entry of raw) {
3623
+ const github = String(entry.github ?? entry.login ?? "").trim();
3624
+ const name = String(entry.name ?? github).trim();
3625
+ if (!github && !name) continue;
3626
+ if (github && out.some((h) => h.github.toLowerCase() === github.toLowerCase())) continue;
3627
+ out.push({
3628
+ github,
3629
+ name: name || github,
3630
+ marker: String(entry.marker ?? "").trim() || defaultMarker2(name || github),
3631
+ role: entry.role === void 0 || entry.role === null ? void 0 : String(entry.role),
3632
+ ...handlesOf2(entry.handles).length ? { handles: handlesOf2(entry.handles) } : {},
3633
+ ...entry.view_only === true ? { viewOnly: true } : {}
3634
+ });
3635
+ }
3636
+ return out;
3637
+ }
3638
+ function handlesOf2(v) {
3639
+ const list2 = Array.isArray(v) ? v : v ? String(v).split(",") : [];
3640
+ return list2.map((x) => String(x ?? "").trim()).filter(Boolean);
3641
+ }
3642
+ function staffHumans(org) {
3643
+ return readHumans2(org).filter((h) => !h.viewOnly);
3644
+ }
3645
+ function isViewOnly(org, login) {
3646
+ const l = login.toLowerCase();
3647
+ return readHumans2(org).some((h) => h.viewOnly && h.github.toLowerCase() === l);
3648
+ }
3649
+ function defaultMarker2(name) {
3650
+ return String(name).trim().split(/[\s-]+/)[0].toLowerCase().replace(/[^a-z0-9]/g, "") || "human";
3651
+ }
3652
+ var clean = (v) => String(v ?? "").replace(/[,{}[\]#"'\n\r]/g, " ").replace(/\s+/g, " ").trim();
3653
+ var LOGIN_RE = /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i;
3654
+ function tidyPeople(input) {
3655
+ const people = [];
3656
+ for (const p of input) {
3657
+ const github = clean(p.github).replace(/^@/, "");
3658
+ const name = clean(p.name) || github;
3659
+ if (!github && !name) continue;
3660
+ if (!LOGIN_RE.test(github))
3661
+ return { people, error: `"${github || name}" is not a GitHub login` };
3662
+ if (people.some((h) => h.github.toLowerCase() === github.toLowerCase())) {
3663
+ return { people, error: `@${github} is in the list twice` };
3664
+ }
3665
+ const marker = (clean(p.marker) || defaultMarker2(name || github)).toLowerCase().replace(/[^a-z0-9-]/g, "");
3666
+ if (people.some((h) => h.marker === marker)) {
3667
+ return {
3668
+ people,
3669
+ error: `two people would share the label "${marker}"; give one a different label`
3670
+ };
3671
+ }
3672
+ const handles = (Array.isArray(p.handles) ? p.handles : String(p.handles ?? "").split(",")).map(clean).filter(Boolean);
3673
+ people.push({
3674
+ github,
3675
+ name,
3676
+ marker,
3677
+ ...clean(p.role) ? { role: clean(p.role) } : {},
3678
+ ...handles.length ? { handles } : {},
3679
+ ...p.view_only === true ? { viewOnly: true } : {}
3680
+ });
3681
+ }
3682
+ if (!people.some((h) => !h.viewOnly)) {
3683
+ return {
3684
+ people,
3685
+ error: "someone has to be able to wake the staff: one person cannot be read-only"
3686
+ };
3687
+ }
3688
+ return { people };
3689
+ }
3690
+ function writeHumans(text2, people) {
3691
+ const lines = text2.split("\n");
3692
+ const block = [
3693
+ "humans:",
3694
+ ...people.map((h) => {
3695
+ const parts = [`name: ${h.name}`, `github: ${h.github}`, `marker: ${h.marker}`];
3696
+ if (h.role) parts.push(`role: ${h.role}`);
3697
+ if (h.handles?.length) parts.push(`handles: [${h.handles.join(", ")}]`);
3698
+ if (h.viewOnly) parts.push("view_only: true");
3699
+ return ` - { ${parts.join(", ")} }`;
3700
+ })
3701
+ ];
3702
+ const out = [];
3703
+ let at = -1;
3704
+ for (let i = 0; i < lines.length; i++) {
3705
+ if (/^humans?:/.test(lines[i])) {
3706
+ if (at < 0) at = out.length;
3707
+ while (i + 1 < lines.length) {
3708
+ const next = lines[i + 1];
3709
+ const more = /^\s+\S/.test(next) || /^\s*$/.test(next) && nextIsIndented(lines, i + 1);
3710
+ if (!more) break;
3711
+ i++;
3712
+ }
3713
+ continue;
3714
+ }
3715
+ out.push(lines[i]);
3716
+ }
3717
+ if (at < 0) {
3718
+ const name = out.findIndex((l) => /^name:/.test(l));
3719
+ at = name >= 0 ? name + 1 : out.length;
3720
+ out.splice(at, 0, "");
3721
+ at++;
3722
+ }
3723
+ out.splice(at, 0, ...block);
3724
+ return out.join("\n");
3725
+ }
3726
+ function nextIsIndented(lines, from) {
3727
+ for (let j = from; j < lines.length; j++) {
3728
+ if (/^\s*$/.test(lines[j])) continue;
3729
+ return /^\s+\S/.test(lines[j]);
3730
+ }
3731
+ return false;
3732
+ }
3733
+
3725
3734
  // src/lib/memory.ts
3726
3735
  import { join as join12 } from "path";
3727
3736
  var FACT_RE = /^- \*\*`([^`]+)`\*\*\s*·\s*(.*)$/;
@@ -4001,7 +4010,7 @@ function buildExport(ws, org, parseYaml3, opts = {}) {
4001
4010
  opsName: ws.opsName,
4002
4011
  human: humans[0] ?? org.human ?? {},
4003
4012
  humans,
4004
- people: readHumans(org),
4013
+ people: readHumans2(org),
4005
4014
  generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
4006
4015
  staff
4007
4016
  };
@@ -5372,12 +5381,13 @@ async function ready(c, opts = {}) {
5372
5381
  ]);
5373
5382
  return { org, brains, results: [{ dir: portal2.opsName, ...ops }, ...results] };
5374
5383
  }
5375
- async function readOrgFor(portal2, gh) {
5384
+ async function humanVerdict(portal2, gh, login) {
5376
5385
  const ops = await portal2.snapshots.refresh(gh, `${portal2.org}/${portal2.opsName}`, {
5377
5386
  force: true
5378
5387
  });
5379
- if (!ops.ok) return null;
5380
- return readOrg(portal2.ws.opsDir, parseYaml2);
5388
+ if (!ops.ok) return ops.status === 401 || ops.status === 404 ? "no" : "unknown";
5389
+ const org = readOrg(portal2.ws.opsDir, parseYaml2);
5390
+ return readHumans2(org).some((h) => h.github?.toLowerCase() === login.toLowerCase()) ? "yes" : "no";
5381
5391
  }
5382
5392
  var DOCS = /* @__PURE__ */ new Set(["/api/docs", "/api/docsearch", "/api/doc", "/api/docasset"]);
5383
5393
  var localLogin = null;
@@ -7734,16 +7744,16 @@ function clientFor2(token2) {
7734
7744
  }
7735
7745
  return gh;
7736
7746
  }
7737
- async function isHuman(p, login, token2) {
7738
- const org = await readOrgFor(p, clientFor2(token2));
7739
- if (!org) return false;
7740
- return readHumans(org).some((h) => h.github?.toLowerCase() === login.toLowerCase());
7741
- }
7747
+ var RETRY_MS = 3e4;
7742
7748
  async function stillHuman(p, login, token2) {
7743
7749
  const at = confirmed.get(login) ?? 0;
7744
7750
  if (Date.now() - at < RECHECK_MS) return true;
7745
- if (!await isHuman(p, login, token2)) return false;
7746
- confirmed.set(login, Date.now());
7751
+ const verdict = await humanVerdict(p, clientFor2(token2), login);
7752
+ if (verdict === "no") {
7753
+ confirmed.delete(login);
7754
+ return false;
7755
+ }
7756
+ confirmed.set(login, verdict === "yes" ? Date.now() : Date.now() - RECHECK_MS + RETRY_MS);
7747
7757
  return true;
7748
7758
  }
7749
7759
  var worker_default = {
@@ -7755,7 +7765,7 @@ var worker_default = {
7755
7765
  clientId: env.GITHUB_CLIENT_ID,
7756
7766
  clientSecret: env.GITHUB_CLIENT_SECRET,
7757
7767
  sessionKey: env.SESSION_KEY,
7758
- allowed: (login, token2) => isHuman(p, login, token2)
7768
+ allowed: (login, token2) => humanVerdict(p, clientFor2(token2), login)
7759
7769
  };
7760
7770
  if (path === "/auth/login") return startSignIn(url, auth);
7761
7771
  const name = env.ROSTER_NAME || env.ROSTER_ORG;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nanocollective/roster",
3
- "version": "0.1.0-beta.31",
3
+ "version": "0.1.0-beta.33",
4
4
  "description": "An agent-run org, powered by GitHub. Scaffold AI staff members whose brain is a repo.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -194,3 +194,6 @@
194
194
  .homesetupsteps{margin:0 0 4px;padding-left:20px;display:flex;flex-direction:column;gap:10px;font-size:13.5px}
195
195
  .homesetupsteps li > span{display:block;margin-bottom:5px}
196
196
  .homesetup .row{margin-top:10px}
197
+ .homesetup > .connline{margin:0 0 4px}
198
+ .homesetup .homesetupor{margin:14px 0 10px}
199
+ .homesetupsteps li > span .ghbtn{margin-left:6px;min-height:24px;padding:1px 10px;font-size:12px}
@@ -60,6 +60,12 @@ const STEP_COMMANDS = {
60
60
  "add the agent credential": () => "credential --apply",
61
61
  "run once": (h) => `run ${h} --apply`,
62
62
  };
63
+ /**
64
+ * The steps that are writing, not wiring: a hosted portal can do these itself (the org's two
65
+ * files on Org, the charter on Staff), so it offers that rather than a command.
66
+ */
67
+ export const IN_PORTAL = new Set(["business", "priorities", "write the charter"]);
68
+
63
69
  export function stepCommand(what, handle) {
64
70
  return STEP_COMMANDS[what]?.(handle) ?? "";
65
71
  }
@@ -296,7 +296,7 @@ export function hireFlow(o) {
296
296
  }
297
297
 
298
298
  /** Three ways to write CHARTER.md. The template is offered only when a worked example fits. */
299
- function charterModes(s, about, onSaved) {
299
+ export function charterModes(s, about, onSaved) {
300
300
  const box = el("div", {}, [el("p", { className: "sub", textContent: "Loading…" })]);
301
301
  const path = s.dir + "/CHARTER.md";
302
302
  getCharterExample(s.handle)
@@ -597,6 +597,9 @@ function team(staff) {
597
597
 
598
598
  /* ------------------------------- setup left ----------------------------- */
599
599
 
600
+ /** The org files a step is about, which can be written on the Org screen. */
601
+ const ORG_FILES = { business: "org/business.md", priorities: "org/priorities.md" };
602
+
600
603
  let readinessAsked = false;
601
604
 
602
605
  /**
@@ -612,33 +615,66 @@ function setupLeft(staff) {
612
615
  if (S.view === "home") render();
613
616
  });
614
617
  }
618
+ // Each step: what, its command, and where to do it here when it is writing rather than wiring.
615
619
  const steps = [];
616
- for (const id of S.data?.unfinished ?? []) if (ORG_STEPS[id]) steps.push(ORG_STEPS[id]);
620
+ for (const id of S.data?.unfinished ?? []) {
621
+ if (!ORG_STEPS[id]) continue;
622
+ const file = ORG_FILES[id];
623
+ const here = file
624
+ ? () => {
625
+ S.orgOpen = file;
626
+ go({ view: "org" });
627
+ }
628
+ : null;
629
+ steps.push([...ORG_STEPS[id], here]);
630
+ }
617
631
  for (const s of notReady()) {
618
632
  for (const what of S.readiness[s.handle]) {
619
- steps.push([`${s.name}: ${what}`, stepCommand(what, s.handle)]);
633
+ const here =
634
+ what === "write the charter"
635
+ ? () => {
636
+ S.writeCharter = s.handle;
637
+ go({ view: "staff" });
638
+ }
639
+ : null;
640
+ steps.push([`${s.name}: ${what}`, stepCommand(what, s.handle), here]);
620
641
  }
621
642
  }
622
643
  if (!steps.length) return null;
644
+ const wiring = steps.filter(([, , here]) => !here).length;
623
645
 
624
646
  const box = el("div", { className: "card homesetup" });
625
- box.append(
626
- el("b", { textContent: "Setup is not finished" }),
627
- el("p", {
628
- className: "sub",
629
- textContent: S.hosted
630
- ? "Nobody runs until these are done. They need your own machine: run each in your workspace, in order."
631
- : "Nobody runs until these are done.",
632
- }),
633
- );
647
+ box.append(el("b", { textContent: "Setup is not finished" }));
648
+ /* Hosted, writing is done here and wiring needs your machine. The portal there has every
649
+ wiring step as a button, which beats a list of commands, so it is offered first; the
650
+ commands stay for anyone who would rather not open it. */
651
+ if (S.hosted && wiring) {
652
+ box.append(
653
+ el("p", {
654
+ className: "sub",
655
+ textContent:
656
+ "Nobody runs until these are done. Writing can be done here. The rest needs your own machine, and the quickest way is the portal there, where each step is a button:",
657
+ }),
658
+ commandLine(`portal --org ${S.data.org}`),
659
+ el("p", { className: "sub homesetupor", textContent: "Or one at a time, in order:" }),
660
+ );
661
+ } else {
662
+ box.append(el("p", { className: "sub", textContent: "Nobody runs until these are done." }));
663
+ }
634
664
  const seen = new Set();
635
665
  const list = el("ol", { className: "homesetupsteps" });
636
- for (const [what, cmd] of steps) {
666
+ for (const [what, cmd, here] of steps) {
637
667
  // The credential is the org's, so two staff members missing it is one step.
638
668
  if (cmd && seen.has(cmd)) continue;
639
669
  seen.add(cmd);
640
- const row = el("li", {}, [el("span", { textContent: cap(what) })]);
641
- if (S.hosted && cmd) row.append(commandLine(cmd));
670
+ const label = el("span", { textContent: cap(what) });
671
+ const row = el("li", {}, [label]);
672
+ if (S.hosted && here) {
673
+ // Writing works from here, and with an AI interviewing you it beats a brief in a terminal.
674
+ const write = el("button", { className: "ghbtn sm", textContent: "Write it here" });
675
+ write.onclick = here;
676
+ label.append(" ", write);
677
+ } else if (S.hosted && cmd) row.append(commandLine(cmd));
642
678
  list.append(row);
643
679
  }
644
680
  box.append(list);
@@ -6,7 +6,7 @@
6
6
  * a hosted portal the command for each step, since setting up is only done on your machine. */
7
7
 
8
8
  import { el, toClipboard } from "../dom.js";
9
- import { canRun, ROSTER, sentence, stepCommand, whatsLeft } from "../readiness.js";
9
+ import { canRun, IN_PORTAL, ROSTER, sentence, stepCommand, whatsLeft } from "../readiness.js";
10
10
  import { go } from "../router.js";
11
11
  import { S } from "../state.js";
12
12
 
@@ -36,8 +36,18 @@ export function notReadyNote(s) {
36
36
  };
37
37
  box.append(el("div", { className: "row" }, [finish]));
38
38
  } else {
39
+ // The charter is writing, which works from here; the rest needs your machine.
40
+ if (left.includes("write the charter")) {
41
+ const write = el("button", { className: "ghbtn primary", textContent: "Write the charter" });
42
+ write.onclick = () => {
43
+ S.writeCharter = s.handle;
44
+ go({ view: "staff" });
45
+ };
46
+ box.append(el("div", { className: "row" }, [write]));
47
+ }
39
48
  const seen = new Set();
40
49
  for (const what of left) {
50
+ if (IN_PORTAL.has(what)) continue;
41
51
  const cmd = stepCommand(what, s.handle);
42
52
  if (!cmd || seen.has(cmd)) continue;
43
53
  seen.add(cmd);
@@ -9,10 +9,10 @@ import { post } from "../api.js";
9
9
  import { askYes, sheet } from "../dialog.js";
10
10
  import { pending } from "../inflight.js";
11
11
  import { ago, el, esc } from "../dom.js";
12
- import { sentence, staffProgress, stepCommand, whatsLeft } from "../readiness.js";
12
+ import { IN_PORTAL, sentence, staffProgress, stepCommand, whatsLeft } from "../readiness.js";
13
13
  import { refreshAll } from "../refresh.js";
14
14
  import { S } from "../state.js";
15
- import { hireFlow, line, rolePicker } from "./hire.js";
15
+ import { charterModes, hireFlow, line, rolePicker } from "./hire.js";
16
16
  import { commandLine } from "./notready.js";
17
17
 
18
18
  /**
@@ -93,6 +93,10 @@ export function viewStaff(m, o = {}) {
93
93
  else pane.replaceChildren();
94
94
  S.staffOpen = null;
95
95
  if (empty && !S.hosted) pick();
96
+ // Home's "Write it here" on a charter lands here with the dialog open.
97
+ const asked = S.writeCharter && S.data.staff.find((s) => s.handle === S.writeCharter);
98
+ S.writeCharter = null;
99
+ if (asked) writeCharter(asked);
96
100
  }
97
101
 
98
102
  // With nobody hired the roles are the page. After that they are a dialog behind Hire someone.
@@ -205,11 +209,20 @@ export function viewStaff(m, o = {}) {
205
209
  warn.textContent =
206
210
  "Not ready to run. " + (p ? `${p.done} of ${p.total} done. ` : "") +
207
211
  "Still to do: " + sentence(left) + ".";
208
- // Hosted has no Finish setting up, so each step comes with what to run instead.
212
+ /* Hosted has no Finish setting up. The charter is writing, which works from here; the
213
+ rest is wiring, which needs your machine, so each of those comes with its command. */
209
214
  if (S.hosted) {
210
- const cmds = [...new Set(left.map((x) => stepCommand(x, s.handle)).filter(Boolean))];
215
+ const cmds = [
216
+ ...new Set(left.filter((x) => !IN_PORTAL.has(x)).map((x) => stepCommand(x, s.handle)).filter(Boolean)),
217
+ ];
211
218
  warn.classList.add("notready");
212
- warn.replaceChildren(el("span", { textContent: warn.textContent }), ...cmds.map(commandLine));
219
+ warn.replaceChildren(el("span", { textContent: warn.textContent }));
220
+ if (left.includes("write the charter")) {
221
+ const write = el("button", { className: "ghbtn primary", textContent: "Write the charter" });
222
+ write.onclick = () => writeCharter(s);
223
+ warn.append(el("div", { className: "row" }, [write]));
224
+ }
225
+ warn.append(...cmds.map(commandLine));
213
226
  }
214
227
  });
215
228
  d.append(warn);
@@ -225,6 +238,18 @@ export function viewStaff(m, o = {}) {
225
238
 
226
239
  /* ------------------------------- retiring ------------------------------- */
227
240
 
241
+ /** The charter's three ways in, in the dialog: the same ones hiring offers. */
242
+ function writeCharter(s) {
243
+ const host = el("div", { className: "charterpane" }, [el("h2", { textContent: s.name + "'s charter" })]);
244
+ host.append(
245
+ charterModes(s, undefined, () => {
246
+ dismiss();
247
+ refreshAll();
248
+ }),
249
+ );
250
+ present(host);
251
+ }
252
+
228
253
  async function retireForm(host, s, cardStatus) {
229
254
  cardStatus.textContent = "planning…";
230
255
  cardStatus.className = "meta";