← Back to Craft
AgentCraft
Document formats and migration
Preserves editable document meaning across serialization, format changes and exports, including content the current editor does not understand.
document-serialization-migration
See how it helpsWhen is it useful?
Use it when saved documents outlive editor releases or must move between rich and simpler formats.
What does it help you do?
- Separates editable source documents from derived exports.
- Preserves unknown blocks and validates versioned schemas.
- Tests deterministic migrations and import-export fidelity.
Try asking this
Upgrade document format while preserving blocks from a newer editor. Open a document containing an unknown chart block, edit a paragraph and save. The chart's original data should survive the round trip unchanged.
Detailed documentation
Read the skill’s original instructions, examples and checks in their authored language.
Show less
Document Serialization & Migration
Use this skill when designing saved document JSON/AST formats, validating persisted editor payloads, migrating legacy document versions, or generating HTML/Markdown/PDF/email exports.
Separate Editable Source Document from Derived Exports
- Persist the Structured Source Model, Not Rendered Output:
- Always save the canonical structured document (
schemaVersion, root blocks, attributes, marks) as the authoritative source of truth. - Treat rendered HTML, email MJML/table HTML, Markdown, PDF, or plain-text search indexes as derived outputs generated from the structured document. Never try to reconstruct complex editor state by reverse-parsing exported presentation HTML when a structured format exists.
- Always save the canonical structured document (
- Explicit
schemaVersion& Server/Client Validation:- Include an explicit integer
schemaVersionat the root of every persisted document and local draft. - Validate document payloads on load and on server save: verify required node fields, valid block types, allowed nesting, and attribute types.
- Include an explicit integer
Safe Schema Evolution & Unknown-Block Preservation
- Never Silently Drop Unsupported or Newer Block Types:
- When an older client or partial editor loads a document containing a block type or attribute it does not yet recognize (or a plugin that is disabled), preserve the unknown block's raw data intact in an inert
UnsupportedBlock/ passthrough wrapper node rather than stripping it on load and deleting the user's content on the next autosave.
- When an older client or partial editor loads a document containing a block type or attribute it does not yet recognize (or a plugin that is disabled), preserve the unknown block's raw data intact in an inert
- Deterministic Version Migrations (
v1 -> v2 -> v3):- Implement pure, idempotent migration functions per version step (
migrateV1ToV2(doc)), tested with representative real-world documents. - Separate read-time migration from silent write-back: do not mark a newly opened document as
dirtyor overwrite the server record with a migrated format without explicit version tracking or user edit.
- Implement pure, idempotent migration functions per version step (
Export Fidelity & Round-Trip Safety
- When importing/exporting Markdown, HTML, or email templates, document accurately which rich blocks degrade gracefully in target formats (e.g., interactive callouts or multi-column layouts in email clients) and test round-trip serialization (
parse(serialize(doc))) for all supported blocks.
Checklist
- Does every persisted document carry an explicit
schemaVersionseparate from derived HTML/Markdown/email exports? - Are unrecognized or newer block types preserved in a safe passthrough node rather than silently deleted on load/save?
- Are format migrations pure, step-by-step, and tested against legacy document fixtures?
- Does loading and migrating a document avoid falsely marking the editor as
modifiedbefore the user edits?
Included files 1
SKILL.md
