ontosight-codegraph 0.1.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,38 @@
1
+ """CodeGraph → OntoSight integration for standalone and Hyper-Extract use."""
2
+
3
+ from ontosight_codegraph.query import make_query_callback
4
+ from ontosight_codegraph.store import (
5
+ INIT_HINT,
6
+ CALL_EDGE_KIND,
7
+ EXCLUDED_NODE_KINDS,
8
+ CodeCallEdge,
9
+ CodeGraphNotFoundError,
10
+ CodeGraphStore,
11
+ CodeSymbolNode,
12
+ SubgraphResult,
13
+ load_call_subgraph,
14
+ make_search_callback,
15
+ merge_query_params,
16
+ parse_codegraph_query,
17
+ resolve_codegraph_db,
18
+ )
19
+ from ontosight_codegraph.view import apply_subgraph_to_view, show_codegraph
20
+
21
+ __all__ = [
22
+ "INIT_HINT",
23
+ "CALL_EDGE_KIND",
24
+ "EXCLUDED_NODE_KINDS",
25
+ "CodeCallEdge",
26
+ "CodeGraphNotFoundError",
27
+ "CodeGraphStore",
28
+ "CodeSymbolNode",
29
+ "SubgraphResult",
30
+ "apply_subgraph_to_view",
31
+ "load_call_subgraph",
32
+ "make_query_callback",
33
+ "make_search_callback",
34
+ "merge_query_params",
35
+ "parse_codegraph_query",
36
+ "resolve_codegraph_db",
37
+ "show_codegraph",
38
+ ]
@@ -0,0 +1,96 @@
1
+ """CLI for visualizing CodeGraph call subgraphs in OntoSight."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import Optional
7
+
8
+ import typer
9
+
10
+ from ontosight_codegraph.store import CodeGraphNotFoundError
11
+ from ontosight_codegraph.view import show_codegraph
12
+
13
+ app = typer.Typer(
14
+ help="Visualize CodeGraph call subgraphs with OntoSight.",
15
+ add_completion=False,
16
+ no_args_is_help=True,
17
+ )
18
+
19
+
20
+ @app.command()
21
+ def show(
22
+ project_path: str = typer.Argument(
23
+ ".",
24
+ help="Project root containing .codegraph/codegraph.db",
25
+ ),
26
+ path_filter: Optional[str] = typer.Option(
27
+ None,
28
+ "--path",
29
+ help="Limit symbols to files under this path prefix",
30
+ ),
31
+ symbol: Optional[str] = typer.Option(
32
+ None,
33
+ "--symbol",
34
+ help="Seed symbol name for subgraph expansion",
35
+ ),
36
+ task: Optional[str] = typer.Option(
37
+ None,
38
+ "--task",
39
+ help="Natural-language task to seed subgraph (keyword match)",
40
+ ),
41
+ hops: int = typer.Option(
42
+ 2,
43
+ "--hops",
44
+ min=0,
45
+ help="BFS hop depth for subgraph expansion",
46
+ ),
47
+ max_nodes: int = typer.Option(
48
+ 200,
49
+ "--max-nodes",
50
+ min=1,
51
+ help="Maximum nodes in subgraph",
52
+ ),
53
+ ) -> None:
54
+ """Open OntoSight with a CodeGraph call subgraph."""
55
+ root = Path(project_path).resolve()
56
+ typer.echo(f"Project: {root}")
57
+ if path_filter:
58
+ typer.echo(f"Path filter: {path_filter}")
59
+ if symbol:
60
+ typer.echo(f"Symbol seed: {symbol}")
61
+ elif task:
62
+ typer.echo(f"Task seed: {task}")
63
+ typer.echo(f"Hops / max nodes: {hops} / {max_nodes}")
64
+ typer.echo()
65
+
66
+ try:
67
+ typer.echo("Visualizing CodeGraph with OntoSight...")
68
+ result = show_codegraph(
69
+ root,
70
+ path_filter=path_filter,
71
+ symbol=symbol,
72
+ task=task,
73
+ hops=hops,
74
+ max_nodes=max_nodes,
75
+ print_topology_summary=True,
76
+ )
77
+ except CodeGraphNotFoundError as exc:
78
+ typer.echo(f"Error: {exc}", err=True)
79
+ raise typer.Exit(1) from exc
80
+ except ValueError as exc:
81
+ typer.echo(f"Error: {exc}", err=True)
82
+ raise typer.Exit(1) from exc
83
+
84
+ typer.echo(
85
+ f"Loaded {len(result.nodes)} nodes, {len(result.edges)} call edges"
86
+ )
87
+ if result.truncated:
88
+ typer.echo(
89
+ f"Warning: Subgraph truncated at {max_nodes} nodes. "
90
+ "Use --symbol, --task, or --path to narrow scope.",
91
+ err=True,
92
+ )
93
+
94
+
95
+ if __name__ == "__main__":
96
+ app()
@@ -0,0 +1,59 @@
1
+ """CodeGraph query callback for OntoSight live subgraph reload."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import Any, Callable, Dict, Optional
7
+
8
+ from ontosight_codegraph.store import (
9
+ load_call_subgraph,
10
+ merge_query_params,
11
+ )
12
+ from ontosight_codegraph.view import apply_subgraph_to_view
13
+
14
+
15
+ def make_query_callback(
16
+ project_path: Path,
17
+ *,
18
+ default_path_filter: Optional[str] = None,
19
+ default_hops: int = 2,
20
+ default_max_nodes: int = 200,
21
+ top_k_critical: int = 10,
22
+ highlight_critical: bool = True,
23
+ ) -> Callable[..., Dict[str, Any]]:
24
+ """Create OntoSight callback to reload CodeGraph subgraph from query input."""
25
+
26
+ def codegraph_query(
27
+ query: Optional[str] = None,
28
+ path_filter: Optional[str] = None,
29
+ symbol: Optional[str] = None,
30
+ task: Optional[str] = None,
31
+ hops: Optional[int] = None,
32
+ max_nodes: Optional[int] = None,
33
+ **_: Any,
34
+ ) -> Dict[str, Any]:
35
+ params = merge_query_params(
36
+ query=query,
37
+ path_filter=path_filter,
38
+ symbol=symbol,
39
+ task=task,
40
+ hops=hops if hops is not None else default_hops,
41
+ max_nodes=max_nodes if max_nodes is not None else default_max_nodes,
42
+ default_path_filter=default_path_filter,
43
+ )
44
+ load_kwargs = {
45
+ "path_filter": params.get("path_filter"),
46
+ "symbol": params.get("symbol"),
47
+ "task": params.get("task"),
48
+ "hops": params.get("hops", default_hops),
49
+ "max_nodes": params.get("max_nodes", default_max_nodes),
50
+ }
51
+ result = load_call_subgraph(project_path, **load_kwargs)
52
+ return apply_subgraph_to_view(
53
+ result,
54
+ max_nodes=load_kwargs["max_nodes"],
55
+ top_k_critical=top_k_critical,
56
+ highlight_critical=highlight_critical,
57
+ )
58
+
59
+ return codegraph_query