@codemation/host 0.6.0 → 0.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.
Files changed (223) hide show
  1. package/CHANGELOG.md +431 -0
  2. package/LICENSE +1 -37
  3. package/dist/{ApiPaths-CLTHphYZ.js → ApiPaths-Dv1dcHu_.js} +4 -4
  4. package/dist/ApiPaths-Dv1dcHu_.js.map +1 -0
  5. package/dist/{AppConfigFactory-C6q-CSKb.js → AppConfigFactory-Cx4qQvRk.js} +112 -52
  6. package/dist/AppConfigFactory-Cx4qQvRk.js.map +1 -0
  7. package/dist/{AppConfigFactory-YnveXE9k.d.ts → AppConfigFactory-DnLoQ9Li.d.ts} +8490 -5548
  8. package/dist/{AppContainerFactory-qaqc-R1D.js → AppContainerFactory-DqKYCRNP.js} +7641 -2083
  9. package/dist/AppContainerFactory-DqKYCRNP.js.map +1 -0
  10. package/dist/{CodemationAppContext-DRu1Dpri.d.ts → CodemationAppContext-CKVv9W9q.d.ts} +8 -4
  11. package/dist/{CodemationAuthoring.types-fBRppnmi.d.ts → CodemationAuthoring.types-DA3G3s6d.d.ts} +25 -5
  12. package/dist/{CodemationAuthoring.types-DZl-sJaM.js → CodemationAuthoring.types-NGkBcmmT.js} +18 -6
  13. package/dist/CodemationAuthoring.types-NGkBcmmT.js.map +1 -0
  14. package/dist/{CodemationConfigNormalizer-DVko3cVN.d.ts → CodemationConfigNormalizer-BAKjetJ6.d.ts} +3 -3
  15. package/dist/{CodemationConsumerConfigLoader-BeAUS144.js → CodemationConsumerConfigLoader-GYpBBvqE.js} +79 -10
  16. package/dist/CodemationConsumerConfigLoader-GYpBBvqE.js.map +1 -0
  17. package/dist/{CodemationConsumerConfigLoader-DJWr86f-.d.ts → CodemationConsumerConfigLoader-nxOqvv46.d.ts} +17 -2
  18. package/dist/{CodemationPluginListMerger-B-W5Fa_X.js → CodemationPluginListMerger-D1B1IEbt.js} +1 -1
  19. package/dist/{CodemationPluginListMerger-B-W5Fa_X.js.map → CodemationPluginListMerger-D1B1IEbt.js.map} +1 -1
  20. package/dist/{CodemationPluginListMerger-DGc-jfa2.d.ts → CodemationPluginListMerger-DKLAHT2b.d.ts} +123 -16
  21. package/dist/CodemationTsyringeTypeInfoRegistrar-Bj6FJYFz.js +97 -0
  22. package/dist/CodemationTsyringeTypeInfoRegistrar-Bj6FJYFz.js.map +1 -0
  23. package/dist/{CodemationWhitelabelConfig-CWbcyQqn.d.ts → CodemationWhitelabelConfig-Ca2mCUeC.d.ts} +2 -2
  24. package/dist/{CollectionContracts.types-DdpHft0i.d.ts → CollectionContracts.types-DDyFYT_D.d.ts} +1 -1
  25. package/dist/{CredentialContractsRegistry-DrMIDSw8.d.ts → CredentialContractsRegistry-Bq2bq28t.d.ts} +2 -2
  26. package/dist/{CredentialServices-UfvHB-rN.d.ts → CredentialServices-Be2I60Th.d.ts} +65 -20
  27. package/dist/{CredentialServices-CgxwguAv.js → CredentialServices-Dk8yypeL.js} +310 -51
  28. package/dist/CredentialServices-Dk8yypeL.js.map +1 -0
  29. package/dist/InternalHonoApiRouteRegistrar-Ce1yxpnO.d.ts +17 -0
  30. package/dist/InternalPingRegistrar-DY3kSfxP.js +221 -0
  31. package/dist/InternalPingRegistrar-DY3kSfxP.js.map +1 -0
  32. package/dist/{ItemsInputNormalizer-C-KHg9Mo.d.ts → ItemsInputNormalizer-_RwIfRIQ.d.ts} +89 -25
  33. package/dist/{LogLevelPolicyFactory-CampWO0l.d.ts → LogLevelPolicyFactory-ewCHLDLn.d.ts} +2 -2
  34. package/dist/{PublicFrontendBootstrap-DzBgwOnG.d.ts → PublicFrontendBootstrap-Cev3qK46.d.ts} +9 -2
  35. package/dist/PublicFrontendBootstrapFactory-CY2FS-5g.d.ts +82 -0
  36. package/dist/{PublicFrontendBootstrapJsonCodec-Cl_DLRh0.d.ts → PublicFrontendBootstrapJsonCodec-CXG9Dxft.d.ts} +3 -3
  37. package/dist/{PublicFrontendBootstrapJsonCodec-DzqvA0uo.js → PublicFrontendBootstrapJsonCodec-CegIF_ne.js} +7 -2
  38. package/dist/PublicFrontendBootstrapJsonCodec-CegIF_ne.js.map +1 -0
  39. package/dist/ServerLoggerFactory-Ckk52S3w.js +223 -0
  40. package/dist/ServerLoggerFactory-Ckk52S3w.js.map +1 -0
  41. package/dist/{TelemetryContracts-DbaNomrH.d.ts → TelemetryContracts-BtDx84Cp.d.ts} +13 -4
  42. package/dist/{WorkflowPolicyUiPresentationFactory-DQEY-h_S.d.ts → WorkflowPolicyUiPresentationFactory-6MyjCvBO.d.ts} +2 -2
  43. package/dist/{WorkflowPolicyUiPresentationFactory-DhPqQ9aB.js → WorkflowPolicyUiPresentationFactory-Bb-ae_Zh.js} +1 -1
  44. package/dist/{WorkflowPolicyUiPresentationFactory-DhPqQ9aB.js.map → WorkflowPolicyUiPresentationFactory-Bb-ae_Zh.js.map} +1 -1
  45. package/dist/{WorkflowViewContracts-CzK2KFuz.d.ts → WorkflowViewContracts-B7aFQcIw.d.ts} +10 -1
  46. package/dist/authoring.d.ts +5 -5
  47. package/dist/authoring.js +1 -1
  48. package/dist/client.d.ts +4 -4
  49. package/dist/client.js +2 -2
  50. package/dist/consumer.d.ts +6 -6
  51. package/dist/consumer.js +2 -2
  52. package/dist/credentials.d.ts +6 -6
  53. package/dist/credentials.js +1 -1
  54. package/dist/devServerSidecar.d.ts +2 -2
  55. package/dist/devServerSidecar.js +1 -94
  56. package/dist/devServerSidecar.js.map +1 -1
  57. package/dist/dto.d.ts +6 -6
  58. package/dist/{index-BbBk26m0.d.ts → index-DilAYwnH.d.ts} +49 -3
  59. package/dist/index.d.ts +110 -21
  60. package/dist/index.js +15 -13
  61. package/dist/mapping.d.ts +2 -2
  62. package/dist/mapping.js +1 -1
  63. package/dist/nextServer.d.ts +43 -88
  64. package/dist/nextServer.js +9 -7
  65. package/dist/pairing.d.ts +93 -0
  66. package/dist/pairing.js +5 -0
  67. package/dist/pairing.types-snfZ_OzB.d.ts +19 -0
  68. package/dist/{persistenceServer-CmsIKnO9.js → persistenceServer-C-hH4z6l.js} +2 -2
  69. package/dist/{persistenceServer-CmsIKnO9.js.map → persistenceServer-C-hH4z6l.js.map} +1 -1
  70. package/dist/persistenceServer-CeTHtC6E.d.ts +30 -0
  71. package/dist/persistenceServer.d.ts +8 -8
  72. package/dist/persistenceServer.js +3 -3
  73. package/dist/{server-MUNGsBYK.d.ts → server-C4bS62rg.d.ts} +21 -6
  74. package/dist/{server-CJFfY67o.js → server-Y7kxwtCK.js} +7 -6
  75. package/dist/{server-CJFfY67o.js.map → server-Y7kxwtCK.js.map} +1 -1
  76. package/dist/server.d.ts +14 -14
  77. package/dist/server.js +13 -11
  78. package/package.json +29 -42
  79. package/prisma/migrations/20260519000000_workflow_audit_log/migration.sql +23 -0
  80. package/prisma/migrations/20260519100000_storage_growth_fixes/migration.sql +61 -0
  81. package/prisma/migrations.sqlite/20260519000000_workflow_audit_log/migration.sql +21 -0
  82. package/prisma/migrations.sqlite/20260519100000_storage_growth_fixes/migration.sql +29 -0
  83. package/prisma/schema.postgresql.prisma +55 -17
  84. package/prisma/schema.sqlite.prisma +55 -17
  85. package/prisma-generated/prisma-postgresql-client/edge.js +33 -5
  86. package/prisma-generated/prisma-postgresql-client/index-browser.js +29 -1
  87. package/prisma-generated/prisma-postgresql-client/index.d.ts +8933 -5716
  88. package/prisma-generated/prisma-postgresql-client/index.js +33 -5
  89. package/prisma-generated/prisma-postgresql-client/package.json +1 -1
  90. package/prisma-generated/prisma-postgresql-client/schema.prisma +38 -0
  91. package/prisma-generated/prisma-sqlite-client/edge.js +33 -5
  92. package/prisma-generated/prisma-sqlite-client/index-browser.js +29 -1
  93. package/prisma-generated/prisma-sqlite-client/index.d.ts +8925 -5713
  94. package/prisma-generated/prisma-sqlite-client/index.js +33 -5
  95. package/prisma-generated/prisma-sqlite-client/package.json +1 -1
  96. package/prisma-generated/prisma-sqlite-client/schema.prisma +38 -0
  97. package/scripts/check-collections.mjs +18 -0
  98. package/scripts/generate-prisma-clients.mjs +20 -11
  99. package/src/application/WorkflowAuditLogPruneScheduler.ts +96 -0
  100. package/src/application/auth/AuthenticatedPrincipal.ts +4 -0
  101. package/src/application/commands/StartWorkflowRunCommandHandler.ts +4 -0
  102. package/src/application/contracts/WorkflowViewContracts.ts +6 -0
  103. package/src/application/contracts/WorkflowWebsocketMessage.ts +3 -1
  104. package/src/application/mapping/WorkflowDefinitionMapper.ts +40 -1
  105. package/src/application/runs/WorkflowRunRetentionPruneScheduler.ts +7 -1
  106. package/src/application/telemetry/OtelExecutionTelemetry.types.ts +5 -0
  107. package/src/application/telemetry/OtelExecutionTelemetryFactory.ts +4 -0
  108. package/src/application/telemetry/StoredTelemetrySpanScope.ts +6 -2
  109. package/src/application/telemetry/TelemetryRetentionTimestampFactory.ts +27 -17
  110. package/src/application/telemetry/TelemetrySpanPublisher.ts +11 -0
  111. package/src/application/websocket/TelemetrySpanWebsocketRelay.ts +31 -0
  112. package/src/applicationTokens.ts +20 -1
  113. package/src/audit/IAuditEmitter.ts +32 -0
  114. package/src/audit/PrismaWorkflowAuditLogRepository.ts +34 -0
  115. package/src/audit/WorkflowAuditLogWriter.ts +125 -0
  116. package/src/auth/managed/ManagedAuthConfig.ts +29 -0
  117. package/src/auth/managed/ManagedAuthMiddleware.ts +52 -0
  118. package/src/auth/managed/ManagedCorsMiddleware.ts +43 -0
  119. package/src/auth/managed/ManagedModeBootGuard.ts +27 -0
  120. package/src/auth/managed/index.ts +5 -0
  121. package/src/bootstrap/AppContainerFactory.ts +277 -29
  122. package/src/bootstrap/AppContainerLifecycle.ts +31 -0
  123. package/src/bootstrap/perf/BootTimer.ts +168 -0
  124. package/src/bootstrap/runtime/AppConfigFactory.ts +21 -65
  125. package/src/bootstrap/runtime/FrontendRuntime.ts +4 -1
  126. package/src/bootstrap/runtime/WorkerRuntime.ts +2 -1
  127. package/src/credentials/BrokerClient.ts +49 -0
  128. package/src/credentials/BrokerRefreshError.ts +12 -0
  129. package/src/credentials/BrokerRefreshInvalidGrantError.ts +13 -0
  130. package/src/credentials/ControlPlaneCatalogFetcher.ts +261 -0
  131. package/src/credentials/CredentialOAuth2MaterialReader.ts +136 -0
  132. package/src/credentials/InternalCredentialsListRegistrar.ts +48 -0
  133. package/src/credentials/InternalCredentialsPushRegistrar.ts +125 -0
  134. package/src/credentials/LocalOAuthFlowExecutor.ts +316 -0
  135. package/src/credentials/ManagedOAuthFlowExecutor.ts +94 -0
  136. package/src/credentials/ManagedOAuthRefreshInvalidGrantError.ts +13 -0
  137. package/src/credentials/catalogTypes.ts +4 -0
  138. package/src/credentials/refresh/CredentialDisconnectedError.ts +11 -0
  139. package/src/domain/credentials/CredentialBindingService.ts +54 -2
  140. package/src/domain/credentials/CredentialKeyRotatedError.ts +22 -0
  141. package/src/domain/credentials/CredentialSecretCipher.ts +68 -6
  142. package/src/domain/credentials/CredentialTypeRegistryImpl.ts +117 -10
  143. package/src/domain/credentials/OAuth2RedirectUriResolver.ts +79 -0
  144. package/src/domain/credentials/WorkflowCredentialNodeResolver.ts +14 -5
  145. package/src/domain/telemetry/TelemetryContracts.ts +7 -1
  146. package/src/domain/workflows/WorkflowActivationPreflight.ts +24 -1
  147. package/src/domain/workflows/WorkflowActivationPreflightRules.ts +40 -1
  148. package/src/index.ts +6 -0
  149. package/src/infrastructure/binary/LocalFilesystemBinaryStorageRegistry.ts +29 -1
  150. package/src/infrastructure/binary/S3BinaryStorage.ts +169 -0
  151. package/src/infrastructure/binary/S3BinaryStorageConfig.ts +17 -0
  152. package/src/infrastructure/config/CodemationPluginRegistrar.ts +3 -1
  153. package/src/infrastructure/persistence/CodemationDatabaseUrlParser.ts +41 -0
  154. package/src/infrastructure/persistence/InMemoryTelemetryArtifactStore.ts +8 -3
  155. package/src/infrastructure/persistence/PrismaMigrationDeployer.ts +21 -13
  156. package/src/infrastructure/persistence/PrismaTelemetryArtifactStore.ts +43 -8
  157. package/src/infrastructure/persistence/PrismaWorkflowRunRepository.ts +26 -3
  158. package/src/infrastructure/persistence/PrismaWorkflowSnapshotRepository.ts +48 -0
  159. package/src/mcp/AgentMcpIntegrationImpl.ts +344 -0
  160. package/src/mcp/McpClientFactory.ts +29 -0
  161. package/src/mcp/McpConnectionPool.ts +184 -0
  162. package/src/mcp/McpConnectionPool.types.ts +12 -0
  163. package/src/mcp/McpServerCatalog.ts +104 -0
  164. package/src/mcp/index.ts +5 -0
  165. package/src/pairing/HmacRequestSigner.ts +32 -0
  166. package/src/pairing/IncomingHmacVerifier.ts +82 -0
  167. package/src/pairing/InternalHmacAuthMiddleware.ts +33 -0
  168. package/src/pairing/InternalPingRegistrar.ts +25 -0
  169. package/src/pairing/PairedFetch.ts +33 -0
  170. package/src/pairing/PairingConfigFactory.ts +35 -0
  171. package/src/pairing/PairingConfigToken.ts +6 -0
  172. package/src/pairing/index.ts +14 -0
  173. package/src/pairing/pairing.types.ts +18 -0
  174. package/src/pairing.ts +17 -0
  175. package/src/persistenceServer.ts +1 -0
  176. package/src/presentation/config/AppConfig.ts +7 -1
  177. package/src/presentation/config/CodemationAuthConfig.ts +1 -1
  178. package/src/presentation/config/CodemationAuthoring.types.ts +54 -5
  179. package/src/presentation/config/CodemationConfig.ts +3 -0
  180. package/src/presentation/config/CodemationConfigNormalizer.ts +39 -1
  181. package/src/presentation/config/CodemationPlugin.ts +2 -1
  182. package/src/presentation/frontend/CodemationFrontendAuthSnapshot.ts +5 -0
  183. package/src/presentation/frontend/CodemationFrontendAuthSnapshotFactory.ts +7 -1
  184. package/src/presentation/frontend/PublicFrontendBootstrap.ts +2 -0
  185. package/src/presentation/frontend/PublicFrontendBootstrapFactory.ts +5 -1
  186. package/src/presentation/frontend/PublicFrontendBootstrapJsonCodec.ts +4 -1
  187. package/src/presentation/http/ApiPaths.ts +4 -4
  188. package/src/presentation/http/ServerHttpErrorResponseFactory.ts +39 -2
  189. package/src/presentation/http/hono/CodemationHonoApiAppFactory.ts +33 -8
  190. package/src/presentation/http/hono/InternalHonoApiRouteRegistrar.ts +12 -0
  191. package/src/presentation/http/hono/registrars/ManagedMeHonoApiRouteRegistrar.ts +35 -0
  192. package/src/presentation/http/hono/registrars/OAuth2HonoApiRouteRegistrar.ts +2 -2
  193. package/src/presentation/http/routeHandlers/CredentialHttpRouteHandler.ts +28 -0
  194. package/src/presentation/http/routeHandlers/OAuth2HttpRouteHandlerFactory.ts +98 -41
  195. package/src/presentation/server/CodemationConsumerConfigLoader.ts +54 -7
  196. package/src/presentation/server/CodemationPluginDiscovery.ts +5 -0
  197. package/src/presentation/server/WorkflowDefinitionExportsResolver.ts +18 -0
  198. package/src/presentation/server/WorkflowModulePathFinder.ts +12 -1
  199. package/src/presentation/websocket/ManagedWebsocketAuthenticator.ts +50 -0
  200. package/src/presentation/websocket/WebsocketAuthenticator.types.ts +12 -0
  201. package/src/presentation/websocket/WorkflowWebsocketServer.ts +24 -3
  202. package/src/process/ExecaProcessRunner.ts +41 -0
  203. package/src/process/ProcessRunner.types.ts +39 -0
  204. package/src/server.ts +2 -0
  205. package/src/workflows/InternalWorkflowActivationRegistrar.ts +42 -0
  206. package/src/workflows/InternalWorkflowDetailRegistrar.ts +33 -0
  207. package/src/workflows/InternalWorkflowTestRunRegistrar.ts +91 -0
  208. package/src/workflows/InternalWorkflowsListRegistrar.ts +28 -0
  209. package/src/workflows/discovery/WorkflowDirectoryDiscoverer.ts +79 -0
  210. package/tsconfig.json +2 -0
  211. package/vitest.shared.ts +5 -0
  212. package/dist/ApiPaths-CLTHphYZ.js.map +0 -1
  213. package/dist/AppConfigFactory-C6q-CSKb.js.map +0 -1
  214. package/dist/AppContainerFactory-qaqc-R1D.js.map +0 -1
  215. package/dist/CodemationAuthoring.types-DZl-sJaM.js.map +0 -1
  216. package/dist/CodemationConsumerConfigLoader-BeAUS144.js.map +0 -1
  217. package/dist/CredentialServices-CgxwguAv.js.map +0 -1
  218. package/dist/PublicFrontendBootstrapFactory-Cb2pLmDd.d.ts +0 -45
  219. package/dist/PublicFrontendBootstrapJsonCodec-DzqvA0uo.js.map +0 -1
  220. package/dist/ServerLoggerFactory-BKSIh9Xv.js +0 -98
  221. package/dist/ServerLoggerFactory-BKSIh9Xv.js.map +0 -1
  222. package/dist/persistenceServer-vtJAGDat.d.ts +0 -9
  223. package/src/domain/credentials/OAuth2ConnectServiceFactory.ts +0 -411
@@ -6,6 +6,7 @@ import type { NamespacedUnregister } from "tsx/esm/api";
6
6
  import type { CodemationConfig } from "../config/CodemationConfig";
7
7
  import { CodemationConfigNormalizer } from "../config/CodemationConfigNormalizer";
8
8
  import type { NormalizedCodemationConfig } from "../config/CodemationConfigNormalizer";
9
+ import { BootTimer } from "../../bootstrap/perf/BootTimer";
9
10
  import { logLevelPolicyFactory } from "../../infrastructure/logging/LogLevelPolicyFactory";
10
11
  import { ServerLoggerFactory } from "../../infrastructure/logging/ServerLoggerFactory";
11
12
  import { DiscoveredWorkflowsEmptyMessageFactory } from "./DiscoveredWorkflowsEmptyMessageFactory";
@@ -37,9 +38,45 @@ export class CodemationConsumerConfigLoader {
37
38
  private readonly performanceDiagnosticsLogger = new ServerLoggerFactory(
38
39
  logLevelPolicyFactory,
39
40
  ).createPerformanceDiagnostics("codemation-config-loader.timing");
41
+ /**
42
+ * In-flight + completed load promises keyed by `${consumerRoot}|${configPathOverride}`. The
43
+ * boot path constructs MULTIPLE CodemationConsumerConfigLoader instances (one inside the CLI's
44
+ * DatabaseMigrationsApplyService, another inside NextHostEdgeSeedLoader, another inside
45
+ * AppConfigLoader for the disposable runtime) and each independently calls `load(...)`. Without
46
+ * a cache shared across instances, the same `${consumerRoot}` ends up importing
47
+ * codemation.config.ts + discovered workflow modules ~3 times for a single dev boot. The cache
48
+ * has to be static so it spans every loader instance in the process.
49
+ *
50
+ * Callers MUST invoke `invalidateAll()` on a source-change reload — the dev source watcher
51
+ * already tears the runtime down and reboots; it just needs to clear this map first.
52
+ */
53
+ private static readonly resolutionCache = new Map<string, Promise<CodemationConsumerConfigResolution>>();
54
+
55
+ static invalidateAll(): void {
56
+ this.resolutionCache.clear();
57
+ }
40
58
 
41
59
  async load(
42
60
  args: Readonly<{ consumerRoot: string; configPathOverride?: string }>,
61
+ ): Promise<CodemationConsumerConfigResolution> {
62
+ const cacheKey = `${args.consumerRoot}|${args.configPathOverride ?? ""}`;
63
+ const cached = CodemationConsumerConfigLoader.resolutionCache.get(cacheKey);
64
+ if (cached) {
65
+ return cached;
66
+ }
67
+ const promise = this.loadUncached(args);
68
+ CodemationConsumerConfigLoader.resolutionCache.set(cacheKey, promise);
69
+ try {
70
+ return await promise;
71
+ } catch (error) {
72
+ // A failed load shouldn't poison the cache — future retries should re-attempt.
73
+ CodemationConsumerConfigLoader.resolutionCache.delete(cacheKey);
74
+ throw error;
75
+ }
76
+ }
77
+
78
+ private async loadUncached(
79
+ args: Readonly<{ consumerRoot: string; configPathOverride?: string }>,
43
80
  ): Promise<CodemationConsumerConfigResolution> {
44
81
  const loadStarted = performance.now();
45
82
  let mark = loadStarted;
@@ -54,25 +91,33 @@ export class CodemationConsumerConfigLoader {
54
91
  `load.${label} +${delta.toFixed(1)}ms (cumulative ${(now - loadStarted).toFixed(1)}ms)`,
55
92
  );
56
93
  };
57
- const bootstrapSource = await this.resolveConfigPath(args.consumerRoot, args.configPathOverride);
94
+ const bootstrapSource = await BootTimer.measureAsync("config.resolveConfigPath", () =>
95
+ this.resolveConfigPath(args.consumerRoot, args.configPathOverride),
96
+ );
58
97
  phaseMs("resolveConfigPath");
59
98
  if (!bootstrapSource) {
60
99
  throw new Error(
61
100
  'Codemation config not found. Expected "codemation.config.ts" in the consumer project root or "src/".',
62
101
  );
63
102
  }
64
- const moduleExports = await this.importModule(bootstrapSource, importSession);
103
+ const moduleExports = await BootTimer.measureAsync("config.importConfigModule", () =>
104
+ this.importModule(bootstrapSource, importSession),
105
+ );
65
106
  phaseMs("importConfigModule");
66
107
  const rawConfig = this.configExportsResolver.resolveConfig(moduleExports);
67
108
  if (!rawConfig) {
68
109
  throw new Error(`Config file does not export a Codemation config object: ${bootstrapSource}`);
69
110
  }
70
111
  const config = this.configNormalizer.normalize(rawConfig);
71
- const workflowSources = await this.resolveWorkflowSources(args.consumerRoot, config);
112
+ const workflowSources = await BootTimer.measureAsync("config.resolveWorkflowSources", () =>
113
+ this.resolveWorkflowSources(args.consumerRoot, config),
114
+ );
72
115
  phaseMs("resolveWorkflowSources");
73
- const workflows = this.mergeWorkflows(
74
- config.workflows ?? [],
75
- await this.loadDiscoveredWorkflows(args.consumerRoot, config, workflowSources, importSession),
116
+ const workflows = await BootTimer.measureAsync("config.loadDiscoveredWorkflows", async () =>
117
+ this.mergeWorkflows(
118
+ config.workflows ?? [],
119
+ await this.loadDiscoveredWorkflows(args.consumerRoot, config, workflowSources, importSession),
120
+ ),
76
121
  );
77
122
  phaseMs("loadDiscoveredWorkflows");
78
123
  const resolvedConfig: NormalizedCodemationConfig = {
@@ -145,7 +190,9 @@ export class CodemationConsumerConfigLoader {
145
190
  workflowDiscoveryDirectories,
146
191
  absoluteWorkflowModulePath: workflowSource,
147
192
  }),
148
- moduleExports: await this.importModule(workflowSource, importSession),
193
+ moduleExports: await BootTimer.measureAsync(`workflow.${path.basename(workflowSource).replace(/\.tsx?$/, "")}`, () =>
194
+ this.importModule(workflowSource, importSession),
195
+ ),
149
196
  })),
150
197
  );
151
198
  for (const loadedWorkflowModule of loadedWorkflowModules) {
@@ -124,6 +124,7 @@ export class CodemationPluginDiscovery {
124
124
  }
125
125
  const pluginValue = value as {
126
126
  credentialTypes?: unknown;
127
+ mcpServers?: unknown;
127
128
  register?: unknown;
128
129
  sandbox?: unknown;
129
130
  };
@@ -133,9 +134,13 @@ export class CodemationPluginDiscovery {
133
134
  if (pluginValue.credentialTypes !== undefined && !Array.isArray(pluginValue.credentialTypes)) {
134
135
  return false;
135
136
  }
137
+ if (pluginValue.mcpServers !== undefined && !Array.isArray(pluginValue.mcpServers)) {
138
+ return false;
139
+ }
136
140
  return (
137
141
  pluginValue.register !== undefined ||
138
142
  pluginValue.credentialTypes !== undefined ||
143
+ pluginValue.mcpServers !== undefined ||
139
144
  pluginValue.sandbox !== undefined ||
140
145
  Object.keys(pluginValue).length === 0
141
146
  );
@@ -1,20 +1,38 @@
1
1
  import type { WorkflowDefinition } from "@codemation/core";
2
+ import { WorkflowEdgePortValidator } from "@codemation/core";
2
3
 
3
4
  /**
4
5
  * Collects exported values that match the {@link WorkflowDefinition} shape.
5
6
  * Other exports (helpers, constants, type-only re-exports) are ignored.
7
+ *
8
+ * Throws if any workflow's edges reference output ports not declared by the
9
+ * source node config. All violations are reported at once so an agent can
10
+ * self-correct in a single pass.
6
11
  */
7
12
  export class WorkflowDefinitionExportsResolver {
13
+ private readonly portValidator = new WorkflowEdgePortValidator();
14
+
8
15
  resolve(moduleExports: Readonly<Record<string, unknown>>): ReadonlyArray<WorkflowDefinition> {
9
16
  const workflows: WorkflowDefinition[] = [];
10
17
  for (const exportedValue of Object.values(moduleExports)) {
11
18
  if (this.isWorkflowDefinition(exportedValue)) {
19
+ this.validatePorts(exportedValue);
12
20
  workflows.push(exportedValue);
13
21
  }
14
22
  }
15
23
  return workflows;
16
24
  }
17
25
 
26
+ private validatePorts(workflow: WorkflowDefinition): void {
27
+ const result = this.portValidator.validate(workflow);
28
+ if (!result.valid) {
29
+ const lines = result.errors.map((e) => ` - ${e.message}`).join("\n");
30
+ throw new Error(
31
+ `Workflow "${workflow.id}" ("${workflow.name}") has ${result.errors.length} invalid edge port(s):\n${lines}`,
32
+ );
33
+ }
34
+ }
35
+
18
36
  private isWorkflowDefinition(value: unknown): value is WorkflowDefinition {
19
37
  if (!value || typeof value !== "object") {
20
38
  return false;
@@ -42,6 +42,17 @@ export class WorkflowModulePathFinder {
42
42
 
43
43
  private isWorkflowModulePath(modulePath: string): boolean {
44
44
  const extension = path.extname(modulePath);
45
- return this.workflowExtensions.has(extension) && !modulePath.endsWith(".d.ts");
45
+ if (!this.workflowExtensions.has(extension)) {
46
+ return false;
47
+ }
48
+ const basename = path.basename(modulePath);
49
+ if (basename.endsWith(".d.ts") || basename.endsWith(".d.mts")) {
50
+ return false;
51
+ }
52
+ const withoutExt = basename.slice(0, -extension.length);
53
+ if (withoutExt.endsWith(".test") || withoutExt.endsWith(".spec")) {
54
+ return false;
55
+ }
56
+ return true;
46
57
  }
47
58
  }
@@ -0,0 +1,50 @@
1
+ import { injectable } from "@codemation/core";
2
+ import type { ManagedJwtVerifier, VerifiedManagedPrincipal } from "@codemation/managed-auth";
3
+ import type { WebsocketAuthenticator } from "./WebsocketAuthenticator.types";
4
+
5
+ /**
6
+ * WebSocket authenticator for `auth.kind: "managed"`.
7
+ *
8
+ * Parses `?token=<jwt>` from the WS upgrade URL and delegates to
9
+ * `ManagedJwtVerifier`. Returns the verified principal on success or `null`
10
+ * when the token is missing, expired, has the wrong audience, or is otherwise
11
+ * invalid.
12
+ *
13
+ * Note: browsers cannot set `Authorization` headers on `new WebSocket(url)`,
14
+ * so the bearer is carried as a query-string parameter.
15
+ */
16
+ @injectable()
17
+ export class ManagedWebsocketAuthenticator implements WebsocketAuthenticator {
18
+ constructor(private readonly verifier: ManagedJwtVerifier) {}
19
+
20
+ async authenticate(requestUrl: string | undefined): Promise<VerifiedManagedPrincipal | null> {
21
+ if (!requestUrl) {
22
+ return null;
23
+ }
24
+
25
+ const token = this.extractToken(requestUrl);
26
+ if (!token) {
27
+ return null;
28
+ }
29
+
30
+ const result = await this.verifier.verify(token);
31
+ if ("failure" in result) {
32
+ return null;
33
+ }
34
+
35
+ return result;
36
+ }
37
+
38
+ private extractToken(requestUrl: string): string | null {
39
+ // requestUrl is a relative path like "/__codemation/internal/ws?token=..."
40
+ // Use a dummy base so URL can parse relative URLs.
41
+ let url: URL;
42
+ try {
43
+ url = new URL(requestUrl, "http://placeholder");
44
+ } catch {
45
+ return null;
46
+ }
47
+ const token = url.searchParams.get("token");
48
+ return token && token.length > 0 ? token : null;
49
+ }
50
+ }
@@ -0,0 +1,12 @@
1
+ import type { VerifiedManagedPrincipal } from "@codemation/managed-auth";
2
+
3
+ /**
4
+ * Authenticates an incoming WebSocket upgrade request.
5
+ *
6
+ * Implementations parse the upgrade URL (e.g. `?token=<jwt>`) and verify the
7
+ * credential. Returns the verified principal on success, or `null` when the
8
+ * request must be rejected with close-code 4401.
9
+ */
10
+ export interface WebsocketAuthenticator {
11
+ authenticate(requestUrl: string | undefined): Promise<VerifiedManagedPrincipal | null>;
12
+ }
@@ -1,8 +1,10 @@
1
1
  import { WebSocket, WebSocketServer } from "ws";
2
+ import type { IncomingMessage } from "node:http";
2
3
  import type { WorkflowWebsocketMessage } from "../../application/contracts/WorkflowWebsocketMessage";
3
4
  import type { Logger } from "../../application/logging/Logger";
4
5
  import type { WorkflowWebsocketPublisher } from "../../application/websocket/WorkflowWebsocketPublisher";
5
6
  import { ApiPaths } from "../http/ApiPaths";
7
+ import type { WebsocketAuthenticator } from "./WebsocketAuthenticator.types";
6
8
 
7
9
  type WorkflowWebsocketClientMessage =
8
10
  | Readonly<{ kind: "subscribe"; roomId: string }>
@@ -26,8 +28,18 @@ export class WorkflowWebsocketServer implements WorkflowWebsocketPublisher {
26
28
  private readonly port: number,
27
29
  private readonly bindHost: string,
28
30
  private readonly logger: Logger,
31
+ private readonly authenticator: WebsocketAuthenticator | null = null,
29
32
  ) {}
30
33
 
34
+ /** Returns the actual port the server is listening on (useful when constructed with port 0). */
35
+ get listeningPort(): number {
36
+ const addr = this.websocketServer?.address();
37
+ if (!addr || typeof addr === "string") {
38
+ return this.port;
39
+ }
40
+ return addr.port;
41
+ }
42
+
31
43
  async start(): Promise<void> {
32
44
  if (this.started) {
33
45
  return;
@@ -38,8 +50,8 @@ export class WorkflowWebsocketServer implements WorkflowWebsocketPublisher {
38
50
  path: ApiPaths.workflowWebsocket(),
39
51
  });
40
52
  this.websocketServer = websocketServer;
41
- websocketServer.on("connection", (socket) => {
42
- void this.connect(socket);
53
+ websocketServer.on("connection", (socket, request) => {
54
+ void this.connect(socket, request);
43
55
  });
44
56
  try {
45
57
  await this.awaitListening(websocketServer);
@@ -98,7 +110,16 @@ export class WorkflowWebsocketServer implements WorkflowWebsocketPublisher {
98
110
  this.logger.debug(`published room=${roomId} sockets=${deliveredSocketCount} kind=${message.kind}`);
99
111
  }
100
112
 
101
- private async connect(socket: WebSocket): Promise<void> {
113
+ private async connect(socket: WebSocket, request: IncomingMessage): Promise<void> {
114
+ if (this.authenticator) {
115
+ const principal = await this.authenticator.authenticate(request.url);
116
+ if (!principal) {
117
+ this.logger.warn("websocket auth failed: closing with 4401");
118
+ socket.close(4401, "unauthorized");
119
+ return;
120
+ }
121
+ }
122
+
102
123
  this.sockets.add(socket);
103
124
  this.roomIdsBySocket.set(socket, new Set());
104
125
  this.logger.debug(`client connected activeSockets=${this.sockets.size}`);
@@ -0,0 +1,41 @@
1
+ import type { ChildProcess } from "node:child_process";
2
+ import { execa, execaSync, type Options as ExecaOptions, type SyncOptions as ExecaSyncOptions } from "execa";
3
+
4
+ import type { ProcessRunner, ProcessRunOptions, ProcessRunResult } from "./ProcessRunner.types";
5
+
6
+ /**
7
+ * Production {@link ProcessRunner}. Defers cross-platform executable resolution (`pnpm` ↔ `pnpm.cmd`,
8
+ * `.cmd` / `.bat` / `.ps1` shims on Windows) and argument quoting to execa so call sites stop having
9
+ * to hand-roll platform conditionals.
10
+ */
11
+ export class ExecaProcessRunner implements ProcessRunner {
12
+ spawn(command: string, args: ReadonlyArray<string>, options?: ProcessRunOptions): ChildProcess {
13
+ return execa(command, [...args], this.toExecaOptions(options)) as unknown as ChildProcess;
14
+ }
15
+
16
+ runSync(command: string, args: ReadonlyArray<string>, options?: ProcessRunOptions): ProcessRunResult {
17
+ const result = execaSync(command, [...args], this.toExecaSyncOptions(options));
18
+ return { exitCode: result.exitCode ?? null };
19
+ }
20
+
21
+ private toExecaOptions(options?: ProcessRunOptions): ExecaOptions {
22
+ return {
23
+ reject: false,
24
+ cwd: options?.cwd,
25
+ env: options?.env,
26
+ stdio: options?.stdio as ExecaOptions["stdio"],
27
+ detached: options?.detached,
28
+ windowsHide: options?.windowsHide,
29
+ };
30
+ }
31
+
32
+ private toExecaSyncOptions(options?: ProcessRunOptions): ExecaSyncOptions {
33
+ return {
34
+ reject: false,
35
+ cwd: options?.cwd,
36
+ env: options?.env,
37
+ stdio: options?.stdio as ExecaSyncOptions["stdio"],
38
+ windowsHide: options?.windowsHide,
39
+ };
40
+ }
41
+ }
@@ -0,0 +1,39 @@
1
+ import type { ChildProcess } from "node:child_process";
2
+
3
+ export type ProcessRunOptions = Readonly<{
4
+ cwd?: string;
5
+ env?: NodeJS.ProcessEnv;
6
+ /**
7
+ * Mirrors `child_process.SpawnOptions["stdio"]`. The runner forwards the value verbatim to the
8
+ * underlying subprocess, so callers that need fine-grained per-fd control (e.g.
9
+ * `["ignore", "pipe", "pipe"]`) can pass a tuple.
10
+ */
11
+ stdio?: "inherit" | "pipe" | "ignore" | ReadonlyArray<"inherit" | "pipe" | "ignore">;
12
+ /**
13
+ * On Unix this detaches the child from the parent's process group so it becomes the group
14
+ * leader (used by {@link DevTrackedProcessTreeKiller} to broadcast SIGTERM to descendants).
15
+ * On Windows it is ignored — `windowsHide` should be used to suppress console windows instead.
16
+ */
17
+ detached?: boolean;
18
+ windowsHide?: boolean;
19
+ }>;
20
+
21
+ export type ProcessRunResult = Readonly<{
22
+ exitCode: number | null;
23
+ }>;
24
+
25
+ /**
26
+ * Cross-platform process spawning seam. Implementations resolve bare CLI names (`pnpm`, `prisma`,
27
+ * `next`, …) against the OS PATH using OS-appropriate executable lookup, so call sites stop having
28
+ * to remember `pnpm.cmd` or `shell: true` on Windows.
29
+ *
30
+ * `spawn` returns a Node `ChildProcess` so existing helpers like `DevNextChildProcessOutputFilter`
31
+ * and `DevTrackedProcessTreeKiller` keep working unchanged.
32
+ */
33
+ export interface ProcessRunner {
34
+ /** Long-lived child (dev watcher, Next dev server). Returns a `ChildProcess`. */
35
+ spawn(command: string, args: ReadonlyArray<string>, options?: ProcessRunOptions): ChildProcess;
36
+
37
+ /** Synchronous one-shot (used by Prisma migrate deploy). */
38
+ runSync(command: string, args: ReadonlyArray<string>, options?: ProcessRunOptions): ProcessRunResult;
39
+ }
package/src/server.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { CodemationPostgresPrismaClientFactory } from "./persistenceServer";
2
2
  export type { PrismaClient } from "./persistenceServer";
3
+ export { ExecaProcessRunner } from "./process/ExecaProcessRunner";
4
+ export type { ProcessRunner, ProcessRunOptions, ProcessRunResult } from "./process/ProcessRunner.types";
3
5
  export { ApiPaths } from "./presentation/http/ApiPaths";
4
6
  export { CodemationServerGateway } from "./presentation/http/CodemationServerGatewayFactory";
5
7
  export { CodemationConsumerAppResolver } from "./presentation/server/CodemationConsumerAppResolver";
@@ -0,0 +1,42 @@
1
+ import { inject, injectable } from "@codemation/core";
2
+ import type { Hono } from "hono";
3
+ import { ApplicationTokens } from "../applicationTokens";
4
+ import type { CommandBus } from "../application/bus/CommandBus";
5
+ import { SetWorkflowActivationCommand } from "../application/commands/SetWorkflowActivationCommand";
6
+ import { InternalHmacAuthMiddleware } from "../pairing/InternalHmacAuthMiddleware";
7
+ import type { InternalHonoApiRouteRegistrar } from "../presentation/http/hono/InternalHonoApiRouteRegistrar";
8
+
9
+ /**
10
+ * Registers POST /internal/workflows/:workflowId/activation — HMAC-verified endpoint
11
+ * that activates or deactivates a workflow. Used by the coding agent to toggle workflow
12
+ * triggers without requiring a user session.
13
+ */
14
+ @injectable()
15
+ export class InternalWorkflowActivationRegistrar implements InternalHonoApiRouteRegistrar {
16
+ constructor(
17
+ @inject(InternalHmacAuthMiddleware) private readonly hmacMiddleware: InternalHmacAuthMiddleware,
18
+ @inject(ApplicationTokens.CommandBus) private readonly commandBus: CommandBus,
19
+ ) {}
20
+
21
+ register(app: Hono): void {
22
+ app.post("/internal/workflows/:workflowId/activation", this.hmacMiddleware.handle(), async (c) => {
23
+ const workflowId = c.req.param("workflowId");
24
+ let body: { active?: unknown };
25
+ try {
26
+ body = await c.req.json<{ active?: unknown }>();
27
+ } catch {
28
+ return c.json({ error: "Request body must be JSON with boolean active" }, 400);
29
+ }
30
+ if (typeof body.active !== "boolean") {
31
+ return c.json({ error: "Request body must include boolean active" }, 400);
32
+ }
33
+ try {
34
+ const result = await this.commandBus.execute(new SetWorkflowActivationCommand(workflowId, body.active));
35
+ return c.json(result);
36
+ } catch (err) {
37
+ const message = err instanceof Error ? err.message : String(err);
38
+ return c.json({ error: message }, 500);
39
+ }
40
+ });
41
+ }
42
+ }
@@ -0,0 +1,33 @@
1
+ import { inject, injectable } from "@codemation/core";
2
+ import type { Hono } from "hono";
3
+ import { ApplicationTokens } from "../applicationTokens";
4
+ import type { QueryBus } from "../application/bus/QueryBus";
5
+ import { GetWorkflowDetailQuery } from "../application/queries/GetWorkflowDetailQuery";
6
+ import { WorkflowDefinitionMapper } from "../application/mapping/WorkflowDefinitionMapper";
7
+ import { InternalHmacAuthMiddleware } from "../pairing/InternalHmacAuthMiddleware";
8
+ import type { InternalHonoApiRouteRegistrar } from "../presentation/http/hono/InternalHonoApiRouteRegistrar";
9
+
10
+ /**
11
+ * Registers GET /internal/workflows/:workflowId — HMAC-verified endpoint that returns a
12
+ * single workflow's full DAG (nodes + edges). Used by the concierge agent to inspect a
13
+ * specific workflow. Returns 404 (empty body) when the workflow id doesn't exist.
14
+ */
15
+ @injectable()
16
+ export class InternalWorkflowDetailRegistrar implements InternalHonoApiRouteRegistrar {
17
+ constructor(
18
+ @inject(InternalHmacAuthMiddleware) private readonly hmacMiddleware: InternalHmacAuthMiddleware,
19
+ @inject(ApplicationTokens.QueryBus) private readonly queryBus: QueryBus,
20
+ @inject(WorkflowDefinitionMapper) private readonly mapper: WorkflowDefinitionMapper,
21
+ ) {}
22
+
23
+ register(app: Hono): void {
24
+ app.get("/internal/workflows/:workflowId", this.hmacMiddleware.handle(), async (c) => {
25
+ const workflowId = c.req.param("workflowId");
26
+ const workflow = await this.queryBus.execute(new GetWorkflowDetailQuery(workflowId));
27
+ if (!workflow) {
28
+ return c.body(null, 404);
29
+ }
30
+ return c.json(await this.mapper.map(workflow));
31
+ });
32
+ }
33
+ }
@@ -0,0 +1,91 @@
1
+ import { inject, injectable } from "@codemation/core";
2
+ import { Engine } from "@codemation/core/bootstrap";
3
+ import { RunIntentService } from "@codemation/core/bootstrap";
4
+ import type { Hono } from "hono";
5
+ import { ApplicationTokens } from "../applicationTokens";
6
+ import type { WorkflowDefinitionRepository } from "../domain/workflows/WorkflowDefinitionRepository";
7
+ import { InternalHmacAuthMiddleware } from "../pairing/InternalHmacAuthMiddleware";
8
+ import type { InternalHonoApiRouteRegistrar } from "../presentation/http/hono/InternalHonoApiRouteRegistrar";
9
+
10
+ const TEST_RUN_TIMEOUT_MS = 30_000;
11
+
12
+ /**
13
+ * Registers POST /internal/workflows/:workflowId/test-run — HMAC-verified endpoint
14
+ * that runs a workflow once synchronously without requiring it to be active.
15
+ * Used by the coding agent to verify a workflow before activating it.
16
+ */
17
+ @injectable()
18
+ export class InternalWorkflowTestRunRegistrar implements InternalHonoApiRouteRegistrar {
19
+ constructor(
20
+ @inject(InternalHmacAuthMiddleware) private readonly hmacMiddleware: InternalHmacAuthMiddleware,
21
+ @inject(RunIntentService) private readonly runIntentService: RunIntentService,
22
+ @inject(Engine) private readonly engine: Engine,
23
+ @inject(ApplicationTokens.WorkflowDefinitionRepository)
24
+ private readonly workflowDefinitionRepository: WorkflowDefinitionRepository,
25
+ ) {}
26
+
27
+ register(app: Hono): void {
28
+ app.post("/internal/workflows/:workflowId/test-run", this.hmacMiddleware.handle(), async (c) => {
29
+ const workflowId = c.req.param("workflowId");
30
+ const startMs = Date.now();
31
+
32
+ let input: unknown;
33
+ try {
34
+ const body = await c.req.json<{ input?: unknown }>();
35
+ input = body.input;
36
+ } catch {
37
+ input = undefined;
38
+ }
39
+
40
+ const workflow = await this.workflowDefinitionRepository.getDefinition(workflowId);
41
+ if (!workflow) {
42
+ return c.json({ ok: false, error: `Unknown workflowId: ${workflowId}`, durationMs: Date.now() - startMs }, 404);
43
+ }
44
+
45
+ const items = input !== undefined ? [{ json: input as Record<string, unknown> }] : [{ json: {} }];
46
+
47
+ let runResult;
48
+ try {
49
+ const timeoutPromise = new Promise<never>((_, reject) =>
50
+ setTimeout(() => reject(new Error("test run timed out after 30s")), TEST_RUN_TIMEOUT_MS),
51
+ );
52
+ const runPromise = (async () => {
53
+ const result = await this.runIntentService.startWorkflow({
54
+ workflow,
55
+ items,
56
+ executionOptions: { localOnly: true },
57
+ });
58
+ if (result.status === "completed") {
59
+ return result;
60
+ }
61
+ if (result.status === "failed") {
62
+ return result;
63
+ }
64
+ // pending — wait for completion
65
+ return await this.engine.waitForCompletion(result.runId);
66
+ })();
67
+ runResult = await Promise.race([runPromise, timeoutPromise]);
68
+ } catch (err) {
69
+ const message = err instanceof Error ? err.message : String(err);
70
+ return c.json({ ok: false, error: message, durationMs: Date.now() - startMs });
71
+ }
72
+
73
+ if (runResult.status === "failed") {
74
+ return c.json({
75
+ ok: false,
76
+ runId: runResult.runId,
77
+ error: runResult.error.message,
78
+ durationMs: Date.now() - startMs,
79
+ });
80
+ }
81
+
82
+ // completed
83
+ return c.json({
84
+ ok: true,
85
+ runId: runResult.runId,
86
+ output: runResult.outputs,
87
+ durationMs: Date.now() - startMs,
88
+ });
89
+ });
90
+ }
91
+ }
@@ -0,0 +1,28 @@
1
+ import { inject, injectable } from "@codemation/core";
2
+ import type { Hono } from "hono";
3
+ import { ApplicationTokens } from "../applicationTokens";
4
+ import type { QueryBus } from "../application/bus/QueryBus";
5
+ import { GetWorkflowSummariesQuery } from "../application/queries/GetWorkflowSummariesQuery";
6
+ import { WorkflowDefinitionMapper } from "../application/mapping/WorkflowDefinitionMapper";
7
+ import { InternalHmacAuthMiddleware } from "../pairing/InternalHmacAuthMiddleware";
8
+ import type { InternalHonoApiRouteRegistrar } from "../presentation/http/hono/InternalHonoApiRouteRegistrar";
9
+
10
+ /**
11
+ * Registers GET /internal/workflows — HMAC-verified endpoint that returns the list of
12
+ * workflow summaries. Used by the concierge agent to enumerate available workflows.
13
+ */
14
+ @injectable()
15
+ export class InternalWorkflowsListRegistrar implements InternalHonoApiRouteRegistrar {
16
+ constructor(
17
+ @inject(InternalHmacAuthMiddleware) private readonly hmacMiddleware: InternalHmacAuthMiddleware,
18
+ @inject(ApplicationTokens.QueryBus) private readonly queryBus: QueryBus,
19
+ @inject(WorkflowDefinitionMapper) private readonly mapper: WorkflowDefinitionMapper,
20
+ ) {}
21
+
22
+ register(app: Hono): void {
23
+ app.get("/internal/workflows", this.hmacMiddleware.handle(), async (c) => {
24
+ const workflows = await this.queryBus.execute(new GetWorkflowSummariesQuery());
25
+ return c.json(workflows.map((w) => this.mapper.toSummary(w)));
26
+ });
27
+ }
28
+ }