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
@@ -11,24 +11,71 @@ const MAX_COMMANDS = 256;
11
11
  const MAX_FILE_COMMANDS = 50_000;
12
12
  /** A block whose scope the file's structure does not determine; scope checks are skipped. */
13
13
  const UNKNOWN_SCOPE = 'unknown';
14
+ /**
15
+ * Commands whose arguments name a definition: the bare value (`add_ideas = X`, also a list
16
+ * `add_ideas = { X Y }`) or named fields of the argument block. From the effects and triggers
17
+ * documentation of 1.19.4.1.
18
+ */
19
+ const identifierArguments = {
20
+ add_ideas: { value: 'idea' },
21
+ remove_ideas: { value: 'idea' },
22
+ has_idea: { value: 'idea' },
23
+ add_timed_idea: { fields: { idea: 'idea' } },
24
+ modify_timed_idea: { fields: { idea: 'idea' } },
25
+ activate_decision: { value: 'decision' },
26
+ activate_targeted_decision: { fields: { decision: 'decision' } },
27
+ has_completed_focus: { value: 'focus' },
28
+ complete_national_focus: { value: 'focus' },
29
+ uncomplete_national_focus: { value: 'focus' },
30
+ has_tech: { value: 'technology' },
31
+ country_event: { value: 'event', fields: { id: 'event' } },
32
+ news_event: { value: 'event', fields: { id: 'event' } },
33
+ state_event: { value: 'event', fields: { id: 'event' } },
34
+ unit_leader_event: { value: 'event', fields: { id: 'event' } },
35
+ operative_leader_event: { value: 'event', fields: { id: 'event' } },
36
+ };
37
+ export const identifierArgumentCommands = new Set(Object.keys(identifierArguments));
38
+ /** Values that are computed or substituted, so their target cannot be read from source. */
39
+ const dynamicValue = /[[\]$@:]|^(?:yes|no)$/u;
14
40
  /**
15
41
  * Scope links from the wiki Scopes page: the scopes each link is usable in and the scope it
16
- * enters. The engine accepts these keys in any letter case.
42
+ * enters. The engine accepts these keys in any letter case. The game's documentation does not
43
+ * list scope links, so vanilla script that loads widens the wiki's list: vanilla 1.19.4.1 uses
44
+ * `controller` in country scope (common/decisions/ENG.txt, common/national_focus/sweden.txt)
45
+ * and `capital_scope` in state scope (common/decisions/SOV.txt).
17
46
  */
18
47
  const scopeLinks = {
19
48
  owner: { from: ['state', 'character', 'combatant'], to: 'country' },
20
- controller: { from: ['state'], to: 'country' },
21
- capital_scope: { from: ['country'], to: 'state' },
49
+ controller: { from: ['state', 'country'], to: 'country' },
50
+ capital_scope: { from: ['country', 'state'], to: 'state' },
22
51
  overlord: { from: ['country'], to: 'country' },
23
52
  faction_leader: { from: ['country'], to: 'country' },
24
53
  };
54
+ /** A scope a link can be compared with: a keyword chain, a country tag or a saved target. */
55
+ const scopeTargetPattern = /^(?:(?:ROOT|THIS|PREV|FROM|root|this|prev|from)(?:\.(?:ROOT|THIS|PREV|FROM|OWNER|CONTROLLER|root|this|prev|from|owner|controller))*|[A-Z][A-Z0-9]{2}|(?:event_target|var):[\w.@:]+)$/u;
56
+ /**
57
+ * The scope an event's trigger, immediate and options run in. In a unit leader event ROOT and
58
+ * THIS are the general and FROM is the country, yet country effects run there without a scope
59
+ * error (in-game check 2026-11-02, run26), as vanilla options use them; `unit_leader` accepts
60
+ * both kinds. An operative leader event runs in the operative (vanilla LaR_agent_events.txt).
61
+ */
25
62
  const eventScopes = {
26
63
  country_event: 'country',
27
64
  news_event: 'country',
28
65
  state_event: 'state',
29
- unit_leader_event: 'character',
66
+ unit_leader_event: 'unit_leader',
30
67
  operative_leader_event: 'character',
31
68
  };
69
+ /** A command or link documented for `scopes` is usable in `scope`. */
70
+ function scopeAccepts(scopes, scope) {
71
+ return (scopes.includes(scope) ||
72
+ (scope === 'unit_leader' && (scopes.includes('character') || scopes.includes('country'))));
73
+ }
74
+ /** Triggers that test what a scope link would enter, for links misused as triggers. */
75
+ const linkTriggers = {
76
+ owner: 'is_owned_by',
77
+ controller: 'is_controlled_by',
78
+ };
32
79
  const optionMetadata = new Set([
33
80
  'name',
34
81
  'ai_chance',
@@ -174,7 +221,7 @@ const iteratorParameters = new Set([
174
221
  'count',
175
222
  ]);
176
223
  /** Check only rules explicitly available from one selected documentation authority. */
177
- export async function validateScript(references, workspace, input, signal, file) {
224
+ export async function validateScript(references, workspace, input, signal, file, identifiers) {
178
225
  if (file === undefined && Buffer.byteLength(input.source ?? '', 'utf8') > 64_000)
179
226
  throw new ServiceError('SCRIPT_SOURCE_TOO_LARGE', 'Snippet exceeds 64000 UTF-8 bytes');
180
227
  const inventory = await references.inventory(workspace, signal, [input.documentation]);
@@ -268,6 +315,58 @@ export async function validateScript(references, workspace, input, signal, file)
268
315
  message: diagnostic.message.slice(0, 500),
269
316
  suggestions: [],
270
317
  });
318
+ /** Identifier sets in lower case, built once per kind. */
319
+ const foldedIds = new Map();
320
+ /** Reports identifier arguments of a native command that name nothing the workspace defines. */
321
+ const checkIdentifiers = (entry, kind, scope) => {
322
+ const rule = identifierArguments[entry.key.value];
323
+ if (rule === undefined || identifiers === undefined)
324
+ return;
325
+ const values = [];
326
+ if (entry.value.type === 'scalar' && rule.value !== undefined)
327
+ values.push({ node: entry, value: entry.value.value, target: rule.value });
328
+ else if (entry.value.type === 'block')
329
+ for (const child of entry.value.entries) {
330
+ if (child.type === 'scalar' && rule.value !== undefined)
331
+ values.push({ node: entry, value: child.value, target: rule.value });
332
+ else if (child.type === 'assignment' && child.value.type === 'scalar') {
333
+ const target = rule.fields?.[child.key.value];
334
+ if (target !== undefined)
335
+ values.push({ node: child, value: child.value.value, target });
336
+ }
337
+ }
338
+ for (const { node, value, target } of values) {
339
+ if (dynamicValue.test(value))
340
+ continue;
341
+ const known = identifiers.ids.get(target);
342
+ if (known === undefined || known.has(value))
343
+ continue;
344
+ // The game finds these ids without case: vanilla fires `NSB_news.2` for `nsb_news.2`, and
345
+ // Kaiserreich adds `spr_carlism1` for `SPR_carlism1`.
346
+ let lower = foldedIds.get(target);
347
+ if (lower === undefined)
348
+ foldedIds.set(target, (lower = new Set([...known].map((id) => id.toLowerCase()))));
349
+ if (lower.has(value.toLowerCase()))
350
+ continue;
351
+ const suggestions = value.length > 128
352
+ ? []
353
+ : [...known]
354
+ .filter((candidate) => Math.abs(candidate.length - value.length) <= 3)
355
+ .filter(() => suggestionBudget-- > 0)
356
+ .map((candidate) => ({ candidate, distance: editDistance(value, candidate) }))
357
+ .filter(({ distance }) => distance <= 3)
358
+ .sort((a, b) => a.distance - b.distance || a.candidate.localeCompare(b.candidate, 'en'))
359
+ .slice(0, 3)
360
+ .map(({ candidate }) => candidate);
361
+ report(node, kind, scope, {
362
+ code: 'SCRIPT_ARGUMENT_UNKNOWN_ID',
363
+ // The game loads the file and the command does nothing, as vanilla's own dangling ids show.
364
+ status: identifiers.complete ? 'warning' : 'unresolved',
365
+ message: `${entry.key.value} names ${target} ${value.slice(0, 256)}, which ${identifiers.complete ? 'no loaded file defines' : 'the indexed files do not define (the index is incomplete)'}`,
366
+ suggestions,
367
+ });
368
+ }
369
+ };
271
370
  const walk = (block, kind, scope, previous) => {
272
371
  for (const entry of block.entries) {
273
372
  signal?.throwIfAborted();
@@ -311,10 +410,29 @@ export async function validateScript(references, workspace, input, signal, file)
311
410
  walk(entry.value, kind, explicitScope ?? fixedScope, scope);
312
411
  continue;
313
412
  }
413
+ // `owner = ROOT` or `owner = GER` is not a trigger: the game drops it at load ("Unknown
414
+ // trigger-type: owner", in-game check 2026-11-02, run26) and the surrounding limit then
415
+ // passes. The trigger that tests the linked scope is named instead.
416
+ const compared = scopeLinks[raw.toLowerCase()];
417
+ if (compared !== undefined &&
418
+ kind === 'trigger' &&
419
+ entry.value.type === 'scalar' &&
420
+ entry.operator.text === '=' &&
421
+ scopeTargetPattern.test(entry.value.value)) {
422
+ checkedCommands++;
423
+ const replacement = linkTriggers[raw.toLowerCase()];
424
+ report(entry, kind, scope, {
425
+ code: 'SCRIPT_SCOPE_LINK_AS_TRIGGER',
426
+ status: 'error',
427
+ message: `${raw} is a scope link, not a trigger; the game drops it and the condition always passes${replacement === undefined ? '' : `. Use ${replacement} = ${entry.value.value.slice(0, 64)}`}`,
428
+ suggestions: replacement === undefined ? [] : [replacement],
429
+ });
430
+ continue;
431
+ }
314
432
  const link = entry.value.type === 'block' ? scopeLinks[raw.toLowerCase()] : undefined;
315
433
  if (link !== undefined && entry.value.type === 'block') {
316
434
  checkedCommands++;
317
- if (scope !== UNKNOWN_SCOPE && !link.from.includes(scope))
435
+ if (scope !== UNKNOWN_SCOPE && !scopeAccepts(link.from, scope))
318
436
  report(entry, kind, scope, {
319
437
  code: 'SCRIPT_SCOPE_LINK_WRONG_SCOPE',
320
438
  status: 'error',
@@ -388,7 +506,7 @@ export async function validateScript(references, workspace, input, signal, file)
388
506
  if (signature !== undefined) {
389
507
  const wrongScope = scope !== UNKNOWN_SCOPE &&
390
508
  !signature.scopes.includes('any') &&
391
- !signature.scopes.includes(scope);
509
+ !scopeAccepts(signature.scopes, scope);
392
510
  report(entry, kind, scope, {
393
511
  code: signature.conflict
394
512
  ? 'SCRIPT_DOCUMENTATION_CONFLICT'
@@ -404,6 +522,7 @@ export async function validateScript(references, workspace, input, signal, file)
404
522
  ? `Supported scopes: ${signature.scopes.join(', ')}`
405
523
  : 'Command kind and declared scope match the selected documentation',
406
524
  });
525
+ checkIdentifiers(entry, kind, scope);
407
526
  }
408
527
  const iterator = /^(?:every|random|any|all)_(?:(?:owned|controlled|neighbor)_)?(state|country)$/u.exec(name);
409
528
  if (entry.value.type !== 'block') {
@@ -517,6 +636,36 @@ export async function validateScript(references, workspace, input, signal, file)
517
636
  inventory.skipped > 0 ||
518
637
  (file === undefined ? catalogs[input.kind].size === 0 : plan.roots.length === 0) ||
519
638
  unknownScopeRoots > 0;
639
+ // A partial result names what is partial (#65), so `null` is never a bare "not sure".
640
+ const unknownScopeLines = plan.roots
641
+ .filter(({ scope }) => scope === UNKNOWN_SCOPE)
642
+ .slice(0, 8)
643
+ .map(({ block }) => locationFor(documentPath, document.lineIndex, block.start, block.end).start.line);
644
+ const partialReasons = [
645
+ ...(unresolvedCount > 0
646
+ ? [
647
+ `${unresolvedCount === 1 ? '1 command' : `${unresolvedCount} commands`} could not be resolved (see findings with status unresolved)`,
648
+ ]
649
+ : []),
650
+ ...(truncated ? [`only the first ${commandLimit} commands were checked`] : []),
651
+ ...(inventory.skipped > 0
652
+ ? [
653
+ `${inventory.skipped === 1 ? '1 documentation source' : `${inventory.skipped} documentation sources`} could not be read`,
654
+ ]
655
+ : []),
656
+ ...((file === undefined ? catalogs[input.kind].size === 0 : plan.roots.length === 0)
657
+ ? [
658
+ file === undefined
659
+ ? `the documentation lists no ${input.kind} commands`
660
+ : `no effect or trigger block of a known file family was found in ${file.path}`,
661
+ ]
662
+ : []),
663
+ ...(unknownScopeRoots > 0
664
+ ? [
665
+ `${unknownScopeRoots === 1 ? '1 block runs' : `${unknownScopeRoots} blocks run`} in a scope this file does not fix (a scripted helper or on_action, at line${unknownScopeLines.length === 1 ? '' : 's'} ${unknownScopeLines.join(', ')}${unknownScopeRoots > unknownScopeLines.length ? ' and more' : ''}), so scope rules were not applied there`,
666
+ ]
667
+ : []),
668
+ ];
520
669
  const order = { error: 0, unresolved: 1, warning: 2, supported: 3 };
521
670
  findings.sort((a, b) => order[a.status] - order[b.status] ||
522
671
  a.line - b.line ||
@@ -531,8 +680,9 @@ export async function validateScript(references, workspace, input, signal, file)
531
680
  ...(playerTextChecked ? ['player_text'] : []),
532
681
  ...(eventPopups === undefined ? [] : ['event_popups']),
533
682
  ...(knownMistakes === undefined ? [] : ['known_mistakes']),
683
+ ...(identifiers === undefined ? [] : ['identifier_arguments']),
534
684
  ],
535
- parametersChecked: false,
685
+ parametersChecked: identifiers !== undefined,
536
686
  documentation: {
537
687
  source: input.documentation,
538
688
  revision: hashCanonical([...sources].sort()),
@@ -547,6 +697,7 @@ export async function validateScript(references, workspace, input, signal, file)
547
697
  unresolvedCount,
548
698
  truncated,
549
699
  argumentBlocksUnchecked,
700
+ ...(partialReasons.length === 0 ? {} : { partialReasons }),
550
701
  ...(file === undefined
551
702
  ? {}
552
703
  : {
@@ -7,6 +7,7 @@ import { ServiceError } from '../core/result.js';
7
7
  import { isWithin } from '../core/workspace.js';
8
8
  import { prepareSource, verifySource, readBoundedFile, } from '../core/scanner.js';
9
9
  import { decodeSource } from '../core/source/encoding.js';
10
+ import commandPhrases from './command-phrases.json' with { type: 'json' };
10
11
  import { activeKnownMistakes } from './known-mistakes.js';
11
12
  import { readBoundedJsonLines } from './lines.js';
12
13
  import { commandTexts, readGameText } from './game-text.js';
@@ -224,6 +225,30 @@ const gameDocNames = {
224
225
  ai: ['common/ai_strategy/_documentation', 'documentation/triggers_documentation'],
225
226
  };
226
227
  const commandHeading = /^[a-z][a-z0-9_]*$/u;
228
+ /**
229
+ * Plain-word phrasings count this many times a game text word, because they name the
230
+ * command the way a question does rather than the way a tooltip labels it.
231
+ */
232
+ const PHRASE_WEIGHT = 4;
233
+ let phraseTerms;
234
+ /**
235
+ * The terms of `command-phrases.json`: four plain-word phrasings of each documented effect,
236
+ * trigger and modifier, such as "state on the coast" for `is_coastal`, written once from
237
+ * the command's documentation and in-game text (ADR 0078). A command the file does not
238
+ * name, such as one a later game version adds, keeps only its documentation and game text.
239
+ */
240
+ function phraseCards() {
241
+ if (phraseTerms !== undefined)
242
+ return phraseTerms;
243
+ phraseTerms = new Map();
244
+ for (const [name, phrases] of Object.entries(commandPhrases)) {
245
+ const card = new Map();
246
+ for (const term of phrases.flatMap((text) => textTerms(text)))
247
+ card.set(term, Math.min((card.get(term) ?? 0) + PHRASE_WEIGHT, 3 * PHRASE_WEIGHT));
248
+ phraseTerms.set(name, card);
249
+ }
250
+ return phraseTerms;
251
+ }
227
252
  /**
228
253
  * For each entry about one command, the words the game shows players for it: the installed
229
254
  * documentation says "check if state is coastal" and the tooltip "Is coastal"; a modifier
@@ -241,6 +266,14 @@ function commandCards(sections, gameText) {
241
266
  card.set(term, Math.min((card.get(term) ?? 0) + 1, 3));
242
267
  spoken.set(name, card);
243
268
  }
269
+ for (const [name, card] of phraseCards()) {
270
+ if (!commands.has(name))
271
+ continue;
272
+ const merged = new Map(spoken.get(name));
273
+ for (const [term, weight] of card)
274
+ merged.set(term, (merged.get(term) ?? 0) + weight);
275
+ spoken.set(name, merged);
276
+ }
244
277
  const cards = new Map();
245
278
  for (const section of sections) {
246
279
  if (section.terms.specialty !== undefined || section.terms.navigation)
@@ -150,6 +150,14 @@ export async function sourceLookup(engine, workspaceId, input, principal, signal
150
150
  path: entry.path,
151
151
  line: entry.location?.start.line ?? null,
152
152
  }));
153
+ // A complete index that neither defines nor uses the symbol answers not-found, never an
154
+ // empty success.
155
+ if (matchedDefinitions.length === 0 && matchedReferences.length === 0 && snapshot.complete) {
156
+ const suggestions = nearestNames(symbol, new Set(snapshot.index.symbols
157
+ .filter((entry) => input.kind === undefined || entry.kind === input.kind)
158
+ .map(({ id }) => id)));
159
+ throw new ServiceError('SYMBOL_NOT_FOUND', `No indexed file defines${input.includeReferences ? ' or uses' : ''} ${symbol.slice(0, 256)}${input.kind === undefined ? '' : ` as a ${input.kind}`}${suggestions.length === 0 ? '' : `; did you mean ${suggestions.join(', ')}?`}`, { symbol: symbol.slice(0, 256), suggestions });
160
+ }
153
161
  const result = {
154
162
  sourceScope: input.kind === 'event'
155
163
  ? input.includeReferences
@@ -94,6 +94,10 @@ export const focusRenderRequestSchema = z
94
94
  .boolean()
95
95
  .optional()
96
96
  .describe('Default true: add a PNG with decoded source icons. False returns only the faster HTML, SVG and JSON.'),
97
+ view: z
98
+ .enum(['full', 'game'])
99
+ .optional()
100
+ .describe('Default full. game: only the tree as the game draws it (PNG, hover map, zoomable HTML, inline overview), without the schematic; fast enough to call after every edit. Needs hoi4-engine.'),
97
101
  })
98
102
  .strict()
99
103
  .superRefine((value, context) => {
@@ -0,0 +1,142 @@
1
+ import { z } from 'zod/v4';
2
+ import { workspaceIdSchema } from './common.js';
3
+ /** `hoi4.idea_inspect`, answered by `hoi4-engine ideas` (ADR 0074). */
4
+ export const ideaInspectRequestSchema = z
5
+ .object({
6
+ workspaceId: workspaceIdSchema,
7
+ /** idea: a national spirit, law or advisor idea. character: a leader, advisor or commander. */
8
+ kind: z.enum(['idea', 'character']).default('idea'),
9
+ /** The idea or character to inspect. Leave it out with audit. */
10
+ id: z.string().min(1).max(256).optional(),
11
+ /** Check every idea or character the mod defines instead of one. */
12
+ audit: z.boolean().default(false),
13
+ /** One: mentions listed. Audit: examples kept per problem code. */
14
+ limit: z.number().int().min(1).max(50).default(5),
15
+ })
16
+ .strict()
17
+ .refine((input) => input.audit || input.id !== undefined, {
18
+ message: 'pass an id, or audit: true',
19
+ path: ['id'],
20
+ });
21
+ export const placeSchema = z
22
+ .object({
23
+ path: z.string().max(1024),
24
+ line: z.number().int().min(0),
25
+ layer: z.string().max(256),
26
+ layerKind: z.enum(['game', 'dlc', 'dependency', 'mod']),
27
+ })
28
+ .strict();
29
+ export const fieldSchema = z
30
+ .object({ name: z.string().max(128), text: z.string().max(2400), line: z.number().int() })
31
+ .strict();
32
+ export const problemSchema = z
33
+ .object({
34
+ code: z.string().max(64),
35
+ severity: z.enum(['warning', 'info']),
36
+ message: z.string().max(1200),
37
+ line: z.number().int().min(0),
38
+ })
39
+ .strict();
40
+ export const textSchema = z
41
+ .object({
42
+ language: z.string().max(64),
43
+ text: z.string().max(2400),
44
+ path: z.string().max(1024),
45
+ line: z.number().int().min(0),
46
+ layer: z.string().max(256),
47
+ layerKind: z.enum(['game', 'dlc', 'dependency', 'mod']),
48
+ replace: z.boolean(),
49
+ })
50
+ .strict();
51
+ /** One idea or character, as the engine answers it. */
52
+ export const ideaEngineInspectionSchema = z
53
+ .object({
54
+ kind: z.enum(['idea', 'character']),
55
+ id: z.string().max(256),
56
+ found: z.boolean(),
57
+ definitions: z.array(placeSchema).max(256),
58
+ category: z.string().max(128).optional(),
59
+ picture: z
60
+ .object({
61
+ sprite: z.string().max(512),
62
+ defined: z.boolean(),
63
+ texture: z.string().max(1024).nullable(),
64
+ textureExists: z.boolean().nullable(),
65
+ })
66
+ .strict()
67
+ .optional(),
68
+ modifiers: z
69
+ .array(z
70
+ .object({
71
+ block: z.string().max(64),
72
+ key: z.string().max(256),
73
+ value: z.string().max(256),
74
+ known: z.boolean(),
75
+ line: z.number().int(),
76
+ })
77
+ .strict())
78
+ .max(512)
79
+ .optional(),
80
+ fields: z.array(fieldSchema).max(128).optional(),
81
+ roles: z
82
+ .array(z
83
+ .object({
84
+ role: z.string().max(64),
85
+ instance: z.number().int().min(0).nullable(),
86
+ fields: z.array(fieldSchema).max(64),
87
+ traits: z
88
+ .array(z.object({ name: z.string().max(256), known: z.boolean() }).strict())
89
+ .max(64),
90
+ line: z.number().int(),
91
+ })
92
+ .strict())
93
+ .max(64)
94
+ .optional(),
95
+ portraits: z
96
+ .array(z
97
+ .object({ slot: z.string().max(64), value: z.string().max(1024), exists: z.boolean() })
98
+ .strict())
99
+ .max(128)
100
+ .optional(),
101
+ advisorOf: z.string().max(256).optional(),
102
+ texts: z
103
+ .array(z.object({ key: z.string().max(256), texts: z.array(textSchema).max(64) }).strict())
104
+ .max(4),
105
+ mentions: z
106
+ .array(z
107
+ .object({ path: z.string().max(1024), line: z.number().int(), layer: z.string() })
108
+ .strict())
109
+ .max(100),
110
+ mentionsTruncated: z.boolean(),
111
+ problems: z.array(problemSchema).max(256),
112
+ suggestions: z.array(z.string().max(256)).max(3).optional(),
113
+ })
114
+ .strict();
115
+ /** Every idea or character of the mod, as the engine answers an audit. */
116
+ export const ideaEngineAuditSchema = z
117
+ .object({
118
+ kind: z.enum(['idea', 'character']),
119
+ checked: z.number().int().min(0),
120
+ counts: z.record(z.string(), z.number().int().min(0)),
121
+ problems: z
122
+ .array(z
123
+ .object({
124
+ code: z.string().max(64),
125
+ severity: z.enum(['warning', 'info']),
126
+ id: z.string().max(256),
127
+ path: z.string().max(1024),
128
+ line: z.number().int().min(0),
129
+ message: z.string().max(1200),
130
+ })
131
+ .strict())
132
+ .max(1000),
133
+ truncated: z.boolean(),
134
+ })
135
+ .strict();
136
+ export const ideaInspectDataSchema = z
137
+ .object({
138
+ inspection: ideaEngineInspectionSchema.optional(),
139
+ audit: ideaEngineAuditSchema.optional(),
140
+ durationMs: z.number().int().min(0),
141
+ })
142
+ .strict();
@@ -0,0 +1,94 @@
1
+ import { z } from 'zod/v4';
2
+ import { workspaceIdSchema } from './common.js';
3
+ /** `hoi4.localisation_inspect`, answered by `hoi4-engine localisation` (ADR 0074). */
4
+ export const localisationInspectRequestSchema = z
5
+ .object({
6
+ workspaceId: workspaceIdSchema,
7
+ /** key: one key in every language. audit: the mod's problems. coverage: keys per language. */
8
+ mode: z.enum(['key', 'audit', 'coverage']).default('audit'),
9
+ key: z.string().min(1).max(256).optional(),
10
+ /** Restricts audit and coverage to one language, for example `german`. */
11
+ language: z
12
+ .string()
13
+ .regex(/^[a-z_]{2,32}$/u)
14
+ .optional(),
15
+ /** key: mentions listed. audit: examples kept per problem code. */
16
+ limit: z.number().int().min(1).max(50).default(5),
17
+ })
18
+ .strict()
19
+ .refine((input) => input.mode !== 'key' || input.key !== undefined, {
20
+ message: 'mode key needs a key',
21
+ path: ['key'],
22
+ });
23
+ const definitionSchema = z
24
+ .object({
25
+ language: z.string().max(64),
26
+ text: z.string().max(2400),
27
+ path: z.string().max(1024),
28
+ line: z.number().int().min(0),
29
+ layer: z.string().max(256),
30
+ layerKind: z.enum(['game', 'dlc', 'dependency', 'mod']),
31
+ replace: z.boolean(),
32
+ })
33
+ .strict();
34
+ const problemSchema = z
35
+ .object({
36
+ code: z.string().max(64),
37
+ severity: z.enum(['warning', 'info']),
38
+ key: z.string().max(256).nullable(),
39
+ language: z.string().max(64).nullable(),
40
+ path: z.string().max(1024),
41
+ line: z.number().int().min(0),
42
+ message: z.string().max(1200),
43
+ })
44
+ .strict();
45
+ /** The engine's answer, checked as it arrives. */
46
+ export const localisationEngineResponseSchema = z
47
+ .object({
48
+ mode: z.enum(['key', 'audit', 'coverage']),
49
+ shippedLanguages: z.array(z.string().max(64)).max(64),
50
+ supportedLanguages: z.array(z.string().max(64)).max(64),
51
+ mainLanguage: z.string().max(64).nullable(),
52
+ filesRead: z.number().int().min(0),
53
+ key: z
54
+ .object({
55
+ key: z.string().max(256),
56
+ found: z.boolean(),
57
+ definitions: z.array(definitionSchema).max(512),
58
+ missingLanguages: z.array(z.string().max(64)).max(64),
59
+ mentions: z
60
+ .array(z
61
+ .object({ path: z.string().max(1024), line: z.number().int(), layer: z.string() })
62
+ .strict())
63
+ .max(200),
64
+ mentionsTruncated: z.boolean(),
65
+ suggestions: z.array(z.string().max(256)).max(3).optional(),
66
+ })
67
+ .strict()
68
+ .optional(),
69
+ audit: z
70
+ .object({
71
+ counts: z.record(z.string(), z.number().int().min(0)),
72
+ problems: z.array(problemSchema).max(4000),
73
+ truncated: z.boolean(),
74
+ })
75
+ .strict()
76
+ .optional(),
77
+ coverage: z
78
+ .array(z
79
+ .object({
80
+ language: z.string().max(64),
81
+ files: z.number().int().min(0),
82
+ keys: z.number().int().min(0),
83
+ missing: z.number().int().min(0),
84
+ supported: z.boolean(),
85
+ })
86
+ .strict())
87
+ .max(64)
88
+ .optional(),
89
+ })
90
+ .strict();
91
+ /** The tool's data: the engine's answer with the problem examples bounded for the inline reply. */
92
+ export const localisationInspectDataSchema = localisationEngineResponseSchema.extend({
93
+ durationMs: z.number().int().min(0),
94
+ });
@@ -193,9 +193,9 @@ export const worldReferenceSchema = z
193
193
  export const worldEdgeSchema = z
194
194
  .object({
195
195
  mode: z
196
- .enum(['sea-band', 'rim', 'none'])
196
+ .enum(['sea-band', 'rim', 'wall', 'none'])
197
197
  .optional()
198
- .describe('sea-band (default when edge is given) clears land from the east and west edges and the poles to open sea; rim ends land at the seam in an impassable snow range with impassable adjacencies across the seam; none keeps the picture and warns about land cut by the wrapping seam.'),
198
+ .describe('sea-band (default when edge is given) clears land from the east and west edges and the poles to open sea; rim ends land at the seam in an impassable snow range with impassable adjacencies across the seam, but sea at the seam stays sailable; wall fills rimPx at the east and west edges with land over the full height, in impassable states, so nothing crosses the seam by land or sea; none keeps the picture and warns about land cut by the wrapping seam.'),
199
199
  bandPx: z
200
200
  .number()
201
201
  .int()
@@ -209,14 +209,42 @@ export const worldEdgeSchema = z
209
209
  .min(0)
210
210
  .max(1_024)
211
211
  .optional()
212
- .describe('North and south sea band in pixels; default 64, at most a quarter of the height.'),
212
+ .describe('North and south sea band in pixels; default 64, at most a quarter of the height. 0 lets land reach the top and bottom edges.'),
213
213
  rimPx: z
214
214
  .number()
215
215
  .int()
216
216
  .min(16)
217
217
  .max(2_048)
218
218
  .optional()
219
- .describe('Rim range width in pixels for mode rim; default 160, at most a quarter of the width.'),
219
+ .describe('Rim range or wall width in pixels for mode rim or wall; default 160 for rim and 48 for wall, at most a quarter of the width. The inner edge of the wall is ragged between 60% and 100% of it.'),
220
+ wallTerrain: z
221
+ .union([
222
+ z.literal('auto'),
223
+ z
224
+ .array(z
225
+ .object({
226
+ y0: z.number().int().min(0).max(16_384),
227
+ y1: z.number().int().min(0).max(16_384),
228
+ kind: z.enum([
229
+ 'snow',
230
+ 'mountain',
231
+ 'hills',
232
+ 'desert',
233
+ 'forest',
234
+ 'plains',
235
+ 'marsh',
236
+ 'jungle',
237
+ ]),
238
+ })
239
+ .strict()
240
+ .refine((segment) => segment.y1 >= segment.y0, {
241
+ message: 'y1 must not be above y0',
242
+ }))
243
+ .min(1)
244
+ .max(256),
245
+ ])
246
+ .optional()
247
+ .describe('Mode wall only: the look of the wall. auto (default) takes, for each row, the terrain of the nearest land the wall meets on that side, or snow toward the poles and mountain elsewhere where it meets only water, smoothed along the edge. A list of {y0, y1, kind} segments (rows counted from the top, inclusive) sets it by rows; uncovered rows fall back to auto.'),
220
248
  })
221
249
  .strict();
222
250
  /** Relief synthesis from a geography model (ADR 0056). */
@@ -35,6 +35,17 @@ export const errorLogDataSchema = z
35
35
  entries: z.number().int().min(0),
36
36
  })
37
37
  .strict(),
38
+ /**
39
+ * The mods the launch that wrote the log ran with, from `logs/system.log` of the same launch.
40
+ * Absent when that log is missing; `modLoaded` is absent when the mod has no descriptor name.
41
+ */
42
+ launch: z
43
+ .object({
44
+ activeMods: z.array(z.string().max(256)).max(64),
45
+ modLoaded: z.boolean().optional(),
46
+ })
47
+ .strict()
48
+ .optional(),
38
49
  scope: z.enum(['all', 'mod', 'unlocated']),
39
50
  totalEntries: z.number().int().min(0),
40
51
  distinctEntries: z.number().int().min(0),
@@ -63,8 +63,13 @@ export const scriptValidateDataSchema = z
63
63
  'player_text',
64
64
  'event_popups',
65
65
  'known_mistakes',
66
+ 'identifier_arguments',
66
67
  ])),
67
- parametersChecked: z.literal(false),
68
+ /**
69
+ * Identifier arguments (ideas, events, decisions, focuses, technologies) were checked against
70
+ * the workspace's definitions. Other argument values are not checked.
71
+ */
72
+ parametersChecked: z.boolean(),
68
73
  documentation: z
69
74
  .object({
70
75
  source: z.enum(['game_doc', 'script_doc']),
@@ -96,6 +101,8 @@ export const scriptValidateDataSchema = z
96
101
  unresolvedCount: z.number().int().min(0),
97
102
  truncated: z.boolean(),
98
103
  argumentBlocksUnchecked: z.number().int().min(0),
104
+ /** What made the result partial when `valid` is null, one plain sentence each. */
105
+ partialReasons: z.array(z.string().max(600)).max(5).optional(),
99
106
  file: z
100
107
  .object({
101
108
  path: z.string().max(4096),