Skip to content

fix: address code quality concerns from walkthrough#32

Closed
philoserf wants to merge 5 commits intoagent-ecosystem:mainfrom
x3c3:fix/code-quality-concerns
Closed

fix: address code quality concerns from walkthrough#32
philoserf wants to merge 5 commits intoagent-ecosystem:mainfrom
x3c3:fix/code-quality-concerns

Conversation

@philoserf
Copy link
Contributor

Summary

  • Cache token encoderstructure/tokens.go now initializes the tokenizer once via sync.Once instead of per CheckTokens call
  • Deduplicate regex patterns — Shared CodeBlockStrip, InlineCodeStrip, and CodeBlockPattern in util/regex.go; fixes tilde-fence stripping in content analysis
  • Tune HTTP transport — Clone DefaultTransport with MaxIdleConnsPerHost=10 for the link checker
  • Rate limit LLM calls — Add configurable RateLimit field to evaluate.Options using time.Ticker; cache hits bypass the limiter
  • Formatting — Apply go fix and gofumpt -extra

Test plan

  • All 14 packages pass with -race
  • New tests for shared regex patterns (backtick + tilde fences)
  • New tests for rate limiting (5 req/s throttle, zero = unlimited)
  • Existing tests unchanged and passing

🤖 Generated with Claude Code

philoserf and others added 5 commits March 17, 2026 11:39
CheckTokens previously created a new tokenizer.Get(O200kBase) on every
call. The encoder is now initialized once at package level via sync.Once
and reused across invocations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Both content/ and links/ defined codeBlockStrip and inlineCodeStrip
independently. The content version only handled backtick fences; the
links version handled both backticks and tildes. Shared patterns now
live in util/ using the more complete tilde-aware version.

This is also a correctness fix: content analysis previously did not
strip tilde-fenced code blocks, inflating word and sentence counts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Clone http.DefaultTransport and set MaxIdleConnsPerHost to 10 (default
is 2). Cloning preserves existing defaults for TLS timeouts, proxy
support, and idle connection management.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add RateLimit field to evaluate.Options (requests per second). Uses a
time.Ticker to throttle actual API calls while allowing cache hits to
bypass the limiter. Default 0 means unlimited (existing behavior).

Applies to both EvaluateSkill and EvaluateSingleFile.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@philoserf philoserf force-pushed the fix/code-quality-concerns branch from 5c45e06 to f27c63b Compare March 17, 2026 15:54
@philoserf
Copy link
Contributor Author

Now that I've had some time to steep in the tea, I realize this should have been five PRs. Feel free to reject it. I'll reorg and resubmit.

@dacharyc
Copy link
Member

Hey @philoserf - thanks for taking the time to put this together and think about it! I probably won't get a chance to look deeply into this for the next day or two, but at a quick glance, these seem like good optimizations. I'll spend some more time with this later this week and will likely merge as-is after I've had a chance to dig in.

@philoserf philoserf closed this Mar 18, 2026
@philoserf
Copy link
Contributor Author

The new smaller pull requests will be easier.

@philoserf philoserf deleted the fix/code-quality-concerns branch March 18, 2026 13:13
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