Skip to content

Export Script Reimplements Service Layer (~700 LOC) #42

Description

@bradjin8

Repository: cppa-cursor-browser
Assignee: Brad @bradjin8
Severity: High

Problem

scripts/export.py operates as a ~700-line parallel implementation of the web application's data pipeline rather than a thin CLI wrapper over the service layer. It reimplements workspace scanning, database reading, conversation assembly, path normalization, and Markdown generation — logic that already exists in services/ and utils/. Functions like to_epoch_ms and normalize_file_path are copied rather than imported. This creates dual maintenance paths: a bug fix in utils/ must be independently located and replicated in the export script's private copy, with no static link between them.

Acceptance Criteria

  • scripts/export.py delegates workspace scanning to services/workspace_listing.py instead of reimplementing it
  • scripts/export.py delegates database reading to services/workspace_db.py instead of reimplementing it
  • scripts/export.py delegates conversation assembly to existing service-layer functions
  • All private copies of utility functions (to_epoch_ms, normalize_file_path, etc.) are removed; the script imports from utils/ instead
  • The sys.path.insert(0, project_root) hack is replaced by a proper import mechanism (requires item 4 — pyproject.toml)
  • Existing export script tests pass after refactoring (update test imports as needed)
  • CLI export produces identical output before and after refactoring (verified by diff on a sample workspace)

Implementation Notes

This is the largest structural refactoring item and has a dependency on item 4 (pyproject.toml). Without an installable package path, shared-module reuse remains mechanically awkward. Recommended sequencing: land pyproject.toml first, then refactor the export script in a follow-up PR. The service layer already encapsulates the patterns the script needs — workspace_db.py, workspace_listing.py, and workspace_tabs.py are the primary targets. Start by identifying every function in export.py that has a counterpart in services/ or utils/, build an import map, and replace incrementally. Keep the CLI argument parsing and output formatting in the script; move all data-access and transformation logic to shared modules.

References

  • Eval finding: test 4
  • Cluster: export-parallel-implementation
  • Related files: scripts/export.py, services/workspace_db.py, services/workspace_listing.py, services/workspace_tabs.py, utils/path_helpers.py
  • Compounds: COMPOUND-A (parallel impl blocks utility consolidation), COMPOUND-C (no install path + parallel implementation)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions