name: workspace-api
description: 'Epicenter workspace API patterns: defineTable, defineKv, migrations, actions, createWorkspace, materializers, openCollaboration, and workspace connections. Use when editing workspace schemas, table/KV access, actions, attachments, or collaboration setup.'
metadata:
author: epicenter
version: '8.0'
Workspace API
Use this skill for Epicenter workspace definitions, table and KV access, inline action registries, attachment composition, collaboration setup, and workspace connections.
Reference Repositories
- Yjs: CRDT framework used by the workspace data layer
- Yjs Protocols: sync, awareness, and protocol helpers used around collaboration
Upstream Grounding
When workspace behavior depends on Yjs transactions, shared types, update encoding, document lifecycle, or conflict semantics, use source-backed grounding before relying on memory. If DeepWiki MCP is available, ask a narrow question against yjs/yjs; for collaboration sync or awareness protocol behavior, ask against yjs/y-protocols. If DeepWiki is unavailable or the repo is not indexed, use upstream source or official docs directly. Treat DeepWiki as orientation, then verify decisive details against local workspace code, installed types, tests, or official docs before changing code.
Skip DeepWiki for Epicenter schema, action, migration, and attachment conventions already documented below.
Related Skills
yjs: Yjs CRDT patterns and shared typessvelte: reactive wrappers such asfromTableandfromKv, plus commit-on-blur workspace inputsattach-primitive: the full contract and invariants everyattach*function must followtypebox: TypeBox primitives used byfield.*,defineKv, and action input schemas
When To Apply This Skill
Use this skill when you are:
- Defining a table or KV store with
defineTable()ordefineKv(). - Adding a version or migration to an existing table definition.
- Reading, writing, or observing table or KV data.
- Creating actions with
defineMutationordefineQuery. - Composing a live document with
createWorkspaceand surroundingattach*primitives (persistence, sync, materializers). - Adding
createDisposableCache(builder)for per-row or fan-out documents. - Attaching persistence, collaboration, or materializers around a workspace.
- Writing server-side Bun scripts with
connectWorkspace().
Core Rules
- Workspace action
defineQuery/defineMutationfactories are not Whispering$lib/rpcadapters fromwellcrafted/query. Do not apply workspace action input-schema rules to Whispering RPC modules. _vis library-managed. Never declare it as a column, never set it on a write, never read it off a row. Single-version tables drop the versioning surface entirely; multi-version tables expose it only inside themigratefunction as({ value, version }).- Columns are TypeBox schemas. Prefer the
field.*builders from@epicenter/field(field.string,field.number,field.boolean,field.select,field.json,field.datetime) plus the standalonenullablewrapper from@epicenter/workspacefor the emptiness axis (an IANA timezone is justfield.string<IanaTimeZone>(), no bespoke builder); rawType.X()is allowed and theFlatJsonTSchemaconstraint enforces SQLite-mappable shapes either way. - Derive row types with
InferTableRow<typeof tableDefinition>in the same module that defines the table. Consumers import the type from the workspace definition module. - Do not re-derive row types from runtime table methods or relay them through state files.
- KV stores use
defineKv(schema, defaultValue)wheredefaultValueis a factory() => Static<S>. Prefer one scalar per dot-namespaced key unless the value is a true atomic object. - Every table
idand string foreign key uses a branded type plus a co-located generator. The brand lives as a pure type alias (type X = string & Brand<'X'>); the generator usesgenerateId<X>(). Call sites use the generator, never a direct cast. - Put isomorphic actions directly on the returned workspace as
actions: defineActions({ ... })insidecreate<App>Workspace(). Avoid a separateconst actionsunless the same registry must be passed to another owner before return. ExtractcreateXActions(workspace)only when the action set is shared, large enough to earn a file, or owns a real invariant. Runtime-specific actions live in the runtime builder where browser, Node, Tauri, or extension APIs are in scope. - Construct a workspace with
createWorkspace({ id, tables, kv, keyring? })(or a per-app wrapper likecreateHoneycrispWorkspace). Plaintext apps omitkeyring; encrypted apps pass the signed-in keyring callback. The bundle exposes{ ydoc, tables, kv, [Symbol.dispose] }andusing workspacecascades disposal to every store. Only the three materializers (attachBunSqliteMaterializer,attachTursoMaterializer,attachMarkdownMaterializer) take the bundle; persistence, log, and sync primitives takeworkspace.ydoc. - Local action calls see the handler shape directly. Remote dispatch wraps raw values and failures in
Promise<Result<T, DispatchError>>. Read the action return reference before changing handler failure behavior. - Every action method inside the workspace action object should have JSDoc that adds developer-facing value beyond the short
descriptionfield. - Keep workspace schema and inline actions isomorphic. If an action file is extracted, it must stay isomorphic too. Keep
client.tsruntime-specific and outside theworkspace/folder. - Compose attachments inline in the builder after calling
createWorkspace. Avoid wrapper helpers that hide ordering unless the abstraction owns a real invariant. - Use
connectWorkspace()for one-off Bun scripts that need a connected workspace without app UI bootstrapping.
Reference Map
- Schema definition patterns:
defineTable,defineKv, row type inference, KV scalar design, and branded IDs. - Actions, layout, and attachments: inline actions, JSDoc, workspace file layout, attachment ordering, and
connectWorkspace. - Deriving action input schemas: use
tables.X.schemaandschema.properties.Xto composedefineQuery/defineMutationinput schemas inline. No helper layer. - Action return shapes: local vs remote action return contracts and error normalization.
- Table, KV, CRUD, and observation: table/KV read, write, observe, and derived-state details.
- Table migrations: migration rules and version evolution examples.
- Primitive API: lower-level primitive contracts and composition details.