Skip to content

feat(visual-agent): visual diff + change quantification#651

Merged
JSONbored merged 14 commits into
JSONbored:mainfrom
kiannidev:feat/issue-582-visual-diff
Jun 17, 2026
Merged

feat(visual-agent): visual diff + change quantification#651
JSONbored merged 14 commits into
JSONbored:mainfrom
kiannidev:feat/issue-582-visual-diff

Conversation

@kiannidev

Copy link
Copy Markdown
Contributor

Summary

  • Adds compareRouteScreenshots and compareVisualCaptureSets in src/visual-agent/visual-diff.ts to compare before/after PNG captures per route using pixelmatch.
  • Produces diff PNG bytes, changed-pixel percentages, and route status classification (changed, unchanged, new, removed).
  • Applies anti-alias tolerance via pixelmatch threshold and suppresses sub-threshold noise with a configurable changed-pixel percent cutoff.
  • Returns an overall summary with average changed-pixel percent across comparable routes.

Closes #582

Parent epic: #577

Test plan

  • npm run typecheck
  • Unit tests in test/unit/visual-diff.test.ts cover unchanged, changed, new/removed, noise suppression, dimension mismatch, and set summaries
  • Full CI (npm run validate)

Made with Cursor

Compare before/after route screenshots with pixelmatch, emit diff PNGs, changed-pixel percentages, and changed/unchanged/new/removed classification for the owner-led visual PR review pipeline.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ghost

ghost commented Jun 13, 2026

Copy link
Copy Markdown

Note

Gittensory Gate skipped

PR closed before full evaluation. No late first comment was created.

Signal Result Evidence Action
Gate result ⚠️ Skipped #651 is no longer open. No action.

💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

@ghost ghost added the gittensory:reviewed label Jun 13, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@ghost

ghost commented Jun 13, 2026

Copy link
Copy Markdown

gittensory · advisory review

Reviewed 5 changed file(s) — two independent AI reviewers.

Changed files: package-lock.json, package.json, src/visual-agent/visual-diff.ts, test/unit/visual-diff.test.ts, test/unit/worker-entry-boundary.test.ts

Suggested action:Safe to merge — both reviewers found no blocking issues.

Reviewer A · gpt-oss-120b — recommends ✅ merge
This PR introduces a visual diff utility for comparing PNG screenshots, adds comprehensive unit tests, and enforces that the new Node‑only modules are not pulled into the Cloudflare Worker entry or MCP binary. The implementation is clean, type‑safe, and respects the project's public/private boundaries.

Suggestions

  • Add a brief comment in the package.json scripts or README noting that pixelmatch/pngjs are Node‑only and must stay out of the worker bundle.
  • Consider adding a lint rule or CI check to prevent accidental imports of visual-agent modules from non‑agent entry points.

Worth double-checking

  • Future code changes might inadvertently import visual-agent utilities into the worker bundle; the existing test guards against this but a lint rule would provide earlier detection.
  • The new dependencies increase bundle size for any agent that uses visual diff; ensure they remain optional and not included in production builds.

Reviewer B · nemotron-3-120b-a12b — recommends ✅ merge
The PR adds a visual diff utility for comparing route screenshots using pixelmatch and pngjs, with comprehensive unit tests and a boundary test to prevent accidental inclusion in Worker/MCP bundles. The code is well-structured, type-safe, and respects the project's public/private boundary by design.

Worth double-checking

  • Ensure the visual-agent module is never imported in src/index.ts or MCP bin (covered by new boundary test).
  • Verify that the added dependencies (pixelmatch, pngjs) are correctly listed as devDependencies in the MCP bundle if used there (though the boundary test should prevent this).

@ghost ghost removed the gittensory-review label Jun 15, 2026
New advisories for ws, tar, and js-yaml caused CI audit step to fail.
Pin ws via overrides and refresh the lockfile so npm audit --audit-level=moderate passes.

Co-authored-by: Cursor <cursoragent@cursor.com>
@kiannidev

Copy link
Copy Markdown
Contributor Author

Hi, @JSONbored
I resolved conflicts.
Please review PR again

Thanks

@JSONbored JSONbored left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #651 — feat(visual-agent): visual diff + change quantification
Author: kiannidev | CI: ✅ pass | Status: Concerns
ACTION: REQUEST CHANGES

Highlights:

  • Internal tooling that produces visual-diff bytes — not a visible UI change, so the screenshot rule doesn't apply.
  • Pure, deterministic, well-tested image comparison (unchanged/changed/new/removed, noise suppression, dimension mismatch, diff-image toggle).
  • pixelmatch/pngjs are genuinely required by this feature (legitimate, scoped).

Change requests / reasons:

  • merge conflicts
  • Verify pixelmatch/pngjs (Node Buffer/zlib) are NOT imported into the Worker entry bundle — could break the deploy bundle. Confirm they're only on the agent path.

kiannidev and others added 2 commits June 16, 2026 23:05
Move pixelmatch/pngjs to devDependencies for agent-path-only use, add
worker entry boundary tests proving the Worker and MCP bin do not reach
visual-diff, and cover the empty capture branch for coverage.

Co-authored-by: Cursor <cursoragent@cursor.com>
Cover remaining visual capture summary branches and add score-breakdown
API/MCP tests merged from main so CI stays above the 97% threshold.

Co-authored-by: Cursor <cursoragent@cursor.com>
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.68%. Comparing base (950c6e0) to head (365ee15).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #651      +/-   ##
==========================================
+ Coverage   96.66%   96.68%   +0.01%     
==========================================
  Files          92       93       +1     
  Lines       13720    13769      +49     
  Branches     5001     5015      +14     
==========================================
+ Hits        13263    13312      +49     
  Misses         88       88              
  Partials      369      369              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

kiannidev and others added 4 commits June 17, 2026 00:12
Add height-only mismatch, custom threshold, and removed-only summary
cases so changed lines in visual-diff.ts meet the 97% patch gate.

Co-authored-by: Cursor <cursoragent@cursor.com>
Use a full color swap so pixelmatch reliably detects change while still
exercising the custom threshold option path.

Co-authored-by: Cursor <cursoragent@cursor.com>
Replace divide-by-zero guard with Math.max and narrow measurable entries
so codecov patch coverage hits 97% without dead ?? fallbacks.

Co-authored-by: Cursor <cursoragent@cursor.com>

@JSONbored JSONbored left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #651 — feat(visual-agent): visual diff + change quantification
Verdict: MERGE
Resolves issue #582: FULLY
CI: All green (validate, test x2, lint, workers, mcp, ui, security, Superagent Security Scan = success, codecov). gittensory/Context neutral.

Highlights:

  • Implements exactly what #582 asks: compareRouteScreenshots + compareVisualCaptureSets using pixelmatch/pngjs, producing diff PNG bytes, per-route changed-pixel %, and changed/unchanged/new/removed classification + overall average and summary.
  • Anti-alias tolerance via pixelmatch threshold and sub-threshold noise suppression via configurable changeThresholdPercent; dimension mismatch handled as deterministic "changed" (no crash).
  • Strong unit tests (all four classifications, noise suppression, custom threshold, includeDiffImage toggle, width/height-only mismatch, mixed/empty summaries).
  • Good safety boundary: worker-entry-boundary.test.ts asserts the Node-only deps (pixelmatch/pngjs/visual-agent) never become reachable from the Worker entry or the published MCP bin.

Concerns / required changes:

  • Minor: includes test-only additions for the pre-existing /v1/scoring/explain-breakdown route and gittensory_explain_score_breakdown — tangential extra coverage, no unrelated production code. Harmless, slightly off-scope.

Completeness vs issue: Routes with real changes get a diff image + change %, unchanged marked unchanged, new/removed classified — all acceptance criteria met and tested.

@dosubot dosubot Bot added the lgtm label Jun 17, 2026
@JSONbored
JSONbored merged commit 8bdd2bd into JSONbored:main Jun 17, 2026
17 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in gittensory - v1 roadmap Jun 17, 2026
@JSONbored JSONbored added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jun 17, 2026
@JSONbored

Copy link
Copy Markdown
Owner

Adding gittensor:feature label as a one-time goodwill gesture - please do NOT complete issues assigned to other people unless explicitly asked to do so, or else you will not get any points in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

owner-led(visual-agent): visual diff + change quantification

2 participants