hoi4-agent-tools 4.11.1 → 4.12.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 (78) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/bin/stdio.js +8 -10
  3. package/dist/hoi4_agent_tools/core/configuration.js +13 -0
  4. package/dist/hoi4_agent_tools/core/engine.js +18 -2
  5. package/dist/hoi4_agent_tools/core/job-store.js +1 -1
  6. package/dist/hoi4_agent_tools/focus/native-effects.js +1 -1
  7. package/dist/hoi4_agent_tools/map/operations.js +37 -8
  8. package/dist/hoi4_agent_tools/map/references.js +87 -0
  9. package/dist/hoi4_agent_tools/map/relief/hydrology.js +7 -2
  10. package/dist/hoi4_agent_tools/map/relief/terrain-synthesis.js +1 -0
  11. package/dist/hoi4_agent_tools/map/service.js +13 -4
  12. package/dist/hoi4_agent_tools/map/tool-operations.js +6 -0
  13. package/dist/hoi4_agent_tools/map/world.js +168 -40
  14. package/dist/hoi4_agent_tools/mcp/plugins.js +74 -0
  15. package/dist/hoi4_agent_tools/mcp/server/create-modern-operations.js +7 -18
  16. package/dist/hoi4_agent_tools/mcp/transports/negotiated-stdio.js +64 -6
  17. package/dist/hoi4_agent_tools/probability/model.js +4 -4
  18. package/dist/hoi4_agent_tools/reference/mod-index.js +63 -65
  19. package/dist/hoi4_agent_tools/runtime.js +6 -2
  20. package/dist/hoi4_agent_tools/schemas/map.js +4 -0
  21. package/dist/hoi4_agent_tools/schemas/mod-tools.js +50 -0
  22. package/dist/hoi4_agent_tools/version.js +1 -1
  23. package/docs/configuration.md +10 -10
  24. package/docs/development.md +2 -0
  25. package/docs/jobs.md +1 -0
  26. package/docs/map.md +6 -2
  27. package/docs/reference.md +2 -0
  28. package/docs/research/probability-adapter-evidence.md +11 -1
  29. package/docs/tools.md +2 -3
  30. package/docs/troubleshooting.md +1 -1
  31. package/engine/bin/darwin-arm64/hoi4-engine +0 -0
  32. package/engine/bin/linux-arm64/hoi4-engine +0 -0
  33. package/engine/bin/linux-x64/hoi4-engine +0 -0
  34. package/engine/bin/manifest.json +8 -8
  35. package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
  36. package/npm-shrinkwrap.json +2 -2
  37. package/package.json +1 -1
  38. package/schemas/configuration.schema.json +154 -138
  39. package/schemas/continuous-focus-palette.schema.json +1 -1
  40. package/schemas/custom-weighted-pool.schema.json +1 -1
  41. package/schemas/decision-inspect-input.schema.json +1 -1
  42. package/schemas/error-log-input.schema.json +1 -1
  43. package/schemas/event-feature-manifest.schema.json +1 -1
  44. package/schemas/focus-plan.schema.json +1 -1
  45. package/schemas/focus-planning-sidecar.schema.json +1 -1
  46. package/schemas/geography-model.schema.json +1 -1
  47. package/schemas/gui-animation-source.schema.json +1 -1
  48. package/schemas/gui-helper.schema.json +1 -1
  49. package/schemas/gui-scenario.schema.json +1 -1
  50. package/schemas/helper-expansion-request.schema.json +1 -1
  51. package/schemas/helper-expansion-summary.schema.json +1 -1
  52. package/schemas/impact-inspect-input.schema.json +1 -1
  53. package/schemas/map-operation.schema.json +152 -138
  54. package/schemas/mechanic-test-input.schema.json +1 -1
  55. package/schemas/mod-index-input.schema.json +1 -1
  56. package/schemas/operation-result.schema.json +1 -1
  57. package/schemas/package-check-input.schema.json +1 -1
  58. package/schemas/package-manifest.schema.json +1 -1
  59. package/schemas/probability-analysis-result.schema.json +1 -1
  60. package/schemas/probability-compare-input.schema.json +1 -1
  61. package/schemas/probability-evaluate-input.schema.json +1 -1
  62. package/schemas/probability-inspect-input.schema.json +1 -1
  63. package/schemas/probability-render-input.schema.json +1 -1
  64. package/schemas/probability-scenario-set.schema.json +1 -1
  65. package/schemas/probability-sequence-input.schema.json +1 -1
  66. package/schemas/probability-simulate-input.schema.json +1 -1
  67. package/schemas/probability-sweep-input.schema.json +1 -1
  68. package/schemas/reference-context-input.schema.json +1 -1
  69. package/schemas/reference-read-input.schema.json +1 -1
  70. package/schemas/reference-search-input.schema.json +1 -1
  71. package/schemas/reference-sheets.schema.json +1 -1
  72. package/schemas/scenario-suite.schema.json +1 -1
  73. package/schemas/scenario-test-input.schema.json +1 -1
  74. package/schemas/script-validate-input.schema.json +1 -1
  75. package/schemas/shared-scenario.schema.json +1 -1
  76. package/schemas/source-lookup-input.schema.json +1 -1
  77. package/server.json +2 -2
  78. package/dist/hoi4_agent_tools/mcp/tools/chaosx.js +0 -509
@@ -1,30 +1,57 @@
1
+ import { defaultPatterns } from '../core/engine.js';
2
+ import { runEngineCommand } from '../core/engine-client.js';
1
3
  import { ServiceError } from '../core/result.js';
2
4
  import { readModDescriptor } from '../core/workspace.js';
5
+ import { modIndexEngineResponseSchema, } from '../schemas/mod-tools.js';
3
6
  const MAX_NAMESPACES = 200;
4
7
  const MAX_FOLDERS = 60;
5
- /** Event namespaces with their numbered range, from `namespace.N` event IDs. */
6
- function namespaces(symbols) {
7
- const byNamespace = new Map();
8
- for (const symbol of symbols) {
9
- if (symbol.kind !== 'event')
10
- continue;
11
- const match = /^(.+)\.(\d{1,9})$/u.exec(symbol.id);
12
- if (match === null)
13
- continue;
14
- const entry = byNamespace.get(match[1]) ?? { numbers: [], files: new Set() };
15
- entry.numbers.push(Number(match[2]));
16
- entry.files.add(symbol.path);
17
- byNamespace.set(match[1], entry);
18
- }
19
- return [...byNamespace]
20
- .map(([namespace, { numbers, files }]) => ({
21
- namespace,
22
- events: new Set(numbers).size,
23
- lowest: Math.min(...numbers),
24
- highest: Math.max(...numbers),
25
- files: files.size,
26
- }))
27
- .sort((left, right) => left.namespace.localeCompare(right.namespace, 'en'));
8
+ /** A cold index of the game, its DLC and a large mod. */
9
+ const MOD_INDEX_TIMEOUT_MS = 180_000;
10
+ const MOD_INDEX_REQUEST_SCHEMA = 'hoi4-mod-index-request/1';
11
+ /** The roots the shared scan reads; artifacts and caches are never sources. */
12
+ export const SOURCE_ROOT_KINDS = [
13
+ 'game',
14
+ 'dlc',
15
+ 'dependency',
16
+ 'mod',
17
+ 'fixture',
18
+ ];
19
+ /** The engine request for the workspace's source roots of `rootKinds` (scan roots of ADR 0080). */
20
+ export function modIndexEngineRequest(workspace, config, rootKinds) {
21
+ return {
22
+ schema: MOD_INDEX_REQUEST_SCHEMA,
23
+ roots: workspace.roots
24
+ .filter(({ kind }) => rootKinds.includes(kind))
25
+ .map(({ kind, path, loadOrder, label, replacePaths }) => ({
26
+ kind,
27
+ path,
28
+ loadOrder,
29
+ ...(label === undefined ? {} : { label }),
30
+ replacePaths,
31
+ })),
32
+ patterns: defaultPatterns(workspace),
33
+ limits: {
34
+ maxFiles: config.scanMaxFiles,
35
+ maxBytes: config.scanMaxBytes,
36
+ maxFileBytes: config.scanMaxFileBytes,
37
+ },
38
+ };
39
+ }
40
+ async function runModIndex(engine, workspaceId, request, principal, signal) {
41
+ signal?.throwIfAborted();
42
+ await engine.resolver.refreshDescriptors(workspaceId, principal);
43
+ const workspace = engine.resolver.get(workspaceId, principal);
44
+ const result = await runEngineCommand('mod-index', {
45
+ ...modIndexEngineRequest(workspace, engine.resolver.config(), request.rootKinds),
46
+ mode: request.mode,
47
+ ...(request.kind === undefined ? {} : { kind: request.kind }),
48
+ ...(request.prefix === undefined ? {} : { prefix: request.prefix }),
49
+ }, modIndexEngineResponseSchema, { timeoutMs: MOD_INDEX_TIMEOUT_MS, ...(signal === undefined ? {} : { signal }) });
50
+ if (!result.available)
51
+ throw new ServiceError('ENGINE_UNAVAILABLE', result.message, { reason: result.reason });
52
+ if (result.outcome === 'invalid_request')
53
+ throw new ServiceError(result.error.code, result.error.message);
54
+ return result.response;
28
55
  }
29
56
  export async function modIndex(engine, workspaceId, input, principal, signal) {
30
57
  if (input.mode === 'next_id') {
@@ -33,51 +60,25 @@ export async function modIndex(engine, workspaceId, input, principal, signal) {
33
60
  if (prefix === undefined)
34
61
  throw new ServiceError('MOD_INDEX_PREFIX_REQUIRED', 'next_id needs prefix or namespace');
35
62
  // Every layer: a new identifier must not collide with game or dependency definitions.
36
- const snapshot = await engine.scan(workspaceId, {}, principal, signal);
37
- const used = new Set();
38
- for (const symbol of snapshot.index.symbols) {
39
- if (symbol.kind !== input.kind || !symbol.id.startsWith(prefix))
40
- continue;
41
- const suffix = symbol.id.slice(prefix.length);
42
- if (/^\d{1,9}$/u.test(suffix))
43
- used.add(Number(suffix));
44
- }
45
- const highest = used.size === 0 ? undefined : Math.max(...used);
46
- let firstGap;
47
- for (let number = 1; highest !== undefined && number < highest; number += 1)
48
- if (!used.has(number)) {
49
- firstGap = number;
50
- break;
51
- }
52
- const next = (highest ?? 0) + 1;
63
+ const answer = await runModIndex(engine, workspaceId, { mode: 'next_id', rootKinds: SOURCE_ROOT_KINDS, kind: input.kind, prefix }, principal, signal);
64
+ const used = answer.next?.used ?? 0;
65
+ const highest = answer.next?.highest;
66
+ const firstGap = answer.next?.firstGap;
53
67
  return {
54
68
  mode: 'next_id',
55
- complete: snapshot.complete,
69
+ complete: answer.complete,
56
70
  next: {
57
71
  kind: input.kind,
58
72
  prefix,
59
- used: used.size,
73
+ used,
60
74
  ...(highest === undefined ? {} : { highest }),
61
- nextId: `${prefix}${next}`,
75
+ nextId: `${prefix}${(highest ?? 0) + 1}`,
62
76
  ...(firstGap === undefined ? {} : { firstGapId: `${prefix}${firstGap}` }),
63
77
  },
64
78
  };
65
79
  }
66
- const snapshot = await engine.scan(workspaceId, input.layer === 'mod' ? { rootKinds: ['mod'] } : {}, principal, signal);
67
- const symbols = snapshot.index.symbols.filter(({ overridden }) => !overridden);
68
- const kinds = new Map();
69
- for (const symbol of symbols)
70
- kinds.set(symbol.kind, (kinds.get(symbol.kind) ?? 0) + 1);
71
- const folders = new Map();
72
- for (const file of snapshot.files) {
73
- const parts = file.relativePath.split('/');
74
- const folder = parts.length > 2 && parts[0] === 'common' ? parts.slice(0, 2).join('/') : parts[0];
75
- const totals = folders.get(folder) ?? { files: 0, bytes: 0 };
76
- totals.files += 1;
77
- totals.bytes += file.size;
78
- folders.set(folder, totals);
79
- }
80
- const allNamespaces = namespaces(symbols);
80
+ const answer = await runModIndex(engine, workspaceId, { mode: 'overview', rootKinds: input.layer === 'mod' ? ['mod'] : SOURCE_ROOT_KINDS }, principal, signal);
81
+ const allNamespaces = [...(answer.namespaces ?? [])].sort((left, right) => left.namespace.localeCompare(right.namespace, 'en'));
81
82
  const modRoot = engine.resolver
82
83
  .get(workspaceId, principal)
83
84
  .roots.find(({ kind }) => kind === 'mod')?.path;
@@ -85,14 +86,11 @@ export async function modIndex(engine, workspaceId, input, principal, signal) {
85
86
  return {
86
87
  mode: 'overview',
87
88
  layer: input.layer,
88
- complete: snapshot.complete,
89
+ complete: answer.complete,
89
90
  ...(descriptor === undefined ? {} : { descriptor }),
90
- files: snapshot.files.length,
91
- kinds: [...kinds]
92
- .map(([kind, count]) => ({ kind, count }))
93
- .sort((left, right) => right.count - left.count || left.kind.localeCompare(right.kind)),
94
- folders: [...folders]
95
- .map(([folder, totals]) => ({ folder, ...totals }))
91
+ files: answer.files ?? 0,
92
+ kinds: [...(answer.kinds ?? [])].sort((left, right) => right.count - left.count || left.kind.localeCompare(right.kind)),
93
+ folders: [...(answer.folders ?? [])]
96
94
  .sort((left, right) => right.files - left.files || left.folder.localeCompare(right.folder))
97
95
  .slice(0, MAX_FOLDERS),
98
96
  namespaces: allNamespaces.slice(0, MAX_NAMESPACES),
@@ -221,7 +221,7 @@ async function configurationExists(configPath) {
221
221
  return false;
222
222
  }
223
223
  }
224
- export async function createEngine(configPath = configurationPath()) {
224
+ export async function createEngine(configPath = configurationPath(), options = {}) {
225
225
  let configuration;
226
226
  try {
227
227
  configuration = await loadConfiguration(configPath);
@@ -250,6 +250,10 @@ export async function createEngine(configPath = configurationPath()) {
250
250
  ],
251
251
  }).catch(() => undefined);
252
252
  const engine = new CoreEngine(resolver);
253
- await engine.initialize();
253
+ // A failed background recovery is the caller's to report through `engine.recovered()`.
254
+ if (options.recovery === 'background')
255
+ engine.initialize().catch(() => undefined);
256
+ else
257
+ await engine.initialize();
254
258
  return engine;
255
259
  }
@@ -1068,6 +1068,10 @@ export const mapOperationSchema = z.discriminatedUnion('kind', [
1068
1068
  .optional()
1069
1069
  .describe('Countries the world generates and writes (an array), or { source: "workspace", realms } for countries the workspace already declares: the world then places them from their capital, seeds, claims and exclusions and writes no country, flag, unit, country history, country name or bookmark file.'),
1070
1070
  continentNames: z.array(worldName).max(12).optional(),
1071
+ inheritedContinents: z
1072
+ .enum(['keep', 'drop'])
1073
+ .optional()
1074
+ .describe('keep (the default) also lists the continents of the active continent.txt after the generated ones; drop writes only the generated continents and warns about every active script that still names a dropped one (MAP_CONTINENT_DROPPED_REFERENCED).'),
1071
1075
  startDate: z
1072
1076
  .string()
1073
1077
  .regex(/^\d{3,4}\.\d{1,2}\.\d{1,2}$/u)
@@ -190,3 +190,53 @@ export const modIndexDataSchema = z
190
190
  .optional(),
191
191
  })
192
192
  .strict();
193
+ /** `hoi4-engine mod-index` (`hoi4-mod-index/1`): what the shared Rust engine answers. */
194
+ export const modIndexEngineResponseSchema = z
195
+ .object({
196
+ schema: z.literal('hoi4-mod-index/1'),
197
+ status: z.literal('ok'),
198
+ complete: z.boolean(),
199
+ skippedSourceCount: z.number().int().min(0),
200
+ skippedSources: z
201
+ .array(z
202
+ .object({
203
+ path: z.string(),
204
+ reasonCodes: z.array(z.string()),
205
+ possibleSymbolKinds: z.array(z.string()),
206
+ })
207
+ .strict())
208
+ .max(100),
209
+ files: z.number().int().min(0).optional(),
210
+ kinds: z
211
+ .array(z.object({ kind: z.string(), count: z.number().int().min(0) }).strict())
212
+ .optional(),
213
+ folders: z
214
+ .array(z
215
+ .object({
216
+ folder: z.string(),
217
+ files: z.number().int().min(0),
218
+ bytes: z.number().int().min(0),
219
+ })
220
+ .strict())
221
+ .optional(),
222
+ namespaces: z
223
+ .array(z
224
+ .object({
225
+ namespace: z.string(),
226
+ events: z.number().int().min(0),
227
+ lowest: z.number().int().min(0),
228
+ highest: z.number().int().min(0),
229
+ files: z.number().int().min(0),
230
+ })
231
+ .strict())
232
+ .optional(),
233
+ next: z
234
+ .object({
235
+ used: z.number().int().min(0),
236
+ highest: z.number().int().min(0).optional(),
237
+ firstGap: z.number().int().min(1).optional(),
238
+ })
239
+ .strict()
240
+ .optional(),
241
+ })
242
+ .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 = '4.11.1';
3
+ export const PACKAGE_VERSION = '4.12.0';
4
4
  export const MCP_PROTOCOL_VERSION = LATEST_PROTOCOL_VERSION;
5
5
  export const CONFIG_VERSION = 1;
6
6
  export const TRANSACTION_VERSION = 2;
@@ -153,15 +153,16 @@ Each `roots` key takes up to 16 folders, and setting `roots` replaces only the k
153
153
 
154
154
  ## Tools, jobs and lifetime
155
155
 
156
- | Key | Type | Range | Default | Purpose |
157
- | ----------------------- | ------- | ---------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
158
- | `maxConcurrentTools` | integer | 1–32 | 2 | Expensive tool calls one server process runs at once. |
159
- | `maxSharedTools` | integer | 1–128 | 4 | Expensive calls and job workers that run at once across every server process sharing the same `serverStateRoot`. |
160
- | `jobDeadlineSeconds` | integer | 1–86,400 | 1,800 | A read-only job still running this long after dispatch is stopped and fails with `JOB_DEADLINE_EXCEEDED`. Rewrite jobs are never stopped this way. |
161
- | `jobCancelGraceSeconds` | integer | 1–600 | 10 | A read-only job still running this long after cancellation is stopped and settles as cancelled. |
162
- | `jobWorkerMaxHeapMiB` | integer | 256–65,536 | unset | Memory ceiling for each job worker's JavaScript heap, in MiB. Unset keeps Node's default. |
163
- | `jobWorkerIdleSeconds` | integer | 0–3,600 | 180 | How long a job worker stays warm after a job so the next job reuses its loaded indexes. `0` starts a fresh worker for every job. |
164
- | `stdioIdleExitMinutes` | integer | 0–10,080 | 0 | A stdio server with no client traffic and no open request for this many minutes exits. `0` never exits. `HOI4_AGENT_STDIO_IDLE_EXIT_MINUTES` overrides it per client. |
156
+ | Key | Type | Range | Default | Purpose |
157
+ | ----------------------- | -------- | ---------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
158
+ | `maxConcurrentTools` | integer | 1–32 | 2 | Expensive tool calls one server process runs at once. |
159
+ | `maxSharedTools` | integer | 1–128 | 4 | Expensive calls and job workers that run at once across every server process sharing the same `serverStateRoot`. |
160
+ | `jobDeadlineSeconds` | integer | 1–86,400 | 1,800 | A read-only job still running this long after dispatch is stopped and fails with `JOB_DEADLINE_EXCEEDED`. Rewrite jobs are never stopped this way. |
161
+ | `jobCancelGraceSeconds` | integer | 1–600 | 10 | A read-only job still running this long after cancellation is stopped and settles as cancelled. |
162
+ | `jobWorkerMaxHeapMiB` | integer | 256–65,536 | unset | Memory ceiling for each job worker's JavaScript heap, in MiB. Unset keeps Node's default. |
163
+ | `jobWorkerIdleSeconds` | integer | 0–3,600 | 180 | How long a job worker stays warm after a job so the next job reuses its loaded indexes. `0` starts a fresh worker for every job. |
164
+ | `plugins` | string[] | up to 8 absolute paths | `[]` | Plugin modules (`.mjs` or `.js`) the stdio server loads to add its own tools. The server loads nothing from a mod folder or the environment, only these paths; a listed file that does not exist is skipped with a warning on stderr, so one shared configuration can name a plugin that exists on one machine. The HTTP server never loads plugins. See [Tools](tools.md#plugins). |
165
+ | `stdioIdleExitMinutes` | integer | 0–10,080 | 0 | A stdio server with no client traffic and no open request for this many minutes exits. `0` never exits. `HOI4_AGENT_STDIO_IDLE_EXIT_MINUTES` overrides it per client. |
165
166
 
166
167
  See [Persistent jobs and MCP tasks](jobs.md) for how jobs, cancellation and recovery behave.
167
168
 
@@ -270,7 +271,6 @@ HTTP server only:
270
271
  | `HOI4_GAME_ROOT` | automatic configuration, setup `--init` and `--discover` | First game folder to try, before the standard Steam locations. |
271
272
  | `HOI4_MOD_ROOTS` | setup `--init` and `--discover` | Extra mod parent folders to discover, separated by `;` on Windows and `:` elsewhere. `--init` uses discovered folders only when no `--mod-root` is given. |
272
273
  | `HOI4_AGENT_STDIO_IDLE_EXIT_MINUTES` | `hoi4-agent-tools` | Overrides `stdioIdleExitMinutes` for one client registration. It must be a whole number from 0 to 10,080; an empty value keeps the configured setting, and any other value stops startup. |
273
- | `HOI4_AGENT_TOOLS_CHAOSX` | `hoi4-agent-tools` | `1` exposes the optional Chaos Redux workflow tools listed in [Tools](tools.md). The HTTP server never exposes them. |
274
274
  | the variable named by `tokenEnv` | `hoi4-agent-tools-http` | Secret for a static bearer token, at least 32 characters. |
275
275
  | `APPDATA`, `XDG_CONFIG_HOME` | every command | Location of the default configuration file. |
276
276
  | `XDG_STATE_HOME`, `XDG_DATA_HOME`, `LOCALAPPDATA` | automatic configuration, setup `--init` | Default `serverStateRoot` and `workspaceStorageRoot`. |
@@ -17,6 +17,8 @@ npm run build
17
17
  npm run inspector
18
18
  ```
19
19
 
20
+ Tools on the shared Rust engine (`hoi4.mod_index`, `hoi4.localisation_inspect`, `hoi4.idea_inspect`, `hoi4.system_inspect`, `hoi4.unit_inspect`, `hoi4.asset_inspect`) need a `hoi4-engine` binary in the tests. Build it once with `cargo build -p hoi4-engine-cli` in `engine/`; the test setup uses that build (in `CARGO_TARGET_DIR` or `engine/target`) unless `HOI4_ENGINE` names another binary.
21
+
20
22
  Keep changes focused and include tests for behavior changes. CI fixtures must be synthetic and project-owned; never commit installed-game or third-party-mod content. Public tool or schema changes require compatibility review and a versioned release.
21
23
 
22
24
  Vitest tracks temporary fixtures created with `mkdtemp` and removes them after each test or suite teardown, with process-exit cleanup as a fallback. Fixture writes and truncations reserve a 256 MiB aggregate disk budget. Test oversized inputs with a small injected limit or mocked metadata; do not allocate gigabyte fixtures. Startup recovery preserves live owners, locks and dated benchmark evidence; see [temporary fixture ownership](adr/0048-temporary-fixture-lifetimes.md).
package/docs/jobs.md CHANGED
@@ -48,6 +48,7 @@ Both native and ordinary calls use that same receipt, while a conflicting retry
48
48
 
49
49
  The server binds an applied rewrite to its authenticated transaction journal before source replacement starts.
50
50
  If execution stops after a commit, recovery reads that journal and reconstructs the domain result without planning or applying the rewrite again.
51
+ At startup the server checks every retained journal and recovers interrupted ones before any call reads or writes a workspace. A stdio server answers `initialize`, `ping`, `server/discover`, `tools/list`, `prompts/list` and `logging/setLevel` meanwhile and holds other requests, in arrival order, until the check ends; more than 128 held requests, or a failed check, closes the connection. The HTTP server finishes the check before it listens.
51
52
  Blocked and unchanged plans do not bind a transaction because they never mutate source.
52
53
 
53
54
  ## Cancellation and recovery
package/docs/map.md CHANGED
@@ -519,6 +519,10 @@ Width and height are multiples of 256 with at most 13,238,272 pixels. Land comes
519
519
 
520
520
  The operation writes `provinces.bmp`, `definition.csv`, `default.map`, `continent.txt`, `heightmap.bmp`, `terrain.bmp`, `rivers.bmp` (rivers run downhill to the coast), `trees.bmp`, `cities.bmp`, `world_normal.bmp`, the land and water colour maps, `adjacencies.csv`, strategic regions (`landProvincesPerRegion`, `seaProvincesPerRegion`) with weather by latitude, states (`provincesPerState`) with population, category, buildings, resources, victory points and ports, country tags, country files, history and three-band flags, a bookmark, localisation, and every position, supply node and railway. Countries grow from spread-out capitals in proportion to `share`; each state lies within one country and one strategic region.
521
521
 
522
+ Continents are the largest landmasses, numbered `world_continent_1` and up and named by `continentNames`; smaller islands join the nearest one. Impassable land (the `wall` edge, painted `impassable_mountain` and impassable model regions) joins no landmass: two lands that only impassable land connects get separate continents, and each connected piece of impassable land takes the continent of the largest landmass it borders, or of the nearest passable province when it borders only water. Strategic regions never cross impassable land either: a piece no larger than a region joins the passable region it borders most, and a larger piece, or one beside only water, forms regions of its own, so no region or state spans the seam over the wall. Countries, generated or workspace realms, grow over passable land only and never cross impassable land or the wall from one edge to the other; land reached only that way follows the island rule (`realms.islands` for workspace realms, the nearest capital otherwise). Impassable provinces take no owner while countries grow: their states take the owner of the passable state they link to with `force_link_ownership_to`.
523
+
524
+ `continent.txt` lists the generated continents first, then by default every continent of the active `continent.txt`, so scripts and portraits that name the base game's continents still load; the in-game trade window then shows a filter for each of them. Set `inheritedContinents: "drop"` (default `"keep"`) to write only the generated continents. The call then reads the scripts that stay active after the write (all of `common`, `events`, `history/countries` and `portraits`, after the `replace_path` folders the world adds) and reports every reference to a dropped continent as `MAP_CONTINENT_DROPPED_REFERENCED` (warning) with its file and line: `is_on_continent = europe`, `continent = europe` (the state set of `any_state_in` and its effects), an AI area's `continents = { europe }` and a portrait pool's `continent = { name = europe }`. `MAP_CONTINENTS_DROPPED` (information) lists the dropped keys and counts the references. An AI strategy's `area = europe` names an AI area, not a continent, and is not reported; localisation keys of the dropped continents are not read.
525
+
522
526
  Each write records its generated files in `.hoi4-agent-world.json`. A later `create_world` deletes the recorded files it no longer writes (retires them) in the same transaction and refuses with `MANAGED_OUTPUT_EDITED` when a recorded file was edited since. `MAP_WORLD_OUTPUTS_RECONCILED` and `data.outputs` give the counts of written, retired and released files with up to 200 paths each; `map-world-outputs.json` lists them all.
523
527
 
524
528
  Every applied map rewrite also returns `data.changedSummary` with the number of changed files (`total`, `created`, `removed`, `modified`) and the same counts for the 40 folders with the most changes (two levels deep, `.` for the mod root, `omittedFolders` for the rest), so the size of a write is visible even when the inline `changedFiles` list is cut.
@@ -567,7 +571,7 @@ Only a course that cannot exist is refused with `MAP_RIVER_UNREACHABLE_MOUTH`: a
567
571
 
568
572
  A declared pass is a saddle lower than the crest on both sides (ADR 0072): the heights in its corridor are capped at the saddle level after all relief is composed, so a volcano cone or plateau on the pass is cut down there (move the volcano if the cone should stay whole). Another range's body is not touched.
569
573
 
570
- To check all of this without a write, call `hoi4.map_rewrite` with `preview: true` and `synthesisCheck: true` on the `create_world` operation: it runs the relief and river synthesis only, writes nothing and returns `MAP_SYNTHESIS_CHECK_READY` or `MAP_SYNTHESIS_CHECK_BLOCKED` with `data.synthesisCheck` (unreachable rivers, carved crossings and passes that are not lower than their crest). It does not run the partition, the countries or the climate stage (ADR 0070). A world that fails to generate returns only its own blockers, never the findings of the map it would replace.
574
+ To check all of this without a write, call `hoi4.map_rewrite` with `preview: true` and `synthesisCheck: true` on the `create_world` operation: it runs the relief and river synthesis only, writes nothing and returns `MAP_SYNTHESIS_CHECK_READY` or `MAP_SYNTHESIS_CHECK_BLOCKED` with `data.synthesisCheck` (unreachable rivers, carved crossings and passes that are not lower than their crest). It reports every blocking problem it finds in one answer, each in `blockers`: realm points that cannot be placed, cities and capitals on impassable land, rivers that cannot reach their mouths, and passes that are not lower than their crest, checked after a river fails too. A write still stops at its first blocking problem. Leaks through a wall (`MAP_RANGE_NOT_CLOSED`) and capitals in provinces that are only mostly impassable need the partition, so only a write finds them. It does not run the partition, the countries or the climate stage (ADR 0070). A world that fails to generate returns only its own blockers, never the findings of the map it would replace.
571
575
 
572
576
  ### Feature-aware provinces, states and strategic regions
573
577
 
@@ -643,7 +647,7 @@ A `rim` leaves sea at the seam as sea, and ships sail across it, because the sea
643
647
 
644
648
  - A band between 60% and 100% of `rimPx` wide at the east and west edges, over the full height, becomes land; sea and lakes in it are filled (`MAP_EDGE_WALL_FILLED`, information). Its inner edge follows fractal noise, so it reads as a coast or cliff line rather than a ruled line. It gets the rim's heights and darker colours, the look `wallTerrain` sets, and the impassable rows across the seam.
645
649
  - The seam is closed at any width, because the seam columns themselves are land. The default of 48 pixels keeps the wall at least one default land province (400 pixels, about 20 across) wide even where it is narrowest; for other province sizes, about 1.7 times the square root of `landProvincePixels` does the same.
646
- - A land province with most of its pixels in the band belongs to the wall. The wall's provinces form their own states with `impassable = yes`, `force_link_ownership_to` the nearest passable state (counted in province steps over land and water) and that state's owner, as the base game's 21 impassable states do; the category is `enclave` where the mod defines it, with infrastructure 0 and no buildings, resources, victory points, ports or forts. A province that straddles the inner edge of the band goes wholly to the side holding most of its pixels.
650
+ - A land province with most of its pixels in the band belongs to the wall. The wall joins no landmass, strategic region or country across the seam (see [Create a new world](#create-a-new-world)): each side of it takes the continent of the land beside it, and its states the owner of the state they link to. The wall's provinces form their own states with `impassable = yes`, `force_link_ownership_to` the nearest passable state (counted in province steps over land and water) and that state's owner, as the base game's 21 impassable states do; the category is `enclave` where the mod defines it, with infrastructure 0 and no buildings, resources, victory points, ports or forts. A province that straddles the inner edge of the band goes wholly to the side holding most of its pixels.
647
651
  - A city in the band (`MAP_EDGE_FEATURE_IN_BAND`) or a workspace capital in a wall province is an error. Capitals are never placed in the wall.
648
652
  - Validation of a `wall` world reports water on the first or last column as `MAP_EDGE_WALL_OPEN` (error) instead of `MAP_EDGE_LAND_CUT`.
649
653
  - With `polarPx: 0` land runs off the top and bottom edges, which validation reports as `MAP_POLAR_LAND` (information); the frame borders are drawn over those rows.
package/docs/reference.md CHANGED
@@ -168,6 +168,8 @@ The result gives `nextId` after the highest used number, and `firstGapId` when a
168
168
  { "mode": "next_id", "kind": "event", "namespace": "my_mod" }
169
169
  ```
170
170
 
171
+ Both modes run on the shared Rust engine (`hoi4-engine mod-index`). Without a usable engine binary the call answers `ENGINE_UNAVAILABLE`; nothing is counted in TypeScript instead.
172
+
171
173
  ## Read the mod's skills
172
174
 
173
175
  `hoi4.skill` serves the modding skills HOI4 Mod Setup installed in the mod, so every client reads the same text.
@@ -1,6 +1,16 @@
1
1
  # Probability adapter evidence
2
2
 
3
- The AI and MTTH Scenario Analyzer targets Hearts of Iron IV **Operation Postern 1.19.4.1 (checksum f584)**. Adapter behavior is versioned as `hoi4-1.19.4.1.v1`. Results always include that adapter version and game build. When the installed build differs, results carry the warning `PROBABILITY_GAME_BUILD_UNVERIFIED`, and the nightly game-update watcher lists the adapters under "Checked against another build" on every run until the pin moves.
3
+ The AI and MTTH Scenario Analyzer targets Hearts of Iron IV **Operation Postern 1.19.4.2 (checksum 0bdb)**. Adapter behavior is versioned as `hoi4-1.19.4.2.v1`. Results always include that adapter version and game build. When the installed build differs, results carry the warning `PROBABILITY_GAME_BUILD_UNVERIFIED`, and the nightly game-update watcher lists the adapters under "Checked against another build" on every run until the pin moves.
4
+
5
+ ## Re-check for 1.19.4.2 (2026-11-08)
6
+
7
+ Every reviewed file was hashed again on the installed game 1.19.4.2:
8
+
9
+ - **Unchanged:** all six reviewed documentation files are byte-identical to the 1.19.4.1 review: `common/decisions/_documentation.md`, `common/doctrines/_documentation.md`, `common/script_constants/documentation.md`, `documentation/script_concept_documentation.md`, `documentation/effects_documentation.md` and `common/ai_strategy/_documentation.md` (`cd19fa14…c715`).
10
+ - **Examples:** each vanilla example below keeps its construct at the line given for 1.19.4.1: `events/Yugoslavia.txt:49`, `events/AAT_Generic_Events.txt:44`, `common/decisions/_generic_decisions.txt:56`, `common/national_focus/austria.txt:122`, `common/technologies/industry.txt:30`, `common/doctrines/grand_doctrines/land_grand_doctrines.txt:14`, `events/AAT_Sweden.txt:1760`, `events/BBA_Switzerland.txt:1205` and the `research_weight_factor` strategy at `common/ai_strategy/ENG.txt:3202`.
11
+ - **Installed build:** `launcher-settings.json` reads `Operation Postern v1.19.4.2.2da5 (0bdb)`, raw version `1.19.4.2`.
12
+
13
+ No adapter rule changed, so only the version pin moved.
4
14
 
5
15
  ## Re-check for 1.19.4.1 (2026-11-06)
6
16
 
package/docs/tools.md CHANGED
@@ -192,7 +192,6 @@ Other clients receive the ordinary synchronous result.
192
192
  Use `hoi4.job_inspect` to inspect an authorized job or retrieve its result, and `hoi4.job_cancel` to request cancellation.
193
193
  See [Background jobs](jobs.md) for request keys, cancellation and recovery.
194
194
 
195
- ## Optional ChaosX tools
195
+ ## Plugins
196
196
 
197
- On the stdio server (`hoi4-agent-tools`), setting `HOI4_AGENT_TOOLS_CHAOSX=1` exposes `chaosx.focus_country_assets` and `chaosx.visual_revision`.
198
- These workflow-specific tools are absent from the default list, and the HTTP server never exposes them.
197
+ A private extension can add tools to the stdio server (`hoi4-agent-tools`). List its module (`.mjs` or `.js`, absolute path) in the configuration key `plugins`; the server loads plugins only from those paths, never from a mod folder or the environment, and the HTTP server never loads them. A plugin tool is named `<plugin>.<tool>` and never starts with `hoi4.`, which this package reserves. A plugin exports a default function that receives a host (`importServerModule` to borrow the server's own modules, `dependency` for the shared `zod` and `sharp`) and returns a factory of tools; each tool has the same definition as a built-in one (name, title, description, input and optional output schema, annotations) and a `call` function. A plugin file that does not exist is skipped with a warning on stderr; a file that is a link, is not a `.mjs` or `.js` file, or exports no factory stops the server at startup.
@@ -14,7 +14,7 @@ This page lists the codes you are most likely to meet, then the checks for probl
14
14
  | Renders lack icons or fonts, native commands are unresolved | The game folder is not configured. Set `--game-root` (or `gameRoot`) to the Hearts of Iron IV folder; `hoi4-agent-tools-setup --discover` prints the folders it can find. |
15
15
  | `ERROR_LOG_NOT_FOUND` | Launch the game once, or set `gameUserRoot` to the folder that holds `logs/`, `mod/` and `save games/` (with OneDrive that is often under `OneDrive\Documents`). |
16
16
  | `AUTH_INVALID` over HTTP | The bearer token is missing, expired or for another server. See the [HTTP guide](http.md). |
17
- | Startup or a call times out in the client | A cold scan of a large mod takes minutes. Raise the client's startup and tool timeouts (the printed Codex entries use 120 and 600 seconds), or use [background jobs](jobs.md). |
17
+ | Startup or a call times out in the client | A cold scan of a large mod takes minutes. Raise the client's startup and tool timeouts (the printed Codex entries use 120 and 600 seconds), or use [background jobs](jobs.md). The stdio server answers the handshake before it checks retained rewrite journals; the first tool call waits for that check. |
18
18
  | Many idle `node` processes | Some clients keep a server per subagent. Set `HOI4_AGENT_STDIO_IDLE_EXIT_MINUTES`; see [Server lifetime](setup.md#server-lifetime). |
19
19
 
20
20
  ## Arguments and results
Binary file
Binary file
Binary file
@@ -4,23 +4,23 @@
4
4
  "binaries": {
5
5
  "darwin-arm64": {
6
6
  "file": "darwin-arm64/hoi4-engine",
7
- "sha256": "d3e0b0e06aa93cc2039de9b82a022921993e45c0fbf94b39c9d83ac53b08a781",
8
- "size": 4215168
7
+ "sha256": "f6dc22cb5f75ff544df60684edd6ff73bfd3bc03b36f0cf281bf1b04e620b871",
8
+ "size": 4562496
9
9
  },
10
10
  "linux-arm64": {
11
11
  "file": "linux-arm64/hoi4-engine",
12
- "sha256": "c391e2e541bc1da6a3e71b8cd21906edfe9b713985e4a34a26fa9d97b418d340",
13
- "size": 4559512
12
+ "sha256": "a535f718dd730b4687c679780a0f063fdc7e7dd81b6aeb7f5fa232d65b1e6b76",
13
+ "size": 4891992
14
14
  },
15
15
  "linux-x64": {
16
16
  "file": "linux-x64/hoi4-engine",
17
- "sha256": "faf47c3b27da419e534e530871ae509a0c98b8b10dc23697f779029a78080720",
18
- "size": 4927760
17
+ "sha256": "5ecb3b90e7d97c9513064f640d41116cc2b209c71478f627919f43ab8d36141a",
18
+ "size": 5274640
19
19
  },
20
20
  "win32-x64": {
21
21
  "file": "win32-x64/hoi4-engine.exe",
22
- "sha256": "e3de6d2103a78107a51fa5904a84f89c39d149f034c87e5a28c19b6ccad13f11",
23
- "size": 4125184
22
+ "sha256": "dac9fd231db24a4e70fd6048da3dc1673185385cd823bb69da8b7c1f2b32fb18",
23
+ "size": 4414464
24
24
  }
25
25
  }
26
26
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "hoi4-agent-tools",
3
- "version": "4.11.1",
3
+ "version": "4.12.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "hoi4-agent-tools",
9
- "version": "4.11.1",
9
+ "version": "4.12.0",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@fontsource-variable/roboto": "5.3.0",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hoi4-agent-tools",
3
3
  "mcpName": "io.github.klimPaskov/hoi4-agent-tools",
4
- "version": "4.11.1",
4
+ "version": "4.12.0",
5
5
  "description": "Build HOI4 mods: focus trees, events, decisions, worlds, GUI previews, docs and AI balance.",
6
6
  "type": "module",
7
7
  "license": "Apache-2.0",