whipped 0.8.1 → 0.9.1

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.
Files changed (86) hide show
  1. package/dist/cli.js +1296 -311
  2. package/dist/mcp-server.js +150 -2
  3. package/dist/migrations/014_companion_sessions.sql +34 -0
  4. package/dist/migrations/015_companion_worktree_mode.sql +45 -0
  5. package/dist/migrations/016_companion_plans.sql +22 -0
  6. package/dist/migrations/017_companion_saved_plans.sql +23 -0
  7. package/dist/migrations/018_generalize_plan_session_ref.sql +29 -0
  8. package/dist/migrations/019_rename_plan_to_canvas.sql +20 -0
  9. package/dist/web-ui/assets/abnfDiagram-VRR7QNED-CMDqE9Fd.js +119 -0
  10. package/dist/web-ui/assets/arc-Dbpy-AQ8.js +131 -0
  11. package/dist/web-ui/assets/architectureDiagram-ZJ3FMSHR-BKEqdC5c.js +8821 -0
  12. package/dist/web-ui/assets/blockDiagram-677ZJIJ3-CTsEohS4.js +3801 -0
  13. package/dist/web-ui/assets/c4Diagram-LMCZKHZV-Dn6mvxwq.js +2479 -0
  14. package/dist/web-ui/assets/channel-CGIzRjBJ.js +7 -0
  15. package/dist/web-ui/assets/chunk-2Q5K7J3B-DYVO9tIE.js +17 -0
  16. package/dist/web-ui/assets/chunk-32BRIVSS-CqBj7LwD.js +116 -0
  17. package/dist/web-ui/assets/chunk-5VM5RSS4-D6as2qUK.js +19 -0
  18. package/dist/web-ui/assets/chunk-EX3LRPZG-Daf_kmKB.js +1996 -0
  19. package/dist/web-ui/assets/chunk-JWPE2WC7-Ab-zf2K1.js +17 -0
  20. package/dist/web-ui/assets/chunk-MOJQB5TN-DnYfTlwW.js +855 -0
  21. package/dist/web-ui/assets/chunk-RYQCIY6F-BkiNDZ_4.js +476 -0
  22. package/dist/web-ui/assets/chunk-V7JOEXUC-DCb_30mT.js +2022 -0
  23. package/dist/web-ui/assets/chunk-VR4S4FIN-CO86AkST.js +25 -0
  24. package/dist/web-ui/assets/chunk-XXDRQBXY--g2YuB3U.js +13 -0
  25. package/dist/web-ui/assets/classDiagram-OUVF2IWQ-C25Jck2H.js +24 -0
  26. package/dist/web-ui/assets/classDiagram-v2-EOCWNBFH-C25Jck2H.js +24 -0
  27. package/dist/web-ui/assets/cose-bilkent-JH36ORCC-DhhXza2J.js +4943 -0
  28. package/dist/web-ui/assets/cynefin-VYW2F7L2-CaR1DgV9.js +31527 -0
  29. package/dist/web-ui/assets/cynefinDiagram-TSTJHNR4-CLGnTJf1.js +454 -0
  30. package/dist/web-ui/assets/cytoscape.esm-CaQ7Fomf.js +30346 -0
  31. package/dist/web-ui/assets/dagre-VKFMJZFB-DitV5zjf.js +526 -0
  32. package/dist/web-ui/assets/defaultLocale-B2RvLBDe.js +206 -0
  33. package/dist/web-ui/assets/diagram-FQU43EPY-C1rGhyyl.js +636 -0
  34. package/dist/web-ui/assets/diagram-G47NLZAW-CTQhjAQX.js +858 -0
  35. package/dist/web-ui/assets/diagram-NH7WQ7WH-DI8N7xbl.js +212 -0
  36. package/dist/web-ui/assets/diagram-OA4YK3LP-WcmQFHPD.js +492 -0
  37. package/dist/web-ui/assets/diagram-WEI45ONY-P5J7jo04.js +309 -0
  38. package/dist/web-ui/assets/ebnfDiagram-CCIWWBDH-VgG6WhIs.js +139 -0
  39. package/dist/web-ui/assets/erDiagram-Q63AITRT-aQJn3J15.js +1238 -0
  40. package/dist/web-ui/assets/flowDiagram-23GEKE2U-mdFXB92B.js +2353 -0
  41. package/dist/web-ui/assets/ganttDiagram-NO4QXBWP-CqDgijmY.js +3733 -0
  42. package/dist/web-ui/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  43. package/dist/web-ui/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  44. package/dist/web-ui/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  45. package/dist/web-ui/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  46. package/dist/web-ui/assets/geist-mono-cyrillic-ext-wght-normal-I4S5GZfc.woff2 +0 -0
  47. package/dist/web-ui/assets/geist-mono-cyrillic-wght-normal-BmXc_FBt.woff2 +0 -0
  48. package/dist/web-ui/assets/geist-mono-latin-ext-wght-normal-DrnZ1wKl.woff2 +0 -0
  49. package/dist/web-ui/assets/geist-mono-latin-wght-normal-B_7UjwxQ.woff2 +0 -0
  50. package/dist/web-ui/assets/geist-mono-symbols2-wght-normal-GZpp1pK2.woff2 +0 -0
  51. package/dist/web-ui/assets/geist-mono-vietnamese-wght-normal-D8KDMBhC.woff2 +0 -0
  52. package/dist/web-ui/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  53. package/dist/web-ui/assets/gitGraphDiagram-IHSO6WYX-8juiaoTk.js +1385 -0
  54. package/dist/web-ui/assets/graph-BMLV0goG.js +2042 -0
  55. package/dist/web-ui/assets/{index-CRXPsGTP.css → index-DPjATOCj.css} +800 -1207
  56. package/dist/web-ui/assets/{index-BMFVAmy4.js → index-DddtVpjm.js} +41479 -39640
  57. package/dist/web-ui/assets/infoDiagram-FWYZ7A6U-C2g8E3ea.js +32 -0
  58. package/dist/web-ui/assets/init-ZxktEp_H.js +16 -0
  59. package/dist/web-ui/assets/ishikawaDiagram-FXEZZL3T-cBRjKZAE.js +967 -0
  60. package/dist/web-ui/assets/journeyDiagram-5HDEW3XC-BvGisWzY.js +1256 -0
  61. package/dist/web-ui/assets/kanban-definition-HUTT4EX6-xCU5FVAS.js +1055 -0
  62. package/dist/web-ui/assets/katex-CqNtglxf.js +14499 -0
  63. package/dist/web-ui/assets/layout-BNmRhaUB.js +2359 -0
  64. package/dist/web-ui/assets/linear-uVfTbk22.js +340 -0
  65. package/dist/web-ui/assets/map-BEO0Bu8q.js +298 -0
  66. package/dist/web-ui/assets/mermaid.core-D-SdXkuv.js +26639 -0
  67. package/dist/web-ui/assets/mindmap-definition-LN4V7U3C-BXMrLpcc.js +1183 -0
  68. package/dist/web-ui/assets/ordinal-DSZU4PqD.js +76 -0
  69. package/dist/web-ui/assets/pegDiagram-2B236MQR-4QY6zfTY.js +127 -0
  70. package/dist/web-ui/assets/pieDiagram-ENE6RG2P-CvA8hnwZ.js +318 -0
  71. package/dist/web-ui/assets/quadrantDiagram-ABIIQ3AL-b9LyRoDu.js +1341 -0
  72. package/dist/web-ui/assets/railroadDiagram-RFXS5EU6-xnbYx8zt.js +93 -0
  73. package/dist/web-ui/assets/requirementDiagram-TGXJPOKE-DXgeFZvD.js +1205 -0
  74. package/dist/web-ui/assets/sankeyDiagram-HTMAVEWB-N3WPRpVR.js +1264 -0
  75. package/dist/web-ui/assets/sequenceDiagram-DBY2YBRQ-CasLOrw_.js +4523 -0
  76. package/dist/web-ui/assets/sizeCapture-X5ZJPWSS-DlBvxVbP.js +64 -0
  77. package/dist/web-ui/assets/stateDiagram-2N3HPSRC-fp4Rfa7y.js +453 -0
  78. package/dist/web-ui/assets/stateDiagram-v2-6OUMAXLB-B1Sbo4u9.js +23 -0
  79. package/dist/web-ui/assets/swimlanes-5IMT3BWC-D8woP0NL.js +8575 -0
  80. package/dist/web-ui/assets/swimlanesDiagram-G3AALYLV-BkAvTJ1E.js +21 -0
  81. package/dist/web-ui/assets/timeline-definition-FHXFAJF6-Bri3dfoP.js +1606 -0
  82. package/dist/web-ui/assets/vennDiagram-L72KCM5P-DTZlIjiw.js +2523 -0
  83. package/dist/web-ui/assets/wardleyDiagram-EHGQE667-CCyt_RTI.js +978 -0
  84. package/dist/web-ui/assets/xychartDiagram-FW5EYKEG-DtQR47sr.js +1972 -0
  85. package/dist/web-ui/index.html +2 -2
  86. package/package.json +1 -1
