# Page Flow

Current confirmed discovery flow:

1. Parse Clinic link fragment:
   - `/portal/#/orgs/{orgId}/clusters/{clusterId}?from=...&to=...`
2. Call dashboard list:
   - `GET /clinic/api/v1/orgs/{orgId}/clusters/{clusterId}/dashboard?startTime={from_sec}&endTime={to_sec}`
3. Extract Grafana dashboard URL from each dashboard item:
   - example: `/grafana/d/{uid}/{slug}?orgId=1&var-tidb_cluster=...&from=...&to=...`
4. Fetch Grafana dashboard JSON:
   - `GET /grafana/api/dashboards/uid/{uid}`
5. Read:
   - `dashboard.title`
   - `dashboard.templating.list`
   - `dashboard.panels[]`
   - `dashboard.panels[].targets[]`

Current confirmed download flow:

1. Start from one Clinic portal link:
   - `/portal/#/orgs/{orgId}/clusters/{clusterId}?from=...&to=...`
2. Check `data_status == 100` for the same time window before downloading
3. Build the download endpoint from the known `itemId`:
   - `GET /clinic/api/v1/orgs/{orgId}/clusters/{clusterId}/download/{itemId}`
   - or `GET /clinic/api/v1/orgs/{orgId}/clusters/{clusterId}/downloadConf/{itemId}`
4. Reuse the same browser cookie + CSRF header
5. Stream the response body to local disk
6. If the filename ends with `.zst` or `.tar.zst`, run `zstd -d`
7. If the result is a tar archive, run `tar -xf`
8. Inspect extracted files:
   - `meta.yaml`
   - `cluster.json`
   - node directories like `{host}/.../log/*.log`
   - `monitor/metrics/...`

Known auth behavior:

- Local Clinic auth in this skill is browser-session based, not API-key based
- Chrome login session stores cookie `clinic.session_id`
- JWT payload contains `user.csrfToken`
- API requests require:
  - cookie: `clinic.session_id`
  - header: `x-csrf-token: {csrfToken}`

Known non-blocker:

- `/clinic/api/v1/dashboard/proxy/.../configuration/all` may return `503`
- discovery can proceed without it by using Grafana dashboard JSON directly
