AGENTS.md
AGENTS.mdAGENTS.mdroot
Quality
89/100
Scores the file, not the repository.Length
1,180 words
25 headings · 5 code blocksRepository
76k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# AGENTS.md23<!-- version: 2.0.0 -->45This file provides guidance to AI agents when working with code in the Grafana repository.67**Directory-scoped agent files exist for specialized areas — read them when working in those directories:**89- `docs/AGENTS.md` — Documentation style guide (for work under `docs/`)10- `public/app/features/alerting/unified/AGENTS.md` — Alerting squad patterns11- `pkg/storage/unified/AGENTS.md` — Unified storage/search compatibility rules (for work under `pkg/storage/unified/`)12- `public/app/core/journeys/AGENTS.md` — Critical User Journey instrumentation1314## Project Overview1516Grafana is a monitoring and observability platform. Go backend, TypeScript/React frontend, monorepo with Yarn workspaces (frontend) and Go workspaces (backend).1718## Principles1920- Follow existing patterns in the surrounding code21- Write tests for new functionality22- Keep changes focused — avoid over-engineering23- Separate PRs for frontend and backend changes (deployed at different cadences)24- Security: prevent XSS, SQL injection, command injection2526## Comments2728- Only add a comment when it explains **why** something is done or reveals non-obvious logic that a reader must know to safely change the code. If the code is self-explanatory, no comment is needed.29- Never include links (Slack, GitHub, Jira, etc.) in code comments.3031## Human Review Gates3233Before running `git push`, stop and get explicit human approval. When changes are ready, show a summary of changes and wait for instruction. "Open a PR" in a task description is intent, not permission to push without review.3435## Commands3637### Build & Run3839```bash40make run # Backend with hot reload (localhost:3000, admin/admin)41make build-backend # Backend only42yarn start # Frontend dev server (watches for changes)43yarn build # Frontend production build44```4546### Test4748```bash49# Backend50go test -run TestName ./pkg/services/myservice/ # Specific test51make test-go-unit # All unit tests52make test-go-integration # Integration tests5354# Frontend55yarn test path/to/file # Specific file56yarn test -t "pattern" # By name pattern57yarn test -u # Update snapshots5859# E2E60yarn e2e:playwright path/to/test.spec.ts # Specific test61```6263### Lint & Format6465```bash66make lint-go # Go linter67yarn lint # ESLint68yarn lint:fix # ESLint auto-fix69yarn prettier:write # Prettier auto-format70yarn typecheck # TypeScript check71```7273### Code Generation7475```bash76make gen-go # Wire DI (after changing service init)77make gen-cue # CUE schemas (after changing kinds/)78make gen-apps # App SDK apps79make swagger-gen # OpenAPI/Swagger specs80make gen-feature-toggles # Feature flags (pkg/services/featuremgmt/)81make i18n-extract # i18n strings82make update-workspace # Go workspace (after adding modules)83```8485### Dev Environment8687```bash88yarn install --immutable # Install frontend deps89make devenv sources=influxdb # Start backing services90make devenv-down # Stop backing services91make lefthook-install # Pre-commit hooks92```9394## Architecture9596### Backend (`pkg/`)9798| Directory | Purpose |99| ----------------- | ----------------------------------------------------------- |100| `pkg/api/` | HTTP API handlers and routes |101| `pkg/services/` | Business logic by domain (alerting, dashboards, auth, etc.) |102| `pkg/server/` | Server init and Wire DI setup (`wire.go`) |103| `pkg/tsdb/` | Time series database query backends |104| `pkg/plugins/` | Plugin system and loader |105| `pkg/infra/` | Logging, metrics, database access |106| `pkg/middleware/` | HTTP middleware |107| `pkg/setting/` | Configuration management |108109**Patterns**: Wire DI (regenerate with `make gen-go`), services implement interfaces in same package, business logic in `pkg/services/<domain>/` not in API handlers, database via `sqlstore`, plugin communication via gRPC/protobuf.110111### Frontend (`public/app/`)112113| Directory | Purpose |114| ---------------------- | ----------------------------------------------------- |115| `public/app/core/` | Shared services, components, utilities |116| `public/app/features/` | Feature code by domain (dashboard, alerting, explore) |117| `public/app/plugins/` | Built-in plugins (many are Yarn workspaces) |118| `public/app/types/` | TypeScript type definitions |119| `public/app/store/` | Redux store configuration |120121**Patterns**: Redux Toolkit with slices (not old Redux), function components with hooks, Emotion CSS-in-JS via `useStyles2`, RTK Query for data fetching, React Testing Library for tests.122123### Shared Packages (`packages/`)124125`@grafana/data` (data structures), `@grafana/ui` (components), `@grafana/runtime` (runtime services), `@grafana/schema` (CUE-generated types), `@grafana/scenes` (dashboard framework).126127### Backend Apps (`apps/`)128129Standalone Go apps using Grafana App SDK: `apps/dashboard/`, `apps/folder/`, `apps/alerting/`.130131### Plugin Workspaces132133These built-in plugins require separate build steps: `azuremonitor`, `loki`, `grafana-testdata-datasource`.134135Build a specific plugin: `yarn workspace @grafana-plugins/<name> dev`136137## Key Notes138139- **Wire DI**: Backend service init changes require `make gen-go`. Wire catches circular deps at compile time.140- **CUE schemas**: Dashboard/panel schemas in `kinds/` generate both Go and TS code via `make gen-cue`.141- **Feature toggles**: Defined in `pkg/services/featuremgmt/`, auto-generate code. Run `make gen-feature-toggles` after changes.142- **Go workspace**: Defined in `go.work`. Run `make update-workspace` when adding Go modules.143- **Build tags**: `oss` (default), `enterprise`, `pro`.144- **Config**: Defaults in `conf/defaults.ini`, overrides in `conf/custom.ini`.145- **Database migrations**: Live in `pkg/services/sqlstore/migrations/`. Test with `make devenv sources=postgres_tests,mysql_tests` then `make test-go-integration-postgres`.146- **CI sharding**: Backend tests use `SHARD`/`SHARDS` env vars for parallelization.147- **Service compatibility**: Unified storage/search (`pkg/storage/unified/`) can be deployed as separate services at a different cadence than the Grafana API layer. Changes spanning API-layer callers and `pkg/storage/unified/` must be backwards compatible in both directions — see `pkg/storage/unified/AGENTS.md`.148149## Cursor Cloud specific instructions150151### Prerequisites152153- **Node.js** — version pinned in `.nvmrc` (check that file for the exact version). Installed via nvm and set as the nvm default. **PATH gotcha:** the infra injects `/exec-daemon/node` ahead of nvm, so the plain non-login shell may resolve `node` to an older version — check it satisfies the `engines` range in `package.json` (it does today, so builds/tests work), but it is not the pinned version. Login shells (tmux sessions, `bash -lc '...'`) get the pinned version because `~/.bashrc` prepends the nvm bin. Run `yarn` / `yarn start` / `jest` / webpack via a login shell (tmux or `bash -lc`) to use the pinned Node.154- **Go** — version pinned in `go.mod` (check that file for the exact version), installed at `/usr/local/go` and symlinked to `/usr/local/bin/go`. The distro `/usr/bin/go` is older; `/usr/local/bin` wins in PATH so `go` resolves correctly. If `go.mod` bumps Go, reinstall a matching toolchain into `/usr/local/go`.155- **Yarn** via corepack — version pinned by `package.json` `packageManager` (check that field for the exact version). Run `corepack enable` if `yarn` is not found. `.yarnrc.yml` sets `enableScripts: false`, so dependency build/lifecycle scripts are disabled by default.156- **GCC** required for CGo/SQLite compilation of the backend.157- Repos in this environment live under `/agent/repos/<repo>` (e.g. `/agent/repos/grafana`); this is a multi-repo workspace, not the single `~/grafana` layout described in `grafana-enterprise/AGENTS.md`.158159### Running services160161- **Backend**: `make run` — builds and starts Grafana backend with hot-reload (air) on `localhost:3000`. Default login: `admin`/`admin`. First build takes ~3 minutes due to debug symbols (`-gcflags all=-N -l`); subsequent hot-reload rebuilds are faster.162- **Frontend**: `yarn start` — starts webpack dev server that watches for changes. The backend proxies to it. First compile takes ~45s.163- No external databases required — Grafana uses embedded SQLite by default.164165### Testing gotchas166167- **Frontend tests**: The `yarn test` script includes `--watch` by default. Always use `yarn jest --no-watch` or add `--watchAll=false` to run tests once and exit.168- **Backend tests**: Some packages (e.g. `pkg/api/`) have slow test compilation (~2 min) due to large dependency graphs. Use targeted test runs with `-run TestName` where possible.169- All standard build/test/lint commands are documented in the Commands section above.170
Also in grafana/grafana
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| grafana/grafanae2e-playwright/alerting-suite/AGENTS.md · 76k | AGENTS.md | teststylearchtesting-strategy+3 | 81/100 | 3 days ago | |
| grafana/grafanae2e-playwright/dashboard-new-layouts/AGENTS.md · 76k | AGENTS.md | teststyletesting-strategydatabase+1 | 62/100 | today | |
| grafana/grafanae2e-playwright/plugin-e2e/plugin-e2e-api-tests/AGENTS.md · 76k | AGENTS.md | teststyletesting-strategygit+4 | 70/100 | 3 days ago | |
| grafana/grafanapackages/grafana-ui/AGENTS.md · 76k | AGENTS.md | uiagent-behaviour | 16/100 | 3 days ago | |
| grafana/grafanapkg/storage/unified/AGENTS.md · 76k | AGENTS.md | do-not | 46/100 | 3 days ago | |
| grafana/grafanapublic/app/core/journeys/AGENTS.md · 76k | AGENTS.md | testtesting-strategygitagent-behaviour | 73/100 | 3 days ago | |
| grafana/grafanapublic/app/features/AGENTS.md · 76k | AGENTS.md | agent-behaviour | 16/100 | 3 days ago | |
| grafana/grafanapublic/app/features/alerting/unified/AGENTS.md · 76k | AGENTS.md | setuptestlint-formatstyle+11 | 76/100 | 3 days ago | |
| grafana/grafanapublic/app/features/expressions/components/SqlExpressions/SqlEditor/AGENTS.md · 76k | AGENTS.md | styleagent-behaviour | 43/100 | 3 days ago | |
| grafana/grafanapublic/app/plugins/panel/AGENTS.md · 76k | AGENTS.md | agent-behaviour | 16/100 | 3 days ago |
Diff against e2e-playwright/alerting-suite/AGENTS.md Diff against e2e-playwright/dashboard-new-layouts/AGENTS.md Diff against e2e-playwright/plugin-e2e/plugin-e2e-api-tests/AGENTS.md Diff against packages/grafana-ui/AGENTS.md Diff against pkg/storage/unified/AGENTS.md Diff against public/app/core/journeys/AGENTS.md Diff against public/app/features/AGENTS.md Diff against public/app/features/alerting/unified/AGENTS.md Diff against public/app/features/expressions/components/SqlExpressions/SqlEditor/AGENTS.md Diff against public/app/plugins/panel/AGENTS.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| code-yeongyu/oh-my-openagentpackages/web/AGENTS.md · 67k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | 3 days ago | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| aaif-goose/gooseAGENTS.md · 52k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| trick77/agents-md-syncAGENTS.md · 2 | AGENTS.md | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| ethereum/go-ethereumAGENTS.md · 51k | AGENTS.md | buildtestlint-formatgit+1 | 100/100 | 3 days ago |
