Skip to content

M27: [Major] Code duplication — FileRecord mapper in 3 places, _FileOrganizer_quarantine literal in 2 files #74

Description

@curtyo18

Summary

Two duplication clusters in the engine. Bundled because they're small fixes with the same shape: extract + import.

A. row → FileRecord mapper open-coded in three places

The same 20-field row-to-record mapping appears in:

  • packages/engine/src/catalog/files-repo.ts:118-140
  • packages/engine/src/organize/planner.ts:183-205
  • packages/engine/src/dedupe/planner.ts:50-79

Per standards/code-duplication.md: "Same multi-line block in three or more places... Severity: Important." A new column added to the files schema will need to be added in three spots. The two planners may also silently drift on which optional columns they read (e.g., lastVerifiedAt).

B. _FileOrganizer_quarantine literal in two files

  • packages/engine/src/quarantine/quarantine.ts:22const QUARANTINE_DIR = '_FileOrganizer_quarantine';
  • packages/engine/src/organize/applier.ts:13 (reviewer-cited as QUARANTINE_DIR_NAME) — same string, different constant name.

If either is renamed, the empty-dir sweep guard at applier.ts:211 silently breaks (it uses the local constant to identify the quarantine subdirectory and skip it). Per code-duplication.md: "Inline literals duplicated across files... extract to a named constant."

Background

From the 2026-05-17 multi-agent full-repo review.

Acceptance criteria

A. Mapper extraction

  • Export a toFileRecord(row: SqliteRow): FileRecord function from packages/engine/src/catalog/files-repo.ts (or a sibling files-mapper.ts if you want to keep the repo class focused).
  • organize/planner.ts:183-205 and dedupe/planner.ts:50-79 import and use it; the open-coded mapping is deleted from both.
  • Tests: existing planner/repo tests pass unchanged (the refactor is pure structural).
  • An optional explicit test on toFileRecord covering all 20 fields including nullable / coerce-to-null branches.

B. Quarantine dir constant

  • Export QUARANTINE_DIR_NAME = '_FileOrganizer_quarantine' from packages/engine/src/quarantine/quarantine.ts (or @fileorganizer/shared if it's needed by tests too).
  • organize/applier.ts imports the named export; the local duplicate constant is deleted.
  • Any other site that has the literal (grep _FileOrganizer_quarantine to find them) uses the import.

Files affected (likely)

  • packages/engine/src/catalog/files-repo.ts — export toFileRecord
  • packages/engine/src/organize/planner.ts:183-205 — use it
  • packages/engine/src/dedupe/planner.ts:50-79 — use it
  • packages/engine/src/quarantine/quarantine.ts:22 — export QUARANTINE_DIR_NAME
  • packages/engine/src/organize/applier.ts:13 — import

Out of scope

  • Larger reorganization of repos / planners
  • Other 2-place duplications (defer until they become 3-place)

References

  • Standards: standards/code-duplication.md
  • Code: paths above

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions