Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
84 changes: 84 additions & 0 deletions .github/workflows/agent-evals.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Agent evals
on:
# Runs the evals from the base branch with access to the pull request
# number. Code from the pull request is never run; it is only read.
pull_request_target:
types: [opened, reopened, synchronize]
env:
NODE_OPTIONS: "--disable-proto=delete"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
audit:
name: "Audit agent-assisted changes"
permissions:
contents: read
pull-requests: write # comment on PRs
runs-on: ubuntu-24.04
steps:
- name: Determine whether to audit the pull request
id: detect
env:
GH_TOKEN: ${{ github.token }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
PR_COMMITS: ${{ github.event.pull_request.commits }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
# GitHub lists at most 250 commits of a pull request
if [[ ${PR_COMMITS} -gt 250 ]]; then
echo "::warning::#${PR_NUMBER} has ${PR_COMMITS} commits; only the first 250 were checked for agents"
fi
# Copilot, Claude and Cursor, as authors of the pull request or its
# commits, or as co-authors of its commits
pattern='^login (Copilot|claude\[bot\]|cursor\[bot\])$|^email .*(\+Copilot@users\.noreply\.github\.com|noreply@anthropic\.com|cursoragent@cursor\.com)>?$'
{
echo "login ${PR_AUTHOR}"
gh api --paginate "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/commits" --jq '
.[]
| "login \(.author.login // "")",
"email \(.commit.author.email)",
(.commit.message | split("\n")[] | sub("\\s+$"; "") | select(test("^co-authored-by:"; "i")) | "email \(.)")'
} > "${RUNNER_TEMP}/identities.txt"
# Skips the audit if the agent already posted a report with its
# session log for this commit. Only reports by the author of the pull
# request and this workflow count; anyone else could post a fake one.
# Not `grep -q`; it may exit before `gh` is done, failing the pipe.
reports='.[]
| select(.user.login == env.PR_AUTHOR or .user.login == "github-actions[bot]")
| .body | split("\n")[0] | rtrimstr("\r")'
if ! grep -qiE "${pattern}" "${RUNNER_TEMP}/identities.txt"; then
echo "#${PR_NUMBER} was not assisted by an agent"
elif gh api --paginate "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --jq "${reports}" \
| grep -xF "<!-- agent-evals head=${HEAD_SHA} log=yes -->" > /dev/null; then
echo "#${PR_NUMBER} already has a report with the session log for ${HEAD_SHA}"
else
echo 'audit=true' >> "${GITHUB_OUTPUT}"
fi
- name: Checkout
if: ${{ steps.detect.outputs.audit == 'true' }}
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
filter: blob:none
fetch-depth: 0
persist-credentials: false
- name: Setup the toolchain
if: ${{ steps.detect.outputs.audit == 'true' }}
uses: microsoft/react-native-test-app/.github/actions/setup-toolchain@6046bdd4914c7ceb35ec83b92ae3211a03ddccef # 5.4.14
with:
node-version: 24
- name: Install npm dependencies
if: ${{ steps.detect.outputs.audit == 'true' }}
run: |
yarn
- name: Audit the pull request
if: ${{ steps.detect.outputs.audit == 'true' }}
env:
GH_TOKEN: ${{ github.token }}
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
# Only reports; failed rules do not fail the check
run: |
yarn workspace @rnx-kit/evals eval:report "${PR_NUMBER}"
timeout-minutes: 30
14 changes: 14 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,20 @@ yarn update-readme # Regenerate API docs
CI uses `suggestion-bot` to post code review suggestions for format,
constraints, align-deps, and readme issues.

### Agent Evals

After creating a pull request, or pushing changes to one, run the evals and
post the report on the pull request:

```sh
cd evals
yarn eval:report
```

This audits the current session and posts the report as a comment. Do not edit
the report. Post it again after every push; if there is no report for the latest
commit, the `Agent evals` workflow replaces it with an audit of the diff.

## Housekeeping

- When triaging issues, ignore the issue titled "Dependency Dashboard" (opened
Expand Down
46 changes: 46 additions & 0 deletions evals/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# @rnx-kit/evals

This is for internal use only. To audit agent sessions in your own repository,
see [`@rnx-kit/agent-evals`](../incubator/agent-evals).

Audits coding agent sessions in this repository against its conventions, e.g.
those in [`AGENTS.md`](../AGENTS.md), with
[`@rnx-kit/agent-evals`](../incubator/agent-evals). Each rule is a test in
[`tests/audit.yaml`](tests/audit.yaml); see
[`promptfooconfig.yaml`](promptfooconfig.yaml) for the options.

```sh
yarn eval # the current or latest local session
yarn eval --var copilotSession=<id> # a specific session
yarn eval --var pullRequest=<number> # a pull request
```

## Reports on pull requests

Run the evals and post the report on a pull request:

```sh
yarn eval:report # the pull request of the current branch
yarn eval:report <number> # a specific pull request
```

Arguments after the number are passed to `yarn eval`. The report is posted in a
single comment, which is updated on every run. If the comment cannot be edited,
e.g. if the workflow posted it on a pull request from a fork, a new one is
posted, and that one is updated from then on. The comment starts with a marker
that records the audited commit, and whether the session log was read.

The [`Agent evals`](../.github/workflows/agent-evals.yml) workflow audits pull
requests that Copilot, Claude or Cursor created or co-authored. It runs
`yarn eval:report <number>` with `GITHUB_TOKEN`, which cannot read the session
logs, so it can only audit the changes. If the comment already has a report with
the session log for the latest commit, the workflow skips the audit. Only
reports by the author of the pull request and the workflow count. The workflow
only reports; failed rules do not fail the check.

## Adding rules

Add a test to [`tests/audit.yaml`](tests/audit.yaml). Use the checks from
`@rnx-kit/agent-evals`, or add your own to [`src`](src) and export it from
[`src/index.ts`](src/index.ts). Set `metadata.requires: session` if the rule
needs more than the changes, e.g. the commands that were run.
2 changes: 2 additions & 0 deletions evals/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"scripts": {
"build": "rnx-kit-scripts build",
"eval": "NODE_OPTIONS=--conditions=typescript npx --yes promptfoo@0.124.1 eval",
"eval:report": "node --conditions=typescript src/post-report.ts",
"format": "rnx-kit-scripts format",
"lint": "rnx-kit-scripts lint",
"promptfoo": "NODE_OPTIONS=--conditions=typescript npx --yes promptfoo@0.124.1",
Expand All @@ -28,6 +29,7 @@
"@rnx-kit/agent-evals": "workspace:*",
"@rnx-kit/eslint-plugin": "workspace:*",
"@rnx-kit/tools-filesystem": "workspace:*",
"@rnx-kit/tools-shell": "workspace:*",
"oxc-parser": "catalog:",
"oxlint": "catalog:",
"parse-diff": "catalog:"
Expand Down
17 changes: 13 additions & 4 deletions evals/promptfooconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@ providers:
defaultTest:
vars:
# ID of the session to audit, e.g. `--var copilotSession=<id>`. If empty,
# audits the most recently updated session in this repository that is not
# in use. Not named `session` because promptfoo redacts fields with that
# name.
# audits the session running the evals, or if there is none, the most
# recently updated session in this repository that is not in use;
# `previous` always audits the latter. Not named `session` because
# promptfoo redacts fields with that name.
copilotSession: ""
# Number of a pull request to audit instead, e.g. `--var pullRequest=123`.
# Reads its Copilot cloud agent sessions from GitHub; if they cannot be
# read, audits only its changes and skips rules with `requires: session`.
pullRequest: ""
options:
# Grades `llm-rubric` assertions with Copilot; requires a GitHub token
# with Copilot access in `COPILOT_GITHUB_TOKEN`, `GH_TOKEN` or
# `GITHUB_TOKEN`, or a `gh auth login` session. Pass `--grader` to use
# another provider instead.
provider: file://src/grader.ts
provider:
id: file://src/grader.ts
# Without a model, the Copilot runtime picks its default, which may not
# be available to every account
config: { model: claude-sonnet-5.5 }
tests: file://tests/*.yaml
extensions:
# Prints each test with the reasons it failed, instead of promptfoo's table.
Expand Down
3 changes: 2 additions & 1 deletion evals/src/oxlint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export function passesOxlint(
"--no-ignore",
"--format",
"json",
...matching,
// Paths starting with `-` would otherwise be parsed as options
...matching.map((file) => `./${file}`),
],
{ cwd: run.workdir, encoding: "utf-8", timeout: OXLINT_TIMEOUT_MS }
);
Expand Down
Loading
Loading