Skip to content

xpd enhance untangle

Run xpd enhance untangle to find pieces that change together in separate modules, needless links between modules, and dead weight across a codebase.

Group Finding kinds
Hidden links copy, near-copy, changes-together, shared-state
Needless links volatile-import, import-cycle, private-reach, vague-module, mixed-responsibilities, reexport-hop
Surplus pass-through, symbol-alias, getattr-shim, parameter-alias, default-argument, unreferenced, constant-parameter, orphaned-module, facade-module, single-use-module
Special cases one-value-branch, one-caller-parameter, defensive-coercion

A module with a finding gets six structural checklist items. Run xpd enhance untangle --questions to read the questions and the facts that inform them, or xpd enhance untangle <paths> --map to print a Mermaid module coupling and health map for Python, Go, Rust, JavaScript, and TypeScript trees, including mixed selections (add --format json for structured nodes, edges, and hidden links). The supported fix goals are shorter and design.

For mechanical Python cleanups, preview diffs with xpd enhance untangle --move <from> <to> or xpd enhance untangle --inline-facade <file> and pass --apply to write the validated changes.

A shorter fix requires a lower line count. For a data script refactor, run xpd equiv on the old and new versions and record the result in the fix commit.

Terminal window
xpd enhance untangle [OPTIONS] [PATHS]...
xpd enhance untangle <COMMAND>
Subcommand What it does
xpd enhance untangle start Start a run: record the commit it starts from, the paths, line count, checks and optional benchmark of the project
xpd enhance untangle plan Record the plan of a round: the fixes in order, and the findings that are right as they are
xpd enhance untangle approve Record that the user said yes to a fix that changes what callers or users see
xpd enhance untangle gate Gate a fix that is committed: run the checks, time --bench when set, count lines and compare the findings with the commit before it. Exit 1 when the fix is not kept
xpd enhance untangle drop Record that a fix was given up, after its files were restored
xpd enhance untangle status Print the run and the stage that comes next
xpd enhance untangle finish End the run: compare findings, line count and benchmark timing with the start commit. Exit 1 while a fix is open or a new finding has no reason
Argument What it does
<PATHS>... Files or directories (directories respect .gitignore)
Option Default What it does
--kind <KIND> List only the findings of these kinds, separated by commas. Repeatable. Values: copy (The same code is written out in more than one place), changes-together (Two files change in the same commits, and no import joins them), shared-state (Code writes state that another module or a function's callers depend on), volatile-import (A module imports a module that changes at least twice as often as it does), import-cycle (Modules import one another in a circle), private-reach (Code uses a private name of another module), vague-module (A module named utils, helpers, config or another role holds code with no single purpose), pass-through (A function or method only passes its parameters to one call), symbol-alias (A class, function, type, or public attribute is aliased under a second name), getattr-shim (A module-level __getattr__ hook or delegating proxy class hides real definitions behind runtime lookup), parameter-alias (A function keeps a legacy parameter alias alive through fallback assignment or kwargs.pop), unreferenced (No file mentions a function or class apart from its definition), test-only-helper (A production definition referenced only by test files), constant-parameter (Every call gives a parameter the same value), one-value-branch (A branch runs for one string value), one-caller-parameter (One call alone passes a parameter that has a default), near-copy, default-argument, orphaned-module (A production module that no other surveyed file imports), facade-module (A module that only re-exports names from other modules), single-use-module (A helper module imported by only one non-test file), mixed-responsibilities (A large module whose top-level functions split into unrelated clusters), reexport-hop (A module imports a symbol through a non-__init__ module that merely re-exports it), defensive-coercion (A function coerces a parameter in place with isinstance instead of accepting one type).
--limit <LIMIT> 20 The most findings to list of each kind, strongest first. 0 lists every finding.
--since <COMMIT> Count the findings at this commit too, and print each count beside the count of today.
--group-by <GROUP_BY> none Group findings and checklist items by owning module or shared cause. Values: none (Keep the default flat per-kind listing), module (Group findings and checklist items by owning module path), cause (Group related findings by shared kind and anchor files).
--packet <N> Emit one 1-indexed deterministic context-budgeted review packet for the Nth cluster.
--budget-lines <LINES> 300 Maximum source lines included across excerpts inside a --packet view.
--all-modules Include checklist review items for every surveyed module, not only modules with findings.
--format <FORMAT> Output format. Default: text on a terminal, json otherwise. Values: text, json.
--questions
--map Print a Mermaid (or JSON with --format json) module coupling and health map for Python, Go, Rust, JavaScript, or TypeScript.
--move <FROM> <TO> Mechanically move a Python module (FROM TO) and rewrite project imports (dry-run unless --apply) Repeatable. Conflicts with --map, --inline-facade, --questions.
--inline-facade <FILE> Inline a pure re-export Python facade module into its callers and remove it (dry-run unless --apply) Conflicts with --map, --move, --questions.
--apply Write mechanical refactor changes to disk instead of printing a preview diff.
xpd enhance untangle start--checkxpd enhance untangle plan(findings, goals, answered)edit and commitkept (checks pass, <= findings,goal met)failed gatexpd enhance untangle finish (allitems settled)startplangatedrop
  1. Start: record the current commit, paths, and project checks from a clean tracked tree with xpd enhance untangle start . --check "your-project-check".
  2. List: read stable finding IDs and checklist item IDs with xpd enhance untangle . --format json.
  3. Plan: record ordered fixes, accepted findings, and checklist verdicts (pass, na, or accepted) with reasons using xpd enhance untangle plan plan.json.
  4. Approve: record approval for an interface change with xpd enhance untangle approve fix-id.
  5. Gate: commit one fix and run xpd enhance untangle gate fix-id. A design fix must edit a file that owns a cited checklist item.
  6. Drop: return to the run's current commit and record a reason with xpd enhance untangle drop fix-id --reason "reason".
  7. Status: show the current run, its recorded answers, and the next stage with xpd enhance untangle status.
  8. Finish: compare against the starting commit with xpd enhance untangle finish. An open fix, a new finding without an accepted reason, or an unanswered checklist item causes exit 1.
Terminal window
$ xpd enhance untangle --questions --format json | jq -c '{facts: (.facts | length), questions: (.questions | length)}'
{"facts":2,"questions":6}

A successful list or recorded stage exits 0. A rejected gate or a finish blocked by findings or checklist items exits 1. Invalid input exits 2.