From f1b634cfede03d36c0cd4ecfc8bde319651a50c4 Mon Sep 17 00:00:00 2001 From: Tomasz Kalinowski Date: Mon, 12 Oct 2026 10:42:26 -0400 Subject: [PATCH 1/4] Fix context construction and generic bindings with development S7 --- NEWS.md | 2 ++ R/btw.R | 2 +- R/zzz.R | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index ae2261c7..1a8a1a3c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # btw (development version) +* `btw()` now handles empty context and package NEWS with development S7. + * `path_find_in_project()` now stops its upward search when it reaches the home directory (either `fs::path_home()` or `fs::path_home_r()`, which differ on Windows) and never treats files there as project files, so `~/AGENTS.md` or `~/CLAUDE.md` are no longer picked up as project context when the working directory is under `~` but outside a project. Home-level files are handled only by the user-level lookup. This also fixes `~/btw.md` instructions being included twice — once as the project file and once as the user-level config (#225). * `btw_client(path_btw = ...)` no longer duplicates instructions when `path_btw` is set explicitly to the same file as the user-level `btw.md` (#225). diff --git a/R/btw.R b/R/btw.R index 73cf62c5..32b3e740 100644 --- a/R/btw.R +++ b/R/btw.R @@ -102,7 +102,7 @@ btw <- function(..., clipboard = TRUE) { if (identical(res, "")) { cli::cli_alert_warning("Nothing to include in the btw() context.") - return(invisible(BTW(""))) + return(invisible(BTW(text = ""))) } BTW(text = res, settings = env(clipboard = clipboard)) diff --git a/R/zzz.R b/R/zzz.R index 497c5417..3b6725ad 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -32,3 +32,7 @@ if (getRversion() < "4.3.0") { # R6 binds `self` and `super` at runtime; declare them so codetools doesn't # flag them as global variables in R CMD check. utils::globalVariables(c("private", "self", "super")) + +if (utils::packageVersion("S7") >= "0.2.2.9000") { + S7::S7_on_build() +} From ec4ad3e17140903b66face33222e811e6ff17828 Mon Sep 17 00:00:00 2001 From: Tomasz Kalinowski Date: Tue, 13 Oct 2026 16:52:00 -0400 Subject: [PATCH 2/4] docs: Simplify S7 compatibility release note --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 1a8a1a3c..d857ec09 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # btw (development version) -* `btw()` now handles empty context and package NEWS with development S7. +* Updates for compatibility with S7 > 0.2.2. * `path_find_in_project()` now stops its upward search when it reaches the home directory (either `fs::path_home()` or `fs::path_home_r()`, which differ on Windows) and never treats files there as project files, so `~/AGENTS.md` or `~/CLAUDE.md` are no longer picked up as project context when the working directory is under `~` but outside a project. Home-level files are handled only by the user-level lookup. This also fixes `~/btw.md` instructions being included twice — once as the project file and once as the user-level config (#225). From ea6990f207ab97ed95969e3886cc0c00f8c667f8 Mon Sep 17 00:00:00 2001 From: Tomasz Kalinowski Date: Wed, 14 Oct 2026 10:49:22 -0400 Subject: [PATCH 3/4] fix: register S7 package lifecycle hooks --- R/zzz.R | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 3b6725ad..0efac44b 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,6 +1,10 @@ .onLoad <- function(libname, pkgname) { # run_on_load() - S7::methods_register() + if ("S7_on_load" %in% getNamespaceExports("S7")) { + S7::S7_on_load() + } else { + S7::methods_register() + } pkg_env <- rlang::fn_env(btw_tools) for (tool_def in as_ellmer_tools(.btw_tools, force = TRUE)) { @@ -33,6 +37,12 @@ if (getRversion() < "4.3.0") { # flag them as global variables in R CMD check. utils::globalVariables(c("private", "self", "super")) -if (utils::packageVersion("S7") >= "0.2.2.9000") { +.onUnload <- function(...) { + if ("S7_on_unload" %in% getNamespaceExports("S7")) { + S7::S7_on_unload() + } +} + +if ("S7_on_build" %in% getNamespaceExports("S7")) { S7::S7_on_build() } From 377d60f9cd20dbca26e7cf95f97d76590d483635 Mon Sep 17 00:00:00 2001 From: Tomasz Kalinowski Date: Fri, 16 Oct 2026 10:11:49 -0400 Subject: [PATCH 4/4] fix: resolve optional S7 hooks dynamically --- R/zzz.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 0efac44b..f2232bd0 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,7 +1,7 @@ .onLoad <- function(libname, pkgname) { # run_on_load() if ("S7_on_load" %in% getNamespaceExports("S7")) { - S7::S7_on_load() + getExportedValue("S7", "S7_on_load")() } else { S7::methods_register() } @@ -39,10 +39,10 @@ utils::globalVariables(c("private", "self", "super")) .onUnload <- function(...) { if ("S7_on_unload" %in% getNamespaceExports("S7")) { - S7::S7_on_unload() + getExportedValue("S7", "S7_on_unload")() } } if ("S7_on_build" %in% getNamespaceExports("S7")) { - S7::S7_on_build() + getExportedValue("S7", "S7_on_build")() }