DEV Community

LeDenti
LeDenti

Posted on Fully Autonomous

Ferret: a rule engine with a mood, built spec-first in Kiro

Written for the Kiroween 2026 hackathon (Frankenstein category). Demo: youtu.be/YyhL1DaMjWk · App, play money: ferret-amw8.onrender.com · Code, MIT, .kiro included: github.com/LeDenti/ferret

Lending rules are fixed. But after a default, a good lender gets more careful. I wanted a program that does the same thing without ever touching its rules. That program is Ferret, and this is how Kiro helped build it, including the parts that did not go smoothly.

The idea: a mood that scales, never decides

Ferret guards a small pool of play money that advances cash on invoices. Every request goes through twelve checks in a fixed order: duplicate invoice, analysis present, amounts, term, advance rate, concentration per debtor, absolute cap, liquidity. Each answer is a yes or a no with a stable reason, written to a field log.

On top of that sits a mood. A refused concentration or a default raises its stress; repayments and buybacks lower it; time makes it forget. The mood is calm, wary or feral. In the demo, one default takes the share a single debtor may hold from 30 % down to 25.5 %, and the longest term from 90 days down to 77. A 90-day invoice that a calm ferret would accept is now refused.

The one rule that matters: the mood changes the ceilings, never the rules. It never removes a check and never changes their order. It only scales two numbers.

The mechanism is borrowed from our research project XRPLife, where a model of the worm C. elegans runs on a public ledger. In that model, serotonin changes how much activity flows through the network, never which connections carry it. Ferret transposes that one idea to a rule book. It is a model, not a living worm, and no code from that project is reused.

Steering before anything else

The first thing Kiro wrote was not code but three steering files: product, tech and structure. They fixed the non-negotiables:

  • integer arithmetic only, no floating point anywhere near money;
  • zero runtime dependencies;
  • the reference/ folder is read-only for the agent;
  • the replay of the case file is the central test.

Writing these first paid off every time the agent was tempted to "help" by adding a library or touching the judge.

Four specs, 51 requirements

Ferret has four specs in .kiro/specs: mood (11 EARS requirements), invoice-pool (14, the twelve checks in their exact order), server (13) and field-log-ui (13). Each went requirements first, then design, then tasks, and only then code.

EARS forced precision where my notes were vague. A line straight from the invoice-pool spec, "WHEN deposit(lender, amount) is requested THE SYSTEM SHALL refuse with family zero_amount if amount ≤ 0", leaves no room for interpretation, and it maps one-to-one to a test.

A judge Kiro did not write

The part I am proudest of is not in Kiro at all, and that is the point. Before the engine existed, a Python reference implementation was written separately. It generated 120 scenarios, 4,926 random events in all, with the expected decision and the expected state after each one.

Kiro then wrote the TypeScript engine from the design. The first replay of the 4,926 events against it: zero mismatch.

Then something better happened. Four of the unit tests Kiro had written alongside the engine failed. The judge settled it in one command: the engine was right, the four tests were wrong about their own expectations. Without an independent judge, I would have "fixed" a correct engine to match wrong tests.

MCP: let the agent ask the judge

The judge is also exposed as an MCP server (.kiro/settings/mcp.json, tool replay_events). Instead of guessing what should happen after a deposit and an oversized advance, Kiro can ask. During the build it did exactly that, and got back "refuse, concentration_breached" with the effective ceilings.

Hooks and a reviewer agent

Three hooks in .kiro/hooks: run the tests whenever the engine changes, revert any edit under reference/, and keep the specs in sync with the code. A custom agent, immunologist, reviews changes for the three things that would quietly break Ferret: floating-point arithmetic, the mood reaching beyond the ceilings, and imports pointing the wrong way.

What did not go smoothly

  • The free tier is small. 50 credits a month, and a fifteen-minute throttle after a burst of large reads. The fix was discipline: short prompts, small read lists, one spec at a time, and never letting the agent open the 4 MB case file.
  • Non-interactive mode drafts in chat. Kiro CLI wrote nothing to disk until told, in so many words, to write to disk.
  • The UI needed three fixes after the first pass: a wrong operation name, a superfluous amount on withdrawals, and silent 400 errors. All three were caught by clicking through the app, not by the replay, which only covers the engine.

How I worked, disclosed

I did not drive Kiro by hand. On my instruction, an AI assistant (Claude Code) wrote the prompts to Kiro CLI, ran the tests between calls and committed the results. Kiro produced the code, the judge checked it, and I decided the scope, the rules and what to disclose. The README says the same.

What I take away

Spec mode is worth its cost when the spec is a contract with a judge. Requirements become tests, and a differential replay against an independent implementation ends every argument in one command. Vibe coding would have produced an engine faster, and left me unable to say why it was right.

Next for Ferret: two more "burrows" on the same engine, pay by evidence and a conditional escrow.

matter-x- · Kiroween 2026

Top comments (0)