tscode-kg 0.2.0__py3-none-any.whl

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.
@@ -0,0 +1,175 @@
1
+ """
2
+ cli/cmd_viz.py — tscodekg visualizer commands.
3
+
4
+ viz — Streamlit-based interactive graph explorer
5
+ viz3d — PyVista/PyQt5 3-D interactive knowledge-graph visualizer
6
+ viz-timeline — Interactive temporal metrics visualization from snapshots
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import importlib.util
12
+ import subprocess
13
+ import sys
14
+ from pathlib import Path
15
+
16
+ import click
17
+
18
+ _VIZ_EXTRA = 'pip install "tscode-kg[viz]"'
19
+
20
+
21
+ @click.command("viz")
22
+ @click.option(
23
+ "--db",
24
+ default=".tscodekg/graph.sqlite",
25
+ show_default=True,
26
+ help="SQLite database path.",
27
+ )
28
+ @click.option(
29
+ "--port",
30
+ default="8500",
31
+ show_default=True,
32
+ help="Streamlit server port.",
33
+ )
34
+ @click.option(
35
+ "--no-browser",
36
+ is_flag=True,
37
+ help="Do not open a browser window automatically.",
38
+ )
39
+ def viz(db: str, port: str, no_browser: bool) -> None:
40
+ """Launch the TypeScriptKG Streamlit visualizer."""
41
+ if importlib.util.find_spec("streamlit") is None:
42
+ raise click.UsageError(
43
+ f"streamlit is not installed. Install viz dependencies with:\n {_VIZ_EXTRA}"
44
+ )
45
+
46
+ app_path = Path(__file__).parent.parent / "app.py"
47
+
48
+ if not app_path.exists():
49
+ click.echo(f"ERROR: Could not find app.py at {app_path}", err=True)
50
+ sys.exit(1)
51
+
52
+ cmd = [
53
+ sys.executable,
54
+ "-m",
55
+ "streamlit",
56
+ "run",
57
+ str(app_path),
58
+ "--server.port",
59
+ str(port),
60
+ "--",
61
+ "--db",
62
+ db,
63
+ ]
64
+ if no_browser:
65
+ cmd[5:5] = ["--server.headless", "true"]
66
+
67
+ click.echo(f"Launching TypeScriptKG Explorer on http://localhost:{port}")
68
+ click.echo(f" app : {app_path}")
69
+ click.echo(f" db : {db}")
70
+ click.echo(" Press Ctrl+C to stop.\n")
71
+
72
+ try:
73
+ subprocess.run(cmd, check=True)
74
+ except KeyboardInterrupt:
75
+ click.echo("\nStopped.")
76
+
77
+
78
+ @click.command("viz3d")
79
+ @click.option(
80
+ "--db",
81
+ default=".tscodekg/graph.sqlite",
82
+ show_default=True,
83
+ help="SQLite database path.",
84
+ )
85
+ @click.option(
86
+ "--layout",
87
+ type=click.Choice(["allium", "funnel"]),
88
+ default="allium",
89
+ show_default=True,
90
+ help=(
91
+ "3-D layout strategy. "
92
+ "'allium' renders each module as a Giant Allium plant; "
93
+ "'funnel' stratifies nodes by kind across Z layers."
94
+ ),
95
+ )
96
+ @click.option(
97
+ "--width",
98
+ type=int,
99
+ default=1400,
100
+ show_default=True,
101
+ help="Window width in pixels.",
102
+ )
103
+ @click.option(
104
+ "--height",
105
+ type=int,
106
+ default=900,
107
+ show_default=True,
108
+ help="Window height in pixels.",
109
+ )
110
+ def viz3d(db: str, layout: str, width: int, height: int) -> None:
111
+ """Launch the TypeScriptKG 3-D PyVista knowledge-graph visualizer."""
112
+ db_path = Path(db)
113
+ if not db_path.exists():
114
+ raise click.UsageError(
115
+ f"Database not found: {db_path}\nRun 'tscodekg build' first to index your repository."
116
+ )
117
+
118
+ from tscode_kg.viz3d import launch # noqa: PLC0415
119
+
120
+ launch(
121
+ db_path=str(db_path),
122
+ layout_name=layout,
123
+ width=width,
124
+ height=height,
125
+ )
126
+
127
+
128
+ @click.command("viz-timeline")
129
+ @click.option(
130
+ "--snapshots",
131
+ default=".tscodekg/snapshots",
132
+ show_default=True,
133
+ help="Snapshots directory path.",
134
+ )
135
+ @click.option(
136
+ "--type",
137
+ type=click.Choice(["2d", "3d"]),
138
+ default="2d",
139
+ show_default=True,
140
+ help="Visualization type: 2d (subplots) or 3d (scatter plot).",
141
+ )
142
+ def viz_timeline(snapshots: str, type: str) -> None:
143
+ """Display temporal metrics evolution across commits."""
144
+ snapshots_path = Path(snapshots)
145
+ if not snapshots_path.exists():
146
+ raise click.UsageError(
147
+ f"Snapshots directory not found: {snapshots_path}\n"
148
+ "Run 'tscodekg snapshot save' first to capture snapshots."
149
+ )
150
+
151
+ if importlib.util.find_spec("plotly") is None:
152
+ raise click.UsageError(
153
+ f"plotly is not installed. Install viz dependencies with:\n {_VIZ_EXTRA}"
154
+ )
155
+
156
+ from tscode_kg.viz3d_timeline import ( # noqa: PLC0415
157
+ create_3d_timeline_figure,
158
+ create_timeline_figure,
159
+ display_timeline_summary,
160
+ )
161
+
162
+ # Display text summary
163
+ summary = display_timeline_summary(snapshots_path)
164
+ click.echo(summary)
165
+
166
+ # Create and display visualization
167
+ if type == "3d":
168
+ fig = create_3d_timeline_figure(snapshots_path)
169
+ else:
170
+ fig = create_timeline_figure(snapshots_path)
171
+
172
+ try:
173
+ fig.show()
174
+ except (OSError, AttributeError, ImportError) as e:
175
+ click.echo(f"Could not display visualization: {e}", err=True)
tscode_kg/cli/main.py ADDED
@@ -0,0 +1,56 @@
1
+ """
2
+ cli/main.py — TypeScriptKG CLI entry point.
3
+
4
+ Usage::
5
+
6
+ tscodekg init --repo /path/to/ts-repo
7
+ tscodekg build --repo /path/to/ts-repo
8
+ tscodekg query "authentication middleware"
9
+ tscodekg pack "error handling" --hop 2
10
+ tscodekg analyze /path/to/ts-repo
11
+ tscodekg snapshot save --repo /path/to/ts-repo
12
+ tscodekg install-hooks --repo /path/to/ts-repo
13
+ tscodekg mcp --repo /path/to/ts-repo
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import click
19
+
20
+ from tscode_kg.cli.cmd_analyze import analyze
21
+ from tscode_kg.cli.cmd_bridges import bridges
22
+ from tscode_kg.cli.cmd_build import build
23
+ from tscode_kg.cli.cmd_centrality import centrality
24
+ from tscode_kg.cli.cmd_explain import explain
25
+ from tscode_kg.cli.cmd_framework_nodes import framework_nodes
26
+ from tscode_kg.cli.cmd_hooks import install_hooks
27
+ from tscode_kg.cli.cmd_init import init
28
+ from tscode_kg.cli.cmd_mcp import mcp_cmd
29
+ from tscode_kg.cli.cmd_model import download_model
30
+ from tscode_kg.cli.cmd_query import pack, query
31
+ from tscode_kg.cli.cmd_snapshot import snapshot
32
+ from tscode_kg.cli.cmd_viz import viz, viz3d, viz_timeline
33
+
34
+
35
+ @click.group()
36
+ @click.version_option(package_name="tscode-kg")
37
+ def cli() -> None:
38
+ """TypeScriptKG — knowledge graph for TypeScript/JavaScript codebases."""
39
+
40
+
41
+ cli.add_command(init)
42
+ cli.add_command(build)
43
+ cli.add_command(query)
44
+ cli.add_command(pack)
45
+ cli.add_command(analyze)
46
+ cli.add_command(explain)
47
+ cli.add_command(centrality)
48
+ cli.add_command(bridges)
49
+ cli.add_command(framework_nodes)
50
+ cli.add_command(snapshot)
51
+ cli.add_command(viz)
52
+ cli.add_command(viz3d)
53
+ cli.add_command(viz_timeline, name="viz-timeline")
54
+ cli.add_command(install_hooks)
55
+ cli.add_command(download_model)
56
+ cli.add_command(mcp_cmd, name="mcp")