From 232fa70b4ddf5bc3a1fff2cfd8a2376e5a6ac02c Mon Sep 17 00:00:00 2001 From: crsei Date: Tue, 21 Apr 2026 02:53:28 -0400 Subject: [PATCH] refactor(workspace): P1.3 extract cc-types leaf crate (partial) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the three pure-leaf files out of `src/types/` into a new `cc-types` workspace crate: - `message.rs` → `cc-types/src/message.rs` - `state.rs` → `cc-types/src/state.rs` - `transitions.rs` → `cc-types/src/transitions.rs` `app_state.rs`, `tool.rs`, and `config.rs` stay in the root crate. Per the routine's analysis in issue #70 and the `cc-types` note in PR #79, those three modules are not true leaves: - `types::app_state::AppState` references `crate::teams::types`, `crate::ui::status_line`, `crate::config::settings`, and the now-extracted `cc_keybindings::KeybindingRegistry`. - `types::tool::ToolUseContext` references `crate::ipc::agent_channel::AgentSender`. - `types::config` pulls `ToolUseContext` and `Tools` from `tool`. Extracting these would require either moving teams/ui/config/ipc out first, or rewriting the struct layouts with trait objects / generics — much larger than a leaf move. They stay put until those subsystems migrate (Phase 5+). The root crate's `types/mod.rs` now re-exports the three moved modules via `pub use cc_types::{message, state, transitions};` so every existing `crate::types::message::*` / `crate::types::state::*` / `crate::types::transitions::*` call site (~80 files) keeps resolving without edits. Verification ------------ - `cargo build` : ok, 2 warnings (pre-existing `web::handlers::session_id` dead_code, identical on `rust-lite@ab8a2fc`). - `cargo build --release` : ok, same 2 warnings. - `cargo test -p cc-types` : 0 tests (no tests moved with the files); compiles clean, no warnings. - `cargo test --bin claude-code-rs --offline -- --test-threads=1` : **1794 / 1794 pass** (matches the `cc-keybindings` / `cc-observability` baselines from PR #79). - Smoke: `claude-code-rs --version` prints `claude-code-rs 0.1.0`. Refs issue #70. --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + crates/cc-types/Cargo.toml | 11 +++++++++++ crates/cc-types/src/lib.rs | 12 ++++++++++++ .../src/types => cc-types/src}/message.rs | 0 .../src/types => cc-types/src}/state.rs | 0 .../src/types => cc-types/src}/transitions.rs | 0 crates/claude-code-rs/Cargo.toml | 1 + crates/claude-code-rs/src/types/mod.rs | 13 ++++++++++--- 9 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 crates/cc-types/Cargo.toml create mode 100644 crates/cc-types/src/lib.rs rename crates/{claude-code-rs/src/types => cc-types/src}/message.rs (100%) rename crates/{claude-code-rs/src/types => cc-types/src}/state.rs (100%) rename crates/{claude-code-rs/src/types => cc-types/src}/transitions.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 83f349ba..b234052b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -504,6 +504,16 @@ dependencies = [ "uuid", ] +[[package]] +name = "cc-types" +version = "0.1.0" +dependencies = [ + "chrono", + "serde", + "serde_json", + "uuid", +] + [[package]] name = "cfg-if" version = "1.0.4" @@ -584,6 +594,7 @@ dependencies = [ "bytes", "cc-keybindings", "cc-observability", + "cc-types", "chrono", "clap", "crossterm", diff --git a/Cargo.toml b/Cargo.toml index 249545fa..e4dd6866 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -122,6 +122,7 @@ parking_lot = "0.12" # 内部 crates (workspace split) cc-keybindings = { path = "crates/cc-keybindings" } cc-observability = { path = "crates/cc-observability" } +cc-types = { path = "crates/cc-types" } # Daemon HTTP server axum = { version = "0.8", features = ["ws"] } diff --git a/crates/cc-types/Cargo.toml b/crates/cc-types/Cargo.toml new file mode 100644 index 00000000..2d2f54b2 --- /dev/null +++ b/crates/cc-types/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "cc-types" +version = "0.1.0" +edition = "2021" +description = "Pure leaf types for cc-rust: message, state, transitions (no runtime deps on root crate)" + +[dependencies] +serde = { workspace = true } +serde_json = { workspace = true } +uuid = { workspace = true } +chrono = { workspace = true } diff --git a/crates/cc-types/src/lib.rs b/crates/cc-types/src/lib.rs new file mode 100644 index 00000000..37f5acf0 --- /dev/null +++ b/crates/cc-types/src/lib.rs @@ -0,0 +1,12 @@ +//! Pure leaf types extracted from `claude-code-rs::types`. +//! +//! This crate holds the subset of `src/types/` with no cross-module dependencies +//! on the main crate (teams / ui / config / ipc). The three modules below are +//! the truly pure leaves; `app_state`, `tool`, and `config` remain in the root +//! crate because they still reach into the not-yet-extracted subsystems. +//! +//! See issue #70 (`[workspace-split] Phase 1`) for the rationale behind this +//! partial split. +pub mod message; +pub mod state; +pub mod transitions; diff --git a/crates/claude-code-rs/src/types/message.rs b/crates/cc-types/src/message.rs similarity index 100% rename from crates/claude-code-rs/src/types/message.rs rename to crates/cc-types/src/message.rs diff --git a/crates/claude-code-rs/src/types/state.rs b/crates/cc-types/src/state.rs similarity index 100% rename from crates/claude-code-rs/src/types/state.rs rename to crates/cc-types/src/state.rs diff --git a/crates/claude-code-rs/src/types/transitions.rs b/crates/cc-types/src/transitions.rs similarity index 100% rename from crates/claude-code-rs/src/types/transitions.rs rename to crates/cc-types/src/transitions.rs diff --git a/crates/claude-code-rs/Cargo.toml b/crates/claude-code-rs/Cargo.toml index 6e02621d..f022887a 100644 --- a/crates/claude-code-rs/Cargo.toml +++ b/crates/claude-code-rs/Cargo.toml @@ -134,6 +134,7 @@ parking_lot = { workspace = true } # 内部 workspace crates (P1) cc-keybindings = { workspace = true } cc-observability = { workspace = true } +cc-types = { workspace = true } # Daemon axum = { workspace = true } diff --git a/crates/claude-code-rs/src/types/mod.rs b/crates/claude-code-rs/src/types/mod.rs index 147d1755..203cf538 100644 --- a/crates/claude-code-rs/src/types/mod.rs +++ b/crates/claude-code-rs/src/types/mod.rs @@ -1,6 +1,13 @@ +// `message`, `state`, `transitions` now live in the `cc-types` workspace crate +// (issue #70 — Phase 1 leaf extraction). Re-export them here so existing +// `crate::types::message::*` paths keep resolving across the ~100 call sites +// in this crate. +// +// `app_state`, `tool`, and `config` still depend on teams / ui / config / ipc +// and stay local to the root crate until those subsystems move out. Once they +// do, this file can collapse to a single `pub use cc_types::*;`. +pub use cc_types::{message, state, transitions}; + pub mod app_state; pub mod config; -pub mod message; -pub mod state; pub mod tool; -pub mod transitions;