Skip to content

cleanup and submit#6

Merged
egenn merged 1 commit into
mainfrom
devel
Apr 29, 2026
Merged

cleanup and submit#6
egenn merged 1 commit into
mainfrom
devel

Conversation

@egenn
Copy link
Copy Markdown
Member

@egenn egenn commented Apr 29, 2026

No description provided.

Co-authored-by: Copilot <copilot@github.com>
Copilot AI review requested due to automatic review settings April 29, 2026 01:33
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the handling of the logfile parameter across the Agent class and security utilities. It simplifies the resolution logic in the generate method by removing the default fallback and updates the Agent class definition to require a character value for the logfile field. Documentation has been updated to reflect these changes and the CRAN policy regarding temporary files. Feedback was provided to include validation for the resolved logfile in the generate method to ensure it is a scalar character, preventing late-stage failures.

Comment thread r/R/07_Agent.R
@egenn egenn merged commit b9b5c15 into main Apr 29, 2026
3 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the agent security log defaults/documentation to align with CRAN policy by avoiding a working-directory logfile default and centralizing the default path on an R option + tempfile() fallback.

Changes:

  • Document logfile defaulting behavior as getOption("rtemis_security_logfile", tempfile(...)).
  • Make Agent@logfile a required character field and simplify generate() logfile resolution to per-call override → agent field.
  • Require logfile to be provided to report_agent_unauthorized_tool() and validate it as a non-empty scalar.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
r/man/create_agent.Rd Updates create_agent() Rd docs for the new CRAN-compliant logfile default behavior.
r/R/utils_security.R Makes incident logging require an explicit logfile and validates it.
r/R/07_Agent.R Makes logfile a required Agent property, updates roxygen docs, and changes generate() logfile fallback logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread r/R/07_Agent.R
Comment on lines +512 to +513
# Resolve logfile: per-call arg > agent field
logfile <- logfile %||% x@logfile
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alters logfile resolution behavior (defaulting via create_agent/constructor and removing the fallback in generate). There are existing testthat tests for create_agent()/Agent behavior, but none assert the new default/option precedence for logfile. Please add tests to cover: (1) create_agent(logfile = NULL) uses getOption("rtemis_security_logfile") when set, else a tempfile; and (2) generate(logfile = NULL) uses x@logfile.

Copilot uses AI. Check for mistakes.
Comment thread r/R/07_Agent.R
tempfile("rtemis_security_log_", fileext = ".jsonl")
)
# Resolve logfile: per-call arg > agent field
logfile <- logfile %||% x@logfile
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After resolving logfile <- logfile %||% x@logfile, the value is never validated. Since Agent@logfile can still be NA_character_ or "" (the property type only enforces character, not non-empty), this can lead to late/indirect failures (e.g., incident logging) or silently skipping audit logging. Consider validating the resolved path immediately (e.g., with .check_scalar_character) and/or ensuring the parent directory exists before proceeding.

Suggested change
logfile <- logfile %||% x@logfile
logfile <- logfile %||% x@logfile
if (!is.character(logfile) || length(logfile) != 1L || is.na(logfile) || !nzchar(logfile)) {
stop("`logfile` must be a non-empty character scalar.", call. = FALSE)
}
logfile_dir <- dirname(logfile)
if (!dir.exists(logfile_dir)) {
dir.create(logfile_dir, recursive = TRUE, showWarnings = FALSE)
if (!dir.exists(logfile_dir)) {
stop(
sprintf("Parent directory for `logfile` does not exist and could not be created: %s", logfile_dir),
call. = FALSE
)
}
}

Copilot uses AI. Check for mistakes.
Comment thread r/R/07_Agent.R
Comment on lines 47 to 50
name = optional(S7::class_character),
allow_custom_tools = class_logical,
logfile = optional(S7::class_character)
logfile = S7::class_character
),
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logfile is now a required character property, but neither the constructor nor the validator enforces that it is a non-empty scalar path. As a result, Agent(logfile = "")/NA_character_ will construct successfully and only fail later when logging is attempted. Consider validating logfile in the constructor after applying the NULL default (and/or in the class validator) so invalid paths are rejected at creation time.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants