threenative-engine-mcp 0.2.13 → 0.2.15
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 +32 -6
- 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
|
-
|
|
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
|
|
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,11 +988,19 @@ 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 =
|
|
977
|
-
const nameWeights = nameTokenWeights(manifest.entries);
|
|
1003
|
+
const { weights, nameWeights } = manifestWeights(manifest.entries);
|
|
978
1004
|
const notOwned = notOwnedMatch(manifest, query);
|
|
979
1005
|
if (notOwned !== void 0 && isSpecificNotOwnedMatch(query, notOwned.matchedSituation)) {
|
|
980
1006
|
return {
|
|
@@ -1359,7 +1385,7 @@ async function handleLine(line2, manifestFile) {
|
|
|
1359
1385
|
capabilities: { tools: { listChanged: false } },
|
|
1360
1386
|
instructions: AUTHORING_INSTRUCTIONS,
|
|
1361
1387
|
protocolVersion: "2025-06-18",
|
|
1362
|
-
serverInfo: { name: "threenative-engine-mcp", version: "0.2.
|
|
1388
|
+
serverInfo: { name: "threenative-engine-mcp", version: "0.2.15" }
|
|
1363
1389
|
});
|
|
1364
1390
|
}
|
|
1365
1391
|
if (request.method === "tools/list") {
|