Skip to content

Fix deletion-only diff mapping; harden the API server and web tier - #2

Merged
Anuragp22 merged 3 commits into
masterfrom
fix/deletion-mapping-and-server-hardening
Jul 13, 2026
Merged

Fix deletion-only diff mapping; harden the API server and web tier#2
Anuragp22 merged 3 commits into
masterfrom
fix/deletion-mapping-and-server-hardening

Conversation

@Anuragp22

Copy link
Copy Markdown
Owner

Summary

Three focused commits: a real correctness bug in the core product, the API-server security hardening, and the web-tier fixes — plus an interactive architecture explorer.

Correctness

  • Deletion-only diff hunks were dropped. A hunk with only - and context lines produced zero line ranges, so the enclosing function was never flagged and its callers were never traversed — a silent empty blast radius for one of the highest-impact change types. Fixed by anchoring a zero-width range at the deletion point (a following + supersedes it; consecutive deletions collapse). Covered by 2 new tests and verified end-to-end.

Security / hardening

  • serve binds 127.0.0.1 by default (was all interfaces, no auth, while the banner claimed localhost); --host makes remote binding an explicit opt-in.
  • No user-controlled value reaches git's argument parser/api/analyze/diff is reduced to the working-tree diff against HEAD; the arbitrary base/head form is gone.
  • Repo→revision binding. GraphData now carries Commit + RepoRemote, stamped at index time; analyze warns on graph/HEAD skew. New GET /api/repo.

Web tier

  • PR analysis is scoped to the served repo (via /api/repo), fixing the flaw where any GitHub repo's diff was analyzed against the local graph and returned confident nonsense. Added a "Local changes" mode; kept Paste Diff.
  • Removed the dead /api/why and /api/analyze/branches endpoints and their unused clients.
  • Auth reads BETTER_AUTH_SECRET from env so sessions survive restart, with a documented note that production must be a GitHub App (an OAuth app can't create check runs).
  • New CI web job (tsc --noEmit, lint, next build) so the dashboard can no longer break silently. The dogfooding workflow's risk gate now blocks on HIGH / tool-failure only (MEDIUM stays advisory).

Docs

  • docs/architecture-explorer.html — an offline, interactive four-layer architecture + LLD + SOTA explorer.

Verification

  • go build ./... and go test ./... -race green across all packages (incl. the server concurrency test).
  • Web tsc --noEmit, npm run lint, and next build all clean.
  • Deletion fix dogfooded: a pure-deletion diff against ComputeBlastRadius now reports the function + its 17 dependents (previously zero).

🤖 Generated with Claude Code

Anuragp22 and others added 3 commits July 14, 2026 03:04
Correctness:
- diff parser dropped pure-deletion hunks (only '-' and context lines),
  producing zero line ranges so the enclosing function was never flagged
  and its callers were never traversed — a silent empty blast radius for
  one of the highest-impact change types. Anchor a zero-width range at the
  deletion point; a following '+' (a modification) supersedes it, and
  consecutive deletions collapse to one range. Covered by two new tests
  and verified end-to-end via a deletion diff against ComputeBlastRadius.

Security:
- serve now binds 127.0.0.1 by default (was all interfaces with no auth
  while the banner claimed localhost); --host makes remote binding opt-in.
- handleGitDiff passes --end-of-options before the user-supplied revision
  so a '-'-prefixed value can't be parsed as a git flag.

Truthfulness / hygiene:
- Drop the stale "WebSocket" claim from serve --help and the README; the
  feature was removed in d7a59cc.
- CI blast-radius job now enforces the exit-code contract: block on HIGH
  (1) or tool failure (3), MEDIUM (2) stays advisory. The comment still posts.
- gitignore cv.*, ideas.txt, web/.next/; allow docs/*.html.
- Add docs/architecture-explorer.html: an offline, interactive four-layer
  architecture + LLD + SOTA explorer.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BcVscS2c2WCee2ZcU353bF
The graph carried only a local RootPath, so analysis joined a diff to the
graph on file paths alone — with no way to tell a stale graph from a fresh
one, or (via the server) one repo's diff from another's. This is the gap
behind the dashboard's unsound "analyze any PR" feature and the documented
graph/diff revision-skew weakness.

- GraphData gains Commit (indexed HEAD) and RepoRemote (normalized origin).
- index stamps both at store time (best-effort; empty outside a git repo).
- analyze warns when the graph's commit != current HEAD, since a stale
  graph drifts line numbers and silently mis-maps the diff.
- New GET /api/repo exposes {remote, commit, root_path} so the dashboard
  can scope PR analysis to the served repo instead of an arbitrary one.
- normalizeRemote canonicalizes https/ssh/.git forms; covered by tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BcVscS2c2WCee2ZcU353bF
The dashboard analyzed any GitHub repo's diff against the local graph — no
repo->graph binding — so it silently produced nonsense for any repo other
than the served one. And four endpoints had no UI, one shelled out to git
with a user-controlled revision, and the web app was in no CI job at all.

- analyze page: scope the GitHub PR picker to the served repo via /api/repo
  (parse its remote); the diff and the graph now always describe the same
  code. Add a "Local changes" mode (analyze the served repo's uncommitted
  work tree) and keep Paste Diff.
- server: drop the dead /api/why and /api/analyze/branches handlers, and
  reduce /api/analyze/diff to the working-tree diff against HEAD only — no
  query value reaches git's argument parser anymore. /api/reload stays
  (exercised by the concurrency test).
- github proxy: remove the now-unused repos action.
- api client: add getRepo(); drop the dead why/getBranches/reload clients;
  add analyzeLocal().
- auth: read BETTER_AUTH_SECRET from env so sessions survive restart, and
  document that production must be a GitHub App (installation tokens, real
  DB) — an OAuth app can't create check runs.
- CI: new web job (npm ci, tsc --noEmit, lint, next build) so the dashboard
  can no longer break silently.

Verified: go build + go test -race green; web tsc/lint/next build green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BcVscS2c2WCee2ZcU353bF
@Anuragp22
Anuragp22 merged commit dda8243 into master Jul 13, 2026
4 of 5 checks passed
@Anuragp22
Anuragp22 deleted the fix/deletion-mapping-and-server-hardening branch July 13, 2026 22:08
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