@hivemagnus/magnus-server 0.0.0-stage → 1.0.2

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 (356) hide show
  1. package/.env.example +171 -0
  2. package/LICENSE +202 -0
  3. package/README.md +169 -2
  4. package/agent-version.json +1 -0
  5. package/dist/ai/HEARTBEAT.md +56 -0
  6. package/dist/ai/IDENTITY.md +54 -0
  7. package/dist/ai/MEMORY.md +40 -0
  8. package/dist/ai/TOOLS.md +538 -0
  9. package/dist/ai/USER.md +32 -0
  10. package/dist/cli/args.js +62 -0
  11. package/dist/cli/env-catalog.js +131 -0
  12. package/dist/cli/preflight.js +89 -0
  13. package/dist/cli.js +175 -0
  14. package/dist/config/cors.js +16 -0
  15. package/dist/config/env.js +392 -0
  16. package/dist/config/features.js +16 -0
  17. package/dist/config/index.js +3 -0
  18. package/dist/config/listener-security.js +38 -0
  19. package/dist/config/version.js +31 -0
  20. package/dist/db/client.js +44 -0
  21. package/dist/db/generated/prisma/browser.js +18 -0
  22. package/dist/db/generated/prisma/client.js +35 -0
  23. package/dist/db/generated/prisma/commonInputTypes.js +11 -0
  24. package/dist/db/generated/prisma/enums.js +42 -0
  25. package/dist/db/generated/prisma/internal/class.js +50 -0
  26. package/dist/db/generated/prisma/internal/prismaNamespace.js +1598 -0
  27. package/dist/db/generated/prisma/internal/prismaNamespaceBrowser.js +1569 -0
  28. package/dist/db/generated/prisma/models/A2ATask.js +2 -0
  29. package/dist/db/generated/prisma/models/AdmissionFence.js +2 -0
  30. package/dist/db/generated/prisma/models/Agent.js +2 -0
  31. package/dist/db/generated/prisma/models/AiConversation.js +2 -0
  32. package/dist/db/generated/prisma/models/AiDashboard.js +2 -0
  33. package/dist/db/generated/prisma/models/AiMemory.js +2 -0
  34. package/dist/db/generated/prisma/models/AiMessage.js +2 -0
  35. package/dist/db/generated/prisma/models/AiScheduledOp.js +2 -0
  36. package/dist/db/generated/prisma/models/AlertConditionState.js +2 -0
  37. package/dist/db/generated/prisma/models/AlertRule.js +2 -0
  38. package/dist/db/generated/prisma/models/AlertViolation.js +2 -0
  39. package/dist/db/generated/prisma/models/AnomalyEvent.js +2 -0
  40. package/dist/db/generated/prisma/models/ApplicationObservation.js +2 -0
  41. package/dist/db/generated/prisma/models/ArdentInstallation.js +2 -0
  42. package/dist/db/generated/prisma/models/ArdentProfile.js +2 -0
  43. package/dist/db/generated/prisma/models/ArdentScopeEnrollment.js +2 -0
  44. package/dist/db/generated/prisma/models/CommandResourceFence.js +2 -0
  45. package/dist/db/generated/prisma/models/CommandResourceLease.js +2 -0
  46. package/dist/db/generated/prisma/models/CommandResult.js +2 -0
  47. package/dist/db/generated/prisma/models/CronJob.js +2 -0
  48. package/dist/db/generated/prisma/models/CronJobExecution.js +2 -0
  49. package/dist/db/generated/prisma/models/DeployJob.js +2 -0
  50. package/dist/db/generated/prisma/models/DriftScan.js +2 -0
  51. package/dist/db/generated/prisma/models/EngineeringMetricSample.js +2 -0
  52. package/dist/db/generated/prisma/models/EngineeringRecoveryExercise.js +2 -0
  53. package/dist/db/generated/prisma/models/ExecutionRun.js +2 -0
  54. package/dist/db/generated/prisma/models/FilePatchTask.js +2 -0
  55. package/dist/db/generated/prisma/models/GpuSnapshot.js +2 -0
  56. package/dist/db/generated/prisma/models/HealthSnapshot.js +2 -0
  57. package/dist/db/generated/prisma/models/HermesCoreRollout.js +2 -0
  58. package/dist/db/generated/prisma/models/HermesCoreRolloutHost.js +2 -0
  59. package/dist/db/generated/prisma/models/HermesCredentialPool.js +2 -0
  60. package/dist/db/generated/prisma/models/HermesCredentialPoolAttachment.js +2 -0
  61. package/dist/db/generated/prisma/models/HermesCronJob.js +2 -0
  62. package/dist/db/generated/prisma/models/HermesHook.js +2 -0
  63. package/dist/db/generated/prisma/models/HermesInstallation.js +2 -0
  64. package/dist/db/generated/prisma/models/HermesMcpServer.js +2 -0
  65. package/dist/db/generated/prisma/models/HermesMcpServerAttachment.js +2 -0
  66. package/dist/db/generated/prisma/models/HermesMessagingBinding.js +2 -0
  67. package/dist/db/generated/prisma/models/HermesOperationJob.js +2 -0
  68. package/dist/db/generated/prisma/models/HermesPluginInstall.js +2 -0
  69. package/dist/db/generated/prisma/models/HermesProfile.js +2 -0
  70. package/dist/db/generated/prisma/models/HermesProviderConfig.js +2 -0
  71. package/dist/db/generated/prisma/models/HermesRegistryClient.js +2 -0
  72. package/dist/db/generated/prisma/models/HermesRegistryInventory.js +2 -0
  73. package/dist/db/generated/prisma/models/HermesRegistryReceipt.js +2 -0
  74. package/dist/db/generated/prisma/models/HermesRegistryRevision.js +2 -0
  75. package/dist/db/generated/prisma/models/HermesRegistryTarget.js +2 -0
  76. package/dist/db/generated/prisma/models/HermesRole.js +2 -0
  77. package/dist/db/generated/prisma/models/HermesRoleApplication.js +2 -0
  78. package/dist/db/generated/prisma/models/HermesSkillAssignment.js +2 -0
  79. package/dist/db/generated/prisma/models/HermesToolsetPolicy.js +2 -0
  80. package/dist/db/generated/prisma/models/IncidentLesson.js +2 -0
  81. package/dist/db/generated/prisma/models/LibraryCategory.js +2 -0
  82. package/dist/db/generated/prisma/models/LibraryFile.js +2 -0
  83. package/dist/db/generated/prisma/models/LogEntry.js +2 -0
  84. package/dist/db/generated/prisma/models/MagnusReleaseCanary.js +2 -0
  85. package/dist/db/generated/prisma/models/MaintenanceWindow.js +2 -0
  86. package/dist/db/generated/prisma/models/ManagedCronDefinition.js +2 -0
  87. package/dist/db/generated/prisma/models/ManagedCronOccurrence.js +2 -0
  88. package/dist/db/generated/prisma/models/Node.js +2 -0
  89. package/dist/db/generated/prisma/models/Notification.js +2 -0
  90. package/dist/db/generated/prisma/models/NotificationPreference.js +2 -0
  91. package/dist/db/generated/prisma/models/RemediationExecution.js +2 -0
  92. package/dist/db/generated/prisma/models/RemediationRule.js +2 -0
  93. package/dist/db/generated/prisma/models/RemoteCommand.js +2 -0
  94. package/dist/db/generated/prisma/models/ResourceDrainParticipant.js +2 -0
  95. package/dist/db/generated/prisma/models/ResourceEnrollment.js +2 -0
  96. package/dist/db/generated/prisma/models/ResourceParticipantWork.js +2 -0
  97. package/dist/db/generated/prisma/models/Role.js +2 -0
  98. package/dist/db/generated/prisma/models/RoleApplication.js +2 -0
  99. package/dist/db/generated/prisma/models/RolloutTarget.js +2 -0
  100. package/dist/db/generated/prisma/models/SecurityExportOutbox.js +2 -0
  101. package/dist/db/generated/prisma/models/SecurityFusionAction.js +2 -0
  102. package/dist/db/generated/prisma/models/SecurityFusionActionApproval.js +2 -0
  103. package/dist/db/generated/prisma/models/SecurityFusionCase.js +2 -0
  104. package/dist/db/generated/prisma/models/SecurityFusionCaseActivity.js +2 -0
  105. package/dist/db/generated/prisma/models/SecurityFusionCaseEntity.js +2 -0
  106. package/dist/db/generated/prisma/models/SecurityFusionCaseEvent.js +2 -0
  107. package/dist/db/generated/prisma/models/SecurityFusionCaseRelationship.js +2 -0
  108. package/dist/db/generated/prisma/models/SecurityFusionCollector.js +2 -0
  109. package/dist/db/generated/prisma/models/SecurityFusionCommandOutbox.js +2 -0
  110. package/dist/db/generated/prisma/models/SecurityFusionDeletionReceipt.js +2 -0
  111. package/dist/db/generated/prisma/models/SecurityFusionDelivery.js +2 -0
  112. package/dist/db/generated/prisma/models/SecurityFusionEntity.js +2 -0
  113. package/dist/db/generated/prisma/models/SecurityFusionEntityAlias.js +2 -0
  114. package/dist/db/generated/prisma/models/SecurityFusionEvent.js +2 -0
  115. package/dist/db/generated/prisma/models/SecurityFusionEventEntity.js +2 -0
  116. package/dist/db/generated/prisma/models/SecurityFusionEvidence.js +2 -0
  117. package/dist/db/generated/prisma/models/SecurityFusionInvestigation.js +2 -0
  118. package/dist/db/generated/prisma/models/SecurityFusionNonce.js +2 -0
  119. package/dist/db/generated/prisma/models/SecurityFusionReceiptChainHead.js +2 -0
  120. package/dist/db/generated/prisma/models/SecurityFusionRuleVersion.js +2 -0
  121. package/dist/db/generated/prisma/models/SecurityFusionSourceState.js +2 -0
  122. package/dist/db/generated/prisma/models/SecurityServiceState.js +2 -0
  123. package/dist/db/generated/prisma/models/SharedResourceFence.js +2 -0
  124. package/dist/db/generated/prisma/models/SharedResourceLease.js +2 -0
  125. package/dist/db/generated/prisma/models/SharedResourceLeaseResource.js +2 -0
  126. package/dist/db/generated/prisma/models/SkillInstallation.js +2 -0
  127. package/dist/db/generated/prisma/models/SkillRegistryEntry.js +2 -0
  128. package/dist/db/generated/prisma/models/SkillTag.js +2 -0
  129. package/dist/db/generated/prisma/models/SkillVersion.js +2 -0
  130. package/dist/db/generated/prisma/models/TeamApprovalDecision.js +2 -0
  131. package/dist/db/generated/prisma/models/User.js +2 -0
  132. package/dist/db/generated/prisma/models/WebhookDelivery.js +2 -0
  133. package/dist/db/generated/prisma/models/WebhookEndpoint.js +2 -0
  134. package/dist/db/generated/prisma/models.js +2 -0
  135. package/dist/db/index.js +3 -0
  136. package/dist/db/read-retry.js +35 -0
  137. package/dist/db/seed.js +348 -0
  138. package/dist/index.js +162 -0
  139. package/dist/middleware/auth.js +361 -0
  140. package/dist/middleware/body-limit.js +14 -0
  141. package/dist/middleware/correlation-id.js +13 -0
  142. package/dist/middleware/error-handler.js +28 -0
  143. package/dist/middleware/iam-token.js +21 -0
  144. package/dist/middleware/rate-limit.js +78 -0
  145. package/dist/middleware/request-logger.js +85 -0
  146. package/dist/middleware/security-headers.js +23 -0
  147. package/dist/middleware/tracing.js +120 -0
  148. package/dist/middleware/user-status.js +33 -0
  149. package/dist/openapi/spec.js +2656 -0
  150. package/dist/queue/redis.js +20 -0
  151. package/dist/queue/requeue.js +27 -0
  152. package/dist/queue/workers.js +342 -0
  153. package/dist/routes/ai-schedule.js +73 -0
  154. package/dist/routes/alerts.js +79 -0
  155. package/dist/routes/anomalies.js +101 -0
  156. package/dist/routes/ardent.js +82 -0
  157. package/dist/routes/assistant.js +417 -0
  158. package/dist/routes/audit.js +138 -0
  159. package/dist/routes/codex.js +65 -0
  160. package/dist/routes/commands.js +226 -0
  161. package/dist/routes/credentials.js +58 -0
  162. package/dist/routes/cron.js +292 -0
  163. package/dist/routes/dependencies.js +49 -0
  164. package/dist/routes/deploy.js +18 -0
  165. package/dist/routes/discovery.js +168 -0
  166. package/dist/routes/docs.js +24 -0
  167. package/dist/routes/drift.js +126 -0
  168. package/dist/routes/events-stream.js +87 -0
  169. package/dist/routes/files.js +214 -0
  170. package/dist/routes/fleet-checks.js +21 -0
  171. package/dist/routes/health.js +133 -0
  172. package/dist/routes/heartbeat.js +545 -0
  173. package/dist/routes/hermes-registry.js +278 -0
  174. package/dist/routes/hermes.js +61 -0
  175. package/dist/routes/library.js +402 -0
  176. package/dist/routes/logs.js +172 -0
  177. package/dist/routes/managed-cron.js +23 -0
  178. package/dist/routes/mcp.js +39 -0
  179. package/dist/routes/metrics.js +187 -0
  180. package/dist/routes/nodes.js +951 -0
  181. package/dist/routes/notifications.js +130 -0
  182. package/dist/routes/ops.js +258 -0
  183. package/dist/routes/orchestra.js +430 -0
  184. package/dist/routes/predictions.js +23 -0
  185. package/dist/routes/profiling.js +68 -0
  186. package/dist/routes/quick-command.js +72 -0
  187. package/dist/routes/remediation.js +111 -0
  188. package/dist/routes/resource-leases.js +297 -0
  189. package/dist/routes/roles.js +370 -0
  190. package/dist/routes/rollout.js +124 -0
  191. package/dist/routes/scan.js +116 -0
  192. package/dist/routes/security-backup.js +58 -0
  193. package/dist/routes/security-fusion.js +605 -0
  194. package/dist/routes/security-integration.js +71 -0
  195. package/dist/routes/self-update.js +129 -0
  196. package/dist/routes/shared-resource-leases.js +78 -0
  197. package/dist/routes/skills.js +485 -0
  198. package/dist/routes/stats.js +96 -0
  199. package/dist/routes/team-approvals.js +23 -0
  200. package/dist/routes/terminal-ticket.js +15 -0
  201. package/dist/routes/terminal.js +17 -0
  202. package/dist/routes/topology.js +37 -0
  203. package/dist/routes/users.js +219 -0
  204. package/dist/routes/webhooks.js +137 -0
  205. package/dist/schemas/command-reconciliation.js +14 -0
  206. package/dist/schemas/commands.js +51 -0
  207. package/dist/schemas/cron.js +33 -0
  208. package/dist/schemas/deploy.js +20 -0
  209. package/dist/schemas/files.js +14 -0
  210. package/dist/schemas/hermes.js +69 -0
  211. package/dist/schemas/index.js +11 -0
  212. package/dist/schemas/library.js +48 -0
  213. package/dist/schemas/logs.js +35 -0
  214. package/dist/schemas/managed-cron.js +127 -0
  215. package/dist/schemas/node-responses.js +87 -0
  216. package/dist/schemas/node-session-receipt.js +84 -0
  217. package/dist/schemas/nodes.js +36 -0
  218. package/dist/schemas/orchestra.js +118 -0
  219. package/dist/schemas/resource-participant-reconciliation.js +99 -0
  220. package/dist/schemas/roles.js +54 -0
  221. package/dist/schemas/shared-resource-lease.js +132 -0
  222. package/dist/schemas/skills.js +44 -0
  223. package/dist/schemas/users.js +28 -0
  224. package/dist/scripts/run-disposable-recovery-exercise.js +39 -0
  225. package/dist/sdk/index.js +2 -0
  226. package/dist/sdk/node-api-client.js +474 -0
  227. package/dist/security/approval-assertion.js +66 -0
  228. package/dist/security/command-completion-registry.js +35 -0
  229. package/dist/security/command-request.js +12 -0
  230. package/dist/security/command-result-signature.js +34 -0
  231. package/dist/security/managed-http.js +45 -0
  232. package/dist/security/native-completion-registry.js +44 -0
  233. package/dist/server.js +178 -0
  234. package/dist/services/admission-fence.js +71 -0
  235. package/dist/services/ai-assistant-service.js +2523 -0
  236. package/dist/services/ai-correlation-service.js +225 -0
  237. package/dist/services/ai-export-service.js +141 -0
  238. package/dist/services/ai-insights-service.js +219 -0
  239. package/dist/services/ai-schedule-service.js +145 -0
  240. package/dist/services/ai-scratchpad-service.js +222 -0
  241. package/dist/services/ai-tools.js +1343 -0
  242. package/dist/services/alert-service.js +313 -0
  243. package/dist/services/anomaly-detector.js +419 -0
  244. package/dist/services/api-local-work.js +79 -0
  245. package/dist/services/application-probes.js +309 -0
  246. package/dist/services/ardent-scope-enrollment.js +123 -0
  247. package/dist/services/ardent-service.js +86 -0
  248. package/dist/services/audit-service.js +308 -0
  249. package/dist/services/codex-service.js +209 -0
  250. package/dist/services/command-lifecycle.js +60 -0
  251. package/dist/services/command-resource-leases.js +305 -0
  252. package/dist/services/control-host-node.js +242 -0
  253. package/dist/services/credential-rotation-service.js +294 -0
  254. package/dist/services/dependency-service.js +145 -0
  255. package/dist/services/disposable-recovery-runner.js +595 -0
  256. package/dist/services/docker-group-health.js +121 -0
  257. package/dist/services/engineering-assurance.js +492 -0
  258. package/dist/services/engineering-evidence-ledger.js +94 -0
  259. package/dist/services/engineering-metric-evidence.js +26 -0
  260. package/dist/services/event-bus.js +227 -0
  261. package/dist/services/fleet-check-log.js +102 -0
  262. package/dist/services/forecast-service.js +154 -0
  263. package/dist/services/health-retention.js +175 -0
  264. package/dist/services/heartbeat-stream.js +63 -0
  265. package/dist/services/hermes-catalog-import.js +62 -0
  266. package/dist/services/hermes-cli-parser.js +671 -0
  267. package/dist/services/hermes-core-rollout.js +90 -0
  268. package/dist/services/hermes-dashboard-endpoint.js +13 -0
  269. package/dist/services/hermes-plugin-source.js +149 -0
  270. package/dist/services/hermes-registry-service.js +258 -0
  271. package/dist/services/hermes-service.js +566 -0
  272. package/dist/services/hivemem-client.js +85 -0
  273. package/dist/services/host-local-writer.js +82 -0
  274. package/dist/services/incident-evidence.js +110 -0
  275. package/dist/services/incident-lessons.js +186 -0
  276. package/dist/services/llm-providers/anthropic.js +143 -0
  277. package/dist/services/llm-providers/index.js +7 -0
  278. package/dist/services/llm-providers/llama-cpp.js +237 -0
  279. package/dist/services/llm-providers/ollama.js +292 -0
  280. package/dist/services/llm-providers/openai-compatible.js +200 -0
  281. package/dist/services/llm-providers/provider-error.js +36 -0
  282. package/dist/services/llm-providers/registry.js +45 -0
  283. package/dist/services/llm-providers/types.js +2 -0
  284. package/dist/services/log-emitter.js +19 -0
  285. package/dist/services/log-retention.js +66 -0
  286. package/dist/services/maintenance-service.js +29 -0
  287. package/dist/services/managed-cron.js +493 -0
  288. package/dist/services/managed-ssh-admission.js +68 -0
  289. package/dist/services/monitor-pulse.js +10 -0
  290. package/dist/services/node-issue-monitor.js +71 -0
  291. package/dist/services/node-service.js +35 -0
  292. package/dist/services/notification-retention.js +51 -0
  293. package/dist/services/notification-service.js +94 -0
  294. package/dist/services/operational-observations.js +112 -0
  295. package/dist/services/operations-config.js +67 -0
  296. package/dist/services/ops-service.js +491 -0
  297. package/dist/services/orchestra-extras-service.js +370 -0
  298. package/dist/services/orchestra-resources-service.js +530 -0
  299. package/dist/services/os-scheduler-writer.js +73 -0
  300. package/dist/services/password-service.js +22 -0
  301. package/dist/services/prediction-service.js +284 -0
  302. package/dist/services/recovery-exercises.js +682 -0
  303. package/dist/services/remediation-service.js +325 -0
  304. package/dist/services/resource-enrollment.js +433 -0
  305. package/dist/services/resource-node-lock.js +18 -0
  306. package/dist/services/resource-participant-work.js +302 -0
  307. package/dist/services/role-service.js +388 -0
  308. package/dist/services/rollout-service.js +440 -0
  309. package/dist/services/security-export.js +185 -0
  310. package/dist/services/security-fusion-actions.js +22 -0
  311. package/dist/services/security-fusion-approvals.js +83 -0
  312. package/dist/services/security-fusion-evidence-integrity.js +144 -0
  313. package/dist/services/security-fusion-ingest.js +101 -0
  314. package/dist/services/security-fusion-outbox.js +185 -0
  315. package/dist/services/security-fusion-receipt-chain.js +134 -0
  316. package/dist/services/security-fusion-service.js +751 -0
  317. package/dist/services/security-fusion-verification.js +50 -0
  318. package/dist/services/self-update-service.js +200 -0
  319. package/dist/services/shared-resource-leases.js +413 -0
  320. package/dist/services/skill-publication-bundle.js +90 -0
  321. package/dist/services/skill-publication-settlement.js +36 -0
  322. package/dist/services/skill-publication-state.js +40 -0
  323. package/dist/services/skill-registry-service.js +327 -0
  324. package/dist/services/skill-service.js +148 -0
  325. package/dist/services/ssh-exec-service.js +139 -0
  326. package/dist/services/ssh-host-verification.js +27 -0
  327. package/dist/services/tailscale-node-key-service.js +75 -0
  328. package/dist/services/team-approvals.js +118 -0
  329. package/dist/services/topology-service.js +138 -0
  330. package/dist/services/transfer-authority-snapshot.js +151 -0
  331. package/dist/services/webhook-credential-migration.js +97 -0
  332. package/dist/services/webhook-security.js +242 -0
  333. package/dist/services/webhook-service.js +494 -0
  334. package/dist/types/auth.js +3 -0
  335. package/dist/types/index.js +3 -0
  336. package/dist/types/library.js +3 -0
  337. package/dist/types/notifications.js +3 -0
  338. package/dist/types/roles.js +3 -0
  339. package/dist/types/shared-contracts.js +3 -0
  340. package/dist/utils/env.js +141 -0
  341. package/dist/utils/heartbeat-peer.js +19 -0
  342. package/dist/utils/idempotency.js +45 -0
  343. package/dist/utils/ip.js +25 -0
  344. package/dist/utils/json-fields.js +94 -0
  345. package/dist/utils/local-tls.js +39 -0
  346. package/dist/utils/magnus-home.js +15 -0
  347. package/dist/utils/node-url.js +59 -0
  348. package/dist/utils/redact.js +26 -0
  349. package/dist/utils/safe-equal.js +13 -0
  350. package/dist/utils/sentinel-nodes.js +16 -0
  351. package/dist/utils/validate.js +41 -0
  352. package/package.json +119 -4
  353. package/prisma/migrations/20261031000000_baseline/migration.sql +2935 -0
  354. package/prisma/migrations/migration_lock.toml +3 -0
  355. package/prisma/schema.prisma +2185 -0
  356. package/prisma.config.ts +14 -0
@@ -0,0 +1,37 @@
1
+ /**
2
+ * topology.ts — Fleet topology discovery routes.
3
+ *
4
+ * GET /topology — cached topology map
5
+ * POST /topology/scan — trigger fresh scan
6
+ */
7
+ import { Hono } from 'hono';
8
+ import { authMiddleware, requireRole } from '../middleware/auth.js';
9
+ import { scanTopology } from '../services/topology-service.js';
10
+ export const topologyRouter = new Hono();
11
+ topologyRouter.use('*', authMiddleware);
12
+ // ── In-memory cache (5 min TTL) ──
13
+ let cachedTopology = null;
14
+ let cacheExpiry = 0;
15
+ const CACHE_TTL_MS = 5 * 60 * 1000;
16
+ /**
17
+ * GET /topology
18
+ * Return the current topology map (cached for 5 min).
19
+ */
20
+ topologyRouter.get('/', async (c) => {
21
+ if (!cachedTopology || Date.now() > cacheExpiry) {
22
+ cachedTopology = await scanTopology();
23
+ cacheExpiry = Date.now() + CACHE_TTL_MS;
24
+ }
25
+ return c.json({ success: true, data: cachedTopology });
26
+ });
27
+ /**
28
+ * POST /topology/scan
29
+ * Force a fresh topology scan (invalidates cache).
30
+ */
31
+ topologyRouter.post('/scan', requireRole('ADMIN', 'OPERATOR'), async (c) => {
32
+ const body = await c.req.json().catch(() => ({}));
33
+ cachedTopology = await scanTopology(body.probeTimeoutMs ?? 3000);
34
+ cacheExpiry = Date.now() + CACHE_TTL_MS;
35
+ return c.json({ success: true, data: cachedTopology });
36
+ });
37
+ //# sourceMappingURL=topology.js.map
@@ -0,0 +1,219 @@
1
+ import { Hono } from 'hono';
2
+ import { getDb } from '../db/index.js';
3
+ import { authMiddleware, getUser, requireRole, signUserToken } from '../middleware/auth.js';
4
+ import { invalidateUserStatus } from '../middleware/user-status.js';
5
+ import { logAuditEvent } from '../services/audit-service.js';
6
+ import { hashPassword, verifyPassword } from '../services/password-service.js';
7
+ import { HttpError } from '../middleware/error-handler.js';
8
+ import { parseBody } from '../utils/validate.js';
9
+ import { loginSchema, createUserSchema, updateUserSchema, changePasswordSchema, } from '../schemas/users.js';
10
+ import { IAM_CORE_URL } from '../utils/env.js';
11
+ export const usersRouter = new Hono();
12
+ export const authRouter = new Hono();
13
+ // ─── Auth: POST /auth/login (local Magnus HS256 mode) ──────────────────────
14
+ authRouter.post('/login', async (c) => {
15
+ // Login is available when Magnus is using its local dashboard/API auth mode.
16
+ if (IAM_CORE_URL) {
17
+ throw new HttpError(404, 'NOT_FOUND', 'Login endpoint is not available in IAM mode');
18
+ }
19
+ const body = await parseBody(c, loginSchema);
20
+ const db = getDb();
21
+ const user = await db.user.findUnique({ where: { email: body.email } });
22
+ // Prevent timing attacks — always evaluate verifyPassword even on miss
23
+ const dummyHash = '$argon2id$v=19$m=65536,t=3,p=4$dummydummydummy$dummydummydummydummydummydummydummydummy';
24
+ const passwordValid = user
25
+ ? await verifyPassword(user.password, body.password)
26
+ : await verifyPassword(dummyHash, body.password).then(() => false);
27
+ if (!user || !user.active || !passwordValid) {
28
+ throw new HttpError(401, 'INVALID_CREDENTIALS', 'Invalid email or password');
29
+ }
30
+ // Update last login timestamp (fire-and-forget)
31
+ void db.user.update({
32
+ where: { id: user.id },
33
+ data: { lastLoginAt: new Date() },
34
+ }).catch(() => undefined);
35
+ const token = await signUserToken({
36
+ userId: user.id,
37
+ email: user.email,
38
+ role: user.role,
39
+ });
40
+ await logAuditEvent({
41
+ action: 'user.login',
42
+ actorId: user.id,
43
+ actorType: 'user',
44
+ targetType: 'user',
45
+ targetId: user.id,
46
+ details: { email: user.email },
47
+ ipAddress: c.req.header('x-forwarded-for') ?? c.req.header('x-real-ip') ?? null,
48
+ });
49
+ return c.json({ token, user: { id: user.id, email: user.email, name: user.name, role: user.role } });
50
+ });
51
+ // ─── Users CRUD (all require authentication) ────────────────────────────────
52
+ usersRouter.use('*', authMiddleware);
53
+ /** Omit password from user responses. */
54
+ function sanitizeUser(user) {
55
+ return {
56
+ id: user.id,
57
+ email: user.email,
58
+ name: user.name,
59
+ role: user.role,
60
+ active: user.active,
61
+ lastLoginAt: user.lastLoginAt,
62
+ createdAt: user.createdAt,
63
+ updatedAt: user.updatedAt,
64
+ };
65
+ }
66
+ // GET /users — list all users (ADMIN only)
67
+ usersRouter.get('/', requireRole('ADMIN'), async (c) => {
68
+ const db = getDb();
69
+ const users = await db.user.findMany({
70
+ where: { NOT: { id: 'system' } },
71
+ orderBy: { createdAt: 'desc' },
72
+ });
73
+ return c.json({ users: users.map(sanitizeUser) });
74
+ });
75
+ // GET /users/:id — get a single user (ADMIN or own account)
76
+ usersRouter.get('/:id', async (c) => {
77
+ const caller = getUser(c);
78
+ const userId = c.req.param('id');
79
+ if (caller.role !== 'ADMIN' && caller.userId !== userId) {
80
+ throw new HttpError(403, 'FORBIDDEN', 'You can only view your own account');
81
+ }
82
+ const db = getDb();
83
+ const user = await db.user.findUnique({ where: { id: userId } });
84
+ if (!user)
85
+ throw new HttpError(404, 'NOT_FOUND', 'User not found');
86
+ return c.json(sanitizeUser(user));
87
+ });
88
+ // POST /users — create a new user (ADMIN only)
89
+ usersRouter.post('/', requireRole('ADMIN'), async (c) => {
90
+ const caller = getUser(c);
91
+ const body = await parseBody(c, createUserSchema);
92
+ const db = getDb();
93
+ const existing = await db.user.findUnique({ where: { email: body.email } });
94
+ if (existing)
95
+ throw new HttpError(409, 'CONFLICT', 'A user with this email already exists');
96
+ const passwordHash = await hashPassword(body.password);
97
+ const user = await db.user.create({
98
+ data: {
99
+ email: body.email,
100
+ name: body.name,
101
+ password: passwordHash,
102
+ role: body.role,
103
+ },
104
+ });
105
+ await logAuditEvent({
106
+ action: 'user.create',
107
+ actorId: caller.userId,
108
+ actorType: 'user',
109
+ targetType: 'user',
110
+ targetId: user.id,
111
+ details: { email: user.email, role: user.role },
112
+ ipAddress: c.req.header('x-forwarded-for') ?? null,
113
+ });
114
+ return c.json(sanitizeUser(user), 201);
115
+ });
116
+ // PATCH /users/:id — update user (ADMIN only)
117
+ usersRouter.patch('/:id', requireRole('ADMIN'), async (c) => {
118
+ const caller = getUser(c);
119
+ const userId = c.req.param('id');
120
+ const body = await parseBody(c, updateUserSchema);
121
+ if (userId === 'system') {
122
+ throw new HttpError(400, 'VALIDATION_ERROR', 'Cannot modify the system user');
123
+ }
124
+ // Prevent admin from demoting themselves
125
+ if (userId === caller.userId && body.role && body.role !== 'ADMIN') {
126
+ throw new HttpError(400, 'VALIDATION_ERROR', 'Admins cannot demote their own account');
127
+ }
128
+ const db = getDb();
129
+ const existing = await db.user.findUnique({ where: { id: userId } });
130
+ if (!existing)
131
+ throw new HttpError(404, 'NOT_FOUND', 'User not found');
132
+ const user = await db.user.update({
133
+ where: { id: userId },
134
+ data: {
135
+ ...(body.name !== undefined && { name: body.name }),
136
+ ...(body.role !== undefined && { role: body.role }),
137
+ ...(body.active !== undefined && { active: body.active }),
138
+ },
139
+ });
140
+ invalidateUserStatus(userId);
141
+ await logAuditEvent({
142
+ action: 'user.update',
143
+ actorId: caller.userId,
144
+ actorType: 'user',
145
+ targetType: 'user',
146
+ targetId: user.id,
147
+ details: { changes: body },
148
+ ipAddress: c.req.header('x-forwarded-for') ?? null,
149
+ });
150
+ return c.json(sanitizeUser(user));
151
+ });
152
+ // DELETE /users/:id — delete a user (ADMIN only)
153
+ usersRouter.delete('/:id', requireRole('ADMIN'), async (c) => {
154
+ const caller = getUser(c);
155
+ const userId = c.req.param('id');
156
+ if (userId === 'system') {
157
+ throw new HttpError(400, 'VALIDATION_ERROR', 'Cannot delete the system user');
158
+ }
159
+ if (userId === caller.userId) {
160
+ throw new HttpError(400, 'VALIDATION_ERROR', 'Cannot delete your own account');
161
+ }
162
+ const db = getDb();
163
+ const existing = await db.user.findUnique({ where: { id: userId } });
164
+ if (!existing)
165
+ throw new HttpError(404, 'NOT_FOUND', 'User not found');
166
+ await db.user.delete({ where: { id: userId } });
167
+ invalidateUserStatus(userId);
168
+ await logAuditEvent({
169
+ action: 'user.update',
170
+ actorId: caller.userId,
171
+ actorType: 'user',
172
+ targetType: 'user',
173
+ targetId: userId,
174
+ details: { action: 'deleted', email: existing.email },
175
+ ipAddress: c.req.header('x-forwarded-for') ?? null,
176
+ });
177
+ return c.json({ success: true });
178
+ });
179
+ // PUT /users/:id/password — change password (own account or ADMIN)
180
+ usersRouter.put('/:id/password', async (c) => {
181
+ const caller = getUser(c);
182
+ const userId = c.req.param('id');
183
+ const body = await parseBody(c, changePasswordSchema);
184
+ const isSelf = caller.userId === userId;
185
+ const isAdmin = caller.role === 'ADMIN';
186
+ if (!isSelf && !isAdmin) {
187
+ throw new HttpError(403, 'FORBIDDEN', 'You can only change your own password');
188
+ }
189
+ if (userId === 'system') {
190
+ throw new HttpError(400, 'VALIDATION_ERROR', 'Cannot change the system user password');
191
+ }
192
+ const db = getDb();
193
+ const user = await db.user.findUnique({ where: { id: userId } });
194
+ if (!user)
195
+ throw new HttpError(404, 'NOT_FOUND', 'User not found');
196
+ // Non-admin users must provide their current password
197
+ if (isSelf && !isAdmin) {
198
+ if (!body.currentPassword) {
199
+ throw new HttpError(400, 'VALIDATION_ERROR', 'Current password is required');
200
+ }
201
+ const valid = await verifyPassword(user.password, body.currentPassword);
202
+ if (!valid) {
203
+ throw new HttpError(401, 'INVALID_CREDENTIALS', 'Current password is incorrect');
204
+ }
205
+ }
206
+ const newHash = await hashPassword(body.newPassword);
207
+ await db.user.update({ where: { id: userId }, data: { password: newHash } });
208
+ await logAuditEvent({
209
+ action: 'user.update',
210
+ actorId: caller.userId,
211
+ actorType: 'user',
212
+ targetType: 'user',
213
+ targetId: userId,
214
+ details: { action: 'password_changed', self: isSelf },
215
+ ipAddress: c.req.header('x-forwarded-for') ?? null,
216
+ });
217
+ return c.json({ success: true });
218
+ });
219
+ //# sourceMappingURL=users.js.map
@@ -0,0 +1,137 @@
1
+ import { Hono } from 'hono';
2
+ import { authMiddleware, getUser, requireRole } from '../middleware/auth.js';
3
+ import { logAuditEvent } from '../services/audit-service.js';
4
+ import { HttpError } from '../middleware/error-handler.js';
5
+ import { listWebhookEndpoints, getWebhookEndpoint, createWebhookEndpoint, updateWebhookEndpoint, deleteWebhookEndpoint, listDeliveries, testWebhookEndpoint, dispatchWebhook, redeliverWebhookDelivery, } from '../services/webhook-service.js';
6
+ import { validateWebhookTarget } from '../services/webhook-security.js';
7
+ /** Audit only the target origin: webhook paths and queries often embed tokens. */
8
+ function webhookOrigin(url) {
9
+ try {
10
+ return new URL(url).origin;
11
+ }
12
+ catch {
13
+ return 'invalid';
14
+ }
15
+ }
16
+ export const webhooksRouter = new Hono();
17
+ // All webhook routes require ADMIN role
18
+ webhooksRouter.use('*', authMiddleware);
19
+ webhooksRouter.use('*', requireRole('ADMIN'));
20
+ // ── List all webhook endpoints ──
21
+ webhooksRouter.get('/', async (c) => {
22
+ const endpoints = await listWebhookEndpoints();
23
+ return c.json({ success: true, data: { endpoints } });
24
+ });
25
+ // ── Get a specific webhook endpoint ──
26
+ webhooksRouter.get('/:id', async (c) => {
27
+ const endpoint = await getWebhookEndpoint(c.req.param('id'));
28
+ if (!endpoint)
29
+ throw new HttpError(404, 'NOT_FOUND', 'Webhook endpoint not found');
30
+ return c.json({ success: true, data: { endpoint } });
31
+ });
32
+ // ── Create a webhook endpoint ──
33
+ webhooksRouter.post('/', async (c) => {
34
+ const body = await c.req.json();
35
+ if (!body.name || !body.url) {
36
+ throw new HttpError(400, 'VALIDATION_ERROR', 'name and url are required');
37
+ }
38
+ try {
39
+ await validateWebhookTarget(body.url);
40
+ }
41
+ catch {
42
+ throw new HttpError(400, 'VALIDATION_ERROR', 'Webhook target is not an approved public HTTPS endpoint');
43
+ }
44
+ const user = c.get('user');
45
+ const endpoint = await createWebhookEndpoint({
46
+ ...body,
47
+ createdBy: user?.userId ?? user?.email ?? 'system',
48
+ });
49
+ await logAuditEvent({
50
+ action: 'webhook.create', actorId: getUser(c).userId, targetType: 'webhook',
51
+ targetId: endpoint.id ?? 'unknown',
52
+ details: { name: body.name, type: body.type ?? 'generic', origin: webhookOrigin(body.url), events: body.events ?? [],
53
+ secretConfigured: Boolean(body.secret), headersConfigured: Object.keys(body.headers ?? {}).length > 0 },
54
+ });
55
+ return c.json({ success: true, data: { endpoint } }, 201);
56
+ });
57
+ // ── Update a webhook endpoint ──
58
+ webhooksRouter.patch('/:id', async (c) => {
59
+ const id = c.req.param('id');
60
+ const existing = await getWebhookEndpoint(id);
61
+ if (!existing)
62
+ throw new HttpError(404, 'NOT_FOUND', 'Webhook endpoint not found');
63
+ const body = await c.req.json();
64
+ if (body.url !== undefined) {
65
+ try {
66
+ await validateWebhookTarget(body.url);
67
+ }
68
+ catch {
69
+ throw new HttpError(400, 'VALIDATION_ERROR', 'Webhook target is not an approved public HTTPS endpoint');
70
+ }
71
+ }
72
+ const endpoint = await updateWebhookEndpoint(id, body);
73
+ // Record which fields changed, never secret or header values.
74
+ await logAuditEvent({
75
+ action: 'webhook.update', actorId: getUser(c).userId, targetType: 'webhook', targetId: id,
76
+ details: { changedFields: Object.keys(body).sort(),
77
+ ...(body.url !== undefined && { origin: webhookOrigin(body.url) }),
78
+ ...(body.active !== undefined && { active: body.active }),
79
+ ...(body.events !== undefined && { events: body.events }) },
80
+ });
81
+ return c.json({ success: true, data: { endpoint } });
82
+ });
83
+ // ── Delete a webhook endpoint ──
84
+ webhooksRouter.delete('/:id', async (c) => {
85
+ const id = c.req.param('id');
86
+ const existing = await getWebhookEndpoint(id);
87
+ if (!existing)
88
+ throw new HttpError(404, 'NOT_FOUND', 'Webhook endpoint not found');
89
+ await deleteWebhookEndpoint(id);
90
+ await logAuditEvent({ action: 'webhook.delete', actorId: getUser(c).userId, targetType: 'webhook', targetId: id,
91
+ details: { name: existing.name ?? null } });
92
+ return c.json({ success: true, data: { success: true } });
93
+ });
94
+ // ── List deliveries for an endpoint ──
95
+ webhooksRouter.get('/:id/deliveries', async (c) => {
96
+ const id = c.req.param('id');
97
+ const existing = await getWebhookEndpoint(id);
98
+ if (!existing)
99
+ throw new HttpError(404, 'NOT_FOUND', 'Webhook endpoint not found');
100
+ const page = parseInt(c.req.query('page') ?? '1', 10);
101
+ const pageSize = parseInt(c.req.query('pageSize') ?? '20', 10);
102
+ const result = await listDeliveries(id, page, pageSize);
103
+ return c.json({ success: true, data: result });
104
+ });
105
+ // ── Test a webhook endpoint ──
106
+ webhooksRouter.post('/:id/test', async (c) => {
107
+ const result = await testWebhookEndpoint(c.req.param('id'));
108
+ await logAuditEvent({ action: 'webhook.test', actorId: getUser(c).userId, targetType: 'webhook',
109
+ targetId: c.req.param('id'), details: { success: result.success } });
110
+ return c.json({ success: true, data: result }, result.success ? 200 : 502);
111
+ });
112
+ // ── Redeliver a failed webhook delivery ──
113
+ webhooksRouter.post('/:id/deliveries/:deliveryId/redeliver', async (c) => {
114
+ const endpointId = c.req.param('id');
115
+ const deliveryId = c.req.param('deliveryId');
116
+ const endpoint = await getWebhookEndpoint(endpointId);
117
+ if (!endpoint)
118
+ throw new HttpError(404, 'NOT_FOUND', 'Webhook endpoint not found');
119
+ const result = await redeliverWebhookDelivery(endpointId, deliveryId);
120
+ if (!result)
121
+ throw new HttpError(404, 'NOT_FOUND', 'Delivery not found');
122
+ await logAuditEvent({ action: 'webhook.redeliver', actorId: getUser(c).userId, targetType: 'webhook',
123
+ targetId: endpointId, details: { deliveryId, newDeliveryId: result } });
124
+ return c.json({ success: true, data: { deliveryId: result } });
125
+ });
126
+ // ── Dispatch a webhook event (system/external callers) ──
127
+ webhooksRouter.post('/dispatch', async (c) => {
128
+ const body = await c.req.json();
129
+ if (!body.event) {
130
+ throw new HttpError(400, 'VALIDATION_ERROR', 'event is required');
131
+ }
132
+ await dispatchWebhook(body.event, body.payload ?? {});
133
+ await logAuditEvent({ action: 'webhook.dispatch', actorId: getUser(c).userId, targetType: 'webhook',
134
+ targetId: body.event, details: { event: body.event } });
135
+ return c.json({ success: true }, 202);
136
+ });
137
+ //# sourceMappingURL=webhooks.js.map
@@ -0,0 +1,14 @@
1
+ import { z } from 'zod';
2
+ import { commandFenceSchema } from './node-responses.js';
3
+ export const commandReconciliationSchema = z.object({
4
+ nodeFqdn: z.string().min(1).max(253),
5
+ commandId: z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/),
6
+ requestSha256: z.string().regex(/^[a-f0-9]{64}$/), coordination: commandFenceSchema.optional(),
7
+ disposition: z.enum(['effects_verified', 'no_effect_verified']),
8
+ evidenceSha256: z.string().regex(/^[a-f0-9]{64}$/),
9
+ approvalRef: z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9:._/-]{0,199}$/),
10
+ decisionId: z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/),
11
+ expiresAt: z.number().int().positive().max(8_640_000_000_000_000),
12
+ signature: z.string().regex(/^[a-f0-9]{64}$/),
13
+ }).strict();
14
+ //# sourceMappingURL=command-reconciliation.js.map
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Zod schemas for command-related routes.
3
+ */
4
+ import { z } from 'zod';
5
+ import { commandReconciliationSchema } from './command-reconciliation.js';
6
+ import { isSensitiveDetailKey } from '../services/audit-service.js';
7
+ /**
8
+ * Node-bound environment. Commands and cron jobs persist their environment and
9
+ * dispatch it from the database, where secret-named values are redacted, so a
10
+ * secret-named key would silently reach the node as "[REDACTED]". Reject it.
11
+ */
12
+ export const nodeEnvironmentSchema = z.record(z.string(), z.string()).superRefine((environment, ctx) => {
13
+ for (const key of Object.keys(environment)) {
14
+ if (!isSensitiveDetailKey(key))
15
+ continue;
16
+ ctx.addIssue({
17
+ code: z.ZodIssueCode.custom,
18
+ path: [key],
19
+ message: `Environment variable "${key}" is secret-named and is never stored or dispatched; `
20
+ + 'provision the secret on the node and reference it instead',
21
+ });
22
+ }
23
+ });
24
+ // ── POST /commands ──
25
+ export const dispatchCommandSchema = z.object({
26
+ idempotencyKey: z.string().optional(),
27
+ nodeIds: z.array(z.string().min(1)).min(1, 'At least one nodeId is required'),
28
+ command: z.string().min(1, 'command is required'),
29
+ args: z.array(z.string()).optional().default([]),
30
+ workingDirectory: z.string().optional(),
31
+ environment: nodeEnvironmentSchema.optional().default({}),
32
+ timeoutSeconds: z.number().int().min(1).max(3600).optional().default(300),
33
+ riskLevel: z.enum(['low', 'medium', 'high']).optional().default('medium'),
34
+ dryRun: z.boolean().optional().default(false),
35
+ });
36
+ // ── POST /commands/:commandId/cancel ──
37
+ export const cancelCommandSchema = z.object({
38
+ reason: z.string().optional(),
39
+ });
40
+ // ── POST /quick-command/:nodeId/exec ──
41
+ export const quickCommandSchema = z.object({
42
+ command: z.string().min(1, 'command is required'),
43
+ args: z.array(z.string()).optional().default([]),
44
+ timeoutSeconds: z.number().int().min(1).max(600).optional().default(120),
45
+ workingDirectory: z.string().optional(),
46
+ });
47
+ // Empty body refreshes the existing signed node receipt; no unsigned unlock.
48
+ export const reconcileCommandResourceSchema = z.object({
49
+ assertion: commandReconciliationSchema.optional(),
50
+ }).strict();
51
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Zod schemas for cron job routes.
3
+ */
4
+ import { z } from 'zod';
5
+ import { managedCronRegistrationSchema } from './managed-cron.js';
6
+ import { nodeEnvironmentSchema } from './commands.js';
7
+ // ── POST /cron ──
8
+ export const createCronSchema = z.object({
9
+ nodeId: z.string().min(1, 'nodeId is required'),
10
+ name: z.string().min(1, 'name is required'),
11
+ description: z.string().optional().default(''),
12
+ schedule: z.string().min(1, 'schedule (cron expression) is required'),
13
+ command: z.string().min(1, 'command is required'),
14
+ args: z.array(z.string()).optional().default([]),
15
+ workingDirectory: z.string().nullable().optional(),
16
+ environment: nodeEnvironmentSchema.optional().default({}),
17
+ timeoutSeconds: z.number().int().min(1).max(7200).optional().default(600),
18
+ managed: managedCronRegistrationSchema.optional(),
19
+ });
20
+ // ── PATCH /cron/:cronId ──
21
+ export const updateCronSchema = z.object({
22
+ name: z.string().min(1).optional(),
23
+ description: z.string().optional(),
24
+ schedule: z.string().min(1).optional(),
25
+ command: z.string().min(1).optional(),
26
+ args: z.array(z.string()).optional(),
27
+ status: z.enum(['active', 'paused', 'error', 'ACTIVE', 'PAUSED', 'ERROR']).optional(),
28
+ timeoutSeconds: z.number().int().min(1).max(7200).optional(),
29
+ workingDirectory: z.string().nullable().optional(),
30
+ environment: nodeEnvironmentSchema.optional(),
31
+ managed: managedCronRegistrationSchema.optional(),
32
+ });
33
+ //# sourceMappingURL=cron.js.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Zod schemas for deploy routes.
3
+ */
4
+ import { z } from 'zod';
5
+ // ── POST /deploy ──
6
+ export const deployNodeSchema = z.object({
7
+ hostname: z.string().min(1, 'hostname is required'),
8
+ name: z.string().optional(),
9
+ sshPort: z.number().int().min(1).max(65535).optional(),
10
+ nodeId: z.string().optional(),
11
+ });
12
+ // ── POST /deploy/control-node ──
13
+ export const deployControlNodeSchema = z.object({
14
+ hostname: z.string().min(1, 'hostname is required'),
15
+ sshPort: z.number().int().min(1).max(65535).optional(),
16
+ controlApiPort: z.number().int().min(1).max(65535).optional(),
17
+ nodeManagerSecret: z.string().optional(),
18
+ corsOrigin: z.string().url().optional(),
19
+ });
20
+ //# sourceMappingURL=deploy.js.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Zod schemas for file routes.
3
+ */
4
+ import { z } from 'zod';
5
+ // ── POST /files/update ──
6
+ export const fileUpdateSchema = z.object({
7
+ nodeIds: z.array(z.string().min(1)).min(1, 'At least one nodeId is required'),
8
+ filePath: z.string().min(1, 'filePath is required'),
9
+ content: z.string(),
10
+ createIfMissing: z.boolean().optional().default(true),
11
+ previewOnly: z.boolean().optional().default(false),
12
+ backup: z.boolean().optional().default(true),
13
+ });
14
+ //# sourceMappingURL=files.js.map
@@ -0,0 +1,69 @@
1
+ import { z } from 'zod';
2
+ const sshPortSchema = z.number().int().min(1).max(65535);
3
+ const optionalString = z.string().trim().min(1).optional();
4
+ const hermesTargetBaseSchema = z.object({
5
+ nodeId: optionalString,
6
+ hostname: optionalString,
7
+ sshPort: sshPortSchema.optional(),
8
+ hermesHome: z.string().trim().min(1).default('~/.hermes'),
9
+ hermesBin: z.string().trim().min(1).default('hermes'),
10
+ });
11
+ export const hermesTargetSchema = hermesTargetBaseSchema.refine((value) => Boolean(value.nodeId || value.hostname), {
12
+ message: 'Either nodeId or hostname is required',
13
+ path: ['hostname'],
14
+ });
15
+ export const hermesDetectSchema = hermesTargetSchema;
16
+ export const hermesDeploySchema = hermesTargetBaseSchema.extend({
17
+ installMethod: z.enum(['official-script', 'pip']).default('official-script'),
18
+ dashboardPort: sshPortSchema.default(9119),
19
+ enableDashboard: z.boolean().default(true),
20
+ enableDashboardTui: z.boolean().default(true),
21
+ startGateway: z.boolean().default(true),
22
+ }).refine((value) => Boolean(value.nodeId || value.hostname), {
23
+ message: 'Either nodeId or hostname is required',
24
+ path: ['hostname'],
25
+ });
26
+ export const hermesProfileCreateSchema = z.object({
27
+ name: z.string().trim().min(1).max(100).regex(/^[a-zA-Z0-9._-]+$/, 'Use letters, numbers, dot, underscore, or dash'),
28
+ description: z.string().trim().max(2000).optional(),
29
+ distribution: z.string().trim().min(1).max(200).optional(),
30
+ setDefault: z.boolean().default(false),
31
+ });
32
+ export const hermesProfileUpdateSchema = z.object({
33
+ description: z.string().trim().max(2000).optional(),
34
+ renameTo: z.string().trim().min(1).max(100).regex(/^[a-zA-Z0-9._-]+$/).optional(),
35
+ }).refine((value) => value.description !== undefined || value.renameTo !== undefined, {
36
+ message: 'At least one update field is required',
37
+ });
38
+ export const hermesConfigUpdateSchema = z.object({
39
+ configYaml: z.string().max(512_000),
40
+ });
41
+ export const hermesGatewayActionSchema = z.object({
42
+ action: z.enum(['install', 'start', 'stop', 'restart', 'status']),
43
+ });
44
+ export const hermesApiServerEnableSchema = z.object({
45
+ port: sshPortSchema.default(8642),
46
+ host: z.string().trim().min(1).default('127.0.0.1'),
47
+ apiKey: z.string().min(16).max(4096).optional(),
48
+ });
49
+ export const hermesOpenClawMigrationSchema = z.object({
50
+ installationId: z.string().min(1),
51
+ profileName: z.string().trim().min(1).max(100).optional(),
52
+ sourcePath: z.string().trim().min(1).default('~/.openclaw'),
53
+ preset: z.enum(['full', 'user-data']).default('full'),
54
+ overwrite: z.boolean().default(false),
55
+ migrateSecrets: z.boolean().default(false),
56
+ });
57
+ export const hermesJobListQuerySchema = z.object({
58
+ status: z.string().optional(),
59
+ type: z.string().optional(),
60
+ /** Category prefix-matched against `type` (e.g. `install`, `skill_push`, `provider`, `cron`). */
61
+ category: z.string().optional(),
62
+ installationId: z.string().optional(),
63
+ profileId: z.string().optional(),
64
+ limit: z.coerce.number().int().min(1).max(100).default(20),
65
+ });
66
+ export const hermesApiServerRotateSchema = z.object({
67
+ apiKey: z.string().min(16).max(4096).optional(),
68
+ });
69
+ //# sourceMappingURL=hermes.js.map
@@ -0,0 +1,11 @@
1
+ export * from './commands.js';
2
+ export * from './cron.js';
3
+ export * from './deploy.js';
4
+ export * from './nodes.js';
5
+ export * from './roles.js';
6
+ export * from './files.js';
7
+ export * from './skills.js';
8
+ export * from './library.js';
9
+ export * from './logs.js';
10
+ export * from './node-responses.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Zod schemas for library routes.
3
+ */
4
+ import { z } from 'zod';
5
+ // ── POST /library/categories ──
6
+ export const createCategorySchema = z.object({
7
+ name: z.string().min(1, 'Category name is required'),
8
+ description: z.string().optional().default(''),
9
+ color: z.string().optional().default('#6366f1'),
10
+ sortOrder: z.number().int().optional().default(0),
11
+ });
12
+ // ── PATCH /library/categories/:categoryId ──
13
+ export const updateCategorySchema = z.object({
14
+ name: z.string().min(1).optional(),
15
+ description: z.string().optional(),
16
+ color: z.string().optional(),
17
+ sortOrder: z.number().int().optional(),
18
+ });
19
+ // ── POST /library/files ──
20
+ export const createLibraryFileSchema = z.object({
21
+ name: z.string().min(1, 'File name is required'),
22
+ fileName: z.string().min(1, 'File name is required'),
23
+ mimeType: z.string().optional().default('text/markdown'),
24
+ content: z.string().optional().default(''),
25
+ categoryId: z.string().nullable().optional(),
26
+ tags: z.array(z.string()).optional().default([]),
27
+ });
28
+ // ── PATCH /library/files/:fileId ──
29
+ export const updateLibraryFileSchema = z.object({
30
+ name: z.string().min(1).optional(),
31
+ fileName: z.string().min(1).optional(),
32
+ mimeType: z.string().optional(),
33
+ content: z.string().optional(),
34
+ categoryId: z.string().nullable().optional(),
35
+ tags: z.array(z.string()).optional(),
36
+ });
37
+ // ── POST /library/files/move ──
38
+ export const moveFilesSchema = z.object({
39
+ fileIds: z.array(z.string().min(1)).min(1, 'fileIds array is required'),
40
+ categoryId: z.string().nullable().optional(),
41
+ });
42
+ // ── POST /library/deploy ──
43
+ export const deployLibrarySchema = z.object({
44
+ fileId: z.string().min(1, 'fileId is required'),
45
+ nodeIds: z.array(z.string().min(1)).min(1, 'At least one nodeId is required'),
46
+ overwrite: z.boolean().optional().default(false),
47
+ });
48
+ //# sourceMappingURL=library.js.map