Skip to content

refactor: merge duplicate type definitions across crates#3185

Merged
houko merged 2 commits into
mainfrom
refactor/types-merge-duplicates
Apr 25, 2026
Merged

refactor: merge duplicate type definitions across crates#3185
houko merged 2 commits into
mainfrom
refactor/types-merge-duplicates

Conversation

@houko

@houko houko commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Three pairs of duplicated/near-duplicated types consolidated:

1. OAuthTokens (was duplicated in extensions + runtime-mcp)

  • New canonical home: crates/librefang-types/src/oauth.rs
  • Both helper methods preserved (access_token_zeroizing, refresh_token_zeroizing, default_token_type)
  • zeroize added as a librefang-types dep
  • Old definitions in librefang-extensions and librefang-runtime-mcp replaced with pub use re-exports — 0 call-site renames, 6 import paths kept working transparently

2. SessionResetPolicy (was duplicated in kernel + types)

  • Kernel-side ResetMode enum and policy struct deleted
  • librefang-kernel/src/session_policy.rs now re-exports the canonical librefang_types::config::{SessionResetPolicy, SessionResetMode, SessionResetReason}
  • Runtime-only logic moved to a SessionResetPolicyExt trait (should_reset)
  • ~20 test references updated to use the canonical enum names

3. UsageSummary + ModelUsage (TUI vs memory)

  • Kept separate — TUI versions are intentional display projections (different field names: model_id/total_calls vs model/call_count)
  • Added explicit From<&memory::UsageSummary> and From<&memory::ModelUsage> impls so the conversion is no longer ad-hoc
  • librefang-memory added as a librefang-cli dep
  • Comment added explaining why both shapes coexist

Test plan

  • cargo build --workspace --lib
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo test --workspace --lib — passes (one pre-existing env-leak test in librefang-runtime::embedding::tests flakes only when OPENAI_API_KEY is set in shell; unrelated to this refactor)

- Move OAuthTokens to librefang-types::oauth (was duplicated in
  librefang-extensions and librefang-runtime-mcp); both helpers
  (access_token_zeroizing, default_token_type) preserved. Old
  call paths kept via pub use re-exports.
- Consolidate SessionResetPolicy / SessionResetMode / SessionResetReason
  on the librefang-types definition (was duplicated in
  librefang-kernel::session_policy with a parallel ResetMode enum).
  Kernel keeps the runtime evaluation via a SessionResetPolicyExt
  trait; the From conversions between the two layers are no longer
  needed.
- Add explicit From<&memory::UsageSummary> / From<&memory::ModelUsage>
  conversions to the TUI display projections in librefang-cli; the
  TUI structs stay separate (different field names match the
  rendered labels) and are now documented as projections.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions github-actions Bot added size/L 250-999 lines changed ready-for-review PR is ready for maintainer review labels Apr 25, 2026
@github-actions github-actions Bot added area/kernel Core kernel (scheduling, RBAC, workflows) area/security Security systems and auditing and removed ready-for-review PR is ready for maintainer review labels Apr 25, 2026
@houko
houko merged commit 330c1a0 into main Apr 25, 2026
20 checks passed
@houko
houko deleted the refactor/types-merge-duplicates branch April 25, 2026 23:29
@houko houko mentioned this pull request Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/kernel Core kernel (scheduling, RBAC, workflows) area/security Security systems and auditing size/L 250-999 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant