Skip to content

[code-simplifier] Simplify claude_tools.go: use getOrCreateToolMap and clearer isClaudeToolName#35855

Merged
pelikhan merged 1 commit into
mainfrom
code-simplifier/2026-05-30-16819c0ccba33d93
May 30, 2026
Merged

[code-simplifier] Simplify claude_tools.go: use getOrCreateToolMap and clearer isClaudeToolName#35855
pelikhan merged 1 commit into
mainfrom
code-simplifier/2026-05-30-16819c0ccba33d93

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 30, 2026

Summary

Refactors pkg/workflow/claude_tools.go to reduce boilerplate and tighten a character-classification helper.

Changes

pkg/workflow/claude_tools.go

  • expandNeutralToolsToClaudeTools — replaced inline map-creation boilerplate with a new getOrCreateToolMap helper; removed redundant explicit writes back to the result map.
  • isClaudeToolName — replaced the strings.ToUpper call with a direct ASCII byte-range check, removing an unnecessary allocation and making the intent clearer.

Motivation

The previous implementation scattered repeated map-initialisation logic across the function body and relied on strings.ToUpper for a simple ASCII range check. The refactor keeps the logic in one place (getOrCreateToolMap) and uses the idiomatic Go byte-range test (c >= 'A' && c <= 'Z') to avoid a string allocation on every call.

Impact

Dimension Assessment
Scope Single file — pkg/workflow/claude_tools.go
Breaking change No
Risk Low — pure internal refactor, no behaviour change
Test impact Existing tests cover the refactored paths; no new tests required

Checklist

  • No breaking changes
  • No new external dependencies
  • Logic equivalent to pre-refactor implementation
  • isClaudeToolName now allocation-free for the common path

Generated by PR Description Updater for issue #35855 · sonnet46 900.9K ·

…deToolName

- Replace manual get-or-create blocks in expandNeutralToolsToClaudeTools with
  the existing getOrCreateToolMap helper, removing 20 lines of duplicated logic
- Simplify isClaudeToolName to a direct byte comparison (toolName[0] >= 'A' &&
  toolName[0] <= 'Z') instead of the opaque strings.HasPrefix + ToUpper pattern;
  all Claude tool names are ASCII so the behavior is identical

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review May 30, 2026 05:11
Copilot AI review requested due to automatic review settings May 30, 2026 05:11
@pelikhan pelikhan merged commit adab887 into main May 30, 2026
18 of 20 checks passed
@pelikhan pelikhan deleted the code-simplifier/2026-05-30-16819c0ccba33d93 branch May 30, 2026 05:11
Copy link
Copy Markdown
Contributor

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 30, 2026

PR Code Quality Reviewer completed the code quality review.

@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 30, 2026

🧪 Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Only pkg/workflow/claude_tools.go was changed (5 additions, 29 deletions). Test Quality Sentinel skipped.

@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 30, 2026

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #35855 does not have the 'implementation' label (has_implementation_label=false) and has only 5 new lines of code in business logic directories (default_business_additions=5, threshold=100).

@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 30, 2026

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions github-actions Bot mentioned this pull request May 30, 2026
Copy link
Copy Markdown
Contributor Author

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /zoom-out and /improve-codebase-architecture — changes are correct and improve readability.

📋 Key Themes & Highlights

Positive Highlights

  • getOrCreateToolMap correctly inserts newly-created maps into the parent (container[key] = created), so removing the now-redundant result["claude"] = claudeSection and claudeSection["allowed"] = claudeAllowed lines is safe — the implicit contract is already verified by the existing helper test.
  • ✅ The isClaudeToolName rewrite (toolName[0] >= 'A' && toolName[0] <= 'Z') is clearer and equally correct for ASCII Claude tool names.
  • ✅ Net -24 lines with zero behaviour change — exactly the right kind of cleanup PR.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 1.1M

Copy link
Copy Markdown
Contributor Author

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Review: Simplification is correct; one implicit contract worth noting

The refactoring is functionally equivalent — getOrCreateToolMap does write the new map back into its container (container[key] = created), so removing the explicit result["claude"] = claudeSection / claudeSection["allowed"] = claudeAllowed lines is safe today.

⚠️ Implicit side-effect contract introduced

The deleted write-back lines were self-documenting: they made it obvious that claudeSection was intentionally placed into result, and claudeAllowed into claudeSection. With those lines gone, correctness is silently coupled to the side-effect behaviour of getOrCreateToolMap (the container[key] = created assignment in the create path).

If someone later changes getOrCreateToolMap to lazy-init (returns a detached map, writes back only on mutation), all Claude tool configuration would be silently dropped with no compile-time or test-time signal. A short comment calling this out would preserve the original intent:

// getOrCreateToolMap inserts newly-created maps into their parent container,
// so claudeSection and claudeAllowed are already wired into result on return.
claudeSection := getOrCreateToolMap(result, "claude")
claudeAllowed := getOrCreateToolMap(claudeSection, "allowed")

The isClaudeToolName byte-index change is correct; the updated comment accurately documents the intentional ASCII-only narrowing.

🔎 Code quality review by PR Code Quality Reviewer · sonnet46 1.2M

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants