@c4a/context-cli 0.7.73 → 0.7.80

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/cli.js CHANGED
@@ -42109,6 +42109,40 @@ var init_debugTrace = __esm(() => {
42109
42109
  SENSITIVE_OPTION = /^(--(?:auth|authorization|password|secret|token|otp|cookie|api-key))(?:=|$)/iu;
42110
42110
  });
42111
42111
 
42112
+ // src/project/derivedValueCache.ts
42113
+ class DerivedValueCache {
42114
+ values = new Map;
42115
+ bytes = 0;
42116
+ get(key, calculate) {
42117
+ const existing = this.values.get(key);
42118
+ if (existing) {
42119
+ this.values.delete(key);
42120
+ this.values.set(key, existing);
42121
+ return existing.value;
42122
+ }
42123
+ const value = calculate();
42124
+ let serialized;
42125
+ try {
42126
+ serialized = JSON.stringify(value);
42127
+ } catch {
42128
+ return value;
42129
+ }
42130
+ if (serialized === undefined)
42131
+ return value;
42132
+ const bytes = Buffer.byteLength(key) + Buffer.byteLength(serialized);
42133
+ if (bytes > 8 * 1024 * 1024)
42134
+ return value;
42135
+ while (this.values.size >= 512 || this.bytes + bytes > 8 * 1024 * 1024) {
42136
+ const oldest = this.values.keys().next().value;
42137
+ this.bytes -= this.values.get(oldest).bytes;
42138
+ this.values.delete(oldest);
42139
+ }
42140
+ this.values.set(key, { value, bytes });
42141
+ this.bytes += bytes;
42142
+ return value;
42143
+ }
42144
+ }
42145
+
42112
42146
  // src/project/commandReadCache.ts
42113
42147
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
42114
42148
  import { readdir as readdir3, stat as stat2 } from "node:fs/promises";
@@ -42122,7 +42156,7 @@ async function readCommandDirectory(path2) {
42122
42156
  return [...entries];
42123
42157
  }
42124
42158
  function withCommandReadCache(action) {
42125
- return commandReads.getStore() === undefined ? commandReads.run(new Map, action) : action();
42159
+ return commandReads.getStore() === undefined ? commandValues.run(new DerivedValueCache, () => commandReads.run(new Map, action)) : action();
42126
42160
  }
42127
42161
  async function reuseCommandFileRead(input) {
42128
42162
  const cache = commandReads.getStore();
@@ -42178,10 +42212,15 @@ async function reuseCommandFileRead(input) {
42178
42212
  throw error;
42179
42213
  }
42180
42214
  }
42181
- var commandReads, MAX_READS = 64;
42215
+ function reuseCommandValue(key, calculate) {
42216
+ const cache = commandValues.getStore();
42217
+ return cache ? cache.get(key, calculate) : calculate();
42218
+ }
42219
+ var commandReads, MAX_READS = 64, commandValues;
42182
42220
  var init_commandReadCache = __esm(() => {
42183
42221
  init_debugTrace();
42184
42222
  commandReads = new AsyncLocalStorage2;
42223
+ commandValues = new AsyncLocalStorage2;
42185
42224
  });
42186
42225
 
42187
42226
  // src/project/writeLock.ts
@@ -53416,8 +53455,11 @@ function destinationRange(raw) {
53416
53455
  function markdownInlineLinks(content3) {
53417
53456
  if (!content3.includes("["))
53418
53457
  return [];
53419
- const tree = unified().use(remarkParse).parse(content3);
53420
- return inlineLinksFromTree(content3, tree);
53458
+ const links = reuseCommandValue(`markdown-inline-links:${content3}`, () => {
53459
+ const tree = unified().use(remarkParse).parse(content3);
53460
+ return inlineLinksFromTree(content3, tree);
53461
+ });
53462
+ return links.map((link) => ({ ...link }));
53421
53463
  }
53422
53464
  function inlineLinksFromTree(content3, tree) {
53423
53465
  const links = [];
@@ -53504,6 +53546,7 @@ function replaceMarkdownInlineLinkTargets(content3, replacement) {
53504
53546
  var init_markdownLinks = __esm(() => {
53505
53547
  init_remark_parse();
53506
53548
  init_unified();
53549
+ init_commandReadCache();
53507
53550
  });
53508
53551
 
53509
53552
  // src/project/documentCaptureAssets.ts