hoi4-agent-tools 4.6.5 → 4.7.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 +16 -5
- package/dist/hoi4_agent_tools/core/engine-client.js +273 -0
- package/dist/hoi4_agent_tools/core/operation-result.js +24 -5
- package/dist/hoi4_agent_tools/focus/compact.js +197 -18
- package/dist/hoi4_agent_tools/focus/engine-layout.js +201 -0
- package/dist/hoi4_agent_tools/focus/job-operations.js +3 -1
- package/dist/hoi4_agent_tools/focus/layout.js +3 -2
- package/dist/hoi4_agent_tools/focus/quality/branches.js +32 -0
- package/dist/hoi4_agent_tools/focus/quality/calibration.js +364 -0
- package/dist/hoi4_agent_tools/focus/quality/delta.js +85 -0
- package/dist/hoi4_agent_tools/focus/quality/focus-quality-calibration.json +2265 -0
- package/dist/hoi4_agent_tools/focus/quality/graph.js +170 -0
- package/dist/hoi4_agent_tools/focus/quality/index.js +24 -0
- package/dist/hoi4_agent_tools/focus/quality/inline-images.js +132 -0
- package/dist/hoi4_agent_tools/focus/quality/metrics.js +424 -0
- package/dist/hoi4_agent_tools/focus/quality/orthogonal.js +202 -0
- package/dist/hoi4_agent_tools/focus/quality/positions.js +41 -0
- package/dist/hoi4_agent_tools/focus/quality/schematic.js +241 -0
- package/dist/hoi4_agent_tools/focus/quality/scorecard.js +549 -0
- package/dist/hoi4_agent_tools/focus/quality/stored-calibration.js +7 -0
- package/dist/hoi4_agent_tools/focus/quality/tool-output.js +113 -0
- package/dist/hoi4_agent_tools/focus/quality/types.js +5 -0
- package/dist/hoi4_agent_tools/focus/tool-operations.js +206 -22
- package/dist/hoi4_agent_tools/focus/tool-support.js +1 -1
- package/dist/hoi4_agent_tools/mcp/server/instructions.js +1 -1
- package/dist/hoi4_agent_tools/mcp/tools/focus.js +76 -4
- package/dist/hoi4_agent_tools/reference/game-text.js +109 -0
- package/dist/hoi4_agent_tools/reference/ranking.js +60 -2
- package/dist/hoi4_agent_tools/reference/service.js +92 -21
- package/dist/hoi4_agent_tools/schemas/focus-requests.js +64 -7
- package/dist/hoi4_agent_tools/schemas/focus.js +121 -6
- package/dist/hoi4_agent_tools/version.js +1 -1
- package/docs/configuration.md +17 -17
- package/docs/focus.md +100 -4
- package/docs/reference.md +1 -1
- package/docs/research/reference-benchmark.md +111 -1
- package/docs/setup.md +1 -1
- package/docs/tools.md +5 -5
- 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 +146 -120
- package/schemas/focus-planning-sidecar.schema.json +15 -7
- package/schemas/geography-model.schema.json +1 -1
- package/schemas/gui-animation-source.schema.json +1 -1
- package/schemas/gui-helper.schema.json +1 -1
- package/schemas/gui-scenario.schema.json +1 -1
- package/schemas/helper-expansion-request.schema.json +1 -1
- package/schemas/helper-expansion-summary.schema.json +1 -1
- package/schemas/impact-inspect-input.schema.json +1 -1
- package/schemas/map-operation.schema.json +1 -1
- package/schemas/mechanic-test-input.schema.json +1 -1
- package/schemas/mod-index-input.schema.json +1 -1
- package/schemas/operation-result.schema.json +1 -1
- package/schemas/package-check-input.schema.json +1 -1
- package/schemas/package-manifest.schema.json +1 -1
- package/schemas/probability-analysis-result.schema.json +1 -1
- package/schemas/probability-compare-input.schema.json +1 -1
- package/schemas/probability-evaluate-input.schema.json +1 -1
- package/schemas/probability-inspect-input.schema.json +1 -1
- package/schemas/probability-render-input.schema.json +1 -1
- package/schemas/probability-scenario-set.schema.json +1 -1
- package/schemas/probability-sequence-input.schema.json +1 -1
- package/schemas/probability-simulate-input.schema.json +1 -1
- package/schemas/probability-sweep-input.schema.json +1 -1
- package/schemas/reference-context-input.schema.json +1 -1
- package/schemas/reference-read-input.schema.json +1 -1
- package/schemas/reference-search-input.schema.json +1 -1
- package/schemas/reference-sheets.schema.json +1 -1
- package/schemas/scenario-suite.schema.json +1 -1
- package/schemas/scenario-test-input.schema.json +1 -1
- package/schemas/script-validate-input.schema.json +1 -1
- package/schemas/shared-scenario.schema.json +1 -1
- package/schemas/source-lookup-input.schema.json +1 -1
- package/server.json +2 -2
|
@@ -166,6 +166,47 @@ export function sectionTerms(title, heading, lines) {
|
|
|
166
166
|
: /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/u.test(heading.trim())
|
|
167
167
|
? 'define'
|
|
168
168
|
: undefined,
|
|
169
|
+
role: commandRole(title, heading.trim()),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function commandRole(title, heading) {
|
|
173
|
+
if (!/^[a-z][a-z0-9_]*$/u.test(heading))
|
|
174
|
+
return undefined;
|
|
175
|
+
const page = title.toLowerCase();
|
|
176
|
+
if (page.includes('dynamic variables'))
|
|
177
|
+
return 'variable';
|
|
178
|
+
if (heading.startsWith('on_'))
|
|
179
|
+
return 'on_action';
|
|
180
|
+
if (page.startsWith('trigger'))
|
|
181
|
+
return 'trigger';
|
|
182
|
+
if (page.startsWith('effect'))
|
|
183
|
+
return 'effect';
|
|
184
|
+
return 'other';
|
|
185
|
+
}
|
|
186
|
+
/** A question that starts with one of these asks for a condition; with these, for an effect. */
|
|
187
|
+
const conditionWords = new Set(['check', 'whether', 'is', 'has', 'does', 'if', 'condition']);
|
|
188
|
+
const actionWords = new Set(('add give make set remove change create increase decrease raise lower reduce grant declare ' +
|
|
189
|
+
'annex move start spawn build rename switch kill transfer fire hide run pick free put queue ' +
|
|
190
|
+
'improve tell gain lose destroy release puppet end apply load swap upgrade unlock').split(' '));
|
|
191
|
+
const timingWords = new Set(['when', 'whenever', 'happens', 'happen', 'after', 'once']);
|
|
192
|
+
/** A command of another kind than the question asks for keeps this share of its score. */
|
|
193
|
+
const intentPenalty = 0.6;
|
|
194
|
+
function questionIntent(normalized) {
|
|
195
|
+
const raw = normalized.match(tokenPattern) ?? [];
|
|
196
|
+
const first = raw.find((word) => !['how', 'to', 'i', 'can', 'do', 'a', 'the'].includes(word));
|
|
197
|
+
const onAction = raw.some((word) => timingWords.has(word)) || /on[ _]actions?/u.test(normalized);
|
|
198
|
+
return {
|
|
199
|
+
role:
|
|
200
|
+
// "Run an effect when ..." asks for the moment, not for an effect.
|
|
201
|
+
onAction || first === undefined || first.includes('_')
|
|
202
|
+
? undefined
|
|
203
|
+
: conditionWords.has(first)
|
|
204
|
+
? 'trigger'
|
|
205
|
+
: actionWords.has(first)
|
|
206
|
+
? 'effect'
|
|
207
|
+
: undefined,
|
|
208
|
+
onAction,
|
|
209
|
+
variable: raw.some((word) => word.startsWith('variable')),
|
|
169
210
|
};
|
|
170
211
|
}
|
|
171
212
|
/** Script names abbreviate counts as `num_`, as in `num_divisions` or `num_of_factories`. */
|
|
@@ -175,13 +216,19 @@ const titleWeight = 0.5;
|
|
|
175
216
|
const bodyWeight = 1;
|
|
176
217
|
const saturation = 1.2;
|
|
177
218
|
const lengthNormalization = 0.75;
|
|
219
|
+
/** Words other copies of the same command use, per occurrence, relative to body text. */
|
|
220
|
+
const cardWeight = 0.5;
|
|
178
221
|
/** Corpus statistics for one immutable inventory of sections. */
|
|
179
222
|
export class RankingIndex {
|
|
180
223
|
entries;
|
|
224
|
+
cards;
|
|
181
225
|
#documentFrequency = new Map();
|
|
182
226
|
#averageBodyLength;
|
|
183
|
-
constructor(entries
|
|
227
|
+
constructor(entries,
|
|
228
|
+
/** For a command entry, the words of its other documentation and in-game text. */
|
|
229
|
+
cards = new Map()) {
|
|
184
230
|
this.entries = entries;
|
|
231
|
+
this.cards = cards;
|
|
185
232
|
let total = 0;
|
|
186
233
|
for (const entry of entries) {
|
|
187
234
|
total += entry.bodyLength;
|
|
@@ -221,6 +268,7 @@ export class RankingIndex {
|
|
|
221
268
|
normalized,
|
|
222
269
|
identifiers: new Set(terms.map(({ term }) => term).filter((term) => term.includes('_'))),
|
|
223
270
|
wants: {
|
|
271
|
+
...questionIntent(normalized),
|
|
224
272
|
console: words.some((word) => word === 'console' || word.startsWith('command')),
|
|
225
273
|
define: words.some((word) => word.startsWith('define')) || /\b[A-Z]{2,}_[A-Z]/u.test(query),
|
|
226
274
|
},
|
|
@@ -236,7 +284,8 @@ export class RankingIndex {
|
|
|
236
284
|
for (const { term, idf, weight } of plan.terms) {
|
|
237
285
|
const weighted = headingWeight * (entry.heading.get(term) ?? 0) +
|
|
238
286
|
titleWeight * (entry.title.get(term) ?? 0) +
|
|
239
|
-
(bodyWeight * (entry.body.get(term) ?? 0)) / lengthFactor
|
|
287
|
+
(bodyWeight * (entry.body.get(term) ?? 0)) / lengthFactor +
|
|
288
|
+
cardWeight * (this.cards.get(entry)?.get(term) ?? 0);
|
|
240
289
|
if (weighted === 0)
|
|
241
290
|
continue;
|
|
242
291
|
matched++;
|
|
@@ -270,6 +319,15 @@ export class RankingIndex {
|
|
|
270
319
|
score *= 0.7;
|
|
271
320
|
if (entry.specialty === 'define' && !plan.wants.define)
|
|
272
321
|
score *= 0.6;
|
|
322
|
+
{
|
|
323
|
+
const { role } = entry;
|
|
324
|
+
if (role === 'on_action' && !plan.wants.onAction)
|
|
325
|
+
score *= intentPenalty;
|
|
326
|
+
else if (role === 'variable' && !plan.wants.variable)
|
|
327
|
+
score *= intentPenalty;
|
|
328
|
+
else if (plan.wants.role !== undefined && role !== undefined && role !== plan.wants.role)
|
|
329
|
+
score *= intentPenalty;
|
|
330
|
+
}
|
|
273
331
|
return score;
|
|
274
332
|
}
|
|
275
333
|
/** Extra credit for query words that appear next to each other in the section. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { statSync } from 'node:fs';
|
|
1
2
|
import { realpath } from 'node:fs/promises';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { globFiles } from '../core/file-glob.js';
|
|
@@ -8,7 +9,8 @@ import { prepareSource, verifySource, readBoundedFile, } from '../core/scanner.j
|
|
|
8
9
|
import { decodeSource } from '../core/source/encoding.js';
|
|
9
10
|
import { activeKnownMistakes } from './known-mistakes.js';
|
|
10
11
|
import { readBoundedJsonLines } from './lines.js';
|
|
11
|
-
import {
|
|
12
|
+
import { commandTexts, readGameText } from './game-text.js';
|
|
13
|
+
import { RankingIndex, sectionTerms, textTerms } from './ranking.js';
|
|
12
14
|
const MAX_FILES = 512;
|
|
13
15
|
const MAX_FILE_BYTES = 2_000_000;
|
|
14
16
|
const MAX_TOTAL_BYTES = 32_000_000;
|
|
@@ -34,6 +36,10 @@ export function publicReferenceSection(section) {
|
|
|
34
36
|
const { lines: _lines, terms: _terms, ...citation } = section;
|
|
35
37
|
return citation;
|
|
36
38
|
}
|
|
39
|
+
/** An unchanged stamp lets a repeated query reuse the hashed revision without rereading. */
|
|
40
|
+
function fileStamp(metadata) {
|
|
41
|
+
return `${metadata.size}:${metadata.mtimeMs}:${metadata.ctimeMs}:${metadata.ino}:${metadata.dev}`;
|
|
42
|
+
}
|
|
37
43
|
/** Up to three non-empty lines from `first`, trimmed to the 300-character excerpt bound. */
|
|
38
44
|
function snippet(lines, first = 0) {
|
|
39
45
|
return lines
|
|
@@ -120,6 +126,21 @@ function sectionize(root, filePath, content, revision) {
|
|
|
120
126
|
...rows.map((row) => section(row.heading, row.start, row.start + 1)),
|
|
121
127
|
];
|
|
122
128
|
}
|
|
129
|
+
/** The kit's HOI4 wiki folder, and the name it had before the kit renamed it. */
|
|
130
|
+
const WIKI_FOLDER = 'hoi4_wiki';
|
|
131
|
+
const LEGACY_WIKI_FOLDER = 'paradox_wiki';
|
|
132
|
+
/** `hoi4_wiki/` when the mod has it, otherwise the older `paradox_wiki/` of a mod the kit has not updated. */
|
|
133
|
+
function defaultWikiRoot(modRoot) {
|
|
134
|
+
const current = path.join(modRoot, WIKI_FOLDER);
|
|
135
|
+
try {
|
|
136
|
+
if (statSync(current).isDirectory())
|
|
137
|
+
return current;
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// Not there: fall back to the legacy name, which is reported unavailable when absent too.
|
|
141
|
+
}
|
|
142
|
+
return path.join(modRoot, LEGACY_WIKI_FOLDER);
|
|
143
|
+
}
|
|
123
144
|
function sourceRoots(workspace) {
|
|
124
145
|
const gameRoot = workspace.gameRoot ?? (workspace.registration.kind === 'game' ? workspace.modRoot : undefined);
|
|
125
146
|
return [
|
|
@@ -135,9 +156,9 @@ function sourceRoots(workspace) {
|
|
|
135
156
|
]),
|
|
136
157
|
{
|
|
137
158
|
kind: 'wiki',
|
|
138
|
-
root: workspace.wikiRoot ??
|
|
159
|
+
root: workspace.wikiRoot ?? defaultWikiRoot(workspace.modRoot),
|
|
139
160
|
patterns: ['**/*.md'],
|
|
140
|
-
authority: '
|
|
161
|
+
authority: 'HOI4 wiki (kit)',
|
|
141
162
|
},
|
|
142
163
|
{
|
|
143
164
|
kind: 'script_doc',
|
|
@@ -202,6 +223,34 @@ const gameDocNames = {
|
|
|
202
223
|
],
|
|
203
224
|
ai: ['common/ai_strategy/_documentation', 'documentation/triggers_documentation'],
|
|
204
225
|
};
|
|
226
|
+
const commandHeading = /^[a-z][a-z0-9_]*$/u;
|
|
227
|
+
/**
|
|
228
|
+
* For each entry about one command, the words the game shows players for it: the installed
|
|
229
|
+
* documentation says "check if state is coastal" and the tooltip "Is coastal"; a modifier
|
|
230
|
+
* entry gains its in-game name, such as "Supply Consumption". Console commands and defines
|
|
231
|
+
* gain nothing.
|
|
232
|
+
*/
|
|
233
|
+
function commandCards(sections, gameText) {
|
|
234
|
+
const commands = new Set(sections
|
|
235
|
+
.filter(({ source, heading }) => source === 'game_doc' && commandHeading.test(heading.trim()))
|
|
236
|
+
.map(({ heading }) => heading.trim()));
|
|
237
|
+
const spoken = new Map();
|
|
238
|
+
for (const [name, texts] of commandTexts(commands, gameText)) {
|
|
239
|
+
const card = new Map();
|
|
240
|
+
for (const term of texts.flatMap((text) => textTerms(text)))
|
|
241
|
+
card.set(term, Math.min((card.get(term) ?? 0) + 1, 3));
|
|
242
|
+
spoken.set(name, card);
|
|
243
|
+
}
|
|
244
|
+
const cards = new Map();
|
|
245
|
+
for (const section of sections) {
|
|
246
|
+
if (section.terms.specialty !== undefined || section.terms.navigation)
|
|
247
|
+
continue;
|
|
248
|
+
const card = spoken.get(section.heading.trim());
|
|
249
|
+
if (card !== undefined)
|
|
250
|
+
cards.set(section.terms, card);
|
|
251
|
+
}
|
|
252
|
+
return cards;
|
|
253
|
+
}
|
|
205
254
|
/** A workspace-private, read-only reference index over explicitly known local roots. */
|
|
206
255
|
export class ReferenceService {
|
|
207
256
|
#cache = new Map();
|
|
@@ -304,7 +353,13 @@ export class ReferenceService {
|
|
|
304
353
|
coverage[root.kind].files++;
|
|
305
354
|
admittedSources.push(source);
|
|
306
355
|
}
|
|
356
|
+
const keyOf = (source) => `${root.kind}:${canonicalRoot}:${source.canonicalPath}`;
|
|
307
357
|
const reads = await Promise.allSettled(admittedSources.map(async (source) => {
|
|
358
|
+
const known = this.#cache.get(keyOf(source));
|
|
359
|
+
if (known?.stamp === fileStamp(source.metadata)) {
|
|
360
|
+
await verifySource(readRoot, source);
|
|
361
|
+
return known;
|
|
362
|
+
}
|
|
308
363
|
const content = await readBoundedFile(source.handle, source.metadata.size, signal);
|
|
309
364
|
await verifySource(readRoot, source);
|
|
310
365
|
if (content.length !== source.metadata.size)
|
|
@@ -318,17 +373,26 @@ export class ReferenceService {
|
|
|
318
373
|
for (const [index, read] of reads.entries()) {
|
|
319
374
|
if (read.status !== 'fulfilled')
|
|
320
375
|
continue;
|
|
321
|
-
const
|
|
322
|
-
const
|
|
323
|
-
const key =
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
376
|
+
const source = admittedSources[index];
|
|
377
|
+
const canonical = source.canonicalPath;
|
|
378
|
+
const key = keyOf(source);
|
|
379
|
+
let cached;
|
|
380
|
+
if (Buffer.isBuffer(read.value)) {
|
|
381
|
+
const content = read.value;
|
|
382
|
+
const revision = sha256Bytes(content);
|
|
383
|
+
const previous = this.#cache.get(key);
|
|
384
|
+
cached =
|
|
385
|
+
previous?.revision === revision
|
|
386
|
+
? { ...previous, stamp: fileStamp(source.metadata) }
|
|
387
|
+
: {
|
|
388
|
+
revision,
|
|
389
|
+
bytes: content.length,
|
|
390
|
+
stamp: fileStamp(source.metadata),
|
|
391
|
+
sections: sectionize(root, canonical, referenceText(content), revision),
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
else
|
|
395
|
+
cached = read.value;
|
|
332
396
|
this.retain(key, cached);
|
|
333
397
|
const admitted = cached.sections.slice(0, MAX_SECTIONS - sections.length);
|
|
334
398
|
if (admitted.length < cached.sections.length)
|
|
@@ -346,7 +410,7 @@ export class ReferenceService {
|
|
|
346
410
|
}
|
|
347
411
|
async search(workspace, input, signal) {
|
|
348
412
|
const inventory = await this.inventory(workspace, signal, input.sources);
|
|
349
|
-
const { ranked: matches, describe } = this.rank(inventory.sections, input.query);
|
|
413
|
+
const { ranked: matches, describe } = this.rank(inventory.sections, input.query, await this.gameText(workspace));
|
|
350
414
|
const results = matches.slice(0, input.limit).map((match) => {
|
|
351
415
|
const { section, score, excerpt, matchLine } = describe(match);
|
|
352
416
|
return { ...this.publicSection(section), score, excerpt, matchLine };
|
|
@@ -367,8 +431,8 @@ export class ReferenceService {
|
|
|
367
431
|
};
|
|
368
432
|
}
|
|
369
433
|
/** One index per distinct set of section revisions; IDF depends on the whole inventory. */
|
|
370
|
-
rankingIndex(sections) {
|
|
371
|
-
const parts = [];
|
|
434
|
+
rankingIndex(sections, gameText) {
|
|
435
|
+
const parts = [`game-text\0${gameText.revision}`];
|
|
372
436
|
let previous;
|
|
373
437
|
for (const section of sections) {
|
|
374
438
|
if (previous?.path !== section.path || previous.revision !== section.revision)
|
|
@@ -382,7 +446,7 @@ export class ReferenceService {
|
|
|
382
446
|
this.#indexes.set(key, cached);
|
|
383
447
|
return cached;
|
|
384
448
|
}
|
|
385
|
-
const index = new RankingIndex(sections.map(({ terms }) => terms));
|
|
449
|
+
const index = new RankingIndex(sections.map(({ terms }) => terms), commandCards(sections, gameText));
|
|
386
450
|
this.#indexes.set(key, index);
|
|
387
451
|
while (this.#indexes.size > 4) {
|
|
388
452
|
const oldest = this.#indexes.keys().next().value;
|
|
@@ -392,8 +456,8 @@ export class ReferenceService {
|
|
|
392
456
|
}
|
|
393
457
|
return index;
|
|
394
458
|
}
|
|
395
|
-
rank(sections, question) {
|
|
396
|
-
const index = this.rankingIndex(sections);
|
|
459
|
+
rank(sections, question, gameText) {
|
|
460
|
+
const index = this.rankingIndex(sections, gameText);
|
|
397
461
|
const plan = index.plan(question);
|
|
398
462
|
const scored = [];
|
|
399
463
|
for (const section of sections) {
|
|
@@ -485,7 +549,9 @@ export class ReferenceService {
|
|
|
485
549
|
async context(workspace, input, signal) {
|
|
486
550
|
const inventory = await this.inventory(workspace, signal);
|
|
487
551
|
const wanted = surfaceNames[input.surface];
|
|
488
|
-
const ranking = input.question === undefined
|
|
552
|
+
const ranking = input.question === undefined
|
|
553
|
+
? undefined
|
|
554
|
+
: this.rank(inventory.sections, input.question, await this.gameText(workspace));
|
|
489
555
|
const ranked = ranking?.ranked ?? [];
|
|
490
556
|
const required = [];
|
|
491
557
|
const missing = [];
|
|
@@ -552,6 +618,11 @@ export class ReferenceService {
|
|
|
552
618
|
})),
|
|
553
619
|
};
|
|
554
620
|
}
|
|
621
|
+
async gameText(workspace) {
|
|
622
|
+
const gameRoot = workspace.gameRoot ??
|
|
623
|
+
(workspace.registration.kind === 'game' ? workspace.modRoot : undefined);
|
|
624
|
+
return readGameText(gameRoot);
|
|
625
|
+
}
|
|
555
626
|
publicSection(section) {
|
|
556
627
|
return publicReferenceSection(section);
|
|
557
628
|
}
|
|
@@ -74,7 +74,20 @@ export const focusRenderRequestSchema = z
|
|
|
74
74
|
.min(FOCUS_RENDER_MIN_OUTPUT_SCALE)
|
|
75
75
|
.max(FOCUS_RENDER_MAX_OUTPUT_SCALE)
|
|
76
76
|
.optional(),
|
|
77
|
-
cropFocusIds: z
|
|
77
|
+
cropFocusIds: z
|
|
78
|
+
.array(z.string().min(1).max(256))
|
|
79
|
+
.max(16)
|
|
80
|
+
.optional()
|
|
81
|
+
.describe('Close-ups around these focuses: PNG artifacts of the icon render, and inline schematic crops.'),
|
|
82
|
+
cropBranchIds: z
|
|
83
|
+
.array(z.string().min(1).max(256))
|
|
84
|
+
.max(8)
|
|
85
|
+
.optional()
|
|
86
|
+
.describe('Inline close-ups of whole branches. Use a declared branch id or the first focus of a derived branch; the scorecard lists them.'),
|
|
87
|
+
inline: z
|
|
88
|
+
.boolean()
|
|
89
|
+
.optional()
|
|
90
|
+
.describe('Default true: return an in-game-style schematic overview and crops of the worst places as inline images, so no second call is needed. False returns only linked artifacts.'),
|
|
78
91
|
columns: z.number().int().min(1).max(12).optional(),
|
|
79
92
|
padding: z.number().int().min(0).max(1000).optional(),
|
|
80
93
|
png: z
|
|
@@ -102,6 +115,8 @@ export const focusRenderRequestSchema = z
|
|
|
102
115
|
['verticalSpacing', value.verticalSpacing],
|
|
103
116
|
['reviewScale', value.reviewScale],
|
|
104
117
|
['cropFocusIds', value.cropFocusIds],
|
|
118
|
+
['cropBranchIds', value.cropBranchIds],
|
|
119
|
+
['inline', value.inline],
|
|
105
120
|
];
|
|
106
121
|
for (const [field, fieldValue] of invalid) {
|
|
107
122
|
if (fieldValue !== undefined)
|
|
@@ -124,7 +139,7 @@ export const focusRewriteRequestSchema = z
|
|
|
124
139
|
workspaceId: workspaceIdSchema,
|
|
125
140
|
relativePath: workspaceRelativePathSchema,
|
|
126
141
|
treeId: z.string().min(1).max(256).optional(),
|
|
127
|
-
layoutMode: z.enum(['authored', 'compact']).default('authored'),
|
|
142
|
+
layoutMode: z.enum(['authored', 'compact', 'engine']).default('authored'),
|
|
128
143
|
compactFocusIds: z.array(z.string().min(1).max(256)).min(1).max(10_000).optional(),
|
|
129
144
|
pinnedFocusIds: z.array(z.string().min(1).max(256)).max(10_000).optional(),
|
|
130
145
|
symmetryGroups: z
|
|
@@ -144,6 +159,15 @@ export const focusRewriteRequestSchema = z
|
|
|
144
159
|
.strict())
|
|
145
160
|
.max(64)
|
|
146
161
|
.optional(),
|
|
162
|
+
placement: z
|
|
163
|
+
.object({
|
|
164
|
+
focusIds: z.array(z.string().min(1).max(256)).min(1).max(10_000),
|
|
165
|
+
anchorId: z.string().min(1).max(256).optional(),
|
|
166
|
+
preferSide: z.enum(['left', 'right', 'either']).optional(),
|
|
167
|
+
allowShift: z.boolean().optional(),
|
|
168
|
+
})
|
|
169
|
+
.strict()
|
|
170
|
+
.optional(),
|
|
147
171
|
plan: compactFocusPlanSchema.optional(),
|
|
148
172
|
createIfMissing: z.boolean().default(false),
|
|
149
173
|
horizontalSpacing: z.number().int().min(80).max(1000).optional(),
|
|
@@ -166,6 +190,33 @@ export const focusRewriteRequestSchema = z
|
|
|
166
190
|
path: [field],
|
|
167
191
|
message: `${field} requires compact layout mode`,
|
|
168
192
|
});
|
|
193
|
+
if (value.placement !== undefined) {
|
|
194
|
+
if (value.layoutMode === 'compact')
|
|
195
|
+
context.addIssue({
|
|
196
|
+
code: 'custom',
|
|
197
|
+
path: ['placement'],
|
|
198
|
+
message: 'placement requires authored or engine layout mode',
|
|
199
|
+
});
|
|
200
|
+
if (value.layoutMode === 'authored' && value.plan === undefined)
|
|
201
|
+
context.addIssue({
|
|
202
|
+
code: 'custom',
|
|
203
|
+
path: ['placement'],
|
|
204
|
+
message: 'placement in authored layout mode requires a plan that adds the focuses',
|
|
205
|
+
});
|
|
206
|
+
if (value.placement.anchorId !== undefined &&
|
|
207
|
+
!value.placement.focusIds.includes(value.placement.anchorId))
|
|
208
|
+
context.addIssue({
|
|
209
|
+
code: 'custom',
|
|
210
|
+
path: ['placement', 'anchorId'],
|
|
211
|
+
message: 'placement.anchorId must be one of placement.focusIds',
|
|
212
|
+
});
|
|
213
|
+
if (new Set(value.placement.focusIds).size !== value.placement.focusIds.length)
|
|
214
|
+
context.addIssue({
|
|
215
|
+
code: 'custom',
|
|
216
|
+
path: ['placement', 'focusIds'],
|
|
217
|
+
message: 'placement.focusIds must not repeat a focus',
|
|
218
|
+
});
|
|
219
|
+
}
|
|
169
220
|
const mode = value.mode ?? 'national';
|
|
170
221
|
const schema = mode === 'continuous' ? continuousFocusPaletteSchema : focusTreePlanSchema;
|
|
171
222
|
if (value.plan !== undefined && !schema.safeParse(value.plan).success)
|
|
@@ -191,7 +242,13 @@ export const focusRewriteRequestSchema = z
|
|
|
191
242
|
context.addIssue({
|
|
192
243
|
code: 'custom',
|
|
193
244
|
path: ['layoutMode'],
|
|
194
|
-
message:
|
|
245
|
+
message: `${value.layoutMode} layout mode is only valid in national mode`,
|
|
246
|
+
});
|
|
247
|
+
if (value.placement !== undefined)
|
|
248
|
+
context.addIssue({
|
|
249
|
+
code: 'custom',
|
|
250
|
+
path: ['placement'],
|
|
251
|
+
message: 'placement is only valid in national mode',
|
|
195
252
|
});
|
|
196
253
|
for (const [field, fieldValue] of [
|
|
197
254
|
['horizontalSpacing', value.horizontalSpacing],
|
|
@@ -207,23 +264,23 @@ export const focusRewriteRequestSchema = z
|
|
|
207
264
|
});
|
|
208
265
|
}
|
|
209
266
|
else {
|
|
210
|
-
if (value.plan === undefined && value.layoutMode
|
|
267
|
+
if (value.plan === undefined && value.layoutMode === 'authored')
|
|
211
268
|
context.addIssue({
|
|
212
269
|
code: 'custom',
|
|
213
270
|
path: ['plan'],
|
|
214
|
-
message: 'plan is required unless layoutMode is compact',
|
|
271
|
+
message: 'plan is required unless layoutMode is compact or engine',
|
|
215
272
|
});
|
|
216
273
|
if (value.plan === undefined && value.treeId === undefined)
|
|
217
274
|
context.addIssue({
|
|
218
275
|
code: 'custom',
|
|
219
276
|
path: ['treeId'],
|
|
220
|
-
message: 'treeId is required for plan-free compact
|
|
277
|
+
message: 'treeId is required for plan-free compact or engine layout',
|
|
221
278
|
});
|
|
222
279
|
if (value.plan === undefined && value.createIfMissing)
|
|
223
280
|
context.addIssue({
|
|
224
281
|
code: 'custom',
|
|
225
282
|
path: ['createIfMissing'],
|
|
226
|
-
message: 'plan-free compact
|
|
283
|
+
message: 'plan-free compact or engine layout requires an existing focus source',
|
|
227
284
|
});
|
|
228
285
|
if (value.plan !== undefined &&
|
|
229
286
|
value.treeId !== undefined &&
|
|
@@ -36,11 +36,24 @@ const automaticPositionSchema = z
|
|
|
36
36
|
.object({
|
|
37
37
|
mode: z.literal('auto'),
|
|
38
38
|
pinned: z.literal(false),
|
|
39
|
-
preferredX: z
|
|
40
|
-
|
|
39
|
+
preferredX: z
|
|
40
|
+
.number()
|
|
41
|
+
.int()
|
|
42
|
+
.min(-100_000)
|
|
43
|
+
.max(100_000)
|
|
44
|
+
.optional()
|
|
45
|
+
.describe('Column the solver aims for; it still spaces and balances the branch.'),
|
|
46
|
+
preferredY: z
|
|
47
|
+
.number()
|
|
48
|
+
.int()
|
|
49
|
+
.min(-100_000)
|
|
50
|
+
.max(100_000)
|
|
51
|
+
.optional()
|
|
52
|
+
.describe('Row the solver aims for; a focus always sits below its lowest prerequisite.'),
|
|
41
53
|
})
|
|
42
54
|
.strict();
|
|
43
|
-
const positionSchema = z
|
|
55
|
+
const positionSchema = z
|
|
56
|
+
.discriminatedUnion('mode', [
|
|
44
57
|
z
|
|
45
58
|
.object({
|
|
46
59
|
mode: z.literal('fixed'),
|
|
@@ -59,7 +72,8 @@ const positionSchema = z.discriminatedUnion('mode', [
|
|
|
59
72
|
})
|
|
60
73
|
.strict(),
|
|
61
74
|
automaticPositionSchema,
|
|
62
|
-
])
|
|
75
|
+
])
|
|
76
|
+
.describe('fixed = an exact grid coordinate; relative = an offset from another focus, so the branch moves with it; auto = the solver places the focus (prefer it for new trees). One x unit is half a plaque: neighbouring plaques are 2 apart on a row, and a focus directly below its parent has the same x.');
|
|
63
77
|
const routeLockSchema = z
|
|
64
78
|
.object({
|
|
65
79
|
id: z.string().min(1),
|
|
@@ -92,8 +106,14 @@ const focusNodeSchema = z
|
|
|
92
106
|
.object({
|
|
93
107
|
id: z.string().min(1).max(256),
|
|
94
108
|
label: z.string().max(1024),
|
|
95
|
-
branchId: z
|
|
96
|
-
|
|
109
|
+
branchId: z
|
|
110
|
+
.string()
|
|
111
|
+
.optional()
|
|
112
|
+
.describe('Branch family of this focus; per-branch crops and the layout scorecard use it.'),
|
|
113
|
+
laneId: z
|
|
114
|
+
.string()
|
|
115
|
+
.optional()
|
|
116
|
+
.describe('Lane the solver keeps this focus in: one column band per lane.'),
|
|
97
117
|
prerequisites: prerequisitesSchema,
|
|
98
118
|
mutuallyExclusive: z.array(z.string()).max(10_000),
|
|
99
119
|
routeLocks: z.array(routeLockSchema).max(10_000),
|
|
@@ -397,3 +417,98 @@ export const focusLayoutSchema = z
|
|
|
397
417
|
layoutHash: z.string().regex(/^[a-f0-9]{64}$/u),
|
|
398
418
|
})
|
|
399
419
|
.strict();
|
|
420
|
+
const qualityMetricIdSchema = z.enum([
|
|
421
|
+
'H1',
|
|
422
|
+
'H2',
|
|
423
|
+
'H3',
|
|
424
|
+
'H4',
|
|
425
|
+
'H5',
|
|
426
|
+
'S1',
|
|
427
|
+
'S2',
|
|
428
|
+
'S3',
|
|
429
|
+
'S4',
|
|
430
|
+
'S5',
|
|
431
|
+
'S6',
|
|
432
|
+
'S7',
|
|
433
|
+
'S8',
|
|
434
|
+
'S9',
|
|
435
|
+
'S10',
|
|
436
|
+
'S11',
|
|
437
|
+
'D1',
|
|
438
|
+
'D2',
|
|
439
|
+
'D3',
|
|
440
|
+
'D4',
|
|
441
|
+
]);
|
|
442
|
+
const qualityVerdictSchema = z.enum(['blocked', 'revise', 'review', 'pass']);
|
|
443
|
+
export const focusScorecardRowSchema = z
|
|
444
|
+
.object({
|
|
445
|
+
id: qualityMetricIdSchema,
|
|
446
|
+
name: z.string().max(128),
|
|
447
|
+
group: z.enum(['H', 'S', 'D']),
|
|
448
|
+
value: z.number(),
|
|
449
|
+
unit: z.string().max(64),
|
|
450
|
+
reviewLimit: z.number().nullable(),
|
|
451
|
+
reviseLimit: z.number().nullable(),
|
|
452
|
+
vanillaMedian: z.number().nullable(),
|
|
453
|
+
status: z.enum(['ok', 'review', 'revise', 'blocked', 'flag', 'not_evaluated']),
|
|
454
|
+
inVerdict: z.boolean(),
|
|
455
|
+
where: z.array(z.string().max(256)).max(8),
|
|
456
|
+
message: z.string().max(600),
|
|
457
|
+
fix: z
|
|
458
|
+
.object({
|
|
459
|
+
action: z.string().max(64),
|
|
460
|
+
targetFocusIds: z.array(z.string().max(256)).max(16),
|
|
461
|
+
suggested: z.string().max(500),
|
|
462
|
+
expectedMetricChange: z.string().max(300),
|
|
463
|
+
preservesGameplay: z.boolean(),
|
|
464
|
+
})
|
|
465
|
+
.strict()
|
|
466
|
+
.optional(),
|
|
467
|
+
})
|
|
468
|
+
.strict();
|
|
469
|
+
/** Verdict, scorecard and fix hints for one layout of a national focus tree. */
|
|
470
|
+
export const focusLayoutQualitySchema = z
|
|
471
|
+
.object({
|
|
472
|
+
verdict: qualityVerdictSchema,
|
|
473
|
+
score: z.number().int().min(0).max(100),
|
|
474
|
+
summary: z.string().max(500),
|
|
475
|
+
focusCount: z.number().int().nonnegative(),
|
|
476
|
+
bucket: z.enum(['small', 'medium', 'large']),
|
|
477
|
+
softMetricsEvaluated: z.boolean(),
|
|
478
|
+
scorecard: z.array(focusScorecardRowSchema).max(20),
|
|
479
|
+
failingRowCount: z.number().int().nonnegative(),
|
|
480
|
+
nextActions: z.array(z.string().max(500)).max(6),
|
|
481
|
+
notEvaluated: z.array(z.string().max(400)).max(8),
|
|
482
|
+
branches: z
|
|
483
|
+
.array(z
|
|
484
|
+
.object({
|
|
485
|
+
id: z.string().max(256),
|
|
486
|
+
focusCount: z.number().int().nonnegative(),
|
|
487
|
+
minimumX: z.number().int(),
|
|
488
|
+
maximumX: z.number().int(),
|
|
489
|
+
minimumY: z.number().int(),
|
|
490
|
+
maximumY: z.number().int(),
|
|
491
|
+
})
|
|
492
|
+
.strict())
|
|
493
|
+
.max(12),
|
|
494
|
+
})
|
|
495
|
+
.strict();
|
|
496
|
+
/** What a layout change did: verdicts, moved focuses and proof that gameplay relations are intact. */
|
|
497
|
+
export const focusLayoutDeltaSchema = z
|
|
498
|
+
.object({
|
|
499
|
+
verdictBefore: qualityVerdictSchema.nullable(),
|
|
500
|
+
verdictAfter: qualityVerdictSchema,
|
|
501
|
+
scoreBefore: z.number().int().min(0).max(100).nullable(),
|
|
502
|
+
scoreAfter: z.number().int().min(0).max(100),
|
|
503
|
+
improved: z.array(qualityMetricIdSchema).max(20),
|
|
504
|
+
regressed: z.array(qualityMetricIdSchema).max(20),
|
|
505
|
+
movedFocusCount: z.number().int().nonnegative(),
|
|
506
|
+
movedFocusIds: z.array(z.string().max(256)).max(100),
|
|
507
|
+
unmovedFocusCount: z.number().int().nonnegative(),
|
|
508
|
+
unmovedHash: z.string().max(64),
|
|
509
|
+
prerequisiteHash: z.string().max(64),
|
|
510
|
+
prerequisitesUnchanged: z.boolean().nullable(),
|
|
511
|
+
mutualExclusionHash: z.string().max(64),
|
|
512
|
+
mutualExclusionsUnchanged: z.boolean().nullable(),
|
|
513
|
+
})
|
|
514
|
+
.strict();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LATEST_PROTOCOL_VERSION } from '@modelcontextprotocol/sdk/types.js';
|
|
2
2
|
export const PACKAGE_NAME = 'hoi4-agent-tools';
|
|
3
|
-
export const PACKAGE_VERSION = '4.
|
|
3
|
+
export const PACKAGE_VERSION = '4.7.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/configuration.md
CHANGED
|
@@ -105,23 +105,23 @@ Over HTTP, a principal sees only the workspaces granted to it, and any other ID
|
|
|
105
105
|
|
|
106
106
|
Each entry in `workspaces` registers one source folder.
|
|
107
107
|
|
|
108
|
-
| Key | Type | Range | Default
|
|
109
|
-
| ----------------- | --------------------------- | ---------------------------------------------- |
|
|
110
|
-
| `id` | string | lower-case letter, then up to 63 of `a-z0-9_-` | none
|
|
111
|
-
| `name` | string | 1–200 characters | none
|
|
112
|
-
| `root` | path | | none
|
|
113
|
-
| `kind` | `mod`, `game`, `dependency` | | `mod`
|
|
114
|
-
| `gameRoot` | path | | top-level `gameRoot` for `mod`
|
|
115
|
-
| `includeGameDlc` | boolean | | `true`
|
|
116
|
-
| `dependencyRoots` | array of paths | up to 16 | `[]`
|
|
117
|
-
| `dependencies` | array of objects | up to 16 | `[]`
|
|
118
|
-
| `replacePaths` | array of relative paths | up to 1,000 | `[]`
|
|
119
|
-
| `wikiRoot` | absolute path | | `
|
|
120
|
-
| `scriptDocsRoot` | absolute path | | `script_docs/` in the mod
|
|
121
|
-
| `roots` | object | | see below
|
|
122
|
-
| `artifactRoot` | path | | see below
|
|
123
|
-
| `cacheRoot` | path | | see below
|
|
124
|
-
| `fixtureRoot` | path | | unset
|
|
108
|
+
| Key | Type | Range | Default | Purpose |
|
|
109
|
+
| ----------------- | --------------------------- | ---------------------------------------------- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
110
|
+
| `id` | string | lower-case letter, then up to 63 of `a-z0-9_-` | none | Workspace ID used in tool calls and grants; required. `current` is reserved. |
|
|
111
|
+
| `name` | string | 1–200 characters | none | Display name; required. |
|
|
112
|
+
| `root` | path | | none | The workspace folder; required and must exist. |
|
|
113
|
+
| `kind` | `mod`, `game`, `dependency` | | `mod` | `mod` is writable source. `game` registers an installed game as read-only source with its DLC layered after it. `dependency` is read-only source. |
|
|
114
|
+
| `gameRoot` | path | | top-level `gameRoot` for `mod` | The installed game loaded beneath this workspace. |
|
|
115
|
+
| `includeGameDlc` | boolean | | `true` | Layer the game's `dlc/` and `integrated_dlc/` folders between the game and the mod. Set `false` to analyze the base game alone. |
|
|
116
|
+
| `dependencyRoots` | array of paths | up to 16 | `[]` | Read-only mods loaded after the game and DLC and before this workspace, in list order. |
|
|
117
|
+
| `dependencies` | array of objects | up to 16 | `[]` | The same as `dependencyRoots`, with a `replacePaths` list per dependency: `{ "root": "...", "replacePaths": ["..."] }`. Use either this or `dependencyRoots`, not both. |
|
|
118
|
+
| `replacePaths` | array of relative paths | up to 1,000 | `[]` | Folders whose earlier-loaded files this workspace unloads, as `replace_path` does. Entries from the folder's `descriptor.mod` are added automatically. Ignored for `kind: "game"`. |
|
|
119
|
+
| `wikiRoot` | absolute path | | `hoi4_wiki/` in the mod, else `paradox_wiki/` | Folder of the kit's HOI4 wiki used by the reference tools. |
|
|
120
|
+
| `scriptDocsRoot` | absolute path | | `script_docs/` in the mod | Folder of a generated script documentation dump used by the reference tools. |
|
|
121
|
+
| `roots` | object | | see below | Folders, relative to each source layer, that the domain tools scan. |
|
|
122
|
+
| `artifactRoot` | path | | see below | Where rendered images and other generated results are stored. |
|
|
123
|
+
| `cacheRoot` | path | | see below | Where rewrite transactions and locks are stored. |
|
|
124
|
+
| `fixtureRoot` | path | | unset | A read-only folder of extra source files scanned with the workspace at the base game's load position and treated as workspace-owned source. |
|
|
125
125
|
|
|
126
126
|
`artifactRoot` and `cacheRoot` default to `<workspaceStorageRoot>/<id>/artifacts` and `<workspaceStorageRoot>/<id>/cache`, or, without `workspaceStorageRoot`, to `.hoi4-agent/artifacts` and `.hoi4-agent/cache` inside a `mod` workspace.
|
|
127
127
|
A `game` or `dependency` workspace needs both, either explicitly or through `workspaceStorageRoot`.
|