Skip to content

feat(code): port posthog detection logic to new pkg#1562

Open
adboio wants to merge 2 commits intomainfrom
04-08-feat_code_port_posthog_detection_logic_to_new_pkg
Open

feat(code): port posthog detection logic to new pkg#1562
adboio wants to merge 2 commits intomainfrom
04-08-feat_code_port_posthog_detection_logic_to_new_pkg

Conversation

@adboio
Copy link
Copy Markdown
Contributor

@adboio adboio commented Apr 8, 2026

Problem

This adds a new @posthog/enricher package that provides PostHog SDK usage detection and enrichment capabilities for source code analysis. The package can detect PostHog method calls, feature flag usage, variant branches, and initialization calls across multiple programming languages (JavaScript, TypeScript, Python, Go, Ruby) using tree-sitter parsers.

Changes

  • New enricher package: Created packages/enricher/ with TypeScript source code for detecting PostHog SDK usage patterns
  • Tree-sitter integration: Added WASM grammar files for JavaScript, TypeScript, Python, Go, and Ruby parsing
  • Detection capabilities:
    • PostHog method calls (capture, getFeatureFlag, isFeatureEnabled, etc.)
    • Feature flag assignments and variant branches (if/else chains, switch statements)
    • PostHog initialization calls (posthog.init, new PostHog constructors)
    • Function definitions and client aliases
  • Flag classification: Added utilities for classifying flags as boolean, multivariate, or remote config
  • Stale flag detection: Added logic to identify potentially stale feature flags
  • Multi-language support: Language-specific queries and method mappings for different PostHog SDKs
  • Build tooling: Added tsup configuration, TypeScript setup, and Vitest for testing
  • Grammar fetching: Added script to build tree-sitter WASM files from grammar packages
  • Development integration: Added enricher to mprocs.yaml for local development

Copy link
Copy Markdown
Contributor Author

adboio commented Apr 8, 2026

@adboio adboio force-pushed the 04-08-feat_code_port_posthog_detection_logic_to_new_pkg branch from 38db67a to 2ea3446 Compare April 8, 2026 18:35
@k11kirky k11kirky marked this pull request as ready for review April 9, 2026 12:22
@k11kirky k11kirky force-pushed the 04-08-feat_code_port_posthog_detection_logic_to_new_pkg branch from bbf4b18 to f213e16 Compare April 9, 2026 12:34
@k11kirky k11kirky mentioned this pull request Apr 9, 2026
Copy link
Copy Markdown
Contributor Author

adboio commented Apr 9, 2026

i'm not allowed to review this cuz github still considers me the author lol

but i see there are a lot of changes, just checking this could still be used in the vscode extension to replace the existing tree sitter service?

Copy link
Copy Markdown
Contributor Author

adboio commented Apr 9, 2026

also looping in @fercgomes , any concerns w/ updating vscode ext to grab the pkg from here?

@adboio adboio requested a review from fercgomes April 9, 2026 15:10
@fercgomes
Copy link
Copy Markdown

also looping in @fercgomes , any concerns w/ updating vscode ext to grab the pkg from here?

Just so I understand the context: is this the actual logic from the extension, or is it a parallel implementation with the same goals?

@adboio
Copy link
Copy Markdown
Contributor Author

adboio commented Apr 9, 2026

@fercgomes the goal is for posthog code to have the same sort of event/flag/etc detection that the vscode extension has. we want to use it in a few places -- injecting into agent context, showing in diff reviews, etc

this base PR is, i think, a pretty direct copy of the logic from the extension (though it is 100% vibe-ported)

@k11kirky has made some changes upstack but i think it's still the same logic, peter can you confirm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants