project-spec 0.0.0-stage → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3615 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Spec</title>
7
+ <style>
8
+ :root {
9
+ color-scheme: light;
10
+ --paper: #ffffff;
11
+ --soft: #f5f4f1;
12
+ --raised: #fafaf8;
13
+ --night: #0e0f11;
14
+ --ink: #111214;
15
+ --muted: #5b5e66;
16
+ --subtle: #8a8d94;
17
+ --line: #e7e5e1;
18
+ --line-strong: #d9d6d0;
19
+ --accent: #eba417;
20
+ --accent-soft: #fcefcf;
21
+ --accent-ink: #a16207;
22
+ --success: #15803d;
23
+ --success-soft: #e8f5ec;
24
+ --notice-soft: #fff7e6;
25
+ --notice-ink: #3d2a00;
26
+ --notice-line: #f3d9a4;
27
+ --on-night-muted: #a9acb3;
28
+ --display: "Inter Tight", Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
29
+ --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
30
+ --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
31
+ }
32
+ * {
33
+ box-sizing: border-box;
34
+ }
35
+ body {
36
+ margin: 0;
37
+ background: var(--paper);
38
+ color: var(--ink);
39
+ font: 15px/1.55 var(--sans);
40
+ }
41
+ button,
42
+ input,
43
+ select,
44
+ textarea {
45
+ font: inherit;
46
+ color: inherit;
47
+ }
48
+ button {
49
+ cursor: pointer;
50
+ }
51
+ button:disabled {
52
+ cursor: default;
53
+ }
54
+ :focus-visible {
55
+ outline: 3px solid var(--accent);
56
+ outline-offset: 2px;
57
+ }
58
+ [hidden] {
59
+ display: none !important;
60
+ }
61
+ h1,
62
+ h2,
63
+ h3,
64
+ p {
65
+ margin: 0;
66
+ }
67
+
68
+ /* Shell: the tree stays on the left, the page scrolls on the right. */
69
+ .app {
70
+ display: flex;
71
+ align-items: flex-start;
72
+ min-height: 100vh;
73
+ }
74
+ .side {
75
+ flex: 0 0 304px;
76
+ position: sticky;
77
+ top: 0;
78
+ height: 100vh;
79
+ overflow: auto;
80
+ padding: 24px 16px 32px;
81
+ border-right: 1px solid var(--line);
82
+ background: var(--raised);
83
+ display: flex;
84
+ flex-direction: column;
85
+ gap: 20px;
86
+ }
87
+ .main {
88
+ flex: 1;
89
+ min-width: 0;
90
+ }
91
+ .brand {
92
+ display: flex;
93
+ flex-direction: column;
94
+ gap: 4px;
95
+ padding: 0 10px;
96
+ }
97
+ .brand strong {
98
+ font: 800 19px/1.2 var(--display);
99
+ letter-spacing: -0.05em;
100
+ white-space: nowrap;
101
+ overflow: hidden;
102
+ text-overflow: ellipsis;
103
+ }
104
+ .mono-label,
105
+ .eyebrow {
106
+ font: 500 12px/1.33 var(--mono);
107
+ letter-spacing: 0.08em;
108
+ text-transform: uppercase;
109
+ color: var(--muted);
110
+ }
111
+ .eyebrow {
112
+ display: flex;
113
+ align-items: center;
114
+ gap: 8px;
115
+ }
116
+ .eyebrow::before {
117
+ content: "";
118
+ flex: none;
119
+ width: 6px;
120
+ height: 6px;
121
+ background: var(--accent);
122
+ }
123
+ .side .eyebrow {
124
+ padding: 0 10px;
125
+ }
126
+ .searchbox {
127
+ display: flex;
128
+ align-items: center;
129
+ gap: 10px;
130
+ width: 100%;
131
+ height: 44px;
132
+ padding: 0 14px;
133
+ border: 1px solid var(--line-strong);
134
+ border-radius: 999px;
135
+ background: var(--paper);
136
+ color: var(--muted);
137
+ font-size: 14px;
138
+ text-align: left;
139
+ }
140
+ .searchbox span {
141
+ flex: 1;
142
+ }
143
+ kbd {
144
+ font: 12px var(--mono);
145
+ color: var(--muted);
146
+ border: 1px solid var(--line);
147
+ border-radius: 6px;
148
+ padding: 1px 6px;
149
+ background: var(--paper);
150
+ }
151
+ .nav-links,
152
+ .tree {
153
+ display: flex;
154
+ flex-direction: column;
155
+ gap: 2px;
156
+ }
157
+ .nav-link,
158
+ .tree-row {
159
+ display: flex;
160
+ align-items: center;
161
+ gap: 8px;
162
+ width: 100%;
163
+ min-height: 44px;
164
+ padding: 6px 10px;
165
+ border: 0;
166
+ border-radius: 10px;
167
+ background: none;
168
+ font-size: 14px;
169
+ line-height: 1.35;
170
+ text-align: left;
171
+ }
172
+ .nav-link {
173
+ font-weight: 500;
174
+ }
175
+ .nav-link span:first-child,
176
+ .tree-row .label {
177
+ flex: 1;
178
+ min-width: 0;
179
+ white-space: nowrap;
180
+ overflow: hidden;
181
+ text-overflow: ellipsis;
182
+ }
183
+ .nav-link .meta,
184
+ .tree-row .meta {
185
+ flex: none;
186
+ font: 12px var(--mono);
187
+ color: var(--muted);
188
+ }
189
+ .tree-row .meta {
190
+ color: var(--accent-ink);
191
+ }
192
+ .nav-link:hover,
193
+ .tree-row:hover,
194
+ .twist:hover {
195
+ background: var(--soft);
196
+ }
197
+ .nav-link[aria-current="page"],
198
+ .tree-row[aria-current="page"] {
199
+ background: var(--soft);
200
+ font-weight: 600;
201
+ color: var(--ink);
202
+ }
203
+ .tree-area {
204
+ display: flex;
205
+ align-items: stretch;
206
+ }
207
+ .twist {
208
+ flex: none;
209
+ width: 32px;
210
+ display: grid;
211
+ place-items: center;
212
+ border: 0;
213
+ border-radius: 10px;
214
+ background: none;
215
+ color: var(--muted);
216
+ }
217
+ .twist svg {
218
+ transition: transform 0.12s;
219
+ }
220
+ .twist[aria-expanded="true"] svg {
221
+ transform: rotate(90deg);
222
+ }
223
+ .tree-row.area {
224
+ font-weight: 600;
225
+ padding-left: 4px;
226
+ }
227
+ .tree-row.note {
228
+ padding-left: 40px;
229
+ color: var(--muted);
230
+ }
231
+
232
+ /* Top bar: where you are, and what you can do with the page. */
233
+ .topbar {
234
+ position: sticky;
235
+ top: 0;
236
+ z-index: 5;
237
+ display: flex;
238
+ align-items: center;
239
+ gap: 12px;
240
+ height: 68px;
241
+ padding: 0 32px;
242
+ border-bottom: 1px solid var(--line);
243
+ background: var(--paper);
244
+ }
245
+ .icon-btn {
246
+ width: 44px;
247
+ height: 44px;
248
+ display: grid;
249
+ place-items: center;
250
+ border: 1px solid var(--line-strong);
251
+ border-radius: 999px;
252
+ background: var(--paper);
253
+ }
254
+ .icon-btn:disabled {
255
+ border-color: var(--line);
256
+ color: var(--subtle);
257
+ }
258
+ /* One line whatever the page is called, so the bar keeps its height from page to page. */
259
+ .crumbs {
260
+ flex: 1 1 0;
261
+ min-width: 0;
262
+ display: flex;
263
+ align-items: center;
264
+ gap: 8px;
265
+ font-size: 14px;
266
+ color: var(--muted);
267
+ white-space: nowrap;
268
+ }
269
+ .crumbs > * {
270
+ flex: 0 1 auto;
271
+ min-width: 0;
272
+ overflow: hidden;
273
+ text-overflow: ellipsis;
274
+ }
275
+ .crumbs > span:not(.here) {
276
+ flex: none;
277
+ }
278
+ /* When room runs out, the name of the page you are on gives way first, then the path before it. */
279
+ .crumbs .here {
280
+ flex-shrink: 50;
281
+ min-width: 12ch;
282
+ }
283
+ .crumbs button {
284
+ min-width: 4ch;
285
+ }
286
+ .crumbs button {
287
+ border: 0;
288
+ padding: 0;
289
+ background: none;
290
+ color: var(--muted);
291
+ text-align: left;
292
+ max-width: 28ch;
293
+ }
294
+ .crumbs button:hover {
295
+ color: var(--accent-ink);
296
+ text-decoration: underline;
297
+ }
298
+ .crumbs .here {
299
+ color: var(--ink);
300
+ font-weight: 600;
301
+ }
302
+ .toast {
303
+ flex: none;
304
+ font-size: 13px;
305
+ color: var(--success);
306
+ font-weight: 600;
307
+ }
308
+ .btn {
309
+ height: 44px;
310
+ display: inline-flex;
311
+ align-items: center;
312
+ gap: 8px;
313
+ padding: 0 18px;
314
+ border: 1px solid var(--line-strong);
315
+ border-radius: 999px;
316
+ background: var(--paper);
317
+ color: var(--ink);
318
+ font: 600 14px/1 var(--sans);
319
+ white-space: nowrap;
320
+ }
321
+ .btn:hover {
322
+ border-color: var(--ink);
323
+ }
324
+ .btn.accent {
325
+ border-color: var(--accent);
326
+ background: var(--accent);
327
+ }
328
+ .btn.large {
329
+ height: 50px;
330
+ padding: 0 24px;
331
+ font-size: 15px;
332
+ }
333
+ .pillrow {
334
+ display: flex;
335
+ flex-wrap: wrap;
336
+ gap: 8px;
337
+ }
338
+ .pill {
339
+ height: 44px;
340
+ display: inline-flex;
341
+ align-items: center;
342
+ gap: 8px;
343
+ padding: 0 16px;
344
+ border: 1px solid var(--line-strong);
345
+ border-radius: 999px;
346
+ background: var(--paper);
347
+ font: 600 14px/1 var(--sans);
348
+ }
349
+ .pill[aria-pressed="true"] {
350
+ border-color: var(--ink);
351
+ background: var(--ink);
352
+ color: #ffffff;
353
+ }
354
+ .pill .n {
355
+ font: 12px var(--mono);
356
+ opacity: 0.75;
357
+ }
358
+ select {
359
+ height: 44px;
360
+ padding: 0 14px;
361
+ border: 1px solid var(--line-strong);
362
+ border-radius: 999px;
363
+ background: var(--paper);
364
+ font-size: 14px;
365
+ }
366
+
367
+ /* Page */
368
+ .view {
369
+ padding: 40px 32px 80px;
370
+ }
371
+ /* The map takes the rest of the window: one row of controls, then the map, no page scroll. */
372
+ .mapview {
373
+ height: calc(100vh - 68px);
374
+ padding: 14px 32px 20px;
375
+ display: flex;
376
+ flex-direction: column;
377
+ gap: 12px;
378
+ }
379
+ .map-head {
380
+ display: flex;
381
+ flex-wrap: wrap;
382
+ align-items: center;
383
+ gap: 10px 16px;
384
+ }
385
+ .map-head h1 {
386
+ font: 700 22px/1.2 var(--display);
387
+ letter-spacing: -0.03em;
388
+ white-space: nowrap;
389
+ }
390
+ .map-head .pill,
391
+ .map-head select {
392
+ height: 34px;
393
+ }
394
+ .map-head .pill {
395
+ padding: 0 12px;
396
+ font-size: 13px;
397
+ }
398
+ .map-head select {
399
+ max-width: 220px;
400
+ }
401
+ .map-head .pillrow {
402
+ gap: 6px;
403
+ }
404
+ .view:has(> .compact) {
405
+ padding-top: 18px;
406
+ }
407
+ .stack.compact {
408
+ gap: 14px;
409
+ max-width: none;
410
+ }
411
+ .stack.compact > .card {
412
+ max-width: 1100px;
413
+ }
414
+ .stack {
415
+ display: flex;
416
+ flex-direction: column;
417
+ gap: 24px;
418
+ max-width: 860px;
419
+ }
420
+ .page {
421
+ display: flex;
422
+ flex-wrap: wrap;
423
+ gap: 48px;
424
+ align-items: flex-start;
425
+ }
426
+ .page-main {
427
+ flex: 999 1 520px;
428
+ min-width: 0;
429
+ max-width: 780px;
430
+ display: flex;
431
+ flex-direction: column;
432
+ gap: 24px;
433
+ }
434
+ .rail {
435
+ flex: 1 1 240px;
436
+ max-width: 320px;
437
+ display: flex;
438
+ flex-direction: column;
439
+ gap: 24px;
440
+ }
441
+ .title {
442
+ font: 700 44px/1.04 var(--display);
443
+ letter-spacing: -0.045em;
444
+ overflow-wrap: anywhere;
445
+ }
446
+ .title .quiet {
447
+ color: var(--subtle);
448
+ }
449
+ .h2 {
450
+ font: 700 22px/1.2 var(--display);
451
+ letter-spacing: -0.03em;
452
+ }
453
+ .h2 button {
454
+ border: 0;
455
+ padding: 0;
456
+ background: none;
457
+ font: inherit;
458
+ letter-spacing: inherit;
459
+ text-align: left;
460
+ }
461
+ .h2 button:hover {
462
+ color: var(--accent-ink);
463
+ }
464
+ .lead {
465
+ font-size: 19px;
466
+ line-height: 1.55;
467
+ color: var(--muted);
468
+ }
469
+ .muted {
470
+ color: var(--muted);
471
+ }
472
+ .small {
473
+ font-size: 13px;
474
+ }
475
+ .path {
476
+ font: 13px var(--mono);
477
+ color: var(--muted);
478
+ overflow-wrap: anywhere;
479
+ }
480
+ .metarow {
481
+ display: flex;
482
+ flex-wrap: wrap;
483
+ align-items: center;
484
+ gap: 8px 12px;
485
+ }
486
+ .badge {
487
+ display: inline-flex;
488
+ align-items: center;
489
+ gap: 8px;
490
+ min-height: 30px;
491
+ padding: 0 12px;
492
+ border-radius: 999px;
493
+ background: var(--soft);
494
+ color: var(--ink);
495
+ font-size: 13px;
496
+ font-weight: 600;
497
+ white-space: nowrap;
498
+ }
499
+ .badge::before {
500
+ content: "";
501
+ width: 8px;
502
+ height: 8px;
503
+ border-radius: 999px;
504
+ background: var(--subtle);
505
+ }
506
+ .badge.ok {
507
+ background: var(--success-soft);
508
+ color: var(--success);
509
+ }
510
+ .badge.ok::before,
511
+ .badge.st-accepted::before,
512
+ .badge.st-done::before {
513
+ background: var(--success);
514
+ }
515
+ .badge.st-needs-recheck,
516
+ .badge.outdated,
517
+ .badge.stale,
518
+ .badge.pending {
519
+ background: var(--accent-soft);
520
+ color: var(--notice-ink);
521
+ }
522
+ .badge.st-needs-recheck::before,
523
+ .badge.outdated::before,
524
+ .badge.stale::before,
525
+ .badge.pending::before {
526
+ background: var(--accent);
527
+ }
528
+ .badge.st-needs-decision::before {
529
+ background: var(--ink);
530
+ }
531
+ .badge.st-accepted,
532
+ .badge.st-done {
533
+ background: var(--success-soft);
534
+ color: var(--success);
535
+ }
536
+ .badge.plain::before {
537
+ display: none;
538
+ }
539
+ .chips {
540
+ display: flex;
541
+ flex-wrap: wrap;
542
+ gap: 8px;
543
+ }
544
+ .chip {
545
+ min-height: 44px;
546
+ display: inline-flex;
547
+ align-items: center;
548
+ padding: 6px 16px;
549
+ border: 1px solid var(--line);
550
+ border-radius: 999px;
551
+ background: var(--paper);
552
+ font-size: 14px;
553
+ text-align: left;
554
+ }
555
+ .chip:hover {
556
+ border-color: var(--ink);
557
+ }
558
+ .card {
559
+ display: flex;
560
+ flex-direction: column;
561
+ border: 1px solid var(--line);
562
+ border-radius: 20px;
563
+ overflow: hidden;
564
+ }
565
+ .card.pad {
566
+ padding: 20px;
567
+ gap: 12px;
568
+ }
569
+ .card-head {
570
+ display: flex;
571
+ flex-wrap: wrap;
572
+ align-items: center;
573
+ gap: 12px;
574
+ padding: 16px 20px;
575
+ border-bottom: 1px solid var(--line);
576
+ }
577
+ .card-head .h2 {
578
+ flex: 1 1 240px;
579
+ }
580
+ .card.notice {
581
+ border-color: var(--notice-line);
582
+ }
583
+ .card.notice .card-head {
584
+ background: var(--notice-soft);
585
+ color: var(--notice-ink);
586
+ border-color: var(--notice-line);
587
+ }
588
+ .row {
589
+ display: flex;
590
+ flex-wrap: wrap;
591
+ align-items: center;
592
+ gap: 8px 14px;
593
+ min-height: 52px;
594
+ padding: 10px 20px;
595
+ border-bottom: 1px solid var(--line);
596
+ }
597
+ .row:last-child {
598
+ border-bottom: 0;
599
+ }
600
+ .row.slim {
601
+ min-height: 44px;
602
+ padding: 6px 20px;
603
+ }
604
+ .row.slim .grow {
605
+ flex: 1 1 200px;
606
+ }
607
+ .row.slim .rowlink,
608
+ .row.slim .grow > span {
609
+ max-width: 100%;
610
+ white-space: nowrap;
611
+ overflow: hidden;
612
+ text-overflow: ellipsis;
613
+ }
614
+ .row.slim .path {
615
+ flex: 0 1 auto;
616
+ max-width: 38%;
617
+ white-space: nowrap;
618
+ overflow: hidden;
619
+ text-overflow: ellipsis;
620
+ }
621
+ .tag {
622
+ flex: none;
623
+ width: 64px;
624
+ font: 500 11px/1.4 var(--mono);
625
+ letter-spacing: 0.06em;
626
+ text-transform: uppercase;
627
+ color: var(--muted);
628
+ }
629
+ .tag.added {
630
+ color: var(--success);
631
+ }
632
+ .tag.removed {
633
+ text-decoration: line-through;
634
+ }
635
+ details.what {
636
+ flex: none;
637
+ font-size: 13px;
638
+ }
639
+ details.what > summary {
640
+ cursor: pointer;
641
+ color: var(--accent-ink);
642
+ }
643
+ details.what[open] {
644
+ flex: 1 1 100%;
645
+ order: 9;
646
+ }
647
+ details.what[open] > summary {
648
+ margin-bottom: 6px;
649
+ }
650
+ .group {
651
+ padding: 12px 20px 4px;
652
+ }
653
+ .commit summary.card-head {
654
+ cursor: pointer;
655
+ list-style: none;
656
+ border-bottom: 0;
657
+ flex-wrap: nowrap;
658
+ }
659
+ .commit summary.card-head::-webkit-details-marker {
660
+ display: none;
661
+ }
662
+ .commit summary.card-head:hover {
663
+ background: var(--raised);
664
+ }
665
+ .commit summary.card-head svg {
666
+ flex: none;
667
+ color: var(--muted);
668
+ transition: transform 0.12s;
669
+ }
670
+ .commit details[open] > summary.card-head {
671
+ border-bottom: 1px solid var(--line);
672
+ }
673
+ .commit details[open] > summary.card-head svg {
674
+ transform: rotate(90deg);
675
+ }
676
+ .commit .grow {
677
+ flex: 1;
678
+ min-width: 0;
679
+ display: flex;
680
+ flex-direction: column;
681
+ gap: 2px;
682
+ }
683
+ .h3 {
684
+ font: 600 16px/1.3 var(--sans);
685
+ white-space: nowrap;
686
+ overflow: hidden;
687
+ text-overflow: ellipsis;
688
+ }
689
+ .row .grow {
690
+ flex: 1 1 260px;
691
+ min-width: 0;
692
+ display: flex;
693
+ flex-direction: column;
694
+ gap: 2px;
695
+ }
696
+ .rowlink {
697
+ border: 0;
698
+ padding: 0;
699
+ background: none;
700
+ font-weight: 600;
701
+ text-align: left;
702
+ }
703
+ .rowlink:hover {
704
+ color: var(--accent-ink);
705
+ text-decoration: underline;
706
+ }
707
+ .feature {
708
+ display: flex;
709
+ flex-direction: column;
710
+ gap: 4px;
711
+ padding: 14px 0;
712
+ border-top: 1px solid var(--line);
713
+ }
714
+ .feature .rowlink {
715
+ font-size: 16px;
716
+ }
717
+ details.fold {
718
+ border-top: 1px solid var(--line);
719
+ }
720
+ details.fold:last-of-type {
721
+ border-bottom: 1px solid var(--line);
722
+ }
723
+ details.fold > summary {
724
+ min-height: 52px;
725
+ display: flex;
726
+ align-items: center;
727
+ cursor: pointer;
728
+ font-weight: 600;
729
+ }
730
+ details.fold[open] > summary {
731
+ margin-bottom: 8px;
732
+ }
733
+ details.fold > :last-child {
734
+ margin-bottom: 20px;
735
+ }
736
+ .here-path {
737
+ display: flex;
738
+ flex-direction: column;
739
+ gap: 8px;
740
+ font-size: 14px;
741
+ }
742
+ .here-path button {
743
+ border: 0;
744
+ border-left: 1px solid var(--line-strong);
745
+ padding: 0 0 0 14px;
746
+ background: none;
747
+ color: var(--muted);
748
+ text-align: left;
749
+ }
750
+ .here-path button:first-child {
751
+ border-left: 0;
752
+ padding-left: 0;
753
+ }
754
+ .here-path .now {
755
+ margin-left: 14px;
756
+ padding-left: 14px;
757
+ border-left: 2px solid var(--ink);
758
+ font-weight: 600;
759
+ }
760
+ .recent {
761
+ display: flex;
762
+ flex-direction: column;
763
+ gap: 10px;
764
+ }
765
+ .recent button {
766
+ border: 0;
767
+ padding: 0;
768
+ background: none;
769
+ font-size: 14px;
770
+ text-align: left;
771
+ }
772
+ .recent button.more {
773
+ font-size: 13px;
774
+ color: var(--muted);
775
+ }
776
+ .pagefoot {
777
+ display: flex;
778
+ flex-wrap: wrap;
779
+ align-items: baseline;
780
+ gap: 4px 14px;
781
+ }
782
+ .recent button:hover,
783
+ .here-path button:hover {
784
+ color: var(--accent-ink);
785
+ text-decoration: underline;
786
+ }
787
+ .gap-facts {
788
+ padding: 16px 20px;
789
+ border: 1px solid var(--line);
790
+ border-left: 4px solid var(--subtle);
791
+ border-radius: 14px;
792
+ background: var(--raised);
793
+ }
794
+ .gap-facts.st-needs-recheck {
795
+ border-left-color: var(--accent);
796
+ }
797
+ .gap-facts.st-needs-decision {
798
+ border-left-color: var(--ink);
799
+ }
800
+ .gap-facts.st-accepted,
801
+ .gap-facts.st-done {
802
+ border-left-color: var(--success);
803
+ }
804
+ .gap-facts dl {
805
+ display: grid;
806
+ grid-template-columns: 110px minmax(0, 1fr);
807
+ gap: 8px 16px;
808
+ margin: 0;
809
+ font-size: 14px;
810
+ }
811
+ .gap-facts dt {
812
+ color: var(--muted);
813
+ }
814
+ .gap-facts dd {
815
+ margin: 0;
816
+ }
817
+ .link-block h2 {
818
+ font: 500 12px/1.33 var(--mono);
819
+ letter-spacing: 0.08em;
820
+ text-transform: uppercase;
821
+ color: var(--muted);
822
+ margin-bottom: 8px;
823
+ }
824
+ .link-list {
825
+ list-style: none;
826
+ margin: 0;
827
+ padding: 0;
828
+ display: flex;
829
+ flex-direction: column;
830
+ gap: 8px;
831
+ }
832
+ .link-list li {
833
+ display: flex;
834
+ flex-wrap: wrap;
835
+ align-items: center;
836
+ gap: 6px 10px;
837
+ }
838
+ .wasnow {
839
+ display: flex;
840
+ flex-direction: column;
841
+ gap: 4px;
842
+ width: 100%;
843
+ padding: 12px 14px;
844
+ border: 1px solid var(--line);
845
+ border-radius: 14px;
846
+ background: var(--raised);
847
+ font-size: 14px;
848
+ }
849
+ .wasnow div {
850
+ display: flex;
851
+ gap: 10px;
852
+ }
853
+ .wasnow b {
854
+ flex: none;
855
+ width: 32px;
856
+ font: 13px var(--mono);
857
+ color: var(--muted);
858
+ }
859
+ .wasnow .was span {
860
+ color: var(--muted);
861
+ text-decoration: line-through;
862
+ }
863
+ textarea {
864
+ width: 100%;
865
+ padding: 14px 16px;
866
+ border: 1px solid var(--line-strong);
867
+ border-radius: 14px;
868
+ background: var(--paper);
869
+ font: 16px/1.6 var(--sans);
870
+ resize: vertical;
871
+ }
872
+ .night {
873
+ display: flex;
874
+ flex-direction: column;
875
+ gap: 12px;
876
+ padding: 20px;
877
+ border-radius: 20px;
878
+ background: var(--night);
879
+ color: #ffffff;
880
+ min-width: 0;
881
+ }
882
+ .night .eyebrow,
883
+ .night .small {
884
+ color: var(--on-night-muted);
885
+ }
886
+ .night pre {
887
+ margin: 0;
888
+ max-height: 420px;
889
+ overflow: auto;
890
+ font: 13px/1.6 var(--mono);
891
+ white-space: pre-wrap;
892
+ overflow-wrap: anywhere;
893
+ }
894
+ .xbtn {
895
+ flex: none;
896
+ width: 44px;
897
+ height: 44px;
898
+ display: grid;
899
+ place-items: center;
900
+ border: 0;
901
+ border-radius: 999px;
902
+ background: none;
903
+ color: var(--muted);
904
+ }
905
+ .xbtn:hover {
906
+ background: var(--soft);
907
+ color: var(--ink);
908
+ }
909
+
910
+ /* Markdown */
911
+ .article {
912
+ line-height: 1.7;
913
+ overflow-wrap: anywhere;
914
+ }
915
+ .article h1,
916
+ .article h2,
917
+ .article h3,
918
+ .article h4 {
919
+ margin: 26px 0 10px;
920
+ font-family: var(--display);
921
+ letter-spacing: -0.03em;
922
+ line-height: 1.2;
923
+ }
924
+ .article > :first-child {
925
+ margin-top: 0;
926
+ }
927
+ .article h1 {
928
+ font-size: 26px;
929
+ }
930
+ .article h2 {
931
+ font-size: 22px;
932
+ }
933
+ .article h3 {
934
+ font-size: 17px;
935
+ }
936
+ .article p,
937
+ .article ul,
938
+ .article ol,
939
+ .article pre {
940
+ margin: 0 0 14px;
941
+ }
942
+ .article ul,
943
+ .article ol {
944
+ padding-left: 22px;
945
+ }
946
+ .article code {
947
+ background: var(--soft);
948
+ border-radius: 4px;
949
+ padding: 1px 5px;
950
+ font: 0.88em var(--mono);
951
+ }
952
+ .article pre {
953
+ background: var(--soft);
954
+ padding: 14px;
955
+ overflow: auto;
956
+ border-radius: 14px;
957
+ }
958
+ .article pre code {
959
+ padding: 0;
960
+ }
961
+ .article a,
962
+ .wiki {
963
+ color: var(--ink);
964
+ text-decoration: underline;
965
+ text-decoration-color: var(--line-strong);
966
+ text-underline-offset: 3px;
967
+ }
968
+ .article a:hover,
969
+ .wiki:hover {
970
+ color: var(--accent-ink);
971
+ text-decoration-color: currentColor;
972
+ }
973
+ .wiki {
974
+ border: 0;
975
+ padding: 0;
976
+ background: none;
977
+ font: inherit;
978
+ text-align: left;
979
+ }
980
+ .article .table-wrap {
981
+ overflow: auto;
982
+ margin: 0 0 14px;
983
+ }
984
+ .article table {
985
+ border-collapse: collapse;
986
+ width: 100%;
987
+ font-size: 14px;
988
+ line-height: 1.5;
989
+ /* Whole words set the column widths; a table that is too wide scrolls instead of breaking words letter by letter. */
990
+ overflow-wrap: break-word;
991
+ }
992
+ .article th,
993
+ .article td {
994
+ border: 1px solid var(--line);
995
+ padding: 7px 10px;
996
+ text-align: left;
997
+ vertical-align: top;
998
+ }
999
+ .article td.rule-id {
1000
+ font: 12.5px/1.7 var(--mono);
1001
+ color: var(--muted);
1002
+ white-space: nowrap;
1003
+ }
1004
+ .article th {
1005
+ background: var(--soft);
1006
+ white-space: nowrap;
1007
+ }
1008
+ .empty {
1009
+ color: var(--muted);
1010
+ padding: 12px 0;
1011
+ }
1012
+
1013
+ /* Map */
1014
+ .graph-wrap {
1015
+ position: relative;
1016
+ flex: 1;
1017
+ min-height: 320px;
1018
+ border: 1px solid var(--line);
1019
+ border-radius: 20px;
1020
+ background: var(--raised);
1021
+ overflow: hidden;
1022
+ }
1023
+ .graph-wrap svg {
1024
+ position: absolute;
1025
+ inset: 0;
1026
+ width: 100%;
1027
+ height: 100%;
1028
+ display: block;
1029
+ touch-action: none;
1030
+ cursor: grab;
1031
+ }
1032
+ .graph-wrap svg.dragging {
1033
+ cursor: grabbing;
1034
+ }
1035
+ .graph-wrap line {
1036
+ stroke: #b3afa6;
1037
+ stroke-width: 1.5;
1038
+ }
1039
+ .graph-wrap line.cross {
1040
+ stroke: #cdc9c1;
1041
+ stroke-dasharray: 5 4;
1042
+ }
1043
+ .graph-wrap rect.cluster {
1044
+ fill: var(--paper);
1045
+ stroke: var(--line);
1046
+ stroke-width: 1.5;
1047
+ }
1048
+ .graph-node {
1049
+ cursor: pointer;
1050
+ }
1051
+ .graph-node circle,
1052
+ .graph-node rect {
1053
+ fill: var(--paper);
1054
+ stroke: var(--ink);
1055
+ stroke-width: 2;
1056
+ }
1057
+ .graph-node.area circle {
1058
+ fill: var(--ink);
1059
+ }
1060
+ .graph-node text {
1061
+ font-size: 12px;
1062
+ fill: var(--muted);
1063
+ paint-order: stroke;
1064
+ stroke: var(--paper);
1065
+ stroke-width: 4px;
1066
+ stroke-linejoin: round;
1067
+ }
1068
+ .graph-wrap text.cluster-label,
1069
+ .graph-node.area text {
1070
+ font-size: 15px;
1071
+ font-weight: 650;
1072
+ fill: var(--ink);
1073
+ }
1074
+ .graph-node.context circle {
1075
+ stroke: var(--subtle);
1076
+ stroke-dasharray: 4 3;
1077
+ }
1078
+ .graph-node.context.area circle {
1079
+ fill: var(--paper);
1080
+ }
1081
+ .graph-node.st-needs-recheck circle {
1082
+ fill: var(--accent);
1083
+ }
1084
+ .graph-node.st-needs-decision circle {
1085
+ fill: var(--ink);
1086
+ }
1087
+ .graph-node.st-accepted circle {
1088
+ fill: var(--success);
1089
+ stroke: var(--success);
1090
+ }
1091
+ .graph-node.st-deferred circle,
1092
+ .graph-node.st-rejected circle,
1093
+ .graph-node.st-done circle,
1094
+ .graph-node.st-duplicate circle {
1095
+ fill: var(--soft);
1096
+ stroke: var(--subtle);
1097
+ }
1098
+ .graph-node.stale circle,
1099
+ .graph-node.pending circle {
1100
+ stroke: var(--accent);
1101
+ stroke-width: 3;
1102
+ }
1103
+ .graph-node.selected circle,
1104
+ .graph-node.selected rect {
1105
+ stroke: var(--accent-ink);
1106
+ stroke-width: 5;
1107
+ }
1108
+ .tools {
1109
+ position: absolute;
1110
+ right: 12px;
1111
+ bottom: 12px;
1112
+ display: flex;
1113
+ gap: 6px;
1114
+ padding: 6px;
1115
+ border: 1px solid var(--line);
1116
+ border-radius: 999px;
1117
+ background: var(--paper);
1118
+ }
1119
+ .tools button {
1120
+ width: 36px;
1121
+ height: 36px;
1122
+ border: 0;
1123
+ border-radius: 999px;
1124
+ background: none;
1125
+ font-size: 18px;
1126
+ }
1127
+ .tools button:hover {
1128
+ background: var(--soft);
1129
+ }
1130
+
1131
+ /* Overlays: search, copy, cited file */
1132
+ .overlay {
1133
+ position: fixed;
1134
+ inset: 0;
1135
+ z-index: 30;
1136
+ display: flex;
1137
+ justify-content: center;
1138
+ align-items: flex-start;
1139
+ padding: 9vh 20px 20px;
1140
+ background: rgba(17, 18, 20, 0.35);
1141
+ overflow: auto;
1142
+ }
1143
+ .palette-card,
1144
+ .copy-card {
1145
+ width: min(720px, 100%);
1146
+ display: flex;
1147
+ flex-direction: column;
1148
+ border: 1px solid var(--line);
1149
+ border-radius: 24px;
1150
+ background: var(--paper);
1151
+ box-shadow:
1152
+ 0 40px 90px -40px rgba(17, 18, 20, 0.35),
1153
+ 0 2px 6px rgba(17, 18, 20, 0.04);
1154
+ overflow: hidden;
1155
+ }
1156
+ .palette-input {
1157
+ display: flex;
1158
+ align-items: center;
1159
+ gap: 12px;
1160
+ height: 64px;
1161
+ padding: 0 20px;
1162
+ border-bottom: 1px solid var(--line);
1163
+ }
1164
+ .palette-input input {
1165
+ flex: 1;
1166
+ min-width: 0;
1167
+ border: 0;
1168
+ outline: none;
1169
+ background: none;
1170
+ font: 500 19px/1.3 var(--sans);
1171
+ }
1172
+ .palette-card .pillrow {
1173
+ padding: 12px 20px;
1174
+ border-bottom: 1px solid var(--line);
1175
+ }
1176
+ .palette-results {
1177
+ display: flex;
1178
+ flex-direction: column;
1179
+ padding: 8px 8px 12px;
1180
+ max-height: 56vh;
1181
+ overflow: auto;
1182
+ }
1183
+ .palette-results .eyebrow {
1184
+ padding: 12px 12px 6px;
1185
+ }
1186
+ .result {
1187
+ display: flex;
1188
+ align-items: center;
1189
+ gap: 12px;
1190
+ width: 100%;
1191
+ min-height: 56px;
1192
+ padding: 8px 12px;
1193
+ border: 0;
1194
+ border-radius: 14px;
1195
+ background: none;
1196
+ text-align: left;
1197
+ }
1198
+ .result:hover,
1199
+ .result[aria-selected="true"] {
1200
+ background: var(--soft);
1201
+ }
1202
+ .result .grow {
1203
+ flex: 1;
1204
+ min-width: 0;
1205
+ display: flex;
1206
+ flex-direction: column;
1207
+ }
1208
+ .result .name {
1209
+ font-weight: 600;
1210
+ }
1211
+ .result mark {
1212
+ background: var(--accent-soft);
1213
+ color: inherit;
1214
+ }
1215
+ .palette-foot {
1216
+ display: flex;
1217
+ flex-wrap: wrap;
1218
+ gap: 20px;
1219
+ padding: 12px 20px;
1220
+ border-top: 1px solid var(--line);
1221
+ background: var(--raised);
1222
+ font: 12px var(--mono);
1223
+ color: var(--muted);
1224
+ }
1225
+ /* The dialog fits the window: what you choose on the left, what gets copied on the right. */
1226
+ #copydlg {
1227
+ align-items: center;
1228
+ padding: 20px;
1229
+ overflow: hidden;
1230
+ }
1231
+ .copy-card {
1232
+ width: min(1040px, 100%);
1233
+ max-height: calc(100vh - 40px);
1234
+ padding: 22px 24px 24px;
1235
+ display: grid;
1236
+ grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
1237
+ gap: 16px 28px;
1238
+ overflow: auto;
1239
+ }
1240
+ .copy-card > .stack {
1241
+ grid-column: 1 / -1;
1242
+ max-width: none;
1243
+ }
1244
+ .copy-card > .stack .h2 {
1245
+ font-size: 18px;
1246
+ }
1247
+ .copy-controls,
1248
+ .copy-side {
1249
+ display: flex;
1250
+ flex-direction: column;
1251
+ gap: 14px;
1252
+ min-width: 0;
1253
+ }
1254
+ .copy-side {
1255
+ align-self: start;
1256
+ position: sticky;
1257
+ top: 0;
1258
+ }
1259
+ .copy-card .pillrow {
1260
+ gap: 6px;
1261
+ }
1262
+ .copy-card .pill {
1263
+ height: 32px;
1264
+ padding: 0 12px;
1265
+ font-size: 13px;
1266
+ }
1267
+ .copy-card fieldset.checks {
1268
+ flex-direction: row;
1269
+ flex-wrap: wrap;
1270
+ gap: 0 20px;
1271
+ }
1272
+ .copy-card fieldset.checks legend {
1273
+ width: 100%;
1274
+ float: left;
1275
+ }
1276
+ .copy-card .check {
1277
+ min-height: 32px;
1278
+ }
1279
+ .copy-card .btn {
1280
+ height: 40px;
1281
+ }
1282
+ @media (max-width: 820px) {
1283
+ .copy-card {
1284
+ grid-template-columns: minmax(0, 1fr);
1285
+ }
1286
+ .copy-side {
1287
+ position: static;
1288
+ }
1289
+ }
1290
+ .copy-card fieldset {
1291
+ margin: 0;
1292
+ padding: 0;
1293
+ border: 0;
1294
+ display: flex;
1295
+ flex-direction: column;
1296
+ gap: 8px;
1297
+ }
1298
+ .copy-card legend {
1299
+ padding: 0;
1300
+ margin-bottom: 6px;
1301
+ font-size: 13px;
1302
+ font-weight: 600;
1303
+ }
1304
+ .field-label {
1305
+ font-size: 13px;
1306
+ font-weight: 600;
1307
+ }
1308
+ .copy-card input[type="text"] {
1309
+ width: 100%;
1310
+ height: 38px;
1311
+ padding: 0 12px;
1312
+ border: 1px solid var(--line-strong);
1313
+ border-radius: 14px;
1314
+ background: var(--paper);
1315
+ font-size: 15px;
1316
+ }
1317
+ .copy-card textarea {
1318
+ padding: 9px 12px;
1319
+ font-size: 15px;
1320
+ line-height: 1.45;
1321
+ }
1322
+ .copy-card .night {
1323
+ padding: 16px 18px;
1324
+ border-radius: 16px;
1325
+ }
1326
+ /* Tall enough to read, short enough that the dialog itself never needs a second scrollbar. */
1327
+ .copy-card .night pre {
1328
+ max-height: max(160px, calc(100vh - 380px));
1329
+ }
1330
+ .check {
1331
+ display: flex;
1332
+ align-items: center;
1333
+ gap: 12px;
1334
+ min-height: 44px;
1335
+ font-size: 14px;
1336
+ }
1337
+ .check input {
1338
+ width: 18px;
1339
+ height: 18px;
1340
+ accent-color: var(--ink);
1341
+ }
1342
+ .actions {
1343
+ display: flex;
1344
+ flex-wrap: wrap;
1345
+ align-items: center;
1346
+ gap: 12px;
1347
+ }
1348
+ .filepane {
1349
+ position: fixed;
1350
+ inset: 0;
1351
+ z-index: 40;
1352
+ display: flex;
1353
+ justify-content: flex-end;
1354
+ background: rgba(17, 18, 20, 0.35);
1355
+ }
1356
+ .file-card {
1357
+ width: min(1040px, 100%);
1358
+ height: 100%;
1359
+ display: flex;
1360
+ flex-direction: column;
1361
+ background: var(--paper);
1362
+ border-left: 1px solid var(--line);
1363
+ }
1364
+ .file-head {
1365
+ display: flex;
1366
+ flex-wrap: wrap;
1367
+ align-items: center;
1368
+ gap: 12px;
1369
+ padding: 14px 22px;
1370
+ border-bottom: 1px solid var(--line);
1371
+ }
1372
+ .file-name {
1373
+ flex: 1;
1374
+ min-width: 0;
1375
+ }
1376
+ .file-name strong {
1377
+ display: block;
1378
+ overflow-wrap: anywhere;
1379
+ font: 500 14px var(--mono);
1380
+ }
1381
+ .file-name small {
1382
+ font-size: 12px;
1383
+ color: var(--muted);
1384
+ }
1385
+ .file-actions {
1386
+ display: flex;
1387
+ gap: 6px;
1388
+ }
1389
+ .file-head button {
1390
+ height: 36px;
1391
+ padding: 0 14px;
1392
+ border: 1px solid var(--line-strong);
1393
+ border-radius: 999px;
1394
+ background: var(--paper);
1395
+ font-size: 13px;
1396
+ font-weight: 600;
1397
+ }
1398
+ .file-head button[aria-pressed="true"] {
1399
+ border-color: var(--ink);
1400
+ background: var(--ink);
1401
+ color: #ffffff;
1402
+ }
1403
+ .file-body {
1404
+ flex: 1;
1405
+ min-height: 0;
1406
+ overflow: auto;
1407
+ padding: 26px 34px 60px;
1408
+ }
1409
+ .file-body > .article {
1410
+ max-width: 900px;
1411
+ }
1412
+ .code-view {
1413
+ font: 12.5px/1.55 var(--mono);
1414
+ min-width: max-content;
1415
+ }
1416
+ .ln {
1417
+ display: flex;
1418
+ gap: 14px;
1419
+ white-space: pre;
1420
+ }
1421
+ .ln .num {
1422
+ flex: 0 0 44px;
1423
+ text-align: right;
1424
+ color: var(--subtle);
1425
+ user-select: none;
1426
+ }
1427
+ .ln.hit {
1428
+ background: var(--accent-soft);
1429
+ }
1430
+ @media (max-width: 860px) {
1431
+ .app {
1432
+ display: block;
1433
+ }
1434
+ .side {
1435
+ position: static;
1436
+ height: auto;
1437
+ border-right: 0;
1438
+ border-bottom: 1px solid var(--line);
1439
+ }
1440
+ .tree {
1441
+ max-height: 40vh;
1442
+ overflow: auto;
1443
+ }
1444
+ .topbar,
1445
+ .view,
1446
+ .mapview {
1447
+ padding-left: 16px;
1448
+ padding-right: 16px;
1449
+ }
1450
+ .mapview {
1451
+ height: auto;
1452
+ }
1453
+ .graph-wrap {
1454
+ flex: none;
1455
+ height: 70vh;
1456
+ }
1457
+ .topbar .btn {
1458
+ padding: 0 12px;
1459
+ }
1460
+ .title {
1461
+ font-size: 32px;
1462
+ }
1463
+ .file-body {
1464
+ padding: 18px 16px 50px;
1465
+ }
1466
+ }
1467
+ @media (prefers-reduced-motion: reduce) {
1468
+ * {
1469
+ transition: none !important;
1470
+ }
1471
+ }
1472
+ </style>
1473
+ </head>
1474
+ <body>
1475
+ <div class="app">
1476
+ <nav class="side" aria-label="Spec navigation">
1477
+ <div class="brand">
1478
+ <strong id="project-title"></strong
1479
+ ><span class="mono-label" id="header-note">Spec</span>
1480
+ </div>
1481
+ <button type="button" class="searchbox" id="open-search">
1482
+ <svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"></circle><path d="m20 20-3.5-3.5"></path></svg>
1483
+ <span>Search</span><kbd>⌘K</kbd>
1484
+ </button>
1485
+ <div class="nav-links" id="nav-links"></div>
1486
+ <div class="eyebrow">Spec</div>
1487
+ <div class="tree" id="tree"></div>
1488
+ </nav>
1489
+ <main class="main">
1490
+ <div class="topbar">
1491
+ <button type="button" class="icon-btn" id="back" aria-label="Back">
1492
+ <svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M19 12H5"></path><path d="m11 6-6 6 6 6"></path></svg></button
1493
+ ><button type="button" class="icon-btn" id="forward" aria-label="Forward">
1494
+ <svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"></path><path d="m13 6 6 6-6 6"></path></svg>
1495
+ </button>
1496
+ <nav class="crumbs" id="crumbs" aria-label="Breadcrumb"></nav>
1497
+ <span class="toast" id="toast" role="status" aria-live="polite"></span>
1498
+ <button type="button" class="btn" id="copy-link">Copy link</button>
1499
+ <button type="button" class="btn accent" id="copy-ai">
1500
+ <svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2"></rect><path d="M5 15V6a2 2 0 0 1 2-2h9"></path></svg>
1501
+ Copy for AI
1502
+ </button>
1503
+ </div>
1504
+ <div class="view" id="view"></div>
1505
+ <section class="mapview" id="mapview" aria-labelledby="map-title" hidden>
1506
+ <div class="map-head">
1507
+ <h1 id="map-title">Map</h1>
1508
+ <div class="pillrow" id="map-controls" role="group" aria-label="Map layer"></div>
1509
+ </div>
1510
+ <div class="graph-wrap">
1511
+ <svg id="graph" role="img" aria-label="Map of linked pages. Every page is also in the tree."></svg>
1512
+ <div class="tools" aria-label="Map zoom">
1513
+ <button type="button" id="zoom-in" aria-label="Zoom in">+</button
1514
+ ><button type="button" id="zoom-out" aria-label="Zoom out">−</button
1515
+ ><button type="button" id="reset" aria-label="Reset view">↺</button>
1516
+ </div>
1517
+ </div>
1518
+ </section>
1519
+ </main>
1520
+ </div>
1521
+ <div class="overlay" id="palette" role="dialog" aria-modal="true" aria-label="Search the spec" hidden>
1522
+ <div class="palette-card">
1523
+ <label class="palette-input">
1524
+ <svg aria-hidden="true" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"></circle><path d="m20 20-3.5-3.5"></path></svg>
1525
+ <input id="palette-input" type="search" placeholder="Search pages, gaps, files" aria-label="Search pages, gaps and files" autocomplete="off" />
1526
+ <kbd>esc</kbd>
1527
+ </label>
1528
+ <div class="pillrow" id="palette-filters" role="group" aria-label="Limit results"></div>
1529
+ <div class="palette-results" id="palette-results"></div>
1530
+ <div class="palette-foot"><span>↑↓ move</span><span>↵ open</span><span>⌘K anywhere</span></div>
1531
+ </div>
1532
+ </div>
1533
+ <div class="overlay" id="copydlg" role="dialog" aria-modal="true" aria-label="Copy for AI" hidden>
1534
+ <div class="copy-card" id="copy-card"></div>
1535
+ </div>
1536
+ <div class="filepane" id="filepane" role="dialog" aria-modal="true" aria-labelledby="file-title" hidden>
1537
+ <div class="file-card">
1538
+ <div class="file-head">
1539
+ <div class="file-name">
1540
+ <strong id="file-title"></strong><small id="file-note"></small>
1541
+ </div>
1542
+ <div class="file-actions" id="file-actions"></div>
1543
+ <button type="button" id="file-close">Close</button>
1544
+ </div>
1545
+ <div class="file-body" id="file-body"></div>
1546
+ </div>
1547
+ </div>
1548
+ <script id="knowledge-data" type="application/json">
1549
+ __KNOWLEDGE_DATA__
1550
+ </script>
1551
+ <script>
1552
+ (() => {
1553
+ "use strict";
1554
+ const data = JSON.parse(
1555
+ document.getElementById("knowledge-data").textContent,
1556
+ );
1557
+ const nodes = (Array.isArray(data.nodes) ? data.nodes : []).filter(
1558
+ (n) => n && typeof n === "object",
1559
+ ),
1560
+ edges = Array.isArray(data.edges) ? data.edges : [];
1561
+ // Sent by `knowledge.py serve` only: the text of cited repository files, the vault's place in the
1562
+ // repository, its Git history and its uncommitted pages. A page without them still works.
1563
+ const files =
1564
+ data.files && typeof data.files === "object" ? data.files : {},
1565
+ vaultPath = typeof data.vaultPath === "string" ? data.vaultPath : "",
1566
+ historyLog = (Array.isArray(data.history) ? data.history : []).filter(
1567
+ (c) => c && typeof c === "object",
1568
+ ),
1569
+ pendingPages = (Array.isArray(data.pending) ? data.pending : []).filter(
1570
+ (p) => p && typeof p === "object",
1571
+ );
1572
+ const live = data.live === true;
1573
+ const byId = new Map(nodes.map((n) => [n.id, n])),
1574
+ byPath = new Map(
1575
+ nodes.map((n) => [String(n.path || "").replace(/\.md$/i, ""), n]),
1576
+ );
1577
+ const $ = (s) => document.querySelector(s),
1578
+ svgNS = "http://www.w3.org/2000/svg";
1579
+ const graph = $("#graph");
1580
+ const projectTitle = typeof data.title === "string" && data.title ? data.title : "Spec";
1581
+ let mode = "spec", // the layer the map draws: "spec" or "gap"
1582
+ selected = null, // the page that is open; the map marks it
1583
+ box = { x: 0, y: 0, w: 1000, h: 700 },
1584
+ initialBox = { ...box };
1585
+ const labels = {
1586
+ current: "Checked against the code",
1587
+ partial: "Partial",
1588
+ planned: "Planned",
1589
+ unverified: "Unverified",
1590
+ conflict: "Conflict",
1591
+ stale: "Stale",
1592
+ superseded: "Superseded",
1593
+ };
1594
+ const types = {
1595
+ index: "Overview",
1596
+ area: "Area",
1597
+ note: "Note",
1598
+ gap: "Gap",
1599
+ plan: "Plan",
1600
+ run: "Research run",
1601
+ };
1602
+ const kindLabels = {
1603
+ "product-gap": "Product gap",
1604
+ "verification-gap": "Verification gap",
1605
+ "product-plan": "Product plan",
1606
+ conflict: "Conflict",
1607
+ "knowledge-gap": "Knowledge gap",
1608
+ };
1609
+ const STATES = [
1610
+ "needs-recheck",
1611
+ "needs-decision",
1612
+ "accepted",
1613
+ "deferred",
1614
+ "rejected",
1615
+ "done",
1616
+ "duplicate",
1617
+ ];
1618
+ const stateLabels = {
1619
+ "needs-recheck": "Needs recheck",
1620
+ "needs-decision": "Needs decision",
1621
+ accepted: "Accepted",
1622
+ deferred: "Deferred",
1623
+ rejected: "Rejected",
1624
+ done: "Done",
1625
+ duplicate: "Duplicate",
1626
+ };
1627
+ const stateHints = {
1628
+ "needs-recheck":
1629
+ "Someone has to confirm that the page's description of the current code is still right.",
1630
+ "needs-decision":
1631
+ "Rechecked; waiting for a person to accept, reject or defer.",
1632
+ };
1633
+ const recheckLabels = {
1634
+ "not-checked": "Not checked",
1635
+ confirmed: "Confirmed (still holds)",
1636
+ "not-reproduced": "Not reproduced (no longer holds)",
1637
+ outdated: "Outdated",
1638
+ };
1639
+ // model:start
1640
+ const str = (v) => (typeof v === "string" ? v : "");
1641
+ const isGap = (n) => n.type === "gap";
1642
+ const isPlan = (n) => n.type === "plan";
1643
+ const layerOf = (n) =>
1644
+ ["spec", "gap", "nav"].includes(n.layer)
1645
+ ? n.layer
1646
+ : n.type === "area" || n.type === "note"
1647
+ ? "spec"
1648
+ : isGap(n) || isPlan(n)
1649
+ ? "gap"
1650
+ : "nav";
1651
+ const stateOf = (n) => {
1652
+ if (!isGap(n)) return "";
1653
+ if (STATES.includes(n.state)) return n.state;
1654
+ const decision = str(n.decision) || "open",
1655
+ recheck = str(n.recheck);
1656
+ if (decision === "open")
1657
+ return recheck === "confirmed" || recheck === "not-reproduced"
1658
+ ? "needs-decision"
1659
+ : "needs-recheck";
1660
+ return STATES.includes(decision) ? decision : "needs-recheck";
1661
+ };
1662
+ const recheckOutdated = (n) =>
1663
+ isGap(n) && (n.recheckOutdated === true || n.recheck === "outdated");
1664
+ const stateRank = (n) => {
1665
+ const i = STATES.indexOf(stateOf(n));
1666
+ return i < 0 ? STATES.length : i;
1667
+ };
1668
+ const stateClass = (n) =>
1669
+ isGap(n)
1670
+ ? "st-" + stateOf(n)
1671
+ : n.stale || n.status === "stale"
1672
+ ? "stale"
1673
+ : n.status === "conflict"
1674
+ ? "conflict"
1675
+ : ["planned", "unverified"].includes(n.status)
1676
+ ? "pending"
1677
+ : "";
1678
+ const inArea = (n, area) =>
1679
+ !area || n.id === area || (n.areas || []).includes(area);
1680
+ const byTitle = (a, b) =>
1681
+ String(a.title || "").localeCompare(String(b.title || ""), "ru");
1682
+ // model:end
1683
+ const el = (tag, text, cls) => {
1684
+ const e = document.createElement(tag);
1685
+ if (text != null) e.textContent = text;
1686
+ if (cls) e.className = cls;
1687
+ return e;
1688
+ };
1689
+ const sv = (tag, attrs) => {
1690
+ const e = document.createElementNS(svgNS, tag);
1691
+ Object.entries(attrs).forEach(([k, v]) => e.setAttribute(k, v));
1692
+ return e;
1693
+ };
1694
+ const areas = nodes.filter((n) => n.type === "area").sort(byTitle);
1695
+ $("#project-title").textContent = projectTitle;
1696
+ $("#project-title").title = projectTitle;
1697
+ $("#header-note").textContent = live ? "Spec · live from disk" : "Spec";
1698
+ // Small things kept in this browser only: where you were, what you picked. Never required.
1699
+ const store = {
1700
+ key: (name) => "spec-viewer:" + projectTitle + ":" + name,
1701
+ get(name, fallback) {
1702
+ try {
1703
+ const raw = localStorage.getItem(store.key(name));
1704
+ return raw == null ? fallback : JSON.parse(raw);
1705
+ } catch {
1706
+ return fallback;
1707
+ }
1708
+ },
1709
+ set(name, value) {
1710
+ try {
1711
+ localStorage.setItem(store.key(name), JSON.stringify(value));
1712
+ } catch {
1713
+ /* private window or storage blocked: the page still works */
1714
+ }
1715
+ },
1716
+ };
1717
+ const hasWindow = typeof window !== "undefined" && typeof history !== "undefined";
1718
+ // Where the page file is in the repository: what an agent needs to open it.
1719
+ const repoPath = (n) =>
1720
+ (vaultPath && vaultPath !== "." ? vaultPath.replace(/\/+$/, "") + "/" : "") + String(n.path || "");
1721
+ let toastTimer = null;
1722
+ function toast(message) {
1723
+ $("#toast").textContent = message;
1724
+ if (typeof setTimeout !== "function") return;
1725
+ if (toastTimer) clearTimeout(toastTimer);
1726
+ toastTimer = setTimeout(() => {
1727
+ $("#toast").textContent = "";
1728
+ }, 2600);
1729
+ }
1730
+ function copyText(text, message) {
1731
+ const ok = () => toast(message || "Copied");
1732
+ const byHand = () => {
1733
+ try {
1734
+ const t = document.createElement("textarea");
1735
+ t.value = text;
1736
+ t.setAttribute("readonly", "");
1737
+ t.style.position = "fixed";
1738
+ t.style.opacity = "0";
1739
+ document.body.append(t);
1740
+ t.select();
1741
+ const done = document.execCommand("copy");
1742
+ t.remove();
1743
+ if (done) return ok();
1744
+ } catch {
1745
+ /* fall through to the message */
1746
+ }
1747
+ toast("Could not copy. Select the text and copy it by hand.");
1748
+ };
1749
+ try {
1750
+ if (typeof navigator !== "undefined" && navigator.clipboard?.writeText) {
1751
+ navigator.clipboard.writeText(text).then(ok, byHand);
1752
+ return;
1753
+ }
1754
+ } catch {
1755
+ /* use the fallback */
1756
+ }
1757
+ byHand();
1758
+ }
1759
+ const icon = (path, size) => {
1760
+ const s = sv("svg", {
1761
+ "aria-hidden": "true",
1762
+ width: size || 16,
1763
+ height: size || 16,
1764
+ viewBox: "0 0 24 24",
1765
+ fill: "none",
1766
+ stroke: "currentColor",
1767
+ "stroke-width": "1.8",
1768
+ "stroke-linecap": "round",
1769
+ "stroke-linejoin": "round",
1770
+ });
1771
+ path.split("|").forEach((d) => s.append(sv("path", { d })));
1772
+ return s;
1773
+ };
1774
+ const ICON = {
1775
+ chevron: "m9 6 6 6-6 6",
1776
+ copy: "M9 11a2 2 0 0 1 2-2h7a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2z|M5 15V6a2 2 0 0 1 2-2h9",
1777
+ close: "M6 6l12 12|M18 6 6 18",
1778
+ };
1779
+ const button = (text, cls, onClick) => {
1780
+ const b = el("button", text, cls);
1781
+ b.type = "button";
1782
+ if (onClick) b.addEventListener("click", onClick);
1783
+ return b;
1784
+ };
1785
+ const bodyOf = (n) => str(n.body).replace(/^\s*# [^\n]*\n?/, "");
1786
+ function splitWiki(raw) {
1787
+ const parts = String(raw).replace(/\\\|/g, "|").split("|");
1788
+ return {
1789
+ target: parts[0]
1790
+ .split("#")[0]
1791
+ .split("^")[0]
1792
+ .trim()
1793
+ .replace(/\.md$/i, ""),
1794
+ label: (parts[1] || "").trim() || parts[0].trim(),
1795
+ };
1796
+ }
1797
+ function resolveWiki(raw) {
1798
+ const target = splitWiki(raw).target;
1799
+ if (!target) return selected;
1800
+ if (target.includes("/")) return byPath.get(target) || null;
1801
+ const matches = nodes.filter(
1802
+ (n) =>
1803
+ String(n.path || "")
1804
+ .replace(/\.md$/i, "")
1805
+ .split("/")
1806
+ .pop() === target,
1807
+ );
1808
+ return matches.length === 1 ? matches[0] : null;
1809
+ }
1810
+ function safeHref(raw, n) {
1811
+ try {
1812
+ const trimmed = raw.trim();
1813
+ if (!trimmed || /[\u0000-\u001f]/.test(trimmed)) return null;
1814
+ const url = new URL(
1815
+ trimmed,
1816
+ new URL(n.path || "", document.baseURI),
1817
+ );
1818
+ return ["http:", "https:", "file:", "mailto:"].includes(
1819
+ url.protocol,
1820
+ )
1821
+ ? url.href
1822
+ : null;
1823
+ } catch {
1824
+ return null;
1825
+ }
1826
+ }
1827
+ function normPath(parts) {
1828
+ const out = [];
1829
+ for (const seg of parts.join("/").split("/")) {
1830
+ if (!seg || seg === ".") continue;
1831
+ if (seg === ".." && out.length && out[out.length - 1] !== "..") out.pop();
1832
+ else out.push(seg);
1833
+ }
1834
+ return out.join("/");
1835
+ }
1836
+ const hasFile = (key) => Object.prototype.hasOwnProperty.call(files, key);
1837
+ // A relative Markdown link to a cited repository file: where it is in `files` and which lines it names.
1838
+ function fileRef(raw, n) {
1839
+ let t = String(raw).trim();
1840
+ if (t.startsWith("<") && t.endsWith(">")) t = t.slice(1, -1);
1841
+ if (!t || t[0] === "#" || t[0] === "/" || /^[A-Za-z][A-Za-z0-9+.-]*:/.test(t))
1842
+ return null;
1843
+ const hash = t.includes("#") ? t.slice(t.indexOf("#") + 1) : "";
1844
+ try {
1845
+ t = decodeURIComponent(t.split(/[?#]/)[0]);
1846
+ } catch {
1847
+ return null;
1848
+ }
1849
+ const dir = String(n.path || "").split("/").slice(0, -1).join("/");
1850
+ // Vault pages link relative to themselves inside the vault; a cited document links relative to itself in the repository.
1851
+ const key = normPath(n.repoFile ? [dir, t] : [vaultPath, dir, t]);
1852
+ if (!hasFile(key)) return null;
1853
+ const m = hash.match(/^L(\d+)(?:-L?(\d+))?$/i);
1854
+ return { key, from: m ? +m[1] : 0, to: m ? +(m[2] || m[1]) : 0 };
1855
+ }
1856
+ const isMarkdownFile = (key) => /\.(md|markdown)$/i.test(key);
1857
+ let fileState = null;
1858
+ function fileButton(ref, text) {
1859
+ const b = el("button", text, "wiki");
1860
+ b.type = "button";
1861
+ b.addEventListener("click", () => openFile(ref));
1862
+ return b;
1863
+ }
1864
+ function openFile(ref) {
1865
+ fileState = { ref, view: isMarkdownFile(ref.key) ? "rendered" : "source" };
1866
+ $("#filepane").hidden = false;
1867
+ lockPage(true);
1868
+ renderFile();
1869
+ const close = $("#file-close");
1870
+ if (typeof close.focus === "function") close.focus();
1871
+ }
1872
+ function closeFile() {
1873
+ fileState = null;
1874
+ lockPage(false);
1875
+ $("#filepane").hidden = true;
1876
+ $("#file-body").replaceChildren();
1877
+ }
1878
+ function renderFile() {
1879
+ const { ref, view } = fileState,
1880
+ file = files[ref.key] || {},
1881
+ text = str(file.text),
1882
+ body = $("#file-body"),
1883
+ actions = $("#file-actions");
1884
+ $("#file-title").textContent = ref.key;
1885
+ $("#file-note").textContent =
1886
+ (ref.from
1887
+ ? (ref.to > ref.from
1888
+ ? "Lines " + ref.from + "–" + ref.to
1889
+ : "Line " + ref.from) + " · "
1890
+ : "") +
1891
+ (live ? "Read from disk when this page loaded" : "Copy taken when this map was built") +
1892
+ (file.truncated ? " · only the beginning of the file is shown" : "");
1893
+ actions.replaceChildren();
1894
+ if (isMarkdownFile(ref.key))
1895
+ [
1896
+ ["rendered", "Document"],
1897
+ ["source", "Source lines"],
1898
+ ].forEach(([v, label]) => {
1899
+ const b = el("button", label);
1900
+ b.type = "button";
1901
+ b.setAttribute("aria-pressed", String(view === v));
1902
+ b.addEventListener("click", () => {
1903
+ fileState.view = v;
1904
+ renderFile();
1905
+ });
1906
+ actions.append(b);
1907
+ });
1908
+ if (view === "rendered") {
1909
+ body.replaceChildren(markdown(text, { path: ref.key, repoFile: true }));
1910
+ body.scrollTop = 0;
1911
+ return;
1912
+ }
1913
+ const view_ = el("div", null, "code-view");
1914
+ let hit = null;
1915
+ text.split(/\r?\n/).forEach((line, i) => {
1916
+ const inRange = ref.from && i + 1 >= ref.from && i + 1 <= ref.to,
1917
+ row = el("div", null, inRange ? "ln hit" : "ln");
1918
+ row.append(el("span", String(i + 1), "num"), el("span", line, "txt"));
1919
+ view_.append(row);
1920
+ if (inRange && !hit) hit = row;
1921
+ });
1922
+ body.replaceChildren(view_);
1923
+ if (hit && typeof hit.scrollIntoView === "function")
1924
+ hit.scrollIntoView({ block: "center" });
1925
+ else body.scrollTop = 0;
1926
+ }
1927
+ $("#file-close").addEventListener("click", closeFile);
1928
+ $("#filepane").addEventListener("click", (e) => {
1929
+ if (e.target === $("#filepane")) closeFile();
1930
+ });
1931
+ $("#filepane").addEventListener("keydown", (e) => {
1932
+ if (e.key === "Escape") closeFile();
1933
+ });
1934
+ function inline(parent, text, n) {
1935
+ const re = /(\[\[[^\]]+\]\]|\[[^\]]+\]\([^\s)]+\)|`[^`]+`|\*\*[^*\n]+\*\*)/g;
1936
+ let last = 0,
1937
+ m;
1938
+ while ((m = re.exec(text))) {
1939
+ parent.append(document.createTextNode(text.slice(last, m.index)));
1940
+ const token = m[0];
1941
+ if (token.startsWith("[[")) {
1942
+ const raw = token.slice(2, -2),
1943
+ target = resolveWiki(raw),
1944
+ label = splitWiki(raw).label;
1945
+ if (target) {
1946
+ const b = el("button", label, "wiki");
1947
+ b.type = "button";
1948
+ b.addEventListener("click", () => openNode(target));
1949
+ parent.append(b);
1950
+ } else parent.append(document.createTextNode(token));
1951
+ } else if (token.startsWith("**")) {
1952
+ const strong = el("strong");
1953
+ inline(strong, token.slice(2, -2), n);
1954
+ parent.append(strong);
1955
+ } else if (token.startsWith("`"))
1956
+ parent.append(el("code", token.slice(1, -1)));
1957
+ else {
1958
+ const parts = token.match(/^\[([^\]]+)\]\(([^)]+)\)$/),
1959
+ ref = parts && fileRef(parts[2], n),
1960
+ href = parts && !ref && !n.repoFile && safeHref(parts[2], n);
1961
+ if (ref) parent.append(fileButton(ref, parts[1]));
1962
+ else if (href) {
1963
+ const a = el("a", parts[1]);
1964
+ a.href = href;
1965
+ parent.append(a);
1966
+ } else parent.append(document.createTextNode(token));
1967
+ }
1968
+ last = re.lastIndex;
1969
+ }
1970
+ parent.append(document.createTextNode(text.slice(last)));
1971
+ }
1972
+ function markdown(body, n) {
1973
+ const container = el("div", null, "article"),
1974
+ lines = String(body || "").split(/\r?\n/);
1975
+ let paragraph = [],
1976
+ listEl = null,
1977
+ code = null;
1978
+ function flush() {
1979
+ if (paragraph.length) {
1980
+ const p = el("p");
1981
+ inline(p, paragraph.join(" "), n);
1982
+ container.append(p);
1983
+ paragraph = [];
1984
+ }
1985
+ listEl = null;
1986
+ }
1987
+ function emitCode() {
1988
+ const pre = el("pre"),
1989
+ c = el("code", code.lines.join("\n"));
1990
+ pre.append(c);
1991
+ container.append(pre);
1992
+ code = null;
1993
+ }
1994
+ // GFM table: a row of cells, then a row of dashes. \| is a literal pipe (and Obsidian's alias separator).
1995
+ // A pipe inside a wikilink or inline code does not split the row.
1996
+ const cells = (row) => {
1997
+ const out = [];
1998
+ let cell = "",
1999
+ i = 0;
2000
+ const src = row.trim().replace(/^\|/, "").replace(/(?<!\\)\|\s*$/, "");
2001
+ while (i < src.length) {
2002
+ const rest = src.slice(i),
2003
+ keep = rest.match(/^(\[\[[^\]]*\]\]|`[^`]*`)/);
2004
+ if (keep) {
2005
+ cell += keep[0];
2006
+ i += keep[0].length;
2007
+ } else if (rest.startsWith("\\|")) {
2008
+ cell += "|";
2009
+ i += 2;
2010
+ } else if (src[i] === "|") {
2011
+ out.push(cell.trim());
2012
+ cell = "";
2013
+ i++;
2014
+ } else cell += src[i++];
2015
+ }
2016
+ out.push(cell.trim());
2017
+ return out;
2018
+ };
2019
+ const isDivider = (row) =>
2020
+ /^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/.test(row) && row.includes("-");
2021
+ for (let i = 0; i < lines.length; i++) {
2022
+ const line = lines[i];
2023
+ if (
2024
+ !code &&
2025
+ line.includes("|") &&
2026
+ i + 1 < lines.length &&
2027
+ isDivider(lines[i + 1]) &&
2028
+ lines[i + 1].includes("|")
2029
+ ) {
2030
+ flush();
2031
+ const wrap = el("div", null, "table-wrap"),
2032
+ table = el("table"),
2033
+ head = el("tr"),
2034
+ tbody = el("tbody");
2035
+ const header = cells(line);
2036
+ header.forEach((c) => {
2037
+ const th = el("th");
2038
+ inline(th, c, n);
2039
+ head.append(th);
2040
+ });
2041
+ const thead = el("thead");
2042
+ thead.append(head);
2043
+ table.append(thead, tbody);
2044
+ i += 2;
2045
+ for (; i < lines.length && lines[i].trim() && lines[i].includes("|"); i++) {
2046
+ const tr = el("tr"),
2047
+ row = cells(lines[i]);
2048
+ header.forEach((_, k) => {
2049
+ // A rule's number (BR-PROFILE-01) is quoted in tickets and chats, so it stays on one line and reads as a code.
2050
+ const td = el("td", null, k === 0 && /^BR-[A-Z0-9]+(-[A-Z0-9]+)*-\d{2,4}$/.test((row[0] || "").trim()) ? "rule-id" : null);
2051
+ inline(td, row[k] || "", n);
2052
+ tr.append(td);
2053
+ });
2054
+ tbody.append(tr);
2055
+ }
2056
+ i--;
2057
+ wrap.append(table);
2058
+ container.append(wrap);
2059
+ continue;
2060
+ }
2061
+ if (code) {
2062
+ // CommonMark: a closing fence uses the same character, is at
2063
+ // least as long as the opener and has no info string.
2064
+ const close = line.match(/^\s*(`{3,}|~{3,})\s*$/);
2065
+ if (
2066
+ close &&
2067
+ close[1][0] === code.ch &&
2068
+ close[1].length >= code.len
2069
+ )
2070
+ emitCode();
2071
+ else code.lines.push(line);
2072
+ continue;
2073
+ }
2074
+ const open = line.match(/^\s*(`{3,}|~{3,})(.*)$/);
2075
+ // A backtick fence's info string cannot contain a backtick.
2076
+ if (open && !(open[1][0] === "`" && open[2].includes("`"))) {
2077
+ flush();
2078
+ code = { ch: open[1][0], len: open[1].length, lines: [] };
2079
+ continue;
2080
+ }
2081
+ if (!line.trim()) {
2082
+ flush();
2083
+ continue;
2084
+ }
2085
+ const h = line.match(/^(#{1,6})\s+(.+)$/),
2086
+ li = line.match(/^\s*([-*+]\s+|\d+[.)]\s+)(.*)$/);
2087
+ if (h) {
2088
+ flush();
2089
+ const e = el("h" + Math.min(h[1].length, 6));
2090
+ inline(e, h[2], n);
2091
+ container.append(e);
2092
+ } else if (li) {
2093
+ if (paragraph.length) flush();
2094
+ const kind = /^\d/.test(li[1]) ? "ol" : "ul";
2095
+ if (!listEl || listEl.tagName.toLowerCase() !== kind) {
2096
+ listEl = el(kind);
2097
+ container.append(listEl);
2098
+ }
2099
+ const item = el("li");
2100
+ inline(item, li[2], n);
2101
+ listEl.append(item);
2102
+ } else {
2103
+ listEl = null;
2104
+ paragraph.push(line);
2105
+ }
2106
+ }
2107
+ flush();
2108
+ if (code) emitCode();
2109
+ return container;
2110
+ }
2111
+ const outdatedBadge = () =>
2112
+ el("span", "Recheck outdated", "badge outdated");
2113
+ function stateBadge(n) {
2114
+ return el("span", stateLabels[stateOf(n)], "badge " + stateClass(n));
2115
+ }
2116
+ function neighbours(n, layer) {
2117
+ const out = new Map();
2118
+ edges.forEach((e) => {
2119
+ const other =
2120
+ e.source === n.id
2121
+ ? byId.get(e.target)
2122
+ : e.target === n.id
2123
+ ? byId.get(e.source)
2124
+ : null;
2125
+ if (other && other.id !== n.id && layerOf(other) === layer)
2126
+ out.set(other.id, other);
2127
+ });
2128
+ return [...out.values()].sort(byTitle);
2129
+ }
2130
+ function gapsAbout(n) {
2131
+ const out = new Map();
2132
+ edges.forEach((e) => {
2133
+ // Gaps link to spec pages; older vaults also had the reverse edge.
2134
+ const g =
2135
+ e.target === n.id
2136
+ ? byId.get(e.source)
2137
+ : e.source === n.id
2138
+ ? byId.get(e.target)
2139
+ : null;
2140
+ if (g && isGap(g)) out.set(g.id, g);
2141
+ });
2142
+ return [...out.values()].sort(
2143
+ (a, b) => stateRank(a) - stateRank(b) || byTitle(a, b),
2144
+ );
2145
+ }
2146
+ const planOf = (g) => nodes.find((p) => isPlan(p) && p.gap === g.id);
2147
+ const byWhom = (who, on) =>
2148
+ (who ? " by " + who : "") + (on ? " on " + on : "");
2149
+ function factsLine(n) {
2150
+ const parts = [];
2151
+ if (str(n.recheckedBy) || str(n.recheckedOn))
2152
+ parts.push(
2153
+ "Rechecked" + byWhom(str(n.recheckedBy), str(n.recheckedOn)),
2154
+ );
2155
+ if (str(n.decidedBy) || str(n.decidedOn))
2156
+ parts.push(
2157
+ "Decided" + byWhom(str(n.decidedBy), str(n.decidedOn)),
2158
+ );
2159
+ if (str(n.priority)) parts.push("Priority " + n.priority);
2160
+ return parts.join(" · ");
2161
+ }
2162
+ function nodeButton(target, text) {
2163
+ const b = el("button", text == null ? target.title : text, "wiki");
2164
+ b.type = "button";
2165
+ b.addEventListener("click", () => openNode(target));
2166
+ return b;
2167
+ }
2168
+ function linkBlock(title, items) {
2169
+ const block = el("div", null, "link-block"),
2170
+ ul = el("ul", null, "link-list");
2171
+ block.append(el("h2", title), ul);
2172
+ items.forEach((fn) => {
2173
+ const li = el("li");
2174
+ fn(li);
2175
+ ul.append(li);
2176
+ });
2177
+ return block;
2178
+ }
2179
+ function gapHeader(n) {
2180
+ const box = el("div", null, "gap-facts " + stateClass(n)),
2181
+ dl = el("dl");
2182
+ const row = (k, v) => {
2183
+ const dd = el("dd");
2184
+ if (typeof v === "string") dd.textContent = v;
2185
+ else dd.append(v);
2186
+ dl.append(el("dt", k), dd);
2187
+ };
2188
+ row("State", stateBadge(n));
2189
+ if (str(n.kind)) row("Kind", kindLabels[n.kind] || n.kind);
2190
+ const recheck = str(n.recheck) || "not-checked",
2191
+ who = byWhom(str(n.recheckedBy), str(n.recheckedOn)),
2192
+ rcell = el("span");
2193
+ rcell.append(
2194
+ document.createTextNode(
2195
+ recheck === "outdated"
2196
+ ? "Outdated" + (who ? " (last" + who + ")" : "")
2197
+ : (recheckLabels[recheck] || recheck) + who,
2198
+ ),
2199
+ );
2200
+ if (recheckOutdated(n)) {
2201
+ rcell.append(document.createTextNode(" "), outdatedBadge());
2202
+ }
2203
+ row("Recheck", rcell);
2204
+ const decision = str(n.decision) || "open";
2205
+ row(
2206
+ "Decision",
2207
+ decision.charAt(0).toUpperCase() +
2208
+ decision.slice(1) +
2209
+ byWhom(str(n.decidedBy), str(n.decidedOn)),
2210
+ );
2211
+ if (str(n.priority)) row("Priority", n.priority);
2212
+ if (str(n.confidence)) row("Confidence", n.confidence);
2213
+ box.append(dl);
2214
+ return box;
2215
+ }
2216
+ const primaryArea = (n) => (n.areas || [])[0] || "";
2217
+ const isFeature = (n) => n.type === "note" && n.status !== "superseded";
2218
+ const featuresOf = (area) =>
2219
+ nodes.filter((n) => isFeature(n) && primaryArea(n) === area.id).sort(byTitle);
2220
+ const looseFeatures = () =>
2221
+ nodes
2222
+ .filter((n) => isFeature(n) && byId.get(primaryArea(n))?.type !== "area")
2223
+ .sort(byTitle);
2224
+ const waiting = (n) =>
2225
+ gapsAbout(n).filter((g) =>
2226
+ ["needs-recheck", "needs-decision"].includes(stateOf(g)),
2227
+ );
2228
+ const plural = (count, word) => count + " " + word + (count === 1 ? "" : "s");
2229
+ // --- Where you are: one route at a time, with a trail for Back and Forward --------------------
2230
+ const trail = []; // every place visited in this session, in order
2231
+ let at = -1, // trail[at] is what is on screen
2232
+ route = { name: "home", id: "" };
2233
+ const ROUTES = ["home", "page", "gaps", "map", "changes"];
2234
+ const sameRoute = (a, b) => a.name === b.name && a.id === b.id;
2235
+ const routeHash = (r) => {
2236
+ if (r.name === "home") return "#/";
2237
+ if (r.name !== "page") return "#/" + r.name;
2238
+ const n = byId.get(r.id);
2239
+ return "#/page/" + encodeURI(String(n ? n.path : "").replace(/\.md$/i, ""));
2240
+ };
2241
+ function parseHash(hash) {
2242
+ const text = String(hash || "").replace(/^#\/?/, "");
2243
+ if (text.startsWith("page/")) {
2244
+ let path = text.slice(5);
2245
+ try {
2246
+ path = decodeURI(path);
2247
+ } catch {
2248
+ /* keep the raw text */
2249
+ }
2250
+ const n = byPath.get(path);
2251
+ return n ? { name: "page", id: n.id } : { name: "home", id: "" };
2252
+ }
2253
+ return { name: ROUTES.includes(text) && text !== "page" ? text : "home", id: "" };
2254
+ }
2255
+ function go(next) {
2256
+ if (at >= 0 && sameRoute(trail[at], next)) return show();
2257
+ trail.splice(at + 1);
2258
+ trail.push(next);
2259
+ at = trail.length - 1;
2260
+ if (hasWindow) {
2261
+ try {
2262
+ history.pushState({ at, route: next }, "", routeHash(next));
2263
+ } catch {
2264
+ /* a sandboxed page cannot touch history; the trail still works */
2265
+ }
2266
+ }
2267
+ show();
2268
+ }
2269
+ function step(delta) {
2270
+ const to = at + delta;
2271
+ if (to < 0 || to >= trail.length) return;
2272
+ if (hasWindow) {
2273
+ try {
2274
+ return history.go(delta); // the popstate handler moves the trail
2275
+ } catch {
2276
+ /* fall through */
2277
+ }
2278
+ }
2279
+ at = to;
2280
+ show();
2281
+ }
2282
+ const openNode = (n) => go({ name: "page", id: n.id });
2283
+ const routeLabel = (r) =>
2284
+ r.name === "page"
2285
+ ? str(byId.get(r.id)?.title)
2286
+ : { home: "the overview", gaps: "the gap queue", map: "the map", changes: "recent changes" }[r.name];
2287
+
2288
+ // Pages opened lately, newest first, kept across reloads.
2289
+ let recent = store.get("recent", []);
2290
+ recent = (Array.isArray(recent) ? recent : []).filter((id) => byId.has(id));
2291
+ function remember(n) {
2292
+ recent = [n.id, ...recent.filter((id) => id !== n.id)].slice(0, 8);
2293
+ store.set("recent", recent);
2294
+ }
2295
+
2296
+ // Pages whose cited sources changed since someone last read them against the code.
2297
+ const changedSources = new Map();
2298
+ (Array.isArray(data.warnings) ? data.warnings : []).forEach((w) => {
2299
+ const m = /^(.+?\.md): changed source (.+?)(?: \(uncommitted change, not counted\))?$/.exec(String(w));
2300
+ if (!m) return;
2301
+ if (!changedSources.has(m[1])) changedSources.set(m[1], []);
2302
+ changedSources.get(m[1]).push(m[2]);
2303
+ });
2304
+ const rereads = nodes
2305
+ .filter((n) => changedSources.has(n.path) || n.stale === true)
2306
+ .sort((a, b) => String(a.path).localeCompare(String(b.path)));
2307
+ const waitingGaps = nodes.filter((n) =>
2308
+ ["needs-recheck", "needs-decision"].includes(stateOf(n)),
2309
+ );
2310
+ // Commits newer than the one that was newest on your previous visit.
2311
+ const seenSha = store.get("seen", "");
2312
+ const seenIndex = historyLog.findIndex((c) => c.sha === seenSha);
2313
+ const newCommits = !seenSha ? 0 : seenIndex < 0 ? historyLog.length : seenIndex;
2314
+
2315
+ const pageLines = (list) =>
2316
+ list.map((n) => "- " + repoPath(n) + " (" + n.title + ")").join("\n");
2317
+
2318
+ // --- Sidebar: places, then the spec as a tree ---------------------------------------------------
2319
+ const openAreas = new Set();
2320
+ function renderSide() {
2321
+ const links = $("#nav-links");
2322
+ links.replaceChildren();
2323
+ [
2324
+ ["Overview", "", "home"],
2325
+ ["Recent changes", rereads.length ? rereads.length + " to re-read" : newCommits ? newCommits + " new" : "", "changes"],
2326
+ ["Gaps", waitingGaps.length ? waitingGaps.length + " waiting" : "", "gaps"],
2327
+ ["Map", "", "map"],
2328
+ ].forEach(([label, meta, name]) => {
2329
+ const b = button(null, "nav-link", () => go({ name, id: "" }));
2330
+ b.append(el("span", label), el("span", meta, "meta"));
2331
+ b.setAttribute("aria-current", route.name === name ? "page" : "false");
2332
+ links.append(b);
2333
+ });
2334
+ const tree = $("#tree");
2335
+ tree.replaceChildren();
2336
+ const noteRow = (f) => {
2337
+ const b = button(null, "tree-row note", () => openNode(f)),
2338
+ open = waiting(f).length;
2339
+ b.append(el("span", f.title, "label"));
2340
+ b.title = f.title; // the row shows one line; the full name is a hover away
2341
+ if (open) b.append(el("span", open + " open", "meta"));
2342
+ b.setAttribute("aria-current", selected === f ? "page" : "false");
2343
+ return b;
2344
+ };
2345
+ areas.forEach((a) => {
2346
+ const open = openAreas.has(a.id),
2347
+ line = el("div", null, "tree-area"),
2348
+ twist = button(null, "twist", () => {
2349
+ if (open) openAreas.delete(a.id);
2350
+ else openAreas.add(a.id);
2351
+ renderSide();
2352
+ }),
2353
+ name = button(null, "tree-row area", () => {
2354
+ openAreas.add(a.id);
2355
+ openNode(a);
2356
+ });
2357
+ twist.append(icon(ICON.chevron));
2358
+ twist.setAttribute("aria-expanded", String(open));
2359
+ twist.setAttribute("aria-label", (open ? "Collapse " : "Expand ") + a.title);
2360
+ name.append(el("span", a.title, "label"));
2361
+ name.title = a.title;
2362
+ name.setAttribute("aria-current", selected === a ? "page" : "false");
2363
+ line.append(twist, name);
2364
+ tree.append(line);
2365
+ if (open) featuresOf(a).forEach((f) => tree.append(noteRow(f)));
2366
+ });
2367
+ const loose = looseFeatures();
2368
+ if (loose.length) {
2369
+ tree.append(el("div", "Other", "eyebrow"));
2370
+ loose.forEach((f) => tree.append(noteRow(f)));
2371
+ }
2372
+ if (!areas.length && !loose.length) tree.append(el("p", "No pages yet.", "empty"));
2373
+ }
2374
+
2375
+ // --- Top bar: breadcrumb, Back and Forward, and the two copy actions ---------------------------
2376
+ function renderTop() {
2377
+ $("#back").disabled = at <= 0;
2378
+ $("#forward").disabled = at >= trail.length - 1;
2379
+ const crumbs = $("#crumbs");
2380
+ crumbs.replaceChildren();
2381
+ const parts = [[projectTitle, { name: "home", id: "" }]];
2382
+ const n = selected;
2383
+ if (n) {
2384
+ const parent = n.type === "note" ? byId.get(primaryArea(n)) : null;
2385
+ if (parent && parent.type === "area") parts.push([parent.title, { name: "page", id: parent.id }]);
2386
+ if (isGap(n) || isPlan(n)) parts.push(["Gaps", { name: "gaps", id: "" }]);
2387
+ if (isPlan(n) && byId.get(n.gap)) parts.push([byId.get(n.gap).title, { name: "page", id: n.gap }]);
2388
+ parts.push([n.title, null]);
2389
+ } else if (route.name !== "home")
2390
+ parts.push([{ gaps: "Gaps", map: "Map", changes: "Recent changes" }[route.name], null]);
2391
+ parts.forEach(([label, to], i) => {
2392
+ if (i) crumbs.append(el("span", "/"));
2393
+ const last = i === parts.length - 1;
2394
+ const crumb = last ? el("span", label, "here") : button(label, null, () => go(to));
2395
+ crumb.title = label; // a long name is cut to keep the bar one line
2396
+ crumbs.append(crumb);
2397
+ });
2398
+ $("#copy-ai").hidden = !n;
2399
+ $("#copy-link").hidden = typeof location === "undefined";
2400
+ }
2401
+ $("#back").addEventListener("click", () => step(-1));
2402
+ $("#forward").addEventListener("click", () => step(1));
2403
+ $("#copy-ai").addEventListener("click", () => selected && openCopy(selected));
2404
+ $("#copy-link").addEventListener("click", () => {
2405
+ if (typeof location !== "undefined") copyText(String(location.href), "Link copied");
2406
+ });
2407
+ $("#open-search").addEventListener("click", () => openPalette());
2408
+
2409
+ // --- Pieces shared by the views ----------------------------------------------------------------
2410
+ const header = (eyebrow, title, lead) => {
2411
+ const box = el("header", null, "stack");
2412
+ box.append(el("div", eyebrow, "eyebrow"));
2413
+ const h = el("h1", null, "title");
2414
+ if (Array.isArray(title)) h.append(el("span", title[0] + " ", "quiet"), document.createTextNode(title[1]));
2415
+ else h.textContent = title;
2416
+ box.append(h);
2417
+ if (lead) box.append(el("p", lead, "lead"));
2418
+ return box;
2419
+ };
2420
+ const pills = (label, options, current, pick) => {
2421
+ const row = el("div", null, "pillrow");
2422
+ row.setAttribute("role", "group");
2423
+ row.setAttribute("aria-label", label);
2424
+ options.forEach(([value, text, count]) => {
2425
+ const b = button(null, "pill", () => pick(value));
2426
+ b.append(document.createTextNode(text));
2427
+ if (count != null) b.append(el("span", String(count), "n"));
2428
+ b.setAttribute("aria-pressed", String(current === value));
2429
+ row.append(b);
2430
+ });
2431
+ return row;
2432
+ };
2433
+ function featureList(features) {
2434
+ const box = el("div");
2435
+ features.forEach((f) => {
2436
+ const item = el("div", null, "feature"),
2437
+ open = waiting(f).length;
2438
+ item.append(button(f.title, "rowlink", () => openNode(f)));
2439
+ if (str(f.summary).trim()) item.append(el("p", f.summary, "muted"));
2440
+ if (open) item.append(el("span", plural(open, "open question"), "muted small"));
2441
+ box.append(item);
2442
+ });
2443
+ return box;
2444
+ }
2445
+ const fold = (title, content, open) => {
2446
+ const d = el("details", null, "fold");
2447
+ if (open) d.open = true;
2448
+ d.append(el("summary", title), content);
2449
+ return d;
2450
+ };
2451
+ const statusBadge = (n) => {
2452
+ const cls = stateClass(n);
2453
+ return el("span", labels[n.status] || str(n.status) || types[n.type] || "Page", "badge " + (cls || (n.status === "current" ? "ok" : "")));
2454
+ };
2455
+ const gapRow = (g) => {
2456
+ const row = el("div", null, "row"),
2457
+ grow = el("div", null, "grow");
2458
+ grow.append(button(g.title, "rowlink", () => openNode(g)));
2459
+ const facts = [kindLabels[g.kind] || str(g.kind), factsLine(g)].filter(Boolean).join(" · ");
2460
+ if (facts) grow.append(el("span", facts, "muted small"));
2461
+ row.append(grow, stateBadge(g));
2462
+ if (recheckOutdated(g)) row.append(outdatedBadge());
2463
+ return row;
2464
+ };
2465
+ const sourceLine = (src) => {
2466
+ const key = normPath([src]);
2467
+ return hasFile(key) ? fileButton({ key, from: 0, to: 0 }, src) : el("span", src);
2468
+ };
2469
+
2470
+ // --- Views ---------------------------------------------------------------------------------------
2471
+ function viewHome(view) {
2472
+ const box = el("div", null, "stack");
2473
+ box.append(header("Overview", projectTitle, "What the product does today, area by area."));
2474
+ areas.forEach((a) => {
2475
+ const section = el("section"),
2476
+ h = el("h2", null, "h2");
2477
+ h.append(button(a.title, null, () => openNode(a)));
2478
+ section.append(h);
2479
+ if (str(a.summary).trim()) section.append(el("p", a.summary, "muted"));
2480
+ section.append(featureList(featuresOf(a)));
2481
+ box.append(section);
2482
+ });
2483
+ const loose = looseFeatures();
2484
+ if (loose.length) {
2485
+ const section = el("section");
2486
+ section.append(el("h2", "Other", "h2"), featureList(loose));
2487
+ box.append(section);
2488
+ }
2489
+ if (!areas.length && !loose.length) box.append(el("p", "This spec has no pages yet.", "empty"));
2490
+ view.append(box);
2491
+ }
2492
+
2493
+ function rail(n) {
2494
+ const box = el("aside", null, "rail");
2495
+ box.setAttribute("aria-label", "Where you are");
2496
+ const card = el("div", null, "card pad"),
2497
+ path = el("div", null, "here-path");
2498
+ card.append(el("div", "You are here", "eyebrow"));
2499
+ path.append(button(projectTitle, null, () => go({ name: "home", id: "" })));
2500
+ const parent = n.type === "note" ? byId.get(primaryArea(n)) : null;
2501
+ if (parent && parent.type === "area") path.append(button(parent.title, null, () => openNode(parent)));
2502
+ if (isGap(n) || isPlan(n)) path.append(button("Gaps", null, () => go({ name: "gaps", id: "" })));
2503
+ path.append(el("span", n.title, "now"));
2504
+ card.append(path);
2505
+ const from = at > 0 ? trail[at - 1] : null;
2506
+ if (from && routeLabel(from))
2507
+ card.append(el("p", "You came from " + routeLabel(from) + ". Back returns there.", "muted small"));
2508
+ box.append(card);
2509
+ // Pages this one links to or is linked from: a short list beside the text, not a block inside it.
2510
+ if (layerOf(n) === "spec") {
2511
+ const related = neighbours(n, "spec").filter(
2512
+ (r) => r.id !== parent?.id && !(n.type === "area" && primaryArea(r) === n.id),
2513
+ );
2514
+ if (related.length) {
2515
+ const list = el("div", null, "recent"),
2516
+ keep = 6;
2517
+ list.append(el("div", "Related", "mono-label"));
2518
+ related.forEach((r, i) => {
2519
+ const b = button(r.title, null, () => openNode(r));
2520
+ if (i >= keep) b.hidden = true;
2521
+ list.append(b);
2522
+ });
2523
+ if (related.length > keep) {
2524
+ const more = button("Show " + (related.length - keep) + " more", "more", () => {
2525
+ [...list.children].forEach((c) => (c.hidden = false));
2526
+ more.hidden = true;
2527
+ });
2528
+ list.append(more);
2529
+ }
2530
+ box.append(list);
2531
+ }
2532
+ }
2533
+ const others = recent.filter((id) => id !== n.id).slice(0, 5);
2534
+ if (others.length) {
2535
+ const list = el("div", null, "recent");
2536
+ list.append(el("div", "Recently viewed", "mono-label"));
2537
+ others.forEach((id) => list.append(button(byId.get(id).title, null, () => openNode(byId.get(id)))));
2538
+ box.append(list);
2539
+ }
2540
+ return box;
2541
+ }
2542
+
2543
+ function viewPage(view, n) {
2544
+ const page = el("div", null, "page"),
2545
+ main = el("article", null, "page-main"),
2546
+ layer = layerOf(n),
2547
+ parent = n.type === "note" ? byId.get(primaryArea(n)) : null,
2548
+ summary = str(n.summary).trim();
2549
+ main.append(
2550
+ el(
2551
+ "div",
2552
+ isGap(n)
2553
+ ? "Gap" + (str(n.kind) ? " · " + (kindLabels[n.kind] || n.kind) : "")
2554
+ : n.type === "note"
2555
+ ? "Feature" + (parent ? " · " + parent.title : "")
2556
+ : types[n.type] || "Page",
2557
+ "eyebrow",
2558
+ ),
2559
+ el("h1", n.title, "title"),
2560
+ );
2561
+ if (summary) main.append(el("p", summary, "lead"));
2562
+ const meta = el("div", null, "metarow");
2563
+ // A page whose code moved on says only that: "checked" beside "changed since" reads as a contradiction.
2564
+ const changed = !isGap(n) && n.stale && n.status !== "stale";
2565
+ if (isGap(n)) meta.append(stateBadge(n));
2566
+ else if (!(changed && n.status === "current")) meta.append(statusBadge(n));
2567
+ if (recheckOutdated(n)) meta.append(outdatedBadge());
2568
+ if (changed) meta.append(el("span", "Code changed since the last check", "badge stale"));
2569
+ // The file path of a spec page is for the person who edits it, so it sits at the foot of the page.
2570
+ if (layer !== "spec") meta.append(el("span", repoPath(n), "path"));
2571
+ main.append(meta);
2572
+
2573
+ if (isGap(n)) {
2574
+ main.append(gapHeader(n));
2575
+ const refs = neighbours(n, "spec"),
2576
+ plan = planOf(n);
2577
+ if (refs.length) {
2578
+ const chips = el("div", null, "chips");
2579
+ refs.forEach((r) => chips.append(button(r.title, "chip", () => openNode(r))));
2580
+ main.append(el("div", "Refers to", "mono-label"), chips);
2581
+ }
2582
+ if (plan)
2583
+ main.append(
2584
+ linkBlock("Plan", [
2585
+ (li) => {
2586
+ li.append(nodeButton(plan));
2587
+ if (plan.status) li.append(el("span", labels[plan.status] || plan.status, "muted small"));
2588
+ },
2589
+ ]),
2590
+ );
2591
+ // Older vaults kept the gap category in tags.
2592
+ if (!str(n.kind))
2593
+ for (const tag of Array.isArray(n.tags) ? n.tags : []) {
2594
+ const text = kindLabels[tag] || (tag === "deferred" ? "Deferred" : "");
2595
+ if (text) main.append(el("span", text, "badge plain"));
2596
+ }
2597
+ main.append(markdown(bodyOf(n), n));
2598
+ } else if (isPlan(n)) {
2599
+ const g = byId.get(n.gap);
2600
+ if (g)
2601
+ main.append(
2602
+ linkBlock("Plan for gap", [
2603
+ (li) => {
2604
+ li.append(nodeButton(g));
2605
+ if (isGap(g)) li.append(stateBadge(g));
2606
+ },
2607
+ ]),
2608
+ );
2609
+ main.append(markdown(bodyOf(n), n));
2610
+ } else if (layer === "spec") {
2611
+ // A note is read as written: what the feature is for and its rules. An area is a map of its notes.
2612
+ if (n.type === "area") main.append(featureList(featuresOf(n)));
2613
+ else main.append(markdown(bodyOf(n), n));
2614
+ const about = gapsAbout(n).filter((g) => !["done", "rejected", "duplicate"].includes(stateOf(g)));
2615
+ if (about.length) {
2616
+ const card = el("section", null, "card"),
2617
+ head = el("div", null, "card-head");
2618
+ head.append(el("h2", "Open questions", "h2"), el("span", about.length + " open", "path"));
2619
+ card.append(head);
2620
+ about.forEach((g) => card.append(gapRow(g)));
2621
+ main.append(card);
2622
+ }
2623
+ const folds = el("div");
2624
+ if (n.type === "area") folds.append(fold("More about this area", markdown(bodyOf(n), n)));
2625
+ const sources = (Array.isArray(n.sources) ? n.sources : []).filter(str);
2626
+ if (sources.length) {
2627
+ const ul = el("ul", null, "link-list");
2628
+ sources.forEach((src) => {
2629
+ const li = el("li", null, "path");
2630
+ li.append(sourceLine(src));
2631
+ ul.append(li);
2632
+ });
2633
+ folds.append(fold("Source files (" + sources.length + ")", ul));
2634
+ }
2635
+ const foot = el("p", null, "muted small pagefoot");
2636
+ if (n.updated) foot.append(el("span", "Updated " + n.updated));
2637
+ foot.append(el("span", repoPath(n), "path"));
2638
+ folds.append(foot);
2639
+ main.append(folds);
2640
+ } else main.append(markdown(bodyOf(n), n));
2641
+ page.append(main, rail(n));
2642
+ view.append(page);
2643
+ }
2644
+
2645
+ let gapState = "all",
2646
+ gapArea = "",
2647
+ gapKind = "";
2648
+ const selectOf = (label, options, value, pick) => {
2649
+ const s = el("select");
2650
+ s.setAttribute("aria-label", label);
2651
+ options.forEach(([v, text]) => {
2652
+ const o = el("option", text);
2653
+ o.value = v;
2654
+ s.append(o);
2655
+ });
2656
+ s.value = value;
2657
+ s.addEventListener("change", () => pick(s.value));
2658
+ return s;
2659
+ };
2660
+ const areaOptions = () => [["", "All areas"], ...areas.map((a) => [a.id, a.title])];
2661
+ // The queue is a work list: one row of title and filters, then the gaps.
2662
+ function viewGaps(view) {
2663
+ const box = el("div", null, "stack compact"),
2664
+ head = el("div", null, "map-head");
2665
+ head.append(el("h1", "Gaps"));
2666
+ head.title = "Questions about what is missing, unverified or could be added. Each one is rechecked and then decided by a person.";
2667
+ box.append(head);
2668
+ const pool = nodes.filter(
2669
+ (n) => isGap(n) && inArea(n, gapArea) && (!gapKind || n.kind === gapKind),
2670
+ ),
2671
+ again = () => show();
2672
+ head.append(
2673
+ pills(
2674
+ "State",
2675
+ // A state with no gaps under the current filters is left out, unless it is the one selected.
2676
+ [
2677
+ ["all", "All", pool.length],
2678
+ ...STATES.map((s) => [s, stateLabels[s], pool.filter((g) => stateOf(g) === s).length]).filter(
2679
+ ([s, , count]) => count || s === gapState,
2680
+ ),
2681
+ ],
2682
+ gapState,
2683
+ (s) => {
2684
+ gapState = s;
2685
+ again();
2686
+ },
2687
+ ),
2688
+ );
2689
+ if (stateHints[gapState]) box.append(el("p", stateHints[gapState], "muted small"));
2690
+ const kinds = Object.keys(kindLabels);
2691
+ nodes.forEach((n) => {
2692
+ if (isGap(n) && str(n.kind) && !kinds.includes(n.kind)) kinds.push(n.kind);
2693
+ });
2694
+ head.append(
2695
+ selectOf("Area", areaOptions(), gapArea, (v) => {
2696
+ gapArea = v;
2697
+ again();
2698
+ }),
2699
+ selectOf("Kind", [["", "All kinds"], ...kinds.map((k) => [k, kindLabels[k] || k])], gapKind, (v) => {
2700
+ gapKind = v;
2701
+ again();
2702
+ }),
2703
+ );
2704
+ const shown = pool
2705
+ .filter((g) => gapState === "all" || stateOf(g) === gapState)
2706
+ .sort((a, b) => stateRank(a) - stateRank(b) || byTitle(a, b));
2707
+ if (shown.length) {
2708
+ const card = el("section", null, "card");
2709
+ card.id = "gap-list";
2710
+ shown.forEach((g) => card.append(gapRow(g)));
2711
+ box.append(card);
2712
+ } else box.append(el("p", "No gaps match. Try other filters.", "empty"));
2713
+ view.append(box);
2714
+ }
2715
+
2716
+ let mapArea = "";
2717
+ function viewMap() {
2718
+ const gaps = mode === "gap";
2719
+ $("#map-title").textContent = gaps ? "Gap map" : "Spec map";
2720
+ graph.setAttribute(
2721
+ "aria-label",
2722
+ gaps
2723
+ ? "Map of gaps and their plans, with the spec pages they refer to, one frame per area. Every page is also in the tree."
2724
+ : "Map of how the spec pages link, one frame per area. Every page is also in the tree.",
2725
+ );
2726
+ const controls = $("#map-controls");
2727
+ controls.replaceChildren(
2728
+ ...pills("Map layer", [["spec", "Spec"], ["gap", "Gaps"]], mode, (m) => {
2729
+ mode = m;
2730
+ show();
2731
+ }).children,
2732
+ selectOf("Area", areaOptions(), mapArea, (v) => {
2733
+ mapArea = v;
2734
+ show();
2735
+ }),
2736
+ );
2737
+ const shown = gaps
2738
+ ? nodes.filter((n) => isGap(n) && inArea(n, mapArea)).sort((a, b) => stateRank(a) - stateRank(b) || byTitle(a, b))
2739
+ : nodes.filter((n) => layerOf(n) === "spec" && inArea(n, mapArea));
2740
+ draw(graphModel(shown), false);
2741
+ }
2742
+
2743
+ let changeFilter = "all";
2744
+ const statusWord = { added: "New", removed: "Removed", changed: "Updated" };
2745
+ const pageByFile = (path) => byPath.get(String(path || "").replace(/\.md$/i, ""));
2746
+ const inFilter = (path) =>
2747
+ changeFilter === "spec"
2748
+ ? /^(areas|notes)\//.test(path)
2749
+ : changeFilter === "gaps"
2750
+ ? /^(gaps|plans)\//.test(path)
2751
+ : true;
2752
+ // One line per page: what happened, its name (a link when the page exists), its file.
2753
+ const pageRow = (entry) => {
2754
+ const row = el("div", null, "row slim"),
2755
+ grow = el("div", null, "grow"),
2756
+ n = pageByFile(entry.path);
2757
+ if (entry.status) row.append(el("span", statusWord[entry.status] || str(entry.status), "tag " + str(entry.status)));
2758
+ grow.append(n ? button(n.title, "rowlink", () => openNode(n)) : el("span", str(entry.path)));
2759
+ row.append(grow);
2760
+ if (n) row.append(el("span", str(entry.path), "path"));
2761
+ if (str(entry.was) && str(entry.now)) {
2762
+ const what = el("details", null, "what"),
2763
+ box = el("div", null, "wasnow"),
2764
+ was = el("div", null, "was"),
2765
+ now = el("div");
2766
+ was.append(el("b", "was"), el("span", entry.was));
2767
+ now.append(el("b", "now"), el("span", entry.now));
2768
+ box.append(was, now);
2769
+ what.append(el("summary", "What changed"), box);
2770
+ row.append(what);
2771
+ }
2772
+ return row;
2773
+ };
2774
+ const GROUPS = [
2775
+ ["Spec pages", /^(areas|notes)\//],
2776
+ ["Gaps and plans", /^(gaps|plans)\//],
2777
+ ["Other pages", /^/],
2778
+ ];
2779
+ // Rows sorted into spec, gaps and the rest, with a label per group when there is more than one.
2780
+ function groupedRows(parent, entries) {
2781
+ const left = entries.slice(),
2782
+ groups = GROUPS.map(([label, test]) => {
2783
+ const mine = left.filter((p) => test.test(str(p.path)));
2784
+ mine.forEach((p) => left.splice(left.indexOf(p), 1));
2785
+ return [label, mine];
2786
+ }).filter(([, mine]) => mine.length);
2787
+ groups.forEach(([label, mine]) => {
2788
+ if (groups.length > 1) parent.append(el("div", label + " · " + mine.length, "mono-label group"));
2789
+ mine.forEach((p) => parent.append(pageRow(p)));
2790
+ });
2791
+ }
2792
+ const rereadBrief = () =>
2793
+ "Use the project-knowledge skill. These pages cite sources that changed since the last review. " +
2794
+ "Re-read each page against its sources, update the text where the code now differs, and accept the fingerprints only for pages you re-read.\n\n" +
2795
+ rereads
2796
+ .map((n) => "- " + repoPath(n) + (changedSources.has(n.path) ? " (changed: " + changedSources.get(n.path).join(", ") + ")" : ""))
2797
+ .join("\n");
2798
+ function viewChanges(view) {
2799
+ const box = el("div", null, "stack");
2800
+ box.append(
2801
+ header(
2802
+ "Recent changes",
2803
+ ["The code moved.", "See what the spec did."],
2804
+ "Pages whose sources changed since someone last read them, then every edit to the spec and the gap queue, newest first.",
2805
+ ),
2806
+ );
2807
+ const options = [["all", "Everything"], ["spec", "Spec pages"], ["gaps", "Gaps"]];
2808
+ if (newCommits) options.push(["new", "Since my last visit", newCommits]);
2809
+ if (!options.some(([v]) => v === changeFilter)) changeFilter = "all";
2810
+ box.append(
2811
+ pills("Show", options, changeFilter, (v) => {
2812
+ changeFilter = v;
2813
+ show();
2814
+ }),
2815
+ );
2816
+ const stale = rereads.filter((n) => inFilter(n.path));
2817
+ if (stale.length && changeFilter !== "new") {
2818
+ const card = el("section", null, "card notice"),
2819
+ head = el("div", null, "card-head"),
2820
+ text = el("div", null, "h2"),
2821
+ copy = button(null, "btn accent", () => copyText(rereadBrief(), "Copied " + plural(rereads.length, "page")));
2822
+ card.id = "rereads";
2823
+ text.textContent = plural(stale.length, "page") + (stale.length === 1 ? " needs" : " need") + " re-reading";
2824
+ copy.append(icon(ICON.copy), document.createTextNode("Copy for AI"));
2825
+ head.append(text, copy);
2826
+ card.append(head);
2827
+ stale.forEach((n) => {
2828
+ const row = el("div", null, "row"),
2829
+ grow = el("div", null, "grow");
2830
+ grow.append(button(n.title, "rowlink", () => openNode(n)), el("span", str(n.path), "path"));
2831
+ row.append(grow);
2832
+ (changedSources.get(n.path) || []).forEach((src) => {
2833
+ const s = el("span", null, "path");
2834
+ s.append(sourceLine(src));
2835
+ row.append(s);
2836
+ });
2837
+ card.append(row);
2838
+ });
2839
+ box.append(
2840
+ card,
2841
+ el("p", "A file these pages cite changed after the last review. The text may still be right; nobody has checked.", "muted small"),
2842
+ );
2843
+ }
2844
+ const waitingCommit = pendingPages.filter((p) => inFilter(str(p.path)));
2845
+ if (waitingCommit.length && changeFilter !== "new") {
2846
+ const card = el("section", null, "card"),
2847
+ head = el("div", null, "card-head");
2848
+ card.id = "pending";
2849
+ head.append(el("h2", "Not committed yet", "h2"), el("span", plural(waitingCommit.length, "page"), "path"));
2850
+ card.append(head);
2851
+ groupedRows(card, waitingCommit);
2852
+ box.append(card);
2853
+ }
2854
+ box.append(
2855
+ el("h2", "History", "h2"),
2856
+ el("p", "One line per commit. Open a commit to see its pages; a page name opens the page.", "muted small"),
2857
+ );
2858
+ let any = false,
2859
+ shownCommits = 0;
2860
+ historyLog.forEach((c, i) => {
2861
+ if (changeFilter === "new" && i >= newCommits) return;
2862
+ const pages = (Array.isArray(c.pages) ? c.pages : []).filter((p) => p && inFilter(str(p.path)));
2863
+ if (!pages.length) return;
2864
+ any = true;
2865
+ const card = el("article", null, "card commit"),
2866
+ open = el("details"),
2867
+ head = el("summary", null, "card-head"),
2868
+ text = el("div", null, "grow"),
2869
+ more = c.more && changeFilter === "all" ? c.more : 0;
2870
+ // New commits and the newest one start open; the rest are one line each.
2871
+ open.open = i < newCommits || shownCommits === 0;
2872
+ shownCommits++;
2873
+ text.append(
2874
+ el("div", str(c.date) + " · commit " + str(c.sha).slice(0, 7) + (i < newCommits ? " · new" : ""), "eyebrow"),
2875
+ el("h3", str(c.subject), "h3"),
2876
+ );
2877
+ head.append(text, el("span", plural(pages.length + more, "page"), "path"), icon(ICON.chevron));
2878
+ open.append(head);
2879
+ groupedRows(open, pages);
2880
+ if (more) {
2881
+ const rest = el("div", null, "row slim");
2882
+ rest.append(el("span", "and " + plural(more, "more page"), "muted small"));
2883
+ open.append(rest);
2884
+ }
2885
+ card.append(open);
2886
+ box.append(card);
2887
+ });
2888
+ if (!any)
2889
+ box.append(
2890
+ el(
2891
+ "p",
2892
+ historyLog.length
2893
+ ? "Nothing in the history matches this filter."
2894
+ : live
2895
+ ? "No Git history was found for this vault."
2896
+ : "History is shown when the spec is opened with the serve command.",
2897
+ "empty",
2898
+ ),
2899
+ );
2900
+ view.append(box);
2901
+ if (historyLog.length) store.set("seen", historyLog[0].sha);
2902
+ }
2903
+
2904
+ // --- Copy for AI: one dialog that turns a page and your words into a request for the agent ----
2905
+ // Each choice says what will happen, what to ask you for, and what the agent is told.
2906
+ const INTENTS = {
2907
+ recheck: {
2908
+ label: "Recheck it",
2909
+ hint: "The agent reads the code and writes what it found into the gap. You decide afterwards.",
2910
+ ask: "Anything it should look at (optional)",
2911
+ text: (c) =>
2912
+ "Use the project-knowledge skill to re-check this gap against the code. Write the result into the gap's Recheck section and leave the decision to me." +
2913
+ (c.note ? "\n\nLook at: " + c.note : ""),
2914
+ },
2915
+ checked: {
2916
+ label: "I checked it myself",
2917
+ hint: "You already verified this. The agent records your result under your name, and closes the gap if that settles it.",
2918
+ ask: "What you checked and what you saw",
2919
+ name: true,
2920
+ choices: ["outcome", [["gone", "It is fine now"], ["holds", "Still a gap"]]],
2921
+ text: (c) =>
2922
+ c.outcome === "holds"
2923
+ ? "Use the project-knowledge skill. I re-checked this gap myself and it still holds: " + (c.note || "[what you checked and saw]") +
2924
+ "\n\nRecord my recheck in the gap as confirmed, under my name (" + c.me + ") and today's date, with what I found in its Recheck section. Leave the decision open."
2925
+ : "Use the project-knowledge skill. I re-checked this gap myself and it no longer holds: " + (c.note || "[what you checked and saw]") +
2926
+ "\n\nRecord my recheck in the gap as not reproduced, under my name (" + c.me + ") and today's date, with what I found in its Recheck section. " +
2927
+ "If that answers the question, close the gap as done and say why in its Decision section.",
2928
+ },
2929
+ decide: {
2930
+ label: "Record my decision",
2931
+ hint: "You have made up your mind. The agent writes your decision into the gap under your name; it does not decide anything itself.",
2932
+ ask: "Why (one or two sentences)",
2933
+ name: true,
2934
+ choices: ["decision", [["accepted", "Accept"], ["rejected", "Reject"], ["deferred", "Defer"]]],
2935
+ text: (c) =>
2936
+ "Use the project-knowledge skill. I have decided this gap: " + c.decision + ". Reason: " + (c.note || "[why]") +
2937
+ "\n\nRecord the decision in the gap under my name (" + c.me + ") with today's date, and my reason in its Decision section. Change nothing else. " +
2938
+ "If the gap has not been rechecked yet, tell me before recording it.",
2939
+ },
2940
+ options: {
2941
+ label: "Lay out options",
2942
+ hint: "The agent writes the possible answers and what each would mean into the gap's Discussion. Nothing is decided.",
2943
+ ask: "What matters to you here (optional)",
2944
+ text: (c) =>
2945
+ "Use the project-knowledge skill. Lay out the options for this gap, with what each would mean, as an entry in its Discussion section. Do not decide it." +
2946
+ (c.note ? "\n\nWhat matters to me: " + c.note : ""),
2947
+ },
2948
+ plan: {
2949
+ label: "Plan it",
2950
+ hint: "The agent writes a plan for an accepted gap: steps, checks, what must be decided first. No code is changed.",
2951
+ ask: "Limits or wishes for the plan (optional)",
2952
+ text: (c) =>
2953
+ "Use the spec-change skill to plan this gap. Plan only, do not build it, and only if its decision is accepted; otherwise tell me what is missing." +
2954
+ (c.note ? "\n\nKeep in mind: " + c.note : ""),
2955
+ },
2956
+ change: {
2957
+ label: "Change the behavior",
2958
+ hint: "You want the product to work differently. The agent asks its questions first, then edits the spec on a branch, builds the change and checks it.",
2959
+ ask: "What should be different, and for whom",
2960
+ text: (c) =>
2961
+ "Use the spec-change skill. I want to change the behavior this page describes. Ask your questions first, then edit the spec on a branch, build it and check every changed statement against the code." +
2962
+ "\n\nWhat I want: " + (c.note || "[describe the change]"),
2963
+ },
2964
+ question: {
2965
+ label: "Ask a question",
2966
+ hint: "The agent investigates and answers from the code, saying what it actually checked.",
2967
+ ask: "Your question",
2968
+ text: (c) => "Use the project-knowledge skill to investigate a question about this page.\n\nQuestion: " + (c.note || "[your question]"),
2969
+ },
2970
+ remove: {
2971
+ label: "Remove this page",
2972
+ hint: "You think this page is noise. The agent deletes the file and fixes the pages that link to it. For a real question you disagree with, record a decision to reject it instead, so the answer is kept.",
2973
+ ask: "Why it should go (optional)",
2974
+ text: (c) =>
2975
+ "Use the project-knowledge skill to remove this page from the vault: " + (c.note || "I consider it noise") +
2976
+ ".\n\nDelete the file, remove or reword every link to it on other pages, and run check. Do not put another page in its place, and tell me what you removed.",
2977
+ },
2978
+ reread: {
2979
+ label: "Re-read against the code",
2980
+ hint: "The agent compares this page with its sources and updates the text where the code now differs.",
2981
+ ask: "Anything that looks wrong to you (optional)",
2982
+ text: (c) =>
2983
+ "Use the project-knowledge skill to re-read this page against its sources and update it where the code now differs." +
2984
+ (c.note ? "\n\nI suspect: " + c.note : ""),
2985
+ },
2986
+ };
2987
+ const intentsFor = (n) =>
2988
+ isGap(n)
2989
+ ? ["recheck", "checked", "decide", "options", "plan", "change", "remove"]
2990
+ : layerOf(n) === "spec"
2991
+ ? ["change", "question", "reread", "remove"]
2992
+ : n.type === "index"
2993
+ ? ["question"]
2994
+ : ["question", "remove"];
2995
+ const refsOf = (n) =>
2996
+ isGap(n)
2997
+ ? neighbours(n, "spec")
2998
+ : neighbours(n, "spec").filter((r) => r.type !== "area");
2999
+ let copyState = null;
3000
+ function pageBrief(n, state) {
3001
+ const lines = [
3002
+ INTENTS[state.intent].text({ ...state, note: state.note.trim(), me: state.me.trim() || "[your name]" }),
3003
+ "",
3004
+ (isGap(n) ? "Gap: " : "Page: ") + repoPath(n),
3005
+ "Title: " + n.title,
3006
+ ];
3007
+ if (isGap(n))
3008
+ lines.push(
3009
+ "State: " +
3010
+ [stateLabels[stateOf(n)].toLowerCase(), (kindLabels[n.kind] || str(n.kind)).toLowerCase(), str(n.priority)]
3011
+ .filter(Boolean)
3012
+ .join(" · "),
3013
+ );
3014
+ const refs = refsOf(n);
3015
+ if (state.refs && refs.length) lines.push("", isGap(n) ? "It refers to:" : "Related pages:", pageLines(refs));
3016
+ if (state.text) lines.push("", "Text of the page:", "", bodyOf(n).trim());
3017
+ return lines.join("\n");
3018
+ }
3019
+ // While a dialog is open the page behind it stays put, so there is one scrollbar at most.
3020
+ function lockPage(on) {
3021
+ if (document.body && document.body.style) document.body.style.overflow = on ? "hidden" : "";
3022
+ }
3023
+ function openCopy(n) {
3024
+ lockPage(true);
3025
+ copyState = {
3026
+ node: n,
3027
+ intent: intentsFor(n)[0],
3028
+ outcome: "gone",
3029
+ decision: "accepted",
3030
+ note: "",
3031
+ me: str(store.get("me", "")),
3032
+ refs: true,
3033
+ text: false,
3034
+ };
3035
+ $("#copydlg").hidden = false;
3036
+ renderCopy();
3037
+ }
3038
+ function closeCopy() {
3039
+ lockPage(false);
3040
+ copyState = null;
3041
+ $("#copydlg").hidden = true;
3042
+ $("#copy-card").replaceChildren();
3043
+ }
3044
+ function renderCopy() {
3045
+ const card = $("#copy-card"),
3046
+ n = copyState.node,
3047
+ intent = INTENTS[copyState.intent],
3048
+ refs = refsOf(n),
3049
+ pre = el("pre", pageBrief(n, copyState)),
3050
+ refresh = () => {
3051
+ pre.textContent = pageBrief(n, copyState);
3052
+ };
3053
+ pre.id = "copy-preview";
3054
+ card.replaceChildren();
3055
+ const top = el("div", null, "stack"),
3056
+ meta = el("div", null, "metarow");
3057
+ top.style.gap = "10px";
3058
+ meta.append(isGap(n) ? stateBadge(n) : statusBadge(n), el("span", repoPath(n), "path"));
3059
+ top.append(el("div", "Copy for AI", "eyebrow"), el("h2", n.title, "h2"), meta);
3060
+
3061
+ const want = el("fieldset");
3062
+ want.append(
3063
+ el("legend", "What should the agent do?"),
3064
+ pills("What should the agent do?", intentsFor(n).map((k) => [k, INTENTS[k].label]), copyState.intent, (v) => {
3065
+ copyState.intent = v;
3066
+ renderCopy();
3067
+ }),
3068
+ );
3069
+ const hint = el("p", intent.hint, "muted small");
3070
+ hint.id = "copy-hint";
3071
+ want.append(hint);
3072
+ if (intent.choices) {
3073
+ const [key, options] = intent.choices,
3074
+ sub = pills(intent.label, options, copyState[key], (v) => {
3075
+ copyState[key] = v;
3076
+ renderCopy();
3077
+ });
3078
+ sub.id = "copy-choice";
3079
+ want.append(sub);
3080
+ }
3081
+
3082
+ // Typing updates the preview in place, so the field keeps the cursor.
3083
+ const words = el("fieldset"),
3084
+ field = (id, label, value, rows, change) => {
3085
+ const tag = el("label", label, "field-label"),
3086
+ input = el(rows ? "textarea" : "input");
3087
+ tag.setAttribute("for", id);
3088
+ input.id = id;
3089
+ if (rows) input.rows = rows;
3090
+ else input.type = "text";
3091
+ input.value = value;
3092
+ input.addEventListener("input", () => {
3093
+ change(input.value);
3094
+ refresh();
3095
+ });
3096
+ words.append(tag, input);
3097
+ };
3098
+ field("copy-note", intent.ask, copyState.note, 2, (v) => {
3099
+ copyState.note = v;
3100
+ });
3101
+ if (intent.name)
3102
+ field("copy-me", "Your name, as it should appear in the gap", copyState.me, 0, (v) => {
3103
+ copyState.me = v;
3104
+ store.set("me", v.trim());
3105
+ });
3106
+
3107
+ const include = el("fieldset", null, "checks");
3108
+ include.append(el("legend", "Include"));
3109
+ const check = (text, key) => {
3110
+ const label = el("label", null, "check"),
3111
+ input = el("input");
3112
+ input.type = "checkbox";
3113
+ input.checked = copyState[key];
3114
+ input.addEventListener("change", () => {
3115
+ copyState[key] = !!input.checked;
3116
+ refresh();
3117
+ });
3118
+ label.append(input, document.createTextNode(text));
3119
+ include.append(label);
3120
+ };
3121
+ if (refs.length) check(isGap(n) ? "The " + plural(refs.length, "spec page") + " it refers to" : "The " + plural(refs.length, "related page"), "refs");
3122
+ check("Full text of the page", "text");
3123
+
3124
+ const actions = el("div", null, "actions"),
3125
+ copy = button(null, "btn accent", () => copyText(pageBrief(n, copyState), "Copied. Paste it into your agent."));
3126
+ copy.id = "copy-do";
3127
+ copy.append(icon(ICON.copy), document.createTextNode("Copy"));
3128
+ actions.append(copy, button("Close", "btn", closeCopy), el("span", "Nothing is sent. It goes to your clipboard.", "muted small"));
3129
+ const preview = el("div", null, "night");
3130
+ preview.append(el("div", "What gets copied", "eyebrow"), pre);
3131
+ const controls = el("div", null, "copy-controls"),
3132
+ side = el("div", null, "copy-side");
3133
+ controls.append(want, words, include);
3134
+ side.append(preview, actions);
3135
+ card.append(top, controls, side);
3136
+ }
3137
+ $("#copydlg").addEventListener("click", (e) => {
3138
+ if (e.target === $("#copydlg")) closeCopy();
3139
+ });
3140
+
3141
+ // --- Search: pages, gaps and cited files, from anywhere -----------------------------------------
3142
+ let palette = { filter: "all", index: 0, hits: [] };
3143
+ const fileText = new Map();
3144
+ const lowerFile = (key) => {
3145
+ if (!fileText.has(key)) fileText.set(key, str(files[key] && files[key].text).toLocaleLowerCase());
3146
+ return fileText.get(key);
3147
+ };
3148
+ const marked = (text, needle) => {
3149
+ const span = el("span"),
3150
+ at = needle ? text.toLocaleLowerCase().indexOf(needle) : -1;
3151
+ if (at < 0) span.textContent = text;
3152
+ else
3153
+ span.append(
3154
+ document.createTextNode(text.slice(0, at)),
3155
+ el("mark", text.slice(at, at + needle.length)),
3156
+ document.createTextNode(text.slice(at + needle.length)),
3157
+ );
3158
+ return span;
3159
+ };
3160
+ function findPages(needle, list, limit) {
3161
+ const scored = [];
3162
+ list.forEach((n) => {
3163
+ const where = str(n.title).toLocaleLowerCase().includes(needle)
3164
+ ? 0
3165
+ : str(n.summary).toLocaleLowerCase().includes(needle)
3166
+ ? 1
3167
+ : str(n.body).toLocaleLowerCase().includes(needle)
3168
+ ? 2
3169
+ : -1;
3170
+ if (where >= 0) scored.push([where, n]);
3171
+ });
3172
+ return scored.sort((a, b) => a[0] - b[0] || byTitle(a[1], b[1])).slice(0, limit).map(([, n]) => n);
3173
+ }
3174
+ function searchGroups(query) {
3175
+ const needle = query.trim().toLocaleLowerCase(),
3176
+ want = (group) => palette.filter === "all" || palette.filter === group;
3177
+ if (!needle) {
3178
+ const lately = recent.map((id) => byId.get(id)).filter(Boolean);
3179
+ return [[lately.length ? "Recently viewed" : "Areas", "features", lately.length ? lately : areas]];
3180
+ }
3181
+ const groups = [];
3182
+ if (want("features"))
3183
+ groups.push(["Features", "features", findPages(needle, nodes.filter((n) => layerOf(n) === "spec" && n.status !== "superseded"), 8)]);
3184
+ if (want("gaps")) groups.push(["Gaps", "gaps", findPages(needle, nodes.filter((n) => layerOf(n) === "gap"), 8)]);
3185
+ if (want("features"))
3186
+ groups.push(["Other pages", "features", findPages(needle, nodes.filter((n) => layerOf(n) === "nav"), 4)]);
3187
+ if (want("files")) {
3188
+ const keys = Object.keys(files),
3189
+ byName = keys.filter((k) => k.toLocaleLowerCase().includes(needle)),
3190
+ byText = keys.filter((k) => !byName.includes(k) && lowerFile(k).includes(needle));
3191
+ groups.push(["Files", "files", [...byName, ...byText].slice(0, 6)]);
3192
+ }
3193
+ return groups.filter(([, , items]) => items.length);
3194
+ }
3195
+ function choose(hit) {
3196
+ closePalette();
3197
+ if (typeof hit === "string") return openFile({ key: hit, from: 0, to: 0 });
3198
+ openNode(hit);
3199
+ }
3200
+ function renderPalette() {
3201
+ const query = $("#palette-input").value,
3202
+ needle = query.trim().toLocaleLowerCase(),
3203
+ filters = $("#palette-filters"),
3204
+ results = $("#palette-results");
3205
+ filters.replaceChildren(
3206
+ ...pills(
3207
+ "Limit results",
3208
+ [["all", "Everything"], ["features", "Features"], ["gaps", "Gaps"], ["files", "Files"]],
3209
+ palette.filter,
3210
+ (v) => {
3211
+ palette.filter = v;
3212
+ palette.index = 0;
3213
+ renderPalette();
3214
+ },
3215
+ ).children,
3216
+ );
3217
+ results.replaceChildren();
3218
+ palette.hits = [];
3219
+ searchGroups(query).forEach(([title, , items]) => {
3220
+ results.append(el("div", title, "eyebrow"));
3221
+ items.forEach((item) => {
3222
+ const i = palette.hits.length,
3223
+ b = button(null, "result", () => choose(item)),
3224
+ grow = el("span", null, "grow");
3225
+ palette.hits.push(item);
3226
+ b.setAttribute("aria-selected", String(i === palette.index));
3227
+ if (typeof item === "string") {
3228
+ const name = marked(item, needle);
3229
+ name.className = "path";
3230
+ grow.append(name);
3231
+ b.append(grow, el("span", "cited file", "muted small"));
3232
+ } else {
3233
+ const name = marked(item.title, needle),
3234
+ parent = item.type === "note" ? byId.get(primaryArea(item)) : null;
3235
+ name.className = "name";
3236
+ grow.append(name, el("span", parent ? parent.title : types[item.type] || "", "muted small"));
3237
+ b.append(grow);
3238
+ if (isGap(item)) b.append(stateBadge(item));
3239
+ }
3240
+ results.append(b);
3241
+ });
3242
+ });
3243
+ if (!palette.hits.length) results.append(el("p", needle ? "Nothing matches." : "Type to search.", "empty"));
3244
+ if (palette.index >= palette.hits.length) palette.index = Math.max(0, palette.hits.length - 1);
3245
+ }
3246
+ function openPalette() {
3247
+ palette = { filter: "all", index: 0, hits: [] };
3248
+ const input = $("#palette-input");
3249
+ input.value = "";
3250
+ $("#palette").hidden = false;
3251
+ lockPage(true);
3252
+ renderPalette();
3253
+ if (typeof input.focus === "function") input.focus();
3254
+ }
3255
+ function closePalette() {
3256
+ lockPage(false);
3257
+ $("#palette").hidden = true;
3258
+ }
3259
+ $("#palette-input").addEventListener("input", () => {
3260
+ palette.index = 0;
3261
+ renderPalette();
3262
+ });
3263
+ $("#palette-input").addEventListener("keydown", (e) => {
3264
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
3265
+ e.preventDefault();
3266
+ const count = palette.hits.length;
3267
+ if (count) palette.index = (palette.index + (e.key === "ArrowDown" ? 1 : count - 1)) % count;
3268
+ renderPalette();
3269
+ } else if (e.key === "Enter") {
3270
+ e.preventDefault();
3271
+ if (palette.hits[palette.index] != null) choose(palette.hits[palette.index]);
3272
+ }
3273
+ });
3274
+ $("#palette").addEventListener("click", (e) => {
3275
+ if (e.target === $("#palette")) closePalette();
3276
+ });
3277
+ if (typeof document.addEventListener === "function")
3278
+ document.addEventListener("keydown", (e) => {
3279
+ if ((e.metaKey || e.ctrlKey) && String(e.key).toLowerCase() === "k") {
3280
+ e.preventDefault();
3281
+ openPalette();
3282
+ } else if (e.key === "Escape") {
3283
+ if (!$("#palette").hidden) closePalette();
3284
+ else if (!$("#copydlg").hidden) closeCopy();
3285
+ }
3286
+ });
3287
+
3288
+ // --- Put the current route on screen -------------------------------------------------------------
3289
+ let shownRoute = null;
3290
+ function show() {
3291
+ route = trail[at];
3292
+ let node = route.name === "page" ? byId.get(route.id) : null;
3293
+ if (route.name === "page" && !node) route = trail[at] = { name: "home", id: "" };
3294
+ selected = node || null;
3295
+ if (node) {
3296
+ remember(node);
3297
+ const area = node.type === "area" ? node.id : node.type === "note" ? primaryArea(node) : "";
3298
+ if (area) openAreas.add(area);
3299
+ }
3300
+ renderSide();
3301
+ renderTop();
3302
+ const view = $("#view"),
3303
+ isMap = route.name === "map";
3304
+ view.replaceChildren();
3305
+ view.hidden = isMap;
3306
+ $("#mapview").hidden = !isMap;
3307
+ if (route.name === "page") viewPage(view, node);
3308
+ else if (route.name === "gaps") viewGaps(view);
3309
+ else if (isMap) viewMap();
3310
+ else if (route.name === "changes") viewChanges(view);
3311
+ else viewHome(view);
3312
+ document.title = (node ? node.title + " · " : "") + projectTitle;
3313
+ if (shownRoute && sameRoute(shownRoute, route)) return;
3314
+ shownRoute = route;
3315
+ if (hasWindow && typeof window.scrollTo === "function") window.scrollTo(0, 0);
3316
+ }
3317
+ function graphModel(shown) {
3318
+ if (mode !== "gap")
3319
+ return { items: shown, links: edges, context: new Set() };
3320
+ const core = new Map(shown.map((n) => [n.id, n]));
3321
+ const plans = nodes.filter((p) => isPlan(p) && core.has(p.gap));
3322
+ plans.forEach((p) => core.set(p.id, p));
3323
+ const context = new Map();
3324
+ edges.forEach((e) =>
3325
+ [
3326
+ [e.source, e.target],
3327
+ [e.target, e.source],
3328
+ ].forEach(([a, b]) => {
3329
+ const o = byId.get(b);
3330
+ if (core.has(a) && o && layerOf(o) === "spec")
3331
+ context.set(o.id, o);
3332
+ }),
3333
+ );
3334
+ return {
3335
+ items: [...core.values(), ...context.values()],
3336
+ links: edges.concat(
3337
+ plans.map((p) => ({ source: p.id, target: p.gap })),
3338
+ ),
3339
+ context: new Set(context.keys()),
3340
+ };
3341
+ }
3342
+ // One labelled frame per area with its pages inside. Membership is shown by the frame,
3343
+ // so only real links are drawn; index, coverage and run pages are not part of the map.
3344
+ function draw(model, preserveView) {
3345
+ const shown = model.items.filter((n) => layerOf(n) !== "nav"),
3346
+ ids = new Set(shown.map((n) => n.id));
3347
+ graph.replaceChildren();
3348
+ const keyOf = (n) => (n.type === "area" ? n.id : (n.areas || [])[0] || "");
3349
+ const groups = new Map();
3350
+ shown.forEach((n) => {
3351
+ const key = keyOf(n);
3352
+ if (!groups.has(key)) groups.set(key, []);
3353
+ groups.get(key).push(n);
3354
+ });
3355
+ const CW = 190,
3356
+ CH = 92,
3357
+ PAD = 24,
3358
+ HEAD = 48,
3359
+ GAP = 34;
3360
+ const titleOf = (key) =>
3361
+ str(byId.get(key)?.title) || (key ? String(key) : "Other");
3362
+ const clusters = [...groups.entries()]
3363
+ .map(([key, group]) => {
3364
+ const head = group.find((n) => n.type === "area") || null;
3365
+ const members = group
3366
+ .filter((n) => n !== head)
3367
+ .sort((x, y) =>
3368
+ model.context.has(x.id) !== model.context.has(y.id)
3369
+ ? model.context.has(x.id)
3370
+ ? 1
3371
+ : -1
3372
+ : stateRank(x) - stateRank(y) || byTitle(x, y),
3373
+ );
3374
+ const cols = Math.max(
3375
+ 1,
3376
+ Math.min(5, Math.ceil(Math.sqrt(members.length))),
3377
+ );
3378
+ const rows = Math.ceil(members.length / cols);
3379
+ return {
3380
+ key,
3381
+ head,
3382
+ members,
3383
+ cols,
3384
+ title: titleOf(key),
3385
+ w: Math.max(cols * CW, 250) + PAD * 2,
3386
+ h: HEAD + rows * CH + (rows ? PAD / 2 : 0),
3387
+ };
3388
+ })
3389
+ .sort(
3390
+ (x, y) =>
3391
+ !x.key - !y.key ||
3392
+ x.title.localeCompare(y.title) ||
3393
+ String(x.key).localeCompare(String(y.key)),
3394
+ );
3395
+ // Shelf packing: fill rows up to a width that keeps the whole map roughly landscape.
3396
+ const area = clusters.reduce((t, c) => t + (c.w + GAP) * (c.h + GAP), 0);
3397
+ const rowWidth = Math.max(900, Math.sqrt(area * 1.8));
3398
+ const positions = new Map();
3399
+ let x = GAP,
3400
+ y = GAP,
3401
+ rowH = 0,
3402
+ maxW = 0;
3403
+ clusters.forEach((c) => {
3404
+ if (x > GAP && x + c.w > rowWidth) {
3405
+ x = GAP;
3406
+ y += rowH + GAP;
3407
+ rowH = 0;
3408
+ }
3409
+ c.x = x;
3410
+ c.y = y;
3411
+ if (c.head) positions.set(c.head.id, { x: x + PAD + 12, y: y + 26 });
3412
+ const inset = (c.w - c.cols * CW) / 2;
3413
+ c.members.forEach((n, i) =>
3414
+ positions.set(n.id, {
3415
+ x: x + inset + (i % c.cols) * CW + CW / 2,
3416
+ y: y + HEAD + Math.floor(i / c.cols) * CH + 26,
3417
+ }),
3418
+ );
3419
+ x += c.w + GAP;
3420
+ rowH = Math.max(rowH, c.h);
3421
+ maxW = Math.max(maxW, x);
3422
+ });
3423
+ initialBox = {
3424
+ x: 0,
3425
+ y: 0,
3426
+ w: Math.max(700, maxW),
3427
+ h: Math.max(430, y + rowH + GAP),
3428
+ };
3429
+ if (!preserveView) box = { ...initialBox };
3430
+ applyBox();
3431
+ const layer = sv("g", {});
3432
+ graph.append(layer);
3433
+ const clip = (text, max) =>
3434
+ text.length > max ? text.slice(0, max - 1) + "…" : text;
3435
+ clusters.forEach((c) => {
3436
+ layer.append(
3437
+ sv("rect", {
3438
+ class: "cluster",
3439
+ x: c.x,
3440
+ y: c.y,
3441
+ width: c.w,
3442
+ height: c.h,
3443
+ rx: 14,
3444
+ }),
3445
+ );
3446
+ if (!c.head) {
3447
+ const t = sv("text", {
3448
+ class: "cluster-label",
3449
+ x: c.x + PAD,
3450
+ y: c.y + 31,
3451
+ });
3452
+ t.textContent = clip(c.title, Math.floor((c.w - PAD * 2) / 9));
3453
+ layer.append(t);
3454
+ }
3455
+ });
3456
+ model.links.forEach((e) => {
3457
+ if (!ids.has(e.source) || !ids.has(e.target)) return;
3458
+ const na = byId.get(e.source),
3459
+ nb = byId.get(e.target),
3460
+ a = positions.get(e.source),
3461
+ b = positions.get(e.target);
3462
+ if (!na || !nb || !a || !b) return;
3463
+ // The frame already says which area a page belongs to.
3464
+ if (
3465
+ (na.type === "area" && keyOf(nb) === na.id) ||
3466
+ (nb.type === "area" && keyOf(na) === nb.id)
3467
+ )
3468
+ return;
3469
+ layer.append(
3470
+ sv("line", {
3471
+ class: keyOf(na) === keyOf(nb) ? "" : "cross",
3472
+ x1: a.x,
3473
+ y1: a.y,
3474
+ x2: b.x,
3475
+ y2: b.y,
3476
+ }),
3477
+ );
3478
+ });
3479
+ const widthOf = new Map(clusters.map((c) => [c.key, c.w]));
3480
+ shown.forEach((n) => {
3481
+ const p = positions.get(n.id),
3482
+ state = stateOf(n),
3483
+ isArea = n.type === "area",
3484
+ g = sv("g", {
3485
+ class:
3486
+ "graph-node " +
3487
+ (isArea ? "area " : "") +
3488
+ (isPlan(n) ? "plan-node " : "") +
3489
+ (model.context.has(n.id) ? "context " : "") +
3490
+ stateClass(n) +
3491
+ (selected?.id === n.id ? " selected" : ""),
3492
+ transform: `translate(${p.x} ${p.y})`,
3493
+ tabindex: "0",
3494
+ role: "button",
3495
+ "aria-label":
3496
+ n.title +
3497
+ (state
3498
+ ? " (" + stateLabels[state] + ")" +
3499
+ (recheckOutdated(n) ? ", recheck outdated" : "")
3500
+ : isPlan(n)
3501
+ ? " (Plan)"
3502
+ : ""),
3503
+ });
3504
+ if (isPlan(n))
3505
+ g.append(sv("rect", { x: -12, y: -12, width: 24, height: 24, rx: 4 }));
3506
+ else
3507
+ g.append(
3508
+ sv("circle", {
3509
+ r: isArea
3510
+ ? 11
3511
+ : ["needs-recheck", "needs-decision"].includes(state)
3512
+ ? 16
3513
+ : 13,
3514
+ }),
3515
+ );
3516
+ const t = isArea
3517
+ ? sv("text", { x: 20, y: 5, "text-anchor": "start" })
3518
+ : sv("text", { x: 0, y: 32, "text-anchor": "middle" });
3519
+ t.textContent = clip(
3520
+ String(n.title || ""),
3521
+ isArea ? Math.floor((widthOf.get(n.id) - PAD * 2 - 32) / 9) : 26,
3522
+ );
3523
+ g.append(t);
3524
+ g.addEventListener("click", () => openNode(n));
3525
+ g.addEventListener("keydown", (e) => {
3526
+ if (e.key === "Enter" || e.key === " ") {
3527
+ e.preventDefault();
3528
+ openNode(n);
3529
+ }
3530
+ });
3531
+ layer.append(g);
3532
+ });
3533
+ }
3534
+ function applyBox() {
3535
+ graph.setAttribute("viewBox", `${box.x} ${box.y} ${box.w} ${box.h}`);
3536
+ }
3537
+ function zoom(f) {
3538
+ const w = box.w * f,
3539
+ h = box.h * f;
3540
+ box.x += (box.w - w) / 2;
3541
+ box.y += (box.h - h) / 2;
3542
+ box.w = w;
3543
+ box.h = h;
3544
+ applyBox();
3545
+ }
3546
+ $("#zoom-in").addEventListener("click", () => zoom(0.8));
3547
+ $("#zoom-out").addEventListener("click", () => zoom(1.25));
3548
+ $("#reset").addEventListener("click", () => {
3549
+ box = { ...initialBox };
3550
+ applyBox();
3551
+ });
3552
+ let drag = null;
3553
+ graph.addEventListener("pointerdown", (e) => {
3554
+ if (e.target.closest(".graph-node")) return;
3555
+ drag = { x: e.clientX, y: e.clientY, box: { ...box } };
3556
+ graph.setPointerCapture(e.pointerId);
3557
+ graph.classList.add("dragging");
3558
+ });
3559
+ graph.addEventListener("pointermove", (e) => {
3560
+ if (!drag) return;
3561
+ const rect = graph.getBoundingClientRect();
3562
+ box.x = drag.box.x - ((e.clientX - drag.x) * drag.box.w) / rect.width;
3563
+ box.y =
3564
+ drag.box.y - ((e.clientY - drag.y) * drag.box.h) / rect.height;
3565
+ applyBox();
3566
+ });
3567
+ graph.addEventListener("pointerup", () => {
3568
+ drag = null;
3569
+ graph.classList.remove("dragging");
3570
+ });
3571
+ graph.addEventListener("pointercancel", () => {
3572
+ drag = null;
3573
+ graph.classList.remove("dragging");
3574
+ });
3575
+ if (hasWindow)
3576
+ window.addEventListener("popstate", (e) => {
3577
+ const s = e.state;
3578
+ if (s && Number.isInteger(s.at) && trail[s.at] && s.route && sameRoute(trail[s.at], s.route)) at = s.at;
3579
+ else {
3580
+ // A reload or a typed address: start a fresh trail at that place.
3581
+ trail.splice(0, trail.length, s && s.route && ROUTES.includes(s.route.name) ? s.route : parseHash(location.hash));
3582
+ at = 0;
3583
+ }
3584
+ show();
3585
+ });
3586
+ // An address typed or pasted into the bar changes only the part after #: follow it.
3587
+ if (hasWindow)
3588
+ window.addEventListener("hashchange", () => {
3589
+ const next = parseHash(location.hash);
3590
+ if (sameRoute(next, trail[at])) return;
3591
+ trail.splice(at + 1);
3592
+ trail.push(next);
3593
+ at = trail.length - 1;
3594
+ try {
3595
+ history.replaceState({ at, route: next }, "", routeHash(next));
3596
+ } catch {
3597
+ /* the trail works without it */
3598
+ }
3599
+ show();
3600
+ });
3601
+ const first = typeof location !== "undefined" ? parseHash(location.hash) : { name: "home", id: "" };
3602
+ trail.push(first);
3603
+ at = 0;
3604
+ if (hasWindow) {
3605
+ try {
3606
+ history.replaceState({ at: 0, route: first }, "", routeHash(first));
3607
+ } catch {
3608
+ /* the trail works without it */
3609
+ }
3610
+ }
3611
+ show();
3612
+ })();
3613
+ </script>
3614
+ </body>
3615
+ </html>