website/reference/commands/enhance/discover.md

Run xpd enhance discover to find the names, strings and modules that one text search does not find, and gate each rename in a recorded run.

GroupFinding kinds
Names that one search does not findname-collision, generic-verb-name, vague-module-name, module-private-name, import-alias, wildcard-import
Strings and dead ends that a search missesinterpolated-key, hasattr-probe, error-message-prefix, deprecated-without-decorator
Types that let a caller swap argumentsid-without-newtype

A name-collision finding means two or more modules define the same public name. The survey counts Python public names, Go exported package declarations, and Rust public items separately. JavaScript and TypeScript exports share a count. It leaves out test files, Python __init__.py and Hamilton modules, main, and names that start with an underscore. The other kinds come from the Python rules of the same name. The header counts how many public names one module alone defines, and a rename that makes a name collide adds a finding that fails the gate.

Every finding of this track is advice: a fix may name one, and no run or audit has to clear one. A kind blocks only after an oracle that can prove a finding wrong has labelled at least 30 of its findings and at least 90% were right, and no kind has reached that.

Run xpd enhance discover --questions to read the six questions and the facts that inform them. Pass --all-modules to start to review every module against the questions that --questions prints.

Recorded run

  1. Start: record the current commit, paths, and project checks from a clean tracked tree with xpd enhance discover start titles.py notes.py --check "your-project-check".
  2. List: read the stable ID of each finding with xpd enhance discover . --format json.
  3. Plan: record the ordered fixes, each naming the findings it removes, using xpd enhance discover plan plan.json. Set changes_interface on a rename that other modules import.
  4. Approve: record approval for an interface change with xpd enhance discover approve fix-id.
  5. Gate: commit one fix and run xpd enhance discover gate fix-id.
  6. Drop: return to the run's current commit and record a reason with xpd enhance discover drop fix-id --reason "reason".
  7. Status: show the current run, its recorded answers, and the next stage with xpd enhance discover status.
  8. Finish: compare against the starting commit with xpd enhance discover finish. An open fix causes exit 1. Advice that is left needs no reason.

Example

Two modules define clean, so a search for it finds two definitions, and neither name says what it cleans.

python
1def clean(text):
2 return text.strip()
python
1def clean(text):
2 return " ".join(text.split())
console
1$ git init -q && git add titles.py notes.py && git -c user.name=xpd -c user.email=xpd@example.com -c commit.gpgsign=false commit -qm start
2$ xpd enhance discover start titles.py notes.py --check "python3 -m py_compile titles.py notes.py" --format json | jq -c '{findings: .run.was, next: .next.stage}'
3{"findings":3,"next":"plan"}
4$ xpd enhance discover titles.py notes.py --format json | jq -c '{names: .read, advice: [.advice[].kind]}'
5{"names":{"files":2,"public_names":1,"defined_once":0},"advice":["name-collision","generic-verb-name","generic-verb-name"]}
6$ xpd enhance discover titles.py notes.py --format json | jq -c '{fixes: [{id: "rename-clean", title: "Name each clean after what it cleans", findings: [.advice[].id], changes_interface: true}]}' | xpd enhance discover plan - --format json | jq -c .next.stage
7"ask"
8$ xpd enhance discover approve rename-clean --format json | jq -c .next.stage
9"fix"
10$ sed -i 's/^def clean(/def clean_title(/' titles.py && sed -i 's/^def clean(/def clean_note(/' notes.py && git -c user.name=xpd -c user.email=xpd@example.com -c commit.gpgsign=false commit -qam "Name each clean after what it cleans"
11$ xpd enhance discover gate rename-clean --format json | jq -c '.run.rounds[0][0] | {outcome, fixed: (.fixed | length)}'
12{"outcome":"kept","fixed":3}
13$ xpd enhance discover titles.py notes.py --format json | jq -c .read
14{"files":2,"public_names":2,"defined_once":2}
15$ xpd enhance discover finish --format json | jq -c .run.finished
16xpd: 3 findings at the start, 0 now: 3 fixed, 0 added, 0 accepted, 0 left without a reason; lines 4 -> 4
17true

Exit status

A successful list or recorded stage exits 0. A rejected gate or a finish with an open fix exits 1. Invalid input exits 2.