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: graph_stats, query_codebase, pack_snippets, callers, get_node, 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.

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.5.1) [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.5.1},
  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.5.1

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.5.1
File Size Uploaded
tscode_kg-0.5.1.tar.gz 114.6 kB Details

Built distribution (wheel)

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

Total release size: 240.5 kB

Release files / tscode_kg-0.5.1.tar.gz

Download URL tscode_kg-0.5.1.tar.gz
Size 114.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6f1e6c66634ecde2b86548bf7be392455f981ec659a2db4abf8df1d938d77dec
BLAKE2b-256 checksum
How to use checksums
696448e9375f507feb1cb45f4c2fdf383d31c705087dba97a29f0e208f99d0c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 18, 2026.

Transparency log

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

Download URL tscode_kg-0.5.1-py3-none-any.whl
Size 125.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a8f1431886b5aec71b4b0c32abe23b789987444af09c898637bde88b852478d
BLAKE2b-256 checksum
How to use checksums
98bae20e6240ffd7eb317b18e6d0f88186116ea5349165dc11deed3c72e82367
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 18, 2026.

Transparency log

Release history Release notifications | RSS feed

0.7.0

2 release files

0.6.0

2 release files

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

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