Writ sits between an AI coding agent and the file system. It pulls the
right rules from a knowledge graph in well under a
millisecond, then refuses to let the agent write code
until the user has approved a plan and tests. This page walks the
whole system end to end, switching diagram types to fit what each part
actually is.
5
retrieval stages, sub-millisecond p95
~30
bash hooks, 11 trigger types
12
knowledge-graph node types
4
session modes, 4 phase gates
3
authority levels in the rule ladder
Diagram 1 / Block diagram
What talks to what
Four layers: the agent at top, the hook scripts in the middle, the HTTP
service below them, and the persistent stores at the bottom. Hooks shell
out to a session helper and to the HTTP API; the API does the heavy
retrieval work over the graph and the two indexes.
How to read it. Solid arrows are runtime calls (the
hooks shell out to writ-session.py and curl the
HTTP API). Dashed arrows are offline data transfers: rule markdown gets
imported into Neo4j once, and exports flow back out when a rule is added
or edited.
Diagram 2 / Process flowchart
Session lifecycle: START to END
Classic process flowchart of one coding session. Rectangles are work,
diamonds are decisions, dashed pink arrows are iterate-until-it-passes
loops. The non-Work modes (Conversation, Debug, Review) skip past the
four phase gates.
Why a flowchart here. The session is a process: start
state, ordered steps, decision points, terminate state. Loop-back arrows
make the iterate-until-it-passes pattern visible. For the inside of one
RAG query, the sequence diagram below is the better idiom.
Diagram 3 / Sequence diagram
What happens when you press Enter
Time goes top to bottom. Each vertical lane is one actor. The whole
round trip, from user keypress to rules-in-context, finishes in roughly
the time it takes to run a single Python function.
Why a sequence diagram here. Six actors and a strict
message ordering. A flowchart would hide the fact that the API holds
open one request while the pipeline does three sub-queries in sequence.
Diagram 4 / Funnel
5-stage retrieval, candidates narrowing
A funnel: corpus on the left, the top few rules that land in the
agent's context on the right. Each stage drops candidates that do not
help, so by the end only the small bundle the agent actually needs
remains.
Why a funnel here. The pipeline is fundamentally a
narrowing process: lots in, few out. The flowchart and sequence diagrams
would not show the candidate-count compression that defines the design.
Diagram 5 / State machine
Modes and phases as a formal state machine
Top row: the four session modes. Bottom row: the four phase sub-states
that exist only inside Work mode. Each arrow is a legal transition.
Anything off this diagram is denied by a hook.
Why a state machine here. Modes and phases are
states with strict legal transitions. A flowchart would imply
a single linear path; a state diagram makes the legal/illegal edges
explicit, which is what the gate hooks actually enforce.
Diagram 6 / Graph view
The knowledge graph: not a flat list
A miniature view of the rule corpus as it actually lives in Neo4j.
One node per category, real edge types. The retrieval pipeline
walks these edges to find related rules when a single rule is hit.
Why a graph here. Because the knowledge base
is a graph. Edges carry meaning: a rule that TEACHES a skill
is different from a rule that COUNTERS an anti-pattern, and the
retrieval pipeline uses those edge types to expand a hit into the
bundle of rules that travel together.
Diagram 7 / Lifecycle
How a rule earns its weight
Rules do not just live in the corpus, they evolve. A proposal starts at
the bottom of the authority ladder and only earns higher confidence
after structural review, human approval, and finally empirical
observation in production.
Why a lifecycle here. Time matters and authority
matters. A flat box-and-arrow diagram would hide that "ai-provisional"
and "battle-tested" are not categories but stages a rule moves through,
with explicit thresholds and decision points between them.