@nanocollective/roster 0.1.0-alpha.9 → 0.1.0-beta.10

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.
Files changed (151) hide show
  1. package/README.md +6 -0
  2. package/dist/cli.js +4189 -1971
  3. package/dist/worker/assets/assets/css/base.css +327 -0
  4. package/dist/worker/assets/assets/css/brain.css +116 -0
  5. package/dist/worker/assets/assets/css/diff.css +33 -0
  6. package/dist/worker/assets/assets/css/graph.css +39 -0
  7. package/dist/worker/assets/assets/css/health.css +75 -0
  8. package/dist/worker/assets/assets/css/home.css +114 -0
  9. package/dist/worker/assets/assets/css/inbox.css +199 -0
  10. package/dist/worker/assets/assets/css/layout.css +181 -0
  11. package/dist/worker/assets/assets/css/markdown.css +96 -0
  12. package/dist/worker/assets/assets/css/runs.css +13 -0
  13. package/dist/worker/assets/assets/css/search.css +48 -0
  14. package/dist/worker/assets/assets/css/setup.css +194 -0
  15. package/dist/worker/assets/assets/js/api.js +191 -0
  16. package/dist/worker/assets/assets/js/app.js +500 -0
  17. package/dist/worker/assets/assets/js/dialog.js +196 -0
  18. package/dist/worker/assets/assets/js/dom.js +131 -0
  19. package/dist/worker/assets/assets/js/homesort.js +174 -0
  20. package/dist/worker/assets/assets/js/icons.js +142 -0
  21. package/dist/worker/assets/assets/js/inflight.js +18 -0
  22. package/dist/worker/assets/assets/js/lightbox.js +273 -0
  23. package/dist/worker/assets/assets/js/md.js +406 -0
  24. package/dist/worker/assets/assets/js/mdedit.js +84 -0
  25. package/dist/worker/assets/assets/js/mention.js +264 -0
  26. package/dist/worker/assets/assets/js/readiness.js +70 -0
  27. package/dist/worker/assets/assets/js/refresh.js +197 -0
  28. package/dist/worker/assets/assets/js/router.js +20 -0
  29. package/dist/worker/assets/assets/js/search.js +366 -0
  30. package/dist/worker/assets/assets/js/state.js +213 -0
  31. package/dist/worker/assets/assets/js/textdiff.js +96 -0
  32. package/dist/worker/assets/assets/js/views/app.js +145 -0
  33. package/dist/worker/assets/assets/js/views/brain.js +260 -0
  34. package/dist/worker/assets/assets/js/views/changed.js +157 -0
  35. package/dist/worker/assets/assets/js/views/checklist.js +115 -0
  36. package/dist/worker/assets/assets/js/views/credential.js +84 -0
  37. package/dist/worker/assets/assets/js/views/docs.js +174 -0
  38. package/dist/worker/assets/assets/js/views/files.js +139 -0
  39. package/dist/worker/assets/assets/js/views/graph.js +436 -0
  40. package/dist/worker/assets/assets/js/views/health.js +304 -0
  41. package/dist/worker/assets/assets/js/views/hire.js +593 -0
  42. package/dist/worker/assets/assets/js/views/home.js +621 -0
  43. package/dist/worker/assets/assets/js/views/inbox.js +1558 -0
  44. package/dist/worker/assets/assets/js/views/memory.js +150 -0
  45. package/dist/worker/assets/assets/js/views/org.js +195 -0
  46. package/dist/worker/assets/assets/js/views/orgedit.js +240 -0
  47. package/dist/worker/assets/assets/js/views/paste.js +216 -0
  48. package/dist/worker/assets/assets/js/views/prompt.js +457 -0
  49. package/dist/worker/assets/assets/js/views/repos.js +97 -0
  50. package/dist/worker/assets/assets/js/views/runonce.js +94 -0
  51. package/dist/worker/assets/assets/js/views/runs.js +182 -0
  52. package/dist/worker/assets/assets/js/views/setup.js +557 -0
  53. package/dist/worker/assets/assets/js/views/staff.js +291 -0
  54. package/dist/worker/assets/assets/js/views/todo.js +62 -0
  55. package/dist/worker/assets/assets/js/yaml.js +134 -0
  56. package/dist/worker/assets/docs-images/brain.jpg +0 -0
  57. package/dist/worker/assets/docs-images/home.jpg +0 -0
  58. package/dist/worker/assets/docs-images/org.jpg +0 -0
  59. package/dist/worker/assets/docs-images/prompt.jpg +0 -0
  60. package/dist/worker/assets/docs-images/setup-org.jpg +0 -0
  61. package/dist/worker/assets/docs-images/setup-plan.jpg +0 -0
  62. package/dist/worker/assets/docs-images/staff.jpg +0 -0
  63. package/dist/worker/assets/index.html +82 -0
  64. package/dist/worker/index.js +5143 -0
  65. package/docs/README.md +2 -2
  66. package/docs/architecture.md +23 -4
  67. package/docs/charters/analyst.md +65 -0
  68. package/docs/charters/community.md +63 -0
  69. package/docs/charters/designer.md +65 -0
  70. package/docs/charters/devops.md +65 -0
  71. package/docs/charters/pm.md +70 -0
  72. package/docs/charters/qa.md +65 -0
  73. package/docs/charters/writer.md +63 -0
  74. package/docs/commands.md +36 -9
  75. package/docs/concepts.md +34 -21
  76. package/docs/cost.md +3 -3
  77. package/docs/developing.md +28 -10
  78. package/docs/doctor-codes.md +3 -1
  79. package/docs/export.md +2 -0
  80. package/docs/getting-started.md +49 -29
  81. package/docs/hosting.md +114 -43
  82. package/docs/images/brain.jpg +0 -0
  83. package/docs/images/home.jpg +0 -0
  84. package/docs/images/org.jpg +0 -0
  85. package/docs/images/prompt.jpg +0 -0
  86. package/docs/images/staff.jpg +0 -0
  87. package/docs/manual-steps.md +3 -2
  88. package/docs/memory.md +2 -1
  89. package/docs/org-yaml.md +3 -0
  90. package/docs/portal.md +144 -45
  91. package/docs/prompts.md +6 -0
  92. package/docs/security.md +70 -11
  93. package/docs/session-workflow.md +24 -6
  94. package/docs/staff-yaml.md +21 -2
  95. package/docs/upgrading.md +3 -3
  96. package/docs/writing-a-charter.md +19 -6
  97. package/package.json +4 -3
  98. package/templates/brain/.github/workflows/%%STAFF%%-daily.yaml +20 -1
  99. package/templates/brain/.github/workflows/%%STAFF%%-mention.yaml +53 -13
  100. package/templates/brain/CHARTER.md +2 -2
  101. package/templates/brain/STATE.md +16 -0
  102. package/templates/brain/memory/INDEX.md +1 -1
  103. package/templates/brain/staff.yaml +4 -1
  104. package/templates/briefs/amend.md +4 -3
  105. package/templates/briefs/priorities.md +46 -0
  106. package/templates/ops/.github/workflows/session.yaml +150 -3
  107. package/templates/ops/compose.mjs +35 -8
  108. package/templates/ops/org/operating.md +29 -10
  109. package/templates/ops/org/voice.md +2 -1
  110. package/templates/ops/prompts/daily.md +51 -14
  111. package/templates/ops/prompts/mention.md +24 -2
  112. package/templates/ops/run-record.mjs +5 -3
  113. package/templates/ops/status-week.mjs +169 -0
  114. package/templates/portal/css/base.css +49 -0
  115. package/templates/portal/css/health.css +14 -1
  116. package/templates/portal/css/home.css +114 -0
  117. package/templates/portal/css/inbox.css +21 -4
  118. package/templates/portal/css/layout.css +35 -3
  119. package/templates/portal/css/markdown.css +19 -0
  120. package/templates/portal/css/search.css +48 -0
  121. package/templates/portal/css/setup.css +79 -4
  122. package/templates/portal/index.html +15 -9
  123. package/templates/portal/js/api.js +60 -4
  124. package/templates/portal/js/app.js +125 -7
  125. package/templates/portal/js/dialog.js +36 -0
  126. package/templates/portal/js/homesort.js +174 -0
  127. package/templates/portal/js/icons.js +41 -0
  128. package/templates/portal/js/inflight.js +18 -0
  129. package/templates/portal/js/md.js +5 -2
  130. package/templates/portal/js/mdedit.js +84 -0
  131. package/templates/portal/js/readiness.js +70 -0
  132. package/templates/portal/js/refresh.js +10 -2
  133. package/templates/portal/js/search.js +366 -0
  134. package/templates/portal/js/state.js +11 -5
  135. package/templates/portal/js/views/app.js +1 -2
  136. package/templates/portal/js/views/brain.js +1 -1
  137. package/templates/portal/js/views/checklist.js +19 -4
  138. package/templates/portal/js/views/credential.js +42 -51
  139. package/templates/portal/js/views/health.js +11 -6
  140. package/templates/portal/js/views/hire.js +593 -0
  141. package/templates/portal/js/views/home.js +621 -0
  142. package/templates/portal/js/views/inbox.js +237 -68
  143. package/templates/portal/js/views/org.js +31 -111
  144. package/templates/portal/js/views/orgedit.js +240 -0
  145. package/templates/portal/js/views/paste.js +111 -66
  146. package/templates/portal/js/views/prompt.js +94 -40
  147. package/templates/portal/js/views/repos.js +10 -10
  148. package/templates/portal/js/views/runs.js +21 -4
  149. package/templates/portal/js/views/setup.js +130 -163
  150. package/templates/portal/js/views/staff.js +181 -301
  151. package/templates/portal/js/views/todo.js +62 -0
@@ -0,0 +1,84 @@
1
+ /* The agent's credential, stored once for the org.
2
+ *
3
+ * The value goes from this box to the local server in a POST, and from there to gh on its
4
+ * standard input. It is not kept in the page after it is sent, and nothing echoes it back. */
5
+
6
+ import { getCredential, storeCredential } from "../api.js";
7
+ import { el } from "../dom.js";
8
+
9
+ /** @param opts.bare drawn inside a step that already has a title. `onStatus(done)` hears whether one is stored. */
10
+ export function credentialPanel(opts = {}) {
11
+ const box = el("div", { className: opts.bare ? "" : "manual" });
12
+ if (!opts.bare) box.append(el("b", { textContent: "Agent credential" }));
13
+ const body = el("div");
14
+ box.append(body);
15
+ body.append(el("p", { className: "sub", textContent: "Checking…" }));
16
+
17
+ getCredential()
18
+ .then((c) => {
19
+ opts.onStatus?.(Boolean(c.stored ?? c.orgSecret));
20
+ draw(body, c, opts);
21
+ })
22
+ .catch((err) => body.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) })));
23
+ return box;
24
+ }
25
+
26
+ function draw(body, c, opts = {}) {
27
+ body.replaceChildren();
28
+
29
+ if (!(c.brains ?? []).length) {
30
+ // Inside a step, the step's own hint already says when this opens.
31
+ if (!opts.bare) body.append(el("p", { className: "sub", textContent: "Available after your first hire. You only add it once." }));
32
+ return;
33
+ }
34
+
35
+ const form = el("div", { className: "credform" });
36
+ const input = el("input", { type: "password", placeholder: "Paste it here", autocomplete: "off", className: "textfield" });
37
+ const go = el("button", { className: "btn primary", textContent: "Save" });
38
+ const out = el("div");
39
+ form.append(
40
+ ...(c.howTo ? [el("p", { className: "sub", textContent: "To get one, " + c.howTo })] : []),
41
+ input,
42
+ el("div", { className: "row" }, [go]),
43
+ out,
44
+ );
45
+
46
+ // Stored already, on the org or on every brain repo: say so, and keep replacing it one click away.
47
+ if (c.stored ?? c.orgSecret) {
48
+ const replace = el("button", { className: "ghbtn", textContent: "Replace it" });
49
+ replace.onclick = () => {
50
+ replace.remove();
51
+ form.hidden = false;
52
+ input.focus?.();
53
+ };
54
+ form.hidden = true;
55
+ body.append(el("p", { className: "okline", textContent: "✓ Stored as " + c.name + "." }), replace, form);
56
+ } else {
57
+ body.append(form);
58
+ }
59
+
60
+ go.onclick = async () => {
61
+ const value = String(input.value ?? "").trim();
62
+ if (!value) {
63
+ input.focus?.();
64
+ return;
65
+ }
66
+ go.disabled = true;
67
+ go.textContent = "Saving…";
68
+ try {
69
+ const r = await storeCredential(value, false);
70
+ input.value = "";
71
+ if (!r.ok) throw new Error(r.error);
72
+ opts.onStatus?.(true);
73
+ out.replaceChildren(
74
+ ...(r.fellBack ? [el("p", { className: "sub", textContent: "Saved on each repo instead: " + r.fellBack })] : []),
75
+ el("p", { className: "okline", textContent: "✓ Saved." }),
76
+ );
77
+ } catch (err) {
78
+ out.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
79
+ } finally {
80
+ go.disabled = false;
81
+ go.textContent = "Save";
82
+ }
83
+ };
84
+ }
@@ -0,0 +1,174 @@
1
+ /* The framework's own documentation, read where you already are. Same renderer as a brain
2
+ file, so a link between pages behaves like a link between files rather than a dead end. */
3
+
4
+ import { getDoc, getDocs, searchDocs } from "../api.js";
5
+ import { el, esc, skeleton, slug } from "../dom.js";
6
+ import { mdlite } from "../md.js";
7
+ import { S, writeHash } from "../state.js";
8
+
9
+ export function viewDocs(m) {
10
+ m.append(el("h1", { textContent: "Docs" }));
11
+ m.append(
12
+ el("p", {
13
+ className: "sub",
14
+ textContent:
15
+ "How roster works, what it will not do for you, and every trap worth knowing about.",
16
+ }),
17
+ );
18
+
19
+ /* Titles are not enough. Twenty-odd pages is too many to scan and few enough for the server
20
+ to read in full on every keystroke, and what you are looking for — "which page explains the
21
+ mention gate" — is a sentence in a paragraph rather than a word in a heading. So the box
22
+ searches the text, and the list becomes the results while there is a query in it. */
23
+ const find = el("input", {
24
+ type: "search",
25
+ placeholder: "Search the docs…",
26
+ value: S.docQuery ?? "",
27
+ style: "width:100%;margin-bottom:12px",
28
+ });
29
+ m.append(find);
30
+
31
+ const split = el("div", { className: "split" });
32
+ const list = el("div", { className: "tree" });
33
+ const viewer = el("div", { className: "viewer" });
34
+ split.append(list, viewer);
35
+ m.append(split);
36
+
37
+ if (S.docs) paint();
38
+ else {
39
+ list.replaceChildren(...skeleton("row", 8));
40
+ getDocs()
41
+ .then((d) => { S.docs = d; paint(); })
42
+ .catch((e) => list.replaceChildren(el("p", { className: "empty err", textContent: e.message })));
43
+ }
44
+
45
+ /* Debounced, because every keystroke is a read of every page. 140ms is below the point
46
+ where the list feels like it is lagging behind the typing. */
47
+ let timer = null;
48
+ find.oninput = () => {
49
+ S.docQuery = find.value;
50
+ writeHash(false);
51
+ clearTimeout(timer);
52
+ timer = setTimeout(run, 140);
53
+ };
54
+ if (S.docQuery) run();
55
+
56
+ async function run() {
57
+ const q = (S.docQuery ?? "").trim();
58
+ if (!q) { paint(); return; }
59
+ let hits;
60
+ try {
61
+ hits = (await searchDocs(q)).hits ?? [];
62
+ } catch (e) {
63
+ list.replaceChildren(el("p", { className: "empty err", textContent: e.message }));
64
+ return;
65
+ }
66
+ // A slow answer to a query you have already moved on from must not land.
67
+ if ((S.docQuery ?? "").trim() !== q) return;
68
+ paintHits(hits, q);
69
+ }
70
+
71
+ function paint() {
72
+ list.replaceChildren();
73
+ if (!S.docs?.length) {
74
+ list.append(el("p", { className: "empty", textContent: "No docs here." }));
75
+ return;
76
+ }
77
+ for (const d of S.docs) {
78
+ const b = el("button", { className: "tfile tmem", title: d.file });
79
+ b.dataset.key = d.file;
80
+ b.append(el("span", { className: "t", textContent: d.title }));
81
+ b.setAttribute("aria-current", String((S.openDoc ?? S.docs[0].file) === d.file));
82
+ b.onclick = () => open(d.file);
83
+ list.append(b);
84
+ }
85
+ show(S.openDoc ?? S.docs[0].file);
86
+ }
87
+
88
+ /** The same list, narrowed, with the lines that matched under each row. */
89
+ function paintHits(hits, q) {
90
+ list.replaceChildren();
91
+ list.append(
92
+ el("div", {
93
+ className: "tdir first",
94
+ textContent: hits.length
95
+ ? hits.length + (hits.length === 1 ? " page" : " pages") + " mention that"
96
+ : "nothing mentions that",
97
+ }),
98
+ );
99
+ if (!hits.length) {
100
+ list.append(
101
+ el("p", {
102
+ className: "empty",
103
+ textContent: "Every word has to appear somewhere on the page. Try fewer.",
104
+ }),
105
+ );
106
+ return;
107
+ }
108
+ for (const h of hits) {
109
+ const b = el("button", { className: "tfile thit", title: h.file });
110
+ b.dataset.key = h.file;
111
+ const t = el("span", { className: "t" });
112
+ t.append(el("span", { className: "hitname", textContent: h.title }));
113
+ for (const line of h.matches ?? []) {
114
+ t.append(el("span", { className: "hitline", innerHTML: mark(line.text, q) }));
115
+ }
116
+ b.append(t);
117
+ b.setAttribute("aria-current", String(S.openDoc === h.file));
118
+ b.onclick = () => open(h.file);
119
+ list.append(b);
120
+ }
121
+ // Opening the first result is what makes typing feel like searching rather than filtering.
122
+ if (!hits.some((h) => h.file === S.openDoc)) open(hits[0].file);
123
+ }
124
+
125
+ /** The words that were asked for, shown in the line they were found in. */
126
+ function mark(text, q) {
127
+ const terms = q.toLowerCase().split(/\s+/).filter(Boolean)
128
+ .map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
129
+ let html = esc(text);
130
+ if (terms.length) {
131
+ html = html.replace(new RegExp("(" + terms.join("|") + ")", "gi"), "<em>$1</em>");
132
+ }
133
+ return html;
134
+ }
135
+
136
+ function open(file) {
137
+ S.openDoc = file;
138
+ writeHash(false);
139
+ for (const o of list.querySelectorAll(".tfile")) {
140
+ o.setAttribute("aria-current", String(o.dataset.key === file));
141
+ }
142
+ show(file);
143
+ }
144
+
145
+ async function show(file) {
146
+ viewer.replaceChildren(...skeleton("head", 1), ...skeleton("line", 8));
147
+ let text;
148
+ try {
149
+ text = await getDoc(file);
150
+ } catch (e) {
151
+ viewer.replaceChildren(el("p", { className: "empty err", textContent: e.message }));
152
+ return;
153
+ }
154
+ const doc = el("div", { className: "md doc" });
155
+ // The pages carry YAML frontmatter for the collective's docs site. It is metadata, not
156
+ // content, so it is dropped rather than rendered as a rule and a stray paragraph.
157
+ doc.innerHTML = mdlite(text.replace(/^---\n[\s\S]*?\n---\n/, ""), { docs: true });
158
+ doc.addEventListener("click", (e) => {
159
+ const link = e.target.closest?.("[data-doc]");
160
+ if (!link) return;
161
+ e.preventDefault();
162
+ const [page, anchor] = link.dataset.doc.split("#");
163
+ if (page && S.docs.some((d) => d.file === page)) open(page);
164
+ if (anchor) {
165
+ const to = [...viewer.querySelectorAll("h1,h2,h3,h4")].find(
166
+ (h) => slug(h.textContent) === anchor,
167
+ );
168
+ if (to?.scrollIntoView) to.scrollIntoView({ block: "start" });
169
+ }
170
+ });
171
+ viewer.replaceChildren(doc);
172
+ viewer.scrollTop = 0;
173
+ }
174
+ }
@@ -0,0 +1,139 @@
1
+ /* Rendering one file out of a brain: markdown, image, video, CSV, JSON, or source. */
2
+
3
+ import { el, kb } from "../dom.js";
4
+ import { fileUrl, getFile } from "../api.js";
5
+ import { icon } from "../icons.js";
6
+ import { mdlite } from "../md.js";
7
+ import { yamlPre } from "../yaml.js";
8
+
9
+ const IMG = ["png", "jpg", "jpeg", "gif", "svg", "webp", "ico"];
10
+
11
+ /* A brain records as often as it screenshots, and a recording read as source is a screenful
12
+ of binary. It plays here for the same reason an image displays here: it is the file. */
13
+ const VIDEO = ["mp4", "m4v", "webm", "mov", "ogv"];
14
+ const AUDIO = ["mp3", "m4a", "wav", "oga"];
15
+
16
+ export async function showFile(viewer, s, f, pick) {
17
+ viewer.replaceChildren(el("p", { className: "empty", textContent: "Loading…" }));
18
+ const path = s.dir + "/" + f.path;
19
+ const head = el("div", { className: "meta", style: "margin-bottom:12px" });
20
+ /* A file the export did not walk (the charter, the manifest) has no size on it, so the
21
+ header says what it knows and fills the rest in once the text arrives. */
22
+ const stamp = (bytes) =>
23
+ f.path + (bytes ? " · " + kb(bytes) : "") +
24
+ (f.bytes ? " · " + new Date(f.modified).toLocaleDateString() : "");
25
+ head.textContent = stamp(f.bytes);
26
+
27
+ if (IMG.includes(f.ext)) {
28
+ /* `zoomable` is the opt-in the lightbox looks for. The gallery tiles above are not
29
+ marked, because their click already means "open this file", and this is where it lands. */
30
+ viewer.replaceChildren(
31
+ head,
32
+ el("img", { className: "zoomable", src: fileUrl(path), alt: f.path }),
33
+ );
34
+ return;
35
+ }
36
+
37
+ if (VIDEO.includes(f.ext) || AUDIO.includes(f.ext)) {
38
+ const player = el(VIDEO.includes(f.ext) ? "video" : "audio", {
39
+ src: fileUrl(path),
40
+ controls: true,
41
+ preload: "metadata",
42
+ className: "player",
43
+ });
44
+ // Nothing else here streams, so say what to do when a codec the browser cannot decode
45
+ // turns up — a .mov is often h.265, and a silent black rectangle explains nothing.
46
+ const fallback = el("p", { className: "meta", hidden: true });
47
+ player.onerror = () => {
48
+ fallback.hidden = false;
49
+ fallback.textContent = "This browser cannot play " + f.ext + ". The file itself is fine — ";
50
+ fallback.append(
51
+ el("a", { href: fileUrl(path), download: f.path.split("/").pop(), textContent: "download it" }),
52
+ );
53
+ };
54
+ viewer.replaceChildren(head, player, fallback);
55
+ return;
56
+ }
57
+
58
+ const text = await getFile(path);
59
+ head.textContent = stamp(f.bytes || text.length);
60
+ if (f.ext === "csv") {
61
+ viewer.replaceChildren(head, csvTable(text));
62
+ return;
63
+ }
64
+
65
+ // A brain is mostly markdown, and reading it as source was the thing that made the file
66
+ // tree feel like a worse GitHub rather than a better one.
67
+ if (f.ext === "md" || f.ext === "markdown") {
68
+ const dir = f.path.includes("/") ? f.path.slice(0, f.path.lastIndexOf("/") + 1) : "";
69
+ const doc = el("div", { className: "md doc" });
70
+ doc.innerHTML = mdlite(text, { repo: s.brain, file: { dir, staffDir: s.dir } });
71
+ doc.addEventListener("click", (e) => {
72
+ const link = e.target.closest?.("[data-file]");
73
+ if (!link) return;
74
+ e.preventDefault();
75
+ pick?.(link.dataset.file);
76
+ });
77
+ viewer.replaceChildren(head, doc);
78
+ return;
79
+ }
80
+
81
+ if (f.ext === "json") {
82
+ let pretty = text;
83
+ try {
84
+ pretty = JSON.stringify(JSON.parse(text), null, 2);
85
+ } catch {
86
+ /* malformed: show it as it is */
87
+ }
88
+ viewer.replaceChildren(head, el("pre", { className: "code", textContent: pretty }));
89
+ return;
90
+ }
91
+
92
+ // A manifest is the one kind of source in a brain that is read closely rather than skimmed.
93
+ if (f.ext === "yaml" || f.ext === "yml") {
94
+ viewer.replaceChildren(head, yamlPre(text));
95
+ return;
96
+ }
97
+
98
+ viewer.replaceChildren(head, el("pre", { className: "code", textContent: text }));
99
+ }
100
+
101
+ function csvTable(text) {
102
+ const rows = text.trim().split("\n").slice(0, 300).map((r) => r.split(","));
103
+ const t = el("table");
104
+ const [head, ...body] = rows;
105
+ t.append(el("tr", {}, (head ?? []).map((h) => el("th", { textContent: h }))));
106
+ for (const r of body) t.append(el("tr", {}, r.map((c) => el("td", { textContent: c }))));
107
+ return t;
108
+ }
109
+
110
+ export function showGallery(viewer, s, surface) {
111
+ const shots = surface.files.filter((f) => IMG.includes(f.ext) || VIDEO.includes(f.ext));
112
+ if (!shots.length) {
113
+ viewer.replaceChildren(el("p", { className: "empty", textContent: "Nothing to show here." }));
114
+ return;
115
+ }
116
+ const g = el("div", { className: "gallery" });
117
+ for (const f of shots.slice(0, 200)) {
118
+ const fig = el("figure");
119
+ const src = fileUrl(s.dir + "/" + f.path);
120
+ /* A video tile is its own first frame rather than a placeholder, which is what makes a
121
+ wall of recordings tell you anything. `preload="metadata"` is enough for that and does
122
+ not pull the whole file for every tile on the page. */
123
+ const tile = IMG.includes(f.ext)
124
+ ? el("img", { src, loading: "lazy", alt: f.path })
125
+ : el("video", { src, preload: "metadata", muted: true, playsInline: true });
126
+ tile.onclick = () => showFile(viewer, s, f);
127
+ fig.append(tile);
128
+ if (!IMG.includes(f.ext)) fig.append(el("span", { className: "playmark" }, [icon("play", "ic")]));
129
+ fig.append(el("figcaption", { textContent: f.path.split("/").pop() }));
130
+ g.append(fig);
131
+ }
132
+ const vids = shots.filter((f) => VIDEO.includes(f.ext)).length;
133
+ viewer.replaceChildren(
134
+ el("div", { className: "meta", style: "margin-bottom:12px" }, [
135
+ shots.length - vids + " images" + (vids ? " and " + vids + " videos" : "") + " in " + surface.path,
136
+ ]),
137
+ g,
138
+ );
139
+ }