hoi4-agent-tools 4.17.0 → 4.18.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/hoi4_agent_tools/core/operation-result.js +37 -6
  3. package/dist/hoi4_agent_tools/event/operations.js +111 -20
  4. package/dist/hoi4_agent_tools/map/border-quality-input.js +57 -8
  5. package/dist/hoi4_agent_tools/map/border-quality.js +15 -6
  6. package/dist/hoi4_agent_tools/map/limits.js +13 -0
  7. package/dist/hoi4_agent_tools/map/natural-lands.js +902 -0
  8. package/dist/hoi4_agent_tools/map/operations.js +246 -18
  9. package/dist/hoi4_agent_tools/map/territory-operations.js +66 -0
  10. package/dist/hoi4_agent_tools/map/territory-quality.js +33 -5
  11. package/dist/hoi4_agent_tools/map/tool-operations.js +52 -2
  12. package/dist/hoi4_agent_tools/mcp/tools/map.js +29 -0
  13. package/dist/hoi4_agent_tools/mcp/tools/reference.js +1 -1
  14. package/dist/hoi4_agent_tools/reference/mod-index.js +14 -5
  15. package/dist/hoi4_agent_tools/schemas/map-requests.js +29 -1
  16. package/dist/hoi4_agent_tools/schemas/map.js +70 -2
  17. package/dist/hoi4_agent_tools/version.js +1 -1
  18. package/docs/map.md +58 -16
  19. package/docs/tools.md +1 -1
  20. package/engine/bin/manifest.json +1 -1
  21. package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
  22. package/npm-shrinkwrap.json +2 -2
  23. package/package.json +1 -1
  24. package/schemas/configuration.schema.json +1 -1
  25. package/schemas/continuous-focus-palette.schema.json +1 -1
  26. package/schemas/custom-weighted-pool.schema.json +1 -1
  27. package/schemas/decision-inspect-input.schema.json +1 -1
  28. package/schemas/error-log-input.schema.json +1 -1
  29. package/schemas/event-feature-manifest.schema.json +1 -1
  30. package/schemas/focus-plan.schema.json +1 -1
  31. package/schemas/focus-planning-sidecar.schema.json +1 -1
  32. package/schemas/geography-model.schema.json +1 -1
  33. package/schemas/gui-animation-source.schema.json +1 -1
  34. package/schemas/gui-helper.schema.json +1 -1
  35. package/schemas/gui-scenario.schema.json +1 -1
  36. package/schemas/helper-expansion-request.schema.json +1 -1
  37. package/schemas/helper-expansion-summary.schema.json +1 -1
  38. package/schemas/impact-inspect-input.schema.json +1 -1
  39. package/schemas/map-operation.schema.json +1004 -821
  40. package/schemas/mechanic-test-input.schema.json +1 -1
  41. package/schemas/mod-index-input.schema.json +1 -1
  42. package/schemas/operation-result.schema.json +1 -1
  43. package/schemas/package-check-input.schema.json +1 -1
  44. package/schemas/package-manifest.schema.json +1 -1
  45. package/schemas/probability-analysis-result.schema.json +1 -1
  46. package/schemas/probability-compare-input.schema.json +1 -1
  47. package/schemas/probability-evaluate-input.schema.json +1 -1
  48. package/schemas/probability-inspect-input.schema.json +1 -1
  49. package/schemas/probability-render-input.schema.json +1 -1
  50. package/schemas/probability-scenario-set.schema.json +1 -1
  51. package/schemas/probability-sequence-input.schema.json +1 -1
  52. package/schemas/probability-simulate-input.schema.json +1 -1
  53. package/schemas/probability-sweep-input.schema.json +1 -1
  54. package/schemas/reference-context-input.schema.json +1 -1
  55. package/schemas/reference-read-input.schema.json +1 -1
  56. package/schemas/reference-search-input.schema.json +1 -1
  57. package/schemas/reference-sheets.schema.json +1 -1
  58. package/schemas/scenario-suite.schema.json +1 -1
  59. package/schemas/scenario-test-input.schema.json +1 -1
  60. package/schemas/script-validate-input.schema.json +1 -1
  61. package/schemas/shared-scenario.schema.json +1 -1
  62. package/schemas/source-lookup-input.schema.json +1 -1
  63. package/server.json +2 -2
@@ -3,8 +3,11 @@ import { runEngineCommand } from '../core/engine-client.js';
3
3
  import { ServiceError } from '../core/result.js';
4
4
  import { readModDescriptor } from '../core/workspace.js';
5
5
  import { modIndexEngineResponseSchema, } from '../schemas/mod-tools.js';
6
- const MAX_NAMESPACES = 200;
7
- const MAX_FOLDERS = 60;
6
+ // An overview answers inline in about 8 KB (issue 66): the busiest namespaces and folders, with a
7
+ // prefix filter for the rest. A namespace line is about 80 bytes and a folder line about 60.
8
+ const MAX_NAMESPACES = 50;
9
+ const MAX_FILTERED_NAMESPACES = 100;
10
+ const MAX_FOLDERS = 25;
8
11
  /** A cold index of the game, its DLC and a large mod. */
9
12
  const MOD_INDEX_TIMEOUT_MS = 180_000;
10
13
  const MOD_INDEX_REQUEST_SCHEMA = 'hoi4-mod-index-request/1';
@@ -78,7 +81,13 @@ export async function modIndex(engine, workspaceId, input, principal, signal) {
78
81
  };
79
82
  }
80
83
  const answer = await runModIndex(engine, workspaceId, { mode: 'overview', rootKinds: input.layer === 'mod' ? ['mod'] : SOURCE_ROOT_KINDS }, principal, signal);
81
- const allNamespaces = [...(answer.namespaces ?? [])].sort((left, right) => left.namespace.localeCompare(right.namespace, 'en'));
84
+ // `namespace` or `prefix` narrows the list to the namespaces that start with it.
85
+ const filter = input.prefix ?? input.namespace;
86
+ const matching = (answer.namespaces ?? []).filter(({ namespace }) => filter === undefined || namespace.startsWith(filter));
87
+ const shownNamespaces = [...matching]
88
+ .sort((left, right) => right.events - left.events || left.namespace.localeCompare(right.namespace, 'en'))
89
+ .slice(0, filter === undefined ? MAX_NAMESPACES : MAX_FILTERED_NAMESPACES)
90
+ .sort((left, right) => left.namespace.localeCompare(right.namespace, 'en'));
82
91
  const modRoot = engine.resolver
83
92
  .get(workspaceId, principal)
84
93
  .roots.find(({ kind }) => kind === 'mod')?.path;
@@ -93,7 +102,7 @@ export async function modIndex(engine, workspaceId, input, principal, signal) {
93
102
  folders: [...(answer.folders ?? [])]
94
103
  .sort((left, right) => right.files - left.files || left.folder.localeCompare(right.folder))
95
104
  .slice(0, MAX_FOLDERS),
96
- namespaces: allNamespaces.slice(0, MAX_NAMESPACES),
97
- omittedNamespaces: Math.max(0, allNamespaces.length - MAX_NAMESPACES),
105
+ namespaces: shownNamespaces,
106
+ omittedNamespaces: matching.length - shownNamespaces.length,
98
107
  };
99
108
  }
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod/v4';
2
2
  import { MAP_PROVINCE_GEOMETRY_SELECTOR_LIMIT } from '../map/limits.js';
3
3
  import { backgroundRequestKeySchema, workspaceIdSchema } from './common.js';
4
- import { mapAllocationRequestSchema, mapOperationSchema } from './map.js';
4
+ import { borderQualityScopeSchema, mapAllocationRequestSchema, mapOperationSchema, naturalLandOptionsSchema, } from './map.js';
5
5
  function compact(schema, description) {
6
6
  return z.unknown().describe(description).pipe(schema);
7
7
  }
@@ -102,6 +102,14 @@ export const mapInspectRequestSchema = z
102
102
  .boolean()
103
103
  .default(false)
104
104
  .describe('Also measure how well province, state, region and country borders follow rivers, slopes, lake shores and terrain changes: enrichment over chance, the natural share of border length, straightness, and the worst artificial runs. Reads the height, river and terrain bitmaps; full inspection only.'),
105
+ lands: z
106
+ .boolean()
107
+ .default(false)
108
+ .describe('Also cut land into natural lands along rivers, crests, terrain edges and basins.'),
109
+ landOptions: naturalLandOptionsSchema
110
+ .optional()
111
+ .describe('Natural lands thresholds (docs/map.md); needs lands.'),
112
+ qualityScope: borderQualityScopeSchema.optional().describe('With quality: measure one region.'),
105
113
  layer: mapLayerSchema
106
114
  .optional()
107
115
  .describe('Render this base layer; combine with overlays, tile or area.'),
@@ -125,6 +133,12 @@ export const mapInspectRequestSchema = z
125
133
  message: 'Choose tile or area, not both',
126
134
  });
127
135
  const viewRequested = MAP_VIEW_FIELDS.some((field) => value[field] !== undefined);
136
+ if (value.qualityScope !== undefined && !value.quality)
137
+ context.addIssue({
138
+ code: 'custom',
139
+ path: ['qualityScope'],
140
+ message: 'qualityScope limits the quality measurement; set quality: true',
141
+ });
128
142
  if (value.quality && (viewRequested || value.lookupOnly))
129
143
  context.addIssue({
130
144
  code: 'custom',
@@ -133,6 +147,20 @@ export const mapInspectRequestSchema = z
133
147
  ? 'quality belongs to full inspection; request the border-quality overlay for a rendered view'
134
148
  : 'quality needs full inspection; remove lookupOnly',
135
149
  });
150
+ if (value.lands && (viewRequested || value.lookupOnly))
151
+ context.addIssue({
152
+ code: 'custom',
153
+ path: ['lands'],
154
+ message: viewRequested
155
+ ? 'lands belongs to full inspection; request a rendered view in a separate call'
156
+ : 'lands needs full inspection; remove lookupOnly',
157
+ });
158
+ if (value.landOptions !== undefined && !value.lands)
159
+ context.addIssue({
160
+ code: 'custom',
161
+ path: ['landOptions'],
162
+ message: 'landOptions needs lands: true',
163
+ });
136
164
  if (!viewRequested)
137
165
  return;
138
166
  for (const field of MAP_LOOKUP_FIELDS) {
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod/v4';
2
2
  import { renderDimensionViolation, RENDER_MAX_DIMENSION } from '../core/render-budget.js';
3
- import { MAP_MASK_CELL_LIMIT, MAP_SELECTED_PIXEL_LIMIT } from '../map/limits.js';
3
+ import { MAP_MASK_CELL_LIMIT, MAP_SELECTED_PIXEL_LIMIT, NATURAL_LAND_ID_PATTERN, NATURAL_TERRAIN_CLASSES, } from '../map/limits.js';
4
4
  import { workspaceRelativePathSchema } from './common.js';
5
5
  import { geographyModelSchema, geographyPathSchema } from './geography.js';
6
6
  import { referenceSheetsDocumentSchema, referenceSheetsPathSchema } from './reference-sheets.js';
@@ -744,6 +744,39 @@ const stateChangesSchema = z
744
744
  provinceBuildings: z.record(z.string().regex(/^\d+$/u), nonnegativeMap).optional(),
745
745
  })
746
746
  .strict();
747
+ export const naturalLandOptionsSchema = z
748
+ .object({
749
+ minProvinces: z.number().int().min(1).max(10_000).optional(),
750
+ minBasinProvinces: z.number().int().min(1).max(10_000).optional(),
751
+ maxBasinProvinces: z.number().int().min(2).max(100_000).optional(),
752
+ riverMajorIndex: z.number().int().min(0).max(11).optional(),
753
+ riverShare: z.number().gt(0).max(1).optional(),
754
+ crestExcess: z.number().gt(0).max(255).optional(),
755
+ splitRangesAtCrests: z.boolean().optional(),
756
+ terrainClasses: z
757
+ .record(z.string().regex(/^[A-Za-z0-9_]{1,64}$/u), z.enum(NATURAL_TERRAIN_CLASSES))
758
+ .optional(),
759
+ })
760
+ .strict()
761
+ .superRefine((value, context) => {
762
+ if (Object.keys(value.terrainClasses ?? {}).length > 64)
763
+ context.addIssue({
764
+ code: 'custom',
765
+ path: ['terrainClasses'],
766
+ message: 'terrainClasses names at most 64 categories',
767
+ });
768
+ const minimum = value.minBasinProvinces ?? value.minProvinces ?? 6;
769
+ if (value.maxBasinProvinces !== undefined && value.maxBasinProvinces < 2 * minimum)
770
+ context.addIssue({
771
+ code: 'custom',
772
+ path: ['maxBasinProvinces'],
773
+ message: 'maxBasinProvinces must be at least twice minBasinProvinces',
774
+ });
775
+ });
776
+ const naturalLandIdSchema = z
777
+ .string()
778
+ .regex(NATURAL_LAND_ID_PATTERN)
779
+ .describe('A natural land id from hoi4.map_inspect with lands: true, such as L120.');
747
780
  const tagSchema = z
748
781
  .string()
749
782
  .regex(/^[A-Z0-9]{3}$/u, 'A country tag is three capital letters or digits');
@@ -751,12 +784,21 @@ const territoryRefSchema = z.union([
751
784
  z.object({ state: stateId }).strict(),
752
785
  z.object({ province: provinceId }).strict(),
753
786
  z.object({ x: z.number().int().min(0), y: z.number().int().min(0) }).strict(),
787
+ z
788
+ .object({ land: naturalLandIdSchema })
789
+ .strict()
790
+ .describe('The province of a natural land nearest its centre.'),
754
791
  ]);
755
792
  const territorySelectionSchema = z
756
793
  .object({
757
794
  stateIds: z.array(stateId).max(100_000).optional(),
758
795
  provinceIds: z.array(provinceId).max(100_000).optional(),
759
796
  regionIds: z.array(z.number().int().positive()).max(10_000).optional(),
797
+ landIds: z
798
+ .array(naturalLandIdSchema)
799
+ .max(10_000)
800
+ .optional()
801
+ .describe('Natural lands, cut with the operation landOptions.'),
760
802
  })
761
803
  .strict();
762
804
  const borderQualityModeSchema = z
@@ -770,6 +812,23 @@ const borderTargetsSchema = z
770
812
  })
771
813
  .strict()
772
814
  .describe('Override the targets (enrichment 1.6; straightness 0.12 for country borders and 0.25 for state borders).');
815
+ /** Where a border quality measurement looks (owners and stateIds add provinces; box cuts). */
816
+ export const borderQualityScopeSchema = z
817
+ .object({
818
+ owners: z.array(tagSchema).max(512).optional(),
819
+ stateIds: z.array(stateId).max(10_000).optional(),
820
+ box: z
821
+ .object({
822
+ x: z.number().int().min(0).max(16_383),
823
+ y: z.number().int().min(0).max(16_383),
824
+ width: z.number().int().min(1).max(16_384),
825
+ height: z.number().int().min(1).max(16_384),
826
+ })
827
+ .strict()
828
+ .optional(),
829
+ })
830
+ .strict()
831
+ .describe('Owners and stateIds add provinces, box cuts; a border counts when either side is inside.');
773
832
  const territoryCountrySchema = z
774
833
  .object({
775
834
  tag: tagSchema,
@@ -783,7 +842,7 @@ const territoryCountrySchema = z
783
842
  .array(territoryRefSchema)
784
843
  .min(1)
785
844
  .max(64)
786
- .describe('{ state }, { province } or a pixel { x, y }. The first is the capital.'),
845
+ .describe('{ state }, { province }, a pixel { x, y } or a natural { land }. The first is the capital.'),
787
846
  forced: territorySelectionSchema.optional(),
788
847
  blocked: territorySelectionSchema.optional(),
789
848
  regions: z
@@ -862,6 +921,12 @@ const territoryOperation = z
862
921
  remapReferences: z.enum(['refuse', 'override']).optional(),
863
922
  borderQuality: borderQualityModeSchema.default('report'),
864
923
  borderTargets: borderTargetsSchema.optional(),
924
+ landOptions: naturalLandOptionsSchema
925
+ .optional()
926
+ .describe('Thresholds of the natural lands that landIds and { land } seeds name; use the same options as the hoi4.map_inspect call that listed them.'),
927
+ borderQualityScope: borderQualityScopeSchema
928
+ .optional()
929
+ .describe('Measure and judge the border quality only here: the owners, stateIds and box of the region being redrawn.'),
865
930
  groups: z
866
931
  .record(z.string().regex(/^\d{1,6}$/u), z.string().min(1).max(64))
867
932
  .refine((value) => Object.keys(value).length <= 65_000, 'At most 65,000 provinces')
@@ -900,6 +965,9 @@ const repartitionOperation = z
900
965
  remapReferences: z.enum(['refuse', 'override']).optional(),
901
966
  borderQuality: borderQualityModeSchema.default('report'),
902
967
  borderTargets: borderTargetsSchema.optional(),
968
+ borderQualityScope: borderQualityScopeSchema
969
+ .optional()
970
+ .describe('Measure and judge the border quality only here: the owners, stateIds and box of the region being redrawn.'),
903
971
  })
904
972
  .strict();
905
973
  export const mapOperationSchema = z.discriminatedUnion('kind', [
@@ -1,6 +1,6 @@
1
1
  import { LATEST_PROTOCOL_VERSION } from '@modelcontextprotocol/sdk/types.js';
2
2
  export const PACKAGE_NAME = 'hoi4-agent-tools';
3
- export const PACKAGE_VERSION = '4.17.0';
3
+ export const PACKAGE_VERSION = '4.18.0';
4
4
  export const MCP_PROTOCOL_VERSION = LATEST_PROTOCOL_VERSION;
5
5
  export const CONFIG_VERSION = 1;
6
6
  export const TRANSACTION_VERSION = 2;
package/docs/map.md CHANGED
@@ -178,18 +178,19 @@ Set `lookupOnly: true` for coordinate, query, and selected-ID lookups without fu
178
178
 
179
179
  `hoi4.map_inspect` accepts these fields:
180
180
 
181
- | Field | Default and limits | Meaning |
182
- | -------------------- | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
183
- | `provinceIds` | `[]`, at most 32 | Province records to return, with exact geometry row runs. |
184
- | `stateIds` | `[]`, at most 1,000 | State records to return. |
185
- | `regionIds` | `[]`, at most 1,000 | Strategic-region records to return. |
186
- | `query` | optional, at most 256 characters | Name, localisation key, or ID search. |
187
- | `queryLimit` | 100, range 1 to 1,000 | Maximum `query` matches. |
188
- | `coordinates` | `[]`, at most 100 | `{ "kind": "pixel", "x", "y" }` with top-left bitmap pixels, or `{ "kind": "map", "x", "z" }` with HOI4 map coordinates. |
189
- | `lookupOnly` | `false` | Return only the requested lookups, as described above. |
190
- | `includeOverview` | `true` | Render the full-map PNG and navigator; set `false` to skip the overview render. |
191
- | `allocationRequests` | `[]`, at most 100 | Preview the next free identifiers: `{ "kind": "state", "requestedId"? }` or `{ "kind": "province", "requestedId"?, "requestedColor"? }`, where `requestedColor` is `{ "r", "g", "b" }`. Not accepted with `lookupOnly`. |
192
- | `quality` | `false` | Also measure border naturalness (see [Border naturalness](#border-naturalness)). Full inspection only; not accepted with `lookupOnly` or a rendered view. |
181
+ | Field | Default and limits | Meaning |
182
+ | -------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
183
+ | `provinceIds` | `[]`, at most 32 | Province records to return, with exact geometry row runs. |
184
+ | `stateIds` | `[]`, at most 1,000 | State records to return. |
185
+ | `regionIds` | `[]`, at most 1,000 | Strategic-region records to return. |
186
+ | `query` | optional, at most 256 characters | Name, localisation key, or ID search. |
187
+ | `queryLimit` | 100, range 1 to 1,000 | Maximum `query` matches. |
188
+ | `coordinates` | `[]`, at most 100 | `{ "kind": "pixel", "x", "y" }` with top-left bitmap pixels, or `{ "kind": "map", "x", "z" }` with HOI4 map coordinates. |
189
+ | `lookupOnly` | `false` | Return only the requested lookups, as described above. |
190
+ | `includeOverview` | `true` | Render the full-map PNG and navigator; set `false` to skip the overview render. |
191
+ | `allocationRequests` | `[]`, at most 100 | Preview the next free identifiers: `{ "kind": "state", "requestedId"? }` or `{ "kind": "province", "requestedId"?, "requestedColor"? }`, where `requestedColor` is `{ "r", "g", "b" }`. Not accepted with `lookupOnly`. |
192
+ | `quality` | `false` | Also measure border naturalness (see [Border naturalness](#border-naturalness)). Full inspection only; not accepted with `lookupOnly` or a rendered view. |
193
+ | `qualityScope` | none | With `quality`: measure only the borders of the states `owners` own or of `stateIds` (either adds provinces), cut to a pixel `box` `{ x, y, width, height }`. A border counts when either side is inside, so a country is measured against its neighbours; `data.quality.scopePixels` gives the size. A scope that selects nothing is reported as `MAP_BORDER_QUALITY_UNAVAILABLE` (`MAP_BORDER_QUALITY_SCOPE_EMPTY`). |
193
194
 
194
195
  Give `hoi4.map_inspect` a `layer`, `overlays`, `scale`, `tile` or `area` to render that view instead of validating; the result is the same complete catalog and navigator drawn with the chosen base layer and overlays, and lookups (`query`, `coordinates`, IDs) belong in a separate call. Base layers include province, state, strategic region, terrain, continent, owner, controller, cores, claims, and coast. Overlays include coastlines, ports, victory points, resources, state and province buildings, supply nodes, railways, adjacencies, building, unit, and weather positions, and `border-quality` (see [Border naturalness](#border-naturalness)).
195
196
 
@@ -235,6 +236,45 @@ A 13.1 million pixel map takes about 1.5 seconds and 100 MB of additional memory
235
236
 
236
237
  The `border-quality` overlay is added to any base layer (state is the natural choice): state borders are green where they follow a feature and orange where they do not, and the worst artificial run of each layer is drawn two pixels wide (province white, state red, region yellow, country magenta). It works with `tile` and `area`, and scans the river and terrain bitmaps for that render only.
237
238
 
239
+ ## Natural lands
240
+
241
+ `hoi4.map_inspect` with `lands: true` cuts the land provinces into natural lands: the pieces the ground suggests, such as river valleys, ranges, forests and coastal basins. It is a full inspection, offline and deterministic, and reads `provinces.bmp`, the definitions (the terrain column of `definition.csv` classes each province) and, when present and the size of the province map, `heightmap.bmp` and `rivers.bmp`. A bitmap that is absent or of another size is skipped and listed in `data.lands.skippedInputs`.
242
+
243
+ A line runs between two neighbouring land provinces when their border:
244
+
245
+ - follows a **major river**: at least `riverShare` (0.4) of its pixel edges touch a `rivers.bmp` pixel with a width index from `riverMajorIndex` (6) to 11 on either side;
246
+ - is a **crest**: the mean heightmap value along its pixels, minus the mean of the higher province, is at least `crestExcess` (3.5);
247
+ - separates two **terrain classes**: forest (`forest`, `jungle`), upland (`hills`, `mountain`), marsh, desert, and open ground (every other category, so plains, urban and farmland are one class). `terrainClasses` classes a mod's own categories, for example `{ "elder_wood": "forest" }`;
248
+ - is **impassable**: the two provinces are joined by an `impassable` row of `adjacencies.csv`, or exactly one of them belongs to a state with `impassable = yes` (a border inside impassable land is not a line). Code that calls the service with a barrier plane (`walls`) also gets an impassable line where the border lies on value 255, the synthesis wall, on the river share of its edges; a scanned map has no such plane, and the walls `create_world` writes are impassable states.
249
+
250
+ Impassable lines are hard. The two sides of one are never in the same land: when a piece reaches round the end of an impassable row, it is split between the two sides, each province going to the side it is fewer steps from. No merge, of basins or of small lands, crosses an impassable border, so a land that has only impassable neighbours stays below the minimum.
251
+
252
+ Provinces of one class that no line separates form a piece. Every piece that is not upland is cut into drainage basins: each province drains to its lowest neighbour in the piece (by mean height), and provinces on a coast or a lake shore are sinks, as is a province with no lower neighbour. Basins smaller than `minBasinProvinces` (default `minProvinces`) merge over their lowest pass, the lowest mean border height they share with another basin of the piece. With `maxBasinProvinces`, a larger basin is split at branch points of its drainage tree: the largest tributary that fits is cut off, then the rest, as long as both parts keep `minBasinProvinces`. Upland pieces are ranges and are not drained; a crest between two upland provinces does not cut a range unless `splitRangesAtCrests` is true. Last, lands smaller than `minProvinces` (6) merge into the neighbour across their weakest line, smallest first. The strength of a line is the length-weighted mean of its borders (impassable 2, river and crest 1, terrain 0.5, divide 0.2); ties go to the longer line, then to the land with the smaller id.
253
+
254
+ | Field of a land | Meaning |
255
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
256
+ | `id` | `L` and the smallest province id of the land, stable for the same map and options. |
257
+ | `kind` | The majority class: `range` (upland), `forest`, `marsh`, `desert`, or open ground as `basin` (with a heightmap) or `plains` (without one). |
258
+ | `provinces` | Province ids, ascending. |
259
+ | `terrain` | Share of provinces per terrain category. |
260
+ | `coast`, `lakeShore` | Whether the land touches the sea, and a lake. |
261
+ | `meanHeight` | Pixel mean of the heightmap, null without one. |
262
+ | `lines` | Per neighbouring land: the shared `length` in pixel edges and how much of it is `river`, `crest`, `terrain`, `impassable` or `divide` (none of these). A border can count as river and terrain at once. |
263
+
264
+ ```json
265
+ {
266
+ "workspaceId": "my-mod",
267
+ "lands": true,
268
+ "landOptions": { "minProvinces": 6, "minBasinProvinces": 10, "maxBasinProvinces": 40 }
269
+ }
270
+ ```
271
+
272
+ `data.lands` holds the count, the count per kind, the inputs used, the number of lands still below `minProvinces` (islands with no land neighbour) and the first 50 lands (`id`, `kind`, province count, `coast`). The artifact `map-natural-lands.<revision>.json` holds every land with its provinces, terrain shares and lines, and the options used. `MAP_NATURAL_LANDS_UNAVAILABLE` (warning) means the map has no province raster. The schema refuses `landOptions` without `lands`, `lands` with `lookupOnly` or a rendered view, and options out of range (`maxBasinProvinces` must be at least twice `minBasinProvinces`).
273
+
274
+ `assign_territory` takes the same lands: `landIds` in `forced`, `blocked`, `cores`, `claims` and `unowned`, and `{ "land": "L120" }` as a seed (the province of the land nearest its centre). The operation's `landOptions` cut the lands, so pass the options of the inspection that listed the ids; an id those options do not produce is refused with `MAP_NATURAL_LAND_UNKNOWN`.
275
+
276
+ Not covered yet: the ranges of a geography model are not read (ranges come from hills and mountain provinces only), an upland province is not moved to the side it drains to, and closed basins (rings) and their spill heights are not reported.
277
+
238
278
  ## Catalog consistency
239
279
 
240
280
  Validation reads the active `common/terrain/*.txt` categories and `map/continent.txt` (or the continent file `default.map` names) along with the map files.
@@ -323,6 +363,8 @@ Pass `provinceId`, `definition`, or the full distribution object when an exact o
323
363
 
324
364
  ## Change IDs
325
365
 
366
+ The game needs every state id from 1 to the highest; a missing one crashes it at setup ("Missing State ID"). So a write never leaves a hole of its own: when `merge_states`, `assign_territory` or another operation removes a state below the highest id, the highest states move into the holes in the same write, with their script references, building positions and `STATE_<id>` localisation, and the result lists the moves in `MAP_STATE_IDS_COMPACTED`. A state id the request names (`stateId`, or the `toId` of `renumber_map_entity`) is never moved, so a named id that would leave holes below it is refused with `MAP_STATE_ID_GAP`: name the next free id instead. Holes the mod already had are reported as a `MAP_STATE_ID_GAP` warning with the ids, and every write still runs, so you can close each with `renumber_map_entity`, the highest state into the hole. Building positions in `map/buildings.txt` that named a removed state move to the state that holds their province (`MAP_BUILDING_POSITIONS_REASSIGNED`).
367
+
326
368
  Use `renumber_map_entity` for `province`, `state`, or `strategic-region` IDs:
327
369
 
328
370
  ```json
@@ -401,14 +443,14 @@ Nothing is lost or duplicated: for any split, merge or move, the sums of manpowe
401
443
  | Field of a country | Meaning |
402
444
  | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
403
445
  | `tag`, `weight` | Three capital letters or digits, and the relative target size (default 1). A tag no `common/country_tags` file declares is assigned with a warning (`MAP_TERRITORY_TAG_UNDEFINED`), or refused with top-level `strictTags: true`. |
404
- | `seeds` | `{ state }`, `{ province }` or a pixel `{ x, y }` of the province map; the first is the capital. A seed in the sea is refused. |
405
- | `forced`, `blocked` | `{ stateIds, provinceIds, regionIds }`: land the country always or never owns. `regionIds` are strategic regions. |
446
+ | `seeds` | `{ state }`, `{ province }`, a pixel `{ x, y }` of the province map or a natural land `{ land }`; the first is the capital. A seed in the sea is refused. |
447
+ | `forced`, `blocked` | `{ stateIds, provinceIds, regionIds, landIds }`: land the country always or never owns. `regionIds` are strategic regions, `landIds` [natural lands](#natural-lands). |
406
448
  | `regions` | Strategic regions the country prefers to grow in (a step into another country's preferred region costs more). |
407
449
  | `overlord`, `mergeInto` | A subject is grown inside its overlord's territory. `mergeInto` relabels the finished territory to another listed country and keeps its tag as a core. |
408
450
  | `cores`, `claims` | Extra states the country holds a core on or claims. |
409
451
  | `fixed` | The country owns exactly its seeds and `forced` land and never grows, for a realm whose land is settled. Smoothing and corridors leave it alone. |
410
452
 
411
- Top-level fields: `unit` (`state`, the default, assigns whole states; `province` assigns provinces and regroups the states a border cuts), `scope` (`stateIds`, `regionIds`, `owners`: only these states take part), `unowned` (land nobody owns), `barriers` (`natural` or `none`, which grows on distance alone), `rules.connectedMainland` (default true) and `rules.islandPolicy` (`one-owner`, `nearest` or `unowned` for landmasses without a seed), `smoothing` (`passes` 0 to 20, `maxShareChange`), `shareTolerance` (default 0.15), `seed` (the same seed gives the same borders), `ownership` (`controller`: `owner` or `keep`; `cores`: `keep`, `owner` or `add-owner`; `claims`: `keep` or `clear`; `unowned`: `clear` or `keep`), `stateSize` (province unit: fragments below `min` provinces join a neighbour of the same owner and strategic region), `remapReferences` (`refuse` or `override`, as for `merge_states`), `borderQuality` and `borderTargets`. `groups` (`{ provinceId: group }`) draws culture or people lines: a growth step across one costs `1 + groupPenalty` times more (default 2), like a ridge, so borders move to the lines but balancing can still cross them; with `groupHard: true` growth never crosses a line, so a people's pocket is never entered from outside. A state takes the group of most of its provinces. Besides `map-territory-report.json`, the result has `map-territory-assignment.json`: the provinces of each owner and of each new or changed state, compact enough to read after a preview. A seed in water is refused with the nearest land province in the message and `details.nearestLandProvince`.
453
+ Top-level fields: `unit` (`state`, the default, assigns whole states; `province` assigns provinces and regroups the states a border cuts), `scope` (`stateIds`, `regionIds`, `owners`: only these states take part), `unowned` (land nobody owns), `barriers` (`natural` or `none`, which grows on distance alone), `rules.connectedMainland` (default true) and `rules.islandPolicy` (`one-owner`, `nearest` or `unowned` for landmasses without a seed), `smoothing` (`passes` 0 to 20, `maxShareChange`), `shareTolerance` (default 0.15), `seed` (the same seed gives the same borders), `ownership` (`controller`: `owner` or `keep`; `cores`: `keep`, `owner` or `add-owner`; `claims`: `keep` or `clear`; `unowned`: `clear` or `keep`), `stateSize` (province unit: fragments below `min` provinces join a neighbour of the same owner and strategic region), `remapReferences` (`refuse` or `override`, as for `merge_states`), `borderQuality`, `borderTargets`, `borderQualityScope` and `landOptions` (the thresholds of the [natural lands](#natural-lands) that `landIds` and `{ land }` seeds name). `groups` (`{ provinceId: group }`) draws culture or people lines: a growth step across one costs `1 + groupPenalty` times more (default 2), like a ridge, so borders move to the lines but balancing can still cross them; with `groupHard: true` growth never crosses a line, so a people's pocket is never entered from outside. A state takes the group of most of its provinces. Besides `map-territory-report.json`, the result has `map-territory-assignment.json`: the provinces of each owner and of each new or changed state, compact enough to read after a preview. A seed in water is refused with the nearest land province in the message and `details.nearestLandProvince`.
412
454
 
413
455
  How it works: a multi-source shortest-path growth from the seeds over the province or state graph, where a step costs the distance between centres times `1 + 6 * barrier` (the barrier is the strength of the rivers, slopes, lake shores and terrain changes along the shared border, measured by the metric of [Border naturalness](#border-naturalness)); country multipliers are corrected until sizes are within the tolerance of their targets; a country cut apart on its capital's landmass is joined by a corridor; and a local search moves boundary atoms when that shortens the artificial border without disconnecting the donor or leaving the size tolerance. Targets follow the weights, corrected for what the land allows (a country alone on an island owns the island).
414
456
 
@@ -418,7 +460,7 @@ The province unit writes the new borders exactly: each state is split by owner,
418
460
 
419
461
  `update_states` takes `updates: [{ stateId, changes }]` with the changes of `update_state`. The index is built once; a state may appear once, and an unknown state refuses the whole list.
420
462
 
421
- `borderQuality` is `report` by default: the result adds `MAP_BORDER_QUALITY_MEASURED` with the enrichment, natural share and straightness of the proposed country and state borders, and the artifact `map-territory-report.json` holds every number. `enforce` blocks the write when a layer misses the targets (enrichment 1.6; straightness 0.12 for countries and 0.25 for states; override with `borderTargets`) with `MAP_TERRITORY_BORDER_ARTIFICIAL`; `off` skips it. `data.territory` returns, per operation, the sizes against targets (worst eight countries), the border score, the same seeds grown on distance alone (`distanceOnly`), and the counts of states changed, created and removed. Previews work as for any rewrite and write nothing.
463
+ `borderQuality` is `report` by default: the result adds `MAP_BORDER_QUALITY_MEASURED` with the enrichment, natural share and straightness of the proposed country and state borders, and the artifact `map-territory-report.json` holds every number. `enforce` blocks the write when a layer misses the targets (enrichment 1.6; straightness 0.12 for countries and 0.25 for states; override with `borderTargets`) with `MAP_TERRITORY_BORDER_ARTIFICIAL`; `off` skips it. `borderQualityScope` (`owners`, `stateIds`, `box`, as `qualityScope` of `hoi4.map_inspect`) measures and judges only the borders of the region being redrawn; the measured note then says `inside the scope`, and an empty scope is `MAP_BORDER_QUALITY_UNAVAILABLE`, a blocker in `enforce`. `data.territory` returns, per operation, the sizes against targets (worst eight countries), the border score, the same seeds grown on distance alone (`distanceOnly`), and the counts of states changed, created and removed. Previews work as for any rewrite and write nothing.
422
464
 
423
465
  Unowned land: states in `unowned`, and landmasses without a seed under `islandPolicy: "unowned"`, are not grown into. With `ownership.unowned: "clear"` (the default) their owner is removed, and their controller too when `controller` is `owner`; `"keep"` leaves them as they were. States outside `scope` are never edited. Provinces that belong to no state cannot be owned and are left out.
424
466
 
package/docs/tools.md CHANGED
@@ -32,7 +32,7 @@ A test fails when this page differs from `tools/list`, so edit the tool descript
32
32
  | `hoi4.mod_health` | Check a whole mod in one call: the last error.log, the engine check (unknown effects, triggers and modifiers, duplicate ids, broken overrides), script validation, and the localisation and asset audits. Returns the 10 problems that matter most, each counted with 2 examples, its fix and the tool to use next, and which audits ran. | — |
33
33
  | `hoi4.script_guard` | Check the files you wrote for invented commands: every effect, trigger and modifier that the installed game documentation does not list and no loaded file defines, with its file, line and the closest real name. Checks the named paths, or the mod script files changed in the last 120 minutes. Needs hoi4-engine. | — |
34
34
  | `hoi4.compat_check` | mod: compare this mod with another in both load orders: files at the same path and who wins, duplicate ids, definitions and hooks dropped, replace_path losses, and which order loses less. patch: store the vanilla files the mod overrides and list those a game update changed. | — |
35
- | `hoi4.mod_index` | Summarize the content in a mod or find a free event ID across the mod, game and dependencies. Use overview for descriptors, folders and definitions, or next_id with a namespace or prefix. | — |
35
+ | `hoi4.mod_index` | Summarize the content in a mod or find a free event ID across the mod, game and dependencies. Use overview for descriptors, folders and definitions (the 50 busiest namespaces; pass a namespace or prefix to list those starting with it), or next_id with a namespace or prefix. | — |
36
36
  | `hoi4.localisation_inspect` | Read localisation in every language the game and mod ship. key: one key per language with file, line and layer, the languages lacking it and the files mentioning it. audit: keys the mod uses that no language defines, keys missing from a supported language, keys defined twice in one language, and file problems. coverage: keys per language. | — |
37
37
  | `hoi4.idea_inspect` | Read an idea or character across the game, DLC and mod. idea: category, picture sprite and texture, modifiers checked against the game docs, conditions, name in every language, the advisor it belongs to, and files mentioning it. character: name, roles with traits checked, portraits checked. audit: true checks every idea or character of the mod. | — |
38
38
  | `hoi4.system_inspect` | Read one definition of a newer system, or audit every one the mod makes: on_actions hooks, MIOs and policies, balance of power, special projects, operations and raids. Returns its parts, each reference with whether it exists, pictures, names in every language and problems. | — |
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "win32-x64": {
21
21
  "file": "win32-x64/hoi4-engine.exe",
22
- "sha256": "e3f56c66d74960b37296f16ff70d37146855dbf1bcd0e414831ebe8733aed088",
22
+ "sha256": "3d51e078f6bc18b84d807fe6ac3b3ee492165810e695509200cf00c3582c9e25",
23
23
  "size": 4691968
24
24
  }
25
25
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "hoi4-agent-tools",
3
- "version": "4.17.0",
3
+ "version": "4.18.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "hoi4-agent-tools",
9
- "version": "4.17.0",
9
+ "version": "4.18.0",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@fontsource-variable/roboto": "5.3.0",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hoi4-agent-tools",
3
3
  "mcpName": "io.github.klimPaskov/hoi4-agent-tools",
4
- "version": "4.17.0",
4
+ "version": "4.18.0",
5
5
  "description": "Build HOI4 mods: focus trees, events, decisions, worlds, GUI previews, docs and AI balance.",
6
6
  "type": "module",
7
7
  "license": "Apache-2.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/configuration.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/configuration.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/continuous-focus-palette.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/continuous-focus-palette.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/custom-weighted-pool.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/custom-weighted-pool.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/decision-inspect-input.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/decision-inspect-input.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/error-log-input.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/error-log-input.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/event-feature-manifest.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/event-feature-manifest.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/focus-plan.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/focus-plan.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/focus-planning-sidecar.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/focus-planning-sidecar.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/geography-model.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/geography-model.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/gui-animation-source.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/gui-animation-source.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/gui-helper.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/gui-helper.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/gui-scenario.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/gui-scenario.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/helper-expansion-request.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/helper-expansion-request.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/helper-expansion-summary.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/helper-expansion-summary.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.17.0/schemas/impact-inspect-input.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.18.0/schemas/impact-inspect-input.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {