Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: saber
Type: Package
Title: Context Engineering for Large Language Model Agents
Version: 0.7.1
Version: 0.7.1.1
Authors@R: c(
person("Troy", "Hernandez", role = c("aut", "cre"),
email = "troy@cornball.ai",
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# saber 0.7.1.1

## Changes

- `fn_graph()` now accepts `cache_dir`, mirroring `blast_radius()` and
`symbols()`. The default is unchanged. The example and tinytest pass
`tempdir()` so R CMD check no longer leaves files under
`tools::R_user_dir("saber", "cache")`.

# saber 0.7.1

## Changes
Expand Down
11 changes: 8 additions & 3 deletions R/fn_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#' functions called from other packages. Default \code{FALSE}.
#' @param ... Passed through to \code{\link{graph_svg}} (e.g.,
#' \code{width}, \code{height}, \code{iterations}, \code{seed}).
#' @param cache_dir Directory for the underlying \code{\link{symbols}}
#' cache. Pass \code{tempdir()} (or any non-default path) when running
#' examples / tests to avoid writing to the user's persistent cache.
#' Name-only argument — must be passed by name.
#' @return Character vector of SVG lines. Write with \code{writeLines()}.
#' @examples
#' d <- file.path(tempdir(), "fngdemo")
Expand All @@ -22,11 +26,12 @@
#' writeLines("add <- function(x, y) x + y", file.path(d, "R", "add.R"))
#' writeLines("double <- function(x) add(x, x)",
#' file.path(d, "R", "double.R"))
#' svg <- fn_graph(d)
#' svg <- fn_graph(d, cache_dir = tempdir())
#' writeLines(svg, tempfile(fileext = ".svg"))
#' @export
fn_graph <- function(project_dir, include_external = FALSE, ...) {
idx <- symbols(project_dir)
fn_graph <- function(project_dir, include_external = FALSE, ...,
cache_dir = file.path(tools::R_user_dir("saber", "cache"), "symbols")) {
idx <- symbols(project_dir, cache_dir = cache_dir)
defs <- idx$defs
calls <- idx$calls

Expand Down
2 changes: 1 addition & 1 deletion inst/tinytest/test_fn_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ writeLines(c("Package: demo", "Version: 0.1.0"), file.path(d, "DESCRIPTION"))
writeLines("add <- function(x, y) x + y", file.path(d, "R", "add.R"))
writeLines("double <- function(x) add(x, x)", file.path(d, "R", "double.R"))

svg <- fn_graph(d)
svg <- fn_graph(d, cache_dir = tempdir())
expect_true(is.character(svg))
expect_true(any(grepl("^<svg", svg)))
# Tooltips carry name + file:line + visibility + degree
Expand Down
10 changes: 8 additions & 2 deletions man/fn_graph.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
\alias{fn_graph}
\title{Code intelligence: function call graph}
\usage{
fn_graph(project_dir, include_external = FALSE, ...)
fn_graph(project_dir, include_external = FALSE, ...,
cache_dir = file.path(tools::R_user_dir("saber", "cache"), "symbols"))
}
\arguments{
\item{project_dir}{Path to the project directory (an R package root).}
Expand All @@ -13,6 +14,11 @@ functions called from other packages. Default \code{FALSE}.}

\item{...}{Passed through to \code{\link{graph_svg}} (e.g.,
\code{width}, \code{height}, \code{iterations}, \code{seed}).}

\item{cache_dir}{Directory for the underlying \code{\link{symbols}}
cache. Pass \code{tempdir()} (or any non-default path) when running
examples / tests to avoid writing to the user's persistent cache.
Name-only argument — must be passed by name.}
}
\value{
Character vector of SVG lines. Write with \code{writeLines()}.
Expand All @@ -34,6 +40,6 @@ writeLines(c("Package: demo", "Version: 0.1.0"),
writeLines("add <- function(x, y) x + y", file.path(d, "R", "add.R"))
writeLines("double <- function(x) add(x, x)",
file.path(d, "R", "double.R"))
svg <- fn_graph(d)
svg <- fn_graph(d, cache_dir = tempdir())
writeLines(svg, tempfile(fileext = ".svg"))
}