hoi4-agent-tools 4.20.3 → 4.21.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 +15 -0
- package/dist/hoi4_agent_tools/characters/write-operations.js +2 -2
- package/dist/hoi4_agent_tools/characters/write-plan.js +21 -205
- package/dist/hoi4_agent_tools/core/artifacts-engine.js +272 -0
- package/dist/hoi4_agent_tools/core/configuration.js +6 -0
- package/dist/hoi4_agent_tools/core/engine.js +67 -21
- package/dist/hoi4_agent_tools/core/idle-cache-lifetime.js +7 -0
- package/dist/hoi4_agent_tools/core/operation-tasks.js +3 -1
- package/dist/hoi4_agent_tools/core/transactions.js +6 -0
- package/dist/hoi4_agent_tools/core/workspace.js +14 -1
- package/dist/hoi4_agent_tools/decision/write-operations.js +7 -8
- package/dist/hoi4_agent_tools/decision/write-plan.js +25 -245
- package/dist/hoi4_agent_tools/doctrine/write-operations.js +2 -2
- package/dist/hoi4_agent_tools/doctrine/write-plan.js +21 -180
- package/dist/hoi4_agent_tools/event/graph.js +3 -3
- package/dist/hoi4_agent_tools/event/job-operations.js +2 -2
- package/dist/hoi4_agent_tools/event/write-job-operations.js +2 -2
- package/dist/hoi4_agent_tools/event/write-operations.js +9 -10
- package/dist/hoi4_agent_tools/event/write-plan.js +28 -278
- package/dist/hoi4_agent_tools/focus/job-operations.js +2 -2
- package/dist/hoi4_agent_tools/gui/assets.js +3 -13
- package/dist/hoi4_agent_tools/gui/job-operations.js +2 -2
- package/dist/hoi4_agent_tools/gui/layout.js +2 -4
- package/dist/hoi4_agent_tools/gui/renderer.js +2 -1
- package/dist/hoi4_agent_tools/gui/source-graph.js +16 -0
- package/dist/hoi4_agent_tools/gui/studio.js +31 -0
- package/dist/hoi4_agent_tools/ideas/write-operations.js +7 -8
- package/dist/hoi4_agent_tools/ideas/write-plan.js +24 -304
- package/dist/hoi4_agent_tools/map/engine-validation.js +230 -0
- package/dist/hoi4_agent_tools/map/job-operations.js +2 -2
- package/dist/hoi4_agent_tools/map/model.js +17 -3
- package/dist/hoi4_agent_tools/map/validation.js +12 -18
- package/dist/hoi4_agent_tools/mcp/transports/negotiated-stdio.js +24 -16
- package/dist/hoi4_agent_tools/probability/job-operations.js +2 -2
- package/dist/hoi4_agent_tools/runtime.js +4 -2
- package/dist/hoi4_agent_tools/script-write/engine-plan.js +45 -0
- package/dist/hoi4_agent_tools/technology/engine-graph.js +156 -0
- package/dist/hoi4_agent_tools/technology/job-operations.js +2 -2
- package/dist/hoi4_agent_tools/technology/operations.js +1 -2
- package/dist/hoi4_agent_tools/technology/service.js +30 -59
- package/dist/hoi4_agent_tools/technology/write-job-operations.js +2 -2
- package/dist/hoi4_agent_tools/technology/write-operations.js +2 -2
- package/dist/hoi4_agent_tools/technology/write-plan.js +21 -207
- package/dist/hoi4_agent_tools/version.js +1 -1
- package/docs/configuration.md +11 -10
- package/docs/troubleshooting.md +11 -11
- 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 +2 -2
- package/schemas/configuration.schema.json +143 -134
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
-
import {
|
|
2
|
+
import { idleCacheLifetime } from '../core/idle-cache-lifetime.js';
|
|
3
3
|
import { errorResult, toolResult } from '../core/operation-result.js';
|
|
4
4
|
import { ServiceError } from '../core/result.js';
|
|
5
5
|
import { technologyInspectRequestSchema, technologyRenderRequestSchema, } from '../schemas/technology.js';
|
|
@@ -9,7 +9,7 @@ const wireResult = z.record(z.string(), z.json());
|
|
|
9
9
|
/** Registers typed technology operations without invoking transport handlers. */
|
|
10
10
|
export function registerTechnologyJobs(operations, engine) {
|
|
11
11
|
const viewer = new TechnologyTreeViewer(engine);
|
|
12
|
-
const lifetime =
|
|
12
|
+
const lifetime = idleCacheLifetime(engine, () => viewer.clearCaches());
|
|
13
13
|
function register(name, schema, normalize, execute, message) {
|
|
14
14
|
operations.registerRead(name, schema, async (input, context) => {
|
|
15
15
|
const release = lifetime.begin();
|
|
@@ -4,7 +4,6 @@ import { compareCodeUnits, hashCanonical } from '../core/canonical.js';
|
|
|
4
4
|
import { emptyServiceResult } from '../core/result.js';
|
|
5
5
|
import { setInlineFilesScanned } from '../core/operation-result.js';
|
|
6
6
|
import { technologyCompareRequestSchema, technologyInspectRequestSchema, splitTechnologyInspectRequest, technologyRenderRequestSchema, } from '../schemas/technology.js';
|
|
7
|
-
import { technologyExplainSummary } from './queries.js';
|
|
8
7
|
import { technologyDiagnostics } from './service.js';
|
|
9
8
|
export function normalizeTechnologyInspectionRequest(input) {
|
|
10
9
|
return JSON.parse(JSON.stringify(technologyInspectRequestSchema.parse(input)));
|
|
@@ -109,7 +108,7 @@ export async function inspectTechnologies(viewer, input) {
|
|
|
109
108
|
counts: technologyCounts(output.graph, output.artifacts.length),
|
|
110
109
|
...(output.helperExpansion === undefined ? {} : { helperExpansion: output.helperExpansion }),
|
|
111
110
|
...(() => {
|
|
112
|
-
const technology = input.mode === 'explain' ?
|
|
111
|
+
const technology = input.mode === 'explain' ? output.explainSummary : undefined;
|
|
113
112
|
return technology === undefined ? {} : { technology };
|
|
114
113
|
})(),
|
|
115
114
|
});
|
|
@@ -15,7 +15,7 @@ import { buildGuiSourceGraph } from '../gui/source-graph.js';
|
|
|
15
15
|
import { compareTechnologyGraphs } from './compare.js';
|
|
16
16
|
import { buildTechnologyGraph, buildTechnologyGraphAsync, technologyAssetPatterns, } from './graph.js';
|
|
17
17
|
import { TECHNOLOGY_GRAPH_SCHEMA_VERSION } from './model.js';
|
|
18
|
-
import {
|
|
18
|
+
import { buildTechnologyGraphOnEngine, queryTechnologyGraph } from './engine-graph.js';
|
|
19
19
|
import { renderTechnologyGraph, technologyRenderIconSprites, } from './render.js';
|
|
20
20
|
const FRAGMENT_CACHE_ENTRIES = 8_192;
|
|
21
21
|
const FRAGMENT_CACHE_BYTES = 134_217_728;
|
|
@@ -70,7 +70,7 @@ function sharedState(engine) {
|
|
|
70
70
|
}
|
|
71
71
|
return state;
|
|
72
72
|
}
|
|
73
|
-
function technologyScanPatterns(workspace) {
|
|
73
|
+
export function technologyScanPatterns(workspace) {
|
|
74
74
|
const roots = workspace.registration.roots;
|
|
75
75
|
const under = (values, glob) => values.map((root) => `${root.replaceAll('\\', '/').replace(/\/$/u, '')}/${glob}`);
|
|
76
76
|
return [
|
|
@@ -97,7 +97,7 @@ function technologyScanPatterns(workspace) {
|
|
|
97
97
|
...under(roots.localisation, '*.{yml,yaml}'),
|
|
98
98
|
].sort(compareCodeUnits);
|
|
99
99
|
}
|
|
100
|
-
async function scanTechnologySources(engine, workspaceId, workspace, principal, signal, renderOnly = false) {
|
|
100
|
+
export async function scanTechnologySources(engine, workspaceId, workspace, principal, signal, renderOnly = false) {
|
|
101
101
|
const patterns = technologyScanPatterns(workspace).filter((pattern) => !renderOnly ||
|
|
102
102
|
!/^(?:events|history|common\/(?:national_focus|decisions|scripted_effects|on_actions|ideas|characters))\//u.test(pattern));
|
|
103
103
|
const snapshot = await engine.scan(workspaceId, { patterns }, principal, signal);
|
|
@@ -454,11 +454,9 @@ export class TechnologyTreeViewer {
|
|
|
454
454
|
const unchangedSource = cached?.generation === generation && cached.snapshot.revision === snapshot.revision;
|
|
455
455
|
const preliminary = unchangedSource
|
|
456
456
|
? cached.graph
|
|
457
|
-
: await
|
|
457
|
+
: await buildTechnologyGraphOnEngine(snapshot, {
|
|
458
458
|
workspaceIdentity: workspace.workspaceIdentity,
|
|
459
|
-
cache: this.#state.fragments,
|
|
460
459
|
...(analysisMode === undefined ? {} : { analysisMode }),
|
|
461
|
-
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
462
460
|
});
|
|
463
461
|
const guiSprites = [
|
|
464
462
|
...preliminary.itemLayouts.flatMap(({ designTeamIcon }) => designTeamIcon === undefined ? [] : [designTeamIcon.sprite]),
|
|
@@ -494,12 +492,10 @@ export class TechnologyTreeViewer {
|
|
|
494
492
|
})));
|
|
495
493
|
if (unchangedSource && assetIdentity(assetFiles) === assetIdentity(cached.assetFiles))
|
|
496
494
|
return cached.graph;
|
|
497
|
-
const graph = await
|
|
495
|
+
const graph = await buildTechnologyGraphOnEngine(snapshot, {
|
|
498
496
|
workspaceIdentity: workspace.workspaceIdentity,
|
|
499
|
-
cache: this.#state.fragments,
|
|
500
497
|
assetFiles,
|
|
501
498
|
...(analysisMode === undefined ? {} : { analysisMode }),
|
|
502
|
-
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
503
499
|
});
|
|
504
500
|
if (options.renderOnly === true)
|
|
505
501
|
graph.analysisBoundary.assumptions.push('Folder renders scan technology definitions, layouts, unlock targets and assets; inbound grants and references require technology inspection.');
|
|
@@ -531,60 +527,32 @@ export class TechnologyTreeViewer {
|
|
|
531
527
|
...(input.principal === undefined ? {} : { principal: input.principal }),
|
|
532
528
|
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
533
529
|
});
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
530
|
+
if (input.mode === 'trace' && input.technologyId === undefined)
|
|
531
|
+
throw new ServiceError('TECHNOLOGY_REQUIRED', 'Technology trace requires technologyId');
|
|
532
|
+
if (input.mode === 'explain' && input.technologyId === undefined)
|
|
533
|
+
throw new ServiceError('TECHNOLOGY_REQUIRED', 'Technology explanation requires technologyId');
|
|
534
|
+
if (input.mode === 'impact' && input.impact === undefined)
|
|
535
|
+
throw new ServiceError('TECH_IMPACT_REQUIRED', 'Technology impact analysis requires a subject');
|
|
536
|
+
const answer = await queryTechnologyGraph(graph, {
|
|
537
|
+
mode: input.mode,
|
|
538
|
+
...(input.folderId === undefined ? {} : { folderId: input.folderId }),
|
|
539
|
+
...(input.technologyId === undefined ? {} : { technologyId: input.technologyId }),
|
|
540
|
+
...(input.categoryId === undefined ? {} : { categoryId: input.categoryId }),
|
|
541
|
+
...(input.targetKind === undefined ? {} : { targetKind: input.targetKind }),
|
|
542
|
+
...(input.targetId === undefined ? {} : { targetId: input.targetId }),
|
|
543
|
+
...(input.mode !== 'trace'
|
|
544
|
+
? {}
|
|
545
|
+
: {
|
|
547
546
|
direction: input.direction ?? 'both',
|
|
548
547
|
maxDepth: input.maxDepth ?? 32,
|
|
549
548
|
maxNodes: input.maxNodes ?? 2_000,
|
|
550
549
|
includeSubTechnologies: input.includeSubTechnologies ?? true,
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
report = explainTechnology(graph, input.technologyId, input.signal);
|
|
558
|
-
break;
|
|
559
|
-
case 'unlocks':
|
|
560
|
-
report = inspectTechnologyUnlocks(graph, {
|
|
561
|
-
...(input.technologyId === undefined ? {} : { technologyId: input.technologyId }),
|
|
562
|
-
...(input.targetKind === undefined ? {} : { targetKind: input.targetKind }),
|
|
563
|
-
...(input.targetId === undefined ? {} : { targetId: input.targetId }),
|
|
564
|
-
});
|
|
565
|
-
break;
|
|
566
|
-
case 'bonus_coverage':
|
|
567
|
-
report = technologyBonusCoverage(graph, {
|
|
568
|
-
...(input.categoryId === undefined ? {} : { categoryId: input.categoryId }),
|
|
569
|
-
...(input.technologyId === undefined ? {} : { technologyId: input.technologyId }),
|
|
570
|
-
});
|
|
571
|
-
break;
|
|
572
|
-
case 'lint':
|
|
573
|
-
report = lintTechnologyGraph(graph, {
|
|
574
|
-
...(input.classifications === undefined
|
|
575
|
-
? {}
|
|
576
|
-
: { classifications: input.classifications }),
|
|
577
|
-
...(input.codes === undefined ? {} : { codes: input.codes }),
|
|
578
|
-
...(input.folderId === undefined ? {} : { folderId: input.folderId }),
|
|
579
|
-
...(input.technologyId === undefined ? {} : { technologyId: input.technologyId }),
|
|
580
|
-
});
|
|
581
|
-
break;
|
|
582
|
-
case 'impact':
|
|
583
|
-
if (input.impact === undefined)
|
|
584
|
-
throw new ServiceError('TECH_IMPACT_REQUIRED', 'Technology impact analysis requires a subject');
|
|
585
|
-
report = analyzeTechnologyImpact(graph, input.impact);
|
|
586
|
-
break;
|
|
587
|
-
}
|
|
550
|
+
}),
|
|
551
|
+
...(input.classifications === undefined ? {} : { classifications: input.classifications }),
|
|
552
|
+
...(input.codes === undefined ? {} : { codes: input.codes }),
|
|
553
|
+
...(input.impact === undefined ? {} : { impact: input.impact }),
|
|
554
|
+
});
|
|
555
|
+
const report = answer.report;
|
|
588
556
|
const reportJson = `${canonicalJson({
|
|
589
557
|
schemaVersion: 'technology-analysis.v1',
|
|
590
558
|
workspaceId: graph.workspaceId,
|
|
@@ -624,6 +592,9 @@ export class TechnologyTreeViewer {
|
|
|
624
592
|
report,
|
|
625
593
|
reportJson,
|
|
626
594
|
artifacts: [artifact, ...(graphArtifact === undefined ? [] : [graphArtifact])],
|
|
595
|
+
...(answer.summary === undefined || answer.summary === null
|
|
596
|
+
? {}
|
|
597
|
+
: { explainSummary: answer.summary }),
|
|
627
598
|
};
|
|
628
599
|
}
|
|
629
600
|
async renderAndStore(input) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
-
import {
|
|
2
|
+
import { idleCacheLifetime } from '../core/idle-cache-lifetime.js';
|
|
3
3
|
import { toolResult } from '../core/operation-result.js';
|
|
4
4
|
import { ServiceError } from '../core/result.js';
|
|
5
5
|
import { techWriteRequestSchema } from '../schemas/tech-write.js';
|
|
@@ -12,7 +12,7 @@ function wire(result) {
|
|
|
12
12
|
/** Registers `hoi4.tech_write`: a read-only preview, or one journaled transaction. */
|
|
13
13
|
export function registerTechWriteJobs(operations, engine) {
|
|
14
14
|
const viewer = new TechnologyTreeViewer(engine);
|
|
15
|
-
const lifetime =
|
|
15
|
+
const lifetime = idleCacheLifetime(engine, () => viewer.clearCaches());
|
|
16
16
|
operations.registerWrite('hoi4.tech_write', techWriteRequestSchema, async (input, context) => {
|
|
17
17
|
if (input.workspaceId !== 'current' && input.workspaceId !== context.workspaceId)
|
|
18
18
|
throw new ServiceError('JOB_ARGUMENT_SCOPE_MISMATCH', 'The request workspace does not match the authorized job workspace');
|
|
@@ -133,7 +133,7 @@ export async function computeTechWrite(engine, input, context, applied) {
|
|
|
133
133
|
let plan;
|
|
134
134
|
if ('file' in target) {
|
|
135
135
|
file = target.file;
|
|
136
|
-
plan = planTechWrite({ bytes: file.bytes, path: file.relativePath }, planInput);
|
|
136
|
+
plan = await planTechWrite({ bytes: file.bytes, path: file.relativePath }, planInput);
|
|
137
137
|
}
|
|
138
138
|
else {
|
|
139
139
|
const inMod = snapshot.index
|
|
@@ -144,7 +144,7 @@ export async function computeTechWrite(engine, input, context, applied) {
|
|
|
144
144
|
id: input.id,
|
|
145
145
|
path: inMod.path,
|
|
146
146
|
});
|
|
147
|
-
plan = planNewTechFile(target.newPath, planInput);
|
|
147
|
+
plan = await planNewTechFile(target.newPath, planInput);
|
|
148
148
|
}
|
|
149
149
|
const missing = {
|
|
150
150
|
localisation: [],
|
|
@@ -1,212 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
:
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (technologies.value.type !== 'block')
|
|
20
|
-
continue;
|
|
21
|
-
const outer = lineIndent(document.text, technologies.start);
|
|
22
|
-
for (const tech of assignments(technologies.value)) {
|
|
23
|
-
const inner = lineIndent(document.text, tech.start);
|
|
24
|
-
if (inner.length > outer.length && inner.startsWith(outer))
|
|
25
|
-
return inner.slice(outer.length);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return '\t';
|
|
29
|
-
}
|
|
30
|
-
/** The body, checked on its own as the block it will become. */
|
|
31
|
-
function assertBodyIsOneBlock(id, body) {
|
|
32
|
-
const probe = parseClausewitz(Buffer.from(`${id} = {\n${body}\n}\n`, 'utf8'), 'tech-body');
|
|
33
|
-
const only = probe.root.entries;
|
|
34
|
-
const single = only.length === 1 && only[0]?.type === 'assignment' && only[0].key.value === id;
|
|
35
|
-
if (hasBlockingDiagnostics(probe.diagnostics) || !single || only[0]?.type !== 'assignment')
|
|
36
|
-
fail('TECH_WRITE_BODY_INVALID', 'The body must be the text between the braces of one technology: balanced braces and no definition of its own', { diagnosticCodes: probe.diagnostics.map(({ code }) => code) });
|
|
37
|
-
if (only[0].value.type !== 'block' || only[0].value.entries.length === 0)
|
|
38
|
-
fail('TECH_WRITE_BODY_INVALID', 'The body of a technology cannot be empty');
|
|
39
|
-
}
|
|
40
|
-
function definitionTexts(document, skip) {
|
|
41
|
-
const byKey = new Map();
|
|
42
|
-
for (const tech of definitions(document)) {
|
|
43
|
-
if (tech.start === skip?.start)
|
|
44
|
-
continue;
|
|
45
|
-
const key = tech.key.value;
|
|
46
|
-
byKey.set(key, [...(byKey.get(key) ?? []), document.text.slice(tech.start, tech.end)]);
|
|
47
|
-
}
|
|
48
|
-
return byKey;
|
|
49
|
-
}
|
|
50
|
-
function checkRequest(input) {
|
|
51
|
-
if (!ID_PATTERN.test(input.id))
|
|
52
|
-
fail('TECH_WRITE_ID_INVALID', `${JSON.stringify(input.id)} is not a valid tech id`, {
|
|
53
|
-
id: input.id,
|
|
54
|
-
});
|
|
55
|
-
if (input.operation === 'remove' && input.body !== undefined)
|
|
56
|
-
fail('TECH_WRITE_BODY_UNEXPECTED', 'remove takes no body');
|
|
57
|
-
if (input.operation !== 'remove' && (input.body === undefined || input.body.trim() === ''))
|
|
58
|
-
fail('TECH_WRITE_BODY_REQUIRED', `${input.operation} needs the body of the tech`);
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
import { callWritePlan, replacementSchema, } from '../script-write/engine-plan.js';
|
|
3
|
+
const planSchema = z.object({
|
|
4
|
+
operation: z.enum(['add', 'replace', 'remove']),
|
|
5
|
+
id: z.string(),
|
|
6
|
+
path: z.string(),
|
|
7
|
+
edit: replacementSchema,
|
|
8
|
+
untouchedDefinitions: z.number().int().nonnegative(),
|
|
9
|
+
});
|
|
10
|
+
async function plan(path, input, source) {
|
|
11
|
+
const answer = await callWritePlan({
|
|
12
|
+
op: 'tech_write.plan',
|
|
13
|
+
path,
|
|
14
|
+
input: { ...input },
|
|
15
|
+
...(source === undefined ? {} : { source }),
|
|
16
|
+
result: planSchema,
|
|
17
|
+
});
|
|
18
|
+
return { ...answer.result, text: answer.text, bytes: answer.bytes, diff: answer.diff };
|
|
59
19
|
}
|
|
60
|
-
/**
|
|
61
|
-
* The plan that creates a new `common/technologies` file holding one new technology, for
|
|
62
|
-
* `createFile: true`. The file is UTF-8 without a byte order mark and uses tabs and LF, as the
|
|
63
|
-
* game's own tech files do.
|
|
64
|
-
*/
|
|
20
|
+
/** The plan that creates a new file holding one new tech, for `createFile: true`. */
|
|
65
21
|
export function planNewTechFile(path, input) {
|
|
66
|
-
|
|
67
|
-
if (input.operation !== 'add')
|
|
68
|
-
fail('TECH_WRITE_FILE_NOT_FOUND', `${path} does not exist, and only add can create a file`);
|
|
69
|
-
assertBodyIsOneBlock(input.id, input.body);
|
|
70
|
-
const text = [
|
|
71
|
-
'technologies = {',
|
|
72
|
-
`\t${input.id} = {`,
|
|
73
|
-
indentedBody(input.body, '\t\t', '\n'),
|
|
74
|
-
'\t}',
|
|
75
|
-
'}',
|
|
76
|
-
'',
|
|
77
|
-
].join('\n');
|
|
78
|
-
const written = parseClausewitz(Buffer.from(text, 'utf8'), path);
|
|
79
|
-
if (hasBlockingDiagnostics(written.diagnostics))
|
|
80
|
-
fail('TECH_WRITE_RESULT_INVALID', 'The new file would have syntax errors', {
|
|
81
|
-
diagnosticCodes: written.diagnostics.map(({ code }) => code),
|
|
82
|
-
});
|
|
83
|
-
return {
|
|
84
|
-
operation: 'add',
|
|
85
|
-
id: input.id,
|
|
86
|
-
path,
|
|
87
|
-
text,
|
|
88
|
-
bytes: Buffer.from(text, 'utf8'),
|
|
89
|
-
edit: { start: 0, end: 0, text, description: `create ${path} with ${input.id}` },
|
|
90
|
-
diff: unifiedTextDiff('', text, `a/${path}`, `b/${path}`, { context: DIFF_CONTEXT_LINES }),
|
|
91
|
-
untouchedDefinitions: 0,
|
|
92
|
-
};
|
|
22
|
+
return plan(path, input, undefined);
|
|
93
23
|
}
|
|
94
24
|
export function planTechWrite(source, input) {
|
|
95
|
-
|
|
96
|
-
const document = parseClausewitz(source.bytes, source.path);
|
|
97
|
-
if (hasBlockingDiagnostics(document.diagnostics))
|
|
98
|
-
fail('TECH_WRITE_SOURCE_INVALID', 'The source has syntax errors and cannot be edited safely', {
|
|
99
|
-
path: source.path,
|
|
100
|
-
diagnosticCodes: document.diagnostics.map(({ code }) => code),
|
|
101
|
-
});
|
|
102
|
-
const text = document.text;
|
|
103
|
-
const newline = document.newline;
|
|
104
|
-
if (input.body !== undefined)
|
|
105
|
-
assertBodyIsOneBlock(input.id, input.body);
|
|
106
|
-
const unit = indentUnit(document);
|
|
107
|
-
const existing = definitions(document).filter(({ key }) => key.value === input.id);
|
|
108
|
-
let edit;
|
|
109
|
-
let skip;
|
|
110
|
-
if (input.operation === 'add') {
|
|
111
|
-
if (existing.length > 0)
|
|
112
|
-
fail('TECH_WRITE_DUPLICATE_ID', `${input.id} is already defined in this file`, {
|
|
113
|
-
id: input.id,
|
|
114
|
-
line: existing[0]?.key.token.line,
|
|
115
|
-
});
|
|
116
|
-
const blocks = assignments(document.root, 'technologies').filter(({ value }) => value.type === 'block');
|
|
117
|
-
if (blocks.length !== 1)
|
|
118
|
-
fail('TECH_WRITE_LAYOUT_UNSUPPORTED', blocks.length === 0
|
|
119
|
-
? 'The file has no technologies block to put the new technology in'
|
|
120
|
-
: `The file has ${blocks.length} technologies blocks, so the new technology has no single place`, { blocks: blocks.length });
|
|
121
|
-
const technologies = blocks[0];
|
|
122
|
-
const block = technologies.value;
|
|
123
|
-
const close = block.close;
|
|
124
|
-
if (close === undefined)
|
|
125
|
-
fail('TECH_WRITE_LAYOUT_UNSUPPORTED', 'The technologynologies block has no closing brace');
|
|
126
|
-
const closeLineStart = text.lastIndexOf('\n', close.start - 1) + 1;
|
|
127
|
-
if (!/^[ \t]*$/u.test(text.slice(closeLineStart, close.start)))
|
|
128
|
-
fail('TECH_WRITE_LAYOUT_UNSUPPORTED', 'The closing brace of the technologies block shares its line with other text, so the new technology has no line to go on', { line: close.line });
|
|
129
|
-
const techIndent = lineIndent(text, technologies.start) + unit;
|
|
130
|
-
const techText = `${techIndent}${input.id} = {${newline}${indentedBody(input.body, techIndent + unit, newline)}${newline}${techIndent}}${newline}`;
|
|
131
|
-
edit = {
|
|
132
|
-
start: closeLineStart,
|
|
133
|
-
end: closeLineStart,
|
|
134
|
-
text: `${block.entries.length > 0 ? newline : ''}${techText}`,
|
|
135
|
-
description: `add ${input.id}`,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
if (existing.length === 0)
|
|
140
|
-
fail('TECH_WRITE_NOT_FOUND', `${input.id} is not defined in this file`, {
|
|
141
|
-
id: input.id,
|
|
142
|
-
});
|
|
143
|
-
if (existing.length > 1)
|
|
144
|
-
fail('TECH_WRITE_DUPLICATE_ID', `${input.id} is defined ${existing.length} times in this file`, { id: input.id, lines: existing.map(({ key }) => key.token.line) });
|
|
145
|
-
const found = existing[0];
|
|
146
|
-
skip = found;
|
|
147
|
-
const techIndent = lineIndent(text, found.start);
|
|
148
|
-
if (input.operation === 'replace') {
|
|
149
|
-
edit = {
|
|
150
|
-
start: found.start,
|
|
151
|
-
end: found.end,
|
|
152
|
-
text: `${input.id} = {${newline}${indentedBody(input.body, techIndent + unit, newline)}${newline}${techIndent}}`,
|
|
153
|
-
description: `replace ${input.id}`,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
const lineStart = text.lastIndexOf('\n', found.start - 1) + 1;
|
|
158
|
-
const lineEndAt = text.indexOf('\n', found.end);
|
|
159
|
-
const lineEnd = lineEndAt === -1 ? text.length : lineEndAt + 1;
|
|
160
|
-
const alone = /^[ \t]*$/u.test(text.slice(lineStart, found.start)) &&
|
|
161
|
-
/^[ \t]*\r?$/u.test(text.slice(found.end, lineEndAt === -1 ? text.length : lineEndAt));
|
|
162
|
-
if (!alone) {
|
|
163
|
-
edit = { start: found.start, end: found.end, text: '', description: `remove ${input.id}` };
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
// A blank line that only separated this tech from the one before it goes with it.
|
|
167
|
-
const before = text.slice(0, lineStart);
|
|
168
|
-
const blankBefore = /(?:^|\n)[ \t]*\r?\n$/u.test(before) && before.length > 0;
|
|
169
|
-
const after = text.slice(lineEnd);
|
|
170
|
-
const nextIsBlankOrClose = /^[ \t]*(?:\r?\n|\})/u.test(after) || after === '';
|
|
171
|
-
let start = lineStart;
|
|
172
|
-
if (blankBefore && nextIsBlankOrClose)
|
|
173
|
-
start = before.lastIndexOf('\n', before.length - 2) + 1;
|
|
174
|
-
edit = { start, end: lineEnd, text: '', description: `remove ${input.id}` };
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
const bytes = applyReplacements(document, [edit]);
|
|
179
|
-
const after = text.slice(0, edit.start) + edit.text + text.slice(edit.end);
|
|
180
|
-
const written = parseClausewitz(bytes, source.path);
|
|
181
|
-
if (hasBlockingDiagnostics(written.diagnostics))
|
|
182
|
-
fail('TECH_WRITE_RESULT_INVALID', 'The edit would leave the file with syntax errors', {
|
|
183
|
-
diagnosticCodes: written.diagnostics.map(({ code }) => code),
|
|
184
|
-
});
|
|
185
|
-
const before = definitionTexts(document, skip);
|
|
186
|
-
const afterTexts = definitionTexts(written, undefined);
|
|
187
|
-
let untouched = 0;
|
|
188
|
-
for (const [key, texts] of before) {
|
|
189
|
-
const now = afterTexts.get(key) ?? [];
|
|
190
|
-
for (const textOfTech of texts)
|
|
191
|
-
if (now.includes(textOfTech))
|
|
192
|
-
untouched += 1;
|
|
193
|
-
else
|
|
194
|
-
fail('TECH_WRITE_RESULT_INVALID', `The edit would change ${key}, which it must not touch`, {
|
|
195
|
-
key,
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
if (written.text !== after)
|
|
199
|
-
fail('TECH_WRITE_RESULT_INVALID', 'The written file does not match the planned edit');
|
|
200
|
-
return {
|
|
201
|
-
operation: input.operation,
|
|
202
|
-
id: input.id,
|
|
203
|
-
path: source.path,
|
|
204
|
-
text: after,
|
|
205
|
-
bytes,
|
|
206
|
-
edit,
|
|
207
|
-
diff: unifiedTextDiff(text, after, `a/${source.path}`, `b/${source.path}`, {
|
|
208
|
-
context: DIFF_CONTEXT_LINES,
|
|
209
|
-
}),
|
|
210
|
-
untouchedDefinitions: untouched,
|
|
211
|
-
};
|
|
25
|
+
return plan(source.path, input, source.bytes);
|
|
212
26
|
}
|
|
@@ -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.21.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
|
@@ -155,16 +155,17 @@ Each `roots` key takes up to 16 folders, and setting `roots` replaces only the k
|
|
|
155
155
|
|
|
156
156
|
## Tools, jobs and lifetime
|
|
157
157
|
|
|
158
|
-
| Key
|
|
159
|
-
|
|
|
160
|
-
| `maxConcurrentTools`
|
|
161
|
-
| `maxSharedTools`
|
|
162
|
-
| `jobDeadlineSeconds`
|
|
163
|
-
| `jobCancelGraceSeconds`
|
|
164
|
-
| `jobWorkerMaxHeapMiB`
|
|
165
|
-
| `jobWorkerIdleSeconds`
|
|
166
|
-
| `
|
|
167
|
-
| `
|
|
158
|
+
| Key | Type | Range | Default | Purpose |
|
|
159
|
+
| ------------------------- | -------- | ---------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
160
|
+
| `maxConcurrentTools` | integer | 1–32 | 2 | Expensive tool calls one server process runs at once. |
|
|
161
|
+
| `maxSharedTools` | integer | 1–128 | 4 | Expensive calls and job workers that run at once across every server process sharing the same `serverStateRoot`. |
|
|
162
|
+
| `jobDeadlineSeconds` | integer | 1–86,400 | 1,800 | A read-only job still running this long after dispatch is stopped and fails with `JOB_DEADLINE_EXCEEDED`. Rewrite jobs are never stopped this way. |
|
|
163
|
+
| `jobCancelGraceSeconds` | integer | 1–600 | 10 | A read-only job still running this long after cancellation is stopped and settles as cancelled. |
|
|
164
|
+
| `jobWorkerMaxHeapMiB` | integer | 256–65,536 | unset | Memory ceiling for each job worker's JavaScript heap, in MiB. Unset keeps Node's default. |
|
|
165
|
+
| `jobWorkerIdleSeconds` | integer | 0–3,600 | 180 | How long a job worker stays warm after a job so the next job reuses its loaded indexes. `0` starts a fresh worker for every job. |
|
|
166
|
+
| `idleCacheReleaseSeconds` | integer | 0–3,600 | 30 | How long after the last tool call the in-memory analysis caches (scans, indexes and the views built from them) are released. The next call rebuilds what it needs, and a busy server reuses the caches between calls. `0` releases them as soon as a call ends. A job worker also exits after `jobWorkerIdleSeconds`. |
|
|
167
|
+
| `plugins` | string[] | up to 8 absolute paths | `[]` | Plugin modules (`.mjs` or `.js`) the stdio server loads to add its own tools. The server loads nothing from a mod folder or the environment, only these paths; a listed file that does not exist is skipped with a warning on stderr, so one shared configuration can name a plugin that exists on one machine. The HTTP server never loads plugins. See [Tools](tools.md#plugins). |
|
|
168
|
+
| `stdioIdleExitMinutes` | integer | 0–10,080 | 0 | A stdio server with no client traffic and no open request for this many minutes exits. `0` never exits. `HOI4_AGENT_STDIO_IDLE_EXIT_MINUTES` overrides it per client. |
|
|
168
169
|
|
|
169
170
|
See [Persistent jobs and MCP tasks](jobs.md) for how jobs, cancellation and recovery behave.
|
|
170
171
|
|
package/docs/troubleshooting.md
CHANGED
|
@@ -5,17 +5,17 @@ This page lists the codes you are most likely to meet, then the checks for probl
|
|
|
5
5
|
|
|
6
6
|
## Setup and connection
|
|
7
7
|
|
|
8
|
-
| Symptom | Cause and fix
|
|
9
|
-
| ----------------------------------------------------------- |
|
|
10
|
-
| The client lists no `hoi4.*` tools | The server did not start. Run `hoi4-agent-tools-setup --diagnose`, which checks the Node.js version (22.19 or newer, or 24), the image library and the configured paths. Then restart the client.
|
|
11
|
-
| `WORKSPACE_CONTEXT_NOT_FOUND` | The server does not know which mod you mean. Pass `workspaceId` (an ID or the mod folder name, such as `"my_mod"`; the error lists them), open the mod folder as the client's working directory, set `defaultWorkspace`, or configure the mod with `--mod-root` or a workspace in the [configuration file](configuration.md).
|
|
12
|
-
| `WORKSPACE_CONTEXT_AMBIGUOUS` | The working directory is inside more than one configured mod. Pass `workspaceId`, or open the one folder you mean.
|
|
13
|
-
| `WORKSPACE_NOT_REGISTERED` | The `workspaceId` is not in the configuration. Use `"current"`, or a workspace id from the configuration file.
|
|
14
|
-
| Renders lack icons or fonts, native commands are unresolved | The game folder is not configured. Set `--game-root` (or `gameRoot`) to the Hearts of Iron IV folder; `hoi4-agent-tools-setup --discover` prints the folders it can find.
|
|
15
|
-
| `ERROR_LOG_NOT_FOUND` | Launch the game once, or set `gameUserRoot` to the folder that holds `logs/`, `mod/` and `save games/` (with OneDrive that is often under `OneDrive\Documents`).
|
|
16
|
-
| `AUTH_INVALID` over HTTP | The bearer token is missing, expired or for another server. See the [HTTP guide](http.md).
|
|
17
|
-
| Startup or a call times out in the client | A cold scan of a large mod takes minutes. Raise the client's startup and tool timeouts (the printed Codex entries use 120 and 600 seconds), or use [background jobs](jobs.md). The stdio server answers the handshake and the tool list
|
|
18
|
-
| Many idle `node` processes | Some clients keep a server per subagent. Set `HOI4_AGENT_STDIO_IDLE_EXIT_MINUTES`; see [Server lifetime](setup.md#server-lifetime).
|
|
8
|
+
| Symptom | Cause and fix |
|
|
9
|
+
| ----------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
10
|
+
| The client lists no `hoi4.*` tools | The server did not start. Run `hoi4-agent-tools-setup --diagnose`, which checks the Node.js version (22.19 or newer, or 24), the image library and the configured paths. Then restart the client. |
|
|
11
|
+
| `WORKSPACE_CONTEXT_NOT_FOUND` | The server does not know which mod you mean. Pass `workspaceId` (an ID or the mod folder name, such as `"my_mod"`; the error lists them), open the mod folder as the client's working directory, set `defaultWorkspace`, or configure the mod with `--mod-root` or a workspace in the [configuration file](configuration.md). |
|
|
12
|
+
| `WORKSPACE_CONTEXT_AMBIGUOUS` | The working directory is inside more than one configured mod. Pass `workspaceId`, or open the one folder you mean. |
|
|
13
|
+
| `WORKSPACE_NOT_REGISTERED` | The `workspaceId` is not in the configuration. Use `"current"`, or a workspace id from the configuration file. |
|
|
14
|
+
| Renders lack icons or fonts, native commands are unresolved | The game folder is not configured. Set `--game-root` (or `gameRoot`) to the Hearts of Iron IV folder; `hoi4-agent-tools-setup --discover` prints the folders it can find. |
|
|
15
|
+
| `ERROR_LOG_NOT_FOUND` | Launch the game once, or set `gameUserRoot` to the folder that holds `logs/`, `mod/` and `save games/` (with OneDrive that is often under `OneDrive\Documents`). |
|
|
16
|
+
| `AUTH_INVALID` over HTTP | The bearer token is missing, expired or for another server. See the [HTTP guide](http.md). |
|
|
17
|
+
| Startup or a call times out in the client | A cold scan of a large mod takes minutes. Raise the client's startup and tool timeouts (the printed Codex entries use 120 and 600 seconds), or use [background jobs](jobs.md). The stdio server answers the handshake and the tool list and loads no workspace until the first tool call needs one; that call waits for the loading, and a workspace checks its retained rewrite journals on its first use. A configuration or workspace error is written to stderr as `startup_failed`, and every call that needs a workspace fails with its code. |
|
|
18
|
+
| Many idle `node` processes | Some clients keep a server per subagent. Set `HOI4_AGENT_STDIO_IDLE_EXIT_MINUTES`; see [Server lifetime](setup.md#server-lifetime). |
|
|
19
19
|
|
|
20
20
|
## Arguments and results
|
|
21
21
|
|
|
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": "7129d97a7eca7ceeabc4f67bdb98e4a53f4fcb9ffb0ddf829f6f84aa56ab5e41",
|
|
8
|
+
"size": 12606080
|
|
9
9
|
},
|
|
10
10
|
"linux-arm64": {
|
|
11
11
|
"file": "linux-arm64/hoi4-engine",
|
|
12
|
-
"sha256": "
|
|
13
|
-
"size":
|
|
12
|
+
"sha256": "17f504a2da464c598fe4b1561910ed650eb00f52238d7fcc10cc6800a0bb7acc",
|
|
13
|
+
"size": 13723152
|
|
14
14
|
},
|
|
15
15
|
"linux-x64": {
|
|
16
16
|
"file": "linux-x64/hoi4-engine",
|
|
17
|
-
"sha256": "
|
|
18
|
-
"size":
|
|
17
|
+
"sha256": "ca4ed02d1e4686c7b1f193e7505dcdaf2e7095614e81e1e64a38c548e2b0ca36",
|
|
18
|
+
"size": 15286720
|
|
19
19
|
},
|
|
20
20
|
"win32-x64": {
|
|
21
21
|
"file": "win32-x64/hoi4-engine.exe",
|
|
22
|
-
"sha256": "
|
|
23
|
-
"size":
|
|
22
|
+
"sha256": "84cf6bfa9f6abaa6bcee4e157edb37881b71c2f9baa0cb99d15585b23a7872fe",
|
|
23
|
+
"size": 13414912
|
|
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.21.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.21.0",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@fontsource-variable/roboto": "5.3.0",
|