threenative-engine-mcp 0.2.15 → 0.2.17
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.d.ts +15 -1
- package/dist/index.js +85 -33
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -65,6 +65,20 @@ interface ICapabilitySearchResponse {
|
|
|
65
65
|
readonly verdict: "matched" | "none" | "starterKit";
|
|
66
66
|
readonly results: readonly ICapabilitySearchResult[];
|
|
67
67
|
readonly guidance: string;
|
|
68
|
+
/**
|
|
69
|
+
* Suggestions under the relevance floor, on a generic `none` only (PRD-063). They share a
|
|
70
|
+
* situation word but are not binding capabilities, and a not-owned request never carries them:
|
|
71
|
+
* "write it in src/" is then the whole answer, and a near symbol would send the author elsewhere.
|
|
72
|
+
*/
|
|
73
|
+
readonly nearMatches?: readonly ICapabilityNearMatch[];
|
|
74
|
+
}
|
|
75
|
+
/** One row of `nearMatches`: enough to recognise the capability, none of the detail a hit carries. */
|
|
76
|
+
interface ICapabilityNearMatch {
|
|
77
|
+
readonly symbol: string;
|
|
78
|
+
readonly importPath: string;
|
|
79
|
+
readonly summary: string;
|
|
80
|
+
readonly matchedSituation: string;
|
|
81
|
+
readonly score: number;
|
|
68
82
|
}
|
|
69
83
|
interface ICapabilityDetail extends ICapabilityEntry {
|
|
70
84
|
}
|
|
@@ -120,4 +134,4 @@ declare function runCli(argv: readonly string[], manifestFile?: string, io?: {
|
|
|
120
134
|
}): Promise<number>;
|
|
121
135
|
declare function runServer(manifestFile?: string): void;
|
|
122
136
|
|
|
123
|
-
export { ENGINE_MCP_TOOL_NAMES, type ICapabilityDetail, type ICapabilityEntry, type ICapabilityManifest, type ICapabilitySearchResponse, type ICapabilitySearchResult, type IEngineTool, type INotOwnedCapability, type IStarterKit, type IStarterKitResult, RELEVANCE_FLOOR, capabilityDetail, capabilityDetails, capabilitySituationTokens, defaultManifestPath, handleLine, loadCapabilityManifest, runCli, runServer, searchCapabilities, toolDefinitions };
|
|
137
|
+
export { ENGINE_MCP_TOOL_NAMES, type ICapabilityDetail, type ICapabilityEntry, type ICapabilityManifest, type ICapabilityNearMatch, type ICapabilitySearchResponse, type ICapabilitySearchResult, type IEngineTool, type INotOwnedCapability, type IStarterKit, type IStarterKitResult, RELEVANCE_FLOOR, capabilityDetail, capabilityDetails, capabilitySituationTokens, defaultManifestPath, handleLine, loadCapabilityManifest, runCli, runServer, searchCapabilities, toolDefinitions };
|
package/dist/index.js
CHANGED
|
@@ -608,6 +608,7 @@ var STOP_WORDS = /* @__PURE__ */ new Set([
|
|
|
608
608
|
]);
|
|
609
609
|
var MAX_COMPLETE_REQUEST_RESULTS = 15;
|
|
610
610
|
var MAX_SITUATION_RESULTS = 5;
|
|
611
|
+
var MAX_NEAR_MATCHES = 3;
|
|
611
612
|
var RELEVANCE_FLOOR = 0.27;
|
|
612
613
|
var AUTHORING_INSTRUCTIONS = "Follow the Authoring flow in the game's AGENTS.md (the threenative-capabilities skill holds the detail): search capabilities and references before the first new src/ file, for a new game and for every change to an existing game. Follow binding capability constraints. Execute with subagents focused on specific areas: bounded tasks, file ownership, then coordinator integration before mechanics playtests. References borrow mechanics only: no code, level layouts, character names or art; cite pinned file:line sources.";
|
|
613
614
|
var GENERIC_GUIDANCE = "No installed engine capability matches this situation. Decompose it into concrete mechanics and write the game-owned behavior in your project's src/; inspect the relevant template AGENTS.md before adding a package.";
|
|
@@ -801,6 +802,13 @@ function isDistinctivePhrase(candidate) {
|
|
|
801
802
|
return !(candidate.agreed === 1 && candidate.coverage < LONE_WORD_COVERAGE);
|
|
802
803
|
}
|
|
803
804
|
function scoreReadableSituations(situations, queryTokens, queryText, weights) {
|
|
805
|
+
if (queryTokens.size === 0)
|
|
806
|
+
return {
|
|
807
|
+
best: 0,
|
|
808
|
+
bestReadableScore: 0,
|
|
809
|
+
bestReadableSituation: situations[0] ?? "",
|
|
810
|
+
matchedSituation: ""
|
|
811
|
+
};
|
|
804
812
|
let best = 0;
|
|
805
813
|
let matchedSituation = "";
|
|
806
814
|
let bestReadableScore = 0;
|
|
@@ -817,9 +825,10 @@ function scoreReadableSituations(situations, queryTokens, queryText, weights) {
|
|
|
817
825
|
matchedSituation = situation;
|
|
818
826
|
}
|
|
819
827
|
}
|
|
820
|
-
return { best, bestReadableSituation, matchedSituation };
|
|
828
|
+
return { best, bestReadableScore, bestReadableSituation, matchedSituation };
|
|
821
829
|
}
|
|
822
830
|
function scoreAliases(aliases, queryTokens, queryText, weights) {
|
|
831
|
+
if (queryTokens.size === 0) return 0;
|
|
823
832
|
let best = 0;
|
|
824
833
|
for (const alias of aliases) {
|
|
825
834
|
const candidate = scorePhrase(alias, queryTokens, queryText, weights);
|
|
@@ -827,14 +836,19 @@ function scoreAliases(aliases, queryTokens, queryText, weights) {
|
|
|
827
836
|
}
|
|
828
837
|
return best;
|
|
829
838
|
}
|
|
839
|
+
function answeredSituation(readable, aliasScore) {
|
|
840
|
+
const best = Math.max(readable.best, aliasScore);
|
|
841
|
+
const matchedSituation = readable.matchedSituation.length > 0 ? readable.matchedSituation : best >= RELEVANCE_FLOOR ? readable.bestReadableSituation : "";
|
|
842
|
+
return matchedSituation.length > 0 ? { matchedSituation, score: best } : { matchedSituation: "", score: 0 };
|
|
843
|
+
}
|
|
830
844
|
function situationScore(query, situations, aliases, weights) {
|
|
831
845
|
if (query.length === 0) return { matchedSituation: "", score: 0 };
|
|
832
846
|
const queryTokens = new Set(query);
|
|
833
847
|
const queryText = query.join(" ");
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
848
|
+
return answeredSituation(
|
|
849
|
+
scoreReadableSituations(situations, queryTokens, queryText, weights),
|
|
850
|
+
scoreAliases(aliases, queryTokens, queryText, weights)
|
|
851
|
+
);
|
|
838
852
|
}
|
|
839
853
|
var EXACT_SYMBOL_LEAD = 4;
|
|
840
854
|
var NAME_BASE_LEAD = 2;
|
|
@@ -962,7 +976,10 @@ function searchCapabilities(situation, manifestFile = defaultManifestPath(), sco
|
|
|
962
976
|
throw new Error("engine_search_capabilities requires a non-empty situation string.");
|
|
963
977
|
const manifest = loadCapabilityManifest(manifestFile);
|
|
964
978
|
const starterKits = matchedStarterKits(situation, manifest.starterKits ?? []);
|
|
965
|
-
const response = withReferenceTools(
|
|
979
|
+
const response = withReferenceTools(
|
|
980
|
+
situation,
|
|
981
|
+
searchMechanics(situation, manifest, scope, starterKits.length === 0)
|
|
982
|
+
);
|
|
966
983
|
if (starterKits.length === 0) return response;
|
|
967
984
|
return {
|
|
968
985
|
starterKits,
|
|
@@ -997,29 +1014,30 @@ function manifestWeights(entries) {
|
|
|
997
1014
|
}
|
|
998
1015
|
return cached;
|
|
999
1016
|
}
|
|
1000
|
-
function searchMechanics(situation, manifest, scope) {
|
|
1017
|
+
function searchMechanics(situation, manifest, scope, suggest = true) {
|
|
1001
1018
|
const query = tokens(situation);
|
|
1002
1019
|
const limit = scope === "request" ? MAX_COMPLETE_REQUEST_RESULTS : MAX_SITUATION_RESULTS;
|
|
1003
1020
|
const { weights, nameWeights } = manifestWeights(manifest.entries);
|
|
1004
1021
|
const notOwned = notOwnedMatch(manifest, query);
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1022
|
+
const specific = notOwned !== void 0 && isSpecificNotOwnedMatch(query, notOwned.matchedSituation);
|
|
1023
|
+
const optionalPackage = specific ? `@threenative/${notOwned.entry.id}` : void 0;
|
|
1024
|
+
const candidates = optionalPackage === void 0 ? manifest.entries : manifest.entries.filter(
|
|
1025
|
+
(entry) => entry.importPath === optionalPackage || entry.importPath.startsWith(`${optionalPackage}/`)
|
|
1026
|
+
);
|
|
1027
|
+
if (specific && candidates.length === 0) {
|
|
1028
|
+
return { guidance: notOwned.entry.guidance, results: [], verdict: "none" };
|
|
1011
1029
|
}
|
|
1012
|
-
const
|
|
1013
|
-
|
|
1014
|
-
).sort(
|
|
1030
|
+
const floor = optionalPackage === void 0 ? RELEVANCE_FLOOR : Number.MIN_VALUE;
|
|
1031
|
+
const scored = candidates.map((entry) => ({ entry, ...capabilityScore(query, entry, weights, nameWeights, situation) })).filter(({ matchedSituation }) => matchedSituation.length > 0).sort(
|
|
1015
1032
|
(left, right) => right.score - left.score || right.specificity - left.specificity || `${left.entry.importPath}:${left.entry.symbol}`.localeCompare(
|
|
1016
1033
|
`${right.entry.importPath}:${right.entry.symbol}`
|
|
1017
1034
|
)
|
|
1018
1035
|
).filter(
|
|
1019
|
-
(candidate, index,
|
|
1036
|
+
(candidate, index, all) => all.findIndex(
|
|
1020
1037
|
(other) => capabilitySearchKey(other.entry) === capabilitySearchKey(candidate.entry)
|
|
1021
1038
|
) === index
|
|
1022
|
-
)
|
|
1039
|
+
);
|
|
1040
|
+
const results = scored.filter(({ score }) => score >= floor).slice(0, limit).map(({ entry, matchedSituation, score }) => ({
|
|
1023
1041
|
constraints: entry.constraints,
|
|
1024
1042
|
...entry.deprecated === void 0 ? {} : { deprecated: entry.deprecated },
|
|
1025
1043
|
example: entry.example,
|
|
@@ -1032,11 +1050,20 @@ function searchMechanics(situation, manifest, scope) {
|
|
|
1032
1050
|
summary: entry.summary,
|
|
1033
1051
|
symbol: entry.symbol
|
|
1034
1052
|
}));
|
|
1035
|
-
if (results.length > 0)
|
|
1053
|
+
if (results.length > 0)
|
|
1054
|
+
return { guidance: specific ? notOwned.entry.guidance : "", results, verdict: "matched" };
|
|
1055
|
+
const nearMatches = suggest && notOwned === void 0 ? scored.filter(({ score }) => score < floor).slice(0, MAX_NEAR_MATCHES).map(({ entry, matchedSituation, score }) => ({
|
|
1056
|
+
importPath: entry.importPath,
|
|
1057
|
+
matchedSituation,
|
|
1058
|
+
score,
|
|
1059
|
+
summary: entry.summary,
|
|
1060
|
+
symbol: entry.symbol
|
|
1061
|
+
})) : [];
|
|
1036
1062
|
return {
|
|
1037
1063
|
guidance: notOwned?.entry.guidance ?? GENERIC_GUIDANCE,
|
|
1038
1064
|
results: [],
|
|
1039
|
-
verdict: "none"
|
|
1065
|
+
verdict: "none",
|
|
1066
|
+
...nearMatches.length > 0 ? { nearMatches } : {}
|
|
1040
1067
|
};
|
|
1041
1068
|
}
|
|
1042
1069
|
function capabilityDetails(symbol, manifestFile = defaultManifestPath(), importPath) {
|
|
@@ -1063,7 +1090,7 @@ var TOOL_DEFINITIONS = [
|
|
|
1063
1090
|
{
|
|
1064
1091
|
annotations: { destructiveHint: false, openWorldHint: false, readOnlyHint: true },
|
|
1065
1092
|
name: "engine_search_capabilities",
|
|
1066
|
-
description: 'Search the installed engine by concrete gameplay mechanic or by an exact exported symbol name. Decompose genres first. Use scope "request" for the mechanically explicit full request and "mechanic" for each focused search; matchedSituation and score explain every result. A row carries the answer (importPath, signature, example, constraints, overrides, deprecations), so call engine_capability_detail only for a symbol the search did not return. The response verdict "none" is an actionable answer with guidance, not a failed search.',
|
|
1093
|
+
description: 'Search the installed engine by concrete gameplay mechanic or by an exact exported symbol name. Decompose genres first. Use scope "request" for the mechanically explicit full request and "mechanic" for each focused search; matchedSituation and score explain every result. A row carries the answer (importPath, signature, example, constraints, overrides, deprecations), so call engine_capability_detail only for a symbol the search did not return. The response verdict "none" is an actionable answer with guidance, not a failed search; its nearMatches are below-floor suggestions that are not binding capabilities.',
|
|
1067
1094
|
inputSchema: {
|
|
1068
1095
|
additionalProperties: false,
|
|
1069
1096
|
properties: {
|
|
@@ -1097,7 +1124,7 @@ var TOOL_DEFINITIONS = [
|
|
|
1097
1124
|
},
|
|
1098
1125
|
{
|
|
1099
1126
|
name: "engine_search_references",
|
|
1100
|
-
description: "Reverse engineer classic games: search mechanic cards and repository map nodes from their decomps. Tier-2 titles link to repos to explore and save. References describe feel only; borrow algorithms, cite pinned sources, copy no code or art.",
|
|
1127
|
+
description: "Reverse engineer classic games: search mechanic cards and repository map nodes from their decomps. Tier-2 titles link to repos to explore and save. References describe feel only; borrow algorithms, cite pinned sources, copy no code or art. An empty reply lists nearMatches: near misses that are suggestions, not capabilities.",
|
|
1101
1128
|
annotations: { destructiveHint: false, openWorldHint: true, readOnlyHint: true },
|
|
1102
1129
|
inputSchema: {
|
|
1103
1130
|
type: "object",
|
|
@@ -1250,20 +1277,45 @@ async function searchReferences(situation, limit = 5) {
|
|
|
1250
1277
|
}));
|
|
1251
1278
|
const weights = tokenWeights(phrases);
|
|
1252
1279
|
const query = tokens(situation);
|
|
1280
|
+
const querySet = new Set(query);
|
|
1281
|
+
const queryText = query.join(" ");
|
|
1282
|
+
const scored = candidates.map((stub, index) => {
|
|
1283
|
+
const situations = phrases[index]?.situations ?? [];
|
|
1284
|
+
const readable = scoreReadableSituations(situations, querySet, queryText, weights);
|
|
1285
|
+
const content = answeredSituation(readable, 0);
|
|
1286
|
+
const title = scoreAliases(phrases[index]?.aliases ?? [], querySet, queryText, weights);
|
|
1287
|
+
return {
|
|
1288
|
+
near: { score: readable.bestReadableScore, situation: readable.bestReadableSituation },
|
|
1289
|
+
stub: { ...stub, ...content, score: content.score + title }
|
|
1290
|
+
};
|
|
1291
|
+
});
|
|
1292
|
+
const results = scored.filter(({ stub }) => stub.score >= RELEVANCE_FLOOR).sort((a, b) => b.stub.score - a.stub.score || a.stub.id.localeCompare(b.stub.id)).slice(0, limit).map(({ stub }) => stub);
|
|
1293
|
+
const nearMatches = results.length === 0 ? referenceSuggestions(scored) : [];
|
|
1253
1294
|
return {
|
|
1254
1295
|
guidance: "",
|
|
1255
|
-
results
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
);
|
|
1263
|
-
return { ...stub, ...content, score: content.score + title };
|
|
1264
|
-
}).filter((stub) => stub.score >= RELEVANCE_FLOOR).sort((a, b) => b.score - a.score || a.id.localeCompare(b.id)).slice(0, limit)
|
|
1296
|
+
results,
|
|
1297
|
+
// An empty reply still names what came close, with the ids engine_reference_detail takes, so a
|
|
1298
|
+
// miss is not a dead end (PRD-063). The score is the one the phrase reached: a capability search
|
|
1299
|
+
// drops a row for being under the floor, while a reference search also drops it for resting on a
|
|
1300
|
+
// word too common to answer alone, so a suggestion here can outscore the floor and still not be
|
|
1301
|
+
// a result. Reference rows carry no binding promise either way.
|
|
1302
|
+
...nearMatches.length > 0 ? { nearMatches } : {}
|
|
1265
1303
|
};
|
|
1266
1304
|
}
|
|
1305
|
+
function referenceSuggestions(scored) {
|
|
1306
|
+
return scored.filter(({ near }) => near.score > 0 && near.situation.length > 0).sort((a, b) => b.near.score - a.near.score || a.stub.id.localeCompare(b.stub.id)).slice(0, MAX_NEAR_MATCHES).map(({ near, stub }) => ({
|
|
1307
|
+
game: stub.game,
|
|
1308
|
+
id: stub.id,
|
|
1309
|
+
kind: stub.kind,
|
|
1310
|
+
matchedSituation: near.situation,
|
|
1311
|
+
// A tier-2 title is a repository, not a card: engine_reference_detail refuses kind "game", so
|
|
1312
|
+
// the link is what makes the suggestion actionable.
|
|
1313
|
+
..."repo" in stub && typeof stub.repo === "string" && stub.repo.length > 0 ? { repo: stub.repo } : {},
|
|
1314
|
+
score: near.score,
|
|
1315
|
+
summary: stub.summary,
|
|
1316
|
+
title: stub.title
|
|
1317
|
+
}));
|
|
1318
|
+
}
|
|
1267
1319
|
async function handleToolCall(params, manifestFile) {
|
|
1268
1320
|
const name = params.name;
|
|
1269
1321
|
const argumentsValue = isRecord(params.arguments) ? params.arguments : {};
|
|
@@ -1385,7 +1437,7 @@ async function handleLine(line2, manifestFile) {
|
|
|
1385
1437
|
capabilities: { tools: { listChanged: false } },
|
|
1386
1438
|
instructions: AUTHORING_INSTRUCTIONS,
|
|
1387
1439
|
protocolVersion: "2025-06-18",
|
|
1388
|
-
serverInfo: { name: "threenative-engine-mcp", version: "0.2.
|
|
1440
|
+
serverInfo: { name: "threenative-engine-mcp", version: "0.2.17" }
|
|
1389
1441
|
});
|
|
1390
1442
|
}
|
|
1391
1443
|
if (request.method === "tools/list") {
|