lwazi 1.10.2 → 1.10.4

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": "lwazi",
3
- "version": "1.10.2",
3
+ "version": "1.10.4",
4
4
  "description": "Lwazi is an AI assistant for Laravel. Install with one command to add an AI assistant to your Laravel app.",
5
5
  "main": "bin/lwazi.js",
6
6
  "bin": {
@@ -14,94 +14,65 @@ class GraphVisualizer
14
14
  return "No graph data available.\n";
15
15
  }
16
16
 
17
- $root = $this->normalizeRoot($rootUrl);
18
17
  $output = "SITE NAVIGATION GRAPH\n";
19
18
  $output .= str_repeat('=', 50) . "\n\n";
20
- $output .= "Root: {$root}\n";
19
+ $output .= "Root: {$rootUrl}\n";
21
20
  $output .= "Total pages: " . count($nodes) . "\n";
22
21
  $output .= "Total links: " . array_sum(array_map('count', $adjacency)) . "\n";
23
22
  $output .= "\n" . str_repeat('-', 50) . "\n\n";
24
23
 
25
- $output .= $this->buildGraphAscii($adjacency, $root, $maxDepth, $maxChildren);
24
+ $output .= $this->buildCompactGraph($adjacency, $nodes);
26
25
 
27
26
  return $output;
28
27
  }
29
28
 
30
- protected function buildGraphAscii(array $adjacency, string $root, int $maxDepth, int $maxChildren): string
29
+ protected function buildCompactGraph(array $adjacency, array $nodes): string
31
30
  {
32
- $visited = [];
33
- $output = $this->renderNodeGraph($adjacency, $root, 0, $maxDepth, $maxChildren, $visited);
34
- return $output;
35
- }
36
-
37
- protected function renderNodeGraph(
38
- array $adjacency,
39
- string $current,
40
- int $depth,
41
- int $maxDepth,
42
- int $maxChildren,
43
- array &$visited
44
- ): string {
45
- if ($depth > $maxDepth) {
46
- return '';
31
+ $outdegree = [];
32
+ foreach ($adjacency as $from => $links) {
33
+ $outdegree[$from] = count($links);
47
34
  }
35
+ arsort($outdegree);
36
+ $hubs = array_slice($outdegree, 0, 15, true);
48
37
 
49
- $label = $this->getPageLabel($current);
50
- $indent = str_repeat(' ', $depth);
51
- $prefix = $depth === 0 ? '●' : '├';
52
- $output = "{$indent}{$prefix} {$label}";
53
-
54
- if (isset($visited[$current])) {
55
- $output .= " → [cycle]\n";
56
- return $output;
38
+ $output = "HUBS (most connected pages)\n";
39
+ $output .= str_repeat('-', 40) . "\n";
40
+ foreach ($hubs as $url => $count) {
41
+ $label = $this->getPageLabel($url);
42
+ $output .= sprintf(" %-35s → %3d links\n", $label, $count);
57
43
  }
58
44
 
59
- $visited[$current] = true;
60
- $children = $adjacency[$current] ?? [];
45
+ $output .= "\n" . str_repeat('-', 40) . "\n";
46
+ $output .= "EDGE LIST (top connections)\n";
47
+ $output .= str_repeat('-', 40) . "\n";
61
48
 
62
- if (empty($children)) {
63
- $output .= " (leaf)\n";
64
- return $output;
49
+ $edges = [];
50
+ foreach ($adjacency as $from => $links) {
51
+ foreach ($links as $to) {
52
+ $key = $this->getPageLabel($from) . ' → ' . $this->getPageLabel($to);
53
+ if (!isset($edges[$key])) {
54
+ $edges[$key] = 0;
55
+ }
56
+ }
65
57
  }
66
58
 
67
- $childCount = count($children);
68
- $output .= " → {$childCount} link" . ($childCount !== 1 ? 's' : '') . "\n";
69
-
70
- $displayChildren = array_slice($children, 0, $maxChildren);
71
- $hasMore = $childCount > $maxChildren;
72
-
73
- foreach ($displayChildren as $i => $child) {
74
- $isLast = ($i === count($displayChildren) - 1) && !$hasMore;
75
- $childIndent = str_repeat(' ', $depth + 1);
76
- $childPrefix = $isLast ? '└' : '├';
77
-
78
- $childLabel = $this->getPageLabel($child);
79
- $output .= "{$childIndent}{$childPrefix}─ {$childLabel}";
80
-
81
- if ($depth < $maxDepth) {
82
- $childVisited = $visited;
83
- $childChildren = $adjacency[$child] ?? [];
84
- if (!empty($childChildren)) {
85
- $output .= " → " . count($childChildren) . " link" . (count($childChildren) !== 1 ? 's' : '') . "\n";
86
- $output .= $this->renderNodeGraph(
87
- $adjacency,
88
- $child,
89
- $depth + 1,
90
- $maxDepth,
91
- $maxChildren,
92
- $visited
93
- );
94
- } else {
95
- $output .= " (leaf)\n";
59
+ $edgeList = [];
60
+ foreach ($adjacency as $from => $links) {
61
+ foreach ($links as $to) {
62
+ $key = $this->getPageLabel($from) . ' → ' . $this->getPageLabel($to);
63
+ if (!isset($edgeList[$key])) {
64
+ $edgeList[$key] = $key;
96
65
  }
97
- } else {
98
- $output .= "\n";
99
66
  }
100
67
  }
101
68
 
102
- if ($hasMore) {
103
- $moreIndent = str_repeat(' ', $depth + 1);
104
- $output .= "{$moreIndent}└─ ... (+" . ($childCount - $maxChildren) . " more)\n";
69
+ $uniqueEdges = array_slice($edgeList, 0, 30, true);
70
+ foreach ($uniqueEdges as $edge) {
71
+ $output .= " {$edge}\n";
72
+ }
73
+
74
+ if (count($edgeList) > 30) {
75
+ $output .= " ... and " . (count($edgeList) - 30) . " more edges\n";
105
76
  }
106
77
 
107
78
  return $output;
@@ -119,7 +90,7 @@ class GraphVisualizer
119
90
  $result .= ':' . $port;
120
91
  }
121
92
 
122
- return rtrim($result, '/');
93
+ return $result . '/';
123
94
  }
124
95
 
125
96
  protected function getPageLabel(string $url): string