Skip to content

refactor(agents,triggers): extract shared modules to eliminate duplication#135

Merged
zbigniewsobiecki merged 2 commits intodevfrom
refactor/agent-trigger-dedup
Feb 11, 2026
Merged

refactor(agents,triggers): extract shared modules to eliminate duplication#135
zbigniewsobiecki merged 2 commits intodevfrom
refactor/agent-trigger-dedup

Conversation

@zbigniewsobiecki
Copy link
Copy Markdown
Member

Summary

  • Extract ~1,530 lines of duplicated code across 4 agent files and 10 trigger/webhook files into focused shared modules under src/agents/shared/ and src/triggers/shared/
  • Net reduction of 436 lines (-1,528 / +1,092) while preserving all existing behavior and test coverage
  • All 436 existing tests pass unchanged — no behavioral changes

Agent shared modules (src/agents/shared/)

Module Replaces Description
lifecycle.ts 4 × ~155L execution skeleton Generic executeAgentLifecycle<TContext>() handling logger setup, watchdog, repo init, LLMist client creation, agent loop, and cleanup
builderFactory.ts 4 × ~60L builder chain createConfiguredBuilder() with full 13-method AgentBuilder chain, AU gadget appending, session state init
syntheticCalls.ts 4 × ~50L injection logic injectDirectoryListing(), injectContextFiles(), injectAUContext(), injectSyntheticCall()
modelResolution.ts 4 × ~25L config resolution resolveModelConfig() with configKey support for config sharing
prFormatting.ts 3 × ~15L formatting formatPRDetails(), formatPRDiff()
repository.ts 4 × ~40L setup setupRepository() with SetupRepositoryOptions interface

Trigger shared utilities

Module Replaces Description
triggers/github/utils.ts 3 × self-auth check, 3 × card validation isSelfAuthored(), requireTrelloCardId()
triggers/shared/agent-result-handler.ts 2 × ~25L log upload + cost update handleAgentResultArtifacts() for both webhook handlers

What stays unique per agent

  • base.ts: Multi-flow dispatch (Trello/PR/debug), Trello card fetching, prompt builders, status updates, extractPRUrl post-processing
  • respond-to-ci.ts: CI log fetching, formatCheckStatus(), pre-flight failed-check verification, acknowledgment comment
  • respond-to-review.ts: formatPRComments/Reviews/IssueComments(), review-specific synthetic calls
  • review.ts: readPRFileContents() with token limiting, CreatePRReview gadget

Test plan

  • npx tsc --noEmit — zero type errors
  • npm test — all 436 tests pass (32 test files)
  • npm run lint — clean (only 5 pre-existing complexity warnings)
  • Pre-commit hooks pass (lint + typecheck + commitlint)
  • Pre-push hooks pass (full test suite)

🤖 Generated with Claude Code

zbigniewsobiecki and others added 2 commits February 11, 2026 15:05
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>
@zbigniewsobiecki zbigniewsobiecki merged commit 89a6117 into dev Feb 11, 2026
3 checks passed
@zbigniewsobiecki zbigniewsobiecki deleted the refactor/agent-trigger-dedup branch February 11, 2026 14:43
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