MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / visualize

Function visualize

openkb/cli.py:1948–1978  ·  view source on GitHub ↗

Render the wiki's [[wikilink]] graph as a self-contained interactive HTML page.

(ctx, open_browser)

Source from the content-addressed store, hash-verified

1946@click.pass_context
1947@_with_kb_lock(exclusive=False)
1948def visualize(ctx, open_browser):
1949 """Render the wiki's [[wikilink]] graph as a self-contained interactive HTML page."""
1950 kb_dir = _find_kb_dir(ctx.obj.get("kb_dir_override"))
1951 if kb_dir is None:
1952 click.echo("No knowledge base found. Run `openkb init` first.")
1953 return
1954 from openkb import visualize as viz
1955
1956 graph = viz.build_graph(kb_dir / "wiki")
1957 if not graph["nodes"]:
1958 click.echo("No wiki pages to visualize yet. Run `openkb add` first.")
1959 return
1960 out = kb_dir / "output" / "visualize" / "graph.html"
1961 out.parent.mkdir(parents=True, exist_ok=True)
1962 out.write_text(viz.render_html(graph), encoding="utf-8")
1963 click.echo(
1964 f"Graph written to {out} ({len(graph['nodes'])} nodes, {len(graph['edges'])} edges)"
1965 )
1966 if open_browser:
1967 import webbrowser
1968
1969 try:
1970 opened = webbrowser.open(
1971 out.resolve().as_uri()
1972 ) # resolve() so a relative --kb-dir still yields a valid file URI
1973 except Exception:
1974 opened = False
1975 if not opened:
1976 click.echo(
1977 "(couldn't launch a browser — open the file above manually, or use --no-open)"
1978 )
1979
1980
1981def print_list(kb_dir: Path) -> None:

Callers

nothing calls this directly

Calls 2

_find_kb_dirFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected