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

LOCFileWhat it is / why it's a refactor candidate
2029workers/mcp/src/instance-tools.tsEvery instance-scoped MCP tool (schema + handler) in one file (~dozens of tools). Split by tool group (knowledge, coding, triggers, board, settings, …).
1470workers/api/src/routes/coding.tsALL coding routes — repos, sessions, deployments/builds, issues, overseer, engines, work-mode. Too many endpoints in one router; split by sub-domain.
1317workers/api/src/routes/instances.tsInstance CRUD + voice-settings + typed settings + language sync + more. Mixed concerns; extract voice-settings and settings routers.
1290workers/api/src/agent-do.tsThe 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.
1276store/console/src/tabs/SettingsTab.tsxOne giant Settings component (voice, translation, board maintenance, runner info, danger zone, …). Split into per-section subcomponents.
1251workers/api/src/agent-storage.tsStorage engine spanning collections, files, vectors, activity, summaries, memory — many domains in one class. Split per storage domain.
1155packages/browser-runner/src/runner.tsRunner entry: Playwright + tmux + relay transport + task dispatch. Mixes transport and task handlers; extract the task registry.
1064workers/mcp/src/index.tsMCP server bootstrap + account-tool registration + dispatch. Split registration from transport/dispatch.
1064packages/sdk/src/voice/use-voice.tsThe 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).
986e2e/console.spec.tsPlaywright e2e suite for the console (one big spec). Lower priority (tests), but could split by feature area for readability.
788workers/api/src/routes/instances-runtime.tsRuntime/relay node routes (register/resolve/status). Cohesive but long; candidate to split node-management vs runtime-call.
763agents/coder/web/src/CodingTab.tsxThe 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).
748workers/api/src/lib/storage-tools.tsexecuteStorageTool — one big switch over all storage + coding tools. Split handlers per group.
725packages/cli/src/commands/runner.tsCLI runner command (connect, relay, multiplex, reattach). Long single command; extract helpers.
720store/console/src/pages/InstanceDetail.tsxInstance 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