Skip to content

fix(incremental): use git --name-status -M to detect renames + prune old-path nodes (#366)#397

Open
tirth8205 wants to merge 1 commit into
Egonex-AI:mainfrom
tirth8205:fix/incremental-rename-detection
Open

fix(incremental): use git --name-status -M to detect renames + prune old-path nodes (#366)#397
tirth8205 wants to merge 1 commit into
Egonex-AI:mainfrom
tirth8205:fix/incremental-rename-detection

Conversation

@tirth8205

Copy link
Copy Markdown
Contributor

Summary

Addresses Bug 1 of 3 from #366: renamed/moved files left orphaned
old-path nodes (plus every edge that referenced them) in the knowledge
graph after an incremental /understand run.

  • Switch the incremental change-detection command in
    skills/understand/SKILL.md from git diff <base>..HEAD --name-only
    to git diff <base>..HEAD --name-status -M. The plain --name-only
    form reports a rename as only the new path, so the prune step never
    saw the old path; with -M the rename appears as
    R<score>\told\tnew and we can route the two paths to different
    buckets.
  • Add a small parser helper skills/understand/parse-git-changes.mjs
    that splits the --name-status lines into two disjoint sets:
    • changed-files.txt — paths to analyze: M, A, T, U,
      plus the new path of R<score> renames and C<score> copies.
    • prune-files.txt — paths to prune-only: D deletions plus
      the old path of R<score> renames. Copies do not prune the
      source because the original file still exists.
  • Update the Phase 2 incremental prune step to prune the union of both
    sets — re-analyzed files still need their old nodes dropped, and
    prune-only files need removal without a replacement.
  • Add tests/skill/understand/test_parse_git_changes.test.mjs with
    16 cases covering all status branches (M / A / D / R / C / T / U /
    unknown / empty) plus a CLI round-trip. Fixtures are raw
    --name-status strings — no real git invocation needed.

Scope

Only Bug 1. Two follow-up PRs cover Bugs 2 (inbound-edge pruning) and
3 (importMap recovery on rename) independently — they have no
overlap with the change-detection path touched here.

Marked Refs #366 rather than Closes #366 since two of the three
bugs ship in separate PRs.

Test plan

  • pnpm test — 216 tests pass (200 prior + 16 new).
  • pnpm lint — clean.
  • Reviewer repro: baseline-scan a repo, git mv docs/a.md docs/b.md,
    commit, run /understand (incremental). Confirm the resulting
    graph contains only document:docs/b.md, not the stale
    document:docs/a.md node + its edges.

Refs #366

🤖 Generated with Claude Code

…d paths (Egonex-AI#366)

Incremental `/understand` runs build the changed-file list via
`git diff <base>..HEAD --name-only`. Git's default rename detection collapses
a rename into a single new-path line, so the prune step never sees the old
path. The pre-rename node (and every edge that touched it) survives in the
graph as an orphan after the rename commit is analyzed.

Switch to `git diff <base>..HEAD --name-status -M` and route each status:

  - `M`, `A`, `T`, `U`                 → analyze
  - `D`                                → prune-only
  - `R<score>\told\tnew`               → prune `old`, analyze `new`
  - `C<score>\told\tnew`               → analyze `new` only (source survives)

Parsing happens in a new shared helper, `parse-git-changes.mjs`, which writes
two newline-delimited files (`changed-files.txt`, `prune-files.txt`) that
SKILL.md feeds to `compute-batches.mjs --changed-files=…` and to the prune
step. The prune step now takes the union of both sets so renamed/deleted
files no longer leave stale nodes + edges behind.

Adds `tests/skill/understand/test_parse_git_changes.test.mjs` covering the
parser's branches (M, A, D, R, C, T, U, unknown status, empty input) plus a
CLI end-to-end check that the two output files contain the expected sorted
paths. No real git invocation needed — the fixtures are raw `--name-status`
strings.

Addresses Bug 1 of 3 from Egonex-AI#366. Bugs 2 (inbound-edge pruning) and 3
(importMap recovery) are covered by separate follow-up PRs.

Refs Egonex-AI#366

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant