Skip to content

refactor(vault): split notes.ts into focused files behind facade (Phase 3.1) - #232

Merged
h4yfans merged 1 commit into
mainfrom
debt/phase-3-u1-vault-notes-split
Apr 16, 2026
Merged

refactor(vault): split notes.ts into focused files behind facade (Phase 3.1)#232
h4yfans merged 1 commit into
mainfrom
debt/phase-3-u1-vault-notes-split

Conversation

@h4yfans

@h4yfans h4yfans commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Splits the 1,546-line vault/notes.ts god-file (43 exports) into 6 focused files behind a re-export facade.
  • Zero consumer changes — all 15 files that import from ./notes keep working (facade preserves public API).
  • Zero behavior changes — this is a pure structural refactor.

Per .claude/plans/tech-debt-remediation.md Phase 3.1.

Split

File LOC Responsibility
notes-io.ts 55 Path utilities (getNotesDir, toAbsolutePath, toRelativePath, emitNoteEvent)
notes-crud.ts 733 CRUD + folders + utilities + import + 14 exported types
notes-queries.ts 213 Cross-note queries (listNotes, getTagsWithCounts, getNoteLinks + helpers)
notes-rename.ts 189 renameNote, moveNote
notes-versions.ts 244 Snapshots + version history (5 functions + 3 threshold constants)
notes.ts 13 Facade re-exporting all 43 original exports

notes-queries.ts was pulled out to keep notes-crud.ts under the 800-line pre-commit guardrail (set by P.1 / P.2 of the tech-debt plan). Clean architectural grouping — cross-note reads cluster naturally together.

Why

  • 43 exports in 1 file meant any consumer could touch any responsibility. The sign-in/sign-out CRDT bug in the memory log was partly caused by mixed concerns.
  • Sub-responsibilities now live next to tests that exercise them; new contributors touch a smaller surface per change.

Test plan

  • pnpm typecheck:node passes on the split
  • Existing notes.test.ts (1,220 LOC, uses * as noteVault namespace import) survives unchanged
  • Full vitest run: 5,862 desktop tests pass (the handful of failures are pre-existing renderer UI timeouts under CPU contention — not in the vault/notes scope)
  • Manual dev-app smoke: create/edit/rename/delete note + restore version

Per .claude/plans/tech-debt-remediation.md Phase 3.1. The 1,546-line
notes.ts with 43 exports is split into 6 focused files. notes.ts stays as
a re-export facade so none of the 15 consumer files need updating.

- notes-io.ts (55 LOC): path utilities — getNotesDir, toAbsolutePath,
  toRelativePath, emitNoteEvent
- notes-crud.ts (733 LOC): CRUD + folders + utilities + import
  (createNote, updateNote, deleteNote, getNoteById, getFileById,
   getNoteByPath, noteExists, folder management, openExternal,
   revealInFinder, importFiles, all 14 exported types)
- notes-queries.ts (213 LOC): cross-note queries (listNotes,
  getTagsWithCounts, getNoteLinks, noteToListItem,
  extractAllLinkContexts) — pulled out to keep notes-crud under
  the 800-line pre-commit guardrail
- notes-rename.ts (189 LOC): renameNote, moveNote
- notes-versions.ts (244 LOC): snapshots + version history
  (createSnapshot, maybeCreateSignificantSnapshot, getVersionHistory,
   getVersion, restoreVersion + 3 threshold constants)
- notes.ts (13 LOC): facade re-exporting all 43 original exports

Type-only imports resolve the notes-crud ↔ notes-versions cycle. Existing
notes.test.ts (1,220 LOC, uses namespace import) runs unchanged.
@h4yfans
h4yfans force-pushed the debt/phase-3-u1-vault-notes-split branch from 7bb6768 to 7b2f093 Compare April 16, 2026 14:02
@h4yfans
h4yfans merged commit 9cad7b1 into main Apr 16, 2026
2 checks passed
h4yfans added a commit that referenced this pull request May 6, 2026
Per .claude/plans/tech-debt-remediation.md Phase 3.1. The 1,546-line
notes.ts with 43 exports is split into 6 focused files. notes.ts stays as
a re-export facade so none of the 15 consumer files need updating.

- notes-io.ts (55 LOC): path utilities — getNotesDir, toAbsolutePath,
  toRelativePath, emitNoteEvent
- notes-crud.ts (733 LOC): CRUD + folders + utilities + import
  (createNote, updateNote, deleteNote, getNoteById, getFileById,
   getNoteByPath, noteExists, folder management, openExternal,
   revealInFinder, importFiles, all 14 exported types)
- notes-queries.ts (213 LOC): cross-note queries (listNotes,
  getTagsWithCounts, getNoteLinks, noteToListItem,
  extractAllLinkContexts) — pulled out to keep notes-crud under
  the 800-line pre-commit guardrail
- notes-rename.ts (189 LOC): renameNote, moveNote
- notes-versions.ts (244 LOC): snapshots + version history
  (createSnapshot, maybeCreateSignificantSnapshot, getVersionHistory,
   getVersion, restoreVersion + 3 threshold constants)
- notes.ts (13 LOC): facade re-exporting all 43 original exports

Type-only imports resolve the notes-crud ↔ notes-versions cycle. Existing
notes.test.ts (1,220 LOC, uses namespace import) runs unchanged.
@h4yfans
h4yfans deleted the debt/phase-3-u1-vault-notes-split branch May 6, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant