@vibesdotdev/localdb 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +10 -109
  2. package/package.json +9 -10
  3. package/SPEC.md +0 -119
package/README.md CHANGED
@@ -1,121 +1,22 @@
1
1
  # @vibesdotdev/localdb
2
2
 
3
- Local SQLite primitive for the vibes consumer-hardware toolkit. Owns the
4
- connection pool, namespace migration registry, recovery/trapdoor flow, and the
5
- `vibes dev localdb` CLI surface. Backed by `bun:sqlite`; server-runtime only.
3
+ Local SQLite storage helpers and migration utilities for Vibes development surfaces.
6
4
 
7
- The contract lives in [`SPEC.md`](./SPEC.md). Operational status lives in
8
- [`PROD-CHECKLIST.md`](./PROD-CHECKLIST.md). This README is the developer
9
- quick-start.
5
+ This package is part of the public Vibes framework package set. The source repository is private while the public repository split is being prepared, so package documentation is published on the Vibes docs site.
10
6
 
11
7
  ## Install
12
8
 
13
- Workspace-only:
14
-
15
- ```jsonc
16
- // package.json
17
- {
18
- "dependencies": {
19
- "@vibesdotdev/localdb": "workspace:*",
20
- "@vibesdotdev/runtime": "workspace:*"
21
- }
22
- }
23
- ```
24
-
25
- ## Register migrations and open a database
26
-
27
- A domain module declares its migrations once and asks for its database by
28
- namespace + path. Migrations run on first `getDatabase()` for that
29
- `namespace:path`.
30
-
31
- ```ts
32
- import { localdb, type Migration } from '@vibesdotdev/localdb';
33
- import type { Database } from 'bun:sqlite';
34
-
35
- const MY_MIGRATIONS: Migration[] = [
36
- {
37
- version: 1,
38
- name: 'Create things table',
39
- up: (db: Database) => {
40
- db.exec(`
41
- CREATE TABLE IF NOT EXISTS things (
42
- id TEXT PRIMARY KEY,
43
- created_at TEXT NOT NULL DEFAULT (datetime('now'))
44
- )
45
- `);
46
- }
47
- }
48
- ];
49
-
50
- localdb.registerMigrations('my-module', MY_MIGRATIONS);
51
-
52
- const handle = await localdb.getDatabase(
53
- 'my-module',
54
- '.vibes/my-module/state.db',
55
- 'my-module-storage'
56
- );
57
-
58
- const db = handle.getDatabase();
59
- db.query('INSERT INTO things (id) VALUES (?)').run('hello');
60
- ```
61
-
62
- Migration versions must be `1..N` consecutive — registering out of order
63
- throws. Asking for an unregistered namespace throws. Migration failure
64
- triggers automatic recovery: the corrupted file is backed up
65
- (`*.bak-{ts}`, last 12 retained) and a fresh database is migrated from
66
- version 0.
67
-
68
- ## Get a raw connection (no migrations)
69
-
70
- For quick read-only tools or one-off scripts that don't need version
71
- management, `getRawDatabase` returns a pooled `bun:sqlite.Database` directly:
72
-
73
- ```ts
74
- import { localdb } from '@vibesdotdev/localdb';
75
-
76
- const raw = localdb.getRawDatabase('.vibes/scratch/log.db', 'log-reader');
77
- const rows = raw.query('SELECT * FROM events ORDER BY ts DESC LIMIT 100').all();
78
- ```
79
-
80
- This bypasses the migration registry. Prefer `getDatabase()` for any
81
- schema-owning code.
82
-
83
- ## CLI
84
-
85
- The package registers `vibes dev localdb` for inspecting state from a
86
- terminal:
87
-
88
9
  ```sh
89
- vibes dev localdb status # connection + migration status across namespaces
90
- vibes dev localdb namespaces # registered migration namespaces
91
- vibes dev localdb pools # connection pool statistics
92
- vibes dev localdb migrate <ns> # run pending migrations for a namespace
93
- vibes dev localdb query <ns> # raw SQL against a namespace database
10
+ bun add @vibesdotdev/localdb
11
+ # or
12
+ npm install @vibesdotdev/localdb
94
13
  ```
95
14
 
96
- Commands run on consumer hardware only.
97
-
98
- ## What lives where
99
-
100
- - The `storage/adapter` impl `storage.localdb.core` →
101
- [`@vibesdotdev/storage-adapter-localdb`](../storage-adapter-localdb/) (the
102
- thin storage wrapper that consumes this package).
103
- - App and feature schemas / migration SQL → the owning package or app.
104
- This package owns the SQLite *primitive*; it does not carry domain SQL.
105
- - Cloud / multi-tenant SQLite → use
106
- [`@vibesdotdev/storage-adapter-drizzle`](../storage-adapter-drizzle/)
107
- with libsql/Turso or D1.
15
+ ## Documentation
108
16
 
109
- ## Verification
110
-
111
- ```sh
112
- bun test packages/localdb
113
- bun --bun tsc -p packages/localdb/tsconfig.json --noEmit
114
- ```
17
+ - Package guide: https://docs.vibes.dev/packages/localdb
18
+ - Vibes docs: https://docs.vibes.dev
115
19
 
116
- ## Links
20
+ ## License
117
21
 
118
- - [SPEC.md](./SPEC.md) — package contract.
119
- - [storage](../storage/SPEC.md),
120
- [storage-adapter-localdb](../storage-adapter-localdb/),
121
- [storage-adapter-drizzle](../storage-adapter-drizzle/SPEC.md).
22
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibesdotdev/localdb",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -100,15 +100,10 @@
100
100
  "registry": "https://registry.npmjs.org",
101
101
  "access": "public"
102
102
  },
103
- "repository": {
104
- "type": "git",
105
- "url": "git+https://github.com/vibesdotdev/monorepo.git",
106
- "directory": "packages/localdb"
107
- },
108
103
  "peerDependencies": {
109
- "@vibesdotdev/runtime": "0.0.1",
110
- "@vibesdotdev/logging": "0.0.1",
111
- "@vibesdotdev/cli": "0.0.1"
104
+ "@vibesdotdev/runtime": "0.0.2",
105
+ "@vibesdotdev/logging": "0.0.2",
106
+ "@vibesdotdev/cli": "0.0.2"
112
107
  },
113
108
  "scripts": {
114
109
  "test": "bun test",
@@ -121,7 +116,6 @@
121
116
  "src",
122
117
  "bin",
123
118
  "README.md",
124
- "SPEC.md",
125
119
  "LICENSE",
126
120
  "!src/**/__tests__/**",
127
121
  "!src/**/__stubs__/**",
@@ -142,5 +136,10 @@
142
136
  ],
143
137
  "vibes": {
144
138
  "visibility": "public-framework"
139
+ },
140
+ "description": "Local SQLite storage helpers and migration utilities for Vibes development surfaces.",
141
+ "homepage": "https://docs.vibes.dev/packages/localdb",
142
+ "bugs": {
143
+ "url": "https://docs.vibes.dev/packages/localdb#support"
145
144
  }
146
145
  }
package/SPEC.md DELETED
@@ -1,119 +0,0 @@
1
- # @vibesdotdev/localdb
2
-
3
- Local SQLite primitive for the vibes consumer-hardware toolkit. Owns the
4
- connection pool (one `bun:sqlite` `Database` per file path, WAL mode, busy
5
- timeout, ref-counted, idle-cleanup), the namespace migration registry
6
- (sequential-version enforcement, legacy `PRAGMA user_version` bootstrap,
7
- `vibes_schema_versions` tracking table), the recovery/trapdoor flow (backup →
8
- delete → recreate → re-migrate on migration failure or version mismatch), and
9
- the `vibes dev localdb` CLI surface. Consumer hardware only — `bun:sqlite` is
10
- server-runtime only. The storage adapter that wraps localdb lives in a sibling
11
- adapter package, not here.
12
-
13
- ## Owns
14
-
15
- - **Plugin descriptors registered by the plugin** (`./plugin`):
16
- - `runtime/context` `dev/localdb` — server-side `LocaldbApi` access for
17
- runtime callers.
18
- - `cli/group` `dev.localdb` parented under `dev` — `vibes dev localdb`.
19
- - `cli/command` `dev.localdb.{status,migrate,namespaces,pools,query}`.
20
- - **Connection pool** (`./core/connection-pool`): per-path pooled `bun:sqlite`
21
- `Database`, ref-counting, idle stale-cleanup (30 min), uniform PRAGMAs
22
- (`journal_mode=WAL`, `busy_timeout=5000`, `foreign_keys=ON`,
23
- `synchronous=NORMAL`, `temp_store=MEMORY`).
24
- - **Migration registry** (`./core/migration-registry`): namespace-keyed
25
- `Migration[]`, sequential `1..N` version enforcement,
26
- `vibes_schema_versions` tracking, legacy `PRAGMA user_version` one-time
27
- bootstrap, incompatible-database (version-too-high) detection.
28
- - **`LocalDatabase` + `localdb` singleton manager** (`./core/database`):
29
- per-`namespace:path` entry caching with per-`dbPath` async lock,
30
- recovery/trapdoor on migration failure with retained backups (last 12),
31
- `getRawDatabase()` for migration-free pooled access, `closeAll()` /
32
- process-exit cleanup.
33
- - **Public API types** (`./schemas`): `LocaldbApi`, `LocaldbRawDatabase`,
34
- `LocaldbStatement`, `Migration`, `MigrationFunction`, `ConnectionStats`,
35
- `ConnectionPoolApi`, `MigrationRegistryApi`.
36
-
37
- ## Does not own
38
-
39
- - The `storage/adapter` impl `storage.localdb.core` →
40
- [`storage-adapter-localdb`](../storage-adapter-localdb/SPEC.md). Per pattern
41
- 1, environment-specific storage adapters live in sibling packages; the
42
- adapter is a thin `storage` consumer of `localdb`.
43
- - Domain migration SQL → owning module:
44
- - `atlas` schema → [`workspace`](../workspace/SPEC.md) (the only registrar,
45
- via `packages/workspace/src/codegraph/storage/register-migrations.ts`).
46
- - `pm-state` schema → [`pm`](../pm/SPEC.md) (already lives there; PM passes
47
- its own dir as an absolute path to `loadMigrationSQLSync`).
48
- - `external` `file_accesses` → [`external`](../external/SPEC.md) (already
49
- inline-defined in `packages/external/src/register-migrations.ts`).
50
- - `config` schema → [`cli`](../cli/SPEC.md) (its app-config storage
51
- subsystem already declares the namespace).
52
- - Cross-process / multi-tenant locking, replication, observability of pool
53
- stats. Out of scope for the consumer-hardware floor; cloud storage uses
54
- [`storage-adapter-drizzle`](../storage-adapter-drizzle/SPEC.md).
55
- - A `runtime/client` descriptor or `getVibesLocaldbClient()`. LocalDB is a
56
- runtime substrate consumed via the `localdb` singleton or the `dev/localdb`
57
- context, not a domain module.
58
-
59
- ## Hard rules
60
-
61
- - **`bun:sqlite`, server-runtime only.** All filesystem/SQLite imports are
62
- dynamic and gated on `isLocaldbServerRuntime()`. `LocalDatabase.initialize()`
63
- throws in browser bundles.
64
- - **Sequential migration versions.** Registered migrations form `1..N` with
65
- no gaps; out-of-sequence registration throws at `register()` time.
66
- - **Unknown namespace = throw.** `needsMigration` / `runMigrations` /
67
- `getDatabase` against an unregistered namespace is a hard failure (per
68
- pattern 4); domain modules call
69
- `localdb.registerMigrations(namespace, migrations)` before opening their
70
- database.
71
- - **Recovery is automatic and lossy.** Migration failure or
72
- version-higher-than-registered triggers backup (`*.bak-{ts}`, last 12
73
- retained) → delete file + WAL/SHM artifacts → fresh DB → re-run migrations
74
- from version 0. Domain code must not rely on data surviving migration
75
- failure.
76
- - **One Database per file path.** All access goes through the pool; the
77
- `usePool: false` direct-connection path stays for special cases but new
78
- code uses the pool.
79
- - **No domain SQL in this package.** Migration SQL files for a feature live
80
- with that feature's package.
81
-
82
- ## Migration debt
83
-
84
- All items completed in t11-mig-localdb-final-and-seal. See git history for original debt items.
85
-
86
- ## Public entrypoints
87
-
88
- `.` — root exports (`localdb`, `LocalDatabase`, `Migration`, etc.)
89
- `./plugin` — LocalDB plugin registration
90
- `./schemas` — TypeScript type definitions (`LocaldbApi`, `Migration`, etc.)
91
-
92
- Migration-era subpaths (`./core/*`, `./migrations/*`, `./localdb.plugin`) have been removed.
93
-
94
- ## Verification
95
-
96
- `bun test` from `packages/localdb`. Covers `MigrationRegistry` (version
97
- tracking, sequence validation, legacy-bootstrap, incompatible-version
98
- detection), `ConnectionPool` (pooling, ref-count, stats), `LocalDatabase`
99
- (init / idempotence / recovery / backup pruning), `localdb` manager
100
- (namespace caching + per-path lock), and `loadMigrationSQL` file resolution.
101
- Today (per `PROD-CHECKLIST.md` 2026-04-18): 79 pass / 0 fail.
102
-
103
- ## Links
104
-
105
- - [storage/SPEC.md](../storage/SPEC.md),
106
- [storage-adapter-localdb/SPEC.md](../storage-adapter-localdb/SPEC.md),
107
- [storage-adapter-drizzle/SPEC.md](../storage-adapter-drizzle/SPEC.md),
108
- [runtime/SPEC.md](../runtime/SPEC.md),
109
- [cli/SPEC.md](../cli/SPEC.md),
110
- [logging/SPEC.md](../logging/SPEC.md)
111
- - Active consumers: [pm](../pm/SPEC.md), [workspace](../workspace/SPEC.md),
112
- [external](../external/SPEC.md), [cli](../cli/SPEC.md),
113
- [presence](../presence/SPEC.md), [prompts](../prompts/SPEC.md),
114
- [experiments](../experiments/SPEC.md), [desktop](../desktop/SPEC.md),
115
- [browser-automation](../browser-automation/SPEC.md),
116
- [knowledge](../knowledge/SPEC.md), [setup](../setup/SPEC.md)
117
- - Doctrine:
118
- [RUNTIME-FIRST-MODULES.md](../../docs/architecture/RUNTIME-FIRST-MODULES.md),
119
- [RUNTIME-SCOPE-TOPOLOGY.md](../../docs/architecture/RUNTIME-SCOPE-TOPOLOGY.md)