Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .agents/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Agent skills for UXarray

Reusable instructions for AI coding agents working on this repository. The repo-wide context every
agent should read is [`AGENTS.md`](../AGENTS.md) at the repo root; the skills here build on it.

| Skill | Use it to |
|---|---|
| [`uxarray-pr-review`](skills/uxarray-pr-review/SKILL.md) | Review a PR and verify every finding by running code before reporting it |
| [`uxarray-issue-triage`](skills/uxarray-issue-triage/SKILL.md) | Classify an issue, find duplicates and related work, try to reproduce it, and suggest labels |

Each skill is a folder with a `SKILL.md` (name, description, steps) and optional `references/` files that
the steps link to.

## Using them

- **Claude Code**: `.claude/skills/` holds symlinks to these folders, so the skills are available as
`/uxarray-pr-review <PR number>` and `/uxarray-issue-triage <issue number>`. Claude Code reads
`AGENTS.md` itself in recent versions (tested with 2.1.323; 2.1.270 does not); if it isn't loaded,
run `claude update`.
- **Other agents**: agents that read `.agents/skills/` pick them up directly. For any other agent, point
it at the skill's `SKILL.md`, e.g. "Follow `.agents/skills/uxarray-pr-review/SKILL.md` for PR 1889".

Windows: the `.claude/skills/` symlinks need `git config core.symlinks true` (and Developer Mode or admin
rights) before checkout; otherwise they appear as small text files.

## Ground rules shared by the skills

- Never post to GitHub, label, or push without the user's approval of the exact text.
- Work in git worktrees and a scratch environment; never switch branches in the user's checkout.
- Report a finding as fact only after reproducing it; otherwise say it was not reproduced and why.

## Adding a skill

Create `.agents/skills/<name>/SKILL.md` with `name` and `description` front matter, add a symlink
`ln -s ../../.agents/skills/<name> .claude/skills/<name>`, and add a row to the table above.
107 changes: 107 additions & 0 deletions .agents/skills/uxarray-issue-triage/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
name: uxarray-issue-triage
description: Triage a UXarray (UXARRAY/uxarray) GitHub issue like a senior maintainer - classify it, find duplicates and past decisions, try to reproduce it, locate the code involved, and suggest labels and next steps. Use when asked to triage, review or assess a uxarray issue by number or URL.
---

# UXarray issue triage

Triage the issue given as the argument. The output is a short triage note for the maintainer, plus an
optional comment for the issue thread. Read `AGENTS.md` at the repo root first for the architecture and
the settled design decisions.

Nothing is posted or labelled without the user's approval.

## 1. Understand

`gh issue view <n> --comments`. Note what the reporter observed, what they expected, their UXarray
version and install method (the bug template asks for both), the grid format and model (MPAS, ICON,
SCRIP, ...), the data size, whether dask/chunking is involved, and anything they already tried.

Read the discussion as carefully as the report: who has already diagnosed or reproduced it, what was
asked of the reporter and whether they answered, existing labels/assignees, decisions posted from
maintainer meetings ("From internal discussion..."), and PRs or issues that mention it
(`gh api repos/UXARRAY/uxarray/issues/<n>/timeline` → `cross-referenced` events). Build on that rather
than repeating it, and list unanswered questions or disagreements under **Needs your call**.

## 2. Classify

- **Type**: bug, feature request, question/support, docs, performance/scalability, accuracy, CI/infra,
upstream (an xarray/numba/dask/cartopy change; label `fix upstream`), environment (install, conda vs
pip, missing optional extra: often not a UXarray bug).
- **Bot issues** ("🤖 Upstream testing failure", "🤖 Minimum dependency testing failure"): find the first
failing run and the dependency release that broke it; a min-deps failure means a lower bound in
`pyproject.toml` needs raising (with a comment) or the code needs a compatible path.
- **AI-reported bugs** (e.g. "[Claude] ..." titles, lists of several bugs): check each claim separately
against current `main`; some may be duplicates or already fixed.
- **Security-sensitive** (exposed credentials, a vulnerability): stop here. Do not draft a public comment
or reproduce it in public; tell the user, who decides how to handle it privately.
- **Area**: io/reader (which format), grid construction/topology, geometry/accuracy, core
(`UxDataArray`/`UxDataset` ops, aggregations, calculus), remap, subset/cross-section, plotting, dask,
docs, packaging/optional deps.
- **Labels**: suggest only from the repo's labels (`gh label list`), e.g. `bug`, `new feature`,
`improvement`, `documentation`, `scalability`, `accuracy`, `visualization`, `extra dims`, `design`,
`developer experience`, `fix upstream`, `CI`, `testing`. The repo has no priority, size or "good first
issue" labels; `may revisit` is for ideas closed as not planned for now.

