@eleboucher/opencode-memini 0.7.4 → 0.7.7

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/memini.js +14 -4
  2. package/package.json +1 -1
package/memini.js CHANGED
@@ -443,15 +443,25 @@ export function effectiveConfig(cfg, hs) {
443
443
  // shape MeminiPlugin uses to memoize the handshake per session. `now` is
444
444
  // injectable so tests can drive expiry without a real 10-minute sleep.
445
445
  // Exported for testing.
446
+ //
447
+ // Caches the promise, not the resolved value, so concurrent callers share
448
+ // one in-flight call. Clears on rejection so a transient failure doesn't
449
+ // poison the TTL window.
446
450
  export function memoizeAsync(fn, ttlMs, now = Date.now) {
447
- let cached = null; // { value, expiresAt }
451
+ let cached = null; // { promise, expiresAt }
448
452
  return async () => {
449
453
  const t = now();
450
454
  if (!cached || t >= cached.expiresAt) {
451
- const value = await fn();
452
- cached = { value, expiresAt: t + ttlMs };
455
+ const promise = fn();
456
+ cached = { promise, expiresAt: t + ttlMs };
457
+ promise.then(
458
+ () => {},
459
+ () => {
460
+ if (cached && cached.promise === promise) cached = null;
461
+ },
462
+ );
453
463
  }
454
- return cached.value;
464
+ return cached.promise;
455
465
  };
456
466
  }
457
467
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleboucher/opencode-memini",
3
- "version": "0.7.4",
3
+ "version": "0.7.7",
4
4
  "description": "Automatic cross-session memory for opencode via memini — recall before each turn, capture after.",
5
5
  "keywords": [
6
6
  "memini",