Skip to content

Module ownership is diffused across thin facades and monoliths #103

Closed

Description

@Sinity

Context

Several core Polylogue subsystems still mix unrelated responsibilities in single files or hide real ownership behind pass-through modules. polylogue/sources/drive_client.py currently spans cached credential loading, OAuth/bootstrap decisions, retrying Drive transport calls, folder/file lookup helpers, and source traversal. polylogue/storage/backends/async_sqlite.py still combines conversation, message, attachment, raw payload, run, and stats SQL with backend orchestration. polylogue/schemas/schema_inference.py blends provider sampling, field statistics, privacy heuristics, annotation, and schema emission. Shared helpers like formatting, theme tokens, and logging also still live under polylogue/lib/ even when the real owners are rendering, UI/site output, or project-wide runtime setup.

On top of that, the tree still contains a meaningful number of thin facades and package shims such as polylogue/export.py, polylogue/render_paths.py, polylogue/storage/async_index.py, polylogue/cli/analytics.py, and several package __init__ modules that mostly forward imports from elsewhere. Those files keep imports superficially convenient, but they make it harder to see which package actually owns a behavior and which import path should be considered canonical.

Motivation

This has become a maintenance problem rather than just an aesthetic one. The current layout makes it difficult to answer basic review questions like "where does Drive auth stop and source iteration begin?" or "is this SQL planner logic part of the backend contract or just a helper hidden in the connection layer?" It also makes mutation-guided testing noisier than it should be, because owner suites need repeated concentration passes before the surviving semantic gaps are even legible. The same fronts keep surfacing: Drive auth/filter logic, query/filter planning, schema generation internals, and broad helper modules that attract unrelated code.

The packaging story is also showing the same pressure. The project is no longer just a single CLI binary; it exposes library-level surfaces that should import cleanly, but the current build/layout still leans on application-style assumptions and a large amount of eager import wiring. If we do not tighten the boundaries now, future work in the pipeline, MCP surface, schema tooling, and Drive acquisition layer will keep paying the cost of ambiguous ownership.

Scope

In scope for this refactor:

  • split Drive responsibilities under polylogue/sources/ into distinct auth, transport/gateway, source traversal, and typed data/error modules
  • move conversation/message/attachment/raw/runs/stats SQL and related filter builders out of polylogue/storage/backends/async_sqlite.py into dedicated query-owned modules
  • separate schema sampling, field statistics, privacy heuristics, and schema-generation logic from polylogue/schemas/schema_inference.py while preserving the provider-facing generation entry points
  • move shared formatting, theme, and logging helpers into the packages that actually own those concerns
  • delete thin re-export modules where they no longer add semantics, and update CLI, pipeline, site, and MCP imports to resolve through the new canonical owners
  • make the package build/import surface reflect the fact that Polylogue is both a CLI and a Python package

Out of scope:

  • changing the user-facing command set
  • changing provider parsing semantics
  • redesigning the database schema itself
  • reworking benchmark or mutation policy beyond the minimum needed to keep the architectural move measurable

Acceptance criteria

  • Drive auth, Drive API transport, Drive source traversal, and Drive-specific typed errors/constants live in separate modules, and the CLI auth/sync flows still resolve through a coherent polylogue.sources surface.
  • polylogue/storage/backends/async_sqlite.py no longer owns every SQL family directly; conversation, message, attachment, raw, run, and stats queries each have dedicated homes under polylogue/storage/backends/queries/, and row hydration/mapping logic is no longer mixed into record-definition code.
  • Schema generation preserves the existing public generation surface, but sampling, field-stat collection, privacy heuristics, and schema emission are split into separately owned modules.
  • Formatting, theme, and logging helpers move out of generic polylogue.lib.* catch-alls into rendering/UI/project-level modules, and thin facade modules that only forward imports are removed.
  • CLI, pipeline, site, and MCP imports compile and run against the new layout, the top-level polylogue package still imports cleanly, and the Nix build still produces a working polylogue program.
  • The full pytest lane plus focused Drive, filters, storage, schema, CLI, and MCP suites pass after the split.

Activity

  1. added
    type:refactor
    faux-pull-request
    on Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cliarea:mcparea:nixarea:parserarea:pipelinearea:qaarea:schemaarea:storagefaux-pull-requesttype:refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions