hoi4-agent-tools 4.16.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 (109) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +1 -0
  3. package/dist/hoi4_agent_tools/core/analysis-checkpoints.js +11 -4
  4. package/dist/hoi4_agent_tools/core/engine-client.js +30 -1
  5. package/dist/hoi4_agent_tools/core/engine.js +56 -27
  6. package/dist/hoi4_agent_tools/core/managed-outputs.js +54 -3
  7. package/dist/hoi4_agent_tools/core/operation-result.js +37 -6
  8. package/dist/hoi4_agent_tools/core/scanner.js +148 -7
  9. package/dist/hoi4_agent_tools/core/server-state.js +50 -2
  10. package/dist/hoi4_agent_tools/core/source/localisation.js +7 -1
  11. package/dist/hoi4_agent_tools/event/compare.js +47 -13
  12. package/dist/hoi4_agent_tools/event/operations.js +111 -20
  13. package/dist/hoi4_agent_tools/focus/importer.js +2 -5
  14. package/dist/hoi4_agent_tools/focus/lint.js +2 -5
  15. package/dist/hoi4_agent_tools/focus/model.js +19 -0
  16. package/dist/hoi4_agent_tools/focus/tool-operations.js +16 -1
  17. package/dist/hoi4_agent_tools/focus/tool-support.js +14 -0
  18. package/dist/hoi4_agent_tools/map/appearance-validation.js +6 -1
  19. package/dist/hoi4_agent_tools/map/border-quality-input.js +57 -8
  20. package/dist/hoi4_agent_tools/map/border-quality.js +15 -6
  21. package/dist/hoi4_agent_tools/map/engine-raster.js +160 -0
  22. package/dist/hoi4_agent_tools/map/limits.js +13 -0
  23. package/dist/hoi4_agent_tools/map/model.js +9 -8
  24. package/dist/hoi4_agent_tools/map/natural-lands.js +902 -0
  25. package/dist/hoi4_agent_tools/map/operations.js +266 -23
  26. package/dist/hoi4_agent_tools/map/partition-provinces.js +6 -2
  27. package/dist/hoi4_agent_tools/map/partition-tuning.js +37 -0
  28. package/dist/hoi4_agent_tools/map/service.js +25 -12
  29. package/dist/hoi4_agent_tools/map/territory-operations.js +180 -3
  30. package/dist/hoi4_agent_tools/map/territory-quality.js +72 -5
  31. package/dist/hoi4_agent_tools/map/territory.js +63 -2
  32. package/dist/hoi4_agent_tools/map/tool-operations.js +79 -3
  33. package/dist/hoi4_agent_tools/map/validation.js +23 -3
  34. package/dist/hoi4_agent_tools/map/water.js +13 -10
  35. package/dist/hoi4_agent_tools/map/world-outputs.js +41 -26
  36. package/dist/hoi4_agent_tools/map/world.js +51 -1
  37. package/dist/hoi4_agent_tools/mcp/tools/map.js +52 -0
  38. package/dist/hoi4_agent_tools/mcp/tools/reference.js +3 -3
  39. package/dist/hoi4_agent_tools/mcp/tools/technology.js +25 -1
  40. package/dist/hoi4_agent_tools/reference/closure.js +65 -0
  41. package/dist/hoi4_agent_tools/reference/command-phrases.json +7899 -1127
  42. package/dist/hoi4_agent_tools/reference/mod-index.js +14 -5
  43. package/dist/hoi4_agent_tools/reference/operations.js +38 -21
  44. package/dist/hoi4_agent_tools/reference/ranking.js +77 -2
  45. package/dist/hoi4_agent_tools/reference/script-validation.js +4 -2
  46. package/dist/hoi4_agent_tools/reference/service.js +45 -2
  47. package/dist/hoi4_agent_tools/reference/source-lookup.js +43 -121
  48. package/dist/hoi4_agent_tools/runtime.js +27 -11
  49. package/dist/hoi4_agent_tools/schemas/lenient-arguments.js +7 -1
  50. package/dist/hoi4_agent_tools/schemas/map-requests.js +29 -1
  51. package/dist/hoi4_agent_tools/schemas/map.js +103 -2
  52. package/dist/hoi4_agent_tools/schemas/mod-tools.js +49 -0
  53. package/dist/hoi4_agent_tools/schemas/reference.js +1 -1
  54. package/dist/hoi4_agent_tools/schemas/script-validation.js +57 -3
  55. package/dist/hoi4_agent_tools/technology/operations.js +5 -0
  56. package/dist/hoi4_agent_tools/technology/queries.js +54 -0
  57. package/dist/hoi4_agent_tools/version.js +1 -1
  58. package/docs/configuration.md +1 -1
  59. package/docs/map.md +67 -23
  60. package/docs/research/reference-benchmark.md +64 -0
  61. package/docs/tools.md +20 -20
  62. package/docs/troubleshooting.md +4 -0
  63. package/engine/bin/darwin-arm64/hoi4-engine +0 -0
  64. package/engine/bin/linux-arm64/hoi4-engine +0 -0
  65. package/engine/bin/linux-x64/hoi4-engine +0 -0
  66. package/engine/bin/manifest.json +8 -8
  67. package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
  68. package/npm-shrinkwrap.json +2 -2
  69. package/package.json +5 -3
  70. package/schemas/configuration.schema.json +1 -1
  71. package/schemas/continuous-focus-palette.schema.json +1 -1
  72. package/schemas/custom-weighted-pool.schema.json +1 -1
  73. package/schemas/decision-inspect-input.schema.json +1 -1
  74. package/schemas/error-log-input.schema.json +1 -1
  75. package/schemas/event-feature-manifest.schema.json +1 -1
  76. package/schemas/focus-plan.schema.json +1 -1
  77. package/schemas/focus-planning-sidecar.schema.json +1 -1
  78. package/schemas/geography-model.schema.json +1 -1
  79. package/schemas/gui-animation-source.schema.json +1 -1
  80. package/schemas/gui-helper.schema.json +1 -1
  81. package/schemas/gui-scenario.schema.json +1 -1
  82. package/schemas/helper-expansion-request.schema.json +1 -1
  83. package/schemas/helper-expansion-summary.schema.json +1 -1
  84. package/schemas/impact-inspect-input.schema.json +1 -1
  85. package/schemas/map-operation.schema.json +1087 -815
  86. package/schemas/mechanic-test-input.schema.json +1 -1
  87. package/schemas/mod-index-input.schema.json +1 -1
  88. package/schemas/operation-result.schema.json +1 -1
  89. package/schemas/package-check-input.schema.json +1 -1
  90. package/schemas/package-manifest.schema.json +1 -1
  91. package/schemas/probability-analysis-result.schema.json +1 -1
  92. package/schemas/probability-compare-input.schema.json +1 -1
  93. package/schemas/probability-evaluate-input.schema.json +1 -1
  94. package/schemas/probability-inspect-input.schema.json +1 -1
  95. package/schemas/probability-render-input.schema.json +1 -1
  96. package/schemas/probability-scenario-set.schema.json +1 -1
  97. package/schemas/probability-sequence-input.schema.json +1 -1
  98. package/schemas/probability-simulate-input.schema.json +1 -1
  99. package/schemas/probability-sweep-input.schema.json +1 -1
  100. package/schemas/reference-context-input.schema.json +1 -1
  101. package/schemas/reference-read-input.schema.json +1 -1
  102. package/schemas/reference-search-input.schema.json +2 -2
  103. package/schemas/reference-sheets.schema.json +1 -1
  104. package/schemas/scenario-suite.schema.json +1 -1
  105. package/schemas/scenario-test-input.schema.json +1 -1
  106. package/schemas/script-validate-input.schema.json +7 -1
  107. package/schemas/shared-scenario.schema.json +1 -1
  108. package/schemas/source-lookup-input.schema.json +1 -1
  109. package/server.json +2 -2
@@ -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';
@@ -410,6 +410,12 @@ export const worldPartitionTuningSchema = z
410
410
  .max(64)
411
411
  .optional()
412
412
  .describe('A sea channel at most this wide gets two sea provinces across it; default 24.'),
413
+ areaByRow: z
414
+ .array(z.tuple([z.number().min(0).max(1), z.number().min(0.25).max(8)]))
415
+ .min(1)
416
+ .max(32)
417
+ .optional()
418
+ .describe('[row, factor] points, row 0 the top edge and 1 the bottom, in increasing row order: the land province area at a row is multiplied by the factor, linearly between points and held beyond the ends, after the plan is scaled to the base area. States keep their province counts, so they grow by the same factor. MAP_PARTITION_AREA_BY_ROW reports the mean province area per band.'),
413
419
  })
414
420
  .strict();
415
421
  const moveStateDistributionSchema = z
@@ -738,6 +744,39 @@ const stateChangesSchema = z
738
744
  provinceBuildings: z.record(z.string().regex(/^\d+$/u), nonnegativeMap).optional(),
739
745
  })
740
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.');
741
780
  const tagSchema = z
742
781
  .string()
743
782
  .regex(/^[A-Z0-9]{3}$/u, 'A country tag is three capital letters or digits');
@@ -745,12 +784,21 @@ const territoryRefSchema = z.union([
745
784
  z.object({ state: stateId }).strict(),
746
785
  z.object({ province: provinceId }).strict(),
747
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.'),
748
791
  ]);
749
792
  const territorySelectionSchema = z
750
793
  .object({
751
794
  stateIds: z.array(stateId).max(100_000).optional(),
752
795
  provinceIds: z.array(provinceId).max(100_000).optional(),
753
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.'),
754
802
  })
755
803
  .strict();
756
804
  const borderQualityModeSchema = z
@@ -764,6 +812,23 @@ const borderTargetsSchema = z
764
812
  })
765
813
  .strict()
766
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.');
767
832
  const territoryCountrySchema = z
768
833
  .object({
769
834
  tag: tagSchema,
@@ -777,7 +842,7 @@ const territoryCountrySchema = z
777
842
  .array(territoryRefSchema)
778
843
  .min(1)
779
844
  .max(64)
780
- .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.'),
781
846
  forced: territorySelectionSchema.optional(),
782
847
  blocked: territorySelectionSchema.optional(),
783
848
  regions: z
@@ -786,6 +851,10 @@ const territoryCountrySchema = z
786
851
  .optional()
787
852
  .describe('Strategic regions this country prefers to grow in.'),
788
853
  overlord: tagSchema.optional().describe('Grow this country inside its overlord.'),
854
+ fixed: z
855
+ .boolean()
856
+ .optional()
857
+ .describe('The country owns exactly its seeds and forced land and never grows, for a realm whose land is already settled.'),
789
858
  mergeInto: tagSchema
790
859
  .optional()
791
860
  .describe('Relabel the finished territory to another listed country (this tag stays a core).'),
@@ -852,6 +921,31 @@ const territoryOperation = z
852
921
  remapReferences: z.enum(['refuse', 'override']).optional(),
853
922
  borderQuality: borderQualityModeSchema.default('report'),
854
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.'),
930
+ groups: z
931
+ .record(z.string().regex(/^\d{1,6}$/u), z.string().min(1).max(64))
932
+ .refine((value) => Object.keys(value).length <= 65_000, 'At most 65,000 provinces')
933
+ .optional()
934
+ .describe('Culture or people group of provinces, { provinceId: group }. Growth across a group boundary costs like a ridge (groupPenalty), or never happens with groupHard. A state atom takes the group of most of its provinces.'),
935
+ groupPenalty: z
936
+ .number()
937
+ .min(0)
938
+ .max(100)
939
+ .optional()
940
+ .describe('A step across a group boundary costs 1 + groupPenalty times more; default 2.'),
941
+ groupHard: z
942
+ .boolean()
943
+ .optional()
944
+ .describe('Growth never crosses a group boundary, so a people keeps its own countries.'),
945
+ strictTags: z
946
+ .boolean()
947
+ .optional()
948
+ .describe('Refuse the operation when a country or overlord tag is not declared in common/country_tags; by default that is a warning (MAP_TERRITORY_TAG_UNDEFINED).'),
855
949
  })
