Skip to content

Latest commit

 

History

History
1085 lines (872 loc) · 45.8 KB

workspace-format.md

File metadata and controls

1085 lines (872 loc) · 45.8 KB

.workspace — File Format (v0, Early Spec)

A .workspace is a folder on disk — or an archive of one — that holds everything a team needs to collaborate: documents, the rules about who can read what, the keys that enforce those rules, and the connection details for syncing with other members. From a user's perspective, the folder is the workspace. You can drag it to a USB stick, AirDrop it, drop it on a NAS, share it however you'd share any folder.

This document describes what lives inside that folder, how it's arranged, and how the on-disk shape supports both the in-app collaboration experience and the portability that lets you take your data anywhere.

The contained files keep their own format identity (.md, .canvas, .table, anything else) and can be opened by any tool that understands them — when viewed outside a workspace they are just files. Inside a workspace, they gain field-level permission enforcement, because the workspace is the primitive container for that enforcement. The file format stays clean; the container does the work.

Status: early. Shape expected to change as implementation proceeds. This document captures the current direction so format and app decisions made today don't paint us into a corner.


Invariants — the working form is a normal folder

The product promise is the Finder/Dropbox metaphor: a workspace is a normal folder of files in open formats that you can browse, grep, back up, and open without the app. Every format decision below — and every future one — must hold these invariants. They exist so the metaphor is tested against, not re-litigated, each time a decision comes up.

  1. One hidden metadata directory. All P2P/permissions machinery lives under a single hidden .workspace/ directory — never scattered dotfiles next to content, never per-document sidecar files. As the metadata surface grows, it grows inside that one directory. (The writeBundleFolder layout — manifest, attestation, envelopes, store under one directory — is the right shape and stays the only metadata surface.)

  2. Content files stay plain. Files in the working tree are never encrypted, wrapped, or renamed in place. Open the folder in any editor and everything works. (Tier-gated content that a peer isn't authorised to read simply isn't materialised in their working tree — it lives only as sealed bytes in .workspace/store/; it is never an unreadable file sitting in the tree. See "On-disk reality".)

  3. The archive is transport-only. name.workspace.zip (or tar) is a serialisation for channels that don't preserve folders, and for backup. The app unpacks on open and operates on the folder, never on the archive in place. This forecloses a whole class of complexity (partial updates inside archives, archive locking) before it starts.

  4. Survives cloud sync. The hidden metadata must tolerate Dropbox/iCloud/OneDrive syncing the folder: append-only and content-addressed layouts tolerate sync races; mutable lock/state files do not — so there are none. The .workspace/ reader must also tolerate iCloud Drive's dataless-faulting/eviction and Dropbox's "conflicted copy" duplicates rather than corrupting on them.

    Implementation status, so the invariant is not read as a description of what exists. The layout half holds: append-only and content-addressed throughout, and ADR 0003 moved RocksDB out of the folder for precisely this reason, so there are no mutable state files. Conflicted-copy tolerance holds for store filenames, with a test. Dataless tolerance is partial: the integration's tree walk skips dataless files, and the reader does not yet — tracked as workspace#237. See "Things that can go wrong" for what each of these actually means in practice.

  5. Plain-copy safe. A cp -R (or rsync, or a backup tool) of the folder must produce a valid workspace. Nothing in .workspace/ may require the app to be present to be copied safely. The folder stays greppable, rsync-able, and backupable with ordinary tools.

  6. Seed/export hygiene. Any path that copies a workspace tree — seed scripts, export flows, fixture tooling, backup helpers — must handle .workspace/ deliberately. "Export this workspace to share" and "back this workspace up with its keys" are different operations and must not be conflatable by accident.

    Two concrete rules, because the general statement was not enough (see below):

    • .workspace/keys/ must never be copied to another device, in any mode, behind any flag. It is this peer's own identity. A second device is a second peer and mints its own.
    • Excluding noise is not excluding secrets. A copy path that prunes .git/ and node_modules/ has demonstrated a mechanism, not a policy. The two look identical in code and are unrelated in intent, so the presence of one must never be read as evidence of the other.

    Match on path segments, not basenames: a working tree may legitimately contain a folder called keys/, and a fixtures tree may contain several .workspace folders at any depth.

    This invariant was violated by the first tool it named. An earlier revision cited the Workspace mobile seed script as already handling this correctly. It was not — it pruned OS and VCS noise and copied .workspace/ wholesale, private keys included, and would have put one developer's identity onto every simulator they seeded (workspace-sh/workspace#233). The invariant was written, published, and pointed at the exact file that broke it. Prose in this repository cannot enforce anything in another one; treat these rules as requiring a test, not a reader.

A caution: the macOS bundle UTI

Registering .workspace as a Finder bundle (so it's a single double-clickable artefact) conflicts with invariant 1's spirit: bundles hide their contents by default in Finder, which cuts against the browsable-folder promise. "Show Package Contents" existing is not the same as the folder feeling normal. Decide deliberately whether the bundle treatment applies to the working folder (likely no — keep it a plain browsable folder) or only to exported/portable artefacts (more defensible). This is an open decision; see "Open design questions".


What a workspace looks like on disk

my-org.workspace/                      ← the workspace itself
├── policies/
│   ├── code-of-conduct.md             ← plaintext, anyone in the workspace can read
│   └── parental-leave.md
├── ideas/
│   └── q2-retro.canvas
├── data/
│   ├── customers.table                ← a single-file .table; public-within-workspace by default
│   └── people.table/                  ← a .table folder, with per-field permissions (planned)
│       └── tables/employees/
│           ├── schema.json            ← public field declarations + hidden-field IDs
│           ├── rows/0001.ndjson       ← rows; only public fields appear here
│           └── bodies/
└── .workspace/                        ← hidden container metadata + encrypted state
    ├── manifest.json                  ← workspace identity, root DID, topic
    ├── attestation.json               ← root signature over the manifest
    ├── policy.json                    ← workspace's cleanup/rotation policy
    ├── envelopes/                     ← bootstrap envelopes for invited peers
    ├── keys/                          ← this peer's local key state
    └── store/                         ← logs in transport form (see `store/`)

Everything above .workspace/ is the user-facing working tree: plaintext files arranged however the user wants. Everything inside .workspace/ is machine-facing container state — the workspace's identity, the encrypted log, the keys.

This split mirrors git's working-tree / .git separation. You can edit code-of-conduct.md in any text editor; you cannot meaningfully edit anything inside .workspace/ by hand.

On macOS and Linux the dot-prefix is enough to hide .workspace/ from default file-browser views. On Windows, where the Unix dot-prefix convention isn't honoured, the writer sets FILE_ATTRIBUTE_HIDDEN on the directory at creation time so Explorer hides it for non-technical users.


On-disk reality: what's plaintext, what's encrypted

This is the most important design decision in the format. Two rules:

Rule 1 — Workspace-public content lives in plaintext

Files anyone in the workspace can read (the "public" tier, protected only by the workspace's K0_org key) sit as plaintext at rest in the working tree. Any tool can open code-of-conduct.md in any editor. This is what makes the folder feel like ordinary files.

Rule 2 — Tier-gated content lives only in the encrypted store

Files and fields that require additional tier keys (K1, K2, K_hr, etc.) are never written to the working tree as plaintext. They exist only as encrypted bytes inside .workspace/store/. The Workspace app, for an authorised viewer, decrypts them into memory when the user opens them — and shows them in the UI — but does not materialise them to disk.

For per-field encryption in a .table (planned: field tiers aren't built), this means the rows files (rows/*.ndjson) on disk contain only public fields:

{"id": "r1", "name": "Alice", "team": "Eng"}
{"id": "r2", "name": "Bob",   "team": "Eng"}

An unauthorised reader cannot tell whether Alice has a salary or whether Bob has medical-leave status. The information that those fields exist is in schema.json; the information that this row has a value for them is sealed in the store.

For whole-file tiering (e.g. an HR-only document), the file does not appear in the working tree at all on a non-authorised peer's machine. The Workspace app shows it in the UI for authorised users, decrypted into memory only.

Consequence: the folder is safe to copy by default

Because the on-disk state already only contains what's workspace-public, copying the folder to a USB stick, AirDrop, NAS, or anywhere else does not leak tier-gated content. Whatever ends up at the destination is already the right thing to share. No "export" step needed for safety.

The trade-off: viewing or editing your own tier-gated content requires the Workspace app. You cannot cat the rows files and see your own salary; you open the table in Workspace and the app decrypts the value for the UI. This is the cost of the copy-paste-safe property, and it's the right trade for a consumer product where avoiding leaks matters more than terminal convenience.


External edits — watching the working tree

A Workspace folder is meant to behave like Dropbox: open a file in whichever editor you like, save, and Workspace picks up the change. The app watches the working tree (everything above .workspace/) and reconciles edits into the workspace's logs as they happen. This is what makes the "the folder is the workspace" promise honest — your existing tools still work.

That said, Workspace ships its own editors for the formats it handles natively — markdown, canvas, .table. Editing inside the app gets you presence, comments, permission-aware field rendering, locator-stable links, and conflict-free collaborative edits. For the formats Workspace handles natively, the in-app editor is where you'll want to be — external editing is the safety net that keeps the folder from being held hostage by the app, not the primary path.

What's watched

  • Everything above .workspace/: markdown, canvas files, table folders, plus any user-added files Workspace recognises.
  • Excluded: .workspace/ itself (machine-facing — only the app touches it), OS junk (.DS_Store, Thumbs.db, desktop.ini), editor sidecar files (*.swp, *~, .~lock.*).
  • Unknown file types are recorded as opaque blobs and sync to peers byte-for-byte. They get no field-level treatment.

How

The working tree is watched via the platform's native change- notification API — FSEvents on macOS, inotify on Linux, ReadDirectoryChangesW on Windows. Node implementations typically use chokidar to wrap all three behind one interface; any equivalent works. Workspace debounces incoming events within a short window (100–300ms) so a single user-level save lands as a single ingest, even when the underlying editor emits a flurry of filesystem events (see "Atomic-save patterns" below).

Atomic-save patterns

Many editors don't write in place. Vim, Sublime Text, and some Office apps write to a temp file and rename over the original. To the watcher this looks like:

add      foo.md.tmp
unlink   foo.md
rename   foo.md.tmp → foo.md

The debounce window collapses these into one "foo.md changed" event with the new content. No special-casing per editor required; the debounce handles it.

What happens on detection

For each changed file, Workspace:

  1. Reads the new content from disk
  2. Reconciles against the in-log version using format-specific logic
  3. Appends a write block to the workspace's data log
  4. Broadcasts to connected peers via Hyperswarm

This is the same write path as in-app edits — the only difference is where the new content comes from (disk vs the app's UI).

Paths stay inside the folder

Log entries come from other peers, and every client joins an entry's path to its own folder to write it. So:

  • A document entry's path is workspace-relative: /-separated names, with no empty, . or .. segment, and no leading /, drive letter, backslash or NUL. An entry with any other path is not a document entry and stays out of the fold.
  • Writing the log back to the folder resolves each destination through symbolic links first, and a write that would land outside the folder is not made. That includes a link to a name that does not exist yet, since writing through it would create the file it names.

Implemented: the path rule in @workspace.sh/core's entry decoder, which every client uses; the destination check in the Linux client. Which links reading follows is #48.

Per-format reconciliation, not raw byte sync

External edits are not blind byte-for-byte writes to the log. Each format has its own reconciliation logic so external editing doesn't break locator stability or section IDs:

  • Markdown — match-by-current-text on headings preserves section IDs across edits, even when headings are reordered or reworded slightly. See uri-scheme.md.
  • .table — the rows files are parsed; row-level adds / modifies / removes become individual log entries. Per-field permission tiers are preserved. Not built: today each file of a .table folder is its own log entry, holding its whole contents, last write wins by path (a single-file .table is one entry); per-format reconciliation is workspace#222.
  • .canvas — node-level diff against the in-log graph.
  • Unknown formats — opaque blob replace.

Cost: editing a tier-gated .table row externally is only possible if the user is authorised to read it. Otherwise the row doesn't appear in the rows files on their disk and external tools can't edit what they can't see. This is the design — tier-gated content exists only as encrypted bytes outside the app.

Conflict with in-app edits

If the same file is open in Workspace's editor AND edited externally, the external edit wins by recency (timestamp + log order). The in-app view reflects the on-disk state after the next watcher event. If the user has unsaved in-app changes when an external edit lands, the app prompts: keep in-app, accept external, or merge — the same pattern VS Code and Obsidian use when a file changes underneath them.

Things that can go wrong

  • Case sensitivity — macOS APFS default is case-insensitive; Linux ext4 is case-sensitive. A workspace created on one and copied to the other can hit name collisions. Workspace normalises to lowercase internally for ID purposes; the on-disk name is whatever the user picked.

  • iCloud / OneDrive / Dropbox over a workspace — supported, and required to be: invariant 4 says the metadata must survive exactly this, and the placement section below lists a Dropbox folder as an ordinary home. What follows is what a reader must actually handle. (An earlier version of this bullet named compression and dot-prefix renames and recommended against nesting at all. Both were checked on macOS 15 and neither holds; see below. The recommendation went with them.)

    • Dataless faulting. The real hazard, and the one the earlier list omitted. iCloud evicts file contents while keeping the name and the full logical size in stat. A read either blocks while the file downloads or fails. A tree walk that reads everything will force a download of the whole folder; a reader that treats a failed read as an empty file will destroy data. Portable signature, no Foundation needed: size > 0 && blocks == 0. Skip such a file — say nothing about it — rather than reading or deleting it.

    • Conflicted-copy duplicates. Real. A sync engine that sees two versions writes a second file beside the first: 000000 (Sam's conflicted copy 2026-08-19).bin. Store filenames are strictly sequence-numbered, so the reader's filename pattern must reject anything that is not exactly a sequence number — a lenient match would splice a duplicate into the log as a real entry. Handled today for store files by an exact six-digit match, which also covers the flush's own .tmp-<seq> files if a sync engine catches one mid-rename: they are inert clutter, never a log entry.

    • Compression is not a hazard. Transparent at the VFS layer: st_blocks changes, the bytes a read returns do not. Nothing to handle.

    • Dot-prefix renames are historical. The .foo.icloud placeholder is legacy. Current macOS evicts in place, keeping the filename, which is why dataless faulting above is the thing to handle instead. Checked on this machine: the newest such placeholder dates from 2016, and none has been created since 2025.

    Sharing via the workspace's own protocol is still the better way to share — a sync engine gives you a copied folder, not a peer. That is a reason to prefer the protocol, not a reason the folder must avoid a sync engine.

  • Symlinks — followed by default; circular symlinks abort the affected subtree.

  • Large-file writes mid-watch — the watcher waits for size to stabilise (a couple of consecutive identical-size reads) before ingesting, so a 500MB video being copied in isn't ingested as four partial copies.

Status

Designed; implementation pending. Tracked alongside the rest of the working-tree work in #24.

A note on holding several

One device runs one runtime — one corestore, one swarm, one identity — and every workspace it has open lives inside it. A connection is per PEER rather than per workspace, because Corestore multiplexes every core it holds over one stream, so sharing ten workspaces with someone costs one connection and not ten.

See many-workspaces.md for the cost model and the three rules an implementation has to follow.

A note on the network

Nothing above waits on a peer. That is deliberate and it is enforced, not merely intended: the DHT announce has been measured at 40 seconds on a cellular connection, against 73 ms for opening the corestore. A local-first format whose local operations wait on a network round trip is not local-first.

See network-conditions.md for the measurements, the suspected-timeout tell, and the rules that follow.


Two ways to view a workspace — file or URL

A workspace can be addressed two ways: as a folder on disk, or as a workspace:// URL. Same identity, two distribution shapes.

As a folder on disk

The default. Sits in ~/Documents/, on a USB stick, in a Dropbox folder, anywhere. Open in the Workspace app via double-click or drag.

As a URL — workspace://

The URL form encodes everything needed for the Workspace app to find and join the workspace's swarm. The shape:

workspace://v1/<workspace-pubkey>[/<path>][?<query>]

For the full URI scheme spec — including path namespaces, sub-resource addressing, locator alphabets per file format (markdown sections, canvas nodes, table rows/columns/cells, video timestamps, etc.), and the parsing rules — see uri-scheme.md.

This is the magnet-link analogue. Tiny URL, leaks no sensitive metadata, embeddable in any text channel. The content lives in the swarm; the URL is the entry ticket.

Two distribution shapes

Shape What it carries When to use
Heavy bundle Full folder including .workspace/store/ (encrypted bytes) Self-contained, offline-capable. USB sticks, AirDrop to a colleague who may not be online, archival snapshots.
Light bundle (workspace:// URL or a .workspace folder with only manifest + attestation + envelopes) ~a few KB; recipient's app fetches encrypted content from peers via Hyperswarm URL-shareable. Embed in chat, QR code, web link.

Same recipient experience either way: app validates the attestation, finds the envelope addressed to its DID, decrypts and projects the working tree. The difference is just whether the encrypted bytes arrive with the bootstrap or are pulled from the swarm afterwards.

Where the analogy diverges from magnet links

  • Magnet links assume "anyone with the link can read everything." Workspaces add an access-control layer: anyone with the bundle can attempt to join, but envelopes gate what they actually decrypt.
  • BitTorrent has no concept of identity or revocation. Workspaces have both, via UCAN delegations and the topic-layer revocation lever.

Container metadata in .workspace/

The hidden subdirectory holds machine-facing state. Each file has a specific role.

manifest.json

{
  "formatVersion": 2,
  "workspaceId": "z6MkpKpf2nFiC5h9qDPgJrkBbYBaThkAEcVCgGuBHkXqK4Vc",
  "createdAt": 1717200000,
  "rootDid": "did:key:z6MkpKpf2nFiC5h9qDPgJrkBbYBaThkAEcVCgGuBHkXqK4Vc",
  "topicId": "af8757dc370b001d97d81bda285b80b147e6ca845967ce387e42ec54425209b9",
  "logs": {
    "data": "hex-encoded-hypercore-key",
    "keyDelivery": "hex-encoded-hypercore-key",
    "blobs": "hex-encoded-hypercore-key"
  }
}

The workspace's stable identity. workspaceId is the multibase encoding of the root pubkey — rootDid without its did:key: prefix (see resolved open question below). A reader refuses a manifest whose workspaceId is not its rootDid's key.

topicId is the Hyperswarm topic peers meet on, hex. A new workspace records SHA-256 of the root's 32-byte public key (the key bytes alone, without the multicodec prefix), the same topic uri-scheme.md derives from a link. Peers join the topic the manifest names; since the attestation signs it, only the root can name a different one.

logs holds the Hypercore keys of the data log, the key delivery log, and the blob log.

formatVersion is 2. A reader refuses a manifest of any other version and says which version it found.

attestation.json

The root DID's signature over every manifest field except rootDid, which is the signer: workspaceId, createdAt, formatVersion, topicId and logs. A manifest that differs from the signed payload in any of them is refused, so a folder cannot point a reader at other logs or another topic. Defeats tampering of the manifest and replay of stale workspaces. Does not defeat fraudulent identity claims — verifying that a given did:key:z… belongs to a legitimate authority still requires an out-of-band channel. See threat-model.md.

The signed bytes are UTF-8 JSON with no whitespace and every object's keys in alphabetical order; absent optional fields are omitted.

Format mirrors the SignedAttestation struct in @workspace.sh/p2p-runtime/src/attestation.ts:

{
  "payload": {
    "workspaceId": "z6MkpKpf2nFiC5h9qDPgJrkBbYBaThkAEcVCgGuBHkXqK4Vc",
    "createdAt": 1717200000,
    "formatVersion": 2,
    "topicId": "af8757dc370b001d97d81bda285b80b147e6ca845967ce387e42ec54425209b9",
    "logs": { "data": "…", "keyDelivery": "…", "blobs": "…" }
  },
  "payloadBytes": "<base64>",
  "signature": "<base64>",
  "rootDid": "did:key:z…"
}

policy.json

Workspace-level behavioural policy. Declares what cooperating apps should do on lifecycle events. Signed by root; cached locally; honoured by well-behaved Workspace clients.

{
  "version": 1,
  "onRevoked": {
    "notify": true,
    "deleteWorkingTree": true,
    "deleteEncryptedStore": true,
    "deleteLocalKeys": true,
    "confirmation": "ask-user"
  },
  "onTierKeyRotated": { "notify": false },
  "onWorkspaceDeleted": { "notify": true, "deleteEverything": true, "confirmation": "ask-user" },
  "audit": {
    "logReads":  false,
    "logWrites": false,
    "scope":     "tier-gated-only",
    "destination": "audit-log",
    "readCapability": "workspace/audit"
  }
}

Action logging — opt-in for compliance use cases

The audit block declares whether cooperating clients should append signed action events (decrypt and/or write) to a dedicated audit Hypercore. When logReads or logWrites is true, the Workspace app appends one signed block per action:

{
  "actor":     "did:key:zBob…",
  "action":    "decrypt",
  "subject":   "people.table#table=employees&row=q8kx1fw6mze5jbsto4hyrdgn3c&field=salary",
  "timestamp": 1717200000,
  "client":    "Workspace/1.2.3",
  "signature": "<base64>"
}

scope can be "tier-gated-only" (log only sensitive content, the typical compliance posture) or "everything" (log all reads, including workspace-public content — heavyweight, rarely useful).

The audit log itself is gated by readCapability: only peers holding the named capability can read it. This is a UCAN like any other capability; admins and designated auditors hold it, regular members do not.

Honest framing of the audit option: it is a cooperating-client hint, not cryptographic enforcement. A modified client can refuse to log or log false events. See threat-model.md ("Action-level audit, when needed") for the contract details and when this evidence is sufficient.

When audit.logReads is enabled, workspaces should disclose this at join time. Logging member activity is a privacy-relevant policy choice; members deserve to know.

Honest framing of the rest of the policy file

This is a hint to cooperating apps, not a cryptographic enforcement mechanism. A modified client can ignore it. A user who stays offline forever never receives the policy updates. The encrypted store remains sealed against unauthorised viewers regardless (cryptographic enforcement carries that load). The policy file is what makes the 95% of cooperating clients clean up cleanly on revocation. See threat-model.md for the full contract.

Replicated state property: the policy file is part of the workspace's replicated state. Deleting the local copy does not escape it; the next sync restores it from peers.

envelopes/

Bootstrap envelopes addressed to invited peers. One file per recipient, named by an encoding of their DID (e.g. did_key_z6Mk_etc.json):

{
  "recipient": "did:key:z6Mk…",
  "resource": "workspace://v1/z6MkpKpf2nFiC5h9qDPgJrkBbYBaThkAEcVCgGuBHkXqK4Vc",
  "ucan": "<base64-encoded delegation>",
  "wrappedKeys": {
    "K0_org": "<base64>",
    "K_employee_edit": "<base64>"
  }
}

The envelope is sealed to the recipient's ed25519 public key — only they can unwrap. Carries: the UCAN that grants their capabilities, the symmetric keys they need, the resource URI.

Bootstrap envelopes are the offline first-contact carrier. For ongoing key delivery to peers already in the swarm, see "The two carriers" in permissions-model.md.

keys/

Local key state for this peer specifically. Holds:

  • This peer's own ed25519 identity material (or a reference to where it lives — OS keystore on most platforms)
  • Unwrapped symmetric keys this peer has been authorised for
  • Cursor positions for the key delivery log (so we don't re-scan history on every restart)

Not part of the shared workspace state — this is per-peer machinery. Not included in archive form unless the recipient is explicitly exporting their own state.

Never travels to another device. Not in a share, not in a seed, not in a fixture copy, not behind a developer flag. A peer that needs keys gets them through an envelope sealed to its own DID; a peer that copies someone else's keys/ has stolen an identity rather than joined a workspace. See invariant 6 — this rule exists in the explicit form it does because the general version was read past once already.

store/

The workspace's logs in transport form: an append-only, content-addressed serialisation of every Hypercore block, which is what makes the folder a complete, portable copy of the workspace. Opaque to anyone inspecting it by hand. The Workspace app projects relevant blocks into the working tree (for public-tier content) or into in-memory views (for tier-gated content).

Layout (store format v1):

store/
└── v1/
    └── <log-key-hex>/
        ├── 000000
        ├── 000001
        └── …                ← one file per replication message, in order
  • Each file holds one message of Hypercore's own replication protocol (wire.data): block ciphertext under the relevant tier key, the Merkle proof for it, and — in the first message of a log — the manifest and signed length upgrade. Hydration is a replay: apply the files in ascending sequence exactly as a replica applies messages from a live peer, verifying each against the log's public key, offline, with no other party present. The transport form is the replication protocol, persisted — not a second format with its own verification story.
  • Committed files are never rewritten, renamed, or deleted. There are no locks, no manifests, no counters: a flush only ever appends files with higher sequence numbers. This is the property invariant 4 requires, satisfied by construction rather than by discipline.
  • Writers create each file atomically (write to a temp name inside store/, fsync, rename into place). Readers ignore any name that is not a bare zero-padded sequence number, which also makes them immune to sync engines' conflicted-copy siblings; a torn or tampered file fails verification and is skipped.
  • Sequence numbers order the replay, not the blocks: the protocol may deliver blocks out of index order, and the proofs are built for a reader that has applied precisely the preceding messages.

The store has two forms — only one lives in the folder

The live store the app operates on — the working store — is a Corestore, and Corestore v7 persists through RocksDB: fast, mutable, and full of exactly the lock and manifest files (LOCK, CURRENT, MANIFEST-*) that invariant 4 forbids from ever meeting a cloud-sync engine. It therefore lives in app-private storage, outside the folder, and is not part of this format:

Platform Working store location
macOS ~/Library/Application Support/<bundle id>/p2p/store
iOS / Android app container documents directory, under /p2p

The working store is a rebuildable cache: the union of every transport form it has hydrated plus writes not yet flushed. Losing it loses nothing that has been flushed or replicated.

Lifecycle between the two forms:

open    → hydrate: ingest transport blocks the working store lacks,
          verifying each against its log's public key
edit    → append to the working store; replicate to peers as normal
close   → flush: write blocks the transport form lacks
share   → flush, then the folder is copied by any ordinary means

Copying the folder mid-write yields a workspace that is valid but possibly stale: every complete block file verifies, the newest blocks may be absent, and staleness heals through ordinary replication when the copy next syncs. A torn block file fails verification and is ignored, then re-fetched. This is the same recency model as copying any file while its author is still typing.

Rationale, options considered, and the history that led here: adr/0003-store-dual-form.md.


Permission semantics

A workspace can contain a mix of:

  • Workspace-public content — readable by any peer holding the workspace's base key (K0_org). The default for .md, .canvas, and most .table files.
  • Tier-gated content — encrypted with tier-specific keys (K1, K2, K_hr, K_admin, etc.) distributed via UCAN delegation. Required for sensitive content; opt-in via x-tier annotations in schemas or via folder-level tiering conventions.

A peer's effective access at any moment is the union of every key they hold, which is the union of every UCAN delegation chain that terminates at their DID. The audit trail is the chain itself (threat-model.md).

File-format-specific semantics

.md, .canvas — flat permission model. Three roles per file: read, edit, admin. Either workspace-public (one key, everyone can read) or tier-gated as a whole file (encrypted in the store, only authorised viewers see it in the working tree).

.table — gains field-level tiering when inside a workspace (planned, not built). Fields without x-tier are tier 0 (workspace-public). Fields with x-tier: 1, 2, ... are encrypted in the store. The rows files on disk contain only the tier-0 fields. schema.json declares both the public and the hidden field IDs (see below). x-tier is an extension key, which the .table spec lets a schema carry (third-party keys take an x- prefix; readers ignore them, writers keep them).

Refer to table-file-format/docs/PERMISSIONS.md (PR #26) for the consumer-side view of .table's tiering.


Hidden schema entries — protecting field names

For fields whose name itself is sensitive (e.g. redundancy_consideration_date, where the existence of the field reveals something even before any value is read), the format supports gating the schema entry too.

Mechanism

schema.json declares two arrays (x-hiddenFields takes the x- prefix the .table spec asks of extension keys):

{
  "fields": [
    { "name": "name",   "type": "string" },
    { "name": "team",   "type": "string" },
    { "name": "salary", "type": "number", "x-tier": 2 }
  ],
  "x-hiddenFields": [
    { "id": "h_a3b9", "tier": "redundancy" },
    { "id": "h_c4d2", "tier": "redundancy" }
  ]
}

The visible fields array lists fields whose names are workspace-public. The x-hiddenFields array lists opaque IDs plus their tier hints — enough for the Workspace app to know "two additional fields exist at the redundancy tier" but nothing about what those fields are.

For each x-hiddenFields[i].id, a sealed entry in the encrypted store contains the full schema entry:

{ "id": "h_a3b9", "name": "redundancy_consideration_date", "type": "date" }

Authorised viewers (those holding the relevant tier key) fetch these entries, decrypt them, and merge into a complete in-memory schema. Per-row values for hidden fields use the same opaque IDs as keys — encrypted (rowId, h_a3b9) blocks in the store.

What each viewer sees

Viewer schema.json rows files
Non-Workspace tool name, team, salary + 2 opaque hidden IDs only public field values per row
Workspace member without the redundancy key same as above same as above
Workspace admin with the redundancy key full schema with redundancy_consideration_date etc. merged view with decrypted hidden-field values

The unauthorised reader knows "two hidden fields exist at the redundancy tier" but nothing else. Existence + count + tier hint are workspace-public; semantics are sealed. If the existence of a schema field being sensitive matters too (i.e. you don't want anyone to know there are any hidden fields at all), the x-hiddenFields array can be omitted entirely and the IDs distributed via the live key delivery log — more aggressive but possible.

Where the full schema lives

In two physical places that the app combines in memory:

  • <table>/schema.json — public entries + hidden-field IDs (markers)
  • .workspace/store/ — encrypted hidden-schema-entry contents, keyed by the IDs

The "full schema" exists only as an in-memory object on an authorised viewer's machine.

Standalone-table portability

If a .table is taken out of a workspace (moved, exported as a standalone file for use in a non-Workspace tool), it carries only its own files: each table's schema.json and rows files. The encrypted blobs in .workspace/store/ don't travel — they were workspace-container state.

On export, the format strips the x-hiddenFields array from the exported schema.json (since the references would be dead anyway). The standalone table is a clean, self-contained data file of the tier-0 public content.


Portability — the folder is the unit

There are three distinct operations a user might call "sharing." Each has clear semantics.

Default: copy the folder

The user opens Finder (or equivalent), drags the .workspace/ folder to a USB stick / AirDrop / NAS / email attachment / cloud storage. No special export step, no Workspace app needed.

What gets sent:

  • Workspace-public content in plaintext (intended — these are public anyway)
  • .workspace/manifest.json, attestation.json, policy.json
  • Tier-gated content as encrypted bytes in .workspace/store/
  • Bootstrap envelopes addressed to whoever was already invited

What does not get sent:

  • Tier-gated content in plaintext form (it never existed on disk)
  • The recipient's own key state (unless they're moving their own copy)

The recipient picks up the folder. With the Workspace app and a valid identity, the app validates the attestation, finds (or doesn't find) an envelope for them, projects the working tree according to their keys. Without the Workspace app, they can browse the public content with any tool; the rest is opaque.

This is the default sharing flow. Safe by construction. The user does not need to think about what's leaking.

Share-with — invite-a-recipient

A guided UX flow inside the Workspace app: "share this workspace with X." Before sending, the user adds a bootstrap envelope for X sealed to their DID, carrying whichever keys they should hold. After the envelope exists in .workspace/envelopes/, the folder is shared via any of the default channels above. The recipient is "pre-onboarded" and can use the workspace immediately.

This is convenience layered on top of the default. The single click adds an envelope; everything else is regular file sharing.

Export plaintext — explicit "leave the protection layer"

A separate UX flow: "export this .table as a standalone file," or "export the entire workspace as a plain folder." Decrypts everything the current user is authorised to read and writes it to a new folder outside the .workspace/ container. No .workspace/ metadata, no encrypted store, no envelopes — just the plaintext content.

The result is a plain folder, suitable for use with non-Workspace tools forever after. The user explicitly steps outside the protection layer. Once exported, the content is no longer protected by the permission model — it's just data on disk, subject to whatever the user does with it.

Summary

Operation What it produces UX
Copy folder The .workspace/ folder as-is File system (default)
Share-with Same + an envelope pre-addressed to recipient In-app, one click
Export plaintext A plain folder, no permission model In-app, explicit "leave the container" step

The folder-as-unit default is the foot-gun-free path. The other two exist when the user wants them.


What the format is not

  • Not a redefinition of the file formats inside it. .md is still .md. .canvas is still .canvas. .table is still .table. The workspace just contains them and adds an enforcement layer.
  • Not the protocol. The cryptographic mechanics (UCAN, key wrapping, Hypercore, Hyperswarm, root attestation) live in permissions-model.md. This document describes the on-disk shape and the user-facing surface.
  • Not a lock-in. The working tree is the user's data, always readable without a Workspace app. The container adds value when Workspace is present; it does not subtract value when Workspace is absent.

Open design questions

Explicit so future contributors don't quietly pick defaults:

  1. Hidden-fields visibility. Current sketch has x-hiddenFields as a public array (count + tier hint visible to all workspace members). Alternative: omit x-hiddenFields from schema.json entirely; distribute hidden-field IDs only via the encrypted store. More aggressive privacy; harder to reason about structurally.
  2. Hidden-field stripping on export. When a .table is exported from a workspace, do we strip x-hiddenFields from the exported schema.json (clean — current preference) or keep markers as "dead references" (honest historical record). Format choice; minor UX.
  3. Archive format on light bundles. When packaging the magnet- equivalent (manifest + attestation + envelopes, no store), is it a tar, zip, plain folder, single binary file? Affects how it's recognised by default OS tooling. 3a. macOS bundle UTI. Should .workspace register as a Finder bundle? It buys a single double-clickable artefact but hides folder contents by default, which fights the browsable-folder invariant (see Invariants → "A caution"). Leaning: working folders stay plain; bundle treatment, if any, applies only to exported/portable artefacts. Needs a deliberate call before the macOS app commits to a UTI registration.
  4. Folder-level whole-file tiering. .table has x-tier for fields. Should there be an equivalent for whole files (a "tier this folder at K1" convention)? If so, where does the declaration live — in manifest.json, in a per-folder dotfile, both?
  5. Workspace identity vs root identity. Resolved: 1 workspace = 1 root identity in v1. The workspace's root pubkey IS the workspaceId at the URI layer; no separate identifier. Orgs with multiple workspaces create multiple .workspace folders, each with its own root keypair. See uri-scheme.md for the URI-side framing of this decision.
  6. Workspace versioning. manifest.json carries a formatVersion. What changes warrant a version bump? Forward compatibility expectations for older readers encountering newer workspaces?
  7. Manifest content boundary. What belongs in manifest.json vs separate files in .workspace/? Tension between "single authoritative file" and "separation of concerns."
  8. Forks and copies. If Alice forks a workspace and modifies it, what identifies the fork as related to the original? Trail in the manifest, separate originWorkspaceId, or no formal relationship?
  9. workspace:// URI scheme details. Concrete encoding, authority component (workspaceId? friendly name?), how the manifest/attestation are embedded (inline base64, fetched separately).

These are not blockers for early implementation; they will be answered as implementation forces choices.


Relationship to the wider spike

This format is the container for everything the permissions model delivers. The model defines the cryptographic protocol; the format defines where the bytes sit on disk. Both serve the contract spelled out in threat-model.md.

Implementation work that materially affects this format:

  • @workspace.sh/p2p-runtime/src/wrap.ts — produces the sealed bytes that go into envelopes/ and into per-field encryption.
  • @workspace.sh/p2p-runtime/src/attestation.ts — produces attestation.json and the .workspace/policy.json signature.
  • @workspace.sh/ucan-boundary — issues and validates the UCANs inside envelopes.
  • @workspace.sh/portable-bootstrap — creates and consumes bundles; handles the bootstrap envelope flow.
  • #9 (key delivery log) — the live-log carrier for ongoing envelope delivery between connected peers (vs. the in-bundle envelopes for offline first-contact).
  • #10 (topic-layer auth) — gates connection to the workspace's swarm; the topic identifier comes from manifest.json.

Cross-references


Up: Format · All docs