hoi4-agent-tools 3.0.9 → 3.1.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 (124) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/README.md +4 -0
  3. package/dist/bin/stdio.js +23 -12
  4. package/dist/hoi4_agent_tools/core/analysis-checkpoints.js +82 -0
  5. package/dist/hoi4_agent_tools/core/artifact-resource.js +173 -0
  6. package/dist/hoi4_agent_tools/core/artifacts.js +84 -2
  7. package/dist/hoi4_agent_tools/core/dependency-pages.js +216 -0
  8. package/dist/hoi4_agent_tools/core/dependency-walk.js +266 -0
  9. package/dist/hoi4_agent_tools/core/domain-validation.js +188 -0
  10. package/dist/hoi4_agent_tools/core/engine.js +48 -5
  11. package/dist/hoi4_agent_tools/core/helper-expansion.js +186 -0
  12. package/dist/hoi4_agent_tools/core/index-segments.js +137 -0
  13. package/dist/hoi4_agent_tools/core/index.js +47 -4
  14. package/dist/hoi4_agent_tools/core/job-controls.js +109 -0
  15. package/dist/hoi4_agent_tools/core/job-executor.js +190 -0
  16. package/dist/hoi4_agent_tools/core/job-service.js +112 -0
  17. package/dist/hoi4_agent_tools/core/job-store.js +641 -0
  18. package/dist/hoi4_agent_tools/core/job-transactions.js +126 -0
  19. package/dist/hoi4_agent_tools/core/job-worker-host.js +200 -0
  20. package/dist/hoi4_agent_tools/core/job-worker.js +62 -0
  21. package/dist/hoi4_agent_tools/core/operation-context.js +31 -0
  22. package/dist/hoi4_agent_tools/core/operation-result.js +412 -0
  23. package/dist/hoi4_agent_tools/core/operation-tasks.js +382 -0
  24. package/dist/hoi4_agent_tools/core/persistent-analysis-cache.js +383 -0
  25. package/dist/hoi4_agent_tools/core/result.js +1 -0
  26. package/dist/hoi4_agent_tools/core/scanner.js +15 -75
  27. package/dist/hoi4_agent_tools/core/semantic-dependencies.js +233 -0
  28. package/dist/hoi4_agent_tools/core/shared-request-capacity.js +43 -11
  29. package/dist/hoi4_agent_tools/core/source/cache.js +107 -0
  30. package/dist/hoi4_agent_tools/core/source/parser.js +11 -1
  31. package/dist/hoi4_agent_tools/core/transaction-execution.js +134 -0
  32. package/dist/hoi4_agent_tools/core/transactions.js +80 -27
  33. package/dist/hoi4_agent_tools/event/graph.js +214 -290
  34. package/dist/hoi4_agent_tools/event/helper-expansion.js +33 -0
  35. package/dist/hoi4_agent_tools/event/job-operations.js +51 -0
  36. package/dist/hoi4_agent_tools/event/operations.js +179 -0
  37. package/dist/hoi4_agent_tools/event/service.js +67 -15
  38. package/dist/hoi4_agent_tools/event/source-analysis.js +5 -4
  39. package/dist/hoi4_agent_tools/focus/job-operations.js +77 -0
  40. package/dist/hoi4_agent_tools/focus/tool-operations.js +669 -0
  41. package/dist/hoi4_agent_tools/focus/tool-support.js +123 -0
  42. package/dist/hoi4_agent_tools/gui/job-operations.js +81 -0
  43. package/dist/hoi4_agent_tools/gui/tool-operations.js +270 -0
  44. package/dist/hoi4_agent_tools/map/job-operations.js +76 -0
  45. package/dist/hoi4_agent_tools/map/tool-operations.js +493 -0
  46. package/dist/hoi4_agent_tools/mcp/prompts/probability.js +25 -0
  47. package/dist/hoi4_agent_tools/mcp/prompts/register-modern.js +29 -0
  48. package/dist/hoi4_agent_tools/mcp/resources/register-modern.js +34 -0
  49. package/dist/hoi4_agent_tools/mcp/resources/register.js +4 -150
  50. package/dist/hoi4_agent_tools/mcp/server/base-tools.js +3 -219
  51. package/dist/hoi4_agent_tools/mcp/server/create-modern-operations.js +188 -0
  52. package/dist/hoi4_agent_tools/mcp/server/create.js +16 -6
  53. package/dist/hoi4_agent_tools/mcp/server/instructions.js +2 -0
  54. package/dist/hoi4_agent_tools/mcp/server/job-task-store.js +67 -0
  55. package/dist/hoi4_agent_tools/mcp/server/legacy-task-tools.js +20 -0
  56. package/dist/hoi4_agent_tools/mcp/server/modern-tasks.js +168 -0
  57. package/dist/hoi4_agent_tools/mcp/server/progress.js +17 -15
  58. package/dist/hoi4_agent_tools/mcp/server/request-lifecycle.js +43 -0
  59. package/dist/hoi4_agent_tools/mcp/server/result.js +2 -412
  60. package/dist/hoi4_agent_tools/mcp/server/task-request-context.js +9 -0
  61. package/dist/hoi4_agent_tools/mcp/server/task-tool-catalog.js +14 -0
  62. package/dist/hoi4_agent_tools/mcp/server/task-tool-definition.js +1 -0
  63. package/dist/hoi4_agent_tools/mcp/server/transaction-execution.js +1 -123
  64. package/dist/hoi4_agent_tools/mcp/tools/chaosx.js +38 -21
  65. package/dist/hoi4_agent_tools/mcp/tools/event.js +24 -315
  66. package/dist/hoi4_agent_tools/mcp/tools/focus.js +34 -1039
  67. package/dist/hoi4_agent_tools/mcp/tools/gui.js +19 -504
  68. package/dist/hoi4_agent_tools/mcp/tools/job.js +46 -0
  69. package/dist/hoi4_agent_tools/mcp/tools/map.js +21 -600
  70. package/dist/hoi4_agent_tools/mcp/tools/probability.js +39 -463
  71. package/dist/hoi4_agent_tools/mcp/tools/technology.js +40 -304
  72. package/dist/hoi4_agent_tools/mcp/transports/http.js +58 -1
  73. package/dist/hoi4_agent_tools/mcp/transports/modern-task-routing.js +109 -0
  74. package/dist/hoi4_agent_tools/mcp/transports/negotiated-stdio.js +121 -0
  75. package/dist/hoi4_agent_tools/probability/job-operations.js +58 -0
  76. package/dist/hoi4_agent_tools/probability/operations.js +183 -0
  77. package/dist/hoi4_agent_tools/probability/service.js +24 -3
  78. package/dist/hoi4_agent_tools/schemas/common.js +2 -0
  79. package/dist/hoi4_agent_tools/schemas/event.js +72 -1
  80. package/dist/hoi4_agent_tools/schemas/focus-requests.js +189 -0
  81. package/dist/hoi4_agent_tools/schemas/gui-requests.js +193 -0
  82. package/dist/hoi4_agent_tools/schemas/helper-expansion.js +58 -0
  83. package/dist/hoi4_agent_tools/schemas/map-requests.js +85 -0
  84. package/dist/hoi4_agent_tools/schemas/probability-requests.js +168 -0
  85. package/dist/hoi4_agent_tools/schemas/technology.js +90 -1
  86. package/dist/hoi4_agent_tools/schemas/transaction.js +1 -0
  87. package/dist/hoi4_agent_tools/technology/graph.js +83 -78
  88. package/dist/hoi4_agent_tools/technology/helper-expansion.js +33 -0
  89. package/dist/hoi4_agent_tools/technology/job-operations.js +60 -0
  90. package/dist/hoi4_agent_tools/technology/operations.js +125 -0
  91. package/dist/hoi4_agent_tools/technology/service.js +89 -15
  92. package/dist/hoi4_agent_tools/technology/source-analysis.js +2 -1
  93. package/dist/hoi4_agent_tools/version.js +1 -1
  94. package/docs/README.md +2 -0
  95. package/docs/development.md +2 -0
  96. package/docs/events.md +7 -2
  97. package/docs/helper-expansion.md +78 -0
  98. package/docs/http.md +2 -0
  99. package/docs/jobs.md +85 -0
  100. package/docs/technology.md +6 -2
  101. package/package.json +11 -5
  102. package/schemas/configuration.schema.json +1 -1
  103. package/schemas/continuous-focus-palette.schema.json +1 -1
  104. package/schemas/custom-weighted-pool.schema.json +1 -1
  105. package/schemas/event-feature-manifest.schema.json +1 -1
  106. package/schemas/focus-plan.schema.json +1 -1
  107. package/schemas/focus-planning-sidecar.schema.json +1 -1
  108. package/schemas/gui-animation-source.schema.json +1 -1
  109. package/schemas/gui-helper.schema.json +1 -1
  110. package/schemas/gui-scenario.schema.json +1 -1
  111. package/schemas/helper-expansion-request.schema.json +44 -0
  112. package/schemas/helper-expansion-summary.schema.json +70 -0
  113. package/schemas/map-operation.schema.json +1 -1
  114. package/schemas/operation-result.schema.json +1 -1
  115. package/schemas/probability-analysis-result.schema.json +1 -1
  116. package/schemas/probability-compare-input.schema.json +1 -1
  117. package/schemas/probability-evaluate-input.schema.json +1 -1
  118. package/schemas/probability-inspect-input.schema.json +1 -1
  119. package/schemas/probability-render-input.schema.json +1 -1
  120. package/schemas/probability-scenario-set.schema.json +1 -1
  121. package/schemas/probability-sequence-input.schema.json +1 -1
  122. package/schemas/probability-simulate-input.schema.json +1 -1
  123. package/schemas/probability-sweep-input.schema.json +1 -1
  124. package/server.json +2 -2
@@ -312,6 +312,7 @@ export class TransactionManager {
312
312
  diagnostics,
313
313
  validation: { passed, checks: validation.checks },
314
314
  artifacts,
315
+ executionArtifacts: [],
315
316
  appliedFiles: [],
316
317
  rollbackStatus: 'available',
317
318
  };
@@ -398,11 +399,17 @@ export class TransactionManager {
398
399
  }
399
400
  if (manifest.diagnostics.length + result.diagnostics.length > TRANSACTION_MAX_DIAGNOSTICS ||
400
401
  manifest.validation.checks.length + result.checks.length >
401
- TRANSACTION_MAX_VALIDATION_CHECKS) {
402
- throw new ServiceError('TRANSACTION_STRUCTURE_LIMIT', 'Post-write validation exceeds the supported transaction review structure limits');
402
+ TRANSACTION_MAX_VALIDATION_CHECKS ||
403
+ (manifest.executionArtifacts?.length ?? 0) + (result.artifacts?.length ?? 0) >
404
+ TRANSACTION_MAX_ARTIFACTS) {
405
+ throw new ServiceError('TRANSACTION_STRUCTURE_LIMIT', 'Post-write validation exceeds the supported transaction review or artifact limits');
403
406
  }
404
407
  manifest.diagnostics.push(...result.diagnostics);
