@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",
@@ -6543,7 +6553,7 @@
6543
6553
  "format": "esm"
6544
6554
  },
6545
6555
  "src/plugin/request.ts": {
6546
- "bytes": 111408,
6556
+ "bytes": 111580,
6547
6557
  "imports": [
6548
6558
  {
6549
6559
  "path": "node:crypto",
@@ -7056,7 +7066,7 @@
7056
7066
  "format": "esm"
7057
7067
  },
7058
7068
  "src/plugin/shared/request-services.ts": {
7059
- "bytes": 137525,
7069
+ "bytes": 140886,
7060
7070
  "imports": [
7061
7071
  {
7062
7072
  "path": "node:crypto",
@@ -7626,7 +7636,7 @@
7626
7636
  "imports": [],
7627
7637
  "exports": [],
7628
7638
  "inputs": {},
7629
- "bytes": 5295096
7639
+ "bytes": 5307248
7630
7640
  },
7631
7641
  "dist/index.js": {
7632
7642
  "imports": [
@@ -9002,10 +9012,10 @@
9002
9012
  "bytesInOutput": 18528
9003
9013
  },
9004
9014
  "../core/dist/rotation.js": {
9005
- "bytesInOutput": 11183
9015
+ "bytesInOutput": 12114
9006
9016
  },
9007
9017
  "../core/dist/account-selector.js": {
9008
- "bytesInOutput": 59520
9018
+ "bytesInOutput": 59753
9009
9019
  },
9010
9020
  "../core/dist/account-repository.js": {
9011
9021
  "bytesInOutput": 81767
@@ -9307,6 +9317,9 @@
9307
9317
  "../core/dist/credential-redaction.js": {
9308
9318
  "bytesInOutput": 8757
9309
9319
  },
9320
+ "../core/dist/harness-identity.js": {
9321
+ "bytesInOutput": 3143
9322
+ },
9310
9323
  "../core/dist/model-types.js": {
9311
9324
  "bytesInOutput": 93
9312
9325
  },
@@ -9362,7 +9375,7 @@
9362
9375
  "bytesInOutput": 2019
9363
9376
  },
9364
9377
  "../core/dist/index.js": {
9365
- "bytesInOutput": 1205
9378
+ "bytesInOutput": 1234
9366
9379
  },
9367
9380
  "src/common-auth-embedded/logger/capture-sink.js": {
9368
9381
  "bytesInOutput": 115
@@ -9761,7 +9774,7 @@
9761
9774
  "bytesInOutput": 7194
9762
9775
  },
9763
9776
  "src/plugin/request.ts": {
9764
- "bytesInOutput": 78189
9777
+ "bytesInOutput": 78333
9765
9778
  },
9766
9779
  "src/plugin/cache.ts": {
9767
9780
  "bytesInOutput": 9034
@@ -9860,7 +9873,7 @@
9860
9873
  "bytesInOutput": 7731
9861
9874
  },
9862
9875
  "src/plugin/shared/request-services.ts": {
9863
- "bytesInOutput": 92128
9876
+ "bytesInOutput": 94665
9864
9877
  },
9865
9878
  "src/common-auth-embedded/routing-accessor/handle.js": {
9866
9879
  "bytesInOutput": 297
@@ -9917,7 +9930,7 @@
9917
9930
  "bytesInOutput": 0
9918
9931
  }
9919
9932
  },
9920
- "bytes": 2397284
9933
+ "bytes": 2404338
9921
9934
  }
9922
9935
  }
9923
9936
  }
package/dist/server.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();
@@ -47340,6 +47439,10 @@ function sanitizeRequestPayloadForAntigravity(payload) {
47340
47439
  };
47341
47440
  });
47342
47441
  }
47442
+ if ("systemInstruction" in anyPayload)
47443
+ anyPayload.systemInstruction = rewriteSystemInstruction(
47444
+ anyPayload.systemInstruction
47445
+ );
47343
47446
  const systemInstruction = anyPayload.systemInstruction;
47344
47447
  if (systemInstruction && typeof systemInstruction === "object" && !Array.isArray(systemInstruction)) {
47345
47448
  const sys = systemInstruction;
@@ -50658,6 +50761,7 @@ function createRequestExecutor(deps) {
50658
50761
  }
50659
50762
  };
50660
50763
  let accountSwitchCount = 0;
50764
+ let unconfirmedRetries = 0;
50661
50765
  const maxAccountSwitches = config.max_account_switches ?? 2;
50662
50766
  let previousAccountIndex = -1;
50663
50767
  let needsCacheWarmup = false;
@@ -51405,6 +51509,7 @@ function createRequestExecutor(deps) {
51405
51509
  let apiRequestCount = 0;
51406
51510
  let shouldSwitchAccount = false;
51407
51511
  let skippedForModelUnavailable = false;
51512
+ let switchedForUnconfirmed = false;
51408
51513
  if (account.fingerprint) {
51409
51514
  pushDebug(
51410
51515
  `fingerprint: deviceId=${account.fingerprint.deviceId.slice(0, 8)}...`
@@ -51636,6 +51741,55 @@ function createRequestExecutor(deps) {
51636
51741
  reasonInfo.message,
51637
51742
  response.status
51638
51743
  );
51744
+ if (response.status === 429 && rateLimitReason === "UNKNOWN") {
51745
+ await logResponseBody2(debugContext, response, 429);
51746
+ const outgoing = JSON.parse(String(prepared.init.body));
51747
+ const recognised = systemInstructionHasHarnessIdentity(
51748
+ outgoing.request?.systemInstruction
51749
+ );
51750
+ const terminal = () => new Response(
51751
+ JSON.stringify({
51752
+ error: {
51753
+ code: 412,
51754
+ status: "FAILED_PRECONDITION",
51755
+ message: UNCONFIRMED_RATE_LIMIT_MESSAGE
51756
+ }
51757
+ }),
51758
+ {
51759
+ status: 412,
51760
+ headers: { "Content-Type": "application/json" }
51761
+ }
51762
+ );
51763
+ void response.body?.cancel().catch(() => {
51764
+ });
51765
+ if (recognised) return terminal();
51766
+ const delayMs = unconfirmedRateLimitDelayMs(
51767
+ response.headers.get("retry-after")
51768
+ );
51769
+ accountManager.markRateLimitedWithReason(
51770
+ account,
51771
+ family,
51772
+ model,
51773
+ "UNKNOWN",
51774
+ delayMs
51775
+ );
51776
+ accountManager.requestSaveToDisk();
51777
+ if (unconfirmedRetries >= MAX_UNCONFIRMED_RATE_LIMIT_RETRIES)
51778
+ return terminal();
51779
+ unconfirmedRetries++;
51780
+ const ready = accountManager.getAccounts().some((entry) => {
51781
+ const resets = entry.rateLimitResetTimes;
51782
+ 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();
51783
+ });
51784
+ if (ready) {
51785
+ switchedForUnconfirmed = true;
51786
+ shouldSwitchAccount = true;
51787
+ break;
51788
+ }
51789
+ await routingSleep(delayMs, "rate_limited", unconfirmedRetries);
51790
+ i -= 1;
51791
+ continue;
51792
+ }
51639
51793
  if (credentials.domain === "vault" && sendAdmission && sessionKey && hasVaultRoutingAccessor()) {
51640
51794
  const group = resolveQuotaGroup(
51641
51795
  family,
@@ -52182,6 +52336,7 @@ function createRequestExecutor(deps) {
52182
52336
  continue;
52183
52337
  }
52184
52338
  if (shouldSwitchAccount) {
52339
+ if (switchedForUnconfirmed) continue;
52185
52340
  accountSwitchCount++;
52186
52341
  if (accountSwitchCount > maxAccountSwitches) {
52187
52342
  pushDebug(