hoi4-agent-tools 4.15.0 → 4.17.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 (101) hide show
  1. package/CHANGELOG.md +33 -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 +153 -26
  7. package/dist/hoi4_agent_tools/core/scanner.js +148 -7
  8. package/dist/hoi4_agent_tools/core/server-state.js +50 -2
  9. package/dist/hoi4_agent_tools/core/source/localisation.js +7 -1
  10. package/dist/hoi4_agent_tools/event/compare.js +47 -13
  11. package/dist/hoi4_agent_tools/focus/importer.js +2 -5
  12. package/dist/hoi4_agent_tools/focus/lint.js +2 -5
  13. package/dist/hoi4_agent_tools/focus/model.js +19 -0
  14. package/dist/hoi4_agent_tools/focus/tool-operations.js +16 -1
  15. package/dist/hoi4_agent_tools/focus/tool-support.js +14 -0
  16. package/dist/hoi4_agent_tools/map/appearance-validation.js +6 -1
  17. package/dist/hoi4_agent_tools/map/engine-raster.js +160 -0
  18. package/dist/hoi4_agent_tools/map/model.js +9 -8
  19. package/dist/hoi4_agent_tools/map/operations.js +74 -2
  20. package/dist/hoi4_agent_tools/map/partition-provinces.js +6 -2
  21. package/dist/hoi4_agent_tools/map/partition-tuning.js +37 -0
  22. package/dist/hoi4_agent_tools/map/service.js +25 -12
  23. package/dist/hoi4_agent_tools/map/territory-operations.js +114 -3
  24. package/dist/hoi4_agent_tools/map/territory-quality.js +39 -0
  25. package/dist/hoi4_agent_tools/map/territory.js +63 -2
  26. package/dist/hoi4_agent_tools/map/tool-operations.js +27 -1
  27. package/dist/hoi4_agent_tools/map/validation.js +23 -3
  28. package/dist/hoi4_agent_tools/map/water.js +13 -10
  29. package/dist/hoi4_agent_tools/map/world-outputs.js +53 -25
  30. package/dist/hoi4_agent_tools/map/world.js +51 -1
  31. package/dist/hoi4_agent_tools/mcp/tools/map.js +23 -0
  32. package/dist/hoi4_agent_tools/mcp/tools/reference.js +2 -2
  33. package/dist/hoi4_agent_tools/mcp/tools/technology.js +25 -1
  34. package/dist/hoi4_agent_tools/reference/closure.js +65 -0
  35. package/dist/hoi4_agent_tools/reference/command-phrases.json +7899 -1127
  36. package/dist/hoi4_agent_tools/reference/operations.js +38 -21
  37. package/dist/hoi4_agent_tools/reference/ranking.js +77 -2
  38. package/dist/hoi4_agent_tools/reference/script-validation.js +4 -2
  39. package/dist/hoi4_agent_tools/reference/service.js +45 -2
  40. package/dist/hoi4_agent_tools/reference/source-lookup.js +43 -121
  41. package/dist/hoi4_agent_tools/runtime.js +27 -11
  42. package/dist/hoi4_agent_tools/schemas/lenient-arguments.js +7 -1
  43. package/dist/hoi4_agent_tools/schemas/map.js +41 -0
  44. package/dist/hoi4_agent_tools/schemas/mod-tools.js +49 -0
  45. package/dist/hoi4_agent_tools/schemas/reference.js +1 -1
  46. package/dist/hoi4_agent_tools/schemas/script-validation.js +57 -3
  47. package/dist/hoi4_agent_tools/technology/operations.js +5 -0
  48. package/dist/hoi4_agent_tools/technology/queries.js +54 -0
  49. package/dist/hoi4_agent_tools/version.js +1 -1
  50. package/docs/configuration.md +1 -1
  51. package/docs/map.md +14 -10
  52. package/docs/research/reference-benchmark.md +64 -0
  53. package/docs/tools.md +20 -20
  54. package/docs/troubleshooting.md +4 -0
  55. package/engine/bin/darwin-arm64/hoi4-engine +0 -0
  56. package/engine/bin/linux-arm64/hoi4-engine +0 -0
  57. package/engine/bin/linux-x64/hoi4-engine +0 -0
  58. package/engine/bin/manifest.json +8 -8
  59. package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
  60. package/npm-shrinkwrap.json +2 -2
  61. package/package.json +5 -3
  62. package/schemas/configuration.schema.json +1 -1
  63. package/schemas/continuous-focus-palette.schema.json +1 -1
  64. package/schemas/custom-weighted-pool.schema.json +1 -1
  65. package/schemas/decision-inspect-input.schema.json +1 -1
  66. package/schemas/error-log-input.schema.json +1 -1
  67. package/schemas/event-feature-manifest.schema.json +1 -1
  68. package/schemas/focus-plan.schema.json +1 -1
  69. package/schemas/focus-planning-sidecar.schema.json +1 -1
  70. package/schemas/geography-model.schema.json +1 -1
  71. package/schemas/gui-animation-source.schema.json +1 -1
  72. package/schemas/gui-helper.schema.json +1 -1
  73. package/schemas/gui-scenario.schema.json +1 -1
  74. package/schemas/helper-expansion-request.schema.json +1 -1
  75. package/schemas/helper-expansion-summary.schema.json +1 -1
  76. package/schemas/impact-inspect-input.schema.json +1 -1
  77. package/schemas/map-operation.schema.json +838 -728
  78. package/schemas/mechanic-test-input.schema.json +1 -1
  79. package/schemas/mod-index-input.schema.json +1 -1
  80. package/schemas/operation-result.schema.json +1 -1
  81. package/schemas/package-check-input.schema.json +1 -1
  82. package/schemas/package-manifest.schema.json +1 -1
  83. package/schemas/probability-analysis-result.schema.json +1 -1
  84. package/schemas/probability-compare-input.schema.json +1 -1
  85. package/schemas/probability-evaluate-input.schema.json +1 -1
  86. package/schemas/probability-inspect-input.schema.json +1 -1
  87. package/schemas/probability-render-input.schema.json +1 -1
  88. package/schemas/probability-scenario-set.schema.json +1 -1
  89. package/schemas/probability-sequence-input.schema.json +1 -1
  90. package/schemas/probability-simulate-input.schema.json +1 -1
  91. package/schemas/probability-sweep-input.schema.json +1 -1
  92. package/schemas/reference-context-input.schema.json +1 -1
  93. package/schemas/reference-read-input.schema.json +1 -1
  94. package/schemas/reference-search-input.schema.json +2 -2
  95. package/schemas/reference-sheets.schema.json +1 -1
  96. package/schemas/scenario-suite.schema.json +1 -1
  97. package/schemas/scenario-test-input.schema.json +1 -1
  98. package/schemas/script-validate-input.schema.json +7 -1
  99. package/schemas/shared-scenario.schema.json +1 -1
  100. package/schemas/source-lookup-input.schema.json +1 -1
  101. package/server.json +2 -2
@@ -120,6 +120,29 @@ const mapWorkspaceInspectDataSchema = z
120
120
  provinceGeometryPixelCount: nonNegativeIntegerSchema,
121
121
  provinceGeometryRowRunCount: nonNegativeIntegerSchema,
122
122
  lookupOnly: z.boolean().optional(),
123
+ /** The first 20 query matches, best first; the full list is in the linked artifact. */
124
+ matches: z
125
+ .array(z
126
+ .object({
127
+ kind: z.enum(['province', 'state', 'strategic-region']),
128
+ id: nonNegativeIntegerSchema,
129
+ key: z.string(),
130
+ name: z.string(),
131
+ })
132
+ .strict())
133
+ .max(20)
134
+ .optional(),
135
+ /** What each requested coordinate falls in (the first 20). */
136
+ coordinateMatches: z
137
+ .array(z
138
+ .object({
139
+ provinceId: nonNegativeIntegerSchema.nullable(),
140
+ stateIds: z.array(nonNegativeIntegerSchema).max(16),
141
+ regionIds: z.array(nonNegativeIntegerSchema).max(16),
142
+ })
143
+ .strict())
144
+ .max(20)
145
+ .optional(),
123
146
  unknownProvinceIds: z.array(nonNegativeIntegerSchema).max(512),
124
147
  missingGeometryProvinceIds: z.array(nonNegativeIntegerSchema).max(512),
125
148
  scriptReferences: z
@@ -19,7 +19,7 @@ export const referenceTools = [
19
19
  {
20
20
  name: 'hoi4.reference_search',
21
21
  title: 'Find a modding rule',
22
- description: 'Find the right modding rule in the offline wiki and installed game docs using ordinary words or script names. Each hit includes its file, lines, revision and answering line. Example: {"query":"add_timed_idea"}. Returns 6 hits by default (up to 12); read one with hoi4.reference_read using its id and revision.',
22
+ description: 'Find a modding rule in the offline wiki and installed game docs by plain words or script name. Returns up to 10 short candidates (limit up to 12) with file, lines, revision and, for a command, a one-line meaning and its scopes. Pick the one that fits, since several commands sound alike, then read it with hoi4.reference_read using its id and revision. Example: {"query":"add_timed_idea"} or {"query":"make a country hold elections now"}.',
23
23
  inputSchema: referenceSearchRequestSchema,
24
24
  outputSchema: strictOperationResultSchema(referenceSearchToolDataSchema),
25
25
  annotations: readOnly,
@@ -51,7 +51,7 @@ export const referenceTools = [
51
51
  {
52
52
  name: 'hoi4.script_validate',
53
53
  title: 'Check HOI4 script commands and scopes',
54
- description: 'Find broken syntax, commands and scopes in an effect, trigger or mod file using the installed docs. Unknown helpers and native argument blocks stay unresolved. Example: {"source":"add_political_power = 10","kind":"effect","scope":"country"} or {"path":"events/a.txt"}. Returns up to 12 findings.',
54
+ description: 'Find broken syntax, commands and scopes in an effect, trigger or mod file using the installed docs. Unknown helpers and native argument blocks stay unresolved. Example: {"source":"add_political_power = 10","kind":"effect","scope":"country"} or {"path":"events/a.txt"}. {"closure":true} instead counts whether the references of the whole mod resolve, per kind. Returns up to 12 findings.',
55
55
  inputSchema: scriptValidateRequestSchema,
56
56
  outputSchema: strictOperationResultSchema(scriptValidateDataSchema),
57
57
  annotations: readOnly,
@@ -45,6 +45,30 @@ const analysisDataSchema = z
45
45
  graphHash: sha256Schema,
46
46
  counts: countsSchema,
47
47
  helperExpansion: helperExpansionSummarySchema.optional(),
48
+ /** Mode explain: the technology, its direct neighbours and unlocks (20 names each at most). */
49
+ technology: z
50
+ .object({
51
+ id: z.string(),
52
+ path: z.string(),
53
+ line: z.number().int().min(0),
54
+ name: z.string().optional(),
55
+ startYear: z.string().optional(),
56
+ researchCost: z.string().optional(),
57
+ folders: z.array(z.string()),
58
+ categories: z.array(z.string()),
59
+ prerequisites: z.array(z.string()).max(20),
60
+ leadsTo: z.array(z.string()).max(20),
61
+ exclusiveWith: z.array(z.string()).max(20),
62
+ unlocks: z.array(z.object({ kind: z.string(), targetId: z.string() }).strict()).max(20),
63
+ allPrerequisites: nonNegativeIntegerSchema,
64
+ allDescendants: nonNegativeIntegerSchema,
65
+ unlockCount: nonNegativeIntegerSchema,
66
+ grantedBy: nonNegativeIntegerSchema,
67
+ issues: nonNegativeIntegerSchema,
68
+ truncated: z.boolean(),
69
+ })
70
+ .strict()
71
+ .optional(),
48
72
  })
49
73
  .strict();
50
74
  const renderOutputSchema = strictOperationResultSchema(z
@@ -93,7 +117,7 @@ export const technologyTaskTools = [
93
117
  {
94
118
  name: 'hoi4.tech_inspect',
95
119
  title: 'Inspect technology trees',
96
- description: 'Explain technology and doctrine paths, unlocks, bonuses and dependencies. Find layout or reference problems and compare revisions with mode compare. Example: {"mode":"explain","technologyId":"my_tech"}. Returns counts and the main findings inline; the full report is a linked resource.',
120
+ description: 'Explain technology and doctrine paths, unlocks, bonuses and dependencies. Find layout or reference problems and compare revisions with mode compare. Example: {"mode":"explain","technologyId":"my_tech"}. Returns counts inline, and for explain the prerequisites, what it leads to and its unlocks; the full report is a linked resource.',
97
121
  inputSchema: inspectInputSchema,
98
122
  outputSchema: analysisOutputSchema,
99
123
  annotations: readOnlyTechnologyTool,
@@ -0,0 +1,65 @@
1
+ import { defaultPatterns } from '../core/engine.js';
2
+ import { runEngineCommand } from '../core/engine-client.js';
3
+ import { ServiceError } from '../core/result.js';
4
+ import { closureEngineResponseSchema } from '../schemas/mod-tools.js';
5
+ import { modIndexEngineRequest, SOURCE_ROOT_KINDS } from './mod-index.js';
6
+ const CLOSURE_REQUEST_SCHEMA = 'hoi4-closure-request/1';
7
+ /** A cold index of the game, its DLC and a large mod, plus the semantic scan of the mod's sources. */
8
+ const CLOSURE_TIMEOUT_MS = 180_000;
9
+ /** One plain sentence on the closure, for the validation message. */
10
+ export function closureMessage(closure) {
11
+ const { resolved, unresolved, unknown } = closure.totals;
12
+ return `Closure ${closure.verdict}: ${resolved} resolved, ${unresolved} unresolved, ${unknown} unknown references in ${closure.sources} sources`;
13
+ }
14
+ /**
15
+ * The closure option of `hoi4.script_validate` (ADR 0083): whether the definitions the mod's own
16
+ * sources point at exist. The shared Rust engine indexes the game, its DLC and the mod, counts the
17
+ * mod's references per target kind and decides the verdict; a missing engine is
18
+ * `ENGINE_UNAVAILABLE`, never a TypeScript scan.
19
+ */
20
+ export async function checkClosure(engine, workspaceId, principal, signal) {
21
+ signal?.throwIfAborted();
22
+ await engine.resolver.refreshDescriptors(workspaceId, principal);
23
+ const workspace = engine.resolver.get(workspaceId, principal);
24
+ const answered = await runEngineCommand('closure', {
25
+ ...modIndexEngineRequest(workspace, engine.resolver.config(), SOURCE_ROOT_KINDS),
26
+ schema: CLOSURE_REQUEST_SCHEMA,
27
+ patterns: defaultPatterns(workspace),
28
+ }, closureEngineResponseSchema, { timeoutMs: CLOSURE_TIMEOUT_MS, ...(signal === undefined ? {} : { signal }) });
29
+ if (!answered.available)
30
+ throw new ServiceError('ENGINE_UNAVAILABLE', answered.message, { reason: answered.reason });
31
+ if (answered.outcome === 'invalid_request')
32
+ throw new ServiceError(answered.error.code, answered.error.message);
33
+ const response = answered.response;
34
+ const reasons = [];
35
+ if (response.totals.unknown > 0)
36
+ reasons.push(`${response.totals.unknown} references cannot be decided: their target is dynamic, a skipped source may define it, or a variable, flag or event target is read with no visible writer`);
37
+ if (!response.complete)
38
+ reasons.push(`The index skipped ${response.skippedSourceCount} sources that exceed a parsing limit, so a definition may be missing`);
39
+ if (!response.semanticComplete)
40
+ reasons.push('The reference scan skipped a source or reached its ceiling');
41
+ const closure = {
42
+ verdict: response.verdict,
43
+ revision: response.revision,
44
+ complete: response.complete,
45
+ semanticComplete: response.semanticComplete,
46
+ skippedSourceCount: response.skippedSourceCount,
47
+ sources: response.sources,
48
+ totals: response.totals,
49
+ kinds: response.kinds,
50
+ };
51
+ return {
52
+ valid: response.verdict === 'closed' ? true : response.verdict === 'unresolved' ? false : null,
53
+ checksPerformed: ['closure'],
54
+ parametersChecked: false,
55
+ findings: [],
56
+ totalFindings: 0,
57
+ omittedFindings: 0,
58
+ checkedCommands: 0,
59
+ unresolvedCount: 0,
60
+ truncated: false,
61
+ argumentBlocksUnchecked: 0,
62
+ ...(reasons.length === 0 ? {} : { partialReasons: reasons.slice(0, 5) }),
63
+ closure,
64
+ };
65
+ }