hoi4-agent-tools 4.19.0 → 4.20.1
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 +18 -0
- package/dist/hoi4_agent_tools/core/diagnostic-rollup.js +9 -1
- package/dist/hoi4_agent_tools/core/domain-validation.js +3 -16
- package/dist/hoi4_agent_tools/core/engine-operation.js +27 -0
- package/dist/hoi4_agent_tools/core/job-worker-host.js +127 -11
- package/dist/hoi4_agent_tools/core/transactions.js +127 -5
- package/dist/hoi4_agent_tools/core/workspace.js +118 -67
- package/dist/hoi4_agent_tools/event/algorithms.js +14 -2
- package/dist/hoi4_agent_tools/gui/layout.js +10 -6
- package/dist/hoi4_agent_tools/gui/renderer.js +74 -34
- package/dist/hoi4_agent_tools/gui/source-graph.js +12 -0
- package/dist/hoi4_agent_tools/gui/studio.js +2 -0
- package/dist/hoi4_agent_tools/map/baseline.js +143 -0
- package/dist/hoi4_agent_tools/map/diagnostic-limit.js +14 -13
- package/dist/hoi4_agent_tools/map/service.js +112 -15
- package/dist/hoi4_agent_tools/map/tool-operations.js +10 -0
- package/dist/hoi4_agent_tools/map/validation.js +13 -5
- package/dist/hoi4_agent_tools/mcp/tools/map.js +1 -0
- package/dist/hoi4_agent_tools/schemas/map-requests.js +6 -0
- package/dist/hoi4_agent_tools/version.js +1 -1
- package/docs/map.md +29 -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 +8 -8
- package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -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 +1 -1
- 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
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { hashCanonical } from '../core/canonical.js';
|
|
2
|
+
import { PACKAGE_VERSION } from '../version.js';
|
|
3
|
+
/**
|
|
4
|
+
* A stated map baseline (ADR 0090, issue 272). A map write that states the fingerprint of the
|
|
5
|
+
* untouched source, as a prior full validation returned it, may leave pre-existing errors in place
|
|
6
|
+
* when it touches none of the objects they belong to. Without a stated fingerprint every error
|
|
7
|
+
* blocks, as before.
|
|
8
|
+
*/
|
|
9
|
+
/** The validation detail ceiling of a write with a stated baseline: the comparison needs every finding. */
|
|
10
|
+
export const MAP_BASELINE_DIAGNOSTIC_LIMIT = 50_000;
|
|
11
|
+
/** Pattern of a stated baseline fingerprint (a SHA-256 in lowercase hex). */
|
|
12
|
+
export const MAP_BASELINE_FINGERPRINT_PATTERN = /^[0-9a-f]{64}$/u;
|
|
13
|
+
/**
|
|
14
|
+
* The fingerprint of the map's untouched source: the tool version and the hash of every scanned
|
|
15
|
+
* map source. The findings of a full validation follow from exactly these, so equal fingerprints
|
|
16
|
+
* mean equal findings, however many of them a result lists.
|
|
17
|
+
*/
|
|
18
|
+
export function mapBaselineFingerprint(sources) {
|
|
19
|
+
return hashCanonical({
|
|
20
|
+
schema: 'hoi4.map-baseline.v1',
|
|
21
|
+
toolVersion: PACKAGE_VERSION,
|
|
22
|
+
sources: sources
|
|
23
|
+
.map(({ displayPath, loadOrder, sha256 }) => ({ displayPath, loadOrder, sha256 }))
|
|
24
|
+
.sort((left, right) => left.loadOrder - right.loadOrder ||
|
|
25
|
+
(left.displayPath < right.displayPath
|
|
26
|
+
? -1
|
|
27
|
+
: left.displayPath > right.displayPath
|
|
28
|
+
? 1
|
|
29
|
+
: 0)),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** Keys of diagnostic details that name provinces by id. */
|
|
33
|
+
const PROVINCE_DETAIL_KEYS = new Set(['province', 'provinceId', 'provinceIds', 'provinces']);
|
|
34
|
+
function sameDefinition(left, right) {
|
|
35
|
+
return (left.color.r === right.color.r &&
|
|
36
|
+
left.color.g === right.color.g &&
|
|
37
|
+
left.color.b === right.color.b &&
|
|
38
|
+
left.type === right.type &&
|
|
39
|
+
left.coastal === right.coastal &&
|
|
40
|
+
left.terrain === right.terrain &&
|
|
41
|
+
left.continent === right.continent);
|
|
42
|
+
}
|
|
43
|
+
function provinceIdsIn(value, into) {
|
|
44
|
+
if (typeof value === 'number' && Number.isInteger(value))
|
|
45
|
+
into.push(value);
|
|
46
|
+
else if (Array.isArray(value))
|
|
47
|
+
for (const entry of value)
|
|
48
|
+
provinceIdsIn(entry, into);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The footprint of a write that turns `before` into `after` by changing `changedPaths`.
|
|
52
|
+
*
|
|
53
|
+
* A finding belongs to the objects its location and related locations name, and to the provinces
|
|
54
|
+
* its details name. A location in an unchanged file is untouched. A location in a changed
|
|
55
|
+
* province definition file is the province on that row, untouched when the write changes neither
|
|
56
|
+
* that row nor that province's pixels. Every other location in a changed file is touched, and so
|
|
57
|
+
* is a finding that names no object at all: what cannot be shown to lie outside the write lies
|
|
58
|
+
* inside it.
|
|
59
|
+
*/
|
|
60
|
+
export function mapWriteFootprint(before, after, changedPaths, normalizePath) {
|
|
61
|
+
const touchedProvinces = new Set();
|
|
62
|
+
for (const [id, definition] of after.definitionsById) {
|
|
63
|
+
const previous = before.definitionsById.get(id);
|
|
64
|
+
if (previous === undefined || !sameDefinition(previous, definition))
|
|
65
|
+
touchedProvinces.add(id);
|
|
66
|
+
}
|
|
67
|
+
for (const id of before.definitionsById.keys())
|
|
68
|
+
if (!after.definitionsById.has(id))
|
|
69
|
+
touchedProvinces.add(id);
|
|
70
|
+
const bitmapChanged = before.provinceBitmapFile?.sha256 !== after.provinceBitmapFile?.sha256 ||
|
|
71
|
+
before.provinceBitmapFile?.displayPath !== after.provinceBitmapFile?.displayPath;
|
|
72
|
+
let allProvinces = false;
|
|
73
|
+
if (bitmapChanged) {
|
|
74
|
+
const left = before.raster;
|
|
75
|
+
const right = after.raster;
|
|
76
|
+
if (right === undefined || left?.width !== right.width || left.height !== right.height) {
|
|
77
|
+
allProvinces = true;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
for (let pixel = 0; pixel < right.provinceIds.length; pixel += 1) {
|
|
81
|
+
const was = left.provinceIds[pixel];
|
|
82
|
+
const is = right.provinceIds[pixel];
|
|
83
|
+
if (was === is)
|
|
84
|
+
continue;
|
|
85
|
+
if (was >= 0)
|
|
86
|
+
touchedProvinces.add(was);
|
|
87
|
+
if (is >= 0)
|
|
88
|
+
touchedProvinces.add(is);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// The rows of every definition file, by path and one-based line, in the source after the write.
|
|
93
|
+
const definitionRows = new Map();
|
|
94
|
+
for (const definition of after.definitionsAcrossRoots) {
|
|
95
|
+
const path = normalizePath(definition.document.file.displayPath);
|
|
96
|
+
if (path === undefined)
|
|
97
|
+
continue;
|
|
98
|
+
const rows = definitionRows.get(path) ?? new Map();
|
|
99
|
+
rows.set(definition.line, definition.id);
|
|
100
|
+
definitionRows.set(path, rows);
|
|
101
|
+
}
|
|
102
|
+
const provinceTouched = (id) => allProvinces || touchedProvinces.has(id);
|
|
103
|
+
return {
|
|
104
|
+
changedPaths,
|
|
105
|
+
touchedProvinces,
|
|
106
|
+
allProvinces,
|
|
107
|
+
touches(diagnostic, paths) {
|
|
108
|
+
const locations = [
|
|
109
|
+
...(diagnostic.location === undefined ? [] : [diagnostic.location]),
|
|
110
|
+
...(diagnostic.related ?? []),
|
|
111
|
+
];
|
|
112
|
+
const named = [];
|
|
113
|
+
for (const [key, value] of Object.entries(diagnostic.details ?? {}))
|
|
114
|
+
if (PROVINCE_DETAIL_KEYS.has(key))
|
|
115
|
+
provinceIdsIn(value, named);
|
|
116
|
+
if (locations.length === 0 && named.length === 0)
|
|
117
|
+
return true;
|
|
118
|
+
if (named.some(provinceTouched))
|
|
119
|
+
return true;
|
|
120
|
+
const located = new Set();
|
|
121
|
+
for (const location of locations) {
|
|
122
|
+
const path = normalizePath(location.path);
|
|
123
|
+
if (path === undefined) {
|
|
124
|
+
// A location that is no workspace path cannot be matched against the write.
|
|
125
|
+
if (changedPaths.size > 0)
|
|
126
|
+
return true;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
located.add(path);
|
|
130
|
+
if (!changedPaths.has(path))
|
|
131
|
+
continue;
|
|
132
|
+
const province = definitionRows.get(path)?.get(location.start.line);
|
|
133
|
+
if (province === undefined || provinceTouched(province))
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
// Paths named only in the details (not as a location) are whole files.
|
|
137
|
+
for (const path of paths)
|
|
138
|
+
if (!located.has(path) && changedPaths.has(path))
|
|
139
|
+
return true;
|
|
140
|
+
return false;
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
@@ -16,10 +16,10 @@ function addOmittedDiagnostic(details, diagnostic) {
|
|
|
16
16
|
(details.omittedBySeverity[diagnostic.severity] ?? 0) + 1;
|
|
17
17
|
details.omittedByCode[diagnostic.code] = (details.omittedByCode[diagnostic.code] ?? 0) + 1;
|
|
18
18
|
}
|
|
19
|
-
function truncationDiagnostic(omitted) {
|
|
19
|
+
function truncationDiagnostic(omitted, limit) {
|
|
20
20
|
const details = {
|
|
21
|
-
limit
|
|
22
|
-
retained:
|
|
21
|
+
limit,
|
|
22
|
+
retained: limit - 1,
|
|
23
23
|
omitted: 0,
|
|
24
24
|
omittedBySeverity: {},
|
|
25
25
|
omittedByCode: {},
|
|
@@ -43,7 +43,7 @@ function existingTruncationDiagnostic(diagnostics) {
|
|
|
43
43
|
? marker
|
|
44
44
|
: undefined;
|
|
45
45
|
}
|
|
46
|
-
function addBoundedDiagnostic(diagnostics, diagnostic, includeBaseline) {
|
|
46
|
+
function addBoundedDiagnostic(diagnostics, diagnostic, includeBaseline, limit) {
|
|
47
47
|
if (!includeBaseline && isBaselineOnlyDiagnostic(diagnostic))
|
|
48
48
|
return;
|
|
49
49
|
const marker = existingTruncationDiagnostic(diagnostics);
|
|
@@ -65,16 +65,16 @@ function addBoundedDiagnostic(diagnostics, diagnostic, includeBaseline) {
|
|
|
65
65
|
addOmittedDiagnostic(marker.details, diagnostic);
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
|
-
if (diagnostics.length <
|
|
68
|
+
if (diagnostics.length < limit) {
|
|
69
69
|
diagnostics.push(diagnostic);
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
72
|
const candidates = [...diagnostics, diagnostic];
|
|
73
73
|
const hard = candidates.filter(isHardDiagnostic);
|
|
74
74
|
const soft = candidates.filter((candidate) => !isHardDiagnostic(candidate));
|
|
75
|
-
const retained = hard.length >=
|
|
76
|
-
? hard.slice(0,
|
|
77
|
-
: [...hard, ...soft.slice(0,
|
|
75
|
+
const retained = hard.length >= limit - 1
|
|
76
|
+
? hard.slice(0, limit - 1)
|
|
77
|
+
: [...hard, ...soft.slice(0, limit - 1 - hard.length)];
|
|
78
78
|
const retainedCounts = new Map();
|
|
79
79
|
for (const item of retained)
|
|
80
80
|
retainedCounts.set(item, (retainedCounts.get(item) ?? 0) + 1);
|
|
@@ -85,15 +85,16 @@ function addBoundedDiagnostic(diagnostics, diagnostic, includeBaseline) {
|
|
|
85
85
|
retainedCounts.set(candidate, count - 1);
|
|
86
86
|
return false;
|
|
87
87
|
});
|
|
88
|
-
diagnostics.splice(0, diagnostics.length, ...retained, truncationDiagnostic(omitted));
|
|
88
|
+
diagnostics.splice(0, diagnostics.length, ...retained, truncationDiagnostic(omitted, limit));
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
/** Add a finding, keeping at most `limit` (default {@link MAP_DIAGNOSTIC_LIMIT}) with omission counts. */
|
|
91
|
+
export function addMapDiagnostic(diagnostics, diagnostic, limit = MAP_DIAGNOSTIC_LIMIT) {
|
|
92
|
+
addBoundedDiagnostic(diagnostics, diagnostic, false, limit);
|
|
92
93
|
}
|
|
93
94
|
/** Active topology validation must report failures in whichever source wins
|
|
94
95
|
* precedence, including inherited game and dependency files. */
|
|
95
|
-
export function addActiveMapDiagnostic(diagnostics, diagnostic) {
|
|
96
|
-
addBoundedDiagnostic(diagnostics, diagnostic, true);
|
|
96
|
+
export function addActiveMapDiagnostic(diagnostics, diagnostic, limit = MAP_DIAGNOSTIC_LIMIT) {
|
|
97
|
+
addBoundedDiagnostic(diagnostics, diagnostic, true, limit);
|
|
97
98
|
}
|
|
98
99
|
export function addMapDiagnostics(diagnostics, additions) {
|
|
99
100
|
for (const diagnostic of additions)
|
|
@@ -20,7 +20,8 @@ import { buildGeographyArtifacts } from './geography/preview.js';
|
|
|
20
20
|
import { operationHasGeography, prepareGeography, } from './geography/preparation.js';
|
|
21
21
|
import { WORLD_OUTPUT_MANIFEST } from './world-outputs.js';
|
|
22
22
|
import { renderMap, renderMapDiff, } from './render.js';
|
|
23
|
-
import { validateMapAsync } from './validation.js';
|
|
23
|
+
import { mapValidationChecks, validateMapAsync } from './validation.js';
|
|
24
|
+
import { MAP_BASELINE_DIAGNOSTIC_LIMIT, mapBaselineFingerprint, mapWriteFootprint, } from './baseline.js';
|
|
24
25
|
import { buildWorldPreviewArtifacts, generatedWorldOperationIds } from './world-preview.js';
|
|
25
26
|
import { evaluateTerritoryQuality, territoryAssignmentContent, territoryArtifactContent, } from './territory-quality.js';
|
|
26
27
|
/**
|
|
@@ -337,6 +338,21 @@ export function attributeMapValidationDiagnostics(input) {
|
|
|
337
338
|
continue;
|
|
338
339
|
}
|
|
339
340
|
const fingerprint = diagnosticFingerprint(diagnostic);
|
|
341
|
+
if (baselineErrors.has(fingerprint) &&
|
|
342
|
+
input.acceptedBaseline !== undefined &&
|
|
343
|
+
!input.acceptedBaseline.touches(diagnostic, diagnosticPaths(diagnostic))) {
|
|
344
|
+
// A stated baseline leaves this pre-existing error in place: it is reported, not blocking.
|
|
345
|
+
attributed.push({
|
|
346
|
+
...diagnostic,
|
|
347
|
+
severity: 'warning',
|
|
348
|
+
details: {
|
|
349
|
+
...diagnostic.details,
|
|
350
|
+
attributionStatus: 'accepted-baseline',
|
|
351
|
+
baselineSeverity: diagnostic.severity,
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
340
356
|
if (baselineErrors.has(fingerprint)) {
|
|
341
357
|
attributed.push({
|
|
342
358
|
...diagnostic,
|
|
@@ -627,6 +643,17 @@ export class AgentNudger {
|
|
|
627
643
|
this.transactions = this.engine.transactions;
|
|
628
644
|
}
|
|
629
645
|
async scan(workspaceId, principal, signal, includeExternalScriptReferences = false, includeWorldContext = false, includeAppearance = false, includeBorderInputs = false, includeContinentReferences = false) {
|
|
646
|
+
const { files, sourceRoots } = await this.scanSources(workspaceId, principal, signal, includeExternalScriptReferences, includeWorldContext, includeAppearance, includeBorderInputs, includeContinentReferences);
|
|
647
|
+
const revision = hashCanonical(files.map(({ displayPath, loadOrder, sha256 }) => ({ displayPath, loadOrder, sha256 })));
|
|
648
|
+
return {
|
|
649
|
+
workspaceId,
|
|
650
|
+
revision,
|
|
651
|
+
files,
|
|
652
|
+
index: MapWorkspaceIndex.build(files, sourceRoots),
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
/** The source files a map scan reads, without the index built from them. */
|
|
656
|
+
async scanSources(workspaceId, principal, signal, includeExternalScriptReferences = false, includeWorldContext = false, includeAppearance = false, includeBorderInputs = false, includeContinentReferences = false) {
|
|
630
657
|
signal?.throwIfAborted();
|
|
631
658
|
const workspace = this.resolver.get(workspaceId, principal);
|
|
632
659
|
const sourceRoots = {
|
|
@@ -705,13 +732,7 @@ export class AgentNudger {
|
|
|
705
732
|
...collected,
|
|
706
733
|
...(continentSnapshot?.files ?? []).filter((file) => !collectedPaths.has(file.displayPath)),
|
|
707
734
|
].sort((left, right) => left.loadOrder - right.loadOrder || compareCodeUnits(left.displayPath, right.displayPath));
|
|
708
|
-
|
|
709
|
-
return {
|
|
710
|
-
workspaceId,
|
|
711
|
-
revision,
|
|
712
|
-
files,
|
|
713
|
-
index: MapWorkspaceIndex.build(files, sourceRoots),
|
|
714
|
-
};
|
|
735
|
+
return { files, sourceRoots };
|
|
715
736
|
}
|
|
716
737
|
async validate(workspaceId, principal, signal, scripts = false, includeAppearance = false) {
|
|
717
738
|
const snapshot = await this.scan(workspaceId, principal, signal, scripts, false, includeAppearance);
|
|
@@ -739,8 +760,13 @@ export class AgentNudger {
|
|
|
739
760
|
scriptReferences: { references: consistency.references, missing: consistency.missing },
|
|
740
761
|
};
|
|
741
762
|
}
|
|
742
|
-
async prepareOperations(workspaceId, operations, principal, signal, synthesisCheck = false) {
|
|
763
|
+
async prepareOperations(workspaceId, operations, principal, signal, synthesisCheck = false, baselineOptions = {}) {
|
|
743
764
|
signal?.throwIfAborted();
|
|
765
|
+
const stated = baselineOptions.baselineFingerprint;
|
|
766
|
+
// The host's own fingerprint of the current source is the evidence; the stated one only opts in.
|
|
767
|
+
const current = stated === undefined
|
|
768
|
+
? undefined
|
|
769
|
+
: await this.baselineFingerprint(workspaceId, principal, signal);
|
|
744
770
|
const snapshot = await this.scan(workspaceId, principal, signal, operations.some((operation) => operation.kind === 'renumber_map_entity' ||
|
|
745
771
|
operation.kind === 'remap_map_references' ||
|
|
746
772
|
'remapReferences' in operation),
|
|
@@ -835,12 +861,36 @@ export class AgentNudger {
|
|
|
835
861
|
}
|
|
836
862
|
plan.diagnostics.push(...importDiagnostics);
|
|
837
863
|
const newWorld = operations.some(({ kind }) => kind === 'create_world');
|
|
864
|
+
const baselineReport = stated === undefined
|
|
865
|
+
? undefined
|
|
866
|
+
: { stated, matched: stated === current, accepted: 0, insideFootprint: 0 };
|
|
867
|
+
if (baselineReport !== undefined && !baselineReport.matched)
|
|
868
|
+
plan.diagnostics.push({
|
|
869
|
+
code: 'MAP_BASELINE_STALE',
|
|
870
|
+
severity: 'blocker',
|
|
871
|
+
category: 'validation',
|
|
872
|
+
message: 'The stated baseline fingerprint does not match the current map source; validate the untouched map again and state its new fingerprint',
|
|
873
|
+
details: { statedBaselineFingerprint: stated },
|
|
874
|
+
});
|
|
875
|
+
if (baselineReport?.matched === true && newWorld)
|
|
876
|
+
plan.diagnostics.push({
|
|
877
|
+
code: 'MAP_BASELINE_NOT_APPLICABLE',
|
|
878
|
+
severity: 'blocker',
|
|
879
|
+
category: 'validation',
|
|
880
|
+
message: 'A stated baseline cannot apply to create_world: a new world replaces the whole map and has no baseline (ADR 0070)',
|
|
881
|
+
});
|
|
882
|
+
// With a matched baseline both validations keep every finding, so none hides behind the cut.
|
|
883
|
+
const acceptBaseline = baselineReport?.matched === true && !newWorld;
|
|
884
|
+
const limit = acceptBaseline ? { diagnosticLimit: MAP_BASELINE_DIAGNOSTIC_LIMIT } : {};
|
|
838
885
|
// A new world replaces the whole map: findings of the map it replaces are not its baseline,
|
|
839
886
|
// so every finding of the generated map is judged on its own and belongs to the world
|
|
840
887
|
// operation (ADR 0070).
|
|
841
888
|
const baselineValidation = newWorld
|
|
842
889
|
? { passed: true, diagnostics: [], checks: [] }
|
|
843
|
-
: await validateMapAsync(snapshot.index,
|
|
890
|
+
: await validateMapAsync(snapshot.index, {
|
|
891
|
+
...limit,
|
|
892
|
+
...(signal === undefined ? {} : { signal }),
|
|
893
|
+
});
|
|
844
894
|
// A new world has nothing to compare its bitmap format and pixels with.
|
|
845
895
|
const worldOperation = operations.find((operation) => operation.kind === 'create_world');
|
|
846
896
|
// A world that failed to generate left the workspace map unchanged; validating that map would
|
|
@@ -851,6 +901,7 @@ export class AgentNudger {
|
|
|
851
901
|
const rawValidation = worldFailed
|
|
852
902
|
? { passed: true, diagnostics: [], checks: [] }
|
|
853
903
|
: await validateMapAsync(plan.finalIndex, {
|
|
904
|
+
...limit,
|
|
854
905
|
...(newWorld ? {} : { baseline: snapshot.index }),
|
|
855
906
|
...(worldOperation?.kind === 'create_world' && worldOperation.edge !== undefined
|
|
856
907
|
? { edgeMode: worldOperation.edge.mode ?? 'sea-band' }
|
|
@@ -860,6 +911,11 @@ export class AgentNudger {
|
|
|
860
911
|
? {}
|
|
861
912
|
: { expectedChangedBounds: plan.expectedChangedBounds }),
|
|
862
913
|
});
|
|
914
|
+
const footprint = acceptBaseline
|
|
915
|
+
? mapWriteFootprint(snapshot.index, plan.finalIndex,
|
|
916
|
+
// Written paths, normalized as attribution matches them (`ownersByPath`).
|
|
917
|
+
new Set(plan.changes.map(({ relativePath }) => relativePath.replaceAll('\\', '/').toLowerCase())), normalizedDiagnosticPath)
|
|
918
|
+
: undefined;
|
|
863
919
|
const attributedValidation = {
|
|
864
920
|
...rawValidation,
|
|
865
921
|
diagnostics: attributeMapValidationDiagnostics({
|
|
@@ -867,8 +923,26 @@ export class AgentNudger {
|
|
|
867
923
|
operations: plan.operations,
|
|
868
924
|
changes: plan.changes,
|
|
869
925
|
baselineDiagnostics: baselineValidation.diagnostics,
|
|
926
|
+
...(footprint === undefined ? {} : { acceptedBaseline: footprint }),
|
|
870
927
|
}),
|
|
871
928
|
};
|
|
929
|
+
if (footprint !== undefined) {
|
|
930
|
+
// Accepted pre-existing errors no longer fail their family's check; everything else still does.
|
|
931
|
+
attributedValidation.checks = mapValidationChecks(attributedValidation.diagnostics);
|
|
932
|
+
attributedValidation.passed =
|
|
933
|
+
attributedValidation.checks.every(({ passed }) => passed) &&
|
|
934
|
+
!attributedValidation.diagnostics.some(({ severity }) => severity === 'error' || severity === 'blocker');
|
|
935
|
+
}
|
|
936
|
+
if (baselineReport !== undefined)
|
|
937
|
+
for (const diagnostic of attributedValidation.diagnostics) {
|
|
938
|
+
const status = diagnostic.details?.attributionStatus;
|
|
939
|
+
if (status === 'accepted-baseline')
|
|
940
|
+
baselineReport.accepted += 1;
|
|
941
|
+
else if (acceptBaseline &&
|
|
942
|
+
status === 'pre-existing-baseline' &&
|
|
943
|
+
diagnostic.code !== 'MAP_VALIDATION_OPERATION_UNOWNED')
|
|
944
|
+
baselineReport.insideFootprint += 1;
|
|
945
|
+
}
|
|
872
946
|
return {
|
|
873
947
|
snapshot,
|
|
874
948
|
plan,
|
|
@@ -877,11 +951,25 @@ export class AgentNudger {
|
|
|
877
951
|
geography: [...geographyModels.values()],
|
|
878
952
|
territory: { reports: plan.territory ?? [], quality: territoryQuality },
|
|
879
953
|
imports,
|
|
954
|
+
...(baselineReport === undefined ? {} : { baseline: baselineReport }),
|
|
880
955
|
};
|
|
881
956
|
}
|
|
957
|
+
/**
|
|
958
|
+
* The baseline fingerprint of a workspace's current map source (ADR 0090), over the same scan
|
|
959
|
+
* whatever tool asks: a full validation reports it, and a write that states it is checked
|
|
960
|
+
* against it.
|
|
961
|
+
*/
|
|
962
|
+
async baselineFingerprint(workspaceId, principal, signal) {
|
|
963
|
+
// The files of a base scan, hashed without building the map index from them (issue 272).
|
|
964
|
+
const { files } = await this.scanSources(workspaceId, principal, signal);
|
|
965
|
+
return mapBaselineFingerprint(files);
|
|
966
|
+
}
|
|
882
967
|
async plan(input) {
|
|
883
|
-
const prepared = await this.prepareOperations(input.workspaceId, input.operations, input.principal, input.signal
|
|
884
|
-
|
|
968
|
+
const prepared = await this.prepareOperations(input.workspaceId, input.operations, input.principal, input.signal, false, input.baselineFingerprint === undefined
|
|
969
|
+
? {}
|
|
970
|
+
: { baselineFingerprint: input.baselineFingerprint });
|
|
971
|
+
const planned = await this.planPrepared(input, prepared);
|
|
972
|
+
return prepared.baseline === undefined ? planned : { ...planned, baseline: prepared.baseline };
|
|
885
973
|
}
|
|
886
974
|
async planPrepared(input, prepared) {
|
|
887
975
|
input.signal?.throwIfAborted();
|
|
@@ -1020,7 +1108,9 @@ export class AgentNudger {
|
|
|
1020
1108
|
* Any source edit after this preparation is rejected by the transaction read-dependency checks.
|
|
1021
1109
|
*/
|
|
1022
1110
|
async planRewriteWithDiff(input) {
|
|
1023
|
-
const prepared = await this.prepareOperations(input.workspaceId, input.operations, input.principal, input.signal
|
|
1111
|
+
const prepared = await this.prepareOperations(input.workspaceId, input.operations, input.principal, input.signal, false, input.baselineFingerprint === undefined
|
|
1112
|
+
? {}
|
|
1113
|
+
: { baselineFingerprint: input.baselineFingerprint });
|
|
1024
1114
|
const diff = await this.renderPreparedDiffAndStore(prepared, input.operations, {
|
|
1025
1115
|
...(input.diffScale === undefined ? {} : { scale: input.diffScale }),
|
|
1026
1116
|
...(input.principal === undefined ? {} : { principal: input.principal }),
|
|
@@ -1033,7 +1123,11 @@ export class AgentNudger {
|
|
|
1033
1123
|
...(input.principal === undefined ? {} : { principal: input.principal }),
|
|
1034
1124
|
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
1035
1125
|
}, prepared);
|
|
1036
|
-
return {
|
|
1126
|
+
return {
|
|
1127
|
+
...diff,
|
|
1128
|
+
...planned,
|
|
1129
|
+
...(prepared.baseline === undefined ? {} : { baseline: prepared.baseline }),
|
|
1130
|
+
};
|
|
1037
1131
|
}
|
|
1038
1132
|
/**
|
|
1039
1133
|
* Run the relief and river synthesis of every `create_world` with `synthesisCheck` and report
|
|
@@ -1056,7 +1150,9 @@ export class AgentNudger {
|
|
|
1056
1150
|
}
|
|
1057
1151
|
/** Build validated offline evidence without planning or applying a write transaction. */
|
|
1058
1152
|
async previewRewriteWithDiff(input) {
|
|
1059
|
-
const prepared = await this.prepareOperations(input.workspaceId, input.operations, input.principal, input.signal
|
|
1153
|
+
const prepared = await this.prepareOperations(input.workspaceId, input.operations, input.principal, input.signal, false, input.baselineFingerprint === undefined
|
|
1154
|
+
? {}
|
|
1155
|
+
: { baselineFingerprint: input.baselineFingerprint });
|
|
1060
1156
|
const diff = await this.renderPreparedDiffAndStore(prepared, input.operations, {
|
|
1061
1157
|
...(input.diffScale === undefined ? {} : { scale: input.diffScale }),
|
|
1062
1158
|
...(input.principal === undefined ? {} : { principal: input.principal }),
|
|
@@ -1065,6 +1161,7 @@ export class AgentNudger {
|
|
|
1065
1161
|
return {
|
|
1066
1162
|
...diff,
|
|
1067
1163
|
validation: prepared.validation,
|
|
1164
|
+
...(prepared.baseline === undefined ? {} : { baseline: prepared.baseline }),
|
|
1068
1165
|
diagnostics: rollupRepeatedSoftDiagnostics(prepared.validation.diagnostics, publicArtifactLink(diff.artifacts.find((artifact) => artifact.name === 'map-validation.json' ||
|
|
1069
1166
|
(artifact.name.startsWith('map-validation.json.') &&
|
|
1070
1167
|
artifact.name.endsWith('.chunks.json'))))),
|
|
@@ -346,6 +346,9 @@ export async function prepareMapRewrite(nudger, input, context) {
|
|
|
346
346
|
workspaceId: context.workspaceId,
|
|
347
347
|
operations: input.operations,
|
|
348
348
|
...(input.diffScale === undefined ? {} : { diffScale: input.diffScale }),
|
|
349
|
+
...(input.baselineFingerprint === undefined
|
|
350
|
+
? {}
|
|
351
|
+
: { baselineFingerprint: input.baselineFingerprint }),
|
|
349
352
|
...(context.principal === undefined ? {} : { principal: context.principal }),
|
|
350
353
|
...(context.signal === undefined ? {} : { signal: context.signal }),
|
|
351
354
|
});
|
|
@@ -369,6 +372,7 @@ export async function prepareMapRewrite(nudger, input, context) {
|
|
|
369
372
|
? {}
|
|
370
373
|
: { territory: planned.plan.territory.map(compactTerritoryReport) }),
|
|
371
374
|
...worldOutputsData(planned.plan),
|
|
375
|
+
...(planned.baseline === undefined ? {} : { baseline: planned.baseline }),
|
|
372
376
|
}),
|
|
373
377
|
filesScanned: planned.filesScanned,
|
|
374
378
|
planBlockers: planned.plan.blockers
|
|
@@ -673,6 +677,9 @@ export async function previewMapRewrite(nudger, input, context) {
|
|
|
673
677
|
workspaceId: context.workspaceId,
|
|
674
678
|
operations: input.operations,
|
|
675
679
|
...(input.diffScale === undefined ? {} : { diffScale: input.diffScale }),
|
|
680
|
+
...(input.baselineFingerprint === undefined
|
|
681
|
+
? {}
|
|
682
|
+
: { baselineFingerprint: input.baselineFingerprint }),
|
|
676
683
|
...(context.principal === undefined ? {} : { principal: context.principal }),
|
|
677
684
|
...(context.signal === undefined ? {} : { signal: context.signal }),
|
|
678
685
|
});
|
|
@@ -696,6 +703,7 @@ export async function previewMapRewrite(nudger, input, context) {
|
|
|
696
703
|
fileCount: planned.plan.changes.length,
|
|
697
704
|
artifactCount: planned.artifacts.length,
|
|
698
705
|
...worldOutputsData(planned.plan),
|
|
706
|
+
...(planned.baseline === undefined ? {} : { baseline: planned.baseline }),
|
|
699
707
|
...(input.operations.some(({ kind }) => kind === 'create_world') &&
|
|
700
708
|
generatedWorldOperationIds(planned.plan).size === 0
|
|
701
709
|
? {}
|
|
@@ -1055,6 +1063,8 @@ export async function inspectMap(engine, nudger, input, context) {
|
|
|
1055
1063
|
...(scriptReferences === undefined ? {} : { scriptReferences }),
|
|
1056
1064
|
...(borderQuality === undefined ? {} : { quality: borderQuality.summary }),
|
|
1057
1065
|
...(naturalLands === undefined ? {} : { lands: naturalLands.summary }),
|
|
1066
|
+
// A map write may state this to leave pre-existing errors outside its footprint (ADR 0090).
|
|
1067
|
+
baselineFingerprint: await nudger.baselineFingerprint(context.workspaceId, context.principal, context.signal),
|
|
1058
1068
|
});
|
|
1059
1069
|
result.code = 'MAP_INSPECTED';
|
|
1060
1070
|
setInlineFilesScanned(result, snapshot.files.map(({ displayPath }) => displayPath));
|
|
@@ -78,7 +78,7 @@ function addDiagnostic(diagnostics, options, diagnostic) {
|
|
|
78
78
|
...(diagnostic.operationId !== undefined || options.operationId === undefined
|
|
79
79
|
? {}
|
|
80
80
|
: { operationId: options.operationId }),
|
|
81
|
-
});
|
|
81
|
+
}, options.diagnosticLimit);
|
|
82
82
|
}
|
|
83
83
|
function duplicateValues(values, key) {
|
|
84
84
|
const groups = new Map();
|
|
@@ -1285,7 +1285,18 @@ function* validateMapSteps(index, options = {}) {
|
|
|
1285
1285
|
yield* validateAppearance(index, (diagnostic) => addDiagnostic(diagnostics, options, { ...diagnostic, category: 'map' }), { signal: options.signal, edgeMode: options.edgeMode });
|
|
1286
1286
|
yield* cancellationCheckpoint(options.signal);
|
|
1287
1287
|
const sorted = sortDiagnostics(diagnostics);
|
|
1288
|
-
const checks =
|
|
1288
|
+
const checks = mapValidationChecks(sorted);
|
|
1289
|
+
const passed = checks.every((check) => check.passed) &&
|
|
1290
|
+
!sorted.some(({ severity }) => severity === 'error' || severity === 'blocker');
|
|
1291
|
+
return { passed, diagnostics: sorted, checks };
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* The map validation checks: one per finding family, failed by any error or blocker of that
|
|
1295
|
+
* family in `diagnostics`.
|
|
1296
|
+
*/
|
|
1297
|
+
export function mapValidationChecks(diagnostics) {
|
|
1298
|
+
const sorted = diagnostics;
|
|
1299
|
+
return [
|
|
1289
1300
|
{
|
|
1290
1301
|
id: 'map-files-and-definitions',
|
|
1291
1302
|
passed: !sorted.some(({ code, severity }) => severity === 'error' || severity === 'blocker'
|
|
@@ -1344,9 +1355,6 @@ function* validateMapSteps(index, options = {}) {
|
|
|
1344
1355
|
message: 'Heightmap, terrain, river, tree, colour, normal and city bitmaps, lakes and the world edge are valid',
|
|
1345
1356
|
},
|
|
1346
1357
|
];
|
|
1347
|
-
const passed = checks.every((check) => check.passed) &&
|
|
1348
|
-
!sorted.some(({ severity }) => severity === 'error' || severity === 'blocker');
|
|
1349
|
-
return { passed, diagnostics: sorted, checks };
|
|
1350
1358
|
}
|
|
1351
1359
|
export function validateMap(index, options = {}) {
|
|
1352
1360
|
return completeSynchronously(validateMapSteps(index, options));
|
|
@@ -179,6 +179,7 @@ const mapWorkspaceInspectDataSchema = z
|
|
|
179
179
|
.optional(),
|
|
180
180
|
quality: borderQualitySummarySchema.optional(),
|
|
181
181
|
lands: naturalLandsSummarySchema.optional(),
|
|
182
|
+
baselineFingerprint: sha256Schema.optional(),
|
|
182
183
|
})
|
|
183
184
|
.strict();
|
|
184
185
|
const mapRenderDataSchema = z
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
+
import { MAP_BASELINE_FINGERPRINT_PATTERN } from '../map/baseline.js';
|
|
2
3
|
import { MAP_PROVINCE_GEOMETRY_SELECTOR_LIMIT } from '../map/limits.js';
|
|
3
4
|
import { backgroundRequestKeySchema, workspaceIdSchema } from './common.js';
|
|
4
5
|
import { borderQualityScopeSchema, mapAllocationRequestSchema, mapOperationSchema, naturalLandOptionsSchema, } from './map.js';
|
|
@@ -194,6 +195,11 @@ export const mapRewriteRequestSchema = z
|
|
|
194
195
|
.default(false)
|
|
195
196
|
.describe('Return generated reference, terrain and political previews and counts without changing mod files.'),
|
|
196
197
|
diffScale: z.number().int().min(1).max(16).optional(),
|
|
198
|
+
baselineFingerprint: z
|
|
199
|
+
.string()
|
|
200
|
+
.regex(MAP_BASELINE_FINGERPRINT_PATTERN)
|
|
201
|
+
.optional()
|
|
202
|
+
.describe('Opt-in: baselineFingerprint from a full hoi4.map_inspect of the untouched map. Pre-existing errors outside the write stop blocking; a changed map is refused.'),
|
|
197
203
|
requestKey: backgroundRequestKeySchema.optional(),
|
|
198
204
|
})
|
|
199
205
|
.strict();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LATEST_PROTOCOL_VERSION } from '@modelcontextprotocol/sdk/types.js';
|
|
2
2
|
export const PACKAGE_NAME = 'hoi4-agent-tools';
|
|
3
|
-
export const PACKAGE_VERSION = '4.
|
|
3
|
+
export const PACKAGE_VERSION = '4.20.1';
|
|
4
4
|
export const MCP_PROTOCOL_VERSION = LATEST_PROTOCOL_VERSION;
|
|
5
5
|
export const CONFIG_VERSION = 1;
|
|
6
6
|
export const TRANSACTION_VERSION = 2;
|
package/docs/map.md
CHANGED
|
@@ -322,6 +322,35 @@ The supported kinds are:
|
|
|
322
322
|
The complete operation schema is [map-operation.schema.json](../schemas/map-operation.schema.json).
|
|
323
323
|
The examples below show single operations; each goes inside the `operations` array.
|
|
324
324
|
|
|
325
|
+
### Writes over a map that already has errors
|
|
326
|
+
|
|
327
|
+
Without further input, every validation error blocks a write, including errors the map had before the write.
|
|
328
|
+
Each such error also adds a `MAP_VALIDATION_OPERATION_UNOWNED` blocker.
|
|
329
|
+
On a map with many pre-existing errors, no write can pass.
|
|
330
|
+
|
|
331
|
+
A write can opt in to a stated baseline ([ADR 0090](adr/0090-stated-map-baseline.md)):
|
|
332
|
+
|
|
333
|
+
1. Run a full `hoi4.map_inspect` on the untouched map. Its result carries `baselineFingerprint`: a hash of the tool version and of every scanned map source.
|
|
334
|
+
2. Pass that value as `baselineFingerprint` in `hoi4.map_rewrite`.
|
|
335
|
+
|
|
336
|
+
The server recomputes the fingerprint on the current source.
|
|
337
|
+
If the map changed since the inspect, the write is refused with `MAP_BASELINE_STALE`, so a caller cannot invent a baseline.
|
|
338
|
+
With a matching fingerprint, both validations keep every finding (up to 50,000) instead of 2,000, and each pre-existing error is judged against the write's footprint:
|
|
339
|
+
|
|
340
|
+
- An error that belongs to nothing the write touches no longer blocks. It is reported as a warning with `attributionStatus: "accepted-baseline"` and `baselineSeverity`. Repeated codes roll up into one entry per code, with its count and samples, so they count once each against the 100-diagnostic review limit.
|
|
341
|
+
- An error inside the footprint still blocks, as before.
|
|
342
|
+
- Every new error still blocks.
|
|
343
|
+
|
|
344
|
+
An error belongs to the objects its location and related locations name, and to the provinces its details name (`province`, `provinceId`, `provinceIds`, `provinces`).
|
|
345
|
+
|
|
346
|
+
- A location in a file the write leaves unchanged is untouched.
|
|
347
|
+
- A location on a row of a changed `definition.csv` is the province on that row. That province is touched when the write changes its definition row or any of its pixels.
|
|
348
|
+
- Any other location in a changed file is touched.
|
|
349
|
+
- An error that names no object at all counts as touched.
|
|
350
|
+
|
|
351
|
+
The result reports `baseline: { stated, matched, accepted, insideFootprint }`.
|
|
352
|
+
A stated baseline does not apply to `create_world`, which replaces the whole map ([ADR 0070](adr/0070-whole-map-validation-and-river-check.md)), and is refused there with `MAP_BASELINE_NOT_APPLICABLE`.
|
|
353
|
+
|
|
325
354
|
## Create states
|
|
326
355
|
|
|
327
356
|
The compact `create_state` form needs selected provinces and a `displayName` or `name`:
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/engine/bin/manifest.json
CHANGED
|
@@ -4,23 +4,23 @@
|
|
|
4
4
|
"binaries": {
|
|
5
5
|
"darwin-arm64": {
|
|
6
6
|
"file": "darwin-arm64/hoi4-engine",
|
|
7
|
-
"sha256": "
|
|
8
|
-
"size":
|
|
7
|
+
"sha256": "7a515361a74ea68802b1b730535b7eb9ca00634912e2c6e76f846d8cdac50532",
|
|
8
|
+
"size": 5332720
|
|
9
9
|
},
|
|
10
10
|
"linux-arm64": {
|
|
11
11
|
"file": "linux-arm64/hoi4-engine",
|
|
12
|
-
"sha256": "
|
|
13
|
-
"size":
|
|
12
|
+
"sha256": "61310845bb5dbcc4eae49c88159da62c263e2c3c44d1c8a555afc7215fac1400",
|
|
13
|
+
"size": 5635832
|
|
14
14
|
},
|
|
15
15
|
"linux-x64": {
|
|
16
16
|
"file": "linux-x64/hoi4-engine",
|
|
17
|
-
"sha256": "
|
|
18
|
-
"size":
|
|
17
|
+
"sha256": "66c15c1bed9da19a85ca842ca19c70b6eb1fc995ac71543893e8548b229ba796",
|
|
18
|
+
"size": 6208144
|
|
19
19
|
},
|
|
20
20
|
"win32-x64": {
|
|
21
21
|
"file": "win32-x64/hoi4-engine.exe",
|
|
22
|
-
"sha256": "
|
|
23
|
-
"size":
|
|
22
|
+
"sha256": "b62bfcd01847e344e7c304cfbdbd30045e74c04c4ce135cf00085c312378bf82",
|
|
23
|
+
"size": 5149184
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
Binary file
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hoi4-agent-tools",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.20.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "hoi4-agent-tools",
|
|
9
|
-
"version": "4.
|
|
9
|
+
"version": "4.20.1",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@fontsource-variable/roboto": "5.3.0",
|