Problem
src/core/loop.ts contains two nearly identical iteration loops: processIssue (lines 39–111) and processIssueInDir (lines 182–237). Both implement the same core pattern:
- Load contexts, instructions, workflow
- Resolve template
- Spawn agent
- Accumulate token usage
- Check timeouts and exit codes
- Run checks and collect failures
- Sleep between iterations
The only meaningful differences are (1) processIssue uses log.step while processIssueInDir uses log.issue, and (2) processIssue sets up the branch before the loop. Any bug fix or behavioral change must be applied in two places, and they have already drifted (e.g. processIssueInDir is missing the explicit check-failure log line).
Suggested fix
Extract a shared runIterationLoop function that takes the issue, config, cwd, and a logger variant. Both processIssue and processIssueInDir call this shared function after their own setup steps:
async function runIterationLoop(
issue: GitHubIssue,
config: StormConfig,
cwd: string,
): Promise<{ totalUsage: AgentUsage }> {
// single implementation of the loop
}
This eliminates the duplication and ensures both paths stay in sync.
Problem
src/core/loop.tscontains two nearly identical iteration loops:processIssue(lines 39–111) andprocessIssueInDir(lines 182–237). Both implement the same core pattern:The only meaningful differences are (1)
processIssueuseslog.stepwhileprocessIssueInDiruseslog.issue, and (2)processIssuesets up the branch before the loop. Any bug fix or behavioral change must be applied in two places, and they have already drifted (e.g.processIssueInDiris missing the explicit check-failure log line).Suggested fix
Extract a shared
runIterationLoopfunction that takes the issue, config, cwd, and a logger variant. BothprocessIssueandprocessIssueInDircall this shared function after their own setup steps:This eliminates the duplication and ensures both paths stay in sync.