856
950
  .strict();
857
951
  const repartitionOperation = z
@@ -871,6 +965,9 @@ const repartitionOperation = z
871
965
  remapReferences: z.enum(['refuse', 'override']).optional(),
872
966
  borderQuality: borderQualityModeSchema.default('report'),
873
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.'),
874
971
  })
875
972
  .strict();
876
973
  export const mapOperationSchema = z.discriminatedUnion('kind', [
@@ -1181,6 +1278,10 @@ export const mapOperationSchema = z.discriminatedUnion('kind', [
1181
1278
  kind: z
1182
1279
  .literal('record_world_outputs')
1183
1280
  .describe('Adopt the current bytes of every output the world inventory (.hoi4-agent-world.json) records, so the next create_world overwrites them instead of refusing them as edited (MANAGED_OUTPUT_EDITED). Recorded files that are gone are dropped. Reports MAP_WORLD_OUTPUTS_RECORDED.'),
1281
+ adoptUnrecorded: z
1282
+ .boolean()
1283
+ .optional()
1284
+ .describe('Add the files of the mod at world output paths (state files, strategic regions, map files, world localisation) that the record lacks, for example ones earlier operations created. Default true; false only re-hashes the listed entries.'),
1184
1285
  })
1185
1286
  .strict(),
1186
1287
  z
@@ -221,6 +221,55 @@ export const sourceLookupEngineResponseSchema = z
221
221
  suggestionCandidates: z
222
222
  .array(z.object({ id: z.string(), distance: z.number().int().min(0).max(3) }).strict())
223
223
  .max(2_000),
224
+ /** With `includeReferences`: the first `maxReferences` references, in the TypeScript order. */
225
+ references: z
226
+ .array(z
227
+ .object({
228
+ kind: z.string(),
229
+ from: z.string(),
230
+ toKind: z.string(),
231
+ path: z.string(),
232
+ line: z.number().int().min(1),
233
+ })
234
+ .strict())
235
+ .max(20)
236
+ .default([]),
237
+ /** Distinct references to the symbol (of the requested kind), all of them. */
238
+ referenceCount: z.number().int().min(0).default(0),
239
+ /** False when the semantic scan skipped a source or reached a ceiling. */
240
+ semanticComplete: z.boolean().default(true),
241
+ /** Dynamic targets the semantic scan could not resolve, in the whole scan. */
242
+ unresolvedReferenceCount: z.number().int().min(0).default(0),
243
+ })
244
+ .strict();
245
+ /** `hoi4-engine closure` (`hoi4-closure/1`): what the shared Rust engine answers. */
246
+ export const closureEngineResponseSchema = z
247
+ .object({
248
+ schema: z.literal('hoi4-closure/1'),
249
+ status: z.literal('ok'),
250
+ revision: z.string().regex(/^[0-9a-f]{64}$/u),
251
+ complete: z.boolean(),
252
+ skippedSourceCount: z.number().int().min(0),
253
+ semanticComplete: z.boolean(),
254
+ verdict: z.enum(['closed', 'unresolved', 'incomplete']),
255
+ sources: z.number().int().min(0),
256
+ totals: z
257
+ .object({
258
+ resolved: z.number().int().min(0),
259
+ unresolved: z.number().int().min(0),
260
+ unknown: z.number().int().min(0),
261
+ })
262
+ .strict(),
263
+ kinds: z
264
+ .array(z
265
+ .object({
266
+ kind: z.string(),
267
+ resolved: z.number().int().min(0),
268
+ unresolved: z.number().int().min(0),
269
+ unknown: z.number().int().min(0),
270
+ })
271
+ .strict())
272
+ .max(64),
224
273
  })
225
274
  .strict();
226
275
  /** `hoi4-engine mod-index` (`hoi4-mod-index/1`): what the shared Rust engine answers. */
@@ -18,7 +18,7 @@ export const referenceSearchRequestSchema = z
18
18
  workspaceId: workspaceIdSchema,
19
19
  query: z.string().trim().min(2).max(160),
20
20
  sources: z.array(referenceSourceSchema).min(1).max(3).optional(),
21
- limit: z.number().int().min(1).max(12).default(6),
21
+ limit: z.number().int().min(1).max(12).default(10),
22
22
  })
23
23
  .strict();
24
24
  export const referenceReadRequestSchema = z
@@ -30,14 +30,32 @@ export const scriptValidateRequestSchema = z
30
30
  .max(16)
31
31
  .default([]),
32
32
  limit: z.number().int().min(1).max(32).default(12),
33
+ /**
34
+ * Whole-mod closure: count the references of the mod's own sources that resolve, do not
35
+ * resolve, or cannot be decided, per target kind, and give a verdict (`incomplete` whenever
36
+ * anything is unknown). Replaces `source` and `path`.
37
+ */
38
+ closure: z.boolean().optional(),
33
39
  })
34
40
  .strict()
35
41
  .superRefine((value, context) => {
36
- if ((value.source === undefined) === (value.path === undefined))
42
+ const modes = [
43
+ value.source !== undefined,
44
+ value.path !== undefined,
45
+ value.closure === true,
46
+ ].filter(Boolean).length;
47
+ if (modes !== 1)
37
48
  context.addIssue({
38
49
  code: 'custom',
39
50
  path: ['source'],
40
- message: 'Provide either source with kind and scope, or a mod file path',
51
+ message: 'Provide either source with kind and scope, a mod file path, or closure: true for the whole mod',
52
+ });
53
+ if (value.closure === true &&
54
+ (value.kind !== undefined || value.scope !== undefined || value.bindings.length > 0))
55
+ context.addIssue({
56
+ code: 'custom',
57
+ path: ['closure'],
58
+ message: 'A closure check covers the whole mod and takes no kind, scope or bindings',
41
59
  });
42
60
  if (value.source !== undefined && value.scope === undefined)
43
61
  context.addIssue({
@@ -64,12 +82,14 @@ export const scriptValidateDataSchema = z
64
82
  'event_popups',
65
83
  'known_mistakes',
66
84
  'identifier_arguments',
85
+ 'closure',
67
86
  ])),
68
87
  /**
69
88
  * Identifier arguments (ideas, events, decisions, focuses, technologies) were checked against
70
89
  * the workspace's definitions. Other argument values are not checked.
71
90
  */
72
91
  parametersChecked: z.boolean(),
92
+ /** Absent for a closure check, which reads no documentation. */
73
93
  documentation: z
74
94
  .object({
75
95
  source: z.enum(['game_doc', 'script_doc']),
@@ -78,7 +98,8 @@ export const scriptValidateDataSchema = z
78
98
  triggerCount: z.number().int().min(0),
79
99
  skippedSources: z.number().int().min(0),
80
100
  })
81
- .strict(),
101
+ .strict()
102
+ .optional(),
82
103
  findings: z
83
104
  .array(z
84
105
  .object({
@@ -103,6 +124,39 @@ export const scriptValidateDataSchema = z
103
124
  argumentBlocksUnchecked: z.number().int().min(0),
104
125
  /** What made the result partial when `valid` is null, one plain sentence each. */
105
126
  partialReasons: z.array(z.string().max(600)).max(5).optional(),
127
+ /** The whole-mod closure (`closure: true`). */
128
+ closure: z
129
+ .object({
130
+ verdict: z.enum(['closed', 'unresolved', 'incomplete']),
131
+ /** The scan revision, as `hoi4.source_lookup` reports it. */
132
+ revision: z.string().regex(/^[a-f0-9]{64}$/u),
133
+ /** False when a source was skipped, so a definition may be missing. */
134
+ complete: z.boolean(),
135
+ /** False when the semantic scan skipped a source or reached a ceiling. */
136
+ semanticComplete: z.boolean(),
137
+ skippedSourceCount: z.number().int().min(0),
138
+ /** Mod-owned sources whose references were counted. */
139
+ sources: z.number().int().min(0),
140
+ totals: z
141
+ .object({
142
+ resolved: z.number().int().min(0),
143
+ unresolved: z.number().int().min(0),
144
+ unknown: z.number().int().min(0),
145
+ })
146
+ .strict(),
147
+ kinds: z
148
+ .array(z
149
+ .object({
150
+ kind: z.string().max(64),
151
+ resolved: z.number().int().min(0),
152
+ unresolved: z.number().int().min(0),
153
+ unknown: z.number().int().min(0),
154
+ })
155
+ .strict())
156
+ .max(64),
157
+ })
158
+ .strict()
159
+ .optional(),
106
160
  file: z
107
161
  .object({
108
162
  path: z.string().max(4096),
@@ -4,6 +4,7 @@ import { compareCodeUnits, hashCanonical } from '../core/canonical.js';
4
4
  import { emptyServiceResult } from '../core/result.js';
5
5
  import { setInlineFilesScanned } from '../core/operation-result.js';
6
6
  import { technologyCompareRequestSchema, technologyInspectRequestSchema, splitTechnologyInspectRequest, technologyRenderRequestSchema, } from '../schemas/technology.js';
7
+ import { technologyExplainSummary } from './queries.js';
7
8
  import { technologyDiagnostics } from './service.js';
8
9
  export function normalizeTechnologyInspectionRequest(input) {
9
10
  return JSON.parse(JSON.stringify(technologyInspectRequestSchema.parse(input)));
@@ -107,6 +108,10 @@ export async function inspectTechnologies(viewer, input) {
107
108
  graphHash: technologyGraphHash(output.graph),
108
109
  counts: technologyCounts(output.graph, output.artifacts.length),
109
110
  ...(output.helperExpansion === undefined ? {} : { helperExpansion: output.helperExpansion }),
111
+ ...(() => {
112
+ const technology = input.mode === 'explain' ? technologyExplainSummary(output.report) : undefined;
113
+ return technology === undefined ? {} : { technology };
114
+ })(),
110
115
  });
111
116
  result.code =
112
117
  (output.helperExpansion?.complete ?? output.graph.complete)
@@ -213,6 +213,9 @@ export function traceTechnology(graph, input) {
213
213
  };
214
214
  }
215
215
  export function explainTechnology(graph, technologyId, signal) {
216
+ return explainTechnologyReport(graph, technologyId, signal);
217
+ }
218
+ function explainTechnologyReport(graph, technologyId, signal) {
216
219
  requireTechnology(graph, technologyId);
217
220
  const technology = graph.technologies.find(({ id }) => id === technologyId);
218
221
  const prerequisites = traceTechnology(graph, {
@@ -369,3 +372,54 @@ export function analyzeTechnologyImpact(graph, input) {
369
372
  limitations: graph.analysisBoundary.unsupportedConstructs,
370
373
  };
371
374
  }
375
+ /** Names listed inline per relation; the full lists are in the linked report. */
376
+ const EXPLAIN_SUMMARY_LIST_LIMIT = 20;
377
+ function limited(values) {
378
+ const sorted = [...new Set(values)].sort(compareCodeUnits);
379
+ return {
380
+ values: sorted.slice(0, EXPLAIN_SUMMARY_LIST_LIMIT),
381
+ cut: sorted.length > EXPLAIN_SUMMARY_LIST_LIMIT,
382
+ };
383
+ }
384
+ /**
385
+ * The inline part of an explanation, so the answer names what the agent asked for without the
386
+ * linked report: the direct prerequisites, what the technology leads to, its exclusive choices and
387
+ * unlocks (each at most 20 names), and the totals of the full report.
388
+ */
389
+ export function technologyExplainSummary(report) {
390
+ if (typeof report !== 'object' || report === null || !('technology' in report))
391
+ return undefined;
392
+ const explained = report;
393
+ const { technology } = explained;
394
+ const prerequisites = limited(explained.directPrerequisites.map(({ from }) => from));
395
+ const leadsTo = limited(explained.directDescendants.map(({ to }) => to));
396
+ const exclusiveWith = limited(explained.exclusiveChoices.map(({ from, to }) => (from === technology.id ? to : from)));
397
+ const unlocks = [...explained.unlocks]
398
+ .sort((left, right) => compareCodeUnits(left.kind, right.kind) || compareCodeUnits(left.targetId, right.targetId))
399
+ .map(({ kind, targetId }) => ({ kind, targetId }));
400
+ return {
401
+ id: technology.id,
402
+ path: technology.source.path,
403
+ line: technology.source.location.start.line,
404
+ ...(technology.localisation.name === undefined ? {} : { name: technology.localisation.name }),
405
+ ...(technology.startYear === undefined ? {} : { startYear: technology.startYear }),
406
+ ...(technology.researchCost === undefined ? {} : { researchCost: technology.researchCost }),
407
+ folders: [...technology.folders].sort(compareCodeUnits),
408
+ categories: [...technology.categories].sort(compareCodeUnits),
409
+ prerequisites: prerequisites.values,
410
+ leadsTo: leadsTo.values,
411
+ exclusiveWith: exclusiveWith.values,
412
+ unlocks: unlocks.slice(0, EXPLAIN_SUMMARY_LIST_LIMIT),
413
+ allPrerequisites: explained.transitivePrerequisites.nodes.length - 1,
414
+ allDescendants: explained.descendants.nodes.length - 1,
415
+ unlockCount: unlocks.length,
416
+ grantedBy: explained.externalGrants.length,
417
+ issues: explained.issues.length,
418
+ truncated: prerequisites.cut ||
419
+ leadsTo.cut ||
420
+ exclusiveWith.cut ||
421
+ unlocks.length > EXPLAIN_SUMMARY_LIST_LIMIT ||
422
+ explained.transitivePrerequisites.truncated ||
423
+ explained.descendants.truncated,
424
+ };
425
+ }
@@ -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.16.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;
@@ -24,7 +24,7 @@ In every other case a missing or unreadable file stops startup with `CONFIG_READ
24
24
  The automatic configuration works like this:
25
25
 
26
26
  - Starting from the server's working directory and moving up through its parents, the server takes the first folder that looks like a mod: it has `descriptor.mod`, a standard `common/` subfolder such as `common/national_focus`, or a standard content folder such as `events/` or `localisation/` with matching files.
27
- The search stops at a game installation (a folder with `hoi4.exe`, `run_hoi4` or `steam_appid.txt`), and startup fails with `AUTO_MOD_ROOT_NOT_FOUND` when nothing is found.
27
+ The search stops at a game installation (a folder with `hoi4.exe`, `run_hoi4` or `steam_appid.txt`), and, when nothing is found, the server still starts with no workspace: the documentation tools (`hoi4.reference_search`, `hoi4.reference_read`, `hoi4.reference_context`) answer from the game and the fetched docs pack, and every mod tool answers `WORKSPACE_CONTEXT_NOT_FOUND`.
28
28
  - That folder becomes the only workspace, with the ID `auto_<folder name>`.
29
29
  - The game folder is the first existing folder among `HOI4_GAME_ROOT` and the standard Steam locations on Windows, Linux and macOS.
30
30
  - Server state and generated files use the default storage locations below.