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): grow readable-v2 nodes to fit their labels
tt-a1i8f1abd4e655b
diff --git a/archify/renderers/workflow/workflow-compiler.mjs b/archify/renderers/workflow/workflow-compiler.mjsindex 9da26d07..1d283030 100644--- a/archify/renderers/workflow/workflow-compiler.mjs+++ b/archify/renderers/workflow/workflow-compiler.mjs@@ -153,8 +153,17 @@ function usesIndependentLaneMeasurement(workflow) {&& !hasAbsoluteWorkflowPins(workflow);}+// A readable-v2 node without an authored width grows to fit its label, up to+// 200px; longer labels still fail the label check. Keyed by the node object so+// the authored document is never rewritten.+const automaticNodeWidths = new WeakMap();+function automaticNodeWidth(node) {+ const fitted = Math.ceil((textUnits(node.label) * 6.8 - 6) / 4) * 4;+ return fitted > 92 ? Math.min(200, fitted) : null;+}+function authoredNodeWidth(node) {- return Number.isFinite(node?.width) ? node.width : 92;+ return Number.isFinite(node?.width) ? node.width : automaticNodeWidths.get(node) ?? 92;}function nodeWidthContributor(node) {@@ -670,6 +679,10 @@ function cloneWorkflow(value) {function canonicalReadableWorkflow(workflow) {if (workflow.schema_version !== 2) return workflow;+ for (const node of asArray(workflow.nodes)) {+ const width = !Number.isFinite(node.width) && automaticNodeWidth(node);+ if (width) automaticNodeWidths.set(node, width);+ }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)@@ -948,7 +961,7 @@ function createWorkflowLaneGeometry(workflow, layout, legendExtraHeight, minimumfunction measureWorkflowNodes(workflow, layout, laneGeometry) {const { laneHeight, laneGroupHeaderH, laneGroupFooterH, laneTop } = laneGeometry;function measureNode(node) {- const width = node.width || layout.nodeW;+ const width = node.width || automaticNodeWidths.get(node) || layout.nodeW;const height = node.height || (node.tag ? 68 : layout.nodeH);const cx = layout.colXs[node.col];const groupHeaderH = laneGroupHeaderH(node.lane);diff --git a/test/workflow-compiler.test.mjs b/test/workflow-compiler.test.mjsindex d34a706f..bbd2e3e9 100644--- a/test/workflow-compiler.test.mjs+++ b/test/workflow-compiler.test.mjs@@ -491,6 +491,15 @@ test('an automatic readable-v2 vertical stack opts into width-first reader fittiassert.equal(attribute(svgRoot, 'data-reader-fit'), 'width-first');});+test('a readable-v2 node without an authored width grows to fit its label', () => {+ const workflow = adjacentWorkflow({ widths: [undefined, undefined], nodeLabels: ['Start', 'TOOL_RESULT 策略'] });+ const before = JSON.stringify(workflow);+ const result = compileSuccessfully(workflow);+ const width = Number(result.svg.match(/data-node-id="b"[\s\S]*?<rect[^>]*width="([\d.]+)"/)[1]);+ assert.equal(JSON.stringify(workflow), before, 'the authored document is not rewritten');+ assert.equal(width, 104);+});+test('an automatic readable-v2 canvas too tall for the desktop page reads at page width', () => {const workflow = adjacentWorkflow();workflow.lanes = Array.from({ length: 6 }, (_, index) => ({ id: `lane-${index}`, label: `Lane ${index}` }));