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.

chore: move query_performance_ai from products/ to tools/ (#60692)

Julian Bezd0b567724bdf
diff --git a/.agents/skills/optimizing-clickhouse-and-hogql-queries/SKILL.md b/.agents/skills/optimizing-clickhouse-and-hogql-queries/SKILL.md
index a1e7be316467..48eaa794ad42 100644
--- a/.agents/skills/optimizing-clickhouse-and-hogql-queries/SKILL.md
+++ b/.agents/skills/optimizing-clickhouse-and-hogql-queries/SKILL.md
@@ -172,12 +172,12 @@ The Test Cluster is read-only, so you cannot try schema changes there. For those
### Query performance autoresearch (the powertool)
-For hard cases, [`products/query_performance_ai/`](../../../products/query_performance_ai/) wraps [pi-autoresearch](https://github.com/davebcn87/pi-autoresearch) in a coordinator that hands the LLM a query and asks it to optimize against the Test Cluster in a loop. Setup is non-trivial (Docker sandbox per query, ANTHROPIC_API_KEY, Metabase database IDs), so ask the user to run the setup themselves:
+For hard cases, [`tools/query-performance-ai/query_performance_ai/`](../../../tools/query-performance-ai/query_performance_ai/) wraps [pi-autoresearch](https://github.com/davebcn87/pi-autoresearch) in a coordinator that hands the LLM a query and asks it to optimize against the Test Cluster in a loop. Setup is non-trivial (Docker sandbox per query, ANTHROPIC_API_KEY, Metabase database IDs), so ask the user to run the setup themselves:
-- Coordinator and setup: [`products/query_performance_ai/README.md`](../../../products/query_performance_ai/README.md)
-- Coordinator entry point: [`products/query_performance_ai/orchestrator/coordinator.py`](../../../products/query_performance_ai/orchestrator/coordinator.py)
-- The campaign skill the sandboxed agent runs: [`products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/SKILL.md`](../../../products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/SKILL.md)
-- Orchestration contract: [`products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/orchestration.md`](../../../products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/orchestration.md)
+- Coordinator and setup: [`tools/query-performance-ai/README.md`](../../../tools/query-performance-ai/README.md)
+- Coordinator entry point: [`tools/query-performance-ai/query_performance_ai/orchestrator/coordinator.py`](../../../tools/query-performance-ai/query_performance_ai/orchestrator/coordinator.py)
+- The campaign skill the sandboxed agent runs: [`tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/SKILL.md`](../../../tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/SKILL.md)
+- Orchestration contract: [`tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/orchestration.md`](../../../tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/orchestration.md)
I am not entirely sure of the exact commands needed beyond the snippets in the README. Ask the user; the setup also takes effort on their side.
diff --git a/.github/CODEOWNERS-soft b/.github/CODEOWNERS-soft
index e13e83643e44..004651177722 100644
--- a/.github/CODEOWNERS-soft
+++ b/.github/CODEOWNERS-soft
@@ -195,6 +195,7 @@ AGENTS.md @PostHog/team-devex
.claude/skills/ingestion-*/ @PostHog/team-ingestion
tools/pr-approval-agent/ @PostHog/team-devex
tools/phrocs/ @PostHog/team-devex
+tools/query-performance-ai/ @PostHog/team-analytics-platform
greptile.json @PostHog/team-devex
docs/published/developing-locally.md @PostHog/team-devex
diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml
index 718cdf00e659..90c8ab0c6c7c 100644
--- a/.github/workflows/ci-backend.yml
+++ b/.github/workflows/ci-backend.yml
@@ -649,8 +649,11 @@ jobs:
# CHANGED_FILES is space-separated (dorny list-files: escape).
# Each entry is products/<name>/product.yaml — strip to <name>.
names=$(echo "$CHANGED_FILES" | tr ' ' '\n' | sed -n 's|^products/\([^/]*\)/product.yaml$|\1|p' | xargs)
+ # Drop products whose product.yaml was deleted in this PR (e.g. the
+ # product moved out of products/) — there are no owners left to validate.
+ names=$(for n in $names; do [ -f "products/$n/product.yaml" ] && printf '%s ' "$n"; done | xargs)
if [ -z "$names" ]; then
- echo "No product.yaml files in diff after filtering"
+ echo "No existing product.yaml files in diff after filtering"
exit 0
fi
./bin/hogli product:lint:owners $names
diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.yml
index bbfa22527280..ee18ba3f737b 100644
--- a/.github/workflows/ci-python.yml
+++ b/.github/workflows/ci-python.yml
@@ -69,6 +69,8 @@ jobs:
- '.github/scripts/**/*.py'
# PR approval agent
- 'tools/pr-approval-agent/**'
+ # query-performance-ai dev tool
+ - 'tools/query-performance-ai/**'
code-quality:
needs: changes
@@ -187,6 +189,11 @@ jobs:
run: |
pytest tools/hogli-commands/hogli_commands/tests -v --junitxml=junit-hogli-commands.xml
+ - name: Run query-performance-ai tests
+ shell: bash
+ run: |
+ pytest tools/query-performance-ai/query_performance_ai -v --junitxml=junit-query-performance-ai.xml
+
- name: Upload test results
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
if: always()
@@ -195,6 +202,7 @@ jobs:
path: |
junit-hogli.xml
junit-hogli-commands.xml
+ junit-query-performance-ai.xml
- name: Run dependency detection script tests
shell: bash
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 1a5dd9876a26..8a91697a0e70 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -3213,8 +3213,6 @@ importers:
products/product_tours: {}
- products/query_performance_ai: {}
-
products/replay:
dependencies:
'@posthog/icons':
diff --git a/posthog/settings/web.py b/posthog/settings/web.py
index f11d6b4cf29a..ad0c0b975909 100644
--- a/posthog/settings/web.py
+++ b/posthog/settings/web.py
@@ -72,7 +72,6 @@ PRODUCTS_APPS = [
"products.platform_features.backend.apps.PlatformFeaturesConfig",
"products.streamlit_apps.backend.apps.StreamlitAppsConfig",
"products.legal_documents.backend.apps.LegalDocumentsConfig",
- "products.query_performance_ai.orchestrator.apps.QueryPerformanceAiConfig",
"products.access_control.backend.apps.AccessControlConfig",
"products.warehouse_sources_queue.backend.apps.WarehouseSourcesQueueConfig",
"products.business_knowledge.backend.apps.BusinessKnowledgeConfig",
diff --git a/products/query_performance_ai/orchestrator/apps.py b/products/query_performance_ai/orchestrator/apps.py
deleted file mode 100644
index 7e333dc8225f..000000000000
--- a/products/query_performance_ai/orchestrator/apps.py
+++ /dev/null
@@ -1,7 +0,0 @@
-from django.apps import AppConfig
-
-
-class QueryPerformanceAiConfig(AppConfig):
- default_auto_field = "django.db.models.BigAutoField"
- name = "products.query_performance_ai.orchestrator"
- label = "query_performance_ai"
diff --git a/products/query_performance_ai/package.json b/products/query_performance_ai/package.json
deleted file mode 100644
index 36cec2ae25cd..000000000000
--- a/products/query_performance_ai/package.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "name": "@posthog/products-query-performance-ai",
- "scripts": {
- "backend:test": "pytest -c ../../pytest.ini --rootdir ../.. orchestrator sandboxed_autoresearch_agent -v --tb=short"
- }
-}
diff --git a/products/query_performance_ai/product.yaml b/products/query_performance_ai/product.yaml
deleted file mode 100644
index 77968835ef25..000000000000
--- a/products/query_performance_ai/product.yaml
+++ /dev/null
@@ -1,3 +0,0 @@
-name: Query performance AI
-owners:
- - team-analytics-platform
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/adapter.json.example b/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/adapter.json.example
deleted file mode 100644
index a83704384672..000000000000
--- a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/adapter.json.example
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "_comment": "Coordinator transport. The only supported `type` is 'coordinator' (see products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/transports.py). `url` is the coordinator's HTTP server (host.docker.internal from inside a Docker sandbox); `token` is the random per-run token the coordinator prints to its stdout at startup.",
- "type": "coordinator",
- "url": "http://host.docker.internal:8765",
- "token": "<coordinator token>"
-}
diff --git a/products/ruff.toml b/products/ruff.toml
index 6f7d8c9806a9..839160d6466f 100644
--- a/products/ruff.toml
+++ b/products/ruff.toml
@@ -86,7 +86,6 @@ extend-select = ["ANN001", "ANN201", "ANN202", "ANN204"]
"posthog_ai/**" = ["PLC0415"]
"product_analytics/**" = ["PLC0415"]
"product_tours/**" = ["PLC0415"]
-"query_performance_ai/**" = ["PLC0415"]
"replay_vision/**" = ["PLC0415"]
"revenue_analytics/**" = ["PLC0415"]
"signals/**" = ["PLC0415"]
diff --git a/pytest.ini b/pytest.ini
index 9b1442b4ada2..0b768928905d 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -1,11 +1,11 @@
[pytest]
-pythonpath = . common tools/hogli-commands
+pythonpath = . common tools/hogli-commands tools/query-performance-ai
env =
DEBUG=1
TEST=1
DJANGO_SETTINGS_MODULE = posthog.settings
# --pytest-durations=0 disables the pytest-durations plugin by default; CI shard steps re-enable it explicitly
-addopts = -p no:warnings --reuse-db --pytest-durations=0 --ignore=posthog/user_scripts --ignore=services/llm-gateway --ignore=services/stripe-mock --ignore=common/ingestion/acceptance_tests --ignore=tools/hogli --ignore=tools/hogli-commands --ignore=tools/traffic-sim
+addopts = -p no:warnings --reuse-db --pytest-durations=0 --ignore=posthog/user_scripts --ignore=services/llm-gateway --ignore=services/stripe-mock --ignore=common/ingestion/acceptance_tests --ignore=tools/hogli --ignore=tools/hogli-commands --ignore=tools/traffic-sim --ignore=tools/query-performance-ai
markers =
ee
diff --git a/tach.toml b/tach.toml
index c5ad36fb7a18..1de43b1ba1be 100644
--- a/tach.toml
+++ b/tach.toml
@@ -461,12 +461,6 @@ depends_on = [
]
layer = "modules"
-[[modules]]
-path = "products.query_performance_ai"
-depends_on = ["products.tasks",
-]
-layer = "modules"
-
[[modules]]
path = "products.replay"
depends_on = [
diff --git a/products/query_performance_ai/README.md b/tools/query-performance-ai/README.md
similarity index 79%
rename from products/query_performance_ai/README.md
rename to tools/query-performance-ai/README.md
index 82755e76212d..21d506991acc 100644
--- a/products/query_performance_ai/README.md
+++ b/tools/query-performance-ai/README.md
@@ -10,6 +10,8 @@ The agent is [pi-coding-agent](https://pi.dev) running the [pi-autoresearch](htt
- A docker daemon (Orbstack etc).
- `ANTHROPIC_API_KEY` in your `.env`.
+The `python -m query_performance_ai.…` commands below need this bundle on `PYTHONPATH` (the inner `query_performance_ai` package imports `products.tasks` from the repo root, so both must be importable). Run from the repo root with `PYTHONPATH=.:tools/query-performance-ai`, or `cd tools/query-performance-ai` with the repo root on the path.
+
## What happens when you run it
1. Fetch slow queries from Metabase's prod `system.query_log` (filtered hard to `ai_data_processing_approved = true` — we only ever feed the agent queries that the customer explicitly approved for AI analysis).
@@ -22,14 +24,14 @@ The agent is [pi-coding-agent](https://pi.dev) running the [pi-autoresearch](htt
```bash
# Replay candidates against a Metabase-fronted test cluster:
-python -m products.query_performance_ai.orchestrator.coordinator \
+python -m query_performance_ai.orchestrator.coordinator \
--target test_cluster --metabase-region us \
--query-log-database-id 142 --test-cluster-database-id 146 \
--team-id 2 --max-queries 5
# Requires `hogli metabase:login --region us` first.
# Replay candidates against your local dev ClickHouse:
-python -m products.query_performance_ai.orchestrator.coordinator --target local
+python -m query_performance_ai.orchestrator.coordinator --target local
```
`--target` decides where candidate SQL runs. Slow queries are always sourced from Metabase regardless; only the execution destination differs.
@@ -37,7 +39,7 @@ python -m products.query_performance_ai.orchestrator.coordinator --target local
## Smoke test
```bash
-python -m products.query_performance_ai.orchestrator.coordinator --target local --test-query
+python -m query_performance_ai.orchestrator.coordinator --target local --test-query
```
`--test-query` skips Metabase and feeds `SELECT 1, sleep(1)` as the campaign SQL. End-to-end smoke — the agent should drop the `sleep` within a couple of iterations.
diff --git a/products/query_performance_ai/__init__.py b/tools/query-performance-ai/query_performance_ai/__init__.py
similarity index 100%
rename from products/query_performance_ai/__init__.py
rename to tools/query-performance-ai/query_performance_ai/__init__.py
diff --git a/products/query_performance_ai/data/.gitignore b/tools/query-performance-ai/query_performance_ai/data/.gitignore
similarity index 100%
rename from products/query_performance_ai/data/.gitignore
rename to tools/query-performance-ai/query_performance_ai/data/.gitignore
diff --git a/products/query_performance_ai/orchestrator/__init__.py b/tools/query-performance-ai/query_performance_ai/orchestrator/__init__.py
similarity index 100%
rename from products/query_performance_ai/orchestrator/__init__.py
rename to tools/query-performance-ai/query_performance_ai/orchestrator/__init__.py
diff --git a/products/query_performance_ai/orchestrator/backends/_query_log.py b/tools/query-performance-ai/query_performance_ai/orchestrator/backends/_query_log.py
similarity index 100%
rename from products/query_performance_ai/orchestrator/backends/_query_log.py
rename to tools/query-performance-ai/query_performance_ai/orchestrator/backends/_query_log.py
diff --git a/products/query_performance_ai/orchestrator/backends/base.py b/tools/query-performance-ai/query_performance_ai/orchestrator/backends/base.py
similarity index 100%
rename from products/query_performance_ai/orchestrator/backends/base.py
rename to tools/query-performance-ai/query_performance_ai/orchestrator/backends/base.py
diff --git a/products/query_performance_ai/orchestrator/backends/local.py b/tools/query-performance-ai/query_performance_ai/orchestrator/backends/local.py
similarity index 100%
rename from products/query_performance_ai/orchestrator/backends/local.py
rename to tools/query-performance-ai/query_performance_ai/orchestrator/backends/local.py
diff --git a/products/query_performance_ai/orchestrator/backends/metabase.py b/tools/query-performance-ai/query_performance_ai/orchestrator/backends/metabase.py
similarity index 100%
rename from products/query_performance_ai/orchestrator/backends/metabase.py
rename to tools/query-performance-ai/query_performance_ai/orchestrator/backends/metabase.py
diff --git a/products/query_performance_ai/orchestrator/backends/tests/test_backends.py b/tools/query-performance-ai/query_performance_ai/orchestrator/backends/tests/test_backends.py
similarity index 97%
rename from products/query_performance_ai/orchestrator/backends/tests/test_backends.py
rename to tools/query-performance-ai/query_performance_ai/orchestrator/backends/tests/test_backends.py
index bedf38460dd1..85e57fea134f 100644
--- a/products/query_performance_ai/orchestrator/backends/tests/test_backends.py
+++ b/tools/query-performance-ai/query_performance_ai/orchestrator/backends/tests/test_backends.py
@@ -7,10 +7,10 @@ from typing import Any
import pytest
from unittest import mock
-from products.query_performance_ai.orchestrator.backends import _query_log
-from products.query_performance_ai.orchestrator.backends.base import BackendError
-from products.query_performance_ai.orchestrator.backends.local import LocalClickhouseBackend
-from products.query_performance_ai.orchestrator.backends.metabase import MetabaseBackend, _tag_with_log_comment
+from query_performance_ai.orchestrator.backends import _query_log
+from query_performance_ai.orchestrator.backends.base import BackendError
+from query_performance_ai.orchestrator.backends.local import LocalClickhouseBackend
+from query_performance_ai.orchestrator.backends.metabase import MetabaseBackend, _tag_with_log_comment
def _completed(stdout: str = "", stderr: str = "", returncode: int = 0) -> Any:
diff --git a/products/query_performance_ai/orchestrator/coordinator.py b/tools/query-performance-ai/query_performance_ai/orchestrator/coordinator.py
similarity index 98%
rename from products/query_performance_ai/orchestrator/coordinator.py
rename to tools/query-performance-ai/query_performance_ai/orchestrator/coordinator.py
index 6c29f1a52b3b..8c9c643c27c7 100644
--- a/products/query_performance_ai/orchestrator/coordinator.py
+++ b/tools/query-performance-ai/query_performance_ai/orchestrator/coordinator.py
@@ -7,7 +7,7 @@ to ``localhost:$PORT`` (best-effort iptables; see run_campaign.py).
Run:
# --query-log-database-id 142 is ClickHouse PROD US - OFFLINE
- python -m products.query_performance_ai.orchestrator.coordinator \\
+ python -m query_performance_ai.orchestrator.coordinator \\
--target test_cluster \\
--metabase-region us \\
--query-log-database-id 142 \\
@@ -16,7 +16,7 @@ Run:
Or just stand the server up for manual experimentation:
- python -m products.query_performance_ai.orchestrator.coordinator --target local --no-spawn
+ python -m query_performance_ai.orchestrator.coordinator --target local --no-spawn
"""
from __future__ import annotations
@@ -212,13 +212,14 @@ def _spawn_one_sandbox(
# Lazy import: SandboxBase pulls in Django settings, structlog, etc.
# Keeping it inside the worker means `--no-spawn` doesn't pay for it.
_ensure_django_setup()
- from products.query_performance_ai.orchestrator.harvest import harvest_artifacts # noqa: PLC0415
from products.tasks.backend.services.sandbox import ( # noqa: PLC0415
SandboxConfig,
SandboxTemplate,
get_sandbox_class_for_backend,
)
+ from query_performance_ai.orchestrator.harvest import harvest_artifacts # noqa: PLC0415
+
sandbox_name = f"qp-autoresearch-{query.query_id[:12]}-{uuid.uuid4().hex[:6]}"
sandbox_env: dict[str, str] = {
"COORDINATOR_URL": coordinator_url,
@@ -311,15 +312,19 @@ def _spawn_one_sandbox(
stderr_tail = (clone_result.stderr or "")[-2000:]
raise RuntimeError(f"git clone failed in sandbox (exit {clone_result.exit_code}):\n{stderr_tail}")
+ # The package lives in the tools/ bundle, not at the repo root, so the
+ # bundle dir has to be on PYTHONPATH for the `-m` lookup to resolve.
+ bundle_dir = f"{repo_path}/tools/query-performance-ai"
command = (
f"cd {shlex.quote(repo_path)} && "
f"trap 'rm -f {shlex.quote(env_file)}' EXIT && "
f"chmod 600 {shlex.quote(env_file)} && "
f"set -a && . {shlex.quote(env_file)} && set +a && "
+ f"export PYTHONPATH={shlex.quote(bundle_dir)}${{PYTHONPATH:+:$PYTHONPATH}} && "
# `-m` (not direct script invocation) so relative imports inside
# the package resolve. `python3 path/to/run_campaign.py` runs the
# file with no parent package, which breaks `from .runtime import …`.
- f"python3 -m products.query_performance_ai.sandboxed_autoresearch_agent.driver.run_campaign 2>&1"
+ f"python3 -m query_performance_ai.sandboxed_autoresearch_agent.driver.run_campaign 2>&1"
)
_log(f"[{query.query_id}] running run_campaign.py inside sandbox {sandbox.id}")
diff --git a/products/query_performance_ai/orchestrator/harvest.py b/tools/query-performance-ai/query_performance_ai/orchestrator/harvest.py
similarity index 100%
rename from products/query_performance_ai/orchestrator/harvest.py
rename to tools/query-performance-ai/query_performance_ai/orchestrator/harvest.py
diff --git a/products/query_performance_ai/orchestrator/server.py b/tools/query-performance-ai/query_performance_ai/orchestrator/server.py
similarity index 100%
rename from products/query_performance_ai/orchestrator/server.py
rename to tools/query-performance-ai/query_performance_ai/orchestrator/server.py
diff --git a/products/query_performance_ai/orchestrator/slow_queries.py b/tools/query-performance-ai/query_performance_ai/orchestrator/slow_queries.py
similarity index 100%
rename from products/query_performance_ai/orchestrator/slow_queries.py
rename to tools/query-performance-ai/query_performance_ai/orchestrator/slow_queries.py
diff --git a/products/query_performance_ai/orchestrator/tests/test_server.py b/tools/query-performance-ai/query_performance_ai/orchestrator/tests/test_server.py
similarity index 95%
rename from products/query_performance_ai/orchestrator/tests/test_server.py
rename to tools/query-performance-ai/query_performance_ai/orchestrator/tests/test_server.py
index 8724f6f79cb1..bd9744b6117b 100644
--- a/products/query_performance_ai/orchestrator/tests/test_server.py
+++ b/tools/query-performance-ai/query_performance_ai/orchestrator/tests/test_server.py
@@ -8,13 +8,8 @@ from typing import Any
import pytest
-from products.query_performance_ai.orchestrator.backends.base import BackendError, ExecutionBackend, ExecutionResult
-from products.query_performance_ai.orchestrator.server import (
- ServerInfo,
- generate_token,
- make_server,
- serve_forever_in_thread,
-)
+from query_performance_ai.orchestrator.backends.base import BackendError, ExecutionBackend, ExecutionResult
+from query_performance_ai.orchestrator.server import ServerInfo, generate_token, make_server, serve_forever_in_thread
class _StubBackend(ExecutionBackend):
diff --git a/products/query_performance_ai/orchestrator/tests/test_slow_queries.py b/tools/query-performance-ai/query_performance_ai/orchestrator/tests/test_slow_queries.py
similarity index 98%
rename from products/query_performance_ai/orchestrator/tests/test_slow_queries.py
rename to tools/query-performance-ai/query_performance_ai/orchestrator/tests/test_slow_queries.py
index 96b7e94c08b7..fc53979ffd89 100644
--- a/products/query_performance_ai/orchestrator/tests/test_slow_queries.py
+++ b/tools/query-performance-ai/query_performance_ai/orchestrator/tests/test_slow_queries.py
@@ -7,7 +7,7 @@ from typing import Any
import pytest
from unittest import mock
-from products.query_performance_ai.orchestrator import slow_queries
+from query_performance_ai.orchestrator import slow_queries
def test_build_sql_substitutes_filters() -> None:
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/driver/run_campaign.py b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/driver/run_campaign.py
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/driver/run_campaign.py
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/driver/run_campaign.py
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/driver/runtime.py b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/driver/runtime.py
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/driver/runtime.py
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/driver/runtime.py
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/driver/sandboxing.py b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/driver/sandboxing.py
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/driver/sandboxing.py
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/driver/sandboxing.py
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/package.json b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/package.json
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/package.json
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/package.json
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/prompts/campaign-review.md b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/prompts/campaign-review.md
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/prompts/campaign-review.md
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/prompts/campaign-review.md
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/prompts/lane-review.md b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/prompts/lane-review.md
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/prompts/lane-review.md
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/prompts/lane-review.md
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/prompts/next-experiment.md b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/prompts/next-experiment.md
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/prompts/next-experiment.md
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/prompts/next-experiment.md
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/_common.py b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/_common.py
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/_common.py
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/_common.py
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_campaign_init.py b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_campaign_init.py
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_campaign_init.py
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_campaign_init.py
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_capture_baseline.py b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_capture_baseline.py
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_capture_baseline.py
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_capture_baseline.py
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_compare_results.py b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_compare_results.py
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_compare_results.py
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_compare_results.py
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_run_candidate.py b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_run_candidate.py
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_run_candidate.py
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/ch_run_candidate.py
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/tests/test_transports.py b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/tests/test_transports.py
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/tests/test_transports.py
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/tests/test_transports.py
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/transports.py b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/transports.py
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/transports.py
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/transports.py
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/SKILL.md b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/SKILL.md
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/SKILL.md
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/SKILL.md
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/orchestration.md b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/orchestration.md
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/orchestration.md
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/skills/clickhouse-autoresearch-campaign/orchestration.md
diff --git a/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/adapter.json.example b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/adapter.json.example
new file mode 100644
index 000000000000..b108d0772363
--- /dev/null
+++ b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/adapter.json.example
@@ -0,0 +1,6 @@
+{
+ "_comment": "Coordinator transport. The only supported `type` is 'coordinator' (see tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/transports.py). `url` is the coordinator's HTTP server (host.docker.internal from inside a Docker sandbox); `token` is the random per-run token the coordinator prints to its stdout at startup.",
+ "type": "coordinator",
+ "url": "http://host.docker.internal:8765",
+ "token": "<coordinator token>"
+}
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/autoresearch.md b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/autoresearch.md
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/autoresearch.md
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/autoresearch.md
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/autoresearch.py b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/autoresearch.py
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/autoresearch.py
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/autoresearch.py
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/autoresearch_checks.py b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/autoresearch_checks.py
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/autoresearch_checks.py
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/autoresearch_checks.py
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/baseline/.gitkeep b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/baseline/.gitkeep
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/baseline/.gitkeep
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/baseline/.gitkeep
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/campaign.json.example b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/campaign.json.example
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/campaign.json.example
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/campaign.json.example
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/hypotheses/.gitkeep b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/hypotheses/.gitkeep
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/hypotheses/.gitkeep
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/hypotheses/.gitkeep
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/lanes/.gitkeep b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/lanes/.gitkeep
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/lanes/.gitkeep
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/lanes/.gitkeep
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/query/best.sql b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/query/best.sql
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/query/best.sql
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/query/best.sql
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/query/current.sql b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/query/current.sql
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/query/current.sql
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/query/current.sql
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/query/original.sql b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/query/original.sql
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/query/original.sql
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/query/original.sql
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/reviews/.gitkeep b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/reviews/.gitkeep
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/reviews/.gitkeep
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/reviews/.gitkeep
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/runs/.gitkeep b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/runs/.gitkeep
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/runs/.gitkeep
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/runs/.gitkeep
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/runtime/.gitkeep b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/runtime/.gitkeep
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/runtime/.gitkeep
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/runtime/.gitkeep
diff --git a/products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/state.json b/tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/state.json
similarity index 100%
rename from products/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/state.json
rename to tools/query-performance-ai/query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/state.json
diff --git a/products/query_performance_ai/ruff.toml b/tools/query-performance-ai/ruff.toml
similarity index 56%
rename from products/query_performance_ai/ruff.toml
rename to tools/query-performance-ai/ruff.toml
index c8e267b29c78..7e628d898911 100644
--- a/products/query_performance_ai/ruff.toml
+++ b/tools/query-performance-ai/ruff.toml
@@ -1,15 +1,15 @@
-extend = "../ruff.toml"
+extend = "../../pyproject.toml"
[lint.extend-per-file-ignores]
# Pi plugin and in-sandbox driver scripts use stdout as their orchestration
# protocol (pi-autoresearch's `METRIC name=value` parse format, the campaign
# init's human-readable banner, structured log lines for the host-side
# coordinator) so the no-print lint doesn't apply.
-"sandboxed_autoresearch_agent/pi_plugin/scripts/**" = ["T201"]
-"sandboxed_autoresearch_agent/pi_plugin/templates/workspace/**" = ["T201"]
-"sandboxed_autoresearch_agent/driver/run_campaign.py" = ["T201"]
+"query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/scripts/**" = ["T201"]
+"query_performance_ai/sandboxed_autoresearch_agent/pi_plugin/templates/workspace/**" = ["T201"]
+"query_performance_ai/sandboxed_autoresearch_agent/driver/run_campaign.py" = ["T201"]
# In-sandbox driver: shell-callable scripts where ANN policing isn't worth
# the noise (overrides Python stdlib base-class signatures without re-typing
# every arg).
-"sandboxed_autoresearch_agent/driver/**" = ["ANN"]
+"query_performance_ai/sandboxed_autoresearch_agent/driver/**" = ["ANN"]