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(skills): reject store skill names that collide with bundled skills (#100746)

posthog[bot]449869392ee1
diff --git a/docs/internal/skills/community-skills-api.md b/docs/internal/skills/community-skills-api.md
index 2040e9fc5ad5..32c9be4965b4 100644
--- a/docs/internal/skills/community-skills-api.md
+++ b/docs/internal/skills/community-skills-api.md
@@ -50,6 +50,11 @@ Because catalog content originates outside the app, the install path re-validate
trusting the sync:
- Bundled file paths and sizes are re-checked with the same guards as normal skill creation.
+- The target name is held to the rule a new store skill is held to, which refuses the name of a skill
+ PostHog bundles (`bundled_skill_names()` in `products/skills/backend/bundled_skills.py`). Both sets
+ of skills reach an agent host under one name space, so a store skill under a bundled name leaves the
+ host unable to tell which skill an agent asked for. Install such an entry under a different
+ `new_name`.
- Installs into auto-running namespaces are refused: the `signals-scout-` and `review-hog-` prefixes,
whose skills PostHog registers and runs on its own (Signals scouts run with privileged scopes,
ReviewHog skills auto-enable in a team's PR reviews). The whole `review-hog-` prefix is reserved,
@@ -91,7 +96,8 @@ After a conflict, retrieve the skill again and require new consent before anothe
also accepts a personal API key, and the inherited throttle key prefers the key hash, so one member
with several keys would otherwise get a fresh budget with each of them. The API-shaped
`BurstRateThrottle` would not fire here at all: it only counts personal-API-key traffic.
-- The slug is held to the same rule ingest applies (`SKILL_NAME_PATTERN`, no reserved name), and body,
+- The slug is held to the same rule ingest applies (`SKILL_NAME_PATTERN`, no reserved name, no name
+ PostHog bundles), and body,
file count, and per-file size to the same caps, so a publish that ingest would silently drop is
refused before the pull request exists. The manifest is also checked for paths that differ only by
case and for a name used as both a file and a folder, neither of which a git tree can hold.
diff --git a/products/posthog_ai/scripts/build_skills.py b/products/posthog_ai/scripts/build_skills.py
index aaf9c5af119a..963af708fd7f 100755
--- a/products/posthog_ai/scripts/build_skills.py
+++ b/products/posthog_ai/scripts/build_skills.py
@@ -42,6 +42,11 @@ from pydantic import BaseModel, Field, ValidationError
REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent
sys.path.insert(0, str(REPO_ROOT))
+# After the sys.path line above, because this module also runs as a script, where the repo root is
+# not importable until then. The skills store reads the same set to refuse a store skill that takes
+# a bundled name, so both sides read one definition.
+from products.skills.backend.bundled_skills import OMNIBUS_SKILL_NAMES # noqa: E402
+
MANIFEST_VERSION = "1.0.0"
_ZIP_FIXED_TIME = (2025, 1, 1, 0, 0, 0)
@@ -49,20 +54,6 @@ _FRONTMATTER_RE = re.compile(r"^---\s*\n(.*?)\n---\s*\n", re.DOTALL)
_BINARY_CHECK_SIZE = 8192
_MAX_SKILL_DESCRIPTION_LENGTH = 1024
_ALLOWED_SUBDIRS = {"references", "scripts"}
-# Skills authored in PostHog/context-mill. Every shipping consumer unzips this
-# repo's skills first and then unzips the context-mill release on top, so a
-# same-named skill here is overwritten instead of shipped — a failure that is
-# silent without this check, because the copy still builds and still publishes.
-OMNIBUS_SKILL_NAMES = frozenset(
- {
- "instrument-integration",
- "instrument-product-analytics",
- "instrument-feature-flags",
- "instrument-error-tracking",
- "instrument-llm-analytics",
- "instrument-logs",
- }
-)
# Tool/skill reference linting: skills must only reference MCP tools and skills that exist.
# The valid tool names come from the checked-in MCP schema registries (kept in sync with the
diff --git a/products/signals/backend/scout_harness/serializers.py b/products/signals/backend/scout_harness/serializers.py
index 3ac34259c860..05c07ae93c4f 100644
--- a/products/signals/backend/scout_harness/serializers.py
+++ b/products/signals/backend/scout_harness/serializers.py
@@ -88,6 +88,7 @@ from products.skills.backend.api.skill_serializers import (
MAX_SKILL_FILE_COUNT,
SPEC_DESCRIPTION_MAX_LENGTH,
LLMSkillFileInputSerializer,
+ validate_new_skill_name_value,
validate_skill_body_size,
validate_skill_name_value,
)
@@ -3583,10 +3584,12 @@ class SignalScoutConfigCreateSerializer(SignalScoutConfigOptionsSerializer):
)
def validate_skill_name(self, value: str) -> str:
- # The generic skill-name contract first, like the sibling create serializer. Nothing
- # downstream re-checks it: the model column carries no validator, `create_skill` skips the
- # pattern, and the view's existence check only proves a row exists. It is also what keeps
- # scout names and the `pipeline:` note audiences disjoint (see `note_targets`).
+ # The generic skill-name contract first, not the stricter contract the sibling create
+ # serializer applies: this field names a skill the project already holds, and the harness
+ # seeds the canonical scouts under names the bundled fleet also uses. Nothing downstream
+ # re-checks it: the model column carries no validator, `create_skill` skips the pattern,
+ # and the view's existence check only proves a row exists. It is also what keeps scout
+ # names and the `pipeline:` note audiences disjoint (see `note_targets`).
value = validate_skill_name_value(value)
if error := reserved_scout_name_error(value):
raise serializers.ValidationError(error)
@@ -3642,7 +3645,7 @@ class SignalScoutCreateSerializer(serializers.Serializer):
)
def validate_name(self, value: str) -> str:
- value = validate_skill_name_value(value)
+ value = validate_new_skill_name_value(value)
if error := reserved_scout_name_error(value):
raise serializers.ValidationError(error)
return value
diff --git a/products/signals/backend/scout_harness/suggestions_runner.py b/products/signals/backend/scout_harness/suggestions_runner.py
index 524407f49c82..1e6c0d755b9a 100644
--- a/products/signals/backend/scout_harness/suggestions_runner.py
+++ b/products/signals/backend/scout_harness/suggestions_runner.py
@@ -46,7 +46,7 @@ from products.signals.backend.temporal.agentic import (
get_or_create_signals_sandbox_env,
resolve_acting_user_id_for_team,
)
-from products.skills.backend.api.skill_serializers import validate_skill_name_value
+from products.skills.backend.api.skill_serializers import validate_new_skill_name_value
from products.tasks.backend.facade import api as tasks_facade
from products.tasks.backend.facade.agents import CustomPromptSandboxContext, MultiTurnSession
@@ -59,10 +59,11 @@ def _valid_cron(expression: str) -> bool:
def _valid_custom_name(name: str) -> bool:
- # Any valid skill name is a valid scout name. The producer prompt still asks for prefixed
- # names, which is a prompt choice rather than a validity rule.
+ # The same rule the scout create API applies, so a suggestion can never fail on the click.
+ # Any name that can name a new skill is a valid scout name. The producer prompt still asks for
+ # prefixed names, which is a prompt choice rather than a validity rule.
try:
- validate_skill_name_value(name)
+ validate_new_skill_name_value(name)
except serializers.ValidationError:
return False
# The inbox-reserved names clear the generic contract but the create serializer refuses them,
diff --git a/products/skills/backend/api/community_publish_services.py b/products/skills/backend/api/community_publish_services.py
index a0961b65e33d..1c430e75717a 100644
--- a/products/skills/backend/api/community_publish_services.py
+++ b/products/skills/backend/api/community_publish_services.py
@@ -32,6 +32,7 @@ from .skill_services import (
MAX_SKILL_FILE_COUNT,
RESERVED_SKILL_NAMES,
SKILL_NAME_PATTERN,
+ bundled_skill_name_error,
check_allowed_tool_name,
normalize_skill_file_path,
)
@@ -148,6 +149,9 @@ def _validate_slug(slug: str) -> str:
raise CommunitySkillPublishValidationError(
f"'{slug}' is a reserved name and can't be published to the community."
)
+ # A catalog entry installs under its slug, so a bundled name would only be refused at install.
+ if error := bundled_skill_name_error(slug):
+ raise CommunitySkillPublishValidationError(error)
return slug
diff --git a/products/skills/backend/api/community_skill_services.py b/products/skills/backend/api/community_skill_services.py
index 13ab43d129af..cc15caa7ff1c 100644
--- a/products/skills/backend/api/community_skill_services.py
+++ b/products/skills/backend/api/community_skill_services.py
@@ -10,7 +10,7 @@ from posthog.models import Team, User
from ..marketplace.packaging import SPEC_DESCRIPTION_MAX_LENGTH
from ..models.community_skills import CommunitySkill, CommunitySkillVote
from ..models.skills import LLMSkill
-from .skill_serializers import validate_allowed_tool, validate_skill_file_path, validate_skill_name_value
+from .skill_serializers import validate_allowed_tool, validate_new_skill_name_value, validate_skill_file_path
from .skill_services import MAX_SKILL_FILE_BYTES, create_skill
from .skill_template_services import parse_template_variables, render_template_skill
@@ -103,7 +103,7 @@ def install_community_skill(
raise CommunitySkillNotFoundError()
try:
- target_name = validate_skill_name_value(new_name or community_skill.slug)
+ target_name = validate_new_skill_name_value(new_name or community_skill.slug)
except DRFValidationError as err:
raise CommunitySkillInvalidPayloadError(_first_error_detail(err)) from err
diff --git a/products/skills/backend/api/community_skill_sync.py b/products/skills/backend/api/community_skill_sync.py
index 1348eec1cdf0..6db56afdb759 100644
--- a/products/skills/backend/api/community_skill_sync.py
+++ b/products/skills/backend/api/community_skill_sync.py
@@ -19,6 +19,7 @@ from .skill_services import (
MAX_SKILL_FILE_COUNT,
RESERVED_SKILL_NAMES,
SKILL_NAME_PATTERN,
+ bundled_skill_names,
)
logger = structlog.get_logger(__name__)
@@ -80,9 +81,11 @@ def _validate_entry_shape(entry: dict[str, Any]) -> None:
"""
slug = entry.get("slug", "")
# The slug is both the catalog URL segment and the default installed-skill name, so it must
- # satisfy the skill-name rules — lowercase alnum + single hyphens, not reserved. This also
- # keeps DRF's default lookup regex (which rejects '.'/'/') able to route detail/install URLs,
- # and means the default-name install can never raise an uncaught name ValidationError.
+ # satisfy the skill-name rules — lowercase alnum + single hyphens, neither reserved nor a name
+ # PostHog bundles (an entry under a bundled name would install to a name the agent host cannot
+ # tell from the bundled skill). This also keeps DRF's default lookup regex (which rejects
+ # '.'/'/') able to route detail/install URLs, and means the default-name install can never
+ # raise an uncaught name ValidationError.
# fullmatch, not match: `$` also matches just before a trailing newline, so `match` would
# accept "valid-skill\n" and persist the newline into the URL segment and install name.
if (
@@ -90,6 +93,7 @@ def _validate_entry_shape(entry: dict[str, Any]) -> None:
or not SKILL_NAME_PATTERN.fullmatch(slug)
or "--" in slug
or slug.lower() in RESERVED_SKILL_NAMES
+ or slug.lower() in bundled_skill_names()
):
raise ValueError(f"slug '{slug}' is not a valid, routable skill identifier")
diff --git a/products/skills/backend/api/skill_serializers.py b/products/skills/backend/api/skill_serializers.py
index 37853bf1418f..dd4631f8c7fd 100644
--- a/products/skills/backend/api/skill_serializers.py
+++ b/products/skills/backend/api/skill_serializers.py
@@ -26,6 +26,7 @@ from .skill_services import (
RESERVED_SKILL_NAMES,
SKILL_NAME_PATTERN,
LLMSkillOwnerNotFoundError,
+ bundled_skill_name_error,
check_allowed_tool_name,
compute_spec_problems,
normalize_skill_file_path,
@@ -84,6 +85,18 @@ def validate_skill_name_value(value: str) -> str:
return value
+def validate_new_skill_name_value(value: str) -> str:
+ """Validate a name a team is claiming for a skill: create, rename, duplicate, install, import.
+
+ Adds the bundled-name rule to `validate_skill_name_value`, which stays the looser contract for
+ a name that points at a skill the project already holds (see `bundled_skill_name_error`).
+ """
+ value = validate_skill_name_value(value)
+ if error := bundled_skill_name_error(value):
+ raise serializers.ValidationError(error, code="bundled_skill_name")
+ return value
+
+
def validate_skill_file_path(value: str) -> str:
try:
return normalize_skill_file_path(value)
@@ -605,6 +618,9 @@ class LLMSkillSerializer(serializers.ModelSerializer):
"first_version_created_at",
]
extra_kwargs = {
+ # No bundled-name rule here: this base serves the read responses, and a project's
+ # seeded canonical skills come back under the names PostHog ships. The write
+ # serializers carry that rule.
"name": {
"help_text": "Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters."
},
@@ -721,7 +737,7 @@ class LLMSkillSerializer(serializers.ModelSerializer):
return data
def validate_name(self, value: str) -> str:
- return validate_skill_name_value(value)
+ return validate_new_skill_name_value(value)
def validate_body(self, value: str) -> str:
return validate_skill_body_size(value)
@@ -772,6 +788,13 @@ class LLMSkillCreateSerializer(LLMSkillSerializer):
class Meta(LLMSkillSerializer.Meta):
read_only_fields = [f for f in LLMSkillSerializer.Meta.read_only_fields if f not in ("files", "owners")]
+ extra_kwargs = {
+ **LLMSkillSerializer.Meta.extra_kwargs,
+ "name": {
+ "help_text": "Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters. "
+ "Cannot be the name of a skill PostHog ships."
+ },
+ }
def validate_files(self, value: list[dict[str, Any]]) -> list[dict[str, Any]]:
return _validate_files(value)
@@ -854,22 +877,22 @@ class LLMSkillImportSerializer(serializers.Serializer):
class LLMSkillDuplicateSerializer(serializers.Serializer):
new_name = serializers.CharField(
max_length=64,
- help_text="Name for the duplicated skill. Must be unique.",
+ help_text="Name for the duplicated skill. Must be unique, and cannot be the name of a skill PostHog ships.",
)
def validate_new_name(self, value: str) -> str:
- return validate_skill_name_value(value)
+ return validate_new_skill_name_value(value)
class LLMSkillRenameSerializer(serializers.Serializer):
new_name = serializers.CharField(
max_length=MAX_SKILL_NAME_LENGTH,
- help_text="New name for the skill. Must be unique in the project, and must not start with "
- "'signals-scout-' or 'review-hog-'.",
+ help_text="New name for the skill. Must be unique in the project, cannot be the name of a skill "
+ "PostHog ships, and must not start with 'signals-scout-' or 'review-hog-'.",
)
def validate_new_name(self, value: str) -> str:
- return validate_skill_name_value(value)
+ return validate_new_skill_name_value(value)
class LLMSkillResolveResponseSerializer(serializers.Serializer):
diff --git a/products/skills/backend/api/skill_services.py b/products/skills/backend/api/skill_services.py
index b3e1c1bd3542..c80ff388c8e6 100644
--- a/products/skills/backend/api/skill_services.py
+++ b/products/skills/backend/api/skill_services.py
@@ -10,6 +10,7 @@ from django.utils import timezone
from posthog.dataclasses import frozen
from posthog.models import Team, User
+from ..bundled_skills import bundled_skill_names
from ..marketplace.packaging import CODEX_METADATA_PATH, SPEC_DESCRIPTION_MAX_LENGTH, compute_plugin_version
from ..models.skills import (
CATEGORY_BY_NAME_PREFIX,
@@ -44,6 +45,24 @@ MAX_SKILL_NAME_LENGTH = 64
RESERVED_SKILL_FILE_PATHS = {"skill.md"}
+def bundled_skill_name_error(value: str) -> str | None:
+ """Why `value` cannot name a new store skill, or None when it can.
+
+ An agent host loads the skills PostHog bundles (products/*/skills, shipped as dist/skills.zip)
+ next to the team's store skills under one flat name space, so a store skill that repeats a
+ bundled name leaves two skills under one name and the host no way to tell which one an agent
+ asked for. The rule holds a name a team claims, not a name that points at a skill the project
+ already holds: the scout harness seeds the canonical `signals-scout-*` skills into every
+ project, so those bundled names are legitimately in use there.
+
+ Returns the message rather than raising it so the REST, MCP tool, community publish and
+ community sync paths can each raise their own error type from the one rule.
+ """
+ if value.lower() not in bundled_skill_names():
+ return None
+ return f"PostHog already ships a skill named '{value}'. Pick a different name."
+
+
def skill_name_is_well_formed(value: str) -> bool:
"""The shape half of the skill-name contract, without the reserved-name rule.
diff --git a/products/skills/backend/api/skills.py b/products/skills/backend/api/skills.py
index 7654ca322503..9387f6b48323 100644
--- a/products/skills/backend/api/skills.py
+++ b/products/skills/backend/api/skills.py
@@ -111,8 +111,8 @@ from .skill_serializers import (
LLMSkillSerializer,
LLMSkillVersionSummarySerializer,
validate_allowed_tool,
+ validate_new_skill_name_value,
validate_skill_body_size,
- validate_skill_name_value,
)
from .skill_services import (
LLMSkillDescriptionTooLongError,
@@ -1298,11 +1298,11 @@ class LLMSkillViewSet(
# (oversized body/files, whitespace-bearing tools) the rest of the system assumes is bounded.
# _spec_problem_messages already covers the description, the name shape and the file paths.
problems: list[str] = _spec_problem_messages(skill_export)
- # The reserved-name rule is all this adds on top of the shape rules above, so calling it for
- # a malformed name would report that defect twice.
+ # The reserved-name and bundled-name rules are all this adds on top of the shape rules
+ # above, so calling it for a malformed name would report that defect twice.
if skill_name_is_well_formed(skill_export.name):
try:
- validate_skill_name_value(skill_export.name)
+ validate_new_skill_name_value(skill_export.name)
except serializers.ValidationError as err:
problems.append(f"name: {self._first_error(err)}")
try:
diff --git a/products/skills/backend/api/test/test_community_publish_services.py b/products/skills/backend/api/test/test_community_publish_services.py
index 9704ca50ecff..ce7f8c979c4b 100644
--- a/products/skills/backend/api/test/test_community_publish_services.py
+++ b/products/skills/backend/api/test/test_community_publish_services.py
@@ -253,7 +253,18 @@ class TestRenderCommunitySkillFiles:
def test_rejects_bad_slug(self) -> None:
# "new" and the category-tab slugs are rejected by ingest, so publishing one merges a pull
# request whose skill never appears in the catalog. A trailing newline needs `fullmatch`.
- for bad in ["Make-PR", "make_pr", "-bad", "double--hyphen", "x" * 65, "new", "review-hog", "make-pr\n"]:
+ # A catalog entry installs under its slug, so a slug PostHog bundles is refused here too.
+ for bad in [
+ "Make-PR",
+ "make_pr",
+ "-bad",
+ "double--hyphen",
+ "x" * 65,
+ "new",
+ "review-hog",
+ "make-pr\n",
+ "signals-scout-logs",
+ ]:
try:
render_community_skill_files(slug=bad, name="n", description="d", body="b")
except CommunitySkillPublishError:
diff --git a/products/skills/backend/api/test/test_community_skill_sync.py b/products/skills/backend/api/test/test_community_skill_sync.py
index a5039e495110..b2af65a35c98 100644
--- a/products/skills/backend/api/test/test_community_skill_sync.py
+++ b/products/skills/backend/api/test/test_community_skill_sync.py
@@ -221,6 +221,9 @@ class TestCommunitySkillSync(APIBaseTest):
# Shape checks: a slug DRF can't route, or a mistyped metadata/tags/allowed_tools that
# would 500 the list/detail render or fracture allowed-tools on export.
("non_routable_slug", {"slug": "triage.v2"}),
+ # Installs under its slug, so a slug PostHog bundles would land a catalog skill under a
+ # bundled name.
+ ("bundled_skill_slug", {"slug": "signals-scout-logs"}),
("scalar_metadata", {"metadata": 5}),
("non_list_tags", {"tags": 5}),
("whitespace_allowed_tool", {"allowed_tools": ["Bash Write"]}),
diff --git a/products/skills/backend/api/test/test_marketplace_endpoints.py b/products/skills/backend/api/test/test_marketplace_endpoints.py
index c86f318b9eee..d035f6776195 100644
--- a/products/skills/backend/api/test/test_marketplace_endpoints.py
+++ b/products/skills/backend/api/test/test_marketplace_endpoints.py
@@ -963,11 +963,12 @@ class TestImportAndCreateValidation(APIBaseTest):
[
("malformed", "Bad_Name", "cannot be a skill directory name"),
("reserved", "community", "is a reserved name"),
+ ("bundled_skill", "signals-scout-logs", "already ships a skill"),
]
)
def test_import_reports_one_message_per_name_problem(self, _label: str, name: str, expected: str):
- # The shared spec rules cover the name shape and the import adds the reserved-name rule on
- # top, so a name that breaks one rule must not be reported by both.
+ # The shared spec rules cover the name shape and the import adds the reserved-name and
+ # bundled-name rules on top, so a name that breaks one rule must not be reported by both.
export = SkillExport(name=name, description="A skill.", body="# skill\n", version=1)
upload = SimpleUploadedFile("skill.zip", build_skill_zip(export), content_type="application/zip")
diff --git a/products/skills/backend/api/test/test_skills.py b/products/skills/backend/api/test/test_skills.py
index 781de9fbb5f9..1d5cbfb8e64f 100644
--- a/products/skills/backend/api/test/test_skills.py
+++ b/products/skills/backend/api/test/test_skills.py
@@ -199,6 +199,26 @@ class TestLLMSkillAPI(APIBaseTest):
assert response.status_code == status.HTTP_400_BAD_REQUEST
+ @parameterized.expand(
+ [
+ # Named by its directory under products/signals/skills/.
+ ("skill_directory", "signals-scout-logs"),
+ # Named by the frontmatter of a loose entry point, which its path does not carry.
+ ("loose_entry_point", "adding-warehouse-person-properties"),
+ ]
+ )
+ def test_create_skill_rejects_a_bundled_skill_name(self, _label, skill_name):
+ response = self.client.post(
+ self._url(),
+ data={"name": skill_name, "description": "Shadows a bundled skill.", "body": "# Shadow"},
+ format="json",
+ )
+
+ assert response.status_code == status.HTTP_400_BAD_REQUEST
+ assert response.json()["attr"] == "name"
+ assert "already ships a skill" in response.json()["detail"]
+ assert not LLMSkill.objects.filter(team=self.team, name=skill_name).exists()
+
def test_create_skill_requires_description(self):
response = self.client.post(
self._url(),
@@ -1571,6 +1591,19 @@ class TestLLMSkillAPI(APIBaseTest):
assert LLMSkill.objects.filter(team=self.team, name=old_name, deleted=False).exists()
assert not LLMSkill.objects.filter(team=self.team, name=new_name).exists()
+ @parameterized.expand([("rename", "rename"), ("duplicate", "duplicate")])
+ def test_taking_a_bundled_skill_name_is_rejected(self, _label, action):
+ self.create_skill(name="source")
+
+ response = self.client.post(
+ self._url(f"name/source/{action}"),
+ data={"new_name": "signals-scout-logs"},
+ format="json",
+ )
+
+ assert response.status_code == status.HTTP_400_BAD_REQUEST
+ assert not LLMSkill.objects.filter(team=self.team, name="signals-scout-logs").exists()
+
def test_rename_of_a_missing_skill_is_not_found(self):
response = self.client.post(
self._url("name/nope/rename"),
diff --git a/products/skills/backend/bundled_skills.py b/products/skills/backend/bundled_skills.py
new file mode 100644
index 000000000000..71d46082c4bd
--- /dev/null
+++ b/products/skills/backend/bundled_skills.py
@@ -0,0 +1,108 @@
+"""The names of the skills this repository bundles.
+
+`hogli build:skills` renders every skill under `products/*/skills/` into `dist/skills.zip`, which
+ships to the agent hosts. A host loads those skills next to the store skills of the team it runs
+for, in one flat name space, so the two sets cannot both hold a name: the skills store reads this
+set to keep a store skill from taking a bundled one.
+"""
+
+from __future__ import annotations
+
+import re
+from functools import cache
+from pathlib import Path
+
+import yaml
+
+# Skills authored in PostHog/context-mill. Every shipping consumer unzips this
+# repo's skills first and then unzips the context-mill release on top, so a
+# same-named skill here is overwritten instead of shipped — a failure that is
+# silent without this check, because the copy still builds and still publishes.
+OMNIBUS_SKILL_NAMES = frozenset(
+ {
+ "instrument-integration",
+ "instrument-product-analytics",
+ "instrument-feature-flags",
+ "instrument-error-tracking",
+ "instrument-llm-analytics",
+ "instrument-logs",
+ }
+)
+
+# The products tree, resolved from this file at products/skills/backend/bundled_skills.py.
+_PRODUCTS_DIR = Path(__file__).resolve().parents[2]
+# Markdown that sits beside skills without being a skill.
+_NON_SKILL_FILES = frozenset({"README.md", "AGENTS.md", "CLAUDE.md"})
+# Frontmatter opens the entry point, so a bounded read holds all of it in every ordinary case.
+_FRONTMATTER_READ_BYTES = 4096
+# The block `parse_frontmatter` in products/posthog_ai/scripts/build_skills.py reads.
+_FRONTMATTER_RE = re.compile(r"^---\s*\n(.*?)\n---\s*\n", re.DOTALL)
+
+
+def _entry_point(path: Path) -> Path | None:
+ """Return the file a skill is built from, or None when `path` holds no skill.
+
+ Mirrors `SkillDiscoverer.discover` in products/posthog_ai/scripts/build_skills.py: a skill is
+ a directory holding a SKILL.md(.j2), or a loose <name>.md(.j2) file. The two walks must agree,
+ because a skill the build ships and this walk misses is a name the skills store hands out.
+ """
+ if path.is_dir():
+ for candidate in (path / "SKILL.md.j2", path / "SKILL.md"):
+ if candidate.is_file():
+ return candidate
+ return None
+ if path.name in _NON_SKILL_FILES or not path.name.endswith((".md", ".md.j2")):
+ return None
+ return path
+
+
+def _declared_name(entry_point: Path) -> str | None:
+ """Return the `name` field of the entry point's YAML frontmatter, or None when it has none.
+
+ `SkillBuilder.build_skill` ships a skill under its frontmatter name rather than its path name,
+ and the two differ for a loose entry point: products/customer_analytics/skills/SKILL.md ships
+ as `adding-warehouse-person-properties`.
+
+ The block is parsed as YAML, the way the build parses it, so a quoted name or a trailing
+ comment resolves to the string the build ships under. Reading the raw text after `name:`
+ instead would record `bundled-skill # note` and let a store skill take `bundled-skill`.
+ A `.md.j2` entry point is read unrendered, so a templated name comes back with its braces and
+ matches nothing. The templated names are the context-mill ones, which `OMNIBUS_SKILL_NAMES`
+ already holds.
+ """
+ try:
+ with entry_point.open(encoding="utf-8", errors="replace") as handle:
+ head = handle.read(_FRONTMATTER_READ_BYTES)
+ match = _FRONTMATTER_RE.match(head)
+ if match is None:
+ # Frontmatter longer than the prefix: read the rest to reach its closing delimiter.
+ match = _FRONTMATTER_RE.match(head + handle.read())
+ if match is None:
+ return None
+ frontmatter = yaml.safe_load(match.group(1))
+ except (OSError, yaml.YAMLError):
+ return None
+ if not isinstance(frontmatter, dict):
+ return None
+ name = frontmatter.get("name")
+ return name if isinstance(name, str) else None
+
+
+def _path_name(path: Path) -> str:
+ return path.name if path.is_dir() else path.name.removesuffix(".j2").removesuffix(".md")
+
+
+@cache
+def bundled_skill_names() -> frozenset[str]:
+ """Every bundled skill name, lowercased.
+
+ Cached because the set is fixed for the life of the process: it only changes with a deploy.
+ """
+ names = {name.lower() for name in OMNIBUS_SKILL_NAMES}
+ for skills_dir in _PRODUCTS_DIR.glob("*/skills"):
+ for path in skills_dir.iterdir():
+ entry_point = _entry_point(path)
+ if entry_point is None:
+ continue
+ names.add((_declared_name(entry_point) or _path_name(path)).lower())
+ return frozenset(names)
diff --git a/products/skills/backend/test_bundled_skills.py b/products/skills/backend/test_bundled_skills.py
new file mode 100644
index 000000000000..255510f5e95e
--- /dev/null
+++ b/products/skills/backend/test_bundled_skills.py
@@ -0,0 +1,44 @@
+from pathlib import Path
+from tempfile import mkdtemp
+
+from django.test import SimpleTestCase
+
+from parameterized import parameterized
+
+from products.skills.backend.bundled_skills import _declared_name, bundled_skill_names
+
+
+class TestBundledSkills(SimpleTestCase):
+ @parameterized.expand(
+ [
+ ("plain", "name: a-skill\ndescription: d", "a-skill"),
+ # YAML semantics, the way the build reads the block. Raw text after `name:` would
+ # record `a-skill # note`, and a store skill could then take `a-skill`.
+ ("trailing_comment", "name: a-skill # note", "a-skill"),
+ ("quoted", 'name: "a-skill"', "a-skill"),
+ # Longer than the bounded first read, so the rest of the file has to be read.
+ ("long_frontmatter", "description: " + "x" * 5000 + "\nname: a-skill", "a-skill"),
+ ("no_name", "description: d", None),
+ ("non_string_name", "name: 42", None),
+ ]
+ )
+ def test_declared_name_reads_the_frontmatter_the_build_reads(self, _label, frontmatter, expected):
+ entry_point = self._write(f"---\n{frontmatter}\n---\n# Body\n")
+
+ assert _declared_name(entry_point) == expected
+
+ def test_declared_name_is_none_without_frontmatter(self):
+ assert _declared_name(self._write("# Body only\n")) is None
+
+ def test_bundled_skill_names_holds_the_tree_and_the_omnibus_names(self):
+ # A walk rooted at the wrong directory returns the omnibus names alone and silently stops
+ # guarding every skill in the tree.
+ names = bundled_skill_names()
+
+ assert "signals-scout-logs" in names
+ assert "instrument-logs" in names
+
+ def _write(self, content: str) -> Path:
+ entry_point = Path(mkdtemp()) / "SKILL.md"
+ entry_point.write_text(content)
+ return entry_point
diff --git a/products/skills/backend/tools/skills.py b/products/skills/backend/tools/skills.py
index 1963bb354ed3..68d3bf498a6b 100644
--- a/products/skills/backend/tools/skills.py
+++ b/products/skills/backend/tools/skills.py
@@ -22,6 +22,7 @@ from products.skills.backend.api.skill_services import (
LLMSkillVersionConflictError,
LLMSkillVersionLimitError,
archive_skill,
+ bundled_skill_name_error,
create_skill,
get_latest_skills_queryset,
get_skill_by_name_from_db,
@@ -145,7 +146,10 @@ class GetSkillFileArgs(BaseModel):
class CreateSkillArgs(BaseModel):
- name: str = Field(description="Kebab-case skill name. <=64 chars. Must be unique within the team.")
+ name: str = Field(
+ description="Kebab-case skill name. <=64 chars. Must be unique within the team, and cannot be the name "
+ "of a skill PostHog ships."
+ )
description: str = Field(
max_length=SPEC_DESCRIPTION_MAX_LENGTH,
description="Short summary explaining what the skill does and when agents should pick it. <=1024 chars.",
@@ -403,9 +407,12 @@ class CreateLLMSkillTool(MaxTool):
files: list[dict[str, str]] | None = None,
) -> tuple[str, None]:
# The tool calls create_skill directly, which skips the serializer's name validation, so a
- # reserved name would persist a skill whose /skills/<name> page is taken by a tab route.
+ # reserved name would persist a skill whose /skills/<name> page is taken by a tab route,
+ # and a bundled name would persist one an agent host cannot tell from the skill we ship.
if name.lower() in RESERVED_SKILL_NAMES:
raise MaxToolFatalError(f"'{name}' is a reserved name and cannot be used for a skill.")
+ if error := bundled_skill_name_error(name):
+ raise MaxToolFatalError(error)
try:
skill = await database_sync_to_async(create_skill)(
diff --git a/products/skills/backend/tools/test_skills.py b/products/skills/backend/tools/test_skills.py
index ccb0e2c05e35..c598ac191380 100644
--- a/products/skills/backend/tools/test_skills.py
+++ b/products/skills/backend/tools/test_skills.py
@@ -200,13 +200,21 @@ class TestCreateLLMSkillTool(BaseTest):
assert first_file is not None
assert first_file.path == "scripts/mandelbrot.py"
- def test_reserved_name_raises_fatal(self):
+ @parameterized.expand(
+ [
+ ("route_name", "community", "reserved name"),
+ # A name PostHog bundles: the tool writes through create_skill, which runs no name
+ # validation of its own, so the check has to sit on the tool.
+ ("bundled_skill_name", "signals-scout-logs", "already ships a skill"),
+ ]
+ )
+ def test_unusable_name_raises_fatal(self, _label, name, expected_error):
tool = CreateLLMSkillTool(team=self.team, user=self.user)
- with self.assertRaisesRegex(MaxToolFatalError, "reserved name"):
- _run(tool, name="community", description="d", body="b")
+ with self.assertRaisesRegex(MaxToolFatalError, expected_error):
+ _run(tool, name=name, description="d", body="b")
- assert not LLMSkill.objects.filter(team=self.team, name="community").exists()
+ assert not LLMSkill.objects.filter(team=self.team, name=name).exists()
def test_duplicate_name_raises_fatal(self):
LLMSkill.objects.create(team=self.team, name="dup", description="d", body="b")
diff --git a/products/skills/frontend/generated/api.schemas.ts b/products/skills/frontend/generated/api.schemas.ts
index 0f8af0daa288..a83ca21ce104 100644
--- a/products/skills/frontend/generated/api.schemas.ts
+++ b/products/skills/frontend/generated/api.schemas.ts
@@ -440,7 +440,7 @@ export interface LLMSkillFileInputApi {
export interface LLMSkillCreateApi {
readonly id: string
/**
- * Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters.
+ * Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters. Cannot be the name of a skill PostHog ships.
* @maxLength 64
*/
name: string
@@ -650,7 +650,7 @@ export interface PatchedLLMSkillPublishApi {
export interface LLMSkillDuplicateApi {
/**
- * Name for the duplicated skill. Must be unique.
+ * Name for the duplicated skill. Must be unique, and cannot be the name of a skill PostHog ships.
* @maxLength 64
*/
new_name: string
@@ -737,7 +737,7 @@ export interface LLMSkillPublishConflictApi {
export interface LLMSkillRenameApi {
/**
- * New name for the skill. Must be unique in the project, and must not start with 'signals-scout-' or 'review-hog-'.
+ * New name for the skill. Must be unique in the project, cannot be the name of a skill PostHog ships, and must not start with 'signals-scout-' or 'review-hog-'.
* @maxLength 64
*/
new_name: string
diff --git a/products/skills/frontend/generated/api.zod.ts b/products/skills/frontend/generated/api.zod.ts
index ba45b8bb3214..3c2842f052ea 100644
--- a/products/skills/frontend/generated/api.zod.ts
+++ b/products/skills/frontend/generated/api.zod.ts
@@ -45,7 +45,9 @@ export const LlmSkillsCreateBody = /* @__PURE__ */ zod
name: zod
.string()
.max(llmSkillsCreateBodyNameMax)
- .describe('Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters.'),
+ .describe(
+ 'Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters. Cannot be the name of a skill PostHog ships.'
+ ),
description: zod
.string()
.max(llmSkillsCreateBodyDescriptionMax)
@@ -247,7 +249,7 @@ export const LlmSkillsNameDuplicateCreateBody = /* @__PURE__ */ zod.object({
new_name: zod
.string()
.max(llmSkillsNameDuplicateCreateBodyNewNameMax)
- .describe('Name for the duplicated skill. Must be unique.'),
+ .describe('Name for the duplicated skill. Must be unique, and cannot be the name of a skill PostHog ships.'),
})
export const llmSkillsNameFilesCreateBodyPathMax = 500
@@ -351,6 +353,6 @@ export const LlmSkillsNameRenameCreateBody = /* @__PURE__ */ zod.object({
.string()
.max(llmSkillsNameRenameCreateBodyNewNameMax)
.describe(
- "New name for the skill. Must be unique in the project, and must not start with 'signals-scout-' or 'review-hog-'."
+ "New name for the skill. Must be unique in the project, cannot be the name of a skill PostHog ships, and must not start with 'signals-scout-' or 'review-hog-'."
),
})
diff --git a/products/skills/frontend/skillConstants.ts b/products/skills/frontend/skillConstants.ts
index ae05f49826dd..f2e5e942f52e 100644
--- a/products/skills/frontend/skillConstants.ts
+++ b/products/skills/frontend/skillConstants.ts
@@ -17,6 +17,8 @@ export const PRODUCT_OWNED_SKILL_NAME_PREFIXES = ['signals-scout-', 'review-hog-
// Names that collide with reserved /skills routes: 'new' (the create form) and the tab slugs
// registered under /skills/<slug> in manifest.tsx. A skill with one of these names would be
// shadowed by its route. Kept in sync with RESERVED_SKILL_NAMES in the backend skill_serializers.
+// The names of the skills PostHog bundles are refused too, but only by the server: the list is
+// read from the repository tree at products/*/skills/, so the client cannot hold a copy.
const RESERVED_SKILL_NAMES = new Set(['new', 'scouts', 'review-hog', 'community'])
export function validateSkillName(name: string): string | undefined {
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 68793735ef2c..fd39c37451d1 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -50869,7 +50869,7 @@ export namespace Schemas {
export interface LLMSkillCreate {
readonly id: string;
/**
- * Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters.
+ * Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters. Cannot be the name of a skill PostHog ships.
* @maxLength 64
*/
name: string;
@@ -50932,7 +50932,7 @@ export namespace Schemas {
export interface LLMSkillDuplicate {
/**
- * Name for the duplicated skill. Must be unique.
+ * Name for the duplicated skill. Must be unique, and cannot be the name of a skill PostHog ships.
* @maxLength 64
*/
new_name: string;
@@ -51190,7 +51190,7 @@ export namespace Schemas {
export interface LLMSkillRename {
/**
- * New name for the skill. Must be unique in the project, and must not start with 'signals-scout-' or 'review-hog-'.
+ * New name for the skill. Must be unique in the project, cannot be the name of a skill PostHog ships, and must not start with 'signals-scout-' or 'review-hog-'.
* @maxLength 64
*/
new_name: string;
diff --git a/services/mcp/src/generated/skills/api.ts b/services/mcp/src/generated/skills/api.ts
index cbe370df7fb7..d97356b46d31 100644
--- a/services/mcp/src/generated/skills/api.ts
+++ b/services/mcp/src/generated/skills/api.ts
@@ -63,7 +63,9 @@ export const LlmSkillsCreateBody = () => zod
name: zod
.string()
.max(llmSkillsCreateBodyNameMax)
- .describe('Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters.'),
+ .describe(
+ 'Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters. Cannot be the name of a skill PostHog ships.'
+ ),
description: zod
.string()
.max(llmSkillsCreateBodyDescriptionMax)
@@ -333,7 +335,7 @@ export const LlmSkillsNameDuplicateCreateBody = () => zod.object({
new_name: zod
.string()
.max(llmSkillsNameDuplicateCreateBodyNewNameMax)
- .describe('Name for the duplicated skill. Must be unique.'),
+ .describe('Name for the duplicated skill. Must be unique, and cannot be the name of a skill PostHog ships.'),
})
export const llmSkillsNameFilesCreatePathSkillNameRegExp = new RegExp('^[^\/]+$')
@@ -464,6 +466,6 @@ export const LlmSkillsNameRenameCreateBody = () => zod.object({
.string()
.max(llmSkillsNameRenameCreateBodyNewNameMax)
.describe(
- "New name for the skill. Must be unique in the project, and must not start with 'signals-scout-' or 'review-hog-'."
+ "New name for the skill. Must be unique in the project, cannot be the name of a skill PostHog ships, and must not start with 'signals-scout-' or 'review-hog-'."
),
})
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-skill-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-skill-create.json
index 9a904a5da830..fc256bbe3e7b 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-skill-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-skill-create.json
@@ -62,7 +62,7 @@
"type": "object"
},
"name": {
- "description": "Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters.",
+ "description": "Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters. Cannot be the name of a skill PostHog ships.",
"maxLength": 64,
"type": "string"
},
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-skill-duplicate.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-skill-duplicate.json
index 81e8ba5a9f07..1f4c9f6ff963 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-skill-duplicate.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/llma-skill-duplicate.json
@@ -2,7 +2,7 @@
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"new_name": {
- "description": "Name for the duplicated skill. Must be unique.",
+ "description": "Name for the duplicated skill. Must be unique, and cannot be the name of a skill PostHog ships.",
"maxLength": 64,
"type": "string"
},
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/skill-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/skill-create.json
index 9a904a5da830..fc256bbe3e7b 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/skill-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/skill-create.json
@@ -62,7 +62,7 @@
"type": "object"
},
"name": {
- "description": "Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters.",
+ "description": "Unique skill name. Lowercase letters, numbers, and hyphens only. Max 64 characters. Cannot be the name of a skill PostHog ships.",
"maxLength": 64,
"type": "string"
},
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/skill-duplicate.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/skill-duplicate.json
index 81e8ba5a9f07..1f4c9f6ff963 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/skill-duplicate.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/skill-duplicate.json
@@ -2,7 +2,7 @@
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"new_name": {
- "description": "Name for the duplicated skill. Must be unique.",
+ "description": "Name for the duplicated skill. Must be unique, and cannot be the name of a skill PostHog ships.",
"maxLength": 64,
"type": "string"
},
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/skill-rename.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/skill-rename.json
index 5c573e7467a2..1e27a0cb036b 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/skill-rename.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/skill-rename.json
@@ -2,7 +2,7 @@
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"new_name": {
- "description": "New name for the skill. Must be unique in the project, and must not start with 'signals-scout-' or 'review-hog-'.",
+ "description": "New name for the skill. Must be unique in the project, cannot be the name of a skill PostHog ships, and must not start with 'signals-scout-' or 'review-hog-'.",
"maxLength": 64,
"type": "string"
},
diff --git a/tach.toml b/tach.toml
index 5c5ca5353d85..82fc2f9cae3c 100644
--- a/tach.toml
+++ b/tach.toml
@@ -694,6 +694,10 @@ depends_on = [
"products.event_definitions",
"products.ai_observability",
"products.logs",
+ # The skill build reads the bundled-skill names the skills store validates against, so the
+ # two sides share one definition. The skills product has no facade, so this matches how
+ # review_hog, signals and tasks reach it.
+ "products.skills",
"products.tasks",
]
layer = "modules"