Skip to main content

Agentic coding CLI with code graph intelligence and cost-aware context optimization.

Project description

RepoLens

Agentic Coding CLI with Code Graph Intelligence.

RepoLens is an open-source coding CLI focused on measurable engineering outcomes: smaller prompts, precise patches, graph-aware repository context, cache reuse, and cost visibility.

It is not positioned as a generic AI coding assistant. The core promise is:

The coding CLI that understands your repo and reduces token costs.

Current v0.1 Scope

repolens init
repolens providers
repolens graph build
repolens graph impact app/auth.py
repolens graph explain app/auth.py
repolens review "review auth security"
repolens fix "fix failing auth test" --path app/auth.py --apply
repolens agent fix "fix failing auth test" --path app/auth.py --apply
repolens stats
repolens optimize
repolens memory show

Implemented capabilities:

  • Provider abstraction for OpenAI, Anthropic, Google AI Studio, DeepSeek, and Ollama.
  • SQLite-backed usage, context, fix, failure, graph, and memory storage.
  • Code graph for files, imports, classes, functions, routes, and tests.
  • Graph-aware context selection with token reduction reporting.
  • Surgical, unified diff, and full-file patch modes.
  • Generated patch cache reuse.
  • Explicit agent workflow orchestration with planner, context, coder, reviewer, test, and repair states.
  • Local patch review gate before generated patches are written.
  • Targeted tests after generated fixes.
  • Bounded repair loop for failed targeted tests.
  • Usage and cost analytics.
  • Context optimization recommendations for generated files, snapshots, fixtures, lockfiles, and large files.
  • Repository memory for architecture, frameworks, build/test commands, generated paths, and provider preferences.

Install

From PyPI after release:

pip install repolens

From this repository:

pip install -e ".[dev]"

Provider Setup

Provider, model, base URL, and API keys are resolved entirely from the environment or the repo config — no model id is hardcoded in the application.

Set the API key for the provider(s) you use:

OPENAI_API_KEY=...
ANTHROPIC_API_KEY=...
GOOGLE_API_KEY=...
DEEPSEEK_API_KEY=...

Ollama uses a local server and does not require an API key.

Choosing or auto-suggesting a provider

Resolution precedence (highest first) for both provider and model:

  1. Explicit --provider / --model on the command.
  2. Environment variables REPOLENS_PROVIDER / REPOLENS_MODEL.
  3. The repo's .repolens/config.toml [provider] block (written by repolens init).
  4. Auto-suggested "best option" — the first provider with an available credential, in the order set by REPOLENS_PROVIDER_PREFERENCE (default deepseek, anthropic, openai, google, ollama). repolens init writes this suggestion into the config so it is a sensible, editable starting point.
repolens fix "fix login bug"                                   # auto-resolved provider + model
repolens fix "fix login bug" --provider anthropic --model claude-haiku-4-5
REPOLENS_PROVIDER=openai REPOLENS_MODEL=gpt-4o-mini repolens fix "fix login bug"

Inspect resolution at any time (offline, read-only — no provider call):

repolens providers

Shows which providers have a detected credential, each provider's base URL and default model, the auto-suggested best option, and the effective provider/model for the current repo with the precedence layer that decided each.

Overridable connection settings (env)

Variable Purpose
REPOLENS_PROVIDER, REPOLENS_MODEL Default provider / model
REPOLENS_PROVIDER_PREFERENCE Comma-separated auto-suggest order
REPOLENS_<PROVIDER>_MODEL Per-provider default model (e.g. REPOLENS_ANTHROPIC_MODEL)
<PROVIDER>_BASE_URL Per-provider base URL (e.g. ANTHROPIC_BASE_URL, OLLAMA_BASE_URL)

Typical Workflow

Initialize repository memory and storage:

repolens init

Build the graph:

repolens graph build

Inspect impact before changing a file:

repolens graph impact app/auth.py
repolens graph explain app/auth.py

Review with compact context:

repolens review "review auth security" --path app/auth.py

Generate and validate a fix without writing files:

repolens fix "fix expired JWT login failure" --path app/auth.py

Apply a generated fix:

repolens fix "fix expired JWT login failure" --path app/auth.py --apply

Run the explicit agent workflow with state trace:

repolens agent fix "fix expired JWT login failure" --path app/auth.py --apply

Generated apply path:

  1. Selects graph-aware compact context.
  2. Generates a patch through the provider.
  3. Validates the patch locally (parses and applies in memory, confirms targets stay inside the repo).
  4. Runs a deterministic patch review. This is a heuristic scan of the introduced lines for secret/risk patterns (hardcoded credentials, eval, shell=True, etc.) plus an oversized-patch check — it is a safety lint, not a correctness check, and does not verify that the fix is right.
  5. Writes the patch only if that review finds no blocking (critical/high) issues.
  6. Runs graph-related targeted tests. This is the real correctness gate — a patch that breaks the targeted tests is reported as failed.
  7. Runs a bounded repair loop if targeted tests fail.
  8. Records usage, cost, patch, test, and repair metadata.

Manual patch application remains available:

repolens fix "apply reviewed patch" --patch-mode diff --patch-file change.diff

Cost Visibility

repolens stats

Reports:

  • Usage events
  • Input/output/cached tokens
  • Estimated cost
  • Cache reuse
  • Provider and model usage

Context Optimization

repolens optimize

Reports token-heavy generated files, snapshots, fixtures, lockfiles, and large files with recommendations for exclusion or compression.

Repository Memory

repolens memory refresh
repolens memory show
repolens memory set provider.default deepseek

Stores durable repo facts such as frameworks, package managers, test commands, build commands, generated paths, and preferred provider/model. repolens init refreshes memory automatically.

Patch Modes

--patch-mode surgical
--patch-mode diff
--patch-mode full

Default is surgical.

Generated patches default to dry-run validation. Use --apply to write. Cached generated patches are still validated and reviewed before apply.

Safety Controls

--allow-dirty
--unsafe-skip-review
--test / --no-test
--repair / --no-repair
--repair-attempts 1

Defaults are conservative:

  • Dirty git targets are blocked unless --allow-dirty is used.
  • Generated patches are reviewed before writing.
  • Targeted tests run after generated apply.
  • One bounded repair attempt is allowed after targeted test failure.

Documentation

Contributing

License

Apache-2.0.

Project details


Download files

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

Source Distribution

repolens_ai-0.1.0.tar.gz (134.8 kB view details)

Uploaded Source

Built Distribution

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

repolens_ai-0.1.0-py3-none-any.whl (129.3 kB view details)

Uploaded Python 3

File details

Details for the file repolens_ai-0.1.0.tar.gz.

File metadata

  • Download URL: repolens_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 134.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for repolens_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 40a8e456b3c0f37eb6aa90ef386f6c58ab5b9c8cc6eabf2facb780a2dafbd90f
MD5 014f178fb4dc658abe7fa5c0878b2b24
BLAKE2b-256 61e9346fbb32156df37304bca913881c75dbf519f26e32235a4f20d1e182cb1f

See more details on using hashes here.

File details

Details for the file repolens_ai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: repolens_ai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 129.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for repolens_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f5710cb60f1e238743263b5058d718b9a74a19be65adb3aaf4a79697bbef32d
MD5 5ca8e73299d4f79984c83ea6dcc10c86
BLAKE2b-256 8fc03f86793d9c405532133d463cf7c4539b22d66b342e5a1e8efda762212fb1

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