Skip to content

Latest commit

Β 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

KontextMind

The Shared Project Brain for AI Coding Agents

KontextMind is a CLI tool and HTTP API server that provides AI coding agents with a centralized knowledge base about your project. It indexes code, generates summaries, builds knowledge graphs, and enables Q&A functionalityβ€”all designed to help AI assistants understand and work with your codebase more effectively.

Features

Core Capabilities

  • Code Indexing β€” Scans project files and builds a comprehensive file index with change detection
  • Symbol Extraction β€” Parses code to extract functions, classes, interfaces, and their relationships
  • AI Summaries β€” Generates natural language summaries for files, functions, and modules using LLM providers
  • Knowledge Graph β€” Builds a graph of project entities and their dependencies
  • Chatbot KB β€” A knowledge base that answers questions about your project without revealing code
  • Session Management β€” Multi-turn conversations with persistent context
  • Dataset Preparation β€” Export training-ready datasets from Q&A interactions

Security & Privacy

  • No Code Exposure β€” The chatbot never reveals source code, file paths, or directory structures
  • Secret Scanning β€” Detects secrets and credentials committed to the repository
  • Privacy-First β€” Designed to protect sensitive project information

Integration Points

  • CLI β€” Full-featured command-line interface
  • HTTP API β€” REST API server for frontend applications
  • MCP Server β€” Model Context Protocol server for AI agent integration

Installation

# Clone the repository
git clone https://github.com/your-org/kontextmind.git
cd kontextmind

# Install dependencies
pnpm install

# Build all packages
pnpm build

# Link CLI globally (optional)
pnpm link -g

Requirements

  • Node.js 18+
  • pnpm 8+
  • For AI features: An LLM provider (OpenAI, Anthropic, Ollama, or custom)

Quick Start

1. Initialize a Project

cd your-project
kontextmind init

This creates:

  • .kontextmind/config.json β€” Project configuration
  • CLAUDE.md β€” Context for AI assistants
  • AGENTS.md β€” Agent-specific instructions
  • .roo/mcp.json, .mcp.json, .codex/config.toml, .cursor/mcp.json β€” Agent IDE MCP configs
  • Policy and instruction files

2. Index Your Project

# Scan files and build index
kontextmind scan

# Extract symbols and build knowledge graph
kontextmind index

# Generate AI summaries (requires LLM provider)
kontextmind summarize --mock    # Use mock provider
kontextmind summarize           # Use configured provider

3. Build the Knowledge Base

# Build chatbot knowledge base
kontextmind kb build

4. Ask Questions

# Simple Q&A
kontextmind ask "What is this project about?"

# With JSON output
kontextmind ask "How does authentication work?" --json

# Session-based chat
kontextmind session create
kontextmind session chat <session-id> "What files handle user authentication?"

5. Start API Server

# Start HTTP API server
kontextmind serve --port 7331

# Or with custom settings
kontextmind serve --port 8080 --host 0.0.0.0

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        User Interface Layer                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   CLI  β”‚  β”‚ HTTP API β”‚  β”‚ MCP CLI β”‚  β”‚  Frontend / AI Agent   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚           β”‚            β”‚                   β”‚
        β–Ό           β–Ό            β–Ό                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         Core Package (@kontextmind/core)             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   Scanner    β”‚  β”‚   Parser    β”‚  β”‚  Summaries  β”‚  β”‚ Chatbot β”‚  β”‚
β”‚  β”‚   Index      β”‚  β”‚  Symbols    β”‚  β”‚  Knowledge  β”‚  β”‚   KB    β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   Session    β”‚  β”‚   Dataset    β”‚  β”‚   Security   β”‚  β”‚   Init  β”‚  β”‚
β”‚  β”‚   Manager    β”‚  β”‚   Pipeline   β”‚  β”‚   Audit     β”‚  β”‚  Config β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Packages

Package Description
@kontextmind/core Core functionality: scanner, parser, summaries, chatbot KB
@kontextmind/cli Command-line interface
@kontextmind/server HTTP API server
@kontextmind/mcp MCP (Model Context Protocol) server
@kontextmind/client JavaScript client library

Project Structure

kontextmind/
β”œβ”€β”€ apps/
β”‚   └── cli/                    # Command-line interface
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ core/                   # Core functionality
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ chatbot/        # Chatbot knowledge base
β”‚   β”‚       β”‚   β”œβ”€β”€ session-manager.ts   # Session management
β”‚   β”‚       β”‚   β”œβ”€β”€ context-builder.ts  # Context building
β”‚   β”‚       β”‚   └── kb-builder.ts       # Knowledge base builder
β”‚   β”‚       β”œβ”€β”€ dataset/        # Dataset preparation
β”‚   β”‚       β”‚   β”œβ”€β”€ collector.ts        # Data collection
β”‚   β”‚       β”‚   β”œβ”€β”€ quality-filter.ts  # Quality filtering
β”‚   β”‚       β”‚   β”œβ”€β”€ versioning.ts       # Version control
β”‚   β”‚       β”‚   └── formats/           # Export formats
β”‚   β”‚       β”œβ”€β”€ config/         # Configuration schemas
β”‚   β”‚       β”œβ”€β”€ filesystem/     # File utilities
β”‚   β”‚       β”œβ”€β”€ init/          # Project initialization
β”‚   β”‚       β”œβ”€β”€ obsidian/      # Obsidian export
β”‚   β”‚       β”œβ”€β”€ parser/        # Code parsing
β”‚   β”‚       β”œβ”€β”€ providers/     # LLM providers
β”‚   β”‚       β”œβ”€β”€ scanner/       # File scanning
β”‚   β”‚       β”œβ”€β”€ security/      # Security audit
β”‚   β”‚       β”œβ”€β”€ summaries/     # AI summaries
β”‚   β”‚       └── templates/     # Template rendering
β”‚   β”œβ”€β”€ server/               # HTTP API server
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ routes/       # API routes
β”‚   β”‚       β”‚   β”œβ”€β”€ ask.ts           # Ask endpoints
β”‚   β”‚       β”‚   β”œβ”€β”€ sessions.ts      # Session endpoints
β”‚   β”‚       β”‚   β”œβ”€β”€ feedback.ts      # Feedback endpoints
β”‚   β”‚       β”‚   └── dataset.ts       # Dataset endpoints
β”‚   β”‚       └── services/     # Business logic
β”‚   β”‚           β”œβ”€β”€ ask-service.ts
β”‚   β”‚           β”œβ”€β”€ session-service.ts
β”‚   β”‚           β”œβ”€β”€ feedback-service.ts
β”‚   β”‚           └── dataset-service.ts
β”‚   β”œβ”€β”€ mcp/                  # MCP server
β”‚   β”œβ”€β”€ adapters/             # Provider adapters
β”‚   └── client/               # Client library
β”œβ”€β”€ docs/                    # Documentation
β”‚   β”œβ”€β”€ cli-reference.md     # CLI commands reference
β”‚   └── api-reference.md     # API endpoints reference
└── templates/               # Project templates

Configuration

Project Configuration (.kontextmind/config.json)

{
  "project": {
    "name": "my-project",
    "description": "Description of what this project does"
  },
  "mode": "readonly",
  "phase": 1,
  "agents": ["claude", "codex", "roo", "cursor"],
  "git": {
    "enabled": true,
    "mode": "auto"
  }
}

Providers Configuration (.kontextmind/providers.json)

{
  "selected_provider": "openai",
  "providers": {
    "openai": {
      "type": "openai",
      "api_key_env": "OPENAI_API_KEY",
      "model": "gpt-4"
    },
    "ollama": {
      "type": "ollama",
      "base_url": "http://localhost:11434",
      "model": "llama3"
    }
  }
}

Environment Variables

Variable Description Default
DATA_DIR Directory for project data /kontextmind/projects
LOG_LEVEL Logging level info

Modes

KontextMind operates in four modes:

Mode File Modifications Description
readonly Prohibited Summaries and context only
suggest Prohibited Suggestions without implementation
edit-with-approval Requires approval Implement with explicit approval
full-agent Allowed Act autonomously within policy

Session-Based Chat

KontextMind supports multi-turn conversations with persistent context.

How It Works

  1. Create a Session β€” Each conversation gets a unique ID
  2. Build Context β€” The system tracks topics, entities, and conversation history
  3. Enhanced Responses β€” Questions are answered with conversation context
  4. Link to Dataset β€” Session data enriches the training dataset

Benefits

  • No Context Repeating β€” Users don't need to re-explain the project
  • Better Answers β€” The LLM has conversation history
  • Rich Dataset β€” Follow-up questions show engagement patterns
  • Topic Tracking β€” Sessions track what topics were discussed

Example Flow

# Create session
kontextmind session create
# Session created: abc-123-xyz

# Ask first question
kontextmind session chat abc-123-xyz "How does auth work?"
# Returns answer with conversationTurn: 1

# Ask follow-up
kontextmind session chat abc-123-xyz "Show me the relevant files"
# Returns answer with conversationTurn: 2

# List all sessions
kontextmind session list

# View session details
kontextmind session show abc-123-xyz

Dataset Preparation

KontextMind collects Q&A interactions for training AI models.

Data Collection

The system automatically collects:

  1. Q&A Events β€” Questions and answers with metadata
  2. Feedback β€” Like/dislike signals from users
  3. Session Data β€” Multi-turn conversation context
  4. Quality Scores β€” Computed from confidence and feedback

Quality Filtering

Records are filtered by:

  • Confidence Threshold β€” Minimum confidence score (default: 0.5)
  • Source Priority β€” API > MCP > CLI (better feedback quality)
  • Code Request Detection β€” Auto-negative for code requests
  • Deduplication β€” Remove duplicate questions
  • Age Filter β€” Records older than 90 days excluded by default

Export Formats

Format Use Case
jsonl Line-oriented training (Llama, Mistral)
json Batch processing
chatml Chat-based models
sharegpt ShareGPT compatible

Version Control

Datasets are versioned for tracking changes:

# Export dataset
kontextmind dataset export --format jsonl --output dataset.jsonl

# View statistics
kontextmind dataset stats

# Validate quality
kontextmind dataset validate --min-quality 0.6

# List versions
kontextmind dataset version list

Security

No Code Exposure

The chatbot is configured with strict policies:

  • No source code in responses
  • No file paths or directory structures
  • No code formatting in output

Secret Scanning

# Scan for secrets
kontextmind secrets --fail-on-critical

# Output as JSON
kontextmind secrets --json

Audit Logging

# View audit summary
kontextmind audit --since 24h

# Export audit log
kontextmind audit --json

MCP Server

KontextMind includes an MCP server for AI agent integration.

Starting MCP Server

# STDIO transport (default)
kontextmind mcp

# HTTP transport
kontextmind mcp --transport http --port 7332

Development

Building

# Build all packages
pnpm build

# Build specific package
pnpm --filter @kontextmind/core build

Testing

# Run tests
pnpm test

# Run specific package tests
pnpm --filter @kontextmind/core test

Documentation


License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages