Scroll right to follow the full flow →

START Session bootstrap SessionStart hook User submits UserPromptSubmit Inject rules 5-stage pipeline Mode? routing non-Work Respond directly no phase gates END Work Write plan.md Files/Analysis/Rules Plan approved? yes no: rewrite plan Write tests skeletons + assertions Tests approved? yes no: rewrite tests Write impl per-write RAG inject Run pending tests Stop hook runs them Tests pass? yes no: fix & rewrite Verify update capabilities.md Session end friction log + audit END

Background loops (run alongside the main flow)

Rule evolution

Proposal » gate » promotion

AI agents propose new rules. Every proposal passes a structural gate before reaching the graph. Humans promote keepers; frequency data battle-tests them over time.

  • Propose: writ propose or POST /propose. Authority forced to ai-provisional.
  • Structural gate: schema, specificity, mechanical enforcement path, redundancy (>= 0.95 cosine), conflicts.
  • Human review: writ review --promote moves authority to ai-promoted, confidence to peer-reviewed.
  • Frequency graduation: 50+ observations at 75%+ positive ratio replaces static confidence with empirical ratio.
Sub-agent dispatch

Orchestrator » worker » report

For non-trivial Work-mode tasks, the master dispatches to named worker sub-agents (writ-explorer, writ-planner, writ-test-writer, writ-implementer), each in an isolated Writ session.

  • Master sets mode set work <id> --orchestrator to suppress broad RAG in its own context.
  • SubagentStart hook tags worker with is_subagent: true; worker bypasses phase gates.
  • Each worker has its own RAG budget and rule injections.
  • Workers run in foreground; each phase is a hard dependency for the next.
Context compaction

Pre-compact » compact » post-compact

When the conversation outgrows the context window, Writ snapshots its rule state, lets compaction proceed, then restores critical rules into the post-compact context.

  • writ-precompact.sh persists the loaded_rule_ids snapshot.
  • clear-rules-for-compaction frees budget so the summary fits.
  • writ-postcompact.sh calls reset-after-compaction and re-injects mandatory rules.
  • Context-pressure tracking ensures RAG is skipped when the budget is near the limit.