refactor(agents,triggers): extract shared modules to eliminate duplication#135
Merged
zbigniewsobiecki merged 2 commits intodevfrom Feb 11, 2026
Merged
refactor(agents,triggers): extract shared modules to eliminate duplication#135zbigniewsobiecki merged 2 commits intodevfrom
zbigniewsobiecki merged 2 commits intodevfrom
Conversation
test: add comprehensive unit tests (17 files, 297 new tests)
…ation (#135) Extract ~1,530 lines of duplicated code across 4 agent files and 10 trigger files into focused shared modules, achieving a net reduction of ~436 lines. Agent shared modules (src/agents/shared/): - lifecycle.ts: generic executeAgentLifecycle<TContext>() replacing 4 copies of the ~155-line execution skeleton (logger, watchdog, repo, LLMist, loop) - builderFactory.ts: createConfiguredBuilder() replacing 4 copies of the 13-method AgentBuilder chain (~60 lines each) - syntheticCalls.ts: injectDirectoryListing(), injectContextFiles(), injectAUContext(), injectSyntheticCall() replacing 4 copies each - modelResolution.ts: resolveModelConfig() replacing 4 copies of model/prompt/iteration config resolution - prFormatting.ts: formatPRDetails(), formatPRDiff() replacing 3 identical copies across PR-aware agents - repository.ts: setupRepository() with SetupRepositoryOptions replacing 4 copies of clone/checkout/setup logic Trigger shared modules: - triggers/github/utils.ts: added isSelfAuthored() and requireTrelloCardId() replacing 3 copies of auth-user checks and 3 copies of card validation - triggers/shared/agent-result-handler.ts: handleAgentResultArtifacts() replacing duplicate log-upload + cost-update blocks in both webhook handlers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
src/agents/shared/andsrc/triggers/shared/Agent shared modules (
src/agents/shared/)lifecycle.tsexecuteAgentLifecycle<TContext>()handling logger setup, watchdog, repo init, LLMist client creation, agent loop, and cleanupbuilderFactory.tscreateConfiguredBuilder()with full 13-methodAgentBuilderchain, AU gadget appending, session state initsyntheticCalls.tsinjectDirectoryListing(),injectContextFiles(),injectAUContext(),injectSyntheticCall()modelResolution.tsresolveModelConfig()withconfigKeysupport for config sharingprFormatting.tsformatPRDetails(),formatPRDiff()repository.tssetupRepository()withSetupRepositoryOptionsinterfaceTrigger shared utilities
triggers/github/utils.tsisSelfAuthored(),requireTrelloCardId()triggers/shared/agent-result-handler.tshandleAgentResultArtifacts()for both webhook handlersWhat stays unique per agent
extractPRUrlpost-processingformatCheckStatus(), pre-flight failed-check verification, acknowledgment commentformatPRComments/Reviews/IssueComments(), review-specific synthetic callsreadPRFileContents()with token limiting,CreatePRReviewgadgetTest plan
npx tsc --noEmit— zero type errorsnpm test— all 436 tests pass (32 test files)npm run lint— clean (only 5 pre-existing complexity warnings)🤖 Generated with Claude Code