@r_masseater/intent-book 0.0.0 → 0.2.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,1859 @@
1
+ #!/usr/bin/env node
2
+ import { runMain } from "@r_masseater/node-main";
3
+ import { Array, Boolean, Console, Effect, FileSystem, Function, Match, Option, Order, Path, Predicate, Record, Schema, String as String$1, pipe } from "effect";
4
+ import { Argument, Command, Flag } from "effect/cli";
5
+ import { h } from "hastscript";
6
+ import { parse } from "yaml";
7
+ import { toHtml } from "hast-util-to-html";
8
+ import { toString } from "mdast-util-to-string";
9
+ import rehypeShiki from "@shikijs/rehype";
10
+ import rehypeSlug from "rehype-slug";
11
+ import remarkGfm from "remark-gfm";
12
+ import remarkParse from "remark-parse";
13
+ import remarkRehype from "remark-rehype";
14
+ import { unified } from "unified";
15
+ import { visit } from "unist-util-visit";
16
+ // package.json
17
+ var version = "0.2.0";
18
+ // src/features/build-site/model/asset-paths.ts
19
+ const ASSET_DIRECTORY = "_intent-book";
20
+ const STYLE_PATH = `${ASSET_DIRECTORY}/book.css`;
21
+ const SCRIPT_PATH = `${ASSET_DIRECTORY}/book.js`;
22
+ const INDEX_PATH = `${ASSET_DIRECTORY}/search.json`;
23
+ // src/features/build-site/model/assets-script.ts
24
+ const SCRIPT = String.raw`const root = document.documentElement;
25
+ const body = document.body;
26
+ const narrow = window.matchMedia("(max-width: 820px)");
27
+
28
+ const remember = (key, value) => {
29
+ try {
30
+ localStorage.setItem(key, value);
31
+ } catch {
32
+ return;
33
+ }
34
+ };
35
+
36
+ const recall = (key) => {
37
+ try {
38
+ return localStorage.getItem(key);
39
+ } catch {
40
+ return null;
41
+ }
42
+ };
43
+
44
+ const savedTheme = recall("intent-book-theme");
45
+ if (savedTheme) {
46
+ root.dataset.theme = savedTheme;
47
+ }
48
+
49
+ if (recall("intent-book-nav") === "closed" && !narrow.matches) {
50
+ body.dataset.nav = "closed";
51
+ }
52
+
53
+ document.querySelector("[data-theme-toggle]")?.addEventListener("click", () => {
54
+ const dark =
55
+ root.dataset.theme === "dark" ||
56
+ (root.dataset.theme === undefined && window.matchMedia("(prefers-color-scheme: dark)").matches);
57
+ root.dataset.theme = dark ? "light" : "dark";
58
+ remember("intent-book-theme", root.dataset.theme);
59
+ });
60
+
61
+ document.querySelector("[data-nav-toggle]")?.addEventListener("click", () => {
62
+ if (narrow.matches) {
63
+ body.dataset.nav = body.dataset.nav === "open" ? "" : "open";
64
+ return;
65
+ }
66
+ body.dataset.nav = body.dataset.nav === "closed" ? "" : "closed";
67
+ remember("intent-book-nav", body.dataset.nav);
68
+ });
69
+
70
+ const headings = [...document.querySelectorAll(".prose :is(h2, h3)[id]")];
71
+ const links = new Map(
72
+ [...document.querySelectorAll(".toc a")].map((link) => [link.getAttribute("href").slice(1), link]),
73
+ );
74
+ if (headings.length > 0 && links.size > 0) {
75
+ const mark = () => {
76
+ const passed = headings.filter((heading) => heading.getBoundingClientRect().top < 120);
77
+ const current = passed.at(-1) ?? headings[0];
78
+ for (const [id, link] of links) {
79
+ if (id === current.id) {
80
+ link.setAttribute("aria-current", "true");
81
+ } else {
82
+ link.removeAttribute("aria-current");
83
+ }
84
+ }
85
+ };
86
+ window.addEventListener("scroll", mark, { passive: true });
87
+ mark();
88
+ }
89
+
90
+ const dialog = document.querySelector("dialog.search");
91
+ if (dialog) {
92
+ const input = dialog.querySelector("input");
93
+ const list = dialog.querySelector("ul");
94
+ const base = document.querySelector("meta[name='intent-book-base']").content;
95
+ let index;
96
+
97
+ const load = async () => {
98
+ if (!index) {
99
+ index = await (await fetch(base + "${INDEX_PATH}")).json();
100
+ }
101
+ return index;
102
+ };
103
+
104
+ const show = (entries) => {
105
+ list.replaceChildren(
106
+ ...entries.map((entry) => {
107
+ const item = document.createElement("li");
108
+ const link = document.createElement("a");
109
+ link.href = entry.url;
110
+ link.textContent = entry.title;
111
+ const detail = document.createElement("small");
112
+ detail.textContent = entry.book + " · " + entry.name;
113
+ link.append(detail);
114
+ item.append(link);
115
+ return item;
116
+ }),
117
+ );
118
+ if (entries.length === 0) {
119
+ const empty = document.createElement("li");
120
+ empty.className = "empty";
121
+ empty.textContent = input.value ? "No matches" : "";
122
+ list.append(empty);
123
+ }
124
+ };
125
+
126
+ const search = async () => {
127
+ const words = input.value.toLowerCase().split(/\s+/u).filter(Boolean);
128
+ const entries = await load();
129
+ if (words.length === 0) {
130
+ show([]);
131
+ return;
132
+ }
133
+ const scored = entries
134
+ .map((entry) => {
135
+ const haystack = entry.text.toLowerCase();
136
+ const title = (entry.title + " " + entry.name).toLowerCase();
137
+ if (!words.every((word) => haystack.includes(word))) {
138
+ return undefined;
139
+ }
140
+ return { entry, score: words.filter((word) => title.includes(word)).length };
141
+ })
142
+ .filter(Boolean)
143
+ .sort((left, right) => right.score - left.score);
144
+ show(scored.slice(0, 30).map((match) => match.entry));
145
+ };
146
+
147
+ const open = () => {
148
+ dialog.showModal();
149
+ input.focus();
150
+ input.select();
151
+ };
152
+
153
+ document.querySelector("[data-search-open]")?.addEventListener("click", open);
154
+ input.addEventListener("input", search);
155
+ input.addEventListener("keydown", (event) => {
156
+ if (event.key === "Enter") {
157
+ list.querySelector("a")?.click();
158
+ }
159
+ });
160
+ dialog.addEventListener("click", (event) => {
161
+ if (event.target === dialog) {
162
+ dialog.close();
163
+ }
164
+ });
165
+ window.addEventListener("keydown", (event) => {
166
+ if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
167
+ event.preventDefault();
168
+ open();
169
+ }
170
+ });
171
+ }
172
+ `;
173
+ // src/features/build-site/model/assets-styles-1.ts
174
+ const BASE_STYLES = String.raw`:root {
175
+ --bg: #ffffff;
176
+ --bg-soft: #f7f7f5;
177
+ --ink: #1b1d1f;
178
+ --ink-soft: #5c6166;
179
+ --line: #e4e4e0;
180
+ --accent: #0b6b5d;
181
+ --accent-soft: #e3f1ee;
182
+ --critical: #b42318;
183
+ --high: #b54708;
184
+ --code-bg: #f6f6f3;
185
+ --sidebar: 17rem;
186
+ --toc: 14.5rem;
187
+ --measure: 46rem;
188
+ --top: 3.5rem;
189
+ color-scheme: light;
190
+ }
191
+
192
+ :root[data-theme="dark"] {
193
+ --bg: #15171a;
194
+ --bg-soft: #1b1e22;
195
+ --ink: #e8e9ea;
196
+ --ink-soft: #a0a5ab;
197
+ --line: #2c3036;
198
+ --accent: #4fc3ae;
199
+ --accent-soft: #1d2f2c;
200
+ --critical: #ff8a80;
201
+ --high: #f5b361;
202
+ --code-bg: #1b1e22;
203
+ color-scheme: dark;
204
+ }
205
+
206
+ @media (prefers-color-scheme: dark) {
207
+ :root:not([data-theme="light"]) {
208
+ --bg: #15171a;
209
+ --bg-soft: #1b1e22;
210
+ --ink: #e8e9ea;
211
+ --ink-soft: #a0a5ab;
212
+ --line: #2c3036;
213
+ --accent: #4fc3ae;
214
+ --accent-soft: #1d2f2c;
215
+ --critical: #ff8a80;
216
+ --high: #f5b361;
217
+ --code-bg: #1b1e22;
218
+ color-scheme: dark;
219
+ }
220
+ }
221
+
222
+ * {
223
+ box-sizing: border-box;
224
+ }
225
+
226
+ html {
227
+ scroll-padding-top: calc(var(--top) + 1rem);
228
+ }
229
+
230
+ body {
231
+ margin: 0;
232
+ background: var(--bg);
233
+ color: var(--ink);
234
+ font: 16px/1.7 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
235
+ -webkit-font-smoothing: antialiased;
236
+ }
237
+
238
+ a {
239
+ color: var(--accent);
240
+ text-underline-offset: 0.18em;
241
+ }
242
+
243
+ button {
244
+ font: inherit;
245
+ color: inherit;
246
+ }
247
+
248
+ .top {
249
+ position: sticky;
250
+ top: 0;
251
+ z-index: 20;
252
+ display: flex;
253
+ align-items: center;
254
+ gap: 0.75rem;
255
+ height: var(--top);
256
+ padding: 0 1rem;
257
+ background: var(--bg);
258
+ border-bottom: 1px solid var(--line);
259
+ }
260
+
261
+ .brand {
262
+ font-weight: 650;
263
+ color: var(--ink);
264
+ text-decoration: none;
265
+ }
266
+
267
+ .brand small {
268
+ margin-left: 0.5rem;
269
+ font-weight: 400;
270
+ color: var(--ink-soft);
271
+ }
272
+
273
+ .top .grow {
274
+ flex: 1;
275
+ }
276
+
277
+ .icon-button,
278
+ .search-open {
279
+ display: inline-flex;
280
+ align-items: center;
281
+ gap: 0.5rem;
282
+ min-height: 2.25rem;
283
+ padding: 0 0.75rem;
284
+ border: 1px solid var(--line);
285
+ border-radius: 0.5rem;
286
+ background: var(--bg);
287
+ cursor: pointer;
288
+ }
289
+
290
+ .icon-button:hover,
291
+ .search-open:hover {
292
+ background: var(--bg-soft);
293
+ }
294
+
295
+ .search-open {
296
+ min-width: 15rem;
297
+ color: var(--ink-soft);
298
+ justify-content: space-between;
299
+ }
300
+
301
+ .search-open kbd {
302
+ font: 0.75rem ui-monospace, monospace;
303
+ padding: 0.05rem 0.4rem;
304
+ border: 1px solid var(--line);
305
+ border-radius: 0.3rem;
306
+ }
307
+
308
+ .shell {
309
+ display: grid;
310
+ grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--toc);
311
+ min-height: calc(100vh - var(--top));
312
+ }
313
+
314
+ body[data-nav="closed"] .shell {
315
+ grid-template-columns: 0 minmax(0, 1fr) var(--toc);
316
+ }
317
+
318
+ body[data-nav="closed"] .side {
319
+ visibility: hidden;
320
+ padding: 0;
321
+ border: 0;
322
+ }
323
+
324
+ .side,
325
+ .toc {
326
+ position: sticky;
327
+ top: var(--top);
328
+ align-self: start;
329
+ max-height: calc(100vh - var(--top));
330
+ overflow-y: auto;
331
+ font-size: 0.9rem;
332
+ }
333
+
334
+ .side {
335
+ padding: 1.25rem 0.75rem 3rem 1rem;
336
+ border-right: 1px solid var(--line);
337
+ }
338
+
339
+ .side ul,
340
+ .toc ul {
341
+ margin: 0;
342
+ padding: 0;
343
+ list-style: none;
344
+ }
345
+
346
+ .side a {
347
+ display: block;
348
+ padding: 0.28rem 0.6rem;
349
+ border-radius: 0.4rem;
350
+ color: var(--ink-soft);
351
+ text-decoration: none;
352
+ }
353
+
354
+ .side a:hover {
355
+ background: var(--bg-soft);
356
+ color: var(--ink);
357
+ }
358
+
359
+ .side a[aria-current="page"] {
360
+ background: var(--accent-soft);
361
+ color: var(--accent);
362
+ font-weight: 600;
363
+ }
364
+
365
+ .side details > summary {
366
+ display: flex;
367
+ align-items: center;
368
+ justify-content: space-between;
369
+ cursor: pointer;
370
+ list-style: none;
371
+ }
372
+
373
+ .side details > summary > a {
374
+ flex: 1;
375
+ }
376
+
377
+ .side details > summary::-webkit-details-marker {
378
+ display: none;
379
+ }
380
+
381
+ .side .group > summary {
382
+ margin-top: 0.9rem;
383
+ padding: 0.25rem 0.6rem;
384
+ color: var(--ink-soft);
385
+ font-size: 0.72rem;
386
+ font-weight: 650;
387
+ letter-spacing: 0.06em;
388
+ text-transform: uppercase;
389
+ }
390
+
391
+ .side summary::after {
392
+ content: "";
393
+ flex: none;
394
+ width: 0.4rem;
395
+ height: 0.4rem;
396
+ margin: 0 0.6rem;
397
+ border-right: 1.5px solid currentColor;
398
+ border-bottom: 1.5px solid currentColor;
399
+ transform: rotate(-45deg);
400
+ transition: transform 0.12s;
401
+ }
402
+ `;
403
+ // src/features/build-site/model/assets-styles-2.ts
404
+ const COMPONENT_STYLES = String.raw`.side details[open] > summary::after {
405
+ transform: rotate(45deg);
406
+ }
407
+
408
+ .side .children {
409
+ margin-left: 0.9rem;
410
+ border-left: 1px solid var(--line);
411
+ }
412
+
413
+ .side .book-switch > summary {
414
+ display: flex;
415
+ align-items: center;
416
+ gap: 0.4rem;
417
+ padding: 0.5rem 0.7rem;
418
+ border: 1px solid var(--line);
419
+ border-radius: 0.5rem;
420
+ font-weight: 600;
421
+ }
422
+
423
+ .side .book-switch ul {
424
+ margin: 0.25rem 0 0.5rem;
425
+ }
426
+
427
+ .side .book-switch summary strong {
428
+ margin-right: auto;
429
+ overflow-wrap: anywhere;
430
+ }
431
+
432
+ main {
433
+ min-width: 0;
434
+ padding: 2rem 2.5rem 5rem;
435
+ }
436
+
437
+ article {
438
+ max-width: var(--measure);
439
+ margin: 0 auto;
440
+ }
441
+
442
+ .crumbs {
443
+ margin: 0 0 0.5rem;
444
+ font-size: 0.85rem;
445
+ color: var(--ink-soft);
446
+ }
447
+
448
+ .crumbs a {
449
+ color: inherit;
450
+ }
451
+
452
+ h1 {
453
+ margin: 0 0 0.4rem;
454
+ font-size: 2.25rem;
455
+ line-height: 1.2;
456
+ letter-spacing: -0.01em;
457
+ }
458
+
459
+ .lead {
460
+ margin: 0 0 1rem;
461
+ font-size: 1rem;
462
+ line-height: 1.65;
463
+ color: var(--ink-soft);
464
+ }
465
+
466
+ .chips {
467
+ display: flex;
468
+ flex-wrap: wrap;
469
+ gap: 0.5rem;
470
+ margin: 0 0 1.25rem;
471
+ }
472
+
473
+ .chips span,
474
+ .chips a {
475
+ display: inline-block;
476
+ padding: 0.05rem 0.65rem;
477
+ border: 1px solid var(--line);
478
+ border-radius: 999px;
479
+ font-size: 0.8rem;
480
+ color: var(--ink-soft);
481
+ text-decoration: none;
482
+ }
483
+
484
+ .chips a:hover {
485
+ background: var(--bg-soft);
486
+ }
487
+
488
+ .need {
489
+ margin: 0 0 1.75rem;
490
+ padding: 0.75rem 1rem;
491
+ border-left: 3px solid var(--accent);
492
+ background: var(--bg-soft);
493
+ border-radius: 0 0.4rem 0.4rem 0;
494
+ font-size: 0.92rem;
495
+ }
496
+
497
+ .need strong {
498
+ display: block;
499
+ margin-bottom: 0.15rem;
500
+ }
501
+
502
+ .need span + span::before {
503
+ content: "·";
504
+ margin: 0 0.5rem;
505
+ color: var(--ink-soft);
506
+ }
507
+
508
+ .prose h2 {
509
+ margin: 2.5rem 0 0.75rem;
510
+ padding-top: 1.5rem;
511
+ border-top: 1px solid var(--line);
512
+ font-size: 1.5rem;
513
+ line-height: 1.3;
514
+ }
515
+
516
+ .prose h3 {
517
+ margin: 1.75rem 0 0.5rem;
518
+ font-size: 1.15rem;
519
+ }
520
+
521
+ .prose h3[data-severity] {
522
+ padding-left: 0.75rem;
523
+ border-left: 3px solid var(--line);
524
+ }
525
+
526
+ .prose h3[data-severity="critical"] {
527
+ border-color: var(--critical);
528
+ }
529
+
530
+ .prose h3[data-severity="high"] {
531
+ border-color: var(--high);
532
+ }
533
+
534
+ .prose :is(h2, h3, h4) > a {
535
+ color: inherit;
536
+ text-decoration: none;
537
+ }
538
+
539
+ .prose p,
540
+ .prose ul,
541
+ .prose ol {
542
+ margin: 0.85rem 0;
543
+ }
544
+
545
+ .prose code {
546
+ padding: 0.1rem 0.3rem;
547
+ border-radius: 0.3rem;
548
+ background: var(--code-bg);
549
+ font: 0.88em ui-monospace, "SF Mono", Menlo, Consolas, monospace;
550
+ }
551
+
552
+ .prose pre {
553
+ margin: 1.1rem 0;
554
+ padding: 0.9rem 1.1rem;
555
+ overflow-x: auto;
556
+ border: 1px solid var(--line);
557
+ border-radius: 0.5rem;
558
+ background: var(--code-bg);
559
+ font-size: 0.86rem;
560
+ line-height: 1.6;
561
+ }
562
+
563
+ .prose pre code {
564
+ padding: 0;
565
+ background: none;
566
+ font-size: inherit;
567
+ }
568
+
569
+ .shiki,
570
+ .shiki span {
571
+ color: var(--shiki-light);
572
+ }
573
+
574
+ :root[data-theme="dark"] .shiki,
575
+ :root[data-theme="dark"] .shiki span {
576
+ color: var(--shiki-dark);
577
+ }
578
+
579
+ @media (prefers-color-scheme: dark) {
580
+ :root:not([data-theme="light"]) .shiki,
581
+ :root:not([data-theme="light"]) .shiki span {
582
+ color: var(--shiki-dark);
583
+ }
584
+ }
585
+
586
+ .shiki {
587
+ background: transparent !important;
588
+ }
589
+
590
+ .prose table {
591
+ width: 100%;
592
+ margin: 1.1rem 0;
593
+ border-collapse: collapse;
594
+ font-size: 0.92rem;
595
+ }
596
+
597
+ .prose th,
598
+ .prose td {
599
+ padding: 0.45rem 0.7rem;
600
+ border: 1px solid var(--line);
601
+ text-align: left;
602
+ }
603
+
604
+ .prose th {
605
+ background: var(--bg-soft);
606
+ }
607
+
608
+ .prose blockquote {
609
+ margin: 1rem 0;
610
+ padding: 0.1rem 1rem;
611
+ border-left: 3px solid var(--line);
612
+ color: var(--ink-soft);
613
+ }
614
+
615
+ .sources {
616
+ margin-top: 3rem;
617
+ padding-top: 1.25rem;
618
+ border-top: 1px solid var(--line);
619
+ font-size: 0.9rem;
620
+ }
621
+
622
+ .sources h2 {
623
+ margin: 0 0 0.5rem;
624
+ font-size: 0.8rem;
625
+ letter-spacing: 0.06em;
626
+ text-transform: uppercase;
627
+ color: var(--ink-soft);
628
+ }
629
+
630
+ .sources ul {
631
+ margin: 0;
632
+ padding-left: 1.1rem;
633
+ }
634
+
635
+ .sources code {
636
+ font: 0.85em ui-monospace, monospace;
637
+ }
638
+ `;
639
+ // src/features/build-site/model/assets-styles-3.ts
640
+ const PAGE_STYLES = String.raw`.pager {
641
+ display: grid;
642
+ grid-template-columns: 1fr 1fr;
643
+ gap: 1rem;
644
+ margin-top: 3rem;
645
+ }
646
+
647
+ .pager a {
648
+ display: block;
649
+ padding: 0.7rem 1rem;
650
+ border: 1px solid var(--line);
651
+ border-radius: 0.5rem;
652
+ text-decoration: none;
653
+ color: var(--ink);
654
+ }
655
+
656
+ .pager a:hover {
657
+ border-color: var(--accent);
658
+ }
659
+
660
+ .pager small {
661
+ display: block;
662
+ color: var(--ink-soft);
663
+ }
664
+
665
+ .pager .next {
666
+ grid-column: 2;
667
+ text-align: right;
668
+ }
669
+
670
+ .rows {
671
+ margin: 0.5rem 0 1.5rem;
672
+ padding: 0;
673
+ list-style: none;
674
+ }
675
+
676
+ .rows a {
677
+ display: grid;
678
+ grid-template-columns: 15rem minmax(0, 1fr);
679
+ gap: 1rem;
680
+ padding: 0.7rem 0;
681
+ border-bottom: 1px solid var(--line);
682
+ color: var(--ink);
683
+ text-decoration: none;
684
+ }
685
+
686
+ .rows a:hover .name {
687
+ text-decoration: underline;
688
+ }
689
+
690
+ .rows .name {
691
+ font-weight: 600;
692
+ overflow-wrap: anywhere;
693
+ }
694
+
695
+ .rows .desc {
696
+ display: -webkit-box;
697
+ overflow: hidden;
698
+ color: var(--ink-soft);
699
+ font-size: 0.92rem;
700
+ -webkit-box-orient: vertical;
701
+ -webkit-line-clamp: 2;
702
+ }
703
+
704
+ .overview h2 {
705
+ margin: 2rem 0 0;
706
+ font-size: 0.8rem;
707
+ letter-spacing: 0.06em;
708
+ text-transform: uppercase;
709
+ color: var(--ink-soft);
710
+ }
711
+
712
+ .toc {
713
+ padding: 2rem 1rem 3rem 0.5rem;
714
+ }
715
+
716
+ .toc h2 {
717
+ margin: 0 0 0.6rem;
718
+ font-size: 0.72rem;
719
+ letter-spacing: 0.06em;
720
+ text-transform: uppercase;
721
+ color: var(--ink-soft);
722
+ }
723
+
724
+ .toc ul {
725
+ border-left: 1px solid var(--line);
726
+ }
727
+
728
+ .toc a {
729
+ display: block;
730
+ padding: 0.18rem 0 0.18rem 0.8rem;
731
+ margin-left: -1px;
732
+ border-left: 2px solid transparent;
733
+ color: var(--ink-soft);
734
+ text-decoration: none;
735
+ }
736
+
737
+ .toc .depth-3 a {
738
+ padding-left: 1.6rem;
739
+ }
740
+
741
+ .toc a:hover {
742
+ color: var(--ink);
743
+ }
744
+
745
+ .toc a[aria-current="true"] {
746
+ border-left-color: var(--accent);
747
+ color: var(--ink);
748
+ font-weight: 600;
749
+ }
750
+
751
+ dialog.search {
752
+ width: min(36rem, calc(100vw - 2rem));
753
+ margin-top: 10vh;
754
+ padding: 0;
755
+ border: 1px solid var(--line);
756
+ border-radius: 0.75rem;
757
+ background: var(--bg);
758
+ color: var(--ink);
759
+ }
760
+
761
+ dialog.search::backdrop {
762
+ background: rgb(0 0 0 / 0.35);
763
+ }
764
+
765
+ .search input {
766
+ width: 100%;
767
+ padding: 0.9rem 1.1rem;
768
+ border: 0;
769
+ border-bottom: 1px solid var(--line);
770
+ background: transparent;
771
+ color: inherit;
772
+ font: inherit;
773
+ outline: none;
774
+ }
775
+
776
+ .search ul {
777
+ max-height: 55vh;
778
+ margin: 0;
779
+ padding: 0.4rem;
780
+ overflow-y: auto;
781
+ list-style: none;
782
+ }
783
+
784
+ .search li a {
785
+ display: block;
786
+ padding: 0.55rem 0.7rem;
787
+ border-radius: 0.4rem;
788
+ color: var(--ink);
789
+ text-decoration: none;
790
+ }
791
+
792
+ .search li a:hover,
793
+ .search li a[data-active] {
794
+ background: var(--accent-soft);
795
+ }
796
+
797
+ .search li small {
798
+ display: block;
799
+ color: var(--ink-soft);
800
+ }
801
+
802
+ .search .empty {
803
+ padding: 0.9rem 1.1rem;
804
+ color: var(--ink-soft);
805
+ }
806
+
807
+ @media (max-width: 1180px) {
808
+ .shell,
809
+ body[data-nav="closed"] .shell {
810
+ grid-template-columns: var(--sidebar) minmax(0, 1fr);
811
+ }
812
+
813
+ body[data-nav="closed"] .shell {
814
+ grid-template-columns: 0 minmax(0, 1fr);
815
+ }
816
+
817
+ .toc {
818
+ display: none;
819
+ }
820
+ }
821
+
822
+ @media (max-width: 820px) {
823
+ .shell,
824
+ body[data-nav="closed"] .shell {
825
+ grid-template-columns: minmax(0, 1fr);
826
+ }
827
+
828
+ .side {
829
+ position: fixed;
830
+ inset: var(--top) 0 0 0;
831
+ z-index: 15;
832
+ width: min(20rem, 88vw);
833
+ max-height: none;
834
+ background: var(--bg);
835
+ transform: translateX(-100%);
836
+ transition: transform 0.15s;
837
+ }
838
+
839
+ body[data-nav="open"] .side {
840
+ transform: none;
841
+ }
842
+
843
+ body[data-nav="closed"] .side {
844
+ visibility: visible;
845
+ padding: 1.25rem 0.75rem 3rem 1rem;
846
+ border-right: 1px solid var(--line);
847
+ }
848
+
849
+ main {
850
+ padding: 1.5rem 1rem 4rem;
851
+ }
852
+
853
+ h1 {
854
+ font-size: 1.8rem;
855
+ }
856
+
857
+ .search-open {
858
+ min-width: 0;
859
+ }
860
+
861
+ .search-open span {
862
+ display: none;
863
+ }
864
+
865
+ .rows a {
866
+ grid-template-columns: 1fr;
867
+ gap: 0.1rem;
868
+ }
869
+ }
870
+ `;
871
+ const ASSET_FILES = [{
872
+ path: STYLE_PATH,
873
+ content: pipe([
874
+ BASE_STYLES,
875
+ COMPONENT_STYLES,
876
+ PAGE_STYLES
877
+ ], Array.join("\n"))
878
+ }, {
879
+ path: SCRIPT_PATH,
880
+ content: SCRIPT
881
+ }];
882
+ // src/entities/book/model/book.ts
883
+ const TYPE_ORDER = [
884
+ "lifecycle",
885
+ "core",
886
+ "sub-skill",
887
+ "framework",
888
+ "composition",
889
+ "security"
890
+ ];
891
+ const OTHER = "other";
892
+ const MARKDOWN_SUFFIX$2 = /\.md$/u;
893
+ const REQUIRE_SEPARATOR = "#";
894
+ const NO_DEPTH = 0;
895
+ const ONE_LEVEL = 1;
896
+ const DATA_FIRST_ARITY = 2;
897
+ const requiredName = (requirement) => pipe(requirement, String$1.split(REQUIRE_SEPARATOR), Array.last, Option.getOrElse(Function.constant(requirement)));
898
+ const typeIndex = (type) => pipe(TYPE_ORDER, Array.findFirstIndex((known) => known === type), Option.getOrElse(Function.constant(TYPE_ORDER.length)));
899
+ const byType = Order.combine(Order.mapInput(Order.Number, typeIndex), Order.String);
900
+ const requiredSkills = (byName, seen) => (skill) => pipe(skill.requires, Array.flatMap((requirement) => Option.toArray(Record.get(byName, requiredName(requirement)))), Array.filter((required) => !Array.contains(seen, required.name)));
901
+ const depth = (byName, seen) => (skill) => pipe(skill, requiredSkills(byName, seen), Array.map((required) => depth(byName, Array.append(seen, skill.name))(required) + ONE_LEVEL), Array.prepend(NO_DEPTH), Array.max(Order.Number));
902
+ const orderedByDepth = (skills) => {
903
+ const byName = Record.fromIterableBy(skills, (skill) => skill.name);
904
+ const compareDepth = Order.mapInput(Order.Number, depth(byName, []));
905
+ const compareName = Order.mapInput(Order.String, (skill) => skill.name);
906
+ return Array.sort(skills, Order.combine(compareDepth, compareName));
907
+ };
908
+ const typeOf = (skill) => Option.getOrElse(skill.type, Function.constant(OTHER));
909
+ const groupSkills = (skills) => {
910
+ const grouped = Array.groupBy(skills, typeOf);
911
+ return pipe(Record.toEntries(grouped), Array.map(([type, members]) => ({
912
+ type,
913
+ skills: orderedByDepth(members)
914
+ })), Array.sortBy(Order.mapInput(byType, (group) => group.type)));
915
+ };
916
+ const orderedSkills = (groups) => pipe(groups, Array.flatMap((group) => group.skills));
917
+ const requiredNames = (skill) => pipe(skill.requires, Array.map(requiredName));
918
+ const entrySkills = (skills) => {
919
+ const required = pipe(skills, Array.flatMap(requiredNames));
920
+ return pipe(skills, Array.filter((skill) => Array.isReadonlyArrayEmpty(skill.requires) && Array.contains(required, skill.name)));
921
+ };
922
+ const pageRoute = (page) => {
923
+ switch (page.kind) {
924
+ case "overview": return "";
925
+ case "skill": return `${page.name}/`;
926
+ case "source": return `${page.name}.md`;
927
+ case "reference": return `${page.name}/${String$1.replace(MARKDOWN_SUFFIX$2, "")(page.file)}/`;
928
+ default: return page;
929
+ }
930
+ };
931
+ const routeOf = Function.dual(DATA_FIRST_ARITY, (slug, page) => `/${slug}/${pageRoute(page)}`);
932
+ // src/entities/book/model/skill.ts
933
+ const taggedError$4 = Schema.TaggedError;
934
+ var SkillFormatError = class extends taggedError$4()("SkillFormatError", {
935
+ skill: Schema.String,
936
+ reason: Schema.String
937
+ }) {};
938
+ const Scalar = Schema.Union([Schema.String, Schema.Finite]);
939
+ const OptionalText = Schema.String.pipe(Schema.optionalKey);
940
+ const OptionalScalar = Scalar.pipe(Schema.optionalKey);
941
+ const OptionalList = Schema.Array(Schema.String).pipe(Schema.optionalKey);
942
+ const Metadata = Schema.Struct({
943
+ type: OptionalText,
944
+ framework: OptionalText,
945
+ library_version: OptionalScalar
946
+ });
947
+ const Frontmatter = Schema.Struct({
948
+ description: Schema.String,
949
+ type: OptionalText,
950
+ framework: OptionalText,
951
+ library_version: OptionalScalar,
952
+ metadata: Metadata.pipe(Schema.optionalKey),
953
+ requires: OptionalList,
954
+ sources: OptionalList
955
+ });
956
+ const FRONTMATTER = /^---[ \t]*\r?\n(?<yaml>[\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)(?<body>[\s\S]*)$/u;
957
+ const WHITESPACE = /\s+/gu;
958
+ const NO_ENTRIES = [];
959
+ const decodeFrontmatter = Schema.decodeUnknownEffect(Frontmatter);
960
+ const splitFrontmatter = (text) => String$1.match(FRONTMATTER)(text).pipe(Option.flatMap((found) => Option.fromNullishOr(found.groups)), Option.flatMap((groups) => Option.all({
961
+ yaml: Record.get(groups, "yaml"),
962
+ body: Record.get(groups, "body")
963
+ })));
964
+ const failed = (skill, reason) => SkillFormatError.make({
965
+ skill,
966
+ reason
967
+ });
968
+ const textOfScalar = (value) => value.pipe(Option.map((scalar) => globalThis.String(scalar)));
969
+ const metadataOr = (frontmatter, read) => Option.fromNullishOr(frontmatter.metadata).pipe(Option.flatMapNullishOr(read), Option.orElse(() => Option.fromNullishOr(read(frontmatter))));
970
+ const parseSkill = Effect.fn("parseSkill")(function* parseSkill(input) {
971
+ const parts = yield* splitFrontmatter(input.text).pipe(Effect.fromOption, Effect.mapError(() => failed(input.name, "SKILL.md has no frontmatter")));
972
+ const data = yield* Effect.try({
973
+ try: () => parse(parts.yaml),
974
+ catch: (cause) => failed(input.name, `frontmatter is not YAML: ${globalThis.String(cause)}`)
975
+ });
976
+ const frontmatter = yield* decodeFrontmatter(data).pipe(Effect.mapError((error) => failed(input.name, error.message)));
977
+ return {
978
+ name: input.name,
979
+ description: pipe(frontmatter.description, String$1.replaceAll(WHITESPACE, " "), String$1.trim),
980
+ type: metadataOr(frontmatter, (source) => source.type),
981
+ framework: metadataOr(frontmatter, (source) => source.framework),
982
+ libraryVersion: textOfScalar(metadataOr(frontmatter, (source) => source.library_version)),
983
+ requires: frontmatter.requires ?? NO_ENTRIES,
984
+ sources: frontmatter.sources ?? NO_ENTRIES,
985
+ text: input.text,
986
+ body: parts.body,
987
+ references: input.references
988
+ };
989
+ });
990
+ // src/shared/lib/html.ts
991
+ const optional = (build) => (option) => pipe(option, Option.map(build), Option.toArray);
992
+ const when = (condition) => (build) => Boolean.match(condition, {
993
+ onTrue: build,
994
+ onFalse: () => []
995
+ });
996
+ const charset = () => h("meta", {
997
+ httpEquiv: "content-type",
998
+ content: "text/html; charset=utf-8"
999
+ });
1000
+ const htmlDocument = (input) => {
1001
+ const page = h("html", { lang: "en" }, [h("head", [...input.head]), h("body", [...input.body])]);
1002
+ return toHtml({
1003
+ type: "root",
1004
+ children: [{ type: "doctype" }, page]
1005
+ });
1006
+ };
1007
+ // src/features/build-site/model/links.ts
1008
+ const LEADING_SLASH = /^\//u;
1009
+ const ORIGIN = "https://intent-book.invalid/";
1010
+ const SKILLS_ROOT = "skills/";
1011
+ const GITHUB = "https://github.com/";
1012
+ const SKILL_FILE$1 = "SKILL.md";
1013
+ const withBase = (base) => (route) => `${base}${String$1.replace(LEADING_SLASH, "")(route)}`;
1014
+ const fileOf = (route) => String$1.replace(LEADING_SLASH, "")(route);
1015
+ const sourcePath = (skill) => `${skill.name}/${SKILL_FILE$1}`;
1016
+ const referencePath = (input) => `${input.skill.name}/${input.file}`;
1017
+ const targetsOf = (slug, base) => (skill) => {
1018
+ const own = [sourcePath(skill), withBase(base)(routeOf(slug, {
1019
+ kind: "skill",
1020
+ name: skill.name
1021
+ }))];
1022
+ const referenced = pipe(skill.references, Array.map((reference) => [referencePath({
1023
+ skill,
1024
+ file: reference.file
1025
+ }), withBase(base)(routeOf(slug, {
1026
+ kind: "reference",
1027
+ name: skill.name,
1028
+ file: reference.file
1029
+ }))]));
1030
+ return Array.prepend(referenced, own);
1031
+ };
1032
+ const pageTarget = (targets, url) => pipe(fileOf(url.pathname), Option.liftPredicate(String$1.startsWith(SKILLS_ROOT)), Option.map(String$1.slice(7)), Option.flatMap((file) => Record.get(targets, file)), Option.map((target) => `${target}${url.hash}`));
1033
+ const repositoryFile = (book, url) => pipe(book.repository, Option.filter(String$1.startsWith(GITHUB)), Option.map((repository) => {
1034
+ return `${repository}/blob/HEAD${pipe(book.directory, Option.map((value) => `/${value}`), Option.getOrElse(Function.constant("")))}${url.pathname}${url.hash}`;
1035
+ }));
1036
+ const resolveAgainst = (input) => (document) => (href) => pipe(Option.liftThrowable(() => new URL(href, `${ORIGIN}${SKILLS_ROOT}${document}`))(), Option.flatMap((url) => pipe(pageTarget(input.targets, url), Option.orElse(() => repositoryFile(input.book, url)))));
1037
+ const linkResolver = (input) => {
1038
+ const targets = pipe(input.book.skills, Array.flatMap(targetsOf(input.slug, input.base)), Record.fromEntries);
1039
+ return resolveAgainst({
1040
+ book: input.book,
1041
+ targets
1042
+ });
1043
+ };
1044
+ // src/features/build-site/model/pages.ts
1045
+ const SOURCE = /^(?<repository>[^/:\s]+\/[^:\s]+):(?<file>.+)$/u;
1046
+ const FIRST_SENTENCE = /^.*?[.。](?=\s|$)/u;
1047
+ const BEHIND = 1;
1048
+ const AHEAD = 1;
1049
+ const CRUMB_SEPARATOR = " › ";
1050
+ const GLOB = "*";
1051
+ const contentOf = (tree) => pipe(tree.children, Array.filter((node) => node.type !== "doctype"));
1052
+ const firstSentence = (description) => pipe(description, String$1.match(FIRST_SENTENCE), Option.flatMap(Array.head), Option.getOrElse(Function.constant(description)));
1053
+ const prose = (tree) => h("div", { class: "prose" }, [...contentOf(tree)]);
1054
+ const crumbs = (trail) => {
1055
+ const parts = pipe(trail, Array.intersperse(CRUMB_SEPARATOR));
1056
+ return h("p", { class: "crumbs" }, [...parts]);
1057
+ };
1058
+ const skillRoute = (base, book, skill) => withBase(base)(routeOf(book.name, {
1059
+ kind: "skill",
1060
+ name: skill.name
1061
+ }));
1062
+ const rawRoute = (base, book, skill) => withBase(base)(routeOf(book.name, {
1063
+ kind: "source",
1064
+ name: skill.name
1065
+ }));
1066
+ const sourceLocation = (source) => pipe(source, String$1.match(SOURCE), Option.flatMapNullishOr((found) => found.groups), Option.flatMap((groups) => Option.all({
1067
+ repository: Record.get(groups, "repository"),
1068
+ file: Record.get(groups, "file")
1069
+ })), Option.filter(({ file }) => !String$1.includes(GLOB)(file)), Option.map(({ repository, file }) => `https://github.com/${repository}/blob/HEAD/${file}`));
1070
+ const sourceItem = (source) => pipe(sourceLocation(source), Option.match({
1071
+ onNone: () => h("li", [h("code", source)]),
1072
+ onSome: (href) => h("li", [h("a", { href }, [h("code", source)])])
1073
+ }));
1074
+ const neighbourLink = (page, style) => (skill) => h("a", {
1075
+ class: style.className,
1076
+ href: skillRoute(page.base, page.book, skill)
1077
+ }, [h("small", style.label), skill.name]);
1078
+ const pager = (base, book, skill) => {
1079
+ const order = orderedSkills(groupSkills(book.skills));
1080
+ const index = pipe(order, Array.findFirstIndex((candidate) => candidate.name === skill.name));
1081
+ const previous = pipe(index, Option.flatMap((position) => Array.get(order, position - BEHIND)), optional(neighbourLink({
1082
+ base,
1083
+ book
1084
+ }, {
1085
+ className: "prev",
1086
+ label: "Previous"
1087
+ })));
1088
+ const next = pipe(index, Option.flatMap((position) => Array.get(order, position + AHEAD)), optional(neighbourLink({
1089
+ base,
1090
+ book
1091
+ }, {
1092
+ className: "next",
1093
+ label: "Next"
1094
+ })));
1095
+ return h("nav", {
1096
+ class: "pager",
1097
+ ariaLabel: "Previous and next skill"
1098
+ }, [...previous, ...next]);
1099
+ };
1100
+ const requiredLink = (base, book, requirement) => pipe(book.skills, Array.findFirst((candidate) => candidate.name === requiredName(requirement)), Option.match({
1101
+ onNone: () => h("code", requirement),
1102
+ onSome: (target) => h("a", { href: skillRoute(base, book, target) }, target.name)
1103
+ }));
1104
+ const overviewRoute$1 = (base, book) => withBase(base)(routeOf(book.name, { kind: "overview" }));
1105
+ const bookLink = (base, book) => h("a", { href: overviewRoute$1(base, book) }, book.name);
1106
+ const skillChips = (base, book, skill) => {
1107
+ const type = pipe(skill.type, optional((value) => h("span", value)));
1108
+ const version = pipe(skill.libraryVersion, optional((value) => h("span", `v${value}`)));
1109
+ const raw = h("a", { href: rawRoute(base, book, skill) }, "SKILL.md");
1110
+ return h("div", { class: "chips" }, [
1111
+ ...type,
1112
+ ...version,
1113
+ raw
1114
+ ]);
1115
+ };
1116
+ const requirementItem = (base, book) => (requirement) => h("span", [requiredLink(base, book, requirement)]);
1117
+ const readFirst = (base, book, skill) => when(!Array.isReadonlyArrayEmpty(skill.requires))(() => {
1118
+ const links = pipe(skill.requires, Array.map(requirementItem(base, book)));
1119
+ return [h("div", { class: "need" }, [h("strong", "Read first"), ...links])];
1120
+ });
1121
+ const sourceSection = (skill) => when(!Array.isReadonlyArrayEmpty(skill.sources))(() => {
1122
+ const items = pipe(skill.sources, Array.map(sourceItem));
1123
+ return [h("section", { class: "sources" }, [h("h2", "Sources"), h("ul", items)])];
1124
+ });
1125
+ const skillMain = (input) => {
1126
+ const { base, book, skill } = input;
1127
+ return [
1128
+ crumbs([
1129
+ bookLink(base, book),
1130
+ typeOf(skill),
1131
+ skill.name
1132
+ ]),
1133
+ h("h1", input.title),
1134
+ h("p", { class: "lead" }, skill.description),
1135
+ skillChips(base, book, skill),
1136
+ ...readFirst(base, book, skill),
1137
+ prose(input.tree),
1138
+ ...sourceSection(skill),
1139
+ pager(base, book, skill)
1140
+ ];
1141
+ };
1142
+ const referenceMain = (input) => {
1143
+ const { base, book, skill } = input;
1144
+ const parent = h("a", { href: skillRoute(base, book, skill) }, skill.name);
1145
+ return [
1146
+ crumbs([bookLink(base, book), parent]),
1147
+ h("h1", input.title),
1148
+ prose(input.tree)
1149
+ ];
1150
+ };
1151
+ const rowLink = (href, name, description) => h("li", [h("a", { href }, [h("span", { class: "name" }, name), h("span", { class: "desc" }, description)])]);
1152
+ const row = (base, book) => (skill) => rowLink(skillRoute(base, book, skill), skill.name, firstSentence(skill.description));
1153
+ const section = (page, title, skills) => when(!Array.isReadonlyArrayEmpty(skills))(() => {
1154
+ const rows = pipe(skills, Array.map(row(page.base, page.book)));
1155
+ return [h("h2", title), h("ul", { class: "rows" }, rows)];
1156
+ });
1157
+ const overviewChips = (book) => {
1158
+ const npm = h("a", { href: `https://www.npmjs.com/package/${book.name}` }, "npm");
1159
+ const repository = pipe(book.repository, optional((href) => h("a", { href }, "repository")));
1160
+ return h("div", { class: "chips" }, [
1161
+ h("span", `v${book.version}`),
1162
+ h("span", `${book.skills.length} skills`),
1163
+ npm,
1164
+ ...repository
1165
+ ]);
1166
+ };
1167
+ const overviewSections = (page) => {
1168
+ const entries = entrySkills(page.book.skills);
1169
+ const entryNames = pipe(entries, Array.map((skill) => skill.name));
1170
+ const groups = pipe(groupSkills(page.book.skills), Array.flatMap((group) => {
1171
+ const rest = pipe(group.skills, Array.filter((skill) => !Array.contains(entryNames, skill.name)));
1172
+ return section(page, group.type, rest);
1173
+ }));
1174
+ return [...section(page, "Start here", entries), ...groups];
1175
+ };
1176
+ const overviewMain = (input) => {
1177
+ const { book } = input;
1178
+ const lead = when(book.description !== "")(() => [h("p", { class: "lead" }, book.description)]);
1179
+ const sections = h("div", { class: "overview" }, [...overviewSections(input)]);
1180
+ return [
1181
+ crumbs([book.name]),
1182
+ h("h1", book.name),
1183
+ ...lead,
1184
+ overviewChips(book),
1185
+ sections
1186
+ ];
1187
+ };
1188
+ const landingRow = (base) => (book) => rowLink(overviewRoute$1(base, book), book.name, book.description);
1189
+ const SINGLE_BOOK$1 = 1;
1190
+ const redirectTarget = (input) => pipe(input.books, Option.liftPredicate((books) => books.length === SINGLE_BOOK$1), Option.flatMap(Array.head), Option.map((only) => overviewRoute$1(input.base, only)));
1191
+ const landingPage = (input) => {
1192
+ const refresh = pipe(redirectTarget(input), optional((target) => h("meta", {
1193
+ httpEquiv: "refresh",
1194
+ content: `0;url=${target}`
1195
+ })));
1196
+ const rows = pipe(input.books, Array.map(landingRow(input.base)));
1197
+ const head = [
1198
+ charset(),
1199
+ h("meta", {
1200
+ name: "viewport",
1201
+ content: "width=device-width, initial-scale=1"
1202
+ }),
1203
+ ...refresh,
1204
+ h("title", "Skills"),
1205
+ h("link", {
1206
+ rel: "stylesheet",
1207
+ href: `${input.base}${STYLE_PATH}`
1208
+ })
1209
+ ];
1210
+ const body = h("main", [h("article", [h("h1", "Skills"), h("ul", { class: "rows" }, rows)])]);
1211
+ return htmlDocument({
1212
+ head,
1213
+ body: [body]
1214
+ });
1215
+ };
1216
+ // src/shared/lib/render-markdown.ts
1217
+ const SECOND_DEPTH = 2;
1218
+ const THIRD_DEPTH = 3;
1219
+ const ONE_NODE = 1;
1220
+ const taggedError$3 = Schema.TaggedError;
1221
+ var MarkdownRenderError = class extends taggedError$3()("MarkdownRenderError", { reason: Schema.String }) {};
1222
+ const SEVERITY = /^(?<word>CRITICAL|HIGH|MEDIUM|LOW)\b/u;
1223
+ const SCHEME = /^(?:[a-z][a-z\d+.-]*:|\/\/|#)/iu;
1224
+ const SECOND_LEVEL = "h2";
1225
+ const THIRD_LEVEL = "h3";
1226
+ const TITLE_LEVEL = "h1";
1227
+ const ANCHOR = "a";
1228
+ const processor = unified().use(remarkParse).use(remarkGfm).use(remarkRehype).use(rehypeSlug).use(rehypeShiki, {
1229
+ themes: {
1230
+ light: "github-light",
1231
+ dark: "github-dark"
1232
+ },
1233
+ defaultColor: false,
1234
+ fallbackLanguage: "text",
1235
+ lazy: true,
1236
+ langs: []
1237
+ });
1238
+ const elementsOf = (tree, tagName) => {
1239
+ const found = [];
1240
+ visit(tree, "element", (node) => {
1241
+ if (node.tagName === tagName) found.push(node);
1242
+ });
1243
+ return found;
1244
+ };
1245
+ const severityOf = (node) => pipe(toString(node), String$1.match(SEVERITY), Option.flatMapNullishOr((found) => found.groups), Option.flatMap((groups) => Record.get(groups, "word")), Option.map(String$1.toLowerCase));
1246
+ const stringProperty = (node, key) => pipe(Option.fromNullishOr(node.properties[key]), Option.filter(Predicate.isString));
1247
+ const markSeverity = (tree) => {
1248
+ for (const node of elementsOf(tree, THIRD_LEVEL)) for (const severity of Option.toArray(severityOf(node))) node.properties = {
1249
+ ...node.properties,
1250
+ dataSeverity: severity
1251
+ };
1252
+ };
1253
+ const resolvedHref = (node, resolveLink) => pipe(stringProperty(node, "href"), Option.filter((href) => !SCHEME.test(href)), Option.flatMap(resolveLink));
1254
+ const rewriteLinks = (tree, resolveLink) => {
1255
+ for (const node of elementsOf(tree, ANCHOR)) for (const target of Option.toArray(resolvedHref(node, resolveLink))) node.properties = {
1256
+ ...node.properties,
1257
+ href: target
1258
+ };
1259
+ };
1260
+ const isTitle = (node) => node.type === "element" && node.tagName === TITLE_LEVEL;
1261
+ const takeTitle = (tree) => pipe(tree.children, Array.findFirstIndex(isTitle), Option.map((position) => {
1262
+ const [removed] = tree.children.splice(position, ONE_NODE);
1263
+ return toString(removed);
1264
+ }));
1265
+ const headingOf = (node, depth) => pipe(stringProperty(node, "id"), Option.map((id) => ({
1266
+ depth,
1267
+ id,
1268
+ text: toString(node)
1269
+ })));
1270
+ const headingsOf = (tree) => {
1271
+ const found = [];
1272
+ visit(tree, "element", (node) => {
1273
+ if (node.tagName === SECOND_LEVEL) found.push(...Option.toArray(headingOf(node, SECOND_DEPTH)));
1274
+ if (node.tagName === THIRD_LEVEL) found.push(...Option.toArray(headingOf(node, THIRD_DEPTH)));
1275
+ });
1276
+ return found;
1277
+ };
1278
+ const renderMarkdown = Effect.fn("renderMarkdown")(function* renderMarkdown(input) {
1279
+ const tree = yield* Effect.tryPromise({
1280
+ try: () => processor.run(processor.parse(input.body), input.body),
1281
+ catch: (cause) => MarkdownRenderError.make({ reason: globalThis.String(cause) })
1282
+ });
1283
+ const title = takeTitle(tree);
1284
+ markSeverity(tree);
1285
+ rewriteLinks(tree, input.resolveLink);
1286
+ return {
1287
+ tree,
1288
+ title,
1289
+ headings: headingsOf(tree)
1290
+ };
1291
+ });
1292
+ // src/features/build-site/model/documents.ts
1293
+ const MARKDOWN_SUFFIX$1 = /\.md$/u;
1294
+ const skillDocument = (context, skill) => ({
1295
+ skill,
1296
+ body: skill.body,
1297
+ from: sourcePath(skill),
1298
+ fallbackTitle: skill.name,
1299
+ current: {
1300
+ kind: "skill",
1301
+ skill
1302
+ },
1303
+ route: routeOf(context.slug, {
1304
+ kind: "skill",
1305
+ name: skill.name
1306
+ }),
1307
+ main: skillMain,
1308
+ raw: {
1309
+ path: fileOf(routeOf(context.slug, {
1310
+ kind: "source",
1311
+ name: skill.name
1312
+ })),
1313
+ content: skill.text
1314
+ },
1315
+ searchName: skill.name,
1316
+ lead: skill.description
1317
+ });
1318
+ const referenceDocument = (context, skill) => (reference) => {
1319
+ const path = referencePath({
1320
+ skill,
1321
+ file: reference.file
1322
+ });
1323
+ return {
1324
+ skill,
1325
+ body: reference.text,
1326
+ from: path,
1327
+ fallbackTitle: String$1.replace(MARKDOWN_SUFFIX$1, "")(reference.file),
1328
+ current: {
1329
+ kind: "reference",
1330
+ skill,
1331
+ file: reference.file
1332
+ },
1333
+ route: routeOf(context.slug, {
1334
+ kind: "reference",
1335
+ name: skill.name,
1336
+ file: reference.file
1337
+ }),
1338
+ main: referenceMain,
1339
+ raw: {
1340
+ path: `${context.slug}/${path}`,
1341
+ content: reference.text
1342
+ },
1343
+ searchName: path,
1344
+ lead: ""
1345
+ };
1346
+ };
1347
+ const documentsOf = (context) => (skill) => {
1348
+ const references = pipe(skill.references, Array.map(referenceDocument(context, skill)));
1349
+ return Array.prepend(references, skillDocument(context, skill));
1350
+ };
1351
+ // src/features/build-site/model/search-index.ts
1352
+ const SearchEntry = Schema.Struct({
1353
+ title: Schema.String,
1354
+ name: Schema.String,
1355
+ book: Schema.String,
1356
+ url: Schema.String,
1357
+ text: Schema.String
1358
+ });
1359
+ const SEARCH_TEXT_START = 0;
1360
+ const SEARCH_TEXT_LIMIT = 6e3;
1361
+ const encodeEntries = Schema.encodeEffect(Schema.fromJsonString(Schema.Array(SearchEntry)));
1362
+ const searchText = (input) => String$1.slice(SEARCH_TEXT_START, SEARCH_TEXT_LIMIT)(`${input.lead} ${input.body}`);
1363
+ const searchIndexFile = (entries) => Effect.map(encodeEntries(entries), (content) => ({
1364
+ path: INDEX_PATH,
1365
+ content
1366
+ }));
1367
+ // src/features/build-site/model/shell.ts
1368
+ const ICON_BARS = [
1369
+ "M3 6h18",
1370
+ "M3 12h18",
1371
+ "M3 18h18"
1372
+ ];
1373
+ const ICON_CONTRAST = ["M12 3a9 9 0 1 0 0 18a9 9 0 0 0 0-18z", "M12 3v18"];
1374
+ const ICON_SIZE = "18";
1375
+ const SINGLE_BOOK = 1;
1376
+ const REFERENCES_PREFIX = /^references\//u;
1377
+ const MARKDOWN_SUFFIX = /\.md$/u;
1378
+ const stroke = (data) => h("path", Record.singleton("d", data));
1379
+ const icon = (strokes) => {
1380
+ const paths = pipe(strokes, Array.map(stroke));
1381
+ return h("svg", {
1382
+ viewBox: "0 0 24 24",
1383
+ width: ICON_SIZE,
1384
+ height: ICON_SIZE,
1385
+ fill: "none",
1386
+ stroke: "currentColor",
1387
+ strokeWidth: "2",
1388
+ ariaHidden: "true"
1389
+ }, paths);
1390
+ };
1391
+ const currentMark = (active) => Boolean.match(active, {
1392
+ onTrue: () => ({ ariaCurrent: "page" }),
1393
+ onFalse: () => ({})
1394
+ });
1395
+ const overviewRoute = (shell, book) => withBase(shell.base)(routeOf(book.name, { kind: "overview" }));
1396
+ const isCurrentSkill = (current, skill) => current.kind !== "overview" && current.skill.name === skill.name;
1397
+ const isActiveSkill = (current, skill) => current.kind === "skill" && current.skill.name === skill.name;
1398
+ const isActiveReference = (current, skill, file) => current.kind === "reference" && current.skill.name === skill.name && current.file === file;
1399
+ const skillLink = (shell, skill) => {
1400
+ const route = routeOf(shell.book.name, {
1401
+ kind: "skill",
1402
+ name: skill.name
1403
+ });
1404
+ const mark = currentMark(isActiveSkill(shell.current, skill));
1405
+ return h("a", {
1406
+ href: withBase(shell.base)(route),
1407
+ ...mark
1408
+ }, skill.name);
1409
+ };
1410
+ const referenceLabel = (file) => pipe(file, String$1.replace(REFERENCES_PREFIX, ""), String$1.replace(MARKDOWN_SUFFIX, ""));
1411
+ const referenceLink = (shell, skill, file) => {
1412
+ const route = routeOf(shell.book.name, {
1413
+ kind: "reference",
1414
+ name: skill.name,
1415
+ file
1416
+ });
1417
+ const mark = currentMark(isActiveReference(shell.current, skill, file));
1418
+ return h("a", {
1419
+ href: withBase(shell.base)(route),
1420
+ ...mark
1421
+ }, referenceLabel(file));
1422
+ };
1423
+ const referenceList = (shell, skill) => {
1424
+ const items = pipe(skill.references, Array.map((reference) => h("li", [referenceLink(shell, skill, reference.file)])));
1425
+ return h("ul", { class: "children" }, items);
1426
+ };
1427
+ const skillWithReferences = (shell, skill) => {
1428
+ const summary = h("summary", [skillLink(shell, skill)]);
1429
+ const open = isCurrentSkill(shell.current, skill);
1430
+ return h("li", [h("details", { open }, [summary, referenceList(shell, skill)])]);
1431
+ };
1432
+ const skillItem = (shell, skill) => Boolean.match(Array.isReadonlyArrayEmpty(skill.references), {
1433
+ onTrue: () => h("li", [skillLink(shell, skill)]),
1434
+ onFalse: () => skillWithReferences(shell, skill)
1435
+ });
1436
+ const bookEntry = (shell, book) => h("li", [h("a", { href: overviewRoute(shell, book) }, book.name)]);
1437
+ const bookSwitch = (shell) => {
1438
+ const entries = pipe(shell.books, Array.map((book) => bookEntry(shell, book)));
1439
+ const summary = h("summary", [h("strong", shell.book.name)]);
1440
+ return when(shell.books.length !== SINGLE_BOOK)(() => [h("details", { class: "book-switch" }, [summary, h("ul", entries)])]);
1441
+ };
1442
+ const overviewItem = (shell) => {
1443
+ const mark = currentMark(shell.current.kind === "overview");
1444
+ return h("li", [h("a", {
1445
+ href: overviewRoute(shell, shell.book),
1446
+ ...mark
1447
+ }, "Overview")]);
1448
+ };
1449
+ const skillGroup = (shell, group) => {
1450
+ const items = pipe(group.skills, Array.map((skill) => skillItem(shell, skill)));
1451
+ return h("details", {
1452
+ class: "group",
1453
+ open: true
1454
+ }, [h("summary", group.type), h("ul", items)]);
1455
+ };
1456
+ const sidebar = (shell) => {
1457
+ const groups = pipe(groupSkills(shell.book.skills), Array.map((group) => skillGroup(shell, group)));
1458
+ return h("nav", {
1459
+ class: "side",
1460
+ ariaLabel: "Skills"
1461
+ }, [
1462
+ ...bookSwitch(shell),
1463
+ h("ul", [overviewItem(shell)]),
1464
+ ...groups
1465
+ ]);
1466
+ };
1467
+ const tocEntry = (heading) => h("li", { class: `depth-${heading.depth}` }, [h("a", { href: `#${heading.id}` }, heading.text)]);
1468
+ const tocList = (headings) => {
1469
+ const entries = pipe(headings, Array.map(tocEntry));
1470
+ return h("div", [h("h2", "On this page"), h("ul", entries)]);
1471
+ };
1472
+ const tableOfContents = (headings) => h("aside", {
1473
+ class: "toc",
1474
+ ariaLabel: "On this page"
1475
+ }, [Boolean.match(Array.isReadonlyArrayEmpty(headings), {
1476
+ onTrue: () => h("span"),
1477
+ onFalse: () => tocList(headings)
1478
+ })]);
1479
+ const iconButton = (label, marker, glyph) => h("button", {
1480
+ class: "icon-button",
1481
+ type: "button",
1482
+ ariaLabel: label,
1483
+ ...marker
1484
+ }, [glyph]);
1485
+ const topBar = (shell) => {
1486
+ const brand = h("a", {
1487
+ class: "brand",
1488
+ href: overviewRoute(shell, shell.book)
1489
+ }, [shell.book.name, h("small", `v${shell.book.version}`)]);
1490
+ const search = h("button", {
1491
+ class: "search-open",
1492
+ type: "button",
1493
+ dataSearchOpen: ""
1494
+ }, [h("span", "Search"), h("kbd", "Ctrl K")]);
1495
+ return h("header", { class: "top" }, [
1496
+ iconButton("Toggle navigation", { dataNavToggle: "" }, icon(ICON_BARS)),
1497
+ brand,
1498
+ h("span", { class: "grow" }),
1499
+ search,
1500
+ iconButton("Toggle theme", { dataThemeToggle: "" }, icon(ICON_CONTRAST))
1501
+ ]);
1502
+ };
1503
+ const searchDialog = () => {
1504
+ const input = h("input", {
1505
+ type: "search",
1506
+ placeholder: "Search skills",
1507
+ ariaLabel: "Search skills",
1508
+ autocomplete: "off"
1509
+ });
1510
+ return h("dialog", {
1511
+ class: "search",
1512
+ ariaLabel: "Search"
1513
+ }, [input, h("ul")]);
1514
+ };
1515
+ const headOf = (shell) => [
1516
+ charset(),
1517
+ h("meta", {
1518
+ name: "viewport",
1519
+ content: "width=device-width, initial-scale=1"
1520
+ }),
1521
+ h("meta", {
1522
+ name: "intent-book-base",
1523
+ content: shell.base
1524
+ }),
1525
+ h("meta", {
1526
+ name: "description",
1527
+ content: shell.description
1528
+ }),
1529
+ h("title", `${shell.title} · ${shell.book.name}`),
1530
+ h("link", {
1531
+ rel: "stylesheet",
1532
+ href: `${shell.base}${STYLE_PATH}`
1533
+ }),
1534
+ h("script", {
1535
+ src: `${shell.base}${SCRIPT_PATH}`,
1536
+ defer: true
1537
+ })
1538
+ ];
1539
+ const layout = (shell) => h("div", { class: "shell" }, [
1540
+ sidebar(shell),
1541
+ h("main", [h("article", [...shell.main])]),
1542
+ tableOfContents(shell.headings)
1543
+ ]);
1544
+ const renderShell = (shell) => htmlDocument({
1545
+ head: headOf(shell),
1546
+ body: [
1547
+ topBar(shell),
1548
+ layout(shell),
1549
+ searchDialog()
1550
+ ]
1551
+ });
1552
+ // src/features/build-site/model/render-book.ts
1553
+ const INDEX = "index.html";
1554
+ const RENDER_CONCURRENCY$1 = 8;
1555
+ const indexFile = (route) => `${fileOf(route)}${INDEX}`;
1556
+ const renderDocument = Effect.fn("renderDocument")(function* renderDocument(context, document) {
1557
+ const rendered = yield* renderMarkdown({
1558
+ body: document.body,
1559
+ resolveLink: context.resolveFrom(document.from)
1560
+ });
1561
+ const title = Option.getOrElse(rendered.title, Function.constant(document.fallbackTitle));
1562
+ const main = document.main({
1563
+ base: context.base,
1564
+ book: context.book,
1565
+ skill: document.skill,
1566
+ title,
1567
+ tree: rendered.tree
1568
+ });
1569
+ const html = renderShell({
1570
+ base: context.base,
1571
+ books: context.books,
1572
+ book: context.book,
1573
+ title,
1574
+ description: document.skill.description,
1575
+ current: document.current,
1576
+ main,
1577
+ headings: rendered.headings
1578
+ });
1579
+ const entry = {
1580
+ title,
1581
+ name: document.searchName,
1582
+ book: context.book.name,
1583
+ url: `${context.base}${fileOf(document.route)}`,
1584
+ text: searchText({
1585
+ lead: document.lead,
1586
+ body: toString(rendered.tree)
1587
+ })
1588
+ };
1589
+ return {
1590
+ files: [{
1591
+ path: indexFile(document.route),
1592
+ content: html
1593
+ }, document.raw],
1594
+ entries: [entry]
1595
+ };
1596
+ });
1597
+ const overviewFile = (context) => ({
1598
+ path: indexFile(routeOf(context.slug, { kind: "overview" })),
1599
+ content: renderShell({
1600
+ base: context.base,
1601
+ books: context.books,
1602
+ book: context.book,
1603
+ title: context.book.name,
1604
+ description: context.book.description,
1605
+ current: { kind: "overview" },
1606
+ main: overviewMain({
1607
+ base: context.base,
1608
+ book: context.book
1609
+ }),
1610
+ headings: []
1611
+ })
1612
+ });
1613
+ const renderBook = Effect.fn("renderBook")(function* renderBook(input) {
1614
+ const slug = input.book.name;
1615
+ const context = {
1616
+ ...input,
1617
+ slug,
1618
+ resolveFrom: linkResolver({
1619
+ slug,
1620
+ book: input.book,
1621
+ base: input.base
1622
+ })
1623
+ };
1624
+ const documents = pipe(input.book.skills, Array.flatMap(documentsOf(context)));
1625
+ const rendered = yield* Effect.forEach(documents, (document) => renderDocument(context, document), { concurrency: RENDER_CONCURRENCY$1 });
1626
+ return {
1627
+ files: pipe(rendered, Array.flatMap((part) => part.files), Array.append(overviewFile(context))),
1628
+ entries: pipe(rendered, Array.flatMap((part) => part.entries))
1629
+ };
1630
+ });
1631
+ // src/features/build-site/model/build-site.ts
1632
+ const RENDER_CONCURRENCY = 8;
1633
+ const landingFiles = (input) => Boolean.match(input.landing, {
1634
+ onTrue: () => [{
1635
+ path: "index.html",
1636
+ content: landingPage(input)
1637
+ }],
1638
+ onFalse: () => []
1639
+ });
1640
+ const buildSite = Effect.fn("buildSite")(function* buildSite(input) {
1641
+ const built = yield* Effect.forEach(input.books, (book) => renderBook({
1642
+ books: input.books,
1643
+ book,
1644
+ base: input.base
1645
+ }), { concurrency: RENDER_CONCURRENCY });
1646
+ const entries = pipe(built, Array.flatMap((part) => part.entries));
1647
+ const search = yield* searchIndexFile(entries);
1648
+ return [
1649
+ ...pipe(built, Array.flatMap((part) => part.files)),
1650
+ ...landingFiles(input),
1651
+ ...ASSET_FILES,
1652
+ search
1653
+ ];
1654
+ });
1655
+ // src/features/read-book/model/no-skills-error.ts
1656
+ const taggedError$2 = Schema.TaggedError;
1657
+ var NoSkillsError = class extends taggedError$2()("NoSkillsError", { directory: Schema.String }) {};
1658
+ // src/features/read-book/model/read-book.ts
1659
+ const taggedError$1 = Schema.TaggedError;
1660
+ var BookReadError = class extends taggedError$1()("BookReadError", {
1661
+ directory: Schema.String,
1662
+ reason: Schema.String
1663
+ }) {};
1664
+ const RepositoryObject = Schema.Struct({
1665
+ url: Schema.String,
1666
+ directory: Schema.optionalKey(Schema.String)
1667
+ });
1668
+ const Repository = Schema.Union([Schema.String, RepositoryObject]);
1669
+ const PackageJson = Schema.Struct({
1670
+ name: Schema.String,
1671
+ version: Schema.String,
1672
+ description: Schema.optionalKey(Schema.String),
1673
+ homepage: Schema.optionalKey(Schema.String),
1674
+ repository: Schema.optionalKey(Repository)
1675
+ });
1676
+ const PackageJsonText = Schema.fromJsonString(PackageJson);
1677
+ const decodePackageJson = Schema.decodeUnknownEffect(PackageJsonText);
1678
+ const SKILLS_DIRECTORY = "skills";
1679
+ const SKILL_FILE = "SKILL.md";
1680
+ const MANIFEST_FILE = "package.json";
1681
+ const MARKDOWN = ".md";
1682
+ const ROOT_ENTRY = ".";
1683
+ const GIT_PREFIX = /^git\+/u;
1684
+ const GIT_SUFFIX = /\.git$/u;
1685
+ const SHORTHAND = /^(?:github:)?(?<slug>[\w.-]+\/[\w.-]+)$/u;
1686
+ const FILE_CONCURRENCY$1 = 16;
1687
+ const READ_CONCURRENCY = 4;
1688
+ const ONE_DIRECTORY = 1;
1689
+ const githubSlug = (value) => pipe(value, String$1.match(SHORTHAND), Option.flatMapNullishOr((found) => found.groups), Option.flatMap((groups) => Record.get(groups, "slug")));
1690
+ const repositoryUrl = (value) => pipe(githubSlug(value), Option.match({
1691
+ onNone: () => pipe(value, String$1.replace(GIT_PREFIX, ""), String$1.replace(GIT_SUFFIX, "")),
1692
+ onSome: (slug) => `https://github.com/${slug}`
1693
+ }));
1694
+ const repositoryText = (repository) => Match.value(repository).pipe(Match.when(Predicate.isString, (text) => text), Match.orElse((described) => described.url));
1695
+ const repositoryDirectory = (repository) => Match.value(repository).pipe(Match.when(Predicate.isString, () => Option.none()), Match.orElse((described) => Option.fromNullishOr(described.directory)));
1696
+ const sortedNames = (names) => pipe(names, Array.sortBy(String$1.Order));
1697
+ const nestedDirectories = (name, names) => {
1698
+ const prefix = `${name}/`;
1699
+ return pipe(names, Array.filter(String$1.startsWith(prefix)), Array.map(String$1.slice(prefix.length)));
1700
+ };
1701
+ const isReference = (nested) => (entry) => String$1.endsWith(MARKDOWN)(entry) && entry !== SKILL_FILE && !pipe(nested, Array.some((directory) => String$1.startsWith(`${directory}/`)(entry)));
1702
+ const readReferences = Effect.fn("readReferences")(function* readReferences(input) {
1703
+ const fileSystem = yield* FileSystem.FileSystem;
1704
+ const path = yield* Path.Path;
1705
+ const entries = yield* fileSystem.readDirectory(input.skillDirectory, { recursive: true });
1706
+ const nested = nestedDirectories(input.name, input.names);
1707
+ const files = pipe(entries, Array.filter(isReference(nested)), sortedNames);
1708
+ return yield* Effect.forEach(files, (file) => fileSystem.readFileString(path.join(input.skillDirectory, file)).pipe(Effect.map((text) => ({
1709
+ file,
1710
+ text
1711
+ }))), { concurrency: FILE_CONCURRENCY$1 });
1712
+ });
1713
+ const readManifest = Effect.fn("readManifest")(function* readManifest(directory) {
1714
+ const fileSystem = yield* FileSystem.FileSystem;
1715
+ const path = yield* Path.Path;
1716
+ return yield* fileSystem.readFileString(path.join(directory, MANIFEST_FILE)).pipe(Effect.flatMap(decodePackageJson), Effect.mapError((cause) => BookReadError.make({
1717
+ directory,
1718
+ reason: `${MANIFEST_FILE}: ${cause.message}`
1719
+ })));
1720
+ });
1721
+ const skillNames = Effect.fn("skillNames")(function* skillNames(skillsDirectory) {
1722
+ const fileSystem = yield* FileSystem.FileSystem;
1723
+ const path = yield* Path.Path;
1724
+ const entries = yield* fileSystem.readDirectory(skillsDirectory, { recursive: true }).pipe(Effect.orElseSucceed(() => []));
1725
+ return pipe(entries, Array.filter((entry) => path.basename(entry) === SKILL_FILE), Array.map((entry) => path.dirname(entry)), Array.filter((name) => name !== ROOT_ENTRY), sortedNames);
1726
+ });
1727
+ const readSkill = Effect.fn("readSkill")(function* readSkill(input) {
1728
+ const { name, names, skillsDirectory } = input;
1729
+ const fileSystem = yield* FileSystem.FileSystem;
1730
+ const path = yield* Path.Path;
1731
+ const skillDirectory = path.join(skillsDirectory, name);
1732
+ const text = yield* fileSystem.readFileString(path.join(skillDirectory, SKILL_FILE));
1733
+ const references = yield* readReferences({
1734
+ skillDirectory,
1735
+ name,
1736
+ names
1737
+ });
1738
+ return yield* parseSkill({
1739
+ name,
1740
+ text,
1741
+ references
1742
+ });
1743
+ });
1744
+ const readSkills = Effect.fn("readSkills")(function* readSkills(directory) {
1745
+ const skillsDirectory = (yield* Path.Path).join(directory, SKILLS_DIRECTORY);
1746
+ const names = yield* skillNames(skillsDirectory);
1747
+ yield* Effect.filterOrFail(Effect.succeed(names), Array.isReadonlyArrayNonEmpty, () => NoSkillsError.make({ directory }));
1748
+ return yield* Effect.forEach(names, (name) => readSkill({
1749
+ skillsDirectory,
1750
+ name,
1751
+ names
1752
+ }), { concurrency: FILE_CONCURRENCY$1 });
1753
+ });
1754
+ /** @internal */
1755
+ const readBook = Effect.fn("readBook")(function* readBook(directory) {
1756
+ const manifest = yield* readManifest(directory);
1757
+ const skills = yield* readSkills(directory);
1758
+ return {
1759
+ name: manifest.name,
1760
+ version: manifest.version,
1761
+ description: manifest.description ?? "",
1762
+ repository: pipe(Option.fromNullishOr(manifest.repository), Option.map(repositoryText), Option.map(repositoryUrl)),
1763
+ directory: pipe(Option.fromNullishOr(manifest.repository), Option.flatMap(repositoryDirectory)),
1764
+ homepage: Option.fromNullishOr(manifest.homepage),
1765
+ skills
1766
+ };
1767
+ });
1768
+ const skippable = (directories) => (error) => Boolean.match(Array.isReadonlyArrayNonEmpty(Array.drop(directories, ONE_DIRECTORY)), {
1769
+ onTrue: () => Effect.succeed(Option.none()),
1770
+ onFalse: () => Effect.fail(error)
1771
+ });
1772
+ /** @internal */
1773
+ const readBooks = Effect.fn("readBooks")(function* readBooks(directories) {
1774
+ const results = yield* Effect.forEach(directories, (directory) => readBook(directory).pipe(Effect.asSome, Effect.catchTag("NoSkillsError", skippable(directories))), { concurrency: READ_CONCURRENCY });
1775
+ const books = Array.getSomes(results);
1776
+ yield* Effect.filterOrFail(Effect.succeed(books), Array.isReadonlyArrayNonEmpty, () => NoSkillsError.make({ directory: Array.join(directories, ", ") }));
1777
+ return {
1778
+ books,
1779
+ skipped: pipe(Array.zip(directories, results), Array.filter(([, result]) => Option.isNone(result)), Array.map(([directory]) => directory))
1780
+ };
1781
+ });
1782
+ // src/features/write-site/model/write-site.ts
1783
+ const taggedError = Schema.TaggedError;
1784
+ var SiteWriteError = class extends taggedError()("SiteWriteError", {
1785
+ directory: Schema.String,
1786
+ reason: Schema.String
1787
+ }) {};
1788
+ const MARKER = ".intent-book";
1789
+ const FILE_CONCURRENCY = 16;
1790
+ const clearOld = Effect.fn("clearOld")(function* clearOld(directory) {
1791
+ const fileSystem = yield* FileSystem.FileSystem;
1792
+ const path = yield* Path.Path;
1793
+ const owned = yield* fileSystem.exists(path.join(directory, MARKER));
1794
+ const entries = yield* fileSystem.readDirectory(directory);
1795
+ const writable = owned || Array.isReadonlyArrayEmpty(entries);
1796
+ yield* Boolean.match(writable, {
1797
+ onTrue: () => fileSystem.remove(directory, { recursive: true }),
1798
+ onFalse: () => SiteWriteError.make({
1799
+ directory,
1800
+ reason: `not empty and not created by intent-book (no ${MARKER} file)`
1801
+ })
1802
+ });
1803
+ });
1804
+ const writeFile = Effect.fn("writeFile")(function* writeFile(directory, file) {
1805
+ const fileSystem = yield* FileSystem.FileSystem;
1806
+ const path = yield* Path.Path;
1807
+ const target = path.join(directory, file.path);
1808
+ yield* fileSystem.makeDirectory(path.dirname(target), { recursive: true });
1809
+ yield* fileSystem.writeFileString(target, file.content);
1810
+ });
1811
+ /** @internal */
1812
+ const writeSite = Effect.fn("writeSite")(function* writeSite(directory, files) {
1813
+ const present = yield* (yield* FileSystem.FileSystem).exists(directory);
1814
+ yield* Boolean.match(present, {
1815
+ onTrue: () => clearOld(directory),
1816
+ onFalse: () => Effect.void
1817
+ });
1818
+ yield* writeFile(directory, {
1819
+ path: MARKER,
1820
+ content: ""
1821
+ });
1822
+ yield* Effect.forEach(files, (file) => writeFile(directory, file), { concurrency: FILE_CONCURRENCY });
1823
+ });
1824
+ // bin/intent-book.ts
1825
+ const CURRENT_DIRECTORY = ".";
1826
+ const directoriesOf = (given) => Boolean.match(Array.isReadonlyArrayEmpty(given), {
1827
+ onTrue: () => [CURRENT_DIRECTORY],
1828
+ onFalse: () => given
1829
+ });
1830
+ const build = Effect.fn("build")(function* build(input) {
1831
+ const path = yield* Path.Path;
1832
+ const { books, skipped } = yield* readBooks(Array.map(directoriesOf(input.directories), (directory) => path.resolve(directory)));
1833
+ const files = yield* buildSite({
1834
+ books,
1835
+ base: input.base,
1836
+ landing: input.landing
1837
+ });
1838
+ yield* Boolean.match(Array.isReadonlyArrayNonEmpty(skipped), {
1839
+ onTrue: () => Console.log(`skipped (no skills): ${Array.join(skipped, ", ")}`),
1840
+ onFalse: () => Effect.void
1841
+ });
1842
+ yield* writeSite(path.resolve(input.out), files);
1843
+ yield* Console.log(`${books.length} package(s), ${files.length} files -> ${input.out}`);
1844
+ });
1845
+ const command = Command.make("intent-book", {
1846
+ directories: Argument.String("package").pipe(Argument.withDescription("Directory of an npm package that ships skills/ (default: .)"), Argument.variadic()),
1847
+ out: Flag.String("out").pipe(Flag.withDescription("Directory to write the site to"), Flag.withDefault("book")),
1848
+ base: Flag.String("base").pipe(Flag.withDescription("Path the site is served under, with a leading and trailing slash"), Flag.withDefault("/")),
1849
+ noLanding: Flag.Boolean("no-landing").pipe(Flag.withDescription("Do not write index.html at the root, for a site that lives inside another site"))
1850
+ }, (input) => build({
1851
+ directories: input.directories,
1852
+ out: input.out,
1853
+ base: input.base,
1854
+ landing: !input.noLanding
1855
+ }));
1856
+ runMain("intent-book")(Command.run(command, { version }));
1857
+ export {};
1858
+
1859
+ //# sourceMappingURL=intent-book.mjs.map