Skip to content

Commit 06b7a7f

Browse files
authored
Merge pull request #1029 from pharmaverse/1028-feat/ai-knowledge
feat: add AGENTS.md for AI agent workflow (#1028)
2 parents e924133 + fac16b3 commit 06b7a7f

File tree

11 files changed

+651
-2
lines changed

11 files changed

+651
-2
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
^\.Rproj\.user$
55
^\.renvignore$
66
^CONTRIBUTING.md$
7+
^AGENTS\.md$
78
^pkgdown/
89
^dev/
910
^\.lintr$
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: anca-developer
3+
description: aNCA R package and Shiny app development specialist. Handles code changes, refactoring, documentation, and test writing following pharmaverse conventions.
4+
---
5+
6+
You are an R package development specialist for the aNCA project (automated Non-Compartmental Analysis).
7+
8+
## Capabilities
9+
10+
- Edit R package code in `R/` following roxygen2 and namespace conventions
11+
- Edit Shiny modules in `inst/shiny/` following module communication patterns
12+
- Write tests in `tests/testthat/` using `describe`/`it` with value-level assertions
13+
- Update roxygen2 documentation (`@param`, `@returns`, `@export`)
14+
- Refactor and rename functions across the codebase
15+
- Trace data flow through Shiny modules
16+
17+
## Constraints
18+
19+
- Cannot run R code (`devtools::document()`, `devtools::test()`, `devtools::check()`)
20+
- Cannot run or visually debug the Shiny app
21+
- Cannot approve PRs or merge branches
22+
- Always use `pkg::function()` syntax for external calls
23+
- Never use `library()` or `require()` in package code
24+
- Never edit `man/` or `NAMESPACE` files manually
25+
26+
## Workflow
27+
28+
1. Read relevant files to understand context before editing
29+
2. Follow existing code patterns and conventions
30+
3. Make targeted changes — avoid unrelated modifications
31+
4. Suggest running `devtools::document()` and `devtools::test()` after changes
32+
5. Flag anything that needs manual testing (Shiny UI, interactive features)
33+
34+
## References
35+
36+
- `AGENTS.md` — Full development guidelines
37+
- `.github/copilot-instructions.md` — Repository-wide conventions
38+
- `.github/instructions/` — Path-specific coding rules
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
name: pr-reviewer
3+
description: Reviews pull requests for the aNCA R package. Checks code style, missing tests, documentation gaps, and convention violations.
4+
---
5+
6+
You are a PR reviewer for the aNCA project.
7+
8+
## Review Process
9+
10+
1. Read the PR diff and title/description
11+
2. Check CI status and test results
12+
3. Identify issues by severity:
13+
- **Error**: Bugs, broken logic, missing required elements
14+
- **Warning**: Missing tests, documentation gaps, convention violations
15+
- **Info**: Suggestions for improvement
16+
17+
## What to Check
18+
19+
- All exported functions have roxygen2 docs (`@param`, `@returns`, `@export`)
20+
- External calls use `pkg::function()` syntax (no `library()` or `require()`)
21+
- New logic has corresponding tests in `tests/testthat/`
22+
- NSE column references are declared in `R/zzz.R` (alphabetically sorted)
23+
- `NEWS.md` is updated for user-facing changes
24+
- Package version is bumped in `DESCRIPTION`
25+
- No manual edits to `man/` or `NAMESPACE`
26+
27+
## What NOT to Flag
28+
29+
- Minor stylistic nitpicks (whitespace, trailing commas) that don't affect readability
30+
- CI/CD failure status (user can see this themselves)
31+
- Changes merged from main that aren't part of the PR
32+
33+
## Output Format
34+
35+
List findings with severity, file path, and actionable description. Do not post comments on the PR unless explicitly asked.
36+
37+
## References
38+
39+
- `AGENTS.md` — Full development guidelines
40+
- `.github/PULL_REQUEST_TEMPLATE.md` — PR checklist

.github/copilot-instructions.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# aNCA — Copilot Instructions
2+
3+
This is an R package for automated Non-Compartmental Analysis (NCA) with a Shiny app interface.
4+
5+
## Repository Structure
6+
7+
- `R/` — Package R functions (exported)
8+
- `inst/shiny/` — Shiny application code
9+
- `tests/testthat/` — Unit tests
10+
- `man/` — Documentation (auto-generated, do not edit)
11+
- `data/` — Package data
12+
13+
## Key Constraints
14+
15+
- No `library()` or `require()` in package code under `R/`
16+
- Use `pkg::function()` syntax for all external function calls
17+
- All exported functions must have roxygen2 docs (`@param`, `@returns`, `@export`)
18+
- Run `devtools::document()` after modifying roxygen comments
19+
- Run `devtools::test()` before committing
20+
21+
## Dependencies
22+
23+
- Check `DESCRIPTION` Imports before using any package
24+
- For new dependencies: `usethis::use_package("pkg")`
25+
- Use explicit namespaces: `dplyr::filter(x > 0)` not `filter(x > 0)`
26+
27+
## Testing
28+
29+
- Test file names match source: `R/foo.R``tests/testthat/test-foo.R`
30+
- Use `describe` and `it` functions
31+
- Include value-level assertions, not just structure checks
32+
- Use test data from `tests/testthat/setup.R` where appropriate
33+
34+
## Anti-patterns
35+
36+
- Do not edit `man/` or `NAMESPACE` files manually
37+
- Do not add unused `globalVariables` to `R/zzz.R`
38+
- Do not push without running `devtools::document()` first
39+
- Do not skip tests or lintr checks
40+
41+
## PR Workflow
42+
43+
- Branch name: `<issue-number>-<type>/<short-description>`
44+
- Before submitting: bump version, update NEWS.md
45+
- Link issue with `Closes #<number>` in PR description
46+
- Add at least 2 core team reviewers (from DESCRIPTION)
47+
48+
## CI Checks
49+
50+
All PRs must pass: lintr, unit tests, test coverage, man page generation, and spell check.
51+
52+
## Additional Context
53+
54+
See `AGENTS.md` for full development guidelines.
55+
See `.github/instructions/` for path-specific coding conventions.
56+
See `.github/skills/` for reusable agent workflows.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
applyTo: "R/**/*.R"
3+
---
4+
5+
# R Package Code
6+
7+
## File naming
8+
9+
- One main function per file: `R/my_function.R`
10+
- Match file name to function: `positive_mean()``positive_mean.R`
11+
- Utilities: `R/utils.R` for small helpers
12+
13+
## Dependencies
14+
15+
- Check `DESCRIPTION` Imports before using any package
16+
- For new dependencies: `usethis::use_package("pkg")`
17+
- Use explicit namespaces in code: `dplyr::filter(x > 0)` not `filter(x > 0)`
18+
- No `library()` or `require()` in package code
19+
20+
## Documentation (roxygen2)
21+
22+
All exported functions must have `@param`, `@returns`, and `@export`:
23+
24+
```r
25+
#' Calculate mean of positive values
26+
#'
27+
#' @param x A numeric vector.
28+
#' @param na.rm Logical. Remove NA values? Default `TRUE`.
29+
#'
30+
#' @returns A single numeric value.
31+
#' @export
32+
#'
33+
#' @examples
34+
#' positive_mean(c(-1, 2, 3, NA))
35+
positive_mean <- function(x, na.rm = TRUE) {
36+
x <- x[x > 0]
37+
mean(x, na.rm = na.rm)
38+
}
39+
```
40+
41+
Run `devtools::document()` after modifying roxygen comments.
42+
43+
## Global variables (`R/zzz.R`)
44+
45+
Use for non-standard evaluation (NSE) column references:
46+
47+
```r
48+
utils::globalVariables(c("DOSEA", "TRT01A", "GROUP"))
49+
```
50+
51+
- Only for code in `R/`, not in `inst/shiny/`
52+
- Keep alphabetically sorted, no duplicates
53+
54+
## Anti-patterns
55+
56+
- Do not edit `man/` or `NAMESPACE` files manually
57+
- Do not add unused globalVariables to `R/zzz.R`
58+
- Do not push without running `devtools::document()` first
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
applyTo: "inst/shiny/**"
3+
---
4+
5+
# Shiny App Code
6+
7+
## Module communication
8+
9+
- `session$userData$results` — computed results (CDISC datasets, NCA results)
10+
- `session$userData$project_name()` — reactive, auto-populated from STUDYID
11+
- `session$userData$slope_rules()` — reactive (non-nested)
12+
- Data flows: `data_upload_server``adnca_raw``tab_data_server``tab_nca_server`
13+
14+
## Export / ZIP (`tab_nca/zip.R`)
15+
16+
- `TREE_LIST` defines export structure
17+
- `input$res_tree` returns selected items as text names
18+
- Zip filename: `ProjectName.zip` or fallback `NCA_STUDYID.zip`
19+
- Pre-Specs sheets auto-generated from CDISC data, filtered to exported variables
20+
21+
## Exploration plots
22+
23+
- Default color_by priority: `DOSEA > TRT01A > GROUP > ACTARM > COHORT`
24+
- Default facet_by priority: `TRT01A > DOSEA > GROUP > ACTARM > COHORT`
25+
- Auto-mapping includes: `COHORT`, `PART`, `PERIOD`
26+
27+
## CSS caveat
28+
29+
`inst/shiny/www/main.css` has `--_sidebar-width: 170px !important`
30+
31+
To change sidebar width, modify the CSS variable, not the R parameter.
32+
33+
## Anti-patterns
34+
35+
- Do not add `globalVariables` here; place them only in `R/zzz.R`
36+
- Agents cannot run or visually debug the Shiny app; test UI changes manually
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
applyTo: "tests/**"
3+
---
4+
5+
# Testing
6+
7+
## File structure
8+
9+
- Test file names match source: `R/foo.R``tests/testthat/test-foo.R`
10+
- Use `describe` and `it` functions
11+
- Include value-level assertions, not just structure checks
12+
- Use the test data created in `tests/testthat/setup.R` where appropriate
13+
14+
## Example
15+
16+
```r
17+
describe("g_lineplot: structure and arguments", {
18+
it("returns a ggplot object with individual labels", {
19+
p <- g_lineplot(
20+
data = ind_data,
21+
x_var = "time_var",
22+
y_var = "AVAL",
23+
x_unit = "RRLTU",
24+
y_unit = "AVALU",
25+
color_by = "USUBJID"
26+
)
27+
expect_s3_class(p, "ggplot")
28+
expect_equal(p$labels$title, "PK Concentration - Time Profile")
29+
expect_equal(p$labels$y, "Concentration [ng/mL]")
30+
expect_equal(p$labels$x, "Time [hours]")
31+
expect_equal(p$labels$colour, "USUBJID")
32+
})
33+
34+
it("applies faceting", {
35+
p <- g_lineplot(
36+
data = ind_data,
37+
x_var = "time_var",
38+
y_var = "AVAL",
39+
color_by = "USUBJID",
40+
facet_by = "PARAM"
41+
)
42+
expect_s3_class(p$facet, "FacetWrap")
43+
})
44+
})
45+
```
46+
47+
## CI Checks
48+
49+
All PRs must pass:
50+
51+
- Code passes lintr checks
52+
- Code passes all unit tests
53+
- New logic covered by unit tests
54+
55+
Run tests with: `devtools::test()`

0 commit comments

Comments
 (0)