hoi4-agent-tools 4.9.0 → 4.11.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 +20 -0
- package/dist/hoi4_agent_tools/core/operation-result.js +51 -11
- package/dist/hoi4_agent_tools/core/workspace.js +22 -7
- package/dist/hoi4_agent_tools/decision/service.js +13 -1
- package/dist/hoi4_agent_tools/event/graph.js +16 -2
- package/dist/hoi4_agent_tools/event/source-analysis.js +35 -16
- package/dist/hoi4_agent_tools/impact/service.js +4 -1
- package/dist/hoi4_agent_tools/map/gameplay/reachability.js +81 -0
- package/dist/hoi4_agent_tools/map/geography/resolve.js +3 -0
- package/dist/hoi4_agent_tools/map/operations.js +8 -0
- package/dist/hoi4_agent_tools/map/partition-tuning.js +2 -1
- package/dist/hoi4_agent_tools/map/reference-world.js +17 -3
- package/dist/hoi4_agent_tools/map/relief/painted-relief.js +143 -0
- package/dist/hoi4_agent_tools/map/relief/terrain-synthesis.js +13 -0
- package/dist/hoi4_agent_tools/map/world.js +108 -23
- package/dist/hoi4_agent_tools/mcp/resources/register-modern.js +11 -4
- package/dist/hoi4_agent_tools/mcp/resources/register.js +7 -0
- package/dist/hoi4_agent_tools/mcp/server/argument-errors.js +1 -0
- package/dist/hoi4_agent_tools/mcp/tools/analysis.js +12 -0
- package/dist/hoi4_agent_tools/mcp/tools/reference.js +12 -3
- package/dist/hoi4_agent_tools/package-check/service.js +14 -1
- package/dist/hoi4_agent_tools/probability/model.js +4 -4
- package/dist/hoi4_agent_tools/probability/operations.js +6 -0
- package/dist/hoi4_agent_tools/probability/service.js +23 -0
- package/dist/hoi4_agent_tools/reference/operations.js +35 -6
- package/dist/hoi4_agent_tools/reference/service.js +118 -14
- package/dist/hoi4_agent_tools/reference/skill-resource.js +74 -0
- package/dist/hoi4_agent_tools/reference/skills.js +278 -0
- package/dist/hoi4_agent_tools/schemas/geography.js +5 -0
- package/dist/hoi4_agent_tools/schemas/map.js +29 -0
- package/dist/hoi4_agent_tools/schemas/reference.js +34 -2
- package/dist/hoi4_agent_tools/schemas/skill.js +72 -0
- package/dist/hoi4_agent_tools/version.js +1 -1
- package/docs/configuration.md +3 -3
- package/docs/map.md +12 -9
- package/docs/probability.md +1 -1
- package/docs/reference.md +27 -1
- package/docs/research/probability-adapter-evidence.md +15 -2
- package/docs/tools.md +101 -86
- package/engine/bin/manifest.json +1 -1
- package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -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 +4 -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 +177 -118
- 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 +3 -3
- 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
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 4.11.0 - 2026-11-07
|
|
6
|
+
|
|
7
|
+
- Add `hoi4.skill` and the skill resources (#108, M-1). The tool lists the skills HOI4 Mod Setup installed in the mod or loads one by name, and the same `SKILL.md` text is the resource `hoi4-agent://workspace/{workspaceId}/skill/{name}`. Both serve the kit version the mod's Setup lock pins, with the kit revision and each file's SHA-256. A file edited since Setup installed it is refused with `SKILL_TEXT_DRIFTED` unless the caller accepts local edits, and a mod without a lock gets its installed skills marked unpinned.
|
|
8
|
+
- Smaller answers (maintainer decision R-4). The reference tools (`reference_search`, `reference_read`, `reference_context`, `source_lookup`, `script_validate`, `error_log`, `mod_index` and the `*_inspect` tools beside them), which agents call most, leave out `filesScanned`, `proposedFiles`, `changedFiles`, `diagnostics`, `artifacts` and `blockers` when they are empty, and `validation.checks` when there are none. An absent list means an empty one, and the advertised output schema marks them optional for every tool. The other tools keep the full envelope for now. A `reference_search` or `reference_context` hit names its file under its source's folder (`wiki:event_modding.md`, `game_doc:documentation/effects_documentation.md`) instead of an absolute path, carries a 16-character id and a 12-character revision instead of two 64-character hashes, leaves out the source's authority line, and repeats the page title only when it differs from the heading. `reference_read` accepts these short forms and still accepts the full ones. A stale revision is still caught. When no mod is selected, `WORKSPACE_CONTEXT_NOT_FOUND` and `WORKSPACE_CONTEXT_REQUIRED` list the mod folder names (`modFolders`) and one line that says what to pass (`fix`), instead of opaque workspace ids. A `workspaceId` that names a mod folder now matches in any letter case and with spaces, as the folder appears in a file manager.
|
|
9
|
+
- Generate the tool tables and example calls in `docs/tools.md` from `tools/list` (#109, M-5). `npm run docs:tools` rewrites them, and `tests/integration/tool-docs.test.ts` fails when the page drifts from the tool definitions, when two tools share a name, when a tool has no section, or when a description has no example call. The first run added the missing `hoi4.asset_inspect` row, updated four example calls that no longer matched their descriptions, and dropped three second calls that no description carries.
|
|
10
|
+
- More answers come inline, with less unrelated noise (part of #66). `package_check` names every item that is not present in `data.notPresent` (category, id, status, reason and path, up to 32), so the answer needs no report. `filesScanned` of `package_check`, of a `decision_inspect` inspection or comparison, and of `impact_inspect` now lists the files that hold the checked items, the decision or the symbol and its consumers, instead of the first twelve files of the workspace. The tools list budget in the discovery test moves from 80 to 84 KiB, as in #104 and #105.
|
|
11
|
+
- Record the 2026-11-01 head-to-head with cpntodd/HOI4-MCP in `docs/research/hoi4-mcp-head-to-head-2026-11-01.md` (part of #111, M-7). The record says that it predates the accuracy fixes and that its seeded `owner = ROOT` control was wrong ground truth, because `owner` is not a trigger.
|
|
12
|
+
|
|
13
|
+
## 4.10.0 - 2026-11-06
|
|
14
|
+
|
|
15
|
+
- Size lake provinces: `create_world.partitionTuning.lakeArea` (default 6,000 pixels, capped at the largest province the map allows) sets the area of a lake province, so a drawn lake no larger than it stays one province.
|
|
16
|
+
- Raise the relief toward a reference picture's painted mountains, hills and volcanoes (`create_world.relief.painted`, ADR 0079). The classes are blurred over `falloffPx` (default 24) before the rivers are routed, so slopes stay natural and the model's rivers flow around the drawn ranges. Painted mountains get permanent snow by latitude. `MAP_RELIEF_SYNTHESIZED` now reports the base game's relief beside the world's.
|
|
17
|
+
- Make land impassable (ADR 0079): paint it with the palette kind `impassable_mountain` or mark a model region `impassable: true`.
|
|
18
|
+
- Its provinces become impassable `enclave` states linked to the nearest passable state, and it rises to the highest ground.
|
|
19
|
+
- Cities and capitals on it are refused (`MAP_FEATURE_IN_IMPASSABLE`).
|
|
20
|
+
- `MAP_REALM_CUT_OFF` and `MAP_REALM_ENCLOSED` warn when impassable land or borders cut a realm apart or box it in.
|
|
21
|
+
- `EVENT_TARGET_READ_BEFORE_SAVE` no longer reports correct script (#60). A `has_event_target` or `has_global_event_target` check tests whether a target exists. Without a visible producer it is now the design warning `EVENT_GATE_WITHOUT_WRITER`, not a probable defect. A read that such a check guards in the same event, focus or decision is not reported. Names built in a `meta_effect` or with `$parameter$`s are no longer cut at their first bracket. Names far into a long block are read in full instead of being cut at the display limit. The event graph now reads shared and joint focuses and the `completion_reward_joint_originator` and `completion_reward_joint_member` rewards, where vanilla saves `SSB_leader`. On Chaos Redux with vanilla 1.19.4.1 the findings drop from 33 to 2. Both remaining ones are real: vanilla reads `demanded_prov_target` in `events/Generic.txt` and saves it nowhere.
|
|
22
|
+
- Check the hand-kept game data against the installed build (#70). The probability adapters were re-checked on 1.19.4.1: five of the six documentation files they rest on are byte-identical to 1.19.2.0, and the two AI strategy sections they use say the same, so the target moves to `Operation Postern 1.19.4.1 (f584)` and the adapter version to `hoi4-1.19.4.1.v1`. A result on another build now carries the warning `PROBABILITY_GAME_BUILD_UNVERIFIED` instead of only recording `workspace_observed` in its metadata. The nightly game-update watcher lists the adapters or the native-effects list under "Checked against another build" on every run while their pin differs from the installed build, not only on the night the build changes.
|
|
23
|
+
- Keep the kit wiki's maintenance text out of reference answers. `hoi4.reference_search`, `hoi4.reference_read` and `hoi4.reference_context` never index `LICENSE.txt`, `SOURCES.json` (or `SOURCES.md`) and `manifest.json` (or `manifest.md`) in the wiki folder, whatever their extension, and no longer serve HTML comments from Markdown sources. Kit wiki pages from before the kit made them lean carry `<!-- kit:begin ... -->` markers, and a search excerpt could open with one. A comment is blanked outside code fences and inline code, and every line is kept, so cited line numbers still match the file. On the 163 hand-checked questions of the discovery benchmark the kit's lean wiki answers as well as before (131 rather than 130 within five results) and the median reply is 9 percent smaller.
|
|
24
|
+
|
|
5
25
|
## 4.9.0 - 2026-11-05
|
|
6
26
|
|
|
7
27
|
- Results no longer suggest the wrong conclusion (#65, the parts #82 left open). `error_log` fails a new `error-log-age` check when the mod's script, localisation or interface files changed after the log was written, and names how many, the newest time and an example file, because such a log cannot vouch for the current source. `script_validate` names what made a result partial (`partialReasons`), for example the blocks of a scripted helper file whose scope depends on the caller, by line, so `SCRIPT_CHECK_PARTIAL` with `unresolvedCount: 0` no longer comes without a reason. Every example in a tool description or an argument error is now checked against the tool's own schema in a test. That found and fixed the `gui_rewrite` patch example, which lacked the required `description`, and the `gui_rewrite` and `mechanic_test` examples, which held `...` placeholders. An unknown field in the arguments now lists the fields that object accepts. The tools list budget in the discovery test moves from 80 to 84 KiB for the longer, runnable examples.
|
|
@@ -57,22 +57,61 @@ const compactPublicOperationResultSchema = z
|
|
|
57
57
|
status: z.enum(['ok', 'blocked', 'error']),
|
|
58
58
|
code: z.string(),
|
|
59
59
|
workspaceId: z.string(),
|
|
60
|
-
filesScanned: z.array(z.unknown()),
|
|
61
|
-
proposedFiles: z.array(z.unknown()),
|
|
62
|
-
changedFiles: z.array(z.unknown()),
|
|
63
|
-
diagnostics: z.array(z.unknown()).max(MAX_INLINE_DIAGNOSTICS),
|
|
64
|
-
artifacts: z.array(z.unknown()).max(MAX_INLINE_ARTIFACT_LINKS),
|
|
60
|
+
filesScanned: z.array(z.unknown()).optional(),
|
|
61
|
+
proposedFiles: z.array(z.unknown()).optional(),
|
|
62
|
+
changedFiles: z.array(z.unknown()).optional(),
|
|
63
|
+
diagnostics: z.array(z.unknown()).max(MAX_INLINE_DIAGNOSTICS).optional(),
|
|
64
|
+
artifacts: z.array(z.unknown()).max(MAX_INLINE_ARTIFACT_LINKS).optional(),
|
|
65
65
|
validation: z.unknown(),
|
|
66
|
-
blockers: z.array(z.unknown()),
|
|
66
|
+
blockers: z.array(z.unknown()).optional(),
|
|
67
67
|
data: z.object({}).catchall(z.unknown()),
|
|
68
68
|
})
|
|
69
69
|
.strict();
|
|
70
|
+
/**
|
|
71
|
+
* Collections a compact tool result leaves out when they are empty. The reference tools answer
|
|
72
|
+
* most often, so their answers do not repeat six empty lists; an absent list is empty.
|
|
73
|
+
*/
|
|
74
|
+
const OMITTED_WHEN_EMPTY = [
|
|
75
|
+
'filesScanned',
|
|
76
|
+
'proposedFiles',
|
|
77
|
+
'changedFiles',
|
|
78
|
+
'diagnostics',
|
|
79
|
+
'artifacts',
|
|
80
|
+
'blockers',
|
|
81
|
+
];
|
|
82
|
+
/** The published envelope: the same fields, with empty collections and empty checks optional. */
|
|
83
|
+
const publicOperationResultBaseSchema = operationResultBaseSchema
|
|
84
|
+
.partial({
|
|
85
|
+
filesScanned: true,
|
|
86
|
+
proposedFiles: true,
|
|
87
|
+
changedFiles: true,
|
|
88
|
+
diagnostics: true,
|
|
89
|
+
artifacts: true,
|
|
90
|
+
blockers: true,
|
|
91
|
+
})
|
|
92
|
+
.extend({ validation: validationSummarySchema.partial({ checks: true }) })
|
|
93
|
+
.strict();
|
|
94
|
+
/** Drop the empty collections and empty validation checks from a structured result. */
|
|
95
|
+
export function withoutEmptyCollections(structured) {
|
|
96
|
+
const omitted = new Set(OMITTED_WHEN_EMPTY);
|
|
97
|
+
const result = Object.fromEntries(Object.entries(structured).filter(([key, value]) => !(omitted.has(key) && Array.isArray(value) && value.length === 0)));
|
|
98
|
+
const validation = result.validation;
|
|
99
|
+
if (validation !== null &&
|
|
100
|
+
typeof validation === 'object' &&
|
|
101
|
+
'checks' in validation &&
|
|
102
|
+
Array.isArray(validation.checks) &&
|
|
103
|
+
validation.checks.length === 0) {
|
|
104
|
+
const { checks: _checks, ...rest } = validation;
|
|
105
|
+
result.validation = rest;
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
70
109
|
/**
|
|
71
110
|
* Advertise one compact operation envelope while retaining exact per-tool runtime validation.
|
|
72
111
|
* The generic operation-result schema remains available for stored envelopes.
|
|
73
112
|
*/
|
|
74
113
|
export function strictOperationResultSchema(successDataSchema) {
|
|
75
|
-
const exactSchema =
|
|
114
|
+
const exactSchema = publicOperationResultBaseSchema
|
|
76
115
|
.extend({ data: z.union([emptyToolDataSchema, successDataSchema]) })
|
|
77
116
|
.strict();
|
|
78
117
|
return compactPublicOperationResultSchema.superRefine((value, context) => {
|
|
@@ -421,8 +460,9 @@ function compactDescriptions(unfiltered) {
|
|
|
421
460
|
})),
|
|
422
461
|
};
|
|
423
462
|
}
|
|
424
|
-
function buildToolResult(selected, imageCount = 0) {
|
|
425
|
-
const
|
|
463
|
+
function buildToolResult(selected, imageCount = 0, compact = false) {
|
|
464
|
+
const parsed = operationResultSchema.parse(selected);
|
|
465
|
+
const structuredContent = compact ? withoutEmptyCollections(parsed) : parsed;
|
|
426
466
|
const shown = selected.artifacts
|
|
427
467
|
.map((artifact, order) => ({ artifact, order }))
|
|
428
468
|
.sort((left, right) => linkPriority(left.artifact.mimeType) - linkPriority(right.artifact.mimeType) ||
|
|
@@ -487,10 +527,10 @@ export function toolResult(result, options = {}) {
|
|
|
487
527
|
? Buffer.byteLength(canonicalJson(compact), 'utf8')
|
|
488
528
|
: MAX_TOOL_RESULT_BYTES + 1;
|
|
489
529
|
const selected = estimatedBytes > MAX_TOOL_RESULT_BYTES ? boundedResult(compact, estimatedBytes) : compact;
|
|
490
|
-
let output = buildToolResult(selected, images.length);
|
|
530
|
+
let output = buildToolResult(selected, images.length, options.compact);
|
|
491
531
|
const wireBytes = Buffer.byteLength(canonicalJson(output), 'utf8');
|
|
492
532
|
if (wireBytes > MAX_TOOL_RESULT_BYTES) {
|
|
493
|
-
output = buildToolResult(boundedResult(compact, wireBytes), images.length);
|
|
533
|
+
output = buildToolResult(boundedResult(compact, wireBytes), images.length, options.compact);
|
|
494
534
|
}
|
|
495
535
|
const finalBytes = Buffer.byteLength(canonicalJson(output), 'utf8');
|
|
496
536
|
if (finalBytes > MAX_TOOL_RESULT_BYTES) {
|
|
@@ -207,15 +207,23 @@ function workspaceAliases(workspace) {
|
|
|
207
207
|
`mod_${nameSlug}`,
|
|
208
208
|
]);
|
|
209
209
|
}
|
|
210
|
-
const WORKSPACE_CONTEXT_FIX = 'Pass workspaceId with
|
|
210
|
+
const WORKSPACE_CONTEXT_FIX = 'Pass workspaceId with a mod folder name from modFolders, start the client in the mod folder, or set defaultWorkspace in the server configuration';
|
|
211
211
|
const WORKSPACE_CANDIDATE_LIMIT = 32;
|
|
212
|
-
/**
|
|
212
|
+
/**
|
|
213
|
+
* The mods a caller could name, bounded and without host paths: their folder names, which
|
|
214
|
+
* `workspaceId` accepts, and one line that says what to pass.
|
|
215
|
+
*/
|
|
213
216
|
function workspaceCandidates(workspaces) {
|
|
214
|
-
const
|
|
217
|
+
const modFolders = workspaces
|
|
218
|
+
.slice(0, WORKSPACE_CANDIDATE_LIMIT)
|
|
219
|
+
.map(({ modRoot }) => path.basename(modRoot));
|
|
220
|
+
const example = modFolders[0];
|
|
215
221
|
return {
|
|
216
|
-
|
|
217
|
-
workspaceNames: listed.map(({ name }) => name),
|
|
222
|
+
modFolders,
|
|
218
223
|
workspaceCount: workspaces.length,
|
|
224
|
+
fix: example === undefined
|
|
225
|
+
? 'Add a mod folder to modRoots in the server configuration'
|
|
226
|
+
: `Pass "workspaceId":${JSON.stringify(example)} (or another folder in modFolders)`,
|
|
219
227
|
};
|
|
220
228
|
}
|
|
221
229
|
function requestedWorkspaceAlias(value) {
|
|
@@ -383,7 +391,7 @@ export class WorkspaceResolver {
|
|
|
383
391
|
resolveCurrentWorkspaceId(principal) {
|
|
384
392
|
const workspaces = this.list(principal).filter(({ registration }) => registration.kind === 'mod');
|
|
385
393
|
if (workspaces.length === 0) {
|
|
386
|
-
throw new ServiceError('WORKSPACE_CONTEXT_NOT_FOUND', 'No writable mod workspace is configured for the MCP server');
|
|
394
|
+
throw new ServiceError('WORKSPACE_CONTEXT_NOT_FOUND', 'No writable mod workspace is configured for the MCP server', workspaceCandidates(workspaces));
|
|
387
395
|
}
|
|
388
396
|
const currentDirectory = path.normalize(process.cwd());
|
|
389
397
|
const containing = workspaces.filter((workspace) => isWithin(workspace.modRoot, currentDirectory));
|
|
@@ -455,7 +463,14 @@ export class WorkspaceResolver {
|
|
|
455
463
|
if (this.#byId.has(workspaceId))
|
|
456
464
|
return workspaceId;
|
|
457
465
|
const alias = requestedWorkspaceAlias(workspaceId);
|
|
458
|
-
|
|
466
|
+
// A folder name as the file manager shows it ("My Mod") names the same mod as its slug.
|
|
467
|
+
const slug = workspaceAliasSlug(alias);
|
|
468
|
+
const matches = this.list(principal).filter((workspace) => {
|
|
469
|
+
if (workspace.registration.kind !== 'mod')
|
|
470
|
+
return false;
|
|
471
|
+
const aliases = workspaceAliases(workspace);
|
|
472
|
+
return aliases.has(alias) || (slug !== '' && aliases.has(slug));
|
|
473
|
+
});
|
|
459
474
|
if (matches.length === 1)
|
|
460
475
|
return matches[0].id;
|
|
461
476
|
if (matches.length > 1) {
|
|
@@ -226,7 +226,19 @@ export class DecisionAnalyzer {
|
|
|
226
226
|
result.code = complete ? 'DECISION_ANALYZED' : 'DECISION_ANALYZED_PARTIAL';
|
|
227
227
|
result.artifacts = [publicArtifactLink(artifact)];
|
|
228
228
|
result.proposedFiles = overlay?.changes.map(({ path }) => path).slice(0, 64) ?? [];
|
|
229
|
-
|
|
229
|
+
// A decision's own files answer an inspection; an inventory spans the workspace (#66).
|
|
230
|
+
setInlineFilesScanned(result, input.mode === 'inventory'
|
|
231
|
+
? before.files.map(({ displayPath }) => displayPath)
|
|
232
|
+
: [
|
|
233
|
+
...new Set(inventory.decisions
|
|
234
|
+
.filter(({ id }) => id === input.id)
|
|
235
|
+
.flatMap(({ path, category }) => [
|
|
236
|
+
path,
|
|
237
|
+
...inventory.categories
|
|
238
|
+
.filter((entry) => entry.id === category)
|
|
239
|
+
.map((entry) => entry.path),
|
|
240
|
+
])),
|
|
241
|
+
]);
|
|
230
242
|
result.validation = {
|
|
231
243
|
passed: complete,
|
|
232
244
|
checks: [
|
|
@@ -1206,15 +1206,29 @@ function stateLifecycleIssues(graph, stateLinks, budget) {
|
|
|
1206
1206
|
clearers.set(key, values);
|
|
1207
1207
|
}
|
|
1208
1208
|
}
|
|
1209
|
+
// has_event_target checks per owner: a read in the same owner that ends after the check starts
|
|
1210
|
+
// is guarded. That includes the read recorded for an enclosing `if` or `limit` block.
|
|
1211
|
+
const presenceChecks = new Map();
|
|
1212
|
+
for (const access of graph.stateAccesses) {
|
|
1213
|
+
if (access.metadata.presence !== true)
|
|
1214
|
+
continue;
|
|
1215
|
+
const key = `${access.ownerId}\u0000${stateKey(access)}`;
|
|
1216
|
+
presenceChecks.set(key, [...(presenceChecks.get(key) ?? []), access]);
|
|
1217
|
+
}
|
|
1218
|
+
const guarded = (access) => (presenceChecks.get(`${access.ownerId}\u0000${stateKey(access)}`) ?? []).some((check) => check.location.path === access.location.path &&
|
|
1219
|
+
check.location.start.offset < access.location.end.offset);
|
|
1209
1220
|
for (const access of graph.stateAccesses) {
|
|
1210
1221
|
if (access.access !== 'read' && access.access !== 'read_write')
|
|
1211
1222
|
continue;
|
|
1212
1223
|
if (compatibleProducerKeys(access).some((producerKey) => (producers.get(producerKey) ?? []).length > 0))
|
|
1213
1224
|
continue;
|
|
1214
1225
|
const owner = semanticOwnerId(access.ownerId, nodes, parent);
|
|
1215
|
-
if (access.kind === 'event_target' ||
|
|
1226
|
+
if ((access.kind === 'event_target' ||
|
|
1216
1227
|
access.kind === 'global_event_target' ||
|
|
1217
|
-
access.kind === 'saved_scope')
|
|
1228
|
+
access.kind === 'saved_scope') &&
|
|
1229
|
+
access.metadata.presence !== true) {
|
|
1230
|
+
if (guarded(access))
|
|
1231
|
+
continue;
|
|
1218
1232
|
addIssue(graph.issues, {
|
|
1219
1233
|
code: 'EVENT_TARGET_READ_BEFORE_SAVE',
|
|
1220
1234
|
classification: 'probable_defect',
|
|
@@ -152,6 +152,12 @@ function isScopeChain(value) {
|
|
|
152
152
|
function isLiteralCountryTag(value) {
|
|
153
153
|
return /^[A-Z][A-Z0-9]{2}$/u.test(value);
|
|
154
154
|
}
|
|
155
|
+
const FOCUS_BLOCKS = new Set(['focus', 'shared_focus', 'joint_focus']);
|
|
156
|
+
const FOCUS_REWARD_BLOCKS = [
|
|
157
|
+
'completion_reward',
|
|
158
|
+
'completion_reward_joint_originator',
|
|
159
|
+
'completion_reward_joint_member',
|
|
160
|
+
];
|
|
155
161
|
const EFFECT_WRAPPER_BLOCKS = new Set([
|
|
156
162
|
...CONTROL_BLOCKS,
|
|
157
163
|
'effect',
|
|
@@ -785,7 +791,9 @@ class FragmentAnalyzer {
|
|
|
785
791
|
}
|
|
786
792
|
analyzeFocuses() {
|
|
787
793
|
this.visitAssignments(this.document.root, (assignment, ancestors) => {
|
|
788
|
-
|
|
794
|
+
// Shared and joint focuses run their rewards like tree focuses (vanilla's Saadabad branch
|
|
795
|
+
// saves SSB_leader in a joint_focus).
|
|
796
|
+
if (!FOCUS_BLOCKS.has(assignment.key.value) || assignment.value.type !== 'block')
|
|
789
797
|
return;
|
|
790
798
|
const id = firstScalar(assignment.value, 'id')?.value;
|
|
791
799
|
if (id === undefined)
|
|
@@ -805,19 +813,22 @@ class FragmentAnalyzer {
|
|
|
805
813
|
});
|
|
806
814
|
});
|
|
807
815
|
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
816
|
+
// A joint focus rewards its originator and its members in blocks of their own.
|
|
817
|
+
for (const key of FOCUS_REWARD_BLOCKS) {
|
|
818
|
+
const rewardOccurrences = new Map();
|
|
819
|
+
childBlocks(assignment.value, key).forEach((block) => this.walk(block, {
|
|
820
|
+
ownerId,
|
|
821
|
+
sourceScope: 'country',
|
|
822
|
+
phase: 'entry',
|
|
823
|
+
conditions: [],
|
|
824
|
+
helperStack: [],
|
|
825
|
+
semanticPath: [
|
|
826
|
+
...ancestors,
|
|
827
|
+
id,
|
|
828
|
+
semanticOccurrenceSegment(key, semanticSourceEntry(block), rewardOccurrences),
|
|
829
|
+
],
|
|
830
|
+
}));
|
|
831
|
+
}
|
|
821
832
|
});
|
|
822
833
|
}
|
|
823
834
|
analyzeDecisions() {
|
|
@@ -1397,8 +1408,11 @@ class FragmentAnalyzer {
|
|
|
1397
1408
|
}
|
|
1398
1409
|
const rule = STATE_RULES[assignment.key.value];
|
|
1399
1410
|
if (rule === undefined) {
|
|
1400
|
-
|
|
1401
|
-
|
|
1411
|
+
// The whole value: valueText is cut for display and would cut a name at its end.
|
|
1412
|
+
const raw = this.document.text.slice(assignment.value.start, assignment.value.end);
|
|
1413
|
+
// A name that runs on into `[...]` or `$...$` is built at run time (meta_effect, scripted
|
|
1414
|
+
// parameters); its literal prefix is not the target's name.
|
|
1415
|
+
for (const match of raw.matchAll(/\b(event_target|global_event_target):([A-Za-z0-9_-]+)(?![A-Za-z0-9_[$-])/gu)) {
|
|
1402
1416
|
this.addState(context, match[1] === 'global_event_target' ? 'global_event_target' : 'event_target', match[2], 'read', assignment, semanticPath, false);
|
|
1403
1417
|
}
|
|
1404
1418
|
return;
|
|
@@ -1430,6 +1444,11 @@ class FragmentAnalyzer {
|
|
|
1430
1444
|
this.addState(context, kind, name, access, assignment, semanticPath, isDynamic(name), {
|
|
1431
1445
|
...(rule.storage === undefined ? {} : { storage: rule.storage }),
|
|
1432
1446
|
...(rule.temporary === true ? { temporary: true } : {}),
|
|
1447
|
+
// has_event_target tests whether the target exists; it never reads an unset one.
|
|
1448
|
+
...(assignment.key.value === 'has_event_target' ||
|
|
1449
|
+
assignment.key.value === 'has_global_event_target'
|
|
1450
|
+
? { presence: true }
|
|
1451
|
+
: {}),
|
|
1433
1452
|
});
|
|
1434
1453
|
}
|
|
1435
1454
|
addState(context, kind, name, access, node, _semanticPath, dynamic, metadata = {}) {
|
|
@@ -125,7 +125,10 @@ export class ImpactAnalyzer {
|
|
|
125
125
|
result.code = complete ? 'IMPACT_ANALYZED' : 'IMPACT_ANALYZED_PARTIAL';
|
|
126
126
|
result.artifacts = [publicArtifactLink(artifact)];
|
|
127
127
|
result.proposedFiles = overlay?.changes.map(({ path }) => path).slice(0, 64) ?? [];
|
|
128
|
-
|
|
128
|
+
// The seed files and the files of the consumers, not the first files of the workspace (#66).
|
|
129
|
+
setInlineFilesScanned(result, [
|
|
130
|
+
...new Set([...(query.changedFiles ?? []), ...suiteGraph.affectedFiles]),
|
|
131
|
+
]);
|
|
129
132
|
result.validation = {
|
|
130
133
|
passed: complete,
|
|
131
134
|
checks: [
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Overland reach of each realm through impassable land (ZR-28). Impassable states and impassable
|
|
3
|
+
* adjacency rows make a strategic board, but they can also cut a realm in two or box it in by
|
|
4
|
+
* accident. This compares two graphs of land provinces joined by shared borders and `sea`
|
|
5
|
+
* crossings: one with every province and border, and one without the impassable provinces and
|
|
6
|
+
* the blocked borders. Whatever the first joins and the second separates was cut by impassable
|
|
7
|
+
* land; islands, which neither graph joins, are never reported.
|
|
8
|
+
*/
|
|
9
|
+
function components(count, include, edges) {
|
|
10
|
+
const label = new Int32Array(count).fill(-1);
|
|
11
|
+
let next = 0;
|
|
12
|
+
for (let start = 0; start < count; start += 1) {
|
|
13
|
+
if (label[start] !== -1 || !include(start))
|
|
14
|
+
continue;
|
|
15
|
+
const queue = [start];
|
|
16
|
+
label[start] = next;
|
|
17
|
+
// The array iterator also visits provinces queued during the loop.
|
|
18
|
+
for (const id of queue)
|
|
19
|
+
for (const other of edges(id))
|
|
20
|
+
if (label[other] === -1 && include(other)) {
|
|
21
|
+
label[other] = next;
|
|
22
|
+
queue.push(other);
|
|
23
|
+
}
|
|
24
|
+
next += 1;
|
|
25
|
+
}
|
|
26
|
+
return label;
|
|
27
|
+
}
|
|
28
|
+
export function realmReachNotes(input) {
|
|
29
|
+
const count = input.kind.length;
|
|
30
|
+
const key = (a, b) => (a < b ? `${a}:${b}` : `${b}:${a}`);
|
|
31
|
+
const blocked = new Set(input.blocked.map(([a, b]) => key(a, b)));
|
|
32
|
+
const linked = [];
|
|
33
|
+
for (const [a, b] of input.crossings) {
|
|
34
|
+
(linked[a] ??= []).push(b);
|
|
35
|
+
(linked[b] ??= []).push(a);
|
|
36
|
+
}
|
|
37
|
+
const land = (id) => input.kind[id] === 1;
|
|
38
|
+
const everything = components(count, land, (id) => [
|
|
39
|
+
...input.neighbors[id],
|
|
40
|
+
...(linked[id] ?? []),
|
|
41
|
+
]);
|
|
42
|
+
const passable = components(count, (id) => land(id) && !input.impassable.has(id), (id) => [...input.neighbors[id], ...(linked[id] ?? [])].filter((other) => !blocked.has(key(id, other))));
|
|
43
|
+
const notes = [];
|
|
44
|
+
for (const [realm, capital] of input.capitals.entries()) {
|
|
45
|
+
const tag = input.tags[realm] ?? String(realm);
|
|
46
|
+
const home = passable[capital];
|
|
47
|
+
const cut = [];
|
|
48
|
+
for (const [id, owner] of input.owner)
|
|
49
|
+
if (owner === realm &&
|
|
50
|
+
!input.impassable.has(id) &&
|
|
51
|
+
passable[id] !== home &&
|
|
52
|
+
everything[id] === everything[capital])
|
|
53
|
+
cut.push(id);
|
|
54
|
+
if (cut.length > 0)
|
|
55
|
+
notes.push({
|
|
56
|
+
code: 'MAP_REALM_CUT_OFF',
|
|
57
|
+
severity: 'warning',
|
|
58
|
+
message: `${cut.length} land province(s) of ${tag} are cut off from its capital by impassable land or borders; open a pass or give them to a realm on their side`,
|
|
59
|
+
details: { tag, provinces: cut.length, sample: cut.slice(0, 10).map((id) => id + 1) },
|
|
60
|
+
});
|
|
61
|
+
// Boxed in: the land around the capital reaches another realm only through impassable land.
|
|
62
|
+
let foreignBefore = false;
|
|
63
|
+
let foreignAfter = false;
|
|
64
|
+
for (const [id, owner] of input.owner) {
|
|
65
|
+
if (owner === realm)
|
|
66
|
+
continue;
|
|
67
|
+
if (everything[id] === everything[capital])
|
|
68
|
+
foreignBefore = true;
|
|
69
|
+
if (passable[id] === home)
|
|
70
|
+
foreignAfter = true;
|
|
71
|
+
}
|
|
72
|
+
if (foreignBefore && !foreignAfter)
|
|
73
|
+
notes.push({
|
|
74
|
+
code: 'MAP_REALM_ENCLOSED',
|
|
75
|
+
severity: 'warning',
|
|
76
|
+
message: `${tag} reaches no other realm over land: impassable land or borders close every way out of the land around its capital`,
|
|
77
|
+
details: { tag, capitalProvince: capital + 1 },
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return notes;
|
|
81
|
+
}
|
|
@@ -540,6 +540,8 @@ export function resolveGeography(model, options) {
|
|
|
540
540
|
const shareSum = Object.values(terrain).reduce((sum, share) => sum + share, 0);
|
|
541
541
|
if (shareSum > 1.05)
|
|
542
542
|
sink('MAP_GEOGRAPHY_REGION_TERRAIN_SUM', 'warning', `The terrain shares of region ${input.id} add up to ${shareSum.toFixed(2)}, above 1`, { featureId: input.id, sum: shareSum });
|
|
543
|
+
if (input.impassable === true && area === undefined)
|
|
544
|
+
sink('MAP_GEOGRAPHY_IMPASSABLE_WITHOUT_AREA', 'error', `Region ${input.id} is impassable but has no polygons to say where`, { featureId: input.id });
|
|
543
545
|
const perState = input.density?.provincesPerState;
|
|
544
546
|
if (perState !== undefined && !(perState[0] <= perState[1] && perState[1] <= perState[2]))
|
|
545
547
|
sink('MAP_GEOGRAPHY_REGION_DENSITY_ORDER', 'error', `Region ${input.id} lists provincesPerState as [smallest, usual, largest] but they are not in order`, { featureId: input.id });
|
|
@@ -551,6 +553,7 @@ export function resolveGeography(model, options) {
|
|
|
551
553
|
...(Object.keys(terrain).length === 0 ? {} : { terrain }),
|
|
552
554
|
...(perState === undefined ? {} : { provincesPerState: perState }),
|
|
553
555
|
...opt('provinceAreaPx', input.density?.provinceAreaPx),
|
|
556
|
+
...(input.impassable === true && area !== undefined ? { impassable: true } : {}),
|
|
554
557
|
});
|
|
555
558
|
}
|
|
556
559
|
const lands = [];
|
|
@@ -16,6 +16,7 @@ import { planWorldOutputs } from './world-outputs.js';
|
|
|
16
16
|
import { resolvePartitionMode } from './partition.js';
|
|
17
17
|
import { applyAssignTerritory, applyRepartitionStates, } from './territory-operations.js';
|
|
18
18
|
import { unsupportedGeographyParts } from './relief/index.js';
|
|
19
|
+
import { resolvePaintedRelief } from './relief/painted-relief.js';
|
|
19
20
|
export function* cancellationCheckpoint(signal, iteration = 0, stride = 1) {
|
|
20
21
|
if (iteration % stride !== 0)
|
|
21
22
|
return;
|
|
@@ -3336,6 +3337,8 @@ function applyCreateWorld(base, changes, operation, context, signal) {
|
|
|
3336
3337
|
throw new ServiceError('MAP_LOOK_CUSTOM_PALETTE_REQUIRED', 'look "custom" needs colormap.palette with at least one class colour');
|
|
3337
3338
|
if (colormapProfile === 'legacy' && look !== undefined)
|
|
3338
3339
|
throw new ServiceError('MAP_LOOK_REQUIRES_CALIBRATED_COLORMAP', 'look selects a calibrated palette; remove colormap.profile "legacy" or look');
|
|
3340
|
+
if ((operation.relief?.painted ?? false) !== false && (!hasGeography || reference === undefined))
|
|
3341
|
+
throw new ServiceError('MAP_RELIEF_PAINTED_INPUTS', 'relief.painted raises the relief from the classes of a reference picture onto a geography model; give both reference and geography (or geographyPath)', { reference: reference !== undefined, geography: hasGeography });
|
|
3339
3342
|
if (!hasGeography && operation.development?.model === 'geography')
|
|
3340
3343
|
throw new ServiceError('MAP_DEVELOPMENT_REQUIRES_GEOGRAPHY', 'development.model "geography" plans the economy from a geography model; give geography or geographyPath, or use "legacy"');
|
|
3341
3344
|
if (!hasGeography && operation.autoStraits !== undefined && operation.autoStraits !== false)
|
|
@@ -3436,6 +3439,11 @@ function applyCreateWorld(base, changes, operation, context, signal) {
|
|
|
3436
3439
|
: { detail: operation.relief.detail }),
|
|
3437
3440
|
},
|
|
3438
3441
|
}),
|
|
3442
|
+
...(operation.relief?.painted === undefined || operation.relief.painted === false
|
|
3443
|
+
? {}
|
|
3444
|
+
: {
|
|
3445
|
+
paintedRelief: resolvePaintedRelief(operation.relief.painted),
|
|
3446
|
+
}),
|
|
3439
3447
|
...(typeof operation.rivers === 'object'
|
|
3440
3448
|
? { riverDensity: operation.rivers.density }
|
|
3441
3449
|
: typeof operation.rivers === 'number'
|
|
@@ -49,6 +49,7 @@ export function resolvePartitionTuning(tuning, base) {
|
|
|
49
49
|
const sea = tuning?.seaArea;
|
|
50
50
|
for (const [name, value] of Object.entries(sea ?? {}))
|
|
51
51
|
checkPixels(`seaArea.${name}`, value, minProvincePixels);
|
|
52
|
+
checkPixels('lakeArea', tuning?.lakeArea, minProvincePixels);
|
|
52
53
|
const coastal = clamp(sea?.coastal ?? base.seaProvincePixels * PARTITION_DEFAULTS.seaCoastal);
|
|
53
54
|
const open = clamp(sea?.open ?? base.seaProvincePixels * PARTITION_DEFAULTS.seaOpen);
|
|
54
55
|
if (coastal > open)
|
|
@@ -85,7 +86,7 @@ export function resolvePartitionTuning(tuning, base) {
|
|
|
85
86
|
return {
|
|
86
87
|
landArea: { fertile, plains: clamp(Math.sqrt(fertile * hills)), hills, mountain, waste },
|
|
87
88
|
seaArea: { coastal, open },
|
|
88
|
-
lakeArea: clamp(PARTITION_DEFAULTS.lake),
|
|
89
|
+
lakeArea: clamp(tuning?.lakeArea ?? PARTITION_DEFAULTS.lake),
|
|
89
90
|
states: group(perState, base.provincesPerState, 0.5, 1.6),
|
|
90
91
|
regions: group(regionSize, base.landProvincesPerRegion, 0.6, 1.5),
|
|
91
92
|
seaRegions: group(undefined, base.seaProvincesPerRegion, 0.5, 1.6),
|
|
@@ -18,12 +18,15 @@ export const REFERENCE_TERRAIN = {
|
|
|
18
18
|
};
|
|
19
19
|
const TERRAIN_ELEVATION = [0.045, 0.055, 0.035, 0.44, 0.045, 0.35, 0.18, 0.025, 0.06];
|
|
20
20
|
const TERRAIN_MOISTURE = [0.45, 0.8, 0.06, 0.35, 0.25, 0.05, 0.4, 0.96, 0.92];
|
|
21
|
+
/** Internal class code of `impassable_mountain`, after the terrain codes. */
|
|
22
|
+
const IMPASSABLE_CODE = 3 + Object.keys(REFERENCE_TERRAIN).length;
|
|
21
23
|
const pointSchema = z.object({ x: z.number().min(0).max(1), y: z.number().min(0).max(1) }).strict();
|
|
22
24
|
const polygonSchema = z.array(pointSchema).min(3).max(2048);
|
|
23
25
|
const semanticSchema = z.enum([
|
|
24
26
|
'sea',
|
|
25
27
|
'land',
|
|
26
28
|
'lake',
|
|
29
|
+
'impassable_mountain',
|
|
27
30
|
'plains',
|
|
28
31
|
'forest',
|
|
29
32
|
'desert',
|
|
@@ -135,7 +138,9 @@ function semanticCode(kind) {
|
|
|
135
138
|
? 2
|
|
136
139
|
: kind === 'land'
|
|
137
140
|
? 3
|
|
138
|
-
:
|
|
141
|
+
: kind === 'impassable_mountain'
|
|
142
|
+
? IMPASSABLE_CODE
|
|
143
|
+
: REFERENCE_TERRAIN[kind] + 3;
|
|
139
144
|
}
|
|
140
145
|
function pixelColor(data, pixel) {
|
|
141
146
|
return { r: data[pixel * 3], g: data[pixel * 3 + 1], b: data[pixel * 3 + 2] };
|
|
@@ -473,9 +478,17 @@ export async function extractReferenceWorld(imageBytes, input) {
|
|
|
473
478
|
}
|
|
474
479
|
const kind = new Uint8Array(codes.length);
|
|
475
480
|
const terrain = new Uint8Array(codes.length);
|
|
481
|
+
let impassable;
|
|
476
482
|
for (let pixel = 0; pixel < codes.length; pixel += 1) {
|
|
477
|
-
|
|
478
|
-
|
|
483
|
+
const code = codes[pixel];
|
|
484
|
+
kind[pixel] = code < 3 ? code : 1;
|
|
485
|
+
if (code === IMPASSABLE_CODE) {
|
|
486
|
+
terrain[pixel] = REFERENCE_TERRAIN.mountain;
|
|
487
|
+
impassable ??= new Uint8Array(codes.length);
|
|
488
|
+
impassable[pixel] = 1;
|
|
489
|
+
}
|
|
490
|
+
else
|
|
491
|
+
terrain[pixel] = code < 3 ? 0 : code - 3;
|
|
479
492
|
}
|
|
480
493
|
const riverPoints = (options.riverAnnotations ?? []).reduce((total, path) => total + path.length, 0);
|
|
481
494
|
if (riverPoints > 131072)
|
|
@@ -514,6 +527,7 @@ export async function extractReferenceWorld(imageBytes, input) {
|
|
|
514
527
|
rivers,
|
|
515
528
|
country: new Uint16Array(kind.length),
|
|
516
529
|
inferredCountries: [],
|
|
530
|
+
...(impassable === undefined ? {} : { impassable }),
|
|
517
531
|
diagnostics,
|
|
518
532
|
};
|
|
519
533
|
if (!exact)
|