Skip to main content

AI Context Core

CI PyPI Version GitHub Release Python Versions Downloads License Linting: Ruff

Compile token-efficient, verifiable context for AI-assisted coding.

ai-context-core (CLI ai-ctx) turns a Python project into context artifacts an AI agent can consume: a structured AI_CONTEXT.md, a machine-readable project_context.json, a token context_manifest.json and a symbol index. Everything is versioned, provenance-tagged and optionally token-budgeted.

Context-only contract (v5.0.0). ai-context-core is a context compiler (source → transform → render → verify): it consumes analysis instead of owning it. QGIS compliance, i18n, security scanning and quality gates live in qgis-plugin-analyzer; scaffolding in agentic-forge. Commands such as audit, qgis, security, patterns, inspect, full-scan, fix, scaffold, doctor, interactive and serve were removed (hidden redirect stubs remain for one release). See ADR-0008, the v5.0.0 plan and the CHANGELOG.

Features

Context compilation

  • Pluggable sources: --source auto|external|builtin. external consumes qgis-plugin-analyzer output (analysis_results/project_context.json); builtin runs the internal AST engine. auto prefers external when present.
  • Hybrid by design: structure tree, git evolution and manual notes are always computed by ai-context-core; the analysis fields come from the selected source.
  • Provenance: every artifact carries a _meta block (source, schema, tool_version, git_sha, content_hash).

Token budget & manifest

  • ai-ctx context --max-tokens N caps AI_CONTEXT.md with deterministic truncation; per-section caps via [context.budget].
  • context_manifest.json records exact per-section token deltas, the budget and the total (total == header + sum(sections)).

Verification & index

  • ai-ctx verify exits 1 when the tracked sources changed since the last render (content hash); ai-ctx context --check gates CI.
  • ai-ctx symbols [--grep] writes a versioned symbols.json (definitions and references with file:line).
  • ai-ctx health reports freshness, token usage, symbol coverage and provenance — no quality gate; it fails only on staleness.

Context analysis (builtin source)

  • Structure: project tree, slide-of-code and file statistics.
  • Entry points: __main__-guard detection.
  • Dependencies: import graph, circular dependencies, unused imports, coupling (CBO), graph density/DAG, Mermaid diagram.
  • Git evolution: hotspots and code churn.
  • Metrics: cyclomatic complexity, Maintenance Index, type-hint coverage.

Performance & robustness

  • Incremental cache: hybrid mtime + SHA-256 file cache (--no-cache to bypass).
  • Smart parallelism: sequential below a threshold, batched ProcessPoolExecutor above it.
  • Fast ignore: compiled-regex file filtering via .analyzerignore.
  • Staleness-safe hashing: verification bypasses the in-process read cache.

Installation

# As a global tool
uv tool install ai-context-core

# Or inside a virtual environment
uv venv && source .venv/bin/activate
uv pip install ai-context-core

Using pip

pip install ai-context-core

It is always recommended to use a virtual environment.

Quick start

# 1. Initialize the .ai-context structure (optional)
ai-ctx init

# 2. Compile context artifacts
ai-ctx context                       # AI_CONTEXT.md + project_context.json + context_manifest.json
ai-ctx context --source external     # consume qgis-plugin-analyzer output
ai-ctx context --max-tokens 8000     # enforce a token budget
ai-ctx context --check               # generate and assert freshness (CI)

# 3. Verify and inspect
ai-ctx verify                        # exit 1 if sources changed since render
ai-ctx symbols --grep my_function    # file:line index lookup
ai-ctx health                        # freshness + tokens + symbols + provenance

Generated artifacts

Artifact Description
AI_CONTEXT.md Structured, token-budgeted context for LLMs.
project_context.json Machine-readable analysis payload + _meta provenance.
context_manifest.json Per-section token counts, budget and total.
symbols.json Versioned symbol index (definitions + references).
PROJECT_SUMMARY.md Human-readable summary (emitted by analyze).

Configuration

Full reference: docs/CONFIGURATION.md. Defaults live in src/ai_context_core/config/defaults.toml.

context_docs = []                      # extra markdown to embed as architecture notes

[context]
sections = ["structure", "metrics", "dependencies", "git"]

[context.budget]
max_tokens = 8000                      # override per run with --max-tokens N
# [context.budget.sections]
# structure = 1500

[sources]
source = "auto"                        # auto | external | builtin
# external_path = "analysis_results/project_context.json"

Analysis scope (.analyzerignore)

ai-ctx reads .analyzerignore at the project root to exclude paths from the analysis scope (modules, dependency graph, code metrics).

Commands reference

Compile & verify

Command Description
ai-ctx context Compile AI_CONTEXT.md, project_context.json, context_manifest.json (primary path). Options: --source, --max-tokens, --check, --include-md, --no-cache, --workers.
ai-ctx analyze Run the pipeline and emit AI_CONTEXT.md, PROJECT_SUMMARY.md, project_context.json. Options: --source, --format markdown|json, --include-md, --no-cache, --workers.
ai-ctx verify Exit 1 when artifacts are stale relative to the tracked sources.
ai-ctx symbols Build symbols.json; --grep <text> prints matching file:line entries.
ai-ctx health Context freshness, token usage, symbol coverage, provenance.

Inspect

Command Description
ai-ctx stats Quick project statistics (SLOC, modules, complexity, maintenance index).
ai-ctx deps Dependency analysis: --unused, --cycles, --metrics (CBO, density, DAG).
ai-ctx git Git evolution: hotspots and churn (--days N).
ai-ctx graph Export the dependency model as a Mermaid diagram (--output ARC.mmd).
ai-ctx roadmap Refactor priority (complexity × churn).
ai-ctx compare <a> <b> Diff two analysis JSON reports by metric.
ai-ctx help-me Context-health recommendations.

Project setup

Command Description
ai-ctx init Create .ai-context config and workflow templates (--profile <name>).
ai-ctx profiles List available profiles (python-generic).
ai-ctx clean Remove cache and generated artifacts (--dry-run to preview).

Metrics

Metrics are heuristics computed from static analysis and are not directly comparable to the canonical metrics of other tools (e.g. qgis-analyzer).

Metric Definition Notes
ai-ctx Quality Score → context health Aggregated 0–100 heuristic: base 100 minus penalties for average/outlier complexity, low maintainability and missing tests, plus test bonuses. Includes an explicit score breakdown. Tool-specific; not a gate. Being reframed as context health (see ADR-0008).
Avg Cyclomatic Complexity Arithmetic mean of per-module cyclomatic complexity. An average; qgis-analyzer applies a per-function gate (CC ≤ 10).
Avg Maintenance Index (MI) SEI Maintenance Index normalized to 0–100, averaged across modules. Exclusive to ai-context-core.
Max Complexity Highest single-module cyclomatic complexity. Complements the average to surface outliers.

API stability and deprecations

The canonical public API lives under ai_context_core.analyzer (engine, providers, visitors, builders), ai_context_core.sources, ai_context_core.context, ai_context_core.model and ai_context_core.cli.commands. Anything else is internal.

Deprecated compatibility aliases emit a DeprecationWarning and are scheduled for removal in v5.0.0 (REMOVAL_VERSION):

Deprecated path Use instead
analyzer.builders.aggregator.ContextAggregator analyzer.builders.aggregator.ResultsAggregator

Docker support

Reproducible development, testing and CI via Docker:

make docker-build    # Build all images
make docker-test     # Run the test suite with coverage
make docker-shell    # Interactive development shell
make docker-lint     # Run the linter

License

This project is licensed under the GNU General Public License v3 (GPLv3). See the LICENSE file for the full license text.

Metadata

Release files for ai-context-core 5.0.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 ai-context-core 5.0.0
File Size Uploaded
ai_context_core-5.0.0.tar.gz 115.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ai-context-core 5.0.0
File Interpreter ABI Platform
ai_context_core-5.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 239.6 kB

Release files / ai_context_core-5.0.0.tar.gz

Download URL ai_context_core-5.0.0.tar.gz
Size 115.0 kB
Tags Source
SHA-256 checksum
How to use checksums
be15507fe121f985bc5bd43b35385e256ad318233ba18ed1c522848a67bded59
BLAKE2b-256 checksum
How to use checksums
3d7126abde2be0d56c88346ad64dace83cee2e784887f5544c9123b851999425
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Manjaro Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / ai_context_core-5.0.0-py3-none-any.whl

Download URL ai_context_core-5.0.0-py3-none-any.whl
Size 124.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5e3e41df558c7d1fcf6e8e8b41bb6eefcf25e3dbc312446a1b3e67cd344b3281
BLAKE2b-256 checksum
How to use checksums
7e1980266e1f7e3de105647ced613bc50c2db6bdcdc40f9226be35fe6789a269
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Manjaro Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

5.1.0

2 release files

5.0.1

2 release files

This release

5.0.0 This release

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.3.0

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.5.2

2 release files

2.5.1

2 release files

2.5.0

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.0.1

2 release files

1.0.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