{
	"name": "MANEF Diagram — JSON and Markdown converter (offline example)",
	"active": false,
	"nodes": [
		{
			"id": "manef-manual-trigger",
			"name": "Manual Trigger",
			"type": "n8n-nodes-base.manualTrigger",
			"typeVersion": 1,
			"position": [240, 300],
			"parameters": {}
		},
		{
			"id": "manef-synthetic-input",
			"name": "Synthetic example input",
			"type": "n8n-nodes-base.code",
			"typeVersion": 2,
			"position": [500, 300],
			"notes": "Synthetic data only. Replace this node with your own input items: {format: \"json\" | \"md\", source: \"...\", target: \"json\" | \"md\"}. The converter never substitutes this sample for invalid input.",
			"notesInFlow": true,
			"parameters": {
				"mode": "runOnceForAllItems",
				"language": "javaScript",
				"jsCode": "const document = {\n  \"format\": \"manef-diagram\",\n  \"schemaVersion\": 1,\n  \"title\": \"Synthetic order review\",\n  \"graph\": {\n    \"schemaVersion\": 1,\n    \"nodes\": [\n      {\n        \"id\": \"request\",\n        \"label\": \"Request\",\n        \"tags\": [\n          \"example\"\n        ],\n        \"inputs\": [],\n        \"outputs\": [\n          {\n            \"id\": \"out\",\n            \"label\": \"Order\"\n          }\n        ],\n        \"views\": [\n          {\n            \"id\": \"sequence\",\n            \"kind\": \"sequence\",\n            \"title\": \"Review sequence\",\n            \"format\": \"md\",\n            \"source\": \"sequenceDiagram\\n  Request->>Review: Check order\\n  Review-->>Request: Approved\"\n          }\n        ]\n      },\n      {\n        \"id\": \"review\",\n        \"label\": \"Review\",\n        \"tags\": [\n          \"example\"\n        ],\n        \"inputs\": [\n          {\n            \"id\": \"in\",\n            \"label\": \"Order\"\n          }\n        ],\n        \"outputs\": [],\n        \"child\": {\n          \"schemaVersion\": 1,\n          \"nodes\": [\n            {\n              \"id\": \"check\",\n              \"label\": \"Check totals\",\n              \"tags\": [],\n              \"inputs\": [],\n              \"outputs\": []\n            }\n          ],\n          \"edges\": []\n        }\n      }\n    ],\n    \"edges\": [\n      {\n        \"id\": \"order-review\",\n        \"source\": \"request\",\n        \"sourcePort\": \"out\",\n        \"target\": \"review\",\n        \"targetPort\": \"in\",\n        \"label\": \"Review order\"\n      }\n    ]\n  },\n  \"ui\": {\n    \"diagramMode\": \"flow\",\n    \"zoom\": 1,\n    \"pan\": {\n      \"x\": 0,\n      \"y\": 0\n    },\n    \"positions\": {\n      \"request\": {\n        \"x\": 40,\n        \"y\": 80\n      },\n      \"review\": {\n        \"x\": 360,\n        \"y\": 80\n      }\n    }\n  },\n  \"extensions\": {\n    \"example\": {\n      \"synthetic\": true,\n      \"order\": [\n        \"request\",\n        \"review\"\n      ],\n      \"nullable\": null\n    }\n  }\n};\nreturn [{ json: { format: \"json\", source: JSON.stringify(document), target: \"md\" } }];"
			}
		},
		{
			"id": "manef-document-converter",
			"name": "MANEF document converter",
			"type": "n8n-nodes-base.code",
			"typeVersion": 2,
			"position": [800, 300],
			"notes": "JSON ↔ MANEF Markdown with the same canonical document core as the editor. Returns {document, source, format} per item and retains item linking. Markdown must contain exactly one manef-diagram-json fenced block. Plain Mermaid alone cannot preserve a complete document. Offline Code-node smoke tested; live n8n import/execution is a separate acceptance gate.",
			"notesInFlow": true,
			"parameters": {
				"mode": "runOnceForAllItems",
				"language": "javaScript",
				"jsCode": "// Generated by bun scripts/build-n8n-converter.mjs from the canonical MANEF document core.\n// n8n Code node: Run Once for All Items. No credentials, imports, or network access.\nlet __manefOutput;\nfunction __manefSetResult(items) { __manefOutput = items; }\n(() => {\n  // slices/architecture-inventory/lib/json.ts\n  var MAX_JSON_DEPTH = 100;\n  var MAX_JSON_VALUES = 200000;\n  function isJsonValue(value) {\n    const ancestors = new Set;\n    let count = 0;\n    function visit(current, depth) {\n      count += 1;\n      if (count > MAX_JSON_VALUES || depth > MAX_JSON_DEPTH)\n        return false;\n      if (current === null || typeof current === \"string\" || typeof current === \"boolean\")\n        return true;\n      if (typeof current === \"number\") {\n        return Number.isFinite(current) && !Object.is(current, -0) && (!Number.isInteger(current) || Number.isSafeInteger(current));\n      }\n      if (typeof current !== \"object\")\n        return false;\n      if (ancestors.has(current))\n        return false;\n      const array = Array.isArray(current);\n      const prototype = Object.getPrototypeOf(current);\n      if (array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null)\n        return false;\n      const keys = Reflect.ownKeys(current);\n      if (keys.some((key) => typeof key !== \"string\"))\n        return false;\n      if (array) {\n        if (keys.length !== current.length + 1)\n          return false;\n        for (let index = 0;index < current.length; index += 1) {\n          if (!Object.hasOwn(current, index))\n            return false;\n        }\n      }\n      ancestors.add(current);\n      for (const key of keys) {\n        if (array && key === \"length\")\n          continue;\n        const descriptor = Object.getOwnPropertyDescriptor(current, key);\n        if (!descriptor?.enumerable || !Object.hasOwn(descriptor, \"value\"))\n          return false;\n        if (!visit(descriptor.value, depth + 1))\n          return false;\n      }\n      ancestors.delete(current);\n      return true;\n    }\n    return visit(value, 0);\n  }\n  function cloneJson(value) {\n    if (!isJsonValue(value))\n      throw new Error(\"Data must use plain JSON values with finite numbers, safe integers, and no negative zero. Encode larger integers as strings.\");\n    return JSON.parse(JSON.stringify(value));\n  }\n  function sameJson(a, b) {\n    if (!isJsonValue(a) || !isJsonValue(b))\n      return false;\n    function signature(value) {\n      if (value === null || typeof value !== \"object\")\n        return JSON.stringify(value);\n      if (Array.isArray(value))\n        return \"[\" + value.map(signature).join(\",\") + \"]\";\n      return \"{\" + Object.keys(value).sort().map((key) => JSON.stringify(key) + \":\" + signature(value[key])).join(\",\") + \"}\";\n    }\n    return signature(a) === signature(b);\n  }\n\n  // slices/architecture-inventory/lib/diagram-views.ts\n  var DIAGRAM_KINDS = [\n    { id: \"flowchart\", label: \"Flowchart\", group: \"Process\", keyword: \"flowchart\" },\n    { id: \"sequence\", label: \"Sequence\", group: \"Process\", keyword: \"sequenceDiagram\" },\n    { id: \"state\", label: \"State\", group: \"Process\", keyword: \"stateDiagram-v2\" },\n    { id: \"journey\", label: \"User journey\", group: \"Process\", keyword: \"journey\" },\n    { id: \"class\", label: \"Class\", group: \"Structure\", keyword: \"classDiagram\" },\n    { id: \"er\", label: \"Entity relationship\", group: \"Structure\", keyword: \"erDiagram\" },\n    { id: \"c4\", label: \"C4\", group: \"Structure\", keyword: \"C4Context\" },\n    { id: \"block\", label: \"Block\", group: \"Structure\", keyword: \"block-beta\" },\n    { id: \"architecture\", label: \"Architecture\", group: \"Structure\", keyword: \"architecture-beta\" },\n    { id: \"packet\", label: \"Packet\", group: \"Structure\", keyword: \"packet-beta\" },\n    { id: \"mindmap\", label: \"Mindmap\", group: \"Structure\", keyword: \"mindmap\" },\n    { id: \"tree\", label: \"Tree\", group: \"Structure\", keyword: \"treeView-beta\" },\n    { id: \"requirement\", label: \"Requirement\", group: \"Structure\", keyword: \"requirementDiagram\" },\n    { id: \"gantt\", label: \"Gantt\", group: \"Planning\", keyword: \"gantt\" },\n    { id: \"timeline\", label: \"Timeline\", group: \"Planning\", keyword: \"timeline\" },\n    { id: \"git\", label: \"Git graph\", group: \"Planning\", keyword: \"gitGraph\" },\n    { id: \"kanban\", label: \"Kanban\", group: \"Planning\", keyword: \"kanban\" },\n    { id: \"pie\", label: \"Pie\", group: \"Charts\", keyword: \"pie\" },\n    { id: \"quadrant\", label: \"Quadrant\", group: \"Charts\", keyword: \"quadrantChart\" },\n    { id: \"xy\", label: \"XY chart\", group: \"Charts\", keyword: \"xychart-beta\" },\n    { id: \"radar\", label: \"Radar\", group: \"Charts\", keyword: \"radar-beta\" },\n    { id: \"sankey\", label: \"Sankey\", group: \"Charts\", keyword: \"sankey-beta\" },\n    { id: \"treemap\", label: \"Treemap\", group: \"Charts\", keyword: \"treemap-beta\" },\n    { id: \"ishikawa\", label: \"Ishikawa\", group: \"Process\", keyword: \"ishikawa-beta\" },\n    { id: \"swimlane\", label: \"Swimlane\", group: \"Process\", keyword: \"swimlane-beta\" },\n    { id: \"eventmodeling\", label: \"Event modeling\", group: \"Process\", keyword: \"eventmodeling\" },\n    { id: \"agentflow\", label: \"Agent flow\", group: \"Process\", keyword: \"agentflow-beta\" },\n    { id: \"usecase\", label: \"Use case\", group: \"Structure\", keyword: \"usecase-beta\" },\n    { id: \"railroad\", label: \"Railroad\", group: \"Structure\", keyword: \"railroad-beta\" },\n    { id: \"info\", label: \"Info card\", group: \"Structure\", keyword: \"info\" },\n    { id: \"venn\", label: \"Venn\", group: \"Charts\", keyword: \"venn-beta\" },\n    { id: \"wardley\", label: \"Wardley map\", group: \"Strategy\", keyword: \"wardley-beta\" },\n    { id: \"cynefin\", label: \"Cynefin\", group: \"Strategy\", keyword: \"cynefin-beta\" }\n  ];\n  function diagramKind(id) {\n    return DIAGRAM_KINDS.find((item) => item.id === id);\n  }\n  function isDiagramKind(id) {\n    return diagramKind(id) !== undefined;\n  }\n  var MAX_NODE_VIEW_SOURCE_LENGTH = 200000;\n  var MAX_AUTHORED_SOURCE_LENGTH = 20000;\n  var MAX_JSON_DEPTH2 = 24;\n  var VIEW_ENVELOPE_FORMAT = \"manef-node-view\";\n  var VIEW_PAYLOAD_LANGUAGE = \"manef-node-view-json\";\n  function isRecord(value) {\n    return typeof value === \"object\" && value !== null && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);\n  }\n  function assertJsonValue(value) {\n    if (!isJsonValue(value)) {\n      throw new Error(\"Node view metadata must contain only finite, plain JSON values.\");\n    }\n    const pending = [{ value, depth: 0 }];\n    while (pending.length > 0) {\n      const item = pending.pop();\n      if (item.depth > MAX_JSON_DEPTH2)\n        throw new Error(\"Node view metadata is nested too deeply.\");\n      if (item.value !== null && typeof item.value === \"object\") {\n        for (const child of Object.values(item.value)) {\n          pending.push({ value: child, depth: item.depth + 1 });\n        }\n      }\n    }\n  }\n  function assertViewShape(value) {\n    if (!isRecord(value) || typeof value.id !== \"string\" || value.id.length === 0 || value.id.length >= 80 || typeof value.kind !== \"string\" || !isDiagramKind(value.kind) || typeof value.title !== \"string\" || typeof value.source !== \"string\" || value.source.length > MAX_NODE_VIEW_SOURCE_LENGTH || value.format !== \"md\" && value.format !== \"json\") {\n      throw new Error(\"Invalid node view.\");\n    }\n    assertJsonValue(value);\n    if (JSON.stringify(value).length > MAX_NODE_VIEW_SOURCE_LENGTH) {\n      throw new Error(\"Node view exceeds the conversion size limit.\");\n    }\n  }\n  function fencedBlocks(source) {\n    const blocks = [];\n    const lines = source.match(/[^\\n]*(?:\\n|$)/g) ?? [];\n    let offset = 0;\n    let open;\n    for (const line of lines) {\n      if (!open) {\n        const match = /^ {0,3}(`{3,}|~{3,})([^\\r\\n]*)\\r?\\n?$/.exec(line);\n        if (match && !(match[1][0] === \"`\" && match[2].includes(\"`\"))) {\n          open = {\n            marker: match[1][0],\n            length: match[1].length,\n            info: match[2].trim().toLowerCase(),\n            start: offset,\n            body: offset + line.length\n          };\n        }\n      } else {\n        const close = /^ {0,3}(`{3,}|~{3,})[ \\t]*\\r?\\n?$/.exec(line);\n        if (close && close[1][0] === open.marker && close[1].length >= open.length) {\n          blocks.push({\n            info: open.info,\n            content: source.slice(open.body, offset),\n            start: open.start,\n            end: offset + line.length\n          });\n          open = undefined;\n        }\n      }\n      offset += line.length;\n    }\n    if (open?.info === VIEW_PAYLOAD_LANGUAGE || open?.info === \"mermaid\") {\n      throw new Error(\"Node view has an unclosed diagram or canonical payload fence.\");\n    }\n    return blocks;\n  }\n  function codeFence(language, content) {\n    const runs = content.match(/`+/g) ?? [];\n    const width = Math.max(3, ...runs.map((run) => run.length + 1));\n    const marker = \"`\".repeat(width);\n    return `${marker}${language}\n${content}\n${marker}\n`;\n  }\n  function envelopeValue(value) {\n    if (!isRecord(value) || value.format !== VIEW_ENVELOPE_FORMAT)\n      return;\n    if (value.schemaVersion !== 1)\n      throw new Error(\"Unsupported node view schema version.\");\n    if (Object.keys(value).some((key) => ![\"format\", \"schemaVersion\", \"view\"].includes(key))) {\n      throw new Error(\"Node view wrapper has unsupported fields.\");\n    }\n    assertViewShape(value.view);\n    return value;\n  }\n  function authoredMermaidSource(view) {\n    if (view.format === \"json\") {\n      const value = JSON.parse(view.source);\n      if (isRecord(value) && typeof value.source === \"string\")\n        return value.source.trim();\n      throw new Error(\"JSON view needs a source string.\");\n    }\n    const blocks = fencedBlocks(view.source).filter((block) => block.info === \"mermaid\");\n    if (blocks.length > 1)\n      throw new Error(\"Node view contains multiple Mermaid diagrams.\");\n    if (blocks.length === 1)\n      return blocks[0].content.trim();\n    return view.source.replace(/^#\\s+.+\\r?\\n+/, \"\").trim();\n  }\n  function markdownEnvelope(envelope) {\n    const preview = codeFence(\"mermaid\", authoredMermaidSource(envelope.view));\n    const payload = codeFence(VIEW_PAYLOAD_LANGUAGE, JSON.stringify(envelope, null, 2));\n    const title = envelope.view.title.replace(/[\\r\\n]+/g, \" \");\n    return `# ${title}\n\n${preview}\n${payload}`;\n  }\n  function readEnvelope(view) {\n    if (view.source.length > MAX_NODE_VIEW_SOURCE_LENGTH) {\n      throw new Error(\"Node view exceeds the conversion size limit.\");\n    }\n    if (view.format === \"json\") {\n      let parsed;\n      try {\n        parsed = JSON.parse(view.source);\n      } catch {\n        if (view.source.includes(VIEW_ENVELOPE_FORMAT)) {\n          throw new Error(\"Invalid node view wrapper JSON.\");\n        }\n        return;\n      }\n      return envelopeValue(parsed);\n    }\n    const blocks = fencedBlocks(view.source);\n    const payloads = blocks.filter((block) => block.info === VIEW_PAYLOAD_LANGUAGE);\n    if (payloads.length > 1)\n      throw new Error(\"Node view contains multiple canonical payloads.\");\n    if (payloads.length === 0)\n      return;\n    const envelope = envelopeValue(JSON.parse(payloads[0].content));\n    if (!envelope)\n      throw new Error(\"Invalid canonical node view payload.\");\n    if (view.source !== markdownEnvelope(envelope)) {\n      throw new Error(\"Markdown preview does not match its canonical node view payload.\");\n    }\n    return envelope;\n  }\n  function originalView(view) {\n    assertViewShape(view);\n    const envelope = readEnvelope(view);\n    const original = envelope?.view ?? view;\n    if (envelope) {\n      const metadata = (value) => Object.fromEntries(Object.entries(value).filter(([key]) => key !== \"source\" && key !== \"format\"));\n      if (!sameJson(metadata(view), metadata(original))) {\n        throw new Error(\"Node view wrapper metadata does not match its canonical payload.\");\n      }\n    }\n    if (envelope && readEnvelope(original))\n      throw new Error(\"Nested node view wrappers are not supported.\");\n    if (original.source.length > MAX_AUTHORED_SOURCE_LENGTH) {\n      throw new Error(\"Authored node view source exceeds 20,000 characters.\");\n    }\n    return original;\n  }\n  function isNodeView(value) {\n    try {\n      assertViewShape(value);\n      originalView(value);\n      return true;\n    } catch {\n      return false;\n    }\n  }\n  function mermaidSource(view) {\n    const envelope = readEnvelope(view);\n    if (!envelope) {\n      if (view.source.length > MAX_AUTHORED_SOURCE_LENGTH) {\n        throw new Error(\"Authored node view source exceeds 20,000 characters.\");\n      }\n      return authoredMermaidSource(view);\n    }\n    if (\"id\" in view || \"title\" in view) {\n      assertViewShape(view);\n      return authoredMermaidSource(originalView(view));\n    }\n    const original = originalView(envelope.view);\n    if (original !== envelope.view)\n      throw new Error(\"Nested node view wrappers are not supported.\");\n    if (view.kind !== original.kind)\n      throw new Error(\"Node view kind does not match its canonical payload.\");\n    return authoredMermaidSource(original);\n  }\n\n  // slices/architecture-inventory/lib/graph.ts\n  var MAX_DIAGRAM_DEPTH = 3;\n  function isRecord2(value) {\n    return typeof value === \"object\" && value !== null && !Array.isArray(value);\n  }\n  function isPort(value) {\n    return isRecord2(value) && typeof value.id === \"string\" && value.id.length > 0 && typeof value.label === \"string\" && (value.kind === undefined || typeof value.kind === \"string\");\n  }\n  function arePorts(value) {\n    if (!Array.isArray(value) || !value.every(isPort))\n      return false;\n    return new Set(value.map((port) => port.id)).size === value.length;\n  }\n  function isInventoryRef(value) {\n    return isRecord2(value) && typeof value.kind === \"string\" && [\"reference\", \"repo\", \"domain\", \"hostname\", \"convex\"].includes(value.kind) && typeof value.key === \"string\" && value.key.length > 0;\n  }\n  function connectionKey(edge) {\n    return JSON.stringify([edge.source, edge.sourcePort, edge.target, edge.targetPort]);\n  }\n  function validateGraph(value) {\n    return validateGraphAt(value, 0);\n  }\n  function validateGraphAt(value, depth) {\n    if (depth > MAX_DIAGRAM_DEPTH)\n      return false;\n    if (!isRecord2(value) || value.schemaVersion !== 1 || !Array.isArray(value.nodes) || !Array.isArray(value.edges)) {\n      return false;\n    }\n    const nodes = value.nodes;\n    const edges = value.edges;\n    const nodeIds = new Set;\n    const nodeMap = new Map;\n    for (const raw of nodes) {\n      if (!isRecord2(raw) || typeof raw.id !== \"string\" || raw.id.length === 0 || nodeIds.has(raw.id) || typeof raw.label !== \"string\" || raw.subtitle !== undefined && typeof raw.subtitle !== \"string\" || raw.group !== undefined && typeof raw.group !== \"string\" || raw.status !== undefined && (typeof raw.status !== \"string\" || ![\"active\", \"proposed\", \"private\"].includes(raw.status)) || raw.level !== undefined && (typeof raw.level !== \"number\" || !Number.isFinite(raw.level)) || raw.inventoryRef !== undefined && !isInventoryRef(raw.inventoryRef) || !Array.isArray(raw.tags) || !raw.tags.every((tag) => typeof tag === \"string\") || !arePorts(raw.inputs) || !arePorts(raw.outputs) || raw.views !== undefined && (!Array.isArray(raw.views) || !raw.views.every((view) => isNodeView(view)) || new Set(raw.views.map((view) => view.id)).size !== raw.views.length) || raw.child !== undefined && !validateGraphAt(raw.child, depth + 1)) {\n        return false;\n      }\n      nodeIds.add(raw.id);\n      nodeMap.set(raw.id, raw);\n    }\n    const edgeIds = new Set;\n    const connections = new Set;\n    for (const raw of edges) {\n      if (!isRecord2(raw) || typeof raw.id !== \"string\" || raw.id.length === 0 || edgeIds.has(raw.id) || typeof raw.source !== \"string\" || typeof raw.sourcePort !== \"string\" || typeof raw.target !== \"string\" || typeof raw.targetPort !== \"string\" || raw.label !== undefined && typeof raw.label !== \"string\" || raw.tags !== undefined && (!Array.isArray(raw.tags) || !raw.tags.every((tag) => typeof tag === \"string\"))) {\n        return false;\n      }\n      const edge = raw;\n      const source = nodeMap.get(edge.source);\n      const target = nodeMap.get(edge.target);\n      if (!source?.outputs.some((port) => port.id === edge.sourcePort) || !target?.inputs.some((port) => port.id === edge.targetPort)) {\n        return false;\n      }\n      const key = connectionKey(edge);\n      if (connections.has(key))\n        return false;\n      edgeIds.add(edge.id);\n      connections.add(key);\n    }\n    return true;\n  }\n  function cloneGraph(graph) {\n    return cloneJson(graph);\n  }\n\n  // slices/architecture-inventory/lib/document.ts\n  var MAX_DOCUMENT_INPUT_CHARS = 5000000;\n  var DOCUMENT_MARKDOWN_LANGUAGE = \"manef-diagram-json\";\n  function isRecord3(value) {\n    return typeof value === \"object\" && value !== null && !Array.isArray(value);\n  }\n  function stringList(value) {\n    return Array.isArray(value) && value.every((item) => typeof item === \"string\");\n  }\n  function isPoint(value) {\n    return isRecord3(value) && typeof value.x === \"number\" && Number.isFinite(value.x) && typeof value.y === \"number\" && Number.isFinite(value.y);\n  }\n  function isPositions(value) {\n    return isRecord3(value) && Object.values(value).every(isPoint);\n  }\n  function isUi(value) {\n    if (!isRecord3(value))\n      return false;\n    if (value.themePreset !== undefined && (typeof value.themePreset !== \"string\" || ![\"system\", \"composio-light\", \"composio-dark\"].includes(value.themePreset)))\n      return false;\n    if (value.diagramMode !== undefined && value.diagramMode !== \"flow\" && value.diagramMode !== \"graph\")\n      return false;\n    if (value.traceMode !== undefined && value.traceMode !== \"direct\" && value.traceMode !== \"component\")\n      return false;\n    if (value.flowDirection !== undefined && ![\"LR\", \"RL\", \"TB\", \"BT\"].includes(value.flowDirection))\n      return false;\n    if (value.focusMode !== undefined && typeof value.focusMode !== \"boolean\")\n      return false;\n    if (value.query !== undefined && typeof value.query !== \"string\")\n      return false;\n    for (const key of [\"tags\", \"seeds\", \"open\"]) {\n      if (value[key] !== undefined && !stringList(value[key]))\n        return false;\n    }\n    if (value.pan !== undefined && !isPoint(value.pan))\n      return false;\n    if (value.zoom !== undefined && (typeof value.zoom !== \"number\" || !Number.isFinite(value.zoom) || value.zoom <= 0))\n      return false;\n    if (value.positions !== undefined && !isPositions(value.positions))\n      return false;\n    if (value.layouts !== undefined && (!isRecord3(value.layouts) || !Object.values(value.layouts).every(isPositions)))\n      return false;\n    return true;\n  }\n  function isInventory(value) {\n    if (!Array.isArray(value))\n      return false;\n    const ids = new Set;\n    for (const item of value) {\n      if (!isRecord3(item) || typeof item.id !== \"string\" || item.id.length === 0 || ids.has(item.id) || typeof item.label !== \"string\" || !stringList(item.tags))\n        return false;\n      if (item.kind !== undefined && (typeof item.kind !== \"string\" || ![\"reference\", \"repo\", \"domain\", \"hostname\", \"convex\"].includes(item.kind)))\n        return false;\n      const node = {\n        ...item,\n        inputs: item.inputs === undefined ? [] : item.inputs,\n        outputs: item.outputs === undefined ? [] : item.outputs\n      };\n      if (!validateGraph({ schemaVersion: 1, nodes: [node], edges: [] }))\n        return false;\n      ids.add(item.id);\n    }\n    return true;\n  }\n  function validateDiagramDocument(value) {\n    return isJsonValue(value) && isRecord3(value) && value.format === \"manef-diagram\" && value.schemaVersion === 1 && typeof value.title === \"string\" && validateGraph(value.graph) && (value.ui === undefined || isUi(value.ui)) && (value.inventory === undefined || isInventory(value.inventory));\n  }\n  function requireDocument(value) {\n    if (!isJsonValue(value)) {\n      throw new Error(\"Document must use plain JSON values with finite numbers, safe integers, and no negative zero. Encode larger integers as strings.\");\n    }\n    if (!validateDiagramDocument(value)) {\n      throw new Error(\"Document does not match the MANEF diagram document contract (version 1, a valid graph, and JSON-safe fields are required).\");\n    }\n    boundedInput(fenced(JSON.stringify(value), DOCUMENT_MARKDOWN_LANGUAGE));\n  }\n  function boundedInput(text) {\n    if (text.length > MAX_DOCUMENT_INPUT_CHARS) {\n      throw new Error(\"Diagram document exceeds the 5,000,000 character limit.\");\n    }\n  }\n  function createDocument(graph, title = \"MANEF Architecture\") {\n    const document = {\n      format: \"manef-diagram\",\n      schemaVersion: 1,\n      title,\n      graph: cloneGraph(graph)\n    };\n    requireDocument(document);\n    return document;\n  }\n  function parseDiagramDocument(json) {\n    boundedInput(json);\n    const value = JSON.parse(json);\n    if (isRecord3(value) && \"format\" in value && value.format !== \"manef-diagram\") {\n      throw new Error(\"Unsupported diagram document format.\");\n    }\n    if (isRecord3(value) && ((\"format\" in value) || (\"graph\" in value))) {\n      if (value.format !== \"manef-diagram\" && ((\"nodes\" in value) || (\"edges\" in value))) {\n        throw new Error(\"Ambiguous diagram document: put graph nodes and edges inside graph.\");\n      }\n      if (value.schemaVersion !== undefined && value.schemaVersion !== 1) {\n        throw new Error(\"Unsupported diagram document version.\");\n      }\n      const document = {\n        ...value,\n        format: \"manef-diagram\",\n        schemaVersion: 1,\n        title: value.title === undefined ? \"MANEF Architecture\" : value.title\n      };\n      requireDocument(document);\n      return cloneJson(document);\n    }\n    if (!validateGraph(value)) {\n      throw new Error(\"JSON is not a MANEF diagram document or architecture graph.\");\n    }\n    return createDocument(value);\n  }\n  function documentAsJson(document) {\n    requireDocument(document);\n    const text = JSON.stringify(document, null, 2);\n    return text.length <= MAX_DOCUMENT_INPUT_CHARS ? text : JSON.stringify(document);\n  }\n  function fenced(source, language) {\n    let run = 0;\n    let length = 3;\n    for (let index = 0;index < source.length; index += 1) {\n      run = source.charCodeAt(index) === 96 ? run + 1 : 0;\n      length = Math.max(length, run + 1);\n    }\n    const marker = \"`\".repeat(length);\n    return marker + language + `\n` + source + (source.endsWith(`\n`) ? \"\" : `\n`) + marker;\n  }\n  function heading(text) {\n    return text.replace(/[\\r\\n]+/g, \" \").trim();\n  }\n  function documentAsMarkdown(document) {\n    const payload = documentAsJson(document);\n    const parts = [\n      \"# \" + heading(document.title),\n      \"The canonical JSON block preserves the complete document. The diagrams below are readable projections.\"\n    ];\n    let projectionBudget = 50000;\n    function graphSummary(graph, path) {\n      if (projectionBudget <= 0)\n        return;\n      const label = path.length ? path.join(\" / \") : \"Architecture\";\n      parts.push(\"## \" + heading(label));\n      const aliases = new Map(graph.nodes.map((node, index) => [node.id, \"n\" + index]));\n      const lines = [\"flowchart LR\"];\n      for (const node of graph.nodes) {\n        lines.push(\"  \" + aliases.get(node.id) + \"[\" + JSON.stringify(node.label) + \"]\");\n      }\n      for (const edge of graph.edges) {\n        lines.push(\"  \" + aliases.get(edge.source) + \" --> \" + aliases.get(edge.target));\n      }\n      const projection = fenced(lines.join(`\n`), \"mermaid\");\n      if (projection.length <= projectionBudget) {\n        parts.push(projection);\n        projectionBudget -= projection.length;\n      }\n      for (const node of graph.nodes) {\n        for (const view of node.views ?? []) {\n          parts.push(\"### \" + heading([...path, node.label, view.title].join(\" / \")));\n          try {\n            const source = fenced(mermaidSource(view), \"mermaid\");\n            if (source.length <= projectionBudget) {\n              parts.push(source);\n              projectionBudget -= source.length;\n            } else {\n              parts.push(\"This view is preserved in the canonical JSON block.\");\n            }\n          } catch {\n            parts.push(\"This authored view is preserved in the canonical JSON block.\");\n          }\n        }\n        if (node.child)\n          graphSummary(node.child, [...path, node.label]);\n      }\n    }\n    graphSummary(document.graph, []);\n    parts.push(\"## Canonical document\", fenced(payload, DOCUMENT_MARKDOWN_LANGUAGE));\n    const text = parts.join(`\n\n`) + `\n`;\n    if (text.length <= MAX_DOCUMENT_INPUT_CHARS)\n      return text;\n    return fenced(JSON.stringify(document), DOCUMENT_MARKDOWN_LANGUAGE);\n  }\n  function parseDiagramMarkdown(markdown) {\n    boundedInput(markdown);\n    const payloads = [];\n    let fence = null;\n    for (const line of markdown.split(/\\r?\\n/)) {\n      if (fence) {\n        const closing = new RegExp(\"^ {0,3}\" + fence.marker + \"{\" + fence.length + \",}[ \\\\t]*$\");\n        if (closing.test(line)) {\n          if (fence.canonical)\n            payloads.push(fence.lines.join(`\n`));\n          fence = null;\n        } else if (fence.canonical) {\n          fence.lines.push(line);\n        }\n        continue;\n      }\n      const opening = /^ {0,3}(\\x60{3,}|~{3,})(.*)$/.exec(line);\n      if (!opening)\n        continue;\n      if (opening[1][0] === String.fromCharCode(96) && opening[2].includes(String.fromCharCode(96)))\n        continue;\n      fence = {\n        marker: opening[1][0],\n        length: opening[1].length,\n        canonical: opening[2].trim() === DOCUMENT_MARKDOWN_LANGUAGE,\n        lines: []\n      };\n    }\n    if (fence?.canonical)\n      throw new Error(\"The canonical diagram JSON block is not closed.\");\n    if (payloads.length !== 1) {\n      throw new Error(\"Markdown must contain exactly one manef-diagram-json block. A plain Mermaid diagram cannot preserve the complete document.\");\n    }\n    return parseDiagramDocument(payloads[0]);\n  }\n\n  // examples/n8n/converter-entry.ts\n  var output = $input.all().map((item, index) => {\n    const payload = item.json;\n    if (typeof payload !== \"object\" || payload === null || Array.isArray(payload)) {\n      throw new Error(`Item ${index}: json must be an object with format, source, and target.`);\n    }\n    const { format, source, target } = payload;\n    if (format !== \"json\" && format !== \"md\") {\n      throw new Error(`Item ${index}: format must be json or md.`);\n    }\n    if (typeof source !== \"string\") {\n      throw new Error(`Item ${index}: source must be a string.`);\n    }\n    if (target !== \"json\" && target !== \"md\") {\n      throw new Error(`Item ${index}: target must be json or md.`);\n    }\n    try {\n      const document = format === \"json\" ? parseDiagramDocument(source) : parseDiagramMarkdown(source);\n      return {\n        json: {\n          document,\n          source: target === \"json\" ? documentAsJson(document) : documentAsMarkdown(document),\n          format: target\n        },\n        pairedItem: { item: index }\n      };\n    } catch (error) {\n      const detail = error instanceof Error ? error.message : \"Diagram conversion failed.\";\n      throw new Error(`Item ${index}: ${detail}`, { cause: error });\n    }\n  });\n  __manefSetResult(output);\n})();\nreturn __manefOutput;"
			}
		}
	],
	"connections": {
		"Manual Trigger": {
			"main": [[{ "node": "Synthetic example input", "type": "main", "index": 0 }]]
		},
		"Synthetic example input": {
			"main": [[{ "node": "MANEF document converter", "type": "main", "index": 0 }]]
		}
	},
	"settings": { "executionOrder": "v1" },
	"pinData": {}
}