@@ -0,0 +1,476 @@
1
+ import { _ as __name, l as log } from "./mermaid.core-D-SdXkuv.js";
2
+ import { i as isUndefined, G as Graph } from "./graph-BMLV0goG.js";
3
+ import { b as baseClone, m as map } from "./map-BEO0Bu8q.js";
4
+ var CLONE_SYMBOLS_FLAG = 4;
5
+ function clone(value) {
6
+ return baseClone(value, CLONE_SYMBOLS_FLAG);
7
+ }
8
+ function write(g) {
9
+ var json = {
10
+ options: {
11
+ directed: g.isDirected(),
12
+ multigraph: g.isMultigraph(),
13
+ compound: g.isCompound()
14
+ },
15
+ nodes: writeNodes(g),
16
+ edges: writeEdges(g)
17
+ };
18
+ if (!isUndefined(g.graph())) {
19
+ json.value = clone(g.graph());
20
+ }
21
+ return json;
22
+ }
23
+ function writeNodes(g) {
24
+ return map(g.nodes(), function(v) {
25
+ var nodeValue = g.node(v);
26
+ var parent = g.parent(v);
27
+ var node = { v };
28
+ if (!isUndefined(nodeValue)) {
29
+ node.value = nodeValue;
30
+ }
31
+ if (!isUndefined(parent)) {
32
+ node.parent = parent;
33
+ }
34
+ return node;
35
+ });
36
+ }
37
+ function writeEdges(g) {
38
+ return map(g.edges(), function(e) {
39
+ var edgeValue = g.edge(e);
40
+ var edge = { v: e.v, w: e.w };
41
+ if (!isUndefined(e.name)) {
42
+ edge.name = e.name;
43
+ }
44
+ if (!isUndefined(edgeValue)) {
45
+ edge.value = edgeValue;
46
+ }
47
+ return edge;
48
+ });
49
+ }
50
+ var clusterDb = /* @__PURE__ */ new Map();
51
+ var descendants = /* @__PURE__ */ new Map();
52
+ var parents = /* @__PURE__ */ new Map();
53
+ var clear = /* @__PURE__ */ __name(() => {
54
+ descendants.clear();
55
+ parents.clear();
56
+ clusterDb.clear();
57
+ }, "clear");
58
+ var isDescendant = /* @__PURE__ */ __name((id, ancestorId) => {
59
+ const ancestorDescendants = descendants.get(ancestorId) || [];
60
+ log.trace("In isDescendant", ancestorId, " ", id, " = ", ancestorDescendants.includes(id));
61
+ return ancestorDescendants.includes(id);
62
+ }, "isDescendant");
63
+ var edgeInCluster = /* @__PURE__ */ __name((edge, clusterId) => {
64
+ const clusterDescendants = descendants.get(clusterId) || [];
65
+ log.info("Descendants of ", clusterId, " is ", clusterDescendants);
66
+ log.info("Edge is ", edge);
67
+ if (edge.v === clusterId || edge.w === clusterId) {
68
+ return false;
69
+ }
70
+ if (!clusterDescendants) {
71
+ log.debug("Tilt, ", clusterId, ",not in descendants");
72
+ return false;
73
+ }
74
+ return clusterDescendants.includes(edge.v) || isDescendant(edge.v, clusterId) || isDescendant(edge.w, clusterId) || clusterDescendants.includes(edge.w);
75
+ }, "edgeInCluster");
76
+ var copy = /* @__PURE__ */ __name((clusterId, graph, newGraph, rootId) => {
77
+ log.warn(
78
+ "Copying children of ",
79
+ clusterId,
80
+ "root",
81
+ rootId,
82
+ "data",
83
+ graph.node(clusterId),
84
+ rootId
85
+ );
86
+ const nodes = graph.children(clusterId) || [];
87
+ if (clusterId !== rootId) {
88
+ nodes.push(clusterId);
89
+ }
90
+ log.warn("Copying (nodes) clusterId", clusterId, "nodes", nodes);
91
+ nodes.forEach((node) => {
92
+ if (graph.children(node).length > 0) {
93
+ copy(node, graph, newGraph, rootId);
94
+ } else {
95
+ const data = graph.node(node);
96
+ log.info("cp ", node, " to ", rootId, " with parent ", clusterId);
97
+ newGraph.setNode(node, data);
98
+ if (rootId !== graph.parent(node)) {
99
+ log.warn("Setting parent", node, graph.parent(node));
100
+ newGraph.setParent(node, graph.parent(node));
101
+ }
102
+ if (clusterId !== rootId && node !== clusterId) {
103
+ log.debug("Setting parent", node, clusterId);
104
+ newGraph.setParent(node, clusterId);
105
+ } else {
106
+ log.info("In copy ", clusterId, "root", rootId, "data", graph.node(clusterId), rootId);
107
+ log.debug(
108
+ "Not Setting parent for node=",
109
+ node,
110
+ "cluster!==rootId",
111
+ clusterId !== rootId,
112
+ "node!==clusterId",
113
+ node !== clusterId
114
+ );
115
+ }
116
+ const edges = graph.edges(node);
117
+ log.debug("Copying Edges", edges);
118
+ edges.forEach((edge) => {
119
+ log.info("Edge", edge);
120
+ const data2 = graph.edge(edge.v, edge.w, edge.name);
121
+ log.info("Edge data", data2, rootId);
122
+ try {
123
+ if (edgeInCluster(edge, rootId)) {
124
+ const rootDescendants = descendants.get(rootId) || [];
125
+ const vIn = rootDescendants.includes(edge.v) || isDescendant(edge.v, rootId) || edge.v === rootId;
126
+ const wIn = rootDescendants.includes(edge.w) || isDescendant(edge.w, rootId) || edge.w === rootId;
127
+ if (vIn && wIn) {
128
+ log.info("Copying as ", edge.v, edge.w, data2, edge.name);
129
+ newGraph.setEdge(edge.v, edge.w, data2, edge.name);
130
+ log.info("newGraph edges ", newGraph.edges(), newGraph.edge(newGraph.edges()[0]));
131
+ } else {
132
+ const newV = vIn ? rootId : edge.v;
133
+ const newW = wIn ? rootId : edge.w;
134
+ log.info("Rebinding cross-boundary edge as ", newV, newW, data2, edge.name);
135
+ graph.setEdge(newV, newW, data2, edge.name);
136
+ }
137
+ } else {
138
+ log.info(
139
+ "Skipping copy of edge ",
140
+ edge.v,
141
+ "-->",
142
+ edge.w,
143
+ " rootId: ",
144
+ rootId,
145
+ " clusterId:",
146
+ clusterId
147
+ );
148
+ }
149
+ } catch (e) {
150
+ log.error(e);
151
+ }
152
+ });
153
+ }
154
+ log.debug("Removing node", node);
155
+ graph.removeNode(node);
156
+ });
157
+ }, "copy");
158
+ var extractDescendants = /* @__PURE__ */ __name((id, graph) => {
159
+ const children = graph.children(id);
160
+ let res = [...children];
161
+ for (const child of children) {
162
+ parents.set(child, id);
163
+ res = [...res, ...extractDescendants(child, graph)];
164
+ }
165
+ return res;
166
+ }, "extractDescendants");
167
+ var findCommonEdges = /* @__PURE__ */ __name((graph, id1, id2) => {
168
+ const edges1 = graph.edges().filter((edge) => edge.v === id1 || edge.w === id1);
169
+ const edges2 = graph.edges().filter((edge) => edge.v === id2 || edge.w === id2);
170
+ const edges1Prim = edges1.map((edge) => {
171
+ return { v: edge.v === id1 ? id2 : edge.v, w: edge.w === id1 ? id1 : edge.w };
172
+ });
173
+ const edges2Prim = edges2.map((edge) => {
174
+ return { v: edge.v, w: edge.w };
175
+ });
176
+ const result = edges1Prim.filter((edgeIn1) => {
177
+ return edges2Prim.some((edge) => edgeIn1.v === edge.v && edgeIn1.w === edge.w);
178
+ });
179
+ return result;
180
+ }, "findCommonEdges");
181
+ var findNonClusterChild = /* @__PURE__ */ __name((id, graph, clusterId) => {
182
+ const children = graph.children(id);
183
+ log.trace("Searching children of id ", id, children);
184
+ if (children.length < 1) {
185
+ return id;
186
+ }
187
+ let reserve;
188
+ for (const child of children) {
189
+ const _id = findNonClusterChild(child, graph, clusterId);
190
+ const commonEdges = findCommonEdges(graph, clusterId, _id);
191
+ if (_id) {
192
+ if (commonEdges.length > 0) {
193
+ reserve = _id;
194
+ } else {
195
+ return _id;
196
+ }
197
+ }
198
+ }
199
+ return reserve;
200
+ }, "findNonClusterChild");
201
+ var getAnchorId = /* @__PURE__ */ __name((id) => {
202
+ if (!clusterDb.has(id)) {
203
+ return id;
204
+ }
205
+ if (!clusterDb.get(id).externalConnections) {
206
+ return id;
207
+ }
208
+ if (clusterDb.has(id)) {
209
+ return clusterDb.get(id).id;
210
+ }
211
+ return id;
212
+ }, "getAnchorId");
213
+ var adjustClustersAndEdges = /* @__PURE__ */ __name((graph, depth) => {
214
+ var _a;
215
+ if (!graph || depth > 10) {
216
+ log.debug("Opting out, no graph ");
217
+ return;
218
+ } else {
219
+ log.debug("Opting in, graph ");
220
+ }
221
+ graph.nodes().forEach(function(id) {
222
+ const children = graph.children(id);
223
+ if (children.length > 0) {
224
+ log.warn(
225
+ "Cluster identified",
226
+ id,
227
+ " Replacement id in edges: ",
228
+ findNonClusterChild(id, graph, id)
229
+ );
230
+ descendants.set(id, extractDescendants(id, graph));
231
+ clusterDb.set(id, { id: findNonClusterChild(id, graph, id), clusterData: graph.node(id) });
232
+ }
233
+ });
234
+ graph.nodes().forEach(function(id) {
235
+ const children = graph.children(id);
236
+ const edges = graph.edges();
237
+ if (children.length > 0) {
238
+ log.debug("Cluster identified", id, descendants);
239
+ edges.forEach((edge) => {
240
+ const d1 = isDescendant(edge.v, id);
241
+ const d2 = isDescendant(edge.w, id);
242
+ if (d1 ^ d2) {
243
+ log.warn("Edge: ", edge, " leaves cluster ", id);
244
+ log.warn("Descendants of XXX ", id, ": ", descendants.get(id));
245
+ clusterDb.get(id).externalConnections = true;
246
+ }
247
+ });
248
+ } else {
249
+ log.debug("Not a cluster ", id, descendants);
250
+ }
251
+ });
252
+ for (let id of clusterDb.keys()) {
253
+ const nonClusterChild = clusterDb.get(id).id;
254
+ const parent = graph.parent(nonClusterChild);
255
+ if (parent !== id && clusterDb.has(parent) && !clusterDb.get(parent).externalConnections) {
256
+ clusterDb.get(id).id = parent;
257
+ }
258
+ const hasDirectOutgoingEdge = graph.edges().some((edge) => edge.v === id);
259
+ if (nonClusterChild && ((_a = clusterDb.get(id)) == null ? void 0 : _a.externalConnections) && hasDirectOutgoingEdge && isNodeInExtractableCluster(graph, nonClusterChild, id)) {
260
+ const safeAnchor = findSafeAnchorNode(graph, id, graph.parent(nonClusterChild));
261
+ if (safeAnchor) {
262
+ clusterDb.get(id).id = safeAnchor;
263
+ }
264
+ }
265
+ }
266
+ graph.edges().forEach(function(e) {
267
+ const edge = graph.edge(e);
268
+ log.warn("Edge " + e.v + " -> " + e.w + ": " + JSON.stringify(e));
269
+ log.warn("Edge " + e.v + " -> " + e.w + ": " + JSON.stringify(graph.edge(e)));
270
+ let v = e.v;
271
+ let w = e.w;
272
+ log.warn(
273
+ "Fix XXX",
274
+ clusterDb,
275
+ "ids:",
276
+ e.v,
277
+ e.w,
278
+ "Translating: ",
279
+ clusterDb.get(e.v),
280
+ " --- ",
281
+ clusterDb.get(e.w)
282
+ );
283
+ if (clusterDb.get(e.v) || clusterDb.get(e.w)) {
284
+ log.warn("Fixing and trying - removing XXX", e.v, e.w, e.name);
285
+ v = getAnchorId(e.v);
286
+ w = getAnchorId(e.w);
287
+ graph.removeEdge(e.v, e.w, e.name);
288
+ if (v !== e.v) {
289
+ const parent = graph.parent(v);
290
+ clusterDb.get(parent).externalConnections = true;
291
+ edge.fromCluster = e.v;
292
+ }
293
+ if (w !== e.w) {
294
+ const parent = graph.parent(w);
295
+ clusterDb.get(parent).externalConnections = true;
296
+ edge.toCluster = e.w;
297
+ }
298
+ log.warn("Fix Replacing with XXX", v, w, e.name);
299
+ graph.setEdge(v, w, edge, e.name);
300
+ }
301
+ });
302
+ log.warn("Adjusted Graph", write(graph));
303
+ extractor(graph, 0);
304
+ log.trace(clusterDb);
305
+ }, "adjustClustersAndEdges");
306
+ var extractor = /* @__PURE__ */ __name((graph, depth) => {
307
+ var _a, _b, _c, _d;
308
+ log.warn("extractor - ", depth, write(graph), graph.children("D"));
309
+ if (depth > 10) {
310
+ log.error("Bailing out");
311
+ return;
312
+ }
313
+ let nodes = graph.nodes();
314
+ let hasChildren = false;
315
+ for (const node of nodes) {
316
+ const children = graph.children(node);
317
+ hasChildren = hasChildren || children.length > 0;
318
+ }
319
+ if (!hasChildren) {
320
+ log.debug("Done, no node has children", graph.nodes());
321
+ return;
322
+ }
323
+ log.debug("Nodes = ", nodes, depth);
324
+ for (const node of nodes) {
325
+ log.debug(
326
+ "Extracting node",
327
+ node,
328
+ clusterDb,
329
+ clusterDb.has(node) && !clusterDb.get(node).externalConnections,
330
+ !graph.parent(node),
331
+ graph.node(node),
332
+ graph.children("D"),
333
+ " Depth ",
334
+ depth
335
+ );
336
+ if (!clusterDb.has(node)) {
337
+ log.debug("Not a cluster", node, depth);
338
+ } else if (((_b = (_a = clusterDb.get(node)) == null ? void 0 : _a.clusterData) == null ? void 0 : _b.explicitDir) && graph.children(node) && graph.children(node).length > 0) {
339
+ log.warn("Cluster with explicit dir, creating subgraph for children", node, depth);
340
+ const dir = clusterDb.get(node).clusterData.dir;
341
+ const clusterGraph = new Graph({
342
+ multigraph: true,
343
+ compound: true
344
+ }).setGraph({
345
+ rankdir: dir,
346
+ nodesep: 50,
347
+ ranksep: 50,
348
+ marginx: 8,
349
+ marginy: 8
350
+ }).setDefaultEdgeLabel(function() {
351
+ return {};
352
+ });
353
+ copy(node, graph, clusterGraph, node);
354
+ const clusterNodeData = graph.node(node) || {};
355
+ graph.setNode(node, {
356
+ ...clusterNodeData,
357
+ clusterNode: true,
358
+ id: node,
359
+ clusterData: clusterDb.get(node).clusterData,
360
+ label: clusterDb.get(node).label,
361
+ graph: clusterGraph
362
+ });
363
+ log.warn(
364
+ "Subgraph for cluster with explicit dir created:",
365
+ node,
366
+ write(clusterGraph)
367
+ );
368
+ } else if (!clusterDb.get(node).externalConnections && graph.children(node) && graph.children(node).length > 0) {
369
+ log.warn(
370
+ "Cluster without external connections, without a parent and with children",
371
+ node,
372
+ depth
373
+ );
374
+ const graphSettings = graph.graph();
375
+ let dir = graphSettings.rankdir === "TB" ? "LR" : "TB";
376
+ if ((_d = (_c = clusterDb.get(node)) == null ? void 0 : _c.clusterData) == null ? void 0 : _d.dir) {
377
+ dir = clusterDb.get(node).clusterData.dir;
378
+ log.warn("Fixing dir", clusterDb.get(node).clusterData.dir, dir);
379
+ }
380
+ const clusterGraph = new Graph({
381
+ multigraph: true,
382
+ compound: true
383
+ }).setGraph({
384
+ rankdir: dir,
385
+ nodesep: 50,
386
+ ranksep: 50,
387
+ marginx: 8,
388
+ marginy: 8
389
+ }).setDefaultEdgeLabel(function() {
390
+ return {};
391
+ });
392
+ copy(node, graph, clusterGraph, node);
393
+ const clusterNodeData = graph.node(node) || {};
394
+ graph.setNode(node, {
395
+ ...clusterNodeData,
396
+ clusterNode: true,
397
+ id: node,
398
+ clusterData: clusterDb.get(node).clusterData,
399
+ label: clusterDb.get(node).label,
400
+ graph: clusterGraph
401
+ });
402
+ log.debug("Old graph after copy", write(graph));
403
+ } else {
404
+ log.warn(
405
+ "Cluster ** ",
406
+ node,
407
+ " **not meeting the criteria !externalConnections:",
408
+ !clusterDb.get(node).externalConnections,
409
+ " no parent: ",
410
+ !graph.parent(node),
411
+ " children ",
412
+ graph.children(node) && graph.children(node).length > 0,
413
+ graph.children("D"),
414
+ depth
415
+ );
416
+ log.debug(clusterDb);
417
+ }
418
+ }
419
+ nodes = graph.nodes();
420
+ log.warn("New list of nodes", nodes);
421
+ for (const node of nodes) {
422
+ const data = graph.node(node);
423
+ log.warn(" Now next level", node, data);
424
+ if (data == null ? void 0 : data.clusterNode) {
425
+ extractor(data.graph, depth + 1);
426
+ }
427
+ }
428
+ }, "extractor");
429
+ var sorter = /* @__PURE__ */ __name((graph, nodes) => {
430
+ if (nodes.length === 0) {
431
+ return [];
432
+ }
433
+ let result = Object.assign([], nodes);
434
+ nodes.forEach((node) => {
435
+ const children = graph.children(node);
436
+ const sorted = sorter(graph, children);
437
+ result = [...result, ...sorted];
438
+ });
439
+ return result;
440
+ }, "sorter");
441
+ var sortNodesByHierarchy = /* @__PURE__ */ __name((graph) => sorter(graph, graph.children()), "sortNodesByHierarchy");
442
+ var isNodeInExtractableCluster = /* @__PURE__ */ __name((graph, node, rootId) => {
443
+ let parent = graph.parent(node);
444
+ while (parent && parent !== rootId) {
445
+ const cluster = clusterDb.get(parent);
446
+ if (cluster && !cluster.externalConnections) {
447
+ return true;
448
+ }
449
+ parent = graph.parent(parent);
450
+ }
451
+ return false;
452
+ }, "isNodeInExtractableCluster");
453
+ var findSafeAnchorNode = /* @__PURE__ */ __name((graph, clusterId, excludedCluster) => {
454
+ const children = graph.children(clusterId) ?? [];
455
+ for (const child of children) {
456
+ if (child === excludedCluster || isDescendant(child, excludedCluster)) {
457
+ continue;
458
+ }
459
+ const candidate = findNonClusterChild(child, graph, clusterId);
460
+ if (!candidate) {
461
+ continue;
462
+ }
463
+ if (!isNodeInExtractableCluster(graph, candidate, clusterId)) {
464
+ return candidate;
465
+ }
466
+ }
467
+ return null;
468
+ }, "findSafeAnchorNode");
469
+ export {
470
+ adjustClustersAndEdges as a,
471
+ clusterDb as b,
472
+ clear as c,
473
+ findNonClusterChild as f,
474
+ sortNodesByHierarchy as s,
475
+ write as w
476
+ };