Skip to main content

Code intelligence tool — fix, scan, and advise on Python, JSON, YAML, and Rust (advisory)

Project description

imodent

PyPI version CI License

Code intelligence tool — fix, scan, and advise on Python, JSON, JSONL, and YAML files.

imodent is a fast first-look mapper and conservative fixer. It is useful for finding syntax blockers, import hygiene issues, lint-backed risks, and areas that need review. It does not replace deeper codegraph or model-assisted code understanding.

Features

  • Auto-detection: Detects Python, JSON, JSONL, YAML automatically
  • AST-based fixing: Python code fixed with Black, validated with ast.parse()
  • Import analysis: Detect unused, duplicate, and misused imports — with 5 fix options (delete, keep, investigate, false-positive, keep-typing)
  • Ruff-backed lint evidence: Attach external lint diagnostics to scan findings
  • Confidence output: Show decision candidates with evidence, confidence, and destructive-action policy
  • Architecture advisor: Circular dependency detection, import clustering warnings
  • Pre-flight checks: Refuses to "fix" structurally broken code (use --force to override)
  • Extensible: Add new languages via @StrategyRegistry.register — no core changes needed
  • CLI: Two modes — FIX (default) and SCAN (--analyze)

Install

pip install -e .
# or system-wide:
pipx install .

Usage

FIX mode — reformat & repair files

# Fix a file with backup
imodent myfile.py --backup

# Preview changes without writing
imodent myfile.py --dry-run

# Syntax check only
imodent myfile.py --check

# Recursive directory scan
imodent ./src --recursive --indent 2 --backup

# Fix structurally broken code (skips pre-flight check)
imodent broken.py --force

SCAN mode — project-wide analysis

# Find unused & duplicate imports
imodent ./src --analyze --imports

# Review without modifying files
imodent ./src --report

# Add Ruff-backed lint evidence
imodent ./src --analyze --imports --lint --report

# Show confidence-weighted decision candidates
imodent ./src --analyze --imports --lint --confidence --report

# Flag architectural issues
imodent ./src --analyze --advisory

# Auto-fix safe findings (analysis implied)
imodent ./src --fix

# Auto-fix safe findings with explicit import analysis
imodent ./src --analyze --imports --fix

# Full audit + fix
imodent ./src --analyze --imports --advisory --fix

SCAN mode always recurses into subdirectories. --report, --confidence, --imports, --lint, --advisory, --interactive, and --fix all route to SCAN mode. -b, -n, and -c also work with scan fixes. -r and --force are FIX-mode controls; when used with scan flags, imodent prints a note.

Import analysis options

When --imports finds an unused import, interactive mode can offer review choices such as:

Option When to use
delete Import is genuinely unused
keep Type hints, re-exports, __all__ entries
keep-typing Import is kept specifically for type annotations
investigate Search codebase before deciding
false-positive Analysis missed a usage (dynamic import, string reference)

Non-interactive --fix only applies findings marked safe by the fixer. Most unused-import candidates remain review-only unless the tool has enough evidence to avoid deleting intent.

Python API

from imodent import FixPipeline

pipeline = FixPipeline(indent_size=4)

# Fix content (auto-detects language)
result = pipeline.fix(messy_code)
if result.success:
    print(result.content)
else:
    for error in result.errors:
        print(f"Error: {error}")

# Force fix on structurally broken code
result = pipeline.fix(broken_code, force=True)

Analysis API

from pathlib import Path

from imodent import AnalysisCoordinator

coordinator = AnalysisCoordinator()
result = coordinator.analyze([Path("src/")])

for finding in result.findings:
    print(f"{finding.severity.value}: {finding.message}")

Add a New Language

from imodent.interfaces import LanguageStrategy, FixResult
from imodent.registry import StrategyRegistry


@StrategyRegistry.register
class TOMLStrategy(LanguageStrategy):
    @property
    def name(self) -> str:
        return "toml"

    @property
    def extensions(self) -> list[str]:
        return [".toml"]

    def detect(self, content: str) -> bool:
        return "[[" in content or "=" in content

    def fix(self, content: str, indent_size: int = 4, force: bool = False) -> FixResult:
        # Your fixing logic
        return FixResult(
            success=True,
            content=content,
            errors=[],
            warnings=[],
            original_valid=True,
            fixed_valid=True,
        )

    def validate(self, content: str) -> tuple[bool, str | None]:
        return True, None

No core changes needed — the strategy auto-registers and the pipeline picks it up.

CLI Reference

Flag Mode Description Default
-i N FIX Indent size (spaces) 4
-b FIX Create .bak backup off
-n FIX Dry run (preview only) off
-c FIX Check only (no fix) off
-r FIX Recursive directory scan off
--force FIX Attempt fix on structurally broken code off
--analyze SCAN Enable project-wide analysis off
--imports SCAN Detect import issues off
--lint SCAN Run lint checks off
--advisory SCAN Flag architectural issues off
--fix SCAN Auto-fix safe findings off
--interactive SCAN Prompt before each fix off
--report SCAN Review findings without modifying files off
--confidence SCAN Show evidence-backed decision candidates off
-v SCAN Show all findings off

-b, -n, and -c are shared controls when scan fixes are enabled. --check prevents --fix from applying changes and prints a note explaining the conflict.

Supported Formats

Format Detection Fixing Validation
Python Keywords + AST parse Black → AST heuristic ast.parse()
JSON {/[ + json.loads() Pretty-print with indent json.loads()
JSONL Each line valid JSON Compact each line json.loads() per line
YAML --- or key patterns + yaml.safe_load() Pretty-print with proper list indent yaml.safe_load()

Known Limitations

  • Confidence is rule-based, not proof of developer intent.
  • Fragmented workspaces with multiple import roots can produce ambiguous import findings.
  • Type-only or quoted annotation issues may need human review even when Ruff reports them as F821.
  • Default scan discovery skips common generated artifacts and test files; run targeted paths when you want to inspect those.
  • Use codegraph or manual review for deep impact analysis. imodent is the fast mapper and conservative hygiene layer.

License

MIT

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

imodent-1.0.0a7.tar.gz (255.2 kB view details)

Uploaded Source

Built Distribution

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

imodent-1.0.0a7-py3-none-any.whl (108.5 kB view details)

Uploaded Python 3

File details

Details for the file imodent-1.0.0a7.tar.gz.

File metadata

  • Download URL: imodent-1.0.0a7.tar.gz
  • Upload date:
  • Size: 255.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for imodent-1.0.0a7.tar.gz
Algorithm Hash digest
SHA256 59acd60adce645cb79c8c5ca09c2639c53b2b7e6bcc3fbd0b811ffeba9f05a0b
MD5 011c60f1f2a020ec29f5ab0d237ee21f
BLAKE2b-256 794a9b9071cc3d0838ac9c458d43b95cec4156d50b0505c75fd31867db3cebb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for imodent-1.0.0a7.tar.gz:

Publisher: release.yml on moeshawky/imodent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file imodent-1.0.0a7-py3-none-any.whl.

File metadata

  • Download URL: imodent-1.0.0a7-py3-none-any.whl
  • Upload date:
  • Size: 108.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for imodent-1.0.0a7-py3-none-any.whl
Algorithm Hash digest
SHA256 7f61d12dc3b5ed430b27a3e6ecad8cc96b16eb312741ad807c89499d3f8a6714
MD5 cee0674efe17b2c05f57308b10809cf2
BLAKE2b-256 81db761138569a4dedfe9bfbd8cca8d18d18f383b9073e5d9c78a12c29073257

See more details on using hashes here.

Provenance

The following attestation bundles were made for imodent-1.0.0a7-py3-none-any.whl:

Publisher: release.yml on moeshawky/imodent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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