Inspiration

AI agents act like a haunted house: something happens, you can't see why, and running it again gives a different result. That makes them hard to trust anywhere a decision matters: pricing, support, games, operations. We wanted agents whose every decision can be replayed exactly and questioned with "what if?".

What it does

Hauntrace is for developers who ship automated decisions they may later have to explain: pricing, support triage, or game logic. You can run the engine as a function, an HTTP endpoint, or an LLM tool: the model proposes an action, the rules decide, and the trace flags every place the rules overruled the model. The two demo apps use labelled EXAMPLE data so a run can be replayed exactly; the Séance viewer is the product surface, a static page with no login and no network calls, including on an iPad.

Hauntrace is a lean skeleton for deterministic, explainable agents. You define typed state, observations, ordered rules and a fallback. A seeded RNG and an injected clock make runs reproducible, and each step leaves a "ghost": a hash-chained record of the input, the rule that fired, the reason, and the state before and after.

  • Replay re-runs a trace and confirms it matches exactly.
  • verifyChain detects any tampered step.
  • What-if changes inputs and shows which decisions would differ.
  • Adapters: export/import trace files, an HTTP endpoint, and an LLM tool adapter where a model proposes an action and the rules decide, flagging every place the rules overruled the model.

The distinctive idea is not only replay: a deterministic rule layer can overrule a model, and every decision is left in a hash-chained, tamper-evident ghost that you can what-if and explain in the browser with no server.

Two distinct apps run on the same skeleton:

  1. Short-let pricing (apps/shortlet-pricing): nightly prices from rules like last-minute, weekend, high demand and event surge, on example data.
  2. Haunted innkeeper NPC (apps/haunted-npc): a ghost innkeeper whose dialogue, mood and trust are rule-driven and seeded. Ask "what if the player had brought the lantern?" and watch her answers change.

The Séance viewer is a static web app that loads any exported trace (or the bundled examples): a step timeline, step detail, a hash-chain verified/broken badge, and a what-if ghost diff that re-runs the real rules in the browser. No network calls, no analytics, built to work on an iPad. New in the latest version:

  • Live what-if editor ("Haunt this step"): edit any step's observation as JSON, and the real agent re-runs in your browser; the page shows exactly which later decisions change (e.g. move the innkeeper's step 3 from 1 AM to 9 AM and the midnight dread never comes).
  • Tamper mode: rewrite one step's recorded reason without re-hashing it and watch the chain break at that step, with every later step marked "haunted"; Exorcise restores the original and the chain verifies again.
  • Share links + "Explain this run": one click copies a link that carries the exact run in the URL (no server), and "Explain this run" tells the whole trace as a plain-English story: which rule fired at each step, why, and whether the hash chain holds.

How we built it

We built Hauntrace with the Kiro CLI (v2.36.0, free plan), in short non-interactive sessions run from the repo root so Kiro loaded the project's steering and specs. We did not use the Kiro IDE, Kiro Web, or Kiro Crew, and we did not add custom agents, MCP servers, or Kiro powers. The .kiro/ directory is in the public repo and is not gitignored. KIRO_USAGE.md logs every session and any hand edits.

Steering (.kiro/steering/). Three always-on files: product.md (Skeleton Crew: one lean skeleton, two distinct apps; spooky naming is welcome in the UI, the core API stays plain), tech.md (TypeScript plus the non-negotiable determinism rules: no Date.now(), no bare new Date(), no Math.random(), and no hidden network, filesystem or env reads; time comes from an injected Clock and randomness from a seeded Rng), and structure.md (apps depend only on packages/core). The strategy that made the biggest difference was putting those determinism rules in steering, not only in a spec. Every later Kiro session stayed inside them, and both agent hooks tell Kiro to explain a failing test against .kiro/steering/tech.md.

Specs (.kiro/specs/). Six specs, each with requirements, design and tasks (51 tasks in total): core-engine, shortlet-pricing, haunted-npc, live-whatif-editor, tamper-mode and share-explain. After a small initial scaffold, we asked Kiro to implement one spec task at a time, each on its own branch and reviewed pull request, with tests. For the haunted innkeeper and the three newest viewer features, Kiro wrote the spec first, then the code and tests. Compared with vibe coding, writing the spec first made Kiro's output much more predictable, and small focused prompts worked better than large ones.

Hooks (.kiro/hooks/). Two hooks fire when packages//*.ts or apps//*.ts are edited. "Determinism tests on save" asks the agent to run npm test and, if anything fails, explain which determinism rule in tech.md was broken. "Regenerate sample traces on save" (sample-traces-replay) asks the agent to run npm run regen:traces, which rebuilds both bundled example traces, then confirm they still pass verifyChain and replay, so the samples cannot silently drift from the rules.

Property-based tests. fast-check locks the core invariants that a single example can miss: same seed and inputs produce the same head hash; every run replays exactly; an identity what-if yields no diffs; export/import round-trips preserve the head hash for arbitrary observations; explain text is deterministic; and the haunted-NPC agent stays deterministic across random observation sequences. The viewer has seeded property-style tests as well (fast-check is not a viewer dependency). We do not claim PBT uniquely found a production bug; it is how we enforce the determinism contract.

Honest provenance. The initial scaffold (core tasks 1–5 and the short-let demo) was written outside Kiro, following the Kiro steering and specs. Everything after that was built by Kiro. Hand edits were limited to docs and one demo:npc npm script line (Kiro created cli.ts but not the script).

Where Kiro surprised us. An early what-if implementation only patched inputs and never re-ran the rules, so every scenario showed "no change." Review caught it; Kiro then built a real in-browser agent runner (viewer/src/agentRunner.ts) so what-if shows actual decision changes — for example, giving the player the lantern changes step 1 of the innkeeper, and removing local events changes the short-let surge. In a later session a seeded live-editor test failed, and Kiro diagnosed the real cause: the test had deleted an optional field that the strict validator treats as required, then fixed the test. Kiro also caught that the NPC trace generator was writing under dist/, which would have left the new sample-traces hook copying a stale file, and pointed the generators at the real source paths.

Challenges we ran into

  • Keeping everything truly deterministic: no hidden clock or randomness anywhere, so replay matches byte for byte.
  • Making the viewer's what-if re-run real agent rules in the browser. An early version only patched inputs and never re-ran the rules, so every scenario showed "no change". Review caught it and Kiro fixed it.
  • Kiro CLI service throttling cut off a few long sessions; we waited and resumed with short "continue" prompts.
  • Making raw trace data readable on an iPad screen.

Accomplishments that we're proud of

  • One skeleton, two genuinely different apps: pricing and a game NPC.
  • Tamper-evident, replayable traces with live what-if editing, a tamper demo, share links and plain-English explanations, all in a browser with no server.
  • 464 passing tests at the time of writing, including property-based determinism tests across the engine, both apps and the viewer.
  • A transparent record of how Kiro was used, including what wasn't Kiro.

What we learned

Writing the spec before the code made Kiro's output much more predictable, and small focused prompts worked better than big ones. Determinism is a design choice you make up front: inject the clock and the RNG and almost everything else gets easier to test.

What's next for Hauntrace

More demo apps (e.g. support ticket triage), a trace diff between two real runs, publishing the core as an npm package, and an MCP server so agents can call Hauntrace as a tool.

Built With

Share this project:

Updates

Submission history