Skip to content

feat(warehouse-source): pass ORM signals for catalog hints - #1631

Open
sinan-ku wants to merge 11 commits into
mainfrom
feat/warehouse-catalog-hints
Open

sinan-ku wants to merge 11 commits into
mainfrom
feat/warehouse-catalog-hints

Conversation

@sinan-ku

@sinan-ku sinan-ku commented Nov 30, 2026 •

Copy link
Copy Markdown

Problem

When a user connects their app's database with wizard warehouse, PostHog's AI enrichment sees only column names and types. The meaning of a column stays in the ORM models, which the setup agent can read but does not use.

Changes

  • Detection finds the ORMs and SQL schema files in the project. It covers Django, Rails, Prisma, SQLAlchemy, TypeORM, Drizzle, Sequelize and .sql files. It skips tests, fixtures, and migration SQL.
  • A .sql file counts only when it defines tables and holds no rows, so the prompt never names a database dump.
  • The prompt ends with a ## Catalog hints section with one line for each ORM. Only SQL lines name a file, because agents that saw the detected model files read only those files.
  • A program can grant its pi subagents PostHog MCP tools with subagentPosthogTools. A granted subagent gets call_posthog_tool, which calls only those tools. wizard warehouse grants external-data-sources-catalog-hints-create and data-catalog-join-candidates-create (feat(data-catalog): store join candidates from the setup agent posthog#146020), so each subagent sends the descriptions it wrote and the joins it found.
  • The child session's tool list now names the granted tools, because pi activates only named tools.
  • The step is optional. After Continue, the intro asks "Describe your tables from your code?" and says what AI reads, what PostHog saves and which permissions it needs.
  • Only a yes adds warehouse_table:write and data_catalog:write to the login, the subagents' tools, and the step in the prompt. The default integration flow asks for neither scope.
  • The question shows only with the new wizard-warehouse-catalog-hints flag on, and only when the project has ORM models and an app database. The flag is read before login, so it can target a percentage or a version, not a person.
  • A run that cannot ask, such as --ci, skips the step.
  • Without a yes, the new deniedPosthogTools setting blocks both catalog tools for the parent agent too. A personal API key can already hold the scopes.
  • The security gate checks call_posthog_tool against the program's tool lists and scans its text for secrets. A cancelled run stops its subagents and their calls.
  • The warehouse intro shows Continue only when detection is done.

Note

The same pi rule means the subagent's scrubbed bash was never active. This PR leaves that unchanged.

The tool and its flag come from PostHog/posthog#144563 and PostHog/posthog#144739. The skill side is PostHog/context-mill#577.

Test plan

  • New tests: the tool refuses an ungranted tool before it connects, and a grant reaches the child and the parent's description.
  • A local run against a local PostHog and the posthog repo's Django models: 5 subagents sent 310 descriptions for all 41 synced tables. A sample of 30 had correct facts. The hints no longer carry a file, line or commit, so the Wizard no longer reads git.
  • Local runs on two open source apps (Rails and Prisma), with the question answered yes, sent 223 and 109 descriptions, and 5 and 6 correct joins.
  • New tests cover each block above. Each guard was broken once to confirm that a test fails.
  • Not checked: a consent screen that shows the new scopes.

🤖 Generated with Claude Code

The warehouse command now finds the ORM and SQL files in the project
and reads the commit at HEAD. The prompt gives both to the
data-warehouse-source-setup skill in a "Catalog hints" section. The
agent then reads the models and sends table and column descriptions
through external-data-sources-catalog-hints-create.

The warehouse scope set adds warehouse_table:write, because the tool
needs it. The default integration flow shares this set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci ai-observability
  • /wizard-ci basic-integration
  • /wizard-ci feature-flags
  • /wizard-ci mcp-analytics
  • /wizard-ci replay-vision
  • /wizard-ci revenue
  • /wizard-ci self-driving
  • /wizard-ci warehouse
  • /wizard-ci warehouse-seeded

Test an individual app:

  • /wizard-ci ai-observability/anthropic
  • /wizard-ci ai-observability/google-adk
  • /wizard-ci ai-observability/groq
Show more apps
  • /wizard-ci ai-observability/manual-capture
  • /wizard-ci ai-observability/openai
  • /wizard-ci ai-observability/openai-agents
  • /wizard-ci ai-observability/opentelemetry
  • /wizard-ci ai-observability/vercel-ai
  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/flutter
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci feature-flags/django
  • /wizard-ci feature-flags/next-js
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/go-sdk
  • /wizard-ci mcp-analytics/python-sdk
  • /wizard-ci mcp-analytics/ruby-sdk
  • /wizard-ci mcp-analytics/rust-sdk
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci replay-vision/javascript-node
  • /wizard-ci replay-vision/next-js
  • /wizard-ci replay-vision/react-vite
  • /wizard-ci revenue/stripe
  • /wizard-ci self-driving/astro
  • /wizard-ci self-driving/fastapi
  • /wizard-ci self-driving/nuxt
  • /wizard-ci self-driving/react-router
  • /wizard-ci self-driving/sveltekit
  • /wizard-ci warehouse/monorepo-env
  • /wizard-ci warehouse/multi-source-next
  • /wizard-ci warehouse/stripe-node
  • /wizard-ci warehouse/zero-source
  • /wizard-ci warehouse-seeded/next-stripe
  • /wizard-ci warehouse-seeded/next-stripe-declined

Test against a Context Mill branch:

  • /wizard-ci all context-mill:my-branch

Add context-mill:<branch> to any command above to pin the Context Mill branch. It defaults to main.

Results will be posted here when complete.

sinan-ku and others added 8 commits December 1, 2026 00:28
A run on a large Django repo listed `models.py` files that hold no ORM
models, and numbered migration SQL, so the agent described the wrong
tables. A Django models file now counts only when its app folder has a
`migrations/` folder. SQL files in a `migrations/` folder or with a
numbered name no longer count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A program can grant its pi subagents PostHog MCP tools with `subagentPosthogTools`. A granted subagent gets `call_posthog_tool`, which calls only those tools.
- The warehouse program grants `external-data-sources-catalog-hints-create`. When the main agent had to copy the subagents' results into its own call, it sent 5 to 41 of about 300 descriptions.
- `dispatch_agent` names the granted tools, and the child's tool list includes them. pi activates only the tools that the list names.
- The `## Catalog hints` section lists each ORM once, without its files. Agents that saw the detected model files read only those files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ints

The PostHog catalog hints tool no longer takes source citations, so the
Wizard does not read the HEAD commit or compute a repository path prefix.
The catalog hints prompt section now lists only the ORM and SQL signals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Subagents may also call `data-catalog-join-candidates-create`, so they send the joins that the code states.
- `wizard warehouse` asks for `data_catalog:write`, which that tool needs. The default integration flow does not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The intro now asks before login, and only a yes adds the two write scopes, the subagents' PostHog tools, and the step in the prompt. A run that cannot ask, such as --ci, skips the step. The question shows only with the wizard-warehouse-catalog-hints flag on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Detection decides whether to ask about the tables, and it needs a flag request. A fast Continue started the run without the question.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sinan-ku
sinan-ku marked this pull request as ready for review December 3, 2026 13:48
@sinan-ku
sinan-ku requested review from a team as code owners December 3, 2026 13:49
@veria-ai

veria-ai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Fixed/addressed: 2 · PR risk: 0/10

Reviews

@posthog-security-review-bot posthog-security-review-bot Bot added the security-review Request a security review label Dec 3, 2026
@posthog-security-review-bot

posthog-security-review-bot Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

✅ Security review complete — b6a203ec2e90

5 findings posted as a review, in 7 min.

Add the security-review label to run again on the latest commit.

@posthog-security-review-bot posthog-security-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent-driven security review - findings inline.

Comment thread src/programs/warehouse-source/index.ts Resolved
Comment thread e2e-harness/action-registry.ts Resolved
@posthog-security-review-bot posthog-security-review-bot Bot removed the security-review Request a security review label Dec 3, 2026
- Block the two catalog tools for the parent agent when the user did not choose the step.
- Check subagent PostHog calls against the program's tool lists, and scan their text before it leaves.
- Stop a subagent and its PostHog call when the run is cancelled.
- Name a SQL file to the agent only when it defines tables and holds no rows.
- Give the e2e driver a separate action that says yes to the question.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019N3KXzMusrHH4bReAdKTw7
Comment thread src/agent/posthog-tool-policy.ts Resolved
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.

1 participant