imodent 1.0.0a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- imodent-1.0.0a1/LICENSE +21 -0
- imodent-1.0.0a1/MANIFEST.in +36 -0
- imodent-1.0.0a1/PKG-INFO +251 -0
- imodent-1.0.0a1/README.md +213 -0
- imodent-1.0.0a1/imodent/__init__.py +59 -0
- imodent-1.0.0a1/imodent/advisors/__init__.py +5 -0
- imodent-1.0.0a1/imodent/advisors/architecture.py +120 -0
- imodent-1.0.0a1/imodent/advisors/base.py +50 -0
- imodent-1.0.0a1/imodent/analysis/__init__.py +36 -0
- imodent-1.0.0a1/imodent/analysis/context.py +205 -0
- imodent-1.0.0a1/imodent/analysis/coordinator.py +662 -0
- imodent-1.0.0a1/imodent/analysis/decisions.py +729 -0
- imodent-1.0.0a1/imodent/analysis/evidence.py +74 -0
- imodent-1.0.0a1/imodent/analysis/findings.py +135 -0
- imodent-1.0.0a1/imodent/analyzers/__init__.py +7 -0
- imodent-1.0.0a1/imodent/analyzers/base.py +72 -0
- imodent-1.0.0a1/imodent/analyzers/imports.py +782 -0
- imodent-1.0.0a1/imodent/analyzers/lint.py +403 -0
- imodent-1.0.0a1/imodent/analyzers/residue.py +174 -0
- imodent-1.0.0a1/imodent/analyzers/rust.py +620 -0
- imodent-1.0.0a1/imodent/analyzers/types.py +184 -0
- imodent-1.0.0a1/imodent/cli.py +650 -0
- imodent-1.0.0a1/imodent/fixers/__init__.py +5 -0
- imodent-1.0.0a1/imodent/fixers/base.py +77 -0
- imodent-1.0.0a1/imodent/fixers/imports.py +229 -0
- imodent-1.0.0a1/imodent/graph/__init__.py +13 -0
- imodent-1.0.0a1/imodent/graph/dependency.py +197 -0
- imodent-1.0.0a1/imodent/graph/imports.py +187 -0
- imodent-1.0.0a1/imodent/interfaces.py +121 -0
- imodent-1.0.0a1/imodent/pipeline.py +124 -0
- imodent-1.0.0a1/imodent/project/__init__.py +0 -0
- imodent-1.0.0a1/imodent/project/config.py +160 -0
- imodent-1.0.0a1/imodent/project/discovery.py +30 -0
- imodent-1.0.0a1/imodent/project/project_context.py +107 -0
- imodent-1.0.0a1/imodent/py.typed +1 -0
- imodent-1.0.0a1/imodent/registry.py +146 -0
- imodent-1.0.0a1/imodent/strategies/__init__.py +12 -0
- imodent-1.0.0a1/imodent/strategies/json.py +124 -0
- imodent-1.0.0a1/imodent/strategies/jsonl.py +86 -0
- imodent-1.0.0a1/imodent/strategies/python.py +357 -0
- imodent-1.0.0a1/imodent/strategies/yaml.py +189 -0
- imodent-1.0.0a1/imodent.egg-info/PKG-INFO +251 -0
- imodent-1.0.0a1/imodent.egg-info/SOURCES.txt +47 -0
- imodent-1.0.0a1/imodent.egg-info/dependency_links.txt +1 -0
- imodent-1.0.0a1/imodent.egg-info/entry_points.txt +2 -0
- imodent-1.0.0a1/imodent.egg-info/requires.txt +16 -0
- imodent-1.0.0a1/imodent.egg-info/top_level.txt +1 -0
- imodent-1.0.0a1/pyproject.toml +105 -0
- imodent-1.0.0a1/setup.cfg +4 -0
imodent-1.0.0a1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 imodent contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md
|
|
3
|
+
include pyproject.toml
|
|
4
|
+
|
|
5
|
+
recursive-exclude tests *
|
|
6
|
+
recursive-exclude build *
|
|
7
|
+
recursive-exclude .annotations *
|
|
8
|
+
recursive-exclude .codegraph *
|
|
9
|
+
recursive-exclude .ix *
|
|
10
|
+
recursive-exclude design *
|
|
11
|
+
recursive-exclude docs *
|
|
12
|
+
recursive-exclude .antigravitycli *
|
|
13
|
+
|
|
14
|
+
exclude nexus.zip
|
|
15
|
+
exclude ses.txt
|
|
16
|
+
exclude prompt.md
|
|
17
|
+
exclude pr-pub-ses.md
|
|
18
|
+
exclude .coverage
|
|
19
|
+
exclude AGENTS.md
|
|
20
|
+
exclude AUDIT_REPORT.md
|
|
21
|
+
exclude CBP_V2_AUDIT_REPORT.md
|
|
22
|
+
exclude CHAIN_BUG_REPORT.md
|
|
23
|
+
exclude CLI_AUDIT_REPORT.md
|
|
24
|
+
exclude COMPLETE_FINDINGS.md
|
|
25
|
+
exclude COMPOUNDED_BUG_PROTOCOL.md
|
|
26
|
+
exclude COMPOUNDED_BUG_PROTOCOL_v2.md
|
|
27
|
+
exclude COMPOUNDED_BUG_PROTOCOL_v2_RUN.md
|
|
28
|
+
exclude HIVEMIND_CBP_v2.md
|
|
29
|
+
exclude IMODENT_DECISION_ARCHITECTURE_PLAN.md
|
|
30
|
+
exclude IMPLEMENTATION_HANDOFF_PROMPT.md
|
|
31
|
+
exclude IMPLEMENTATION_REPORT.md
|
|
32
|
+
exclude IMPLEMENTATION_REPORT_PASS_2.md
|
|
33
|
+
exclude NEXT_DELEGATION_PROMPT.md
|
|
34
|
+
exclude PREPUBLISH_AUDIT_FINAL.md
|
|
35
|
+
exclude PREPUBLISH_AUDIT_REPORT.md
|
|
36
|
+
exclude ROOT_CAUSE_ANALYSIS.md
|
imodent-1.0.0a1/PKG-INFO
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: imodent
|
|
3
|
+
Version: 1.0.0a1
|
|
4
|
+
Summary: Code intelligence tool — fix, scan, and advise on Python, JSON, YAML, and Rust (advisory)
|
|
5
|
+
Author: imodent contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: code-quality,formatter,linter,python,json,yaml,ast,import-analysis,architecture,rust,cargo,clippy
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
19
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
20
|
+
Classifier: Topic :: Utilities
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: black>=23.0
|
|
25
|
+
Requires-Dist: ruamel.yaml>=0.18
|
|
26
|
+
Requires-Dist: pyyaml>=6.0
|
|
27
|
+
Requires-Dist: json-repair>=0.20
|
|
28
|
+
Requires-Dist: ruff>=0.1.0
|
|
29
|
+
Requires-Dist: tomli>=2.0; python_version < "3.11"
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: coverage>=7.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pre-commit>=4.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov>=6.0; extra == "dev"
|
|
36
|
+
Requires-Dist: ruff>=0.8; extra == "dev"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# imodent
|
|
40
|
+
|
|
41
|
+
Code intelligence tool — fix, scan, and advise on Python, JSON, JSONL, and YAML files.
|
|
42
|
+
|
|
43
|
+
imodent is a fast first-look mapper and conservative fixer. It is useful for
|
|
44
|
+
finding syntax blockers, import hygiene issues, lint-backed risks, and areas
|
|
45
|
+
that need review. It does not replace deeper codegraph or model-assisted code
|
|
46
|
+
understanding.
|
|
47
|
+
|
|
48
|
+
## Features
|
|
49
|
+
|
|
50
|
+
- **Auto-detection**: Detects Python, JSON, JSONL, YAML automatically
|
|
51
|
+
- **AST-based fixing**: Python code fixed with Black, validated with `ast.parse()`
|
|
52
|
+
- **Import analysis**: Detect unused, duplicate, and misused imports — with 5 fix options (delete, keep, investigate, false-positive, keep-typing)
|
|
53
|
+
- **Ruff-backed lint evidence**: Attach external lint diagnostics to scan findings
|
|
54
|
+
- **Confidence output**: Show decision candidates with evidence, confidence, and destructive-action policy
|
|
55
|
+
- **Architecture advisor**: Circular dependency detection, import clustering warnings
|
|
56
|
+
- **Pre-flight checks**: Refuses to "fix" structurally broken code (use `--force` to override)
|
|
57
|
+
- **Extensible**: Add new languages via `@StrategyRegistry.register` — no core changes needed
|
|
58
|
+
- **CLI**: Two modes — FIX (default) and SCAN (`--analyze`)
|
|
59
|
+
|
|
60
|
+
## Install
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install -e .
|
|
64
|
+
# or system-wide:
|
|
65
|
+
pipx install .
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
### FIX mode — reformat & repair files
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Fix a file with backup
|
|
74
|
+
imodent myfile.py --backup
|
|
75
|
+
|
|
76
|
+
# Preview changes without writing
|
|
77
|
+
imodent myfile.py --dry-run
|
|
78
|
+
|
|
79
|
+
# Syntax check only
|
|
80
|
+
imodent myfile.py --check
|
|
81
|
+
|
|
82
|
+
# Recursive directory scan
|
|
83
|
+
imodent ./src --recursive --indent 2 --backup
|
|
84
|
+
|
|
85
|
+
# Fix structurally broken code (skips pre-flight check)
|
|
86
|
+
imodent broken.py --force
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### SCAN mode — project-wide analysis
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Find unused & duplicate imports
|
|
93
|
+
imodent ./src --analyze --imports
|
|
94
|
+
|
|
95
|
+
# Review without modifying files
|
|
96
|
+
imodent ./src --report
|
|
97
|
+
|
|
98
|
+
# Add Ruff-backed lint evidence
|
|
99
|
+
imodent ./src --analyze --imports --lint --report
|
|
100
|
+
|
|
101
|
+
# Show confidence-weighted decision candidates
|
|
102
|
+
imodent ./src --analyze --imports --lint --confidence --report
|
|
103
|
+
|
|
104
|
+
# Flag architectural issues
|
|
105
|
+
imodent ./src --analyze --advisory
|
|
106
|
+
|
|
107
|
+
# Auto-fix safe findings (analysis implied)
|
|
108
|
+
imodent ./src --fix
|
|
109
|
+
|
|
110
|
+
# Auto-fix safe findings with explicit import analysis
|
|
111
|
+
imodent ./src --analyze --imports --fix
|
|
112
|
+
|
|
113
|
+
# Full audit + fix
|
|
114
|
+
imodent ./src --analyze --imports --advisory --fix
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
SCAN mode always recurses into subdirectories. `--report`, `--confidence`,
|
|
118
|
+
`--imports`, `--lint`, `--advisory`, `--interactive`, and `--fix` all route to
|
|
119
|
+
SCAN mode. `-b`, `-n`, and `-c` also work with scan fixes. `-r` and `--force`
|
|
120
|
+
are FIX-mode controls; when used with scan flags, imodent prints a note.
|
|
121
|
+
|
|
122
|
+
### Import analysis options
|
|
123
|
+
|
|
124
|
+
When `--imports` finds an unused import, interactive mode can offer review
|
|
125
|
+
choices such as:
|
|
126
|
+
|
|
127
|
+
| Option | When to use |
|
|
128
|
+
|--------|-------------|
|
|
129
|
+
| **delete** | Import is genuinely unused |
|
|
130
|
+
| **keep** | Type hints, re-exports, `__all__` entries |
|
|
131
|
+
| **keep-typing** | Import is kept specifically for type annotations |
|
|
132
|
+
| **investigate** | Search codebase before deciding |
|
|
133
|
+
| **false-positive** | Analysis missed a usage (dynamic import, string reference) |
|
|
134
|
+
|
|
135
|
+
Non-interactive `--fix` only applies findings marked safe by the fixer. Most
|
|
136
|
+
unused-import candidates remain review-only unless the tool has enough evidence
|
|
137
|
+
to avoid deleting intent.
|
|
138
|
+
|
|
139
|
+
## Python API
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from imodent import FixPipeline
|
|
143
|
+
|
|
144
|
+
pipeline = FixPipeline(indent_size=4)
|
|
145
|
+
|
|
146
|
+
# Fix content (auto-detects language)
|
|
147
|
+
result = pipeline.fix(messy_code)
|
|
148
|
+
if result.success:
|
|
149
|
+
print(result.content)
|
|
150
|
+
else:
|
|
151
|
+
for error in result.errors:
|
|
152
|
+
print(f"Error: {error}")
|
|
153
|
+
|
|
154
|
+
# Force fix on structurally broken code
|
|
155
|
+
result = pipeline.fix(broken_code, force=True)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Analysis API
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from pathlib import Path
|
|
162
|
+
|
|
163
|
+
from imodent import AnalysisCoordinator
|
|
164
|
+
|
|
165
|
+
coordinator = AnalysisCoordinator()
|
|
166
|
+
result = coordinator.analyze([Path("src/")])
|
|
167
|
+
|
|
168
|
+
for finding in result.findings:
|
|
169
|
+
print(f"{finding.severity.value}: {finding.message}")
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Add a New Language
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from imodent.interfaces import LanguageStrategy, FixResult
|
|
176
|
+
from imodent.registry import StrategyRegistry
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
@StrategyRegistry.register
|
|
180
|
+
class TOMLStrategy(LanguageStrategy):
|
|
181
|
+
@property
|
|
182
|
+
def name(self) -> str:
|
|
183
|
+
return "toml"
|
|
184
|
+
|
|
185
|
+
@property
|
|
186
|
+
def extensions(self) -> list[str]:
|
|
187
|
+
return [".toml"]
|
|
188
|
+
|
|
189
|
+
def detect(self, content: str) -> bool:
|
|
190
|
+
return "[[" in content or "=" in content
|
|
191
|
+
|
|
192
|
+
def fix(self, content: str, indent_size: int = 4, force: bool = False) -> FixResult:
|
|
193
|
+
# Your fixing logic
|
|
194
|
+
return FixResult(
|
|
195
|
+
success=True,
|
|
196
|
+
content=content,
|
|
197
|
+
errors=[],
|
|
198
|
+
warnings=[],
|
|
199
|
+
original_valid=True,
|
|
200
|
+
fixed_valid=True,
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
def validate(self, content: str) -> tuple[bool, str | None]:
|
|
204
|
+
return True, None
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
No core changes needed — the strategy auto-registers and the pipeline picks it up.
|
|
208
|
+
|
|
209
|
+
## CLI Reference
|
|
210
|
+
|
|
211
|
+
| Flag | Mode | Description | Default |
|
|
212
|
+
|------|------|-------------|---------|
|
|
213
|
+
| `-i N` | FIX | Indent size (spaces) | `4` |
|
|
214
|
+
| `-b` | FIX | Create `.bak` backup | off |
|
|
215
|
+
| `-n` | FIX | Dry run (preview only) | off |
|
|
216
|
+
| `-c` | FIX | Check only (no fix) | off |
|
|
217
|
+
| `-r` | FIX | Recursive directory scan | off |
|
|
218
|
+
| `--force` | FIX | Attempt fix on structurally broken code | off |
|
|
219
|
+
| `--analyze` | SCAN | Enable project-wide analysis | off |
|
|
220
|
+
| `--imports` | SCAN | Detect import issues | off |
|
|
221
|
+
| `--lint` | SCAN | Run lint checks | off |
|
|
222
|
+
| `--advisory` | SCAN | Flag architectural issues | off |
|
|
223
|
+
| `--fix` | SCAN | Auto-fix safe findings | off |
|
|
224
|
+
| `--interactive` | SCAN | Prompt before each fix | off |
|
|
225
|
+
| `--report` | SCAN | Review findings without modifying files | off |
|
|
226
|
+
| `--confidence` | SCAN | Show evidence-backed decision candidates | off |
|
|
227
|
+
| `-v` | SCAN | Show all findings | off |
|
|
228
|
+
|
|
229
|
+
`-b`, `-n`, and `-c` are shared controls when scan fixes are enabled. `--check`
|
|
230
|
+
prevents `--fix` from applying changes and prints a note explaining the conflict.
|
|
231
|
+
|
|
232
|
+
## Supported Formats
|
|
233
|
+
|
|
234
|
+
| Format | Detection | Fixing | Validation |
|
|
235
|
+
|--------|-----------|--------|------------|
|
|
236
|
+
| **Python** | Keywords + AST parse | Black → AST heuristic | `ast.parse()` |
|
|
237
|
+
| **JSON** | `{`/`[` + `json.loads()` | Pretty-print with indent | `json.loads()` |
|
|
238
|
+
| **JSONL** | Each line valid JSON | Compact each line | `json.loads()` per line |
|
|
239
|
+
| **YAML** | `---` or key patterns + `yaml.safe_load()` | Pretty-print with proper list indent | `yaml.safe_load()` |
|
|
240
|
+
|
|
241
|
+
## Known Limitations
|
|
242
|
+
|
|
243
|
+
- Confidence is rule-based, not proof of developer intent.
|
|
244
|
+
- Fragmented workspaces with multiple import roots can produce ambiguous import findings.
|
|
245
|
+
- Type-only or quoted annotation issues may need human review even when Ruff reports them as `F821`.
|
|
246
|
+
- Default scan discovery skips common generated artifacts and test files; run targeted paths when you want to inspect those.
|
|
247
|
+
- Use codegraph or manual review for deep impact analysis. imodent is the fast mapper and conservative hygiene layer.
|
|
248
|
+
|
|
249
|
+
## License
|
|
250
|
+
|
|
251
|
+
MIT
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# imodent
|
|
2
|
+
|
|
3
|
+
Code intelligence tool — fix, scan, and advise on Python, JSON, JSONL, and YAML files.
|
|
4
|
+
|
|
5
|
+
imodent is a fast first-look mapper and conservative fixer. It is useful for
|
|
6
|
+
finding syntax blockers, import hygiene issues, lint-backed risks, and areas
|
|
7
|
+
that need review. It does not replace deeper codegraph or model-assisted code
|
|
8
|
+
understanding.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Auto-detection**: Detects Python, JSON, JSONL, YAML automatically
|
|
13
|
+
- **AST-based fixing**: Python code fixed with Black, validated with `ast.parse()`
|
|
14
|
+
- **Import analysis**: Detect unused, duplicate, and misused imports — with 5 fix options (delete, keep, investigate, false-positive, keep-typing)
|
|
15
|
+
- **Ruff-backed lint evidence**: Attach external lint diagnostics to scan findings
|
|
16
|
+
- **Confidence output**: Show decision candidates with evidence, confidence, and destructive-action policy
|
|
17
|
+
- **Architecture advisor**: Circular dependency detection, import clustering warnings
|
|
18
|
+
- **Pre-flight checks**: Refuses to "fix" structurally broken code (use `--force` to override)
|
|
19
|
+
- **Extensible**: Add new languages via `@StrategyRegistry.register` — no core changes needed
|
|
20
|
+
- **CLI**: Two modes — FIX (default) and SCAN (`--analyze`)
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install -e .
|
|
26
|
+
# or system-wide:
|
|
27
|
+
pipx install .
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### FIX mode — reformat & repair files
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Fix a file with backup
|
|
36
|
+
imodent myfile.py --backup
|
|
37
|
+
|
|
38
|
+
# Preview changes without writing
|
|
39
|
+
imodent myfile.py --dry-run
|
|
40
|
+
|
|
41
|
+
# Syntax check only
|
|
42
|
+
imodent myfile.py --check
|
|
43
|
+
|
|
44
|
+
# Recursive directory scan
|
|
45
|
+
imodent ./src --recursive --indent 2 --backup
|
|
46
|
+
|
|
47
|
+
# Fix structurally broken code (skips pre-flight check)
|
|
48
|
+
imodent broken.py --force
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### SCAN mode — project-wide analysis
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Find unused & duplicate imports
|
|
55
|
+
imodent ./src --analyze --imports
|
|
56
|
+
|
|
57
|
+
# Review without modifying files
|
|
58
|
+
imodent ./src --report
|
|
59
|
+
|
|
60
|
+
# Add Ruff-backed lint evidence
|
|
61
|
+
imodent ./src --analyze --imports --lint --report
|
|
62
|
+
|
|
63
|
+
# Show confidence-weighted decision candidates
|
|
64
|
+
imodent ./src --analyze --imports --lint --confidence --report
|
|
65
|
+
|
|
66
|
+
# Flag architectural issues
|
|
67
|
+
imodent ./src --analyze --advisory
|
|
68
|
+
|
|
69
|
+
# Auto-fix safe findings (analysis implied)
|
|
70
|
+
imodent ./src --fix
|
|
71
|
+
|
|
72
|
+
# Auto-fix safe findings with explicit import analysis
|
|
73
|
+
imodent ./src --analyze --imports --fix
|
|
74
|
+
|
|
75
|
+
# Full audit + fix
|
|
76
|
+
imodent ./src --analyze --imports --advisory --fix
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
SCAN mode always recurses into subdirectories. `--report`, `--confidence`,
|
|
80
|
+
`--imports`, `--lint`, `--advisory`, `--interactive`, and `--fix` all route to
|
|
81
|
+
SCAN mode. `-b`, `-n`, and `-c` also work with scan fixes. `-r` and `--force`
|
|
82
|
+
are FIX-mode controls; when used with scan flags, imodent prints a note.
|
|
83
|
+
|
|
84
|
+
### Import analysis options
|
|
85
|
+
|
|
86
|
+
When `--imports` finds an unused import, interactive mode can offer review
|
|
87
|
+
choices such as:
|
|
88
|
+
|
|
89
|
+
| Option | When to use |
|
|
90
|
+
|--------|-------------|
|
|
91
|
+
| **delete** | Import is genuinely unused |
|
|
92
|
+
| **keep** | Type hints, re-exports, `__all__` entries |
|
|
93
|
+
| **keep-typing** | Import is kept specifically for type annotations |
|
|
94
|
+
| **investigate** | Search codebase before deciding |
|
|
95
|
+
| **false-positive** | Analysis missed a usage (dynamic import, string reference) |
|
|
96
|
+
|
|
97
|
+
Non-interactive `--fix` only applies findings marked safe by the fixer. Most
|
|
98
|
+
unused-import candidates remain review-only unless the tool has enough evidence
|
|
99
|
+
to avoid deleting intent.
|
|
100
|
+
|
|
101
|
+
## Python API
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from imodent import FixPipeline
|
|
105
|
+
|
|
106
|
+
pipeline = FixPipeline(indent_size=4)
|
|
107
|
+
|
|
108
|
+
# Fix content (auto-detects language)
|
|
109
|
+
result = pipeline.fix(messy_code)
|
|
110
|
+
if result.success:
|
|
111
|
+
print(result.content)
|
|
112
|
+
else:
|
|
113
|
+
for error in result.errors:
|
|
114
|
+
print(f"Error: {error}")
|
|
115
|
+
|
|
116
|
+
# Force fix on structurally broken code
|
|
117
|
+
result = pipeline.fix(broken_code, force=True)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Analysis API
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from pathlib import Path
|
|
124
|
+
|
|
125
|
+
from imodent import AnalysisCoordinator
|
|
126
|
+
|
|
127
|
+
coordinator = AnalysisCoordinator()
|
|
128
|
+
result = coordinator.analyze([Path("src/")])
|
|
129
|
+
|
|
130
|
+
for finding in result.findings:
|
|
131
|
+
print(f"{finding.severity.value}: {finding.message}")
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Add a New Language
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from imodent.interfaces import LanguageStrategy, FixResult
|
|
138
|
+
from imodent.registry import StrategyRegistry
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@StrategyRegistry.register
|
|
142
|
+
class TOMLStrategy(LanguageStrategy):
|
|
143
|
+
@property
|
|
144
|
+
def name(self) -> str:
|
|
145
|
+
return "toml"
|
|
146
|
+
|
|
147
|
+
@property
|
|
148
|
+
def extensions(self) -> list[str]:
|
|
149
|
+
return [".toml"]
|
|
150
|
+
|
|
151
|
+
def detect(self, content: str) -> bool:
|
|
152
|
+
return "[[" in content or "=" in content
|
|
153
|
+
|
|
154
|
+
def fix(self, content: str, indent_size: int = 4, force: bool = False) -> FixResult:
|
|
155
|
+
# Your fixing logic
|
|
156
|
+
return FixResult(
|
|
157
|
+
success=True,
|
|
158
|
+
content=content,
|
|
159
|
+
errors=[],
|
|
160
|
+
warnings=[],
|
|
161
|
+
original_valid=True,
|
|
162
|
+
fixed_valid=True,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
def validate(self, content: str) -> tuple[bool, str | None]:
|
|
166
|
+
return True, None
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
No core changes needed — the strategy auto-registers and the pipeline picks it up.
|
|
170
|
+
|
|
171
|
+
## CLI Reference
|
|
172
|
+
|
|
173
|
+
| Flag | Mode | Description | Default |
|
|
174
|
+
|------|------|-------------|---------|
|
|
175
|
+
| `-i N` | FIX | Indent size (spaces) | `4` |
|
|
176
|
+
| `-b` | FIX | Create `.bak` backup | off |
|
|
177
|
+
| `-n` | FIX | Dry run (preview only) | off |
|
|
178
|
+
| `-c` | FIX | Check only (no fix) | off |
|
|
179
|
+
| `-r` | FIX | Recursive directory scan | off |
|
|
180
|
+
| `--force` | FIX | Attempt fix on structurally broken code | off |
|
|
181
|
+
| `--analyze` | SCAN | Enable project-wide analysis | off |
|
|
182
|
+
| `--imports` | SCAN | Detect import issues | off |
|
|
183
|
+
| `--lint` | SCAN | Run lint checks | off |
|
|
184
|
+
| `--advisory` | SCAN | Flag architectural issues | off |
|
|
185
|
+
| `--fix` | SCAN | Auto-fix safe findings | off |
|
|
186
|
+
| `--interactive` | SCAN | Prompt before each fix | off |
|
|
187
|
+
| `--report` | SCAN | Review findings without modifying files | off |
|
|
188
|
+
| `--confidence` | SCAN | Show evidence-backed decision candidates | off |
|
|
189
|
+
| `-v` | SCAN | Show all findings | off |
|
|
190
|
+
|
|
191
|
+
`-b`, `-n`, and `-c` are shared controls when scan fixes are enabled. `--check`
|
|
192
|
+
prevents `--fix` from applying changes and prints a note explaining the conflict.
|
|
193
|
+
|
|
194
|
+
## Supported Formats
|
|
195
|
+
|
|
196
|
+
| Format | Detection | Fixing | Validation |
|
|
197
|
+
|--------|-----------|--------|------------|
|
|
198
|
+
| **Python** | Keywords + AST parse | Black → AST heuristic | `ast.parse()` |
|
|
199
|
+
| **JSON** | `{`/`[` + `json.loads()` | Pretty-print with indent | `json.loads()` |
|
|
200
|
+
| **JSONL** | Each line valid JSON | Compact each line | `json.loads()` per line |
|
|
201
|
+
| **YAML** | `---` or key patterns + `yaml.safe_load()` | Pretty-print with proper list indent | `yaml.safe_load()` |
|
|
202
|
+
|
|
203
|
+
## Known Limitations
|
|
204
|
+
|
|
205
|
+
- Confidence is rule-based, not proof of developer intent.
|
|
206
|
+
- Fragmented workspaces with multiple import roots can produce ambiguous import findings.
|
|
207
|
+
- Type-only or quoted annotation issues may need human review even when Ruff reports them as `F821`.
|
|
208
|
+
- Default scan discovery skips common generated artifacts and test files; run targeted paths when you want to inspect those.
|
|
209
|
+
- Use codegraph or manual review for deep impact analysis. imodent is the fast mapper and conservative hygiene layer.
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
MIT
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Code intelligence tool — fix, scan, and advise on Python, JSON, YAML, and Rust.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .interfaces import LanguageStrategy, Processor, FixResult
|
|
6
|
+
from .registry import StrategyRegistry, ProcessorRegistry
|
|
7
|
+
from .pipeline import FixPipeline
|
|
8
|
+
|
|
9
|
+
# Analysis components
|
|
10
|
+
from .analysis import (
|
|
11
|
+
AnalysisContext,
|
|
12
|
+
AnalysisConfig,
|
|
13
|
+
FileInfo,
|
|
14
|
+
DependencyGraph,
|
|
15
|
+
SymbolUsage,
|
|
16
|
+
Finding,
|
|
17
|
+
Severity,
|
|
18
|
+
Location,
|
|
19
|
+
FixOption,
|
|
20
|
+
Advice,
|
|
21
|
+
Change,
|
|
22
|
+
AnalysisCoordinator,
|
|
23
|
+
AnalysisResult,
|
|
24
|
+
FixMode,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
from importlib.metadata import version as _pkg_version, PackageNotFoundError
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
__version__ = _pkg_version("imodent")
|
|
31
|
+
except PackageNotFoundError:
|
|
32
|
+
__version__ = "0.0.0dev"
|
|
33
|
+
|
|
34
|
+
__all__ = [
|
|
35
|
+
# Core
|
|
36
|
+
"LanguageStrategy",
|
|
37
|
+
"Processor",
|
|
38
|
+
"FixResult",
|
|
39
|
+
"StrategyRegistry",
|
|
40
|
+
"ProcessorRegistry",
|
|
41
|
+
"FixPipeline",
|
|
42
|
+
# Analysis
|
|
43
|
+
"AnalysisContext",
|
|
44
|
+
"AnalysisConfig",
|
|
45
|
+
"FileInfo",
|
|
46
|
+
"DependencyGraph",
|
|
47
|
+
"SymbolUsage",
|
|
48
|
+
"Finding",
|
|
49
|
+
"Severity",
|
|
50
|
+
"Location",
|
|
51
|
+
"FixOption",
|
|
52
|
+
"Advice",
|
|
53
|
+
"Change",
|
|
54
|
+
"AnalysisCoordinator",
|
|
55
|
+
"AnalysisResult",
|
|
56
|
+
"FixMode",
|
|
57
|
+
# Version
|
|
58
|
+
"__version__",
|
|
59
|
+
]
|