Skip to content

Refactor duplicated filter validation and localize RPC/launcher helpers#7802

Merged
lpcox merged 3 commits into
mainfrom
copilot/refactor-semantic-function-clustering
Jun 19, 2026
Merged

Refactor duplicated filter validation and localize RPC/launcher helpers#7802
lpcox merged 3 commits into
mainfrom
copilot/refactor-semantic-function-clustering

Conversation

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

This addresses the main semantic-clustering findings from the refactor audit: duplicated jq filter validation logic, RPC logging helpers split across too many files, and a launcher-specific session formatter living in strutil. The change keeps behavior intact while tightening package boundaries and reducing maintenance overhead.

  • Config validation

    • Reduced validateToolResponseFilters to a thin wrapper over validateToolResponseFiltersWithVars(..., nil).
    • Kept the variable-aware path as the single implementation and documented that nil preserves the existing “no jq variables” behavior.
    func validateToolResponseFilters(filters map[string]string, jsonPath string) error {
        return validateToolResponseFiltersWithVars(filters, jsonPath, nil)
    }
  • RPC logger consolidation

    • Merged payload-formatting and marshal helper functions into internal/logger/rpc_format.go.
    • Removed the extra rpc_helpers.go split; rpc_logger.go remains the coordination/API surface.
  • Launcher/package boundary cleanup

    • Moved session-suffix formatting out of internal/strutil into internal/launcher/log_helpers.go as a local helper.
    • Updated the launcher call sites to use the package-local helper and moved the corresponding test coverage with it.
  • Scope intentionally left out

    • Did not fold server/gateway_tls.go or middleware/schema.go; those were lower-priority organizational observations rather than the highest-value refactors.

GitHub Advanced Security started work on behalf of lpcox June 19, 2026 22:27 View session
GitHub Advanced Security finished work on behalf of lpcox June 19, 2026 22:29
Copilot AI changed the title [WIP] Refactor semantic function clustering for outliers and near-duplicates Refactor duplicated filter validation and localize RPC/launcher helpers Jun 19, 2026
Copilot AI requested a review from lpcox June 19, 2026 22:36
Copilot finished work on behalf of lpcox June 19, 2026 22:36
GitHub Advanced Security started work on behalf of lpcox June 19, 2026 22:52 View session
GitHub Advanced Security finished work on behalf of lpcox June 19, 2026 22:54
GitHub Advanced Security started work on behalf of lpcox June 19, 2026 22:54 View session
GitHub Advanced Security finished work on behalf of lpcox June 19, 2026 22:55
@lpcox lpcox marked this pull request as ready for review June 19, 2026 23:09
Copilot AI review requested due to automatic review settings June 19, 2026 23:09
@lpcox lpcox merged commit 21110aa into main Jun 19, 2026
41 checks passed
@lpcox lpcox deleted the copilot/refactor-semantic-function-clustering branch June 19, 2026 23:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors and consolidates a few duplicated/helper utilities (jq filter validation, RPC logging helpers, and launcher session suffix formatting) to tighten package boundaries and reduce maintenance overhead while aiming to preserve existing behavior.

Changes:

  • Refactors config tool-response-filter validation so the no-vars path delegates to the vars-aware implementation.
  • Consolidates RPC payload formatting + marshal helpers into internal/logger/rpc_format.go and removes the extra helper file.
  • Moves launcher session suffix formatting out of internal/strutil into a launcher-local helper (and relocates the test).
Show a summary per file
File Description
internal/strutil/strutil.go Removes exported SessionSuffix helper from strutil to reduce cross-package coupling.
internal/strutil/session_suffix_test.go Deletes the strutil-scoped test that covered the removed helper.
internal/logger/rpc_logger.go Updates the internal file-organization comment to reflect the consolidation.
internal/logger/rpc_helpers.go Removes the standalone RPC helper file (helpers moved into rpc_format.go).
internal/logger/rpc_format.go Adds payload/marshal helper functions alongside formatting utilities.
internal/launcher/log_helpers.go Introduces a launcher-local sessionSuffix helper and updates call sites.
internal/launcher/log_helpers_test.go Adds coverage for the moved sessionSuffix helper.
internal/config/validation.go Refactors tool response filter validation to delegate through the vars-aware implementation.

Copilot's findings

Tip

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

  • Files reviewed: 8/8 changed files
  • Comments generated: 2

Comment on lines +129 to 133
// filters that reference variables which are only bound at run time. A nil varNames
// slice preserves validateToolResponseFilters behavior by disallowing jq variables.
func validateToolResponseFiltersWithVars(filters map[string]string, jsonPath string, varNames []string) error {
if len(filters) == 0 {
return nil
Comment on lines +117 to 121
// validateToolResponseFilters validates tool response filters without permitting jq
// variables, preserving the historical runtime behavior by delegating with nil varNames.
func validateToolResponseFilters(filters map[string]string, jsonPath string) error {
if len(filters) == 0 {
return nil
}

for toolName, rawFilter := range filters {
if strings.TrimSpace(toolName) == "" {
return fmt.Errorf("%s contains an empty tool name", jsonPath)
}
filter := strings.TrimSpace(rawFilter)
if filter == "" {
return fmt.Errorf("%s.%s must not be empty", jsonPath, toolName)
}

query, err := gojq.Parse(filter)
if err != nil {
return fmt.Errorf("%s.%s contains an invalid jq expression: %w", jsonPath, toolName, err)
}
if _, err := gojq.Compile(query,
gojq.WithEnvironLoader(func() []string { return nil }), // match runtime compile options (defense-in-depth)
); err != nil {
return fmt.Errorf("%s.%s contains an invalid jq expression: %w", jsonPath, toolName, err)
}
}

return nil
return validateToolResponseFiltersWithVars(filters, jsonPath, nil)
}
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.

3 participants