-
-
Immutable SHA-256 run history tracking matched, divergent, and insufficient-evidence verdicts across all 57 live tests.
-
Static forensic graph mapping dependencies, dead-code candidates, and source-linked business rules across 6 languages.
-
PHP 5.6 to 8.4: Attempt 1 is flagged divergent after inserting 2 SQLite ledger rows despite returning an identical JSON receipt.
-
Attempt 2 applies an explicit cast fix, restores 1-row SQLite parity (matched), and shows side-by-side PHP source diffs.
-
Migration workbench overview with 1-click repository import and verified parity across PHP, Python, and jQuery runs.
Inspiration
AI coding assistants can translate legacy syntax in seconds, yet 70%–88% of enterprise legacy modernization projects still fail. Why? Because syntax translation does not prove behavioral equivalence. A migrated PHP 5 payment handler can return the exact same HTTP 200 JSON receipt while silently inserting duplicate ledger rows into a database—or a Python 2 to Python 3 migration can subtly alter financial rounding rules (round(2.5) evaluating to 3 in Python 2 vs. 2 in Python 3).
We built NecroPatch to close this verification gap: a local-first software archaeology and verified resurrection workbench that captures a frozen behavioral baseline before modifying a single line of code, then proves parity across stdout/HTTP outputs, SQLite database rows, and live browser DOM interactions.
What it does
NecroPatch turns legacy modernization into an auditable, evidence-backed engineering workflow:
- Read-Only Polyglot Forensics (6 Languages): Imports local folders, archives, or pinned Git commits and parses Python, PHP, JavaScript, Java, Ruby, and C# using pinned Tree-sitter grammars. It builds a dependency graph (
resolved,possible, andunresolvededges), flags dead-code candidates, extracts source-linked business rules, and matches package manifests against OSV/CVE advisories while explicitly reporting coverage gaps. - Frozen Behavioral Baselines & Auto-Fixtures: Runs legacy code twice from a clean, reset state inside isolated Docker containers (
--network=none, read-only rootfs, resource limits) to eliminate nondeterministic noise and freeze a SHA-256-bound baseline. Includes an Auto-Fixture Generator that synthesizes nominal and edge-case test inputs directly from Tree-sitter AST branches and SQLite schemas. - Multi-Language Resurrection & Bounded AI Repair (6 Live Targets):
- PHP 5.6 → PHP 8.4 (plus FastAPI gateway target): Catches duplicate SQLite ledger postings hidden behind identical HTTP receipts (
0 == "posted"loose comparison drift). - Python 2.7 → Python 3.13 (plus FastAPI gateway target): Catches positive/negative integer division and banker's rounding regressions (
Decimal.quantize(ROUND_HALF_UP)). - Legacy JS/jQuery → TypeScript: Serves both versions in isolated Playwright Chromium contexts, catching duplicate form submissions even when visual confirmation messages match.
- Ruby 2.7 → Ruby 3.3: Full CLI JSON observation and migration path.
- Combines deterministic AST recipes with a bounded 3-attempt Multi-Provider AI Repair Agent (OpenRouter, Anthropic, OpenAI, Gemini, Ollama) governed by strict anti-tampering locks so repair models can never alter the frozen baseline oracle.
- PHP 5.6 → PHP 8.4 (plus FastAPI gateway target): Catches duplicate SQLite ledger postings hidden behind identical HTTP receipts (
- Topological Multi-File Migration & Strangler Fig Proxy: Migrates interdependent files wave-by-wave from leaf dependencies to entry points and exports a production-ready Strangler Fig Shadow Traffic Proxy (
nginx.conf+shadow_proxy.py+docker-compose.strangler.yml) alongside automated GitHub PR autopsy reports. - Standalone Reproducible Exports: Exports a self-contained ZIP containing the legacy snapshot, candidate attempts, SHA-256
evidence.json, a standalonereplay.pyrunner, and a generated.kiro/specs/migration-plan/bundle.
How we built it
- Core Engine & Control Plane: Python 3, FastAPI, SQLite (WAL mode with content-addressed SHA-256 artifacts), Tree-sitter, and an enforceable
AnalysisProvider/RuntimeProviderplugin registry. - Isolated Workers: Ephemeral Docker containers for Python, PHP, Ruby, and FastAPI gateways, paired with a headless Playwright Chromium worker for jQuery-to-TypeScript behavioral diffing.
- Frontend Workbench: React, TypeScript, and Vite featuring a surgical, Linear-inspired forensic interface with side-by-side source diffs, SQLite row comparisons, and Light/Dark themes.
How We Used Kiro
Kiro was central both to how NecroPatch was built and how NecroPatch integrates into developer workflows:
- Spec-Driven Development (
.kiro/specs/necropatch/): All 17 core requirements (R1–R17), architectural invariants, and implementation tasks were authored inrequirements.md,design.md, andtasks.mdwith linked verification records before implementation. - Steering & Agent Hooks (
.kiro/steering/&.kiro/hooks/): Persistent steering enforced our strict verdict taxonomy (matched,divergent,insufficient evidence) and exact decimal money comparisons, whilePostFileSavehooks automatically triggeredpytestcontract checks and spec evidence synchronization. - Native MCP Server (
necropatch/mcp.py&.kiro/settings/mcp.json): NecroPatch exposes 5 stdio MCP tools (providers,projects,analyze,verify,evidence), allowing developers inside Kiro IDE to inspect legacy repositories and trigger verified migrations directly from their agent chat.
Challenges we ran into
- Nondeterminism & State Isolation: Comparing legacy and modern runs fails immediately if timestamps, process IDs, or leftover SQLite rows bleed between runs. We solved this by cloning clean SQLite fixtures per execution, pinning environment locales/timezones, and applying explicit comparison masks.
- LLM Patch Format Mismatches: When testing our live AI repair loop against OpenRouter (
nvidia/nemotron-3-ultra-550b-a55b:free), the model accurately diagnosed Python 3's banker's rounding shift (round(2.5)) but returned file patches as a dictionary rather than a list. Discovering this live forced us to harden our multi-provider prompt schema and accept both structures under identical path/size safety checks. - Docker Socket & Worker Security: Running untrusted legacy repositories safely required strict worker isolation (
--network=none, non-root users, CPU/memory/timeout limits) and an honestinsufficient evidencefallback whenever a historical runtime is unavailable.
Accomplishments that we're proud of
- 57/57 Automated Tests Passing across real Docker containers, Playwright Chromium, SQLite state observers, single-file plugin extensibility, and live OpenRouter LLM repair.
- Zero-Trust Extensibility: Adding a new runtime adapter takes a single plugin file in a trusted directory without modifying the UI, CLI, database, or MCP server—verified by our fourth-adapter acceptance test.
- End-to-End Reproducibility: Every exported ZIP includes
replay.pyso any engineer can independently re-verify behavioral parity outside the UI.
What we learned
- Syntax Is the Easy Part; Oracles Are Hard: LLMs excel at idiomatic translation, but deterministic behavioral baselines (capturing database side effects and browser network calls) are essential to prevent silent regressions.
- Spec-Driven Agent Workflows Scale: Keeping
.kiro/specs/and automatedPostFileSavehooks synchronized prevented architectural drift across 6 analysis languages, 6 live runtime targets, and 3 user surfaces (Web UI, CLI, and MCP).
What's next for NecroPatch
- Expanding live runtime workers to Java (8 → 21) and .NET Framework → .NET 9 (already supported by our Tree-sitter static scanner).
- Deploying a multi-tenant cloud sandbox powered by Firecracker microVMs for zero-setup browser trials.
- Streaming live production shadow-traffic telemetry from the Strangler Fig proxy directly into the workbench.
Built With
- docker
- fastapi
- javascript
- kiro
- mcp
- nginx
- openrouter
- php
- playwright
- python
- react
- ruby
- sqlite
- tree-sitter
- typescript
- vite