@zqagent/core 0.3.22 → 0.3.25

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/index.js CHANGED
@@ -9020,6 +9020,7 @@ function markLoaded(langId) {
9020
9020
  failedAt.delete(langId);
9021
9021
  }
9022
9022
  var inflight = /* @__PURE__ */ new Map();
9023
+ var readyCache = /* @__PURE__ */ new Map();
9023
9024
  function grammarDir() {
9024
9025
  const explicit = process.env.ZQAGENT_REPOMAP_GRAMMAR_DIR?.trim();
9025
9026
  if (explicit) return explicit;
@@ -9043,10 +9044,7 @@ function verify(spec, buf) {
9043
9044
  return sha256Hex(buf) === spec.sha256;
9044
9045
  }
9045
9046
  function readLocal(spec) {
9046
- const candidates = [cachePath(spec)];
9047
- const explicit = process.env.ZQAGENT_REPOMAP_GRAMMAR_DIR?.trim();
9048
- if (explicit) candidates.push(path14.join(explicit, `${spec.id}.wasm`));
9049
- for (const file of candidates) {
9047
+ for (const file of localCandidates(spec)) {
9050
9048
  try {
9051
9049
  const buf = fs11.readFileSync(file);
9052
9050
  if (verify(spec, buf)) return new Uint8Array(buf);
@@ -9055,6 +9053,24 @@ function readLocal(spec) {
9055
9053
  }
9056
9054
  return null;
9057
9055
  }
9056
+ function localCandidates(spec) {
9057
+ const candidates = [cachePath(spec)];
9058
+ const explicit = process.env.ZQAGENT_REPOMAP_GRAMMAR_DIR?.trim();
9059
+ if (explicit) candidates.push(path14.join(explicit, `${spec.id}.wasm`));
9060
+ return candidates;
9061
+ }
9062
+ function localSignature(spec) {
9063
+ const parts = [];
9064
+ for (const file of localCandidates(spec)) {
9065
+ try {
9066
+ const st = fs11.statSync(file);
9067
+ parts.push(`${st.mtimeMs}:${st.size}`);
9068
+ } catch {
9069
+ parts.push("-");
9070
+ }
9071
+ }
9072
+ return parts.join("|");
9073
+ }
9058
9074
  async function download(spec) {
9059
9075
  if (offline()) return null;
9060
9076
  for (const build of CDN_TEMPLATES) {
@@ -9113,7 +9129,13 @@ async function loadGrammar(langId) {
9113
9129
  function grammarReady(langId) {
9114
9130
  if (resolved.get(langId)) return true;
9115
9131
  const spec = GRAMMARS[langId];
9116
- return spec ? readLocal(spec) !== null : false;
9132
+ if (!spec) return false;
9133
+ const sig = localSignature(spec);
9134
+ const hit = readyCache.get(langId);
9135
+ if (hit && hit.sig === sig) return hit.ready;
9136
+ const ready = readLocal(spec) !== null;
9137
+ readyCache.set(langId, { sig, ready });
9138
+ return ready;
9117
9139
  }
9118
9140
 
9119
9141
  // src/repomap/extract/index.ts
@@ -9965,10 +9987,12 @@ function attachRepoMap(engine, opts) {
9965
9987
  const original = spec.func;
9966
9988
  engine.registry.register(
9967
9989
  async (args, ctx) => {
9968
- const out = await original(args, ctx);
9969
- invalidateRepoMap(workspace);
9970
- schedule();
9971
- return out;
9990
+ try {
9991
+ return await original(args, ctx);
9992
+ } finally {
9993
+ invalidateRepoMap(workspace);
9994
+ schedule();
9995
+ }
9972
9996
  },
9973
9997
  spec.metadata,
9974
9998
  spec.schema,