How I Used Kiro Specs, Steering, and Hooks to Stitch Excel to the Z3 Theorem Prover (ProofSheet — Kiroween 2026)

2026-12-05来源 dev.toEnglish

This post is being written as part of the **Kiroween 2026 hackathon* (Kiroween Hackathon 2026).*

Every quarter, RevOps and deal-desk teams ship updated Excel pricing workbooks after spot-checking five or ten sample deals. Everything looks fine — until a real customer hits an edge-case combination of seat tier, annual billing, and referral stacking that quietly blows past a discount cap or sells below gross-margin floor.

Most modern tools try to audit spreadsheets by pasting formulas into an LLM and hoping it does the math right. For the Frankenstein category at Kiroween 2026, I built ProofSheet by Aletric using the opposite philosophy: stitch the world's most ubiquitous business tool (Microsoft Excel .xlsx) directly to a formal theorem prover (Microsoft Z3 SMT solver), so pricing policies are mathematically proven rather than guessed.

Why Formal Verification Needs Guardrails (And How Kiro Changed My Workflow)

Building a compiler from Excel formulas to Z3 SMT constraints is unforgiving. One floating-point rounding shortcut, one missed division-by-zero branch, or one dropped timeout check can turn a formal verifier into a silent false pass — which is worse than having no verifier at all.

Using Kiro changed how I approached building this from day one. Instead of vibe-coding features and hoping tests would catch architectural drift later, I used four Kiro primitives together:

1. Spec-Driven Design Before Code (.kiro/specs/excel-z3-compiler/)

Before writing the compiler, I locked down requirements.md, design.md, and checkbox tasks.md in Kiro. The spec fixed the exact pricing domain (1 to 5,000 seats, annual billing, referral — 20,000 discrete deals), exact rational representation (cents and basis points), and strict verdict semantics:

  • Violation found (with a downloadable *_witness.xlsx workbook and a minimality proof when Z3 proves no smaller seat count breaks the rule)
  • Verified for the stated inputs (UNSAT across the entire declared domain)
  • Unable to verify (returned honestly on unsupported formulas, circular references, or solver timeouts — never a false pass)

2. File-Scoped Steering Rules (.kiro/steering/z3-safety.md)

My favorite Kiro feature on this build was file-scoped steering. Alongside product.md (always included) and tech.md, I created .kiro/steering/z3-safety.md scoped specifically to backend/compiler/**/*.py. Every time an agent touched compiler code, Kiro automatically enforced four non-negotiable invariants:

  1. Exact rational arithmetic only (no IEEE-754 float drift on boundary thresholds like 40.0% or 20.0%).
  2. A domain-satisfiability pre-check before every policy proof.
  3. A 3-second solver timeout mapped cleanly to Unable to verify.
  4. Explicit definedness tracking for division-by-zero hazards (catching =100/(B4-250) failing at 250 seats in cell B24).

3. Automated Verdict Smoke Hook (.kiro/hooks/proofsheet-verdict-smoke.json)

To make sure no refactor quietly broke an existing verdict, I wired a PostTaskExec Kiro hook that automatically runs test_verdict_matrix.py and test_unable.py after task execution. If a change alters any verdict across the three revisions (original, cap-only, repaired) or breaks an Unable to verify case, it fails immediately.

4. Parallel Subagents with Disjoint File Ownership

Once the spec and contracts were locked, I split independent modules across parallel agents — separating the workbook loader from the formula parser, and later splitting the FastAPI backend (backend/web/), React/Vite UI (frontend/), deployment setup (Dockerfile), and regression test suites with clean file ownership.

A Real Bug Kiro's Spec Process Caught

Midway through the build, we hit a subtle formal-methods edge case: what if Z3 finds a valid violating deal (SAT) quickly, but times out on the follow-up query trying to prove minimality? A naive wrapper would discard the counterexample and return Unable to verify.

We revised the spec and compiler so a valid counterexample is never lost — ProofSheet still returns the violating deal, explicitly labeling it "Counterexample (minimality not proven)" instead of "Proven minimal deal", backed by dedicated regression tests in backend/tests/test_verify_minimization.py.

What Shipped

By submission time, ProofSheet shipped as a single Dockerized FastAPI + React/TypeScript web app live at proofsheet.aletric.com with:

  • Interactive cell-chain trace showing the exact failing deal (101 seats, annual billing, referral -> $55.00 quote, 45.0% discount, 11.2% margin on original; 18.6% margin still failing on cap-only; both policies proven on repaired).
  • Expandable Z3 SMT-LIB v2 proof drawers with one-click copy so anyone can replay both the counterexample query and the minimality proof in a fresh Z3 solver.
  • Downloadable witness .xlsx workbooks with the failing deal pre-filled, ready to inspect in Excel.
  • 1,002 passing backend tests (0 failed, 0 skipped — including Hypothesis property-based tests against an independent exact-arithmetic oracle and LibreOffice Calc replay) plus 6 frontend unit tests and 5 Playwright E2E tests.

What's Next

Next for ProofSheet at Aletric: CEGIS Auto-Heal (where an LLM proposes formula repairs while Z3 proves the fix satisfies every policy and preserves existing compliant deal prices), natural-language rule translation with human confirmation, and a Z3 MCP server.

Try it live at https://proofsheet.aletric.com — and check out the full .kiro/ folder and build log in the GitHub repo.

KiroweenHackathon26 #Kiroween #Kiro #Z3 #FormalVerification

原文:https://www.a8q9.cn/en/article/how-i-used-kiro-specs-steering-and-hooks-to-stitch-excel-to-the-z3-theorem-prove-4436d9.html

相关文章