Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 100
extend-ignore = E203, W503
9 changes: 6 additions & 3 deletions .github/workflows/auto-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ name: Auto-label Bot
on:
issues:
types: [opened, edited]
pull_request:
pull_request_target:
types: [opened, edited, synchronize]

# Default permissions for the workflow
permissions:
contents: read
issues: write
pull-requests: write
contents: read

jobs:
label-issues:
Expand All @@ -20,6 +21,7 @@ jobs:
- name: Auto-label issues
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo, number } = context.issue;
const issue = context.payload.issue;
Expand Down Expand Up @@ -116,7 +118,7 @@ jobs:
}

label-pull-requests:
if: github.event_name == 'pull_request'
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -127,6 +129,7 @@ jobs:
- name: Auto-label PRs
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo, number } = context.issue;
const pr = context.payload.pull_request;
Expand Down
1 change: 1 addition & 0 deletions coverage.json

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions debug_syntax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ast
import sys

files = [
r"c:\Users\Shruti kulkarni\Downloads\Refactron_lib\refactron\rag\parser.py",
r"c:\Users\Shruti kulkarni\Downloads\Refactron_lib\refactron\rag\indexer.py"
]

for f_path in files:
print(f"Checking {f_path}...")
try:
with open(f_path, "rb") as f:
content = f.read()
# Look for non-ascii or weird bytes
non_ascii = [(i, b) for i, b in enumerate(content) if b > 127]
if non_ascii:
print(f" Found {len(non_ascii)} non-ASCII bytes. First few: {non_ascii[:5]}")

ast.parse(content)
print(" AST parse: SUCCESS")

# Search for the string the user is seeing
if b"PY_LANGUAGE" in content:
print(" CRITICAL: Found 'PY_LANGUAGE' in file despite overwrite!")
else:
print(" 'PY_LANGUAGE' not found.")

except Exception as e:
print(f" ERROR: {e}")
import traceback
traceback.print_exc()
print("-" * 20)
12 changes: 6 additions & 6 deletions docs/advanced/ci-cd.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Install Refactron
run: pip install refactron

- name: Analyze Code
run: refactron analyze . --log-format json
```
Expand Down Expand Up @@ -131,7 +131,7 @@ repos:
refactron analyze . --log-format json
```
</Accordion>

<Accordion title="Configure Failure Thresholds">
Fail builds based on severity:
```yaml
Expand All @@ -142,7 +142,7 @@ repos:
max_error_issues: 10
```
</Accordion>

<Accordion title="Cache Dependencies">
Speed up CI runs by caching pip packages:
```yaml
Expand All @@ -153,7 +153,7 @@ repos:
key: ${{ runner.os }}-pip-refactron
```
</Accordion>

<Accordion title="Generate Reports">
Create HTML reports and save as artifacts:
```bash
Expand Down
8 changes: 4 additions & 4 deletions docs/advanced/monitoring.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: 'Production monitoring and telemetry'
Refactron includes comprehensive logging and monitoring capabilities for production environments:

- **Structured Logging** - JSON-formatted logs for CI/CD
- **Metrics Collection** - Track analysis time and success rates
- **Metrics Collection** - Track analysis time and success rates
- **Prometheus Integration** - Expose metrics via HTTP endpoint
- **Opt-in Telemetry** - Anonymous usage analytics

Expand Down Expand Up @@ -187,15 +187,15 @@ prometheus_port: 9090
<Step title="Use JSON Logging in CI/CD">
JSON format integrates easily with log aggregation systems
</Step>

<Step title="Enable Metrics in Production">
Track performance and identify bottlenecks
</Step>

<Step title="Set Up Prometheus Dashboards">
Visualize Refactron metrics over time
</Step>

<Step title="Keep Telemetry Optional">
Respect user privacy with opt-in telemetry
</Step>
Expand Down
10 changes: 5 additions & 5 deletions docs/advanced/performance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ Cache parsed Abstract Syntax Trees to avoid re-parsing.
- Reduces CPU usage
- Especially effective for large files
</Accordion>

<Accordion title="Configuration">
```python
from refactron import Refactron
from refactron.core.config import RefactronConfig

config = RefactronConfig(
enable_ast_cache=True,
max_ast_cache_size_mb=100
)
refactron = Refactron(config)
```
</Accordion>

<Accordion title="Cache Statistics">
```python
stats = refactron.get_performance_stats()
Expand Down Expand Up @@ -156,13 +156,13 @@ refactron.clear_caches()
print(f"Hit rate: {stats['ast_cache']['hit_rate']}%")
```
</Accordion>

<Accordion title="High Memory Usage">
- Reduce cache size: `max_ast_cache_size_mb: 50`
- Lower parallel workers: `max_parallel_workers: 2`
- Clear caches periodically: `refactron.clear_caches()`
</Accordion>

<Accordion title="Parallel Processing Slower">
Disable for small codebases:
```yaml
Expand Down
4 changes: 2 additions & 2 deletions docs/api-reference/refactron-class.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def refactor(

<ParamField path="operation_types" type="List[str]" default="None">
Specific refactoring types to apply. None = all types.

Available types:
- `extract_constant`
- `add_docstring`
Expand Down Expand Up @@ -316,7 +316,7 @@ for op in result.operations:
print(f" File: {op.file_path}:{op.line_number}")
print(f" Risk: {op.risk_score}")
print(f" Description: {op.description}")

# Record feedback
refactron.record_feedback(
operation_id=op.operation_id,
Expand Down
2 changes: 1 addition & 1 deletion docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@
"vscode"
]
}
}
}
10 changes: 5 additions & 5 deletions docs/essentials/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ Features that require authentication:
refactron repo connect my-repo
```
</Accordion>

<Accordion icon="sparkles" title="Cloud AI Features">
Enhanced AI-powered refactoring with cloud LLM models
</Accordion>

<Accordion icon="chart-simple" title="Usage Analytics">
```bash
refactron metrics
```
</Accordion>

<Accordion icon="share-nodes" title="Team Pattern Sharing">
Share learned patterns across your team
</Accordion>
Expand All @@ -120,15 +120,15 @@ Cloud features gracefully degrade when offline.
2. Paste it into your browser manually
3. Complete the authentication
</Accordion>

<Accordion title="Token expired">
If you see "Token expired" errors:
```bash
refactron auth logout
refactron login
```
</Accordion>

<Accordion title="API key not working">
Verify the API key is set correctly:
```bash
Expand Down
16 changes: 8 additions & 8 deletions docs/essentials/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ pattern_storage_dir: null # null = auto-detect
<Accordion icon="shield" title="security">
Detects security vulnerabilities like SQL injection, code injection, hardcoded secrets, and SSRF
</Accordion>

<Accordion icon="code" title="code_smell">
Identifies magic numbers, long functions, excessive parameters, and deep nesting
</Accordion>

<Accordion icon="chart-line" title="complexity">
Measures cyclomatic complexity, maintainability index, and nested loops
</Accordion>

<Accordion icon="file-code" title="type_hint">
Checks for missing or incomplete type annotations
</Accordion>

<Accordion icon="trash" title="dead_code">
Finds unused functions and unreachable code
</Accordion>

<Accordion icon="link" title="dependency">
Analyzes circular imports and wildcard imports
</Accordion>
Expand All @@ -95,15 +95,15 @@ pattern_storage_dir: null # null = auto-detect
<Accordion title="extract_constant">
Extract magic numbers into named constants
</Accordion>

<Accordion title="add_docstring">
Add missing docstrings to functions and classes
</Accordion>

<Accordion title="simplify_conditionals">
Simplify complex conditional statements
</Accordion>

<Accordion title="reduce_parameters">
Reduce function parameter count using dataclasses or dictionaries
</Accordion>
Expand Down
8 changes: 4 additions & 4 deletions docs/essentials/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: 'How to install and set up Refactron'
## Requirements

<Info>
**Python Version**: 3.8 or higher
**Python Version**: 3.8 or higher
**Supported Platforms**: macOS, Linux, Windows
</Info>

Expand Down Expand Up @@ -71,7 +71,7 @@ Refactron automatically installs these dependencies:
- **radon** - Complexity metrics
- **astroid** - AST analysis
</Accordion>

<Accordion title="AI & RAG Dependencies">
- **chromadb** - Vector database for RAG
- **tree-sitter** - Code parsing
Expand All @@ -90,7 +90,7 @@ Refactron automatically installs these dependencies:
pip install --user refactron
```
</Accordion>

<Accordion title="Python Version Issues">
Ensure you're using Python 3.8+:
```bash
Expand All @@ -101,7 +101,7 @@ Refactron automatically installs these dependencies:
python3.10 -m pip install refactron
```
</Accordion>

<Accordion title="SSL Certificate Errors">
On macOS, you may need to install certificates:
```bash
Expand Down
Loading