Skip to content

Split store.js: pure helpers and Store method groups into focused modules (#1447 pass P) - #1469

Merged
currentbits merged 8 commits into
mainfrom
coder/refactor-p-split-store-js-827b15
Oct 5, 2026
Merged

currentbits merged 8 commits into
mainfrom
coder/refactor-p-split-store-js-827b15

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Round 6, pass P of #1447. electron/store.js (4,185 lines) persists all app state. It goes to 2,052 lines; seven focused modules now hold the rest.

Part 1: pure helpers out of the file

Module Lines Holds
store-migrate.js 583 pure thread/project/template migrations
store-normalize.js 550 settings/profile/quota normalisers and validators
store-util.js 303 spend/usage/shard-id helpers

Part 2: method groups out of class Store

Module Lines Methods
store-settings-methods.js 363 settings read/patch
store-usage-methods.js 208 usage/spend ledger
store-search-methods.js 160 full-content thread search
store-templates-methods.js 117 workflow templates

Each method group is written as a class. store.js copies the groups' property descriptors onto Store.prototype with Object.defineProperty, and throws if a name is defined twice. This keeps methods non-enumerable (as in the class body), keeps accessors intact, and never shadows silently. None of the moved methods uses super or #private fields.

Untouched: constructor, load, _readFile, save, flush and _writeAtomic are byte-identical to main. The debounce, atomic write and backup handling don't move.

Checked

  • Same API: the 29 module.exports keys are identical. Store.prototype has the same 93 own properties, with identical descriptor shapes (enumerable / writable / configurable / value vs accessor) and zero enumerable keys, as on main.
  • Pure move, ignoring indentation: the only non-move lines are the descriptor-copy loop above.
  • Real data: a read-only copy of the live coder-store.json (6 MB) was loaded with main's Store and with this branch's Store.
    • Loading isn't deterministic on its own: recovery of interrupted runs stamps Date.now() and random ids, so two loads with main's code differ in the same 8 places.
    • With Date.now and crypto.randomUUID frozen, both produce byte-identical normalised state: 6,043,877 bytes, the same SHA-256.
    • The copies were deleted afterwards; the original was never written.
  • Tests:
    • Full electron suite (CI-like env, machine at heavy load): 4122/4126. The 4 failures are the known mcp-inject / memory-sup load flakes, which pass 54/54 on their own.
    • npm run typecheck is clean.
    • Per the worker's own run, vite build and test:smoke A–E pass.

🤖 Generated with Claude Code

Willem and others added 7 commits October 5, 2026 13:38
….js (#1447)

Verbatim move of SPEND_RETENTION_DAYS, capList, localDayKey,
pruneSpendByDay, the spend/usage/run-artifact normalizers and the
thread shard-id encoders. store.js requires them back and re-exports
the same module.exports keys.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…alize.js (#1447)

Verbatim move of isHttpUrl, the agent-profile parse/normalize/validate
trio, matchingProfileId, the settings defaults and normalizeSettings
with its otel/webhook/quota-failover helpers. store.js requires back
what Store uses and drops the requires only the moved code needed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e-migrate.js (#1447)

Verbatim move of STANDARD_TEMPLATE and its clone/ensure helpers, the
kimi-model, automation, project and thread migrations with their
per-field normalizers, and backfillFromNotice. store.js requires back
what Store uses and drops the requires only the moved code needed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ethods.js (#1447)

Verbatim move of getUsage..getUsageThreadsByDay into a StoreUsageMethods
class. store.js copies its prototype descriptors onto Store.prototype,
so the methods keep class-method semantics (non-enumerable, same this,
same names) and instanceof is unchanged. A duplicate name throws at load.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…js (#1447)

Verbatim move of getSettings and setSettings into a StoreSettingsMethods
class, attached through the same descriptor copy as the usage methods.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ds.js (#1447)

Verbatim move of _buildSearchSnapshot, _cancelSearchWorker,
_runSearchScan and searchThreads into a StoreSearchMethods class. The
worker path still resolves threadSearch.js via __dirname, which is the
same electron/ directory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s-methods.js (#1447)

Verbatim move of listTemplates, getTemplate, saveTemplate and
removeTemplate into a StoreTemplateMethods class.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit d02841d into main Oct 5, 2026
6 checks passed
@currentbits
currentbits deleted the coder/refactor-p-split-store-js-827b15 branch October 5, 2026 12:49
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