Skip to content

feat(server): Change Lens engine, API and srcly changes - #408

Merged
byronwall merged 16 commits into
mainfrom
change-lens/server
Nov 22, 2026
Merged

byronwall merged 16 commits into
mainfrom
change-lens/server

Conversation

@byronwall

@byronwall byronwall commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

srcly changes and a new API report the code chunks that a branch or a time window edited. Each chunk is a function, a Markdown section or a line range, with complexity before and after, the commits that touched it, and its diff. Part of #397.

What you'll see

  • srcly changes [path] prints the resolved window, two review lists, and the edited chunks by folder. Flags: --window branch|24h|7d|custom, --mode touched|net, --base, --head, --since, --until, --no-worktree, --json.
  • Touched keeps work that was changed and put back, as reverted. Net compares the two end snapshots, so that work is gone.
  • Staged and unstaged edits count as one Working tree entry after the last commit.
  • A pure rename reports no complexity change. A file no analyzer reads says not measured, never 0.
  • GET /api/change-lens and GET /api/change-lens/hunk serve the same result to the client. No screen uses them in this layer.

Proof

srcly changes on the acceptance repo that server/tests/fixtures/change_lens_repo.py builds (trimmed). It shows a function edited three times, a reverted function, a deleted function, a pure rename, and config and Markdown hunks:

# Change Lens: clfix

- Window: This branch, touched (every chunk a commit changed), first-parent history of `HEAD`
- Base: main @ 97e5cf7 (2026-01-05T04:00:00-05:00)
- Head: Working tree on feature @ 0c1943e
- 11 commits · 7 of 7 files edited · 11 chunks · 68 lines churned · 52 net · 1 reverted

### Already complex and changed
- `src/router.ts::dispatch` modified · complexity 11 → 13 · +1 −0

### New hotspot
- `src/planner.ts::planRoute` added · complexity – → 12 · +23 −0
- `src/worker.ts::retryJob` modified · complexity 5 → 11 · +6 −1 · 3 touches

- `config/settings.yaml` `line 3` modified · not measured · +1 −1
- `scheduler.ts` `pickNext` reverted · complexity 3 → 3 · +7 −7 · 2 touches
- `worker.ts` `legacyCleanup` deleted · complexity 3 → – · +0 −7
- `text.ts` moved · from `src/util/strings.ts` · complexity 2 → 2 · +0 −0

With --mode net, pickNext does not appear (0 matches).

  • scripts/check.sh server on the top of the stack: 606 passed. 23 of them are tests/test_change_lens.py, one per acceptance case and one per bug below.
  • A separate read-only test pass built about 60 hostile repos (reverts, rename chains, moves, merges, shallow clones, dirty trees). It found 10 bugs. Each is fixed here in its own commit with a test: upstream merges counted as session work, PR merges dropped on a local main that is ahead, invented object symbols, same-named functions paired by position, a reused path after a rename, comments above a method given to the class, nested lines in a parent's diff, odd line-break characters, a renamed Markdown heading, and a syntax error at head.
  • Speed, measured by the worker on this repo: --window 7d (23 commits, 417 chunks) in 1.5 to 1.8 s.

Limits

  • The upstream-merge rule needs git 2.45 or later.
  • A file broken only in a mid-window commit keeps the analyzer's scopes for that commit.
  • The syntax-error check flags client/src/components/FileTypeFilter.tsx in this repo. Nobody checked whether that is a false positive.
  • The branch window calls gh to find a PR base. Offline, that call can wait up to 10 s.
  • A file added and then deleted inside the window gives one reverted chunk per symbol, which is noisy.
  • Worker-process parsing has no per-file timeout.

Stack: Change Lens

What splits: The Change Lens feature from #397: the git engine and CLI, the review panel, the map view, and the join with docs.
Why it splits: The engine is the risky part and has its own tests and CLI proof. Each client layer adds files that nothing loads until the top layer, so the lower three can merge with no visible change in the app.
Why this split: Three workers built the server, the panel and the map at the same time against one contract, so these seams match file ownership and each diff reads alone. I rejected one PR (about 10,000 lines) and a split by feature (windows, then chunks, then buckets), because each feature cuts through all three parts.

  1. feat(server): Change Lens engine, API and srcly changes #408: the engine, the API, srcly changes, and the acceptance fixture.
  2. feat(client): Change Lens review panel components #409: the review panel components and a dev harness.
  3. feat(client): Changes view with Only edits and In repo maps #410: the Changes view with both maps, on mock data.
  4. feat: Change Lens on real history, with docs #411: the join on the real API, the e2e test, and the docs.

Survey moves: +31 traces in server (160 → 191; 30 partial, 1 assumed) and more stops with them, the largest being frontier: external-code +705. All come from the new server/app/services/changelens/ files entering the surveyed corpus; the one new assumed trace is app/services/changelens/chunks.py#_buckets. No analysis code changed and no trace errored.

🤖 Generated with Claude Code

@byronwall
byronwall added this pull request to stack #412 November 21, 2026 23:58
@byronwall byronwall changed the title change lens/server feat(server): Change Lens engine, API and srcly changes Nov 21, 2026
byronwall and others added 16 commits November 21, 2026 22:00
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The engine reads one first-parent history, follows each changed file
through the window, and gives every changed line to the scope that holds
it in that revision. It pairs base and head chunks by name, never by
line number.

- GET /api/change-lens and /api/change-lens/hunk
- srcly changes [path], Markdown by default and --json
- An acceptance repo builder with fixed dates, and tests on it

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- selection.repoRoot: payload paths are relative to it.
- A file no analyzer reads gives range chunks. A whole file (added,
  deleted, renamed with no edit, generated) is one file chunk.
- Upstream merges, the 200-commit cap and left-out files are noted.
- Hunk diffs hold only the chunk's own lines.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
fixture.json and fixture.net.json are the payloads the engine returns for
the acceptance repo. The ranking parity snapshot scans tests/fixtures, so
it gains the new fixture builder.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
When a window holds a merge of the default branch and its base is older
than that merge, the base tree takes the merge's own diff. Before values,
the net diff and hunk diffs then show only the branch's own work.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A merge commit that is itself on the default branch is that branch's own
history. It was dropped as an upstream merge when local main was ahead of
origin/main.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…mous objects

Scopes that share a qualified name in one file pair across revisions by
body (identical first, then closest), so a function that only moved down
is no longer read as modified. An object literal with no binding is no
chunk: its lines stay with the scope around it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…her's path

A file added in the window has no base and a file deleted in it has no
head, even when another lineage holds the same path at that end. The
files list holds each path once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The lines right above a method were left with the class around it,
because the class already owned them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…s' lines

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Git output is read as bytes, and file text is split on "\n" alone. A lone
CR, a form feed or U+2028 in a file no longer shifts line numbers or
breaks the diff parse.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ction

A heading reworded above the same text is one modified section with an
uncertain match, not one section deleted and one added. A section's body
is its own text, without its subsections.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A file that does not parse at base or head gets no symbols and no
metrics: its hunks are range chunks with a reason, and a note names the
file. Before, the analyzer's guesses read as confident deletes and moves.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ache

- An empty added or deleted file is one file chunk in both modes.
- /hunk answers 404 for a commit outside the selection and 400 for a sha
  under 7 characters.
- since later than until is a 400 with a plain reason.
- A time window that reads the 5,000-commit limit says so in a note.
- A lock guards the parse cache.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…iff text

The net lines of a moved or renamed symbol leave out the lines of the
scopes nested in it, as its hunk diff does. Diff text drops the CR that
ends each line of a CRLF file.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@byronwall
byronwall marked this pull request as ready for review November 22, 2026 03:03
@byronwall
byronwall merged commit 0db5cec into main Nov 22, 2026
6 checks passed
@byronwall
byronwall deleted the change-lens/server branch November 22, 2026 03:14
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