claude-memory/graph/problems/cognitive-memory-clientpy-at-3260-lines-needs-modular-refact-8d3654.md

1.4 KiB

id type title tags importance confidence created updated
8d365483-701f-49fe-a55e-4d524ae2eff3 problem cognitive-memory client.py at 3260 lines needs modular refactor
cognitive-memory
refactoring
architecture
tech-debt
0.7 0.8 2026-02-19T20:57:01.898902+00:00 2026-02-19T20:57:01.898902+00:00

client.py has grown to 3260 lines with 47 methods in a single CognitiveMemoryClient class. Breakdown by concern:

  • Constants + module helpers: ~548 lines → common.py
  • Core CRUD (store/get/delete/search/recall): ~435 lines → stays in client.py
  • Edges (relate/edge_get/edge_search/edge_update/edge_delete): ~352 lines → edges.py
  • Embeddings (embed/semantic_recall/provider fallback): ~209 lines → embeddings.py
  • Decay/Core/Reflect (decay scoring, CORE.md gen, reflection): ~1097 lines → analysis.py (biggest chunk)
  • CLI parser + dispatch: ~463 lines → cli.py or main.py
  • Index/state/git plumbing: ~115 lines → internal helpers

Refactor considerations:

  • MCP server imports from client import CognitiveMemoryClient — needs updating
  • CLI wrapper claude-memory uses exec uv run python client.py — needs package structure
  • Systemd services depend on the wrapper — must test after
  • Could use mixin classes or composition to split the monolithic class
  • Similar to the Major Domo CLI modular refactor (that went well)

Priority: near-future. Nothing is broken but finding anything requires line-number hunting.