feat(8.0)!: delete fork/branch/commit/history/versions — superseded by the Db API

The COW version-control surface (fork, branches, checkout, commit,
getHistory/streamHistory, asOfCommit, brain.versions) is gone, along with
its subsystems: src/versioning/, the COW object store (CommitLog,
CommitObject, RefManager, TreeObject), HistoricalStorageAdapter, and the
TypeAwareHNSWIndex path it kept alive. The Db API (now/transact/asOf/
with/persist/restore) is the one versioning model in 8.0.

Survivors and replacements:
- BlobStorage survives (the VFS stores file content through it), relocated
  to src/storage/blobStorage.ts with binaryDataCodec.ts; its adapter
  interface is now BlobStoreAdapter, slimmed to the consumed surface
  (write/read/has/delete/getMetadata + MIME-aware compression policy).
- brain.migrate() backup branches are replaced by persist-before-migrate:
  MigrateOptions.backupTo persists a hard-link snapshot of the current
  generation before any transform runs; MigrationResult.backupPath reports
  it, and brain.restore(path) brings it back wholesale.
- CLI: cow.ts (fork/branch/checkout/history/migrate) is replaced by
  snapshot.ts — snapshot <path>, restore <path>, history (tx-log),
  generation.
- New public read API: brain.transactionLog({limit}) exposes the reified
  tx-log (generation/timestamp/meta, newest first) that backs the CLI
  history command; TxLogEntry is exported.

Tests: superseded suites deleted; fork/commit blocks excised from shared
suites; BlobStorage tests relocated + reworked against the slimmed store;
migration tests now prove the backupTo snapshot/restore round trip; new
transactionLog coverage in db-mvcc.
This commit is contained in:
David Snelling 2026-06-10 15:22:47 -07:00
parent 431cd64406
commit 8f93add705
64 changed files with 1444 additions and 16313 deletions

View file

@ -192,7 +192,7 @@ export class MigrationRunner {
* Entity-level errors are tracked (not thrown). If maxErrors is exceeded, migration
* stops early and returns partial results with errors.
*/
async run(options?: Pick<MigrateOptions, 'onProgress' | 'maxErrors'>): Promise<Omit<MigrationResult, 'backupBranch'>> {
async run(options?: Pick<MigrateOptions, 'onProgress' | 'maxErrors'>): Promise<Omit<MigrationResult, 'backupPath'>> {
const state = await this.getState()
const pending = this.getPendingMigrations(state)
@ -259,93 +259,6 @@ export class MigrationRunner {
}
}
/**
* Run specific migrations without checking completion state.
* Used for branch iterations where the state on main says "completed"
* but branch-local entities still need transforming.
*
* Safe because transforms are idempotent (return null when already applied).
* Does NOT save migration state the authoritative state lives on main.
*/
async runMigrations(
migrations: Migration[],
options?: Pick<MigrateOptions, 'onProgress' | 'maxErrors'>
): Promise<Omit<MigrationResult, 'backupBranch'>> {
if (migrations.length === 0) {
return { migrationsApplied: [], entitiesProcessed: 0, entitiesModified: 0, errors: [] }
}
let totalProcessed = 0
let totalModified = 0
const appliedMigrations: string[] = []
const errors: MigrationError[] = []
const maxErrors = options?.maxErrors ?? DEFAULT_MAX_ERRORS
const batchConfig = this.storage.getBatchConfig()
const batchSize = batchConfig.maxBatchSize
const batchDelay = batchConfig.batchDelayMs
for (const migration of migrations) {
if (errors.length >= maxErrors) break
let processed = 0
let modified = 0
if (migration.applies === 'nouns' || migration.applies === 'both') {
const result = await this.migrateNouns(migration, 0, batchSize, batchDelay, errors, maxErrors, options?.onProgress)
processed += result.processed
modified += result.modified
}
if (migration.applies === 'verbs' || migration.applies === 'both') {
if (errors.length < maxErrors) {
const result = await this.migrateVerbs(migration, 0, batchSize, batchDelay, errors, maxErrors, options?.onProgress)
processed += result.processed
modified += result.modified
}
}
totalProcessed += processed
totalModified += modified
if (modified > 0) {
appliedMigrations.push(migration.id)
}
}
return {
migrationsApplied: appliedMigrations,
entitiesProcessed: totalProcessed,
entitiesModified: totalModified,
errors
}
}
/**
* Clean up old system:backup branches created by previous migrations.
* Identifies backups via ref metadata (not by name prefix).
*/
async cleanupOldBackups(): Promise<void> {
const refManager = this.storage.refManager
if (!refManager) return
const refs = await refManager.listRefs()
const currentBranch = this.storage.currentBranch || 'main'
for (const ref of refs) {
if (
ref.metadata?.type === 'system:backup' &&
ref.name.startsWith('refs/heads/') &&
ref.name !== `refs/heads/${currentBranch}`
) {
const branchName = ref.name.replace('refs/heads/', '')
try {
await refManager.deleteRef(branchName)
} catch {
// Ignore — branch may be current or protected
}
}
}
}
// ─── Private helpers ───────────────────────────────────────────────
private async migrateNouns(
@ -524,12 +437,11 @@ export class MigrationRunner {
private async saveResumeState(migrationId: string, offset: number): Promise<void> {
const state = await this.getState()
const branch = this.storage.currentBranch || 'main'
await this.saveState({
completedVersion: state?.completedVersion || '',
completedAt: state?.completedAt || 0,
completedMigrations: state?.completedMigrations || [],
resumeState: { migrationId, lastProcessedOffset: offset, branch }
resumeState: { migrationId, lastProcessedOffset: offset }
})
}

View file

@ -29,7 +29,6 @@ export interface MigrationState {
resumeState?: {
migrationId: string
lastProcessedOffset: number
branch: string
}
}
@ -56,8 +55,8 @@ export interface MigrationError {
}
export interface MigrationResult {
/** Backup branch name, or null if no changes were needed */
backupBranch: string | null
/** Path of the pre-migration snapshot, or null when no `backupTo` was supplied */
backupPath: string | null
/** IDs of migrations that were applied */
migrationsApplied: string[]
/** Total entities processed (scanned) */
@ -71,6 +70,13 @@ export interface MigrationResult {
export interface MigrateOptions {
/** Preview what would change without writing */
dryRun?: boolean
/**
* Directory to persist a pre-migration snapshot into (created; must be
* empty or absent). The snapshot is cut via the Db API (hard-link
* snapshot of the current generation) BEFORE any transform runs; restore
* it wholesale with `brain.restore(path, { confirm: true })`.
*/
backupTo?: string
/** Progress callback for long-running migrations */
onProgress?: (progress: {
migrationId: string