-
Notifications
You must be signed in to change notification settings - Fork 40
LLMs: Scaffolding agents.md for datasource plugins #2322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
56e2f53
43c0bc2
1718e20
68e9c0e
40503a1
670e592
bb6815a
7bb76e9
5726492
d2b568d
f5286f4
39ac36f
17555c2
c843c5a
297a0d9
604f780
45921a5
69d9ec0
8e13dde
ff0be90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| @AGENTS.md |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,136 @@ | ||||||||||
| You are an expert Grafana datasource plugin developer for this project. | ||||||||||
|
|
||||||||||
| ## Your role | ||||||||||
|
|
||||||||||
| - You are fluent in TypeScript and React (frontend) | ||||||||||
| {{#if hasBackend}}- You are fluent in Go (backend){{/if}} | ||||||||||
| - You know how to use Grafana dashboards | ||||||||||
| - You know how to setup and manage Grafana datasources | ||||||||||
|
|
||||||||||
| ## Project knowledge | ||||||||||
|
|
||||||||||
| This repository contains a **Grafana datasource**, providing a custom datasource for Grafana. | ||||||||||
| Datasource plugins are used to fetch and query data from external systems. | ||||||||||
|
|
||||||||||
| It is recommended that the datasource includes: | ||||||||||
| - A health check | ||||||||||
| - Template variable support | ||||||||||
| - A default query | ||||||||||
| {{#if hasBackend}} | ||||||||||
| - Support for alerting | ||||||||||
| {{/if}} | ||||||||||
|
|
||||||||||
| ### Plugin anatomy | ||||||||||
|
|
||||||||||
| {{#if hasBackend}}A typical datasource with backend plugin includes:{{/if}} | ||||||||||
| {{#unless hasBackend}}A typical datasource frontend only plugin includes:{{/unless}} | ||||||||||
|
|
||||||||||
| **plugin.json** | ||||||||||
|
|
||||||||||
| - Declares plugin ID, type (`datasource`), name, version | ||||||||||
| - Gives Grafana the instructions it needs during startup to know how to run the plugin. | ||||||||||
| {{#if hasBackend}}- Needs to define `backend:true` and `executable:gpx_<name_of_plugin>` to launch the backend part of Grafana during startup.{{/if}} | ||||||||||
|
|
||||||||||
| Reference: https://grafana.com/developers/plugin-tools/reference/plugin-json | ||||||||||
|
|
||||||||||
| **Main module (`src/module.ts(x)`)** | ||||||||||
|
|
||||||||||
| - Exports: `new DataSourcePlugin(DataSource)` | ||||||||||
| - Registers query editor, config editor | ||||||||||
|
|
||||||||||
| **Data source (`src/datasource.ts`)** | ||||||||||
|
|
||||||||||
| {{#if hasBackend}}- Frontend datasource that extends DataSourceWithBackend.{{/if}} | ||||||||||
| {{#unless hasBackend}}- Frontend datasource that extends DataSourceApi<MyQuery>.{{/unless}} | ||||||||||
| - Connects the UI to the backend, provides the default query, applies template variables, filters queries, and sends them to the Go backend for execution | ||||||||||
|
|
||||||||||
| **Query editor (`src/QueryEditor.tsx`)** | ||||||||||
|
|
||||||||||
| - React component where users build and customize queries that will be sent to the data source | ||||||||||
|
|
||||||||||
| **Config editor (`src/ConfigEditor.tsx`)** | ||||||||||
|
|
||||||||||
| - React component where users manage and configure a data source instance | ||||||||||
| - Configures instance specific settings (like URLs or credentials) | ||||||||||
|
|
||||||||||
| {{#if hasBackend}} | ||||||||||
| **Main module (`pkg/main.go`)** | ||||||||||
|
|
||||||||||
| - Register a factory function with `grafana-plugin-sdk-go` to create datasource backend instances | ||||||||||
|
|
||||||||||
| **Data source (`pkg/plugin/datasource.go`)** | ||||||||||
|
|
||||||||||
| - Backend datasource that Implements QueryData (receives queries from frontend, unmarshals into queryModel, returns data frames). Remember to skip execution for hidden or empty queries. | ||||||||||
| - CheckHealth (validates API key from settings) | ||||||||||
| - Dispose (cleanup hook). | ||||||||||
| - NewDatasource factory called when Grafana starts instance of plugin | ||||||||||
|
|
||||||||||
| **Instance Settings (`pkg/models/settings.go`)** | ||||||||||
|
|
||||||||||
| - Loads instance settings by parsing its persisted JSON, retrieving secure and non-secure values, and returning a combined settings object for the plugin to use at runtime. | ||||||||||
| {{/if}} | ||||||||||
|
|
||||||||||
| ### Repository layout | ||||||||||
|
|
||||||||||
| - `src/` - Frontend (TypeScript/React) | ||||||||||
| - `src/plugin.json` — Plugin manifest (metadata) | ||||||||||
| - `src/module.ts` — Frontend entry point | ||||||||||
| - `src/datasource.ts` - Datasource implementation | ||||||||||
| - `src/components/QueryEditor.tsx` — Query builder UI | ||||||||||
| - `src/components/ConfigEditor.tsx` — Data source settings UI | ||||||||||
| - `src/types.ts` — Shared frontend types | ||||||||||
| - `tests/` — E2E tests (if present) | ||||||||||
| - `provisioning/` — Local development provisioning | ||||||||||
| - `README.md` — Human documentation | ||||||||||
| {{#if hasBackend}} | ||||||||||
| - `pkg/` - Backend (Go) | ||||||||||
| - `pkg/main.go` - Backend entry point | ||||||||||
| - `pkg/plugin/datasource.go` - Datasource implementation | ||||||||||
| - `Magefile.go` - Backend build tasks | ||||||||||
| {{/if}} | ||||||||||
| - `package.json` - Frontend build scripts + deps | ||||||||||
|
|
||||||||||
| ## Coding guidelines | ||||||||||
|
|
||||||||||
| - Use **TypeScript** (in strict mode), functional React components, and idiomatic patterns | ||||||||||
| - Use **@grafana/ui**, **@grafana/data**, **@grafana/runtime** | ||||||||||
| - Use **`useTheme2()`** for all colors, spacing, typography | ||||||||||
| - **Never hardcode** colors, spacing, padding, or font sizes | ||||||||||
| - Use **Emotion** + `useStyles2()` + theme tokens for styling | ||||||||||
| - Keep layouts responsive (use `width`/`height`) | ||||||||||
| - Avoid new dependencies unless necessary + Grafana-compatible | ||||||||||
| - Maintain consistent file structure and predictable types | ||||||||||
| - Use **`@grafana/plugin-e2e`** npm package for E2E tests and **always use versioned selectors** to interact with the Grafana UI. | ||||||||||
|
|
||||||||||
| ## Boundaries | ||||||||||
|
|
||||||||||
| You must **NOT**: | ||||||||||
mckn marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the LLm will quickly forget the you will have to put "do not" or "must not" in every line. |
||||||||||
|
|
||||||||||
| - Change plugin ID or plugin type in `plugin.json` | ||||||||||
| - Modify anything inside `.config/*` | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had this "packages being removed from package.json" happen to me recently, and then it went into a weird direction trying to fix the issues by adjusting tsconfig and a bunch of files in .config folder.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But for some scenarios we need the agent to update the dependencies? I wonder if we can rewrite this to something like: Change any scaffolded dependencies in package.json or go.mod unless you have explicit approval to do so. What do you think?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is it not the case for any command by default? Maybe:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I think the following line need to be more explicit: Modify anything inside -> Never modify files in .config/ without explicit user approval
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I think the star .config/* <-- is causing issues here |
||||||||||
| - Remove/change existing query model without a migration handler | ||||||||||
| - Break public APIs (query model) | ||||||||||
| {{#if hasBackend}} | ||||||||||
| - Use the local file system | ||||||||||
| - Use environment variables | ||||||||||
| - Execute arbitrary code in the backend | ||||||||||
mckn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| - Log sensitive data | ||||||||||
| - Use upstream Golang HTTP client in the backend | ||||||||||
| - Use `info` level for logging | ||||||||||
| {{/if}} | ||||||||||
|
|
||||||||||
| You **SHOULD**: | ||||||||||
|
|
||||||||||
| - Maintain backward compatibility | ||||||||||
| - Preserve query model schema unless migration handler is added | ||||||||||
| - Follow official Grafana datasource plugin patterns | ||||||||||
| - Use idiomatic React + TypeScript | ||||||||||
| - Use secureJsonData instead of jsonData for credentials and sensitive data | ||||||||||
| {{#if hasBackend}} | ||||||||||
| - Use Grafana plugin SDK HTTP client in the backend | ||||||||||
| - Use `debug` or `error` level for logging | ||||||||||
| - Cache and reuse backend connections to external services | ||||||||||
| {{/if}} | ||||||||||
|
|
||||||||||
mckn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| ## Instructions for specific tasks | ||||||||||
| - [Add template variable support](./tasks/support-template-variables.md) | ||||||||||
Uh oh!
There was an error while loading. Please reload this page.