hoi4-agent-tools 4.7.0 → 4.8.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 +24 -0
- package/README.md +32 -13
- package/dist/hoi4_agent_tools/core/engine-client.js +74 -5
- package/dist/hoi4_agent_tools/core/operation-result.js +9 -0
- package/dist/hoi4_agent_tools/core/resident-engine.js +273 -0
- package/dist/hoi4_agent_tools/core/temporary-directories.js +3 -2
- package/dist/hoi4_agent_tools/decision/service.js +7 -0
- package/dist/hoi4_agent_tools/event/service.js +18 -6
- package/dist/hoi4_agent_tools/event/summary.js +9 -0
- package/dist/hoi4_agent_tools/focus/engine-layout.js +1 -1
- package/dist/hoi4_agent_tools/focus/game-render.js +72 -0
- package/dist/hoi4_agent_tools/focus/game-view-output.js +160 -0
- package/dist/hoi4_agent_tools/focus/native-effects.js +4 -4
- package/dist/hoi4_agent_tools/focus/quality/focus-quality-calibration.json +241 -241
- package/dist/hoi4_agent_tools/focus/quality/orthogonal.js +30 -19
- package/dist/hoi4_agent_tools/focus/quality/schematic.js +5 -3
- package/dist/hoi4_agent_tools/focus/quality/scorecard.js +1 -1
- package/dist/hoi4_agent_tools/focus/render.js +21 -9
- package/dist/hoi4_agent_tools/focus/tool-operations.js +158 -3
- package/dist/hoi4_agent_tools/gui/assets.js +18 -0
- package/dist/hoi4_agent_tools/gui/dds.js +38 -5
- package/dist/hoi4_agent_tools/gui/engine-textures.js +48 -0
- package/dist/hoi4_agent_tools/gui/source-graph.js +7 -0
- package/dist/hoi4_agent_tools/gui/tool-operations.js +23 -4
- package/dist/hoi4_agent_tools/gui/validators.js +31 -2
- package/dist/hoi4_agent_tools/ideas/inspect.js +43 -0
- package/dist/hoi4_agent_tools/localisation/inspect.js +34 -0
- package/dist/hoi4_agent_tools/mcp/server/argument-errors.js +2 -0
- package/dist/hoi4_agent_tools/mcp/tools/event.js +2 -0
- package/dist/hoi4_agent_tools/mcp/tools/focus.js +1 -1
- package/dist/hoi4_agent_tools/mcp/tools/reference.js +18 -0
- package/dist/hoi4_agent_tools/probability/operations.js +27 -1
- package/dist/hoi4_agent_tools/probability/service.js +91 -11
- package/dist/hoi4_agent_tools/probability/source-analysis.js +2 -2
- package/dist/hoi4_agent_tools/probability/sweep.js +20 -6
- package/dist/hoi4_agent_tools/reference/command-phrases.json +11065 -0
- package/dist/hoi4_agent_tools/reference/error-log.js +24 -0
- package/dist/hoi4_agent_tools/reference/known-mistakes.js +8 -5
- package/dist/hoi4_agent_tools/reference/known-mistakes.json +4 -4
- package/dist/hoi4_agent_tools/reference/operations.js +68 -2
- package/dist/hoi4_agent_tools/reference/ranking.js +32 -0
- package/dist/hoi4_agent_tools/reference/script-validation.js +46 -6
- package/dist/hoi4_agent_tools/reference/service.js +33 -0
- package/dist/hoi4_agent_tools/reference/source-lookup.js +8 -0
- package/dist/hoi4_agent_tools/schemas/focus-requests.js +4 -0
- package/dist/hoi4_agent_tools/schemas/ideas.js +142 -0
- package/dist/hoi4_agent_tools/schemas/localisation.js +94 -0
- package/dist/hoi4_agent_tools/schemas/mod-tools.js +11 -0
- package/dist/hoi4_agent_tools/version.js +1 -1
- package/docs/focus.md +9 -5
- package/docs/research/reference-benchmark.md +41 -0
- package/docs/tools.md +43 -39
- package/docs/troubleshooting.md +13 -12
- package/engine/README.md +284 -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 +26 -0
- package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -1
- package/schemas/configuration.schema.json +1 -1
- package/schemas/continuous-focus-palette.schema.json +1 -1
- package/schemas/custom-weighted-pool.schema.json +1 -1
- package/schemas/decision-inspect-input.schema.json +1 -1
- package/schemas/error-log-input.schema.json +1 -1
- package/schemas/event-feature-manifest.schema.json +1 -1
- package/schemas/focus-plan.schema.json +1 -1
- package/schemas/focus-planning-sidecar.schema.json +1 -1
- package/schemas/geography-model.schema.json +1 -1
- package/schemas/gui-animation-source.schema.json +1 -1
- package/schemas/gui-helper.schema.json +1 -1
- package/schemas/gui-scenario.schema.json +1 -1
- package/schemas/helper-expansion-request.schema.json +1 -1
- package/schemas/helper-expansion-summary.schema.json +1 -1
- package/schemas/impact-inspect-input.schema.json +1 -1
- package/schemas/map-operation.schema.json +1 -1
- package/schemas/mechanic-test-input.schema.json +1 -1
- package/schemas/mod-index-input.schema.json +1 -1
- package/schemas/operation-result.schema.json +1 -1
- package/schemas/package-check-input.schema.json +1 -1
- package/schemas/package-manifest.schema.json +1 -1
- package/schemas/probability-analysis-result.schema.json +1 -1
- package/schemas/probability-compare-input.schema.json +1 -1
- package/schemas/probability-evaluate-input.schema.json +1 -1
- package/schemas/probability-inspect-input.schema.json +1 -1
- package/schemas/probability-render-input.schema.json +1 -1
- package/schemas/probability-scenario-set.schema.json +1 -1
- package/schemas/probability-sequence-input.schema.json +1 -1
- package/schemas/probability-simulate-input.schema.json +1 -1
- package/schemas/probability-sweep-input.schema.json +1 -1
- package/schemas/reference-context-input.schema.json +1 -1
- package/schemas/reference-read-input.schema.json +1 -1
- package/schemas/reference-search-input.schema.json +1 -1
- package/schemas/reference-sheets.schema.json +1 -1
- package/schemas/scenario-suite.schema.json +1 -1
- package/schemas/scenario-test-input.schema.json +1 -1
- package/schemas/script-validate-input.schema.json +1 -1
- package/schemas/shared-scenario.schema.json +1 -1
- package/schemas/source-lookup-input.schema.json +1 -1
- package/server.json +2 -2
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { sharedResidentEngine, } from '../core/resident-engine.js';
|
|
2
|
+
const MAX_LOCALISATION_DEPTH = 4;
|
|
3
|
+
/** A localisation value with `$KEY$` references resolved, or undefined when the key has none. */
|
|
4
|
+
function localised(index, language, key, depth = 0) {
|
|
5
|
+
const entry = index.find('localisation', `${language}:${key}`);
|
|
6
|
+
const value = typeof entry?.metadata.value === 'string' ? entry.metadata.value : undefined;
|
|
7
|
+
if (value === undefined || depth >= MAX_LOCALISATION_DEPTH)
|
|
8
|
+
return value;
|
|
9
|
+
return value.replace(/\$([A-Za-z0-9_.-]+)(?:\|[^$]*)?\$/gu, (whole, inner) => inner === key ? whole : (localised(index, language, inner, depth + 1) ?? whole));
|
|
10
|
+
}
|
|
11
|
+
/** The game's layers in load order: game, DLC, dependencies, then the mod. */
|
|
12
|
+
export function gameLayers(workspace) {
|
|
13
|
+
return workspace.roots
|
|
14
|
+
.filter(({ kind }) => kind === 'game' || kind === 'dlc' || kind === 'dependency' || kind === 'mod')
|
|
15
|
+
.sort((left, right) => left.loadOrder - right.loadOrder)
|
|
16
|
+
.map((root) => ({
|
|
17
|
+
name: 'label' in root && typeof root.label === 'string' ? root.label : root.kind,
|
|
18
|
+
path: root.path,
|
|
19
|
+
replacePaths: root.replacePaths,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
export async function renderFocusGameView(input) {
|
|
23
|
+
const positions = new Map(input.layout.nodes.map((node) => [node.id, node]));
|
|
24
|
+
const titles = {};
|
|
25
|
+
const focuses = input.plan.focuses.flatMap((focus) => {
|
|
26
|
+
const node = positions.get(focus.id);
|
|
27
|
+
if (node === undefined)
|
|
28
|
+
return [];
|
|
29
|
+
const value = localised(input.index, input.language, focus.localisation.titleKey);
|
|
30
|
+
// The game shows the raw key when a title has no localisation.
|
|
31
|
+
const title = value ?? focus.localisation.titleKey;
|
|
32
|
+
titles[focus.id] = { text: title, resolved: value !== undefined };
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
id: focus.id,
|
|
36
|
+
x: node.x,
|
|
37
|
+
y: node.y,
|
|
38
|
+
...(focus.icons[0] === undefined ? {} : { icon: focus.icons[0].sprite }),
|
|
39
|
+
title,
|
|
40
|
+
prerequisites: focus.prerequisites.groups.map(({ focusIds }) => focusIds),
|
|
41
|
+
mutuallyExclusive: focus.mutuallyExclusive,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
});
|
|
45
|
+
const request = { focuses, scale: input.scale, maxPixels: input.maxPixels };
|
|
46
|
+
const engine = input.engine ?? sharedResidentEngine();
|
|
47
|
+
const outcome = await engine.request('focus.render', {
|
|
48
|
+
layers: gameLayers(input.workspace),
|
|
49
|
+
request,
|
|
50
|
+
}, undefined, input.signal === undefined ? {} : { signal: input.signal });
|
|
51
|
+
if (!outcome.ok)
|
|
52
|
+
return outcome.kind === 'error'
|
|
53
|
+
? { ok: false, code: outcome.code, message: outcome.message }
|
|
54
|
+
: { ok: false, code: outcome.reason, message: outcome.message };
|
|
55
|
+
const result = outcome.response.result;
|
|
56
|
+
const report = result.report;
|
|
57
|
+
if (report === undefined ||
|
|
58
|
+
typeof report.width !== 'number' ||
|
|
59
|
+
!Array.isArray(report.focuses) ||
|
|
60
|
+
!Array.isArray(report.missing) ||
|
|
61
|
+
outcome.response.payload.length === 0)
|
|
62
|
+
return { ok: false, code: 'invalid_output', message: 'The engine returned no focus render' };
|
|
63
|
+
return {
|
|
64
|
+
ok: true,
|
|
65
|
+
png: outcome.response.payload,
|
|
66
|
+
report,
|
|
67
|
+
cache: result.cache ?? {},
|
|
68
|
+
timings: result.timings ?? {},
|
|
69
|
+
titles,
|
|
70
|
+
request,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import sharp from 'sharp';
|
|
2
|
+
import { ArtifactStore, boundedSourceHashEvidence, } from '../core/artifacts.js';
|
|
3
|
+
import { canonicalJson, sha256Bytes } from '../core/canonical.js';
|
|
4
|
+
import { PACKAGE_VERSION } from '../version.js';
|
|
5
|
+
/**
|
|
6
|
+
* Artifacts of the game view alone (`view: "game"`): the PNG, a JSON report, an SVG hover map
|
|
7
|
+
* on the same pixels and a self-contained HTML viewer with zoom and hover titles. No schematic is
|
|
8
|
+
* drawn, so this is the fast path an in-app preview calls on every edit.
|
|
9
|
+
*/
|
|
10
|
+
const artifacts = new ArtifactStore();
|
|
11
|
+
/** Longest edge of the inline overview. */
|
|
12
|
+
const INLINE_EDGE = 1500;
|
|
13
|
+
/** Largest inline overview, the same budget as the schematic pictures. */
|
|
14
|
+
const INLINE_BYTES = 700_000;
|
|
15
|
+
function escapeXml(value) {
|
|
16
|
+
return value
|
|
17
|
+
.replaceAll('&', '&')
|
|
18
|
+
.replaceAll('<', '<')
|
|
19
|
+
.replaceAll('>', '>')
|
|
20
|
+
.replaceAll('"', '"')
|
|
21
|
+
.replaceAll("'", ''');
|
|
22
|
+
}
|
|
23
|
+
function safeStem(value) {
|
|
24
|
+
const safe = value
|
|
25
|
+
.replace(/[^A-Za-z0-9._-]+/gu, '_')
|
|
26
|
+
.replace(/^[_-]+/u, '')
|
|
27
|
+
.slice(0, 80);
|
|
28
|
+
return safe.length === 0 ? 'focus-tree' : safe;
|
|
29
|
+
}
|
|
30
|
+
export async function gameViewBundle(plan, layout, png, report, titles, request) {
|
|
31
|
+
const boxes = report.focuses
|
|
32
|
+
.map((box) => {
|
|
33
|
+
const title = titles[box.id]?.text ?? box.id;
|
|
34
|
+
return `<rect class="focus" data-focus-id="${escapeXml(box.id)}" x="${box.x}" y="${box.y}" width="${box.width}" height="${box.height}"><title>${escapeXml(`${title} (${box.id})`)}</title></rect>`;
|
|
35
|
+
})
|
|
36
|
+
.join('\n');
|
|
37
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${report.width}" height="${report.height}" viewBox="0 0 ${report.width} ${report.height}" role="img" aria-label="${escapeXml(plan.id)} focus tree, game view hover map">
|
|
38
|
+
<style>.focus{fill:transparent;stroke:none}.focus:hover{stroke:#66d9ef;stroke-width:2}</style>
|
|
39
|
+
${boxes}
|
|
40
|
+
</svg>
|
|
41
|
+
`;
|
|
42
|
+
const json = `${canonicalJson({
|
|
43
|
+
schemaVersion: 1,
|
|
44
|
+
view: 'game',
|
|
45
|
+
tree: {
|
|
46
|
+
id: plan.id,
|
|
47
|
+
sourcePath: plan.provenance.sourcePath,
|
|
48
|
+
sourceHash: plan.provenance.sourceHash,
|
|
49
|
+
focusCount: plan.focuses.length,
|
|
50
|
+
},
|
|
51
|
+
layout: { hash: layout.layoutHash, nodes: layout.nodes.map(({ id, x, y }) => ({ id, x, y })) },
|
|
52
|
+
render: report,
|
|
53
|
+
titles,
|
|
54
|
+
request,
|
|
55
|
+
})}\n`;
|
|
56
|
+
const html = `<!doctype html>
|
|
57
|
+
<html lang="en">
|
|
58
|
+
<head>
|
|
59
|
+
<meta charset="utf-8">
|
|
60
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
61
|
+
<title>${escapeXml(plan.id)} focus tree · game view · HOI4 Agent Tools</title>
|
|
62
|
+
<style>
|
|
63
|
+
html,body{margin:0;height:100%;background:#111;color:#ddd;font-family:system-ui,sans-serif}
|
|
64
|
+
#view{position:absolute;inset:0;overflow:hidden;cursor:grab}
|
|
65
|
+
#stage{position:absolute;transform-origin:0 0}
|
|
66
|
+
#stage img,#stage svg{position:absolute;left:0;top:0;display:block}
|
|
67
|
+
#note{position:fixed;left:8px;bottom:8px;font-size:12px;background:#000a;padding:4px 8px;border-radius:4px}
|
|
68
|
+
</style>
|
|
69
|
+
</head>
|
|
70
|
+
<body>
|
|
71
|
+
<div id="view"><div id="stage"><img alt="${escapeXml(plan.id)} focus tree as the game draws it" width="${report.width}" height="${report.height}" src="data:image/png;base64,${png.toString('base64')}">${svg}</div></div>
|
|
72
|
+
<div id="note">${escapeXml(plan.id)} · ${plan.focuses.length} focuses · wheel to zoom, drag to move, hover for titles. Tool render, not a game screenshot.</div>
|
|
73
|
+
<script>
|
|
74
|
+
const view=document.getElementById('view'),stage=document.getElementById('stage');
|
|
75
|
+
let scale=Math.min(1,view.clientWidth/${report.width}),x=0,y=0,drag;
|
|
76
|
+
const apply=()=>{stage.style.transform='translate('+x+'px,'+y+'px) scale('+scale+')'};
|
|
77
|
+
view.addEventListener('wheel',(e)=>{e.preventDefault();const k=Math.exp(-e.deltaY*0.0015),n=Math.min(8,Math.max(0.05,scale*k));x=e.clientX-(e.clientX-x)*n/scale;y=e.clientY-(e.clientY-y)*n/scale;scale=n;apply()},{passive:false});
|
|
78
|
+
view.addEventListener('pointerdown',(e)=>{drag=[e.clientX-x,e.clientY-y];view.setPointerCapture(e.pointerId)});
|
|
79
|
+
view.addEventListener('pointermove',(e)=>{if(drag){x=e.clientX-drag[0];y=e.clientY-drag[1];apply()}});
|
|
80
|
+
view.addEventListener('pointerup',()=>{drag=undefined});
|
|
81
|
+
apply();
|
|
82
|
+
</script>
|
|
83
|
+
</body>
|
|
84
|
+
</html>
|
|
85
|
+
`;
|
|
86
|
+
// The overview shrinks until it fits the inline byte budget, like the schematic pictures.
|
|
87
|
+
let fit = Math.min(1, INLINE_EDGE / Math.max(report.width, report.height));
|
|
88
|
+
let inlinePng = png;
|
|
89
|
+
for (let attempt = 0; attempt < 6; attempt += 1) {
|
|
90
|
+
inlinePng =
|
|
91
|
+
fit >= 1 && png.length <= INLINE_BYTES
|
|
92
|
+
? png
|
|
93
|
+
: await sharp(png)
|
|
94
|
+
.resize(Math.max(1, Math.round(report.width * fit)), Math.max(1, Math.round(report.height * fit)), { fit: 'fill', kernel: sharp.kernel.lanczos3 })
|
|
95
|
+
.png({ compressionLevel: 9, palette: true, quality: 90 })
|
|
96
|
+
.toBuffer();
|
|
97
|
+
if (inlinePng.length <= INLINE_BYTES)
|
|
98
|
+
break;
|
|
99
|
+
fit *= 0.75;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
png,
|
|
103
|
+
svg,
|
|
104
|
+
html,
|
|
105
|
+
json,
|
|
106
|
+
hashes: {
|
|
107
|
+
html: sha256Bytes(html),
|
|
108
|
+
svg: sha256Bytes(svg),
|
|
109
|
+
png: sha256Bytes(png),
|
|
110
|
+
json: sha256Bytes(json),
|
|
111
|
+
},
|
|
112
|
+
inline: {
|
|
113
|
+
png: inlinePng,
|
|
114
|
+
width: Math.max(1, Math.round(report.width * fit)),
|
|
115
|
+
height: Math.max(1, Math.round(report.height * fit)),
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export async function storeGameViewArtifacts(workspace, plan, bundle, renderProfile, signal) {
|
|
120
|
+
const stem = safeStem(plan.id);
|
|
121
|
+
const sourceEvidence = boundedSourceHashEvidence({
|
|
122
|
+
[plan.provenance.sourcePath]: plan.provenance.sourceHash,
|
|
123
|
+
});
|
|
124
|
+
const provenance = {
|
|
125
|
+
toolVersion: PACKAGE_VERSION,
|
|
126
|
+
schemaVersion: 'focus-render.v1',
|
|
127
|
+
sourceHashes: sourceEvidence.sourceHashes,
|
|
128
|
+
renderProfile: { renderer: 'hoi4-engine game view', ...renderProfile },
|
|
129
|
+
metadata: { sourceHashInventory: sourceEvidence.inventory },
|
|
130
|
+
};
|
|
131
|
+
const writes = [
|
|
132
|
+
{
|
|
133
|
+
name: `${stem}.focus.png`,
|
|
134
|
+
mimeType: 'image/png',
|
|
135
|
+
content: bundle.png,
|
|
136
|
+
provenance: { ...provenance, kind: 'focus-png' },
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: `${stem}.focus.json`,
|
|
140
|
+
mimeType: 'application/json',
|
|
141
|
+
content: bundle.json,
|
|
142
|
+
provenance: { ...provenance, kind: 'focus-json' },
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: `${stem}.focus.svg`,
|
|
146
|
+
mimeType: 'image/svg+xml',
|
|
147
|
+
content: bundle.svg,
|
|
148
|
+
provenance: { ...provenance, kind: 'focus-svg' },
|
|
149
|
+
description: 'Hover map of the game view: one titled box per focus, on the PNG pixels',
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: `${stem}.focus.html`,
|
|
153
|
+
mimeType: 'text/html',
|
|
154
|
+
content: bundle.html,
|
|
155
|
+
provenance: { ...provenance, kind: 'focus-html' },
|
|
156
|
+
description: 'The game view with zoom, pan and hover titles',
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
return artifacts.withAtomicChunkedWrites(workspace, writes, (stored) => Promise.resolve([...stored]), signal);
|
|
160
|
+
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Native effect identifiers used to distinguish direct scripted-effect calls
|
|
3
3
|
* from engine effects while importing focus completion rewards.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* fallback list; analysis also accepts every effect the installed
|
|
7
|
-
* documentation/effects_documentation.md, so effects added by later patches
|
|
8
|
-
*
|
|
5
|
+
* Generated by scripts/generate-native-effects.ts from the HOI4 1.19.4.1 effects
|
|
6
|
+
* documentation. This is the fallback list; analysis also accepts every effect the installed
|
|
7
|
+
* game documents in documentation/effects_documentation.md, so effects added by later patches
|
|
8
|
+
* are recognized. The nightly game-update watcher regenerates it for review on a new build.
|
|
9
9
|
*/
|
|
10
10
|
export const nativeEffectKeys = new Set([
|
|
11
11
|
'activate_advisor',
|