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.

chore(agents): replace scene/product split gate with a skill (#75099)

Georges-Antoine Assi20e144ae9246
diff --git a/.agents/skills/placing-product-frontend-code/SKILL.md b/.agents/skills/placing-product-frontend-code/SKILL.md
new file mode 100644
index 000000000000..d171e4a12881
--- /dev/null
+++ b/.agents/skills/placing-product-frontend-code/SKILL.md
@@ -0,0 +1,60 @@
+---
+name: placing-product-frontend-code
+description: >
+ Decide which tree a frontend file belongs in — `products/<name>/frontend/` or
+ `frontend/src/scenes/<name>/` — and explain why the boundary is real rather than stylistic.
+ Use when adding a new scene, component, or logic file for a product; when creating a new
+ directory under `frontend/src/scenes/`; when a product has UI in both trees and you need to
+ know which side to extend; or when moving a scene into its product. Covers the merge-queue
+ lane cost of the split, the measurement showing a dependency graph cannot substitute for the
+ path signal, and a report script that shows how far each product's move has gone.
+---
+
+# Placing product frontend code
+
+**A product's UI belongs in `products/<name>/frontend/`, not `frontend/src/scenes/<name>/`.**
+
+About 18 products still have UI in both trees, so "there's already a folder in `scenes/`" is not evidence that a new file belongs there. Check before you add.
+
+```sh
+# Where does one directory stand?
+python3 .agents/skills/placing-product-frontend-code/scripts/scene_product_split.py data-warehouse
+
+# Every scene dir with a product counterpart, most migrated first
+python3 .agents/skills/placing-product-frontend-code/scripts/scene_product_split.py
+```
+
+The script is advisory and read-only — no baseline, no exit code to satisfy. It counts hand-written `.ts`/`.tsx` on each side, skipping `generated/` (orval writes those, so they are not migration progress).
+
+## Deciding where a file goes
+
+| Situation | Where it goes |
+| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
+| `products/<name>/frontend/` holds as much or more than `scenes/<name>/` | `products/<name>/frontend/` — the scenes copy is a remnant |
+| The move is under way but early | `products/<name>/frontend/`, and move the files the new code touches if that is cheap |
+| `products/<name>/` exists, no `scenes/<name>/` yet | `products/<name>/frontend/` — never create the scenes directory |
+| No product directory at all, and the feature is product-shaped | Bootstrap the product: `bin/hogli product:bootstrap <name>`, see [products/README.md](../../../products/README.md) |
+| App-level scene — `settings`, `onboarding`, `billing`, `max`, `error-tracking` shells | `frontend/src/scenes/` is correct; these have nowhere else to go |
+
+The last row is the reason this is a skill and not a lint rule: deciding whether a new directory is a product or an app-level scene is a judgment call, and a check script that guesses gets it wrong on `onboarding` and `settings`.
+
+Migrating an existing scene wholesale is welcome and is the point of the convention. Expect that PR to report every merge-queue target once, because scenes register in `products/<name>/manifest.tsx` — a one-time cost per migration.
+
+## Why the directory is a real boundary
+
+`.github/scripts/trunk-impacted-targets.js` assigns merge-queue lanes by path.
+
+- A change anywhere under `frontend/` reports `fe:core` plus every `fe:product:*` target, so it serializes against every other frontend PR in the queue.
+- A change confined to `products/<name>/frontend/` reports one target.
+
+The obvious fix — narrow lanes with a frontend dependency graph instead of paths — was measured and does not work. A static import graph over the frontend (8430 files, 43924 edges) puts **2226 modules in a single strongly connected component**, 27% of the graph, spanning 31 products. Every member of an SCC has identical reverse-reachability by definition, so reverse-reachability from any file under `frontend/src` reaches 73 of 79 products — a leaf tab component five levels into the replay player gives the byte-identical answer to `types.ts`. Cutting all 498 `lib/**` → `scenes|products` back-edges moved it from 6918 to 6909 modules: hundreds of redundant cycles, not one bad edge.
+
+`bin/find-affected-stories` already concedes the same thing by listing `frontend/src/lib/` as a full-run invalidator.
+
+So path is the only signal that discriminates, and moving files is the only thing that narrows a lane. Note what this does and does not buy: merge-queue parallelism, not decoupling — the import graph stays as tangled as it was.
+
+## Related
+
+- [products/README.md](../../../products/README.md) — product layout and setup
+- [products/architecture.md](../../../products/architecture.md) — DTOs, facades, isolated testing
+- [frontend/src/AGENTS.md](../../../frontend/src/AGENTS.md) — the rest of the frontend guide
diff --git a/.agents/skills/placing-product-frontend-code/scripts/scene_product_split.py b/.agents/skills/placing-product-frontend-code/scripts/scene_product_split.py
new file mode 100644
index 000000000000..7596c9bc061d
--- /dev/null
+++ b/.agents/skills/placing-product-frontend-code/scripts/scene_product_split.py
@@ -0,0 +1,127 @@
+#!/usr/bin/env python3
+# ruff: noqa: T201 allow print statements
+"""
+Report where a product's frontend currently lives: ``products/<name>/frontend/``,
+``frontend/src/scenes/<name>/``, or both.
+
+Advisory only — nothing here fails a build. It answers "does this scene directory have a
+product counterpart, and how far has the move gone", so a new file lands in the right tree.
+
+Usage:
+ python scene_product_split.py # every scene dir with a product counterpart
+ python scene_product_split.py data-warehouse # one directory
+"""
+
+from __future__ import annotations
+
+import sys
+import argparse
+from dataclasses import dataclass
+from pathlib import Path
+
+REPO_ROOT = Path(__file__).resolve().parents[4]
+SCENES_ROOT = REPO_ROOT / "frontend/src/scenes"
+PRODUCTS_ROOT = REPO_ROOT / "products"
+
+SOURCE_SUFFIXES = (".ts", ".tsx")
+
+
+@dataclass(frozen=True)
+class SceneDir:
+ name: str
+ scene_files: int
+ product: str | None
+ product_files: int
+
+ @property
+ def status(self) -> str:
+ if self.product is None:
+ return "app-level"
+ if self.product_files == 0:
+ return "not started"
+ return "past halfway" if self.product_files >= self.scene_files else "under way"
+
+ @property
+ def destination(self) -> str | None:
+ return f"products/{self.product}/frontend/" if self.product else None
+
+
+def count_sources(root: Path) -> int:
+ """Hand-written .ts/.tsx under root. `generated/` trees are orval's output, not migration progress."""
+ if not root.is_dir():
+ return 0
+ return sum(
+ 1
+ for path in root.rglob("*")
+ if path.suffix in SOURCE_SUFFIXES and path.is_file() and "generated" not in path.relative_to(root).parts
+ )
+
+
+def product_directories() -> dict[str, str]:
+ """Normalized product name -> real directory name. scenes/ uses kebab-case, products/ snake_case."""
+ if not PRODUCTS_ROOT.is_dir():
+ return {}
+ return {entry.name.replace("_", ""): entry.name for entry in sorted(PRODUCTS_ROOT.iterdir()) if entry.is_dir()}
+
+
+def scan() -> dict[str, SceneDir]:
+ if not SCENES_ROOT.is_dir():
+ return {}
+ products = product_directories()
+ found: dict[str, SceneDir] = {}
+ for entry in sorted(SCENES_ROOT.iterdir()):
+ if not entry.is_dir():
+ continue
+ scene_files = count_sources(entry)
+ if scene_files == 0:
+ continue
+ product = products.get(entry.name.replace("-", "").replace("_", ""))
+ found[entry.name] = SceneDir(
+ name=entry.name,
+ scene_files=scene_files,
+ product=product,
+ product_files=count_sources(PRODUCTS_ROOT / product / "frontend") if product else 0,
+ )
+ return found
+
+
+def describe(d: SceneDir) -> str:
+ if not d.product:
+ return f" {d.name}/ {d.scene_files} files in scenes/ — app-level scene, no product counterpart"
+ return f" {d.name}/ {d.scene_files} in scenes/, {d.product_files} in {d.destination} — {d.status}"
+
+
+def main() -> int:
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("directory", nargs="?", help="A scene directory name, e.g. data-warehouse.")
+ args = parser.parse_args()
+
+ found = scan()
+
+ if args.directory:
+ d = found.get(args.directory)
+ if not d:
+ products = product_directories()
+ product = products.get(args.directory.replace("-", "").replace("_", ""))
+ if product:
+ print(f"No frontend/src/scenes/{args.directory}/ — put the UI in products/{product}/frontend/.")
+ else:
+ print(f"No frontend/src/scenes/{args.directory}/ and no products/ counterpart.")
+ print("New product-shaped UI: `bin/hogli product:bootstrap <name>`. See products/README.md.")
+ return 0
+ print(describe(d))
+ if d.product:
+ print(f"\n New files belong in {d.destination}, not frontend/src/scenes/{d.name}/.")
+ return 0
+
+ owned = [d for d in found.values() if d.product]
+ print(f"{len(found)} scene dirs; {len(owned)} have a product counterpart; ", end="")
+ print(f"{sum(d.scene_files for d in owned)} files awaiting a move.\n")
+ print("Scene dirs whose UI belongs under products/ (most migrated first):\n")
+ for d in sorted(owned, key=lambda d: -d.product_files):
+ print(describe(d))
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/AGENTS.md b/AGENTS.md
index c521f1bc2e8b..b6c0c4d4ea01 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -258,6 +258,7 @@ ALWAYS invoke the matching skill **before** writing or reviewing code in these a
- `/stacking-prs` — creating, restacking, adopting, or landing a stack of PRs (`gh stack`)
- `/implementing-mcp-tools` — adding/modifying endpoints or `tools.yaml`
- `/modifying-taxonomic-filter` — any TaxonomicFilter change
+- `/placing-product-frontend-code` — adding a frontend file or directory for a product, or deciding between `products/<name>/frontend/` and `frontend/src/scenes/<name>/`
- `/sending-notifications` — adding notification support
- `/writing-skills` — creating or updating skills in `.agents/skills/`
- `/writing-evals` — adding or changing eval suites, cases, scorers, or seeders under `products/posthog_ai/evals/` or `products/*/evals/`, touching the harness in `products/posthog_ai/eval_harness/`, or running those evals
diff --git a/frontend/src/AGENTS.md b/frontend/src/AGENTS.md
index e69498c24db0..43f711ab3daf 100644
--- a/frontend/src/AGENTS.md
+++ b/frontend/src/AGENTS.md
@@ -32,7 +32,19 @@ The same goes for patterns, not just components: before building a new scene or
> LemonUI vs quill lives in the root `AGENTS.md` ("Code Style → Frontend (quill vs LemonUI)"). If you're working somewhere quill genuinely applies (an MCP app, the desktop app), `packages/quill/packages/primitives/AGENTS.md` has its component-choice and spacing rules, and the two libraries must not be mixed inside one component's internals.
-## Rule 2 — Don't handwrite API types; use the generated ones
+## Rule 2 — A product's UI goes in `products/<name>/frontend/`
+
+`frontend/src/scenes/<name>/` is not the default home for product UI, and an existing folder there is not evidence that new files belong in it — about 18 products currently have UI in both trees. App-level scenes (`settings`, `onboarding`, `billing`, `max`) do legitimately live here.
+
+Before adding a file or a directory under `scenes/`, check where that product stands:
+
+```sh
+python3 .agents/skills/placing-product-frontend-code/scripts/scene_product_split.py <scene-dir>
+```
+
+Invoke `/placing-product-frontend-code` for the decision table and for why the path matters — it drives merge-queue lane assignment, and a change anywhere under `frontend/` serializes against every other frontend PR.
+
+## Rule 3 — Don't handwrite API types; use the generated ones
Django serializers are the source of truth. `hogli build:openapi` generates TypeScript types (suffix `Api`) and API functions. **Never write an `interface` that mirrors a backend serializer** — import the generated type instead.
@@ -44,7 +56,7 @@ Django serializers are the source of truth. `hogli build:openapi` generates Type
When touching `lib/api`, `api.get<`, `api.create<`, or any handwritten API interface, invoke the `/adopting-generated-api-types` skill first.
-## Rule 3 — Business logic in kea, not React hooks
+## Rule 4 — Business logic in kea, not React hooks
Covered by the root `AGENTS.md` (Code Style → Frontend). The discovery hint for this tree: if a scene/component has a `*Logic.ts`, that's where actions/reducers/selectors/listeners belong. See `/writing-kea-logics` and `/using-kea-disposables`.
@@ -83,4 +95,4 @@ Adding a button/toggle/action to a scene's `ScenePanel`? It must also go in that
- `layout/scenes/AGENTS.md` (scene action surfaces: `ScenePanel` + `SceneMenuBar` dual-write rule).
- `packages/quill/packages/primitives/AGENTS.md` — component selection matrix.
- `docs/published/handbook/engineering/conventions/frontend-coding.md` — frontend conventions.
-- Skills: `/writing-ui-components`, `/adopting-generated-api-types`, `/writing-kea-logics`, `/using-kea-disposables`, `/writing-tests`.
+- Skills: `/writing-ui-components`, `/placing-product-frontend-code`, `/adopting-generated-api-types`, `/writing-kea-logics`, `/using-kea-disposables`, `/writing-tests`.