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