Skip to content

refactor: Split engine.rs (4734 LoC) into 17 submodules (1139 LoC core)#130

Merged
2witstudios merged 2 commits intomainfrom
pu/refactor-engine
Mar 10, 2026
Merged

refactor: Split engine.rs (4734 LoC) into 17 submodules (1139 LoC core)#130
2witstudios merged 2 commits intomainfrom
pu/refactor-engine

Conversation

@2witstudios
Copy link
Owner

@2witstudios 2witstudios commented Mar 10, 2026

Summary

  • Splits the monolithic engine.rs (4,734 lines) into 17 focused submodule files under engine/
  • Core mod.rs reduced to 1,139 lines (struct definitions, new(), handle_request() dispatch, initialization, and tests)
  • All impl Engine blocks — Rust allows splitting these across files in submodules
  • Zero behavioral changes — pure code-move refactoring
  • Rebased onto main (includes PR feat: Make triggers opt-in and fix inject submission #131 trigger opt-in changes)

Module breakdown

Module Lines Contents
mod.rs 1,139 Engine struct, dispatch, init, reaper, tests
spawn.rs 519 handle_spawn, handle_spawn_shell
agent_lifecycle.rs 516 kill, rename, suspend, resume, assign_trigger
status.rs 303 status, pulse, diff, agent status reports
worktree_ops.rs 200 create/delete worktree, rollback
helpers.rs 191 parse_agent_command, reconcile, reap, error helpers
definitions/ 1,239 CRUD for templates, agent defs, swarm defs, schedules, triggers
subscriptions.rs 128 grid + status pub/sub
scheduler.rs 178 periodic schedule evaluation
trigger_executor.rs 287 idle trigger evaluation + inject
session_repair.rs 232 session file repair + prompt injection
pty_operations.rs 157 PTY I/O: logs, attach, input, resize

Test plan

🤖 Generated with Claude Code

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Warning

Rate limit exceeded

@2witstudios has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 32 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 86fb5b2f-0c05-40a0-9c18-3a9bcd14baff

📥 Commits

Reviewing files that changed from the base of the PR and between 8d8ff39 and ce7f9cf.

📒 Files selected for processing (18)
  • crates/pu-engine/src/engine.rs
  • crates/pu-engine/src/engine/agent_lifecycle.rs
  • crates/pu-engine/src/engine/definitions/agent_defs.rs
  • crates/pu-engine/src/engine/definitions/mod.rs
  • crates/pu-engine/src/engine/definitions/schedules.rs
  • crates/pu-engine/src/engine/definitions/swarm_defs.rs
  • crates/pu-engine/src/engine/definitions/templates.rs
  • crates/pu-engine/src/engine/definitions/triggers.rs
  • crates/pu-engine/src/engine/helpers.rs
  • crates/pu-engine/src/engine/mod.rs
  • crates/pu-engine/src/engine/pty_operations.rs
  • crates/pu-engine/src/engine/scheduler.rs
  • crates/pu-engine/src/engine/session_repair.rs
  • crates/pu-engine/src/engine/spawn.rs
  • crates/pu-engine/src/engine/status.rs
  • crates/pu-engine/src/engine/subscriptions.rs
  • crates/pu-engine/src/engine/trigger_executor.rs
  • crates/pu-engine/src/engine/worktree_ops.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pu/refactor-engine

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

2witstudios and others added 2 commits March 9, 2026 22:28
Break the 4733-line engine.rs into engine/mod.rs (2650 lines) plus
11 focused submodules. All extracted methods remain as `impl Engine`
blocks — no public API changes, all 130 tests pass unmodified.

New structure:
- engine/definitions/{templates,agent_defs,swarm_defs,schedules,triggers}.rs
- engine/{scheduler,trigger_executor,session_repair,pty_operations,subscriptions}.rs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract spawn, worktree_ops, agent_lifecycle, status, and helpers
from mod.rs, reducing it from 2776 to 1139 lines. Combined with
the first extraction, engine.rs went from 4734 to 1139 lines
across 17 submodule files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@2witstudios 2witstudios changed the title refactor: Split engine.rs into submodules refactor: Split engine.rs (4734 LoC) into 17 submodules (1139 LoC core) Mar 10, 2026
@2witstudios 2witstudios merged commit 5530e3b into main Mar 10, 2026
5 checks passed
@2witstudios 2witstudios deleted the pu/refactor-engine branch March 10, 2026 14:45
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