: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(devex): cover core frontend code in the namespaced codegen rules (#104952)
Julian Bez840905222bd1
diff --git a/.semgrep/rules/devex/prefer-codegen-api-namespaced.test.ts b/.semgrep/rules/devex/prefer-codegen-api-namespaced.test.tsindex 535fab2be397..e96abd83691d 100644--- a/.semgrep/rules/devex/prefer-codegen-api-namespaced.test.ts+++ b/.semgrep/rules/devex/prefer-codegen-api-namespaced.test.ts@@ -32,6 +32,9 @@ const g = await api.signalTeamConfig.get()// ruleid: prefer-codegen-api-namespaced-posthog_aiconst h = await api.coreMemory.get()+// ruleid: prefer-codegen-api-namespaced-shared-activity+const l = await api.activity.list(id)+// The bare verbs are the other rule's job.// ok: prefer-codegen-api-namespaced-signalsconst i = await api.get(`api/projects/${projectId}/signals/reports/`)diff --git a/.semgrep/rules/devex/prefer-codegen-api-namespaced.yaml b/.semgrep/rules/devex/prefer-codegen-api-namespaced.yamlindex 03cc8587687d..683139ba9d1f 100644--- a/.semgrep/rules/devex/prefer-codegen-api-namespaced.yaml+++ b/.semgrep/rules/devex/prefer-codegen-api-namespaced.yaml@@ -9,7 +9,11 @@## One rule per product, rather than one rule listing every namespace: a call on# another product's namespace, such as conversations calling api.comments, is-# legitimate, and a global list would block it.+# legitimate, and a global list would block it. Each rule also covers core code+# under frontend/src, which owns no product namespace. A scene that moves into its+# product keeps the same rule id, so the baseline diff does not report it as new.+# A namespace several products share gets one shared rule over those products and+# core instead, so a call on it is reported once, not once per owner.## WARNING severity, so the backlog prints without failing and the devex job's# --baseline-commit pass blocks only the calls a pull request adds. See@@ -18,7 +22,7 @@ rules:# --- generated by `hogli lint:api-ratchet --write-semgrep` ---- id: prefer-codegen-api-namespaced-actionsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/actions. The namespace+ Manual `api.<namespace>.<method>(...)` call on a actions namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/actions/frontend/generated/api.ts`.@@ -40,7 +44,9 @@ rules:paths:include:- '/products/actions/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -50,7 +56,7 @@ rules:- id: prefer-codegen-api-namespaced-ai_observabilitymessage: >-- Manual `api.<namespace>.<method>(...)` call in products/ai_observability. The namespace+ Manual `api.<namespace>.<method>(...)` call on a ai_observability namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/ai_observability/frontend/generated/api.ts`.@@ -74,7 +80,9 @@ rules:paths:include:- '/products/ai_observability/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -84,7 +92,7 @@ rules:- id: prefer-codegen-api-namespaced-alertsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/alerts. The namespace+ Manual `api.<namespace>.<method>(...)` call on a alerts namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/alerts/frontend/generated/api.ts`.@@ -106,7 +114,9 @@ rules:paths:include:- '/products/alerts/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -116,7 +126,7 @@ rules:- id: prefer-codegen-api-namespaced-annotationsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/annotations. The namespace+ Manual `api.<namespace>.<method>(...)` call on a annotations namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/annotations/frontend/generated/api.ts`.@@ -138,7 +148,9 @@ rules:paths:include:- '/products/annotations/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -148,7 +160,7 @@ rules:- id: prefer-codegen-api-namespaced-batch_exportsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/batch_exports. The namespace+ Manual `api.<namespace>.<method>(...)` call on a batch_exports namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/batch_exports/frontend/generated/api.ts`.@@ -170,7 +182,9 @@ rules:paths:include:- '/products/batch_exports/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -180,7 +194,7 @@ rules:- id: prefer-codegen-api-namespaced-cdpmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/cdp. The namespace+ Manual `api.<namespace>.<method>(...)` call on a cdp namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/cdp/frontend/generated/api.ts`.@@ -202,7 +216,9 @@ rules:paths:include:- '/products/cdp/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -212,7 +228,7 @@ rules:- id: prefer-codegen-api-namespaced-cohortsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/cohorts. The namespace+ Manual `api.<namespace>.<method>(...)` call on a cohorts namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/cohorts/frontend/generated/api.ts`.@@ -234,7 +250,9 @@ rules:paths:include:- '/products/cohorts/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -244,7 +262,7 @@ rules:- id: prefer-codegen-api-namespaced-conversationsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/conversations. The namespace+ Manual `api.<namespace>.<method>(...)` call on a conversations namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/conversations/frontend/generated/api.ts`.@@ -266,7 +284,9 @@ rules:paths:include:- '/products/conversations/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -276,7 +296,7 @@ rules:- id: prefer-codegen-api-namespaced-customer_analyticsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/customer_analytics. The namespace+ Manual `api.<namespace>.<method>(...)` call on a customer_analytics namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/customer_analytics/frontend/generated/api.ts`.@@ -300,7 +320,9 @@ rules:paths:include:- '/products/customer_analytics/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -310,7 +332,7 @@ rules:- id: prefer-codegen-api-namespaced-dashboardsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/dashboards. The namespace+ Manual `api.<namespace>.<method>(...)` call on a dashboards namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/dashboards/frontend/generated/api.ts`.@@ -336,7 +358,9 @@ rules:paths:include:- '/products/dashboards/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -346,7 +370,7 @@ rules:- id: prefer-codegen-api-namespaced-data_modelingmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/data_modeling. The namespace+ Manual `api.<namespace>.<method>(...)` call on a data_modeling namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/data_modeling/frontend/generated/api.ts`.@@ -370,7 +394,9 @@ rules:paths:include:- '/products/data_modeling/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -380,7 +406,7 @@ rules:- id: prefer-codegen-api-namespaced-data_warehousemessage: >-- Manual `api.<namespace>.<method>(...)` call in products/data_warehouse. The namespace+ Manual `api.<namespace>.<method>(...)` call on a data_warehouse namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/data_warehouse/frontend/generated/api.ts`.@@ -397,8 +423,6 @@ rules:severity: WARNINGlanguages: [typescript, javascript]pattern-either:- - pattern: api.activity.$METHOD(...)- - pattern: api.activity.$MEMBER.$METHOD(...)- pattern: api.dataModelingJobs.$METHOD(...)- pattern: api.dataModelingJobs.$MEMBER.$METHOD(...)- pattern: api.dataWarehouseManagedViewsets.$METHOD(...)@@ -422,7 +446,9 @@ rules:paths:include:- '/products/data_warehouse/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -432,7 +458,7 @@ rules:- id: prefer-codegen-api-namespaced-early_access_featuresmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/early_access_features. The namespace+ Manual `api.<namespace>.<method>(...)` call on a early_access_features namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/early_access_features/frontend/generated/api.ts`.@@ -454,7 +480,9 @@ rules:paths:include:- '/products/early_access_features/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -464,7 +492,7 @@ rules:- id: prefer-codegen-api-namespaced-endpointsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/endpoints. The namespace+ Manual `api.<namespace>.<method>(...)` call on a endpoints namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/endpoints/frontend/generated/api.ts`.@@ -486,7 +514,9 @@ rules:paths:include:- '/products/endpoints/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -496,7 +526,7 @@ rules:- id: prefer-codegen-api-namespaced-error_trackingmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/error_tracking. The namespace+ Manual `api.<namespace>.<method>(...)` call on a error_tracking namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/error_tracking/frontend/generated/api.ts`.@@ -518,7 +548,9 @@ rules:paths:include:- '/products/error_tracking/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -528,7 +560,7 @@ rules:- id: prefer-codegen-api-namespaced-event_definitionsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/event_definitions. The namespace+ Manual `api.<namespace>.<method>(...)` call on a event_definitions namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/event_definitions/frontend/generated/api.ts`.@@ -550,7 +582,9 @@ rules:paths:include:- '/products/event_definitions/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -560,7 +594,7 @@ rules:- id: prefer-codegen-api-namespaced-experimentsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/experiments. The namespace+ Manual `api.<namespace>.<method>(...)` call on a experiments namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/experiments/frontend/generated/api.ts`.@@ -577,14 +611,14 @@ rules:severity: WARNINGlanguages: [typescript, javascript]pattern-either:- - pattern: api.activity.$METHOD(...)- - pattern: api.activity.$MEMBER.$METHOD(...)- pattern: api.experiments.$METHOD(...)- pattern: api.experiments.$MEMBER.$METHOD(...)paths:include:- '/products/experiments/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -594,7 +628,7 @@ rules:- id: prefer-codegen-api-namespaced-exportsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/exports. The namespace+ Manual `api.<namespace>.<method>(...)` call on a exports namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/exports/frontend/generated/api.ts`.@@ -616,7 +650,9 @@ rules:paths:include:- '/products/exports/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -626,7 +662,7 @@ rules:- id: prefer-codegen-api-namespaced-feature_flagsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/feature_flags. The namespace+ Manual `api.<namespace>.<method>(...)` call on a feature_flags namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/feature_flags/frontend/generated/api.ts`.@@ -643,8 +679,6 @@ rules:severity: WARNINGlanguages: [typescript, javascript]pattern-either:- - pattern: api.activity.$METHOD(...)- - pattern: api.activity.$MEMBER.$METHOD(...)- pattern: api.featureFlags.$METHOD(...)- pattern: api.featureFlags.$MEMBER.$METHOD(...)- pattern: api.organizationFeatureFlags.$METHOD(...)@@ -652,7 +686,9 @@ rules:paths:include:- '/products/feature_flags/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -662,7 +698,7 @@ rules:- id: prefer-codegen-api-namespaced-groupsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/groups. The namespace+ Manual `api.<namespace>.<method>(...)` call on a groups namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/groups/frontend/generated/api.ts`.@@ -679,14 +715,14 @@ rules:severity: WARNINGlanguages: [typescript, javascript]pattern-either:- - pattern: api.activity.$METHOD(...)- - pattern: api.activity.$MEMBER.$METHOD(...)- pattern: api.groups.$METHOD(...)- pattern: api.groups.$MEMBER.$METHOD(...)paths:include:- '/products/groups/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -696,7 +732,7 @@ rules:- id: prefer-codegen-api-namespaced-integrationsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/integrations. The namespace+ Manual `api.<namespace>.<method>(...)` call on a integrations namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/integrations/frontend/generated/api.ts`.@@ -718,7 +754,9 @@ rules:paths:include:- '/products/integrations/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -728,7 +766,7 @@ rules:- id: prefer-codegen-api-namespaced-linksmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/links. The namespace+ Manual `api.<namespace>.<method>(...)` call on a links namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/links/frontend/generated/api.ts`.@@ -750,7 +788,9 @@ rules:paths:include:- '/products/links/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -760,7 +800,7 @@ rules:- id: prefer-codegen-api-namespaced-logsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/logs. The namespace+ Manual `api.<namespace>.<method>(...)` call on a logs namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/logs/frontend/generated/api.ts`.@@ -782,7 +822,9 @@ rules:paths:include:- '/products/logs/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -792,7 +834,7 @@ rules:- id: prefer-codegen-api-namespaced-messagingmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/messaging. The namespace+ Manual `api.<namespace>.<method>(...)` call on a messaging namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/messaging/frontend/generated/api.ts`.@@ -814,7 +856,9 @@ rules:paths:include:- '/products/messaging/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -824,7 +868,7 @@ rules:- id: prefer-codegen-api-namespaced-notebooksmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/notebooks. The namespace+ Manual `api.<namespace>.<method>(...)` call on a notebooks namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/notebooks/frontend/generated/api.ts`.@@ -841,14 +885,14 @@ rules:severity: WARNINGlanguages: [typescript, javascript]pattern-either:- - pattern: api.activity.$METHOD(...)- - pattern: api.activity.$MEMBER.$METHOD(...)- pattern: api.notebooks.$METHOD(...)- pattern: api.notebooks.$MEMBER.$METHOD(...)paths:include:- '/products/notebooks/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -858,7 +902,7 @@ rules:- id: prefer-codegen-api-namespaced-personsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/persons. The namespace+ Manual `api.<namespace>.<method>(...)` call on a persons namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/persons/frontend/generated/api.ts`.@@ -875,14 +919,14 @@ rules:severity: WARNINGlanguages: [typescript, javascript]pattern-either:- - pattern: api.activity.$METHOD(...)- - pattern: api.activity.$MEMBER.$METHOD(...)- pattern: api.persons.$METHOD(...)- pattern: api.persons.$MEMBER.$METHOD(...)paths:include:- '/products/persons/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -892,7 +936,7 @@ rules:- id: prefer-codegen-api-namespaced-platform_featuresmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/platform_features. The namespace+ Manual `api.<namespace>.<method>(...)` call on a platform_features namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/platform_features/frontend/generated/api.ts`.@@ -909,8 +953,6 @@ rules:severity: WARNINGlanguages: [typescript, javascript]pattern-either:- - pattern: api.activity.$METHOD(...)- - pattern: api.activity.$MEMBER.$METHOD(...)- pattern: api.comments.$METHOD(...)- pattern: api.comments.$MEMBER.$METHOD(...)- pattern: api.organizationMembers.$METHOD(...)@@ -920,7 +962,9 @@ rules:paths:include:- '/products/platform_features/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -930,7 +974,7 @@ rules:- id: prefer-codegen-api-namespaced-posthog_aimessage: >-- Manual `api.<namespace>.<method>(...)` call in products/posthog_ai. The namespace+ Manual `api.<namespace>.<method>(...)` call on a posthog_ai namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/posthog_ai/frontend/generated/api.ts`.@@ -954,7 +998,9 @@ rules:paths:include:- '/products/posthog_ai/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -964,7 +1010,7 @@ rules:- id: prefer-codegen-api-namespaced-product_analyticsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/product_analytics. The namespace+ Manual `api.<namespace>.<method>(...)` call on a product_analytics namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/product_analytics/frontend/generated/api.ts`.@@ -981,8 +1027,6 @@ rules:severity: WARNINGlanguages: [typescript, javascript]pattern-either:- - pattern: api.activity.$METHOD(...)- - pattern: api.activity.$MEMBER.$METHOD(...)- pattern: api.columnConfigurations.$METHOD(...)- pattern: api.columnConfigurations.$MEMBER.$METHOD(...)- pattern: api.insights.$METHOD(...)@@ -990,7 +1034,9 @@ rules:paths:include:- '/products/product_analytics/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -1000,7 +1046,7 @@ rules:- id: prefer-codegen-api-namespaced-product_toursmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/product_tours. The namespace+ Manual `api.<namespace>.<method>(...)` call on a product_tours namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/product_tours/frontend/generated/api.ts`.@@ -1022,7 +1068,9 @@ rules:paths:include:- '/products/product_tours/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -1032,7 +1080,7 @@ rules:- id: prefer-codegen-api-namespaced-replaymessage: >-- Manual `api.<namespace>.<method>(...)` call in products/replay. The namespace+ Manual `api.<namespace>.<method>(...)` call on a replay namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/replay/frontend/generated/api.ts`.@@ -1054,7 +1102,9 @@ rules:paths:include:- '/products/replay/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -1064,7 +1114,7 @@ rules:- id: prefer-codegen-api-namespaced-revenue_analyticsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/revenue_analytics. The namespace+ Manual `api.<namespace>.<method>(...)` call on a revenue_analytics namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/revenue_analytics/frontend/generated/api.ts`.@@ -1086,7 +1136,9 @@ rules:paths:include:- '/products/revenue_analytics/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -1096,7 +1148,7 @@ rules:- id: prefer-codegen-api-namespaced-signalsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/signals. The namespace+ Manual `api.<namespace>.<method>(...)` call on a signals namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/signals/frontend/generated/api.ts`.@@ -1120,7 +1172,9 @@ rules:paths:include:- '/products/signals/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -1130,7 +1184,7 @@ rules:- id: prefer-codegen-api-namespaced-subscriptionsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/subscriptions. The namespace+ Manual `api.<namespace>.<method>(...)` call on a subscriptions namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/subscriptions/frontend/generated/api.ts`.@@ -1152,7 +1206,9 @@ rules:paths:include:- '/products/subscriptions/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -1162,7 +1218,7 @@ rules:- id: prefer-codegen-api-namespaced-surveysmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/surveys. The namespace+ Manual `api.<namespace>.<method>(...)` call on a surveys namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/surveys/frontend/generated/api.ts`.@@ -1179,14 +1235,14 @@ rules:severity: WARNINGlanguages: [typescript, javascript]pattern-either:- - pattern: api.activity.$METHOD(...)- - pattern: api.activity.$MEMBER.$METHOD(...)- pattern: api.surveys.$METHOD(...)- pattern: api.surveys.$MEMBER.$METHOD(...)paths:include:- '/products/surveys/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -1196,7 +1252,7 @@ rules:- id: prefer-codegen-api-namespaced-tasksmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/tasks. The namespace+ Manual `api.<namespace>.<method>(...)` call on a tasks namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/tasks/frontend/generated/api.ts`.@@ -1218,7 +1274,9 @@ rules:paths:include:- '/products/tasks/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -1228,7 +1286,7 @@ rules:- id: prefer-codegen-api-namespaced-user_interviewsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/user_interviews. The namespace+ Manual `api.<namespace>.<method>(...)` call on a user_interviews namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/user_interviews/frontend/generated/api.ts`.@@ -1250,7 +1308,9 @@ rules:paths:include:- '/products/user_interviews/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -1260,7 +1320,7 @@ rules:- id: prefer-codegen-api-namespaced-warehouse_sourcesmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/warehouse_sources. The namespace+ Manual `api.<namespace>.<method>(...)` call on a warehouse_sources namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/warehouse_sources/frontend/generated/api.ts`.@@ -1284,7 +1344,9 @@ rules:paths:include:- '/products/warehouse_sources/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -1294,7 +1356,7 @@ rules:- id: prefer-codegen-api-namespaced-web_analyticsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/web_analytics. The namespace+ Manual `api.<namespace>.<method>(...)` call on a web_analytics namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/web_analytics/frontend/generated/api.ts`.@@ -1318,7 +1380,9 @@ rules:paths:include:- '/products/web_analytics/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'@@ -1328,7 +1392,7 @@ rules:- id: prefer-codegen-api-namespaced-workflowsmessage: >-- Manual `api.<namespace>.<method>(...)` call in products/workflows. The namespace+ Manual `api.<namespace>.<method>(...)` call on a workflows namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/workflows/frontend/generated/api.ts`.@@ -1352,7 +1416,54 @@ rules:paths:include:- '/products/workflows/frontend/'+ - '/frontend/src/'+ exclude:+ - '/frontend/src/lib/api.ts'+ - '**/generated/**'+ - '**/*.test.ts'+ - '**/*.test.tsx'+ - '**/*.stories.tsx'+ - '**/__mocks__/**'+ - '**/mocks/**'++ - id: prefer-codegen-api-namespaced-shared-activity+ message: >-+ Manual `api.activity.<method>(...)` call on a namespace several products build+ routes on: data_warehouse, experiments, feature_flags, groups, notebooks, persons, platform_features, product_analytics, surveys.++ The namespace builds its URL in `frontend/src/lib/api.ts`. Use the generated+ client of whichever product's route this call reaches, from+ `products/<product>/frontend/generated/api.ts`.++ Informational while the backlog is worked down, but a call this pull request adds+ fails the job.++ Agents: invoke the `adopting-generated-api-types` skill+ (`.agents/skills/adopting-generated-api-types/SKILL.md`) for the migration+ workflow.++ If no generated equivalent is available yet (endpoint missing OpenAPI tags,+ dynamic URL, etc.), add `// nosemgrep: prefer-codegen-api-namespaced-shared-activity`+ above this line - the maturity tooling continues to track tagged sites.+ severity: WARNING+ languages: [typescript, javascript]+ pattern-either:+ - pattern: api.activity.$METHOD(...)+ - pattern: api.activity.$MEMBER.$METHOD(...)+ paths:+ include:+ - '/products/data_warehouse/frontend/'+ - '/products/experiments/frontend/'+ - '/products/feature_flags/frontend/'+ - '/products/groups/frontend/'+ - '/products/notebooks/frontend/'+ - '/products/persons/frontend/'+ - '/products/platform_features/frontend/'+ - '/products/product_analytics/frontend/'+ - '/products/surveys/frontend/'+ - '/frontend/src/'exclude:+ - '/frontend/src/lib/api.ts'- '**/generated/**'- '**/*.test.ts'- '**/*.test.tsx'diff --git a/tools/hogli-commands/hogli_commands/api_ratchet.py b/tools/hogli-commands/hogli_commands/api_ratchet.pyindex d1990948b816..66734308911d 100644--- a/tools/hogli-commands/hogli_commands/api_ratchet.py+++ b/tools/hogli-commands/hogli_commands/api_ratchet.py@@ -36,6 +36,7 @@ from __future__ import annotationsimport reimport json+from collections.abc import Iterablefrom dataclasses import dataclassfrom functools import lru_cachefrom pathlib import Path@@ -68,12 +69,26 @@ SEMGREP_RULE: Final = Path(".semgrep/rules/devex/prefer-codegen-api-namespaced.ySEMGREP_BEGIN: Final = " # --- generated by `hogli lint:api-ratchet --write-semgrep` ---"SEMGREP_END: Final = " # --- end generated ---"+# Shared by both templates below, so they can't drift apart on what they exclude.+SEMGREP_EXCLUDE_PATHS: Final[tuple[str, ...]] = (+ "/frontend/src/lib/api.ts",+ "**/generated/**",+ "**/*.test.ts",+ "**/*.test.tsx",+ "**/*.stories.tsx",+ "**/__mocks__/**",+ "**/mocks/**",+)+# One rule per product. The message names the product because the rule is scoped to it,# and the rule id carries the product so a `nosemgrep` line stays as narrow as the rule.+# Each rule also covers core frontend code, so a scene that moves from frontend/src into+# its product keeps the same rule id and the baseline diff does not count it as new.+# A namespace more than one product owns is left out - see SEMGREP_SHARED_RULE_TEMPLATE.SEMGREP_RULE_TEMPLATE: Final = """\- id: prefer-codegen-api-namespaced-{product}message: >-- Manual `api.<namespace>.<method>(...)` call in products/{product}. The namespace+ Manual `api.<namespace>.<method>(...)` call on a {product} namespace. The namespacebuilds its URL in `frontend/src/lib/api.ts`, and this product's generated clientalready covers that URL. Use `products/{product}/frontend/generated/api.ts`.@@ -93,14 +108,42 @@ SEMGREP_RULE_TEMPLATE: Final = """\{patterns}paths:include:- - '/products/{product}/frontend/'+{include}exclude:- - '**/generated/**'- - '**/*.test.ts'- - '**/*.test.tsx'- - '**/*.stories.tsx'- - '**/__mocks__/**'- - '**/mocks/**'+{exclude}+"""++# One rule for a namespace more than one product owns, replacing a copy in each+# owner's SEMGREP_RULE_TEMPLATE rule, scoped over every owner's tree plus core.+SEMGREP_SHARED_RULE_TEMPLATE: Final = """\+ - id: prefer-codegen-api-namespaced-shared-{namespace}+ message: >-+ Manual `api.{namespace}.<method>(...)` call on a namespace several products build+ routes on: {products}.++ The namespace builds its URL in `frontend/src/lib/api.ts`. Use the generated+ client of whichever product's route this call reaches, from+ `products/<product>/frontend/generated/api.ts`.++ Informational while the backlog is worked down, but a call this pull request adds+ fails the job.++ Agents: invoke the `adopting-generated-api-types` skill+ (`.agents/skills/adopting-generated-api-types/SKILL.md`) for the migration+ workflow.++ If no generated equivalent is available yet (endpoint missing OpenAPI tags,+ dynamic URL, etc.), add `// nosemgrep: prefer-codegen-api-namespaced-shared-{namespace}`+ above this line - the maturity tooling continues to track tagged sites.+ severity: WARNING+ languages: [typescript, javascript]+ pattern-either:+{patterns}+ paths:+ include:+{include}+ exclude:+{exclude}"""BASELINE_HEADER: Final = """\@@ -915,10 +958,28 @@ def namespaces_owned_by(product: str, repo_root: Path | None = None) -> frozensereturn frozenset(namespace for namespace, products in ratchet.namespaces().items() if product in products)+def shared_namespaces(ratchet: Ratchet) -> dict[str, list[str]]:+ """Namespaces more than one product owns, each with its owning products, sorted.++ ``ratchet.namespaces()`` already drops CORE_OWNER, so every product left in a+ namespace's set names a real product directory. More than one such product is+ the case a single product-scoped rule can't cover without also firing on the+ other owners' legitimate calls.+ """+ return {namespace: sorted(products) for namespace, products in ratchet.namespaces().items() if len(products) > 1}++def owned_namespaces_by_product(ratchet: Ratchet) -> dict[str, list[str]]:- """Product -> the ``api`` namespaces its own generated client covers, sorted."""+ """Product -> the ``api`` namespaces its own generated client covers, sorted.++ A namespace ``shared_namespaces`` claims is left out here - it gets one shared+ rule instead of a copy in every owner's rule.+ """+ shared = shared_namespaces(ratchet)owned: dict[str, list[str]] = {}for namespace, products in ratchet.namespaces().items():+ if namespace in shared:+ continuefor product in products:if product == CORE_OWNER:continue # core owns no product directory, so no rule can scope to it@@ -926,24 +987,53 @@ def owned_namespaces_by_product(ratchet: Ratchet) -> dict[str, list[str]]:return {product: sorted(namespaces) for product, namespaces in sorted(owned.items())}+def _render_patterns(namespaces: list[str]) -> str:+ """The pattern-either lines matching a call on any of the given namespaces.++ Nested members (api.signalScout.runs.list) are a different AST shape, so each+ namespace needs the one-level and the two-level pattern.+ """+ return "\n".join(+ f" - pattern: api.{namespace}.$METHOD(...)\n - pattern: api.{namespace}.$MEMBER.$METHOD(...)"+ for namespace in namespaces+ )+++def _render_path_bullets(paths: Iterable[str]) -> str:+ """One YAML bullet per path, at the indentation ``paths.include``/``exclude`` use."""+ return "\n".join(f" - '{path}'" for path in paths)++def render_semgrep_rules(ratchet: Ratchet) -> str:- """The generated rule block: one rule per product, scoped to that product's tree.+ """The generated rule block: one rule per product, plus one per shared namespace.One global namespace list would fire on a legitimate cross-product call, such asconversations calling api.comments, and the blocking new-warning pass would stopit. Scoping each namespace to the product that owns it matches what- ``product:maturity`` counts.+ ``product:maturity`` counts. A namespace more than one product owns gets its own+ rule instead of a copy in each owner's: covering it there would report one call+ once per owner, each naming a different product's client."""+ exclude = _render_path_bullets(SEMGREP_EXCLUDE_PATHS)blocks: list[str] = []for product, namespaces in owned_namespaces_by_product(ratchet).items():- patterns = "\n".join(- # Nested members (api.signalScout.runs.list) are a different AST shape, so- # each namespace needs the one-level and the two-level pattern.- f" - pattern: api.{namespace}.$METHOD(...)\n"- f" - pattern: api.{namespace}.$MEMBER.$METHOD(...)"- for namespace in namespaces+ include = _render_path_bullets([f"/products/{product}/frontend/", "/frontend/src/"])+ blocks.append(+ SEMGREP_RULE_TEMPLATE.format(+ product=product, patterns=_render_patterns(namespaces), include=include, exclude=exclude+ )+ )+ for namespace, products in sorted(shared_namespaces(ratchet).items()):+ include = _render_path_bullets([f"/products/{product}/frontend/" for product in products] + ["/frontend/src/"])+ blocks.append(+ SEMGREP_SHARED_RULE_TEMPLATE.format(+ namespace=namespace,+ products=", ".join(products),+ patterns=_render_patterns([namespace]),+ include=include,+ exclude=exclude,+ ))- blocks.append(SEMGREP_RULE_TEMPLATE.format(product=product, patterns=patterns))return "\n".join(blocks)@@ -966,11 +1056,11 @@ def _read_marked_block(text: str) -> MarkedBlock:def write_semgrep_rules(repo_root: Path, ratchet: Ratchet) -> int:- """Rewrite the generated rule block in place. Returns the rule count."""+ """Rewrite the generated rule block in place. Returns the total rule count."""path = repo_root / SEMGREP_RULEblock = _read_marked_block(path.read_text())path.write_text(f"{block.before}{SEMGREP_BEGIN}\n{render_semgrep_rules(ratchet)}{SEMGREP_END}{block.after}")- return len(owned_namespaces_by_product(ratchet))+ return len(owned_namespaces_by_product(ratchet)) + len(shared_namespaces(ratchet))def semgrep_drift(repo_root: Path, ratchet: Ratchet) -> str | None:@@ -1023,7 +1113,7 @@ def cmd_lint_api_ratchet(if write_semgrep:count = write_semgrep_rules(repo_root, ratchet)- click.echo(f"{SEMGREP_RULE}: {count} product rule(s) written.")+ click.echo(f"{SEMGREP_RULE}: {count} rule(s) written.")if not prune_baseline and not update_baseline:returndiff --git a/tools/hogli-commands/hogli_commands/tests/test_api_ratchet.py b/tools/hogli-commands/hogli_commands/tests/test_api_ratchet.pyindex 34c09928b6c2..68e0d6923902 100644--- a/tools/hogli-commands/hogli_commands/tests/test_api_ratchet.py+++ b/tools/hogli-commands/hogli_commands/tests/test_api_ratchet.py@@ -189,13 +189,14 @@ def _write_repo(api_ts: str = API_TS_FIXTURE,baseline: str | None = None,generated_signals: str = GENERATED_SIGNALS,+ generated_workflows: str = GENERATED_WORKFLOWS,) -> None:(root / "frontend/src/lib").mkdir(parents=True, exist_ok=True)(root / "frontend/src/lib/api.ts").write_text(api_ts)(root / "products/signals/frontend/generated").mkdir(parents=True, exist_ok=True)(root / "products/signals/frontend/generated/api.ts").write_text(generated_signals)(root / "products/workflows/frontend/generated").mkdir(parents=True, exist_ok=True)- (root / "products/workflows/frontend/generated/api.ts").write_text(GENERATED_WORKFLOWS)+ (root / "products/workflows/frontend/generated/api.ts").write_text(generated_workflows)(root / api_ratchet.CORE_GENERATED).parent.mkdir(parents=True, exist_ok=True)(root / api_ratchet.CORE_GENERATED).write_text(GENERATED_CORE)rule = root / api_ratchet.SEMGREP_RULE@@ -478,7 +479,8 @@ class TestSemgrepRules:"prefer-codegen-api-namespaced-workflows",]signals = by_id["prefer-codegen-api-namespaced-signals"]- assert signals["paths"]["include"] == ["/products/signals/frontend/"]+ assert signals["paths"]["include"] == ["/products/signals/frontend/", "/frontend/src/"]+ assert "/frontend/src/lib/api.ts" in signals["paths"]["exclude"]assert signals["severity"] == "WARNING"# Both nesting depths, so api.signalScout.runs.list() cannot slip through.assert signals["pattern-either"] == [@@ -488,6 +490,67 @@ class TestSemgrepRules:# A namespace only the core client covers belongs to no product, so no rule.assert "prefer-codegen-api-namespaced-core" not in by_id+ # Covering a shared namespace in each owner's own rule would report one call per owner.+ def test_a_namespace_two_products_own_gets_one_shared_rule_instead(self, tmp_path: Path) -> None:+ api_ts = API_TS_FIXTURE.replace(+ " public hogFlows(): ApiRequest {",+ " public activity(teamId?: TeamType['id']): ApiRequest {\n"+ " return this.environmentsDetail(teamId).addPathComponent('activity')\n"+ " }\n\n"+ " public hogFlows(): ApiRequest {",+ ).replace(+ "const api = {",+ "const api = {\n"+ " activity: {\n"+ " async list(): Promise<any> {\n"+ " return await new ApiRequest().activity().get()\n"+ " },\n"+ " },",+ )+ generated_signals = GENERATED_SIGNALS + (+ "export const signalsActivityList = (projectId: string) => {\n"+ " return apiMutator({ url: `/api/projects/${projectId}/activity/`, method: 'GET' })\n"+ "}\n"+ )+ generated_workflows = GENERATED_WORKFLOWS + (+ "export const workflowsActivityList = (projectId: string) => {\n"+ " return apiMutator({ url: `/api/projects/${projectId}/activity/`, method: 'GET' })\n"+ "}\n"+ )+ _write_repo(+ tmp_path, api_ts=api_ts, generated_signals=generated_signals, generated_workflows=generated_workflows+ )+ parsed = yaml.safe_load((tmp_path / api_ratchet.SEMGREP_RULE).read_text())+ by_id = {rule["id"]: rule for rule in parsed["rules"]}++ assert sorted(by_id) == [+ "prefer-codegen-api-namespaced-shared-activity",+ "prefer-codegen-api-namespaced-signals",+ "prefer-codegen-api-namespaced-workflows",+ ]++ signals_patterns = {+ pattern["pattern"] for pattern in by_id["prefer-codegen-api-namespaced-signals"]["pattern-either"]+ }+ workflows_patterns = {+ pattern["pattern"] for pattern in by_id["prefer-codegen-api-namespaced-workflows"]["pattern-either"]+ }+ assert signals_patterns == {"api.signalReports.$METHOD(...)", "api.signalReports.$MEMBER.$METHOD(...)"}+ assert workflows_patterns == {"api.hogFlows.$METHOD(...)", "api.hogFlows.$MEMBER.$METHOD(...)"}++ shared = by_id["prefer-codegen-api-namespaced-shared-activity"]+ assert shared["pattern-either"] == [+ {"pattern": "api.activity.$METHOD(...)"},+ {"pattern": "api.activity.$MEMBER.$METHOD(...)"},+ ]+ assert shared["paths"]["include"] == [+ "/products/signals/frontend/",+ "/products/workflows/frontend/",+ "/frontend/src/",+ ]+ assert "/frontend/src/lib/api.ts" in shared["paths"]["exclude"]+ assert shared["severity"] == "WARNING"+def test_the_check_fails_when_the_committed_rules_are_stale(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: