hoi4-agent-tools 3.5.1 → 3.7.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 (72) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +137 -116
  3. package/dist/hoi4_agent_tools/core/engine.js +7 -7
  4. package/dist/hoi4_agent_tools/core/file-glob.js +164 -0
  5. package/dist/hoi4_agent_tools/core/index-segments.js +4 -0
  6. package/dist/hoi4_agent_tools/core/job-operation-registration.js +31 -0
  7. package/dist/hoi4_agent_tools/core/job-worker-host.js +27 -11
  8. package/dist/hoi4_agent_tools/core/job-worker.js +8 -16
  9. package/dist/hoi4_agent_tools/core/persistent-analysis-cache.js +37 -6
  10. package/dist/hoi4_agent_tools/core/scanner.js +133 -47
  11. package/dist/hoi4_agent_tools/core/source/cache.js +4 -0
  12. package/dist/hoi4_agent_tools/gui/layout.js +237 -11
  13. package/dist/hoi4_agent_tools/gui/renderer.js +36 -3
  14. package/dist/hoi4_agent_tools/gui/scenario.js +18 -0
  15. package/dist/hoi4_agent_tools/gui/studio.js +73 -21
  16. package/dist/hoi4_agent_tools/map/service.js +2 -2
  17. package/dist/hoi4_agent_tools/mcp/server/instructions.js +1 -1
  18. package/dist/hoi4_agent_tools/mcp/tools/reference.js +10 -1
  19. package/dist/hoi4_agent_tools/reference/lines.js +12 -0
  20. package/dist/hoi4_agent_tools/reference/operations.js +45 -2
  21. package/dist/hoi4_agent_tools/reference/script-validation.js +277 -0
  22. package/dist/hoi4_agent_tools/reference/service.js +139 -67
  23. package/dist/hoi4_agent_tools/reference/source-lookup.js +91 -15
  24. package/dist/hoi4_agent_tools/reference/source-navigation.js +130 -0
  25. package/dist/hoi4_agent_tools/schemas/reference.js +55 -0
  26. package/dist/hoi4_agent_tools/schemas/script-validation.js +69 -0
  27. package/dist/hoi4_agent_tools/version.js +1 -1
  28. package/docs/README.md +34 -18
  29. package/docs/examples.md +75 -0
  30. package/docs/gui.md +23 -0
  31. package/docs/reference.md +43 -2
  32. package/docs/research/reference-benchmark.md +41 -0
  33. package/docs/setup.md +50 -26
  34. package/docs/tools.md +65 -0
  35. package/npm-shrinkwrap.json +7088 -0
  36. package/package.json +10 -7
  37. package/schemas/configuration.schema.json +1 -1
  38. package/schemas/continuous-focus-palette.schema.json +1 -1
  39. package/schemas/custom-weighted-pool.schema.json +1 -1
  40. package/schemas/decision-inspect-input.schema.json +1 -1
  41. package/schemas/event-feature-manifest.schema.json +1 -1
  42. package/schemas/focus-plan.schema.json +1 -1
  43. package/schemas/focus-planning-sidecar.schema.json +1 -1
  44. package/schemas/gui-animation-source.schema.json +1 -1
  45. package/schemas/gui-helper.schema.json +1 -1
  46. package/schemas/gui-scenario.schema.json +139 -89
  47. package/schemas/helper-expansion-request.schema.json +1 -1
  48. package/schemas/helper-expansion-summary.schema.json +1 -1
  49. package/schemas/impact-inspect-input.schema.json +1 -1
  50. package/schemas/map-operation.schema.json +1 -1
  51. package/schemas/mechanic-test-input.schema.json +1 -1
  52. package/schemas/operation-result.schema.json +1 -1
  53. package/schemas/package-check-input.schema.json +1 -1
  54. package/schemas/package-manifest.schema.json +1 -1
  55. package/schemas/probability-analysis-result.schema.json +1 -1
  56. package/schemas/probability-compare-input.schema.json +1 -1
  57. package/schemas/probability-evaluate-input.schema.json +1 -1
  58. package/schemas/probability-inspect-input.schema.json +1 -1
  59. package/schemas/probability-render-input.schema.json +1 -1
  60. package/schemas/probability-scenario-set.schema.json +1 -1
  61. package/schemas/probability-sequence-input.schema.json +1 -1
  62. package/schemas/probability-simulate-input.schema.json +1 -1
  63. package/schemas/probability-sweep-input.schema.json +1 -1
  64. package/schemas/reference-context-input.schema.json +1 -1
  65. package/schemas/reference-read-input.schema.json +9 -1
  66. package/schemas/reference-search-input.schema.json +1 -1
  67. package/schemas/scenario-suite.schema.json +1 -1
  68. package/schemas/scenario-test-input.schema.json +1 -1
  69. package/schemas/script-validate-input.schema.json +92 -0
  70. package/schemas/shared-scenario.schema.json +1 -1
  71. package/schemas/source-lookup-input.schema.json +68 -2
  72. package/server.json +3 -3
@@ -26,6 +26,7 @@ export const referenceReadRequestSchema = z
26
26
  workspaceId: workspaceIdSchema,
27
27
  id: z.string().regex(/^[a-f0-9]{64}$/u),
28
28
  revision: z.string().regex(/^[a-f0-9]{64}$/u),
29
+ source: referenceSourceSchema.optional(),
29
30
  startLine: z.number().int().min(1).optional(),
30
31
  startColumn: z.number().int().min(1).optional(),
31
32
  maxLines: z.number().int().min(1).max(80).default(40),
@@ -39,6 +40,17 @@ export const referenceContextRequestSchema = z
39
40
  limit: z.number().int().min(1).max(24).default(16),
40
41
  })
41
42
  .strict();
