Skip to content

refactor: simplify codebase — remove dead code and duplication#18

Merged
jacksoncage merged 3 commits intomainfrom
refactor/simplify-codebase
Mar 1, 2026
Merged

refactor: simplify codebase — remove dead code and duplication#18
jacksoncage merged 3 commits intomainfrom
refactor/simplify-codebase

Conversation

@jacksoncage
Copy link
Owner

@jacksoncage jacksoncage commented Mar 1, 2026

Summary

  • Remove dead code: PLATFORM_FORMAT_HINTS, listRecentFailed, cleanup() in trace, unused ValidationResult interface, unused imports
  • Extract shared helpers: replyAndLog, formatDuration, cancelDebouncedStatus, initRepoFromSlug, loadHtml, getConfigPath, whichSync, withTimeout (new runners/timeout.ts)
  • Consolidate duplication: complete/fail → shared finish method, adapter status collection, SSE broadcasting, bot token verification loop, .env section writing, 13 command if-statements → lookup table
  • Reduce verbosity: priority maps → module-level constants, nested if chains → optional chaining, noise comments removed

22 files changed, 329 net lines removed (-696/+367). All 369 tests pass.

Test plan

  • bun test — 369 tests pass, 744 assertions, 0 failures
  • Verify adapters start correctly (Slack, Discord, Telegram, WhatsApp, CLI)
  • Verify HTTP API + Web UI still works
  • Verify task queue and worker processing
  • Verify bun run setup interactive flow

…ication, and reducing verbosity

- Remove dead code: PLATFORM_FORMAT_HINTS, listRecentFailed, cleanup method in trace, unused ValidationResult interface, unused imports
- Extract shared helpers: replyAndLog, formatDuration, cancelDebouncedStatus, initRepoFromSlug, loadHtml, getConfigPath, whichSync
- Consolidate duplication: withTimeout into shared runners/timeout.ts, complete/fail into shared finish method, adapter status collection, SSE broadcasting, bot token verification loop, .env section writing
- Replace verbose patterns: 13 command if-statements → lookup table, priority maps → module-level constants, nested if chains → optional chaining
- Remove noise comments that restate what code already communicates

21 files changed, 344 net lines removed. All 369 tests pass.
Bare catch blocks were silently swallowing errors in broadcastSSE,
SSE controller close, and config loading. Restore debug/warn logging
so failures are observable without changing control flow.
The withTimeout helper left a dangling 30-minute setTimeout when the
process exited normally, leaking one timer per task. Clear it on exit.
@jacksoncage
Copy link
Owner Author

Code Review Summary

Reviewed by 4 specialized agents: code quality, silent failure analysis, test coverage, and type design.

Findings & Fixes

Fixed — Silent failure issues (3 bare catch {} blocks):

  • broadcastSSE in http.ts — restored logger.debug for SSE broadcast errors
  • SSE controller.close() in http.ts (2 places) — restored logger.debug for close errors
  • loadConfig/saveConfig in config.ts — added logger.warn for non-ENOENT errors (file-not-found is expected on first run)

Fixed — Timer leak in withTimeout:

  • The 30-minute setTimeout was never cleared when the process exited normally, leaking one timer per task
  • Now calls clearTimeout on normal exit

No Issues Found

  • Code quality: All behavioral changes verified equivalent, all dead code removals confirmed safe (zero references)
  • Test coverage: 369 tests pass with 744 assertions, no blocking gaps identified
  • Type design: Clean types overall. TaskQueue.finish union type "completed" | "failed" is a good improvement. SIMPLE_COMMANDS lookup table eliminates copy-paste risk. RepoResolution discriminated union is well-designed.

Stats

  • 22 files changed, ~344 net lines removed
  • Helpers extracted: replyAndLog, formatDuration, broadcastSSE, cancelDebouncedStatus, initRepoFromSlug, loadHtml, getConfigPath, whichSync, withTimeout
  • Dead code removed: PLATFORM_FORMAT_HINTS, listRecentFailed, cleanup(), ValidationResult, unused imports
  • Duplication consolidated: complete/failfinish, 13 command if-statements → lookup table, bot token verification → data-driven loop

@jacksoncage jacksoncage merged commit 18e9f16 into main Mar 1, 2026
1 check passed
@jacksoncage jacksoncage deleted the refactor/simplify-codebase branch March 1, 2026 21:00
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