-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathwrit-workflow-flowchart.html
More file actions
900 lines (830 loc) · 40.8 KB
/
Copy pathwrit-workflow-flowchart.html
File metadata and controls
900 lines (830 loc) · 40.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Writ End-to-End Workflow</title>
<style>
:root {
--bg: #f7f5f0;
--panel: #ffffff;
--panel-2: #fafaf7;
--ink: #1a1a1a;
--ink-soft: #4a4a4a;
--line: #d8d4cc;
--line-soft: #ebe7dd;
--blue: #0a4a7f;
--blue-soft: #e7f0f7;
--amber: #b45309;
--amber-soft: #fdf3e2;
--green: #047857;
--green-soft: #e6f4ee;
--purple: #6d28d9;
--purple-soft: #f0e9fc;
--pink: #be185d;
--pink-soft: #fce7f0;
--gray: #4a4a4a;
--gray-soft: #f1f1ef;
--shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.05);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
margin: 0; background: var(--bg); color: var(--ink);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
"Helvetica Neue", Arial, sans-serif;
line-height: 1.5;
-webkit-font-smoothing: antialiased;
}
/* === SHARED TOP NAV === */
.topnav {
position: sticky; top: 0; z-index: 50;
background: rgba(247, 245, 240, 0.92);
backdrop-filter: saturate(140%) blur(8px);
-webkit-backdrop-filter: saturate(140%) blur(8px);
border-bottom: 1px solid var(--line);
}
.topnav-inner {
max-width: 1280px; margin: 0 auto; padding: 11px 24px;
display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}
.topnav-brand {
font-weight: 700; font-size: 15px; letter-spacing: 0.04em;
color: var(--ink); text-decoration: none;
}
.topnav-brand .dot { color: var(--blue); margin-right: 4px; }
.topnav ul {
display: flex; gap: 4px; list-style: none; padding: 0; margin: 0; flex-wrap: wrap;
}
.topnav a {
display: inline-block; padding: 6px 12px; border-radius: 999px;
font-size: 13px; color: var(--ink-soft); text-decoration: none;
border: 1px solid transparent; transition: background 120ms, color 120ms, border-color 120ms;
}
.topnav a:hover { color: var(--ink); border-color: var(--line); background: var(--panel); }
.topnav a.active { background: var(--blue); color: white; border-color: var(--blue); }
/* === /SHARED TOP NAV === */
.wrap { max-width: 1480px; margin: 0 auto; padding: 28px 24px 60px; }
/* Two-column layout */
.layout {
display: grid;
grid-template-columns: 360px minmax(0, 1fr);
gap: 28px;
align-items: start;
}
.left-col {
position: sticky;
top: 64px;
max-height: calc(100vh - 84px);
overflow-y: auto;
padding-right: 6px;
}
.right-col { min-width: 0; }
@media (max-width: 1000px) {
.layout { grid-template-columns: 1fr; }
.left-col { position: static; max-height: none; overflow: visible; padding-right: 0; }
}
/* Hero (in left column) */
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 0.12em;
text-transform: uppercase; color: var(--blue); }
h1 { font-size: 28px; line-height: 1.12; margin: 8px 0 12px; font-weight: 700; }
.pitch { font-size: 14.5px; color: var(--ink-soft); margin: 0 0 14px; }
.pitch strong { color: var(--ink); }
.legend {
display: flex; flex-direction: column; gap: 6px;
margin: 0 0 16px;
font-size: 12.5px; color: var(--ink-soft);
}
.legend-item { display: inline-flex; align-items: center; gap: 8px; }
.legend-swatch {
width: 22px; height: 14px;
border: 2px solid var(--blue);
background: var(--panel);
border-radius: 3px;
}
.legend-swatch.diamond {
width: 14px; height: 14px;
background: var(--amber-soft);
border-color: var(--amber);
transform: rotate(45deg);
border-radius: 2px;
}
.legend-swatch.terminus {
border-radius: 999px;
background: var(--blue);
border-color: var(--blue);
}
.legend-swatch.loop {
border-style: dashed;
border-color: var(--pink);
background: transparent;
}
/* Detail panel (in left column, updates on node click) */
.detail-shell {
background: var(--panel);
border: 1px solid var(--line);
border-radius: 12px;
padding: 16px 18px;
box-shadow: var(--shadow);
min-height: 200px;
}
.detail-shell .empty {
color: var(--ink-soft); font-size: 13.5px; text-align: center;
padding: 22px 0;
}
.detail-panel { display: none; }
.detail-panel.active { display: block; }
.detail-head {
display: flex; align-items: baseline; gap: 12px;
margin-bottom: 4px; flex-wrap: wrap;
}
.detail-step {
font-size: 10.5px; font-weight: 700;
letter-spacing: 0.08em; text-transform: uppercase;
color: var(--blue);
}
.detail-step.work { color: var(--purple); }
.detail-step.gray { color: var(--gray); }
.detail-step.amber { color: var(--amber); }
.detail-step.green { color: var(--green); }
.detail-title { margin: 0 0 6px; font-size: 17px; font-weight: 700; }
.detail-summary { margin: 0 0 10px; font-size: 13.5px; color: var(--ink-soft); }
.detail-body h4 {
margin: 10px 0 4px; font-size: 11px;
text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft);
}
.detail-body h4:first-child { margin-top: 0; }
.detail-body ul { margin: 0; padding-left: 18px; }
.detail-body li { margin-bottom: 4px; font-size: 13px; }
.detail-body code {
background: var(--panel-2);
border: 1px solid var(--line-soft);
border-radius: 4px;
padding: 1px 5px;
font-family: "SF Mono", Menlo, Consolas, monospace;
font-size: 11.5px;
}
.answers { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 0; }
.answer-pill {
border: 1px solid var(--line); background: var(--panel-2);
border-radius: 999px; padding: 3px 9px; font-size: 11.5px;
}
.answer-pill.green { border-color: var(--green); color: var(--green); background: var(--green-soft); }
.answer-pill.pink { border-color: var(--pink); color: var(--pink); background: var(--pink-soft); }
/* Right column: chart + loops */
.chart-scroll {
background: var(--panel);
border: 1px solid var(--line);
border-radius: 14px;
padding: 16px;
box-shadow: var(--shadow);
overflow-x: auto;
overflow-y: hidden;
margin-bottom: 24px;
}
.chart-scroll-hint {
font-size: 12px; color: var(--ink-soft); margin: 0 0 10px;
font-style: italic;
}
.chart-scroll svg {
display: block;
min-width: 2440px;
width: 2440px;
height: auto;
}
/* SVG node styles */
.node { cursor: pointer; }
.node rect, .node polygon, .node ellipse {
transition: filter 140ms ease, stroke-width 140ms ease;
}
.node:hover rect,
.node:hover polygon,
.node:hover ellipse {
filter: drop-shadow(0 2px 6px rgba(0,0,0,0.18));
stroke-width: 3px;
}
.node.selected rect,
.node.selected polygon,
.node.selected ellipse {
stroke-width: 4px;
filter: drop-shadow(0 3px 8px rgba(0,0,0,0.22));
}
.node text { pointer-events: none; }
.node-process rect { fill: var(--panel); stroke: var(--blue); stroke-width: 2; }
.node-process.work rect { stroke: var(--purple); fill: #faf7ff; }
.node-decision polygon { fill: var(--amber-soft); stroke: var(--amber); stroke-width: 2; }
.node-decision.tests polygon { fill: var(--green-soft); stroke: var(--green); }
.node-terminus ellipse { fill: var(--blue); stroke: var(--blue); stroke-width: 2; }
.node-terminus.gray ellipse { fill: var(--gray); stroke: var(--gray); }
.node-side rect { fill: var(--blue-soft); stroke: var(--blue); stroke-width: 2; }
.arr { stroke: #1a1a1a; stroke-width: 2; fill: none; }
.arr-loop { stroke: var(--pink); stroke-width: 2; stroke-dasharray: 6 4; fill: none; }
.label-on-arrow {
fill: var(--gray); font-size: 12px; font-weight: 600;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.node-text {
fill: var(--ink); font-size: 13px; text-anchor: middle; dominant-baseline: central;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.node-text.bold { font-weight: 600; font-size: 13px; }
.node-text.white { fill: white; font-weight: 700; }
.node-text.small { font-size: 11px; fill: var(--ink-soft); }
/* Loops side cards */
.loops {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 14px;
}
@media (max-width: 1100px) {
.loops { grid-template-columns: 1fr; }
}
.loop-card {
background: var(--panel);
border: 1px solid var(--line);
border-radius: 12px;
padding: 14px 16px;
box-shadow: var(--shadow);
cursor: pointer;
transition: border-color 140ms ease, transform 120ms ease;
}
.loop-card:hover { border-color: var(--amber); transform: translateY(-1px); }
.loop-card.open { border-color: var(--amber); cursor: default; }
.loop-card h3 { margin: 6px 0 6px; font-size: 14px; font-weight: 600; }
.loop-card p { margin: 0; font-size: 13px; color: var(--ink-soft); }
.loop-tag {
font-size: 10.5px; font-weight: 600;
text-transform: uppercase; letter-spacing: 0.06em;
padding: 2px 8px; border-radius: 999px;
background: var(--amber-soft); color: var(--amber);
display: inline-block;
}
.loop-tag.pink { background: var(--pink-soft); color: var(--pink); }
.loop-tag.gray { background: var(--gray-soft); color: var(--gray); }
.loop-detail {
display: none; margin-top: 10px; padding-top: 10px;
border-top: 1px solid var(--line-soft); font-size: 12.5px;
}
.loop-card.open .loop-detail { display: block; }
.loop-detail ul { margin: 0; padding-left: 16px; }
.loop-detail li { margin-bottom: 4px; }
.loop-detail code {
background: var(--panel-2);
border: 1px solid var(--line-soft);
border-radius: 4px;
padding: 1px 4px;
font-family: "SF Mono", Menlo, Consolas, monospace;
font-size: 11.5px;
}
.loops-head {
font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
color: var(--ink-soft); font-weight: 600;
margin: 0 0 10px;
}
footer {
margin-top: 36px; padding-top: 18px;
border-top: 1px solid var(--line);
color: var(--ink-soft); font-size: 12.5px;
}
</style>
</head>
<body>
<nav class="topnav" aria-label="Writ navigation">
<div class="topnav-inner">
<a class="topnav-brand" href="writ-complete-overview.html"><span class="dot">•</span>Writ</a>
<ul>
<li><a href="writ-architecture-flowchart.html">Architecture</a></li>
<li><a class="active" href="writ-workflow-flowchart.html">Workflow</a></li>
<li><a href="writ-commands.html">Commands</a></li>
</ul>
</div>
</nav>
<div class="wrap">
<div class="layout">
<!-- LEFT: hero + detail panel (sticky, always visible) -->
<aside class="left-col">
<div class="eyebrow">Writ End-to-End Workflow</div>
<h1>START to END, drawn long ways.</h1>
<p class="pitch">
Every Writ-enforced coding session walks this flow. <strong>Click any
shape</strong> to see what triggers it, which hooks fire, and what state
changes. The detail panel below stays in view; the flowchart on the
right scrolls horizontally.
</p>
<div class="legend">
<span class="legend-item"><span class="legend-swatch terminus"></span> Start / End</span>
<span class="legend-item"><span class="legend-swatch"></span> Process step</span>
<span class="legend-item"><span class="legend-swatch diamond"></span> Decision</span>
<span class="legend-item"><span class="legend-swatch loop"></span> Loop-back (iterate)</span>
</div>
<div class="detail-shell" id="detail-shell">
<div class="empty" id="empty-msg">Click any shape on the right to see its detail.</div>
<div class="detail-panel" id="detail-node-start">
<div class="detail-head"><span class="detail-step">Stage 1 / Setup</span></div>
<h2 class="detail-title">START</h2>
<p class="detail-summary">A coding session begins. Claude Code launches; Writ has not yet been touched.</p>
<div class="detail-body">
<h4>State at this point</h4>
<ul>
<li>No session cache exists on disk.</li>
<li>Mode is unset; phase is unset.</li>
<li>The agent has no Writ rules in context yet.</li>
</ul>
</div>
</div>
<div class="detail-panel" id="detail-node-bootstrap">
<div class="detail-head"><span class="detail-step">Stage 2 / Setup</span></div>
<h2 class="detail-title">Session bootstrap</h2>
<p class="detail-summary">The SessionStart hook fires once and prepares Writ for the rest of the session.</p>
<div class="detail-body">
<h4>What runs</h4>
<ul><li><code>.claude/hooks/session-start-bootstrap.sh</code></li></ul>
<h4>What it does</h4>
<ul>
<li>Calls <code>GET /always-on</code> to fetch the mandatory rules bundle (capped near 5K tokens).</li>
<li>Creates a session-cache file keyed by session_id.</li>
<li>Initializes <code>mode = null</code>, <code>phase = null</code>, <code>loaded_rule_ids = []</code>.</li>
</ul>
<h4>Why it matters</h4>
<ul><li>Without bootstrap there is no session state, and the gate hooks have nothing to gate against.</li></ul>
</div>
</div>
<div class="detail-panel" id="detail-node-prompt">
<div class="detail-head"><span class="detail-step">Stage 3 / Setup</span></div>
<h2 class="detail-title">User submits prompt</h2>
<p class="detail-summary">Every Enter-press fires UserPromptSubmit. Three hooks run in order.</p>
<div class="detail-body">
<h4>Hooks (in order)</h4>
<ul>
<li><code>auto-approve-gate.sh</code>: defense-in-depth pattern match on "approved" (primary path is the <code>writ-approve</code> tool call).</li>
<li><code>writ-rag-inject.sh</code>: calls <code>POST /query</code> to retrieve relevant rules.</li>
<li><code>writ-context-watcher.sh</code>: records a context-pressure snapshot.</li>
</ul>
</div>
</div>
<div class="detail-panel" id="detail-node-rag">
<div class="detail-head"><span class="detail-step">Stage 4 / Setup</span></div>
<h2 class="detail-title">Inject rules (the RAG pipeline)</h2>
<p class="detail-summary">The five-stage retrieval pipeline picks the most relevant rules for this prompt and injects them into the agent's context.</p>
<div class="detail-body">
<h4>The five stages</h4>
<ul><li>Domain filter, BM25 (Tantivy), ANN vector (hnswlib), graph traversal (Neo4j adjacency cache), two-pass ranking with RRF.</li></ul>
<h4>What the agent sees</h4>
<ul>
<li>The always-active rules block (mandatory, every turn).</li>
<li>A small bundle of retrieved domain rules (3 to 8 typically).</li>
</ul>
<h4>Source</h4>
<ul>
<li><code>writ/retrieval/pipeline.py</code> for the orchestration.</li>
<li><code>writ/retrieval/ranking.py</code> for the weight formula.</li>
</ul>
</div>
</div>
<div class="detail-panel" id="detail-node-mode">
<div class="detail-head"><span class="detail-step amber">Decision / Routing</span></div>
<h2 class="detail-title">Which mode? (decision)</h2>
<p class="detail-summary">Before any write, the agent declares the session's mode. Until a mode is set, gate hooks deny all writes except plan.md.</p>
<div class="detail-body">
<h4>The four modes</h4>
<ul>
<li><strong>Conversation</strong>: discuss, brainstorm. No phase gates.</li>
<li><strong>Debug</strong>: investigate a problem. No code generation expected.</li>
<li><strong>Review</strong>: evaluate existing code against rules. Structured findings only.</li>
<li><strong>Work</strong>: build or modify code. Enters the four phase gates.</li>
</ul>
<h4>How the agent sets mode</h4>
<ul>
<li><code>python3 bin/lib/writ-session.py mode set <mode> <session_id></code></li>
<li>With <code>--orchestrator</code> for sub-agent dispatch workflows.</li>
</ul>
<h4>Source</h4>
<ul><li><code>bin/lib/writ-session.py:835-985</code></li></ul>
</div>
</div>
<div class="detail-panel" id="detail-node-respond">
<div class="detail-head"><span class="detail-step">Non-Work branch</span></div>
<h2 class="detail-title">Respond directly</h2>
<p class="detail-summary">In Conversation, Debug, and Review modes, the agent answers the prompt with no phase gates and no write enforcement (beyond the always-active rules).</p>
<div class="detail-body">
<h4>Why this path exists</h4>
<ul>
<li>Most prompts are not "write me production code." Modes that do not generate code skip the gate ceremony entirely.</li>
<li>RAG still injects relevant rules. The mandatory rules still apply (forbidden phrases, etc.).</li>
</ul>
<h4>Mode-specific deliverables</h4>
<ul>
<li><strong>Debug:</strong> root-cause evidence (per ENF-PROC-DEBUG-001).</li>
<li><strong>Review:</strong> per-file structured findings.</li>
</ul>
</div>
</div>
<div class="detail-panel" id="detail-node-end-side">
<div class="detail-head"><span class="detail-step gray">Terminal</span></div>
<h2 class="detail-title">END (non-Work)</h2>
<p class="detail-summary">For non-Work modes, the response is the deliverable. The SessionEnd hook still runs for friction logging.</p>
</div>
<div class="detail-panel" id="detail-node-plan">
<div class="detail-head"><span class="detail-step work">Work mode / Phase 1</span></div>
<h2 class="detail-title">Write plan.md</h2>
<p class="detail-summary">The agent writes plan.md and capabilities.md to the project root, then presents the plan and waits for the user.</p>
<div class="detail-body">
<h4>Required sections</h4>
<ul>
<li><code>## Files</code>, <code>## Analysis</code>, <code>## Rules Applied</code>, <code>## Capabilities</code>.</li>
<li>No placeholder text (TBD, TODO, "similar to N") - enforced by ENF-PROC-PLAN-001.</li>
</ul>
<h4>Hooks involved</h4>
<ul>
<li><code>validate-exit-plan.sh</code> (PreToolUse on ExitPlanMode).</li>
<li><code>validate-file.sh</code> (PostToolUse): runs the structural gate.</li>
</ul>
</div>
</div>
<div class="detail-panel" id="detail-node-plan-approved">
<div class="detail-head"><span class="detail-step amber">Decision / Phase gate 1</span></div>
<h2 class="detail-title">Plan approved? (decision)</h2>
<p class="detail-summary">The user reads the plan and either approves it or asks for changes. Approval is recorded in the audit trail.</p>
<div class="detail-body">
<h4>How approval advances the phase</h4>
<ul>
<li>User types "approved".</li>
<li>Agent invokes the <code>writ-approve</code> tool.</li>
<li>That calls <code>POST /session/{id}/advance-phase</code> with <code>confirmation_source: "tool"</code>.</li>
<li>Phase moves planning -> testing.</li>
</ul>
<h4>Outcomes</h4>
<div class="answers">
<span class="answer-pill green">yes: advance to Testing</span>
<span class="answer-pill pink">no: rewrite plan, loop back</span>
</div>
</div>
</div>
<div class="detail-panel" id="detail-node-tests">
<div class="detail-head"><span class="detail-step work">Work mode / Phase 2</span></div>
<h2 class="detail-title">Write test skeletons</h2>
<p class="detail-summary">The agent writes test files: class names, method signatures, and assertions, but no implementation code.</p>
<div class="detail-body">
<h4>Hooks involved</h4>
<ul>
<li><code>validate-test-file.sh</code> (PreToolUse): structural check on test files.</li>
<li><code>writ-mark-pending-test.sh</code> (PostToolUse): records the test path for the run hook.</li>
</ul>
<h4>What the agent shows the user</h4>
<ul><li>Class names and test counts only. No method-by-method listing.</li></ul>
</div>
</div>
<div class="detail-panel" id="detail-node-tests-approved">
<div class="detail-head"><span class="detail-step amber">Decision / Phase gate 2</span></div>
<h2 class="detail-title">Tests approved? (decision)</h2>
<p class="detail-summary">User reviews the test list. Approval moves the phase to implementation.</p>
<div class="detail-body">
<h4>Outcomes</h4>
<div class="answers">
<span class="answer-pill green">yes: advance to Implementation</span>
<span class="answer-pill pink">no: rewrite tests, loop back</span>
</div>
</div>
</div>
<div class="detail-panel" id="detail-node-impl">
<div class="detail-head"><span class="detail-step work">Work mode / Phase 3</span></div>
<h2 class="detail-title">Write implementation</h2>
<p class="detail-summary">The agent writes production code. Every Write or Edit fires more hooks: validate, rule-check, re-inject rules, mark tests pending.</p>
<div class="detail-body">
<h4>Per-write hooks</h4>
<ul>
<li><code>pre-validate-file.sh</code> (PreToolUse): structural check.</li>
<li><code>writ-pre-write-dispatch.sh</code> (PreToolUse): can-write gate.</li>
<li><code>validate-file.sh</code> (PostToolUse): rule-compliance check.</li>
<li><code>validate-rules.sh</code> (PostToolUse): asserts no rule violations.</li>
<li><code>writ-posttool-rag.sh</code> (PostToolUse): re-injects rules surfaced by the file just written.</li>
<li><code>writ-quality-judge.sh</code> (PostToolUse): per-rubric quality scoring.</li>
<li><code>writ-mark-pending-test.sh</code> (PostToolUse): marks test for next Stop hook.</li>
</ul>
</div>
</div>
<div class="detail-panel" id="detail-node-runtests">
<div class="detail-head"><span class="detail-step work">Work mode / Phase 3</span></div>
<h2 class="detail-title">Run pending tests</h2>
<p class="detail-summary">When the agent pauses (Stop hook), Writ runs every test marked this session and writes the result to the friction log.</p>
<div class="detail-body">
<h4>What runs</h4>
<ul>
<li><code>.claude/hooks/writ-run-pending-tests.sh</code></li>
<li>60-second timeout, runner grouping (pytest, PHPUnit, jest detected from paths).</li>
</ul>
<h4>What lands in the friction log</h4>
<ul><li><code>writ-run-pending-tests</code> event with <code>result_code</code> and <code>resolved_count</code>.</li></ul>
</div>
</div>
<div class="detail-panel" id="detail-node-tests-pass">
<div class="detail-head"><span class="detail-step green">Decision / Phase gate 3</span></div>
<h2 class="detail-title">Tests pass? (decision)</h2>
<p class="detail-summary">If tests pass, the agent advances to verification. If they fail, it loops back to implementation and tries again.</p>
<div class="detail-body">
<h4>Outcomes</h4>
<div class="answers">
<span class="answer-pill green">yes: advance to Verification</span>
<span class="answer-pill pink">no: agent fixes code, re-runs tests, loop back</span>
</div>
<h4>Why automatic rather than user-approved</h4>
<ul>
<li>Test pass/fail is a fact, not a judgment. The runner exit code is authoritative.</li>
<li>The user is still informed via the friction log and the agent's own summary.</li>
</ul>
</div>
</div>
<div class="detail-panel" id="detail-node-verify">
<div class="detail-head"><span class="detail-step work">Work mode / Phase 4</span></div>
<h2 class="detail-title">Verify + update capabilities.md</h2>
<p class="detail-summary">The agent checks off completed items in capabilities.md, citing verification evidence (test runs, file paths, line numbers).</p>
<div class="detail-body">
<h4>Hooks involved</h4>
<ul><li><code>writ-verify-before-claim.sh</code> (PreToolUse on TodoWrite, and on Stop): denies completion marks without evidence.</li></ul>
<h4>Why this is the strictest hook</h4>
<ul><li>False completion claims compound across the rest of the workflow. The gate forces evidence in the same message as the claim.</li></ul>
</div>
</div>
<div class="detail-panel" id="detail-node-session-end">
<div class="detail-head"><span class="detail-step gray">Cleanup</span></div>
<h2 class="detail-title">Session end: friction log + audit</h2>
<p class="detail-summary">SessionEnd hooks write the final friction entries, persist session state, and emit a pressure audit.</p>
<div class="detail-body">
<h4>Hooks involved</h4>
<ul>
<li><code>writ-session-end.sh</code>: persists final session cache.</li>
<li><code>writ-pressure-audit.sh</code>: emits a context-pressure summary.</li>
<li><code>friction-logger.sh</code>: writes the final friction entries.</li>
<li><code>enforce-violations.sh</code>: applies any pending violations.</li>
</ul>
<h4>What lands on disk</h4>
<ul>
<li><code>workflow-friction.log</code>: append-only event stream.</li>
<li>Session cache file remains for replay or post-mortem.</li>
</ul>
</div>
</div>
<div class="detail-panel" id="detail-node-end">
<div class="detail-head"><span class="detail-step gray">Terminal</span></div>
<h2 class="detail-title">END</h2>
<p class="detail-summary">Session complete. The agent's outputs (code, plan, capabilities) and the friction log are the artifacts that survive.</p>
</div>
</div>
</aside>
<!-- RIGHT: horizontal flowchart + loops -->
<div class="right-col">
<p class="chart-scroll-hint">Scroll right to follow the full flow →</p>
<div class="chart-scroll">
<svg viewBox="0 0 2440 460" xmlns="http://www.w3.org/2000/svg" aria-label="Writ workflow flowchart (horizontal)">
<defs>
<marker id="arrW" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" fill="#1a1a1a"/>
</marker>
<marker id="arrWp" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" fill="#be185d"/>
</marker>
</defs>
<!-- START -->
<g class="node node-terminus" data-node-id="node-start" tabindex="0" role="button">
<ellipse cx="60" cy="240" rx="50" ry="24"/>
<text class="node-text bold white" x="60" y="240">START</text>
</g>
<path class="arr" d="M 110 240 L 128 240" marker-end="url(#arrW)"/>
<!-- Bootstrap -->
<g class="node node-process" data-node-id="node-bootstrap" tabindex="0" role="button">
<rect x="130" y="210" width="140" height="60" rx="8"/>
<text class="node-text bold" x="200" y="232">Session bootstrap</text>
<text class="node-text small" x="200" y="252">SessionStart hook</text>
</g>
<path class="arr" d="M 270 240 L 288 240" marker-end="url(#arrW)"/>
<!-- Prompt -->
<g class="node node-process" data-node-id="node-prompt" tabindex="0" role="button">
<rect x="290" y="210" width="140" height="60" rx="8"/>
<text class="node-text bold" x="360" y="232">User submits</text>
<text class="node-text small" x="360" y="252">UserPromptSubmit</text>
</g>
<path class="arr" d="M 430 240 L 448 240" marker-end="url(#arrW)"/>
<!-- RAG -->
<g class="node node-process" data-node-id="node-rag" tabindex="0" role="button">
<rect x="450" y="210" width="140" height="60" rx="8"/>
<text class="node-text bold" x="520" y="232">Inject rules</text>
<text class="node-text small" x="520" y="252">5-stage pipeline</text>
</g>
<path class="arr" d="M 590 240 L 608 240" marker-end="url(#arrW)"/>
<!-- Mode? -->
<g class="node node-decision" data-node-id="node-mode" tabindex="0" role="button">
<polygon points="680,180 750,240 680,300 610,240"/>
<text class="node-text bold" x="680" y="232">Mode?</text>
<text class="node-text small" x="680" y="252">routing</text>
</g>
<!-- Branch UP to non-Work spur -->
<path class="arr" d="M 680 180 L 680 110" marker-end="url(#arrW)"/>
<text class="label-on-arrow" x="688" y="150" text-anchor="start">non-Work</text>
<path class="arr" d="M 680 95 L 728 65" marker-end="url(#arrW)"/>
<!-- Respond (non-Work) -->
<g class="node node-side" data-node-id="node-respond" tabindex="0" role="button">
<rect x="730" y="35" width="160" height="60" rx="8"/>
<text class="node-text bold" x="810" y="58">Respond directly</text>
<text class="node-text small" x="810" y="78">no phase gates</text>
</g>
<path class="arr" d="M 890 65 L 908 65" marker-end="url(#arrW)"/>
<!-- END-side -->
<g class="node node-terminus gray" data-node-id="node-end-side" tabindex="0" role="button">
<ellipse cx="960" cy="65" rx="48" ry="22"/>
<text class="node-text bold white" x="960" y="65">END</text>
</g>
<!-- Forward (Work) from Mode? -->
<path class="arr" d="M 750 240 L 768 240" marker-end="url(#arrW)"/>
<text class="label-on-arrow" x="759" y="232" text-anchor="middle">Work</text>
<!-- Plan -->
<g class="node node-process work" data-node-id="node-plan" tabindex="0" role="button">
<rect x="770" y="210" width="150" height="60" rx="8"/>
<text class="node-text bold" x="845" y="232">Write plan.md</text>
<text class="node-text small" x="845" y="252">Files/Analysis/Rules</text>
</g>
<path class="arr" d="M 920 240 L 938 240" marker-end="url(#arrW)"/>
<!-- Plan approved? -->
<g class="node node-decision" data-node-id="node-plan-approved" tabindex="0" role="button">
<polygon points="1010,180 1080,240 1010,300 940,240"/>
<text class="node-text bold" x="1010" y="232">Plan</text>
<text class="node-text small" x="1010" y="252">approved?</text>
</g>
<path class="arr" d="M 1080 240 L 1098 240" marker-end="url(#arrW)"/>
<text class="label-on-arrow" x="1089" y="232" text-anchor="middle">yes</text>
<!-- Loop back: Plan? no -> Plan -->
<path class="arr-loop" d="M 1010 300 C 1010 380, 845 380, 845 280" marker-end="url(#arrWp)"/>
<text class="label-on-arrow" x="928" y="395" text-anchor="middle" style="fill:#be185d">no: rewrite plan</text>
<!-- Tests -->
<g class="node node-process work" data-node-id="node-tests" tabindex="0" role="button">
<rect x="1100" y="210" width="150" height="60" rx="8"/>
<text class="node-text bold" x="1175" y="232">Write tests</text>
<text class="node-text small" x="1175" y="252">skeletons + assertions</text>
</g>
<path class="arr" d="M 1250 240 L 1268 240" marker-end="url(#arrW)"/>
<!-- Tests approved? -->
<g class="node node-decision" data-node-id="node-tests-approved" tabindex="0" role="button">
<polygon points="1340,180 1410,240 1340,300 1270,240"/>
<text class="node-text bold" x="1340" y="232">Tests</text>
<text class="node-text small" x="1340" y="252">approved?</text>
</g>
<path class="arr" d="M 1410 240 L 1428 240" marker-end="url(#arrW)"/>
<text class="label-on-arrow" x="1419" y="232" text-anchor="middle">yes</text>
<!-- Loop back: Tests? no -> Tests -->
<path class="arr-loop" d="M 1340 300 C 1340 380, 1175 380, 1175 280" marker-end="url(#arrWp)"/>
<text class="label-on-arrow" x="1258" y="395" text-anchor="middle" style="fill:#be185d">no: rewrite tests</text>
<!-- Impl -->
<g class="node node-process work" data-node-id="node-impl" tabindex="0" role="button">
<rect x="1430" y="210" width="150" height="60" rx="8"/>
<text class="node-text bold" x="1505" y="232">Write impl</text>
<text class="node-text small" x="1505" y="252">per-write RAG inject</text>
</g>
<path class="arr" d="M 1580 240 L 1598 240" marker-end="url(#arrW)"/>
<!-- RunTests -->
<g class="node node-process work" data-node-id="node-runtests" tabindex="0" role="button">
<rect x="1600" y="210" width="150" height="60" rx="8"/>
<text class="node-text bold" x="1675" y="232">Run pending tests</text>
<text class="node-text small" x="1675" y="252">Stop hook runs them</text>
</g>
<path class="arr" d="M 1750 240 L 1768 240" marker-end="url(#arrW)"/>
<!-- Tests pass? (green) -->
<g class="node node-decision tests" data-node-id="node-tests-pass" tabindex="0" role="button">
<polygon points="1840,180 1910,240 1840,300 1770,240"/>
<text class="node-text bold" x="1840" y="232">Tests</text>
<text class="node-text small" x="1840" y="252">pass?</text>
</g>
<path class="arr" d="M 1910 240 L 1928 240" marker-end="url(#arrW)"/>
<text class="label-on-arrow" x="1919" y="232" text-anchor="middle">yes</text>
<!-- Loop back: Tests pass? no -> Impl -->
<path class="arr-loop" d="M 1840 300 C 1840 400, 1505 400, 1505 280" marker-end="url(#arrWp)"/>
<text class="label-on-arrow" x="1672" y="418" text-anchor="middle" style="fill:#be185d">no: fix & rewrite</text>
<!-- Verify -->
<g class="node node-process work" data-node-id="node-verify" tabindex="0" role="button">
<rect x="1930" y="210" width="160" height="60" rx="8"/>
<text class="node-text bold" x="2010" y="232">Verify</text>
<text class="node-text small" x="2010" y="252">update capabilities.md</text>
</g>
<path class="arr" d="M 2090 240 L 2108 240" marker-end="url(#arrW)"/>
<!-- SessionEnd -->
<g class="node node-process" data-node-id="node-session-end" tabindex="0" role="button">
<rect x="2110" y="210" width="180" height="60" rx="8"/>
<text class="node-text bold" x="2200" y="232">Session end</text>
<text class="node-text small" x="2200" y="252">friction log + audit</text>
</g>
<path class="arr" d="M 2290 240 L 2308 240" marker-end="url(#arrW)"/>
<!-- END -->
<g class="node node-terminus" data-node-id="node-end" tabindex="0" role="button">
<ellipse cx="2370" cy="240" rx="58" ry="24"/>
<text class="node-text bold white" x="2370" y="240">END</text>
</g>
</svg>
</div>
<p class="loops-head">Background loops (run alongside the main flow)</p>
<div class="loops">
<div class="loop-card" data-loop-id="loop-evolution">
<span class="loop-tag">Rule evolution</span>
<h3>Proposal » gate » promotion</h3>
<p>
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.
</p>
<div class="loop-detail">
<ul>
<li><strong>Propose:</strong> <code>writ propose</code> or <code>POST /propose</code>. Authority forced to ai-provisional.</li>
<li><strong>Structural gate:</strong> schema, specificity, mechanical enforcement path, redundancy (>= 0.95 cosine), conflicts.</li>
<li><strong>Human review:</strong> <code>writ review --promote</code> moves authority to ai-promoted, confidence to peer-reviewed.</li>
<li><strong>Frequency graduation:</strong> 50+ observations at 75%+ positive ratio replaces static confidence with empirical ratio.</li>
</ul>
</div>
</div>
<div class="loop-card" data-loop-id="loop-subagent">
<span class="loop-tag pink">Sub-agent dispatch</span>
<h3>Orchestrator » worker » report</h3>
<p>
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.
</p>
<div class="loop-detail">
<ul>
<li>Master sets <code>mode set work <id> --orchestrator</code> to suppress broad RAG in its own context.</li>
<li>SubagentStart hook tags worker with <code>is_subagent: true</code>; worker bypasses phase gates.</li>
<li>Each worker has its own RAG budget and rule injections.</li>
<li>Workers run in foreground; each phase is a hard dependency for the next.</li>
</ul>
</div>
</div>
<div class="loop-card" data-loop-id="loop-compaction">
<span class="loop-tag gray">Context compaction</span>
<h3>Pre-compact » compact » post-compact</h3>
<p>
When the conversation outgrows the context window, Writ snapshots its
rule state, lets compaction proceed, then restores critical rules into
the post-compact context.
</p>
<div class="loop-detail">
<ul>
<li><code>writ-precompact.sh</code> persists the <code>loaded_rule_ids</code> snapshot.</li>
<li><code>clear-rules-for-compaction</code> frees budget so the summary fits.</li>
<li><code>writ-postcompact.sh</code> calls <code>reset-after-compaction</code> and re-injects mandatory rules.</li>
<li>Context-pressure tracking ensures RAG is skipped when the budget is near the limit.</li>
</ul>
</div>
</div>
</div>
<footer>
<p>
Click any shape in the flowchart to load that step's detail in the
left panel. Pairs with
<code style="background:transparent;border:none">writ-architecture-flowchart.html</code>:
that one shows the parts, this one shows the sequence.
</p>
</footer>
</div>
</div>
</div>
<script>
// Node click -> populate left-rail detail panel.
var emptyMsg = document.getElementById('empty-msg');
var panels = document.querySelectorAll('.detail-panel');
function selectNode(nodeId) {
document.querySelectorAll('.node.selected').forEach(function (n) {
n.classList.remove('selected');
});
panels.forEach(function (p) { p.classList.remove('active'); });
var target = document.getElementById('detail-' + nodeId);
var nodeEl = document.querySelector('[data-node-id="' + nodeId + '"]');
if (target) {
target.classList.add('active');
emptyMsg.style.display = 'none';
if (nodeEl) nodeEl.classList.add('selected');
}
}
document.querySelectorAll('.node').forEach(function (n) {
var id = n.getAttribute('data-node-id');
if (!id) return;
n.addEventListener('click', function () { selectNode(id); });
n.addEventListener('keydown', function (e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
selectNode(id);
}
});
});
// Background loop cards toggle independently.
document.querySelectorAll('.loop-card').forEach(function (c) {
c.addEventListener('click', function () { c.classList.toggle('open'); });
c.addEventListener('keydown', function (e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
c.classList.toggle('open');
}
});
c.setAttribute('tabindex', '0');
c.setAttribute('role', 'button');
});
// Default: select START on load so the detail panel is never empty.
selectNode('node-start');
</script>
</body>
</html>