Kitsune Blocks Your Coding Agent, Then Hands It a Map

A finite state machine that enforces agent behavior at the tool layer, where prompts cannot be ignored. The idea is sharper than the code, and the code is worth reading anyway.

9 min read • View on GitHub • More from sagnik3788

A wide editorial illustration of a workshop floor with a single heavy brass turnstile gate at center. A robotic arm reaches toward a rack of tools (a wrench, a soldering iron, a hammer) while the turnstile arm is down, and the robot's other arm reaches up to take a small printed card hanging from a wire. Three more turnstile stations recede into the distance, all raised. The illustration explains how Kitsune stops a tool call at the gate but offers the agent a card that shows the way through.
The gate blocks the tool. The card is the way through. Kitsune refuses the out-of-phase call and hands the agent the exact trigger that advances it.
Key Takeaways

The Call That Does Not Go Through

An agent in the PLAN phase decides it has seen enough and reaches for the editor. It calls edit("src/app.py"). Kitsune refuses. Not with an exception, not with a bare "permission denied," but with a structured object that tells the agent exactly where it stands.

{
    "allowed": False,
    "reason": "Tool 'edit' is not allowed in phase 'plan'",
    "current_phase": "plan",
    "next_phase": None,
    "available_tools": ["read", "grep", "glob"],
    "available_transitions": ["READY"],
    "message": "\U0001F98A [Kitsune] Blocked: 'edit' is not available in PLAN.\n"
               "Available tools: read, grep, glob.\n"
               "To advance: call kitsune_transition with trigger: READY",
}

The return is not a boolean. It is a small report: whether the call is allowed, why, which phase the session is in, which tools are open right now, and which triggers will move it forward. The README's check description still reads check(phase, tool, workflow) -> bool, which is out of date. The real function takes a context argument and returns this dict. That shift, from a yes or no to a map, is the whole design.

The Denial Is the Feature

Every denial path in engine.py ends the same way. It appends a hint to the message: "To advance: call kitsune_transition with trigger: READY, ...". A blocked agent is told what it can do now and the exact trigger that unlocks the next step.

An extreme close-up editorial illustration of two hands at the moment of a handoff. A mechanical hand has just been stopped by a thin vertical bar drawn with dense vertical hatching, and a second hand is pressing a small rectangular card with three short ruled lines into the stopped hand's grip. The image explains how Kitsune turns a denial into a message that is physically handed to the agent rather than a wall it hits.
The message is not a wall. It is an object being handed over: what is allowed now, and the trigger that moves the session forward.

A bare denial is a wall. The agent, having no information, tends to retry variations of the same call, burn turns, and drift. Kitsune's denial is a waypoint. The agent reads the available transitions, calls kitsune_transition with the right trigger, and continues. The redirect costs one tool call instead of a guessing loop.

This is the part nobody leads with, and it is the most careful piece of agent UX in the repo. Enforcement is easy to get wrong in the direction of hostility. Kitsune chose to be helpful about it.

Four Steps, Then Allow

When a tool call arrives, engine.check() runs a fixed sequence. The order is the policy.

  1. Tool whitelist. tool.lower() is compared against the phase's tools, lowercased. Matching is case-insensitive.
  2. Phase-wide guards. Every Guard on the phase is evaluated against the session context.
  3. Per-tool guards. phase.tool_guards is keyed by tool name, again matched case-insensitively.
  4. Default allow. If nothing above objects, the call goes through.

The evaluation order is the policy. A tool call walks four checks and falls through to allow by default, so the burden is on the workflow author. Click the chip to cycle presets and hover a stage to see the code that runs there.

Step four is the surprising one. The engine does not decide what is safe. It decides what the workflow author has forbidden. The burden sits with whoever wrote the YAML, not with the runtime. That inversion is the reason the tool is small, and the reason a sloppy workflow is a sloppy guardrail.

The bridge between runtime state and these rules is build_context. It packs turn_count, every counter (keyed by tool name, so edit_count appears after the first edit), files_touched_count, the files_touched list, and the raw args into one dict. Guards read from it by field name.

There is a limitation worth knowing. eval_guard calls context.get(guard.field), so it does not walk dotted paths. A guard cannot reach into args.path directly; the author has to flatten what they need into the context first. The README's "Bash discernment" and "Edit limits" ideas would both have to work around this.

Also in eval_guard: a missing numeric field is coerced to 0, so edit_count < 20 passes on a fresh session with no setup. Convenient, and a footgun. A typo in a field name silently becomes zero, and the guard passes.

What the README Promises and the Engine Delivers

The README sells two headline guardrails: turn limits and edit limits. The code does not enforce either one as written.

README claimCode realityEvidence
Turn limits (<code>max_turns: 8</code>)Field commented out in <code>Phase</code>; Pydantic drops unknown YAML keys silently<code>schema.py</code>, <code>engine.py</code>
Edit limits (<code>max_edits: 20</code>)<code>edit_count</code> counter exists, no workflow-level cap wired to it<code>gateway.py</code>, <code>schema.py</code>
Bash discernment (<code>commands: [pytest, ...]</code>)<code>commands</code> declared on <code>Phase</code>, never read by <code>engine.py</code><code>engine.py</code>
Approval gates (<code>requires_approval</code>)Field exists, no enforcement path<code>schema.py</code>
Tool whitelisting per phaseWorks. Case-insensitive, checked first<code>engine.py</code>

The mechanism is that Pydantic ignores unknown fields by default. The README's example YAML sets max_turns: 8 and max_edits: 20, but those fields are commented out in the Phase model, so the parser drops them without a warning. Turn counting does exist (increment_turn, turn_count), but the workflow-level cap is not wired to anything visible.

commands is declared on Phase and never read by engine.py. requires_approval, blocked_env, and env_overrides exist in the schema and have no enforcement path. The README's own example would not do what it claims.

The important row is the last one. Per-phase tool whitelisting works, exactly as described, case-insensitively, checked first. The core mechanism is real. The gap is in the advertised extras, and it reads like a project that shipped the hard part and left the easy parts as promises.

There is also comment drift. schema.py and the README both reference Turso, while db.py talks to Postgres through asyncpg and a POSTGRES_URL. The DDL uses TIMESTAMPTZ and CREATE INDEX IF NOT EXISTS, which are Postgres idioms. The data layer almost certainly migrated, and the comments did not follow. The README calls the dashboard a "Vanilla JS SPA." It is Vue 3.

Two Ways to Guardrail an Agent

There are two places to put a rule for an agent. In the prompt, or in the tool layer. They are not equivalent.

Prompt-level instructionTool-layer enforcement
The model can ignore it, soften it, or reinterpret itThe call returns False and never executes
Enforcement is probabilisticEnforcement is deterministic

A prompt is a suggestion the model weighs against everything else in its context. It can be softened, reinterpreted, or simply forgotten after enough turns. A function that returns False cannot be argued with. The call does not execute, full stop.

This is why Kitsune's approach is structurally stronger, and why it is a category rather than a product. Anything that sits between the agent and its tools and returns a verdict can do this. The interesting design question is not whether to enforce. It is what you return when you do. Kitsune's answer is the map.

A Solo Project With a Sharp Idea

What is verifiable about the project is its shape. It is a Python 3.12 backend (FastAPI plus FastMCP) with a TypeScript plugin for opencode, a Vue 3 dashboard, Redis for session state, Postgres for persistence, and Clerk for auth. The commit history is dominated by a single author.

The Redis TTL is worth flagging. Sessions are stored with setex(..., 3600, ...), and every save resets the clock. An active session stays alive. An agent that pauses for more than an hour loses its FSM state, and its next tool call fails with "session not found or expired." The Session model carries an expires_at field that is set but never read, because Redis owns expiry.

On the author: the web research turned up no interviews, announcements, or talks tied to this repository. Searches mostly surface four unrelated projects that share the name Kitsune. So the honest statement is that the project speaks for itself through its code, and the code is worth reading.