{"id":50472330,"url":"https://github.com/semcod/prefact","last_synced_at":"2026-06-01T11:03:10.377Z","repository":{"id":347250358,"uuid":"1193325166","full_name":"semcod/prefact","owner":"semcod","description":null,"archived":false,"fork":false,"pushed_at":"2026-05-13T16:49:19.000Z","size":65483,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-13T18:31:26.190Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/semcod.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-27T05:19:45.000Z","updated_at":"2026-05-13T16:49:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/semcod/prefact","commit_stats":null,"previous_names":["semcod/refactoring"],"tags_count":61,"template":false,"template_full_name":null,"purl":"pkg:github/semcod/prefact","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fprefact","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fprefact/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fprefact/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fprefact/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/semcod","download_url":"https://codeload.github.com/semcod/prefact/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fprefact/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33771630,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-01T02:00:06.963Z","response_time":115,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-01T11:03:09.058Z","updated_at":"2026-06-01T11:03:10.364Z","avatar_url":"https://github.com/semcod.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# prefact\n\n[![PyPI version](https://badge.fury.io/py/prefact.svg)](https://badge.fury.io/py/prefact)\n[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)\n[![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n\n## AI Cost Tracking\n\n![PyPI](https://img.shields.io/badge/pypi-costs-blue) ![Version](https://img.shields.io/badge/version-0.1.58-blue) ![Python](https://img.shields.io/badge/python-3.9+-blue) ![License](https://img.shields.io/badge/license-Apache--2.0-green)\n![AI Cost](https://img.shields.io/badge/AI%20Cost-$16.10-orange) ![Human Time](https://img.shields.io/badge/Human%20Time-24.3h-blue) ![Model](https://img.shields.io/badge/Model-openrouter%2Fqwen%2Fqwen3--coder--next-lightgrey)\n\n- 🤖 **LLM usage:** $16.1026 (63 commits)\n- 👤 **Human dev:** ~$2434 (24.3h @ $100/h, 30min dedup)\n\nGenerated on 2026-05-24 using [openrouter/qwen/qwen3-coder-next](https://openrouter.ai/qwen/qwen3-coder-next)\n\n---\n\nAutomatic Python prefactoring toolkit — detect, fix, and validate common code issues introduced by LLMs and humans alike.\n\n## The Problem\n\n![img.png](img.png)\n\nWhen using LLMs for code generation, they often silently change import paths from absolute to deep relative:\n\n```python\n# ❌ LLM introduces this\nfrom ....llm.generator import generate_strategy\nfrom ....loaders.yaml_loader import save_strategy_yaml\n\n# ✅ You wanted this\nfrom planfile.llm.generator import generate_strategy\nfrom planfile.loaders.yaml_loader import save_strategy_yaml\n```\n\n**prefact** automatically **detects**, **fixes**, and **validates** such issues in a three-phase pipeline.\n\n## Features\n\n| Rule | ID | Auto-fix | Description |\n|---|---|---|---|\n| Relative → Absolute imports | `relative-imports` | ✅ | Converts `from ....x import y` to `from pkg.x import y` |\n| Unused imports | `unused-imports` | ✅ | Removes imports never referenced in the module |\n| Duplicate imports | `duplicate-imports` | ✅ | Removes the same name imported twice |\n| Wildcard imports | `wildcard-imports` | 🔍 | Flags `from x import *` |\n| Unsorted imports | `sorted-imports` | 🔍 | Flags import blocks not ordered stdlib→3rd-party→local |\n| String concatenation | `string-concat` | 🔍 | Flags `\"Hello \" + name` → suggests f-strings |\n| Missing return types | `missing-return-type` | 🔍 | Flags public functions without return type hints |\n\n✅ = auto-fix  ·  🔍 = scan-only (report)\n\n## Performance Improvements\n\n- **Parallel Processing**: Scans files in parallel when enabled\n- **Smart Filtering**: Automatically skips large files (\u003e100KB) and empty files\n- **Optimized Scanning**: Excludes test directories and examples by default\n- **Deduplication**: Prevents duplicate tickets and TODO entries\n\n## Examples\n\nThe `examples/` directory contains comprehensive examples for different use cases:\n\n| Example | Description |\n|---|---|\n| [sample-project](examples/sample-project/) | Realistic project with all issues demonstrated |\n| [01-individual-rules](examples/01-individual-rules/) | Each rule explained with before/after code |\n| [02-multiple-rules](examples/02-multiple-rules/) | Combining multiple rules for comprehensive cleanup |\n| [03-output-formats](examples/03-output-formats/) | Console vs JSON output examples |\n| [04-custom-rules](examples/04-custom-rules/) | Writing your own prefactoring rules |\n| [05-ci-cd](examples/05-ci-cd/) | GitHub Actions, GitLab CI, Azure DevOps configs |\n| [06-api-usage](examples/06-api-usage/) | Using prefact programmatically from Python |\n\n### Quick Example\n\n```bash\n# Try the sample project\ncd examples/sample-project\nprefact scan --path . --config prefact.yaml\nprefact fix --path . --config prefact.yaml\n```\n\nSee [examples/README.md](examples/README.md) for a detailed guide to all examples.\n\n## Installation\n\n```bash\npip install -e .\n\n# with dev dependencies (pytest)\npip install -e \".[dev]\"\n```\n\n## Quick Start\n\n```bash\n# Generate config file\nprefact init\n\n# List all available rules\nprefact rules\n\n# Scan only (no changes)\nprefact scan --path ./my_project --package mypackage\n\n# Fix + validate (with backups)\nprefact fix --path ./my_project --package mypackage\n\n# Dry-run (show what would change)\nprefact fix --path ./my_project --package mypackage --dry-run\n\n# Check a single file\nprefact check ./my_project/src/mypackage/core/service.py --package mypackage\n\n# JSON output for CI\nprefact fix --path . --format json -o report.json\n```\n\n📚 **Want to see prefact in action?** Check out our [comprehensive examples](examples/) with real-world scenarios!\n\n## Pipeline Architecture\n\n```\n┌─────────┐      ┌─────────┐      ┌────────────┐\n│  SCAN   │ ──→  │   FIX   │ ──→  │  VALIDATE  │\n│         │      │         │      │            │\n│ Detect  │      │ Apply   │      │ Syntax OK? │\n│ issues  │      │ fixes   │      │ Regressions│\n│ per rule│      │ + backup│      │ preserved? │\n└─────────┘      └─────────┘      └────────────┘\n```\n\n1. **Scan** — each rule walks the AST / CST and emits `Issue` objects\n2. **Fix** — rules with auto-fix transform the source (via `libcst` for formatting-safe changes)\n3. **Validate** — post-fix checks: syntax valid, no regressions, import counts preserved\n\n## Configuration\n\nCreate `prefact.yaml` (auto-generated via `prefact init`):\n\n```yaml\npackage_name: planfile\n\ninclude:\n  - \"**/*.py\"\n\nexclude:\n  - \"**/venv/**\"\n  - \"**/build/**\"\n  - \"**/tests/**\"\n  - \"**/test*/**\"\n  - \"**/examples/**\"\n\ntools:\n  parallel: true\n  cache: true\n  performance:\n    max_workers: 4\n\nrules:\n  relative-imports:\n    enabled: true\n    severity: warning\n  unused-imports:\n    enabled: true\n    severity: info\n  duplicate-imports:\n    enabled: true\n  wildcard-imports:\n    enabled: true\n    severity: error\n  sorted-imports:\n    enabled: false\n  string-concat:\n    enabled: true\n  missing-return-type:\n    enabled: false\n```\n\n## Autonomous Mode\n\nPrefact includes an autonomous mode that automatically:\n- Scans your project for issues\n- Generates TODO.md with all found issues\n- Creates tickets in planfile.yaml for tracking\n- Updates CHANGELOG.md with fixes\n- Optionally runs TestQL scenarios and bridges failures into tickets\n\n```bash\n# Run full autonomous workflow\nprefact -a\n\n# Or skip tests/examples for faster runs\nprefact -a --skip-tests --skip-examples\n\n# Include TestQL validation as the final step\nprefact -a --with-testql\n\n# Use a custom directory for *.testql.toon.yaml scenarios\nprefact -a --with-testql --testql-dir ./testql-scenarios\n```\n\n## TestQL Integration\n\nPrefact can run TestQL DSL validation scenarios and bridge failing checks directly into planfile tickets, TODO.md, and configured backends (GitHub, GitLab, Jira).\n\n### `prefact testql` — Run a Single Scenario\n\n```bash\n# Validate a scenario and create/sync tickets\nprefact testql testql-scenarios/smoke.testql.toon.yaml\n\n# Dry-run: validate without creating tickets\nprefact testql testql-scenarios/smoke.testql.toon.yaml --dry-run\n\n# Custom project root and strategy\nprefact testql scenarios/api.testql.toon.yaml -p ./my-api -s my-api/planfile.yaml\n\n# Limit ticket generation and disable sync\nprefact testql scenarios/api.testql.toon.yaml --max-tickets 10 --no-sync\n```\n\n### Options\n\n| Option | Default | Description |\n|--------|---------|-------------|\n| `-p`, `--path` | `.` | Project root directory |\n| `--url` | `http://localhost:8101` | TestQL service base URL |\n| `--dry-run` | `False` | Parse/validate only |\n| `-s`, `--strategy` | `\u003cproject\u003e/planfile.yaml` | Target planfile YAML |\n| `--create-tickets` / `--no-create-tickets` | `True` | Create tickets for failures |\n| `--sync` / `--no-sync` | `True` | Sync to TODO.md and integrations |\n| `--max-tickets` | `25` | Max tickets per run |\n| `--testql-bin` | `testql` | TestQL CLI executable |\n| `--testql-repo-path` | `/home/tom/github/oqlos/testql` | Fallback local repo path |\n\n### Identity-Aware Deduplication\n\nWhen creating tickets, prefact uses identity-aware deduplication based on:\n- Ticket `id` / `ticket_id`\n- Integration-specific IDs (`github_id`, `gitlab_id`, `jira_id`)\n- Keys (`github_key`, `gitlab_key`, `jira_key`)\n- URLs (`github_url`, `gitlab_url`, `jira_url`, `external_url`)\n- `source` and `external_refs` metadata\n\nIf a ticket already exists with any matching identity key, it is skipped to avoid duplicates.\n\n## Performance Improvements\n\nRecent updates have significantly improved performance:\n- **Parallel Processing**: Scans files using multiple workers (configurable)\n- **Smart Filtering**: Skips large files (\u003e100KB) and files with minimal content\n- **Optimized Exclusions**: Automatically excludes test directories and examples\n- **Deduplication**: Prevents duplicate tickets and TODO entries across runs\n\n## Python API\n\n```python\nfrom pathlib import Path\nfrom prefact.config import Config\nfrom prefact.engine import RefactoringEngine\n\nconfig = Config(\n    project_root=Path(\"./my_project\"),\n    package_name=\"planfile\",\n    dry_run=False,\n    backup=True,\n)\n\nengine = RefactoringEngine(config)\nresult = engine.run()\n\nprint(f\"Found {result.total_issues} issues\")\nprint(f\"Fixed {result.total_fixed}\")\nprint(f\"All valid: {result.all_valid}\")\n```\n\n## Writing Custom Rules\n\nExtend `BaseRule` and use the `@register` decorator:\n\n```python\nfrom prefact.rules import BaseRule, register\nfrom prefact.models import Issue, Fix, ValidationResult\n\n@register\nclass MyCustomRule(BaseRule):\n    rule_id = \"my-custom-rule\"\n    description = \"Does something useful.\"\n\n    def scan_file(self, path, source):\n        # Return list[Issue]\n        ...\n\n    def fix(self, path, source, issues):\n        # Return (fixed_source, list[Fix])\n        ...\n\n    def validate(self, path, original, fixed):\n        # Return ValidationResult\n        ...\n```\n\n## CI/CD Integration\n\n```yaml\n# GitHub Actions\n- name: prefact check\n  run: |\n    pip install ./prefact\n    prefact scan --path . --format json -o prefact-report.json\n    prefact fix --path . --dry-run\n```\n\n## Running Tests\n\n```bash\npip install -e \".[dev]\"\npytest -v\n```\n\n## License\n\nLicensed under Apache-2.0.\n## Author\n\nTom Sapletta\n## Status\n\n_Last updated by [taskill](https://github.com/oqlos/taskill) at 2026-04-25 13:43 UTC_\n\n| Metric | Value |\n|---|---|\n| HEAD | `0aac827` |\n| Coverage | — |\n| Failing tests | — |\n| Commits in last cycle | 50 |\n\n\u003e Primarily documentation and refactoring work: the docs and README were updated, the code-analysis engine and configuration/CLI were refactored and improved, and Markdown output and example modules were added. Minor fixes include suppressing mypy errors with type: ignore and auto-fixing ruff formatting and imports.\n\n\u003c!-- taskill:status:end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemcod%2Fprefact","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsemcod%2Fprefact","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemcod%2Fprefact/lists"}