Skip to content

refactor(kcastle): apply Single Responsibility Principle to Skill, SkillManager, and Castle#6

Merged
shenxiangzhuang merged 2 commits intomasterfrom
copilot/improve-class-design-srp
Mar 10, 2026
Merged

refactor(kcastle): apply Single Responsibility Principle to Skill, SkillManager, and Castle#6
shenxiangzhuang merged 2 commits intomasterfrom
copilot/improve-class-design-srp

Conversation

Copy link
Contributor

Copilot AI commented Mar 10, 2026

Three classes carried responsibilities beyond their core concerns, violating SRP. This refactor extracts those responsibilities into dedicated owners.

Skill — rendering and parsing extracted to module-level functions

Skill was a data/persistence class that also owned prompt rendering and hint parsing. Removed three static methods; replaced with module-level functions exported from kcastle.skills:

# Before
Skill.render_compact(skills)
Skill.render_expanded(skills)
Skill.extract_hints(text)

# After
from kcastle.skills import render_compact_skills, render_expanded_skills, extract_skill_hints
render_compact_skills(skills)
render_expanded_skills(skills)
extract_skill_hints(text)

SkillManager — gains expand_hints()

Skill hint expansion (parse hints → look up skills → render bodies) is a skill-management concern. Moved the logic from Castle.prepare_user_input() into SkillManager.expand_hints(user_input). Castle.prepare_user_input() is now a one-line delegate.

New ModelManager — LLM model management extracted from Castle

Castle mixed lifecycle orchestration with per-session provider/model state. Extracted into kcastle/providers/model_manager.py:

  • get_active_model(session_id) — session override lookup with persistence restoration
  • switch_model(provider_name, model_id, *, session_id) — runtime model switching
  • available_models() — enumerate all configured active models
  • build_provider(provider_name, model_id) — validated provider construction

Castle stores a ModelManager instance and exposes thin delegation wrappers to preserve the existing public API.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: shenxiangzhuang <17157965+shenxiangzhuang@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor class design for Single Responsibility Principle refactor(kcastle): apply Single Responsibility Principle to Skill, SkillManager, and Castle Mar 10, 2026
@shenxiangzhuang shenxiangzhuang marked this pull request as ready for review March 10, 2026 07:25
@shenxiangzhuang shenxiangzhuang merged commit 747dc23 into master Mar 10, 2026
10 checks passed
@shenxiangzhuang shenxiangzhuang deleted the copilot/improve-class-design-srp branch March 10, 2026 07:28
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.

2 participants