Skip to content

edit - #67

Merged
nazozokc merged 1 commit into
mainfrom
AI-agent
Jul 1, 2026
Merged

edit#67
nazozokc merged 1 commit into
mainfrom
AI-agent

Conversation

@nazozokc

@nazozokc nazozokc commented Jul 1, 2026

Copy link
Copy Markdown
Owner

コードリファクタリングと責務分離

Summary by CodeRabbit

  • New Features

    • Added TUI column visibility settings for tags, notes, and method columns, saved in app configuration.
    • Improved search behavior so filters can be partially specified, with sensible defaults applied automatically.
  • Bug Fixes

    • Standardized price and billing-cycle calculations across reports, forecasts, calendar, and payment views.
    • Improved config reset behavior by cleaning up saved configuration more reliably.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4daa7871-7103-4702-9efc-f7be899c6737

📥 Commits

Reviewing files that changed from the base of the PR and between 76834d3 and ca6008b.

📒 Files selected for processing (33)
  • subtrack/src/__tests__/db.test.ts
  • subtrack/src/__tests__/mcp.test.ts
  • subtrack/src/analytics.ts
  • subtrack/src/calendar.ts
  • subtrack/src/commands.ts
  • subtrack/src/compare.ts
  • subtrack/src/config.ts
  • subtrack/src/date-utils.ts
  • subtrack/src/db.ts
  • subtrack/src/db/connection.ts
  • subtrack/src/db/price-history.ts
  • subtrack/src/db/schema.ts
  • subtrack/src/db/subscriptions.ts
  • subtrack/src/db/tags.ts
  • subtrack/src/db/trials.ts
  • subtrack/src/db/usage.ts
  • subtrack/src/display-constants.ts
  • subtrack/src/display.ts
  • subtrack/src/export.ts
  • subtrack/src/forecast.ts
  • subtrack/src/mcp.ts
  • subtrack/src/optimize.ts
  • subtrack/src/payment.ts
  • subtrack/src/search.ts
  • subtrack/src/subscription.ts
  • subtrack/src/timeline.ts
  • subtrack/src/trial.ts
  • subtrack/src/tui/config.ts
  • subtrack/src/tui/context/app-context.tsx
  • subtrack/src/tui/screens/calendar-screen.tsx
  • subtrack/src/tui/screens/reports/helpers.ts
  • subtrack/src/types.ts
  • subtrack/src/upcoming.ts

📝 Walkthrough

Walkthrough

This PR refactors subtrack/src/db.ts into modular db/* files (connection, schema, subscriptions, tags, trials, usage, price-history), extracts config CLI handlers into config.ts, moves MCP helpers (nextDateForCycle, calcUpcoming, searchSubscriptions) into upcoming.ts/search.ts, introduces date-utils.ts and display-constants.ts as shared sources for periodFactor and table styling, and adds a TUI column-settings module, updating import wiring across many consumer files.

Changes

Database module split

Layer / File(s) Summary
db.ts re-export entrypoint
subtrack/src/db.ts
Replaces prior inline DB logic with re-exports from new db/* modules.
Connection, locking, backup/restore
subtrack/src/db/connection.ts
Implements SQL.js init, directory validation, cross-process locking, save/load, SQL mapping helpers, backup discovery, multi-format restore, and hash-based backup integrity checks.
Schema and migrations
subtrack/src/db/schema.ts
Creates subscriptions, tags, subscription_tags, llm_usage, trials, price_history tables, adds conditional column migrations, and logs integrity check warnings.
Subscriptions CRUD
subtrack/src/db/subscriptions.ts
Adds getSubscriptions, writeSubscription, deleteSubscription, getSubscription, updateSubscription, and mapTags with tag transaction handling.
Tag utilities
subtrack/src/db/tags.ts
Adds getAllTags, tagsSubscription, getTagsWithCount, renameTag, deleteTag, pruneTags.
Trials CRUD
subtrack/src/db/trials.ts
Adds writeTrial, getTrials, getTrial, deleteTrial, getTrialsExpiringSoon.
LLM usage tracking
subtrack/src/db/usage.ts
Adds addLlmUsage, addLlmUsageFromLog, batchAddLlmUsageFromLog, getLlmUsage, deleteLlmUsage, and cost total aggregation functions.
Price history
subtrack/src/db/price-history.ts
Adds PriceHistoryEntry type, writePriceHistory, getPriceHistory, getAllPriceChanges.

Config handler extraction

Layer / File(s) Summary
Config persistence and CLI handlers
subtrack/src/config.ts
Adds saveConfig, handleConfigList, handleConfigGet, handleConfigSet, handleConfigReset, and unlinkSync usage for reset.
commands.ts wiring
subtrack/src/commands.ts
Updates import sources and replaces inline config handlers with a re-export from config.ts.

MCP helper extraction

Layer / File(s) Summary
search.ts defaulting behavior
subtrack/src/search.ts
Exports searchSubscriptions with optional field flags defaulting to search-all when omitted.
upcoming.ts export changes
subtrack/src/upcoming.ts
Exports nextDateForCycle and switches formatPrice import to price.ts.
mcp.ts import wiring
subtrack/src/mcp.ts
Removes in-file logic, imports periodFactor/calcUpcoming/searchSubscriptions from new modules.
mcp.test.ts updates
subtrack/src/__tests__/mcp.test.ts
Updates import sources and assertions for the new result shape.

Shared date/price/table-style extraction

Layer / File(s) Summary
date-utils.ts and types.ts cleanup
subtrack/src/date-utils.ts, subtrack/src/types.ts
Moves OCCURRENCES_PER_YEAR/periodFactor to date-utils.ts and removes them from types.ts.
db.test.ts import update
subtrack/src/__tests__/db.test.ts
Updates periodFactor tests to import from date-utils.ts.
display-constants.ts
subtrack/src/display-constants.ts
New module exporting TABLE_CHARS and TABLE_STYLE.
display.ts wiring
subtrack/src/display.ts
Removes local table constants and formatPrice re-export; imports from display-constants.ts.
Consumer import updates
subtrack/src/analytics.ts, subtrack/src/calendar.ts, subtrack/src/compare.ts, subtrack/src/forecast.ts, subtrack/src/optimize.ts, subtrack/src/payment.ts, subtrack/src/timeline.ts, subtrack/src/trial.ts, subtrack/src/export.ts, subtrack/src/subscription.ts, subtrack/src/tui/screens/calendar-screen.tsx, subtrack/src/tui/screens/reports/helpers.ts
Updates modules to import formatPrice, periodFactor/OCCURRENCES_PER_YEAR, and TABLE_CHARS/TABLE_STYLE from their new sources.

TUI column settings

Layer / File(s) Summary
tui/config.ts settings module
subtrack/src/tui/config.ts
Adds TuiColumnSettings type and loadTuiColumns/saveTuiColumns persistence functions.
app-context.tsx wiring
subtrack/src/tui/context/app-context.tsx
Updates import path for TUI config functions and type.

Estimated code review effort: 4 (Complex) | ~75 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant restoreDb
  participant Filesystem
  participant SqlJs

  Caller->>restoreDb: restoreDb(backupPath)
  restoreDb->>Filesystem: read backup file
  restoreDb->>restoreDb: detect gzip/encryption
  restoreDb->>SqlJs: load decoded database
  SqlJs-->>restoreDb: validate subscriptions table
  restoreDb->>Filesystem: overwrite active DB file
  restoreDb->>SqlJs: runMigrations(db)
Loading

Possibly related PRs

  • nazozokc/subtrack#6: Uses the same db.ts/connection.ts primitives (saveDb, getDbPath) introduced here for backup operations.
  • nazozokc/subtrack#13: Directly related to the same subscriptions/tags DB operations now being extracted into db/* modules.
  • nazozokc/subtrack#63: Depends on the periodFactor helper introduced in date-utils.ts for monthly-normalized total calculations.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch AI-agent

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nazozokc
nazozokc merged commit b6a21ea into main Jul 1, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant