@inerrata-corporation/errata 2.0.6-dev.2115 → 2.0.6-dev.2157

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/errata.mjs +52 -5
  2. package/package.json +1 -1
package/errata.mjs CHANGED
@@ -23789,7 +23789,8 @@ function renderSnapshot(s) {
23789
23789
  lines.push("");
23790
23790
  lines.push(`### Active workspace profile`);
23791
23791
  lines.push(`- **Name:** ${s.profile.name}`);
23792
- const ctxTag = (e) => e.node && s.edgeElicitation ? `${e.name} \`[${priorHandle(e.node)}]\`` : e.name;
23792
+ const ctxName = (name2) => name2.startsWith("@") ? `\`${name2}\`` : name2;
23793
+ const ctxTag = (e) => e.node && s.edgeElicitation ? `${ctxName(e.name)} \`[${priorHandle(e.node)}]\`` : ctxName(e.name);
23793
23794
  if (s.profileContext.packages.length) {
23794
23795
  lines.push(`- **Stack:** ${s.profileContext.packages.map(ctxTag).join(", ")}`);
23795
23796
  }
@@ -77056,7 +77057,7 @@ function createWatchBreaker(deps) {
77056
77057
  }
77057
77058
 
77058
77059
  // src/engine.ts
77059
- var DAEMON_VERSION = true ? "2.0.6-dev.2115" : "2.0.0-alpha.0";
77060
+ var DAEMON_VERSION = true ? "2.0.6-dev.2157" : "2.0.0-alpha.0";
77060
77061
  var IGNORED_PATH = /[\\/](?:\.git|node_modules|\.errata|\.claude|\.codex|\.cursor|\.turbo|\.next|dist|coverage|test-results|playwright-report|__pycache__)(?:[\\/]|$)/;
77061
77062
  var IGNORED_NOISE = /castalia\.db|eventlog\.sqlite|turn-cursors/;
77062
77063
  var GIT_OP_MUTE_MS = 4e3;
@@ -82572,6 +82573,28 @@ import { execFileSync as execFileSync4 } from "node:child_process";
82572
82573
  import { existsSync as existsSync29, writeFileSync as writeFileSync22 } from "node:fs";
82573
82574
  import { join as join34 } from "node:path";
82574
82575
 
82576
+ // src/device-poll.ts
82577
+ var THROTTLED_POLL_MIN_WAIT_MS = 11e3;
82578
+ var THROTTLED_INTERVAL_CAP_MS = 6e4;
82579
+ function throttledPoll(res, intervalMs) {
82580
+ if (res.status !== 429 && res.status !== 503) return null;
82581
+ const next = Math.max(intervalMs, Math.min(intervalMs + 5e3, THROTTLED_INTERVAL_CAP_MS));
82582
+ return {
82583
+ intervalMs: next,
82584
+ waitMs: Math.max(next, retryAfterMs(res.headers) ?? 0, THROTTLED_POLL_MIN_WAIT_MS)
82585
+ };
82586
+ }
82587
+ function retryAfterMs(headers, now = Date.now()) {
82588
+ for (const name2 of ["retry-after", "x-retry-after"]) {
82589
+ const raw2 = headers.get(name2)?.trim();
82590
+ if (!raw2) continue;
82591
+ if (/^\d+$/.test(raw2)) return Number(raw2) * 1e3;
82592
+ const at = Date.parse(raw2);
82593
+ if (!Number.isNaN(at)) return Math.max(0, at - now);
82594
+ }
82595
+ return null;
82596
+ }
82597
+
82575
82598
  // src/oauth-login.ts
82576
82599
  init_src7();
82577
82600
  init_cloud_auth();
@@ -82626,10 +82649,12 @@ async function loginOAuthDevice(opts) {
82626
82649
  });
82627
82650
  const deadline = Date.now() + Math.min(code.expires_in * 1e3, opts.timeoutMs ?? Number.POSITIVE_INFINITY);
82628
82651
  let intervalMs = Math.max(2, code.interval ?? 5) * 1e3;
82652
+ let waitMs = intervalMs;
82629
82653
  let deviceSession = null;
82630
82654
  let approvedInstallation = null;
82631
82655
  while (Date.now() < deadline) {
82632
- await (opts.sleep ?? ((ms) => new Promise((resolve7) => setTimeout(resolve7, ms))))(intervalMs);
82656
+ await (opts.sleep ?? ((ms) => new Promise((resolve7) => setTimeout(resolve7, ms))))(waitMs);
82657
+ waitMs = intervalMs;
82633
82658
  const poll = await fetchFn(device.token, {
82634
82659
  method: "POST",
82635
82660
  headers: { "content-type": "application/json", accept: "application/json" },
@@ -82641,10 +82666,16 @@ async function loginOAuthDevice(opts) {
82641
82666
  });
82642
82667
  const payload = await poll.json().catch(() => null);
82643
82668
  if (!poll.ok) {
82669
+ const throttle = throttledPoll(poll, intervalMs);
82670
+ if (throttle) {
82671
+ ({ intervalMs, waitMs } = throttle);
82672
+ continue;
82673
+ }
82644
82674
  const error48 = typeof payload?.["error"] === "string" ? payload["error"] : "device_poll_failed";
82645
82675
  if (error48 === "authorization_pending") continue;
82646
82676
  if (error48 === "slow_down") {
82647
82677
  intervalMs += 5e3;
82678
+ waitMs = intervalMs;
82648
82679
  continue;
82649
82680
  }
82650
82681
  throw new Error(`device authorization failed: ${error48}`);
@@ -82855,9 +82886,11 @@ async function linkThroughConsole(opts) {
82855
82886
  });
82856
82887
  const deadline = Date.now() + Math.min(code.expires_in * 1e3, opts.timeoutMs ?? Number.POSITIVE_INFINITY);
82857
82888
  let intervalMs = Math.max(2, code.interval ?? 5) * 1e3;
82889
+ let waitMs = intervalMs;
82858
82890
  const sleep = opts.sleep ?? ((ms) => new Promise((resolve7) => setTimeout(resolve7, ms)));
82859
82891
  while (Date.now() < deadline) {
82860
- await sleep(intervalMs);
82892
+ await sleep(waitMs);
82893
+ waitMs = intervalMs;
82861
82894
  const poll = await fetchFn(device.token, {
82862
82895
  method: "POST",
82863
82896
  headers: { "content-type": "application/json", accept: "application/json" },
@@ -82869,10 +82902,16 @@ async function linkThroughConsole(opts) {
82869
82902
  });
82870
82903
  const payload = await poll.json().catch(() => null);
82871
82904
  if (!poll.ok) {
82905
+ const throttle = throttledPoll(poll, intervalMs);
82906
+ if (throttle) {
82907
+ ({ intervalMs, waitMs } = throttle);
82908
+ continue;
82909
+ }
82872
82910
  const error48 = typeof payload?.["error"] === "string" ? payload["error"] : "device_poll_failed";
82873
82911
  if (error48 === "authorization_pending") continue;
82874
82912
  if (error48 === "slow_down") {
82875
82913
  intervalMs += 5e3;
82914
+ waitMs = intervalMs;
82876
82915
  continue;
82877
82916
  }
82878
82917
  if (error48 === "access_denied") return { status: "denied" };
@@ -84898,9 +84937,11 @@ async function requestDeviceAuthorization(fetchFn, deviceEndpoint, p) {
84898
84937
  async function pollDeviceApproval(fetchFn, deviceEndpoint, p, sleep = (ms) => new Promise((r) => setTimeout(r, ms))) {
84899
84938
  const deadline = Date.now() + p.timeoutMs;
84900
84939
  let intervalMs = Math.max(1, p.intervalSeconds) * 1e3;
84940
+ let waitMs = intervalMs;
84901
84941
  for (; ; ) {
84902
84942
  if (Date.now() >= deadline) throw new Error("device approval timed out \u2014 run `errata login` again");
84903
- await sleep(intervalMs);
84943
+ await sleep(waitMs);
84944
+ waitMs = intervalMs;
84904
84945
  const res = await fetchFn(`${strip2(deviceEndpoint)}/token`, {
84905
84946
  method: "POST",
84906
84947
  headers: { "content-type": "application/json", accept: "application/json" },
@@ -84912,9 +84953,15 @@ async function pollDeviceApproval(fetchFn, deviceEndpoint, p, sleep = (ms) => ne
84912
84953
  });
84913
84954
  const j = await res.json().catch(() => ({}));
84914
84955
  if (res.ok && j.access_token) return j.access_token;
84956
+ const throttle = throttledPoll(res, intervalMs);
84957
+ if (throttle) {
84958
+ ({ intervalMs, waitMs } = throttle);
84959
+ continue;
84960
+ }
84915
84961
  if (j.error === "authorization_pending") continue;
84916
84962
  if (j.error === "slow_down") {
84917
84963
  intervalMs += 5e3;
84964
+ waitMs = intervalMs;
84918
84965
  continue;
84919
84966
  }
84920
84967
  throw new Error(`device approval failed: ${j.error ?? `HTTP ${res.status}`}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inerrata-corporation/errata",
3
- "version": "2.0.6-dev.2115",
3
+ "version": "2.0.6-dev.2157",
4
4
  "description": "errata - local-first observation engine for AI coding agents",
5
5
  "type": "module",
6
6
  "bin": {