Skip to content

refactor: Split types.rs into domain-focused submodules#133

Merged
2witstudios merged 1 commit intomainfrom
pu/refactor-types
Mar 10, 2026
Merged

refactor: Split types.rs into domain-focused submodules#133
2witstudios merged 1 commit intomainfrom
pu/refactor-types

Conversation

@2witstudios
Copy link
Owner

@2witstudios 2witstudios commented Mar 10, 2026

Summary

  • Decompose 960-line types.rs (highest churn: 16 changes) into types/ directory with agent.rs, config.rs, manifest.rs, worktree.rs
  • Re-exports from mod.rs preserve all existing use crate::types::* import paths
  • Add AgentEntry::new() constructor to reduce test boilerplate — new optional fields only need updating in one place

Baseline (from churn analysis)

Metric Before
Cx 19
Density 17%
Churn 16 (highest)

Test plan

  • Build and run cargo test to verify compilation
  • Verify all imports resolve correctly across crates
  • Run npx aidd churn to compare metrics

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Reorganized the type system architecture into modular components for improved code maintainability and scalability.

Decompose 960-line types.rs (highest churn: 16 changes) into types/
directory with agent.rs, config.rs, manifest.rs, and worktree.rs.
Re-exports from mod.rs preserve all existing import paths. Add
AgentEntry::new() constructor to reduce test boilerplate churn.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 36f71e66-f7d6-43d2-83de-7b23a43a73d8

📥 Commits

Reviewing files that changed from the base of the PR and between 9bbaf05 and b0792ac.

📒 Files selected for processing (6)
  • crates/pu-core/src/types.rs
  • crates/pu-core/src/types/agent.rs
  • crates/pu-core/src/types/config.rs
  • crates/pu-core/src/types/manifest.rs
  • crates/pu-core/src/types/mod.rs
  • crates/pu-core/src/types/worktree.rs

📝 Walkthrough

Walkthrough

The types.rs module is refactored into a multi-file structure: agent.rs, config.rs, manifest.rs, worktree.rs, and mod.rs. The original 960 lines of code are reorganized across ~992 new lines, maintaining backward compatibility in serialization/deserialization while splitting concerns by domain.

Changes

Cohort / File(s) Summary
Module Restructuring
crates/pu-core/src/types.rs, crates/pu-core/src/types/mod.rs
Deleted monolithic types.rs file and introduced new module file with declarations and re-exports for agent, config, manifest, and worktree submodules.
Agent Data Models
crates/pu-core/src/types/agent.rs
Extracted AgentStatus enum (Streaming, Waiting, Broken) with is_alive() method; added TriggerState enum; defined AgentEntry struct with comprehensive fields; implemented custom Serialize/Deserialize with backward-compatibility mappings (e.g., spawning→Streaming, idle→Waiting) and suspended_at inference.
Configuration Utilities
crates/pu-core/src/types/config.rs
Extracted AgentConfig and Config structs; added helper functions default_env_files(), default_agents() with built-in agent mappings (claude, codex, opencode, terminal), and resolved_launch_args() for launch argument resolution per agent type.
Manifest Utilities
crates/pu-core/src/types/manifest.rs
Introduced Manifest struct with version, project_root, worktrees, agents, and timestamps; added methods for agent lookup (find_agent, find_agent_mut, all_agents); defined AgentLocation enum for location tracking.
Worktree Data Models
crates/pu-core/src/types/worktree.rs
Extracted WorktreeStatus enum (Active, Merging, Merged, Failed, Cleaned) and WorktreeEntry struct containing nested agents (IndexMap); applied camelCase serialization conventions.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • PR #117: Modifies agent/config data models, AgentConfig, launch_args resolution, and default_agents—directly overlaps with this refactoring's config and agent type definitions.
  • PR #122: Adds plan_mode field to AgentEntry with serialization/deserialization support, which is now consolidated in the new agent.rs module structure.
  • PR #121: Introduces TriggerState and trigger-related fields to AgentEntry and manifest lookup helpers, mirroring the organization and functionality introduced in this refactoring.

Poem

🐰 Types were scattered, one file wide,
Now split into modules, standing side by side!
Agent, config, manifest—each finds its place,
Backward compat sewn throughout with grace.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pu/refactor-types

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 2witstudios merged commit 41a2b12 into main Mar 10, 2026
4 of 5 checks passed
@2witstudios 2witstudios deleted the pu/refactor-types branch March 10, 2026 15:15
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