@radicaltools/mcp 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radicaltools/mcp",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Local MCP server for Radical Markdown model folders.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://radical.tools",
@@ -1,185 +0,0 @@
1
- import {
2
- COLLAPSED_HEIGHT,
3
- COLLAPSED_WIDTH,
4
- ELK_CHILD_SPACING,
5
- ELK_ROOT_SPACING,
6
- isContainerType,
7
- projectToVisibleGraph
8
- } from "./chunk-KI4NVSTU.js";
9
-
10
- // ../../packages/layout/src/elkLayout.ts
11
- import ELK from "elkjs/lib/elk.bundled.js";
12
- var elk = new ELK();
13
- var LAYERED_OPTIONS = {
14
- "elk.algorithm": "layered",
15
- "elk.direction": "DOWN",
16
- // SEPARATE_CHILDREN (default): each compound node is laid out independently.
17
- // Cross-boundary crossing minimisation is handled by our geometric post-process
18
- // (minimizeCrossings in crossingOpt.ts) — safer than INCLUDE_CHILDREN which
19
- // crashes ELK's internal scanline constraint calculator with compound graphs.
20
- // ── Connected-component placement ────────────────────────────────────────
21
- "elk.separateConnectedComponents": "true",
22
- // ── Crossing minimisation ─────────────────────────────────────────────────
23
- "elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
24
- "elk.layered.crossingMinimization.greedySwitch.type": "TWO_SIDED",
25
- "elk.layered.thoroughness": "50",
26
- "elk.layered.considerModelOrder.strategy": "NONE",
27
- // ── Node placement ────────────────────────────────────────────────────────
28
- "elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
29
- // ── Spacing ───────────────────────────────────────────────────────────────
30
- ...ELK_ROOT_SPACING,
31
- // ── Post-layout ──────────────────────────────────────────────────────────
32
- "elk.layered.unnecessaryBendpoints": "true",
33
- "elk.layered.compaction.postCompaction.strategy": "EDGE_LENGTH",
34
- "elk.padding": "[top=120, right=30, bottom=30, left=30]"
35
- };
36
- var CHILD_OPTIONS = {
37
- "elk.algorithm": "layered",
38
- "elk.direction": "RIGHT",
39
- "elk.separateConnectedComponents": "true",
40
- "elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
41
- "elk.layered.crossingMinimization.greedySwitch.type": "TWO_SIDED",
42
- "elk.layered.thoroughness": "50",
43
- "elk.layered.considerModelOrder.strategy": "NONE",
44
- "elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
45
- ...ELK_CHILD_SPACING,
46
- "elk.layered.unnecessaryBendpoints": "true",
47
- "elk.layered.compaction.postCompaction.strategy": "EDGE_LENGTH",
48
- "elk.padding": "[top=110, right=20, bottom=20, left=20]"
49
- };
50
- function ancestorChain(nodeId, nodes) {
51
- const chain = [nodeId];
52
- let cur = nodes[nodeId];
53
- while (cur?.parentId) {
54
- chain.push(cur.parentId);
55
- cur = nodes[cur.parentId];
56
- }
57
- return chain;
58
- }
59
- function lcaContainerId(srcId, tgtId, nodes) {
60
- if (srcId === tgtId) return nodes[srcId]?.parentId;
61
- const srcSet = new Set(ancestorChain(srcId, nodes));
62
- for (const id of ancestorChain(tgtId, nodes)) {
63
- if (srcSet.has(id) && id !== srcId && id !== tgtId) return id;
64
- }
65
- return void 0;
66
- }
67
- function buildElkNode(n, allNodes, elkNodeMap) {
68
- const isCollapsed = n.collapsed && isContainerType(n.type);
69
- const width = isCollapsed ? COLLAPSED_WIDTH[n.type] : n.width;
70
- const height = isCollapsed ? COLLAPSED_HEIGHT[n.type] : n.height;
71
- const childC4 = isCollapsed ? [] : Object.values(allNodes).filter((c) => c.parentId === n.id);
72
- const children = childC4.map((c) => buildElkNode(c, allNodes, elkNodeMap));
73
- const elkNode = {
74
- id: n.id,
75
- width,
76
- height,
77
- layoutOptions: children.length > 0 ? CHILD_OPTIONS : void 0,
78
- children,
79
- edges: []
80
- };
81
- elkNodeMap[n.id] = elkNode;
82
- return elkNode;
83
- }
84
- function parseElkResult(node, result) {
85
- if (node.id !== "root" && node.x != null && node.y != null) {
86
- result[node.id] = { x: node.x, y: node.y, width: node.width, height: node.height };
87
- }
88
- for (const child of node.children ?? []) {
89
- parseElkResult(child, result);
90
- }
91
- }
92
- async function applyElkLayout(inputNodes, inputRelations, opts) {
93
- const { nodes: c4Nodes, relations: c4Relations } = projectToVisibleGraph(inputNodes, inputRelations);
94
- const elkNodeMap = {};
95
- const childOpts = opts?.childOptions ?? CHILD_OPTIONS;
96
- const buildWith = (n) => {
97
- const built = buildElkNode(n, c4Nodes, elkNodeMap);
98
- const apply = (node) => {
99
- if (node.children && node.children.length > 0) {
100
- node.layoutOptions = childOpts;
101
- for (const c of node.children) apply(c);
102
- }
103
- };
104
- apply(built);
105
- return built;
106
- };
107
- const rootChildren = Object.values(c4Nodes).filter((n) => !n.parentId).map(buildWith);
108
- const root = {
109
- id: "root",
110
- layoutOptions: opts?.rootOptions ?? LAYERED_OPTIONS,
111
- children: rootChildren,
112
- edges: []
113
- };
114
- elkNodeMap["root"] = root;
115
- for (const rel of Object.values(c4Relations)) {
116
- if (!c4Nodes[rel.sourceId] || !c4Nodes[rel.targetId]) continue;
117
- const lca = lcaContainerId(rel.sourceId, rel.targetId, c4Nodes);
118
- const container = (lca ? elkNodeMap[lca] : root) ?? root;
119
- const edge = { id: rel.id, sources: [rel.sourceId], targets: [rel.targetId] };
120
- if (!container.edges) container.edges = [];
121
- container.edges.push(edge);
122
- }
123
- try {
124
- const result = await elk.layout(root);
125
- const positions = {};
126
- parseElkResult(result, positions);
127
- return positions;
128
- } catch (err) {
129
- console.error("[ELK] Layout error:", err);
130
- return {};
131
- }
132
- }
133
- var TREE_ROOT_OPTIONS = {
134
- "elk.algorithm": "layered",
135
- "elk.direction": "DOWN",
136
- "elk.separateConnectedComponents": "true",
137
- "elk.spacing.componentComponent": "60",
138
- "elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
139
- "elk.layered.crossingMinimization.greedySwitch.type": "TWO_SIDED",
140
- "elk.layered.thoroughness": "50",
141
- // Honour input order so siblings stay close to their declared grouping —
142
- // the dominant cue users associate with "tree" layouts.
143
- "elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES",
144
- "elk.layered.nodePlacement.strategy": "BRANDES_KOEPF",
145
- "elk.layered.nodePlacement.bk.fixedAlignment": "BALANCED",
146
- "elk.spacing.nodeNode": "50",
147
- "elk.layered.spacing.nodeNodeBetweenLayers": "70",
148
- "elk.spacing.edgeNode": "20",
149
- "elk.spacing.edgeEdge": "10",
150
- "elk.layered.compaction.postCompaction.strategy": "LEFT",
151
- "elk.layered.unnecessaryBendpoints": "true",
152
- "elk.padding": "[top=120, right=30, bottom=30, left=30]"
153
- };
154
- var TREE_CHILD_OPTIONS = {
155
- // Children of every compound container also flow top-down — this is what
156
- // produces the visible "nested tree" look (vs. the default ELK config
157
- // where compound children flow left-to-right).
158
- "elk.algorithm": "layered",
159
- "elk.direction": "DOWN",
160
- "elk.separateConnectedComponents": "true",
161
- "elk.spacing.componentComponent": "30",
162
- "elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
163
- "elk.layered.crossingMinimization.greedySwitch.type": "TWO_SIDED",
164
- "elk.layered.thoroughness": "50",
165
- "elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES",
166
- "elk.layered.nodePlacement.strategy": "BRANDES_KOEPF",
167
- "elk.layered.nodePlacement.bk.fixedAlignment": "BALANCED",
168
- "elk.spacing.nodeNode": "28",
169
- "elk.layered.spacing.nodeNodeBetweenLayers": "40",
170
- "elk.spacing.edgeNode": "12",
171
- "elk.spacing.edgeEdge": "8",
172
- "elk.layered.compaction.postCompaction.strategy": "LEFT",
173
- "elk.layered.unnecessaryBendpoints": "true",
174
- "elk.padding": "[top=110, right=20, bottom=20, left=20]"
175
- };
176
- async function applyTreeLayout(c4Nodes, c4Relations) {
177
- return applyElkLayout(c4Nodes, c4Relations, {
178
- rootOptions: TREE_ROOT_OPTIONS,
179
- childOptions: TREE_CHILD_OPTIONS
180
- });
181
- }
182
- export {
183
- applyElkLayout,
184
- applyTreeLayout
185
- };