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

Function print_list

openkb/cli.py:1981–2041  ·  view source on GitHub ↗

Print all documents in the knowledge base. Usable from CLI and chat REPL.

(kb_dir: Path)

Source from the content-addressed store, hash-verified

1979
1980
1981def print_list(kb_dir: Path) -> None:
1982 """Print all documents in the knowledge base. Usable from CLI and chat REPL."""
1983 openkb_dir = kb_dir / ".openkb"
1984 hashes_file = openkb_dir / "hashes.json"
1985 if not hashes_file.exists():
1986 click.echo("No documents indexed yet.")
1987 return
1988
1989 hashes = json.loads(hashes_file.read_text(encoding="utf-8"))
1990 if not hashes:
1991 click.echo("No documents indexed yet.")
1992 return
1993
1994 # Display documents table with count in header
1995 doc_count = len(hashes)
1996 click.echo(f"Documents ({doc_count}):")
1997 click.echo(f" {'Name':<40} {'Type':<12} {'Pages':<8}")
1998 click.echo(f" {'-' * 40} {'-' * 12} {'-' * 8}")
1999 for file_hash, meta in hashes.items():
2000 name = meta.get("name", "unknown")
2001 raw_type = meta.get("type", "unknown")
2002 display = _display_type(raw_type)
2003 pages = meta.get("pages", "")
2004 pages_str = str(pages) if pages else ""
2005 click.echo(f" {name:<40} {display:<12} {pages_str:<8}")
2006
2007 # Display summaries
2008 summaries_dir = kb_dir / "wiki" / "summaries"
2009 if summaries_dir.exists():
2010 summaries = sorted(p.stem for p in summaries_dir.glob("*.md"))
2011 if summaries:
2012 click.echo(f"\nSummaries ({len(summaries)}):")
2013 for s in summaries:
2014 click.echo(f" - {s}")
2015
2016 # Display concepts
2017 concepts_dir = kb_dir / "wiki" / "concepts"
2018 if concepts_dir.exists():
2019 concepts = sorted(p.stem for p in concepts_dir.glob("*.md"))
2020 if concepts:
2021 click.echo(f"\nConcepts ({len(concepts)}):")
2022 for c in concepts:
2023 click.echo(f" - {c}")
2024
2025 # Display entities
2026 entities_dir = kb_dir / "wiki" / "entities"
2027 if entities_dir.exists():
2028 entities = sorted(p.stem for p in entities_dir.glob("*.md"))
2029 if entities:
2030 click.echo(f"\nEntities ({len(entities)}):")
2031 for e in entities:
2032 click.echo(f" - {e}")
2033
2034 # Display reports
2035 reports_dir = kb_dir / "wiki" / "reports"
2036 if reports_dir.exists():
2037 reports = sorted(p.name for p in reports_dir.glob("*.md"))
2038 if reports:

Callers 2

_handle_slashFunction · 0.90
list_cmdFunction · 0.85

Calls 2

_display_typeFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected