Inspiration

AI coding agents generate working code at record speed, easily passing functional unit tests and linters. However, a "green" CI pipeline often hides structural debt: an AI patch might solve a problem in a new way or duplicate existing business rules across multiple entry points (portal, api, batch). As these patterns accumulate, developers and coding agents spend more time figuring out where a rule lives and what else a change might affect. We built DupeSeek as a deterministic architectural quality gate for the Green CI Lies challenge—blocking unmaintainable AI-generated patches before they merge, even when all functional tests pass.

How we built it

We engineered a two-layer, deterministic pipeline separating static AST analysis from reporting and policy enforcement:

  • Universal AST & Unified IR (src/ + analyzer/main.py): Using Python and tree-sitter-language-pack, DupeSeek parses source files into a language-agnostic Unified Intermediate Representation (UIR). By applying alpha-renaming to local variables ($VAR_0, $VAR_1) and hashing canonical expression subtrees with SHA-256, the analyzer detects duplicated business rules even when variables are renamed or logic is inlined inside callbacks (such as .filter()).
  • Deterministic Rule Engine & Scoring (rules.json): Every threshold and weight is read from a versioned rules.json file whose SHA-256 prefix is echoed in every report. Duplicated business logic is scored non-linearly: $$\text{weight} = \text{round}\left(w \cdot (n - 1)^{1.3}\right)$$ Combined with penalties for control-flow nesting depth and hardcoded magic literals, the engine computes a clamped risk score ($0\text{--}100$) and a strict pass/fail verdict.
  • Go CLI, SARIF & Air-Gapped Docker (greenci/): A static Go binary orchestrates the analyzer subprocess, enforces path sandboxing, compares clean vs. risky patches (--compare), exports SARIF 2.1.0 logs for VS Code, and proves reproducibility via --verify-runs N (re-running fresh processes and failing with exit code 3 on any SHA-256 drift). All tree-sitter grammars are pre-baked into a python:3.12-slim image so the entire gate runs offline with --network none.
  • Zero-Build Web Dashboard (greenci-web + web/): A vanilla ES-module dashboard fronting the exact same Go pipeline—featuring A-vs-B comparison, a "tomorrow's requirement" stale-rule simulator, determinism verification, and an interactive rules.json sandbox that tests custom weights in isolated temp files without touching the repository.

Benchmarks & Validation

We built six benchmark pairs (benchmarks/) covering real-world scenarios: order dispatch, shipping labels, checkout discounts, document access, signup validation, and premium entitlement. In every pair, both Patch A (centralized rule) and Patch B (fragmented rule) pass the exact same node:test suite, demonstrating how traditional CI stays green while maintainability degrades—and how DupeSeek catches the regression (e.g., 0 LOW vs. 74 HIGH across 5 identical SHA-256 runs).

Challenges we faced

  • Catching inline rule duplication: Comparing whole function declarations initially missed cases where an AI agent inlined a duplicated condition directly into an arrow callback. Extracting and hashing top-level logical expression subtrees solved this across entry points.
  • Offline non-root Docker execution: tree-sitter-language-pack acquires a download lock inside XDG_CACHE_HOME even when grammars are pre-baked. We solved this with a lightweight entrypoint wrapper that copies the read-only baked cache into a user-owned temp directory on first run, allowing docker run --network none --user $(id -u):$(id -g) to pass 5/5 determinism checks cleanly.
  • Strict byte-for-byte determinism: Eliminating timestamps, host paths, and unordered map/set iteration across both Python and Go so repeated runs produce identical JSON, Markdown PR comments, and SHA-256 hashes.

What we learned

  • Deterministic AST normalization and alpha-renaming catch semantic duplication reliably without probabilistic LLM overhead.
  • Separating core analysis (analyzer/) from orchestration, SARIF rendering, and UI (greenci/) makes multi-language tooling easy to verify, containerize, and reproduce.
Share this project:

Updates

Submission history