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
package/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.12.0 - 2026-11-08
6
+
7
+ - `create_world.synthesisCheck` reports every blocking problem it can find in one preview. A ZIN map write on 6 November needed six attempts, one blocked problem each; four of the six never appeared in a preview, and the check stopped at its first error. The check now lists, together and each as a blocker: realm points that cannot be placed, cities and capitals on impassable land (found from the impassable mask before the synthesis instead of after the partition), rivers that cannot reach their mouths, and passes that are not lower than their crest, which are now checked even when a river fails. A write still stops at its first blocking problem, and a city on impassable land is now refused before the synthesis instead of after the partition, with the same code and message. Leaks through a wall still need the partition, so only a write reports them.
8
+ - Release workflow: the npm and GHCR publication checks call the GitHub API with the job's token, check the release tag once before they wait for the registry, and wait up to 20 minutes for npm instead of 5. The 4.11.1 run published to npm, but npm held the version for processing longer than 5 minutes; the check retried the anonymous tag lookup every 5 seconds until GitHub refused it (403) and the release stopped before the image, GitHub release and MCP Registry steps.
9
+ - Answer the stdio handshake before startup recovery. The server checked every retained rewrite journal before it answered `initialize`, and each applied `create_world` leaves a journal of about 7 MB, so a mod with eight map writes took 4 to 5 seconds to connect (7.5 seconds with five clients starting at once, 8.7 seconds cold) and clients that allow 30 seconds gave up under load. The stdio server now answers `initialize`, `ping`, `server/discover`, `tools/list`, `prompts/list` and `logging/setLevel` at once, recovers in the background, and holds every other request, in arrival order, until recovery ends, so no call reads or writes a workspace before its interrupted rewrite is recovered. Measured on a configuration with six mods and 28 MB of map journals, the handshake takes 1.1 to 1.2 seconds (1.8 to 1.9 seconds for five at once); the first tool call waits for the rest. More than 128 held requests, or a failed recovery, closes the connection without answering them. The HTTP server still recovers before it listens.
10
+ - Add `create_world.inheritedContinents` (`keep` by default, or `drop`). With `drop`, `continent.txt` lists only the generated continents instead of also every continent of the active `continent.txt`, so a total conversion no longer shows the base game's continents in the trade window. Each active script reference to a dropped continent is reported with its file and line as `MAP_CONTINENT_DROPPED_REFERENCED` (warning): `is_on_continent`, `continent =` in `any_state_in` and its effects, AI areas' `continents` lists and portrait pools' `continent = { name = ... }`. Requests without the field are unchanged.
11
+ - Impassable land no longer joins landmasses, strategic regions or countries in `create_world`. The `wall` edge connected a landmass at the east edge with one at the west edge across the seam into one continent, and a strategic region could run over the wall from one edge to the other; land that only a painted or regional impassable strip connected was one continent too. Continents and land regions are now grouped over passable land. Each piece of impassable land takes the continent of the largest landmass it borders (or of the nearest one, when it borders only water), and joins the passable region it borders most when it is no larger than a region, or forms regions of its own. Generated countries and workspace realms also grow over passable land only, so a realm seeded at the east edge no longer takes land at the west edge over the wall; land reached only that way follows the island rule. Impassable provinces take no owner while countries grow, and their states take the owner of the passable state they link to (`force_link_ownership_to`). Worlds without impassable land are unchanged.
12
+ - Move the probability adapters' pin to game 1.19.4.2. The six documentation files they rest on and every vanilla example are unchanged from the 1.19.4.1 review, so no adapter rule changed: the target is `Operation Postern 1.19.4.2 (0bdb)` and the adapter version `hoi4-1.19.4.2.v1`. The native-effects fallback list is regenerated from the same documentation (identical list). A result on another build still carries `PROBABILITY_GAME_BUILD_UNVERIFIED`.
13
+ - Run `hoi4.mod_index` on the shared Rust engine (`hoi4-engine mod-index`, ADR 0080; M-8 step 1). The engine's new shared symbol index (`symbol_index`) reproduces the TypeScript index's kinds, definition rules and `overridden` rule, so the answers do not change: on vanilla 1.19.4.2, Chaos Redux, ZIN, Ireland Total Overhaul, Atlantis, Kaiserreich and Old World Blues, for the mod layer and every layer, each (kind, id, overridden) record, file count, completeness flag, folder total and namespace matches the TypeScript scan, and so do 203 `next_id` answers (`scripts/mod-index-parity.ts`). A first overview of Chaos Redux takes 5 s instead of 23 s, and a repeated one 1 s instead of 5 s. Without a usable engine the tool answers `ENGINE_UNAVAILABLE`; nothing is counted in TypeScript instead. `hoi4-engine symbol-index` prints every record of the index. The tests now need a cargo build of the engine, which CI and the release workflow build first. The benchmark gains warm `mod_index` cases for every corpus and an every-layer case for the game.
14
+ - Move the two ChaosX tools out of the public package (maintainer decision M-14, #110, ADR 0081). `chaosx.visual_revision` and `chaosx.focus_country_assets` are gone, and `HOI4_AGENT_TOOLS_CHAOSX` does nothing. The stdio server instead loads plugins from the absolute paths the new configuration key `plugins` lists, never from a mod folder or the environment; a plugin adds tools named `<plugin>.<tool>` (never `hoi4.`), and the HTTP server never loads one. A listed plugin file that does not exist is skipped with a warning on stderr.
15
+
5
16
  ## 4.11.1 - 2026-11-07
6
17
 
7
18
  - Close impassable walls in generated maps, and keep pass saddles and point river mouths that a 4.10.0 `create_world` lost.
package/dist/bin/stdio.js CHANGED
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env node
2
+ import path from 'node:path';
2
3
  import { canonicalJson } from '../hoi4_agent_tools/core/canonical.js';
3
4
  import { StdioFrameLimitError, StdioInvalidMessageError, StdioInvalidUtf8Error, } from '../hoi4_agent_tools/mcp/transports/bounded-stdio.js';
4
5
  import { serveNegotiatedStdio } from '../hoi4_agent_tools/mcp/transports/negotiated-stdio.js';
5
6
  import { ServerRegistry } from '../hoi4_agent_tools/core/server-registry.js';
6
7
  import { StdioLifetime } from '../hoi4_agent_tools/mcp/transports/stdio-lifetime.js';
8
+ import { loadPlugins } from '../hoi4_agent_tools/mcp/plugins.js';
9
+ import { PACKAGE_VERSION } from '../hoi4_agent_tools/version.js';
7
10
  import { createEngine } from '../hoi4_agent_tools/runtime.js';
8
11
  /**
9
12
  * A client registration can set its own idle limit, because the server configuration is shared
@@ -20,10 +23,10 @@ function idleExitMinutes(configured) {
20
23
  return minutes;
21
24
  }
22
25
  async function main() {
23
- const engine = await createEngine();
24
- const chaosxTools = process.env.HOI4_AGENT_TOOLS_CHAOSX === '1'
25
- ? await import('../hoi4_agent_tools/mcp/tools/chaosx.js')
26
- : undefined;
26
+ // The handshake must not wait for journal recovery; the transport holds workspace requests.
27
+ const engine = await createEngine(undefined, { recovery: 'background' });
28
+ // Plugins load only from the paths the server configuration lists (M-14).
29
+ const plugins = await loadPlugins(engine.resolver.config().plugins, PACKAGE_VERSION, (file, reason) => process.stderr.write(`${canonicalJson({ level: 'warn', event: 'plugin_skipped', plugin: path.basename(file), reason })}\n`));
27
30
  const onerror = (error) => {
28
31
  const fatalInputError = error instanceof StdioFrameLimitError || error instanceof StdioInvalidUtf8Error;
29
32
  const rejectedMessage = error instanceof StdioInvalidMessageError;
@@ -65,12 +68,7 @@ async function main() {
65
68
  : {}),
66
69
  })}\n`);
67
70
  },
68
- ...(chaosxTools === undefined
69
- ? {}
70
- : {
71
- createModernPrivateTools: chaosxTools.createChaosxToolOperations,
72
- registerLegacy: (server) => chaosxTools.registerChaosxTools(server, engine, {}),
73
- }),
71
+ ...(plugins === undefined ? {} : { plugins }),
74
72
  });
75
73
  closeTransport = () => transport.close();
76
74
  lifetime.start();
@@ -151,6 +151,19 @@ export const serverConfigurationSchema = z
151
151
  jobDeadlineSeconds: z.number().int().min(1).max(86_400).default(1_800),
152
152
  /** A read-only job that has not stopped this long after cancellation is stopped. */
153
153
  jobCancelGraceSeconds: z.number().int().min(1).max(600).default(10),
154
+ /**
155
+ * Absolute paths of plugin modules (.mjs or .js) the stdio server loads (M-14). A plugin adds
156
+ * its own tools; the server loads nothing from a mod folder or the environment. A listed file
157
+ * that does not exist is skipped, so a shared configuration can name a private plugin.
158
+ */
159
+ plugins: z
160
+ .array(z
161
+ .string()
162
+ .min(1)
163
+ .max(1024)
164
+ .refine((value) => path.isAbsolute(value), 'A plugin path must be absolute'))
165
+ .max(8)
166
+ .default([]),
154
167
  /** A stdio server with no client traffic or open request for this long exits; 0 never. */
155
168
  stdioIdleExitMinutes: z.number().int().min(0).max(10_080).default(0),
156
169
  /** V8 heap ceiling for each job worker in MiB; unset keeps Node's default. */
@@ -35,7 +35,8 @@ function under(roots, glob) {
35
35
  function englishLocalisationPatterns(roots) {
36
36
  return [...under(roots, 'english/**/*.{yml,yaml}'), ...under(roots, '*.{yml,yaml}')];
37
37
  }
38
- function defaultPatterns(workspace) {
38
+ /** The glob patterns of the shared scan, relative to each root. `hoi4.mod_index` passes them to the engine. */
39
+ export function defaultPatterns(workspace) {
39
40
  const roots = workspace.registration.roots;
40
41
  return [
41
42
  ...new Set([
@@ -101,6 +102,7 @@ export class CoreEngine {
101
102
  #scanGenerations = new Map();
102
103
  #scanAdmissionQueue = [];
103
104
  #activeScanAdmissions = new Set();
105
+ #recovery;
104
106
  constructor(resolver, services = {}) {
105
107
  this.resolver = resolver;
106
108
  this.indexSegments = services.indexSegments ?? new IndexSegmentCache();
@@ -131,7 +133,21 @@ export class CoreEngine {
131
133
  services.transactions ??
132
134
  new TransactionManager(resolver, this.artifacts, RECOVERY_TTL_SECONDS, RECOVERY_MAX_BYTES, RECOVERY_MAX_RECORDS, resolver.serverState());
133
135
  }
134
- async initialize() {
136
+ /**
137
+ * Recover interrupted internal rewrites in every workspace. A stdio server starts this in the
138
+ * background and answers the client handshake meanwhile; it holds workspace requests until
139
+ * {@link recovered} settles.
140
+ */
141
+ initialize() {
142
+ const recovery = this.#recoverWorkspaces();
143
+ this.#recovery = recovery;
144
+ return recovery;
145
+ }
146
+ /** Settles when the latest {@link initialize} has finished, at once when none was started. */
147
+ recovered() {
148
+ return this.#recovery ?? Promise.resolve();
149
+ }
150
+ async #recoverWorkspaces() {
135
151
  for (const workspace of this.resolver.list()) {
136
152
  // Recovery repairs an interrupted internal rewrite before the workspace is exposed. A
137
153
  // journal that cannot be recovered blocks rewrites of its own workspace, not the server.
@@ -42,7 +42,7 @@ const ownerSchema = z
42
42
  .strict();
43
43
  const requestSchema = z
44
44
  .object({
45
- toolName: z.string().regex(/^(?:hoi4|chaosx)\.[a-z_]+$/u),
45
+ toolName: z.string().regex(/^hoi4\.[a-z_]+$/u),
46
46
  arguments: z.record(z.string(), z.json()),
47
47
  mutation: z.boolean(),
48
48
  requestKey: z.string().min(1).max(256).optional(),
@@ -2,7 +2,7 @@
2
2
  * Native effect identifiers used to distinguish direct scripted-effect calls
3
3
  * from engine effects while importing focus completion rewards.
4
4
  *
5
- * Generated by scripts/generate-native-effects.ts from the HOI4 1.19.4.1 effects
5
+ * Generated by scripts/generate-native-effects.ts from the HOI4 1.19.4.2 effects
6
6
  * documentation. This is the fallback list; analysis also accepts every effect the installed
7
7
  * game documents in documentation/effects_documentation.md, so effects added by later patches
8
8
  * are recognized. The nightly game-update watcher regenerates it for review on a new build.
@@ -6,7 +6,7 @@ import { applyReplacements, assignments, encodeSource, parseLocalisation, parseC
6
6
  import { rgbKey } from './bmp.js';
7
7
  import { MAP_MASK_CELL_LIMIT, MAP_POLYGON_WORK_LIMIT, MAP_SELECTED_OFFSET_BYTES, MAP_SELECTED_PIXEL_LIMIT, } from './limits.js';
8
8
  import { derivedStateCapital, encodeTextDocument, LEVEL_STATE_BUILDINGS, MapWorkspaceIndex, parseMapDate, parseTextDocument, } from './model.js';
9
- import { planReferenceRemap, ReferenceRemapError } from './references.js';
9
+ import { collectContinentReferences, droppedContinentDiagnostics, planReferenceRemap, ReferenceRemapError, } from './references.js';
10
10
  import { generateWorld } from './world.js';
11
11
  import { resolveEdge } from './world-edge.js';
12
12
  import { DEFAULT_AUTO_STRAIT_GAP_PX } from './gameplay/crossings.js';
@@ -3421,6 +3421,7 @@ function applyCreateWorld(base, changes, operation, context, signal) {
3421
3421
  ...(operation.continentNames === undefined
3422
3422
  ? {}
3423
3423
  : { continentNames: operation.continentNames }),
3424
+ ...(operation.inheritedContinents === 'drop' ? { inheritedContinents: 'drop' } : {}),
3424
3425
  startDate: operation.startDate ?? '1936.1.1',
3425
3426
  rivers: typeof operation.rivers === 'number' ? operation.rivers : reference === undefined ? 8 : 80,
3426
3427
  ...(geography === undefined
@@ -3482,13 +3483,17 @@ function applyCreateWorld(base, changes, operation, context, signal) {
3482
3483
  message: note.message,
3483
3484
  ...(note.details === undefined ? {} : { details: note.details }),
3484
3485
  })),
3485
- {
3486
- code: 'MAP_SYNTHESIS_CHECK_READY',
3487
- severity: 'info',
3488
- category: 'map',
3489
- operationId: operation.id,
3490
- message: `Every river of the model reaches its mouth over the synthesised relief of a ${world.summary.width}x${world.summary.height} map; nothing was written`,
3491
- },
3486
+ ...(world.notes.some(({ severity }) => severity === 'error')
3487
+ ? []
3488
+ : [
3489
+ {
3490
+ code: 'MAP_SYNTHESIS_CHECK_READY',
3491
+ severity: 'info',
3492
+ category: 'map',
3493
+ operationId: operation.id,
3494
+ message: `Every river of the model reaches its mouth over the synthesised relief of a ${world.summary.width}x${world.summary.height} map; nothing was written`,
3495
+ },
3496
+ ]),
3492
3497
  ];
3493
3498
  const roots = operation.replaceBaseGame === false
3494
3499
  ? []
@@ -3512,6 +3517,9 @@ function applyCreateWorld(base, changes, operation, context, signal) {
3512
3517
  if (roots.length > 0)
3513
3518
  addChange(changes, 'descriptor.mod', descriptorWithReplacePaths(base, roots), operation.id, 'text/plain');
3514
3519
  const generated = currentIndex(base, changes);
3520
+ // Scripts that stay active after the write and still name a continent the world dropped.
3521
+ const droppedContinents = world.droppedContinents ?? [];
3522
+ const continentReferences = collectContinentReferences(generated.activeFiles.all, new Set(droppedContinents));
3515
3523
  for (const file of planMapPositions(generated, { mode: 'replace' }))
3516
3524
  addChange(changes, file.relativePath, file.content, operation.id, 'text/plain');
3517
3525
  const positioned = currentIndex(base, changes);
@@ -3576,6 +3584,27 @@ function applyCreateWorld(base, changes, operation, context, signal) {
3576
3584
  },
3577
3585
  ]),
3578
3586
  ...worldTagDiagnostics(operation.id, tagCatalog, world, workspaceCountries !== undefined),
3587
+ ...(operation.inheritedContinents === 'drop'
3588
+ ? [
3589
+ {
3590
+ code: 'MAP_CONTINENTS_DROPPED',
3591
+ severity: 'info',
3592
+ category: 'map',
3593
+ operationId: operation.id,
3594
+ message: droppedContinents.length === 0
3595
+ ? 'continent.txt lists only the generated continents; the active sources declared no other'
3596
+ : `continent.txt lists only the generated continents and leaves out ${droppedContinents.length} inherited one(s); ${continentReferences.length} active script reference(s) still name them`,
3597
+ details: {
3598
+ dropped: droppedContinents,
3599
+ references: continentReferences.length,
3600
+ },
3601
+ },
3602
+ ...droppedContinentDiagnostics(continentReferences).map((diagnostic) => ({
3603
+ ...diagnostic,
3604
+ operationId: operation.id,
3605
+ })),
3606
+ ]
3607
+ : []),
3579
3608
  ...worldRealmDiagnostics(operation.id, world),
3580
3609
  ...(outputs.released.length === 0
3581
3610
  ? []
@@ -506,3 +506,90 @@ export function mapScriptConsistency(index) {
506
506
  }
507
507
  return { diagnostics, references: references.length, missing };
508
508
  }
509
+ /**
510
+ * Folders whose scripts may name a continent: triggers and effects anywhere in `common`, events
511
+ * and country history, the AI areas, and the portrait pools.
512
+ */
513
+ export const CONTINENT_REFERENCE_SCRIPT_PATTERNS = [
514
+ 'common/**/*.txt',
515
+ 'events/**/*.txt',
516
+ 'history/countries/**/*.txt',
517
+ 'portraits/**/*.txt',
518
+ ];
519
+ const CONTINENT_SCRIPT_FILE = /^(?:common|events|history\/countries|portraits)\/.+\.txt$/iu;
520
+ /** Every place an active script names one of `keys` as a continent, in load order. */
521
+ export function collectContinentReferences(files, keys) {
522
+ const references = [];
523
+ if (keys.size === 0)
524
+ return references;
525
+ const active = files
526
+ .filter((file) => file.shadowedBy === undefined &&
527
+ CONTINENT_SCRIPT_FILE.test(file.relativePath.replaceAll('\\', '/')))
528
+ .sort((left, right) => left.loadOrder - right.loadOrder || compareCodeUnits(left.displayPath, right.displayPath));
529
+ for (const file of active) {
530
+ // A cheap byte check skips the many files that name no continent key at all.
531
+ const text = file.bytes.toString('latin1');
532
+ if (![...keys].some((key) => text.includes(key)))
533
+ continue;
534
+ const document = parseClausewitz(file.bytes, file.displayPath);
535
+ const folder = file.relativePath.replaceAll('\\', '/').toLowerCase();
536
+ const aiAreas = folder.startsWith('common/ai_areas/');
537
+ const portraits = folder.startsWith('portraits/');
538
+ const add = (node, kind) => {
539
+ if (keys.has(node.value))
540
+ references.push({ continent: node.value, kind, file, document, node });
541
+ };
542
+ const visit = (entry) => {
543
+ if (entry.type === 'block') {
544
+ for (const child of entry.entries)
545
+ visit(child);
546
+ return;
547
+ }
548
+ if (entry.type !== 'assignment')
549
+ return;
550
+ const key = entry.key.value;
551
+ if (entry.value.type === 'scalar') {
552
+ if (key === 'is_on_continent')
553
+ add(entry.value, 'is_on_continent');
554
+ else if (key === 'continent')
555
+ add(entry.value, 'continent');
556
+ return;
557
+ }
558
+ if (aiAreas && key === 'continents')
559
+ for (const item of entry.value.entries)
560
+ if (item.type === 'scalar')
561
+ add(item, 'ai_area');
562
+ if (portraits && key === 'continent')
563
+ for (const child of entry.value.entries)
564
+ if (child.type === 'assignment' &&
565
+ child.key.value === 'name' &&
566
+ child.value.type === 'scalar')
567
+ add(child.value, 'portrait');
568
+ for (const child of entry.value.entries)
569
+ visit(child);
570
+ };
571
+ visit(document.root);
572
+ }
573
+ return references;
574
+ }
575
+ const CONTINENT_REFERENCE_FORMS = {
576
+ is_on_continent: 'is_on_continent',
577
+ continent: 'continent',
578
+ ai_area: "an AI area's continents",
579
+ portrait: "a portrait pool's continent",
580
+ };
581
+ /** One warning for each script reference to a continent the new `continent.txt` leaves out. */
582
+ export function droppedContinentDiagnostics(references) {
583
+ return references.map((reference) => ({
584
+ code: 'MAP_CONTINENT_DROPPED_REFERENCED',
585
+ severity: 'warning',
586
+ category: 'map',
587
+ message: `${reference.file.relativePath} names the dropped continent ${reference.continent} (${CONTINENT_REFERENCE_FORMS[reference.kind]}); the new continent.txt no longer declares it`,
588
+ location: nodeLocation(reference.document, reference.node),
589
+ details: {
590
+ continent: reference.continent,
591
+ kind: reference.kind,
592
+ layer: reference.file.rootKind,
593
+ },
594
+ }));
595
+ }
@@ -750,10 +750,14 @@ function routeNamedRivers(context) {
750
750
  }
751
751
  }
752
752
  }
753
- void notes;
754
753
  if (failures.length > 0) {
755
754
  const first = failures[0];
756
- fail('MAP_RIVER_UNREACHABLE_MOUTH', failures.length === 1
755
+ const report = context.collectUnreachable
756
+ ? (code, message, details) => {
757
+ notes.push({ code, severity: 'error', message, details });
758
+ }
759
+ : fail;
760
+ report('MAP_RIVER_UNREACHABLE_MOUTH', failures.length === 1
757
761
  ? `River ${first.riverId} cannot reach its mouth: ${first.reason}`
758
762
  : `${failures.length} rivers cannot reach their mouths: ${failures
759
763
  .slice(0, 12)
@@ -1326,6 +1330,7 @@ export function synthesizeHydrology(input) {
1326
1330
  notes,
1327
1331
  seed,
1328
1332
  signal: input.signal,
1333
+ collectUnreachable: input.collectUnreachable,
1329
1334
  });
1330
1335
  // Burn the channels into the heights and flood again with the channels as outlets, so every
1331
1336
  // other cell drains either to the coast or into a channel.
@@ -128,6 +128,7 @@ export function checkTerrainRivers(input) {
128
128
  rainfall: input.rainfall,
129
129
  landPixels,
130
130
  signal: input.signal,
131
+ collectUnreachable: true,
131
132
  });
132
133
  const notes = [...hydrology.notes];
133
134
  // The pass test of the write, on the macro grid: a declared pass must be a saddle lower than
@@ -1,4 +1,4 @@
1
- import { MAP_REFERENCE_SCRIPT_PATTERNS, mapScriptConsistency } from './references.js';
1
+ import { CONTINENT_REFERENCE_SCRIPT_PATTERNS, MAP_REFERENCE_SCRIPT_PATTERNS, mapScriptConsistency, } from './references.js';
2
2
  import path from 'node:path';
3
3
  import { escapeFileGlob } from '../core/file-glob.js';
4
4
  import { ArtifactStore, boundedSourceHashEvidence, publicArtifactLink, } from '../core/artifacts.js';
@@ -627,7 +627,7 @@ export class AgentNudger {
627
627
  this.scanner = this.engine.scanner;
628
628
  this.transactions = this.engine.transactions;
629
629
  }
630
- async scan(workspaceId, principal, signal, includeExternalScriptReferences = false, includeWorldContext = false, includeAppearance = false, includeBorderInputs = false) {
630
+ async scan(workspaceId, principal, signal, includeExternalScriptReferences = false, includeWorldContext = false, includeAppearance = false, includeBorderInputs = false, includeContinentReferences = false) {
631
631
  signal?.throwIfAborted();
632
632
  const workspace = this.resolver.get(workspaceId, principal);
633
633
  const sourceRoots = {
@@ -688,14 +688,23 @@ export class AgentNudger {
688
688
  ],
689
689
  }, principal, signal)
690
690
  : undefined;
691
+ // Scripts that may name a continent, read when a new world drops the inherited continents.
692
+ const continentSnapshot = includeContinentReferences
693
+ ? await this.engine.scan(workspaceId, { patterns: [...CONTINENT_REFERENCE_SCRIPT_PATTERNS] }, principal, signal)
694
+ : undefined;
691
695
  signal?.throwIfAborted();
692
- const files = [
696
+ const collected = [
693
697
  ...contentSnapshot.files,
694
698
  ...locatorSnapshot.files,
695
699
  ...(externalScriptSnapshot?.files ?? []),
696
700
  ...(worldContextSnapshot?.files ?? []).filter((file) => !contentSnapshot.files.some((existing) => existing.displayPath === file.displayPath)),
697
701
  ...(appearanceSnapshot?.files ?? []).filter((file) => ![...contentSnapshot.files, ...(worldContextSnapshot?.files ?? [])].some((existing) => existing.displayPath === file.displayPath)),
698
702
  ...(generatedOutputsSnapshot?.files ?? []).filter((file) => ![...contentSnapshot.files, ...(worldContextSnapshot?.files ?? [])].some((existing) => existing.displayPath === file.displayPath)),
703
+ ];
704
+ const collectedPaths = new Set(collected.map(({ displayPath }) => displayPath));
705
+ const files = [
706
+ ...collected,
707
+ ...(continentSnapshot?.files ?? []).filter((file) => !collectedPaths.has(file.displayPath)),
699
708
  ].sort((left, right) => left.loadOrder - right.loadOrder || compareCodeUnits(left.displayPath, right.displayPath));
700
709
  const revision = hashCanonical(files.map(({ displayPath, loadOrder, sha256 }) => ({ displayPath, loadOrder, sha256 })));
701
710
  return {
@@ -735,7 +744,7 @@ export class AgentNudger {
735
744
  signal?.throwIfAborted();
736
745
  const snapshot = await this.scan(workspaceId, principal, signal, operations.some((operation) => operation.kind === 'renumber_map_entity' ||
737
746
  operation.kind === 'remap_map_references' ||
738
- 'remapReferences' in operation), operations.some((operation) => operation.kind === 'create_world'), false, operations.some((operation) => operation.kind === 'assign_territory' || operation.kind === 'repartition_states'));
747
+ 'remapReferences' in operation), operations.some((operation) => operation.kind === 'create_world'), false, operations.some((operation) => operation.kind === 'assign_territory' || operation.kind === 'repartition_states'), operations.some((operation) => operation.kind === 'create_world' && operation.inheritedContinents === 'drop'));
739
748
  const referenceWorlds = new Map();
740
749
  const referenceImages = [];
741
750
  const referenceLoads = new Map();
@@ -616,12 +616,18 @@ async function previewSynthesisCheck(nudger, input, context) {
616
616
  },
617
617
  ],
618
618
  };
619
+ // Every blocking problem the check found is listed, not only the first (one fix round, not six).
619
620
  result.blockers = [
620
621
  ...checked.plan.blockers.map(({ code, message, details }) => ({
621
622
  code,
622
623
  message,
623
624
  ...(details === undefined ? {} : { details }),
624
625
  })),
626
+ ...blocked.map(({ code, message, details }) => ({
627
+ code,
628
+ message,
629
+ ...(details === undefined ? {} : { details }),
630
+ })),
625
631
  ].slice(0, 100);
626
632
  await context.progress(2, 2, 'River check complete; nothing was written');
627
633
  return result;