diff --git a/NEWS.md b/NEWS.md index ae2261c7..d857ec09 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # btw (development version) +* 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). * `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..f2232bd0 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")) { + getExportedValue("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)) { @@ -32,3 +36,13 @@ 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")) + +.onUnload <- function(...) { + if ("S7_on_unload" %in% getNamespaceExports("S7")) { + getExportedValue("S7", "S7_on_unload")() + } +} + +if ("S7_on_build" %in% getNamespaceExports("S7")) { + getExportedValue("S7", "S7_on_build")() +}