hoi4-agent-tools 4.11.1 → 4.13.0
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/CHANGELOG.md +21 -0
- package/README.md +3 -3
- package/dist/bin/setup.js +38 -0
- package/dist/bin/stdio.js +12 -10
- package/dist/hoi4_agent_tools/core/configuration.js +29 -0
- package/dist/hoi4_agent_tools/core/domain-tools.js +4 -0
- package/dist/hoi4_agent_tools/core/engine-check.js +87 -0
- package/dist/hoi4_agent_tools/core/engine-client.js +1 -1
- package/dist/hoi4_agent_tools/core/engine.js +18 -2
- package/dist/hoi4_agent_tools/core/job-operation-registration.js +2 -0
- package/dist/hoi4_agent_tools/core/job-store.js +1 -1
- package/dist/hoi4_agent_tools/focus/native-effects.js +1 -1
- package/dist/hoi4_agent_tools/localisation/job-operations.js +42 -0
- package/dist/hoi4_agent_tools/localisation/write-diff.js +96 -0
- package/dist/hoi4_agent_tools/localisation/write-format.js +329 -0
- package/dist/hoi4_agent_tools/localisation/write-operations.js +213 -0
- package/dist/hoi4_agent_tools/localisation/write-plan.js +557 -0
- package/dist/hoi4_agent_tools/map/gameplay/crossing-validation.js +17 -0
- package/dist/hoi4_agent_tools/map/model.js +31 -1
- package/dist/hoi4_agent_tools/map/operations.js +37 -8
- package/dist/hoi4_agent_tools/map/references.js +87 -0
- package/dist/hoi4_agent_tools/map/relief/hydrology.js +7 -2
- package/dist/hoi4_agent_tools/map/relief/terrain-synthesis.js +1 -0
- package/dist/hoi4_agent_tools/map/service.js +13 -4
- package/dist/hoi4_agent_tools/map/tool-operations.js +6 -0
- package/dist/hoi4_agent_tools/map/world-edge.js +0 -25
- package/dist/hoi4_agent_tools/map/world.js +181 -64
- package/dist/hoi4_agent_tools/mcp/plugins.js +74 -0
- package/dist/hoi4_agent_tools/mcp/server/argument-errors.js +5 -0
- package/dist/hoi4_agent_tools/mcp/server/create-modern-operations.js +15 -21
- package/dist/hoi4_agent_tools/mcp/server/create.js +5 -1
- package/dist/hoi4_agent_tools/mcp/server/request-lifecycle.js +10 -2
- package/dist/hoi4_agent_tools/mcp/server/task-tool-catalog.js +2 -0
- package/dist/hoi4_agent_tools/mcp/server/tool-profiles.js +83 -0
- package/dist/hoi4_agent_tools/mcp/tools/localisation-write.js +21 -0
- package/dist/hoi4_agent_tools/mcp/tools/reference.js +34 -0
- package/dist/hoi4_agent_tools/mcp/transports/http.js +6 -1
- package/dist/hoi4_agent_tools/mcp/transports/negotiated-stdio.js +64 -6
- package/dist/hoi4_agent_tools/probability/model.js +4 -4
- package/dist/hoi4_agent_tools/reference/compat-patch.js +555 -0
- package/dist/hoi4_agent_tools/reference/compat.js +255 -0
- package/dist/hoi4_agent_tools/reference/docs-pack.js +164 -0
- package/dist/hoi4_agent_tools/reference/docs-pack.json +339 -0
- package/dist/hoi4_agent_tools/reference/documented-commands.js +26 -0
- package/dist/hoi4_agent_tools/reference/error-explain.js +235 -0
- package/dist/hoi4_agent_tools/reference/error-explanations.json +262 -0
- package/dist/hoi4_agent_tools/reference/error-log.js +30 -10
- package/dist/hoi4_agent_tools/reference/mod-health.js +255 -0
- package/dist/hoi4_agent_tools/reference/mod-index.js +63 -65
- package/dist/hoi4_agent_tools/reference/operations.js +435 -21
- package/dist/hoi4_agent_tools/reference/script-guard.js +109 -0
- package/dist/hoi4_agent_tools/reference/service.js +58 -20
- package/dist/hoi4_agent_tools/runtime.js +17 -2
- package/dist/hoi4_agent_tools/schemas/compat.js +153 -0
- package/dist/hoi4_agent_tools/schemas/localisation-write.js +154 -0
- package/dist/hoi4_agent_tools/schemas/map.js +5 -1
- package/dist/hoi4_agent_tools/schemas/mod-tools.js +50 -0
- package/dist/hoi4_agent_tools/schemas/modder-tools.js +191 -0
- package/dist/hoi4_agent_tools/version.js +1 -1
- package/docs/configuration.md +14 -11
- package/docs/development.md +2 -0
- package/docs/jobs.md +3 -1
- package/docs/map.md +8 -4
- package/docs/reference.md +47 -5
- package/docs/research/probability-adapter-evidence.md +11 -1
- package/docs/setup.md +23 -3
- package/docs/tools.md +18 -4
- package/docs/troubleshooting.md +1 -1
- package/engine/bin/darwin-arm64/hoi4-engine +0 -0
- package/engine/bin/linux-arm64/hoi4-engine +0 -0
- package/engine/bin/linux-x64/hoi4-engine +0 -0
- package/engine/bin/manifest.json +8 -8
- package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/schemas/configuration.schema.json +181 -138
- package/schemas/continuous-focus-palette.schema.json +1 -1
- package/schemas/custom-weighted-pool.schema.json +1 -1
- package/schemas/decision-inspect-input.schema.json +1 -1
- package/schemas/error-log-input.schema.json +1 -1
- package/schemas/event-feature-manifest.schema.json +1 -1
- package/schemas/focus-plan.schema.json +1 -1
- package/schemas/focus-planning-sidecar.schema.json +1 -1
- package/schemas/geography-model.schema.json +1 -1
- package/schemas/gui-animation-source.schema.json +1 -1
- package/schemas/gui-helper.schema.json +1 -1
- package/schemas/gui-scenario.schema.json +1 -1
- package/schemas/helper-expansion-request.schema.json +1 -1
- package/schemas/helper-expansion-summary.schema.json +1 -1
- package/schemas/impact-inspect-input.schema.json +1 -1
- package/schemas/map-operation.schema.json +153 -139
- package/schemas/mechanic-test-input.schema.json +1 -1
- package/schemas/mod-index-input.schema.json +1 -1
- package/schemas/operation-result.schema.json +1 -1
- package/schemas/package-check-input.schema.json +1 -1
- package/schemas/package-manifest.schema.json +1 -1
- package/schemas/probability-analysis-result.schema.json +1 -1
- package/schemas/probability-compare-input.schema.json +1 -1
- package/schemas/probability-evaluate-input.schema.json +1 -1
- package/schemas/probability-inspect-input.schema.json +1 -1
- package/schemas/probability-render-input.schema.json +1 -1
- package/schemas/probability-scenario-set.schema.json +1 -1
- package/schemas/probability-sequence-input.schema.json +1 -1
- package/schemas/probability-simulate-input.schema.json +1 -1
- package/schemas/probability-sweep-input.schema.json +1 -1
- package/schemas/reference-context-input.schema.json +1 -1
- package/schemas/reference-read-input.schema.json +1 -1
- package/schemas/reference-search-input.schema.json +1 -1
- package/schemas/reference-sheets.schema.json +1 -1
- package/schemas/scenario-suite.schema.json +1 -1
- package/schemas/scenario-test-input.schema.json +1 -1
- package/schemas/script-validate-input.schema.json +1 -1
- package/schemas/shared-scenario.schema.json +1 -1
- package/schemas/source-lookup-input.schema.json +1 -1
- package/server.json +2 -2
- package/dist/hoi4_agent_tools/mcp/tools/chaosx.js +0 -509
|
@@ -22,7 +22,7 @@ import { planEconomy } from './gameplay/economy.js';
|
|
|
22
22
|
import { prepareGameplay } from './gameplay/prepare.js';
|
|
23
23
|
import { fractal, lattice } from './world-noise.js';
|
|
24
24
|
import { calibratedColourMap, COLOUR_CLASSES, } from './colormap.js';
|
|
25
|
-
import { ambientObjectText, applyEdgePolicy, assertFeaturesOutsideBand, edgeWaterDarkness, hasRimRange, RIM_COLOUR_FACTOR,
|
|
25
|
+
import { ambientObjectText, applyEdgePolicy, assertFeaturesOutsideBand, edgeWaterDarkness, hasRimRange, RIM_COLOUR_FACTOR, rimHeight, rimStrength, WALL_TERRAIN_KINDS, wallRowKinds, } from './world-edge.js';
|
|
26
26
|
import { landDistanceField, lakeHeight, normalizeLakes, waterColourLevel } from './water.js';
|
|
27
27
|
import { DEFAULT_PAINTED_RELIEF } from './relief/painted-relief.js';
|
|
28
28
|
import { rowStrips, scanAreaStrip } from './geography/index.js';
|
|
@@ -651,10 +651,44 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
651
651
|
height,
|
|
652
652
|
land: (pixel) => surface.kind[pixel] === LAND,
|
|
653
653
|
});
|
|
654
|
-
|
|
655
|
-
|
|
654
|
+
// Cities and capitals on impassable land are known from the impassable mask alone, so they are
|
|
655
|
+
// found before the synthesis, not after the partition.
|
|
656
|
+
const onImpassable = ({ x, y }) => {
|
|
657
|
+
const px = Math.floor(x);
|
|
658
|
+
const py = Math.floor(y);
|
|
659
|
+
return (px >= 0 && py >= 0 && px < width && py < height && impassableMask?.[py * width + px] === 1);
|
|
660
|
+
};
|
|
661
|
+
const offendingCities = (spec.referenceCities ?? []).filter(onImpassable);
|
|
662
|
+
const cityError = offendingCities.length === 0
|
|
663
|
+
? undefined
|
|
664
|
+
: new ServiceError('MAP_FEATURE_IN_IMPASSABLE', `${offendingCities.length} city or cities stand on impassable land: ${offendingCities
|
|
665
|
+
.slice(0, 5)
|
|
666
|
+
.map(({ name, x, y }) => `${name} (${Math.round(x)}, ${Math.round(y)})`)
|
|
667
|
+
.join('; ')}. Move them or repaint the land.`, { cities: offendingCities.slice(0, 20) });
|
|
668
|
+
if (options.riverCheck !== true) {
|
|
669
|
+
if (pointProblems.length > 0)
|
|
670
|
+
throw realmPointsError(pointProblems);
|
|
671
|
+
if (cityError !== undefined)
|
|
672
|
+
throw cityError;
|
|
673
|
+
}
|
|
656
674
|
if (options.riverCheck === true && geography !== undefined) {
|
|
657
|
-
|
|
675
|
+
// The check reports every blocking problem it can find without a partition in one answer:
|
|
676
|
+
// realm points, cities and capitals on impassable land, unreachable rivers and filled passes.
|
|
677
|
+
const blocking = [];
|
|
678
|
+
if (pointProblems.length > 0)
|
|
679
|
+
blocking.push(realmPointsError(pointProblems));
|
|
680
|
+
if (cityError !== undefined)
|
|
681
|
+
blocking.push(cityError);
|
|
682
|
+
const walledCapitals = (spec.realms?.list ?? []).filter(({ capital }) => onImpassable(capital));
|
|
683
|
+
if (walledCapitals.length > 0)
|
|
684
|
+
blocking.push(new ServiceError('MAP_FEATURE_IN_IMPASSABLE', `${walledCapitals.length} capital(s) stand on impassable land: ${walledCapitals
|
|
685
|
+
.slice(0, 5)
|
|
686
|
+
.map(({ tag, capital }) => `${tag} (${Math.round(capital.x)}, ${Math.round(capital.y)})`)
|
|
687
|
+
.join('; ')}. Move them onto passable land.`, {
|
|
688
|
+
capitals: walledCapitals
|
|
689
|
+
.slice(0, 20)
|
|
690
|
+
.map(({ tag, capital }) => ({ tag, x: capital.x, y: capital.y })),
|
|
691
|
+
}));
|
|
658
692
|
try {
|
|
659
693
|
const checked = checkTerrainRivers({
|
|
660
694
|
geography,
|
|
@@ -670,34 +704,26 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
670
704
|
painted,
|
|
671
705
|
signal: options.signal,
|
|
672
706
|
});
|
|
673
|
-
for (const note of checked)
|
|
674
|
-
if (note.severity === 'error')
|
|
675
|
-
throw new ServiceError(note.code, note.message, note.details);
|
|
707
|
+
for (const note of checked)
|
|
676
708
|
notes.push({
|
|
677
709
|
code: note.code,
|
|
678
710
|
severity: note.severity,
|
|
679
711
|
message: note.message,
|
|
680
712
|
...(note.details === undefined ? {} : { details: note.details }),
|
|
681
713
|
});
|
|
682
|
-
}
|
|
683
714
|
}
|
|
684
715
|
catch (error) {
|
|
685
716
|
if (!(error instanceof ServiceError))
|
|
686
717
|
throw error;
|
|
687
|
-
|
|
688
|
-
}
|
|
689
|
-
// The preview reports the realm points and the synthesis together.
|
|
690
|
-
if (pointProblems.length > 0) {
|
|
691
|
-
const pointError = realmPointsError(pointProblems);
|
|
692
|
-
throw failure === undefined
|
|
693
|
-
? pointError
|
|
694
|
-
: new ServiceError(pointError.code, `${pointError.message}. The relief synthesis also failed: ${failure.message}`, {
|
|
695
|
-
...pointError.details,
|
|
696
|
-
synthesis: { code: failure.code, message: failure.message, details: failure.details },
|
|
697
|
-
});
|
|
718
|
+
blocking.push(error);
|
|
698
719
|
}
|
|
699
|
-
|
|
700
|
-
|
|
720
|
+
for (const error of blocking)
|
|
721
|
+
notes.push({
|
|
722
|
+
code: error.code,
|
|
723
|
+
severity: 'error',
|
|
724
|
+
message: error.message,
|
|
725
|
+
details: error.details,
|
|
726
|
+
});
|
|
701
727
|
return {
|
|
702
728
|
files: [],
|
|
703
729
|
warnings: [],
|
|
@@ -900,16 +926,17 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
900
926
|
return found;
|
|
901
927
|
};
|
|
902
928
|
const wallProvinces = majorityIn(wallMask);
|
|
929
|
+
// `rim` and `wall` close the seam with impassable land, never with adjacency rows: the engine
|
|
930
|
+
// does not wrap adjacencies and draws a row between the two edges as a line across the whole
|
|
931
|
+
// map. Every land province on the first or last column is therefore impassable.
|
|
932
|
+
if (hasRimRange(edge))
|
|
933
|
+
for (let y = 0; y < height; y += 1)
|
|
934
|
+
for (const pixel of [y * width, y * width + width - 1]) {
|
|
935
|
+
const id = provinces.pixel[pixel];
|
|
936
|
+
if (provinces.kind[id] === LAND)
|
|
937
|
+
wallProvinces.add(id);
|
|
938
|
+
}
|
|
903
939
|
const impassableProvinces = new Set([...wallProvinces, ...majorityIn(impassableMask)]);
|
|
904
|
-
const offendingCities = (spec.referenceCities ?? []).filter(({ x, y }) => {
|
|
905
|
-
const pixel = Math.floor(y) * width + Math.floor(x);
|
|
906
|
-
return impassableMask?.[pixel] === 1;
|
|
907
|
-
});
|
|
908
|
-
if (offendingCities.length > 0)
|
|
909
|
-
throw new ServiceError('MAP_FEATURE_IN_IMPASSABLE', `${offendingCities.length} city or cities stand on impassable land: ${offendingCities
|
|
910
|
-
.slice(0, 5)
|
|
911
|
-
.map(({ name, x, y }) => `${name} (${Math.round(x)}, ${Math.round(y)})`)
|
|
912
|
-
.join('; ')}. Move them or repaint the land.`, { cities: offendingCities.slice(0, 20) });
|
|
913
940
|
if (landIds.length < spec.countries.length)
|
|
914
941
|
throw new ServiceError('MAP_WORLD_LAND_TOO_SMALL', 'The generated land has fewer provinces than countries; raise landCoverage or lower landProvincePixels', { landProvinces: landIds.length, countries: spec.countries.length });
|
|
915
942
|
const coastal = (id) => [...provinces.neighbors[id]].some((other) => provinces.kind[id] === SEA
|
|
@@ -978,19 +1005,50 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
978
1005
|
terrain.set(id, referenceTerrainNames[selected]);
|
|
979
1006
|
}
|
|
980
1007
|
}
|
|
1008
|
+
// Impassable land (the `wall` at the seam, painted or regional impassable land) joins no
|
|
1009
|
+
// landmasses or strategic regions: no army crosses it, and the wall's two halves meet only
|
|
1010
|
+
// across the seam. Its connected pieces, never joined across the seam, follow the passable
|
|
1011
|
+
// land they border. A world without passable land keeps the plain land connectivity.
|
|
1012
|
+
const separateImpassable = impassableProvinces.size > 0 && landIds.some((id) => !impassableProvinces.has(id));
|
|
1013
|
+
const acrossSeam = (left, right) => Math.abs(provinces.sumX[left] / provinces.size[left] -
|
|
1014
|
+
provinces.sumX[right] / provinces.size[right]) >
|
|
1015
|
+
width / 2;
|
|
1016
|
+
const impassableComponents = [];
|
|
1017
|
+
if (separateImpassable) {
|
|
1018
|
+
const seen = new Set();
|
|
1019
|
+
for (const start of landIds) {
|
|
1020
|
+
if (!impassableProvinces.has(start) || seen.has(start))
|
|
1021
|
+
continue;
|
|
1022
|
+
const component = [start];
|
|
1023
|
+
seen.add(start);
|
|
1024
|
+
// The array iterator also visits the provinces pushed while it runs.
|
|
1025
|
+
for (const current of component) {
|
|
1026
|
+
for (const next of provinces.neighbors[current])
|
|
1027
|
+
if (impassableProvinces.has(next) && !seen.has(next) && !acrossSeam(current, next)) {
|
|
1028
|
+
seen.add(next);
|
|
1029
|
+
component.push(next);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
impassableComponents.push(component);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
const joinsLand = (id) => provinces.kind[id] === LAND && !(separateImpassable && impassableProvinces.has(id));
|
|
1036
|
+
const passableLandIds = separateImpassable
|
|
1037
|
+
? landIds.filter((id) => !impassableProvinces.has(id))
|
|
1038
|
+
: landIds;
|
|
981
1039
|
// Continents: the largest land masses, with islands joining the nearest one.
|
|
982
1040
|
const landParts = new Map();
|
|
983
1041
|
{
|
|
984
1042
|
let part = 0;
|
|
985
1043
|
for (const start of landIds) {
|
|
986
|
-
if (landParts.has(start))
|
|
1044
|
+
if (landParts.has(start) || !joinsLand(start))
|
|
987
1045
|
continue;
|
|
988
1046
|
const queue = [start];
|
|
989
1047
|
landParts.set(start, part);
|
|
990
1048
|
while (queue.length > 0) {
|
|
991
1049
|
const current = queue.pop();
|
|
992
1050
|
for (const next of provinces.neighbors[current])
|
|
993
|
-
if (
|
|
1051
|
+
if (joinsLand(next) && !landParts.has(next)) {
|
|
994
1052
|
landParts.set(next, part);
|
|
995
1053
|
queue.push(next);
|
|
996
1054
|
}
|
|
@@ -1033,6 +1091,45 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
1033
1091
|
best = position;
|
|
1034
1092
|
continentOfPart.set(part, best + 1);
|
|
1035
1093
|
}
|
|
1094
|
+
// Each impassable piece takes the landmass of its largest passable neighbour, or, when it
|
|
1095
|
+
// borders only water (as the wall usually does), the landmass of the nearest passable province.
|
|
1096
|
+
for (const component of impassableComponents) {
|
|
1097
|
+
let chosen = -1;
|
|
1098
|
+
for (const id of component)
|
|
1099
|
+
for (const next of provinces.neighbors[id]) {
|
|
1100
|
+
const part = landParts.get(next);
|
|
1101
|
+
if (part === undefined || impassableProvinces.has(next) || acrossSeam(id, next))
|
|
1102
|
+
continue;
|
|
1103
|
+
if (chosen < 0 ||
|
|
1104
|
+
partSizes.get(part) > partSizes.get(chosen) ||
|
|
1105
|
+
(partSizes.get(part) === partSizes.get(chosen) && part < chosen))
|
|
1106
|
+
chosen = part;
|
|
1107
|
+
}
|
|
1108
|
+
if (chosen < 0) {
|
|
1109
|
+
let sx = 0;
|
|
1110
|
+
let sy = 0;
|
|
1111
|
+
let n = 0;
|
|
1112
|
+
for (const id of component) {
|
|
1113
|
+
sx += provinces.sumX[id];
|
|
1114
|
+
sy += provinces.sumY[id];
|
|
1115
|
+
n += provinces.size[id];
|
|
1116
|
+
}
|
|
1117
|
+
let nearest = Number.POSITIVE_INFINITY;
|
|
1118
|
+
for (const id of landIds) {
|
|
1119
|
+
if (impassableProvinces.has(id))
|
|
1120
|
+
continue;
|
|
1121
|
+
const c = center(id);
|
|
1122
|
+
const distance = Math.hypot(c.x - sx / n, c.y - sy / n);
|
|
1123
|
+
if (distance < nearest) {
|
|
1124
|
+
nearest = distance;
|
|
1125
|
+
chosen = landParts.get(id);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
for (const id of component)
|
|
1130
|
+
landParts.set(id, chosen);
|
|
1131
|
+
}
|
|
1132
|
+
const generatedContinentKeys = majorParts.map((_, index) => `world_continent_${index + 1}`);
|
|
1036
1133
|
const continentNames = majorParts.map((_, index) => spec.continentNames?.[index] ?? `Continent ${String.fromCharCode(65 + (index % 26))}`);
|
|
1037
1134
|
// Countries: grow territories from spread-out capitals in proportion to their shares.
|
|
1038
1135
|
const owner = new Map();
|
|
@@ -1194,7 +1291,12 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
1194
1291
|
}
|
|
1195
1292
|
const shares = spec.countries.map((country) => Math.max(0.05, country.share ?? 1));
|
|
1196
1293
|
const owned = new Array(countryCount).fill(0);
|
|
1294
|
+
// Countries grow over passable land only, so none crosses impassable land or the wall from one
|
|
1295
|
+
// edge to the other. Impassable provinces stay unowned here; their states take the owner of the
|
|
1296
|
+
// passable state they link to (finishImpassableStates).
|
|
1197
1297
|
for (const [id, country] of realmRules?.forced ?? referenceOwners) {
|
|
1298
|
+
if (!joinsLand(id))
|
|
1299
|
+
continue;
|
|
1198
1300
|
owner.set(id, country);
|
|
1199
1301
|
owned[country] += provinces.size[id];
|
|
1200
1302
|
}
|
|
@@ -1206,7 +1308,7 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
1206
1308
|
owner.set(capital, index);
|
|
1207
1309
|
if (realmRules !== undefined)
|
|
1208
1310
|
return [...owner]
|
|
1209
|
-
.filter(([, country]) => country === index)
|
|
1311
|
+
.filter(([id, country]) => country === index && joinsLand(id))
|
|
1210
1312
|
.flatMap(([id]) => [...provinces.neighbors[id]]);
|
|
1211
1313
|
return [...provinces.neighbors[capital]];
|
|
1212
1314
|
});
|
|
@@ -1214,13 +1316,13 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
1214
1316
|
// The feature-aware partition grows generated countries along its natural lines (ADR 0060).
|
|
1215
1317
|
// Workspace-owned countries keep the realm growth with its forced and blocked land (ADR 0069).
|
|
1216
1318
|
if (featurePartition !== undefined && referenceOwners.size === 0 && realmRules === undefined) {
|
|
1217
|
-
const atoms = buildTerritoryAtoms(territoryGraphFromPartition(featurePartition.graph, provinces.sumX, provinces.sumY),
|
|
1319
|
+
const atoms = buildTerritoryAtoms(territoryGraphFromPartition(featurePartition.graph, provinces.sumX, provinces.sumY), passableLandIds.map((id) => [id]));
|
|
1218
1320
|
const grown = growTerritory(atoms, spec.countries.map((country, index) => ({
|
|
1219
1321
|
tag: country.tag,
|
|
1220
1322
|
weight: shares[index],
|
|
1221
1323
|
seeds: [atoms.atomOfProvince[capitals[index]]],
|
|
1222
1324
|
})), { seed: spec.seed });
|
|
1223
|
-
for (const [atom, id] of
|
|
1325
|
+
for (const [atom, id] of passableLandIds.entries())
|
|
1224
1326
|
if (grown.owner[atom] >= 0)
|
|
1225
1327
|
owner.set(id, grown.owner[atom]);
|
|
1226
1328
|
grownByTerritory = true;
|
|
@@ -1228,7 +1330,7 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
1228
1330
|
while (!grownByTerritory) {
|
|
1229
1331
|
let chosen = -1;
|
|
1230
1332
|
for (let index = 0; index < countryCount; index += 1) {
|
|
1231
|
-
frontiers[index] = frontiers[index].filter((id) =>
|
|
1333
|
+
frontiers[index] = frontiers[index].filter((id) => joinsLand(id) && !owner.has(id) && !blockedFor(index, id));
|
|
1232
1334
|
if (frontiers[index].length === 0)
|
|
1233
1335
|
continue;
|
|
1234
1336
|
if (chosen < 0 || owned[index] / shares[index] < owned[chosen] / shares[chosen])
|
|
@@ -1247,7 +1349,7 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
1247
1349
|
// Land no workspace country reached follows the island rule; the rest of the land is unowned.
|
|
1248
1350
|
if (realmRules !== undefined)
|
|
1249
1351
|
assignUnreachedRealmLand({
|
|
1250
|
-
landIds,
|
|
1352
|
+
landIds: passableLandIds,
|
|
1251
1353
|
owner,
|
|
1252
1354
|
unowned: unownedLand,
|
|
1253
1355
|
capitals,
|
|
@@ -1257,7 +1359,7 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
1257
1359
|
center,
|
|
1258
1360
|
});
|
|
1259
1361
|
// Islands no country reached go to the nearest capital's country.
|
|
1260
|
-
for (const id of
|
|
1362
|
+
for (const id of passableLandIds)
|
|
1261
1363
|
if (!owner.has(id) && !unownedLand.has(id)) {
|
|
1262
1364
|
const c = center(id);
|
|
1263
1365
|
let best = 0;
|
|
@@ -1269,9 +1371,40 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
1269
1371
|
}
|
|
1270
1372
|
// Strategic regions: land regions over the land graph, sea regions over the sea graph.
|
|
1271
1373
|
const graph = (id) => provinces.neighbors[id];
|
|
1374
|
+
// Impassable land is clustered apart from passable land, so no region bridges two landmasses
|
|
1375
|
+
// over it or spans the seam over the wall.
|
|
1272
1376
|
const landRegion = featurePartition === undefined
|
|
1273
|
-
? growClusters(
|
|
1274
|
-
: clusterRegions(featurePartition,
|
|
1377
|
+
? growClusters(passableLandIds, graph, spec.landProvincesPerRegion, random)
|
|
1378
|
+
: clusterRegions(featurePartition, passableLandIds, 'land');
|
|
1379
|
+
if (separateImpassable) {
|
|
1380
|
+
const regionTarget = featurePartition?.tuning.regions.target ?? spec.landProvincesPerRegion;
|
|
1381
|
+
let nextRegion = Math.max(-1, ...landRegion.values()) + 1;
|
|
1382
|
+
for (const component of impassableComponents) {
|
|
1383
|
+
// A piece no larger than a region joins the passable region it borders most; a larger
|
|
1384
|
+
// piece, or one that borders only water, forms regions of its own.
|
|
1385
|
+
const contacts = new Map();
|
|
1386
|
+
for (const id of component)
|
|
1387
|
+
for (const next of provinces.neighbors[id]) {
|
|
1388
|
+
const region = landRegion.get(next);
|
|
1389
|
+
if (region === undefined || impassableProvinces.has(next) || acrossSeam(id, next))
|
|
1390
|
+
continue;
|
|
1391
|
+
contacts.set(region, (contacts.get(region) ?? 0) + 1);
|
|
1392
|
+
}
|
|
1393
|
+
if (contacts.size > 0 && component.length <= regionTarget) {
|
|
1394
|
+
const [joined] = [...contacts].sort((left, right) => right[1] - left[1] || left[0] - right[0])[0];
|
|
1395
|
+
for (const id of component)
|
|
1396
|
+
landRegion.set(id, joined);
|
|
1397
|
+
continue;
|
|
1398
|
+
}
|
|
1399
|
+
const clusters = growClusters(component, (id) => [...provinces.neighbors[id]].filter((next) => !acrossSeam(id, next)), regionTarget, random);
|
|
1400
|
+
let largest = -1;
|
|
1401
|
+
for (const [id, cluster] of clusters) {
|
|
1402
|
+
landRegion.set(id, nextRegion + cluster);
|
|
1403
|
+
largest = Math.max(largest, cluster);
|
|
1404
|
+
}
|
|
1405
|
+
nextRegion += largest + 1;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1275
1408
|
const seaRegion = featurePartition === undefined
|
|
1276
1409
|
? growClusters(seaIds, graph, spec.seaProvincesPerRegion, random)
|
|
1277
1410
|
: clusterRegions(featurePartition, seaIds, 'sea');
|
|
@@ -1588,22 +1721,7 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
1588
1721
|
'tree = { 3 4 7 10 }',
|
|
1589
1722
|
'',
|
|
1590
1723
|
].join('\n')));
|
|
1591
|
-
add(`${map}/continent.txt`, text(`continents = {\n${[...new Set([...
|
|
1592
|
-
const rimRows = hasRimRange(edge)
|
|
1593
|
-
? rimAdjacencyRows({
|
|
1594
|
-
provincePixels: provinces.pixel,
|
|
1595
|
-
provinceKinds: provinces.kind,
|
|
1596
|
-
width,
|
|
1597
|
-
height,
|
|
1598
|
-
})
|
|
1599
|
-
: [];
|
|
1600
|
-
if (rimRows.length > 0)
|
|
1601
|
-
notes.push({
|
|
1602
|
-
code: 'MAP_EDGE_RIM_ADJACENCIES',
|
|
1603
|
-
severity: 'info',
|
|
1604
|
-
message: `The ${edge.mode} edge policy wrote ${rimRows.length} impassable adjacency row(s) for provinces that meet across the seam`,
|
|
1605
|
-
details: { rows: rimRows.length },
|
|
1606
|
-
});
|
|
1724
|
+
add(`${map}/continent.txt`, text(`continents = {\n${[...new Set([...generatedContinentKeys, ...(spec.inheritedContinents === 'drop' ? [] : (context.continentKeys ?? []))])].map((key) => `\t${key}`).join('\n')}\n}\n`));
|
|
1607
1725
|
const crossingRows = (gameplay?.crossings.rows ?? []).map(adjacencyRowText);
|
|
1608
1726
|
// Impassable land and rows must not cut a realm apart or box it in by accident (ZR-28).
|
|
1609
1727
|
if (impassableProvinces.size > 0 || (gameplay?.crossings.blocked.length ?? 0) > 0)
|
|
@@ -1611,13 +1729,7 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
1611
1729
|
kind: provinces.kind,
|
|
1612
1730
|
neighbors: provinces.neighbors,
|
|
1613
1731
|
impassable: impassableProvinces,
|
|
1614
|
-
blocked: [
|
|
1615
|
-
...(gameplay?.crossings.blocked ?? []),
|
|
1616
|
-
...rimRows.map((row) => {
|
|
1617
|
-
const [from, to] = row.split(';').map(Number);
|
|
1618
|
-
return [from - 1, to - 1];
|
|
1619
|
-
}),
|
|
1620
|
-
],
|
|
1732
|
+
blocked: [...(gameplay?.crossings.blocked ?? [])],
|
|
1621
1733
|
crossings: (gameplay?.crossings.rows ?? [])
|
|
1622
1734
|
.filter(({ type }) => type === 'sea')
|
|
1623
1735
|
.map(({ from, to }) => [from - 1, to - 1]),
|
|
@@ -1626,7 +1738,7 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
1626
1738
|
tags: spec.countries.map(({ tag }) => tag),
|
|
1627
1739
|
}))
|
|
1628
1740
|
notes.push(note);
|
|
1629
|
-
add(`${map}/adjacencies.csv`, text(`From;To;Type;Through;start_x;start_y;stop_x;stop_y;adjacency_rule_name;Comment\r\n${
|
|
1741
|
+
add(`${map}/adjacencies.csv`, text(`From;To;Type;Through;start_x;start_y;stop_x;stop_y;adjacency_rule_name;Comment\r\n${crossingRows.map((row) => `${row}\r\n`).join('')}-1;-1;;-1;-1;-1;-1;-1;-1\r\n`));
|
|
1630
1742
|
add(`${map}/adjacency_rules.txt`, text(gameplay === undefined
|
|
1631
1743
|
? '# No straits or canals in this world yet.\n'
|
|
1632
1744
|
: adjacencyRulesText(gameplay.crossings.rules)));
|
|
@@ -2250,5 +2362,10 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
2250
2362
|
rivers: riverCount,
|
|
2251
2363
|
},
|
|
2252
2364
|
...(spec.realms === undefined ? {} : { realms: realmSummary() }),
|
|
2365
|
+
...(spec.inheritedContinents === 'drop'
|
|
2366
|
+
? {
|
|
2367
|
+
droppedContinents: (context.continentKeys ?? []).filter((key) => !generatedContinentKeys.includes(key)),
|
|
2368
|
+
}
|
|
2369
|
+
: {}),
|
|
2253
2370
|
};
|
|
2254
2371
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { lstat, realpath } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
+
const PLUGIN_TOOL_NAME = /^(?!hoi4\.)[a-z][a-z0-9_]{1,31}\.[a-z][a-z0-9_]{1,63}$/u;
|
|
5
|
+
const MAX_PLUGIN_TOOLS = 16;
|
|
6
|
+
const SERVER_MODULE_ROOT = fileURLToPath(new URL('..', import.meta.url));
|
|
7
|
+
export class PluginError extends Error {
|
|
8
|
+
code;
|
|
9
|
+
constructor(code, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'PluginError';
|
|
12
|
+
this.code = code;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function sameFile(left, right) {
|
|
16
|
+
const normalize = (value) => process.platform === 'win32' ? path.normalize(value).toLowerCase() : path.normalize(value);
|
|
17
|
+
return normalize(left) === normalize(right);
|
|
18
|
+
}
|
|
19
|
+
function createHost(serverVersion) {
|
|
20
|
+
return {
|
|
21
|
+
serverVersion,
|
|
22
|
+
importServerModule: async (relativePath) => {
|
|
23
|
+
const target = path.resolve(SERVER_MODULE_ROOT, relativePath);
|
|
24
|
+
if (!target.startsWith(SERVER_MODULE_ROOT) ||
|
|
25
|
+
!/\.(?:js|ts)$/u.test(target) ||
|
|
26
|
+
relativePath.includes('..'))
|
|
27
|
+
throw new PluginError('PLUGIN_IMPORT_REFUSED', `Not a server module: ${relativePath}`);
|
|
28
|
+
return (await import(pathToFileURL(target).href));
|
|
29
|
+
},
|
|
30
|
+
dependency: async (name) => name === 'zod' ? await import('zod/v4') : await import('sharp'),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Load every configured plugin. A listed file that does not exist is skipped, because a private
|
|
35
|
+
* plugin lives on one machine and the shared configuration may list it on others; `onSkipped`
|
|
36
|
+
* reports it. A file that exists and is not a plain `.mjs` or `.js` file, or that does not export
|
|
37
|
+
* a factory, is an error.
|
|
38
|
+
*/
|
|
39
|
+
export async function loadPlugins(paths, serverVersion, onSkipped = () => undefined) {
|
|
40
|
+
const factories = [];
|
|
41
|
+
for (const file of paths) {
|
|
42
|
+
if (!path.isAbsolute(file) || !/\.(?:mjs|js)$/u.test(file))
|
|
43
|
+
throw new PluginError('PLUGIN_PATH_INVALID', 'A plugin path is absolute and names a .mjs or .js file');
|
|
44
|
+
const info = await lstat(file).catch(() => undefined);
|
|
45
|
+
if (info === undefined) {
|
|
46
|
+
onSkipped(file, 'file not found');
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (!info.isFile() || info.isSymbolicLink())
|
|
50
|
+
throw new PluginError('PLUGIN_PATH_INVALID', 'A plugin is a plain file, not a link');
|
|
51
|
+
if (!sameFile(await realpath(file), file))
|
|
52
|
+
throw new PluginError('PLUGIN_PATH_INVALID', 'A plugin path passes through a link or a short 8.3 name; list its full canonical path');
|
|
53
|
+
const loaded = (await import(pathToFileURL(file).href));
|
|
54
|
+
if (typeof loaded.default !== 'function')
|
|
55
|
+
throw new PluginError('PLUGIN_INVALID', 'A plugin exports a factory function as default');
|
|
56
|
+
factories.push(await loaded.default(createHost(serverVersion)));
|
|
57
|
+
}
|
|
58
|
+
if (factories.length === 0)
|
|
59
|
+
return undefined;
|
|
60
|
+
return (engine, context) => {
|
|
61
|
+
const tools = factories.flatMap((factory) => factory(engine, context));
|
|
62
|
+
const seen = new Set();
|
|
63
|
+
if (tools.length > MAX_PLUGIN_TOOLS)
|
|
64
|
+
throw new PluginError('PLUGIN_INVALID', `Plugins add at most ${MAX_PLUGIN_TOOLS} tools`);
|
|
65
|
+
for (const { definition } of tools) {
|
|
66
|
+
if (!PLUGIN_TOOL_NAME.test(definition.name))
|
|
67
|
+
throw new PluginError('PLUGIN_INVALID', `Plugin tool "${definition.name}" must be named <plugin>.<tool> and not start with hoi4.`);
|
|
68
|
+
if (seen.has(definition.name))
|
|
69
|
+
throw new PluginError('PLUGIN_INVALID', `Two plugin tools are named ${definition.name}`);
|
|
70
|
+
seen.add(definition.name);
|
|
71
|
+
}
|
|
72
|
+
return tools;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -12,8 +12,12 @@ export const ARGUMENT_EXAMPLES = {
|
|
|
12
12
|
'hoi4.source_lookup': '{"symbol":"my_scripted_effect"} or {"path":"events/my_events.txt","line":42}',
|
|
13
13
|
'hoi4.script_validate': '{"path":"events/my_events.txt"} or {"source":"add_political_power = 10","kind":"effect","scope":"country"}',
|
|
14
14
|
'hoi4.error_log': '{"scope":"mod","category":"effect"}',
|
|
15
|
+
'hoi4.script_guard': '{"paths":["events/my_events.txt"]} or {"sinceMinutes":30}',
|
|
16
|
+
'hoi4.mod_health': '{"limit":5} or {"checks":["error_log","engine_check"]}',
|
|
17
|
+
'hoi4.explain_error': `{"line":"Invalid trigger 'stability' in events/my_events.txt line : 12"}`,
|
|
15
18
|
'hoi4.mod_index': '{"mode":"overview"} or {"mode":"next_id","kind":"event","namespace":"my_mod"}',
|
|
16
19
|
'hoi4.localisation_inspect': '{"mode":"key","key":"my_event.1.t"} or {"mode":"audit"}',
|
|
20
|
+
'hoi4.compat_check': '{"mode":"mod","other":"my_other_mod"} or {"mode":"patch"}',
|
|
17
21
|
'hoi4.idea_inspect': '{"kind":"idea","id":"my_idea"} or {"kind":"character","audit":true}',
|
|
18
22
|
'hoi4.system_inspect': '{"kind":"mio","id":"my_organization"} or {"kind":"on_actions","audit":true}',
|
|
19
23
|
'hoi4.unit_inspect': '{"kind":"oob","id":"GER_1936"} or {"kind":"variant","audit":true}',
|
|
@@ -24,6 +28,7 @@ export const ARGUMENT_EXAMPLES = {
|
|
|
24
28
|
'hoi4.focus_inspect': '{"treeId":"my_focus_tree"}',
|
|
25
29
|
'hoi4.focus_render': '{"relativePath":"common/national_focus/my_tree.txt","treeId":"my_focus_tree"}',
|
|
26
30
|
'hoi4.focus_rewrite': '{"relativePath":"common/national_focus/my_tree.txt","treeId":"my_focus_tree","layoutMode":"compact"}',
|
|
31
|
+
'hoi4.localisation_write': '{"mode":"add","entries":[{"key":"my_focus","text":"My focus"}]} or {"mode":"fix","apply":true}',
|
|
27
32
|
'hoi4.gui_inspect': '{"windowName":"my_window"}',
|
|
28
33
|
'hoi4.gui_render': '{"windowName":"my_window","scenario":{"id":"normal"}}',
|
|
29
34
|
'hoi4.gui_rewrite': '{"mode":"patches","relativePath":"interface/my_window.gui","windowName":"my_window","scenario":{"id":"normal"},"expectedSourceHash":"<sha256 of the file>","patches":[{"description":"Move the button right","start":120,"end":130,"expectedText":"x = 10 y","text":"x = 40 y"}]}',
|
|
@@ -19,6 +19,7 @@ import { ModernTaskAdapter, TASKS_EXTENSION } from './modern-tasks.js';
|
|
|
19
19
|
import { SERVER_INSTRUCTIONS } from './instructions.js';
|
|
20
20
|
import { jobProgressReporter, modernProgressReporter, withProgressHeartbeat } from './progress.js';
|
|
21
21
|
import { taskToolCatalog } from './task-tool-catalog.js';
|
|
22
|
+
import { isListed, profileInstructions, resolveProfiles } from './tool-profiles.js';
|
|
22
23
|
const rootsResponseSchema = z
|
|
23
24
|
.object({
|
|
24
25
|
roots: z
|
|
@@ -38,15 +39,15 @@ function clientCapabilities(envelope) {
|
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
41
|
* Modern operation/task factory, shared by the connection and HTTP serving entries.
|
|
41
|
-
* The stdio entry
|
|
42
|
-
* HTTP remains mod-independent and never
|
|
42
|
+
* The stdio entry adds the tools of the plugins its configuration lists (M-14).
|
|
43
|
+
* HTTP remains mod-independent and never loads a plugin.
|
|
43
44
|
*/
|
|
44
45
|
export function createModernOperationServer(engine, context = {}, tasks = new OperationTaskService(engine), options = {}) {
|
|
45
46
|
const adapter = new ModernTaskAdapter(tasks);
|
|
46
47
|
const controls = new JobControlService(engine);
|
|
47
48
|
const references = new ReferenceToolService(engine);
|
|
48
49
|
const privateOperations = options.createPrivateTools?.(engine, context);
|
|
49
|
-
const mapEnd = taskToolCatalog.findIndex(({ name }) => name === 'hoi4.
|
|
50
|
+
const mapEnd = taskToolCatalog.findIndex(({ name }) => name === 'hoi4.localisation_write') + 1;
|
|
50
51
|
const definitions = [
|
|
51
52
|
...taskToolCatalog.slice(0, mapEnd),
|
|
52
53
|
...referenceTools,
|
|
@@ -54,7 +55,7 @@ export function createModernOperationServer(engine, context = {}, tasks = new Op
|
|
|
54
55
|
...jobControlTools,
|
|
55
56
|
...(privateOperations === undefined
|
|
56
57
|
? []
|
|
57
|
-
:
|
|
58
|
+
: privateOperations.map(({ definition }) => definition)),
|
|
58
59
|
];
|
|
59
60
|
const server = new ModernTaskRoutingServer({ name: PACKAGE_NAME, version: PACKAGE_VERSION }, {
|
|
60
61
|
capabilities: {
|
|
@@ -63,7 +64,8 @@ export function createModernOperationServer(engine, context = {}, tasks = new Op
|
|
|
63
64
|
prompts: {},
|
|
64
65
|
extensions: { [TASKS_EXTENSION]: {} },
|
|
65
66
|
},
|
|
66
|
-
instructions: SERVER_INSTRUCTIONS
|
|
67
|
+
instructions: SERVER_INSTRUCTIONS +
|
|
68
|
+
(profileInstructions(resolveProfiles(engine.resolver.config().profiles)) ?? ''),
|
|
67
69
|
});
|
|
68
70
|
// Warm job workers outlive single calls, not the client session that used them.
|
|
69
71
|
const previousOnClose = server.onclose;
|
|
@@ -73,8 +75,11 @@ export function createModernOperationServer(engine, context = {}, tasks = new Op
|
|
|
73
75
|
};
|
|
74
76
|
registerModernResources(server, engine, context);
|
|
75
77
|
registerModernPrompts(server);
|
|
78
|
+
const profiles = resolveProfiles(engine.resolver.config().profiles);
|
|
76
79
|
server.setRequestHandler('tools/list', () => ListToolsResultSchema.parse({
|
|
77
|
-
tools: definitions
|
|
80
|
+
tools: definitions
|
|
81
|
+
.filter(({ name }) => isListed(name, profiles))
|
|
82
|
+
.map(({ name, inputSchema, outputSchema, ...metadata }) => slimListedTool({
|
|
78
83
|
...metadata,
|
|
79
84
|
name,
|
|
80
85
|
inputSchema: {
|
|
@@ -148,22 +153,11 @@ export function createModernOperationServer(engine, context = {}, tasks = new Op
|
|
|
148
153
|
const operations = operationContext === context || options.createPrivateTools === undefined
|
|
149
154
|
? privateOperations
|
|
150
155
|
: options.createPrivateTools(engine, operationContext);
|
|
151
|
-
const
|
|
152
|
-
if (
|
|
153
|
-
const result = await
|
|
156
|
+
const tool = operations.find((candidate) => candidate.definition.name === definition.name);
|
|
157
|
+
if (tool !== undefined) {
|
|
158
|
+
const result = await tool.call(input.data, modernProgressReporter(extra));
|
|
154
159
|
if (result.isError !== true)
|
|
155
|
-
|
|
156
|
-
return CallToolResultSchema.parse({
|
|
157
|
-
...result,
|
|
158
|
-
resultType: 'complete',
|
|
159
|
-
ttlMs: 0,
|
|
160
|
-
cacheScope: 'private',
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
if (definition.name === operations.country.definition.name) {
|
|
164
|
-
const result = await operations.country.call(operations.country.definition.inputSchema.parse(arguments_), progress);
|
|
165
|
-
if (result.isError !== true)
|
|
166
|
-
operations.country.definition.outputSchema.parse(result.structuredContent);
|
|
160
|
+
definition.outputSchema?.parse(result.structuredContent);
|
|
167
161
|
return CallToolResultSchema.parse({
|
|
168
162
|
...result,
|
|
169
163
|
resultType: 'complete',
|
|
@@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
3
3
|
import { PACKAGE_NAME, PACKAGE_VERSION } from '../../version.js';
|
|
4
4
|
import { registerFocusTools } from '../tools/focus.js';
|
|
5
5
|
import { registerGuiTools } from '../tools/gui.js';
|
|
6
|
+
import { registerLocalisationWriteTools } from '../tools/localisation-write.js';
|
|
6
7
|
import { registerMapTools } from '../tools/map.js';
|
|
7
8
|
import { registerReferenceTools } from '../tools/reference.js';
|
|
8
9
|
import { registerEventTools } from '../tools/event.js';
|
|
@@ -15,6 +16,7 @@ import { installRequestLifecycle } from './request-lifecycle.js';
|
|
|
15
16
|
import { PersistentJobTaskStore } from './job-task-store.js';
|
|
16
17
|
import { SERVER_INSTRUCTIONS } from './instructions.js';
|
|
17
18
|
import { releaseIdleWorkers } from '../../core/operation-tasks.js';
|
|
19
|
+
import { profileInstructions, resolveProfiles } from './tool-profiles.js';
|
|
18
20
|
export { SERVER_INSTRUCTIONS } from './instructions.js';
|
|
19
21
|
export function createMcpServer(engine, context = {}) {
|
|
20
22
|
let serverContext = context;
|
|
@@ -28,7 +30,8 @@ export function createMcpServer(engine, context = {}) {
|
|
|
28
30
|
logging: {},
|
|
29
31
|
tasks: { list: {}, cancel: {}, requests: { tools: { call: {} } } },
|
|
30
32
|
},
|
|
31
|
-
instructions: SERVER_INSTRUCTIONS
|
|
33
|
+
instructions: SERVER_INSTRUCTIONS +
|
|
34
|
+
(profileInstructions(resolveProfiles(engine.resolver.config().profiles)) ?? ''),
|
|
32
35
|
taskStore,
|
|
33
36
|
});
|
|
34
37
|
installRequestLifecycle(server, engine);
|
|
@@ -61,6 +64,7 @@ export function createMcpServer(engine, context = {}) {
|
|
|
61
64
|
registerFocusTools(server, engine, serverContext);
|
|
62
65
|
registerGuiTools(server, engine, serverContext);
|
|
63
66
|
registerMapTools(server, engine, serverContext);
|
|
67
|
+
registerLocalisationWriteTools(server, engine, serverContext);
|
|
64
68
|
registerReferenceTools(server, engine, serverContext);
|
|
65
69
|
registerEventTools(server);
|
|
66
70
|
registerAnalysisTools(server);
|
|
@@ -8,6 +8,7 @@ import { taskToolCatalog } from './task-tool-catalog.js';
|
|
|
8
8
|
import { jobProgressReporter, progressReporter, withProgressHeartbeat } from './progress.js';
|
|
9
9
|
import { withTaskRequestSignal } from './task-request-context.js';
|
|
10
10
|
import { slimToolList } from './tool-listing.js';
|
|
11
|
+
import { isListed, resolveProfiles } from './tool-profiles.js';
|
|
11
12
|
// Durable task compatibility and cancellation are control traffic. They must
|
|
12
13
|
// remain responsive while every domain-execution slot is occupied.
|
|
13
14
|
const controlTools = new Set(['hoi4.job_inspect', 'hoi4.job_cancel']);
|
|
@@ -23,8 +24,15 @@ export function installRequestLifecycle(server, engine) {
|
|
|
23
24
|
const owner = {};
|
|
24
25
|
server.server.setRequestHandler = (schema, handler) => {
|
|
25
26
|
register(schema, (request, extra) => {
|
|
26
|
-
if (request.method === 'tools/list')
|
|
27
|
-
|
|
27
|
+
if (request.method === 'tools/list') {
|
|
28
|
+
const profiles = resolveProfiles(engine.resolver.config().profiles);
|
|
29
|
+
return Promise.resolve(handler(request, extra)).then((result) => {
|
|
30
|
+
const slim = slimToolList(result);
|
|
31
|
+
return slim.tools === undefined
|
|
32
|
+
? slim
|
|
33
|
+
: { ...slim, tools: slim.tools.filter(({ name }) => isListed(name, profiles)) };
|
|
34
|
+
});
|
|
35
|
+
}
|
|
28
36
|
if (request.method !== 'tools/call')
|
|
29
37
|
return handler(request, extra);
|
|
30
38
|
const params = request.params;
|
|
@@ -2,6 +2,7 @@ import { analysisTaskTools } from '../tools/analysis.js';
|
|
|
2
2
|
import { eventTaskTools } from '../tools/event.js';
|
|
3
3
|
import { focusTaskTools } from '../tools/focus.js';
|
|
4
4
|
import { guiTaskTools } from '../tools/gui.js';
|
|
5
|
+
import { localisationTaskTools } from '../tools/localisation-write.js';
|
|
5
6
|
import { mapTaskTools } from '../tools/map.js';
|
|
6
7
|
import { probabilityTaskTools } from '../tools/probability.js';
|
|
7
8
|
import { technologyTaskTools } from '../tools/technology.js';
|
|
@@ -9,6 +10,7 @@ export const taskToolCatalog = [
|
|
|
9
10
|
...focusTaskTools,
|
|
10
11
|
...guiTaskTools,
|
|
11
12
|
...mapTaskTools,
|
|
13
|
+
...localisationTaskTools,
|
|
12
14
|
...eventTaskTools,
|
|
13
15
|
...analysisTaskTools,
|
|
14
16
|
...technologyTaskTools,
|