Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.
HTML agent-skillsai-agentsarchitecture-diagramclaude-codeclaude-skillscodexcoding-agentsdeepseek-harnessdeveloper-toolsdiagramsdiagrams-as-codedsh-pluginflowchartllmmermaidopencodesequence-diagramsoftware-architecturesystem-designvisualization
Merge remote-tracking branch 'origin/main' into fix/edge-label-variant-color
Beverly62184107d2710a1
diff --cc archify.zipindex ce4a91e1,8d7011a4..f19b95acBinary files differdiff --cc archify/examples/workflow-agent-tool-call-rendered.htmlindex 36d95fbd,0fb6bb9a..a4c89f72--- a/archify/examples/workflow-agent-tool-call-rendered.html+++ b/archify/examples/workflow-agent-tool-call-rendered.html@@@ -5036,56 -5030,52 +5036,52 @@@<rect width="100%" height="100%" fill="url(#grid)" /><!-- Swimlanes -->- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-0" x="40" y="52" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-0" x="40" y="52" width="1028" height="106" rx="10" class="c-lane" stroke-width="1"/><text x="54" y="74" class="t-dim" font-size="10" font-weight="600">01 / User Interface</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-1" x="40" y="176" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <text x="54" y="198" class="t-dim" font-size="10" font-weight="600">02 / Agent Runtime</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-1" x="40" y="178" width="1028" height="114" rx="10" class="c-lane" stroke-width="1"/>+ <text x="54" y="200" class="t-dim" font-size="10" font-weight="600">02 / Agent Runtime</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-2" x="40" y="300" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <text x="54" y="322" class="t-dim" font-size="10" font-weight="600">03 / Policy Boundary</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-2" x="40" y="312" width="1028" height="114" rx="10" class="c-lane" stroke-width="1"/>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="exception-lane" data-composition-frame-id="lane-2-exception" x="46" y="318" width="1016" height="102" rx="8" class="c-security-group" stroke-width="1"/>+ <text x="54" y="334" class="t-security" font-size="10" font-weight="600">EX / Policy & Recovery</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-3" x="40" y="424" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <rect data-graph-role="structural-frame" data-composition-frame-kind="exception-lane" data-composition-frame-id="lane-3-exception" x="46" y="430" width="628" height="92" rx="8" class="c-security-group" stroke-width="1"/>- <text x="54" y="446" class="t-security" font-size="10" font-weight="600">EX / Exception Handling</text>-- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-4" x="40" y="548" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <text x="54" y="570" class="t-dim" font-size="10" font-weight="600">05 / Tool Execution</text>-- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-5" x="40" y="672" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <text x="54" y="694" class="t-dim" font-size="10" font-weight="600">06 / Observability</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-3" x="40" y="446" width="1028" height="114" rx="10" class="c-lane" stroke-width="1"/>+ <text x="54" y="468" class="t-dim" font-size="10" font-weight="600">04 / Tool Execution & Evidence</text><!-- Phase headers -->- <line x1="42" y1="35" x2="266" y2="35" class="a-default" stroke-width="1.1"/>- <rect x="42" y="27" width="224" height="16" rx="4" class="c-mask"/>- <text x="154" y="39" class="t-edge-default" font-size="8" font-weight="600" text-anchor="middle">Intake</text>- <line x1="254" y1="35" x2="476" y2="35" class="a-emphasis" stroke-width="1.1"/>- <rect x="254" y="27" width="222" height="16" rx="4" class="c-mask"/>- <text x="365" y="39" class="t-edge-emphasis" font-size="8" font-weight="600" text-anchor="middle">Plan + route</text>- <line x1="454" y1="35" x2="671" y2="35" class="a-dashed" stroke-width="1.1"/>- <rect x="454" y="27" width="217" height="16" rx="4" class="c-mask"/>- <text x="562.5" y="39" class="t-edge-dashed" font-size="8" font-weight="600" text-anchor="middle">Execute + report</text>+ <line x1="68" y1="35" x2="320" y2="35" class="a-default" stroke-width="1.1"/>+ <rect x="68" y="27" width="252" height="16" rx="4" class="c-mask"/>- <text x="194" y="39" class="t-muted" font-size="8" font-weight="600" text-anchor="middle">Intake</text>++ <text x="194" y="39" class="t-edge-default" font-size="8" font-weight="600" text-anchor="middle">Intake</text>+ <line x1="445.20000000000005" y1="35" x2="697.2" y2="35" class="a-emphasis" stroke-width="1.1"/>+ <rect x="445.20000000000005" y="27" width="252.00000000000006" height="16" rx="4" class="c-mask"/>- <text x="571.2" y="39" class="t-backend" font-size="8" font-weight="600" text-anchor="middle">Plan + route</text>++ <text x="571.2" y="39" class="t-edge-emphasis" font-size="8" font-weight="600" text-anchor="middle">Plan + route</text>+ <line x1="784" y1="35" x2="1036" y2="35" class="a-dashed" stroke-width="1.1"/>+ <rect x="784" y="27" width="252" height="16" rx="4" class="c-mask"/>- <text x="910" y="39" class="t-messagebus" font-size="8" font-weight="600" text-anchor="middle">Execute + report</text>++ <text x="910" y="39" class="t-edge-dashed" font-size="8" font-weight="600" text-anchor="middle">Execute + report</text><!-- Workflow groups -->- <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-0" x="250" y="214" width="230" height="58" rx="9" class="c-lane" stroke-width="1"/>- <text x="260" y="228" class="t-edge-emphasis" font-size="7" font-weight="600">Planning loop</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-1" x="450" y="586" width="225" height="58" rx="9" class="c-lane" stroke-width="1"/>- <text x="460" y="600" class="t-edge-dashed" font-size="7" font-weight="600">Tool work</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-2" x="380" y="462" width="295" height="58" rx="9" class="c-security-group" stroke-width="1"/>- <text x="390" y="476" class="t-edge-security" font-size="7" font-weight="600">Human or policy stop</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-0" x="421.2" y="216" width="300.00000000000006" height="72" rx="9" class="c-lane" stroke-width="1"/>- <text x="431.2" y="214" class="t-backend" font-size="7" font-weight="600">Planning loop</text>++ <text x="431.2" y="214" class="t-edge-emphasis" font-size="7" font-weight="600">Planning loop</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-1" x="581.2" y="350" width="478.79999999999995" height="72" rx="9" class="c-security-group" stroke-width="1"/>- <text x="591.2" y="348" class="t-security" font-size="7" font-weight="600">Human or policy stop</text>++ <text x="591.2" y="348" class="t-edge-security" font-size="7" font-weight="600">Human or policy stop</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-2" x="204" y="484" width="357.20000000000005" height="72" rx="9" class="c-lane" stroke-width="1"/>- <text x="214" y="482" class="t-messagebus" font-size="7" font-weight="600">Evidence path</text>++ <text x="214" y="482" class="t-edge-dashed" font-size="7" font-weight="600">Evidence path</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-3" x="760" y="484" width="300" height="72" rx="9" class="c-lane" stroke-width="1"/>- <text x="770" y="482" class="t-messagebus" font-size="7" font-weight="600">Tool work</text>++ <text x="770" y="482" class="t-edge-dashed" font-size="7" font-weight="600">Tool work</text><!-- Edge paths -->- <path data-edge-from="user" data-edge-to="chat" data-edge-key="0" data-edge-id="request-chat" data-composition-points="134,119;174,119" d="M 134 119 L 174 119" class="a-default" data-animate="edge" style="--step:0" stroke-width="1.4" marker-end="url(#arrowhead)"/>- <path data-edge-from="chat" data-edge-to="planner" data-edge-label="plan" data-edge-key="1" data-edge-id="plan-request" data-composition-points="220,145;220,166;300,166;300,209" d="M 220 145 L 220 166 L 300 166 L 300 209" class="a-emphasis" data-animate="edge" style="--step:1" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>- <path data-edge-from="planner" data-edge-to="router" data-edge-key="2" data-edge-id="planner-route" data-composition-points="346,243;384,243" d="M 346 243 L 384 243" class="a-default" data-animate="edge" style="--step:2" stroke-width="1.4" marker-end="url(#arrowhead)"/>- <path data-edge-from="router" data-edge-to="approval" data-edge-label="needs approval?" data-edge-key="3" data-edge-id="approval-check" data-composition-points="430,269;430,290;430,290;430,333" d="M 430 269 L 430 290 L 430 290 L 430 333" class="a-security" data-animate="edge" style="--step:3" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>- <path data-edge-from="approval" data-edge-to="tool" data-edge-key="4" data-edge-id="approved-tool" data-composition-points="384,367;356,367;356,615;454,615" d="M 384 367 L 356 367 L 356 615 L 454 615" class="a-emphasis" data-animate="edge" style="--step:4" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>- <path data-edge-from="approval" data-edge-to="blocked" data-edge-label="denied" data-edge-key="5" data-edge-id="approval-denied" data-composition-points="430,401;430,414;500,414;500,465" d="M 430 401 L 430 414 L 500 414 L 500 465" class="a-security" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>- <path data-edge-from="blocked" data-edge-to="retry" data-edge-key="6" data-edge-id="retry-request" data-composition-points="546,491;579,491" d="M 546 491 L 579 491" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>- <path data-edge-from="tool" data-edge-to="external" data-edge-key="7" data-edge-id="tool-external-call" data-composition-points="546,615;579,615" d="M 546 615 L 579 615" class="a-default" data-animate="edge" style="--step:5" stroke-width="1.4" marker-end="url(#arrowhead)"/>- <path data-edge-from="external" data-edge-to="final" data-edge-key="8" data-edge-id="external-reply" data-composition-points="671,615;692,615;692,119;671,119" d="M 671 615 L 692 615 L 692 119 L 671 119" class="a-emphasis" data-animate="edge" style="--step:6" stroke-width="1.2" marker-end="url(#arrowhead-emphasis)"/>- <path data-edge-from="external" data-edge-to="trace" data-edge-label="record result" data-edge-key="9" data-edge-id="record-result" data-composition-points="625,641;625,797;500,797;500,765" d="M 625 641 L 625 797 L 500 797 L 500 765" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>- <path data-edge-from="store" data-edge-to="trace" data-edge-label="trace + memory" data-edge-key="10" data-edge-id="write-trace-memory" data-composition-points="266,739;454,739" d="M 266 739 L 454 739" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>+ <path data-edge-from="router" data-edge-to="approval" data-edge-label="needs approval?" data-edge-key="0" data-edge-id="approval-check" data-composition-points="651.2,279;651.2,302;569.2,302;569.2,387;585.2,387" d="M 651.2 279 L 651.2 302 L 569.2 302 L 569.2 387 L 585.2 387" class="a-security" data-animate="edge" style="--step:3" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>+ <path data-edge-from="approval" data-edge-to="blocked" data-edge-label="denied" data-edge-key="1" data-edge-id="approval-denied" data-composition-points="651.2,421;651.2,442;830,442;830,413" d="M 651.2 421 L 651.2 442 L 830 442 L 830 413" class="a-security" data-animate="edge" style="--step:9" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>+ <path data-edge-from="approval" data-edge-to="tool" data-edge-key="2" data-edge-id="approved-tool" data-composition-points="651.2,421;651.2,521;764,521" d="M 651.2 421 L 651.2 521 L 764 521" class="a-emphasis" data-animate="edge" style="--step:4" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>+ <path data-edge-from="external" data-edge-to="final" data-edge-key="3" data-edge-id="external-reply" data-composition-points="1056,521;1080,521;1080,120;1056,120" d="M 1056 521 L 1080 521 L 1080 120 L 1056 120" class="a-emphasis" data-animate="edge" style="--step:6" stroke-width="1.2" marker-end="url(#arrowhead-emphasis)"/>+ <path data-edge-from="chat" data-edge-to="planner" data-edge-label="plan" data-edge-key="4" data-edge-id="plan-request" data-composition-points="274,146;274,253;425.2,253" d="M 274 146 L 274 253 L 425.2 253" class="a-emphasis" data-animate="edge" style="--step:1" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>+ <path data-edge-from="planner" data-edge-to="router" data-edge-key="5" data-edge-id="planner-route" data-composition-points="557.2,253;585.2,253" d="M 557.2 253 L 585.2 253" class="a-default" data-animate="edge" style="--step:2" stroke-width="1.4" marker-end="url(#arrowhead)"/>+ <path data-edge-from="external" data-edge-to="trace" data-edge-label="record result" data-edge-key="6" data-edge-id="record-result" data-composition-points="990,547;990,579;491.2,579;491.2,547" d="M 990 547 L 990 579 L 491.2 579 L 491.2 547" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>+ <path data-edge-from="user" data-edge-to="chat" data-edge-key="7" data-edge-id="request-chat" data-composition-points="180,120;208,120" d="M 180 120 L 208 120" class="a-default" data-animate="edge" style="--step:0" stroke-width="1.4" marker-end="url(#arrowhead)"/>+ <path data-edge-from="blocked" data-edge-to="retry" data-edge-key="8" data-edge-id="retry-request" data-composition-points="896,387;924,387" d="M 896 387 L 924 387" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>+ <path data-edge-from="tool" data-edge-to="external" data-edge-key="9" data-edge-id="tool-external-call" data-composition-points="896,521;924,521" d="M 896 521 L 924 521" class="a-default" data-animate="edge" style="--step:5" stroke-width="1.4" marker-end="url(#arrowhead)"/>+ <path data-edge-from="store" data-edge-to="trace" data-edge-label="trace + memory" data-edge-key="10" data-edge-id="write-trace-memory" data-composition-points="340,521;425.2,521" d="M 340 521 L 425.2 521" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/><!-- Nodes --><g id="node-user" data-node-id="user" data-node-label="User" tabindex="0" role="button" aria-label="Focus User, asks for work, User Interface › Intake" aria-pressed="false" data-node-kind="external" data-node-sublabel="asks for work" data-node-context="User Interface › Intake">@@@ -5238,31 -5228,31 +5234,31 @@@</g><!-- Edge labels -->-- <g data-detail="context" data-edge-from="chat" data-edge-to="planner" data-edge-label="plan" data-edge-key="1" data-edge-id="plan-request">- <rect x="245" y="146" width="30" height="14" rx="3" class="c-mask"/>- <text x="260" y="156" class="t-edge-emphasis" font-size="8" text-anchor="middle">plan</text>+ <g data-detail="context" data-edge-from="router" data-edge-to="approval" data-edge-label="needs approval?" data-edge-key="0" data-edge-id="approval-check">+ <rect x="569.2" y="282" width="82" height="14" rx="3" class="c-mask"/>- <text x="610.2" y="292" class="t-security" font-size="8" text-anchor="middle">needs approval?</text>++ <text x="610.2" y="292" class="t-edge-security" font-size="8" text-anchor="middle">needs approval?</text>+ </g>+ <g data-detail="context" data-edge-from="approval" data-edge-to="blocked" data-edge-label="denied" data-edge-key="1" data-edge-id="approval-denied">+ <rect x="721.2" y="422" width="38.8" height="14" rx="3" class="c-mask"/>- <text x="740.6" y="432" class="t-security" font-size="8" text-anchor="middle">denied</text>++ <text x="740.6" y="432" class="t-edge-security" font-size="8" text-anchor="middle">denied</text></g>- <g data-detail="context" data-edge-from="router" data-edge-to="approval" data-edge-label="needs approval?" data-edge-key="3" data-edge-id="approval-check">- <rect x="423" y="277.5" width="82" height="14" rx="3" class="c-mask"/>- <text x="464" y="287.5" class="t-edge-security" font-size="8" text-anchor="middle">needs approval?</text>++ <g data-detail="context" data-edge-from="chat" data-edge-to="planner" data-edge-label="plan" data-edge-key="4" data-edge-id="plan-request">+ <rect x="334.6" y="233" width="30" height="14" rx="3" class="c-mask"/>- <text x="349.6" y="243" class="t-backend" font-size="8" text-anchor="middle">plan</text>++ <text x="349.6" y="243" class="t-edge-emphasis" font-size="8" text-anchor="middle">plan</text></g>- <g data-detail="context" data-edge-from="approval" data-edge-to="blocked" data-edge-label="denied" data-edge-key="5" data-edge-id="approval-denied">- <rect x="445.6" y="406" width="38.8" height="14" rx="3" class="c-mask"/>- <text x="465" y="416" class="t-edge-security" font-size="8" text-anchor="middle">denied</text>+ <g data-detail="context" data-edge-from="external" data-edge-to="trace" data-edge-label="record result" data-edge-key="6" data-edge-id="record-result">+ <rect x="704.4" y="559" width="72.4" height="14" rx="3" class="c-mask"/>- <text x="740.6" y="569" class="t-database" font-size="8" text-anchor="middle">record result</text>++ <text x="740.6" y="569" class="t-edge-dashed" font-size="8" text-anchor="middle">record result</text></g>- <g data-detail="context" data-edge-from="external" data-edge-to="trace" data-edge-label="record result" data-edge-key="9" data-edge-id="record-result">- <rect x="526.3" y="777" width="72.4" height="14" rx="3" class="c-mask"/>- <text x="562.5" y="787" class="t-edge-dashed" font-size="8" text-anchor="middle">record result</text>- </g><g data-detail="context" data-edge-from="store" data-edge-to="trace" data-edge-label="trace + memory" data-edge-key="10" data-edge-id="write-trace-memory">- <rect x="326.4" y="725" width="77.2" height="14" rx="3" class="c-mask"/>- <text x="365" y="735" class="t-edge-dashed" font-size="8" text-anchor="middle">trace + memory</text>+ <rect x="344" y="501" width="77.2" height="14" rx="3" class="c-mask"/>- <text x="382.6" y="511" class="t-database" font-size="8" text-anchor="middle">trace + memory</text>++ <text x="382.6" y="511" class="t-edge-dashed" font-size="8" text-anchor="middle">trace + memory</text></g><!-- Legend -->diff --cc archify/renderers/workflow/workflow-compiler.mjsindex 00000000,81ba79a1..37d2fb6bmode 000000,100644..100644--- a/archify/renderers/workflow/workflow-compiler.mjs+++ b/archify/renderers/workflow/workflow-compiler.mjs@@@ -1,0 -1,4400 +1,4400 @@@+ import { esc, renderDefinitions, renderSemanticSigil, textUnits } from '../shared/utils.mjs';+ import { animateAttr, focusEdgeAttrs, focusNodeAttrs, focusNodeTitle, svgAccessibleText, svgRootAttrs } from '../shared/cli.mjs';+ import {+ throwDiagnosticError,+ throwDiagnosticProblems,+ withDiagnosticRecordingSuppressed,+ } from '../shared/diagnostics.mjs';+ import { validateSchema } from '../shared/validator.mjs';+ import {+ legendFootprint,+ measureLegend,+ relationshipLegendObstacles,+ resolveLegend,+ renderLegend as renderResolvedLegend,+ } from '../shared/legend.mjs';+ import { availableNodeTextWidth, fittedNodeFontSize, minimumNodeTextWidth } from '../shared/text-fit.mjs';+ import { brandLabelFitWidth, brandMetadataFor, brandTopRailProblem, renderBrandMark } from '../shared/brand-marks.mjs';+ import { translateMessage as i18nText } from '../shared/i18n.mjs';+ import {+ createMappedWorkflowCandidate,+ intrinsicWorkflow,+ planningWorkflow,+ } from './workflow-migration-geometry.mjs';+ import {+ asArray,+ isFinitePoint,+ rectsOverlap,+ segmentIntersectsRect,+ segmentRectClearance,+ cleanEndpointSideProblems,+ cleanFlowProblems,+ cleanCrossingProblems,+ cleanAmbiguousCorridorProblems,+ cleanBorderRunProblems,+ cleanRouteRhythmProblems,+ cleanLabelRouteClearanceProblems,+ collectAmbiguousCorridors,+ collectLabelRouteClearance,+ collectBorderRuns,+ forwardCollinearAnalysisSegments,+ sourceSegmentIndexAtPoint,+ suggestLabelObstacleFix,+ suggestLabelPairFix,+ anchor,+ automaticPortSpread,+ defaultFromSide,+ defaultToSide,+ chosenSide,+ normalizeRoutePoints,+ routeHonorsEndpointSides,+ polylinePath,+ routePointsValue,+ labelPoint,+ componentFill,+ componentText,+ arrowClassMap,+ variantAccent+ } from '../shared/geometry.mjs';++ const LEGACY_COLUMN_CENTERS = Object.freeze([88, 220, 300, 430, 500, 625]);+ const READABLE_CANDIDATE_COST_PRIORITY = Object.freeze([+ 'automaticForwardReversePx',+ 'properCrossingCount',+ 'sharedCorridorPx',+ 'labelRouteClearanceDeficit',+ 'interiorPreferred28Deficit',+ 'bendCount',+ 'stretchMilli',+ 'canvasGrowthPx',+ 'portDisplacementMilli',+ 'legacyCoordinateDisplacement',+ 'stableCandidateOrdinal',+ ]);+ const MAX_READABLE_LAYOUT_FEEDBACK_ROUNDS = 3;+ const GROUP_FRAME_TOP_INSET = 8;+ const GROUP_FRAME_BOTTOM_INSET = 4;+ const GROUP_LABEL_BASELINE_OFFSET = -2;+ const GROUP_LABEL_MASK_ASCENT = 10;+ const GROUP_LABEL_MASK_H = 14;+ const GROUP_NODE_INSET = 4;++ class WorkflowLayoutFeedback extends Error {+ constructor(request) {+ super(`Workflow layout requires ${request.kind} feedback.`);+ this.name = 'WorkflowLayoutFeedback';+ this.request = request;+ }+ }++ function createLegacyLayout() {+ return {+ contract: 'fixed-v1',+ laneX: 40,+ laneY: 52,+ laneW: 640,+ laneH: 104,+ laneGap: 20,+ laneTitleH: 30,+ colXs: [...LEGACY_COLUMN_CENTERS],+ nodeW: 92,+ nodeH: 52,+ defaultViewBoxWidth: 720,+ };+ }++ function authoredNodeWidth(node) {+ return Number.isFinite(node?.width) ? node.width : 92;+ }++ function nodeWidthContributor(node) {+ return `node ${node.id} width ${authoredNodeWidth(node)}px`;+ }++ function authoredNodeHeight(node) {+ if (Number.isFinite(node?.height)) return node.height;+ return node?.tag ? 68 : 52;+ }++ function workflowLabelWidth(label) {+ return Math.max(30, textUnits(label) * 4.8 + 10);+ }++ function readableGroupBounds(workflow, group, colXs) {+ if (!Number.isInteger(group.fromCol) || !Number.isInteger(group.toCol)+ || group.fromCol < 0 || group.fromCol > group.toCol || group.toCol >= colXs.length) {+ return { x: 0, width: 0, cx: 0 };+ }+ const start = colXs[group.fromCol] - 50;+ const end = colXs[group.toCol] + 50;+ const naturalWidth = end - start;+ const minimumWidth = textUnits(group.label) * 5.6 + 20;+ let width = Math.max(naturalWidth, minimumWidth);+ let left = group.fromCol === group.toCol && width > naturalWidth+ ? start+ : (start + end - width) / 2;+ let right = left + width;+ for (const node of asArray(workflow.nodes)) {+ if (node.lane !== group.lane+ || !Number.isInteger(node.col)+ || node.col < group.fromCol+ || node.col > group.toCol+ || node.col < 0+ || node.col >= colXs.length) continue;+ const halfWidth = authoredNodeWidth(node) / 2;+ left = Math.min(left, colXs[node.col] - halfWidth - GROUP_NODE_INSET);+ right = Math.max(right, colXs[node.col] + halfWidth + GROUP_NODE_INSET);+ }+ width = right - left;+ return { x: left, width, cx: left + width / 2 };+ }++ function verticalIntervalsOverlap(a, b, clearance = 0) {+ const aCenter = Number(a?.yOffset) || 0;+ const bCenter = Number(b?.yOffset) || 0;+ return Math.abs(aCenter - bCenter)+ < authoredNodeHeight(a) / 2 + authoredNodeHeight(b) / 2 + clearance;+ }++ function createReadableLayout(workflow, layoutFeedback = {}) {+ const columnCount = 6;+ const baselinePitch = 120;+ const columnStart = 94;+ const maxLayoutIterations = 3;+ const channelDetourBudgetPx = 4 * 28;+ const constraints = [];+ const feedbackConstraints = [];+ const channelLabelEdgeKeys = new Set();+ const widthContributors = new Set();+ const heightContributors = new Set();+ const nodes = asArray(workflow.nodes);+ const nodesById = new Map(nodes.map((node) => [node.id, node]));++ for (let col = 0; col < columnCount - 1; col += 1) {+ constraints.push({ from: col, to: col + 1, minimum: baselinePitch });+ }+ for (const [key, minimum] of Object.entries(layoutFeedback.rankGapMinimums || {}).sort()) {+ const [from, to] = key.split(':').map(Number);+ constraints.push({+ from,+ to,+ minimum,+ contributors: layoutFeedback.rankGapContributors?.[key]+ || [`rank ${from}→${to} route clearance`],+ });+ }++ for (let leftIndex = 0; leftIndex < nodes.length; leftIndex += 1) {+ for (let rightIndex = leftIndex + 1; rightIndex < nodes.length; rightIndex += 1) {+ const leftNode = nodes[leftIndex];+ const rightNode = nodes[rightIndex];+ if (leftNode.lane !== rightNode.lane || leftNode.col === rightNode.col) continue;+ if (!verticalIntervalsOverlap(leftNode, rightNode, 8)) continue;+ const fromNode = leftNode.col < rightNode.col ? leftNode : rightNode;+ const toNode = fromNode === leftNode ? rightNode : leftNode;+ constraints.push({+ from: fromNode.col,+ to: toNode.col,+ minimum: authoredNodeWidth(fromNode) / 2 + 8 + authoredNodeWidth(toNode) / 2,+ contributors: [+ `rank ${fromNode.col}→${toNode.col} node width clearance`,+ nodeWidthContributor(fromNode),+ nodeWidthContributor(toNode),+ ],+ });+ }+ }++ for (const edge of asArray(workflow.edges)) {+ const fromNode = nodesById.get(edge.from);+ const toNode = nodesById.get(edge.to);+ if (!fromNode || !toNode || fromNode.lane !== toNode.lane || fromNode.col === toNode.col) continue;+ if (edge.via || edge.channelX !== undefined || edge.channelY !== undefined+ || !['auto', 'straight'].includes(edge.route || 'auto')) continue;+ if ((Number(fromNode.yOffset) || 0) !== (Number(toNode.yOffset) || 0)) continue;+ const earlier = fromNode.col < toNode.col ? fromNode : toNode;+ const later = earlier === fromNode ? toNode : fromNode;+ const labeledDirectClearance = edge.label && !edge.labelAt+ ? Math.max(28, workflowLabelWidth(edge.label) + 8)+ : 28;+ const directLabelExpansionCost = Math.max(0, labeledDirectClearance - 28);+ const canUseAutomaticLabelChannel = edge.label+ && !edge.labelAt+ && (edge.route || 'auto') === 'auto'+ && !edge.fromSide+ && !edge.toSide+ && edge.channelX === undefined+ && edge.channelY === undefined;+ const preferLabelChannel = canUseAutomaticLabelChannel+ && directLabelExpansionCost > channelDetourBudgetPx;+ if (preferLabelChannel) channelLabelEdgeKeys.add(stableValueKey(edge));+ constraints.push({+ from: earlier.col,+ to: later.col,+ minimum: authoredNodeWidth(earlier) / 2 + 28 + authoredNodeWidth(later) / 2,+ contributors: [+ `rank ${earlier.col}→${later.col} direct clearance`,+ `rank ${earlier.col}→${later.col} node width clearance`,+ nodeWidthContributor(earlier),+ nodeWidthContributor(later),+ ],+ });+ if (!preferLabelChannel && labeledDirectClearance > 28) {+ const labelConstraintMinimum = authoredNodeWidth(earlier) / 2+ + labeledDirectClearance+ + authoredNodeWidth(later) / 2;+ feedbackConstraints.push({+ from: earlier.col,+ to: later.col,+ minimum: labelConstraintMinimum,+ contributors: [+ `rank ${earlier.col}→${later.col} direct clearance`,+ `edge ${workflowEdgeName(edge)} label mask`,+ nodeWidthContributor(earlier),+ nodeWidthContributor(later),+ ],+ });+ }+ }++ for (const phase of asArray(workflow.phases)) {+ if (!Number.isInteger(phase.fromCol) || !Number.isInteger(phase.toCol)+ || phase.fromCol < 0 || phase.fromCol > phase.toCol || phase.toCol >= columnCount) continue;+ const minimumWidth = textUnits(phase.label) * 5.6 + 8;+ if (phase.fromCol === phase.toCol) {+ if (phase.toCol < columnCount - 1) {+ constraints.push({+ from: phase.toCol,+ to: phase.toCol + 1,+ minimum: baselinePitch + Math.max(0, minimumWidth - 92),+ contributors: [`phase ${phase.id || phase.label} label span`],+ });+ }+ continue;+ }+ constraints.push({+ from: phase.fromCol,+ to: phase.toCol,+ minimum: Math.max(0, minimumWidth - 92),+ contributors: [`phase ${phase.id || phase.label} label span`],+ });+ }++ for (const group of asArray(workflow.groups)) {+ if (!Number.isInteger(group.fromCol) || !Number.isInteger(group.toCol)+ || group.fromCol < 0 || group.fromCol > group.toCol || group.toCol >= columnCount) continue;+ const minimumWidth = textUnits(group.label) * 5.6 + 20;+ if (group.fromCol === group.toCol) {+ if (group.toCol < columnCount - 1) {+ constraints.push({+ from: group.toCol,+ to: group.toCol + 1,+ minimum: baselinePitch + Math.max(0, minimumWidth - 100),+ contributors: [`group ${group.id || group.label} label span`],+ });+ }+ continue;+ }+ constraints.push({+ from: group.fromCol,+ to: group.toCol,+ minimum: Math.max(0, minimumWidth - 100),+ contributors: [`group ${group.id || group.label} label span`],+ });+ }++ let activeConstraints = [...constraints];+ let colXs;+ let colProvenance;+ for (let iteration = 0; iteration < maxLayoutIterations; iteration += 1) {+ colXs = Array.from({ length: columnCount }, (_, col) => columnStart + col * baselinePitch);+ colProvenance = Array.from({ length: columnCount }, () => new Set());+ const orderedConstraints = activeConstraints+ .filter(({ from, to, minimum }) => (+ Number.isInteger(from) && Number.isInteger(to)+ && from >= 0 && from < to && to < columnCount+ && Number.isFinite(minimum)+ ))+ .sort((a, b) => a.to - b.to || a.from - b.from || a.minimum - b.minimum);+ for (let to = 1; to < columnCount; to += 1) {+ for (const constraint of orderedConstraints) {+ if (constraint.to !== to) continue;+ const candidate = colXs[constraint.from] + constraint.minimum;+ const candidateProvenance = new Set([+ ...colProvenance[constraint.from],+ ...asArray(constraint.contributors),+ ]);+ if (candidate > colXs[to] + 0.0001) {+ colXs[to] = candidate;+ colProvenance[to] = candidateProvenance;+ } else if (Math.abs(candidate - colXs[to]) <= 0.0001+ && candidate > columnStart + to * baselinePitch + 0.0001) {+ for (const contributor of candidateProvenance) colProvenance[to].add(contributor);+ }+ }+ }+ if (iteration > 0 || !feedbackConstraints.length) break;+ activeConstraints = [...activeConstraints, ...feedbackConstraints];+ }++ const firstRankNodes = nodes.filter((node) => node.col === 0);+ const firstExtent = firstRankNodes.reduce(+ (maximum, node) => Math.max(maximum, authoredNodeWidth(node) / 2),+ 46,+ );+ const leftInset = 8;+ const leftShift = Math.max(0, 40 + leftInset + firstExtent - colXs[0]);+ if (leftShift) {+ for (let col = 0; col < colXs.length; col += 1) colXs[col] += leftShift;+ for (const node of firstRankNodes) {+ if (Math.abs(authoredNodeWidth(node) / 2 - firstExtent) > 0.0001) continue;+ for (const provenance of colProvenance) provenance.add(nodeWidthContributor(node));+ }+ }++ const unpinnedTopEndpointIds = new Set();+ for (const edge of asArray(workflow.edges)) {+ const preservesHorizontalPins = Array.isArray(edge.via) || edge.channelX !== undefined;+ if (preservesHorizontalPins) continue;+ if (edge.fromSide === 'top') unpinnedTopEndpointIds.add(edge.from);+ if (edge.toSide === 'top') unpinnedTopEndpointIds.add(edge.to);+ }+ const laneOrder = new Map(asArray(workflow.lanes).map((lane, index) => [lane.id, index]));+ let laneHeaderShift = 0;+ const laneHeaderShiftContributors = new Set();+ for (const nodeId of unpinnedTopEndpointIds) {+ const node = nodesById.get(nodeId);+ if (!node || !Number.isInteger(node.col) || node.col < 0 || node.col >= columnCount) continue;+ const lanePosition = laneOrder.get(node.lane);+ const lane = asArray(workflow.lanes)[lanePosition];+ if (!lane) continue;+ const prefix = lane.variant === 'exception'+ ? 'EX'+ : String(lanePosition + 1).padStart(2, '0');+ const laneHeaderRight = 40 + 14 + textUnits(`${prefix} / ${lane.label}`) * 6.2;+ const requiredShift = laneHeaderRight + 2 - colXs[node.col];+ if (requiredShift > laneHeaderShift + 0.0001) {+ laneHeaderShift = requiredShift;+ laneHeaderShiftContributors.clear();+ laneHeaderShiftContributors.add(`lane ${lane.id} label width`);+ } else if (requiredShift > 0 && Math.abs(requiredShift - laneHeaderShift) <= 0.0001) {+ laneHeaderShiftContributors.add(`lane ${lane.id} label width`);+ }+ }+ if (laneHeaderShift > 0) {+ for (let col = 0; col < colXs.length; col += 1) colXs[col] += laneHeaderShift;+ for (const provenance of colProvenance) {+ for (const contributor of laneHeaderShiftContributors) provenance.add(contributor);+ }+ }++ let measuredContentLeftShift = asArray(workflow.edges).reduce((maximum, edge) => {+ if (!channelLabelEdgeKeys.has(stableValueKey(edge))) return maximum;+ const fromNode = nodesById.get(edge.from);+ const toNode = nodesById.get(edge.to);+ if (!fromNode || !toNode) return maximum;+ const labelCenter = (colXs[fromNode.col] + colXs[toNode.col]) / 2;+ const labelLeft = labelCenter - workflowLabelWidth(edge.label) / 2;+ return Math.max(maximum, 16 - labelLeft);+ }, 0);+ for (const phase of asArray(workflow.phases)) {+ if (!Number.isInteger(phase.fromCol) || !Number.isInteger(phase.toCol)) continue;+ const width = Math.max(+ colXs[phase.toCol] - colXs[phase.fromCol] + 92,+ textUnits(phase.label) * 5.6 + 8,+ );+ const left = phase.fromCol === phase.toCol+ ? colXs[phase.fromCol] - 46+ : (colXs[phase.fromCol] + colXs[phase.toCol] - width) / 2;+ measuredContentLeftShift = Math.max(measuredContentLeftShift, 16 - left);+ }+ for (const group of asArray(workflow.groups)) {+ if (!Number.isInteger(group.fromCol) || !Number.isInteger(group.toCol)) continue;+ const bounds = readableGroupBounds(workflow, group, colXs);+ measuredContentLeftShift = Math.max(measuredContentLeftShift, 44 - bounds.x);+ }+ if (measuredContentLeftShift > 0) {+ for (let col = 0; col < colXs.length; col += 1) colXs[col] += measuredContentLeftShift;+ }++ let rightmost = colXs.at(-1) + 50;+ let rightmostContributors = new Set(colProvenance.at(-1));+ for (const node of nodes) {+ if (!Number.isInteger(node.col) || node.col < 0 || node.col >= columnCount) continue;+ const nodeRight = colXs[node.col] + authoredNodeWidth(node) / 2;+ const nodeContributors = new Set([+ ...colProvenance[node.col],+ nodeWidthContributor(node),+ ]);+ if (nodeRight > rightmost + 0.0001) {+ rightmost = nodeRight;+ rightmostContributors = nodeContributors;+ } else if (Math.abs(nodeRight - rightmost) <= 0.0001) {+ for (const contributor of nodeContributors) rightmostContributors.add(contributor);+ }+ }+ for (const group of asArray(workflow.groups)) {+ if (!Number.isInteger(group.fromCol) || !Number.isInteger(group.toCol)) continue;+ const bounds = readableGroupBounds(workflow, group, colXs);+ const groupRight = bounds.x + bounds.width;+ const groupContributors = new Set([+ ...colProvenance[group.fromCol],+ ...colProvenance[group.toCol],+ `group ${group.id || group.label} label span`,+ ...nodes+ .filter((node) => node.lane === group.lane+ && node.col >= group.fromCol && node.col <= group.toCol)+ .map(nodeWidthContributor),+ ]);+ if (groupRight > rightmost + 0.0001) {+ rightmost = groupRight;+ rightmostContributors = groupContributors;+ } else if (Math.abs(groupRight - rightmost) <= 0.0001) {+ for (const contributor of groupContributors) rightmostContributors.add(contributor);+ }+ }+ const widestLaneLabel = asArray(workflow.lanes).reduce((widest, lane, index) => {+ const width = textUnits(`${String(index + 1).padStart(2, '0')} / ${lane.label}`) * 6.2 + 30;+ return width > widest.width ? { width, lane } : widest;+ }, { width: 0, lane: null });+ const laneLabelWidth = widestLaneLabel.width;+ const rightmostLaneWidth = Math.ceil(rightmost - 40 + 8);+ const laneW = Math.max(+ 640,+ rightmostLaneWidth,+ Math.ceil(laneLabelWidth),+ );+ if (laneW > 640) {+ if (rightmostLaneWidth === laneW) {+ for (const contributor of rightmostContributors) widthContributors.add(contributor);+ }+ if (Math.ceil(laneLabelWidth) === laneW && widestLaneLabel.lane) {+ widthContributors.add(`lane ${widestLaneLabel.lane.id || widestLaneLabel.lane.label} label width`);+ }+ }+ let maxVerticalExtent = 0;+ const verticalExtentContributors = new Set();+ for (const node of nodes) {+ const yOffset = Number(node.yOffset) || 0;+ const extent = authoredNodeHeight(node) / 2 + Math.abs(yOffset);+ const contributor = `node ${node.id} height ${authoredNodeHeight(node)}px${yOffset ? ` with yOffset ${yOffset}px` : ''}`;+ if (extent > maxVerticalExtent + 0.0001) {+ maxVerticalExtent = extent;+ verticalExtentContributors.clear();+ verticalExtentContributors.add(contributor);+ } else if (Math.abs(extent - maxVerticalExtent) <= 0.0001) {+ verticalExtentContributors.add(contributor);+ }+ }+ const baseContentH = Math.max(74, Math.ceil(maxVerticalExtent * 2 + 8));+ const laneH = 30 + baseContentH;+ const groupsByLane = new Map();+ for (const group of asArray(workflow.groups)) {+ groupsByLane.set(group.lane, [...(groupsByLane.get(group.lane) || []), group]);+ }+ const groupLaneReserves = asArray(workflow.lanes).map((lane) => {+ let header = 0;+ let footer = 0;+ for (const group of groupsByLane.get(lane.id) || []) {+ const bounds = readableGroupBounds(workflow, group, colXs);+ const labelLeft = bounds.x + 10;+ const labelRight = labelLeft + textUnits(group.label) * 5.6;+ for (const node of nodes) {+ if (node.lane !== group.lane+ || !Number.isInteger(node.col)+ || node.col < group.fromCol+ || node.col > group.toCol+ || node.col < 0+ || node.col >= colXs.length) continue;+ const halfWidth = authoredNodeWidth(node) / 2;+ const nodeLeft = colXs[node.col] - halfWidth;+ const nodeRight = colXs[node.col] + halfWidth;+ const overlapsLabel = nodeRight > labelLeft && nodeLeft < labelRight;+ const topOffset = (baseContentH - authoredNodeHeight(node)) / 2+ + (Number(node.yOffset) || 0);+ const minimumTopOffset = overlapsLabel ? 11 : 9;+ header = Math.max(header, Math.ceil(minimumTopOffset - topOffset));+ const bottomMargin = baseContentH - GROUP_FRAME_BOTTOM_INSET+ - topOffset - authoredNodeHeight(node);+ footer = Math.max(footer, Math.ceil(1 - bottomMargin));+ }+ }+ return { header: Math.max(0, header), footer: Math.max(0, footer) };+ });+ const groupHeaderHeights = groupLaneReserves.map(({ header }) => header);+ const groupFooterHeights = groupLaneReserves.map(({ footer }) => footer);+ const laneHeights = groupLaneReserves.map(({ header, footer }) => laneH + header + footer);+ const laneGap = Math.max(20, Math.ceil(layoutFeedback.laneGapMin || 0));+ for (const [index, reserve] of groupHeaderHeights.entries()) {+ if (!reserve) continue;+ const lane = asArray(workflow.lanes)[index];+ heightContributors.add(`lane ${lane.id || lane.label} group label clearance ${reserve}px`);+ }+ for (const [index, reserve] of groupFooterHeights.entries()) {+ if (!reserve) continue;+ const lane = asArray(workflow.lanes)[index];+ heightContributors.add(`lane ${lane.id || lane.label} group frame containment ${reserve}px`);+ }+ if (laneH > 104) {+ for (const contributor of verticalExtentContributors) heightContributors.add(contributor);+ }+ if (laneGap > 20) {+ for (const contributor of asArray(layoutFeedback.laneGapContributors)) {+ heightContributors.add(contributor);+ }+ }+ const requiredWidth = 40 + laneW + 16;++ return {+ contract: 'readable-v2',+ laneX: 40,+ laneY: 52,+ laneW,+ laneH,+ laneHeights,+ laneGap,+ laneTitleH: 30,+ groupHeaderHeights,+ groupFooterHeights,+ colXs,+ nodeW: 92,+ nodeH: 52,+ defaultViewBoxWidth: requiredWidth,+ channelLabelEdgeKeys,+ widthContributors: [...widthContributors].sort(stableCompare),+ heightContributors: [...heightContributors].sort(stableCompare),+ };+ }++ function compilerFailure(contract, diagnostics, error = diagnostics.map(({ message }) => message).join('\n')) {+ return {+ ok: false,+ error,+ diagnostics,+ receipt: { contract, diagnostics },+ };+ }++ function workflowEdgeName(edge) {+ return edge.id || `${edge.from}->${edge.to}`;+ }++ function stableText(value) {+ return value == null ? '' : String(value);+ }++ function stableCompare(left, right) {+ const a = stableText(left);+ const b = stableText(right);+ return a < b ? -1 : a > b ? 1 : 0;+ }++ function stableValueKey(value) {+ if (Array.isArray(value)) return `[${value.map(stableValueKey).join(',')}]`;+ if (value && typeof value === 'object') {+ return `{${Object.keys(value).sort(stableCompare).map((key) => `${JSON.stringify(key)}:${stableValueKey(value[key])}`).join(',')}}`;+ }+ return JSON.stringify(value);+ }++ function cloneWorkflow(value) {+ return JSON.parse(JSON.stringify(value));+ }++ function canonicalReadableWorkflow(workflow) {+ if (workflow.schema_version !== 2) return workflow;+ const laneOrder = new Map(asArray(workflow.lanes).map((lane, index) => [lane.id, index]));+ const nodes = [...asArray(workflow.nodes)].sort((left, right) => (+ (laneOrder.get(left.lane) ?? Number.MAX_SAFE_INTEGER) - (laneOrder.get(right.lane) ?? Number.MAX_SAFE_INTEGER)+ || left.col - right.col+ || stableCompare(left.id, right.id)+ ));+ const edges = [...asArray(workflow.edges)].sort((left, right) => (+ stableCompare(left.id, right.id)+ || stableCompare(left.from, right.from)+ || stableCompare(left.to, right.to)+ || stableCompare(left.label, right.label)+ || stableCompare(left.route, right.route)+ || stableCompare(stableValueKey(left), stableValueKey(right))+ ));+ const phases = workflow.phases === undefined ? undefined : [...asArray(workflow.phases)].sort((left, right) => (+ left.fromCol - right.fromCol || left.toCol - right.toCol+ || stableCompare(left.id, right.id)+ ));+ const groups = workflow.groups === undefined ? undefined : [...asArray(workflow.groups)].sort((left, right) => (+ (laneOrder.get(left.lane) ?? Number.MAX_SAFE_INTEGER) - (laneOrder.get(right.lane) ?? Number.MAX_SAFE_INTEGER)+ || left.fromCol - right.fromCol || left.toCol - right.toCol+ || stableCompare(left.id, right.id)+ ));+ return {+ ...workflow,+ nodes,+ edges,+ ...(phases ? { phases } : {}),+ ...(groups ? { groups } : {}),+ };+ }++ function semanticContractDiagnostics(workflow) {+ const checks = workflow.semanticChecks;+ if (!checks) return [];++ const nodeIds = new Set(asArray(workflow.nodes).map((node) => node.id));+ const incoming = new Map([...nodeIds].map((id) => [id, 0]));+ const outgoing = new Map([...nodeIds].map((id) => [id, 0]));+ const adjacency = new Map([...nodeIds].map((id) => [id, new Set()]));+ for (const edge of asArray(workflow.edges)) {+ if (!nodeIds.has(edge.from) || !nodeIds.has(edge.to)) continue;+ outgoing.set(edge.from, outgoing.get(edge.from) + 1);+ incoming.set(edge.to, incoming.get(edge.to) + 1);+ adjacency.get(edge.from).add(edge.to);+ }++ const diagnostics = [];+ const diagnostic = (code, message, subject, evidence, supportedFixes) => ({+ code,+ severity: 'error',+ message,+ subject: { diagramType: 'workflow', ...subject },+ evidence,+ supportedFixes,+ });+ const referencedNodes = [+ ...asArray(checks.allowedRoots).map((id, index) => ({ id, path: `/semanticChecks/allowedRoots/${index}` })),+ ...asArray(checks.allowedTerminals).map((id, index) => ({ id, path: `/semanticChecks/allowedTerminals/${index}` })),+ ...asArray(checks.requiredEdges).flatMap((relation, index) => [+ { id: relation.from, path: `/semanticChecks/requiredEdges/${index}/from` },+ { id: relation.to, path: `/semanticChecks/requiredEdges/${index}/to` },+ ]),+ ...asArray(checks.requiredPaths).flatMap((relation, index) => [+ { id: relation.from, path: `/semanticChecks/requiredPaths/${index}/from` },+ { id: relation.to, path: `/semanticChecks/requiredPaths/${index}/to` },+ ]),+ ];+ for (const { id, path } of referencedNodes) {+ if (nodeIds.has(id)) continue;+ diagnostics.push(diagnostic(+ 'workflow/semantic-node-reference',+ `Workflow semantic contract references unknown node "${id}" at ${path}.`,+ { node: id, path },+ { knownNodes: [...nodeIds] },+ [`replace "${id}" with an existing node id`, 'add the missing node before compiling'],+ ));+ }+ if (diagnostics.length) return diagnostics;++ if (checks.allowedRoots !== undefined) {+ const allowed = new Set(checks.allowedRoots);+ for (const [node, count] of incoming) {+ if (count > 0 || allowed.has(node)) continue;+ diagnostics.push(diagnostic(+ 'workflow/unexpected-root',+ `Workflow node "${node}" has no incoming edge and is not declared in semanticChecks.allowedRoots.`,+ { node, path: '/semanticChecks/allowedRoots' },+ { incomingEdges: 0, allowedRoots: [...allowed] },+ [`add the missing incoming edge to "${node}"`, `declare "${node}" in semanticChecks.allowedRoots if it is an intentional source`],+ ));+ }+ }++ if (checks.allowedTerminals !== undefined) {+ const allowed = new Set(checks.allowedTerminals);+ for (const [node, count] of outgoing) {+ if (count > 0 || allowed.has(node)) continue;+ diagnostics.push(diagnostic(+ 'workflow/unexpected-terminal',+ `Workflow node "${node}" has no outgoing edge and is not declared in semanticChecks.allowedTerminals.`,+ { node, path: '/semanticChecks/allowedTerminals' },+ { outgoingEdges: 0, allowedTerminals: [...allowed] },+ [`add the missing outgoing edge from "${node}"`, `declare "${node}" in semanticChecks.allowedTerminals if it is an intentional sink`],+ ));+ }+ }++ const authoredEdges = new Set(asArray(workflow.edges).map((edge) => `${edge.from}\u0000${edge.to}`));+ for (const [index, relation] of asArray(checks.requiredEdges).entries()) {+ if (authoredEdges.has(`${relation.from}\u0000${relation.to}`)) continue;+ diagnostics.push(diagnostic(+ 'workflow/required-edge',+ `Workflow semantic contract requires edge "${relation.from}" -> "${relation.to}", but no authored edge matches it.`,+ { from: relation.from, to: relation.to, path: `/semanticChecks/requiredEdges/${index}` },+ { authoredEdgeCount: asArray(workflow.edges).length },+ [`add an edge from "${relation.from}" to "${relation.to}" without deleting the semantic requirement`],+ ));+ }++ function reachable(from, to) {+ const visited = new Set([from]);+ const pending = [from];+ while (pending.length) {+ const current = pending.shift();+ if (current === to) return true;+ for (const next of adjacency.get(current) || []) {+ if (visited.has(next)) continue;+ visited.add(next);+ pending.push(next);+ }+ }+ return false;+ }++ for (const [index, relation] of asArray(checks.requiredPaths).entries()) {+ if (reachable(relation.from, relation.to)) continue;+ diagnostics.push(diagnostic(+ 'workflow/required-path',+ `Workflow semantic contract requires a directed path from "${relation.from}" to "${relation.to}", but none exists.`,+ { from: relation.from, to: relation.to, path: `/semanticChecks/requiredPaths/${index}` },+ { reachableNodes: [...new Set([relation.from, ...(adjacency.get(relation.from) || [])])] },+ [`restore a directed path from "${relation.from}" to "${relation.to}" without weakening the semantic requirement`],+ ));+ }++ return diagnostics;+ }++ function compileWorkflowInternal({+ workflow: inputWorkflow,+ qualityProfile,+ discoverFixes = true,+ layoutFeedback = {},+ } = {}) {+ if (!inputWorkflow || typeof inputWorkflow !== 'object' || Array.isArray(inputWorkflow)) {+ const diagnostics = [{+ code: 'workflow/input-contract',+ severity: 'error',+ message: 'compileWorkflow requires one parsed workflow document object.',+ subject: { diagramType: 'workflow', path: '/' },+ evidence: {},+ supportedFixes: [],+ }];+ return compilerFailure('fixed-v1', diagnostics, diagnostics[0].message);+ }+ const resolvedQualityProfile = qualityProfile || inputWorkflow.meta?.quality_profile;+ const authoredQualityProfile = inputWorkflow.meta?.quality_profile;+ const qualityResolvedWorkflow = resolvedQualityProfile && resolvedQualityProfile !== inputWorkflow.meta?.quality_profile+ ? { ...inputWorkflow, meta: { ...inputWorkflow.meta, quality_profile: resolvedQualityProfile } }+ : inputWorkflow;+ let inputDiagnostics = [];+ try {+ validateSchema('workflow', qualityResolvedWorkflow);+ } catch (error) {+ inputDiagnostics = Array.isArray(error?.archifyDiagnostics)+ ? error.archifyDiagnostics.map((diagnostic) => ({+ ...diagnostic,+ supportedFixes: [],+ }))+ : [{+ code: 'workflow/input-contract',+ severity: 'error',+ message: 'Workflow schema validation failed unexpectedly.',+ subject: { diagramType: 'workflow', path: '/' },+ evidence: { reason: error?.message || String(error) },+ supportedFixes: [],+ }];+ }+ if (inputDiagnostics.length) {+ return compilerFailure(+ inputWorkflow.schema_version === 2 ? 'readable-v2' : 'fixed-v1',+ inputDiagnostics,+ );+ }+ const workflow = canonicalReadableWorkflow(qualityResolvedWorkflow);+ const semanticDiagnostics = semanticContractDiagnostics(workflow);+ if (semanticDiagnostics.length) {+ return compilerFailure(+ workflow.schema_version === 2 ? 'readable-v2' : 'fixed-v1',+ semanticDiagnostics,+ );+ }+ const sourceIndexes = {+ lanes: new Map(asArray(qualityResolvedWorkflow.lanes).map((lane, index) => [lane, index])),+ nodes: new Map(asArray(qualityResolvedWorkflow.nodes).map((node, index) => [node, index])),+ edges: new Map(asArray(qualityResolvedWorkflow.edges).map((edge, index) => [edge, index])),+ };+ const layout = workflow.schema_version === 2+ ? createReadableLayout(workflow, layoutFeedback)+ : createLegacyLayout();++ const LEGEND_CATALOG = [+ 'frontend',+ 'backend',+ 'security',+ 'messagebus',+ 'database',+ 'cloud',+ 'external',+ ].map((kind) => ({ kind, label: i18nText(workflow.meta.locale, `legend.workflow.${kind}`) }));+ const presentLegendKinds = new Set(asArray(workflow.nodes).map((node) => node.type));+ const workflowLegendEntries = resolveLegend(+ workflow.meta?.legend,+ LEGEND_CATALOG,+ presentLegendKinds,+ );+ const legendFootprintOptions = { fontSize: 7, itemGap: 7 };+ const oneRowLegendFootprint = legendFootprint(workflowLegendEntries, {+ ...legendFootprintOptions,+ width: Number.MAX_SAFE_INTEGER,+ });+ const minimumCanvasWidth = workflow.schema_version === 2+ ? Math.max(layout.defaultViewBoxWidth, oneRowLegendFootprint.minWidth + 40)+ : layout.defaultViewBoxWidth;+ const legendPackingWidth = Math.max(+ 1,+ (workflow.schema_version === 2+ ? minimumCanvasWidth+ : (workflow.meta?.viewBox?.[0] ?? minimumCanvasWidth)) - 40,+ );+ const packedLegendFootprint = legendFootprint(workflowLegendEntries, {+ ...legendFootprintOptions,+ width: legendPackingWidth,+ });+ const legendExtraHeight = workflow.schema_version === 2+ ? packedLegendFootprint.extraHeight+ : 0;++ // Content is 680px wide (laneX + laneW); auto height fits the lanes plus legend.+ const autoHeight = layout.laneY+ + (layout.laneHeights?.reduce((total, height) => total + height, 0)+ ?? (workflow.lanes?.length || 1) * layout.laneH)+ + ((workflow.lanes?.length || 1) - 1) * layout.laneGap+ + 124+ + legendExtraHeight;+ let viewBox = workflow.meta?.viewBox || [minimumCanvasWidth, autoHeight];+ let requiredViewBox = [...viewBox];++ const laneIndex = new Map(asArray(workflow.lanes).map((lane, index) => [lane.id, index]));+ const laneLabels = new Map(asArray(workflow.lanes).map((lane) => [lane.id, lane.label]));++ function nodeContext(node) {+ const group = asArray(workflow.groups).find((candidate) => (+ candidate.lane === node.lane && node.col >= candidate.fromCol && node.col <= candidate.toCol+ ));+ const phase = asArray(workflow.phases).find((candidate) => (+ node.col >= candidate.fromCol && node.col <= candidate.toCol+ ));+ return [laneLabels.get(node.lane), group?.label, phase?.label].filter(Boolean).join(' › ')+ || i18nText(workflow.meta.locale, 'node.context.workflow');+ }++ function laneHeight(idOrIndex) {+ const index = typeof idOrIndex === 'number' ? idOrIndex : laneIndex.get(idOrIndex);+ return layout.laneHeights?.[index] ?? layout.laneH;+ }++ function laneGroupHeaderH(idOrIndex) {+ const index = typeof idOrIndex === 'number' ? idOrIndex : laneIndex.get(idOrIndex);+ return layout.groupHeaderHeights?.[index] ?? 0;+ }++ function laneGroupFooterH(idOrIndex) {+ const index = typeof idOrIndex === 'number' ? idOrIndex : laneIndex.get(idOrIndex);+ return layout.groupFooterHeights?.[index] ?? 0;+ }++ function laneTop(id) {+ const index = laneIndex.get(id);+ const precedingHeight = asArray(workflow.lanes).slice(0, index)+ .reduce((total, _lane, lanePosition) => total + laneHeight(lanePosition), 0);+ return layout.laneY + precedingHeight + index * layout.laneGap;+ }++ function lastLaneBottom() {+ return layout.laneY+ + asArray(workflow.lanes).reduce((total, _lane, index) => total + laneHeight(index), 0)+ + (workflow.lanes.length - 1) * layout.laneGap;+ }++ function legendY() {+ return lastLaneBottom() + 44 + legendExtraHeight;+ }++ function workflowLegendLayout(obstacles = []) {+ return {+ x: 20,+ baselineY: legendY(),+ width: workflow.schema_version === 2 ? legendPackingWidth : viewBox[0] - 40,+ fontSize: 7,+ itemGap: 7,+ minTitleY: lastLaneBottom() + 8,+ obstacles,+ unfit: workflow.meta?.legend === undefined ? 'hide' : 'error',+ diagramType: 'workflow',+ };+ }++ function workflowLegendRects() {+ if (!workflowLegendEntries.length) return [];+ const measured = measureLegend(workflowLegendEntries, workflowLegendLayout());+ if (!measured) return [];+ return [+ { kind: 'title', x: 20, y: measured.titleY - 10, width: 48, height: 14 },+ ...measured.entries.map((entry) => ({+ kind: entry.kind,+ x: entry.x,+ y: entry.baseline - 10,+ width: entry.width,+ height: 14,+ })),+ ];+ }++ function measureNode(node) {+ const width = node.width || layout.nodeW;+ const height = node.height || (node.tag ? 68 : layout.nodeH);+ const cx = layout.colXs[node.col];+ const groupHeaderH = laneGroupHeaderH(node.lane);+ const contentH = laneHeight(node.lane) - layout.laneTitleH+ - groupHeaderH - laneGroupFooterH(node.lane);+ const y = laneTop(node.lane) + layout.laneTitleH + groupHeaderH+ + (contentH - height) / 2 + (node.yOffset || 0);+ return {+ ...node,+ width,+ height,+ x: cx - width / 2,+ y,+ cx,+ cy: y + height / 2+ };+ }++ // Font sizes for this renderer's node text; the fitting geometry is shared.+ const nodeTextFit = {+ labelPreferred: 11,+ labelMinimum: 9,+ sublabelPreferred: 8,+ sublabelMinimum: 6,+ tagPreferred: 7,+ tagMinimum: 6,+ };++ const nodes = new Map(asArray(workflow.nodes).map((node) => [node.id, measureNode(node)]));++ function workflowCompositionFrames() {+ const frames = [];+ for (const [index, lane] of asArray(workflow.lanes).entries()) {+ const y = laneTop(lane.id);+ const height = laneHeight(index);+ frames.push({ id: `lane-${index}`, label: lane.label, kind: 'lane', x: layout.laneX, y, width: layout.laneW, height, radius: 10 });+ if (lane.variant === 'exception') {+ frames.push({ id: `lane-${index}-exception`, label: `${lane.label} exception`, kind: 'exception-lane', x: layout.laneX + 6, y: y + 6, width: layout.laneW - 12, height: height - 12, radius: 8 });+ }+ }+ for (const [index, group] of asArray(workflow.groups).entries()) {+ const span = groupSpan(group);+ frames.push({+ id: `group-${index}`,+ label: group.label,+ kind: 'group',+ x: span.x,+ y: laneTop(group.lane) + layout.laneTitleH + GROUP_FRAME_TOP_INSET,+ width: span.width,+ height: workflow.schema_version === 2+ ? laneHeight(group.lane) - layout.laneTitleH+ - GROUP_FRAME_TOP_INSET - GROUP_FRAME_BOTTOM_INSET+ : layout.laneH - layout.laneTitleH - 16,+ radius: 9,+ });+ }+ return frames;+ }++ function workflowSceneLabelObstacles() {+ const obstacles = [];+ for (const [index, lane] of asArray(workflow.lanes).entries()) {+ const prefix = lane.variant === 'exception' ? 'EX' : String(index + 1).padStart(2, '0');+ const label = `${prefix} / ${lane.label}`;+ obstacles.push({+ kind: 'lane-header',+ id: lane.id,+ x: layout.laneX + 14,+ y: laneTop(lane.id) + 12,+ width: textUnits(label) * 6.2,+ height: 14,+ });+ }+ for (const phase of asArray(workflow.phases)) {+ if (!Number.isInteger(phase.fromCol) || !Number.isInteger(phase.toCol)+ || phase.fromCol < 0 || phase.toCol >= layout.colXs.length || phase.fromCol > phase.toCol) continue;+ const span = phaseSpan(phase);+ obstacles.push({+ kind: 'phase-header',+ id: phase.id ?? null,+ x: span.x,+ y: 27,+ width: span.width,+ height: 16,+ });+ }+ for (const group of asArray(workflow.groups)) {+ if (!laneIndex.has(group.lane)+ || !Number.isInteger(group.fromCol) || !Number.isInteger(group.toCol)+ || group.fromCol < 0 || group.toCol >= layout.colXs.length || group.fromCol > group.toCol) continue;+ const span = groupSpan(group);+ const frameY = laneTop(group.lane) + layout.laneTitleH + GROUP_FRAME_TOP_INSET;+ const labelBaseline = frameY + GROUP_LABEL_BASELINE_OFFSET;+ obstacles.push({+ kind: 'group-label',+ id: group.id ?? null,+ x: span.x + 10,+ y: labelBaseline - GROUP_LABEL_MASK_ASCENT,+ width: textUnits(group.label) * 5.6,+ height: GROUP_LABEL_MASK_H,+ });+ }+ return obstacles;+ }++ const mainPathSteps = new Map(asArray(workflow.mainPath).map((id, index) => [id, index]));+ const edgeSteps = new Map(asArray(workflow.edges).map((edge, index) => {+ const fromStep = mainPathSteps.get(edge.from);+ const toStep = mainPathSteps.get(edge.to);+ const mainStep = Number.isInteger(fromStep) && toStep === fromStep + 1 ? fromStep : null;+ return [edge, mainStep ?? asArray(workflow.mainPath).length + index];+ }));++ function nodeStep(node) {+ return mainPathSteps.get(node.id) ?? asArray(workflow.mainPath).length + asArray(workflow.nodes).findIndex((item) => item.id === node.id);+ }++ function acceptsFix(mutator) {+ if (!discoverFixes) return false;+ const candidate = cloneWorkflow(workflow);+ mutator(candidate);+ return withDiagnosticRecordingSuppressed(() => compileWorkflowWithFeedback({+ workflow: candidate,+ qualityProfile: resolvedQualityProfile,+ discoverFixes: false,+ }).ok);+ }++ function verifiedLegacyAlternative(edge, from, to, requiredClearance) {+ const occupied = [...nodes.values()].filter((node) => node.lane === to.lane && node.id !== to.id);+ const candidates = layout.colXs.map((center, col) => ({ center, col }))+ .filter(({ col }) => col !== to.col)+ .sort((a, b) => Math.abs(a.col - to.col) - Math.abs(b.col - to.col) || a.col - b.col);+ for (const candidate of candidates) {+ const candidateRect = { ...to, col: candidate.col, cx: candidate.center, x: candidate.center - to.width / 2 };+ if (occupied.some((node) => rectsOverlap(candidateRect, node, 8))) continue;+ const centerDistance = Math.abs(candidate.center - from.cx);+ const signedClearance = centerDistance - from.width / 2 - to.width / 2;+ if (signedClearance < requiredClearance) continue;+ if (acceptsFix((document) => {+ document.nodes.find((node) => node.id === to.id).col = candidate.col;+ })) return candidate.col;+ }+ return null;+ }++ function readableMigrationProvidesCapacity(from, to, requiredClearance) {+ const readable = createReadableLayout({ ...workflow, schema_version: 2 });+ const centerDistance = Math.abs(readable.colXs[to.col] - readable.colXs[from.col]);+ if (centerDistance - from.width / 2 - to.width / 2 < requiredClearance) return false;+ if (!discoverFixes) return false;++ return withDiagnosticRecordingSuppressed(() => {+ const migrationQualityProfile = authoredQualityProfile;+ let planned = compileWorkflowWithFeedback({+ workflow: intrinsicWorkflow(workflow),+ qualityProfile: migrationQualityProfile,+ discoverFixes: false,+ });+ if (!planned.ok) {+ planned = compileWorkflowWithFeedback({+ workflow: planningWorkflow(workflow),+ qualityProfile: migrationQualityProfile,+ discoverFixes: false,+ });+ }+ if (!planned.ok || !Array.isArray(planned.receipt?.columns)) return false;++ let candidate;+ try {+ candidate = createMappedWorkflowCandidate(+ workflow,+ LEGACY_COLUMN_CENTERS,+ planned.receipt.columns,+ ).document;+ } catch {+ return false;+ }+ let compiled = compileWorkflowWithFeedback({+ workflow: candidate,+ qualityProfile: migrationQualityProfile,+ discoverFixes: false,+ });+ const requiredViewBox = compiled.diagnostics?.length+ && compiled.diagnostics.every(({ code }) => code === 'workflow/viewbox-capacity')+ ? compiled.diagnostics.find(({ evidence }) => Array.isArray(evidence?.requiredViewBox))+ ?.evidence.requiredViewBox+ : null;+ if (!compiled.ok && Array.isArray(candidate.meta?.viewBox) && requiredViewBox) {+ candidate.meta.viewBox = [+ Math.max(candidate.meta.viewBox[0], requiredViewBox[0]),+ Math.max(candidate.meta.viewBox[1], requiredViewBox[1]),+ ];+ compiled = compileWorkflowWithFeedback({+ workflow: candidate,+ qualityProfile: migrationQualityProfile,+ discoverFixes: false,+ });+ }+ return compiled.ok;+ });+ }++ function verifiedReducedWidths(from, to, requiredClearance) {+ const widthBudget = 2 * (Math.abs(to.cx - from.cx) - requiredClearance);+ if (widthBudget < 64) return null;+ const widths = [from.width, to.width];+ let excess = widths[0] + widths[1] - widthBudget;+ for (const index of widths[0] >= widths[1] ? [0, 1] : [1, 0]) {+ const reduction = Math.min(excess, widths[index] - 32);+ widths[index] -= reduction;+ excess -= reduction;+ }+ if (excess > 0.0001) return null;+ const candidates = [from, to];+ const labelsFit = candidates.every((node, index) => (+ textUnits(node.label) * 6.8 <= widths[index] + 6+ && (!node.sublabel || minimumNodeTextWidth(node.sublabel, nodeTextFit.sublabelMinimum) <= availableNodeTextWidth(widths[index]))+ && (!node.tag || minimumNodeTextWidth(node.tag, nodeTextFit.tagMinimum) <= availableNodeTextWidth(widths[index]))+ ));+ if (!labelsFit) return null;+ const serializedWidths = widths.map((width) => Math.floor((width + 1e-9) * 100) / 100);+ const signedClearance = Math.abs(to.cx - from.cx)+ - serializedWidths[0] / 2 - serializedWidths[1] / 2;+ if (signedClearance + 0.0001 < requiredClearance) return null;+ const accepted = acceptsFix((document) => {+ document.nodes.find((node) => node.id === from.id).width = serializedWidths[0];+ document.nodes.find((node) => node.id === to.id).width = serializedWidths[1];+ });+ return accepted ? serializedWidths : null;+ }++ function enforceLegacyColumnCapacity() {+ if (workflow.schema_version !== 1) return;+ for (const edge of workflow.edges) {+ const from = nodes.get(edge.from);+ const to = nodes.get(edge.to);+ if (!from || !to || from.lane !== to.lane || from.col === to.col) continue;+ if (!verticalIntervalsOverlap(from, to, 8)) continue;+ const centerDistance = Math.abs(to.cx - from.cx);+ const actualSignedClearance = centerDistance - from.width / 2 - to.width / 2;+ const direct = !edge.via && ['auto', 'straight'].includes(edge.route || 'auto')+ && Math.abs(from.cy - to.cy) < 0.0001;+ const requiredDirectClearance = direct ? 28 : 8;+ if (actualSignedClearance >= requiredDirectClearance) continue;+ const alternative = verifiedLegacyAlternative(edge, from, to, requiredDirectClearance);+ const reducedWidths = verifiedReducedWidths(from, to, requiredDirectClearance);+ const capacity = actualSignedClearance < 0+ ? `overlap by ${Math.abs(Math.round(actualSignedClearance))}px`+ : `leave only ${Math.round(actualSignedClearance)}px of direct clearance`;+ const message = `Workflow columns ${from.col}→${to.col} place nodes "${from.id}" and "${to.id}" so they ${capacity} under the fixed-v1 layout.`;+ const supportedFixes = [];+ if (readableMigrationProvidesCapacity(from, to, requiredDirectClearance)) {+ supportedFixes.push('migrate this workflow to schema_version 2');+ }+ if (alternative !== null) supportedFixes.push(`move node "${to.id}" to verified free column ${alternative}`);+ if (reducedWidths) {+ supportedFixes.push(`set node widths "${from.id}"=${Math.round(reducedWidths[0] * 100) / 100}px and "${to.id}"=${Math.round(reducedWidths[1] * 100) / 100}px`);+ }+ throwDiagnosticError(message, [{+ code: 'workflow/column-capacity',+ severity: 'error',+ message,+ subject: {+ diagramType: 'workflow',+ edge: edge.id ?? null,+ from: edge.from,+ to: edge.to,+ fromCol: from.col,+ toCol: to.col,+ },+ evidence: {+ centerDistancePx: centerDistance,+ nodeWidthsPx: [from.width, to.width],+ actualSignedClearancePx: actualSignedClearance,+ requiredDirectClearancePx: requiredDirectClearance,+ },+ supportedFixes,+ suppresses: [+ 'workflow/short-edge',+ 'clean-flow/endpoint-side-direction',+ 'workflow/label-node-overlap',+ ],+ }]);+ }+ }++ function verifiedEdgeFix(edge, message, mutator) {+ const edgeIndex = workflow.edges.indexOf(edge);+ if (edgeIndex < 0) return null;+ const accepted = acceptsFix((document) => mutator(document.edges[edgeIndex], document));+ return accepted ? message : null;+ }++ function verifiedAutomaticRouteFix(edge, { clearSides = false } = {}) {+ const edgeName = workflowEdgeName(edge);+ return verifiedEdgeFix(+ edge,+ clearSides+ ? `remove explicit route geometry and endpoint sides from edge "${edgeName}" so readable-v2 can use its verified automatic candidate`+ : `remove explicit route geometry from edge "${edgeName}" so readable-v2 can use its verified automatic candidate`,+ (candidate) => {+ delete candidate.via;+ delete candidate.channelX;+ delete candidate.channelY;+ delete candidate.route;+ if (clearSides) {+ delete candidate.fromSide;+ delete candidate.toSide;+ }+ },+ );+ }++ function authoredPinEvidence(edge, field) {+ const authoredEdgeIndex = sourceIndexes.edges.get(edge);+ const value = Array.isArray(edge[field])+ ? edge[field].map((item) => (Array.isArray(item) ? [...item] : item))+ : edge[field];+ return {+ edge: workflowEdgeName(edge),+ field,+ ...(Number.isInteger(authoredEdgeIndex) ? { path: `/edges/${authoredEdgeIndex}/${field}` } : {}),+ value,+ };+ }++ function combinations(values, size, start = 0, prefix = [], output = []) {+ if (prefix.length === size) {+ output.push([...prefix]);+ return output;+ }+ for (let index = start; index <= values.length - (size - prefix.length); index += 1) {+ prefix.push(values[index]);+ combinations(values, size, index + 1, prefix, output);+ prefix.pop();+ }+ return output;+ }++ function verifiedPinRemovalAlternatives(edge, fields, reason) {+ if (!discoverFixes) return { removalSets: [], supportedFixes: [] };+ const edgeIndex = workflow.edges.indexOf(edge);+ if (edgeIndex < 0) return { removalSets: [], supportedFixes: [] };+ const uniqueFields = [...new Set(fields.filter((field) => edge[field] !== undefined))];+ for (let size = 1; size <= uniqueFields.length; size += 1) {+ const removalSets = combinations(uniqueFields, size).filter((fieldSet) => (+ acceptsFix((document) => {+ for (const field of fieldSet) delete document.edges[edgeIndex][field];+ })+ ));+ if (!removalSets.length) continue;+ const edgeName = workflowEdgeName(edge);+ return {+ removalSets,+ supportedFixes: removalSets.map((fieldSet) => (+ `remove ${fieldSet.join(' and ')} from edge "${edgeName}" ${reason}`+ )),+ };+ }+ return { removalSets: [], supportedFixes: [] };+ }++ function conflictPinsFromRemovalSets(edge, removalSets, fallbackFields = []) {+ const fields = removalSets.length+ ? [...new Set(removalSets.flat())]+ : [...new Set(fallbackFields)];+ return fields.map((field) => authoredPinEvidence(edge, field));+ }++ function authoredRouteAssertionFields(edge) {+ return [+ ...(Array.isArray(edge?.via) ? ['via'] : []),+ ...(edge?.channelX !== undefined ? ['channelX'] : []),+ ...(edge?.channelY !== undefined ? ['channelY'] : []),+ ...(edge?.route && edge.route !== 'auto' ? ['route'] : []),+ ...(edge?.fromSide && edge.fromSide !== 'auto' ? ['fromSide'] : []),+ ...(edge?.toSide && edge.toSide !== 'auto' ? ['toSide'] : []),+ ];+ }++ function hasAuthoredRouteAssertions(edge) {+ return authoredRouteAssertionFields(edge).length > 0;+ }++ function verifiedPinReferenceAlternatives(candidateRefs, reason) {+ const seenRefs = new Set();+ const refs = candidateRefs.filter(({ edge, edgeIndex, field }) => {+ if (edgeIndex < 0 || edge?.[field] === undefined) return false;+ const key = `${edgeIndex}:${field}`;+ if (seenRefs.has(key)) return false;+ seenRefs.add(key);+ return true;+ });+ const fallbackPins = refs.map(({ edge, field }) => authoredPinEvidence(edge, field));+ if (!discoverFixes) {+ return {+ removalSets: [], conflictingRefs: refs, conflictingPins: fallbackPins, repairs: [], supportedFixes: [],+ };+ }++ for (let size = 1; size <= refs.length; size += 1) {+ const removalSets = combinations(refs, size).filter((removalSet) => (+ acceptsFix((document) => {+ for (const { edgeIndex, field } of removalSet) delete document.edges[edgeIndex][field];+ })+ ));+ if (!removalSets.length) continue;+ const conflictingRefs = [];+ const conflictingPins = [];+ const seenPins = new Set();+ for (const removalSet of removalSets) {+ for (const { edge, field } of removalSet) {+ const key = `${workflow.edges.indexOf(edge)}:${field}`;+ if (seenPins.has(key)) continue;+ seenPins.add(key);+ conflictingRefs.push({ edge, edgeIndex: workflow.edges.indexOf(edge), field });+ conflictingPins.push(authoredPinEvidence(edge, field));+ }+ }+ const repairs = removalSets.map((removalSet) => {+ const grouped = [];+ for (const ref of removalSet) {+ let group = grouped.find(({ edge }) => edge === ref.edge);+ if (!group) {+ group = { edge: ref.edge, fields: [] };+ grouped.push(group);+ }+ group.fields.push(ref.field);+ }+ const removals = grouped.map(({ edge, fields }) => (+ `remove ${fields.join(' and ')} from edge "${workflowEdgeName(edge)}"`+ ));+ return { removalSet, message: `${removals.join(' and ')} ${reason}` };+ });+ return {+ removalSets,+ conflictingRefs,+ conflictingPins,+ repairs,+ supportedFixes: repairs.map(({ message }) => message),+ };+ }+ return {+ removalSets: [], conflictingRefs: refs, conflictingPins: fallbackPins, repairs: [], supportedFixes: [],+ };+ }++ function verifiedRoutePairPinAlternatives(leftEdge, rightEdge, reason) {+ const refs = [leftEdge, rightEdge].flatMap((edge) => {+ const edgeIndex = workflow.edges.indexOf(edge);+ return authoredRouteAssertionFields(edge).map((field) => ({ edge, edgeIndex, field }));+ });+ return verifiedPinReferenceAlternatives(refs, reason);+ }++ function verifiedLabelRoutePinAlternatives(labelEdge, routeEdge) {+ const refs = [];+ const labelEdgeIndex = workflow.edges.indexOf(labelEdge);+ if (Array.isArray(labelEdge?.labelAt)) {+ refs.push({ edge: labelEdge, edgeIndex: labelEdgeIndex, field: 'labelAt' });+ }+ const routeEdgeIndex = workflow.edges.indexOf(routeEdge);+ for (const field of authoredRouteAssertionFields(routeEdge)) {+ refs.push({ edge: routeEdge, edgeIndex: routeEdgeIndex, field });+ }+ return verifiedPinReferenceAlternatives(+ refs,+ Array.isArray(labelEdge?.labelAt)+ ? 'so readable-v2 can replan the remaining authored label-route pins'+ : 'so readable-v2 can replan the remaining authored route assertions',+ );+ }++ function verifiedLabelPairPinAlternatives(leftEdge, rightEdge) {+ return verifiedPinReferenceAlternatives(+ [leftEdge, rightEdge].flatMap((edge) => (+ Array.isArray(edge?.labelAt)+ ? [{ edge, edgeIndex: workflow.edges.indexOf(edge), field: 'labelAt' }]+ : []+ )),+ 'so readable-v2 can replan the remaining authored label pins',+ );+ }++ function verifiedRepairsWithLabelNudges(alternatives) {+ return alternatives.repairs.flatMap(({ removalSet, message }) => {+ if (removalSet.length !== 1 || removalSet[0].field !== 'labelAt') return [message];+ const nudges = verifiedLabelAtAlternatives(removalSet[0].edge);+ return nudges.length ? nudges : [message];+ });+ }++ function throwExplicitPinConflict(edge, invariant, evidence, supportedFixes = []) {+ const message = `Workflow edge "${workflowEdgeName(edge)}" has explicit geometry that violates ${invariant}.`;+ const [onlyPin] = asArray(evidence?.conflictingPins);+ const authoredEdgeIndex = sourceIndexes.edges.get(edge);+ const pinPath = asArray(evidence?.conflictingPins).length === 1+ && Number.isInteger(authoredEdgeIndex)+ && onlyPin?.field+ ? onlyPin.path || `/edges/${authoredEdgeIndex}/${onlyPin.field}`+ : null;+ throwDiagnosticError(message, [{+ code: 'workflow/explicit-pin-conflict',+ severity: 'error',+ message,+ subject: {+ diagramType: 'workflow',+ edge: edge.id ?? null,+ from: edge.from,+ to: edge.to,+ ...(pinPath ? { path: pinPath } : {}),+ },+ evidence: { invariant, ...evidence },+ supportedFixes: supportedFixes.filter(Boolean),+ }]);+ }++ function hasAbsoluteRoutePins(edge) {+ return Array.isArray(edge?.via)+ || edge?.channelX !== undefined+ || edge?.channelY !== undefined;+ }++ function presentRouteGeometryFields(edge) {+ return [+ ...(Array.isArray(edge?.via) ? ['via'] : []),+ ...(edge?.channelX !== undefined ? ['channelX'] : []),+ ...(edge?.channelY !== undefined ? ['channelY'] : []),+ ];+ }++ function verifiedRouteGeometryPinAlternatives(+ edge,+ reason = 'so readable-v2 can replan the remaining explicit route assertions',+ ) {+ const edgeIndex = workflow.edges.indexOf(edge);+ return verifiedPinReferenceAlternatives(+ authoredRouteAssertionFields(edge).map((field) => ({ edge, edgeIndex, field })),+ reason,+ );+ }++ function properOrthogonalIntersection(leftStart, leftEnd, rightStart, rightEnd) {+ const leftOrientation = segmentOrientation(leftStart, leftEnd);+ const rightOrientation = segmentOrientation(rightStart, rightEnd);+ if (leftOrientation === rightOrientation+ || leftOrientation === 'diagonal'+ || rightOrientation === 'diagonal') return null;+ const horizontalStart = leftOrientation === 'horizontal' ? leftStart : rightStart;+ const horizontalEnd = leftOrientation === 'horizontal' ? leftEnd : rightEnd;+ const verticalStart = leftOrientation === 'vertical' ? leftStart : rightStart;+ const verticalEnd = leftOrientation === 'vertical' ? leftEnd : rightEnd;+ const point = [verticalStart[0], horizontalStart[1]];+ const epsilon = 0.0001;+ const insideHorizontal = point[0] > Math.min(horizontalStart[0], horizontalEnd[0]) + epsilon+ && point[0] < Math.max(horizontalStart[0], horizontalEnd[0]) - epsilon;+ const insideVertical = point[1] > Math.min(verticalStart[1], verticalEnd[1]) + epsilon+ && point[1] < Math.max(verticalStart[1], verticalEnd[1]) - epsilon;+ return insideHorizontal && insideVertical ? point : null;+ }++ function verifiedLabelAtAlternatives(edge) {+ if (!Array.isArray(edge.labelAt)) return [];+ const [x, y] = edge.labelAt;+ return [+ [0, 24], [0, -24], [24, 0], [-24, 0],+ [0, 48], [0, -48], [48, 0], [-48, 0],+ ].map(([dx, dy]) => {+ const next = [x + dx, y + dy];+ return verifiedEdgeFix(+ edge,+ `set labelAt on edge "${workflowEdgeName(edge)}" to [${next[0]}, ${next[1]}]`,+ (candidate) => { candidate.labelAt = next; },+ );+ }).filter(Boolean);+ }++ function verifiedLabelAtNudge(edge) {+ const [alternative] = verifiedLabelAtAlternatives(edge);+ if (alternative) return alternative;+ return verifiedEdgeFix(+ edge,+ `remove labelAt from edge "${workflowEdgeName(edge)}" so readable-v2 can use verified automatic label placement`,+ (candidate) => { delete candidate.labelAt; },+ );+ }++ function throwReadableLabelRoutePinConflict(hit, routePoints = null) {+ const labelEdge = hit.labelRelation;+ const routeEdge = hit.otherRelation;+ const labelPinned = Array.isArray(labelEdge?.labelAt);+ const routePinned = hasAuthoredRouteAssertions(routeEdge);+ if (!labelPinned && !routePinned) return false;+ const alternatives = verifiedLabelRoutePinAlternatives(labelEdge, routeEdge);+ const actualRoutePoints = routePoints+ || pathCache.get(routeEdge)?.points+ || pathFor(routeEdge).points;+ const diagnosticEdge = alternatives.conflictingRefs[0]?.edge+ || (labelPinned ? labelEdge : routeEdge);+ throwExplicitPinConflict(diagnosticEdge, 'explicit label-route clearance', {+ conflictingPins: alternatives.conflictingPins,+ ...(labelPinned ? { labelAt: [...labelEdge.labelAt] } : {}),+ labelRect: {+ x: hit.rect.x,+ y: hit.rect.y,+ width: hit.rect.width,+ height: hit.rect.height,+ },+ collidedRoute: {+ edge: routeEdge.id || `${routeEdge.from}->${routeEdge.to}`,+ from: routeEdge.from,+ to: routeEdge.to,+ points: actualRoutePoints.map((point) => [...point]),+ },+ routeSegmentIndex: hit.segmentIndex,+ routeSegment: { from: [...hit.start], to: [...hit.end] },+ clearancePx: Math.round(hit.clearance * 10) / 10,+ minimumPx: hit.threshold,+ }, [+ ...verifiedRepairsWithLabelNudges(alternatives),+ ]);+ return true;+ }++ function throwReadableLabelLabelPinConflict(left, right) {+ const leftEdge = left.relation;+ const rightEdge = right.relation;+ const pinnedEdges = [leftEdge, rightEdge].filter((edge) => Array.isArray(edge?.labelAt));+ if (!pinnedEdges.length) return false;+ const alternatives = verifiedLabelPairPinAlternatives(leftEdge, rightEdge);+ const causalLabelEdges = [...new Set(alternatives.conflictingRefs.map(({ edge }) => edge))];+ const diagnosticEdge = causalLabelEdges[0] || pinnedEdges[0];+ throwExplicitPinConflict(diagnosticEdge, 'explicit label-label clearance', {+ conflictingPins: alternatives.conflictingPins,+ labelRects: [left, right].map((rect) => ({+ edge: rect.relation.id ?? null,+ x: rect.x,+ y: rect.y,+ width: rect.width,+ height: rect.height,+ })),+ minimumGapPx: -2,+ }, verifiedRepairsWithLabelNudges(alternatives));+ return true;+ }++ function classifyFailedAutomaticCandidatePins(edge, rawCandidates) {+ const relationIndex = workflow.edges.indexOf(edge);+ const priorRoutes = [...pathCache.entries()]+ .filter(([otherEdge]) => otherEdge !== edge)+ .map(([relation, routed]) => ({+ relation,+ relationIndex: workflow.edges.indexOf(relation),+ points: routed.points,+ }));+ if (!priorRoutes.length) return;+ const priorLabels = priorRoutes.map(({ relation, relationIndex }) => (+ labelRectFor(relation, relationIndex)+ )).filter(Boolean);++ for (const { points } of rawCandidates) {+ const candidateRect = candidateLabelRect(edge, points);+ const candidateLabel = candidateRect+ ? { ...candidateRect, relation: edge, relationIndex, label: edge.label }+ : null;+ if (candidateLabel) {+ const priorLabel = priorLabels.find((otherLabel) => (+ rectsOverlap(candidateLabel, otherLabel, -2)+ && (Array.isArray(edge.labelAt) || Array.isArray(otherLabel.relation?.labelAt))+ ));+ if (priorLabel) throwReadableLabelLabelPinConflict(candidateLabel, priorLabel);++ const labelRouteHit = collectLabelRouteClearance({+ labels: [candidateLabel],+ routedRelations: priorRoutes,+ threshold: 4,+ }).find((hit) => (+ Array.isArray(edge.labelAt) || hasAbsoluteRoutePins(hit.otherRelation)+ ));+ if (labelRouteHit) {+ const collidedRoute = priorRoutes.find(({ relation }) => relation === labelRouteHit.otherRelation);+ throwReadableLabelRoutePinConflict(labelRouteHit, collidedRoute?.points);+ }+ }++ const reverseHit = collectLabelRouteClearance({+ labels: priorLabels,+ routedRelations: [{ relation: edge, relationIndex, points }],+ threshold: 4,+ }).find((hit) => Array.isArray(hit.labelRelation?.labelAt));+ if (reverseHit) throwReadableLabelRoutePinConflict(reverseHit, points);+ }+ }++ function validateReadablePairwisePinConflicts() {+ const labels = workflow.edges.map((edge, relationIndex) => (+ labelRectFor(edge, relationIndex)+ )).filter(Boolean);+ const routedRelations = workflow.edges.map((edge, relationIndex) => (+ nodes.has(edge.from) && nodes.has(edge.to)+ ? { relation: edge, relationIndex, points: pathFor(edge).points }+ : null+ )).filter(Boolean);++ const labelRouteHit = collectLabelRouteClearance({+ labels,+ routedRelations,+ threshold: 4,+ }).find((hit) => (+ Array.isArray(hit.labelRelation?.labelAt) || hasAuthoredRouteAssertions(hit.otherRelation)+ ));+ if (labelRouteHit) throwReadableLabelRoutePinConflict(labelRouteHit);++ for (let leftIndex = 0; leftIndex < labels.length; leftIndex += 1) {+ for (let rightIndex = leftIndex + 1; rightIndex < labels.length; rightIndex += 1) {+ const left = labels[leftIndex];+ const right = labels[rightIndex];+ if (!rectsOverlap(left, right, -2)) continue;+ throwReadableLabelLabelPinConflict(left, right);+ }+ }++ const requestedProfile = workflow.meta?.quality_profile;+ if (requestedProfile !== 'showcase') return;+ for (let leftIndex = 0; leftIndex < routedRelations.length; leftIndex += 1) {+ const left = routedRelations[leftIndex];+ for (let rightIndex = leftIndex + 1; rightIndex < routedRelations.length; rightIndex += 1) {+ const right = routedRelations[rightIndex];+ const leftPinned = hasAuthoredRouteAssertions(left.relation);+ const rightPinned = hasAuthoredRouteAssertions(right.relation);+ if (!leftPinned && !rightPinned) continue;+ if ([left.relation.from, left.relation.to].some((id) => (+ id === right.relation.from || id === right.relation.to+ ))) continue;+ const leftAnalysis = forwardCollinearAnalysisSegments(left.points);+ const rightAnalysis = forwardCollinearAnalysisSegments(right.points);+ for (const leftSegment of leftAnalysis) {+ for (const rightSegment of rightAnalysis) {+ const point = properOrthogonalIntersection(+ leftSegment.start,+ leftSegment.end,+ rightSegment.start,+ rightSegment.end,+ );+ if (!point) continue;+ const leftSourceIndex = sourceSegmentIndexAtPoint(leftSegment, point);+ const rightSourceIndex = sourceSegmentIndexAtPoint(rightSegment, point);+ const leftSource = {+ from: left.points[leftSourceIndex],+ to: left.points[leftSourceIndex + 1],+ };+ const rightSource = {+ from: right.points[rightSourceIndex],+ to: right.points[rightSourceIndex + 1],+ };+ const alternatives = verifiedRoutePairPinAlternatives(+ left.relation,+ right.relation,+ 'so readable-v2 can replan the remaining authored route assertions',+ );+ const diagnosticEdge = leftPinned ? left.relation : right.relation;+ throwExplicitPinConflict(diagnosticEdge, 'explicit route-route crossing', {+ conflictingPins: alternatives.conflictingPins,+ point,+ segmentIndex: leftSourceIndex,+ otherSegmentIndex: rightSourceIndex,+ routeSegments: [+ { edge: left.relation.id ?? null, from: [...leftSegment.start], to: [...leftSegment.end] },+ { edge: right.relation.id ?? null, from: [...rightSegment.start], to: [...rightSegment.end] },+ ],+ sourceRouteSegments: [+ { edge: left.relation.id ?? null, from: [...leftSource.from], to: [...leftSource.to] },+ { edge: right.relation.id ?? null, from: [...rightSource.from], to: [...rightSource.to] },+ ],+ }, alternatives.supportedFixes);+ }+ }+ }+ }++ const corridorHit = collectAmbiguousCorridors({+ routedRelations,+ minOverlapPx: 8,+ }).find((hit) => (+ hasAuthoredRouteAssertions(hit.left.relation)+ || hasAuthoredRouteAssertions(hit.right.relation)+ ));+ if (corridorHit) {+ const leftSegment = {+ from: corridorHit.left.points[corridorHit.leftSegment],+ to: corridorHit.left.points[corridorHit.leftSegment + 1],+ };+ const rightSegment = {+ from: corridorHit.right.points[corridorHit.rightSegment],+ to: corridorHit.right.points[corridorHit.rightSegment + 1],+ };+ const leftPinned = hasAuthoredRouteAssertions(corridorHit.left.relation);+ const alternatives = verifiedRoutePairPinAlternatives(+ corridorHit.left.relation,+ corridorHit.right.relation,+ 'so readable-v2 can replan the remaining authored route assertions',+ );+ const diagnosticEdge = leftPinned ? corridorHit.left.relation : corridorHit.right.relation;+ throwExplicitPinConflict(diagnosticEdge, 'explicit route-route corridor clearance', {+ conflictingPins: alternatives.conflictingPins,+ segmentIndex: corridorHit.leftSegment,+ otherSegmentIndex: corridorHit.rightSegment,+ routeSegments: [+ {+ edge: corridorHit.left.relation.id ?? null,+ from: [...leftSegment.from],+ to: [...leftSegment.to],+ },+ {+ edge: corridorHit.right.relation.id ?? null,+ from: [...rightSegment.from],+ to: [...rightSegment.to],+ },+ ],+ overlapStart: [...corridorHit.overlapStart],+ overlapEnd: [...corridorHit.overlapEnd],+ overlapLengthPx: corridorHit.overlapLength,+ minimumClearancePx: 8,+ }, alternatives.supportedFixes);+ }+ }++ const READABLE_PRESET_PIN_FIELDS = Object.freeze({+ straight: [],+ drop: ['channelY'],+ 'outside-right': ['channelX'],+ 'return-left': ['channelX'],+ 'bottom-channel': ['channelY'],+ 'up-channel': ['channelY'],+ });++ function presentChannelPins(edge) {+ return ['channelX', 'channelY'].filter((field) => edge[field] !== undefined);+ }++ function validateReadableRouteControls(edge) {+ const channelPins = presentChannelPins(edge);+ const preset = edge.route || 'auto';+ if (preset === 'auto') return;+ const allowedPins = new Set(READABLE_PRESET_PIN_FIELDS[preset] || []);+ const conflictingPins = channelPins.filter((field) => !allowedPins.has(field));+ if (!conflictingPins.length) return;+ const edgeIndex = workflow.edges.indexOf(edge);+ const alternatives = verifiedPinReferenceAlternatives([+ { edge, edgeIndex, field: 'route' },+ ...conflictingPins.map((field) => ({ edge, edgeIndex, field })),+ ], 'and keep the remaining verified route assertions');+ throwExplicitPinConflict(edge, 'route preset compatibility', {+ route: preset,+ allowedPins: [...allowedPins],+ conflictingPins: alternatives.conflictingPins,+ }, alternatives.supportedFixes);+ }++ function segmentOrientation(start, end) {+ if (Math.abs(start[0] - end[0]) <= 0.0001) return 'vertical';+ if (Math.abs(start[1] - end[1]) <= 0.0001) return 'horizontal';+ return 'diagonal';+ }++ function routeSegments(points) {+ return points.slice(0, -1).map((start, index) => ({+ start,+ end: points[index + 1],+ orientation: segmentOrientation(start, points[index + 1]),+ }));+ }++ function endpointSideIsHonored(points, side, endpoint) {+ if (!side || side === 'auto' || points.length < 2) return true;+ const source = endpoint === 'source';+ const from = source ? points[0] : points.at(-2);+ const to = source ? points[1] : points.at(-1);+ const dx = to[0] - from[0];+ const dy = to[1] - from[1];+ if (source) {+ if (side === 'right') return dx > 0 && Math.abs(dy) <= 0.0001;+ if (side === 'left') return dx < 0 && Math.abs(dy) <= 0.0001;+ if (side === 'bottom') return dy > 0 && Math.abs(dx) <= 0.0001;+ if (side === 'top') return dy < 0 && Math.abs(dx) <= 0.0001;+ return false;+ }+ if (side === 'right') return dx < 0 && Math.abs(dy) <= 0.0001;+ if (side === 'left') return dx > 0 && Math.abs(dy) <= 0.0001;+ if (side === 'bottom') return dy < 0 && Math.abs(dx) <= 0.0001;+ if (side === 'top') return dy > 0 && Math.abs(dx) <= 0.0001;+ return false;+ }++ function corridorTopologyMatches(points, axis, coordinate) {+ const collapsed = normalizeRoutePoints(points.map((point) => [...point]));+ const start = collapsed[0];+ const end = collapsed.at(-1);+ const via = axis === 'x'+ ? [[coordinate, start[1]], [coordinate, end[1]]]+ : [[start[0], coordinate], [end[0], coordinate]];+ const expected = normalizeRoutePoints([start, ...via, end]);+ const actualPattern = routeSegments(collapsed).map(({ orientation }) => orientation);+ const expectedPattern = routeSegments(expected).map(({ orientation }) => orientation);+ return actualPattern.length === expectedPattern.length+ && actualPattern.every((orientation, index) => orientation === expectedPattern[index])+ && routeContainsChannelPin(+ collapsed,+ axis === 'x' ? 'channelX' : 'channelY',+ coordinate,+ );+ }++ function routeMatchesPresetFamily(preset, points, from, to) {+ const collapsed = normalizeRoutePoints(points.map((point) => [...point]));+ const segments = routeSegments(collapsed);+ if (preset === 'straight') return collapsed.length === 2;+ if (preset === 'drop') {+ if (from.lane === to.lane) return false;+ if (collapsed.length === 2 && segments[0]?.orientation === 'vertical') return true;+ const upper = from.cy <= to.cy ? from : to;+ const lower = upper === from ? to : from;+ return segments.some(({ start, orientation }) => (+ orientation === 'horizontal'+ && start[1] >= upper.y + upper.height - 0.0001+ && start[1] <= lower.y + 0.0001+ && corridorTopologyMatches(points, 'y', start[1])+ ));+ }+ if (preset === 'outside-right' || preset === 'return-left') {+ const boundary = preset === 'outside-right'+ ? Math.max(from.x + from.width, to.x + to.width)+ : Math.min(from.x, to.x);+ return segments.some(({ start, orientation }) => (+ orientation === 'vertical'+ && (preset === 'outside-right'+ ? start[0] > boundary + 0.0001+ : start[0] < boundary - 0.0001)+ && corridorTopologyMatches(points, 'x', start[0])+ ));+ }+ if (preset === 'bottom-channel' || preset === 'up-channel') {+ const boundary = preset === 'bottom-channel'+ ? Math.max(from.y + from.height, to.y + to.height)+ : Math.min(from.y, to.y);+ return segments.some(({ start, orientation }) => (+ orientation === 'horizontal'+ && (preset === 'bottom-channel'+ ? start[1] > boundary + 0.0001+ : start[1] < boundary - 0.0001)+ && corridorTopologyMatches(points, 'y', start[1])+ ));+ }+ return false;+ }++ function routeContainsChannelPin(points, field, value) {+ return points.slice(0, -1).some((start, index) => {+ const end = points[index + 1];+ if (field === 'channelX') {+ return start[0] === value+ && end[0] === value+ && Math.abs(end[1] - start[1]) > 0.0001;+ }+ return start[1] === value+ && end[1] === value+ && Math.abs(end[0] - start[0]) > 0.0001;+ });+ }++ function validateReadablePinnedGeometry() {+ if (workflow.schema_version !== 2) return;+ for (const edge of workflow.edges) {+ if (!nodes.has(edge.from) || !nodes.has(edge.to)) continue;+ validateReadableRouteControls(edge);+ const edgeName = workflowEdgeName(edge);+ const edgeIndex = sourceIndexes.edges.get(edge);+ if (Array.isArray(edge.labelAt)) {+ const rect = labelRectFor(edge, workflow.edges.indexOf(edge));+ if (rect && (rect.x < 0 || rect.y < 0)) {+ throwExplicitPinConflict(edge, 'viewBox-origin containment', {+ conflictingPins: [{+ edge: edgeName,+ field: 'labelAt',+ path: `/edges/${edgeIndex}/labelAt`,+ value: [...edge.labelAt],+ }],+ offendingRect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },+ minimumCoordinate: 0,+ }, [verifiedLabelAtNudge(edge)]);+ }+ }+ const negativeViaIndex = asArray(edge.via).findIndex(([x, y]) => x < 0 || y < 0);+ const negativeRoutePin = negativeViaIndex >= 0+ ? {+ field: 'via',+ path: `/edges/${edgeIndex}/via/${negativeViaIndex}`,+ value: [...edge.via[negativeViaIndex]],+ }+ : edge.channelX < 0+ ? { field: 'channelX', path: `/edges/${edgeIndex}/channelX`, value: edge.channelX }+ : edge.channelY < 0+ ? { field: 'channelY', path: `/edges/${edgeIndex}/channelY`, value: edge.channelY }+ : null;+ if (negativeRoutePin) {+ throwExplicitPinConflict(edge, 'viewBox-origin containment', {+ conflictingPins: [{ edge: edgeName, ...negativeRoutePin }],+ minimumCoordinate: 0,+ }, [+ verifiedAutomaticRouteFix(edge),+ verifiedAutomaticRouteFix(edge, { clearSides: true }),+ ]);+ }+ const hasPinnedRoute = Array.isArray(edge.via)+ || edge.channelX !== undefined+ || edge.channelY !== undefined;+ const points = pathFor(edge).points;+ if (hasPinnedRoute) {+ const invalidPointIndex = points.findIndex((point) => (+ !Array.isArray(point) || point.length !== 2 || !isFinitePoint(...point)+ ));+ if (invalidPointIndex !== -1) {+ const alternatives = verifiedRouteGeometryPinAlternatives(edge);+ throwExplicitPinConflict(edge, 'finite route coordinates', {+ conflictingPins: alternatives.conflictingPins,+ pointIndex: invalidPointIndex,+ point: points[invalidPointIndex],+ }, alternatives.supportedFixes);+ }+ for (let segmentIndex = 0; segmentIndex < points.length - 1; segmentIndex += 1) {+ const start = points[segmentIndex];+ const end = points[segmentIndex + 1];+ const dx = Math.abs(end[0] - start[0]);+ const dy = Math.abs(end[1] - start[1]);+ if (dx <= 0.0001 && dy <= 0.0001) {+ const duplicateFix = Array.isArray(edge.via) && edge.via.length+ ? verifiedEdgeFix(+ edge,+ `remove duplicate via[${Math.min(segmentIndex, edge.via.length - 1)}] and keep the remaining authored pins unchanged`,+ (candidate) => candidate.via.splice(Math.min(segmentIndex, candidate.via.length - 1), 1),+ )+ : verifiedAutomaticRouteFix(edge);+ const alternatives = Array.isArray(edge.via)+ ? null+ : verifiedRouteGeometryPinAlternatives(edge);+ throwExplicitPinConflict(edge, 'non-zero route segments', {+ conflictingPins: alternatives?.conflictingPins+ || [authoredPinEvidence(edge, 'via')],+ segmentIndex,+ from: start,+ to: end,+ }, alternatives?.supportedFixes || [duplicateFix]);+ }+ if (dx > 0.0001 && dy > 0.0001) {+ const alternatives = verifiedRouteGeometryPinAlternatives(edge);+ throwExplicitPinConflict(edge, 'orthogonal route segments', {+ conflictingPins: alternatives.conflictingPins,+ segmentIndex,+ from: start,+ to: end,+ }, alternatives.supportedFixes);+ }+ const endpoint = segmentIndex === 0 || segmentIndex === points.length - 2;+ const minimumPx = points.length === 2 ? 28 : endpoint ? 8 : 16;+ const lengthPx = dx + dy;+ if (lengthPx + 0.0001 < minimumPx) {+ const alternatives = verifiedRouteGeometryPinAlternatives(edge);+ throwExplicitPinConflict(edge, endpoint ? '8px endpoint stub clearance' : '16px interior turn clearance', {+ conflictingPins: alternatives.conflictingPins,+ segmentIndex,+ position: segmentIndex === 0 ? 'source-stub' : segmentIndex === points.length - 2 ? 'target-stub' : 'interior',+ from: start,+ to: end,+ lengthPx,+ minimumPx,+ }, alternatives.supportedFixes);+ }+ }+ const { fromSide, toSide } = edgeSides(edge);+ if (Array.isArray(edge.via)) {+ const missingChannelPins = presentChannelPins(edge).filter((field) => (+ !routeContainsChannelPin(points, field, edge[field])+ ));+ if (missingChannelPins.length) {+ const candidateFields = ['via', ...missingChannelPins];+ const alternatives = verifiedPinRemovalAlternatives(+ edge,+ candidateFields,+ 'and replan the remaining explicit route assertions',+ );+ throwExplicitPinConflict(edge, 'channel pin preservation', {+ route: edge.route || 'auto',+ conflictingPins: conflictPinsFromRemovalSets(+ edge,+ alternatives.removalSets,+ candidateFields,+ ),+ points: points.map((point) => [...point]),+ }, alternatives.supportedFixes);+ }+ }+ if (edge.route+ && edge.route !== 'auto'+ && !routeMatchesPresetFamily(+ edge.route,+ points,+ nodes.get(edge.from),+ nodes.get(edge.to),+ )) {+ const authoredEdgeIndex = workflow.edges.indexOf(edge);+ const alternatives = verifiedPinReferenceAlternatives([+ { edge, edgeIndex: authoredEdgeIndex, field: 'route' },+ ...presentRouteGeometryFields(edge)+ .map((field) => ({ edge, edgeIndex: authoredEdgeIndex, field })),+ ], 'and keep the remaining verified route assertions');+ throwExplicitPinConflict(edge, 'route preset compatibility', {+ route: edge.route,+ conflictingPins: alternatives.conflictingPins,+ points: points.map((point) => [...point]),+ }, alternatives.supportedFixes);+ }+ if (!routeHonorsEndpointSides(points, fromSide, toSide)) {+ const mismatchedSideFields = [+ ...(edge.fromSide && edge.fromSide !== 'auto'+ && !endpointSideIsHonored(points, fromSide, 'source') ? ['fromSide'] : []),+ ...(edge.toSide && edge.toSide !== 'auto'+ && !endpointSideIsHonored(points, toSide, 'target') ? ['toSide'] : []),+ ];+ const candidateFields = [+ ...mismatchedSideFields,+ ...presentRouteGeometryFields(edge),+ ];+ const alternatives = verifiedPinRemovalAlternatives(+ edge,+ candidateFields,+ 'and replan the remaining explicit pins',+ );+ throwExplicitPinConflict(edge, 'perpendicular endpoint-side direction', {+ conflictingPins: conflictPinsFromRemovalSets(+ edge,+ alternatives.removalSets,+ candidateFields,+ ),+ points: points.map((point) => [...point]),+ fromSide,+ toSide,+ }, alternatives.supportedFixes);+ }+ const nodeCollision = firstRouteNodeCollision(edge, points);+ if (nodeCollision) {+ const alternatives = verifiedRouteGeometryPinAlternatives(edge);+ throwExplicitPinConflict(edge, 'node clearance', {+ conflictingPins: alternatives.conflictingPins,+ ...nodeCollision,+ }, alternatives.supportedFixes);+ }+ const legendObstacle = workflowLegendRects().find((rect) => points.slice(0, -1).some((point, index) => (+ segmentIntersectsRect({ start: point, end: points[index + 1] }, rect)+ )));+ if (legendObstacle) {+ const alternatives = verifiedRouteGeometryPinAlternatives(edge);+ throwExplicitPinConflict(edge, 'legend clearance', {+ conflictingPins: alternatives.conflictingPins,+ points: points.map((point) => [...point]),+ legendObstacle,+ }, alternatives.supportedFixes);+ }+ const compositionObstacle = workflowSceneLabelObstacles().find((rect) => (+ points.slice(0, -1).some((point, index) => (+ segmentIntersectsRect({ start: point, end: points[index + 1] }, rect)+ ))+ ));+ if (compositionObstacle) {+ const alternatives = verifiedRouteGeometryPinAlternatives(edge);+ throwExplicitPinConflict(edge, 'lane/phase/group label clearance', {+ conflictingPins: alternatives.conflictingPins,+ points: points.map((point) => [...point]),+ compositionObstacle,+ }, alternatives.supportedFixes);+ }+ const [frameRun] = collectBorderRuns({+ routedRelations: [{ points }],+ frames: workflowCompositionFrames(),+ });+ if (frameRun) {+ const alternatives = verifiedRouteGeometryPinAlternatives(edge);+ throwExplicitPinConflict(edge, 'structural-frame border clearance', {+ conflictingPins: alternatives.conflictingPins,+ points: points.map((point) => [...point]),+ frame: frameRun.frame?.id ?? frameRun.frameIndex,+ side: frameRun.side,+ overlapLengthPx: frameRun.overlapLength,+ }, alternatives.supportedFixes);+ }+ }++ if (edge.labelAt) {+ const rect = labelRectFor(edge, workflow.edges.indexOf(edge));+ const obstacle = rect && [...nodes.values()].find((node) => rectsOverlap(rect, node, -2));+ if (obstacle) {+ throwExplicitPinConflict(edge, 'edge-label node clearance', {+ conflictingPins: [authoredPinEvidence(edge, 'labelAt')],+ labelAt: [...edge.labelAt],+ labelRect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },+ obstacleNode: obstacle.id,+ }, [verifiedEdgeFix(+ edge,+ 'remove labelAt so readable-v2 can use its verified automatic label placement',+ (candidate) => { delete candidate.labelAt; },+ )]);+ }+ const legendObstacle = rect && workflowLegendRects().find((legendRect) => (+ rectsOverlap(rect, legendRect)+ ));+ if (legendObstacle) {+ throwExplicitPinConflict(edge, 'edge-label legend clearance', {+ conflictingPins: [authoredPinEvidence(edge, 'labelAt')],+ labelAt: [...edge.labelAt],+ labelRect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },+ legendObstacle,+ }, [verifiedEdgeFix(+ edge,+ 'remove labelAt so readable-v2 can use its verified automatic label placement',+ (candidate) => { delete candidate.labelAt; },+ )]);+ }+ const compositionObstacle = rect && workflowSceneLabelObstacles().find((candidate) => (+ rectsOverlap(rect, candidate)+ ));+ if (compositionObstacle) {+ throwExplicitPinConflict(edge, 'edge-label lane/phase/group clearance', {+ conflictingPins: [authoredPinEvidence(edge, 'labelAt')],+ labelAt: [...edge.labelAt],+ labelRect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },+ compositionObstacle,+ }, [verifiedEdgeFix(+ edge,+ `remove labelAt from edge "${workflowEdgeName(edge)}" so readable-v2 can use its verified automatic label placement`,+ (candidate) => { delete candidate.labelAt; },+ )]);+ }+ }+ }+ validateReadablePairwisePinConflicts();+ }++ function validateWorkflow() {+ const problems = [];+ if (workflow.schema_version !== 1 && workflow.schema_version !== 2) {+ problems.push('Workflow files must set "schema_version" to 1 or 2.');+ }+ if (workflow.diagram_type !== 'workflow') {+ problems.push(`Unsupported diagram_type "${workflow.diagram_type}". Expected "workflow".`);+ }+ if (!workflow.meta || !workflow.meta.title) {+ problems.push('Workflow files must include meta.title.');+ }+ if (!Array.isArray(workflow.lanes) || !workflow.lanes.length) {+ problems.push('Workflow files must include at least one lane.');+ }+ if (!Array.isArray(workflow.nodes)) {+ problems.push('Workflow files must include a nodes array.');+ }+ if (!Array.isArray(workflow.edges)) {+ problems.push('Workflow files must include an edges array.');+ }+ if (workflow.phases !== undefined && !Array.isArray(workflow.phases)) {+ problems.push('Workflow "phases" must be an array.');+ }+ if (workflow.groups !== undefined && !Array.isArray(workflow.groups)) {+ problems.push('Workflow "groups" must be an array.');+ }+ if (workflow.mainPath !== undefined && !Array.isArray(workflow.mainPath)) {+ problems.push('Workflow "mainPath" must be an array of node ids.');+ }+ if (workflow.cards !== undefined && !Array.isArray(workflow.cards)) {+ problems.push('Workflow "cards" must be an array.');+ }+ if (problems.length) {+ throwDiagnosticProblems('Workflow layout validation failed', problems, {+ subject: { diagramType: 'workflow' },+ });+ }++ enforceLegacyColumnCapacity();++ const laneIds = new Set(workflow.lanes.map((lane) => lane.id));+ if (laneIds.size !== workflow.lanes.length) {+ problems.push('Lane ids must be unique.');+ }+ if (nodes.size !== workflow.nodes.length) {+ problems.push('Node ids must be unique.');+ }+ const phaseIds = new Set(asArray(workflow.phases).map((phase) => phase.id));+ if (phaseIds.size !== asArray(workflow.phases).length) {+ problems.push('Phase ids must be unique.');+ }+ const groupIds = new Set(asArray(workflow.groups).map((group) => group.id));+ if (groupIds.size !== asArray(workflow.groups).length) {+ problems.push('Group ids must be unique.');+ }++ for (const node of nodes.values()) {+ if (!laneIds.has(node.lane)) {+ problems.push(`Node "${node.id}" uses unknown lane "${node.lane}".`);+ continue;+ }+ if (!Number.isInteger(node.col) || node.col < 0 || node.col >= layout.colXs.length) {+ problems.push(`Node "${node.id}" uses column ${node.col}, but valid columns are integers 0..${layout.colXs.length - 1}.`);+ continue;+ }+ if (!isFinitePoint(node.x, node.y, node.cx, node.cy)) {+ problems.push(`Node "${node.id}" produced non-finite coordinates — check col, width, height, and yOffset are numbers.`);+ continue;+ }+ const estLabelW = textUnits(node.label) * 6.8;+ if (estLabelW > node.width + 6) {+ problems.push(`Label "${node.label}" (~${Math.round(estLabelW)}px) is wider than node "${node.id}" (${node.width}px) — shorten the label or increase node.width.`);+ }+ const brandRailProblem = brandTopRailProblem(node, node.width, nodeTextFit.labelMinimum);+ if (brandRailProblem) problems.push(brandRailProblem);+ const availableTextW = availableNodeTextWidth(node.width);+ for (const [field, value, minimum] of [+ ['Sublabel', node.sublabel, nodeTextFit.sublabelMinimum],+ ['Tag', node.tag, nodeTextFit.tagMinimum],+ ]) {+ if (!value) continue;+ const minimumW = minimumNodeTextWidth(value, minimum);+ if (minimumW > availableTextW) {+ problems.push(`${field} "${value}" needs ~${Math.ceil(minimumW)}px at the ${minimum}px legible minimum, but node "${node.id}" provides ${availableTextW}px — shorten the ${field.toLowerCase()} or increase node.width.`);+ }+ }++ const top = laneTop(node.lane);+ const contentTop = top + layout.laneTitleH + laneGroupHeaderH(node.lane);+ const laneRight = layout.laneX + layout.laneW;+ if (node.x < layout.laneX || node.x + node.width > laneRight) {+ problems.push(`Node "${node.id}" exceeds the horizontal bounds of lane "${node.lane}".`);+ }+ if (node.y < contentTop || node.y + node.height > top + laneHeight(node.lane)) {+ problems.push(`Node "${node.id}" collides with the title or boundary of lane "${node.lane}".`);+ }+ }++ const phaseRanges = [];+ for (const phase of asArray(workflow.phases)) {+ if (!Number.isInteger(phase.fromCol) || !Number.isInteger(phase.toCol)) {+ problems.push(`Phase "${phase.id}" must use integer fromCol/toCol values.`);+ continue;+ }+ if (phase.fromCol < 0 || phase.toCol >= layout.colXs.length || phase.fromCol > phase.toCol) {+ problems.push(`Phase "${phase.id}" uses invalid columns ${phase.fromCol}..${phase.toCol}; use an ordered range within 0..${layout.colXs.length - 1}.`);+ } else {+ phaseRanges.push(phase);+ }+ const estLabelW = textUnits(phase.label) * 5.6;+ const width = phaseSpan(phase).width;+ if (estLabelW > width + 8) {+ problems.push(`Phase label "${phase.label}" (~${Math.round(estLabelW)}px) is wider than its ${Math.round(width)}px span — shorten the label or widen the phase range.`);+ }+ }+ phaseRanges.sort((a, b) => a.fromCol - b.fromCol || a.toCol - b.toCol);+ for (let i = 0; i < phaseRanges.length; i += 1) {+ for (let j = i + 1; j < phaseRanges.length; j += 1) {+ const earlier = phaseRanges[i];+ const later = phaseRanges[j];+ if (later.fromCol > earlier.toCol) break;+ problems.push(`Phase "${later.id}" (${later.fromCol}..${later.toCol}) overlaps phase "${earlier.id}" (${earlier.fromCol}..${earlier.toCol}) — start at col ${earlier.toCol + 1} or later, or end the earlier phase at col ${later.fromCol - 1}.`);+ }+ }++ for (const group of asArray(workflow.groups)) {+ if (!laneIds.has(group.lane)) {+ problems.push(`Group "${group.id}" uses unknown lane "${group.lane}".`);+ continue;+ }+ if (!Number.isInteger(group.fromCol) || !Number.isInteger(group.toCol)) {+ problems.push(`Group "${group.id}" must use integer fromCol/toCol values.`);+ continue;+ }+ if (group.fromCol < 0 || group.toCol >= layout.colXs.length || group.fromCol > group.toCol) {+ problems.push(`Group "${group.id}" uses invalid columns ${group.fromCol}..${group.toCol}; use an ordered range within 0..${layout.colXs.length - 1}.`);+ }+ const contained = [...nodes.values()].some((node) => node.lane === group.lane && node.col >= group.fromCol && node.col <= group.toCol);+ if (!contained) {+ problems.push(`Group "${group.id}" does not contain any nodes — align its lane/columns with the parallel or branch work it frames.`);+ }+ }++ const byLane = new Map();+ for (const node of nodes.values()) {+ byLane.set(node.lane, [...(byLane.get(node.lane) || []), node]);+ }+ for (const [lane, laneNodes] of byLane) {+ for (let i = 0; i < laneNodes.length; i += 1) {+ for (let j = i + 1; j < laneNodes.length; j += 1) {+ if (rectsOverlap(laneNodes[i], laneNodes[j], 8)) {+ problems.push(`Nodes "${laneNodes[i].id}" and "${laneNodes[j].id}" are less than 8px apart in lane "${lane}" — move one to another col, adjust yOffset, or reduce width/height.`);+ }+ }+ }+ }++ for (const edge of workflow.edges) {+ if (!nodes.has(edge.from)) problems.push(`Edge "${edge.label || edge.from}" references unknown source "${edge.from}".`);+ if (!nodes.has(edge.to)) problems.push(`Edge "${edge.label || edge.to}" references unknown target "${edge.to}".`);+ if (nodes.has(edge.from) && nodes.has(edge.to)) {+ const routed = pathFor(edge);+ if (routed.points.length === 2) {+ const [start, end] = routed.points;+ const segmentLength = Math.hypot(end[0] - start[0], end[1] - start[1]);+ if (segmentLength < 28) {+ problems.push(`Edge "${edge.from}" -> "${edge.to}" is too short (${Math.round(segmentLength)}px; minimum 28px) — move the nodes farther apart or use a verified orthogonal route with readable clearance.`);+ }+ }+ }+ }++ problems.push(...cleanEndpointSideProblems({+ relations: workflow.edges,+ endpointIds: new Set(nodes.keys()),+ pathFor,+ diagramType: 'workflow',+ relationCollection: 'edges',+ fromSideFor: (edge) => edgeSides(edge).fromSide,+ toSideFor: (edge) => edgeSides(edge).toSide,+ routeHint: 'keep automatic routing, or choose fromSide/toSide and via points whose first and final segments cross node borders perpendicularly',+ }));+ problems.push(...cleanFlowProblems({+ relations: workflow.edges,+ obstacles: nodes.values(),+ pathFor,+ diagramType: 'workflow',+ relationCollection: 'edges',+ obstacleKind: 'node',+ routeHint: 'adjust fromSide/toSide, set route/via or channel coordinates, or move the node to a clearer lane/column'+ }));+ problems.push(...cleanCrossingProblems({+ relations: workflow.edges,+ endpointIds: new Set(nodes.keys()),+ pathFor,+ diagramType: 'workflow',+ relationCollection: 'edges',+ profile: workflow.meta?.quality_profile,+ profileIsAuthoritative: true,+ mergeForwardCollinearWaypoints: workflow.schema_version === 2,+ routeHint: 'adjust route/via, bias, or channel coordinates so the edges use separate lane corridors'+ }));+ problems.push(...cleanAmbiguousCorridorProblems({+ relations: workflow.edges,+ endpointIds: new Set(nodes.keys()),+ pathFor,+ diagramType: 'workflow',+ relationCollection: 'edges',+ profile: workflow.meta?.quality_profile,+ profileIsAuthoritative: true,+ routeHint: 'adjust route/via, bias, or channel coordinates so unrelated edges do not visually merge'+ }));+ problems.push(...cleanBorderRunProblems({+ relations: workflow.edges,+ endpointIds: new Set(nodes.keys()),+ frames: workflowCompositionFrames(),+ pathFor,+ diagramType: 'workflow',+ relationCollection: 'edges',+ profile: workflow.meta?.quality_profile,+ profileIsAuthoritative: true,+ routeHint: 'adjust route/via, bias, or channel coordinates so the edge crosses the lane or group perpendicularly instead of following its border'+ }));+ problems.push(...cleanRouteRhythmProblems({+ relations: workflow.edges,+ endpointIds: new Set(nodes.keys()),+ pathFor,+ diagramType: 'workflow',+ relationCollection: 'edges',+ profile: workflow.meta?.quality_profile,+ profileIsAuthoritative: true,+ routeHint: 'adjust route/via, bias, or channel coordinates so each turn has a readable run-up'+ }));++ if (Array.isArray(workflow.mainPath)) {+ for (const id of workflow.mainPath) {+ if (!nodes.has(id)) {+ problems.push(`mainPath references unknown node "${id}".`);+ }+ }+ for (let i = 0; i < workflow.mainPath.length - 1; i += 1) {+ const fromId = workflow.mainPath[i];+ const toId = workflow.mainPath[i + 1];+ const from = nodes.get(fromId);+ const to = nodes.get(toId);+ if (!from || !to) continue;+ const linked = workflow.edges.some((edge) => edge.from === fromId && edge.to === toId);+ if (!linked) {+ problems.push(`mainPath step "${fromId}" -> "${toId}" has no matching edge — add the edge or remove the pair from mainPath.`);+ }+ if (to.col < from.col) {+ problems.push(`mainPath step "${fromId}" -> "${toId}" moves backward from col ${from.col} to ${to.col} — use a return edge outside mainPath for loops.`);+ }+ }+ }++ const labelRects = [];+ for (const [edgeIndex, edge] of workflow.edges.entries()) {+ const labelRect = labelRectFor(edge, edgeIndex);+ if (labelRect) labelRects.push(labelRect);+ }+ for (const rect of labelRects) {+ for (const node of nodes.values()) {+ if (rectsOverlap(rect, node, -2)) {+ problems.push(`Label "${rect.label}" overlaps node "${node.id}" — adjust labelDx/labelDy/labelSegment or set labelAt.\n${suggestLabelObstacleFix(rect, rect.lx, rect.ly, node, 'node')}`);+ }+ }+ }+ for (let i = 0; i < labelRects.length; i += 1) {+ for (let j = i + 1; j < labelRects.length; j += 1) {+ if (rectsOverlap(labelRects[i], labelRects[j], -2)) {+ problems.push(`Labels "${labelRects[i].label}" and "${labelRects[j].label}" overlap — adjust labelDx/labelDy/labelSegment or route one relationship through a separate corridor.\n${suggestLabelPairFix(labelRects[i], labelRects[j])}`);+ }+ }+ }+ problems.push(...cleanLabelRouteClearanceProblems({+ relations: workflow.edges,+ labels: labelRects,+ endpointIds: new Set(nodes.keys()),+ pathFor,+ diagramType: 'workflow',+ relationCollection: 'edges',+ profile: workflow.meta?.quality_profile,+ profileIsAuthoritative: true,+ }));++ if (workflow.schema_version === 1) {+ if (viewBox[0] < layout.laneX + layout.laneW + 16) {+ problems.push(`viewBox width ${viewBox[0]} clips the ${layout.laneW}px lanes — set meta.viewBox[0] to at least ${layout.laneX + layout.laneW + 16}.`);+ }+ if (legendY() + 18 > viewBox[1]) {+ problems.push(`Legend exceeds viewBox height ${viewBox[1]} — set meta.viewBox[1] to at least ${legendY() + 18}.`);+ }+ }++ if (problems.length) {+ throwDiagnosticProblems('Workflow layout validation failed', problems, {+ subject: { diagramType: 'workflow' },+ });+ }+ }++ function validateReadableInputsBeforeRouting() {+ if (workflow.schema_version !== 2) return;+ const fail = (diagnostic) => throwDiagnosticError(diagnostic.message, [diagnostic]);+ const unusedId = (base, used) => {+ for (let suffix = 2; ; suffix += 1) {+ const candidate = `${base}-${suffix}`;+ if (!used.has(candidate)) return candidate;+ }+ };+ const authoredLanes = [...workflow.lanes].sort((left, right) => (+ sourceIndexes.lanes.get(left) - sourceIndexes.lanes.get(right)+ ));+ const authoredNodes = [...workflow.nodes].sort((left, right) => (+ sourceIndexes.nodes.get(left) - sourceIndexes.nodes.get(right)+ ));+ const authoredEdges = [...workflow.edges].sort((left, right) => (+ sourceIndexes.edges.get(left) - sourceIndexes.edges.get(right)+ ));++ const firstLaneIndex = new Map();+ for (const lane of authoredLanes) {+ const laneIndex = sourceIndexes.lanes.get(lane);+ if (firstLaneIndex.has(lane.id)) {+ const message = `Workflow lane id "${lane.id}" is duplicated.`;+ const replacement = unusedId(lane.id, new Set(workflow.lanes.map(({ id }) => id)));+ const canonicalLaneIndex = workflow.lanes.indexOf(lane);+ const supportedFixes = acceptsFix((document) => {+ document.lanes[canonicalLaneIndex].id = replacement;+ }) ? [`rename /lanes/${laneIndex}/id to verified unique id "${replacement}"`] : [];+ fail({+ code: 'workflow/duplicate-lane-id',+ severity: 'error',+ message,+ subject: { diagramType: 'workflow', lane: lane.id, path: `/lanes/${laneIndex}/id` },+ evidence: {+ duplicateLaneId: lane.id,+ firstPath: `/lanes/${firstLaneIndex.get(lane.id)}/id`,+ duplicatePath: `/lanes/${laneIndex}/id`,+ },+ supportedFixes,+ });+ }+ firstLaneIndex.set(lane.id, laneIndex);+ }++ const firstNodeIndex = new Map();+ for (const node of authoredNodes) {+ const nodeIndex = sourceIndexes.nodes.get(node);+ if (firstNodeIndex.has(node.id)) {+ const message = `Workflow node id "${node.id}" is duplicated.`;+ const replacement = unusedId(node.id, new Set(workflow.nodes.map(({ id }) => id)));+ const canonicalNodeIndex = workflow.nodes.indexOf(node);+ const supportedFixes = acceptsFix((document) => {+ document.nodes[canonicalNodeIndex].id = replacement;+ }) ? [`rename /nodes/${nodeIndex}/id to verified unique id "${replacement}"`] : [];+ fail({+ code: 'workflow/duplicate-node-id',+ severity: 'error',+ message,+ subject: { diagramType: 'workflow', node: node.id, path: `/nodes/${nodeIndex}/id` },+ evidence: {+ duplicateNodeId: node.id,+ firstPath: `/nodes/${firstNodeIndex.get(node.id)}/id`,+ duplicatePath: `/nodes/${nodeIndex}/id`,+ },+ supportedFixes,+ });+ }+ firstNodeIndex.set(node.id, nodeIndex);+ }++ const availableNodeIds = [...nodes.keys()].sort(stableCompare);+ for (const edge of authoredEdges) {+ const edgeIndex = sourceIndexes.edges.get(edge);+ for (const [field, endpoint] of [['from', 'source'], ['to', 'target']]) {+ if (nodes.has(edge[field])) continue;+ const message = `Workflow edge "${workflowEdgeName(edge)}" references unknown ${endpoint} "${edge[field]}".`;+ const canonicalEdgeIndex = workflow.edges.indexOf(edge);+ const supportedFixes = availableNodeIds.flatMap((nodeId) => (+ acceptsFix((document) => {+ document.edges[canonicalEdgeIndex][field] = nodeId;+ })+ ? [`set /edges/${edgeIndex}/${field} to verified node id "${nodeId}"`]+ : []+ ));+ fail({+ code: 'workflow/unknown-edge-endpoint',+ severity: 'error',+ message,+ subject: {+ diagramType: 'workflow',+ edge: edge.id ?? null,+ path: `/edges/${edgeIndex}/${field}`,+ from: edge.from,+ to: edge.to,+ },+ evidence: {+ endpoint,+ unknownNodeId: edge[field],+ availableNodeIds,+ },+ supportedFixes,+ });+ }+ }+ const laneIds = new Set(workflow.lanes.map((lane) => lane.id));+ const availableLaneIds = [...laneIds].sort(stableCompare);+ const nodeSourceIndexes = new Map(authoredNodes.map((node) => [+ node.id,+ sourceIndexes.nodes.get(node),+ ]));++ const byLane = new Map();+ for (const authoredNode of authoredNodes) {+ const nodeIndex = sourceIndexes.nodes.get(authoredNode);+ const node = nodes.get(authoredNode.id);+ if (!laneIds.has(node.lane)) {+ const message = `Workflow node "${node.id}" uses unknown lane "${node.lane}".`;+ const canonicalNodeIndex = workflow.nodes.findIndex((candidate) => candidate.id === node.id);+ const supportedFixes = availableLaneIds.flatMap((laneId) => (+ acceptsFix((document) => {+ document.nodes[canonicalNodeIndex].lane = laneId;+ })+ ? [`set /nodes/${nodeIndex}/lane to verified lane id "${laneId}"`]+ : []+ ));+ fail({+ code: 'workflow/unknown-node-lane',+ severity: 'error',+ message,+ subject: { diagramType: 'workflow', node: node.id, path: `/nodes/${nodeIndex}/lane` },+ evidence: { unknownLaneId: node.lane, availableLaneIds },+ supportedFixes,+ });+ }+ if (!Number.isInteger(node.col) || node.col < 0 || node.col >= layout.colXs.length) {+ const message = `Workflow node "${node.id}" uses column ${node.col}, but valid columns are integers 0..${layout.colXs.length - 1}.`;+ const canonicalNodeIndex = workflow.nodes.findIndex((candidate) => candidate.id === node.id);+ const supportedFixes = layout.colXs.flatMap((_x, col) => (+ acceptsFix((document) => {+ document.nodes[canonicalNodeIndex].col = col;+ })+ ? [`set /nodes/${nodeIndex}/col to verified column ${col}`]+ : []+ ));+ fail({+ code: 'workflow/invalid-node-column',+ severity: 'error',+ message,+ subject: { diagramType: 'workflow', node: node.id, path: `/nodes/${nodeIndex}/col` },+ evidence: { actualColumn: node.col, minimumColumn: 0, maximumColumn: layout.colXs.length - 1 },+ supportedFixes,+ });+ }+ if (!isFinitePoint(node.x, node.y, node.cx, node.cy)) {+ const message = `Workflow node "${node.id}" produced non-finite coordinates.`;+ fail({+ code: 'workflow/non-finite-node-geometry',+ severity: 'error',+ message,+ subject: { diagramType: 'workflow', node: node.id, path: `/nodes/${nodeIndex}` },+ evidence: {+ measuredRect: { x: node.x, y: node.y, width: node.width, height: node.height },+ authored: {+ col: authoredNode.col,+ width: authoredNode.width ?? null,+ height: authoredNode.height ?? null,+ yOffset: authoredNode.yOffset ?? null,+ },+ },+ supportedFixes: [],+ });+ }+ byLane.set(node.lane, [...(byLane.get(node.lane) || []), node]);+ }+ for (const [lane, laneNodes] of byLane) {+ for (let left = 0; left < laneNodes.length; left += 1) {+ for (let right = left + 1; right < laneNodes.length; right += 1) {+ if (rectsOverlap(laneNodes[left], laneNodes[right], 8)) {+ const leftNode = laneNodes[left];+ const rightNode = laneNodes[right];+ const rightIndex = nodeSourceIndexes.get(rightNode.id);+ const canonicalNodeIndex = workflow.nodes.findIndex((candidate) => (+ candidate.id === rightNode.id+ ));+ const supportedFixes = layout.colXs.flatMap((_x, col) => {+ if (col === rightNode.col) return [];+ return acceptsFix((document) => {+ document.nodes[canonicalNodeIndex].col = col;+ })+ ? [`set /nodes/${rightIndex}/col to verified free column ${col}`]+ : [];+ });+ const message = `Workflow nodes "${leftNode.id}" and "${rightNode.id}" are less than 8px apart in lane "${lane}".`;+ fail({+ code: 'workflow/node-overlap',+ severity: 'error',+ message,+ subject: { diagramType: 'workflow', node: rightNode.id, path: `/nodes/${rightIndex}` },+ evidence: {+ lane,+ minimumClearancePx: 8,+ nodes: [+ { id: leftNode.id, rect: { x: leftNode.x, y: leftNode.y, width: leftNode.width, height: leftNode.height } },+ { id: rightNode.id, rect: { x: rightNode.x, y: rightNode.y, width: rightNode.width, height: rightNode.height } },+ ],+ },+ supportedFixes,+ });+ }+ }+ }+ }+ }++ function gapYBetween(fromLane, toLane, bias = 0.5) {+ const a = laneTop(fromLane) + laneHeight(fromLane);+ const b = laneTop(toLane);+ return a + (b - a) * bias;+ }++ function spanForCols(fromCol, toCol, pad = 46, minimumWidth = 0) {+ const start = layout.colXs[fromCol] - pad;+ const end = layout.colXs[toCol] + pad;+ const width = Math.max(end - start, minimumWidth);+ if (fromCol === toCol && width > end - start) {+ return { x: start, width, cx: start + width / 2 };+ }+ const cx = (start + end) / 2;+ return { x: cx - width / 2, width, cx };+ }++ function phaseSpan(phase) {+ return spanForCols(+ phase.fromCol,+ phase.toCol,+ 46,+ workflow.schema_version === 2 ? textUnits(phase.label) * 5.6 + 8 : 0,+ );+ }++ function groupSpan(group) {+ if (workflow.schema_version === 2) {+ return readableGroupBounds(workflow, group, layout.colXs);+ }+ return spanForCols(+ group.fromCol,+ group.toCol,+ 50,+ 0,+ );+ }++ function sameLaneAutoVia(start, end) {+ if (start[0] === end[0] || start[1] === end[1]) return [];+ const midX = (start[0] + end[0]) / 2;+ return [[midX, start[1]], [midX, end[1]]];+ }++ function routeClearsUnrelatedNodes(edge, points, clearance = 2) {+ const endpointIds = new Set([edge.from, edge.to]);+ for (const node of nodes.values()) {+ if (endpointIds.has(node.id)) continue;+ for (let index = 0; index < points.length - 1; index += 1) {+ if (segmentIntersectsRect({ start: points[index], end: points[index + 1] }, node, clearance)) {+ return false;+ }+ }+ }+ return true;+ }++ function firstRouteNodeCollision(edge, points) {+ const lastSegment = points.length - 2;+ for (const node of nodes.values()) {+ const endpointRole = node.id === edge.from+ ? 'source-endpoint'+ : node.id === edge.to ? 'target-endpoint' : 'unrelated';+ for (let segmentIndex = 0; segmentIndex <= lastSegment; segmentIndex += 1) {+ if (endpointRole === 'source-endpoint' && segmentIndex === 0) continue;+ if (endpointRole === 'target-endpoint' && segmentIndex === lastSegment) continue;+ const clearancePx = endpointRole === 'unrelated' ? 2 : 0;+ const from = points[segmentIndex];+ const to = points[segmentIndex + 1];+ if (segmentIntersectsRect({ start: from, end: to }, node, clearancePx)) {+ return {+ obstacleNode: node.id,+ obstacleRole: endpointRole,+ segmentIndex,+ from: [...from],+ to: [...to],+ clearancePx,+ };+ }+ }+ }+ return null;+ }++ function oneBendCrossLaneVia(edge, start, end, fromSide, toSide) {+ const fromVertical = fromSide === 'top' || fromSide === 'bottom';+ const toVertical = toSide === 'top' || toSide === 'bottom';+ if (fromVertical === toVertical) return null;++ const corner = fromVertical ? [start[0], end[1]] : [end[0], start[1]];+ const points = normalizeRoutePoints([start, corner, end]);+ if (points.length !== 3 || !routeHonorsEndpointSides(points, fromSide, toSide)) return null;++ const segmentsAreReadable = points.slice(0, -1).every((point, index) => (+ Math.hypot(+ points[index + 1][0] - point[0],+ points[index + 1][1] - point[1],+ ) >= 8+ ));+ if (!segmentsAreReadable || !routeClearsUnrelatedNodes(edge, points)) return null;+ return points.slice(1, -1);+ }++ const pathCache = new Map();+ const readableSideCache = new Map();++ function legacyAutomaticOneBendSides(edge, from, to) {+ const automaticRoute = !edge.via && (!edge.route || edge.route === 'auto');+ const automaticFrom = !edge.fromSide || edge.fromSide === 'auto';+ const automaticTo = !edge.toSide || edge.toSide === 'auto';+ if (!automaticRoute || !automaticFrom || !automaticTo || from.lane === to.lane) return null;+ if (from.cx === to.cx || from.cy === to.cy) return null;+ const verticalFrom = to.cy < from.cy ? 'top' : 'bottom';+ const horizontalTo = to.cx < from.cx ? 'right' : 'left';+ const horizontalFrom = to.cx < from.cx ? 'left' : 'right';+ const verticalTo = to.cy < from.cy ? 'bottom' : 'top';+ const candidates = [+ { fromSide: verticalFrom, toSide: horizontalTo },+ { fromSide: horizontalFrom, toSide: verticalTo },+ ];++ return candidates.find(({ fromSide, toSide }) => {+ const start = anchor(from, fromSide);+ const end = anchor(to, toSide);+ return oneBendCrossLaneVia(edge, start, end, fromSide, toSide);+ }) || null;+ }++ function readableAutomaticSides(edge, from, to) {+ const automaticRoute = !edge.via+ && edge.channelX === undefined+ && edge.channelY === undefined+ && (!edge.route || edge.route === 'auto');+ const authoredFrom = edge.fromSide && edge.fromSide !== 'auto' ? edge.fromSide : null;+ const authoredTo = edge.toSide && edge.toSide !== 'auto' ? edge.toSide : null;+ if (!automaticRoute || (authoredFrom && authoredTo)) return null;+ if (readableSideCache.has(edge)) return readableSideCache.get(edge);++ const preferred = [];+ const legacyPreferred = legacyAutomaticOneBendSides(edge, from, to);+ if (legacyPreferred) preferred.push(legacyPreferred);+ preferred.push({+ fromSide: authoredFrom || defaultFromSide(from, to),+ toSide: authoredTo || defaultToSide(from, to),+ });+ const sideOrder = ['right', 'bottom', 'left', 'top'];+ for (const fromSide of authoredFrom ? [authoredFrom] : sideOrder) {+ for (const toSide of authoredTo ? [authoredTo] : sideOrder) {+ preferred.push({ fromSide, toSide });+ }+ }++ const seen = new Set();+ const sidePairs = [];+ for (const candidate of preferred) {+ if (authoredFrom && candidate.fromSide !== authoredFrom) continue;+ if (authoredTo && candidate.toSide !== authoredTo) continue;+ const key = `${candidate.fromSide}:${candidate.toSide}`;+ if (seen.has(key)) continue;+ seen.add(key);+ sidePairs.push(candidate);+ }++ const naturalFromSide = authoredFrom || defaultFromSide(from, to);+ const naturalToSide = authoredTo || defaultToSide(from, to);+ const planFor = (candidate, pairOrdinal) => {+ const start = anchor(from, candidate.fromSide);+ const end = anchor(to, candidate.toSide);+ return {+ start,+ end,+ planned: readableAutomaticCandidateSet(+ edge,+ from,+ to,+ start,+ end,+ candidate.fromSide,+ candidate.toSide,+ {+ ordinalOffset: pairOrdinal * 9,+ naturalFromSide,+ naturalToSide,+ },+ ),+ };+ };++ const primary = sidePairs[0];+ if (primary) {+ const { planned } = planFor(primary, 0);+ if (planned.candidates.length) {+ readableSideCache.set(edge, primary);+ return primary;+ }+ }++ const candidates = [];+ for (const [pairOrdinal, candidate] of sidePairs.entries()) {+ const { planned } = planFor(candidate, pairOrdinal);+ candidates.push(...planned.candidates.map((route) => ({ ...route, ...candidate })));+ }+ candidates.sort((left, right) => compareCost(left.cost, right.cost));+ if (candidates.length) {+ const selected = {+ fromSide: candidates[0].fromSide,+ toSide: candidates[0].toSide,+ };+ readableSideCache.set(edge, selected);+ return selected;+ }+ readableSideCache.set(edge, null);+ return null;+ }++ function automaticOneBendSides(edge, from, to) {+ return workflow.schema_version === 2+ ? readableAutomaticSides(edge, from, to)+ : legacyAutomaticOneBendSides(edge, from, to);+ }++ const OUTWARD_SIDE_VECTOR = Object.freeze({+ left: [-1, 0],+ right: [1, 0],+ top: [0, -1],+ bottom: [0, 1],+ });++ function outwardStub(point, side, distance = 16) {+ const [dx, dy] = OUTWARD_SIDE_VECTOR[side] || [0, 0];+ return [point[0] + dx * distance, point[1] + dy * distance];+ }++ function orthogonalRoute(points) {+ return points.every((point, index) => {+ if (!Array.isArray(point) || point.length !== 2 || !isFinitePoint(...point)) return false;+ if (index === 0) return true;+ const previous = points[index - 1];+ const dx = Math.abs(point[0] - previous[0]);+ const dy = Math.abs(point[1] - previous[1]);+ return (dx <= 0.0001) !== (dy <= 0.0001);+ });+ }++ function routeClearsEndpointNodes(points, from, to) {+ const lastSegment = points.length - 2;+ for (let index = 0; index <= lastSegment; index += 1) {+ const segment = { start: points[index], end: points[index + 1] };+ if (index > 0 && segmentIntersectsRect(segment, from)) return false;+ if (index < lastSegment && segmentIntersectsRect(segment, to)) return false;+ }+ return true;+ }++ function routeMeetsHardRhythm(points) {+ if (points.length === 2) {+ return Math.hypot(points[1][0] - points[0][0], points[1][1] - points[0][1]) + 0.0001 >= 28;+ }+ return points.slice(0, -1).every((point, index) => {+ const length = Math.abs(points[index + 1][0] - point[0]) + Math.abs(points[index + 1][1] - point[1]);+ const endpoint = index === 0 || index === points.length - 2;+ return length + 0.0001 >= (endpoint ? 8 : 16);+ });+ }++ function routeLabelClearsNodes(edge, points) {+ if (!edge.label || edge.labelAt) return true;+ const [lx, ly] = workflowEdgeLabelPoint(edge, points);+ const rect = {+ x: lx - workflowLabelWidth(edge.label) / 2,+ y: ly - 10,+ width: workflowLabelWidth(edge.label),+ height: 14,+ };+ return [...nodes.values()].every((node) => !rectsOverlap(rect, node, -2));+ }++ function candidateLabelRect(edge, points) {+ if (!edge.label) return null;+ const [lx, ly] = workflowEdgeLabelPoint(edge, points);+ const width = workflowLabelWidth(edge.label);+ return { x: lx - width / 2, y: ly - 10, width, height: 14 };+ }++ function labelRouteClearanceDeficit(edge, points, threshold = 8) {+ const candidateLabel = candidateLabelRect(edge, points);+ let deficit = 0;+ for (const [otherEdge, routed] of pathCache) {+ const otherIndex = workflow.edges.indexOf(otherEdge);+ const otherLabel = labelRectFor(otherEdge, otherIndex);+ if (candidateLabel) {+ for (let index = 0; index < routed.points.length - 1; index += 1) {+ const clearance = segmentRectClearance({+ start: routed.points[index],+ end: routed.points[index + 1],+ }, candidateLabel);+ if (clearance != null) deficit += Math.max(0, threshold - clearance);+ }+ }+ if (otherLabel) {+ for (let index = 0; index < points.length - 1; index += 1) {+ const clearance = segmentRectClearance({+ start: points[index],+ end: points[index + 1],+ }, otherLabel);+ if (clearance != null) deficit += Math.max(0, threshold - clearance);+ }+ }+ }+ return deficit;+ }++ function routeClearsPlacedLabels(edge, points) {+ const candidateLabel = candidateLabelRect(edge, points);+ for (const [otherEdge, routed] of pathCache) {+ const otherIndex = workflow.edges.indexOf(otherEdge);+ const otherLabel = labelRectFor(otherEdge, otherIndex);+ if (candidateLabel && otherLabel && rectsOverlap(candidateLabel, otherLabel, -2)) return false;+ if (candidateLabel) {+ for (let index = 0; index < routed.points.length - 1; index += 1) {+ const clearance = segmentRectClearance({+ start: routed.points[index],+ end: routed.points[index + 1],+ }, candidateLabel);+ if (clearance != null && clearance + 0.0001 < 4) return false;+ }+ }+ if (otherLabel) {+ for (let index = 0; index < points.length - 1; index += 1) {+ const clearance = segmentRectClearance({+ start: points[index],+ end: points[index + 1],+ }, otherLabel);+ if (clearance != null && clearance + 0.0001 < 4) return false;+ }+ }+ }+ return true;+ }++ function routeClearsLegend(edge, points) {+ if (!workflowLegendEntries.length) return true;+ const legendRects = workflowLegendRects();+ for (const rect of legendRects) {+ for (let index = 0; index < points.length - 1; index += 1) {+ if (segmentIntersectsRect({ start: points[index], end: points[index + 1] }, rect)) return false;+ }+ const label = candidateLabelRect(edge, points);+ if (label && rectsOverlap(label, rect)) return false;+ }+ return true;+ }++ function routeClearsSceneLabelObstacles(edge, points) {+ const label = candidateLabelRect(edge, points);+ for (const obstacle of workflowSceneLabelObstacles()) {+ for (let index = 0; index < points.length - 1; index += 1) {+ if (segmentIntersectsRect({ start: points[index], end: points[index + 1] }, obstacle)) {+ return false;+ }+ }+ if (label && rectsOverlap(label, obstacle)) return false;+ }+ return true;+ }++ function routeClearsFrameBorders(points) {+ return collectBorderRuns({+ routedRelations: [{ points }],+ frames: workflowCompositionFrames(),+ }).length === 0;+ }++ function routeExtentCoordinates(edge, points) {+ const coordinates = [...points];+ if (!edge.labelAt) {+ const label = candidateLabelRect(edge, points);+ if (label) {+ coordinates.push([label.x, label.y], [label.x + label.width, label.y + label.height]);+ }+ }+ return coordinates;+ }++ function routeFitsCanvasOrigin(edge, points) {+ return routeExtentCoordinates(edge, points).every(([x, y]) => x >= 0 && y >= 0);+ }++ function readableCandidateIsFeasible(edge, points, from, to, fromSide, toSide) {+ return points.length >= 2+ && orthogonalRoute(points)+ && routeHonorsEndpointSides(points, fromSide, toSide)+ && routeMeetsHardRhythm(points)+ && routeClearsEndpointNodes(points, from, to)+ && routeClearsUnrelatedNodes(edge, points)+ && routeLabelClearsNodes(edge, points)+ && routeClearsPlacedLabels(edge, points)+ && routeClearsLegend(edge, points)+ && routeClearsSceneLabelObstacles(edge, points)+ && routeClearsFrameBorders(points)+ && routeFitsCanvasOrigin(edge, points);+ }++ function corridorViaY(start, end, fromSide, toSide, y) {+ const startStub = outwardStub(start, fromSide);+ const endStub = outwardStub(end, toSide);+ return [startStub, [startStub[0], y], [endStub[0], y], endStub];+ }++ function corridorViaX(start, end, fromSide, toSide, x) {+ const startStub = outwardStub(start, fromSide);+ const endStub = outwardStub(end, toSide);+ return [startStub, [x, startStub[1]], [x, endStub[1]], endStub];+ }++ function axisOverlapLength(a, b, c, d) {+ const horizontal = Math.abs(a[1] - b[1]) <= 0.0001+ && Math.abs(c[1] - d[1]) <= 0.0001+ && Math.abs(a[1] - c[1]) <= 0.0001;+ const vertical = Math.abs(a[0] - b[0]) <= 0.0001+ && Math.abs(c[0] - d[0]) <= 0.0001+ && Math.abs(a[0] - c[0]) <= 0.0001;+ if (!horizontal && !vertical) return 0;+ const axis = horizontal ? 0 : 1;+ return Math.max(0, Math.min(Math.max(a[axis], b[axis]), Math.max(c[axis], d[axis]))+ - Math.max(Math.min(a[axis], b[axis]), Math.min(c[axis], d[axis])));+ }++ function properAxisCrossing(a, b, c, d) {+ const firstHorizontal = Math.abs(a[1] - b[1]) <= 0.0001;+ const secondHorizontal = Math.abs(c[1] - d[1]) <= 0.0001;+ if (firstHorizontal === secondHorizontal) return false;+ const horizontal = firstHorizontal ? [a, b] : [c, d];+ const vertical = firstHorizontal ? [c, d] : [a, b];+ const x = vertical[0][0];+ const y = horizontal[0][1];+ return x > Math.min(horizontal[0][0], horizontal[1][0]) + 0.0001+ && x < Math.max(horizontal[0][0], horizontal[1][0]) - 0.0001+ && y > Math.min(vertical[0][1], vertical[1][1]) + 0.0001+ && y < Math.max(vertical[0][1], vertical[1][1]) - 0.0001;+ }++ function routeInteractionMetrics(edge, points) {+ let properCrossingCount = 0;+ let sharedCorridorPx = 0;+ for (const [otherEdge, routed] of pathCache) {+ if ([edge.from, edge.to].some((id) => id === otherEdge.from || id === otherEdge.to)) continue;+ for (let left = 0; left < points.length - 1; left += 1) {+ for (let right = 0; right < routed.points.length - 1; right += 1) {+ if (properAxisCrossing(points[left], points[left + 1], routed.points[right], routed.points[right + 1])) {+ properCrossingCount += 1;+ }+ sharedCorridorPx += axisOverlapLength(+ points[left], points[left + 1], routed.points[right], routed.points[right + 1],+ );+ }+ }+ }+ return { properCrossingCount, sharedCorridorPx };+ }++ function automaticForwardReversePx(edge, points) {+ const from = nodes.get(edge.from);+ const to = nodes.get(edge.to);+ if (!from || !to || ['return', 'error'].includes(edge.role) || to.col <= from.col) return 0;+ return points.slice(0, -1).reduce((total, point, index) => (+ total + Math.max(0, point[0] - points[index + 1][0])+ ), 0);+ }++ function readableCandidateCost(+ edge,+ points,+ ordinal,+ naturalFromSide,+ naturalToSide,+ ) {+ const interaction = routeInteractionMetrics(edge, points);+ const segmentLengths = points.slice(0, -1).map((point, index) => (+ Math.abs(points[index + 1][0] - point[0]) + Math.abs(points[index + 1][1] - point[1])+ ));+ const routeLength = segmentLengths.reduce((total, length) => total + length, 0);+ const directLength = Math.abs(points.at(-1)[0] - points[0][0]) + Math.abs(points.at(-1)[1] - points[0][1]);+ const interiorPreferred28Deficit = segmentLengths.slice(1, -1)+ .reduce((total, length) => total + Math.max(0, 28 - length), 0);+ const xs = points.map(([x]) => x);+ const ys = points.map(([, y]) => y);+ const canvasGrowthPx = Math.max(0, -Math.min(...xs))+ + Math.max(0, Math.max(...xs) - minimumCanvasWidth)+ + Math.max(0, -Math.min(...ys))+ + Math.max(0, Math.max(...ys) - autoHeight);+ const from = nodes.get(edge.from);+ const to = nodes.get(edge.to);+ const naturalStart = anchor(from, naturalFromSide);+ const naturalEnd = anchor(to, naturalToSide);+ const portDisplacementPx = Math.abs(points[0][0] - naturalStart[0])+ + Math.abs(points[0][1] - naturalStart[1])+ + Math.abs(points.at(-1)[0] - naturalEnd[0])+ + Math.abs(points.at(-1)[1] - naturalEnd[1]);+ const legacyCoordinateDisplacement = Math.abs(from.cx - LEGACY_COLUMN_CENTERS[from.col])+ + Math.abs(to.cx - LEGACY_COLUMN_CENTERS[to.col]);+ return {+ automaticForwardReversePx: automaticForwardReversePx(edge, points),+ properCrossingCount: interaction.properCrossingCount,+ sharedCorridorPx: interaction.sharedCorridorPx,+ labelRouteClearanceDeficit: labelRouteClearanceDeficit(edge, points),+ interiorPreferred28Deficit,+ bendCount: Math.max(0, points.length - 2),+ stretchMilli: Math.round((directLength > 0 ? routeLength / directLength : 1) * 1000),+ canvasGrowthPx,+ portDisplacementMilli: Math.round(portDisplacementPx * 1000),+ legacyCoordinateDisplacement,+ stableCandidateOrdinal: ordinal,+ };+ }++ function compareCost(left, right) {+ for (const dimension of READABLE_CANDIDATE_COST_PRIORITY) {+ if ((left[dimension] || 0) !== (right[dimension] || 0)) {+ return (left[dimension] || 0) - (right[dimension] || 0);+ }+ }+ return 0;+ }++ function readableAutomaticCandidateSet(+ edge,+ from,+ to,+ start,+ end,+ fromSide,+ toSide,+ {+ ordinalOffset = 0,+ naturalFromSide = fromSide,+ naturalToSide = toSide,+ } = {},+ ) {+ const midX = (start[0] + end[0]) / 2;+ const laneGapY = from.lane === to.lane+ ? laneTop(from.lane) - 16+ : gapYBetween(from.lane, to.lane, edge.bias ?? 0.5);+ const topY = Math.max(8, Math.min(laneTop(from.lane), laneTop(to.lane)) - 16);+ const bottomY = Math.max(+ laneTop(from.lane) + laneHeight(from.lane),+ laneTop(to.lane) + laneHeight(to.lane),+ ) + 16;+ const outsideLeft = layout.laneX - 20;+ const outsideRight = layout.laneX + layout.laneW + 12;+ const rawCandidates = [+ { family: 'facing-straight', via: [] },+ { family: 'horizontal-then-vertical', via: [[end[0], start[1]]] },+ { family: 'vertical-then-horizontal', via: [[start[0], end[1]]] },+ { family: 'lane-gap-corridor', via: corridorViaY(start, end, fromSide, toSide, laneGapY) },+ { family: 'column-gap-corridor', via: corridorViaX(start, end, fromSide, toSide, midX) },+ { family: 'outside-left', via: corridorViaX(start, end, fromSide, toSide, outsideLeft) },+ { family: 'outside-right', via: corridorViaX(start, end, fromSide, toSide, outsideRight) },+ { family: 'top-corridor', via: corridorViaY(start, end, fromSide, toSide, topY) },+ { family: 'bottom-corridor', via: corridorViaY(start, end, fromSide, toSide, bottomY) },+ ];+ const candidates = rawCandidates.map((candidate, ordinal) => ({+ ...candidate,+ ordinal: ordinalOffset + ordinal,+ points: normalizeRoutePoints([start, ...candidate.via, end]),+ })).filter(({ points }) => (+ readableCandidateIsFeasible(edge, points, from, to, fromSide, toSide)+ )).map((candidate) => ({+ ...candidate,+ cost: readableCandidateCost(+ edge,+ candidate.points,+ candidate.ordinal,+ naturalFromSide,+ naturalToSide,+ ),+ })).sort((left, right) => compareCost(left.cost, right.cost));+ return { rawCandidates, candidates, outsideRight };+ }++ function readableAutomaticVia(edge, from, to, start, end, fromSide, toSide) {+ const { rawCandidates, candidates, outsideRight } = readableAutomaticCandidateSet(+ edge,+ from,+ to,+ start,+ end,+ fromSide,+ toSide,+ );++ if (candidates.length) return candidates[0].points.slice(1, -1);+ const outsideRightCandidate = rawCandidates.find(({ family }) => family === 'outside-right');+ if (outsideRightCandidate) {+ const currentPoints = normalizeRoutePoints([start, ...outsideRightCandidate.via, end]);+ const labelRect = candidateLabelRect(edge, currentPoints);+ let outsideRightMinX = outsideRight;+ for (const node of nodes.values()) {+ if (!labelRect || !rectsOverlap(labelRect, node, -2)) continue;+ const rightwardLabelDeficit = node.x + node.width - 2 - labelRect.x;+ if (rightwardLabelDeficit > 0) {+ outsideRightMinX = Math.max(+ outsideRightMinX,+ outsideRight + rightwardLabelDeficit * 2,+ );+ }+ }+ for (const [otherEdge, routed] of pathCache) {+ const otherIndex = workflow.edges.indexOf(otherEdge);+ const otherLabel = labelRectFor(otherEdge, otherIndex);+ if (labelRect && otherLabel && rectsOverlap(labelRect, otherLabel, -2)) {+ const rightwardLabelDeficit = otherLabel.x + otherLabel.width - 2 - labelRect.x;+ if (rightwardLabelDeficit > 0) {+ outsideRightMinX = Math.max(+ outsideRightMinX,+ outsideRight + rightwardLabelDeficit * 2,+ );+ }+ }+ if (!labelRect) continue;+ for (let index = 0; index < routed.points.length - 1; index += 1) {+ const segment = {+ start: routed.points[index],+ end: routed.points[index + 1],+ };+ const clearance = segmentRectClearance(segment, labelRect);+ if (clearance == null || clearance + 0.0001 >= 4) continue;+ const rightwardLabelDeficit = Math.max(segment.start[0], segment.end[0])+ + 4 - labelRect.x;+ if (rightwardLabelDeficit > 0) {+ outsideRightMinX = Math.max(+ outsideRightMinX,+ outsideRight + rightwardLabelDeficit * 2,+ );+ }+ }+ }+ outsideRightMinX = Math.ceil(outsideRightMinX * 1000) / 1000;+ let rightmostPlacedX = outsideRight;+ for (const node of nodes.values()) {+ rightmostPlacedX = Math.max(rightmostPlacedX, node.x + node.width);+ }+ for (const [otherEdge, routed] of pathCache) {+ for (const [x] of routed.points) rightmostPlacedX = Math.max(rightmostPlacedX, x);+ const otherLabel = labelRectFor(otherEdge, workflow.edges.indexOf(otherEdge));+ if (otherLabel) {+ rightmostPlacedX = Math.max(rightmostPlacedX, otherLabel.x + otherLabel.width);+ }+ }+ let probeGrowth = Math.max(+ 32,+ labelRect?.width ?? 0,+ rightmostPlacedX + 16 - outsideRightMinX,+ );+ let lastInfeasibleX = outsideRight;+ for (let probe = 0; probe < 7; probe += 1) {+ if (outsideRightMinX > outsideRight + 0.0001) {+ const expandedPoints = normalizeRoutePoints([+ start,+ ...corridorViaX(start, end, fromSide, toSide, outsideRightMinX),+ end,+ ]);+ if (readableCandidateIsFeasible(edge, expandedPoints, from, to, fromSide, toSide)) {+ let feasibleX = outsideRightMinX;+ let feasiblePoints = expandedPoints;+ let infeasibleX = lastInfeasibleX;+ for (let refinement = 0;+ refinement < 53 && feasibleX - infeasibleX > 0.001;+ refinement += 1) {+ const midpointX = Math.ceil(((infeasibleX + feasibleX) / 2) * 1000) / 1000;+ if (midpointX >= feasibleX - 0.0001) break;+ const midpointPoints = normalizeRoutePoints([+ start,+ ...corridorViaX(start, end, fromSide, toSide, midpointX),+ end,+ ]);+ if (readableCandidateIsFeasible(+ edge,+ midpointPoints,+ from,+ to,+ fromSide,+ toSide,+ )) {+ feasibleX = midpointX;+ feasiblePoints = midpointPoints;+ } else {+ infeasibleX = midpointX;+ }+ }+ return feasiblePoints.slice(1, -1);+ }+ lastInfeasibleX = outsideRightMinX;+ }+ outsideRightMinX = Math.ceil((outsideRightMinX + probeGrowth) * 1000) / 1000;+ probeGrowth *= 2;+ }+ }+ const hasRelevantAbsolutePin = Array.isArray(edge.labelAt)+ || [...pathCache.keys()].some((otherEdge) => (+ Array.isArray(otherEdge.labelAt) || hasAbsoluteRoutePins(otherEdge)+ ));+ if (hasRelevantAbsolutePin) classifyFailedAutomaticCandidatePins(edge, rawCandidates);+ const horizontallyFacing = (+ fromSide === 'right' && toSide === 'left' && end[0] > start[0]+ ) || (+ fromSide === 'left' && toSide === 'right' && start[0] > end[0]+ );+ if (horizontallyFacing && from.col !== to.col) {+ const fromCol = Math.min(from.col, to.col);+ const toCol = Math.max(from.col, to.col);+ const requiredRankGap = from.width / 2 + 32 + to.width / 2;+ const actualRankGap = layout.colXs[toCol] - layout.colXs[fromCol];+ if (actualRankGap + 0.0001 < requiredRankGap) {+ throw new WorkflowLayoutFeedback({+ kind: 'rank-gap-minimum',+ fromCol,+ toCol,+ minimum: Math.ceil(requiredRankGap * 1000) / 1000,+ edge: edge.id ?? null,+ from: edge.from,+ to: edge.to,+ attemptedCandidateFamilies: rawCandidates.map(({ family }) => family),+ candidateCount: rawCandidates.length,+ });+ }+ }+ if (from.lane !== to.lane && layout.laneGap < 32) {+ throw new WorkflowLayoutFeedback({+ kind: 'lane-gap-minimum',+ minimum: 32,+ edge: edge.id ?? null,+ from: edge.from,+ to: edge.to,+ attemptedCandidateFamilies: rawCandidates.map(({ family }) => family),+ candidateCount: rawCandidates.length,+ });+ }+ const message = `Workflow edge "${workflowEdgeName(edge)}" has no feasible readable-v2 automatic route.`;+ throwDiagnosticError(message, [{+ code: 'workflow/solver-budget-exhausted',+ severity: 'error',+ message,+ subject: {+ diagramType: 'workflow',+ edge: edge.id ?? null,+ from: edge.from,+ to: edge.to,+ },+ evidence: {+ attemptedCandidateFamilies: rawCandidates.map(({ family }) => family),+ candidateCount: rawCandidates.length,+ },+ supportedFixes: [],+ }]);+ }++ function readablePresetVia(edge, from, to, start, end, fromSide, toSide) {+ const preset = edge.route;+ let via;+ switch (preset) {+ case 'straight':+ via = [];+ break;+ case 'drop': {+ const y = gapYBetween(from.lane, to.lane, edge.bias ?? 0.5);+ via = [[start[0], y], [end[0], y]];+ break;+ }+ case 'outside-right': {+ const x = layout.laneX + layout.laneW + 12;+ via = [[x, start[1]], [x, end[1]]];+ break;+ }+ case 'return-left': {+ const x = Math.min(from.x, to.x) - 28;+ via = [[x, start[1]], [x, end[1]]];+ break;+ }+ case 'bottom-channel': {+ const y = Math.max(from.y + from.height, to.y + to.height) + 32;+ via = [[start[0], y], [end[0], y]];+ break;+ }+ case 'up-channel': {+ const y = Math.min(from.y, to.y) - 28;+ via = [[start[0], y], [end[0], y]];+ break;+ }+ default:+ return readableAutomaticVia(edge, from, to, start, end, fromSide, toSide);+ }+ const points = normalizeRoutePoints([start, ...via, end]);+ if (readableCandidateIsFeasible(edge, points, from, to, fromSide, toSide)+ && routeMatchesPresetFamily(preset, points, from, to)) {+ return points.slice(1, -1);+ }+ const message = `Workflow edge "${workflowEdgeName(edge)}" cannot satisfy route preset "${preset}" under readable-v2 constraints (minimum 8px endpoint stubs, 16px interior turns, and 28px direct clearance).`;+ const edgeIndex = workflow.edges.indexOf(edge);+ const edgeName = workflowEdgeName(edge);+ const supportedFixes = [];+ for (const candidatePreset of ['straight', 'drop', 'outside-right', 'return-left', 'bottom-channel', 'up-channel']) {+ if (candidatePreset === preset) continue;+ if (acceptsFix((document) => {+ document.edges[edgeIndex].route = candidatePreset;+ })) {+ supportedFixes.push(`set edge "${edgeName}" route to verified preset "${candidatePreset}"`);+ }+ }+ if (acceptsFix((document) => {+ delete document.edges[edgeIndex].route;+ })) {+ supportedFixes.push(`remove route from edge "${edgeName}" so readable-v2 can use its verified automatic candidate`);+ }+ throwDiagnosticError(message, [{+ code: 'workflow/route-preset-conflict',+ severity: 'error',+ message,+ subject: {+ diagramType: 'workflow',+ edge: edge.id ?? null,+ from: edge.from,+ to: edge.to,+ route: preset,+ },+ evidence: {+ attemptedCandidateFamily: preset,+ points,+ fromSide,+ toSide,+ requiredEndpointStubPx: 8,+ requiredInteriorSegmentPx: 16,+ requiredDirectClearancePx: 28,+ },+ supportedFixes,+ }]);+ }++ function routeVia(+ edge,+ from,+ to,+ start,+ end,+ fromSide,+ toSide,+ { validateReadablePreset = true } = {},+ ) {+ if (edge.via) return edge.via;+ const hasCoordinatePins = edge.channelX !== undefined || edge.channelY !== undefined;+ if (workflow.schema_version === 2+ && edge.route+ && edge.route !== 'auto'+ && !hasCoordinatePins+ && validateReadablePreset) {+ return readablePresetVia(edge, from, to, start, end, fromSide, toSide);+ }+ switch (edge.route || 'auto') {+ case 'straight':+ return [];+ case 'drop': {+ const y = edge.channelY ?? gapYBetween(from.lane, to.lane, edge.bias ?? 0.5);+ return [[start[0], y], [end[0], y]];+ }+ case 'outside-right': {+ const x = edge.channelX ?? layout.laneX + layout.laneW + 12;+ return [[x, start[1]], [x, end[1]]];+ }+ case 'return-left': {+ const x = edge.channelX ?? Math.min(from.x, to.x) - 28;+ return [[x, start[1]], [x, end[1]]];+ }+ case 'bottom-channel': {+ const y = edge.channelY ?? Math.max(from.y + from.height, to.y + to.height) + 32;+ return [[start[0], y], [end[0], y]];+ }+ case 'up-channel': {+ const y = edge.channelY ?? Math.min(from.y, to.y) - 28;+ return [[start[0], y], [end[0], y]];+ }+ case 'auto':+ default: {+ if (workflow.schema_version === 2) {+ if (edge.channelX !== undefined && edge.channelY !== undefined) {+ return [[edge.channelX, start[1]], [edge.channelX, edge.channelY], [end[0], edge.channelY]];+ }+ if (edge.channelX !== undefined) return [[edge.channelX, start[1]], [edge.channelX, end[1]]];+ if (edge.channelY !== undefined) return [[start[0], edge.channelY], [end[0], edge.channelY]];+ return readableAutomaticVia(edge, from, to, start, end, fromSide, toSide);+ }+ if (from.lane === to.lane) return sameLaneAutoVia(start, end);+ const oneBendVia = oneBendCrossLaneVia(edge, start, end, fromSide, toSide);+ if (oneBendVia) return oneBendVia;+ const y = gapYBetween(from.lane, to.lane, edge.bias ?? 0.5);+ return [[start[0], y], [end[0], y]];+ }+ }+ }++ function workflowEdgeLabelPoint(edge, points) {+ if (workflow.schema_version === 1) {+ if (edge.labelAt || Number.isInteger(edge.labelSegment) || points.length !== 3) {+ return labelPoint(edge, points);+ }+ const segmentLengths = [0, 1].map((index) => Math.hypot(+ points[index + 1][0] - points[index][0],+ points[index + 1][1] - points[index][1],+ ));+ const labelSegment = segmentLengths[0] >= segmentLengths[1] ? 0 : 1;+ const point = labelPoint({ ...edge, labelSegment }, points);+ if (points[labelSegment][0] === points[labelSegment + 1][0]) point[1] += 10;+ return point;+ }+ if (edge.labelAt || Number.isInteger(edge.labelSegment) || points.length <= 2) {+ return labelPoint(edge, points);+ }+ const segments = points.slice(0, -1).map((point, index) => ({+ index,+ horizontal: Math.abs(points[index + 1][1] - point[1]) <= 0.0001,+ length: Math.hypot(+ points[index + 1][0] - point[0],+ points[index + 1][1] - point[1],+ ),+ })).sort((left, right) => (+ Number(right.horizontal) - Number(left.horizontal)+ || right.length - left.length+ || left.index - right.index+ ));+ const labelSegment = segments[0]?.index ?? 0;+ const point = labelPoint({ ...edge, labelSegment }, points);+ if (points[labelSegment][0] === points[labelSegment + 1][0]) point[1] += 10;+ return point;+ }++ function edgeSides(edge) {+ const from = nodes.get(edge.from);+ const to = nodes.get(edge.to);+ const resolved = workflow.schema_version === 2 ? readableSideCache.get(edge) : null;+ if (resolved) return resolved;+ const oneBendSides = automaticOneBendSides(edge, from, to);+ if (oneBendSides) return oneBendSides;+ if (workflow.schema_version === 2+ && layout.channelLabelEdgeKeys?.has(stableValueKey(edge))+ && !edge.fromSide+ && !edge.toSide) {+ return { fromSide: 'top', toSide: 'top' };+ }+ return {+ fromSide: chosenSide(edge.fromSide, defaultFromSide(from, to)),+ toSide: chosenSide(edge.toSide, defaultToSide(from, to)),+ };+ }++ const automaticPorts = automaticPortSpread(workflow.edges, nodes, {+ sideFor: (edge, endpoint) => edgeSides(edge)[endpoint === 'source' ? 'fromSide' : 'toSide'],+ });++ function readableAutomaticRoute(edge, from, to, primarySides, primaryPorts) {+ const authoredFrom = edge.fromSide && edge.fromSide !== 'auto' ? edge.fromSide : null;+ const authoredTo = edge.toSide && edge.toSide !== 'auto' ? edge.toSide : null;+ const sideOrder = ['right', 'bottom', 'left', 'top'];+ const sidePairs = [primarySides];+ for (const fromSide of authoredFrom ? [authoredFrom] : sideOrder) {+ for (const toSide of authoredTo ? [authoredTo] : sideOrder) {+ sidePairs.push({ fromSide, toSide });+ }+ }++ const naturalFromSide = authoredFrom || defaultFromSide(from, to);+ const naturalToSide = authoredTo || defaultToSide(from, to);+ const seen = new Set();+ const plans = [];+ const feedback = [];+ let firstFailure = null;+ for (const candidateSides of sidePairs) {+ if (authoredFrom && candidateSides.fromSide !== authoredFrom) continue;+ if (authoredTo && candidateSides.toSide !== authoredTo) continue;+ const key = `${candidateSides.fromSide}:${candidateSides.toSide}`;+ if (seen.has(key)) continue;+ const pairOrdinal = seen.size;+ seen.add(key);+ const primary = pairOrdinal === 0;+ const start = primaryPorts?.from && primary+ ? primaryPorts.from+ : anchor(from, candidateSides.fromSide);+ const end = primaryPorts?.to && primary+ ? primaryPorts.to+ : anchor(to, candidateSides.toSide);+ const planned = readableAutomaticCandidateSet(+ edge,+ from,+ to,+ start,+ end,+ candidateSides.fromSide,+ candidateSides.toSide,+ {+ ordinalOffset: pairOrdinal * 9,+ naturalFromSide,+ naturalToSide,+ },+ );+ plans.push(...planned.candidates.map((candidate) => ({+ ...candidate,+ ...candidateSides,+ })));+ if (planned.candidates.length) continue;+ try {+ const expandedVia = withDiagnosticRecordingSuppressed(() => readableAutomaticVia(+ edge,+ from,+ to,+ start,+ end,+ candidateSides.fromSide,+ candidateSides.toSide,+ ));+ const expandedPoints = normalizeRoutePoints([start, ...expandedVia, end]);+ const outsideRightOrdinal = planned.rawCandidates.findIndex(({ family }) => (+ family === 'outside-right'+ ));+ const ordinal = pairOrdinal * 9 + Math.max(0, outsideRightOrdinal);+ plans.push({+ family: 'outside-right',+ ordinal,+ points: expandedPoints,+ cost: readableCandidateCost(+ edge,+ expandedPoints,+ ordinal,+ naturalFromSide,+ naturalToSide,+ ),+ ...candidateSides,+ });+ } catch (error) {+ if (error instanceof WorkflowLayoutFeedback) {+ feedback.push({ error, pairOrdinal });+ } else if (!firstFailure) {+ firstFailure = error;+ }+ }+ }++ plans.sort((left, right) => compareCost(left.cost, right.cost));+ if (plans.length) {+ const selected = plans[0];+ return {+ points: selected.points,+ fromSide: selected.fromSide,+ toSide: selected.toSide,+ };+ }++ const feedbackPriority = {+ 'rank-gap-minimum': 0,+ 'lane-gap-minimum': 1,+ };+ feedback.sort((left, right) => (+ (feedbackPriority[left.error.request?.kind] ?? 99)+ - (feedbackPriority[right.error.request?.kind] ?? 99)+ || left.pairOrdinal - right.pairOrdinal+ ));+ if (feedback.length) throw feedback[0].error;+ const authoredSideFields = [+ ...(authoredFrom ? ['fromSide'] : []),+ ...(authoredTo ? ['toSide'] : []),+ ];+ if (authoredSideFields.length) {+ const alternatives = verifiedPinRemovalAlternatives(+ edge,+ authoredSideFields,+ 'so readable-v2 can replan the remaining endpoint-side pins',+ );+ const sourceAnchor = primaryPorts?.from || anchor(from, primarySides.fromSide);+ const targetAnchor = primaryPorts?.to || anchor(to, primarySides.toSide);+ const attemptedEvidence = firstFailure?.archifyDiagnostics?.[0]?.evidence || {};+ throwExplicitPinConflict(edge, 'readable route feasibility with authored endpoint sides', {+ conflictingPins: conflictPinsFromRemovalSets(+ edge,+ alternatives.removalSets,+ authoredSideFields,+ ),+ actualCoordinates: {+ sourceAnchor: [...sourceAnchor],+ targetAnchor: [...targetAnchor],+ },+ fromSide: primarySides.fromSide,+ toSide: primarySides.toSide,+ ...(attemptedEvidence.attemptedCandidateFamilies+ ? { attemptedCandidateFamilies: attemptedEvidence.attemptedCandidateFamilies }+ : {}),+ ...(attemptedEvidence.candidateCount !== undefined+ ? { candidateCount: attemptedEvidence.candidateCount }+ : {}),+ }, alternatives.supportedFixes);+ }+ if (firstFailure) throw firstFailure;+ throw new Error('readable-v2 automatic route enumeration produced no result');+ }++ function isReadableControlledRoute(edge) {+ return workflow.schema_version === 2 && (+ Array.isArray(edge.via)+ || edge.channelX !== undefined+ || edge.channelY !== undefined+ || (edge.route && edge.route !== 'auto')+ );+ }++ function readableControlledRoute(edge, from, to) {+ const authoredFrom = edge.fromSide && edge.fromSide !== 'auto' ? edge.fromSide : null;+ const authoredTo = edge.toSide && edge.toSide !== 'auto' ? edge.toSide : null;+ const naturalFromSide = authoredFrom || defaultFromSide(from, to);+ const naturalToSide = authoredTo || defaultToSide(from, to);+ const sideOrder = ['right', 'bottom', 'left', 'top'];+ const preferredPairs = [{+ fromSide: naturalFromSide,+ toSide: naturalToSide,+ }];+ for (const fromSide of authoredFrom ? [authoredFrom] : sideOrder) {+ for (const toSide of authoredTo ? [authoredTo] : sideOrder) {+ preferredPairs.push({ fromSide, toSide });+ }+ }++ const seen = new Set();+ const sidePairs = preferredPairs.filter(({ fromSide, toSide }) => {+ if (authoredFrom && fromSide !== authoredFrom) return false;+ if (authoredTo && toSide !== authoredTo) return false;+ const key = `${fromSide}:${toSide}`;+ if (seen.has(key)) return false;+ seen.add(key);+ return true;+ });+ const hasAbsoluteRoutePins = Array.isArray(edge.via)+ || edge.channelX !== undefined+ || edge.channelY !== undefined;+ const candidates = [];+ const diagnosticCandidates = [];+ const materializedCandidates = [];+ for (const [ordinal, { fromSide, toSide }] of sidePairs.entries()) {+ const start = anchor(from, fromSide);+ const end = anchor(to, toSide);+ const via = routeVia(+ edge,+ from,+ to,+ start,+ end,+ fromSide,+ toSide,+ { validateReadablePreset: false },+ );+ const authoredPoints = [start, ...via, end];+ const points = hasAbsoluteRoutePins+ ? authoredPoints+ : normalizeRoutePoints(authoredPoints);+ const materialized = { points, fromSide, toSide, ordinal };+ materializedCandidates.push(materialized);+ if (points.length >= 2+ && points.every((point) => (+ Array.isArray(point) && point.length === 2 && isFinitePoint(...point)+ ))+ && routeHonorsEndpointSides(points, fromSide, toSide)) {+ diagnosticCandidates.push(materialized);+ }+ if (!readableCandidateIsFeasible(edge, points, from, to, fromSide, toSide)) continue;+ if (edge.route && edge.route !== 'auto' && !routeMatchesPresetFamily(+ edge.route,+ points,+ from,+ to,+ )) continue;+ if (presentChannelPins(edge).some((field) => (+ !routeContainsChannelPin(points, field, edge[field])+ ))) continue;+ candidates.push({+ points,+ fromSide,+ toSide,+ cost: readableCandidateCost(+ edge,+ points,+ ordinal,+ naturalFromSide,+ naturalToSide,+ ),+ });+ }+ candidates.sort((left, right) => compareCost(left.cost, right.cost));+ if (candidates.length) return candidates[0];++ // Absolute geometry is authoritative even when it is invalid. Preserve the+ // best endpoint-side inference so validation can diagnose the authored+ // segment or preset that actually failed instead of silently falling back to+ // default sides and changing the route's meaning.+ if (hasAbsoluteRoutePins) {+ return diagnosticCandidates[0] || materializedCandidates[0] || null;+ }++ // Preset-only routes retain their dedicated typed conflict (and verified+ // alternative search) when exhaustive side inference found no valid plan.+ const fallback = materializedCandidates[0];+ if (!fallback) return null;+ const fallbackVia = readablePresetVia(+ edge,+ from,+ to,+ fallback.points[0],+ fallback.points.at(-1),+ fallback.fromSide,+ fallback.toSide,+ );+ return {+ ...fallback,+ points: normalizeRoutePoints([+ fallback.points[0],+ ...fallbackVia,+ fallback.points.at(-1),+ ]),+ };+ }++ function pathFor(edge) {+ if (pathCache.has(edge)) return pathCache.get(edge);+ const from = nodes.get(edge.from);+ const to = nodes.get(edge.to);+ if (isReadableControlledRoute(edge)) {+ const planned = readableControlledRoute(edge, from, to);+ if (planned) {+ readableSideCache.set(edge, {+ fromSide: planned.fromSide,+ toSide: planned.toSide,+ });+ const routed = { d: polylinePath(planned.points), points: planned.points };+ pathCache.set(edge, routed);+ return routed;+ }+ }+ const ports = automaticPorts.get(edge);+ const { fromSide, toSide } = edgeSides(edge);+ const readableAutomatic = workflow.schema_version === 2+ && !Array.isArray(edge.via)+ && edge.channelX === undefined+ && edge.channelY === undefined+ && (!edge.route || edge.route === 'auto');+ if (readableAutomatic) {+ const planned = readableAutomaticRoute(+ edge,+ from,+ to,+ { fromSide, toSide },+ ports,+ );+ readableSideCache.set(edge, {+ fromSide: planned.fromSide,+ toSide: planned.toSide,+ });+ const routed = { d: polylinePath(planned.points), points: planned.points };+ pathCache.set(edge, routed);+ return routed;+ }+ const start = ports?.from || anchor(from, fromSide);+ const end = ports?.to || anchor(to, toSide);+ const authoredPoints = [start, ...routeVia(edge, from, to, start, end, fromSide, toSide), end];+ const hasAbsoluteRoutePins = Array.isArray(edge.via)+ || edge.channelX !== undefined+ || edge.channelY !== undefined;+ const points = workflow.schema_version === 2 && !hasAbsoluteRoutePins+ ? normalizeRoutePoints(authoredPoints)+ : authoredPoints;+ const routed = { d: polylinePath(points), points };+ pathCache.set(edge, routed);+ return routed;+ }++ function labelRectFor(edge, relationIndex) {+ if (!edge.label || !nodes.has(edge.from) || !nodes.has(edge.to)) return null;+ const [lx, ly] = workflowEdgeLabelPoint(edge, pathFor(edge).points);+ const width = workflowLabelWidth(edge.label);+ return {+ relation: edge,+ relationIndex,+ label: edge.label,+ x: lx - width / 2,+ y: ly - 10,+ width,+ height: 14,+ lx,+ ly,+ };+ }++ function measuredContentBounds() {+ let left = layout.laneX;+ let top = 27;+ let right = layout.laneX + layout.laneW;+ let bottom = legendY() + 18;+ const owners = {+ left: 'workflow lanes',+ top: asArray(workflow.phases).length ? 'phase header band' : 'workflow top padding',+ right: 'workflow lanes',+ bottom: workflowLegendEntries.length ? 'legend' : 'workflow lanes and bottom padding',+ };+ const includePoint = ([x, y], contributor) => {+ if (x < left) {+ left = x;+ owners.left = contributor;+ }+ if (y < top) {+ top = y;+ owners.top = contributor;+ }+ if (x > right) {+ right = x;+ owners.right = contributor;+ }+ if (y > bottom) {+ bottom = y;+ owners.bottom = contributor;+ }+ };+ const includeRect = (rect, contributor) => {+ includePoint([rect.x, rect.y], contributor);+ includePoint([rect.x + rect.width, rect.y + rect.height], contributor);+ };++ for (const node of nodes.values()) includeRect(node, `node ${node.id}`);+ for (const [index, edge] of workflow.edges.entries()) {+ if (!nodes.has(edge.from) || !nodes.has(edge.to)) continue;+ for (const point of pathFor(edge).points) includePoint(point, `edge ${edge.id || index}`);+ const label = labelRectFor(edge, index);+ if (label) includeRect(label, `edge ${edge.id || index} label mask`);+ }+ for (const phase of asArray(workflow.phases)) {+ if (!Number.isInteger(phase.fromCol) || !Number.isInteger(phase.toCol)+ || phase.fromCol < 0 || phase.toCol >= layout.colXs.length || phase.fromCol > phase.toCol) continue;+ const span = phaseSpan(phase);+ includeRect({ x: span.x, y: 27, width: span.width, height: 16 }, `phase ${phase.id}`);+ }+ for (const group of asArray(workflow.groups)) {+ if (!laneIndex.has(group.lane) || !Number.isInteger(group.fromCol) || !Number.isInteger(group.toCol)+ || group.fromCol < 0 || group.toCol >= layout.colXs.length || group.fromCol > group.toCol) continue;+ const span = groupSpan(group);+ includeRect({+ x: span.x,+ y: laneTop(group.lane) + layout.laneTitleH + GROUP_FRAME_TOP_INSET,+ width: span.width,+ height: workflow.schema_version === 2+ ? laneHeight(group.lane) - layout.laneTitleH+ - GROUP_FRAME_TOP_INSET - GROUP_FRAME_BOTTOM_INSET+ : layout.laneH - layout.laneTitleH - 16,+ }, `group ${group.id}`);+ if (workflow.schema_version === 2) {+ const frameY = laneTop(group.lane) + layout.laneTitleH + GROUP_FRAME_TOP_INSET;+ const labelBaseline = frameY + GROUP_LABEL_BASELINE_OFFSET;+ includeRect({+ x: span.x + 10,+ y: labelBaseline - GROUP_LABEL_MASK_ASCENT,+ width: textUnits(group.label) * 5.6,+ height: GROUP_LABEL_MASK_H,+ }, `group ${group.id} label`);+ }+ }+ if (workflowLegendEntries.length) {+ for (const rect of workflowLegendRects()) includeRect(rect, `legend ${rect.kind}`);+ }+ return {+ left,+ top,+ right,+ bottom,+ contributors: [...new Set([+ ...Object.values(owners),+ ...asArray(layout.widthContributors),+ ...asArray(layout.heightContributors),+ ])],+ };+ }++ function finalizeReadableViewBox() {+ if (workflow.schema_version !== 2) {+ requiredViewBox = [...viewBox];+ return;+ }+ const bounds = measuredContentBounds();+ requiredViewBox = [+ Math.max(minimumCanvasWidth, Math.ceil(bounds.right + 16)),+ Math.max(autoHeight, Math.ceil(bounds.bottom + 18)),+ ];+ const outsideOrigin = bounds.left < 0 || bounds.top < 0;+ if (outsideOrigin) {+ const hasAbsolutePins = workflow.edges.some((edge) => (+ Array.isArray(edge.via)+ || Array.isArray(edge.labelAt)+ || edge.channelX !== undefined+ || edge.channelY !== undefined+ ));+ const message = `Workflow geometry extends above or left of the viewBox origin (${Math.round(bounds.left)}, ${Math.round(bounds.top)}).`;+ throwDiagnosticError(message, [{+ code: hasAbsolutePins ? 'workflow/explicit-pin-conflict' : 'workflow/solver-budget-exhausted',+ severity: 'error',+ message,+ subject: { diagramType: 'workflow', path: '/meta/viewBox' },+ evidence: {+ actualViewBox: [...viewBox],+ requiredViewBox: [...requiredViewBox],+ contentBounds: [bounds.left, bounds.top, bounds.right, bounds.bottom],+ contributors: bounds.contributors,+ },+ supportedFixes: [],+ }]);+ }+ if (!workflow.meta?.viewBox) {+ viewBox = [...requiredViewBox];+ return;+ }+ const tooNarrow = viewBox[0] < requiredViewBox[0];+ const tooShort = viewBox[1] < requiredViewBox[1];+ if (!tooNarrow && !tooShort) return;+ const message = `Workflow viewBox ${viewBox[0]}×${viewBox[1]} cannot contain the readable-v2 layout; minimum ${requiredViewBox[0]}×${requiredViewBox[1]}.`;+ const supportedFixes = [];+ if (acceptsFix((document) => {+ document.meta.viewBox = [...requiredViewBox];+ })) {+ supportedFixes.push(`set meta.viewBox to at least [${requiredViewBox[0]}, ${requiredViewBox[1]}]`);+ }+ if (acceptsFix((document) => {+ delete document.meta.viewBox;+ })) {+ supportedFixes.push('omit meta.viewBox so the compiler can use its measured intrinsic canvas');+ }+ throwDiagnosticError(message, [{+ code: 'workflow/viewbox-capacity',+ severity: 'error',+ message,+ subject: { diagramType: 'workflow', path: '/meta/viewBox' },+ evidence: {+ actualViewBox: [...viewBox],+ requiredViewBox: [...requiredViewBox],+ contentBounds: [bounds.left, bounds.top, bounds.right, bounds.bottom],+ contributors: bounds.contributors,+ },+ supportedFixes,+ }]);+ }++ function renderLane(lane, index) {+ const y = laneTop(lane.id);+ const height = laneHeight(index);+ const exception = lane.variant === 'exception'+ ? `\n <rect data-graph-role="structural-frame" data-composition-frame-kind="exception-lane" data-composition-frame-id="lane-${index}-exception" x="${layout.laneX + 6}" y="${y + 6}" width="${layout.laneW - 12}" height="${height - 12}" rx="8" class="c-security-group" stroke-width="1"/>`+ : '';+ const labelClass = lane.variant === 'exception' ? 't-security' : 't-dim';+ const prefix = lane.variant === 'exception' ? 'EX' : String(index + 1).padStart(2, '0');+ return ` <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-${index}" x="${layout.laneX}" y="${y}" width="${layout.laneW}" height="${height}" rx="10" class="c-lane" stroke-width="1"/>${exception}+ <text x="${layout.laneX + 14}" y="${y + 22}" class="${labelClass}" font-size="10" font-weight="600">${prefix} / ${esc(lane.label)}</text>`;+ }++ function renderPhase(phase) {+ const span = phaseSpan(phase);+ const accent = variantAccent(phase.variant);+ const [lineClass] = arrowClassMap[phase.variant || 'default'] || arrowClassMap.default;+ return ` <line x1="${span.x}" y1="35" x2="${span.x + span.width}" y2="35" class="${lineClass}" stroke-width="1.1"/>+ <rect x="${span.x}" y="27" width="${span.width}" height="16" rx="4" class="c-mask"/>+ <text x="${span.cx}" y="39" class="${accent}" font-size="8" font-weight="600" text-anchor="middle">${esc(phase.label)}</text>`;+ }++ function renderGroup(group, index) {+ const span = groupSpan(group);+ const y = laneTop(group.lane) + layout.laneTitleH + GROUP_FRAME_TOP_INSET;+ const height = workflow.schema_version === 2+ ? laneHeight(group.lane) - layout.laneTitleH+ - GROUP_FRAME_TOP_INSET - GROUP_FRAME_BOTTOM_INSET+ : layout.laneH - layout.laneTitleH - 16;+ const cls = group.variant === 'security' ? 'c-security-group' : 'c-lane';+ const textClass = variantAccent(group.variant);+ const labelY = workflow.schema_version === 2 ? y + GROUP_LABEL_BASELINE_OFFSET : y + 14;+ return ` <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-${index}" x="${span.x}" y="${y}" width="${span.width}" height="${height}" rx="9" class="${cls}" stroke-width="1"/>+ <text x="${span.x + 10}" y="${labelY}" class="${textClass}" font-size="7" font-weight="600">${esc(group.label)}</text>`;+ }++ function renderNode(node) {+ const fill = componentFill[node.type] || 'c-external';+ const accent = componentText[node.type] || 't-muted';+ const hasSub = node.sublabel != null && node.sublabel !== '';+ const labelFontSize = fittedNodeFontSize(node.label, brandLabelFitWidth(node, node.width), nodeTextFit.labelPreferred, nodeTextFit.labelMinimum);+ const sublabelFontSize = hasSub+ ? fittedNodeFontSize(node.sublabel, node.width, nodeTextFit.sublabelPreferred, nodeTextFit.sublabelMinimum)+ : nodeTextFit.sublabelPreferred;+ const sub = hasSub+ ? `\n <text data-detail="context" x="${node.cx}" y="${node.y + 38}" class="t-muted" font-size="${sublabelFontSize}" text-anchor="middle">${esc(node.sublabel)}</text>`+ : '';+ const tag = node.tag+ ? `\n <text data-detail="fine" x="${node.cx}" y="${node.y + node.height - 12}" class="${accent}" font-size="${fittedNodeFontSize(node.tag, node.width, nodeTextFit.tagPreferred, nodeTextFit.tagMinimum)}" text-anchor="middle">${esc(node.tag)}</text>`+ : '';+ const brand = renderBrandMark(node, { x: node.x + node.width - 22, y: node.y + 6 });+ const passport = { kind: node.type, sublabel: node.sublabel, tag: node.tag, context: nodeContext(node), ...brandMetadataFor(node) };+ return ` <g ${focusNodeAttrs(node.id, node.label, passport, workflow.meta.locale)}>+ ${focusNodeTitle(node.label, passport)}+ <rect x="${node.x}" y="${node.y}" width="${node.width}" height="${node.height}" rx="6" class="c-mask"/>+ <rect x="${node.x}" y="${node.y}" width="${node.width}" height="${node.height}" rx="6" class="${fill}"${animateAttr(workflow.meta, 'node', nodeStep(node))} stroke-width="1.5"/>+ ${renderSemanticSigil(node.type, { x: node.x + 6, y: node.y + 6 })}${brand ? `\n ${brand}` : ''}+ <text data-node-label=""${hasSub ? ' data-detail-anchor=""' : ''} x="${node.cx}" y="${node.y + 21}" class="t-primary" font-size="${labelFontSize}" font-weight="600" text-anchor="middle">${esc(node.label)}</text>${sub}${tag}+ </g>`;+ }++ function renderEdgePath(edge, index) {+ const [cls, marker] = arrowClassMap[edge.variant || 'default'] || arrowClassMap.default;+ const routed = pathFor(edge);+ const strokeWidth = edge.width || (edge.variant === 'emphasis' ? 1.8 : 1.4);+ return ` <path ${focusEdgeAttrs(edge.from, edge.to, edge.label, index, edge.id)} data-composition-points="${routePointsValue(routed.points)}" d="${routed.d}" class="${cls}"${animateAttr(workflow.meta, 'edge', edgeSteps.get(edge))} stroke-width="${strokeWidth}" marker-end="url(#${marker})"/>`;+ }++ function renderEdgeLabel(edge, index) {+ if (!edge.label) return '';+ const routed = pathFor(edge);+ const [lx, ly] = workflowEdgeLabelPoint(edge, routed.points);+ const labelW = workflowLabelWidth(edge.label);+ return ` <g data-detail="context" ${focusEdgeAttrs(edge.from, edge.to, edge.label, index, edge.id)}>+ <rect x="${lx - labelW / 2}" y="${ly - 10}" width="${labelW}" height="14" rx="3" class="c-mask"/>- <text x="${lx}" y="${ly}" class="${variantAccent(edge.variant, { dashed: 't-database' })}" font-size="8" text-anchor="middle">${esc(edge.label)}</text>++ <text x="${lx}" y="${ly}" class="${variantAccent(edge.variant)}" font-size="8" text-anchor="middle">${esc(edge.label)}</text>+ </g>`;+ }++ function renderLegend() {+ const obstacles = workflow.schema_version === 2+ ? relationshipLegendObstacles(workflow.edges, {+ pointsFor: (edge) => pathFor(edge).points,+ labelRectFor,+ })+ : [];+ return renderResolvedLegend({+ entries: workflowLegendEntries,+ locale: workflow.meta.locale,+ layout: workflowLegendLayout(obstacles),+ renderSwatch: (entry) => `<rect x="${entry.x}" y="${entry.baseline - 8}" width="14" height="9" rx="2" class="${componentFill[entry.kind] || 'c-external'}" stroke-width="1"/>`,+ });+ }++ function renderSvg() {+ return ` <svg viewBox="0 0 ${viewBox[0]} ${viewBox[1]}" ${svgRootAttrs(workflow.meta, 'workflow diagram')}>+ ${svgAccessibleText(workflow.meta, 'workflow')}+ ${renderDefinitions()}++ <!-- Background Grid -->+ <rect width="100%" height="100%" fill="url(#grid)" />++ <!-- Swimlanes -->+ ${workflow.lanes.map(renderLane).join('\n\n')}++ <!-- Phase headers -->+ ${asArray(workflow.phases).map(renderPhase).join('\n')}++ <!-- Workflow groups -->+ ${asArray(workflow.groups).map(renderGroup).join('\n')}++ <!-- Edge paths -->+ ${workflow.edges.map(renderEdgePath).join('\n')}++ <!-- Nodes -->+ ${[...nodes.values()].map(renderNode).join('\n\n')}++ <!-- Edge labels -->+ ${workflow.edges.map(renderEdgeLabel).join('\n')}++ <!-- Legend -->+ ${renderLegend()}+ </svg>`;+ }+++ try {+ validateReadableInputsBeforeRouting();+ validateReadablePinnedGeometry();+ validateWorkflow();+ finalizeReadableViewBox();+ const svg = renderSvg();+ const receipt = {+ contract: layout.contract,+ viewBox: [...viewBox],+ requiredViewBox: [...requiredViewBox],+ columns: [...layout.colXs],+ nodes: [...nodes.values()].map((node) => ({+ id: node.id,+ lane: node.lane,+ col: node.col,+ x: node.x,+ y: node.y,+ width: node.width,+ height: node.height,+ })),+ edges: workflow.edges.map((edge) => ({+ id: edge.id ?? null,+ from: edge.from,+ to: edge.to,+ points: pathFor(edge).points.map((point) => [...point]),+ })),+ labels: workflow.edges.flatMap((edge) => {+ if (!edge.label || !nodes.has(edge.from) || !nodes.has(edge.to)) return [];+ const [x, y] = workflowEdgeLabelPoint(edge, pathFor(edge).points);+ return [{ edge: edge.id ?? null, label: edge.label, x, y, width: workflowLabelWidth(edge.label), height: 14 }];+ }),+ diagnostics: [],+ };+ return { ok: true, svg, receipt };+ } catch (error) {+ if (!Array.isArray(error?.archifyDiagnostics)) throw error;+ const diagnostics = error.archifyDiagnostics.map((diagnostic) => ({ ...diagnostic }));+ return compilerFailure(layout.contract, diagnostics, error.message);+ }+ }++ function feedbackFailure(request) {+ const message = `Workflow edge "${request.edge || `${request.from}->${request.to}`}" exhausted bounded readable-v2 layout feedback without a feasible automatic route.`;+ const diagnostics = [{+ code: 'workflow/solver-budget-exhausted',+ severity: 'error',+ message,+ subject: {+ diagramType: 'workflow',+ edge: request.edge,+ from: request.from,+ to: request.to,+ },+ evidence: {+ attemptedCandidateFamilies: request.attemptedCandidateFamilies,+ candidateCount: request.candidateCount,+ },+ supportedFixes: [],+ }];+ return compilerFailure('readable-v2', diagnostics, message);+ }++ function compileWorkflowWithFeedback({ workflow, qualityProfile, discoverFixes = true } = {}) {+ let layoutFeedback = {};+ for (let attempt = 0; attempt <= MAX_READABLE_LAYOUT_FEEDBACK_ROUNDS; attempt += 1) {+ try {+ return compileWorkflowInternal({+ workflow,+ qualityProfile,+ discoverFixes,+ layoutFeedback,+ });+ } catch (error) {+ if (!(error instanceof WorkflowLayoutFeedback)) throw error;+ const request = error.request;+ let nextFeedback = null;+ if (request.kind === 'rank-gap-minimum'+ && Number.isInteger(request.fromCol)+ && Number.isInteger(request.toCol)+ && Number.isFinite(request.minimum)) {+ const key = `${request.fromCol}:${request.toCol}`;+ const current = layoutFeedback.rankGapMinimums?.[key] ?? -Infinity;+ if (request.minimum > current + 0.0001) {+ nextFeedback = {+ ...layoutFeedback,+ rankGapMinimums: {+ ...(layoutFeedback.rankGapMinimums || {}),+ [key]: request.minimum,+ },+ rankGapContributors: {+ ...(layoutFeedback.rankGapContributors || {}),+ [key]: [+ `rank ${request.fromCol}→${request.toCol} route clearance`,+ `edge ${request.edge || `${request.from}->${request.to}`} route`,+ ],+ },+ };+ }+ } else if (request.kind === 'lane-gap-minimum'+ && Number.isFinite(request.minimum)+ && request.minimum > (layoutFeedback.laneGapMin ?? -Infinity) + 0.0001) {+ nextFeedback = {+ ...layoutFeedback,+ laneGapMin: request.minimum,+ laneGapContributors: [+ `edge ${request.edge || `${request.from}->${request.to}`} lane-gap route clearance`,+ ],+ };+ }+ if (!nextFeedback || attempt === MAX_READABLE_LAYOUT_FEEDBACK_ROUNDS) {+ return feedbackFailure(request);+ }+ layoutFeedback = nextFeedback;+ }+ }+ throw new Error('unreachable readable-v2 layout feedback state');+ }++ export function compileWorkflow({ workflow, qualityProfile } = {}) {+ return compileWorkflowWithFeedback({ workflow, qualityProfile });+ }diff --cc archify/test/workflow-compiler.test.mjsindex 00000000,5266aaa1..9d077a03mode 000000,100644..100644--- a/archify/test/workflow-compiler.test.mjs+++ b/archify/test/workflow-compiler.test.mjs@@@ -1,0 -1,1163 +1,1163 @@@+ import { test } from 'node:test';+ import assert from 'node:assert/strict';+ import { spawnSync } from 'node:child_process';+ import { createHash } from 'node:crypto';+ import fs from 'node:fs';+ import os from 'node:os';+ import path from 'node:path';+ import { fileURLToPath } from 'node:url';++ import { compileWorkflow } from '../renderers/workflow/workflow-compiler.mjs';++ const __dirname = path.dirname(fileURLToPath(import.meta.url));+ const skillRoot = path.resolve(__dirname, '..');+ const cli = path.join(skillRoot, 'bin', 'archify.mjs');+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-workflow-compiler-'));++ function readJson(file) {+ return JSON.parse(fs.readFileSync(file, 'utf8'));+ }++ function clone(value) {+ return JSON.parse(JSON.stringify(value));+ }++ function sha256(value) {+ return createHash('sha256').update(value).digest('hex');+ }++ function attribute(tag, name) {+ const value = tag.match(new RegExp(`\\b${name}="([^"]*)"`))?.[1];+ assert.notEqual(value, undefined, `expected ${name} in ${tag}`);+ return value;+ }++ function numericRect(attributes) {+ return Object.fromEntries(['x', 'y', 'width', 'height'].map((name) => [+ name,+ Number(attribute(attributes, name)),+ ]));+ }++ function nodeRect(svg, id) {+ const escapedId = id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');+ const attributes = svg.match(new RegExp(+ `<g\\b[^>]*id="node-${escapedId}"[^>]*>[\\s\\S]*?<rect\\b([^>]*)>`,+ ))?.[1];+ assert.ok(attributes, `expected rendered node ${id}`);+ return numericRect(attributes);+ }++ function edgePoints(svg, id) {+ const tag = (svg.match(/<path\b[^>]*>/g) || []).find((candidate) => (+ attributeOrUndefined(candidate, 'data-edge-id') === id+ ));+ assert.ok(tag, `expected rendered edge ${id}`);+ return attribute(tag, 'data-composition-points')+ .split(';')+ .map((point) => point.split(',').map(Number));+ }++ function edgeLabelRect(svg, id) {+ const escapedId = id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');+ const attributes = svg.match(new RegExp(+ `<g\\b(?=[^>]*data-edge-id="${escapedId}")(?=[^>]*data-edge-label=)[^>]*>[\\s\\S]*?<rect\\b([^>]*)>`,+ ))?.[1];+ assert.ok(attributes, `expected rendered label mask for edge ${id}`);+ return numericRect(attributes);+ }++ function attributeOrUndefined(tag, name) {+ return tag.match(new RegExp(`\\b${name}="([^"]*)"`))?.[1];+ }++ function svgViewBox(svg) {+ const tag = svg.match(/<svg\b[^>]*>/)?.[0];+ assert.ok(tag, 'expected an SVG root');+ return attribute(tag, 'viewBox').split(/\s+/).map(Number);+ }++ function legendGeometry(svg) {+ return svg.match(/<g data-legend-semantic-kind="[^"]+"[^>]*>/g) || [];+ }++ function assertRectInsideViewBox(rect, viewBox, message) {+ const [minX, minY, width, height] = viewBox;+ assert.ok(rect.x >= minX, `${message}: left edge ${rect.x} is outside ${minX}`);+ assert.ok(rect.y >= minY, `${message}: top edge ${rect.y} is outside ${minY}`);+ assert.ok(+ rect.x + rect.width <= minX + width,+ `${message}: right edge ${rect.x + rect.width} is outside ${minX + width}`,+ );+ assert.ok(+ rect.y + rect.height <= minY + height,+ `${message}: bottom edge ${rect.y + rect.height} is outside ${minY + height}`,+ );+ }++ function assertRectInsideRect(rect, container, message) {+ assert.ok(rect.x >= container.x, `${message}: left edge ${rect.x} is outside ${container.x}`);+ assert.ok(rect.y >= container.y, `${message}: top edge ${rect.y} is outside ${container.y}`);+ assert.ok(+ rect.x + rect.width <= container.x + container.width,+ `${message}: right edge ${rect.x + rect.width} is outside ${container.x + container.width}`,+ );+ assert.ok(+ rect.y + rect.height <= container.y + container.height,+ `${message}: bottom edge ${rect.y + rect.height} is outside ${container.y + container.height}`,+ );+ }++ function groupFrameRect(svg, index = 0) {+ const attributes = svg.match(new RegExp(+ `<rect\\b(?=[^>]*data-composition-frame-kind="group")(?=[^>]*data-composition-frame-id="group-${index}")([^>]*)/>`,+ ))?.[1];+ assert.ok(attributes, `expected rendered group frame ${index}`);+ return numericRect(attributes);+ }++ function asciiGroupLabelTextRect(svg, label) {+ const escapedLabel = label.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');+ const attributes = svg.match(new RegExp(`<text\\b([^>]*)>${escapedLabel}</text>`))?.[1];+ assert.ok(attributes, `expected rendered group label ${label}`);+ return {+ x: Number(attribute(attributes, 'x')),+ y: Number(attribute(attributes, 'y')) - 10,+ width: Array.from(label).length * 5.6,+ height: 14,+ };+ }++ function rectsOverlap(left, right) {+ return !(+ left.x + left.width <= right.x+ || right.x + right.width <= left.x+ || left.y + left.height <= right.y+ || right.y + right.height <= left.y+ );+ }++ function orthogonalSegmentIntersectsRect(start, end, rect) {+ const left = rect.x;+ const right = rect.x + rect.width;+ const top = rect.y;+ const bottom = rect.y + rect.height;+ if (start[1] === end[1]) {+ return start[1] >= top && start[1] <= bottom+ && Math.max(start[0], end[0]) >= left+ && Math.min(start[0], end[0]) <= right;+ }+ if (start[0] === end[0]) {+ return start[0] >= left && start[0] <= right+ && Math.max(start[1], end[1]) >= top+ && Math.min(start[1], end[1]) <= bottom;+ }+ throw new Error(`expected an orthogonal route segment: ${JSON.stringify([start, end])}`);+ }++ function asciiLaneHeaderTextRect(label, { laneTop = 52, laneIndex = 0 } = {}) {+ const prefix = String(laneIndex + 1).padStart(2, '0');+ return {+ x: 54,+ y: laneTop + 12,+ width: Array.from(`${prefix} / ${label}`).length * 6.2,+ height: 14,+ };+ }++ function compileSuccessfully(workflow, qualityProfile) {+ const request = qualityProfile === undefined+ ? { workflow }+ : { workflow, qualityProfile };+ const result = compileWorkflow(request);+ assert.equal(+ result.ok,+ true,+ `expected workflow compilation to succeed:\n${JSON.stringify(result.diagnostics, null, 2)}`,+ );+ assert.equal(typeof result.svg, 'string');+ assert.match(result.svg, /^\s*<svg\b/, 'compiler should return one canonical renderer SVG');+ assert.ok(result.receipt);+ assert.deepEqual(result.receipt.diagnostics, []);+ return result;+ }++ function adjacentWorkflow({+ fromCol = 1,+ toCol = fromCol + 1,+ label,+ widths = [92, 92],+ nodeLabels = ['A', 'B'],+ viewBox,+ frames = false,+ } = {}) {+ const workflow = {+ schema_version: 2,+ diagram_type: 'workflow',+ meta: {+ title: `Adjacent ranks ${fromCol} to ${toCol}`,+ legend: { mode: 'hidden' },+ ...(viewBox ? { viewBox } : {}),+ },+ lanes: [{ id: 'main', label: 'Main' }],+ nodes: [+ {+ id: 'a', lane: 'main', col: fromCol, type: 'backend', label: nodeLabels[0], width: widths[0],+ },+ {+ id: 'b', lane: 'main', col: toCol, type: 'backend', label: nodeLabels[1], width: widths[1],+ },+ ],+ edges: [{ id: 'ab', from: 'a', to: 'b', ...(label ? { label } : {}) }],+ };+ if (frames) {+ workflow.phases = [{+ id: 'phase', label: 'P', fromCol, toCol,+ }];+ workflow.groups = [{+ id: 'group', label: 'G', lane: 'main', fromCol, toCol,+ }];+ }+ return workflow;+ }++ function assertReadableAdjacentResult(result, { label, widths = [92, 92] } = {}) {+ assert.equal(result.receipt.contract, 'readable-v2');+ assert.deepEqual(result.receipt.viewBox, svgViewBox(result.svg).slice(2));+ assert.ok(Array.isArray(result.receipt.requiredViewBox));+ assert.equal(result.receipt.columns.length, 6);+ assert.ok(result.receipt.columns.every(Number.isFinite));+ for (let index = 1; index < result.receipt.columns.length; index += 1) {+ assert.ok(+ result.receipt.columns[index] > result.receipt.columns[index - 1],+ `column ${index} must be strictly after column ${index - 1}`,+ );+ }++ const source = nodeRect(result.svg, 'a');+ const target = nodeRect(result.svg, 'b');+ assert.equal(source.width, widths[0]);+ assert.equal(target.width, widths[1]);+ assert.ok(source.x + source.width <= target.x, 'same-lane nodes must not overlap');++ const points = edgePoints(result.svg, 'ab');+ assert.deepEqual(points.length, 2, `adjacent facing nodes should use a direct route: ${JSON.stringify(points)}`);+ assert.equal(points[0][0], source.x + source.width, 'edge must leave the source right side');+ assert.equal(points[1][0], target.x, 'edge must enter the target left side');+ assert.equal(points[0][1], points[1][1], 'direct route must be horizontal');+ const directClearance = points[1][0] - points[0][0];+ assert.ok(directClearance >= 28, `direct clearance ${directClearance}px must be at least 28px`);++ if (label) {+ const mask = edgeLabelRect(result.svg, 'ab');+ assert.ok(+ directClearance + 1e-9 >= mask.width + 8,+ `labeled direct clearance ${directClearance}px must fit ${mask.width}px mask plus 8px breathing room`,+ );+ assertRectInsideViewBox(mask, svgViewBox(result.svg), 'edge label mask');+ }+ }++ test('fixed-v1 compiler preserves the official workflow baseline SVG byte-for-byte', () => {+ const workflow = readJson(path.join(__dirname, 'fixtures', 'v1-baseline', 'agent-tool-call.workflow.json'));+ const result = compileSuccessfully(workflow);+ assert.equal(result.receipt.contract, 'fixed-v1');+ assert.equal(+ sha256(result.svg),- '4e493db1977889675ce7b04bf9ba60fb97cb50f01fc0fd9e8446861282c65645',++ '8147f7ff3e41c4aa968cea637645c85ec51ca0160503828a973b620dc62e3aaa',+ );+ });++ test('fixed-v1 compiler preserves the exact 700x400 compatibility geometry', () => {+ const workflow = readJson(path.join(+ __dirname,+ 'fixtures',+ 'v1-workflow-700x400.workflow.json',+ ));++ const result = compileSuccessfully(workflow);+ assert.equal(result.receipt.contract, 'fixed-v1');+ assert.deepEqual(result.receipt.viewBox, [700, 400]);+ assert.deepEqual(svgViewBox(result.svg), [0, 0, 700, 400]);+ assert.equal(+ sha256(result.svg),+ '28b0167460d16c55ae6bf38bde41368248671a78b3a49133da05ed1efb4354af',+ 'the v1 compiler extraction must not move or reserialize legacy geometry',+ );+ });++ test('fixed-v1 keeps valid phase and group spans independent of label measurement', () => {+ const workflow = {+ schema_version: 1,+ diagram_type: 'workflow',+ meta: { title: 'Fixed v1 frame geometry', legend: { mode: 'hidden' } },+ lanes: [{ id: 'main', label: 'Main' }],+ phases: [{ id: 'phase', label: 'P'.repeat(17), fromCol: 0, toCol: 0 }],+ groups: [{+ id: 'group', label: 'G'.repeat(30), lane: 'main', fromCol: 0, toCol: 0,+ }],+ nodes: [{ id: 'a', lane: 'main', col: 0, type: 'backend', label: 'A' }],+ edges: [],+ };++ const result = compileSuccessfully(workflow);+ assert.match(+ result.svg,+ /<line x1="42" y1="35" x2="134" y2="35"/,+ 'v1 phase spans must retain the legacy fixed 46px padding',+ );+ assert.match(+ result.svg,+ /data-composition-frame-kind="group"[^>]* x="38" y="90" width="100"/,+ 'v1 group spans must retain the legacy fixed 50px padding',+ );+ });++ test('fixed-v1 reports one causal column-capacity diagnostic for issue #126', () => {+ const workflow = {+ schema_version: 1,+ diagram_type: 'workflow',+ meta: { title: 'Issue 126 causal diagnostic', legend: { mode: 'hidden' } },+ lanes: [{ id: 'main', label: 'Main' }],+ nodes: [+ { id: 'a', lane: 'main', col: 1, type: 'backend', label: 'A' },+ { id: 'b', lane: 'main', col: 2, type: 'backend', label: 'B' },+ ],+ edges: [{ id: 'ab', from: 'a', to: 'b', label: 'liga' }],+ };++ const result = compileWorkflow({ workflow, qualityProfile: 'showcase' });+ assert.equal(result.ok, false);+ assert.equal(result.diagnostics.length, 1, JSON.stringify(result.diagnostics, null, 2));+ assert.deepEqual(result.receipt.diagnostics, result.diagnostics);++ const [diagnostic] = result.diagnostics;+ assert.equal(diagnostic.code, 'workflow/column-capacity');+ assert.equal(diagnostic.subject.edge, 'ab');+ assert.equal(diagnostic.subject.from, 'a');+ assert.equal(diagnostic.subject.to, 'b');+ assert.equal(diagnostic.subject.fromCol, 1);+ assert.equal(diagnostic.subject.toCol, 2);+ assert.deepEqual(diagnostic.evidence, {+ centerDistancePx: 80,+ nodeWidthsPx: [92, 92],+ actualSignedClearancePx: -12,+ requiredDirectClearancePx: 28,+ });+ assert.deepEqual(diagnostic.suppresses, [+ 'workflow/short-edge',+ 'clean-flow/endpoint-side-direction',+ 'workflow/label-node-overlap',+ ]);+ assert.ok(diagnostic.supportedFixes.some((fix) => /schema_version 2/.test(fix)));+ assert.ok(diagnostic.supportedFixes.some((fix) => /column 3/.test(fix)));+ assert.ok(diagnostic.supportedFixes.some((fix) => /width/i.test(fix)));+ assert.doesNotMatch(+ diagnostic.supportedFixes.join('\n'),+ /drop|remove|omit|unlabel|channel/i,+ 'a causal overlap diagnostic must not propose a label or routing non-fix',+ );+ });++ test('fixed-v1 verifies the real coordinate migration before advertising it', () => {+ const workflow = {+ schema_version: 1,+ diagram_type: 'workflow',+ meta: {+ title: 'Pinned issue 126 migration',+ viewBox: [720, 400],+ legend: { mode: 'hidden' },+ },+ lanes: [{ id: 'main', label: 'Main' }],+ nodes: [+ { id: 'a', lane: 'main', col: 1, type: 'backend', label: 'A' },+ { id: 'b', lane: 'main', col: 2, type: 'backend', label: 'B' },+ ],+ edges: [{+ id: 'ab',+ from: 'a',+ to: 'b',+ fromSide: 'top',+ toSide: 'top',+ via: [[220, 60], [300, 60]],+ }],+ };++ const result = compileWorkflow({ workflow, qualityProfile: 'showcase' });+ assert.equal(result.ok, false);+ assert.equal(result.diagnostics[0].code, 'workflow/column-capacity');+ assert.ok(+ result.diagnostics[0].supportedFixes.includes('migrate this workflow to schema_version 2'),+ JSON.stringify(result.diagnostics[0], null, 2),+ );+ });++ test('readable-v2 supports every adjacent rank with and without a semantic label', () => {+ for (const qualityProfile of ['standard', 'showcase']) {+ for (let fromCol = 0; fromCol < 5; fromCol += 1) {+ for (const label of [undefined, 'liga']) {+ const result = compileSuccessfully(adjacentWorkflow({ fromCol, label }), qualityProfile);+ assertReadableAdjacentResult(result, { label });+ }+ }+ }+ });++ test('readable-v2 satisfies the complete adjacent-rank acceptance matrix', () => {+ let cases = 0;+ for (const qualityProfile of ['standard', 'showcase']) {+ for (let fromCol = 0; fromCol < 5; fromCol += 1) {+ for (const label of [undefined, 'liga']) {+ for (const frames of [false, true]) {+ for (const width of [900, 1080, 1400, 1600]) {+ const result = compileSuccessfully(adjacentWorkflow({+ fromCol,+ label,+ frames,+ viewBox: [width, 420],+ }), qualityProfile);+ assert.deepEqual(result.receipt.viewBox, [width, 420]);+ assertReadableAdjacentResult(result, { label });+ if (frames) assert.match(result.svg, /data-composition-frame-kind="group"/);+ cases += 1;+ }+ }+ }+ }+ }+ assert.equal(cases, 160);+ });++ test('readable-v2 phase and group frames derive from solved ranks without moving the core geometry', () => {+ for (const qualityProfile of ['standard', 'showcase']) {+ for (let fromCol = 0; fromCol < 5; fromCol += 1) {+ const plain = compileSuccessfully(adjacentWorkflow({ fromCol, label: 'liga' }), qualityProfile);+ const framed = compileSuccessfully(+ adjacentWorkflow({ fromCol, label: 'liga', frames: true }),+ qualityProfile,+ );++ assert.deepEqual(framed.receipt.columns, plain.receipt.columns);+ assert.deepEqual(nodeRect(framed.svg, 'a'), nodeRect(plain.svg, 'a'));+ assert.deepEqual(nodeRect(framed.svg, 'b'), nodeRect(plain.svg, 'b'));+ assert.deepEqual(edgePoints(framed.svg, 'ab'), edgePoints(plain.svg, 'ab'));+ assert.match(framed.svg, /data-composition-frame-kind="group"/);+ assertReadableAdjacentResult(framed, { label: 'liga' });+ }+ }+ });++ test('readable-v2 treats the phase header mask as a routing obstacle', () => {+ const document = {+ schema_version: 2,+ diagram_type: 'workflow',+ meta: { title: 'Phase route obstacle', legend: { mode: 'hidden' } },+ lanes: [{ id: 'top', label: 'Top' }, { id: 'bottom', label: 'Bottom' }],+ nodes: [+ { id: 'a', lane: 'top', col: 0, type: 'backend', label: 'A' },+ { id: 'b', lane: 'bottom', col: 4, type: 'backend', label: 'B' },+ ],+ edges: [{+ id: 'ab', from: 'a', to: 'b', fromSide: 'top', toSide: 'top',+ }],+ };++ const withoutPhase = compileSuccessfully(clone(document), 'showcase');+ assert.ok(withoutPhase.receipt.edges.find(({ id }) => id === 'ab'));++ const withPhaseDocument = clone(document);+ withPhaseDocument.phases = [{ id: 'p', label: 'Phase', fromCol: 0, toCol: 5 }];+ const withPhase = compileSuccessfully(withPhaseDocument, 'showcase');+ const columns = withPhase.receipt.columns;+ const phaseMask = {+ x: columns[0] - 46,+ y: 27,+ width: (columns[5] + 46) - (columns[0] - 46),+ height: 16,+ };+ const points = withPhase.receipt.edges.find(({ id }) => id === 'ab').points;+ for (let index = 0; index < points.length - 1; index += 1) {+ assert.equal(+ orthogonalSegmentIntersectsRect(points[index], points[index + 1], phaseMask),+ false,+ `edge ab segment ${index} must clear the phase mask: ${JSON.stringify(points)}`,+ );+ }+ });++ test('readable-v2 never routes through a single-rank group label', () => {+ const groupLabel = 'Very long group label';+ const document = {+ schema_version: 2,+ diagram_type: 'workflow',+ meta: { title: 'Group label route obstacle', legend: { mode: 'hidden' } },+ lanes: [{ id: 'top', label: 'Top' }, { id: 'bottom', label: 'Bottom' }],+ groups: [{ id: 'g', label: groupLabel, lane: 'top', fromCol: 2, toCol: 2 }],+ nodes: [+ { id: 'a', lane: 'top', col: 2, type: 'backend', label: 'A' },+ { id: 'b', lane: 'bottom', col: 4, type: 'database', label: 'B' },+ ],+ edges: [{+ id: 'ab', from: 'a', to: 'b', fromSide: 'top', toSide: 'top',+ }],+ };++ const first = compileWorkflow({ workflow: document, qualityProfile: 'showcase' });+ const second = compileWorkflow({ workflow: clone(document), qualityProfile: 'showcase' });+ assert.deepEqual(second, first, 'repeated compilation must be deterministic');++ assert.equal(first.ok, false);+ assert.equal(first.svg, undefined);+ assert.equal(first.diagnostics.length, 1, JSON.stringify(first.diagnostics, null, 2));+ const [diagnostic] = first.diagnostics;+ assert.equal(diagnostic.code, 'workflow/explicit-pin-conflict');+ assert.equal(diagnostic.subject.path, '/edges/0/fromSide');+ assert.equal(+ diagnostic.evidence.invariant,+ 'readable route feasibility with authored endpoint sides',+ );+ assert.deepEqual(diagnostic.evidence.conflictingPins, [{+ edge: 'ab',+ field: 'fromSide',+ path: '/edges/0/fromSide',+ value: 'top',+ }]);+ assert.ok(diagnostic.supportedFixes.length > 0);+ assert.deepEqual(first.receipt.diagnostics, first.diagnostics);++ const repaired = clone(document);+ delete repaired.edges[0].fromSide;+ const rendered = compileWorkflow({ workflow: repaired, qualityProfile: 'showcase' });+ assert.equal(rendered.ok, true, JSON.stringify(rendered.diagnostics, null, 2));++ const escapedLabel = groupLabel.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');+ const attributes = rendered.svg.match(new RegExp(+ `<text\\b([^>]*)>${escapedLabel}</text>`,+ ))?.[1];+ assert.ok(attributes, 'expected the rendered group label');+ const groupLabelRect = {+ x: Number(attribute(attributes, 'x')),+ y: Number(attribute(attributes, 'y')) - 10,+ width: Array.from(groupLabel).length * 5.6,+ height: 14,+ };+ const points = rendered.receipt.edges.find(({ id }) => id === 'ab').points;+ for (let index = 0; index < points.length - 1; index += 1) {+ assert.equal(+ orthogonalSegmentIntersectsRect(points[index], points[index + 1], groupLabelRect),+ false,+ `edge ab segment ${index} must clear the group label: ${JSON.stringify(points)}`,+ );+ }+ });++ test('readable-v2 shifts top-side routes beyond lane header text deterministically', () => {+ const makeDocument = (topLaneLabel) => ({+ schema_version: 2,+ diagram_type: 'workflow',+ meta: { title: 'Lane header route obstacle', legend: { mode: 'hidden' } },+ lanes: [+ { id: 'top', label: topLaneLabel },+ { id: 'bottom', label: 'Bottom' },+ ],+ nodes: [+ { id: 'a', lane: 'top', col: 0, type: 'backend', label: 'A' },+ { id: 'b', lane: 'bottom', col: 4, type: 'database', label: 'B' },+ ],+ edges: [{+ id: 'ab', from: 'a', to: 'b', fromSide: 'top', toSide: 'top',+ }],+ });++ const compiled = new Map();+ for (const label of ['Responsibility owner', 'R']) {+ const first = compileSuccessfully(makeDocument(label), 'showcase');+ const second = compileSuccessfully(makeDocument(label), 'showcase');+ assert.deepEqual(second, first, `${label}: repeated compilation must be deterministic`);++ const points = first.receipt.edges.find(({ id }) => id === 'ab').points;+ const headerRect = asciiLaneHeaderTextRect(label);+ for (let index = 0; index < points.length - 1; index += 1) {+ assert.equal(+ orthogonalSegmentIntersectsRect(points[index], points[index + 1], headerRect),+ false,+ `${label}: edge ab segment ${index} must clear the top lane header: ${JSON.stringify(points)}`,+ );+ }+ compiled.set(label, first);+ }++ assert.ok(+ compiled.get('Responsibility owner').receipt.columns[0]+ > compiled.get('R').receipt.columns[0],+ 'the wider lane header must move the col-0 top-side corridor farther right',+ );+ });++ test('explicit viewBox width is containment capacity and never stretches readable-v2 geometry', () => {+ for (const qualityProfile of ['standard', 'showcase']) {+ for (let fromCol = 0; fromCol < 5; fromCol += 1) {+ const intrinsic = compileSuccessfully(adjacentWorkflow({+ fromCol,+ label: 'liga',+ }), qualityProfile);+ const expectedGeometry = {+ columns: intrinsic.receipt.columns,+ source: nodeRect(intrinsic.svg, 'a'),+ target: nodeRect(intrinsic.svg, 'b'),+ edge: edgePoints(intrinsic.svg, 'ab'),+ };++ for (const width of [900, 1080, 1400, 1600]) {+ const result = compileSuccessfully(adjacentWorkflow({+ fromCol,+ label: 'liga',+ viewBox: [width, 420],+ }), qualityProfile);+ assert.deepEqual(result.receipt.viewBox, [width, 420]);+ assert.deepEqual(svgViewBox(result.svg), [0, 0, width, 420]);+ assert.deepEqual(result.receipt.requiredViewBox, intrinsic.receipt.requiredViewBox);+ assert.deepEqual(result.receipt.columns, expectedGeometry.columns);+ assert.deepEqual(nodeRect(result.svg, 'a'), expectedGeometry.source);+ assert.deepEqual(nodeRect(result.svg, 'b'), expectedGeometry.target);+ assert.deepEqual(edgePoints(result.svg, 'ab'), expectedGeometry.edge);+ assertReadableAdjacentResult(result, { label: 'liga' });+ }+ }+ }+ });++ test('capacity-only viewBox failures preserve the intrinsic routes, labels, and requirement', () => {+ const document = {+ schema_version: 2,+ diagram_type: 'workflow',+ meta: { title: 'capacity', legend: { mode: 'hidden' } },+ lanes: [{ id: 'top', label: 'Top' }, { id: 'bottom', label: 'Bottom' }],+ nodes: [+ { id: 'n0', lane: 'top', col: 0, type: 'backend', label: 'N0' },+ { id: 'n1', lane: 'bottom', col: 1, type: 'backend', label: 'N1' },+ { id: 'n2', lane: 'top', col: 1, type: 'database', label: 'N2' },+ { id: 'n3', lane: 'bottom', col: 3, type: 'database', label: 'N3' },+ ],+ edges: [+ { id: 'e0', from: 'n3', to: 'n0' },+ {+ id: 'e1',+ from: 'n1',+ to: 'n2',+ label: 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ',+ },+ ],+ };+ const intrinsic = compileSuccessfully(clone(document), 'showcase');++ const insufficientDocument = clone(document);+ insufficientDocument.meta.viewBox = [900, 1000];+ const insufficient = compileWorkflow({+ workflow: insufficientDocument,+ qualityProfile: 'showcase',+ });+ assert.equal(insufficient.ok, false);+ assert.equal(insufficient.svg, undefined);+ assert.equal(insufficient.diagnostics.length, 1, JSON.stringify(insufficient.diagnostics, null, 2));+ const [capacity] = insufficient.diagnostics;+ assert.equal(capacity.code, 'workflow/viewbox-capacity');+ assert.deepEqual(capacity.evidence.actualViewBox, [900, 1000]);+ assert.deepEqual(capacity.evidence.requiredViewBox, intrinsic.receipt.requiredViewBox);++ const sufficientDocument = clone(document);+ sufficientDocument.meta.viewBox = [intrinsic.receipt.requiredViewBox[0], 1000];+ const sufficient = compileSuccessfully(sufficientDocument, 'showcase');+ assert.deepEqual(sufficient.receipt.requiredViewBox, intrinsic.receipt.requiredViewBox);+ assert.deepEqual(sufficient.receipt.edges, intrinsic.receipt.edges);+ assert.deepEqual(sufficient.receipt.labels, intrinsic.receipt.labels);+ });++ test('explicit viewBox capacity names the rank and label constraints that require more width', () => {+ const result = compileWorkflow({+ workflow: adjacentWorkflow({ fromCol: 1, label: 'liga', viewBox: [700, 420] }),+ qualityProfile: 'showcase',+ });+ assert.equal(result.ok, false);+ const diagnostic = result.diagnostics.find(({ code }) => code === 'workflow/viewbox-capacity');+ assert.ok(diagnostic, JSON.stringify(result.diagnostics, null, 2));+ assert.ok(diagnostic.evidence.contributors.includes('rank 1→2 direct clearance'));+ assert.ok(diagnostic.evidence.contributors.includes('edge ab label mask'));+ });++ test('explicit viewBox capacity names the rank and authored node widths that require more width', () => {+ const result = compileWorkflow({+ workflow: adjacentWorkflow({+ fromCol: 1,+ widths: [240, 240],+ viewBox: [700, 420],+ }),+ qualityProfile: 'showcase',+ });+ assert.equal(result.ok, false);+ const diagnostic = result.diagnostics.find(({ code }) => code === 'workflow/viewbox-capacity');+ assert.ok(diagnostic, JSON.stringify(result.diagnostics, null, 2));+ const contributors = diagnostic.evidence.contributors;+ assert.ok(+ contributors.some((contributor) => /rank 1→2/i.test(contributor) && /clearance/i.test(contributor)),+ `contributors must name the rank 1→2 width constraint: ${JSON.stringify(contributors)}`,+ );+ for (const nodeId of ['a', 'b']) {+ assert.ok(+ contributors.some((contributor) => (+ new RegExp(`node ${nodeId}\\b`, 'i').test(contributor) && /width/i.test(contributor)+ )),+ `contributors must name node ${nodeId}'s authored width: ${JSON.stringify(contributors)}`,+ );+ }+ });++ test('explicit viewBox height capacity names the authored tall node without naming a hidden legend', () => {+ const result = compileWorkflow({+ workflow: {+ schema_version: 2,+ diagram_type: 'workflow',+ meta: {+ title: 'Tall node height capacity',+ legend: { mode: 'hidden' },+ viewBox: [1200, 280],+ },+ lanes: [{ id: 'main', label: 'M' }],+ nodes: [{+ id: 'tall', lane: 'main', col: 0, type: 'backend', label: 'Tall', height: 160,+ }],+ edges: [],+ },+ qualityProfile: 'showcase',+ });++ assert.equal(result.ok, false);+ assert.equal(result.svg, undefined);+ assert.equal(result.diagnostics.length, 1, JSON.stringify(result.diagnostics, null, 2));+ const [diagnostic] = result.diagnostics;+ assert.equal(diagnostic.code, 'workflow/viewbox-capacity');+ assert.deepEqual(diagnostic.evidence.actualViewBox, [1200, 280]);+ assert.equal(diagnostic.evidence.requiredViewBox[1], 374);+ const contributors = diagnostic.evidence.contributors;+ assert.ok(+ contributors.some((contributor) => (+ /node tall\b/i.test(contributor)+ && /height/i.test(contributor)+ && /160px/i.test(contributor)+ )),+ `contributors must name tall's authored 160px height: ${JSON.stringify(contributors)}`,+ );+ assert.equal(+ contributors.some((contributor) => /legend/i.test(contributor)),+ false,+ `a hidden legend must not be named as a height contributor: ${JSON.stringify(contributors)}`,+ );+ });++ test('readable-v2 measures asymmetric custom widths and CJK edge labels', () => {+ const cases = [+ { widths: [32, 92], label: '同步', nodeLabels: ['甲', '乙'] },+ { widths: [102, 124], label: '資料 ready', nodeLabels: ['入口', '出口'] },+ { widths: [132, 160], label: '审批通过', nodeLabels: ['请求', '执行'] },+ { widths: [92, 240], label: '结果 ✅ 回传', nodeLabels: ['工具', '外部服务'] },+ ];++ for (const current of cases) {+ const result = compileSuccessfully(adjacentWorkflow({+ fromCol: 1,+ label: current.label,+ widths: current.widths,+ nodeLabels: current.nodeLabels,+ viewBox: [1600, 420],+ }), 'showcase');+ assertReadableAdjacentResult(result, current);+ }+ });++ test('readable-v2 compares long-label gutter growth with a legal automatic channel', () => {+ const automaticDocument = adjacentWorkflow({+ fromCol: 3,+ label: 'L'.repeat(80),+ });+ const automatic = compileSuccessfully(automaticDocument, 'showcase');+ const forcedStraightDocument = clone(automaticDocument);+ forcedStraightDocument.edges[0].route = 'straight';+ const forcedStraight = compileSuccessfully(forcedStraightDocument, 'showcase');++ assert.ok(edgePoints(automatic.svg, 'ab').length > 2, 'the compact plan must use a legal channel');+ assert.ok(+ automatic.receipt.requiredViewBox[0] < forcedStraight.receipt.requiredViewBox[0],+ 'the selected channel must require less canvas than forcing the direct gutter',+ );+ assertRectInsideViewBox(+ edgeLabelRect(automatic.svg, 'ab'),+ svgViewBox(automatic.svg),+ 'long automatic edge label',+ );++ const leftRankDocument = adjacentWorkflow({ fromCol: 0, label: 'X'.repeat(100) });+ const leftRank = compileSuccessfully(leftRankDocument, 'showcase');+ assertRectInsideViewBox(+ edgeLabelRect(leftRank.svg, 'ab'),+ svgViewBox(leftRank.svg),+ 'left-rank long automatic edge label',+ );+ });++ test('readable-v2 property matrix satisfies every adjacent rank across supported representative widths', () => {+ const widths = [32, 92, 102, 124, 132, 160, 240];+ for (let fromCol = 0; fromCol < 5; fromCol += 1) {+ for (const sourceWidth of widths) {+ for (const targetWidth of widths) {+ const result = compileSuccessfully(adjacentWorkflow({+ fromCol,+ label: '同步 ✅',+ widths: [sourceWidth, targetWidth],+ }), 'showcase');+ assertReadableAdjacentResult(result, {+ label: '同步 ✅',+ widths: [sourceWidth, targetWidth],+ });+ }+ }+ }+ });++ test('readable-v2 expands rank spans for measured phase and group label capacity', () => {+ const workflow = adjacentWorkflow({ fromCol: 0, frames: true });+ workflow.phases[0].label = 'P'.repeat(50);+ workflow.groups[0].label = 'G'.repeat(50);++ const result = compileSuccessfully(workflow, 'showcase');+ assert.ok(result.receipt.columns[1] - result.receipt.columns[0] > 120);+ assertReadableAdjacentResult(result);+ });++ test('readable-v2 contains a long single-rank group label in its frame and intrinsic canvas', () => {+ const workflow = {+ schema_version: 2,+ diagram_type: 'workflow',+ meta: { title: 'Single-rank group capacity', legend: { mode: 'hidden' } },+ lanes: [{ id: 'main', label: 'Main' }],+ groups: [{+ id: 'long-group',+ label: 'X'.repeat(120),+ lane: 'main',+ fromCol: 5,+ toCol: 5,+ }],+ nodes: [+ { id: 'outside', lane: 'main', col: 2, type: 'database', label: 'Outside' },+ { id: 'node', lane: 'main', col: 5, type: 'backend', label: 'Node' },+ ],+ edges: [],+ };++ const result = compileSuccessfully(workflow, 'showcase');+ assert.ok(result.receipt.requiredViewBox[0] > 768);+ const groupAttributes = result.svg.match(+ /<rect\b(?=[^>]*data-composition-frame-id="group-0")[^>]*\b(x="[^"]+"[^>]*)\/>/,+ )?.[1];+ assert.ok(groupAttributes);+ const group = numericRect(groupAttributes);+ assert.ok(group.width >= 120 * 5.6 + 20, `group width ${group.width} must contain its label`);+ const outside = nodeRect(result.svg, 'outside');+ assert.ok(group.x >= outside.x + outside.width, 'single-rank group must not cover an unrelated rank');+ const labelBaseline = Number(result.svg.match(/<text\b[^>]*\by="([^"]+)"[^>]*>X{120}<\/text>/)?.[1]);+ assert.ok(labelBaseline <= nodeRect(result.svg, 'node').y - 4, 'group label must remain above its node');+ });++ test('readable-v2 group frames contain custom-width member rectangles on every side', () => {+ const workflow = {+ schema_version: 2,+ diagram_type: 'workflow',+ meta: { title: 'Wide group member', legend: { mode: 'hidden' } },+ lanes: [{ id: 'main', label: 'Main' }],+ groups: [{ id: 'group', label: 'G', lane: 'main', fromCol: 2, toCol: 2 }],+ nodes: [{+ id: 'wide', lane: 'main', col: 2, type: 'backend', label: 'Wide', width: 240,+ }],+ edges: [],+ };++ const result = compileSuccessfully(workflow, 'showcase');+ assertRectInsideRect(+ nodeRect(result.svg, 'wide'),+ groupFrameRect(result.svg),+ 'custom-width group member',+ );+ });++ test('readable-v2 group frames contain tagged and tall members away from the label rail', () => {+ const cases = [+ ['tagged member', { tag: 'TAG' }],+ ['120px-tall member', { height: 120 }],+ ];++ for (const [description, authoredGeometry] of cases) {+ const workflow = {+ schema_version: 2,+ diagram_type: 'workflow',+ meta: { title: description, legend: { mode: 'hidden' } },+ lanes: [{ id: 'main', label: 'Main' }],+ groups: [{ id: 'group', label: 'G', lane: 'main', fromCol: 0, toCol: 1 }],+ nodes: [{+ id: 'member',+ lane: 'main',+ col: 1,+ type: 'backend',+ label: 'Member',+ ...authoredGeometry,+ }],+ edges: [],+ };++ const result = compileSuccessfully(workflow, 'showcase');+ const member = nodeRect(result.svg, 'member');+ const groupLabel = asciiGroupLabelTextRect(result.svg, 'G');+ assert.ok(+ member.x >= groupLabel.x + groupLabel.width,+ `${description}: fixture must keep the member horizontally clear of its group label`,+ );+ assertRectInsideRect(member, groupFrameRect(result.svg), description);+ }+ });++ test('readable-v2 keeps a first-rank group label mask clear of its lane header mask', () => {+ const workflow = {+ schema_version: 2,+ diagram_type: 'workflow',+ meta: { title: 'First-rank group labels', legend: { mode: 'hidden' } },+ lanes: [{ id: 'main', label: 'Main' }],+ groups: [{ id: 'group', label: 'G', lane: 'main', fromCol: 0, toCol: 0 }],+ nodes: [{ id: 'member', lane: 'main', col: 0, type: 'backend', label: 'Member' }],+ edges: [],+ };++ const result = compileSuccessfully(workflow, 'showcase');+ const laneHeader = asciiLaneHeaderTextRect('Main');+ const groupLabel = asciiGroupLabelTextRect(result.svg, 'G');+ assert.equal(+ rectsOverlap(laneHeader, groupLabel),+ false,+ `lane header ${JSON.stringify(laneHeader)} must not overlap group label ${JSON.stringify(groupLabel)}`,+ );+ });++ test('readable-v2 measures multi-row legends into intrinsic and explicit viewBox capacity', () => {+ const workflow = adjacentWorkflow({ fromCol: 0 });+ workflow.meta.legend = {+ mode: 'all',+ entries: Object.fromEntries([+ 'frontend', 'backend', 'security', 'messagebus', 'database', 'cloud', 'external',+ ].map((kind) => [kind, { label: `${kind} contract evidence` }])),+ };+ const hiddenDocument = clone(workflow);+ hiddenDocument.meta.legend = { mode: 'hidden' };+ const hidden = compileSuccessfully(hiddenDocument, 'showcase');+ const intrinsic = compileSuccessfully(workflow, 'showcase');+ assert.ok(intrinsic.receipt.requiredViewBox[1] > hidden.receipt.requiredViewBox[1]);++ const tooShortDocument = clone(workflow);+ tooShortDocument.meta.viewBox = [+ intrinsic.receipt.requiredViewBox[0],+ hidden.receipt.requiredViewBox[1],+ ];+ const tooShort = compileWorkflow({ workflow: tooShortDocument, qualityProfile: 'showcase' });+ assert.equal(tooShort.ok, false);+ assert.ok(tooShort.diagnostics.some(({ code }) => code === 'workflow/viewbox-capacity'));++ const sufficientDocument = clone(workflow);+ sufficientDocument.meta.viewBox = [...intrinsic.receipt.requiredViewBox];+ const sufficient = compileSuccessfully(sufficientDocument, 'showcase');+ assert.deepEqual(sufficient.receipt.viewBox, intrinsic.receipt.requiredViewBox);++ const expectedGeometry = {+ requiredViewBox: intrinsic.receipt.requiredViewBox,+ columns: intrinsic.receipt.columns,+ nodes: intrinsic.receipt.nodes,+ edges: intrinsic.receipt.edges,+ labels: intrinsic.receipt.labels,+ legend: legendGeometry(intrinsic.svg),+ };+ for (const width of [900, 1400]) {+ const explicitDocument = clone(workflow);+ explicitDocument.meta.viewBox = [width, 1000];+ const explicit = compileSuccessfully(explicitDocument, 'showcase');+ assert.deepEqual(explicit.receipt.requiredViewBox, expectedGeometry.requiredViewBox);+ assert.deepEqual(explicit.receipt.columns, expectedGeometry.columns);+ assert.deepEqual(explicit.receipt.nodes, expectedGeometry.nodes);+ assert.deepEqual(explicit.receipt.edges, expectedGeometry.edges);+ assert.deepEqual(explicit.receipt.labels, expectedGeometry.labels);+ assert.deepEqual(legendGeometry(explicit.svg), expectedGeometry.legend);+ }+ });++ test('a wide node in an unrelated lane does not expand the adjacent-rank gap', () => {+ const baselineDocument = adjacentWorkflow({+ fromCol: 1,+ label: 'liga',+ viewBox: [1600, 520],+ });+ baselineDocument.lanes.push({ id: 'other', label: 'Other' });+ const baseline = compileSuccessfully(baselineDocument, 'showcase');++ const withUnrelatedWideNode = clone(baselineDocument);+ withUnrelatedWideNode.nodes.push({+ id: 'wide', lane: 'other', col: 1, type: 'database', label: 'Wide', width: 240,+ });+ const widened = compileSuccessfully(withUnrelatedWideNode, 'showcase');++ assert.equal(+ widened.receipt.columns[2] - widened.receipt.columns[1],+ baseline.receipt.columns[2] - baseline.receipt.columns[1],+ );+ });++ test('explicit labelAt participates in readable-v2 viewBox containment', () => {+ const workflow = adjacentWorkflow({+ fromCol: 0,+ label: 'outside',+ viewBox: [900, 420],+ });+ workflow.nodes[1].col = 5;+ workflow.edges[0].labelAt = [563, 539];++ const result = compileWorkflow({ workflow, qualityProfile: 'showcase' });+ assert.equal(result.ok, false);+ assert.equal(result.diagnostics.length, 1, JSON.stringify(result.diagnostics, null, 2));+ const [diagnostic] = result.diagnostics;+ assert.equal(diagnostic.code, 'workflow/viewbox-capacity');+ assert.deepEqual(diagnostic.evidence.actualViewBox, [900, 420]);+ assert.ok(diagnostic.evidence.requiredViewBox[1] > 420);+ assert.ok(+ diagnostic.evidence.contributors.some((contributor) => /edge ab label/i.test(contributor)),+ JSON.stringify(diagnostic.evidence.contributors),+ );+ assert.doesNotMatch(diagnostic.supportedFixes.join('\n'), /drop|remove (?:the )?label|unlabel/i);+ });++ test('sanitized downstream fixtures cover labels, explicit routes, custom widths, and explicit viewBoxes', () => {+ const fixtureRoot = path.join(__dirname, 'fixtures', 'issue-126');++ const labels = compileSuccessfully(readJson(path.join(fixtureRoot, 'labels.workflow.json')), 'showcase');+ assertRectInsideViewBox(+ edgeLabelRect(labels.svg, 'request-result'),+ svgViewBox(labels.svg),+ 'sanitized semantic label',+ );++ const explicitRoute = compileSuccessfully(+ readJson(path.join(fixtureRoot, 'explicit-route.workflow.json')),+ 'showcase',+ );+ assert.ok(+ edgePoints(explicitRoute.svg, 'producer-consumer').some(([x]) => x === 720),+ 'the authored channelX pin must remain exact',+ );++ const customWidths = compileSuccessfully(+ readJson(path.join(fixtureRoot, 'custom-widths.workflow.json')),+ 'showcase',+ );+ assert.equal(nodeRect(customWidths.svg, 'compact').width, 32);+ assert.equal(nodeRect(customWidths.svg, 'wide').width, 240);++ const explicitViewBox = compileSuccessfully(+ readJson(path.join(fixtureRoot, 'explicit-viewbox.workflow.json')),+ 'showcase',+ );+ assert.deepEqual(explicitViewBox.receipt.viewBox, [1600, 520]);+ });++ test('readable-v2 SVG and receipt bytes are deterministic across repeated and reordered input', () => {+ const workflow = {+ schema_version: 2,+ diagram_type: 'workflow',+ meta: { title: 'Deterministic workflow', legend: { mode: 'hidden' } },+ lanes: [{ id: 'main', label: 'Main' }],+ nodes: [+ { id: 'a', lane: 'main', col: 0, type: 'frontend', label: 'A' },+ { id: 'b', lane: 'main', col: 2, type: 'backend', label: 'B' },+ { id: 'c', lane: 'main', col: 4, type: 'database', label: 'C' },+ ],+ edges: [+ { id: 'ab', from: 'a', to: 'b', label: 'one' },+ { id: 'bc', from: 'b', to: 'c', label: 'two' },+ ],+ };++ const first = compileSuccessfully(clone(workflow), 'showcase');+ for (let iteration = 0; iteration < 3; iteration += 1) {+ const repeated = compileSuccessfully(clone(workflow), 'showcase');+ assert.equal(repeated.svg, first.svg);+ assert.equal(JSON.stringify(repeated.receipt), JSON.stringify(first.receipt));+ }++ const reordered = clone(workflow);+ reordered.nodes.reverse();+ reordered.edges.reverse();+ const reorderedResult = compileSuccessfully(reordered, 'showcase');+ assert.equal(reorderedResult.svg, first.svg);+ assert.equal(JSON.stringify(reorderedResult.receipt), JSON.stringify(first.receipt));+ });++ test('CLI validate workflow --layout-json prints the stable compiler receipt', () => {+ const input = path.join(tmp, 'layout-json.workflow.json');+ fs.writeFileSync(input, JSON.stringify(adjacentWorkflow({+ fromCol: 3,+ label: 'liga',+ viewBox: [1080, 420],+ })));++ const result = spawnSync(process.execPath, [+ cli,+ 'validate',+ 'workflow',+ input,+ '--layout-json',+ '--quality',+ 'standard',+ ], { encoding: 'utf8' });++ assert.equal(result.status, 0, result.stderr);+ const receipt = JSON.parse(result.stdout);+ assert.equal(receipt.contract, 'readable-v2');+ assert.deepEqual(receipt.viewBox, [1080, 420]);+ assert.ok(Array.isArray(receipt.requiredViewBox));+ assert.equal(receipt.columns.length, 6);+ assert.deepEqual(receipt.diagnostics, []);+ });++ test('CLI validate workflow --layout-json returns only the causal compiler failure receipt', () => {+ const input = path.join(tmp, 'layout-json-failure.workflow.json');+ fs.writeFileSync(input, JSON.stringify({+ schema_version: 1,+ diagram_type: 'workflow',+ meta: { title: 'Issue 126 failure receipt', legend: { mode: 'hidden' } },+ lanes: [{ id: 'main', label: 'Main' }],+ nodes: [+ { id: 'a', lane: 'main', col: 1, type: 'backend', label: 'A' },+ { id: 'b', lane: 'main', col: 2, type: 'backend', label: 'B' },+ ],+ edges: [{ id: 'ab', from: 'a', to: 'b' }],+ }));++ const result = spawnSync(process.execPath, [+ cli,+ 'validate',+ 'workflow',+ input,+ '--layout-json',+ '--json',+ ], { encoding: 'utf8' });++ assert.equal(result.status, 1);+ assert.equal(result.stderr, '');+ const receipt = JSON.parse(result.stdout);+ assert.equal(receipt.contract, 'fixed-v1');+ assert.equal(receipt.diagnostics.length, 1, JSON.stringify(receipt.diagnostics, null, 2));+ assert.equal(receipt.diagnostics[0].code, 'workflow/column-capacity');+ });++ process.on('exit', () => fs.rmSync(tmp, { recursive: true, force: true }));diff --cc docs/assets/archify-live-proof.gifindex a208aedf,c4482fde..f0c48056Binary files differdiff --cc docs/assets/archify-live-proof.jsonindex 40d83edb,9239205b..9dd9b074--- a/docs/assets/archify-live-proof.json+++ b/docs/assets/archify-live-proof.json@@@ -7,13 -7,13 +7,13 @@@"fps": 10,"frameCount": 54,"durationSeconds": 5.4,- "bytes": 1872060,- "sha256": "381b2331dbae6d9f97cc44df62048d15c1158e36ca8944545dacd2f1b0aa83e4",- "bytes": 1542193,- "sha256": "e0fe704e5d230c0478bc5a48b7668815b5790eed496da87ce7a5f8e5b2416c28",++ "bytes": 1691035,++ "sha256": "9c86ec7a3935f4267142d9b7680458d47824c6f7b50d6bb078cfdb00c22de86b","scenes": [{"id": "signal-flow","artifact": "docs/gallery/artifacts/agent-tool-call.workflow.html",- "artifactSha256": "76322a20d6dace7c37ba81f8ca8a93f95ae7f56d56b4bf2124ff62123ac321dc",- "artifactSha256": "e083cfe2d35701472374910e922ebdf8b30fdd3d5547d0e2cabd05094d033c66",++ "artifactSha256": "1992954ecc4ccea2a7d8f75835ebc429381f9b5ffa8e0d27d9a3dd354071ce9c","view": "happy-path","eyebrow": "WORKFLOW · SIGNAL FLOW","title": "Agent Tool Call",@@@ -22,7 -22,7 +22,7 @@@{"id": "blueprint","artifact": "docs/gallery/artifacts/production-deployment.architecture.html",- "artifactSha256": "2599b3e126c3d18cf2300a2cc83efa6a7fd6cd3a67c6d209daea6eabc6f5245f",- "artifactSha256": "dbf6d1b3cffa610f2e538cca3b9aa1c65eb45f580154f316d97c157d90916faa",++ "artifactSha256": "9aedac2719539c54d88a3919553fd2d664841f5198da98582991a1f254dc2089","view": "request-boundary","eyebrow": "ARCHITECTURE · BLUEPRINT","title": "Production Deployment",@@@ -31,7 -31,7 +31,7 @@@{"id": "classic","artifact": "docs/gallery/artifacts/cache-miss.sequence.html",- "artifactSha256": "94d067515da75d17d1ed25b406831b71c17f74bc750e8804023f790c011fa1ba",- "artifactSha256": "6bf688c8577049973ace979ac73292eda0cc8f349934c6ba4452720853ced84c",++ "artifactSha256": "701f624494c36350433eaee1bca6747b15838be6c2ff7b9cdcc971014c74fbe8","view": "cache-fallback","eyebrow": "SEQUENCE · CLASSIC","title": "Cache Miss Request",diff --cc docs/gallery.htmlindex e4eb6ffe,7c2e6aa3..993cbd1e--- a/docs/gallery.html+++ b/docs/gallery.html@@@ -306,7 -298,7 +298,7 @@@<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div><div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div><div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">12N · 11E</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="76322a20d6dace7c37ba81f8ca8a93f95ae7f56d56b4bf2124ff62123ac321dc">76322a20d6da</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="e083cfe2d35701472374910e922ebdf8b30fdd3d5547d0e2cabd05094d033c66">e083cfe2d357</span></div>++ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="1992954ecc4ccea2a7d8f75835ebc429381f9b5ffa8e0d27d9a3dd354071ce9c">1992954ecc4c</span></div></div><div class="card-actions"><a class="card-link primary" href="gallery/artifacts/agent-tool-call.workflow.html?present=1&play=1#view=happy-path" target="_blank" rel="noopener" data-en="Play named chapter ↗" data-zh="播放命名章节 ↗">Play named chapter ↗</a>@@@ -336,7 -328,7 +328,7 @@@<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div><div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div><div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">12N · 12E</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="2599b3e126c3d18cf2300a2cc83efa6a7fd6cd3a67c6d209daea6eabc6f5245f">2599b3e126c3</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="dbf6d1b3cffa610f2e538cca3b9aa1c65eb45f580154f316d97c157d90916faa">dbf6d1b3cffa</span></div>++ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="9aedac2719539c54d88a3919553fd2d664841f5198da98582991a1f254dc2089">9aedac271953</span></div></div><div class="card-actions"><a class="card-link primary" href="gallery/artifacts/production-deployment.architecture.html?present=1&play=1#view=request-boundary" target="_blank" rel="noopener" data-en="Play named chapter ↗" data-zh="播放命名章节 ↗">Play named chapter ↗</a>@@@ -365,7 -357,7 +357,7 @@@<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div><div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div><div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">7N · 12E</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="94d067515da75d17d1ed25b406831b71c17f74bc750e8804023f790c011fa1ba">94d067515da7</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="6bf688c8577049973ace979ac73292eda0cc8f349934c6ba4452720853ced84c">6bf688c85770</span></div>++ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="701f624494c36350433eaee1bca6747b15838be6c2ff7b9cdcc971014c74fbe8">701f624494c3</span></div></div><div class="card-actions"><a class="card-link primary" href="gallery/artifacts/cache-miss.sequence.html?present=1&play=1#view=cache-fallback" target="_blank" rel="noopener" data-en="Play named chapter ↗" data-zh="播放命名章节 ↗">Play named chapter ↗</a>@@@ -394,7 -386,7 +386,7 @@@<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div><div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div><div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">10N · 10E</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="9e8f6c4d2f3dac66943175589e60342a11e5347fed6888eac13e8b6ba369208f">9e8f6c4d2f3d</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="358289f1aee93c3bf1075ce95372325ea415c0178f76ce62c868bdc3683cc5f4">358289f1aee9</span></div>++ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="31b81e8c33e787ace2567da5685eaa6adcf8c8b224a38e2ebbeb37b9eda05e98">31b81e8c33e7</span></div></div><div class="card-actions"><a class="card-link primary" href="gallery/artifacts/release-delivery.workflow.html?present=1&play=1#view=approval-to-production" target="_blank" rel="noopener" data-en="Play named chapter ↗" data-zh="播放命名章节 ↗">Play named chapter ↗</a>@@@ -423,7 -415,7 +415,7 @@@<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div><div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div><div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">11N · 10E</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="ca28468ccc905e04a5ea1e77c26c6028cbdd1f0ed36ad28eb21fd05851ef5a83">ca28468ccc90</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="d50feba56cbba1bf62a19b45f142bc1f964bf6831730a79d2760aadcf106542a">d50feba56cbb</span></div>++ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="e1ae74cb033215bc0f29e00712b938ec4d4368befcaeadc2cd56dcbfffb7534a">e1ae74cb0332</span></div></div><div class="card-actions"><a class="card-link primary" href="gallery/artifacts/incident-response.workflow.html?present=1&play=1#view=mitigate-and-verify" target="_blank" rel="noopener" data-en="Play named chapter ↗" data-zh="播放命名章节 ↗">Play named chapter ↗</a>@@@ -452,7 -444,7 +444,7 @@@<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div><div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div><div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">10N · 10E</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="3bb96e400186da5e47b81d545b2c079fcd5579d535199f2680689cf3ad416a8a">3bb96e400186</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="d66d70595448044a92d032738e2437980d2160462f974a1de8cfa82c5e148d54">d66d70595448</span></div>++ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="914129ff263b0cdcd7b5630b80eeb08d0a76d4adc3a04f292cd223cbeacbe555">914129ff263b</span></div></div><div class="card-actions"><a class="card-link primary" href="gallery/artifacts/product-analytics.dataflow.html?present=1&play=1#view=consent-boundary" target="_blank" rel="noopener" data-en="Play named chapter ↗" data-zh="播放命名章节 ↗">Play named chapter ↗</a>@@@ -481,7 -473,7 +473,7 @@@<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div><div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div><div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">7N · 14E</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="039714fbb6d2a698cdd38aa973d61f352ad170027333242f22758f9cef2eaa14">039714fbb6d2</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="c4d7cb0eaecfeff4d713b8f3b36b916840d6530f08e9b698ded308effd3ff59b">c4d7cb0eaecf</span></div>++ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="0b84c8244f7dc1f0fb5831a278c8e909d99eb4cbb028740b57a85612e16997c9">0b84c8244f7d</span></div></div><div class="card-actions"><a class="card-link primary" href="gallery/artifacts/async-job-roundtrip.sequence.html?present=1&play=1#view=work-and-retry" target="_blank" rel="noopener" data-en="Play named chapter ↗" data-zh="播放命名章节 ↗">Play named chapter ↗</a>@@@ -510,7 -502,7 +502,7 @@@<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div><div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div><div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">12N · 12E</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="425a1d62302d50dff13a5ab1aa2ac6e7c52fea8a35e2e83b75f0cd10d1bc06a8">425a1d62302d</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="cab32bd06250fdc18f7d25e7562407af9b2e2a37f9ca65c6a852716f7faf1892">cab32bd06250</span></div>++ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="093c9615cbec70afac11139f8d046ce27b9d9c9bd81f5c7dc7454b58d8347e91">093c9615cbec</span></div></div><div class="card-actions"><a class="card-link primary" href="gallery/artifacts/event-stream.dataflow.html?present=1&play=1#view=order-transit" target="_blank" rel="noopener" data-en="Play named chapter ↗" data-zh="播放命名章节 ↗">Play named chapter ↗</a>@@@ -539,7 -531,7 +531,7 @@@<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div><div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div><div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">10N · 6E</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="bd13f1cb147fed53002efe600b11a4e1d8a75e3a13b08644daf010cdbf790468">bd13f1cb147f</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="d15306112803fe6ac1050c6fd5d943545a5bc6a72a0407cd0751d0d8794f6429">d15306112803</span></div>++ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="1363d2fffd62c21d95a6c0af4d2eb698b88f56561c883034bd34065c84a09a2c">1363d2fffd62</span></div></div><div class="card-actions"><a class="card-link primary" href="gallery/artifacts/agent-run.lifecycle.html?present=1&play=1#view=main-lifecycle" target="_blank" rel="noopener" data-en="Play named chapter ↗" data-zh="播放命名章节 ↗">Play named chapter ↗</a>@@@ -568,7 -560,7 +560,7 @@@<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div><div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div><div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">11N · 6E</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="a3c6a862830f3a522aad4e7339a406e5bb4b1dcab1969b34d9f0bfb5bdd00dae">a3c6a862830f</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="2b41af0f84ff5cdbe21f0d672d1d9825eab246b3e7fbaa0237c49042bf28547d">2b41af0f84ff</span></div>++ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="9556a18d4406c025c8d979a509eaa09e07f6d68064329d0328c04bf0f60422cb">9556a18d4406</span></div></div><div class="card-actions"><a class="card-link primary" href="gallery/artifacts/deployment-release.lifecycle.html?present=1&play=1#view=rollback-outcomes" target="_blank" rel="noopener" data-en="Play named chapter ↗" data-zh="播放命名章节 ↗">Play named chapter ↗</a>@@@ -597,7 -589,7 +589,7 @@@<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div><div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div><div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">10N · 9E</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="caed76c7d2bf84b8c166757780bbe919a2b3c1919772e19bfcd17a742aa6a49d">caed76c7d2bf</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="26784b847623e79727e44eb5fabfbedc2c47289bf877703eee78787a3eb5bee5">26784b847623</span></div>++ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="2896f0d59782986081e39bc62bab748a5aea819c18e656d45373ebfebc265e7b">2896f0d59782</span></div></div><div class="card-actions"><a class="card-link primary" href="gallery/artifacts/web-app.architecture.html?present=1&play=1#view=request-path" target="_blank" rel="noopener" data-en="Play named chapter ↗" data-zh="播放命名章节 ↗">Play named chapter ↗</a>@@@ -683,10 -675,10 +675,10 @@@ receipt 99 checks / 11 artifacts / dete"engineeringProfile": null,"nodeCount": 12,"edgeCount": 11,- "artifactBytes": 720788,- "artifactSha256": "76322a20d6dace7c37ba81f8ca8a93f95ae7f56d56b4bf2124ff62123ac321dc",- "sourceBytes": 6367,- "sourceSha256": "9c94c8c0b2104478b77befb4cc5e343d381acba6e66645ab17616fde20b60e05",- "artifactBytes": 723038,- "artifactSha256": "e083cfe2d35701472374910e922ebdf8b30fdd3d5547d0e2cabd05094d033c66",++ "artifactBytes": 723375,++ "artifactSha256": "1992954ecc4ccea2a7d8f75835ebc429381f9b5ffa8e0d27d9a3dd354071ce9c",+ "sourceBytes": 5687,+ "sourceSha256": "4d3f6c23de2ca7d306e05d0041a9506833bb5a164a2bddc2d1984cf4da3ee90c","checks": [{"name": "single_svg",@@@ -783,8 -775,8 +775,8 @@@"engineeringProfile": "deployment-ownership","nodeCount": 12,"edgeCount": 12,- "artifactBytes": 724872,- "artifactSha256": "dbf6d1b3cffa610f2e538cca3b9aa1c65eb45f580154f316d97c157d90916faa",+ "artifactBytes": 725205,- "artifactSha256": "2599b3e126c3d18cf2300a2cc83efa6a7fd6cd3a67c6d209daea6eabc6f5245f",++ "artifactSha256": "9aedac2719539c54d88a3919553fd2d664841f5198da98582991a1f254dc2089","sourceBytes": 5476,"sourceSha256": "ec484aa8576664fdb207b543fa49486b23273faccb7a5071e1a0becfb48c22eb","checks": [@@@ -883,8 -875,8 +875,8 @@@"engineeringProfile": null,"nodeCount": 7,"edgeCount": 12,- "artifactBytes": 716842,- "artifactSha256": "6bf688c8577049973ace979ac73292eda0cc8f349934c6ba4452720853ced84c",+ "artifactBytes": 717130,- "artifactSha256": "94d067515da75d17d1ed25b406831b71c17f74bc750e8804023f790c011fa1ba",++ "artifactSha256": "701f624494c36350433eaee1bca6747b15838be6c2ff7b9cdcc971014c74fbe8","sourceBytes": 4345,"sourceSha256": "4bbaa6ca3cd4036002fd5d0f3a332eb922cec69d09bac3d7925f95beb4308389","checks": [@@@ -983,8 -975,8 +975,8 @@@"engineeringProfile": null,"nodeCount": 10,"edgeCount": 10,- "artifactBytes": 719238,- "artifactSha256": "358289f1aee93c3bf1075ce95372325ea415c0178f76ce62c868bdc3683cc5f4",+ "artifactBytes": 719571,- "artifactSha256": "9e8f6c4d2f3dac66943175589e60342a11e5347fed6888eac13e8b6ba369208f",++ "artifactSha256": "31b81e8c33e787ace2567da5685eaa6adcf8c8b224a38e2ebbeb37b9eda05e98","sourceBytes": 5164,"sourceSha256": "e5c880417eac1623923c3dd5461e0c78acd762e1621a28bd53fc14a84cad6a91","checks": [@@@ -1083,8 -1075,8 +1075,8 @@@"engineeringProfile": null,"nodeCount": 11,"edgeCount": 10,- "artifactBytes": 716567,- "artifactSha256": "d50feba56cbba1bf62a19b45f142bc1f964bf6831730a79d2760aadcf106542a",+ "artifactBytes": 716886,- "artifactSha256": "ca28468ccc905e04a5ea1e77c26c6028cbdd1f0ed36ad28eb21fd05851ef5a83",++ "artifactSha256": "e1ae74cb033215bc0f29e00712b938ec4d4368befcaeadc2cd56dcbfffb7534a","sourceBytes": 5375,"sourceSha256": "5c760c82eee545dfb7da38a4e628059d7891af4cfbfc13c8a7009ea64f69aa1b","checks": [@@@ -1183,8 -1175,8 +1175,8 @@@"engineeringProfile": null,"nodeCount": 10,"edgeCount": 10,- "artifactBytes": 720496,- "artifactSha256": "d66d70595448044a92d032738e2437980d2160462f974a1de8cfa82c5e148d54",+ "artifactBytes": 720833,- "artifactSha256": "3bb96e400186da5e47b81d545b2c079fcd5579d535199f2680689cf3ad416a8a",++ "artifactSha256": "914129ff263b0cdcd7b5630b80eeb08d0a76d4adc3a04f292cd223cbeacbe555","sourceBytes": 5627,"sourceSha256": "6fa38a7ccedf96da592d60b392783b846188eaa3ec9136c6dc06ca020e43a110","checks": [@@@ -1283,8 -1275,8 +1275,8 @@@"engineeringProfile": null,"nodeCount": 7,"edgeCount": 14,- "artifactBytes": 717252,- "artifactSha256": "c4d7cb0eaecfeff4d713b8f3b36b916840d6530f08e9b698ded308effd3ff59b",+ "artifactBytes": 717540,- "artifactSha256": "039714fbb6d2a698cdd38aa973d61f352ad170027333242f22758f9cef2eaa14",++ "artifactSha256": "0b84c8244f7dc1f0fb5831a278c8e909d99eb4cbb028740b57a85612e16997c9","sourceBytes": 4370,"sourceSha256": "545f20920c89b69c2bb1f15508d5543fddbeb15cffba61e102206e04bd5a5cd9","checks": [@@@ -1383,8 -1375,8 +1375,8 @@@"engineeringProfile": null,"nodeCount": 12,"edgeCount": 12,- "artifactBytes": 724459,- "artifactSha256": "cab32bd06250fdc18f7d25e7562407af9b2e2a37f9ca65c6a852716f7faf1892",+ "artifactBytes": 724813,- "artifactSha256": "425a1d62302d50dff13a5ab1aa2ac6e7c52fea8a35e2e83b75f0cd10d1bc06a8",++ "artifactSha256": "093c9615cbec70afac11139f8d046ce27b9d9c9bd81f5c7dc7454b58d8347e91","sourceBytes": 5433,"sourceSha256": "a92d6597ddbe164f395da32a7d4b33cfae08edd7d9600a6fb45a2058e5bbb43e","checks": [@@@ -1483,8 -1475,8 +1475,8 @@@"engineeringProfile": null,"nodeCount": 10,"edgeCount": 6,- "artifactBytes": 714131,- "artifactSha256": "d15306112803fe6ac1050c6fd5d943545a5bc6a72a0407cd0751d0d8794f6429",+ "artifactBytes": 714419,- "artifactSha256": "bd13f1cb147fed53002efe600b11a4e1d8a75e3a13b08644daf010cdbf790468",++ "artifactSha256": "1363d2fffd62c21d95a6c0af4d2eb698b88f56561c883034bd34065c84a09a2c","sourceBytes": 4417,"sourceSha256": "af939579dcafc8b4c49f09594591577994398aee57a57369d4c791dfc0d85a42","checks": [@@@ -1583,8 -1575,8 +1575,8 @@@"engineeringProfile": null,"nodeCount": 11,"edgeCount": 6,- "artifactBytes": 715123,- "artifactSha256": "2b41af0f84ff5cdbe21f0d672d1d9825eab246b3e7fbaa0237c49042bf28547d",+ "artifactBytes": 715411,- "artifactSha256": "a3c6a862830f3a522aad4e7339a406e5bb4b1dcab1969b34d9f0bfb5bdd00dae",++ "artifactSha256": "9556a18d4406c025c8d979a509eaa09e07f6d68064329d0328c04bf0f60422cb","sourceBytes": 4274,"sourceSha256": "735c2c5819266e6ea2a71775b6eefce98b53030ce90cb721dc8e1d022ce5be71","checks": [@@@ -1683,8 -1675,8 +1675,8 @@@"engineeringProfile": null,"nodeCount": 10,"edgeCount": 9,- "artifactBytes": 715216,- "artifactSha256": "26784b847623e79727e44eb5fabfbedc2c47289bf877703eee78787a3eb5bee5",+ "artifactBytes": 715531,- "artifactSha256": "caed76c7d2bf84b8c166757780bbe919a2b3c1919772e19bfcd17a742aa6a49d",++ "artifactSha256": "2896f0d59782986081e39bc62bab748a5aea819c18e656d45373ebfebc265e7b","sourceBytes": 3793,"sourceSha256": "483350f5297df682aba4e4a0fa491307ce3d3abd725ae4df07fab177490752cf","checks": [diff --cc docs/gallery/artifacts/agent-tool-call.workflow.htmlindex 36d95fbd,0fb6bb9a..a4c89f72--- a/docs/gallery/artifacts/agent-tool-call.workflow.html+++ b/docs/gallery/artifacts/agent-tool-call.workflow.html@@@ -5036,56 -5030,52 +5036,52 @@@<rect width="100%" height="100%" fill="url(#grid)" /><!-- Swimlanes -->- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-0" x="40" y="52" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-0" x="40" y="52" width="1028" height="106" rx="10" class="c-lane" stroke-width="1"/><text x="54" y="74" class="t-dim" font-size="10" font-weight="600">01 / User Interface</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-1" x="40" y="176" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <text x="54" y="198" class="t-dim" font-size="10" font-weight="600">02 / Agent Runtime</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-1" x="40" y="178" width="1028" height="114" rx="10" class="c-lane" stroke-width="1"/>+ <text x="54" y="200" class="t-dim" font-size="10" font-weight="600">02 / Agent Runtime</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-2" x="40" y="300" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <text x="54" y="322" class="t-dim" font-size="10" font-weight="600">03 / Policy Boundary</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-2" x="40" y="312" width="1028" height="114" rx="10" class="c-lane" stroke-width="1"/>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="exception-lane" data-composition-frame-id="lane-2-exception" x="46" y="318" width="1016" height="102" rx="8" class="c-security-group" stroke-width="1"/>+ <text x="54" y="334" class="t-security" font-size="10" font-weight="600">EX / Policy & Recovery</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-3" x="40" y="424" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <rect data-graph-role="structural-frame" data-composition-frame-kind="exception-lane" data-composition-frame-id="lane-3-exception" x="46" y="430" width="628" height="92" rx="8" class="c-security-group" stroke-width="1"/>- <text x="54" y="446" class="t-security" font-size="10" font-weight="600">EX / Exception Handling</text>-- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-4" x="40" y="548" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <text x="54" y="570" class="t-dim" font-size="10" font-weight="600">05 / Tool Execution</text>-- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-5" x="40" y="672" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <text x="54" y="694" class="t-dim" font-size="10" font-weight="600">06 / Observability</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-3" x="40" y="446" width="1028" height="114" rx="10" class="c-lane" stroke-width="1"/>+ <text x="54" y="468" class="t-dim" font-size="10" font-weight="600">04 / Tool Execution & Evidence</text><!-- Phase headers -->- <line x1="42" y1="35" x2="266" y2="35" class="a-default" stroke-width="1.1"/>- <rect x="42" y="27" width="224" height="16" rx="4" class="c-mask"/>- <text x="154" y="39" class="t-edge-default" font-size="8" font-weight="600" text-anchor="middle">Intake</text>- <line x1="254" y1="35" x2="476" y2="35" class="a-emphasis" stroke-width="1.1"/>- <rect x="254" y="27" width="222" height="16" rx="4" class="c-mask"/>- <text x="365" y="39" class="t-edge-emphasis" font-size="8" font-weight="600" text-anchor="middle">Plan + route</text>- <line x1="454" y1="35" x2="671" y2="35" class="a-dashed" stroke-width="1.1"/>- <rect x="454" y="27" width="217" height="16" rx="4" class="c-mask"/>- <text x="562.5" y="39" class="t-edge-dashed" font-size="8" font-weight="600" text-anchor="middle">Execute + report</text>+ <line x1="68" y1="35" x2="320" y2="35" class="a-default" stroke-width="1.1"/>+ <rect x="68" y="27" width="252" height="16" rx="4" class="c-mask"/>- <text x="194" y="39" class="t-muted" font-size="8" font-weight="600" text-anchor="middle">Intake</text>++ <text x="194" y="39" class="t-edge-default" font-size="8" font-weight="600" text-anchor="middle">Intake</text>+ <line x1="445.20000000000005" y1="35" x2="697.2" y2="35" class="a-emphasis" stroke-width="1.1"/>+ <rect x="445.20000000000005" y="27" width="252.00000000000006" height="16" rx="4" class="c-mask"/>- <text x="571.2" y="39" class="t-backend" font-size="8" font-weight="600" text-anchor="middle">Plan + route</text>++ <text x="571.2" y="39" class="t-edge-emphasis" font-size="8" font-weight="600" text-anchor="middle">Plan + route</text>+ <line x1="784" y1="35" x2="1036" y2="35" class="a-dashed" stroke-width="1.1"/>+ <rect x="784" y="27" width="252" height="16" rx="4" class="c-mask"/>- <text x="910" y="39" class="t-messagebus" font-size="8" font-weight="600" text-anchor="middle">Execute + report</text>++ <text x="910" y="39" class="t-edge-dashed" font-size="8" font-weight="600" text-anchor="middle">Execute + report</text><!-- Workflow groups -->- <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-0" x="250" y="214" width="230" height="58" rx="9" class="c-lane" stroke-width="1"/>- <text x="260" y="228" class="t-edge-emphasis" font-size="7" font-weight="600">Planning loop</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-1" x="450" y="586" width="225" height="58" rx="9" class="c-lane" stroke-width="1"/>- <text x="460" y="600" class="t-edge-dashed" font-size="7" font-weight="600">Tool work</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-2" x="380" y="462" width="295" height="58" rx="9" class="c-security-group" stroke-width="1"/>- <text x="390" y="476" class="t-edge-security" font-size="7" font-weight="600">Human or policy stop</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-0" x="421.2" y="216" width="300.00000000000006" height="72" rx="9" class="c-lane" stroke-width="1"/>- <text x="431.2" y="214" class="t-backend" font-size="7" font-weight="600">Planning loop</text>++ <text x="431.2" y="214" class="t-edge-emphasis" font-size="7" font-weight="600">Planning loop</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-1" x="581.2" y="350" width="478.79999999999995" height="72" rx="9" class="c-security-group" stroke-width="1"/>- <text x="591.2" y="348" class="t-security" font-size="7" font-weight="600">Human or policy stop</text>++ <text x="591.2" y="348" class="t-edge-security" font-size="7" font-weight="600">Human or policy stop</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-2" x="204" y="484" width="357.20000000000005" height="72" rx="9" class="c-lane" stroke-width="1"/>- <text x="214" y="482" class="t-messagebus" font-size="7" font-weight="600">Evidence path</text>++ <text x="214" y="482" class="t-edge-dashed" font-size="7" font-weight="600">Evidence path</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-3" x="760" y="484" width="300" height="72" rx="9" class="c-lane" stroke-width="1"/>- <text x="770" y="482" class="t-messagebus" font-size="7" font-weight="600">Tool work</text>++ <text x="770" y="482" class="t-edge-dashed" font-size="7" font-weight="600">Tool work</text><!-- Edge paths -->- <path data-edge-from="user" data-edge-to="chat" data-edge-key="0" data-edge-id="request-chat" data-composition-points="134,119;174,119" d="M 134 119 L 174 119" class="a-default" data-animate="edge" style="--step:0" stroke-width="1.4" marker-end="url(#arrowhead)"/>- <path data-edge-from="chat" data-edge-to="planner" data-edge-label="plan" data-edge-key="1" data-edge-id="plan-request" data-composition-points="220,145;220,166;300,166;300,209" d="M 220 145 L 220 166 L 300 166 L 300 209" class="a-emphasis" data-animate="edge" style="--step:1" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>- <path data-edge-from="planner" data-edge-to="router" data-edge-key="2" data-edge-id="planner-route" data-composition-points="346,243;384,243" d="M 346 243 L 384 243" class="a-default" data-animate="edge" style="--step:2" stroke-width="1.4" marker-end="url(#arrowhead)"/>- <path data-edge-from="router" data-edge-to="approval" data-edge-label="needs approval?" data-edge-key="3" data-edge-id="approval-check" data-composition-points="430,269;430,290;430,290;430,333" d="M 430 269 L 430 290 L 430 290 L 430 333" class="a-security" data-animate="edge" style="--step:3" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>- <path data-edge-from="approval" data-edge-to="tool" data-edge-key="4" data-edge-id="approved-tool" data-composition-points="384,367;356,367;356,615;454,615" d="M 384 367 L 356 367 L 356 615 L 454 615" class="a-emphasis" data-animate="edge" style="--step:4" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>- <path data-edge-from="approval" data-edge-to="blocked" data-edge-label="denied" data-edge-key="5" data-edge-id="approval-denied" data-composition-points="430,401;430,414;500,414;500,465" d="M 430 401 L 430 414 L 500 414 L 500 465" class="a-security" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>- <path data-edge-from="blocked" data-edge-to="retry" data-edge-key="6" data-edge-id="retry-request" data-composition-points="546,491;579,491" d="M 546 491 L 579 491" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>- <path data-edge-from="tool" data-edge-to="external" data-edge-key="7" data-edge-id="tool-external-call" data-composition-points="546,615;579,615" d="M 546 615 L 579 615" class="a-default" data-animate="edge" style="--step:5" stroke-width="1.4" marker-end="url(#arrowhead)"/>- <path data-edge-from="external" data-edge-to="final" data-edge-key="8" data-edge-id="external-reply" data-composition-points="671,615;692,615;692,119;671,119" d="M 671 615 L 692 615 L 692 119 L 671 119" class="a-emphasis" data-animate="edge" style="--step:6" stroke-width="1.2" marker-end="url(#arrowhead-emphasis)"/>- <path data-edge-from="external" data-edge-to="trace" data-edge-label="record result" data-edge-key="9" data-edge-id="record-result" data-composition-points="625,641;625,797;500,797;500,765" d="M 625 641 L 625 797 L 500 797 L 500 765" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>- <path data-edge-from="store" data-edge-to="trace" data-edge-label="trace + memory" data-edge-key="10" data-edge-id="write-trace-memory" data-composition-points="266,739;454,739" d="M 266 739 L 454 739" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>+ <path data-edge-from="router" data-edge-to="approval" data-edge-label="needs approval?" data-edge-key="0" data-edge-id="approval-check" data-composition-points="651.2,279;651.2,302;569.2,302;569.2,387;585.2,387" d="M 651.2 279 L 651.2 302 L 569.2 302 L 569.2 387 L 585.2 387" class="a-security" data-animate="edge" style="--step:3" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>+ <path data-edge-from="approval" data-edge-to="blocked" data-edge-label="denied" data-edge-key="1" data-edge-id="approval-denied" data-composition-points="651.2,421;651.2,442;830,442;830,413" d="M 651.2 421 L 651.2 442 L 830 442 L 830 413" class="a-security" data-animate="edge" style="--step:9" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>+ <path data-edge-from="approval" data-edge-to="tool" data-edge-key="2" data-edge-id="approved-tool" data-composition-points="651.2,421;651.2,521;764,521" d="M 651.2 421 L 651.2 521 L 764 521" class="a-emphasis" data-animate="edge" style="--step:4" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>+ <path data-edge-from="external" data-edge-to="final" data-edge-key="3" data-edge-id="external-reply" data-composition-points="1056,521;1080,521;1080,120;1056,120" d="M 1056 521 L 1080 521 L 1080 120 L 1056 120" class="a-emphasis" data-animate="edge" style="--step:6" stroke-width="1.2" marker-end="url(#arrowhead-emphasis)"/>+ <path data-edge-from="chat" data-edge-to="planner" data-edge-label="plan" data-edge-key="4" data-edge-id="plan-request" data-composition-points="274,146;274,253;425.2,253" d="M 274 146 L 274 253 L 425.2 253" class="a-emphasis" data-animate="edge" style="--step:1" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>+ <path data-edge-from="planner" data-edge-to="router" data-edge-key="5" data-edge-id="planner-route" data-composition-points="557.2,253;585.2,253" d="M 557.2 253 L 585.2 253" class="a-default" data-animate="edge" style="--step:2" stroke-width="1.4" marker-end="url(#arrowhead)"/>+ <path data-edge-from="external" data-edge-to="trace" data-edge-label="record result" data-edge-key="6" data-edge-id="record-result" data-composition-points="990,547;990,579;491.2,579;491.2,547" d="M 990 547 L 990 579 L 491.2 579 L 491.2 547" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>+ <path data-edge-from="user" data-edge-to="chat" data-edge-key="7" data-edge-id="request-chat" data-composition-points="180,120;208,120" d="M 180 120 L 208 120" class="a-default" data-animate="edge" style="--step:0" stroke-width="1.4" marker-end="url(#arrowhead)"/>+ <path data-edge-from="blocked" data-edge-to="retry" data-edge-key="8" data-edge-id="retry-request" data-composition-points="896,387;924,387" d="M 896 387 L 924 387" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>+ <path data-edge-from="tool" data-edge-to="external" data-edge-key="9" data-edge-id="tool-external-call" data-composition-points="896,521;924,521" d="M 896 521 L 924 521" class="a-default" data-animate="edge" style="--step:5" stroke-width="1.4" marker-end="url(#arrowhead)"/>+ <path data-edge-from="store" data-edge-to="trace" data-edge-label="trace + memory" data-edge-key="10" data-edge-id="write-trace-memory" data-composition-points="340,521;425.2,521" d="M 340 521 L 425.2 521" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/><!-- Nodes --><g id="node-user" data-node-id="user" data-node-label="User" tabindex="0" role="button" aria-label="Focus User, asks for work, User Interface › Intake" aria-pressed="false" data-node-kind="external" data-node-sublabel="asks for work" data-node-context="User Interface › Intake">@@@ -5238,31 -5228,31 +5234,31 @@@</g><!-- Edge labels -->-- <g data-detail="context" data-edge-from="chat" data-edge-to="planner" data-edge-label="plan" data-edge-key="1" data-edge-id="plan-request">- <rect x="245" y="146" width="30" height="14" rx="3" class="c-mask"/>- <text x="260" y="156" class="t-edge-emphasis" font-size="8" text-anchor="middle">plan</text>+ <g data-detail="context" data-edge-from="router" data-edge-to="approval" data-edge-label="needs approval?" data-edge-key="0" data-edge-id="approval-check">+ <rect x="569.2" y="282" width="82" height="14" rx="3" class="c-mask"/>- <text x="610.2" y="292" class="t-security" font-size="8" text-anchor="middle">needs approval?</text>++ <text x="610.2" y="292" class="t-edge-security" font-size="8" text-anchor="middle">needs approval?</text>+ </g>+ <g data-detail="context" data-edge-from="approval" data-edge-to="blocked" data-edge-label="denied" data-edge-key="1" data-edge-id="approval-denied">+ <rect x="721.2" y="422" width="38.8" height="14" rx="3" class="c-mask"/>- <text x="740.6" y="432" class="t-security" font-size="8" text-anchor="middle">denied</text>++ <text x="740.6" y="432" class="t-edge-security" font-size="8" text-anchor="middle">denied</text></g>- <g data-detail="context" data-edge-from="router" data-edge-to="approval" data-edge-label="needs approval?" data-edge-key="3" data-edge-id="approval-check">- <rect x="423" y="277.5" width="82" height="14" rx="3" class="c-mask"/>- <text x="464" y="287.5" class="t-edge-security" font-size="8" text-anchor="middle">needs approval?</text>++ <g data-detail="context" data-edge-from="chat" data-edge-to="planner" data-edge-label="plan" data-edge-key="4" data-edge-id="plan-request">+ <rect x="334.6" y="233" width="30" height="14" rx="3" class="c-mask"/>- <text x="349.6" y="243" class="t-backend" font-size="8" text-anchor="middle">plan</text>++ <text x="349.6" y="243" class="t-edge-emphasis" font-size="8" text-anchor="middle">plan</text></g>- <g data-detail="context" data-edge-from="approval" data-edge-to="blocked" data-edge-label="denied" data-edge-key="5" data-edge-id="approval-denied">- <rect x="445.6" y="406" width="38.8" height="14" rx="3" class="c-mask"/>- <text x="465" y="416" class="t-edge-security" font-size="8" text-anchor="middle">denied</text>+ <g data-detail="context" data-edge-from="external" data-edge-to="trace" data-edge-label="record result" data-edge-key="6" data-edge-id="record-result">+ <rect x="704.4" y="559" width="72.4" height="14" rx="3" class="c-mask"/>- <text x="740.6" y="569" class="t-database" font-size="8" text-anchor="middle">record result</text>++ <text x="740.6" y="569" class="t-edge-dashed" font-size="8" text-anchor="middle">record result</text></g>- <g data-detail="context" data-edge-from="external" data-edge-to="trace" data-edge-label="record result" data-edge-key="9" data-edge-id="record-result">- <rect x="526.3" y="777" width="72.4" height="14" rx="3" class="c-mask"/>- <text x="562.5" y="787" class="t-edge-dashed" font-size="8" text-anchor="middle">record result</text>- </g><g data-detail="context" data-edge-from="store" data-edge-to="trace" data-edge-label="trace + memory" data-edge-key="10" data-edge-id="write-trace-memory">- <rect x="326.4" y="725" width="77.2" height="14" rx="3" class="c-mask"/>- <text x="365" y="735" class="t-edge-dashed" font-size="8" text-anchor="middle">trace + memory</text>+ <rect x="344" y="501" width="77.2" height="14" rx="3" class="c-mask"/>- <text x="382.6" y="511" class="t-database" font-size="8" text-anchor="middle">trace + memory</text>++ <text x="382.6" y="511" class="t-edge-dashed" font-size="8" text-anchor="middle">trace + memory</text></g><!-- Legend -->diff --cc docs/gallery/manifest.jsonindex 8b14a71a,d75d682f..7afd1a44--- a/docs/gallery/manifest.json+++ b/docs/gallery/manifest.json@@@ -27,10 -27,10 +27,10 @@@"engineeringProfile": null,"nodeCount": 12,"edgeCount": 11,- "artifactBytes": 720788,- "artifactSha256": "76322a20d6dace7c37ba81f8ca8a93f95ae7f56d56b4bf2124ff62123ac321dc",- "sourceBytes": 6367,- "sourceSha256": "9c94c8c0b2104478b77befb4cc5e343d381acba6e66645ab17616fde20b60e05",- "artifactBytes": 723038,- "artifactSha256": "e083cfe2d35701472374910e922ebdf8b30fdd3d5547d0e2cabd05094d033c66",++ "artifactBytes": 723375,++ "artifactSha256": "1992954ecc4ccea2a7d8f75835ebc429381f9b5ffa8e0d27d9a3dd354071ce9c",+ "sourceBytes": 5687,+ "sourceSha256": "4d3f6c23de2ca7d306e05d0041a9506833bb5a164a2bddc2d1984cf4da3ee90c","checks": [{"name": "single_svg",@@@ -127,8 -127,8 +127,8 @@@"engineeringProfile": "deployment-ownership","nodeCount": 12,"edgeCount": 12,- "artifactBytes": 724872,- "artifactSha256": "dbf6d1b3cffa610f2e538cca3b9aa1c65eb45f580154f316d97c157d90916faa",+ "artifactBytes": 725205,- "artifactSha256": "2599b3e126c3d18cf2300a2cc83efa6a7fd6cd3a67c6d209daea6eabc6f5245f",++ "artifactSha256": "9aedac2719539c54d88a3919553fd2d664841f5198da98582991a1f254dc2089","sourceBytes": 5476,"sourceSha256": "ec484aa8576664fdb207b543fa49486b23273faccb7a5071e1a0becfb48c22eb","checks": [@@@ -227,8 -227,8 +227,8 @@@"engineeringProfile": null,"nodeCount": 7,"edgeCount": 12,- "artifactBytes": 716842,- "artifactSha256": "6bf688c8577049973ace979ac73292eda0cc8f349934c6ba4452720853ced84c",+ "artifactBytes": 717130,- "artifactSha256": "94d067515da75d17d1ed25b406831b71c17f74bc750e8804023f790c011fa1ba",++ "artifactSha256": "701f624494c36350433eaee1bca6747b15838be6c2ff7b9cdcc971014c74fbe8","sourceBytes": 4345,"sourceSha256": "4bbaa6ca3cd4036002fd5d0f3a332eb922cec69d09bac3d7925f95beb4308389","checks": [@@@ -327,8 -327,8 +327,8 @@@"engineeringProfile": null,"nodeCount": 10,"edgeCount": 10,- "artifactBytes": 719238,- "artifactSha256": "358289f1aee93c3bf1075ce95372325ea415c0178f76ce62c868bdc3683cc5f4",+ "artifactBytes": 719571,- "artifactSha256": "9e8f6c4d2f3dac66943175589e60342a11e5347fed6888eac13e8b6ba369208f",++ "artifactSha256": "31b81e8c33e787ace2567da5685eaa6adcf8c8b224a38e2ebbeb37b9eda05e98","sourceBytes": 5164,"sourceSha256": "e5c880417eac1623923c3dd5461e0c78acd762e1621a28bd53fc14a84cad6a91","checks": [@@@ -427,8 -427,8 +427,8 @@@"engineeringProfile": null,"nodeCount": 11,"edgeCount": 10,- "artifactBytes": 716567,- "artifactSha256": "d50feba56cbba1bf62a19b45f142bc1f964bf6831730a79d2760aadcf106542a",+ "artifactBytes": 716886,- "artifactSha256": "ca28468ccc905e04a5ea1e77c26c6028cbdd1f0ed36ad28eb21fd05851ef5a83",++ "artifactSha256": "e1ae74cb033215bc0f29e00712b938ec4d4368befcaeadc2cd56dcbfffb7534a","sourceBytes": 5375,"sourceSha256": "5c760c82eee545dfb7da38a4e628059d7891af4cfbfc13c8a7009ea64f69aa1b","checks": [@@@ -527,8 -527,8 +527,8 @@@"engineeringProfile": null,"nodeCount": 10,"edgeCount": 10,- "artifactBytes": 720496,- "artifactSha256": "d66d70595448044a92d032738e2437980d2160462f974a1de8cfa82c5e148d54",+ "artifactBytes": 720833,- "artifactSha256": "3bb96e400186da5e47b81d545b2c079fcd5579d535199f2680689cf3ad416a8a",++ "artifactSha256": "914129ff263b0cdcd7b5630b80eeb08d0a76d4adc3a04f292cd223cbeacbe555","sourceBytes": 5627,"sourceSha256": "6fa38a7ccedf96da592d60b392783b846188eaa3ec9136c6dc06ca020e43a110","checks": [@@@ -627,8 -627,8 +627,8 @@@"engineeringProfile": null,"nodeCount": 7,"edgeCount": 14,- "artifactBytes": 717252,- "artifactSha256": "c4d7cb0eaecfeff4d713b8f3b36b916840d6530f08e9b698ded308effd3ff59b",+ "artifactBytes": 717540,- "artifactSha256": "039714fbb6d2a698cdd38aa973d61f352ad170027333242f22758f9cef2eaa14",++ "artifactSha256": "0b84c8244f7dc1f0fb5831a278c8e909d99eb4cbb028740b57a85612e16997c9","sourceBytes": 4370,"sourceSha256": "545f20920c89b69c2bb1f15508d5543fddbeb15cffba61e102206e04bd5a5cd9","checks": [@@@ -727,8 -727,8 +727,8 @@@"engineeringProfile": null,"nodeCount": 12,"edgeCount": 12,- "artifactBytes": 724459,- "artifactSha256": "cab32bd06250fdc18f7d25e7562407af9b2e2a37f9ca65c6a852716f7faf1892",+ "artifactBytes": 724813,- "artifactSha256": "425a1d62302d50dff13a5ab1aa2ac6e7c52fea8a35e2e83b75f0cd10d1bc06a8",++ "artifactSha256": "093c9615cbec70afac11139f8d046ce27b9d9c9bd81f5c7dc7454b58d8347e91","sourceBytes": 5433,"sourceSha256": "a92d6597ddbe164f395da32a7d4b33cfae08edd7d9600a6fb45a2058e5bbb43e","checks": [@@@ -827,8 -827,8 +827,8 @@@"engineeringProfile": null,"nodeCount": 10,"edgeCount": 6,- "artifactBytes": 714131,- "artifactSha256": "d15306112803fe6ac1050c6fd5d943545a5bc6a72a0407cd0751d0d8794f6429",+ "artifactBytes": 714419,- "artifactSha256": "bd13f1cb147fed53002efe600b11a4e1d8a75e3a13b08644daf010cdbf790468",++ "artifactSha256": "1363d2fffd62c21d95a6c0af4d2eb698b88f56561c883034bd34065c84a09a2c","sourceBytes": 4417,"sourceSha256": "af939579dcafc8b4c49f09594591577994398aee57a57369d4c791dfc0d85a42","checks": [@@@ -927,8 -927,8 +927,8 @@@"engineeringProfile": null,"nodeCount": 11,"edgeCount": 6,- "artifactBytes": 715123,- "artifactSha256": "2b41af0f84ff5cdbe21f0d672d1d9825eab246b3e7fbaa0237c49042bf28547d",+ "artifactBytes": 715411,- "artifactSha256": "a3c6a862830f3a522aad4e7339a406e5bb4b1dcab1969b34d9f0bfb5bdd00dae",++ "artifactSha256": "9556a18d4406c025c8d979a509eaa09e07f6d68064329d0328c04bf0f60422cb","sourceBytes": 4274,"sourceSha256": "735c2c5819266e6ea2a71775b6eefce98b53030ce90cb721dc8e1d022ce5be71","checks": [@@@ -1027,8 -1027,8 +1027,8 @@@"engineeringProfile": null,"nodeCount": 10,"edgeCount": 9,- "artifactBytes": 715216,- "artifactSha256": "26784b847623e79727e44eb5fabfbedc2c47289bf877703eee78787a3eb5bee5",+ "artifactBytes": 715531,- "artifactSha256": "caed76c7d2bf84b8c166757780bbe919a2b3c1919772e19bfcd17a742aa6a49d",++ "artifactSha256": "2896f0d59782986081e39bc62bab748a5aea819c18e656d45373ebfebc265e7b","sourceBytes": 3793,"sourceSha256": "483350f5297df682aba4e4a0fa491307ce3d3abd725ae4df07fab177490752cf","checks": [diff --cc examples/checkout-platform-delta.receipt.jsonindex 1f18d1cd,1e37e685..79c8a05b--- a/examples/checkout-platform-delta.receipt.json+++ b/examples/checkout-platform-delta.receipt.json@@@ -219,8 -219,8 +219,8 @@@"Boundary identity is conservatively derived from kind + label."],"artifact": {- "sha256": "284b9fc35989f8785945071c2ff0cb82f887905fcf765b6be63cfbb0d759416d",- "bytes": 2024987- "sha256": "b509920b635dc816d7b0f9848bec5bbbf0b77a049ccb50225afbd1dae7a62e39",- "bytes": 2023841++ "sha256": "3f088518d125762a3a603ab48b8db2324be2ea046a9b077329236af4502a6343",++ "bytes": 2025086},"validation": {"checksPassed": 28,diff --cc examples/workflow-agent-tool-call-rendered.htmlindex 36d95fbd,0fb6bb9a..a4c89f72--- a/examples/workflow-agent-tool-call-rendered.html+++ b/examples/workflow-agent-tool-call-rendered.html@@@ -5036,56 -5030,52 +5036,52 @@@<rect width="100%" height="100%" fill="url(#grid)" /><!-- Swimlanes -->- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-0" x="40" y="52" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-0" x="40" y="52" width="1028" height="106" rx="10" class="c-lane" stroke-width="1"/><text x="54" y="74" class="t-dim" font-size="10" font-weight="600">01 / User Interface</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-1" x="40" y="176" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <text x="54" y="198" class="t-dim" font-size="10" font-weight="600">02 / Agent Runtime</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-1" x="40" y="178" width="1028" height="114" rx="10" class="c-lane" stroke-width="1"/>+ <text x="54" y="200" class="t-dim" font-size="10" font-weight="600">02 / Agent Runtime</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-2" x="40" y="300" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <text x="54" y="322" class="t-dim" font-size="10" font-weight="600">03 / Policy Boundary</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-2" x="40" y="312" width="1028" height="114" rx="10" class="c-lane" stroke-width="1"/>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="exception-lane" data-composition-frame-id="lane-2-exception" x="46" y="318" width="1016" height="102" rx="8" class="c-security-group" stroke-width="1"/>+ <text x="54" y="334" class="t-security" font-size="10" font-weight="600">EX / Policy & Recovery</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-3" x="40" y="424" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <rect data-graph-role="structural-frame" data-composition-frame-kind="exception-lane" data-composition-frame-id="lane-3-exception" x="46" y="430" width="628" height="92" rx="8" class="c-security-group" stroke-width="1"/>- <text x="54" y="446" class="t-security" font-size="10" font-weight="600">EX / Exception Handling</text>-- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-4" x="40" y="548" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <text x="54" y="570" class="t-dim" font-size="10" font-weight="600">05 / Tool Execution</text>-- <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-5" x="40" y="672" width="640" height="104" rx="10" class="c-lane" stroke-width="1"/>- <text x="54" y="694" class="t-dim" font-size="10" font-weight="600">06 / Observability</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="lane" data-composition-frame-id="lane-3" x="40" y="446" width="1028" height="114" rx="10" class="c-lane" stroke-width="1"/>+ <text x="54" y="468" class="t-dim" font-size="10" font-weight="600">04 / Tool Execution & Evidence</text><!-- Phase headers -->- <line x1="42" y1="35" x2="266" y2="35" class="a-default" stroke-width="1.1"/>- <rect x="42" y="27" width="224" height="16" rx="4" class="c-mask"/>- <text x="154" y="39" class="t-edge-default" font-size="8" font-weight="600" text-anchor="middle">Intake</text>- <line x1="254" y1="35" x2="476" y2="35" class="a-emphasis" stroke-width="1.1"/>- <rect x="254" y="27" width="222" height="16" rx="4" class="c-mask"/>- <text x="365" y="39" class="t-edge-emphasis" font-size="8" font-weight="600" text-anchor="middle">Plan + route</text>- <line x1="454" y1="35" x2="671" y2="35" class="a-dashed" stroke-width="1.1"/>- <rect x="454" y="27" width="217" height="16" rx="4" class="c-mask"/>- <text x="562.5" y="39" class="t-edge-dashed" font-size="8" font-weight="600" text-anchor="middle">Execute + report</text>+ <line x1="68" y1="35" x2="320" y2="35" class="a-default" stroke-width="1.1"/>+ <rect x="68" y="27" width="252" height="16" rx="4" class="c-mask"/>- <text x="194" y="39" class="t-muted" font-size="8" font-weight="600" text-anchor="middle">Intake</text>++ <text x="194" y="39" class="t-edge-default" font-size="8" font-weight="600" text-anchor="middle">Intake</text>+ <line x1="445.20000000000005" y1="35" x2="697.2" y2="35" class="a-emphasis" stroke-width="1.1"/>+ <rect x="445.20000000000005" y="27" width="252.00000000000006" height="16" rx="4" class="c-mask"/>- <text x="571.2" y="39" class="t-backend" font-size="8" font-weight="600" text-anchor="middle">Plan + route</text>++ <text x="571.2" y="39" class="t-edge-emphasis" font-size="8" font-weight="600" text-anchor="middle">Plan + route</text>+ <line x1="784" y1="35" x2="1036" y2="35" class="a-dashed" stroke-width="1.1"/>+ <rect x="784" y="27" width="252" height="16" rx="4" class="c-mask"/>- <text x="910" y="39" class="t-messagebus" font-size="8" font-weight="600" text-anchor="middle">Execute + report</text>++ <text x="910" y="39" class="t-edge-dashed" font-size="8" font-weight="600" text-anchor="middle">Execute + report</text><!-- Workflow groups -->- <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-0" x="250" y="214" width="230" height="58" rx="9" class="c-lane" stroke-width="1"/>- <text x="260" y="228" class="t-edge-emphasis" font-size="7" font-weight="600">Planning loop</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-1" x="450" y="586" width="225" height="58" rx="9" class="c-lane" stroke-width="1"/>- <text x="460" y="600" class="t-edge-dashed" font-size="7" font-weight="600">Tool work</text>- <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-2" x="380" y="462" width="295" height="58" rx="9" class="c-security-group" stroke-width="1"/>- <text x="390" y="476" class="t-edge-security" font-size="7" font-weight="600">Human or policy stop</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-0" x="421.2" y="216" width="300.00000000000006" height="72" rx="9" class="c-lane" stroke-width="1"/>- <text x="431.2" y="214" class="t-backend" font-size="7" font-weight="600">Planning loop</text>++ <text x="431.2" y="214" class="t-edge-emphasis" font-size="7" font-weight="600">Planning loop</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-1" x="581.2" y="350" width="478.79999999999995" height="72" rx="9" class="c-security-group" stroke-width="1"/>- <text x="591.2" y="348" class="t-security" font-size="7" font-weight="600">Human or policy stop</text>++ <text x="591.2" y="348" class="t-edge-security" font-size="7" font-weight="600">Human or policy stop</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-2" x="204" y="484" width="357.20000000000005" height="72" rx="9" class="c-lane" stroke-width="1"/>- <text x="214" y="482" class="t-messagebus" font-size="7" font-weight="600">Evidence path</text>++ <text x="214" y="482" class="t-edge-dashed" font-size="7" font-weight="600">Evidence path</text>+ <rect data-graph-role="structural-frame" data-composition-frame-kind="group" data-composition-frame-id="group-3" x="760" y="484" width="300" height="72" rx="9" class="c-lane" stroke-width="1"/>- <text x="770" y="482" class="t-messagebus" font-size="7" font-weight="600">Tool work</text>++ <text x="770" y="482" class="t-edge-dashed" font-size="7" font-weight="600">Tool work</text><!-- Edge paths -->- <path data-edge-from="user" data-edge-to="chat" data-edge-key="0" data-edge-id="request-chat" data-composition-points="134,119;174,119" d="M 134 119 L 174 119" class="a-default" data-animate="edge" style="--step:0" stroke-width="1.4" marker-end="url(#arrowhead)"/>- <path data-edge-from="chat" data-edge-to="planner" data-edge-label="plan" data-edge-key="1" data-edge-id="plan-request" data-composition-points="220,145;220,166;300,166;300,209" d="M 220 145 L 220 166 L 300 166 L 300 209" class="a-emphasis" data-animate="edge" style="--step:1" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>- <path data-edge-from="planner" data-edge-to="router" data-edge-key="2" data-edge-id="planner-route" data-composition-points="346,243;384,243" d="M 346 243 L 384 243" class="a-default" data-animate="edge" style="--step:2" stroke-width="1.4" marker-end="url(#arrowhead)"/>- <path data-edge-from="router" data-edge-to="approval" data-edge-label="needs approval?" data-edge-key="3" data-edge-id="approval-check" data-composition-points="430,269;430,290;430,290;430,333" d="M 430 269 L 430 290 L 430 290 L 430 333" class="a-security" data-animate="edge" style="--step:3" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>- <path data-edge-from="approval" data-edge-to="tool" data-edge-key="4" data-edge-id="approved-tool" data-composition-points="384,367;356,367;356,615;454,615" d="M 384 367 L 356 367 L 356 615 L 454 615" class="a-emphasis" data-animate="edge" style="--step:4" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>- <path data-edge-from="approval" data-edge-to="blocked" data-edge-label="denied" data-edge-key="5" data-edge-id="approval-denied" data-composition-points="430,401;430,414;500,414;500,465" d="M 430 401 L 430 414 L 500 414 L 500 465" class="a-security" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>- <path data-edge-from="blocked" data-edge-to="retry" data-edge-key="6" data-edge-id="retry-request" data-composition-points="546,491;579,491" d="M 546 491 L 579 491" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>- <path data-edge-from="tool" data-edge-to="external" data-edge-key="7" data-edge-id="tool-external-call" data-composition-points="546,615;579,615" d="M 546 615 L 579 615" class="a-default" data-animate="edge" style="--step:5" stroke-width="1.4" marker-end="url(#arrowhead)"/>- <path data-edge-from="external" data-edge-to="final" data-edge-key="8" data-edge-id="external-reply" data-composition-points="671,615;692,615;692,119;671,119" d="M 671 615 L 692 615 L 692 119 L 671 119" class="a-emphasis" data-animate="edge" style="--step:6" stroke-width="1.2" marker-end="url(#arrowhead-emphasis)"/>- <path data-edge-from="external" data-edge-to="trace" data-edge-label="record result" data-edge-key="9" data-edge-id="record-result" data-composition-points="625,641;625,797;500,797;500,765" d="M 625 641 L 625 797 L 500 797 L 500 765" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>- <path data-edge-from="store" data-edge-to="trace" data-edge-label="trace + memory" data-edge-key="10" data-edge-id="write-trace-memory" data-composition-points="266,739;454,739" d="M 266 739 L 454 739" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>+ <path data-edge-from="router" data-edge-to="approval" data-edge-label="needs approval?" data-edge-key="0" data-edge-id="approval-check" data-composition-points="651.2,279;651.2,302;569.2,302;569.2,387;585.2,387" d="M 651.2 279 L 651.2 302 L 569.2 302 L 569.2 387 L 585.2 387" class="a-security" data-animate="edge" style="--step:3" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>+ <path data-edge-from="approval" data-edge-to="blocked" data-edge-label="denied" data-edge-key="1" data-edge-id="approval-denied" data-composition-points="651.2,421;651.2,442;830,442;830,413" d="M 651.2 421 L 651.2 442 L 830 442 L 830 413" class="a-security" data-animate="edge" style="--step:9" stroke-width="1.4" marker-end="url(#arrowhead-security)"/>+ <path data-edge-from="approval" data-edge-to="tool" data-edge-key="2" data-edge-id="approved-tool" data-composition-points="651.2,421;651.2,521;764,521" d="M 651.2 421 L 651.2 521 L 764 521" class="a-emphasis" data-animate="edge" style="--step:4" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>+ <path data-edge-from="external" data-edge-to="final" data-edge-key="3" data-edge-id="external-reply" data-composition-points="1056,521;1080,521;1080,120;1056,120" d="M 1056 521 L 1080 521 L 1080 120 L 1056 120" class="a-emphasis" data-animate="edge" style="--step:6" stroke-width="1.2" marker-end="url(#arrowhead-emphasis)"/>+ <path data-edge-from="chat" data-edge-to="planner" data-edge-label="plan" data-edge-key="4" data-edge-id="plan-request" data-composition-points="274,146;274,253;425.2,253" d="M 274 146 L 274 253 L 425.2 253" class="a-emphasis" data-animate="edge" style="--step:1" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>+ <path data-edge-from="planner" data-edge-to="router" data-edge-key="5" data-edge-id="planner-route" data-composition-points="557.2,253;585.2,253" d="M 557.2 253 L 585.2 253" class="a-default" data-animate="edge" style="--step:2" stroke-width="1.4" marker-end="url(#arrowhead)"/>+ <path data-edge-from="external" data-edge-to="trace" data-edge-label="record result" data-edge-key="6" data-edge-id="record-result" data-composition-points="990,547;990,579;491.2,579;491.2,547" d="M 990 547 L 990 579 L 491.2 579 L 491.2 547" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>+ <path data-edge-from="user" data-edge-to="chat" data-edge-key="7" data-edge-id="request-chat" data-composition-points="180,120;208,120" d="M 180 120 L 208 120" class="a-default" data-animate="edge" style="--step:0" stroke-width="1.4" marker-end="url(#arrowhead)"/>+ <path data-edge-from="blocked" data-edge-to="retry" data-edge-key="8" data-edge-id="retry-request" data-composition-points="896,387;924,387" d="M 896 387 L 924 387" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/>+ <path data-edge-from="tool" data-edge-to="external" data-edge-key="9" data-edge-id="tool-external-call" data-composition-points="896,521;924,521" d="M 896 521 L 924 521" class="a-default" data-animate="edge" style="--step:5" stroke-width="1.4" marker-end="url(#arrowhead)"/>+ <path data-edge-from="store" data-edge-to="trace" data-edge-label="trace + memory" data-edge-key="10" data-edge-id="write-trace-memory" data-composition-points="340,521;425.2,521" d="M 340 521 L 425.2 521" class="a-dashed" data-animate="edge" style="--step:12" stroke-width="1.4" marker-end="url(#arrowhead-dashed)"/><!-- Nodes --><g id="node-user" data-node-id="user" data-node-label="User" tabindex="0" role="button" aria-label="Focus User, asks for work, User Interface › Intake" aria-pressed="false" data-node-kind="external" data-node-sublabel="asks for work" data-node-context="User Interface › Intake">@@@ -5238,31 -5228,31 +5234,31 @@@</g><!-- Edge labels -->-- <g data-detail="context" data-edge-from="chat" data-edge-to="planner" data-edge-label="plan" data-edge-key="1" data-edge-id="plan-request">- <rect x="245" y="146" width="30" height="14" rx="3" class="c-mask"/>- <text x="260" y="156" class="t-edge-emphasis" font-size="8" text-anchor="middle">plan</text>+ <g data-detail="context" data-edge-from="router" data-edge-to="approval" data-edge-label="needs approval?" data-edge-key="0" data-edge-id="approval-check">+ <rect x="569.2" y="282" width="82" height="14" rx="3" class="c-mask"/>- <text x="610.2" y="292" class="t-security" font-size="8" text-anchor="middle">needs approval?</text>++ <text x="610.2" y="292" class="t-edge-security" font-size="8" text-anchor="middle">needs approval?</text>+ </g>+ <g data-detail="context" data-edge-from="approval" data-edge-to="blocked" data-edge-label="denied" data-edge-key="1" data-edge-id="approval-denied">+ <rect x="721.2" y="422" width="38.8" height="14" rx="3" class="c-mask"/>- <text x="740.6" y="432" class="t-security" font-size="8" text-anchor="middle">denied</text>++ <text x="740.6" y="432" class="t-edge-security" font-size="8" text-anchor="middle">denied</text></g>- <g data-detail="context" data-edge-from="router" data-edge-to="approval" data-edge-label="needs approval?" data-edge-key="3" data-edge-id="approval-check">- <rect x="423" y="277.5" width="82" height="14" rx="3" class="c-mask"/>- <text x="464" y="287.5" class="t-edge-security" font-size="8" text-anchor="middle">needs approval?</text>++ <g data-detail="context" data-edge-from="chat" data-edge-to="planner" data-edge-label="plan" data-edge-key="4" data-edge-id="plan-request">+ <rect x="334.6" y="233" width="30" height="14" rx="3" class="c-mask"/>- <text x="349.6" y="243" class="t-backend" font-size="8" text-anchor="middle">plan</text>++ <text x="349.6" y="243" class="t-edge-emphasis" font-size="8" text-anchor="middle">plan</text></g>- <g data-detail="context" data-edge-from="approval" data-edge-to="blocked" data-edge-label="denied" data-edge-key="5" data-edge-id="approval-denied">- <rect x="445.6" y="406" width="38.8" height="14" rx="3" class="c-mask"/>- <text x="465" y="416" class="t-edge-security" font-size="8" text-anchor="middle">denied</text>+ <g data-detail="context" data-edge-from="external" data-edge-to="trace" data-edge-label="record result" data-edge-key="6" data-edge-id="record-result">+ <rect x="704.4" y="559" width="72.4" height="14" rx="3" class="c-mask"/>- <text x="740.6" y="569" class="t-database" font-size="8" text-anchor="middle">record result</text>++ <text x="740.6" y="569" class="t-edge-dashed" font-size="8" text-anchor="middle">record result</text></g>- <g data-detail="context" data-edge-from="external" data-edge-to="trace" data-edge-label="record result" data-edge-key="9" data-edge-id="record-result">- <rect x="526.3" y="777" width="72.4" height="14" rx="3" class="c-mask"/>- <text x="562.5" y="787" class="t-edge-dashed" font-size="8" text-anchor="middle">record result</text>- </g><g data-detail="context" data-edge-from="store" data-edge-to="trace" data-edge-label="trace + memory" data-edge-key="10" data-edge-id="write-trace-memory">- <rect x="326.4" y="725" width="77.2" height="14" rx="3" class="c-mask"/>- <text x="365" y="735" class="t-edge-dashed" font-size="8" text-anchor="middle">trace + memory</text>+ <rect x="344" y="501" width="77.2" height="14" rx="3" class="c-mask"/>- <text x="382.6" y="511" class="t-database" font-size="8" text-anchor="middle">trace + memory</text>++ <text x="382.6" y="511" class="t-edge-dashed" font-size="8" text-anchor="middle">trace + memory</text></g><!-- Legend -->