hoi4-agent-tools 4.7.0 → 4.9.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.
- package/CHANGELOG.md +34 -0
- package/README.md +32 -13
- package/dist/hoi4_agent_tools/core/engine-client.js +74 -5
- package/dist/hoi4_agent_tools/core/index.js +28 -0
- package/dist/hoi4_agent_tools/core/operation-result.js +9 -0
- package/dist/hoi4_agent_tools/core/resident-engine.js +273 -0
- package/dist/hoi4_agent_tools/core/temporary-directories.js +3 -2
- package/dist/hoi4_agent_tools/decision/service.js +46 -2
- package/dist/hoi4_agent_tools/event/queries.js +25 -2
- package/dist/hoi4_agent_tools/event/service.js +78 -11
- package/dist/hoi4_agent_tools/event/summary.js +9 -0
- package/dist/hoi4_agent_tools/focus/engine-layout.js +1 -1
- package/dist/hoi4_agent_tools/focus/game-render.js +72 -0
- package/dist/hoi4_agent_tools/focus/game-view-output.js +160 -0
- package/dist/hoi4_agent_tools/focus/native-effects.js +4 -4
- package/dist/hoi4_agent_tools/focus/quality/focus-quality-calibration.json +241 -241
- package/dist/hoi4_agent_tools/focus/quality/orthogonal.js +30 -19
- package/dist/hoi4_agent_tools/focus/quality/schematic.js +5 -3
- package/dist/hoi4_agent_tools/focus/quality/scorecard.js +1 -1
- package/dist/hoi4_agent_tools/focus/render.js +21 -9
- package/dist/hoi4_agent_tools/focus/tool-operations.js +158 -3
- package/dist/hoi4_agent_tools/gui/assets.js +18 -0
- package/dist/hoi4_agent_tools/gui/dds.js +38 -5
- package/dist/hoi4_agent_tools/gui/engine-textures.js +48 -0
- package/dist/hoi4_agent_tools/gui/source-graph.js +7 -0
- package/dist/hoi4_agent_tools/gui/tool-operations.js +23 -4
- package/dist/hoi4_agent_tools/gui/validators.js +31 -2
- package/dist/hoi4_agent_tools/ideas/inspect.js +43 -0
- package/dist/hoi4_agent_tools/impact/service.js +15 -0
- package/dist/hoi4_agent_tools/localisation/inspect.js +34 -0
- package/dist/hoi4_agent_tools/map/appearance-validation.js +14 -2
- package/dist/hoi4_agent_tools/map/geography/resolve.js +3 -2
- package/dist/hoi4_agent_tools/map/tool-operations.js +41 -0
- package/dist/hoi4_agent_tools/map/world-edge.js +117 -15
- package/dist/hoi4_agent_tools/map/world.js +158 -34
- package/dist/hoi4_agent_tools/mcp/server/argument-errors.js +59 -9
- package/dist/hoi4_agent_tools/mcp/server/create-modern-operations.js +1 -1
- package/dist/hoi4_agent_tools/mcp/server/request-lifecycle.js +1 -1
- package/dist/hoi4_agent_tools/mcp/tools/analysis.js +4 -2
- package/dist/hoi4_agent_tools/mcp/tools/event.js +15 -0
- package/dist/hoi4_agent_tools/mcp/tools/focus.js +1 -1
- package/dist/hoi4_agent_tools/mcp/tools/gui.js +1 -1
- package/dist/hoi4_agent_tools/mcp/tools/reference.js +43 -0
- package/dist/hoi4_agent_tools/probability/operations.js +27 -1
- package/dist/hoi4_agent_tools/probability/service.js +91 -11
- package/dist/hoi4_agent_tools/probability/source-analysis.js +2 -2
- package/dist/hoi4_agent_tools/probability/sweep.js +20 -6
- package/dist/hoi4_agent_tools/reference/command-phrases.json +11065 -0
- package/dist/hoi4_agent_tools/reference/error-log.js +59 -1
- package/dist/hoi4_agent_tools/reference/known-mistakes.js +8 -5
- package/dist/hoi4_agent_tools/reference/known-mistakes.json +4 -4
- package/dist/hoi4_agent_tools/reference/operations.js +205 -12
- package/dist/hoi4_agent_tools/reference/ranking.js +32 -0
- package/dist/hoi4_agent_tools/reference/script-validation.js +159 -8
- package/dist/hoi4_agent_tools/reference/service.js +33 -0
- package/dist/hoi4_agent_tools/reference/source-lookup.js +8 -0
- package/dist/hoi4_agent_tools/schemas/focus-requests.js +4 -0
- package/dist/hoi4_agent_tools/schemas/ideas.js +142 -0
- package/dist/hoi4_agent_tools/schemas/localisation.js +94 -0
- package/dist/hoi4_agent_tools/schemas/map.js +32 -4
- package/dist/hoi4_agent_tools/schemas/mod-tools.js +11 -0
- package/dist/hoi4_agent_tools/schemas/script-validation.js +8 -1
- package/dist/hoi4_agent_tools/schemas/system.js +157 -0
- package/dist/hoi4_agent_tools/system/inspect.js +55 -0
- package/dist/hoi4_agent_tools/version.js +1 -1
- package/docs/analysis.md +2 -2
- package/docs/events.md +1 -1
- package/docs/focus.md +9 -5
- package/docs/map.md +19 -8
- package/docs/research/reference-benchmark.md +41 -0
- package/docs/tools.md +49 -39
- package/docs/troubleshooting.md +13 -12
- package/engine/README.md +293 -0
- package/engine/bin/darwin-arm64/hoi4-engine +0 -0
- package/engine/bin/linux-arm64/hoi4-engine +0 -0
- package/engine/bin/linux-x64/hoi4-engine +0 -0
- package/engine/bin/manifest.json +26 -0
- package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -1
- package/schemas/configuration.schema.json +1 -1
- package/schemas/continuous-focus-palette.schema.json +1 -1
- package/schemas/custom-weighted-pool.schema.json +1 -1
- package/schemas/decision-inspect-input.schema.json +1 -1
- package/schemas/error-log-input.schema.json +1 -1
- package/schemas/event-feature-manifest.schema.json +1 -1
- package/schemas/focus-plan.schema.json +1 -1
- package/schemas/focus-planning-sidecar.schema.json +1 -1
- package/schemas/geography-model.schema.json +1 -1
- package/schemas/gui-animation-source.schema.json +1 -1
- package/schemas/gui-helper.schema.json +1 -1
- package/schemas/gui-scenario.schema.json +1 -1
- package/schemas/helper-expansion-request.schema.json +1 -1
- package/schemas/helper-expansion-summary.schema.json +1 -1
- package/schemas/impact-inspect-input.schema.json +1 -1
- package/schemas/map-operation.schema.json +165 -101
- package/schemas/mechanic-test-input.schema.json +1 -1
- package/schemas/mod-index-input.schema.json +1 -1
- package/schemas/operation-result.schema.json +1 -1
- package/schemas/package-check-input.schema.json +1 -1
- package/schemas/package-manifest.schema.json +1 -1
- package/schemas/probability-analysis-result.schema.json +1 -1
- package/schemas/probability-compare-input.schema.json +1 -1
- package/schemas/probability-evaluate-input.schema.json +1 -1
- package/schemas/probability-inspect-input.schema.json +1 -1
- package/schemas/probability-render-input.schema.json +1 -1
- package/schemas/probability-scenario-set.schema.json +1 -1
- package/schemas/probability-sequence-input.schema.json +1 -1
- package/schemas/probability-simulate-input.schema.json +1 -1
- package/schemas/probability-sweep-input.schema.json +1 -1
- package/schemas/reference-context-input.schema.json +1 -1
- package/schemas/reference-read-input.schema.json +1 -1
- package/schemas/reference-search-input.schema.json +1 -1
- package/schemas/reference-sheets.schema.json +1 -1
- package/schemas/scenario-suite.schema.json +1 -1
- package/schemas/scenario-test-input.schema.json +1 -1
- package/schemas/script-validate-input.schema.json +1 -1
- package/schemas/shared-scenario.schema.json +1 -1
- package/schemas/source-lookup-input.schema.json +1 -1
- package/server.json +2 -2
|
@@ -3,6 +3,7 @@ import { sortDiagnostics } from '../core/diagnostics.js';
|
|
|
3
3
|
import { sha256Bytes } from '../core/canonical.js';
|
|
4
4
|
import { assertRenderDimensions } from '../core/render-budget.js';
|
|
5
5
|
import { GuiAssetCatalog } from './assets.js';
|
|
6
|
+
import { RISKY_TEXTURE_FORMATS } from './engine-textures.js';
|
|
6
7
|
import { GUI_GRAPH_MAX_EDGES, GUI_GRAPH_MAX_NODES, GUI_SCENE_MAX_ELEMENTS, GUI_VALIDATION_MAX_ANCESTOR_HOPS, GUI_VALIDATION_MAX_DIAGNOSTICS, GUI_VALIDATION_MAX_PAIR_COMPARISONS, } from './limits.js';
|
|
7
8
|
/** Horizontal offsets from a parent's centre above rounding and up to a few pixels look accidental. */
|
|
8
9
|
const NEAR_CENTRE_TOLERANCE_PX = 0.5;
|
|
@@ -434,6 +435,31 @@ function validateSourceCosts(graph, scene, diagnostics) {
|
|
|
434
435
|
}
|
|
435
436
|
}
|
|
436
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* A plain image drawn beneath an element that lies wholly inside it is a background, frame or
|
|
440
|
+
* fill layer, not a collision: panels sit under their titles and frames sit over their fills.
|
|
441
|
+
*/
|
|
442
|
+
function isBackdropLayering(left, right) {
|
|
443
|
+
const isBackdrop = (candidate, other) => candidate.text === undefined &&
|
|
444
|
+
!candidate.clickable &&
|
|
445
|
+
candidate.sprite !== undefined &&
|
|
446
|
+
candidate.zIndex <= other.zIndex &&
|
|
447
|
+
contains(candidate.rect, other.rect, 0.5);
|
|
448
|
+
return isBackdrop(left, right) || isBackdrop(right, left);
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Meters slide a fill image through a clipping window: an icon parked beyond the leading edge
|
|
452
|
+
* is the empty state. Only an image that never reaches past the window's far edges counts, so
|
|
453
|
+
* an icon overflowing to the right or bottom is still reported.
|
|
454
|
+
*/
|
|
455
|
+
function isSlidingFill(element) {
|
|
456
|
+
const clip = element.clipRect;
|
|
457
|
+
if (clip === undefined || element.text !== undefined || element.clickable)
|
|
458
|
+
return false;
|
|
459
|
+
const rect = element.unclippedRect;
|
|
460
|
+
return (rect.x + rect.width <= clip.x + clip.width + 0.5 &&
|
|
461
|
+
rect.y + rect.height <= clip.y + clip.height + 0.5);
|
|
462
|
+
}
|
|
437
463
|
function validateOverlapAndGeometry(scene, diagnostics, work) {
|
|
438
464
|
const visible = scene.elements.filter((element) => element.visible && area(element.rect) > 0);
|
|
439
465
|
const byId = new Map(scene.elements.map((element) => [element.id, element]));
|
|
@@ -454,7 +480,7 @@ function validateOverlapAndGeometry(scene, diagnostics, work) {
|
|
|
454
480
|
if (element.unclippedRect.width <= 0 || element.unclippedRect.height <= 0) {
|
|
455
481
|
diagnostics.push(issue('GUI_INVALID_SIZE', 'warning', 'layout', `${element.name} has a non-positive ${element.unclippedRect.width}x${element.unclippedRect.height} size.`, element));
|
|
456
482
|
}
|
|
457
|
-
if (element.clipped)
|
|
483
|
+
if (element.clipped && !isSlidingFill(element))
|
|
458
484
|
diagnostics.push(issue('GUI_ACCIDENTAL_CLIPPING', 'warning', 'layout', `${element.name} is clipped from ${element.unclippedRect.width}x${element.unclippedRect.height} to ${element.rect.width}x${element.rect.height}.`, element));
|
|
459
485
|
if (element.text?.overflowX === true || element.text?.overflowY === true) {
|
|
460
486
|
diagnostics.push(issue('GUI_TEXT_OVERFLOW', 'warning', 'layout', `${element.name} text measures ${element.text.measuredWidth.toFixed(2)}x${element.text.measuredHeight.toFixed(2)} inside ${element.unclippedRect.width.toFixed(2)}x${element.unclippedRect.height.toFixed(2)}.`, element));
|
|
@@ -501,7 +527,7 @@ function validateOverlapAndGeometry(scene, diagnostics, work) {
|
|
|
501
527
|
if (left.clickable && right.clickable && ratio > 0.02) {
|
|
502
528
|
diagnostics.push(issue('GUI_CONFLICTING_CLICK_REGIONS', 'error', 'design', `${left.name} and ${right.name} have overlapping click regions (${(ratio * 100).toFixed(1)}%).`, right, { left: left.id, right: right.id, ratio }));
|
|
503
529
|
}
|
|
504
|
-
if (left.depth === right.depth && ratio > 0.2) {
|
|
530
|
+
if (left.depth === right.depth && ratio > 0.2 && !isBackdropLayering(left, right)) {
|
|
505
531
|
diagnostics.push(issue('GUI_VISIBLE_OVERLAP', 'warning', 'layout', `${left.name} and ${right.name} overlap by ${(ratio * 100).toFixed(1)}% of the smaller element.`, right, { left: left.id, right: right.id, ratio }));
|
|
506
532
|
}
|
|
507
533
|
const later = left.zIndex > right.zIndex ? left : right;
|
|
@@ -966,6 +992,9 @@ async function validateGuiAnimationsInto(graph, files, selectedSpriteNames, cata
|
|
|
966
992
|
add(sprite.frameAnimated ? 'GUI_ANIMATION_TEXTURE_UNSUPPORTED' : 'GUI_TEXTURE_UNSUPPORTED', 'error', `${sprite.name}: ${raster.reason ?? 'texture unsupported'}`);
|
|
967
993
|
continue;
|
|
968
994
|
}
|
|
995
|
+
const risk = RISKY_TEXTURE_FORMATS[raster.format];
|
|
996
|
+
if (risk !== undefined)
|
|
997
|
+
add('GUI_TEXTURE_FORMAT_RISKY', 'warning', `${sprite.name}: ${sprite.texturePath} is ${raster.format}, which the preview draws. ${risk}`);
|
|
969
998
|
const safeFrameCount = Math.max(1, sprite.frameCount);
|
|
970
999
|
if (raster.width % safeFrameCount !== 0)
|
|
971
1000
|
add(sprite.frameAnimated
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { runEngineCommand } from '../core/engine-client.js';
|
|
2
|
+
import { ServiceError } from '../core/result.js';
|
|
3
|
+
import { ideaEngineAuditSchema, ideaEngineInspectionSchema, } from '../schemas/ideas.js';
|
|
4
|
+
/** A whole-mod audit of a large mod reads every idea, character, sprite and name. */
|
|
5
|
+
const IDEAS_TIMEOUT_MS = 180_000;
|
|
6
|
+
/**
|
|
7
|
+
* `hoi4.idea_inspect` on the shared Rust engine (`hoi4-engine ideas`). This side passes the
|
|
8
|
+
* workspace's roots and turns the engine's answer into the tool's data. A missing engine is
|
|
9
|
+
* `ENGINE_UNAVAILABLE`, with no TypeScript fallback.
|
|
10
|
+
*/
|
|
11
|
+
export async function inspectIdeas(workspace, input, signal) {
|
|
12
|
+
const started = Date.now();
|
|
13
|
+
const request = {
|
|
14
|
+
...(workspace.gameRoot === undefined ? {} : { game: workspace.gameRoot }),
|
|
15
|
+
...(workspace.registration.kind === 'game' ? {} : { mod: workspace.modRoot }),
|
|
16
|
+
dependencies: workspace.dependencyRoots,
|
|
17
|
+
includeDlc: workspace.dlcLayers.length > 0,
|
|
18
|
+
kind: input.kind,
|
|
19
|
+
...(input.id === undefined ? {} : { id: input.id }),
|
|
20
|
+
audit: input.audit,
|
|
21
|
+
limit: input.limit,
|
|
22
|
+
};
|
|
23
|
+
const options = { timeoutMs: IDEAS_TIMEOUT_MS, ...(signal === undefined ? {} : { signal }) };
|
|
24
|
+
if (input.audit) {
|
|
25
|
+
const result = await runEngineCommand('ideas', request, ideaEngineAuditSchema, options);
|
|
26
|
+
if (!result.available)
|
|
27
|
+
throw new ServiceError('ENGINE_UNAVAILABLE', result.message, { reason: result.reason });
|
|
28
|
+
if (result.outcome === 'invalid_request')
|
|
29
|
+
throw new ServiceError(result.error.code, result.error.message);
|
|
30
|
+
return { audit: result.response, durationMs: Date.now() - started };
|
|
31
|
+
}
|
|
32
|
+
const result = await runEngineCommand('ideas', request, ideaEngineInspectionSchema, options);
|
|
33
|
+
if (!result.available)
|
|
34
|
+
throw new ServiceError('ENGINE_UNAVAILABLE', result.message, { reason: result.reason });
|
|
35
|
+
if (result.outcome === 'invalid_request')
|
|
36
|
+
throw new ServiceError(result.error.code, result.error.message);
|
|
37
|
+
const inspection = result.response;
|
|
38
|
+
if (!inspection.found) {
|
|
39
|
+
const suggestions = inspection.suggestions ?? [];
|
|
40
|
+
throw new ServiceError(input.kind === 'idea' ? 'IDEA_NOT_FOUND' : 'CHARACTER_NOT_FOUND', `No loaded file defines the ${input.kind} ${input.id ?? ''}${suggestions.length === 0 ? '' : `; did you mean ${suggestions.join(', ')}?`}`, { id: input.id ?? '', suggestions });
|
|
41
|
+
}
|
|
42
|
+
return { inspection, durationMs: Date.now() - started };
|
|
43
|
+
}
|
|
@@ -6,6 +6,7 @@ import { inspectImpactGraph } from '../core/impact-graph.js';
|
|
|
6
6
|
import { setInlineFilesScanned } from '../core/operation-result.js';
|
|
7
7
|
import { emptyServiceResult, ServiceError } from '../core/result.js';
|
|
8
8
|
import { buildProposedSourceOverlay } from '../core/source-overlay.js';
|
|
9
|
+
import { nearestNames } from '../reference/suggestions.js';
|
|
9
10
|
import { PACKAGE_VERSION } from '../version.js';
|
|
10
11
|
import { inspectImpactScenarioSuites } from './scenario-suites.js';
|
|
11
12
|
/** Authorized, read-only impact operation shared by ordinary calls and persistent jobs. */
|
|
@@ -35,6 +36,20 @@ export class ImpactAnalyzer {
|
|
|
35
36
|
for (const file of input.changedFiles)
|
|
36
37
|
if (!availablePaths.has(file))
|
|
37
38
|
throw new ServiceError('IMPACT_SOURCE_UNKNOWN', 'Changed file is not in the authorized source inventory or proposed overlay', { file });
|
|
39
|
+
// A symbol that nothing defines or names would answer an empty graph; say so instead (#59).
|
|
40
|
+
const indexes = [before.index, ...(overlay === undefined ? [] : [overlay.snapshot.index])];
|
|
41
|
+
const unknown = input.symbols.filter(({ kind, id }) => !indexes.some((index) => index.find(kind, id) !== undefined ||
|
|
42
|
+
index.references.some((reference) => reference.toKind === kind && reference.to === id)));
|
|
43
|
+
if (unknown.length > 0) {
|
|
44
|
+
const symbols = unknown.map(({ kind, id }) => ({
|
|
45
|
+
kind,
|
|
46
|
+
id: id.slice(0, 256),
|
|
47
|
+
suggestions: nearestNames(id, new Set(before.index.findAll(kind).map((symbol) => symbol.id))),
|
|
48
|
+
}));
|
|
49
|
+
throw new ServiceError('IMPACT_SYMBOL_NOT_FOUND', `Nothing defines or uses ${symbols
|
|
50
|
+
.map(({ kind, id, suggestions }) => `${kind} ${id}${suggestions.length === 0 ? '' : ` (did you mean ${suggestions.join(', ')}?)`}`)
|
|
51
|
+
.join('; ')}${before.complete ? '' : ' in the scanned files (the scan is incomplete)'}`, { symbols, scanComplete: before.complete });
|
|
52
|
+
}
|
|
38
53
|
const query = {
|
|
39
54
|
symbols: input.symbols,
|
|
40
55
|
changedFiles: input.changedFiles.length > 0
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { runEngineCommand } from '../core/engine-client.js';
|
|
2
|
+
import { ServiceError } from '../core/result.js';
|
|
3
|
+
import { localisationEngineResponseSchema, } from '../schemas/localisation.js';
|
|
4
|
+
/** A whole-mod audit of a large mod reads every localisation file and the mod's script. */
|
|
5
|
+
const LOCALISATION_TIMEOUT_MS = 180_000;
|
|
6
|
+
/**
|
|
7
|
+
* `hoi4.localisation_inspect` on the shared Rust engine. The engine reads the workspace's layers
|
|
8
|
+
* in load order; this side only passes the roots and turns its answer into the tool's data. A
|
|
9
|
+
* missing engine is `ENGINE_UNAVAILABLE`, with no TypeScript fallback.
|
|
10
|
+
*/
|
|
11
|
+
export async function inspectLocalisation(workspace, input, signal) {
|
|
12
|
+
const started = Date.now();
|
|
13
|
+
const isGame = workspace.registration.kind === 'game';
|
|
14
|
+
const result = await runEngineCommand('localisation', {
|
|
15
|
+
...(workspace.gameRoot === undefined ? {} : { game: workspace.gameRoot }),
|
|
16
|
+
...(isGame ? {} : { mod: workspace.modRoot }),
|
|
17
|
+
dependencies: workspace.dependencyRoots,
|
|
18
|
+
includeDlc: workspace.dlcLayers.length > 0,
|
|
19
|
+
mode: input.mode,
|
|
20
|
+
...(input.key === undefined ? {} : { key: input.key }),
|
|
21
|
+
...(input.language === undefined ? {} : { language: input.language }),
|
|
22
|
+
limit: input.limit,
|
|
23
|
+
}, localisationEngineResponseSchema, { timeoutMs: LOCALISATION_TIMEOUT_MS, ...(signal === undefined ? {} : { signal }) });
|
|
24
|
+
if (!result.available)
|
|
25
|
+
throw new ServiceError('ENGINE_UNAVAILABLE', result.message, { reason: result.reason });
|
|
26
|
+
if (result.outcome === 'invalid_request')
|
|
27
|
+
throw new ServiceError(result.error.code, result.error.message);
|
|
28
|
+
const answer = result.response;
|
|
29
|
+
if (answer.key?.found === false) {
|
|
30
|
+
const suggestions = answer.key.suggestions ?? [];
|
|
31
|
+
throw new ServiceError('LOCALISATION_KEY_NOT_FOUND', `No language defines ${input.key ?? ''}${suggestions.length === 0 ? '' : `; did you mean ${suggestions.join(', ')}?`}`, { key: input.key ?? '', suggestions, mentions: answer.key.mentions.length });
|
|
32
|
+
}
|
|
33
|
+
return { ...answer, durationMs: Date.now() - started };
|
|
34
|
+
}
|
|
@@ -1046,11 +1046,23 @@ function* validateLakesAndEdge(index, raster, report, options) {
|
|
|
1046
1046
|
pairs.add(`${Math.min(a, b)}:${Math.max(a, b)}`);
|
|
1047
1047
|
}
|
|
1048
1048
|
}
|
|
1049
|
-
|
|
1049
|
+
// A wall closes the seam with land on purpose; there, water at the seam is the defect.
|
|
1050
|
+
if (options.edgeMode === 'wall') {
|
|
1051
|
+
const open = height * 2 - left - right;
|
|
1052
|
+
if (open > 0)
|
|
1053
|
+
report({
|
|
1054
|
+
code: 'MAP_EDGE_WALL_OPEN',
|
|
1055
|
+
severity: 'error',
|
|
1056
|
+
message: `Water reaches the first or last column at ${open} pixels (${height - left} on the west edge, ${height - right} on the east); ships can cross the seam there`,
|
|
1057
|
+
location,
|
|
1058
|
+
details: { west: height - left, east: height - right },
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
else if (rows > 0)
|
|
1050
1062
|
report({
|
|
1051
1063
|
code: 'MAP_EDGE_LAND_CUT',
|
|
1052
1064
|
severity: options.edgeMode === 'sea-band' ? 'error' : 'warning',
|
|
1053
|
-
message: `Land touches the first or last column on ${rows} rows (${left} on the west edge, ${right} on the east); where the world wraps, the coast is cut by a straight vertical line. Use edge.mode "sea-band" or "
|
|
1065
|
+
message: `Land touches the first or last column on ${rows} rows (${left} on the west edge, ${right} on the east); where the world wraps, the coast is cut by a straight vertical line. Use edge.mode "sea-band", "rim" or "wall"`,
|
|
1054
1066
|
location,
|
|
1055
1067
|
details: { rows, west: left, east: right, firstRows: rowSamples },
|
|
1056
1068
|
});
|
|
@@ -1421,8 +1421,9 @@ function coarseChecks(input) {
|
|
|
1421
1421
|
}
|
|
1422
1422
|
function edgeChecks(input) {
|
|
1423
1423
|
const { frame, edgeBand, sink, grid } = input;
|
|
1424
|
-
// A rim wall ends land inside the band by design, and `none` opts out of the check.
|
|
1425
|
-
|
|
1424
|
+
// A rim or wall ends land inside the band by design, and `none` opts out of the check.
|
|
1425
|
+
const mode = input.policy?.mode;
|
|
1426
|
+
if (mode === 'none' || mode === 'rim' || mode === 'wall')
|
|
1426
1427
|
return;
|
|
1427
1428
|
const severity = input.policy?.mode === 'sea-band' ? 'error' : 'warning';
|
|
1428
1429
|
const fx = edgeBand.westEastPx / frame.width;
|
|
@@ -140,6 +140,43 @@ function mapArtifactSourceEvidence(files) {
|
|
|
140
140
|
const complete = Object.fromEntries(files.map(({ displayPath, sha256 }) => [displayPath, sha256]));
|
|
141
141
|
return { complete, bounded: boundedSourceHashEvidence(complete) };
|
|
142
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* A selection whose ids the map defines none of is not-found before any work, never an ok result
|
|
145
|
+
* with empty records and a whole-map artifact (#59). A selection with some known ids goes on and
|
|
146
|
+
* reports the unknown ones (unknownProvinceIds, and a null state or region record).
|
|
147
|
+
*/
|
|
148
|
+
function assertKnownMapEntities(snapshot, input) {
|
|
149
|
+
const index = snapshot.index;
|
|
150
|
+
const unknown = {
|
|
151
|
+
stateIds: [...new Set(input.stateIds)].filter((id) => !index.statesById.has(id)),
|
|
152
|
+
provinceIds: [...new Set(input.provinceIds)].filter((id) => !index.definitionsById.has(id)),
|
|
153
|
+
regionIds: [...new Set(input.regionIds)].filter((id) => !index.regionsById.has(id)),
|
|
154
|
+
};
|
|
155
|
+
const requested = new Set(input.stateIds).size + new Set(input.provinceIds).size + new Set(input.regionIds).size;
|
|
156
|
+
const unknownCount = unknown.stateIds.length + unknown.provinceIds.length + unknown.regionIds.length;
|
|
157
|
+
if (requested === 0 || unknownCount < requested)
|
|
158
|
+
return;
|
|
159
|
+
const highest = (ids) => {
|
|
160
|
+
let value = 0;
|
|
161
|
+
for (const id of ids)
|
|
162
|
+
if (id > value)
|
|
163
|
+
value = id;
|
|
164
|
+
return value;
|
|
165
|
+
};
|
|
166
|
+
const parts = [
|
|
167
|
+
['state', unknown.stateIds, highest(index.statesById.keys())],
|
|
168
|
+
['province', unknown.provinceIds, highest(index.definitionsById.keys())],
|
|
169
|
+
['strategic region', unknown.regionIds, highest(index.regionsById.keys())],
|
|
170
|
+
];
|
|
171
|
+
const missing = parts.filter(([, ids]) => ids.length > 0);
|
|
172
|
+
throw new ServiceError('MAP_ENTITY_ID_NOT_FOUND', `The map defines no ${missing
|
|
173
|
+
.map(([kind, ids, highest]) => `${kind} ${ids.slice(0, 16).join(', ')}${ids.length > 16 ? ' and more' : ''} (the highest ${kind} id is ${highest})`)
|
|
174
|
+
.join('; no ')}`, {
|
|
175
|
+
stateIds: unknown.stateIds.slice(0, 64),
|
|
176
|
+
provinceIds: unknown.provinceIds.slice(0, 64),
|
|
177
|
+
regionIds: unknown.regionIds.slice(0, 64),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
143
180
|
function selectedMapEntities(snapshot, provinceIds, stateIds, regionIds) {
|
|
144
181
|
const provinces = [...new Set(provinceIds)]
|
|
145
182
|
.sort((a, b) => a - b)
|
|
@@ -661,6 +698,7 @@ export async function inspectMap(engine, nudger, input, context) {
|
|
|
661
698
|
if (input.allocationRequests.length > 0)
|
|
662
699
|
throw new ServiceError('MAP_LOOKUP_ALLOCATION_UNSUPPORTED', 'Use full map inspection for identifier allocation previews');
|
|
663
700
|
const snapshot = await nudger.scan(context.workspaceId, context.principal, context.signal);
|
|
701
|
+
assertKnownMapEntities(snapshot, input);
|
|
664
702
|
const catalog = input.query === undefined ? undefined : buildMapCatalog(snapshot.index);
|
|
665
703
|
const queryMatches = catalog === undefined ? [] : searchMapCatalog(catalog, input.query, input.queryLimit);
|
|
666
704
|
const coordinateMatches = input.coordinates.map((coordinate) => lookupMapCoordinate(snapshot.index, coordinate));
|
|
@@ -720,6 +758,9 @@ export async function inspectMap(engine, nudger, input, context) {
|
|
|
720
758
|
await context.progress(3, 3, 'Map lookup complete');
|
|
721
759
|
return result;
|
|
722
760
|
}
|
|
761
|
+
// Check the ids on the cached scan before the full validation.
|
|
762
|
+
if (input.stateIds.length + input.provinceIds.length + input.regionIds.length > 0)
|
|
763
|
+
assertKnownMapEntities(await nudger.scan(context.workspaceId, context.principal, context.signal), input);
|
|
723
764
|
const { snapshot, validation, scriptReferences } = await nudger.validate(context.workspaceId, context.principal, context.signal, input.references, input.quality);
|
|
724
765
|
const sharedRevision = snapshot.revision;
|
|
725
766
|
let borderQuality;
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* World edge and seam policy (ADR 0061). The engine wraps the map horizontally and draws it as a
|
|
3
3
|
* sphere for day and night, so land that touches column 0 or the last column is cut by a straight
|
|
4
|
-
* line where the world repeats. This module keeps land away from the seam and the poles,
|
|
5
|
-
*
|
|
4
|
+
* line where the world repeats. This module keeps land away from the seam and the poles, ends it in
|
|
5
|
+
* an impassable rim, or closes the seam with an impassable wall over the full height, and writes the
|
|
6
|
+
* north and south frame borders the base map has.
|
|
6
7
|
*/
|
|
7
8
|
import { ServiceError } from '../core/result.js';
|
|
8
|
-
import { valueNoise } from './world-noise.js';
|
|
9
|
+
import { fractal, valueNoise } from './world-noise.js';
|
|
9
10
|
const SEA = 0;
|
|
10
11
|
const LAND = 1;
|
|
12
|
+
/** Land classes a wall can take its look from. */
|
|
13
|
+
export const WALL_TERRAIN_KINDS = [
|
|
14
|
+
'snow',
|
|
15
|
+
'mountain',
|
|
16
|
+
'hills',
|
|
17
|
+
'desert',
|
|
18
|
+
'forest',
|
|
19
|
+
'plains',
|
|
20
|
+
'marsh',
|
|
21
|
+
'jungle',
|
|
22
|
+
];
|
|
23
|
+
/** Default wall width: its narrowest rows (60%) still hold a default 400-pixel land province. */
|
|
24
|
+
export const WALL_DEFAULT_PX = 48;
|
|
11
25
|
/** Lowest height of the rim range at its inner foot, and its height at the seam. */
|
|
12
26
|
export const RIM_FOOT_HEIGHT = 150;
|
|
13
27
|
export const RIM_SEAM_HEIGHT = 230;
|
|
@@ -25,7 +39,10 @@ export function resolveEdge(input, width, height) {
|
|
|
25
39
|
const polarLimit = Math.floor(height / 4);
|
|
26
40
|
const bandPx = input.bandPx ?? Math.min(Math.max(192, Math.round(0.04 * width)), quarter);
|
|
27
41
|
const polarPx = input.polarPx ?? Math.min(64, Math.floor(height / 8));
|
|
28
|
-
|
|
42
|
+
// A wall closes the seam at any width; the default is the narrowest that still forms its own
|
|
43
|
+
// provinces at the usual province sizes, so it costs as little of the picture as possible.
|
|
44
|
+
const rimPx = input.rimPx ?? Math.min(mode === 'wall' ? WALL_DEFAULT_PX : 160, quarter);
|
|
45
|
+
const ranged = mode === 'rim' || mode === 'wall';
|
|
29
46
|
if (bandPx > quarter || rimPx > quarter || polarPx > polarLimit)
|
|
30
47
|
throw new ServiceError('MAP_EDGE_BAND_TOO_WIDE', 'The edge band and rim may not exceed a quarter of the world width, nor the polar band a quarter of its height', { width, height, bandPx, rimPx, polarPx, maximumWidth: quarter, maximumHeight: polarLimit });
|
|
31
48
|
if (mode === 'none')
|
|
@@ -34,9 +51,16 @@ export function resolveEdge(input, width, height) {
|
|
|
34
51
|
mode,
|
|
35
52
|
bandPx: mode === 'sea-band' ? bandPx : 0,
|
|
36
53
|
polarPx,
|
|
37
|
-
rimPx:
|
|
54
|
+
rimPx: ranged ? rimPx : 0,
|
|
55
|
+
...(mode === 'wall' && input.wallTerrain !== undefined
|
|
56
|
+
? { wallTerrain: input.wallTerrain }
|
|
57
|
+
: {}),
|
|
38
58
|
};
|
|
39
59
|
}
|
|
60
|
+
/** `rim` and `wall` both end land at the seam in a raised snow range. */
|
|
61
|
+
export function hasRimRange(edge) {
|
|
62
|
+
return edge.mode === 'rim' || edge.mode === 'wall';
|
|
63
|
+
}
|
|
40
64
|
/** Cities and named land features may not stand where the policy clears land. */
|
|
41
65
|
export function assertFeaturesOutsideBand(edge, width, height, features) {
|
|
42
66
|
if (edge.mode === 'none')
|
|
@@ -45,7 +69,8 @@ export function assertFeaturesOutsideBand(edge, width, height, features) {
|
|
|
45
69
|
if (feature.kind === 'sea')
|
|
46
70
|
return false;
|
|
47
71
|
const northSouth = feature.y < edge.polarPx || feature.y >= height - edge.polarPx;
|
|
48
|
-
const
|
|
72
|
+
const side = edge.mode === 'sea-band' ? edge.bandPx : edge.mode === 'wall' ? edge.rimPx : 0;
|
|
73
|
+
const eastWest = side > 0 && (feature.x < side || feature.x >= width - side);
|
|
49
74
|
return northSouth || eastWest;
|
|
50
75
|
});
|
|
51
76
|
if (offenders.length === 0)
|
|
@@ -57,6 +82,7 @@ export function assertFeaturesOutsideBand(edge, width, height, features) {
|
|
|
57
82
|
mode: edge.mode,
|
|
58
83
|
bandPx: edge.bandPx,
|
|
59
84
|
polarPx: edge.polarPx,
|
|
85
|
+
...(edge.mode === 'wall' ? { rimPx: edge.rimPx } : {}),
|
|
60
86
|
features: offenders.slice(0, 20),
|
|
61
87
|
});
|
|
62
88
|
}
|
|
@@ -64,13 +90,16 @@ export function assertFeaturesOutsideBand(edge, width, height, features) {
|
|
|
64
90
|
function limits(edge, width, height, seed) {
|
|
65
91
|
const rows = new Int32Array(height);
|
|
66
92
|
const columns = new Int32Array(width);
|
|
67
|
-
const scaleY = Math.max(8, edge.bandPx / 3);
|
|
93
|
+
const scaleY = Math.max(8, (edge.mode === 'wall' ? edge.rimPx : edge.bandPx) / 3);
|
|
68
94
|
const scaleX = Math.max(8, edge.polarPx / 1.5);
|
|
69
95
|
for (let y = 0; y < height; y += 1)
|
|
70
96
|
rows[y] =
|
|
71
97
|
edge.mode === 'sea-band'
|
|
72
98
|
? edge.bandPx + Math.round(valueNoise(seed + 9187, y / scaleY, 0.5) * edge.bandPx * 0.5)
|
|
73
|
-
:
|
|
99
|
+
: edge.mode === 'wall'
|
|
100
|
+
? // The wall's inner edge is ragged like a coast, but never wider than the band itself.
|
|
101
|
+
Math.round(edge.rimPx * (0.6 + 0.4 * fractal(seed + 9187, 0.5, y, scaleY, 5)))
|
|
102
|
+
: 0;
|
|
74
103
|
for (let x = 0; x < width; x += 1)
|
|
75
104
|
columns[x] =
|
|
76
105
|
edge.polarPx > 0
|
|
@@ -116,7 +145,9 @@ function landComponents(kind, width) {
|
|
|
116
145
|
/**
|
|
117
146
|
* Clear land and lakes from the east, west, north and south bands (modifying `kind` and
|
|
118
147
|
* `elevation` in place). The outline is ragged so the cleared coast does not read as a ruled
|
|
119
|
-
* line; land fragments the clearing detached sink when smaller than `minimumIsland`.
|
|
148
|
+
* line; land fragments the clearing detached sink when smaller than `minimumIsland`. A `wall`
|
|
149
|
+
* instead fills its east and west band with land over the full height, so no water reaches the
|
|
150
|
+
* seam, and returns the band as `wall`.
|
|
120
151
|
*/
|
|
121
152
|
export function applyEdgePolicy(kind, elevation, width, height, edge, seed, minimumIsland) {
|
|
122
153
|
if (edge.mode === 'none')
|
|
@@ -124,11 +155,24 @@ export function applyEdgePolicy(kind, elevation, width, height, edge, seed, mini
|
|
|
124
155
|
const before = landComponents(kind, width);
|
|
125
156
|
const { rows, columns } = limits(edge, width, height, seed);
|
|
126
157
|
const cleared = new Uint8Array(kind.length);
|
|
158
|
+
const wall = edge.mode === 'wall' ? new Uint8Array(kind.length) : undefined;
|
|
127
159
|
let clearedLand = 0;
|
|
160
|
+
let filledWater = 0;
|
|
128
161
|
for (let y = 0; y < height; y += 1)
|
|
129
162
|
for (let x = 0; x < width; x += 1) {
|
|
130
163
|
const limitX = rows[y];
|
|
131
|
-
const
|
|
164
|
+
const side = x < limitX || x >= width - limitX;
|
|
165
|
+
if (wall !== undefined && side) {
|
|
166
|
+
const pixel = y * width + x;
|
|
167
|
+
wall[pixel] = 1;
|
|
168
|
+
if (kind[pixel] !== LAND) {
|
|
169
|
+
filledWater += 1;
|
|
170
|
+
kind[pixel] = LAND;
|
|
171
|
+
elevation[pixel] = Math.max(elevation[pixel], 0.05);
|
|
172
|
+
}
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const clear = (wall === undefined && side) || y < columns[x] || y >= height - columns[x];
|
|
132
176
|
if (!clear)
|
|
133
177
|
continue;
|
|
134
178
|
const pixel = y * width + x;
|
|
@@ -152,14 +196,25 @@ export function applyEdgePolicy(kind, elevation, width, height, edge, seed, mini
|
|
|
152
196
|
}
|
|
153
197
|
reshapeClearedCoast(kind, elevation, cleared, width, height);
|
|
154
198
|
const notes = [];
|
|
199
|
+
if (filledWater > 0)
|
|
200
|
+
notes.push({
|
|
201
|
+
code: 'MAP_EDGE_WALL_FILLED',
|
|
202
|
+
severity: 'info',
|
|
203
|
+
message: `The wall edge policy filled ${filledWater} water pixels of its east and west band with land, so no water reaches the seam`,
|
|
204
|
+
details: { mode: edge.mode, rimPx: edge.rimPx, filledWaterPixels: filledWater },
|
|
205
|
+
});
|
|
155
206
|
if (clearedLand + sunk > 0)
|
|
156
207
|
notes.push({
|
|
157
208
|
code: 'MAP_EDGE_LAND_CLEARED',
|
|
158
209
|
severity: 'warning',
|
|
159
|
-
message: `The ${edge.mode} edge policy cleared ${clearedLand} land pixels to open sea${sunk > 0 ? ` and sank ${sunk} pixels of fragments it detached` : ''}; land that must reach the edge needs edge.mode "rim"`,
|
|
210
|
+
message: `The ${edge.mode} edge policy cleared ${clearedLand} land pixels to open sea${sunk > 0 ? ` and sank ${sunk} pixels of fragments it detached` : ''}; land that must reach the edge needs edge.mode "rim" or "wall"${edge.mode === 'wall' ? ', and land that must reach the poles needs polarPx 0' : ''}`,
|
|
160
211
|
details: { mode: edge.mode, clearedLandPixels: clearedLand, sunkFragmentPixels: sunk },
|
|
161
212
|
});
|
|
162
|
-
return {
|
|
213
|
+
return {
|
|
214
|
+
notes,
|
|
215
|
+
clearedLandPixels: clearedLand + sunk,
|
|
216
|
+
...(wall === undefined ? {} : { wall }),
|
|
217
|
+
};
|
|
163
218
|
}
|
|
164
219
|
/**
|
|
165
220
|
* Give the new coast a shelf and a coastal land ramp, as the reference interpretation does for
|
|
@@ -229,10 +284,56 @@ function smooth(t) {
|
|
|
229
284
|
return clamped * clamped * (3 - 2 * clamped);
|
|
230
285
|
}
|
|
231
286
|
/**
|
|
232
|
-
*
|
|
287
|
+
* The look of the wall row by row on each side. Each row takes the kind of the nearest land
|
|
288
|
+
* beyond the wall within four wall widths, short of the other side's wall; a row that meets only water is snow in the outer
|
|
289
|
+
* fifths of the map and mountain elsewhere. Kinds are smoothed by a majority over about half a
|
|
290
|
+
* wall width of rows, so the look changes in stretches, and caller segments win over all of it.
|
|
291
|
+
*/
|
|
292
|
+
export function wallRowKinds(input) {
|
|
293
|
+
const { edge, width, height, wall } = input;
|
|
294
|
+
const reach = Math.max(16, edge.rimPx * 4);
|
|
295
|
+
const fallback = (y) => y < height * 0.2 || y >= height * 0.8 ? 'snow' : 'mountain';
|
|
296
|
+
const side = (step) => {
|
|
297
|
+
const raw = [];
|
|
298
|
+
for (let y = 0; y < height; y += 1) {
|
|
299
|
+
let x = step === 1 ? 0 : width - 1;
|
|
300
|
+
while (x >= 0 && x < width && wall[y * width + x] === 1)
|
|
301
|
+
x += step;
|
|
302
|
+
let found;
|
|
303
|
+
for (let distance = 0; distance < reach && x >= 0 && x < width; distance += 1, x += step) {
|
|
304
|
+
// The other side's wall ends the search: a narrow map meets only water.
|
|
305
|
+
if (wall[y * width + x] === 1)
|
|
306
|
+
break;
|
|
307
|
+
found = input.landKind(y * width + x);
|
|
308
|
+
if (found !== undefined)
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
raw.push(found ?? fallback(y));
|
|
312
|
+
}
|
|
313
|
+
const window = Math.max(8, Math.round(edge.rimPx / 2));
|
|
314
|
+
const smoothed = [];
|
|
315
|
+
for (let y = 0; y < height; y += 1) {
|
|
316
|
+
const counts = new Map();
|
|
317
|
+
for (let other = Math.max(0, y - window); other <= Math.min(height - 1, y + window); other++)
|
|
318
|
+
counts.set(raw[other], (counts.get(raw[other]) ?? 0) + 1);
|
|
319
|
+
// Ties keep the row's own kind, then the order of WALL_TERRAIN_KINDS.
|
|
320
|
+
smoothed.push([...counts].sort(([a, left], [b, right]) => right - left ||
|
|
321
|
+
Number(b === raw[y]) - Number(a === raw[y]) ||
|
|
322
|
+
WALL_TERRAIN_KINDS.indexOf(a) - WALL_TERRAIN_KINDS.indexOf(b))[0][0]);
|
|
323
|
+
}
|
|
324
|
+
if (Array.isArray(edge.wallTerrain))
|
|
325
|
+
for (const segment of edge.wallTerrain)
|
|
326
|
+
for (let y = Math.max(0, segment.y0); y <= Math.min(height - 1, segment.y1); y += 1)
|
|
327
|
+
smoothed[y] = segment.kind;
|
|
328
|
+
return smoothed;
|
|
329
|
+
};
|
|
330
|
+
return { west: side(1), east: side(-1) };
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Rim strength 0 to 1 at a column: 0 at the inner foot, 1 at the seam. Zero outside `rim` and `wall`.
|
|
233
334
|
*/
|
|
234
335
|
export function rimStrength(edge, width, x) {
|
|
235
|
-
if (edge
|
|
336
|
+
if (!hasRimRange(edge))
|
|
236
337
|
return 0;
|
|
237
338
|
const distance = Math.min(x, width - 1 - x);
|
|
238
339
|
return distance >= edge.rimPx ? 0 : smooth(1 - distance / edge.rimPx);
|
|
@@ -258,7 +359,8 @@ export function edgeWaterDarkness(edge, width, height, x, y) {
|
|
|
258
359
|
return Math.max(side, pole);
|
|
259
360
|
}
|
|
260
361
|
/**
|
|
261
|
-
* Impassable rows for every pair of distinct land provinces that meet across the seam
|
|
362
|
+
* Impassable rows for every pair of distinct land provinces that meet across the seam (`rim` and
|
|
363
|
+
* `wall`), in
|
|
262
364
|
* `adjacencies.csv` order (rows are sorted by the lower then the higher province ID).
|
|
263
365
|
*/
|
|
264
366
|
export function rimAdjacencyRows(input) {
|