AGENTS.md
Guidance for everyone working on this repository: the maintainer, collaborators, and any AI coding agents working for them. It covers how to work here: conventions, unpublished material, and checks.
Five places divide the documentation:
| Where | Covers |
|---|---|
analysis-plan.md |
Study design: what the cost-effectiveness analysis is meant to do |
ARCHITECTURE.md |
Code structure: scripts, data flow, and the objects passed between them |
AGENTS.md (this file) |
How to work in the repository: rules, conventions, and checks |
| GitHub Issues | Open design decisions (one decision issue per Decision Dn) |
TODO.md |
Implementation status: where the code does not yet match the plan, and known defects |
Read the three files before making changes. Each covers its own topic and does not repeat the others. The evidence for every model input is in references/literature-review.md, with citations in references.bib.
The project
This repository evaluates donor serum cryptococcal antigen (CrAg) screening in US deceased-donor kidney transplantation with a decision-analytic cost-effectiveness model, and it publishes its code, methods and results as a Quarto website.
analysis-plan.mdis the source of truth for design. It covers the comparators, population, unit of analysis, perspective, time horizon, model structure, input definitions, and sensitivity analyses. Code implements the plan; it does not redefine it.- If the code needs to depart from the plan, change the plan in the same pull request.
- Plan changes are tracked in git, not in a change log inside the plan. Commit each design change on its own, with a message that gives the reason and says whether any results that depend on it had already been seen.
- The plan lists open design choices as Decision Dn in its “Open decisions” table, each linked to its decision issue. Options and evidence go in the issue. Do not settle one in code. Raise it with the decider.
- Deciders. Scientific decisions are made by Vagish Hemmige (all areas). Anyone may contribute options and evidence to an open decision; only a decider settles it (see “Working with agents”).
- This is an analysis project, not an R package, even though the scripts live in
R/and there is an.Rbuildignore. Do not add DESCRIPTION, NAMESPACE, roxygen, or {pkgdown} infrastructure. Do not apply CRAN conventions. - Default branch:
master, protected. Changes reach it only through pull requests. - Implementation status lives in
TODO.md, not in these files. When you find a gap between the code and the plan, or a defect, add it there. When an item is done, delete it and record the outcome in the code, the plan or the evidence page.
Data sources
This project uses no data set. Its inputs are values taken from published literature, guidelines and registry reports, and every one is entered as a named constant in R/setup.R.
| Source | Accessed through | Package documentation | Package maintained by | Access | What AI agents may do |
|---|---|---|---|---|---|
Published literature, guidelines and registry reports, as listed in references/literature-review.md |
No package: values entered by hand in R/setup.R |
— | — | Public (paywalled full texts are not copied into the repository) | No restriction on the published values; follow “Unpublished material” below |
| Inputs that rest on unpublished data | No package: values entered by hand in R/setup.R, described as “source to be documented” |
— | — | Not public | None beyond the values already in R/setup.R; never add the underlying material |
To allow more for a source, a person changes its row through a pull request, naming the agreement or permission that allows it and exactly what agents may do. Agents never propose or make this change themselves.
For a source with no package: record each value’s source, release or access date, and any processing in references/literature-review.md, and check it against the original publication.
Exploration and definitive analysis
Exploration is welcome on branches or forks. Experimental scripts need not be sourced from R/main.R or have Quarto pages, and their findings are labelled preliminary. A script becomes part of the definitive analysis when it is sourced from R/main.R; from then on every rule below applies to it.
R scripts
- Running the analysis. Open the
.Rprojand runR/main.Rfrom the project root.main.Rsources the other scripts in dependency order.ARCHITECTURE.mddescribes what each script does and how data flows between them. - One job per script: setup, model functions, base case, scenarios, sensitivity analyses. When you add a script:
- source it from
main.Rat the right point - update
ARCHITECTURE.mdin the same commit
- source it from
- Header comment. Each script begins with a comment saying what it does and which objects it needs from earlier scripts.
- Constants, libraries, and model inputs live in
R/setup.R. Other scripts do not calllibrary(), re-sourcesetup.R, or hard-code values. Any number a reader might want to change, such as an input’s base value or distribution shape, the willingness-to-pay threshold, the seed, or the number of PSA draws, is a named constant insetup.R. - Helper functions go in
R/functions.R, sourced aftersetup.R. A function takes its inputs as arguments and does not read global objects, including through default arguments. - No side effects outside the project. Do not use
setwd(), absolute paths, or writes outside the project. - Exploration code does not stay in pipeline scripts. Delete it, or move it below a chunk label that no Quarto page uses. The website shows the scripts as they are.
Chunk labels
Scripts are divided into labelled sections, so that Quarto pages can show the code without copying it:
## ---- calculate-cost-qaly- Every logical step has a label. A label covers the code from its line to the next label.
- Labels are kebab-case, describe the step, and are unique across all scripts. Quarto pulls chunks by label, so a duplicate label silently picks up the wrong code.
- Renaming or deleting a label breaks the Quarto page that uses it. Search the
.qmdfiles before you change one. - Scripts must still run end to end through
main.R. Labels are comments and must never change what the code does.
Quarto website
The Quarto site documents the code and displays results. It does not run the model.
- Setup files:
_quarto.yml,index.qmd,404.qmd(the page GitHub Pages shows for a missing address) andstyles.csssit at the root. There is one page per pipeline script inquarto/, named after the script (for example,quarto/sensitivity_analyses.qmdforR/sensitivity_analyses.R), plus the background, methods, results, About and project-document pages. Thecustom-calloutextension in_extensions/provides theRcode,ResultsandPendingcallouts._quarto.ymlhas an explicit render list; a page that is not on it is not published. - Visual cues. Each kind of page has one sidebar icon, coloured by
styles.css, and pages mark the same kind of content with the callout of that colour: backgroundbook(blue); study design and methodsdiagram-3(orange); R codelaptop(pink,Rcode💻); resultsclipboard-data(green,Results📊); project documentsfile-earmark-ruled(grey). Give every new page the icon of its kind. - Provisional content.
quarto/_pending.luahighlights in yellow every paragraph that starts with Decision pending: or, in the plan, contains Open:, and any[text]{.pending}, and adds a ⏳Pendingcallout to pages that have a mark. Mark only what an open decision could change, and remove the mark when the decision is settled. - Project documents.
analysis-plan.md,ARCHITECTURE.md,AGENTS.mdandREPOSITORY-BLUEPRINT.mdare shown on the site by pages inquarto/that only include the root file, which stays the one source: edit the root file, not the page. - Showing code: each code page loads its script with
knitr::read_chunk("../R/<script>.R")in a hidden chunk. It then shows each labelled section in a chunk with#| eval: false, with prose explaining what the section does and why. Pages link to the script on GitHub and to the scripts it depends on. - Results come from saved outputs. Results pages read
output/andfigures/, and methods pages evaluate only the parameter chunks ofR/setup.R. Every number shown on a page comes from those files, never typed into the prose. - Rendering: the site renders to
docs/, which is not committed..github/workflows/publish.ymlrenders it on every pull request as a check and, on each push tomaster, publishes it to thegh-pagesbranch, which GitHub Pages serves. The workflow does not run the model, so after any change toR/, rerunR/main.Rand commitoutput/,figures/andtables/in the same pull request. Render locally to preview, but do not commit the output. - New scripts: when you add a script, add its page and its sidebar entry in
_quarto.ymlin the same commit. - Prose must match the code. If a change alters what a section does, update that section’s explanation in the same pull request.
Outputs
- Exported files: results are written by the pipeline to
output/(CSV),figures/andtables/. These folders are tracked, because the website reads them. Commit them together with the code that they belong to; the site is rendered from them when the change reachesmaster. - Figures need alt text when they are published.
README.Rmdis the source ofREADME.md. Edit the.Rmdand re-knit; do not editREADME.mddirectly.
Unpublished material (applies to everyone)
The repository and website are public. The rules below apply to people and agents alike.
- Never commit unpublished material. That includes manuscript drafts, reviewer or co-author comments, data obtained by personal communication or from an organization without permission to publish, unpublished case reports, patient-level information, and copies of or long quotations from paywalled articles. Keep such material outside the repository.
- An input that rests on unpublished data is described as “source to be documented” until there is permission to cite it.
- Never commit credentials, tokens, or local
.Renvironfiles.
Coding conventions
- Probabilities
- At every chance node, branch probabilities sum to 1. Complements are computed in code (
1 - p), never entered as inputs. Every pathway ends in exactly one terminal node. - The model is defined once. While the pathway table exists in both
calculate_cost_QALY_QC()andcreate_tree_diagram_QC()(ARCHITECTURE.md), a structural change goes into both, and the two must give the same base-case result.
- At every chance node, branch probabilities sum to 1. Complements are computed in code (
- Unit of analysis. Every result is per the unit the plan defines. An aggregate (for example a cohort total) is an explicit multiplication in code, labelled with its multiplier.
- Distributions
- Each input’s family follows the plan: Beta for probabilities, gamma or log-normal for nonnegative costs, and a distribution that allows negative values for any quantity that can be negative.
- Check that a distribution’s parameterization reproduces its intended mean and interval.
- Inputs are drawn independently unless the plan specifies joint sampling. A draw that feeds a complement must keep every branch within 0 to 1.
- Costs carry their price year. Inflation adjustment uses the constants in
setup.R. Costs, payments and charges are not mixed. - Simulation. The PSA must be reproducible from the seed and number of draws recorded in
setup.R. The tornado, acceptability curve, EVPI and cost-effectiveness plane use the same inputs, threshold and NMB formula. - Evidence. Every input value and range traces to
references/literature-review.md. Never invent parameter values, sources, citations or clinical definitions. Add new citations toreferences.bibwith author-year keys. - Style: the tidyverse style guide. Style changes go in their own commits, separate from changes that alter analytical behavior.
Checks for any change
Before opening a pull request, check the items below that apply to your change.
Model structure
- Do branch probabilities sum to 1 at every node, with complements computed?
- If the tree changed, were both pathway tables changed, and do they agree?
- Is the unit of analysis the same in the tree, inputs, outputs and website text?
- Do both strategies share the same baseline organ nonuse, so that only nonuse caused by a positive screen is attributed to screening?
- Are true-positive and false-positive paths handled separately for cancellation and prophylaxis?
- Do the scenario trees differ from the base case only in the inputs their descriptions name?
Inputs
- Do the values in
setup.Rmatch the evidence page and the website? - Is any input hard-coded outside
setup.R? - Does each distribution fit its support and reproduce its intended mean and interval?
- Do all costs share one price year and one index?
- Are all terminal QALYs and costs measured against the same reference endpoint?
Limiting cases (run them)
- Prevalence 0: screening adds the test cost and false-positive consequences only.
- Sensitivity 1 and specificity 1: no false negatives or false positives.
- Cancellation 0 and prophylaxis efficacy 0: screening has no effect on QALYs.
- A small tree reproduced by hand gives the same expected values.
Sensitivity analyses
- Does each tornado input vary alone over its stated range, with others at base values, and do its endpoints match direct reruns?
- Is the PSA mean close to the deterministic base case?
- Are the summaries computed from the same draws?
Structure and documentation
- Does
ARCHITECTURE.mdstill describe the scripts and the data flow? - Are the chunk labels unique, and does each script’s Quarto page still find every label it uses?
- Does every script have a Quarto page and a sidebar entry, were
output/,figures/andtables/regenerated by rerunningmain.R, and does the pull request’s render check pass? - Are all code-page chunks
eval: false?
Execution
- Does
main.Rrun from a clean session (Ctrl+Shift+F10in RStudio, then sourcemain.R), with no objects left over from earlier work? - Are paths relative?
- Is every package the code uses loaded in
setup.R, and are package versions recorded? - Are
output/,figures/andtables/current with the code?
Working with agents
- Autonomy. The person directing an agent sets its working style (review only, step by step, or hands-off) in their own instructions, and may add stricter rules; those take precedence. Without a style, an agent works step by step. At most, an agent may edit code and documentation, add scripts and tests, run code and render the site, and commit to a branch and open a pull request.
- Collaborators:
masteris protected. Changes reach it only through a pull request that the maintainer reviews. - Decisions. Anyone, including an agent, may add options and evidence to an open decision. A decider states the choice. Agents implement decisions; they never choose among options on their own, in the plan or the code.
- Every agent, under any level of autonomy:
- never merges a pull request
- follows the unpublished-material rules above
- asks before running the full pipeline (including the full PSA) or making expensive calls
- shows a person the exact text before posting or sending anything as them, unless that person’s own instructions waive this
- proposes another way of writing something already agreed before committing it
- Keep pull requests focused. In each one, state which section of the plan or which
TODO.mditem it addresses, and what was checked. Say whether it was checked by running code or by reading only. Never describe results from a reduced number of PSA draws as results. - For references, use OPTN/SRTR, CDC, AST and global cryptococcosis guidelines, FDA labeling, USRDS, and PubMed. Cite what you used.