mergen-server 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +57 -0
- package/README.md +96 -0
- package/dist/__stubs__/calibration.js +471 -0
- package/dist/__stubs__/causal.js +601 -0
- package/dist/__stubs__/closed-source.js +150 -0
- package/dist/__stubs__/license.js +35 -0
- package/dist/__stubs__/plans.js +197 -0
- package/dist/app.js +467 -0
- package/dist/cli.js +250 -0
- package/dist/commands/agent-identity.js +79 -0
- package/dist/commands/gate.js +107 -0
- package/dist/commands/github.js +632 -0
- package/dist/commands/incident.js +644 -0
- package/dist/commands/policy.js +710 -0
- package/dist/commands/scan.js +243 -0
- package/dist/commands/setup.js +1218 -0
- package/dist/commands/shared.js +109 -0
- package/dist/commands/team.js +809 -0
- package/dist/datadog/blame-attribution.js +228 -0
- package/dist/datadog/client.js +159 -0
- package/dist/datadog/compactor.js +169 -0
- package/dist/datadog/fingerprinter.js +34 -0
- package/dist/datadog/incident-state.js +21 -0
- package/dist/datadog/line-matcher.js +56 -0
- package/dist/datadog/memory-store.js +399 -0
- package/dist/datadog/otel-trace.js +67 -0
- package/dist/index.js +505 -0
- package/dist/intelligence/action-risk.js +132 -0
- package/dist/intelligence/activity-feed.js +40 -0
- package/dist/intelligence/agent-identity.js +115 -0
- package/dist/intelligence/agent-pipeline.js +329 -0
- package/dist/intelligence/agent-profiles.js +81 -0
- package/dist/intelligence/ai-commit.js +16 -0
- package/dist/intelligence/approval-analytics.js +42 -0
- package/dist/intelligence/approval-events.js +5 -0
- package/dist/intelligence/arch-boundaries.js +94 -0
- package/dist/intelligence/arch-graph.js +117 -0
- package/dist/intelligence/autonomy.js +397 -0
- package/dist/intelligence/azure-broker.js +57 -0
- package/dist/intelligence/azure-proxy-sessions.js +49 -0
- package/dist/intelligence/baseline.js +1 -0
- package/dist/intelligence/behavior-baseline.js +134 -0
- package/dist/intelligence/billing.js +1 -0
- package/dist/intelligence/blast-radius.js +224 -0
- package/dist/intelligence/bypass.js +157 -0
- package/dist/intelligence/calibration-classifier.js +77 -0
- package/dist/intelligence/calibration-git-sync.js +74 -0
- package/dist/intelligence/calibration.js +1 -0
- package/dist/intelligence/cascade-detector.js +58 -0
- package/dist/intelligence/case-study-generator.js +126 -0
- package/dist/intelligence/causal-graph.js +126 -0
- package/dist/intelligence/causal.js +1 -0
- package/dist/intelligence/change-risk.js +102 -0
- package/dist/intelligence/compliance-report.js +134 -0
- package/dist/intelligence/confidence-report.js +85 -0
- package/dist/intelligence/corpus-to-policy.js +140 -0
- package/dist/intelligence/credential-broker.js +112 -0
- package/dist/intelligence/credential-misuse.js +39 -0
- package/dist/intelligence/debug-sessions.js +108 -0
- package/dist/intelligence/decision-escalation.js +36 -0
- package/dist/intelligence/decision-memory.js +47 -0
- package/dist/intelligence/decision-similarity.js +85 -0
- package/dist/intelligence/default-safety-tests.js +53 -0
- package/dist/intelligence/degradation-watcher.js +108 -0
- package/dist/intelligence/detector-plugins.js +70 -0
- package/dist/intelligence/detectors.js +1 -0
- package/dist/intelligence/device-auth.js +138 -0
- package/dist/intelligence/diff-size.js +42 -0
- package/dist/intelligence/ebpf-verify.js +45 -0
- package/dist/intelligence/enterprise-policy-engine.js +1122 -0
- package/dist/intelligence/error-fingerprint.js +1 -0
- package/dist/intelligence/execution-gate.js +100 -0
- package/dist/intelligence/execution-mode.js +22 -0
- package/dist/intelligence/gate-analytics.js +256 -0
- package/dist/intelligence/gate-decision.js +64 -0
- package/dist/intelligence/gcp-broker.js +50 -0
- package/dist/intelligence/git-adr-sync.js +207 -0
- package/dist/intelligence/hitl-hold.js +460 -0
- package/dist/intelligence/hypothesis-history.js +93 -0
- package/dist/intelligence/idp-identity.js +83 -0
- package/dist/intelligence/impl-critic.js +216 -0
- package/dist/intelligence/incident-autopilot.js +622 -0
- package/dist/intelligence/incident-replay.js +162 -0
- package/dist/intelligence/incident-result-cache.js +33 -0
- package/dist/intelligence/incident-similarity.js +58 -0
- package/dist/intelligence/infra-detectors.js +312 -0
- package/dist/intelligence/license.js +185 -0
- package/dist/intelligence/llm-spokesperson.js +62 -0
- package/dist/intelligence/mcp-prompts.js +320 -0
- package/dist/intelligence/mcp-resources.js +171 -0
- package/dist/intelligence/normalize.js +108 -0
- package/dist/intelligence/notifications.js +83 -0
- package/dist/intelligence/oidc-issuer.js +87 -0
- package/dist/intelligence/override-corpus.js +597 -0
- package/dist/intelligence/planning-gate.js +84 -0
- package/dist/intelligence/plans.js +223 -0
- package/dist/intelligence/platt-scaling.js +164 -0
- package/dist/intelligence/policy-proposals.js +84 -0
- package/dist/intelligence/policy-suggester.js +161 -0
- package/dist/intelligence/policy-sync.js +103 -0
- package/dist/intelligence/policy-test-runner.js +35 -0
- package/dist/intelligence/postmortem-parser.js +181 -0
- package/dist/intelligence/postmortem-retrieval.js +224 -0
- package/dist/intelligence/postmortem-store.js +596 -0
- package/dist/intelligence/pr-commenter.js +81 -0
- package/dist/intelligence/pr-policy-gate.js +38 -0
- package/dist/intelligence/pr-shadow-analyzer.js +229 -0
- package/dist/intelligence/process-tree.js +108 -0
- package/dist/intelligence/prompts.js +1 -0
- package/dist/intelligence/replay.js +38 -0
- package/dist/intelligence/repro-steps.js +1 -0
- package/dist/intelligence/resource-extractors.js +0 -0
- package/dist/intelligence/resource-file-context.js +138 -0
- package/dist/intelligence/risk-score.js +22 -0
- package/dist/intelligence/rollback.js +137 -0
- package/dist/intelligence/runbook-updater.js +143 -0
- package/dist/intelligence/sandbox.js +194 -0
- package/dist/intelligence/script-trust.js +104 -0
- package/dist/intelligence/session-metrics.js +67 -0
- package/dist/intelligence/session-threat-tracker.js +231 -0
- package/dist/intelligence/shadow-digest-cron.js +81 -0
- package/dist/intelligence/shadow-log.js +284 -0
- package/dist/intelligence/shell-ast.js +145 -0
- package/dist/intelligence/siem-forward.js +104 -0
- package/dist/intelligence/slack-digest.js +151 -0
- package/dist/intelligence/slack-override-loop.js +217 -0
- package/dist/intelligence/slack-routing.js +67 -0
- package/dist/intelligence/slack.js +900 -0
- package/dist/intelligence/sql-ast.js +31 -0
- package/dist/intelligence/team.js +1 -0
- package/dist/intelligence/telemetry.js +76 -0
- package/dist/intelligence/threshold-optimizer.js +75 -0
- package/dist/intelligence/token-budget.js +66 -0
- package/dist/intelligence/tool-guard.js +708 -0
- package/dist/intelligence/tool-manifest 2.js +74 -0
- package/dist/intelligence/tool-manifest.js +125 -0
- package/dist/intelligence/tools-analysis.js +857 -0
- package/dist/intelligence/tools-arch.js +152 -0
- package/dist/intelligence/tools-autonomy.js +495 -0
- package/dist/intelligence/tools-blast-radius.js +140 -0
- package/dist/intelligence/tools-browser.js +431 -0
- package/dist/intelligence/tools-change-timeline.js +154 -0
- package/dist/intelligence/tools-credentials.js +117 -0
- package/dist/intelligence/tools-datadog.js +233 -0
- package/dist/intelligence/tools-debug-sessions.js +209 -0
- package/dist/intelligence/tools-discovery.js +284 -0
- package/dist/intelligence/tools-infra.js +612 -0
- package/dist/intelligence/tools-intent.js +128 -0
- package/dist/intelligence/tools-memory.js +514 -0
- package/dist/intelligence/tools-runbook.js +951 -0
- package/dist/intelligence/tools-sessions.js +107 -0
- package/dist/intelligence/tools-state.js +232 -0
- package/dist/intelligence/tools-utility.js +430 -0
- package/dist/intelligence/tools-validate.js +215 -0
- package/dist/intelligence/tools.js +1 -0
- package/dist/intelligence/trace-context.js +11 -0
- package/dist/intelligence/unclassified-clusters.js +87 -0
- package/dist/intelligence/usage.js +195 -0
- package/dist/routes/active-authors.js +63 -0
- package/dist/routes/activity-feed.js +21 -0
- package/dist/routes/adr.js +117 -0
- package/dist/routes/agent-activity.js +184 -0
- package/dist/routes/agent-blunders.js +163 -0
- package/dist/routes/agents.js +175 -0
- package/dist/routes/api-keys.js +65 -0
- package/dist/routes/arch.js +75 -0
- package/dist/routes/audit-export.js +93 -0
- package/dist/routes/billing-dashboard.js +158 -0
- package/dist/routes/billing-outcome.js +77 -0
- package/dist/routes/calibration.js +305 -0
- package/dist/routes/ci-gate-history.js +20 -0
- package/dist/routes/ci-gate.js +232 -0
- package/dist/routes/ci.js +293 -0
- package/dist/routes/compliance-report.js +24 -0
- package/dist/routes/confidence.js +30 -0
- package/dist/routes/credentials.js +119 -0
- package/dist/routes/dashboard.js +1407 -0
- package/dist/routes/decision-memory.js +42 -0
- package/dist/routes/demo.js +844 -0
- package/dist/routes/device-auth-stub.js +173 -0
- package/dist/routes/explain-why.js +39 -0
- package/dist/routes/gate-analytics.js +213 -0
- package/dist/routes/gate.js +28 -0
- package/dist/routes/github-webhook.js +364 -0
- package/dist/routes/habituation.js +30 -0
- package/dist/routes/health-integrations.js +243 -0
- package/dist/routes/heartbeats.js +45 -0
- package/dist/routes/hitl.js +364 -0
- package/dist/routes/impact-report.js +645 -0
- package/dist/routes/incident-webhook.js +63 -0
- package/dist/routes/incidents.js +366 -0
- package/dist/routes/layers.js +62 -0
- package/dist/routes/license.js +187 -0
- package/dist/routes/oidc-issuer.js +30 -0
- package/dist/routes/onboarding.js +170 -0
- package/dist/routes/otel.js +67 -0
- package/dist/routes/otlp-receiver.js +179 -0
- package/dist/routes/overrides.js +241 -0
- package/dist/routes/pagerduty.js +258 -0
- package/dist/routes/policies.js +809 -0
- package/dist/routes/policy-nl.js +169 -0
- package/dist/routes/postmortem.js +102 -0
- package/dist/routes/pr-shadow.js +47 -0
- package/dist/routes/rbac.js +61 -0
- package/dist/routes/replay.js +17 -0
- package/dist/routes/risk-report.js +164 -0
- package/dist/routes/runbooks.js +125 -0
- package/dist/routes/safety-test.js +174 -0
- package/dist/routes/sdk.js +222 -0
- package/dist/routes/sensor.js +819 -0
- package/dist/routes/sentry.js +140 -0
- package/dist/routes/sessions.js +43 -0
- package/dist/routes/setup-ui.js +594 -0
- package/dist/routes/shadow-report.js +107 -0
- package/dist/routes/slack-routing.js +171 -0
- package/dist/routes/team-usage.js +71 -0
- package/dist/routes/telemetry.js +28 -0
- package/dist/routes/tenants.js +199 -0
- package/dist/routes/tickets.js +167 -0
- package/dist/routes/validate.js +13 -0
- package/dist/routes/war-room.js +113 -0
- package/dist/scripts/check-arch.js +22 -0
- package/dist/seeds/community-corpus.js +176 -0
- package/dist/seeds/corpus.js +1224 -0
- package/dist/sensor/action-ledger.js +327 -0
- package/dist/sensor/adr-store.js +140 -0
- package/dist/sensor/agent-blunder-store.js +370 -0
- package/dist/sensor/agent-context-store.js +225 -0
- package/dist/sensor/agent-memory-store.js +231 -0
- package/dist/sensor/audit-fetch.js +23 -0
- package/dist/sensor/audit-log.js +273 -0
- package/dist/sensor/buffer-schemas.js +225 -0
- package/dist/sensor/buffer.js +599 -0
- package/dist/sensor/bypass-tracker.js +93 -0
- package/dist/sensor/ci-gate-history.js +70 -0
- package/dist/sensor/cloud-auth.js +183 -0
- package/dist/sensor/commit-context-store.js +235 -0
- package/dist/sensor/docker-log-stream.js +164 -0
- package/dist/sensor/docker-monitor.js +122 -0
- package/dist/sensor/extended-buffer.js +46 -0
- package/dist/sensor/feedback-token.js +41 -0
- package/dist/sensor/file-lock.js +6 -0
- package/dist/sensor/fs-watcher.js +106 -0
- package/dist/sensor/gate-heartbeat.js +122 -0
- package/dist/sensor/git-suspect.js +136 -0
- package/dist/sensor/habituation-store.js +77 -0
- package/dist/sensor/heartbeat-monitor.js +133 -0
- package/dist/sensor/incident-store.js +340 -0
- package/dist/sensor/infra-normalizer.js +513 -0
- package/dist/sensor/ingest.js +339 -0
- package/dist/sensor/jest-reporter.js +52 -0
- package/dist/sensor/k8s-events.js +132 -0
- package/dist/sensor/layer2-store.js +111 -0
- package/dist/sensor/layer3-store.js +230 -0
- package/dist/sensor/layer4-store.js +147 -0
- package/dist/sensor/logger.js +13 -0
- package/dist/sensor/otel-exporter.js +161 -0
- package/dist/sensor/paths.js +71 -0
- package/dist/sensor/policy-history.js +147 -0
- package/dist/sensor/pr-shadow-store.js +83 -0
- package/dist/sensor/process-watcher.js +162 -0
- package/dist/sensor/rbac.js +92 -0
- package/dist/sensor/redact.js +114 -0
- package/dist/sensor/redis-store.js +191 -0
- package/dist/sensor/route-reachability.js +64 -0
- package/dist/sensor/security-utils.js +18 -0
- package/dist/sensor/service-graph.js +170 -0
- package/dist/sensor/service-topology.js +227 -0
- package/dist/sensor/session-history.js +74 -0
- package/dist/sensor/session-persist.js +38 -0
- package/dist/sensor/shadow-promote.js +122 -0
- package/dist/sensor/sourcemap.js +281 -0
- package/dist/sensor/sqlite-store.js +205 -0
- package/dist/sensor/sso.js +164 -0
- package/dist/sensor/vitest-reporter.js +65 -0
- package/dist/sensor/watcher.js +48 -0
- package/dist/storage/interfaces.js +0 -0
- package/dist/storage/pg/pg-action-ledger.js +138 -0
- package/dist/storage/pg/pg-approval-store.js +107 -0
- package/dist/storage/pg/pg-blunder-store.js +193 -0
- package/dist/storage/pg/pg-ci-gate-history.js +83 -0
- package/dist/storage/pg/pg-client.js +24 -0
- package/dist/storage/pg/pg-event-store.js +63 -0
- package/dist/storage/pg/pg-incident-store.js +190 -0
- package/dist/storage/pg/pg-migrations.js +26 -0
- package/dist/storage/pg/pg-override-corpus.js +447 -0
- package/dist/storage/pg/pg-shadow-log.js +129 -0
- package/dist/storage/sqlite/sqlite-action-ledger.js +18 -0
- package/dist/storage/sqlite/sqlite-approval-store.js +37 -0
- package/dist/storage/sqlite/sqlite-blunder-store.js +27 -0
- package/dist/storage/sqlite/sqlite-ci-gate-history.js +19 -0
- package/dist/storage/sqlite/sqlite-event-store.js +29 -0
- package/dist/storage/sqlite/sqlite-incident-store.js +34 -0
- package/dist/storage/sqlite/sqlite-override-corpus.js +75 -0
- package/dist/storage/sqlite/sqlite-shadow-log.js +36 -0
- package/dist/storage/store-factory.js +55 -0
- package/dist/storage/store-registry.js +31 -0
- package/dist/update-checker.js +107 -0
- package/dist/workers/autopilot-worker.js +28 -0
- package/dist/workers/notification-worker.js +28 -0
- package/dist/workers/queues.js +58 -0
- package/dist/workers/validation-worker.js +24 -0
- package/dist/workers/worker-registry.js +18 -0
- package/package.json +123 -0
- package/sdk/mergen-inject.js +260 -0
- package/sdk/node.js +313 -0
- package/sdk/vite-plugin.ts +57 -0
- package/sdk/webpack-plugin.js +106 -0
package/dist/app.js
ADDED
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { LRUCache } from "lru-cache";
|
|
3
|
+
import helmet from "helmet";
|
|
4
|
+
import logger from "./sensor/logger.js";
|
|
5
|
+
import { timingSafeSecretEqualAny } from "./sensor/security-utils.js";
|
|
6
|
+
import { billingRouter } from "./intelligence/billing.js";
|
|
7
|
+
import { teamRouter } from "./intelligence/team.js";
|
|
8
|
+
import { createIngestRouter } from "./sensor/ingest.js";
|
|
9
|
+
import { createSensorRouter } from "./routes/sensor.js";
|
|
10
|
+
import { createLicenseRouter } from "./routes/license.js";
|
|
11
|
+
import { createDeviceAuthStubRouter } from "./routes/device-auth-stub.js";
|
|
12
|
+
import { createCalibrationRouter } from "./routes/calibration.js";
|
|
13
|
+
import { createTelemetryRouter } from "./routes/telemetry.js";
|
|
14
|
+
import { createSetupRouter } from "./routes/setup-ui.js";
|
|
15
|
+
import { layersRouter } from "./routes/layers.js";
|
|
16
|
+
import { sentryRouter } from "./routes/sentry.js";
|
|
17
|
+
import { otelRouter } from "./routes/otel.js";
|
|
18
|
+
import { otlpReceiverRouter } from "./routes/otlp-receiver.js";
|
|
19
|
+
import { createCIRouter } from "./routes/ci.js";
|
|
20
|
+
import { createIncidentsRouter } from "./routes/incidents.js";
|
|
21
|
+
import { createTicketsRouter } from "./routes/tickets.js";
|
|
22
|
+
import { createValidateRouter } from "./routes/validate.js";
|
|
23
|
+
import { createDashboardRouter } from "./routes/dashboard.js";
|
|
24
|
+
import { createDemoRouter } from "./routes/demo.js";
|
|
25
|
+
import { createSdkRouter } from "./routes/sdk.js";
|
|
26
|
+
import { createSessionsRouter } from "./routes/sessions.js";
|
|
27
|
+
import { createPagerDutyRouter } from "./routes/pagerduty.js";
|
|
28
|
+
import { createIncidentWebhookRouter } from "./routes/incident-webhook.js";
|
|
29
|
+
import { createHeartbeatsRouter } from "./routes/heartbeats.js";
|
|
30
|
+
import { createGitHubWebhookRouter } from "./routes/github-webhook.js";
|
|
31
|
+
import { createWarRoomRouter } from "./routes/war-room.js";
|
|
32
|
+
import { createSlackRoutingRouter } from "./routes/slack-routing.js";
|
|
33
|
+
import { createApiKeysRouter } from "./routes/api-keys.js";
|
|
34
|
+
import { createTenantsRouter } from "./routes/tenants.js";
|
|
35
|
+
import { createRbacRouter } from "./routes/rbac.js";
|
|
36
|
+
import { createOverridesRouter } from "./routes/overrides.js";
|
|
37
|
+
import { createShadowReportRouter } from "./routes/shadow-report.js";
|
|
38
|
+
import { createDecisionMemoryRouter } from "./routes/decision-memory.js";
|
|
39
|
+
import { createPRShadowRouter } from "./routes/pr-shadow.js";
|
|
40
|
+
import { createImpactReportRouter } from "./routes/impact-report.js";
|
|
41
|
+
import { createBillingOutcomeRouter } from "./routes/billing-outcome.js";
|
|
42
|
+
import { createBillingDashboardRouter } from "./routes/billing-dashboard.js";
|
|
43
|
+
import { createOnboardingRouter } from "./routes/onboarding.js";
|
|
44
|
+
import { createHealthIntegrationsRouter } from "./routes/health-integrations.js";
|
|
45
|
+
import { createTeamUsageRouter } from "./routes/team-usage.js";
|
|
46
|
+
import { createActiveAuthorsRouter } from "./routes/active-authors.js";
|
|
47
|
+
import { createPostmortemRouter } from "./routes/postmortem.js";
|
|
48
|
+
import { createExplainWhyRouter } from "./routes/explain-why.js";
|
|
49
|
+
import { createAgentBlundersRouter } from "./routes/agent-blunders.js";
|
|
50
|
+
import { createHabituationRouter } from "./routes/habituation.js";
|
|
51
|
+
import { createAdrRouter } from "./routes/adr.js";
|
|
52
|
+
import { createConfidenceRouter } from "./routes/confidence.js";
|
|
53
|
+
import { createArchRouter } from "./routes/arch.js";
|
|
54
|
+
import { createRunbooksRouter } from "./routes/runbooks.js";
|
|
55
|
+
import { createCIGateRouter } from "./routes/ci-gate.js";
|
|
56
|
+
import { createCIGateHistoryRouter } from "./routes/ci-gate-history.js";
|
|
57
|
+
import { createHitlRouter } from "./routes/hitl.js";
|
|
58
|
+
import { createGateAnalyticsRouter } from "./routes/gate-analytics.js";
|
|
59
|
+
import { createPoliciesRouter } from "./routes/policies.js";
|
|
60
|
+
import { createRiskReportRouter } from "./routes/risk-report.js";
|
|
61
|
+
import { createSafetyTestRouter } from "./routes/safety-test.js";
|
|
62
|
+
import { createAgentActivityRouter } from "./routes/agent-activity.js";
|
|
63
|
+
import { createPolicyNlRouter } from "./routes/policy-nl.js";
|
|
64
|
+
import { createAgentsRouter } from "./routes/agents.js";
|
|
65
|
+
import { createActivityFeedRouter } from "./routes/activity-feed.js";
|
|
66
|
+
import { createAuditExportRouter } from "./routes/audit-export.js";
|
|
67
|
+
import { createGateRouter } from "./routes/gate.js";
|
|
68
|
+
import { createCredentialsRouter } from "./routes/credentials.js";
|
|
69
|
+
import { createReplayRouter } from "./routes/replay.js";
|
|
70
|
+
import { createOidcIssuerRouter } from "./routes/oidc-issuer.js";
|
|
71
|
+
import { createComplianceReportRouter } from "./routes/compliance-report.js";
|
|
72
|
+
import { cloudAuthMiddleware, CLOUD_MODE } from "./sensor/cloud-auth.js";
|
|
73
|
+
import { handleSlackActions, handleFeedbackLink } from "./intelligence/slack.js";
|
|
74
|
+
import { getPrometheusMetrics } from "./sensor/otel-exporter.js";
|
|
75
|
+
import { auditMiddleware } from "./sensor/audit-log.js";
|
|
76
|
+
import { ssoMiddleware } from "./sensor/sso.js";
|
|
77
|
+
import { serviceGraph } from "./sensor/service-graph.js";
|
|
78
|
+
import { routeReachability } from "./sensor/route-reachability.js";
|
|
79
|
+
import { idpIdentityMiddleware } from "./intelligence/idp-identity.js";
|
|
80
|
+
const MUTATING_PATHS = [
|
|
81
|
+
"/feedback",
|
|
82
|
+
"/license",
|
|
83
|
+
"/clear",
|
|
84
|
+
"/checkpoint",
|
|
85
|
+
"/telemetry",
|
|
86
|
+
"/otel-config",
|
|
87
|
+
"/postmortem",
|
|
88
|
+
// Incident pipeline — triggers autonomous command execution
|
|
89
|
+
"/incident",
|
|
90
|
+
// Infrastructure mutations
|
|
91
|
+
"/ci",
|
|
92
|
+
"/overrides",
|
|
93
|
+
"/rbac",
|
|
94
|
+
"/heartbeats",
|
|
95
|
+
"/slack/routing",
|
|
96
|
+
"/slack/test",
|
|
97
|
+
"/runbooks",
|
|
98
|
+
"/ci/gate",
|
|
99
|
+
"/policies",
|
|
100
|
+
// /hitl/approve and /hitl/deny are self-authenticated (HMAC nonce or x-mergen-secret
|
|
101
|
+
// handled inside createHitlRouter). Only /hitl/pending requires the global secret guard.
|
|
102
|
+
"/hitl/pending",
|
|
103
|
+
// Process / container watchers
|
|
104
|
+
"/watchers",
|
|
105
|
+
// Billing & account mutations
|
|
106
|
+
"/api-keys",
|
|
107
|
+
"/tenants",
|
|
108
|
+
"/onboarding/dismiss",
|
|
109
|
+
// Shadow report verdict → writes to override corpus (safety gate)
|
|
110
|
+
"/shadow-report",
|
|
111
|
+
// Demo injection routes → write directly to the ring buffer
|
|
112
|
+
"/demo",
|
|
113
|
+
// CLI/hook gate evaluation — same enforcement decision as an MCP tool call
|
|
114
|
+
"/gate",
|
|
115
|
+
// Ephemeral cloud credential brokering — also requires its own verified
|
|
116
|
+
// x-mergen-agent-token; the shared secret is defense-in-depth on top of that.
|
|
117
|
+
"/credentials"
|
|
118
|
+
];
|
|
119
|
+
const LOCAL_HOSTNAMES = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "::1"]);
|
|
120
|
+
function createApp(opts) {
|
|
121
|
+
const { serverVersion, localSecret, port, bindHost } = opts;
|
|
122
|
+
const app = express();
|
|
123
|
+
app.use(billingRouter);
|
|
124
|
+
app.use(sentryRouter);
|
|
125
|
+
app.use(createGitHubWebhookRouter());
|
|
126
|
+
app.use(createPagerDutyRouter());
|
|
127
|
+
app.post("/slack/actions", (req, res) => {
|
|
128
|
+
const chunks = [];
|
|
129
|
+
req.on("data", (chunk) => chunks.push(chunk));
|
|
130
|
+
req.on("end", () => {
|
|
131
|
+
const rawBody = Buffer.concat(chunks);
|
|
132
|
+
req.rawBody = rawBody;
|
|
133
|
+
const ct = (req.headers["content-type"] ?? "").toLowerCase();
|
|
134
|
+
if (ct.includes("application/x-www-form-urlencoded")) {
|
|
135
|
+
const params = new URLSearchParams(rawBody.toString("utf8"));
|
|
136
|
+
req.body = Object.fromEntries(params);
|
|
137
|
+
} else {
|
|
138
|
+
try {
|
|
139
|
+
req.body = JSON.parse(rawBody.toString("utf8"));
|
|
140
|
+
} catch {
|
|
141
|
+
req.body = {};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
void handleSlackActions(req, res);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
app.use(express.json({
|
|
148
|
+
strict: true,
|
|
149
|
+
limit: "1mb",
|
|
150
|
+
verify: (req, _res, buf) => {
|
|
151
|
+
req.rawBody = buf;
|
|
152
|
+
}
|
|
153
|
+
}));
|
|
154
|
+
app.use(auditMiddleware);
|
|
155
|
+
app.use(helmet({ contentSecurityPolicy: false, crossOriginEmbedderPolicy: false }));
|
|
156
|
+
const STRICT_CSP = "default-src 'none'; frame-ancestors 'none'";
|
|
157
|
+
const CSP_EXEMPT_PREFIXES = [
|
|
158
|
+
"/dashboard",
|
|
159
|
+
"/setup",
|
|
160
|
+
"/demo",
|
|
161
|
+
"/sdk",
|
|
162
|
+
// UI with external scripts
|
|
163
|
+
"/feedback",
|
|
164
|
+
"/billing",
|
|
165
|
+
// pages with external embeds
|
|
166
|
+
"/slack/actions",
|
|
167
|
+
// form redirect targets
|
|
168
|
+
"/hitl/approve",
|
|
169
|
+
"/hitl/deny",
|
|
170
|
+
// HTML confirmation pages
|
|
171
|
+
"/activate",
|
|
172
|
+
// device-flow activation page (inline poll script)
|
|
173
|
+
"/device"
|
|
174
|
+
// local auth-stub approval page (inline script)
|
|
175
|
+
];
|
|
176
|
+
app.use((req, res, next) => {
|
|
177
|
+
const isExempt = CSP_EXEMPT_PREFIXES.some(
|
|
178
|
+
(p) => req.path === p || req.path.startsWith(p + "/") || req.path.startsWith(p + "?")
|
|
179
|
+
);
|
|
180
|
+
if (!isExempt) {
|
|
181
|
+
res.setHeader("Content-Security-Policy", STRICT_CSP);
|
|
182
|
+
}
|
|
183
|
+
next();
|
|
184
|
+
});
|
|
185
|
+
const _lsBucket = { count: 0, resetAt: 0 };
|
|
186
|
+
app.get("/local-secret", (_req, res) => {
|
|
187
|
+
if (bindHost !== "127.0.0.1") {
|
|
188
|
+
res.status(404).json({ error: "not available in team mode" });
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const now = Date.now();
|
|
192
|
+
if (now > _lsBucket.resetAt) {
|
|
193
|
+
_lsBucket.count = 0;
|
|
194
|
+
_lsBucket.resetAt = now + 1e3;
|
|
195
|
+
}
|
|
196
|
+
if (++_lsBucket.count > 10) {
|
|
197
|
+
res.status(429).json({ error: "rate limit exceeded" });
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
res.setHeader("Cache-Control", "no-store");
|
|
201
|
+
res.setHeader("Access-Control-Allow-Origin", "null");
|
|
202
|
+
res.json({ secret: localSecret });
|
|
203
|
+
});
|
|
204
|
+
let allowedOrigins = null;
|
|
205
|
+
if (process.env.MERGEN_ALLOWED_ORIGINS) {
|
|
206
|
+
const validated = process.env.MERGEN_ALLOWED_ORIGINS.split(",").map((s) => s.trim()).filter((s) => {
|
|
207
|
+
try {
|
|
208
|
+
new URL(s);
|
|
209
|
+
return true;
|
|
210
|
+
} catch {
|
|
211
|
+
logger.warn({ origin: s }, "CORS: invalid origin in MERGEN_ALLOWED_ORIGINS \u2014 skipped");
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
allowedOrigins = new Set(validated);
|
|
216
|
+
}
|
|
217
|
+
if (bindHost !== "127.0.0.1" && !allowedOrigins) {
|
|
218
|
+
logger.error(
|
|
219
|
+
"FATAL: MERGEN_BIND is not 127.0.0.1 (team/cloud mode) but MERGEN_ALLOWED_ORIGINS is not set. Set MERGEN_ALLOWED_ORIGINS=https://your-dashboard.example.com to restrict cross-origin access, then restart."
|
|
220
|
+
);
|
|
221
|
+
process.exit(1);
|
|
222
|
+
}
|
|
223
|
+
app.use((req, res, next) => {
|
|
224
|
+
const origin = req.headers.origin;
|
|
225
|
+
if (bindHost === "127.0.0.1") {
|
|
226
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
227
|
+
} else if (allowedOrigins) {
|
|
228
|
+
if (origin && allowedOrigins.has(origin)) {
|
|
229
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
230
|
+
res.setHeader("Vary", "Origin");
|
|
231
|
+
}
|
|
232
|
+
} else {
|
|
233
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
234
|
+
}
|
|
235
|
+
res.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
|
|
236
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, x-mergen-secret, x-api-key");
|
|
237
|
+
next();
|
|
238
|
+
});
|
|
239
|
+
if (bindHost === "127.0.0.1") {
|
|
240
|
+
app.use((req, res, next) => {
|
|
241
|
+
if (req.method === "OPTIONS") {
|
|
242
|
+
next();
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const raw = req.headers.host ?? "";
|
|
246
|
+
const hostname = raw.replace(/^\[([^\]]+)\].*$/, "$1").split(":")[0];
|
|
247
|
+
const hostPort = raw.includes(":") ? raw.split(":").pop() : null;
|
|
248
|
+
if (!LOCAL_HOSTNAMES.has(hostname) || hostPort !== null && hostPort !== String(port)) {
|
|
249
|
+
res.status(421).json({ error: "misdirected request" });
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
next();
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
app.options("*", (_req, res) => res.status(204).end());
|
|
256
|
+
const RATE_WINDOW_MS = 6e4;
|
|
257
|
+
const RATE_MAX = 600;
|
|
258
|
+
const _ipBuckets = new LRUCache({ max: 1e4 });
|
|
259
|
+
const TRUST_PROXY = process.env.MERGEN_TRUSTED_PROXY === "true" && bindHost !== "127.0.0.1";
|
|
260
|
+
function getClientIp(req) {
|
|
261
|
+
if (TRUST_PROXY) {
|
|
262
|
+
const xff = req.headers["x-forwarded-for"];
|
|
263
|
+
const raw = (Array.isArray(xff) ? xff[0] : xff ?? "").split(",")[0].trim();
|
|
264
|
+
if (raw) return raw.replace(/^::ffff:/, "");
|
|
265
|
+
}
|
|
266
|
+
return (req.socket.remoteAddress ?? "unknown").replace(/^::ffff:/, "");
|
|
267
|
+
}
|
|
268
|
+
app.use((req, res, next) => {
|
|
269
|
+
if (req.path === "/ingest" || req.path.startsWith("/v1/")) {
|
|
270
|
+
next();
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const ip = getClientIp(req);
|
|
274
|
+
const now = Date.now();
|
|
275
|
+
let bucket = _ipBuckets.get(ip);
|
|
276
|
+
if (!bucket || now > bucket.resetAt) {
|
|
277
|
+
bucket = { count: 0, resetAt: now + RATE_WINDOW_MS };
|
|
278
|
+
_ipBuckets.set(ip, bucket);
|
|
279
|
+
}
|
|
280
|
+
if (++bucket.count > RATE_MAX) {
|
|
281
|
+
res.status(429).json({ error: "rate limit exceeded" });
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
next();
|
|
285
|
+
});
|
|
286
|
+
app.use(ssoMiddleware);
|
|
287
|
+
app.use(idpIdentityMiddleware());
|
|
288
|
+
app.use((req, res, next) => {
|
|
289
|
+
if (req.method === "GET" || req.method === "OPTIONS") {
|
|
290
|
+
next();
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (!MUTATING_PATHS.some((p) => req.path === p || req.path.startsWith(p + "/"))) {
|
|
294
|
+
next();
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const presented = req.headers["x-mergen-secret"];
|
|
298
|
+
if (!timingSafeSecretEqualAny(presented, localSecret)) {
|
|
299
|
+
res.status(401).json({ error: "unauthorized" });
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
next();
|
|
303
|
+
});
|
|
304
|
+
const SENSITIVE_GET_PATHS = [
|
|
305
|
+
"/api/war-room",
|
|
306
|
+
// incident attribution + Slack thread history
|
|
307
|
+
"/sessions",
|
|
308
|
+
// session event replay + per-session threat-graph (call ring, verdicts, attack chains)
|
|
309
|
+
"/audit",
|
|
310
|
+
// audit log
|
|
311
|
+
"/license",
|
|
312
|
+
// plan, customer email, activation date
|
|
313
|
+
"/agent-blunders",
|
|
314
|
+
// blocked command history — reveals system constraints
|
|
315
|
+
"/incidents",
|
|
316
|
+
// live incident list + MTTR data
|
|
317
|
+
"/override-corpus",
|
|
318
|
+
// team's operational override knowledge
|
|
319
|
+
"/shadow-report/entries",
|
|
320
|
+
// shadow log entries with proposed commands
|
|
321
|
+
"/impact-report",
|
|
322
|
+
// autonomous resolution rate + MTTR metrics
|
|
323
|
+
"/hitl/pending",
|
|
324
|
+
// currently-held gate tokens + policy reasons
|
|
325
|
+
"/hitl/fatigue",
|
|
326
|
+
// HITL fatigue status — operational posture signal
|
|
327
|
+
"/gate-analytics",
|
|
328
|
+
// retry success rates, coverage gaps, HITL decision patterns
|
|
329
|
+
"/policies",
|
|
330
|
+
// policy rules + trigger counts — reveals enforcement posture
|
|
331
|
+
"/policy-suggestions",
|
|
332
|
+
// auto-discovered blunder patterns — reveals enforcement gaps
|
|
333
|
+
"/audit/export",
|
|
334
|
+
// full compliance export — tamper-evident audit log
|
|
335
|
+
"/agents",
|
|
336
|
+
// per-agent identity + forensics timeline
|
|
337
|
+
"/activity-feed",
|
|
338
|
+
// live tool call stream — reveals agent activity patterns
|
|
339
|
+
"/risk-report",
|
|
340
|
+
// CISO-grade security risk report — reveals incident rates & rules
|
|
341
|
+
"/compliance/report",
|
|
342
|
+
// SOC2-structured report — RBAC membership, policy rules, blocked-action counts
|
|
343
|
+
"/replay",
|
|
344
|
+
// runtime replay — full gate-event + blunder-log timeline for a trace
|
|
345
|
+
"/analytics",
|
|
346
|
+
// approval analytics — blocked action history + rule override rates
|
|
347
|
+
"/rbac",
|
|
348
|
+
// RBAC roster — who's an admin, useful recon for identity-spoofing attempts
|
|
349
|
+
"/credentials",
|
|
350
|
+
// configured credential-broker scope names — recon for cross-tenant/scope guessing
|
|
351
|
+
"/activate"
|
|
352
|
+
// device-flow activation page — embeds the local secret for its poll script
|
|
353
|
+
];
|
|
354
|
+
if (localSecret) {
|
|
355
|
+
app.use((req, res, next) => {
|
|
356
|
+
if (req.method !== "GET") {
|
|
357
|
+
next();
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (!SENSITIVE_GET_PATHS.some((p) => req.path === p || req.path.startsWith(p + "/"))) {
|
|
361
|
+
next();
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const qSecret = req.query["secret"];
|
|
365
|
+
const presented = req.headers["x-mergen-secret"] ?? (typeof qSecret === "string" ? qSecret : void 0);
|
|
366
|
+
const valid = timingSafeSecretEqualAny(presented, localSecret);
|
|
367
|
+
if (!valid) {
|
|
368
|
+
res.status(401).json({ error: "unauthorized" });
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
next();
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
app.use(createDashboardRouter(serverVersion, localSecret));
|
|
375
|
+
app.use(createSetupRouter());
|
|
376
|
+
app.use(createDemoRouter());
|
|
377
|
+
app.use(createSdkRouter());
|
|
378
|
+
app.use(createSensorRouter(serverVersion));
|
|
379
|
+
app.use(createLicenseRouter());
|
|
380
|
+
if (process.env.MERGEN_AUTH_STUB === "true") app.use(createDeviceAuthStubRouter());
|
|
381
|
+
app.use(createCalibrationRouter());
|
|
382
|
+
app.use(createTelemetryRouter());
|
|
383
|
+
app.use(teamRouter);
|
|
384
|
+
app.use("/ingest", cloudAuthMiddleware);
|
|
385
|
+
app.use("/v1", cloudAuthMiddleware);
|
|
386
|
+
app.use(createIngestRouter(localSecret));
|
|
387
|
+
app.use(layersRouter);
|
|
388
|
+
app.use(otelRouter);
|
|
389
|
+
app.use(otlpReceiverRouter);
|
|
390
|
+
app.use(createCIRouter());
|
|
391
|
+
app.use(createIncidentsRouter());
|
|
392
|
+
app.use(createTicketsRouter());
|
|
393
|
+
app.use(createValidateRouter());
|
|
394
|
+
app.use(createSessionsRouter());
|
|
395
|
+
if (CLOUD_MODE) app.use("/incident", cloudAuthMiddleware);
|
|
396
|
+
app.use(createIncidentWebhookRouter());
|
|
397
|
+
app.use(createHeartbeatsRouter());
|
|
398
|
+
app.use(createWarRoomRouter());
|
|
399
|
+
app.use(createSlackRoutingRouter());
|
|
400
|
+
app.use(createApiKeysRouter());
|
|
401
|
+
app.use(createTenantsRouter());
|
|
402
|
+
app.use(createRbacRouter());
|
|
403
|
+
app.use(createOverridesRouter());
|
|
404
|
+
app.use(createShadowReportRouter());
|
|
405
|
+
app.use(createDecisionMemoryRouter());
|
|
406
|
+
app.use(createPRShadowRouter());
|
|
407
|
+
app.use(createImpactReportRouter());
|
|
408
|
+
app.use(createBillingOutcomeRouter());
|
|
409
|
+
app.use(createBillingDashboardRouter());
|
|
410
|
+
app.use(createOnboardingRouter());
|
|
411
|
+
app.use(createHealthIntegrationsRouter());
|
|
412
|
+
app.use(createTeamUsageRouter());
|
|
413
|
+
app.use(createActiveAuthorsRouter());
|
|
414
|
+
app.use(createPostmortemRouter());
|
|
415
|
+
app.use(createExplainWhyRouter());
|
|
416
|
+
app.use(createAgentBlundersRouter(localSecret));
|
|
417
|
+
app.use(createHabituationRouter());
|
|
418
|
+
app.use(createAdrRouter());
|
|
419
|
+
app.use(createConfidenceRouter());
|
|
420
|
+
app.use(createArchRouter());
|
|
421
|
+
app.use(createRunbooksRouter());
|
|
422
|
+
if (CLOUD_MODE) app.use("/ci/gate", cloudAuthMiddleware);
|
|
423
|
+
app.use(createCIGateRouter());
|
|
424
|
+
app.use(createCIGateHistoryRouter());
|
|
425
|
+
app.use(createHitlRouter(localSecret));
|
|
426
|
+
app.use(createGateAnalyticsRouter());
|
|
427
|
+
app.use(createPoliciesRouter(localSecret));
|
|
428
|
+
app.use(createRiskReportRouter());
|
|
429
|
+
app.use(createSafetyTestRouter());
|
|
430
|
+
app.use(createAgentActivityRouter());
|
|
431
|
+
app.use(createPolicyNlRouter());
|
|
432
|
+
app.use(createAgentsRouter());
|
|
433
|
+
app.use(createActivityFeedRouter());
|
|
434
|
+
app.use(createAuditExportRouter());
|
|
435
|
+
app.use(createGateRouter(port));
|
|
436
|
+
if (CLOUD_MODE) app.use("/credentials", cloudAuthMiddleware);
|
|
437
|
+
app.use(createCredentialsRouter(port));
|
|
438
|
+
app.use(createReplayRouter());
|
|
439
|
+
app.use(createOidcIssuerRouter());
|
|
440
|
+
app.use(createComplianceReportRouter());
|
|
441
|
+
app.get("/service-graph", ...CLOUD_MODE ? [cloudAuthMiddleware] : [], (_req, res) => {
|
|
442
|
+
res.json({ ok: true, graph: serviceGraph.toJSON() });
|
|
443
|
+
});
|
|
444
|
+
app.get("/route-reachability", ...CLOUD_MODE ? [cloudAuthMiddleware] : [], (_req, res) => {
|
|
445
|
+
res.json({ ok: true, ...routeReachability.toJSON() });
|
|
446
|
+
});
|
|
447
|
+
app.get("/metrics", ...CLOUD_MODE ? [cloudAuthMiddleware] : [], (_req, res) => {
|
|
448
|
+
res.setHeader("Content-Type", "text/plain; version=0.0.4; charset=utf-8");
|
|
449
|
+
res.send(getPrometheusMetrics());
|
|
450
|
+
});
|
|
451
|
+
app.get("/feedback", (req, res) => {
|
|
452
|
+
void handleFeedbackLink(req, res);
|
|
453
|
+
});
|
|
454
|
+
app.use(
|
|
455
|
+
(err, _req, res, next) => {
|
|
456
|
+
if (err.type === "entity.parse.failed") {
|
|
457
|
+
res.status(400).json({ error: "malformed JSON" });
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
next(err);
|
|
461
|
+
}
|
|
462
|
+
);
|
|
463
|
+
return app;
|
|
464
|
+
}
|
|
465
|
+
export {
|
|
466
|
+
createApp
|
|
467
|
+
};
|