## 3. Look for duplicates, related work and past decisions

Search open **and** closed issues, PRs and Discussions with 2-3 keyword variants:
`gh search issues --repo UXARRAY/uxarray "<keywords>"`, `gh pr list --state all --search "<keywords>"`,
and Discussions via `gh api graphql` (`repository.discussions` or `search(type: DISCUSSION)`).
Also check whether a PR already claims to fix it (`closedByPullRequestsReferences`:
`gh api graphql -f query='query{repository(owner:"UXARRAY",name:"uxarray"){issue(number:<n>){
closedByPullRequestsReferences(first:10,includeClosedPrs:true){nodes{number title state}}}}}'`).

For feature requests, check them against the settled decisions in AGENTS.md (scope: 2D grids on the
sphere; structured grids only through `from_structured()`; file writing through xarray; `Grid` not
growing Dataset API) and look for an earlier issue closed as not planned or `may revisit`. Link what
you find rather than re-arguing it.

## 4. Locate and reproduce

1. Check whether it is already fixed: get the reporter's version (a dev version such as
`2026.9.1.dev24+ge01d71e37` names the commit after the `g`; a release maps to tag `v<version>`) and
run `git log <their-commit>..origin/main -- <files involved>`. If a later commit fixed it, say which.
2. Find the code involved and trace it to the public entry point, as in the PR-review skill's Stage 1
(`.agents/skills/uxarray-pr-review/SKILL.md`).
3. For a bug, try to reproduce it on current `main` in a clean worktree with the environment from
`.agents/skills/uxarray-pr-review/references/verification.md` §Setup. Write the smallest script that
shows it, preferring a mesh from `test/meshfiles/` (table in verification.md) or a face built with
`Grid.from_face_vertices` over the reporter's large file. Result is one of:
- **Reproduced** — include the script and its output.
- **Not reproduced** — say what was tried; ask the reporter for the missing detail (grid file or a
link to it, version, full traceback).
- **Needs reporter data** — the bug depends on a grid or dataset that isn't available; say what is
needed. Many model files live on NCAR GLADE or are large; a subset or the grid file alone often
suffices.
4. Give a root-cause hypothesis with `file:line`, labelled confirmed or suspected. For geometry bugs, a
sweep over antimeridian, pole and rotated inputs (verification.md §Techniques, item 2) often shows
the pattern.

For a **feature request**, instead of reproducing: does it fit UXarray's scope, can it be done today with
existing API (e.g. via `.to_xarray()` and plain xarray), does an xarray analogue define what the API
should look like, and does it overlap open work? For a **question**, find the docs page or user-guide
notebook that answers it; if none does, that is a docs gap worth noting.

## 5. Report

Show the user, in this order and briefly:

```
#<n> <title>
Type / area: ...
Duplicates / related: #.. (why), past decisions (link) — or none found
Reproduction: Reproduced | Not reproduced | Needs reporter data — one line, script path
Likely cause: file:line — confirmed | suspected
Suggested labels: ...
Priority (advisory): high (wrong results, data loss, crash in common path) | medium | low — one-line reason
Size (advisory): S | M | L — one-line reason
Next step: who/what, e.g. "needs reporter's grid file", "fix with #PR", "maintainer design call"
Needs your call: open disagreements or unanswered questions from the thread, if any
```

Priority and size are advice to the maintainer, not repo labels.

Then, if useful, a draft comment for the issue thread (under ~100 words: what was reproduced, what is
needed from the reporter, or the duplicate link). Post the comment or apply labels only after the user
approves, with `gh issue comment` / `gh issue edit --add-label`.
125 changes: 125 additions & 0 deletions .agents/skills/uxarray-pr-review/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
name: uxarray-pr-review
description: Review a UXarray (UXARRAY/uxarray) pull request like a senior maintainer and verify every finding by running code before reporting it. Use when asked to review, check or comment on a uxarray PR by number, branch or URL.
---

# UXarray PR review (self-verifying)

Review the pull request given as the argument (number, branch or URL). The goal is a review that is
**deep but short**, where every finding has been **checked by running code**, not just by reading it.
Read `AGENTS.md` at the repo root first: it holds the architecture and the repo rules this review
checks against.

Work in four stages. Do not skip stage 3: a finding that has not been through it is not reported as fact.

## Stage 0 — Set up (once per PR)

Follow [references/verification.md](references/verification.md) §Setup: a worktree for the PR, a clean
worktree of the base branch, and a Python environment that imports the tree under test. Never switch
branches in the user's own checkout.

PRs from forks run someone else's code on this machine. For an unfamiliar author, say so and ask
before running anything.

## Stage 1 — Context

1. `gh pr view <n>` (body, author, commits, `closingIssuesReferences`) and every linked issue with its
comments. Note what the PR **claims** to do: you will check the code against those claims. Maintainer
decisions are often posted on the issue as "From internal discussion..." comments; the PR must follow
them.
2. **Review history** — follow [references/history.md](references/history.md): earlier reviews and the
commit each one reviewed, every inline thread and comment, commits since the last review, description
edits, force-pushes, CI status. Build the ledger of points raised and their status, and note
disagreements and unanswered questions. Do this even when the PR looks fresh.
3. `git diff <base>...HEAD --stat`, then the full diff. If there was an earlier review, also the diff since
that review's commit: it is the least-reviewed code in the PR.
4. For every changed function, **trace its callers up to a public entry point** (`ux.open_*`, a `Grid`
property or classmethod, a `UxDataArray`/`UxDataset` method, an accessor method such as `.remap.*`,
`.subset.*`, `.plot.*`). Record:
- which grid formats and readers reach it, and whether faces can be mixed-size (padded with
`INT_FILL_VALUE`), cross the antimeridian, contain a pole, or come from a projected grid;
- which data locations it handles (node / edge / face) and which it rejects;
- whether it runs on numpy or chunked (dask) data, and whether the caller can pass either;
- which options select the path (`periodic_elements`, `backend`, `remap_to`, `destination`,
`latlon`, `inverse_indices`, ...).
This step decides which findings are possible at all. Skipping it produces false positives.

## Stage 2 — Find candidates

Look at the diff along these dimensions. Use parallel subagents (one per dimension) when the PR is
large; for small PRs, do it in one pass.

- **Correctness and numerics**: degrees vs radians and the two longitude ranges ([-180, 180] vs
[0, 2π)); `INT_FILL_VALUE` padding handled (not `-1`, `0`, `np.nan`); `ERROR_TOLERANCE` vs
`MACHINE_EPSILON`; antimeridian and pole faces; unit sphere vs `sphere_radius` scaling; NaN comparison
semantics; dtype promotion and integer overflow (int32 vs int64, Windows); `np.isclose(a, b, tol)`
passing `rtol` by position.
- **Accuracy-sensitive geometry**: naive arithmetic replacing `utils/computing.py` primitives,
`fastmath=True`, branching inside hot kernels, comments that overclaim ("robust", "exact",
"branch-free") or don't match the code. Compare against an analytic value or the existing accuracy
baselines (`test/grid/geometry/test_eft_accuracy.py`, `test_accusphgeom_baseline.py`).
- **Grid and data model** (AGENTS.md "Core data model"): `uxgrid` lost or not sliced after an op (e.g.
`sel` vs `isel`); coords and attrs dropped; objects on different grids combined without
`GridsMismatchError`; `_uxgrid` vs `uxgrid` misuse; topology mutated in place instead of returning a
new `Grid`; a connectivity renumbered without its pair; new grid variables not registered in
`uxarray/conventions` (works but invisible in `repr`).
- **Dask and performance**: `.values` / `np.asarray` on whole arrays, eager compute or silent rechunking
of chunked input; numba kernels allocating small arrays in loops; raw `njit(parallel=True)` instead of
`parallel_njit`; work done at import time; heavy imports at module level. Does a hot-path change need
the `run-benchmark` label or a new ASV benchmark?
- **API and back-compat**: consistency with xarray and existing UXarray signatures, argument order,
defaults and names; public vs `_private`; behavior changes not stated in the description; removals
without a `FutureWarning` cycle; structured-grid handling leaking into core APIs; new write APIs
(AGENTS.md "Core data model").
- **Optional dependencies**: optional packages imported at module level or without
`_raise_hint_if_optional_deps_missing`; a new optional dep missing from `_OPTIONAL_DEPS_TO_EXTRAS`; a
newer dependency API used without raising the lower bound (min-deps CI).
- **Errors**: right type (`uxarray/errors.py` for domain errors, built-ins for generic checks), message
with expected and actual values and no private names, no `assert` for validation, no broad
`try/except` hiding the cause, invalid input raising rather than silently changing results.
- **Tests**: do the new tests fail without the fix (stage 3 checks this)? Do they assert what their
name says? Are tolerances and expected values justified? Are mixed-size, antimeridian, pole, extra-dim
and chunked cases covered where the caller allows them?
- **Docs and PR hygiene**: numpydoc docstrings (types in `Parameters`); new public API in `docs/api.rst`;
a user-guide section or notebook for a new user-facing feature; notebook outputs cleared (unless the
notebook is in `nb_execution_excludepatterns`); description matches the code; "Closes" vs "Related
to"; AI disclosure line filled in and its box ticked.
- **Scope and LLM habits**: unrelated changes, PRs that should be split; unneeded defensive code,
over-general helpers, hedging, boilerplate module docstrings (AGENTS.md "Pull requests").
- **Scientific-software practice**: reproducibility, units, readability, maintainability.

For each candidate, write down: the claim, `file:line`, the concrete failure scenario, and how you will
verify it. Candidates are hypotheses, not findings.

Check each candidate against the ledger from Stage 1: drop it if someone already raised it, unless you
have new evidence, in which case it becomes a reply in that thread or a line in the summary.

## Stage 3 — Verify

Apply the techniques in [references/verification.md](references/verification.md) §Techniques. Then label
each candidate:

- **CONFIRMED** — reproduced by running code (a failing test, a mutation that survives, an experiment).
- **PLAUSIBLE** — the code path is real but cannot be run here (e.g. needs YAC, NCAR GLADE data or a
large mesh). State why it cannot be run.
- **Dropped** — disproved. Keep a one-line note of why: dropped candidates show the review was thorough
and stop the next reviewer from raising them again.

Always run, whatever the candidates: the PR's new and changed tests on the PR; the tests of the touched
area on the PR; a **mutation test of each source hunk** (revert it, rerun the tests; a hunk whose
reversion no test notices is a coverage finding); ruff on changed files under `uxarray/`.

For a PR with **no source hunks** (docs, notebooks, CI, agent files), mutation testing does not apply.
Instead: build the docs if `docs/` or docstrings changed and compare warnings with base; run touched
notebooks; and check that every code reference in the changed text (paths, functions, options, commands)
exists on the PR branch and says what the text claims.

For a **refactor or performance PR** (behavior should not change), compare outputs on base vs PR
(verification.md §Techniques, item 4) and time both (item 6).

## Stage 4 — Report

Write the draft to a file in the scratchpad using [references/report.md](references/report.md), then
**show it to the user and wait**. Post only after explicit approval, exactly as approved, following
report.md §Posting. Then clean up per verification.md §Cleanup (keep the PR worktree until the PR merges
if a re-review is likely).
Loading
Loading