Skip to main content

TypeScriptKG

Python License: Elastic-2.0 PyPI Version CI Poetry DOI

Knowledge graph for TypeScript and JavaScript codebases — deterministic AST extraction, hybrid semantic + structural search.

Overview

TypeScriptKG builds a queryable knowledge graph from TypeScript/JavaScript source code using:

  • tree-sitter for deterministic, parser-level AST extraction (no LLM inference during indexing)
  • SQLite for the structural graph (nodes, edges, provenance)
  • sqlite-vec for the semantic vector index (embeddings via BAAI/bge-small-en-v1.5)
  • Hybrid retrieval: semantic seed → graph hop expansion → lexical re-ranking

Node types

Kind Description
module Every indexed .ts/.tsx/.js/.jsx file
class Class declaration
interface TypeScript interface
type_alias TypeScript type alias
enum TypeScript enum
namespace TypeScript namespace / module declaration
function Module-level function (declaration or const arrow)
method Method or accessor within a class
symbol Unresolved external import stub

Edge types

Relation Description
CONTAINS module → class/function/interface…
IMPORTS module → module
CALLS function/method → function
INHERITS class extends class
IMPLEMENTS class implements interface
EXTENDS interface extends interface

Quick start

pip install tscode-kg

# First-time setup (downloads model, builds graph, installs hooks, snapshots)
tscodekg init --repo /path/to/ts-repo

# Build the KG for a TypeScript repo
tscodekg build --repo /path/to/ts-repo

# Query
tscodekg query "authentication middleware"
tscodekg pack "error handling utilities" --hop 2

# Thorough architectural analysis (fan-in/out, CodeRank, SIR centrality, JSDoc coverage)
tscodekg analyze /path/to/ts-repo --report analysis.md

# Structural rankings and node explanations
tscodekg centrality --top 20
tscodekg bridges --top 20
tscodekg framework-nodes --top 20
tscodekg explain "fn:src/utils/helpers.ts:formatDate"

# Temporal metric snapshots
tscodekg snapshot save 0.4.0 --repo /path/to/ts-repo --subject repo:tscode-kg
tscodekg snapshot list

# Interactive visualizers (install extras: tscode-kg[viz] / tscode-kg[viz3d])
tscodekg viz --port 8500
tscodekg viz3d --layout allium
tscodekg viz-timeline --type 2d

# Install the pre-commit snapshot hook
tscodekg install-hooks --repo /path/to/ts-repo

# MCP server (Claude Desktop, Cursor, etc.)
tscodekg mcp --repo /path/to/ts-repo

Each subcommand is also available as a dedicated script alias — tscodekg-init, tscodekg-build, tscodekg-query, tscodekg-pack, tscodekg-analyze, tscodekg-centrality, tscodekg-viz, tscodekg-viz3d, tscodekg-viz-timeline, tscodekg-install-hooks, tscodekg-download-model, tscodekg-mcp — both forms are equivalent.

MCP tools

The MCP server exposes the full PyCodeKG toolkit, applied to TypeScript/JavaScript codebases, as 20 tools. The first five are the fleet's canonical tools, named the same on every KG server: stats, query, pack, get_node and neighbors. The other fifteen are TypeScriptKG's own: callers, list_nodes, find_node, centrality, bridge_centrality, framework_nodes, find_definition_at, analyze_repo, explain, rank_nodes, query_ranked, explain_rank, snapshot_list, snapshot_show, and snapshot_diff. tscodekg mcp --manifest prints the live list as JSON without opening the graph.

See docs/MCP.md for setup and docs/CHEATSHEET.md for a query cookbook. Repo-local Claude Code skills live in skills/.

Snapshots & git hook

tscodekg snapshot save [VERSION] captures graph metrics (nodes, edges, JSDoc coverage, issues, hotspots) into .tscodekg/snapshots/, keyed on VERSION -- pass a release tag at release time, or omit it for a UTC timestamp key, which is what the per-commit hook below uses. The git tree hash is recorded as provenance, not the key. Deltas are computed against the previous and baseline snapshots. tscodekg install-hooks installs a pre-commit hook that rebuilds the index, captures a snapshot, stages the snapshot directory, and then runs the pre-commit framework checks — so every commit records the state of the knowledge graph. Skip it for one commit with TSCODEKG_SKIP_SNAPSHOT=1.

Python API

from tscode_kg import TypeScriptKG

kg = TypeScriptKG(repo_root="/path/to/ts-repo")
stats = kg.build(wipe=True)

result = kg.query("authentication middleware", k=8)
result.print_summary()

pack = kg.pack("error handling", k=8, hop=1)
pack.save("context.md")

Architecture

TypeScriptKG is a domain implementation of the KGModule base class from kgmodule-utils. Only the TypeScript/JS-specific extraction layer is implemented here — all generic infrastructure (SQLite, sqlite-vec, hybrid query, snippet packing) is inherited from KGModule.

Configuration

In your project's pyproject.toml:

[tool.tscodekg]
include = ["src"]           # top-level dirs to index (empty = all)
exclude = ["__tests__"]     # extra dirs to skip

Author

Eric G. Suchanek, PhD — Flux Frontiers

Citation

If you use TypeScriptKG in your research or project, please cite it:

DOI

Suchanek, E. G. (2026). TypeScriptKG: Semantic Knowledge Graph for TypeScript/JavaScript Codebases (Version 0.8.0) [Software]. Flux-Frontiers. https://doi.org/10.5281/zenodo.22559450

@software{suchanek_tscode_kg,
  author    = {Suchanek, Eric G.},
  title     = {{TypeScriptKG}: Semantic Knowledge Graph for TypeScript/JavaScript Codebases},
  version   = {0.8.0},
  year      = {2026},
  publisher = {Flux-Frontiers},
  doi       = {10.5281/zenodo.22559450},
  url       = {https://github.com/Flux-Frontiers/tscode_kg},
}

Full citation metadata in CITATION.cff.

License

Elastic-2.0

Metadata

Release files for tscode-kg 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tscode-kg 0.8.0
File Size Uploaded Provenance Actions
tscode_kg-0.8.0.tar.gz 113.1 kB With provenance Details for tscode_kg-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tscode-kg 0.8.0
File Interpreter ABI Platform Actions
tscode_kg-0.8.0-py3-none-any.whl Python 3 none any Details for tscode_kg-0.8.0-py3-none-any.whl

Total release size: 238.1 kB

Release files / tscode_kg-0.8.0.tar.gz

Download URL tscode_kg-0.8.0.tar.gz
Size 113.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7dcbcea7fafb174aee849e986428178e0b69a7569264a24033f058639bf5e74c
BLAKE2b-256 checksum
How to use checksums
17eab55ad001855278aaf2ccdb67754ae9cbc32c6778356611dc3f0d78ad06e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / tscode_kg-0.8.0-py3-none-any.whl

Download URL tscode_kg-0.8.0-py3-none-any.whl
Size 125.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac5cd10028b819cad15851f148458cfee8309a4997ec5e66a323a067e660def8
BLAKE2b-256 checksum
How to use checksums
7600f33b7aec318c75f91463bd7226b1f367e9e08888a3de86bc651239e8b255
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Security for tscode-kg 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tscode_kg-0.8.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page