Skip to content

Untangle codebase structure

Run xpd enhance untangle to find code that changes together in separate files, needless module links, and dead weight using source files and Git history without running project code.

Source files and Git historyxpd enhance untangle--mapxpd enhance untangle--format jsonMechanical --move and--inline-facade or manualeditxpd enhance untangle gate<fix-id>xpd enhance untangle finish

Print a Mermaid coupling map for Python packages, Go packages, Rust crates, and JavaScript or TypeScript modules, including mixed selections, or pass --format json to inspect nodes, directed edges, import cycles, orphans, and hidden co-change links.

Terminal window
xpd enhance untangle src/ --map
xpd enhance untangle src/ --map --format json

In an editor running xpd lsp, workspace-level structural findings such as untangle/import-cycle, untangle/orphaned-module, untangle/facade-module, untangle/single-use-module, untangle/mixed-responsibilities, and untangle/shared-state appear as HINT diagnostics.

Preview and apply mechanical Python refactors

Section titled “Preview and apply mechanical Python refactors”

Use --move to relocate a Python module and rewrite every importing caller, or --inline-facade to collapse a re-export shim directly onto its defining modules. Both flags print a unified diff in dry-run mode first and validate every edited file with libcst before writing when --apply is passed.

Terminal window
xpd enhance untangle --move pkg/old_module.py pkg/new_module.py
xpd enhance untangle --move pkg/old_module.py pkg/new_module.py --apply
xpd enhance untangle --inline-facade pkg/compat_shim.py
xpd enhance untangle --inline-facade pkg/compat_shim.py --apply

Record structural cleanups in a Duroxide ledger so every commit must pass your checks and lower or settle findings.

Stage Command Purpose
Start xpd enhance untangle start src/ --check "<cmd>" Record the baseline commit, paths, and project checks
Survey xpd enhance untangle src/ --format json Read stable finding IDs and six structural checklist items per module
Plan xpd enhance untangle plan plan.json Register ordered fixes (shorter or design), accepted findings, and checklist verdicts
Gate xpd enhance untangle gate <fix-id> Verify checks pass, findings do not regress, and goal constraints hold
Finish xpd enhance untangle finish Confirm every open fix, new finding, and checklist item is settled

See xpd enhance untangle for every finding kind and stage command.