threenative-engine-mcp 0.2.13 → 0.2.16

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/dist/index.js +44 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { realpathSync, readFileSync, existsSync, mkdirSync, rmSync, writeFileSync, appendFileSync, mkdtempSync, renameSync, readdirSync } from 'fs';
2
+ import { realpathSync, statSync, readFileSync, existsSync, mkdirSync, rmSync, writeFileSync, appendFileSync, mkdtempSync, renameSync, readdirSync } from 'fs';
3
3
  import path from 'path';
4
4
  import { createInterface } from 'readline';
5
5
  import { fileURLToPath } from 'url';
@@ -673,15 +673,23 @@ function validateManifest(value, file) {
673
673
  }
674
674
  return value;
675
675
  }
676
+ var manifestCache = /* @__PURE__ */ new Map();
676
677
  function loadCapabilityManifest(file = defaultManifestPath()) {
677
678
  let raw;
679
+ let stamp;
678
680
  try {
681
+ const stat = statSync(file);
682
+ stamp = `${stat.mtimeMs}:${stat.size}`;
683
+ const cached = manifestCache.get(file);
684
+ if (cached?.stamp === stamp) return cached.manifest;
679
685
  raw = readFileSync(file, "utf8");
680
686
  } catch (error) {
681
687
  throw manifestError(file, `cannot read committed manifest: ${String(error)}`);
682
688
  }
683
689
  try {
684
- return validateManifest(JSON.parse(raw), file);
690
+ const manifest = validateManifest(JSON.parse(raw), file);
691
+ manifestCache.set(file, { stamp, manifest });
692
+ return manifest;
685
693
  } catch (error) {
686
694
  if (error instanceof Error && error.message.startsWith("TN_ENGINE_CAPABILITIES_MANIFEST:"))
687
695
  throw error;
@@ -710,7 +718,17 @@ function splitSymbolCase(value) {
710
718
  function capabilitySituationTokens(value) {
711
719
  return splitSymbolCase(value).toLocaleLowerCase().split(/[^a-z0-9]+/u).filter((token) => token.length > 1 && !STOP_WORDS.has(token)).map(stem).filter((token) => !STOP_WORD_STEMS.has(token));
712
720
  }
713
- var tokens = capabilitySituationTokens;
721
+ var tokenCache = /* @__PURE__ */ new Map();
722
+ var TOKEN_CACHE_LIMIT = 2e4;
723
+ function tokens(value) {
724
+ let cached = tokenCache.get(value);
725
+ if (cached === void 0) {
726
+ if (tokenCache.size >= TOKEN_CACHE_LIMIT) tokenCache.clear();
727
+ cached = Object.freeze(capabilitySituationTokens(value));
728
+ tokenCache.set(value, cached);
729
+ }
730
+ return cached;
731
+ }
714
732
  function tokenWeights(entries) {
715
733
  const frequency = /* @__PURE__ */ new Map();
716
734
  let situations = 0;
@@ -970,27 +988,35 @@ function withReferenceTools(situation, response) {
970
988
  guidance: `Reverse engineer the game with engine_search_references, then engine_reference_detail for its pinned cards. ${response.guidance}`
971
989
  };
972
990
  }
991
+ var weightCache = /* @__PURE__ */ new WeakMap();
992
+ function manifestWeights(entries) {
993
+ let cached = weightCache.get(entries);
994
+ if (cached === void 0) {
995
+ cached = { weights: tokenWeights(entries), nameWeights: nameTokenWeights(entries) };
996
+ weightCache.set(entries, cached);
997
+ }
998
+ return cached;
999
+ }
973
1000
  function searchMechanics(situation, manifest, scope) {
974
1001
  const query = tokens(situation);
975
1002
  const limit = scope === "request" ? MAX_COMPLETE_REQUEST_RESULTS : MAX_SITUATION_RESULTS;
976
- const weights = tokenWeights(manifest.entries);
977
- const nameWeights = nameTokenWeights(manifest.entries);
1003
+ const { weights, nameWeights } = manifestWeights(manifest.entries);
978
1004
  const notOwned = notOwnedMatch(manifest, query);
979
- if (notOwned !== void 0 && isSpecificNotOwnedMatch(query, notOwned.matchedSituation)) {
980
- return {
981
- guidance: notOwned.entry.guidance,
982
- results: [],
983
- verdict: "none"
984
- };
1005
+ const specific = notOwned !== void 0 && isSpecificNotOwnedMatch(query, notOwned.matchedSituation);
1006
+ const optionalPackage = specific ? `@threenative/${notOwned.entry.id}` : void 0;
1007
+ const candidates = optionalPackage === void 0 ? manifest.entries : manifest.entries.filter(
1008
+ (entry) => entry.importPath === optionalPackage || entry.importPath.startsWith(`${optionalPackage}/`)
1009
+ );
1010
+ if (specific && candidates.length === 0) {
1011
+ return { guidance: notOwned.entry.guidance, results: [], verdict: "none" };
985
1012
  }
986
- const results = manifest.entries.map((entry) => ({ entry, ...capabilityScore(query, entry, weights, nameWeights, situation) })).filter(
987
- ({ matchedSituation, score }) => matchedSituation.length > 0 && score >= RELEVANCE_FLOOR
988
- ).sort(
1013
+ const floor = optionalPackage === void 0 ? RELEVANCE_FLOOR : Number.MIN_VALUE;
1014
+ const results = candidates.map((entry) => ({ entry, ...capabilityScore(query, entry, weights, nameWeights, situation) })).filter(({ matchedSituation, score }) => matchedSituation.length > 0 && score >= floor).sort(
989
1015
  (left, right) => right.score - left.score || right.specificity - left.specificity || `${left.entry.importPath}:${left.entry.symbol}`.localeCompare(
990
1016
  `${right.entry.importPath}:${right.entry.symbol}`
991
1017
  )
992
1018
  ).filter(
993
- (candidate, index, candidates) => candidates.findIndex(
1019
+ (candidate, index, candidates2) => candidates2.findIndex(
994
1020
  (other) => capabilitySearchKey(other.entry) === capabilitySearchKey(candidate.entry)
995
1021
  ) === index
996
1022
  ).slice(0, limit).map(({ entry, matchedSituation, score }) => ({
@@ -1006,7 +1032,8 @@ function searchMechanics(situation, manifest, scope) {
1006
1032
  summary: entry.summary,
1007
1033
  symbol: entry.symbol
1008
1034
  }));
1009
- if (results.length > 0) return { guidance: "", results, verdict: "matched" };
1035
+ if (results.length > 0)
1036
+ return { guidance: specific ? notOwned.entry.guidance : "", results, verdict: "matched" };
1010
1037
  return {
1011
1038
  guidance: notOwned?.entry.guidance ?? GENERIC_GUIDANCE,
1012
1039
  results: [],
@@ -1359,7 +1386,7 @@ async function handleLine(line2, manifestFile) {
1359
1386
  capabilities: { tools: { listChanged: false } },
1360
1387
  instructions: AUTHORING_INSTRUCTIONS,
1361
1388
  protocolVersion: "2025-06-18",
1362
- serverInfo: { name: "threenative-engine-mcp", version: "0.2.13" }
1389
+ serverInfo: { name: "threenative-engine-mcp", version: "0.2.16" }
1363
1390
  });
1364
1391
  }
1365
1392
  if (request.method === "tools/list") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "threenative-engine-mcp",
3
- "version": "0.2.13",
3
+ "version": "0.2.16",
4
4
  "license": "MIT",
5
5
  "description": "Offline MCP capability discovery for ThreeNative authoring agents.",
6
6
  "keywords": [