hird 0.3.1

Cross-harness agent work queue and shared assertion memory, backed by one local SQLite database
Documentation
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
901
902
903
904
905
906
907
908
909
910
911
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>hird — the software factory</title>
<meta name="description" content="A step-by-step walkthrough of hird-server's software factory: builders, reviewers, CI and a human working one release from ready to merged, with every refusal the factory exists to make.">
<link rel="stylesheet" href="style.css">
<style>
  /* ------------------------------------------------- the factory's palette
     One colour per stage, the same family `/watch` draws. Declared for all
     three theme states, like style.css. */
  :root {
    --st-ready: #ffffff; --st-claimed: #fff3b0; --st-built: #dbe9ff;
    --st-review: #e8dcff; --st-approved: #d4f0e0; --st-merged: #b6e3c0;
    --st-escalated: #f5b7b1; --card-ink: #1c1c1a;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --st-ready: #2a2a26; --st-claimed: #5a4a10; --st-built: #1f3450;
      --st-review: #3a2d55; --st-approved: #1f4535; --st-merged: #1f4d2a;
      --st-escalated: #5c2222; --card-ink: #ecebe6;
    }
  }
  :root[data-theme="dark"] {
    --st-ready: #2a2a26; --st-claimed: #5a4a10; --st-built: #1f3450;
    --st-review: #3a2d55; --st-approved: #1f4535; --st-merged: #1f4d2a;
    --st-escalated: #5c2222; --card-ink: #ecebe6;
  }

  /* ------------------------------------------------------------ the player */
  .player {
    background: var(--bg-raised);
    border: 1px solid var(--rule);
    border-radius: 10px;
    margin: 1.5rem 0;
    overflow: hidden;
  }
  .player .controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-sunken);
    border-bottom: 1px solid var(--rule);
    font-size: 0.875rem;
  }
  .player button, .player select {
    font: inherit;
    font-size: 0.875rem;
    color: var(--ink);
    background: var(--bg-raised);
    border: 1px solid var(--rule);
    border-radius: 6px;
    padding: 0.25rem 0.6rem;
    cursor: pointer;
  }
  .player button:hover:not(:disabled) { border-color: var(--accent); }
  .player button:disabled { opacity: 0.5; cursor: default; }
  .player button.go {
    background: var(--accent); border-color: var(--accent);
    color: var(--bg-raised); font-weight: 500; min-width: 5rem;
  }
  .player .controls label { color: var(--ink-faint); display: inline-flex; gap: 0.35rem; align-items: center; }
  .player .spacer { flex: 1 1 auto; }
  .player .clock { font-family: var(--mono); font-size: 0.75rem; color: var(--ink-faint); }

  .act {
    padding: 0.9rem 1rem 0.2rem;
    font-weight: 600;
    font-size: 0.9375rem;
  }
  .act small { display: block; font-weight: 400; color: var(--ink-faint); font-family: var(--mono); font-size: 0.75rem; }

  /* the crew */
  .crew {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 0.5rem;
    padding: 0.75rem 1rem;
  }
  .member {
    border: 1px solid var(--rule);
    border-radius: 8px;
    padding: 0.4rem 0.5rem;
    font-size: 0.75rem;
    line-height: 1.35;
    transition: border-color 0.2s, box-shadow 0.2s, opacity 0.2s;
    opacity: 0.7;
  }
  .member b { display: block; font-size: 0.875rem; }
  .member .h { color: var(--ink-faint); font-family: var(--mono); }
  .member .role {
    display: inline-block; margin-top: 0.2rem;
    font-family: var(--mono); font-size: 0.6875rem;
    border-radius: 999px; padding: 0 0.4rem;
    background: var(--bg-sunken); color: var(--ink-soft);
  }
  .member.on { opacity: 1; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
  .member.on.no { border-color: var(--red); }

  /* the lanes */
  .lanes {
    display: grid;
    grid-template-columns: repeat(7, minmax(5.25rem, 1fr));
    gap: 0.4rem;
    padding: 0.25rem 1rem 0.75rem;
    overflow-x: auto;
  }
  .lane {
    background: var(--bg-sunken);
    border-radius: 8px;
    min-height: 11rem;
    padding: 0.35rem;
  }
  .lane h4 {
    margin: 0 0 0.35rem;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-faint);
    font-weight: 600;
    text-align: center;
  }
  .lane.escalated h4 { color: var(--red); }
  .tcard {
    position: relative;
    border-radius: 6px;
    border: 1px solid var(--rule);
    padding: 0.35rem 0.45rem;
    margin-bottom: 0.35rem;
    font-size: 0.75rem;
    line-height: 1.3;
    color: var(--card-ink);
    background: var(--st-ready);
  }
  .tcard .n { font-family: var(--mono); font-weight: 600; }
  .tcard .meta { display: block; margin-top: 0.2rem; font-family: var(--mono); font-size: 0.6875rem; opacity: 0.8; }
  .tcard.moved { box-shadow: 0 0 0 2px var(--accent); }
  .tcard[data-stage="claimed"] { background: var(--st-claimed); }
  .tcard[data-stage="built"] { background: var(--st-built); }
  .tcard[data-stage="in_review"] { background: var(--st-review); }
  .tcard[data-stage="approved"] { background: var(--st-approved); }
  .tcard[data-stage="merged"] { background: var(--st-merged); }
  .tcard[data-stage="escalated"] { background: var(--st-escalated); }

  /* the wire: the calls this beat made, and what the server said */
  .wire {
    margin: 0;
    padding: 0.75rem 1rem 1rem;
    border-top: 1px solid var(--rule);
    font-family: var(--mono);
    font-size: 0.75rem;
    line-height: 1.5;
    min-height: 7.5rem;
  }
  .wire .call { color: var(--ink); }
  .wire .call .who { color: var(--accent); font-weight: 600; }
  .wire .ok { color: var(--green); padding-left: 2.2rem; }
  .wire .no { color: var(--red); padding-left: 2.2rem; }
  .wire .why {
    font-family: var(--sans); font-size: 0.8125rem; color: var(--ink-soft);
    margin-top: 0.5rem; border-left: 2px solid var(--rule); padding-left: 0.6rem;
  }

  @media (max-width: 48rem) {
    .crew { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  }

  /* the pipeline diagram */
  .pipeline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    margin: 1.25rem 0;
    font-family: var(--mono);
    font-size: 0.8125rem;
  }
  .pipeline span.s {
    border: 1px solid var(--rule);
    border-radius: 999px;
    padding: 0.1rem 0.6rem;
    color: var(--card-ink);
  }
  .pipeline .arrow { color: var(--ink-faint); }

  /* the run in words */
  ol.beats { margin: 1rem 0; padding: 0; list-style: none; counter-reset: beat; }
  ol.beats li {
    counter-increment: beat;
    display: grid;
    grid-template-columns: 2rem minmax(0, 1fr);
    gap: 0.5rem;
    padding: 0.45rem 0.4rem;
    border-top: 1px solid var(--rule);
    margin: 0;
  }
  ol.beats li::before {
    content: counter(beat);
    font-family: var(--mono); font-size: 0.75rem; color: var(--ink-faint); padding-top: 0.15rem;
  }
  ol.beats li.here { background: var(--accent-soft); }
  ol.beats button {
    font: inherit; text-align: left; background: none; border: 0; padding: 0;
    color: var(--ink); cursor: pointer; font-size: 0.875rem;
  }
  ol.beats button:hover { color: var(--accent); }
  ol.beats .refused { color: var(--red); font-family: var(--mono); font-size: 0.75rem; margin-left: 0.35rem; }

  @media (prefers-reduced-motion: reduce) {
    .tcard { transition: none !important; }
  }
</style>
</head>
<body>

<button id="theme" type="button" aria-label="Toggle colour theme">theme</button>

<div class="shell">
<nav class="toc" aria-label="Contents">
  <a class="brand" href="#top">hird</a>
  <p class="tagline">Builders build, reviewers who built none of it review it, CI gates it, a human decides.</p>
  <details class="nav-body" open>
  <summary>Contents</summary>
  <ol>
    <li><a href="#start">Get started in five minutes</a></li>
    <li><a href="#idea">What the factory adds</a></li>
    <li><a href="#watch">One release, step by step</a></li>
    <li><a href="#beats">The run, in words</a></li>
    <li><a href="#roles">Roles</a></li>
    <li><a href="#stages">Stages</a></li>
    <li><a href="#refusals">The refusals it exists to make</a></li>
    <li><a href="#run">Run it yourself</a></li>
  </ol>
  <div class="away">
    <a href="index.html">The usage guide &rarr;</a>
    <a href="server.html">How the central queue works &rarr;</a>
    <a href="swarm.html">How a swarm collaborates &rarr;</a>
    <a href="https://github.com/aoprisan/hird">Source on GitHub &rarr;</a>
  </div>
  </details>
</nav>

<main id="top">

<header class="hero">
  <div class="badges">
    <span class="badge">four roles</span>
    <span class="badge">four more tools</span>
    <span class="badge">stages derived, never stored</span>
    <span class="badge">done is not merged</span>
  </div>
  <h1>The software factory</h1>
  <p class="lede">
    Give the workers in a <strong>hird-server</strong> roster <em>roles</em>
    and the central queue becomes the backbone of a software factory.
    Builders build. Reviewers who held none of the work review it. CI gates
    it. A human decides what nobody else may. Work is finished when it is
    <strong>merged</strong>, not when its author says so.
  </p>
  <div class="cta">
    <a class="primary" href="#start">Get started</a>
    <a href="#watch">Step through a release</a>
    <a href="#run">Run the example</a>
    <a href="https://github.com/aoprisan/hird/blob/main/examples/factory.sh">examples/factory.sh</a>
  </div>
</header>

<section id="start">
<h2>Get started in five minutes</h2>

<p>
  You need two agent harnesses, so that each can review what the other
  built. Install <code>hird-server</code> from a release binary (Linux or
  Apple silicon, no Rust needed) or with Cargo, and one command sets up
  everything else and walks you through it.
</p>

<pre><code><span class="k">curl</span> -fsSL https://raw.githubusercontent.com/aoprisan/hird/main/scripts/get.sh | sh -s -- --server
<span class="c"># or, with a Rust toolchain:</span> <span class="k">cargo install</span> hird-server --locked
<span class="k">hird-server quickstart</span> --tour                <span class="c"># set up, then a guided tour of the sample</span>
<span class="k">hird-server quickstart</span> --harness gemini --harness opencode</code></pre>

<p>It writes a <code>hird-factory/</code> directory:</p>

<div class="table-wrap">
<table>
  <thead><tr><th>File</th><th>What it is</th></tr></thead>
  <tbody>
    <tr><td><code>roster.toml</code></td><td>A factory roster with fresh tokens: you as <code>human</code>, one builder-and-reviewer token per agent harness, and <code>ci</code>.</td></tr>
    <tr><td><code>connect/&lt;harness&gt;.md</code></td><td>The command or config that connects that harness, with its token filled in.</td></tr>
    <tr><td><code>ci</code>, <code>human</code></td><td>Scripts for the moves no agent makes: <code>ci pass 1</code>, <code>ci merge 1</code>, <code>human answer 3 "&hellip;"</code>, <code>human board</code>.</td></tr>
    <tr><td><code>playground/</code></td><td>A git repository with a sample release already filed: <em>Write fizzbuzz</em>, then <em>Test</em> and <em>Document</em> it, which wait on the first until it is merged.</td></tr>
    <tr><td><code>GUIDE.md</code></td><td>The steps, which it also prints before it starts serving.</td></tr>
  </tbody>
</table>
</div>

<p>
  With <code>--tour</code>, it first plays the sample&rsquo;s first task from
  <em>ready</em> to <em>merged</em> in your terminal, as the two agents, CI
  and you would, and stops after each step to say what happened and why. Press
  Enter for the next one, and keep the <code>/watch</code> link open to see
  the cards move:
</p>

<ol class="numbered">
  <li><strong>The board.</strong> Three tasks; two wait on the first.</li>
  <li><strong>A builder asks for work</strong> and claims #1. The other agent is refused #2: #1 is not merged.</li>
  <li><strong>It builds</strong>, commits <code>fizzbuzz.py</code>, and completes. The factory files a review the builder may not take.</li>
  <li><strong>CI fails it.</strong> Back to <em>ready</em>, with the output kept.</li>
  <li><strong>The rebuild is handed the failure</strong>, fixes it, and completes again.</li>
  <li><strong>The other harness reviews</strong> and upholds it: <em>approved</em>.</li>
  <li><strong>Approved is not merged.</strong> The builder may not merge, and CI may not until its last run passes. Pass, then merge.</li>
  <li><strong>Your turn.</strong> #2 and #3 are free, and are for your own agents.</li>
</ol>

<p>Then it serves, and the guide takes you through a lap of your own:</p>

<ol class="numbered">
  <li><strong>Watch the floor.</strong> Open the <code>/watch</code> link it prints.</li>
  <li><strong>Connect your agents.</strong> One snippet each, from <code>connect/</code>.</li>
  <li><strong>Put them to work.</strong> Start each in the playground and say <em>work the hird queue</em>. One builds; the other is the only one allowed to review it.</li>
  <li><strong>Be CI.</strong> Run the tests, then <code>./ci pass 1</code> or <code>./ci fail 1 "what broke"</code>.</li>
  <li><strong>Merge.</strong> <code>./ci merge 1</code> records the playground&rsquo;s HEAD, and frees the two tasks waiting on it.</li>
  <li><strong>Decide.</strong> <code>./human</code> approves, rejects, answers escalations, reopens and cancels.</li>
</ol>

<p>
  Run it again to come back: the same tokens and the same board. When you are
  ready for real work, <code>hird-server quickstart --dir factory --project /path/to/repo</code>
  sets the same thing up for your repository, with nothing filed for you.
</p>
</section>

<section id="idea">
<h2>What the factory adds</h2>

<p>
  Core hird is a queue: tasks claimed under leases, dependencies enforced,
  reviews filed on completion, verdicts that act. What it never had is a
  notion of <em>who may do what</em>, or of work being <em>in</em> rather
  than merely done. The factory adds both, on the server only, and the
  local queue is unchanged.
</p>

<div class="pipeline" aria-label="The factory pipeline">
  <span class="s" style="background:var(--st-ready)">ready</span><span class="arrow">&rarr;</span>
  <span class="s" style="background:var(--st-claimed)">claimed</span><span class="arrow">&rarr;</span>
  <span class="s" style="background:var(--st-built)">built</span><span class="arrow">&rarr;</span>
  <span class="s" style="background:var(--st-review)">in_review</span><span class="arrow">&rarr;</span>
  <span class="s" style="background:var(--st-approved)">approved</span><span class="arrow">&rarr;</span>
  <span class="s" style="background:var(--st-merged)">merged</span>
  <span class="arrow">&nbsp;·&nbsp; rejections loop back to ready; the third asks a human:</span>
  <span class="s" style="background:var(--st-escalated)">escalated</span>
</div>

<div class="cols">
  <div class="card">
    <h4>Roles come from the roster</h4>
    <p>Each token's <code>roles</code> say what it may do. No client, header or tool argument can grant one, and every claim and finish is checked against them in the same transaction.</p>
  </div>
  <div class="card">
    <h4>Four more tools</h4>
    <p><code>factory_gate</code> for CI, <code>factory_merge</code> for CI or a human, <code>factory_decide</code> for the human, and <code>factory_board</code> for anyone &mdash; beside the twelve every worker has.</p>
  </div>
  <div class="card">
    <h4>Nothing is assigned</h4>
    <p>Roles say who <em>may</em> take work, never who <em>will</em>. Agents still pull with <code>task_next</code>; escalation asks a human rather than retrying.</p>
  </div>
</div>
</section>

<section id="watch">
<h2>One release, step by step</h2>

<p>
  This is <a href="https://github.com/aoprisan/hird/blob/main/examples/factory.sh"><code>examples/factory.sh</code></a>,
  played back. Six workers hold six tokens. The human files three tasks;
  <strong>#2</strong> waits on <strong>#1</strong>, and <strong>#3</strong> is a flaky
  test that will not go quietly. Every step is one or more real tool calls,
  and every refusal shown is the server&rsquo;s own words.
</p>

<div class="player" id="player">
  <div class="controls">
    <button class="go" id="play" type="button">Play</button>
    <button id="prev" type="button">&#9664; back</button>
    <button id="next" type="button">forward &#9654;</button>
    <button id="restart" type="button">restart</button>
    <label>speed
      <select id="speed">
        <option value="0.5">slow</option>
        <option value="1" selected>normal</option>
        <option value="2">fast</option>
      </select>
    </label>
    <span class="spacer"></span>
    <span class="clock" id="clock"></span>
  </div>
  <div class="act" id="act" aria-live="polite"></div>
  <div class="crew" id="crew"></div>
  <div class="lanes" id="lanes"></div>
  <div class="wire" id="wire"></div>
</div>
</section>

<section id="beats">
<h2>The run, in words</h2>
<p class="quiet">Click a step to jump the player to it.</p>
<ol class="beats" id="beat-list"></ol>
</section>

<section id="roles">
<h2>Roles</h2>

<div class="table-wrap">
<table>
  <thead><tr><th>Role</th><th>May</th><th>May not</th></tr></thead>
  <tbody>
    <tr><td><code>builder</code></td><td>Claim and finish work tasks. Every finish files a review.</td><td>Take a review; record a merge.</td></tr>
    <tr><td><code>reviewer</code></td><td>Claim a review and return <code>upheld</code> or <code>sent_back</code>.</td><td>Review work it, or (under the policy) its harness, ever held.</td></tr>
    <tr><td><code>ci</code></td><td><code>factory_gate</code> a test run; <code>factory_merge</code> approved work.</td><td>Claim anything.</td></tr>
    <tr><td><code>human</code></td><td><code>factory_decide</code>: approve, reject, answer an escalation, reopen, cancel; and merge.</td><td>&mdash;</td></tr>
  </tbody>
</table>
</div>

<pre><code><span class="c"># factory-roster.toml — the policy, and one entry per token</span>
[factory]
reviewer_harness_differs = true   <span class="c"># no harness that held the work reviews it</span>
max_attempts = 3                  <span class="c"># the third rejection asks a human</span>
require_ci_to_merge = true        <span class="c"># merge only what CI last passed</span>

[[worker]]
token = "…"
identity = "ana"
harness = "claude-code"           <span class="c"># builders and reviewers must pin a harness</span>
model = "model-id"                <span class="c"># recorded on everything this worker does</span>
roles = ["builder"]</code></pre>
</section>

<section id="stages">
<h2>Stages</h2>

<p>
  A stage is computed from what the queue already records &mdash; status,
  reviews, verdicts, attempts, CI reports, merges &mdash; and never stored,
  so it cannot disagree with them.
</p>

<div class="table-wrap">
<table>
  <thead><tr><th>Stage</th><th>Means</th><th>Leaves by</th></tr></thead>
  <tbody>
    <tr><td><code>ready</code></td><td>Open, no unanswered question, dependencies merged.</td><td>A builder claims it.</td></tr>
    <tr><td><code>claimed</code></td><td>A builder holds the lease.</td><td><code>task_complete</code>; or the lease lapses back to ready, with no attempt counted.</td></tr>
    <tr><td><code>built</code></td><td>Done, and its review is waiting.</td><td>A reviewer claims the review; CI fails it; a human decides.</td></tr>
    <tr><td><code>in_review</code></td><td>A reviewer holds the review.</td><td><code>upheld</code> &rarr; approved; <code>sent_back</code> &rarr; an attempt, back to ready.</td></tr>
    <tr><td><code>approved</code></td><td>Upheld since its latest completion.</td><td><code>factory_merge</code> with a SHA or PR URL, once CI&rsquo;s latest word is a pass.</td></tr>
    <tr><td><code>merged</code></td><td>In. Its dependents are released.</td><td>Only a human reopen.</td></tr>
    <tr><td><code>escalated</code></td><td>Rejected <code>max_attempts</code> times, or failed: a question for a human.</td><td><code>factory_decide</code> answer or reopen.</td></tr>
  </tbody>
</table>
</div>
</section>

<section id="refusals">
<h2>The refusals it exists to make</h2>

<div class="cols">
  <div class="card">
    <h4>No one reviews their own work</h4>
    <p>Not the builder, not another session of the builder&rsquo;s harness, and not an earlier holder whose lease lapsed. In the run, <strong>cy</strong> runs codex like <strong>ben</strong> did, so <code>task_next</code> hands cy nothing.</p>
  </div>
  <div class="card">
    <h4>Nothing builds on unmerged work</h4>
    <p>A dependency clears only once it is merged. Approved work can still fail CI, so <strong>#2</strong> stays held until <strong>#1</strong> is in.</p>
  </div>
  <div class="card">
    <h4>Approved is not merged</h4>
    <p>A builder cannot record a merge, and CI cannot merge work whose latest report is a fail. A merge carries its evidence: a commit SHA or a PR URL.</p>
  </div>
  <div class="card">
    <h4>The queue asks, it never retries</h4>
    <p>The third rejection turns into a question for a human. Until it is answered nobody can claim the work, and the answer rides in the next claim along with every attempt.</p>
  </div>
</div>
</section>

<section id="run">
<h2>Run it yourself</h2>

<p>
  Both examples start a throwaway <code>hird-server</code> on a temporary
  database with a generated roster, so nothing touches your real queue.
</p>

<pre><code><span class="c"># a factory of your own, with a guided tour</span>
<span class="k">hird-server quickstart</span> --tour

<span class="c"># the run on this page: scripted, the same every time</span>
<span class="k">./examples/factory.sh</span>              <span class="c"># prints every call and the server's answer</span>
<span class="k">./examples/factory.sh</span> --pause      <span class="c"># stops between acts; open the /watch URL it prints</span>

<span class="c"># a crew working at random, for watching the live floor</span>
<span class="k">just floor</span>
<span class="c">#   The floor:  http://127.0.0.1:7474/watch#token=…</span></code></pre>

<p>
  For a real deployment, start from
  <a href="https://github.com/aoprisan/hird/blob/main/examples/factory-roster.toml"><code>examples/factory-roster.toml</code></a>.
  The design, with every allowed and forbidden transition, is
  <a href="https://github.com/aoprisan/hird/blob/main/DESIGN.md">DESIGN.md &sect;33</a>.
</p>
</section>

</main>
</div>

<footer class="page">
  <span>hird &mdash; a work queue for coding agents</span>
  <span><a href="index.html">Usage guide</a> · <a href="server.html">The central queue</a> · <a href="swarm.html">The swarm</a></span>
</footer>

<script>
  // Theme toggle: follow the OS by default, remember an explicit choice.
  (function () {
    var root = document.documentElement;
    var saved = null;
    try { saved = localStorage.getItem("hird-theme"); } catch (e) {}
    if (saved) root.setAttribute("data-theme", saved);

    document.getElementById("theme").addEventListener("click", function () {
      var dark = root.getAttribute("data-theme") === "dark" ||
        (!root.getAttribute("data-theme") &&
          window.matchMedia("(prefers-color-scheme: dark)").matches);
      var next = dark ? "light" : "dark";
      root.setAttribute("data-theme", next);
      try { localStorage.setItem("hird-theme", next); } catch (e) {}
    });
  })();

  // On a phone the contents fold away, so the page starts at the page.
  (function () {
    var nav = document.querySelector("nav.toc .nav-body");
    var narrow = window.matchMedia("(max-width: 62rem)");
    if (!nav) return;
    if (narrow.matches) nav.removeAttribute("open");
    nav.addEventListener("click", function (event) {
      if (narrow.matches && event.target.closest("a")) nav.removeAttribute("open");
    });
  })();
</script>

<script>
/* ===========================================================================
   The player.

   examples/factory.sh as a list of beats. Each beat names the calls it made,
   what the server answered, and how it changes the board. The board at beat
   N is rebuilt by replaying beats 0..N, so stepping back is exact.
   =========================================================================== */
(function () {
  "use strict";

  var $ = function (id) { return document.getElementById(id); };

  var CREW = [
    { id: "ana", harness: "claude-code", role: "builder" },
    { id: "ben", harness: "codex", role: "builder" },
    { id: "cy", harness: "codex", role: "reviewer" },
    { id: "eve", harness: "copilot", role: "reviewer" },
    { id: "ci", harness: "ci", role: "ci" },
    { id: "dee", harness: "human", role: "human" }
  ];

  var STAGES = ["ready", "claimed", "built", "in_review", "approved", "merged", "escalated"];
  var LABEL = { in_review: "in review" };

  var TITLES = {
    1: "Parse the config format",
    2: "Wire the config into the server",
    3: "Fix the flaky lease-expiry test"
  };

  // A call: [who, tool, args, ok?, answer]. `set` moves tasks: {seq: {stage, ...}}.
  var BEATS = [
    { act: "dee files the release",
      calls: [["dee", "hird add", "Parse the config format", true, "1"],
              ["dee", "hird add", "Wire the config into the server --needs 1", true, "2"],
              ["dee", "hird add", "Fix the flaky lease-expiry test --priority 1", true, "3"]],
      why: "Three tasks. #2 waits on #1; in a factory that means until #1 is merged, not merely done.",
      set: { 1: { stage: "ready" }, 2: { stage: "ready", waits: [1] }, 3: { stage: "ready" } } },

    { act: "ana claims #1",
      calls: [["ana", "task_claim", '{"seq":1}', true, '{"claimed":1,"holder":"ana/claude-code:6bdz"}'],
              ["ana", "task_update", '{"seq":1,"branch":"feat/parse-config","pr_url":"…/pull/1"}', true, '{"links":{"branch":"feat/parse-config"}}']],
      why: "A builder pulls work and records its branch and pull request on the task.",
      set: { 1: { stage: "claimed", holder: "ana" } } },

    { act: "ana finishes #1 — the factory files its review",
      calls: [["ana", "task_complete", '{"seq":1,"result":"Parser and tests…"}', true, '{"status":"done","review_filed":4}']],
      why: "Every completion files a review in a factory, even though the server never sees the working tree.",
      set: { 1: { stage: "built", holder: null, review: 4 } } },

    { act: "a builder may not review, nor start on unmerged work",
      calls: [["ana", "task_claim", '{"seq":4}', false, "task 4 is recused from task 1 (no agent reviews its own work) — ana/claude-code cannot take it"],
              ["ana", "task_claim", '{"seq":2}', false, "task 2 depends on work that is not merged yet: 1; in this factory a dependency clears only once it is merged"]],
      why: "Two refusals, both inside the claim's own transaction, both leaving no trace.",
      set: {} },

    { act: "CI fails #1",
      calls: [["ci", "factory_gate", '{"seq":1,"outcome":"fail","output":"test_parse_empty … FAILED"}', true, '{"from":"built","to":"ready","attempts":1}']],
      why: "A failure is an attempt: who held it, what model it ran, and the output, kept for the next builder. The pending review is cancelled.",
      set: { 1: { stage: "ready", attempts: 1, review: null, ci: "fail" } } },

    { act: "ben picks #1 up, and is handed what went wrong",
      calls: [["ben", "task_claim", '{"seq":1}', true, '{"claimed":1,"attempts":[{"n":1,"by":"CI","output":"test_parse_empty … FAILED"}]}'],
              ["ben", "task_complete", '{"seq":1,"result":"Empty input is now an empty Config"}', true, '{"status":"done","review_filed":5}']],
      why: "The claim carries every earlier attempt, with a reminder to fix the latest first.",
      set: { 1: { stage: "built", review: 5, holders: ["ana", "ben"] } } },

    { act: "cy runs codex, like ben: no review for cy",
      calls: [["cy", "task_next", "{}", false, "idle: 1 task is ready, but every one is a review of work this harness did — they need an agent in another harness"]],
      why: "reviewer_harness_differs: no harness that held the work reviews it. ben is codex, so every codex session is barred.",
      set: {} },

    { act: "eve (copilot) reviews #1 and upholds it",
      calls: [["eve", "task_claim", '{"seq":5}', true, '{"claimed":5,"title":"Review: Parse the config format"}'],
              ["eve", "task_complete", '{"seq":5,"verdict":"upheld"}', true, '{"verdicts":["task 1 upheld — the work stands"]}']],
      why: "Upheld after the latest completion: approved. Not yet merged.",
      phases: [{ 1: { stage: "in_review", reviewer: "eve" } }, { 1: { stage: "approved", reviewer: null } }] },

    { act: "approved is not merged",
      calls: [["ana", "factory_merge", '{"seq":1,"evidence":"4f2a9c1"}', false, "recording a merge needs one of the ci, human roles, and this connection is builder"],
              ["ci", "factory_merge", '{"seq":1,"evidence":"4f2a9c1"}', false, "the latest CI report on it is not a pass, and this factory merges only work CI has passed"]],
      why: "Roles first, then policy: require_ci_to_merge reads CI's latest word, which is still the fail.",
      set: {} },

    { act: "CI passes #1 and merges it — #2 is free",
      calls: [["ci", "factory_gate", '{"seq":1,"outcome":"pass"}', true, '{"from":"approved","to":"approved"}'],
              ["ci", "factory_merge", '{"seq":1,"evidence":"4f2a9c1"}', true, '{"from":"approved","to":"merged"}']],
      why: "A merge needs evidence: a SHA or a PR URL. It announces the dependents it frees.",
      set: { 1: { stage: "merged", ci: "pass" }, 2: { waits: [] } } },

    { act: "the flaky test, round 1",
      calls: [["ana", "task_claim", '{"seq":3}', true, '{"claimed":3}'],
              ["ana", "task_complete", '{"seq":3,"result":"Raised the timeout to 2s."}', true, '{"review_filed":6}'],
              ["ci", "factory_gate", '{"seq":3,"outcome":"fail"}', true, '{"from":"built","to":"ready","attempts":1}']],
      why: "Built, then failed by CI before anyone reviewed it.",
      phases: [{ 3: { stage: "claimed", holder: "ana" } }, { 3: { stage: "built", holder: null } }, { 3: { stage: "ready", attempts: 1 } }] },

    { act: "round 2",
      calls: [["ana", "task_claim", '{"seq":3}', true, '{"claimed":3,"attempts":[…1]}'],
              ["ana", "task_complete", '{"seq":3}', true, '{"review_filed":7}'],
              ["ci", "factory_gate", '{"seq":3,"outcome":"fail"}', true, '{"from":"built","to":"ready","attempts":2}']],
      why: "Same fix, same failure.",
      phases: [{ 3: { stage: "claimed", holder: "ana" } }, { 3: { stage: "built", holder: null } }, { 3: { stage: "ready", attempts: 2 } }] },

    { act: "round 3: escalated",
      calls: [["ana", "task_claim", '{"seq":3}', true, '{"claimed":3,"attempts":[…2]}'],
              ["ana", "task_complete", '{"seq":3}', true, '{"review_filed":8}'],
              ["ci", "factory_gate", '{"seq":3,"outcome":"fail"}', true, '{"from":"built","to":"escalated","attempts":3}']],
      why: "max_attempts = 3: the third rejection becomes a question for a human, not a fourth try.",
      phases: [{ 3: { stage: "claimed", holder: "ana" } }, { 3: { stage: "built", holder: null } }, { 3: { stage: "escalated", attempts: 3 } }] },

    { act: "nobody takes escalated work until dee answers",
      calls: [["ben", "task_claim", '{"seq":3}', false, "task 3 is awaiting an answer: This work has been rejected 3 times… use `hird answer 3` before an agent claims it"],
              ["dee", "factory_decide", '{"seq":3,"action":"answer","text":"Use a fake clock in the test."}', true, '{"from":"escalated","to":"ready"}']],
      why: "The answer rides in the next claim, beside all three attempts.",
      set: { 3: { stage: "ready" } } },

    { act: "ben builds #2; ana has another go at #3",
      calls: [["ben", "task_claim", '{"seq":2}', true, '{"claimed":2,"built_on":[{"seq":1,"standing":"upheld"}]}'],
              ["ben", "task_complete", '{"seq":2}', true, '{"review_filed":9}'],
              ["ana", "task_claim", '{"seq":3}', true, '{"claimed":3,"questions":[…],"attempts":[…3]}'],
              ["ana", "task_complete", '{"seq":3,"result":"The test drives a fake clock."}', true, '{"review_filed":10}']],
      why: "#2's claim is handed what it builds on: #1's result and its standing.",
      phases: [{ 2: { stage: "claimed", holder: "ben" } }, { 2: { stage: "built", holder: null, review: 9 } },
               { 3: { stage: "claimed", holder: "ana" } }, { 3: { stage: "built", holder: null, review: 10 } }] },

    { act: "each review goes to a harness that held none of the work",
      calls: [["eve", "task_claim", '{"seq":9}', true, '{"claimed":9,"title":"Review: Wire the config…"}'],
              ["cy", "task_claim", '{"seq":10}', true, '{"claimed":10,"title":"Review: Fix the flaky…"}'],
              ["eve", "task_complete", '{"seq":9,"verdict":"upheld"}', true, '{"verdicts":["task 2 upheld"]}'],
              ["cy", "task_complete", '{"seq":10,"verdict":"upheld"}', true, '{"verdicts":["task 3 upheld"]}']],
      why: "eve (copilot) reviews ben's codex work; cy (codex) may review ana's, which only claude-code ever held.",
      phases: [{ 2: { stage: "in_review", reviewer: "eve" } }, { 3: { stage: "in_review", reviewer: "cy" } },
               { 2: { stage: "approved", reviewer: null } }, { 3: { stage: "approved", reviewer: null } }] },

    { act: "CI passes both; the release is in",
      calls: [["ci", "factory_gate", '{"seq":2,"outcome":"pass"}', true, '{"to":"approved"}'],
              ["ci", "factory_gate", '{"seq":3,"outcome":"pass"}', true, '{"to":"approved"}'],
              ["ci", "factory_merge", '{"seq":2,"evidence":"9b1e07d"}', true, '{"from":"approved","to":"merged"}'],
              ["dee", "factory_merge", '{"seq":3,"evidence":"…/pull/3"}', true, '{"from":"approved","to":"merged"}']],
      why: "CI or the human may merge. Every move is on the append-only trail with its role, model and evidence.",
      phases: [{ 2: { ci: "pass" } }, { 3: { ci: "pass" } }, { 2: { stage: "merged" } }, { 3: { stage: "merged" } }] }
  ];

  // Flatten phases into one `set` per call so the board moves call by call.
  function steps(beat) {
    if (beat.phases) return beat.phases;
    return [beat.set || {}];
  }

  function stateAt(n, sub) {
    var tasks = {};
    for (var i = 0; i <= n; i++) {
      var ph = steps(BEATS[i]);
      var upto = i === n && sub != null ? Math.min(sub, ph.length - 1) : ph.length - 1;
      for (var j = 0; j <= upto; j++) {
        var set = ph[j];
        Object.keys(set).forEach(function (seq) {
          tasks[seq] = Object.assign({ attempts: 0, waits: [] }, tasks[seq] || {}, set[seq]);
        });
      }
    }
    return tasks;
  }

  // ------------------------------------------------------------- render
  var crewEl = $("crew"), lanesEl = $("lanes"), wireEl = $("wire");
  CREW.forEach(function (m) {
    var d = document.createElement("div");
    d.className = "member";
    d.id = "m-" + m.id;
    d.innerHTML = "<b>" + m.id + "</b><span class=\"h\">" + m.harness + "</span><br><span class=\"role\">" + m.role + "</span>";
    crewEl.appendChild(d);
  });
  STAGES.forEach(function (s) {
    var lane = document.createElement("div");
    lane.className = "lane " + s;
    lane.id = "lane-" + s;
    lane.innerHTML = "<h4>" + (LABEL[s] || s) + "</h4>";
    lanesEl.appendChild(lane);
  });

  function esc(s) {
    return String(s).replace(/[&<>"]/g, function (c) {
      return { "&": "&amp;", "<": "&lt;", ">": "&gt;", "\"": "&quot;" }[c];
    });
  }

  var shown = {};   // seq -> stage drawn last, to mark what moved

  function render(n, sub) {
    var beat = BEATS[n];
    var tasks = stateAt(n, sub);
    var calls = beat.calls;
    // A beat with phases moves one call at a time; one without shows every
    // call at once.
    var lastCall = beat.phases && sub != null ? sub : calls.length - 1;

    $("act").innerHTML = esc(beat.act) + "<small>step " + (n + 1) + " of " + BEATS.length + "</small>";
    $("clock").textContent = (n + 1) + " / " + BEATS.length;

    // crew: who is acting, and whether the server said no
    CREW.forEach(function (m) {
      var el = $("m-" + m.id);
      var acted = calls.slice(0, lastCall + 1).filter(function (c) { return c[0] === m.id; });
      el.classList.toggle("on", acted.length > 0);
      el.classList.toggle("no", acted.some(function (c) { return !c[3]; }));
    });

    // FLIP: remember where each card was, redraw, then slide from there.
    var before = {};
    lanesEl.querySelectorAll(".tcard").forEach(function (c) {
      before[c.dataset.seq] = c.getBoundingClientRect();
    });
    lanesEl.querySelectorAll(".tcard").forEach(function (c) { c.remove(); });

    Object.keys(tasks).sort().forEach(function (seq) {
      var t = tasks[seq];
      var card = document.createElement("div");
      card.className = "tcard";
      card.dataset.seq = seq;
      card.dataset.stage = t.stage;
      var meta = [];
      if (t.holder) meta.push("held by " + t.holder);
      if (t.reviewer) meta.push("review: " + t.reviewer);
      if (t.waits && t.waits.length) meta.push("waits on #" + t.waits.join(", #"));
      if (t.attempts) meta.push("attempts " + t.attempts);
      if (t.ci) meta.push("CI " + t.ci);
      card.innerHTML = "<span class=\"n\">#" + seq + "</span> " + esc(TITLES[seq]) +
        (meta.length ? "<span class=\"meta\">" + esc(meta.join(" · ")) + "</span>" : "");
      if (shown[seq] && shown[seq] !== t.stage) card.classList.add("moved");
      $("lane-" + t.stage).appendChild(card);
      shown[seq] = t.stage;
    });

    if (!reduce) {
      lanesEl.querySelectorAll(".tcard").forEach(function (c) {
        var was = before[c.dataset.seq];
        if (!was) return;
        var now = c.getBoundingClientRect();
        var dx = was.left - now.left, dy = was.top - now.top;
        if (!dx && !dy) return;
        c.style.transition = "none";
        c.style.transform = "translate(" + dx + "px," + dy + "px)";
        requestAnimationFrame(function () {
          requestAnimationFrame(function () {
            c.style.transition = "transform 0.45s ease";
            c.style.transform = "";
          });
        });
      });
    }

    // the wire
    var html = "";
    calls.slice(0, lastCall + 1).forEach(function (c) {
      html += "<div class=\"call\"><span class=\"who\">" + esc(c[0]) + "</span> " + esc(c[1]) + " " + esc(c[2]) + "</div>";
      html += "<div class=\"" + (c[3] ? "ok" : "no") + "\">" + (c[3] ? "→ " : "REFUSED: ") + esc(c[4]) + "</div>";
    });
    if (sub == null || lastCall === calls.length - 1) html += "<div class=\"why\">" + esc(beat.why) + "</div>";
    wireEl.innerHTML = html;

    document.querySelectorAll("#beat-list li").forEach(function (li, i) {
      li.classList.toggle("here", i === n);
    });
    $("prev").disabled = n === 0 && !sub;
    $("next").disabled = n === BEATS.length - 1 && (sub == null || sub >= steps(beat).length - 1);
  }

  // ------------------------------------------------------------- playback
  var reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
  var idx = 0, sub = null, playing = false, timer = null, speed = 1;

  function go(n, s) {
    idx = Math.max(0, Math.min(BEATS.length - 1, n));
    sub = s;
    render(idx, sub);
  }

  function forward() {
    var count = steps(BEATS[idx]).length;
    if (sub != null && sub < count - 1) { go(idx, sub + 1); return true; }
    if (idx >= BEATS.length - 1) return false;
    var nextCount = steps(BEATS[idx + 1]).length;
    go(idx + 1, nextCount > 1 ? 0 : null);
    return true;
  }

  function back() {
    if (sub != null && sub > 0) { go(idx, sub - 1); return; }
    if (idx === 0) return;
    go(idx - 1, null);
  }

  function schedule() {
    window.clearTimeout(timer);
    if (!playing) return;
    var last = sub == null || sub >= steps(BEATS[idx]).length - 1;
    timer = window.setTimeout(function () {
      if (!forward()) { stop(); return; }
      schedule();
    }, (last ? 3200 : 1300) / speed);
  }

  function play() {
    if (idx >= BEATS.length - 1 && (sub == null || sub >= steps(BEATS[idx]).length - 1)) go(0, null);
    playing = true; $("play").textContent = "Pause"; schedule();
  }
  function stop() { playing = false; $("play").textContent = "Play"; window.clearTimeout(timer); }

  $("play").addEventListener("click", function () { playing ? stop() : play(); });
  $("next").addEventListener("click", function () { stop(); forward(); });
  $("prev").addEventListener("click", function () { stop(); back(); });
  $("restart").addEventListener("click", function () { shown = {}; go(0, null); play(); });
  $("speed").addEventListener("change", function () { speed = parseFloat(this.value) || 1; schedule(); });

  // the run, in words
  var list = $("beat-list");
  BEATS.forEach(function (b, i) {
    var li = document.createElement("li");
    var btn = document.createElement("button");
    btn.type = "button";
    btn.textContent = b.act;
    btn.addEventListener("click", function () {
      stop(); go(i, null);
      $("player").scrollIntoView({ behavior: reduce ? "auto" : "smooth", block: "start" });
    });
    li.appendChild(btn);
    var refused = b.calls.filter(function (c) { return !c[3]; }).length;
    if (refused) {
      var s = document.createElement("span");
      s.className = "refused";
      s.textContent = refused === 1 ? "1 refusal" : refused + " refusals";
      li.appendChild(s);
    }
    list.appendChild(li);
  });

  go(0, null);

  // Play once the player is on screen, and only while it is.
  if ("IntersectionObserver" in window && !reduce) {
    var started = false;
    new IntersectionObserver(function (entries) {
      if (entries[0].isIntersecting && !started) { started = true; play(); }
      else if (!entries[0].isIntersecting && playing) { window.clearTimeout(timer); }
      else if (entries[0].isIntersecting && playing) { schedule(); }
    }, { threshold: 0.3 }).observe($("player"));
  }
})();
</script>
</body>
</html>