@cortexkit/opencode-antigravity-auth 3.1.1 → 3.1.2

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.
@@ -120,12 +120,12 @@
120
120
  "format": "esm"
121
121
  },
122
122
  "../core/dist/rotation.js": {
123
- "bytes": 14986,
123
+ "bytes": 16060,
124
124
  "imports": [],
125
125
  "format": "esm"
126
126
  },
127
127
  "../core/dist/account-selector.js": {
128
- "bytes": 68923,
128
+ "bytes": 69159,
129
129
  "imports": [
130
130
  {
131
131
  "path": "../core/dist/fingerprint.js",
@@ -2514,6 +2514,11 @@
2514
2514
  "imports": [],
2515
2515
  "format": "esm"
2516
2516
  },
2517
+ "../core/dist/harness-identity.js": {
2518
+ "bytes": 3577,
2519
+ "imports": [],
2520
+ "format": "esm"
2521
+ },
2517
2522
  "../core/dist/model-types.js": {
2518
2523
  "bytes": 130,
2519
2524
  "imports": [],
@@ -2777,7 +2782,7 @@
2777
2782
  "format": "esm"
2778
2783
  },
2779
2784
  "../core/dist/index.js": {
2780
- "bytes": 1975,
2785
+ "bytes": 2014,
2781
2786
  "imports": [
2782
2787
  {
2783
2788
  "path": "../core/dist/abort-forwarding.js",
@@ -2894,6 +2899,11 @@
2894
2899
  "kind": "import-statement",
2895
2900
  "original": "./fingerprint.js"
2896
2901
  },
2902
+ {
2903
+ "path": "../core/dist/harness-identity.js",
2904
+ "kind": "import-statement",
2905
+ "original": "./harness-identity.js"
2906
+ },
2897
2907
  {
2898
2908
  "path": "../core/dist/logger.js",
2899
2909
  "kind": "import-statement",
@@ -4635,7 +4645,7 @@
4635
4645
  "imports": [],
4636
4646
  "exports": [],
4637
4647
  "inputs": {},
4638
- "bytes": 3382090
4648
+ "bytes": 3387251
4639
4649
  },
4640
4650
  "dist/cli.js": {
4641
4651
  "imports": [
@@ -5780,6 +5790,9 @@
5780
5790
  "../core/dist/credential-redaction.js": {
5781
5791
  "bytesInOutput": 324
5782
5792
  },
5793
+ "../core/dist/harness-identity.js": {
5794
+ "bytesInOutput": 103
5795
+ },
5783
5796
  "../core/dist/model-types.js": {
5784
5797
  "bytesInOutput": 93
5785
5798
  },
@@ -5835,7 +5848,7 @@
5835
5848
  "bytesInOutput": 152
5836
5849
  },
5837
5850
  "../core/dist/index.js": {
5838
- "bytesInOutput": 1205
5851
+ "bytesInOutput": 1234
5839
5852
  },
5840
5853
  "src/common-auth-embedded/logger/capture-sink.js": {
5841
5854
  "bytesInOutput": 115
@@ -6024,7 +6037,7 @@
6024
6037
  "bytesInOutput": 292
6025
6038
  }
6026
6039
  },
6027
- "bytes": 1271691
6040
+ "bytes": 1271860
6028
6041
  }
6029
6042
  }
6030
6043
  }
package/dist/index.js CHANGED
@@ -4561,6 +4561,11 @@ var init_model_registry = __esm({
4561
4561
  });
4562
4562
 
4563
4563
  // ../core/dist/rotation.js
4564
+ function unconfirmedRateLimitDelayMs(retryAfter, now = Date.now()) {
4565
+ const value = retryAfter?.trim();
4566
+ const delay3 = value ? /^\d+(?:\.\d+)?$/.test(value) ? Number(value) * 1e3 : Date.parse(value) - now : Number.NaN;
4567
+ return Number.isFinite(delay3) ? Math.min(UNCONFIRMED_RATE_LIMIT_MAX_MS, Math.max(UNCONFIRMED_RATE_LIMIT_MIN_MS, delay3)) : UNCONFIRMED_RATE_LIMIT_MIN_MS;
4568
+ }
4564
4569
  function parseRateLimitReason(reason, message, status) {
4565
4570
  if (status === 529 || status === 503)
4566
4571
  return "MODEL_CAPACITY_EXHAUSTED";
@@ -4587,6 +4592,9 @@ function parseRateLimitReason(reason, message, status) {
4587
4592
  return "UNKNOWN";
4588
4593
  }
4589
4594
  function calculateBackoffMs(reason, consecutiveFailures, retryAfterMs, random = Math.random) {
4595
+ if (reason === "UNKNOWN") {
4596
+ return Math.min(UNCONFIRMED_RATE_LIMIT_MAX_MS, Math.max(UNCONFIRMED_RATE_LIMIT_MIN_MS, retryAfterMs ?? 0));
4597
+ }
4590
4598
  if (retryAfterMs && retryAfterMs > 0) {
4591
4599
  return Math.max(retryAfterMs, MIN_BACKOFF_MS);
4592
4600
  }
@@ -4676,7 +4684,7 @@ function initHealthTracker(config) {
4676
4684
  globalHealthTracker = new HealthScoreTracker(config);
4677
4685
  return globalHealthTracker;
4678
4686
  }
4679
- var QUOTA_EXHAUSTED_BACKOFFS, MAX_QUOTA_EXHAUSTED_BACKOFF_MS, RATE_LIMIT_EXCEEDED_BACKOFF, MODEL_CAPACITY_EXHAUSTED_BASE_BACKOFF, MODEL_CAPACITY_EXHAUSTED_JITTER_MAX, SERVER_ERROR_BACKOFF, UNKNOWN_BACKOFF, MIN_BACKOFF_MS, DEFAULT_HEALTH_SCORE_CONFIG, HealthScoreTracker, STICKINESS_BONUS, SWITCH_THRESHOLD, DEFAULT_TOKEN_BUCKET_CONFIG, TokenBucketTracker, globalTokenTracker, globalHealthTracker;
4687
+ var QUOTA_EXHAUSTED_BACKOFFS, MAX_QUOTA_EXHAUSTED_BACKOFF_MS, RATE_LIMIT_EXCEEDED_BACKOFF, MODEL_CAPACITY_EXHAUSTED_BASE_BACKOFF, MODEL_CAPACITY_EXHAUSTED_JITTER_MAX, SERVER_ERROR_BACKOFF, UNKNOWN_BACKOFF, MIN_BACKOFF_MS, UNCONFIRMED_RATE_LIMIT_MIN_MS, UNCONFIRMED_RATE_LIMIT_MAX_MS, MAX_UNCONFIRMED_RATE_LIMIT_RETRIES, UNCONFIRMED_RATE_LIMIT_MESSAGE, DEFAULT_HEALTH_SCORE_CONFIG, HealthScoreTracker, STICKINESS_BONUS, SWITCH_THRESHOLD, DEFAULT_TOKEN_BUCKET_CONFIG, TokenBucketTracker, globalTokenTracker, globalHealthTracker;
4680
4688
  var init_rotation = __esm({
4681
4689
  "../core/dist/rotation.js"() {
4682
4690
  "use strict";
@@ -4693,6 +4701,10 @@ var init_rotation = __esm({
4693
4701
  SERVER_ERROR_BACKOFF = 2e4;
4694
4702
  UNKNOWN_BACKOFF = 6e4;
4695
4703
  MIN_BACKOFF_MS = 2e3;
4704
+ UNCONFIRMED_RATE_LIMIT_MIN_MS = 5e3;
4705
+ UNCONFIRMED_RATE_LIMIT_MAX_MS = 3e4;
4706
+ MAX_UNCONFIRMED_RATE_LIMIT_RETRIES = 2;
4707
+ UNCONFIRMED_RATE_LIMIT_MESSAGE = "Antigravity could not confirm a temporary request limit. Try again later or change the agent system prompt.";
4696
4708
  DEFAULT_HEALTH_SCORE_CONFIG = {
4697
4709
  initial: 70,
4698
4710
  successReward: 1,
@@ -5678,6 +5690,11 @@ var init_account_selector = __esm({
5678
5690
  }
5679
5691
  markRateLimitedWithReason(account, family, model, reason, retryAfterMs, failureTtlMs = 36e5) {
5680
5692
  const now = this.now();
5693
+ if (reason === "UNKNOWN") {
5694
+ const backoffMs2 = calculateBackoffMs(reason, 0, retryAfterMs);
5695
+ this.setRateLimit(account, getQuotaKey(family, model), now + backoffMs2);
5696
+ return backoffMs2;
5697
+ }
5681
5698
  if (account.lastFailureTime !== void 0 && now - account.lastFailureTime > failureTtlMs) {
5682
5699
  account.consecutiveFailures = 0;
5683
5700
  }
@@ -27556,6 +27573,87 @@ var init_credential_redaction = __esm({
27556
27573
  }
27557
27574
  });
27558
27575
 
27576
+ // ../core/dist/harness-identity.js
27577
+ function rewriteHarnessIdentity(text2) {
27578
+ const paragraphs = HARNESS_IDENTITY_PARAGRAPHS.some((marker) => text2.includes(marker)) ? text2.split(/\n\n+/).filter((paragraph) => !HARNESS_IDENTITY_PARAGRAPHS.some((marker) => paragraph.includes(marker))).join("\n\n") : text2;
27579
+ return HARNESS_IDENTITY_REWRITES.reduce((result, { pattern, replacement }) => result.replace(pattern, replacement), paragraphs);
27580
+ }
27581
+ function hasHarnessIdentity(text2) {
27582
+ return HARNESS_IDENTITY_PARAGRAPHS.some((marker) => text2.includes(marker)) || HARNESS_IDENTITY_REWRITES.some(({ pattern, replacement }) => text2.replace(pattern, replacement) !== text2);
27583
+ }
27584
+ function rewriteSystemInstruction(instruction) {
27585
+ if (typeof instruction === "string")
27586
+ return rewriteHarnessIdentity(instruction);
27587
+ if (!instruction || typeof instruction !== "object" || Array.isArray(instruction))
27588
+ return instruction;
27589
+ const record5 = instruction;
27590
+ if (!Array.isArray(record5.parts))
27591
+ return instruction;
27592
+ return {
27593
+ ...record5,
27594
+ parts: record5.parts.map((part) => {
27595
+ if (!part || typeof part !== "object" || Array.isArray(part))
27596
+ return part;
27597
+ const value = part;
27598
+ return typeof value.text === "string" ? { ...value, text: rewriteHarnessIdentity(value.text) } : part;
27599
+ })
27600
+ };
27601
+ }
27602
+ function systemInstructionHasHarnessIdentity(instruction) {
27603
+ if (typeof instruction === "string")
27604
+ return hasHarnessIdentity(instruction);
27605
+ if (!instruction || typeof instruction !== "object" || Array.isArray(instruction))
27606
+ return false;
27607
+ const parts = instruction.parts;
27608
+ return Array.isArray(parts) && parts.some((part) => {
27609
+ if (!part || typeof part !== "object" || Array.isArray(part))
27610
+ return false;
27611
+ const text2 = part.text;
27612
+ return typeof text2 === "string" && hasHarnessIdentity(text2);
27613
+ });
27614
+ }
27615
+ var HARNESS_IDENTITY_PARAGRAPHS, HARNESS_IDENTITY_REWRITES;
27616
+ var init_harness_identity = __esm({
27617
+ "../core/dist/harness-identity.js"() {
27618
+ "use strict";
27619
+ HARNESS_IDENTITY_PARAGRAPHS = [
27620
+ "github.com/anomalyco/opencode",
27621
+ "github.com/sst/opencode",
27622
+ "opencode.ai/docs"
27623
+ ];
27624
+ HARNESS_IDENTITY_REWRITES = [
27625
+ {
27626
+ pattern: /You are opencode, /gi,
27627
+ replacement: "You are "
27628
+ },
27629
+ {
27630
+ pattern: /You are opencode(?!\.\w)(?=[.!;:]|$|\n)/gi,
27631
+ replacement: "You are a coding assistant"
27632
+ },
27633
+ {
27634
+ pattern: /if OpenCode honestly/g,
27635
+ replacement: "if the assistant honestly"
27636
+ },
27637
+ {
27638
+ pattern: /running inside Pi-Bolt, a build of pi \(a coding agent harness\) compiled ahead of time/gi,
27639
+ replacement: "running inside your development environment"
27640
+ },
27641
+ {
27642
+ pattern: /running inside pi, a coding agent harness/gi,
27643
+ replacement: "running inside your development environment"
27644
+ },
27645
+ {
27646
+ pattern: /running inside opencode, a coding agent harness/gi,
27647
+ replacement: "running inside your development environment"
27648
+ },
27649
+ {
27650
+ pattern: /\brunning inside (?:pi-bolt|pi|opencode)(?!\.\w)(?=$|\s|[.,;:!?])/gi,
27651
+ replacement: "running inside your development environment"
27652
+ }
27653
+ ];
27654
+ }
27655
+ });
27656
+
27559
27657
  // ../core/dist/model-types.js
27560
27658
  var init_model_types = __esm({
27561
27659
  "../core/dist/model-types.js"() {
@@ -30553,6 +30651,7 @@ var init_dist = __esm({
30553
30651
  init_fetch_timeout();
30554
30652
  init_file_lock();
30555
30653
  init_fingerprint();
30654
+ init_harness_identity();
30556
30655
  init_logger();
30557
30656
  init_model_registry();
30558
30657
  init_model_types();
@@ -55858,6 +55957,10 @@ function sanitizeRequestPayloadForAntigravity(payload) {
55858
55957
  };
55859
55958
  });
55860
55959
  }
55960
+ if ("systemInstruction" in anyPayload)
55961
+ anyPayload.systemInstruction = rewriteSystemInstruction(
55962
+ anyPayload.systemInstruction
55963
+ );
55861
55964
  const systemInstruction = anyPayload.systemInstruction;
55862
55965
  if (systemInstruction && typeof systemInstruction === "object" && !Array.isArray(systemInstruction)) {
55863
55966
  const sys = systemInstruction;
@@ -60800,6 +60903,7 @@ function createRequestExecutor(deps) {
60800
60903
  }
60801
60904
  };
60802
60905
  let accountSwitchCount = 0;
60906
+ let unconfirmedRetries = 0;
60803
60907
  const maxAccountSwitches = config.max_account_switches ?? 2;
60804
60908
  let previousAccountIndex = -1;
60805
60909
  let needsCacheWarmup = false;
@@ -61547,6 +61651,7 @@ function createRequestExecutor(deps) {
61547
61651
  let apiRequestCount = 0;
61548
61652
  let shouldSwitchAccount = false;
61549
61653
  let skippedForModelUnavailable = false;
61654
+ let switchedForUnconfirmed = false;
61550
61655
  if (account.fingerprint) {
61551
61656
  pushDebug(
61552
61657
  `fingerprint: deviceId=${account.fingerprint.deviceId.slice(0, 8)}...`
@@ -61778,6 +61883,55 @@ function createRequestExecutor(deps) {
61778
61883
  reasonInfo.message,
61779
61884
  response.status
61780
61885
  );
61886
+ if (response.status === 429 && rateLimitReason === "UNKNOWN") {
61887
+ await logResponseBody2(debugContext, response, 429);
61888
+ const outgoing = JSON.parse(String(prepared.init.body));
61889
+ const recognised = systemInstructionHasHarnessIdentity(
61890
+ outgoing.request?.systemInstruction
61891
+ );
61892
+ const terminal = () => new Response(
61893
+ JSON.stringify({
61894
+ error: {
61895
+ code: 412,
61896
+ status: "FAILED_PRECONDITION",
61897
+ message: UNCONFIRMED_RATE_LIMIT_MESSAGE
61898
+ }
61899
+ }),
61900
+ {
61901
+ status: 412,
61902
+ headers: { "Content-Type": "application/json" }
61903
+ }
61904
+ );
61905
+ void response.body?.cancel().catch(() => {
61906
+ });
61907
+ if (recognised) return terminal();
61908
+ const delayMs = unconfirmedRateLimitDelayMs(
61909
+ response.headers.get("retry-after")
61910
+ );
61911
+ accountManager.markRateLimitedWithReason(
61912
+ account,
61913
+ family,
61914
+ model,
61915
+ "UNKNOWN",
61916
+ delayMs
61917
+ );
61918
+ accountManager.requestSaveToDisk();
61919
+ if (unconfirmedRetries >= MAX_UNCONFIRMED_RATE_LIMIT_RETRIES)
61920
+ return terminal();
61921
+ unconfirmedRetries++;
61922
+ const ready = accountManager.getAccounts().some((entry) => {
61923
+ const resets = entry.rateLimitResetTimes;
61924
+ return entry.index !== account.index && entry.enabled !== false && !entry.accountIneligible && !entry.verificationRequired && !allowlistExcluded?.has(entry.index) && !unavailableIndexes.has(entry.index) && (eligibleIndexes === null || eligibleIndexes.has(entry.index)) && (entry.coolingDownUntil ?? 0) <= Date.now() && (resets[family] ?? 0) <= Date.now() && (resets[getQuotaKey(family, model)] ?? 0) <= Date.now();
61925
+ });
61926
+ if (ready) {
61927
+ switchedForUnconfirmed = true;
61928
+ shouldSwitchAccount = true;
61929
+ break;
61930
+ }
61931
+ await routingSleep(delayMs, "rate_limited", unconfirmedRetries);
61932
+ i -= 1;
61933
+ continue;
61934
+ }
61781
61935
  if (credentials.domain === "vault" && sendAdmission && sessionKey && hasVaultRoutingAccessor()) {
61782
61936
  const group = resolveQuotaGroup(
61783
61937
  family,
@@ -62324,6 +62478,7 @@ function createRequestExecutor(deps) {
62324
62478
  continue;
62325
62479
  }
62326
62480
  if (shouldSwitchAccount) {
62481
+ if (switchedForUnconfirmed) continue;
62327
62482
  accountSwitchCount++;
62328
62483
  if (accountSwitchCount > maxAccountSwitches) {
62329
62484
  pushDebug(