Skip to content

Refactor: largest files audit #125

Description

@serge-ivo

Audit of the largest TypeScript source files (excluding node_modules, dist, and unit *.test.*). Purpose: identify refactor candidates — files that are too long and/or mix multiple responsibilities. No refactoring in this issue — just the list + rationale, to be split into follow-up tasks.

Command used:

find . -type f \( -name "*.tsx" -o -name "*.ts" \) ! -path "*/node_modules/*" \
  ! -path "*/.git/*" ! -path "*/dist/*" ! -name "*.test.ts" ! -name "*.test.tsx" \
  -exec wc -l {} + | sort -rn | head

Top 15 by line count

LOC File What it is / why it's a refactor candidate
2029 workers/mcp/src/instance-tools.ts Every instance-scoped MCP tool (schema + handler) in one file (~dozens of tools). Split by tool group (knowledge, coding, triggers, board, settings, …).
1470 workers/api/src/routes/coding.ts ALL coding routes — repos, sessions, deployments/builds, issues, overseer, engines, work-mode. Too many endpoints in one router; split by sub-domain.
1317 workers/api/src/routes/instances.ts Instance CRUD + voice-settings + typed settings + language sync + more. Mixed concerns; extract voice-settings and settings routers.
1290 workers/api/src/agent-do.ts The AgentDO Durable Object: chat loop, tool execution, storage wiring, repo ingest, alarm state machine. Classic god-object; split the ingest/alarm and chat loop out.
1276 store/console/src/tabs/SettingsTab.tsx One giant Settings component (voice, translation, board maintenance, runner info, danger zone, …). Split into per-section subcomponents.
1251 workers/api/src/agent-storage.ts Storage engine spanning collections, files, vectors, activity, summaries, memory — many domains in one class. Split per storage domain.
1155 packages/browser-runner/src/runner.ts Runner entry: Playwright + tmux + relay transport + task dispatch. Mixes transport and task handlers; extract the task registry.
1064 workers/mcp/src/index.ts MCP server bootstrap + account-tool registration + dispatch. Split registration from transport/dispatch.
1064 packages/sdk/src/voice/use-voice.ts The voice hook — STT/TTS/VAD/modes/commands/timers/echo-guard all in one useVoice. Very high complexity; extract sub-hooks (e.g. useStt, useTurnTimers, useCommands).
986 e2e/console.spec.ts Playwright e2e suite for the console (one big spec). Lower priority (tests), but could split by feature area for readability.
788 workers/api/src/routes/instances-runtime.ts Runtime/relay node routes (register/resolve/status). Cohesive but long; candidate to split node-management vs runtime-call.
763 agents/coder/web/src/CodingTab.tsx The Coder UI container: repos, sessions, terminal/co-pilot, header override, builds toggle, loop, engines. Many responsibilities in one component — prime split candidate (header, session view, landing view).
748 workers/api/src/lib/storage-tools.ts executeStorageTool — one big switch over all storage + coding tools. Split handlers per group.
725 packages/cli/src/commands/runner.ts CLI runner command (connect, relay, multiplex, reattach). Long single command; extract helpers.
720 store/console/src/pages/InstanceDetail.tsx Instance detail page: chat thread + tab routing + voice + loop + gloss. Mixed concerns; extract the chat thread component.

Suggested next steps

  • Prioritize the god-objects first: agent-do.ts, agent-storage.ts, instance-tools.ts, and use-voice.ts — highest complexity-per-file and most-touched.
  • UI: SettingsTab.tsx, CodingTab.tsx, InstanceDetail.tsx split into subcomponents (they already have natural section boundaries).
  • Each split should be behavior-preserving with the existing tests kept green; file one follow-up issue per target.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions