-
Notifications
You must be signed in to change notification settings - Fork 52
Common search for .roast
#134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
nfgrep
wants to merge
11
commits into
main
Choose a base branch
from
use-config-root-for-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
504d33e
Refactor and use a single source .roast config dir
nfgrep b079389
Small optimization for finding .roast
nfgrep a230d81
Fix cache_test
nfgrep 4b7fa36
Call it DotRoast not config
nfgrep a6c9ff8
Cleanup tests
nfgrep d6d34a0
Fix missing .roast in shallow fixture
nfgrep db087bc
Return start_path if no .roast is found
nfgrep ee2a89c
Refactor
nfgrep 7bca90a
Fix workflow_configuration not used
nfgrep f436306
Better cache namespace and factor out interceptor
nfgrep 35ceb0a
dotroast again
nfgrep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
**/.claude/settings.local.json | ||
|
||
**/CLAUDE.local.md | ||
.roast/ | ||
/.roast/ | ||
|
||
bin/_guard-core | ||
bin/bundle | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require "fileutils" | ||
require "roast/helpers/logger" | ||
|
||
module Roast | ||
module DotRoast | ||
class << self | ||
def root(starting_path = Dir.pwd, ending_path = File.dirname(Dir.home)) | ||
unless starting_path.start_with?(ending_path) | ||
Roast::Helpers::Logger.warn(<<~WARN) | ||
Unexpected ending path when looking for .roast: | ||
Starting path #{starting_path} is not a subdir of ending path #{ending_path} | ||
Will check all the way up to root. | ||
WARN | ||
|
||
ending_path = "/" | ||
end | ||
|
||
candidate = starting_path | ||
until candidate == ending_path | ||
dot_roast_candidate = File.join(candidate, ".roast") | ||
return dot_roast_candidate if Dir.exist?(dot_roast_candidate) | ||
|
||
candidate = File.dirname(candidate) | ||
end | ||
|
||
File.join(starting_path, ".roast") | ||
end | ||
|
||
def ensure_subdir(subdir_name, gitignored: true) | ||
subdir_path = File.join(root, subdir_name) | ||
FileUtils.mkdir_p(subdir_path) unless File.directory?(subdir_path) | ||
|
||
if gitignored | ||
gitignore_path = File.join(subdir_path, ".gitignore") | ||
File.write(gitignore_path, "*") unless File.exist?(gitignore_path) | ||
end | ||
|
||
subdir_path | ||
end | ||
|
||
def subdir_path(subdir_name) | ||
path = File.join(root, subdir_name) | ||
File.directory?(path) ? path : nil | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require "digest" | ||
require "roast/dot_roast" | ||
|
||
module Roast | ||
module Helpers | ||
module FunctionCache | ||
autoload :Interceptor, "roast/helpers/function_cache/interceptor" | ||
|
||
class << self | ||
def for_workflow(workflow_name, workflow_path) | ||
for_namespace(namespace_from_workflow(workflow_name, workflow_path)) | ||
end | ||
|
||
def for_namespace(namespace) | ||
cache_dir = Roast::DotRoast.ensure_subdir("cache") | ||
cache_path = namespace.empty? ? cache_dir : File.join(cache_dir, namespace) | ||
ActiveSupport::Cache::FileStore.new(cache_path) | ||
end | ||
|
||
def namespace_from_workflow(workflow_name, workflow_path) | ||
sanitized_name = workflow_name.parameterize.underscore | ||
workflow_path_sha = Digest::MD5.hexdigest(workflow_path).first(4) | ||
"#{sanitized_name}_#{workflow_path_sha}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# frozen_string_literal: true | ||
|
||
require "roast/helpers/logger" | ||
|
||
module Roast | ||
module Helpers | ||
module FunctionCache | ||
# Intercepts function dispatching to add caching capabilities | ||
# This module wraps around Raix::FunctionDispatch to provide caching for tool functions | ||
module Interceptor | ||
def dispatch_tool_function(function_name, params) | ||
start_time = Time.now | ||
|
||
ActiveSupport::Notifications.instrument("roast.tool.execute", { | ||
function_name: function_name, | ||
params: params, | ||
}) | ||
|
||
# Handle workflows with or without configuration | ||
result = if !respond_to?(:workflow_configuration) || workflow_configuration.nil? | ||
super(function_name, params) | ||
else | ||
function_config = if workflow_configuration.respond_to?(:function_config) | ||
workflow_configuration.function_config(function_name) | ||
else | ||
{} | ||
end | ||
|
||
# Check if caching is enabled - handle both formats: | ||
# 1. cache: true (boolean format) | ||
# 2. cache: { enabled: true } (hash format) | ||
cache_enabled = if function_config.is_a?(Hash) | ||
cache_config = function_config["cache"] | ||
if cache_config.is_a?(Hash) | ||
cache_config["enabled"] | ||
else | ||
# Direct boolean value | ||
cache_config | ||
end | ||
else | ||
false | ||
end | ||
|
||
if cache_enabled | ||
# Call the original function and pass in the cache | ||
cache = Roast::Helpers::FunctionCache.for_workflow(workflow_configuration.name, workflow_configuration.workflow_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We used |
||
super(function_name, params, cache:) | ||
else | ||
Roast::Helpers::Logger.debug("⚠️ Caching not enabled for #{function_name}") | ||
super(function_name, params) | ||
end | ||
end | ||
|
||
execution_time = Time.now - start_time | ||
|
||
# Determine if caching was enabled for metrics | ||
cache_enabled = if defined?(function_config) && function_config.is_a?(Hash) | ||
cache_config = function_config["cache"] | ||
if cache_config.is_a?(Hash) | ||
cache_config["enabled"] | ||
else | ||
# Direct boolean value | ||
cache_config | ||
end | ||
else | ||
false | ||
end | ||
|
||
ActiveSupport::Notifications.instrument("roast.tool.complete", { | ||
function_name: function_name, | ||
execution_time: execution_time, | ||
cache_enabled: cache_enabled, | ||
}) | ||
|
||
result | ||
rescue => e | ||
execution_time = Time.now - start_time | ||
|
||
ActiveSupport::Notifications.instrument("roast.tool.error", { | ||
function_name: function_name, | ||
error: e.class.name, | ||
message: e.message, | ||
execution_time: execution_time, | ||
}) | ||
raise | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require "roast/dot_roast" | ||
|
||
module Roast | ||
module Workflow | ||
class Initializers | ||
class << self | ||
def load_all | ||
project_initializers = Roast::DotRoast.subdir_path("initializers") | ||
return unless project_initializers | ||
|
||
$stderr.puts "Loading project initializers from #{project_initializers}" | ||
pattern = File.join(project_initializers, "**/*.rb") | ||
Dir.glob(pattern, sort: true).each do |file| | ||
$stderr.puts "Loading initializer: #{file}" | ||
require file | ||
end | ||
rescue => e | ||
puts "ERROR: Error loading initializers: #{e.message}" | ||
Roast::Helpers::Logger.error("Error loading initializers: #{e.message}") | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lack of this was a bug in the prev code, pwd wasn't under HOME, you'd end up hanging/looping forever.