hoi4-agent-tools 4.7.0 → 4.9.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 (120) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +32 -13
  3. package/dist/hoi4_agent_tools/core/engine-client.js +74 -5
  4. package/dist/hoi4_agent_tools/core/index.js +28 -0
  5. package/dist/hoi4_agent_tools/core/operation-result.js +9 -0
  6. package/dist/hoi4_agent_tools/core/resident-engine.js +273 -0
  7. package/dist/hoi4_agent_tools/core/temporary-directories.js +3 -2
  8. package/dist/hoi4_agent_tools/decision/service.js +46 -2
  9. package/dist/hoi4_agent_tools/event/queries.js +25 -2
  10. package/dist/hoi4_agent_tools/event/service.js +78 -11
  11. package/dist/hoi4_agent_tools/event/summary.js +9 -0
  12. package/dist/hoi4_agent_tools/focus/engine-layout.js +1 -1
  13. package/dist/hoi4_agent_tools/focus/game-render.js +72 -0
  14. package/dist/hoi4_agent_tools/focus/game-view-output.js +160 -0
  15. package/dist/hoi4_agent_tools/focus/native-effects.js +4 -4
  16. package/dist/hoi4_agent_tools/focus/quality/focus-quality-calibration.json +241 -241
  17. package/dist/hoi4_agent_tools/focus/quality/orthogonal.js +30 -19
  18. package/dist/hoi4_agent_tools/focus/quality/schematic.js +5 -3
  19. package/dist/hoi4_agent_tools/focus/quality/scorecard.js +1 -1
  20. package/dist/hoi4_agent_tools/focus/render.js +21 -9
  21. package/dist/hoi4_agent_tools/focus/tool-operations.js +158 -3
  22. package/dist/hoi4_agent_tools/gui/assets.js +18 -0
  23. package/dist/hoi4_agent_tools/gui/dds.js +38 -5
  24. package/dist/hoi4_agent_tools/gui/engine-textures.js +48 -0
  25. package/dist/hoi4_agent_tools/gui/source-graph.js +7 -0
  26. package/dist/hoi4_agent_tools/gui/tool-operations.js +23 -4
  27. package/dist/hoi4_agent_tools/gui/validators.js +31 -2
  28. package/dist/hoi4_agent_tools/ideas/inspect.js +43 -0
  29. package/dist/hoi4_agent_tools/impact/service.js +15 -0
  30. package/dist/hoi4_agent_tools/localisation/inspect.js +34 -0
  31. package/dist/hoi4_agent_tools/map/appearance-validation.js +14 -2
  32. package/dist/hoi4_agent_tools/map/geography/resolve.js +3 -2
  33. package/dist/hoi4_agent_tools/map/tool-operations.js +41 -0
  34. package/dist/hoi4_agent_tools/map/world-edge.js +117 -15
  35. package/dist/hoi4_agent_tools/map/world.js +158 -34
  36. package/dist/hoi4_agent_tools/mcp/server/argument-errors.js +59 -9
  37. package/dist/hoi4_agent_tools/mcp/server/create-modern-operations.js +1 -1
  38. package/dist/hoi4_agent_tools/mcp/server/request-lifecycle.js +1 -1
  39. package/dist/hoi4_agent_tools/mcp/tools/analysis.js +4 -2
  40. package/dist/hoi4_agent_tools/mcp/tools/event.js +15 -0
  41. package/dist/hoi4_agent_tools/mcp/tools/focus.js +1 -1
  42. package/dist/hoi4_agent_tools/mcp/tools/gui.js +1 -1
  43. package/dist/hoi4_agent_tools/mcp/tools/reference.js +43 -0
  44. package/dist/hoi4_agent_tools/probability/operations.js +27 -1
  45. package/dist/hoi4_agent_tools/probability/service.js +91 -11
  46. package/dist/hoi4_agent_tools/probability/source-analysis.js +2 -2
  47. package/dist/hoi4_agent_tools/probability/sweep.js +20 -6
  48. package/dist/hoi4_agent_tools/reference/command-phrases.json +11065 -0
  49. package/dist/hoi4_agent_tools/reference/error-log.js +59 -1
  50. package/dist/hoi4_agent_tools/reference/known-mistakes.js +8 -5
  51. package/dist/hoi4_agent_tools/reference/known-mistakes.json +4 -4
  52. package/dist/hoi4_agent_tools/reference/operations.js +205 -12
  53. package/dist/hoi4_agent_tools/reference/ranking.js +32 -0
  54. package/dist/hoi4_agent_tools/reference/script-validation.js +159 -8
  55. package/dist/hoi4_agent_tools/reference/service.js +33 -0
  56. package/dist/hoi4_agent_tools/reference/source-lookup.js +8 -0
  57. package/dist/hoi4_agent_tools/schemas/focus-requests.js +4 -0
  58. package/dist/hoi4_agent_tools/schemas/ideas.js +142 -0
  59. package/dist/hoi4_agent_tools/schemas/localisation.js +94 -0
  60. package/dist/hoi4_agent_tools/schemas/map.js +32 -4
  61. package/dist/hoi4_agent_tools/schemas/mod-tools.js +11 -0
  62. package/dist/hoi4_agent_tools/schemas/script-validation.js +8 -1
  63. package/dist/hoi4_agent_tools/schemas/system.js +157 -0
  64. package/dist/hoi4_agent_tools/system/inspect.js +55 -0
  65. package/dist/hoi4_agent_tools/version.js +1 -1
  66. package/docs/analysis.md +2 -2
  67. package/docs/events.md +1 -1
  68. package/docs/focus.md +9 -5
  69. package/docs/map.md +19 -8
  70. package/docs/research/reference-benchmark.md +41 -0
  71. package/docs/tools.md +49 -39
  72. package/docs/troubleshooting.md +13 -12
  73. package/engine/README.md +293 -0
  74. package/engine/bin/darwin-arm64/hoi4-engine +0 -0
  75. package/engine/bin/linux-arm64/hoi4-engine +0 -0
  76. package/engine/bin/linux-x64/hoi4-engine +0 -0
  77. package/engine/bin/manifest.json +26 -0
  78. package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
  79. package/npm-shrinkwrap.json +2 -2
  80. package/package.json +4 -1
  81. package/schemas/configuration.schema.json +1 -1
  82. package/schemas/continuous-focus-palette.schema.json +1 -1
  83. package/schemas/custom-weighted-pool.schema.json +1 -1
  84. package/schemas/decision-inspect-input.schema.json +1 -1
  85. package/schemas/error-log-input.schema.json +1 -1
  86. package/schemas/event-feature-manifest.schema.json +1 -1
  87. package/schemas/focus-plan.schema.json +1 -1
  88. package/schemas/focus-planning-sidecar.schema.json +1 -1
  89. package/schemas/geography-model.schema.json +1 -1
  90. package/schemas/gui-animation-source.schema.json +1 -1
  91. package/schemas/gui-helper.schema.json +1 -1
  92. package/schemas/gui-scenario.schema.json +1 -1
  93. package/schemas/helper-expansion-request.schema.json +1 -1
  94. package/schemas/helper-expansion-summary.schema.json +1 -1
  95. package/schemas/impact-inspect-input.schema.json +1 -1
  96. package/schemas/map-operation.schema.json +165 -101
  97. package/schemas/mechanic-test-input.schema.json +1 -1
  98. package/schemas/mod-index-input.schema.json +1 -1
  99. package/schemas/operation-result.schema.json +1 -1
  100. package/schemas/package-check-input.schema.json +1 -1
  101. package/schemas/package-manifest.schema.json +1 -1
  102. package/schemas/probability-analysis-result.schema.json +1 -1
  103. package/schemas/probability-compare-input.schema.json +1 -1
  104. package/schemas/probability-evaluate-input.schema.json +1 -1
  105. package/schemas/probability-inspect-input.schema.json +1 -1
  106. package/schemas/probability-render-input.schema.json +1 -1
  107. package/schemas/probability-scenario-set.schema.json +1 -1
  108. package/schemas/probability-sequence-input.schema.json +1 -1
  109. package/schemas/probability-simulate-input.schema.json +1 -1
  110. package/schemas/probability-sweep-input.schema.json +1 -1
  111. package/schemas/reference-context-input.schema.json +1 -1
  112. package/schemas/reference-read-input.schema.json +1 -1
  113. package/schemas/reference-search-input.schema.json +1 -1
  114. package/schemas/reference-sheets.schema.json +1 -1
  115. package/schemas/scenario-suite.schema.json +1 -1
  116. package/schemas/scenario-test-input.schema.json +1 -1
  117. package/schemas/script-validate-input.schema.json +1 -1
  118. package/schemas/shared-scenario.schema.json +1 -1
  119. package/schemas/source-lookup-input.schema.json +1 -1
  120. package/server.json +2 -2
@@ -52,6 +52,12 @@ function resolveSourceBackedAdapter(snapshot, source, candidatePool, requested)
52
52
  (error.code !== 'PROBABILITY_SURFACE_EMPTY' &&
53
53
  error.code !== 'PROBABILITY_IDENTIFIER_NOT_FOUND'))
54
54
  throw error;
55
+ // An explicit adapter is honoured or refused. Running another one would answer a
56
+ // different question than the one asked.
57
+ const alternatives = inventoryWeightedSurfaces(snapshot, source, candidatePool).adapters.filter(({ candidateCount }) => candidateCount > 0);
58
+ throw new ServiceError(error.code, `Adapter ${requested} found no matching weighted blocks in this source${alternatives.length === 0
59
+ ? ''
60
+ : `; adapters with weighted blocks here: ${alternatives.map(({ adapterId }) => adapterId).join(', ')}`}`, { requestedAdapter: requested, source, candidatePool, availableAdapters: alternatives });
55
61
  }
56
62
  }
57
63
  const inventory = inventoryWeightedSurfaces(snapshot, source, candidatePool);
@@ -210,8 +216,61 @@ function filterCandidateMetrics(candidate, metrics) {
210
216
  : {}),
211
217
  };
212
218
  }
219
+ /** A requested metric that no candidate carries gets a reason instead of a silent null. */
220
+ function unmetMetricDiagnostics(scenarios, surface, requested) {
221
+ const output = [];
222
+ const candidates = scenarios.flatMap((scenario) => scenario.candidates);
223
+ const timed = surface.adapter.id === 'event_mean_time_to_happen';
224
+ const pending = candidates.some(({ eligibility }) => eligibility === 'unresolved') ||
225
+ scenarios.some(({ unresolved }) => unresolved.length > 0);
226
+ const reasonFor = (metric) => {
227
+ if (candidates.some((candidate) => {
228
+ if (metric === 'conditional_probability')
229
+ return (candidate.conditionalProbability !== undefined &&
230
+ candidate.conditionalProbability !== null);
231
+ if (metric === 'cumulative_chance')
232
+ return candidate.cumulativeChance !== undefined;
233
+ if (metric === 'effective_mtth_days')
234
+ return candidate.effectiveMtthDays !== undefined;
235
+ return candidate.rawValue !== undefined && candidate.rawValue !== null;
236
+ }))
237
+ return undefined;
238
+ if (metric === 'conditional_probability') {
239
+ if (surface.adapter.selectionRule === 'score_only')
240
+ return `${surface.adapter.id} is score-only, so its weights are not normalized into probabilities`;
241
+ if (timed)
242
+ return 'a mean time to happen is a timing model with no categorical probability; use cumulative_chance with horizonDays';
243
+ if (!surface.poolComplete && surface.adapter.completePoolRequired)
244
+ return 'the candidate pool is not proven complete';
245
+ }
246
+ if (metric === 'cumulative_chance' || metric === 'effective_mtth_days') {
247
+ if (!timed)
248
+ return `${surface.adapter.id} has no timing model`;
249
+ if (metric === 'cumulative_chance' &&
250
+ scenarios.every(({ horizonDays }) => horizonDays === undefined))
251
+ return 'cumulative_chance needs horizonDays, the number of days to accumulate over';
252
+ }
253
+ return pending
254
+ ? 'a condition or value in the source needs a scenario fact that was not declared (see missingInputs)'
255
+ : 'the adapter did not produce this metric for the evaluated candidates';
256
+ };
257
+ for (const metric of requested ?? []) {
258
+ const reason = reasonFor(metric);
259
+ if (reason !== undefined)
260
+ output.push({
261
+ code: 'PROBABILITY_METRIC_NOT_COMPUTED',
262
+ severity: 'warning',
263
+ category: 'validation',
264
+ message: `${metric} was requested but not computed: ${reason}`,
265
+ details: { metric, adapterId: surface.adapter.id },
266
+ });
267
+ }
268
+ return output;
269
+ }
213
270
  function diagnosticsFor(scenarios, surface, extra = {}) {
214
- const diagnostics = [];
271
+ const diagnostics = [
272
+ ...unmetMetricDiagnostics(scenarios, surface, extra.requestedMetrics),
273
+ ];
215
274
  const thresholds = resolvedThresholds(extra.diagnosticThresholds);
216
275
  if (!surface.poolComplete && surface.adapter.completePoolRequired)
217
276
  diagnostics.push({
@@ -895,15 +954,23 @@ export class ProbabilityAnalyzer {
895
954
  adapter: surface.adapter,
896
955
  scenarios,
897
956
  ...(prevalenceAggregate === undefined ? {} : { prevalenceAggregate }),
898
- diagnostics: diagnosticsFor(scenarios, surface, {
899
- ...(extra.sweep === undefined ? {} : { sweep: extra.sweep }),
900
- ...(extra.simulation === undefined ? {} : { simulation: extra.simulation }),
901
- ...(extra.acceptanceBands === undefined ? {} : { acceptanceBands: extra.acceptanceBands }),
902
- ...(extra.diagnosticThresholds === undefined
903
- ? {}
904
- : { diagnosticThresholds: extra.diagnosticThresholds }),
905
- ...(extra.unresolved === undefined ? {} : { unresolved: extra.unresolved }),
906
- }),
957
+ diagnostics: [
958
+ ...diagnosticsFor(scenarios, surface, {
959
+ ...(metadata.requestedMetrics === undefined
960
+ ? {}
961
+ : { requestedMetrics: metadata.requestedMetrics }),
962
+ ...(extra.sweep === undefined ? {} : { sweep: extra.sweep }),
963
+ ...(extra.simulation === undefined ? {} : { simulation: extra.simulation }),
964
+ ...(extra.acceptanceBands === undefined
965
+ ? {}
966
+ : { acceptanceBands: extra.acceptanceBands }),
967
+ ...(extra.diagnosticThresholds === undefined
968
+ ? {}
969
+ : { diagnosticThresholds: extra.diagnosticThresholds }),
970
+ ...(extra.unresolved === undefined ? {} : { unresolved: extra.unresolved }),
971
+ }),
972
+ ...(extra.diagnostics ?? []),
973
+ ],
907
974
  unresolved,
908
975
  ...(extra.sweep === undefined ? {} : { sweep: extra.sweep }),
909
976
  ...(extra.simulation === undefined ? {} : { simulation: extra.simulation }),
@@ -1205,9 +1272,22 @@ export class ProbabilityAnalyzer {
1205
1272
  const analyzed = await this.analyzeUnstored('sweep', request, { sweep: request.sweep });
1206
1273
  if (analyzed.result.operation === 'sweep' && analyzed.result.sweep !== undefined)
1207
1274
  return this.store(analyzed.result, request.outputs ?? ['json', 'sensitivity'], false, request.signal, request.principal);
1208
- const sweep = sweepSurface(analyzed.surface, request.scenarioSet.scenarios, analyzed.definitions, request.sweep, request.signal);
1275
+ const { defaultedRanges, ...sweep } = sweepSurface(analyzed.surface, request.scenarioSet.scenarios, analyzed.definitions, request.sweep, request.signal);
1209
1276
  const result = this.buildResult('sweep', analyzed.result.metadata, analyzed.surface, analyzed.result.scenarios, {
1210
1277
  sweep,
1278
+ ...(defaultedRanges.length === 0
1279
+ ? {}
1280
+ : {
1281
+ diagnostics: [
1282
+ {
1283
+ code: 'PROBABILITY_SWEEP_RANGE_DEFAULTED',
1284
+ severity: 'info',
1285
+ category: 'configuration',
1286
+ message: 'No range or alternatives were declared for some sweep paths, so the requested steps were spread from zero to twice the current value; declare uncertainInputs to choose the range',
1287
+ details: { ranges: defaultedRanges },
1288
+ },
1289
+ ],
1290
+ }),
1211
1291
  ...(request.acceptanceBands === undefined
1212
1292
  ? {}
1213
1293
  : { acceptanceBands: request.acceptanceBands }),
@@ -152,9 +152,9 @@ function decisionCandidates(context, adapterId) {
152
152
  eventKeys.has(ancestors[0].key) ||
153
153
  ignored.has(assignment.key.value))
154
154
  continue;
155
+ // days_remove is not a mission marker: ordinary decisions often carry days_remove = -1.
155
156
  const mission = firstScalar(assignment.value, 'is_mission')?.value === 'yes' ||
156
- firstScalar(assignment.value, 'days_mission_timeout') !== undefined ||
157
- firstScalar(assignment.value, 'days_remove') !== undefined;
157
+ firstScalar(assignment.value, 'days_mission_timeout') !== undefined;
158
158
  if ((adapterId === 'mission_ai_will_do') !== mission)
159
159
  continue;
160
160
  const weight = childBlocks(assignment.value, 'ai_will_do')[0];
@@ -2,7 +2,13 @@ import { ServiceError } from '../core/result.js';
2
2
  import { conditionBreakpointValues, evaluateSurfaceScenarios } from './evaluation.js';
3
3
  import { scenarioPathValue, withScenarioPathValue } from './scenario-state.js';
4
4
  const MAX_SWEEP_POINTS = 250_000;
5
- function declaredValues(surface, scenario, path, steps) {
5
+ /** From zero to twice the current value, so the declared value sits in the middle of the sweep. */
6
+ function defaultRange(current) {
7
+ if (current === 0)
8
+ return { min: 0, max: 1 };
9
+ return current > 0 ? { min: 0, max: current * 2 } : { min: current * 2, max: 0 };
10
+ }
11
+ function declaredValues(surface, scenario, path, steps, defaulted) {
6
12
  const uncertain = scenario.uncertainInputs?.find((input) => input.path === path);
7
13
  if (uncertain?.range !== undefined)
8
14
  return [
@@ -17,8 +23,14 @@ function declaredValues(surface, scenario, path, steps) {
17
23
  return [...new Set(values)].sort((left, right) => left - right);
18
24
  }
19
25
  const current = scenarioPathValue(scenario, path);
20
- if (typeof current === 'number')
21
- return [current];
26
+ if (typeof current === 'number') {
27
+ // Only a current value is declared. Sweeping it as one point would ignore the requested
28
+ // steps, so spread them over a default range and report the range that was chosen.
29
+ const range = defaultRange(current);
30
+ if (!defaulted.some((item) => item.scenarioId === scenario.id && item.path === path))
31
+ defaulted.push({ scenarioId: scenario.id, path, current, ...range });
32
+ return values(range, steps);
33
+ }
22
34
  throw new ServiceError('PROBABILITY_SWEEP_RANGE_REQUIRED', 'Every sweep path requires a scenario range, numeric alternatives, or numeric state value', { scenarioId: scenario.id, path });
23
35
  }
24
36
  function values(range, steps) {
@@ -217,14 +229,15 @@ export function sweepSurface(surface, scenarios, definitions, request, signal) {
217
229
  limit: MAX_SWEEP_POINTS,
218
230
  });
219
231
  const points = [];
232
+ const defaultedRanges = [];
220
233
  for (const scenario of scenarios) {
221
234
  if (request.pairwise && request.paths.length > 1) {
222
235
  for (let leftIndex = 0; leftIndex < request.paths.length; leftIndex += 1) {
223
236
  for (let rightIndex = leftIndex + 1; rightIndex < request.paths.length; rightIndex += 1) {
224
237
  const leftPath = request.paths[leftIndex];
225
238
  const rightPath = request.paths[rightIndex];
226
- const leftValues = declaredValues(surface, scenario, leftPath, request.steps);
227
- const rightValues = declaredValues(surface, scenario, rightPath, request.steps);
239
+ const leftValues = declaredValues(surface, scenario, leftPath, request.steps, defaultedRanges);
240
+ const rightValues = declaredValues(surface, scenario, rightPath, request.steps, defaultedRanges);
228
241
  for (const left of leftValues) {
229
242
  for (const right of rightValues) {
230
243
  if ((points.length & 1023) === 0)
@@ -242,7 +255,7 @@ export function sweepSurface(surface, scenarios, definitions, request, signal) {
242
255
  }
243
256
  else {
244
257
  for (const path of request.paths) {
245
- for (const value of declaredValues(surface, scenario, path, request.steps)) {
258
+ for (const value of declaredValues(surface, scenario, path, request.steps, defaultedRanges)) {
246
259
  if ((points.length & 1023) === 0)
247
260
  signal?.throwIfAborted();
248
261
  if (points.length >= MAX_SWEEP_POINTS)
@@ -265,5 +278,6 @@ export function sweepSurface(surface, scenarios, definitions, request, signal) {
265
278
  breakpoints,
266
279
  localElasticities: localElasticities(points),
267
280
  pairwiseInteractions: pairwiseInteractions(points),
281
+ defaultedRanges,
268
282
  };
269
283
  }