Skip to content

code: run.ts is 2615 lines with 345-line function — extract execution engine #447

@kokevidaurre

Description

@kokevidaurre

Problem

src/commands/run.ts is 2615 lines — the largest file in the codebase by 45%. It contains 8 functions over 80 lines, with runAgent() at 345 lines being the worst offender.

Measurements

Function Lines Start
runAgent 345 L1706
gatherSquadContext 198 L250
runSquad 185 L1360
runCloudDispatch 163 L1112
runLeadMode 149 L1555
executeWithClaude 136 L2334
executeWithProvider 128 L2480
runCommand 81 L1277

Location

src/commands/run.ts — all functions listed above.

Suggested Fix

Extract into focused modules under src/lib/execution/:

  • engine.tsexecuteWithClaude, executeWithProvider, shared env/model resolution
  • context.tsgatherSquadContext, learnings, definitions
  • modes.tsrunSquad, runLeadMode, runAgent orchestration
  • cloud.tsrunCloudDispatch
  • helpers.tsgenerateExecutionId, detectTaskType, formatDuration, etc.

Keep run.ts as a thin command handler (~200 lines) that delegates to these modules.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions