[mirror] Opinionated R package quickstart
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add AGENTS file

VisruthSK 9eb4ad81 aa4c38f8

+103 -12
+15
AGENTS.md
··· 1 + # General Rules 2 + First run the tests. 3 + red/green TDD. Add tests using usethis::use_test() 4 + Read DESCRIPTION and README.md. 5 + 6 + # Personality 7 + Use literal, direct, concise, specific, high signal, non-empathic, highly structured language. Don't hedge. Don't both sides issues. Don't ask questions at the end of the turn. Don't make offers at the end of the turn. 8 + Only ask questions if it is a request for information necessary for a previous request 9 + 10 + # R Package Development Rules 11 + Never edit .Rd files or NAMESPACE directly. 12 + Use devtools::document(), devtools::test(), devtools::check() for redoc, tests, R CMD CHECK 13 + Try not to add new dependencies unless the code would be much cleaner/faster/better--note added deps to me. Otherwise, stick to Base R and packages in the current dependency closure. 14 + Use usethis::use_import_from() or usethis::use_package() to add dependencies 15 + Make sure air format ., jarl check . --fix --allow-dirty, all tests, and R CMD check pass before you claim to be done.
+43 -9
R/bootstrapper.R
··· 8 8 #' @param private Whether to create the GitHub repository as private. Defaults to `TRUE`. 9 9 #' @param setup_gha Whether to configure GitHub Actions setup. 10 10 #' @param setup_dependabot Whether to write a Dependabot configuration. 11 + #' @param setup_AGENTS Whether to write a default AGENTS file. 11 12 #' @param ... Additional arguments passed to [usethis::create_package()]. 12 13 #' 13 14 #' @return Invisibly returns `NULL`. ··· 18 19 private = TRUE, 19 20 setup_gha = TRUE, 20 21 setup_dependabot = TRUE, 22 + setup_AGENTS = FALSE, 21 23 ... 22 24 ) { 23 25 create_package(path, fields, private, ...) 24 26 pkg_setup( 25 27 setup_gha = setup_gha, 26 - setup_dependabot = setup_dependabot 28 + setup_dependabot = setup_dependabot, 29 + setup_AGENTS = setup_AGENTS 27 30 ) 28 31 invisible(NULL) 29 32 } ··· 84 87 #' 85 88 #' @param setup_gha Whether to configure GitHub Actions setup. 86 89 #' @param setup_dependabot Whether to write a Dependabot configuration. 90 + #' @param setup_AGENTS Whether to write a default AGENTS file. 87 91 #' 88 92 #' @return Invisibly returns `NULL`. 89 93 #' @export 90 94 pkg_setup <- function( 91 95 setup_gha = TRUE, 92 - setup_dependabot = TRUE 96 + setup_dependabot = TRUE, 97 + setup_AGENTS = FALSE 93 98 ) { 94 99 tryCatch( 95 100 usethis::use_testthat(), ··· 109 114 ) 110 115 111 116 if (setup_gha) { 112 - configure_gha() 117 + setup_gha() 113 118 } 114 119 if (setup_dependabot) { 115 - configure_dependabot() 120 + setup_dependabot() 121 + } 122 + if (setup_AGENTS) { 123 + setup_AGENTS() 116 124 } 117 125 118 126 try_air_jarl_format() ··· 166 174 #' @return Invisibly returns `NULL`. 167 175 #' @keywords internal 168 176 #' @noRd 169 - configure_gha <- function() { 177 + setup_gha <- function() { 170 178 usethis::use_github_action("check-standard", badge = TRUE) 171 179 usethis::use_github_action("test-coverage", badge = TRUE) 172 180 usethis::use_github_action( ··· 196 204 "extend-select = [\"TESTTHAT\"]" 197 205 ) |> 198 206 write_to_path(fs::path("tests", "jarl.toml")) # TODO: need to make GHA jarl runs respect this 199 - 200 - invisible(NULL) 201 207 } 202 208 203 209 #' Configure Dependabot Defaults ··· 207 213 #' @return Invisibly returns `NULL`. 208 214 #' @keywords internal 209 215 #' @noRd 210 - configure_dependabot <- function() { 216 + setup_dependabot <- function() { 211 217 c( 212 218 "version: 2", 213 219 "updates:", ··· 217 223 " interval: \"weekly\"" 218 224 ) |> # TODO: move file to inst? 219 225 write_to_path(fs::path(".github", "dependabot.yml")) 220 - invisible(NULL) 226 + } 227 + 228 + #' Configure AGENTS Defaults 229 + #' 230 + #' Placeholder for AGENTS file setup. 231 + #' 232 + #' @return Invisibly returns `NULL`. 233 + #' @keywords internal 234 + #' @noRd 235 + setup_agents <- function() { 236 + # See https://simonwillison.net/guides/agentic-engineering-patterns/ 237 + c( 238 + "# General Rules", 239 + "First run the tests.", 240 + "red/green TDD. Add tests using usethis::use_test()", 241 + "Read DESCRIPTION and README.md.", 242 + "", 243 + "# Personality", 244 + "Use literal, direct, concise, specific, high signal, non-empathic, highly structured language. Don't hedge. Don't both sides issues. Don't ask questions at the end of the turn. Don't make offers at the end of the turn.", 245 + "Only ask questions if it is a request for information necessary for a previous request", 246 + "", 247 + "# R Package Development Rules", 248 + "Never edit .Rd files or NAMESPACE directly.", 249 + "Use devtools::document(), devtools::test(), devtools::check() for redoc, tests, R CMD CHECK", 250 + "Try not to add new dependencies unless the code would be much cleaner/faster/better--note added deps to me. Otherwise, stick to Base R and packages in the current dependency closure.", 251 + "Use usethis::use_import_from() or usethis::use_package() to add dependencies", 252 + "Make sure air format ., jarl check . --fix --allow-dirty, all tests, and R CMD check pass before you claim to be done." 253 + ) |> 254 + write_to_path(fs::path("AGENTS.md")) 221 255 } 222 256 223 257
+3
man/bootstrapper.Rd
··· 10 10 private = TRUE, 11 11 setup_gha = TRUE, 12 12 setup_dependabot = TRUE, 13 + setup_AGENTS = FALSE, 13 14 ... 14 15 ) 15 16 } ··· 24 25 \item{setup_gha}{Whether to configure GitHub Actions setup.} 25 26 26 27 \item{setup_dependabot}{Whether to write a Dependabot configuration.} 28 + 29 + \item{setup_AGENTS}{Whether to write a default AGENTS file.} 27 30 28 31 \item{...}{Additional arguments passed to \code{\link[usethis:create_package]{usethis::create_package()}}.} 29 32 }
+3 -1
man/pkg_setup.Rd
··· 4 4 \alias{pkg_setup} 5 5 \title{Apply Opinionated Package Setup} 6 6 \usage{ 7 - pkg_setup(setup_gha = TRUE, setup_dependabot = TRUE) 7 + pkg_setup(setup_gha = TRUE, setup_dependabot = TRUE, setup_AGENTS = FALSE) 8 8 } 9 9 \arguments{ 10 10 \item{setup_gha}{Whether to configure GitHub Actions setup.} 11 11 12 12 \item{setup_dependabot}{Whether to write a Dependabot configuration.} 13 + 14 + \item{setup_AGENTS}{Whether to write a default AGENTS file.} 13 15 } 14 16 \value{ 15 17 Invisibly returns \code{NULL}.
+39 -2
tests/testthat/test-bootstrapper.R
··· 10 10 expect_identical(list(...), list(open = FALSE)) 11 11 NULL 12 12 }, 13 - pkg_setup = function(setup_gha, setup_dependabot) { 13 + pkg_setup = function(setup_gha, setup_dependabot, setup_AGENTS) { 14 14 calls <<- c(calls, "pkg_setup") 15 15 expect_false(setup_gha) 16 16 expect_false(setup_dependabot) 17 + expect_false(setup_AGENTS) 17 18 NULL 18 19 }, 19 20 .package = "bootstrapper" ··· 118 119 calls$sections <<- c(calls$sections, "dependabot") 119 120 NULL 120 121 }, 122 + configure_agents = function() { 123 + calls$sections <<- c(calls$sections, "agents") 124 + NULL 125 + }, 121 126 find_replace_in_file = function(from, to, file, fixed = TRUE) { 122 127 calls$replaced <<- TRUE 123 128 expect_identical(from, "(development version)") ··· 165 170 called <<- TRUE 166 171 NULL 167 172 }, 173 + configure_agents = function() { 174 + called <<- TRUE 175 + NULL 176 + }, 168 177 find_replace_in_file = function(from, to, file, fixed = TRUE) NULL, 169 178 try_air_jarl_format = function() { 170 179 formatted <<- TRUE ··· 176 185 expect_null( 177 186 bootstrapper::pkg_setup( 178 187 setup_gha = FALSE, 179 - setup_dependabot = FALSE 188 + setup_dependabot = FALSE, 189 + setup_AGENTS = FALSE 180 190 ) 181 191 ) 182 192 expect_false(called) 183 193 expect_true(formatted) 194 + }) 195 + 196 + test_that("pkg_setup runs AGENTS setup when enabled", { 197 + called <- FALSE 198 + 199 + testthat::local_mocked_bindings( 200 + use_testthat = function() NULL, 201 + use_readme_md = function(open = FALSE) NULL, 202 + use_news_md = function(open = FALSE) NULL, 203 + use_tidy_description = function() NULL, 204 + .package = "usethis" 205 + ) 206 + 207 + testthat::local_mocked_bindings( 208 + configure_gha = function() NULL, 209 + configure_dependabot = function() NULL, 210 + configure_agents = function() { 211 + called <<- TRUE 212 + NULL 213 + }, 214 + find_replace_in_file = function(from, to, file, fixed = TRUE) NULL, 215 + try_air_jarl_format = function() NULL, 216 + .package = "bootstrapper" 217 + ) 218 + 219 + expect_null(bootstrapper::pkg_setup(setup_AGENTS = TRUE)) 220 + expect_true(called) 184 221 }) 185 222 186 223 test_that("configure_gha runs expected usethis, replacement, and air/jarl calls", {