Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(wizard): serve the tool catalog from a public cached endpoint (#116268)

Rafael Audibert297dc01dac6a
diff --git a/posthog/settings/web.py b/posthog/settings/web.py
index 914e68065b93..e32d1f7b07ec 100644
--- a/posthog/settings/web.py
+++ b/posthog/settings/web.py
@@ -891,6 +891,8 @@ GZIP_RESPONSE_ALLOW_LIST = get_list(
# Deploy-static source catalog (no user input or secrets reflected): several
# hundred KB of JSON that compresses ~7x.
"^/?api/(environments|projects)/(\\d+|@current)/external_data_sources/wizard/?$",
+ # The wizard tool catalog: deploy-static public JSON that compresses ~5x.
+ "^/?api/wizard/tool_catalog/?$",
"^/?api/instance_status/?$",
"^/array/.*$",
]
diff --git a/posthog/test/repo_invariants/test_pagination_contract.py b/posthog/test/repo_invariants/test_pagination_contract.py
index e802240769f5..e2edee511451 100644
--- a/posthog/test/repo_invariants/test_pagination_contract.py
+++ b/posthog/test/repo_invariants/test_pagination_contract.py
@@ -268,6 +268,8 @@ EXISTING_CUSTOM_LIST_VIEWSETS = {
"products.wizard.backend.presentation.registry.views.WizardRegistryViewSet",
"products.wizard.backend.presentation.runs.views.WizardRunViewSet",
"products.wizard.backend.presentation.sessions.views.WizardSessionViewSet",
+ # Serves the whole tool catalog as one cached document, so there is nothing to page.
+ "products.wizard.backend.presentation.tool_catalog.views.WizardToolCatalogViewSet",
"products.workflows.backend.presentation.views.hog_flow.HogFlowViewSet",
"products.workflows.backend.presentation.views.hog_flow_template.HogFlowTemplateViewSet",
"products.workflows.backend.presentation.views.hog_flow_template.PublicHogFlowTemplateViewSet",
diff --git a/products/wizard/backend/facade/api.py b/products/wizard/backend/facade/api.py
index a68edad3aff3..149b708cd00e 100644
--- a/products/wizard/backend/facade/api.py
+++ b/products/wizard/backend/facade/api.py
@@ -45,6 +45,7 @@ from products.wizard.backend.logic import (
from products.wizard.backend.logic.artifacts import service as artifacts
from products.wizard.backend.logic.runs import pubsub as run_pubsub
from products.wizard.backend.logic.sessions import pubsub
+from products.wizard.backend.tool_catalog.catalog import tool_catalog_json
def upsert(params: UpsertWizardSessionInput) -> tuple[WizardSessionDTO, bool]:
@@ -56,6 +57,10 @@ def record_scan(params: RecordWizardScanInput) -> WizardScanResult:
return scans.record_scan(params)
+def get_tool_catalog_json() -> bytes:
+ return tool_catalog_json()
+
+
def get(team_id: int, session_id: str) -> WizardSessionDTO | None:
return sessions.get_session(team_id, session_id)
diff --git a/products/wizard/backend/presentation/tool_catalog/__init__.py b/products/wizard/backend/presentation/tool_catalog/__init__.py
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/products/wizard/backend/presentation/tool_catalog/serializers.py b/products/wizard/backend/presentation/tool_catalog/serializers.py
new file mode 100644
index 000000000000..d811d85a4737
--- /dev/null
+++ b/products/wizard/backend/presentation/tool_catalog/serializers.py
@@ -0,0 +1,55 @@
+from django.db.models import TextChoices
+
+from drf_spectacular.utils import extend_schema_serializer
+from rest_framework import serializers
+
+
+class WizardSetupMode(TextChoices):
+ IN_CLI = "in-cli", "In the terminal"
+ DEEP_LINK = "deep-link", "In the app"
+
+
+class WizardCatalogToolSignalsSerializer(serializers.Serializer):
+ env_key_patterns = serializers.ListField(
+ child=serializers.CharField(),
+ help_text="Anchored regexes matched against `.env` key names. Values are never read.",
+ )
+ script_hosts = serializers.ListField(
+ child=serializers.CharField(),
+ help_text="Hosts matched against script URLs. A host also matches its subdomains.",
+ )
+ packages = serializers.DictField(
+ child=serializers.ListField(child=serializers.CharField()),
+ help_text="Package names keyed by ecosystem, such as `npm`, `pypi` or `maven`.",
+ )
+
+
+class WizardCatalogToolSerializer(serializers.Serializer):
+ kind = serializers.CharField(help_text="Unique tool identifier, such as `Stripe` or `Hotjar`.")
+ label = serializers.CharField(help_text="Human-readable tool name.") # type: ignore[assignment]
+ warehouse_source_type = serializers.CharField(
+ allow_null=True,
+ help_text="Data warehouse source type the tool imports as, or null for a tool with no warehouse source.",
+ )
+ wizard_setup_mode = serializers.ChoiceField(
+ choices=WizardSetupMode.choices,
+ allow_null=True,
+ help_text="How the wizard sets up the source: in the terminal or in the app. Null for a tool with no warehouse source.",
+ )
+ competes_with = serializers.ListField(
+ child=serializers.CharField(), help_text="PostHog products this tool competes with."
+ )
+ superseded_by = serializers.ListField(
+ child=serializers.CharField(),
+ help_text="Kinds that reach the same data through a more specific source. When one of them also matches, the wizard drops this tool.",
+ )
+ signals = WizardCatalogToolSignalsSerializer(help_text="How the wizard detects the tool in a codebase.")
+
+
+# The catalog is served from `list`, which drf-spectacular documents as an array by default.
+@extend_schema_serializer(many=False)
+class WizardToolCatalogSerializer(serializers.Serializer):
+ schema_version = serializers.IntegerField(
+ help_text="Bumped when the shape changes in a way an older wizard cannot read."
+ )
+ tools = WizardCatalogToolSerializer(many=True, help_text="Every tool the wizard can detect.")
diff --git a/products/wizard/backend/presentation/tool_catalog/views.py b/products/wizard/backend/presentation/tool_catalog/views.py
new file mode 100644
index 000000000000..b531964cee74
--- /dev/null
+++ b/products/wizard/backend/presentation/tool_catalog/views.py
@@ -0,0 +1,31 @@
+from django.http import HttpResponse
+from django.utils.cache import patch_cache_control
+
+from drf_spectacular.utils import extend_schema
+from rest_framework import viewsets
+from rest_framework.permissions import AllowAny
+from rest_framework.request import Request
+
+from products.wizard.backend.facade import api as wizard_facade
+from products.wizard.backend.presentation.tool_catalog.serializers import WizardToolCatalogSerializer
+
+# The catalog only changes on deploy, so clients and proxies can reuse a response for an hour.
+CACHE_MAX_AGE_SECONDS = 60 * 60
+
+
+class WizardToolCatalogViewSet(viewsets.ViewSet):
+ # Public: the wizard scans a codebase before the user logs in, and the catalog is in the public repo.
+ authentication_classes: list[type] = []
+ permission_classes = [AllowAny]
+ scope_object = None
+ http_method_names = ["get", "head", "options"]
+
+ @extend_schema(
+ responses={200: WizardToolCatalogSerializer},
+ summary="Get the wizard tool catalog",
+ description="Every tool the wizard can detect in a codebase, with the signals that identify it.",
+ )
+ def list(self, request: Request) -> HttpResponse:
+ response = HttpResponse(wizard_facade.get_tool_catalog_json(), content_type="application/json")
+ patch_cache_control(response, public=True, max_age=CACHE_MAX_AGE_SECONDS)
+ return response
diff --git a/products/wizard/backend/routes.py b/products/wizard/backend/routes.py
index ae6575f502f1..f6edbdad11f1 100644
--- a/products/wizard/backend/routes.py
+++ b/products/wizard/backend/routes.py
@@ -5,9 +5,11 @@ from products.wizard.backend.presentation.registry.views import WizardRegistryVi
from products.wizard.backend.presentation.runs.views import WizardRunTasksViewSet, WizardRunViewSet
from products.wizard.backend.presentation.scans.views import WizardScanViewSet
from products.wizard.backend.presentation.sessions.views import WizardSessionViewSet
+from products.wizard.backend.presentation.tool_catalog.views import WizardToolCatalogViewSet
def register_routes(routers: RouterRegistry) -> None:
+ routers.root.register(r"wizard/tool_catalog", WizardToolCatalogViewSet, "wizard_tool_catalog")
routers.projects.register(r"wizard/sessions", WizardSessionViewSet, "project_wizard_sessions", ["project_id"])
routers.projects.register(r"wizard/scans", WizardScanViewSet, "project_wizard_scans", ["project_id"])
diff --git a/products/wizard/backend/tests/test_tool_catalog_presentation.py b/products/wizard/backend/tests/test_tool_catalog_presentation.py
new file mode 100644
index 000000000000..e8a1f0597f94
--- /dev/null
+++ b/products/wizard/backend/tests/test_tool_catalog_presentation.py
@@ -0,0 +1,44 @@
+import json
+from pathlib import Path
+
+from unittest.mock import patch
+
+from django.test import TestCase
+
+from rest_framework import status
+
+from products.wizard.backend.presentation.tool_catalog.serializers import WizardToolCatalogSerializer
+from products.wizard.backend.tool_catalog import catalog
+
+
+class TestWizardToolCatalogViewSet(TestCase):
+ def setUp(self) -> None:
+ catalog._catalog_document.cache_clear()
+ catalog.tool_catalog_json.cache_clear()
+ self.addCleanup(catalog._catalog_document.cache_clear)
+ self.addCleanup(catalog.tool_catalog_json.cache_clear)
+
+ def test_anonymous_client_gets_the_built_catalog_from_memory(self) -> None:
+ text = json.dumps({"schema_version": catalog.CATALOG_SCHEMA_VERSION, "tools": []})
+ with patch.object(catalog, "CATALOG_JSON") as catalog_file:
+ catalog_file.exists.return_value = True
+ catalog_file.read_text.return_value = text
+ responses = [self.client.get("/api/wizard/tool_catalog/") for _ in range(2)]
+
+ for response in responses:
+ assert response.status_code == status.HTTP_200_OK
+ assert response["Content-Type"] == "application/json"
+ assert "public" in response["Cache-Control"]
+ assert json.loads(response.content) == json.loads(text)
+ assert catalog_file.read_text.call_count == 1
+
+ def test_catalog_rendered_without_a_build_matches_the_documented_schema(self) -> None:
+ with patch.object(catalog, "CATALOG_JSON", Path("/nonexistent/tool-catalog.json")):
+ document = json.loads(self.client.get("/api/wizard/tool_catalog/").content)
+
+ assert len(document["tools"]) > 0
+
+ serializer = WizardToolCatalogSerializer(data=document)
+ assert serializer.is_valid(), serializer.errors
+ # is_valid() drops keys the serializer does not declare, so equality catches an undocumented field.
+ assert serializer.validated_data == document
diff --git a/products/wizard/backend/tool_catalog/catalog.py b/products/wizard/backend/tool_catalog/catalog.py
index ab0a802d1d50..e3ab2b7c68f8 100644
--- a/products/wizard/backend/tool_catalog/catalog.py
+++ b/products/wizard/backend/tool_catalog/catalog.py
@@ -1,8 +1,9 @@
"""The tools the wizard can detect in a codebase, and what each one means to PostHog.
Each warehouse source declares its own `codebase_detection`. The image build renders the catalog to
-`products/wizard/tool-catalog.json` with `manage.py render_wizard_tool_catalog`. The backend reads
-that file to classify reported scans.
+`products/wizard/tool-catalog.json` with `manage.py render_wizard_tool_catalog`. The public
+`/api/wizard/tool_catalog/` endpoint serves that file, and the wizard downloads it at runtime from US,
+then EU. The backend reads the same file to classify reported scans.
"""
import json
@@ -69,9 +70,9 @@ def write_catalog(path: Path) -> None:
path.write_text(json.dumps(build_catalog_document(), separators=(",", ":")))
-# A web worker reads the file that the image build rendered, so classifying a reported scan never
-# imports every warehouse source module. Local dev and tests have no such file, and render the
-# catalog from the source declarations on first use.
+# A web worker reads the file that the image build rendered, so serving the catalog or classifying a
+# reported scan never imports every warehouse source module. Local dev and tests have no such file, and
+# render the catalog from the source declarations on first use.
@cache
def _catalog_document() -> dict[str, Any]:
if CATALOG_JSON.exists():
@@ -79,6 +80,11 @@ def _catalog_document() -> dict[str, Any]:
return build_catalog_document()
+@cache
+def tool_catalog_json() -> bytes:
+ return json.dumps(_catalog_document(), separators=(",", ":")).encode()
+
+
@cache
def _classifications() -> dict[str, ToolClassification]:
tools = _catalog_document()["tools"]
diff --git a/products/wizard/frontend/generated/api.schemas.ts b/products/wizard/frontend/generated/api.schemas.ts
index fee955194e17..11a67967d0d1 100644
--- a/products/wizard/frontend/generated/api.schemas.ts
+++ b/products/wizard/frontend/generated/api.schemas.ts
@@ -693,6 +693,61 @@ export interface UpsertWizardSessionRequestApi {
error?: UpsertWizardSessionRequestApiError
}
+/**
+ * * `in-cli` - In the terminal
+ * * `deep-link` - In the app
+ */
+export type WizardSetupModeEnumApi = (typeof WizardSetupModeEnumApi)[keyof typeof WizardSetupModeEnumApi]
+
+export const WizardSetupModeEnumApi = {
+ InCli: 'in-cli',
+ DeepLink: 'deep-link',
+} as const
+
+/**
+ * Package names keyed by ecosystem, such as `npm`, `pypi` or `maven`.
+ */
+export type WizardCatalogToolSignalsApiPackages = { [key: string]: string[] }
+
+export interface WizardCatalogToolSignalsApi {
+ /** Anchored regexes matched against `.env` key names. Values are never read. */
+ env_key_patterns: string[]
+ /** Hosts matched against script URLs. A host also matches its subdomains. */
+ script_hosts: string[]
+ /** Package names keyed by ecosystem, such as `npm`, `pypi` or `maven`. */
+ packages: WizardCatalogToolSignalsApiPackages
+}
+
+export interface WizardCatalogToolApi {
+ /** Unique tool identifier, such as `Stripe` or `Hotjar`. */
+ kind: string
+ /** Human-readable tool name. */
+ label: string
+ /**
+ * Data warehouse source type the tool imports as, or null for a tool with no warehouse source.
+ * @nullable
+ */
+ warehouse_source_type: string | null
+ /** How the wizard sets up the source: in the terminal or in the app. Null for a tool with no warehouse source.
+ *
+ * * `in-cli` - In the terminal
+ * * `deep-link` - In the app */
+ wizard_setup_mode: WizardSetupModeEnumApi | null
+ /** PostHog products this tool competes with. */
+ competes_with: string[]
+ /** Kinds that reach the same data through a more specific source. When one of them also matches, the wizard drops this tool. */
+ superseded_by: string[]
+ /** How the wizard detects the tool in a codebase. */
+ signals: WizardCatalogToolSignalsApi
+}
+
+export interface WizardToolCatalogApi {
+ /** Bumped when the shape changes in a way an older wizard cannot read. */
+ schema_version: number
+ /** Every tool the wizard can detect. */
+ tools: WizardCatalogToolApi[]
+}
+
/**
* * `git_diff` - git_diff
*/
diff --git a/products/wizard/frontend/generated/api.ts b/products/wizard/frontend/generated/api.ts
index 441d9197bde9..8b0661f12d6e 100644
--- a/products/wizard/frontend/generated/api.ts
+++ b/products/wizard/frontend/generated/api.ts
@@ -28,6 +28,7 @@ import type {
WizardSessionsLatestRetrieveParams,
WizardSessionsListParams,
WizardSessionsStreamRetrieveParams,
+ WizardToolCatalogApi,
} from './api.schemas'
export const getWizardRegistryListUrl = (projectId: string, params?: WizardRegistryListParams) => {
@@ -413,3 +414,18 @@ export const wizardSessionsStreamRetrieve = async (
method: 'GET',
})
}
+
+export const getWizardToolCatalogListUrl = () => {
+ return `/api/wizard/tool_catalog/`
+}
+
+/**
+ * Every tool the wizard can detect in a codebase, with the signals that identify it.
+ * @summary Get the wizard tool catalog
+ */
+export const wizardToolCatalogList = async (options?: RequestInit): Promise<WizardToolCatalogApi> => {
+ return apiMutator<WizardToolCatalogApi>(getWizardToolCatalogListUrl(), {
+ ...options,
+ method: 'GET',
+ })
+}
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index e079dc37d1be..1a84c441dd86 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -114032,6 +114032,55 @@ export namespace Schemas {
paths: string[];
}
+ /**
+ * * `in-cli` - In the terminal
+ * * `deep-link` - In the app
+ */
+ export type WizardSetupModeEnum = typeof WizardSetupModeEnum[keyof typeof WizardSetupModeEnum];
+
+
+ export const WizardSetupModeEnum = {
+ InCli: 'in-cli',
+ DeepLink: 'deep-link',
+ } as const;
+
+ /**
+ * Package names keyed by ecosystem, such as `npm`, `pypi` or `maven`.
+ */
+ export type WizardCatalogToolSignalsPackages = {[key: string]: string[]};
+
+ export interface WizardCatalogToolSignals {
+ /** Anchored regexes matched against `.env` key names. Values are never read. */
+ env_key_patterns: string[];
+ /** Hosts matched against script URLs. A host also matches its subdomains. */
+ script_hosts: string[];
+ /** Package names keyed by ecosystem, such as `npm`, `pypi` or `maven`. */
+ packages: WizardCatalogToolSignalsPackages;
+ }
+
+ export interface WizardCatalogTool {
+ /** Unique tool identifier, such as `Stripe` or `Hotjar`. */
+ kind: string;
+ /** Human-readable tool name. */
+ label: string;
+ /**
+ * Data warehouse source type the tool imports as, or null for a tool with no warehouse source.
+ * @nullable
+ */
+ warehouse_source_type: string | null;
+ /** How the wizard sets up the source: in the terminal or in the app. Null for a tool with no warehouse source.
+ *
+ * * `in-cli` - In the terminal
+ * * `deep-link` - In the app */
+ wizard_setup_mode: WizardSetupModeEnum | null;
+ /** PostHog products this tool competes with. */
+ competes_with: string[];
+ /** Kinds that reach the same data through a more specific source. When one of them also matches, the wizard drops this tool. */
+ superseded_by: string[];
+ /** How the wizard detects the tool in a codebase. */
+ signals: WizardCatalogToolSignals;
+ }
+
/**
* The team's active onboarding wizard cloud run, used to rehydrate
* the setup-progress FAB when the run was started server-side (drop flow).
@@ -114152,6 +114201,13 @@ export namespace Schemas {
created: boolean;
}
+ export interface WizardToolCatalog {
+ /** Bumped when the shape changes in a way an older wizard cannot read. */
+ schema_version: number;
+ /** Every tool the wizard can detect. */
+ tools: WizardCatalogTool[];
+ }
+
/**
* Whether PostHog paused this one workflow's email sending, and why.
*/