hoi4-agent-tools 4.11.1 → 4.13.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 (116) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +3 -3
  3. package/dist/bin/setup.js +38 -0
  4. package/dist/bin/stdio.js +12 -10
  5. package/dist/hoi4_agent_tools/core/configuration.js +29 -0
  6. package/dist/hoi4_agent_tools/core/domain-tools.js +4 -0
  7. package/dist/hoi4_agent_tools/core/engine-check.js +87 -0
  8. package/dist/hoi4_agent_tools/core/engine-client.js +1 -1
  9. package/dist/hoi4_agent_tools/core/engine.js +18 -2
  10. package/dist/hoi4_agent_tools/core/job-operation-registration.js +2 -0
  11. package/dist/hoi4_agent_tools/core/job-store.js +1 -1
  12. package/dist/hoi4_agent_tools/focus/native-effects.js +1 -1
  13. package/dist/hoi4_agent_tools/localisation/job-operations.js +42 -0
  14. package/dist/hoi4_agent_tools/localisation/write-diff.js +96 -0
  15. package/dist/hoi4_agent_tools/localisation/write-format.js +329 -0
  16. package/dist/hoi4_agent_tools/localisation/write-operations.js +213 -0
  17. package/dist/hoi4_agent_tools/localisation/write-plan.js +557 -0
  18. package/dist/hoi4_agent_tools/map/gameplay/crossing-validation.js +17 -0
  19. package/dist/hoi4_agent_tools/map/model.js +31 -1
  20. package/dist/hoi4_agent_tools/map/operations.js +37 -8
  21. package/dist/hoi4_agent_tools/map/references.js +87 -0
  22. package/dist/hoi4_agent_tools/map/relief/hydrology.js +7 -2
  23. package/dist/hoi4_agent_tools/map/relief/terrain-synthesis.js +1 -0
  24. package/dist/hoi4_agent_tools/map/service.js +13 -4
  25. package/dist/hoi4_agent_tools/map/tool-operations.js +6 -0
  26. package/dist/hoi4_agent_tools/map/world-edge.js +0 -25
  27. package/dist/hoi4_agent_tools/map/world.js +181 -64
  28. package/dist/hoi4_agent_tools/mcp/plugins.js +74 -0
  29. package/dist/hoi4_agent_tools/mcp/server/argument-errors.js +5 -0
  30. package/dist/hoi4_agent_tools/mcp/server/create-modern-operations.js +15 -21
  31. package/dist/hoi4_agent_tools/mcp/server/create.js +5 -1
  32. package/dist/hoi4_agent_tools/mcp/server/request-lifecycle.js +10 -2
  33. package/dist/hoi4_agent_tools/mcp/server/task-tool-catalog.js +2 -0
  34. package/dist/hoi4_agent_tools/mcp/server/tool-profiles.js +83 -0
  35. package/dist/hoi4_agent_tools/mcp/tools/localisation-write.js +21 -0
  36. package/dist/hoi4_agent_tools/mcp/tools/reference.js +34 -0
  37. package/dist/hoi4_agent_tools/mcp/transports/http.js +6 -1
  38. package/dist/hoi4_agent_tools/mcp/transports/negotiated-stdio.js +64 -6
  39. package/dist/hoi4_agent_tools/probability/model.js +4 -4
  40. package/dist/hoi4_agent_tools/reference/compat-patch.js +555 -0
  41. package/dist/hoi4_agent_tools/reference/compat.js +255 -0
  42. package/dist/hoi4_agent_tools/reference/docs-pack.js +164 -0
  43. package/dist/hoi4_agent_tools/reference/docs-pack.json +339 -0
  44. package/dist/hoi4_agent_tools/reference/documented-commands.js +26 -0
  45. package/dist/hoi4_agent_tools/reference/error-explain.js +235 -0
  46. package/dist/hoi4_agent_tools/reference/error-explanations.json +262 -0
  47. package/dist/hoi4_agent_tools/reference/error-log.js +30 -10
  48. package/dist/hoi4_agent_tools/reference/mod-health.js +255 -0
  49. package/dist/hoi4_agent_tools/reference/mod-index.js +63 -65
  50. package/dist/hoi4_agent_tools/reference/operations.js +435 -21
  51. package/dist/hoi4_agent_tools/reference/script-guard.js +109 -0
  52. package/dist/hoi4_agent_tools/reference/service.js +58 -20
  53. package/dist/hoi4_agent_tools/runtime.js +17 -2
  54. package/dist/hoi4_agent_tools/schemas/compat.js +153 -0
  55. package/dist/hoi4_agent_tools/schemas/localisation-write.js +154 -0
  56. package/dist/hoi4_agent_tools/schemas/map.js +5 -1
  57. package/dist/hoi4_agent_tools/schemas/mod-tools.js +50 -0
  58. package/dist/hoi4_agent_tools/schemas/modder-tools.js +191 -0
  59. package/dist/hoi4_agent_tools/version.js +1 -1
  60. package/docs/configuration.md +14 -11
  61. package/docs/development.md +2 -0
  62. package/docs/jobs.md +3 -1
  63. package/docs/map.md +8 -4
  64. package/docs/reference.md +47 -5
  65. package/docs/research/probability-adapter-evidence.md +11 -1
  66. package/docs/setup.md +23 -3
  67. package/docs/tools.md +18 -4
  68. package/docs/troubleshooting.md +1 -1
  69. package/engine/bin/darwin-arm64/hoi4-engine +0 -0
  70. package/engine/bin/linux-arm64/hoi4-engine +0 -0
  71. package/engine/bin/linux-x64/hoi4-engine +0 -0
  72. package/engine/bin/manifest.json +8 -8
  73. package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
  74. package/npm-shrinkwrap.json +2 -2
  75. package/package.json +1 -1
  76. package/schemas/configuration.schema.json +181 -138
  77. package/schemas/continuous-focus-palette.schema.json +1 -1
  78. package/schemas/custom-weighted-pool.schema.json +1 -1
  79. package/schemas/decision-inspect-input.schema.json +1 -1
  80. package/schemas/error-log-input.schema.json +1 -1
  81. package/schemas/event-feature-manifest.schema.json +1 -1
  82. package/schemas/focus-plan.schema.json +1 -1
  83. package/schemas/focus-planning-sidecar.schema.json +1 -1
  84. package/schemas/geography-model.schema.json +1 -1
  85. package/schemas/gui-animation-source.schema.json +1 -1
  86. package/schemas/gui-helper.schema.json +1 -1
  87. package/schemas/gui-scenario.schema.json +1 -1
  88. package/schemas/helper-expansion-request.schema.json +1 -1
  89. package/schemas/helper-expansion-summary.schema.json +1 -1
  90. package/schemas/impact-inspect-input.schema.json +1 -1
  91. package/schemas/map-operation.schema.json +153 -139
  92. package/schemas/mechanic-test-input.schema.json +1 -1
  93. package/schemas/mod-index-input.schema.json +1 -1
  94. package/schemas/operation-result.schema.json +1 -1
  95. package/schemas/package-check-input.schema.json +1 -1
  96. package/schemas/package-manifest.schema.json +1 -1
  97. package/schemas/probability-analysis-result.schema.json +1 -1
  98. package/schemas/probability-compare-input.schema.json +1 -1
  99. package/schemas/probability-evaluate-input.schema.json +1 -1
  100. package/schemas/probability-inspect-input.schema.json +1 -1
  101. package/schemas/probability-render-input.schema.json +1 -1
  102. package/schemas/probability-scenario-set.schema.json +1 -1
  103. package/schemas/probability-sequence-input.schema.json +1 -1
  104. package/schemas/probability-simulate-input.schema.json +1 -1
  105. package/schemas/probability-sweep-input.schema.json +1 -1
  106. package/schemas/reference-context-input.schema.json +1 -1
  107. package/schemas/reference-read-input.schema.json +1 -1
  108. package/schemas/reference-search-input.schema.json +1 -1
  109. package/schemas/reference-sheets.schema.json +1 -1
  110. package/schemas/scenario-suite.schema.json +1 -1
  111. package/schemas/scenario-test-input.schema.json +1 -1
  112. package/schemas/script-validate-input.schema.json +1 -1
  113. package/schemas/shared-scenario.schema.json +1 -1
  114. package/schemas/source-lookup-input.schema.json +1 -1
  115. package/server.json +2 -2
  116. package/dist/hoi4_agent_tools/mcp/tools/chaosx.js +0 -509
@@ -13,6 +13,7 @@ import { activeKnownMistakes } from './known-mistakes.js';
13
13
  import { readBoundedJsonLines } from './lines.js';
14
14
  import { commandTexts, readGameText } from './game-text.js';
15
15
  import { RankingIndex, sectionTerms, textTerms } from './ranking.js';
16
+ import { installedDocsPackWiki } from './docs-pack.js';
16
17
  const MAX_FILES = 512;
17
18
  const MAX_FILE_BYTES = 2_000_000;
18
19
  const MAX_TOTAL_BYTES = 32_000_000;
@@ -214,19 +215,42 @@ function sectionize(root, canonicalRoot, filePath, content, revision) {
214
215
  /** The kit's HOI4 wiki folder, and the name it had before the kit renamed it. */
215
216
  const WIKI_FOLDER = 'hoi4_wiki';
216
217
  const LEGACY_WIKI_FOLDER = 'paradox_wiki';
217
- /** `hoi4_wiki/` when the mod has it, otherwise the older `paradox_wiki/` of a mod the kit has not updated. */
218
- function defaultWikiRoot(modRoot) {
219
- const current = path.join(modRoot, WIKI_FOLDER);
218
+ function isDirectory(candidate) {
220
219
  try {
221
- if (statSync(current).isDirectory())
222
- return current;
220
+ return statSync(candidate).isDirectory();
223
221
  }
224
222
  catch {
225
- // Not there: fall back to the legacy name, which is reported unavailable when absent too.
223
+ return false;
226
224
  }
227
- return path.join(modRoot, LEGACY_WIKI_FOLDER);
228
225
  }
229
- function sourceRoots(workspace) {
226
+ /** `hoi4_wiki/` when the mod has it, otherwise the older `paradox_wiki/` of a mod the kit has not updated. */
227
+ function modWikiRoot(modRoot) {
228
+ return [WIKI_FOLDER, LEGACY_WIKI_FOLDER]
229
+ .map((folder) => path.join(modRoot, folder))
230
+ .find(isDirectory);
231
+ }
232
+ /**
233
+ * The wiki a workspace reads: a configured folder, the mod's own copy, or else the docs pack.
234
+ * Without any of them it is the legacy folder name, which is reported unavailable.
235
+ */
236
+ function wikiRoot(workspace, docsPackWiki) {
237
+ const own = workspace.wikiRoot ?? modWikiRoot(workspace.modRoot);
238
+ if (own === undefined && docsPackWiki !== undefined)
239
+ return {
240
+ kind: 'wiki',
241
+ root: docsPackWiki,
242
+ patterns: ['**/*.md'],
243
+ authority: 'HOI4 wiki (docs pack)',
244
+ authorityRoot: docsPackWiki,
245
+ };
246
+ return {
247
+ kind: 'wiki',
248
+ root: own ?? path.join(workspace.modRoot, LEGACY_WIKI_FOLDER),
249
+ patterns: ['**/*.md'],
250
+ authority: 'HOI4 wiki (kit)',
251
+ };
252
+ }
253
+ function sourceRoots(workspace, docsPackWiki) {
230
254
  const gameRoot = workspace.gameRoot ?? (workspace.registration.kind === 'game' ? workspace.modRoot : undefined);
231
255
  return [
232
256
  ...(gameRoot === undefined
@@ -239,12 +263,7 @@ function sourceRoots(workspace) {
239
263
  authority: 'Installed game documentation',
240
264
  },
241
265
  ]),
242
- {
243
- kind: 'wiki',
244
- root: workspace.wikiRoot ?? defaultWikiRoot(workspace.modRoot),
245
- patterns: ['**/*.md'],
246
- authority: 'HOI4 wiki (kit)',
247
- },
266
+ wikiRoot(workspace, docsPackWiki),
248
267
  {
249
268
  kind: 'script_doc',
250
269
  root: workspace.scriptDocsRoot ?? path.join(workspace.modRoot, 'script_docs'),
@@ -373,6 +392,24 @@ export class ReferenceService {
373
392
  #cache = new Map();
374
393
  #indexes = new Map();
375
394
  #cacheBytes = 0;
395
+ #docsRoot;
396
+ /** `docsRoot`: where a fetched docs pack lives; without it no pack is read. */
397
+ constructor(options = {}) {
398
+ this.#docsRoot = options.docsRoot;
399
+ }
400
+ /** The wiki folder of the installed docs pack this package version pins, if there is one. */
401
+ async docsPackWiki() {
402
+ const wiki = await installedDocsPackWiki(this.#docsRoot);
403
+ if (wiki === undefined)
404
+ return undefined;
405
+ // The canonical path: a data folder named by its 8.3 short form (a Windows user name can
406
+ // be shortened) must not look like a root that resolves outside itself.
407
+ return realpath(wiki).catch(() => wiki);
408
+ }
409
+ /** Whether a docs pack location is configured, so a missing pack can be named as the fix. */
410
+ get docsPackConfigured() {
411
+ return this.#docsRoot !== undefined;
412
+ }
376
413
  retain(key, value) {
377
414
  this.#cacheBytes -= this.#cache.get(key)?.bytes ?? 0;
378
415
  this.#cache.delete(key);
@@ -410,7 +447,7 @@ export class ReferenceService {
410
447
  };
411
448
  let skipped = 0;
412
449
  let bytes = 0;
413
- for (const root of sourceRoots(workspace)) {
450
+ for (const root of sourceRoots(workspace, await this.docsPackWiki())) {
414
451
  if (sources !== undefined && !sources.includes(root.kind))
415
452
  continue;
416
453
  signal?.throwIfAborted();
@@ -422,11 +459,12 @@ export class ReferenceService {
422
459
  coverage[root.kind].unavailable = true;
423
460
  continue;
424
461
  }
425
- const configuredAuthorityRoot = root.kind === 'game_doc'
426
- ? root.root
427
- : root.kind === 'wiki'
428
- ? (workspace.wikiRoot ?? workspace.modRoot)
429
- : (workspace.scriptDocsRoot ?? workspace.modRoot);
462
+ const configuredAuthorityRoot = root.authorityRoot ??
463
+ (root.kind === 'game_doc'
464
+ ? root.root
465
+ : root.kind === 'wiki'
466
+ ? (workspace.wikiRoot ?? workspace.modRoot)
467
+ : (workspace.scriptDocsRoot ?? workspace.modRoot));
430
468
  if (!isWithin(configuredAuthorityRoot, canonicalRoot)) {
431
469
  throw new ServiceError('REFERENCE_ROOT_ESCAPE', 'Reference root resolves outside its configured workspace');
432
470
  }
@@ -7,6 +7,8 @@ import { ServiceError } from './core/result.js';
7
7
  import { WorkspaceResolver } from './core/workspace.js';
8
8
  import { CONFIG_VERSION } from './version.js';
9
9
  import { sweepTemporaryDirectories } from './core/temporary-directories.js';
10
+ import { PROFILES_ENV, parseProfilesEnv, } from './mcp/server/tool-profiles.js';
11
+ import { defaultDocsRoot } from './reference/docs-pack.js';
10
12
  export function defaultConfigurationPath() {
11
13
  const configRoot = process.env.APPDATA ?? process.env.XDG_CONFIG_HOME ?? path.join(homedir(), '.config');
12
14
  return path.join(configRoot, 'hoi4-agent-tools', 'config.json');
@@ -221,7 +223,7 @@ async function configurationExists(configPath) {
221
223
  return false;
222
224
  }
223
225
  }
224
- export async function createEngine(configPath = configurationPath()) {
226
+ export async function createEngine(configPath = configurationPath(), options = {}) {
225
227
  let configuration;
226
228
  try {
227
229
  configuration = await loadConfiguration(configPath);
@@ -236,6 +238,15 @@ export async function createEngine(configPath = configurationPath()) {
236
238
  throw error;
237
239
  configuration = await automaticConfiguration();
238
240
  }
241
+ // The stdio server lists the core tools unless the client or the file asks for more.
242
+ const profiles = parseProfilesEnv(process.env[PROFILES_ENV]) ??
243
+ configuration.profiles ??
244
+ options.defaultProfiles;
245
+ if (profiles !== undefined)
246
+ configuration = { ...configuration, profiles: [...profiles] };
247
+ // The command-line servers read a fetched docs pack from the user's data folder by default.
248
+ if (configuration.docsRoot === undefined)
249
+ configuration = { ...configuration, docsRoot: defaultDocsRoot() };
239
250
  const resolver = await WorkspaceResolver.create(configuration);
240
251
  await sweepTemporaryDirectories(tmpdir(), {
241
252
  protectedRoots: [
@@ -250,6 +261,10 @@ export async function createEngine(configPath = configurationPath()) {
250
261
  ],
251
262
  }).catch(() => undefined);
252
263
  const engine = new CoreEngine(resolver);
253
- await engine.initialize();
264
+ // A failed background recovery is the caller's to report through `engine.recovered()`.
265
+ if (options.recovery === 'background')
266
+ engine.initialize().catch(() => undefined);
267
+ else
268
+ await engine.initialize();
254
269
  return engine;
255
270
  }
@@ -0,0 +1,153 @@
1
+ import { z } from 'zod/v4';
2
+ import { workspaceIdSchema } from './common.js';
3
+ /** `hoi4.compat_check`: how the mod fits another mod, and what a game patch changed under its overrides. */
4
+ export const COMPAT_DEFAULT_LIMIT = 10;
5
+ export const COMPAT_MAX_LIMIT = 50;
6
+ const buildSchema = z.string().min(1).max(64);
7
+ export const compatCheckRequestSchema = z
8
+ .object({
9
+ workspaceId: workspaceIdSchema,
10
+ /** mod: the mod against another mod, in both load orders. patch: the mod's overrides across game builds. */
11
+ mode: z.enum(['mod', 'patch']),
12
+ /** mod only: the other mod's folder name or workspace id. */
13
+ other: z.string().min(1).max(128).optional(),
14
+ /** patch only: the older stored game build; default is the newest stored build other than `to`. */
15
+ from: buildSchema.optional(),
16
+ /** patch only: the newer game build; default is the installed build. */
17
+ to: buildSchema.optional(),
18
+ /** Items listed per list; the counts are always complete. */
19
+ limit: z.number().int().min(1).max(COMPAT_MAX_LIMIT).default(COMPAT_DEFAULT_LIMIT),
20
+ })
21
+ .strict()
22
+ .superRefine((input, context) => {
23
+ if (input.mode === 'mod' && input.other === undefined)
24
+ context.addIssue({ code: 'custom', path: ['other'], message: 'mode mod needs other' });
25
+ if (input.mode === 'patch' && input.other !== undefined)
26
+ context.addIssue({
27
+ code: 'custom',
28
+ path: ['other'],
29
+ message: 'other belongs to mode mod',
30
+ });
31
+ if (input.mode === 'mod' && (input.from !== undefined || input.to !== undefined))
32
+ context.addIssue({
33
+ code: 'custom',
34
+ path: [input.from === undefined ? 'to' : 'from'],
35
+ message: 'from and to belong to mode patch',
36
+ });
37
+ });
38
+ const modRefSchema = z.object({ id: z.string().max(64), name: z.string().max(256) }).strict();
39
+ const findingSchema = z
40
+ .object({
41
+ code: z.string().max(64),
42
+ severity: z.enum(['error', 'warning', 'info']),
43
+ subject: z.string().max(256).nullable(),
44
+ layer: z.string().max(256),
45
+ path: z.string().max(512),
46
+ message: z.string().max(400),
47
+ })
48
+ .strict();
49
+ const listSchema = (item) => z
50
+ .object({
51
+ count: z.number().int().min(0),
52
+ omitted: z.number().int().min(0),
53
+ items: z.array(item).max(COMPAT_MAX_LIMIT),
54
+ })
55
+ .strict();
56
+ const loadOrderSchema = z
57
+ .object({
58
+ /** Loads first; its files lose a clash. */
59
+ first: modRefSchema,
60
+ /** Loads last; its files win a clash. */
61
+ second: modRefSchema,
62
+ errors: z.number().int().min(0),
63
+ warnings: z.number().int().min(0),
64
+ sameFile: listSchema(z.object({ path: z.string().max(512), winner: z.string().max(256) }).strict()),
65
+ duplicateDefinitions: listSchema(findingSchema),
66
+ dropped: listSchema(findingSchema),
67
+ replacePathDrops: listSchema(z
68
+ .object({
69
+ folder: z.string().max(512),
70
+ fileCount: z.number().int().min(1),
71
+ files: z.array(z.string().max(512)).max(5),
72
+ })
73
+ .strict()),
74
+ })
75
+ .strict();
76
+ export const compatModDataSchema = z
77
+ .object({
78
+ mode: z.literal('mod'),
79
+ workspace: modRefSchema,
80
+ other: modRefSchema,
81
+ verdict: z.enum(['no_conflicts', 'conflicts']),
82
+ /** The load order that loses less, from its error and warning counts against the other order; null when they match. */
83
+ lessLoss: z
84
+ .object({
85
+ loadsLast: modRefSchema,
86
+ errors: z.number().int().min(0),
87
+ warnings: z.number().int().min(0),
88
+ otherOrderErrors: z.number().int().min(0),
89
+ otherOrderWarnings: z.number().int().min(0),
90
+ })
91
+ .strict()
92
+ .nullable(),
93
+ summary: z.string().max(600),
94
+ loadOrders: z.array(loadOrderSchema).length(2),
95
+ notes: z.array(z.string().max(400)).max(8),
96
+ durationMs: z.number().int().min(0),
97
+ })
98
+ .strict();
99
+ const hunkFileSchema = z
100
+ .object({
101
+ path: z.string().max(512),
102
+ layer: z.string().max(256),
103
+ change: z.enum(['changed', 'added', 'removed']),
104
+ binary: z.boolean(),
105
+ oldLines: z.number().int().min(0).nullable(),
106
+ newLines: z.number().int().min(0).nullable(),
107
+ linesAdded: z.number().int().min(0).nullable(),
108
+ linesRemoved: z.number().int().min(0).nullable(),
109
+ firstHunk: z.string().max(2400).nullable(),
110
+ })
111
+ .strict();
112
+ const snapshotInfoSchema = z
113
+ .object({
114
+ build: z.string().max(64),
115
+ files: z.number().int().min(0),
116
+ copiedFiles: z.number().int().min(0),
117
+ uncopiedFiles: z.number().int().min(0),
118
+ bytes: z.number().int().min(0),
119
+ })
120
+ .strict();
121
+ export const compatPatchDataSchema = z
122
+ .object({
123
+ mode: z.literal('patch'),
124
+ workspace: modRefSchema,
125
+ /** The installed build; null when only stored snapshots were compared. */
126
+ installedBuild: z.string().max(64).nullable(),
127
+ /** The snapshot this call stored; null when only stored snapshots were compared. */
128
+ recorded: snapshotInfoSchema.nullable(),
129
+ pruned: z.array(z.string().max(64)).max(16),
130
+ stored: z.array(snapshotInfoSchema).max(8),
131
+ comparison: z
132
+ .object({
133
+ from: z.string().max(64),
134
+ to: z.string().max(64),
135
+ changed: z.number().int().min(0),
136
+ added: z.number().int().min(0),
137
+ removed: z.number().int().min(0),
138
+ unchanged: z.number().int().min(0),
139
+ /** Overridden in the older snapshot, gone from the newer one, and no longer shipped by the mod. */
140
+ noLongerOverridden: z.number().int().min(0),
141
+ omitted: z.number().int().min(0),
142
+ files: z.array(hunkFileSchema).max(COMPAT_MAX_LIMIT),
143
+ })
144
+ .strict()
145
+ .nullable(),
146
+ summary: z.string().max(600),
147
+ durationMs: z.number().int().min(0),
148
+ })
149
+ .strict();
150
+ export const compatCheckDataSchema = z.discriminatedUnion('mode', [
151
+ compatModDataSchema,
152
+ compatPatchDataSchema,
153
+ ]);
@@ -0,0 +1,154 @@
1
+ import { z } from 'zod/v4';
2
+ import { backgroundRequestKeySchema, workspaceIdSchema, workspaceRelativePathSchema, } from './common.js';
3
+ /** The languages the game ships (`localisation/languages.yml`). */
4
+ export const LOCALISATION_LANGUAGES = [
5
+ 'english',
6
+ 'french',
7
+ 'german',
8
+ 'spanish',
9
+ 'polish',
10
+ 'russian',
11
+ 'braz_por',
12
+ 'japanese',
13
+ 'simp_chinese',
14
+ 'korean',
15
+ ];
16
+ export const localisationLanguageSchema = z.enum(LOCALISATION_LANGUAGES);
17
+ export const LOCALISATION_FIXES = ['bom', 'quotes', 'missing_languages'];
18
+ export const localisationFixSchema = z.enum(LOCALISATION_FIXES);
19
+ export const LOCALISATION_KEY_PATTERN = /^[A-Za-z0-9_.-]{1,256}$/u;
20
+ // A value is one line: no line break, tab or other control character.
21
+ const FORBIDDEN_TEXT = /[\p{Cc}\p{Zl}\p{Zp}]/u;
22
+ export const localisationEntrySchema = z
23
+ .object({
24
+ key: z.string().regex(LOCALISATION_KEY_PATTERN),
25
+ text: z
26
+ .string()
27
+ .max(2000)
28
+ .refine((value) => !FORBIDDEN_TEXT.test(value), {
29
+ message: 'text must be one line; write a line break as \\n',
30
+ }),
31
+ })
32
+ .strict();
33
+ export const localisationWriteRequestSchema = z
34
+ .object({
35
+ workspaceId: workspaceIdSchema,
36
+ mode: z.enum(['add', 'fix']),
37
+ apply: z
38
+ .boolean()
39
+ .default(false)
40
+ .describe('false returns the diff and writes nothing; true makes the same change.'),
41
+ entries: z.array(localisationEntrySchema).min(1).max(200).optional(),
42
+ language: localisationLanguageSchema.default('english'),
43
+ file: workspaceRelativePathSchema.max(512).optional(),
44
+ replace: z.boolean().default(false),
45
+ fixes: z
46
+ .array(localisationFixSchema)
47
+ .min(1)
48
+ .max(3)
49
+ .default([...LOCALISATION_FIXES]),
50
+ paths: z.array(workspaceRelativePathSchema.max(512)).min(1).max(200).optional(),
51
+ requestKey: backgroundRequestKeySchema.optional(),
52
+ })
53
+ .strict()
54
+ .superRefine((value, context) => {
55
+ const misplaced = (field) => context.addIssue({
56
+ code: 'custom',
57
+ path: [field],
58
+ message: `${field} belongs to the other mode`,
59
+ });
60
+ if (value.mode === 'add') {
61
+ if (value.entries === undefined)
62
+ context.addIssue({ code: 'custom', path: ['entries'], message: 'mode add needs entries' });
63
+ else {
64
+ const seen = new Set();
65
+ for (const [index, entry] of value.entries.entries()) {
66
+ if (seen.has(entry.key))
67
+ context.addIssue({
68
+ code: 'custom',
69
+ path: ['entries', index, 'key'],
70
+ message: `${entry.key} appears twice in entries`,
71
+ });
72
+ seen.add(entry.key);
73
+ }
74
+ }
75
+ if (value.paths !== undefined)
76
+ misplaced('paths');
77
+ }
78
+ else {
79
+ if (value.entries !== undefined)
80
+ misplaced('entries');
81
+ if (value.file !== undefined)
82
+ misplaced('file');
83
+ if (value.replace)
84
+ misplaced('replace');
85
+ }
86
+ });
87
+ const countSchema = z.number().int().min(0);
88
+ const changeKindSchema = z.enum([
89
+ 'add_key',
90
+ 'replace_key',
91
+ 'override_key',
92
+ 'create_file',
93
+ 'add_bom',
94
+ 'reencode_utf16',
95
+ 'fix_quote',
96
+ 'copy_missing_key',
97
+ ]);
98
+ export const localisationWriteDataSchema = z
99
+ .object({
100
+ mode: z.enum(['add', 'fix']),
101
+ applied: z.boolean(),
102
+ files: z
103
+ .array(z
104
+ .object({
105
+ path: z.string().max(1024),
106
+ action: z.enum(['create', 'update']),
107
+ diff: z.string().max(12_000),
108
+ diffTruncated: z.boolean(),
109
+ changes: z
110
+ .array(z
111
+ .object({
112
+ kind: changeKindSchema,
113
+ key: z.string().max(256).optional(),
114
+ line: z.number().int().min(1).optional(),
115
+ })
116
+ .strict())
117
+ .max(8),
118
+ changesOmitted: countSchema,
119
+ })
120
+ .strict())
121
+ .max(12),
122
+ skipped: z
123
+ .array(z.object({ key: z.string().max(256), reason: z.string().max(300) }).strict())
124
+ .max(20),
125
+ unfixable: z
126
+ .array(z
127
+ .object({
128
+ kind: z.string().max(64),
129
+ path: z.string().max(1024).optional(),
130
+ key: z.string().max(256).optional(),
131
+ reason: z.string().max(300),
132
+ })
133
+ .strict())
134
+ .max(20),
135
+ notes: z.array(z.string().max(400)).max(10),
136
+ counts: z
137
+ .object({
138
+ filesChanged: countSchema,
139
+ filesCreated: countSchema,
140
+ filesOmitted: countSchema,
141
+ keysAdded: countSchema,
142
+ keysReplaced: countSchema,
143
+ keysOverridden: countSchema,
144
+ keysSkipped: countSchema,
145
+ skippedOmitted: countSchema,
146
+ bomsAdded: countSchema,
147
+ quotesFixed: countSchema,
148
+ keysCopied: countSchema,
149
+ unfixable: countSchema,
150
+ unfixableOmitted: countSchema,
151
+ })
152
+ .strict(),
153
+ })
154
+ .strict();
@@ -196,7 +196,7 @@ export const worldEdgeSchema = z
196
196
  mode: z
197
197
  .enum(['sea-band', 'rim', 'wall', 'none'])
198
198
  .optional()
199
- .describe('sea-band (default when edge is given) clears land from the east and west edges and the poles to open sea; rim ends land at the seam in an impassable snow range with impassable adjacencies across the seam, but sea at the seam stays sailable; wall fills rimPx at the east and west edges with land over the full height, in impassable states, so nothing crosses the seam by land or sea; none keeps the picture and warns about land cut by the wrapping seam.'),
199
+ .describe('sea-band (default when edge is given) clears land from the east and west edges and the poles to open sea; rim ends land at the seam in an impassable snow range whose seam provinces are impassable states, but sea at the seam stays sailable; wall fills rimPx at the east and west edges with land over the full height, in impassable states, so nothing crosses the seam by land or sea; none keeps the picture and warns about land cut by the wrapping seam.'),
200
200
  bandPx: z
201
201
  .number()
202
202
  .int()
@@ -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();