@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.
- package/.env.example +171 -0
- package/LICENSE +202 -0
- package/README.md +169 -2
- package/agent-version.json +1 -0
- package/dist/ai/HEARTBEAT.md +56 -0
- package/dist/ai/IDENTITY.md +54 -0
- package/dist/ai/MEMORY.md +40 -0
- package/dist/ai/TOOLS.md +538 -0
- package/dist/ai/USER.md +32 -0
- package/dist/cli/args.js +62 -0
- package/dist/cli/env-catalog.js +131 -0
- package/dist/cli/preflight.js +89 -0
- package/dist/cli.js +175 -0
- package/dist/config/cors.js +16 -0
- package/dist/config/env.js +392 -0
- package/dist/config/features.js +16 -0
- package/dist/config/index.js +3 -0
- package/dist/config/listener-security.js +38 -0
- package/dist/config/version.js +31 -0
- package/dist/db/client.js +44 -0
- package/dist/db/generated/prisma/browser.js +18 -0
- package/dist/db/generated/prisma/client.js +35 -0
- package/dist/db/generated/prisma/commonInputTypes.js +11 -0
- package/dist/db/generated/prisma/enums.js +42 -0
- package/dist/db/generated/prisma/internal/class.js +50 -0
- package/dist/db/generated/prisma/internal/prismaNamespace.js +1598 -0
- package/dist/db/generated/prisma/internal/prismaNamespaceBrowser.js +1569 -0
- package/dist/db/generated/prisma/models/A2ATask.js +2 -0
- package/dist/db/generated/prisma/models/AdmissionFence.js +2 -0
- package/dist/db/generated/prisma/models/Agent.js +2 -0
- package/dist/db/generated/prisma/models/AiConversation.js +2 -0
- package/dist/db/generated/prisma/models/AiDashboard.js +2 -0
- package/dist/db/generated/prisma/models/AiMemory.js +2 -0
- package/dist/db/generated/prisma/models/AiMessage.js +2 -0
- package/dist/db/generated/prisma/models/AiScheduledOp.js +2 -0
- package/dist/db/generated/prisma/models/AlertConditionState.js +2 -0
- package/dist/db/generated/prisma/models/AlertRule.js +2 -0
- package/dist/db/generated/prisma/models/AlertViolation.js +2 -0
- package/dist/db/generated/prisma/models/AnomalyEvent.js +2 -0
- package/dist/db/generated/prisma/models/ApplicationObservation.js +2 -0
- package/dist/db/generated/prisma/models/ArdentInstallation.js +2 -0
- package/dist/db/generated/prisma/models/ArdentProfile.js +2 -0
- package/dist/db/generated/prisma/models/ArdentScopeEnrollment.js +2 -0
- package/dist/db/generated/prisma/models/CommandResourceFence.js +2 -0
- package/dist/db/generated/prisma/models/CommandResourceLease.js +2 -0
- package/dist/db/generated/prisma/models/CommandResult.js +2 -0
- package/dist/db/generated/prisma/models/CronJob.js +2 -0
- package/dist/db/generated/prisma/models/CronJobExecution.js +2 -0
- package/dist/db/generated/prisma/models/DeployJob.js +2 -0
- package/dist/db/generated/prisma/models/DriftScan.js +2 -0
- package/dist/db/generated/prisma/models/EngineeringMetricSample.js +2 -0
- package/dist/db/generated/prisma/models/EngineeringRecoveryExercise.js +2 -0
- package/dist/db/generated/prisma/models/ExecutionRun.js +2 -0
- package/dist/db/generated/prisma/models/FilePatchTask.js +2 -0
- package/dist/db/generated/prisma/models/GpuSnapshot.js +2 -0
- package/dist/db/generated/prisma/models/HealthSnapshot.js +2 -0
- package/dist/db/generated/prisma/models/HermesCoreRollout.js +2 -0
- package/dist/db/generated/prisma/models/HermesCoreRolloutHost.js +2 -0
- package/dist/db/generated/prisma/models/HermesCredentialPool.js +2 -0
- package/dist/db/generated/prisma/models/HermesCredentialPoolAttachment.js +2 -0
- package/dist/db/generated/prisma/models/HermesCronJob.js +2 -0
- package/dist/db/generated/prisma/models/HermesHook.js +2 -0
- package/dist/db/generated/prisma/models/HermesInstallation.js +2 -0
- package/dist/db/generated/prisma/models/HermesMcpServer.js +2 -0
- package/dist/db/generated/prisma/models/HermesMcpServerAttachment.js +2 -0
- package/dist/db/generated/prisma/models/HermesMessagingBinding.js +2 -0
- package/dist/db/generated/prisma/models/HermesOperationJob.js +2 -0
- package/dist/db/generated/prisma/models/HermesPluginInstall.js +2 -0
- package/dist/db/generated/prisma/models/HermesProfile.js +2 -0
- package/dist/db/generated/prisma/models/HermesProviderConfig.js +2 -0
- package/dist/db/generated/prisma/models/HermesRegistryClient.js +2 -0
- package/dist/db/generated/prisma/models/HermesRegistryInventory.js +2 -0
- package/dist/db/generated/prisma/models/HermesRegistryReceipt.js +2 -0
- package/dist/db/generated/prisma/models/HermesRegistryRevision.js +2 -0
- package/dist/db/generated/prisma/models/HermesRegistryTarget.js +2 -0
- package/dist/db/generated/prisma/models/HermesRole.js +2 -0
- package/dist/db/generated/prisma/models/HermesRoleApplication.js +2 -0
- package/dist/db/generated/prisma/models/HermesSkillAssignment.js +2 -0
- package/dist/db/generated/prisma/models/HermesToolsetPolicy.js +2 -0
- package/dist/db/generated/prisma/models/IncidentLesson.js +2 -0
- package/dist/db/generated/prisma/models/LibraryCategory.js +2 -0
- package/dist/db/generated/prisma/models/LibraryFile.js +2 -0
- package/dist/db/generated/prisma/models/LogEntry.js +2 -0
- package/dist/db/generated/prisma/models/MagnusReleaseCanary.js +2 -0
- package/dist/db/generated/prisma/models/MaintenanceWindow.js +2 -0
- package/dist/db/generated/prisma/models/ManagedCronDefinition.js +2 -0
- package/dist/db/generated/prisma/models/ManagedCronOccurrence.js +2 -0
- package/dist/db/generated/prisma/models/Node.js +2 -0
- package/dist/db/generated/prisma/models/Notification.js +2 -0
- package/dist/db/generated/prisma/models/NotificationPreference.js +2 -0
- package/dist/db/generated/prisma/models/RemediationExecution.js +2 -0
- package/dist/db/generated/prisma/models/RemediationRule.js +2 -0
- package/dist/db/generated/prisma/models/RemoteCommand.js +2 -0
- package/dist/db/generated/prisma/models/ResourceDrainParticipant.js +2 -0
- package/dist/db/generated/prisma/models/ResourceEnrollment.js +2 -0
- package/dist/db/generated/prisma/models/ResourceParticipantWork.js +2 -0
- package/dist/db/generated/prisma/models/Role.js +2 -0
- package/dist/db/generated/prisma/models/RoleApplication.js +2 -0
- package/dist/db/generated/prisma/models/RolloutTarget.js +2 -0
- package/dist/db/generated/prisma/models/SecurityExportOutbox.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionAction.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionActionApproval.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCase.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCaseActivity.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCaseEntity.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCaseEvent.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCaseRelationship.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCollector.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCommandOutbox.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionDeletionReceipt.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionDelivery.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionEntity.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionEntityAlias.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionEvent.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionEventEntity.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionEvidence.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionInvestigation.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionNonce.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionReceiptChainHead.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionRuleVersion.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionSourceState.js +2 -0
- package/dist/db/generated/prisma/models/SecurityServiceState.js +2 -0
- package/dist/db/generated/prisma/models/SharedResourceFence.js +2 -0
- package/dist/db/generated/prisma/models/SharedResourceLease.js +2 -0
- package/dist/db/generated/prisma/models/SharedResourceLeaseResource.js +2 -0
- package/dist/db/generated/prisma/models/SkillInstallation.js +2 -0
- package/dist/db/generated/prisma/models/SkillRegistryEntry.js +2 -0
- package/dist/db/generated/prisma/models/SkillTag.js +2 -0
- package/dist/db/generated/prisma/models/SkillVersion.js +2 -0
- package/dist/db/generated/prisma/models/TeamApprovalDecision.js +2 -0
- package/dist/db/generated/prisma/models/User.js +2 -0
- package/dist/db/generated/prisma/models/WebhookDelivery.js +2 -0
- package/dist/db/generated/prisma/models/WebhookEndpoint.js +2 -0
- package/dist/db/generated/prisma/models.js +2 -0
- package/dist/db/index.js +3 -0
- package/dist/db/read-retry.js +35 -0
- package/dist/db/seed.js +348 -0
- package/dist/index.js +162 -0
- package/dist/middleware/auth.js +361 -0
- package/dist/middleware/body-limit.js +14 -0
- package/dist/middleware/correlation-id.js +13 -0
- package/dist/middleware/error-handler.js +28 -0
- package/dist/middleware/iam-token.js +21 -0
- package/dist/middleware/rate-limit.js +78 -0
- package/dist/middleware/request-logger.js +85 -0
- package/dist/middleware/security-headers.js +23 -0
- package/dist/middleware/tracing.js +120 -0
- package/dist/middleware/user-status.js +33 -0
- package/dist/openapi/spec.js +2656 -0
- package/dist/queue/redis.js +20 -0
- package/dist/queue/requeue.js +27 -0
- package/dist/queue/workers.js +342 -0
- package/dist/routes/ai-schedule.js +73 -0
- package/dist/routes/alerts.js +79 -0
- package/dist/routes/anomalies.js +101 -0
- package/dist/routes/ardent.js +82 -0
- package/dist/routes/assistant.js +417 -0
- package/dist/routes/audit.js +138 -0
- package/dist/routes/codex.js +65 -0
- package/dist/routes/commands.js +226 -0
- package/dist/routes/credentials.js +58 -0
- package/dist/routes/cron.js +292 -0
- package/dist/routes/dependencies.js +49 -0
- package/dist/routes/deploy.js +18 -0
- package/dist/routes/discovery.js +168 -0
- package/dist/routes/docs.js +24 -0
- package/dist/routes/drift.js +126 -0
- package/dist/routes/events-stream.js +87 -0
- package/dist/routes/files.js +214 -0
- package/dist/routes/fleet-checks.js +21 -0
- package/dist/routes/health.js +133 -0
- package/dist/routes/heartbeat.js +545 -0
- package/dist/routes/hermes-registry.js +278 -0
- package/dist/routes/hermes.js +61 -0
- package/dist/routes/library.js +402 -0
- package/dist/routes/logs.js +172 -0
- package/dist/routes/managed-cron.js +23 -0
- package/dist/routes/mcp.js +39 -0
- package/dist/routes/metrics.js +187 -0
- package/dist/routes/nodes.js +951 -0
- package/dist/routes/notifications.js +130 -0
- package/dist/routes/ops.js +258 -0
- package/dist/routes/orchestra.js +430 -0
- package/dist/routes/predictions.js +23 -0
- package/dist/routes/profiling.js +68 -0
- package/dist/routes/quick-command.js +72 -0
- package/dist/routes/remediation.js +111 -0
- package/dist/routes/resource-leases.js +297 -0
- package/dist/routes/roles.js +370 -0
- package/dist/routes/rollout.js +124 -0
- package/dist/routes/scan.js +116 -0
- package/dist/routes/security-backup.js +58 -0
- package/dist/routes/security-fusion.js +605 -0
- package/dist/routes/security-integration.js +71 -0
- package/dist/routes/self-update.js +129 -0
- package/dist/routes/shared-resource-leases.js +78 -0
- package/dist/routes/skills.js +485 -0
- package/dist/routes/stats.js +96 -0
- package/dist/routes/team-approvals.js +23 -0
- package/dist/routes/terminal-ticket.js +15 -0
- package/dist/routes/terminal.js +17 -0
- package/dist/routes/topology.js +37 -0
- package/dist/routes/users.js +219 -0
- package/dist/routes/webhooks.js +137 -0
- package/dist/schemas/command-reconciliation.js +14 -0
- package/dist/schemas/commands.js +51 -0
- package/dist/schemas/cron.js +33 -0
- package/dist/schemas/deploy.js +20 -0
- package/dist/schemas/files.js +14 -0
- package/dist/schemas/hermes.js +69 -0
- package/dist/schemas/index.js +11 -0
- package/dist/schemas/library.js +48 -0
- package/dist/schemas/logs.js +35 -0
- package/dist/schemas/managed-cron.js +127 -0
- package/dist/schemas/node-responses.js +87 -0
- package/dist/schemas/node-session-receipt.js +84 -0
- package/dist/schemas/nodes.js +36 -0
- package/dist/schemas/orchestra.js +118 -0
- package/dist/schemas/resource-participant-reconciliation.js +99 -0
- package/dist/schemas/roles.js +54 -0
- package/dist/schemas/shared-resource-lease.js +132 -0
- package/dist/schemas/skills.js +44 -0
- package/dist/schemas/users.js +28 -0
- package/dist/scripts/run-disposable-recovery-exercise.js +39 -0
- package/dist/sdk/index.js +2 -0
- package/dist/sdk/node-api-client.js +474 -0
- package/dist/security/approval-assertion.js +66 -0
- package/dist/security/command-completion-registry.js +35 -0
- package/dist/security/command-request.js +12 -0
- package/dist/security/command-result-signature.js +34 -0
- package/dist/security/managed-http.js +45 -0
- package/dist/security/native-completion-registry.js +44 -0
- package/dist/server.js +178 -0
- package/dist/services/admission-fence.js +71 -0
- package/dist/services/ai-assistant-service.js +2523 -0
- package/dist/services/ai-correlation-service.js +225 -0
- package/dist/services/ai-export-service.js +141 -0
- package/dist/services/ai-insights-service.js +219 -0
- package/dist/services/ai-schedule-service.js +145 -0
- package/dist/services/ai-scratchpad-service.js +222 -0
- package/dist/services/ai-tools.js +1343 -0
- package/dist/services/alert-service.js +313 -0
- package/dist/services/anomaly-detector.js +419 -0
- package/dist/services/api-local-work.js +79 -0
- package/dist/services/application-probes.js +309 -0
- package/dist/services/ardent-scope-enrollment.js +123 -0
- package/dist/services/ardent-service.js +86 -0
- package/dist/services/audit-service.js +308 -0
- package/dist/services/codex-service.js +209 -0
- package/dist/services/command-lifecycle.js +60 -0
- package/dist/services/command-resource-leases.js +305 -0
- package/dist/services/control-host-node.js +242 -0
- package/dist/services/credential-rotation-service.js +294 -0
- package/dist/services/dependency-service.js +145 -0
- package/dist/services/disposable-recovery-runner.js +595 -0
- package/dist/services/docker-group-health.js +121 -0
- package/dist/services/engineering-assurance.js +492 -0
- package/dist/services/engineering-evidence-ledger.js +94 -0
- package/dist/services/engineering-metric-evidence.js +26 -0
- package/dist/services/event-bus.js +227 -0
- package/dist/services/fleet-check-log.js +102 -0
- package/dist/services/forecast-service.js +154 -0
- package/dist/services/health-retention.js +175 -0
- package/dist/services/heartbeat-stream.js +63 -0
- package/dist/services/hermes-catalog-import.js +62 -0
- package/dist/services/hermes-cli-parser.js +671 -0
- package/dist/services/hermes-core-rollout.js +90 -0
- package/dist/services/hermes-dashboard-endpoint.js +13 -0
- package/dist/services/hermes-plugin-source.js +149 -0
- package/dist/services/hermes-registry-service.js +258 -0
- package/dist/services/hermes-service.js +566 -0
- package/dist/services/hivemem-client.js +85 -0
- package/dist/services/host-local-writer.js +82 -0
- package/dist/services/incident-evidence.js +110 -0
- package/dist/services/incident-lessons.js +186 -0
- package/dist/services/llm-providers/anthropic.js +143 -0
- package/dist/services/llm-providers/index.js +7 -0
- package/dist/services/llm-providers/llama-cpp.js +237 -0
- package/dist/services/llm-providers/ollama.js +292 -0
- package/dist/services/llm-providers/openai-compatible.js +200 -0
- package/dist/services/llm-providers/provider-error.js +36 -0
- package/dist/services/llm-providers/registry.js +45 -0
- package/dist/services/llm-providers/types.js +2 -0
- package/dist/services/log-emitter.js +19 -0
- package/dist/services/log-retention.js +66 -0
- package/dist/services/maintenance-service.js +29 -0
- package/dist/services/managed-cron.js +493 -0
- package/dist/services/managed-ssh-admission.js +68 -0
- package/dist/services/monitor-pulse.js +10 -0
- package/dist/services/node-issue-monitor.js +71 -0
- package/dist/services/node-service.js +35 -0
- package/dist/services/notification-retention.js +51 -0
- package/dist/services/notification-service.js +94 -0
- package/dist/services/operational-observations.js +112 -0
- package/dist/services/operations-config.js +67 -0
- package/dist/services/ops-service.js +491 -0
- package/dist/services/orchestra-extras-service.js +370 -0
- package/dist/services/orchestra-resources-service.js +530 -0
- package/dist/services/os-scheduler-writer.js +73 -0
- package/dist/services/password-service.js +22 -0
- package/dist/services/prediction-service.js +284 -0
- package/dist/services/recovery-exercises.js +682 -0
- package/dist/services/remediation-service.js +325 -0
- package/dist/services/resource-enrollment.js +433 -0
- package/dist/services/resource-node-lock.js +18 -0
- package/dist/services/resource-participant-work.js +302 -0
- package/dist/services/role-service.js +388 -0
- package/dist/services/rollout-service.js +440 -0
- package/dist/services/security-export.js +185 -0
- package/dist/services/security-fusion-actions.js +22 -0
- package/dist/services/security-fusion-approvals.js +83 -0
- package/dist/services/security-fusion-evidence-integrity.js +144 -0
- package/dist/services/security-fusion-ingest.js +101 -0
- package/dist/services/security-fusion-outbox.js +185 -0
- package/dist/services/security-fusion-receipt-chain.js +134 -0
- package/dist/services/security-fusion-service.js +751 -0
- package/dist/services/security-fusion-verification.js +50 -0
- package/dist/services/self-update-service.js +200 -0
- package/dist/services/shared-resource-leases.js +413 -0
- package/dist/services/skill-publication-bundle.js +90 -0
- package/dist/services/skill-publication-settlement.js +36 -0
- package/dist/services/skill-publication-state.js +40 -0
- package/dist/services/skill-registry-service.js +327 -0
- package/dist/services/skill-service.js +148 -0
- package/dist/services/ssh-exec-service.js +139 -0
- package/dist/services/ssh-host-verification.js +27 -0
- package/dist/services/tailscale-node-key-service.js +75 -0
- package/dist/services/team-approvals.js +118 -0
- package/dist/services/topology-service.js +138 -0
- package/dist/services/transfer-authority-snapshot.js +151 -0
- package/dist/services/webhook-credential-migration.js +97 -0
- package/dist/services/webhook-security.js +242 -0
- package/dist/services/webhook-service.js +494 -0
- package/dist/types/auth.js +3 -0
- package/dist/types/index.js +3 -0
- package/dist/types/library.js +3 -0
- package/dist/types/notifications.js +3 -0
- package/dist/types/roles.js +3 -0
- package/dist/types/shared-contracts.js +3 -0
- package/dist/utils/env.js +141 -0
- package/dist/utils/heartbeat-peer.js +19 -0
- package/dist/utils/idempotency.js +45 -0
- package/dist/utils/ip.js +25 -0
- package/dist/utils/json-fields.js +94 -0
- package/dist/utils/local-tls.js +39 -0
- package/dist/utils/magnus-home.js +15 -0
- package/dist/utils/node-url.js +59 -0
- package/dist/utils/redact.js +26 -0
- package/dist/utils/safe-equal.js +13 -0
- package/dist/utils/sentinel-nodes.js +16 -0
- package/dist/utils/validate.js +41 -0
- package/package.json +119 -4
- package/prisma/migrations/20261031000000_baseline/migration.sql +2935 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +2185 -0
- package/prisma.config.ts +14 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getDb } from '../db/index.js';
|
|
4
|
+
import { authMiddleware, getUser, requireRole } from '../middleware/auth.js';
|
|
5
|
+
import { HttpError } from '../middleware/error-handler.js';
|
|
6
|
+
import { parseBody } from '../utils/validate.js';
|
|
7
|
+
import { logAuditEvent } from '../services/audit-service.js';
|
|
8
|
+
import { authenticateRegistryToken, assignSkillTargets, desiredManifest, enrollClient, identity, publishRevision, registryKind, isDeployHost } from '../services/hermes-registry-service.js';
|
|
9
|
+
import { requestCoreSlot, settleCoreSlot } from '../services/hermes-core-rollout.js';
|
|
10
|
+
import { refreshTrackedSources } from '../services/hermes-plugin-source.js';
|
|
11
|
+
export const hermesRegistryRouter = new Hono();
|
|
12
|
+
const client = (c, scope) => authenticateRegistryToken(c.req.header('x-hermes-registry-token'), scope);
|
|
13
|
+
hermesRegistryRouter.post('/clients', authMiddleware, requireRole('ADMIN'), async (c) => {
|
|
14
|
+
const body = await parseBody(c, z.object({ nodeId: z.string(), installationId: z.string(), canSubmit: z.boolean().default(true) }));
|
|
15
|
+
const result = await enrollClient(body.nodeId, body.installationId, body.canSubmit);
|
|
16
|
+
await logAuditEvent({ action: 'hermes.registry.enroll', actorId: getUser(c).userId, targetType: 'hermes-installation', targetId: body.installationId,
|
|
17
|
+
details: { host: result.host, canPull: result.canPull, canSubmit: result.canSubmit } });
|
|
18
|
+
return c.json({ success: true, data: result }, 201);
|
|
19
|
+
});
|
|
20
|
+
hermesRegistryRouter.get('/manifest', async (c) => {
|
|
21
|
+
const { installation } = await client(c, 'pull');
|
|
22
|
+
return c.json({ success: true, data: { installationId: installation.id, components: await desiredManifest(installation.id) } });
|
|
23
|
+
});
|
|
24
|
+
hermesRegistryRouter.post('/core/slot', async (c) => {
|
|
25
|
+
const { host, installation } = await client(c, 'pull');
|
|
26
|
+
return c.json({ success: true, data: { ...await requestCoreSlot(host, installation.id), hermesHome: installation.hermesHome,
|
|
27
|
+
hermesBin: installation.hermesBin } });
|
|
28
|
+
});
|
|
29
|
+
hermesRegistryRouter.post('/core/receipts', async (c) => {
|
|
30
|
+
const { host, installation } = await client(c, 'pull');
|
|
31
|
+
const body = await parseBody(c, z.object({ commit: z.string().regex(/^[a-f0-9]{40}$/), status: z.enum(['applied', 'failed']),
|
|
32
|
+
evidence: z.object({ beforeVersion: z.string().max(100).optional(), afterVersion: z.string().max(100).optional(),
|
|
33
|
+
beforeGatewayActive: z.boolean().optional(), afterGatewayActive: z.boolean().optional(), backupSha256: z.string().regex(/^[a-f0-9]{64}$/).optional(),
|
|
34
|
+
nativeReceiptSha256: z.string().regex(/^[a-f0-9]{64}$/).optional(), toolCheck: z.boolean().optional(), pluginCheck: z.boolean().optional(),
|
|
35
|
+
error: z.string().max(500).optional() }) }));
|
|
36
|
+
return c.json({ success: true, data: await settleCoreSlot(host, installation.id, body) });
|
|
37
|
+
});
|
|
38
|
+
hermesRegistryRouter.get('/profiles', async (c) => {
|
|
39
|
+
const { installation } = await client(c, 'submit');
|
|
40
|
+
const profiles = await getDb().hermesProfile.findMany({ where: { installationId: installation.id }, select: { id: true, profileHome: true } });
|
|
41
|
+
return c.json({ success: true, data: { installationId: installation.id, hermesBin: installation.hermesBin,
|
|
42
|
+
profiles: profiles.length ? profiles : [{ id: '', profileHome: installation.hermesHome }] } });
|
|
43
|
+
});
|
|
44
|
+
hermesRegistryRouter.post('/tool-surface', async (c) => {
|
|
45
|
+
const { installation } = await client(c, 'pull');
|
|
46
|
+
const body = await parseBody(c, z.object({ profileId: z.string().default(''), surface: z.array(z.object({
|
|
47
|
+
platform: identity, enabled: z.array(z.string().min(1).max(120)).max(250),
|
|
48
|
+
})).min(1).max(16) }));
|
|
49
|
+
const profile = body.profileId ? await getDb().hermesProfile.findFirst({ where: { id: body.profileId, installationId: installation.id } }) : null;
|
|
50
|
+
if (body.profileId && !profile)
|
|
51
|
+
throw new HttpError(403, 'INVALID_PROFILE', 'Tool surface profile is not on this installation');
|
|
52
|
+
if (profile) {
|
|
53
|
+
let capabilities = {};
|
|
54
|
+
try {
|
|
55
|
+
capabilities = JSON.parse(profile.capabilities);
|
|
56
|
+
}
|
|
57
|
+
catch { /* replace malformed inventory */ }
|
|
58
|
+
await getDb().hermesProfile.update({ where: { id: profile.id }, data: { capabilities: JSON.stringify({ ...capabilities,
|
|
59
|
+
toolSurface: body.surface, toolSurfaceObservedAt: new Date().toISOString() }) } });
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
let raw = {};
|
|
63
|
+
try {
|
|
64
|
+
raw = JSON.parse(installation.rawStatus);
|
|
65
|
+
}
|
|
66
|
+
catch { /* replace malformed inventory */ }
|
|
67
|
+
await getDb().hermesInstallation.update({ where: { id: installation.id }, data: { rawStatus: JSON.stringify({ ...raw,
|
|
68
|
+
toolSurface: body.surface, toolSurfaceObservedAt: new Date().toISOString() }) } });
|
|
69
|
+
}
|
|
70
|
+
return c.json({ success: true, data: { profileId: body.profileId, platforms: body.surface.length } });
|
|
71
|
+
});
|
|
72
|
+
hermesRegistryRouter.get('/policy', async (c) => {
|
|
73
|
+
const { installation } = await client(c, 'pull');
|
|
74
|
+
const profiles = await getDb().hermesProfile.findMany({ where: { installationId: installation.id }, select: { id: true, profileHome: true } });
|
|
75
|
+
const homes = new Map(profiles.map(profile => [profile.id, profile.profileHome]));
|
|
76
|
+
const rows = await getDb().hermesToolsetPolicy.findMany({ where: { installationId: installation.id } });
|
|
77
|
+
const policies = rows.map(row => {
|
|
78
|
+
let metadata = {};
|
|
79
|
+
try {
|
|
80
|
+
metadata = JSON.parse(row.metadata);
|
|
81
|
+
}
|
|
82
|
+
catch { /* malformed metadata is ignored */ }
|
|
83
|
+
const platforms = Array.isArray(metadata['platforms']) ? metadata['platforms'].filter(value => typeof value === 'string' && identity.safeParse(value).success) : ['cli'];
|
|
84
|
+
return { id: row.id, profileId: row.profileId, profileHome: row.profileId ? homes.get(row.profileId) ?? '' : installation.hermesHome,
|
|
85
|
+
hermesBin: installation.hermesBin, toolset: row.toolset, enabled: row.enabled, platforms, approvalMode: row.approvalMode,
|
|
86
|
+
perToolHooks: JSON.parse(row.perToolHooks), allowList: JSON.parse(row.allowList),
|
|
87
|
+
denyList: JSON.parse(row.denyList) };
|
|
88
|
+
}).filter(row => !!row.profileHome);
|
|
89
|
+
return c.json({ success: true, data: { policies } });
|
|
90
|
+
});
|
|
91
|
+
hermesRegistryRouter.post('/policy/receipts', async (c) => {
|
|
92
|
+
const { installation } = await client(c, 'pull');
|
|
93
|
+
const body = await parseBody(c, z.object({ id: z.string(), status: z.enum(['applied', 'failed', 'unsupported']), error: z.string().max(500).optional() }));
|
|
94
|
+
const row = await getDb().hermesToolsetPolicy.findUnique({ where: { id: body.id } });
|
|
95
|
+
if (!row || row.installationId !== installation.id)
|
|
96
|
+
throw new HttpError(403, 'INVALID_POLICY', 'Policy is outside this installation');
|
|
97
|
+
await getDb().hermesToolsetPolicy.update({ where: { id: row.id }, data: { status: body.status, lastSyncedAt: new Date(),
|
|
98
|
+
metadata: JSON.stringify({ ...JSON.parse(row.metadata), lastRegistryError: body.error ?? null }) } });
|
|
99
|
+
return c.json({ success: true, data: { id: row.id, status: body.status } });
|
|
100
|
+
});
|
|
101
|
+
hermesRegistryRouter.get('/artifacts/:kind/:slug/:revision', async (c) => {
|
|
102
|
+
const { installation } = await client(c, 'pull');
|
|
103
|
+
const kind = registryKind.parse(c.req.param('kind'));
|
|
104
|
+
const slug = identity.parse(c.req.param('slug'));
|
|
105
|
+
const number = z.coerce.number().int().positive().parse(c.req.param('revision'));
|
|
106
|
+
const allowed = (await desiredManifest(installation.id)).some(item => item.kind === kind && item.slug === slug && item.revision === number);
|
|
107
|
+
if (!allowed)
|
|
108
|
+
throw new HttpError(403, 'REGISTRY_TARGET_REQUIRED', 'Artifact is not assigned to this installation');
|
|
109
|
+
const revision = await getDb().hermesRegistryRevision.findUnique({ where: { kind_slug_revision: { kind, slug, revision: number } } });
|
|
110
|
+
if (!revision || revision.status !== 'published')
|
|
111
|
+
throw new HttpError(404, 'NOT_FOUND', 'Published artifact not found');
|
|
112
|
+
return c.json({ success: true, data: { kind, slug, revision: number, sha256: revision.sha256, artifact: JSON.parse(revision.artifactJson) } });
|
|
113
|
+
});
|
|
114
|
+
hermesRegistryRouter.post('/capture', async (c) => {
|
|
115
|
+
const { installation, host } = await client(c, 'submit');
|
|
116
|
+
const body = await parseBody(c, z.object({ slug: identity, profileId: z.string().default(''), artifact: z.unknown().optional(),
|
|
117
|
+
baseRevision: z.number().int().nonnegative().optional(), tags: z.array(identity).max(32).default([]) }));
|
|
118
|
+
if (body.profileId && !(await getDb().hermesProfile.findFirst({ where: { id: body.profileId, installationId: installation.id } })))
|
|
119
|
+
throw new HttpError(403, 'INVALID_PROFILE', 'Profile does not belong to this installation');
|
|
120
|
+
const result = await publishRevision({ kind: 'skill', slug: body.slug, artifact: body.artifact, metadata: { tags: body.tags, authorProfileId: body.profileId },
|
|
121
|
+
sourceHost: host, publishedBy: `node:${installation.id}`, baseRevision: body.baseRevision });
|
|
122
|
+
if (!result.duplicate && result.revision.status === 'published') {
|
|
123
|
+
await assignSkillTargets(body.slug, body.tags, body.profileId, host);
|
|
124
|
+
}
|
|
125
|
+
await logAuditEvent({ action: 'hermes.registry.capture', actorId: `node:${installation.id}`, targetType: 'hermes-skill', targetId: body.slug,
|
|
126
|
+
details: { revision: result.revision.revision, status: result.revision.status, duplicate: result.duplicate, host } });
|
|
127
|
+
return c.json({ success: true, data: { revision: result.revision.revision, sha256: result.revision.sha256, status: result.revision.status, duplicate: result.duplicate } }, result.duplicate ? 200 : 201);
|
|
128
|
+
});
|
|
129
|
+
hermesRegistryRouter.post('/receipts', async (c) => {
|
|
130
|
+
const { installation, node } = await client(c, 'pull');
|
|
131
|
+
const body = await parseBody(c, z.object({ kind: registryKind, slug: identity, profileId: z.string().default(''), revision: z.number().int().positive(),
|
|
132
|
+
sha256: z.string().regex(/^[a-f0-9]{64}$/), status: z.enum(['applied', 'drifted', 'failed', 'busy', 'unsupported']), details: z.record(z.string(), z.unknown()).default({}) }));
|
|
133
|
+
const target = await getDb().hermesRegistryTarget.findUnique({ where: { kind_slug_installationId_profileId: {
|
|
134
|
+
kind: body.kind, slug: body.slug, installationId: installation.id, profileId: body.profileId
|
|
135
|
+
} } });
|
|
136
|
+
const revision = await getDb().hermesRegistryRevision.findUnique({ where: { kind_slug_revision: { kind: body.kind, slug: body.slug, revision: body.revision } } });
|
|
137
|
+
if (!target || !revision || revision.sha256 !== body.sha256)
|
|
138
|
+
throw new HttpError(403, 'REGISTRY_RECEIPT_INVALID', 'Receipt does not match an assigned revision');
|
|
139
|
+
const desired = (await desiredManifest(installation.id)).find(item => item.kind === body.kind && item.slug === body.slug
|
|
140
|
+
&& item.profileId === body.profileId);
|
|
141
|
+
if (!desired || desired.revision !== body.revision || desired.sha256 !== body.sha256)
|
|
142
|
+
throw new HttpError(409, 'REGISTRY_RECEIPT_STALE', 'Receipt no longer matches the desired immutable revision');
|
|
143
|
+
const data = await getDb().hermesRegistryReceipt.create({ data: { nodeId: node.id, installationId: installation.id, profileId: body.profileId,
|
|
144
|
+
kind: body.kind, slug: body.slug, revision: body.revision, sha256: body.sha256, status: body.status,
|
|
145
|
+
detailsJson: JSON.stringify(body.details) } });
|
|
146
|
+
await getDb().hermesRegistryTarget.update({ where: { id: target.id }, data: { observedRevision: body.status === 'applied' ? body.revision : target.observedRevision,
|
|
147
|
+
status: body.status, lastReceiptAt: data.createdAt, error: body.status === 'applied' ? null : String(body.details['error'] ?? body.status).slice(0, 500) } });
|
|
148
|
+
return c.json({ success: true, data: { receiptId: data.id } }, 201);
|
|
149
|
+
});
|
|
150
|
+
hermesRegistryRouter.post('/inventory', async (c) => {
|
|
151
|
+
const { installation } = await client(c, 'pull');
|
|
152
|
+
const item = z.object({ profileId: z.string().default(''), kind: z.enum(['plugin', 'mcp']), slug: identity,
|
|
153
|
+
pluginType: z.enum(['general', 'memory-provider', 'context-engine', 'transport', 'provider']).nullable().default(null),
|
|
154
|
+
sourceKind: z.enum(['bundled', 'git', 'pip', 'local', 'remote', 'unknown']), sourceUrl: z.string().url().nullable().default(null),
|
|
155
|
+
commit: z.string().regex(/^[a-f0-9]{40}$/).nullable().default(null), version: z.string().max(100).nullable().default(null),
|
|
156
|
+
status: z.string().max(100) });
|
|
157
|
+
const body = await parseBody(c, z.object({ items: z.array(item).max(500) }));
|
|
158
|
+
for (const observed of body.items) {
|
|
159
|
+
if (observed.sourceUrl) {
|
|
160
|
+
const source = new URL(observed.sourceUrl);
|
|
161
|
+
if (source.protocol !== 'https:' || source.username || source.password || source.search || source.hash)
|
|
162
|
+
throw new HttpError(400, 'INVALID_SOURCE', 'Inventory source URL must be public and free of credentials');
|
|
163
|
+
}
|
|
164
|
+
if (observed.profileId && !(await getDb().hermesProfile.findFirst({ where: { id: observed.profileId, installationId: installation.id } })))
|
|
165
|
+
throw new HttpError(403, 'INVALID_PROFILE', 'Inventory profile is not on this installation');
|
|
166
|
+
await getDb().hermesRegistryInventory.upsert({ where: { installationId_profileId_kind_slug: { installationId: installation.id,
|
|
167
|
+
profileId: observed.profileId, kind: observed.kind, slug: observed.slug } },
|
|
168
|
+
create: { installationId: installation.id, ...observed }, update: { ...observed, observedAt: new Date() } });
|
|
169
|
+
}
|
|
170
|
+
return c.json({ success: true, data: { count: body.items.length } });
|
|
171
|
+
});
|
|
172
|
+
hermesRegistryRouter.post('/revisions', authMiddleware, requireRole('ADMIN', 'OPERATOR'), async (c) => {
|
|
173
|
+
const body = await parseBody(c, z.object({ kind: registryKind, slug: identity, artifact: z.unknown().optional(), metadata: z.record(z.string(), z.unknown()).default({}), baseRevision: z.number().int().nonnegative().optional() }));
|
|
174
|
+
if (body.artifact === undefined)
|
|
175
|
+
throw new HttpError(400, 'INVALID_ARTIFACT', 'Artifact is required');
|
|
176
|
+
const result = await publishRevision({ ...body, artifact: body.artifact, publishedBy: getUser(c).userId });
|
|
177
|
+
await logAuditEvent({ action: 'hermes.registry.publish', actorId: getUser(c).userId, targetType: body.kind, targetId: body.slug,
|
|
178
|
+
details: { revision: result.revision.revision, status: result.revision.status } });
|
|
179
|
+
return c.json({ success: true, data: { revision: result.revision.revision, sha256: result.revision.sha256, status: result.revision.status, duplicate: result.duplicate } }, 201);
|
|
180
|
+
});
|
|
181
|
+
hermesRegistryRouter.post('/sources/refresh', authMiddleware, requireRole('ADMIN', 'OPERATOR'), async (c) => {
|
|
182
|
+
const results = await refreshTrackedSources();
|
|
183
|
+
await logAuditEvent({ action: 'hermes.registry.publish', actorId: getUser(c).userId, targetType: 'hermes-plugin-source', targetId: 'refresh',
|
|
184
|
+
details: { results: results.map(row => ({ kind: row.kind, slug: row.slug, status: row.status, commit: row.commit })) } });
|
|
185
|
+
return c.json({ success: true, data: results });
|
|
186
|
+
});
|
|
187
|
+
hermesRegistryRouter.post('/targets', authMiddleware, requireRole('ADMIN', 'OPERATOR'), async (c) => {
|
|
188
|
+
const body = await parseBody(c, z.object({ kind: registryKind, slug: identity, installationId: z.string(), profileId: z.string().default(''),
|
|
189
|
+
pinnedRevision: z.number().int().positive().nullable().default(null), enabled: z.boolean().default(true) }));
|
|
190
|
+
const installation = await getDb().hermesInstallation.findUnique({ where: { id: body.installationId } });
|
|
191
|
+
if (!installation || !isDeployHost(installation.hostname.split('.')[0].toLowerCase()))
|
|
192
|
+
throw new HttpError(403, 'REGISTRY_PULL_DISABLED', 'Only named rollout hosts may be assigned');
|
|
193
|
+
if (body.profileId && !(await getDb().hermesProfile.findFirst({ where: { id: body.profileId, installationId: body.installationId } })))
|
|
194
|
+
throw new HttpError(400, 'INVALID_PROFILE', 'Profile is not on the target installation');
|
|
195
|
+
if (body.pinnedRevision !== null && !(await getDb().hermesRegistryRevision.findFirst({ where: {
|
|
196
|
+
kind: body.kind, slug: body.slug, revision: body.pinnedRevision, status: 'published'
|
|
197
|
+
} })))
|
|
198
|
+
throw new HttpError(400, 'INVALID_PIN', 'Pinned revision is not published');
|
|
199
|
+
if (body.kind === 'plugin' && body.enabled) {
|
|
200
|
+
const release = await getDb().hermesRegistryRevision.findFirst({ where: { kind: 'plugin', slug: body.slug, status: 'published',
|
|
201
|
+
...(body.pinnedRevision === null ? {} : { revision: body.pinnedRevision }) }, orderBy: { revision: 'desc' } });
|
|
202
|
+
if (!release)
|
|
203
|
+
throw new HttpError(400, 'INVALID_TARGET', 'Plugin has no published release');
|
|
204
|
+
if (JSON.parse(release.metadataJson)['consentRequiresPreinstalledTarget'] === true) {
|
|
205
|
+
const commit = JSON.parse(release.artifactJson).commit;
|
|
206
|
+
const installed = await getDb().hermesRegistryInventory.findUnique({ where: { installationId_profileId_kind_slug: {
|
|
207
|
+
installationId: body.installationId, profileId: body.profileId, kind: 'plugin', slug: body.slug
|
|
208
|
+
} } });
|
|
209
|
+
if (!installed || installed.commit !== commit || !/^(enabled|loaded|active)$/i.test(installed.status.trim()))
|
|
210
|
+
throw new HttpError(409, 'CONSENT_NOT_INSTALLED', 'Target must install the consented plugin commit interactively before enrollment');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (body.kind === 'mcp') {
|
|
214
|
+
const release = await getDb().hermesRegistryRevision.findFirst({ where: { kind: 'mcp', slug: body.slug, status: 'published',
|
|
215
|
+
...(body.pinnedRevision === null ? {} : { revision: body.pinnedRevision }) }, orderBy: { revision: 'desc' } });
|
|
216
|
+
if (!release || JSON.parse(release.artifactJson).ownerHost.toLowerCase() !== installation.hostname.split('.')[0].toLowerCase())
|
|
217
|
+
throw new HttpError(403, 'MCP_OWNER_MISMATCH', 'MCP backend must be assigned to its owning host');
|
|
218
|
+
}
|
|
219
|
+
const row = await getDb().hermesRegistryTarget.upsert({ where: { kind_slug_installationId_profileId: { kind: body.kind, slug: body.slug,
|
|
220
|
+
installationId: body.installationId, profileId: body.profileId } }, create: body, update: { pinnedRevision: body.pinnedRevision, enabled: body.enabled, status: 'pending' } });
|
|
221
|
+
await logAuditEvent({ action: 'hermes.registry.target', actorId: getUser(c).userId, targetType: body.kind, targetId: body.slug,
|
|
222
|
+
details: { installationId: body.installationId, profileId: body.profileId, pinnedRevision: body.pinnedRevision, enabled: body.enabled } });
|
|
223
|
+
return c.json({ success: true, data: row });
|
|
224
|
+
});
|
|
225
|
+
hermesRegistryRouter.post('/revisions/:kind/:slug/:revision/consent', authMiddleware, requireRole('ADMIN'), async (c) => {
|
|
226
|
+
const kind = registryKind.parse(c.req.param('kind'));
|
|
227
|
+
const slug = identity.parse(c.req.param('slug'));
|
|
228
|
+
const revision = z.coerce.number().int().positive().parse(c.req.param('revision'));
|
|
229
|
+
if (kind === 'skill')
|
|
230
|
+
throw new HttpError(400, 'INVALID_CONSENT', 'Skill conflicts require a new reviewed revision');
|
|
231
|
+
const body = await parseBody(c, z.object({ evidence: z.string().min(20).max(2000) }));
|
|
232
|
+
const row = await getDb().hermesRegistryRevision.findUnique({ where: { kind_slug_revision: { kind, slug, revision } } });
|
|
233
|
+
if (!row || row.status !== 'needs-consent')
|
|
234
|
+
throw new HttpError(409, 'CONSENT_NOT_PENDING', 'Revision is not waiting for consent');
|
|
235
|
+
if (kind === 'plugin') {
|
|
236
|
+
const release = JSON.parse(row.artifactJson);
|
|
237
|
+
const targets = await getDb().hermesRegistryTarget.findMany({ where: { kind: 'plugin', slug, enabled: true } });
|
|
238
|
+
const observed = await getDb().hermesRegistryInventory.findMany({ where: { kind: 'plugin', slug, commit: release.commit } });
|
|
239
|
+
const missing = targets.filter(target => !observed.some(item => item.installationId === target.installationId
|
|
240
|
+
&& item.profileId === target.profileId && /^(enabled|loaded|active)$/i.test(item.status.trim())));
|
|
241
|
+
if (missing.length)
|
|
242
|
+
throw new HttpError(409, 'CONSENT_NOT_INSTALLED', 'Each enabled target must first install this commit and grant capabilities interactively');
|
|
243
|
+
}
|
|
244
|
+
await getDb().hermesRegistryRevision.update({ where: { id: row.id }, data: { status: 'published', metadataJson: JSON.stringify({
|
|
245
|
+
...JSON.parse(row.metadataJson), consentEvidence: body.evidence, consentBy: getUser(c).userId,
|
|
246
|
+
consentRequiresPreinstalledTarget: kind === 'plugin'
|
|
247
|
+
}) } });
|
|
248
|
+
await logAuditEvent({ action: 'hermes.registry.publish', actorId: getUser(c).userId, targetType: kind, targetId: slug,
|
|
249
|
+
details: { revision, consentRecorded: true } });
|
|
250
|
+
return c.json({ success: true, data: { kind, slug, revision, status: 'published' } });
|
|
251
|
+
});
|
|
252
|
+
hermesRegistryRouter.put('/profile-groups/:profileId', authMiddleware, requireRole('ADMIN', 'OPERATOR'), async (c) => {
|
|
253
|
+
const profileId = identity.parse(c.req.param('profileId'));
|
|
254
|
+
const body = await parseBody(c, z.object({ groups: z.array(identity).max(32) }));
|
|
255
|
+
const profile = await getDb().hermesProfile.findUnique({ where: { id: profileId }, include: { installation: true } });
|
|
256
|
+
if (!profile || !isDeployHost(profile.installation.hostname.split('.')[0].toLowerCase()))
|
|
257
|
+
throw new HttpError(403, 'REGISTRY_PULL_DISABLED', 'Profile is not on a named rollout host');
|
|
258
|
+
let metadata = {};
|
|
259
|
+
try {
|
|
260
|
+
metadata = JSON.parse(profile.metadata);
|
|
261
|
+
}
|
|
262
|
+
catch { /* replace malformed metadata */ }
|
|
263
|
+
await getDb().hermesProfile.update({ where: { id: profileId }, data: { metadata: JSON.stringify({ ...metadata, groups: [...new Set(body.groups)] }) } });
|
|
264
|
+
await logAuditEvent({ action: 'hermes.registry.target', actorId: getUser(c).userId, targetType: 'hermes-profile', targetId: profileId,
|
|
265
|
+
details: { groups: body.groups } });
|
|
266
|
+
return c.json({ success: true, data: { profileId, groups: body.groups } });
|
|
267
|
+
});
|
|
268
|
+
hermesRegistryRouter.get('/status', authMiddleware, async (c) => {
|
|
269
|
+
const [targets, clients, revisions, inventory, coreRollouts] = await Promise.all([
|
|
270
|
+
getDb().hermesRegistryTarget.findMany({ orderBy: { updatedAt: 'desc' } }),
|
|
271
|
+
getDb().hermesRegistryClient.findMany({ select: { nodeId: true, installationId: true, canPull: true, canSubmit: true, enabled: true, revokedAt: true } }),
|
|
272
|
+
getDb().hermesRegistryRevision.findMany({ select: { kind: true, slug: true, revision: true, sha256: true, status: true, sourceHost: true, createdAt: true }, orderBy: { createdAt: 'desc' }, take: 500 }),
|
|
273
|
+
getDb().hermesRegistryInventory.findMany({ orderBy: { observedAt: 'desc' }, take: 1000 }),
|
|
274
|
+
getDb().hermesCoreRollout.findMany({ include: { hosts: true }, orderBy: { createdAt: 'desc' }, take: 10 }),
|
|
275
|
+
]);
|
|
276
|
+
return c.json({ success: true, data: { targets, clients, revisions, inventory, coreRollouts } });
|
|
277
|
+
});
|
|
278
|
+
//# sourceMappingURL=hermes-registry.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { authMiddleware } from '../middleware/auth.js';
|
|
3
|
+
import { HttpError } from '../middleware/error-handler.js';
|
|
4
|
+
import { hermesJobListQuerySchema } from '../schemas/hermes.js';
|
|
5
|
+
import { getHermesApiServerStatus, getHermesInstallation, getHermesJob, listHermesInstallations, listHermesJobs, listHermesProfiles, } from '../services/hermes-service.js';
|
|
6
|
+
export const hermesRouter = new Hono();
|
|
7
|
+
hermesRouter.use('*', authMiddleware);
|
|
8
|
+
function requiredParam(c, name) {
|
|
9
|
+
const value = c.req.param(name);
|
|
10
|
+
if (!value)
|
|
11
|
+
throw new HttpError(400, 'VALIDATION_ERROR', `${name} is required`);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
// Read-only inventory/status endpoints remain available because they use the
|
|
15
|
+
// Control database and never open SSH connections.
|
|
16
|
+
hermesRouter.get('/installations', async (c) => c.json({ success: true, data: await listHermesInstallations() }));
|
|
17
|
+
hermesRouter.get('/installations/:id', async (c) => {
|
|
18
|
+
const data = await getHermesInstallation(requiredParam(c, 'id'));
|
|
19
|
+
if (!data)
|
|
20
|
+
throw new HttpError(404, 'NOT_FOUND', 'Hermes installation not found');
|
|
21
|
+
return c.json({ success: true, data });
|
|
22
|
+
});
|
|
23
|
+
hermesRouter.get('/installations/:id/profiles', async (c) => {
|
|
24
|
+
const installation = await getHermesInstallation(requiredParam(c, 'id'));
|
|
25
|
+
if (!installation)
|
|
26
|
+
throw new HttpError(404, 'NOT_FOUND', 'Hermes installation not found');
|
|
27
|
+
return c.json({ success: true, data: await listHermesProfiles(installation.id) });
|
|
28
|
+
});
|
|
29
|
+
hermesRouter.get('/profiles', async (c) => c.json({ success: true, data: await listHermesProfiles() }));
|
|
30
|
+
hermesRouter.get('/profiles/:id/api-server/status', async (c) => c.json({ success: true, data: await getHermesApiServerStatus(requiredParam(c, 'id')) }));
|
|
31
|
+
hermesRouter.get('/jobs', async (c) => {
|
|
32
|
+
const parsed = hermesJobListQuerySchema.safeParse({
|
|
33
|
+
status: c.req.query('status'),
|
|
34
|
+
type: c.req.query('type'),
|
|
35
|
+
category: c.req.query('category'),
|
|
36
|
+
installationId: c.req.query('installationId'),
|
|
37
|
+
profileId: c.req.query('profileId'),
|
|
38
|
+
limit: c.req.query('limit'),
|
|
39
|
+
});
|
|
40
|
+
if (!parsed.success) {
|
|
41
|
+
throw new HttpError(400, 'VALIDATION_ERROR', parsed.error.issues.map((issue) => issue.message).join('; '));
|
|
42
|
+
}
|
|
43
|
+
return c.json({ success: true, data: await listHermesJobs(parsed.data) });
|
|
44
|
+
});
|
|
45
|
+
hermesRouter.get('/jobs/:id', async (c) => {
|
|
46
|
+
const data = await getHermesJob(requiredParam(c, 'id'));
|
|
47
|
+
if (!data)
|
|
48
|
+
throw new HttpError(404, 'NOT_FOUND', 'Hermes operation job not found');
|
|
49
|
+
return c.json({ success: true, data });
|
|
50
|
+
});
|
|
51
|
+
// SSH-backed detection, deployment, config, profile, gateway, dashboard,
|
|
52
|
+
// migration, and credential-bearing operations are retired until every call
|
|
53
|
+
// can use an inventory-pinned host key or the authenticated agent API.
|
|
54
|
+
hermesRouter.all('*', (c) => c.json({
|
|
55
|
+
success: false,
|
|
56
|
+
error: {
|
|
57
|
+
code: 'HERMES_SSH_OPERATION_RETIRED',
|
|
58
|
+
message: 'SSH-backed Hermes operations are retired; use the reviewed key-only host runbook',
|
|
59
|
+
},
|
|
60
|
+
}, 410));
|
|
61
|
+
//# sourceMappingURL=hermes.js.map
|