Skip to content

πŸ€– β†’ feat: extend global config directive to accept name/pattern specifiers#1035

Draft
juniper-shopify wants to merge 1 commit into
mainfrom
juniper/global-config-specifiers
Draft

πŸ€– β†’ feat: extend global config directive to accept name/pattern specifiers#1035
juniper-shopify wants to merge 1 commit into
mainfrom
juniper/global-config-specifiers

Conversation

@juniper-shopify

Copy link
Copy Markdown
Contributor

πŸ€– β†’ Extend the global config directive to accept optional name/pattern specifiers, mirroring the existing support in cog-type blocks (agent, chat, cmd, etc.).

Motivation

Currently, global { ... } applies configuration to every cog unconditionally. There's no way to target a cross-cutting config at a specific step (or set of steps) without knowing the cog type. This feature enables:

config do
  global(:my_step) { async! }                    # target by exact name
  global(/^api_/) { abort_on_failure! }          # target by pattern
  global { working_directory("/tmp") }           # bare (existing behavior)
end

Implementation

Approach: Structural Mimicry β€” mirrors the proven 3-variable pattern already used by cog-type blocks.

Storage

Adds two new instance variables alongside the existing @global_config:

Variable Type Purpose
@global_config Cog::Config Bare global { } (unchanged)
@global_regexp_configs Hash{Regexp => Cog::Config} global(/pattern/) { }
@global_name_configs Hash{Symbol => Cog::Config} global(:name) { }

Merge Cascade (7 tiers)

The config_for(type, name) method now resolves configuration in this priority order (lowest β†’ highest):

Priority Tier Example
1 (lowest) Global bare global { }
2 Global regexp global(/pattern/) { }
3 Global name global(:step_name) { }
4 Cog-type general agent { }
5 Cog-type regexp agent(/pattern/) { }
6 Cog-type name agent(:step_name) { }
7 (highest) Inline YAML Step-level YAML config

This preserves the invariant that cog-specific blocks always override globals.

Files Changed

  • lib/roast/config_manager.rb β€” new storage, expanded bind_global/on_global, updated config_for
  • sorbet/rbi/shims/lib/roast/config_context.rbi β€” updated type signature + docs for global
  • test/roast/config_manager_test.rb β€” 8 new tests covering all specifier combinations

Drive-by

Replaced a vestigial instance_variable_get(:@values) with the public .values accessor.

Test Plan

All 1188 existing tests pass. 8 new tests cover:

  • global(:name) exact match
  • global(/regexp/) pattern match
  • global(:name) skipped when name is nil
  • Multiple matching regexps (insertion order)
  • Global name below cog-type general in cascade
  • Cog-specific override of global specifier
  • Duplicate global(:name) accumulation
  • Workflow params accessible inside global(:name) blocks

Allow `global(:step_name)` and `global(/pattern/)` in Roast config blocks,
mirroring the existing name/pattern specifier support in cog-type blocks
(agent, chat, cmd, etc.).

This enables targeted cross-cutting configuration like:
  global(:my_step) { async! }
  global(/^api_/) { abort_on_failure! }

The merge cascade expands from 4 tiers to 7:
  1. global (bare)
  2. global (regexp match)
  3. global (exact name)
  4. cog-type general
  5. cog-type regexp match
  6. cog-type exact name
  7. inline YAML

Also cleans up a vestigial `instance_variable_get(:@values)` call
to use the public `.values` accessor instead.
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.

1 participant