43
+ export const sourceKeyPathSchema = z
44
+ .array(z.union([
45
+ z
46
+ .object({
47
+ key: z.string().min(1).max(1024),
48
+ occurrence: z.number().int().min(0).max(100_000).optional(),
49
+ })
50
+ .strict(),
51
+ z.object({ index: z.number().int().min(0).max(100_000) }).strict(),
52
+ ]))
53
+ .max(24);
42
54
  export const sourceLookupRequestSchema = z
43
55
  .object({
44
56
  workspaceId: workspaceIdSchema,
@@ -51,6 +63,10 @@ export const sourceLookupRequestSchema = z
51
63
  maxDefinitions: z.number().int().min(1).max(3).default(3),
52
64
  maxReferences: z.number().int().min(0).max(20).default(10),
53
65
  maxLines: z.number().int().min(1).max(80).default(30),
66
+ keyPath: sourceKeyPathSchema.optional(),
67
+ view: z.enum(['source', 'structure']).default('source'),
68
+ maxChildren: z.number().int().min(1).max(40).default(20),
69
+ childOffset: z.number().int().min(0).max(100_000).default(0),
54
70
  fromLine: z.number().int().min(1).optional(),
55
71
  fromColumn: z.number().int().min(1).optional(),
56
72
  expectedRevision: z
@@ -67,6 +83,7 @@ const coverage = z
67
83
  files: count,
68
84
  sections: count,
69
85
  unavailable: z.boolean(),
86
+ included: z.boolean(),
70
87
  })
71
88
  .strict();
72
89
  const coverageBySource = z
@@ -90,6 +107,8 @@ export const referenceSearchDataSchema = z
90
107
  .object({
91
108
  results: z.array(referenceSectionSchema.extend({ score: z.number() })).max(12),
92
109
  total: count,
110
+ omitted: count,
111
+ limitedByBytes: z.boolean(),
93
112
  coverage: coverageBySource,
94
113
  skipped: count,
95
114
  })
@@ -109,6 +128,7 @@ export const referenceContextDataSchema = z
109
128
  surface: referenceSurfaceSchema,
110
129
  sections: z.array(referenceSectionSchema).max(24),
111
130
  omitted: count,
131
+ limitedByBytes: z.boolean(),
112
132
  omittedSources: z.array(z.string().max(256)).max(32),
113
133
  missing: z.array(z.string().max(256)).max(32),
114
134
  coverage: coverageBySource,
@@ -117,10 +137,17 @@ export const referenceContextDataSchema = z
117
137
  .strict();
118
138
  export const sourceLookupDataSchema = z
119
139
  .object({
140
+ sourceScope: z.enum([
141
+ 'workspace_index',
142
+ 'event_definitions',
143
+ 'event_consumers',
144
+ 'helper_definitions',
145
+ ]),
120
146
  revision: hash,
121
147
  complete: z.boolean(),
122
148
  skippedSourceCount: count,
123
149
  definitionCount: count,
150
+ definitionsTruncated: z.boolean(),
124
151
  referencesIncluded: z.boolean(),
125
152
  referenceCount: count,
126
153
  referencesTruncated: z.boolean(),
@@ -143,6 +170,34 @@ export const sourceLookupDataSchema = z
143
170
  nextLine: line.nullable(),
144
171
  nextColumn: line.nullable(),
145
172
  text: z.string().max(2000),
173
+ navigation: z
174
+ .object({
175
+ keyPath: sourceKeyPathSchema,
176
+ startLine: line,
177
+ startColumn: line,
178
+ endLine: line,
179
+ endColumn: line,
180
+ children: z
181
+ .array(z
182
+ .object({
183
+ key: z.string().max(1024).nullable(),
184
+ index: count,
185
+ keyTruncated: z.boolean(),
186
+ occurrence: count,
187
+ kind: z.enum(['scalar', 'block']),
188
+ value: z.string().max(120).nullable(),
189
+ valueTruncated: z.boolean(),
190
+ startLine: line,
191
+ endLine: line,
192
+ childCount: count,
193
+ })
194
+ .strict())
195
+ .max(40),
196
+ omittedChildren: count,
197
+ nextChildOffset: count.nullable(),
198
+ })
199
+ .strict()
200
+ .optional(),
146
201
  })
147
202
  .strict())
148
203
  .max(3),
@@ -0,0 +1,69 @@
1
+ import { z } from 'zod/v4';
2
+ import { workspaceIdSchema } from './common.js';
3
+ import { referenceSectionSchema } from './reference.js';
4
+ const scope = z.enum([
5
+ 'country',
6
+ 'state',
7
+ 'character',
8
+ 'combatant',
9
+ 'ace',
10
+ 'strategic_region',
11
+ 'operation',
12
+ 'industrial_org',
13
+ 'purchase_contract',
14
+ 'raid_instance',
15
+ 'special_project',
16
+ 'faction',
17
+ ]);
18
+ export const scriptValidateRequestSchema = z
19
+ .object({
20
+ workspaceId: workspaceIdSchema,
21
+ source: z.string().min(1).max(64_000),
22
+ kind: z.enum(['effect', 'trigger']),
23
+ scope,
24
+ documentation: z.enum(['game_doc', 'script_doc']).default('game_doc'),
25
+ bindings: z
26
+ .array(z.object({ name: z.string().min(1).max(256), scope }).strict())
27
+ .max(16)
28
+ .default([]),
29
+ limit: z.number().int().min(1).max(32).default(12),
30
+ })
31
+ .strict();
32
+ export const scriptValidateDataSchema = z
33
+ .object({
34
+ valid: z.boolean().nullable(),
35
+ checksPerformed: z.array(z.enum(['syntax', 'command_kind', 'declared_scope'])),
36
+ parametersChecked: z.literal(false),
37
+ documentation: z
38
+ .object({
39
+ source: z.enum(['game_doc', 'script_doc']),
40
+ revision: z.string().regex(/^[a-f0-9]{64}$/u),
41
+ effectCount: z.number().int().min(0),
42
+ triggerCount: z.number().int().min(0),
43
+ skippedSources: z.number().int().min(0),
44
+ })
45
+ .strict(),
46
+ findings: z
47
+ .array(z
48
+ .object({
49
+ code: z.string().max(80),
50
+ status: z.enum(['supported', 'error', 'unresolved']),
51
+ command: z.string().max(256),
52
+ kind: z.enum(['effect', 'trigger']),
53
+ scope: z.string().max(64),
54
+ line: z.number().int().min(1),
55
+ column: z.number().int().min(1),
56
+ message: z.string().max(500),
57
+ suggestions: z.array(z.string().max(256)).max(3),
58
+ reference: referenceSectionSchema.optional(),
59
+ })
60
+ .strict())
61
+ .max(32),
62
+ totalFindings: z.number().int().min(0),
63
+ omittedFindings: z.number().int().min(0),
64
+ checkedCommands: z.number().int().min(0),
65
+ unresolvedCount: z.number().int().min(0),
66
+ truncated: z.boolean(),
67
+ argumentBlocksUnchecked: z.number().int().min(0),
68
+ })
69
+ .strict();
@@ -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 = '3.5.1';
3
+ export const PACKAGE_VERSION = '3.7.0';
4
4
  export const MCP_PROTOCOL_VERSION = LATEST_PROTOCOL_VERSION;
5
5
  export const CONFIG_VERSION = 1;
6
6
  export const TRANSACTION_VERSION = 1;
package/docs/README.md CHANGED
@@ -1,20 +1,36 @@
1
1
  # Documentation
2
2
 
3
- - [Setup](setup.md): install the server, configure HOI4 paths, and connect an MCP client.
4
- - [Local references](reference.md): retrieve cited offline wiki and installed documentation sections and exact source definitions.
5
- - [Event chains](events.md): inspect, trace, lint, render, and compare event chains.
6
- - [Cross-system impact and decisions](analysis.md): trace source consumers and evaluate decision or mission scenarios.
7
- - [Mechanic tests and scenario suites](mechanics.md): interpret declared effect steps, check package links, and run resumable cases.
8
- - [Technology trees](technology.md): inspect, trace, lint, render, and compare technologies and doctrines.
9
- - [Visual examples and comparison limits](visual-comparisons.md): real game captures beside MCP renders, with measured findings and limits.
10
- - [Interface examples and comparison limits](https://github.com/klimPaskov/hoi4-agent-tools/blob/main/docs/gui-comparisons.md): native-size vanilla and Chaos Redux windows, populated templates, scenarios, and provenance.
11
- - [Bounded helper expansion](helper-expansion.md): resume source-linked event and technology helper paths with exact coverage boundaries.
12
- - [Persistent jobs](jobs.md): run, inspect, cancel, and recover long operations.
13
- - [AI and MTTH analysis](probability.md): evaluate weighted logic, timing, uncertainty, sequences, and patches.
14
- - [Focus trees](focus.md): inspect, create, render, and clean national or continuous focus content.
15
- - [Scripted GUIs](gui.md): inspect linked UI source, render states, and create or repair GUIs.
16
- - [Maps](map.md): inspect and edit provinces, states, regions, adjacency, supply, and railways.
17
- - [HTTP](http.md): run the MCP server for shared or remote access.
18
- - [Development](development.md): build, test, and contribute.
19
-
20
- For vulnerability reporting, see the repository [Security Policy](../SECURITY.md).
3
+ Start with [Setup](setup.md), then try the [Examples](examples.md).
4
+ You can ask your coding agent for these tasks in ordinary language; you do not need to memorize tool names.
5
+
6
+ ## Choose a task
7
+
8
+ | I want to… | Read |
9
+ | ---------------------------------------------------- | ----------------------------------------- |
10
+ | Find a modding rule or a vanilla example | [Local references](reference.md) |
11
+ | Work on a focus tree | [Focus trees](focus.md) |
12
+ | Understand an event chain | [Events](events.md) |
13
+ | Trace dependencies or inspect decisions and missions | [Decisions and dependencies](analysis.md) |
14
+ | Preview a technology or doctrine tree | [Technology trees](technology.md) |
15
+ | Build or review an interface | [Scripted GUIs](gui.md) |
16
+ | Inspect or edit the map | [Maps](map.md) |
17
+ | Compare weights, chances or timing | [AI and probability](probability.md) |
18
+ | Test a mechanic or check a content package | [Mechanic tests](mechanics.md) |
19
+
20
+ ## See the results
21
+
22
+ - [Examples](examples.md): practical prompts with real renders.
23
+ - [Latest release](https://github.com/klimPaskov/hoi4-agent-tools/releases/latest): a short introduction to the published server.
24
+ - [Focus and technology comparisons](visual-comparisons.md): supplied game captures beside source renders.
25
+ - [Interface comparisons](gui-comparisons.md): vanilla and Chaos Redux windows.
26
+
27
+ ## Detailed reference
28
+
29
+ - [Tool reference](tools.md): tool names and what each one does.
30
+ - [Background jobs](jobs.md): inspect, cancel or retrieve long operations.
31
+ - [Large event and technology queries](helper-expansion.md): follow bounded results without losing coverage.
32
+ - [Remote hosting](http.md): share the server over HTTP.
33
+ - [Development](development.md): build, test and contribute.
34
+ - [Architecture decisions](adr/README.md): implementation rationale for contributors.
35
+
36
+ For vulnerability reporting, use the [security policy](../SECURITY.md).
@@ -0,0 +1,75 @@
1
+ # Examples
2
+
3
+ Start with a task you would normally give your coding agent.
4
+ The agent chooses the MCP tools and opens the resulting images or source references.
5
+ The renders below use actual Chaos Redux and installed HOI4 files; use names from your own mod when trying the prompts.
6
+
7
+ ## Find a rule without reading a whole wiki
8
+
9
+ > Find the installed documentation for `save_event_target_as`, read the relevant section, and show a vanilla usage. Keep the file and line references.
10
+
11
+ The reference tools find the section, read a small excerpt, and retain its source revision so the agent can return to it later.
12
+ In the [measured reference example](research/reference-benchmark.md), the search found the installed effect documentation first and a 12-line read supplied the command and supported scopes.
13
+ No wiki download or game launch was needed.
14
+
15
+ Use [Local references](reference.md) to configure an offline wiki snapshot or narrow a search.
16
+
17
+ ## Review a large tree
18
+
19
+ > Render the Utopia Manifesto focus tree. Check its branch connections, alternative prerequisites, missing references and crowded areas before suggesting edits.
20
+
21
+ [![Utopia Manifesto focus tree](images/comparisons/utopia-mcp.png)](images/comparisons/utopia-mcp.png)
22
+
23
+ Open the image at full size for the complete layout.
24
+ This example contains 124 focuses in the recorded source version.
25
+ The [focus guide](focus.md) covers inspecting, rendering and reorganizing trees.
26
+
27
+ ## Preview technology layouts and artwork
28
+
29
+ > Render the infantry technology folder using this mod and its installed game assets. Check card sizes, icons, prerequisite links and missing placements.
30
+
31
+ [![Infantry technology folder](images/comparisons/infantry-mcp.png)](images/comparisons/infantry-mcp.png)
32
+
33
+ The preview follows the loaded technology and GUI definitions, including wide equipment cards.
34
+ The [technology comparisons](visual-comparisons.md#technology-folders) also show a chemical folder rendered from a matching recorded source revision.
35
+ See the [technology guide](technology.md) for grants, bonuses and doctrine paths.
36
+
37
+ ## Inspect an interface before editing it
38
+
39
+ > Find the Video options window in the installed interface files. Render it with labelled control regions, then check its text, spacing and clipping.
40
+
41
+ | Supplied in-game capture | MCP source preview |
42
+ | ------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
43
+ | ![Video options in game](images/comparisons/gui/options-video-ingame.png) | ![Video options preview](images/comparisons/gui/options-video-mcp.png) |
44
+
45
+ For a mod window, ask for the same view at 100% and 125% UI scale and supply the state values needed by its controls.
46
+ Unknown state values must stay unresolved; a visible button alone does not establish that it is enabled in the game.
47
+ The [interface gallery](gui-comparisons.md) includes Škoda Priority, Chaos Redux Settings, Event Log, Chaos Meter, decisions and occupation views.
48
+
49
+ ## Locate map data and plan an edit
50
+
51
+ > Find Brandenburg by name, show it on the map, and inspect its provinces, neighbours and railway connections. Show the affected files before changing anything.
52
+
53
+ [![Map rendered from installed source](images/comparisons/source/map-mcp.png)](images/comparisons/source/map-mcp.png)
54
+
55
+ After reviewing the selection, you can ask for a specific change such as moving named provinces into a state or updating a railway path.
56
+ The map tools check connected records and preserve dated state history when the operation can be represented safely.
57
+ See [Maps](map.md) for supported edits.
58
+
59
+ ## Trace an event or compare AI weights
60
+
61
+ > Trace this event's options and follow-up events. Point out unresolved calls and link each route to its source.
62
+
63
+ [![Chaos Redux event options](images/comparisons/source/event-chain-mcp.png)](images/comparisons/source/event-chain-mcp.png)
64
+
65
+ > Compare this decision's `ai_will_do` score before and after my change in peace and war. List missing conditions separately from known results.
66
+
67
+ Use [Events](events.md) for route graphs and [AI analysis](probability.md) for supported weights, chances and timing models.
68
+ A decision score is not automatically a percentage chance of an AI click.
69
+
70
+ ## About these examples
71
+
72
+ The images are source previews, not recordings of the server running the game.
73
+ Supplied game screenshots are identified separately and published with permission.
74
+ The [comparison pages](visual-comparisons.md) and [interface gallery](gui-comparisons.md) keep source details, reproducible inputs and known differences alongside the images.
75
+ The package does not include HOI4 or Chaos Redux source files or artwork.
package/docs/gui.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  Use `hoi4.gui_inspect`, `hoi4.gui_render`, and `hoi4.gui_rewrite` for `.gui`, `.gfx`, `common/scripted_guis`, localisation, sprites, fonts, and linked decision entry points.
4
4
 
5
+ ## Start with a preview
6
+
7
+ > Render this window at 100% and 125% UI scale. Show its control regions and list the state inputs needed to establish visibility and availability.
8
+
9
+ The [interface examples](gui-comparisons.md) show real vanilla and Chaos Redux windows.
10
+ Cyan click regions have confirmed availability under the supplied scenario.
11
+ Dashed amber regions are potential controls with unresolved visibility or enabling conditions; they do not count as confirmed branch coverage.
12
+ The scene retains the reason so the agent can supply the missing facts instead of guessing.
13
+ These are source-model results, not proof of native click execution.
14
+
15
+ ## Preview immediate tooltip text
16
+
17
+ An explicit tooltip request uses a visible element's `pdx_tooltip` localisation key. Supply `tooltip.target` with its inspected instance ID or a unique element name, plus viewport `x`, `y`, `width` and `padding` values.
18
+
19
+ Position, width and padding are declared viewport pixels; height follows the measured text.
20
+ The preview uses the loaded `ToolTip` sprite and `cg_16b` font.
21
+ Missing or ambiguous targets, hidden or unresolved visibility, missing text/assets, and bounds errors produce diagnostics without a guessed popup.
22
+ A visibly disabled control can still have tooltip text.
23
+
24
+ Engine-generated `[!element_action]` and `[!element_action_enabled]` descriptions are not invented.
25
+ If their exact text is known, supply the exact bracketed token as a string key in `scenario.values` or `scenario.scriptedGui`; otherwise the tooltip remains unresolved.
26
+ The preview does not establish native automatic positioning, frame composition, delayed timing or `click_to_front` behavior.
27
+
5
28
  ## Create a GUI
6
29
 
7
30
  `hoi4.gui_rewrite` can work from supported source, targeted patches, or structured helpers. Source and helper rewrites may include one bounded text package: the main `.gui` plus additional interface `.gui`/`.gfx`, configured GFX `.gfx`, `common/scripted_guis/*.txt`, and localisation `.yml` files. The package is path-checked, parsed, linked, rendered, validated, and applied together in one rewrite. Existing text encodings are retained, while localisation is always written as UTF-8 with BOM.
package/docs/reference.md CHANGED
@@ -15,9 +15,50 @@ Only Markdown headings and recognizable standalone names in generated `.log` fil
15
15
  ## Tools
16
16
 
17
17
  - `hoi4.reference_context`: request a surface such as `event`, `focus`, `technology`, `gui`, or `map`. It reserves citations for available installed documentation and offline wiki sources before adding further question matches. Supply `question` to select the best matching section within each required source. At a limit of two or more, both source kinds are represented when available; a one-result limit prioritizes installed documentation. `omittedSources` names required sources excluded by the result limit, while `missing` names sources absent from the configured roots. Increase the limit or search an omitted source directly before treating the bundle as sufficient. Citations are pointers and excerpts; read the pertinent sections before changing code.
18
- - `hoi4.reference_search`: search page names, headings, exact script tokens, and matching body lines. The default limit is six results and the maximum is twelve. Filter `sources` to `game_doc`, `wiki`, or `script_doc` when appropriate.
19
- - `hoi4.reference_read`: provide a search/context result's `id` and `revision`. Read up to 80 lines and 8,000 UTF-8 bytes. Continue with the returned `nextLine`, `nextColumn` as `startColumn`, and the same revision. Long source lines continue without losing characters. A changed source returns `REFERENCE_REVISION_STALE`.
18
+ - `hoi4.reference_search`: search page names, headings, exact script tokens, and matching body lines. The default limit is six results and the maximum is twelve. Filter `sources` to `game_doc`, `wiki`, or `script_doc` when appropriate. Only selected authorities are scanned; `coverage.included = false` means that an authority was excluded from this query, not that it is missing.
19
+ - `hoi4.reference_read`: provide a search/context result's `id` and `revision`. Optionally pass its `source` for a focused authority read; resident citations provide this hint automatically. Read up to 80 lines and 8,000 UTF-8 bytes, with JSON escaping also bounded. Continue with the returned `nextLine`, `nextColumn` as `startColumn`, and the same revision. Long source lines continue without losing characters. A changed source returns `REFERENCE_REVISION_STALE`.
20
20
  - `hoi4.source_lookup`: find exact definitions and indexed usages in the installed game and configured mod source. The response includes load order, override status, up to three source blocks bounded to 2,000 bytes each, a scan revision, and explicit reference counts and truncation. Follow `nextLine` and `nextColumn` as `fromLine` and `fromColumn`, with `expectedRevision`, to read more of the active definition.
21
+ - `hoi4.script_validate`: check a bounded effect or trigger body against installed native-command documentation. Supply the body in `source`, its `kind`, and its current `scope`. Results cover syntax, command kind, and declared scope, with exact documentation citations. They do not validate command parameters or prove game execution.
22
+
23
+ ## Navigate a definition
24
+
25
+ Use `view: "structure"` to list the immediate children of the active definition, then pass `keyPath` to select a nested block or scalar assignment.
26
+ Keyed path steps have a `key` and an optional zero-based `occurrence`; repeated keys require an explicit occurrence.
27
+ Use an `{ "index": 1 }` step to select an unkeyed array entry or a child with an unusually long key.
28
+ For example, `[{"key":"option","occurrence":1},{"key":"hidden_effect"}]` selects the second option's hidden effects.
29
+ Navigation reads exact parser boundaries, including when several assignments share a line.
30
+ If an identifier has multiple symbol kinds, supply `kind` before navigating it.
31
+ Override counts remain visible, while navigation selects the active definition.
32
+
33
+ Structure replies have at most 40 children.
34
+ They also have a byte ceiling, with `keyTruncated` and `valueTruncated` identifying shortened previews.
35
+ Continue with `navigation.nextChildOffset` as `childOffset`, retaining the same `keyPath`, query settings, and `expectedRevision`.
36
+ Source replies continue with `nextLine` and `nextColumn` as before.
37
+ Use `includeReferences: false` with an exact `event`, `scripted_effect`, or `scripted_trigger` kind when only the definition is needed; this limits scanning to that source family.
38
+ Enable references when looking for consumers across the workspace.
39
+ Event-consumer queries scan the source families supported by event reference analysis rather than unrelated presentation files.
40
+ `sourceScope` labels the scanned surface, and `definitionsTruncated` and reference omission fields identify bounded output.
41
+ Revisions describe the selected scan, so keep the scan settings unchanged during continuation.
42
+
43
+ ## Check native commands
44
+
45
+ `hoi4.script_validate` accepts a standalone effect or trigger body rather than an entire event or focus definition.
46
+ It recognizes documented control wrappers, conditional limits, country/state iterators, fixed country/state scopes, and the `ROOT`, `THIS`, and `PREV` traversal context.
47
+ Use `bindings` to declare external scope names such as `event_target:recipient` when their type is known.
48
+ Those bindings are supplied facts, not observed game state.
49
+
50
+ The default documentation authority is `game_doc`.
51
+ Use `documentation: "script_doc"` explicitly for a configured generated dump; the checker does not silently mix authorities or substitute wiki text for native signatures.
52
+ It reads supported scopes from `effects_documentation.md`, `triggers_documentation.md`, and corresponding `effect_docs.log`/`trigger_docs.log` files.
53
+
54
+ `valid: false` identifies a syntax, kind, or scope error.
55
+ `valid: null` identifies missing or conflicting documentation, an unresolved command/helper, an unchecked native argument block, or exhausted coverage.
56
+ `valid: true` applies only to `checksPerformed`; `parametersChecked` remains false.
57
+ Inspect the cited parameter syntax and use the relevant domain tools for broader validation.
58
+ Replies prioritize problems, bound `findings`, and report `omittedFindings`; execution is bounded to 256 visited entries and 64,000 UTF-8 source bytes.
59
+ Search and context replies also report `limitedByBytes` when metadata exceeds their reply budget.
60
+ Read omitted required sources with targeted calls rather than repeatedly requesting the same oversized bundle.
61
+ Reference text supports UTF-8, Windows-1252, and explicitly BOM-marked UTF-16; native engine source encoding rules remain separate.
21
62
 
22
63
  Example:
23
64
 
@@ -40,3 +40,44 @@ For the GUI question “Where are scripted GUI click effects and triggers define
40
40
  | 8 | Installed documentation and wiki | 0 | 5,926 | 339 |
41
41
 
42
42
  The default six-surface context bundles used 3,545–5,556 bytes including omission metadata. A smaller response is not sufficient evidence when `omittedSources` is nonempty: increase the limit or search and read those sources directly. The evaluation script fails when a compact budget drops a required source kind or silently omits its required-source pointers.
43
+
44
+ ## Source navigation and scan measurements
45
+
46
+ On 2026-10-03, `scripts/evaluate-source-tools.ts --game-only` selected the installed `political.1` definition, listed its options, read exactly `add_political_power = -100` from its first option, and checked that command against installed documentation.
47
+ The country-scope check succeeded and the state-scope check reported the documented mismatch.
48
+ The evaluation retained source and documentation revisions and compared repeated reference results for equality.
49
+
50
+ | Operation | Initial cache-enabled run | Scoped-cache run | Reply bytes |
51
+ | ------------------------------ | ------------------------: | ---------------: | ----------: |
52
+ | Cold event structure | 55,550 ms | 24,723 ms | 2,258 |
53
+ | Repeated nested read | 20,936 ms | 3,565 ms | 862 |
54
+ | Installed command check | 1,471 ms | 10,804 ms | 1,152 |
55
+ | Event-consumer lookup | Timed out at 180,002 ms | 145,532 ms | 1,363 |
56
+ | Repeated event-consumer lookup | Not completed in that run | 16,233 ms | 1,363 |
57
+
58
+ A separate run with persistent caching disabled completed the broader lookup in 102,437 ms and its repeated lookup in 122,023 ms.
59
+ This helped identify filesystem and cache costs; it is not a causal comparison under identical machine load.
60
+ The candidate bounds optional cache writes, skips resident hydration, overlaps source verification, and scopes event queries to the analyser's supported owner sources.
61
+ Its persistent cache recorded 32 writes across two bounded batches, with no invalid entries or evictions.
62
+ The process recorded 616–625 MiB resident memory during the consumer lookups; these are sampled values, not peak-memory guarantees.
63
+
64
+ Other work was running on the host, and latency varied materially.
65
+ The command-document check was slower in the scoped-cache run, so these measurements must not be presented as an improvement for every operation or as a latency guarantee.
66
+ The selected source index was complete, while reference completeness remained false because 2,379 dynamic references were unresolved.
67
+ Static retrieval does not resolve those engine-dependent dispatches or establish runtime behavior.
68
+
69
+ These source timings preceded the subsequent batched reference reader and glob-library replacement.
70
+ A separate 2026-10-03 reference evaluation found all nine expected pages and answer-bearing sections and passed all eighteen compact-context cases, with no missing required sources or budget failures.
71
+ Its six context replies used 3,616–5,627 JSON bytes.
72
+ The candidate's complete MCP discovery list contains 35 tools and is tested against a 75 KiB ceiling.
73
+
74
+ ## Worker startup
75
+
76
+ Five isolated readiness handshakes on 2026-10-03 averaged 2,163 ms with eager imports and 1,408 ms with authenticated domain loading.
77
+ The individual samples were 2,056/2,570/2,349/1,857/1,985 ms and 3,213/930/995/960/942 ms respectively.
78
+ The first changed-worker sample includes a cold TypeScript loader cache.
79
+ These samples measure the readiness handshake without running a job, and do not establish complete request latency or throughput.
80
+ Concurrent HTTP qualification keeps its original four-minute total request ceiling.
81
+ Two earlier 64-request runs exceeded that ceiling for 23 and five requests respectively.
82
+ The isolated run after domain loading passed all 64 requests in a 124.49-second test, including fixture setup and cleanup.
83
+ Shared-host load varied between runs, so these are qualification receipts rather than a controlled throughput comparison.
package/docs/setup.md CHANGED
@@ -1,50 +1,74 @@
1
1
  # Setup
2
2
 
3
- For Codex, the supplied registration allows 120 seconds for startup and 600 seconds per tool call.
4
- Large source scans and GUI renders can take several minutes; keep selectors and scenario matrices bounded and use negotiated task support when available.
5
- `tool_timeout_sec` is the per-server tool deadline described in the [official configuration reference](https://developers.openai.com/ja-JP/docs/config-file/config-reference).
3
+ You need a coding agent that supports MCP and Node.js 22.19+ in the Node 22 line, or Node.js 24.
4
+ Keep an installed copy of Hearts of Iron IV available for vanilla references, artwork and fonts.
6
5
 
7
- HOI4 Agent Tools requires Node.js 22.19 or later in the Node 22 line, or Node.js 24.
8
-
9
- ## Install
6
+ ## 1. Install
10
7
 
11
8
  ```bash
12
9
  npm install --global hoi4-agent-tools
13
10
  ```
14
11
 
15
- Set the MCP process working directory to the mod being edited. The server creates its local workspace in memory, keeps generated artifacts in the per-user data directory, and starts without a config file. The installed game is detected when available for vanilla references; it is not required for source inspection or offline rendering.
12
+ Source inspection can work without an installed game.
13
+ Previews need the assets and fonts referenced by the mod; missing files are reported in the result.
14
+
15
+ ## 2. Connect your agent
16
+
17
+ ```bash
18
+ hoi4-agent-tools-setup --print-client-config
19
+ ```
20
+
21
+ Copy the printed `globalInstall` configuration into your MCP client, or use `codexTomlGlobal` for a TOML-based Codex configuration.
22
+ The printed command is correct for your platform.
23
+
24
+ Open the mod as your agent's workspace.
25
+ If your client does not supply workspace roots, set the MCP process working directory to that mod folder.
26
+ The server can then select the active mod without a separate configuration file.
27
+ It keeps indexes and generated images in your user data directory.
16
28
 
17
- When the MCP server starts with its working directory inside a mod, every focus, GUI, map, event, and technology call uses that mod automatically. Configured multi-mod or remote deployments can use explicit workspace selection.
29
+ ## 3. Try a small task
18
30
 
19
- Local startup accepts normal descriptor-based mods and sparse descriptor-less mods that contain standard HOI4 content folders. Empty roots need a `descriptor.mod` or an explicit configuration so the server does not guess an unrelated directory.
31
+ > Find the focus trees in this mod and render one of them.
20
32
 
21
- ## Optional persistent configuration
33
+ > Find the installed documentation for `save_event_target_as` and read only the relevant section.
22
34
 
23
- Use `--init` only when you need several mod roots, a fixed game path, or a shared/remote process:
35
+ Continue with the [examples guide](examples.md).
36
+ A mod normally has `descriptor.mod` or standard HOI4 content folders; an empty folder needs a descriptor or explicit configuration.
24
37
 
25
- ### Configure explicit paths
38
+ ## Choose game and mod paths
26
39
 
27
- Use explicit paths when discovery is incomplete or when you want to expose more than one mod root:
40
+ Use explicit paths if automatic discovery cannot find the game, or if you want to configure several mods:
28
41
 
29
42
  ```bash
30
- hoi4-agent-tools-setup --init --mod-root /projects/hoi4-mods --mod-root /workshop/hoi4-mods --game-root "/games/Hearts of Iron IV" --workspace-storage-root /var/lib/hoi4-agent-tools
43
+ hoi4-agent-tools-setup --init --mod-root "/projects/hoi4-mods" --game-root "/games/Hearts of Iron IV"
44
+ hoi4-agent-tools-setup --print-client-config
31
45
  ```
32
46
 
33
- - `--mod-root PATH` adds a parent folder containing mods. Repeat it for additional locations.
34
- - `--game-root PATH` selects the installed game folder used for vanilla references.
35
- - `--workspace-storage-root PATH` selects where indexes, renders, and other generated workspace files are stored.
36
- - `--config PATH` writes or reads a config at a custom path instead of the default per-user location.
47
+ `--mod-root` is a parent folder containing mod directories, not the game installation.
48
+ It can be repeated for several locations.
49
+ `--game-root` points to the installed game.
50
+ Use quoted Windows paths on Windows, for example `"C:/Program Files (x86)/Steam/steamapps/common/Hearts of Iron IV"`.
37
51
 
38
- The corresponding config fields are `modRoots`, `gameRoot`, and `workspaceStorageRoot`.
52
+ For a custom configuration location, add `--config PATH` to both setup commands.
53
+ `--workspace-storage-root PATH` chooses where generated indexes and images are saved.
54
+ Linked mod directories are not followed; configure their real parent directory instead.
39
55
 
40
- For a configured workspace, `wikiRoot` can select an absolute path to an offline Paradox Wiki snapshot and `scriptDocsRoot` can select an absolute path to a user-supplied generated documentation dump. Without these fields, the reference tools look for `paradox_wiki/` and `script_docs/` inside the mod. See [Local references](reference.md).
56
+ ## Add local reference material
41
57
 
42
- Linked directory entries are not followed. If a mod folder is a symlink or junction, configure the real parent directory as another `--mod-root`.
58
+ Place an offline wiki snapshot in `paradox_wiki/` inside the mod.
59
+ An optional generated documentation dump can go in `script_docs/`.
60
+ For a configured workspace, `wikiRoot` and `scriptDocsRoot` can point to other absolute directories.
61
+ The server reads these local files; it does not download the wiki.
62
+ See [Local references](reference.md) for source selection and missing-source reports.
43
63
 
44
- ## MCP client registration
64
+ ## Common problems
45
65
 
46
- ```bash
47
- hoi4-agent-tools-setup --print-client-config
48
- ```
66
+ | Problem | Check |
67
+ | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
68
+ | The agent cannot find a mod | Open the mod workspace, set the server working directory, or configure its real parent with `--mod-root`. |
69
+ | A render lacks icons or fonts | Confirm `--game-root` and the mod's asset paths. Read the missing-file findings. |
70
+ | A control's state is unresolved | Supply the scenario's required country, state, controller or variable inputs; do not assume a visible control is available. |
71
+ | A large query takes several minutes | Start with the specific tree, window or source area you need. Use [background jobs](jobs.md) when supported by your client. |
49
72
 
50
- Use the printed `globalInstall` or `codexTomlGlobal` entry. It is platform-correct and uses the default config without an environment variable. For a custom config, add `--config PATH` when printing the registration.
73
+ The supplied Codex registration allows 120 seconds for startup and 600 seconds per tool call.
74
+ For remote or shared deployments, use the [HTTP guide](http.md).
package/docs/tools.md ADDED
@@ -0,0 +1,65 @@
1
+ # Tool reference
2
+
3
+ Most users can ask their agent in ordinary language; the [examples guide](examples.md) is the best starting point.
4
+ This page lists exact tool names for agents and integrations.
5
+ Use the connected server's live schema for the fields accepted by each call.
6
+
7
+ | Tool | Purpose |
8
+ | --------------------------- | -------------------------------------------------------------------------------------------- |
9
+ | `hoi4.focus_inspect` | Read focus trees, continuous-focus placement, and structural or reference problems. |
10
+ | `hoi4.focus_render` | Produce fast HTML, SVG, JSON, and source-linked layout artifacts. |
11
+ | `hoi4.focus_raster` | Produce a PNG preview with decoded source icons. |
12
+ | `hoi4.focus_rewrite` | Create or update a focus tree. |
13
+ | `hoi4.gui_inspect` | Read a scripted GUI and its linked assets and logic. |
14
+ | `hoi4.gui_render` | Render generated and explicit GUI scenarios, states, resolutions, and layout diagnostics. |
15
+ | `hoi4.gui_rewrite` | Create or update a GUI source package. |
16
+ | `hoi4.map_inspect` | Search, click, navigate, and inspect the complete rendered map and its linked data. |
17
+ | `hoi4.map_render` | Render full-map layers, overlays, names, IDs, coordinates, and source-linked catalogs. |
18
+ | `hoi4.map_rewrite` | Create or update states, provinces, IDs, networks, positions, and connected map data. |
19
+ | `hoi4.reference_context` | Get compact, cited wiki and installed documentation pointers for a modding surface. |
20
+ | `hoi4.reference_search` | Search bounded local documentation sections. |
21
+ | `hoi4.reference_read` | Read one revision-bound section, with line continuation. |
22
+ | `hoi4.source_lookup` | Find exact definitions, overrides, usages, and narrow source blocks. |
23
+ | `hoi4.script_validate` | Check snippet syntax, native command kinds, and declared scopes against local documentation. |
24
+ | `hoi4.event_inspect` | Scan, trace, explain, lint, or assess event chains and their state flow. |
25
+ | `hoi4.event_render` | Render source-linked event routes, options, timing, state, scope, and unresolved edges. |
26
+ | `hoi4.event_compare` | Compare event-chain topology and diagnostics between revisions. |
27
+ | `hoi4.impact_inspect` | Trace symbol and changed-file consumers across source systems and compare proposals. |
28
+ | `hoi4.decision_inspect` | Inventory and evaluate decisions or missions under declared scenarios and source changes. |
29
+ | `hoi4.mechanic_test` | Execute bounded source effects on a copied declared scenario and check assertions. |
30
+ | `hoi4.package_check` | Check declarative package definitions, calls, registrations, assets, and case links. |
31
+ | `hoi4.scenario_test` | Run named source and domain cases in resumable, revision-bound batches. |
32
+ | `hoi4.job_inspect` | Inspect durable background work or retrieve its completed tool result. |
33
+ | `hoi4.job_cancel` | Durably request cancellation of authorized background work. |
34
+ | `hoi4.tech_inspect` | Scan, trace, explain, lint, and assess technology and doctrine systems. |
35
+ | `hoi4.tech_render` | Render source layouts with real item sizes and year guides, plus dependencies and assets. |
36
+ | `hoi4.tech_compare` | Compare technology graphs, placements, references, diagnostics, and source overlays. |
37
+ | `hoi4.probability_inspect` | Locate weighted logic and discover compatible adapters, candidates, and required inputs. |
38
+ | `hoi4.probability_evaluate` | Evaluate supported weights, probability and timing models, and missing inputs. |
39
+ | `hoi4.probability_sweep` | Find sensitivity, breakpoints, cliffs, and rank reversals across declared ranges. |
40
+ | `hoi4.probability_simulate` | Run deterministic sampled analysis with confidence and convergence data. |
41
+ | `hoi4.probability_sequence` | Analyze declared recovery, caps, cooldowns, resets, timers, and terminal states. |
42
+ | `hoi4.probability_compare` | Attribute AI-weight and MTTH changes between real or proposed source. |
43
+ | `hoi4.probability_render` | Render cached rankings, matrices, timing, sensitivity, sequence, and comparisons. |
44
+
45
+ ## Reading results
46
+
47
+ Inspect findings and missing inputs along with the image or result.
48
+ A rendered control does not by itself prove native availability, and a source simulation is not a game-engine receipt.
49
+ For reference searches, retain the cited file, lines and revision so you can reopen the same section.
50
+
51
+ Large results are returned as linked `hoi4-agent://` resources.
52
+ Follow `continuationUri` until it is `null`; clients can also request byte ranges with `?offset=<bytes>&length=<bytes>`.
53
+ Archive images you need to keep rather than relying on temporary server storage.
54
+
55
+ ## Longer operations
56
+
57
+ Clients that negotiate MCP tasks can retrieve a long operation after reconnecting.
58
+ Other clients receive the ordinary synchronous result.
59
+ Use `hoi4.job_inspect` to inspect an authorized job or retrieve its result, and `hoi4.job_cancel` to request cancellation.
60
+ See [Background jobs](jobs.md) for request keys, cancellation and recovery.
61
+
62
+ ## Optional ChaosX tools
63
+
64
+ Setting `HOI4_AGENT_TOOLS_CHAOSX=1` on the server process exposes `chaosx.focus_country_assets` and `chaosx.visual_revision`.
65
+ These workflow-specific tools are absent from the default public list.