@nanocollective/roster 0.1.0-beta.32 → 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.
Files changed (2) hide show
  1. package/dist/worker/index.js +147 -137
  2. package/package.json +1 -1
@@ -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.32",
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": {