hoi4-agent-tools 4.16.0 → 4.17.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 +29 -0
- package/README.md +1 -0
- package/dist/hoi4_agent_tools/core/analysis-checkpoints.js +11 -4
- package/dist/hoi4_agent_tools/core/engine-client.js +30 -1
- package/dist/hoi4_agent_tools/core/engine.js +56 -27
- package/dist/hoi4_agent_tools/core/managed-outputs.js +54 -3
- package/dist/hoi4_agent_tools/core/scanner.js +148 -7
- package/dist/hoi4_agent_tools/core/server-state.js +50 -2
- package/dist/hoi4_agent_tools/core/source/localisation.js +7 -1
- package/dist/hoi4_agent_tools/event/compare.js +47 -13
- package/dist/hoi4_agent_tools/focus/importer.js +2 -5
- package/dist/hoi4_agent_tools/focus/lint.js +2 -5
- package/dist/hoi4_agent_tools/focus/model.js +19 -0
- package/dist/hoi4_agent_tools/focus/tool-operations.js +16 -1
- package/dist/hoi4_agent_tools/focus/tool-support.js +14 -0
- package/dist/hoi4_agent_tools/map/appearance-validation.js +6 -1
- package/dist/hoi4_agent_tools/map/engine-raster.js +160 -0
- package/dist/hoi4_agent_tools/map/model.js +9 -8
- package/dist/hoi4_agent_tools/map/operations.js +20 -5
- package/dist/hoi4_agent_tools/map/partition-provinces.js +6 -2
- package/dist/hoi4_agent_tools/map/partition-tuning.js +37 -0
- package/dist/hoi4_agent_tools/map/service.js +25 -12
- package/dist/hoi4_agent_tools/map/territory-operations.js +114 -3
- package/dist/hoi4_agent_tools/map/territory-quality.js +39 -0
- package/dist/hoi4_agent_tools/map/territory.js +63 -2
- package/dist/hoi4_agent_tools/map/tool-operations.js +27 -1
- package/dist/hoi4_agent_tools/map/validation.js +23 -3
- package/dist/hoi4_agent_tools/map/water.js +13 -10
- package/dist/hoi4_agent_tools/map/world-outputs.js +41 -26
- package/dist/hoi4_agent_tools/map/world.js +51 -1
- package/dist/hoi4_agent_tools/mcp/tools/map.js +23 -0
- package/dist/hoi4_agent_tools/mcp/tools/reference.js +2 -2
- package/dist/hoi4_agent_tools/mcp/tools/technology.js +25 -1
- package/dist/hoi4_agent_tools/reference/closure.js +65 -0
- package/dist/hoi4_agent_tools/reference/command-phrases.json +7899 -1127
- package/dist/hoi4_agent_tools/reference/operations.js +38 -21
- package/dist/hoi4_agent_tools/reference/ranking.js +77 -2
- package/dist/hoi4_agent_tools/reference/script-validation.js +4 -2
- package/dist/hoi4_agent_tools/reference/service.js +45 -2
- package/dist/hoi4_agent_tools/reference/source-lookup.js +43 -121
- package/dist/hoi4_agent_tools/runtime.js +27 -11
- package/dist/hoi4_agent_tools/schemas/lenient-arguments.js +7 -1
- package/dist/hoi4_agent_tools/schemas/map.js +33 -0
- package/dist/hoi4_agent_tools/schemas/mod-tools.js +49 -0
- package/dist/hoi4_agent_tools/schemas/reference.js +1 -1
- package/dist/hoi4_agent_tools/schemas/script-validation.js +57 -3
- package/dist/hoi4_agent_tools/technology/operations.js +5 -0
- package/dist/hoi4_agent_tools/technology/queries.js +54 -0
- package/dist/hoi4_agent_tools/version.js +1 -1
- package/docs/configuration.md +1 -1
- package/docs/map.md +13 -11
- package/docs/research/reference-benchmark.md +64 -0
- package/docs/tools.md +20 -20
- package/docs/troubleshooting.md +4 -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 +5 -3
- 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 +817 -728
- 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 +2 -2
- 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 +7 -1
- package/schemas/shared-scenario.schema.json +1 -1
- package/schemas/source-lookup-input.schema.json +1 -1
- package/server.json +2 -2
|
@@ -24,39 +24,51 @@ export function reconcileWorldOutputs(sources, proposed, operationId, mapRoot, s
|
|
|
24
24
|
* output the request writes gets its new hash, or with `adoptAll` every recorded output its
|
|
25
25
|
* current bytes (`record_world_outputs`). Undefined when the workspace has no world inventory.
|
|
26
26
|
*/
|
|
27
|
-
export function refreshWorldOutputs(sources, proposed,
|
|
27
|
+
export function refreshWorldOutputs(sources, proposed, roots, options = {}) {
|
|
28
|
+
const permits = worldOutputPermits(roots);
|
|
28
29
|
return refreshManagedOutputs({
|
|
29
30
|
manifestPath: WORLD_OUTPUT_MANIFEST,
|
|
30
31
|
sources,
|
|
31
32
|
proposed,
|
|
32
|
-
|
|
33
|
+
// New files join the record where the world keeps its map outputs; country files stay out,
|
|
34
|
+
// since a workspace may own its countries (ADR 0069).
|
|
35
|
+
addable: (name) => permits(name) && !isWorldCountryOutput(name),
|
|
36
|
+
// States and strategic regions are in every map scan; bitmaps, colour maps and the world
|
|
37
|
+
// scripts only in some, so only the first can be known to be gone.
|
|
38
|
+
alwaysScanned: (name) => {
|
|
39
|
+
const dir = path.posix.dirname(name);
|
|
40
|
+
return roots.stateRoots.includes(dir) || dir === `${roots.mapRoot}/strategicregions`;
|
|
41
|
+
},
|
|
42
|
+
...(options.adoptAll === true ? { adoptAll: true } : {}),
|
|
43
|
+
...(options.adoptUnrecorded === true ? { adoptUnrecorded: true } : {}),
|
|
33
44
|
});
|
|
34
45
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
const WORLD_MAP_FILES = new Set([
|
|
47
|
+
'provinces.bmp',
|
|
48
|
+
'definition.csv',
|
|
49
|
+
'default.map',
|
|
50
|
+
'continent.txt',
|
|
51
|
+
'adjacencies.csv',
|
|
52
|
+
'adjacency_rules.txt',
|
|
53
|
+
'positions.txt',
|
|
54
|
+
'ambient_object.txt',
|
|
55
|
+
'heightmap.bmp',
|
|
56
|
+
'terrain.bmp',
|
|
57
|
+
'rivers.bmp',
|
|
58
|
+
'trees.bmp',
|
|
59
|
+
'cities.bmp',
|
|
60
|
+
'world_normal.bmp',
|
|
61
|
+
'buildings.txt',
|
|
62
|
+
'unitstacks.txt',
|
|
63
|
+
'weatherpositions.txt',
|
|
64
|
+
'supply_nodes.txt',
|
|
65
|
+
'railways.txt',
|
|
66
|
+
]);
|
|
67
|
+
/** The paths a generated world records as its outputs. */
|
|
68
|
+
export function worldOutputPermits({ mapRoot, stateRoots, localisationRoots, }) {
|
|
69
|
+
return (name) => {
|
|
58
70
|
const dir = path.posix.dirname(name), file = path.posix.basename(name);
|
|
59
|
-
return ((dir === mapRoot &&
|
|
71
|
+
return ((dir === mapRoot && WORLD_MAP_FILES.has(file)) ||
|
|
60
72
|
(dir === `${mapRoot}/terrain` && /^colormap_[a-z0-9_]+\.dds$/u.test(file)) ||
|
|
61
73
|
(dir === `${mapRoot}/strategicregions` && /^\d+.*\.txt$/u.test(file)) ||
|
|
62
74
|
(stateRoots.includes(dir) && /^\d+.*\.txt$/u.test(file)) ||
|
|
@@ -69,6 +81,9 @@ export function planWorldOutputs(sources, proposed, operationId, mapRoot, stateR
|
|
|
69
81
|
localisationRoots.some((root) => name === `${root}/english/world_l_english.yml` ||
|
|
70
82
|
name === `${root}/replace/world_l_english.yml`));
|
|
71
83
|
};
|
|
84
|
+
}
|
|
85
|
+
export function planWorldOutputs(sources, proposed, operationId, mapRoot, stateRoots, localisationRoots, options = {}) {
|
|
86
|
+
const permitsPath = worldOutputPermits({ mapRoot, stateRoots, localisationRoots });
|
|
72
87
|
return planManagedOutputs({
|
|
73
88
|
manifestPath: WORLD_OUTPUT_MANIFEST,
|
|
74
89
|
sources,
|
|
@@ -11,7 +11,7 @@ import { generateWorldDrainage } from './world-drainage.js';
|
|
|
11
11
|
import { generateWorldProvinces } from './world-provinces.js';
|
|
12
12
|
import { clusterRegions, clusterStates, partitionWorldFromRequest, } from './partition.js';
|
|
13
13
|
import { repairSeamCorners, smoothDiagonalContacts } from './partition-fields.js';
|
|
14
|
-
import { PARTITION_PROVINCE_ERROR, PARTITION_PROVINCE_WARNING } from './partition-tuning.js';
|
|
14
|
+
import { areaRowFactor, PARTITION_PROVINCE_ERROR, PARTITION_PROVINCE_WARNING, } from './partition-tuning.js';
|
|
15
15
|
import { buildTerritoryAtoms, territoryGraphFromPartition } from './territory-graph.js';
|
|
16
16
|
import { growTerritory } from './territory.js';
|
|
17
17
|
import { geographyPartitionFields, provinceCountNote, surfacePartitionFields, } from './world-partition.js';
|
|
@@ -409,6 +409,53 @@ function estimatePermanentSnow(input) {
|
|
|
409
409
|
}
|
|
410
410
|
return count;
|
|
411
411
|
}
|
|
412
|
+
/**
|
|
413
|
+
* The realised land province areas of `partitionTuning.areaByRow`: for each band between two of
|
|
414
|
+
* its rows (and the rows beyond its ends), the land provinces whose centre lies there, their mean
|
|
415
|
+
* area and its ratio to the mean of the band with the smallest factor.
|
|
416
|
+
*/
|
|
417
|
+
function areaByRowNote(provinces, points, height) {
|
|
418
|
+
const edges = [...new Set([0, ...points.map(([row]) => row), 1])].sort((a, b) => a - b);
|
|
419
|
+
const bands = edges.slice(0, -1).map((from, index) => ({
|
|
420
|
+
from,
|
|
421
|
+
to: edges[index + 1],
|
|
422
|
+
factor: [
|
|
423
|
+
Number(areaRowFactor(points, from * height - 0.5, height).toFixed(3)),
|
|
424
|
+
Number(areaRowFactor(points, edges[index + 1] * height - 0.5, height).toFixed(3)),
|
|
425
|
+
],
|
|
426
|
+
provinces: 0,
|
|
427
|
+
pixels: 0,
|
|
428
|
+
}));
|
|
429
|
+
for (let id = 0; id < provinces.kind.length; id += 1) {
|
|
430
|
+
if (provinces.kind[id] !== LAND || (provinces.size[id] ?? 0) === 0)
|
|
431
|
+
continue;
|
|
432
|
+
const row = provinces.sumY[id] / provinces.size[id] / height;
|
|
433
|
+
const band = bands.find(({ from, to }, index) => row >= from && (row < to || index === bands.length - 1)) ?? bands[bands.length - 1];
|
|
434
|
+
band.provinces += 1;
|
|
435
|
+
band.pixels += provinces.size[id];
|
|
436
|
+
}
|
|
437
|
+
const filled = bands.filter(({ provinces: count }) => count > 0);
|
|
438
|
+
const smallest = filled.reduce((best, band) => best === undefined || Math.max(...band.factor) < Math.max(...best.factor) ? band : best, undefined);
|
|
439
|
+
const reference = smallest === undefined ? 0 : smallest.pixels / smallest.provinces;
|
|
440
|
+
const report = bands.map(({ from, to, factor, provinces: count, pixels }) => {
|
|
441
|
+
const mean = count === 0 ? 0 : pixels / count;
|
|
442
|
+
return {
|
|
443
|
+
rows: [from, to],
|
|
444
|
+
factor,
|
|
445
|
+
landProvinces: count,
|
|
446
|
+
meanAreaPx: Math.round(mean),
|
|
447
|
+
...(reference > 0 && count > 0 ? { ratio: Number((mean / reference).toFixed(2)) } : {}),
|
|
448
|
+
};
|
|
449
|
+
});
|
|
450
|
+
return {
|
|
451
|
+
code: 'MAP_PARTITION_AREA_BY_ROW',
|
|
452
|
+
severity: 'info',
|
|
453
|
+
message: `Land province area by row: ${report
|
|
454
|
+
.map(({ rows, landProvinces, meanAreaPx }) => `rows ${rows[0]}-${rows[1]}: ${landProvinces} provinces of ${meanAreaPx} px on average`)
|
|
455
|
+
.join('; ')}`,
|
|
456
|
+
details: { areaByRow: points, bands: report },
|
|
457
|
+
};
|
|
458
|
+
}
|
|
412
459
|
/** Land relief of the base game 1.19.4.1 (`reliefStatistics` over its land provinces). */
|
|
413
460
|
export const VANILLA_RELIEF = { median: 107, p99: 213, maximum: 239, meanStep: 2.69 };
|
|
414
461
|
function terrainSummaryNote(terrain, geography) {
|
|
@@ -1039,6 +1086,9 @@ export function generateWorld(spec, context, options = {}) {
|
|
|
1039
1086
|
provinces = featurePartition.provinces;
|
|
1040
1087
|
for (const note of featurePartition.notes)
|
|
1041
1088
|
notes.push(note);
|
|
1089
|
+
const areaByRow = featurePartition.tuning.areaByRow;
|
|
1090
|
+
if (areaByRow !== undefined)
|
|
1091
|
+
notes.push(areaByRowNote(provinces, areaByRow, height));
|
|
1042
1092
|
}
|
|
1043
1093
|
else
|
|
1044
1094
|
provinces = generateWorldProvinces({
|
|
@@ -120,6 +120,29 @@ const mapWorkspaceInspectDataSchema = z
|
|
|
120
120
|
provinceGeometryPixelCount: nonNegativeIntegerSchema,
|
|
121
121
|
provinceGeometryRowRunCount: nonNegativeIntegerSchema,
|
|
122
122
|
lookupOnly: z.boolean().optional(),
|
|
123
|
+
/** The first 20 query matches, best first; the full list is in the linked artifact. */
|
|
124
|
+
matches: z
|
|
125
|
+
.array(z
|
|
126
|
+
.object({
|
|
127
|
+
kind: z.enum(['province', 'state', 'strategic-region']),
|
|
128
|
+
id: nonNegativeIntegerSchema,
|
|
129
|
+
key: z.string(),
|
|
130
|
+
name: z.string(),
|
|
131
|
+
})
|
|
132
|
+
.strict())
|
|
133
|
+
.max(20)
|
|
134
|
+
.optional(),
|
|
135
|
+
/** What each requested coordinate falls in (the first 20). */
|
|
136
|
+
coordinateMatches: z
|
|
137
|
+
.array(z
|
|
138
|
+
.object({
|
|
139
|
+
provinceId: nonNegativeIntegerSchema.nullable(),
|
|
140
|
+
stateIds: z.array(nonNegativeIntegerSchema).max(16),
|
|
141
|
+
regionIds: z.array(nonNegativeIntegerSchema).max(16),
|
|
142
|
+
})
|
|
143
|
+
.strict())
|
|
144
|
+
.max(20)
|
|
145
|
+
.optional(),
|
|
123
146
|
unknownProvinceIds: z.array(nonNegativeIntegerSchema).max(512),
|
|
124
147
|
missingGeometryProvinceIds: z.array(nonNegativeIntegerSchema).max(512),
|
|
125
148
|
scriptReferences: z
|
|
@@ -19,7 +19,7 @@ export const referenceTools = [
|
|
|
19
19
|
{
|
|
20
20
|
name: 'hoi4.reference_search',
|
|
21
21
|
title: 'Find a modding rule',
|
|
22
|
-
description: 'Find
|
|
22
|
+
description: 'Find a modding rule in the offline wiki and installed game docs by plain words or script name. Returns up to 10 short candidates (limit up to 12) with file, lines, revision and, for a command, a one-line meaning and its scopes. Pick the one that fits, since several commands sound alike, then read it with hoi4.reference_read using its id and revision. Example: {"query":"add_timed_idea"} or {"query":"make a country hold elections now"}.',
|
|
23
23
|
inputSchema: referenceSearchRequestSchema,
|
|
24
24
|
outputSchema: strictOperationResultSchema(referenceSearchToolDataSchema),
|
|
25
25
|
annotations: readOnly,
|
|
@@ -51,7 +51,7 @@ export const referenceTools = [
|
|
|
51
51
|
{
|
|
52
52
|
name: 'hoi4.script_validate',
|
|
53
53
|
title: 'Check HOI4 script commands and scopes',
|
|
54
|
-
description: 'Find broken syntax, commands and scopes in an effect, trigger or mod file using the installed docs. Unknown helpers and native argument blocks stay unresolved. Example: {"source":"add_political_power = 10","kind":"effect","scope":"country"} or {"path":"events/a.txt"}. Returns up to 12 findings.',
|
|
54
|
+
description: 'Find broken syntax, commands and scopes in an effect, trigger or mod file using the installed docs. Unknown helpers and native argument blocks stay unresolved. Example: {"source":"add_political_power = 10","kind":"effect","scope":"country"} or {"path":"events/a.txt"}. {"closure":true} instead counts whether the references of the whole mod resolve, per kind. Returns up to 12 findings.',
|
|
55
55
|
inputSchema: scriptValidateRequestSchema,
|
|
56
56
|
outputSchema: strictOperationResultSchema(scriptValidateDataSchema),
|
|
57
57
|
annotations: readOnly,
|
|
@@ -45,6 +45,30 @@ const analysisDataSchema = z
|
|
|
45
45
|
graphHash: sha256Schema,
|
|
46
46
|
counts: countsSchema,
|
|
47
47
|
helperExpansion: helperExpansionSummarySchema.optional(),
|
|
48
|
+
/** Mode explain: the technology, its direct neighbours and unlocks (20 names each at most). */
|
|
49
|
+
technology: z
|
|
50
|
+
.object({
|
|
51
|
+
id: z.string(),
|
|
52
|
+
path: z.string(),
|
|
53
|
+
line: z.number().int().min(0),
|
|
54
|
+
name: z.string().optional(),
|
|
55
|
+
startYear: z.string().optional(),
|
|
56
|
+
researchCost: z.string().optional(),
|
|
57
|
+
folders: z.array(z.string()),
|
|
58
|
+
categories: z.array(z.string()),
|
|
59
|
+
prerequisites: z.array(z.string()).max(20),
|
|
60
|
+
leadsTo: z.array(z.string()).max(20),
|
|
61
|
+
exclusiveWith: z.array(z.string()).max(20),
|
|
62
|
+
unlocks: z.array(z.object({ kind: z.string(), targetId: z.string() }).strict()).max(20),
|
|
63
|
+
allPrerequisites: nonNegativeIntegerSchema,
|
|
64
|
+
allDescendants: nonNegativeIntegerSchema,
|
|
65
|
+
unlockCount: nonNegativeIntegerSchema,
|
|
66
|
+
grantedBy: nonNegativeIntegerSchema,
|
|
67
|
+
issues: nonNegativeIntegerSchema,
|
|
68
|
+
truncated: z.boolean(),
|
|
69
|
+
})
|
|
70
|
+
.strict()
|
|
71
|
+
.optional(),
|
|
48
72
|
})
|
|
49
73
|
.strict();
|
|
50
74
|
const renderOutputSchema = strictOperationResultSchema(z
|
|
@@ -93,7 +117,7 @@ export const technologyTaskTools = [
|
|
|
93
117
|
{
|
|
94
118
|
name: 'hoi4.tech_inspect',
|
|
95
119
|
title: 'Inspect technology trees',
|
|
96
|
-
description: 'Explain technology and doctrine paths, unlocks, bonuses and dependencies. Find layout or reference problems and compare revisions with mode compare. Example: {"mode":"explain","technologyId":"my_tech"}. Returns counts and the
|
|
120
|
+
description: 'Explain technology and doctrine paths, unlocks, bonuses and dependencies. Find layout or reference problems and compare revisions with mode compare. Example: {"mode":"explain","technologyId":"my_tech"}. Returns counts inline, and for explain the prerequisites, what it leads to and its unlocks; the full report is a linked resource.',
|
|
97
121
|
inputSchema: inspectInputSchema,
|
|
98
122
|
outputSchema: analysisOutputSchema,
|
|
99
123
|
annotations: readOnlyTechnologyTool,
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { defaultPatterns } from '../core/engine.js';
|
|
2
|
+
import { runEngineCommand } from '../core/engine-client.js';
|
|
3
|
+
import { ServiceError } from '../core/result.js';
|
|
4
|
+
import { closureEngineResponseSchema } from '../schemas/mod-tools.js';
|
|
5
|
+
import { modIndexEngineRequest, SOURCE_ROOT_KINDS } from './mod-index.js';
|
|
6
|
+
const CLOSURE_REQUEST_SCHEMA = 'hoi4-closure-request/1';
|
|
7
|
+
/** A cold index of the game, its DLC and a large mod, plus the semantic scan of the mod's sources. */
|
|
8
|
+
const CLOSURE_TIMEOUT_MS = 180_000;
|
|
9
|
+
/** One plain sentence on the closure, for the validation message. */
|
|
10
|
+
export function closureMessage(closure) {
|
|
11
|
+
const { resolved, unresolved, unknown } = closure.totals;
|
|
12
|
+
return `Closure ${closure.verdict}: ${resolved} resolved, ${unresolved} unresolved, ${unknown} unknown references in ${closure.sources} sources`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The closure option of `hoi4.script_validate` (ADR 0083): whether the definitions the mod's own
|
|
16
|
+
* sources point at exist. The shared Rust engine indexes the game, its DLC and the mod, counts the
|
|
17
|
+
* mod's references per target kind and decides the verdict; a missing engine is
|
|
18
|
+
* `ENGINE_UNAVAILABLE`, never a TypeScript scan.
|
|
19
|
+
*/
|
|
20
|
+
export async function checkClosure(engine, workspaceId, principal, signal) {
|
|
21
|
+
signal?.throwIfAborted();
|
|
22
|
+
await engine.resolver.refreshDescriptors(workspaceId, principal);
|
|
23
|
+
const workspace = engine.resolver.get(workspaceId, principal);
|
|
24
|
+
const answered = await runEngineCommand('closure', {
|
|
25
|
+
...modIndexEngineRequest(workspace, engine.resolver.config(), SOURCE_ROOT_KINDS),
|
|
26
|
+
schema: CLOSURE_REQUEST_SCHEMA,
|
|
27
|
+
patterns: defaultPatterns(workspace),
|
|
28
|
+
}, closureEngineResponseSchema, { timeoutMs: CLOSURE_TIMEOUT_MS, ...(signal === undefined ? {} : { signal }) });
|
|
29
|
+
if (!answered.available)
|
|
30
|
+
throw new ServiceError('ENGINE_UNAVAILABLE', answered.message, { reason: answered.reason });
|
|
31
|
+
if (answered.outcome === 'invalid_request')
|
|
32
|
+
throw new ServiceError(answered.error.code, answered.error.message);
|
|
33
|
+
const response = answered.response;
|
|
34
|
+
const reasons = [];
|
|
35
|
+
if (response.totals.unknown > 0)
|
|
36
|
+
reasons.push(`${response.totals.unknown} references cannot be decided: their target is dynamic, a skipped source may define it, or a variable, flag or event target is read with no visible writer`);
|
|
37
|
+
if (!response.complete)
|
|
38
|
+
reasons.push(`The index skipped ${response.skippedSourceCount} sources that exceed a parsing limit, so a definition may be missing`);
|
|
39
|
+
if (!response.semanticComplete)
|
|
40
|
+
reasons.push('The reference scan skipped a source or reached its ceiling');
|
|
41
|
+
const closure = {
|
|
42
|
+
verdict: response.verdict,
|
|
43
|
+
revision: response.revision,
|
|
44
|
+
complete: response.complete,
|
|
45
|
+
semanticComplete: response.semanticComplete,
|
|
46
|
+
skippedSourceCount: response.skippedSourceCount,
|
|
47
|
+
sources: response.sources,
|
|
48
|
+
totals: response.totals,
|
|
49
|
+
kinds: response.kinds,
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
valid: response.verdict === 'closed' ? true : response.verdict === 'unresolved' ? false : null,
|
|
53
|
+
checksPerformed: ['closure'],
|
|
54
|
+
parametersChecked: false,
|
|
55
|
+
findings: [],
|
|
56
|
+
totalFindings: 0,
|
|
57
|
+
omittedFindings: 0,
|
|
58
|
+
checkedCommands: 0,
|
|
59
|
+
unresolvedCount: 0,
|
|
60
|
+
truncated: false,
|
|
61
|
+
argumentBlocksUnchecked: 0,
|
|
62
|
+
...(reasons.length === 0 ? {} : { partialReasons: reasons.slice(0, 5) }),
|
|
63
|
+
closure,
|
|
64
|
+
};
|
|
65
|
+
}
|