Skip to content

Stop hand-editing the @bb/db data export list - #7554

Merged
ymichael merged 2 commits into
mainfrom
bb/stop-hand-editing-the-bb-db-data-export-list-thr_yf5f8s7zrb
Nov 16, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/stop-hand-editing-the-bb-db-data-export-list-thr_yf5f8s7zrb

Conversation

@ymichael

@ymichael ymichael commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

packages/db/src/data/index.ts re-exported every public data function, type, and constant by name: 582 lines, 512 names across 38 modules. Adding or renaming any data function meant editing that list, and 82 commits touched it in the last 60 days, so two open PRs that each add a data function usually conflicted there. The list also served as the public/private filter for @bb/db. It hid 11 helper modules entirely and, inconsistently, about 20 helpers in otherwise-public modules. Only one of those hidden groups was deliberate: the environment-lifecycle writers, which apps/server reaches through @bb/db/internal-environment-lifecycle.

What changed

  • packages/db/src/data/index.ts is now one export * from "./<module>.js" line per public module (38 lines). A module is public if and only if it is listed there; unlisted modules stay package-private. Adding, renaming, or deleting a function in a public module no longer touches a shared file. Only a new public module adds one line. That happened in 9 of the 82 commits, and a sorted one-line-per-module list conflicts only on adjacent insertions.
  • The deliberately internal environment writers moved out of environments.ts into a new private module, packages/db/src/data/environment-lifecycle.ts: applyEnvironmentLifecycleEvent, applyEnvironmentLifecycleEventInTransaction, recordProvisionedEnvironmentWorkspace, and the shared updateEnvironmentMetadataRecord. So the root @bb/db still does not expose them. updateEnvironmentMetadata and recordEnvironmentCurrentBranch share the private record writer, and every writer reads through getEnvironment, so those three live in that module too. environments.ts imports and re-exports them, so they stay public. The private module imports nothing from environments.ts, so the dependency runs one way and the data modules still have no value-import cycles, as on main. @bb/db/internal-environment-lifecycle now re-exports from the new module and exports the same 4 values and 2 types as before.
  • CreateProjectSourceInput was declared, with different shapes, in both projects.ts and project-sources.ts. Star exports reject that (TS2308), and no code outside the two files used either alias, so both aliases are deleted and their one use each now names the underlying type.
  • The old barrel also re-exported COMPLETED_EVENT_OUTPUT_RETENTION_MS and RETAINED_EVENT_OUTPUT_TARGETS from src/retained-event-output.ts (not a data module). That re-export moved to src/index.ts.
  • Query-cost cases for the six moved functions are now keyed packages/db/src/data/environment-lifecycle.ts#…, because listQueryFunctions keys functions by their declaring file. Relative imports in environments.test.ts, environment-lifecycle.test.ts, and hosts-environments-cases.ts point at the new file.

Export surface change (computed with the TypeScript checker over src/index.ts and src/internal-environment-lifecycle.ts, before vs after):

  • Removed: none. Every existing @bb/db and @bb/db/internal-environment-lifecycle import keeps working, so no caller changed.
  • Added to @bb/db: 230 types and 20 values that their modules already exported but the list left out. Most of the types already appear in public signatures, for example CreateThreadInput and ListThreadsOptions. The values: ACTIVE_PENDING_INTERACTION_STATUSES, ACTIVE_THREAD_STATUSES, appendStoredThreadEventInTransaction, bumpThreadEventRewriteGeneration, copyRetainedEventOutputs, getContextWindowUsagePruningBoundarySequence, listActiveVisiblePinnedThreadRoots, markHostSeen, MAX_COMPLETED_EVENT_OUTPUT_MIGRATION_EVENT_DATA_BYTES, NON_TERMINAL_SESSION_STATUSES, prepareLegacyImageGenerationOutputData, PRUNABLE_THREAD_EVENT_TYPES, pruneContextWindowUsageEventsInTransaction, pruneTokenUsageEventsInTransaction, resolveStoredProviderSessions, THREAD_PRUNING_ADVANCE_WORK_BUDGET_MS, ThreadLifecycleEventNotAppliedError, toProjectSource, upsertThreadSearchSegmentBatch, upsertThreadSearchSegments. Each is a sibling of names that were already public (for example, the plural appendStoredThreadEventsInTransaction and getStoredProviderSession were public), so hiding them was incidental, not a boundary.

Alternatives rejected:

  • Delete the barrel and use a @bb/db/data/* subpath: this would rewrite imports in 451 files, conflict with every open PR, and expose the private helper modules.
  • Generate the barrel: this would add a Turbo task and a gitignored artifact to produce the same thing export * already gives.
  • Keep named exports but split them per module: the central-list conflicts would remain.

No wire, CLI, or plugin-API change.

How you verified

  • Export-surface diff before vs after with the TypeScript checker, over src/index.ts and src/internal-environment-lifecycle.ts: 0 names removed; the additions are listed above.
  • Import cycles: a scan of value imports among packages/db/src/data/*.ts finds none on main and none on this branch.
  • Collision safety: temporarily re-adding a duplicate type name made tsrs --noEmit fail with TS2308: Module "./project-sources.js" has already exported a member named ..., so a future clash fails typecheck instead of silently dropping a name.
  • pnpm exec turbo run typecheck --filter='...@bb/db' passed (@bb/db, @bb/server, @bb/host-daemon, @bb/scripts, @bb/integration-tests).
  • vitest run on test/data/environments, environment-lifecycle, projects, project-sources, and prompt-history: 50/50 passed.
  • Query-cost coverage (listQueryFunctions vs QUERY_COST_CASES): no missing cases, no stale cases.
  • oxlint on the changed files: clean. lint:type-aware --filter=@bb/db: passed.
  • CI runs the full suites.

🤖 Generated with Claude Code

AGENT GENERATED

ymichael and others added 2 commits November 13, 2026 23:32
packages/db/src/data/index.ts listed 512 names by hand and conflicted
whenever two PRs added a data function. It is now one export * line per
public module. Environment lifecycle writers move to a private
data/environment-lifecycle.ts so @bb/db still does not expose them; the
@bb/db/internal-environment-lifecycle subpath is unchanged. No export is
removed; 230 types and 20 helpers their modules already exported are now
also reachable from @bb/db.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
data/environment-lifecycle.ts imported getEnvironment from
data/environments.ts while environments.ts re-exported from it. Move
getEnvironment into the private module so the dependency runs one way;
environments.ts still re-exports it, so @bb/db is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 49982f7 into main Nov 16, 2026
35 checks passed
@ymichael
ymichael deleted the bb/stop-hand-editing-the-bb-db-data-export-list-thr_yf5f8s7zrb branch November 16, 2026 18:50
mistakeknot added a commit to mistakeknot/aleph that referenced this pull request Nov 17, 2026
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