405
408
  manifest.validation.checks.push(...result.checks);
409
+ manifest.executionArtifacts ??= [];
410
+ for (const artifact of result.artifacts ?? [])
411
+ if (!manifest.executionArtifacts.some(({ uri }) => uri === artifact.uri))
412
+ manifest.executionArtifacts.push(artifact);
406
413
  manifest.validation.passed =
407
414
  manifest.validation.passed &&
408
415
  result.checks.every(({ passed }) => passed) &&
@@ -513,6 +520,61 @@ export class TransactionManager {
513
520
  totalSize: cached.bytes.length,
514
521
  };
515
522
  }
523
+ /** Reconcile one interrupted job's journal without sweeping unrelated transactions. */
524
+ async recoverTransaction(workspaceId, transactionId, principal, signal) {
525
+ signal?.throwIfAborted();
526
+ const workspace = this.resolver.get(workspaceId, principal);
527
+ // Authenticate the selected journal and authorize its owner before changing protected state.
528
+ const initial = await this.load(workspace, transactionId, {
529
+ headMode: 'none',
530
+ ...(signal === undefined ? {} : { signal }),
531
+ });
532
+ this.assertRecoveryPrincipal(initial, principal);
533
+ return this.withWorkspaceLock(workspace, transactionId, async () => {
534
+ signal?.throwIfAborted();
535
+ // Never restore a pre-lock snapshot: a writer may have committed since the first read.
536
+ const current = await this.load(workspace, transactionId, {
537
+ headMode: 'none',
538
+ ...(signal === undefined ? {} : { signal }),
539
+ });
540
+ this.assertRecoveryPrincipal(current, principal);
541
+ const manifest = await this.load(workspace, transactionId, {
542
+ headMode: 'reconcile',
543
+ ...(signal === undefined ? {} : { signal }),
544
+ });
545
+ signal?.throwIfAborted();
546
+ if (manifest.state === 'applying' || manifest.state === 'rolling_back') {
547
+ await this.restoreInterruptedTransaction(workspace, manifest, principal);
548
+ }
549
+ return manifest;
550
+ });
551
+ }
552
+ assertRecoveryPrincipal(manifest, principal) {
553
+ if (principal !== undefined && (manifest.principal ?? null) !== principal) {
554
+ throw new ServiceError('TRANSACTION_PRINCIPAL_MISMATCH', 'Transaction recovery belongs to another principal');
555
+ }
556
+ }
557
+ async restoreInterruptedTransaction(workspace, manifest, principal) {
558
+ // Restoration and authenticated journal advancement are a non-cancellable critical phase.
559
+ try {
560
+ await this.restoreBeforeState(workspace, manifest, principal);
561
+ manifest.state = 'rolled_back';
562
+ manifest.failure = {
563
+ code: 'TRANSACTION_RECOVERED',
564
+ message: 'Incomplete transaction was rolled back during recovery',
565
+ };
566
+ await this.writeManifest(workspace, manifest);
567
+ }
568
+ catch (error) {
569
+ manifest.rollbackStatus = 'failed';
570
+ manifest.state = 'failed';
571
+ manifest.failure = this.safeFailure(error, 'TRANSACTION_RECOVERY_FAILED', 'Interrupted transaction could not be recovered safely');
572
+ await this.writeManifest(workspace, manifest);
573
+ if (error instanceof ServiceError)
574
+ throw error;
575
+ throw new ServiceError('TRANSACTION_RECOVERY_FAILED', 'Interrupted transaction could not be recovered safely');
576
+ }
577
+ }
516
578
  async recover(workspaceId, principal, signal) {
517
579
  signal?.throwIfAborted();
518
580
  const workspace = this.resolver.get(workspaceId, principal);
@@ -536,38 +598,29 @@ export class TransactionManager {
536
598
  if (!transactionIdPattern.test(entry.name))
537
599
  continue;
538
600
  const manifest = await this.load(workspace, entry.name, {
539
- headMode: 'reconcile',
601
+ headMode: 'none',
540
602
  ...(signal === undefined ? {} : { signal }),
541
603
  });
542
- if (principal !== undefined && (manifest.principal ?? null) !== principal) {
543
- throw new ServiceError('TRANSACTION_PRINCIPAL_MISMATCH', 'Transaction recovery belongs to another principal');
544
- }
545
- if (manifest.state !== 'applying' && manifest.state !== 'rolling_back')
546
- continue;
547
- await this.withWorkspaceLock(workspace, manifest.transactionId, async () => {
548
- signal?.throwIfAborted();
549
- // Once source restoration starts, recovery and authenticated journal
550
- // advancement form a non-cancellable critical phase.
604
+ this.assertRecoveryPrincipal(manifest, principal);
605
+ const interrupted = manifest.state === 'applying' || manifest.state === 'rolling_back';
606
+ if (!interrupted) {
551
607
  try {
552
- await this.restoreBeforeState(workspace, manifest, principal);
553
- manifest.state = 'rolled_back';
554
- manifest.failure = {
555
- code: 'TRANSACTION_RECOVERED',
556
- message: 'Incomplete transaction was rolled back during recovery',
557
- };
558
- await this.writeManifest(workspace, manifest);
608
+ // Ordinary startup must not contend with a live writer just to read terminal journals.
609
+ await this.load(workspace, entry.name, {
610
+ ...(signal === undefined ? {} : { signal }),
611
+ });
612
+ continue;
559
613
  }
560
614
  catch (error) {
561
- manifest.rollbackStatus = 'failed';
562
- manifest.state = 'failed';
563
- manifest.failure = this.safeFailure(error, 'TRANSACTION_RECOVERY_FAILED', 'Interrupted transaction could not be recovered safely');
564
- await this.writeManifest(workspace, manifest);
565
- if (error instanceof ServiceError)
615
+ if (!(error instanceof ServiceError) ||
616
+ error.code !== 'TRANSACTION_HEAD_RECONCILIATION_REQUIRED')
566
617
  throw error;
567
- throw new ServiceError('TRANSACTION_RECOVERY_FAILED', 'Interrupted transaction could not be recovered safely');
568
618
  }
569
- });
570
- recovered.push(manifest);
619
+ }
620
+ const reconciled = await this.recoverTransaction(workspaceId, entry.name, principal, signal);
621
+ if (interrupted) {
622
+ recovered.push(reconciled);
623
+ }
571
624
  }
572
625
  return recovered;
573
626
  }