hoi4-agent-tools 4.20.3 → 4.22.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.
Files changed (140) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +2 -0
  3. package/dist/bin/setup.js +1 -0
  4. package/dist/bin/stdio.js +1 -0
  5. package/dist/hoi4_agent_tools/characters/write-operations.js +2 -2
  6. package/dist/hoi4_agent_tools/characters/write-plan.js +21 -205
  7. package/dist/hoi4_agent_tools/common-write/documented-lists.js +62 -0
  8. package/dist/hoi4_agent_tools/common-write/limits.js +35 -0
  9. package/dist/hoi4_agent_tools/common-write/paths.js +17 -0
  10. package/dist/hoi4_agent_tools/common-write/write-job-operations.js +42 -0
  11. package/dist/hoi4_agent_tools/common-write/write-operations.js +360 -0
  12. package/dist/hoi4_agent_tools/common-write/write-plan.js +34 -0
  13. package/dist/hoi4_agent_tools/core/artifacts-engine.js +272 -0
  14. package/dist/hoi4_agent_tools/core/configuration.js +6 -0
  15. package/dist/hoi4_agent_tools/core/domain-tools.js +8 -0
  16. package/dist/hoi4_agent_tools/core/engine.js +67 -21
  17. package/dist/hoi4_agent_tools/core/idle-cache-lifetime.js +7 -0
  18. package/dist/hoi4_agent_tools/core/job-controls.js +12 -2
  19. package/dist/hoi4_agent_tools/core/job-executor.js +8 -7
  20. package/dist/hoi4_agent_tools/core/job-operation-registration.js +4 -0
  21. package/dist/hoi4_agent_tools/core/job-store.js +97 -5
  22. package/dist/hoi4_agent_tools/core/job-worker-host.js +2 -2
  23. package/dist/hoi4_agent_tools/core/operation-result.js +118 -33
  24. package/dist/hoi4_agent_tools/core/operation-tasks.js +4 -2
  25. package/dist/hoi4_agent_tools/core/transactions.js +6 -0
  26. package/dist/hoi4_agent_tools/core/workspace.js +25 -2
  27. package/dist/hoi4_agent_tools/country/job-operations.js +42 -0
  28. package/dist/hoi4_agent_tools/country/write-operations.js +646 -0
  29. package/dist/hoi4_agent_tools/country/write-plan.js +28 -0
  30. package/dist/hoi4_agent_tools/decision/write-operations.js +7 -8
  31. package/dist/hoi4_agent_tools/decision/write-plan.js +25 -245
  32. package/dist/hoi4_agent_tools/doctrine/write-operations.js +2 -2
  33. package/dist/hoi4_agent_tools/doctrine/write-plan.js +21 -180
  34. package/dist/hoi4_agent_tools/event/graph.js +3 -3
  35. package/dist/hoi4_agent_tools/event/job-operations.js +2 -2
  36. package/dist/hoi4_agent_tools/event/write-job-operations.js +2 -2
  37. package/dist/hoi4_agent_tools/event/write-operations.js +9 -10
  38. package/dist/hoi4_agent_tools/event/write-plan.js +28 -278
  39. package/dist/hoi4_agent_tools/focus/job-operations.js +2 -2
  40. package/dist/hoi4_agent_tools/gui/assets.js +3 -13
  41. package/dist/hoi4_agent_tools/gui/job-operations.js +2 -2
  42. package/dist/hoi4_agent_tools/gui/layout.js +2 -4
  43. package/dist/hoi4_agent_tools/gui/renderer.js +2 -1
  44. package/dist/hoi4_agent_tools/gui/source-graph.js +16 -0
  45. package/dist/hoi4_agent_tools/gui/studio.js +31 -0
  46. package/dist/hoi4_agent_tools/ideas/write-operations.js +7 -8
  47. package/dist/hoi4_agent_tools/ideas/write-plan.js +24 -304
  48. package/dist/hoi4_agent_tools/map/engine-validation.js +230 -0
  49. package/dist/hoi4_agent_tools/map/job-operations.js +2 -2
  50. package/dist/hoi4_agent_tools/map/landmass-source.js +42 -0
  51. package/dist/hoi4_agent_tools/map/landmass.js +190 -0
  52. package/dist/hoi4_agent_tools/map/model.js +17 -3
  53. package/dist/hoi4_agent_tools/map/operations.js +20 -6
  54. package/dist/hoi4_agent_tools/map/references.js +6 -3
  55. package/dist/hoi4_agent_tools/map/service.js +88 -8
  56. package/dist/hoi4_agent_tools/map/validation.js +12 -18
  57. package/dist/hoi4_agent_tools/mcp/server/argument-errors.js +2 -0
  58. package/dist/hoi4_agent_tools/mcp/server/create-modern-operations.js +1 -1
  59. package/dist/hoi4_agent_tools/mcp/server/create.js +4 -0
  60. package/dist/hoi4_agent_tools/mcp/server/task-tool-catalog.js +4 -0
  61. package/dist/hoi4_agent_tools/mcp/tools/common-write.js +21 -0
  62. package/dist/hoi4_agent_tools/mcp/tools/country-write.js +21 -0
  63. package/dist/hoi4_agent_tools/mcp/tools/map.js +1 -1
  64. package/dist/hoi4_agent_tools/mcp/transports/http.js +2 -0
  65. package/dist/hoi4_agent_tools/mcp/transports/negotiated-stdio.js +24 -16
  66. package/dist/hoi4_agent_tools/probability/job-operations.js +2 -2
  67. package/dist/hoi4_agent_tools/runtime.js +83 -3
  68. package/dist/hoi4_agent_tools/schemas/character-write.js +5 -1
  69. package/dist/hoi4_agent_tools/schemas/common-write.js +74 -0
  70. package/dist/hoi4_agent_tools/schemas/country-write.js +206 -0
  71. package/dist/hoi4_agent_tools/schemas/decision-write.js +5 -1
  72. package/dist/hoi4_agent_tools/schemas/doctrine-write.js +5 -1
  73. package/dist/hoi4_agent_tools/schemas/event-write.js +5 -1
  74. package/dist/hoi4_agent_tools/schemas/idea-write.js +5 -1
  75. package/dist/hoi4_agent_tools/schemas/landmass.js +129 -0
  76. package/dist/hoi4_agent_tools/schemas/localisation-write.js +10 -1
  77. package/dist/hoi4_agent_tools/schemas/map-requests.js +1 -1
  78. package/dist/hoi4_agent_tools/schemas/map.js +2 -0
  79. package/dist/hoi4_agent_tools/schemas/tech-write.js +5 -1
  80. package/dist/hoi4_agent_tools/script-write/engine-plan.js +45 -0
  81. package/dist/hoi4_agent_tools/technology/engine-graph.js +156 -0
  82. package/dist/hoi4_agent_tools/technology/job-operations.js +2 -2
  83. package/dist/hoi4_agent_tools/technology/operations.js +1 -2
  84. package/dist/hoi4_agent_tools/technology/service.js +30 -59
  85. package/dist/hoi4_agent_tools/technology/write-job-operations.js +2 -2
  86. package/dist/hoi4_agent_tools/technology/write-operations.js +2 -2
  87. package/dist/hoi4_agent_tools/technology/write-plan.js +21 -207
  88. package/dist/hoi4_agent_tools/version.js +1 -1
  89. package/docs/configuration.md +11 -10
  90. package/docs/jobs.md +2 -2
  91. package/docs/setup.md +1 -0
  92. package/docs/tools.md +16 -2
  93. package/docs/troubleshooting.md +11 -11
  94. package/engine/bin/darwin-arm64/hoi4-engine +0 -0
  95. package/engine/bin/linux-arm64/hoi4-engine +0 -0
  96. package/engine/bin/linux-x64/hoi4-engine +0 -0
  97. package/engine/bin/manifest.json +8 -8
  98. package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
  99. package/npm-shrinkwrap.json +43 -19
  100. package/package.json +2 -2
  101. package/schemas/configuration.schema.json +143 -134
  102. package/schemas/continuous-focus-palette.schema.json +1 -1
  103. package/schemas/custom-weighted-pool.schema.json +1 -1
  104. package/schemas/decision-inspect-input.schema.json +1 -1
  105. package/schemas/error-log-input.schema.json +1 -1
  106. package/schemas/event-feature-manifest.schema.json +1 -1
  107. package/schemas/focus-plan.schema.json +1 -1
  108. package/schemas/focus-planning-sidecar.schema.json +1 -1
  109. package/schemas/geography-model.schema.json +1 -1
  110. package/schemas/gui-animation-source.schema.json +1 -1
  111. package/schemas/gui-helper.schema.json +1 -1
  112. package/schemas/gui-scenario.schema.json +1 -1
  113. package/schemas/helper-expansion-request.schema.json +1 -1
  114. package/schemas/helper-expansion-summary.schema.json +1 -1
  115. package/schemas/impact-inspect-input.schema.json +1 -1
  116. package/schemas/map-operation.schema.json +354 -1
  117. package/schemas/mechanic-test-input.schema.json +1 -1
  118. package/schemas/mod-index-input.schema.json +1 -1
  119. package/schemas/operation-result.schema.json +1 -1
  120. package/schemas/package-check-input.schema.json +1 -1
  121. package/schemas/package-manifest.schema.json +1 -1
  122. package/schemas/probability-analysis-result.schema.json +1 -1
  123. package/schemas/probability-compare-input.schema.json +1 -1
  124. package/schemas/probability-evaluate-input.schema.json +1 -1
  125. package/schemas/probability-inspect-input.schema.json +1 -1
  126. package/schemas/probability-render-input.schema.json +1 -1
  127. package/schemas/probability-scenario-set.schema.json +1 -1
  128. package/schemas/probability-sequence-input.schema.json +1 -1
  129. package/schemas/probability-simulate-input.schema.json +1 -1
  130. package/schemas/probability-sweep-input.schema.json +1 -1
  131. package/schemas/reference-context-input.schema.json +1 -1
  132. package/schemas/reference-read-input.schema.json +1 -1
  133. package/schemas/reference-search-input.schema.json +1 -1
  134. package/schemas/reference-sheets.schema.json +1 -1
  135. package/schemas/scenario-suite.schema.json +1 -1
  136. package/schemas/scenario-test-input.schema.json +1 -1
  137. package/schemas/script-validate-input.schema.json +1 -1
  138. package/schemas/shared-scenario.schema.json +1 -1
  139. package/schemas/source-lookup-input.schema.json +1 -1
  140. package/server.json +2 -2
@@ -1,3 +1,4 @@
1
+ import { realpathSync } from 'node:fs';
1
2
  import { lstat, mkdir, opendir, readFile, readdir, realpath } from 'node:fs/promises';
2
3
  import path from 'node:path';
3
4
  import { WORKSPACE_MAX_REGISTRATIONS, workspaceRegistrationSchema, } from './configuration.js';
@@ -389,6 +390,7 @@ export class WorkspaceResolver {
389
390
  #state = 'prepared';
390
391
  #population;
391
392
  #startupError;
393
+ #useHook;
392
394
  constructor(configuration) {
393
395
  this.configuration = configuration;
394
396
  }
@@ -503,6 +505,14 @@ export class WorkspaceResolver {
503
505
  : new ServiceError('INTERNAL_ERROR', error instanceof Error ? error.message : String(error));
504
506
  return this.#startupError;
505
507
  }
508
+ /**
509
+ * Run `hook` with the workspace's ID before each file access through this resolver
510
+ * (`refreshDescriptors`, `resolvePath`, `resolvePathInRoot`). The engine uses it to
511
+ * recover a workspace on its first use.
512
+ */
513
+ onWorkspaceUse(hook) {
514
+ this.#useHook = hook;
515
+ }
506
516
  /** The reason the server could not start, when it could not. */
507
517
  startupError() {
508
518
  return this.#startupError;
@@ -551,7 +561,16 @@ export class WorkspaceResolver {
551
561
  throw new ServiceError('WORKSPACE_CONTEXT_NOT_FOUND', 'No writable mod workspace is configured for the MCP server', workspaceCandidates(workspaces));
552
562
  }
553
563
  const currentDirectory = path.normalize(process.cwd());
554
- const containing = workspaces.filter((workspace) => isWithin(workspace.modRoot, currentDirectory));
564
+ // Workspace roots are canonical, so a symlink, junction or 8.3 name must be resolved too.
565
+ let canonicalDirectory = currentDirectory;
566
+ try {
567
+ canonicalDirectory = path.normalize(realpathSync.native(currentDirectory));
568
+ }
569
+ catch {
570
+ // A vanished working folder keeps its lexical form.
571
+ }
572
+ const containing = workspaces.filter((workspace) => isWithin(workspace.modRoot, currentDirectory) ||
573
+ isWithin(workspace.modRoot, canonicalDirectory));
555
574
  if (containing.length === 1)
556
575
  return containing[0].id;
557
576
  if (containing.length > 1) {
@@ -723,6 +742,7 @@ export class WorkspaceResolver {
723
742
  */
724
743
  async refreshDescriptors(workspaceId, principal) {
725
744
  const workspace = this.get(workspaceId, principal);
745
+ await this.#useHook?.(workspace.id);
726
746
  if (workspace.registration.kind === 'game')
727
747
  return;
728
748
  const dependencies = workspace.registration.dependencies;
@@ -809,13 +829,16 @@ export class WorkspaceResolver {
809
829
  * workspace lookup when it was TypeScript.
810
830
  */
811
831
  async getAfterPathCheck(workspaceId, relativePath, principal) {
832
+ let workspace;
812
833
  try {
813
- return this.get(workspaceId, principal);
834
+ workspace = this.get(workspaceId, principal);
814
835
  }
815
836
  catch (error) {
816
837
  await refuseUnsafeRelativePath(relativePath);
817
838
  throw error;
818
839
  }
840
+ await this.#useHook?.(workspace.id);
841
+ return workspace;
819
842
  }
820
843
  allowedWorkspaceIds(principal) {
821
844
  const token = this.configuration.http.tokens.find((entry) => entry.principal === principal);
@@ -0,0 +1,42 @@
1
+ import { z } from 'zod/v4';
2
+ import { toolResult } from '../core/operation-result.js';
3
+ import { ServiceError } from '../core/result.js';
4
+ import { countryWriteRequestSchema } from '../schemas/country-write.js';
5
+ import { completeCountryWrite, prepareCountryWrite, previewCountryWrite, } from './write-operations.js';
6
+ const wireResult = z.record(z.string(), z.json());
7
+ function wire(result) {
8
+ return wireResult.parse(JSON.parse(JSON.stringify(toolResult(result))));
9
+ }
10
+ /** Registers `hoi4.country_write`: a read-only preview, or one journaled transaction. */
11
+ export function registerCountryWriteJobs(operations, engine) {
12
+ operations.registerWrite('hoi4.country_write', countryWriteRequestSchema, async (input, context) => {
13
+ if (input.workspaceId !== 'current' && input.workspaceId !== context.workspaceId)
14
+ throw new ServiceError('JOB_ARGUMENT_SCOPE_MISMATCH', 'The request workspace does not match the authorized job workspace');
15
+ const operationContext = {
16
+ workspaceId: context.workspaceId,
17
+ ...(context.principal === undefined ? {} : { principal: context.principal }),
18
+ signal: context.signal,
19
+ progress: (completed, total, message) => context.progress({ completed, total, message }),
20
+ };
21
+ if (!input.apply)
22
+ return {
23
+ readOnlyPreview: wire(await previewCountryWrite(engine, input, operationContext)),
24
+ };
25
+ const prepared = await prepareCountryWrite(engine, input, operationContext);
26
+ if ('readOnlyPreview' in prepared)
27
+ return { readOnlyPreview: wire(prepared.readOnlyPreview) };
28
+ return { transaction: prepared.transaction, recipe: { ...prepared.recipe } };
29
+ }, async (_input, execution, _reconciled, recipe, context) => {
30
+ const result = completeCountryWrite(context.workspaceId, execution, recipe);
31
+ await context.progress({
32
+ completed: 3,
33
+ total: 3,
34
+ message: execution.outcome === 'applied'
35
+ ? 'Country change complete'
36
+ : execution.outcome === 'unchanged'
37
+ ? 'The country already matched the request'
38
+ : 'Country change blocked',
39
+ });
40
+ return wire(result);
41
+ });
42
+ }