lwazi 1.9.9 → 1.10.2

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.9.9",
3
+ "version": "1.10.2",
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": {
@@ -127,10 +127,6 @@ class SetupCommand extends Command
127
127
 
128
128
  $this->info("Crawled " . count($manifest['nodes'] ?? $manifest['flat'] ?? []) . " pages.");
129
129
 
130
- $this->info("\n" . str_repeat('=', 50));
131
- $this->info('SITE NAVIGATION GRAPH');
132
- $this->info(str_repeat('=', 50));
133
-
134
130
  $visualizer = new GraphVisualizer();
135
131
  $graphOutput = $visualizer->generateAsciiGraph($manifest);
136
132
  $this->line($graphOutput);
@@ -15,7 +15,6 @@ class GraphVisualizer
15
15
  }
16
16
 
17
17
  $root = $this->normalizeRoot($rootUrl);
18
- $visited = [];
19
18
  $output = "SITE NAVIGATION GRAPH\n";
20
19
  $output .= str_repeat('=', 50) . "\n\n";
21
20
  $output .= "Root: {$root}\n";
@@ -23,27 +22,19 @@ class GraphVisualizer
23
22
  $output .= "Total links: " . array_sum(array_map('count', $adjacency)) . "\n";
24
23
  $output .= "\n" . str_repeat('-', 50) . "\n\n";
25
24
 
26
- $output .= $this->buildTreeAscii($adjacency, $root, 0, $maxDepth, $maxChildren, $visited);
25
+ $output .= $this->buildGraphAscii($adjacency, $root, $maxDepth, $maxChildren);
27
26
 
28
27
  return $output;
29
28
  }
30
29
 
31
- protected function normalizeRoot(string $url): string
30
+ protected function buildGraphAscii(array $adjacency, string $root, int $maxDepth, int $maxChildren): string
32
31
  {
33
- $parts = parse_url($url);
34
- $scheme = $parts['scheme'] ?? 'http';
35
- $host = $parts['host'] ?? $url;
36
- $port = $parts['port'] ?? parse_url($url, PHP_URL_PORT);
37
-
38
- $result = $scheme . '://' . $host;
39
- if ($port && (($scheme === 'http' && $port !== 80) || ($scheme === 'https' && $port !== 443))) {
40
- $result .= ':' . $port;
41
- }
42
-
43
- return $result;
32
+ $visited = [];
33
+ $output = $this->renderNodeGraph($adjacency, $root, 0, $maxDepth, $maxChildren, $visited);
34
+ return $output;
44
35
  }
45
36
 
46
- protected function buildTreeAscii(
37
+ protected function renderNodeGraph(
47
38
  array $adjacency,
48
39
  string $current,
49
40
  int $depth,
@@ -55,23 +46,27 @@ class GraphVisualizer
55
46
  return '';
56
47
  }
57
48
 
58
- if (isset($visited[$current])) {
59
- return " [loop back]\n";
60
- }
61
- $visited[$current] = true;
62
-
63
49
  $label = $this->getPageLabel($current);
64
50
  $indent = str_repeat(' ', $depth);
65
51
  $prefix = $depth === 0 ? '●' : '├';
66
- $output = "{$indent}{$prefix} {$label}\n";
52
+ $output = "{$indent}{$prefix} {$label}";
53
+
54
+ if (isset($visited[$current])) {
55
+ $output .= " → [cycle]\n";
56
+ return $output;
57
+ }
67
58
 
59
+ $visited[$current] = true;
68
60
  $children = $adjacency[$current] ?? [];
69
- $childCount = count($children);
70
61
 
71
- if ($childCount === 0) {
62
+ if (empty($children)) {
63
+ $output .= " (leaf)\n";
72
64
  return $output;
73
65
  }
74
66
 
67
+ $childCount = count($children);
68
+ $output .= " → {$childCount} link" . ($childCount !== 1 ? 's' : '') . "\n";
69
+
75
70
  $displayChildren = array_slice($children, 0, $maxChildren);
76
71
  $hasMore = $childCount > $maxChildren;
77
72
 
@@ -81,17 +76,26 @@ class GraphVisualizer
81
76
  $childPrefix = $isLast ? '└' : '├';
82
77
 
83
78
  $childLabel = $this->getPageLabel($child);
84
- $output .= "{$childIndent}{$childPrefix}─ {$childLabel}\n";
79
+ $output .= "{$childIndent}{$childPrefix}─ {$childLabel}";
85
80
 
86
81
  if ($depth < $maxDepth) {
87
- $output .= $this->buildTreeAscii(
88
- $adjacency,
89
- $child,
90
- $depth + 1,
91
- $maxDepth,
92
- $maxChildren,
93
- $visited
94
- );
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";
96
+ }
97
+ } else {
98
+ $output .= "\n";
95
99
  }
96
100
  }
97
101
 
@@ -103,6 +107,21 @@ class GraphVisualizer
103
107
  return $output;
104
108
  }
105
109
 
110
+ protected function normalizeRoot(string $url): string
111
+ {
112
+ $parts = parse_url($url);
113
+ $scheme = $parts['scheme'] ?? 'http';
114
+ $host = $parts['host'] ?? $url;
115
+ $port = $parts['port'] ?? null;
116
+
117
+ $result = $scheme . '://' . $host;
118
+ if ($port) {
119
+ $result .= ':' . $port;
120
+ }
121
+
122
+ return rtrim($result, '/');
123
+ }
124
+
106
125
  protected function getPageLabel(string $url): string
107
126
  {
108
127
  $path = parse_url($url, PHP_URL_PATH) ?? '/';