Skip to content

feat: add td diff command for semantic code change analysis#72

Open
marcus wants to merge 1 commit intomainfrom
semantic-diff-v2
Open

feat: add td diff command for semantic code change analysis#72
marcus wants to merge 1 commit intomainfrom
semantic-diff-v2

Conversation

@marcus
Copy link
Copy Markdown
Owner

@marcus marcus commented Mar 22, 2026

Summary

  • Adds td diff command that parses unified git diffs and uses Go AST analysis to identify symbol-level changes (functions, types, methods, imports added/removed/modified)
  • Supports --staged, --ref HEAD~N, --issue (diff since issue start snapshot), and --json output
  • Fixes v1 correctness bug: new file content is now retrieved from the working tree (non-staged) or git index (git show :path for staged) instead of always reading from HEAD, which gave wrong results for staged diffs and uncommitted changes

Architecture

  • internal/diff/parse.go — unified diff parser: FileDiff, Hunk, Parse()
  • internal/diff/semantic.go — Go AST symbol extraction and comparison: AnalyzeGoFile()
  • internal/diff/summarize.go — orchestrator: reads old/new content, runs AST analysis on .go files, file-level categories for non-Go
  • internal/git/git.go — new helpers: GetDiffContent, GetDiffContentStaged, GetFileAtRef, GetStagedFile
  • cmd/diff.go — cobra command wiring with flags

Test plan

  • internal/diff unit tests: parser (add/delete/modify/rename/multi-file), AST analysis (functions, types, methods, imports, consts, vars)
  • cmd tests: command registration, flag defaults, parse+summarize integration
  • Full go test ./... passes

Nightshift-Task: semantic-diff

🤖 Generated with Claude Code


Automated by nightshift

Parses unified git diffs and uses Go AST analysis to identify symbol-level
changes (functions/types/methods/imports added/removed/modified). Supports
--staged, --ref HEAD~N, --issue (diff since start snapshot), and --json.

Fixes correctness bug from v1: new file content is now retrieved from the
working tree (non-staged) or git index (staged) instead of always reading
from HEAD, which gave wrong results for staged diffs and uncommitted changes.

Nightshift-Task: semantic-diff
Nightshift-Ref: https://github.com/marcus/nightshift

Co-Authored-By: Claude Opus 4.6 (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