Skip to content

Refactor: replace level magic numbers with LevelPolicy object #83

Closed

Description

@itdove

Problem

The level 1 (project) redesign in #80 introduced == 1 / > 1 / < 2 / {0, 1} magic number comparisons scattered across 6 files:

  • server.py: _resolve_level, store_knowledge, negate_knowledge, delete_knowledge
  • sqlite.py: _build_filter
  • cli.py: _build_hierarchy_filters, _cmd_config_add_level
  • manager.py: get_project_config validation
  • engine.py: _sync_project_levels

Adding a third storage behavior (e.g., level 0 writes to a local file) would require touching all of these.

Proposed solution

Replace the raw level integer with a LevelPolicy dataclass returned by _resolve_level:

@dataclass
class LevelPolicy:
    level: int
    name: str
    repo_url: str | None
    repo_branch: str | None
    writable: bool
    stores_locally: bool      # level 0 and 1: True, level 2+: False
    creates_pr: bool           # level 1 and 2+: True, level 0: False
    locally_deletable: bool    # level 0 and 1: True, level 2+: False
    pr_path_fn: Callable[[str], str] | None  # level 1: .lore/knowledge/<key>.md, level 2+: <key>.md

Then store_knowledge becomes:

policy = _resolve_level(level)
if policy.creates_pr and policy.repo_url:
    pr_url = _create_shared_pr(..., file_path_override=policy.pr_path_fn(key) if policy.pr_path_fn else None)
if policy.stores_locally:
    # SQLite upsert

No branching on magic numbers. New level behaviors are added by defining a new policy, not by editing every consumer.

Files affected

  • src/lore/mcp/server.py — _resolve_level returns LevelPolicy, consumers use policy fields
  • src/lore/store/sqlite.py — _build_filter takes implicit_levels param instead of hardcoding {0, 1}
  • src/lore/config/models.py — LevelPolicy dataclass
  • src/lore/cli.py — _build_hierarchy_filters uses policy
  • src/lore/sync/engine.py — _sync_project_levels uses policy

Origin

Identified by /simplify altitude review on #80 changes.

Activity

  1. self-assigned this
    on Jul 27, 2026
  2. itdove commented on Jul 27, 2026

    @itdove
    OwnerAuthor

    Pull request created: #86

  3. itdove commented on Jul 27, 2026

    @itdove
    OwnerAuthor

    ✅ Session Complete

    Project: lore
    Goal: #83: Refactor: replace level magic numbers with LevelPolicy object
    Time Spent:
    0h 38m total

    • dvernier: 0h 37m
    • unknown: 0h 0m
      Branch: 83

    The session created 1 new files and modified 8 existing files. Work included: made 23 edits, wrote 1 files, ran 22 commands.

    Generated by DevAIFlow

  4. added a commit that references this issue on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions