{
  "slug": "ai-lock",
  "title": "AI Lock — Field-Level Content Protection",
  "description": "How AI Lock prevents AI agents from overwriting human edits — field-level protection enforced at the engine level.",
  "category": "concepts",
  "order": 4,
  "locale": "en",
  "translationGroup": "8f7534a3-e648-4862-a040-dcd9021a44d9",
  "helpCardId": null,
  "content": "## The problem\n\nYou carefully edit a blog post title. An AI agent runs overnight and overwrites it with a generated version. Your work is gone.\n\nThis happens in every CMS that bolts AI onto existing content workflows. AI and humans fight over the same fields with no rules about who wins.\n\n## How AI Lock works\n\n@webhouse/cms tracks **who last edited each field** — human or AI. When a human edits a field, it becomes **locked**. AI agents can never overwrite a locked field. Only a human can unlock it.\n\nThis isn't a setting you toggle. It's enforced at the engine level, in every write operation, through the `WriteContext` actor system.\n\n### The _fieldMeta system\n\nEvery document has a `_fieldMeta` object that tracks the lock state per field:\n\n```json\n{\n  \"slug\": \"my-post\",\n  \"data\": {\n    \"title\": \"My Carefully Written Title\",\n    \"content\": \"AI-generated content here...\"\n  },\n  \"_fieldMeta\": {\n    \"title\": {\n      \"lockedBy\": \"user\",\n      \"lockedAt\": \"2026-03-30T10:00:00Z\",\n      \"lastEditedBy\": \"cb@webhouse.dk\"\n    },\n    \"content\": {\n      \"lockedBy\": null,\n      \"lastEditedBy\": \"ai:content-writer\"\n    }\n  }\n}\n```\n\nIn this example:\n- **title** is locked — a human edited it. No AI agent can touch it.\n- **content** is unlocked — AI generated it. AI agents can update it freely.\n\n### Write context actors\n\nEvery write operation carries a `WriteContext` that identifies who's making the change:\n\n```typescript\ninterface WriteContext {\n  actor: \"user\" | \"ai\" | \"system\" | \"import\";\n  userId?: string;\n  agentId?: string;\n  source?: string;\n}\n```\n\nWhen `actor: \"user\"`, the CMS auto-locks edited fields. When `actor: \"ai\"`, the CMS checks locks and skips locked fields.\n\n### What happens when AI tries to write a locked field\n\n1. AI agent calls `update_document` with new data for all fields\n2. CMS engine reads `_fieldMeta` for each field\n3. Locked fields are **silently skipped** — AI data is ignored for those fields\n4. Unlocked fields are updated normally\n5. No error thrown — the agent doesn't need to know about locks\n\nThis means AI agents can run bulk operations across the entire site without any risk of overwriting human work.\n\n## Configuration\n\n### Per-field AI lock behavior\n\n```typescript\n{\n  name: 'title',\n  type: 'text',\n  aiLock: {\n    autoLockOnEdit: true,    // Lock when human edits (default: true)\n    lockable: true,          // Whether field can be locked at all (default: true)\n    requireApproval: false,  // Require human approval before AI writes\n  }\n}\n```\n\n### Unlocking a field\n\nIn the editor, each field shows a lock icon when locked:\n- 🔒 **Locked** — human-edited, AI cannot change\n- 🔓 **Unlocked** — AI can update freely\n\nClick the lock icon to toggle. Only humans can unlock fields.\n\n## Use cases\n\n### Content Writer agent\n- AI generates blog posts → all fields unlocked\n- Human edits the title → title locks\n- AI runs SEO optimization → updates description, keywords, but **skips title**\n\n### Translator agent\n- AI translates all fields to Danish\n- Human corrects a specific phrase → that field locks\n- AI re-translates the page → skips the corrected field\n\n### Bulk SEO optimization\n- AI runs `bulk_update` on 100 documents\n- Documents with human-edited meta titles → titles preserved\n- Documents with AI-generated titles → titles updated\n\n## For AI builders\n\nWhen building sites or scripts that write content:\n\n```typescript\n// Creating content as AI (fields stay unlocked)\nawait cms.content.create('posts', {\n  slug: 'new-post',\n  data: { title: 'AI Title', content: '...' },\n}, { actor: 'ai', agentId: 'content-writer' });\n\n// Creating content as user (fields auto-lock)\nawait cms.content.create('posts', {\n  slug: 'new-post',\n  data: { title: 'My Title', content: '...' },\n}, { actor: 'user', userId: 'cb@webhouse.dk' });\n```\n\n## Why this is different\n\nOther CMS platforms with AI features either:\n- Let AI overwrite everything (dangerous)\n- Require manual \"approve each change\" workflows (slow)\n- Have no concept of field-level ownership (crude)\n\n@webhouse/cms AI Lock is:\n- **Automatic** — locks on human edit, no manual step\n- **Granular** — per-field, not per-document\n- **Non-blocking** — AI agents run freely, locked fields are silently skipped\n- **Transparent** — lock state visible in editor and `_fieldMeta`\n- **Engine-level** — enforced in every write path, not just the UI",
  "excerpt": "The problem\n\nYou carefully edit a blog post title. An AI agent runs overnight and overwrites it with a generated version. Your work is gone.\n\nThis happens in every CMS that bolts AI onto existing content workflows. AI and humans fight over the same fields with no rules about who wins.\n\n How AI Lock ",
  "seo": {
    "metaTitle": "AI Lock — Field-Level Content Protection — webhouse.app Docs",
    "metaDescription": "How AI Lock prevents AI agents from overwriting human edits — field-level protection enforced at the engine level."
  },
  "createdAt": "2026-03-30T19:25:39.857Z",
  "updatedAt": "2026-03-30T19:25:39.858Z"
}