@nanocollective/roster 0.1.0-beta.24 → 0.1.0-beta.25

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.
package/dist/cli.js CHANGED
@@ -3763,11 +3763,76 @@ function parseFlags5(argv) {
3763
3763
  // src/commands/deploy.ts
3764
3764
  import { spawn as spawn2 } from "child_process";
3765
3765
  import { randomBytes as randomBytes2 } from "crypto";
3766
- import { existsSync as existsSync6, mkdirSync as mkdirSync3, mkdtempSync as mkdtempSync2, readFileSync as readFileSync7, rmSync as rmSync2, writeFileSync as writeFileSync5 } from "fs";
3766
+ import {
3767
+ copyFileSync,
3768
+ cpSync,
3769
+ existsSync as existsSync7,
3770
+ mkdirSync as mkdirSync3,
3771
+ mkdtempSync as mkdtempSync2,
3772
+ readFileSync as readFileSync8,
3773
+ rmSync as rmSync2,
3774
+ writeFileSync as writeFileSync5
3775
+ } from "fs";
3767
3776
  import { tmpdir as tmpdir2 } from "os";
3768
- import { dirname as dirname6, join as join16 } from "path";
3777
+ import { dirname as dirname7, extname as extname2, join as join17 } from "path";
3769
3778
  import { createInterface } from "readline/promises";
3779
+ import { fileURLToPath as fileURLToPath4 } from "url";
3780
+
3781
+ // src/portal/assets.ts
3782
+ import { existsSync as existsSync6, readFileSync as readFileSync7, statSync as statSync3 } from "fs";
3783
+ import { dirname as dirname6, extname, join as join16, resolve as resolve3 } from "path";
3770
3784
  import { fileURLToPath as fileURLToPath3 } from "url";
3785
+ function portalDir() {
3786
+ const fixed = frameworkRoot();
3787
+ if (fixed) return join16(fixed, "templates", "portal");
3788
+ const here = dirname6(fileURLToPath3(import.meta.url));
3789
+ const candidates = [
3790
+ join16(here, "..", "..", "templates", "portal"),
3791
+ // src/portal → package root
3792
+ join16(here, "..", "templates", "portal")
3793
+ // dist → package root
3794
+ ];
3795
+ for (const path of candidates) if (existsSync6(join16(path, "index.html"))) return path;
3796
+ throw new Error(`portal UI not found. Looked in:
3797
+ ${candidates.join("\n ")}`);
3798
+ }
3799
+ function portalIndex() {
3800
+ return readFileSync7(join16(portalDir(), "index.html"), "utf8");
3801
+ }
3802
+ var ASSET_MIME = {
3803
+ ".css": "text/css; charset=utf-8",
3804
+ ".js": "text/javascript; charset=utf-8",
3805
+ ".mjs": "text/javascript; charset=utf-8",
3806
+ ".svg": "image/svg+xml",
3807
+ ".png": "image/png",
3808
+ ".jpg": "image/jpeg",
3809
+ ".webp": "image/webp",
3810
+ ".woff2": "font/woff2"
3811
+ };
3812
+ function portalAsset(rel) {
3813
+ const root2 = portalDir();
3814
+ const full = resolve3(root2, rel);
3815
+ if (!inside(resolve3(root2), full)) return null;
3816
+ const type = ASSET_MIME[extname(full).toLowerCase()];
3817
+ if (!type) return null;
3818
+ if (!existsSync6(full) || statSync3(full).isDirectory()) return null;
3819
+ return { body: readFileSync7(full), type };
3820
+ }
3821
+ var ICON_FILES = [
3822
+ "portal/icon.svg",
3823
+ "portal/icon.png",
3824
+ "portal/icon.jpg",
3825
+ "portal/icon.webp"
3826
+ ];
3827
+ function orgIcon(opsDir) {
3828
+ for (const rel of ICON_FILES) {
3829
+ const path = join16(opsDir, rel);
3830
+ if (existsSync6(path)) return { path, rel, type: ASSET_MIME[extname(rel)] };
3831
+ }
3832
+ return null;
3833
+ }
3834
+
3835
+ // src/commands/deploy.ts
3771
3836
  var deployHelp = `
3772
3837
  roster portal deploy [--domain <host>] [--apply]
3773
3838
 
@@ -3801,11 +3866,11 @@ async function deployCommand(argv) {
3801
3866
  const ws = findWorkspace(opts.ops);
3802
3867
  const { parseYaml: parseYaml3 } = await loadComposer(ws.opsDir);
3803
3868
  const org = readOrg(ws.opsDir, parseYaml3);
3804
- const configPath = join16(ws.opsDir, CONFIG);
3805
- const exists = existsSync6(configPath);
3869
+ const configPath = join17(ws.opsDir, CONFIG);
3870
+ const exists = existsSync7(configPath);
3806
3871
  let config;
3807
3872
  if (exists) {
3808
- config = parseJsonc(readFileSync7(configPath, "utf8"));
3873
+ config = parseJsonc(readFileSync8(configPath, "utf8"));
3809
3874
  if (opts.domain && opts.domain !== domainOf(config)) {
3810
3875
  config.routes = [{ pattern: opts.domain, custom_domain: true }];
3811
3876
  }
@@ -3821,6 +3886,7 @@ async function deployCommand(argv) {
3821
3886
  if (opts.account) config.account_id = opts.account;
3822
3887
  if (!config.vars.ROSTER_NAME) config.vars.ROSTER_NAME = String(org.name ?? org.org);
3823
3888
  const domain = domainOf(config);
3889
+ const icon = orgIcon(ws.opsDir);
3824
3890
  process.stdout.write(
3825
3891
  `
3826
3892
  roster portal deploy \u2014 ${org.name ?? org.org}
@@ -3828,7 +3894,8 @@ async function deployCommand(argv) {
3828
3894
  serves https://${domain}, on the Worker "${config.name}"
3829
3895
  ` + (config.account_id ? ` account ${config.account_id}
3830
3896
  ` : "") + ` signs in the humans in org.yaml, with GitHub
3831
- ` + (exists ? "" : ` writes ${ws.opsName}/${CONFIG} and ${ws.opsName}/${WORKFLOW}
3897
+ ` + (icon ? ` icon ${ws.opsName}/${icon.rel}
3898
+ ` : "") + (exists ? "" : ` writes ${ws.opsName}/${CONFIG} and ${ws.opsName}/${WORKFLOW}
3832
3899
  `) + (config.vars.GITHUB_CLIENT_ID ? "" : " asks for the portal's GitHub OAuth App (a three-field form)\n") + (hasConnectorStore(config) ? "" : " binds a KV namespace for connectors that sign in, such as Notion\n") + ` deploys with ${WRANGLER}, as whoever wrangler is signed in as
3833
3900
 
3834
3901
  `
@@ -3857,24 +3924,32 @@ async function deployCommand(argv) {
3857
3924
  secrets.GITHUB_CLIENT_SECRET = app.secret;
3858
3925
  secrets.SESSION_KEY = randomBytes2(32).toString("base64");
3859
3926
  }
3860
- const tmp = mkdtempSync2(join16(tmpdir2(), "roster-deploy-"));
3927
+ const tmp = mkdtempSync2(join17(tmpdir2(), "roster-deploy-"));
3861
3928
  try {
3862
3929
  const full = {
3863
3930
  ...config,
3864
3931
  main: bundle.main,
3865
3932
  assets: { ...config.assets, directory: bundle.assets }
3866
3933
  };
3867
- writeFileSync5(join16(tmp, "wrangler.json"), JSON.stringify(full, null, 2));
3934
+ if (icon) {
3935
+ const assets = join17(tmp, "assets");
3936
+ cpSync(bundle.assets, assets, { recursive: true });
3937
+ const served = `/org-icon${extname2(icon.rel)}`;
3938
+ copyFileSync(icon.path, join17(assets, served));
3939
+ full.assets = { ...config.assets, directory: assets };
3940
+ full.vars = { ...config.vars, ROSTER_ICON: served };
3941
+ }
3942
+ writeFileSync5(join17(tmp, "wrangler.json"), JSON.stringify(full, null, 2));
3868
3943
  if (!hasConnectorStore(config)) {
3869
3944
  process.stdout.write(" finding the KV namespace for signed-in connectors\u2026\n");
3870
- const id = await namespaceFor(`${config.name}-connectors`, join16(tmp, "wrangler.json"));
3945
+ const id = await namespaceFor(`${config.name}-connectors`, join17(tmp, "wrangler.json"));
3871
3946
  if (id) {
3872
3947
  config.kv_namespaces = [
3873
3948
  ...config.kv_namespaces ?? [],
3874
3949
  { binding: "CONNECTORS", id }
3875
3950
  ];
3876
3951
  full.kv_namespaces = config.kv_namespaces;
3877
- writeFileSync5(join16(tmp, "wrangler.json"), JSON.stringify(full, null, 2));
3952
+ writeFileSync5(join17(tmp, "wrangler.json"), JSON.stringify(full, null, 2));
3878
3953
  } else {
3879
3954
  process.stdout.write(
3880
3955
  " could not create it, so connectors that sign in are not offered yet. Run this again later.\n"
@@ -3882,15 +3957,15 @@ async function deployCommand(argv) {
3882
3957
  }
3883
3958
  }
3884
3959
  process.stdout.write(" deploying\u2026\n");
3885
- if (await wrangler(["deploy", "--config", join16(tmp, "wrangler.json")]) !== 0) {
3960
+ if (await wrangler(["deploy", "--config", join17(tmp, "wrangler.json")]) !== 0) {
3886
3961
  process.stderr.write("roster: wrangler could not deploy. Its own message is above.\n");
3887
3962
  return 1;
3888
3963
  }
3889
3964
  if (Object.keys(secrets).length) {
3890
- const file = join16(tmp, "secrets.json");
3965
+ const file = join17(tmp, "secrets.json");
3891
3966
  writeFileSync5(file, JSON.stringify(secrets), { mode: 384 });
3892
3967
  process.stdout.write(" storing the App's secret and a session key on the Worker\u2026\n");
3893
- if (await wrangler(["secret", "bulk", file, "--config", join16(tmp, "wrangler.json")]) !== 0) {
3968
+ if (await wrangler(["secret", "bulk", file, "--config", join17(tmp, "wrangler.json")]) !== 0) {
3894
3969
  process.stderr.write("roster: the secrets were not stored. Run this again.\n");
3895
3970
  return 1;
3896
3971
  }
@@ -3899,11 +3974,11 @@ async function deployCommand(argv) {
3899
3974
  rmSync2(tmp, { recursive: true, force: true });
3900
3975
  }
3901
3976
  if (!opts.ci) {
3902
- mkdirSync3(dirname6(configPath), { recursive: true });
3977
+ mkdirSync3(dirname7(configPath), { recursive: true });
3903
3978
  writeFileSync5(configPath, renderConfig(config));
3904
- const workflow = join16(ws.opsDir, WORKFLOW);
3905
- if (!existsSync6(workflow)) {
3906
- mkdirSync3(dirname6(workflow), { recursive: true });
3979
+ const workflow = join17(ws.opsDir, WORKFLOW);
3980
+ if (!existsSync7(workflow)) {
3981
+ mkdirSync3(dirname7(workflow), { recursive: true });
3907
3982
  writeFileSync5(workflow, WORKFLOW_TEXT);
3908
3983
  }
3909
3984
  const done = commitAndPush(ws.opsDir, [CONFIG, WORKFLOW], "roster: the hosted portal");
@@ -4011,10 +4086,10 @@ function parseJsonc(text2) {
4011
4086
  return JSON.parse(text2.replace(/^\s*\/\/.*$/gm, ""));
4012
4087
  }
4013
4088
  function workerBundle() {
4014
- const here = dirname6(fileURLToPath3(import.meta.url));
4015
- for (const dist of [here, join16(here, "..", "..", "dist")]) {
4016
- const main2 = join16(dist, "worker", "index.js");
4017
- if (existsSync6(main2)) return { main: main2, assets: join16(dist, "worker", "assets") };
4089
+ const here = dirname7(fileURLToPath4(import.meta.url));
4090
+ for (const dist of [here, join17(here, "..", "..", "dist")]) {
4091
+ const main2 = join17(dist, "worker", "index.js");
4092
+ if (existsSync7(main2)) return { main: main2, assets: join17(dist, "worker", "assets") };
4018
4093
  }
4019
4094
  return null;
4020
4095
  }
@@ -4106,8 +4181,8 @@ function parseFlags6(argv) {
4106
4181
  }
4107
4182
 
4108
4183
  // src/commands/doctor.ts
4109
- import { existsSync as existsSync8, readdirSync as readdirSync5, readFileSync as readFileSync9 } from "fs";
4110
- import { join as join20 } from "path";
4184
+ import { existsSync as existsSync9, readdirSync as readdirSync5, readFileSync as readFileSync10 } from "fs";
4185
+ import { join as join21 } from "path";
4111
4186
  import { pathToFileURL as pathToFileURL3 } from "url";
4112
4187
 
4113
4188
  // src/lib/callable.ts
@@ -4133,13 +4208,13 @@ function refusal(res) {
4133
4208
  }
4134
4209
 
4135
4210
  // src/lib/memory.ts
4136
- import { join as join17 } from "path";
4211
+ import { join as join18 } from "path";
4137
4212
  var FACT_RE = /^- \*\*`([^`]+)`\*\*\s*·\s*(.*)$/;
4138
4213
  var PROVENANCE_RE = /^\[([a-z][a-z0-9-]*)\]\s*/;
4139
4214
  var NOTE_RE = /\s*·?\s*\[note\]\(([^)]+)\)\s*$/;
4140
4215
  var SO_RE = /\*\*So:\*\*\s*/;
4141
4216
  function parseMemory(dir) {
4142
- const indexPath = join17(dir, "INDEX.md");
4217
+ const indexPath = join18(dir, "INDEX.md");
4143
4218
  if (!existsSync2(indexPath)) throw new Error(`no memory index at ${indexPath}`);
4144
4219
  const lines = readFileSync2(indexPath, "utf8").split("\n");
4145
4220
  const facts2 = [];
@@ -4186,7 +4261,7 @@ function parseMemory(dir) {
4186
4261
  raw
4187
4262
  });
4188
4263
  });
4189
- const notesDir = join17(dir, "notes");
4264
+ const notesDir = join18(dir, "notes");
4190
4265
  const notes = existsSync2(notesDir) ? readdirSync2(notesDir).filter((f) => f.endsWith(".md")).sort() : [];
4191
4266
  return {
4192
4267
  facts: facts2,
@@ -4220,7 +4295,7 @@ function extractLinks(facts2, notes, dir) {
4220
4295
  scan(f.slug, f.raw);
4221
4296
  }
4222
4297
  for (const note of notes) {
4223
- const path = join17(dir, "notes", note);
4298
+ const path = join18(dir, "notes", note);
4224
4299
  if (!existsSync2(path)) continue;
4225
4300
  scan(note, readFileSync2(path, "utf8"));
4226
4301
  }
@@ -4271,7 +4346,7 @@ function lintMemory(doc, dir, budgets = DEFAULT_BUDGETS) {
4271
4346
  }
4272
4347
  if (f.note) {
4273
4348
  linked.add(f.note.replace(/^notes\//, ""));
4274
- if (!existsSync2(join17(dir, f.note))) {
4349
+ if (!existsSync2(join18(dir, f.note))) {
4275
4350
  problems.push({
4276
4351
  level: "error",
4277
4352
  rule: "dangling-note",
@@ -4332,7 +4407,7 @@ function lintMemory(doc, dir, budgets = DEFAULT_BUDGETS) {
4332
4407
  function overBudget(doc, dir, budgets) {
4333
4408
  const out = [];
4334
4409
  const kb = (bytes2) => Math.round(bytes2 / 1024);
4335
- const index = join17(dir, "INDEX.md");
4410
+ const index = join18(dir, "INDEX.md");
4336
4411
  const indexBytes = existsSync2(index) ? statSync2(index).size : 0;
4337
4412
  if (indexBytes > budgets.indexKb * 1024) {
4338
4413
  const longest = [...doc.facts].sort((a, b) => b.raw.length - a.raw.length).slice(0, 3).map((f) => `\`${f.slug}\` (${f.raw.length})`);
@@ -4343,7 +4418,7 @@ function overBudget(doc, dir, budgets) {
4343
4418
  file: "memory/INDEX.md"
4344
4419
  });
4345
4420
  }
4346
- const log = join17(dir, "..", "log", "decisions.md");
4421
+ const log = join18(dir, "..", "log", "decisions.md");
4347
4422
  const logBytes = existsSync2(log) ? statSync2(log).size : 0;
4348
4423
  if (logBytes > budgets.decisionsKb * 1024) {
4349
4424
  out.push({
@@ -4619,28 +4694,28 @@ function budgetOf(value) {
4619
4694
  // src/commands/upgrade.ts
4620
4695
  import { execFileSync as execFileSync5 } from "child_process";
4621
4696
  import {
4622
- existsSync as existsSync7,
4697
+ existsSync as existsSync8,
4623
4698
  mkdirSync as mkdirSync4,
4624
4699
  mkdtempSync as mkdtempSync4,
4625
4700
  readdirSync as readdirSync4,
4626
- readFileSync as readFileSync8,
4701
+ readFileSync as readFileSync9,
4627
4702
  rmSync as rmSync4,
4628
4703
  writeFileSync as writeFileSync7
4629
4704
  } from "fs";
4630
4705
  import { tmpdir as tmpdir4 } from "os";
4631
- import { dirname as dirname7, join as join19 } from "path";
4706
+ import { dirname as dirname8, join as join20 } from "path";
4632
4707
 
4633
4708
  // src/lib/merge.ts
4634
4709
  import { execFileSync as execFileSync4 } from "child_process";
4635
4710
  import { mkdtempSync as mkdtempSync3, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "fs";
4636
4711
  import { tmpdir as tmpdir3 } from "os";
4637
- import { join as join18 } from "path";
4712
+ import { join as join19 } from "path";
4638
4713
  function merge3(current, base2, incoming) {
4639
- const dir = mkdtempSync3(join18(tmpdir3(), "roster-merge-"));
4714
+ const dir = mkdtempSync3(join19(tmpdir3(), "roster-merge-"));
4640
4715
  try {
4641
- const c = join18(dir, "current");
4642
- const b = join18(dir, "base");
4643
- const i = join18(dir, "incoming");
4716
+ const c = join19(dir, "current");
4717
+ const b = join19(dir, "base");
4718
+ const i = join19(dir, "incoming");
4644
4719
  writeFileSync6(c, current);
4645
4720
  writeFileSync6(b, base2);
4646
4721
  writeFileSync6(i, incoming);
@@ -4713,7 +4788,7 @@ async function upgradeCommand(argv) {
4713
4788
  const ws = findWorkspace(opts.ops);
4714
4789
  const { parseYaml: parseYaml3 } = await loadComposer(ws.opsDir);
4715
4790
  const tplDir = opsTemplateDir();
4716
- const seedDir = join19(ws.opsDir, ".roster", "seed");
4791
+ const seedDir = join20(ws.opsDir, ".roster", "seed");
4717
4792
  if (opts.baseline) {
4718
4793
  return writeBaseline(ws.opsDir, seedDir, tplDir, opts.baseline);
4719
4794
  }
@@ -4744,12 +4819,12 @@ function planAll(tplDir, seedDir, opsDir) {
4744
4819
  }
4745
4820
  function plan(rel, tplDir, seedDir, opsDir) {
4746
4821
  const kind = classify(rel);
4747
- const incoming = readFileSync8(join19(tplDir, rel), "utf8");
4748
- const currentPath = join19(opsDir, rel);
4749
- const basePath = join19(seedDir, rel);
4750
- const has = (p) => existsSync7(p);
4751
- const current = has(currentPath) ? readFileSync8(currentPath, "utf8") : null;
4752
- const base2 = has(basePath) ? readFileSync8(basePath, "utf8") : null;
4822
+ const incoming = readFileSync9(join20(tplDir, rel), "utf8");
4823
+ const currentPath = join20(opsDir, rel);
4824
+ const basePath = join20(seedDir, rel);
4825
+ const has = (p) => existsSync8(p);
4826
+ const current = has(currentPath) ? readFileSync9(currentPath, "utf8") : null;
4827
+ const base2 = has(basePath) ? readFileSync9(basePath, "utf8") : null;
4753
4828
  if (current === null) {
4754
4829
  return { rel, kind, verdict: "added", note: "new in the framework", next: incoming };
4755
4830
  }
@@ -4851,8 +4926,8 @@ function apply(opsDir, seedDir, tplDir, plans) {
4851
4926
  for (const p of plans) {
4852
4927
  if (p.verdict === "edited-managed") edited++;
4853
4928
  if (p.verdict === "conflict") {
4854
- const out = join19(opsDir, p.rel + ".roster-merge");
4855
- mkdirSync4(dirname7(out), { recursive: true });
4929
+ const out = join20(opsDir, p.rel + ".roster-merge");
4930
+ mkdirSync4(dirname8(out), { recursive: true });
4856
4931
  writeFileSync7(out, p.rejected);
4857
4932
  process.stdout.write(` wrote ${p.rel}.roster-merge \u2014 resolve it, then re-run
4858
4933
  `);
@@ -4867,8 +4942,8 @@ function apply(opsDir, seedDir, tplDir, plans) {
4867
4942
  if (p.verdict === "same") seed(seedDir, tplDir, p.rel);
4868
4943
  continue;
4869
4944
  }
4870
- const dest = join19(opsDir, p.rel);
4871
- mkdirSync4(dirname7(dest), { recursive: true });
4945
+ const dest = join20(opsDir, p.rel);
4946
+ mkdirSync4(dirname8(dest), { recursive: true });
4872
4947
  writeFileSync7(dest, p.next);
4873
4948
  seed(seedDir, tplDir, p.rel);
4874
4949
  wrote++;
@@ -4878,7 +4953,7 @@ function apply(opsDir, seedDir, tplDir, plans) {
4878
4953
  process.stdout.write(left ? `, ${left} left for you
4879
4954
 
4880
4955
  ` : "\n\n");
4881
- if (!left) writeFileSync7(join19(opsDir, ".roster-version"), stamp() + "\n");
4956
+ if (!left) writeFileSync7(join20(opsDir, ".roster-version"), stamp() + "\n");
4882
4957
  if (edited) {
4883
4958
  process.stdout.write(
4884
4959
  ` ${edited} framework file${edited === 1 ? "" : "s"} still carr${edited === 1 ? "ies" : "y"} a local edit. Move it into the framework, or doctor keeps failing.
@@ -4889,12 +4964,12 @@ function apply(opsDir, seedDir, tplDir, plans) {
4889
4964
  return left || edited ? 1 : 0;
4890
4965
  }
4891
4966
  function seed(seedDir, tplDir, rel) {
4892
- const dest = join19(seedDir, rel);
4893
- mkdirSync4(dirname7(dest), { recursive: true });
4894
- writeFileSync7(dest, readFileSync8(join19(tplDir, rel), "utf8"));
4967
+ const dest = join20(seedDir, rel);
4968
+ mkdirSync4(dirname8(dest), { recursive: true });
4969
+ writeFileSync7(dest, readFileSync9(join20(tplDir, rel), "utf8"));
4895
4970
  }
4896
4971
  function writeBaseline(opsDir, seedDir, tplDir, ref) {
4897
- const framework = join19(tplDir, "..", "..");
4972
+ const framework = join20(tplDir, "..", "..");
4898
4973
  let files;
4899
4974
  try {
4900
4975
  files = execFileSync5(
@@ -4915,16 +4990,16 @@ function writeBaseline(opsDir, seedDir, tplDir, ref) {
4915
4990
  encoding: "utf8",
4916
4991
  maxBuffer: 16 * 1024 * 1024
4917
4992
  });
4918
- const dest = join19(seedDir, rel);
4919
- mkdirSync4(dirname7(dest), { recursive: true });
4993
+ const dest = join20(seedDir, rel);
4994
+ mkdirSync4(dirname8(dest), { recursive: true });
4920
4995
  writeFileSync7(dest, text2);
4921
4996
  }
4922
- writeFileSync7(join19(opsDir, ".roster-version"), `${ref}
4997
+ writeFileSync7(join20(opsDir, ".roster-version"), `${ref}
4923
4998
  `);
4924
4999
  process.stdout.write(
4925
5000
  `
4926
5001
  Recorded ${files.length} files as the base, from the framework at ${ref}.
4927
- Written to ${join19(opsDir, ".roster", "seed")} \u2014 commit it; it is what makes the next
5002
+ Written to ${join20(opsDir, ".roster", "seed")} \u2014 commit it; it is what makes the next
4928
5003
  upgrade a merge rather than a copy.
4929
5004
 
4930
5005
  Now run: roster upgrade
@@ -4937,7 +5012,7 @@ function stamp() {
4937
5012
  try {
4938
5013
  return execFileSync5(
4939
5014
  "git",
4940
- ["-C", join19(opsTemplateDir(), "..", ".."), "rev-parse", "--short", "HEAD"],
5015
+ ["-C", join20(opsTemplateDir(), "..", ".."), "rev-parse", "--short", "HEAD"],
4941
5016
  {
4942
5017
  encoding: "utf8",
4943
5018
  stdio: ["ignore", "pipe", "ignore"]
@@ -4976,17 +5051,17 @@ function planBrains(ws, parseYaml3) {
4976
5051
  const out = [];
4977
5052
  for (const entry of org.staff ?? []) {
4978
5053
  const dir = entry.dir ?? entry.handle;
4979
- const root2 = join19(ws.root, dir);
5054
+ const root2 = join20(ws.root, dir);
4980
5055
  const base2 = { handle: entry.handle, dir, root: root2, files: [] };
4981
- const manifestPath = join19(root2, "staff.yaml");
4982
- if (!existsSync7(manifestPath)) {
4983
- out.push({ ...base2, problem: existsSync7(root2) ? "no staff.yaml" : "not checked out here" });
5056
+ const manifestPath = join20(root2, "staff.yaml");
5057
+ if (!existsSync8(manifestPath)) {
5058
+ out.push({ ...base2, problem: existsSync8(root2) ? "no staff.yaml" : "not checked out here" });
4984
5059
  continue;
4985
5060
  }
4986
5061
  let want;
4987
5062
  try {
4988
5063
  const spec2 = specFromManifest(
4989
- parseYaml3(readFileSync8(manifestPath, "utf8"), "staff.yaml"),
5064
+ parseYaml3(readFileSync9(manifestPath, "utf8"), "staff.yaml"),
4990
5065
  dir
4991
5066
  );
4992
5067
  want = renderTree(brainTemplateDir(), tokensFor(orgSpec2, spec2));
@@ -4999,20 +5074,20 @@ function planBrains(ws, parseYaml3) {
4999
5074
  }
5000
5075
  for (const [rel, text2] of want) {
5001
5076
  const kind = classifyBrain(rel);
5002
- const live = join19(root2, rel);
5003
- if (!existsSync7(live)) {
5077
+ const live = join20(root2, rel);
5078
+ if (!existsSync8(live)) {
5004
5079
  base2.files.push({ rel, kind, verdict: "missing", next: text2 });
5005
5080
  continue;
5006
5081
  }
5007
5082
  if (kind === "scaffold") continue;
5008
- const have = readFileSync8(live, "utf8");
5083
+ const have = readFileSync9(live, "utf8");
5009
5084
  base2.files.push(
5010
5085
  have === text2 ? { rel, kind, verdict: "same" } : { rel, kind, verdict: "regenerate", next: text2, diff: unified(have, text2) }
5011
5086
  );
5012
5087
  }
5013
5088
  for (const rel of callerFiles(root2)) {
5014
5089
  if (want.has(rel)) continue;
5015
- const text2 = readFileSync8(join19(root2, rel), "utf8");
5090
+ const text2 = readFileSync9(join20(root2, rel), "utf8");
5016
5091
  if (!text2.includes(`${orgSpec2.opsRepo}/.github/workflows/session.yaml`)) continue;
5017
5092
  base2.files.push({ rel, kind: "generated", verdict: "obsolete" });
5018
5093
  }
@@ -5021,14 +5096,14 @@ function planBrains(ws, parseYaml3) {
5021
5096
  return out;
5022
5097
  }
5023
5098
  function unified(before, after) {
5024
- const dir = mkdtempSync4(join19(tmpdir4(), "roster-diff-"));
5099
+ const dir = mkdtempSync4(join20(tmpdir4(), "roster-diff-"));
5025
5100
  try {
5026
- writeFileSync7(join19(dir, "a"), before);
5027
- writeFileSync7(join19(dir, "b"), after);
5101
+ writeFileSync7(join20(dir, "a"), before);
5102
+ writeFileSync7(join20(dir, "b"), after);
5028
5103
  try {
5029
5104
  execFileSync5(
5030
5105
  "diff",
5031
- ["-u", "--label", "yours", "--label", "generated", join19(dir, "a"), join19(dir, "b")],
5106
+ ["-u", "--label", "yours", "--label", "generated", join20(dir, "a"), join20(dir, "b")],
5032
5107
  { encoding: "utf8" }
5033
5108
  );
5034
5109
  return "";
@@ -5041,8 +5116,8 @@ function unified(before, after) {
5041
5116
  }
5042
5117
  }
5043
5118
  function callerFiles(root2) {
5044
- const dir = join19(root2, ".github", "workflows");
5045
- if (!existsSync7(dir)) return [];
5119
+ const dir = join20(root2, ".github", "workflows");
5120
+ if (!existsSync8(dir)) return [];
5046
5121
  return readdirSync4(dir).filter((n) => n.endsWith(".yaml") || n.endsWith(".yml")).map((n) => `.github/workflows/${n}`);
5047
5122
  }
5048
5123
  function reportBrains(brains, opts) {
@@ -5090,13 +5165,13 @@ function applyBrains(brains) {
5090
5165
  for (const b of brains) {
5091
5166
  for (const f of b.files) {
5092
5167
  if (f.verdict === "obsolete") {
5093
- rmSync4(join19(b.root, f.rel), { force: true });
5168
+ rmSync4(join20(b.root, f.rel), { force: true });
5094
5169
  wrote++;
5095
5170
  continue;
5096
5171
  }
5097
5172
  if (f.next === void 0) continue;
5098
- const dest = join19(b.root, f.rel);
5099
- mkdirSync4(dirname7(dest), { recursive: true });
5173
+ const dest = join20(b.root, f.rel);
5174
+ mkdirSync4(dirname8(dest), { recursive: true });
5100
5175
  writeFileSync7(dest, f.next);
5101
5176
  wrote++;
5102
5177
  }
@@ -5222,7 +5297,7 @@ function checkWorkspace(ws, org) {
5222
5297
  });
5223
5298
  }
5224
5299
  try {
5225
- const plans = planAll(opsTemplateDir(), join20(ws.opsDir, ".roster", "seed"), ws.opsDir);
5300
+ const plans = planAll(opsTemplateDir(), join21(ws.opsDir, ".roster", "seed"), ws.opsDir);
5226
5301
  const edited = plans.filter((p) => p.verdict === "edited-managed");
5227
5302
  const stale = plans.filter((p) => p.next !== void 0);
5228
5303
  const unmergeable = plans.filter((p) => p.verdict === "conflict" || p.verdict === "no-base");
@@ -5271,7 +5346,7 @@ async function checkAgent(ws, org) {
5271
5346
  const scope = "workspace";
5272
5347
  let agent;
5273
5348
  try {
5274
- const { resolveAgent } = await import(pathToFileURL3(join20(ws.opsDir, "agents.mjs")).href);
5349
+ const { resolveAgent } = await import(pathToFileURL3(join21(ws.opsDir, "agents.mjs")).href);
5275
5350
  agent = resolveAgent(org, {});
5276
5351
  } catch (err) {
5277
5352
  return [
@@ -5285,8 +5360,8 @@ async function checkAgent(ws, org) {
5285
5360
  ];
5286
5361
  }
5287
5362
  const out = [{ scope, level: "ok", id: "agent", title: `runs on ${agent.id}` }];
5288
- const orgFile = join20(ws.opsDir, "org.yaml");
5289
- if (existsSync8(orgFile) && /FILL IN/.test(readFileSync9(orgFile, "utf8"))) {
5363
+ const orgFile = join21(ws.opsDir, "org.yaml");
5364
+ if (existsSync9(orgFile) && /FILL IN/.test(readFileSync10(orgFile, "utf8"))) {
5290
5365
  out.push({
5291
5366
  scope,
5292
5367
  level: "fail",
@@ -5296,8 +5371,8 @@ async function checkAgent(ws, org) {
5296
5371
  });
5297
5372
  }
5298
5373
  if (!agent.config) return out;
5299
- const path = join20(ws.opsDir, agent.config.path);
5300
- if (!existsSync8(path)) {
5374
+ const path = join21(ws.opsDir, agent.config.path);
5375
+ if (!existsSync9(path)) {
5301
5376
  out.push({
5302
5377
  scope,
5303
5378
  level: "fail",
@@ -5307,7 +5382,7 @@ async function checkAgent(ws, org) {
5307
5382
  });
5308
5383
  return out;
5309
5384
  }
5310
- if (/FILL IN/.test(readFileSync9(path, "utf8"))) {
5385
+ if (/FILL IN/.test(readFileSync10(path, "utf8"))) {
5311
5386
  out.push({
5312
5387
  scope,
5313
5388
  level: "fail",
@@ -5319,8 +5394,8 @@ async function checkAgent(ws, org) {
5319
5394
  return out;
5320
5395
  }
5321
5396
  function checkBusiness(ws) {
5322
- const path = join20(ws.opsDir, "org", "business.md");
5323
- if (!existsSync8(path)) {
5397
+ const path = join21(ws.opsDir, "org", "business.md");
5398
+ if (!existsSync9(path)) {
5324
5399
  return [
5325
5400
  {
5326
5401
  scope: "workspace",
@@ -5331,7 +5406,7 @@ function checkBusiness(ws) {
5331
5406
  }
5332
5407
  ];
5333
5408
  }
5334
- if (looksUnwritten(readFileSync9(path, "utf8"))) {
5409
+ if (looksUnwritten(readFileSync10(path, "utf8"))) {
5335
5410
  return [
5336
5411
  {
5337
5412
  scope: "workspace",
@@ -5345,8 +5420,8 @@ function checkBusiness(ws) {
5345
5420
  return [{ scope: "workspace", level: "ok", id: "business", title: "org/business.md is written" }];
5346
5421
  }
5347
5422
  function checkPriorities(ws) {
5348
- const path = join20(ws.opsDir, "org", "priorities.md");
5349
- if (!existsSync8(path)) {
5423
+ const path = join21(ws.opsDir, "org", "priorities.md");
5424
+ if (!existsSync9(path)) {
5350
5425
  return [
5351
5426
  {
5352
5427
  scope: "workspace",
@@ -5357,7 +5432,7 @@ function checkPriorities(ws) {
5357
5432
  }
5358
5433
  ];
5359
5434
  }
5360
- if (looksUnwritten(readFileSync9(path, "utf8"))) {
5435
+ if (looksUnwritten(readFileSync10(path, "utf8"))) {
5361
5436
  return [
5362
5437
  {
5363
5438
  scope: "workspace",
@@ -5376,8 +5451,8 @@ async function checkStaff(ws, org, entry, composer, online) {
5376
5451
  const scope = entry.handle;
5377
5452
  const out = [];
5378
5453
  const dir = entry.dir ?? entry.handle;
5379
- const root2 = join20(ws.root, dir);
5380
- if (!existsSync8(root2)) {
5454
+ const root2 = join21(ws.root, dir);
5455
+ if (!existsSync9(root2)) {
5381
5456
  return [
5382
5457
  {
5383
5458
  scope,
@@ -5388,9 +5463,9 @@ async function checkStaff(ws, org, entry, composer, online) {
5388
5463
  }
5389
5464
  ];
5390
5465
  }
5391
- const manifestPath = join20(root2, "staff.yaml");
5466
+ const manifestPath = join21(root2, "staff.yaml");
5392
5467
  let manifest = {};
5393
- if (!existsSync8(manifestPath)) {
5468
+ if (!existsSync9(manifestPath)) {
5394
5469
  out.push({
5395
5470
  scope,
5396
5471
  level: "fail",
@@ -5400,7 +5475,7 @@ async function checkStaff(ws, org, entry, composer, online) {
5400
5475
  });
5401
5476
  } else {
5402
5477
  try {
5403
- manifest = composer.parseYaml(readFileSync9(manifestPath, "utf8"), "staff.yaml");
5478
+ manifest = composer.parseYaml(readFileSync10(manifestPath, "utf8"), "staff.yaml");
5404
5479
  if (manifest.handle !== entry.handle) {
5405
5480
  out.push({
5406
5481
  scope,
@@ -5429,9 +5504,9 @@ async function checkStaff(ws, org, entry, composer, online) {
5429
5504
  });
5430
5505
  }
5431
5506
  }
5432
- const charterPath = join20(root2, "CHARTER.md");
5507
+ const charterPath = join21(root2, "CHARTER.md");
5433
5508
  out.push(
5434
- existsSync8(charterPath) ? { scope, level: "ok", id: "charter", title: "CHARTER.md present" } : {
5509
+ existsSync9(charterPath) ? { scope, level: "ok", id: "charter", title: "CHARTER.md present" } : {
5435
5510
  scope,
5436
5511
  level: "fail",
5437
5512
  id: "charter",
@@ -5439,7 +5514,7 @@ async function checkStaff(ws, org, entry, composer, online) {
5439
5514
  fix: "The charter is the personality; nothing else supplies it."
5440
5515
  }
5441
5516
  );
5442
- if (existsSync8(charterPath) && looksUnwritten(readFileSync9(charterPath, "utf8"))) {
5517
+ if (existsSync9(charterPath) && looksUnwritten(readFileSync10(charterPath, "utf8"))) {
5443
5518
  out.push({
5444
5519
  scope,
5445
5520
  level: "warn",
@@ -5448,8 +5523,8 @@ async function checkStaff(ws, org, entry, composer, online) {
5448
5523
  fix: `roster brief charter ${entry.handle}, or "Write the charter" on the portal's Staff screen`
5449
5524
  });
5450
5525
  }
5451
- const memDir = join20(root2, "memory");
5452
- if (!existsSync8(join20(memDir, "INDEX.md"))) {
5526
+ const memDir = join21(root2, "memory");
5527
+ if (!existsSync9(join21(memDir, "INDEX.md"))) {
5453
5528
  out.push({
5454
5529
  scope,
5455
5530
  level: "fail",
@@ -5546,8 +5621,8 @@ async function checkStaff(ws, org, entry, composer, online) {
5546
5621
  fix: "A private reusable workflow is only callable inside its own org, so this can never resolve."
5547
5622
  });
5548
5623
  }
5549
- const local = join20(ws.opsDir, ref.slice(opsRepo.length + 1));
5550
- if (!existsSync8(local)) {
5624
+ const local = join21(ws.opsDir, ref.slice(opsRepo.length + 1));
5625
+ if (!existsSync9(local)) {
5551
5626
  out.push({
5552
5627
  scope,
5553
5628
  level: "fail",
@@ -5565,7 +5640,7 @@ async function checkStaff(ws, org, entry, composer, online) {
5565
5640
  title: `2 callers, both pointing at ${opsRepo}`
5566
5641
  });
5567
5642
  }
5568
- const missing2 = (manifest.surfaces ?? []).map((s) => s.path).filter((p) => p && !existsSync8(join20(root2, p)));
5643
+ const missing2 = (manifest.surfaces ?? []).map((s) => s.path).filter((p) => p && !existsSync9(join21(root2, p)));
5569
5644
  if (missing2.length) {
5570
5645
  out.push({
5571
5646
  scope,
@@ -5611,10 +5686,10 @@ function inferredCeiling(cancelled) {
5611
5686
  return most >= 2 ? best : null;
5612
5687
  }
5613
5688
  function readCallers(root2, handle) {
5614
- const dir = join20(root2, ".github", "workflows");
5615
- if (!existsSync8(dir)) return [];
5689
+ const dir = join21(root2, ".github", "workflows");
5690
+ if (!existsSync9(dir)) return [];
5616
5691
  const mine = new RegExp(`^${handle}-(daily|mention)\\.ya?ml$`);
5617
- return readdirSync5(dir).filter((f) => mine.test(f)).sort().map((name) => ({ name, text: readFileSync9(join20(dir, name), "utf8") }));
5692
+ return readdirSync5(dir).filter((f) => mine.test(f)).sort().map((name) => ({ name, text: readFileSync10(join21(dir, name), "utf8") }));
5618
5693
  }
5619
5694
  async function checkOrgOnline(ws, org) {
5620
5695
  const out = [];
@@ -5694,10 +5769,10 @@ async function checkReviewGates(ws, org, composer) {
5694
5769
  );
5695
5770
  const apps = /* @__PURE__ */ new Set();
5696
5771
  for (const s of org.staff ?? []) {
5697
- const path = join20(ws.root, s.dir ?? s.handle, "staff.yaml");
5698
- if (!existsSync8(path)) continue;
5772
+ const path = join21(ws.root, s.dir ?? s.handle, "staff.yaml");
5773
+ if (!existsSync9(path)) continue;
5699
5774
  try {
5700
- const m = composer.parseYaml(readFileSync9(path, "utf8"), "staff.yaml");
5775
+ const m = composer.parseYaml(readFileSync10(path, "utf8"), "staff.yaml");
5701
5776
  for (const w of m.works_in ?? []) if (w?.repo) repos.add(String(w.repo));
5702
5777
  for (const i of m.identities ?? []) if (i?.app) apps.add(String(i.app));
5703
5778
  } catch {
@@ -6242,7 +6317,7 @@ import { writeFileSync as writeFileSync8 } from "fs";
6242
6317
 
6243
6318
  // src/lib/export.ts
6244
6319
  import { execFileSync as execFileSync6 } from "child_process";
6245
- import { join as join21, relative as relative4 } from "path";
6320
+ import { join as join22, relative as relative4 } from "path";
6246
6321
  var gitHistory = {
6247
6322
  log: (root2, n, path) => gitLog(root2, n, path ? ["--", path] : []),
6248
6323
  factsChanged: (root2, since) => factsChanged(root2, since)
@@ -6253,11 +6328,11 @@ function buildExport(ws, org, parseYaml3, opts = {}) {
6253
6328
  const history = opts.history ?? gitHistory;
6254
6329
  for (const entry of org.staff ?? []) {
6255
6330
  const dir = entry.dir ?? entry.handle;
6256
- const root2 = join21(ws.root, dir);
6331
+ const root2 = join22(ws.root, dir);
6257
6332
  if (!existsSync2(root2)) continue;
6258
6333
  const manifest = readManifest2(root2, parseYaml3);
6259
- const memDir = join21(root2, "memory");
6260
- const doc = existsSync2(join21(memDir, "INDEX.md")) ? parseMemory(memDir) : { facts: [], sections: [], notes: [], preamble: "", links: [] };
6334
+ const memDir = join22(root2, "memory");
6335
+ const doc = existsSync2(join22(memDir, "INDEX.md")) ? parseMemory(memDir) : { facts: [], sections: [], notes: [], preamble: "", links: [] };
6261
6336
  const commits = history.log(root2, 25);
6262
6337
  staff.push({
6263
6338
  handle: entry.handle,
@@ -6277,7 +6352,7 @@ function buildExport(ws, org, parseYaml3, opts = {}) {
6277
6352
  sections: doc.sections,
6278
6353
  notes: doc.notes,
6279
6354
  links: doc.links,
6280
- problems: existsSync2(join21(memDir, "INDEX.md")) ? lintMemory(doc, memDir, budgetsFor(org, manifest)) : [],
6355
+ problems: existsSync2(join22(memDir, "INDEX.md")) ? lintMemory(doc, memDir, budgetsFor(org, manifest)) : [],
6281
6356
  surfaces: readSurfaces(root2, manifest.surfaces ?? []),
6282
6357
  recentCommits: commits,
6283
6358
  factsChanged: history.factsChanged(root2, opts.since ?? "14 days ago"),
@@ -6306,7 +6381,7 @@ function botName(raw) {
6306
6381
  return String(raw).replace(/\[bot\]$/, "");
6307
6382
  }
6308
6383
  function readManifest2(root2, parseYaml3) {
6309
- const path = join21(root2, "staff.yaml");
6384
+ const path = join22(root2, "staff.yaml");
6310
6385
  if (!existsSync2(path)) return {};
6311
6386
  try {
6312
6387
  return parseYaml3(readFileSync2(path, "utf8"), "staff.yaml");
@@ -6315,16 +6390,16 @@ function readManifest2(root2, parseYaml3) {
6315
6390
  }
6316
6391
  }
6317
6392
  function readRig(root2, manifest, commits, history) {
6318
- const wfDir = join21(root2, ".github", "workflows");
6393
+ const wfDir = join22(root2, ".github", "workflows");
6319
6394
  const declared3 = manifest.surfaces ?? [];
6320
6395
  return {
6321
6396
  workflows: existsSync2(wfDir) ? readdirSync2(wfDir).filter((f) => /\.ya?ml$/.test(f)).sort() : [],
6322
- hasCharter: existsSync2(join21(root2, "CHARTER.md")),
6323
- charterStub: !existsSync2(join21(root2, "CHARTER.md")) || looksUnwritten(readFileSync2(join21(root2, "CHARTER.md"), "utf8")),
6324
- hasManifest: existsSync2(join21(root2, "staff.yaml")),
6325
- missingSurfaces: declared3.filter((s) => s?.path && !existsSync2(join21(root2, s.path))).map((s) => s.path),
6326
- memoryBytes: bytesOf(join21(root2, "memory", "INDEX.md")),
6327
- notesBytes: dirBytes(join21(root2, "memory", "notes")),
6397
+ hasCharter: existsSync2(join22(root2, "CHARTER.md")),
6398
+ charterStub: !existsSync2(join22(root2, "CHARTER.md")) || looksUnwritten(readFileSync2(join22(root2, "CHARTER.md"), "utf8")),
6399
+ hasManifest: existsSync2(join22(root2, "staff.yaml")),
6400
+ missingSurfaces: declared3.filter((s) => s?.path && !existsSync2(join22(root2, s.path))).map((s) => s.path),
6401
+ memoryBytes: bytesOf(join22(root2, "memory", "INDEX.md")),
6402
+ notesBytes: dirBytes(join22(root2, "memory", "notes")),
6328
6403
  lastCommit: commits[0],
6329
6404
  lastMemoryCommit: history.log(root2, 1, "memory")[0]
6330
6405
  };
@@ -6341,16 +6416,16 @@ function dirBytes(dir) {
6341
6416
  return walk2(dir, dir).reduce((n, f) => n + f.bytes, 0);
6342
6417
  }
6343
6418
  function readSurfaces(root2, declared3) {
6344
- return declared3.filter((s) => s?.path && existsSync2(join21(root2, s.path))).map((s) => ({
6419
+ return declared3.filter((s) => s?.path && existsSync2(join22(root2, s.path))).map((s) => ({
6345
6420
  path: s.path,
6346
6421
  render: s.render ?? "doc",
6347
- files: walk2(join21(root2, s.path), root2)
6422
+ files: walk2(join22(root2, s.path), root2)
6348
6423
  }));
6349
6424
  }
6350
6425
  function walk2(dir, root2, out = []) {
6351
6426
  for (const name of [...readdirSync2(dir)].sort()) {
6352
6427
  if (SKIP.has(name)) continue;
6353
- const full = join21(dir, name);
6428
+ const full = join22(dir, name);
6354
6429
  const st = statSync2(full);
6355
6430
  if (st.isDirectory()) walk2(full, root2, out);
6356
6431
  else {
@@ -6454,13 +6529,13 @@ async function exportCommand(argv) {
6454
6529
  }
6455
6530
 
6456
6531
  // src/lib/audit.ts
6457
- import { join as join22 } from "path";
6532
+ import { join as join23 } from "path";
6458
6533
  var LONG_WORDS = 3500;
6459
6534
  var ECHO_CHARS = 60;
6460
6535
  function auditPrompt(ws, view, roots) {
6461
6536
  const out = [];
6462
6537
  const text2 = (rel) => {
6463
- const full = join22(ws.root, rel);
6538
+ const full = join23(ws.root, rel);
6464
6539
  return existsSync2(full) ? readFileSync2(full, "utf8") : "";
6465
6540
  };
6466
6541
  for (const layer of [...view.layers, ...view.runtime]) {
@@ -6514,9 +6589,9 @@ Decide which layer each one belongs in and remove it from the others.`
6514
6589
  want: `This prompt is ${words.toLocaleString()} words and is read in full on every run. Find what can go: anything restated, anything that was true once, anything an agent would do anyway. Cut more than you add, and tell me what you cut.`
6515
6590
  });
6516
6591
  }
6517
- const bases = [ws.root, ...roots.map((r) => join22(ws.root, r))];
6592
+ const bases = [ws.root, ...roots.map((r) => join23(ws.root, r))];
6518
6593
  for (const rel of namedPaths(view.composed)) {
6519
- if (bases.some((b) => existsSync2(join22(b, rel)))) continue;
6594
+ if (bases.some((b) => existsSync2(join23(b, rel)))) continue;
6520
6595
  out.push({
6521
6596
  id: "dangling",
6522
6597
  level: "warning",
@@ -6795,8 +6870,8 @@ function parseFlags9(argv) {
6795
6870
 
6796
6871
  // src/commands/init.ts
6797
6872
  import { execFileSync as execFileSync7 } from "child_process";
6798
- import { existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as readFileSync10, writeFileSync as writeFileSync9 } from "fs";
6799
- import { dirname as dirname8, join as join23, resolve as resolve3 } from "path";
6873
+ import { existsSync as existsSync10, mkdirSync as mkdirSync5, readFileSync as readFileSync11, writeFileSync as writeFileSync9 } from "fs";
6874
+ import { dirname as dirname9, join as join24, resolve as resolve4 } from "path";
6800
6875
  import { pathToFileURL as pathToFileURL4 } from "url";
6801
6876
  var initHelp = `
6802
6877
  roster init --org <github-org> [--name "Acme"] [--human <login>] [--apply]
@@ -6841,10 +6916,10 @@ async function initCommand(argv) {
6841
6916
  const human = opts.human ?? ready2.data.login;
6842
6917
  const name = opts.name ?? opts.org;
6843
6918
  const opsName = opts.ops ?? "roster-ops";
6844
- const root2 = resolve3(opts.dir ?? process.cwd());
6845
- const opsDir = join23(root2, opsName);
6919
+ const root2 = resolve4(opts.dir ?? process.cwd());
6920
+ const opsDir = join24(root2, opsName);
6846
6921
  const marker = opts.marker ?? human.split("-")[0];
6847
- if (existsSync9(opsDir)) {
6922
+ if (existsSync10(opsDir)) {
6848
6923
  process.stderr.write(`roster: ${opsDir} already exists. This org is already initialised.
6849
6924
  `);
6850
6925
  return 2;
@@ -6891,14 +6966,14 @@ async function initCommand(argv) {
6891
6966
  }
6892
6967
  mkdirSync5(opsDir, { recursive: true });
6893
6968
  for (const [rel, text2] of files) {
6894
- const dest = join23(opsDir, rel);
6895
- mkdirSync5(dirname8(dest), { recursive: true });
6969
+ const dest = join24(opsDir, rel);
6970
+ mkdirSync5(dirname9(dest), { recursive: true });
6896
6971
  writeFileSync9(dest, text2);
6897
6972
  }
6898
6973
  for (const rel of templateFiles(opsTemplateDir())) {
6899
- const dest = join23(opsDir, ".roster", "seed", rel);
6900
- mkdirSync5(dirname8(dest), { recursive: true });
6901
- writeFileSync9(dest, readFileSync10(join23(opsTemplateDir(), rel), "utf8"));
6974
+ const dest = join24(opsDir, ".roster", "seed", rel);
6975
+ mkdirSync5(dirname9(dest), { recursive: true });
6976
+ writeFileSync9(dest, readFileSync11(join24(opsTemplateDir(), rel), "utf8"));
6902
6977
  }
6903
6978
  process.stdout.write(` wrote ${files.size} files and the recorded base
6904
6979
  `);
@@ -6948,7 +7023,7 @@ async function initCommand(argv) {
6948
7023
  async function initFiles(o) {
6949
7024
  const files = /* @__PURE__ */ new Map();
6950
7025
  for (const rel of templateFiles(opsTemplateDir())) {
6951
- files.set(rel, readFileSync10(join23(opsTemplateDir(), rel), "utf8"));
7026
+ files.set(rel, readFileSync11(join24(opsTemplateDir(), rel), "utf8"));
6952
7027
  }
6953
7028
  const agent = o.agent ?? "claude-code-action";
6954
7029
  const preset = await agentPreset(agent);
@@ -6973,7 +7048,7 @@ async function initFiles(o) {
6973
7048
  return files;
6974
7049
  }
6975
7050
  async function agentPreset(id) {
6976
- const path = join23(opsTemplateDir(), "agents.mjs");
7051
+ const path = join24(opsTemplateDir(), "agents.mjs");
6977
7052
  const { PRESETS } = await import(pathToFileURL4(path).href);
6978
7053
  const preset = PRESETS[id];
6979
7054
  if (!preset) {
@@ -7107,7 +7182,7 @@ function stamp2() {
7107
7182
  try {
7108
7183
  return execFileSync7(
7109
7184
  "git",
7110
- ["-C", join23(opsTemplateDir(), "..", ".."), "rev-parse", "--short", "HEAD"],
7185
+ ["-C", join24(opsTemplateDir(), "..", ".."), "rev-parse", "--short", "HEAD"],
7111
7186
  {
7112
7187
  encoding: "utf8",
7113
7188
  stdio: ["ignore", "pipe", "ignore"]
@@ -7143,7 +7218,7 @@ function parseFlags10(argv) {
7143
7218
  }
7144
7219
 
7145
7220
  // src/commands/lint.ts
7146
- import { join as join24 } from "path";
7221
+ import { join as join25 } from "path";
7147
7222
  var lintHelp = `
7148
7223
  roster lint [handle]
7149
7224
 
@@ -7171,8 +7246,8 @@ async function lintCommand(argv) {
7171
7246
  let errors = 0;
7172
7247
  let warnings = 0;
7173
7248
  for (const s of staff) {
7174
- const root2 = join24(ws.root, s.dir ?? s.handle);
7175
- const dir = join24(root2, "memory");
7249
+ const root2 = join25(ws.root, s.dir ?? s.handle);
7250
+ const dir = join25(root2, "memory");
7176
7251
  const budgets = budgetsFor(org, readManifest2(root2, parseYaml3));
7177
7252
  let problems;
7178
7253
  let factCount = 0;
@@ -7234,14 +7309,14 @@ import { join as join33, resolve as resolve6 } from "path";
7234
7309
 
7235
7310
  // src/lib/attach.ts
7236
7311
  import { execFileSync as execFileSync8 } from "child_process";
7237
- import { existsSync as existsSync10, mkdirSync as mkdirSync6, writeFileSync as writeFileSync10 } from "fs";
7238
- import { basename as basename2, extname, join as join25 } from "path";
7312
+ import { existsSync as existsSync11, mkdirSync as mkdirSync6, writeFileSync as writeFileSync10 } from "fs";
7313
+ import { basename as basename2, extname as extname3, join as join26 } from "path";
7239
7314
  var MAX_UPLOAD = 25 * 1024 * 1024;
7240
7315
  var ATTACH_DIR = "attachments";
7241
7316
  function safeName(raw) {
7242
7317
  const name = basename2(String(raw ?? "")).replace(/^\.+/, "");
7243
- const ext = extname(name).toLowerCase().slice(0, 12);
7244
- const stem = name.slice(0, name.length - extname(name).length).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "file";
7318
+ const ext = extname3(name).toLowerCase().slice(0, 12);
7319
+ const stem = name.slice(0, name.length - extname3(name).length).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "file";
7245
7320
  return stem + ext.replace(/[^a-z0-9.]/g, "");
7246
7321
  }
7247
7322
  function attachPath(name, size2, today, taken) {
@@ -7253,7 +7328,7 @@ function attachPath(name, size2, today, taken) {
7253
7328
  }
7254
7329
  function free(rel, taken) {
7255
7330
  if (!taken(rel)) return rel;
7256
- const ext = extname(rel);
7331
+ const ext = extname3(rel);
7257
7332
  const stem = rel.slice(0, rel.length - ext.length);
7258
7333
  for (let n = 2; n < 500; n++) {
7259
7334
  const next = `${stem}-${n}${ext}`;
@@ -7288,16 +7363,16 @@ function rewriteOutput(name = bin()) {
7288
7363
 
7289
7364
  // src/lib/sync.ts
7290
7365
  import { execFile as execFile5 } from "child_process";
7291
- import { existsSync as existsSync11 } from "fs";
7292
- import { join as join26 } from "path";
7366
+ import { existsSync as existsSync12 } from "fs";
7367
+ import { join as join27 } from "path";
7293
7368
  import { promisify as promisify2 } from "util";
7294
7369
  var run2 = promisify2(execFile5);
7295
7370
  async function syncRepos(root2, dirs) {
7296
- return Promise.all(dirs.map((dir) => syncOne(join26(root2, dir), dir)));
7371
+ return Promise.all(dirs.map((dir) => syncOne(join27(root2, dir), dir)));
7297
7372
  }
7298
7373
  async function syncOne(path, dir) {
7299
7374
  const base2 = { dir, behind: 0, ahead: 0, dirty: false, pulled: false };
7300
- if (!existsSync11(join26(path, ".git"))) return { ...base2, skipped: "no-remote" };
7375
+ if (!existsSync12(join27(path, ".git"))) return { ...base2, skipped: "no-remote" };
7301
7376
  const git4 = async (...args) => (await run2("git", ["-C", path, ...args], { encoding: "utf8" })).stdout.trim();
7302
7377
  try {
7303
7378
  const remotes = await git4("remote");
@@ -7331,45 +7406,6 @@ function reason(e) {
7331
7406
  return line.length > 180 ? line.slice(0, 179) + "\u2026" : line;
7332
7407
  }
7333
7408
 
7334
- // src/portal/assets.ts
7335
- import { existsSync as existsSync12, readFileSync as readFileSync11, statSync as statSync3 } from "fs";
7336
- import { dirname as dirname9, extname as extname2, join as join27, resolve as resolve4 } from "path";
7337
- import { fileURLToPath as fileURLToPath4 } from "url";
7338
- function portalDir() {
7339
- const fixed = frameworkRoot();
7340
- if (fixed) return join27(fixed, "templates", "portal");
7341
- const here = dirname9(fileURLToPath4(import.meta.url));
7342
- const candidates = [
7343
- join27(here, "..", "..", "templates", "portal"),
7344
- // src/portal → package root
7345
- join27(here, "..", "templates", "portal")
7346
- // dist → package root
7347
- ];
7348
- for (const path of candidates) if (existsSync12(join27(path, "index.html"))) return path;
7349
- throw new Error(`portal UI not found. Looked in:
7350
- ${candidates.join("\n ")}`);
7351
- }
7352
- function portalIndex() {
7353
- return readFileSync11(join27(portalDir(), "index.html"), "utf8");
7354
- }
7355
- var ASSET_MIME = {
7356
- ".css": "text/css; charset=utf-8",
7357
- ".js": "text/javascript; charset=utf-8",
7358
- ".mjs": "text/javascript; charset=utf-8",
7359
- ".svg": "image/svg+xml",
7360
- ".png": "image/png",
7361
- ".woff2": "font/woff2"
7362
- };
7363
- function portalAsset(rel) {
7364
- const root2 = portalDir();
7365
- const full = resolve4(root2, rel);
7366
- if (!inside(resolve4(root2), full)) return null;
7367
- const type = ASSET_MIME[extname2(full).toLowerCase()];
7368
- if (!type) return null;
7369
- if (!existsSync12(full) || statSync3(full).isDirectory()) return null;
7370
- return { body: readFileSync11(full), type };
7371
- }
7372
-
7373
7409
  // src/portal/handler.ts
7374
7410
  import { join as join30, relative as relative5, resolve as resolve5 } from "path";
7375
7411
 
@@ -9297,8 +9333,9 @@ var ROUTES = {
9297
9333
  const g = await readGrant(portal.grants.store, portal.grants.secret, x.id);
9298
9334
  if (g) signedIn = { by: g.by, at: g.at };
9299
9335
  }
9300
- const { entry: _entry, ...rest } = x;
9301
- return { ...rest, keys, signedIn };
9336
+ const { entry, ...rest } = x;
9337
+ const url = x.known ? null : entry.url ?? null;
9338
+ return { ...rest, url, keys, signedIn };
9302
9339
  })
9303
9340
  );
9304
9341
  return json({
@@ -9332,9 +9369,13 @@ var ROUTES = {
9332
9369
  const id = String(p.id ?? "");
9333
9370
  const known = CATALOGUE2[id];
9334
9371
  const existing = org.connectors?.[id];
9335
- if (!known && !existing) return json({ error: `roster does not know ${id}` }, 400);
9336
9372
  const handles = new Set((org.staff ?? []).map((s) => String(s.handle)));
9337
9373
  const staff = (p.staff ?? []).map(String).filter((h) => handles.has(h));
9374
+ if (p.custom || existing && !known) {
9375
+ if (!staff.length) return json({ error: "Pick at least one staff member." }, 400);
9376
+ return saveCustom(c, org, id, staff, p.custom ?? null, String(p.values?.token ?? "").trim());
9377
+ }
9378
+ if (!known && !existing) return json({ error: `roster does not know ${id}` }, 400);
9338
9379
  if (!staff.length) return json({ error: "Pick at least one staff member." }, 400);
9339
9380
  const entry = { staff, read_only: p.readOnly === true };
9340
9381
  for (const f of known?.fields ?? []) {
@@ -9418,19 +9459,29 @@ var ROUTES = {
9418
9459
  const p = await body(c.req);
9419
9460
  const id = String(p.id ?? "");
9420
9461
  const known = CATALOGUE2[id];
9421
- if (!known?.oauth) return json({ error: `${id} does not sign in` }, 400);
9422
9462
  const { org } = await ready(c);
9463
+ const existing = org.connectors?.[id];
9464
+ let resource = known?.oauth?.resource;
9465
+ if (!known && (p.custom || existing?.auth === "oauth")) {
9466
+ const wrong = customWrong(org, id, p.custom ? String(p.custom.url ?? "") : existing?.url, {
9467
+ isNew: Boolean(p.custom)
9468
+ });
9469
+ if (wrong) return json({ error: wrong }, 400);
9470
+ resource = String(p.custom?.url ?? existing?.url).trim();
9471
+ }
9472
+ if (!resource) return json({ error: `${id} does not sign in` }, 400);
9423
9473
  const handles = new Set((org.staff ?? []).map((s) => String(s.handle)));
9424
9474
  const staff = (p.staff ?? []).map(String).filter((h) => handles.has(h));
9425
9475
  if (!staff.length) return json({ error: "Pick at least one staff member." }, 400);
9426
9476
  const redirect = `${portal.grants.base}/connectors/callback`;
9427
- const meta = await discover(known.oauth.resource);
9428
- const client = await clientFor(
9429
- meta,
9430
- redirect,
9431
- `Roster (${portal.org})`,
9432
- portal.grants.store
9433
- );
9477
+ let meta;
9478
+ let client;
9479
+ try {
9480
+ meta = await discover(resource);
9481
+ client = await clientFor(meta, redirect, `Roster (${portal.org})`, portal.grants.store);
9482
+ } catch (err) {
9483
+ return json({ error: err.message }, 400);
9484
+ }
9434
9485
  const v = verifier();
9435
9486
  const state = verifier();
9436
9487
  const pending2 = await sealJson(
@@ -9441,6 +9492,7 @@ var ROUTES = {
9441
9492
  readOnly: p.readOnly === true,
9442
9493
  verifier: v,
9443
9494
  state,
9495
+ resource,
9444
9496
  tokenEndpoint: meta.token_endpoint,
9445
9497
  ...client,
9446
9498
  exp: Date.now() + 6e5
@@ -9455,7 +9507,7 @@ var ROUTES = {
9455
9507
  code_challenge: await challenge(v),
9456
9508
  code_challenge_method: "S256",
9457
9509
  state,
9458
- resource: known.oauth.resource
9510
+ resource
9459
9511
  })) {
9460
9512
  go.searchParams.set(k, val);
9461
9513
  }
@@ -9490,11 +9542,11 @@ var ROUTES = {
9490
9542
  if (!code)
9491
9543
  return back(url.searchParams.get("error_description") ?? "The sign-in was cancelled.");
9492
9544
  const known = CATALOGUE2[pending2.id];
9493
- if (!known?.oauth) return back("That service is not one roster signs in to.");
9545
+ if (known && !known.oauth) return back("That service is not one roster signs in to.");
9494
9546
  try {
9495
9547
  const grant = await exchange2({
9496
9548
  connector: pending2.id,
9497
- resource: known.oauth.resource,
9549
+ resource: pending2.resource,
9498
9550
  tokenEndpoint: pending2.tokenEndpoint,
9499
9551
  clientId: pending2.clientId,
9500
9552
  clientSecret: pending2.clientSecret,
@@ -9509,6 +9561,8 @@ var ROUTES = {
9509
9561
  const after = setConnector(before, org, pending2.id, {
9510
9562
  staff: pending2.staff,
9511
9563
  read_only: pending2.readOnly,
9564
+ // Written out longhand when roster has no entry for it: the server, and that it signs in.
9565
+ ...known ? {} : { url: pending2.resource, auth: "oauth" },
9512
9566
  portal: portal.grants.base
9513
9567
  });
9514
9568
  await commitFile(
@@ -9517,7 +9571,7 @@ var ROUTES = {
9517
9571
  portal.opsName,
9518
9572
  "org.yaml",
9519
9573
  after,
9520
- `portal: connect ${known.name}`,
9574
+ `portal: connect ${known?.name ?? pending2.id}`,
9521
9575
  before
9522
9576
  );
9523
9577
  } catch (err) {
@@ -10075,6 +10129,69 @@ async function staffProgress(gh, org, spec2, workflow) {
10075
10129
  ran: runs.ok ? (runs.data?.total_count ?? 0) > 0 : null
10076
10130
  };
10077
10131
  }
10132
+ function customWrong(org, id, url, { isNew }) {
10133
+ if (CATALOGUE2[id]) return `${CATALOGUE2[id].name} is in the list: add it from there.`;
10134
+ if (isNew && org.connectors?.[id]) return `There is already a connector called ${id}.`;
10135
+ const problem = declared2({ connectors: { [id]: { url: url || void 0 } } })[0]?.problem;
10136
+ if (problem) return problem;
10137
+ let parsed;
10138
+ try {
10139
+ parsed = new URL(String(url).trim());
10140
+ } catch {
10141
+ return "The server's URL is not a URL.";
10142
+ }
10143
+ if (parsed.protocol !== "https:") return "The server's URL has to start with https://.";
10144
+ return null;
10145
+ }
10146
+ async function saveCustom(c, org, id, staff, custom, token) {
10147
+ const { portal, actor } = c;
10148
+ const existing = org.connectors?.[id];
10149
+ const entry = { staff };
10150
+ let secret = null;
10151
+ if (custom) {
10152
+ const wrong2 = customWrong(org, id, custom.url, { isNew: true });
10153
+ if (wrong2) return json({ error: wrong2 }, 400);
10154
+ entry.url = String(custom.url).trim();
10155
+ if (token) {
10156
+ const header = String(custom.header ?? "").trim() || "Authorization";
10157
+ if (!/^[A-Za-z0-9-]+$/.test(header))
10158
+ return json({ error: `"${header}" is not a header name.` }, 400);
10159
+ entry.secrets = ["TOKEN"];
10160
+ entry.headers = { [header]: "${TOKEN}" };
10161
+ secret = secretName2(id, "TOKEN");
10162
+ }
10163
+ } else if (token) {
10164
+ const names = declared2(org).find((d) => d.id === id)?.secrets ?? [];
10165
+ if (names.length !== 1)
10166
+ return json(
10167
+ { error: `${id} takes ${names.length} keys: change them with roster connector.` },
10168
+ 400
10169
+ );
10170
+ secret = names[0].name;
10171
+ }
10172
+ const stored = [];
10173
+ if (secret) {
10174
+ const brains = (org.staff ?? []).map((s) => `${portal.org}/${s.dir ?? s.handle}`);
10175
+ stored.push({
10176
+ name: secret,
10177
+ ...await storeSecret(actor.gh, portal.org, secret, token, brains)
10178
+ });
10179
+ }
10180
+ const before = portal.snapshots.get(`${portal.org}/${portal.opsName}`)?.files.get("org.yaml")?.text ?? "";
10181
+ const after = setConnector(before, org, id, entry);
10182
+ const wrong = validateOrgYaml(after, parseYaml2);
10183
+ if (wrong) return json({ error: wrong }, 400);
10184
+ const committed = await commitFile(
10185
+ portal,
10186
+ actor.gh,
10187
+ portal.opsName,
10188
+ "org.yaml",
10189
+ after,
10190
+ existing ? `portal: change who has ${id}` : `portal: connect ${id}`,
10191
+ before
10192
+ );
10193
+ return json({ ok: true, stored, committed });
10194
+ }
10078
10195
  var JSON_TYPE = "application/json; charset=utf-8";
10079
10196
  function json(data, status = 200) {
10080
10197
  return text(JSON.stringify(data), JSON_TYPE, status);
@@ -10837,6 +10954,16 @@ async function portalCommand(argv) {
10837
10954
  res.end(portalIndex());
10838
10955
  return;
10839
10956
  }
10957
+ if (url.pathname === "/icon") {
10958
+ const icon = ws ? orgIcon(ws.opsDir) : null;
10959
+ if (!icon) {
10960
+ res.writeHead(404).end("not found");
10961
+ return;
10962
+ }
10963
+ res.writeHead(200, { "content-type": icon.type, "cache-control": "no-store" });
10964
+ res.end(readFileSync14(icon.path));
10965
+ return;
10966
+ }
10840
10967
  if (url.pathname.startsWith("/assets/")) {
10841
10968
  const asset = portalAsset(decodeURIComponent(url.pathname.slice("/assets/".length)));
10842
10969
  if (!asset) {