webstatus-search-grammar
This skill provides instructions for modifying the feature search syntax in webstatus.dev, which is built on ANTLR v4.
Architecture
For a technical breakdown of the ANTLR grammar, search node transformation, and the FeaturesSearchVisitor implementation, see references/architecture.md.
Source of Truth
- The canonical source of truth for the search syntax is
antlr/FeatureSearch.g4. - DON'T edit the generated parser files in
lib/gen/featuresearch/parser/directly.
General Guidelines
- DO cross-reference all Go and test code against the official Google Go Style Guide. If you are unsure about a specific style rule, DO NOT assume; you MUST ask the user for clarification.
How to Add a New Search Term (e.g., is:discouraged)
- Update Grammar (
antlr/FeatureSearch.g4):- Add the new term to the
search_criteriarule in the grammar file (e.g., add| discouraged_term). - Define the new rule:
discouraged_term: 'is' ':' 'discouraged';.
- Add the new term to the
- Regenerate Parser:
- Run
make antlr-gen. This will update the files inlib/gen/featuresearch/parser/. Note: If you do not have thedevcontaineropen or do not have the right Java dependency versions, ask the user to run this step for you.
- Run
- Update Visitor (
lib/gcpspanner/searchtypes/):- Add a new
SearchIdentifierfor your term insearchtypes.go(e.g.,IdentifierIsDiscouraged). - In FeaturesSearchVisitor.go, implement the
VisitDiscouraged_termContextmethod. This visitor is the source-of-truth for how grammar terms are translated into Spanner SQL.
- Add a new
- Update Query Builder (
lib/gcpspanner/feature_search_query.go):- In
FeatureSearchFilterBuilder.traverseAndGenerateFilters, add acasefor your newSearchIdentifier. - This case should generate the appropriate Spanner SQL
WHEREclause for the filter.
- In
- Add Tests:
- Add a parsing test in
lib/gcpspanner/searchtypes/features_search_parse_test.go. - Add a SQL generation test in
lib/gcpspanner/feature_search_query_test.go. - Add an integration test in
lib/gcpspanner/feature_search_test.go.
- Add a parsing test in
- Update Frontend UI:
- Add the new search term to the search builder UI vocabulary in
frontend/src/static/js/utils/constants.tsto make it discoverable to users.
- Add the new search term to the search builder UI vocabulary in
Documentation Updates
When you add a new search grammar term or modify parsing:
- Trigger the "Updating the Knowledge Base" prompt in
GEMINI.mdto ensure I am aware of the changes. - Ensure that
docs/ARCHITECTURE.mdis updated if there are broader system impacts.
Error Handling & Query Validation
- Query Execution Errors: When translating search logic into Spanner SQL or exploring
saved:references viaexpandSavedSearches, unexpected edge cases (e.g.backendtypes.ErrSavedSearchNotFound, or cyclic references) MUST NOT crash the request and MUST NOT return500 Internal Server Error. - 400 Bad Request Mapping: Endpoint handlers (e.g.,
get_features.go,create_saved_search.go) MUST explicitly catch these semantic validation errors and map them to HTTP400 Bad RequestJSON responses. The frontend relies on these 400s to render in-app warning banners for invalid subsets of an otherwise valid query string. - Reference Validation: Always ensure that
ValidateQueryReferences(or equivalent dry-run query validators) intercepts invalid cycles or missing queries before a database mutation is committed.