hoi4-agent-tools 4.13.0 → 4.15.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 +10 -0
- package/dist/hoi4_agent_tools/map/operations.js +2 -1
- package/dist/hoi4_agent_tools/map/relief/painted-relief.js +2 -2
- package/dist/hoi4_agent_tools/map/relief/terrain-synthesis.js +25 -3
- package/dist/hoi4_agent_tools/map/tool-operations.js +5 -0
- package/dist/hoi4_agent_tools/map/world.js +229 -12
- package/dist/hoi4_agent_tools/reference/source-lookup.js +226 -74
- package/dist/hoi4_agent_tools/schemas/map.js +13 -0
- package/dist/hoi4_agent_tools/schemas/mod-tools.js +33 -0
- package/dist/hoi4_agent_tools/version.js +1 -1
- package/docs/map.md +2 -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 +174 -138
- 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
|
@@ -1,13 +1,225 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFile, realpath, stat } from 'node:fs/promises';
|
|
3
|
+
import { defaultPatterns } from '../core/engine.js';
|
|
4
|
+
import { runEngineCommand } from '../core/engine-client.js';
|
|
1
5
|
import { ServiceError } from '../core/result.js';
|
|
6
|
+
import { isWithin } from '../core/workspace.js';
|
|
2
7
|
import { decodeSource } from '../core/source/encoding.js';
|
|
8
|
+
import { sourceLookupEngineResponseSchema } from '../schemas/mod-tools.js';
|
|
9
|
+
import { modIndexEngineRequest, SOURCE_ROOT_KINDS } from './mod-index.js';
|
|
3
10
|
import { readBoundedJsonLines } from './lines.js';
|
|
4
11
|
import { IMPACT_SEMANTIC_MAX_REFERENCES, scanImpactSemanticReferences, } from '../core/impact-semantic.js';
|
|
5
12
|
import { parseClausewitz } from '../core/source/parser.js';
|
|
13
|
+
import { positionAt } from '../core/source/lexer.js';
|
|
6
14
|
import { navigateSource } from './source-navigation.js';
|
|
7
15
|
import { locatePatterns, locateSource } from './source-locate.js';
|
|
8
16
|
import { nearestNames } from './suggestions.js';
|
|
9
17
|
const semanticCache = new WeakMap();
|
|
10
|
-
/**
|
|
18
|
+
/** The lines, or the nested navigation, of one matched definition. */
|
|
19
|
+
function describeDefinition(entry, source, index, input, navigating) {
|
|
20
|
+
const start = entry.startLine;
|
|
21
|
+
const end = entry.endLine;
|
|
22
|
+
const navigation = navigating
|
|
23
|
+
? (() => {
|
|
24
|
+
if (source === undefined || /\.ya?ml$/iu.test(entry.path))
|
|
25
|
+
throw new ServiceError('SOURCE_STRUCTURE_UNAVAILABLE', 'Nested navigation requires an indexed Clausewitz definition');
|
|
26
|
+
const document = parseClausewitz(source.bytes, source.displayPath);
|
|
27
|
+
const range = entry.rangeIn(document);
|
|
28
|
+
if (range === undefined)
|
|
29
|
+
throw new ServiceError('SOURCE_STRUCTURE_UNAVAILABLE', 'Nested navigation requires an indexed Clausewitz definition');
|
|
30
|
+
return navigateSource(document, range, input.keyPath ?? [], {
|
|
31
|
+
structure: input.view === 'structure',
|
|
32
|
+
maxChildren: input.maxChildren,
|
|
33
|
+
childOffset: input.childOffset,
|
|
34
|
+
maxLines: input.maxLines,
|
|
35
|
+
...(index === 0 && input.fromLine !== undefined ? { fromLine: input.fromLine } : {}),
|
|
36
|
+
...(index === 0 && input.fromColumn !== undefined
|
|
37
|
+
? { fromColumn: input.fromColumn }
|
|
38
|
+
: {}),
|
|
39
|
+
});
|
|
40
|
+
})()
|
|
41
|
+
: undefined;
|
|
42
|
+
const fromLine = index === 0 ? (input.fromLine ?? start) : start;
|
|
43
|
+
if (fromLine !== undefined &&
|
|
44
|
+
start !== undefined &&
|
|
45
|
+
end !== undefined &&
|
|
46
|
+
(fromLine < start || fromLine > end)) {
|
|
47
|
+
throw new ServiceError('SOURCE_LINE_OUTSIDE_DEFINITION', 'Requested line is outside a matched definition');
|
|
48
|
+
}
|
|
49
|
+
const lines = source === undefined || fromLine === undefined
|
|
50
|
+
? []
|
|
51
|
+
: decodeSource(source.bytes)
|
|
52
|
+
.text.split(/\r?\n/u)
|
|
53
|
+
.slice((start ?? fromLine) - 1, end);
|
|
54
|
+
const selected = fromLine === undefined || lines.length === 0
|
|
55
|
+
? null
|
|
56
|
+
: readBoundedJsonLines(lines, start ?? fromLine, fromLine, index === 0 ? (input.fromColumn ?? 1) : 1, input.maxLines, 2_000, 4_096);
|
|
57
|
+
return {
|
|
58
|
+
kind: entry.kind,
|
|
59
|
+
id: entry.id,
|
|
60
|
+
path: entry.path,
|
|
61
|
+
rootKind: entry.rootKind,
|
|
62
|
+
loadOrder: entry.loadOrder,
|
|
63
|
+
overridden: entry.overridden,
|
|
64
|
+
sourceShadowed: entry.sourceShadowed,
|
|
65
|
+
startLine: start ?? null,
|
|
66
|
+
endLine: end ?? null,
|
|
67
|
+
fromLine: navigation?.fromLine ?? fromLine ?? null,
|
|
68
|
+
toLine: navigation?.endLine ?? selected?.endLine ?? null,
|
|
69
|
+
nextLine: navigation === undefined ? (selected?.nextLine ?? null) : navigation.nextLine,
|
|
70
|
+
nextColumn: navigation === undefined ? (selected?.nextColumn ?? null) : navigation.nextColumn,
|
|
71
|
+
text: navigation?.text ?? selected?.text ?? '',
|
|
72
|
+
...(navigation === undefined ? {} : { navigation: navigation.navigation }),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** The reply stays within 24,000 bytes: references go first, then definitions after the first. */
|
|
76
|
+
function boundResult(result) {
|
|
77
|
+
while (Buffer.byteLength(JSON.stringify(result), 'utf8') > 24_000 &&
|
|
78
|
+
result.references.length > 0) {
|
|
79
|
+
result.references.pop();
|
|
80
|
+
result.referencesTruncated = true;
|
|
81
|
+
result.referencesComplete = false;
|
|
82
|
+
}
|
|
83
|
+
while (Buffer.byteLength(JSON.stringify(result), 'utf8') > 24_000 &&
|
|
84
|
+
result.definitions.length > 1) {
|
|
85
|
+
result.definitions.pop();
|
|
86
|
+
result.definitionsTruncated = true;
|
|
87
|
+
}
|
|
88
|
+
if (Buffer.byteLength(JSON.stringify(result), 'utf8') > 24_000)
|
|
89
|
+
throw new ServiceError('REFERENCE_RESPONSE_TOO_LARGE', 'Selected source metadata exceeds the bounded reply; use entry-index selectors for long nested keys');
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
/** `nearestNames` over the engine's candidates: nearest first, ties in the English locale order. */
|
|
93
|
+
function nearestOf(candidates) {
|
|
94
|
+
return [...candidates]
|
|
95
|
+
.sort((a, b) => a.distance - b.distance || a.id.localeCompare(b.id, 'en'))
|
|
96
|
+
.slice(0, 5)
|
|
97
|
+
.map(({ id }) => id);
|
|
98
|
+
}
|
|
99
|
+
function notFound(symbol, kind, suggestions) {
|
|
100
|
+
return new ServiceError('SYMBOL_NOT_FOUND', `No indexed file defines ${symbol.slice(0, 256)}${kind === undefined ? '' : ` as a ${kind}`}${suggestions.length === 0 ? '' : `; did you mean ${suggestions.join(', ')}?`}`, { symbol: symbol.slice(0, 256), suggestions });
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The first line of a definition's assignment in a parsed file. The engine names a definition by
|
|
104
|
+
* its first and last line; the nested navigation needs its offsets.
|
|
105
|
+
*/
|
|
106
|
+
function rangeByLines(document, startLine, endLine) {
|
|
107
|
+
if (startLine === undefined)
|
|
108
|
+
return undefined;
|
|
109
|
+
let fallback;
|
|
110
|
+
const visit = (block) => {
|
|
111
|
+
for (const entry of block.entries) {
|
|
112
|
+
if (entry.type !== 'assignment')
|
|
113
|
+
continue;
|
|
114
|
+
if (positionAt(document.lineIndex, entry.start).line === startLine) {
|
|
115
|
+
const last = positionAt(document.lineIndex, Math.max(entry.start, entry.end - 1)).line;
|
|
116
|
+
if (endLine === undefined || last === endLine)
|
|
117
|
+
return { start: entry.start, end: entry.end };
|
|
118
|
+
fallback ??= { start: entry.start, end: entry.end };
|
|
119
|
+
}
|
|
120
|
+
if (entry.value.type === 'block') {
|
|
121
|
+
const found = visit(entry.value);
|
|
122
|
+
if (found !== undefined)
|
|
123
|
+
return found;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
};
|
|
128
|
+
return visit(document.root) ?? fallback;
|
|
129
|
+
}
|
|
130
|
+
/** Read one file the engine named, only from a configured root and only as it was scanned. */
|
|
131
|
+
async function readScannedFile(engine, workspaceId, absolutePath, sha256, principal) {
|
|
132
|
+
const maxBytes = engine.resolver.config().scanMaxFileBytes;
|
|
133
|
+
const workspace = engine.resolver.get(workspaceId, principal);
|
|
134
|
+
const real = await realpath(absolutePath);
|
|
135
|
+
const roots = await Promise.all(workspace.roots.map(({ path: root }) => realpath(root)));
|
|
136
|
+
if (!roots.some((root) => isWithin(root, real)))
|
|
137
|
+
throw new ServiceError('SOURCE_FILE_NOT_INDEXED', 'The source file is outside the workspace');
|
|
138
|
+
if ((await stat(real)).size > maxBytes)
|
|
139
|
+
throw new ServiceError('SCAN_BYTE_LIMIT', 'Scan exceeds the configured byte limit');
|
|
140
|
+
const bytes = await readFile(real);
|
|
141
|
+
if (createHash('sha256').update(bytes).digest('hex') !== sha256)
|
|
142
|
+
throw new ServiceError('SOURCE_REVISION_STALE', 'Indexed source changed; look up the symbol again');
|
|
143
|
+
return bytes;
|
|
144
|
+
}
|
|
145
|
+
/** `sourceScope` of the reply. */
|
|
146
|
+
function scopeOf(input, patterns) {
|
|
147
|
+
return input.kind === 'event'
|
|
148
|
+
? input.includeReferences
|
|
149
|
+
? 'event_consumers'
|
|
150
|
+
: 'event_definitions'
|
|
151
|
+
: patterns === undefined
|
|
152
|
+
? 'workspace_index'
|
|
153
|
+
: 'helper_definitions';
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* A lookup that asks for no references: the shared Rust engine (ADR 0082) finds the definitions,
|
|
157
|
+
* the scan revision and the near-miss names, and this side reads only the chosen files for their
|
|
158
|
+
* lines and nested navigation. A missing engine is `ENGINE_UNAVAILABLE`.
|
|
159
|
+
*/
|
|
160
|
+
async function lookupFromEngine(engine, workspaceId, input, symbol, patterns, principal, signal) {
|
|
161
|
+
signal?.throwIfAborted();
|
|
162
|
+
await engine.resolver.refreshDescriptors(workspaceId, principal);
|
|
163
|
+
const workspace = engine.resolver.get(workspaceId, principal);
|
|
164
|
+
const navigating = input.keyPath !== undefined || input.view === 'structure';
|
|
165
|
+
const answered = await runEngineCommand('source-lookup', {
|
|
166
|
+
...modIndexEngineRequest(workspace, engine.resolver.config(), SOURCE_ROOT_KINDS),
|
|
167
|
+
schema: SOURCE_LOOKUP_REQUEST_SCHEMA,
|
|
168
|
+
patterns: patterns ?? defaultPatterns(workspace),
|
|
169
|
+
symbol,
|
|
170
|
+
...(input.kind === undefined ? {} : { kind: input.kind }),
|
|
171
|
+
maxDefinitions: navigating ? 1 : input.maxDefinitions,
|
|
172
|
+
}, sourceLookupEngineResponseSchema, { timeoutMs: SOURCE_LOOKUP_TIMEOUT_MS, ...(signal === undefined ? {} : { signal }) });
|
|
173
|
+
if (!answered.available)
|
|
174
|
+
throw new ServiceError('ENGINE_UNAVAILABLE', answered.message, { reason: answered.reason });
|
|
175
|
+
if (answered.outcome === 'invalid_request')
|
|
176
|
+
throw new ServiceError(answered.error.code, answered.error.message);
|
|
177
|
+
const response = answered.response;
|
|
178
|
+
if (input.expectedRevision !== undefined && input.expectedRevision !== response.revision) {
|
|
179
|
+
throw new ServiceError('SOURCE_REVISION_STALE', 'Indexed source changed; look up the symbol again', { currentRevision: response.revision });
|
|
180
|
+
}
|
|
181
|
+
if (navigating && response.kindCount > 1)
|
|
182
|
+
throw new ServiceError('SOURCE_KIND_AMBIGUOUS', 'Nested navigation requires kind when the identifier has multiple symbol kinds');
|
|
183
|
+
const suggestions = nearestOf(response.suggestionCandidates);
|
|
184
|
+
// A complete index that does not define the symbol answers not-found, never an empty success.
|
|
185
|
+
if (response.definitionCount === 0 && response.complete)
|
|
186
|
+
throw notFound(symbol, input.kind, suggestions);
|
|
187
|
+
const definitions = await Promise.all(response.definitions.map(async (entry, index) => {
|
|
188
|
+
const bytes = await readScannedFile(engine, workspaceId, entry.absolutePath, entry.sha256, principal);
|
|
189
|
+
return describeDefinition({
|
|
190
|
+
kind: entry.kind,
|
|
191
|
+
id: entry.id,
|
|
192
|
+
path: entry.path,
|
|
193
|
+
rootKind: entry.rootKind,
|
|
194
|
+
loadOrder: entry.loadOrder,
|
|
195
|
+
overridden: entry.overridden,
|
|
196
|
+
sourceShadowed: entry.sourceShadowed,
|
|
197
|
+
startLine: entry.startLine === 0 ? undefined : entry.startLine,
|
|
198
|
+
endLine: entry.endLine === 0 ? undefined : entry.endLine,
|
|
199
|
+
rangeIn: (document) => rangeByLines(document, entry.startLine, entry.endLine),
|
|
200
|
+
}, { bytes, displayPath: entry.path }, index, input, navigating);
|
|
201
|
+
}));
|
|
202
|
+
return boundResult({
|
|
203
|
+
sourceScope: scopeOf(input, patterns),
|
|
204
|
+
revision: response.revision,
|
|
205
|
+
complete: response.complete,
|
|
206
|
+
skippedSourceCount: response.skippedSourceCount,
|
|
207
|
+
definitionCount: response.definitionCount,
|
|
208
|
+
definitionsTruncated: response.definitionCount > definitions.length,
|
|
209
|
+
...(response.definitionCount === 0 ? { suggestions } : {}),
|
|
210
|
+
definitions,
|
|
211
|
+
references: [],
|
|
212
|
+
referencesIncluded: false,
|
|
213
|
+
referenceCount: 0,
|
|
214
|
+
referencesTruncated: false,
|
|
215
|
+
referencesComplete: false,
|
|
216
|
+
unresolvedReferenceCount: 0,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/** A cold index of the game, its DLC and a large mod. */
|
|
220
|
+
const SOURCE_LOOKUP_TIMEOUT_MS = 180_000;
|
|
221
|
+
const SOURCE_LOOKUP_REQUEST_SCHEMA = 'hoi4-source-lookup-request/1';
|
|
222
|
+
/** Exact source definitions and usage over the shared Clausewitz index. */
|
|
11
223
|
export async function sourceLookup(engine, workspaceId, input, principal, signal) {
|
|
12
224
|
const narrowPatterns = {
|
|
13
225
|
event: ['events/**/*.txt'],
|
|
@@ -32,6 +244,9 @@ export async function sourceLookup(engine, workspaceId, input, principal, signal
|
|
|
32
244
|
: input.includeReferences || input.kind === undefined
|
|
33
245
|
? undefined
|
|
34
246
|
: narrowPatterns[input.kind];
|
|
247
|
+
const locating = input.path !== undefined && input.line !== undefined;
|
|
248
|
+
if (!locating && input.symbol !== undefined && !input.includeReferences)
|
|
249
|
+
return lookupFromEngine(engine, workspaceId, input, input.symbol, patterns, principal, signal);
|
|
35
250
|
const snapshot = await engine.scan(workspaceId, patterns === undefined ? {} : { patterns }, principal, signal);
|
|
36
251
|
if (input.path !== undefined && input.line !== undefined)
|
|
37
252
|
return {
|
|
@@ -66,47 +281,7 @@ export async function sourceLookup(engine, workspaceId, input, principal, signal
|
|
|
66
281
|
.slice(0, navigating ? 1 : input.maxDefinitions)
|
|
67
282
|
.map((entry, index) => {
|
|
68
283
|
const source = snapshot.index.files.get(entry.path);
|
|
69
|
-
|
|
70
|
-
const end = entry.location?.end.line;
|
|
71
|
-
const navigation = navigating
|
|
72
|
-
? (() => {
|
|
73
|
-
if (source === undefined ||
|
|
74
|
-
entry.location === undefined ||
|
|
75
|
-
/\.ya?ml$/iu.test(entry.path))
|
|
76
|
-
throw new ServiceError('SOURCE_STRUCTURE_UNAVAILABLE', 'Nested navigation requires an indexed Clausewitz definition');
|
|
77
|
-
return navigateSource(parseClausewitz(source.bytes, source.displayPath), {
|
|
78
|
-
start: entry.location.start.offset,
|
|
79
|
-
end: entry.location.end.offset,
|
|
80
|
-
}, input.keyPath ?? [], {
|
|
81
|
-
structure: input.view === 'structure',
|
|
82
|
-
maxChildren: input.maxChildren,
|
|
83
|
-
childOffset: input.childOffset,
|
|
84
|
-
maxLines: input.maxLines,
|
|
85
|
-
...(index === 0 && input.fromLine !== undefined
|
|
86
|
-
? { fromLine: input.fromLine }
|
|
87
|
-
: {}),
|
|
88
|
-
...(index === 0 && input.fromColumn !== undefined
|
|
89
|
-
? { fromColumn: input.fromColumn }
|
|
90
|
-
: {}),
|
|
91
|
-
});
|
|
92
|
-
})()
|
|
93
|
-
: undefined;
|
|
94
|
-
const fromLine = index === 0 ? (input.fromLine ?? start) : start;
|
|
95
|
-
if (fromLine !== undefined &&
|
|
96
|
-
start !== undefined &&
|
|
97
|
-
end !== undefined &&
|
|
98
|
-
(fromLine < start || fromLine > end)) {
|
|
99
|
-
throw new ServiceError('SOURCE_LINE_OUTSIDE_DEFINITION', 'Requested line is outside a matched definition');
|
|
100
|
-
}
|
|
101
|
-
const lines = source === undefined || fromLine === undefined
|
|
102
|
-
? []
|
|
103
|
-
: decodeSource(source.bytes)
|
|
104
|
-
.text.split(/\r?\n/u)
|
|
105
|
-
.slice((start ?? fromLine) - 1, end);
|
|
106
|
-
const selected = fromLine === undefined || lines.length === 0
|
|
107
|
-
? null
|
|
108
|
-
: readBoundedJsonLines(lines, start ?? fromLine, fromLine, index === 0 ? (input.fromColumn ?? 1) : 1, input.maxLines, 2_000, 4_096);
|
|
109
|
-
return {
|
|
284
|
+
return describeDefinition({
|
|
110
285
|
kind: entry.kind,
|
|
111
286
|
id: entry.id,
|
|
112
287
|
path: entry.path,
|
|
@@ -114,15 +289,12 @@ export async function sourceLookup(engine, workspaceId, input, principal, signal
|
|
|
114
289
|
loadOrder: entry.loadOrder,
|
|
115
290
|
overridden: entry.overridden,
|
|
116
291
|
sourceShadowed: entry.sourceShadowed,
|
|
117
|
-
startLine: start
|
|
118
|
-
endLine: end
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
text: navigation?.text ?? selected?.text ?? '',
|
|
124
|
-
...(navigation === undefined ? {} : { navigation: navigation.navigation }),
|
|
125
|
-
};
|
|
292
|
+
startLine: entry.location?.start.line,
|
|
293
|
+
endLine: entry.location?.end.line,
|
|
294
|
+
rangeIn: () => entry.location === undefined
|
|
295
|
+
? undefined
|
|
296
|
+
: { start: entry.location.start.offset, end: entry.location.end.offset },
|
|
297
|
+
}, source === undefined ? undefined : { bytes: source.bytes, displayPath: source.displayPath }, index, input, navigating);
|
|
126
298
|
});
|
|
127
299
|
let semantic = input.includeReferences ? semanticCache.get(snapshot) : undefined;
|
|
128
300
|
if (input.includeReferences && semantic === undefined) {
|
|
@@ -158,14 +330,8 @@ export async function sourceLookup(engine, workspaceId, input, principal, signal
|
|
|
158
330
|
.map(({ id }) => id)));
|
|
159
331
|
throw new ServiceError('SYMBOL_NOT_FOUND', `No indexed file defines${input.includeReferences ? ' or uses' : ''} ${symbol.slice(0, 256)}${input.kind === undefined ? '' : ` as a ${input.kind}`}${suggestions.length === 0 ? '' : `; did you mean ${suggestions.join(', ')}?`}`, { symbol: symbol.slice(0, 256), suggestions });
|
|
160
332
|
}
|
|
161
|
-
|
|
162
|
-
sourceScope: input
|
|
163
|
-
? input.includeReferences
|
|
164
|
-
? 'event_consumers'
|
|
165
|
-
: 'event_definitions'
|
|
166
|
-
: patterns === undefined
|
|
167
|
-
? 'workspace_index'
|
|
168
|
-
: 'helper_definitions',
|
|
333
|
+
return boundResult({
|
|
334
|
+
sourceScope: scopeOf(input, patterns),
|
|
169
335
|
revision: snapshot.revision,
|
|
170
336
|
complete: snapshot.complete,
|
|
171
337
|
skippedSourceCount: snapshot.skippedSourceCount,
|
|
@@ -189,19 +355,5 @@ export async function sourceLookup(engine, workspaceId, input, principal, signal
|
|
|
189
355
|
semantic.unresolved.length === 0 &&
|
|
190
356
|
matchedReferences.length <= references.length,
|
|
191
357
|
unresolvedReferenceCount: semantic?.unresolved.length ?? 0,
|
|
192
|
-
};
|
|
193
|
-
while (Buffer.byteLength(JSON.stringify(result), 'utf8') > 24_000 &&
|
|
194
|
-
result.references.length > 0) {
|
|
195
|
-
result.references.pop();
|
|
196
|
-
result.referencesTruncated = true;
|
|
197
|
-
result.referencesComplete = false;
|
|
198
|
-
}
|
|
199
|
-
while (Buffer.byteLength(JSON.stringify(result), 'utf8') > 24_000 &&
|
|
200
|
-
result.definitions.length > 1) {
|
|
201
|
-
result.definitions.pop();
|
|
202
|
-
result.definitionsTruncated = true;
|
|
203
|
-
}
|
|
204
|
-
if (Buffer.byteLength(JSON.stringify(result), 'utf8') > 24_000)
|
|
205
|
-
throw new ServiceError('REFERENCE_RESPONSE_TOO_LARGE', 'Selected source metadata exceeds the bounded reply; use entry-index selectors for long nested keys');
|
|
206
|
-
return result;
|
|
358
|
+
});
|
|
207
359
|
}
|
|
@@ -1072,6 +1072,19 @@ export const mapOperationSchema = z.discriminatedUnion('kind', [
|
|
|
1072
1072
|
.enum(['keep', 'drop'])
|
|
1073
1073
|
.optional()
|
|
1074
1074
|
.describe('keep (the default) also lists the continents of the active continent.txt after the generated ones; drop writes only the generated continents and warns about every active script that still names a dropped one (MAP_CONTINENT_DROPPED_REFERENCED).'),
|
|
1075
|
+
permanentSnow: z
|
|
1076
|
+
.union([
|
|
1077
|
+
z.literal('snowlines'),
|
|
1078
|
+
z
|
|
1079
|
+
.object({
|
|
1080
|
+
iceCapLatitude: z.number().min(0).max(1).optional(),
|
|
1081
|
+
peakHeight: z.number().int().min(96).max(256).optional(),
|
|
1082
|
+
paintedHeight: z.number().int().min(96).max(256).optional(),
|
|
1083
|
+
})
|
|
1084
|
+
.strict(),
|
|
1085
|
+
])
|
|
1086
|
+
.optional()
|
|
1087
|
+
.describe('Where land drawn as snow in the reference keeps permanent snow; other drawn snow is ordinary land with seasonal snow. iceCapLatitude (default 0.8; 0 is the middle row, 1 the top and bottom edge, 1 turns ice caps off) and peakHeight (heightmap value, default 150; 256 turns it off). paintedHeight (heightmap value, no default) is the lowest the snow line of painted mountains, volcanoes and impassable land may go; without it that line runs from 232 at the equator to 140 at the poles, and 256 puts none. snowlines keeps permanent snow only above the snow lines of ranges and painted mountains. MAP_PERMANENT_SNOW_SHARE reports the result against the base game, by source; a synthesisCheck preview estimates it as MAP_PERMANENT_SNOW_ESTIMATE.'),
|
|
1075
1088
|
startDate: z
|
|
1076
1089
|
.string()
|
|
1077
1090
|
.regex(/^\d{3,4}\.\d{1,2}\.\d{1,2}$/u)
|
|
@@ -190,6 +190,39 @@ export const modIndexDataSchema = z
|
|
|
190
190
|
.optional(),
|
|
191
191
|
})
|
|
192
192
|
.strict();
|
|
193
|
+
/** `hoi4-engine source-lookup` (`hoi4-source-lookup/1`): what the shared Rust engine answers. */
|
|
194
|
+
export const sourceLookupEngineResponseSchema = z
|
|
195
|
+
.object({
|
|
196
|
+
schema: z.literal('hoi4-source-lookup/1'),
|
|
197
|
+
status: z.literal('ok'),
|
|
198
|
+
/** The scan revision, the same value `CoreEngine.scan` computes. */
|
|
199
|
+
revision: z.string().regex(/^[0-9a-f]{64}$/u),
|
|
200
|
+
complete: z.boolean(),
|
|
201
|
+
skippedSourceCount: z.number().int().min(0),
|
|
202
|
+
definitionCount: z.number().int().min(0),
|
|
203
|
+
kindCount: z.number().int().min(0),
|
|
204
|
+
definitions: z
|
|
205
|
+
.array(z
|
|
206
|
+
.object({
|
|
207
|
+
kind: z.string(),
|
|
208
|
+
id: z.string(),
|
|
209
|
+
path: z.string(),
|
|
210
|
+
rootKind: z.string(),
|
|
211
|
+
loadOrder: z.number().int(),
|
|
212
|
+
overridden: z.boolean(),
|
|
213
|
+
sourceShadowed: z.boolean(),
|
|
214
|
+
startLine: z.number().int().min(0),
|
|
215
|
+
endLine: z.number().int().min(0),
|
|
216
|
+
absolutePath: z.string().min(1),
|
|
217
|
+
sha256: z.string().regex(/^[0-9a-f]{64}$/u),
|
|
218
|
+
})
|
|
219
|
+
.strict())
|
|
220
|
+
.max(50),
|
|
221
|
+
suggestionCandidates: z
|
|
222
|
+
.array(z.object({ id: z.string(), distance: z.number().int().min(0).max(3) }).strict())
|
|
223
|
+
.max(2_000),
|
|
224
|
+
})
|
|
225
|
+
.strict();
|
|
193
226
|
/** `hoi4-engine mod-index` (`hoi4-mod-index/1`): what the shared Rust engine answers. */
|
|
194
227
|
export const modIndexEngineResponseSchema = z
|
|
195
228
|
.object({
|
|
@@ -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.15.0';
|
|
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
|
@@ -44,6 +44,8 @@ Optional `reference` controls refine the same call:
|
|
|
44
44
|
| `cities` | `{name,x,y,countryTag?}` reviewed city and optional capital anchors. `countryTag` must name a generated country. |
|
|
45
45
|
| `labels` | `{name,x,y,kind}` reviewed names for `state`, `country`, `city`, `sea`, `region`, `mountain` or `geography`; useful for handwritten or ambiguous labels. |
|
|
46
46
|
|
|
47
|
+
Land drawn as `snow` is plains in play and ordinary land in `terrain.bmp`, with seasonal snow, as the base game's northern lands are: a strategic region drawn mostly as snow takes the weather of at least latitude 0.7 (0 at the equator, 1 at the map's top and bottom), so its winters bring snow. Permanent snow, which the game draws as bright ice, is kept to drawn snow in the tenth of rows nearest each pole (ice caps, index 19), drawn snow at height 150 or more (index 16), and the snow lines of ranges and painted mountains (index 16). The operation's `permanentSnow` moves the two thresholds, `{ "iceCapLatitude": 0.97, "peakHeight": 200 }` for a world whose inhabited north reaches the top rows (1 turns ice caps off, 256 high ground), or `"snowlines"` keeps permanent snow only above the snow lines. With `relief.painted`, drawn high ground stands well above the base game's, so a `peakHeight` of 150 to 200 can take whole painted ranges: start near 230 and read the share note. Painted mountains, volcanoes and impassable land also keep permanent snow above a snow line of their own, from 232 at the equator to 140 at the poles; `permanentSnow.paintedHeight` keeps that line at or above its height, and 256 removes it. On a 5,120 by 2,560 world with 29% of its land drawn as snow, `0.97` and `230` left 0.9% permanent snow, and the defaults 9.5%. `MAP_PERMANENT_SNOW_SHARE` reports the permanent-snow share of the land against the base game's 0.76%, with the `rim` and `wall` seam ranges counted apart, the thresholds used, and `bySource`, which counts the pixels above range snow lines, above painted snow lines and on drawn snow apart; it is a warning above four times that share. A `synthesisCheck` preview estimates the same share without a write, as `MAP_PERMANENT_SNOW_ESTIMATE` and `synthesisCheck.permanentSnow`: it applies the same rule to the half-resolution relief the check builds, so try thresholds there and read the exact share at the write. On the test world the estimate was within 1% of the written share; the full-resolution detail of the heights makes the difference.
|
|
48
|
+
|
|
47
49
|
Reviewed geography labels preserve names for lakes, rivers, forests and other features in localisation and generated-world provenance. They do not invent a native HOI4 map entity or turn a geographic label into a city or victory point.
|
|
48
50
|
|
|
49
51
|
All annotation positions and polygons use normalized 0 to 1 coordinates relative to the original, uncropped reference, with the origin at its top left. Crop uses source pixels instead. Explicit `countries` on the operation supplies reviewed country tags, names, colors and relative shares. If borders or names cannot be inferred reliably, the server generates named defaults and reports the assumptions. Manual controls are optional and never change the original image.
|
|
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": "0e9337f9fc3db3d24f1b2a1ceceefeb1e971ae26be7aae5307bf4aa1c16c87b2",
|
|
8
|
+
"size": 4626736
|
|
9
9
|
},
|
|
10
10
|
"linux-arm64": {
|
|
11
11
|
"file": "linux-arm64/hoi4-engine",
|
|
12
|
-
"sha256": "
|
|
13
|
-
"size":
|
|
12
|
+
"sha256": "1bafcd4c8f966fa4bdfe6c879ddd58aaca010e30762f8a0bbcc76cd13fa644b7",
|
|
13
|
+
"size": 4948256
|
|
14
14
|
},
|
|
15
15
|
"linux-x64": {
|
|
16
16
|
"file": "linux-x64/hoi4-engine",
|
|
17
|
-
"sha256": "
|
|
18
|
-
"size":
|
|
17
|
+
"sha256": "f8cad660e7d2940f03f045693f91c6bf75c729062a0414bb8c94346a07ce37b5",
|
|
18
|
+
"size": 5357024
|
|
19
19
|
},
|
|
20
20
|
"win32-x64": {
|
|
21
21
|
"file": "win32-x64/hoi4-engine.exe",
|
|
22
|
-
"sha256": "
|
|
23
|
-
"size":
|
|
22
|
+
"sha256": "f476db7b7916da8768d1354dd1cd419ebfd25c6d87832a55a1221c426525e154",
|
|
23
|
+
"size": 4474880
|
|
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.15.0",
|
|
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.15.0",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@fontsource-variable/roboto": "5.3.0",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hoi4-agent-tools",
|
|
3
3
|
"mcpName": "io.github.klimPaskov/hoi4-agent-tools",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.15.0",
|
|
5
5
|
"description": "Build HOI4 mods: focus trees, events, decisions, worlds, GUI previews, docs and AI balance.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/configuration.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/continuous-focus-palette.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/custom-weighted-pool.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/decision-inspect-input.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/error-log-input.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/event-feature-manifest.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/focus-plan.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/focus-planning-sidecar.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/geography-model.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/gui-animation-source.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/gui-helper.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/gui-scenario.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/helper-expansion-request.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/helper-expansion-summary.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.
|
|
2
|
+
"$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.15.0/schemas/impact-inspect-input.schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|