Skip to main content

Auto-generate structured knowledge base documents from source code. Supports AI agent mode (skill-based) and standalone CLI.

Project description

source-kb

English | 中文

Auto-generate structured knowledge base documents from source code, build vector indexes, and support RAG retrieval.

Features

  • CLI toolchain: skeleton extraction, prompt rendering, intelligent splitting, quality validation, vector indexing — all standalone Python scripts
  • Platform-agnostic: works in Kiro / Cursor / Claude Code / Windsurf / any AI Agent
  • LLM-agnostic: without an Agent, use engine with any OpenAI-compatible API (Anthropic / OpenAI / DeepSeek / Ollama / vLLM, etc.)
  • Intelligent subagent splitting: semantic grouping by business domain (LLM-based) or package-aware greedy algorithm (code-based)
  • Two-phase generation: outline first, then expand — eliminates information isolation between shards
  • Method-level source injection: prioritized by complexity (high=full body / medium=first 20 lines / low=signature only)
  • Real-time quality validation: each subagent output is verified immediately, with automatic retry on failure
  • Document deduplication: LLM-powered post-merge dedup (internal redundancy + cross-doc ownership)
  • Module doc distillation: summarize multiple microservice docs into domain-level documentation
  • Any language support via preset system (java-spring built-in)
  • Source code access through git remote (multi-repo & monorepo)
  • Lightweight self-built RAG engine (ChromaDB + pluggable embedding)
  • Auto-publish docs to source repo knowledge branch

Quick Start

Option 1: Skill Mode (recommended)

Install the CLI toolchain:

pip install source-kb[full]

# If you have multiple Python versions, specify the target version:
py -3.12 -m pip install source-kb[full]

Install skills to your Agent's directory:

source-kb install-skills --agent kiro     # Kiro
source-kb install-skills --agent cursor   # Cursor
source-kb install-skills --agent claude   # Claude Code

This automatically installs presets/ and examples/ to ~/.source-kb/ (shared globally across all projects). To install global assets only:

source-kb install-skills --assets-only   # Install presets/ + examples/ to ~/.source-kb/

Then talk to your AI Agent (Kiro / Claude Code / Cursor / Windsurf):

Please read skills/kb-init/SKILL.md and follow the steps to initialize the knowledge base.

Or add the guide to your project rules file (.kiro/steering/, .cursorrules, .claude/CLAUDE.md, etc.). See Getting Started.

Non-Java project? Works the same way. Configure kb-project.yaml with the generic preset:

# Use generic preset (works for any language)
source-kb extract --repo .source-cache/my-app --preset generic --output knowledge/my-app

The generic preset uses path-based rules + regex parser for file classification — no tree-sitter required. For higher accuracy, create a custom preset following presets/java-spring/ as reference.

Option 2: CLI Mode (no Agent, requires LLM API config)

pip install source-kb[full]

export LLM_BASE_URL="https://api.anthropic.com"
export LLM_MODEL="claude-sonnet-4-6"
export LLM_API_KEY="sk-xxx"
source-kb extract --repo .source-cache/my-app --preset java-spring --summary --output knowledge/my-app
source-kb index --kb my-app

Full guide: Getting Started.

CLI Quick Reference

# Skeleton extraction
source-kb extract --repo .source-cache/xxx --preset java-spring --summary --output knowledge/xxx

# Prompt rendering
source-kb render --template presets/java-spring/templates/subagent-business.md --module xxx --kb yyy --doc-type business-logic --mode readwrite

# File list extraction
source-kb file-list --module-dir knowledge/xxx --preset java-spring --doc-type business-logic --output knowledge/xxx/.meta/file-lists/business-logic.txt

# Coverage validation
source-kb validate coverage check --module-dir knowledge/xxx --docs-dir knowledge/xxx --type service

# Index & search
source-kb index --kb my-project
source-kb search --kb my-project "query"

Skills

Skill Purpose
kb-init Generate all docs from source + build index
kb-audit Compare docs vs source, fix inconsistencies
kb-sync Detect git changes, incrementally update docs and index
kb-search Vector retrieval + contextual answers

Skill files are Agent operation guides — no platform-specific instructions.

Requirements

  • Python 3.10~3.12 (⚠️ 3.13 not supported — tree-sitter-languages has no prebuilt wheel)
  • Git
  • Embedding backend (Ollama / OpenAI-compatible / DashScope / ChromaDB built-in)

Installation

# Basic install (CLI toolchain)
pip install source-kb

# Full install (skeleton parsing + vector index)
pip install source-kb[full]

# Skeleton parsing only (tree-sitter)
pip install source-kb[skeleton]

# Vector index only (ChromaDB)
pip install source-kb[rag]

Verify installation:

source-kb --version
source-kb --help

Documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

source_kb-0.2.37-py3-none-any.whl (564.6 kB view details)

Uploaded Python 3

File details

Details for the file source_kb-0.2.37-py3-none-any.whl.

File metadata

  • Download URL: source_kb-0.2.37-py3-none-any.whl
  • Upload date:
  • Size: 564.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for source_kb-0.2.37-py3-none-any.whl
Algorithm Hash digest
SHA256 abf0d73d6160fa2243ebb97cc219815888f41cb3682d4a54bf835095fd8ba74d
MD5 497c487bcc2fc32a6a0221bf2f1b8f42
BLAKE2b-256 76d6308212fd966a59fe5fc7862e7bc6b2ebb038ecc1477cb8e6ba97534e6b3c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page