@funnycode/myclaude 0.1.91 → 0.1.93

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/myclaude.js CHANGED
@@ -4,8 +4,8 @@
4
4
  // MACRO - build-time constants (injected by build.ts)
5
5
  // MACRO injected by build script
6
6
  globalThis.MACRO = {
7
- VERSION: "0.1.91",
8
- BUILD_TIME: "2026-07-17T20:20:49.267Z",
7
+ VERSION: "0.1.93",
8
+ BUILD_TIME: "2026-07-18T04:08:04.637Z",
9
9
  PACKAGE_URL: "@funnycode/myclaude",
10
10
  NATIVE_PACKAGE_URL: "@funnycode/myclaude",
11
11
  VERSION_CHANGELOG: '',
@@ -117484,7 +117484,7 @@ var package_default;
117484
117484
  var init_package = __esm(() => {
117485
117485
  package_default = {
117486
117486
  name: "@funnycode/myclaude",
117487
- version: "0.1.91",
117487
+ version: "0.1.93",
117488
117488
  private: false,
117489
117489
  description: "An open-source AI coding assistant in your terminal - powered by Claude",
117490
117490
  license: "MIT",
@@ -210146,6 +210146,214 @@ var init_postSamplingHooks = __esm(() => {
210146
210146
  postSamplingHooks = [];
210147
210147
  });
210148
210148
 
210149
+ // node_modules/async-mutex/index.mjs
210150
+ class Semaphore {
210151
+ constructor(_value, _cancelError = E_CANCELED) {
210152
+ this._value = _value;
210153
+ this._cancelError = _cancelError;
210154
+ this._queue = [];
210155
+ this._weightedWaiters = [];
210156
+ }
210157
+ acquire(weight = 1, priority = 0) {
210158
+ if (weight <= 0)
210159
+ throw new Error(`invalid weight ${weight}: must be positive`);
210160
+ return new Promise((resolve25, reject2) => {
210161
+ const task = { resolve: resolve25, reject: reject2, weight, priority };
210162
+ const i3 = findIndexFromEnd(this._queue, (other) => priority <= other.priority);
210163
+ if (i3 === -1 && weight <= this._value) {
210164
+ this._dispatchItem(task);
210165
+ } else {
210166
+ this._queue.splice(i3 + 1, 0, task);
210167
+ }
210168
+ });
210169
+ }
210170
+ runExclusive(callback_1) {
210171
+ return __awaiter$2(this, arguments, undefined, function* (callback, weight = 1, priority = 0) {
210172
+ const [value, release] = yield this.acquire(weight, priority);
210173
+ try {
210174
+ return yield callback(value);
210175
+ } finally {
210176
+ release();
210177
+ }
210178
+ });
210179
+ }
210180
+ waitForUnlock(weight = 1, priority = 0) {
210181
+ if (weight <= 0)
210182
+ throw new Error(`invalid weight ${weight}: must be positive`);
210183
+ if (this._couldLockImmediately(weight, priority)) {
210184
+ return Promise.resolve();
210185
+ } else {
210186
+ return new Promise((resolve25) => {
210187
+ if (!this._weightedWaiters[weight - 1])
210188
+ this._weightedWaiters[weight - 1] = [];
210189
+ insertSorted(this._weightedWaiters[weight - 1], { resolve: resolve25, priority });
210190
+ });
210191
+ }
210192
+ }
210193
+ isLocked() {
210194
+ return this._value <= 0;
210195
+ }
210196
+ getValue() {
210197
+ return this._value;
210198
+ }
210199
+ setValue(value) {
210200
+ this._value = value;
210201
+ this._dispatchQueue();
210202
+ }
210203
+ release(weight = 1) {
210204
+ if (weight <= 0)
210205
+ throw new Error(`invalid weight ${weight}: must be positive`);
210206
+ this._value += weight;
210207
+ this._dispatchQueue();
210208
+ }
210209
+ cancel() {
210210
+ this._queue.forEach((entry) => entry.reject(this._cancelError));
210211
+ this._queue = [];
210212
+ }
210213
+ _dispatchQueue() {
210214
+ this._drainUnlockWaiters();
210215
+ while (this._queue.length > 0 && this._queue[0].weight <= this._value) {
210216
+ this._dispatchItem(this._queue.shift());
210217
+ this._drainUnlockWaiters();
210218
+ }
210219
+ }
210220
+ _dispatchItem(item) {
210221
+ const previousValue = this._value;
210222
+ this._value -= item.weight;
210223
+ item.resolve([previousValue, this._newReleaser(item.weight)]);
210224
+ }
210225
+ _newReleaser(weight) {
210226
+ let called = false;
210227
+ return () => {
210228
+ if (called)
210229
+ return;
210230
+ called = true;
210231
+ this.release(weight);
210232
+ };
210233
+ }
210234
+ _drainUnlockWaiters() {
210235
+ if (this._queue.length === 0) {
210236
+ for (let weight = this._value;weight > 0; weight--) {
210237
+ const waiters = this._weightedWaiters[weight - 1];
210238
+ if (!waiters)
210239
+ continue;
210240
+ waiters.forEach((waiter) => waiter.resolve());
210241
+ this._weightedWaiters[weight - 1] = [];
210242
+ }
210243
+ } else {
210244
+ const queuedPriority = this._queue[0].priority;
210245
+ for (let weight = this._value;weight > 0; weight--) {
210246
+ const waiters = this._weightedWaiters[weight - 1];
210247
+ if (!waiters)
210248
+ continue;
210249
+ const i3 = waiters.findIndex((waiter) => waiter.priority <= queuedPriority);
210250
+ (i3 === -1 ? waiters : waiters.splice(0, i3)).forEach((waiter) => waiter.resolve());
210251
+ }
210252
+ }
210253
+ }
210254
+ _couldLockImmediately(weight, priority) {
210255
+ return (this._queue.length === 0 || this._queue[0].priority < priority) && weight <= this._value;
210256
+ }
210257
+ }
210258
+ function insertSorted(a2, v2) {
210259
+ const i3 = findIndexFromEnd(a2, (other) => v2.priority <= other.priority);
210260
+ a2.splice(i3 + 1, 0, v2);
210261
+ }
210262
+ function findIndexFromEnd(a2, predicate) {
210263
+ for (let i3 = a2.length - 1;i3 >= 0; i3--) {
210264
+ if (predicate(a2[i3])) {
210265
+ return i3;
210266
+ }
210267
+ }
210268
+ return -1;
210269
+ }
210270
+
210271
+ class Mutex {
210272
+ constructor(cancelError) {
210273
+ this._semaphore = new Semaphore(1, cancelError);
210274
+ }
210275
+ acquire() {
210276
+ return __awaiter$1(this, arguments, undefined, function* (priority = 0) {
210277
+ const [, releaser] = yield this._semaphore.acquire(1, priority);
210278
+ return releaser;
210279
+ });
210280
+ }
210281
+ runExclusive(callback, priority = 0) {
210282
+ return this._semaphore.runExclusive(() => callback(), 1, priority);
210283
+ }
210284
+ isLocked() {
210285
+ return this._semaphore.isLocked();
210286
+ }
210287
+ waitForUnlock(priority = 0) {
210288
+ return this._semaphore.waitForUnlock(1, priority);
210289
+ }
210290
+ release() {
210291
+ if (this._semaphore.isLocked())
210292
+ this._semaphore.release();
210293
+ }
210294
+ cancel() {
210295
+ return this._semaphore.cancel();
210296
+ }
210297
+ }
210298
+ var E_TIMEOUT, E_ALREADY_LOCKED, E_CANCELED, __awaiter$2 = function(thisArg, _arguments, P2, generator) {
210299
+ function adopt(value) {
210300
+ return value instanceof P2 ? value : new P2(function(resolve25) {
210301
+ resolve25(value);
210302
+ });
210303
+ }
210304
+ return new (P2 || (P2 = Promise))(function(resolve25, reject2) {
210305
+ function fulfilled(value) {
210306
+ try {
210307
+ step(generator.next(value));
210308
+ } catch (e) {
210309
+ reject2(e);
210310
+ }
210311
+ }
210312
+ function rejected(value) {
210313
+ try {
210314
+ step(generator["throw"](value));
210315
+ } catch (e) {
210316
+ reject2(e);
210317
+ }
210318
+ }
210319
+ function step(result) {
210320
+ result.done ? resolve25(result.value) : adopt(result.value).then(fulfilled, rejected);
210321
+ }
210322
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
210323
+ });
210324
+ }, __awaiter$1 = function(thisArg, _arguments, P2, generator) {
210325
+ function adopt(value) {
210326
+ return value instanceof P2 ? value : new P2(function(resolve25) {
210327
+ resolve25(value);
210328
+ });
210329
+ }
210330
+ return new (P2 || (P2 = Promise))(function(resolve25, reject2) {
210331
+ function fulfilled(value) {
210332
+ try {
210333
+ step(generator.next(value));
210334
+ } catch (e) {
210335
+ reject2(e);
210336
+ }
210337
+ }
210338
+ function rejected(value) {
210339
+ try {
210340
+ step(generator["throw"](value));
210341
+ } catch (e) {
210342
+ reject2(e);
210343
+ }
210344
+ }
210345
+ function step(result) {
210346
+ result.done ? resolve25(result.value) : adopt(result.value).then(fulfilled, rejected);
210347
+ }
210348
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
210349
+ });
210350
+ };
210351
+ var init_async_mutex = __esm(() => {
210352
+ E_TIMEOUT = new Error("timeout while waiting for mutex to become available");
210353
+ E_ALREADY_LOCKED = new Error("mutex already locked");
210354
+ E_CANCELED = new Error("request for lock canceled");
210355
+ });
210356
+
210149
210357
  // src/services/api/dumpPrompts.ts
210150
210358
  import { createHash as createHash5 } from "crypto";
210151
210359
  import { promises as fs11 } from "fs";
@@ -210158,26 +210366,34 @@ function enqueueDumpRequest(agentIdOrSessionId, callback) {
210158
210366
  dumpRequestQueue.set(agentIdOrSessionId, []);
210159
210367
  }
210160
210368
  dumpRequestQueue.get(agentIdOrSessionId).push(callback);
210161
- if (!processingQueues.has(agentIdOrSessionId)) {
210162
- processingQueues.add(agentIdOrSessionId);
210163
- processQueue(agentIdOrSessionId);
210164
- }
210369
+ processQueue(agentIdOrSessionId);
210165
210370
  }
210166
210371
  async function processQueue(agentIdOrSessionId) {
210167
- processingQueues.add(agentIdOrSessionId);
210168
- const queue = dumpRequestQueue.get(agentIdOrSessionId);
210169
- if (!queue || queue.length === 0) {
210170
- dumpRequestQueue.delete(agentIdOrSessionId);
210171
- processingQueues.delete(agentIdOrSessionId);
210172
- return;
210372
+ const mapRelease = await dumpRequestMapMutex.acquire();
210373
+ let mutex = dumpRequestMutexes.get(agentIdOrSessionId);
210374
+ if (!mutex) {
210375
+ mutex = new Mutex;
210376
+ dumpRequestMutexes.set(agentIdOrSessionId, mutex);
210173
210377
  }
210174
- const callback = queue.shift();
210175
- await callback();
210176
- if (queue.length > 0) {
210177
- setImmediate(() => processQueue(agentIdOrSessionId));
210178
- } else {
210179
- dumpRequestQueue.delete(agentIdOrSessionId);
210180
- processingQueues.delete(agentIdOrSessionId);
210378
+ mapRelease();
210379
+ const release = await mutex.acquire();
210380
+ try {
210381
+ const queue = dumpRequestQueue.get(agentIdOrSessionId);
210382
+ if (!queue || queue.length === 0) {
210383
+ dumpRequestQueue.delete(agentIdOrSessionId);
210384
+ dumpRequestMutexes.delete(agentIdOrSessionId);
210385
+ return;
210386
+ }
210387
+ const callback = queue.shift();
210388
+ await callback();
210389
+ if (queue.length > 0) {
210390
+ setImmediate(() => processQueue(agentIdOrSessionId));
210391
+ } else {
210392
+ dumpRequestQueue.delete(agentIdOrSessionId);
210393
+ dumpRequestMutexes.delete(agentIdOrSessionId);
210394
+ }
210395
+ } finally {
210396
+ release();
210181
210397
  }
210182
210398
  }
210183
210399
  function clearDumpState(agentIdOrSessionId) {
@@ -210228,6 +210444,7 @@ async function dumpRequest(body, ts, state, filePath) {
210228
210444
  addApiRequestToCache(req);
210229
210445
  if (process.env.USER_TYPE !== "ant" || process.env.DUMP_PROMPTS !== "1")
210230
210446
  return;
210447
+ logForDebugging("DUMP_PROMPTS is enabled. This will write full API payloads (including system prompts, user messages, and tool definitions) to the filesystem. This is intended for debugging only and should NOT be used in production.", { level: "warn" });
210231
210448
  const entries = [];
210232
210449
  const messages = req.messages ?? [];
210233
210450
  const fingerprint = initFingerprint(req);
@@ -210293,7 +210510,7 @@ function createDumpPromptsFetch(agentIdOrSessionId) {
210293
210510
  const reader = cloned.body.getReader();
210294
210511
  const decoder = new TextDecoder;
210295
210512
  let buffer = "";
210296
- const chunks = [];
210513
+ const chunkEntries = [];
210297
210514
  try {
210298
210515
  while (true) {
210299
210516
  const { done, value } = await reader.read();
@@ -210313,7 +210530,12 @@ function createDumpPromptsFetch(agentIdOrSessionId) {
210313
210530
  `)) {
210314
210531
  if (line.startsWith("data: ") && line !== "data: [DONE]") {
210315
210532
  try {
210316
- chunks.push(jsonParse(line.slice(6)));
210533
+ const chunk = jsonParse(line.slice(6));
210534
+ chunkEntries.push(jsonStringify({ type: "chunk", timestamp, data: chunk }));
210535
+ if (chunkEntries.length >= 50) {
210536
+ await appendToFile(filePath, chunkEntries);
210537
+ chunkEntries.length = 0;
210538
+ }
210317
210539
  } catch (err2) {
210318
210540
  logForDebugging(`dumpPrompts.SSE parse error: ${err2}`, { level: "error" });
210319
210541
  }
@@ -210333,7 +210555,8 @@ function createDumpPromptsFetch(agentIdOrSessionId) {
210333
210555
  `)) {
210334
210556
  if (line.startsWith("data: ") && line !== "data: [DONE]") {
210335
210557
  try {
210336
- chunks.push(jsonParse(line.slice(6)));
210558
+ const chunk = jsonParse(line.slice(6));
210559
+ chunkEntries.push(jsonStringify({ type: "chunk", timestamp, data: chunk }));
210337
210560
  } catch (err2) {
210338
210561
  logForDebugging(`dumpPrompts.SSE parse error: ${err2}`, { level: "error" });
210339
210562
  }
@@ -210341,12 +210564,16 @@ function createDumpPromptsFetch(agentIdOrSessionId) {
210341
210564
  }
210342
210565
  }
210343
210566
  }
210344
- data = { stream: true, chunks };
210567
+ if (chunkEntries.length > 0) {
210568
+ await appendToFile(filePath, chunkEntries);
210569
+ }
210570
+ data = { stream: true, chunks: [] };
210345
210571
  } else {
210346
210572
  data = await cloned.json();
210347
210573
  }
210348
- await fs11.appendFile(filePath, jsonStringify({ type: "response", timestamp, data }) + `
210349
- `);
210574
+ await appendToFile(filePath, [
210575
+ jsonStringify({ type: "response", timestamp, data })
210576
+ ]);
210350
210577
  } catch (err2) {
210351
210578
  try {
210352
210579
  logForDebugging(`dumpPrompts.response handler error: ${err2}`, { level: "error" });
@@ -210359,17 +210586,22 @@ function createDumpPromptsFetch(agentIdOrSessionId) {
210359
210586
  return response;
210360
210587
  };
210361
210588
  }
210362
- var MAX_CACHED_REQUESTS = 5, cachedApiRequests, dumpState, dumpRequestQueue, processingQueues;
210589
+ var MAX_CACHED_REQUESTS = 5, cachedApiRequests, dumpState, dumpRequestQueue, dumpRequestMutexes, dumpRequestMapMutex;
210363
210590
  var init_dumpPrompts = __esm(() => {
210364
210591
  init_state();
210365
210592
  init_envUtils();
210366
210593
  init_slowOperations();
210367
210594
  init_debug();
210368
210595
  init_log3();
210596
+ init_async_mutex();
210597
+ if (process.env.USER_TYPE === "ant" && process.env.DUMP_PROMPTS === "1") {
210598
+ logForDebugging("DUMP_PROMPTS is enabled. This will write full API payloads (including system prompts, user messages, and tool definitions) to the filesystem. This is intended for debugging only and should NOT be used in production.", { level: "warn" });
210599
+ }
210369
210600
  cachedApiRequests = [];
210370
210601
  dumpState = new Map;
210371
210602
  dumpRequestQueue = new Map;
210372
- processingQueues = new Set;
210603
+ dumpRequestMutexes = new Map;
210604
+ dumpRequestMapMutex = new Mutex;
210373
210605
  });
210374
210606
 
210375
210607
  // src/utils/abortController.ts
@@ -300903,214 +301135,6 @@ var init_gracefulShutdown = __esm(() => {
300903
301135
  };
300904
301136
  });
300905
301137
 
300906
- // node_modules/async-mutex/index.mjs
300907
- class Semaphore {
300908
- constructor(_value, _cancelError = E_CANCELED) {
300909
- this._value = _value;
300910
- this._cancelError = _cancelError;
300911
- this._queue = [];
300912
- this._weightedWaiters = [];
300913
- }
300914
- acquire(weight = 1, priority = 0) {
300915
- if (weight <= 0)
300916
- throw new Error(`invalid weight ${weight}: must be positive`);
300917
- return new Promise((resolve28, reject2) => {
300918
- const task = { resolve: resolve28, reject: reject2, weight, priority };
300919
- const i3 = findIndexFromEnd(this._queue, (other) => priority <= other.priority);
300920
- if (i3 === -1 && weight <= this._value) {
300921
- this._dispatchItem(task);
300922
- } else {
300923
- this._queue.splice(i3 + 1, 0, task);
300924
- }
300925
- });
300926
- }
300927
- runExclusive(callback_1) {
300928
- return __awaiter$2(this, arguments, undefined, function* (callback, weight = 1, priority = 0) {
300929
- const [value, release] = yield this.acquire(weight, priority);
300930
- try {
300931
- return yield callback(value);
300932
- } finally {
300933
- release();
300934
- }
300935
- });
300936
- }
300937
- waitForUnlock(weight = 1, priority = 0) {
300938
- if (weight <= 0)
300939
- throw new Error(`invalid weight ${weight}: must be positive`);
300940
- if (this._couldLockImmediately(weight, priority)) {
300941
- return Promise.resolve();
300942
- } else {
300943
- return new Promise((resolve28) => {
300944
- if (!this._weightedWaiters[weight - 1])
300945
- this._weightedWaiters[weight - 1] = [];
300946
- insertSorted(this._weightedWaiters[weight - 1], { resolve: resolve28, priority });
300947
- });
300948
- }
300949
- }
300950
- isLocked() {
300951
- return this._value <= 0;
300952
- }
300953
- getValue() {
300954
- return this._value;
300955
- }
300956
- setValue(value) {
300957
- this._value = value;
300958
- this._dispatchQueue();
300959
- }
300960
- release(weight = 1) {
300961
- if (weight <= 0)
300962
- throw new Error(`invalid weight ${weight}: must be positive`);
300963
- this._value += weight;
300964
- this._dispatchQueue();
300965
- }
300966
- cancel() {
300967
- this._queue.forEach((entry) => entry.reject(this._cancelError));
300968
- this._queue = [];
300969
- }
300970
- _dispatchQueue() {
300971
- this._drainUnlockWaiters();
300972
- while (this._queue.length > 0 && this._queue[0].weight <= this._value) {
300973
- this._dispatchItem(this._queue.shift());
300974
- this._drainUnlockWaiters();
300975
- }
300976
- }
300977
- _dispatchItem(item) {
300978
- const previousValue = this._value;
300979
- this._value -= item.weight;
300980
- item.resolve([previousValue, this._newReleaser(item.weight)]);
300981
- }
300982
- _newReleaser(weight) {
300983
- let called = false;
300984
- return () => {
300985
- if (called)
300986
- return;
300987
- called = true;
300988
- this.release(weight);
300989
- };
300990
- }
300991
- _drainUnlockWaiters() {
300992
- if (this._queue.length === 0) {
300993
- for (let weight = this._value;weight > 0; weight--) {
300994
- const waiters = this._weightedWaiters[weight - 1];
300995
- if (!waiters)
300996
- continue;
300997
- waiters.forEach((waiter) => waiter.resolve());
300998
- this._weightedWaiters[weight - 1] = [];
300999
- }
301000
- } else {
301001
- const queuedPriority = this._queue[0].priority;
301002
- for (let weight = this._value;weight > 0; weight--) {
301003
- const waiters = this._weightedWaiters[weight - 1];
301004
- if (!waiters)
301005
- continue;
301006
- const i3 = waiters.findIndex((waiter) => waiter.priority <= queuedPriority);
301007
- (i3 === -1 ? waiters : waiters.splice(0, i3)).forEach((waiter) => waiter.resolve());
301008
- }
301009
- }
301010
- }
301011
- _couldLockImmediately(weight, priority) {
301012
- return (this._queue.length === 0 || this._queue[0].priority < priority) && weight <= this._value;
301013
- }
301014
- }
301015
- function insertSorted(a2, v2) {
301016
- const i3 = findIndexFromEnd(a2, (other) => v2.priority <= other.priority);
301017
- a2.splice(i3 + 1, 0, v2);
301018
- }
301019
- function findIndexFromEnd(a2, predicate) {
301020
- for (let i3 = a2.length - 1;i3 >= 0; i3--) {
301021
- if (predicate(a2[i3])) {
301022
- return i3;
301023
- }
301024
- }
301025
- return -1;
301026
- }
301027
-
301028
- class Mutex {
301029
- constructor(cancelError) {
301030
- this._semaphore = new Semaphore(1, cancelError);
301031
- }
301032
- acquire() {
301033
- return __awaiter$1(this, arguments, undefined, function* (priority = 0) {
301034
- const [, releaser] = yield this._semaphore.acquire(1, priority);
301035
- return releaser;
301036
- });
301037
- }
301038
- runExclusive(callback, priority = 0) {
301039
- return this._semaphore.runExclusive(() => callback(), 1, priority);
301040
- }
301041
- isLocked() {
301042
- return this._semaphore.isLocked();
301043
- }
301044
- waitForUnlock(priority = 0) {
301045
- return this._semaphore.waitForUnlock(1, priority);
301046
- }
301047
- release() {
301048
- if (this._semaphore.isLocked())
301049
- this._semaphore.release();
301050
- }
301051
- cancel() {
301052
- return this._semaphore.cancel();
301053
- }
301054
- }
301055
- var E_TIMEOUT, E_ALREADY_LOCKED, E_CANCELED, __awaiter$2 = function(thisArg, _arguments, P2, generator) {
301056
- function adopt(value) {
301057
- return value instanceof P2 ? value : new P2(function(resolve28) {
301058
- resolve28(value);
301059
- });
301060
- }
301061
- return new (P2 || (P2 = Promise))(function(resolve28, reject2) {
301062
- function fulfilled(value) {
301063
- try {
301064
- step(generator.next(value));
301065
- } catch (e) {
301066
- reject2(e);
301067
- }
301068
- }
301069
- function rejected(value) {
301070
- try {
301071
- step(generator["throw"](value));
301072
- } catch (e) {
301073
- reject2(e);
301074
- }
301075
- }
301076
- function step(result) {
301077
- result.done ? resolve28(result.value) : adopt(result.value).then(fulfilled, rejected);
301078
- }
301079
- step((generator = generator.apply(thisArg, _arguments || [])).next());
301080
- });
301081
- }, __awaiter$1 = function(thisArg, _arguments, P2, generator) {
301082
- function adopt(value) {
301083
- return value instanceof P2 ? value : new P2(function(resolve28) {
301084
- resolve28(value);
301085
- });
301086
- }
301087
- return new (P2 || (P2 = Promise))(function(resolve28, reject2) {
301088
- function fulfilled(value) {
301089
- try {
301090
- step(generator.next(value));
301091
- } catch (e) {
301092
- reject2(e);
301093
- }
301094
- }
301095
- function rejected(value) {
301096
- try {
301097
- step(generator["throw"](value));
301098
- } catch (e) {
301099
- reject2(e);
301100
- }
301101
- }
301102
- function step(result) {
301103
- result.done ? resolve28(result.value) : adopt(result.value).then(fulfilled, rejected);
301104
- }
301105
- step((generator = generator.apply(thisArg, _arguments || [])).next());
301106
- });
301107
- };
301108
- var init_async_mutex = __esm(() => {
301109
- E_TIMEOUT = new Error("timeout while waiting for mutex to become available");
301110
- E_ALREADY_LOCKED = new Error("mutex already locked");
301111
- E_CANCELED = new Error("request for lock canceled");
301112
- });
301113
-
301114
301138
  // src/services/api/grove.ts
301115
301139
  function memoizeWithTTL(fn, ttlMs) {
301116
301140
  let lastCachedAt = 0;
@@ -301210,11 +301234,13 @@ async function isQualifiedForGrove() {
301210
301234
  return cachedEntry.grove_enabled;
301211
301235
  }
301212
301236
  async function fetchAndStoreGroveConfig(accountId) {
301237
+ const mapRelease = await groveConfigMapMutex.acquire();
301213
301238
  let mutex = groveConfigMutexes.get(accountId);
301214
301239
  if (!mutex) {
301215
301240
  mutex = new Mutex;
301216
301241
  groveConfigMutexes.set(accountId, mutex);
301217
301242
  }
301243
+ mapRelease();
301218
301244
  const release = await mutex.acquire();
301219
301245
  try {
301220
301246
  const result = await getGroveNoticeConfig();
@@ -301293,7 +301319,7 @@ An update to our Consumer Terms and Privacy Policy will take effect on October 8
301293
301319
  }
301294
301320
  }
301295
301321
  }
301296
- var groveConfigMutexes, GROVE_CACHE_EXPIRATION_MS, GROVE_API_TIMEOUT_MS, getGroveSettings, getGroveNoticeConfig;
301322
+ var groveConfigMutexes, groveConfigMapMutex, GROVE_CACHE_EXPIRATION_MS, GROVE_API_TIMEOUT_MS, getGroveSettings, getGroveNoticeConfig;
301297
301323
  var init_grove = __esm(() => {
301298
301324
  init_axios2();
301299
301325
  init_memoize();
@@ -301307,6 +301333,7 @@ var init_grove = __esm(() => {
301307
301333
  init_log3();
301308
301334
  init_async_mutex();
301309
301335
  groveConfigMutexes = new Map;
301336
+ groveConfigMapMutex = new Mutex;
301310
301337
  GROVE_CACHE_EXPIRATION_MS = 24 * 60 * 60 * 1000;
301311
301338
  GROVE_API_TIMEOUT_MS = parseInt(process.env.GROVE_API_TIMEOUT_MS ?? "3000", 10);
301312
301339
  getGroveSettings = memoizeWithTTL(async () => {
@@ -453850,14 +453877,16 @@ async function fetchAndStorePassesEligibility() {
453850
453877
  if (!orgId) {
453851
453878
  return null;
453852
453879
  }
453853
- if (fetchInProgress) {
453854
- logForDebugging("Passes: Reusing in-flight eligibility fetch");
453855
- return fetchInProgress;
453880
+ const existingPromise = fetchInProgressMap.get(orgId);
453881
+ if (existingPromise) {
453882
+ logForDebugging(`Passes: Reusing in-flight eligibility fetch for org ${orgId}`);
453883
+ return existingPromise;
453856
453884
  }
453857
453885
  let resolvePromise;
453858
- fetchInProgress = new Promise((resolve47) => {
453886
+ const promise3 = new Promise((resolve47) => {
453859
453887
  resolvePromise = resolve47;
453860
453888
  });
453889
+ fetchInProgressMap.set(orgId, promise3);
453861
453890
  (async () => {
453862
453891
  try {
453863
453892
  const response = await fetchReferralEligibility();
@@ -453879,10 +453908,10 @@ async function fetchAndStorePassesEligibility() {
453879
453908
  logError2(error49);
453880
453909
  resolvePromise(null);
453881
453910
  } finally {
453882
- fetchInProgress = null;
453911
+ fetchInProgressMap.delete(orgId);
453883
453912
  }
453884
453913
  })();
453885
- return fetchInProgress;
453914
+ return promise3;
453886
453915
  }
453887
453916
  async function getCachedOrFetchPassesEligibility() {
453888
453917
  if (!shouldCheckForPasses()) {
@@ -453916,7 +453945,7 @@ async function prefetchPassesEligibility() {
453916
453945
  }
453917
453946
  getCachedOrFetchPassesEligibility().catch(() => {});
453918
453947
  }
453919
- var CACHE_EXPIRATION_MS, fetchInProgress = null, CURRENCY_SYMBOLS;
453948
+ var CACHE_EXPIRATION_MS, fetchInProgressMap, CURRENCY_SYMBOLS;
453920
453949
  var init_referral = __esm(() => {
453921
453950
  init_axios2();
453922
453951
  init_oauth();
@@ -453926,6 +453955,7 @@ var init_referral = __esm(() => {
453926
453955
  init_log3();
453927
453956
  init_api2();
453928
453957
  CACHE_EXPIRATION_MS = 24 * 60 * 60 * 1000;
453958
+ fetchInProgressMap = new Map;
453929
453959
  CURRENCY_SYMBOLS = {
453930
453960
  USD: "$",
453931
453961
  EUR: "€",
package/dist/myclaude.mjs CHANGED
@@ -4,8 +4,8 @@
4
4
  // MACRO - build-time constants (injected by build.ts)
5
5
  // MACRO injected by build script
6
6
  globalThis.MACRO = {
7
- VERSION: "0.1.91",
8
- BUILD_TIME: "2026-07-17T20:20:49.267Z",
7
+ VERSION: "0.1.93",
8
+ BUILD_TIME: "2026-07-18T04:08:04.637Z",
9
9
  PACKAGE_URL: "@funnycode/myclaude",
10
10
  NATIVE_PACKAGE_URL: "@funnycode/myclaude",
11
11
  VERSION_CHANGELOG: '',
@@ -117484,7 +117484,7 @@ var package_default;
117484
117484
  var init_package = __esm(() => {
117485
117485
  package_default = {
117486
117486
  name: "@funnycode/myclaude",
117487
- version: "0.1.91",
117487
+ version: "0.1.93",
117488
117488
  private: false,
117489
117489
  description: "An open-source AI coding assistant in your terminal - powered by Claude",
117490
117490
  license: "MIT",
@@ -210146,6 +210146,214 @@ var init_postSamplingHooks = __esm(() => {
210146
210146
  postSamplingHooks = [];
210147
210147
  });
210148
210148
 
210149
+ // node_modules/async-mutex/index.mjs
210150
+ class Semaphore {
210151
+ constructor(_value, _cancelError = E_CANCELED) {
210152
+ this._value = _value;
210153
+ this._cancelError = _cancelError;
210154
+ this._queue = [];
210155
+ this._weightedWaiters = [];
210156
+ }
210157
+ acquire(weight = 1, priority = 0) {
210158
+ if (weight <= 0)
210159
+ throw new Error(`invalid weight ${weight}: must be positive`);
210160
+ return new Promise((resolve25, reject2) => {
210161
+ const task = { resolve: resolve25, reject: reject2, weight, priority };
210162
+ const i3 = findIndexFromEnd(this._queue, (other) => priority <= other.priority);
210163
+ if (i3 === -1 && weight <= this._value) {
210164
+ this._dispatchItem(task);
210165
+ } else {
210166
+ this._queue.splice(i3 + 1, 0, task);
210167
+ }
210168
+ });
210169
+ }
210170
+ runExclusive(callback_1) {
210171
+ return __awaiter$2(this, arguments, undefined, function* (callback, weight = 1, priority = 0) {
210172
+ const [value, release] = yield this.acquire(weight, priority);
210173
+ try {
210174
+ return yield callback(value);
210175
+ } finally {
210176
+ release();
210177
+ }
210178
+ });
210179
+ }
210180
+ waitForUnlock(weight = 1, priority = 0) {
210181
+ if (weight <= 0)
210182
+ throw new Error(`invalid weight ${weight}: must be positive`);
210183
+ if (this._couldLockImmediately(weight, priority)) {
210184
+ return Promise.resolve();
210185
+ } else {
210186
+ return new Promise((resolve25) => {
210187
+ if (!this._weightedWaiters[weight - 1])
210188
+ this._weightedWaiters[weight - 1] = [];
210189
+ insertSorted(this._weightedWaiters[weight - 1], { resolve: resolve25, priority });
210190
+ });
210191
+ }
210192
+ }
210193
+ isLocked() {
210194
+ return this._value <= 0;
210195
+ }
210196
+ getValue() {
210197
+ return this._value;
210198
+ }
210199
+ setValue(value) {
210200
+ this._value = value;
210201
+ this._dispatchQueue();
210202
+ }
210203
+ release(weight = 1) {
210204
+ if (weight <= 0)
210205
+ throw new Error(`invalid weight ${weight}: must be positive`);
210206
+ this._value += weight;
210207
+ this._dispatchQueue();
210208
+ }
210209
+ cancel() {
210210
+ this._queue.forEach((entry) => entry.reject(this._cancelError));
210211
+ this._queue = [];
210212
+ }
210213
+ _dispatchQueue() {
210214
+ this._drainUnlockWaiters();
210215
+ while (this._queue.length > 0 && this._queue[0].weight <= this._value) {
210216
+ this._dispatchItem(this._queue.shift());
210217
+ this._drainUnlockWaiters();
210218
+ }
210219
+ }
210220
+ _dispatchItem(item) {
210221
+ const previousValue = this._value;
210222
+ this._value -= item.weight;
210223
+ item.resolve([previousValue, this._newReleaser(item.weight)]);
210224
+ }
210225
+ _newReleaser(weight) {
210226
+ let called = false;
210227
+ return () => {
210228
+ if (called)
210229
+ return;
210230
+ called = true;
210231
+ this.release(weight);
210232
+ };
210233
+ }
210234
+ _drainUnlockWaiters() {
210235
+ if (this._queue.length === 0) {
210236
+ for (let weight = this._value;weight > 0; weight--) {
210237
+ const waiters = this._weightedWaiters[weight - 1];
210238
+ if (!waiters)
210239
+ continue;
210240
+ waiters.forEach((waiter) => waiter.resolve());
210241
+ this._weightedWaiters[weight - 1] = [];
210242
+ }
210243
+ } else {
210244
+ const queuedPriority = this._queue[0].priority;
210245
+ for (let weight = this._value;weight > 0; weight--) {
210246
+ const waiters = this._weightedWaiters[weight - 1];
210247
+ if (!waiters)
210248
+ continue;
210249
+ const i3 = waiters.findIndex((waiter) => waiter.priority <= queuedPriority);
210250
+ (i3 === -1 ? waiters : waiters.splice(0, i3)).forEach((waiter) => waiter.resolve());
210251
+ }
210252
+ }
210253
+ }
210254
+ _couldLockImmediately(weight, priority) {
210255
+ return (this._queue.length === 0 || this._queue[0].priority < priority) && weight <= this._value;
210256
+ }
210257
+ }
210258
+ function insertSorted(a2, v2) {
210259
+ const i3 = findIndexFromEnd(a2, (other) => v2.priority <= other.priority);
210260
+ a2.splice(i3 + 1, 0, v2);
210261
+ }
210262
+ function findIndexFromEnd(a2, predicate) {
210263
+ for (let i3 = a2.length - 1;i3 >= 0; i3--) {
210264
+ if (predicate(a2[i3])) {
210265
+ return i3;
210266
+ }
210267
+ }
210268
+ return -1;
210269
+ }
210270
+
210271
+ class Mutex {
210272
+ constructor(cancelError) {
210273
+ this._semaphore = new Semaphore(1, cancelError);
210274
+ }
210275
+ acquire() {
210276
+ return __awaiter$1(this, arguments, undefined, function* (priority = 0) {
210277
+ const [, releaser] = yield this._semaphore.acquire(1, priority);
210278
+ return releaser;
210279
+ });
210280
+ }
210281
+ runExclusive(callback, priority = 0) {
210282
+ return this._semaphore.runExclusive(() => callback(), 1, priority);
210283
+ }
210284
+ isLocked() {
210285
+ return this._semaphore.isLocked();
210286
+ }
210287
+ waitForUnlock(priority = 0) {
210288
+ return this._semaphore.waitForUnlock(1, priority);
210289
+ }
210290
+ release() {
210291
+ if (this._semaphore.isLocked())
210292
+ this._semaphore.release();
210293
+ }
210294
+ cancel() {
210295
+ return this._semaphore.cancel();
210296
+ }
210297
+ }
210298
+ var E_TIMEOUT, E_ALREADY_LOCKED, E_CANCELED, __awaiter$2 = function(thisArg, _arguments, P2, generator) {
210299
+ function adopt(value) {
210300
+ return value instanceof P2 ? value : new P2(function(resolve25) {
210301
+ resolve25(value);
210302
+ });
210303
+ }
210304
+ return new (P2 || (P2 = Promise))(function(resolve25, reject2) {
210305
+ function fulfilled(value) {
210306
+ try {
210307
+ step(generator.next(value));
210308
+ } catch (e) {
210309
+ reject2(e);
210310
+ }
210311
+ }
210312
+ function rejected(value) {
210313
+ try {
210314
+ step(generator["throw"](value));
210315
+ } catch (e) {
210316
+ reject2(e);
210317
+ }
210318
+ }
210319
+ function step(result) {
210320
+ result.done ? resolve25(result.value) : adopt(result.value).then(fulfilled, rejected);
210321
+ }
210322
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
210323
+ });
210324
+ }, __awaiter$1 = function(thisArg, _arguments, P2, generator) {
210325
+ function adopt(value) {
210326
+ return value instanceof P2 ? value : new P2(function(resolve25) {
210327
+ resolve25(value);
210328
+ });
210329
+ }
210330
+ return new (P2 || (P2 = Promise))(function(resolve25, reject2) {
210331
+ function fulfilled(value) {
210332
+ try {
210333
+ step(generator.next(value));
210334
+ } catch (e) {
210335
+ reject2(e);
210336
+ }
210337
+ }
210338
+ function rejected(value) {
210339
+ try {
210340
+ step(generator["throw"](value));
210341
+ } catch (e) {
210342
+ reject2(e);
210343
+ }
210344
+ }
210345
+ function step(result) {
210346
+ result.done ? resolve25(result.value) : adopt(result.value).then(fulfilled, rejected);
210347
+ }
210348
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
210349
+ });
210350
+ };
210351
+ var init_async_mutex = __esm(() => {
210352
+ E_TIMEOUT = new Error("timeout while waiting for mutex to become available");
210353
+ E_ALREADY_LOCKED = new Error("mutex already locked");
210354
+ E_CANCELED = new Error("request for lock canceled");
210355
+ });
210356
+
210149
210357
  // src/services/api/dumpPrompts.ts
210150
210358
  import { createHash as createHash5 } from "crypto";
210151
210359
  import { promises as fs11 } from "fs";
@@ -210158,26 +210366,34 @@ function enqueueDumpRequest(agentIdOrSessionId, callback) {
210158
210366
  dumpRequestQueue.set(agentIdOrSessionId, []);
210159
210367
  }
210160
210368
  dumpRequestQueue.get(agentIdOrSessionId).push(callback);
210161
- if (!processingQueues.has(agentIdOrSessionId)) {
210162
- processingQueues.add(agentIdOrSessionId);
210163
- processQueue(agentIdOrSessionId);
210164
- }
210369
+ processQueue(agentIdOrSessionId);
210165
210370
  }
210166
210371
  async function processQueue(agentIdOrSessionId) {
210167
- processingQueues.add(agentIdOrSessionId);
210168
- const queue = dumpRequestQueue.get(agentIdOrSessionId);
210169
- if (!queue || queue.length === 0) {
210170
- dumpRequestQueue.delete(agentIdOrSessionId);
210171
- processingQueues.delete(agentIdOrSessionId);
210172
- return;
210372
+ const mapRelease = await dumpRequestMapMutex.acquire();
210373
+ let mutex = dumpRequestMutexes.get(agentIdOrSessionId);
210374
+ if (!mutex) {
210375
+ mutex = new Mutex;
210376
+ dumpRequestMutexes.set(agentIdOrSessionId, mutex);
210173
210377
  }
210174
- const callback = queue.shift();
210175
- await callback();
210176
- if (queue.length > 0) {
210177
- setImmediate(() => processQueue(agentIdOrSessionId));
210178
- } else {
210179
- dumpRequestQueue.delete(agentIdOrSessionId);
210180
- processingQueues.delete(agentIdOrSessionId);
210378
+ mapRelease();
210379
+ const release = await mutex.acquire();
210380
+ try {
210381
+ const queue = dumpRequestQueue.get(agentIdOrSessionId);
210382
+ if (!queue || queue.length === 0) {
210383
+ dumpRequestQueue.delete(agentIdOrSessionId);
210384
+ dumpRequestMutexes.delete(agentIdOrSessionId);
210385
+ return;
210386
+ }
210387
+ const callback = queue.shift();
210388
+ await callback();
210389
+ if (queue.length > 0) {
210390
+ setImmediate(() => processQueue(agentIdOrSessionId));
210391
+ } else {
210392
+ dumpRequestQueue.delete(agentIdOrSessionId);
210393
+ dumpRequestMutexes.delete(agentIdOrSessionId);
210394
+ }
210395
+ } finally {
210396
+ release();
210181
210397
  }
210182
210398
  }
210183
210399
  function clearDumpState(agentIdOrSessionId) {
@@ -210228,6 +210444,7 @@ async function dumpRequest(body, ts, state, filePath) {
210228
210444
  addApiRequestToCache(req);
210229
210445
  if (process.env.USER_TYPE !== "ant" || process.env.DUMP_PROMPTS !== "1")
210230
210446
  return;
210447
+ logForDebugging("DUMP_PROMPTS is enabled. This will write full API payloads (including system prompts, user messages, and tool definitions) to the filesystem. This is intended for debugging only and should NOT be used in production.", { level: "warn" });
210231
210448
  const entries = [];
210232
210449
  const messages = req.messages ?? [];
210233
210450
  const fingerprint = initFingerprint(req);
@@ -210293,7 +210510,7 @@ function createDumpPromptsFetch(agentIdOrSessionId) {
210293
210510
  const reader = cloned.body.getReader();
210294
210511
  const decoder = new TextDecoder;
210295
210512
  let buffer = "";
210296
- const chunks = [];
210513
+ const chunkEntries = [];
210297
210514
  try {
210298
210515
  while (true) {
210299
210516
  const { done, value } = await reader.read();
@@ -210313,7 +210530,12 @@ function createDumpPromptsFetch(agentIdOrSessionId) {
210313
210530
  `)) {
210314
210531
  if (line.startsWith("data: ") && line !== "data: [DONE]") {
210315
210532
  try {
210316
- chunks.push(jsonParse(line.slice(6)));
210533
+ const chunk = jsonParse(line.slice(6));
210534
+ chunkEntries.push(jsonStringify({ type: "chunk", timestamp, data: chunk }));
210535
+ if (chunkEntries.length >= 50) {
210536
+ await appendToFile(filePath, chunkEntries);
210537
+ chunkEntries.length = 0;
210538
+ }
210317
210539
  } catch (err2) {
210318
210540
  logForDebugging(`dumpPrompts.SSE parse error: ${err2}`, { level: "error" });
210319
210541
  }
@@ -210333,7 +210555,8 @@ function createDumpPromptsFetch(agentIdOrSessionId) {
210333
210555
  `)) {
210334
210556
  if (line.startsWith("data: ") && line !== "data: [DONE]") {
210335
210557
  try {
210336
- chunks.push(jsonParse(line.slice(6)));
210558
+ const chunk = jsonParse(line.slice(6));
210559
+ chunkEntries.push(jsonStringify({ type: "chunk", timestamp, data: chunk }));
210337
210560
  } catch (err2) {
210338
210561
  logForDebugging(`dumpPrompts.SSE parse error: ${err2}`, { level: "error" });
210339
210562
  }
@@ -210341,12 +210564,16 @@ function createDumpPromptsFetch(agentIdOrSessionId) {
210341
210564
  }
210342
210565
  }
210343
210566
  }
210344
- data = { stream: true, chunks };
210567
+ if (chunkEntries.length > 0) {
210568
+ await appendToFile(filePath, chunkEntries);
210569
+ }
210570
+ data = { stream: true, chunks: [] };
210345
210571
  } else {
210346
210572
  data = await cloned.json();
210347
210573
  }
210348
- await fs11.appendFile(filePath, jsonStringify({ type: "response", timestamp, data }) + `
210349
- `);
210574
+ await appendToFile(filePath, [
210575
+ jsonStringify({ type: "response", timestamp, data })
210576
+ ]);
210350
210577
  } catch (err2) {
210351
210578
  try {
210352
210579
  logForDebugging(`dumpPrompts.response handler error: ${err2}`, { level: "error" });
@@ -210359,17 +210586,22 @@ function createDumpPromptsFetch(agentIdOrSessionId) {
210359
210586
  return response;
210360
210587
  };
210361
210588
  }
210362
- var MAX_CACHED_REQUESTS = 5, cachedApiRequests, dumpState, dumpRequestQueue, processingQueues;
210589
+ var MAX_CACHED_REQUESTS = 5, cachedApiRequests, dumpState, dumpRequestQueue, dumpRequestMutexes, dumpRequestMapMutex;
210363
210590
  var init_dumpPrompts = __esm(() => {
210364
210591
  init_state();
210365
210592
  init_envUtils();
210366
210593
  init_slowOperations();
210367
210594
  init_debug();
210368
210595
  init_log3();
210596
+ init_async_mutex();
210597
+ if (process.env.USER_TYPE === "ant" && process.env.DUMP_PROMPTS === "1") {
210598
+ logForDebugging("DUMP_PROMPTS is enabled. This will write full API payloads (including system prompts, user messages, and tool definitions) to the filesystem. This is intended for debugging only and should NOT be used in production.", { level: "warn" });
210599
+ }
210369
210600
  cachedApiRequests = [];
210370
210601
  dumpState = new Map;
210371
210602
  dumpRequestQueue = new Map;
210372
- processingQueues = new Set;
210603
+ dumpRequestMutexes = new Map;
210604
+ dumpRequestMapMutex = new Mutex;
210373
210605
  });
210374
210606
 
210375
210607
  // src/utils/abortController.ts
@@ -300903,214 +301135,6 @@ var init_gracefulShutdown = __esm(() => {
300903
301135
  };
300904
301136
  });
300905
301137
 
300906
- // node_modules/async-mutex/index.mjs
300907
- class Semaphore {
300908
- constructor(_value, _cancelError = E_CANCELED) {
300909
- this._value = _value;
300910
- this._cancelError = _cancelError;
300911
- this._queue = [];
300912
- this._weightedWaiters = [];
300913
- }
300914
- acquire(weight = 1, priority = 0) {
300915
- if (weight <= 0)
300916
- throw new Error(`invalid weight ${weight}: must be positive`);
300917
- return new Promise((resolve28, reject2) => {
300918
- const task = { resolve: resolve28, reject: reject2, weight, priority };
300919
- const i3 = findIndexFromEnd(this._queue, (other) => priority <= other.priority);
300920
- if (i3 === -1 && weight <= this._value) {
300921
- this._dispatchItem(task);
300922
- } else {
300923
- this._queue.splice(i3 + 1, 0, task);
300924
- }
300925
- });
300926
- }
300927
- runExclusive(callback_1) {
300928
- return __awaiter$2(this, arguments, undefined, function* (callback, weight = 1, priority = 0) {
300929
- const [value, release] = yield this.acquire(weight, priority);
300930
- try {
300931
- return yield callback(value);
300932
- } finally {
300933
- release();
300934
- }
300935
- });
300936
- }
300937
- waitForUnlock(weight = 1, priority = 0) {
300938
- if (weight <= 0)
300939
- throw new Error(`invalid weight ${weight}: must be positive`);
300940
- if (this._couldLockImmediately(weight, priority)) {
300941
- return Promise.resolve();
300942
- } else {
300943
- return new Promise((resolve28) => {
300944
- if (!this._weightedWaiters[weight - 1])
300945
- this._weightedWaiters[weight - 1] = [];
300946
- insertSorted(this._weightedWaiters[weight - 1], { resolve: resolve28, priority });
300947
- });
300948
- }
300949
- }
300950
- isLocked() {
300951
- return this._value <= 0;
300952
- }
300953
- getValue() {
300954
- return this._value;
300955
- }
300956
- setValue(value) {
300957
- this._value = value;
300958
- this._dispatchQueue();
300959
- }
300960
- release(weight = 1) {
300961
- if (weight <= 0)
300962
- throw new Error(`invalid weight ${weight}: must be positive`);
300963
- this._value += weight;
300964
- this._dispatchQueue();
300965
- }
300966
- cancel() {
300967
- this._queue.forEach((entry) => entry.reject(this._cancelError));
300968
- this._queue = [];
300969
- }
300970
- _dispatchQueue() {
300971
- this._drainUnlockWaiters();
300972
- while (this._queue.length > 0 && this._queue[0].weight <= this._value) {
300973
- this._dispatchItem(this._queue.shift());
300974
- this._drainUnlockWaiters();
300975
- }
300976
- }
300977
- _dispatchItem(item) {
300978
- const previousValue = this._value;
300979
- this._value -= item.weight;
300980
- item.resolve([previousValue, this._newReleaser(item.weight)]);
300981
- }
300982
- _newReleaser(weight) {
300983
- let called = false;
300984
- return () => {
300985
- if (called)
300986
- return;
300987
- called = true;
300988
- this.release(weight);
300989
- };
300990
- }
300991
- _drainUnlockWaiters() {
300992
- if (this._queue.length === 0) {
300993
- for (let weight = this._value;weight > 0; weight--) {
300994
- const waiters = this._weightedWaiters[weight - 1];
300995
- if (!waiters)
300996
- continue;
300997
- waiters.forEach((waiter) => waiter.resolve());
300998
- this._weightedWaiters[weight - 1] = [];
300999
- }
301000
- } else {
301001
- const queuedPriority = this._queue[0].priority;
301002
- for (let weight = this._value;weight > 0; weight--) {
301003
- const waiters = this._weightedWaiters[weight - 1];
301004
- if (!waiters)
301005
- continue;
301006
- const i3 = waiters.findIndex((waiter) => waiter.priority <= queuedPriority);
301007
- (i3 === -1 ? waiters : waiters.splice(0, i3)).forEach((waiter) => waiter.resolve());
301008
- }
301009
- }
301010
- }
301011
- _couldLockImmediately(weight, priority) {
301012
- return (this._queue.length === 0 || this._queue[0].priority < priority) && weight <= this._value;
301013
- }
301014
- }
301015
- function insertSorted(a2, v2) {
301016
- const i3 = findIndexFromEnd(a2, (other) => v2.priority <= other.priority);
301017
- a2.splice(i3 + 1, 0, v2);
301018
- }
301019
- function findIndexFromEnd(a2, predicate) {
301020
- for (let i3 = a2.length - 1;i3 >= 0; i3--) {
301021
- if (predicate(a2[i3])) {
301022
- return i3;
301023
- }
301024
- }
301025
- return -1;
301026
- }
301027
-
301028
- class Mutex {
301029
- constructor(cancelError) {
301030
- this._semaphore = new Semaphore(1, cancelError);
301031
- }
301032
- acquire() {
301033
- return __awaiter$1(this, arguments, undefined, function* (priority = 0) {
301034
- const [, releaser] = yield this._semaphore.acquire(1, priority);
301035
- return releaser;
301036
- });
301037
- }
301038
- runExclusive(callback, priority = 0) {
301039
- return this._semaphore.runExclusive(() => callback(), 1, priority);
301040
- }
301041
- isLocked() {
301042
- return this._semaphore.isLocked();
301043
- }
301044
- waitForUnlock(priority = 0) {
301045
- return this._semaphore.waitForUnlock(1, priority);
301046
- }
301047
- release() {
301048
- if (this._semaphore.isLocked())
301049
- this._semaphore.release();
301050
- }
301051
- cancel() {
301052
- return this._semaphore.cancel();
301053
- }
301054
- }
301055
- var E_TIMEOUT, E_ALREADY_LOCKED, E_CANCELED, __awaiter$2 = function(thisArg, _arguments, P2, generator) {
301056
- function adopt(value) {
301057
- return value instanceof P2 ? value : new P2(function(resolve28) {
301058
- resolve28(value);
301059
- });
301060
- }
301061
- return new (P2 || (P2 = Promise))(function(resolve28, reject2) {
301062
- function fulfilled(value) {
301063
- try {
301064
- step(generator.next(value));
301065
- } catch (e) {
301066
- reject2(e);
301067
- }
301068
- }
301069
- function rejected(value) {
301070
- try {
301071
- step(generator["throw"](value));
301072
- } catch (e) {
301073
- reject2(e);
301074
- }
301075
- }
301076
- function step(result) {
301077
- result.done ? resolve28(result.value) : adopt(result.value).then(fulfilled, rejected);
301078
- }
301079
- step((generator = generator.apply(thisArg, _arguments || [])).next());
301080
- });
301081
- }, __awaiter$1 = function(thisArg, _arguments, P2, generator) {
301082
- function adopt(value) {
301083
- return value instanceof P2 ? value : new P2(function(resolve28) {
301084
- resolve28(value);
301085
- });
301086
- }
301087
- return new (P2 || (P2 = Promise))(function(resolve28, reject2) {
301088
- function fulfilled(value) {
301089
- try {
301090
- step(generator.next(value));
301091
- } catch (e) {
301092
- reject2(e);
301093
- }
301094
- }
301095
- function rejected(value) {
301096
- try {
301097
- step(generator["throw"](value));
301098
- } catch (e) {
301099
- reject2(e);
301100
- }
301101
- }
301102
- function step(result) {
301103
- result.done ? resolve28(result.value) : adopt(result.value).then(fulfilled, rejected);
301104
- }
301105
- step((generator = generator.apply(thisArg, _arguments || [])).next());
301106
- });
301107
- };
301108
- var init_async_mutex = __esm(() => {
301109
- E_TIMEOUT = new Error("timeout while waiting for mutex to become available");
301110
- E_ALREADY_LOCKED = new Error("mutex already locked");
301111
- E_CANCELED = new Error("request for lock canceled");
301112
- });
301113
-
301114
301138
  // src/services/api/grove.ts
301115
301139
  function memoizeWithTTL(fn, ttlMs) {
301116
301140
  let lastCachedAt = 0;
@@ -301210,11 +301234,13 @@ async function isQualifiedForGrove() {
301210
301234
  return cachedEntry.grove_enabled;
301211
301235
  }
301212
301236
  async function fetchAndStoreGroveConfig(accountId) {
301237
+ const mapRelease = await groveConfigMapMutex.acquire();
301213
301238
  let mutex = groveConfigMutexes.get(accountId);
301214
301239
  if (!mutex) {
301215
301240
  mutex = new Mutex;
301216
301241
  groveConfigMutexes.set(accountId, mutex);
301217
301242
  }
301243
+ mapRelease();
301218
301244
  const release = await mutex.acquire();
301219
301245
  try {
301220
301246
  const result = await getGroveNoticeConfig();
@@ -301293,7 +301319,7 @@ An update to our Consumer Terms and Privacy Policy will take effect on October 8
301293
301319
  }
301294
301320
  }
301295
301321
  }
301296
- var groveConfigMutexes, GROVE_CACHE_EXPIRATION_MS, GROVE_API_TIMEOUT_MS, getGroveSettings, getGroveNoticeConfig;
301322
+ var groveConfigMutexes, groveConfigMapMutex, GROVE_CACHE_EXPIRATION_MS, GROVE_API_TIMEOUT_MS, getGroveSettings, getGroveNoticeConfig;
301297
301323
  var init_grove = __esm(() => {
301298
301324
  init_axios2();
301299
301325
  init_memoize();
@@ -301307,6 +301333,7 @@ var init_grove = __esm(() => {
301307
301333
  init_log3();
301308
301334
  init_async_mutex();
301309
301335
  groveConfigMutexes = new Map;
301336
+ groveConfigMapMutex = new Mutex;
301310
301337
  GROVE_CACHE_EXPIRATION_MS = 24 * 60 * 60 * 1000;
301311
301338
  GROVE_API_TIMEOUT_MS = parseInt(process.env.GROVE_API_TIMEOUT_MS ?? "3000", 10);
301312
301339
  getGroveSettings = memoizeWithTTL(async () => {
@@ -453850,14 +453877,16 @@ async function fetchAndStorePassesEligibility() {
453850
453877
  if (!orgId) {
453851
453878
  return null;
453852
453879
  }
453853
- if (fetchInProgress) {
453854
- logForDebugging("Passes: Reusing in-flight eligibility fetch");
453855
- return fetchInProgress;
453880
+ const existingPromise = fetchInProgressMap.get(orgId);
453881
+ if (existingPromise) {
453882
+ logForDebugging(`Passes: Reusing in-flight eligibility fetch for org ${orgId}`);
453883
+ return existingPromise;
453856
453884
  }
453857
453885
  let resolvePromise;
453858
- fetchInProgress = new Promise((resolve47) => {
453886
+ const promise3 = new Promise((resolve47) => {
453859
453887
  resolvePromise = resolve47;
453860
453888
  });
453889
+ fetchInProgressMap.set(orgId, promise3);
453861
453890
  (async () => {
453862
453891
  try {
453863
453892
  const response = await fetchReferralEligibility();
@@ -453879,10 +453908,10 @@ async function fetchAndStorePassesEligibility() {
453879
453908
  logError2(error49);
453880
453909
  resolvePromise(null);
453881
453910
  } finally {
453882
- fetchInProgress = null;
453911
+ fetchInProgressMap.delete(orgId);
453883
453912
  }
453884
453913
  })();
453885
- return fetchInProgress;
453914
+ return promise3;
453886
453915
  }
453887
453916
  async function getCachedOrFetchPassesEligibility() {
453888
453917
  if (!shouldCheckForPasses()) {
@@ -453916,7 +453945,7 @@ async function prefetchPassesEligibility() {
453916
453945
  }
453917
453946
  getCachedOrFetchPassesEligibility().catch(() => {});
453918
453947
  }
453919
- var CACHE_EXPIRATION_MS, fetchInProgress = null, CURRENCY_SYMBOLS;
453948
+ var CACHE_EXPIRATION_MS, fetchInProgressMap, CURRENCY_SYMBOLS;
453920
453949
  var init_referral = __esm(() => {
453921
453950
  init_axios2();
453922
453951
  init_oauth();
@@ -453926,6 +453955,7 @@ var init_referral = __esm(() => {
453926
453955
  init_log3();
453927
453956
  init_api2();
453928
453957
  CACHE_EXPIRATION_MS = 24 * 60 * 60 * 1000;
453958
+ fetchInProgressMap = new Map;
453929
453959
  CURRENCY_SYMBOLS = {
453930
453960
  USD: "$",
453931
453961
  EUR: "€",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnycode/myclaude",
3
- "version": "0.1.91",
3
+ "version": "0.1.93",
4
4
  "private": false,
5
5
  "description": "An open-source AI coding assistant in your terminal - powered by Claude",
6
6
  "license": "MIT",