@nanocollective/roster 0.1.0-beta.3 → 0.1.0-beta.4

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
@@ -7548,12 +7548,14 @@ function isTextPath(path, size2) {
7548
7548
  return size2 <= MAX_TEXT && !BINARY.test(path);
7549
7549
  }
7550
7550
  var Snapshots = class {
7551
- constructor(kv, freshMs = 4e3) {
7551
+ constructor(kv, freshMs = 4e3, shareInflight = true) {
7552
7552
  this.kv = kv;
7553
7553
  this.freshMs = freshMs;
7554
+ this.shareInflight = shareInflight;
7554
7555
  }
7555
7556
  kv;
7556
7557
  freshMs;
7558
+ shareInflight;
7557
7559
  repos = /* @__PURE__ */ new Map();
7558
7560
  inflight = /* @__PURE__ */ new Map();
7559
7561
  checked = /* @__PURE__ */ new Map();
@@ -7573,13 +7575,20 @@ var Snapshots = class {
7573
7575
  if (!opts.force && this.repos.has(repo) && Date.now() - last < this.freshMs) {
7574
7576
  return Promise.resolve({ ok: true, changed: false });
7575
7577
  }
7578
+ const pathsOnly = opts.pathsOnly === true;
7579
+ if (!this.shareInflight) {
7580
+ return this.load(gh, repo, pathsOnly, (step) => opts.report?.(repo, step));
7581
+ }
7576
7582
  if (opts.report) {
7577
7583
  if (!this.listeners.has(repo)) this.listeners.set(repo, /* @__PURE__ */ new Set());
7578
7584
  this.listeners.get(repo).add(opts.report);
7579
7585
  }
7580
7586
  const running = this.inflight.get(repo);
7581
7587
  if (running) return running;
7582
- const work = this.load(gh, repo, opts.pathsOnly === true).finally(() => {
7588
+ const say = (step) => {
7589
+ for (const report3 of this.listeners.get(repo) ?? []) report3(repo, step);
7590
+ };
7591
+ const work = this.load(gh, repo, pathsOnly, say).finally(() => {
7583
7592
  this.inflight.delete(repo);
7584
7593
  this.listeners.delete(repo);
7585
7594
  });
@@ -7603,11 +7612,8 @@ var Snapshots = class {
7603
7612
  if (commit2) snap.sha = commit2;
7604
7613
  void this.kv.put(`blob:${sha}`, text2);
7605
7614
  }
7606
- say(repo, step) {
7607
- for (const report3 of this.listeners.get(repo) ?? []) report3(repo, step);
7608
- }
7609
- async load(gh, repo, pathsOnly) {
7610
- this.say(repo, "checking for changes");
7615
+ async load(gh, repo, pathsOnly, say) {
7616
+ say("checking for changes");
7611
7617
  const head2 = await gh.request("GET", `repos/${repo}/commits/HEAD`, {
7612
7618
  accept: "application/vnd.github.sha",
7613
7619
  as: "text"
@@ -7619,16 +7625,16 @@ var Snapshots = class {
7619
7625
  const sha = head2.data.trim();
7620
7626
  const before = this.repos.get(repo);
7621
7627
  if (before && before.sha === sha && before.pathsOnly === pathsOnly) {
7622
- this.say(repo, "up to date");
7628
+ say("up to date");
7623
7629
  return { ok: true, changed: false };
7624
7630
  }
7625
- this.say(repo, "reading the file list");
7626
- const next = await this.build(gh, repo, sha, pathsOnly, before);
7631
+ say("reading the file list");
7632
+ const next = await this.build(gh, repo, sha, pathsOnly, say, before);
7627
7633
  if (!next.ok) return { ok: false, changed: false, error: next.error, status: next.status };
7628
7634
  this.repos.set(repo, next.snap);
7629
7635
  return { ok: true, changed: true };
7630
7636
  }
7631
- async build(gh, repo, sha, pathsOnly, before) {
7637
+ async build(gh, repo, sha, pathsOnly, say, before) {
7632
7638
  const [tree, commit2] = await Promise.all([
7633
7639
  gh.request(
7634
7640
  "GET",
@@ -7671,7 +7677,7 @@ var Snapshots = class {
7671
7677
  })
7672
7678
  );
7673
7679
  if (missing2.length > TARBALL_OVER) {
7674
- this.say(repo, "downloading the repository");
7680
+ say("downloading the repository");
7675
7681
  const tgz = await gh.request("GET", `repos/${repo}/tarball/${sha}`, {
7676
7682
  as: "bytes"
7677
7683
  });
@@ -7687,7 +7693,7 @@ var Snapshots = class {
7687
7693
  }
7688
7694
  } else {
7689
7695
  if (missing2.length) {
7690
- this.say(repo, `fetching ${missing2.length} changed file${missing2.length === 1 ? "" : "s"}`);
7696
+ say(`fetching ${missing2.length} changed file${missing2.length === 1 ? "" : "s"}`);
7691
7697
  }
7692
7698
  await pool2(missing2, 8, async ([, e]) => {
7693
7699
  const res = await gh.request("GET", `repos/${repo}/git/blobs/${e.sha}`, {
@@ -7701,7 +7707,7 @@ var Snapshots = class {
7701
7707
  void this.kv.put(`blob:${e.sha}`, text2);
7702
7708
  });
7703
7709
  }
7704
- await this.dates(gh, repo, snap, before);
7710
+ await this.dates(gh, repo, snap, say, before);
7705
7711
  return { ok: true, snap };
7706
7712
  }
7707
7713
  /**
@@ -7711,7 +7717,7 @@ var Snapshots = class {
7711
7717
  * GitHub, in batches, only for the ones that are new or changed. Kept by commit, so a warm
7712
7718
  * start never asks at all.
7713
7719
  */
7714
- async dates(gh, repo, snap, before) {
7720
+ async dates(gh, repo, snap, say, before) {
7715
7721
  const key = `dates:${repo}@${snap.sha}`;
7716
7722
  const kept = await this.kv.get(key);
7717
7723
  if (kept) {
@@ -7726,7 +7732,7 @@ var Snapshots = class {
7726
7732
  else ask.push(path);
7727
7733
  }
7728
7734
  const [owner, name] = repo.split("/");
7729
- if (ask.length) this.say(repo, "reading file dates");
7735
+ if (ask.length) say("reading file dates");
7730
7736
  for (let i = 0; i < ask.length; i += DATES_PER_QUERY) {
7731
7737
  const batch = ask.slice(i, i + DATES_PER_QUERY);
7732
7738
  const fields = batch.map(
@@ -7812,7 +7818,7 @@ var TTL = 45e3;
7812
7818
  var LABEL_TTL = 3e5;
7813
7819
  function createPortal(opts) {
7814
7820
  const root2 = opts.root ?? `/@roster/${opts.org}`;
7815
- const snapshots = new Snapshots(opts.kv);
7821
+ const snapshots = new Snapshots(opts.kv, void 0, opts.shareInflight ?? true);
7816
7822
  mount(
7817
7823
  root2,
7818
7824
  snapshots.tree((repo) => repo.slice(repo.indexOf("/") + 1))
@@ -2994,12 +2994,14 @@ function isTextPath(path, size2) {
2994
2994
  return size2 <= MAX_TEXT && !BINARY.test(path);
2995
2995
  }
2996
2996
  var Snapshots = class {
2997
- constructor(kv, freshMs = 4e3) {
2997
+ constructor(kv, freshMs = 4e3, shareInflight = true) {
2998
2998
  this.kv = kv;
2999
2999
  this.freshMs = freshMs;
3000
+ this.shareInflight = shareInflight;
3000
3001
  }
3001
3002
  kv;
3002
3003
  freshMs;
3004
+ shareInflight;
3003
3005
  repos = /* @__PURE__ */ new Map();
3004
3006
  inflight = /* @__PURE__ */ new Map();
3005
3007
  checked = /* @__PURE__ */ new Map();
@@ -3019,13 +3021,20 @@ var Snapshots = class {
3019
3021
  if (!opts.force && this.repos.has(repo) && Date.now() - last < this.freshMs) {
3020
3022
  return Promise.resolve({ ok: true, changed: false });
3021
3023
  }
3024
+ const pathsOnly = opts.pathsOnly === true;
3025
+ if (!this.shareInflight) {
3026
+ return this.load(gh, repo, pathsOnly, (step) => opts.report?.(repo, step));
3027
+ }
3022
3028
  if (opts.report) {
3023
3029
  if (!this.listeners.has(repo)) this.listeners.set(repo, /* @__PURE__ */ new Set());
3024
3030
  this.listeners.get(repo).add(opts.report);
3025
3031
  }
3026
3032
  const running = this.inflight.get(repo);
3027
3033
  if (running) return running;
3028
- const work = this.load(gh, repo, opts.pathsOnly === true).finally(() => {
3034
+ const say = (step) => {
3035
+ for (const report of this.listeners.get(repo) ?? []) report(repo, step);
3036
+ };
3037
+ const work = this.load(gh, repo, pathsOnly, say).finally(() => {
3029
3038
  this.inflight.delete(repo);
3030
3039
  this.listeners.delete(repo);
3031
3040
  });
@@ -3049,11 +3058,8 @@ var Snapshots = class {
3049
3058
  if (commit2) snap.sha = commit2;
3050
3059
  void this.kv.put(`blob:${sha}`, text2);
3051
3060
  }
3052
- say(repo, step) {
3053
- for (const report of this.listeners.get(repo) ?? []) report(repo, step);
3054
- }
3055
- async load(gh, repo, pathsOnly) {
3056
- this.say(repo, "checking for changes");
3061
+ async load(gh, repo, pathsOnly, say) {
3062
+ say("checking for changes");
3057
3063
  const head2 = await gh.request("GET", `repos/${repo}/commits/HEAD`, {
3058
3064
  accept: "application/vnd.github.sha",
3059
3065
  as: "text"
@@ -3065,16 +3071,16 @@ var Snapshots = class {
3065
3071
  const sha = head2.data.trim();
3066
3072
  const before = this.repos.get(repo);
3067
3073
  if (before && before.sha === sha && before.pathsOnly === pathsOnly) {
3068
- this.say(repo, "up to date");
3074
+ say("up to date");
3069
3075
  return { ok: true, changed: false };
3070
3076
  }
3071
- this.say(repo, "reading the file list");
3072
- const next = await this.build(gh, repo, sha, pathsOnly, before);
3077
+ say("reading the file list");
3078
+ const next = await this.build(gh, repo, sha, pathsOnly, say, before);
3073
3079
  if (!next.ok) return { ok: false, changed: false, error: next.error, status: next.status };
3074
3080
  this.repos.set(repo, next.snap);
3075
3081
  return { ok: true, changed: true };
3076
3082
  }
3077
- async build(gh, repo, sha, pathsOnly, before) {
3083
+ async build(gh, repo, sha, pathsOnly, say, before) {
3078
3084
  const [tree, commit2] = await Promise.all([
3079
3085
  gh.request(
3080
3086
  "GET",
@@ -3117,7 +3123,7 @@ var Snapshots = class {
3117
3123
  })
3118
3124
  );
3119
3125
  if (missing2.length > TARBALL_OVER) {
3120
- this.say(repo, "downloading the repository");
3126
+ say("downloading the repository");
3121
3127
  const tgz = await gh.request("GET", `repos/${repo}/tarball/${sha}`, {
3122
3128
  as: "bytes"
3123
3129
  });
@@ -3133,7 +3139,7 @@ var Snapshots = class {
3133
3139
  }
3134
3140
  } else {
3135
3141
  if (missing2.length) {
3136
- this.say(repo, `fetching ${missing2.length} changed file${missing2.length === 1 ? "" : "s"}`);
3142
+ say(`fetching ${missing2.length} changed file${missing2.length === 1 ? "" : "s"}`);
3137
3143
  }
3138
3144
  await pool2(missing2, 8, async ([, e]) => {
3139
3145
  const res = await gh.request("GET", `repos/${repo}/git/blobs/${e.sha}`, {
@@ -3147,7 +3153,7 @@ var Snapshots = class {
3147
3153
  void this.kv.put(`blob:${e.sha}`, text2);
3148
3154
  });
3149
3155
  }
3150
- await this.dates(gh, repo, snap, before);
3156
+ await this.dates(gh, repo, snap, say, before);
3151
3157
  return { ok: true, snap };
3152
3158
  }
3153
3159
  /**
@@ -3157,7 +3163,7 @@ var Snapshots = class {
3157
3163
  * GitHub, in batches, only for the ones that are new or changed. Kept by commit, so a warm
3158
3164
  * start never asks at all.
3159
3165
  */
3160
- async dates(gh, repo, snap, before) {
3166
+ async dates(gh, repo, snap, say, before) {
3161
3167
  const key = `dates:${repo}@${snap.sha}`;
3162
3168
  const kept = await this.kv.get(key);
3163
3169
  if (kept) {
@@ -3172,7 +3178,7 @@ var Snapshots = class {
3172
3178
  else ask.push(path);
3173
3179
  }
3174
3180
  const [owner, name] = repo.split("/");
3175
- if (ask.length) this.say(repo, "reading file dates");
3181
+ if (ask.length) say("reading file dates");
3176
3182
  for (let i = 0; i < ask.length; i += DATES_PER_QUERY) {
3177
3183
  const batch = ask.slice(i, i + DATES_PER_QUERY);
3178
3184
  const fields = batch.map(
@@ -3258,7 +3264,7 @@ var TTL = 45e3;
3258
3264
  var LABEL_TTL = 3e5;
3259
3265
  function createPortal(opts) {
3260
3266
  const root2 = opts.root ?? `/@roster/${opts.org}`;
3261
- const snapshots = new Snapshots(opts.kv);
3267
+ const snapshots = new Snapshots(opts.kv, void 0, opts.shareInflight ?? true);
3262
3268
  mount(
3263
3269
  root2,
3264
3270
  snapshots.tree((repo) => repo.slice(repo.indexOf("/") + 1))
@@ -4398,7 +4404,13 @@ function boot(env) {
4398
4404
  useFrameworkRoot(FRAMEWORK);
4399
4405
  const kv = cloudflareKV(env.CACHE);
4400
4406
  useRecordStore(recordStore(kv));
4401
- portal = createPortal({ org: env.ROSTER_ORG, opsName: env.ROSTER_OPS_REPO ?? "roster-ops", kv });
4407
+ portal = createPortal({
4408
+ org: env.ROSTER_ORG,
4409
+ opsName: env.ROSTER_OPS_REPO ?? "roster-ops",
4410
+ kv,
4411
+ // A Worker request that awaits a fetch another request started never finishes.
4412
+ shareInflight: false
4413
+ });
4402
4414
  return portal;
4403
4415
  }
4404
4416
  function clientFor(token) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nanocollective/roster",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.4",
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": {