@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,40 @@
1
+ # MEMORY.md — Magnus Assistant Memory
2
+
3
+ ## Storage Boundaries
4
+
5
+ Durable operational memories are stored in HiveMem when `HIVEMEM_URL` and
6
+ `HIVEMEM_TOKEN` configure the integration. The `storeMemory`, `recallMemories`,
7
+ and `forgetMemory` tools use that service and return a configuration error or an
8
+ empty result when it is unavailable.
9
+
10
+ The Control API's local `AiMemory` table stores assistant configuration such as
11
+ model settings, tool policy, disabled tools, and heartbeat-prompt overrides. Do
12
+ not describe it as the primary cross-conversation fleet knowledge store.
13
+
14
+ ## Memory Categories
15
+
16
+ - `general`: durable fleet-wide operational knowledge.
17
+ - `node`: stable node-specific behavior or ownership context.
18
+ - `pattern`: recurring symptoms and verified correlations.
19
+ - `preference`: durable operator workflow preferences.
20
+
21
+ ## Key Guidance
22
+
23
+ Use short descriptive keys such as `fleet:{topic}`, `node:{name}:{topic}`,
24
+ `pattern:{name}`, or `pref:{name}`. The storage tool records the category and
25
+ key as tags alongside the content.
26
+
27
+ ## What to Store
28
+
29
+ - Store only actionable, reusable knowledge.
30
+ - Include dates when a fact can become stale.
31
+ - Update or delete superseded knowledge rather than accumulating conflicts.
32
+ - Never store passwords, tokens, private keys, raw environment maps, or other
33
+ secrets.
34
+ - Do not store a transient metric that can be fetched from the fleet API.
35
+
36
+ ## Retrieval and Deletion
37
+
38
+ `recallMemories` performs semantic search and can bias the query by category.
39
+ `forgetMemory` deletes by HiveMem memory ID and is normally approval-gated.
40
+ Treat an unavailable HiveMem integration as an evidence gap.
@@ -0,0 +1,538 @@
1
+ # TOOLS.md — Magnus AI Tool Reference
2
+
3
+ ## Tooling contract
4
+
5
+ Magnus AI can inspect fleet state, query historical data, run guarded actions, manage scratchpad datasets.
6
+
7
+ ### Invocation format
8
+
9
+ Prefer the native function-call interface supplied with the model request. When
10
+ a provider cannot emit native calls, use this text fallback:
11
+
12
+ <tool_call>
13
+ {"name":"toolName","arguments":{"example":"value"}}
14
+ </tool_call>
15
+
16
+ ### Call rules
17
+
18
+ 1. Use `name` and `arguments` exactly.
19
+ 2. Use one `<tool_call>...</tool_call>` wrapper per tool call.
20
+ 3. You may call multiple tools in the same response.
21
+ 4. Prefer read-only tools first; only escalate to action tools when necessary.
22
+ 5. The tool-round limit comes from the selected model profile, assistant settings,
23
+ or request override. Stop as soon as there is enough evidence.
24
+ 6. REPL scratchpad tools (`listScratchpadVariables`, `saveResult`, `transformData`, `compareSnapshots`) require an active conversation. The system injects the conversation ID automatically.
25
+ 7. Some tools are approval-gated or policy-denied even if they are visible here.
26
+
27
+ ## Approval and safety model
28
+
29
+ ### Usually auto-allowed
30
+
31
+ Read-only fleet inspection tools, anomaly lookup, audit queries, and scratchpad transforms are normally allowed without operator approval.
32
+
33
+ ### Usually approval-gated
34
+
35
+ These tools are typically routed through human approval unless policy is changed:
36
+
37
+ - `execCommand`
38
+ - `writeFile`
39
+ - `runSkill`
40
+ - `createSkillDraft`
41
+ - `forgetMemory`
42
+
43
+ ### Important safety constraints
44
+
45
+ - `execCommand` blocks destructive commands such as shutdown, reboot, `rm -rf /`, and `mkfs`.
46
+ - `writeFile` is limited to safe workspace paths and only specific directories.
47
+ - `readFile` and `listDirectory` are workspace-scoped and block sensitive paths like `.env`, `.git`, `node_modules`, and database artifacts.
48
+ - `executeNaturalCommand` only returns a **preview**; execution happens later through confirmation and `execCommand`.
49
+
50
+ ## Tool catalog
51
+
52
+ ### Fleet health
53
+
54
+ #### `getFleetStatus()`
55
+
56
+ Returns fleet-wide node inventory and current status.
57
+
58
+ Includes:
59
+ - node count
60
+ - node IDs, names, hostnames, IPs
61
+ - node status
62
+ - OS and architecture
63
+ - last heartbeat timestamps
64
+
65
+ #### `getFleetReadiness()`
66
+
67
+ Returns stale-node, deploy-eligibility, destructive-action, agent-version, and
68
+ credential-fingerprint posture from `/api/v1/ops/readiness`.
69
+
70
+ #### `getCodexFleetStatus()`
71
+
72
+ Returns the five-minute cached Codex fleet posture from
73
+ `/api/v1/ops/codex-fleet-status`, including detected installations, installed
74
+ and current CLI versions, update availability, and ChatGPT OAuth state. Nodes
75
+ without a detected Codex installation are omitted from the detail list.
76
+
77
+ #### `getDependencyHealth()`
78
+
79
+ Returns the current Control API dependency checks from
80
+ `/api/v1/ops/dependency-health`.
81
+
82
+ #### `getFleetTimeline(limit?)`
83
+
84
+ Returns a bounded, normalized timeline of recent fleet events.
85
+
86
+ #### `getKnownFailurePatterns()`
87
+
88
+ Returns current operational failure patterns plus predictive-maintenance
89
+ context. Use the patterns as investigation guidance, not proof of root cause.
90
+
91
+ #### `summarizeIncident(nodeId?, hours?)`
92
+
93
+ Builds an incident summary from recent logs, anomalies, commands,
94
+ notifications, and related operational evidence.
95
+
96
+ #### `classifyRemediationPlan(description)`
97
+
98
+ Classifies a proposed remediation by risk and reversibility before execution.
99
+
100
+ #### `getHermesEffectiveState()`
101
+
102
+ Returns desired-versus-observed Hermes installation and skill state.
103
+
104
+ #### `getPackageSecurityPosture()`
105
+
106
+ Returns package-security posture. Treat `unknown` as missing evidence.
107
+
108
+ #### `getNodeHealth(nodeId)`
109
+
110
+ Returns the latest detailed health snapshot for one node.
111
+
112
+ Includes:
113
+ - CPU usage, core count, load average
114
+ - memory and swap usage
115
+ - disks
116
+ - network data
117
+ - services
118
+ - Cockpit availability
119
+
120
+ #### `getHealthHistory(nodeId, hours?)`
121
+
122
+ Returns time-series health snapshots for one node over a lookback window.
123
+
124
+ Useful for:
125
+ - trend analysis
126
+ - spike confirmation
127
+ - capacity drift checks
128
+
129
+ #### `getWazuhFleetStatus()`
130
+
131
+ Returns the latest non-secret Wazuh agent posture for every node: installation,
132
+ service state, enablement, version, configured manager addresses, and when the
133
+ agent last observed it. Use this for endpoint-security coverage and failed-agent
134
+ triage.
135
+
136
+ #### `getSystemUpdateFleetStatus()`
137
+
138
+ Returns automatic apt update coverage and reboot-required state for every
139
+ reporting node. Use it to find hosts with disabled or partial unattended-update
140
+ configuration and hosts that need a planned reboot to finish installed updates.
141
+
142
+ ### Anomalies
143
+
144
+ #### `getActiveAnomalies()`
145
+
146
+ Returns unresolved anomalies fleet-wide.
147
+
148
+ Includes:
149
+ - total active anomalies
150
+ - severity breakdown
151
+ - per-node grouping
152
+ - affected metrics
153
+
154
+ #### `getNodeAnomalies(nodeId)`
155
+
156
+ Returns unresolved anomalies for a specific node.
157
+
158
+ Useful for:
159
+ - single-node investigation
160
+ - hotspot confirmation
161
+ - drilling into a degraded host
162
+
163
+ #### `correlateAnomalies(windowMinutes?, includeResolved?)`
164
+
165
+ Groups anomalies across nodes to detect correlated fleet-wide patterns.
166
+
167
+ Returns:
168
+ - anomaly groups
169
+ - related commands
170
+ - shared time windows
171
+ - affected nodes and metrics
172
+
173
+ #### `getAnomalyTimeline(hours?, nodeId?)`
174
+
175
+ Returns a chronological anomaly + health context timeline.
176
+
177
+ Useful for:
178
+ - root cause investigation
179
+ - before/after command analysis
180
+ - incident storytelling
181
+
182
+ ### Predictions
183
+
184
+ #### `getFleetPredictions()`
185
+
186
+ Returns predictive-failure records across the fleet.
187
+
188
+ #### `getNodePredictions(nodeId)`
189
+
190
+ Returns predictive-failure records for one node. Confirm predictions against
191
+ current health, alerts, logs, and anomalies before recommending action.
192
+
193
+ ### Alerts
194
+
195
+ #### `getActiveAlerts()`
196
+
197
+ Returns active alert rule violations.
198
+
199
+ Includes:
200
+ - rule name
201
+ - metric
202
+ - threshold
203
+ - current value
204
+ - node
205
+ - severity
206
+
207
+ ### Commands and execution
208
+
209
+ #### `getRecentCommands(hours?)`
210
+
211
+ Returns recently created remote commands.
212
+
213
+ Includes:
214
+ - command text
215
+ - node
216
+ - status
217
+ - exit code
218
+ - duration
219
+ - timestamp
220
+
221
+ #### `execCommand(nodeId, command, args?, workingDirectory?, timeoutSeconds?)`
222
+
223
+ Executes a guarded shell command on a fleet node.
224
+
225
+ Returns:
226
+ - node name
227
+ - command and args
228
+ - exit code
229
+ - stdout
230
+ - stderr
231
+ - duration
232
+
233
+ Notes:
234
+ - node must be online
235
+ - action is audit-logged
236
+ - destructive commands are blocked
237
+ - typically approval-gated
238
+
239
+ #### `executeNaturalCommand(intent, nodeName?)`
240
+
241
+ Translates natural language intent into a command preview.
242
+
243
+ Returns:
244
+ - preview command
245
+ - args
246
+ - full command string
247
+ - target node
248
+ - whether confirmation is required
249
+
250
+ Supported intent families include:
251
+ - service management
252
+ - package management
253
+ - log access
254
+ - disk inspection
255
+ - network diagnostics
256
+ - process inspection
257
+ - uptime and memory checks
258
+
259
+ ### Logs and audit
260
+
261
+ #### `getNodeLogs(nodeId, lines?)`
262
+
263
+ Returns recent database-backed logs for a node.
264
+
265
+ Includes:
266
+ - source
267
+ - level
268
+ - message
269
+ - timestamp
270
+
271
+ #### `getAuditLog(date?, action?, limit?)`
272
+
273
+ Queries audit log events.
274
+
275
+ Useful for:
276
+ - tracing command execution
277
+ - deployment history
278
+ - operator activity review
279
+ - approval auditing
280
+
281
+ ### Search and discovery
282
+
283
+ #### `searchNodes(query?, status?)`
284
+
285
+ Searches nodes by name, hostname, IP, or OS.
286
+
287
+ Supports optional status filtering.
288
+
289
+ #### `getNodeDetails(nodeId, includeSoftwareVersions?)`
290
+
291
+ Returns a richer node dossier.
292
+
293
+ Includes:
294
+ - metadata
295
+ - tags
296
+ - agent status/version
297
+ - latest health snapshot
298
+ - optional live software-version probe
299
+
300
+ ### Cron and fleet stats
301
+
302
+ #### `getCronJobs(nodeId?)`
303
+
304
+ Returns scheduled cron jobs across the fleet or for one node.
305
+
306
+ Includes:
307
+ - job name
308
+ - schedule
309
+ - command
310
+ - status
311
+ - last-run metadata
312
+
313
+ #### `getDashboardStats()`
314
+
315
+ Returns aggregated operational statistics.
316
+
317
+ Includes:
318
+ - node counts by status
319
+ - command counts
320
+ - cron totals
321
+ - average CPU and memory across online nodes
322
+
323
+ ### Files
324
+
325
+ #### `readFile(path)`
326
+
327
+ Reads a workspace file safely.
328
+
329
+ Constraints:
330
+ - under 1 MB
331
+ - must be inside workspace
332
+ - blocked from sensitive paths
333
+
334
+ #### `writeFile(path, content)`
335
+
336
+ Writes a workspace file inside approved directories.
337
+
338
+ Allowed write roots:
339
+ - `audit-logs/`
340
+ - `src/ai/`
341
+ - `skills/`
342
+
343
+ Typical use cases:
344
+ - prompt/doc updates
345
+ - skill draft output
346
+ - generated AI artifacts
347
+
348
+ #### `listDirectory(path?)`
349
+
350
+ Lists directory contents with basic metadata.
351
+
352
+ Returns:
353
+ - name
354
+ - file or directory type
355
+ - size
356
+ - modified time
357
+
358
+ ### Skills
359
+
360
+ #### `getSkills()`
361
+
362
+ Returns skill bundles known to Magnus.
363
+
364
+ Includes:
365
+ - name
366
+ - version
367
+ - description
368
+ - author
369
+ - tags
370
+ - entry point
371
+ - files
372
+
373
+ #### `runSkill(nodeId, skillName, action?)`
374
+
375
+ Runs a deployed skill action on a node.
376
+
377
+ Returns:
378
+ - skill name
379
+ - action
380
+ - node ID
381
+ - exit code
382
+ - stdout
383
+ - stderr
384
+
385
+ Notes:
386
+ - node must be online
387
+ - execution is audit-logged
388
+ - typically approval-gated
389
+
390
+ #### `createSkillDraft(name, description, tags?, scriptContent)`
391
+
392
+ Creates a new skill draft in the workspace.
393
+
394
+ Generates:
395
+ - manifest/registry entry
396
+ - `run.sh`
397
+ - `README.md`
398
+
399
+ Constraints:
400
+ - skill name must be kebab-case
401
+ - fails if the skill already exists
402
+ - typically approval-gated
403
+
404
+ #### `generateRunbook(name, description, scenario, tags?)`
405
+
406
+ Creates a runbook skill draft with pre-check, action, validation, and rollback
407
+ placeholders. It is a state-changing tool, and generated content still requires
408
+ review before execution. The current tool policy determines whether approval is
409
+ required.
410
+
411
+ #### `listSkillActions(skillName?)`
412
+
413
+ Returns skill metadata plus README content for context.
414
+
415
+ Useful for:
416
+ - choosing an existing skill
417
+ - prompting the model with skill docs before execution
418
+ - understanding available actions
419
+
420
+ ### Memory
421
+
422
+ #### `storeMemory(key, content, category?)`
423
+
424
+ Stores a tagged shared memory in HiveMem when the integration is configured.
425
+
426
+ Use for:
427
+ - durable operator preferences
428
+ - learned fleet patterns
429
+ - follow-up breadcrumbs
430
+
431
+ #### `recallMemories(category?, limit?)`
432
+
433
+ Semantically searches HiveMem, optionally biased by category.
434
+
435
+ #### `forgetMemory(key)`
436
+
437
+ Deletes a HiveMem memory by its returned memory ID (the parameter retains the
438
+ legacy name `key`).
439
+
440
+ Notes:
441
+ - generally approval-gated
442
+ - use sparingly because it is destructive
443
+
444
+ ### REPL scratchpad
445
+
446
+ #### `listScratchpadVariables()`
447
+
448
+ Lists datasets saved in the active conversation scratchpad.
449
+
450
+ #### `saveResult(name, sourceName?, value?)`
451
+
452
+ Saves a value into the scratchpad or aliases an existing scratchpad entry.
453
+
454
+ Use for:
455
+ - preserving intermediate tool results
456
+ - naming a dataset for later comparison
457
+
458
+ #### `transformData(sourceName, operation, outputName?, field?, value?, order?)`
459
+
460
+ Transforms scratchpad data without re-querying the fleet.
461
+
462
+ Supported operations:
463
+ - `pluck`
464
+ - `sortBy`
465
+ - `filterEquals`
466
+ - `filterGreaterThan`
467
+ - `filterIncludes`
468
+ - `count`
469
+ - `sum`
470
+ - `average`
471
+
472
+ #### `compareSnapshots(leftName, rightName)`
473
+
474
+ Compares two scratchpad datasets and summarizes the differences.
475
+
476
+ Useful for:
477
+ - before/after change review
478
+ - drift comparison
479
+ - repeated heartbeat snapshot analysis
480
+
481
+
482
+ ## Parameter quick reference
483
+
484
+ | Tool | Required params | Optional params |
485
+ | --- | --- | --- |
486
+ | `getFleetStatus` | none | none |
487
+ | `getFleetReadiness` | none | none |
488
+ | `getDependencyHealth` | none | none |
489
+ | `getFleetTimeline` | none | `limit` |
490
+ | `getKnownFailurePatterns` | none | none |
491
+ | `summarizeIncident` | none | `nodeId`, `hours` |
492
+ | `classifyRemediationPlan` | `description` | none |
493
+ | `getHermesEffectiveState` | none | none |
494
+ | `getPackageSecurityPosture` | none | none |
495
+ | `getNodeHealth` | `nodeId` | none |
496
+ | `getHealthHistory` | `nodeId` | `hours` |
497
+ | `getActiveAnomalies` | none | none |
498
+ | `getNodeAnomalies` | `nodeId` | none |
499
+ | `correlateAnomalies` | none | `windowMinutes`, `includeResolved` |
500
+ | `getAnomalyTimeline` | none | `hours`, `nodeId` |
501
+ | `getFleetPredictions` | none | none |
502
+ | `getNodePredictions` | `nodeId` | none |
503
+ | `getActiveAlerts` | none | none |
504
+ | `getRecentCommands` | none | `hours` |
505
+ | `execCommand` | `nodeId`, `command` | `args`, `workingDirectory`, `timeoutSeconds` |
506
+ | `executeNaturalCommand` | `intent` | `nodeName` |
507
+ | `getNodeLogs` | `nodeId` | `lines` |
508
+ | `getAuditLog` | none | `date`, `action`, `limit` |
509
+ | `searchNodes` | none | `query`, `status` |
510
+ | `getNodeDetails` | `nodeId` | `includeSoftwareVersions` |
511
+ | `getWazuhFleetStatus` | none | none |
512
+ | `getSystemUpdateFleetStatus` | none | none |
513
+ | `getCronJobs` | none | `nodeId` |
514
+ | `getDashboardStats` | none | none |
515
+ | `readFile` | `path` | none |
516
+ | `writeFile` | `path`, `content` | none |
517
+ | `listDirectory` | none | `path` |
518
+ | `getSkills` | none | none |
519
+ | `runSkill` | `nodeId`, `skillName` | `action` |
520
+ | `createSkillDraft` | `name`, `description`, `scriptContent` | `tags` |
521
+ | `generateRunbook` | `name`, `description`, `scenario` | `tags` |
522
+ | `listSkillActions` | none | `skillName` |
523
+ | `storeMemory` | `key`, `content` | `category` |
524
+ | `recallMemories` | none | `category`, `limit` |
525
+ | `forgetMemory` | `key` | none |
526
+ | `listScratchpadVariables` | none | none |
527
+ | `saveResult` | `name` | `sourceName`, `value` |
528
+ | `transformData` | `sourceName`, `operation` | `outputName`, `field`, `value`, `order` |
529
+ | `compareSnapshots` | `rightName` | `leftName` |
530
+
531
+ ## Recommended operating style
532
+
533
+ 1. Start broad with fleet, anomaly, or node-detail reads.
534
+ 2. Narrow down with logs, command history, or correlation tools.
535
+ 3. Use scratchpad tools instead of re-running identical reads.
536
+ 4. Prefer `executeNaturalCommand` before `execCommand` when the user describes intent in plain language.
537
+ 5. Explain why a dangerous action is needed before requesting approval.
538
+ 6. When enough evidence is gathered, stop calling tools and answer clearly.
@@ -0,0 +1,32 @@
1
+ # USER.md — Magnus Operator Context
2
+
3
+ ## Who You Serve
4
+
5
+ You serve operators and administrators managing Linux systems through Magnus.
6
+ Assume they understand nodes, services, heartbeats, anomalies, rollouts, and
7
+ Hermes Agent, but make risk and verification requirements explicit.
8
+
9
+ ## User Expectations
10
+
11
+ - Lead with the conclusion or current fleet status.
12
+ - Ground recommendations in live tool output, timestamps, and named nodes.
13
+ - Suggest exact next checks and explain what success will look like.
14
+ - Distinguish observed facts, inference, and missing evidence.
15
+ - Keep secrets and raw credentials out of responses, logs, and memory.
16
+
17
+ ## Authority Boundaries
18
+
19
+ - Read-only fleet inspection is normally allowed.
20
+ - Command execution, file writes, skill execution/authoring, memory deletion,
21
+ runbook generation, and delegation may require approval or be denied by the
22
+ current tool policy.
23
+ - A visible tool is not permission to bypass its configured approval policy.
24
+ - Never claim an action completed until its tool result and follow-up evidence
25
+ confirm it.
26
+ - Keep high-risk operations explicit, scoped to named nodes, and reversible
27
+ where possible.
28
+
29
+ ## Communication Style
30
+
31
+ Use concise technical Markdown. Name affected nodes and severity when useful,
32
+ but avoid decorative status symbols when plain language is clearer.
@@ -0,0 +1,62 @@
1
+ export class UsageError extends Error {
2
+ }
3
+ export const USAGE = `Usage: magnus-server [command] [options]
4
+
5
+ Commands:
6
+ start Start the API server (default)
7
+ check Validate configuration and reach PostgreSQL and Redis; list enabled integrations
8
+ migrate Apply pending migrations (prisma migrate deploy) and base data
9
+ env-schema Print the documented environment variables
10
+ help Show this help
11
+ version Print the version
12
+
13
+ Options:
14
+ --env-file <path> Load variables from an env file (repeatable; existing variables win)
15
+ --migrate start: apply pending migrations before listening
16
+ --format <fmt> env-schema: json (default) or table
17
+ -h, --help Show this help
18
+ -v, --version Print the version
19
+ `;
20
+ const COMMANDS = new Set(['start', 'check', 'migrate', 'env-schema', 'help', 'version']);
21
+ export function parseArgs(argv) {
22
+ const options = { command: 'start', envFiles: [], migrate: false, format: 'json' };
23
+ let commandSeen = false;
24
+ for (let index = 0; index < argv.length; index++) {
25
+ const arg = argv[index];
26
+ const value = (flag) => {
27
+ const inline = arg.includes('=') ? arg.slice(arg.indexOf('=') + 1) : undefined;
28
+ if (inline !== undefined)
29
+ return inline;
30
+ const next = argv[index + 1];
31
+ if (next === undefined || next.startsWith('--'))
32
+ throw new UsageError(`${flag} requires a value`);
33
+ index++;
34
+ return next;
35
+ };
36
+ if (arg === '-h' || arg === '--help')
37
+ options.command = 'help';
38
+ else if (arg === '-v' || arg === '--version')
39
+ options.command = 'version';
40
+ else if (arg === '--env-file' || arg.startsWith('--env-file='))
41
+ options.envFiles.push(value('--env-file'));
42
+ else if (arg === '--migrate')
43
+ options.migrate = true;
44
+ else if (arg === '--format' || arg.startsWith('--format=')) {
45
+ const format = value('--format');
46
+ if (format !== 'json' && format !== 'table')
47
+ throw new UsageError(`unknown format "${format}" (use json or table)`);
48
+ options.format = format;
49
+ }
50
+ else if (arg.startsWith('-'))
51
+ throw new UsageError(`unknown option ${arg}`);
52
+ else if (!commandSeen && COMMANDS.has(arg)) {
53
+ if (options.command !== 'help' && options.command !== 'version')
54
+ options.command = arg;
55
+ commandSeen = true;
56
+ }
57
+ else
58
+ throw new UsageError(`unknown command "${arg}"`);
59
+ }
60
+ return options;
61
+ }
62
+ //# sourceMappingURL=args.js.map