You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## TLDR
Adds a file enrichment feature that annotates PostHog-related code with live metadata (event volume, flag rollout/staleness, experiment links) as the agent reads files.
Closes#1097
## Problem
When the agent reads source files containing PostHog SDK calls, it has no awareness of the current state of those flags or events in production. This means the agent lacks important product context — such as whether a flag is rolled out, how much volume an event has, or whether an event is verified — that would help it make better recommendations.
## Changes
- Introduces a new `@posthog/enricher` package dependency in the agent, with a `FileEnrichmentDeps`/`Enrichment` abstraction in `packages/agent/src/enrichment/file-enricher.ts` that wraps `PostHogEnricher` and exposes an `enrichFileForAgent` function
- For the Claude adapter, a `PostToolUse` hook (`createReadEnrichmentHook`) intercepts `Read` tool responses, strips line numbers, runs enrichment, and returns `additionalContext` to the model alongside writing enriched content to an `EnrichedReadCache` keyed by `tool_use_id`; the cache is consumed in `toolUpdateFromToolResult` so the UI displays the annotated version
- For the Codex adapter, enrichment is applied directly inside `readTextFile` on the `CodexClient`, replacing the file content before it reaches codex-acp
- Adds a `toInlineComments()` method on `EnrichedResult` that appends PostHog annotations as inline comments on the same source line (rather than inserting new lines above), and a corresponding `formatInlineComments` function in the comment formatter
- API errors (401, 500, network failures, malformed JSON) in `enrichFromApi` are now tolerated via `Promise.allSettled` rather than rejecting, returning partial/empty enrichment instead
- Fixes a HogQL query bug where typed placeholders (`{name:Type}`) and `INTERVAL` with a placeholder were rejected; `daysBack` is now inlined directly into the query string
- Enrichment is enabled by default when `posthog` config is present and can be disabled via `enricher: { enabled: false }` in `AgentConfig`
- Grammar file resolution in `ParserManager` now checks multiple candidate paths to support packaged Electron app layouts; the `forge.config.ts` asar unpack glob and a new `copyEnricherGrammars` Vite plugin ensure grammars are available at both dev and packaged runtime paths
- CI build and test workflows include a build step for `@posthog/enricher`
- Adds unit tests for `enrichFileForAgent`, `createReadEnrichmentHook`, and `createCodexClient.readTextFile`
0 commit comments