Implementation:0xsline OpenChatCut Project Store
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Storage, Editing, Data_Persistence |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Concrete CRUD API for the project store backed by SQLite, providing atomic read, write, delete, and merge operations with process-level serialization and full-text search indexing.
Description
The Project Store module manages all project document persistence in OpenChatCut. It replaced the original JSON file store with a SQLite-backed key-value store, providing:
- Entry-level CRUD: `readStore`, `getStoredEntry`, `setStoredEntry`, `deleteStoredEntry`.
- Merge operations: `mergeStoredEntries` for importing project data with agent-session migration safety.
- Serialized writes: A process-level promise chain (`serializeProjectStore`) ensures multi-step read-modify-write operations do not interleave.
- Deleted-project tracking: A deleted-projects registry prevents tombstoned projects from reappearing.
- Full-text indexing: Chat and project entries are indexed for search via `indexStoreKey` / `removeStoreKey`.
- Locked store operations: `withSerializedProjectStore` provides a locked store view for compound atomic operations.
- Project document CAS: `writeProjectDocument` provides compare-and-swap document writes.
- Export recovery: `updateExportRecoveryLease` manages export recovery leases.
Usage
- Agent edit sessions: The offline runtime reads project documents and commits drafts through the project store.
- Export recovery: The export pipeline uses the store to recover interrupted exports.
- Editor sync: The browser editor reads and writes projects through these APIs.
- Agent runtime state: `writeAgentRuntime` and `updateStoredAgentRunLease` persist agent execution state.
Code Reference
Source Location
- Repository: OpenChatCut
- File: server/plugins/project-store.ts
Signature
export async function readStore(): Promise<StoreFile>;
export async function mergeStoredEntries(incoming: Record<string, unknown>): Promise<StoreFile>;
export async function setStoredEntry(key: string, value: unknown): Promise<void>;
export async function deleteStoredEntry(key: string): Promise<void>;
export async function getStoredEntry(key: string): Promise<StoredEntryValue>;
export async function withSerializedProjectStore<T>(
work: (store: LockedProjectStore) => Promise<T>,
): Promise<T>;
export async function updateExportRecoveryLease(
input: ExportRecoveryLeaseInput,
): Promise<ProjectStoreMutationResponse>;
export const writeProjectDocument: (typeof createProjectDocumentStoreOperation) extends () => infer R ? R : never;
export const rotateAgentSession: typeof createAgentSessionStoreOperation;
export const { writeAgentRuntime, updateStoredAgentRunLease }: ReturnType<typeof createAgentRuntimeStoreOperations>;
Import
import {
readStore,
getStoredEntry,
setStoredEntry,
deleteStoredEntry,
mergeStoredEntries,
withSerializedProjectStore,
} from '../server/plugins/project-store.ts';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| key | string | Yes | Store entry key (validated by `isProjectStoreKey`) |
| value | unknown | Yes | Entry value to store |
| incoming | Record<string, unknown> | Yes | Entries to merge (for `mergeStoredEntries`) |
Outputs
| Name | Type | Description |
|---|---|---|
| readStore() returns | StoreFile | { version: 1, entries: Record<string, unknown> } |
| getStoredEntry() returns | StoredEntryValue | { found: boolean, value: unknown } |
| withSerializedProjectStore() returns | T | Result of the locked store work function |
Usage Examples
Read a Project Document
import { getStoredEntry } from '../server/plugins/project-store.ts';
const result = await getStoredEntry('project:my-project-id');
if (result.found) {
console.log('Project document:', result.value);
}
Atomic Document Update
import { withSerializedProjectStore } from '../server/plugins/project-store.ts';
const newRevision = await withSerializedProjectStore(async (store) => {
const current = await store.read('project:my-project-id');
if (!current.found) throw new Error('project not found');
const doc = current.value as ProjectDoc;
doc.activeTimelineId = 'timeline-2';
return store.write('project:my-project-id', doc);
});
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment