pi-mono/packages/session-backends/sqlite-node
2026-08-31 00:19:51 +02:00
..
benchmark/session feat(agent,ai): add narrow subpath exports so clients skip the barrel 2026-08-26 22:02:31 +02:00
scripts fix(sqlite): ENOENT, copy migs into dist 2026-08-13 14:26:09 +02:00
src feat(agent): expose durable lane operations 2026-08-26 21:14:59 +02:00
test feat(agent,ai): add narrow subpath exports so clients skip the barrel 2026-08-26 22:02:31 +02:00
CHANGELOG.md Add [Unreleased] section for next cycle 2026-08-28 23:56:06 +02:00
package.json Merge remote-tracking branch 'origin/main' into dev 2026-08-29 08:21:44 +00:00
README.md docs(agent): align SQLite ownership with session workers 2026-08-31 00:19:51 +02:00
tsconfig.build.json chore: rename storage package to session-backends 2026-08-05 09:28:44 +02:00
vitest.benchmark.config.ts feat: move facet services into Chord 2026-08-29 14:55:51 +02:00
vitest.config.ts feat: move facet services into Chord 2026-08-29 14:55:51 +02:00

@earendil-works/pi-session-backend-sqlite-node

Node node:sqlite Session backend for @earendil-works/pi-agent-core.

import { BACKGROUND_CONTEXT } from "@earendil-works/pi-agent-core";
import {
  createNodeSqliteFactory,
  SqliteSessionRepo,
} from "@earendil-works/pi-session-backend-sqlite-node";

const repository = new SqliteSessionRepo({
  directory: "/var/lib/pi/sessions",
  databaseFactory: createNodeSqliteFactory(),
});

const session = await repository.create({}, BACKGROUND_CONTEXT);
const main = await session.createBranch("main", null, BACKGROUND_CONTEXT);
await main.appendMessage(
  { role: "user", content: "hello", timestamp: Date.now() },
  BACKGROUND_CONTEXT,
);
await session.close(BACKGROUND_CONTEXT);
await repository.close(BACKGROUND_CONTEXT);

The default layout currently creates one {sessionId}.sqlite file per Session under directory; WP07 replaces that direct interpolation with path-safe encoding for arbitrary explicit IDs. Pass databasePath to place multiple Sessions in one supported shared container. Open Sessions own separate SQLite connections. A fork of a source open in the same repository queues on that source; WP07 adds an independent read-only WAL snapshot for a source owned by another process, including a live Session worker.

The host lifecycle, not this backend, guarantees one writable owner per Session. Directly opening the same Session for writes in another process is unsupported; read-only listing and fork-source access may overlap the worker. The backend provides atomic storage, branch projections, and maintained statistics. WP07 removes the current storage-layer writer lease and adds the read-only live-fork path, repository-local deletion reservation, physical/path safety, and complete close draining. The package does not currently export a search service or FTS index; search is the separate S3 projection.