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
fix(workflow): move a label that overflows its short preferred run instead of detouring the edge
tt-a1i62c245b78ac1
diff --git a/archify/renderers/workflow/workflow-compiler.mjs b/archify/renderers/workflow/workflow-compiler.mjsindex 5ce9f205..90c9785f 100644--- a/archify/renderers/workflow/workflow-compiler.mjs+++ b/archify/renderers/workflow/workflow-compiler.mjs@@ -4177,10 +4177,36 @@ function workflowEdgeLabelPoint(edge, points) {|| 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;+ const pointOn = (labelSegment) => {+ const point = labelPoint({ ...edge, labelSegment }, points);+ if (points[labelSegment][0] === points[labelSegment + 1][0]) point[1] += 10;+ return point;+ };+ // The longest horizontal run is the preferred home, but a run shorter than+ // its label pushes the label onto a node, and the planner then detours the+ // whole edge to manufacture a longer run. When the preferred run is that+ // short, use the next run that keeps the label clear of every node and+ // inside one lane, off the lane dividers, before giving up on it.+ const width = workflowLabelWidth(edge.label);+ const clearOfNodes = ([lx, ly]) => {+ const rect = { x: lx - width / 2, y: ly - 10, width, height: 14 };+ return ![...nodes.values()].some((node) => rectsOverlap(rect, node, -2));+ };+ const insideOneLane = ([lx, ly]) => lx - width / 2 >= layout.laneX + 4+ && lx + width / 2 <= layout.laneX + layout.laneW - 4+ && asArray(workflow.lanes).some((lane, index) => {+ const top = laneTop(lane.id);+ return ly - 10 >= top + 4 && ly + 4 <= top + laneHeight(index) - 4;+ });+ const preferred = pointOn(segments[0]?.index ?? 0);+ if (!edge.label || !segments[0]?.horizontal || segments[0].length >= width + 8+ || clearOfNodes(preferred)) return preferred;+ for (const segment of segments.slice(1)) {+ if (segment.length < 28) continue;+ const point = pointOn(segment.index);+ if (clearOfNodes(point) && insideOneLane(point)) return point;+ }+ return preferred;}function edgeSides(edge) {diff --git a/test/fixtures/workflow-first-draft/incident-response.workflow.json b/test/fixtures/workflow-first-draft/incident-response.workflow.jsonnew file mode 100644index 00000000..b2869c72--- /dev/null+++ b/test/fixtures/workflow-first-draft/incident-response.workflow.json@@ -0,0 +1,135 @@+{+ "schema_version": 2,+ "diagram_type": "workflow",+ "meta": {+ "title": "Incident response",+ "locale": "en",+ "quality_profile": "showcase",+ "output": "incident-en.html"+ },+ "lanes": [+ {+ "id": "mon",+ "label": "Monitoring"+ },+ {+ "id": "oncall",+ "label": "On-call"+ },+ {+ "id": "eng",+ "label": "Service team"+ },+ {+ "id": "comms",+ "label": "Comms"+ }+ ],+ "nodes": [+ {+ "id": "alert",+ "lane": "mon",+ "col": 0,+ "type": "messagebus",+ "label": "Alert fires",+ "sublabel": "SLO burn"+ },+ {+ "id": "ack",+ "lane": "oncall",+ "col": 1,+ "type": "backend",+ "label": "Acknowledge",+ "sublabel": "within 5 min"+ },+ {+ "id": "triage",+ "lane": "oncall",+ "col": 2,+ "type": "backend",+ "label": "Triage",+ "sublabel": "severity"+ },+ {+ "id": "fix",+ "lane": "eng",+ "col": 3,+ "type": "backend",+ "label": "Mitigate",+ "sublabel": "rollback / flag"+ },+ {+ "id": "status",+ "lane": "comms",+ "col": 3,+ "type": "frontend",+ "label": "Status page",+ "sublabel": "public update"+ },+ {+ "id": "verify",+ "lane": "mon",+ "col": 4,+ "type": "messagebus",+ "label": "Verify recovery",+ "sublabel": "SLO green"+ },+ {+ "id": "review",+ "lane": "eng",+ "col": 5,+ "type": "backend",+ "label": "Postmortem",+ "sublabel": "within 3 days"+ }+ ],+ "edges": [+ {+ "from": "alert",+ "to": "ack",+ "label": "page"+ },+ {+ "from": "ack",+ "to": "triage",+ "label": "acknowledged"+ },+ {+ "from": "triage",+ "to": "fix",+ "label": "SEV1/2"+ },+ {+ "from": "triage",+ "to": "status",+ "label": "customer impact",+ "role": "async",+ "variant": "dashed"+ },+ {+ "from": "fix",+ "to": "verify",+ "label": "deployed"+ },+ {+ "from": "verify",+ "to": "fix",+ "label": "still failing",+ "role": "error",+ "variant": "security"+ },+ {+ "from": "verify",+ "to": "review",+ "label": "resolved"+ }+ ],+ "mainPath": [+ "alert",+ "ack",+ "triage",+ "fix",+ "verify",+ "review"+ ]+}\ No newline at end of filediff --git a/test/workflow-route-order.test.mjs b/test/workflow-route-order.test.mjsindex 481b1c10..6a782fde 100644--- a/test/workflow-route-order.test.mjs+++ b/test/workflow-route-order.test.mjs@@ -39,3 +39,16 @@ test('pinned geometry keeps its own diagnostic: only automatic edges are re-ordeassert.equal(pinned.ok, false);assert.deepEqual(pinned.diagnostics.map((diagnostic) => diagnostic.code), ['workflow/explicit-pin-conflict']);});++// The "customer impact" edge runs from the on-call lane down to the comms lane,+// and its one horizontal stretch is shorter than its 82px label. Keeping+// the label there made the planner detour the edge into a U below its target.+const incident = path.join(__dirname, 'fixtures', 'workflow-first-draft', 'incident-response.workflow.json');++test('a label that does not fit its preferred stretch moves to a run that clears every node, so the edge does not detour to make room', () => {+ const validation = spawnSync(process.execPath, [cli, 'validate', 'workflow', incident, '--quality', 'showcase', '--json'], { encoding: 'utf8' });+ assert.equal(validation.status, 0, validation.stdout + validation.stderr);+ const result = compileWorkflow({ workflow: JSON.parse(fs.readFileSync(incident, 'utf8')) });+ const edge = result.receipt.edges.find((entry) => entry.from === 'triage' && entry.to === 'status');+ assert.deepEqual(edge.points, [[388.6, 269], [388.6, 491], [455.6, 491]]);+});