Skip to content

Monolithic CLI, pipeline, and source parsing modules concentrate too many responsibilities #49

Closed

Description

@Sinity

Context

Three modules have grown past comfortable working size:

  • click_app.py (830 lines): Every CLI command definition, all formatting helpers (format_counts, format_cursors, format_index_status), source resolution logic, the AppEnv dataclass, plain-mode detection, and the summary printer. Adding a new command or modifying output formatting requires navigating the entire file.

  • run.py (510 lines): Content hashing (_hash_text, _hash_payload, _hash_file), ID generation (_conversation_id, _message_id, _attachment_content_id), existing-record lookups, ingest preparation, pipeline orchestration, run JSON writing, and the re-run detection logic. The hashing functions are duplicated from source_ingest.py.

  • source_ingest.py (560 lines): Provider detection heuristics, five different parsing strategies (ChatGPT mapping, Claude chat_messages, Claude Code sessions, Codex prompt/completion, Drive chunkedPrompt), role normalization, attachment extraction, and file iteration. Each provider's logic is interleaved with generic dispatch.

Carrying costs

  1. Duplicate code: SHA-256 hashing is implemented identically in both run.py and source_ingest.py. Timestamp formatting exists in click_app.py with no shared utility.

  2. Testing friction: Testing a single provider's parsing requires importing the entire source_ingest module with all its dependencies. Similarly, testing CLI formatting pulls in every command's imports.

  3. Merge conflicts: Any two branches touching CLI commands will conflict in the same 830-line file. Same for pipeline changes in run.py.

  4. Feature resistance: Adding a web server, search filters, or concurrent ingestion to these monoliths means either bloating them further or doing ad-hoc extraction mid-feature.

Scope

In scope:

  • Decompose click_app.py into a commands subpackage plus shared helpers
  • Extract pipeline orchestration from run.py into a pipeline/ package
  • Split provider-specific parsing from source_ingest.py into importers/ modules
  • Consolidate duplicated utilities (hashing, timestamps) into a core/ package
  • Separate render output path from archive root in config

Out of scope:

  • Async pipeline execution (concurrency is fine, async conversion is separate)
  • Provider plugin system (importers are still hard-coded dispatch)
  • Schema migration tooling

Acceptance criteria

  • click_app.py is under 50 lines; each command lives in its own module
  • run.py contains only re-exports; actual logic lives in pipeline/
  • Each provider has a dedicated module under importers/ with looks_like() and parse() functions
  • No duplicate hashing implementations; core/hashing.py is the single source
  • render_root is a separate config field with environment variable override
  • Existing import paths from run.py still work (backward-compatible facade)

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:parserarea:pipelinearea: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