@join-pantheon/cli 0.37.0-rc.1 → 0.37.0

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/accounts.js CHANGED
@@ -383,6 +383,7 @@ export class Accounts {
383
383
  pending_label = excluded.pending_label, expires_at = excluded.expires_at,
384
384
  attempts = 0, created_at = excluded.created_at
385
385
  `).run(e, sha(code), purpose, purpose === "signup" ? normalizeUsername(opts.username) : null, key, opts.label, t + CODE_TTL_MS, t);
386
+ this.db.prepare("DELETE FROM link_confirms WHERE email = ? AND pending_pubkey = ?").run(e, key);
386
387
  return { ok: true, code };
387
388
  }
388
389
  failsOf(key, t = now()) {
@@ -505,15 +506,19 @@ export class Accounts {
505
506
  .run(sha(token), e, pubkey, words, o.label.slice(0, 60), o.ip, v.expires_at, now());
506
507
  return { token, words };
507
508
  }
509
+ linkStillLive(r) {
510
+ const v = this.db.prepare("SELECT expires_at FROM verifications_by_device WHERE email = ? AND pending_pubkey = ? AND purpose != 'viewer'").get(r.email, r.pending_pubkey);
511
+ return !!v && v.expires_at === r.expires_at;
512
+ }
508
513
  linkInfo(token) {
509
514
  const r = this.db.prepare("SELECT * FROM link_confirms WHERE token_hash = ?").get(sha(token));
510
- if (!r || r.voided || now() > r.expires_at)
515
+ if (!r || r.voided || now() > r.expires_at || !this.linkStillLive(r))
511
516
  return null;
512
517
  return { label: r.label ?? "a device", ip: r.ip ?? "", created_at: r.created_at, email: r.email };
513
518
  }
514
519
  confirmLink(token, typed, ip) {
515
520
  const r = this.db.prepare("SELECT * FROM link_confirms WHERE token_hash = ?").get(sha(token));
516
- if (!r || r.voided || now() > r.expires_at)
521
+ if (!r || r.voided || now() > r.expires_at || !this.linkStillLive(r))
517
522
  return { ok: false, reason: "no_link" };
518
523
  const words = typed.toLowerCase().replace(/[^a-z]+/g, " ").trim();
519
524
  if (!/^[a-z]+ [a-z]+$/.test(words))
package/dist/cli.js CHANGED
@@ -132,6 +132,7 @@ async function signedFetch(cfg, method, path, params = {}) {
132
132
  }
133
133
  return res;
134
134
  }
135
+ const FLAG_SIGNIN_POST_MS = 30_000;
135
136
  function wantsFlagSignIn() {
136
137
  return flag("email") !== undefined || flag("code") !== undefined || argv.includes("--continue");
137
138
  }
@@ -139,20 +140,23 @@ async function flagSignIn(which, relay, joining) {
139
140
  const base = relay.replace(/^ws/, "http").replace(/\/+$/, "");
140
141
  let why = "";
141
142
  const deps = {
142
- post: (path, body) => fetch(`${base}${path}`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) })
143
+ post: (path, body) => fetch(`${base}${path}`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body), signal: AbortSignal.timeout(FLAG_SIGNIN_POST_MS) })
143
144
  .then(async (x) => ({ status: x.status, j: await relayJson(x, `${base}${path}`) }))
144
145
  .catch(async (e) => { why = await describeRelayFailure(e, relay); return null; }),
145
146
  unreachable: () => why,
146
147
  identity: () => identity(),
147
148
  saveLocked: (fn) => withConfigLock(() => { const next = fn(identity()); save({ ...next, relay: next.relay || relay }); return next; }),
148
149
  newKeypair,
149
- status: async () => {
150
+ status: async (timeoutMs) => {
150
151
  const me = identity();
151
152
  if (!me?.publicKey || !me.privateKey)
152
153
  return null;
153
154
  const ts = Date.now(), nonce = randomBytes(18).toString("base64url");
154
- return fetch(`${base}/auth/status`, { headers: { "x-pantheon-key": me.publicKey, "x-pantheon-ts": String(ts), "x-pantheon-nonce": nonce, "x-pantheon-sig": signStatus(me.privateKey, me.publicKey, ts, nonce, me.pendingAuth?.aud ?? new URL(base).host) } })
155
- .then(async (x) => ({ status: x.status, j: await relayJson(x, `${base}/auth/status`) }))
155
+ return fetch(`${base}/auth/status`, { headers: { "x-pantheon-key": me.publicKey, "x-pantheon-ts": String(ts), "x-pantheon-nonce": nonce, "x-pantheon-sig": signStatus(me.privateKey, me.publicKey, ts, nonce, me.pendingAuth?.aud ?? new URL(base).host) }, signal: AbortSignal.timeout(timeoutMs) })
156
+ .then(async (x) => {
157
+ const after = Number(x.headers.get("retry-after"));
158
+ return { status: x.status, j: await relayJson(x, `${base}/auth/status`), ...(x.status === 429 && Number.isFinite(after) && after > 0 ? { retryAfter: Math.min(after, 60) } : {}) };
159
+ })
156
160
  .catch(async (e) => { why = await describeRelayFailure(e, relay); return null; });
157
161
  },
158
162
  label: flag("label") ?? deviceLabel(),
package/dist/config.js CHANGED
@@ -667,10 +667,11 @@ export function fromInvite(invite) {
667
667
  }
668
668
  export const INVITE_CODE = /^[A-Za-z0-9_-]{16,64}$/;
669
669
  export const looksLikeInviteCode = (s) => INVITE_CODE.test(s.trim().replace(/^['"`]|['"`]$/g, ""));
670
- export async function resolveInviteCode(code, relays, fetchImpl = fetch) {
670
+ export async function resolveInviteCode(code, relays, fetchImpl = fetch, sleep = (ms) => new Promise((r) => setTimeout(r, ms))) {
671
671
  const token = code.trim().replace(/^['"`]|['"`]$/g, "");
672
672
  const tried = [...new Set(relays.map((r) => r.replace(/\/+$/, "")).filter(Boolean))];
673
673
  let answered = false;
674
+ let busy, waited = false;
674
675
  let nonJsonFrom;
675
676
  const json = async (res, relay) => {
676
677
  const text = await res.text();
@@ -685,7 +686,30 @@ export async function resolveInviteCode(code, relays, fetchImpl = fetch) {
685
686
  for (const relay of tried) {
686
687
  const http = relay.replace(/^ws/, "http");
687
688
  try {
688
- const res = await fetchImpl(`${http}/join?token=${encodeURIComponent(token)}`, { signal: AbortSignal.timeout(6_000) });
689
+ const ask = () => fetchImpl(`${http}/join?token=${encodeURIComponent(token)}`, { signal: AbortSignal.timeout(6_000) });
690
+ const lookupsBusy = async (r) => {
691
+ if (r.status !== 429)
692
+ return null;
693
+ const j = await json(r, relay);
694
+ if (j?.reason !== "lookups_busy")
695
+ return null;
696
+ const after = Number(r.headers.get("retry-after"));
697
+ return Number.isFinite(after) && after > 0 ? after : 10;
698
+ };
699
+ let res = await ask();
700
+ let after = await lookupsBusy(res);
701
+ if (after !== null && after <= 20 && !waited) {
702
+ waited = true;
703
+ await sleep(after * 1000);
704
+ res = await ask();
705
+ after = await lookupsBusy(res);
706
+ }
707
+ if (after !== null) {
708
+ busy ??= relay;
709
+ continue;
710
+ }
711
+ if (res.status === 429)
712
+ continue;
689
713
  if (res.status === 404) {
690
714
  const j = await json(res, relay);
691
715
  answered = (!!j && typeof j === "object") || answered;
@@ -702,6 +726,9 @@ export async function resolveInviteCode(code, relays, fetchImpl = fetch) {
702
726
  catch { }
703
727
  }
704
728
  const hosts = tried.map((r) => new URL(r).host).join(", ");
729
+ if (busy) {
730
+ throw new Error(`INVITE_CODE_UNREACHABLE: ${new URL(busy).host} is busy with invite lookups from your network just now.\n Wait a minute, then run the same command again — or paste the whole invite line: pantheon join https://www.joinpantheon.network/join/<team>#${token}`);
731
+ }
705
732
  if (answered) {
706
733
  throw new Error(`INVITE_CODE_UNKNOWN: that is an invite code, but no open invite on ${hosts} matches it — it may have been used already or expired (they last 24 hours).\n Ask your teammate for a fresh one: pantheon invite`);
707
734
  }
@@ -162,7 +162,7 @@ export function welcomeEmailHtml(to, joining) {
162
162
  <tr>
163
163
  <td width="34" valign="top" style="padding:2px 0 16px"><span style="display:inline-block;width:24px;height:24px;line-height:24px;border-radius:12px;background:#e0aa3e;color:#1b1917;font-weight:700;text-align:center;font-size:13px">1</span></td>
164
164
  <td valign="top" style="padding:2px 0 16px">${joining !== undefined
165
- ? `<b>You're joining ${joining ? esc(joining) : "your teammate's team"}.</b> Once it finishes, your agent can reach your teammates' agents.
165
+ ? `<b>You're joining ${joining ? esc(joining) : "your teammate's team"}.</b> Once setup finishes, your agent can reach your teammates' agents.
166
166
  <span style="color:#6b6257">If your coding agent was open while you joined, quit and reopen it once.</span>`
167
167
  : `<b>Bring one teammate.</b> Run:
168
168
  <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="margin-top:8px"><tr><td style="background:#1b1917;border-radius:8px;padding:12px 16px;font-family:'Space Mono',Menlo,Consolas,monospace;font-size:14px;color:#f1e7d3"><span style="color:#e36f55">$</span> pantheon invite</td></tr></table>
@@ -213,7 +213,7 @@ export function welcomeEmailText(to, joining) {
213
213
  "",
214
214
  "Your first hand-off:",
215
215
  ...(joining !== undefined
216
- ? [`1. You're joining ${joining || "your teammate's team"}. Once it finishes, your agent can reach your teammates' agents.`,
216
+ ? [`1. You're joining ${joining || "your teammate's team"}. Once setup finishes, your agent can reach your teammates' agents.`,
217
217
  " If your coding agent was open while you joined, quit and reopen it once."]
218
218
  : ["1. Bring one teammate. Run: pantheon invite",
219
219
  " It prints a link that works once, for 24 hours. Send it to them."]),
@@ -127,13 +127,15 @@ export async function requestCode(o) {
127
127
  if (login.status === 404 && !noAccount) {
128
128
  return { kind: "error", exit: "failed", message: "this relay has no email accounts — no sign-in is needed: run the same command without --email" };
129
129
  }
130
+ const chosen = o.username ?? (pend && pend.purpose === "signup" && pend.username && normalizeEmail(pend.email) === normalizeEmail(email)
131
+ && typeof pend.at === "number" && deps.now() - pend.at < RESUME_MS ? pend.username : undefined);
130
132
  if (noAccount) {
131
- if (o.username === undefined) {
133
+ if (chosen === undefined) {
132
134
  const suggested = usernameSuggestion(email, deps.gitEmail) || null;
133
135
  saveResumeOnly(deps, withKey, email, o.resume);
134
136
  return needsUsername(cmd, deps, email, suggested, `there is no Pantheon account for ${email} yet.`);
135
137
  }
136
- username = o.username.trim();
138
+ username = chosen.trim();
137
139
  purpose = "signup";
138
140
  const up = await deps.post("/auth/signup", { email, username, pubkey, label: deps.label, link: true, ...(o.joining ? { joining: o.joining } : {}) });
139
141
  if (!up)
@@ -158,12 +160,16 @@ export async function requestCode(o) {
158
160
  if (res.status !== 200 && !tooSoon) {
159
161
  return { kind: "error", exit: "failed", message: String(res.j.error ?? `sign-in failed (${res.status})`) };
160
162
  }
161
- if (tooSoon && !(pendNow && typeof pendNow.at === "number" && normalizeEmail(pendNow.email) === normalizeEmail(email))) {
163
+ if (tooSoon && !(pendNow && typeof pendNow.at === "number" && normalizeEmail(pendNow.email) === normalizeEmail(email) && deps.now() - pendNow.at < CODE_REUSE_MS)) {
162
164
  return { kind: "error", exit: "failed", message: `a code for ${email} was asked for a moment ago from another device, and it would not work on this one. Wait a minute, then run this again.` };
163
165
  }
164
166
  if (res.status === 200 && res.j.sent === false && res.j.via === "resend") {
165
167
  return { kind: "error", exit: "failed", message: "the relay could not send the email just now — run the same command again in a minute" };
166
168
  }
169
+ if (tooSoon)
170
+ username = pendNow?.purpose === "signup" ? pendNow.username : undefined;
171
+ if (tooSoon && pendNow?.purpose)
172
+ purpose = pendNow.purpose;
167
173
  const at = tooSoon && pendNow?.at ? pendNow.at : deps.now();
168
174
  const words = typeof res.j.words === "string" && /^[a-z]+ [a-z]+$/.test(res.j.words) ? res.j.words : tooSoon ? pendNow?.words : undefined;
169
175
  const aud = typeof res.j.status_aud === "string" && /^[A-Za-z0-9.:\[\]-]{1,255}$/.test(res.j.status_aud) ? res.j.status_aud : tooSoon ? pendNow?.aud : undefined;
@@ -251,6 +257,17 @@ export async function enterCode(o) {
251
257
  json: { needs: "code", sent_to: pend.email, retry: !spent, ...(typeof v.j.tries_left === "number" ? { tries_left: v.j.tries_left } : {}), next: again },
252
258
  };
253
259
  }
260
+ const LATE = Symbol("late");
261
+ async function withinMs(p, ms) {
262
+ let timer;
263
+ const late = new Promise((res) => { timer = setTimeout(() => res(LATE), ms); });
264
+ try {
265
+ return await Promise.race([p, late]);
266
+ }
267
+ finally {
268
+ clearTimeout(timer);
269
+ }
270
+ }
254
271
  export const CONTINUE_WAIT_MS = 90_000;
255
272
  export const CONTINUE_EVERY_MS = 5_000;
256
273
  export async function awaitLink(o) {
@@ -264,11 +281,16 @@ export async function awaitLink(o) {
264
281
  }
265
282
  const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
266
283
  const until = deps.now() + (o.waitMs ?? CONTINUE_WAIT_MS);
267
- let reached = false;
284
+ const every = o.everyMs ?? CONTINUE_EVERY_MS;
285
+ let reached = false, late = false, throttled = false;
268
286
  for (;;) {
269
- const r = await deps.status();
270
- if (r) {
287
+ const budget = Math.max(250, until - deps.now());
288
+ const r = await withinMs(deps.status(budget), budget);
289
+ late = r === LATE;
290
+ throttled = false;
291
+ if (r && r !== LATE) {
271
292
  reached = true;
293
+ throttled = r.status === 429 && r.j.reason !== "too_often";
272
294
  if (r.status === 200 && r.j.state === "confirmed") {
273
295
  const acct = r.j.account;
274
296
  if (normalizeEmail(acct.email) !== normalizeEmail(pend.email)) {
@@ -289,13 +311,21 @@ export async function awaitLink(o) {
289
311
  return { kind: "needs_person", needs: "code", lines: ["That sign-in has expired or was used up.", `Get a new code and link: ${again}`], json: { needs: "code", sent_to: pend.email, retry: false, next: again } };
290
312
  }
291
313
  }
292
- if (deps.now() >= until)
314
+ if (until - deps.now() < 250)
293
315
  break;
294
- await sleep(o.everyMs ?? CONTINUE_EVERY_MS);
316
+ const wait = r && r !== LATE && r.status === 429 && r.retryAfter ? Math.max(every, r.retryAfter * 1000) : every;
317
+ await sleep(Math.max(0, Math.min(wait, until - deps.now())));
295
318
  }
296
319
  if (!reached)
297
- return { kind: "error", exit: "network", message: `could not reach the relay: ${deps.unreachable()} — run the same command again` };
320
+ return { kind: "error", exit: "network", message: `could not reach the relay: ${late ? "it did not answer in time" : deps.unreachable()} — run the same command again` };
298
321
  const nxt = next(cmd, deps, "code"), cont = deps.command(`${cmd} --continue`);
322
+ if (throttled) {
323
+ return {
324
+ kind: "needs_person", needs: "code",
325
+ lines: [`Pantheon's server is busy with sign-ins from this network, so it could not check yet. If the words were typed in the link, it may already be done: run this again in a minute: ${cont}`, `Or give the 6-digit code: ${nxt}`],
326
+ json: { needs: "code", sent_to: pend.email, busy: true, next: nxt, ...(pend.words ? { link: true, words: pend.words, next_link: cont } : {}) },
327
+ };
328
+ }
299
329
  return {
300
330
  kind: "needs_person", needs: "code",
301
331
  lines: [`Not confirmed yet.${pend.words ? ` In the email's link, type ${pend.words.toUpperCase()}, then run: ${cont}` : ""}`, `Or give the 6-digit code: ${nxt}`],
package/dist/relay.js CHANGED
@@ -364,6 +364,9 @@ function firstLedgerName(file) {
364
364
  }
365
365
  }
366
366
  const GOAL_OPENED = /^goal opened: ([^\n]*)\nacceptance: ([\s\S]*?)(?:\ndeadline: (\S+))?(?:\nkind: (\w+)[\s\S]*)?$/;
367
+ const STATUS_PER_NETWORK = 1_200;
368
+ const AUTH_PER_ADDRESS = 120;
369
+ const JOIN_LOOKUPS_PER_ADDRESS = 20;
367
370
  const LIMITS_GOAL_READ = 1000;
368
371
  function repoLabelSafe(v) {
369
372
  if (!v)
@@ -961,8 +964,8 @@ export class Relay {
961
964
  return;
962
965
  }
963
966
  if (url.pathname === "/join") {
964
- if (!this.authRateOk(ip))
965
- return this.json(res, 429, { error: "too many lookups from your network — wait a minute" });
967
+ if (!this.localTrusted(ip) && !this.hitsOk(this.joinHits, ip, JOIN_LOOKUPS_PER_ADDRESS))
968
+ return this.json(res, 429, { error: "too many lookups from your network — wait a minute", reason: "lookups_busy" }, { "retry-after": String(this.retryAfter(this.joinHits, ip)) });
966
969
  const token = (url.searchParams.get("token") ?? "").trim();
967
970
  if (!/^[A-Za-z0-9_-]{16,64}$/.test(token))
968
971
  return this.json(res, 400, { error: "an invite code is required: /join?token=<code>" });
@@ -1370,12 +1373,12 @@ export class Relay {
1370
1373
  const ts = Number(req.headers["x-pantheon-ts"] ?? NaN), sig = String(req.headers["x-pantheon-sig"] ?? "");
1371
1374
  if (!key || key.length > 200 || !canonicalKey(key) || !/^[A-Za-z0-9_-]{16,64}$/.test(nonce) || !Number.isFinite(ts) || Math.abs(Date.now() - ts) > 120_000)
1372
1375
  return this.json(res, 400, { error: "a signed status request needs x-pantheon-key, -ts (within 2 minutes), -nonce and -sig" });
1373
- if (!this.localTrusted(ip) && !this.hitsOk(this.statusIpHits, ip, 120))
1374
- return this.json(res, 429, { error: "too many requests from your network — wait a minute" });
1376
+ if (!this.localTrusted(ip) && !this.networkStatusOk(netOf(ip)))
1377
+ return this.json(res, 429, { error: "too many requests from your network — wait a minute", reason: "network_busy" }, { "retry-after": String(this.networkStatusRetry(netOf(ip))) });
1375
1378
  if (!verifyStatus(key, ts, nonce, sig, this.statusAudience(req)))
1376
1379
  return this.json(res, 403, { error: "this request must be signed by the device that is signing in, for this relay" });
1377
1380
  if (!this.statusBudgetOk(key))
1378
- return this.json(res, 429, { error: "asking too often — once every few seconds is enough" });
1381
+ return this.json(res, 429, { error: "asking too often — once every few seconds is enough", reason: "too_often" }, { "retry-after": String(this.retryAfter(this.statusHits, key)) });
1379
1382
  if (!this.freshNonce(nonce))
1380
1383
  return this.json(res, 403, { error: "that request was already answered" });
1381
1384
  const acct = A.signedInDevice(key);
@@ -1531,7 +1534,7 @@ export class Relay {
1531
1534
  const cap = Number(process.env.PANTHEON_EMAIL_MAX_PER_HOUR) || 200;
1532
1535
  const reserved = Math.min(cap - 1, Math.max(0, Number(process.env.PANTHEON_EMAIL_RESERVED_PER_HOUR ?? Math.floor(cap / 4)) || 0));
1533
1536
  const perAddress = Number(process.env.PANTHEON_EMAIL_MAX_PER_ADDRESS) || 5;
1534
- const perNet = Number(process.env.PANTHEON_EMAIL_MAX_PER_NETWORK) || 20;
1537
+ const perNet = Number(process.env.PANTHEON_EMAIL_MAX_PER_NETWORK) || 100;
1535
1538
  if (live(this.emailSendsTo.get(this.emailBucket(email, pubkey, own)) ?? []).length >= perAddress) {
1536
1539
  return own ? "this device has asked for too many codes in the last hour — use the latest one, or try again in an hour"
1537
1540
  : "too many codes were sent to this address in the last hour — use the latest one, or try again in an hour";
@@ -1583,29 +1586,59 @@ export class Relay {
1583
1586
  return String(req.headers.host ?? "");
1584
1587
  }
1585
1588
  statusHits = new Map();
1586
- statusIpHits = new Map();
1589
+ joinHits = new Map();
1590
+ statusIpWindow = new Map();
1591
+ networkStatusOk(net) {
1592
+ const t = Date.now();
1593
+ let w = this.statusIpWindow.get(net);
1594
+ if (!w || t - w.from >= 60_000) {
1595
+ if (this.statusIpWindow.size > 10_000)
1596
+ for (const [k, v] of this.statusIpWindow)
1597
+ if (t - v.from >= 60_000)
1598
+ this.statusIpWindow.delete(k);
1599
+ w = { from: t, n: 0 };
1600
+ this.statusIpWindow.set(net, w);
1601
+ }
1602
+ if (w.n >= STATUS_PER_NETWORK)
1603
+ return false;
1604
+ w.n++;
1605
+ return true;
1606
+ }
1607
+ networkStatusRetry(net) {
1608
+ const w = this.statusIpWindow.get(net);
1609
+ return w ? Math.min(60, Math.max(1, Math.ceil((w.from + 60_000 - Date.now()) / 1000))) : 1;
1610
+ }
1587
1611
  hitsOk(map, key, limit) {
1588
1612
  const t = Date.now();
1589
1613
  const recent = (map.get(key) ?? []).filter((x) => t - x < 60_000);
1590
- recent.push(t);
1614
+ const ok = recent.length < limit;
1615
+ if (ok)
1616
+ recent.push(t);
1591
1617
  map.set(key, recent);
1592
1618
  if (map.size > 10_000)
1593
1619
  for (const [k, v] of map)
1594
1620
  if (!v.some((x) => t - x < 60_000))
1595
1621
  map.delete(k);
1596
- return recent.length <= limit;
1622
+ return ok;
1623
+ }
1624
+ retryAfter(map, key) {
1625
+ const oldest = (map.get(key) ?? [])[0];
1626
+ return oldest === undefined ? 1 : Math.min(60, Math.max(1, Math.ceil((oldest + 60_000 - Date.now()) / 1000)));
1597
1627
  }
1598
1628
  statusBudgetOk(key) { return this.hitsOk(this.statusHits, key, 40); }
1599
1629
  statusNonces = new Map();
1630
+ statusNonceSweep = 0;
1600
1631
  freshNonce(nonce) {
1601
1632
  const t = Date.now();
1602
1633
  if (this.statusNonces.has(nonce))
1603
1634
  return false;
1604
1635
  this.statusNonces.set(nonce, t);
1605
- if (this.statusNonces.size > 20_000)
1636
+ if (this.statusNonces.size > 20_000 && t - this.statusNonceSweep > 10_000) {
1637
+ this.statusNonceSweep = t;
1606
1638
  for (const [k, v] of this.statusNonces)
1607
1639
  if (t - v > 300_000)
1608
1640
  this.statusNonces.delete(k);
1641
+ }
1609
1642
  return true;
1610
1643
  }
1611
1644
  confirmPage(res, token, o = {}) {
@@ -1677,7 +1710,9 @@ ${body}`;
1677
1710
  return true;
1678
1711
  const now = Date.now();
1679
1712
  const recent = (this.authHits.get(ip) ?? []).filter((t) => now - t < 60_000);
1680
- recent.push(now);
1713
+ const ok = recent.length < AUTH_PER_ADDRESS;
1714
+ if (ok)
1715
+ recent.push(now);
1681
1716
  this.authHits.set(ip, recent);
1682
1717
  if (this.authHits.size > 10_000) {
1683
1718
  for (const [k, v] of this.authHits) {
@@ -1688,7 +1723,7 @@ ${body}`;
1688
1723
  this.authHits.delete(k);
1689
1724
  }
1690
1725
  }
1691
- return recent.length <= 20;
1726
+ return ok;
1692
1727
  }
1693
1728
  readBody(req, res, limit, cb) {
1694
1729
  const HARD = 4 * 1024 * 1024;
@@ -4483,9 +4518,9 @@ pantheon start</code></pre>
4483
4518
  catch { }
4484
4519
  }
4485
4520
  }
4486
- json(res, code, body) {
4521
+ json(res, code, body, headers = {}) {
4487
4522
  const s = JSON.stringify(body);
4488
- res.writeHead(code, { "content-type": "application/json", "content-length": Buffer.byteLength(s) });
4523
+ res.writeHead(code, { ...headers, "content-type": "application/json", "content-length": Buffer.byteLength(s) });
4489
4524
  res.end(s);
4490
4525
  }
4491
4526
  onSocket(ws, ip = "unknown") {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@join-pantheon/cli",
3
- "version": "0.37.0-rc.1",
3
+ "version": "0.37.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@join-pantheon/cli",
9
- "version": "0.37.0-rc.1",
9
+ "version": "0.37.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@modelcontextprotocol/sdk": "^1.32.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@join-pantheon/cli",
3
- "version": "0.37.0-rc.1",
3
+ "version": "0.37.0",
4
4
  "description": "Let your coding agent collaborate directly with your teammates' agents — ask, agree an interface, and deliver, without a human relaying messages.",
5
5
  "type": "module",
6
6
  "bin": {